Index: Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs =================================================================== diff -u -r4dbfc20ef0200e34db43efeb8899d72e4046cc5b -r7660d43cae4eda23b77c027f50dde28c23715c1b --- Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs (.../MapControl.cs) (revision 4dbfc20ef0200e34db43efeb8899d72e4046cc5b) +++ Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs (.../MapControl.cs) (revision 7660d43cae4eda23b77c027f50dde28c23715c1b) @@ -92,10 +92,15 @@ public void ZoomToAllVisibleLayers() { - IEnvelope envelope = CreateEnvelopeForAllVisibleLayers(); + ZoomToAllVisibleLayers(Data); + } + + public void ZoomToAllVisibleLayers(MapData layerData) + { + IEnvelope envelope = CreateEnvelopeForAllVisibleLayers(layerData); if (!envelope.IsNull) { - var extent = envelope.ToExtent(); + Extent extent = envelope.ToExtent(); AddPadding(extent); map.ViewExtents = extent; } @@ -151,16 +156,58 @@ } } - private IEnvelope CreateEnvelopeForAllVisibleLayers() + /// + /// Defines the area taken up by the visible map-data based on the provided map-data. + /// + /// The data to determine the visible extent for. + /// The area definition. + /// Thrown when is + /// not part of the drawn map features. + private IEnvelope CreateEnvelopeForAllVisibleLayers(MapData mapData) { + var collection = mapData as MapDataCollection; + if (collection != null) + { + return CreateEnvelopeForAllVisibleLayers(collection); + } + + DrawnMapData drawnMapData = drawnMapDataList.FirstOrDefault(dmd => dmd.FeatureBasedMapData.Equals(mapData)); + if (drawnMapData == null) + { + throw new ArgumentException($"Can only zoom to {typeof(MapData).Name} that is part of this {typeof(MapControl).Name}s drawn mapdata.", + nameof(mapData)); + } + IEnvelope envelope = new Envelope(); - foreach (IMapLayer layer in map.Layers.Where(layer => layer.IsVisible && !layer.Extent.IsEmpty())) + if (LayerHasVisibleExtent(drawnMapData.FeatureBasedMapDataLayer)) { - envelope.ExpandToInclude(layer.Extent.ToEnvelope()); + envelope.ExpandToInclude(drawnMapData.FeatureBasedMapDataLayer.Extent.ToEnvelope()); } return envelope; } + /// + /// Defines the area taken up by the visible map-data based on the provided map-data. + /// + /// The data to determine the visible extent for. + /// The area definition. + /// Thrown when or + /// any of it's children is not part of the drawn map features. + private IEnvelope CreateEnvelopeForAllVisibleLayers(MapDataCollection mapData) + { + IEnvelope envelope = new Envelope(); + foreach (MapData childMapData in mapData.Collection) + { + envelope.ExpandToInclude(CreateEnvelopeForAllVisibleLayers(childMapData)); + } + return envelope; + } + + private static bool LayerHasVisibleExtent(IMapLayer layer) + { + return layer.IsVisible && !layer.Extent.IsEmpty(); + } + private void ResetDefaultInteraction() { IsPanningEnabled = false; @@ -199,7 +246,7 @@ private void DrawInitialMapData() { - foreach (var featureBasedMapData in GetFeatureBasedMapDataRecursively(Data)) + foreach (FeatureBasedMapData featureBasedMapData in GetFeatureBasedMapDataRecursively(Data)) { DrawMapData(featureBasedMapData); } Index: Core/Components/src/Core.Components.Gis.Forms/IMapControl.cs =================================================================== diff -u -r675771641656abfb56ef89be86bad7bd21684016 -r7660d43cae4eda23b77c027f50dde28c23715c1b --- Core/Components/src/Core.Components.Gis.Forms/IMapControl.cs (.../IMapControl.cs) (revision 675771641656abfb56ef89be86bad7bd21684016) +++ Core/Components/src/Core.Components.Gis.Forms/IMapControl.cs (.../IMapControl.cs) (revision 7660d43cae4eda23b77c027f50dde28c23715c1b) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using Core.Components.Gis.Data; namespace Core.Components.Gis.Forms @@ -54,6 +55,14 @@ void ZoomToAllVisibleLayers(); /// + /// Zooms to a level such that the given map data is in view. + /// + /// The data to zoom to. + /// Thrown when + /// is not part of . + void ZoomToAllVisibleLayers(MapData layerData); + + /// /// Toggles panning of the . Panning is invoked by clicking the left mouse-button. /// void TogglePanning(); Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/Core.Components.DotSpatial.Forms.Test.csproj =================================================================== diff -u -r23d1e296e2da4364fbfe346e68d582dfcf966bb0 -r7660d43cae4eda23b77c027f50dde28c23715c1b --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/Core.Components.DotSpatial.Forms.Test.csproj (.../Core.Components.DotSpatial.Forms.Test.csproj) (revision 23d1e296e2da4364fbfe346e68d582dfcf966bb0) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/Core.Components.DotSpatial.Forms.Test.csproj (.../Core.Components.DotSpatial.Forms.Test.csproj) (revision 7660d43cae4eda23b77c027f50dde28c23715c1b) @@ -80,6 +80,10 @@ {3BBFD65B-B277-4E50-AE6D-BD24C3434609} Core.Common.Base + + {d749ee4c-ce50-4c17-bf01-9a953028c126} + Core.Common.TestUtil + {5a91174a-fb95-4c9d-9ca5-81c0b8d4361a} Core.Components.DotSpatial.Forms Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs =================================================================== diff -u -r2cafb330e0b90d1103bc9329eafbcba24836787f -r7660d43cae4eda23b77c027f50dde28c23715c1b --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs (.../MapControlTest.cs) (revision 2cafb330e0b90d1103bc9329eafbcba24836787f) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs (.../MapControlTest.cs) (revision 7660d43cae4eda23b77c027f50dde28c23715c1b) @@ -19,9 +19,12 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; +using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using Core.Common.Base.Geometry; +using Core.Common.TestUtil; using Core.Components.DotSpatial.MapFunctions; using Core.Components.Gis.Data; using Core.Components.Gis.Features; @@ -374,10 +377,10 @@ // Assert Assert.AreEqual(2, invalidated); + Extent expectedExtent = mapView.GetMaxExtent(); + ExtendWithExpectedMargin(expectedExtent); - var smallest = expectedExtent.Height < expectedExtent.Width ? expectedExtent.Height : expectedExtent.Width; - expectedExtent.ExpandBy(smallest*padding); Assert.AreEqual(expectedExtent, mapView.ViewExtents); } } @@ -393,8 +396,7 @@ map.Data = GetTestData(); var expectedExtent = new Extent(0.0, 0.5, 1.6, 2.1); - var smallest = expectedExtent.Height < expectedExtent.Width ? expectedExtent.Height : expectedExtent.Width; - expectedExtent.ExpandBy(smallest*padding); + ExtendWithExpectedMargin(expectedExtent); // Precondition Assert.AreEqual(3, mapView.Layers.Count, "Precondition failed: mapView.Layers != 3"); @@ -444,8 +446,7 @@ map.Data = mapDataCollection; var expectedExtent = new Extent(0.0, 0.0, xMax, yMax); - var smallest = expectedExtent.Height < expectedExtent.Width ? expectedExtent.Height : expectedExtent.Width; - expectedExtent.ExpandBy(smallest*padding); + ExtendWithExpectedMargin(expectedExtent); // Call map.ZoomToAllVisibleLayers(); @@ -465,7 +466,226 @@ } [Test] + public void ZoomToAllVisibleLayers_WithNonChildMapData_ThrowArgumentException() + { + // Setup + var mapDataCollection = new MapDataCollection("Collection"); + using (var map = new MapControl + { + Data = mapDataCollection + }) + { + var mapData = new MapPointData("Test data"); + + // Call + TestDelegate call = () => map.ZoomToAllVisibleLayers(mapData); + + // Assert + string message = "Can only zoom to MapData that is part of this MapControls drawn mapdata."; + string paramName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, message).ParamName; + Assert.AreEqual("mapData", paramName); + } + } + + [Test] [RequiresSTA] + public void ZoomToAllVisibleLayers_MapInFormWithEmptyDataSetAndForChildMapData_ViewInvalidatedLayersSame() + { + // Setup + using (var map = new MapControl()) + { + var mapDataCollection = new MapDataCollection("Collection"); + var mapData = new MapPointData("Test data"); + var invalidated = 0; + var mapView = map.Controls.OfType().First(); + + mapDataCollection.Add(mapData); + + map.Data = mapDataCollection; + + mapView.Invalidated += (sender, args) => { invalidated++; }; + + Assert.AreEqual(0, invalidated, "Precondition failed: mapView.Invalidated > 0"); + + // Call + map.ZoomToAllVisibleLayers(mapData); + + // Assert + Assert.AreEqual(0, invalidated); + Extent expectedExtent = new Extent(0.0, 0.0, 0.0, 0.0); + Assert.AreEqual(expectedExtent, mapView.ViewExtents); + } + } + + [Test] + [RequiresSTA] + public void ZoomToAllVisibleLayers_MapInFormForChildMapData_ViewInvalidatedLayersSame() + { + // Setup + using (var form = new Form()) + { + var map = new MapControl(); + var mapFeatures = new[] + { + new MapFeature(new[] + { + new MapGeometry(new[] + { + new[] + { + new Point2D(0.0, 0.0), + new Point2D(1.0, 1.0) + } + }) + }) + }; + var mapDataCollection = new MapDataCollection("Collection"); + var mapData = new MapPointData("Test data") + { + Features = mapFeatures + }; + var mapView = map.Controls.OfType().First(); + var invalidated = 0; + + mapDataCollection.Add(mapData); + + map.Data = mapDataCollection; + + form.Controls.Add(map); + + mapView.Invalidated += (sender, args) => { invalidated++; }; + + form.Show(); + Assert.AreEqual(0, invalidated, "Precondition failed: mapView.Invalidated > 0"); + + // Call + map.ZoomToAllVisibleLayers(mapData); + + // Assert + Assert.AreEqual(2, invalidated); + + Extent expectedExtent = mapView.GetMaxExtent(); + ExtendWithExpectedMargin(expectedExtent); + + Assert.AreEqual(expectedExtent, mapView.ViewExtents); + } + } + + [Test] + public void ZoomToAllVisibleLayers_ForVisibleChildMapData_ZoomToVisibleLayerExtent() + { + // Setup + using (var map = new MapControl()) + { + var mapView = map.Controls.OfType().First(); + + MapDataCollection dataCollection = GetTestData(); + map.Data = dataCollection; + + MapData mapData = dataCollection.Collection.ElementAt(0); + var expectedExtent = GetExpectedExtent((FeatureBasedMapData)mapData); + ExtendWithExpectedMargin(expectedExtent); + + // Precondition + Assert.IsTrue(mapData.IsVisible); + + // Call + map.ZoomToAllVisibleLayers(mapData); + + // Assert + Assert.AreNotEqual(mapView.GetMaxExtent(), mapView.ViewExtents); + Assert.AreEqual(expectedExtent, mapView.ViewExtents); + } + } + + [Test] + public void ZoomToAllVisibleLayers_ForInvisibleChildMapData_DoNotChangeViewExtentsOfMapView() + { + // Setup + using (var map = new MapControl()) + { + var mapView = map.Controls.OfType().First(); + + MapDataCollection dataCollection = GetTestData(); + map.Data = dataCollection; + + MapData mapData = dataCollection.Collection.ElementAt(2); + Extent expectedExtent = GetExpectedExtent((FeatureBasedMapData)mapData); + ExtendWithExpectedMargin(expectedExtent); + + // Precondition + Assert.IsFalse(mapData.IsVisible); + + var originalViewExtents = (Extent)mapView.ViewExtents.Clone(); + + // Call + map.ZoomToAllVisibleLayers(mapData); + + // Assert + Assert.AreNotEqual(expectedExtent, mapView.ViewExtents, + "Do not set extent based on the invisible layer."); + Assert.AreEqual(originalViewExtents, mapView.ViewExtents); + } + } + + [Test] + [TestCase(5.0, 5.0)] + [TestCase(5.0, 1.0)] + [TestCase(1.0, 5.0)] + [TestCase(double.MaxValue * 0.96, double.MaxValue * 0.96)] + [TestCase(double.MaxValue, double.MaxValue)] + public void ZoomToAllVisibleLayers_ForMapDataOfVariousDimensions_ZoomToVisibleLayerExtent(double xMax, double yMax) + { + // Setup + using (var map = new MapControl()) + { + var mapView = map.Controls.OfType().First(); + + + MapData mapData = new MapPointData("Test data") + { + Features = new[] + { + new MapFeature(new[] + { + new MapGeometry(new[] + { + new[] + { + new Point2D(0.0, 0.0), + new Point2D(xMax, yMax) + } + }) + }) + } + }; + var mapDataCollection = new MapDataCollection("Test data collection"); + mapDataCollection.Add(mapData); + + map.Data = mapDataCollection; + + var expectedExtent = new Extent(0.0, 0.0, xMax, yMax); + ExtendWithExpectedMargin(expectedExtent); + + // Call + map.ZoomToAllVisibleLayers(mapData); + + // Assert + if (double.IsInfinity(expectedExtent.Height) || double.IsInfinity(expectedExtent.Width)) + { + Assert.AreEqual(mapView.GetMaxExtent(), mapView.ViewExtents); + Assert.AreNotEqual(expectedExtent, mapView.ViewExtents); + } + else + { + Assert.AreNotEqual(mapView.GetMaxExtent(), mapView.ViewExtents); + Assert.AreEqual(expectedExtent, mapView.ViewExtents); + } + } + } + + [Test] + [RequiresSTA] public void SelectionZoom_MouseUp_DefaultCursorSet() { using (var form = new Form()) @@ -918,5 +1138,39 @@ return mapDataCollection; } + + private static void ExtendWithExpectedMargin(Extent expectedExtent) + { + double smallestDimension = Math.Min(expectedExtent.Height, expectedExtent.Width); + expectedExtent.ExpandBy(smallestDimension * padding); + } + + private Extent GetExpectedExtent(FeatureBasedMapData visibleMapData) + { + double minX = double.MaxValue; + double maxX = double.MinValue; + double minY = double.MaxValue; + double maxY = double.MinValue; + + foreach (MapFeature feature in visibleMapData.Features) + { + foreach (MapGeometry geometry in feature.MapGeometries) + { + foreach (IEnumerable pointCollection in geometry.PointCollections) + { + foreach (Point2D point in pointCollection) + { + minX = Math.Min(minX, point.X); + maxX = Math.Max(maxX, point.X); + + minY = Math.Min(minY, point.Y); + maxY = Math.Max(maxY, point.Y); + } + } + } + } + + return new Extent(minX, minY, maxX, maxY); + } } } \ No newline at end of file Index: Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendController.cs =================================================================== diff -u -rb78eea44f0c54cf91f8357c96b5c9af8655308d7 -r7660d43cae4eda23b77c027f50dde28c23715c1b --- Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendController.cs (.../MapLegendController.cs) (revision b78eea44f0c54cf91f8357c96b5c9af8655308d7) +++ Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendController.cs (.../MapLegendController.cs) (revision 7660d43cae4eda23b77c027f50dde28c23715c1b) @@ -21,11 +21,10 @@ using System; using System.Linq; -using Core.Common.Controls.Views; using Core.Common.Gui; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms.ViewHost; -using Core.Components.Gis.Data; +using Core.Components.Gis.Forms; using Core.Plugins.Map.Properties; namespace Core.Plugins.Map.Legend @@ -43,7 +42,7 @@ /// public EventHandler OnOpenLegend; - private IView legendView; + private MapLegendView legendView; /// /// Creates a new instance of . @@ -56,11 +55,13 @@ { if (viewController == null) { - throw new ArgumentNullException("viewController", @"Cannot create a MapLegendController when the view controller is null."); + throw new ArgumentNullException(nameof(viewController), + $"Cannot create a {typeof(MapLegendController).Name} when the view controller is null."); } if (contextMenuBuilderProvider == null) { - throw new ArgumentNullException("contextMenuBuilderProvider", @"Cannot create a MapLegendController when the context menu builder provider is null."); + throw new ArgumentNullException(nameof(contextMenuBuilderProvider), + $"Cannot create a {typeof(MapLegendController).Name} when the context menu builder provider is null."); } this.viewController = viewController; this.contextMenuBuilderProvider = contextMenuBuilderProvider; @@ -95,13 +96,14 @@ /// /// Updates the data for the if it is open. /// - /// The to show. If null the data + /// The being shown, for which + /// the legend view should to show its contents. If null, the legend view /// will be cleared. - public void Update(MapData data) + public void Update(IMapControl mapControl) { if (IsMapLegendViewOpen) { - legendView.Data = data; + legendView.MapControl = mapControl; } } @@ -120,10 +122,7 @@ viewController.ViewHost.AddToolView(legendView, ToolViewLocation.Left); viewController.ViewHost.SetImage(legendView, Resources.MapIcon); - if (OnOpenLegend != null) - { - OnOpenLegend(this, EventArgs.Empty); - } + OnOpenLegend?.Invoke(this, EventArgs.Empty); } /// @@ -132,6 +131,7 @@ private void CloseLegendView() { viewController.ViewHost.Remove(legendView); + legendView.Dispose(); legendView = null; } } Index: Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs =================================================================== diff -u -reef2ea9bdf721e0dcb425f4681eea0c84ee0ad75 -r7660d43cae4eda23b77c027f50dde28c23715c1b --- Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision eef2ea9bdf721e0dcb425f4681eea0c84ee0ad75) +++ Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision 7660d43cae4eda23b77c027f50dde28c23715c1b) @@ -25,19 +25,20 @@ using Core.Common.Controls.TreeView; using Core.Common.Controls.Views; using Core.Common.Gui.ContextMenu; -using Core.Components.DotSpatial.Forms; using Core.Components.Gis.Data; +using Core.Components.Gis.Forms; using MapResources = Core.Plugins.Map.Properties.Resources; using GuiResources = Core.Common.Gui.Properties.Resources; namespace Core.Plugins.Map.Legend { /// - /// The view which shows the data that is added to a . + /// The view which shows the data that is added to a . /// public sealed partial class MapLegendView : UserControl, ISelectionProvider { private readonly IContextMenuBuilderProvider contextMenuBuilderProvider; + private IMapControl mapControl; public event EventHandler SelectionChanged; @@ -50,7 +51,8 @@ { if (contextMenuBuilderProvider == null) { - throw new ArgumentNullException("contextMenuBuilderProvider", @"Cannot create a MapLegendView when the context menu builder provider is null."); + throw new ArgumentNullException(nameof(contextMenuBuilderProvider), + $"Cannot create a {typeof(MapLegendView).Name} when the context menu builder provider is null."); } this.contextMenuBuilderProvider = contextMenuBuilderProvider; @@ -62,6 +64,23 @@ treeViewControl.SelectedDataChanged += TreeViewControlSelectedDataChanged; } + /// + /// Gets or sets the for which this legend view is configured + /// to show the internal map data for. + /// + public IMapControl MapControl + { + get + { + return mapControl; + } + set + { + mapControl = value; + Data = value?.Data; + } + } + public object Data { get @@ -84,10 +103,7 @@ private void TreeViewControlSelectedDataChanged(object sender, EventArgs e) { - if (SelectionChanged != null) - { - SelectionChanged(this, new EventArgs()); - } + SelectionChanged?.Invoke(this, new EventArgs()); } private void RegisterTreeNodeInfos() @@ -97,6 +113,8 @@ Text = mapPointData => mapPointData.Name, Image = mapPointData => MapResources.PointsIcon, ContextMenuStrip = (nodeData, parentData, treeView) => contextMenuBuilderProvider.Get(nodeData, treeView) + .AddCustomItem(CreateZoomToExtentsItem(nodeData)) + .AddSeparator() .AddPropertiesItem() .Build(), CanDrag = (mapPointData, parentData) => true, @@ -110,6 +128,8 @@ Text = mapLineData => mapLineData.Name, Image = mapLineData => MapResources.LineIcon, ContextMenuStrip = (nodeData, parentData, treeView) => contextMenuBuilderProvider.Get(nodeData, treeView) + .AddCustomItem(CreateZoomToExtentsItem(nodeData)) + .AddSeparator() .AddPropertiesItem() .Build(), CanDrag = (mapLineData, parentData) => true, @@ -123,6 +143,8 @@ Text = mapPolygonData => mapPolygonData.Name, Image = mapPolygonData => MapResources.AreaIcon, ContextMenuStrip = (nodeData, parentData, treeView) => contextMenuBuilderProvider.Get(nodeData, treeView) + .AddCustomItem(CreateZoomToExtentsItem(nodeData)) + .AddSeparator() .AddPropertiesItem() .Build(), CanDrag = (mapPolygonData, parentData) => true, @@ -141,15 +163,30 @@ OnDrop = MapControlOnDrop, ContextMenuStrip = (mapDataCollection, parentData, treeView) => contextMenuBuilderProvider.Get(mapDataCollection, treeView) .AddCustomImportItem( - MapResources.MapLegendView_MapDataCollectionContextMenuStrip_Add_MapLayer, - MapResources.MapLegendView_MapDataCollectionContextMenuStrip_Add_MapLayer_ToolTip, - MapResources.MapPlusIcon) + MapResources.MapLegendView_MapDataCollectionContextMenuStrip_Add_MapLayer, + MapResources.MapLegendView_MapDataCollectionContextMenuStrip_Add_MapLayer_ToolTip, + MapResources.MapPlusIcon) .AddSeparator() + .AddCustomItem(CreateZoomToExtentsItem(mapDataCollection)) + .AddSeparator() .AddPropertiesItem() .Build() }); } + private StrictContextMenuItem CreateZoomToExtentsItem(MapData nodeData) + { + return new StrictContextMenuItem($"&{MapResources.Ribbon_ZoomToAll}", + nodeData.IsVisible ? + MapResources.MapLegendView_CreateZoomToExtentsItem_ZoomToAll_Tooltip : + MapResources.MapLegendView_CreateZoomToExtentsItem_ZoomToAllDisabled_Tooltip, + MapResources.ZoomToAllIcon, + (sender, args) => { MapControl?.ZoomToAllVisibleLayers(nodeData); }) + { + Enabled = nodeData.IsVisible + }; + } + #region MapData private static void MapDataOnNodeChecked(FeatureBasedMapData featureBasedMapData, object parentData) Index: Core/Plugins/src/Core.Plugins.Map/MapPlugin.cs =================================================================== diff -u -rb78eea44f0c54cf91f8357c96b5c9af8655308d7 -r7660d43cae4eda23b77c027f50dde28c23715c1b --- Core/Plugins/src/Core.Plugins.Map/MapPlugin.cs (.../MapPlugin.cs) (revision b78eea44f0c54cf91f8357c96b5c9af8655308d7) +++ Core/Plugins/src/Core.Plugins.Map/MapPlugin.cs (.../MapPlugin.cs) (revision 7660d43cae4eda23b77c027f50dde28c23715c1b) @@ -91,10 +91,7 @@ Gui.ViewHost.ActiveDocumentViewChanged -= OnActiveDocumentViewChanged; Gui.ViewHost.ViewOpened -= OnViewOpened; } - if (mapLegendController != null) - { - mapLegendController.Dispose(); - } + mapLegendController?.Dispose(); base.Dispose(); } @@ -103,7 +100,8 @@ { if (viewController == null) { - throw new ArgumentNullException("viewController", @"Cannot create a MapLegendController when the view controller is null"); + throw new ArgumentNullException(nameof(viewController), + $"Cannot create a {typeof(MapLegendController).Name} when the view controller is null"); } var controller = new MapLegendController(viewController, Gui); @@ -127,29 +125,19 @@ private static void OnViewOpened(object sender, ViewChangeEventArgs e) { var view = e.View as IMapView; - if (view != null) - { - view.Map.ZoomToAllVisibleLayers(); - } + view?.Map.ZoomToAllVisibleLayers(); } /// - /// Updates the components which the knows about so that it reflects - /// the currently active view. + /// Updates the components which the knows about so that + /// it reflects the currently active view. /// private void UpdateComponentsForActiveDocumentView() { var mapView = Gui.ViewHost.ActiveDocumentView as IMapView; - if (mapView != null) - { - mapRibbon.Map = mapView.Map; - mapLegendController.Update(mapView.Map.Data); - } - else - { - mapRibbon.Map = null; - mapLegendController.Update(null); - } + IMapControl mapControl = mapView?.Map; + mapLegendController.Update(mapControl); + mapRibbon.Map = mapControl; } } } \ No newline at end of file Index: Core/Plugins/src/Core.Plugins.Map/MapRibbon.xaml =================================================================== diff -u -rae99d19be5c1bd59e6cc85669c96a3b9895e660d -r7660d43cae4eda23b77c027f50dde28c23715c1b --- Core/Plugins/src/Core.Plugins.Map/MapRibbon.xaml (.../MapRibbon.xaml) (revision ae99d19be5c1bd59e6cc85669c96a3b9895e660d) +++ Core/Plugins/src/Core.Plugins.Map/MapRibbon.xaml (.../MapRibbon.xaml) (revision 7660d43cae4eda23b77c027f50dde28c23715c1b) @@ -42,18 +42,18 @@ - + - + - + Index: Core/Plugins/src/Core.Plugins.Map/Properties/Resources.Designer.cs =================================================================== diff -u -reef2ea9bdf721e0dcb425f4681eea0c84ee0ad75 -r7660d43cae4eda23b77c027f50dde28c23715c1b --- Core/Plugins/src/Core.Plugins.Map/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision eef2ea9bdf721e0dcb425f4681eea0c84ee0ad75) +++ Core/Plugins/src/Core.Plugins.Map/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 7660d43cae4eda23b77c027f50dde28c23715c1b) @@ -22,7 +22,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.17929 +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -274,6 +274,24 @@ } /// + /// Looks up a localized string similar to Zet het zoomniveau van de kaart dusdanig dat alle zichtbare elementen van deze laag precies in het beeld passen.. + /// + public static string MapLegendView_CreateZoomToExtentsItem_ZoomToAll_Tooltip { + get { + return ResourceManager.GetString("MapLegendView_CreateZoomToExtentsItem_ZoomToAll_Tooltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Om het zoomniveau aan te passen moet de laag zichtbaar zijn.. + /// + public static string MapLegendView_CreateZoomToExtentsItem_ZoomToAllDisabled_Tooltip { + get { + return ResourceManager.GetString("MapLegendView_CreateZoomToExtentsItem_ZoomToAllDisabled_Tooltip", resourceCulture); + } + } + + /// /// Looks up a localized string similar to &Voeg kaartlaag toe.... /// public static string MapLegendView_MapDataCollectionContextMenuStrip_Add_MapLayer { Index: Core/Plugins/src/Core.Plugins.Map/Properties/Resources.resx =================================================================== diff -u -reef2ea9bdf721e0dcb425f4681eea0c84ee0ad75 -r7660d43cae4eda23b77c027f50dde28c23715c1b --- Core/Plugins/src/Core.Plugins.Map/Properties/Resources.resx (.../Resources.resx) (revision eef2ea9bdf721e0dcb425f4681eea0c84ee0ad75) +++ Core/Plugins/src/Core.Plugins.Map/Properties/Resources.resx (.../Resources.resx) (revision 7660d43cae4eda23b77c027f50dde28c23715c1b) @@ -250,4 +250,10 @@ Shapebestand (*.shp)|*.shp + + Zet het zoomniveau van de kaart dusdanig dat alle zichtbare elementen van deze laag precies in het beeld passen. + + + Om het zoomniveau aan te passen moet de laag zichtbaar zijn. + \ No newline at end of file Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataCollectionTreeNodeInfoTest.cs =================================================================== diff -u -rf2f7d22ee59276f5df1f83fd409899bd895ea163 -r7660d43cae4eda23b77c027f50dde28c23715c1b --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataCollectionTreeNodeInfoTest.cs (.../MapDataCollectionTreeNodeInfoTest.cs) (revision f2f7d22ee59276f5df1f83fd409899bd895ea163) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataCollectionTreeNodeInfoTest.cs (.../MapDataCollectionTreeNodeInfoTest.cs) (revision 7660d43cae4eda23b77c027f50dde28c23715c1b) @@ -27,9 +27,11 @@ using Core.Common.Controls.TreeView; using Core.Common.Gui.Commands; using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.TestUtil.ContextMenu; using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; +using Core.Components.Gis.Forms; using Core.Plugins.Map.Legend; using Core.Plugins.Map.Properties; using NUnit.Extensions.Forms; @@ -42,6 +44,10 @@ [TestFixture] public class MapDataCollectionTreeNodeInfoTest : NUnitFormTest { + private const int contextMenuAddMapLayerIndex = 0; + private const int contextMenuZoomToAllIndex = 2; + private const int contextMenuPropertiesIndex = 4; + private MockRepository mocks; private MapLegendView mapLegendView; private TreeNodeInfo info; @@ -268,10 +274,13 @@ } [Test] - public void ContextMenuStrip_Always_CallsContextMenuBuilderMethods() + public void ContextMenuStrip_VisibleMapDataCollection_CallsContextMenuBuilderMethods() { // Setup - var mapDataCollection = new MapDataCollection("test data"); + var mapDataCollection = new MapDataCollection("test data") + { + IsVisible = true + }; var applicationFeatureCommandsStub = mocks.Stub(); var importCommandHandlerMock = mocks.Stub(); @@ -297,26 +306,146 @@ using (ContextMenuStrip contextMenu = info.ContextMenuStrip(mapDataCollection, null, treeViewControl)) { // Assert - Assert.AreEqual(3, contextMenu.Items.Count); - TestHelper.AssertContextMenuStripContainsItem(contextMenu, 0, + Assert.AreEqual(5, contextMenu.Items.Count); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuAddMapLayerIndex, "&Voeg kaartlaag toe...", "Importeer een nieuwe kaartlaag en voeg deze toe.", Resources.MapPlusIcon); - TestHelper.AssertContextMenuStripContainsItem(contextMenu, 2, + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Zet het zoomniveau van de kaart dusdanig dat alle zichtbare elementen van deze laag precies in het beeld passen.", + Resources.ZoomToAllIcon); + + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuPropertiesIndex, "Ei&genschappen", "Toon de eigenschappen in het Eigenschappenpaneel.", GuiResources.PropertiesHS, false); CollectionAssert.AllItemsAreInstancesOfType(new[] { - contextMenu.Items[1] + contextMenu.Items[1], + contextMenu.Items[3] }, typeof(ToolStripSeparator)); } } } + [Test] + public void ContextMenuStrip_InvisibleMapDataCollection_CallsContextMenuBuilderMethods() + { + // Setup + var mapDataCollection = new MapDataCollection("test data") + { + IsVisible = false + }; + + var applicationFeatureCommandsStub = mocks.Stub(); + var importCommandHandlerMock = mocks.Stub(); + importCommandHandlerMock.Stub(ich => ich.CanImportOn(null)).IgnoreArguments().Return(true); + var exportCommandHandlerMock = mocks.Stub(); + var viewCommandsMock = mocks.Stub(); + + using (var treeViewControl = new TreeViewControl()) + { + // Call + var builder = new ContextMenuBuilder(applicationFeatureCommandsStub, + importCommandHandlerMock, + exportCommandHandlerMock, + viewCommandsMock, + mapDataCollection, + treeViewControl); + + contextMenuBuilderProvider.Expect(cmbp => cmbp.Get(mapDataCollection, treeViewControl)).Return(builder); + + mocks.ReplayAll(); + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(mapDataCollection, null, treeViewControl)) + { + // Assert + Assert.AreEqual(5, contextMenu.Items.Count); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuAddMapLayerIndex, + "&Voeg kaartlaag toe...", + "Importeer een nieuwe kaartlaag en voeg deze toe.", + Resources.MapPlusIcon); + + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Om het zoomniveau aan te passen moet de laag zichtbaar zijn.", + Resources.ZoomToAllIcon, + false); + + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuPropertiesIndex, + "Ei&genschappen", + "Toon de eigenschappen in het Eigenschappenpaneel.", + GuiResources.PropertiesHS, + false); + + CollectionAssert.AllItemsAreInstancesOfType(new[] + { + contextMenu.Items[1], + contextMenu.Items[3] + }, typeof(ToolStripSeparator)); + } + } + } + + [Test] + public void ContextMenuStrip_MapLegendViewHasMapControlAndClickZoomToAll_DoZoomToAllVisibleLayersForMapData() + { + // Setup + var mapData = new MapDataCollection("A") + { + IsVisible = true + }; + + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + var mapControl = mocks.Stub(); + mapControl.Expect(c => c.ZoomToAllVisibleLayers(mapData)); + mocks.ReplayAll(); + + mapLegendView.MapControl = mapControl; + + using (var contextMenu = info.ContextMenuStrip(mapData, null, null)) + { + // Call + contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + // Assert expectancies are called in TearDown() + } + } + + [Test] + public void ContextMenuStrip_MapLegendViewWithoutMapControlAndClickZoomToAll_DoNothing() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + mapLegendView.MapControl = null; + + var mapData = new MapDataCollection("A") + { + IsVisible = true + }; + + using (var contextMenu = info.ContextMenuStrip(mapData, null, null)) + { + // Call + TestDelegate call = () => contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + Assert.DoesNotThrow(call); + } + } + public override void TearDown() { mapLegendView.Dispose(); Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapLegendViewTest.cs =================================================================== diff -u -rb78eea44f0c54cf91f8357c96b5c9af8655308d7 -r7660d43cae4eda23b77c027f50dde28c23715c1b --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapLegendViewTest.cs (.../MapLegendViewTest.cs) (revision b78eea44f0c54cf91f8357c96b5c9af8655308d7) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapLegendViewTest.cs (.../MapLegendViewTest.cs) (revision 7660d43cae4eda23b77c027f50dde28c23715c1b) @@ -30,6 +30,7 @@ using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; using Core.Components.Gis.Features; +using Core.Components.Gis.Forms; using Core.Components.Gis.Geometries; using Core.Plugins.Map.Legend; using Core.Plugins.Map.Properties; @@ -192,7 +193,50 @@ } } + [Test] + public void MapControl_MapControlHasMapWithData_DataReturnsMapDataOfMap() + { + // Setup + var mapData = new MapDataCollection("A"); + + var mockRepository = new MockRepository(); + var mapControl = mockRepository.Stub(); + mapControl.Data = mapData; + mockRepository.ReplayAll(); + + using (var view = new MapLegendView(contextMenuBuilderProvider) + { + Data = new MapDataCollection("A") + }) + { + // Call + view.MapControl = mapControl; + + // Assert + Assert.AreSame(mapData, view.Data); + } + mockRepository.VerifyAll(); + } + + [Test] + public void MapControl_DataSetAndThenMapControlSetToNull_DataSetToNull() + { + // Setup + using (var view = new MapLegendView(contextMenuBuilderProvider) + { + Data = new MapDataCollection("A") + }) + { + // Call + view.MapControl = null; + + // Assert + Assert.IsNull(view.Data); + } + } + + [Test] [RequiresSTA] public void Selection_Always_ReturnsSelectedNodeData() { Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapLineDataTreeNodeInfoTest.cs =================================================================== diff -u -rf2f7d22ee59276f5df1f83fd409899bd895ea163 -r7660d43cae4eda23b77c027f50dde28c23715c1b --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapLineDataTreeNodeInfoTest.cs (.../MapLineDataTreeNodeInfoTest.cs) (revision f2f7d22ee59276f5df1f83fd409899bd895ea163) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapLineDataTreeNodeInfoTest.cs (.../MapLineDataTreeNodeInfoTest.cs) (revision 7660d43cae4eda23b77c027f50dde28c23715c1b) @@ -25,9 +25,11 @@ using Core.Common.Base; using Core.Common.Controls.TreeView; using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.TestUtil.ContextMenu; using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; +using Core.Components.Gis.Forms; using Core.Plugins.Map.Legend; using Core.Plugins.Map.Properties; using NUnit.Framework; @@ -38,6 +40,8 @@ [TestFixture] public class MapLineDataTreeNodeInfoTest { + private const int contextMenuZoomToAllIndex = 0; + private TreeNodeInfo info; private MockRepository mocks; private MapLegendView mapLegendView; @@ -123,22 +127,133 @@ public void ContextMenuStrip_Always_CallsBuilder() { // Setup - var menuBuilderMock = mocks.StrictMock(); - menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); - menuBuilderMock.Expect(mb => mb.Build()).Return(null); + var builder = mocks.StrictMock(); + using (mocks.Ordered()) + { + builder.Expect(mb => mb.AddCustomItem(Arg.Is.NotNull)).Return(builder); + builder.Expect(mb => mb.AddSeparator()).Return(builder); + builder.Expect(mb => mb.AddPropertiesItem()).Return(builder); + builder.Expect(mb => mb.Build()).Return(null); + } + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); - contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(menuBuilderMock); - mocks.ReplayAll(); + var mapData = new MapLineData("A"); + // Call - info.ContextMenuStrip(null, null, null); + info.ContextMenuStrip(mapData, null, null); // Assert // Assert expectancies are called in TearDown() } [Test] + public void ContextMenuStrip_VisibleMapData_ZoomToAllItemEnabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + var mapData = new MapLineData("A") + { + IsVisible = true + }; + + // Call + using (var contextMenu = info.ContextMenuStrip(mapData, null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Zet het zoomniveau van de kaart dusdanig dat alle zichtbare elementen van deze laag precies in het beeld passen.", + Resources.ZoomToAllIcon); + } + } + + [Test] + public void ContextMenuStrip_InvisibleMapData_ZoomToAllItemDisabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + var mapData = new MapLineData("A") + { + IsVisible = false + }; + + // Call + using (var contextMenu = info.ContextMenuStrip(mapData, null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Om het zoomniveau aan te passen moet de laag zichtbaar zijn.", + Resources.ZoomToAllIcon, + false); + } + } + + [Test] + public void ContextMenuStrip_MapLegendViewHasMapControlAndClickZoomToAll_DoZoomToAllVisibleLayersForMapData() + { + // Setup + var mapData = new MapLineData("A") + { + IsVisible = true + }; + + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + var mapControl = mocks.Stub(); + mapControl.Expect(c => c.ZoomToAllVisibleLayers(mapData)); + mocks.ReplayAll(); + + mapLegendView.MapControl = mapControl; + + using (var contextMenu = info.ContextMenuStrip(mapData, null, null)) + { + // Call + contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + // Assert expectancies are called in TearDown() + } + } + + [Test] + public void ContextMenuStrip_MapLegendViewWithoutMapControlAndClickZoomToAll_DoNothing() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + mapLegendView.MapControl = null; + + var mapData = new MapLineData("A") + { + IsVisible = true + }; + + using (var contextMenu = info.ContextMenuStrip(mapData, null, null)) + { + // Call + TestDelegate call = () => contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + Assert.DoesNotThrow(call); + } + } + + [Test] public void CanCheck_Always_ReturnsTrue() { // Setup Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPointDataTreeNodeInfoTest.cs =================================================================== diff -u -rf2f7d22ee59276f5df1f83fd409899bd895ea163 -r7660d43cae4eda23b77c027f50dde28c23715c1b --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPointDataTreeNodeInfoTest.cs (.../MapPointDataTreeNodeInfoTest.cs) (revision f2f7d22ee59276f5df1f83fd409899bd895ea163) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPointDataTreeNodeInfoTest.cs (.../MapPointDataTreeNodeInfoTest.cs) (revision 7660d43cae4eda23b77c027f50dde28c23715c1b) @@ -21,12 +21,15 @@ using System; using System.Collections.Generic; +using System.Windows.Forms; using Core.Common.Base; using Core.Common.Controls.TreeView; using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.TestUtil.ContextMenu; using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; +using Core.Components.Gis.Forms; using Core.Plugins.Map.Legend; using Core.Plugins.Map.Properties; using NUnit.Framework; @@ -37,6 +40,8 @@ [TestFixture] public class MapPointDataTreeNodeInfoTest { + private const int contextMenuZoomToAllIndex = 0; + private TreeNodeInfo info; private MockRepository mocks; private MapLegendView mapLegendView; @@ -122,22 +127,133 @@ public void ContextMenuStrip_Always_CallsBuilder() { // Setup - var menuBuilderMock = mocks.StrictMock(); - menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); - menuBuilderMock.Expect(mb => mb.Build()).Return(null); + var builder = mocks.StrictMock(); + using (mocks.Ordered()) + { + builder.Expect(mb => mb.AddCustomItem(Arg.Is.NotNull)).Return(builder); + builder.Expect(mb => mb.AddSeparator()).Return(builder); + builder.Expect(mb => mb.AddPropertiesItem()).Return(builder); + builder.Expect(mb => mb.Build()).Return(null); + } + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); - contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(menuBuilderMock); - mocks.ReplayAll(); + var mapData = new MapPointData("A"); + // Call - info.ContextMenuStrip(null, null, null); + info.ContextMenuStrip(mapData, null, null); // Assert // Assert expectancies are called in TearDown() } [Test] + public void ContextMenuStrip_VisibleMapData_ZoomToAllItemEnabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + var mapData = new MapPointData("A") + { + IsVisible = true + }; + + // Call + using (var contextMenu = info.ContextMenuStrip(mapData, null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Zet het zoomniveau van de kaart dusdanig dat alle zichtbare elementen van deze laag precies in het beeld passen.", + Resources.ZoomToAllIcon); + } + } + + [Test] + public void ContextMenuStrip_InvisibleMapData_ZoomToAllItemDisabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + var mapData = new MapPointData("A") + { + IsVisible = false + }; + + // Call + using (var contextMenu = info.ContextMenuStrip(mapData, null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Om het zoomniveau aan te passen moet de laag zichtbaar zijn.", + Resources.ZoomToAllIcon, + false); + } + } + + [Test] + public void ContextMenuStrip_MapLegendViewHasMapControlAndClickZoomToAll_DoZoomToAllVisibleLayersForMapData() + { + // Setup + var mapData = new MapPointData("A") + { + IsVisible = true + }; + + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + var mapControl = mocks.Stub(); + mapControl.Expect(c => c.ZoomToAllVisibleLayers(mapData)); + mocks.ReplayAll(); + + mapLegendView.MapControl = mapControl; + + using (var contextMenu = info.ContextMenuStrip(mapData, null, null)) + { + // Call + contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + // Assert expectancies are called in TearDown() + } + } + + [Test] + public void ContextMenuStrip_MapLegendViewWithoutMapControlAndClickZoomToAll_DoNothing() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + mapLegendView.MapControl = null; + + var mapData = new MapPointData("A") + { + IsVisible = true + }; + + using (var contextMenu = info.ContextMenuStrip(mapData, null, null)) + { + // Call + TestDelegate call = () => contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + Assert.DoesNotThrow(call); + } + } + + [Test] public void CanCheck_Always_ReturnsTrue() { // Setup Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPolygonDataTreeNodeInfoTest.cs =================================================================== diff -u -rf2f7d22ee59276f5df1f83fd409899bd895ea163 -r7660d43cae4eda23b77c027f50dde28c23715c1b --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPolygonDataTreeNodeInfoTest.cs (.../MapPolygonDataTreeNodeInfoTest.cs) (revision f2f7d22ee59276f5df1f83fd409899bd895ea163) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPolygonDataTreeNodeInfoTest.cs (.../MapPolygonDataTreeNodeInfoTest.cs) (revision 7660d43cae4eda23b77c027f50dde28c23715c1b) @@ -21,12 +21,15 @@ using System; using System.Collections.Generic; +using System.Windows.Forms; using Core.Common.Base; using Core.Common.Controls.TreeView; using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.TestUtil.ContextMenu; using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; +using Core.Components.Gis.Forms; using Core.Plugins.Map.Legend; using Core.Plugins.Map.Properties; using NUnit.Framework; @@ -37,6 +40,8 @@ [TestFixture] public class MapPolygonDataTreeNodeInfoTest { + private const int contextMenuZoomToAllIndex = 0; + private TreeNodeInfo info; private MockRepository mocks; private MapLegendView mapLegendView; @@ -122,22 +127,133 @@ public void ContextMenuStrip_Always_CallsBuilder() { // Setup - var menuBuilderMock = mocks.StrictMock(); - menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); - menuBuilderMock.Expect(mb => mb.Build()).Return(null); + var builder = mocks.StrictMock(); + using (mocks.Ordered()) + { + builder.Expect(mb => mb.AddCustomItem(Arg.Is.NotNull)).Return(builder); + builder.Expect(mb => mb.AddSeparator()).Return(builder); + builder.Expect(mb => mb.AddPropertiesItem()).Return(builder); + builder.Expect(mb => mb.Build()).Return(null); + } + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); - contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(menuBuilderMock); - mocks.ReplayAll(); + var mapData = new MapPolygonData("A"); + // Call - info.ContextMenuStrip(null, null, null); + info.ContextMenuStrip(mapData, null, null); // Assert // Assert expectancies are called in TearDown() } [Test] + public void ContextMenuStrip_VisibleMapData_ZoomToAllItemEnabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + var mapData = new MapPolygonData("A") + { + IsVisible = true + }; + + // Call + using (var contextMenu = info.ContextMenuStrip(mapData, null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Zet het zoomniveau van de kaart dusdanig dat alle zichtbare elementen van deze laag precies in het beeld passen.", + Resources.ZoomToAllIcon); + } + } + + [Test] + public void ContextMenuStrip_InvisibleMapData_ZoomToAllItemDisabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + var mapData = new MapPolygonData("A") + { + IsVisible = false + }; + + // Call + using (var contextMenu = info.ContextMenuStrip(mapData, null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Om het zoomniveau aan te passen moet de laag zichtbaar zijn.", + Resources.ZoomToAllIcon, + false); + } + } + + [Test] + public void ContextMenuStrip_MapLegendViewHasMapControlAndClickZoomToAll_DoZoomToAllVisibleLayersForMapData() + { + // Setup + var mapData = new MapPolygonData("A") + { + IsVisible = true + }; + + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + var mapControl = mocks.Stub(); + mapControl.Expect(c => c.ZoomToAllVisibleLayers(mapData)); + mocks.ReplayAll(); + + mapLegendView.MapControl = mapControl; + + using (var contextMenu = info.ContextMenuStrip(mapData, null, null)) + { + // Call + contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + // Assert expectancies are called in TearDown() + } + } + + [Test] + public void ContextMenuStrip_MapLegendViewWithoutMapControlAndClickZoomToAll_DoNothing() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + mapLegendView.MapControl = null; + + var mapData = new MapPolygonData("A") + { + IsVisible = true + }; + + using (var contextMenu = info.ContextMenuStrip(mapData, null, null)) + { + // Call + TestDelegate call = () => contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + Assert.DoesNotThrow(call); + } + } + + [Test] public void CanCheck_Always_ReturnsTrue() { // Setup