Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data.Tests/Deltares.Dam.Data.Tests.csproj =================================================================== diff -u -r6436 -r6554 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data.Tests/Deltares.Dam.Data.Tests.csproj (.../Deltares.Dam.Data.Tests.csproj) (revision 6436) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data.Tests/Deltares.Dam.Data.Tests.csproj (.../Deltares.Dam.Data.Tests.csproj) (revision 6554) @@ -4,6 +4,12 @@ + + ..\..\..\lib\DSL-Geo\Deltares.Geometry.dll + + + ..\..\..\lib\DSL-Geo\Deltares.Geotechnics.dll + ..\..\..\lib\DSL-Core\Deltares.Standard.dll Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/Translations.xml =================================================================== diff -u -r6439 -r6554 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/Translations.xml (.../Translations.xml) (revision 6439) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/Translations.xml (.../Translations.xml) (revision 6554) @@ -840,4 +840,7 @@ + \ No newline at end of file Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data.Tests/LocationTests.cs =================================================================== diff -u --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data.Tests/LocationTests.cs (revision 0) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data.Tests/LocationTests.cs (revision 6554) @@ -0,0 +1,122 @@ +// Copyright (C) Stichting Deltares 2025. 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 Deltares.Geometry; +using Deltares.Geotechnics.GeotechnicalGeometry; +using Deltares.Geotechnics.SurfaceLines; +using Deltares.Standard.Validation; +using NUnit.Framework; + +namespace Deltares.Dam.Data.Tests; + +[TestFixture] +public class LocationTests +{ + [Test] + [TestCase(CharacteristicPointType.InsertRiverChannel, true)] + [TestCase(CharacteristicPointType.SurfaceLevelOutside, false)] + [TestCase(CharacteristicPointType.DikeToeAtRiver, false)] + [TestCase(CharacteristicPointType.DikeTopAtRiver, false)] + [TestCase(CharacteristicPointType.DikeTopAtPolder, false)] + [TestCase(CharacteristicPointType.DikeToeAtPolder, false)] + [TestCase(CharacteristicPointType.SurfaceLevelInside, false)] + public void GivenSurfaceLine_WhenValidatingTheRequiredCharacteristicPoints_ReturnsExpectedResult(CharacteristicPointType typeNotPresent, bool isValid) + { + SurfaceLine2 surfaceLine = CreateSurfaceLine(typeNotPresent); + var location = new Location(); + location.LocalXZSurfaceLine2 = surfaceLine; + + ValidationResult[] validationResults = location.ValidateRequiredCharacteristicPoints(); + + if (isValid) + { + Assert.That(validationResults, Is.Null); + } + else + { + Assert.That(validationResults, Has.Length.EqualTo(1)); + Assert.Multiple(() => + { + Assert.That(validationResults[0].Subject, Is.EqualTo(surfaceLine)); + Assert.That(validationResults[0].Text, Is.EqualTo("Not all the required characteristic points (see user manual) are available in the surface line.")); + }); + } + } + + private static SurfaceLine2 CreateSurfaceLine(CharacteristicPointType typeNotPresent) + { + var gp0 = new GeometryPoint(0.0, 0.0, 0.0); + var gp1 = new GeometryPoint(1.0, 0.0, 0.0); + var gp2 = new GeometryPoint(2.0, 0.0, 1.0); + var gp3 = new GeometryPoint(4.0, 0.0, 1.0); + var gp4 = new GeometryPoint(10.0, 0.0, 0.0); + var gp5 = new GeometryPoint(12.0, 0.0, 0.0); + + var line = new LocalizedGeometryPointString(); + line.Points.Add(gp0); + line.Points.Add(new GeometryPoint(0.1, 0.0, 0.0)); + line.Points.Add(new GeometryPoint(0.9, 0.0, 0.0)); + line.Points.Add(gp1); + line.Points.Add(gp2); + line.Points.Add(gp3); + line.Points.Add(new GeometryPoint(4.1, 0.0, 1.0)); + line.Points.Add(new GeometryPoint(4.1, 0.0, 1.0)); + line.Points.Add(gp4); + line.Points.Add(gp5); + + var surfaceLine = new SurfaceLine2 + { + Geometry = line + }; + + if (typeNotPresent != CharacteristicPointType.SurfaceLevelOutside) + { + surfaceLine.AddCharacteristicPoint(gp0, CharacteristicPointType.SurfaceLevelOutside); + } + + if (typeNotPresent != CharacteristicPointType.DikeToeAtRiver) + { + surfaceLine.AddCharacteristicPoint(gp0, CharacteristicPointType.DikeToeAtRiver); + } + + if (typeNotPresent != CharacteristicPointType.DikeTopAtRiver) + { + surfaceLine.AddCharacteristicPoint(gp2, CharacteristicPointType.DikeTopAtRiver); + } + + if (typeNotPresent != CharacteristicPointType.DikeTopAtPolder) + { + surfaceLine.AddCharacteristicPoint(gp3, CharacteristicPointType.DikeTopAtPolder); + } + + if (typeNotPresent != CharacteristicPointType.DikeToeAtPolder) + { + surfaceLine.AddCharacteristicPoint(gp4, CharacteristicPointType.DikeToeAtPolder); + } + + if (typeNotPresent != CharacteristicPointType.SurfaceLevelInside) + { + surfaceLine.AddCharacteristicPoint(gp5, CharacteristicPointType.SurfaceLevelInside); + } + + return surfaceLine; + } +} \ No newline at end of file Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/Location.cs =================================================================== diff -u -r6436 -r6554 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/Location.cs (.../Location.cs) (revision 6436) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/Location.cs (.../Location.cs) (revision 6554) @@ -1081,6 +1081,21 @@ return new ValidationResult[0]; } + [Validate] + public ValidationResult[] ValidateRequiredCharacteristicPoints() + { + if (!AreAllRequiredCharacteristicTypesAvailable(LocalXZSurfaceLine2)) + { + return new[] + { + new ValidationResult(ValidationResultType.Error, + LocalizationManager.GetTranslatedText(this, "NotAllRequiredCharacteristicPointsAreDefined"), LocalXZSurfaceLine2) + }; + } + + return null; + } + /// /// Gets the dike embankment soil. /// @@ -1589,6 +1604,24 @@ return ""; } + /// + /// Are all required characteristic types available. + /// + /// The surface line. + /// + private static bool AreAllRequiredCharacteristicTypesAvailable(SurfaceLine2 surfaceLine) + { + IEnumerable requiredPoints = + surfaceLine.CharacteristicPoints.Where(p => !double.IsNaN(p.X) && + (p.CharacteristicPointType == CharacteristicPointType.SurfaceLevelOutside || + p.CharacteristicPointType == CharacteristicPointType.DikeToeAtRiver || + p.CharacteristicPointType == CharacteristicPointType.DikeTopAtRiver || + p.CharacteristicPointType == CharacteristicPointType.DikeTopAtPolder || + p.CharacteristicPointType == CharacteristicPointType.DikeToeAtPolder || + p.CharacteristicPointType == CharacteristicPointType.SurfaceLevelInside)).OrderBy(p => p.CharacteristicPointType); + return requiredPoints.Count() == 6; + } + #region IGeographic Members [Label("Zone type")]