private void buttonGraph_Click(object sender, RibbonControlEventArgs e) { var form = new FormDirectedGraph(); var result = form.ShowDialog(); if (result != DialogResult.OK) { return; } var text = form.GraphText.Trim(); var lines = text.Split('\n').Select(s => s.Trim()).Where( s=>s.Length>0).ToList(); var model = new VA.Models.DirectedGraph.Drawing(); int cn = 0; var dic = new Dictionary<string, VA.Models.DirectedGraph.Shape>(); foreach (var line in lines) { var tokens = line.Split(new[] {"->"}, System.StringSplitOptions.RemoveEmptyEntries); if (tokens.Length==0) { // do nothing } else if (tokens.Length==1) { string from = tokens[0]; if (dic.ContainsKey(from)) { } else { } } else if (tokens.Length >=2 ) { string from = tokens[0]; string to = tokens[1]; VA.Models.DirectedGraph.Shape fromnode; VA.Models.DirectedGraph.Shape tonode; if (!dic.ContainsKey(from)) { fromnode = model.AddShape(from, from, "basic_u.vss", "rectangle"); fromnode.Label = from; dic[from] = fromnode; } else { fromnode = dic[from]; } if (!dic.ContainsKey(to)) { tonode= model.AddShape(to, to, "basic_u.vss", "rectangle"); tonode.Label = to; dic[to] = tonode; } else { tonode = dic[to]; } model.AddConnection("C" + cn.ToString(), fromnode, tonode); cn +=1; } } var app = Globals.ThisAddIn.Application; var doc = Globals.ThisAddIn.Application.ActiveDocument; IVisio.Page page; if (doc==null) { var docs = app.Documents; doc = docs.Add(""); var pages = doc.Pages; page = pages[1]; } else { page = doc.Pages.Add(); } var visio_options = new DGMODEL.VisioLayoutOptions(); model.Render(page,visio_options); var pl = new VA.Pages.PageLayout.FlowchartLayout(); pl.ConnectorStyle = VisioAutomation.Pages.PageLayout.ConnectorStyle.Flowchart; pl.ConnectorAppearance = VisioAutomation.Pages.PageLayout.ConnectorAppearance.Curved; pl.Apply(page); page.ResizeToFitContents(); }
private void buttonGraph_Click(object sender, RibbonControlEventArgs e) { var form = new FormDirectedGraph(); var result = form.ShowDialog(); if (result != DialogResult.OK) { return; } var text = form.GraphText.Trim(); var lines = text.Split('\n').Select(s => s.Trim()).Where(s => s.Length > 0).ToList(); var model = new VA.Models.DirectedGraph.Drawing(); int cn = 0; var dic = new Dictionary <string, VA.Models.DirectedGraph.Shape>(); foreach (var line in lines) { var tokens = line.Split(new[] { "->" }, System.StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 0) { // do nothing } else if (tokens.Length == 1) { string from = tokens[0]; if (dic.ContainsKey(from)) { } else { } } else if (tokens.Length >= 2) { string from = tokens[0]; string to = tokens[1]; VA.Models.DirectedGraph.Shape fromnode; VA.Models.DirectedGraph.Shape tonode; if (!dic.ContainsKey(from)) { fromnode = model.AddShape(from, from, "basic_u.vss", "rectangle"); fromnode.Label = from; dic[from] = fromnode; } else { fromnode = dic[from]; } if (!dic.ContainsKey(to)) { tonode = model.AddShape(to, to, "basic_u.vss", "rectangle"); tonode.Label = to; dic[to] = tonode; } else { tonode = dic[to]; } model.AddConnection("C" + cn.ToString(), fromnode, tonode); cn += 1; } } var app = Globals.ThisAddIn.Application; var doc = Globals.ThisAddIn.Application.ActiveDocument; IVisio.Page page; if (doc == null) { var docs = app.Documents; doc = docs.Add(""); var pages = doc.Pages; page = pages[1]; } else { page = doc.Pages.Add(); } var visio_options = new DGMODEL.VisioLayoutOptions(); model.Render(page, visio_options); var pl = new VA.Pages.PageLayout.FlowchartLayout(); pl.ConnectorStyle = VisioAutomation.Pages.PageLayout.ConnectorStyle.Flowchart; pl.ConnectorAppearance = VisioAutomation.Pages.PageLayout.ConnectorAppearance.Curved; pl.Apply(page); page.ResizeToFitContents(); }