public DiagramEdge(Diagram diagram)
            : base(diagram)
        {
            _sourceNode = null;
            _destinationNode = null;

            Background = new SolidColorBrush((BorderPen.Brush as SolidColorBrush).Color);

            _label = new DiagramLabel(diagram, this);
            _label.NeedRecalc = true;

            if (!diagram.Edges.Contains(this))
                diagram.Edges.Add(this);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            using (DiagramRenderLock diagramLock = new DiagramRenderLock(MyDiagram))
            {
                DiagramNode node = new DiagramNode(MyDiagram);
                node.Bounds = new Rect(50, 50, 50, 50);
                node.Background = new SolidColorBrush(Colors.Azure);
                node.RadiusX = 15;
                node.RadiusY = 15;
                node.Drawer = new RoundedRectangleItemDrawer();
                node.Label.Text = "AAZzzффффф";
                node.Label.Foreground = new SolidColorBrush(Colors.DarkRed);
                node.Label.FontStyle = FontStyles.Italic;

                DiagramNode node1 = new DiagramNode(MyDiagram);
                node1.Bounds = new Rect(75, 200, 50, 50);
                node1.Background = new SolidColorBrush(Colors.Violet);
                node1.Label.Text = "wow";
                LinearGradientBrush brush = new LinearGradientBrush();
                brush.GradientStops.Add(new GradientStop(Colors.White, 0));
                brush.GradientStops.Add(new GradientStop(Colors.Blue, 1));
                brush.Opacity = 0.5;
                node1.Label.Background = brush;
                node1.Label.BorderPen = new Pen(Brushes.BlanchedAlmond, 2);

                //DiagramEdge edge = new DiagramEdge(MyDiagram);
                //edge.SourcePoint = new Point(100, 100);
                //edge.DestinationPoint = new Point(150, 150);
                //edge.Label.Text = "lololol";
                //edge.Label.Background = brush;

                //DiagramEdge edge1 = new DiagramEdge(MyDiagram);
                //edge1.AnchoringMode = EdgeAnchoringMode.NodeToNode;
                //edge1.SourceNode = node;
                //edge1.DestinationNode = node1;
            }
        }
Example #3
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);
        }
Example #4
0
        private void DrawNode(DrawingContext dc, DiagramNode node, ref List<DiagramItem> itemsToDraw, bool considerViewport)
        {
            if (_itemsInDrawingOrder.Contains(node) || itemsToDraw.Contains(node))
                return;

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

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

            foreach (var edge in node.Edges)
            {
                DrawEdge(dc, edge, ref itemsToDraw, considerViewport);

                if (node == edge.SourceNode && edge.DestinationNode != null)
                    DrawNode(dc, edge.DestinationNode, ref itemsToDraw, considerViewport);

                if (node == edge.DestinationNode && edge.SourceNode != null)
                    DrawNode(dc, edge.SourceNode, ref itemsToDraw, considerViewport);
            }
        }
        private void SaveNodeToXElement(XElement xNodes, DiagramNode node)
        {
            XElement xNode = new XElement("Node");

            WriteElement(xNode, "RadiusX", node.RadiusX);
            WriteElement(xNode, "RadiusY", node.RadiusY);
            WriteElement(xNode, "Bounds", node.Bounds);

            SaveItemPart(xNode, node);

            if (node.Label != null)
                SaveLabelToXElement(xNode, node.Label);

            xNodes.Add(xNode);
        }
 private void LoadNodesFromXElement(XElement xNodes)
 {
     IEnumerable<XElement> xNodeList = xNodes.Elements("Node");
     foreach (var xNode in xNodeList)
     {
         DiagramNode node = new DiagramNode(_diagram);
         LoadNodeFromXElement(xNode, node);
     }
 }
        private void LoadNodeFromXElement(XElement xNode, DiagramNode node)
        {
            double tmp = 0;
            if (ReadElement(xNode, "RadiusX", out tmp))
            {
                node.RadiusX = tmp;
            }

            if (ReadElement(xNode, "RadiusY", out tmp))
            {
                node.RadiusY = tmp;
            }

            Rect bounds;
            if (ReadElement(xNode, "Bounds", out bounds))
            {
                node.Bounds = bounds;
            }

            LoadItemPart(xNode, node);

            XElement xLabel = xNode.Element("Label");
            if (xLabel != null)
            {
                LoadLabelFromXElement(xLabel, node.Label);
            }
        }
 protected void RaiseNodeAdded(DiagramNode node, NetworkObject obj)
 {
     if (NodeAdded != null)
         NodeAdded(node, obj);
 }
Example #9
0
        public static void UpdateNodeStyle(DiagramNode node)
        {
            if (node == null)
                return;

            SolidColorBrush brush = App.Current.TryFindResource("DefaultNodeBackgroundBrush") as SolidColorBrush;
            Pen pen = App.Current.FindResource("DefaultNodeBorderPen") as Pen;

            node.BorderPen = pen;
            node.Background = brush;
            node.Label.FontWeight = FontWeights.Bold;
        }
        private void OnSourceNodeChanged(DiagramNode oldSourceNode, DiagramNode newSourceNode)
        {
            var edge = this;

            if (oldSourceNode != null)
            {
                oldSourceNode.Edges.Remove(edge);
            }

            if (newSourceNode != null)
            {
                if (!newSourceNode.Edges.Contains(edge))
                    newSourceNode.Edges.Add(edge);
            }

            if (AnchoringMode == EdgeAnchoringMode.NodeToPoint || AnchoringMode == EdgeAnchoringMode.NodeToNode)
                OnLayoutPropertyChanged(this);

            RaiseSourceNodeChanged();
        }
        private void OnDesinationNodeChanged(DiagramNode oldDestinationNode, DiagramNode newDestinationNode)
        {
            var edge = this;

            if (oldDestinationNode != null)
            {
                oldDestinationNode.Edges.Remove(edge);
            }

            if (newDestinationNode != null)
            {
                if (!newDestinationNode.Edges.Contains(edge))
                    newDestinationNode.Edges.Add(edge);
            }

            if (AnchoringMode == EdgeAnchoringMode.PointToNode || AnchoringMode == EdgeAnchoringMode.NodeToNode)
                OnLayoutPropertyChanged(this);

            RaiseDestinationNodeChanged();
        }
 private void CreateNode(Point mousePosition)
 {
     using (new DiagramUpdateLock(_diagram))
     {
         var newNode = new DiagramNode(_diagram);
         newNode.Bounds = new Rect(mousePosition.X, mousePosition.Y, GlobalData.DefaultNodeSize.Width, GlobalData.DefaultNodeSize.Height);
     }
 }