Index: DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/DikeTest.cs =================================================================== diff -u -r4070 -r4170 --- DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/DikeTest.cs (.../DikeTest.cs) (revision 4070) +++ DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/DikeTest.cs (.../DikeTest.cs) (revision 4170) @@ -19,9 +19,12 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using Deltares.Dam.Data; +using Deltares.Dam.Data.CsvImporters; using Deltares.Geometry; using Deltares.Geotechnics.GeotechnicalGeometry; using Deltares.Geotechnics.Soils; @@ -56,8 +59,10 @@ dike.Name = "Dike"; // Segments - segment1 = new Segment(); - segment1.Name = "Segment1"; + segment1 = new Segment + { + Name = "Segment1" + }; // this.dike.Segments.Add(this.segment1); // Locations @@ -79,8 +84,10 @@ dike.SurfaceLines2.Add(surfaceLine1); // Soil profiles - soilProfile = new SoilProfile1D(); - soilProfile.Name = "SoilProfile1"; + soilProfile = new SoilProfile1D + { + Name = "SoilProfile1" + }; dike.SoilProfiles.Add(soilProfile); // Locations' Segments @@ -209,5 +216,90 @@ Assert.IsTrue(surfaceLine1.HasDike()); } + + [Test] + public void TestFillDataBaseSoilListFromCsvFileWithoutSoilRecords_ThenNoDataBaseSoilsArePresent() + { + var newDike = new Dike(); + newDike.FillDataBaseSoilListFromCsvFile(new List()); + Assert.That(newDike.DatabaseSoils.Count, Is.Zero); + } + + [Test] + public void TestFillDataBaseSoilListFromCsvFileWithoutSoilRecords_ThenDataBaseSoilsAreFilled() + { + var newDike = new Dike(); + + var random = new Random(21); + var soilRecords = new List + { + new() + { + SoilName = "Soil_1", + SoilColor = Color.Black, + SoilType = SoilType.Sand, + SaturatedUnitWeight = random.NextDouble(), + UnsaturatedUnitWeight = random.NextDouble(), + Cohesion = random.NextDouble(), + FrictionAngle = random.NextDouble(), + DiameterD70 = random.NextDouble(), + PermeabilityX = random.NextDouble(), + ShearStrengthModel = ShearStrengthModel.CPhi, + StrengthIncreaseExponent = random.NextDouble(), + RatioSuPc = random.NextDouble(), + UsePop = true, + Pop = random.NextDouble() + }, + new() + { + SoilName = "Soil_2", + SoilColor = Color.White, + SoilType = SoilType.Clay, + SaturatedUnitWeight = random.NextDouble(), + UnsaturatedUnitWeight = random.NextDouble(), + Cohesion = random.NextDouble(), + FrictionAngle = random.NextDouble(), + DiameterD70 = random.NextDouble(), + PermeabilityX = random.NextDouble(), + ShearStrengthModel = ShearStrengthModel.CuCalculated, + StrengthIncreaseExponent = random.NextDouble(), + RatioSuPc = random.NextDouble(), + UsePop = false, + Pop = random.NextDouble() + } + }; + + newDike.FillDataBaseSoilListFromCsvFile(soilRecords); + Assert.That(newDike.DatabaseSoils.Count, Is.EqualTo(2)); + + for (var i = 0; i < newDike.DatabaseSoils.Count; i++) + { + Soil soil = newDike.DatabaseSoils[i]; + CsvImporterSoils.SoilRecord soilRecord = soilRecords[i]; + Assert.That(soil.Name, Is.EqualTo(soilRecord.SoilName)); + Assert.That(soil.Color, Is.EqualTo(soilRecord.SoilColor)); + Assert.That(soil.SoilType, Is.EqualTo(soilRecord.SoilType)); + Assert.That(soil.AbovePhreaticLevel, Is.EqualTo(soilRecord.SaturatedUnitWeight)); + Assert.That(soil.BelowPhreaticLevel, Is.EqualTo(soilRecord.UnsaturatedUnitWeight)); + Assert.That(soil.Cohesion, Is.EqualTo(soilRecord.Cohesion)); + Assert.That(soil.FrictionAngle, Is.EqualTo(soilRecord.FrictionAngle)); + Assert.That(soil.DiameterD70, Is.EqualTo(soilRecord.DiameterD70)); + Assert.That(soil.PermeabKx, Is.EqualTo(soilRecord.PermeabilityX)); + Assert.That(soil.ShearStrengthModel, Is.EqualTo(soilRecord.ShearStrengthModel)); + Assert.That(soil.StrengthIncreaseExponent, Is.EqualTo(soilRecord.StrengthIncreaseExponent)); + Assert.That(soil.RatioCuPc, Is.EqualTo(soilRecord.RatioSuPc)); + switch (i) + { + case 0: + Assert.That(soil.POP, Is.EqualTo(soilRecord.Pop)); + break; + case 1: + Assert.That(soil.POP, Is.NaN); + break; + } + + } + + } } } \ No newline at end of file Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/Dike.cs =================================================================== diff -u -r4169 -r4170 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/Dike.cs (.../Dike.cs) (revision 4169) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/Dike.cs (.../Dike.cs) (revision 4170) @@ -61,7 +61,6 @@ private SoilList soilList; private IList soilProfiles; private string soilDatabaseName = ""; - private List databaseSoils = new (); public Dike() { @@ -91,10 +90,7 @@ public virtual string SoilDatabaseName { - get - { - return soilDatabaseName; - } + get => soilDatabaseName; set { soilDatabaseName = value; @@ -105,72 +101,42 @@ [XmlIgnore] public SoilbaseDB SoilBaseDB { get; set; } /// - /// Gets the locations. + /// Gets the locations. /// /// - /// The locations. + /// The locations. /// public virtual IList Locations { - get - { - return locations; - } - private set - { - locations = value; - } + get => locations; + private set => locations = value; } public IList SurfaceLines2 { get; set; } public virtual IList PL1Lines { - get - { - return pl1Lines; - } - set - { - pl1Lines = value; - } + get => pl1Lines; + set => pl1Lines = value; } public virtual IList SoilProfiles { - get - { - return soilProfiles; - } - set - { - soilProfiles = value; - } + get => soilProfiles; + set => soilProfiles = value; } public virtual SoilList SoilList { - get - { - return soilList; - } - set - { - soilList = value; - } + get => soilList; + set => soilList = value; } [Browsable(false)] public virtual IList Gauges { get; set; } = new List(); [Browsable(false)] public virtual IList GaugePLLines { get; set; } = new List(); - public bool UsesGauges - { - get - { - return GaugePLLines != null && GaugePLLines.Count > 0 && Gauges != null; - } - } + public bool UsesGauges => (GaugePLLines != null) && (GaugePLLines.Count > 0) && (Gauges != null); public virtual List Scenarios { @@ -189,7 +155,7 @@ public string Description { get; set; } = ""; /// - /// Updates the locations for scenarios. + /// Updates the locations for scenarios. /// public void UpdateLocationsForScenarios() { @@ -203,7 +169,7 @@ } /// - /// Updates the name soil database for all locations. + /// Updates the name soil database for all locations. /// public void UpdateLocationsDatabaseName() { @@ -214,7 +180,7 @@ } /// - /// Sorts the locations. + /// Sorts the locations. /// public void SortLocations() { @@ -223,7 +189,7 @@ public void Validate() { - if (Locations == null || Locations.Count < 1) + if ((Locations == null) || (Locations.Count < 1)) { throw new DikeException("The dike ring has no locations defined"); } @@ -245,7 +211,7 @@ public void CreateSoilBase() { - if (SoilDatabaseName == null || !File.Exists(SoilDatabaseName)) + if ((SoilDatabaseName == null) || !File.Exists(SoilDatabaseName)) { throw new DikeException($"The soil database '{SoilDatabaseName}' cannot be found"); } @@ -254,34 +220,34 @@ } /// - /// Read all the soils and their parameters from the database + /// Read all the soils and their parameters from the database /// public void FillDataBaseSoilListFromSoilBase() { using (var geoDatabase = new GeoDatabase(SoilDatabaseName)) { geoDatabase.ReUseSoils = true; SoilList newSoilList = geoDatabase.ReadSoils(soilList.Soils); - databaseSoils = newSoilList.Soils; + DatabaseSoils = newSoilList.Soils; } } /// - /// Read all the soils and their parameters from the database + /// Read all the soils and their parameters from the database /// /// Add 1D-soilprofiles from MGeobase database /// public void AddSoilProfilesFromDB() { - if (SoilDatabaseName == null || !File.Exists(SoilDatabaseName)) + if ((SoilDatabaseName == null) || !File.Exists(SoilDatabaseName)) { throw new DikeException($"The MGeobase database '{SoilDatabaseName}' cannot be found"); } if (soilList.Soils.Count == 0) { FillDataBaseSoilListFromSoilBase(); - soilList.Soils.AddRange(databaseSoils); + soilList.Soils.AddRange(DatabaseSoils); } if (soilList.Soils.Count == 0) @@ -296,9 +262,9 @@ soilProfiles.Add(addedSoilProfile); } } - + /// - /// Add to soil data as read from the csv-file to the dike database + /// Add to soil data as read from the csv-file to the dike database /// public void FillDataBaseSoilListFromCsvFile(IEnumerable soilRecords) { @@ -313,12 +279,12 @@ soil.Name = soilRecord.SoilName; soil.Color = soilRecord.SoilColor; soil.SoilType = soilRecord.SoilType; - + if (soilRecord.SaturatedUnitWeight.HasValue) { soil.AbovePhreaticLevel = soilRecord.SaturatedUnitWeight.Value; } - + if (soilRecord.UnsaturatedUnitWeight.HasValue) { soil.BelowPhreaticLevel = soilRecord.UnsaturatedUnitWeight.Value; @@ -342,9 +308,9 @@ if (soilRecord.PermeabilityX.HasValue) { soil.PermeabKx = soilRecord.PermeabilityX.Value; - } + soil.UseDefaultShearStrengthModel = false; soil.ShearStrengthModel = soilRecord.ShearStrengthModel; if (soilRecord.StrengthIncreaseExponent.HasValue) @@ -362,12 +328,12 @@ soil.POP = soilRecord.Pop.Value; } - databaseSoils.Add(soil); + DatabaseSoils.Add(soil); } } /// - /// Adapt data so it is consistent + /// Adapt data so it is consistent /// public List MakeDataConsistent() { @@ -442,11 +408,13 @@ } } + internal List DatabaseSoils { get; private set; } = new(); + /// - /// 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). + /// 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() @@ -456,7 +424,7 @@ // 1D profiles) but that are not found in the soil database because that are errors foreach (Soil soil in soilList.Soils) { - Soil fs = databaseSoils.Find(t => String.Equals(t.Name, soil.Name, StringComparison.CurrentCultureIgnoreCase)); + Soil fs = DatabaseSoils.Find(t => string.Equals(t.Name, soil.Name, StringComparison.CurrentCultureIgnoreCase)); if (fs == null) { errorSoils.Add(soil); @@ -471,7 +439,7 @@ // 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) + foreach (Soil soil in DatabaseSoils) { Soil existingSoil = soilList.GetSoilByName(soil.Name); if (existingSoil == null) @@ -488,7 +456,7 @@ } /// - /// Removes all locations which have profiles that have invalid soils + /// Removes all locations which have profiles that have invalid soils /// private List DeleteLocationsWithProfilesWithUnknownSoils(List invalidSoils) { @@ -503,14 +471,14 @@ if (location.Segment == null) { isInValid = true; - message = String.Format(LocalizationManager.GetTranslatedText(GetType(), "LocationWitNameHasNoSegment"), location.Name); + 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); + message = string.Format(LocalizationManager.GetTranslatedText(GetType(), "LocationHasProfileWithInvalidSoils"), location.Name, soilProf, invSoil); } } @@ -530,8 +498,8 @@ } /// - /// 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. + /// 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. /// /// /// @@ -546,7 +514,7 @@ { foreach (Soil invalidSoil in invalidSoils) { - SoilLayer1D fl = spp.SoilProfile.Layers.Find(l => String.Equals(l.Soil.Name, invalidSoil.Name, StringComparison.CurrentCultureIgnoreCase)); + SoilLayer1D fl = spp.SoilProfile.Layers.Find(l => string.Equals(l.Soil.Name, invalidSoil.Name, StringComparison.CurrentCultureIgnoreCase)); if (fl != null) { @@ -561,7 +529,7 @@ } /// - /// Delete all locations without surfacelines + /// Delete all locations without surfacelines /// private List DeleteLocationsWithoutSurfaceLines() { @@ -578,7 +546,7 @@ { string locationHasNoSurfaceLine = LocalizationManager.GetTranslatedText(GetType(), "LocationHasNoSurfaceLine"); logMessages.Add(new LogMessage(LogMessageType.Warning, this, - String.Format(locationHasNoSurfaceLine, deletedLocation.Name))); + string.Format(locationHasNoSurfaceLine, deletedLocation.Name))); } Locations = newLocations; @@ -590,26 +558,22 @@ private IList surfaceLines; /// - /// Gets or sets all surface lines instances associated with this dike. + /// Gets or sets all surface lines instances associated with this dike. /// - /// Composite owner of all that are part of the - /// application that are associated with this dike. + /// + /// Composite owner of all that are part of the + /// application that are associated with this dike. + /// [Obsolete("Do not use this member; Only exists for backwards compatibility.", true)] public virtual IList SurfaceLines { - get - { - return surfaceLines; - } - set - { - surfaceLines = value; - } + get => surfaceLines; + set => surfaceLines = value; } /// - /// Performs backwards compatibility conversion from old-style surfaceline to new-style - /// surfaceline, and ensures that shared references are set correctly. + /// Performs backwards compatibility conversion from old-style surfaceline to new-style + /// surfaceline, and ensures that shared references are set correctly. /// /// Persisted version of the old-style surfaceline. private void ConvertAddedOldSurfaceLineToNewFormat(SurfaceLine argument)