Index: src/Plugins/Wti/Wti.IO/Builders/SoilLayer2D.cs =================================================================== diff -u -r2423a70958e7fecfc92afa462c34194cc695a81e -rf97fbfa34ad013491cc6ec609a9ef097be6625b7 --- src/Plugins/Wti/Wti.IO/Builders/SoilLayer2D.cs (.../SoilLayer2D.cs) (revision 2423a70958e7fecfc92afa462c34194cc695a81e) +++ src/Plugins/Wti/Wti.IO/Builders/SoilLayer2D.cs (.../SoilLayer2D.cs) (revision f97fbfa34ad013491cc6ec609a9ef097be6625b7) @@ -1,25 +1,42 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Collections.Specialized; using System.Linq; using Wti.Data; using Wti.IO.Calculation; using Wti.IO.Properties; namespace Wti.IO.Builders { - public class SoilLayer2D + /// + /// This class represents objects which were imported from a DSoilModel database. This class + /// + internal class SoilLayer2D { + /// + /// Creates a new instance of . + /// public SoilLayer2D() { InnerLoops = new Collection>(); } - public HashSet OuterLoop { get; set; } - public Collection> InnerLoops { get; private set; } + /// + /// Gets the outer loop of the as a of . + /// + internal HashSet OuterLoop { get; set; } + /// + /// Gets the of inner loops (as of ) of the . + /// + internal Collection> InnerLoops { get; private set; } + + /// + /// Constructs a (1D) based on the and set for the . + /// + /// The point from which to take a 1D profile. + /// The bottom level of the . + /// internal IEnumerable AsPipingSoilLayers(double atX, out double bottom) { bottom = Double.MaxValue; Index: src/Plugins/Wti/Wti.IO/Builders/SoilProfileBuilder.cs =================================================================== diff -u -r947dc8ecd6e0b674f39bf1a22aef489ec8cc21fa -rf97fbfa34ad013491cc6ec609a9ef097be6625b7 --- src/Plugins/Wti/Wti.IO/Builders/SoilProfileBuilder.cs (.../SoilProfileBuilder.cs) (revision 947dc8ecd6e0b674f39bf1a22aef489ec8cc21fa) +++ src/Plugins/Wti/Wti.IO/Builders/SoilProfileBuilder.cs (.../SoilProfileBuilder.cs) (revision f97fbfa34ad013491cc6ec609a9ef097be6625b7) @@ -7,13 +7,19 @@ namespace Wti.IO.Builders { /// - /// Constructs a 1d Soil Profile based on definitions of . + /// Constructs a 1d Soil Profile based on definitions of . /// - public class SoilProfileBuilder + internal class SoilProfileBuilder { private readonly ICollection layers = new Collection(); - public SoilProfileBuilder(string profileName, double atX) + /// + /// Creates a new instance of with the supposed name for the new + /// and the point at which a 1D profile should be obtained from the 2D profile. + /// + /// The name for the constructed by the . + /// The x position from which to obtain a 1D profile. + internal SoilProfileBuilder(string profileName, double atX) { if (double.IsNaN(atX)) { @@ -24,17 +30,27 @@ Bottom = double.MaxValue; } - public void Add(SoilLayer2D soilLayer) + /// + /// Adds a new to the profile. + /// + /// The to add to the profile. + /// The . + internal SoilProfileBuilder Add(SoilLayer2D soilLayer) { double bottom; foreach (PipingSoilLayer layer in soilLayer.AsPipingSoilLayers(AtX, out bottom)) { layers.Add(layer); } Bottom = Math.Min(Bottom, bottom); + return this; } - public PipingSoilProfile Build() + /// + /// Creates a new instance of . + /// + /// A new . + internal PipingSoilProfile Build() { return new PipingSoilProfile(ProfileName, Bottom, layers); } Index: src/Plugins/Wti/Wti.IO/PipingSoilProfileReader.cs =================================================================== diff -u -r947dc8ecd6e0b674f39bf1a22aef489ec8cc21fa -rf97fbfa34ad013491cc6ec609a9ef097be6625b7 --- src/Plugins/Wti/Wti.IO/PipingSoilProfileReader.cs (.../PipingSoilProfileReader.cs) (revision 947dc8ecd6e0b674f39bf1a22aef489ec8cc21fa) +++ src/Plugins/Wti/Wti.IO/PipingSoilProfileReader.cs (.../PipingSoilProfileReader.cs) (revision f97fbfa34ad013491cc6ec609a9ef097be6625b7) @@ -122,7 +122,7 @@ CommandText = string.Format( "SELECT p.SP2D_Name, l.GeometrySurface, mat.MA_Name, mpl.X " + "FROM MechanismPointLocation as m " + - "JOIN MechanismPointLocation as mpl ON m.ME_ID = mpl.ME_ID " + + "JOIN MechanismPointLocation as mpl ON p.SP2D_ID = mpl.SP2D_ID " + "JOIN SoilProfile2D as p ON m.SP2D_ID = p.SP2D_ID " + "JOIN SoilLayer2D as l ON l.SP2D_ID = p.SP2D_ID " + "JOIN Materials as mat ON mat.MA_ID = l.MA_ID " + Index: test/Plugins/Wti/Wti.IO.Test/Builders/SoilProfileBuilderTest.cs =================================================================== diff -u -r947dc8ecd6e0b674f39bf1a22aef489ec8cc21fa -rf97fbfa34ad013491cc6ec609a9ef097be6625b7 --- test/Plugins/Wti/Wti.IO.Test/Builders/SoilProfileBuilderTest.cs (.../SoilProfileBuilderTest.cs) (revision 947dc8ecd6e0b674f39bf1a22aef489ec8cc21fa) +++ test/Plugins/Wti/Wti.IO.Test/Builders/SoilProfileBuilderTest.cs (.../SoilProfileBuilderTest.cs) (revision f97fbfa34ad013491cc6ec609a9ef097be6625b7) @@ -3,6 +3,7 @@ using System.Linq; using NUnit.Framework; using Wti.Data; +using Wti.Data.TestUtil; using Wti.IO.Builders; using Wti.IO.Properties; @@ -87,5 +88,112 @@ Assert.AreEqual(1.0, soilProfile.Layers.ToArray()[0].Top); Assert.AreEqual(-1.0, soilProfile.Bottom); } + + [Test] + public void Build_WithMultipleLayersOnlyOuterLoop_ReturnsProfileWithBottomAndALayers() + { + // Setup + var profileName = "SomeProfile"; + var builder = new SoilProfileBuilder(profileName, 1.0); + builder.Add(new SoilLayer2D + { + OuterLoop = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "10", + "...", + "...", + "...", + "...", + "...", + "...", + "...", + "1.2", + "4.3", + "..." + )) + }).Add(new SoilLayer2D + { + OuterLoop = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "10", + "...", + "...", + "...", + "...", + "...", + "4.3", + "...", + "1.2", + "...", + "..." + )) + }).Add(new SoilLayer2D + { + OuterLoop = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "10", + "...", + "1.2", + "...", + "...", + "...", + "4.3", + "...", + "...", + "...", + "..." + )) + }); + + // Call + PipingSoilProfile soilProfile = builder.Build(); + + // Assert + Assert.AreEqual(profileName, soilProfile.Name); + Assert.AreEqual(3, soilProfile.Layers.Count()); + CollectionAssert.AreEquivalent(new[] { 2.0, 4.0, 8.0 }, soilProfile.Layers.Select(rl => rl.Top)); + Assert.AreEqual(1.0, soilProfile.Bottom); + } + + + [Test] + public void Build_WithLayerFilledWithOtherLayer_ReturnsProfileWithBottomAndALayers() + { + // Setup + var profileName = "SomeProfile"; + var builder = new SoilProfileBuilder(profileName, 2.0); + var loopHole = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "5", + ".....", + ".4.1.", + ".3.2.", + ".....", + "....." + )); + builder.Add(new SoilLayer2D + { + OuterLoop = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "5", + "2...3", + ".....", + ".....", + ".....", + "1...4" + )), + InnerLoops = + { + loopHole + } + }).Add(new SoilLayer2D + { + OuterLoop = loopHole + }); + + // Call + PipingSoilProfile soilProfile = builder.Build(); + + // Assert + Assert.AreEqual(profileName, soilProfile.Name); + Assert.AreEqual(3, soilProfile.Layers.Count()); + CollectionAssert.AreEquivalent(new[] { 4.0, 3.0, 2.0 }, soilProfile.Layers.Select(rl => rl.Top)); + Assert.AreEqual(0.0, soilProfile.Bottom); + } } } \ No newline at end of file Index: test/Plugins/Wti/Wti.IO.Test/PipingSoilProfileReaderTest.cs =================================================================== diff -u -r65260b1c152bf584ac4d6bdb68f6e4d115c513a0 -rf97fbfa34ad013491cc6ec609a9ef097be6625b7 --- test/Plugins/Wti/Wti.IO.Test/PipingSoilProfileReaderTest.cs (.../PipingSoilProfileReaderTest.cs) (revision 65260b1c152bf584ac4d6bdb68f6e4d115c513a0) +++ test/Plugins/Wti/Wti.IO.Test/PipingSoilProfileReaderTest.cs (.../PipingSoilProfileReaderTest.cs) (revision f97fbfa34ad013491cc6ec609a9ef097be6625b7) @@ -7,6 +7,7 @@ using log4net.Core; using NUnit.Framework; using Wti.Data; +using Wti.IO.Calculation; using Wti.IO.Exceptions; using Wti.IO.Properties; @@ -72,5 +73,60 @@ var exception = Assert.Throws(test); Assert.AreEqual(String.Format(Resources.Error_SoilProfileReadFromDatabase, dbName), exception.Message); } + + [Test] + [SetCulture("nl-NL")] + public void ReadSoilProfiles_NLCompleteDatabase_Returns2ProfilesWithLayersAndGeometries() + { + ReadSoilProfiles_CompleteDatabase_Returns2ProfilesWithLayersAndGeometries(); + } + + [Test] + [SetCulture("en-US")] + public void ReadSoilProfiles_ENCompleteDatabase_Returns2ProfilesWithLayersAndGeometries() + { + ReadSoilProfiles_CompleteDatabase_Returns2ProfilesWithLayersAndGeometries(); + } + + private void ReadSoilProfiles_CompleteDatabase_Returns2ProfilesWithLayersAndGeometries() + { + // Setup + var testFile = "complete.soil"; + var pipingSoilProfilesReader = new PipingSoilProfileReader(Path.Combine(testDataPath, testFile)); + + // Call + PipingSoilProfile[] result = pipingSoilProfilesReader.Read().ToArray(); + + // Assert + Assert.AreEqual(2, result.Length); + var firstProfile = result.SingleOrDefault(psp => psp.Name == "10Y_005_STBI"); + Assert.NotNull(firstProfile); + + Assert.AreEqual(-10, firstProfile.Bottom); + Assert.AreEqual(6, firstProfile.Layers.Count()); + var expected = new[] + { + -3.5, + -1.2, + 0.63, + 1.088434916, + 1.947578092, + 2.473341176 + }; + CollectionAssert.AllItemsAreUnique(firstProfile.Layers.Select(l => l.Top)); + Assert.AreEqual(6, firstProfile.Layers.Count(l => expected.Contains(l.Top, new DoubleComparer()))); + } } + + internal class DoubleComparer : IEqualityComparer { + public bool Equals(double x, double y) + { + return Math.Abs(x - y) < Math2D.EpsilonForComparisons; + } + + public int GetHashCode(double obj) + { + return obj.GetHashCode(); + } + } } \ No newline at end of file