Esempio n. 1
0
        /// <summary>
        /// Finalizes dragging of a line segment.
        /// </summary>
        /// <param name="e">The <see cref="T:System.Windows.Input.MouseButtonEventArgs"/> that contains the event data. The event data reports that the mouse button was released.</param>
        /// <seealso cref="AutoPosModeOnly"/>
        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            if (segmentDragging)
            {
                segmentDragging = false;

                JunctionPointCommand.PointMoveDataDictionary pointMoveDataCollection =
                    new JunctionPointCommand.PointMoveDataDictionary();
                foreach (KeyValuePair <DragThumb, rPoint> pair in startPositions)
                {
                    JunctionPoint junctionPoint = (JunctionPoint)pair.Key;

                    if (junctionPoint.Position == pair.Value)
                    {
                        continue;
                    }

                    JunctionPointCommand.PointMoveData data = new JunctionPointCommand.PointMoveData
                    {
                        Index       = junctionPoint.OrderInJunction,
                        OldPosition = pair.Value,
                        NewPosition =
                            new rPoint(junctionPoint.Position)
                        {
                            tag = junctionPoint.Placement
                        },
                    };

                    if (!pointMoveDataCollection.ContainsKey(viewHelperPointsCollection))
                    {
                        pointMoveDataCollection[viewHelperPointsCollection] = new List <JunctionPointCommand.PointMoveData>();
                    }
                    pointMoveDataCollection[viewHelperPointsCollection].Add(data);
                }

                if (pointMoveDataCollection.Count > 0)
                {
                    JunctionPointCommand junctionPointCommand =
                        (JunctionPointCommand)JunctionPointCommandFactory.Factory().Create(XCaseCanvas.Controller);
                    junctionPointCommand.Action = JunctionPointCommand.EJunctionPointAction.MovePoints;
                    junctionPointCommand.PointMoveDataCollection = pointMoveDataCollection;
                    junctionPointCommand.Description             = CommandDescription.MOVE_JUNCTION_SEGMENT;
                    junctionPointCommand.Execute();
                }
            }
            this.ReleaseMouseCapture();
            base.OnMouseUp(e);
        }
Esempio n. 2
0
        /// <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();
                }
            }
        }