Example #1
0
        private void UpdateNetworkEdge(DiagramEdge edge)
        {
            RaiseLockEdgeUpdate(true);

            //delete old
            NetworkEdge networkEdge = _network.Edges.FindById(Convert.ToInt32(edge.UserData));
            if (networkEdge != null)
            {
                _network.Edges.Remove(networkEdge);
            }

            //create new
            RaiseEdgeCreated(edge);

            RaiseLockEdgeUpdate(false);
        }
Example #2
0
        public void SubscribeOnEdgeEvents(DiagramEdge edge)
        {
            if (edge == null)
                return;

            edge.SourceNodeChanged -= new EdgeEventHandler(OnSourceNodeChanged);
            edge.SourceNodeChanged += new EdgeEventHandler(OnSourceNodeChanged);
            edge.DestinationNodeChanged -= new EdgeEventHandler(OnDestinationNodeChanged);
            edge.DestinationNodeChanged += new EdgeEventHandler(OnDestinationNodeChanged);
            edge.AnchoringModeChanged -= new EdgeEventHandler(OnAnchoringModeChanged);
            edge.AnchoringModeChanged += new EdgeEventHandler(OnAnchoringModeChanged);
        }
Example #3
0
 private void RaiseEdgeCreated(DiagramEdge edge)
 {
     if (EdgeCreated != null)
     {
         EdgeCreated(edge, null);
     }
 }
 public EdgeEventArgs(Diagram diagram, DiagramEdge edge)
     : base(diagram)
 {
     Edge = edge;
 }
Example #5
0
        public void CreateVisual()
        {
            if (_network == null)
                return;

            RaiseLockNodeUpdate(true);

            foreach (var netNode in _network.Nodes)
            {
                DiagramNode node = new DiagramNode(_diagram);
                NodeAdded(node, netNode);
                node.Bounds = node.Label.Drawer.CalculateGeometry(node.Label).Bounds;
                if (node.Bounds.Width == 0 || node.Bounds.Height == 0)
                {
                    node.Bounds = new Rect(0, 0, 25, 25);
                }
                else
                {
                    Rect nodeBounds = node.Bounds;
                    nodeBounds.Width = nodeBounds.Width * 1.3;
                    nodeBounds.Height = nodeBounds.Height * 1.2;
                    node.Bounds = nodeBounds;
                }
            }

            RaiseLockNodeUpdate(false);

            RaiseLockEdgeUpdate(true);

            foreach (var netEdge in _network.Edges)
            {
                var origin = Utils.FindItemByUserData(_diagram, netEdge.StartNode.Id) as DiagramNode;
                var destination = Utils.FindItemByUserData(_diagram, netEdge.EndNode.Id) as DiagramNode;

                var edge = new DiagramEdge(_diagram);
                edge.AnchoringMode = EdgeAnchoringMode.NodeToNode;
                edge.SourceNode = origin;
                edge.DestinationNode = destination;

                LinkAdded(edge, netEdge);
            }

            RaiseLockEdgeUpdate(false);
        }
        private void SaveEdgeToXElement(XElement xEdges, DiagramEdge edge)
        {
            XElement xEdge = new XElement("Edge");

            WriteElement(xEdge, "AnchoringMode", Enum.GetName(typeof(EdgeAnchoringMode), edge.AnchoringMode));
            WriteElement(xEdge, "SourcePoint", edge.SourcePoint);
            WriteElement(xEdge, "DestinationPoint", edge.DestinationPoint);

            if (edge.SourceNode != null)
            {
                int sourceIndex = _diagram.Nodes.IndexOf(edge.SourceNode);
                if (sourceIndex >= 0)
                {
                    WriteElement(xEdge, "SourceNodeIndex", sourceIndex);
                }
            }

            if (edge.DestinationNode != null)
            {
                int destinationIndex = _diagram.Nodes.IndexOf(edge.DestinationNode);
                if (destinationIndex >= 0)
                {
                    WriteElement(xEdge, "DestinationNodeIndex", destinationIndex);
                }
            }

            SaveItemPart(xEdge, edge);

            if (edge.Label != null)
            {
                SaveLabelToXElement(xEdge, edge.Label);
            }

            xEdges.Add(xEdge);
        }
Example #7
0
        private void DrawEdge(DrawingContext dc, DiagramEdge edge, ref List<DiagramItem> itemsToDraw, bool considerViewport)
        {
            if (_itemsInDrawingOrder.Contains(edge) || itemsToDraw.Contains(edge))
                return;

            if (_selection.Contains(edge))
            {
                if (!itemsToDraw.Contains(edge))
                    itemsToDraw.Add(edge);
            }
            else
            {
                edge.Draw(dc, considerViewport);
                _itemsInDrawingOrder.Add(edge);

                if (_selection.Contains(edge.Label))
                {
                    if (!itemsToDraw.Contains(edge.Label))
                        itemsToDraw.Add(edge.Label);
                }
                else if (edge.Label != null)
                {
                    edge.Label.Draw(dc, considerViewport);
                    _itemsInDrawingOrder.Add(edge.Label);

                }
            }
        }
        private void LoadEdgesFromXElement(XElement xEdges)
        {
            IEnumerable<XElement> xEdgeList = xEdges.Elements("Edge");

            foreach (var xEdge in xEdgeList)
            {
                DiagramEdge edge = new DiagramEdge(_diagram);
                LoadEdgeFromXElement(xEdge, edge);
            }
        }
        private void LoadEdgeFromXElement(XElement xEdge, DiagramEdge edge)
        {
            string anMode = "";
            if (ReadElement(xEdge, "AnchoringMode", out anMode))
            {
                edge.AnchoringMode = (EdgeAnchoringMode)Enum.Parse(typeof(EdgeAnchoringMode), anMode);
            }

            Point sourcePoint;
            if (ReadElement(xEdge, "SourcePoint", out sourcePoint))
            {
                edge.SourcePoint = sourcePoint;
            }

            Point DestinationPoint;
            if (ReadElement(xEdge, "DestinationPoint", out DestinationPoint))
            {
                edge.DestinationPoint = DestinationPoint;
            }

            int sourceNodeIndex = -1;
            if (ReadElement(xEdge, "SourceNodeIndex", out sourceNodeIndex))
            {
                if (sourceNodeIndex >= 0 && sourceNodeIndex < _diagram.Nodes.Count)
                {
                    edge.SourceNode = _diagram.Nodes[sourceNodeIndex];
                }
            }

            int destinationNodeIndex = -1;
            if (ReadElement(xEdge, "DestinationNodeIndex", out destinationNodeIndex))
            {
                if (destinationNodeIndex >= 0 && destinationNodeIndex < _diagram.Nodes.Count)
                {
                    edge.DestinationNode = _diagram.Nodes[destinationNodeIndex];
                }
            }

            LoadItemPart(xEdge, edge);

            XElement xLabel = xEdge.Element("Label");
            if (xLabel != null)
            {
                LoadLabelFromXElement(xLabel, edge.Label);
            }
        }
 protected void RaiseLinkAdded(DiagramEdge link, NetworkObject obj)
 {
     if (LinkAdded != null)
         LinkAdded(link, obj);
 }
Example #11
0
        public static void UpdateEdgeStyleFromType(DiagramEdge edge, NetworkEdgeType type)
        {
            if (edge != null)
            {
                edge.Label.Text = Utils.ConvertType(type);
                edge.Label.AllowInPlaceEdit = false;

                Style style = new Style();
                Setter setter = new Setter();
                string str;
                switch (type)
                {
                    case NetworkEdgeType.Agent:
                        str = "Agent";
                        break;
                    case NetworkEdgeType.Recipient:
                        str = "Recipient";
                        break;
                    case NetworkEdgeType.Goal:
                        str = "Goal";
                        break;
                    case NetworkEdgeType.Locative:
                        str = "Locative";
                        break;
                    case NetworkEdgeType.Follow:
                        str = "Follow";
                        break;
                    case NetworkEdgeType.IsInstance:
                        str = "IsInstance";
                        break;
                    case NetworkEdgeType.Template:
                        str = "Template";
                        break;
                    case NetworkEdgeType.PartOf:
                        str = "PartOf";
                        break;
                    default:
                        str = "IsA";
                        break;
                }
                SolidColorBrush brush = App.Current.TryFindResource(str + "Brush") as SolidColorBrush;
                Pen pen = App.Current.FindResource(str + "Pen") as Pen;

                edge.BorderPen = pen;
                edge.Background = brush;
                edge.Label.Foreground = brush;
                edge.Label.FontWeight = FontWeights.Bold;
            }
        }
        private void CreateEdge(Point mousePosition)
        {
            var node = _mouseDownOnItem as DiagramNode;
            if (node == null)
            {
                var label = _mouseDownOnItem as DiagramLabel;
                node = label.Owner as DiagramNode;
            }
            if (node != null && !node.Bounds.Contains(mousePosition))
            {
                using (new DiagramUpdateLock(_diagram))
                {
                    var edge = new DiagramEdge(_diagram);
                    edge.AnchoringMode = EdgeAnchoringMode.NodeToPoint;
                    edge.SourceNode = node;
                    edge.DestinationPoint = mousePosition;
                    _currentResizeDirection = ResizeDirection.AllRoundDestination;

                    _diagram.Selection.Clear();
                    _diagram.Selection.Add(edge);
                }
                _leftButtonAction = MouseAction.MoveItem;
                _mouseDownOnItem = null;
            }
        }