Index: Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.Designer.cs =================================================================== diff -u -r9e9976818f1b446948c3bf815cafe2e023f98ac1 -r407f4e5c9039e9172d377e1406076e31c7fce954 --- Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.Designer.cs (.../MapControl.Designer.cs) (revision 9e9976818f1b446948c3bf815cafe2e023f98ac1) +++ Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.Designer.cs (.../MapControl.Designer.cs) (revision 407f4e5c9039e9172d377e1406076e31c7fce954) @@ -44,6 +44,7 @@ { this.toolStrip = new System.Windows.Forms.ToolStrip(); this.panToolStripButton = new System.Windows.Forms.ToolStripButton(); + this.rectangleSelectToolStripButton = new System.Windows.Forms.ToolStripButton(); this.zoomToRectangleToolStripButton = new System.Windows.Forms.ToolStripButton(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.zoomToVisibleLayersToolStripButton = new System.Windows.Forms.ToolStripButton(); @@ -63,6 +64,7 @@ this.toolStrip.BackColor = ColorDefinitions.ControlBackgroundColor; this.toolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.panToolStripButton, + this.rectangleSelectToolStripButton, this.zoomToRectangleToolStripButton, this.toolStripSeparator1, this.zoomToVisibleLayersToolStripButton, @@ -85,6 +87,16 @@ this.panToolStripButton.ToolTipText = global::Core.Components.DotSpatial.Forms.Properties.Resources.MapControl_Pan; this.panToolStripButton.Click += new System.EventHandler(this.PanToolStripButtonClick); // + // rectangleSelectToolStripButton + // + this.rectangleSelectToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.rectangleSelectToolStripButton.Margin = new System.Windows.Forms.Padding(2, 2, 2, 3); + this.rectangleSelectToolStripButton.Name = "rectangleSelectToolStripButton"; + this.rectangleSelectToolStripButton.Size = new System.Drawing.Size(22, 19); + this.rectangleSelectToolStripButton.Text = "\uE901"; + this.rectangleSelectToolStripButton.ToolTipText = global::Core.Components.DotSpatial.Forms.Properties.Resources.MapControl_RectangleSelect; + this.rectangleSelectToolStripButton.Click += new System.EventHandler(this.RectangleSelectToolStripButtonClick); + // // zoomToRectangleToolStripButton // this.zoomToRectangleToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; @@ -158,6 +170,7 @@ #endregion private System.Windows.Forms.ToolStrip toolStrip; private System.Windows.Forms.ToolStripButton panToolStripButton; + private System.Windows.Forms.ToolStripButton rectangleSelectToolStripButton; private System.Windows.Forms.ToolStripButton zoomToRectangleToolStripButton; private System.Windows.Forms.ToolStripButton zoomToVisibleLayersToolStripButton; private System.Windows.Forms.ToolStripButton showCoordinatesToolStripButton; Index: Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs =================================================================== diff -u -r9e9976818f1b446948c3bf815cafe2e023f98ac1 -r407f4e5c9039e9172d377e1406076e31c7fce954 --- Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs (.../MapControl.cs) (revision 9e9976818f1b446948c3bf815cafe2e023f98ac1) +++ Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs (.../MapControl.cs) (revision 407f4e5c9039e9172d377e1406076e31c7fce954) @@ -185,6 +185,7 @@ private void SetFonts() { panToolStripButton.Font = font; + rectangleSelectToolStripButton.Font = font; zoomToRectangleToolStripButton.Font = font; zoomToVisibleLayersToolStripButton.Font = font; showCoordinatesToolStripButton.Font = font; @@ -205,6 +206,11 @@ mapFunctionPan.MouseDown += MapFunctionPanOnMouseDown; mapFunctionPan.MouseUp += MapFunctionOnMouseUp; + MapFunctionSelect mapFunctionSelect = map.MapFunctions.OfType().First(); + mapFunctionSelect.FunctionActivated += MapFunctionActivateFunction; + mapFunctionSelect.MouseDown += MapFunctionSelectOnMouseDown; + mapFunctionSelect.MouseUp += MapFunctionOnMouseUp; + mapFunctionSelectionZoom = new MapFunctionSelectionZoom(map); map.MapFunctions.Add(mapFunctionSelectionZoom); mapFunctionSelectionZoom.FunctionActivated += MapFunctionActivateFunction; @@ -576,6 +582,11 @@ map.Cursor = geoMouseArgs.Button != MouseButtons.Right ? Cursors.Hand : defaultCursor; } + private void MapFunctionSelectOnMouseDown(object sender, GeoMouseArgs geoMouseArgs) + { + map.Cursor = geoMouseArgs.Button != MouseButtons.Right ? Cursors.Arrow : defaultCursor; + } + private void MapFunctionSelectionZoomOnMouseDown(object sender, GeoMouseArgs geoMouseArgs) { switch (geoMouseArgs.Button) @@ -601,9 +612,24 @@ map.FunctionMode = FunctionMode.Pan; panToolStripButton.Checked = true; + rectangleSelectToolStripButton.Checked = false; zoomToRectangleToolStripButton.Checked = false; } + private void RectangleSelectToolStripButtonClick(object sender, EventArgs e) + { + if (rectangleSelectToolStripButton.Checked) + { + return; + } + + map.FunctionMode = FunctionMode.Select; + + panToolStripButton.Checked = false; + rectangleSelectToolStripButton.Checked = true; + zoomToRectangleToolStripButton.Checked = false; + } + private void ZoomToRectangleToolStripButtonClick(object sender, EventArgs e) { if (zoomToRectangleToolStripButton.Checked) @@ -615,6 +641,7 @@ map.ActivateMapFunction(mapFunctionSelectionZoom); panToolStripButton.Checked = false; + rectangleSelectToolStripButton.Checked = false; zoomToRectangleToolStripButton.Checked = true; } Index: Core/Components/src/Core.Components.DotSpatial.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -r9e9976818f1b446948c3bf815cafe2e023f98ac1 -r407f4e5c9039e9172d377e1406076e31c7fce954 --- Core/Components/src/Core.Components.DotSpatial.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 9e9976818f1b446948c3bf815cafe2e023f98ac1) +++ Core/Components/src/Core.Components.DotSpatial.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 407f4e5c9039e9172d377e1406076e31c7fce954) @@ -1,4 +1,4 @@ -// Copyright (C) Stichting Deltares 2022. All rights reserved. +// Copyright (C) Stichting Deltares 2022. All rights reserved. // // This file is part of Riskeer. // @@ -101,6 +101,15 @@ } /// + /// Looks up a localized string similar to Selecteer door rechthoek. + /// + internal static string MapControl_RectangleSelect { + get { + return ResourceManager.GetString("MapControl_RectangleSelect", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Toon coördinaten. /// internal static string MapControl_ShowCoordinates { Index: Core/Components/src/Core.Components.DotSpatial.Forms/Properties/Resources.resx =================================================================== diff -u -r3b75626e8f322a39e07c03da3ef5f382639eb15c -r407f4e5c9039e9172d377e1406076e31c7fce954 --- Core/Components/src/Core.Components.DotSpatial.Forms/Properties/Resources.resx (.../Resources.resx) (revision 3b75626e8f322a39e07c03da3ef5f382639eb15c) +++ Core/Components/src/Core.Components.DotSpatial.Forms/Properties/Resources.resx (.../Resources.resx) (revision 407f4e5c9039e9172d377e1406076e31c7fce954) @@ -127,6 +127,9 @@ Verschuiven + + Selecteer door rechthoek + Zoom door rechthoek Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs =================================================================== diff -u -r9e9976818f1b446948c3bf815cafe2e023f98ac1 -r407f4e5c9039e9172d377e1406076e31c7fce954 --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs (.../MapControlTest.cs) (revision 9e9976818f1b446948c3bf815cafe2e023f98ac1) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/MapControlTest.cs (.../MapControlTest.cs) (revision 407f4e5c9039e9172d377e1406076e31c7fce954) @@ -95,6 +95,7 @@ Assert.AreEqual(9, map.MapFunctions.Count); Assert.AreEqual(1, map.MapFunctions.OfType().Count()); + Assert.AreEqual(1, map.MapFunctions.OfType().Count()); Assert.AreEqual(1, map.MapFunctions.OfType().Count()); Assert.AreEqual(KnownCoordinateSystems.Projected.NationalGrids.Rijksdriehoekstelsel, map.Projection); @@ -2720,7 +2721,7 @@ [Test] [Apartment(ApartmentState.STA)] - public void Panning_MouseUp_DefaultCursorSet() + public void Panning_Activated_DefaultCursorSet() { using (var form = new Form()) { @@ -2735,7 +2736,7 @@ map.Cursor = Cursors.WaitCursor; // Call - EventHelper.RaiseEvent(mapFunctionPan, "MouseUp", new GeoMouseArgs(new MouseEventArgs(MouseButtons.None, 1, 2, 3, 4), map)); + mapFunctionPan.Activate(); // Assert Assert.AreEqual(Cursors.Default, map.Cursor); @@ -2744,7 +2745,9 @@ [Test] [Apartment(ApartmentState.STA)] - public void Panning_Activated_DefaultCursorSet() + [TestCase(MouseButtons.Left)] + [TestCase(MouseButtons.Middle)] + public void Panning_LeftOrMiddleMouseDown_HandCursorSet(MouseButtons mouseButton) { using (var form = new Form()) { @@ -2759,16 +2762,16 @@ map.Cursor = Cursors.WaitCursor; // Call - mapFunctionPan.Activate(); + EventHelper.RaiseEvent(mapFunctionPan, "MouseDown", new GeoMouseArgs(new MouseEventArgs(mouseButton, 1, 2, 3, 4), map)); // Assert - Assert.AreEqual(Cursors.Default, map.Cursor); + Assert.AreEqual(Cursors.Hand, map.Cursor); } } [Test] [Apartment(ApartmentState.STA)] - public void Panning_LeftMouseDown_HandCursorSet() + public void Panning_RightMouseDown_DefaultCursorSet() { using (var form = new Form()) { @@ -2783,16 +2786,16 @@ map.Cursor = Cursors.WaitCursor; // Call - EventHelper.RaiseEvent(mapFunctionPan, "MouseDown", new GeoMouseArgs(new MouseEventArgs(MouseButtons.Left, 1, 2, 3, 4), map)); + EventHelper.RaiseEvent(mapFunctionPan, "MouseDown", new GeoMouseArgs(new MouseEventArgs(MouseButtons.Right, 1, 2, 3, 4), map)); // Assert - Assert.AreEqual(Cursors.Hand, map.Cursor); + Assert.AreEqual(Cursors.Default, map.Cursor); } } - + [Test] [Apartment(ApartmentState.STA)] - public void Panning_MiddleMouseDown_HandCursorSet() + public void Panning_MouseUp_DefaultCursorSet() { using (var form = new Form()) { @@ -2807,16 +2810,20 @@ map.Cursor = Cursors.WaitCursor; // Call - EventHelper.RaiseEvent(mapFunctionPan, "MouseDown", new GeoMouseArgs(new MouseEventArgs(MouseButtons.Middle, 1, 2, 3, 4), map)); + EventHelper.RaiseEvent(mapFunctionPan, "MouseUp", new GeoMouseArgs(new MouseEventArgs(MouseButtons.None, 1, 2, 3, 4), map)); // Assert - Assert.AreEqual(Cursors.Hand, map.Cursor); + Assert.AreEqual(Cursors.Default, map.Cursor); } } + #endregion + + #region Select + [Test] [Apartment(ApartmentState.STA)] - public void Panning_RightMouseDown_DefaultCursorSet() + public void Select_Activated_DefaultCursorSet() { using (var form = new Form()) { @@ -2826,18 +2833,95 @@ form.Show(); var map = (Map) new ControlTester("Map").TheObject; - MapFunctionPan mapFunctionPan = map.MapFunctions.OfType().First(); + MapFunctionSelect mapFunctionSelect = map.MapFunctions.OfType().First(); map.Cursor = Cursors.WaitCursor; // Call - EventHelper.RaiseEvent(mapFunctionPan, "MouseDown", new GeoMouseArgs(new MouseEventArgs(MouseButtons.Right, 1, 2, 3, 4), map)); + mapFunctionSelect.Activate(); // Assert Assert.AreEqual(Cursors.Default, map.Cursor); } } + [Test] + [Apartment(ApartmentState.STA)] + [TestCase(MouseButtons.Left)] + [TestCase(MouseButtons.Middle)] + public void Select_LeftOrMiddleMouseDown_HandCursorSet(MouseButtons mouseButton) + { + using (var form = new Form()) + { + // Setup + var mapControl = new MapControl(); + form.Controls.Add(mapControl); + form.Show(); + + var map = (Map) new ControlTester("Map").TheObject; + MapFunctionSelect mapFunctionSelect = map.MapFunctions.OfType().First(); + + map.Cursor = Cursors.WaitCursor; + + // Call + EventHelper.RaiseEvent(mapFunctionSelect, "MouseDown", new GeoMouseArgs(new MouseEventArgs(mouseButton, 1, 2, 3, 4), map)); + + // Assert + Assert.AreEqual(Cursors.Arrow, map.Cursor); + } + } + + [Test] + [Apartment(ApartmentState.STA)] + public void Select_RightMouseDown_DefaultCursorSet() + { + using (var form = new Form()) + { + // Setup + var mapControl = new MapControl(); + form.Controls.Add(mapControl); + form.Show(); + + var map = (Map) new ControlTester("Map").TheObject; + MapFunctionSelect mapFunctionSelect = map.MapFunctions.OfType().First(); + + map.Cursor = Cursors.WaitCursor; + + // Call + EventHelper.RaiseEvent(mapFunctionSelect, "MouseDown", new GeoMouseArgs(new MouseEventArgs(MouseButtons.Right, 1, 2, 3, 4), map)); + + // Assert + Assert.AreEqual(Cursors.Default, map.Cursor); + } + } + + [Test] + [Apartment(ApartmentState.STA)] + [Ignore("Fix when layer selection is dynamic.")] + public void Select_MouseUp_DefaultCursorSet() + { + using (var form = new Form()) + { + // Setup + var mapControl = new MapControl(); + form.Controls.Add(mapControl); + form.Show(); + + var map = (Map) new ControlTester("Map").TheObject; + MapFunctionSelect mapFunctionSelect = map.MapFunctions.OfType().First(); + + // Need to raise MouseDown event to set the 'isDragging' state to true. Otherwise the MouseUp event will be swallowed. + EventHelper.RaiseEvent(mapFunctionSelect, "MouseDown", new GeoMouseArgs(new MouseEventArgs(MouseButtons.Left, 1, 2, 3, 4), map)); + map.Cursor = Cursors.WaitCursor; + + // Call + EventHelper.RaiseEvent(mapFunctionSelect, "MouseUp", new GeoMouseArgs(new MouseEventArgs(MouseButtons.None, 1, 2, 3, 4), map)); + + // Assert + Assert.AreEqual(Cursors.Default, map.Cursor); + } + } + #endregion } } \ No newline at end of file