Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingInput.cs =================================================================== diff -u -r0faea705e7f83205f8420c52edda8a5473485bcd -r614c1aa4bf54ed2852d93a58ba8d49b549d5f46c --- Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingInput.cs (.../PipingInput.cs) (revision 0faea705e7f83205f8420c52edda8a5473485bcd) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingInput.cs (.../PipingInput.cs) (revision 614c1aa4bf54ed2852d93a58ba8d49b549d5f46c) @@ -46,7 +46,6 @@ private RoundedDouble exitPointL; private RoundedDouble entryPointL; private RingtoetsPipingSurfaceLine surfaceLine; - private StochasticSoilModel stochasticSoilModel; /// /// Initializes a new instance of the class. @@ -148,18 +147,7 @@ /// /// Gets or sets the stochastic soil model which is linked to the . /// - public StochasticSoilModel StochasticSoilModel - { - get - { - return stochasticSoilModel; - } - set - { - stochasticSoilModel = value; - UpdateStochasticSoilProfile(); - } - } + public StochasticSoilModel StochasticSoilModel { get; set; } /// /// Gets or sets the profile which contains a 1 dimensional definition of soil layers with properties. @@ -171,25 +159,6 @@ /// public HydraulicBoundaryLocation HydraulicBoundaryLocation { get; set; } - private void UpdateStochasticSoilProfile() - { - if (stochasticSoilModel == null) - { - StochasticSoilProfile = null; - return; - } - if (stochasticSoilModel.StochasticSoilProfiles.Contains(StochasticSoilProfile)) - { - return; - } - if (stochasticSoilModel.StochasticSoilProfiles.Count == 1) - { - StochasticSoilProfile = stochasticSoilModel.StochasticSoilProfiles.First(); - return; - } - StochasticSoilProfile = null; - } - private void UpdateEntryAndExitPoint() { if (SurfaceLine == null) Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/PresentationObjects/PipingInputContext.cs =================================================================== diff -u -ra9aafffab97152303562110b1d789bacb465ce24 -r614c1aa4bf54ed2852d93a58ba8d49b549d5f46c --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/PresentationObjects/PipingInputContext.cs (.../PipingInputContext.cs) (revision a9aafffab97152303562110b1d789bacb465ce24) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/PresentationObjects/PipingInputContext.cs (.../PipingInputContext.cs) (revision 614c1aa4bf54ed2852d93a58ba8d49b549d5f46c) @@ -20,7 +20,7 @@ // All rights reserved. using System.Collections.Generic; -using Ringtoets.Common.Data; +using System.Linq; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Piping.Data; using Ringtoets.Piping.Primitives; @@ -43,8 +43,37 @@ /// The assessment section which the piping context belongs to. /// When any input parameter is null. public PipingInputContext(PipingInput pipingInput, IEnumerable surfaceLines, IEnumerable stochasticSoilModels, IAssessmentSection assessmentSection) - : base(pipingInput, surfaceLines, stochasticSoilModels, assessmentSection) + : base(pipingInput, surfaceLines, stochasticSoilModels, assessmentSection) {} + + /// + /// Sets and that matching the input of a calculation if there is one matching + /// or respectively. + /// + public void SetStochasticSoilModelAndStochasticSoilProfileForSurfaceLine() { + var available = PipingCalculationConfigurationHelper.GetStochasticSoilModelsForSurfaceLine(WrappedData.SurfaceLine, AvailableStochasticSoilModels).ToList(); + if (available.Count == 1) + { + if (WrappedData.StochasticSoilModel == available.First()) + { + return; + } + WrappedData.StochasticSoilModel = available.First(); + } + SetStochasticSoilProfile(); } + + private void SetStochasticSoilProfile() + { + if (WrappedData.StochasticSoilModel != null) + { + if (WrappedData.StochasticSoilModel.StochasticSoilProfiles.Count == 1) + { + WrappedData.StochasticSoilProfile = WrappedData.StochasticSoilModel.StochasticSoilProfiles.First(); + return; + } + } + WrappedData.StochasticSoilProfile = null; + } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/PropertyClasses/PipingInputContextProperties.cs =================================================================== diff -u -r0faea705e7f83205f8420c52edda8a5473485bcd -r614c1aa4bf54ed2852d93a58ba8d49b549d5f46c --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/PropertyClasses/PipingInputContextProperties.cs (.../PipingInputContextProperties.cs) (revision 0faea705e7f83205f8420c52edda8a5473485bcd) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/PropertyClasses/PipingInputContextProperties.cs (.../PipingInputContextProperties.cs) (revision 614c1aa4bf54ed2852d93a58ba8d49b549d5f46c) @@ -171,8 +171,7 @@ if (!ReferenceEquals(value, data.WrappedData.SurfaceLine)) { data.WrappedData.SurfaceLine = value; - data.WrappedData.StochasticSoilModel = null; - data.WrappedData.StochasticSoilProfile = null; + data.SetStochasticSoilModelAndStochasticSoilProfileForSurfaceLine(); data.WrappedData.NotifyObservers(); } } Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingInputTest.cs =================================================================== diff -u -r0faea705e7f83205f8420c52edda8a5473485bcd -r614c1aa4bf54ed2852d93a58ba8d49b549d5f46c --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingInputTest.cs (.../PipingInputTest.cs) (revision 0faea705e7f83205f8420c52edda8a5473485bcd) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingInputTest.cs (.../PipingInputTest.cs) (revision 614c1aa4bf54ed2852d93a58ba8d49b549d5f46c) @@ -149,48 +149,6 @@ } [Test] - public void StochasticSoilModel_NewStochasticSoilModelWithOneStochasticSoilProfile_SetsStochasticSoilProfile() - { - // Setup - var pipingInput = new PipingInput(new GeneralPipingInput()); - StochasticSoilModel stochasticSoilModel = new StochasticSoilModel(0, "StochasticSoilModelName", "StochasticSoilModelSegmentName"); - StochasticSoilProfile stochasticSoilProfile = new StochasticSoilProfile(1.1, SoilProfileType.SoilProfile1D, 0); - stochasticSoilModel.StochasticSoilProfiles.Add(stochasticSoilProfile); - - // Call - pipingInput.StochasticSoilModel = stochasticSoilModel; - - // Assert - Assert.AreEqual(stochasticSoilProfile, pipingInput.StochasticSoilProfile); - Assert.AreEqual(stochasticSoilModel, pipingInput.StochasticSoilModel); - } - - [Test] - public void StochasticSoilModel_NewStochasticSoilModelWithMultipleStochasticSoilProfile_SetsStochasticSoilProfileToNull() - { - // Setup - var pipingInput = new PipingInput(new GeneralPipingInput()); - - StochasticSoilModel stochasticSoilModel = new StochasticSoilModel(0, "StochasticSoilModelName", "StochasticSoilModelSegmentName"); - StochasticSoilProfile stochasticSoilProfile = new StochasticSoilProfile(1.1, SoilProfileType.SoilProfile1D, 0); - stochasticSoilModel.StochasticSoilProfiles.Add(stochasticSoilProfile); - - StochasticSoilModel stochasticSoilModelWithMiltipleProfiles = new StochasticSoilModel(0, "StochasticSoilModelName", "StochasticSoilModelSegmentName"); - stochasticSoilModelWithMiltipleProfiles.StochasticSoilProfiles.Add(new StochasticSoilProfile(1.1, SoilProfileType.SoilProfile1D, 1)); - stochasticSoilModelWithMiltipleProfiles.StochasticSoilProfiles.Add(new StochasticSoilProfile(2.2, SoilProfileType.SoilProfile1D, 2)); - - // Precondition - pipingInput.StochasticSoilModel = stochasticSoilModel; - Assert.AreEqual(stochasticSoilProfile, pipingInput.StochasticSoilProfile); - - // Call - pipingInput.StochasticSoilModel = stochasticSoilModelWithMiltipleProfiles; - - // Assert - Assert.IsNull(pipingInput.StochasticSoilProfile); - } - - [Test] public void ExitPointL_SetToValueWithTooManyDecimalPlaces_ValueIsRounded() { // Setup Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PresentationObjects/PipingContextTest.cs =================================================================== diff -u -rd2a52a4a27bba0bcf0437e905fe3985484c0219c -r614c1aa4bf54ed2852d93a58ba8d49b549d5f46c --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PresentationObjects/PipingContextTest.cs (.../PipingContextTest.cs) (revision d2a52a4a27bba0bcf0437e905fe3985484c0219c) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PresentationObjects/PipingContextTest.cs (.../PipingContextTest.cs) (revision 614c1aa4bf54ed2852d93a58ba8d49b549d5f46c) @@ -1,10 +1,30 @@ -using System; +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; using System.Collections.Generic; using System.Linq; using Core.Common.Base; using NUnit.Framework; using Rhino.Mocks; -using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Piping.Data; using Ringtoets.Piping.Data.TestUtil; Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PresentationObjects/PipingInputContextTest.cs =================================================================== diff -u -ra9aafffab97152303562110b1d789bacb465ce24 -r614c1aa4bf54ed2852d93a58ba8d49b549d5f46c --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PresentationObjects/PipingInputContextTest.cs (.../PipingInputContextTest.cs) (revision a9aafffab97152303562110b1d789bacb465ce24) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PresentationObjects/PipingInputContextTest.cs (.../PipingInputContextTest.cs) (revision 614c1aa4bf54ed2852d93a58ba8d49b549d5f46c) @@ -1,13 +1,34 @@ -using System; -using System.Linq; +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. +using System; +using System.Collections.Generic; +using System.Linq; using Core.Common.Base; +using Core.Common.Base.Geometry; using Core.Common.TestUtil; using NUnit.Framework; - using Rhino.Mocks; -using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Piping.Data; using Ringtoets.Piping.Data.TestUtil; using Ringtoets.Piping.Forms.PresentationObjects; @@ -23,14 +44,20 @@ { // Setup var pipingInput = new PipingInput(new GeneralPipingInput()); - var surfaceLines = new[] { new RingtoetsPipingSurfaceLine() }; - var stochasticSoilModels = new[] { new TestStochasticSoilModel() }; + var surfaceLines = new[] + { + new RingtoetsPipingSurfaceLine() + }; + var stochasticSoilModels = new[] + { + new TestStochasticSoilModel() + }; var mocks = new MockRepository(); var assessmentSection = mocks.StrictMock(); mocks.ReplayAll(); - + // Call var context = new PipingInputContext(pipingInput, surfaceLines, stochasticSoilModels, assessmentSection); @@ -66,6 +93,218 @@ } [Test] + public void SetStochasticSoilModelAndStochasticSoilProfileForSurfaceLine_NewStochasticSoilModelWithOneStochasticSoilProfile_SetsStochasticSoilProfile() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.StrictMock(); + mocks.ReplayAll(); + + var surfaceLine = new RingtoetsPipingSurfaceLine + { + Name = "Surface line 1", + ReferenceLineIntersectionWorldPoint = new Point2D(0.0, 0.0) + }; + surfaceLine.SetGeometry(new[] + { + new Point3D(0.0, 5.0, 0.0), + new Point3D(0.0, 0.0, 1.0), + new Point3D(0.0, -5.0, 0.0) + }); + + var stochasticSoilProfile = new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, 1) + { + SoilProfile = new PipingSoilProfile("Profile 1", -10.0, new[] + { + new PipingSoilLayer(-5.0), + new PipingSoilLayer(-2.0), + new PipingSoilLayer(1.0) + }, SoilProfileType.SoilProfile1D, 1) + }; + + var stochasticSoilModel = new StochasticSoilModel(1, "Model A", "Model B") + { + Geometry = + { + new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) + }, + StochasticSoilProfiles = + { + stochasticSoilProfile + } + }; + + var pipingInput = new PipingInput(new GeneralPipingInput()); + + pipingInput.SurfaceLine = surfaceLine; + + PipingInputContext pipingInputContext = new PipingInputContext(pipingInput, new[] + { + surfaceLine + }, new[] + { + stochasticSoilModel + }, assessmentSection); + + // Call + pipingInputContext.SetStochasticSoilModelAndStochasticSoilProfileForSurfaceLine(); + + // Assert + Assert.AreEqual(stochasticSoilModel, pipingInputContext.WrappedData.StochasticSoilModel); + Assert.AreEqual(stochasticSoilProfile, pipingInputContext.WrappedData.StochasticSoilProfile); + + mocks.VerifyAll(); + } + + [Test] + public void SetStochasticSoilModelAndStochasticSoilProfileForSurfaceLine_NewStochasticSoilModelWithMultipleStochasticSoilProfiles_SetsStochasticSoilProfileToNull() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.StrictMock(); + mocks.ReplayAll(); + + var surfaceLine = new RingtoetsPipingSurfaceLine + { + Name = "Surface line 1", + ReferenceLineIntersectionWorldPoint = new Point2D(0.0, 0.0) + }; + surfaceLine.SetGeometry(new[] + { + new Point3D(0.0, 5.0, 0.0), + new Point3D(0.0, 0.0, 1.0), + new Point3D(0.0, -5.0, 0.0) + }); + + var stochasticSoilModel = new StochasticSoilModel(1, "Model A", "Model B") + { + Geometry = + { + new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) + }, + StochasticSoilProfiles = + { + new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, 1) + { + SoilProfile = new PipingSoilProfile("Profile 1", -10.0, new[] + { + new PipingSoilLayer(-5.0), + new PipingSoilLayer(-2.0), + new PipingSoilLayer(1.0) + }, SoilProfileType.SoilProfile1D, 1) + }, + new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, 1) + { + SoilProfile = new PipingSoilProfile("Profile 2", -10.0, new[] + { + new PipingSoilLayer(-5.0), + new PipingSoilLayer(-2.0), + new PipingSoilLayer(1.0) + }, SoilProfileType.SoilProfile1D, 2) + } + } + }; + + var pipingInput = new PipingInput(new GeneralPipingInput()); + pipingInput.SurfaceLine = surfaceLine; + + PipingInputContext pipingInputContext = new PipingInputContext(pipingInput, new[] + { + surfaceLine + }, new[] + { + stochasticSoilModel + }, assessmentSection); + + // Call + pipingInputContext.SetStochasticSoilModelAndStochasticSoilProfileForSurfaceLine(); + + // Assert + Assert.AreEqual(stochasticSoilModel, pipingInputContext.WrappedData.StochasticSoilModel); + Assert.IsNull(pipingInputContext.WrappedData.StochasticSoilProfile); + + mocks.VerifyAll(); + } + + [Test] + public void SetStochasticSoilModelAndStochasticSoilProfileForSurfaceLine_MatchingStochasticSoilProfileAlreadySet_DoesNotSetsStochasticSoilProfileToNull() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.StrictMock(); + mocks.ReplayAll(); + + var surfaceLine = new RingtoetsPipingSurfaceLine + { + Name = "Surface line 1", + ReferenceLineIntersectionWorldPoint = new Point2D(0.0, 0.0) + }; + surfaceLine.SetGeometry(new[] + { + new Point3D(0.0, 5.0, 0.0), + new Point3D(0.0, 0.0, 1.0), + new Point3D(0.0, -5.0, 0.0) + }); + + + + var stochasticSoilProfile = new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, 1) + { + SoilProfile = new PipingSoilProfile("Profile 1", -10.0, new[] + { + new PipingSoilLayer(-5.0), + new PipingSoilLayer(-2.0), + new PipingSoilLayer(1.0) + }, SoilProfileType.SoilProfile1D, 1) + }; + + var stochasticSoilModel = new StochasticSoilModel(1, "Model A", "Model B") + { + Geometry = + { + new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) + }, + StochasticSoilProfiles = + { + stochasticSoilProfile, + new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, 1) + { + SoilProfile = new PipingSoilProfile("Profile 2", -10.0, new[] + { + new PipingSoilLayer(-5.0), + new PipingSoilLayer(-2.0), + new PipingSoilLayer(1.0) + }, SoilProfileType.SoilProfile1D, 2) + } + } + }; + + var pipingInput = new PipingInput(new GeneralPipingInput()); + pipingInput.SurfaceLine = surfaceLine; + + PipingInputContext pipingInputContext = new PipingInputContext(pipingInput, new[] + { + surfaceLine + }, new[] + { + stochasticSoilModel + }, assessmentSection); + + // Precondition + pipingInputContext.WrappedData.StochasticSoilModel = stochasticSoilModel; + pipingInputContext.WrappedData.StochasticSoilProfile = stochasticSoilProfile; + + // Call + pipingInputContext.SetStochasticSoilModelAndStochasticSoilProfileForSurfaceLine(); + + // Assert + Assert.AreEqual(stochasticSoilModel, pipingInputContext.WrappedData.StochasticSoilModel); + Assert.AreEqual(stochasticSoilProfile, pipingInputContext.WrappedData.StochasticSoilProfile); + + mocks.VerifyAll(); + } + + [Test] public void Attach_Observer_ObserverAttachedToPipingInput() { // Setup Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/PipingInputContextPropertiesTest.cs =================================================================== diff -u -r0faea705e7f83205f8420c52edda8a5473485bcd -r614c1aa4bf54ed2852d93a58ba8d49b549d5f46c --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/PipingInputContextPropertiesTest.cs (.../PipingInputContextPropertiesTest.cs) (revision 0faea705e7f83205f8420c52edda8a5473485bcd) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/PipingInputContextPropertiesTest.cs (.../PipingInputContextPropertiesTest.cs) (revision 614c1aa4bf54ed2852d93a58ba8d49b549d5f46c) @@ -162,7 +162,7 @@ var mocks = new MockRepository(); var assessmentSectionMock = mocks.StrictMock(); var projectObserver = mocks.StrictMock(); - int numberProperties = 8; + int numberProperties = 9; projectObserver.Expect(o => o.UpdateObserver()).Repeat.Times(numberProperties); mocks.ReplayAll();