Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineUpdateStrategy.cs =================================================================== diff -u -r92549be285a5082435e9625732cf33ff50cd60b9 -r2939615955f7dc0d299fd1baa7b2c7dafcca3db2 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineUpdateStrategy.cs (.../RingtoetsPipingSurfaceLineUpdateStrategy.cs) (revision 92549be285a5082435e9625732cf33ff50cd60b9) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineUpdateStrategy.cs (.../RingtoetsPipingSurfaceLineUpdateStrategy.cs) (revision 2939615955f7dc0d299fd1baa7b2c7dafcca3db2) @@ -25,6 +25,7 @@ using Core.Common.Base; using Core.Common.Utils; using Ringtoets.Piping.Data; +using Ringtoets.Piping.Forms; using Ringtoets.Piping.IO.Importers; using Ringtoets.Piping.Plugin.Properties; using Ringtoets.Piping.Primitives; @@ -166,12 +167,38 @@ { RingtoetsPipingSurfaceLine matchingSurfaceLine = readSurfaceLines.Single(sl => sl.Name == updatedSurfaceLine.Name); updatedSurfaceLine.Update(matchingSurfaceLine); + affectedObjects.Add(updatedSurfaceLine); + affectedObjects.AddRange(UpdateAvailableStochasticSoilModels(updatedSurfaceLine)); } return affectedObjects; } + private IEnumerable UpdateAvailableStochasticSoilModels(RingtoetsPipingSurfaceLine updatedSurfaceLine) + { + IEnumerable affectedCalculations = + failureMechanism.Calculations + .Cast() + .Where(calc => ReferenceEquals(updatedSurfaceLine, calc.InputParameters.SurfaceLine)); + + var affectedObjects = new List(); + foreach (PipingCalculation affectedCalculation in affectedCalculations) + { + IEnumerable matchingSoilModels = GetAvailableStochasticSoilModels(updatedSurfaceLine); + PipingInputService.SetMatchingStochasticSoilModel(affectedCalculation.InputParameters, matchingSoilModels); + affectedObjects.Add(affectedCalculation); + affectedObjects.Add(affectedCalculation.InputParameters); + } + return affectedObjects; + } + + private IEnumerable GetAvailableStochasticSoilModels(RingtoetsPipingSurfaceLine surfaceLine) + { + return PipingCalculationConfigurationHelper.GetStochasticSoilModelsForSurfaceLine(surfaceLine, + failureMechanism.StochasticSoilModels); + } + #endregion /// Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs =================================================================== diff -u -r92549be285a5082435e9625732cf33ff50cd60b9 -r2939615955f7dc0d299fd1baa7b2c7dafcca3db2 --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs (.../RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs) (revision 92549be285a5082435e9625732cf33ff50cd60b9) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs (.../RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs) (revision 2939615955f7dc0d299fd1baa7b2c7dafcca3db2) @@ -266,5 +266,295 @@ targetSurfaceLine }, affectedObjects); } + + [Test] + public void UpdateSurfaceLinesWithImportedData_WithCalculationAssignedToUpdatedLine_UpdatesCalculationAndStochasticSoilModel() + { + // Setup + RingtoetsPipingSurfaceLine surfaceLine = CreateValidSurfaceLineForCalculations(); + var calculation = new PipingCalculation(new GeneralPipingInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine + } + }; + + var soilModels = new[] + { + new StochasticSoilModel(1, "A", "B") + { + Geometry = + { + new Point2D(2, -1), + new Point2D(2, 1) + }, + StochasticSoilProfiles = + { + new StochasticSoilProfile(0.2, SoilProfileType.SoilProfile1D, 1) + } + }, + new StochasticSoilModel(2, "C", "D") + { + Geometry = + { + new Point2D(-2, -1), + new Point2D(-2, 1) + }, + StochasticSoilProfiles = + { + new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, 2) + } + } + }; + + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.SurfaceLines.AddRange(new[] + { + surfaceLine + }, "path"); + failureMechanism.StochasticSoilModels.AddRange(soilModels, "path"); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + var importedSurfaceLine = new RingtoetsPipingSurfaceLine + { + Name = "Name A" + }; + importedSurfaceLine.SetGeometry(new[] + { + new Point3D(0, 0, 0), + new Point3D(10, 0, 0) + }); + + var strategy = new RingtoetsPipingSurfaceLineUpdateDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(failureMechanism.SurfaceLines, + new[] + { + importedSurfaceLine + }, "path").ToArray(); + + // Assert + PipingInput calculationInput = calculation.InputParameters; + CollectionAssert.Contains(affectedObjects, calculation); + CollectionAssert.Contains(affectedObjects, calculationInput); + Assert.AreSame(surfaceLine, calculationInput.SurfaceLine); + CollectionAssert.AreEqual(importedSurfaceLine.Points, surfaceLine.Points); + Assert.AreEqual(soilModels[0], calculationInput.StochasticSoilModel); + } + + [Test] + public void UpdateSurfaceLinesWithImportedData_WithCalculationAssignedToUpdatedLineAndMultipleMatchingSoilModels_UpdatesCalculationAndStochasticSoilModelToNull() + { + // Setup + var soilModels = new[] + { + new StochasticSoilModel(1, "A", "B") + { + Geometry = + { + new Point2D(2, -1), + new Point2D(2, 1) + }, + StochasticSoilProfiles = + { + new StochasticSoilProfile(0.2, SoilProfileType.SoilProfile1D, 1) + } + }, + new StochasticSoilModel(2, "C", "D") + { + Geometry = + { + new Point2D(-2, -1), + new Point2D(-2, 1) + }, + StochasticSoilProfiles = + { + new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, 2) + } + }, + new StochasticSoilModel(3, "E", "F") + { + Geometry = + { + new Point2D(6, -1), + new Point2D(6, 1) + }, + StochasticSoilProfiles = + { + new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, 3) + } + } + }; + + RingtoetsPipingSurfaceLine surfaceLine = CreateValidSurfaceLineForCalculations(); + var calculation = new PipingCalculation(new GeneralPipingInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine, + StochasticSoilModel = soilModels[1] + } + }; + + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculation); + failureMechanism.SurfaceLines.AddRange(new[] + { + surfaceLine + }, "path"); + failureMechanism.StochasticSoilModels.AddRange(soilModels, "path"); + + var importedSurfaceLine = new RingtoetsPipingSurfaceLine + { + Name = "Name A" + }; + importedSurfaceLine.SetGeometry(new[] + { + new Point3D(0, 0, 0), + new Point3D(10, 0, 0) + }); + + var strategy = new RingtoetsPipingSurfaceLineUpdateDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(failureMechanism.SurfaceLines, + new[] + { + importedSurfaceLine + }, "path").ToArray(); + + // Assert + PipingInput calculationInput = calculation.InputParameters; + CollectionAssert.Contains(affectedObjects, calculation); + CollectionAssert.Contains(affectedObjects, calculationInput); + Assert.AreSame(surfaceLine, calculationInput.SurfaceLine); + CollectionAssert.AreEqual(importedSurfaceLine.Points, surfaceLine.Points); + Assert.IsNull(calculationInput.StochasticSoilModel); + } + + [Test] + public void UpdateSurfaceLinesWithImportedData_MultipleCalculations_OnlyUpdatesCalculationWithUpdatedSurfaceLine() + { + // Setup + var affectedSurfaceLine = new RingtoetsPipingSurfaceLine + { + Name = "Name A" + }; + affectedSurfaceLine.SetGeometry(new[] + { + new Point3D(1, 2, 3), + new Point3D(4, 5, 6) + }); + var affectedCalculation = new PipingCalculation(new GeneralPipingInput()) + { + InputParameters = + { + SurfaceLine = affectedSurfaceLine + } + }; + + var unaffectedGeometry = new[] + { + new Point3D(10, 9, 8), + new Point3D(7, 6, 5) + }; + var unaffectedSurfaceLine = new RingtoetsPipingSurfaceLine(); + unaffectedSurfaceLine.SetGeometry(unaffectedGeometry); + var unAffectedCalculation = new PipingCalculation(new GeneralPipingInput()) + { + InputParameters = + { + SurfaceLine = unaffectedSurfaceLine + } + }; + + var soilModels = new[] + { + new StochasticSoilModel(1, "A", "B") + { + Geometry = + { + new Point2D(2, -1), + new Point2D(2, 1) + }, + StochasticSoilProfiles = + { + new StochasticSoilProfile(0.2, SoilProfileType.SoilProfile1D, 1) + } + }, + new StochasticSoilModel(2, "C", "D") + { + Geometry = + { + new Point2D(-2, -1), + new Point2D(-2, 1) + }, + StochasticSoilProfiles = + { + new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, 2) + } + } + }; + + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(affectedCalculation); + failureMechanism.CalculationsGroup.Children.Add(unAffectedCalculation); + + failureMechanism.SurfaceLines.AddRange(new[] + { + affectedSurfaceLine + }, "path"); + failureMechanism.StochasticSoilModels.AddRange(soilModels, "path"); + + var importedSurfaceLine = new RingtoetsPipingSurfaceLine + { + Name = "Name A" + }; + importedSurfaceLine.SetGeometry(new[] + { + new Point3D(0, 0, 0), + new Point3D(10, 0, 0) + }); + + var strategy = new RingtoetsPipingSurfaceLineUpdateDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(failureMechanism.SurfaceLines, + new[] + { + importedSurfaceLine + }, "path").ToArray(); + + // Assert + PipingInput unaffectedInput = unAffectedCalculation.InputParameters; + CollectionAssert.DoesNotContain(affectedObjects, unAffectedCalculation); + CollectionAssert.DoesNotContain(affectedObjects, unaffectedInput); + Assert.AreSame(unaffectedSurfaceLine, unaffectedInput.SurfaceLine); + CollectionAssert.AreEqual(unaffectedGeometry, unaffectedSurfaceLine.Points); + Assert.IsNull(unaffectedInput.StochasticSoilModel); + + PipingInput affectedInput = affectedCalculation.InputParameters; + CollectionAssert.Contains(affectedObjects, affectedCalculation); + CollectionAssert.Contains(affectedObjects, affectedInput); + Assert.AreSame(affectedSurfaceLine, affectedInput.SurfaceLine); + CollectionAssert.AreEqual(importedSurfaceLine.Points, affectedSurfaceLine.Points); + Assert.AreEqual(soilModels[0], affectedInput.StochasticSoilModel); + } + + private static RingtoetsPipingSurfaceLine CreateValidSurfaceLineForCalculations() + { + var surfaceLine = new RingtoetsPipingSurfaceLine + { + Name = "Name A" + }; + surfaceLine.SetGeometry(new[] + { + new Point3D(1, 2, 3), + new Point3D(4, 5, 6) + }); + return surfaceLine; + } } } \ No newline at end of file