/// <summary>
        /// Performs custom actions on adaptable control MouseUp events; base method should
        /// be called first</summary>
        /// <param name="sender">Adaptable control</param>
        /// <param name="e">Event args</param>
        protected override void OnMouseUp(object sender, MouseEventArgs e)
        {
            base.OnMouseUp(sender, e);

            if (e.Button == MouseButtons.Left)
            {
                if (m_draggingNodes != null)
                {
                    if (m_initiated)
                    {
                        ITransactionContext transactionContext = AdaptedControl.ContextAs <ITransactionContext>();
                        transactionContext.DoTransaction(delegate
                        {
                            foreach (IItemDragAdapter itemDragAdapter in AdaptedControl.AsAll <IItemDragAdapter>())
                            {
                                itemDragAdapter.EndDrag();
                            }
                        }, "Drag Items".Localize());

                        m_initiated = false;
                    }

                    AdaptedControl.Invalidate();
                }

                if (m_autoTranslateAdapter != null)
                {
                    m_autoTranslateAdapter.Enabled = false;
                }
            }
        }
Exemplo n.º 2
0
 private void Invalidate()
 {
     if (AdaptedControl != null)
     {
         AdaptedControl.Invalidate();
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Does the work of connecting and disconnecting wires. Is called by OnMouseUp(),
        /// but clients may want to call it from OnMouseClick().</summary>
        /// <param name="e">Mouse event arguments</param>
        protected void DoMouseClick(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left &&
                ((Control.ModifierKeys & Keys.Alt) == 0))
            {
                if (!m_isConnecting)
                {
                    ConnectWires(e);
                }
                else
                {
                    // Attempt to complete the connection
                    if (m_dragEdgeReversed)
                    {
                        if (CanConnectTo())
                        {
                            m_draggingContext.DisconnectEdge = GetDisconnectEdgeTo();
                        }
                    }
                    else
                    {
                        if (CanConnectFrom())
                        {
                            m_draggingContext.DisconnectEdge = GetDisconnectEdgeFrom();
                        }
                    }

                    // make sure drag changed the edge
                    if (m_draggingContext.ExistingEdge == null || // this is a new edge
                        m_draggingContext.ExistingEdge.ToNode != m_draggingContext.DragToNode ||
                        m_draggingContext.ExistingEdge.ToRoute != m_draggingContext.DragToRoute ||
                        m_draggingContext.ExistingEdge.FromNode != m_draggingContext.DragFromNode ||
                        m_draggingContext.ExistingEdge.FromRoute != m_draggingContext.DragFromRoute)
                    {
                        ITransactionContext transactionContext = AdaptedControl.ContextAs <ITransactionContext>();
                        transactionContext.DoTransaction(MakeConnection, "Drag Edge".Localize());
                    }

                    if (m_autoTranslateAdapter != null)
                    {
                        m_autoTranslateAdapter.Enabled = false;
                    }

                    m_isConnecting = false;
                    m_draggingContext.DragFromNode   = null;
                    m_draggingContext.DragFromRoute  = null;
                    m_draggingContext.DragToNode     = null;
                    m_draggingContext.DragToRoute    = null;
                    m_draggingContext.ExistingEdge   = null;
                    m_draggingContext.DisconnectEdge = null;
                    m_graphAdapter.HideEdge(null);

                    AdaptedControl.AutoResetCursor = true;
                    AdaptedControl.Cursor          = m_oldCursor;
                    m_renderer.RouteConnecting     = null;

                    AdaptedControl.Invalidate();
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.MouseUp"></see> event. Performs custom actions on MouseUp event.</summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs"></see> that contains the event data</param>
        protected override void OnMouseUp(object sender, MouseEventArgs e)
        {
            base.OnMouseUp(sender, e);

            if (e.Button == MouseButtons.Left)
            {
                if (Dragging())
                {
                    // Reset the positions to be their original values, before doing the transaction.
                    // The transaction will then record the correct before-and-after changes for undo/redo.
                    for (int i = 0; i < m_draggingItems.Length; i++)
                    {
                        m_layoutContext.SetBounds(m_draggingItems[i], m_originalBounds[i], BoundsSpecified.All);
                    }

                    var transactionContext = AdaptedControl.ContextAs <ITransactionContext>();
                    transactionContext.DoTransaction(UpdateBounds, "Resize States".Localize());

                    AdaptedControl.Invalidate();
                }

                if (m_autoTranslateAdapter != null)
                {
                    m_autoTranslateAdapter.Enabled = false;
                }
            }

            m_draggingItems = null;
            m_direction     = Direction.None;
        }
Exemplo n.º 5
0
        public void SetTransformInternal(float zoom, float xTranslation, float yTranslation)
        {
            bool transformChanged = false;

            if (_zoom != zoom)
            {
                _zoom            = zoom;
                transformChanged = true;
            }

            if (_translation.X != xTranslation || _translation.Y != xTranslation)
            {
                _translation     = new PointF(xTranslation, yTranslation);
                transformChanged = true;
            }

            if (transformChanged)
            {
                UpdateMatrices();
                TransformChanged.Raise(this, EventArgs.Empty);
                if (AdaptedControl != null)
                {
                    AdaptedControl.Invalidate();
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Performs custom actions when performing a mouse dragging operation</summary>
        /// <param name="e">Mouse move event args</param>
        protected override void OnDragging(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Point currentPoint = GdiUtil.InverseTransform(m_transformAdapter.Transform, CurrentPoint);
                Point fristPoint   = GdiUtil.InverseTransform(m_transformAdapter.Transform, FirstPoint);
                Point offset       = new Point(currentPoint.X - fristPoint.X, currentPoint.Y - fristPoint.Y);
                if (m_draggingNodes.Any())
                {
                    if (!offset.IsEmpty)
                    {
                        AdjustLayout(m_selectionContext.GetSelection <Element>(), m_draggingGroupPins, offset);
                    }
                }

                if (m_draggingGroupPins.Any() && offset.Y != 0)
                {
                    for (int i = 0; i < m_originalPinY.Length; i++)
                    {
                        m_draggingGroupPins[i].Bounds = new Rectangle(m_draggingGroupPins[i].Bounds.Location.X, Constrain(m_originalPinY[i] + offset.Y),
                                                                      m_draggingGroupPins[i].Bounds.Width, m_draggingGroupPins[i].Bounds.Height);
                    }
                    AdaptedControl.Invalidate();
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Ends the current label editing operation</summary>
        public void EndEdit()
        {
            m_labelEditTimer.Enabled = false;

            if (m_namingContext == null || m_item == null)
            {
                return;
            }

            if (!m_textBox.Visible)
            {
                return;
            }

            string text = m_textBox.Text;

            if (text != m_namingContext.GetName(m_item))
            {
                var transactionContext = AdaptedControl.ContextAs <ITransactionContext>();
                // check that some other transaction hasn't ended our edit
                if (transactionContext == null ||
                    !transactionContext.InTransaction)
                {
                    transactionContext.DoTransaction(delegate
                    {
                        m_namingContext.SetName(m_item, text);
                    }, "Edit Label".Localize());
                }
            }

            m_textBox.Visible = false;
            m_namingContext   = null;
            m_item            = null;
            AdaptedControl.Invalidate();
        }
Exemplo n.º 8
0
 private void Invalidate()
 {
     if (!IsDragging())// no need to invalidate when dragging.
     {
         AdaptedControl.Invalidate();
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Performs custom actions when performing a mouse dragging operation</summary>
        /// <param name="e">Mouse event args</param>
        protected override void OnDragging(MouseEventArgs e)
        {
            m_modifiers = Control.ModifierKeys;
            if (e.Button == MouseButtons.Left &&
                ((m_modifiers & ~m_modifierKeys) == 0))
            {
                // make sure we can capture the mouse
                if (!AdaptedControl.Capture)
                {
                    m_firstCanvasPoint = m_currentCanvasPoint = ClientToCanvas(FirstPoint);

                    IsSelecting = true;

                    AdaptedControl.Capture = true;
                    m_saveCursor           = AdaptedControl.Cursor;
                    AdaptedControl.Cursor  = Cursors.Cross;

                    if (m_autoTranslateAdapter != null)
                    {
                        m_autoTranslateAdapter.Enabled = true;
                    }
                }
            }

            if (IsSelecting)
            {
                AdaptedControl.Invalidate();
                m_currentCanvasPoint = ClientToCanvas(CurrentPoint);
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Performs custom actions when performing a mouse dragging operation</summary>
 /// <param name="e">Mouse event args</param>
 /// <remarks>If dragging, raises the DrawingD2d event.</remarks>
 protected override void OnDragging(MouseEventArgs e)
 {
     if (Dragging())
     {
         UpdateBounds();
         AdaptedControl.Invalidate();
     }
 }
Exemplo n.º 11
0
        private void SetHotEdge(TEdge hotEdge)
        {
            m_hotEdge = hotEdge;
            if (hotEdge != null)
            {
                m_graphAdapter.SetStyle(m_hotEdge, DiagramDrawingStyle.Hot);
            }

            if (AdaptedControl.Focused)
            {
                AdaptedControl.Invalidate();
            }
        }
Exemplo n.º 12
0
        private void ResetHotEdge()
        {
            if (m_hotEdge != null)
            {
                m_graphAdapter.ResetStyle(m_hotEdge);
                m_hotEdge = null;

                if (AdaptedControl.Focused)
                {
                    AdaptedControl.Invalidate();
                }
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Sets the transform to scale and translate. The scale is applied first, so that subscribers
        /// to the TransformChanged event can change the translation constraint.</summary>
        /// <param name="xScale">X scale</param>
        /// <param name="yScale">Y scale</param>
        /// <param name="xTranslation">X translation</param>
        /// <param name="yTranslation">Y translation</param>
        public void SetTransform(float xScale, float yScale, float xTranslation, float yTranslation)
        {
            if (m_settingTransform)
            {
                return;
            }
            try
            {
                m_settingTransform = true;

                bool    transformChanged = false;
                float[] m = m_transform.Elements;

                PointF scale = EnforceConstraints ? this.ConstrainScale(new PointF(xScale, yScale)) : new PointF(xScale, yScale);
                if (m[0] != scale.X || m[3] != scale.Y)
                {
                    m_transform = new Matrix(scale.X, 0, 0, scale.Y, m_transform.OffsetX, m_transform.OffsetY);
                    OnTransformChanged(EventArgs.Empty);
                    TransformChanged.Raise(this, EventArgs.Empty);
                    transformChanged = true;
                }

                PointF translation = EnforceConstraints ? this.ConstrainTranslation(new PointF(xTranslation, yTranslation)) : new PointF(xTranslation, yTranslation);
                if (m[4] != translation.X || m[5] != translation.Y)
                {
                    m_transform = new Matrix(scale.X, 0, 0, scale.Y, translation.X, translation.Y);
                    OnTransformChanged(EventArgs.Empty);
                    TransformChanged.Raise(this, EventArgs.Empty);
                    transformChanged = true;
                }

                if (transformChanged)
                {
                    var d2dCtrl = AdaptedControl as D2dAdaptableControl;
                    if (d2dCtrl != null)
                    {
                        d2dCtrl.DrawD2d();
                    }
                    else if (AdaptedControl != null)
                    {
                        AdaptedControl.Invalidate();
                    }
                }
            }
            finally
            {
                m_settingTransform = false;
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Ends dragging any selected items managed by the adapter. May be called
        /// by another adapter when it ends dragging.</summary>
        void IItemDragAdapter.EndDrag()
        {
            int i = 0;

            foreach (IAnnotation annotation in m_draggingAnnotations)
            {
                MoveAnnotation(annotation, m_newPositions[i]);
                i++;
            }

            m_draggingAnnotations = null;
            m_annotationSet       = null;
            m_newPositions        = null;
            m_oldPositions        = null;

            AdaptedControl.Invalidate();
        }
Exemplo n.º 15
0
 /// <summary>
 /// Performs custom actions on PreviewKeyDown events</summary>
 /// <param name="sender">Sender</param>
 /// <param name="e"> PreviewKeyDown event args</param>
 void textBox_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
 {
     if (e.KeyData == Keys.Escape)
     {
         if (m_namingContext != null && m_item != null)
         {
             m_textBox.Text = m_namingContext.GetName(m_item);
             EndEdit();
             AdaptedControl.Invalidate();
         }
     }
     else
     {
         if (e.KeyData == Keys.Enter)
         {
             EndEdit();
         }
     }
 }
Exemplo n.º 16
0
        /// <summary>
        /// Performs custom actions on adaptable control MouseUp events; base method should
        /// be called first</summary>
        /// <param name="sender">Adaptable control</param>
        /// <param name="e">Event args</param>
        protected override void OnMouseUp(object sender, MouseEventArgs e)
        {
            base.OnMouseUp(sender, e);

            if (IsSelecting)
            {
                Rectangle rect = MakeSelectionRect(m_currentCanvasPoint, m_firstCanvasPoint);
                RaiseSelected(rect, m_modifiers);

                IsSelecting            = false;
                AdaptedControl.Cursor  = m_saveCursor;
                AdaptedControl.Capture = false;

                if (m_autoTranslateAdapter != null)
                {
                    m_autoTranslateAdapter.Enabled = false;
                }

                // In case nothing was selected, we need to make sure that the rectangle is cleared.
                AdaptedControl.Invalidate();
            }
        }
        /// <summary>
        /// Performs custom actions when performing a mouse dragging operation</summary>
        /// <param name="e">Mouse move event args</param>
        protected override void OnDragging(MouseEventArgs e)
        {
            if (m_layoutContext != null &&
                !m_isDragging)
            {
                ResetHotNode();

                if (e.Button == MouseButtons.Left &&
                    ((Control.ModifierKeys & Keys.Alt) == 0) &&
                    !AdaptedControl.Capture)
                {
                    {
                        m_firstPoint = GdiUtil.InverseTransform(m_transformAdapter.Transform, FirstPoint);
                        m_mousePick  = m_graphAdapter.Pick(FirstPoint);
                        if (m_mousePick.Node != null)
                        {
                            m_initiated = true;

                            foreach (IItemDragAdapter itemDragAdapter in AdaptedControl.AsAll <IItemDragAdapter>())
                            {
                                itemDragAdapter.BeginDrag(this);
                            }

                            AdaptedControl.Capture = true;

                            if (m_autoTranslateAdapter != null)
                            {
                                m_autoTranslateAdapter.Enabled = true;
                            }
                        }
                    }
                }
            }

            if (m_draggingNodes != null)
            {
                AdaptedControl.Invalidate();
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Performs custom actions when ending a mouse dragging operation</summary>
        /// <param name="e">Mouse event args</param>
        protected override void OnEndDrag(MouseEventArgs e)
        {
            base.OnEndDrag(e);
            if (m_draggingNodes != null && m_draggingNodes.Length > 0)
            {
                foreach (var draggingNode in m_draggingNodes)
                {
                    ResetCustomStyle(draggingNode);
                }

                foreach (IItemDragAdapter itemDragAdapter in AdaptedControl.AsAll <IItemDragAdapter>())
                {
                    itemDragAdapter.EndingDrag(); //call ourselves, too
                }
                var transactionContext = AdaptedControl.ContextAs <ITransactionContext>();
                transactionContext.DoTransaction(delegate
                {
                    foreach (IItemDragAdapter itemDragAdapter in AdaptedControl.AsAll <IItemDragAdapter>())
                    {
                        itemDragAdapter.EndDrag();         //call ourselves, too
                    }
                }, "Drag Items".Localize());

                if (m_autoTranslateAdapter != null)
                {
                    m_autoTranslateAdapter.Enabled = false;
                }
                AdaptedControl.Invalidate();
            }
            m_draggingNodes = null;
            m_newPositions  = null;
            m_oldPositions  = null;
            ResetCustomStyle(m_targetItem);
            m_targetItem          = null;
            m_resizing            = false;
            AdaptedControl.Cursor = Cursors.Default;
        }
Exemplo n.º 19
0
        /// <summary>
        /// Performs custom actions when performing a mouse dragging operation</summary>
        /// <param name="e">Mouse event args</param>
        protected override void OnDragging(MouseEventArgs e)
        {
            if (m_layoutContext != null &&
                m_draggingAnnotations == null)
            {
                if (e.Button == MouseButtons.Left &&
                    ((Control.ModifierKeys & Keys.Alt) == 0) &&
                    !AdaptedControl.Capture)
                {
                    {
                        m_mousePick = Pick(FirstPoint);
                        if (m_mousePick.Item != null)
                        {
                            m_initiated = true;

                            foreach (IItemDragAdapter itemDragAdapter in AdaptedControl.AsAll <IItemDragAdapter>())
                            {
                                itemDragAdapter.BeginDrag(this);
                            }

                            AdaptedControl.Capture = true;

                            if (m_autoTranslateAdapter != null)
                            {
                                m_autoTranslateAdapter.Enabled = true;
                            }
                        }
                    }
                }
            }

            if (m_draggingAnnotations != null)
            {
                AdaptedControl.Invalidate();
            }
        }
Exemplo n.º 20
0
 private void Invalidate()
 {
     AdaptedControl.Invalidate();
 }
Exemplo n.º 21
0
 private void theme_Redraw(object sender, EventArgs e)
 {
     AdaptedControl.Invalidate();
 }
Exemplo n.º 22
0
        private void ConnectWires(MouseEventArgs e)
        {
            if (m_mainEditableGraph != null &&
                !m_isConnecting)
            {
                if (e.Button == MouseButtons.Left &&
                    ((Control.ModifierKeys & Keys.Alt) == 0) &&
                    !AdaptedControl.Capture)
                {
                    // reset dragging context
                    m_draggingContext.DisconnectEdge = null;
                    m_draggingContext.DragFromNode   = null;
                    m_draggingContext.DragToNode     = null;
                    m_draggingContext.DragFromRoute  = null;
                    m_draggingContext.DragToRoute    = null;

                    m_mousePick = m_graphAdapter.Pick(FirstPoint);
                    if (m_mousePick.Node != null)
                    {
                        Cursor cursor = AdaptedControl.Cursor;
                        m_edgeDragPoint = FirstPoint;

                        //m_existingEdge = m_mousePick.Edge; // Don't pick wires under nodes

                        // reversed if dragging edge from its destination node's ToRoute(input pin)
                        // towards source node's FromRoute(output pin)
                        m_draggingContext.FromSourceToDestination = false;

                        // if no edge is picked but there are fan-in/out restrictions, try to drag an existing edge
                        if (m_draggingContext.ExistingEdge == null)
                        {
                            if (m_mousePick.FromRoute != null && !m_mousePick.FromRoute.AllowFanOut)
                            {
                                m_draggingContext.ExistingEdge = GetFirstEdgeFrom(m_draggingContext.ActualFromNode(), m_mousePick.FromRoute);
                            }
                            else if (m_mousePick.ToRoute != null && !m_mousePick.ToRoute.AllowFanIn)
                            {
                                m_draggingContext.ExistingEdge = GetFirstEdgeTo(m_draggingContext.ActualToNode(), m_mousePick.ToRoute);
                            }
                        }

                        TNode      startNode  = null;
                        TEdgeRoute startRoute = null;

                        if (m_mousePick.FromRoute != null) // favor dragging from source to destination
                        {
                            startNode = m_draggingContext.DragFromNode = m_mousePick.SubNode ?? m_mousePick.Node;
                            m_draggingContext.DragFromNodeHitPath = m_mousePick.HitPath;
                            startRoute = m_draggingContext.DragFromRoute = m_mousePick.FromRoute;
                            m_draggingContext.FromRoutePos = m_mousePick.FromRoutePos;

                            m_dragEdgeReversed = true;
                            m_draggingContext.FromSourceToDestination = true;
                            m_isConnecting = true;
                            cursor         = OverRouteCursor;
                        }
                        else if (m_mousePick.ToRoute != null)
                        {
                            startNode = m_draggingContext.DragToNode = m_mousePick.SubNode ?? m_mousePick.Node;
                            m_draggingContext.DragToNodeHitPath = m_mousePick.HitPath;
                            startRoute = m_draggingContext.DragToRoute = m_mousePick.ToRoute;
                            m_draggingContext.ToRoutePos = m_mousePick.ToRoutePos;
                            m_dragEdgeReversed           = false;
                            m_isConnecting = true;
                            cursor         = OverRouteCursor;
                        }

                        if (m_isConnecting)
                        {
                            m_oldCursor = AdaptedControl.Cursor;
                            AdaptedControl.AutoResetCursor = false;
                            AdaptedControl.Cursor          = cursor;
                            AdaptedControl.Capture         = true;
                            if (startNode != null)
                            {
                                var info = new D2dGraphRenderer <TNode, TEdge, TEdgeRoute> .RouteConnectingInfo()
                                {
                                    EditableGraph = DraggingContext.EditableGraph,
                                    StartNode     = startNode,
                                    StartRoute    = startRoute
                                };
                                m_renderer.RouteConnecting = info;
                            }
                            else
                            {
                                m_renderer.RouteConnecting = null;
                            }

                            if (m_autoTranslateAdapter != null)
                            {
                                m_autoTranslateAdapter.Enabled = true;
                            }
                        }
                    }
                    m_graphAdapter.HideEdge(m_draggingContext.ExistingEdge);
                }
            }

            if (m_isConnecting)
            {
                m_edgeDragPoint = CurrentPoint;
                m_mousePick     = m_graphAdapter.Pick(CurrentPoint);
                Cursor cursor;

                if (m_dragEdgeReversed)
                {
                    if (CanConnectTo())
                    {
                        m_draggingContext.DragToNode        = m_mousePick.SubNode ?? m_mousePick.Node;
                        m_draggingContext.DragToNodeHitPath = m_mousePick.HitPath;
                        m_draggingContext.DragToRoute       = m_mousePick.ToRoute;
                        m_draggingContext.ToRoutePos        = m_mousePick.ToRoutePos;
                        cursor = ToPlaceCursor;
                    }
                    else
                    {
                        m_draggingContext.DragToNode  = null;
                        m_draggingContext.DragToRoute = null;
                        cursor = InadmissibleCursor;
                    }
                }
                else
                {
                    if (CanConnectFrom())
                    {
                        m_draggingContext.DragFromNode        = m_mousePick.SubNode ?? m_mousePick.Node;
                        m_draggingContext.DragFromNodeHitPath = m_mousePick.HitPath;
                        m_draggingContext.DragFromRoute       = m_mousePick.FromRoute;
                        m_draggingContext.FromRoutePos        = m_mousePick.FromRoutePos;
                        cursor = FromPlaceCursor;
                    }
                    else
                    {
                        m_draggingContext.DragFromNode  = null;
                        m_draggingContext.DragFromRoute = null;
                        cursor = InadmissibleCursor;
                    }
                }

                AdaptedControl.AutoResetCursor = false;
                AdaptedControl.Cursor          = cursor;
                AdaptedControl.Invalidate();
                //var d2dControl = this.AdaptedControl as D2dAdaptableControl;
                //d2dControl.DrawD2d();
            }
        }
Exemplo n.º 23
0
 protected override void OnMouseMove(object sender, MouseEventArgs e)
 {
     base.OnMouseMove(sender, e);
     AdaptedControl.Invalidate();
 }
Exemplo n.º 24
0
 private void Invalidate()
 {
     m_cachedHitRecord = null;
     AdaptedControl.Invalidate();
 }
Exemplo n.º 25
0
        /// <summary>
        /// Performs custom actions on adaptable control MouseUp events; base method should
        /// be called first</summary>
        /// <param name="sender">Adaptable control</param>
        /// <param name="e">Event args</param>
        protected override void OnMouseUp(object sender, MouseEventArgs e)
        {
            base.OnMouseUp(sender, e);

            if (e.Button == MouseButtons.Left)
            {
                if (m_isDragging)
                {
                    if (m_existingEdge != null)
                    {
                        m_graphAdapter.ResetStyle(m_existingEdge);
                    }

                    if (m_disconnectEdge != null)
                    {
                        m_graphAdapter.ResetStyle(m_disconnectEdge);
                    }

                    // make sure drag changed the edge
                    if (m_existingEdge == null || // this is a new edge
                        m_existingEdge.ToNode != m_dragToNode ||
                        m_existingEdge.ToRoute != m_dragToRoute ||
                        m_existingEdge.FromNode != m_dragFromNode ||
                        m_existingEdge.FromRoute != m_dragFromRoute)
                    {
                        ITransactionContext transactionContext = AdaptedControl.ContextAs <ITransactionContext>();
                        TransactionContexts.DoTransaction(transactionContext,
                                                          delegate
                        {
                            // disconnect any existing edge on the node route
                            if (m_disconnectEdge != null)
                            {
                                m_editableGraph.Disconnect(m_disconnectEdge);
                            }

                            if (m_existingEdge != null)
                            {
                                m_editableGraph.Disconnect(m_existingEdge);
                            }

                            if (m_dragToNode != null &&
                                m_dragToRoute != null &&
                                m_dragFromNode != null &&
                                m_dragFromRoute != null)
                            {
                                m_editableGraph.Connect(
                                    m_dragFromNode,
                                    m_dragFromRoute,
                                    m_dragToNode,
                                    m_dragToRoute,
                                    m_existingEdge);
                            }
                        },
                                                          "Drag Edge".Localize());
                    }

                    AdaptedControl.Invalidate();
                }
            }

            if (m_autoTranslateAdapter != null)
            {
                m_autoTranslateAdapter.Enabled = false;
            }

            m_isDragging     = false;
            m_dragFromNode   = null;
            m_dragFromRoute  = null;
            m_dragToNode     = null;
            m_dragToRoute    = null;
            m_existingEdge   = null;
            m_disconnectEdge = null;

            AdaptedControl.Cursor = m_oldCursor;
        }
Exemplo n.º 26
0
 private void selectionContext_SelectionChanged(object sender, EventArgs e)
 {
     AdaptedControl.Invalidate();
 }
Exemplo n.º 27
0
        /// <summary>
        /// Performs custom actions when performing a mouse dragging operation</summary>
        /// <param name="e">Mouse move event args</param>
        protected override void OnDragging(MouseEventArgs e)
        {
            if (m_editableGraph != null &&
                !m_isDragging)
            {
                ResetHotEdge();

                if (e.Button == MouseButtons.Left &&
                    ((Control.ModifierKeys & Keys.Alt) == 0) &&
                    !AdaptedControl.Capture)
                {
                    {
                        m_mousePick = m_graphAdapter.Pick(FirstPoint);
                        if (m_mousePick.Node != null)
                        {
                            Cursor cursor = AdaptedControl.Cursor;
                            m_edgeDragPoint = FirstPoint;

                            m_existingEdge = m_mousePick.Edge;
                            bool reversed = m_mousePick.FromRoute == null; // TODO explain!

                            // if no edge is picked but there are fan-in/out restrictions, try to drag an existing edge
                            if (m_existingEdge == null)
                            {
                                if (m_mousePick.FromRoute != null && !m_mousePick.FromRoute.AllowFanOut)
                                {
                                    m_existingEdge = GetFirstEdgeFrom(m_mousePick.Node, m_mousePick.FromRoute);
                                    reversed       = false; // connecting "from-to"
                                }
                                else if (m_mousePick.ToRoute != null && !m_mousePick.ToRoute.AllowFanIn)
                                {
                                    m_existingEdge = GetFirstEdgeTo(m_mousePick.Node, m_mousePick.ToRoute);
                                    reversed       = true; // connecting "to-from"
                                }
                            }

                            if (m_existingEdge != null)
                            {
                                if (m_editableGraph.CanDisconnect(m_existingEdge))
                                {
                                    m_dragFromNode  = m_existingEdge.FromNode;
                                    m_dragFromRoute = m_existingEdge.FromRoute;
                                    m_dragToNode    = m_existingEdge.ToNode;
                                    m_dragToRoute   = m_existingEdge.ToRoute;

                                    m_graphAdapter.SetStyle(m_existingEdge, DiagramDrawingStyle.Ghosted);
                                    m_dragEdgeReversed = reversed;
                                    m_isDragging       = true;
                                    cursor             = Cursors.UpArrow;
                                }
                            }
                            else if (m_mousePick.FromRoute != null) // favor dragging from source to destination
                            {
                                m_dragFromNode     = m_mousePick.Node;
                                m_dragFromRoute    = m_mousePick.FromRoute;
                                m_dragEdgeReversed = true;
                                m_isDragging       = true;
                                cursor             = Cursors.UpArrow;
                            }
                            else if (m_mousePick.ToRoute != null)
                            {
                                m_dragToNode       = m_mousePick.Node;
                                m_dragToRoute      = m_mousePick.ToRoute;
                                m_dragEdgeReversed = false;
                                m_isDragging       = true;
                                cursor             = Cursors.UpArrow;
                            }

                            if (m_isDragging)
                            {
                                m_oldCursor            = AdaptedControl.Cursor;
                                AdaptedControl.Cursor  = cursor;
                                AdaptedControl.Capture = true;

                                if (m_autoTranslateAdapter != null)
                                {
                                    m_autoTranslateAdapter.Enabled = true;
                                }
                            }
                        }
                    }
                }
            }

            if (m_isDragging)
            {
                m_edgeDragPoint = CurrentPoint;
                m_mousePick     = m_graphAdapter.Pick(CurrentPoint);

                if (m_disconnectEdge != null)
                {
                    m_graphAdapter.ResetStyle(m_disconnectEdge);
                    m_disconnectEdge = null;
                }

                if (m_dragEdgeReversed)
                {
                    if (CanConnectTo())
                    {
                        m_dragToNode          = m_mousePick.Node;
                        m_dragToRoute         = m_mousePick.ToRoute;
                        m_disconnectEdge      = GetDisconnectEdgeTo();
                        AdaptedControl.Cursor = Cursors.UpArrow;
                    }
                    else
                    {
                        m_dragToNode          = null;
                        m_dragToRoute         = null;
                        AdaptedControl.Cursor = Cursors.No;
                    }
                }
                else
                {
                    if (CanConnectFrom())
                    {
                        m_dragFromNode        = m_mousePick.Node;
                        m_dragFromRoute       = m_mousePick.FromRoute;
                        m_disconnectEdge      = GetDisconnectEdgeFrom();
                        AdaptedControl.Cursor = Cursors.UpArrow;
                    }
                    else
                    {
                        m_dragFromNode        = null;
                        m_dragFromRoute       = null;
                        AdaptedControl.Cursor = Cursors.No;
                    }
                }

                if (m_disconnectEdge != null)
                {
                    m_graphAdapter.SetStyle(m_disconnectEdge, DiagramDrawingStyle.Ghosted);
                }

                AdaptedControl.Invalidate();
            }
        }