Index: Core/Components/src/Core.Components.Gis.IO/Importers/FeatureBasedMapDataImporter.cs =================================================================== diff -u -rd1bf253a0e3f11a168b4e185c4413c23995a1e8b -rbd6c70ad432ca3368d79c8bc2765de16dd0b574a --- Core/Components/src/Core.Components.Gis.IO/Importers/FeatureBasedMapDataImporter.cs (.../FeatureBasedMapDataImporter.cs) (revision d1bf253a0e3f11a168b4e185c4413c23995a1e8b) +++ Core/Components/src/Core.Components.Gis.IO/Importers/FeatureBasedMapDataImporter.cs (.../FeatureBasedMapDataImporter.cs) (revision bd6c70ad432ca3368d79c8bc2765de16dd0b574a) @@ -26,6 +26,7 @@ using Core.Common.IO.Readers; using Core.Common.Utils.Builders; using Core.Components.Gis.Data; +using Core.Components.Gis.Data.Removable; using Core.Components.Gis.IO.Properties; using Core.Components.Gis.IO.Readers; using DotSpatial.Data; @@ -69,7 +70,7 @@ private void AddFeatureBasedMapDataToMapDataCollection(FeatureBasedMapData importedMapData) { - ImportTarget.Add(importedMapData); + ImportTarget.Add(RemovableMapDataConverter.FromFeatureBasedMapData(importedMapData)); } private ReadResult ReadFeatureBasedMapData() Index: Core/Components/src/Core.Components.Gis/Core.Components.Gis.csproj =================================================================== diff -u -rbb84e8f229fbe284207a2ca2f4ce2244f4ce6076 -rbd6c70ad432ca3368d79c8bc2765de16dd0b574a --- Core/Components/src/Core.Components.Gis/Core.Components.Gis.csproj (.../Core.Components.Gis.csproj) (revision bb84e8f229fbe284207a2ca2f4ce2244f4ce6076) +++ Core/Components/src/Core.Components.Gis/Core.Components.Gis.csproj (.../Core.Components.Gis.csproj) (revision bd6c70ad432ca3368d79c8bc2765de16dd0b574a) @@ -41,13 +41,18 @@ Properties\GlobalAssembly.cs + + + + + Index: Core/Components/src/Core.Components.Gis/Data/Removable/IRemovable.cs =================================================================== diff -u --- Core/Components/src/Core.Components.Gis/Data/Removable/IRemovable.cs (revision 0) +++ Core/Components/src/Core.Components.Gis/Data/Removable/IRemovable.cs (revision bd6c70ad432ca3368d79c8bc2765de16dd0b574a) @@ -0,0 +1,28 @@ +// Copyright (C) Stichting Deltares 2017. 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. + +namespace Core.Components.Gis.Data.Removable +{ + public interface IRemovable + { + + } +} \ No newline at end of file Index: Core/Components/src/Core.Components.Gis/Data/Removable/RemovableMapDataConverter.cs =================================================================== diff -u --- Core/Components/src/Core.Components.Gis/Data/Removable/RemovableMapDataConverter.cs (revision 0) +++ Core/Components/src/Core.Components.Gis/Data/Removable/RemovableMapDataConverter.cs (revision bd6c70ad432ca3368d79c8bc2765de16dd0b574a) @@ -0,0 +1,69 @@ +// Copyright (C) Stichting Deltares 2017. 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; + +namespace Core.Components.Gis.Data.Removable +{ + /// + /// Helper for converting to + /// implementing . + /// + public static class RemovableMapDataConverter + { + /// + /// Converts the given to + /// implementing + /// + /// The map data to convert. + /// A new implementing . + /// Thrown when the type + /// could not be converted. + public static FeatureBasedMapData FromFeatureBasedMapData(FeatureBasedMapData mapData) + { + var mapPointData = mapData as MapPointData; + if (mapPointData != null) + { + return new RemovableMapPointData(mapPointData.Name, mapPointData.Style) + { + Features = mapPointData.Features + }; + } + var mapLineData = mapData as MapLineData; + if (mapLineData != null) + { + return new RemovableMapLineData(mapLineData.Name, mapLineData.Style) + { + Features = mapLineData.Features + }; + } + var mapPolygonData = mapData as MapPolygonData; + if (mapPolygonData != null) + { + return new RemovableMapPolygonData(mapPolygonData.Name, mapPolygonData.Style) + { + Features = mapPolygonData.Features + }; + } + throw new NotSupportedException($"The given {nameof(mapData)} was not convertible to {typeof(IRemovable).Name} data."); + } + } +} \ No newline at end of file Index: Core/Components/src/Core.Components.Gis/Data/Removable/RemovableMapLineData.cs =================================================================== diff -u --- Core/Components/src/Core.Components.Gis/Data/Removable/RemovableMapLineData.cs (revision 0) +++ Core/Components/src/Core.Components.Gis/Data/Removable/RemovableMapLineData.cs (revision bd6c70ad432ca3368d79c8bc2765de16dd0b574a) @@ -0,0 +1,51 @@ +// Copyright (C) Stichting Deltares 2017. 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 Core.Components.Gis.Style; + +namespace Core.Components.Gis.Data.Removable +{ + /// + /// that is marked as being removable. + /// + public class RemovableMapLineData : MapLineData, IRemovable + { + /// + /// Creates a new instance of with default styling. + /// + /// The name of the . + /// Thrown when is + /// null or only whitespace. + public RemovableMapLineData(string name) : base(name) {} + + /// + /// Creates a new instance of with default styling. + /// + /// The name of the . + /// The style of the data. + /// Thrown when is + /// null or only whitespace. + /// Thrown when + /// is null. + public RemovableMapLineData(string name, LineStyle style) : base(name, style) {} + } +} \ No newline at end of file Index: Core/Components/src/Core.Components.Gis/Data/Removable/RemovableMapPointData.cs =================================================================== diff -u --- Core/Components/src/Core.Components.Gis/Data/Removable/RemovableMapPointData.cs (revision 0) +++ Core/Components/src/Core.Components.Gis/Data/Removable/RemovableMapPointData.cs (revision bd6c70ad432ca3368d79c8bc2765de16dd0b574a) @@ -0,0 +1,51 @@ +// Copyright (C) Stichting Deltares 2017. 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 Core.Components.Gis.Style; + +namespace Core.Components.Gis.Data.Removable +{ + /// + /// that is marked as being removable. + /// + public class RemovableMapPointData : MapPointData, IRemovable + { + /// + /// Creates a new instance of with default styling. + /// + /// The name of the . + /// Thrown when is + /// null or only whitespace. + public RemovableMapPointData(string name) : base(name) {} + + /// + /// Creates a new instance of . + /// + /// The name of the . + /// The style of the data. + /// Thrown when is + /// null or only whitespace. + /// Thrown when + /// is null. + public RemovableMapPointData(string name, PointStyle style) : base(name, style) {} + } +} \ No newline at end of file Index: Core/Components/src/Core.Components.Gis/Data/Removable/RemovableMapPolygonData.cs =================================================================== diff -u --- Core/Components/src/Core.Components.Gis/Data/Removable/RemovableMapPolygonData.cs (revision 0) +++ Core/Components/src/Core.Components.Gis/Data/Removable/RemovableMapPolygonData.cs (revision bd6c70ad432ca3368d79c8bc2765de16dd0b574a) @@ -0,0 +1,51 @@ +// Copyright (C) Stichting Deltares 2017. 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 Core.Components.Gis.Style; + +namespace Core.Components.Gis.Data.Removable +{ + /// + /// that is marked as being removable. + /// + public class RemovableMapPolygonData : MapPolygonData, IRemovable + { + /// + /// Creates a new instance of with default styling. + /// + /// The name of the . + /// Thrown when is + /// null or only whitespace. + public RemovableMapPolygonData(string name) : base(name) {} + + /// + /// Creates a new instance of . + /// + /// The name of the . + /// The style of the data. + /// Thrown when is + /// null or only whitespace. + /// Thrown when + /// is null. + public RemovableMapPolygonData(string name, PolygonStyle style) : base(name, style) {} + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.Gis.Test/Core.Components.Gis.Test.csproj =================================================================== diff -u -r380ff7e39d59dc26bf7d03596a807acf3d2eeb24 -rbd6c70ad432ca3368d79c8bc2765de16dd0b574a --- Core/Components/test/Core.Components.Gis.Test/Core.Components.Gis.Test.csproj (.../Core.Components.Gis.Test.csproj) (revision 380ff7e39d59dc26bf7d03596a807acf3d2eeb24) +++ Core/Components/test/Core.Components.Gis.Test/Core.Components.Gis.Test.csproj (.../Core.Components.Gis.Test.csproj) (revision bd6c70ad432ca3368d79c8bc2765de16dd0b574a) @@ -54,6 +54,10 @@ + + + + Index: Core/Components/test/Core.Components.Gis.Test/Data/Removable/MapLineDataTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.Gis.Test/Data/Removable/MapLineDataTest.cs (revision 0) +++ Core/Components/test/Core.Components.Gis.Test/Data/Removable/MapLineDataTest.cs (revision bd6c70ad432ca3368d79c8bc2765de16dd0b574a) @@ -0,0 +1,93 @@ +// Copyright (C) Stichting Deltares 2017. 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.Drawing; +using System.Drawing.Drawing2D; +using Core.Common.TestUtil; +using Core.Components.Gis.Data; +using Core.Components.Gis.Data.Removable; +using Core.Components.Gis.Style; +using NUnit.Framework; + +namespace Core.Components.Gis.Test.Data.Removable +{ + [TestFixture] + public class RemovableMapLineDataTest + { + [Test] + public void Constructor_ValidName_NameAndDefaultValuesSet() + { + // Call + var data = new RemovableMapLineData("test data"); + + // Assert + Assert.AreEqual("test data", data.Name); + Assert.IsEmpty(data.Features); + Assert.IsInstanceOf(data); + Assert.IsInstanceOf(data); + Assert.AreEqual(Color.Black, data.Style.Color); + Assert.AreEqual(2, data.Style.Width); + Assert.AreEqual(DashStyle.Solid, data.Style.DashStyle); + } + + [Test] + [TestCase(null)] + [TestCase("")] + [TestCase(" ")] + public void Constructor_InvalidName_ThrowsArgumentException(string invalidName) + { + // Call + TestDelegate test = () => new RemovableMapLineData(invalidName); + + // Assert + const string expectedMessage = "A name must be set to the map data."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + public void Constructor_StyleNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => new RemovableMapLineData("test data", null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("style", exception.ParamName); + } + + [Test] + public void Constructor_WithStyle_ExpectedValues() + { + // Setup + var style = new LineStyle(Color.Red, 5, DashStyle.Dash); + + // Call + var data = new RemovableMapLineData("test data", style); + + // Assert + Assert.AreEqual("test data", data.Name); + Assert.IsEmpty(data.Features); + Assert.IsInstanceOf(data); + Assert.AreSame(style, data.Style); + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.Gis.Test/Data/Removable/MapPointDataTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.Gis.Test/Data/Removable/MapPointDataTest.cs (revision 0) +++ Core/Components/test/Core.Components.Gis.Test/Data/Removable/MapPointDataTest.cs (revision bd6c70ad432ca3368d79c8bc2765de16dd0b574a) @@ -0,0 +1,94 @@ +// Copyright (C) Stichting Deltares 2017. 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.Drawing; +using Core.Common.TestUtil; +using Core.Components.Gis.Data; +using Core.Components.Gis.Data.Removable; +using Core.Components.Gis.Style; +using NUnit.Framework; + +namespace Core.Components.Gis.Test.Data.Removable +{ + [TestFixture] + public class RemovableMapPointDataTest + { + [Test] + public void Constructor_ValidName_NameAndDefaultValuesSet() + { + // Call + var data = new RemovableMapPointData("test data"); + + // Assert + Assert.AreEqual("test data", data.Name); + Assert.IsEmpty(data.Features); + Assert.IsInstanceOf(data); + Assert.IsInstanceOf(data); + Assert.AreEqual(Color.Black, data.Style.Color); + Assert.AreEqual(2, data.Style.Size); + Assert.AreEqual(PointSymbol.Square, data.Style.Symbol); + Assert.AreEqual(Color.Black, data.Style.StrokeColor); + Assert.AreEqual(1, data.Style.StrokeThickness); + } + + [Test] + [TestCase(null)] + [TestCase("")] + [TestCase(" ")] + public void Constructor_InvalidName_ThrowsArgumentException(string invalidName) + { + // Call + TestDelegate test = () => new RemovableMapPointData(invalidName); + + // Assert + const string expectedMessage = "A name must be set to the map data."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + public void Constructor_StyleNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => new RemovableMapPointData("test data", null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("style", exception.ParamName); + } + + [Test] + public void Constructor_WithStyle_ExpectedValues() + { + // Setup + var style = new PointStyle(Color.Aqua, 3, PointSymbol.Circle); + + // Call + var data = new RemovableMapPointData("test data", style); + + // Assert + Assert.AreEqual("test data", data.Name); + Assert.IsEmpty(data.Features); + Assert.IsInstanceOf(data); + Assert.AreSame(style, data.Style); + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.Gis.Test/Data/Removable/MapPolygonDataTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.Gis.Test/Data/Removable/MapPolygonDataTest.cs (revision 0) +++ Core/Components/test/Core.Components.Gis.Test/Data/Removable/MapPolygonDataTest.cs (revision bd6c70ad432ca3368d79c8bc2765de16dd0b574a) @@ -0,0 +1,92 @@ +// Copyright (C) Stichting Deltares 2017. 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.Drawing; +using Core.Common.TestUtil; +using Core.Components.Gis.Data; +using Core.Components.Gis.Data.Removable; +using Core.Components.Gis.Style; +using NUnit.Framework; + +namespace Core.Components.Gis.Test.Data.Removable +{ + [TestFixture] + public class RemovableMapPolygonDataTest + { + [Test] + public void Constructor_ValidName_NameAndDefaultValuesSet() + { + // Call + var data = new RemovableMapPolygonData("test data"); + + // Assert + Assert.AreEqual("test data", data.Name); + Assert.IsEmpty(data.Features); + Assert.IsInstanceOf(data); + Assert.IsInstanceOf(data); + Assert.AreEqual(Color.DarkGray, data.Style.FillColor); + Assert.AreEqual(Color.Black, data.Style.StrokeColor); + Assert.AreEqual(2, data.Style.Width); + } + + [Test] + [TestCase(null)] + [TestCase("")] + [TestCase(" ")] + public void Constructor_InvalidName_ThrowsArgumentException(string invalidName) + { + // Call + TestDelegate test = () => new RemovableMapPolygonData(invalidName); + + // Assert + const string expectedMessage = "A name must be set to the map data."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + public void Constructor_StyleNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => new RemovableMapPolygonData("test data", null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("style", exception.ParamName); + } + + [Test] + public void Constructor_WithStyle_ExpectedValues() + { + // Setup + var style = new PolygonStyle(Color.Aqua, Color.DarkGoldenrod, 3); + + // Call + var data = new RemovableMapPolygonData("test data", style); + + // Assert + Assert.AreEqual("test data", data.Name); + Assert.IsEmpty(data.Features); + Assert.IsInstanceOf(data); + Assert.AreSame(style, data.Style); + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.Gis.Test/Data/Removable/RemovableMapDataConverterTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.Gis.Test/Data/Removable/RemovableMapDataConverterTest.cs (revision 0) +++ Core/Components/test/Core.Components.Gis.Test/Data/Removable/RemovableMapDataConverterTest.cs (revision bd6c70ad432ca3368d79c8bc2765de16dd0b574a) @@ -0,0 +1,120 @@ +// Copyright (C) Stichting Deltares 2017. 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.Drawing; +using System.Drawing.Drawing2D; +using Core.Components.DotSpatial.TestUtil; +using Core.Components.Gis.Data; +using Core.Components.Gis.Data.Removable; +using Core.Components.Gis.Features; +using Core.Components.Gis.Style; +using NUnit.Framework; + +namespace Core.Components.Gis.Test.Data.Removable +{ + [TestFixture] + public class RemovableMapDataConverterTest + { + [Test] + public void FromFeatureBasedMapData_WithMapPointData_ReturnsNewRemoveableDataWithSameProperties() + { + // Setup + const string name = "test"; + var mapFeatures = new MapFeature[0]; + var pointStyle = new PointStyle(Color.AliceBlue, 3, PointSymbol.Diamond); + + var mapData = new MapPointData(name, pointStyle) + { + Features = mapFeatures + }; + + // Call + var convertedData = RemovableMapDataConverter.FromFeatureBasedMapData(mapData) as RemovableMapPointData; + + // Assert + Assert.NotNull(convertedData); + Assert.AreEqual(name, convertedData.Name); + Assert.AreEqual(pointStyle, convertedData.Style); + Assert.AreSame(mapFeatures, convertedData.Features); + } + + [Test] + public void FromFeatureBasedMapData_WithMapLineData_ReturnsNewRemoveableDataWithSameProperties() + { + // Setup + const string name = "test"; + var mapFeatures = new MapFeature[0]; + var lineStyle = new LineStyle(Color.AliceBlue, 3, DashStyle.Dash); + + var mapData = new MapLineData(name, lineStyle) + { + Features = mapFeatures + }; + + // Call + var convertedData = RemovableMapDataConverter.FromFeatureBasedMapData(mapData) as RemovableMapLineData; + + // Assert + Assert.NotNull(convertedData); + Assert.AreEqual(name, convertedData.Name); + Assert.AreEqual(lineStyle, convertedData.Style); + Assert.AreSame(mapFeatures, convertedData.Features); + } + + [Test] + public void FromFeatureBasedMapData_WithMapPolygonData_ReturnsNewRemoveableDataWithSameProperties() + { + // Setup + const string name = "test"; + var mapFeatures = new MapFeature[0]; + var polygonStyle = new PolygonStyle(Color.AliceBlue, Color.DeepSkyBlue, 3); + + var mapData = new MapPolygonData(name, polygonStyle) + { + Features = mapFeatures + }; + + // Call + var convertedData = RemovableMapDataConverter.FromFeatureBasedMapData(mapData) as RemovableMapPolygonData; + + // Assert + Assert.NotNull(convertedData); + Assert.AreEqual(name, convertedData.Name); + Assert.AreEqual(polygonStyle, convertedData.Style); + Assert.AreSame(mapFeatures, convertedData.Features); + } + + [Test] + public void FromFeatureBasedMapData_WithUnsupportedFeatureBasedMapData_ThrowsNotSupportedException() + { + // Setup + var testData = new TestFeatureBasedMapData("test"); + + // Call + TestDelegate test = () => RemovableMapDataConverter.FromFeatureBasedMapData(testData); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("The given mapData was not convertible to IRemovable data.", exception.Message); + } + } +} \ No newline at end of file Index: Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rbd6c70ad432ca3368d79c8bc2765de16dd0b574a --- Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision bd6c70ad432ca3368d79c8bc2765de16dd0b574a) @@ -26,6 +26,7 @@ using Core.Common.Controls.Views; using Core.Common.Gui.ContextMenu; using Core.Components.Gis.Data; +using Core.Components.Gis.Data.Removable; using Core.Components.Gis.Forms; using MapResources = Core.Plugins.Map.Properties.Resources; using GuiResources = Core.Common.Gui.Properties.Resources; @@ -126,6 +127,8 @@ .AddSeparator() .AddPropertiesItem() .Build(), + CanRemove = CanRemoveMapData, + OnNodeRemoved = RemoveFromParent, CanDrag = (mapPointData, parentData) => true, CanCheck = mapPointData => true, IsChecked = mapPointData => mapPointData.IsVisible, @@ -141,6 +144,8 @@ .AddSeparator() .AddPropertiesItem() .Build(), + CanRemove = CanRemoveMapData, + OnNodeRemoved = RemoveFromParent, CanDrag = (mapLineData, parentData) => true, CanCheck = mapLineData => true, IsChecked = mapLineData => mapLineData.IsVisible, @@ -156,6 +161,8 @@ .AddSeparator() .AddPropertiesItem() .Build(), + CanRemove = CanRemoveMapData, + OnNodeRemoved = RemoveFromParent, CanDrag = (mapPolygonData, parentData) => true, CanCheck = mapPolygonData => true, IsChecked = mapPolygonData => mapPolygonData.IsVisible, @@ -183,6 +190,21 @@ }); } + private static bool CanRemoveMapData(MapData mapData, object parent) + { + return mapData is IRemovable && parent is MapDataCollection; + } + + private static void RemoveFromParent(MapData dataToRemove, object parentData) + { + if (CanRemoveMapData(dataToRemove, parentData)) + { + var collection = (MapDataCollection) parentData; + collection.Remove(dataToRemove); + collection.NotifyObservers(); + } + } + private StrictContextMenuItem CreateZoomToExtentsItem(MapData nodeData, string toolTip, bool isEnabled) { return new StrictContextMenuItem($"&{MapResources.Ribbon_ZoomToAll}", Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapLineDataTreeNodeInfoTest.cs =================================================================== diff -u -r39c7764f75bd4ab7e0f7c172c4eb446bae7a3d1d -rbd6c70ad432ca3368d79c8bc2765de16dd0b574a --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapLineDataTreeNodeInfoTest.cs (.../MapLineDataTreeNodeInfoTest.cs) (revision 39c7764f75bd4ab7e0f7c172c4eb446bae7a3d1d) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapLineDataTreeNodeInfoTest.cs (.../MapLineDataTreeNodeInfoTest.cs) (revision bd6c70ad432ca3368d79c8bc2765de16dd0b574a) @@ -31,6 +31,7 @@ using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; +using Core.Components.Gis.Data.Removable; using Core.Components.Gis.Features; using Core.Components.Gis.Forms; using Core.Components.Gis.Geometries; @@ -89,8 +90,8 @@ Assert.IsNull(info.ChildNodeObjects); Assert.IsNull(info.CanRename); Assert.IsNull(info.OnNodeRenamed); - Assert.IsNull(info.CanRemove); - Assert.IsNull(info.OnNodeRemoved); + Assert.IsNotNull(info.CanRemove); + Assert.IsNotNull(info.OnNodeRemoved); Assert.IsNotNull(info.CanCheck); Assert.IsNotNull(info.IsChecked); Assert.IsNotNull(info.OnNodeChecked); @@ -317,6 +318,79 @@ Assert.IsTrue(canDrag); } + [Test] + public void CanRemove_WithRemovableDataAndCollection_ReturnTrue() + { + // Setup + var removable = mocks.StrictMultiMock(new[] + { + typeof(IRemovable) + }, "name"); + mocks.ReplayAll(); + + // Call + bool canRemove = info.CanRemove(removable, new MapDataCollection("collection")); + + // Assert + Assert.IsTrue(canRemove); + } + + [Test] + public void CanRemove_WithoutCollection_ReturnFalse() + { + // Setup + var removable = mocks.StrictMultiMock(new[] + { + typeof(IRemovable) + }, "name"); + mocks.ReplayAll(); + + // Call + bool canRemove = info.CanRemove(removable, null); + + // Assert + Assert.IsFalse(canRemove); + } + + [Test] + public void CanRemove_WithNotRemovableData_ReturnTrue() + { + // Setup + var notRemovable = mocks.StrictMock("name"); + mocks.ReplayAll(); + + // Call + bool canRemove = info.CanRemove(notRemovable, new MapDataCollection("collection")); + + // Assert + Assert.IsFalse(canRemove); + } + + [Test] + public void OnNodeRemoved_WithRemovableDataToRemove_DataRemoved() + { + // Setup + var toRemove = mocks.StrictMultiMock(new[] + { + typeof(IRemovable) + }, "name"); + var otherData = mocks.Stub("name"); + mocks.ReplayAll(); + + var collection = new MapDataCollection("collection"); + collection.Add(toRemove); + collection.Add(otherData); + + // Call + info.OnNodeRemoved(toRemove, collection); + + // Assert + Assert.AreEqual(new[] + { + otherData + }, collection.Collection); + } + [TestCase(true)] [TestCase(false)] public void IsChecked_Always_ReturnsAccordingToVisibleStateOfLineData(bool isVisible) Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPointDataTreeNodeInfoTest.cs =================================================================== diff -u -r39c7764f75bd4ab7e0f7c172c4eb446bae7a3d1d -rbd6c70ad432ca3368d79c8bc2765de16dd0b574a --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPointDataTreeNodeInfoTest.cs (.../MapPointDataTreeNodeInfoTest.cs) (revision 39c7764f75bd4ab7e0f7c172c4eb446bae7a3d1d) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPointDataTreeNodeInfoTest.cs (.../MapPointDataTreeNodeInfoTest.cs) (revision bd6c70ad432ca3368d79c8bc2765de16dd0b574a) @@ -31,6 +31,7 @@ using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; +using Core.Components.Gis.Data.Removable; using Core.Components.Gis.Features; using Core.Components.Gis.Forms; using Core.Components.Gis.Geometries; @@ -89,8 +90,8 @@ Assert.IsNull(info.ChildNodeObjects); Assert.IsNull(info.CanRename); Assert.IsNull(info.OnNodeRenamed); - Assert.IsNull(info.CanRemove); - Assert.IsNull(info.OnNodeRemoved); + Assert.IsNotNull(info.CanRemove); + Assert.IsNotNull(info.OnNodeRemoved); Assert.IsNotNull(info.CanCheck); Assert.IsNotNull(info.IsChecked); Assert.IsNotNull(info.OnNodeChecked); @@ -317,6 +318,79 @@ Assert.IsTrue(canDrag); } + [Test] + public void CanRemove_WithRemovableDataAndCollection_ReturnTrue() + { + // Setup + var removable = mocks.StrictMultiMock(new[] + { + typeof(IRemovable) + }, "name"); + mocks.ReplayAll(); + + // Call + bool canRemove = info.CanRemove(removable, new MapDataCollection("collection")); + + // Assert + Assert.IsTrue(canRemove); + } + + [Test] + public void CanRemove_WithoutCollection_ReturnFalse() + { + // Setup + var removable = mocks.StrictMultiMock(new[] + { + typeof(IRemovable) + }, "name"); + mocks.ReplayAll(); + + // Call + bool canRemove = info.CanRemove(removable, null); + + // Assert + Assert.IsFalse(canRemove); + } + + [Test] + public void CanRemove_WithNotRemovableData_ReturnTrue() + { + // Setup + var notRemovable = mocks.StrictMock("name"); + mocks.ReplayAll(); + + // Call + bool canRemove = info.CanRemove(notRemovable, new MapDataCollection("collection")); + + // Assert + Assert.IsFalse(canRemove); + } + + [Test] + public void OnNodeRemoved_WithRemovableDataToRemove_DataRemoved() + { + // Setup + var toRemove = mocks.StrictMultiMock(new[] + { + typeof(IRemovable) + }, "name"); + var otherData = mocks.Stub("name"); + mocks.ReplayAll(); + + var collection = new MapDataCollection("collection"); + collection.Add(toRemove); + collection.Add(otherData); + + // Call + info.OnNodeRemoved(toRemove, collection); + + // Assert + Assert.AreEqual(new[] + { + otherData + }, collection.Collection); + } + [TestCase(true)] [TestCase(false)] public void IsChecked_Always_ReturnsAccordingToVisibleStateOfPointData(bool isVisible) Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPolygonDataTreeNodeInfoTest.cs =================================================================== diff -u -r39c7764f75bd4ab7e0f7c172c4eb446bae7a3d1d -rbd6c70ad432ca3368d79c8bc2765de16dd0b574a --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPolygonDataTreeNodeInfoTest.cs (.../MapPolygonDataTreeNodeInfoTest.cs) (revision 39c7764f75bd4ab7e0f7c172c4eb446bae7a3d1d) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPolygonDataTreeNodeInfoTest.cs (.../MapPolygonDataTreeNodeInfoTest.cs) (revision bd6c70ad432ca3368d79c8bc2765de16dd0b574a) @@ -31,6 +31,7 @@ using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; +using Core.Components.Gis.Data.Removable; using Core.Components.Gis.Features; using Core.Components.Gis.Forms; using Core.Components.Gis.Geometries; @@ -89,8 +90,8 @@ Assert.IsNull(info.ChildNodeObjects); Assert.IsNull(info.CanRename); Assert.IsNull(info.OnNodeRenamed); - Assert.IsNull(info.CanRemove); - Assert.IsNull(info.OnNodeRemoved); + Assert.IsNotNull(info.CanRemove); + Assert.IsNotNull(info.OnNodeRemoved); Assert.IsNotNull(info.CanCheck); Assert.IsNotNull(info.IsChecked); Assert.IsNotNull(info.OnNodeChecked); @@ -317,6 +318,79 @@ Assert.IsTrue(canDrag); } + [Test] + public void CanRemove_WithRemovableDataAndCollection_ReturnTrue() + { + // Setup + var removable = mocks.StrictMultiMock(new[] + { + typeof(IRemovable) + }, "name"); + mocks.ReplayAll(); + + // Call + bool canRemove = info.CanRemove(removable, new MapDataCollection("collection")); + + // Assert + Assert.IsTrue(canRemove); + } + + [Test] + public void CanRemove_WithoutCollection_ReturnFalse() + { + // Setup + var removable = mocks.StrictMultiMock(new[] + { + typeof(IRemovable) + }, "name"); + mocks.ReplayAll(); + + // Call + bool canRemove = info.CanRemove(removable, null); + + // Assert + Assert.IsFalse(canRemove); + } + + [Test] + public void CanRemove_WithNotRemovableData_ReturnTrue() + { + // Setup + var notRemovable = mocks.StrictMock("name"); + mocks.ReplayAll(); + + // Call + bool canRemove = info.CanRemove(notRemovable, new MapDataCollection("collection")); + + // Assert + Assert.IsFalse(canRemove); + } + + [Test] + public void OnNodeRemoved_WithRemovableDataToRemove_DataRemoved() + { + // Setup + var toRemove = mocks.StrictMultiMock(new[] + { + typeof(IRemovable) + }, "name"); + var otherData = mocks.Stub("name"); + mocks.ReplayAll(); + + var collection = new MapDataCollection("collection"); + collection.Add(toRemove); + collection.Add(otherData); + + // Call + info.OnNodeRemoved(toRemove, collection); + + // Assert + Assert.AreEqual(new[] + { + otherData + }, collection.Collection); + } + [TestCase(true)] [TestCase(false)] public void IsChecked_Always_ReturnsAccordingToVisibleStateOfPolygonData(bool isVisible)