private Dom.BezierCurve draw_edge_bezier(MSAGL.Core.Layout.Edge edge) { var final_bez_points = MsaglUtil.ToVAPoints(edge).Select(p => this.ToDocumentCoordinates(p)).ToList(); var bez_shape = new Dom.BezierCurve(final_bez_points); return(bez_shape); }
public static IList <Point> ToVAPoints(MG.Core.Layout.Edge edge) { if (edge.Curve is MG.Core.Geometry.Curves.Curve) { var curve = (MG.Core.Geometry.Curves.Curve)edge.Curve; var final_bez_points = new List <Point> { MsaglUtil.ToVAPoint(edge.Curve.Start) }; foreach (var cur_seg in curve.Segments) { if (cur_seg is MG.Core.Geometry.Curves.CubicBezierSegment) { var bezier_seg = (MG.Core.Geometry.Curves.CubicBezierSegment)cur_seg; var bez_points = new[] { 0, 1, 2, 3 } .Select(bezier_seg.B) .Select(MsaglUtil.ToVAPoint) .ToArray(); final_bez_points.AddRange(bez_points.Skip(1)); } else if (cur_seg is MG.Core.Geometry.Curves.LineSegment) { var line_seg = (MG.Core.Geometry.Curves.LineSegment)cur_seg; final_bez_points.Add(MsaglUtil.ToVAPoint(line_seg.Start)); final_bez_points.Add(MsaglUtil.ToVAPoint(line_seg.End)); final_bez_points.Add(MsaglUtil.ToVAPoint(line_seg.End)); } else { throw new InvalidOperationException("Unsupported Curve Segment type"); } } return(final_bez_points); } else if (edge.Curve is MG.Core.Geometry.Curves.LineSegment) { var final_bez_points = new List <Point> { MsaglUtil.ToVAPoint(edge.Curve.Start) }; var line_seg = (MG.Core.Geometry.Curves.LineSegment)edge.Curve; final_bez_points.Add(MsaglUtil.ToVAPoint(line_seg.Start)); final_bez_points.Add(MsaglUtil.ToVAPoint(line_seg.End)); final_bez_points.Add(MsaglUtil.ToVAPoint(line_seg.End)); return(final_bez_points); } throw new Exception(); }
public static IList <VisioAutomation.Geometry.Point> ToVAPoints(MG.Core.Layout.Edge edge) { if (edge.Curve is MG.Core.Geometry.Curves.Curve) { var curve = (MG.Core.Geometry.Curves.Curve)edge.Curve; var final_bez_points = new List <VisioAutomation.Geometry.Point> { MsaglUtil.ToVAPoint(edge.Curve.Start) }; foreach (var cur_seg in curve.Segments) { if (cur_seg is MG.Core.Geometry.Curves.CubicBezierSegment) { var bezier_seg = (MG.Core.Geometry.Curves.CubicBezierSegment)cur_seg; // The first point at index 0 is deliberately not added final_bez_points.Add(MsaglUtil.ToVAPoint(bezier_seg.B(1))); final_bez_points.Add(MsaglUtil.ToVAPoint(bezier_seg.B(2))); final_bez_points.Add(MsaglUtil.ToVAPoint(bezier_seg.B(3))); } else if (cur_seg is MG.Core.Geometry.Curves.LineSegment) { var line_seg = (MG.Core.Geometry.Curves.LineSegment)cur_seg; final_bez_points.Add(MsaglUtil.ToVAPoint(line_seg.Start)); final_bez_points.Add(MsaglUtil.ToVAPoint(line_seg.End)); final_bez_points.Add(MsaglUtil.ToVAPoint(line_seg.End)); } else { throw new InvalidOperationException("Unsupported Curve Segment type"); } } return(final_bez_points); } else if (edge.Curve is MG.Core.Geometry.Curves.LineSegment) { var final_bez_points = new List <VisioAutomation.Geometry.Point> { MsaglUtil.ToVAPoint(edge.Curve.Start) }; var line_seg = (MG.Core.Geometry.Curves.LineSegment)edge.Curve; final_bez_points.Add(MsaglUtil.ToVAPoint(line_seg.Start)); final_bez_points.Add(MsaglUtil.ToVAPoint(line_seg.End)); final_bez_points.Add(MsaglUtil.ToVAPoint(line_seg.End)); return(final_bez_points); } throw new System.ArgumentException("Unhandled Curve Type"); }
private void CreateBezierEdges(Dom.ShapeList domshapes, MSAGL.Core.Layout.GeometryGraph mg_graph) { // DRAW EDGES WITH BEZIERS foreach (var mg_edge in mg_graph.Edges) { var ud = (NodeUserData)mg_edge.UserData; var layoutconnector = ud.Connector; var vconnector = this.draw_edge_bezier(mg_edge); layoutconnector.DOMNode = vconnector; domshapes.Add(vconnector); } foreach (var mg_edge in mg_graph.Edges) { var ud = (NodeUserData)mg_edge.UserData; var layout_connector = ud.Connector; if (layout_connector.Cells != null) { var bezier_node = (Dom.BezierCurve)layout_connector.DOMNode; bezier_node.Cells = layout_connector.Cells.ShallowCopy(); } } foreach (var mg_edge in mg_graph.Edges) { var ud = (NodeUserData)mg_edge.UserData; var layout_connector = ud.Connector; if (!string.IsNullOrEmpty(layout_connector.Label)) { // this is a bezier connector // draw a manual box instead var label_bb = this.ToDocumentCoordinates(MsaglUtil.ToVARectangle(mg_edge.Label.BoundingBox)); var vshape = new Dom.Rectangle(label_bb); domshapes.Add(vshape); vshape.Cells = this.DefaultBezierConnectorShapeCells.ShallowCopy(); vshape.Text = new VisioAutomation.Models.Text.TextElement(layout_connector.Label); } } }
private void CreateDOMShapes(Dom.ShapeList domshapeslist, MSAGL.Core.Layout.GeometryGraph mg_graph, IVisio.Application app) { var node_centerpoints = mg_graph.Nodes .Select(n => this.ToDocumentCoordinates(MsaglUtil.ToVAPoint(n.Center))) .ToArray(); // Load up all the stencil docs var app_documents = app.Documents; var uds = mg_graph.Nodes.Where(n => n.UserData != null).Select(n => (NodeUserData)n.UserData).ToList(); var shapes = uds.Where(ud => ud.Shape != null).Select(ud => ud.Shape).ToList(); var stencilnames0 = shapes.Select(s => s.StencilName).ToList(); var stencil_names = stencilnames0.Distinct().ToList(); var compare = StringComparer.InvariantCultureIgnoreCase; var stencil_map = new Dictionary <string, IVisio.Document>(compare); foreach (var stencil_name in stencil_names) { if (!stencil_map.ContainsKey(stencil_name)) { var stencil = app_documents.OpenStencil(stencil_name); stencil_map[stencil_name] = stencil; } } var master_map = new Dictionary <string, IVisio.Master>(compare); foreach (var nv in shapes) { var key = nv.StencilName + "+" + nv.MasterName; if (!master_map.ContainsKey(key)) { var stencil = stencil_map[nv.StencilName]; var masters = stencil.Masters; var master = masters[nv.MasterName]; master_map[key] = master; } } // Create DOM Shapes for each AutoLayoutShape int count = 0; foreach (var layout_shape in shapes) { var key = layout_shape.StencilName.ToLower() + "+" + layout_shape.MasterName; var master = master_map[key]; var shape_node = new Dom.Shape(master, node_centerpoints[count]); layout_shape.DOMNode = shape_node; domshapeslist.Add(shape_node); count++; } // FORMAT EACH SHAPE foreach (var n in mg_graph.Nodes) { var ud = (NodeUserData)n.UserData; var layout_shape = ud.Shape; if (layout_shape != null) { this.format_shape(layout_shape, layout_shape.DOMNode); } } }