Index: Core/Components/src/Core.Components.Charting/Data/PointBasedChartData.cs
===================================================================
diff -u -rfbb37872d09f1ded75ce2209e8e48a6b64d8a78f -r3167b898b071fea4cf86c775bca5467fab086038
--- Core/Components/src/Core.Components.Charting/Data/PointBasedChartData.cs (.../PointBasedChartData.cs) (revision fbb37872d09f1ded75ce2209e8e48a6b64d8a78f)
+++ Core/Components/src/Core.Components.Charting/Data/PointBasedChartData.cs (.../PointBasedChartData.cs) (revision 3167b898b071fea4cf86c775bca5467fab086038)
@@ -29,8 +29,8 @@
///
/// Base class for which is based on a collection of points.
///
- public abstract class PointBasedChartData : ChartData {
-
+ public abstract class PointBasedChartData : ChartData
+ {
///
/// Creates a new instance of .
///
Index: Core/Components/src/Core.Components.DotSpatial/BaseMap.cs
===================================================================
diff -u -r37dc25947c67f84a31ca868d2acceec4f48721cc -r3167b898b071fea4cf86c775bca5467fab086038
--- Core/Components/src/Core.Components.DotSpatial/BaseMap.cs (.../BaseMap.cs) (revision 37dc25947c67f84a31ca868d2acceec4f48721cc)
+++ Core/Components/src/Core.Components.DotSpatial/BaseMap.cs (.../BaseMap.cs) (revision 3167b898b071fea4cf86c775bca5467fab086038)
@@ -19,14 +19,10 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
-using System;
-using System.IO;
using System.Windows.Forms;
+using Core.Components.DotSpatial.Converter;
using Core.Components.DotSpatial.Data;
-using Core.Components.DotSpatial.Exceptions;
-using Core.Components.DotSpatial.Properties;
using DotSpatial.Controls;
-using log4net;
namespace Core.Components.DotSpatial
{
@@ -35,7 +31,7 @@
///
public sealed class BaseMap : Control, IMap
{
- private static readonly ILog Log = LogManager.GetLogger(typeof(BaseMap));
+ private readonly MapDataFactory mapDataFactory = new MapDataFactory();
private MapData data;
private Map map;
@@ -50,9 +46,6 @@
///
/// Gets and sets the . When is not empty it will load the data on the map.
///
- /// Thrown when is null.
- /// Thrown when does not exist.
- /// Thrown when the data in is not valid.
public MapData Data
{
get
@@ -66,47 +59,29 @@
return;
}
- if (value == null)
- {
- throw new ArgumentNullException("MapData", "MapData is required when adding shapeFiles");
- }
+ data = value;
+ DrawFeatureSets();
+ }
+ }
- if (value.IsValid())
- {
- data = value;
- LoadData();
- }
- else
- {
- throw new MapDataException(Resources.BaseMap_SetMapData_The_data_available_in_MapData_is_not_valid_);
- }
+ private void DrawFeatureSets()
+ {
+ map.ClearLayers();
+ if (data != null)
+ {
+ map.Layers.Add(mapDataFactory.Create(data));
}
}
- ///
- /// Initialize the for the
- ///
private void InitializeMapView()
{
map = new Map
{
+ ProjectionModeDefine = ActionMode.Never,
Dock = DockStyle.Fill,
FunctionMode = FunctionMode.Pan,
};
Controls.Add(map);
}
-
- ///
- /// Loads the data from the files given in and shows them on the .
- ///
- private void LoadData()
- {
- foreach (string filePath in data.FilePaths)
- {
- map.AddLayer(filePath);
-
- Log.InfoFormat(Resources.BaseMap_LoadData_Shape_file_on_path__0__is_added_to_the_map_, filePath);
- }
- }
}
}
\ No newline at end of file
Index: Core/Components/src/Core.Components.DotSpatial/Converter/IMapDataConverter.cs
===================================================================
diff -u
--- Core/Components/src/Core.Components.DotSpatial/Converter/IMapDataConverter.cs (revision 0)
+++ Core/Components/src/Core.Components.DotSpatial/Converter/IMapDataConverter.cs (revision 3167b898b071fea4cf86c775bca5467fab086038)
@@ -0,0 +1,50 @@
+// 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 Core.Components.DotSpatial.Data;
+using DotSpatial.Data;
+
+namespace Core.Components.DotSpatial.Converter
+{
+ ///
+ /// The interface for a converter which converts into .
+ ///
+ public interface IMapDataConverter
+ {
+ ///
+ /// Checks whether the can convert the .
+ ///
+ /// The to check for.
+ /// True if the can be converter by the
+ /// , false otheriwse.
+ bool CanConvertMapData(MapData data);
+
+ ///
+ /// Creates a based on the that was given.
+ ///
+ /// The data to transform into a .
+ /// A new .
+ /// Thrown when returns false.
+ /// Thrown when is null.
+ FeatureSet Convert(MapData data);
+ }
+}
Index: Core/Components/src/Core.Components.DotSpatial/Converter/MapDataConverter.cs
===================================================================
diff -u
--- Core/Components/src/Core.Components.DotSpatial/Converter/MapDataConverter.cs (revision 0)
+++ Core/Components/src/Core.Components.DotSpatial/Converter/MapDataConverter.cs (revision 3167b898b071fea4cf86c775bca5467fab086038)
@@ -0,0 +1,60 @@
+// 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 Core.Components.DotSpatial.Data;
+using DotSpatial.Data;
+
+namespace Core.Components.DotSpatial.Converter
+{
+ ///
+ /// The abstract base class for transforming in specific instances.
+ ///
+ public abstract class MapDataConverter : IMapDataConverter where T : MapData
+ {
+ public bool CanConvertMapData(MapData data)
+ {
+ return data.GetType() == typeof(T);
+ }
+
+ public FeatureSet Convert(MapData data)
+ {
+ if (data == null)
+ {
+ throw new ArgumentNullException("Null data cannot be converted into feature sets");
+ }
+
+ if (!CanConvertMapData(data))
+ {
+ var message = string.Format("The data of type {0} cannot be converted by this converter.", data.GetType());
+ throw new ArgumentException(message);
+ }
+ return Convert((T) data);
+ }
+
+ ///
+ /// Creates a based on the that was given.
+ ///
+ /// The data to transform into a .
+ /// A new .
+ protected abstract FeatureSet Convert(T data);
+ }
+}
Index: Core/Components/src/Core.Components.DotSpatial/Converter/MapDataFactory.cs
===================================================================
diff -u
--- Core/Components/src/Core.Components.DotSpatial/Converter/MapDataFactory.cs (revision 0)
+++ Core/Components/src/Core.Components.DotSpatial/Converter/MapDataFactory.cs (revision 3167b898b071fea4cf86c775bca5467fab086038)
@@ -0,0 +1,58 @@
+// 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.DotSpatial.Data;
+using DotSpatial.Data;
+
+namespace Core.Components.DotSpatial.Converter
+{
+ ///
+ /// A factory to create data from which can be used on the map.
+ ///
+ public class MapDataFactory
+ {
+ private readonly IEnumerable converters = new Collection
+ {
+ new MapPointDataConverter()
+ };
+ ///
+ /// Creates a new from the given .
+ ///
+ /// The to base the creation of upon.
+ /// A new .
+ /// Thrown when the given type is not supported.
+ public FeatureSet 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));
+ }
+ }
+}
Index: Core/Components/src/Core.Components.DotSpatial/Converter/MapPointDataConverter.cs
===================================================================
diff -u
--- Core/Components/src/Core.Components.DotSpatial/Converter/MapPointDataConverter.cs (revision 0)
+++ Core/Components/src/Core.Components.DotSpatial/Converter/MapPointDataConverter.cs (revision 3167b898b071fea4cf86c775bca5467fab086038)
@@ -0,0 +1,43 @@
+// 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 Core.Components.DotSpatial.Data;
+using DotSpatial.Data;
+using DotSpatial.Topology;
+
+namespace Core.Components.DotSpatial.Converter
+{
+ public class MapPointDataConverter : MapDataConverter
+ {
+ protected override FeatureSet Convert(MapPointData data)
+ {
+ var featureSet = new FeatureSet(FeatureType.Point);
+
+ foreach (var point in data.Points)
+ {
+ var coordinate = new Coordinate(point.Item1, point.Item2);
+ featureSet.Features.Add(coordinate);
+ }
+
+ return featureSet;
+ }
+ }
+}
\ No newline at end of file
Index: Core/Components/src/Core.Components.DotSpatial/Core.Components.DotSpatial.csproj
===================================================================
diff -u -r22f1bb3808dd48f3350d6a39171fe3b002da0a91 -r3167b898b071fea4cf86c775bca5467fab086038
--- Core/Components/src/Core.Components.DotSpatial/Core.Components.DotSpatial.csproj (.../Core.Components.DotSpatial.csproj) (revision 22f1bb3808dd48f3350d6a39171fe3b002da0a91)
+++ Core/Components/src/Core.Components.DotSpatial/Core.Components.DotSpatial.csproj (.../Core.Components.DotSpatial.csproj) (revision 3167b898b071fea4cf86c775bca5467fab086038)
@@ -95,7 +95,12 @@
Component
+
+
+
+
+
Index: Core/Components/src/Core.Components.DotSpatial/Data/MapPointData.cs
===================================================================
diff -u
--- Core/Components/src/Core.Components.DotSpatial/Data/MapPointData.cs (revision 0)
+++ Core/Components/src/Core.Components.DotSpatial/Data/MapPointData.cs (revision 3167b898b071fea4cf86c775bca5467fab086038)
@@ -0,0 +1,60 @@
+// 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 System.Linq;
+
+namespace Core.Components.DotSpatial.Data
+{
+ ///
+ /// A collection of points for the Map.
+ ///
+ public class MapPointData : MapData
+ {
+ ///
+ /// Create a new instance of .
+ ///
+ /// A of as (X,Y) coordinates.
+ /// Thrown when is null.
+ public MapPointData(IEnumerable> points)
+ {
+ if (points == null)
+ {
+ throw new ArgumentNullException("points", "A point collection is required when creating MapPointData.");
+ }
+
+ Points = points.ToArray();
+ IsVisible = true;
+ }
+
+ ///
+ /// Gets or sets a value indicating whether the is visible.
+ ///
+ public bool IsVisible { get; set; }
+
+ ///
+ /// Gets to collection of points in 2D space.
+ ///
+ public IEnumerable> Points { get; private set; }
+ }
+}
Index: Core/Components/test/Core.Components.DotSpatial.Test/BaseMapTest.cs
===================================================================
diff -u -r37dc25947c67f84a31ca868d2acceec4f48721cc -r3167b898b071fea4cf86c775bca5467fab086038
--- Core/Components/test/Core.Components.DotSpatial.Test/BaseMapTest.cs (.../BaseMapTest.cs) (revision 37dc25947c67f84a31ca868d2acceec4f48721cc)
+++ Core/Components/test/Core.Components.DotSpatial.Test/BaseMapTest.cs (.../BaseMapTest.cs) (revision 3167b898b071fea4cf86c775bca5467fab086038)
@@ -1,155 +1,85 @@
using System;
using System.IO;
+using System.Linq;
using System.Windows.Forms;
-using Core.Common.TestUtil;
using Core.Common.Utils.Reflection;
using Core.Components.DotSpatial.Data;
-using Core.Components.DotSpatial.Exceptions;
-using Core.Components.DotSpatial.Properties;
+using Core.Components.DotSpatial.TestUtil;
using DotSpatial.Controls;
using NUnit.Framework;
-using Rhino.Mocks;
-using Rhino.Mocks.Constraints;
namespace Core.Components.DotSpatial.Test
{
[TestFixture]
public class BaseMapTest
{
- private readonly string segmentsFile = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Core.Components.DotSpatial, "ShapeFiles"), "DR10_segments.shp");
- private readonly string dijkvakgebiedenFile = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Core.Components.DotSpatial, "ShapeFiles"), "DR10_dijkvakgebieden.shp");
- private readonly string binnenTeenFile = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Core.Components.DotSpatial, "ShapeFiles"), "DR10_binnenteen.shp");
- private readonly string tempTeenFile = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Core.Components.DotSpatial, "ShapeFiles"), "DR10_teen.shp");
-
[Test]
- public void DefaultConstructor_PropertiesSet()
+ public void DefaultConstructor_DefaultValues()
{
// Call
- var baseMap = new BaseMap();
-
- // Assert
- Assert.IsInstanceOf(baseMap);
- }
-
- [Test]
- public void Data_ShapeFileIsValidMissesNeededFiles_ThrowsFileNotFoundException()
- {
- // Setup
var map = new BaseMap();
- var data = new MapData();
- data.AddShapeFile(segmentsFile);
-
- // Call
- TestDelegate setDataDelegate = () => map.Data = data;
-
// Assert
- Assert.Throws(setDataDelegate);
+ Assert.IsInstanceOf(map);
+ Assert.IsInstanceOf(map);
+ Assert.IsNull(map.Data);
}
[Test]
- public void SetDataOnMap_FileDeleted_ThrowsFileNotFoundException()
+ public void Data_NotKnowMapData_ThrowsNotSupportedException()
{
// Setup
var map = new BaseMap();
- var data = new MapData();
+ var testData = new TestMapData();
- data.AddShapeFile(binnenTeenFile);
-
- RenameFile(tempTeenFile, binnenTeenFile);
-
// Call
- TestDelegate testDelegate = () => map.Data = data;
+ TestDelegate test = () => map.Data = testData;
- try
- {
- // Assert
- Assert.Throws(testDelegate);
- }
- finally
- {
- // Place the original file back for other tests.
- RenameFile(binnenTeenFile, tempTeenFile);
- }
- }
-
- [Test]
- public void SetData_ToNull_ThrowsArgrumentNullException()
- {
- // Setup
- var map = new BaseMap();
-
- // Call
- TestDelegate testDelegate = () => map.Data = null;
-
// Assert
- ArgumentNullException exception = Assert.Throws(testDelegate);
- Assert.AreEqual("MapData", exception.ParamName);
+ Assert.Throws(test);
}
[Test]
- public void Data_IsValid_DoesNotThrowException()
+ public void Data_Null_ReturnsNull()
{
// Setup
var map = new BaseMap();
- var data = new MapData();
- data.AddShapeFile(dijkvakgebiedenFile);
-
// Call
- TestDelegate setDataDelegate = () => map.Data = data;
+ map.Data = null;
// Assert
- Assert.DoesNotThrow(setDataDelegate);
+ Assert.IsNull(map.Data);
}
[Test]
- public void GetData_Always_ReturnsData()
+ public void Data_NotNull_ReturnsData()
{
// Setup
var map = new BaseMap();
- var data = new MapData();
- data.AddShapeFile(dijkvakgebiedenFile);
- map.Data = data;
+ var testData = new MapPointData(Enumerable.Empty>());
+ map.Data = testData;
// Call
- var getData = map.Data;
+ var data = map.Data;
// Assert
- Assert.AreSame(getData, data);
+ Assert.AreSame(testData, data);
}
[Test]
- public void SetDataOnMap_Succeeds_AddOneMapLayerAndWriteLog()
+ public void Data_KnownMapData_MapFeatureAdded()
{
// Setup
var map = new BaseMap();
- var data = new MapData();
+ var testData = new MapPointData(Enumerable.Empty>());
+ var mapView = TypeUtils.GetField