Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SurfaceLine2.cs =================================================================== diff -u -r4000 -r4052 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SurfaceLine2.cs (.../SurfaceLine2.cs) (revision 4000) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SurfaceLine2.cs (.../SurfaceLine2.cs) (revision 4052) @@ -28,363 +28,362 @@ using Deltares.DamEngine.Data.Standard.Language; using Deltares.DamEngine.Data.Standard.Validation; -namespace Deltares.DamEngine.Data.Geotechnics +namespace Deltares.DamEngine.Data.Geotechnics; + +/// +/// Representation of a surface line with characteristic point annotations. +/// +/// Extension methods can be found in . +public class SurfaceLine2 : GeometryObject { + private CharacteristicPointSet characteristicPoints; + private GeometryPointString geometry; + /// - /// Representation of a surface line with characteristic point annotations. + /// Create a new empty surface line. /// - /// Extension methods can be found in . - public class SurfaceLine2 : GeometryObject + public SurfaceLine2() { - private CharacteristicPointSet characteristicPoints; - private GeometryPointString geometry; + geometry = new GeometryPointString(); + characteristicPoints = new CharacteristicPointSet + { + GeometryMustContainPoint = true + }; + LandwardDirection = LandwardDirection.PositiveX; + Name = LocalizationManager.GetTranslatedText(this, "DefaultNameSurfaceLine2"); + } - /// - /// Create a new empty surface line. - /// - public SurfaceLine2() + /// + /// The geometrical description of the surface line. + /// + /// Aggregation relationship. + public GeometryPointString Geometry + { + get { - geometry = new GeometryPointString(); - characteristicPoints = new CharacteristicPointSet - { - GeometryMustContainPoint = true - }; - LandwardDirection = LandwardDirection.PositiveX; - Name = LocalizationManager.GetTranslatedText(this, "DefaultNameSurfaceLine2"); + return geometry; } - - /// - /// The geometrical description of the surface line. - /// - /// Aggregation relationship. - public GeometryPointString Geometry + set { - get - { - return geometry; - } - set - { - geometry = value; - CharacteristicPoints.Geometry = geometry; - } + geometry = value; + CharacteristicPoints.Geometry = geometry; } + } - /// - /// The characteristic point annotations for . - /// - /// Cannot be null. - public CharacteristicPointSet CharacteristicPoints + /// + /// The characteristic point annotations for . + /// + /// Cannot be null. + public CharacteristicPointSet CharacteristicPoints + { + get { - get - { - return characteristicPoints; - } - set - { - characteristicPoints = value; - characteristicPoints.Geometry = geometry; - } + return characteristicPoints; } + set + { + characteristicPoints = value; + characteristicPoints.Geometry = geometry; + } + } - /// - /// Determines toward which direction land is expected. Value is used as reference. - /// - public LandwardDirection LandwardDirection { get; set; } + /// + /// Determines toward which direction land is expected. Value is used as reference. + /// + public LandwardDirection LandwardDirection { get; set; } - /// - /// Deep clone the object. - /// - /// - public SurfaceLine2 FullDeepClone() + /// + /// Deep clone the object. + /// + /// + public SurfaceLine2 FullDeepClone() + { + var surfaceLine2 = new SurfaceLine2(); + surfaceLine2.SetValuesFromOtherSurfaceLine(this, true); + return surfaceLine2; + } + + /// + /// Define a new characteristic point on the surface line with the given characteristic + /// point annotation. + /// + /// The point to be added. Cannot be null. + /// The annotations for . + public void AddCharacteristicPoint(GeometryPoint geometryPoint, params CharacteristicPointType[] annotations) + { + if (annotations == null || annotations.Length == 0) { - var surfaceLine2 = new SurfaceLine2(); - surfaceLine2.SetValuesFromOtherSurfaceLine(this, true); - return surfaceLine2; + CharacteristicPoints.Add(new CharacteristicPoint + { + GeometryPoint = geometryPoint, + CharacteristicPointType = CharacteristicPointType.None + }); } - - /// - /// Define a new characteristic point on the surface line with the given characteristic - /// point annotation. - /// - /// The point to be added. Cannot be null. - /// The annotations for . - public void AddCharacteristicPoint(GeometryPoint geometryPoint, params CharacteristicPointType[] annotations) + else { - if (annotations == null || annotations.Length == 0) + foreach (CharacteristicPointType type in annotations) { CharacteristicPoints.Add(new CharacteristicPoint { GeometryPoint = geometryPoint, - CharacteristicPointType = CharacteristicPointType.None + CharacteristicPointType = type }); } - else - { - foreach (CharacteristicPointType type in annotations) - { - CharacteristicPoints.Add(new CharacteristicPoint - { - GeometryPoint = geometryPoint, - CharacteristicPointType = type - }); - } - } } + } - /// - /// Define a new characteristic point on the surface line with the given characteristic - /// point annotation. - /// - /// The x. - /// The y. - /// The annotations for geometryPoint with x, z/>. - public void AddCharacteristicPoint(double x, double z, params CharacteristicPointType[] annotations) - { - var geometryPoint = new GeometryPoint(x, z); - AddCharacteristicPoint(geometryPoint, annotations); - } + /// + /// Define a new characteristic point on the surface line with the given characteristic + /// point annotation. + /// + /// The x. + /// The y. + /// The annotations for geometryPoint with x, z/>. + public void AddCharacteristicPoint(double x, double z, params CharacteristicPointType[] annotations) + { + var geometryPoint = new GeometryPoint(x, z); + AddCharacteristicPoint(geometryPoint, annotations); + } - /// - /// Find all characteristic point annotations corresponding with the given location. - /// - /// - /// - public IEnumerable GetCharacteristicPoints(GeometryPoint geometryPoint) - { - return CharacteristicPoints.Where(cp => ReferenceEquals(cp.GeometryPoint, geometryPoint)) - .Select(cp => cp.CharacteristicPointType); - } + /// + /// Find all characteristic point annotations corresponding with the given location. + /// + /// + /// + public IEnumerable GetCharacteristicPoints(GeometryPoint geometryPoint) + { + return CharacteristicPoints.Where(cp => ReferenceEquals(cp.GeometryPoint, geometryPoint)) + .Select(cp => cp.CharacteristicPointType); + } - /// - /// Sort all points on X in a ascending manner. - /// - public void SortPoints() + /// + /// Sort all points on X in a ascending manner. + /// + public void SortPoints() + { + CharacteristicPoints.Sort(); + } + + /// + /// Gets the point segment including given start x and end x. + /// + /// The start x. + /// The end x. + /// collection of points between start X and end X (inlcuding those) + /// End value is smaller then the start value + public virtual IEnumerable GetPointSegmentIncluding(double startX, double endX) + { + if (endX < startX) { - CharacteristicPoints.Sort(); + throw new ArgumentException(Resources.GetPointSegmentIncludingEndValueSmallerThanStartValue); } - /// - /// Gets the point segment including given start x and end x. - /// - /// The start x. - /// The end x. - /// collection of points between start X and end X (inlcuding those) - /// End value is smaller then the start value - public virtual IEnumerable GetPointSegmentIncluding(double startX, double endX) - { - if (endX < startX) - { - throw new ArgumentException(Resources.GetPointSegmentIncludingEndValueSmallerThanStartValue); - } + return from point in PointsOrderedByX + where TestIncluding(point, startX, endX) + orderby point.X + select point; + } - return from point in PointsOrderedByX - where TestIncluding(point, startX, endX) - orderby point.X - select point; - } + /// + /// Validates this surfaceline. + /// + /// All validation messages. + [Validate] + public ValidationResult[] Validate() + { + return new SurfaceLine2Validator().Validate(this).ToArray(); + } - /// - /// Validates this surfaceline. - /// - /// All validation messages. - [Validate] - public ValidationResult[] Validate() - { - return new SurfaceLine2Validator().Validate(this).ToArray(); - } + /// + /// Copy all characteristic point related data from another . + /// + /// Data source + public void Assign(SurfaceLine2 source) + { + SetValuesFromOtherSurfaceLine(source); + } - /// - /// Copy all characteristic point related data from another . - /// - /// Data source - public void Assign(SurfaceLine2 source) - { - SetValuesFromOtherSurfaceLine(source); - } + /// + /// Returns a that represents this instance. + /// + /// + /// A that represents this instance. + /// + public override string ToString() + { + return Name; + } - /// - /// Returns a that represents this instance. - /// - /// - /// A that represents this instance. - /// - public override string ToString() + /// + /// Gets the geometry bounds (i.e. the extents for drawing) + /// + /// + public override GeometryBounds GetGeometryBounds() + { + if (CharacteristicPoints.Geometry != null) { - return Name; + return CharacteristicPoints.Geometry.GetGeometryBounds(); } - /// - /// Gets the geometry bounds (i.e. the extents for drawing) - /// - /// - public override GeometryBounds GetGeometryBounds() - { - if (CharacteristicPoints.Geometry != null) - { - return CharacteristicPoints.Geometry.GetGeometryBounds(); - } + return null; + } - return null; - } - - /// - /// Gets the points orderd by x. - /// - /// - /// The points orderd by x. - /// - private IEnumerable PointsOrderedByX + /// + /// Gets the points orderd by x. + /// + /// + /// The points orderd by x. + /// + private IEnumerable PointsOrderedByX + { + get { - get - { - return Geometry.Points.OrderBy(p => p.X); - } + return Geometry.Points.OrderBy(p => p.X); } + } - /// - /// Tests if the given point is between the given start X and end X. - /// - /// The point. - /// The start x. - /// The end x. - /// true if the given point is between the given start X and end X, otherwise false - private bool TestIncluding(GeometryPoint point, double startX, double endX) + /// + /// Tests if the given point is between the given start X and end X. + /// + /// The point. + /// The start x. + /// The end x. + /// true if the given point is between the given start X and end X, otherwise false + private bool TestIncluding(GeometryPoint point, double startX, double endX) + { + if (point == null) { - if (point == null) - { - return false; - } - - double x = point.X; - return (x >= startX || x.AlmostEquals(startX, GeometryPoint.Precision)) - && (x <= endX || x.AlmostEquals(endX, GeometryPoint.Precision)); + return false; } - /// - /// Sets the values from another surface line. - /// - /// The source. - /// If set to true, the of - /// will be deep cloned, otherwise the reference is shared. - private void SetValuesFromOtherSurfaceLine(SurfaceLine2 source, bool cloneGeometry = false) - { - CharacteristicPoints.Clear(); // clears the whole characteristic points state. + double x = point.X; + return (x >= startX || x.AlmostEquals(startX, GeometryPoint.Precision)) + && (x <= endX || x.AlmostEquals(endX, GeometryPoint.Precision)); + } - Name = source.Name; - Geometry.Name = Name; - LandwardDirection = source.LandwardDirection; + /// + /// Sets the values from another surface line. + /// + /// The source. + /// If set to true, the of + /// will be deep cloned, otherwise the reference is shared. + private void SetValuesFromOtherSurfaceLine(SurfaceLine2 source, bool cloneGeometry = false) + { + CharacteristicPoints.Clear(); // clears the whole characteristic points state. - CharacteristicPoints.GeometryMustContainPoint = source.CharacteristicPoints.GeometryMustContainPoint; - Geometry = cloneGeometry ? source.Geometry.Clone() : source.Geometry; + Name = source.Name; + Geometry.Name = Name; + LandwardDirection = source.LandwardDirection; - Dictionary geometryAnnotations = GetCharacteristicAnnotationsInSource(source, cloneGeometry); + CharacteristicPoints.GeometryMustContainPoint = source.CharacteristicPoints.GeometryMustContainPoint; + Geometry = cloneGeometry ? source.Geometry.Clone() : source.Geometry; - // Reconstruct annotation state from dictionary: - if (CharacteristicPoints.GeometryMustContainPoint) + Dictionary geometryAnnotations = GetCharacteristicAnnotationsInSource(source, cloneGeometry); + + // Reconstruct annotation state from dictionary: + if (CharacteristicPoints.GeometryMustContainPoint) + { + foreach (KeyValuePair annotation in geometryAnnotations) { - foreach (KeyValuePair annotation in geometryAnnotations) + for (var i = 0; i < annotation.Value.Length; i++) { - for (var i = 0; i < annotation.Value.Length; i++) + int index = -1; + for (var j = 0; j < CharacteristicPoints.Count; j++) { - int index = -1; - for (var j = 0; j < CharacteristicPoints.Count; j++) + if (ReferenceEquals(CharacteristicPoints[j].GeometryPoint, annotation.Key)) { - if (ReferenceEquals(CharacteristicPoints[j].GeometryPoint, annotation.Key)) - { - index = j; - break; - } + index = j; + break; } + } - if (i == 0) + if (i == 0) + { + // Reassign annotation of already created CharacteristicPoint: + CharacteristicPoints.Annotate(index, annotation.Value[i]); + } + else + { + // Add new CharacteristicPoint instance for all subsequent annotations and ensuring to keep the defined order: + CharacteristicPoints.Insert(index + i, new CharacteristicPoint(CharacteristicPoints, annotation.Key) { - // Reassign annotation of already created CharacteristicPoint: - CharacteristicPoints.Annotate(index, annotation.Value[i]); - } - else - { - // Add new CharacteristicPoint instance for all subsequent annotations and ensuring to keep the defined order: - CharacteristicPoints.Insert(index + i, new CharacteristicPoint(CharacteristicPoints, annotation.Key) - { - CharacteristicPointType = annotation.Value[i] - }); - } + CharacteristicPointType = annotation.Value[i] + }); } } } - else + } + else + { + foreach (KeyValuePair annotation in geometryAnnotations) { - foreach (KeyValuePair annotation in geometryAnnotations) - { - AddCharacteristicPoint((GeometryPoint) annotation.Key.Clone(), annotation.Value); - } + AddCharacteristicPoint((GeometryPoint) annotation.Key.Clone(), annotation.Value); } } + } - /// - /// Collapses all characteristic point annotations in the given surfaceline into - /// a dictionary keyed on instances in that surfaceline - /// and their annotations. - /// - /// The referenced surfaceline. - /// True if should be a clone from - /// .; false if it should - /// take the same instance instead. - /// Dictionary keyed on instances in the surfaceline - /// that have annotations. - private Dictionary GetCharacteristicAnnotationsInSource(SurfaceLine2 source, bool cloneGeometry) - { - return CharacteristicPoints.GeometryMustContainPoint - ? GetCharacteristicAnnotationsInSource_GeometryMustContainPoints(source, cloneGeometry) - : GetCharacteristicAnnotationsInSource_GeometryMustNotContainPoints(source); - } + /// + /// Collapses all characteristic point annotations in the given surfaceline into + /// a dictionary keyed on instances in that surfaceline + /// and their annotations. + /// + /// The referenced surfaceline. + /// True if should be a clone from + /// .; false if it should + /// take the same instance instead. + /// Dictionary keyed on instances in the surfaceline + /// that have annotations. + private Dictionary GetCharacteristicAnnotationsInSource(SurfaceLine2 source, bool cloneGeometry) + { + return CharacteristicPoints.GeometryMustContainPoint + ? GetCharacteristicAnnotationsInSource_GeometryMustContainPoints(source, cloneGeometry) + : GetCharacteristicAnnotationsInSource_GeometryMustNotContainPoints(source); + } - /// - /// Handlers return value in case - /// is true. - /// - /// The referenced surfaceline. - /// True if should be a clone from - /// .; false if it should - /// take the same instance instead. - /// Dictionary keyed on instances in the surfaceline - /// that have annotations. - private Dictionary GetCharacteristicAnnotationsInSource_GeometryMustContainPoints(SurfaceLine2 source, bool cloneGeometry) + /// + /// Handlers return value in case + /// is true. + /// + /// The referenced surfaceline. + /// True if should be a clone from + /// .; false if it should + /// take the same instance instead. + /// Dictionary keyed on instances in the surfaceline + /// that have annotations. + private Dictionary GetCharacteristicAnnotationsInSource_GeometryMustContainPoints(SurfaceLine2 source, bool cloneGeometry) + { + var geometryAnnotations = new Dictionary(); + for (var i = 0; i < source.Geometry.Count; i++) { - var geometryAnnotations = new Dictionary(); - for (var i = 0; i < source.Geometry.Count; i++) + CharacteristicPointType[] annotationsForPoint = source.GetCharacteristicPoints(source.Geometry.Points[i]).Where(cpt => cpt != CharacteristicPointType.None).ToArray(); + if (annotationsForPoint.Length > 0) { - CharacteristicPointType[] annotationsForPoint = source.GetCharacteristicPoints(source.Geometry.Points[i]).Where(cpt => cpt != CharacteristicPointType.None).ToArray(); - if (annotationsForPoint.Length > 0) - { - geometryAnnotations[Geometry.Points[i]] = annotationsForPoint; - } + geometryAnnotations[Geometry.Points[i]] = annotationsForPoint; } - - return geometryAnnotations; } - /// - /// Handles return value in case - /// is false. - /// - /// The referenced surfaceline. - /// Dictionary keyed on instances in the surfaceline - /// that have annotations. - private static Dictionary GetCharacteristicAnnotationsInSource_GeometryMustNotContainPoints(SurfaceLine2 source) + return geometryAnnotations; + } + + /// + /// Handles return value in case + /// is false. + /// + /// The referenced surfaceline. + /// Dictionary keyed on instances in the surfaceline + /// that have annotations. + private static Dictionary GetCharacteristicAnnotationsInSource_GeometryMustNotContainPoints(SurfaceLine2 source) + { + var geometryAnnotations = new Dictionary(); + foreach (CharacteristicPoint characteristicPoint in source.CharacteristicPoints) { - var geometryAnnotations = new Dictionary(); - foreach (CharacteristicPoint characteristicPoint in source.CharacteristicPoints) + if (!geometryAnnotations.ContainsKey(characteristicPoint.GeometryPoint)) { - if (!geometryAnnotations.ContainsKey(characteristicPoint.GeometryPoint)) - { - geometryAnnotations[characteristicPoint.GeometryPoint] = - source.GetCharacteristicPoints(characteristicPoint.GeometryPoint).ToArray(); - } + geometryAnnotations[characteristicPoint.GeometryPoint] = + source.GetCharacteristicPoints(characteristicPoint.GeometryPoint).ToArray(); } - - return geometryAnnotations; } + + return geometryAnnotations; } } \ No newline at end of file