Index: Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj =================================================================== diff -u -r92372ba046f1df1593268f692339a53dc1b94e12 -r04bb0523abe526947e76b0701728506e7293792c --- Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj (.../Ringtoets.Common.Data.csproj) (revision 92372ba046f1df1593268f692339a53dc1b94e12) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj (.../Ringtoets.Common.Data.csproj) (revision 04bb0523abe526947e76b0701728506e7293792c) @@ -85,6 +85,7 @@ + Index: Ringtoets/Common/src/Ringtoets.Common.Data/Structures/StructuresInputBase.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Data/Structures/StructuresInputBase.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Structures/StructuresInputBase.cs (revision 04bb0523abe526947e76b0701728506e7293792c) @@ -0,0 +1,116 @@ +// 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.Linq; +using Core.Common.Base; +using Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; + +namespace Ringtoets.Common.Data.Structures +{ + /// + /// Base class that holds all structures calculation specific input parameters. + /// + public abstract class StructuresInputBase : Observable, ICalculationInput, IUseBreakWater, IUseForeshore + where T : StructureBase + { + private T structure; + private ForeshoreProfile foreshoreProfile; + + protected StructuresInputBase() + { + UpdateForeshoreProperties(); + } + + #region Foreshore Profile + + /// + /// Gets or sets the foreshore profile. + /// + public ForeshoreProfile ForeshoreProfile + { + get + { + return foreshoreProfile; + } + set + { + foreshoreProfile = value; + UpdateForeshoreProperties(); + } + } + + /// + /// Gets or sets whether the needs to be taken into account. + /// + public bool UseBreakWater { get; set; } + + /// + /// Gets or sets whether the needs to be taken into account. + /// + public bool UseForeshore { get; set; } + + /// + /// Gets the geometry of the foreshore. + /// + public RoundedPoint2DCollection ForeshoreGeometry + { + get + { + return foreshoreProfile != null + ? foreshoreProfile.Geometry + : new RoundedPoint2DCollection(2, Enumerable.Empty()); + } + } + + /// + /// Gets the . + /// + public BreakWater BreakWater { get; private set; } + + private void UpdateForeshoreProperties() + { + if (foreshoreProfile == null) + { + UseForeshore = false; + UseBreakWater = false; + BreakWater = GetDefaultBreakWaterProperties(); + } + else + { + UseForeshore = foreshoreProfile.Geometry.Count() > 1; + UseBreakWater = foreshoreProfile.HasBreakWater; + BreakWater = foreshoreProfile.HasBreakWater ? + new BreakWater(foreshoreProfile.BreakWater.Type, foreshoreProfile.BreakWater.Height) : + GetDefaultBreakWaterProperties(); + } + } + + private static BreakWater GetDefaultBreakWaterProperties() + { + return new BreakWater(BreakWaterType.Dam, 0.0); + } + + #endregion + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj =================================================================== diff -u -r238800aea14ad46b711dc0520d9416a05f6693ae -r04bb0523abe526947e76b0701728506e7293792c --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj (.../Ringtoets.Common.Data.Test.csproj) (revision 238800aea14ad46b711dc0520d9416a05f6693ae) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj (.../Ringtoets.Common.Data.Test.csproj) (revision 04bb0523abe526947e76b0701728506e7293792c) @@ -78,6 +78,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Structures/StructuresInputBaseTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Structures/StructuresInputBaseTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Structures/StructuresInputBaseTest.cs (revision 04bb0523abe526947e76b0701728506e7293792c) @@ -0,0 +1,155 @@ +// 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.Collections.Generic; +using Core.Common.Base; +using Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Structures; + +namespace Ringtoets.Common.Data.Test.Structures +{ + [TestFixture] + public class StructuresInputBaseTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var input = new SimpleStructuresInput(); + + // Assert + Assert.IsInstanceOf(input); + Assert.IsInstanceOf(input); + Assert.IsInstanceOf(input); + Assert.IsInstanceOf(input); + } + + [Test] + [Combinatorial] + public void ForeshoreProfile_SetNewValue_InputSyncedAccordingly( + [Values(true, false)] bool withBreakWater, + [Values(true, false)] bool withValidForeshore) + { + // Setup + var input = new SimpleStructuresInput(); + BreakWaterType originalBreakWaterType = input.BreakWater.Type; + RoundedDouble originalBreakWaterHeight = input.BreakWater.Height; +// HydraulicBoundaryLocation originalHydraulicBoundaryLocation = input.HydraulicBoundaryLocation; + + var foreshoreGeometry = new List + { + new Point2D(2.2, 3.3) + }; + + if (withValidForeshore) + { + foreshoreGeometry.Add(new Point2D(4.4, 5.5)); + } + + BreakWater breakWater = null; + if (withBreakWater) + { + var nonDefaultBreakWaterType = BreakWaterType.Wall; + var nonDefaultBreakWaterHeight = 5.5; + + // Precondition + Assert.AreNotEqual(nonDefaultBreakWaterType, input.BreakWater.Type); + Assert.AreNotEqual(nonDefaultBreakWaterHeight, input.BreakWater.Height); + + breakWater = new BreakWater(nonDefaultBreakWaterType, nonDefaultBreakWaterHeight); + } + + double orientation = 96; + var foreshoreProfile = new ForeshoreProfile(new Point2D(0, 0), + foreshoreGeometry.ToArray(), + breakWater, + new ForeshoreProfile.ConstructionProperties + { + Orientation = orientation + }); + + // Call + input.ForeshoreProfile = foreshoreProfile; + + // Assert + Assert.AreSame(foreshoreProfile, input.ForeshoreProfile); + Assert.AreEqual(withBreakWater, input.UseBreakWater); + Assert.AreEqual(withBreakWater ? foreshoreProfile.BreakWater.Type : originalBreakWaterType, input.BreakWater.Type); + Assert.AreEqual(withBreakWater ? foreshoreProfile.BreakWater.Height : originalBreakWaterHeight, input.BreakWater.Height); + Assert.AreEqual(withValidForeshore, input.UseForeshore); + CollectionAssert.AreEqual(foreshoreProfile.Geometry, input.ForeshoreGeometry); +// Assert.AreEqual(originalHydraulicBoundaryLocation, input.HydraulicBoundaryLocation); + } + + [Test] + public void Foreshore_SetNullValue_InputSyncedToDefaults() + { + // Setup + var input = new SimpleStructuresInput(); + BreakWaterType originalBreakWaterType = input.BreakWater.Type; + RoundedDouble originalBreakWaterHeight = input.BreakWater.Height; +// HydraulicBoundaryLocation originalHydraulicBoundaryLocation = input.HydraulicBoundaryLocation; + + var foreshoreProfile = new ForeshoreProfile(new Point2D(0, 0), + new[] + { + new Point2D(3.3, 4.4), + new Point2D(5.5, 6.6) + }, + new BreakWater(BreakWaterType.Caisson, 2.2), + new ForeshoreProfile.ConstructionProperties + { + Orientation = 96 + }); + + input.ForeshoreProfile = foreshoreProfile; + + // Precondition + Assert.AreSame(foreshoreProfile, input.ForeshoreProfile); + Assert.IsTrue(input.UseBreakWater); + Assert.AreNotEqual(originalBreakWaterType, input.BreakWater.Type); + Assert.AreNotEqual(originalBreakWaterHeight, input.BreakWater.Height); + Assert.IsTrue(input.UseForeshore); + CollectionAssert.IsNotEmpty(input.ForeshoreGeometry); +// Assert.AreEqual(originalHydraulicBoundaryLocation, input.HydraulicBoundaryLocation); + + // Call + input.ForeshoreProfile = null; + + // Assert + Assert.IsFalse(input.UseBreakWater); + Assert.AreEqual(originalBreakWaterType, input.BreakWater.Type); + Assert.AreEqual(originalBreakWaterHeight, input.BreakWater.Height); + Assert.IsFalse(input.UseForeshore); + CollectionAssert.IsEmpty(input.ForeshoreGeometry); +// Assert.AreEqual(originalHydraulicBoundaryLocation, input.HydraulicBoundaryLocation); + } + + private class SimpleStructuresInput : StructuresInputBase + { + + } + } +} \ No newline at end of file