internal DEdge(DNode source, DNode target, DrawingEdge drawingEdgeParam, ConnectionToGraph connection,
                       GViewer gviewer) : base(gviewer) {
            DrawingEdge = drawingEdgeParam;
            Source = source;
            Target = target;

            if (connection == ConnectionToGraph.Connected) {
                if (source == target)
                    source.AddSelfEdge(this);
                else {
                    source.AddOutEdge(this);
                    target.AddInEdge(this);
                }
            }

            if (drawingEdgeParam.Label != null)
                Label = new DLabel(this, drawingEdge.Label, gviewer);
        }
 internal void AddNode(DNode dNode){
     nodeMap[dNode.DrawingNode.Id] = dNode;
 }
        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;
        }
        /// <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;
        }
        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 DEBUG
                    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);            
        }
 static BBNode BuildBBHierarchyUnderDNode(DNode dNode){
     var bbNode = new BBNode();
     bbNode.geometry = new Geometry(dNode);
     bbNode.bBox = dNode.DrawingNode.BoundingBox;
     return bbNode;
 }
Beispiel #7
0
 static IEnumerable<DEdge> Edges(DNode dNode)
 {
     foreach (DEdge de in dNode.OutEdges)
         yield return de;
     foreach (DEdge de in dNode.InEdges)
         yield return de;
     foreach (DEdge de in dNode.SelfEdges)
         yield return de;
 }
 internal static void DrawEllipse(Graphics g, Pen pen, DNode dNode) {
     var drNode = dNode.DrawingNode;
     NodeAttr nodeAttr = drNode.Attr;
     var width = (float)drNode.Width;
     var height = (float)drNode.Height;
     var x = (float)(drNode.Pos.X - width / 2.0);
     var y = (float) (drNode.Pos.Y - height/2.0);
   
     DrawEllipseOnPosition(dNode, nodeAttr, g, x, y, width, height, pen);
 }
        static void DrawEllipseOnPosition(DNode dNode, NodeAttr nodeAttr, Graphics g, float x, float y, float width,
                                          float height, Pen pen){
            if(NeedToFill(dNode.FillColor))
                g.FillEllipse(new SolidBrush(dNode.FillColor), x, y, width, height);
            if(nodeAttr.Shape == Shape.Point)
                g.FillEllipse(new SolidBrush(pen.Color), x, y, width, height);

            g.DrawEllipse(pen, x, y, width, height);
        }
        internal static void DrawDiamond(Graphics g, Pen pen, DNode dNode) {
            var drNode = dNode.DrawingNode;
            NodeAttr nodeAttr = drNode.Attr;

            double w2 = drNode.Width/2.0f;
            double h2 = drNode.Height/2.0f;
            double cx = drNode.Pos.X;
            double cy = drNode.Pos.Y;
            var ps = new[]{
                              new PointF((float) cx - (float) w2, (float) cy),
                              new PointF((float) cx, (float) cy + (float) h2),
                              new PointF((float) cx + (float) w2, (float) cy),
                              new PointF((float) cx, (float) cy - (float) h2)
                          };

            if(NeedToFill(dNode.FillColor)){
                Color fc = FillColor(nodeAttr);
                g.FillPolygon(new SolidBrush(fc), ps);
            }

            g.DrawPolygon(pen, ps);
        }
        internal static void DrawBox(Graphics g, Pen pen, DNode dNode) {
            var drNode = dNode.DrawingNode;
            NodeAttr nodeAttr = drNode.Attr;
            if(nodeAttr.XRadius == 0 || nodeAttr.YRadius == 0){
                double x = drNode.GeometryNode.Center.X - drNode.Width/2.0f;
                double y = drNode.GeometryNode.Center.Y - drNode.Height / 2.0f;

                if(NeedToFill(dNode.FillColor)){
                    Color fc = FillColor(nodeAttr);
                    g.FillRectangle(new SolidBrush(fc), (float) x, (float) y, (float) drNode.Width,
                                    (float) drNode.Height);
                }

                g.DrawRectangle(pen, (float) x, (float) y, (float) drNode.Width, (float) drNode.Height);
            } else{
                var width = (float) drNode.Width;
                var height = (float) drNode.Height;
                var xRadius = (float) nodeAttr.XRadius;
                var yRadius = (float) nodeAttr.YRadius;
                using (var path = new GraphicsPath()){
                    FillTheGraphicsPath(drNode, width, height, ref xRadius, ref yRadius, path);

                    if(NeedToFill(dNode.FillColor)){
                        g.FillPath(new SolidBrush(dNode.FillColor), path);
                    }


                    g.DrawPath(pen, path);
                }
            }
        }
        internal static void DrawDoubleCircle(Graphics g, Pen pen, DNode dNode) {
            var drNode = dNode.DrawingNode;
               NodeAttr nodeAttr = drNode.Attr;
            
            double x = drNode.GeometryNode.Center.X - drNode.GeometryNode.Width/2.0f;
            double y = drNode.GeometryNode.Center.Y - drNode.GeometryNode.Height / 2.0f;
            if(NeedToFill(dNode.FillColor)){
                g.FillEllipse(new SolidBrush(dNode.FillColor), (float) x, (float) y, (float) drNode.Width,
                              (float) drNode.Height);
            }

            g.DrawEllipse(pen, (float) x, (float) y, (float) drNode.Width, (float) drNode.Height);
            var w = (float) drNode.Width;
            var h = (float) drNode.Height;
            float m = Math.Max(w, h);
            float coeff = (float) 1.0 - (float) (DoubleCircleOffsetRatio);
            x += coeff*m/2.0;
            y += coeff*m/2.0;
            g.DrawEllipse(pen, (float) x, (float) y, w - coeff*m, h - coeff*m);
        }
        static void DrawCurve(DNode dNode, Curve c, Graphics g, Pen pen) {
            var path = new GraphicsPath();
            foreach (ICurve seg in c.Segments)
                AddSegToPath(seg, ref path);

            if (NeedToFill(dNode.FillColor))
                g.FillPath(new SolidBrush(dNode.FillColor), path);
            g.DrawPath(pen, path);
        }
 internal static void DrawFromMsaglCurve(Graphics g, Pen pen, DNode dNode){
     var drNode = dNode.DrawingNode;
     NodeAttr attr = dNode.DrawingNode.Attr;
     var iCurve=drNode.GeometryNode.BoundaryCurve;
     var c =iCurve as Curve;
     if(c != null){
         DrawCurve(dNode, c, g, pen);
     } else{
         var ellipse = iCurve as Ellipse;
         if(ellipse != null){
             double w = ellipse.AxisA.X;
             double h = ellipse.AxisB.Y;
             DrawEllipseOnPosition(dNode, dNode.DrawingNode.Attr, g, (float) (ellipse.Center.X - w),
                                   (float) (ellipse.Center.Y - h),
                                   (float) w*2, (float) h*2, pen);
         } else {
             var poly = iCurve as Polyline;
             if (poly != null) {
                 var path = new GraphicsPath();
                 path.AddLines(poly.Select(p => new Point((int)p.X, (int)p.Y)).ToArray());
                 path.CloseAllFigures();
                 if (NeedToFill(dNode.FillColor))
                     g.FillPath(new SolidBrush(dNode.FillColor), path);
                 g.DrawPath(pen, path);
             } else {
                 var roundedRect = iCurve as RoundedRect;
                 if (roundedRect != null)
                     DrawCurve(dNode, roundedRect.Curve, g, pen);
             }
         }
         
     }
 }