private DirectedGraphLayout create_sample_graph()
        {
            var d = new DirectedGraphLayout();

            var basic_stencil = "basic_u.vss";
            var n0            = d.AddShape("n0", "Node 0", basic_stencil, "Rectangle");

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

            return(d);
        }
        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();
        }
Beispiel #3
0
        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";
            }
        }
Beispiel #4
0
        protected override void ProcessRecord()
        {
            var dg_model = new DirectedGraphLayout();

            this.WriteObject(dg_model);
        }
Beispiel #5
0
        private static DirectedGraphLayout 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 DirectedGraphLayout();

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

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

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

            // Format Node 1
            n1.Cells = new ShapeCells();
            n1.Cells.FillForeground = "rgb(255,0,0)";
            n1.Cells.FillBackground = "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     = VisioAutomation.Models.ConnectorType.Curved;
            var rightangle = VisioAutomation.Models.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 ShapeCells();
            c0.Cells.LineBeginArrow = 1;
            c0.Cells.LineWeight     = 0.10;

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

            // Format connector 2 to point "back" and "forward"
            c2.Cells = new ShapeCells();
            c2.Cells.LineEndArrow   = 1;
            c2.Cells.LineBeginArrow = 1;
            c2.Cells.LineWeight     = 0.10;
            return(directed_graph_drawing);
        }