//-------------------------------------------------------------------------------------------------- #endregion #region Selection void _OnSelectionChanged(ToolAction toolAction) { if (CurrentTool != null) { return; } if (_MoveAction != null) { _MoveAction.Stop(); _MoveAction = null; } _UpdateSelections(); if (SelectedSegments.Any() || SelectedPoints.Any()) { _MoveAction = new MoveSketchPointAction(this); if (!WorkspaceController.StartToolAction(_MoveAction, false)) { return; } _MoveAction.Previewed += _OnMoveActionPreview; _MoveAction.Finished += _OnMoveActionFinished; var segPoints = SelectedSegments.SelectMany(seg => seg.Points); _MoveAction.SetSketchElements(Sketch, SelectedPoints.Union(segPoints).ToList()); } WorkspaceController.Invalidate(); }
//-------------------------------------------------------------------------------------------------- void _OnMoveActionFinished(ToolAction toolAction) { if (CurrentTool != null) { return; } if (!_MoveAction.Points.Any()) { // MoveAction has lost all it's point, stop it now _MoveAction.Stop(); _MoveAction = null; WorkspaceController.Invalidate(); return; } if (_MoveAction.MoveDelta.Magnitude() > 0) { Sketch.Points = new Dictionary <int, Pnt2d>(_ApplyMoveDelta(_MoveAction.Points, _MoveAction.MoveDelta)); // Check if points can be merged, and merge them var mergeCandidates = _MoveAction.CheckMergePoints(Vec2d.Zero); if (mergeCandidates.Any()) { var pointString = mergeCandidates.Select(mc => String.Format("({0},{1})", mc.Value, mc.Key)).ToList().Join(", "); if (MessageBox.Show(Application.Current.MainWindow, "Merge this points?\n " + pointString, "Merge points", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.Yes) { // Do merge foreach (var mc in mergeCandidates) { Sketch.MergePoints(mc.Value, mc.Key); } } } // Run solver Sketch.SolveConstraints(true); // Commit changes InteractiveContext.Current.UndoHandler.Commit(); } }