Exemplo n.º 1
0
        internal static DNode CreateDNodeAndSetNodeBoundaryCurve(Graph drawingGraph, DGraph dGraph, GeometryNode geomNode,
                                                                 DrawingNode drawingNode, GViewer viewer){
            double width = 0;
            double height = 0;
            var dNode = new DNode(drawingNode, viewer);
            dGraph.AddNode(dNode);
            Drawing.Label label = drawingNode.Label;
            if (label != null){
                CreateDLabel(dNode, label, out width, out height, viewer);
                width += 2*dNode.DrawingNode.Attr.LabelMargin;
                height += 2*dNode.DrawingNode.Attr.LabelMargin;
            }
            if (width < drawingGraph.Attr.MinNodeWidth)
                width = drawingGraph.Attr.MinNodeWidth;
            if (height < drawingGraph.Attr.MinNodeHeight)
                height = drawingGraph.Attr.MinNodeHeight;

            // Filippo Polo: I'm taking this out because I've modified the drawing of a double circle
            // so that it can be used with ellipses too.
            //if (drawingNode.Attr.Shape == Shape.DoubleCircle)
            //width = height = Math.Max(width, height) * Draw.DoubleCircleOffsetRatio;
            ICurve curve;
            if (drawingNode.NodeBoundaryDelegate != null &&
                (curve = drawingNode.NodeBoundaryDelegate(drawingNode)) != null)
                geomNode.BoundaryCurve = curve;
            else if (geomNode.BoundaryCurve == null)
                geomNode.BoundaryCurve =
                    NodeBoundaryCurves.GetNodeBoundaryCurve(dNode.DrawingNode, width, height);
            return dNode;
        }
Exemplo n.º 2
0
        internal static DNode CreateDNodeAndSetNodeBoundaryCurveForSubgraph(Graph drawingGraph, DGraph dGraph, GeometryNode geomNode,
                                                                            DrawingNode drawingNode, GViewer viewer)
        {
            double width  = 0;
            double height = 0;
            var    dNode  = new DNode(drawingNode, viewer);

            dGraph.AddNode(dNode);
            Drawing.Label label = drawingNode.Label;
            if (label != null)
            {
                CreateDLabel(dNode, label, out width, out height, viewer);
            }
            if (width < drawingGraph.Attr.MinNodeWidth)
            {
                width = drawingGraph.Attr.MinNodeWidth;
            }
            if (height < drawingGraph.Attr.MinNodeHeight)
            {
                height = drawingGraph.Attr.MinNodeHeight;
            }

            var cluster = (Cluster)geomNode;
            var margin  = dNode.DrawingNode.Attr.LabelMargin;

            if (label != null)
            {
                CreateDLabel(dNode, label, out width, out height, viewer);
                width  += 2 * dNode.DrawingNode.Attr.LabelMargin + 2 * drawingNode.Attr.LineWidth;
                height += 2 * dNode.DrawingNode.Attr.LabelMargin + 2 * drawingNode.Attr.LineWidth;
            }
            cluster.RectangularBoundary = new RectangularClusterBoundary()
            {
                BottomMargin = margin,
                LeftMargin   = margin,
                RightMargin  = margin,
                TopMargin    = height,
                MinWidth     = width
            };
            // Filippo Polo: I'm taking this out because I've modified the drawing of a double circle
            // so that it can be used with ellipses too.
            //if (drawingNode.Attr.Shape == Shape.DoubleCircle)
            //width = height = Math.Max(width, height) * Draw.DoubleCircleOffsetRatio;
            ICurve curve;

            if (drawingNode.NodeBoundaryDelegate != null &&
                (curve = drawingNode.NodeBoundaryDelegate(drawingNode)) != null)
            {
                geomNode.BoundaryCurve = curve;
            }
            else if (geomNode.BoundaryCurve == null)
            {
                geomNode.BoundaryCurve =
                    NodeBoundaryCurves.GetNodeBoundaryCurve(dNode.DrawingNode, width, height);
            }
            return(dNode);
        }
Exemplo n.º 3
0
        /// <summary>
        /// creates DGraph from a precalculated drawing graph
        /// </summary>
        /// <param name="drawingGraph"></param>
        /// <param name="viewer">the owning viewer</param>
        /// <returns></returns>
        internal static DGraph CreateDGraphFromPrecalculatedDrawingGraph(Graph drawingGraph, GViewer viewer){
            var dGraph = new DGraph(drawingGraph, viewer);
            //create dnodes and node boundary curves

            if (drawingGraph.RootSubgraph != null)
                foreach (DrawingNode drawingNode in drawingGraph.RootSubgraph.AllSubgraphsWidthFirstExcludingSelf())
                {
                    var dNode = new DNode(drawingNode, viewer);
                    if (drawingNode.Label != null)
                        dNode.Label = new DLabel(dNode, drawingNode.Label, viewer);
                    dGraph.AddNode(dNode);
                }

            foreach (DrawingNode drawingNode in drawingGraph.Nodes){
                var dNode = new DNode(drawingNode, viewer);
                if (drawingNode.Label != null)
                    dNode.Label = new DLabel(dNode, drawingNode.Label, viewer);
                dGraph.AddNode(dNode);
            }

            
            foreach (DrawingEdge drawingEdge in drawingGraph.Edges)
                dGraph.AddEdge(new DEdge(dGraph.GetNode(drawingEdge.SourceNode), dGraph.GetNode(drawingEdge.TargetNode),
                                      drawingEdge, ConnectionToGraph.Connected, viewer));

            return dGraph;
        }
Exemplo n.º 4
0
        internal static DGraph CreateDGraphAndGeometryInfo(Graph drawingGraph, GeometryGraph geometryGraph,
                                                           GViewer viewer) {
            var dGraph = new DGraph(drawingGraph, viewer);
            //create dnodes and glee node boundary curves
            var nodeMapping = new Dictionary<GeometryNode, DNode>();
            if (geometryGraph.RootCluster != null)
                foreach (var geomCluster in geometryGraph.RootCluster.AllClustersDepthFirstExcludingSelf()) {
                    var drawingNode = (Drawing.Node) geomCluster.UserData;
                    DNode dNode = CreateDNodeAndSetNodeBoundaryCurveForSubgraph(drawingGraph, dGraph, geomCluster,
                                                                                drawingNode, viewer);
                    nodeMapping[geomCluster] = dNode;
                }

            foreach (GeometryNode geomNode in geometryGraph.Nodes) {
                var drawingNode = (Drawing.Node) geomNode.UserData;
                DNode dNode = CreateDNodeAndSetNodeBoundaryCurve(drawingGraph, dGraph, geomNode, drawingNode, viewer);
                nodeMapping[geomNode] = dNode;
            }

            foreach (GeometryEdge gleeEdge in geometryGraph.Edges) {
                var dEdge = new DEdge(nodeMapping[gleeEdge.Source], nodeMapping[gleeEdge.Target],
                                      gleeEdge.UserData as DrawingEdge, ConnectionToGraph.Connected, viewer);
                dGraph.AddEdge(dEdge);
                DrawingEdge drawingEdge = dEdge.Edge;
                Drawing.Label label = drawingEdge.Label;

                if (label != null) {
                    double width, height;
                    CreateDLabel(dEdge, label, out width, out height, viewer);
                }
            }

            return dGraph;
        }
Exemplo n.º 5
0
        internal static bool DrawDebugStuff(Graphics g, DGraph graphToDraw, Pen myPen)
        {
            bool debugDrawing = false;

            if (graphToDraw.DrawingGraph.debugPolylines != null)
            {
                foreach (Polyline p in graphToDraw.DrawingGraph.debugPolylines)
                {
                    SetColor(graphToDraw, myPen, p);
                    if (p.Closed)
                    {
                        g.FillPolygon(new SolidBrush(myPen.Color), GetPolylinePoints(p));
                    }
                    else
                    {
                        g.DrawLines(myPen, GetPolylinePoints(p));
                    }
                }
            }

            if (graphToDraw.DrawingGraph.DebugLines != null)
            {
                debugDrawing = true;
                foreach (LineSegment bs in graphToDraw.DrawingGraph.DebugLines)
                {
                    SetColor(graphToDraw, myPen, bs);
                    g.DrawLine(myPen, (float)bs.Start.X, (float)bs.Start.Y, (float)bs.End.X, (float)bs.End.Y);
                }
            }
            if (graphToDraw.DrawingGraph.DebugBezierCurves != null)
            {
                debugDrawing = true;
                foreach (CubicBezierSegment bs in graphToDraw.DrawingGraph.DebugBezierCurves)
                {
                    SetColor(graphToDraw, myPen, bs);
                    g.DrawBezier(myPen, (float)bs.B(0).X, (float)bs.B(0).Y,
                                 (float)bs.B(1).X, (float)bs.B(1).Y,
                                 (float)bs.B(2).X, (float)bs.B(2).Y,
                                 (float)bs.B(3).X, (float)bs.B(3).Y);
                    if (graphToDraw.DrawingGraph.ShowControlPoints)
                    {
                        DrawControlPoints(g, bs);
                    }
                }
            }

            if (graphToDraw.DrawingGraph.DebugEllipses != null)
            {
                debugDrawing = true;

                foreach (Ellipse el in graphToDraw.DrawingGraph.DebugEllipses)
                {
                    SetColor(graphToDraw, myPen, el);
                    g.DrawEllipse(myPen, (float)(el.Center.X - el.AxisA.X), (float)(el.Center.Y - el.AxisB.Y), (float)(el.AxisA.X * 2), Math.Abs((float)el.AxisB.Y * 2));
                }
            }

            myPen.Color = System.Drawing.Color.Red;
            if (graphToDraw.DrawingGraph.DebugBoxes != null)
            {
                debugDrawing = true;

                foreach (Parallelogram pb in graphToDraw.DrawingGraph.DebugBoxes)
                {
                    SetColor(graphToDraw, myPen, pb);
                    PointF[] ps = new PointF[4];
                    for (int i = 0; i < 4; i++)
                    {
                        ps[i] = new PointF((float)pb.Vertex((VertexId)i).X, (float)pb.Vertex((VertexId)i).Y);
                    }
                    g.DrawPolygon(myPen, ps);
                }
            }
            return(debugDrawing);
        }
Exemplo n.º 6
0
        internal static DNode CreateDNodeAndSetNodeBoundaryCurve(DrawingGraph drawingGraph, DGraph dGraph, GeometryNode geomNode, DrawingNode drawingNode)
        {
            double width  = 0;
            double height = 0;
            DNode  dNode  = new DNode(drawingNode);

            dGraph.AddNode(dNode);
            Microsoft.Msagl.Drawing.Label label = drawingNode.Label;
            if (label != null)
            {
                CreateDLabel(dNode, label, out width, out height);
                width  += 2 * dNode.DrawingNode.Attr.LabelMargin;
                height += 2 * dNode.DrawingNode.Attr.LabelMargin;
            }
            if (width < drawingGraph.Attr.MinNodeWidth)
            {
                width = drawingGraph.Attr.MinNodeWidth;
            }
            if (height < drawingGraph.Attr.MinNodeHeight)
            {
                height = drawingGraph.Attr.MinNodeHeight;
            }

            // Filippo Polo: I'm taking this out because I've modified the drawing of a double circle
            // so that it can be used with ellipses too.
            //if (drawingNode.Attr.Shape == Shape.DoubleCircle)
            //width = height = Math.Max(width, height) * Draw.DoubleCircleOffsetRatio;
            if (geomNode.BoundaryCurve == null)
            {
                geomNode.BoundaryCurve = Microsoft.Msagl.Drawing.NodeBoundaryCurves.GetNodeBoundaryCurve(dNode.DrawingNode, width, height);
            }
            return(dNode);
        }
 static void SetColor(DGraph graphToDraw, Pen myPen, object bs){
     // Microsoft.Msagl.Drawing.Color color;
     if(bs is CubicBezierSegment)
         myPen.Color = Color.Green;
     else if(bs is Polyline)
         myPen.Color = Color.Brown;
     else
         myPen.Color = Color.Blue;
 }
        internal static void DrawDebugStuff(Graphics g, DGraph graphToDraw, Pen myPen){
            if(graphToDraw.DrawingGraph.DebugICurves != null){
                foreach (ICurve c in graphToDraw.DrawingGraph.DebugICurves){
                    DrawDebugICurve(graphToDraw, c, myPen, g);
                }
            }

            if(graphToDraw.DrawingGraph.DebugCurves != null){
                foreach (DebugCurve shape in graphToDraw.DrawingGraph.DebugCurves)
                    DrawDebugCurve(graphToDraw, shape, g);
            }
        }
 static void DrawBezier(DGraph graphToDraw, Pen myPen, Graphics g, CubicBezierSegment bs){
     g.DrawBezier(myPen, (float) bs.B(0).X, (float) bs.B(0).Y,
                  (float) bs.B(1).X, (float) bs.B(1).Y,
                  (float) bs.B(2).X, (float) bs.B(2).Y,
                  (float) bs.B(3).X, (float) bs.B(3).Y);
     if(graphToDraw.DrawingGraph.ShowControlPoints)
         DrawControlPoints(g, bs);
 }
Exemplo n.º 10
0
        static void DrawDebugICurve(DGraph graphToDraw, ICurve c, Pen myPen, Graphics g) {
            var p = c as Polyline;
            if (p != null) {
                SetColor(graphToDraw, myPen, p);
                DrawPolyline(p, myPen, g);
            }
            else {
                var lineSeg = c as LineSegment;

                if (lineSeg != null) {
                    SetColor(graphToDraw, myPen, lineSeg);

                    DrawLine(myPen, g, lineSeg);
                }
                else {
                    var bs = c as CubicBezierSegment;
                    if (bs != null) {
                        SetColor(graphToDraw, myPen, bs);
                        DrawBezier(graphToDraw, myPen, g, bs);
                    }
                    else {
                        var el = c as Ellipse;
                        if (el != null) {
                            SetColor(graphToDraw, myPen, el);
                            DrawArc(myPen, g, el);
                        }
                        else {
                            var curve = c as Curve;
                            if (curve != null)
                                foreach (ICurve ss in curve.Segments)
                                    DrawDebugICurve(graphToDraw, ss, myPen, g);
                            else {
                                var rect = c as RoundedRect;
                                if (rect != null) {
                                    foreach (ICurve ss in rect.Curve.Segments)
                                        DrawDebugICurve(graphToDraw, ss, myPen, g);
                                }
                            }

                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
        static void DrawSimpleSeg(ICurve c, Graphics g, Pen myPen, DGraph graphToDraw) {
            var lineSeg = c as LineSegment;

            if (lineSeg != null) {
                g.DrawLine(myPen, (float) lineSeg.Start.X, (float) lineSeg.Start.Y, (float) lineSeg.End.X,
                           (float) lineSeg.End.Y);
            }
            else {
                var bs = c as CubicBezierSegment;
                if (bs != null) {
                    g.DrawBezier(myPen, (float) bs.B(0).X, (float) bs.B(0).Y,
                                 (float) bs.B(1).X, (float) bs.B(1).Y,
                                 (float) bs.B(2).X, (float) bs.B(2).Y,
                                 (float) bs.B(3).X, (float) bs.B(3).Y);
                    if (graphToDraw.DrawingGraph.ShowControlPoints)
                        DrawControlPoints(g, bs);
                }
                else {
                    var el = c as Ellipse;
                    if (el != null) {
                        DrawArc(myPen, g, el);
                    }
                    else {
                        throw new InvalidOperationException();
                    }
                }
            }
        }
Exemplo n.º 12
0
        static void DrawDebugCurve(DGraph graphToDraw, ICurve c, Pen myPen, SolidBrush solidBrush, Graphics g, object id){
            
            var p = c as Polyline;
            if (p != null)
            {
                if (solidBrush.Color!=Color.Transparent)
                    g.FillPolygon(solidBrush, GetPolylinePoints(p));
                if (p.Closed) {
                    g.DrawPolygon(myPen, GetPolylinePoints(p));
                   
                }
                else
                    g.DrawLines(myPen, GetPolylinePoints(p));
                
            }
            else {
                if (SimpleSeg(c)) {
                    DrawSimpleSeg(c, g, myPen, graphToDraw);
                }
                else {
                    var curve = c as Curve;
                    if (curve != null)
                        foreach (ICurve ss in curve.Segments) {
                            DrawSimpleSeg(ss, g, myPen, graphToDraw);
                        }
                    else {
                        var rect = c as RoundedRect;
                        if (rect != null) {
                            foreach (ICurve ss in rect.Curve.Segments)
                                DrawSimpleSeg(ss, g, myPen, graphToDraw);
                        }}
                }
            }
            if(id!=null && c!=null)
            {
                var s = id.ToString();
                var brush = new SolidBrush(myPen.Color);
                var point = c.Start;
                var rect = new RectangleF((float)c.Start.X, (float)c.Start.Y, (float)c.BoundingBox.Width, (float)c.BoundingBox.Height);
                DrawStringInRectCenter(g, brush, new Font(FontFamily.GenericSerif, 10),s, rect );

            }

        }
Exemplo n.º 13
0
        static void DrawDebugCurve(DGraph graph, DebugCurve debugCurve, Graphics graphics) {

            using (var pen = new Pen(GetColorFromString(debugCurve), (float) debugCurve.Width)) 
            using (var brush=new SolidBrush(GetFillColorFromString(debugCurve))){
                if (debugCurve.DashArray != null) {
                    pen.DashStyle = DashStyle.Dash;
                    pen.DashPattern = CreateDashArray(debugCurve.DashArray);
                    pen.DashOffset = pen.DashPattern[0];
                }
                DrawDebugCurve(graph, debugCurve.Curve, pen, brush, graphics, debugCurve.Label);
            }
        }