Example #1
0
        private void HACK_Control_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            DropLinkEventArgs args = null;

            if (PotentialLinkSource != null)
            {
                object target = PotentialLinkTarget != null ? PotentialLinkTarget.Vertex : null;
                object edge   = LinkBeingMoved != null ? LinkBeingMoved.Edge : null;

                args           = new DropLinkEventArgs(PotentialLinkSource.Vertex, target, edge);
                LinkBeingMoved = null;
            }

            if (args != null && DropCommand.CanExecute(args))
            {
                /// checking if Target is different HACK_NODE is related to hard to reproduce error
                /// somehow when you drag a link quickly to the existing node, but you don't really reach it or you are too far from node, then the target appears to be HACK_NODE
                if (args.Target == null || (args.Target != null && args.Target.ToString().Equals("HACK_Node") == false))
                {
                    DropCommand.Execute(args);
                }
            }

            CancelAllDragging();
        }
Example #2
0
        protected override void OnMouseRightButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseRightButtonDown(e);

            if (e.Handled != true)
            {
                var hitElement = InputHitTest(e.GetPosition(this)) as DependencyObject;
                if (hitElement != null)
                {
                    e.Handled = true;
                    GraphSharp.Controls.VertexControl hitVertex = hitElement.GetParent <GraphSharp.Controls.VertexControl>(this);
                    if (hitVertex != null)
                    {
                        // 1) if vertex is not already selected, then clear selection and select this vertex.
                        if ((bool)hitVertex.GetValue(GraphView.IsSelectedProperty) == false)
                        {
                            UnselectAll();
                            SetIsSelected(hitVertex, true);
                        }
                    }
                    else
                    {
                        GraphSharp.Controls.EdgeControl hitEdge = hitElement.GetParent <GraphSharp.Controls.EdgeControl>(this);
                        if (hitEdge != null)
                        {
                            CreateRoutePointOnEdge(e, hitEdge);
                        }
                    }
                }

                // Take focus
                Focus();
            }
        }
Example #3
0
        protected void graphLayout_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (IsExperimentRunning == false)
            {
                //check if current GraphLayout at the specified coordinates is occluded by another graph view
                //Checking on GraphLayout not this GraphView, because hit elemenent must be checked relative to the current GraphLayout origin, not constant graph view element
                Point clickPoint            = e.GetPosition(GraphLayout);
                bool  isGraphLayoutOccluded = IsUIElementOccludedByAnotherGraphView(GraphLayout, clickPoint);

                if (!isGraphLayoutOccluded)
                {
                    IInputElement ele = GraphLayout.InputHitTest(clickPoint);
                    if (ele != null && HACK_VertexControl.Visibility != System.Windows.Visibility.Visible)
                    {
                        // if they clicked on a edge start redirecting the edge
                        DependencyObject obj = (DependencyObject)ele;
                        TraceLab.UI.WPF.Controls.RoutePointThumb routePointThumb = obj.GetParent <TraceLab.UI.WPF.Controls.RoutePointThumb>(this);
                        if (routePointThumb == null)
                        {
                            GraphSharp.Controls.EdgeControl edge = obj.GetParent <GraphSharp.Controls.EdgeControl>(this);
                            if (CanRedirectLink(edge))
                            {
                                StartRedirectLinkDrag(e, clickPoint, edge);
                            }
                        }
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Creates the route point on edge.
        /// </summary>
        /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param>
        /// <param name="hitEdge">The hit edge.</param>
        private void CreateRoutePointOnEdge(MouseButtonEventArgs e, GraphSharp.Controls.EdgeControl hitEdge)
        {
            ExperimentNodeConnection connection = (ExperimentNodeConnection)hitEdge.Edge;

            Point      canvasPoint = e.GetPosition(GraphLayout);
            RoutePoint finalPoint  = new RoutePoint(canvasPoint.X, canvasPoint.Y);

            connection.RoutePoints.Add(finalPoint);
        }
Example #5
0
        /// <summary>
        /// Determines whether the edge can be redirected
        /// </summary>
        /// <param name="edge">The edge.</param>
        /// <returns>
        ///   <c>true</c> if this instance [can redirect link] the specified current edge; otherwise, <c>false</c>.
        /// </returns>
        private bool CanRedirectLink(GraphSharp.Controls.EdgeControl edge)
        {
            bool canRedirect = false;

            if (edge != null)
            {
                ExperimentNodeConnection connection = edge.Edge as ExperimentNodeConnection;
                if (connection != null && connection.IsFixed == false)
                {
                    canRedirect = true;
                }
            }

            return(canRedirect);
        }
Example #6
0
        private void StartRedirectLinkDrag(MouseButtonEventArgs e, Point clickPoint, GraphSharp.Controls.EdgeControl currentEdge)
        {
            // Cache information about currentEdge
            LinkBeingMoved = currentEdge;

            GraphSharp.Controls.VertexControl source = currentEdge.Source;

            // Reveal the manipulation controls.
            RevealHACKControls(clickPoint, source);

            // handle mouse event so any other control
            e.Handled = true;

            // When we lose mouse capture, then cancel all dragging.
            BeginDrag(e.MouseDevice, e.Timestamp, e.ChangedButton);
        }
Example #7
0
        private void CancelAllDragging()
        {
            HACK_VertexControl.Visibility = Visibility.Hidden;
            HACK_EdgeControl.SetValue(GraphSharp.Controls.EdgeControl.SourceProperty, null);
            HACK_EdgeControl.SetValue(GraphSharp.Controls.EdgeControl.TargetProperty, null);
            HACK_EdgeControl.Visibility = Visibility.Collapsed;

            HACK_VertexControl.PreviewMouseLeftButtonUp -= HACK_Control_PreviewMouseLeftButtonUp;
            HACK_VertexControl.PreviewMouseMove         -= HACK_Control_PreviewMouseMove;

            PotentialLinkTarget = null;
            PotentialLinkSource = null;

            if (LinkBeingMoved != null)
            {
                // Move was cancelled, re-validate the link.
                SetIsLinkValid(LinkBeingMoved, true);
                LinkBeingMoved = null;
            }
        }
        private void StartRedirectLinkDrag(MouseButtonEventArgs e, Point clickPoint, GraphSharp.Controls.EdgeControl currentEdge)
        {
            // Cache information about currentEdge
            LinkBeingMoved = currentEdge;

            GraphSharp.Controls.VertexControl source = currentEdge.Source;

            // Reveal the manipulation controls.
            RevealHACKControls(clickPoint, source);

            // handle mouse event so any other control 
            e.Handled = true;

            // When we lose mouse capture, then cancel all dragging.
            BeginDrag(e.MouseDevice, e.Timestamp, e.ChangedButton);
        }
        private void CancelAllDragging()
        {
            HACK_VertexControl.Visibility = Visibility.Hidden;
            HACK_EdgeControl.SetValue(GraphSharp.Controls.EdgeControl.SourceProperty, null);
            HACK_EdgeControl.SetValue(GraphSharp.Controls.EdgeControl.TargetProperty, null);
            HACK_EdgeControl.Visibility = Visibility.Collapsed;

            HACK_VertexControl.PreviewMouseLeftButtonUp -= HACK_Control_PreviewMouseLeftButtonUp;
            HACK_VertexControl.PreviewMouseMove -= HACK_Control_PreviewMouseMove;

            PotentialLinkTarget = null;
            PotentialLinkSource = null;

            if (LinkBeingMoved != null)
            {
                // Move was cancelled, re-validate the link.
                SetIsLinkValid(LinkBeingMoved, true);
                LinkBeingMoved = null;
            }
        }
        private void HACK_Control_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            DropLinkEventArgs args = null;
            if (PotentialLinkSource != null)
            {
                object target = PotentialLinkTarget != null ? PotentialLinkTarget.Vertex : null;
                object edge = LinkBeingMoved != null ? LinkBeingMoved.Edge : null;

                args = new DropLinkEventArgs(PotentialLinkSource.Vertex, target, edge);
                LinkBeingMoved = null;
            }

            if (args != null && DropCommand.CanExecute(args))
            {
                /// checking if Target is different HACK_NODE is related to hard to reproduce error
                /// somehow when you drag a link quickly to the existing node, but you don't really reach it or you are too far from node, then the target appears to be HACK_NODE
                if (args.Target == null || (args.Target != null && args.Target.ToString().Equals("HACK_Node") == false))
                {
                    DropCommand.Execute(args);
                }
            }

            CancelAllDragging();
        }