コード例 #1
0
            void CreateNodeGeometry(DrawingNode node, Graph graph, GeometryGraph geometryGraph, GeometryPoint center, ConnectionToGraph connectionTo = ConnectionToGraph.Connected)
            {
                double width, height;

                StringMeasure.MeasureWithFont(node.Label.Text, new Font(node.Label.FontName, (float)node.Label.FontSize, (System.Drawing.FontStyle)(int) node.Label.FontStyle), out width,
                                              out height);

                node.Label.Width  = width;
                node.Label.Height = height;

                if (node.Label != null)
                {
                    width  += 2 * node.Attr.LabelMargin;
                    height += 2 * node.Attr.LabelMargin;
                }
                if (width < graph.Attr.MinNodeWidth)
                {
                    width = graph.Attr.MinNodeWidth;
                }
                if (height < graph.Attr.MinNodeHeight)
                {
                    height = graph.Attr.MinNodeHeight;
                }

                Node geomNode =
                    node.GeometryNode =
                        GeometryGraphCreator.CreateGeometryNode(graph, geometryGraph, node, connectionTo);

                geomNode.BoundaryCurve = NodeBoundaryCurves.GetNodeBoundaryCurve(node, width, height);
                geomNode.BoundaryCurve.Translate(center);
                geomNode.Center = center;
            }
コード例 #2
0
        public static void addLineEdge(GraphViewer gv, string src, string tar)
        {
            var graph = gv.Graph;
            var edge  = graph.AddEdge(src, null, tar);

            edge.SourceNode.AddOutEdge(edge);
            edge.TargetNode.AddInEdge(edge);

            var ledge = GeometryGraphCreator.CreateGeometryEdgeFromDrawingEdge(edge);

            //ledge.Source = edge.SourceNode.GeometryNode;
            //ledge.Target = edge.TargetNode.GeometryNode;
            ledge.Source.AddOutEdge(ledge);
            ledge.Target.AddInEdge(ledge);
            edge.GeometryEdge = ledge;
            ledge.Curve       = new Microsoft.Msagl.Core.Geometry.Curves.LineSegment(ledge.Source.Center, ledge.Target.Center);
            //gv.AddEdge(gv.CreateEdgeWithGivenGeometry(edge), true);
            Microsoft.Msagl.Layout.LargeGraphLayout.LgLayoutSettings lgsets = null;

            Microsoft.Msagl.Routing.StraightLineEdges.RouteEdge(ledge, 0);
            var oute = gv.CreateEdgeWithGivenGeometry(edge);

            gv.LayoutEditor.AttachLayoutChangeEvent(oute);
            gv.Invalidate();
            var sss = oute.Target;
            //gv.RouteEdge(edge);
        }
コード例 #3
0
        public IViewerEdge RouteEdge(DrawingEdge drawingEdge)
        {
            var geomEdge  = GeometryGraphCreator.CreateGeometryEdgeFromDrawingEdge(drawingEdge);
            var geomGraph = drawingGraph.GeometryGraph;

            LayoutHelpers.RouteAndLabelEdges(geomGraph, drawingGraph.LayoutAlgorithmSettings, new[] { geomEdge });
            return(CreateEdge(drawingEdge, drawingGraph.LayoutAlgorithmSettings as LgLayoutSettings));
        }
コード例 #4
0
        internal void CreateEdge()
        {
            if (Model == null)
            {
                return;
            }

            if (this.Source.Label == null || this.Target.Label == null)
            {
                return;
            }

            Dictionary <string, Entity> entitiesLookup = Model.DisplayedSubmodel.Entities.ToDictionary(x => x.Label, y => y);

            if ((entitiesLookup.ContainsKey(Source.Label) || entitiesLookup.ContainsKey(Target.Label)) == false)
            {
                return;
            }

            if (drawingEdge != null)
            {
                DeleteDrawingEdge(false);
            }

            if (Model.Graph != null)
            {
                drawingEdge       = Model.Graph.AddEdge(Source.Label, Target.Label);
                drawingEdge.Attr  = CreateEdgeAttr();
                drawingEdge.Label = CreateLabel(drawingEdge, Model.ShowRelationshipLabels ? Type : "");

                LayoutEdge coreEdge = GeometryGraphCreator.CreateGeometryEdgeFromDrawingEdge(drawingEdge);
                CreateEdgeCurve(drawingEdge, coreEdge);

                Model.GeometryGraph.Edges.Add(coreEdge);
                drawingEdge.GeometryEdge = coreEdge;
                drawingEdge.UserData     = this;
            }
            else
            {
                if (IsAddedOnViewGraph)
                {
                    IsAddedOnViewGraph = false;
                    return;
                }

                DrawingNode source = Model.GraphEditor.Graph.FindNode(Source.Label);
                DrawingNode target = Model.GraphEditor.Graph.FindNode(Target.Label);

                if (target != null)
                {
                    drawingEdge = Model.GraphEditor.Viewer.AddEdge(source, target, false);

                    drawingEdge.Attr     = CreateEdgeAttr();
                    drawingEdge.UserData = this;
                }
                RenameEdge();
            }
        }
コード例 #5
0
        public static IViewerNode addVnodeByDnode(GraphViewer gv, Node node, DPoint pos)
        {
            var graph = gv.Graph;

            Debug.Assert(node.GeometryNode == null);
            LNode lnode     = GeometryGraphCreator.CreateGeometryNode(graph, graph.GeometryGraph, node, ConnectionToGraph.Disconnected);
            var   labelSize = Common.MeasureLabel(node.Label);
            var   mar       = node.Attr.LabelMargin;

            lnode.BoundaryCurve = NodeBoundaryCurves.GetNodeBoundaryCurve(node, labelSize.Width + mar * 2, labelSize.Height + mar * 2);
            node.GeometryNode   = lnode;

            var vnode = gv.CreateIViewerNode(node, pos, null);

            return(vnode);
        }
コード例 #6
0
        public static IViewerNode addNode(GraphViewer gv, string id, double x, double y)
        {
            //var node = new Node(id);
            var graph     = gv.Graph;
            var node      = graph.AddNode(id);
            var lnode     = GeometryGraphCreator.CreateGeometryNode(graph, graph.GeometryGraph, node, ConnectionToGraph.Disconnected);
            var labelSize = Common.MeasureLabel(node.Label);

            lnode.BoundaryCurve = NodeBoundaryCurves.GetNodeBoundaryCurve(node, labelSize.Width, labelSize.Height);
            node.GeometryNode   = lnode;
            var vnode = gv.CreateIViewerNode(node, new DPoint(x, y), null);

            return(vnode);
            //gv.AddNode(vnode, true);
            //gv.CreateVNode(node);
        }
コード例 #7
0
        void InsertNodeIntoGraph(Rectangle rectangle)
        {
            Node node = new Node("testNode");

            node.Attr.FillColor = Color.Red;
            node.Attr.Shape     = Shape.DrawFromGeometry;
            node.Label          = null;
            var geomNode =
                node.GeometryNode = GeometryGraphCreator.CreateGeometryNode(gViewer.Graph, gViewer.Graph.GeometryGraph, node, ConnectionToGraph.Disconnected);
            var center = (rectangle.LeftBottom + rectangle.RightTop) / 2;

            geomNode.BoundaryCurve = CurveFactory.CreateRectangle(rectangle.Width, rectangle.Height, center);
            node.GeometryNode      = geomNode;
            var dNode = gViewer.CreateIViewerNode(node);

            gViewer.AddNode(dNode, true);
        }
コード例 #8
0
        private void InitPalette()
        {
            foreach (var type in this.graph.GetNodeTypes())
            {
                var button = new Button {
                    Text = type.Name, Dock = DockStyle.Bottom
                };
                button.Click += (sender, args) =>
                {
                    var node = this.graph.CreateNewNode(type);
                    node.GeometryNode = GeometryGraphCreator.CreateGeometryNode(this.viewer.Graph, this.viewer.Graph.GeometryGraph, node, ConnectionToGraph.Disconnected);
                    var viewNode = this.viewer.CreateIViewerNode(node, this.viewer.Graph.Nodes.ToList()[0].Pos - new Point(250, 0), null);
                    this.viewer.AddNode(viewNode, true);
                    this.viewer.Graph.AddNode(node);
                    this.viewer.Invalidate();
                };
                button.Font = new Font(button.Font.FontFamily, fontSize);
                button.Size = new Size(button.Width, button.Height + 10);
                this.paletteGrid.Controls.Add(button, 0, this.paletteGrid.RowCount - 1);

                ++this.paletteGrid.RowCount;
            }
        }
コード例 #9
0
        public static IViewerNode addNodeWithStyles(GraphViewer gv, string id, DPoint pos, ICollection <Style> styles)
        {
            var graph = gv.Graph;
            var node  = graph.AddNode(id);

            if (styles != null)
            {
                foreach (var s in styles)
                {
                    node.Attr.AddStyle(s);
                }
            }

            var lnode     = GeometryGraphCreator.CreateGeometryNode(graph, graph.GeometryGraph, node, ConnectionToGraph.Disconnected);
            var labelSize = Common.MeasureLabel(node.Label);
            var mar       = node.Attr.LabelMargin;

            lnode.BoundaryCurve = NodeBoundaryCurves.GetNodeBoundaryCurve(node, labelSize.Width + mar * 2, labelSize.Height + mar * 2);
            node.GeometryNode   = lnode;
            var vnode = gv.CreateIViewerNode(node, pos, null);

            return(vnode);
        }
コード例 #10
0
        public static IViewerEdge addLineEdge2(GraphViewer gv, string src, string tar)
        {
            var graph = gv.Graph;
            var edge  = graph.AddEdge(src, null, tar);

            edge.SourceNode.AddOutEdge(edge);
            edge.TargetNode.AddInEdge(edge);

            var ledge = GeometryGraphCreator.CreateGeometryEdgeFromDrawingEdge(edge);

            ledge.Source.AddOutEdge(ledge);
            ledge.Target.AddInEdge(ledge);
            ledge.GeometryParent = graph.GeometryGraph;
            graph.GeometryGraph.Edges.Add(ledge);
            edge.GeometryEdge = ledge;
            //ledge.Curve = new LineSegment(ledge.Source.Center, ledge.Target.Center);
            //gv.AddEdge(gv.CreateEdgeWithGivenGeometry(edge), true);
            Microsoft.Msagl.Routing.StraightLineEdges.RouteEdge(ledge, 0);
            var oute = gv.CreateEdgeWithGivenGeometry(edge);

            gv.LayoutEditor.AttachLayoutChangeEvent(oute);
            return(oute);
        }