Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/Geometry2DImporter/SoilProfile2DImporter.cs
===================================================================
diff -u -r4939 -r5875
--- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/Geometry2DImporter/SoilProfile2DImporter.cs (.../SoilProfile2DImporter.cs) (revision 4939)
+++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/Geometry2DImporter/SoilProfile2DImporter.cs (.../SoilProfile2DImporter.cs) (revision 5875)
@@ -24,6 +24,7 @@
using System.IO;
using System.Linq;
using Deltares.Dam.StixFileReader;
+using Deltares.DamEngine.Data.Geometry;
using Deltares.Geotechnics.Soils;
using Deltares.Standard.Language;
@@ -41,14 +42,16 @@
/// The to import the soil profiles for.
/// The that contains all the valid soil materials.
/// The collection of that is imported from csv.>
+ ///
/// A collection of .
/// Thrown when or is null.
///
/// Thrown when
/// is null, empty or consist of only whitespaces.
///
/// Thrown when the soil profiles could not be successfully imported.
- public static IEnumerable Import(string soilProfileDirectory, Segment segment, SoilList availableSoils, IEnumerable aquifers)
+ public static IEnumerable Import(string soilProfileDirectory, Segment segment, SoilList availableSoils,
+ IEnumerable aquifers, double xSoilGeometry2DOrigin = 0.0)
{
if (segment == null)
{
@@ -72,7 +75,7 @@
foreach (SoilGeometryProbability profile in soilProfiles)
{
string profileName = profile.SoilGeometry2DName;
- SoilProfile2D readSoilProfile = ReadSoilProfile(soilProfileDirectory, profileName, aquifers);
+ SoilProfile2D readSoilProfile = ReadSoilProfile(soilProfileDirectory, profileName, aquifers, xSoilGeometry2DOrigin);
foreach (string soilName in readSoilProfile.Surfaces.Select(surface => surface.Soil.Name))
{
if (!IsSoilOfSurfacePresent(availableSoils.Soils, soilName))
@@ -94,43 +97,25 @@
/// The directory to read the from.
/// The name of the soil profile.
/// The collection of that is imported from csv.>
+ ///
/// A .
/// Thrown when the soil profile could not be read.
- private static SoilProfile2D ReadSoilProfile(string soilProfileDirectory, string soilProfileName, IEnumerable aquifers)
+ private static SoilProfile2D ReadSoilProfile(string soilProfileDirectory, string soilProfileName,
+ IEnumerable aquifers, double xSoilGeometry2DOrigin)
{
- string soilProfileFileName = HasStiFileExtension(soilProfileName) ? soilProfileName : $"{soilProfileName}.sti";
- string filePath = Path.Combine(soilProfileDirectory, soilProfileFileName);
+ var soilProfileFileName = StixFileReaderHelper.FetchFileNameWithStixExtension(soilProfileName);
+ var filePath = Path.Combine(soilProfileDirectory, soilProfileFileName);
if (File.Exists(filePath))
{
- soilProfileFileName = HasStiFileExtension(soilProfileName) ? soilProfileName : $"{soilProfileName}.sti";
filePath = Path.Combine(soilProfileDirectory, soilProfileFileName);
try
{
- var reader = new StiFileReader();
- SoilProfile2D readSoilProfile = reader.ReadSoilProfile(filePath);
- readSoilProfile.Name = soilProfileName;
-
- return readSoilProfile;
- }
- catch (StiFileReadException e)
- {
- string messageFormat = LocalizationManager.GetTranslatedText(typeof(SoilProfile2DImporter), "ImportSoilProfileErrorReadFailed");
- throw new SoilProfileImporterException(string.Format(messageFormat, soilProfileName, e.Message), e);
- }
- }
-
- soilProfileFileName = StixFileReaderHelper.FetchFileNameWithStixExtension(soilProfileName);
- filePath = Path.Combine(soilProfileDirectory, soilProfileFileName);
- if (File.Exists(filePath))
- {
- filePath = Path.Combine(soilProfileDirectory, soilProfileFileName);
- try
- {
var reader = new StixFileReader.StixFileReader();
SoilProfile2D readSoilProfile = reader.ReadSoilProfile(filePath);
TransferAquiferData(soilProfileFileName, readSoilProfile.Surfaces, aquifers);
+ var originalSurfaces = AdaptGeometryForXSoilGeometry2DOrigin(readSoilProfile, xSoilGeometry2DOrigin);
readSoilProfile.Geometry.RegenerateGeometry();
-
+ ResetSoilsForSurfaces(originalSurfaces, readSoilProfile, xSoilGeometry2DOrigin);
return readSoilProfile;
}
catch (StixFileReadException e)
@@ -144,11 +129,72 @@
throw new SoilProfileImporterException(string.Format(message, soilProfileName, string.Empty));
}
- private static bool HasStiFileExtension(string profileName)
+ private static void ResetSoilsForSurfaces(List originalSurfaces, SoilProfile2D readSoilProfile,
+ double xSoilGeometry2DOrigin)
{
- return string.Equals(Path.GetExtension(profileName), ".sti", StringComparison.OrdinalIgnoreCase);
+ if (originalSurfaces != null)
+ {
+ for (int i = 0; i < readSoilProfile.Surfaces.Count; i++)
+ {
+ var topCurves = readSoilProfile.Surfaces[i].GeometrySurface.DetermineTopGeometrySurface();
+ var point = topCurves.Points[1];
+ var soil = FindSoilInOldSurfaces(originalSurfaces, point, xSoilGeometry2DOrigin);
+ readSoilProfile.Surfaces[i].Soil = soil;
+ }
+ }
}
+ private static Soil FindSoilInOldSurfaces(List originalSurfaces, Deltares.Geometry.GeometryPoint point,
+ double xSoilGeometry2DOrigin)
+ {
+ point.X -= xSoilGeometry2DOrigin;
+ point.Y -= GeometryConstants.Accuracy / 2.0;
+ foreach (var soilLayer2D in originalSurfaces)
+ {
+ if (soilLayer2D.GeometrySurface.OuterLoop.IsPointInLoopArea(point))
+ {
+ return soilLayer2D.Soil;
+ }
+ }
+ return null;
+ }
+
+ private static List AdaptGeometryForXSoilGeometry2DOrigin(SoilProfile2D profile2D, double xSoilGeometry2DOrigin)
+ {
+ if (Math.Abs(xSoilGeometry2DOrigin) < GeometryConstants.Accuracy)
+ {
+ return null;
+ }
+ var backupSoils = new List();
+ foreach (var surface in profile2D.Surfaces)
+ {
+ backupSoils.Add(surface.Soil);
+ }
+ var oldSurfaces = new List();
+ oldSurfaces.AddRange((IEnumerable) profile2D.Surfaces);
+
+ foreach (var point in profile2D.Geometry.Points)
+ {
+ MoveXCoordinatePointInCurvesWithCoincidingInputPoint(profile2D, point, xSoilGeometry2DOrigin);
+ point.X += xSoilGeometry2DOrigin;
+ }
+ profile2D.Geometry.Rebox();
+ return oldSurfaces;
+ }
+
+ private static void MoveXCoordinatePointInCurvesWithCoincidingInputPoint(SoilProfile2D profile2D,
+ Deltares.Geometry.GeometryPoint inputPoint,
+ double xSoilGeometry2DOrigin)
+ {
+ foreach (Deltares.Geometry.GeometryCurve curve in profile2D.Geometry.Curves)
+ {
+ if (curve.HeadPoint.LocationEquals(inputPoint))
+ curve.HeadPoint.X += xSoilGeometry2DOrigin;
+ if (curve.EndPoint.LocationEquals(inputPoint))
+ curve.EndPoint.X += xSoilGeometry2DOrigin;
+ }
+ }
+
private static bool IsSoilOfSurfacePresent(IEnumerable availableSoils, string soilName)
{
var soilNames = new HashSet(availableSoils.Select(s => s.Name));
Index: DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Geometry2DImporter/SoilProfile2DImporterTest.cs
===================================================================
diff -u -r4937 -r5875
--- DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Geometry2DImporter/SoilProfile2DImporterTest.cs (.../SoilProfile2DImporterTest.cs) (revision 4937)
+++ DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Geometry2DImporter/SoilProfile2DImporterTest.cs (.../SoilProfile2DImporterTest.cs) (revision 5875)
@@ -76,7 +76,7 @@
.EqualTo("availableSoils"));
}
- [Test]
+ [Test, Ignore("Is sti based, maybe replace with a test that uses stix files")]
public void Import_WithValidArguments_ReturnsExpectedSoilProfiles()
{
// Setup
@@ -122,7 +122,7 @@
AssertSoilLayerProperties(soilProfileTwo.Surfaces);
}
- [Test]
+ [Test, Ignore("Is sti based, maybe replace with a test that uses stix files")]
public void Import_WithProfileNamesNotHavingStiExtension_ReturnsExpectedSoilProfiles()
{
// Setup
@@ -168,7 +168,7 @@
AssertSoilLayerProperties(soilProfileTwo.Surfaces);
}
- [Test]
+ [Test, Ignore("Is sti based, maybe replace with a test that uses stix files")]
public void Import_WithIncompleteSoilList_ThrowsSoilProfileImporterException()
{
const string invalidSoilProfile = "Tutorial-1a 10.1.4.3.sti"; // Soil profile also contains peat and sand for its layers
@@ -188,7 +188,7 @@
Throws.Exception.TypeOf().With.Message.EqualTo($"'{invalidSoilProfile}' contains the undefined soil: Sand."));
}
- [Test]
+ [Test, Ignore("Is sti based, maybe replace with a test that uses stix files")]
public void Import_WithSoilProfileCausingReadException_ThrowsSoilProfileImporterException()
{
const string invalidSoilProfileName = "NonExistentSoilProfile";
@@ -252,16 +252,20 @@
];
}
- [Test]
- public void WhenImported_ThenSoilProfile2DHasValidGeometry()
+ [TestCase(0.0)]
+ [TestCase(10.0)]
+ [TestCase(-9.999)]
+ public void WhenImported_ThenSoilProfile2DHasValidGeometry(double xSoilProfile2DOrigin)
{
// Call
- List soilProfiles = SoilProfile2DImporter.Import(StixTestDataFolder, segment, availableSoils, aquifers).ToList();
+ List soilProfiles = SoilProfile2DImporter.Import(StixTestDataFolder, segment,
+ availableSoils, aquifers, xSoilProfile2DOrigin).ToList();
// Assert
Assert.That(soilProfiles, Has.Count.EqualTo(2));
GeometryData geometry = soilProfiles.ElementAt(0).Geometry;
Assert.That(geometry.Surfaces, Has.Count.EqualTo(12));
+ Assert.That(geometry.Left, Is.EqualTo(xSoilProfile2DOrigin));
ValidationResult[] validationResults = geometry.ValidateGeometry();
Assert.That(validationResults, Has.Length.EqualTo(0));
geometry = soilProfiles.ElementAt(1).Geometry;
Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamEngineIo/FillXmlInputFromDamUi.cs
===================================================================
diff -u -r5814 -r5875
--- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamEngineIo/FillXmlInputFromDamUi.cs (.../FillXmlInputFromDamUi.cs) (revision 5814)
+++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamEngineIo/FillXmlInputFromDamUi.cs (.../FillXmlInputFromDamUi.cs) (revision 5875)
@@ -796,7 +796,7 @@
Location location = locationJob.Location;
try
{
- foreach (SoilProfile2D soilProfile in GetSoilProfiles(soilProfileDirectory, location.Segment, availableSoils, aquifers))
+ foreach (SoilProfile2D soilProfile in GetSoilProfiles(soilProfileDirectory, location.Segment, availableSoils, aquifers, location.XSoilGeometry2DOrigin))
{
string soilProfileName = soilProfile.Name;
if (!uniqueSoilProfileNames.Contains(soilProfileName))
@@ -841,12 +841,14 @@
/// The to retrieve the soil profiles for.
/// The containing the available soils.
/// The collection of that is imported from csv.>
+ ///
/// An array of .
/// Thrown when the soil profiles could not be successfully imported.
/// Thrown when the soil profiles could not be successfully converted.
- private static IEnumerable GetSoilProfiles(string soilProfileDirectory, Segment segment, SoilList soils, IEnumerable aquifers)
+ private static IEnumerable GetSoilProfiles(string soilProfileDirectory, Segment segment, SoilList soils,
+ IEnumerable aquifers, double xSoilGeometry2DOrigin)
{
- IEnumerable importedSoilProfiles = SoilProfile2DImporter.Import(soilProfileDirectory, segment, soils, aquifers);
+ IEnumerable importedSoilProfiles = SoilProfile2DImporter.Import(soilProfileDirectory, segment, soils, aquifers, xSoilGeometry2DOrigin);
if (importedSoilProfiles == null)
{
return Enumerable.Empty();
Index: DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/DamEngineIo/FillXmlInputFromDamUiTests.cs
===================================================================
diff -u -r5825 -r5875
--- DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/DamEngineIo/FillXmlInputFromDamUiTests.cs (.../FillXmlInputFromDamUiTests.cs) (revision 5825)
+++ DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/DamEngineIo/FillXmlInputFromDamUiTests.cs (.../FillXmlInputFromDamUiTests.cs) (revision 5875)
@@ -204,11 +204,11 @@
}));
Assert.That(input.SoilProfiles2D.Select(profile => profile.Name), Is.EquivalentTo(new[]
{
- profile2DName
+ profile2DName + ".stix"
}));
}
- [Test]
+ [Test, Ignore("Is sti based, maybe replace with a test that uses stix files")]
public void GivenDamProjectWithValidLocationsWith2DProfiles_WhenCreatingInput_ThenSelectedLocationsSerialized()
{
// Given
@@ -299,7 +299,7 @@
}));
}
- [Test]
+ [Test, Ignore("Is sti based, maybe replace with a test that uses stix files")]
public void GivenDamProjectWithValidLocationsWithTheSame2DProfiles_WhenCreatingInput_ThenSelectedLocationsAndOneSoilProfileSerialized()
{
// Given
@@ -375,7 +375,7 @@
}));
}
- [Test]
+ [Test, Ignore("Is sti based, maybe replace with a test that uses stix files")]
public void GivenDamProjectWithInvalidLocationsWithoutScenariosWith2DProfiles_WhenCreatingInput_ThenOnlyValidLocationsSerializedAndLogsErrorMessage()
{
// Given
@@ -473,7 +473,7 @@
Assert.That(LogManager.Messages, Has.All.Property(nameof(LogMessage.Subject)).EqualTo(null));
}
- [Test]
+ [Test, Ignore("Is sti based, maybe replace with a test that uses stix files")]
public void GivenDamProjectWithInvalidLocationsWithScenariosWith2DProfiles_WhenCreatingInput_ThenOnlyValidLocationsSerializedAndLogsErrorMessage()
{
// Given