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); }
public IVisio.Document DrawNamespacesAndClasses() { return(this.DrawNamespacesAndClasses(DeveloperCommands.GetTypes())); }
public IVisio.Document DrawInteropEnumDocumentation() { this._client.Application.AssertApplicationAvailable(); var formdoc = new Models.Forms.FormDocument(); var helpstr = new System.Text.StringBuilder(); int chunksize = 70; var interop_enums = Interop.InteropHelper.GetEnums(); foreach (var enum_ in interop_enums) { int chunkcount = 0; var values = enum_.Values.OrderBy(i => i.Name).ToList(); foreach (var chunk in DeveloperCommands.Chunk(values, chunksize)) { helpstr.Length = 0; foreach (var val in chunk) { helpstr.AppendFormat("0x{0}\t{1}\n", val.Value.ToString("x"), val.Name); } var formpage = new Models.Forms.FormPage(); formpage.Size = new Drawing.Size(8.5, 11); formpage.Margin = new Drawing.Margin(0.5, 0.5, 0.5, 0.5); formpage.Title = enum_.Name; formpage.Body = helpstr.ToString(); if (chunkcount == 0) { formpage.Name = String.Format("{0}", enum_.Name); } else { formpage.Name = String.Format("{0} ({1})", enum_.Name, chunkcount + 1); } //docbuilder.BodyParaSpacingAfter = 2.0; formpage.BodyTextSize = 8.0; formdoc.Pages.Add(formpage); var tabstops = new[] { new Text.TabStop(1.5, Text.TabStopAlignment.Left) }; //VA.Text.TextFormat.SetTabStops(docpage.VisioBodyShape, tabstops); chunkcount++; } } formdoc.Subject = "Visio Interop Enum Documenation"; formdoc.Title = "Visio Interop Enum Documenation"; formdoc.Creator = ""; formdoc.Company = ""; //hide_ui_stuff(docbuilder.VisioDocument); var application = this._client.Application.Get(); var doc = formdoc.Render(application); return(doc); }