private static void GetRenderOptionsFromXml(SXL.XElement el, MsaglLayoutOptions options) { System.Func <string, double> double_parse = str => double.Parse(str, System.Globalization.CultureInfo.InvariantCulture); options.UseDynamicConnectors = el.GetAttributeValue("usedynamicconnectors", bool.Parse); options.ScalingFactor = el.GetAttributeValue("scalingfactor", double_parse); }
public static void DirectedGraphViaMsagl() { var page1 = SampleEnvironment.Application.ActiveDocument.Pages.Add(); var directed_graph_drawing = DirectedGraphLayoutSamples.get_dg_drawing(); var options = new MsaglLayoutOptions(); options.UseDynamicConnectors = false; directed_graph_drawing.Render(page1, options); }
private static void _get_render_options_from_xml(SXL.XElement el, MsaglLayoutOptions options) { var culture = System.Globalization.CultureInfo.InvariantCulture; double DoubleParse(string str) => double.Parse(str, culture); options.UseDynamicConnectors = el.GetAttributeValue("usedynamicconnectors", bool.Parse); options.ScalingFactor = el.GetAttributeValue("scalingfactor", DoubleParse); }
public void DirectedGraph_WithDynamicConnectors() { var directed_graph_drawing = this.create_sample_graph(); var options = new MsaglLayoutOptions(); options.UseDynamicConnectors = true; var visapp = this.GetVisioApplication(); var doc = this.GetNewDoc(); var page1 = visapp.ActivePage; directed_graph_drawing.Render(page1, options); string output_filename = TestGlobals.TestHelper.GetOutputFilename(nameof(DirectedGraph_WithDynamicConnectors), ".vsd"); doc.SaveAs(output_filename); doc.Close(); }
public void DirectedGraph(IList <DirectedGraphLayout> graph) { this._client.Application.AssertApplicationAvailable(); this._client.WriteVerbose("Start rendering directed graph"); var app = this._client.Application.Get(); this._client.WriteVerbose("Creating a New Document For the Directed Graphs"); var doc = this._client.Document.New(null); int num_pages_created = 0; var doc_pages = doc.Pages; foreach (int i in Enumerable.Range(0, graph.Count)) { var dg = graph[i]; var options = new MsaglLayoutOptions(); options.UseDynamicConnectors = false; // if this is the first page to drawe // then reuse the initial empty page in the document // otherwise, create a new page. var page = num_pages_created == 0 ? app.ActivePage : doc_pages.Add(); this._client.WriteVerbose("Rendering page: {0}", i + 1); dg.Render(page, options); this._client.Page.ResizeToFitContents(new Drawing.Size(1.0, 1.0), true); this._client.View.Zoom(VisioAutomation.Scripting.View.Zoom.ToPage); this._client.WriteVerbose("Finished rendering page"); num_pages_created++; } this._client.WriteVerbose("Finished rendering all pages"); this._client.WriteVerbose("Finished rendering directed graph."); }
public void RenderDirectedGraphWithCustomProps() { var d = new DirectedGraphLayout(); var n0 = d.AddShape("n0", "Untitled Node", "basflo_u.vss", "Decision"); n0.Size = new VA.Geometry.Size(3, 2); n0.CustomProperties = new CustomPropertyDictionary(); n0.CustomProperties["p1"] = new CustomPropertyCells("\"v1\""); n0.CustomProperties["p2"] = new CustomPropertyCells("\"v2\""); n0.CustomProperties["p3"] = new CustomPropertyCells("\"v3\""); var options = new 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 = CustomPropertyHelper.GetCells(n0.VisioShape, CellValueType.Formula); Assert.IsTrue(props_dic.Count >= 3); Assert.AreEqual("\"v1\"", props_dic["p1"].Value.Value); Assert.AreEqual("\"v2\"", props_dic["p2"].Value.Value); Assert.AreEqual("\"v3\"", props_dic["p3"].Value.Value); page1.Application.ActiveWindow.ViewFit = (short)IVisio.VisWindowFit.visFitPage; string output_filename = TestGlobals.TestHelper.GetOutputFilename(nameof(RenderDirectedGraphWithCustomProps), ".vsd"); doc.SaveAs(output_filename); doc.Close(); }
public static void RenderVisioDiagram(RegEx regex) { // Start Visio Visio.Application app = new Visio.Application(); // Create a new document. Visio.Document doc = app.Documents.Add(string.Empty); // The new document will have one page, // get the a reference to it. Visio.Page page1 = doc.Pages[1]; // Name the page. This is want is shown in the page tabs. page1.Name = "Diagram"; DirectedGraphLayout d = new DirectedGraphLayout(); string basic_stencil = "basic_u.vss"; Shape[] shapes = new Shape[regex.States.Count]; for (int i = 0, len = regex.States.Count; i < len; i++) { string stateInfo = $"State {i}"; if (i == regex.StartingState) { stateInfo += Environment.NewLine + "[START]"; } if (regex.States[i].Ending) { stateInfo += Environment.NewLine + "[END]"; } shapes[i] = d.AddShape( $"s{i}", stateInfo, basic_stencil, "Rectangle" ); } for (int i = 0, len = regex.Edges.Count; i < len; i++) { Edge edge = regex.Edges[i]; const ConnectorType type = ConnectorType.RightAngle; const int beginArrow = 20; const int endArrow = 5; if (string.IsNullOrEmpty(edge.Value)) { d.AddConnection( $"e{i}", shapes[edge.Origin], shapes[edge.Destination], string.Empty, type, beginArrow, endArrow, string.Empty ); } else { string edgeValue = $"\"{edge.Value}\"" + Environment.NewLine + $"[{string.Join(",", edge.CaptureGroups)}]"; Shape edgeShape = d.AddShape($"e{i}", edgeValue, basic_stencil, "Diamond"); edgeShape.Size = new Size(2.5, 1.75); d.AddConnection($"e{i}_1", shapes[edge.Origin], edgeShape, string.Empty, type, beginArrow, endArrow, string.Empty); d.AddConnection($"e{i}_2", edgeShape, shapes[edge.Destination], string.Empty, type, beginArrow, endArrow, string.Empty); } //d.AddConnection( // $"e{i}", // shapes[edge.Origin], // shapes[edge.Destination], // edgeValue, // ConnectorType.RightAngle //); } MsaglLayoutOptions options = new MsaglLayoutOptions(); d.Render(page1, options); foreach (Visio.Shape shape in page1.Shapes) { Visio.Cell cell = shape.CellsU["Char.Size"]; cell.FormulaU = "20 pt"; } }