Пример #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
        static Graph CtreateDrawingGraph(out FastIncrementalLayoutSettings settings)
        {
            settings = new FastIncrementalLayoutSettings {
                RouteEdges = true, NodeSeparation = 30
            };
            var drawingGraph = new Graph();

            AddEdge(drawingGraph, "0", "1");
            AddEdge(drawingGraph, "0", "2");
            AddEdge(drawingGraph, "1", "3");
            AddEdge(drawingGraph, "2", "4");
            AddEdge(drawingGraph, "2", "5");
            AddEdge(drawingGraph, "2", "6");
            AddEdge(drawingGraph, "5", "7");
            AddEdge(drawingGraph, "5", "6");
            AddEdge(drawingGraph, "7", "8");
            AddEdge(drawingGraph, "8", "6");


            drawingGraph.CreateGeometryGraph();
            foreach (DrawingNode node in drawingGraph.Nodes)
            {
                double w, h;
                var    label = node.Label;
                var    font  = new Font(label.FontName, (float)label.FontSize);
                StringMeasure.MeasureWithFont(label.Text, font, out w, out h);
                node.Label.Width  = w;
                node.Label.Height = h;
                node.Attr.Shape   = Shape.DrawFromGeometry;
                node.GeometryNode.BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(1.2 * w, 1.2 * h, 3, 3, new Point());
            }

            return(drawingGraph);
        }
Пример #3
0
        private void CreateBoundaryCurve(Microsoft.Msagl.Drawing.Node node)
        {
            double w, h;
            var    label = node.Label;
            var    font  = new Font(label.FontName, (float)label.FontSize);

            StringMeasure.MeasureWithFont(label.Text, font, out w, out h);
            node.Label.Width  = w;
            node.Label.Height = h;
            node.Attr.Shape   = Shape.DrawFromGeometry;
            node.GeometryNode.BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(1.2 * w, 1.2 * h, 3, 3, new Microsoft.Msagl.Core.Geometry.Point());
        }
Пример #4
0
        private static void SetNodeBoundary(Microsoft.Msagl.Drawing.Node drawingNode)
        {
            var font = new System.Drawing.Font(drawingNode.Label.FontName, (float)drawingNode.Label.FontSize);

            StringMeasure.MeasureWithFont(drawingNode.LabelText, font, out double width, out double height);
            drawingNode.Label.GeometryLabel        = new Microsoft.Msagl.Core.Layout.Label();
            drawingNode.Label.GeometryLabel.Width  = width;
            drawingNode.Label.GeometryLabel.Height = width;
            drawingNode.Label.Width  = width;
            drawingNode.Label.Height = height;
            int r = drawingNode.Attr.LabelMargin;

            drawingNode.GeometryNode.BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(width + r * 2, height + r * 2, r, r, new Point());
        }
        static ICurve CreateLabelAndBoundary(Node node)
        {
            node.Attr.Shape        = Shape.DrawFromGeometry;
            node.Attr.LabelMargin *= 2;
            double width;
            double height;

            StringMeasure.MeasureWithFont(node.Label.Text,
                                          new Font(node.Label.FontName, (float)node.Label.FontSize), out width, out height);
            node.Label.Width  = width;
            node.Label.Height = height;
            int r = node.Attr.LabelMargin;

            return(CurveFactory.CreateRectangleWithRoundedCorners(width + r * 2, height + r * 2, r, r, new Point()));
        }
Пример #6
0
        private static void InitNodeBoundary(Node node)
        {
            double width  = 0;
            double height = 0;

            if (node.Label != null)
            {
                var font = new Font(node.Label.FontName, (float)node.Label.FontSize);
                StringMeasure.MeasureWithFont(node.LabelText, font, out width, out height);
            }
            if (width <= 0)
            {
                StringMeasure.MeasureWithFont("a", new Font("New Courer", 10), out width, out height);
            }

            node.GeometryNode.BoundaryCurve = CurveFactory.CreateEllipse(width / 2, height / 2, new Point());
        }
Пример #7
0
        DrawingLabel CreateLabel(DrawingEdge edge, string rel)
        {
            DrawingLabel label = new DrawingLabel
            {
                Text      = rel,
                FontName  = "Times-Roman",
                FontColor = Styles.RELATION_LABEL_COLOR.ToMsAgl(),
                FontStyle = Microsoft.Msagl.Drawing.FontStyle.Regular,
                FontSize  = 4,
                Owner     = edge,
            };

            double width, height;

            StringMeasure.MeasureWithFont(rel, new Font(label.FontName, (float)label.FontSize, (System.Drawing.FontStyle)(int) label.FontStyle), out width,
                                          out height);
            label.Width  = width;
            label.Height = height;

            return(label);
        }
Пример #8
0
        void GViewerOnMouseMove(object sender, MouseEventArgs mouseEventArgs)
        {
            if (labelToChange == null)
            {
                return;
            }
            labelToChange.Text = MousePosition.ToString();
            if (viewerEntityCorrespondingToLabelToChange == null)
            {
                foreach (var e in gViewer.Entities)
                {
                    if (e.DrawingObject == labelToChange)
                    {
                        viewerEntityCorrespondingToLabelToChange = e;
                        break;
                    }
                }
            }
            if (viewerEntityCorrespondingToLabelToChange == null)
            {
                return;
            }
            var    rect = labelToChange.BoundingBox;
            var    font = new Font(labelToChange.FontName, (int)labelToChange.FontSize);
            double width;
            double height;

            StringMeasure.MeasureWithFont(labelToChange.Text, font, out width, out height);

            if (width <= 0)
            {
                //this is a temporary fix for win7 where Measure fonts return negative lenght for the string " "
                StringMeasure.MeasureWithFont("a", font, out width, out height);
            }

            labelToChange.Width  = width;
            labelToChange.Height = height;
            rect.Add(labelToChange.BoundingBox);
            gViewer.Invalidate(gViewer.MapSourceRectangleToScreenRectangle(rect));
        }
Пример #9
0
        private static ICurve GetNodeBoundary(DrawingNode node)
        {
            double width;
            double height;
            var    font = new Font(node.Label.FontName, (float)node.Label.FontSize, (System.Drawing.FontStyle)(int) node.Label.FontStyle);

            StringMeasure.MeasureWithFont(node.Label.Text, font, out width, out height);
            width  += node.Attr.LabelMargin * 2;
            height += node.Attr.LabelMargin * 2;
            if (width <= 0)
            {
                // Temporary fix for Win7 where Measure fonts return negative length for the string " ".
                StringMeasure.MeasureWithFont("a", font, out width, out height);
            }

            if ((node.UserData as NodeDisplaySettings).Icon != null)
            {
                width += kIconSize;
            }

            return(NodeBoundaryCurves.GetNodeBoundaryCurve(node, width, height));
        }
Пример #10
0
        void GViewerOnMouseMove(Edge edge, string value)
        {
            if (edge.Label == null)
            {
                return;
            }
            edge.Label.Text = value;

            var rect = edge.Label.BoundingBox;
            var font = new Font(edge.Label.FontName, (int)edge.Label.FontSize);

            StringMeasure.MeasureWithFont(edge.Label.Text, font, out double width, out double height);

            if (width <= 0)
            {
                StringMeasure.MeasureWithFont("a", font, out width, out height);
            }

            edge.Label.Width  = width;
            edge.Label.Height = height;
            rect.Add(edge.Label.BoundingBox);
            gViewer.Invalidate(gViewer.MapSourceRectangleToScreenRectangle(rect));
        }
Пример #11
0
        private void SetGraph()
        {
            var graph = new Graph();

            graph.AddEdge("a", "b");
            graph.AddEdge("e", "b");
            graph.AddEdge("d", "b");
            graph.AddEdge("b", "c");

            graph.AddEdge("a22", "b22");
            graph.AddEdge("e22", "b22");
            graph.AddEdge("d22", "b22");
            graph.AddEdge("b22", "c22");

            graph.AddEdge("a0", "b0");
            graph.AddEdge("b0", "c0");

            graph.AddEdge("a33", "b33");
            graph.AddEdge("e33", "b33");
            graph.AddEdge("d33", "b33");
            graph.AddEdge("b33", "c33");

            graph.AddEdge("a11", "b11");
            graph.AddEdge("b11", "c11").LabelText = "Test labels!";

            graph.CreateGeometryGraph();
            foreach (Node node in graph.Nodes)
            {
                node.GeometryNode.BoundaryCurve = CreateLabelAndBoundary(node);
            }

            foreach (var edge in graph.Edges)
            {
                if (edge.Label != null)
                {
                    var    geomEdge = edge.GeometryEdge;
                    double width;
                    double height;
                    StringMeasure.MeasureWithFont(edge.LabelText,
                                                  new Font(edge.Label.FontName, (float)edge.Label.FontSize), out width, out height);
                    edge.Label.GeometryLabel = geomEdge.Label = new Label(width, height, geomEdge);
                }
            }

            var geomGraph = graph.GeometryGraph;

            var geomGraphComponents = GraphConnectedComponents.CreateComponents(geomGraph.Nodes, geomGraph.Edges);
            var settings            = new SugiyamaLayoutSettings();

            foreach (var subgraph in geomGraphComponents)
            {
                var layout = new LayeredLayout(subgraph, settings);
                subgraph.Margins = settings.NodeSeparation / 2;
                layout.Run();
            }

            Microsoft.Msagl.Layout.MDS.MdsGraphLayout.PackGraphs(geomGraphComponents, settings);

            geomGraph.UpdateBoundingBox();


            gViewer1.NeedToCalculateLayout = false;
            gViewer1.Graph = graph;
        }