Index: Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs =================================================================== diff -u -r39e8708a598b25c51c5fa0affceecdc9d9054d21 -r473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6 --- Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs (.../MapControl.cs) (revision 39e8708a598b25c51c5fa0affceecdc9d9054d21) +++ Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs (.../MapControl.cs) (revision 473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6) @@ -40,7 +40,7 @@ /// public sealed class MapControl : Control, IMapControl, IObserver { - private readonly MapDataFactory mapDataFactory = new MapDataFactory(); + private readonly MapFeatureLayerFactory mapFeatureLayerFactory = new MapFeatureLayerFactory(); private Map map; private IMapFunction mapFunctionSelectionZoom; @@ -168,7 +168,7 @@ map.ClearLayers(); if (Data != null) { - foreach (IMapFeatureLayer mapLayer in mapDataFactory.Create(Data)) + foreach (IMapFeatureLayer mapLayer in mapFeatureLayerFactory.Create(Data)) { map.Layers.Add(mapLayer); } Index: Core/Components/src/Core.Components.DotSpatial/Converter/MapDataCollectionConverter.cs =================================================================== diff -u -r287b1b719a43b0de337f8149dfa3a2a3220a375a -r473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6 --- Core/Components/src/Core.Components.DotSpatial/Converter/MapDataCollectionConverter.cs (.../MapDataCollectionConverter.cs) (revision 287b1b719a43b0de337f8149dfa3a2a3220a375a) +++ Core/Components/src/Core.Components.DotSpatial/Converter/MapDataCollectionConverter.cs (.../MapDataCollectionConverter.cs) (revision 473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6) @@ -34,7 +34,7 @@ { protected override IList Convert(MapDataCollection data) { - var factory = new MapDataFactory(); + var factory = new MapFeatureLayerFactory(); return data.List.SelectMany(md => factory.Create(md)).ToList(); } Index: Core/Components/src/Core.Components.DotSpatial/Converter/MapDataConverter.cs =================================================================== diff -u -r4dc676d1823dfb3c1d52935ccc2f107883fa10ad -r473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6 --- Core/Components/src/Core.Components.DotSpatial/Converter/MapDataConverter.cs (.../MapDataConverter.cs) (revision 4dc676d1823dfb3c1d52935ccc2f107883fa10ad) +++ Core/Components/src/Core.Components.DotSpatial/Converter/MapDataConverter.cs (.../MapDataConverter.cs) (revision 473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6) @@ -21,11 +21,8 @@ using System; using System.Collections.Generic; -using System.Drawing.Drawing2D; using Core.Components.Gis.Data; -using Core.Components.Gis.Style; using DotSpatial.Controls; -using DotSpatial.Symbology; namespace Core.Components.DotSpatial.Converter { Fisheye: Tag 473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6 refers to a dead (removed) revision in file `Core/Components/src/Core.Components.DotSpatial/Converter/MapDataFactory.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Components/src/Core.Components.DotSpatial/Converter/MapFeatureLayerFactory.cs =================================================================== diff -u --- Core/Components/src/Core.Components.DotSpatial/Converter/MapFeatureLayerFactory.cs (revision 0) +++ Core/Components/src/Core.Components.DotSpatial/Converter/MapFeatureLayerFactory.cs (revision 473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6) @@ -0,0 +1,66 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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 System; +using System.Collections.Generic; +using System.Collections.ObjectModel; + +using Core.Components.Gis.Data; +using DotSpatial.Controls; + +namespace Core.Components.DotSpatial.Converter +{ + /// + /// A factory to create data from which can be used on the map. + /// + public class MapFeatureLayerFactory + { + /// + /// Collection of converters that the can use to transform . + /// + private readonly IEnumerable converters = new Collection + { + new MapDataCollectionConverter(), + new MapPointDataConverter(), + new MapLineDataConverter(), + new MapPolygonDataConverter() + }; + + /// + /// Creates one or more new from the given . + /// + /// The to base the creation of upon. + /// A new of . + /// Thrown when the given type is not supported. + public IList Create(MapData data) + { + foreach (var converter in converters) + { + if (converter.CanConvertMapData(data)) + { + return converter.Convert(data); + } + } + + throw new NotSupportedException(string.Format("MapData of type {0} is not supported.", data.GetType().Name)); + } + } +} \ No newline at end of file Index: Core/Components/src/Core.Components.DotSpatial/Core.Components.DotSpatial.csproj =================================================================== diff -u -r4dc676d1823dfb3c1d52935ccc2f107883fa10ad -r473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6 --- Core/Components/src/Core.Components.DotSpatial/Core.Components.DotSpatial.csproj (.../Core.Components.DotSpatial.csproj) (revision 4dc676d1823dfb3c1d52935ccc2f107883fa10ad) +++ Core/Components/src/Core.Components.DotSpatial/Core.Components.DotSpatial.csproj (.../Core.Components.DotSpatial.csproj) (revision 473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6) @@ -92,7 +92,7 @@ - + Index: Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapDataFactoryTest.cs =================================================================== diff -u -rd2d0c9d6f209b4f3a36da6f8692cd66d8ce767b6 -r473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6 --- Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapDataFactoryTest.cs (.../MapDataFactoryTest.cs) (revision d2d0c9d6f209b4f3a36da6f8692cd66d8ce767b6) +++ Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapDataFactoryTest.cs (.../MapDataFactoryTest.cs) (revision 473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6) @@ -20,7 +20,7 @@ public void Create_MapPointData_ReturnMapPointLayer() { // Setup - var factory = new MapDataFactory(); + var factory = new MapFeatureLayerFactory(); var testData = CreateTestData(); // Call @@ -36,7 +36,7 @@ public void Create_MapLineData_ReturnMapLineLayer() { // Setup - var factory = new MapDataFactory(); + var factory = new MapFeatureLayerFactory(); var testData = CreateTestData(); // Call @@ -52,7 +52,7 @@ public void Create_MapPolygonData_ReturnMapPolygonLayer() { // Setup - var factory = new MapDataFactory(); + var factory = new MapFeatureLayerFactory(); var testData = CreateTestData(); // Call @@ -71,7 +71,7 @@ public void Create_MapDataCollection_ReturnMapLayersCorrespondingToListItems() { // Setup - var factory = new MapDataFactory(); + var factory = new MapFeatureLayerFactory(); var testData = CreateTestData(); var mapDataCollection = new MapDataCollection(new List { @@ -112,7 +112,7 @@ public void Create_OtherData_ThrownsNotSupportedException() { // Setup - var factory = new MapDataFactory(); + var factory = new MapFeatureLayerFactory(); var testData = new TestMapData("test data"); // Call Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/MapDataFactory.cs =================================================================== diff -u -rc67c5e4d2dcf0e3a105aab6b2bb323e9a128ff22 -r473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/MapDataFactory.cs (.../MapDataFactory.cs) (revision c67c5e4d2dcf0e3a105aab6b2bb323e9a128ff22) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/MapDataFactory.cs (.../MapDataFactory.cs) (revision 473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6) @@ -20,11 +20,17 @@ /// public static class MapDataFactory { + /// + /// Create with default styling based on the . + /// + /// The for which to create . + /// based on the . + /// is null. public static MapData Create(ReferenceLine referenceLine) { if (referenceLine == null) { - throw new ArgumentNullException(); + throw new ArgumentNullException("referenceLine"); } var features = GetMapFeature(referenceLine.Points); @@ -34,8 +40,19 @@ }; } + /// + /// Create with default styling based on the locations of . + /// + /// The for which to create . + /// based on the locations in the . + /// is null. public static MapData Create(HydraulicBoundaryDatabase hydraulicBoundaryDatabase) { + if (hydraulicBoundaryDatabase == null) + { + throw new ArgumentNullException("hydraulicBoundaryDatabase"); + } + IEnumerable locations = hydraulicBoundaryDatabase.Locations.Select(h => h.Location).ToArray(); var features = GetMapFeature(locations); @@ -46,6 +63,26 @@ }; } + /// + /// Create a instance with a name, but without data. + /// + /// The name of the . + /// An empty object. + public static MapLineData CreateEmptyLineData(string name) + { + return new MapLineData(Enumerable.Empty(), name); + } + + /// + /// Create a instance with a name, but without data. + /// + /// The name of the . + /// An empty object. + public static MapPointData CreateEmptyPointData(string name) + { + return new MapPointData(Enumerable.Empty(), name); + } + private static IEnumerable GetMapFeature(IEnumerable points) { var features = new List @@ -57,15 +94,5 @@ }; return features; } - - public static MapData CreateEmptyLineData(string name) - { - return new MapLineData(Enumerable.Empty(), name); - } - - public static MapData CreateEmptyPointData(string name) - { - return new MapPointData(Enumerable.Empty(), name); - } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/MapDataFactoryTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/MapDataFactoryTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/MapDataFactoryTest.cs (revision 473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6) @@ -0,0 +1,142 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Linq; +using Core.Common.Base.Geometry; +using Core.Components.Gis.Data; +using Core.Components.Gis.Geometries; +using Core.Components.Gis.Style; +using NUnit.Framework; +using Ringtoets.Common.Data; +using Ringtoets.HydraRing.Data; + +namespace Ringtoets.Integration.Forms.Test +{ + [TestFixture] + public class MapDataFactoryTest + { + [Test] + public void CreateEmptyLineData_Always_ReturnEmptyMapLineDataWithNameSet() + { + // Setup + const string name = ""; + + // Call + MapLineData mapData = MapDataFactory.CreateEmptyLineData(name); + + // Assert + Assert.AreEqual(name, mapData.Name); + Assert.IsEmpty(mapData.Features); + } + + [Test] + public void CreateEmptyPointData_Always_ReturnEmptyMapLineDataWithNameSet() + { + // Setup + const string name = ""; + + // Call + MapPointData mapData = MapDataFactory.CreateEmptyPointData(name); + + // Assert + Assert.AreEqual(name, mapData.Name); + Assert.IsEmpty(mapData.Features); + } + + [Test] + public void Create_GivenReferenceLine_ReturnsMapFeaturesWithDefaultStyling() + { + // Setup + var pointsOne = new[] + { + new Point2D(1.2, 2.3), + new Point2D(2.7, 2.0) + }; + var line = new ReferenceLine(); + line.SetGeometry(pointsOne); + + // Call + MapData data = MapDataFactory.Create(line); + + // Assert + Assert.IsInstanceOf(data); + var mapLineData = (MapLineData)data; + Assert.AreEqual(1, mapLineData.Features.Count()); + Assert.AreEqual(1, mapLineData.Features.ElementAt(0).MapGeometries.Count()); + AssertEqualPointCollections(pointsOne, mapLineData.Features.ElementAt(0).MapGeometries.ElementAt(0)); + + Assert.AreEqual(Common.Data.Properties.Resources.ReferenceLine_DisplayName, data.Name); + + AssertEqualStyle(mapLineData.Style, Color.Red, 3, DashStyle.Solid); + } + + [Test] + public void Create_NoReferenceLine_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => MapDataFactory.Create((ReferenceLine)null); + + // Assert + var parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("referenceLine", parameter); + } + + [Test] + public void Create_GivenHydraulicDatabase_ReturnsMapFeaturesWithDefaultStyling() + { + // Setup + var pointsOne = new[] + { + new Point2D(1.2, 2.3), + new Point2D(2.7, 2.0) + }; + var database = new HydraulicBoundaryDatabase(); + database.Locations.AddRange(pointsOne.Select(p => new HydraulicBoundaryLocation(0, "", p.X, p.Y))); + + // Call + MapData data = MapDataFactory.Create(database); + + // Assert + Assert.IsInstanceOf(data); + var mapPointData = (MapPointData)data; + Assert.AreEqual(1, mapPointData.Features.Count()); + Assert.AreEqual(1, mapPointData.Features.ElementAt(0).MapGeometries.Count()); + AssertEqualPointCollections(pointsOne, mapPointData.Features.ElementAt(0).MapGeometries.ElementAt(0)); + + Assert.AreEqual(Common.Data.Properties.Resources.HydraulicBoundaryConditions_DisplayName, data.Name); + + AssertEqualStyle(mapPointData.Style, Color.DarkBlue, 6, PointSymbol.Circle); + } + + [Test] + public void Create_NoHydraulicDatabase_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => MapDataFactory.Create((HydraulicBoundaryDatabase)null); + + // Assert + var parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("hydraulicBoundaryDatabase", parameter); + } + + private void AssertEqualStyle(PointStyle pointStyle, Color color, int width, PointSymbol symbol) + { + Assert.AreEqual(color, pointStyle.Color); + Assert.AreEqual(width, pointStyle.Size); + Assert.AreEqual(symbol, pointStyle.Symbol); + } + + private static void AssertEqualStyle(LineStyle lineStyle, Color color, int width, DashStyle style) + { + Assert.AreEqual(color, lineStyle.Color); + Assert.AreEqual(width, lineStyle.Width); + Assert.AreEqual(style, lineStyle.Style); + } + + private void AssertEqualPointCollections(IEnumerable points, MapGeometry geometry) + { + CollectionAssert.AreEqual(points.Select(p => new Point2D(p.X, p.Y)), geometry.Points); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj =================================================================== diff -u -rc8eb333514adae8495778ed16c71c41a6eb4251b -r473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision c8eb333514adae8495778ed16c71c41a6eb4251b) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision 473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6) @@ -58,6 +58,7 @@ + Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj =================================================================== diff -u -r8832cfacbfb0a999d9dd5ddcb93fd81bdb2fb09f -r473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision 8832cfacbfb0a999d9dd5ddcb93fd81bdb2fb09f) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision 473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6) @@ -107,6 +107,7 @@ PipingFailureMechanismView.cs + UserControl Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismView.cs =================================================================== diff -u -rc67c5e4d2dcf0e3a105aab6b2bb323e9a128ff22 -r473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismView.cs (.../PipingFailureMechanismView.cs) (revision c67c5e4d2dcf0e3a105aab6b2bb323e9a128ff22) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismView.cs (.../PipingFailureMechanismView.cs) (revision 473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6) @@ -19,25 +19,14 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Drawing2D; using System.Linq; using System.Windows.Forms; using Core.Common.Base; -using Core.Common.Base.Geometry; using Core.Components.Gis.Data; -using Core.Components.Gis.Features; using Core.Components.Gis.Forms; -using Core.Components.Gis.Geometries; -using Core.Components.Gis.Style; -using Ringtoets.Common.Data; using Ringtoets.Common.Forms.Properties; -using Ringtoets.HydraRing.Data; using Ringtoets.Piping.Forms.PresentationObjects; -using Ringtoets.Piping.Primitives; using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; using PipingDataResources = Ringtoets.Piping.Data.Properties.Resources; using PipingFormsResources = Ringtoets.Piping.Forms.Properties.Resources; @@ -210,106 +199,4 @@ return PipingMapDataFactory.CreateEndPoints(data.WrappedData.Sections); } } - - public static class PipingMapDataFactory - { - public static MapData Create(ICollection surfaceLines) - { - var mapFeatures = new List - { - new MapFeature(surfaceLines.Select(surfaceLine => new MapGeometry(surfaceLine.Points.Select(p => new Point2D(p.X, p.Y))))) - }; - - return new MapLineData(mapFeatures, PipingFormsResources.PipingSurfaceLinesCollection_DisplayName) - { - Style = new LineStyle(Color.DarkSeaGreen, 2, DashStyle.Solid) - }; - } - - public static MapData Create(IEnumerable sections) - { - var mapFeatures = new List - { - new MapFeature(sections.Select(section => new MapGeometry(section.Points.Select(p => new Point2D(p.X, p.Y))))) - }; - - return new MapLineData(mapFeatures, Resources.FailureMechanism_Sections_DisplayName) - { - Style = new LineStyle(Color.Khaki, 3, DashStyle.Dot) - }; - } - - public static MapData CreateStartPoints(IEnumerable sections) - { - - IEnumerable startPoints = sections.Select(sl => sl.GetStart()); - string mapDataName = string.Format("{0} ({1})", - Resources.FailureMechanism_Sections_DisplayName, - Resources.FailureMechanismSections_StartPoints_DisplayName); - return new MapPointData(GetMapFeature(startPoints), mapDataName) - { - Style = new PointStyle(Color.DarkKhaki, 15, PointSymbol.Triangle) - }; - } - - public static MapData CreateEndPoints(IEnumerable sections) - { - IEnumerable startPoints = sections.Select(sl => sl.GetLast()); - string mapDataName = string.Format("{0} ({1})", - Resources.FailureMechanism_Sections_DisplayName, - Resources.FailureMechanismSections_EndPoints_DisplayName); - return new MapPointData(GetMapFeature(startPoints), mapDataName) - { - Style = new PointStyle(Color.DarkKhaki, 15, PointSymbol.Triangle) - }; - } - - public static MapData Create(ReferenceLine referenceLine) - { - if (referenceLine == null) - { - throw new ArgumentNullException(); - } - var features = GetMapFeature(referenceLine.Points); - - return new MapLineData(features, RingtoetsCommonDataResources.ReferenceLine_DisplayName) - { - Style = new LineStyle(Color.Red, 3, DashStyle.Solid) - }; - } - - public static MapData Create(HydraulicBoundaryDatabase hydraulicBoundaryDatabase) - { - IEnumerable locations = hydraulicBoundaryDatabase.Locations.Select(h => h.Location).ToArray(); - - var features = GetMapFeature(locations); - - return new MapPointData(features, RingtoetsCommonDataResources.HydraulicBoundaryConditions_DisplayName) - { - Style = new PointStyle(Color.DarkBlue, 6, PointSymbol.Circle) - }; - } - - private static IEnumerable GetMapFeature(IEnumerable points) - { - var features = new List - { - new MapFeature(new List - { - new MapGeometry(points) - }) - }; - return features; - } - - public static MapData CreateEmptyLineData(string name) - { - return new MapLineData(Enumerable.Empty(), name); - } - - public static MapData CreateEmptyPointData(string name) - { - return new MapPointData(Enumerable.Empty(), name); - } - } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingMapDataFactory.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingMapDataFactory.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingMapDataFactory.cs (revision 473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6) @@ -0,0 +1,193 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Linq; +using Core.Common.Base.Geometry; +using Core.Components.Gis.Data; +using Core.Components.Gis.Features; +using Core.Components.Gis.Geometries; +using Core.Components.Gis.Style; +using Ringtoets.Common.Data; +using Ringtoets.HydraRing.Data; +using Ringtoets.Piping.Forms.Properties; +using Ringtoets.Piping.Primitives; + +namespace Ringtoets.Piping.Forms.Views +{ + /// + /// Factory for creating based on information used as input in the piping failure mechanism. + /// + public static class PipingMapDataFactory + { + /// + /// Create with default styling based on the . + /// + /// The collection for which to create . + /// based on . + /// is null. + public static MapData Create(IEnumerable surfaceLines) + { + if (surfaceLines == null) + { + throw new ArgumentNullException("surfaceLines"); + } + + var mapFeatures = new List + { + new MapFeature(surfaceLines.Select(surfaceLine => new MapGeometry(surfaceLine.Points.Select(p => new Point2D(p.X, p.Y))))) + }; + + return new MapLineData(mapFeatures, Resources.PipingSurfaceLinesCollection_DisplayName) + { + Style = new LineStyle(Color.DarkSeaGreen, 2, DashStyle.Solid) + }; + } + + /// + /// Create with default styling based on the . + /// + /// The collection for which to create . + /// based on . + /// is null. + public static MapData Create(IEnumerable sections) + { + if (sections == null) + { + throw new ArgumentNullException("sections"); + } + + var mapFeatures = new List + { + new MapFeature(sections.Select(section => new MapGeometry(section.Points.Select(p => new Point2D(p.X, p.Y))))) + }; + + return new MapLineData(mapFeatures, Common.Forms.Properties.Resources.FailureMechanism_Sections_DisplayName) + { + Style = new LineStyle(Color.Khaki, 3, DashStyle.Dot) + }; + } + + /// + /// Create with default styling based on the start points of . + /// + /// The collection which's start points will be used to create . + /// based on the start points of . + /// is null. + public static MapData CreateStartPoints(IEnumerable sections) + { + if (sections == null) + { + throw new ArgumentNullException("sections"); + } + + IEnumerable startPoints = sections.Select(sl => sl.GetStart()); + string mapDataName = string.Format("{0} ({1})", + Common.Forms.Properties.Resources.FailureMechanism_Sections_DisplayName, + Common.Forms.Properties.Resources.FailureMechanismSections_StartPoints_DisplayName); + return new MapPointData(GetMapFeature(startPoints), mapDataName) + { + Style = new PointStyle(Color.DarkKhaki, 15, PointSymbol.Triangle) + }; + } + + /// + /// Create with default styling based on the end points of . + /// + /// The collection which's end points will be used to create . + /// based on the end points of . + /// is null. + public static MapData CreateEndPoints(IEnumerable sections) + { + if (sections == null) + { + throw new ArgumentNullException("sections"); + } + + IEnumerable startPoints = sections.Select(sl => sl.GetLast()); + string mapDataName = string.Format("{0} ({1})", + Common.Forms.Properties.Resources.FailureMechanism_Sections_DisplayName, + Common.Forms.Properties.Resources.FailureMechanismSections_EndPoints_DisplayName); + return new MapPointData(GetMapFeature(startPoints), mapDataName) + { + Style = new PointStyle(Color.DarkKhaki, 15, PointSymbol.Triangle) + }; + } + + /// + /// Create with default styling based on the . + /// + /// The for which to create . + /// based on the . + /// is null. + public static MapData Create(ReferenceLine referenceLine) + { + if (referenceLine == null) + { + throw new ArgumentNullException("referenceLine"); + } + + var features = GetMapFeature(referenceLine.Points); + + return new MapLineData(features, Common.Data.Properties.Resources.ReferenceLine_DisplayName) + { + Style = new LineStyle(Color.Red, 3, DashStyle.Solid) + }; + } + + /// + /// Create with default styling based on the locations of . + /// + /// The for which to create . + /// based on the locations in the . + /// is null. + public static MapData Create(HydraulicBoundaryDatabase hydraulicBoundaryDatabase) + { + if (hydraulicBoundaryDatabase == null) + { + throw new ArgumentNullException("hydraulicBoundaryDatabase"); + } + + IEnumerable locations = hydraulicBoundaryDatabase.Locations.Select(h => h.Location).ToArray(); + + var features = GetMapFeature(locations); + + return new MapPointData(features, Common.Data.Properties.Resources.HydraulicBoundaryConditions_DisplayName) + { + Style = new PointStyle(Color.DarkBlue, 6, PointSymbol.Circle) + }; + } + + /// + /// Create a instance with a name, but without data. + /// + /// The name of the . + /// An empty object. + public static MapLineData CreateEmptyLineData(string name) + { + return new MapLineData(Enumerable.Empty(), name); + } + + /// + /// Create a instance with a name, but without data. + /// + /// The name of the . + /// An empty object. + public static MapPointData CreateEmptyPointData(string name) + { + return new MapPointData(Enumerable.Empty(), name); + } + + private static IEnumerable GetMapFeature(IEnumerable points) + { + var features = new List + { + new MapFeature(new List + { + new MapGeometry(points) + }) + }; + return features; + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj =================================================================== diff -u -r8832cfacbfb0a999d9dd5ddcb93fd81bdb2fb09f -r473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision 8832cfacbfb0a999d9dd5ddcb93fd81bdb2fb09f) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision 473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6) @@ -102,6 +102,7 @@ + Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingMapDataFactoryTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingMapDataFactoryTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingMapDataFactoryTest.cs (revision 473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6) @@ -0,0 +1,353 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Linq; +using Core.Common.Base.Geometry; +using Core.Components.Gis.Data; +using Core.Components.Gis.Geometries; +using Core.Components.Gis.Style; +using NUnit.Framework; +using Ringtoets.Common.Data; +using Ringtoets.HydraRing.Data; +using Ringtoets.Piping.Forms.Properties; +using Ringtoets.Piping.Forms.Views; +using Ringtoets.Piping.Primitives; + +namespace Ringtoets.Piping.Forms.Test.Views +{ + [TestFixture] + public class PipingMapDataFactoryTest + { + [Test] + public void CreateEmptyLineData_Always_ReturnEmptyMapLineDataWithNameSet() + { + // Setup + const string name = ""; + + // Call + MapLineData mapData = PipingMapDataFactory.CreateEmptyLineData(name); + + // Assert + Assert.AreEqual(name, mapData.Name); + Assert.IsEmpty(mapData.Features); + } + + [Test] + public void CreateEmptyPointData_Always_ReturnEmptyMapLineDataWithNameSet() + { + // Setup + const string name = ""; + + // Call + MapPointData mapData = PipingMapDataFactory.CreateEmptyPointData(name); + + // Assert + Assert.AreEqual(name, mapData.Name); + Assert.IsEmpty(mapData.Features); + } + + [Test] + public void Create_GivenSurfaceLines_ReturnsMapFeaturesWithDefaultStyling() + { + // Setup + var pointsOne = new[] + { + new Point3D(1.2, 2.3, 4.0), + new Point3D(2.7, 2.0, 6.0) + }; + var pointsTwo = new[] + { + new Point3D(3.2, 23.3, 34.2), + new Point3D(7.7, 12.6, 1.2) + }; + var lines = new[] + { + new RingtoetsPipingSurfaceLine(), + new RingtoetsPipingSurfaceLine() + }; + lines[0].SetGeometry(pointsOne); + lines[1].SetGeometry(pointsTwo); + + // Call + MapData data = PipingMapDataFactory.Create(lines); + + // Assert + Assert.IsInstanceOf(data); + var mapLineData = (MapLineData) data; + Assert.AreEqual(1, mapLineData.Features.Count()); + Assert.AreEqual(2, mapLineData.Features.ElementAt(0).MapGeometries.Count()); + AssertEqualPointCollections(pointsOne, mapLineData.Features.ElementAt(0).MapGeometries.ElementAt(0)); + AssertEqualPointCollections(pointsTwo, mapLineData.Features.ElementAt(0).MapGeometries.ElementAt(1)); + Assert.AreEqual(Resources.PipingSurfaceLinesCollection_DisplayName, data.Name); + + AssertEqualStyle(mapLineData.Style, Color.DarkSeaGreen, 2, DashStyle.Solid); + } + + [Test] + public void Create_NoSurfaceLines_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => PipingMapDataFactory.Create((IEnumerable) null); + + // Assert + var parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("surfaceLines", parameter); + } + + [Test] + public void Create_GivenSections_ReturnsMapFeaturesWithDefaultStyling() + { + // Setup + var pointsOne = new[] + { + new Point2D(1.2, 2.3), + new Point2D(2.7, 2.0) + }; + var pointsTwo = new[] + { + new Point2D(3.2, 23.3), + new Point2D(7.7, 12.6) + }; + var lines = new[] + { + new FailureMechanismSection(string.Empty, pointsOne), + new FailureMechanismSection(string.Empty, pointsTwo) + }; + + // Call + MapData data = PipingMapDataFactory.Create(lines); + + // Assert + Assert.IsInstanceOf(data); + var mapLineData = (MapLineData) data; + Assert.AreEqual(1, mapLineData.Features.Count()); + Assert.AreEqual(2, mapLineData.Features.ElementAt(0).MapGeometries.Count()); + AssertEqualPointCollections(pointsOne, mapLineData.Features.ElementAt(0).MapGeometries.ElementAt(0)); + AssertEqualPointCollections(pointsTwo, mapLineData.Features.ElementAt(0).MapGeometries.ElementAt(1)); + Assert.AreEqual(Common.Forms.Properties.Resources.FailureMechanism_Sections_DisplayName, data.Name); + + AssertEqualStyle(mapLineData.Style, Color.Khaki, 3, DashStyle.Dot); + } + + [Test] + public void Create_NoSections_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => PipingMapDataFactory.Create((IEnumerable) null); + + // Assert + var parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("sections", parameter); + } + + [Test] + public void CreateStartPoints_GivenSections_ReturnsMapFeaturesWithDefaultStyling() + { + // Setup + var pointsOne = new[] + { + new Point2D(1.2, 2.3), + new Point2D(2.7, 2.0) + }; + var pointsTwo = new[] + { + new Point2D(3.2, 23.3), + new Point2D(7.7, 12.6) + }; + var lines = new[] + { + new FailureMechanismSection(string.Empty, pointsOne), + new FailureMechanismSection(string.Empty, pointsTwo) + }; + + // Call + MapData data = PipingMapDataFactory.CreateStartPoints(lines); + + // Assert + Assert.IsInstanceOf(data); + var mapPointData = (MapPointData) data; + Assert.AreEqual(1, mapPointData.Features.Count()); + Assert.AreEqual(1, mapPointData.Features.ElementAt(0).MapGeometries.Count()); + AssertEqualPointCollections(new[] + { + pointsOne[0], + pointsTwo[0] + }, mapPointData.Features.ElementAt(0).MapGeometries.ElementAt(0)); + + var name = SectionPointDisplayName(Common.Forms.Properties.Resources.FailureMechanismSections_StartPoints_DisplayName); + Assert.AreEqual(name, data.Name); + + AssertEqualStyle(mapPointData.Style, Color.DarkKhaki, 15, PointSymbol.Triangle); + } + + [Test] + public void CreateStartPoints_NoSections_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => PipingMapDataFactory.CreateStartPoints(null); + + // Assert + var parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("sections", parameter); + } + + [Test] + public void CreateEndPoints_GivenSections_ReturnsMapFeaturesWithDefaultStyling() + { + // Setup + var pointsOne = new[] + { + new Point2D(1.2, 2.3), + new Point2D(2.7, 2.0) + }; + var pointsTwo = new[] + { + new Point2D(3.2, 23.3), + new Point2D(7.7, 12.6) + }; + var lines = new[] + { + new FailureMechanismSection(string.Empty, pointsOne), + new FailureMechanismSection(string.Empty, pointsTwo) + }; + + // Call + MapData data = PipingMapDataFactory.CreateEndPoints(lines); + + // Assert + Assert.IsInstanceOf(data); + var mapPointData = (MapPointData) data; + Assert.AreEqual(1, mapPointData.Features.Count()); + Assert.AreEqual(1, mapPointData.Features.ElementAt(0).MapGeometries.Count()); + AssertEqualPointCollections(new[] + { + pointsOne[1], + pointsTwo[1] + }, mapPointData.Features.ElementAt(0).MapGeometries.ElementAt(0)); + + var name = SectionPointDisplayName(Common.Forms.Properties.Resources.FailureMechanismSections_EndPoints_DisplayName); + Assert.AreEqual(name, data.Name); + + AssertEqualStyle(mapPointData.Style, Color.DarkKhaki, 15, PointSymbol.Triangle); + } + + [Test] + public void CreateEndPoints_NoSections_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => PipingMapDataFactory.CreateEndPoints(null); + + // Assert + var parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("sections", parameter); + } + + [Test] + public void Create_GivenReferenceLine_ReturnsMapFeaturesWithDefaultStyling() + { + // Setup + var pointsOne = new[] + { + new Point2D(1.2, 2.3), + new Point2D(2.7, 2.0) + }; + var line = new ReferenceLine(); + line.SetGeometry(pointsOne); + + // Call + MapData data = PipingMapDataFactory.Create(line); + + // Assert + Assert.IsInstanceOf(data); + var mapLineData = (MapLineData) data; + Assert.AreEqual(1, mapLineData.Features.Count()); + Assert.AreEqual(1, mapLineData.Features.ElementAt(0).MapGeometries.Count()); + AssertEqualPointCollections(pointsOne, mapLineData.Features.ElementAt(0).MapGeometries.ElementAt(0)); + + Assert.AreEqual(Common.Data.Properties.Resources.ReferenceLine_DisplayName, data.Name); + + AssertEqualStyle(mapLineData.Style, Color.Red, 3, DashStyle.Solid); + } + + [Test] + public void Create_NoReferenceLine_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => PipingMapDataFactory.Create((ReferenceLine) null); + + // Assert + var parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("referenceLine", parameter); + } + + [Test] + public void Create_GivenHydraulicDatabase_ReturnsMapFeaturesWithDefaultStyling() + { + // Setup + var pointsOne = new[] + { + new Point2D(1.2, 2.3), + new Point2D(2.7, 2.0) + }; + var database = new HydraulicBoundaryDatabase(); + database.Locations.AddRange(pointsOne.Select(p => new HydraulicBoundaryLocation(0, "", p.X, p.Y))); + + // Call + MapData data = PipingMapDataFactory.Create(database); + + // Assert + Assert.IsInstanceOf(data); + var mapPointData = (MapPointData)data; + Assert.AreEqual(1, mapPointData.Features.Count()); + Assert.AreEqual(1, mapPointData.Features.ElementAt(0).MapGeometries.Count()); + AssertEqualPointCollections(pointsOne, mapPointData.Features.ElementAt(0).MapGeometries.ElementAt(0)); + + Assert.AreEqual(Common.Data.Properties.Resources.HydraulicBoundaryConditions_DisplayName, data.Name); + + AssertEqualStyle(mapPointData.Style, Color.DarkBlue, 6, PointSymbol.Circle); + } + + [Test] + public void Create_NoHydraulicDatabase_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => PipingMapDataFactory.Create((HydraulicBoundaryDatabase) null); + + // Assert + var parameter = Assert.Throws(test).ParamName; + Assert.AreEqual("hydraulicBoundaryDatabase", parameter); + } + + private void AssertEqualStyle(PointStyle pointStyle, Color color, int width, PointSymbol symbol) + { + Assert.AreEqual(color, pointStyle.Color); + Assert.AreEqual(width, pointStyle.Size); + Assert.AreEqual(symbol, pointStyle.Symbol); + } + + private static void AssertEqualStyle(LineStyle lineStyle, Color color, int width, DashStyle style) + { + Assert.AreEqual(color, lineStyle.Color); + Assert.AreEqual(width, lineStyle.Width); + Assert.AreEqual(style, lineStyle.Style); + } + + private static string SectionPointDisplayName(string name) + { + return string.Format("{0} ({1})", + Common.Forms.Properties.Resources.FailureMechanism_Sections_DisplayName, + name); + } + + private void AssertEqualPointCollections(IEnumerable points, MapGeometry geometry) + { + AssertEqualPointCollections(points.Select(p => new Point2D(p.X, p.Y)), geometry); + } + + private void AssertEqualPointCollections(IEnumerable points, MapGeometry geometry) + { + CollectionAssert.AreEqual(points.Select(p => new Point2D(p.X, p.Y)), geometry.Points); + } + } +} \ No newline at end of file