Ejemplo n.º 1
0
 public void InvokeElementSizeChanged(DragThumb element, SizeChangedEventArgs e)
 {
     if (ElementSizeChanged != null)
     {
         ElementSizeChanged(element, e);
     }
 }
Ejemplo n.º 2
0
 internal void UpdateNameLabelPosition()
 {
     if (nameLabel != null)
     {
         ((VirtualReferentialThumb)nameLabel.ReferentialElement).CanvasPosition = GetOptimalNameLabelPos().Value;
         DragThumb.UpdatePos(nameLabel);
     }
 }
Ejemplo n.º 3
0
        public VisualAidsAdorner(XCaseCanvas designerCanvas, DragThumb draggedObject)
            : base(designerCanvas)
        {
            this.draggedObject = (IAlignable)draggedObject;

            foreach (object element in designerCanvas.Children)
            {
                if (element is IAlignable && draggedObject != element)
                {
                    otherVisualAidsPoints.AddRange((element as IAlignable).GetVisualAidsPoints());
                }
            }
        }
Ejemplo n.º 4
0
        /// <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);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Updates the x and y coordinates of an element
        /// </summary>
        /// <param name="element">The element whose position is updated</param>
        internal static void UpdatePos(ISnappable element)
        {
            if (element is DragThumb)
            {
                DragThumb thumb = (DragThumb)element;
                double    _x    = Canvas.GetLeft(thumb);
                double    _y    = Canvas.GetTop(thumb);
                switch (thumb.Placement)
                {
                case EPlacementKind.AbsoluteCanvas:
                case EPlacementKind.ParentAutoPos:
                case EPlacementKind.AbsoluteSubCanvas:
                    Canvas.SetLeft(thumb, thumb.X);
                    Canvas.SetTop(thumb, thumb.Y);
                    break;

                case EPlacementKind.RelativeCanvas:
                    if (thumb.ReferentialElement != null)
                    {
                        Canvas.SetLeft(thumb, thumb.X + thumb.ReferentialElement.CanvasPosition.X);
                        Canvas.SetTop(thumb, thumb.Y + thumb.ReferentialElement.CanvasPosition.Y);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                if (_x != Canvas.GetLeft(thumb) || _y != Canvas.GetTop(thumb))
                {
                    ((DragThumb)element).InvokePositionChanged();
                    ((DragThumb)element).FellowTravellersUpdate();
                }
            }
            else
            {
                Canvas.SetLeft((UIElement)element, element.SnapOffsetX + element.ReferentialElement.CanvasPosition.X);
                Canvas.SetTop((UIElement)element, element.SnapOffsetY + element.ReferentialElement.CanvasPosition.Y);
            }
        }
Ejemplo n.º 6
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();
                }
            }
        }
Ejemplo n.º 7
0
 void updateLayout(DragThumb element, SizeChangedEventArgs e)
 {
     updateLayout();
 }