Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategy.cs =================================================================== diff -u -r0c3836acca0399823bbd7f8c9e242a5de7692aa2 -rd16c525c53b03da07dd18853da6b8b256ede5b5a --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategy.cs (.../RingtoetsPipingSurfaceLineUpdateDataStrategy.cs) (revision 0c3836acca0399823bbd7f8c9e242a5de7692aa2) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategy.cs (.../RingtoetsPipingSurfaceLineUpdateDataStrategy.cs) (revision d16c525c53b03da07dd18853da6b8b256ede5b5a) @@ -184,6 +184,13 @@ protected override IEnumerable RemoveObjectAndDependentData(RingtoetsPipingSurfaceLine removedSurfaceLine) { + IEnumerable calculationsToUpdate = GetAffectedCalculationWithSurfaceLine(removedSurfaceLine); + foreach (PipingCalculation affectedCalculation in calculationsToUpdate) + { + IEnumerable matchingSoilModels = GetAvailableStochasticSoilModels(null); + PipingInputService.SetMatchingStochasticSoilModel(affectedCalculation.InputParameters, matchingSoilModels); + } + return PipingDataSynchronizationService.RemoveSurfaceLine(failureMechanism, removedSurfaceLine); } Index: Ringtoets/Piping/src/Ringtoets.Piping.Primitives/RingtoetsPipingSurfaceLine.cs =================================================================== diff -u -r0c3836acca0399823bbd7f8c9e242a5de7692aa2 -rd16c525c53b03da07dd18853da6b8b256ede5b5a --- Ringtoets/Piping/src/Ringtoets.Piping.Primitives/RingtoetsPipingSurfaceLine.cs (.../RingtoetsPipingSurfaceLine.cs) (revision 0c3836acca0399823bbd7f8c9e242a5de7692aa2) +++ Ringtoets/Piping/src/Ringtoets.Piping.Primitives/RingtoetsPipingSurfaceLine.cs (.../RingtoetsPipingSurfaceLine.cs) (revision d16c525c53b03da07dd18853da6b8b256ede5b5a) @@ -368,6 +368,7 @@ } Name = fromSurfaceLine.Name; + ReferenceLineIntersectionWorldPoint = fromSurfaceLine.ReferenceLineIntersectionWorldPoint; SetGeometry(fromSurfaceLine.Points); ClearCharacteristicPoints(); SetCharacteristicPoints(fromSurfaceLine); @@ -457,7 +458,8 @@ private bool Equals(RingtoetsPipingSurfaceLine other) { return string.Equals(Name, other.Name) - && EqualPoints(other.Points) + && Equals(ReferenceLineIntersectionWorldPoint, other.ReferenceLineIntersectionWorldPoint) + && EqualGeometricPoints(other.Points) && EqualCharacteristicPoints(other); } @@ -471,7 +473,7 @@ && Equals(BottomDitchPolderSide, other.BottomDitchPolderSide); } - private bool EqualPoints(Point3D[] otherPoints) + private bool EqualGeometricPoints(Point3D[] otherPoints) { int nrOfOtherPoints = otherPoints.Length; if (Points.Length != nrOfOtherPoints) Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineTest.cs =================================================================== diff -u -r0c3836acca0399823bbd7f8c9e242a5de7692aa2 -rd16c525c53b03da07dd18853da6b8b256ede5b5a --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineTest.cs (.../RingtoetsPipingSurfaceLineTest.cs) (revision 0c3836acca0399823bbd7f8c9e242a5de7692aa2) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineTest.cs (.../RingtoetsPipingSurfaceLineTest.cs) (revision d16c525c53b03da07dd18853da6b8b256ede5b5a) @@ -762,6 +762,8 @@ // Assert Assert.AreEqual(surfaceLineToUpdateFrom.Name, surfaceLine.Name); + Assert.AreEqual(surfaceLineToUpdateFrom.ReferenceLineIntersectionWorldPoint, + surfaceLine.ReferenceLineIntersectionWorldPoint); CollectionAssert.AreEqual(expectedGeometry, surfaceLine.Points); AssertCharacteristicPoints(surfaceLineToUpdateFrom, surfaceLine); } @@ -773,7 +775,8 @@ RingtoetsPipingSurfaceLine surfaceLine = CreateSurfaceLineWithCharacteristicPoints(); var surfaceLineToUpdateFrom = new RingtoetsPipingSurfaceLine { - Name = surfaceLine.Name + Name = surfaceLine.Name, + ReferenceLineIntersectionWorldPoint = surfaceLine.ReferenceLineIntersectionWorldPoint }; surfaceLineToUpdateFrom.SetGeometry(surfaceLine.Points); @@ -782,14 +785,36 @@ // Assert Assert.AreEqual(surfaceLineToUpdateFrom.Name, surfaceLine.Name); + Assert.AreEqual(surfaceLineToUpdateFrom.ReferenceLineIntersectionWorldPoint, + surfaceLine.ReferenceLineIntersectionWorldPoint); CollectionAssert.AreEqual(surfaceLineToUpdateFrom.Points, surfaceLine.Points); AssertCharacteristicPoints(surfaceLineToUpdateFrom, surfaceLine); } [Test] - public void CopyProperties_LineWithUpdatedGeometryAndCharacteristicPoints_PropertiesUpdated() + public void CopyProperties_LineWithUpdatedReferenceLineWorldPoint_PropertiesUpdated() { // Setup + RingtoetsPipingSurfaceLine surfaceLine = CreateSurfaceLineWithCharacteristicPoints(); + + var expectedIntersectionPoint = new Point2D(123, 456); + RingtoetsPipingSurfaceLine surfaceLineToUpdateFrom = CreateSurfaceLineWithCharacteristicPoints(); + surfaceLineToUpdateFrom.ReferenceLineIntersectionWorldPoint = expectedIntersectionPoint; + + // Call + surfaceLine.CopyProperties(surfaceLineToUpdateFrom); + + // Assert + Assert.AreEqual(surfaceLineToUpdateFrom.Name, surfaceLine.Name); + Assert.AreEqual(expectedIntersectionPoint, surfaceLine.ReferenceLineIntersectionWorldPoint); + CollectionAssert.AreEqual(surfaceLineToUpdateFrom.Points, surfaceLine.Points); + AssertCharacteristicPoints(surfaceLineToUpdateFrom, surfaceLine); + } + + [Test] + public void CopyProperties_LineWithUpdatedGeometryAndReferenceLineIntersectionAndCharacteristicPoints_PropertiesUpdated() + { + // Setup var surfaceLine = new RingtoetsPipingSurfaceLine(); RingtoetsPipingSurfaceLine surfaceLineToUpdateFrom = CreateSurfaceLineWithCharacteristicPoints(); @@ -798,6 +823,8 @@ // Assert Assert.AreEqual(surfaceLineToUpdateFrom.Name, surfaceLine.Name); + Assert.AreEqual(surfaceLineToUpdateFrom.ReferenceLineIntersectionWorldPoint, + surfaceLine.ReferenceLineIntersectionWorldPoint); CollectionAssert.AreEqual(surfaceLineToUpdateFrom.Points, surfaceLine.Points); AssertCharacteristicPoints(surfaceLineToUpdateFrom, surfaceLine); } @@ -918,6 +945,25 @@ } [Test] + public void Equals_DifferentReferenceLineIntersectionWorldPoint_ReturnsFalse() + { + // Setup + RingtoetsPipingSurfaceLine surfaceLineOne = CreateSurfaceLineWithCharacteristicPoints(); + surfaceLineOne.ReferenceLineIntersectionWorldPoint = new Point2D(0, 0); + + RingtoetsPipingSurfaceLine surfaceLineTwo = CreateSurfaceLineWithCharacteristicPoints(); + surfaceLineTwo.ReferenceLineIntersectionWorldPoint = new Point2D(1, 1); + + // Call + bool isLineOneEqualToLineTwo = surfaceLineOne.Equals(surfaceLineTwo); + bool isLineTwoEqualToLineOne = surfaceLineTwo.Equals(surfaceLineOne); + + // Assert + Assert.IsFalse(isLineOneEqualToLineTwo); + Assert.IsFalse(isLineTwoEqualToLineOne); + } + + [Test] public void Equals_DifferentBottomDitchDikeSide_ReturnsFalse() { // Setup @@ -1026,7 +1072,7 @@ } [Test] - public void Equals_NamesGeometriesAndCharacteristicPointsEqual_ReturnsTrue() + public void Equals_NamesGeometriesAndReferenceLineIntersectionWorldPointAndCharacteristicPointsEqual_ReturnsTrue() { // Setup RingtoetsPipingSurfaceLine surfaceLineOne = CreateSurfaceLineWithCharacteristicPoints(); @@ -1079,7 +1125,8 @@ { var surfaceLine = new RingtoetsPipingSurfaceLine { - Name = "Name A" + Name = "Name A", + ReferenceLineIntersectionWorldPoint = new Point2D(0, 0) }; var geometry = new[] { Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs =================================================================== diff -u -r55d21f6ba06c58de1fe3406a950890668643e038 -rd16c525c53b03da07dd18853da6b8b256ede5b5a --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs (.../RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs) (revision 55d21f6ba06c58de1fe3406a950890668643e038) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs (.../RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs) (revision d16c525c53b03da07dd18853da6b8b256ede5b5a) @@ -160,11 +160,45 @@ // Assert Assert.AreEqual(surfaceLineToUpdateFrom.Name, surfaceLine.Name); + Assert.AreEqual(surfaceLineToUpdateFrom.ReferenceLineIntersectionWorldPoint, + surfaceLine.ReferenceLineIntersectionWorldPoint); CollectionAssert.AreEqual(surfaceLineToUpdateFrom.Points, surfaceLine.Points); AssertCharacteristicPoints(surfaceLineToUpdateFrom, surfaceLine); } [Test] + public void UpdateSurfaceLinesWithImportedData_OnlyReferenceLineIntersectionPointChanged_UpdatesCharacteristicPointsOnly() + { + // Setup + RingtoetsPipingSurfaceLine surfaceLine = CreateValidSurfaceLineForCalculations(); + + RingtoetsPipingSurfaceLine surfaceLineToUpdateFrom = CreateValidSurfaceLineForCalculations(); + surfaceLineToUpdateFrom.ReferenceLineIntersectionWorldPoint = new Point2D(123, 456); + + var targetCollection = new RingtoetsPipingSurfaceLineCollection(); + targetCollection.AddRange(new[] + { + surfaceLine + }, sourceFilePath); + var strategy = new RingtoetsPipingSurfaceLineUpdateDataStrategy(new PipingFailureMechanism()); + + // Call + strategy.UpdateSurfaceLinesWithImportedData(targetCollection, + new[] + { + surfaceLineToUpdateFrom + }, + sourceFilePath); + + // Assert + Assert.AreEqual(surfaceLineToUpdateFrom.Name, surfaceLine.Name); + Assert.AreEqual(surfaceLineToUpdateFrom.ReferenceLineIntersectionWorldPoint, + surfaceLine.ReferenceLineIntersectionWorldPoint); + CollectionAssert.AreEqual(surfaceLineToUpdateFrom.Points, surfaceLine.Points); + AssertCharacteristicPoints(surfaceLineToUpdateFrom, surfaceLine); + } + + [Test] public void UpdateSurfaceLinesWithImportedData_OnlyCharacteristicPointsChanged_UpdatesCharacteristicPointsOnly() { // Setup @@ -192,12 +226,14 @@ // Assert Assert.AreEqual(surfaceLineToUpdateFrom.Name, surfaceLine.Name); + Assert.AreEqual(surfaceLineToUpdateFrom.ReferenceLineIntersectionWorldPoint, + surfaceLine.ReferenceLineIntersectionWorldPoint); CollectionAssert.AreEqual(surfaceLineToUpdateFrom.Points, surfaceLine.Points); AssertCharacteristicPoints(surfaceLineToUpdateFrom, surfaceLine); } [Test] - public void UpdateSurfaceLinesWithImportedData_GeometryAndCharacteristicPointsChanged_UpdatesGeometryAndCharacteristicPoints() + public void UpdateSurfaceLinesWithImportedData_GeometryAndReferenceLineIntersectionPointAndCharacteristicPointsChanged_UpdatesRelevantProperties() { // Setup RingtoetsPipingSurfaceLine surfaceLine = CreateValidSurfaceLineForCalculations(); @@ -220,6 +256,8 @@ // Assert Assert.AreEqual(surfaceLineToUpdateFrom.Name, surfaceLine.Name); + Assert.AreEqual(surfaceLineToUpdateFrom.ReferenceLineIntersectionWorldPoint, + surfaceLine.ReferenceLineIntersectionWorldPoint); CollectionAssert.AreEqual(surfaceLineToUpdateFrom.Points, surfaceLine.Points); AssertCharacteristicPoints(surfaceLineToUpdateFrom, surfaceLine); } @@ -838,6 +876,74 @@ } [Test] + public void UpdateSurfaceLinesWithImportedData_WithCalculationAssignedToRemovedLine_UpdatesCalculationAndRemoveStochasticSoilModelInput() + { + // 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) + } + } + }; + + 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 strategy = new RingtoetsPipingSurfaceLineUpdateDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(failureMechanism.SurfaceLines, + Enumerable.Empty(), + "path").ToArray(); + + // Assert + PipingInput calculationInput = calculation.InputParameters; + CollectionAssert.AreEquivalent(new IObservable[] + { + failureMechanism.SurfaceLines, + calculationInput + }, affectedObjects); + Assert.IsNull(calculationInput.SurfaceLine); + Assert.IsNull(calculationInput.StochasticSoilModel); + } + + [Test] public void UpdateSurfaceLinesWithImportedData_MultipleCalculations_OnlyUpdatesCalculationWithUpdatedSurfaceLine() { // Setup @@ -1141,7 +1247,8 @@ { var surfaceLine = new RingtoetsPipingSurfaceLine { - Name = "Name A" + Name = "Name A", + ReferenceLineIntersectionWorldPoint = new Point2D(123, 456) }; var geometry = new[] { @@ -1182,17 +1289,28 @@ /// /// Makes a deep clone of the and sets a - /// new geometry and characteristic points. + /// new geometry, reference line intersection world reference point and + /// characteristic points. /// /// The /// which needs to be deep cloned and modified. /// A deep clone of with modified /// geometric and characteristic points. private static RingtoetsPipingSurfaceLine DeepCloneAndModifyPoints(RingtoetsPipingSurfaceLine surfaceLine) { + var random = new Random(21); + Point2D newIntersectionPoint = null; + if (surfaceLine.ReferenceLineIntersectionWorldPoint != null) + { + Point2D oldIntersectionPoint = surfaceLine.ReferenceLineIntersectionWorldPoint; + newIntersectionPoint = new Point2D(oldIntersectionPoint.X + random.NextDouble(), + oldIntersectionPoint.Y + random.NextDouble()); + } + var copiedLine = new RingtoetsPipingSurfaceLine { - Name = surfaceLine.Name + Name = surfaceLine.Name, + ReferenceLineIntersectionWorldPoint = newIntersectionPoint }; var newGeometry = new[]