Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator.Tests/Deltares.LayerOnSlopeTool.StiFileCreator.Tests.csproj =================================================================== diff -u -r3101 -r3147 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator.Tests/Deltares.LayerOnSlopeTool.StiFileCreator.Tests.csproj (.../Deltares.LayerOnSlopeTool.StiFileCreator.Tests.csproj) (revision 3101) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator.Tests/Deltares.LayerOnSlopeTool.StiFileCreator.Tests.csproj (.../Deltares.LayerOnSlopeTool.StiFileCreator.Tests.csproj) (revision 3147) @@ -28,6 +28,7 @@ + @@ -45,11 +46,19 @@ {83D297FB-CFC7-4154-AEB7-5E09E10E24D0} Deltares.LayerOnSlopeTool.Data + + {62171502-3f8d-45cb-992a-45c5ac0f8ce6} + Deltares.LayerOnSlopeTool.Io + {8484e328-75fc-4343-82d4-4e024ab06eb0} Deltares.LayerOnSlopeTool.StiFileCreator - + + + PreserveNewest + + \ No newline at end of file Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator.Tests/TestFiles/Example.mdb =================================================================== diff -u Binary files differ Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator/Deltares.LayerOnSlopeTool.StiFileCreator.csproj =================================================================== diff -u -r3100 -r3147 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator/Deltares.LayerOnSlopeTool.StiFileCreator.csproj (.../Deltares.LayerOnSlopeTool.StiFileCreator.csproj) (revision 3100) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator/Deltares.LayerOnSlopeTool.StiFileCreator.csproj (.../Deltares.LayerOnSlopeTool.StiFileCreator.csproj) (revision 3147) @@ -44,6 +44,7 @@ + @@ -66,6 +67,10 @@ {83d297fb-cfc7-4154-aeb7-5e09e10e24d0} Deltares.LayerOnSlopeTool.Data + + {62171502-3F8D-45CB-992A-45C5AC0F8CE6} + Deltares.LayerOnSlopeTool.Io + \ No newline at end of file Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator/StiFileCreatorInput.cs =================================================================== diff -u -r3099 -r3147 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator/StiFileCreatorInput.cs (.../StiFileCreatorInput.cs) (revision 3099) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator/StiFileCreatorInput.cs (.../StiFileCreatorInput.cs) (revision 3147) @@ -29,14 +29,22 @@ /// Gets or sets the input filename. /// The input filename. public string InputFilename { get; set; } + /// Gets or sets the surfaceline. /// The surfaceline. public SurfaceLine SurfaceLine { get; set; } + /// Gets or sets the x offset. /// The x offset. public double XOffset { get; set; } + /// Gets or sets the name of the dike material. /// The name of the dike material. public string DikeMaterialName { get; set; } + + /// Gets or sets the output filename. + /// The output filename. + public string OutputFilename { get; set; } + } } \ No newline at end of file Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator/ConversionHelper.cs =================================================================== diff -u --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator/ConversionHelper.cs (revision 0) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator/ConversionHelper.cs (revision 3147) @@ -0,0 +1,55 @@ +// Copyright (C) Stichting Deltares 2020. All rights reserved. +// +// This file is part of the Dam Engine. +// +// The Dam Engine is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero 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 Deltares.LayerOnSlopeTool.Io; + +namespace Deltares.LayerOnSlopeTool.StiFileCreator +{ + public class ConversionHelper + { + public static CharacteristicPointType ConvertDomainToIo(Data.CharacteristicPointType pointType) + { + var translationTable = new Dictionary() + { + {Data.CharacteristicPointType.None, Io.CharacteristicPointType.Unknown}, + {Data.CharacteristicPointType.SurfaceLevelOutside, Io.CharacteristicPointType.SurfaceLevelOutside}, + {Data.CharacteristicPointType.DikeToeAtRiver, Io.CharacteristicPointType.DikeToeAtRiver}, + {Data.CharacteristicPointType.DikeTopAtRiver, Io.CharacteristicPointType.DikeTopAtRiver}, + {Data.CharacteristicPointType.DikeTopAtPolder, Io.CharacteristicPointType.DikeTopAtPolder}, + {Data.CharacteristicPointType.DikeToeAtPolder, Io.CharacteristicPointType.DikeToeAtPolder}, + {Data.CharacteristicPointType.SurfaceLevelInside, Io.CharacteristicPointType.SurfaceLevelInside}, + + {Data.CharacteristicPointType.BottomRiverChannel, Io.CharacteristicPointType.Unknown}, + {Data.CharacteristicPointType.BottomDitchDikeSide, Io.CharacteristicPointType.Unknown}, + {Data.CharacteristicPointType.BottomDitchPolderSide, Io.CharacteristicPointType.Unknown}, + {Data.CharacteristicPointType.DikeLine, Io.CharacteristicPointType.Unknown}, + {Data.CharacteristicPointType.DitchDikeSide, Io.CharacteristicPointType.Unknown}, + {Data.CharacteristicPointType.InsertRiverChannel, Io.CharacteristicPointType.Unknown}, + {Data.CharacteristicPointType.ShoulderBaseInside, Io.CharacteristicPointType.Unknown}, + {Data.CharacteristicPointType.ShoulderTopInside, Io.CharacteristicPointType.Unknown}, + {Data.CharacteristicPointType.TrafficLoadInside, Io.CharacteristicPointType.Unknown}, + {Data.CharacteristicPointType.TrafficLoadOutside, Io.CharacteristicPointType.Unknown}, + }; + return translationTable[pointType]; + } + } +} \ No newline at end of file Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator/StiFileCreator.cs =================================================================== diff -u -r3099 -r3147 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator/StiFileCreator.cs (.../StiFileCreator.cs) (revision 3099) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator/StiFileCreator.cs (.../StiFileCreator.cs) (revision 3147) @@ -19,8 +19,10 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using Deltares.LayerOnSlopeTool.Io; using System; using System.IO; +using System.Text; namespace Deltares.LayerOnSlopeTool.StiFileCreator { @@ -29,18 +31,104 @@ { /// Create a new .sti file based on the defined input. /// The sti file creator input. - /// The output filename. - public static void ProcessFile(StiFileCreatorInput stiFileCreatorInput, string outputFilename) + public static void ProcessFile(StiFileCreatorInput stiFileCreatorInput) { ValidateInput(stiFileCreatorInput); + // TODO process file + var mStabDAMInterface = new DGSMStabDAMInterface(); + IoMStabDamDoc ioMStabDamDoc = CreateMStabDamDocFromInput(stiFileCreatorInput); + tnsPrefixDamMStabDoc xmlDamMStabDoc = FillXmlDamMStabDocFromIo.FillXmlDamMStabDoc(ioMStabDamDoc); + string xmlString = MStabDamXmlSerializer.SaveDamMStabDocAsXmlString(xmlDamMStabDoc); + File.WriteAllText(stiFileCreatorInput.OutputFilename + ".xml", xmlString, Encoding.Unicode); + int result = mStabDAMInterface.CreateProjectFile(xmlString); + if (result != 0) + { + throw new Exception(String.Format("Error {0} in DGSMStabDamDll.CreateProjectFile()", result)); + } } + private static IoMStabDamDoc CreateMStabDamDocFromInput(StiFileCreatorInput stiFileCreatorInput) + { + var ioMStabDamDoc = new IoMStabDamDoc(); + ioMStabDamDoc.MStabInput.MStabFileName = stiFileCreatorInput.OutputFilename; + ioMStabDamDoc.MStabInput.SoilDbName = @"TestFiles\Example.mdb"; // TODO: make soilbase optionals + ioMStabDamDoc.MStabInput.Model.CalculationModel = ModelType.Bishop; + ioMStabDamDoc.MStabInput.Model.GridPosition = GridPositionType.Right; + ioMStabDamDoc.MStabInput.Model.Probabilistic = false; + ioMStabDamDoc.MStabInput.Model.SearchMethod = SearchMethodType.Grid; + ioMStabDamDoc.MStabInput.Model.ShearStrength = ShearStrengthType.CPhi; + ioMStabDamDoc.MStabInput.GeometryCreationOptions.SoilGeometryType = SoilGeometryType.SoilGeometry2D; + ioMStabDamDoc.MStabInput.GeometryCreationOptions.MaterialForDike = stiFileCreatorInput.DikeMaterialName; + ioMStabDamDoc.MStabInput.GeometryCreationOptions.XOffsetSoilGeometry2DOrigin = stiFileCreatorInput.XOffset; + ioMStabDamDoc.MStabInput.GeometryCreationOptions.SoilGeometry2DFilename = stiFileCreatorInput.InputFilename; + double leftSide = stiFileCreatorInput.SurfaceLine.SurfaceLinePoints[0].XCoordinate; + double rightSide = stiFileCreatorInput.SurfaceLine.SurfaceLinePoints[stiFileCreatorInput.SurfaceLine.SurfaceLinePoints.Count - 1].XCoordinate; + double yLevel = -10; + var pl1 = new IoPlLine(); + pl1.Points.Add(new IoGeometryPoint() + { + X = leftSide, + Y = yLevel + }); + pl1.Points.Add(new IoGeometryPoint() + { + X = rightSide, + Y = yLevel + }); + ioMStabDamDoc.MStabInput.ExternalPlLines.Add(pl1); + var pl2 = new IoPlLine(); + pl2.Points.Add(new IoGeometryPoint() + { + X = leftSide, + Y = yLevel + }); + pl2.Points.Add(new IoGeometryPoint() + { + X = rightSide, + Y = yLevel + }); + ioMStabDamDoc.MStabInput.ExternalPlLines.Add(pl2); + var pl3 = new IoPlLine(); + pl3.Points.Add(new IoGeometryPoint() + { + X = leftSide, + Y = yLevel + }); + pl3.Points.Add(new IoGeometryPoint() + { + X = rightSide, + Y = yLevel + }); + ioMStabDamDoc.MStabInput.ExternalPlLines.Add(pl3); + for (int i = 0; i < stiFileCreatorInput.SurfaceLine.SurfaceLinePoints.Count; i++) + { + var surfaceLinePoint = stiFileCreatorInput.SurfaceLine.SurfaceLinePoints[i]; + ioMStabDamDoc.MStabInput.SurfaceLine.Add(new IoGeometryPoint() + { + X = surfaceLinePoint.XCoordinate, + Y = surfaceLinePoint.ZCoordinate + }); + CharacteristicPointType ioCharacteristicPointType = ConversionHelper.ConvertDomainToIo(surfaceLinePoint.PointType); + if (ioCharacteristicPointType != CharacteristicPointType.Unknown) + { + ioMStabDamDoc.MStabInput.CharacteristicPoints.Add(new IoCharacteristicPoint() + { + X = surfaceLinePoint.XCoordinate, + Y = surfaceLinePoint.ZCoordinate, + CharacteristicPointType = ioCharacteristicPointType + }); + } + } + + return ioMStabDamDoc; + } + private static void ValidateInput(StiFileCreatorInput stiFileCreatorInput) { if (stiFileCreatorInput == null) { - throw new ArgumentNullException("StiFileCreatorInput"); + throw new ArgumentNullException("stiFileCreatorInput"); } if (String.IsNullOrWhiteSpace(stiFileCreatorInput.InputFilename)) Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator.Tests/ConversionHelperTests.cs =================================================================== diff -u --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator.Tests/ConversionHelperTests.cs (revision 0) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator.Tests/ConversionHelperTests.cs (revision 3147) @@ -0,0 +1,52 @@ +// Copyright (C) Stichting Deltares 2020. All rights reserved. +// +// This file is part of the Dam Engine. +// +// The Dam Engine is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero 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 NUnit.Framework; + +namespace Deltares.LayerOnSlopeTool.StiFileCreator.Tests +{ + [TestFixture] + public class ConversionHelperTests + { + [TestCase(Data.CharacteristicPointType.None, Io.CharacteristicPointType.Unknown)] + [TestCase(Data.CharacteristicPointType.SurfaceLevelOutside, Io.CharacteristicPointType.SurfaceLevelOutside)] + [TestCase(Data.CharacteristicPointType.DikeToeAtRiver, Io.CharacteristicPointType.DikeToeAtRiver)] + [TestCase(Data.CharacteristicPointType.DikeTopAtRiver, Io.CharacteristicPointType.DikeTopAtRiver)] + [TestCase(Data.CharacteristicPointType.DikeTopAtPolder, Io.CharacteristicPointType.DikeTopAtPolder)] + [TestCase(Data.CharacteristicPointType.DikeToeAtPolder, Io.CharacteristicPointType.DikeToeAtPolder)] + [TestCase(Data.CharacteristicPointType.SurfaceLevelInside, Io.CharacteristicPointType.SurfaceLevelInside)] + [TestCase(Data.CharacteristicPointType.BottomRiverChannel, Io.CharacteristicPointType.Unknown)] + [TestCase(Data.CharacteristicPointType.BottomDitchDikeSide, Io.CharacteristicPointType.Unknown)] + [TestCase(Data.CharacteristicPointType.BottomDitchPolderSide, Io.CharacteristicPointType.Unknown)] + [TestCase(Data.CharacteristicPointType.DikeLine, Io.CharacteristicPointType.Unknown)] + [TestCase(Data.CharacteristicPointType.DitchDikeSide, Io.CharacteristicPointType.Unknown)] + [TestCase(Data.CharacteristicPointType.InsertRiverChannel, Io.CharacteristicPointType.Unknown)] + [TestCase(Data.CharacteristicPointType.ShoulderBaseInside, Io.CharacteristicPointType.Unknown)] + [TestCase(Data.CharacteristicPointType.ShoulderTopInside, Io.CharacteristicPointType.Unknown)] + [TestCase(Data.CharacteristicPointType.TrafficLoadInside, Io.CharacteristicPointType.Unknown)] + [TestCase(Data.CharacteristicPointType.TrafficLoadOutside, Io.CharacteristicPointType.Unknown)] + public void GivenDomainCharacteristicPointTypeWhenConvertingThenReturnsCorrectIoType(Data.CharacteristicPointType domainType, Io.CharacteristicPointType ioType) + { + Assert.AreEqual(ioType, ConversionHelper.ConvertDomainToIo(domainType)); + } + + } +} \ No newline at end of file Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Io/IoDamMStabInput.cs =================================================================== diff -u -r3138 -r3147 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Io/IoDamMStabInput.cs (.../IoDamMStabInput.cs) (revision 3138) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Io/IoDamMStabInput.cs (.../IoDamMStabInput.cs) (revision 3147) @@ -26,8 +26,8 @@ /// public class IoDamMStabInput { - /// Gets or sets the name of the m stab file. - /// The name of the m stab file. + /// Gets or sets the name of the mstab file. + /// The name of the mstab file. public string MStabFileName { get; set; } = ""; /// Gets or sets the name of the soil database. Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator.Tests/StiFileCreatorTests.cs =================================================================== diff -u -r3099 -r3147 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator.Tests/StiFileCreatorTests.cs (.../StiFileCreatorTests.cs) (revision 3099) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.StiFileCreator.Tests/StiFileCreatorTests.cs (.../StiFileCreatorTests.cs) (revision 3147) @@ -30,6 +30,7 @@ [TestFixture] public class StiFileCreatorTests { + private const string TestFileFolder = @"TestFiles\"; private static IEnumerable GetInvalidStiFileCreatorInput() { SurfaceLine validSurfaceLine = new SurfaceLine(); @@ -50,7 +51,7 @@ Assert.That( // Given Null Input // When Processing - () => StiFileCreator.ProcessFile(null, ""), + () => StiFileCreator.ProcessFile(null), // Then Exception Is Thrown Throws.TypeOf().With.Message.EqualTo( @@ -72,10 +73,86 @@ Assert.That( // When Processing - () => StiFileCreator.ProcessFile(stiFileCreatorInput, ""), + () => StiFileCreator.ProcessFile(stiFileCreatorInput), // Then Exception Is Thrown Throws.ArgumentException.With.Message.EqualTo(errorMessage)); } + + [Test] + [Ignore("Work in progress")] + public void GivenValidInputWhenProcessingThenValidStiFileIsGenerated() + { + // Given Valid Input + var surfaceLine = new SurfaceLine(); + surfaceLine.SurfaceLinePoints.Add(new SurfaceLinePoint() + { + XCoordinate = 1, + ZCoordinate = 1.5, + PointType = CharacteristicPointType.SurfaceLevelOutside, + }); + surfaceLine.SurfaceLinePoints.Add(new SurfaceLinePoint() + { + XCoordinate = 2.0, + ZCoordinate = 1.5, + PointType = CharacteristicPointType.None + }); + surfaceLine.SurfaceLinePoints.Add(new SurfaceLinePoint() + { + XCoordinate = 3.0, + ZCoordinate = 1.5, + PointType = CharacteristicPointType.DikeToeAtRiver + }); + surfaceLine.SurfaceLinePoints.Add(new SurfaceLinePoint() + { + XCoordinate = 5.0, + ZCoordinate = 2.5, + PointType = CharacteristicPointType.DikeTopAtRiver + }); + surfaceLine.SurfaceLinePoints.Add(new SurfaceLinePoint() + { + XCoordinate = 7.0, + ZCoordinate = 2.5, + PointType = CharacteristicPointType.DikeTopAtPolder + }); + surfaceLine.SurfaceLinePoints.Add(new SurfaceLinePoint() + { + XCoordinate = 10.0, + ZCoordinate = 0.5, + PointType = CharacteristicPointType.DikeToeAtPolder + }); + surfaceLine.SurfaceLinePoints.Add(new SurfaceLinePoint() + { + XCoordinate = 12.0, + ZCoordinate = 2.5, + PointType = CharacteristicPointType.None + }); + surfaceLine.SurfaceLinePoints.Add(new SurfaceLinePoint() + { + XCoordinate = 15, + ZCoordinate = 0.5, + PointType = CharacteristicPointType.SurfaceLevelInside + }); + string outputFilename = Path.Combine(TestFileFolder, "ExampleOutput.sti"); + var stiFileCreatorInput = new StiFileCreatorInput() + { + InputFilename = Path.Combine(TestFileFolder, "Example.sti"), + OutputFilename = outputFilename, + SurfaceLine = surfaceLine, + DikeMaterialName = "Clay", + XOffset = 0.0 + }; + + // When Processing + if (File.Exists(outputFilename)) + { + File.Delete(outputFilename); + } + StiFileCreator.ProcessFile(stiFileCreatorInput); + + // Then Valid Sti File Is Generated + Assert.IsTrue(File.Exists(outputFilename),String.Format("File '{0}' has not been created", outputFilename)); + } + } } \ No newline at end of file