// Copyright (C) Stichting Deltares 2018. 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 Deltares.DamEngine.Data.General.Results;
using Deltares.DamEngine.Data.General.Sensors;
using Deltares.DamEngine.Data.General.TimeSeries;
using Deltares.DamEngine.Data.RegionalAssessmentResults;
using Deltares.DamEngine.Data.Standard.Language;
using Deltares.DamEngine.Data.Standard.Logging;
using Deltares.DamEngine.Data.Standard.Validation;
namespace Deltares.DamEngine.Data.General
{
public class DamProjectData
{
private IList segments;
private Dike dike;
private DamProjectCalculationSpecification damProjectCalculationSpecification;
private DikeJob dikeJob;
private DamProjectType damProjectType = DamProjectType.Operational;
private List jobs = new List();
private List designCalculations;
private TimeSerieCollection outputTimeSerieCollection = null;
private SensorData sensorData;
private string calculationMap = "";
private string projectPath = "";
private int maxCalculationCores = 1;
///
/// Gets or sets the calculation messages.
///
///
/// The calculation messages.
///
public List CalculationMessages { get; set; } = null;
///
/// Gets or sets the output time serie collection.
///
///
/// Output time series for operational use
///
public TimeSerieCollection OutputTimeSerieCollection
{
get
{
return outputTimeSerieCollection;
}
set
{
outputTimeSerieCollection = value;
}
}
///
/// Constructor
///
public DamProjectData()
{
dikeJob = null;
damProjectCalculationSpecification = new DamProjectCalculationSpecification();
dike = new Dike();
segments = new List();
}
///
/// Gets the name.
///
///
/// The name.
///
public virtual string Name
{
get { return String.Format(LocalizationManager.GetTranslatedText(this, "WaterBoard")); }
}
///
/// Gets or sets the segments.
///
///
/// The segments.
///
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 selected dike.
///
public Dike Dike
{
get
{
return dike;
}
set
{
dike = value;
}
}
///
/// calculation specification for the project
///
/// Composite relationship
[Validate]
public DamProjectCalculationSpecification DamProjectCalculationSpecification
{
get { return damProjectCalculationSpecification; }
set { damProjectCalculationSpecification = value; }
}
public virtual DamJob DikeJob
{
get
{
if (dikeJob == null)
{
dikeJob = new DikeJob(dike);
foreach (Location location in dike.Locations)
{
LocationJob locationJob = new LocationJob(location);
dikeJob.Jobs.Add(locationJob);
}
}
return dikeJob;
}
set { dikeJob = value as DikeJob; }
}
///
/// Gets or sets the type of the dam project.
///
///
/// The type of the dam project.
///
public virtual DamProjectType DamProjectType
{
get { return damProjectType; }
set
{
bool modified = damProjectType != value;
damProjectType = value;
Location.DamProjectType = value;
DamFailureMechanismeCalculationSpecification.DamProjectType = value;
if (modified)
{
LocationJob.DamProjectType = damProjectType;
}
}
}
///
/// Gets or sets the design calculations.
///
///
/// The design calculations.
///
public List DesignCalculations
{
get
{
return designCalculations;
}
set
{
designCalculations = value;
}
}
///
/// Gets or sets the location jobs.
///
///
/// The location jobs.
///
public List LocationJobs
{
get
{
if (jobs.Count == 0 && dikeJob != null)
{
foreach (LocationJob locationJob in dikeJob.Jobs)
{
jobs.Add(locationJob);
}
}
return jobs;
}
set
{
jobs = value;
}
}
///
/// Gets or sets the project path.
///
///
/// The project path.
///
public string ProjectPath
{
get { return projectPath; }
set { projectPath = value ?? ""; }
}
///
/// Gets or sets the calculation map.
/// This does not include a full path but can include a relative path
///
///
/// The calculation map.
///
public string CalculationMap
{
get { return calculationMap; }
set { calculationMap = value?? ""; }
}
///
/// Gets or sets the maximum calculation cores.
///
///
/// The maximum calculation cores.
///
public int MaxCalculationCores {
get
{
return maxCalculationCores;
}
set
{
maxCalculationCores = value;
}
}
///
/// Gets or sets the sensor data.
///
///
/// The sensor data.
///
public SensorData SensorData
{
get { return sensorData; }
set { sensorData = value; }
}
public EvaluationJob GetEvaluationJob()
{
EvaluationJob evaluationJob = new EvaluationJob
{
DikeName = dike.Name
};
foreach (var locationJob in LocationJobs)
{
evaluationJob.Locations.Add(locationJob.Location);
}
return evaluationJob;
}
///
/// Returns a that represents this instance.
///
///
/// A that represents this instance.
///
public override string ToString()
{
return Name;
}
///
/// Fills the overall sensor data.
///
public void FillOverallSensorData()
{
if (sensorData != null)
{
sensorData.Sensors.Clear();
sensorData.SensorGroups.Clear();
sensorData.SensorLocations.Clear();
}
else
{
sensorData = new SensorData();
}
foreach (var location in dike.Locations)
{
var sensorLocation = location.SensorLocation;
foreach (var sensor in sensorLocation.Sensors )
{
if (sensorData.GetSensorById(sensor.ID) == null)
{
sensorData.Sensors.Add(sensor);
}
}
if (sensorData.GetGroupById(sensorLocation.SensorGroup.ID) == null && sensorLocation.SensorGroup.ID >= 0)
{
sensorLocation.SensorGroup.PickSensors = sensorData.Sensors;
sensorData.SensorGroups.Add(sensorLocation.SensorGroup);
}
if (sensorData.GetSensorLocationByLocationName(sensorLocation.LocationName) == null)
{
sensorData.SensorLocations.Add(sensorLocation);
}
}
}
}
}