protected virtual void InitializePosition(TVertex vertex)
        {
            VertexControl presenter = _vertexControls[vertex];

            //initialize position
            if (Graph.ContainsVertex(vertex) && Graph.Degree(vertex) > 0)
            {
                var pos   = new Point();
                int count = 0;
                foreach (var neighbour in Graph.GetNeighbours(vertex))
                {
                    VertexControl neighbourControl;
                    if (_vertexControls.TryGetValue(neighbour, out neighbourControl))
                    {
                        double x = GetX(neighbourControl);
                        double y = GetY(neighbourControl);
                        pos.X += double.IsNaN(x) ? 0.0 : x;
                        pos.Y += double.IsNaN(y) ? 0.0 : y;
                        count++;
                    }
                }
                if (count > 0)
                {
                    pos.X /= count;
                    pos.Y /= count;
                    SetX(presenter, pos.X);
                    SetY(presenter, pos.Y);
                }
            }
        }
        public VertexControl GetVertexControl(TVertex vertex)
        {
            VertexControl vc = null;

            _vertexControls.TryGetValue(vertex, out vc);
            return(vc);
        }
Example #3
0
 private static void ComputeProperty(VertexControl control, DependencyProperty prop, double newValue, double oldValue, double dimension)
 {
     if (control != null)
     {
         newValue = newValue - (dimension / 2);
         if (0.0001 < Math.Abs(newValue - (double)control.GetValue(prop)))
         {
             control.SetValue(prop, newValue);
         }
     }
 }
        protected virtual void CreateVertexControl(TVertex vertex)
        {
            VertexControl presenter;
            var           compoundGraph = Graph as ICompoundGraph <TVertex, TEdge>;

            if (IsCompoundMode && compoundGraph != null && compoundGraph.IsCompoundVertex(vertex))
            {
                var compoundPresenter = new CompoundVertexControl
                {
                    Vertex = vertex
                };
                compoundPresenter.Expanded  += CompoundVertexControl_ExpandedOrCollapsed;
                compoundPresenter.Collapsed += CompoundVertexControl_ExpandedOrCollapsed;
                presenter = compoundPresenter;
            }
            else
            {
                // Create the Control of the vertex
                presenter = new VertexControl
                {
                    Vertex = vertex
                };
            }

            //var presenter = _vertexPool.GetObject();
            //presenter.Vertex = vertex;
            _vertexControls[vertex] = presenter;
            presenter.RootCanvas    = this;

            if (IsCompoundMode && compoundGraph != null && compoundGraph.IsChildVertex(vertex))
            {
                var parent        = compoundGraph.GetParent(vertex);
                var parentControl = GetOrCreateVertexControl(parent) as CompoundVertexControl;

                Debug.Assert(parentControl != null);

                parentControl.Vertices.Add(presenter);
            }
            else
            {
                //add the presenter to the GraphLayout
                Children.Add(presenter);
            }

            presenter.ApplyTemplate();
            VisualStateManager.GoToState(presenter, "BeforeAdded", false);
            VisualStateManager.GoToState(presenter, "AfterAdded", true);

            //Measuring & Arrange
            presenter.InvalidateMeasure();
            //SetHighlightProperties(vertex, presenter);
        }
Example #5
0
        public IEnumerable <FrameworkElement> GetChildElements()
        {
            foreach (EdgeControl control in AsSources)
            {
                VertexControl target = control.Target;
                yield return(target);

                foreach (FrameworkElement element in target.GetChildElements())
                {
                    yield return(element);
                }
            }
        }
Example #6
0
        protected virtual void CreateVertexControl(TVertex vertex)
        {
            VertexControl presenter;
            var           compoundGraph = Graph as ICompoundGraph <TVertex, TEdge>;

            if (IsCompoundMode && compoundGraph != null && compoundGraph.IsCompoundVertex(vertex))
            {
                var compoundPresenter = new CompoundVertexControl
                {
                    Vertex      = vertex,
                    DataContext = vertex,
                };
                compoundPresenter.Expanded  += CompoundVertexControl_ExpandedOrCollapsed;
                compoundPresenter.Collapsed += CompoundVertexControl_ExpandedOrCollapsed;
                presenter = compoundPresenter;
            }
            else
            {
                // Create the Control of the vertex
                presenter = new VertexControl
                {
                    Vertex      = vertex,
                    DataContext = vertex,
                };
            }

            //var presenter = _vertexPool.GetObject();
            //presenter.Vertex = vertex;
            VertexControls[vertex] = presenter;
            presenter.RootCanvas   = this;

            if (IsCompoundMode && compoundGraph != null && compoundGraph.IsChildVertex(vertex))
            {
                var parent        = compoundGraph.GetParent(vertex);
                var parentControl = GetOrCreateVertexControl(parent) as CompoundVertexControl;

                Debug.Assert(parentControl != null);

                parentControl.Vertices.Add(presenter);
            }
            else
            {
                //add the presenter to the GraphLayout
                Children.Add(presenter);
            }

            //Measuring & Arrange
            presenter.InvalidateMeasure();
            SetHighlightProperties(vertex, presenter);
            RunCreationTransition(presenter);
        }
Example #7
0
        private static void SourceChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            EdgeControl c = d as EdgeControl;

            VertexControl vcn = e.NewValue as VertexControl;

            if (vcn != null)
            {
                vcn.AsSources.AddEdge(c);
            }
            VertexControl vco = e.OldValue as VertexControl;

            if (vco != null)
            {
                vco.AsSources.RemoveEdge(c);
            }
        }
Example #8
0
        protected void SetHighlightProperties(TVertex vertex, VertexControl presenter)
        {
            object highlightInfo;

            if (IsHighlightedVertex(vertex, out highlightInfo))
            {
                GraphElementBehavior.SetIsHighlighted(presenter, true);
                GraphElementBehavior.SetHighlightInfo(presenter, highlightInfo);
            }

            object semiHighlightInfo;

            if (IsSemiHighlightedVertex(vertex, out semiHighlightInfo))
            {
                GraphElementBehavior.SetIsSemiHighlighted(presenter, true);
                GraphElementBehavior.SetSemiHighlightInfo(presenter, semiHighlightInfo);
            }
        }
 private void HighlightVertex(VertexControl vc)
 {
     ClearHighlights();
     foreach (var child in AssociatedObject.Children)
     {
         var ec = child as EdgeControl;
         if (ec != null)
         {
             if (ec.Source == vc)
             {
                 VisualStateManager.GoToState(ec, "HighlightedTarget", true);
                 VisualStateManager.GoToState(ec.Target, "HighlightedTarget", true);
             }
             else if (ec.Target == vc)
             {
                 VisualStateManager.GoToState(ec, "HighlightedSource", true);
                 VisualStateManager.GoToState(ec.Source, "HighlightedSource", true);
             }
         }
     }
     VisualStateManager.GoToState(vc, "Highlighted", true);
 }
Example #10
0
 public void Reset()
 {
     Edge = null;
     RoutePoints = null;
     Source = null;
     Target = null;
 }
 private static void ComputeProperty(VertexControl control, DependencyProperty prop, double newValue, double oldValue, double dimension)
 {
     if (control != null)
     {
         newValue = newValue - (dimension / 2);
         if (0.0001 < Math.Abs(newValue - (double)control.GetValue(prop)))
         {
             control.SetValue(prop, newValue);
         }
     }
 }
        /// <summary>
        /// Get the data about the current graph's
        /// node, edges and their coordinates. Save this
        /// data to citiesLocations and citiesConnections.
        /// </summary>
        public void GetCurrentGraph(GraphLayoutCity graphLayout,
            ref CitiesLocations citiesLocations)
        {
            VertexControl vertexControl = new VertexControl();
            Coordinates tempVertexCoordinates;
            int tempXCoord;
            int tempYCoord;

            foreach (VertexCity vertex in graphLayout.Graph.Vertices)
            {
                // Get the vertex data and a vertex control
                citiesLocations.locations.TryGetValue(vertex.City, out tempVertexCoordinates);
                vertexControl = graphLayout.GetVertexControl(vertex);

                // Get current coordinates
                tempXCoord = (int)GraphCanvas.GetX(vertexControl);
                tempYCoord = (int)GraphCanvas.GetY(vertexControl);

                // Update the information
                tempVertexCoordinates.setX(tempXCoord);
                tempVertexCoordinates.setY(tempYCoord);
            }
        }
        /// <summary>
        /// Set the nodes coordinates to the coordinates from the 
        /// locations file.
        /// </summary>
        /// <param name="graphLayout">
        /// Graph layout
        /// </param>
        /// <param name="citiesLocations">
        /// Locations file that has the desired coordinates for the graph's vertices
        /// </param>
        public void EstablishCoordinates(ref GraphLayoutCity graphLayout,
            CitiesLocations citiesLocations)
        {
            VertexControl vertexControl = new VertexControl();
            Coordinates tempVertexCoordinates;

            if (citiesLocations != null)
            {
                foreach (VertexCity vertex in graphLayout.Graph.Vertices)
                {
                    // Get the coordinates from the locations file
                    citiesLocations.locations.TryGetValue(vertex.City, out tempVertexCoordinates);

                    // Update the vertex data
                    vertex.CityCoordinates.setX(tempVertexCoordinates.getX());
                    vertex.CityCoordinates.setY(tempVertexCoordinates.getY());

                    // Update the vertex position on the screen
                    vertexControl = graphLayout.GetVertexControl(vertex);
                    GraphCanvas.SetX(vertexControl, vertex.CityCoordinates.getX());
                    GraphCanvas.SetY(vertexControl, vertex.CityCoordinates.getY());
                }
            }
        }
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     
     #line 40 "..\..\..\Views\ScopeGraph.xaml"
     ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.ExecuteRemoveNode);
     
     #line default
     #line hidden
     
     #line 41 "..\..\..\Views\ScopeGraph.xaml"
     ((System.Windows.Input.CommandBinding)(target)).CanExecute += new System.Windows.Input.CanExecuteRoutedEventHandler(this.CanExecuteRemoveNode);
     
     #line default
     #line hidden
     return;
     case 2:
     
     #line 43 "..\..\..\Views\ScopeGraph.xaml"
     ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.ExecuteRemoveSelectedNodes);
     
     #line default
     #line hidden
     
     #line 44 "..\..\..\Views\ScopeGraph.xaml"
     ((System.Windows.Input.CommandBinding)(target)).CanExecute += new System.Windows.Input.CanExecuteRoutedEventHandler(this.CanExecuteRemoveSelectedNodes);
     
     #line default
     #line hidden
     return;
     case 3:
     
     #line 46 "..\..\..\Views\ScopeGraph.xaml"
     ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.ExecuteToggleLogLevel);
     
     #line default
     #line hidden
     
     #line 47 "..\..\..\Views\ScopeGraph.xaml"
     ((System.Windows.Input.CommandBinding)(target)).CanExecute += new System.Windows.Input.CanExecuteRoutedEventHandler(this.CanToggleLogLevel);
     
     #line default
     #line hidden
     return;
     case 4:
     
     #line 49 "..\..\..\Views\ScopeGraph.xaml"
     ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.ExecuteCreateConnection);
     
     #line default
     #line hidden
     return;
     case 5:
     
     #line 51 "..\..\..\Views\ScopeGraph.xaml"
     ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.ExecuteAddScopeToDecision);
     
     #line default
     #line hidden
     return;
     case 6:
     
     #line 54 "..\..\..\Views\ScopeGraph.xaml"
     ((System.Windows.Controls.DockPanel)(target)).PreviewDrop += new System.Windows.DragEventHandler(this.Graph_Drop);
     
     #line default
     #line hidden
     
     #line 55 "..\..\..\Views\ScopeGraph.xaml"
     ((System.Windows.Controls.DockPanel)(target)).PreviewDragOver += new System.Windows.DragEventHandler(this.Graph_DragOver);
     
     #line default
     #line hidden
     return;
     case 7:
     this.zoomControl = ((TraceLab.UI.WPF.Controls.ZoomControl.ZoomControl)(target));
     return;
     case 8:
     this.marqueeAdorner = ((System.Windows.Shapes.Rectangle)(target));
     return;
     case 9:
     this.graphLayout = ((TraceLab.UI.WPF.Controls.NodeGraphLayout)(target));
     return;
     case 10:
     this.HACK_Vertex = ((GraphSharp.Controls.VertexControl)(target));
     return;
     case 11:
     this.HACK_Edge = ((GraphSharp.Controls.EdgeControl)(target));
     return;
     }
     this._contentLoaded = true;
 }
Example #15
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:

            #line 40 "..\..\..\Views\ScopeGraph.xaml"
                ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.ExecuteRemoveNode);

            #line default
            #line hidden

            #line 41 "..\..\..\Views\ScopeGraph.xaml"
                ((System.Windows.Input.CommandBinding)(target)).CanExecute += new System.Windows.Input.CanExecuteRoutedEventHandler(this.CanExecuteRemoveNode);

            #line default
            #line hidden
                return;

            case 2:

            #line 43 "..\..\..\Views\ScopeGraph.xaml"
                ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.ExecuteRemoveSelectedNodes);

            #line default
            #line hidden

            #line 44 "..\..\..\Views\ScopeGraph.xaml"
                ((System.Windows.Input.CommandBinding)(target)).CanExecute += new System.Windows.Input.CanExecuteRoutedEventHandler(this.CanExecuteRemoveSelectedNodes);

            #line default
            #line hidden
                return;

            case 3:

            #line 46 "..\..\..\Views\ScopeGraph.xaml"
                ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.ExecuteToggleLogLevel);

            #line default
            #line hidden

            #line 47 "..\..\..\Views\ScopeGraph.xaml"
                ((System.Windows.Input.CommandBinding)(target)).CanExecute += new System.Windows.Input.CanExecuteRoutedEventHandler(this.CanToggleLogLevel);

            #line default
            #line hidden
                return;

            case 4:

            #line 49 "..\..\..\Views\ScopeGraph.xaml"
                ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.ExecuteCreateConnection);

            #line default
            #line hidden
                return;

            case 5:

            #line 51 "..\..\..\Views\ScopeGraph.xaml"
                ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.ExecuteAddScopeToDecision);

            #line default
            #line hidden
                return;

            case 6:

            #line 54 "..\..\..\Views\ScopeGraph.xaml"
                ((System.Windows.Controls.DockPanel)(target)).PreviewDrop += new System.Windows.DragEventHandler(this.Graph_Drop);

            #line default
            #line hidden

            #line 55 "..\..\..\Views\ScopeGraph.xaml"
                ((System.Windows.Controls.DockPanel)(target)).PreviewDragOver += new System.Windows.DragEventHandler(this.Graph_DragOver);

            #line default
            #line hidden
                return;

            case 7:
                this.zoomControl = ((TraceLab.UI.WPF.Controls.ZoomControl.ZoomControl)(target));
                return;

            case 8:
                this.marqueeAdorner = ((System.Windows.Shapes.Rectangle)(target));
                return;

            case 9:
                this.graphLayout = ((TraceLab.UI.WPF.Controls.NodeGraphLayout)(target));
                return;

            case 10:
                this.HACK_Vertex = ((GraphSharp.Controls.VertexControl)(target));
                return;

            case 11:
                this.HACK_Edge = ((GraphSharp.Controls.EdgeControl)(target));
                return;
            }
            this._contentLoaded = true;
        }