// Copyright (C) Stichting Deltares 2018. All rights reserved.
//
// This file is part of the application DAM - Clients Library.
//
// DAM - UI is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU 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.ComponentModel;
using System.Linq;
using System.Xml.Serialization;
using Deltares.Maps;
using Deltares.Standard;
using Deltares.Standard.Attributes;
using Deltares.Standard.EventPublisher;
using Deltares.Standard.Language;
namespace Deltares.Dam.Data
{
public class WaterBoard : IVisibleEnabled, IDisposable
{
private string description = "";
private IList dikes;
private List locations = null;
private readonly FeatureRepository backgroundRepository;
private IList featureList = null;
private IList segments;
private IList soilgeometry2DNames;
private string waterLevelTimeSeriesFileName;
private IVisibleEnabledProvider visibleEnabledProvider;
private Dike selectedDike;
public WaterBoard()
{
this.dikes = new List();
this.featureList = new List();
this.backgroundRepository = new FeatureRepository();
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);
}
}
}
}
public void FillFeatureList()
{
foreach (var feature in backgroundRepository.Features)
{
BackgroundRepositoryFeature featureStr = new BackgroundRepositoryFeature();
featureStr.Feature = feature.WktFormat;
featureList.Add(featureStr);
}
}
///
/// 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
{
DataEventPublisher.BeforeChange(this, x => x.SelectedDike);
selectedDike = value;
DataEventPublisher.AfterChange(this, x => x.SelectedDike);
}
}
private bool SoilGeometry2DNamesContains(string Name)
{
foreach (var soilGeometry2DName in SoilGeometry2DNames)
{
if (soilGeometry2DName.Geometry2DName == Name)
return true;
}
return false;
}
private void FillBackGroundRepos()
{
if (featureList != null)
{
backgroundRepository.Clear();
foreach (BackgroundRepositoryFeature s in featureList)
{
backgroundRepository.Add(Feature.Create(s.Feature));
}
}
}
public virtual IList BackgroundRepositoryFeatures
{
get
{
return this.featureList;
}
set
{
this.featureList = value;
FillBackGroundRepos();
}
}
public virtual IList Dikes
{
get { return this.dikes; }
set { this.dikes = value; }
}
[XmlIgnore]
[Browsable(false)]
[ReadOnly(true)]
[Label("Locations")]
public List Locations
{
get
{
if (locations == null)
{
locations = new List();
foreach (Dike dike in this.Dikes)
{
locations.AddRange(dike.Locations);
}
}
return locations;
}
}
[Label("Number of Dikes")]
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 bool IsVisible(string property)
{
switch (property)
{
case "SelectedDike": return visibleEnabledProvider != null && visibleEnabledProvider.IsVisible(this, "SelectedDike");
case "WaterLevelTimeSeriesFileName": return Location.DamProjectType == DamProjectType.Calamity;
default : return true;
}
}
[XmlIgnore]
[Browsable(false)]
public IVisibleEnabledProvider VisibleEnabledProvider
{
get { return visibleEnabledProvider; }
set { visibleEnabledProvider = value; }
}
public bool IsEnabled(string property)
{
return true;
}
public void AddBackgroundGeometry(IFeature geometry)
{
this.backgroundRepository.Add(geometry);
}
[Label("Waterlevel timeseries filename")]
public string WaterLevelTimeSeriesFileName
{
get { return waterLevelTimeSeriesFileName; }
set
{
DataEventPublisher.BeforeChange(this, "WaterLevelTimeSeriesFileName");
waterLevelTimeSeriesFileName = value;
DataEventPublisher.AfterChange(this, "WaterLevelTimeSeriesFileName");
}
}
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();
}
}
}
}