/// <summary> /// Called when dragging starts, stores old positions of the dragged element /// </summary> protected virtual void DragStarted() { startPositions = new Dictionary <DragThumb, rPoint>(); if (!(this is ISelectable) || !XCaseCanvas.SelectedItems.Contains(this as ISelectable)) { startPositions.Add(this, new rPoint(this.Left, this.Top)); } else { foreach (ISelectable item in XCaseCanvas.SelectedItems) { if (item.CanBeDraggedInGroup || DraggingAllone(item)) { DragThumb thumb = item as DragThumb; if (thumb != null) { startPositions.Add(thumb, new rPoint(thumb.Position) { tag = thumb.Placement }); } else { throw new InvalidOperationException( string.Format("Dragging is implemented only for DragThumb and descendants. Object {0} of type {1} does not derive from DrugThumb. ", item, item.GetType())); } } } } if (this is IAlignable) { AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(XCaseCanvas); visualAidsAdorner = new VisualAidsAdorner(XCaseCanvas, this); adornerLayer.Add(visualAidsAdorner); } }
/// <summary> /// Drags the completed. /// </summary> /// <param name="finalPoint">The final point.</param> /// <param name="totalShift">The total shift.</param> protected virtual void DragCompleted(Point finalPoint, Vector totalShift) { if (visualAidsAdorner != null) { AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(XCaseCanvas); adornerLayer.Remove(visualAidsAdorner); visualAidsAdorner = null; } if (DragStartPoint != finalPoint) { DiagramController controller = XCaseCanvas.Controller; MacroCommand <DiagramController> moveMacroCommand = MacroCommandFactory <DiagramController> .Factory().Create(controller); moveMacroCommand.Description = CommandDescription.MOVE_MACRO; JunctionPointCommand.PointMoveDataDictionary pointMoveDataCollection = null; foreach (KeyValuePair <DragThumb, rPoint> pair in startPositions) { if (pair.Key is IAlignable) { IAlignable element = (IAlignable)pair.Key; DragThumb dragThumb = element as DragThumb; double _x; double _y; if (dragThumb != null && dragThumb.Placement == EPlacementKind.RelativeCanvas) { _x = dragThumb.Left - dragThumb.ReferentialElement.CanvasPosition.X; _y = dragThumb.Top - dragThumb.ReferentialElement.CanvasPosition.Y; } else { _x = element.Left; _y = element.Top; } CommandBase command = ViewController.CreateMoveCommand( _x, _y, element.ViewHelper, controller); moveMacroCommand.Commands.Add(command); } else if (pair.Key is JunctionPoint) { JunctionPoint junctionPoint = (JunctionPoint)pair.Key; JunctionPointCommand.PointMoveData data = new JunctionPointCommand.PointMoveData { Index = junctionPoint.OrderInJunction, OldPosition = pair.Value, NewPosition = new rPoint(junctionPoint.Position) { tag = junctionPoint.Placement }, }; if (pointMoveDataCollection == null) { pointMoveDataCollection = new JunctionPointCommand.PointMoveDataDictionary(); } if (!pointMoveDataCollection.ContainsKey(junctionPoint.Junction.viewHelperPointsCollection)) { pointMoveDataCollection[junctionPoint.Junction.viewHelperPointsCollection] = new List <JunctionPointCommand.PointMoveData>(); } pointMoveDataCollection[junctionPoint.Junction.viewHelperPointsCollection].Add(data); } } // add one command for each affected junction if (pointMoveDataCollection != null) { JunctionPointCommand junctionPointCommand = (JunctionPointCommand)JunctionPointCommandFactory.Factory().Create(controller); junctionPointCommand.Action = JunctionPointCommand.EJunctionPointAction.MovePoints; junctionPointCommand.PointMoveDataCollection = pointMoveDataCollection; junctionPointCommand.Description = CommandDescription.MOVE_JUNCTION_POINTS; moveMacroCommand.Commands.Add(junctionPointCommand); } moveMacroCommand.Execute(); if (Dropped != null) { Dropped(); } } }