// Copyright (C) Stichting Deltares 2017. All rights reserved.
//
// This file is part of the DAM Engine.
//
// The DAM Engine is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
using Deltares.DamEngine.Data.Standard.Language;
namespace Deltares.DamEngine.Data.General
{
public class WaterBoard
{
private string description = "";
private IList dikes;
private List locations = null;
private IList segments;
private IList soilgeometry2DNames;
private string waterLevelTimeSeriesFileName;
private Dike selectedDike;
public WaterBoard()
{
this.dikes = new List();
this.segments = new List();
this.soilgeometry2DNames = new List();
}
public virtual IList Segments
{
get { return this.segments; }
set { this.segments = value; }
}
public virtual IList SoilGeometry2DNames
{
get { return this.soilgeometry2DNames; }
set { this.soilgeometry2DNames = value; }
}
public void FillGeometry2DNamesFromSegments()
{
// Add soilgeometry2D names into list
foreach (Segment segment in Segments)
{
foreach (SoilGeometryProbability soilGeometryProbability in segment.SoilProfileProbabilities)
{
if (soilGeometryProbability.SoilGeometry2DName != null && !SoilGeometry2DNamesContains(soilGeometryProbability.SoilGeometry2DName))
{
SoilGeometry2DName soilGeometry2DName = new SoilGeometry2DName();
soilGeometry2DName.Geometry2DName = soilGeometryProbability.SoilGeometry2DName;
SoilGeometry2DNames.Add(soilGeometry2DName);
}
}
}
}
///
/// Updates the locations for scenarios.
///
public void UpdateLocationsForScenarios()
{
foreach (Dike dike in this.Dikes)
{
dike.UpdateLocationsForScenarios();
}
}
///
/// Gets the selected dike.
/// Is a helper property to be able to show the soil table. When more Dikes than one are allowed,
/// this has to become a "real" property set by the onselectionchanged event.
///
///
/// The selected dike.
///
public Dike SelectedDike
{
get
{
if (selectedDike != null)
{
return selectedDike;
}
return dikes.Count > 0 ? dikes[0] : null;
}
set
{
selectedDike = value;
}
}
private bool SoilGeometry2DNamesContains(string Name)
{
foreach (var soilGeometry2DName in SoilGeometry2DNames)
{
if (soilGeometry2DName.Geometry2DName == Name)
return true;
}
return false;
}
public virtual IList Dikes
{
get { return this.dikes; }
set { this.dikes = value; }
}
[XmlIgnore]
public List Locations
{
get
{
if (locations == null)
{
locations = new List();
foreach (Dike dike in this.Dikes)
{
locations.AddRange(dike.Locations);
}
}
return locations;
}
}
public virtual string NumberOfDikes
{
get { return this.dikes.Count.ToString(); }
}
public virtual string Name
{
get { return String.Format(LocalizationManager.GetTranslatedText(this, "WaterBoard")); }
}
public virtual string Description
{
get { return description; }
set { description = value; }
}
public override string ToString()
{
return Name;
}
public string WaterLevelTimeSeriesFileName
{
get { return waterLevelTimeSeriesFileName; }
set
{
waterLevelTimeSeriesFileName = value;
}
}
public Segment GetSegmentByName(string segmentId)
{
Segment segment = this.segments.Where(x => ((x.Name == segmentId))).FirstOrDefault();
return segment;
}
}
}