Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Importers/WaveConditionsCalculationConfigurationImporter.cs =================================================================== diff -u -r7f1ba7a4362a13d9b0e8dca02691bb3eae74bd79 -r28b8182ae19e0d84eb705a013149c05ef99a94dc --- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Importers/WaveConditionsCalculationConfigurationImporter.cs (.../WaveConditionsCalculationConfigurationImporter.cs) (revision 7f1ba7a4362a13d9b0e8dca02691bb3eae74bd79) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Importers/WaveConditionsCalculationConfigurationImporter.cs (.../WaveConditionsCalculationConfigurationImporter.cs) (revision 28b8182ae19e0d84eb705a013149c05ef99a94dc) @@ -26,6 +26,7 @@ using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.IO; using Ringtoets.Common.IO.Exceptions; using Ringtoets.Common.IO.FileImporters; using Ringtoets.Revetment.Data; @@ -46,7 +47,6 @@ { private readonly IEnumerable hydraulicBoundaryLocations; private readonly IEnumerable foreshoreProfiles; - private readonly WaveConditionsInputStepSizeTypeConverter waveConditionsInputStepSizeConverter; /// /// Creates a new instance of . @@ -75,8 +75,6 @@ } this.hydraulicBoundaryLocations = hydraulicBoundaryLocations; this.foreshoreProfiles = foreshoreProfiles; - - waveConditionsInputStepSizeConverter = new WaveConditionsInputStepSizeTypeConverter(); } protected override WaveConditionsCalculationConfigurationReader CreateCalculationConfigurationReader(string xmlFilePath) @@ -96,6 +94,7 @@ ReadStepSize(readCalculation, waveConditionsCalculation); ReadForeshoreProfile(readCalculation, waveConditionsCalculation); ReadOrientation(readCalculation, waveConditionsCalculation); + ReadWaveReduction(readCalculation, waveConditionsCalculation); return waveConditionsCalculation; } @@ -173,7 +172,8 @@ { if (readCalculation.StepSize != null) { - calculation.InputParameters.StepSize = (WaveConditionsInputStepSize) waveConditionsInputStepSizeConverter.ConvertFrom(readCalculation.StepSize.ToString()); + calculation.InputParameters.StepSize = (WaveConditionsInputStepSize) + new WaveConditionsInputStepSizeTypeConverter().ConvertFrom(readCalculation.StepSize.ToString()); } } @@ -200,6 +200,12 @@ } } + /// + /// Reads the orientation. + /// + /// The calculation read from the imported file. + /// The calculation to configure. + /// Thrown when the orientation is invalid. private static void ReadOrientation(ReadWaveConditionsCalculation readCalculation, IWaveConditionsCalculation calculation) { if (readCalculation.Orientation.HasValue) @@ -211,5 +217,66 @@ string.Format(Resources.WaveConditionsCalculationConfigurationImporter_ReadOrientation_Orientation_0_invalid, orientation)); } } + + /// + /// Reads the wave reduction parameters. + /// + /// The calculation read from the imported file. + /// The calculation to configure. + /// Thrown when there is an invalid + /// wave reduction parameter defined. + private static void ReadWaveReduction(ReadWaveConditionsCalculation readCalculation, IWaveConditionsCalculation calculation) + { + ValidateWaveReduction(readCalculation, calculation); + + if (readCalculation.UseForeshore.HasValue) + { + calculation.InputParameters.UseForeshore = (bool) readCalculation.UseForeshore; + } + + if (readCalculation.UseBreakWater.HasValue) + { + calculation.InputParameters.UseBreakWater = (bool) readCalculation.UseBreakWater; + } + + if (readCalculation.BreakWaterType != null) + { + calculation.InputParameters.BreakWater.Type = (BreakWaterType) new BreakWaterTypeTypeConverter().ConvertFrom(readCalculation.BreakWaterType); + } + + if (readCalculation.BreakWaterHeight.HasValue) + { + calculation.InputParameters.BreakWater.Height = (RoundedDouble) readCalculation.BreakWaterHeight; + } + } + + /// + /// Validation to check if the defined wave reduction parameters are valid. + /// + /// The calculation read from the imported file. + /// The calculation to configure. + /// Thrown when there is an + /// invalid wave reduction parameter defined. + private static void ValidateWaveReduction(ReadWaveConditionsCalculation readCalculation, IWaveConditionsCalculation calculation) + { + if (calculation.InputParameters.ForeshoreProfile == null) + { + if (readCalculation.UseBreakWater.HasValue + || readCalculation.UseForeshore.HasValue + || readCalculation.BreakWaterHeight != null + || readCalculation.BreakWaterType != null) + { + throw new CriticalFileValidationException(Resources.WaveConditionsCalculationConfigurationImporter_ValidateWaveReduction_No_foreshore_profile_provided); + } + } + else if (!calculation.InputParameters.ForeshoreGeometry.Any()) + { + if (readCalculation.UseForeshore.HasValue) + { + throw new CriticalFileValidationException(string.Format(Resources.WaveConditionsCalculationConfigurationImporter_ValidateWaveReduction_Foreshore_profile_0_has_no_geometry_and_cannot_be_used, + readCalculation.ForeshoreProfile)); + } + } + } } } \ No newline at end of file Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Properties/Resources.Designer.cs =================================================================== diff -u -r7f1ba7a4362a13d9b0e8dca02691bb3eae74bd79 -r28b8182ae19e0d84eb705a013149c05ef99a94dc --- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 7f1ba7a4362a13d9b0e8dca02691bb3eae74bd79) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 28b8182ae19e0d84eb705a013149c05ef99a94dc) @@ -1,4 +1,25 @@ -//------------------------------------------------------------------------------ +// 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. + +//------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.42000 @@ -186,6 +207,26 @@ } /// + /// Looks up a localized string similar to Het opgegeven voorlandprofiel '{0}' heeft geen geometrie en kan daarom niet gebruikt worden.. + /// + internal static string WaveConditionsCalculationConfigurationImporter_ValidateWaveReduction_Foreshore_profile_0_has_no_geometry_and_cannot_be_used { + get { + return ResourceManager.GetString("WaveConditionsCalculationConfigurationImporter_ValidateWaveReduction_Foreshore_pr" + + "ofile_0_has_no_geometry_and_cannot_be_used", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Er is geen voorlandprofiel opgegeven om golfreductie parameters aan toe te voegen.. + /// + internal static string WaveConditionsCalculationConfigurationImporter_ValidateWaveReduction_No_foreshore_profile_provided { + get { + return ResourceManager.GetString("WaveConditionsCalculationConfigurationImporter_ValidateWaveReduction_No_foreshore" + + "_profile_provided", resourceCulture); + } + } + + /// /// Looks up a localized string similar to {0} Er zijn geen golfrandvoorwaarden geëxporteerd.. /// internal static string WaveConditionsExporter_Error_Exception_0_no_WaveConditions_exported { Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Properties/Resources.resx =================================================================== diff -u -r7f1ba7a4362a13d9b0e8dca02691bb3eae74bd79 -r28b8182ae19e0d84eb705a013149c05ef99a94dc --- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Properties/Resources.resx (.../Resources.resx) (revision 7f1ba7a4362a13d9b0e8dca02691bb3eae74bd79) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Properties/Resources.resx (.../Resources.resx) (revision 28b8182ae19e0d84eb705a013149c05ef99a94dc) @@ -163,4 +163,10 @@ Het voorlandprofiel '{0}' bestaat niet. + + Het opgegeven voorlandprofiel '{0}' heeft geen geometrie en kan daarom niet gebruikt worden. + + + Er is geen voorlandprofiel opgegeven om golfreductie parameters aan toe te voegen. + \ No newline at end of file Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Importers/WaveConditionsCalculationConfigurationImporterTest.cs =================================================================== diff -u -r7f1ba7a4362a13d9b0e8dca02691bb3eae74bd79 -r28b8182ae19e0d84eb705a013149c05ef99a94dc --- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Importers/WaveConditionsCalculationConfigurationImporterTest.cs (.../WaveConditionsCalculationConfigurationImporterTest.cs) (revision 7f1ba7a4362a13d9b0e8dca02691bb3eae74bd79) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Importers/WaveConditionsCalculationConfigurationImporterTest.cs (.../WaveConditionsCalculationConfigurationImporterTest.cs) (revision 28b8182ae19e0d84eb705a013149c05ef99a94dc) @@ -24,6 +24,7 @@ using System.Linq; using Core.Common.Base; using Core.Common.Base.Data; +using Core.Common.Base.Geometry; using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data; @@ -167,14 +168,76 @@ } [Test] + public void Import_WaveReductionWithoutForeshoreProfile_LogMessageAndContinueImport() + { + // Setup + string filePath = Path.Combine(path, "validConfigurationCalculationContainingWaveReductionWithoutForeshoreProfile.xml"); + + var calculationGroup = new CalculationGroup(); + var importer = new WaveConditionsCalculationConfigurationImporter( + filePath, + calculationGroup, + Enumerable.Empty(), + Enumerable.Empty()); + + // Call + var successful = false; + Action call = () => successful = importer.Import(); + + // Assert + const string expectedMessage = "Er is geen voorlandprofiel opgegeven om golfreductie parameters aan toe te voegen. Berekening 'Berekening 1' is overgeslagen."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + Assert.IsTrue(successful); + CollectionAssert.IsEmpty(calculationGroup.Children); + } + + [Test] + public void Import_UseForeshoreButProfileWithoutGeometry_LogMessageAndContinueImport() + { + // Setup + string filePath = Path.Combine(path, "validConfigurationCalculationContainingUseForeshoreForeshoreProfileWithoutGeometry.xml"); + + var calculationGroup = new CalculationGroup(); + var foreshoreProfile = new TestForeshoreProfile("Voorlandprofiel"); + var importer = new WaveConditionsCalculationConfigurationImporter( + filePath, + calculationGroup, + Enumerable.Empty(), + new[] + { + foreshoreProfile + }); + + // Call + var successful = false; + Action call = () => successful = importer.Import(); + + // Assert + const string expectedMessage = "Het opgegeven voorlandprofiel 'Voorlandprofiel' heeft geen geometrie en kan daarom niet gebruikt worden. Berekening 'Berekening 1' is overgeslagen."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + Assert.IsTrue(successful); + CollectionAssert.IsEmpty(calculationGroup.Children); + } + + [Test] public void Import_ValidConfigurationWithValidData_DataAddedToModel() { // Setup string filePath = Path.Combine(path, "validConfigurationFullCalculation.xml"); var calculationGroup = new CalculationGroup(); var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "HRlocatie", 10, 20); - var foreshoreProfile = new TestForeshoreProfile("Voorlandprofiel"); + var foreshoreProfile = new ForeshoreProfile(new Point2D(0, 0), new [] + { + new Point2D(0, 0), + new Point2D(1, 1), + new Point2D(2, 2) + },new BreakWater(BreakWaterType.Caisson, 0), new ForeshoreProfile.ConstructionProperties + { + Id = "id", + Name = "Voorlandprofiel" + }); + var importer = new WaveConditionsCalculationConfigurationImporter( filePath, calculationGroup, @@ -205,7 +268,14 @@ LowerBoundaryWaterLevels = (RoundedDouble) 4, StepSize = WaveConditionsInputStepSize.Half, ForeshoreProfile = foreshoreProfile, - Orientation = (RoundedDouble) 5.5 + Orientation = (RoundedDouble) 5.5, + UseForeshore = false, + UseBreakWater = true, + BreakWater = + { + Height = (RoundedDouble) 6.6, + Type = BreakWaterType.Caisson + } } }; @@ -224,6 +294,10 @@ Assert.AreEqual(expectedCalculation.InputParameters.StepSize, actualCalculation.InputParameters.StepSize); Assert.AreEqual(expectedCalculation.InputParameters.Orientation, actualCalculation.InputParameters.Orientation); Assert.AreEqual(expectedCalculation.InputParameters.ForeshoreProfile, actualCalculation.InputParameters.ForeshoreProfile); + Assert.AreEqual(expectedCalculation.InputParameters.UseForeshore, actualCalculation.InputParameters.UseForeshore); + Assert.AreEqual(expectedCalculation.InputParameters.UseBreakWater, actualCalculation.InputParameters.UseBreakWater); + Assert.AreEqual(expectedCalculation.InputParameters.BreakWater.Height, actualCalculation.InputParameters.BreakWater.Height); + Assert.AreEqual(expectedCalculation.InputParameters.BreakWater.Type, actualCalculation.InputParameters.BreakWater.Type); } private class SimpleWaveConditionsCalculation : Observable, IWaveConditionsCalculation Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/test-data/WaveConditionsCalculationConfigurationImporter/validConfigurationCalculationContainingUseForeshoreForeshoreProfileWithoutGeometry.xml =================================================================== diff -u --- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/test-data/WaveConditionsCalculationConfigurationImporter/validConfigurationCalculationContainingUseForeshoreForeshoreProfileWithoutGeometry.xml (revision 0) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/test-data/WaveConditionsCalculationConfigurationImporter/validConfigurationCalculationContainingUseForeshoreForeshoreProfileWithoutGeometry.xml (revision 28b8182ae19e0d84eb705a013149c05ef99a94dc) @@ -0,0 +1,9 @@ + + + + Voorlandprofiel + + false + + + Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/test-data/WaveConditionsCalculationConfigurationImporter/validConfigurationCalculationContainingWaveReductionWithoutForeshoreProfile.xml =================================================================== diff -u --- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/test-data/WaveConditionsCalculationConfigurationImporter/validConfigurationCalculationContainingWaveReductionWithoutForeshoreProfile.xml (revision 0) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/test-data/WaveConditionsCalculationConfigurationImporter/validConfigurationCalculationContainingWaveReductionWithoutForeshoreProfile.xml (revision 28b8182ae19e0d84eb705a013149c05ef99a94dc) @@ -0,0 +1,11 @@ + + + + + true + caisson + 6.6 + false + + +