Skip to content

Commit

Permalink
added possibility to snap only to selected layers instead of all
Browse files Browse the repository at this point in the history
  • Loading branch information
jany-tenaj committed Aug 2, 2017
1 parent e181a34 commit fdf6baf
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 24 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Be aware that code written for 1.9 will not work out of the box because DotSpati
- Possibility to drag layers out of their group into the parent group (in legend) (#1008)
- Clear parameter to Select function to speed up drawing (#1024)
- LayoutControl.InitialOpenFileDirectory property that allows to set the folder that is shown in the OpenFileDialog that is used to open an existing layout
- FeatureLayer.Snappable to indicate whether the layer can be used for snapping

### Changed
- Switched to VS2015 and C#6
Expand All @@ -44,6 +45,8 @@ Be aware that code written for 1.9 will not work out of the box because DotSpati
- Made Shapefile class abstract, because we already have FeatureSet for creating unspecified Shapefiles (#890)
- Moved MapFrame extension methods to Group (#1008)
- Drawing functions so selected features are drawn on top (#897)
- ShapeEditors AddFeature and MoveVertex functions, so they snap only to the layers that allow snapping
- ShapeEditors SnapSettingsDialog to allow the users to select the layers the editor functions may snap to

### Removed
- Removed DotSpatial.Topology assembly (#633)
Expand Down
31 changes: 25 additions & 6 deletions Source/DotSpatial.Plugins.ShapeEditor/ButtonHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,33 @@ private void SetSnapLayers(SnappableMapFunction func)

private void SnappingButtonClick(object sender, EventArgs e)
{
SnapSettingsDialog dlg = new SnapSettingsDialog
using (SnapSettingsDialog dlg = new SnapSettingsDialog(_geoMap)
{
DoSnapping = _doSnapping
};
dlg.ShowDialog();
_doSnapping = dlg.DoSnapping;
if (_moveVertexFunction != null) _moveVertexFunction.DoSnapping = _doSnapping; // changed by jany_ (2016-02-24) update the snap settings of the functions without having to stop editing
if (_addShapeFunction != null) _addShapeFunction.DoSnapping = _doSnapping;
})
{
if (dlg.ShowDialog() == DialogResult.OK)
{
_doSnapping = dlg.DoSnapping;
if (_moveVertexFunction != null)
{
_moveVertexFunction.DoSnapping = _doSnapping; // changed by jany_ (2016-02-24) update the snap settings of the functions without having to stop editing
if (_doSnapping)
{
SetSnapLayers(_moveVertexFunction);
}
}

if (_addShapeFunction != null)
{
_addShapeFunction.DoSnapping = _doSnapping;
if (_doSnapping)
{
SetSnapLayers(_addShapeFunction);
}
}
}
}
}

private void UpdateAddShapeFunctionLayer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>ShapeEditorResources.resx</DependentUpon>
</Compile>
<Compile Include="SnapLayer.cs" />
<Compile Include="SnappableMapFunction.cs">
<SubType>Code</SubType>
</Compile>
Expand Down
60 changes: 60 additions & 0 deletions Source/DotSpatial.Plugins.ShapeEditor/SnapLayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) DotSpatial Team. All rights reserved.
// Licensed under the MIT license. See License.txt file in the project root for full license information.

using DotSpatial.Symbology;

namespace DotSpatial.Plugins.ShapeEditor
{
/// <summary>
/// Class to control layers snappable property through the datagridview.
/// </summary>
public class SnapLayer
{
#region Fields

/// <summary>
/// Layer, whose snappable property can be changed.
/// </summary>
private readonly IFeatureLayer _layer;

#endregion

#region Constructors

/// <summary>
/// Initializes a new instance of the <see cref="SnapLayer"/> class.
/// </summary>
/// <param name="pLayer">Layer, for which the SnapLayer-object gets created.</param>
public SnapLayer(IFeatureLayer pLayer)
{
_layer = pLayer;
}

#endregion

#region Properties

/// <summary>
/// Gets the layer name so it can be shown in the DataGridView.
/// </summary>
public string LayerName => _layer.LegendText;

/// <summary>
/// Gets or sets a value indicating whether snapping to the coordinates of the layers features is allowed.
/// </summary>
public bool Snappable
{
get
{
return _layer.Snappable;
}

set
{
_layer.Snappable = value;
}
}

#endregion
}
}
117 changes: 101 additions & 16 deletions Source/DotSpatial.Plugins.ShapeEditor/SnapSettingsDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 29 additions & 1 deletion Source/DotSpatial.Plugins.ShapeEditor/SnapSettingsDialog.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) DotSpatial Team. All rights reserved.
// Licensed under the MIT license. See License.txt file in the project root for full license information.

using System.Collections.Generic;
using System.Windows.Forms;
using DotSpatial.Controls;

namespace DotSpatial.Plugins.ShapeEditor
{
Expand All @@ -13,9 +15,19 @@ public partial class SnapSettingsDialog : Form
/// <summary>
/// Initializes a new instance of the <see cref="SnapSettingsDialog"/> class.
/// </summary>
public SnapSettingsDialog()
/// <param name="map">The map that contains the layers.</param>
public SnapSettingsDialog(IMap map)
{
InitializeComponent();
List<SnapLayer> snaplist = new List<SnapLayer>();

foreach (var layer in map.GetFeatureLayers())
{
snaplist.Add(new SnapLayer(layer));
}

dgvLayer.AutoGenerateColumns = false;
dgvLayer.DataSource = snaplist;
}

/// <summary>
Expand All @@ -26,5 +38,21 @@ public bool DoSnapping
get { return cbPerformSnap.Checked; }
set { cbPerformSnap.Checked = value; }
}

/// <summary>
/// Sets the check mark of the selected cell.
/// </summary>
/// <param name="sender">The sender of the event.</param>
/// <param name="e">The event args.</param>
private void DgvLayerCellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex < 0 || e.ColumnIndex < 0) return;

if (dgvLayer.Columns[e.ColumnIndex].Name == dgvcSnappable.Name)
{
DataGridViewRow row = dgvLayer.Rows[e.RowIndex];
row.Cells[e.ColumnIndex].Value = !(bool)row.Cells[e.ColumnIndex].Value;
}
}
}
}
6 changes: 6 additions & 0 deletions Source/DotSpatial.Plugins.ShapeEditor/SnapSettingsDialog.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="dgvcSnappable.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="dgvcLayerName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using DotSpatial.Controls;
using DotSpatial.Data;
using DotSpatial.Symbology;
Expand Down Expand Up @@ -97,7 +98,7 @@ protected bool ComputeSnappedLocation(GeoMouseArgs e, ref Coordinate snappedCoor

Envelope env = pix.ToEnvelope();

foreach (IFeatureLayer layer in SnapLayers)
foreach (IFeatureLayer layer in SnapLayers.Where(_ => _.Snappable && _.IsVisible))
{
foreach (IFeature feat in layer.DataSet.Features)
{
Expand Down
9 changes: 9 additions & 0 deletions Source/DotSpatial.Symbology/FeatureLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,14 @@ public virtual bool ShowLabels
}
}

/// <summary>
/// Gets or sets a value indicating whether this layer can be used for snapping.
/// </summary>
[Category("Behavior")]
[Description("Gets or sets a value indicating whether this layer can be used for snapping.")]
[Serialize("Snappable")]
public bool Snappable { get; set; }

/// <summary>
/// Gets or sets and interface for the shared symbol characteristics between point, line and polygon features
/// </summary>
Expand Down Expand Up @@ -1709,6 +1717,7 @@ private void Configure(IFeatureSet featureSet)
{
_categoryExtents = new Dictionary<IFeatureCategory, Extent>();
DrawingBounds = new Rectangle(-32000, -32000, 64000, 64000);
Snappable = true;
DataSet = featureSet;
LegendText = featureSet.Name;
Name = featureSet.Name;
Expand Down
7 changes: 7 additions & 0 deletions Source/DotSpatial.Symbology/IFeatureLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ public interface IFeatureLayer : ILayer
[Description("Gets or sets whether labels should be drawn.")]
bool ShowLabels { get; set; }

/// <summary>
/// Gets or sets a value indicating whether this layer can be used for snapping.
/// </summary>
[Category("Behavior")]
[Description("Gets or sets a value indicating whether this layer can be used for snapping.")]
bool Snappable { get; set; }

/// <summary>
/// Gets or sets and interface for the shared symbol characteristics between point, line and polygon features
/// </summary>
Expand Down

0 comments on commit fdf6baf

Please sign in to comment.