Index: Core/Components/src/Core.Components.DotSpatial.Forms/BaseMap.cs =================================================================== diff -u -r5fd8bf3258c1096c0b7fd950240068ba85db559e -r2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c --- Core/Components/src/Core.Components.DotSpatial.Forms/BaseMap.cs (.../BaseMap.cs) (revision 5fd8bf3258c1096c0b7fd950240068ba85db559e) +++ Core/Components/src/Core.Components.DotSpatial.Forms/BaseMap.cs (.../BaseMap.cs) (revision 2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c) @@ -20,21 +20,21 @@ // All rights reserved. using System.Windows.Forms; - +using Core.Common.Base; using Core.Components.DotSpatial.Converter; using Core.Components.Gis.Data; using DotSpatial.Controls; using DotSpatial.Data; - +using DotSpatial.Symbology; using IMap = Core.Components.Gis.IMap; namespace Core.Components.DotSpatial.Forms { /// /// This class describes a map view with configured projection and function mode. /// - public sealed class BaseMap : Control, IMap + public sealed class BaseMap : Control, IMap, IObserver { private readonly MapDataFactory mapDataFactory = new MapDataFactory(); private MapData data; @@ -48,6 +48,28 @@ InitializeMapView(); } + /// + /// Attaches the to the currently set , if there is any. + /// + private void AttachToData() + { + if (data != null) + { + data.Attach(this); + } + } + + /// + /// Detaches the to the currently set , if there is any. + /// + private void DetachFromData() + { + if (data != null) + { + data.Detach(this); + } + } + public MapData Data { get @@ -61,7 +83,9 @@ return; } + DetachFromData(); data = value; + AttachToData(); DrawFeatureSets(); } } @@ -75,6 +99,8 @@ { map.Layers.Add(featureSet); } + + map.ZoomToMaxExtent(); } } @@ -84,10 +110,15 @@ { ProjectionModeDefine = ActionMode.Never, Dock = DockStyle.Fill, - FunctionMode = FunctionMode.Pan + FunctionMode = FunctionMode.Pan, }; Controls.Add(map); } + + public void UpdateObserver() + { + DrawFeatureSets(); + } } } \ No newline at end of file Index: Core/Components/src/Core.Components.DotSpatial.Forms/Core.Components.DotSpatial.Forms.csproj =================================================================== diff -u -ra3c8c0cb4384de51a18d77cc7bea487f97ba21e1 -r2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c --- Core/Components/src/Core.Components.DotSpatial.Forms/Core.Components.DotSpatial.Forms.csproj (.../Core.Components.DotSpatial.Forms.csproj) (revision a3c8c0cb4384de51a18d77cc7bea487f97ba21e1) +++ Core/Components/src/Core.Components.DotSpatial.Forms/Core.Components.DotSpatial.Forms.csproj (.../Core.Components.DotSpatial.Forms.csproj) (revision 2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c) @@ -96,6 +96,11 @@ + + {3bbfd65b-b277-4e50-ae6d-bd24c3434609} + Core.Common.Base + False + {c90b77da-e421-43cc-b82e-529651bc21ac} Core.Common.Version Index: Core/Components/src/Core.Components.Gis/Data/MapData.cs =================================================================== diff -u -r61f3b606ba0003553fe583462bab6e493043be5e -r2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c --- Core/Components/src/Core.Components.Gis/Data/MapData.cs (.../MapData.cs) (revision 61f3b606ba0003553fe583462bab6e493043be5e) +++ Core/Components/src/Core.Components.Gis/Data/MapData.cs (.../MapData.cs) (revision 2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c) @@ -19,10 +19,12 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using Core.Common.Base; + namespace Core.Components.Gis.Data { /// /// Abstract class for data with the purpose of becoming visible in map components. /// - public abstract class MapData {} + public abstract class MapData : Observable {} } \ No newline at end of file Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/BaseMapTest.cs =================================================================== diff -u -r33c64ea2cd6b287bf5954e63a548d89dadb7f153 -r2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/BaseMapTest.cs (.../BaseMapTest.cs) (revision 33c64ea2cd6b287bf5954e63a548d89dadb7f153) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/BaseMapTest.cs (.../BaseMapTest.cs) (revision 2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c) @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Windows.Forms; +using Core.Common.Base; using Core.Common.Base.Geometry; using Core.Common.Utils.Reflection; using Core.Components.DotSpatial.TestUtil; @@ -71,7 +73,7 @@ } [Test] - public void Data_KnownMapData_MapFeatureAdded() + public void Data_KnownMapData_MapFeatureAddedAndZoomedToExtents() { // Setup var map = new BaseMap(); @@ -83,14 +85,16 @@ // Assert Assert.AreEqual(1, mapView.Layers.Count); + Assert.AreEqual(mapView.GetMaxExtent(), mapView.ViewExtents); } [Test] - public void Data_SetToNull_MapFeaturesCleared() + public void Data_SetToNull_BaseMapDetachedFeaturesCleared() { // Setup var map = new BaseMap(); var testData = new MapPointData(Enumerable.Empty()); + var observers = TypeUtils.GetField>(testData, "observers"); var mapView = TypeUtils.GetField(map, "map"); map.Data = testData; @@ -103,7 +107,55 @@ // Assert Assert.IsNull(map.Data); - Assert.AreEqual(0, mapView.Layers.Count); + CollectionAssert.IsEmpty(observers); + CollectionAssert.IsEmpty(mapView.Layers); } + + [Test] + public void Data_NewDataSet_BaseMapDetachedFromOldAttachedToNewFeaturesUpdated() + { + // Setup + var map = new BaseMap(); + var testDataOld = new MapPointData(Enumerable.Empty()); + var testDataNew = new MapPointData(Enumerable.Empty()); + + var observersOld = TypeUtils.GetField>(testDataOld, "observers"); + var observersNew = TypeUtils.GetField>(testDataNew, "observers"); + var view = TypeUtils.GetField(map, "map"); + + // Call + map.Data = testDataOld; + map.Data = testDataNew; + + // Assert + CollectionAssert.IsEmpty(observersOld); + CollectionAssert.AreEqual(new[] { map }, observersNew); + Assert.AreEqual(1, view.Layers.Count); + } + + [Test] + [RequiresSTA] + public void UpdateObserver_MapInForm_MapLayersRenewed() + { + // Setup + var form = new Form(); + var map = new BaseMap(); + var testData = new MapPointData(Enumerable.Empty()); + var view = TypeUtils.GetField(map, "map"); + + map.Data = testData; + var layers = view.Layers.ToList(); + + form.Controls.Add(map); + + form.Show(); + + // Call + map.UpdateObserver(); + + // Assert + Assert.AreEqual(1, view.Layers.Count); + Assert.AreNotSame(layers[0], view.Layers[0]); + } } } \ No newline at end of file Index: Core/Components/test/Core.Components.DotSpatial.TestUtil/Core.Components.DotSpatial.TestUtil.csproj =================================================================== diff -u -r61f3b606ba0003553fe583462bab6e493043be5e -r2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c --- Core/Components/test/Core.Components.DotSpatial.TestUtil/Core.Components.DotSpatial.TestUtil.csproj (.../Core.Components.DotSpatial.TestUtil.csproj) (revision 61f3b606ba0003553fe583462bab6e493043be5e) +++ Core/Components/test/Core.Components.DotSpatial.TestUtil/Core.Components.DotSpatial.TestUtil.csproj (.../Core.Components.DotSpatial.TestUtil.csproj) (revision 2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c) @@ -47,6 +47,10 @@ + + {3bbfd65b-b277-4e50-ae6d-bd24c3434609} + Core.Common.Base + {aa47e858-a2a7-470e-8b2d-c76ae8ed9ccd} Core.Components.DotSpatial Index: Core/Components/test/Core.Components.Gis.Test/Core.Components.Gis.Test.csproj =================================================================== diff -u -r33c64ea2cd6b287bf5954e63a548d89dadb7f153 -r2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c --- Core/Components/test/Core.Components.Gis.Test/Core.Components.Gis.Test.csproj (.../Core.Components.Gis.Test.csproj) (revision 33c64ea2cd6b287bf5954e63a548d89dadb7f153) +++ Core/Components/test/Core.Components.Gis.Test/Core.Components.Gis.Test.csproj (.../Core.Components.Gis.Test.csproj) (revision 2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c) @@ -42,6 +42,7 @@ + Index: Core/Components/test/Core.Components.Gis.Test/Data/MapDataTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.Gis.Test/Data/MapDataTest.cs (revision 0) +++ Core/Components/test/Core.Components.Gis.Test/Data/MapDataTest.cs (revision 2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c) @@ -0,0 +1,22 @@ +using Core.Common.Base; +using Core.Components.Gis.Data; +using NUnit.Framework; + +namespace Core.Components.Gis.Test.Data +{ + [TestFixture] + public class MapDataTest + { + [Test] + public void DefaultConstructor_Values() + { + // Call + var mapData = new MapDataChild(); + + // Assert + Assert.IsInstanceOf(mapData); + } + + private class MapDataChild : MapData { } + } +} Index: Core/Plugins/src/Core.Plugins.DotSpatial/Core.Plugins.DotSpatial.csproj =================================================================== diff -u -ra3c8c0cb4384de51a18d77cc7bea487f97ba21e1 -r2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c --- Core/Plugins/src/Core.Plugins.DotSpatial/Core.Plugins.DotSpatial.csproj (.../Core.Plugins.DotSpatial.csproj) (revision a3c8c0cb4384de51a18d77cc7bea487f97ba21e1) +++ Core/Plugins/src/Core.Plugins.DotSpatial/Core.Plugins.DotSpatial.csproj (.../Core.Plugins.DotSpatial.csproj) (revision 2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c) @@ -77,6 +77,10 @@ + + {3bbfd65b-b277-4e50-ae6d-bd24c3434609} + Core.Common.Base + {1D27F91F-4E62-4EAF-A0A8-A32708B9A9B1} Core.Common.Controls.TreeView Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryDatabase.cs =================================================================== diff -u -r33c64ea2cd6b287bf5954e63a548d89dadb7f153 -r2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryDatabase.cs (.../HydraulicBoundaryDatabase.cs) (revision 33c64ea2cd6b287bf5954e63a548d89dadb7f153) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryDatabase.cs (.../HydraulicBoundaryDatabase.cs) (revision 2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c) @@ -52,5 +52,10 @@ /// Gets the hydraulic boundary locations. /// public ICollection Locations { get; private set; } + + public void ClearLocations() + { + Locations.Clear(); + } } } \ No newline at end of file Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.Test/HydraulicBoundaryDatabaseTest.cs =================================================================== diff -u -r33c64ea2cd6b287bf5954e63a548d89dadb7f153 -r2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.Test/HydraulicBoundaryDatabaseTest.cs (.../HydraulicBoundaryDatabaseTest.cs) (revision 33c64ea2cd6b287bf5954e63a548d89dadb7f153) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.Test/HydraulicBoundaryDatabaseTest.cs (.../HydraulicBoundaryDatabaseTest.cs) (revision 2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c) @@ -35,8 +35,26 @@ // Assert Assert.IsNullOrEmpty(null, hydraulicBoundaryDatabase.FilePath); Assert.IsNullOrEmpty(null, hydraulicBoundaryDatabase.Version); - Assert.IsInstanceOf>(hydraulicBoundaryDatabase.Locations); + Assert.IsInstanceOf>(hydraulicBoundaryDatabase.Locations); CollectionAssert.IsEmpty(hydraulicBoundaryDatabase.Locations); } + + [Test] + public void ClearLocations_Always_EmtpyLocationCollection() + { + // Setup + HydraulicBoundaryDatabase hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + var location = hydraulicBoundaryDatabase.Locations; + location.Add(new HydraulicBoundaryLocation(1, "test", 1.0, 2.0)); + + // Precondition + CollectionAssert.IsNotEmpty(location); + + // Call + hydraulicBoundaryDatabase.ClearLocations(); + + // Assert + CollectionAssert.IsEmpty(location); + } } } \ No newline at end of file Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Plugin.Test/HydraulicBoundaryLocationsImporterTest.cs =================================================================== diff -u -rdcd6469f6000957bc1604da8e92bd5ea09e43769 -r2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Plugin.Test/HydraulicBoundaryLocationsImporterTest.cs (.../HydraulicBoundaryLocationsImporterTest.cs) (revision dcd6469f6000957bc1604da8e92bd5ea09e43769) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Plugin.Test/HydraulicBoundaryLocationsImporterTest.cs (.../HydraulicBoundaryLocationsImporterTest.cs) (revision 2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c) @@ -72,7 +72,7 @@ [Test] [TestCase("/")] - [TestCase("nonexisting.sqlit")] + [TestCase("nonexisting.sqlite")] public void ValidateFile_NonExistingFileOrInvalidFile_LogError(string filename) { // Setup Index: Ringtoets/Integration/src/Ringtoets.Integration.Data/Map/AssessmentSectionMapData.cs =================================================================== diff -u -r33c64ea2cd6b287bf5954e63a548d89dadb7f153 -r2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c --- Ringtoets/Integration/src/Ringtoets.Integration.Data/Map/AssessmentSectionMapData.cs (.../AssessmentSectionMapData.cs) (revision 33c64ea2cd6b287bf5954e63a548d89dadb7f153) +++ Ringtoets/Integration/src/Ringtoets.Integration.Data/Map/AssessmentSectionMapData.cs (.../AssessmentSectionMapData.cs) (revision 2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c) @@ -46,19 +46,43 @@ throw new ArgumentNullException("assessmentSection"); } this.assessmentSection = assessmentSection; - - var locationData = assessmentSection.HydraulicBoundaryDatabase.Locations.Select(hydraulicBoundaryLocation => hydraulicBoundaryLocation.Location).ToList(); + + CheckHydraulicBoundaryDatabaseLocationData(); + } + + public void UpdateHydraulicBoundaryDatabaseMap() + { + List.Clear(); + + CheckHydraulicBoundaryDatabaseLocationData(); + } + + private void CheckHydraulicBoundaryDatabaseLocationData() + { + var locationData = GetHydraulicBoundaryDatabaseLocationData(); if (locationData.Count > 0) { CreateMapPointData(locationData); } } + private List GetHydraulicBoundaryDatabaseLocationData() + { + return assessmentSection.HydraulicBoundaryDatabase.Locations.Select(hydraulicBoundaryLocation => hydraulicBoundaryLocation.Location).ToList(); + } + private void CreateMapPointData(IEnumerable locationData) { List.Add(new MapPointData(locationData)); } + #region IEquatable implementation + + public bool Equals(AssessmentSectionMapData other) + { + return other != null && Equals(other.assessmentSection, assessmentSection); + } + public override bool Equals(object other) { return Equals(other as AssessmentSectionMapData); @@ -69,9 +93,6 @@ return assessmentSection.GetHashCode(); } - public bool Equals(AssessmentSectionMapData other) - { - return other != null && Equals(other.assessmentSection, assessmentSection); - } + #endregion } } \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs =================================================================== diff -u -r439d9a38704806fd3c659d37fe4b00e8f0888b5e -r2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs (.../RingtoetsGuiPlugin.cs) (revision 439d9a38704806fd3c659d37fe4b00e8f0888b5e) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs (.../RingtoetsGuiPlugin.cs) (revision 2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c) @@ -60,6 +60,7 @@ public class RingtoetsGuiPlugin : GuiPlugin { private static readonly ILog log = LogManager.GetLogger(typeof(GuiPlugin)); + private static AssessmentSectionMapData assessmentSectionMapData; public override IRibbonCommandHandler RibbonCommandHandler { @@ -97,7 +98,11 @@ yield return new ViewInfo { GetViewName = (v, o) => RingtoetsFormsResources.TrajectMap_DisplayName, - GetViewData = assessmentSectionBase => new AssessmentSectionMapData(assessmentSectionBase), + GetViewData = assessmentSectionBase => + { + assessmentSectionMapData = new AssessmentSectionMapData(assessmentSectionBase); + return assessmentSectionMapData; + }, Image = RingtoetsFormsResources.Map }; } @@ -460,7 +465,6 @@ string filePath, string version) { - var confirmation = MessageBox.Show( HydraringResources.Delete_Calculations_Text, BaseResources.Confirm, @@ -492,9 +496,11 @@ string selectedFile, string newVersion) { + nodeData.BoundaryDatabase.ClearLocations(); if (hydraulicBoundaryLocationsImporter.Import(nodeData.BoundaryDatabase.Locations, selectedFile)) { SetBoundaryDatabaseData(nodeData, selectedFile, newVersion); + UpdateMap(); } } @@ -506,6 +512,15 @@ log.InfoFormat(HydraringResources.RingtoetsGuiPlugin_SetBoundaryDatabaseFilePath_Database_on_path__0__linked, selectedFile); } + private static void UpdateMap() + { + if (assessmentSectionMapData != null) + { + assessmentSectionMapData.UpdateHydraulicBoundaryDatabaseMap(); + assessmentSectionMapData.NotifyObservers(); + } + } + #endregion } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/Map/AssessmentSectionMapDataTest.cs =================================================================== diff -u -r33c64ea2cd6b287bf5954e63a548d89dadb7f153 -r2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c --- Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/Map/AssessmentSectionMapDataTest.cs (.../AssessmentSectionMapDataTest.cs) (revision 33c64ea2cd6b287bf5954e63a548d89dadb7f153) +++ Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/Map/AssessmentSectionMapDataTest.cs (.../AssessmentSectionMapDataTest.cs) (revision 2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c) @@ -21,7 +21,9 @@ using System; using System.Collections.Generic; +using Core.Components.DotSpatial.Forms; using Core.Components.Gis.Data; +using Core.Plugins.DotSpatial.Forms; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data; @@ -90,6 +92,32 @@ } [Test] + public void UpdateHydraulicBoundaryDatabaseMap_NewDataSet_RemovesOldListItemAndAddsNew() + { + // Setup + var assessmentSection = new TestAssessmentSectionBase(); + + assessmentSection.HydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(1, "test", 1.0, 1.1)); + assessmentSection.HydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(2, "test2", 2.0, 1.4)); + + var mapData = new AssessmentSectionMapData(assessmentSection); + + // Precondition + Assert.AreEqual(1, mapData.List.Count); + + assessmentSection.HydraulicBoundaryDatabase.Locations.Clear(); + assessmentSection.HydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(3, "test3", 3.0, 3.1)); + assessmentSection.HydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(4, "test4", 5.0, 4.4)); + + // Call + mapData.UpdateHydraulicBoundaryDatabaseMap(); + + // Assert + Assert.AreEqual(1, mapData.List.Count); + } + + + [Test] public void Equals_EqualsWithItself_ReturnTrue() { // Setup Index: Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/Ringtoets.Integration.Data.Test.csproj =================================================================== diff -u -racbd08302b69fc06e5cade26def0dea4d35e3b92 -r2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c --- Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/Ringtoets.Integration.Data.Test.csproj (.../Ringtoets.Integration.Data.Test.csproj) (revision acbd08302b69fc06e5cade26def0dea4d35e3b92) +++ Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/Ringtoets.Integration.Data.Test.csproj (.../Ringtoets.Integration.Data.Test.csproj) (revision 2310b1df9f3fcfa1e01ee6eec2206a4dd0f38f5c) @@ -49,6 +49,7 @@ + @@ -66,14 +67,26 @@ {3bbfd65b-b277-4e50-ae6d-bd24c3434609} Core.Common.Base + + {9a2d67e6-26ac-4d17-b11a-2b4372f2f572} + Core.Common.Controls + {D749EE4C-CE50-4C17-BF01-9A953028C126} Core.Common.TestUtil + + {5A91174A-FB95-4C9D-9CA5-81C0B8D4361A} + Core.Components.DotSpatial.Forms + {318ba582-88c9-4816-a54a-a7e431461de3} Core.Components.Gis + + {610E0A9C-1997-4C43-A10E-39D4C66ADA93} + Core.Plugins.DotSpatial + {d4200f43-3f72-4f42-af0a-8ced416a38ec} Ringtoets.Common.Data