Index: src/Deltares.DSoilModel.Forms/DSoilModelPlugin.cs =================================================================== diff -u -r385 -r391 --- src/Deltares.DSoilModel.Forms/DSoilModelPlugin.cs (.../DSoilModelPlugin.cs) (revision 385) +++ src/Deltares.DSoilModel.Forms/DSoilModelPlugin.cs (.../DSoilModelPlugin.cs) (revision 391) @@ -446,6 +446,27 @@ private void DataEventPublisherOnDataListModified(object sender, PublishEventArgs publishEventArgs) { + + if (sender is List) + { + var args = publishEventArgs as DataListModifiedArgs; + if (args != null && (args.Action == ListModifyAction.Add || args.Action == ListModifyAction.Insert) && publishEventArgs.Objects.Length > 0) + { + // handle the case where a new soil is added to the materials table + foreach (var item in publishEventArgs.Objects) + { + var soil = item as Soil; + if (soil != null) + { + if (soil.GetOrdinaryParameters().Count == 0 && soil.GetStochasticParameters().Count == 0) + { + project.SetSoilDefaults(soil); + } + } + } + } + } + if (sender is List) { mainForm.DynamicTableControl.GetTable(typeof(SurfaceLine2)).Refresh(); Index: src/Deltares.DSoilModel.Data/DSoilModelProject.cs =================================================================== diff -u -r362 -r391 --- src/Deltares.DSoilModel.Data/DSoilModelProject.cs (.../DSoilModelProject.cs) (revision 362) +++ src/Deltares.DSoilModel.Data/DSoilModelProject.cs (.../DSoilModelProject.cs) (revision 391) @@ -415,12 +415,14 @@ } }); } - // missing soils may have been added ? + // missing soils may have been added as new soil() ? if (Soils.Soils.Count > soilsCount) { - DataEventPublisher.DataListModified(Soils.Soils); + for (int i = soilsCount; i < Soils.Soils.Count; i++) + { + SetSoilDefaults(Soils.Soils[i]); + } } - } /// @@ -688,6 +690,8 @@ { var isNewSoil = true; + SetSoilDefaults(newSoil); + foreach (var soilAlreadyKnown in soils.Soils) { if (soilAlreadyKnown.Name.Equals(newSoil.Name, StringComparison.InvariantCultureIgnoreCase)) @@ -932,31 +936,6 @@ private void DataEventPublisher_OnDataListModified(object sender, PublishEventArgs e) { - if (sender is List) - { - var args = e as DataListModifiedArgs; - if (args != null && (args.Action == ListModifyAction.Add || args.Action == ListModifyAction.Insert) && e.Objects.Length > 0) - { - // check the added soil(s) - foreach (var item in e.Objects) - { - var soil = item as Soil; - if (soil != null) - { - CheckSoilDefaults(soil); - } - } - } - else - { - // check all soils (event may be the result of an import action with missing soils) - foreach (var soil in Soils.Soils) - { - CheckSoilDefaults(soil); - } - } - } - if (sender == SoilSegments) { FilterSegments(); @@ -981,17 +960,34 @@ } } } - private void CheckSoilDefaults(Soil soil) + + /// + /// Set the soil defaults. + /// See the functional design document for D-SoilModel, some stochasts have a specific distribution type + /// + /// The soil. + public void SetSoilDefaults(Soil soil) { - // see functional design document, some stochasts have a specific distribution type - if (soil.GetOrdinaryParameters().Count == 0 && soil.GetStochasticParameters().Count == 0) + // only set the defaults if a stochast has not been defined otherwise + var definedStochasts = soil.GetStochasticParameters(); + + if (!definedStochasts.ContainsValue(soil.AbovePhreaticLevelStochast)) { soil.AbovePhreaticLevelStochast.DistributionType = DistributionType.LogNormal; soil.AbovePhreaticLevelStochast.Shift = 0; + } + if (!definedStochasts.ContainsValue(soil.BelowPhreaticLevelStochast)) + { soil.BelowPhreaticLevelStochast.DistributionType = DistributionType.LogNormal; soil.BelowPhreaticLevelStochast.Shift = 10.0; + } + if (!definedStochasts.ContainsValue(soil.DiameterD70Stochast)) + { soil.DiameterD70Stochast.DistributionType = DistributionType.LogNormal; soil.DiameterD70Stochast.Shift = 10; + } + if (!definedStochasts.ContainsValue(soil.PermeabKxStochast)) + { soil.PermeabKxStochast.DistributionType = DistributionType.LogNormal; soil.PermeabKxStochast.Shift = 0; } Index: src/Deltares.DSoilModel.Data.Tests/DSoilModelProjectTest.cs =================================================================== diff -u -r362 -r391 --- src/Deltares.DSoilModel.Data.Tests/DSoilModelProjectTest.cs (.../DSoilModelProjectTest.cs) (revision 362) +++ src/Deltares.DSoilModel.Data.Tests/DSoilModelProjectTest.cs (.../DSoilModelProjectTest.cs) (revision 391) @@ -40,23 +40,14 @@ } [Test] - public void TestDefaultsForAddedSoils() + public void TestSetSoilDefaults() { - var project = new DSoilModelProject(); var soil = new Soil(); - - // the only two defaults that differ from default soil - Assert.AreEqual(0, soil.BelowPhreaticLevelStochast.Shift); - Assert.AreEqual(0, soil.DiameterD70Stochast.Shift); - - project.Soils.Soils.Add(soil); - DataEventPublisher.InvokeAndPublish(() => - { - DataEventPublisher.DataListModified(project.Soils.Soils); - }); - - // defaults listed in functional design document + + project.SetSoilDefaults(soil); + + // defaults are set Assert.AreEqual(DistributionType.LogNormal, soil.AbovePhreaticLevelStochast.DistributionType); Assert.AreEqual(0, soil.AbovePhreaticLevelStochast.Shift); Assert.AreEqual(DistributionType.LogNormal, soil.BelowPhreaticLevelStochast.DistributionType); @@ -65,6 +56,21 @@ Assert.AreEqual(10.0, soil.DiameterD70Stochast.Shift); Assert.AreEqual(DistributionType.LogNormal, soil.PermeabKxStochast.DistributionType); Assert.AreEqual(0, soil.PermeabKxStochast.Shift); + + // set non-default values + soil = new Soil(); + soil.AbovePhreaticLevelStochast.DistributionType = DistributionType.Deterministic; + soil.BelowPhreaticLevelStochast.DistributionType = DistributionType.Deterministic; + soil.DiameterD70Stochast.DistributionType = DistributionType.Deterministic; + soil.PermeabKxStochast.DistributionType = DistributionType.Deterministic; + + project.SetSoilDefaults(soil); + + // nondefault values are NOT overwritten + Assert.AreEqual(DistributionType.Deterministic, soil.AbovePhreaticLevelStochast.DistributionType); + Assert.AreEqual(DistributionType.Deterministic, soil.BelowPhreaticLevelStochast.DistributionType); + Assert.AreEqual(DistributionType.Deterministic, soil.DiameterD70Stochast.DistributionType); + Assert.AreEqual(DistributionType.Deterministic, soil.PermeabKxStochast.DistributionType); } [Test]