コード例 #1
0
        public void Page_SwitchPages()
        {
            var app = this.GetVisioApplication();

            var documents     = app.Documents;
            int old_doc_count = documents.Count;

            var doc1 = this.GetNewDoc();

            Assert.AreEqual(documents.Count, old_doc_count + 1);
            Assert.AreEqual(doc1.Pages.Count, 1);
            var page1 = doc1.Pages[1];

            Assert.AreEqual(app.ActivePage, page1);

            var page2 = doc1.Pages.Add();

            page2.Background = 0;
            VisioAutomationTest.SetPageSize(page2, this.StandardPageSize);

            var active_window = app.ActiveWindow;

            Assert.AreEqual(app.ActivePage, page2);
            active_window.Page = page1;
            Assert.AreEqual(app.ActivePage, page1);
            active_window.Page = page2;
            Assert.AreEqual(app.ActivePage, page2);
            doc1.Close(true);
        }
コード例 #2
0
        public void ShapeHelper_Test_GetNestedShapes_GroupWithSubGroups()
        {
            // group with subgroups
            var page          = this.GetNewPage();
            var active_window = page.Application.ActiveWindow;

            var shape0 = page.DrawRectangle(0, 0, 1, 1);
            var shape1 = page.DrawRectangle(2, 0, 3, 1);

            var group0 = VisioAutomationTest.SelectAndGroup(active_window, new[] { shape0, shape1 });

            page.Application.ActiveWindow.DeselectAll();

            var shape2 = page.DrawRectangle(0, 3, 1, 4);
            var shape3 = page.DrawRectangle(2, 0, 5, 6);

            var group1 = VisioAutomationTest.SelectAndGroup(active_window, new[] { shape2, shape3 });

            page.Application.ActiveWindow.Selection.DeselectAll();

            var group2 = VisioAutomationTest.SelectAndGroup(active_window, new[] { group0, group1 });

            page.Application.ActiveWindow.Selection.DeselectAll();

            var shapes = VA.Shapes.ShapeHelper.GetNestedShapes(group2);

            Assert.AreEqual(7, shapes.Count);
            Assert.IsTrue(shapes.Contains(shape0));
            Assert.IsTrue(shapes.Contains(shape1));
            Assert.IsTrue(shapes.Contains(shape2));
            Assert.IsTrue(shapes.Contains(shape3));
            Assert.IsTrue(shapes.Contains(group0));
            Assert.IsTrue(shapes.Contains(group1));
            page.Delete(0);
        }
コード例 #3
0
        public void ShapeSheet_Query_Demo_AllCellsAndSections()
        {
            var doc1  = this.GetNewDoc();
            var page1 = doc1.Pages[1];

            VisioAutomationTest.SetPageSize(page1, this.StandardPageSize);

            // draw simple shapes
            var s1 = page1.DrawRectangle(0, 0, 1, 1);
            var s2 = page1.DrawRectangle(2, 2, 3, 3);


            var query = new VA.ShapeSheet.Query.CellQuery();

            var name_to_src         = VA.ShapeSheet.SRCConstants.GetSRCDictionary();
            var section_to_secquery = new Dictionary <short, VA.ShapeSheet.Query.CellQuery.SectionQuery>();

            foreach (var kv in name_to_src)
            {
                var name = kv.Key;
                var src  = kv.Value;

                if (src.Section == (short)IVisio.VisSectionIndices.visSectionObject)
                {
                    query.Columns.Add(src, name);
                }
                else if ((src.Section == (short)IVisio.VisSectionIndices.visSectionFirst) ||
                         (src.Section == (short)IVisio.VisSectionIndices.visSectionFirstComponent) ||
                         (src.Section == (short)IVisio.VisSectionIndices.visSectionLast) ||
                         (src.Section == (short)IVisio.VisSectionIndices.visSectionInval) ||
                         (src.Section == (short)IVisio.VisSectionIndices.visSectionNone) ||
                         (src.Section == (short)IVisio.VisSectionIndices.visSectionFirst) ||
                         (src.Section == (short)IVisio.VisSectionIndices.visSectionLastComponent)
                         )
                {
                    //skip
                }
                else
                {
                    VA.ShapeSheet.Query.CellQuery.SectionQuery sec;
                    if (!section_to_secquery.ContainsKey(src.Section))
                    {
                        sec = query.Sections.Add((IVisio.VisSectionIndices)src.Section);
                        section_to_secquery[src.Section] = sec;
                    }
                    else
                    {
                        sec = section_to_secquery[src.Section];
                    }
                    sec.Columns.Add(src.Cell, name);
                }
            }

            var formulas1 = query.GetFormulas(s1);
            var formulas2 = query.GetFormulas(page1, new [] { s1.ID, s2.ID });

            doc1.Close(true);
        }
コード例 #4
0
        public void EnumerateShapes()
        {
            var page1 = GetNewPage();
            var app   = page1.Application;

            // -------------------------------
            var a1 = page1.Shapes.AsEnumerable().ToList();

            Assert.AreEqual(0, a1.Count);

            var a2 = VA.Shapes.ShapeHelper.GetNestedShapes(page1.Shapes.AsEnumerable());

            Assert.AreEqual(0, a2.Count);

            // -------------------------------

            var s1 = page1.DrawRectangle(0, 0, 1, 1);
            var b1 = page1.Shapes.AsEnumerable().ToList();

            Assert.AreEqual(1, b1.Count);

            var b2 = VA.Shapes.ShapeHelper.GetNestedShapes(page1.Shapes.AsEnumerable());

            Assert.AreEqual(1, b2.Count);

            // -------------------------------

            var s2 = page1.DrawRectangle(1, 0, 2, 1);
            var s3 = page1.DrawRectangle(2, 0, 3, 1);
            var c1 = page1.Shapes.AsEnumerable().ToList();

            Assert.AreEqual(3, c1.Count);

            var c2 = VA.Shapes.ShapeHelper.GetNestedShapes(page1.Shapes.AsEnumerable());

            Assert.AreEqual(3, c2.Count);

            // -------------------------------

            var active_window = app.ActiveWindow;
            var selection     = active_window.Selection;

            selection.DeselectAll();
            var g1 = VisioAutomationTest.SelectAndGroup(active_window, new[] { s2, s3 });

            var d1 = page1.Shapes.AsEnumerable().ToList();

            Assert.AreEqual(2, d1.Count);

            var d2 = VA.Shapes.ShapeHelper.GetNestedShapes(page1.Shapes.AsEnumerable());

            Assert.AreEqual(4, d2.Count);

            page1.Delete(0);
        }
コード例 #5
0
        public void OrgChart_FiveNodes()
        {
            // Verify that basic org chart connectivity is maintained

            var orgchart_doc = new OCMODEL.OrgChartDocument();

            var n_a = new OCMODEL.Node("A");
            var n_b = new OCMODEL.Node("B");
            var n_c = new OCMODEL.Node("C");
            var n_d = new OCMODEL.Node("D");
            var n_e = new OCMODEL.Node("E");

            n_a.Children.Add(n_b);
            n_a.Children.Add(n_c);
            n_c.Children.Add(n_d);
            n_c.Children.Add(n_e);

            n_a.Size = new VA.Drawing.Size(4, 2);

            orgchart_doc.OrgCharts.Add(n_a);

            var app = new IVisio.Application();

            orgchart_doc.Render(app);

            var active_page = app.ActivePage;
            var page        = active_page;

            page.ResizeToFitContents();

            var shapes           = active_page.Shapes.AsEnumerable().ToList();
            var shapes_2d        = shapes.Where(s => s.OneD == 0).ToList();
            var shapes_1d        = shapes.Where(s => s.OneD != 0).ToList();
            var shapes_connector = shapes.Where(s => s.Master.NameU == "Dynamic connector").ToList();

            Assert.AreEqual(5 + 4, shapes.Count());
            Assert.AreEqual(5, shapes_2d.Count());
            Assert.AreEqual(4, shapes_1d.Count());
            Assert.AreEqual(4, shapes_connector.Count());

            Assert.AreEqual("A", n_a.VisioShape.Text.Trim());
            // trimming because extra ending space is added (don't know why)
            Assert.AreEqual("B", n_b.VisioShape.Text.Trim());
            Assert.AreEqual("C", n_c.VisioShape.Text.Trim());
            Assert.AreEqual("D", n_d.VisioShape.Text.Trim());
            Assert.AreEqual("E", n_e.VisioShape.Text.Trim());

            Assert.AreEqual(new VA.Drawing.Size(4, 2), VisioAutomationTest.GetSize(n_a.VisioShape));
            Assert.AreEqual(orgchart_doc.LayoutOptions.DefaultNodeSize, VisioAutomationTest.GetSize(n_b.VisioShape));

            app.Quit(true);
        }
コード例 #6
0
        public void TreeLayout_MultiNode()
        {
            // Verify that a tree with multiple nodes can be drawn
            // Note that  the DefaultNodeSize option is being used

            var t = new TREEMODEL.Drawing();

            t.Root = new TREEMODEL.Node("Root");

            var na = new TREEMODEL.Node("A");
            var nb = new TREEMODEL.Node("B");

            var na1 = new TREEMODEL.Node("A1");
            var na2 = new TREEMODEL.Node("A2");

            var nb1 = new TREEMODEL.Node("B1");
            var nb2 = new TREEMODEL.Node("B2");

            t.Root.Children.Add(na);
            t.Root.Children.Add(nb);

            na.Children.Add(na1);
            na.Children.Add(na2);

            nb.Children.Add(nb1);
            nb1.Children.Add(nb2);

            t.LayoutOptions.DefaultNodeSize = new VA.Drawing.Size(1, 1);

            var app  = this.GetVisioApplication();
            var doc  = this.GetNewDoc();
            var page = app.ActivePage;

            t.Render(page);

            AssertVA.AreEqual(5.25, 8.0, VisioAutomationTest.GetPageSize(page), 0.05);

            Assert.AreEqual("Root", t.Root.VisioShape.Text);
            Assert.AreEqual("A", na.VisioShape.Text);
            Assert.AreEqual("B", nb.VisioShape.Text);

            Assert.AreEqual("A1", na1.VisioShape.Text);
            Assert.AreEqual("A2", na2.VisioShape.Text);

            Assert.AreEqual("B1", nb1.VisioShape.Text);
            Assert.AreEqual("B2", nb2.VisioShape.Text);

            doc.Close(true);
        }
コード例 #7
0
        public void DOM_DrawEmpty()
        {
            // Verify that an empty DOM page can be created and rendered
            var doc       = this.GetNewDoc();
            var page_node = new VA.DOM.Page();

            page_node.Size = new VA.Drawing.Size(5, 5);
            var page = page_node.Render(doc);

            Assert.AreEqual(0, page.Shapes.Count);
            Assert.AreEqual(new VA.Drawing.Size(5, 5), VisioAutomationTest.GetPageSize(page));

            page.Delete(0);
            doc.Close(true);
        }
コード例 #8
0
        public void ShapeHelper_Test_GetNestedShapes_GroupWithTwoSubShapes()
        {
            // group with two shapes
            var page   = this.GetNewPage();
            var shape0 = page.DrawRectangle(0, 0, 1, 1);
            var shape1 = page.DrawRectangle(2, 0, 3, 1);

            var active_window = page.Application.ActiveWindow;
            var group         = VisioAutomationTest.SelectAndGroup(active_window, new[] { shape0, shape1 });
            var shapes        = VA.Shapes.ShapeHelper.GetNestedShapes(group);

            Assert.AreEqual(3, shapes.Count);
            Assert.IsTrue(shapes.Contains(shape0));
            Assert.IsTrue(shapes.Contains(shape1));
            Assert.IsTrue(shapes.Contains(group));
            page.Delete(0);
        }
コード例 #9
0
        public void TreeLayout_SingleNode()
        {
            // Verify that a tree with a single node can be drawn
            var t = new TREEMODEL.Drawing();

            t.Root = new TREEMODEL.Node("Root");

            var app  = this.GetVisioApplication();
            var doc  = this.GetNewDoc();
            var page = app.ActivePage;

            t.Render(page);

            AssertVA.AreEqual(3.0, 1.5, VisioAutomationTest.GetPageSize(page), 0.05);

            doc.Close(true);
        }
コード例 #10
0
        public IVisio.Page GetNewPage(VisioAutomation.Drawing.Size s)
        {
            var app       = this.GetVisioApplication();
            var documents = app.Documents;

            if (documents.Count < 1)
            {
                documents.Add(string.Empty);
            }
            var active_document = app.ActiveDocument;
            var pages           = active_document.Pages;
            var page            = pages.Add();

            page.Background = 0;
            VisioAutomationTest.SetPageSize(page, s);

            return(page);
        }
コード例 #11
0
        public void DOM_DrawSimpleShape()
        {
            // Create the doc
            var page_node = new VA.DOM.Page();
            var vrect1    = new VA.DOM.Rectangle(1, 1, 9, 9);

            vrect1.Text = new VA.Text.Markup.TextElement("HELLO WORLD");
            vrect1.Cells.FillForegnd = "rgb(255,0,0)";
            page_node.Shapes.Add(vrect1);

            // Render it
            var app = this.GetVisioApplication();
            var doc = this.GetNewDoc();

            VisioAutomationTest.SetPageSize(app.ActivePage, new VA.Drawing.Size(10, 10));
            var page = page_node.Render(app.ActiveDocument);

            // Verify
            Assert.IsNotNull(vrect1.VisioShape);
            Assert.AreEqual("HELLO WORLD", vrect1.VisioShape.Text);

            app.ActiveDocument.Close(true);
        }
コード例 #12
0
        public void Page_Duplicate()
        {
            var page1 = GetNewPage(new VA.Drawing.Size(4, 3));
            var s1    = page1.DrawRectangle(1, 1, 3, 3);

            var doc   = page1.Document;
            var pages = doc.Pages;

            var page2 = pages.Add();

            // Activate Page 1 - needed for duplicate to work
            var app           = page1.Application;
            var active_window = app.ActiveWindow;

            active_window.Page = page1;

            VA.Pages.PageHelper.Duplicate(page1, page2);

            Assert.AreEqual(new VA.Drawing.Size(4, 3), VisioAutomationTest.GetPageSize(page2));
            Assert.AreEqual(1, page2.Shapes.Count);

            page2.Delete(0);
            page1.Delete(0);
        }
コード例 #13
0
        public void ShapeSheet_Query_GetResults_SingleShape()
        {
            var doc1  = this.GetNewDoc();
            var page1 = doc1.Pages[1];

            VisioAutomationTest.SetPageSize(page1, this.StandardPageSize);

            // draw a simple shape
            var s1    = page1.DrawRectangle(this.StandardPageSizeRect);
            int s1_id = s1.ID;

            // format it with setformulas
            var fg_cell  = s1.Cells["FillForegnd"];
            var bg_cell  = s1.Cells["FillBkgnd"];
            var pat_cell = s1.Cells["FillPattern"];

            fg_cell.FormulaU  = "RGB(255,0,0)";
            bg_cell.FormulaU  = "RGB(0,0,255)";
            pat_cell.FormulaU = "40";

            // now retrieve the formulas with GetFormulas

            var src_fg     = VA.ShapeSheet.SRCConstants.FillForegnd;
            var src_bg     = VA.ShapeSheet.SRCConstants.FillBkgnd;
            var src_filpat = VA.ShapeSheet.SRCConstants.FillPattern;

            var query         = new VA.ShapeSheet.Query.CellQuery();
            var col_fg        = query.Columns.Add(src_fg, "Foreground");
            var col_bg        = query.Columns.Add(src_bg, "Background");
            var col_filpat    = query.Columns.Add(src_filpat, "FillPattern");
            var sec_char      = query.Sections.Add(IVisio.VisSectionIndices.visSectionCharacter);
            var col_charcase  = sec_char.Columns.Add(VA.ShapeSheet.SRCConstants.CharCase, "Case");
            var col_charcolor = sec_char.Columns.Add(VA.ShapeSheet.SRCConstants.CharColor, "Color");
            var col_chartrans = sec_char.Columns.Add(VA.ShapeSheet.SRCConstants.CharColorTrans, "ColorTrans");

            var shapeids = new[] { s1_id };

            var formulas = query.GetFormulas(page1, shapeids);

            // now verify that the formulas were actually set
            Assert.AreEqual("RGB(255,0,0)", formulas[0][col_fg.Ordinal]);
            Assert.AreEqual("RGB(0,0,255)", formulas[0][col_bg.Ordinal]);
            Assert.AreEqual("40", formulas[0][col_filpat.Ordinal]);

            // now retrieve the results with GetResults as floats
            var float_results = query.GetResults <double>(page1, shapeids);

            Assert.IsNotNull(float_results);
            Assert.AreEqual(40.0, float_results[0][col_filpat.Ordinal]);

            // now retrieve the results with GetResults as ints
            var int_results = query.GetResults <int>(page1, shapeids);

            Assert.AreEqual(40, int_results[0][col_filpat.Ordinal]);

            // now retrieve the results with GetResults as strings

            var string_results = query.GetResults <string>(page1, shapeids);

            Assert.AreEqual("RGB(255, 0, 0)", string_results[0][col_fg.Ordinal]);
            Assert.AreEqual("RGB(0, 0, 255)", string_results[0][col_bg.Ordinal]);
            Assert.AreEqual("40", string_results[0][col_filpat.Ordinal]);

            page1.Delete(0);
            doc1.Close(true);
        }