//-----------------------------------------------------------------------
//
// Copyright (c) 2011 Deltares. All rights reserved.
//
// J. Bokma
// j.bokma@deltares.nl
// 02-02-2011
// n.a.
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Xml.Serialization;
using Deltares.DamEngine.Data.Standard.Language;
namespace Deltares.DamEngine.Data.General
{
public class WaterBoard : IDisposable
{
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;
}
public void Dispose()
{
foreach (var dike in Dikes)
{
dike.Dispose();
}
}
}
}