Example #1
0
        public override void Do()
        {
            _Edge = new DataEdge(_source, _target);

            _sourceVC = _graph.VertexList.Where(pair => pair.Key.Id == _source.Id).Select(pair => pair.Value).FirstOrDefault();
            _targetVC = _graph.VertexList.Where(pair => pair.Key.Id == _target.Id).Select(pair => pair.Value).FirstOrDefault();

            if (_sourceVC == null || _targetVC == null)
            {
                throw new ArgumentNullException("Vertex Control");
            }

            _eCtrl = new EdgeControl(_sourceVC, _targetVC, _Edge)
            {
                ShowArrows = true,
                ShowLabel  = true
            };

            _graph.Graph.AddEdge(_Edge);
            _graph.AddEdge(_Edge, _eCtrl);

            if (_callback != null)
            {
                _callback.Invoke(_eCtrl);
            }
        }
Example #2
0
        public override void UnDo()
        {
            _Edge = new DataEdge(_source, _target);

            _sourceVC = _graph.VertexList.Where(pair => pair.Key == _source).Select(pair => pair.Value).FirstOrDefault();
            _targetVC = _graph.VertexList.Where(pair => pair.Key == _target).Select(pair => pair.Value).FirstOrDefault();

            if (_sourceVC == null || _targetVC == null)
            {
                throw new ArgumentNullException("VertexControl");
            }

            _eCtrl = new EdgeControl(_sourceVC, _targetVC, _Edge)
            {
                ShowArrows = true,
                ShowLabel  = true
            };

            _graph.Graph.AddEdge(_Edge);
            _graph.AddEdge(_Edge, _eCtrl);

            HighlightBehaviour.SetIsHighlightEnabled(_eCtrl, false);

            if (_undoCallback != null)
            {
                _undoCallback.Invoke(_eCtrl);
            }
        }
 //dispose operation, release reference
 public virtual void Dispose()
 {
     _Edge.Dispose();
     _Edge         = null;
     _eCtrl        = null;
     _callback     = null;
     _undoCallback = null;
     _graph        = null;
 }
        void Area_VertexSelected(object sender, GraphX.Models.VertexSelectedEventArgs args)
        {
            if (args.MouseArgs.LeftButton == MouseButtonState.Pressed)
            {
                //if (DragBehaviour.GetIsDragging(args.VertexControl)) return;
                SelectVertex(args.VertexControl);

                if (IsInEditMode && _status.HasFlag(GraphExplorerStatus.CreateLinkSelectSource))
                {
                    if (_edVertex == null) //select starting vertex
                    {
                        _edVertex = args.VertexControl;
                        _edFakeDV = new DataVertex()
                        {
                            ID = -666
                        };
                        _edGeo = new PathGeometry(new PathFigureCollection()
                        {
                            new PathFigure()
                            {
                                IsClosed = false, StartPoint = _edVertex.GetPosition(), Segments = new PathSegmentCollection()
                                {
                                    new PolyLineSegment(new List <Point>()
                                    {
                                        new Point()
                                    }, true)
                                }
                            }
                        });
                        var pos     = zoomctrl.TranslatePoint(args.VertexControl.GetPosition(), Area);
                        var lastseg = _edGeo.Figures[0].Segments[_edGeo.Figures[0].Segments.Count - 1] as PolyLineSegment;
                        lastseg.Points[lastseg.Points.Count - 1] = pos;

                        var dedge = new DataEdge(_edVertex.Vertex as DataVertex, _edFakeDV);
                        _edEdge = new EdgeControl(_edVertex, null, dedge)
                        {
                            ManualDrawing = true
                        };
                        Area.AddEdge(dedge, _edEdge);
                        Area.Graph.AddVertex(_edFakeDV);
                        Area.Graph.AddEdge(dedge);
                        _edEdge.SetEdgePathManually(_edGeo);
                        _status = GraphExplorerStatus.CreateLinkSelectTarget;
                        _viewmodel.PostStatusMessage("Select Target Node");
                    }
                    else if (_edVertex != args.VertexControl && _status.HasFlag(GraphExplorerStatus.CreateLinkSelectTarget)) //finish draw
                    {
                        _viewmodel.CreateEdge((_edVertex.Vertex as DataVertex).Id, (args.VertexControl.Vertex as DataVertex).Id);

                        ClearEdgeDrawing();

                        _status = GraphExplorerStatus.Ready;

                        tbnNewEdge.IsChecked = false;
                    }
                }
            }
            else if (args.MouseArgs.RightButton == MouseButtonState.Pressed && IsInEditMode)
            {
                args.VertexControl.ContextMenu = new System.Windows.Controls.ContextMenu();
                var miDeleteVertex = new System.Windows.Controls.MenuItem()
                {
                    Header = "Delete", Tag = args.VertexControl
                };
                miDeleteVertex.Click += miDeleteVertex_Click;
                args.VertexControl.ContextMenu.Items.Add(miDeleteVertex);
            }
        }
Example #5
0
 public DeleteEdgeOperation(GraphArea graph, DataVertex source, DataVertex target, DataEdge edge, Action <EdgeControl> callback = null, Action <EdgeControl> undoCallback = null)
     : base(graph, source, target, callback, undoCallback)
 {
     _Edge        = edge;
     base.Sammary = "Delete Edge";
 }