public void recordMoveFeature(SymbolFeature symbol, SymbolFeature newSymbol) { undoElementCurrent.moveSymbol(symbol, new SymbolFeature(symbol)); symbol.x = newSymbol.x; symbol.y = newSymbol.y; }
public void featureMoved(SymbolFeature actualFeatureMoved, SymbolFeature originalFeatureLocation) { operationType = UndoElementType.MoveFeature; this.feature = actualFeatureMoved; this.originalFeature = originalFeatureLocation; }
public void moveSymbol(SymbolFeature actualFeatureMoved, SymbolFeature originalFeatureLocation) { UndoElementPrimitive elem = new UndoElementPrimitive(); elem.featureMoved(actualFeatureMoved, originalFeatureLocation); undoPrimitives.Add(elem); }
/// <summary> /// Select all objects within the rectangle /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public override void MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { bool modified = false; base.MouseUp(sender, e); bool keyShift = ((System.Windows.Forms.Control.ModifierKeys & Keys.Shift) == Keys.Shift); bool keyControl = ((System.Windows.Forms.Control.ModifierKeys & Keys.Control) == Keys.Control); MapControl.Globals.Instance.MapControl.Cursor = Cursors.Arrow; if (ActiveRectangle.Width == 0 && ActiveRectangle.Height == 0) { relocateMode = false; rotateMode = false; rectSelectionMode = false; relocateModeAllowRelocation = false; DRect rect = calculateRectangleFromPoint(e.X, e.Y); List<DPoint> points = polylineLayer.SearchForPolylinePoints(rect); if (points.Count > 0) { if (points[0].Selected) { if (!keyControl && !keyShift) { polylineLayer.selectionClear(); points[0].Selected = true; MapControl.Globals.Instance.MapControl.InvalidateMap(); modified = true; } if (keyControl && !keyShift) { points[0].Selected = false; MapControl.Globals.Instance.MapControl.InvalidateMap(); modified = true; } } else { if (keyControl && !keyShift) { points[0].Selected = true; MapControl.Globals.Instance.MapControl.InvalidateMap(); modified = true; } } if (modified) { if (ToolUsed != null) ToolUsed(this, new EventArgs()); } return; } // select polyline // try to select an object List<Feature> features = polylineLayer.SearchForFeaturesColliding(rect); if (features.Count > 0) { if (features[0].Selected) { if (!keyControl && !keyShift) { polylineLayer.selectionClear(); features[0].Selected = true; modified = true; MapControl.Globals.Instance.MapControl.InvalidateMap(); } if (keyControl && !keyShift) { features[0].Selected = false; modified = true; MapControl.Globals.Instance.MapControl.InvalidateMap(); } } else { if (keyControl && !keyShift) { features[0].Selected = true; modified = true; MapControl.Globals.Instance.MapControl.InvalidateMap(); } } if (modified) { if (ToolUsed != null) ToolUsed(this, new EventArgs()); } return; } if (!keyControl && !keyShift) { polylineLayer.selectionClear(); modified = true; } } else { // Dragging done if (relocateMode && relocateModeAllowRelocation) { List<Feature> features = polylineLayer.selectionFeatures(); List<DPoint> points = polylineLayer.selectionPoints(true); // calculate delta... // mouse start: m_oMouseStart // mouse end: m_oMouseCurrent int dxi = m_oMouseStart.X - m_oMouseCurrent.X; int dyi = m_oMouseStart.Y - m_oMouseCurrent.Y; int pixelDelta = (int)Math.Sqrt(dxi * dxi + dyi * dyi); DRect r1 = calculateRectangleFromPoint(m_oMouseStart.X, m_oMouseStart.Y); DRect r2 = calculateRectangleFromPoint(m_oMouseCurrent.X, m_oMouseCurrent.Y); double dx = r2.X1 - r1.X1; double dy = r2.Y1 - r1.Y1; // store copy of original point for undo polylineLayer.Manager.startRecordingUndoElement(); symbolLayer.Manager.startRecordingUndoElement(); // move polylines for (int i = 0; i < points.Count; i++) { DPoint newPoint = new DPoint(points[i].X + dx, points[i].Y + dy); polylineLayer.Manager.recordMovePoint(points[i], newPoint); // find correcponding symbol in symbolLayer SymbolFeature symbol = (SymbolFeature)points[i].Tag; Debug.Assert(symbol != null); SymbolFeature newSymbol = new SymbolFeature(symbol.x + dx, symbol.y + dy); symbolLayer.Manager.recordMoveFeature(symbol, newSymbol); modified = true; } polylineLayer.Manager.stopRecordingUndoElement(); symbolLayer.Manager.stopRecordingUndoElement(); // refresh view MapControl.Globals.Instance.MapControl.InvalidateMap(); } if (rotateMode) { // rotation } if (rectSelectionMode) { if (!keyShift && !keyControl) { polylineLayer.selectionClear(); modified = true; /* // emit clear selection for all wpt-s for (int i = 0; i < symbolLayer.FeaturesCount; i++) { SymbolFeature symbol = symbolLayer.FeatureGet(i) as SymbolFeature; if (symbol != null) { //WptSelected(this, (symbol.Tag as GpxWpt), false); } }*/ } if (!keyControl) { System.Drawing.Rectangle r = ActiveRectangle; System.Drawing.Point p1 = new System.Drawing.Point(r.X, r.Y); System.Drawing.Point p2 = new System.Drawing.Point(r.X + r.Width, r.Y + r.Height); DPoint pt1, pt2; map.DisplayTransform.FromDisplay(p1, out pt1); map.DisplayTransform.FromDisplay(p2, out pt2); // convert mercator to wgs84 CoordConverter occ = new CoordConverter(); CoordSys oCSMercator = CoordSysFactory.CreateCoordSys(CoordSysType.Mercator, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); CoordSys oCSWGS84 = CoordSysFactory.CreateCoordSys(CoordSysType.LatLong, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); occ.Init(oCSMercator, oCSWGS84); occ.Convert(pt1.X, pt1.Y); DPoint dp1 = new DPoint(occ.X, occ.Y); occ.Convert(pt2.X, pt2.Y); DPoint dp2 = new DPoint(occ.X, occ.Y); DRect rect = new DRect(dp1.X, dp2.Y, dp2.X, dp1.Y); List<DPoint> points = polylineLayer.SearchForPolylinePoints(rect); for (int i = 0; i < points.Count; i++) { points[i].Selected = true; modified = true; } List<Feature> features = polylineLayer.SearchForFeaturesContained(rect); for (int i = 0; i < features.Count; i++) { features[i].Selected = true; modified = true; } MapControl.Globals.Instance.MapControl.InvalidateMap(); } } if (timer != null) { timer.Stop(); timer = null; } relocateMode = false; rotateMode = false; rectSelectionMode = false; relocateModeAllowRelocation = false; } if (modified) { if (ToolUsed != null) ToolUsed(this, new EventArgs()); } }