Ejemplo n.º 1
0
        internal static void DrawEdge(Graphics graphics, DEdge dEdge)
        {
            DrawingEdge drawingEdge = dEdge.DrawingEdge;

            if (!drawingEdge.IsVisible || drawingEdge.GeometryEdge == null)
            {
                return;
            }


            DrawingEdge edge = dEdge.DrawingEdge;

            if (edge.DrawEdgeDelegate != null)
            {
                if (edge.DrawEdgeDelegate(edge, graphics))
                {
                    return; //the client draws instead
                }
            }
            if (dEdge.GraphicsPath == null)
            {
                dEdge.GraphicsPath = Draw.CreateGraphicsPath(dEdge.Edge.GeometryEdge.Curve);
            }

            EdgeAttr attr = drawingEdge.Attr;

            using (var myPen = new Pen(dEdge.Color, (float)attr.LineWidth)) {
                foreach (Style style in attr.Styles)
                {
                    Draw.AddStyleForPen(dEdge, myPen, style);
                }
                try {
                    if (dEdge.GraphicsPath != null)
                    {
                        graphics.DrawPath(myPen, dEdge.GraphicsPath);
                    }
                }
                catch {
                    //  sometimes on Vista it throws an out of memory exception without any obvious reason
                }
                Draw.DrawEdgeArrows(graphics, drawingEdge, dEdge.Color, myPen);
                if (dEdge.DrawingEdge.GeometryEdge.Label != null)
                {
                    Draw.DrawLabel(graphics, dEdge.Label);
                }

#if TEST_MSAGL
                if (DrawControlPoints)
                {
                    ICurve iCurve = dEdge.DrawingEdge.GeometryEdge.Curve;
                    var    c      = iCurve as Curve;

                    if (c != null)
                    {
                        foreach (ICurve seg in c.Segments)
                        {
                            var cubic = seg as CubicBezierSegment;
                            if (cubic != null)
                            {
                                Draw.DrawControlPoints(graphics, cubic);
                            }
                        }
                    }
                    else
                    {
                        var seg = iCurve as CubicBezierSegment;
                        if (seg != null)
                        {
                            Draw.DrawControlPoints(graphics, seg);
                        }
                    }
                }
#endif
            }
        }
Ejemplo n.º 2
0
        internal void DrawNode(Graphics g, DNode dnode)
        {
            DrawingNode node = dnode.DrawingNode;

            if (node.IsVisible == false)
            {
                return;
            }

            if (node.DrawNodeDelegate != null)
            {
                if (node.DrawNodeDelegate(node, g))
                {
                    return; //the client draws instead
                }
            }
            if (node.GeometryNode == null || node.GeometryNode.BoundaryCurve == null) //node comes with non-initilalized attribute - should not be drawn
            {
                return;
            }
            NodeAttr attr = node.Attr;

            using (var pen = new Pen(dnode.Color, (float)attr.LineWidth)) {
                foreach (Style style in attr.Styles)
                {
                    Draw.AddStyleForPen(dnode, pen, style);
                }
                switch (attr.Shape)
                {
                case Shape.DoubleCircle:
                    Draw.DrawDoubleCircle(g, pen, dnode);
                    break;

                case Shape.Box:
                    Draw.DrawBox(g, pen, dnode);
                    break;

                case Shape.Diamond:
                    Draw.DrawDiamond(g, pen, dnode);
                    break;

                case Shape.Point:
                    Draw.DrawEllipse(g, pen, dnode);
                    break;

                case Shape.Plaintext: {
                    break;
                    //do nothing
                }

                case Shape.Octagon:
                case Shape.House:
                case Shape.InvHouse:
                case Shape.Ellipse:
                case Shape.DrawFromGeometry:

#if TEST_MSAGL
                case Shape.TestShape:
#endif
                    pen.EndCap = LineCap.Square;
                    Draw.DrawFromMsaglCurve(g, pen, dnode);
                    break;

                default:
                    Draw.DrawEllipse(g, pen, dnode);
                    break;
                }
            }
            Draw.DrawLabel(g, dnode.Label);
        }
Ejemplo n.º 3
0
        internal void DrawGraph(Graphics g)
        {
            #region drawing of database for debugging only

#if TEST_MSAGL
            Graph dg = DrawingGraph;

            if (dg.DataBase != null)
            {
                var myPen = new Pen(Color.Blue, (float)(1 / 1000.0));
                Draw.DrawDataBase(g, myPen, dg);
            }

            if (NeedToDrawDebugStuff())
            {
                var myPen = new Pen(Color.Blue, (float)(1 / 1000.0));
                Draw.DrawDebugStuff(g, this, myPen);
            }
#endif

            #endregion

            if (drawingGraph.Attr.Border > 0)
            {
                DrawGraphBorder(drawingGraph.Attr.Border, g);
            }

            //we need to draw the edited edges last
            DEdge dEdgeSelectedForEditing = null;

            foreach (var subgraph in drawingGraph.RootSubgraph.AllSubgraphsWidthFirstExcludingSelf())
            {
                DrawNode(g, nodeMap[subgraph.Id]);
            }


            foreach (DEdge dEdge in Edges)
            {
                if (!dEdge.SelectedForEditing)
                {
                    DrawEdge(g, dEdge);
                }
                else //there must be no more than one edge selected for editing
                {
                    dEdgeSelectedForEditing = dEdge;
                }
            }


            foreach (DNode dnode in nodeMap.Values)
            {
                if (!(dnode.DrawingNode is Subgraph))
                {
                    DrawNode(g, dnode);
                }
            }

            //draw the selected edge
            if (dEdgeSelectedForEditing != null)
            {
                DrawEdge(g, dEdgeSelectedForEditing);
                DrawUnderlyingPolyline(g, dEdgeSelectedForEditing);
            }

            if (Viewer.SourcePortIsPresent)
            {
                DrawPortAtLocation(g, Viewer.SourcePortLocation);
            }
            if (Viewer.TargetPortIsPresent)
            {
                DrawPortAtLocation(g, Viewer.TargetPortLocation);
            }
        }