// Copyright (C) Stichting Deltares 2025. All rights reserved.
//
// This file is part of the application DAM - UI.
//
// 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;
using Deltares.Standard.Validation;
namespace Deltares.Dam.Data;
public class WaterBoard : IVisibleEnabled, IDisposable
{
private readonly FeatureRepository backgroundRepository;
private List locations;
private IList featureList;
private IList segments;
private string waterLevelTimeSeriesFileName;
private Dike dike;
public WaterBoard()
{
featureList = new List();
backgroundRepository = new FeatureRepository();
segments = new List();
}
public virtual IList Segments
{
get
{
return segments;
}
set
{
segments = value;
}
}
///
/// Gets the 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 dike.
///
public Dike Dike
{
get
{
return dike;
}
set
{
DataEventPublisher.BeforeChange(this, x => x.Dike);
dike = value;
DataEventPublisher.AfterChange(this, x => x.Dike);
}
}
public virtual IList BackgroundRepositoryFeatures
{
get
{
return featureList;
}
set
{
featureList = value;
FillBackGroundRepos();
}
}
[XmlIgnore]
[Browsable(false)]
[ReadOnly(true)]
[Label("Locations")]
public List Locations
{
get
{
if (locations == null)
{
locations = new List();
if (Dike != null)
{
locations.AddRange(Dike.Locations);
}
}
return locations;
}
}
public virtual string Name
{
get
{
return String.Format(LocalizationManager.GetTranslatedText(this, "WaterBoard"));
}
}
public virtual string Description { get; set; } = "";
[XmlIgnore] [Browsable(false)] public IVisibleEnabledProvider VisibleEnabledProvider { get; set; }
[Label("Waterlevel timeseries filename")]
public string WaterLevelTimeSeriesFileName
{
get
{
return waterLevelTimeSeriesFileName;
}
set
{
DataEventPublisher.BeforeChange(this, "WaterLevelTimeSeriesFileName");
waterLevelTimeSeriesFileName = value;
DataEventPublisher.AfterChange(this, "WaterLevelTimeSeriesFileName");
}
}
public void FillFeatureList()
{
foreach (IFeature feature in backgroundRepository.Features)
{
var featureStr = new BackgroundRepositoryFeature();
featureStr.Feature = feature.WktFormat;
featureList.Add(featureStr);
}
}
public void AddBackgroundGeometry(IFeature geometry)
{
backgroundRepository.Add(geometry);
}
public Segment GetSegmentByName(string segmentId)
{
Segment segment = segments.Where(x => ((x.Name == segmentId))).FirstOrDefault();
return segment;
}
public override string ToString()
{
return Name;
}
public void Dispose()
{
Dike?.Dispose();
}
public bool IsVisible(string property)
{
switch (property)
{
case "Dike": return VisibleEnabledProvider != null && VisibleEnabledProvider.IsVisible(this, "Dike");
case "WaterLevelTimeSeriesFileName": return Location.DamProjectType == DamProjectType.DamLiveConfiguration;
default: return true;
}
}
public bool IsEnabled(string property)
{
return true;
}
private void FillBackGroundRepos()
{
if (featureList != null)
{
backgroundRepository.Clear();
foreach (BackgroundRepositoryFeature s in featureList)
{
backgroundRepository.Add(Feature.Create(s.Feature));
}
}
}
}