Index: Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapMultiLineDataConverterTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapMultiLineDataConverterTest.cs (revision 0) +++ Core/Components/test/Core.Components.DotSpatial.Test/Converter/MapMultiLineDataConverterTest.cs (revision 3607710d80a1f77bf97f81b10869074b765686a0) @@ -0,0 +1,120 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using Core.Components.DotSpatial.Converter; +using Core.Components.DotSpatial.TestUtil; +using Core.Components.Gis.Data; +using DotSpatial.Controls; +using NUnit.Framework; + +namespace Core.Components.DotSpatial.Test.Converter +{ + [TestFixture] + public class MapMultiLineDataConverterTest + { + [Test] + public void DefaultConstructor_IsMapMultiLineDataConverter() + { + // Call + var converter = new MapMultiLineDataConverter(); + + // Assert + Assert.IsInstanceOf>(converter); + } + + [Test] + public void CanConvertMapData_MapLineData_ReturnTrue() + { + // Setup + var converter = new MapMultiLineDataConverter(); + var lineData = new MapMultiLineData(Enumerable.Empty>()); + + // Call + var canConvert = converter.CanConvertMapData(lineData); + + // Assert + Assert.IsTrue(canConvert); + } + + [Test] + public void CanConvertMapData_TestMapData_ReturnsFalse() + { + // Setup + var converter = new MapMultiLineDataConverter(); + var mapData = new TestMapData(); + + // Call + var canConvert = converter.CanConvertMapData(mapData); + + // Assert + Assert.IsFalse(canConvert); + } + + [Test] + public void Convert_DataNull_ThrowsArgumentNullException() + { + // Setup + var testConverter = new MapMultiLineDataConverter(); + + // Call + TestDelegate test = () => testConverter.Convert(null); + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, "Null data cannot be converted into feature sets."); + } + + [Test] + public void Convert_DataCannotBeConverted_ThrowsArgumentException() + { + // Setup + var testConverter = new MapMultiLineDataConverter(); + var testMapData = new TestMapData(); + var expectedMessage = string.Format("The data of type {0} cannot be converted by this converter.", testMapData.GetType()); + + // Precondition + Assert.IsFalse(testConverter.CanConvertMapData(testMapData)); + + // Call + TestDelegate test = () => testConverter.Convert(testMapData); + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + public void Convert_RandomMultiLineData_ReturnsNewMapLineLayerList() + { + // Setup + var converter = new MapMultiLineDataConverter(); + var random = new Random(21); + var pointCount = random.Next(5, 10); + var lineCount = random.Next(5, 10); + var points = new Collection(); + var lines = new Collection>(); + + for (int li = 0; li < lineCount; li++) + { + for (int pi = 0; pi < pointCount; pi++) + { + points.Add(new Point2D(random.NextDouble(), random.NextDouble())); + } + lines.Add(points); + } + + var lineData = new MapMultiLineData(lines); + + // Call + var mapLayers = converter.Convert(lineData); + + // Assert + Assert.IsInstanceOf>(mapLayers); + Assert.AreEqual(1, mapLayers.Count); + var layer = mapLayers[0]; + Assert.IsInstanceOf(layer); + Assert.AreEqual(lineCount, layer.DataSet.Features.Count); + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.DotSpatial.Test/Core.Components.DotSpatial.Test.csproj =================================================================== diff -u -rca53cf67b367c4d2fab058aa39b3fe8de536dc7f -r3607710d80a1f77bf97f81b10869074b765686a0 --- Core/Components/test/Core.Components.DotSpatial.Test/Core.Components.DotSpatial.Test.csproj (.../Core.Components.DotSpatial.Test.csproj) (revision ca53cf67b367c4d2fab058aa39b3fe8de536dc7f) +++ Core/Components/test/Core.Components.DotSpatial.Test/Core.Components.DotSpatial.Test.csproj (.../Core.Components.DotSpatial.Test.csproj) (revision 3607710d80a1f77bf97f81b10869074b765686a0) @@ -99,6 +99,7 @@ + Index: Core/Components/test/Core.Components.Gis.Test/Core.Components.Gis.Test.csproj =================================================================== diff -u -r2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c -r3607710d80a1f77bf97f81b10869074b765686a0 --- Core/Components/test/Core.Components.Gis.Test/Core.Components.Gis.Test.csproj (.../Core.Components.Gis.Test.csproj) (revision 2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c) +++ Core/Components/test/Core.Components.Gis.Test/Core.Components.Gis.Test.csproj (.../Core.Components.Gis.Test.csproj) (revision 3607710d80a1f77bf97f81b10869074b765686a0) @@ -41,6 +41,7 @@ + Index: Core/Components/test/Core.Components.Gis.Test/Data/MapMultiLineDataTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.Gis.Test/Data/MapMultiLineDataTest.cs (revision 0) +++ Core/Components/test/Core.Components.Gis.Test/Data/MapMultiLineDataTest.cs (revision 3607710d80a1f77bf97f81b10869074b765686a0) @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using Core.Components.Gis.Data; + +using NUnit.Framework; + +namespace Core.Components.Gis.Test.Data +{ + [TestFixture] + public class MapMultiLineDataTest + { + [Test] + public void Constructor_NullCollection_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new MapMultiLineData(null); + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, string.Format("A point collection is required when creating a subclass of {0}.", typeof(PointBasedMapData))); + } + + [Test] + public void Constructor_WithEmptyCollection_CreatesNewMapLineData() + { + // Setup + var collection = new Collection>(); + + // Call + var data = new MapMultiLineData(collection); + + // Assert + Assert.IsInstanceOf(data); + Assert.AreNotSame(collection, data.Lines); + } + + [Test] + public void Constructor_WithPoints_CreatesNewMapLineData() + { + // Setup + var lines = CreateTestLines(); + + // Call + var data = new MapMultiLineData(lines); + + // Assert + Assert.IsInstanceOf(data); + Assert.AreNotSame(lines, data.Lines); + CollectionAssert.AreEqual(lines, data.Lines); + } + + private static IEnumerable> CreateTestLines() + { + return new Collection> + { + new Collection { + new Point2D(0.0, 1.1), + new Point2D(1.0, 2.1), + new Point2D(1.6, 1.6) + } + }; + } + } +} \ No newline at end of file Index: Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendView.cs =================================================================== diff -u -r61de56d96afe43d6ba193795c084a07fdff78b34 -r3607710d80a1f77bf97f81b10869074b765686a0 --- Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision 61de56d96afe43d6ba193795c084a07fdff78b34) +++ Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision 3607710d80a1f77bf97f81b10869074b765686a0) @@ -126,6 +126,16 @@ CanInsert = BaseMapCanInsert, OnDrop = BaseMapOnDrop }); + + treeViewControl.RegisterTreeNodeInfo(new TreeNodeInfo + { + Text = mapMultiLineData => DotSpatialResources.MapData_MultiLine_data_label, + Image = mapMultiLineData => DotSpatialResources.LineIcon, + CanDrag = (mapMultiLineData, parentData) => true, + CanCheck = mapMultiLineData => true, + IsChecked = mapMultiLineData => mapMultiLineData.IsVisible, + OnNodeChecked = MapMultiLineDataOnNodeChecked + }); } #region MapData @@ -145,6 +155,18 @@ PointBasedMapDataOnNodeChecked(mapPolygonData, parentData); } + private void MapMultiLineDataOnNodeChecked(MapMultiLineData mapMultiLineData, object parentData) + { + mapMultiLineData.IsVisible = !mapMultiLineData.IsVisible; + mapMultiLineData.NotifyObservers(); + + var observableParent = parentData as IObservable; + if (observableParent != null) + { + observableParent.NotifyObservers(); + } + } + private void PointBasedMapDataOnNodeChecked(PointBasedMapData pointBasedMapData, object parentData) { pointBasedMapData.IsVisible = !pointBasedMapData.IsVisible; Index: Core/Plugins/src/Core.Plugins.DotSpatial/Properties/Resources.Designer.cs =================================================================== diff -u -r3aa114b55dd6caa46890a54af64fba874497c135 -r3607710d80a1f77bf97f81b10869074b765686a0 --- Core/Plugins/src/Core.Plugins.DotSpatial/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 3aa114b55dd6caa46890a54af64fba874497c135) +++ Core/Plugins/src/Core.Plugins.DotSpatial/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 3607710d80a1f77bf97f81b10869074b765686a0) @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// Runtime Version:4.0.30319.34209 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -109,6 +109,15 @@ } /// + /// Looks up a localized string similar to Lijnen. + /// + public static string MapData_MultiLine_data_label { + get { + return ResourceManager.GetString("MapData_MultiLine_data_label", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Punten. /// public static string MapData_Point_data_label { Index: Core/Plugins/src/Core.Plugins.DotSpatial/Properties/Resources.resx =================================================================== diff -u -r3aa114b55dd6caa46890a54af64fba874497c135 -r3607710d80a1f77bf97f81b10869074b765686a0 --- Core/Plugins/src/Core.Plugins.DotSpatial/Properties/Resources.resx (.../Resources.resx) (revision 3aa114b55dd6caa46890a54af64fba874497c135) +++ Core/Plugins/src/Core.Plugins.DotSpatial/Properties/Resources.resx (.../Resources.resx) (revision 3607710d80a1f77bf97f81b10869074b765686a0) @@ -181,4 +181,7 @@ ..\Resources\zoomextents.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + Lijnen + \ No newline at end of file Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLegendViewTest.cs =================================================================== diff -u -r61f3b606ba0003553fe583462bab6e493043be5e -r3607710d80a1f77bf97f81b10869074b765686a0 --- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLegendViewTest.cs (.../MapLegendViewTest.cs) (revision 61f3b606ba0003553fe583462bab6e493043be5e) +++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLegendViewTest.cs (.../MapLegendViewTest.cs) (revision 3607710d80a1f77bf97f81b10869074b765686a0) @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Windows.Forms; +using Core.Common.Base.Geometry; using Core.Common.Controls.TreeView; using Core.Common.Controls.Views; using Core.Common.Utils.Reflection; @@ -41,7 +43,7 @@ } [Test] - public void Data_MapData_DataSet() + public void Data_MapDataCollection_DataSet() { // Setup var view = new MapLegendView(); @@ -55,7 +57,68 @@ Assert.IsInstanceOf(view.Data); } + [Test] + public void Data_MapPointData_DataSet() + { + // Setup + var view = new MapLegendView(); + var mapData = new MapPointData(Enumerable.Empty()); + + // Call + view.Data = mapData; + + // Assert + Assert.AreSame(mapData, view.Data); + Assert.IsInstanceOf(view.Data); + } + + [Test] + public void Data_MapLineData_DataSet() + { + // Setup + var view = new MapLegendView(); + var mapData = new MapLineData(Enumerable.Empty()); + + // Call + view.Data = mapData; + + // Assert + Assert.AreSame(mapData, view.Data); + Assert.IsInstanceOf(view.Data); + } + + [Test] + public void Data_MapPolygonData_DataSet() + { + // Setup + var view = new MapLegendView(); + var mapData = new MapPolygonData(Enumerable.Empty()); + + // Call + view.Data = mapData; + + // Assert + Assert.AreSame(mapData, view.Data); + Assert.IsInstanceOf(view.Data); + } + + [Test] + public void Data_MapMultiLineData_DataSet() + { + // Setup + var view = new MapLegendView(); + var mapData = new MapMultiLineData(Enumerable.Empty>()); + + // Call + view.Data = mapData; + + // Assert + Assert.AreSame(mapData, view.Data); + Assert.IsInstanceOf(view.Data); + } + + [Test] public void Data_ForNull_NullSet() { // Setup Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismView.cs =================================================================== diff -u -rdb376befd1575a80aa5f4d3e84f803e132ac1a75 -r3607710d80a1f77bf97f81b10869074b765686a0 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismView.cs (.../PipingFailureMechanismView.cs) (revision db376befd1575a80aa5f4d3e84f803e132ac1a75) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismView.cs (.../PipingFailureMechanismView.cs) (revision 3607710d80a1f77bf97f81b10869074b765686a0) @@ -57,17 +57,41 @@ } set { - data = value as PipingFailureMechanismContext; + var newValue = value as PipingFailureMechanismContext; - if (data != null) + DetachFromData(); + data = newValue; + SetDataToMap(); + AttachToData(); + } + } + + private void AttachToData() + { + if (data != null) + { + data.Parent.Attach(this); + var surfaceLines = data.WrappedData.SurfaceLines as IObservable; + if (surfaceLines != null) { - data.Parent.Detach(this); - SetDataToMap(); - data.Parent.Attach(this); + surfaceLines.Attach(this); } } } + private void DetachFromData() + { + if (data != null) + { + data.Parent.Detach(this); + var surfaceLines = data.WrappedData.SurfaceLines as IObservable; + if (surfaceLines != null) + { + surfaceLines.Detach(this); + } + } + } + public IMap Map { get @@ -80,14 +104,22 @@ { var mapDataList = new List(); - if (HasReferenceLinePoints()) + if (data != null) { - mapDataList.Add(GetReferenceLineData()); - } + if (HasReferenceLinePoints()) + { + mapDataList.Add(GetReferenceLineData()); + } - if (HasHydraulicBoundaryLocations()) - { - mapDataList.Add(GetHydraulicBoundaryLocations()); + if (HasHydraulicBoundaryLocations()) + { + mapDataList.Add(GetHydraulicBoundaryLocations()); + } + + if (HasSurfaceLines()) + { + mapDataList.Add(GetSurfaceLines()); + } } map.Data = new MapDataCollection(mapDataList); @@ -105,6 +137,12 @@ return new MapPointData(hrLocations); } + private MapData GetSurfaceLines() + { + IEnumerable> surfaceLines = data.WrappedData.SurfaceLines.Select(sl => sl.Points.Select(p => new Point2D(p.X, p.Y))); + return new MapMultiLineData(surfaceLines); + } + private bool HasReferenceLinePoints() { return data.Parent.ReferenceLine != null && data.Parent.ReferenceLine.Points.Any(); @@ -115,6 +153,11 @@ return data.Parent.HydraulicBoundaryDatabase != null && data.Parent.HydraulicBoundaryDatabase.Locations.Any(); } + private bool HasSurfaceLines() + { + return data.WrappedData.SurfaceLines.Any(); + } + public void UpdateObserver() { if (data != null) Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismViewTest.cs =================================================================== diff -u -r0965fa8f8a151c07b31ea35ab888c4ef969638e6 -r3607710d80a1f77bf97f81b10869074b765686a0 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismViewTest.cs (.../PipingFailureMechanismViewTest.cs) (revision 0965fa8f8a151c07b31ea35ab888c4ef969638e6) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismViewTest.cs (.../PipingFailureMechanismViewTest.cs) (revision 3607710d80a1f77bf97f81b10869074b765686a0) @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Windows.Forms; using Core.Common.Base; @@ -78,7 +79,7 @@ var assessmentSectionBase = new TestAssessmentSectionBase { HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(), - ReferenceLine = new ReferenceLine() + ReferenceLine = new ReferenceLine(), }; assessmentSectionBase.HydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(1, "test", 1.0, 2.0)); assessmentSectionBase.ReferenceLine.SetGeometry(new List @@ -88,6 +89,8 @@ }); var pipingFailureMechanism = new PipingFailureMechanism(); + pipingFailureMechanism.SurfaceLines.Add(new RingtoetsPipingSurfaceLine()); + var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSectionBase); // Call @@ -98,8 +101,9 @@ Assert.IsInstanceOf(map.Data); var mapData = map.Data as MapDataCollection; Assert.IsNotNull(mapData); - Assert.IsTrue(mapData.List.Any(md => md is MapPointData)); - Assert.IsTrue(mapData.List.Any(md => md is MapLineData)); + Assert.AreEqual(1, mapData.List.Count(md => md is MapPointData)); + Assert.AreEqual(1, mapData.List.Count(md => md is MapLineData)); + Assert.AreEqual(1, mapData.List.Count(md => md is MapMultiLineData)); } [Test] @@ -170,7 +174,6 @@ view.Data = pipingContext; var mapData = map.Data; - assessmentSectionBase.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); assessmentSectionBase.ReferenceLine.SetGeometry(new List { new Point2D(2.0, 5.0), @@ -187,6 +190,45 @@ } [Test] + public void UpdateObserver_SurfaceLinesUpdated_SetNewMapDataData() + { + // Setup + var view = new PipingFailureMechanismView(); + var map = (BaseMap)view.Controls[0]; + + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + var assessmentSectionBase = new TestAssessmentSectionBase(); + var pipingFailureMechanism = new PipingFailureMechanism(); + ((IObservable)pipingFailureMechanism.SurfaceLines).Attach(observer); + + var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSectionBase); + + view.Data = pipingContext; + var mapData = map.Data; + + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(new Collection + { + new Point3D(1,2,3), + new Point3D(1,2,3) + }); + pipingFailureMechanism.SurfaceLines.Add(surfaceLine); + + // Call + ((IObservable)pipingFailureMechanism.SurfaceLines).NotifyObservers(); + + // Assert + Assert.AreNotEqual(mapData, map.Data); + Assert.IsInstanceOf(map.Data); + mocks.VerifyAll(); + } + + [Test] public void UpdateObserver_OtherAssessmentSectionUpdated_MapDataNotUpdated() { // Setup @@ -271,8 +313,8 @@ assessmentSectionBase.Attach(observer); - MapData dataBeforeUpdate = map.Data; view.Data = null; + MapData dataBeforeUpdate = map.Data; assessmentSectionBase.ReferenceLine = new ReferenceLine(); assessmentSectionBase.ReferenceLine.SetGeometry(new List @@ -285,11 +327,46 @@ assessmentSectionBase.NotifyObservers(); // Assert - Assert.IsNull(view.Data); Assert.AreEqual(dataBeforeUpdate, map.Data); mocks.VerifyAll(); } + [Test] + public void NotifyObservers_DataUpdatedNotifyObserversOnOldData_NoUpdateInViewData() + { + // Setup + var mocks = new MockRepository(); + AssessmentSectionBase oldAssessmentSectionMock = mocks.Stub(); + AssessmentSectionBase newAssessmentSectionMock = mocks.Stub(); + mocks.ReplayAll(); + + newAssessmentSectionMock.ReferenceLine = new ReferenceLine(); + newAssessmentSectionMock.ReferenceLine.SetGeometry(new[] + { + new Point2D(2,4), + new Point2D(3,4) + }); + + var oldPipingFailureMechanismContext = new PipingFailureMechanismContext(new PipingFailureMechanism(), oldAssessmentSectionMock); + var newPipingFailureMechanismContext = new PipingFailureMechanismContext(new PipingFailureMechanism(), newAssessmentSectionMock); + var view = new PipingFailureMechanismView(); + var map = (BaseMap)view.Controls[0]; + + view.Data = oldPipingFailureMechanismContext; + view.Data = newPipingFailureMechanismContext; + MapData dataBeforeUpdate = map.Data; + + newAssessmentSectionMock.ReferenceLine.SetGeometry(Enumerable.Empty()); + + // Call + oldAssessmentSectionMock.NotifyObservers(); + + // Assert + Assert.AreEqual(dataBeforeUpdate, map.Data); + + mocks.VerifyAll(); + } + private class TestAssessmentSectionBase : AssessmentSectionBase { public override IEnumerable GetFailureMechanisms()