Index: DamEngine/trunk/src/Deltares.DamEngine.Data/General/Dike.cs =================================================================== diff -u -r4000 -r4052 --- DamEngine/trunk/src/Deltares.DamEngine.Data/General/Dike.cs (.../Dike.cs) (revision 4000) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/General/Dike.cs (.../Dike.cs) (revision 4052) @@ -34,416 +34,415 @@ using Deltares.DamEngine.Data.Standard.Logging; using Deltares.DamEngine.Data.Standard.Validation; -namespace Deltares.DamEngine.Data.General +namespace Deltares.DamEngine.Data.General; + +/// +/// Class for the dike parameter names +/// +public class DikeParameterNames { /// - /// Class for the dike parameter names + /// The map for soilgeometries2d /// - public class DikeParameterNames - { - /// - /// The map for soilgeometries2d - /// - public const string MapForSoilGeometries2D = "MapForSoilGeometries2D"; - } + public const string MapForSoilGeometries2D = "MapForSoilGeometries2D"; +} +/// +/// Class holding all info for a Dike. +/// +public class Dike +{ + private IList locations; + + private IList pl1Lines; + private SoilList soilList; + private IList soilProfiles; + private IList soilProfiles2D; + private readonly List databaseSoils = new List(); + /// - /// Class holding all info for a Dike. + /// Initializes a new instance of the class. /// - public class Dike + public Dike() { - private IList locations; + Name = "Dijkring"; + MapForSoilGeometries2D = ""; - private IList pl1Lines; - private SoilList soilList; - private IList soilProfiles; - private IList soilProfiles2D; - private readonly List databaseSoils = new List(); + locations = new List(); + soilProfiles = new List(); + soilProfiles2D = new List(); + // this.surfaceLines = new DelegatedList { AddMethod = ConvertAddedOldSurfaceLineToNewFormat }; + SurfaceLines2 = new List(); + pl1Lines = new List(); + soilList = new SoilList(); + IsRemoveStiFiles = true; + } - /// - /// Initializes a new instance of the class. - /// - public Dike() - { - Name = "Dijkring"; - MapForSoilGeometries2D = ""; + public virtual string MapForSoilGeometries2D { get; set; } - locations = new List(); - soilProfiles = new List(); - soilProfiles2D = new List(); - // this.surfaceLines = new DelegatedList { AddMethod = ConvertAddedOldSurfaceLineToNewFormat }; - SurfaceLines2 = new List(); - pl1Lines = new List(); - soilList = new SoilList(); - IsRemoveStiFiles = true; - } + public bool IsRemoveStiFiles { get; set; } - public virtual string MapForSoilGeometries2D { get; set; } + public MStabShearStrength ShearStrengthModel { get; set; } - public bool IsRemoveStiFiles { get; set; } + public virtual string Name { get; set; } - public MStabShearStrength ShearStrengthModel { get; set; } - - public virtual string Name { get; set; } - - /// - /// Gets the locations. - /// - /// - /// The locations. - /// - public virtual IList Locations + /// + /// Gets the locations. + /// + /// + /// The locations. + /// + public virtual IList Locations + { + get { - get - { - return locations; - } - private set - { - locations = value; - } + return locations; } + private set + { + locations = value; + } + } - public IList SurfaceLines2 { get; set; } + public IList SurfaceLines2 { get; set; } - public virtual IList PL1Lines + public virtual IList PL1Lines + { + get { - get - { - return pl1Lines; - } - set - { - pl1Lines = value; - } + return pl1Lines; } + set + { + pl1Lines = value; + } + } - public virtual IList SoilProfiles + public virtual IList SoilProfiles + { + get { - get - { - return soilProfiles; - } - set - { - soilProfiles = value; - } + return soilProfiles; } + set + { + soilProfiles = value; + } + } - /// - /// Gets or sets the soilprofiles2d. - /// - /// - /// The soilprofiles2d. - /// - public virtual IList SoilProfiles2D + /// + /// Gets or sets the soilprofiles2d. + /// + /// + /// The soilprofiles2d. + /// + public virtual IList SoilProfiles2D + { + get { - get - { - return soilProfiles2D; - } - set - { - soilProfiles2D = value; - } + return soilProfiles2D; } + set + { + soilProfiles2D = value; + } + } - public virtual SoilList SoilList + public virtual SoilList SoilList + { + get { - get - { - return soilList; - } - set - { - soilList = value; - } + return soilList; } + set + { + soilList = value; + } + } - [Browsable(false)] public virtual IList Gauges { get; set; } = new List(); + [Browsable(false)] public virtual IList Gauges { get; set; } = new List(); - [Browsable(false)] public virtual IList GaugePlLines { get; set; } = new List(); + [Browsable(false)] public virtual IList GaugePlLines { get; set; } = new List(); - public bool UsesGauges + public bool UsesGauges + { + get { - get - { - return GaugePlLines != null && GaugePlLines.Count > 0 && Gauges != null; - } + return GaugePlLines != null && GaugePlLines.Count > 0 && Gauges != null; } + } - public virtual List Scenarios + public virtual List Scenarios + { + get { - get + var scenarios = new List(); + foreach (Location location in Locations) { - var scenarios = new List(); - foreach (Location location in Locations) - { - scenarios.AddRange(location.Scenarios); - } - - return scenarios; + scenarios.AddRange(location.Scenarios); } + + return scenarios; } + } - public string Description { get; set; } = ""; + public string Description { get; set; } = ""; - /// - /// Gets or sets the input time serie collection. - /// - /// - /// Input time series for operational use - /// - public TimeSerieCollection InputTimeSerieCollection { get; set; } = null; + /// + /// Gets or sets the input time serie collection. + /// + /// + /// Input time series for operational use + /// + public TimeSerieCollection InputTimeSerieCollection { get; set; } = null; - /// - /// Sorts the locations. - /// - public void SortLocations() + /// + /// Sorts the locations. + /// + public void SortLocations() + { + locations = Locations.OrderBy(o => o.Name).ToList(); + } + + public void Validate(bool isOperational) + { + if (Locations == null || Locations.Count < 1) { - locations = Locations.OrderBy(o => o.Name).ToList(); + throw new DikeException("The dike ring has no locations defined"); } - public void Validate(bool isOperational) + foreach (Location location in Locations) { - if (Locations == null || Locations.Count < 1) + if (location.SurfaceLine != null) { - throw new DikeException("The dike ring has no locations defined"); + var validator = new SurfaceLine2Validator(); + ValidationResult[] validationResults = validator.ValidateCharacteristicPointsAreOrdered(location.SurfaceLine) + .Concat(validator.ValidateGeometryPointsAreOrdered(location.SurfaceLine)).ToArray(); + if (validationResults.Length > 0) + { + throw new SurfaceLineException(validationResults[0].Text); + } } - foreach (Location location in Locations) + if (location.Scenarios.Count < 1) { - if (location.SurfaceLine != null) - { - var validator = new SurfaceLine2Validator(); - ValidationResult[] validationResults = validator.ValidateCharacteristicPointsAreOrdered(location.SurfaceLine) - .Concat(validator.ValidateGeometryPointsAreOrdered(location.SurfaceLine)).ToArray(); - if (validationResults.Length > 0) - { - throw new SurfaceLineException(validationResults[0].Text); - } - } + throw new DikeException("Location " + location.Name + " has no scenarios, at least one scenario is required."); + } - if (location.Scenarios.Count < 1) + if (isOperational) + { + if (location.Scenarios.Count > 1) { - throw new DikeException("Location " + location.Name + " has no scenarios, at least one scenario is required."); + throw new DikeException(string.Format( + "For Operational (DamLive), location {0} has {1} scenarios but only one is allowed!", location.Name, location.Scenarios.Count)); } - if (isOperational) + if (location.SensorLocation != null) { - if (location.Scenarios.Count > 1) + foreach (Sensor sensorArray in location.SensorLocation.SensorGroup.SensorArray) { - throw new DikeException(string.Format( - "For Operational (DamLive), location {0} has {1} scenarios but only one is allowed!", location.Name, location.Scenarios.Count)); - } - - if (location.SensorLocation != null) - { - foreach (Sensor sensorArray in location.SensorLocation.SensorGroup.SensorArray) + if (sensorArray.RelativeLocation < 0) { - if (sensorArray.RelativeLocation < 0) - { - throw new DikeException(string.Format( - "For Operational (DamLive), location {0} has sensor which are not relative to the starting point.", - location.Name)); - } + throw new DikeException(string.Format( + "For Operational (DamLive), location {0} has sensor which are not relative to the starting point.", + location.Name)); } } } } } + } - /// - /// Adapt data so it is consistent - /// - public List MakeDataConsistent() - { - List errorSoils = TryToMakeSoilDataConsistent(); - var logMessages = new List(); - // Delete all locations without surfaceline - logMessages.AddRange(DeleteLocationsWithoutSurfaceLines()); - // Delete all locations that have profiles (in their segment) which hold soils - // that are not in the soil database and so have no parameters. - logMessages.AddRange(DeleteLocationsWithProfilesWithUnknownSoils(errorSoils)); - return logMessages; - } + /// + /// Adapt data so it is consistent + /// + public List MakeDataConsistent() + { + List errorSoils = TryToMakeSoilDataConsistent(); + var logMessages = new List(); + // Delete all locations without surfaceline + logMessages.AddRange(DeleteLocationsWithoutSurfaceLines()); + // Delete all locations that have profiles (in their segment) which hold soils + // that are not in the soil database and so have no parameters. + logMessages.AddRange(DeleteLocationsWithProfilesWithUnknownSoils(errorSoils)); + return logMessages; + } - public Dictionary GetParametersAsNameValuePairs() + public Dictionary GetParametersAsNameValuePairs() + { + var nameValuePairs = new Dictionary(); + nameValuePairs.Add(DikeParameterNames.MapForSoilGeometries2D, MapForSoilGeometries2D); + return nameValuePairs; + } + + public void SetParameterFromNameValuePair(string parameterName, string parameterValue) + { + if (parameterName.Equals(DikeParameterNames.MapForSoilGeometries2D)) { - var nameValuePairs = new Dictionary(); - nameValuePairs.Add(DikeParameterNames.MapForSoilGeometries2D, MapForSoilGeometries2D); - return nameValuePairs; + MapForSoilGeometries2D = parameterValue; } + } - public void SetParameterFromNameValuePair(string parameterName, string parameterValue) + public void UpdateLocation(Location location) + { + location.SoilList = SoilList; + if (location.StabilityOptions != null) { - if (parameterName.Equals(DikeParameterNames.MapForSoilGeometries2D)) - { - MapForSoilGeometries2D = parameterValue; - } + location.StabilityOptions.SoilGeometries2DPath = MapForSoilGeometries2D; } - public void UpdateLocation(Location location) + location.Gauges.Clear(); + location.Gauges.AddRange(Gauges); + + location.GaugePlLines.Clear(); + location.GaugePlLines.AddRange(GaugePlLines); + } + + public override string ToString() + { + return Name; + } + + /// + /// Tries to make the soil data as read for 1D profiles consistent with the data in the soil database. + /// In the end we have a neat soil list with parameters for every soil as read from the database. + /// We might have a list with errors (soils that were not to be found in the database so soils for which + /// no parameters could be found). + /// + /// + private List TryToMakeSoilDataConsistent() + { + var errorSoils = new List(); + // Fill the list of errorSoils with soils that are in the current soillist (as result of importing + // 1D profiles) but that are not found in the soil database because that are errors + foreach (Soil soil in soilList.Soils) { - location.SoilList = SoilList; - if (location.StabilityOptions != null) + Soil fs = databaseSoils.Find(t => String.Equals(t.Name, soil.Name, StringComparison.CurrentCultureIgnoreCase)); + if (fs == null) { - location.StabilityOptions.SoilGeometries2DPath = MapForSoilGeometries2D; + errorSoils.Add(soil); } - - location.Gauges.Clear(); - location.Gauges.AddRange(Gauges); - - location.GaugePlLines.Clear(); - location.GaugePlLines.AddRange(GaugePlLines); } - public override string ToString() + // Remove the error soils form the list + foreach (Soil errorSoil in errorSoils) { - return Name; + soilList.Soils.Remove(errorSoil); } - /// - /// Tries to make the soil data as read for 1D profiles consistent with the data in the soil database. - /// In the end we have a neat soil list with parameters for every soil as read from the database. - /// We might have a list with errors (soils that were not to be found in the database so soils for which - /// no parameters could be found). - /// - /// - private List TryToMakeSoilDataConsistent() + // Get the parameters for every soil in the now proper soil list from the database. Add soils + // that are in the database but not yet in the soil list. + foreach (Soil soil in databaseSoils) { - var errorSoils = new List(); - // Fill the list of errorSoils with soils that are in the current soillist (as result of importing - // 1D profiles) but that are not found in the soil database because that are errors - foreach (Soil soil in soilList.Soils) + Soil existingSoil = soilList.GetSoilByName(soil.Name); + if (existingSoil == null) { - Soil fs = databaseSoils.Find(t => String.Equals(t.Name, soil.Name, StringComparison.CurrentCultureIgnoreCase)); - if (fs == null) - { - errorSoils.Add(soil); - } + soilList.Soils.Add(soil); } - - // Remove the error soils form the list - foreach (Soil errorSoil in errorSoils) + else { - soilList.Soils.Remove(errorSoil); + existingSoil.Assign(soil); } - - // Get the parameters for every soil in the now proper soil list from the database. Add soils - // that are in the database but not yet in the soil list. - foreach (Soil soil in databaseSoils) - { - Soil existingSoil = soilList.GetSoilByName(soil.Name); - if (existingSoil == null) - { - soilList.Soils.Add(soil); - } - else - { - existingSoil.Assign(soil); - } - } - - return errorSoils; } - /// - /// Removes all locations which have profiles that have invalid soils - /// - private List DeleteLocationsWithProfilesWithUnknownSoils(List invalidSoils) + return errorSoils; + } + + /// + /// Removes all locations which have profiles that have invalid soils + /// + private List DeleteLocationsWithProfilesWithUnknownSoils(List invalidSoils) + { + var logMessages = new List(); + var invalidLocations = new List(); + string soilProf; + string invSoil; + foreach (Location location in locations) { - var logMessages = new List(); - var invalidLocations = new List(); - string soilProf; - string invSoil; - foreach (Location location in locations) + bool isInValid; + var message = ""; + if (location.Segment == null) { - bool isInValid; - var message = ""; - if (location.Segment == null) - { - isInValid = true; - message = String.Format(LocalizationManager.GetTranslatedText(GetType(), "LocationWitNameHasNoSegment"), location.Name); - } - else - { - isInValid = DoesLocationHaveInvalidSoils(invalidSoils, location, out soilProf, out invSoil); - if (isInValid) - { - message = String.Format(LocalizationManager.GetTranslatedText(GetType(), "locationHasProfileWithInvalidSoils"), location.Name, soilProf, invSoil); - } - } - + isInValid = true; + message = String.Format(LocalizationManager.GetTranslatedText(GetType(), "LocationWitNameHasNoSegment"), location.Name); + } + else + { + isInValid = DoesLocationHaveInvalidSoils(invalidSoils, location, out soilProf, out invSoil); if (isInValid) { - invalidLocations.Add(location); - logMessages.Add(new LogMessage(LogMessageType.Warning, this, message)); + message = String.Format(LocalizationManager.GetTranslatedText(GetType(), "locationHasProfileWithInvalidSoils"), location.Name, soilProf, invSoil); } } - foreach (Location invalidLocation in invalidLocations) + if (isInValid) { - locations.Remove(invalidLocation); + invalidLocations.Add(location); + logMessages.Add(new LogMessage(LogMessageType.Warning, this, message)); } + } - return logMessages; + foreach (Location invalidLocation in invalidLocations) + { + locations.Remove(invalidLocation); } - /// - /// Checks wether a location (or rather the soilprofiles in the segement of the location) contains invalid soils. - /// A soil is hereby considered invalid if it is not found in the database. - /// - /// - /// - /// - /// - /// - private bool DoesLocationHaveInvalidSoils(List invalidSoils, Location location, out string soilProf, out string invSoil) + return logMessages; + } + + /// + /// Checks wether a location (or rather the soilprofiles in the segement of the location) contains invalid soils. + /// A soil is hereby considered invalid if it is not found in the database. + /// + /// + /// + /// + /// + /// + private bool DoesLocationHaveInvalidSoils(List invalidSoils, Location location, out string soilProf, out string invSoil) + { + soilProf = " "; + invSoil = " "; + foreach (SoilGeometryProbability spp in location.Segment.SoilProfileProbabilities) { - soilProf = " "; - invSoil = " "; - foreach (SoilGeometryProbability spp in location.Segment.SoilProfileProbabilities) + foreach (Soil invalidSoil in invalidSoils) { - foreach (Soil invalidSoil in invalidSoils) - { - SoilLayer1D fl = spp.SoilProfile1D.Layers.Find(l => String.Equals(l.Soil.Name, invalidSoil.Name, StringComparison.CurrentCultureIgnoreCase)); + SoilLayer1D fl = spp.SoilProfile1D.Layers.Find(l => String.Equals(l.Soil.Name, invalidSoil.Name, StringComparison.CurrentCultureIgnoreCase)); - if (fl != null) - { - soilProf = spp.SoilProfile1D.Name; - invSoil = invalidSoil.Name; - return true; - } + if (fl != null) + { + soilProf = spp.SoilProfile1D.Name; + invSoil = invalidSoil.Name; + return true; } } - - return false; } - /// - /// Delete all locations without surfacelines - /// - private List DeleteLocationsWithoutSurfaceLines() - { - var logMessages = new List(); + return false; + } - //Add all locations with valid surfaceline - var newLocations = new List(); - newLocations.AddRange(Locations.Where(loc => loc.SurfaceLine != null)); + /// + /// Delete all locations without surfacelines + /// + private List DeleteLocationsWithoutSurfaceLines() + { + var logMessages = new List(); - // Report which locations are not added because no valid surfaceline is found - var deletedLocations = new List(); - deletedLocations.AddRange(Locations.Where(loc => loc.SurfaceLine == null)); - foreach (Location deletedLocation in deletedLocations) - { - string locationHasNoSurfaceLine = LocalizationManager.GetTranslatedText(GetType(), "LocationHasNoSurfaceLine"); - logMessages.Add(new LogMessage(LogMessageType.Warning, this, - String.Format(locationHasNoSurfaceLine, deletedLocation.Name))); - } + //Add all locations with valid surfaceline + var newLocations = new List(); + newLocations.AddRange(Locations.Where(loc => loc.SurfaceLine != null)); - Locations = newLocations; - return logMessages; + // Report which locations are not added because no valid surfaceline is found + var deletedLocations = new List(); + deletedLocations.AddRange(Locations.Where(loc => loc.SurfaceLine == null)); + foreach (Location deletedLocation in deletedLocations) + { + string locationHasNoSurfaceLine = LocalizationManager.GetTranslatedText(GetType(), "LocationHasNoSurfaceLine"); + logMessages.Add(new LogMessage(LogMessageType.Warning, this, + String.Format(locationHasNoSurfaceLine, deletedLocation.Name))); } + + Locations = newLocations; + return logMessages; } } \ No newline at end of file