protected override void ProcessRecord()
        {
            if (this.FitContents)
            {
                var bordersize = new VisioAutomation.Drawing.Size(this.BorderWidth, this.BorderWidth);
                this.client.Page.ResizeToFitContents(bordersize, true);
            }

            if (this.Width > 0 || this.Height > 0)
            {
                var page = this.client.Application.Get().ActivePage;
                var pagecells = VisioAutomation.Pages.PageCells.GetCells(page.PageSheet);

                var newpagecells = new VisioAutomation.Pages.PageCells();

                if (this.Width > 0)
                {
                    newpagecells.PageWidth = this.Width;
                }

                if (this.Height > 0)
                {
                    newpagecells.PageHeight = this.Height;
                }

                var update = new VisioAutomation.ShapeSheet.Update();
                update.SetFormulas(newpagecells);
                update.BlastGuards = true;
                update.Execute(page);
            }
        }
        protected override void ProcessRecord()
        {
            if (this.FitContents)
            {
                var bordersize = new VisioAutomation.Drawing.Size(this.BorderWidth, this.BorderWidth);
                this.Client.Page.ResizeToFitContents(bordersize, true);
            }

            if (this.Width > 0 || this.Height > 0)
            {
                var page      = this.Client.Application.Get().ActivePage;
                var pagecells = VisioAutomation.Pages.PageCells.GetCells(page.PageSheet);

                var newpagecells = new VisioAutomation.Pages.PageCells();

                if (this.Width > 0)
                {
                    newpagecells.PageWidth = this.Width;
                }

                if (this.Height > 0)
                {
                    newpagecells.PageHeight = this.Height;
                }

                var writer = new FormulaWriterSRC();
                newpagecells.SetFormulas(writer);
                writer.BlastGuards = true;
                writer.Commit(page);
            }
        }
示例#3
0
        public static void SnapSize(IVisio.Page page, VisioScripting.Models.TargetShapeIDs target, VisioAutomation.Drawing.Size snapsize, VisioAutomation.Drawing.Size minsize)
        {
            var input_xfrms = VisioScripting.Models.ShapeXFormData.Get(page, target);
            var sizes       = new List <VisioAutomation.Drawing.Size>(input_xfrms.Count);

            var grid = new VisioScripting.Models.SnappingGrid(snapsize);

            foreach (var input_xfrm in input_xfrms)
            {
                // First snap the size to the grid
                double old_w        = input_xfrm.Width;
                double old_h        = input_xfrm.Height;
                var    input_size   = new VisioAutomation.Drawing.Size(old_w, old_h);
                var    snapped_size = grid.Snap(input_size);

                // then account for any minum size requirements
                double new_w = System.Math.Max(snapped_size.Width, minsize.Width);
                double new_h = System.Math.Max(snapped_size.Height, minsize.Height);

                sizes.Add(new VisioAutomation.Drawing.Size(new_w, new_h));
            }

            // Now apply the updates to the sizes
            ModifySizes(page, target.ShapeIDs, sizes);
        }
        public static void NURBS1()
        {
            // Draw a simple NURBS
            // Example from this page:http://www.robthebloke.org/opengl_programming.html

            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            var points = new[]
                             {
                                 new VA.Drawing.Point(10, 10),
                                 new VA.Drawing.Point(5, 10),
                                 new VA.Drawing.Point(-5, 5),
                                 new VA.Drawing.Point(-10, 5),
                                 new VA.Drawing.Point(-4, 10),
                                 new VA.Drawing.Point(-4, 5),
                                 new VA.Drawing.Point(-8, 1)
                             };

            var origin = new VA.Drawing.Point(4, 4);
            var scale = new VA.Drawing.Size(1.0/4.0, 1.0/4.0);

            var controlpoints = points.Select(x => (x*scale) + origin).ToList();
            var knots = new double[] {0, 0, 0, 0, 1, 2, 3, 4, 4, 4, 4};
            var degree = 3;
            var weights = controlpoints.Select(i => 1.0).ToList();

            var s0 = page.DrawNURBS(controlpoints, knots, weights, degree);
            s0.Text = "Generic NURBS shape";
        }
示例#5
0
        private static VisioAutomation.Drawing.Point GetPinPositionForCorner(VisioScripting.Models.ShapeXFormData input_xfrm, VisioAutomation.Drawing.Point new_lower_left, VisioScripting.Models.SnapCornerPosition corner)
        {
            var size   = new VisioAutomation.Drawing.Size(input_xfrm.Width, input_xfrm.Height);
            var locpin = new VisioAutomation.Drawing.Point(input_xfrm.LocPinX, input_xfrm.LocPinY);

            switch (corner)
            {
            case VisioScripting.Models.SnapCornerPosition.LowerLeft:
            {
                return(new_lower_left.Add(locpin.X, locpin.Y));
            }

            case VisioScripting.Models.SnapCornerPosition.UpperRight:
            {
                return(new_lower_left.Subtract(size.Width, size.Height).Add(locpin.X, locpin.Y));
            }

            case VisioScripting.Models.SnapCornerPosition.LowerRight:
            {
                return(new_lower_left.Subtract(size.Width, 0).Add(locpin.X, locpin.Y));
            }

            case VisioScripting.Models.SnapCornerPosition.UpperLeft:
            {
                return(new_lower_left.Subtract(0, size.Height).Add(locpin.X, locpin.Y));
            }

            default:
            {
                throw new System.ArgumentOutOfRangeException(nameof(corner), "Unsupported corner");
            }
            }
        }
        public void Scripting_Connects_Scenario_1()
        {
            var client = this.GetScriptingClient();
            client.Document.New();
            var pagesize = new VA.Drawing.Size(4, 4);
            client.Page.New(pagesize, false);

            var s1 = client.Draw.Rectangle(1, 1, 1.25, 1.5);

            var s2 = client.Draw.Rectangle(2, 3, 2.5, 3.5);

            var s3 = client.Draw.Rectangle(4.5, 2.5, 6, 3.5);

            client.Selection.None();
            client.Selection.Select(s1);
            client.Selection.Select(s2);
            client.Selection.Select(s3);

            client.Document.OpenStencil("basic_u.vss");
            var connec_stencil = client.Document.OpenStencil("connec_u.vss");
            var master = client.Master.Get("Dynamic Connector", connec_stencil);
            var undirected_connectors = client.Connection.Connect(new [] { s1,s2},new [] { s2,s3}, master);

            var directed_edges0 = client.Connection.GetDirectedEdges(VACONNECT.ConnectorEdgeHandling.Arrow_ExcludeConnectorsWithoutArrows);
            Assert.AreEqual(0, directed_edges0.Count);

            var directed_edges1 =
                client.Connection.GetDirectedEdges(VACONNECT.ConnectorEdgeHandling.Arrow_TreatConnectorsWithoutArrowsAsBidirectional);
            Assert.AreEqual(4, directed_edges1.Count);

            var undirected_edges0 = client.Connection.GetDirectedEdges(VACONNECT.ConnectorEdgeHandling.Raw);
            Assert.AreEqual(2, undirected_edges0.Count);

            client.Document.Close(true);
        }
示例#7
0
        public void Scripting_Distribute()
        {
            var client   = this.GetScriptingClient();
            var pagesize = new VA.Drawing.Size(4, 4);

            client.Document.New();
            client.Page.New(pagesize, false);

            var size1 = new VA.Drawing.Size(0.5, 0.5);
            var size2 = new VA.Drawing.Size(1.0, 1.0);
            var size3 = new VA.Drawing.Size(1.5, 1.5);

            var r1 = new VA.Drawing.Rectangle(new VA.Drawing.Point(1, 1), size1);
            var r2 = new VA.Drawing.Rectangle(new VA.Drawing.Point(2, 2), size2);
            var r3 = new VA.Drawing.Rectangle(new VA.Drawing.Point(4, 4), size3);

            var s1 = client.Draw.Rectangle(r1);
            var s2 = client.Draw.Rectangle(r2);
            var s3 = client.Draw.Rectangle(r3);

            client.Selection.SelectNone();
            client.Selection.Select(s1);
            client.Selection.Select(s2);
            client.Selection.Select(s3);

            var targets = new TargetShapes();

            client.Distribute.DistributeHorizontal(targets, AlignmentHorizontal.Center);

            var shapeids = new[] { s1.ID, s2.ID, s3.ID };

            VisioAutomation.Shapes.ShapeXFormCells.GetCells(client.Page.Get(), shapeids);

            client.Document.Close(true);
        }
示例#8
0
        public void Scripting_Draw_Grid()
        {
            var origin   = new VisioAutomation.Drawing.Point(0, 4);
            var pagesize = new VisioAutomation.Drawing.Size(4, 4);
            var cellsize = new VisioAutomation.Drawing.Size(0.5, 0.25);
            int cols     = 3;
            int rows     = 6;

            // Create the Page
            var client = this.GetScriptingClient();

            client.Document.New();
            client.Page.New(pagesize, false);

            // Find the stencil and master
            var stencildoc = client.Document.OpenStencil("basic_u.vss");
            var master     = client.Master.Get("Rectangle", stencildoc);

            // Draw the grid
            var page = client.Page.Get();
            var grid = new GridLayout(cols, rows, cellsize, master);

            grid.Origin = origin;
            grid.Render(page);

            // Verify
            int total_shapes_expected = cols * rows;
            var shapes = page.Shapes.ToEnumerable().ToList();
            int total_shapes_actual = shapes.Count;

            Assert.AreEqual(total_shapes_expected, total_shapes_actual);

            // Cleanup
            client.Document.Close(true);
        }
示例#9
0
        public void Scripting_Test_Export_Selection_SVGHTML()
        {
            var client    = this.GetScriptingClient();
            var page_size = new VisioAutomation.Drawing.Size(10, 5);

            var doc = client.Document.New(page_size);

            var page1 = doc.Pages[1];

            var s1 = page1.DrawRectangle(0, 0, 1, 1);
            var s2 = page1.DrawRectangle(1, 0, 2, 1);
            var s3 = page1.DrawRectangle(0, 1, 1, 2);
            var s4 = page1.DrawRectangle(1, 1, 2, 2);

            client.Selection.SelectAll();

            string output_filename = TestGlobals.TestHelper.GetOutputFilename(nameof(Scripting_Test_Export_Selection_SVGHTML), ".html");

            if (File.Exists(output_filename))
            {
                File.Delete(output_filename);
            }

            client.Export.SelectionToSVGXHTML(output_filename);

            AssertUtil.FileExists(output_filename);
            client.Document.Close(true);
        }
示例#10
0
        public void Page_Query()
        {
            var size           = new VA.Drawing.Size(4, 3);
            var page1          = this.GetNewPage(size);
            var page_fmt_cells = VA.Pages.PageFormatCells.GetCells(page1.PageSheet);

            Assert.AreEqual("4.0000 in.", page_fmt_cells.Width.Result);
            Assert.AreEqual("3.0000 in.", page_fmt_cells.Height.Result);

            // Double each side
            page_fmt_cells.Width  = "8.0";
            page_fmt_cells.Height = "6.0";

            var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();

            page_fmt_cells.SetFormulas(writer);

            writer.Commit(page1.PageSheet);

            var actual_page_format_cells = VA.Pages.PageFormatCells.GetCells(page1.PageSheet);

            Assert.AreEqual("8.0000 in.", actual_page_format_cells.Width.Result);
            Assert.AreEqual("6.0000 in.", actual_page_format_cells.Height.Result);
            page1.Delete(0);
        }
示例#11
0
        private static void SnapSize(IVisio.Page page, IList <int> shapeids, VA.Drawing.Size snapsize, VA.Drawing.Size minsize)
        {
            var input_xfrms  = VA.Shapes.XFormCells.GetCells(page, shapeids);
            var output_xfrms = new List <VA.Shapes.XFormCells>(input_xfrms.Count);

            var grid = new VA.Drawing.SnappingGrid(snapsize);

            foreach (var input_xfrm in input_xfrms)
            {
                var    inut_size    = new VA.Drawing.Size(input_xfrm.Width.Result, input_xfrm.Height.Result);
                var    snapped_size = grid.Snap(inut_size);
                double max_w        = System.Math.Max(snapped_size.Width, minsize.Width);
                double max_h        = System.Math.Max(snapped_size.Height, minsize.Height);
                var    new_size     = new VA.Drawing.Size(max_w, max_h);

                var output_xfrm = new VA.Shapes.XFormCells();
                output_xfrm.Width  = new_size.Width;
                output_xfrm.Height = new_size.Height;

                output_xfrms.Add(output_xfrm);
            }

            // Now apply them
            update_xfrms(page, shapeids, output_xfrms);
        }
示例#12
0
        public void SnapSize(IList <IVisio.Shape> target_shapes, double w, double h)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = GetTargetShapes(target_shapes);

            if (shapes.Count < 1)
            {
                return;
            }

            var shapes_2d = shapes.Where(s => s.OneD == 0).ToList();
            var shapeids  = shapes_2d.Select(s => s.ID).ToList();

            var application = this.Client.VisioApplication;

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Snape Shape Sizes"))
            {
                var active_page = application.ActivePage;
                var snapsize    = new VA.Drawing.Size(w, h);
                var minsize     = new VA.Drawing.Size(w, h);
                SnapSize(active_page, shapeids, snapsize, minsize);
            }
        }
示例#13
0
        public static void FontGlyphComparision2(IVisio.Document doc, string[] fontnames, List <string> samplechars)
        {
            double w  = 2.0;
            double h  = 1;
            double th = 1;

            int chunksize = 12;
            var chunks    = LinqUtil.Split(samplechars, chunksize);

            foreach (var chunk in chunks)
            {
                var domshapescol = new VA.DOM.ShapeList();

                for (int j = 0; j < fontnames.Count(); j++)
                {
                    string fontname = fontnames[j];
                    double x0       = j * w;

                    var r  = new VA.Drawing.Rectangle(x0, 0 - th, x0 + w, 0);
                    var n1 = domshapescol.Drop("Rectangle", "basic_u.vss", r);
                    n1.Text = new VA.Text.Markup.TextElement(fontname.ToUpper());
                    n1.Cells.FillForegnd = "rgb(255,255,255)";
                    n1.Cells.LineWeight  = 0.0;
                    n1.Cells.LinePattern = 0;
                    n1.Cells.CharSize    = "16pt";
                }


                for (int j = 0; j < fontnames.Count(); j++)
                {
                    for (int i = 0; i < chunksize; i++)
                    {
                        double x0 = j * w;
                        double y0 = i * h * -1 - th - h;

                        var r  = new VA.Drawing.Rectangle(x0, y0, x0 + w, y0 + h);
                        var n1 = domshapescol.Drop("Rectangle", "basic_u.vss", r);
                        if (i < chunk.Count)
                        {
                            n1.Text = new VA.Text.Markup.TextElement(chunk[i]);
                        }
                        else
                        {
                            // empty
                        }
                        n1.CharFontName      = fontnames[j];
                        n1.Cells.CharSize    = "36pt";
                        n1.Cells.FillForegnd = "rgb(255,255,255)";
                        n1.Cells.LineWeight  = 0.0;
                        n1.Cells.LinePattern = 0;
                    }
                }

                var page = doc.Pages.Add();
                domshapescol.Render(page);

                var bordersize = new VA.Drawing.Size(0.5, 0.5);
                page.ResizeToFitContents(bordersize);
            }
        }
        public static void NURBS2()
        {
            // Draw a simple NURBS
            // Example from Graham Wideman's book

            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            var points = new[]
            {
                new VA.Drawing.Point(0.2500, 0.2500),
                new VA.Drawing.Point(0.2500, 0.7500),
                new VA.Drawing.Point(0.4063, 0.8125),
                new VA.Drawing.Point(0.5625, 0.3750),
                new VA.Drawing.Point(0.5538, 0.8125),
                new VA.Drawing.Point(0.7600, 0.7500),
                new VA.Drawing.Point(0.7600, 0.2500)
            };

            var origin = new VA.Drawing.Point(4, 4);
            var scale  = new VA.Drawing.Size(4, 4);

            var controlpoints = points.Select(x => (x * scale) + origin).ToList();
            var knots         = new double[] { 0, 0, 0, 0, 25, 50, 75, 100, 100, 100, 100 };
            var degree        = 3;
            var Weights       = controlpoints.Select(i => 1.0).ToList();

            var s0 = page.DrawNURBS(controlpoints, knots, Weights, degree);

            s0.Text = "Generic NURBS shape";
        }
示例#15
0
        private static void TestResize(IVisio.Document doc,
                                       VA.Drawing.Size bottomleft_margin,
                                       VA.Drawing.Size upperright_margin,
                                       VA.Drawing.Size shape_size,
                                       VA.Drawing.Size padding_size,
                                       double expected_pinx,
                                       double expected_piny)
        {
            var page = doc.Pages.Add();

            var pagecells = new VA.Pages.PageCells();

            pagecells.PageTopMargin    = upperright_margin.Height;
            pagecells.PageBottomMargin = bottomleft_margin.Height;
            pagecells.PageLeftMargin   = bottomleft_margin.Width;
            pagecells.PageRightMargin  = upperright_margin.Width;

            var pageupdate = new VA.ShapeSheet.Update();

            pageupdate.SetFormulas(pagecells);
            pageupdate.Execute(page.PageSheet);


            var shape = page.DrawRectangle(5, 5, 5 + shape_size.Width, 5 + shape_size.Height);

            page.ResizeToFitContents(padding_size);
            var xform = VA.Shapes.XFormCells.GetCells(shape);

            AssertVA.AreEqual(expected_pinx, expected_piny, xform.Pin(), 0.1);
            page.Delete(0);
        }
        public void Scripting_Draw_Grid()
        {
            var origin = new VisioAutomation.Drawing.Point(0, 4);
            var pagesize = new VisioAutomation.Drawing.Size(4, 4);
            var cellsize = new VisioAutomation.Drawing.Size(0.5, 0.25);
            int cols = 3;
            int rows = 6;

            // Create the Page
            var client = this.GetScriptingClient();
            client.Document.New();
            client.Page.New(pagesize, false);

            // Find the stencil and master
            var stencildoc = client.Document.OpenStencil("basic_u.vss");
            var master = client.Master.Get("Rectangle", stencildoc);

            // Draw the grid
            var page = client.Page.Get();
            var grid = new VisioAutomation.Models.Grid.GridLayout(cols, rows, cellsize, master);
            grid.Origin = origin;
            grid.Render(page);

            // Verify
            int total_shapes_expected = cols*rows;
            var shapes = page.Shapes.AsEnumerable().ToList();
            int total_shapes_actual = shapes.Count;
            Assert.AreEqual(total_shapes_expected,total_shapes_actual);

            // Cleanup
            client.Document.Close(true);
        }
示例#17
0
        public void Page_Draw_PieSlices()
        {
            var app  = this.GetVisioApplication();
            var doc  = this.GetNewDoc();
            var page = app.ActivePage;

            int    n           = 36;
            double start_angle = 0.0;
            double radius      = 1.0;
            double cx          = 0.0;
            double cy          = 2.0;
            double angle_step  = Math.PI * 2.0 / (n - 1);

            foreach (double end_angle in Enumerable.Range(0, n).Select(i => i * angle_step))
            {
                var center = new VA.Drawing.Point(cx, cy);
                var ps     = new VACHART.PieSlice(center, radius, start_angle, end_angle);
                ps.Render(page);
                cx += 2.5;
            }

            var bordersize = new VA.Drawing.Size(1, 1);

            page.ResizeToFitContents(bordersize);

            doc.Close(true);
        }
示例#18
0
        public void Scripting_Distribute_With_Spacing()
        {
            var client   = this.GetScriptingClient();
            var pagesize = new VA.Drawing.Size(4, 4);

            client.Document.New();
            client.Page.New(pagesize, false);

            var s1 = client.Draw.Rectangle(new VA.Drawing.Rectangle(new VA.Drawing.Point(1, 1), new VA.Drawing.Size(0.5, 0.5)));
            var s2 = client.Draw.Rectangle(new VA.Drawing.Rectangle(new VA.Drawing.Point(2, 2), new VA.Drawing.Size(1.0, 1.0)));
            var s3 = client.Draw.Rectangle(new VA.Drawing.Rectangle(new VA.Drawing.Point(4, 4), new VA.Drawing.Size(1.5, 1.5)));

            client.Selection.SelectNone();
            client.Selection.Select(s1);
            client.Selection.Select(s2);
            client.Selection.Select(s3);

            var targets = new VA.Scripting.TargetShapes();

            client.Distribute.DistributeOnAxis(targets, Axis.XAxis, 0.25);
            client.Distribute.DistributeOnAxis(targets, Axis.YAxis, 1.0);

            var out_xfrms     = VisioAutomation.Shapes.XFormCells.GetCells(client.Page.Get(), new[] { s1.ID, s2.ID, s3.ID });
            var out_positions = out_xfrms.Select(xfrm => TestExtensions.ToPoint(xfrm.PinX.Result, xfrm.PinY.Result)).ToArray();

            Assert.AreEqual(1.25, out_positions[0].X);
            Assert.AreEqual(1.25, out_positions[0].Y);
            Assert.AreEqual(2.25, out_positions[1].X);
            Assert.AreEqual(3.00, out_positions[1].Y);
            Assert.AreEqual(3.75, out_positions[2].X);
            Assert.AreEqual(5.25, out_positions[2].Y);
            client.Document.Close(true);
        }
示例#19
0
        public Node <T> AddNewChild(VA.Drawing.Size size)
        {
            var new_child = new Node <T>(node_seq_num++, null, size);

            this.add_child(new_child);
            return(new_child);
        }
示例#20
0
        protected override void ProcessRecord()
        {
            if (this.FitContents)
            {
                var bordersize = new VisioAutomation.Drawing.Size(this.BorderWidth, this.BorderWidth);
                this.Client.Page.ResizeToFitContents(bordersize, true);
            }

            if (this.Width > 0 || this.Height > 0)
            {
                var page      = this.Client.Application.Get().ActivePage;
                var pagecells = VisioAutomation.Pages.PageCells.GetCells(page.PageSheet);

                var newpagecells = new VisioAutomation.Pages.PageCells();

                if (this.Width > 0)
                {
                    newpagecells.PageWidth = this.Width;
                }

                if (this.Height > 0)
                {
                    newpagecells.PageHeight = this.Height;
                }

                var update = new VisioAutomation.ShapeSheet.Update();
                update.SetFormulas(newpagecells);
                update.BlastGuards = true;
                update.Execute(page);
            }
        }
示例#21
0
        public void Scripting_Draw_PieChart()
        {
            var    pagesize = new VA.Drawing.Size(4, 4);
            var    center   = new VA.Drawing.Point(2, 2);
            double radius   = 1.0;

            var chart = new VisioAutomation.Models.Charting.PieChart(center, radius);

            chart.DataPoints.Add(1.0);
            chart.DataPoints.Add(2.0);
            chart.DataPoints.Add(3.0);
            chart.DataPoints.Add(4.0);

            // Create the Page
            var client = this.GetScriptingClient();

            client.Document.New();
            client.Page.New(pagesize, false);

            // Draw the chart

            client.Draw.PieChart(chart);

            // Cleanup
            client.Document.Close(true);
        }
示例#22
0
        public void Scripting_Drop_Master()
        {
            var pagesize = new VA.Drawing.Size(4, 4);
            var client   = this.GetScriptingClient();

            // Create the page
            client.Document.New();
            client.Page.New(pagesize, false);

            // Load the stencils and find the masters
            var basic_stencil = client.Document.OpenStencil("Basic_U.VSS");
            var master        = client.Master.Get("Rectangle", basic_stencil);

            // Frop the Shapes
            client.Master.Drop(master, new VA.Drawing.Point(2, 2));

            // Verify
            var application = client.Application.Get();
            var active_page = application.ActivePage;
            var shapes      = active_page.Shapes;

            Assert.AreEqual(1, shapes.Count);

            // cleanup
            client.Document.Close(true);
        }
示例#23
0
        public void Scripting_Drop_Many()
        {
            var pagesize = new VA.Drawing.Size(10, 10);
            var client   = this.GetScriptingClient();

            // Create the Page
            client.Document.New();
            client.Page.New(pagesize, false);

            // Load the stencils and find the masters
            var basic_stencil = client.Document.OpenStencil("Basic_U.VSS");
            var m1            = client.Master.Get("Rectangle", basic_stencil);
            var m2            = client.Master.Get("Ellipse", basic_stencil);

            // Drop the Shapes
            var masters = new[] { m1, m2 };
            var xys     = new[] { 1.0, 2.0, 3.0, 4.0, 1.5, 4.5, 5.7, 2.4 };
            var points  = VA.Drawing.Point.FromDoubles(xys).ToList();

            client.Master.Drop(masters, points);

            // Verify
            var application = client.Application.Get();

            Assert.AreEqual(4, application.ActivePage.Shapes.Count);

            // Cleanup
            client.Document.Close(true);
        }
        public void Page_Draw_PieSlices()
        {
            var app = this.GetVisioApplication();
            var doc = this.GetNewDoc();
            var page = app.ActivePage;

            int n = 36;
            double start_angle = 0.0;
            double radius = 1.0;
            double cx = 0.0;
            double cy = 2.0;
            double angle_step = System.Math.PI * 2.0 / (n - 1);

            foreach (double end_angle in Enumerable.Range(0, n).Select(i => i * angle_step))
            {
                var center = new VA.Drawing.Point(cx, cy);
                var ps = new VA.Models.Charting.PieSlice(center, radius, start_angle, end_angle);
                ps.Render(page);
                cx += 2.5;
            }

            var bordersize = new VA.Drawing.Size(1, 1);
            page.ResizeToFitContents(bordersize);

            doc.Close(true);
        }
        public static void NURBS1()
        {
            // Draw a simple NURBS
            // Example from this page:http://www.robthebloke.org/opengl_programming.html

            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            var points = new[]
            {
                new VA.Drawing.Point(10, 10),
                new VA.Drawing.Point(5, 10),
                new VA.Drawing.Point(-5, 5),
                new VA.Drawing.Point(-10, 5),
                new VA.Drawing.Point(-4, 10),
                new VA.Drawing.Point(-4, 5),
                new VA.Drawing.Point(-8, 1)
            };

            var origin = new VA.Drawing.Point(4, 4);
            var scale  = new VA.Drawing.Size(1.0 / 4.0, 1.0 / 4.0);

            var controlpoints = points.Select(x => (x * scale) + origin).ToList();
            var knots         = new double[] { 0, 0, 0, 0, 1, 2, 3, 4, 4, 4, 4 };
            var degree        = 3;
            var weights       = controlpoints.Select(i => 1.0).ToList();

            var s0 = page.DrawNURBS(controlpoints, knots, weights, degree);

            s0.Text = "Generic NURBS shape";
        }
示例#26
0
        public static BezierCurve FromEllipse(VA.Drawing.Point center, VA.Drawing.Size radius)
        {
            var pt1 = new VA.Drawing.Point(0, radius.Height);  // top
            var pt2 = new VA.Drawing.Point(radius.Width, 0);   // right
            var pt3 = new VA.Drawing.Point(0, -radius.Height); // bottom
            var pt4 = new VA.Drawing.Point(-radius.Width, 0);  // left

            double dx = radius.Width * 4.0 * (System.Math.Sqrt(2) - 1) / 3;
            double dy = radius.Height * 4.0 * (System.Math.Sqrt(2) - 1) / 3;

            var curve_ControlPoints = new []
            {
                pt1,
                pt1.Add(dx, 0),
                pt2.Add(0, dy),
                pt2,
                pt2.Add(0, -dy),
                pt3.Add(dx, 0),
                pt3,
                pt3.Add(-dx, 0),
                pt4.Add(0, -dy),
                pt4,
                pt4.Add(0, dy),
                pt1.Add(-dx, 0),
                pt1
            }
            .Select(p => p + center).ToArray();
            var curve_Degree = 3;

            var curve = new BezierCurve(curve_ControlPoints, curve_Degree);

            return(curve);
        }
示例#27
0
        private static void VerifyPageSizeToFit(IVisio.Document doc,
                                                VA.Drawing.Size bottomleft_margin,
                                                VA.Drawing.Size upperright_margin,
                                                VA.Drawing.Size shape_size,
                                                VA.Drawing.Size padding_size,
                                                double expected_pinx,
                                                double expected_piny)
        {
            var page = doc.Pages.Add();

            var pagecells = new VA.Pages.PagePrintCells();

            pagecells.TopMargin    = upperright_margin.Height;
            pagecells.BottomMargin = bottomleft_margin.Height;
            pagecells.LeftMargin   = bottomleft_margin.Width;
            pagecells.RightMargin  = upperright_margin.Width;

            var page_writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();

            pagecells.SetFormulas(page_writer);

            page_writer.Commit(page.PageSheet);


            var shape = page.DrawRectangle(5, 5, 5 + shape_size.Width, 5 + shape_size.Height);

            page.ResizeToFitContents(padding_size);
            var xform  = VA.Shapes.ShapeXFormCells.GetCells(shape);
            var pinpos = xform.GetPinPosResult();

            Assert.AreEqual(expected_pinx, pinpos.X, 0.1);
            Assert.AreEqual(expected_piny, pinpos.Y, 0.1);
            page.Delete(0);
        }
示例#28
0
        public void Page_Orientation()
        {
            var size = new VA.Drawing.Size(4, 3);

            var page1 = this.GetNewPage(size);

            var client = this.GetScriptingClient();

            var orientation_1 = client.Page.GetOrientation();

            Assert.AreEqual(VisioScripting.Models.PageOrientation.Portrait, orientation_1);

            var size1 = client.Page.GetSize();

            Assert.AreEqual(size, size1);

            client.Page.SetOrientation(VisioScripting.Models.PageOrientation.Landscape);

            var orientation_2 = client.Page.GetOrientation();

            Assert.AreEqual(VisioScripting.Models.PageOrientation.Landscape, orientation_2);

            var actual_final_size   = client.Page.GetSize();
            var expected_final_size = new VA.Drawing.Size(3, 4);

            Assert.AreEqual(expected_final_size, actual_final_size);

            page1.Delete(0);
        }
示例#29
0
        private static VA.Drawing.Point GetPinPositionForCorner(VA.Shapes.XFormCells input_xfrm, VA.Drawing.Point new_lower_left, VA.Arrange.SnapCornerPosition corner)
        {
            var size   = new VA.Drawing.Size(input_xfrm.Width.Result, input_xfrm.Height.Result);
            var locpin = new VA.Drawing.Point(input_xfrm.LocPinX.Result, input_xfrm.LocPinY.Result);

            switch (corner)
            {
            case VA.Arrange.SnapCornerPosition.LowerLeft:
            {
                return(new_lower_left.Add(locpin.X, locpin.Y));
            }

            case VA.Arrange.SnapCornerPosition.UpperRight:
            {
                return(new_lower_left.Subtract(size.Width, size.Height).Add(locpin.X, locpin.Y));
            }

            case VA.Arrange.SnapCornerPosition.LowerRight:
            {
                return(new_lower_left.Subtract(size.Width, 0).Add(locpin.X, locpin.Y));
            }

            case VA.Arrange.SnapCornerPosition.UpperLeft:
            {
                return(new_lower_left.Subtract(0, size.Height).Add(locpin.X, locpin.Y));
            }

            default:
            {
                throw new System.ArgumentOutOfRangeException("corner", "Unsupported corner");
            }
            }
        }
示例#30
0
        public void Page_Duplicate()
        {
            var page_size = new VA.Drawing.Size(4, 3);
            var page1     = this.GetNewPage(page_size);
            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(page_size, VisioAutomationTest.GetPageSize(page2));
            Assert.AreEqual(1, page2.Shapes.Count);

            page2.Delete(0);
            page1.Delete(0);
        }
示例#31
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);
        }
示例#32
0
        public VA.Drawing.Size Snap(VA.Drawing.Size size)
        {
            double x;
            double y;

            this.SnapXY(size.Width, size.Height, out x, out y);
            return(new VA.Drawing.Size(x, y));
        }
示例#33
0
        public IVisio.Document New(VisioAutomation.Drawing.Size size, string template)
        {
            this._client.Application.AssertApplicationAvailable();
            var doc = this.New(template);

            this._client.Page.SetSize(size);
            return(doc);
        }
示例#34
0
        private static VA.Drawing.Rectangle GetRectangle(VA.Shapes.XFormCells xFormCells)
        {
            var pin    = new VA.Drawing.Point(xFormCells.PinX.Result, xFormCells.PinY.Result);
            var locpin = new VA.Drawing.Point(xFormCells.LocPinX.Result, xFormCells.LocPinY.Result);
            var size   = new VA.Drawing.Size(xFormCells.Width.Result, xFormCells.Height.Result);

            return(new VA.Drawing.Rectangle(pin - locpin, size));
        }
示例#35
0
 public TextBlock(VA.Drawing.Size size, string text)
 {
     this.Text = text;
     this.Size = size;
     this.Textcells = new VA.Text.TextCells();
     this.ParagraphCells = new VA.Text.ParagraphCells();
     this.FormatCells = new VA.Shapes.FormatCells();
     this.CharacterCells = new VA.Text.CharacterCells();
 }
        public static void ColorGrid()
        {
            // Draws a grid rectangles and then formats the shapes
            // with different colors

            // Demonstrates:
            // How use the GridLayout object to quickly drop a grid
            // How to use ShapeFormatCells to apply formatting to shapes
            // How UpdateBase can be used to modfiy multiple shapes at once

            int[] colors = {
                    0x0A3B76, 0x4395D1, 0x99D9EA, 0x0D686B, 0x00A99D, 0x7ACCC8, 0x82CA9C,
                    0x74A402,
                    0xC4DF9B, 0xD9D56F, 0xFFF468, 0xFFF799, 0xFFC20E, 0xEB6119, 0xFBAF5D,
                    0xE57300, 0xC14000, 0xB82832, 0xD85171, 0xFEDFEC, 0x563F7F, 0xA186BE,
                    0xD9CFE5
                };

            const int num_cols = 5;
            const int num_rows = 5;

            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            var page_size = new VA.Drawing.Size(10, 10);
            SampleEnvironment.SetPageSize(page,page_size);

            var stencil = SampleEnvironment.Application.Documents.OpenStencil("basic_u.vss");
            var master = stencil.Masters["Rectangle"];

            var layout = new VA.Models.Grid.GridLayout(num_cols, num_rows, new VA.Drawing.Size(1, 1), master);
            layout.Origin = new VA.Drawing.Point(0, 0);
            layout.CellSpacing = new VA.Drawing.Size(0, 0);
            layout.RowDirection = VA.Models.Grid.RowDirection.BottomToTop;

            layout.PerformLayout();
            layout.Render(page);

            var fmtcells = new VA.Shapes.FormatCells();
            int i = 0;
            var update = new VA.ShapeSheet.Update();
            foreach (var node in layout.Nodes)
            {
                var shapeid = node.ShapeID;
                int color_index = i%colors.Length;
                var color = colors[color_index];
                fmtcells.FillForegnd = new VA.Drawing.ColorRGB(color).ToFormula();
                fmtcells.LinePattern = 0;
                fmtcells.LineWeight = 0;
                update.SetFormulas(shapeid, fmtcells);
                i++;
            }

            update.Execute(page);

            var bordersize = new VA.Drawing.Size(1,1);
            page.ResizeToFitContents(bordersize);
        }
示例#37
0
 public FormPage()
 {
     this.Size = new VA.Drawing.Size(8.5, 11);
     this.Margin = new VA.Drawing.Margin(0.5, 0.5, 0.5, 0.5);
     DefaultFont = "Segoe UI";
     BodyTextSize = 8.0;
     BodyParaSpacingAfter = 0.0;
     TitleTextSize = 15.0;
 }
 public void Scripting_Page_Duplication()
 {
     var page_size = new VA.Drawing.Size(8.5, 11);
     var client = GetScriptingClient();
     var doc = client.Document.New(page_size.Width, page_size.Height);
     client.Draw.Rectangle(0, 0, 1, 1);
     client.Page.Duplicate();
     doc.Close(true);
 }
 protected override void ProcessRecord()
 {
     var cellsize = new VA.Drawing.Size(CellWidth, CellHeight);
     var layout = new GRID.GridLayout(this.Columns, this.Rows, cellsize, this.Master);
     layout.CellSpacing = new VA.Drawing.Size(this.CellHorizontalSpacing, this.CellVerticalSpacing);
     layout.RowDirection = this.RowDirection;
     layout.ColumnDirection = this.ColumnDirection;
     this.WriteObject(layout);
 }
示例#40
0
 public TextBlock(VA.Drawing.Size size, string text)
 {
     this.Text           = text;
     this.Size           = size;
     this.Textcells      = new VA.Text.TextCells();
     this.ParagraphCells = new VA.Text.ParagraphCells();
     this.FormatCells    = new VA.Shapes.FormatCells();
     this.CharacterCells = new VA.Text.CharacterCells();
 }
        public VA.Drawing.Point TopAdjustment; // How to adjust the apex

        #endregion Fields

        #region Constructors

        public TreeLayoutOptions()
        {
            SubtreeSeparation = 1;
            SiblingSeparation = 1;
            Direction = LayoutDirection.Up;
            Alignment = VA.Drawing.AlignmentVertical.Top;
            MaximumDepth = 100;
            LevelSeparation = 1;
            DefaultNodeSize = new VA.Drawing.Size(1, 1);
        }
        public static void DirectedGraphViaVisio()
        {
            var page1 = SampleEnvironment.Application.ActiveDocument.Pages.Add();
            var directed_graph_drawing = DirectGraphLayoutSamples.get_dg_drawing();

            var visio_options = new DGMODEL.VisioLayoutOptions();
            directed_graph_drawing.Render(page1, visio_options);

            var padding = new VA.Drawing.Size(0.5, 0.5);
            page1.ResizeToFitContents(padding);
        }
        public void Draw(Session session)
        {
            var normalized_values = this.DataPoints.GetNormalizedValues();
            var heights = DOMUtil.ConstructPositions(this.DataPoints.Count(), CellHeight, this.VerticalSeparation);
            var widths = DOMUtil.ConstructPositions(new[] { this.CategoryLabelHeight, this.CellWidth }, this.HorizontalSeparation);
            var grid = new GridLayout(widths, heights);

            int catcol = 0;
            int barcol = 2;

            var content_rects = this.SkipOdd(grid.GetRectsInCol(barcol)).ToList();

            var domshapescol = new VA.DOM.ShapeList();

            var bar_rects = new List<VA.Drawing.Rectangle>(content_rects.Count);
            for (int i = 0; i < content_rects.Count; i++)
            {
                var r = content_rects[i];
                domshapescol.DrawRectangle(r);
                var size = new VA.Drawing.Size(normalized_values[i] * r.Width, this.CellHeight);
                var bar_rect = new VA.Drawing.Rectangle(r.LowerLeft, size);
                bar_rects.Add(bar_rect);
            }

            var cat_rects = this.SkipOdd(grid.GetRectsInCol(catcol)).ToList();

            var bar_shapes = DOMUtil.DrawRects(domshapescol, bar_rects, session.MasterRectangle);
            var cat_shapes = DOMUtil.DrawRects(domshapescol, cat_rects, session.MasterRectangle);

            for (int i = 0; i < this.DataPoints.Count; i++)
            {
                bar_shapes[i].Text = new VA.Text.Markup.TextElement(this.DataPoints[i].Text);
                cat_shapes[i].Text = new VA.Text.Markup.TextElement(this.CategoryLabels[i]);
            }

            foreach (var shape in bar_shapes)
            {
                var cells = shape.Cells;

                cells.FillForegnd = this.ValueFillColor;
                cells.LineColor = this.LineLightBorder;

            }

            foreach (var shape in cat_shapes)
            {
                var cells = shape.Cells;

                cells.FillPattern = this.CategoryFillPattern;
                cells.LineWeight = this.CategoryLineWeight;
                cells.LinePattern = this.CategoryLinePattern;
            }
            domshapescol.Render(session.Page);
        }
        public static VisioAutomation.Drawing.Size GetSize(IVisio.Shape shape)
        {
            var query = new VisioAutomation.ShapeSheet.Query.CellQuery();
            var col_w = query.AddCell(VisioAutomation.ShapeSheet.SRCConstants.Width,"Width");
            var col_h = query.AddCell(VisioAutomation.ShapeSheet.SRCConstants.Height,"Height");

            var table = query.GetResults<double>(shape);
            double w = table[col_w];
            double h = table[col_h];
            var size = new VisioAutomation.Drawing.Size(w, h);
            return size;
        }
        public static VA.Drawing.Size GetSize(IVisio.Shape shape)
        {
            var query = new VA.ShapeSheet.Query.CellQuery();
            var col_w = query.Columns.Add(VA.ShapeSheet.SRCConstants.Width,"Width");
            var col_h = query.Columns.Add(VA.ShapeSheet.SRCConstants.Height,"Height");

            var table = query.GetResults<double>(shape);
            double w = table[col_w.Ordinal];
            double h = table[col_h.Ordinal];
            var size = new VA.Drawing.Size(w, h);
            return size;
        }
        public static void GradientTransparencies()
        {
            int num_cols = 1;
            int num_rows = 10;
            var color1 = new VA.Drawing.ColorRGB(0xff000);
            var color2 = new VA.Drawing.ColorRGB(0x000ff);

            var page_size = new VA.Drawing.Size(num_rows/2.0, num_rows);
            var upperleft = new VA.Drawing.Point(0, page_size.Height);

            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();
            var app = page.Application;
            var docs = app.Documents;
            var stencil = docs.OpenStencil("basic_U.vss");
            var master = stencil.Masters["Rectangle"];

            SampleEnvironment.SetPageSize(page,page_size);

            var layout = new GRIDMODEL.GridLayout(num_cols, num_rows, new VA.Drawing.Size(6.0, 1.0), master);
            layout.RowDirection = GRIDMODEL.RowDirection.TopToBottom;
            layout.Origin = upperleft;
            layout.CellSpacing = new VA.Drawing.Size(0.1, 0.1);
            layout.PerformLayout();

            double[] trans = RangeSteps(0.0, 1.0, num_rows).ToArray();

            int i = 0;
            foreach (var node in layout.Nodes)
            {
                double transparency = trans[i];

                var fmt = new VA.DOM.ShapeCells();
                node.Cells = fmt;

                fmt.FillPattern = 25; // Linear pattern left to right
                fmt.FillForegnd = color1.ToFormula();
                fmt.FillBkgnd = color2.ToFormula();
                fmt.FillForegndTrans = 0;
                fmt.FillBkgndTrans = transparency;
                fmt.LinePattern = 0;

                node.Text = string.Format("bg trans = {0}%", transparency);
                i++;
            }

            layout.Render(page);

            page.ResizeToFitContents();
        }
        public static VA.Drawing.Size GetPageSize(IVisio.Page page)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException("page");
            }

            var query = new VA.ShapeSheet.Query.CellQuery();
            var col_height = query.AddCell(VA.ShapeSheet.SRCConstants.PageHeight,"PageHeight");
            var col_width = query.AddCell(VA.ShapeSheet.SRCConstants.PageWidth, "PageWidth");
            var results = query.GetResults<double>(page.PageSheet);
            double height = results[col_height];
            double width = results[col_width];
            var s = new VA.Drawing.Size(width, height);
            return s;
        }
        protected override void ProcessRecord()
        {
            if (this.OrgChart != null)
            {
                this.client.Draw.OrgChart(this.OrgChart);
            }
            else if (this.GridLayout != null)
            {
                this.client.Draw.Grid(this.GridLayout);
            }
            else if (this.DirectedGraphs != null)
            {
                this.client.Draw.DirectedGraph(this.DirectedGraphs);
            }
            else if (this.DataTable != null)
            {
                var widths = Enumerable.Repeat<double>(this.CellWidth, this.DataTable.Columns.Count).ToList();
                var heights = Enumerable.Repeat<double>(this.CellHeight, this.DataTable.Rows.Count).ToList();
                var spacing = new VisioAutomation.Drawing.Size(this.CellSpacing, this.CellSpacing);
                var shapes = this.client.Draw.Table(this.DataTable, widths, heights, spacing);
                this.WriteObject(shapes);
            }
            else if (this.PieChart != null)
            {
                this.client.Draw.PieChart(this.PieChart);
            }
            else if (this.BarChart != null)
            {
                this.client.Draw.BarChart(this.BarChart);
            }
            else if (this.AreaChart != null)
            {
                this.client.Draw.AreaChart(this.AreaChart);
            }
            else if (this.XmlDocument != null)
            {
                this.WriteVerbose("XmlDocument");
                var tree_drawing = new VisioAutomation.Models.Tree.Drawing();
                this.build_from_xml_doc(this.XmlDocument, tree_drawing);

                tree_drawing.Render(this.client.Page.Get());
            }
            else
            {
                this.WriteVerbose("No object to draw");
            }
        }
 public void Page_ResizeBorder()
 {
     var doc = this.GetNewDoc();
     var shapesize = new VA.Drawing.Size(1, 2);
     var border1 = new VA.Drawing.Size(0, 0);
     var border2 = new VA.Drawing.Size(3, 4);
     TestResize(doc, new VA.Drawing.Size(1, 1), new VA.Drawing.Size(1, 1), shapesize, border1, 1.5, 2);
     TestResize(doc, new VA.Drawing.Size(0, 0), new VA.Drawing.Size(0, 0), shapesize, border1, 0.5, 1);
     TestResize(doc, new VA.Drawing.Size(1, 0), new VA.Drawing.Size(0, 0), shapesize, border1, 1.5, 1);
     TestResize(doc, new VA.Drawing.Size(0, 1), new VA.Drawing.Size(0, 0), shapesize, border1, 0.5, 2);
     TestResize(doc, new VA.Drawing.Size(0, 0), new VA.Drawing.Size(1, 0), shapesize, border1, 0.5, 1);
     TestResize(doc, new VA.Drawing.Size(0, 0), new VA.Drawing.Size(0, 1), shapesize, border1, 0.5, 1);
     TestResize(doc, new VA.Drawing.Size(1, 1), new VA.Drawing.Size(1, 1), shapesize, border2, 4.5, 6);
     TestResize(doc, new VA.Drawing.Size(1, 0), new VA.Drawing.Size(0, 0), shapesize, border2, 4, 5);
     TestResize(doc, new VA.Drawing.Size(0, 1), new VA.Drawing.Size(0, 0), shapesize, border2, 3.5, 5.5);
     TestResize(doc, new VA.Drawing.Size(0, 0), new VA.Drawing.Size(1, 0), shapesize, border2, 4, 5);
     TestResize(doc, new VA.Drawing.Size(0, 0), new VA.Drawing.Size(0, 1), shapesize, border2, 3.5, 5.5);
     doc.Close(true);
 }
        public static void OrgChart()
        {
            // This creates a new document
            var orgchart = new OCMODEL.OrgChartDocument();

            var bob = new OCMODEL.Node("Bob");
            var ted = new OCMODEL.Node("Ted");
            var alice = new OCMODEL.Node("Alice");

            bob.Children.Add(ted);
            bob.Children.Add(alice);

            orgchart.OrgCharts.Add(bob);

            orgchart.Render(SampleEnvironment.Application);

            var bordersize = new VA.Drawing.Size(1,1);
            SampleEnvironment.Application.ActivePage.ResizeToFitContents(bordersize);
        }
        public void Scripting_Connects_Scenario_0()
        {
            var client = this.GetScriptingClient();
            client.Document.New();
            var pagesize = new VA.Drawing.Size(4, 4);
            client.Page.New(pagesize, false);

            var s1 = client.Draw.Rectangle(1, 1, 1.25, 1.5);

            var s2 = client.Draw.Rectangle(2, 3, 2.5, 3.5);

            var s3 = client.Draw.Rectangle(4.5, 2.5, 6, 3.5);

            client.Selection.None();
            client.Selection.Select(s1);
            client.Selection.Select(s2);
            client.Selection.Select(s3);

            client.Document.OpenStencil("basic_u.vss");
            var connec_stencil = client.Document.OpenStencil("connec_u.vss");
            var master = client.Master.Get("Dynamic Connector", connec_stencil);
            var fromshapes = new [] { s1,s2};
            var toshapes = new [] { s2,s3};
            var directed_connectors = client.Connection.Connect(fromshapes,toshapes, master);
            client.Selection.None();
            client.Selection.Select(directed_connectors);

            IVisio.VisGetSetArgs flags = 0;
            client.ShapeSheet.SetFormula(null,new[] { VA.ShapeSheet.SRCConstants.EndArrow }, new [] {"13"}, flags);

            var undirected_edges0 = client.Connection.GetDirectedEdges(VACONNECT.ConnectorEdgeHandling.Raw);
            Assert.AreEqual(2, undirected_edges0.Count);

            var directed_edges0 = client.Connection.GetDirectedEdges(VACONNECT.ConnectorEdgeHandling.Arrow_ExcludeConnectorsWithoutArrows);
            Assert.AreEqual(2, directed_edges0.Count);

            var directed_edges1 = client.Connection.GetDirectedEdges(VACONNECT.ConnectorEdgeHandling.Arrow_TreatConnectorsWithoutArrowsAsBidirectional);
            Assert.AreEqual(2, directed_edges1.Count);

            client.Document.Close(true);
        }
        public void Scripting_Draw_DataTable()
        {
            var pagesize = new VisioAutomation.Drawing.Size(4, 4);
            var widths = new[] { 2.0, 1.5, 1.0 };
            double default_height = 0.25;
            var cellspacing = new VisioAutomation.Drawing.Size(0, 0);

            var items = new[]
                {
                    new {Name = "X", Age = 28, Score = 16},
                    new {Name = "Y", Age = 32, Score = 23},
                    new {Name = "Z", Age = 45, Score = 12},
                    new {Name = "U", Age = 48, Score = 10}
                };

            var dt = new DataTable();
            dt.Columns.Add("X", typeof(string));
            dt.Columns.Add("Age", typeof(int));
            dt.Columns.Add("Score", typeof(int));

            foreach (var item in items)
            {
                dt.Rows.Add(item.Name, item.Age, item.Score);
            }

            // Prepare the Page
            var client = this.GetScriptingClient();
            client.Document.New();
            client.Page.New(pagesize, false);

            // Draw the table
            var heights = Enumerable.Repeat(default_height, items.Length).ToList();
            var shapes = client.Draw.Table(dt, widths, heights, cellspacing);

            // Verify
            int num_shapes_expected = items.Length*dt.Columns.Count;
            Assert.AreEqual(num_shapes_expected, shapes.Count);

            // Cleanup
            client.Document.Close(true);
        }
        public void Scripting_Draw_BarChart()
        {
            var pagesize = new VA.Drawing.Size(4, 4);
            var rect1 = new VA.Drawing.Rectangle(0, 0, 4, 4);
            var rect2 = new VA.Drawing.Rectangle(5, 0, 9, 4);
            var rect3 = new VA.Drawing.Rectangle(10, 0, 14, 4);
            var bordersize = new VA.Drawing.Size(1.0, 1.0);

            var chart1 = new VisioAutomation.Models.Charting.BarChart(rect1);
            chart1.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(1.0));
            chart1.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(2.0));
            chart1.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(3.0));
            chart1.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(4.0));

            var chart2 = new VisioAutomation.Models.Charting.BarChart(rect2);
            chart2.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(1.0));
            chart2.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(2.0));
            chart2.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(-3.0));
            chart2.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(4.0));

            var chart3 = new VisioAutomation.Models.Charting.BarChart(rect3);
            chart3.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(-1.0));
            chart3.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(-2.0));
            chart3.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(-3.0));
            chart3.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(-4.0));

            // Create the page
            var client = this.GetScriptingClient();
            client.Document.New();
            client.Page.New(pagesize, false);

            // Draw the Charts
            client.Draw.BarChart(chart1);
            client.Draw.BarChart(chart2);
            client.Draw.BarChart(chart3);
            client.Page.ResizeToFitContents(bordersize,true);

            // Cleanup
            client.Document.Close(true);
        }
示例#54
0
        public GridLayout(int cols, int rows, VA.Drawing.Size cellsize, IVisio.Master master)
        {
            ColumnDirection = ColumnDirection.LeftToRight;
            RowDirection = RowDirection.BottomToTop;
            CellSpacing = new VA.Drawing.Size(0.5, 0.25);
            this.ColumnCount = cols;
            this.RowCount = rows;

            // initialize the sizes for the rows and columns
            this.Rows = new List<Row>(this.RowCount);
            foreach (int row in Enumerable.Range(0, this.RowCount))
            {
                var r = new Row();
                r.Height = cellsize.Height;
                this.Rows.Add(r);
            }

            this.Columns = new List<Column>(this.ColumnCount);
            foreach (int col in Enumerable.Range(0, this.ColumnCount))
            {
                var c = new Column();
                c.Width = cellsize.Width;
                this.Columns.Add(c);
            }

            // Create the nodes
            this._nodes = new Node[this.RowCount, this.ColumnCount];
            foreach (int row in Enumerable.Range(0, this.RowCount))
            {
                foreach (int col in Enumerable.Range(0, this.ColumnCount))
                {
                    var node = new Node();
                    node.Column = col;
                    node.Row = row;
                    node.Master = master;
                    node.Draw = true;
                    this._nodes[row, col] = node;
                }
            }
        }
        public void Scripting_Draw_AreaChart()
        {
            var pagesize = new VA.Drawing.Size(4, 4);
            var rect1 = new VA.Drawing.Rectangle(0, 0, 4, 4);
            var rect2 = new VA.Drawing.Rectangle(5, 0, 9, 4);
            var rect3 = new VA.Drawing.Rectangle(10, 0, 14, 4);
            var padding = new VA.Drawing.Size(1.0, 1.0);

            var chart1 = new VisioAutomation.Models.Charting.AreaChart(rect1);
            chart1.DataPoints.Add(1.0);
            chart1.DataPoints.Add(2.0);
            chart1.DataPoints.Add(3.0);
            chart1.DataPoints.Add(4.0);

            var chart2 = new VisioAutomation.Models.Charting.AreaChart(rect2);
            chart2.DataPoints.Add(1.0);
            chart2.DataPoints.Add(2.0);
            chart2.DataPoints.Add(-3.0);
            chart2.DataPoints.Add(4.0);

            var chart3 = new VisioAutomation.Models.Charting.AreaChart(rect3);
            chart3.DataPoints.Add(-1.0);
            chart3.DataPoints.Add(-2.0);
            chart3.DataPoints.Add(-3.0);
            chart3.DataPoints.Add(-4.0);

            // Setup the Page
            var client = this.GetScriptingClient();
            client.Document.New();
            client.Page.New(pagesize, false);

            // Draw the Charts
            client.Draw.AreaChart(chart1);
            client.Draw.AreaChart(chart2);
            client.Draw.AreaChart(chart3);
            client.Page.Get().ResizeToFitContents(padding);

            // Cleanup
            client.Document.Close(true);
        }
        public static void DrawGridOfMasters()
        {
            // http://blogs.msdn.com/saveenr/archive/2008/08/06/visioautoext-simplifying-dropmany-to-quickly-draw-a-grid.aspx

            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            // Resize the page to a sqaure
            var page_size = new VA.Drawing.Size(4, 4);
            SampleEnvironment.SetPageSize(page,page_size);

            // Load the Stencil
            var application = page.Application;
            var documents = application.Documents;
            var stencil = documents.OpenStencil("basic_u.vss");
            var stencil_masters = stencil.Masters;
            var master = stencil_masters["Rectangle"];

            // Calculate where to drop the masters
            int num_cols = 10;
            int num_rows = 10;

            var centerpoints = new List<VA.Drawing.Point>(num_rows*num_cols);
            foreach (var row in Enumerable.Range(0, num_rows))
            {
                foreach (var col in Enumerable.Range(0, num_cols))
                {
                    var p = new VA.Drawing.Point(row*1.0, col*1.0);
                    centerpoints.Add(p);
                }
            }

            var masters = new[] {master};

            // Draw the masters
            var shapeids = page.DropManyU(masters, centerpoints);

            var bordersize = new VA.Drawing.Size(1,1);
            page.ResizeToFitContents(bordersize);
        }
        public void DOM_DrawSimpleShape()
        {
            // Create the doc
            var page_node = new VA.DOM.Page();
            var vrect1 = new VisioAutomation.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();
            this.pagesize = new VA.Drawing.Size(10, 10);
            VisioAutomationTest.SetPageSize(app.ActivePage, this.pagesize);
            var page = page_node.Render(app.ActiveDocument);

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

            app.ActiveDocument.Close(true);
        }
        public void Scripting_Page_Navigation()
        {
            var page_size = new VA.Drawing.Size(8.5, 11);
            var client = GetScriptingClient();
            var doc = client.Document.New(page_size.Width, page_size.Height);

            var page1 = client.Page.Get();
            client.Page.New(page_size, false);
            var page2 = client.Page.Get();
            client.Page.New(page_size, false);
            var page3 = client.Page.Get();

            Assert.AreEqual(3,doc.Pages.Count);
            Assert.AreEqual(page3, client.Page.Get());
            client.Page.GoTo(VA.Scripting.PageDirection.First);
            Assert.AreEqual(page1, client.Page.Get());
            client.Page.GoTo(VA.Scripting.PageDirection.Last);
            Assert.AreEqual(page3, client.Page.Get());
            client.Page.GoTo(VA.Scripting.PageDirection.Previous);
            Assert.AreEqual(page2, client.Page.Get());
            client.Page.GoTo(VA.Scripting.PageDirection.Next);
            Assert.AreEqual(page3, client.Page.Get());

            // move to last and try to go to next page
            client.Page.GoTo(VA.Scripting.PageDirection.Last);
            Assert.AreEqual(page3, client.Page.Get());
            client.Page.GoTo(VA.Scripting.PageDirection.Next);
            Assert.AreEqual(page3, client.Page.Get());

            // move to first and try to go to previous page
            client.Page.GoTo(VA.Scripting.PageDirection.First);
            Assert.AreEqual(page1, client.Page.Get());
            client.Page.GoTo(VA.Scripting.PageDirection.Previous);
            Assert.AreEqual(page1, client.Page.Get());

            doc.Close(true);
        }
        public static void BoxLayout_TwoLevelGrouping()
        {
            int num_types = 10;
            int max_properties = 50;

            var types = typeof (UserDefinedCell).Assembly.GetExportedTypes().Take(num_types).ToList();

            var data = new List<string[]>();
            foreach (var type in types)
            {
                var properties = type.GetProperties().Take(max_properties).ToList();
                foreach (var property in properties)
                {
                    var item = new[] {type.Name, property.Name[0].ToString().ToUpper(), property.Name};
                    data.Add(item);
                }
            }

            var layout1 = CreateTwoLevelLayout(data);

            layout1.PerformLayout();

            // TODO: Check that each data item has at least 3 values

            // Create a blank canvas in Visio
            var app = SampleEnvironment.Application;
            var documents = app.Documents;
            var doc = documents.Add(string.Empty);
            var page = app.ActivePage;

            var domshapescol = new VA.DOM.ShapeList();
            //var rect_master = dom.m
            foreach (var item in layout1.Nodes)
            {
                if (item.Data ==null)
                {
                    continue;
                }
                var info = (TwoLevelInfo) item.Data;

                if (!info.Render)
                {
                    continue;
                }

                var shape = domshapescol.Drop("Rectangle", "Basic_U.VSS",item.Rectangle);

                if (info.Text!=null)
                {
                    shape.Text = new VA.Text.Markup.TextElement(info.Text);
                }

                shape.Cells = info.ShapeCells.ShallowCopy();
            }
            domshapescol.Render(page);

            var bordersize = new VA.Drawing.Size(0.5, 0.5);
            page.ResizeToFitContents(bordersize);
        }
        public static void NURBS2()
        {
            // Draw a simple NURBS
            // Example from Graham Wideman's book

            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            var points = new[]
                             {
                                 new VA.Drawing.Point(0.2500, 0.2500),
                                 new VA.Drawing.Point(0.2500, 0.7500),
                                 new VA.Drawing.Point(0.4063, 0.8125),
                                 new VA.Drawing.Point(0.5625, 0.3750),
                                 new VA.Drawing.Point(0.5538, 0.8125),
                                 new VA.Drawing.Point(0.7600, 0.7500),
                                 new VA.Drawing.Point(0.7600, 0.2500)
                             };

            var origin = new VA.Drawing.Point(4, 4);
            var scale = new VA.Drawing.Size(4, 4);

            var controlpoints = points.Select(x => (x*scale) + origin).ToList();
            var knots = new double[] {0, 0, 0, 0, 25, 50, 75, 100, 100, 100, 100};
            var degree = 3;
            var Weights = controlpoints.Select(i => 1.0).ToList();

            var s0 = page.DrawNURBS(controlpoints, knots, Weights, degree);
            s0.Text = "Generic NURBS shape";
        }