Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/PipingSoilLayer2DReader.cs =================================================================== diff -u -ra950714ad9510756331d862aa35695fa0b2ed03b -r2da86d14cee084c7d6bfa52136d387cdcdb0a025 --- Ringtoets/Piping/src/Ringtoets.Piping.IO/PipingSoilLayer2DReader.cs (.../PipingSoilLayer2DReader.cs) (revision a950714ad9510756331d862aa35695fa0b2ed03b) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/PipingSoilLayer2DReader.cs (.../PipingSoilLayer2DReader.cs) (revision 2da86d14cee084c7d6bfa52136d387cdcdb0a025) @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Globalization; using System.IO; using System.Xml; @@ -20,8 +21,8 @@ private const string innerLoopElementName = "InnerLoop"; private const string endPointElementName = "EndPoint"; private const string headPointElementName = "HeadPoint"; + private const string geometryCurveElementName = "GeometryCurve"; private const string xElementName = "X"; - private const string yElementName = "Y"; private const string zElementName = "Z"; private readonly XmlTextReader xmlTextReader; @@ -50,15 +51,15 @@ while (xmlTextReader.Read()) { - HashSet outerLoop; - HashSet innerLoop; + List outerLoop; + List innerLoop; if (TryParseLoop(outerLoopElementName, out outerLoop)) { pipingSoilLayer.OuterLoop = outerLoop; } if (TryParseLoop(innerLoopElementName, out innerLoop)) { - pipingSoilLayer.InnerLoops.Add(innerLoop); + pipingSoilLayer.AddInnerLoop(innerLoop); } } @@ -71,22 +72,24 @@ /// The name of the element which the reader should be currently pointing at. /// The result of parsing the element as a loop. null if the current element's name does not match . /// True if the reader currently points to an element with name . False otherwise. - private bool TryParseLoop(String elementName, out HashSet loop) + /// Thrown when not both HeadPoint and EndPoint are defined in + /// the GeometryCurve XML element. + private bool TryParseLoop(string elementName, out List loop) { loop = null; if (IsElementWithName(elementName)) { - loop = new HashSet(); + loop = new List(); if (!IsEmptyElement()) { while (xmlTextReader.Read() && !IsEndElementWithName(elementName)) { - Point3D parsedPoint; - if (TryParsePoint(out parsedPoint)) + Segment2D segment; + if (TryParseSegment(out segment)) { - loop.Add(parsedPoint); + loop.Add(segment); } } } @@ -96,6 +99,42 @@ } /// + /// Tries to parse a GeometryCurve XML element to a . + /// + /// The segment reference in which to put the parsed . + /// true if a segment could be parsed. false otherwise. + /// Thrown when not both HeadPoint and EndPoint are defined in + /// the GeometryCurve XML element. + private bool TryParseSegment(out Segment2D segment) + { + segment = null; + if (IsElementWithName(geometryCurveElementName) || IsElementWithName(endPointElementName)) + { + var points = new Point2D[2]; + var index = 0; + while (xmlTextReader.Read() && !IsEndElementWithName(geometryCurveElementName)) + { + Point2D point; + if (TryParsePoint(out point)) + { + points[index] = point; + index++; + } + } + try + { + segment = new Segment2D(points[0], points[1]); + return true; + } + catch (ArgumentException e) + { + throw new XmlException(e.Message, e); + } + } + return false; + } + + /// /// Finds out whether the element which the reader is currently pointing at is empty. /// /// True if the element is empty. False otherwise. @@ -109,18 +148,17 @@ /// /// The result of parsing the element as a point. null if current element is not a head or end point. /// True if the reader currently points to an element with name or . False otherwise. - private bool TryParsePoint(out Point3D point) + private bool TryParsePoint(out Point2D point) { point = null; if (IsElementWithName(headPointElementName) || IsElementWithName(endPointElementName)) { var pointValues = ReadChildValues(); - point = new Point3D + point = new Point2D { X = double.Parse(pointValues[xElementName], CultureInfo.InvariantCulture), - Y = double.Parse(pointValues[yElementName], CultureInfo.InvariantCulture), - Z = double.Parse(pointValues[zElementName], CultureInfo.InvariantCulture) + Y = double.Parse(pointValues[zElementName], CultureInfo.InvariantCulture) }; return true; }