예제 #1
0
        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);
        }
예제 #2
0
        private VA.DOM.BezierCurve draw_edge_bezier(
            VA.DOM.ShapeList page,
            DGMODEL.Connector connector,
            MG.Edge edge)
        {
            var final_bez_points =
                VA.Internal.MSAGLUtil.ToVAPoints(edge).Select(p => ToDocumentCoordinates(p)).ToList();

            var bez_shape = new VA.DOM.BezierCurve(final_bez_points);

            return(bez_shape);
        }
예제 #3
0
        public static IList <VA.Drawing.Point> ToVAPoints(MG.Edge edge)
        {
            var final_bez_points = new List <VA.Drawing.Point> {
                ToVAPoint(edge.Curve.Start)
            };

            var curve = (MG.Splines.Curve)edge.Curve;

            foreach (var cur_seg in curve.Segments)
            {
                if (cur_seg is MG.Splines.CubicBezierSegment)
                {
                    var bezier_seg = (MG.Splines.CubicBezierSegment)cur_seg;

                    var bez_points =
                        new[] { 0, 1, 2, 3 }
                    .Select(bezier_seg.B)
                    .Select(ToVAPoint)
                    .ToArray();

                    final_bez_points.AddRange(bez_points.Skip(1));
                }
                else if (cur_seg is MG.Splines.LineSegment)
                {
                    var line_seg = (MG.Splines.LineSegment)cur_seg;
                    final_bez_points.Add(ToVAPoint(line_seg.Start));
                    final_bez_points.Add(ToVAPoint(line_seg.End));
                    final_bez_points.Add(ToVAPoint(line_seg.End));
                }
                else
                {
                    throw new System.InvalidOperationException("Unsupported Curve Segment type");
                }
            }

            return(final_bez_points);
        }