Index: dam engine/trunk/src/Deltares.DamEngine.Interface/FillXmlInputFromDam.cs =================================================================== diff -u -r452 -r478 --- dam engine/trunk/src/Deltares.DamEngine.Interface/FillXmlInputFromDam.cs (.../FillXmlInputFromDam.cs) (revision 452) +++ dam engine/trunk/src/Deltares.DamEngine.Interface/FillXmlInputFromDam.cs (.../FillXmlInputFromDam.cs) (revision 478) @@ -20,28 +20,64 @@ // All rights reserved. using Deltares.DamEngine.Data.General; -//using Deltares.DamEngine.Io.XmlInput; -//using Deltares.DamEngine.Io.XmlOutput; +using Deltares.DamEngine.Io.XmlInput; using Input = Deltares.DamEngine.Io.XmlInput.Input; namespace Deltares.DamEngine.Interface { public class FillXmlInputFromDam { + /// + /// Creates the input. + /// + /// The dam project data. + /// public static Input CreateInput(DamProjectData damProjectData) { Input input = new Input(); input.DamProjectType = ConversionHelper.ConvertToInputDamProjectType(damProjectData.DamProjectType); - int locationCount = damProjectData.Dike.Locations.Count; + Dike dike = damProjectData.Dike; + TransferLocations(dike, input); + TransferSurfaceLines(dike, input); + return input; + } + + private static void TransferSurfaceLines(Dike dike, Input input) + { + input.SurfaceLines = new SurfaceLine[dike.SurfaceLines2.Count]; + for (int i = 0; i < dike.SurfaceLines2.Count; i++) + { + var surfaceLine = dike.SurfaceLines2[i]; + var inputSurfaceLine = new SurfaceLine(); + inputSurfaceLine.Points = new SurfaceLinePoint[surfaceLine.CharacteristicPoints.Count]; + // This is not completely correct. The geometry points should also be transferred + for (int j = 0; j < surfaceLine.CharacteristicPoints.Count; j++) + { + var characteristicPoint = surfaceLine.CharacteristicPoints[j]; + var inputPoint = new SurfaceLinePoint() + { + PointType = ConversionHelper.ConvertToInputPointType(characteristicPoint.CharacteristicPointType), + X = characteristicPoint.X, + Z = characteristicPoint.Z + }; + inputSurfaceLine.Points[j] = inputPoint; + } + input.SurfaceLines[i] = inputSurfaceLine; + } + } + + private static void TransferLocations(Dike dike, Input input) + { + int locationCount = dike.Locations.Count; input.Locations = new Io.XmlInput.Location[locationCount]; for (int i = 0; i < locationCount; i++) { - var location = damProjectData.Dike.Locations[i]; + var location = dike.Locations[i]; input.Locations[i] = new Io.XmlInput.Location(); - var waternetOptions = new Io.XmlInput.LocationWaternetOptions(); + var waternetOptions = new LocationWaternetOptions(); waternetOptions.PhreaticLineCreationMethod = ConversionHelper.ConvertToInputPhreaticLineCreationMethod(location.ModelParametersForPLLines.PLLineCreationMethod); - waternetOptions.IntrusionVerticalWaterPressure = ConversionHelper.ConvertToInputIntrusionVerticalWaterPressure(location.IntrusionVerticalWaterPressure?? IntrusionVerticalWaterPressureType.Standard); + waternetOptions.IntrusionVerticalWaterPressure = ConversionHelper.ConvertToInputIntrusionVerticalWaterPressure(location.IntrusionVerticalWaterPressure ?? IntrusionVerticalWaterPressureType.Standard); waternetOptions.PolderLevel = location.PolderLevel; waternetOptions.DampingFactorPL3 = location.ModelParametersForPLLines.DampingFactorPL4; waternetOptions.DampingFactorPL4 = location.ModelParametersForPLLines.DampingFactorPL3; @@ -53,7 +89,7 @@ waternetOptions.DryPl1BelowCrestMiddleSpecified = location.PlLineOffsetDryBelowDikeCrestMiddle.HasValue; waternetOptions.DryPl1BelowCrestMiddle = location.PlLineOffsetDryBelowDikeCrestMiddle ?? 0.0; waternetOptions.DryPl1FactorBelowShoulderCrestSpecified = location.UsePlLineOffsetDryFactorBelowShoulderCrest ?? false; - waternetOptions.DryPl1FactorBelowShoulderCrest = location.PlLineOffsetDryFactorBelowShoulderCrest??0.0; + waternetOptions.DryPl1FactorBelowShoulderCrest = location.PlLineOffsetDryFactorBelowShoulderCrest ?? 0.0; waternetOptions.HeadPl2Specified = location.HeadPl2.HasValue; waternetOptions.HeadPl2 = location.HeadPl2 ?? 0.0; waternetOptions.HeadPl3Specified = location.HeadPl3.HasValue; @@ -67,7 +103,6 @@ waternetOptions.Pl1BelowToeDikePolderside = location.PlLineOffsetBelowDikeToeAtPolder; input.Locations[i].WaternetOptions = waternetOptions; } - return input; } } } Index: dam engine/trunk/src/Deltares.DamEngine.Interface/FillDamFromXmlInput.cs =================================================================== diff -u -r477 -r478 --- dam engine/trunk/src/Deltares.DamEngine.Interface/FillDamFromXmlInput.cs (.../FillDamFromXmlInput.cs) (revision 477) +++ dam engine/trunk/src/Deltares.DamEngine.Interface/FillDamFromXmlInput.cs (.../FillDamFromXmlInput.cs) (revision 478) @@ -28,10 +28,15 @@ namespace Deltares.DamEngine.Interface { /// - /// + /// Fill Dam Engine data object from Input serializer object /// public class FillDamFromXmlInput { + /// + /// Creates the dam project data from an Input serializer object + /// + /// The input. + /// public static DamProjectData CreateDamProjectData(Input input) { var damProjectData = new DamProjectData(); @@ -40,35 +45,39 @@ damProjectData.Dike = new Dike(); Dike dike = damProjectData.Dike; TransferLocations(input, dike); - //for (int i = 0; i < input.SurfaceLines.Length; i++) - //{ - // var surfaceLine = new SurfaceLine2(); - // var inputSurfaceLine = input.SurfaceLines[i]; - // for (int j = 0; j < inputSurfaceLine.Points.Length; j++) - // { - // var inputPoint = inputSurfaceLine.Points[j]; - // surfaceLine.Geometry = new GeometryPointString(); - // var geometryPoint = new GeometryPoint() - // { - // X = inputPoint.X, - // Y = 0.0, - // Z = inputPoint.Z - // }; - // surfaceLine.Geometry.Points.Add(geometryPoint); - // if (inputPoint.PointType != ConversionHelper.CpNone) - // { - // surfaceLine.CharacteristicPoints.Add(new CharacteristicPoint() - // { - // GeometryPoint = geometryPoint, - // CharacteristicPointType = ConversionHelper.ConvertToDamPointType(inputPoint.PointType) - // }); - // } - // } - //} + TransferSurfaceLines(input, dike); return damProjectData; } + private static void TransferSurfaceLines(Input input, Dike dike) + { + for (int i = 0; i < input.SurfaceLines.Length; i++) + { + var surfaceLine = new SurfaceLine2(); + var inputSurfaceLine = input.SurfaceLines[i]; + surfaceLine.CharacteristicPoints.Geometry = surfaceLine.Geometry; + AddPointsToSurfaceLine(inputSurfaceLine, surfaceLine); + dike.SurfaceLines2.Add(surfaceLine); + } + } + + private static void AddPointsToSurfaceLine(SurfaceLine inputSurfaceLine, SurfaceLine2 surfaceLine) + { + surfaceLine.Geometry = new GeometryPointString(); + for (int j = 0; j < inputSurfaceLine.Points.Length; j++) + { + var inputPoint = inputSurfaceLine.Points[j]; + var geometryPoint = new GeometryPoint() + { + X = inputPoint.X, + Y = 0.0, + Z = inputPoint.Z + }; + surfaceLine.AddCharacteristicPoint(geometryPoint, ConversionHelper.ConvertToDamPointType(inputPoint.PointType)); + } + } + private static void TransferLocations(Input input, Dike dike) { for (int i = 0; i < input.Locations.Length; i++) Index: dam engine/trunk/src/Deltares.DamEngine.Interface.Tests/FillDamFromXmlInputTests.cs =================================================================== diff -u -r477 -r478 --- dam engine/trunk/src/Deltares.DamEngine.Interface.Tests/FillDamFromXmlInputTests.cs (.../FillDamFromXmlInputTests.cs) (revision 477) +++ dam engine/trunk/src/Deltares.DamEngine.Interface.Tests/FillDamFromXmlInputTests.cs (.../FillDamFromXmlInputTests.cs) (revision 478) @@ -64,12 +64,7 @@ Y = 0.0, Z = zCoordinate, }; - surfaceLine.Geometry.Points.Add(geometryPoint); - surfaceLine.CharacteristicPoints.Add(new CharacteristicPoint() - { - GeometryPoint = geometryPoint, - CharacteristicPointType = characteristicPointType - }); + surfaceLine.AddCharacteristicPoint(geometryPoint, characteristicPointType); } private DamProjectData CreateExampleDamProjectData() { @@ -78,7 +73,7 @@ damProjectData.Dike = new Dike(); Dike dike = damProjectData.Dike; FillLocations(dike); - //FillSurfaceLines(dike); + FillSurfaceLines(dike); return damProjectData; } @@ -88,16 +83,22 @@ for (int i = 0; i < surfaceLineCount; i++) { var surfaceLine = new SurfaceLine2(); - AddPointToSurfaceLine(surfaceLine, 0.0, 0.0, CharacteristicPointType.SurfaceLevelOutside); - AddPointToSurfaceLine(surfaceLine, 4.0, 0.0, CharacteristicPointType.DikeToeAtRiver); - AddPointToSurfaceLine(surfaceLine, 9.0, 5.0, CharacteristicPointType.DikeTopAtRiver); - AddPointToSurfaceLine(surfaceLine, 13.0, 5.0, CharacteristicPointType.DikeTopAtPolder); - AddPointToSurfaceLine(surfaceLine, 18.0, 1.0, CharacteristicPointType.DikeToeAtPolder); - AddPointToSurfaceLine(surfaceLine, 24.0, 1.0, CharacteristicPointType.SurfaceLevelInside); + surfaceLine.CharacteristicPoints.Geometry = surfaceLine.Geometry; + AddPointsToSurfaceLines(surfaceLine); dike.SurfaceLines2.Add(surfaceLine); } } + private void AddPointsToSurfaceLines(SurfaceLine2 surfaceLine) + { + AddPointToSurfaceLine(surfaceLine, 0.0, 0.0, CharacteristicPointType.SurfaceLevelOutside); + AddPointToSurfaceLine(surfaceLine, 4.0, 0.0, CharacteristicPointType.DikeToeAtRiver); + AddPointToSurfaceLine(surfaceLine, 9.0, 5.0, CharacteristicPointType.DikeTopAtRiver); + AddPointToSurfaceLine(surfaceLine, 13.0, 5.0, CharacteristicPointType.DikeTopAtPolder); + AddPointToSurfaceLine(surfaceLine, 18.0, 1.0, CharacteristicPointType.DikeToeAtPolder); + AddPointToSurfaceLine(surfaceLine, 24.0, 1.0, CharacteristicPointType.SurfaceLevelInside); + } + private static void FillLocations(Dike dike) { const int locationCount = 3;