Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -rb5accd775c390fa85f815ef13c3c3e54a6d10ada -rcc8077f0d935a92dd18a5d551788e3548645a5d2 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision b5accd775c390fa85f815ef13c3c3e54a6d10ada) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision cc8077f0d935a92dd18a5d551788e3548645a5d2) @@ -46,6 +46,7 @@ using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Probability; +using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Forms.GuiServices; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.PropertyClasses; @@ -855,10 +856,10 @@ IFailureMechanism failureMechanism = parentContext.ParentFailureMechanism; return failureMechanism is StabilityStoneCoverFailureMechanism || failureMechanism is WaveImpactAsphaltCoverFailureMechanism || - failureMechanism is GrassCoverErosionOutwardsFailureMechanism /*|| - failureMechanism is HeightStructuresFailureMechanism || - failureMechanism is ClosingStructuresFailureMechanism || - failureMechanism is StabilityPointStructuresFailureMechanism*/; + failureMechanism is GrassCoverErosionOutwardsFailureMechanism || + failureMechanism is HeightStructuresFailureMechanism || + failureMechanism is ClosingStructuresFailureMechanism || + failureMechanism is StabilityPointStructuresFailureMechanism; } private void OnForeshoreProfileRemoved(ForeshoreProfile nodeData, object parentNodeData) @@ -881,14 +882,29 @@ { OnGrassCoverErosionOutwardsForeshoreProfileRemoved(nodeData, parentContext.WrappedData, grassCoverErosionOutwardsFailureMechanism); } + var heightStructuresFailureMechanism = failureMechanism as HeightStructuresFailureMechanism; + if (heightStructuresFailureMechanism != null) + { + OnHeightStructuresForeshoreProfileRemoved(nodeData, parentContext.WrappedData, heightStructuresFailureMechanism); + } + var closingStructuresFailureMechanism = failureMechanism as ClosingStructuresFailureMechanism; + if (closingStructuresFailureMechanism != null) + { + OnClosingStructuresForeshoreProfileRemoved(nodeData, parentContext.WrappedData, closingStructuresFailureMechanism); + } + var stabilityPointStructuresFailureMechanism = failureMechanism as StabilityPointStructuresFailureMechanism; + if (stabilityPointStructuresFailureMechanism != null) + { + OnStabilityPointStructuresForeshoreProfileRemoved(nodeData, parentContext.WrappedData, stabilityPointStructuresFailureMechanism); + } } private static void OnStabilityStoneCoverForeshoreProfileRemoved(ForeshoreProfile nodeData, ObservableList foreshoreProfiles, StabilityStoneCoverFailureMechanism failureMechanism) { var changedObservables = new List(); StabilityStoneCoverWaveConditionsCalculation[] calculations = failureMechanism.Calculations - .Cast() - .ToArray(); + .Cast() + .ToArray(); StabilityStoneCoverWaveConditionsCalculation[] calculationWithRemovedForeshoreProfile = calculations .Where(c => ReferenceEquals(c.InputParameters.ForeshoreProfile, nodeData)) .ToArray(); @@ -911,8 +927,8 @@ { var changedObservables = new List(); WaveImpactAsphaltCoverWaveConditionsCalculation[] calculations = failureMechanism.Calculations - .Cast() - .ToArray(); + .Cast() + .ToArray(); WaveImpactAsphaltCoverWaveConditionsCalculation[] calculationWithRemovedForeshoreProfile = calculations .Where(c => ReferenceEquals(c.InputParameters.ForeshoreProfile, nodeData)) .ToArray(); @@ -935,8 +951,8 @@ { var changedObservables = new List(); GrassCoverErosionOutwardsWaveConditionsCalculation[] calculations = failureMechanism.Calculations - .Cast() - .ToArray(); + .Cast() + .ToArray(); GrassCoverErosionOutwardsWaveConditionsCalculation[] calculationWithRemovedForeshoreProfile = calculations .Where(c => ReferenceEquals(c.InputParameters.ForeshoreProfile, nodeData)) .ToArray(); @@ -955,6 +971,78 @@ } } + private static void OnHeightStructuresForeshoreProfileRemoved(ForeshoreProfile nodeData, ObservableList foreshoreProfiles, HeightStructuresFailureMechanism failureMechanism) + { + var changedObservables = new List(); + StructuresCalculation[] calculations = failureMechanism.Calculations + .Cast>() + .ToArray(); + StructuresCalculation[] calculationWithRemovedForeshoreProfile = calculations + .Where(c => ReferenceEquals(c.InputParameters.ForeshoreProfile, nodeData)) + .ToArray(); + foreach (StructuresCalculation calculation in calculationWithRemovedForeshoreProfile) + { + calculation.InputParameters.ForeshoreProfile = null; + changedObservables.Add(calculation.InputParameters); + } + + foreshoreProfiles.Remove(nodeData); + changedObservables.Add(foreshoreProfiles); + + foreach (IObservable observable in changedObservables) + { + observable.NotifyObservers(); + } + } + + private static void OnClosingStructuresForeshoreProfileRemoved(ForeshoreProfile nodeData, ObservableList foreshoreProfiles, ClosingStructuresFailureMechanism failureMechanism) + { + var changedObservables = new List(); + StructuresCalculation[] calculations = failureMechanism.Calculations + .Cast>() + .ToArray(); + StructuresCalculation[] calculationWithRemovedForeshoreProfile = calculations + .Where(c => ReferenceEquals(c.InputParameters.ForeshoreProfile, nodeData)) + .ToArray(); + foreach (StructuresCalculation calculation in calculationWithRemovedForeshoreProfile) + { + calculation.InputParameters.ForeshoreProfile = null; + changedObservables.Add(calculation.InputParameters); + } + + foreshoreProfiles.Remove(nodeData); + changedObservables.Add(foreshoreProfiles); + + foreach (IObservable observable in changedObservables) + { + observable.NotifyObservers(); + } + } + + private static void OnStabilityPointStructuresForeshoreProfileRemoved(ForeshoreProfile nodeData, ObservableList foreshoreProfiles, StabilityPointStructuresFailureMechanism failureMechanism) + { + var changedObservables = new List(); + StructuresCalculation[] calculations = failureMechanism.Calculations + .Cast>() + .ToArray(); + StructuresCalculation[] calculationWithRemovedForeshoreProfile = calculations + .Where(c => ReferenceEquals(c.InputParameters.ForeshoreProfile, nodeData)) + .ToArray(); + foreach (StructuresCalculation calculation in calculationWithRemovedForeshoreProfile) + { + calculation.InputParameters.ForeshoreProfile = null; + changedObservables.Add(calculation.InputParameters); + } + + foreshoreProfiles.Remove(nodeData); + changedObservables.Add(foreshoreProfiles); + + foreach (IObservable observable in changedObservables) + { + observable.NotifyObservers(); + } + } + #endregion #region DikeProfile TreeNodeInfo Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/ForeshoreTreeNodeInfoTest.cs =================================================================== diff -u -rb5accd775c390fa85f815ef13c3c3e54a6d10ada -rcc8077f0d935a92dd18a5d551788e3548645a5d2 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/ForeshoreTreeNodeInfoTest.cs (.../ForeshoreTreeNodeInfoTest.cs) (revision b5accd775c390fa85f815ef13c3c3e54a6d10ada) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/ForeshoreTreeNodeInfoTest.cs (.../ForeshoreTreeNodeInfoTest.cs) (revision cc8077f0d935a92dd18a5d551788e3548645a5d2) @@ -30,14 +30,18 @@ using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; +using Ringtoets.ClosingStructures.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.HeightStructures.Data; using Ringtoets.Integration.Plugin; using Ringtoets.Integration.Plugin.Properties; +using Ringtoets.StabilityPointStructures.Data; using Ringtoets.StabilityStoneCover.Data; using Ringtoets.WaveImpactAsphaltCover.Data; @@ -187,6 +191,66 @@ } [Test] + public void CanRemove_ParentFailureMechanismIsHeightStructures_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + + var parentData = new ForeshoreProfilesContext(failureMechanism.ForeshoreProfiles, failureMechanism, assessmentSection); + + // Call + bool canRemove = info.CanRemove(null, parentData); + + // Assert + Assert.IsTrue(canRemove); + mocks.VerifyAll(); + } + + [Test] + public void CanRemove_ParentFailureMechanismIsClosingStructures_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new ClosingStructuresFailureMechanism(); + + var parentData = new ForeshoreProfilesContext(failureMechanism.ForeshoreProfiles, failureMechanism, assessmentSection); + + // Call + bool canRemove = info.CanRemove(null, parentData); + + // Assert + Assert.IsTrue(canRemove); + mocks.VerifyAll(); + } + + [Test] + public void CanRemove_ParentFailureMechanismIsStabilityPointStructures_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + var parentData = new ForeshoreProfilesContext(failureMechanism.ForeshoreProfiles, failureMechanism, assessmentSection); + + // Call + bool canRemove = info.CanRemove(null, parentData); + + // Assert + Assert.IsTrue(canRemove); + mocks.VerifyAll(); + } + + [Test] public void CanRemove_UnsupportedFailureMechanism_ReturnFalse() { // Setup @@ -217,7 +281,7 @@ observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); - var nodeData = new ForeshoreProfile(new Point2D(0,0), new Point2D[0], null, new ForeshoreProfile.ConstructionProperties()); + var nodeData = new ForeshoreProfile(new Point2D(0, 0), new Point2D[0], null, new ForeshoreProfile.ConstructionProperties()); var failureMechanism = new StabilityStoneCoverFailureMechanism { @@ -550,6 +614,348 @@ } [Test] + public void OnNodeRemoved_ForeshoreProfileOfHeightStructures_ForeshoreProfileRemovedFromFailureMechanism() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var observer = mocks.Stub(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var nodeData = new ForeshoreProfile(new Point2D(0, 0), new Point2D[0], null, new ForeshoreProfile.ConstructionProperties()); + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism + { + ForeshoreProfiles = + { + nodeData + } + }; + failureMechanism.ForeshoreProfiles.Attach(observer); + + var parentData = new ForeshoreProfilesContext(failureMechanism.ForeshoreProfiles, failureMechanism, assessmentSection); + + // Call + info.OnNodeRemoved(nodeData, parentData); + + // Assert + CollectionAssert.DoesNotContain(failureMechanism.ForeshoreProfiles, nodeData); + mocks.VerifyAll(); + } + + [Test] + public void OnNodeRemoved_ForeshoreProfileOfHeightStructuresWaveConditionsCalculation_CalculationForeshoreProfileCleared() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var observer = mocks.Stub(); + observer.Expect(o => o.UpdateObserver()); + var calculation1Observer = mocks.StrictMock(); + calculation1Observer.Expect(o => o.UpdateObserver()); + var calculation2Observer = mocks.StrictMock(); + calculation2Observer.Expect(o => o.UpdateObserver()); + var calculation3Observer = mocks.StrictMock(); + calculation3Observer.Expect(o => o.UpdateObserver()).Repeat.Never(); + mocks.ReplayAll(); + + var nodeData = new ForeshoreProfile(new Point2D(0, 0), new Point2D[0], null, new ForeshoreProfile.ConstructionProperties()); + var otherProfile = new ForeshoreProfile(new Point2D(1, 1), new Point2D[0], null, new ForeshoreProfile.ConstructionProperties()); + + var calculation1 = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = nodeData + } + }; + calculation1.InputParameters.Attach(calculation1Observer); + var calculation2 = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = nodeData + } + }; + calculation2.InputParameters.Attach(calculation2Observer); + var calculation3 = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = otherProfile + } + }; + calculation3.InputParameters.Attach(calculation3Observer); + + var failureMechanism = new HeightStructuresFailureMechanism + { + ForeshoreProfiles = + { + nodeData, + otherProfile + }, + CalculationsGroup = + { + Children = + { + calculation1, + new CalculationGroup("A", true) + { + Children = + { + calculation2 + } + }, + calculation3 + } + } + }; + failureMechanism.ForeshoreProfiles.Attach(observer); + + var parentData = new ForeshoreProfilesContext(failureMechanism.ForeshoreProfiles, failureMechanism, assessmentSection); + + // Call + info.OnNodeRemoved(nodeData, parentData); + + // Assert + CollectionAssert.DoesNotContain(failureMechanism.ForeshoreProfiles, nodeData); + + Assert.IsNull(calculation1.InputParameters.ForeshoreProfile); + Assert.IsNull(calculation2.InputParameters.ForeshoreProfile); + Assert.AreSame(otherProfile, calculation3.InputParameters.ForeshoreProfile); + mocks.VerifyAll(); + } + + [Test] + public void OnNodeRemoved_ForeshoreProfileOfClosingStructures_ForeshoreProfileRemovedFromFailureMechanism() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var observer = mocks.Stub(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var nodeData = new ForeshoreProfile(new Point2D(0, 0), new Point2D[0], null, new ForeshoreProfile.ConstructionProperties()); + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism + { + ForeshoreProfiles = + { + nodeData + } + }; + failureMechanism.ForeshoreProfiles.Attach(observer); + + var parentData = new ForeshoreProfilesContext(failureMechanism.ForeshoreProfiles, failureMechanism, assessmentSection); + + // Call + info.OnNodeRemoved(nodeData, parentData); + + // Assert + CollectionAssert.DoesNotContain(failureMechanism.ForeshoreProfiles, nodeData); + mocks.VerifyAll(); + } + + [Test] + public void OnNodeRemoved_ForeshoreProfileOfClosingStructuresWaveConditionsCalculation_CalculationForeshoreProfileCleared() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var observer = mocks.Stub(); + observer.Expect(o => o.UpdateObserver()); + var calculation1Observer = mocks.StrictMock(); + calculation1Observer.Expect(o => o.UpdateObserver()); + var calculation2Observer = mocks.StrictMock(); + calculation2Observer.Expect(o => o.UpdateObserver()); + var calculation3Observer = mocks.StrictMock(); + calculation3Observer.Expect(o => o.UpdateObserver()).Repeat.Never(); + mocks.ReplayAll(); + + var nodeData = new ForeshoreProfile(new Point2D(0, 0), new Point2D[0], null, new ForeshoreProfile.ConstructionProperties()); + var otherProfile = new ForeshoreProfile(new Point2D(1, 1), new Point2D[0], null, new ForeshoreProfile.ConstructionProperties()); + + var calculation1 = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = nodeData + } + }; + calculation1.InputParameters.Attach(calculation1Observer); + var calculation2 = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = nodeData + } + }; + calculation2.InputParameters.Attach(calculation2Observer); + var calculation3 = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = otherProfile + } + }; + calculation3.InputParameters.Attach(calculation3Observer); + + var failureMechanism = new ClosingStructuresFailureMechanism + { + ForeshoreProfiles = + { + nodeData, + otherProfile + }, + CalculationsGroup = + { + Children = + { + calculation1, + new CalculationGroup("A", true) + { + Children = + { + calculation2 + } + }, + calculation3 + } + } + }; + failureMechanism.ForeshoreProfiles.Attach(observer); + + var parentData = new ForeshoreProfilesContext(failureMechanism.ForeshoreProfiles, failureMechanism, assessmentSection); + + // Call + info.OnNodeRemoved(nodeData, parentData); + + // Assert + CollectionAssert.DoesNotContain(failureMechanism.ForeshoreProfiles, nodeData); + + Assert.IsNull(calculation1.InputParameters.ForeshoreProfile); + Assert.IsNull(calculation2.InputParameters.ForeshoreProfile); + Assert.AreSame(otherProfile, calculation3.InputParameters.ForeshoreProfile); + mocks.VerifyAll(); + } + + [Test] + public void OnNodeRemoved_ForeshoreProfileOfStabilityPointStructures_ForeshoreProfileRemovedFromFailureMechanism() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var observer = mocks.Stub(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var nodeData = new ForeshoreProfile(new Point2D(0, 0), new Point2D[0], null, new ForeshoreProfile.ConstructionProperties()); + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism + { + ForeshoreProfiles = + { + nodeData + } + }; + failureMechanism.ForeshoreProfiles.Attach(observer); + + var parentData = new ForeshoreProfilesContext(failureMechanism.ForeshoreProfiles, failureMechanism, assessmentSection); + + // Call + info.OnNodeRemoved(nodeData, parentData); + + // Assert + CollectionAssert.DoesNotContain(failureMechanism.ForeshoreProfiles, nodeData); + mocks.VerifyAll(); + } + + [Test] + public void OnNodeRemoved_ForeshoreProfileOfStabilityPointStructuresWaveConditionsCalculation_CalculationForeshoreProfileCleared() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var observer = mocks.Stub(); + observer.Expect(o => o.UpdateObserver()); + var calculation1Observer = mocks.StrictMock(); + calculation1Observer.Expect(o => o.UpdateObserver()); + var calculation2Observer = mocks.StrictMock(); + calculation2Observer.Expect(o => o.UpdateObserver()); + var calculation3Observer = mocks.StrictMock(); + calculation3Observer.Expect(o => o.UpdateObserver()).Repeat.Never(); + mocks.ReplayAll(); + + var nodeData = new ForeshoreProfile(new Point2D(0, 0), new Point2D[0], null, new ForeshoreProfile.ConstructionProperties()); + var otherProfile = new ForeshoreProfile(new Point2D(1, 1), new Point2D[0], null, new ForeshoreProfile.ConstructionProperties()); + + var calculation1 = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = nodeData + } + }; + calculation1.InputParameters.Attach(calculation1Observer); + var calculation2 = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = nodeData + } + }; + calculation2.InputParameters.Attach(calculation2Observer); + var calculation3 = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = otherProfile + } + }; + calculation3.InputParameters.Attach(calculation3Observer); + + var failureMechanism = new StabilityPointStructuresFailureMechanism + { + ForeshoreProfiles = + { + nodeData, + otherProfile + }, + CalculationsGroup = + { + Children = + { + calculation1, + new CalculationGroup("A", true) + { + Children = + { + calculation2 + } + }, + calculation3 + } + } + }; + failureMechanism.ForeshoreProfiles.Attach(observer); + + var parentData = new ForeshoreProfilesContext(failureMechanism.ForeshoreProfiles, failureMechanism, assessmentSection); + + // Call + info.OnNodeRemoved(nodeData, parentData); + + // Assert + CollectionAssert.DoesNotContain(failureMechanism.ForeshoreProfiles, nodeData); + + Assert.IsNull(calculation1.InputParameters.ForeshoreProfile); + Assert.IsNull(calculation2.InputParameters.ForeshoreProfile); + Assert.AreSame(otherProfile, calculation3.InputParameters.ForeshoreProfile); + mocks.VerifyAll(); + } + + [Test] public void ContextMenuStrip_Always_CallsBuilder() { // Setup