private MG.GeometryGraph CreateMSAGLGraph(DGMODEL.Drawing layout_diagram) { var msagl_graph = new MG.GeometryGraph(); var defsize = new VA.Drawing.Size(this.LayoutOptions.DefaultShapeSize.Width, this.LayoutOptions.DefaultShapeSize.Height); // Create the nodes in MSAGL foreach (var layout_shape in layout_diagram.Shapes) { var nodesize = ToMSAGLCoordinates(layout_shape.Size ?? defsize); var msagl_node = new MG.Node(layout_shape.ID, MG.Splines.CurveFactory.CreateBox(nodesize.Width, nodesize.Height, new MG.Point())); msagl_graph.AddNode(msagl_node); msagl_node.UserData = layout_shape; } bool connectors_ok = this.validate_connectors(layout_diagram); // TODO: What to do if connectors_ok is false? var msagl_size = this.ToMSAGLCoordinates(DefaultBezierConnectorLabelBoxSize); // Create the MSAGL Connectors foreach (var layout_connector in layout_diagram.Connectors) { if (layout_connector.From == null) { throw new System.ArgumentException("Connector's From node is null"); } if (layout_connector.To == null) { throw new System.ArgumentException("Connector's To node is null"); } var from_node = msagl_graph.NodeMap[layout_connector.From.ID]; var to_node = msagl_graph.NodeMap[layout_connector.To.ID]; var new_edge = new MG.Edge(from_node, to_node); new_edge.ArrowheadAtTarget = false; new_edge.UserData = layout_connector; msagl_graph.AddEdge(new_edge); new_edge.Label = new Microsoft.Msagl.Label(msagl_size.Width, msagl_size.Height, new_edge); } msagl_graph.CalculateLayout(); this.msagl_bb = new VA.Drawing.Rectangle( msagl_graph.BoundingBox.Left, msagl_graph.BoundingBox.Bottom, msagl_graph.BoundingBox.Right, msagl_graph.BoundingBox.Top); this.layout_bb = new VA.Drawing.Rectangle(0, 0, this.msagl_bb.Width, msagl_bb.Height) .Multiply(ScaleToDocument, ScaleToDocument); return(msagl_graph); }
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); }
// Given the MSAGL node, this function returns the Shape object private static DGMODEL.Shape get_shape(MG.Node msagl_node) { var shape = (DGMODEL.Shape)msagl_node.UserData; return(shape); }