Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader/StixFileReader.cs =================================================================== diff -u -r4249 -r4254 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader/StixFileReader.cs (.../StixFileReader.cs) (revision 4249) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader/StixFileReader.cs (.../StixFileReader.cs) (revision 4254) @@ -50,7 +50,7 @@ VerifyReadData(dataModel); SoilProfile2D soilProfile2D = new SoilProfile2DDataModel().Create(dataModel); - soilProfile2D.Name = Path.GetFileName(Path.GetFileNameWithoutExtension(filePath)); + soilProfile2D.Name = Path.GetFileName(filePath); return soilProfile2D; } Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader/SoilProfile2DDataModel.cs =================================================================== diff -u -r4249 -r4254 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader/SoilProfile2DDataModel.cs (.../SoilProfile2DDataModel.cs) (revision 4249) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader/SoilProfile2DDataModel.cs (.../SoilProfile2DDataModel.cs) (revision 4254) @@ -46,25 +46,19 @@ var soilProfile2D = new SoilProfile2D(); - var xMin = double.MaxValue; - var xMax = double.MinValue; - var zMin = double.MaxValue; - var zMax = double.MinValue; foreach (PersistableLayer layer in geometry.Layers) { CreateCurvesFromLayer(layer, soilProfile2D.Geometry.Curves); CreateSurfacesFromLayer(layer, soilProfile2D.Geometry.Surfaces); foreach (PersistablePoint point in layer.Points) { - xMin = Math.Min(xMin, point.X); - xMax = Math.Max(xMax, point.X); - zMin = Math.Min(zMin, point.Z); - zMax = Math.Max(zMax, point.Z); if (!IsPointPresent(point, soilProfile2D.Geometry.Points)) { soilProfile2D.Geometry.Points.Add(new GeometryPoint(point.X, 0, point.Z)); } } + + soilProfile2D.Geometry.RegenerateGeometry(); PersistableSoil persistableSoil = FetchSoilProperties(layer.Id, dataModel); @@ -79,10 +73,6 @@ soilProfile2D.Surfaces.Add(soilLayer2D); } - soilProfile2D.Geometry.Left = xMin; - soilProfile2D.Geometry.Right = xMax; - soilProfile2D.Geometry.Bottom = zMin; - soilProfile2D.YEnd = zMin; return soilProfile2D; } @@ -107,11 +97,11 @@ foreach (PersistableSoilLayerCollection soilLayer in dataModel.SoilLayers) { - foreach (PersistableSoilLayer s in soilLayer.SoilLayers) + foreach (PersistableSoilLayer persistableSoilLayer in soilLayer.SoilLayers) { - if (s.LayerId == layerId) + if (persistableSoilLayer.LayerId == layerId) { - soilId = s.SoilId; + soilId = persistableSoilLayer.SoilId; } } } Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader.Tests/SoilProfile2DDataModelTest.cs =================================================================== diff -u -r4249 -r4254 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader.Tests/SoilProfile2DDataModelTest.cs (.../SoilProfile2DDataModelTest.cs) (revision 4249) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader.Tests/SoilProfile2DDataModelTest.cs (.../SoilProfile2DDataModelTest.cs) (revision 4254) @@ -19,7 +19,11 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System.Collections.Generic; +using System.Linq; using Components.Persistence.Stability.Version2.Data; +using Deltares.Dam.StixFileReader.Tests.TestUtils; +using Deltares.Geometry; using Deltares.Geotechnics.Soils; using NUnit.Framework; @@ -31,12 +35,84 @@ [Test] public void WhenDataModelWithMultipleScenarioAndStagesIsCreated_ThenGeometryFromLastScenarioAndStageIsRetrieved() { - PersistableDataModel dataModel = PersistableDataModelFactory.CreateSimpleDataModel(); + PersistableDataModel dataModel = PersistableDataModelFactory.CreateSimpleDataModelWithMultipleScenarioAndStages(); SoilProfile2D soilProfile2D = new SoilProfile2DDataModel().Create(dataModel); - Assert.That(soilProfile2D.Geometry.Left, Is.EqualTo(-500)); - Assert.That(soilProfile2D.Geometry.Right, Is.EqualTo(500)); - Assert.That(soilProfile2D.Geometry.Bottom, Is.EqualTo(-100)); + Assert.That(soilProfile2D.Geometry.MinGeometryPointsX, Is.EqualTo(-500)); + Assert.That(soilProfile2D.Geometry.MaxGeometryPointsX, Is.EqualTo(500)); + Assert.That(soilProfile2D.Geometry.MinGeometryPointsZ, Is.EqualTo(-100)); + Assert.That(soilProfile2D.Geometry.MaxGeometryPointsZ, Is.EqualTo(100)); } + + [Test] + public void WhenDataModelWithMultipleLayersIsCreated_ThenSoilProfile2DIsAsExpected() + { + PersistableDataModel dataModel = PersistableDataModelFactory.CreateSimpleDataModelWithMultipleLayers(); + + SoilProfile2D soilProfile2D = new SoilProfile2DDataModel().Create(dataModel); + + Assert.That(soilProfile2D.Geometry.Points, Is.EqualTo(new List + { + new(12, 0, -5), + new(12, 0, 5), + new(15, 0, 5), + new(15, 0, -5), + new(10, 0, -10), + new(10, 0, 10), + new(20, 0, 10), + new(20, 0, -10), + new(18, 0, 5), + new(18, 0, -5) + }).Using(new GeometryPointEqualityComparer())); + + Assert.That(soilProfile2D.Geometry.Surfaces.Count, Is.EqualTo(3)); + + GeometrySurface surface = soilProfile2D.Geometry.Surfaces.ElementAt(0); + Assert.That(surface.OuterLoop.CurveList, Is.EqualTo(new List + { + new(new GeometryPoint(12, 0, -5), new GeometryPoint(12, 0, 5)), + new(new GeometryPoint(12, 0, 5), new GeometryPoint(15, 0, 5)), + new(new GeometryPoint(15, 0, 5), new GeometryPoint(15, 0, -5)), + new(new GeometryPoint(15, 0, -5), new GeometryPoint(12, 0, -5)) + }).Using(new GeometryCurveEqualityComparer())); + + surface = soilProfile2D.Geometry.Surfaces.ElementAt(1); + Assert.That(surface.OuterLoop.CurveList, Is.EqualTo(new List + { + new(new GeometryPoint(10, 0, -10), new GeometryPoint(10, 0, 10)), + new(new GeometryPoint(10, 0, 10), new GeometryPoint(20, 0, 10)), + new(new GeometryPoint(20, 0, 10), new GeometryPoint(20, 0, -10)), + new(new GeometryPoint(20, 0, -10), new GeometryPoint(10, 0, -10)) + }).Using(new GeometryCurveEqualityComparer())); + + surface = soilProfile2D.Geometry.Surfaces.ElementAt(2); + Assert.That(surface.OuterLoop.CurveList, Is.EqualTo(new List + { + new(new GeometryPoint(15, 0, 5), new GeometryPoint(18, 0, 5)), + new(new GeometryPoint(18, 0, 5), new GeometryPoint(18, 0, -5)), + new(new GeometryPoint(18, 0, -5), new GeometryPoint(15, 0, 5)) + }).Using(new GeometryCurveEqualityComparer())); + + Assert.That(soilProfile2D.Geometry.SurfaceLine.Points, Is.EqualTo(new List + { + new(20, 0, 10), + new(10, 0, 10) + }).Using(new GeometryPointEqualityComparer())); + + Assert.That(soilProfile2D.Geometry.Curves, Is.EqualTo(new List + { + new(new GeometryPoint(12, 0, -5), new GeometryPoint(12, 0, 5)), + new(new GeometryPoint(12, 0, 5), new GeometryPoint(15, 0, 5)), + new(new GeometryPoint(15, 0, 5), new GeometryPoint(15, 0, -5)), + new(new GeometryPoint(15, 0, -5), new GeometryPoint(12, 0, -5)), + new(new GeometryPoint(10, 0, -10), new GeometryPoint(10, 0, 10)), + new(new GeometryPoint(10, 0, 10), new GeometryPoint(20, 0, 10)), + new(new GeometryPoint(20, 0, 10), new GeometryPoint(20, 0, -10)), + new(new GeometryPoint(20, 0, -10), new GeometryPoint(10, 0, -10)), + new(new GeometryPoint(15, 0, 5), new GeometryPoint(18, 0, 5)), + new(new GeometryPoint(18, 0, 5), new GeometryPoint(18, 0, -5)), + new(new GeometryPoint(18, 0, -5), new GeometryPoint(15, 0, 5)) + }).Using(new GeometryCurveEqualityComparer())); + } } \ No newline at end of file Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader.Tests/StixFileReaderTest.cs =================================================================== diff -u -r4249 -r4254 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader.Tests/StixFileReaderTest.cs (.../StixFileReaderTest.cs) (revision 4249) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader.Tests/StixFileReaderTest.cs (.../StixFileReaderTest.cs) (revision 4254) @@ -50,6 +50,7 @@ SoilProfile2D soilProfile2D = new StixFileReader().ReadSoilProfile(fileName); Assert.That(soilProfile2D, Is.Not.Null); - Assert.That(soilProfile2D.Name, Is.EqualTo("DWP_1")); + Assert.That(soilProfile2D.Name, Is.EqualTo("DWP_1.stix")); + Assert.That(soilProfile2D.Geometry, Is.Not.Null); } } \ No newline at end of file Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader.Tests/TestUtils/GeometryPointComparer.cs =================================================================== diff -u --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader.Tests/TestUtils/GeometryPointComparer.cs (revision 0) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader.Tests/TestUtils/GeometryPointComparer.cs (revision 4254) @@ -0,0 +1,64 @@ +// Copyright (C) Stichting Deltares 2023. All rights reserved. +// +// This file is part of the application DAM - UI. +// +// DAM - UI 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 Deltares.Geometry; + +namespace Deltares.Dam.StixFileReader.Tests.TestUtils; + +/// +/// Class which contains methods for comparing . +/// +public class GeometryPointEqualityComparer : IEqualityComparer +{ + private readonly DoubleEqualityComparer doubleEqualityComparer = new(1e-6); + + /// + /// Class which contains methods for comparing . + /// + /// First point to compare. + /// Second point to compare. + public bool Equals(GeometryPoint x, GeometryPoint y) + { + if (x == null && y == null) + { + return true; + } + + if (x == null || y == null) + { + return false; + } + + return AreEqual(x.X, y.X) + && AreEqual(x.Z, y.Z); + } + + public int GetHashCode(GeometryPoint obj) + { + return 0; + } + + private bool AreEqual(double x, double y) + { + return doubleEqualityComparer.Equals(x, y); + } +} \ No newline at end of file Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader.Tests/PersistableDataModelFactory.cs =================================================================== diff -u -r4249 -r4254 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader.Tests/PersistableDataModelFactory.cs (.../PersistableDataModelFactory.cs) (revision 4249) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader.Tests/PersistableDataModelFactory.cs (.../PersistableDataModelFactory.cs) (revision 4254) @@ -20,6 +20,7 @@ // All rights reserved. using System.Collections.Generic; +using System.Drawing; using Components.Persistence.Stability.Version2.Data; namespace Deltares.Dam.StixFileReader.Tests; @@ -33,9 +34,9 @@ /// Factory for creating a simple . /// /// - public static PersistableDataModel CreateSimpleDataModel() + public static PersistableDataModel CreateSimpleDataModelWithMultipleScenarioAndStages() { - var dataModel = new PersistableDataModel + return new PersistableDataModel { Scenarios = new List { @@ -118,7 +119,137 @@ SoilVisualizations = new List() } }; + } - return dataModel; + /// + /// Factory for creating a simple . + /// + /// + public static PersistableDataModel CreateSimpleDataModelWithMultipleLayers() + { + return new PersistableDataModel + { + Scenarios = new List + { + new() + { + Stages = new List + { + new() + { + GeometryId = "15", + SoilLayersId = "20" + } + } + } + }, + Geometry = new List + { + new() + { + Id = "15", + Layers = new List + { + new() + { + Id = "16", + Points = new List + { + new(12, -5), + new(12, 5), + new(15, 5), + new(15, -5) + } + }, + new() + { + Id = "17", + Points = new List + { + new(10, -10), + new(10, 10), + new(20, 10), + new(20, -10) + } + }, + new() + { + Id = "18", + Points = new List + { + new(15, 5), + new(18, 5), + new(18, -5), + new(15, 5) + } + } + } + } + }, + SoilLayers = new List + { + new() + { + Id = "20", + SoilLayers = new List + { + new() + { + LayerId = "16", + SoilId = "12" + }, + new() + { + LayerId = "17", + SoilId = "13" + }, + new() + { + LayerId = "18", + SoilId = "7" + } + } + } + }, + Soils = new PersistableSoilCollection + { + Soils = new List + { + new() + { + Id = "7" + }, + new() + { + Id = "12" + }, + new() + { + Id = "13" + } + } + }, + SoilVisualizations = new PersistableSoilVisualizationCollection + { + SoilVisualizations = new List + { + new() + { + SoilId = "7", + Color = ColorTranslator.FromHtml("#80657F22") + }, + new() + { + SoilId = "12", + Color = ColorTranslator.FromHtml("#80FFCC00") + }, + new() + { + SoilId = "13", + Color = ColorTranslator.FromHtml("#80BB8800") + } + } + } + }; } } \ No newline at end of file Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader.Tests/TestUtils/GeometryCurveEqualityComparer.cs =================================================================== diff -u --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader.Tests/TestUtils/GeometryCurveEqualityComparer.cs (revision 0) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader.Tests/TestUtils/GeometryCurveEqualityComparer.cs (revision 4254) @@ -0,0 +1,62 @@ +// Copyright (C) Stichting Deltares 2023. All rights reserved. +// +// This file is part of the application DAM - UI. +// +// DAM - UI 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 Deltares.Geometry; + +namespace Deltares.Dam.StixFileReader.Tests.TestUtils; + +/// +/// Class which contains methods for comparing . +/// +public class GeometryCurveEqualityComparer : IEqualityComparer +{ + /// + /// Class which contains methods for comparing . + /// + /// First point to compare. + /// Second point to compare. + public bool Equals(GeometryCurve x, GeometryCurve y) + { + if (x == null && y == null) + { + return true; + } + + if (x == null || y == null) + { + return false; + } + + return AreEqual(x.HeadPoint, y.HeadPoint) && + AreEqual(x.EndPoint, y.EndPoint); + } + + public int GetHashCode(GeometryCurve obj) + { + return 0; + } + + private bool AreEqual(GeometryPoint x, GeometryPoint y) + { + return new GeometryPointEqualityComparer().Equals(x, y); + } +} \ No newline at end of file Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader.Tests/TestUtils/DoubleEqualityComparer.cs =================================================================== diff -u --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader.Tests/TestUtils/DoubleEqualityComparer.cs (revision 0) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.StixFileReader.Tests/TestUtils/DoubleEqualityComparer.cs (revision 4254) @@ -0,0 +1,77 @@ +// Copyright (C) Stichting Deltares 2023. All rights reserved. +// +// This file is part of the application DAM - UI. +// +// DAM - UI 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; +using System.Collections.Generic; + +namespace Deltares.Dam.StixFileReader.Tests.TestUtils; + +/// +/// Class which contains methods for comparing . +/// +public class DoubleEqualityComparer : IEqualityComparer +{ + private readonly double tolerance; + + /// + /// Create a new instance of . + /// + /// The tolerance to use when comparing. + public DoubleEqualityComparer(double tolerance) + { + this.tolerance = tolerance; + } + + /// + /// Creates a new instance of . + /// + public DoubleEqualityComparer() : this(0) {} + + /// + public bool Equals(double x, double y) + { + return AreEqual(x, y); + } + + /// + public int GetHashCode(double obj) + { + unchecked + { + return 51 * (int) obj; + } + } + + private bool AreEqual(double x, double y) + { + return IsBothNaN(x, y) || IsValueEqual(x, y); + } + + private bool IsValueEqual(double x, double y) + { + return x == y || Math.Abs(x - y) <= tolerance; + } + + private static bool IsBothNaN(double x, double y) + { + return double.IsNaN(x) && double.IsNaN(y); + } +} \ No newline at end of file