public override void SetTrackerSelection(TrackerFeature trackerFeature, bool select) { if (trackerFeature.Selected != select) { trackerFeature.Selected = select; if (null != VectorStyle) { if (select) { trackerFeature.Bitmap = TrackerSymbolHelper.GenerateComposite(new Pen(Color.Blue), new SolidBrush(Color.DarkBlue), VectorStyle.Symbol.Width, VectorStyle.Symbol.Height, 6, 6); } else { trackerFeature.Bitmap = TrackerSymbolHelper.GenerateComposite(new Pen(Color.Lime), new SolidBrush(Color.Green), VectorStyle.Symbol.Width, VectorStyle.Symbol.Height, 6, 6); } } } }
public void LineStringEditorCreationWithoutMapControlTest() { var mapControl = new MapControl(); mapControl.Map.ZoomToFit(new Envelope(new Coordinate(0, 0), new Coordinate(1000, 1000))); var lineStringEditor = new LineStringInteractor(null, sampleFeature, GetStyle(), null); Assert.AreEqual(null, lineStringEditor.TargetFeature); Assert.AreNotEqual(null, lineStringEditor.SourceFeature); // There are no default focused trackers var trackers = lineStringEditor.Trackers.Where(t => t.Selected); Assert.AreEqual(0, trackers.Count()); TrackerFeature tracker = lineStringEditor.Trackers[2]; Assert.AreNotEqual(null, tracker); Assert.AreEqual(20.0, tracker.Geometry.Coordinates[0].X); Assert.AreEqual(0.0, tracker.Geometry.Coordinates[0].Y); lineStringEditor.Start(); lineStringEditor.SetTrackerSelection(tracker, true); trackers = lineStringEditor.Trackers.Where(t => t.Selected); Assert.AreEqual(1, trackers.Count()); Assert.AreNotEqual(null, lineStringEditor.TargetFeature); Assert.AreNotEqual(lineStringEditor.SourceFeature, lineStringEditor.TargetFeature); }
private void FocusTracker(TrackerFeature trackFeature) { if (null == trackFeature) { return; } if (!((KeyToggleSelection) || (KeyExtendSelection))) { foreach (IFeatureInteractor featureInteractor in SelectedFeatureInteractors) { foreach (TrackerFeature trackerFeature in featureInteractor.Trackers) { featureInteractor.SetTrackerSelection(trackerFeature, false); } } } foreach (IFeatureInteractor featureInteractor in SelectedFeatureInteractors) { foreach (TrackerFeature trackerFeature in featureInteractor.Trackers) { if (trackerFeature == trackFeature) { if (KeyToggleSelection) { featureInteractor.SetTrackerSelection(trackFeature, !trackFeature.Selected); } else { featureInteractor.SetTrackerSelection(trackFeature, true); } } } } }
public override void OnMouseMove(Coordinate worldPosition, MouseEventArgs e) { if (IsMultiSelect) { //WORLDPOSITION = worldPosition; UpdateMultiSelection(worldPosition); DoDrawing(false); return; } if (MapControl.Tools.Any(t => t != this && t.IsBusy)) { return; //don't influence cursor when other tools are busy } Cursor cursor = null; foreach (IFeatureInteractor featureInteractor in SelectedFeatureInteractors) { TrackerFeature trackerFeature = featureInteractor.GetTrackerAtCoordinate(worldPosition); if (null != trackerFeature) { cursor = ((FeatureInteractor)featureInteractor).GetCursor(trackerFeature); } } if (null == cursor) { cursor = Cursors.Default; } MapControl.Cursor = cursor; }
public override Cursor GetCursor(TrackerFeature trackerFeature) { if (trackerFeature == AllTracker) { return(Cursors.SizeAll); } return(new Cursor(Assembly.GetExecutingAssembly().GetManifestResourceStream("SharpMap.Editors.Cursors.Move.cur"))); }
public override Cursor GetCursor(TrackerFeature trackerFeature) { if (Trackers[0] == trackerFeature) { // ReSharper disable AssignNullToNotNullAttribute return(new Cursor(Assembly.GetExecutingAssembly().GetManifestResourceStream("SharpMap.Editors.Cursors.Move.cur"))); // ReSharper restore AssignNullToNotNullAttribute } return(null); }
public override Cursor GetCursor(TrackerFeature trackerFeature) { if (Trackers[0] == trackerFeature) { // ReSharper disable AssignNullToNotNullAttribute return new Cursor(Assembly.GetExecutingAssembly().GetManifestResourceStream("SharpMap.Editors.Cursors.Move.cur")); // ReSharper restore AssignNullToNotNullAttribute } return null; }
public TrackerFeature GetTrackerAtCoordinate(Coordinate worldPos) { TrackerFeature trackerFeature = null; foreach (IFeatureInteractor featureInteractor in SelectedFeatureInteractors) { trackerFeature = featureInteractor.GetTrackerAtCoordinate(worldPos); if (null != trackerFeature) { break; } } return(trackerFeature); }
/// <summary> /// Sets the selected object in the selectTool. SetSelection supports also the toggling/extending the /// selected trackers. /// </summary> /// <param name="feature"></param> /// <param name="featureLayer"></param> /// <param name="trackerIndex"></param> /// <returns>A clone of the original object.</returns> /// special cases /// feature is ILineString or IPolygon and trackerIndex != 1 : user clicked an already selected /// features -> only selected tracker changes. private void SetSelection(IFeature feature, ILayer featureLayer, int trackerIndex) { if (null != feature) { // store selected trackers IList <int> featureTrackers = new List <int>(); for (int i = 0; i < TrackingLayer.DataSource.Features.Count; i++) { TrackerFeature trackerFeature = (TrackerFeature)TrackingLayer.DataSource.Features[i]; if (trackerFeature == feature) { featureTrackers.Add(i); } } // store selected objects AddSelection(featureLayer, feature, trackerIndex, true); } }
protected override void CreateTrackers() { if (SourceFeature == null || SourceFeature.Geometry == null) { return; } if (trackerSmallStart == null) { trackerSmallStart = TrackerSymbolHelper.GenerateSimple(new Pen(Color.Blue), new SolidBrush(Color.DarkBlue), 6, 6); trackerSmallEnd = TrackerSymbolHelper.GenerateSimple(new Pen(Color.Tomato), new SolidBrush(Color.Maroon), 6, 6); trackerSmall = TrackerSymbolHelper.GenerateSimple(new Pen(Color.Green), new SolidBrush(Color.Lime), 6, 6); selectedTrackerSmall = TrackerSymbolHelper.GenerateSimple(new Pen(Color.DarkMagenta), new SolidBrush(Color.Magenta), 6, 6); } Trackers.Clear(); Trackers.AddRange(CreateTrackersForGeometry(SourceFeature.Geometry)); AllTracker = new TrackerFeature(this, null, -1, null); }
public void MoveTrackerWithSelection() { var lineStringEditor = new LineStringInteractor(null, sampleFeature, GetStyle(), null); TrackerFeature tracker = lineStringEditor.Trackers[2]; // 20,0 tracker.Selected = true; lineStringEditor.Start(); lineStringEditor.MoveTracker(tracker, 0, 5); Assert.AreEqual(20, tracker.Geometry.Coordinates[0].X); Assert.AreEqual(5, tracker.Geometry.Coordinates[0].Y); // check if changed coordinate is NOT set to sampleFeature Assert.AreEqual(20, sampleFeature.Geometry.Coordinates[2].X); Assert.AreEqual(0, sampleFeature.Geometry.Coordinates[2].Y); // todo redesign .Stop //lineStringMutator.Stop(); //// check if changed coordinate IS set to sampleFeature //Assert.AreEqual(20, sampleFeature.Geometry.Coordinates[2].X); //Assert.AreEqual(5, sampleFeature.Geometry.Coordinates[2].Y); }
public virtual bool MoveTracker(TrackerFeature trackerFeature, double deltaX, double deltaY, SnapResult snapResult = null) { if (trackerFeature.Index == -1) { throw new ArgumentException("Can not find tracker; can not move."); } var handles = SelectedTrackerIndices.ToList(); if (handles.Count == 0) { return(false); // Do not throw exception, can occur in special cases when moving with CTRL toggle selection } if (FallOffPolicy != null) { FallOffPolicy.Move(TargetFeature.Geometry, trackers.Select(t => t.Geometry).ToList(), handles, trackerFeature.Index, deltaX, deltaY); } else { GeometryHelper.MoveCoordinate(TargetFeature.Geometry, trackerFeature.Index, deltaX, deltaY); TargetFeature.Geometry = TargetFeature.Geometry; // fire event GeometryHelper.MoveCoordinate(trackerFeature.Geometry, 0, deltaX, deltaY); trackerFeature.Geometry = trackerFeature.Geometry; // fire event } foreach (var topologyRule in FeatureRelationEditors) { topologyRule.UpdateRelatedFeatures(SourceFeature, TargetFeature.Geometry, handles); } return(true); }
public virtual bool MoveTracker(TrackerFeature trackerFeature, double deltaX, double deltaY, SnapResult snapResult = null) { if (trackerFeature.Index == -1) { throw new ArgumentException("Can not find tracker; can not move."); } var handles = SelectedTrackerIndices.ToList(); if (handles.Count == 0) { return false; // Do not throw exception, can occur in special cases when moving with CTRL toggle selection } if (FallOffPolicy != null) { FallOffPolicy.Move(TargetFeature.Geometry, trackers.Select(t => t.Geometry).ToList(), handles, trackerFeature.Index, deltaX, deltaY); } else { GeometryHelper.MoveCoordinate(TargetFeature.Geometry, trackerFeature.Index, deltaX, deltaY); TargetFeature.Geometry = TargetFeature.Geometry; // fire event GeometryHelper.MoveCoordinate(trackerFeature.Geometry, 0, deltaX, deltaY); trackerFeature.Geometry = trackerFeature.Geometry; // fire event } foreach (var topologyRule in FeatureRelationEditors) { topologyRule.UpdateRelatedFeatures(SourceFeature, TargetFeature.Geometry, handles); } return true; }
public override bool MoveTracker(TrackerFeature trackerFeature, double deltaX, double deltaY, SnapResult snapResult = null) { if (trackerFeature == AllTracker) { if (FallOffPolicy == null) { FallOffPolicy = new NoFallOffPolicy(); } var handles = TrackerIndices.ToList(); FallOffPolicy.Move(TargetFeature.Geometry, Trackers.Select(t => t.Geometry).ToList(), handles, -1, deltaX, deltaY); foreach (var topologyRule in FeatureRelationEditors) { topologyRule.UpdateRelatedFeatures(SourceFeature, TargetFeature.Geometry, handles); } return(true); } return(base.MoveTracker(trackerFeature, deltaX, deltaY, snapResult)); }
public virtual bool RemoveTracker(TrackerFeature trackerFeature) { if (trackerFeature.Index == -1) { return(false); } var newGeometry = GeometryHelper.RemoveCurvePoint(TargetFeature.Geometry, trackerFeature.Index, TargetFeature is IBranch); if (newGeometry == null) { return(false); } TargetFeature.Geometry = newGeometry; foreach (var topologyRule in FeatureRelationEditors) { topologyRule.UpdateRelatedFeatures(SourceFeature, TargetFeature.Geometry, SelectedTrackerIndices.ToList()); } return(true); }
public virtual Cursor GetCursor(TrackerFeature trackerFeature) { return(new Cursor(Assembly.GetExecutingAssembly().GetManifestResourceStream("SharpMap.Editors.Cursors.Move.cur"))); }
public virtual void SetTrackerSelection(TrackerFeature trackerFeature, bool select) { }
public override bool MoveTracker(TrackerFeature trackerFeature, double deltaX, double deltaY, SnapResult snapResult = null) { if (trackerFeature == AllTracker) { if (FallOffPolicy == null) { FallOffPolicy = new NoFallOffPolicy(); } var handles = TrackerIndices.ToList(); FallOffPolicy.Move(TargetFeature.Geometry, Trackers.Select(t => t.Geometry).ToList(), handles, -1, deltaX, deltaY); foreach (var topologyRule in FeatureRelationEditors) { topologyRule.UpdateRelatedFeatures(SourceFeature, TargetFeature.Geometry, handles); } return true; } return base.MoveTracker(trackerFeature, deltaX, deltaY, snapResult); }
public override void OnMouseDown(Coordinate worldPosition, MouseEventArgs e) { MapControl.SnapTool.Reset(); var selectTool = MapControl.SelectTool; IFeature oldSelectedFeature = null; IList <TrackerFeature> focusedTrackers = null; var trackerFeature = selectTool.GetTrackerAtCoordinate(worldPosition); if (trackerFeature != null) { oldSelectedFeature = trackerFeature.FeatureInteractor.SourceFeature; focusedTrackers = trackerFeature.FeatureInteractor.Trackers.Where(t => t.Selected).ToList(); } // Let the select tool handle the mouse event unless multiple Trackers have focus and // there is no key pressed. In this case the user expects to move the focused Trackers // and SelectTool will reset them if (!((trackerFeature != null && focusedTrackers.Count > 1) && (!selectTool.KeyToggleSelection) && (!selectTool.KeyExtendSelection) /* && (trackerFeature.Selected)*/)) { selectTool.OnMouseDown(worldPosition, e); // did we just deselect out only selected tracker? if (null != trackerFeature) { var focusedTrackersCount = trackerFeature.FeatureInteractor.Trackers.Count(t => t.Selected); if ((focusedTrackers.Count != focusedTrackersCount) && (0 == focusedTrackersCount)) { return; } } } if (e.Button != MouseButtons.Left) { return; } if (selectTool.SelectedFeatureInteractors.Count != 1) { return; } dragSource = null; if (selectTool.SelectedFeatureInteractors.Count == 1) { isBusy = true; var feature = selectTool.SelectedFeatureInteractors[0].SourceFeature; if (oldSelectedFeature != feature) { if (!selectTool.SelectedFeatureInteractors[0].AllowSingleClickAndMove()) { isBusy = false; return; } } if (!selectTool.SelectedFeatureInteractors[0].AllowMove()) { isBusy = false; return; } var featureProvider = selectTool.SelectedFeatureInteractors[0].Layer.DataSource; // IndexOf doesn't work on shape files; feature rows are recreated during each read int dragIndex = featureProvider.Features.IndexOf(feature); if (dragIndex == -1) { isBusy = false; return; } dragSource = StartDragging(worldPosition, feature); // featureProvider.GetFeature(dragIndex)); if (dragSource == null) { isBusy = false; return; } } else { return; } LastMouseLocation = worldPosition; MouseDownLocation = worldPosition; snappingSource = null; var list = selectTool.SelectedFeatureInteractors[0].Trackers.Where(t => t.Selected).ToList(); if (list.Count == 0) { return; } if (list.Count == 1) { snappingSource = list.First(); } }
public override void SetTrackerSelection(TrackerFeature trackerFeature, bool select) { trackerFeature.Selected = select; trackerFeature.Bitmap = select ? selectedTrackerSmall : trackerSmall; }
public override bool MoveTracker(TrackerFeature trackerFeature, double deltaX, double deltaY, SnapResult snapResult) { moving = true; return(base.MoveTracker(trackerFeature, deltaX, deltaY, snapResult)); }
public virtual bool RemoveTracker(TrackerFeature trackerFeature) { if (trackerFeature.Index == -1) { return false; } var newGeometry = GeometryHelper.RemoveCurvePoint(TargetFeature.Geometry, trackerFeature.Index, TargetFeature is IBranch); if (newGeometry == null) { return false; } TargetFeature.Geometry = newGeometry; foreach (var topologyRule in FeatureRelationEditors) { topologyRule.UpdateRelatedFeatures(SourceFeature, TargetFeature.Geometry, SelectedTrackerIndices.ToList()); } return true; }
public override void OnMouseDown(ICoordinate worldPosition, MouseEventArgs e) { MapControl.SnapTool.Reset(); var selectTool = MapControl.SelectTool; IFeature oldSelectedFeature = null; IList<TrackerFeature> focusedTrackers = null; var trackerFeature = selectTool.GetTrackerAtCoordinate(worldPosition); if (trackerFeature != null) { oldSelectedFeature = trackerFeature.FeatureInteractor.SourceFeature; focusedTrackers = trackerFeature.FeatureInteractor.Trackers.Where(t => t.Selected).ToList(); } // Let the select tool handle the mouse event unless multiple Trackers have focus and // there is no key pressed. In this case the user expects to move the focused Trackers // and SelectTool will reset them if (!((trackerFeature != null && focusedTrackers.Count > 1) && (!selectTool.KeyToggleSelection) && (!selectTool.KeyExtendSelection)/* && (trackerFeature.Selected)*/)) { selectTool.OnMouseDown(worldPosition, e); // did we just deselect out only selected tracker? if (null != trackerFeature) { var focusedTrackersCount = trackerFeature.FeatureInteractor.Trackers.Count(t => t.Selected); if ((focusedTrackers.Count != focusedTrackersCount) && (0 == focusedTrackersCount)) { return; } } } if (e.Button != MouseButtons.Left) { return; } if (selectTool.SelectedFeatureInteractors.Count != 1) { return; } dragSource = null; if (selectTool.SelectedFeatureInteractors.Count == 1) { isBusy = true; var feature = selectTool.SelectedFeatureInteractors[0].SourceFeature; if (oldSelectedFeature != feature) { if (!selectTool.SelectedFeatureInteractors[0].AllowSingleClickAndMove()) { isBusy = false; return; } } if (!selectTool.SelectedFeatureInteractors[0].AllowMove()) { isBusy = false; return; } var featureProvider = selectTool.SelectedFeatureInteractors[0].Layer.DataSource; // IndexOf doesn't work on shape files; feature rows are recreated during each read int dragIndex = featureProvider.Features.IndexOf(feature); if (dragIndex == -1) { isBusy = false; return; } dragSource = StartDragging(worldPosition, featureProvider.GetFeature(dragIndex)); if (dragSource == null) { isBusy = false; return; } } else { return; } LastMouseLocation = worldPosition; MouseDownLocation = worldPosition; snappingSource = null; var list = selectTool.SelectedFeatureInteractors[0].Trackers.Where(t => t.Selected).ToList(); if (list.Count == 0) { return; } if (list.Count == 1) { snappingSource = list.First(); } }
public virtual Cursor GetCursor(TrackerFeature trackerFeature) { return new Cursor(Assembly.GetExecutingAssembly().GetManifestResourceStream("SharpMap.Editors.Cursors.Move.cur")); }
private void FocusTracker(TrackerFeature trackFeature) { if (null == trackFeature) return; if (!((KeyToggleSelection) || (KeyExtendSelection))) { foreach (IFeatureInteractor featureInteractor in SelectedFeatureInteractors) { foreach (TrackerFeature trackerFeature in featureInteractor.Trackers) { featureInteractor.SetTrackerSelection(trackerFeature, false); } } } foreach (IFeatureInteractor featureInteractor in SelectedFeatureInteractors) { foreach (TrackerFeature trackerFeature in featureInteractor.Trackers) { if (trackerFeature == trackFeature) { if (KeyToggleSelection) { featureInteractor.SetTrackerSelection(trackFeature, !trackFeature.Selected); } else { featureInteractor.SetTrackerSelection(trackFeature, true); } } } } }
public override Cursor GetCursor(TrackerFeature trackerFeature) { if (trackerFeature == AllTracker) { return Cursors.SizeAll; } return new Cursor(Assembly.GetExecutingAssembly().GetManifestResourceStream("SharpMap.Editors.Cursors.Move.cur")); }