Example #1
0
        private static void ResolveMasters(DGMODEL.Drawing 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 VA.Internal.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   = 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;
            }
        }
Example #2
0
        public VA.DOM.Page CreateDOMPage(DGMODEL.Drawing layout_diagram, IVisio.Application vis)
        {
            var page_node = new VA.DOM.Page();

            ResolveMasters(layout_diagram, vis);

            var msagl_graph = this.CreateMSAGLGraph(layout_diagram);

            CreateDOMShapes(page_node.Shapes, msagl_graph, vis);

            if (this.LayoutOptions.UseDynamicConnectors)
            {
                CreateDynamicConnectorEdges(page_node.Shapes, msagl_graph);
            }
            else
            {
                CreateBezierEdges(page_node.Shapes, msagl_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);
        }
Example #3
0
        public void  Render(
            DGMODEL.Drawing layout_diagram,
            IVisio.Page page)
        {
            // Create A DOM and render it to the page
            var app       = page.Application;
            var page_node = 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;
            }
        }
        public void RenderDirectedGraphWithCustomProps()
        {
            var d = new DG.Drawing();

            var n0 = d.AddShape("n0", "Untitled Node", "basflo_u.vss",
                                   "Decision");
            n0.Size = new VA.Drawing.Size(3, 2);
            n0.CustomProperties = new Dictionary<string, VACUSTPROP.CustomPropertyCells>();
            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.GetTestMethodOutputFilename(".vsd");
            doc.SaveAs(output_filename);
            doc.Close();
        }
Example #5
0
        public void RenderDirectedGraphWithCustomProps()
        {
            var d = new VA.Models.DirectedGraph.Drawing();

            var n0 = d.AddShape("n0", "Untitled Node", "basflo_u.vss",
                                "Decision");

            n0.Size                   = new VA.Drawing.Size(3, 2);
            n0.CustomProperties       = new Dictionary <string, CustomPropertyCells>();
            n0.CustomProperties["p1"] = new CustomPropertyCells("v1");
            n0.CustomProperties["p2"] = new CustomPropertyCells("v2");
            n0.CustomProperties["p3"] = new CustomPropertyCells("v3");

            var options = new VA.Models.DirectedGraph.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.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;

            doc.Close(true);
        }
Example #6
0
        private MG.GeometryGraph CreateMSAGLGraph(DGMODEL.Drawing layout_diagram)
        {
            var msagl_graph = new MG.GeometryGraph();
            var defsize     = new VA.Drawing.Size(this.LayoutOptions.DefaultShapeSize.Width,
                                                  this.LayoutOptions.DefaultShapeSize.Height);

            // Create the nodes in MSAGL
            foreach (var layout_shape in layout_diagram.Shapes)
            {
                var nodesize   = ToMSAGLCoordinates(layout_shape.Size ?? defsize);
                var msagl_node = new MG.Node(layout_shape.ID,
                                             MG.Splines.CurveFactory.CreateBox(nodesize.Width, nodesize.Height,
                                                                               new MG.Point()));
                msagl_graph.AddNode(msagl_node);
                msagl_node.UserData = layout_shape;
            }

            bool connectors_ok = this.validate_connectors(layout_diagram);
            // TODO: What to do if connectors_ok is false?

            var msagl_size = this.ToMSAGLCoordinates(DefaultBezierConnectorLabelBoxSize);

            // Create the MSAGL Connectors
            foreach (var layout_connector in layout_diagram.Connectors)
            {
                if (layout_connector.From == null)
                {
                    throw new System.ArgumentException("Connector's From node is null");
                }

                if (layout_connector.To == null)
                {
                    throw new System.ArgumentException("Connector's To node is null");
                }

                var from_node = msagl_graph.NodeMap[layout_connector.From.ID];
                var to_node   = msagl_graph.NodeMap[layout_connector.To.ID];

                var new_edge = new MG.Edge(from_node, to_node);
                new_edge.ArrowheadAtTarget = false;
                new_edge.UserData          = layout_connector;
                msagl_graph.AddEdge(new_edge);

                new_edge.Label = new Microsoft.Msagl.Label(msagl_size.Width, msagl_size.Height, new_edge);
            }

            msagl_graph.CalculateLayout();

            this.msagl_bb = new VA.Drawing.Rectangle(
                msagl_graph.BoundingBox.Left,
                msagl_graph.BoundingBox.Bottom,
                msagl_graph.BoundingBox.Right,
                msagl_graph.BoundingBox.Top);

            this.layout_bb = new VA.Drawing.Rectangle(0, 0, this.msagl_bb.Width, msagl_bb.Height)
                             .Multiply(ScaleToDocument, ScaleToDocument);

            return(msagl_graph);
        }
Example #7
0
        public static void Render(IVisio.Page page, VisioAutomation.Models.DirectedGraph.Drawing drawing, DGMODEL.MSAGLLayoutOptions options)
        {
            var renderer = new VA.Models.DirectedGraph.MSAGLRenderer();

            renderer.LayoutOptions = options;
            renderer.Render(drawing, page);
            page.ResizeToFitContents(renderer.LayoutOptions.ResizeBorderWidth);
        }
Example #8
0
        private bool validate_connectors(DGMODEL.Drawing layout_diagram)
        {
            bool success = true;

            foreach (var layout_connector in layout_diagram.Connectors)
            {
                if (layout_connector.From == null)
                {
                    throw new VA.AutomationException("Connector's From node is null");
                }

                if (layout_connector.To == null)
                {
                    throw new VA.AutomationException("Connector's From node is null");
                }
            }

            return(success);
        }
Example #9
0
        private DG.Drawing create_sample_graph()
        {
            var d = new DG.Drawing();

            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.Connect("c0", n0, n1, "0 -> 1", ConnectorType.Curved);
            var c1 = d.Connect("c1", n1, n2, "1 -> 2", ConnectorType.RightAngle);
            var c2 = d.Connect("c2", n1, n0, "0 -> 1", ConnectorType.Curved);
            var c3 = d.Connect("c3", n0, n2, "0 -> 2", ConnectorType.Straight);
            var c4 = d.Connect("c4", n2, n3, "2 -> 3", ConnectorType.Curved);
            var c5 = d.Connect("c5", n3, n0, "3 -> 0", ConnectorType.Curved);

            return(d);
        }
        private DG.Drawing create_sample_graph()
        {
            var d = new DG.Drawing();

            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", VACONNECT.ConnectorType.Curved);
            var c1 = d.AddConnection("c1", n1, n2, "1 -> 2", VACONNECT.ConnectorType.RightAngle);
            var c2 = d.AddConnection("c2", n1, n0, "0 -> 1", VACONNECT.ConnectorType.Curved);
            var c3 = d.AddConnection("c3", n0, n2, "0 -> 2", VACONNECT.ConnectorType.Straight);
            var c4 = d.AddConnection("c4", n2, n3, "2 -> 3", VACONNECT.ConnectorType.Curved);
            var c5 = d.AddConnection("c5", n3, n0, "3 -> 0", VACONNECT.ConnectorType.Curved);

            return d;
        }
        private static DGMODEL.Drawing 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.Drawing();

            // 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 VA.DOM.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     = VA.Shapes.Connections.ConnectorType.Curved;
            var rightangle = VA.Shapes.Connections.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 VA.DOM.ShapeCells();
            c0.Cells.BeginArrow = 1;
            c0.Cells.LineWeight = 0.10;

            // Format connector 1 to point "forward"
            c1.Cells            = new VA.DOM.ShapeCells();
            c1.Cells.EndArrow   = 1;
            c1.Cells.LineWeight = 0.10;

            // Format connector 2 to point "back" and "forward"
            c2.Cells            = new VA.DOM.ShapeCells();
            c2.Cells.EndArrow   = 1;
            c2.Cells.BeginArrow = 1;
            c2.Cells.LineWeight = 0.10;
            return(directed_graph_drawing);
        }
        public static void DirectedGraphViaVisio()
        {
            var page1 = SampleEnvironment.Application.ActiveDocument.Pages.Add();
            var directed_graph_drawing = new DGMODEL.Drawing();

            // Create a Node 0
            var n0 = directed_graph_drawing.AddShape("n0", "N0 Untitled Node", "basflo_u.vss", "Decision");

            // Format Node 0
            n0.Size = new VA.Drawing.Size(3, 2);

            // Create Node 1
            var n1 = directed_graph_drawing.AddShape("n1", "N1", "basflo_u.vss", "Decision");

            // Format Node 1
            n1.Cells = new VA.DOM.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_u.vss", "Server");

            // Create Node 3

            var n3 = directed_graph_drawing.AddShape("n3", "N3", "basflo_u.vss", "Data");

            // Create Node 4
            var n4 = directed_graph_drawing.AddShape("n4", "N4", "basflo_u.vss", "Data");

            // Create the connectors to join the nodes
            // Note that Node 4 is deliberately not connected to any other node
            var c0 = directed_graph_drawing.Connect("c0", n0, n1, null, ConnectorType.Curved);
            var c1 = directed_graph_drawing.Connect("c1", n1, n2, "YES", ConnectorType.RightAngle);
            var c2 = directed_graph_drawing.Connect("c2", n3, n4, "NO", ConnectorType.Curved);
            var c3 = directed_graph_drawing.Connect("c3", n0, n2, null, ConnectorType.Straight);
            var c4 = directed_graph_drawing.Connect("c4", n2, n3, null, ConnectorType.Curved);
            var c5 = directed_graph_drawing.Connect("c5", n3, n0, null, ConnectorType.Curved);

            // Format connector 0 to point "back"
            c0.Cells = new VA.DOM.ShapeCells();
            c0.Cells.BeginArrow = 1;
            c0.Cells.LineWeight = 0.10;

            // Format connector 1 to point "forward"
            c1.Cells = new VA.DOM.ShapeCells();
            c1.Cells.EndArrow = 1;
            c1.Cells.LineWeight = 0.10;

            // Format connector 2 to point "back" and "forward"
            c2.Cells = new VA.DOM.ShapeCells();
            c2.Cells.EndArrow = 1;
            c2.Cells.BeginArrow = 1;
            c2.Cells.LineWeight = 0.10;

            // Perform the rendering
            var options = new DGMODEL.MSAGLLayoutOptions();
            options.UseDynamicConnectors = false;

            directed_graph_drawing.Render(page1);

            var layout_config = new VA.Pages.PageLayout.HierarchyLayout();
            layout_config.Direction = VA.Pages.PageLayout.Direction.BottomToTop;
            layout_config.HorizontalAlignment = VA.Pages.PageLayout.HorizontalAlignment.Center;
            layout_config.AvenueSize = new VA.Drawing.Size(1, 1);
            layout_config.ConnectorAppearance = VA.Pages.PageLayout.ConnectorAppearance.Curved;
            layout_config.Apply(page1);

            page1.ResizeToFitContents(new VA.Drawing.Size(0.5, 0.5));
        }
        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();

        }
        public IList<IVisio.Shape> Table(System.Data.DataTable datatable,
                                          IList<double> widths,
                                          IList<double> heights,
                                          Drawing.Size cellspacing)
        {
            this.Client.Application.AssertApplicationAvailable();
            this.Client.Document.AssertDocumentAvailable();

            if (datatable == null)
            {
                throw new System.ArgumentNullException(nameof(datatable));
            }

            if (widths == null)
            {
                throw new System.ArgumentNullException(nameof(widths));
            }

            if (heights == null)
            {
                throw new System.ArgumentNullException(nameof(heights));
            }

            if (datatable.Rows.Count < 1)
            {
                return new List<IVisio.Shape>(0);
            }


            string master = "Rectangle";
            string stencil = "basic_u.vss";
            var stencildoc = this.Client.Document.OpenStencil(stencil);
            var stencildoc_masters = stencildoc.Masters;
            var masterobj = stencildoc_masters.ItemU[master];

            var app = this.Client.Application.Get();
            var application = app;
            var active_document = application.ActiveDocument;
            var pages = active_document.Pages;

            var page = pages.Add();
            page.Background = 0; // ensure this is a foreground page

            var pagesize = this.Client.Page.GetSize();

            var layout = new GRIDLAYOUT.GridLayout(datatable.Columns.Count, datatable.Rows.Count, new Drawing.Size(1, 1), masterobj);
            layout.Origin = new Drawing.Point(0, pagesize.Height);
            layout.CellSpacing = cellspacing;
            layout.RowDirection = GRIDLAYOUT.RowDirection.TopToBottom;
            layout.PerformLayout();

            foreach (var i in Enumerable.Range(0, datatable.Rows.Count))
            {
                var row = datatable.Rows[i];

                for (int col_index = 0; col_index < row.ItemArray.Length; col_index++)
                {
                    var col = row.ItemArray[col_index];
                    var cur_label = (col != null) ? col.ToString() : string.Empty;
                    var node = layout.GetNode(col_index, i);
                    node.Text = cur_label;
                }
            }

            using (var undoscope = this.Client.Application.NewUndoScope("Draw Table"))
            {
                layout.Render(page);
                page.ResizeToFitContents();
            }

            var page_shapes = page.Shapes;
            var shapes = layout.Nodes.Select(n => n.Shape).ToList();
            return shapes;

        }
        public IVisio.Shape DoughnutSlice(Drawing.Point center,
                          double inner_radius,
                          double outer_radius,
                          double start_angle,
                          double end_angle)
        {
            this.Client.Application.AssertApplicationAvailable();
            this.Client.Document.AssertDocumentAvailable();

            var application = this.Client.Application.Get();
            using (var undoscope = this.Client.Application.NewUndoScope("Draw Pie Slice"))
            {
                var active_page = application.ActivePage;
                var slice = new Models.Charting.PieSlice(center, inner_radius, outer_radius, start_angle, end_angle);
                var shape = slice.Render(active_page);
                return shape;
            }
        }
 public IVisio.Shape Oval(Drawing.Point center, double radius)
 {
     var surface = this.GetDrawingSurface();
     var application = this.Client.Application.Get();
     using (var undoscope = this.Client.Application.NewUndoScope("Draw Oval"))
     {
         var shape = surface.DrawOval(center, radius);
         return shape;
     }
 }
Example #17
0
        public static void DirectedGraphViaVisio()
        {
            var page1 = SampleEnvironment.Application.ActiveDocument.Pages.Add();
            var directed_graph_drawing = new DGMODEL.Drawing();

            // Create a Node 0
            var n0 = directed_graph_drawing.AddShape("n0", "N0 Untitled Node", "basflo_u.vss", "Decision");

            // Format Node 0
            n0.Size = new VA.Drawing.Size(3, 2);

            // Create Node 1
            var n1 = directed_graph_drawing.AddShape("n1", "N1", "basflo_u.vss", "Decision");

            // Format Node 1
            n1.Cells             = new VA.DOM.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_u.vss", "Server");

            // Create Node 3

            var n3 = directed_graph_drawing.AddShape("n3", "N3", "basflo_u.vss", "Data");

            // Create Node 4
            var n4 = directed_graph_drawing.AddShape("n4", "N4", "basflo_u.vss", "Data");

            // Create the connectors to join the nodes
            // Note that Node 4 is deliberately not connected to any other node
            var c0 = directed_graph_drawing.Connect("c0", n0, n1, null, ConnectorType.Curved);
            var c1 = directed_graph_drawing.Connect("c1", n1, n2, "YES", ConnectorType.RightAngle);
            var c2 = directed_graph_drawing.Connect("c2", n3, n4, "NO", ConnectorType.Curved);
            var c3 = directed_graph_drawing.Connect("c3", n0, n2, null, ConnectorType.Straight);
            var c4 = directed_graph_drawing.Connect("c4", n2, n3, null, ConnectorType.Curved);
            var c5 = directed_graph_drawing.Connect("c5", n3, n0, null, ConnectorType.Curved);

            // Format connector 0 to point "back"
            c0.Cells            = new VA.DOM.ShapeCells();
            c0.Cells.BeginArrow = 1;
            c0.Cells.LineWeight = 0.10;

            // Format connector 1 to point "forward"
            c1.Cells            = new VA.DOM.ShapeCells();
            c1.Cells.EndArrow   = 1;
            c1.Cells.LineWeight = 0.10;

            // Format connector 2 to point "back" and "forward"
            c2.Cells            = new VA.DOM.ShapeCells();
            c2.Cells.EndArrow   = 1;
            c2.Cells.BeginArrow = 1;
            c2.Cells.LineWeight = 0.10;

            // Perform the rendering
            var options = new DGMODEL.MSAGLLayoutOptions();

            options.UseDynamicConnectors = false;

            directed_graph_drawing.Render(page1);

            var layout_config = new VA.Pages.PageLayout.HierarchyLayout();

            layout_config.Direction           = VA.Pages.PageLayout.Direction.BottomToTop;
            layout_config.HorizontalAlignment = VA.Pages.PageLayout.HorizontalAlignment.Center;
            layout_config.AvenueSize          = new VA.Drawing.Size(1, 1);
            layout_config.ConnectorAppearance = VA.Pages.PageLayout.ConnectorAppearance.Curved;
            layout_config.Apply(page1);

            page1.ResizeToFitContents(new VA.Drawing.Size(0.5, 0.5));
        }
        private static DGMODEL.Drawing 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.Drawing();

            // 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 VA.DOM.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 = VA.Shapes.Connections.ConnectorType.Curved;
            var rightangle = VA.Shapes.Connections.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 VA.DOM.ShapeCells();
            c0.Cells.BeginArrow = 1;
            c0.Cells.LineWeight = 0.10;

            // Format connector 1 to point "forward"
            c1.Cells = new VA.DOM.ShapeCells();
            c1.Cells.EndArrow = 1;
            c1.Cells.LineWeight = 0.10;

            // Format connector 2 to point "back" and "forward"
            c2.Cells = new VA.DOM.ShapeCells();
            c2.Cells.EndArrow = 1;
            c2.Cells.BeginArrow = 1;
            c2.Cells.LineWeight = 0.10;
            return directed_graph_drawing;
        }
        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();
        }