예제 #1
0
파일: GraphView.cs 프로젝트: thbin/TraceLab
        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();
            }
        }
        private static Point FindOptimalLocation(GraphSharp.Controls.VertexControl vertexControl)
        {
            Point suggestedLocation = new Point();

            var node = vertexControl.Vertex as ExperimentNode;

            if (node != null)
            {
                if (vertexControl != null)
                {
                    const int padding = 5;
                    suggestedLocation = new Point(vertexControl.TopLeftX + vertexControl.ActualWidth, vertexControl.TopLeftY + vertexControl.ActualHeight + padding);

                    //special case, if node belongs to the graph in the scope
                    var ownerGraph = node.Owner as CompositeComponentEditableGraph;
                    if (ownerGraph != null)
                    {
                        var scopeNode = ownerGraph.OwnerNode as ScopeNodeBase;
                        if (scopeNode != null)
                        {
                            var    data = scopeNode.DataWithSize;
                            double labelBorderHeight = 23; // check scope node control
                            suggestedLocation = new Point(suggestedLocation.X + data.X - (data.Width / 2), suggestedLocation.Y + data.Y - (data.Height / 2) + labelBorderHeight);
                        }
                    }
                }
            }

            return(suggestedLocation);
        }
예제 #3
0
        /// <summary>
        /// Finds the vertex control (view) of the given node
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="graphView">The graph view.</param>
        /// <returns></returns>
        private GraphSharp.Controls.VertexControl FindVertexControl(ExperimentNode node, TraceLab.UI.WPF.Views.GraphView graphView)
        {
            GraphSharp.Controls.VertexControl vertexControl = null;

            //check if node belongs to scope, ie. editable composite component graph of the scopenode
            var ownerGraph = node.Owner as CompositeComponentEditableGraph;

            if (ownerGraph != null)
            {
                //double check if the OwnerNode of the graph is a ScopeNode
                var scopeNode = ownerGraph.OwnerNode as ScopeNodeBase;
                if (scopeNode != null)
                {
                    var scopeVertexControl = FindVertexControl(scopeNode, graphView);
                    var scopeGraphView     = FindVisualChild <TraceLab.UI.WPF.Views.GraphView>(scopeVertexControl);
                    if (scopeGraphView != null)
                    {
                        vertexControl = scopeGraphView.ControlForNode(node);
                    }
                }
            }
            else
            {
                vertexControl = graphView.ControlForNode(node);
            }

            return(vertexControl);
        }
예제 #4
0
파일: GraphView.cs 프로젝트: thbin/TraceLab
        /// <summary>
        /// Performs operation of adding the new scope to the given decision.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param>
        protected void ExecuteAddScopeToDecision(object sender, ExecutedRoutedEventArgs e)
        {
            GraphSharp.Controls.VertexControl vertexControl = e.Parameter as GraphSharp.Controls.VertexControl;

            if (vertexControl != null)
            {
                ExperimentDecisionNode decisionNode = vertexControl.Vertex as ExperimentDecisionNode;

                if (decisionNode != null)
                {
                    ExitDecisionNode    exitDecisionNode = null;
                    IEditableExperiment experiment       = decisionNode.Owner as IEditableExperiment;
                    double           rightmostX          = decisionNode.Data.X;
                    HashSet <string> currentLabels       = new HashSet <string>();

                    //iterate through outgoing scopes and find the scope with right border located most to the right among all scopes
                    //also locate among outgoing edges reference to exit
                    IEnumerable <ExperimentNodeConnection> outEdges;
                    if (experiment.TryGetOutEdges(decisionNode, out outEdges))
                    {
                        foreach (ExperimentNodeConnection connection in outEdges)
                        {
                            ScopeNode scope = connection.Target as ScopeNode;

                            if (scope != null)
                            {
                                double candidateRightMostX = scope.DataWithSize.X + scope.DataWithSize.Width / 2;
                                if (candidateRightMostX > rightmostX)
                                {
                                    rightmostX = candidateRightMostX;
                                }

                                //also collect labels
                                currentLabels.Add(scope.Data.Metadata.Label);
                            }
                            else if (exitDecisionNode == null)
                            {
                                //try find exit decision node
                                exitDecisionNode = connection.Target as ExitDecisionNode;
                            }
                        }
                    }

                    double xPosition = rightmostX + 100;
                    double yPosition = decisionNode.Data.Y + 120;

                    string finalLabel = DetermineNewScopeLabel(currentLabels);

                    //check if deicion node is not null. In old decision nodes without scopes, there were no associated exit node,
                    //thus the scope cannot be added for these decisions.
                    if (exitDecisionNode != null)
                    {
                        ComponentFactory.AddScopeToDecision(finalLabel, xPosition, yPosition, decisionNode, exitDecisionNode, experiment);
                    }
                }
            }
        }
예제 #5
0
파일: GraphView.cs 프로젝트: thbin/TraceLab
        private void StartCreateLinkDrag(GraphSharp.Controls.VertexControl node)
        {
            Point clickPoint = Mouse.GetPosition(GraphLayout);

            RevealHACKControls(clickPoint, node);

            int timestamp = new TimeSpan(DateTime.Now.Ticks).Milliseconds;

            BeginDrag(Mouse.PrimaryDevice, timestamp, MouseButton.Left);
        }
예제 #6
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (Template != null)
            {
                //locate template part and gets it data context which is suppose to be a VertexControl
                m_nodeControl = (FrameworkElement)Template.FindName("PART_NodeControl", this);
                VertexControl = (GraphSharp.Controls.VertexControl)m_nodeControl.DataContext;
                ((ExperimentNode)VertexControl.Vertex).PropertyChanged += experimentNode_PropertyChanged;
            }
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (Template != null)
            {
                //locate template part and gets it data context which is suppose to be a VertexControl
                m_nodeControl = (FrameworkElement)Template.FindName("PART_NodeControl", this);
                VertexControl = (GraphSharp.Controls.VertexControl)m_nodeControl.DataContext;
                ((ExperimentNode)VertexControl.Vertex).PropertyChanged += experimentNode_PropertyChanged;
            }
        }
예제 #8
0
파일: GraphView.cs 프로젝트: thbin/TraceLab
        private void RevealHACKControls(Point clickPoint, GraphSharp.Controls.VertexControl parent)
        {
            PotentialLinkSource = parent;

            HACK_VertexControl.CenterX    = clickPoint.X;
            HACK_VertexControl.CenterY    = clickPoint.Y;
            HACK_VertexControl.Visibility = Visibility.Visible;
            HACK_VertexControl.PreviewMouseLeftButtonUp += HACK_Control_PreviewMouseLeftButtonUp;
            HACK_VertexControl.PreviewMouseMove         += HACK_Control_PreviewMouseMove;

            HACK_EdgeControl.SetValue(GraphSharp.Controls.EdgeControl.SourceProperty, parent);
            HACK_EdgeControl.SetValue(GraphSharp.Controls.EdgeControl.TargetProperty, HACK_VertexControl);
            HACK_EdgeControl.Visibility = Visibility.Visible;
        }
예제 #9
0
파일: GraphView.cs 프로젝트: thbin/TraceLab
        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);
        }
예제 #10
0
파일: GraphView.cs 프로젝트: thbin/TraceLab
        void HACK_Control_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            Point            clickPoint = e.GetPosition(GraphLayout);
            DependencyObject obj        = (DependencyObject)GraphLayout.InputHitTest(clickPoint);

            GraphSharp.Controls.VertexControl parent = null;
            if (obj != null)
            {
                parent = obj.GetParent <GraphSharp.Controls.VertexControl>(this);
            }

            if (parent != null && parent != PotentialLinkSource && DropCommand.CanExecute(new DropLinkEventArgs(PotentialLinkSource.Vertex, parent.Vertex, null)))
            {
                PotentialLinkTarget = parent;
            }
            else
            {
                PotentialLinkTarget = null;
            }
        }
예제 #11
0
        /// <summary>
        /// Creates the info panel view model for the given vertex control based on its type
        /// </summary>
        /// <param name="vertexControl">The vertex control for which the info is created.</param>
        /// <returns>node info view model</returns>
        public static ExperimentNodeInfo CreateInfo(GraphSharp.Controls.VertexControl vertexControl)
        {
            var node = vertexControl.Vertex as ExperimentNode;

            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (node.Data == null)
            {
                throw new InvalidOperationException("Cannot create info for node with invalid data.");
            }

            ExperimentNodeInfo info = null;

            //there are different types of node info view models depending on what vertex control type is
            //based on the node info type different view templates are used to render the info panel

            //most common is component, so check it first
            if (node.Data.Metadata is ComponentMetadata)
            {
                info = new ComponentNodeInfo(vertexControl);
            }
            else if (node.Data.Metadata is CompositeComponentMetadata)
            {
                info = new CompositeComponentNodeInfo(vertexControl);
            }
            else if (node.Data.Metadata is DecisionMetadata)
            {
                info = new DecisionNodeInfo(vertexControl);
            }
            else if (node.Data.Metadata is LoopScopeMetadata)
            {
                info = new LoopDecisionNodeInfo(vertexControl);
            }

            return(info);
        }
예제 #12
0
        /// <summary>
        /// Toogles off/on the info pane for the given vertex
        /// </summary>
        /// <param name="vertexControl">The vertex control.</param>
        /// <param name="toggleInfoPaneForNodeCommand">The toggle info pane for node command.</param>
        private static void Toogle(GraphSharp.Controls.VertexControl vertexControl, ICommand toggleInfoPaneForNodeCommand)
        {
            if (toggleInfoPaneForNodeCommand != null)
            {
                var node = vertexControl.Vertex as ExperimentNode;
                if (node != null)
                {
                    Point suggestedLocation = new Point();
                    var   param             = new TraceLab.UI.WPF.Commands.ToggleNodeInfoParameters()
                    {
                        SuggestedLocation = suggestedLocation, Node = node
                    };

                    if (vertexControl != null)
                    {
                        const int padding = 5;
                        suggestedLocation       = new Point(vertexControl.TopLeftX + vertexControl.ActualWidth, vertexControl.TopLeftY + vertexControl.ActualHeight + padding);
                        param.SuggestedLocation = suggestedLocation;
                    }

                    toggleInfoPaneForNodeCommand.Execute(param);
                }
            }
        }
예제 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DecisionNodeInfo"/> class.
 /// </summary>
 /// <param name="originVertexControl">The origin vertex control.</param>
 internal DecisionNodeInfo(GraphSharp.Controls.VertexControl originVertexControl)
     : base(originVertexControl)
 {
 }
예제 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CompositeComponentNodeInfo"/> class.
 /// </summary>
 /// <param name="originVertexControl">The origin vertex control.</param>
 internal CompositeComponentNodeInfo(GraphSharp.Controls.VertexControl originVertexControl)
     : base(originVertexControl)
 {
 }
예제 #15
0
파일: GraphView.cs 프로젝트: thbin/TraceLab
 public static void SetIsSelected(GraphSharp.Controls.VertexControl element, Boolean value)
 {
     element.SetValue(IsSelectedProperty, value);
 }
예제 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExperimentNodeInfo"/> class.
 /// </summary>
 /// <param name="originVertexControl">The origin vertex control.</param>
 protected ExperimentNodeInfo(GraphSharp.Controls.VertexControl originVertexControl)
 {
     OriginVertexControl = originVertexControl;
     Node = (ExperimentNode)originVertexControl.Vertex;
 }
예제 #17
0
파일: GraphView.cs 프로젝트: thbin/TraceLab
 public static Boolean GetIsSelected(GraphSharp.Controls.VertexControl element)
 {
     return((Boolean)element.GetValue(IsSelectedProperty));
 }