public Dom.Page CreateDOMPage(DirectedGraphLayout layout_diagram, IVisio.Application vis) { var page_node = new Dom.Page(); MsaglRenderer.ResolveMasters(layout_diagram, vis); var mg_graph = this.CreateMsaglGraph(layout_diagram); this.CreateDOMShapes(page_node.Shapes, mg_graph, vis); if (this.LayoutOptions.UseDynamicConnectors) { this.CreateDynamicConnectorEdges(page_node.Shapes, mg_graph); } else { this.CreateBezierEdges(page_node.Shapes, mg_graph); } // Additional Page properties page_node.PageCells.PlaceStyle = 1; page_node.PageCells.RouteStyle = 5; page_node.PageCells.AvenueSizeX = 2.0; page_node.PageCells.AvenueSizeY = 2.0; page_node.PageCells.LineRouteExt = 2; page_node.Size = this._layout_bb.Size; return(page_node); }
public void Render( DirectedGraphLayout layout_diagram, IVisio.Page page) { // Create A DOM and render it to the page var app = page.Application; var page_node = this.CreateDOMPage(layout_diagram, app); page_node.Render(page); // Find all the shapes that were created in the DOM and put them in the layout structure foreach (var layout_shape in layout_diagram.Shapes) { var shape_node = layout_shape.DOMNode; layout_shape.VisioShape = shape_node.VisioShape; } var layout_edges = layout_diagram.Connectors; foreach (var layout_edge in layout_edges) { var vnode = layout_edge.DOMNode; layout_edge.VisioShape = vnode.VisioShape; } }
private static void ResolveMasters(DirectedGraphLayout layout_diagram, IVisio.Application app) { // for masters that are identified by their name and stencil, go find the actual master objects by // loading the specified stenciles var documents = app.Documents; var master_to_size = new Dictionary <IVisio.Master, VA.Drawing.Size>(); // Load and cache all the masters var loader = new MasterLoader(); foreach (var layout_shape in layout_diagram.Shapes) { loader.Add(layout_shape.MasterName, layout_shape.StencilName); } loader.Resolve(documents); // If no size was provided for the shape, then set the size based on the master var layoutshapes_without_size_info = layout_diagram.Shapes.Where(s => s.Size == null); foreach (var layoutshape in layoutshapes_without_size_info) { var master = loader.Get(layoutshape.MasterName, layoutshape.StencilName); var size = MsaglRenderer.TryGetValue(master_to_size, master.VisioMaster); if (!size.HasValue) { var master_bb = master.VisioMaster.GetBoundingBox(IVisio.VisBoundingBoxArgs.visBBoxUprightWH); size = master_bb.Size; master_to_size[master.VisioMaster] = size.Value; } layoutshape.Size = size.Value; } }
public Dom.Page CreateDomPage(DirectedGraphLayout dglayout, IVisio.Application vis, DirectedGraphStyling dgstyling) { var page_node = new Dom.Page(); MsaglRenderer._resolve_masters(dglayout, vis); var mg_graph = this._create_msagl_graph(dglayout); this._create_dom_shapes(page_node.Shapes, mg_graph, vis); if (this.LayoutOptions.UseDynamicConnectors) { this._create_dynamic_connector_edges(page_node.Shapes, mg_graph, dgstyling); } else { this._create_bezier_edges(page_node.Shapes, mg_graph); } // Additional Page properties page_node.PageLayoutCells.PlaceStyle = 1; page_node.PageLayoutCells.RouteStyle = 5; page_node.PageLayoutCells.AvenueSizeX = 2.0; page_node.PageLayoutCells.AvenueSizeY = 2.0; page_node.PageLayoutCells.LineRouteExt = 2; page_node.Size = this._visio_bb.Size; return(page_node); }
private static void _resolve_masters(DirectedGraphLayout dglayout, IVisio.Application app) { // for masters that are identified by their name and stencil, go find the actual master objects by // loading the specified stencils var documents = app.Documents; var master_to_size = new Dictionary <IVisio.Master, VA.Geometry.Size>(); // Load and cache all the masters var master_cache = new VA.Models.Utilities.MasterCache(); foreach (var layout_shape in dglayout.Nodes) { master_cache.Add(layout_shape.MasterName, layout_shape.StencilName); } master_cache.Resolve(documents); // If no size was provided for the shape, then set the size based on the master var layoutshapes_without_size_info = dglayout.Nodes.Where(s => s.Size == null); foreach (var layoutshape in layoutshapes_without_size_info) { var master = master_cache.Get(layoutshape.MasterName, layoutshape.StencilName); var size = MsaglRenderer._try_get_value(master_to_size, master.VisioMaster); if (!size.HasValue) { var master_bb = master.VisioMaster.GetBoundingBox(IVisio.VisBoundingBoxArgs.visBBoxUprightWH); size = master_bb.Size; master_to_size[master.VisioMaster] = size.Value; } layoutshape.Size = size.Value; } }
public void Render(IVisio.Page page, DirectedGraphLayout dglayout) { // Create A DOM and render it to the page var app = page.Application; var page_node = this.CreateDomPage(dglayout, app, this.Styling); page_node.Render(page); // Find all the shapes that were created in the DOM and put them in the layout structure foreach (var layout_shape in dglayout.Nodes) { var shape_node = layout_shape.DomNode; layout_shape.VisioShape = shape_node.VisioShape; } var layout_edges = dglayout.Edges; foreach (var layout_edge in layout_edges) { var vnode = layout_edge.DomNode; layout_edge.VisioShape = vnode.VisioShape; } page.ResizeToFitContents(LayoutOptions.PageBorderWidth); }
public static void Render(IVisio.Page page, DirectedGraphLayout directedGraphLayout, MsaglLayoutOptions options) { if (page == null) { throw new ArgumentNullException(nameof(page)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } var renderer = new MsaglRenderer(); renderer.LayoutOptions = options; renderer.Render(directedGraphLayout, page); page.ResizeToFitContents(renderer.LayoutOptions.ResizeBorderWidth); }
private void validate_connectors(DirectedGraphLayout layout_diagram) { foreach (var layout_connector in layout_diagram.Connectors) { if (layout_connector.ID == null) { throw new AutomationException("Connector's ID is null"); } if (layout_connector.From == null) { throw new AutomationException("Connector's From node is null"); } if (layout_connector.To == null) { throw new AutomationException("Connector's From node is null"); } } }
public void Render(IVisio.Page page, DirectedGraphLayout directedGraphLayout, VisioLayoutOptions options) { // This is Visio-based render - it does NOT use MSAGL if (page == null) { throw new System.ArgumentNullException(nameof(page)); } if (options == null) { throw new System.ArgumentNullException(nameof(options)); } var page_node = new Dom.Page(); double x = 0; double y = 1; foreach (var shape in directedGraphLayout.Shapes) { var shape_nodes = page_node.Shapes.Drop(shape.MasterName, shape.StencilName, x, y); shape.DomNode = shape_nodes; shape.DomNode.Text = new VisioAutomation.Models.Text.Element(shape.Label); x += 1.0; } foreach (var connector in directedGraphLayout.Connectors) { var connector_node = page_node.Shapes.Connect("Dynamic Connector", "connec_u.vss", connector.From.DomNode, connector.To.DomNode); connector.DomNode = connector_node; connector.DomNode.Text = new VisioAutomation.Models.Text.Element(connector.Label); } page_node.ResizeToFit = true; page_node.ResizeToFitMargin = new VisioAutomation.Drawing.Size(0.5, 0.5); if (options.Layout != null) { page_node.Layout = options.Layout; } page_node.Render(page); }
public void Render(IVisio.Page page, DirectedGraphLayout dglayout) { // This is Visio-based render - it does NOT use MSAGL if (page == null) { throw new System.ArgumentNullException(nameof(page)); } if (this.Styling == null) { throw new System.ArgumentNullException(nameof(this.Styling)); } var page_node = new Dom.Page(); double x = 0; double y = 1; foreach (var shape in dglayout.Nodes) { var shape_nodes = page_node.Shapes.Drop(shape.MasterName, shape.StencilName, x, y); shape.DomNode = shape_nodes; shape.DomNode.Text = new VisioAutomation.Models.Text.Element(shape.Label); x += 1.0; } foreach (var connector in dglayout.Edges) { var connector_node = page_node.Shapes.Connect(this.Styling.EdgeMasterName, this.Styling.EdgeStencilName, connector.From.DomNode, connector.To.DomNode); connector.DomNode = connector_node; connector.DomNode.Text = new VisioAutomation.Models.Text.Element(connector.Label); } page_node.ResizeToFit = true; page_node.ResizeToFitMargin = new VisioAutomation.Geometry.Size(0.5, 0.5); if (this.LayoutOptions.VisioLayoutStyle != null) { page_node.Layout = this.LayoutOptions.VisioLayoutStyle; } page_node.Render(page); }
private DG.DirectedGraphLayout create_sample_graph() { var d = new DG.DirectedGraphLayout(); var basic_stencil = "basic_u.vss"; var n0 = d.AddShape("n0", "Node 0", basic_stencil, "Rectangle"); n0.Size = new VA.Drawing.Size(3, 2); var n1 = d.AddShape("n1", "Node 1", basic_stencil, "Rectangle"); var n2 = d.AddShape("n2", "Node 2", basic_stencil, "Rectangle"); var n3 = d.AddShape("n3", "Node 3", basic_stencil, "Rectangle"); var n4 = d.AddShape("n4", "Node 4\nUnconnected", basic_stencil, "Rectangle"); var c0 = d.AddConnection("c0", n0, n1, "0 -> 1", ConnectorType.Curved); var c1 = d.AddConnection("c1", n1, n2, "1 -> 2", ConnectorType.RightAngle); var c2 = d.AddConnection("c2", n1, n0, "0 -> 1", ConnectorType.Curved); var c3 = d.AddConnection("c3", n0, n2, "0 -> 2", ConnectorType.Straight); var c4 = d.AddConnection("c4", n2, n3, "2 -> 3", ConnectorType.Curved); var c5 = d.AddConnection("c5", n3, n0, "3 -> 0", ConnectorType.Curved); return(d); }
public void RenderDirectedGraphWithCustomProps() { var d = new DG.DirectedGraphLayout(); var n0 = d.AddShape("n0", "Untitled Node", "basflo_u.vss", "Decision"); n0.Size = new VA.Drawing.Size(3, 2); n0.CustomProperties = new VA.Shapes.CustomProperties.CustomPropertyDictionary(); n0.CustomProperties["p1"] = new VACUSTPROP.CustomPropertyCells("v1"); n0.CustomProperties["p2"] = new VACUSTPROP.CustomPropertyCells("v2"); n0.CustomProperties["p3"] = new VACUSTPROP.CustomPropertyCells("v3"); var options = new DG.MsaglLayoutOptions(); options.UseDynamicConnectors = true; var visapp = this.GetVisioApplication(); var doc = this.GetNewDoc(); var page1 = visapp.ActivePage; d.Render(page1, options); Assert.IsNotNull(n0.VisioShape); var props_dic = VACUSTPROP.CustomPropertyHelper.Get(n0.VisioShape); Assert.IsTrue(props_dic.Count >= 3); Assert.AreEqual("\"v1\"", props_dic["p1"].Value.Formula); Assert.AreEqual("\"v2\"", props_dic["p2"].Value.Formula); Assert.AreEqual("\"v3\"", props_dic["p3"].Value.Formula); page1.Application.ActiveWindow.ViewFit = (short)IVisio.VisWindowFit.visFitPage; string output_filename = TestGlobals.TestHelper.GetOutputFilename(nameof(RenderDirectedGraphWithCustomProps), ".vsd"); doc.SaveAs(output_filename); doc.Close(); }
private MSAGL.Core.Layout.GeometryGraph CreateMsaglGraph(DirectedGraphLayout layout_diagram) { var mg_graph = new MSAGL.Core.Layout.GeometryGraph(); // Create the nodes in MSAGL foreach (var layout_shape in layout_diagram.Shapes) { var nodesize = this.ToMGCoordinates(layout_shape.Size ?? this.LayoutOptions.DefaultShapeSize); var node_user_data = new NodeUserData(layout_shape.ID, layout_shape); var center = new MSAGL.Core.Geometry.Point(); var rectangle = MSAGL.Core.Geometry.Curves.CurveFactory.CreateRectangle(nodesize.Width, nodesize.Height, center); var mg_node = new MSAGL.Core.Layout.Node(rectangle, node_user_data); mg_graph.Nodes.Add(mg_node); } this.validate_connectors(layout_diagram); var mg_coordinates = this.ToMGCoordinates(this.DefaultBezierConnectorLabelBoxSize); var map_id_to_ud = new Dictionary <string, MSAGL.Core.Layout.Node>(); foreach (var n in mg_graph.Nodes) { var ud = (NodeUserData)n.UserData; if (ud != null) { map_id_to_ud[ud.ID] = n; } } // Create the MG Connectors foreach (var layout_connector in layout_diagram.Connectors) { if (layout_connector.From == null) { throw new ArgumentException("Connector's From node is null"); } if (layout_connector.To == null) { throw new ArgumentException("Connector's To node is null"); } var from_node = map_id_to_ud[layout_connector.From.ID]; var to_node = map_id_to_ud[layout_connector.To.ID]; var new_edge = new MSAGL.Core.Layout.Edge(from_node, to_node); // TODO: MSAGL //new_edge.ArrowheadAtTarget = false; new_edge.UserData = new NodeUserData(layout_connector.ID, layout_connector); mg_graph.Edges.Add(new_edge); new_edge.Label = new MSAGL.Core.Layout.Label(mg_coordinates.Width, mg_coordinates.Height, new_edge); } var geom_graph_components = MSAGL.Core.Layout.GraphConnectedComponents.CreateComponents(mg_graph.Nodes, mg_graph.Edges); var settings = new MSAGL.Layout.Layered.SugiyamaLayoutSettings(); foreach (var subgraph in geom_graph_components) { var layout = new Microsoft.Msagl.Layout.Layered.LayeredLayout(subgraph, settings); subgraph.Margins = settings.NodeSeparation / 2; layout.Run(); } // Pack the graphs using Golden Aspect Ratio MSAGL.Layout.MDS.MdsGraphLayout.PackGraphs(geom_graph_components, settings); //Update the graphs bounding box mg_graph.UpdateBoundingBox(); this._mg_bb = new VA.Drawing.Rectangle( mg_graph.BoundingBox.Left, mg_graph.BoundingBox.Bottom, mg_graph.BoundingBox.Right, mg_graph.BoundingBox.Top); this._layout_bb = new VA.Drawing.Rectangle(0, 0, this._mg_bb.Width, this._mg_bb.Height) .Multiply(this.ScaleToDocument, this.ScaleToDocument); return(mg_graph); }
private MSAGL.Core.Layout.GeometryGraph _create_msagl_graph(DirectedGraphLayout dglayout) { var msagl_graph = new MSAGL.Core.Layout.GeometryGraph(); // Create the nodes in MSAGL foreach (var layout_shape in dglayout.Nodes) { var nodesize = this._to_mg_coordinates(layout_shape.Size ?? this.LayoutOptions.DefaultShapeSize); var node_user_data = new ElementUserData(layout_shape.ID, layout_shape); var center = new MSAGL.Core.Geometry.Point(); var rectangle = MSAGL.Core.Geometry.Curves.CurveFactory.CreateRectangle(nodesize.Width, nodesize.Height, center); var mg_node = new MSAGL.Core.Layout.Node(rectangle, node_user_data); msagl_graph.Nodes.Add(mg_node); } this.validate_connectors(dglayout); var mg_coordinates = this._to_mg_coordinates(this.DefaultBezierConnectorLabelBoxSize); var map_id_to_ud = new Dictionary <string, MSAGL.Core.Layout.Node>(); foreach (var n in msagl_graph.Nodes) { var ud = (ElementUserData)n.UserData; if (ud != null) { map_id_to_ud[ud.ID] = n; } } // Create the MG Connectors foreach (var layout_connector in dglayout.Edges) { if (layout_connector.From == null) { throw new ArgumentException("Connector's From node is null"); } if (layout_connector.To == null) { throw new ArgumentException("Connector's To node is null"); } var from_node = map_id_to_ud[layout_connector.From.ID]; var to_node = map_id_to_ud[layout_connector.To.ID]; var new_edge = new MSAGL.Core.Layout.Edge(from_node, to_node); // TODO: MSAGL //new_edge.ArrowheadAtTarget = false; new_edge.UserData = new ElementUserData(layout_connector.ID, layout_connector); msagl_graph.Edges.Add(new_edge); new_edge.Label = new MSAGL.Core.Layout.Label(mg_coordinates.Width, mg_coordinates.Height, new_edge); } var msagl_graphs = MSAGL.Core.Layout.GraphConnectedComponents.CreateComponents(msagl_graph.Nodes, msagl_graph.Edges); var msagl_sugiyamasettings = new MSAGL.Layout.Layered.SugiyamaLayoutSettings(); if (this.LayoutOptions.Direction == MsaglDirection.TopToBottom) { // do nothing } else if (this.LayoutOptions.Direction == MsaglDirection.BottomToTop) { msagl_sugiyamasettings.Transformation = MSAGL.Core.Geometry.Curves.PlaneTransformation.Rotation(Math.PI); } else if (this.LayoutOptions.Direction == MsaglDirection.LeftToRight) { msagl_sugiyamasettings.Transformation = MSAGL.Core.Geometry.Curves.PlaneTransformation.Rotation(Math.PI / 2); } else if (this.LayoutOptions.Direction == MsaglDirection.RightToLeft) { msagl_sugiyamasettings.Transformation = MSAGL.Core.Geometry.Curves.PlaneTransformation.Rotation(-Math.PI / 2); } else { throw new System.ArgumentOutOfRangeException(); } foreach (var subgraph in msagl_graphs) { var layout = new Microsoft.Msagl.Layout.Layered.LayeredLayout(subgraph, msagl_sugiyamasettings); subgraph.Margins = msagl_sugiyamasettings.NodeSeparation / 2; layout.Run(); } // Pack the graphs using Golden Aspect Ratio MSAGL.Layout.MDS.MdsGraphLayout.PackGraphs(msagl_graphs, msagl_sugiyamasettings); //Update the graphs bounding box msagl_graph.UpdateBoundingBox(); this._msagl_bb = new VA.Geometry.Rectangle( msagl_graph.BoundingBox.Left, msagl_graph.BoundingBox.Bottom, msagl_graph.BoundingBox.Right, msagl_graph.BoundingBox.Top); this._visio_bb = new VA.Geometry.Rectangle(0, 0, this._msagl_bb.Width, this._msagl_bb.Height) .Multiply(this._scale_to_document, this._scale_to_document); return(msagl_graph); }
private static DGMODEL.DirectedGraphLayout get_dg_drawing() { var ver = VA.Application.ApplicationHelper.GetVersion(SampleEnvironment.Application); string server_stencil = (ver.Major >= 15) ? "server_u.vssx" : "server_u.vss"; string basflo_stencil = (ver.Major >= 15) ? "basflo_u.vssx" : "basflo_u.vss"; var directed_graph_drawing = new DGMODEL.DirectedGraphLayout(); // Create a Node 0 var n0 = directed_graph_drawing.AddShape("n0", "N0 Untitled Node", basflo_stencil, "Decision"); // Format Node 0 n0.Size = new VA.Drawing.Size(3, 2); // Create Node 1 var n1 = directed_graph_drawing.AddShape("n1", "N1", basflo_stencil, "Decision"); // Format Node 1 n1.Cells = new ShapeCells(); n1.Cells.FillForegnd = "rgb(255,0,0)"; n1.Cells.FillBkgnd = "rgb(255,255,0)"; n1.Cells.FillPattern = 40; // Create Node 2 var n2 = directed_graph_drawing.AddShape("n2", "N2 MailServer", server_stencil, "Server"); // Create Node 3 var n3 = directed_graph_drawing.AddShape("n3", "N3", basflo_stencil, "Data"); // Create Node 4 var n4 = directed_graph_drawing.AddShape("n4", "N4", basflo_stencil, "Data"); // Create the connectors to join the nodes // Note that Node 4 is deliberately not connected to any other node var curved = ConnectorType.Curved; var rightangle = ConnectorType.RightAngle; var c0 = directed_graph_drawing.AddConnection("c0", n0, n1, null, curved); var c1 = directed_graph_drawing.AddConnection("c1", n1, n2, "YES", rightangle); var c2 = directed_graph_drawing.AddConnection("c2", n3, n4, "NO", curved); var c3 = directed_graph_drawing.AddConnection("c3", n0, n2, null, rightangle); var c4 = directed_graph_drawing.AddConnection("c4", n2, n3, null, curved); var c5 = directed_graph_drawing.AddConnection("c5", n3, n0, null, curved); // Format connector 0 to point "back" c0.Cells = new ShapeCells(); c0.Cells.BeginArrow = 1; c0.Cells.LineWeight = 0.10; // Format connector 1 to point "forward" c1.Cells = new ShapeCells(); c1.Cells.EndArrow = 1; c1.Cells.LineWeight = 0.10; // Format connector 2 to point "back" and "forward" c2.Cells = new ShapeCells(); c2.Cells.EndArrow = 1; c2.Cells.BeginArrow = 1; c2.Cells.LineWeight = 0.10; return(directed_graph_drawing); }