Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator.Tests/LayerCreatorTests.cs =================================================================== diff -u -r3175 -r3176 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator.Tests/LayerCreatorTests.cs (.../LayerCreatorTests.cs) (revision 3175) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator.Tests/LayerCreatorTests.cs (.../LayerCreatorTests.cs) (revision 3176) @@ -20,18 +20,20 @@ // All rights reserved. using System.IO; +using Deltares.LayerOnSlopeTool.Data; using NUnit.Framework; namespace Deltares.LayerOnSlopeTool.LayerCreator.Tests { [TestFixture] public class LayerCreatorTests { - private string importFolder = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles\\InputFilesSingleFile"); - private string importFolderIncorrectLocation = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles\\InputFilesSingleFileMissingDikeMaterial"); - private string importFolderStiGeometryLeftOfSurfaceLine = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles\\InputFilesSingleFileStiGeometryLeftOfSurfaceLine"); + private readonly string importFolder = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles\\InputFilesSingleFile"); + private readonly string importFolderIncorrectLocation = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles\\InputFilesSingleFileMissingDikeMaterial"); + private readonly string importFolderStiGeometryLeftOfSurfaceLine = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles\\InputFilesSingleFileStiGeometryLeftOfSurfaceLine"); - private string outputFolder = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles\\OutputFilesSingleFile"); + private readonly string outputFolder = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles\\OutputFilesSingleFile"); + private const double Diff = 0.001; [Test] public void TestLayerCreatorForSingleFileWithLocationNoDikeMaterial() @@ -94,5 +96,76 @@ Assert.IsTrue(lines[0].Contains("Handling location")); } + [Test] + public void TestDetermineLoweredSurfaceLineForGivenLayerThickness() + { + var originalSurfaceLine = CreateSimpleStraightSurfaceLine(); + var loweredSurfaceLine = originalSurfaceLine.DetermineLoweredSurfaceLineForGivenLayerThickness(1); + Assert.AreEqual(8,loweredSurfaceLine.SurfaceLinePoints.Count); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[0].XCoordinate, Diff); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[0].ZCoordinate, Diff); + Assert.AreEqual(10, loweredSurfaceLine.SurfaceLinePoints[1].XCoordinate, Diff); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[1].ZCoordinate, Diff); + Assert.AreEqual(12, loweredSurfaceLine.SurfaceLinePoints[2].XCoordinate, Diff); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[2].ZCoordinate, Diff); + Assert.AreEqual(14, loweredSurfaceLine.SurfaceLinePoints[3].XCoordinate, Diff); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[3].ZCoordinate, Diff); + Assert.AreEqual(14.01, loweredSurfaceLine.SurfaceLinePoints[4].XCoordinate, Diff); + Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[4].ZCoordinate, Diff); + Assert.AreEqual(15.99, loweredSurfaceLine.SurfaceLinePoints[5].XCoordinate, Diff); + Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[5].ZCoordinate, Diff); + Assert.AreEqual(16, loweredSurfaceLine.SurfaceLinePoints[6].XCoordinate, Diff); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[6].ZCoordinate, Diff); + Assert.AreEqual(30, loweredSurfaceLine.SurfaceLinePoints[7].XCoordinate, Diff); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[7].ZCoordinate, Diff); + + } + + private SurfaceLine CreateSimpleStraightSurfaceLine() + { + var surfaceLine = new SurfaceLine(); + surfaceLine.SurfaceLineId = "SimpleStraightSurfaceLine"; + var point = new SurfaceLinePoint + { + XCoordinate = 0, ZCoordinate = 0, PointType = CharacteristicPointType.SurfaceLevelOutside + }; + surfaceLine.SurfaceLinePoints.Add(point); + var point1 = new SurfaceLinePoint + { + XCoordinate = 10, + ZCoordinate = 0, + PointType = CharacteristicPointType.DikeToeAtRiver + }; + surfaceLine.SurfaceLinePoints.Add(point1); + var point2 = new SurfaceLinePoint + { + XCoordinate = 12, + ZCoordinate = 0, + PointType = CharacteristicPointType.DikeTopAtRiver + }; + surfaceLine.SurfaceLinePoints.Add(point2); + var point3 = new SurfaceLinePoint + { + XCoordinate = 14, + ZCoordinate = 0, + PointType = CharacteristicPointType.DikeTopAtPolder + }; + surfaceLine.SurfaceLinePoints.Add(point3); + var point4 = new SurfaceLinePoint + { + XCoordinate = 16, + ZCoordinate = 0, + PointType = CharacteristicPointType.DikeToeAtPolder + }; + surfaceLine.SurfaceLinePoints.Add(point4); + var point5 = new SurfaceLinePoint + { + XCoordinate = 30, + ZCoordinate = 0, + PointType = CharacteristicPointType.SurfaceLevelInside + }; + surfaceLine.SurfaceLinePoints.Add(point5); + return surfaceLine; + } } } \ No newline at end of file Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator.Tests/Deltares.LayerOnSlopeTool.LayerCreator.Tests.csproj =================================================================== diff -u -r3175 -r3176 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator.Tests/Deltares.LayerOnSlopeTool.LayerCreator.Tests.csproj (.../Deltares.LayerOnSlopeTool.LayerCreator.Tests.csproj) (revision 3175) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator.Tests/Deltares.LayerOnSlopeTool.LayerCreator.Tests.csproj (.../Deltares.LayerOnSlopeTool.LayerCreator.Tests.csproj) (revision 3176) @@ -74,6 +74,10 @@ + + {83d297fb-cfc7-4154-aeb7-5e09e10e24d0} + Deltares.LayerOnSlopeTool.Data + {561636be-1d0b-412d-a419-d852ca17b26a} Deltares.LayerOnSlopeTool.LayerCreator Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/CsvImporterSurfaceLines.cs =================================================================== diff -u -r3148 -r3176 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/CsvImporterSurfaceLines.cs (.../CsvImporterSurfaceLines.cs) (revision 3148) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/CsvImporterSurfaceLines.cs (.../CsvImporterSurfaceLines.cs) (revision 3176) @@ -34,7 +34,7 @@ public class CsvImporterSurfaceLines { private readonly List surfaceLineRecords = new List(); - private List errorMessages = new List(); + private readonly List errorMessages = new List(); private const string LocationColumnName = "LocationId"; private const string ProfileNameColumnName = "Profielnaam"; private const string FirstXColumnName = "X1"; @@ -44,29 +44,26 @@ /// public class SurfaceLineRecord { - private IList xcoors = new List(); - private IList ycoors = new List(); - private IList zcoors = new List(); + private readonly IList xcoors = new List(); + private readonly IList ycoors = new List(); + private readonly IList zcoors = new List(); public string SurfaceLineId { get; set; } public int SurfaceLineRecordId { get; set; } public IList Xcoors { get { return xcoors; } - set { xcoors = value; } } public IList Ycoors { get { return ycoors; } - set { ycoors = value; } } public IList Zcoors { get { return zcoors; } - set { zcoors = value; } } } @@ -75,7 +72,7 @@ if (index < 0) { var csvHeaderFieldError = "The header misses the field: "; - throw new ArgumentException(string.Format("{0} : {1} {2}", fileName, csvHeaderFieldError, fieldName)); + throw new ArgumentException(string.Format("{0} : {1} {2} at index {3}.", fileName, csvHeaderFieldError, fieldName, index)); } } @@ -210,7 +207,6 @@ public List ErrorMessages { get { return errorMessages; } - set { errorMessages = value; } } } Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Data/SurfaceLine.cs =================================================================== diff -u -r3175 -r3176 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Data/SurfaceLine.cs (.../SurfaceLine.cs) (revision 3175) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Data/SurfaceLine.cs (.../SurfaceLine.cs) (revision 3176) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Collections.Generic; namespace Deltares.LayerOnSlopeTool.Data @@ -86,5 +87,74 @@ } return surfaceLinePoint; } + + public SurfaceLine DetermineLoweredSurfaceLineForGivenLayerThickness(double layerThickness) + { + const double diff = 1e-4; + var loweredSurfaceLine = new SurfaceLine(); + var dikeTopPolder = GetSurfaceLinePointByType(CharacteristicPointType.DikeTopAtPolder); + var dikeToePolder = GetSurfaceLinePointByType(CharacteristicPointType.DikeToeAtPolder); + foreach (var point in SurfaceLinePoints) + { + if (point.XCoordinate <= dikeTopPolder.XCoordinate) + { + var newPointUpToDikeTop = new SurfaceLinePoint + { + XCoordinate = point.XCoordinate, + ZCoordinate = point.ZCoordinate, + PointType = point.PointType + }; + loweredSurfaceLine.SurfaceLinePoints.Add(newPointUpToDikeTop); + if (Math.Abs(point.XCoordinate - dikeTopPolder.XCoordinate) < diff) + { + var newPointAtDikeTop = new SurfaceLinePoint + { + XCoordinate = point.XCoordinate + 0.01, + ZCoordinate = point.ZCoordinate - layerThickness, + PointType = CharacteristicPointType.None + }; + loweredSurfaceLine.SurfaceLinePoints.Add(newPointAtDikeTop); + } + } + else + { + if (point.XCoordinate > dikeTopPolder.XCoordinate && point.XCoordinate < dikeToePolder.XCoordinate) + { + var newPointLowered = new SurfaceLinePoint + { + XCoordinate = point.XCoordinate, + ZCoordinate = point.ZCoordinate - layerThickness, + PointType = point.PointType + }; + loweredSurfaceLine.SurfaceLinePoints.Add(newPointLowered); + } + else + { + if (Math.Abs(point.XCoordinate - dikeToePolder.XCoordinate) < diff) + { + var newPointAtDikeToe = new SurfaceLinePoint + { + XCoordinate = point.XCoordinate - 0.01, + ZCoordinate = point.ZCoordinate - layerThickness, + PointType = CharacteristicPointType.None + }; + loweredSurfaceLine.SurfaceLinePoints.Add(newPointAtDikeToe); + + } + if (point.XCoordinate >= dikeToePolder.XCoordinate) + { + var newPointBeyondDikeToe = new SurfaceLinePoint + { + XCoordinate = point.XCoordinate, + ZCoordinate = point.ZCoordinate, + PointType = point.PointType + }; + loweredSurfaceLine.SurfaceLinePoints.Add(newPointBeyondDikeToe); + } + } + } + } + return loweredSurfaceLine; + } } } \ No newline at end of file Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/CsvImporterCharacteristicPoints.cs =================================================================== diff -u -r3148 -r3176 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/CsvImporterCharacteristicPoints.cs (.../CsvImporterCharacteristicPoints.cs) (revision 3148) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/CsvImporterCharacteristicPoints.cs (.../CsvImporterCharacteristicPoints.cs) (revision 3176) @@ -35,8 +35,8 @@ /// public class CsvImporterCharacteristicPoints { - private List characteristicPointsRecords = new List(); - private List errorMessages = new List(); + private readonly List characteristicPointsRecords = new List(); + private readonly List errorMessages = new List(); public class CharPoint { @@ -65,7 +65,7 @@ if (index < 0) { var csvHeaderFieldError = "The header misses the field: "; - throw new ArgumentException(string.Format("{0} : {1} {2}", fileName, csvHeaderFieldError, fieldName)); + throw new ArgumentException(string.Format("{0} : {1} {2} at index {3}.", fileName, csvHeaderFieldError, fieldName, index)); } } @@ -504,7 +504,6 @@ public List ErrorMessages { get { return errorMessages; } - set { errorMessages = value; } } } Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/LayerCreator.cs =================================================================== diff -u -r3175 -r3176 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/LayerCreator.cs (.../LayerCreator.cs) (revision 3175) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/LayerCreator.cs (.../LayerCreator.cs) (revision 3176) @@ -151,49 +151,7 @@ private SurfaceLine DetermineSurfaceLineForGivenLayerData(SurfaceLine originalSurfaceLine, double layerThickness) { - var loweredSurfaceLine = new SurfaceLine(); - var dikeTopPolder = originalSurfaceLine.GetSurfaceLinePointByType(CharacteristicPointType.DikeTopAtPolder); - var dikeToePolder = originalSurfaceLine.GetSurfaceLinePointByType(CharacteristicPointType.DikeToeAtPolder); - foreach (var point in originalSurfaceLine.SurfaceLinePoints) - { - if (point.XCoordinate <= dikeTopPolder.XCoordinate) - { - var newPointUpToDikeTop = new SurfaceLinePoint - { - XCoordinate = point.XCoordinate, - ZCoordinate = point.ZCoordinate, - PointType = point.PointType - }; - loweredSurfaceLine.SurfaceLinePoints.Add(newPointUpToDikeTop); - } - else - { - if (point.XCoordinate >= dikeTopPolder.XCoordinate && point.XCoordinate <= dikeToePolder.XCoordinate) - { - var newPointUpToDikeTop = new SurfaceLinePoint - { - XCoordinate = point.XCoordinate, - ZCoordinate = point.ZCoordinate - layerThickness, - PointType = point.PointType - }; - loweredSurfaceLine.SurfaceLinePoints.Add(newPointUpToDikeTop); - } - else - { - if (point.XCoordinate >= dikeToePolder.XCoordinate) - { - var newPointUpToDikeTop = new SurfaceLinePoint - { - XCoordinate = point.XCoordinate, - ZCoordinate = point.ZCoordinate, - PointType = point.PointType - }; - loweredSurfaceLine.SurfaceLinePoints.Add(newPointUpToDikeTop); - } - } - } - } - return loweredSurfaceLine; + return originalSurfaceLine.DetermineLoweredSurfaceLineForGivenLayerThickness(layerThickness); } } Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/CsvImporterHelper.cs =================================================================== diff -u -r3175 -r3176 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/CsvImporterHelper.cs (.../CsvImporterHelper.cs) (revision 3175) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/CsvImporterHelper.cs (.../CsvImporterHelper.cs) (revision 3176) @@ -35,7 +35,7 @@ /// the calling object /// the scv reader /// - static public string[] GetFieldHeaders(Object caller, CsvReader csvReader) + public static string[] GetFieldHeaders(Object caller, CsvReader csvReader) { try { Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/GeometryCreator.cs =================================================================== diff -u -r3175 -r3176 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/GeometryCreator.cs (.../GeometryCreator.cs) (revision 3175) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/GeometryCreator.cs (.../GeometryCreator.cs) (revision 3176) @@ -68,7 +68,8 @@ } var stiFileCreatorInput = new StiFileCreatorInput { - XOffset = location.XOffset, + // Note that for second generation the offset MUST be 0 as any offset is already taken care of in the first generation. + XOffset = 0, SurfaceLine = surfaceLine, DikeMaterialName = location.LayerMaterial, InputFilename = Path.Combine(outputFolderName, "Interim" + location.SoilGeometryName), Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/CsvImporter.cs =================================================================== diff -u -r3160 -r3176 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/CsvImporter.cs (.../CsvImporter.cs) (revision 3160) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/CsvImporter.cs (.../CsvImporter.cs) (revision 3176) @@ -142,6 +142,7 @@ List errors) { const string importFile = "characteristicpoints.csv"; + const double diff = 1e-4; string fullFilePath = Path.Combine(inputFolderName, importFile); try { @@ -166,7 +167,7 @@ foreach (var point in characteristicPointRecord.Points) { // ignore 'unset' points - if (!((point.X == -1) && (point.Y == -1) && (point.Z == -1))) + if (!(Math.Abs(point.X + 1) < diff && Math.Abs(point.Y + 1) < diff && Math.Abs(point.Z + 1) < diff)) { var surfaceLinePoint = surfaceLine.GetSurfaceLinePointByLocation(point.X, point.Z); if (surfaceLinePoint == null) Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/CsvImporterLocations.cs =================================================================== diff -u -r3148 -r3176 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/CsvImporterLocations.cs (.../CsvImporterLocations.cs) (revision 3148) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/CsvImporterLocations.cs (.../CsvImporterLocations.cs) (revision 3176) @@ -34,8 +34,8 @@ /// public class CsvImporterLocations { - private List locationRecords = new List(); - private List errorMessages = new List(); + private readonly List locationRecords = new List(); + private readonly List errorMessages = new List(); /// /// Record used for importing the items from the locations csv file. @@ -229,7 +229,7 @@ if (index < 0) { var csvHeaderFieldError = "The header misses the field: "; - throw new ArgumentException(string.Format("{0} : {1} {2}", fileName, csvHeaderFieldError, fieldName)); + throw new ArgumentException(string.Format("{0} : {1} {2} at index {3}.", fileName, csvHeaderFieldError, fieldName, index)); } } }