Esempio n. 1
0
 /// <summary>
 /// Constructor</summary>
 /// <param name="renderer">Graph renderer to draw and hit-test graph</param>
 /// <param name="transformAdapter">Transform adapter</param>
 public D2dGraphAdapter(D2dGraphRenderer <TNode, TEdge, TEdgeRoute> renderer,
                        ITransformAdapter transformAdapter)
 {
     m_renderer          = renderer;
     m_renderer.Redraw  += renderer_Redraw;
     m_renderer.GetStyle = GetStyle;
 }
Esempio n. 2
0
 /// <summary>
 /// Constructor</summary>
 /// <param name="renderer">Graph renderer to draw and hit-test graph</param>
 /// <param name="transformAdapter">Transform adapter</param>
 public D2dGraphAdapter(D2dGraphRenderer <TNode, TEdge, TEdgeRoute> renderer,
                        ITransformAdapter transformAdapter)
 {
     m_renderer         = renderer;
     m_renderer.Redraw += renderer_Redraw;
     EdgeRenderPolicy   = DrawEdgePolicy.AllFirst;
 }
Esempio n. 3
0
 /// <summary>
 /// Constructor</summary>
 /// <param name="renderer">Graph renderer to draw and hit-test graph</param>
 /// <param name="transformAdapter">Transform adapter</param>
 public D2dGraphAdapter(D2dGraphRenderer <TNode, TEdge, TEdgeRoute> renderer,
                        ITransformAdapter transformAdapter)
 {
     m_renderer          = renderer;
     m_renderer.Redraw  += new EventHandler(renderer_Redraw);
     m_transformAdapter  = transformAdapter;
     m_renderer.GetStyle = GetStyle;
 }
Esempio n. 4
0
 /// <summary>
 /// Constructor</summary>
 /// <param name="renderer">Graph renderer</param>
 /// <param name="graphAdapter">Graph adapter</param>
 /// <param name="transformAdapter">Transform adapter</param>
 public D2dGraphEdgeEditAdapter(
     D2dGraphRenderer <TNode, TEdge, TEdgeRoute> renderer,
     D2dGraphAdapter <TNode, TEdge, TEdgeRoute> graphAdapter,
     ITransformAdapter transformAdapter)
 {
     m_renderer        = renderer;
     m_graphAdapter    = graphAdapter;
     m_draggingContext = new EdgeDraggingContext(this);
 }
Esempio n. 5
0
 /// <summary>
 /// Constructor</summary>
 /// <param name="renderer">Graph renderer</param>
 /// <param name="graphAdapter">Graph adapter</param>
 /// <param name="transformAdapter">Transform adapter</param>
 public D2dGraphNodeEditAdapter(
     D2dGraphRenderer <TNode, TEdge, TEdgeRoute> renderer,
     D2dGraphAdapter <TNode, TEdge, TEdgeRoute> graphAdapter,
     ITransformAdapter transformAdapter)
 {
     m_renderer         = renderer;
     m_graphAdapter     = graphAdapter;
     m_transformAdapter = transformAdapter;
 }
Esempio n. 6
0
        /// <summary>
        /// Constructor</summary>
        /// <param name="renderer">Graph renderer</param>
        /// <param name="graphAdapter">Graph adapter</param>
        /// <param name="transformAdapter">Transform adapter</param>
        public D2dGraphEdgeEditAdapter(
            D2dGraphRenderer <TNode, TEdge, TEdgeRoute> renderer,
            D2dGraphAdapter <TNode, TEdge, TEdgeRoute> graphAdapter,
            ITransformAdapter transformAdapter)
        {
            m_renderer        = renderer;
            m_graphAdapter    = graphAdapter;
            m_draggingContext = new EdgeDraggingContext(this);

            OverRouteCursor    = Cursors.Cross;
            FromPlaceCursor    = Cursors.PanWest;
            ToPlaceCursor      = Cursors.PanEast;
            InadmissibleCursor = Cursors.Cross;
        }
Esempio n. 7
0
        private void ConnectWires(MouseEventArgs e)
        {
            if (m_mainEditableGraph != null &&
                !m_isConnecting)
            {
                if (e.Button == MouseButtons.Left &&
                    ((Control.ModifierKeys & Keys.Alt) == 0) &&
                    !AdaptedControl.Capture)
                {
                    m_draggingContext.DisconnectEdge = 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)
                        bool dragEdgeReversed = m_mousePick.FromRoute == null; // mouse is over a FromRoute(output pin), assume not making reverse connections
                        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_mousePick.Node, m_mousePick.FromRoute);
                                dragEdgeReversed = false; // connecting "from-to"
                            }
                            else if (m_mousePick.ToRoute != null && !m_mousePick.ToRoute.AllowFanIn)
                            {
                                m_draggingContext.ExistingEdge = GetFirstEdgeTo(m_mousePick.Node, m_mousePick.ToRoute);
                                dragEdgeReversed = true; // connecting "to-from"
                            }
                        }
                        TNode      startNode  = null;
                        TEdgeRoute startRoute = null;

                        if (m_draggingContext.ExistingEdge != null)
                        {
                            if (DraggingContext.EditableGraph.CanDisconnect(m_draggingContext.ExistingEdge))
                            {
                                m_draggingContext.DragFromNode  = m_draggingContext.ExistingEdge.FromNode;
                                m_draggingContext.DragFromRoute = m_draggingContext.ExistingEdge.FromRoute;
                                m_draggingContext.DragToNode    = m_draggingContext.ExistingEdge.ToNode;
                                m_draggingContext.DragToRoute   = m_draggingContext.ExistingEdge.ToRoute;

                                if (dragEdgeReversed)
                                {
                                    startNode  = m_draggingContext.DragFromNode;
                                    startRoute = m_draggingContext.DragFromRoute;
                                }
                                else
                                {
                                    startNode  = m_draggingContext.DragToNode;
                                    startRoute = m_draggingContext.DragToRoute;
                                }

                                m_dragEdgeReversed = dragEdgeReversed;
                                m_isConnecting     = true;
                                cursor             = Cursors.UpArrow;
                            }
                        }
                        else 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         = Cursors.UpArrow;
                        }
                        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         = Cursors.UpArrow;
                        }

                        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 = Cursors.UpArrow;
                    }
                    else
                    {
                        m_draggingContext.DragToNode  = null;
                        m_draggingContext.DragToRoute = null;
                        cursor = Cursors.No;
                    }
                }
                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 = Cursors.UpArrow;
                    }
                    else
                    {
                        m_draggingContext.DragFromNode  = null;
                        m_draggingContext.DragFromRoute = null;
                        cursor = Cursors.No;
                    }
                }

                AdaptedControl.AutoResetCursor = false;
                AdaptedControl.Cursor          = cursor;
                var d2dControl = this.AdaptedControl as D2dAdaptableControl;
                d2dControl.DrawD2d();
            }
        }