public void TreeLayout_MultiNode() { // Verify that a tree with multiple nodes can be drawn // Note that the DefaultNodeSize option is being used var t = new TREEMODEL.Drawing(); t.Root = new TREEMODEL.Node("Root"); var na = new TREEMODEL.Node("A"); var nb = new TREEMODEL.Node("B"); var na1 = new TREEMODEL.Node("A1"); var na2 = new TREEMODEL.Node("A2"); var nb1 = new TREEMODEL.Node("B1"); var nb2 = new TREEMODEL.Node("B2"); t.Root.Children.Add(na); t.Root.Children.Add(nb); na.Children.Add(na1); na.Children.Add(na2); nb.Children.Add(nb1); nb1.Children.Add(nb2); t.LayoutOptions.DefaultNodeSize = new VA.Drawing.Size(1, 1); var app = this.GetVisioApplication(); var doc = this.GetNewDoc(); var page = app.ActivePage; t.Render(page); AssertVA.AreEqual(5.25, 8.0, VisioAutomationTest.GetPageSize(page), 0.05); Assert.AreEqual("Root", t.Root.VisioShape.Text); Assert.AreEqual("A", na.VisioShape.Text); Assert.AreEqual("B", nb.VisioShape.Text); Assert.AreEqual("A1", na1.VisioShape.Text); Assert.AreEqual("A2", na2.VisioShape.Text); Assert.AreEqual("B1", nb1.VisioShape.Text); Assert.AreEqual("B2", nb2.VisioShape.Text); doc.Close(true); }
public void TreeLayout_SingleNode() { // Verify that a tree with a single node can be drawn var t = new TREEMODEL.Drawing(); t.Root = new TREEMODEL.Node("Root"); var app = this.GetVisioApplication(); var doc = this.GetNewDoc(); var page = app.ActivePage; t.Render(page); AssertVA.AreEqual(3.0, 1.5, VisioAutomationTest.GetPageSize(page), 0.05); doc.Close(true); }
public static void TreeWithTwoPassLayoutAndFormatting() { var doc = SampleEnvironment.Application.ActiveDocument; var page1 = doc.Pages.Add(); var t = new TREEMODEL.Drawing(); t.Root = new TREEMODEL.Node("Root"); var na = new TREEMODEL.Node("A"); var nb = new TREEMODEL.Node("B"); var na1 = new TREEMODEL.Node("A1"); var na2 = new TREEMODEL.Node("A2"); var nb1 = new TREEMODEL.Node("B1"); var nb2 = new TREEMODEL.Node("B2"); t.Root.Children.Add(na); t.Root.Children.Add(nb); na.Children.Add(na1); na.Children.Add(na2); nb.Children.Add(nb1); nb1.Children.Add(nb2); var fontname = "Segoe UI"; var font = doc.Fonts[fontname]; foreach (var tn in t.Nodes) { var cells = new VA.DOM.ShapeCells(); tn.Cells = cells; cells.ParaHorizontalAlign = 0; // align text to left cells.VerticalAlign = 0; // align text block to top cells.CharFont = font.ID; cells.CharSize = "10pt"; cells.FillForegnd = "rgb(255,250,200)"; cells.CharColor = "rgb(255,0,0)"; } // TODO: Complete this sample }
public IVisio.Document DrawNamespacesAndClasses(IList <Type> types_) { this._client.Application.AssertApplicationAvailable(); string segoeui_fontname = "Segoe UI"; string segoeuilight_fontname = "Segoe UI Light"; string def_linecolor = "rgb(180,180,180)"; string def_shape_fill = "rgb(245,245,245)"; var doc = this._client.Document.New(8.5, 11, null); var fonts = doc.Fonts; var font_segoe = fonts[segoeui_fontname]; var font_segoelight = fonts[segoeuilight_fontname]; int fontid_segoe = font_segoe.ID16; int fontid_segoelight = font_segoelight.ID16; var types = types_.Select(t => new TypeInfo(t)); var pathbuilder = new PathTreeBuilder(); foreach (var type in types) { pathbuilder.Add(type.Type.Namespace); } var namespaces = pathbuilder.GetPaths(); var tree_layout = new VATREE.Drawing(); tree_layout.LayoutOptions.Direction = VATREE.LayoutDirection.Down; tree_layout.LayoutOptions.ConnectorType = VATREE.ConnectorType.PolyLine; var ns_node_map = new Dictionary <string, VATREE.Node>(namespaces.Count); var node_to_nslabel = new Dictionary <VATREE.Node, string>(namespaces.Count); // create nodes for every namespace foreach (string ns in namespaces) { string label = ns; int index_of_last_sep = ns.LastIndexOf(pathbuilder.Separator, StringComparison.Ordinal); if (index_of_last_sep > 0) { label = ns.Substring(index_of_last_sep + 1); } string ns1 = ns; var types_in_namespace = types.Where(t => t.Type.Namespace == ns1) .OrderBy(t => t.Type.Name) .Select(t => t.Label); var node = new VATREE.Node(ns); node.Size = new Drawing.Size(2.0, (0.15) * (1 + 2 + types_in_namespace.Count())); var markup = new Text.Markup.TextElement(); var m1 = markup.AddElement(label + "\n"); m1.CharacterCells.Font = fontid_segoe; m1.CharacterCells.Size = "12.0pt"; m1.CharacterCells.Style = "1"; // Bold var m2 = markup.AddElement(); m2.CharacterCells.Font = fontid_segoe; m2.CharacterCells.Size = "8.0pt"; m2.AddText(string.Join("\n", types_in_namespace)); node.Text = markup; ns_node_map[ns] = node; node_to_nslabel[node] = label; } // add children to nodes foreach (string ns in namespaces) { var parent_ns = pathbuilder.PathToParentPath[ns]; if (parent_ns != null) { // the current namespace has a parent var parent_node = ns_node_map[parent_ns]; var child_node = ns_node_map[ns]; parent_node.Children.Add(child_node); } else { // that means this namespace is a root, forget about it } } if (pathbuilder.Roots.Count == 0) { } else if (pathbuilder.Roots.Count == 1) { // when there is exactly one root namespace, then that node will be the tree's root node var first_root = pathbuilder.Roots[0]; var root_n = ns_node_map[first_root]; tree_layout.Root = root_n; } else { // if there are multiple root namespaces, inject an empty placeholder root var root_n = new VATREE.Node(); tree_layout.Root = root_n; foreach (var root_ns in pathbuilder.Roots) { var node = ns_node_map[root_ns]; tree_layout.Root.Children.Add(node); } } // format the shapes foreach (var node in tree_layout.Nodes) { if (node.Cells == null) { node.Cells = new DOM.ShapeCells(); } node.Cells.FillForegnd = def_shape_fill; //node.ShapeCells.LineWeight = "0"; //node.ShapeCells.LinePattern = "0"; node.Cells.LineColor = def_linecolor; node.Cells.ParaHorizontalAlign = "0"; node.Cells.VerticalAlign = "0"; } var cxn_cells = new DOM.ShapeCells(); cxn_cells.LineColor = def_linecolor; tree_layout.LayoutOptions.ConnectorCells = cxn_cells; tree_layout.Render(doc.Application.ActivePage); DeveloperCommands.hide_ui_stuff(doc); return(doc); }
public IVisio.Document DrawNamespaces(IList <Type> types) { this._client.Application.AssertApplicationAvailable(); string def_linecolor = "rgb(140,140,140)"; string def_fillcolor = "rgb(240,240,240)"; string def_font = "Segoe UI"; var doc = this._client.Document.New(8.5, 11, null); var fonts = doc.Fonts; var font = fonts[def_font]; int fontid = font.ID16; var pathbuilder = new PathTreeBuilder(); foreach (var type in types) { pathbuilder.Add(type.Namespace); } var namespaces = pathbuilder.GetPaths(); var tree_layout = new VATREE.Drawing(); tree_layout.LayoutOptions.Direction = VATREE.LayoutDirection.Right; tree_layout.LayoutOptions.ConnectorType = VATREE.ConnectorType.CurvedBezier; var ns_node_map = new Dictionary <string, VATREE.Node>(namespaces.Count); // create nodes for every namespace foreach (string ns in namespaces) { string label = ns; int index_of_last_sep = ns.LastIndexOf(pathbuilder.Separator, StringComparison.Ordinal); if (index_of_last_sep > 0) { label = ns.Substring(index_of_last_sep + 1); } var node = new VATREE.Node(ns); node.Text = new Text.Markup.TextElement(label); node.Size = new Drawing.Size(2.0, 0.25); ns_node_map[ns] = node; } // add children to nodes foreach (string ns in namespaces) { var parent_ns = pathbuilder.PathToParentPath[ns]; if (parent_ns != null) { // the current namespace has a parent var parent_node = ns_node_map[parent_ns]; var child_node = ns_node_map[ns]; parent_node.Children.Add(child_node); } else { // that means this namespace is a root, forget about it } } if (pathbuilder.Roots.Count == 0) { } else if (pathbuilder.Roots.Count == 1) { // when there is exactly one root namespace, then that node will be the tree's root node var first_root = pathbuilder.Roots[0]; var root_n = ns_node_map[first_root]; tree_layout.Root = root_n; } else { // if there are multiple root namespaces, inject an empty placeholder root var root_n = new VATREE.Node(); tree_layout.Root = root_n; foreach (var root_ns in pathbuilder.Roots) { var node = ns_node_map[root_ns]; tree_layout.Root.Children.Add(node); } } // format the shapes foreach (var node in tree_layout.Nodes) { if (node.Cells == null) { node.Cells = new DOM.ShapeCells(); } node.Cells.FillForegnd = def_fillcolor; node.Cells.CharFont = fontid; node.Cells.LineColor = def_linecolor; node.Cells.ParaHorizontalAlign = "0"; } var cxn_cells = new DOM.ShapeCells(); cxn_cells.LineColor = def_linecolor; tree_layout.LayoutOptions.ConnectorCells = cxn_cells; tree_layout.Render(doc.Application.ActivePage); DeveloperCommands.hide_ui_stuff(doc); return(doc); }
internal void RenderToVisio(Drawing drawing, IVisio.Page page) { if (drawing == null) { throw new System.ArgumentNullException(nameof(drawing)); } if (page== null) { throw new System.ArgumentNullException(nameof(page)); } if (drawing.Root == null) { throw new System.ArgumentException("Tree has root node set to null", nameof(drawing)); } const double border_width = 0.5; // Construct a layout tree from the hierarchy var treenodes = Internal.TreeOps.CopyTree( drawing.Root, n => n.Children, n => this.node_to_layout_node(n), (p, c) => p.AddChild(c)); // Perform the layout var layout = new InternalTree.TreeLayout<object>(); layout.Options.Direction = this.map_direction2(this.LayoutOptions.Direction); layout.Options.LevelSeparation = 1; layout.Options.SiblingSeparation = 0.25; layout.Options.SubtreeSeparation = 1; layout.Root.AddChild(treenodes[0]); layout.PerformLayout(); // Render the Document in Visio var bb = layout.GetBoundingBoxOfTree(); var app = page.Application; var documents = app.Documents; var basic_stencil = documents.OpenStencil(TreeLayout.basic_stencil_name); var connectors_stencil = documents.OpenStencil(TreeLayout.connectors_stencil_name); var basic_masters = basic_stencil.Masters; var connectors_masters = connectors_stencil.Masters; var node_master = basic_masters[this.rect_master_name]; var connector_master = connectors_masters[this.dc_master_name]; var page_node = new DOM.Page(); var page_size = bb.Size.Add(border_width*2, border_width*2.0); // fixup the nodes so that they render on the page foreach (var i in treenodes) { i.Position = i.Position.Add(border_width, border_width); } var centerpoints = treenodes.Select(tn => tn.Rect.Center).ToList(); var master_nodes = centerpoints.Select(cp => page_node.Shapes.Drop(node_master, cp)).ToList(); // For each OrgChart object, attach the shape that corresponds to it foreach (int i in Enumerable.Range(0, treenodes.Count)) { var tree_node = (Node)treenodes[i].Data; DOM.Shape master_node = master_nodes[i]; tree_node.DOMNode = master_node; if (tree_node.Cells!=null) { master_node.Cells = tree_node.Cells.ShallowCopy(); } master_node.Cells.Width = treenodes[i].Size.Width; master_node.Cells.Height = treenodes[i].Size.Height; master_node.Text = tree_node.Text; } if (this.LayoutOptions.ConnectorType == ConnectorType.DynamicConnector) { var orgchart_nodes = treenodes.Select(tn => tn.Data).Cast<Node>(); foreach (var parent in orgchart_nodes) { foreach (var child in parent.Children) { var parent_shape = (DOM.BaseShape)parent.DOMNode; var child_shape = (DOM.BaseShape)child.DOMNode; var connector = page_node.Shapes.Connect(connector_master, parent_shape, child_shape); connector.Cells = this.LayoutOptions.ConnectorCells; } } } else if (this.LayoutOptions.ConnectorType == ConnectorType.CurvedBezier) { foreach (var connection in layout.EnumConnections()) { var bez = layout.GetConnectionBezier(connection); var shape = page_node.Shapes.DrawBezier(bez); shape.Cells = this.LayoutOptions.ConnectorCells; } } else if (this.LayoutOptions.ConnectorType == ConnectorType.PolyLine) { foreach (var connection in layout.EnumConnections()) { var polyline = layout.GetConnectionPolyline(connection); var shape = page_node.Shapes.DrawPolyLine(polyline); shape.Cells = this.LayoutOptions.ConnectorCells; } } else { string msg = "Unsupported Connector Type"; throw new AutomationException(msg); } page_node.Size = page_size; page_node.Render(page); // Attach all the orgchart nodes to the Visio shapes that were created foreach (int i in Enumerable.Range(0, treenodes.Count)) { var orgnode = (Node) treenodes[i].Data; var shape = (DOM.BaseShape)orgnode.DOMNode; orgnode.VisioShape = shape.VisioShape; } }