public void Scripting_Distribute()
        {
            var client   = this.GetScriptingClient();
            var pagesize = new VA.Geometry.Size(4, 4);

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

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

            var r1 = new VA.Geometry.Rectangle(new VA.Geometry.Point(1, 1), size1);
            var r2 = new VA.Geometry.Rectangle(new VA.Geometry.Point(2, 2), size2);
            var r3 = new VA.Geometry.Rectangle(new VA.Geometry.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 VisioScripting.Models.TargetShapes();

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

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

            VisioAutomation.Shapes.ShapeXFormCells.GetCells(client.Page.Get(), shapeids, VA.ShapeSheet.CellValueType.Formula);

            client.Document.Close(true);
        }
Пример #2
0
        public Rectangle DrawRectangle(VisioAutomation.Geometry.Rectangle r)
        {
            var rectangle = new Rectangle(r);

            this.Add(rectangle);
            return(rectangle);
        }
Пример #3
0
        public Oval DrawOval(VisioAutomation.Geometry.Rectangle r)
        {
            var oval = new Oval(r);

            this.Add(oval);
            return(oval);
        }
Пример #4
0
        private static double _get_side(VisioAutomation.Geometry.Rectangle r, LayoutDirection direction)
        {
            switch (direction)
            {
            case (LayoutDirection.Up):
            {
                return(r.Top);
            }

            case (LayoutDirection.Down):
            {
                return(r.Bottom);
            }

            case (LayoutDirection.Left):
            {
                return(r.Left);
            }

            case (LayoutDirection.Right):
            {
                return(r.Right);
            }

            default:
            {
                throw new System.ArgumentOutOfRangeException();
            }
            }
        }
Пример #5
0
        public void Scripting_Nudge2()
        {
            var client = this.GetScriptingClient();

            client.Document.NewDocument();
            client.Page.NewPage(new VA.Geometry.Size(4, 4), false);

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

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

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

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

            client.Arrange.NudgeSelection(0.50, -0.25);

            var shapes   = new[] { s1, s2, s3 };
            var shapeids = shapes.Select(s => (int)s.ID16).ToList();
            var xforms   = VisioAutomation.Shapes.ShapeXFormCells.GetCells(client.Page.GetActivePage(), shapeids, VA.ShapeSheet.CellValueType.Result);

            AssertUtil.AreEqual((1.75, 1), xforms[0].GetPinPosResult(), 0.00001);
            AssertUtil.AreEqual((3, 2.25), xforms[1].GetPinPosResult(), 0.00001);
            AssertUtil.AreEqual((5.25, 4.5), xforms[2].GetPinPosResult(), 0.00001);
            client.Document.CloseActiveDocument(true);
        }
Пример #6
0
        public Shape Drop(string master, string stencil, VisioAutomation.Geometry.Rectangle rect)
        {
            var m = new Shape(master, stencil, rect);

            this.Add(m);
            return(m);
        }
Пример #7
0
        private static void SetViewRectToSelection(
            IVisio.Window window,
            IVisio.VisBoundingBoxArgs bbargs,
            double padding_scale)
        {
            if (padding_scale < 0.0)
            {
                throw new System.ArgumentOutOfRangeException(nameof(padding_scale));
            }

            if (padding_scale > 1.0)
            {
                throw new System.ArgumentOutOfRangeException(nameof(padding_scale));
            }

            var app           = window.Application;
            var active_window = app.ActiveWindow;
            var sel           = active_window.Selection;
            var sel_bb        = sel.GetBoundingBox(bbargs);

            var delta     = sel_bb.Size * (new VisioAutomation.Geometry.Size(padding_scale, padding_scale));
            var view_rect = new VisioAutomation.Geometry.Rectangle(sel_bb.Left - delta.Width, sel_bb.Bottom - delta.Height,
                                                                   sel_bb.Right + delta.Height, sel_bb.Top + delta.Height);

            window.SetViewRect(view_rect);
        }
Пример #8
0
        public void Page_Draw_RoundedRectangle()
        {
            var page1 = this.GetNewPage();
            var rect  = new VA.Geometry.Rectangle(1, 1, 3, 2);
            // draw an inital framing rectangle so the coordinates are easy to calculate
            var    s0     = page1.DrawRectangle(rect);
            double width  = rect.Width;
            double height = rect.Height;
            double delta  = 1.0 / 8.0;

            var o = new VA.Geometry.Point(0, 0);

            var a = new VA.Geometry.Point(o.X + delta, o.Y);
            var b = new VA.Geometry.Point(o.X, o.Y + delta);
            var c = new VA.Geometry.Point(o.X, o.Y + height - delta);
            var d = new VA.Geometry.Point(o.X + delta, o.Y + height);
            var e = new VA.Geometry.Point(o.X + width - delta, o.Y + height);
            var f = new VA.Geometry.Point(o.X + width, o.Y + height - delta);
            var g = new VA.Geometry.Point(o.X + width, o.Y + delta);
            var h = new VA.Geometry.Point(o.X + width - delta, o.Y);

            var bottom_left_curve  = s0.DrawQuarterArc(a, b, IVisio.VisArcSweepFlags.visArcSweepFlagConcave);
            var left_side          = s0.DrawLine(b, c);
            var top_left_curve     = s0.DrawQuarterArc(c, d, IVisio.VisArcSweepFlags.visArcSweepFlagConvex);
            var top_side           = s0.DrawLine(d, e);
            var top_right_curve    = s0.DrawQuarterArc(e, f, IVisio.VisArcSweepFlags.visArcSweepFlagConcave);
            var right_side         = s0.DrawLine(f, g);
            var bottom_right_curve = s0.DrawQuarterArc(g, h, IVisio.VisArcSweepFlags.visArcSweepFlagConvex);
            var bottom_side        = s0.DrawLine(h, a);

            // delete the framing rectangle
            s0.DeleteSection((short)IVisio.VisSectionIndices.visSectionFirstComponent);

            page1.Delete(0);
        }
        public IVisio.Shape AddShape(TextBlock block)
        {
            // Remember this Block
            this.Blocks.Add(block);

            // Calculate the Correct Full Rectangle
            var ll   = new VisioAutomation.Geometry.Point(this.InsertionPoint.X, this.InsertionPoint.Y - block.Size.Height);
            var tr   = new VisioAutomation.Geometry.Point(this.InsertionPoint.X + block.Size.Width, this.InsertionPoint.Y);
            var rect = new VisioAutomation.Geometry.Rectangle(ll, tr);

            // Draw the Shape
            var newshape = this._page.DrawRectangle(rect);

            block.VisioShape   = newshape;
            block.VisioShapeID = newshape.ID;
            block.Rectangle    = rect;

            // Handle Text If Needed
            if (block.Text != null)
            {
                newshape.Text = block.Text;
            }

            this._adjust_insertion_point(block.Size);

            return(newshape);
        }
Пример #10
0
        public void Scripting_Distribute()
        {
            var client   = this.GetScriptingClient();
            var pagesize = new VA.Geometry.Size(4, 4);

            client.Document.NewDocument();
            client.Page.NewPage(VisioScripting.TargetDocument.Auto, pagesize, false);

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

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

            var s1 = client.Draw.DrawRectangle(VisioScripting.TargetPage.Auto, r1);
            var s2 = client.Draw.DrawRectangle(VisioScripting.TargetPage.Auto, r2);
            var s3 = client.Draw.DrawRectangle(VisioScripting.TargetPage.Auto, r3);

            client.Selection.SelectNone(VisioScripting.TargetWindow.Auto);
            client.Selection.SelectShapesById(VisioScripting.TargetWindow.Auto, s1);
            client.Selection.SelectShapesById(VisioScripting.TargetWindow.Auto, s2);
            client.Selection.SelectShapesById(VisioScripting.TargetWindow.Auto, s3);

            client.Arrange.DistributeHorizontal(VisioScripting.TargetSelection.Auto, VisioScripting.Models.AlignmentHorizontal.Center);

            var shapes   = new[] { s1, s2, s3 };
            var shapeids = shapes.Select(s => (int)s.ID16).ToList();

            VisioAutomation.Shapes.ShapeXFormCells.GetCells(client.Page.GetActivePage(), shapeids, VA.ShapeSheet.CellValueType.Formula);

            client.Document.CloseDocument(VisioScripting.TargetDocuments.Auto);
        }
Пример #11
0
        public VisioAutomation.Geometry.Rectangle GetBoundingBox(IVisio.VisBoundingBoxArgs args)
        {
            double bbx0, bby0, bbx1, bby1;

            if (this.Master != null)
            {
                this.Master.BoundingBox((short)args, out bbx0, out bby0, out bbx1, out bby1);
            }
            else if (this.Page != null)
            {
                this.Page.BoundingBox((short)args, out bbx0, out bby0, out bbx1, out bby1);
            }
            else if (this.Shape != null)
            {
                this.Shape.BoundingBox((short)args, out bbx0, out bby0, out bbx1, out bby1);
            }
            else
            {
                throw new System.ArgumentException("Unhandled Drawing Surface");
            }

            var r = new VisioAutomation.Geometry.Rectangle(bbx0, bby0, bbx1, bby1);

            return(r);
        }
        protected override void ProcessRecord()
        {
            var rect  = new VA.Geometry.Rectangle(this.X0, this.Y0, this.X1, this.Y1);
            var chart = new VA.Models.Charting.AreaChart(rect);

            chart.DataPoints = new VA.Models.Charting.DataPointList(this.Values, this.Labels);
            this.WriteObject(chart);
        }
Пример #13
0
        public static void DrawNode(
            Node node,
            VA.Geometry.Rectangle rect, IVisio.Page page)
        {
            var shape = page.DrawRectangle(rect);

            node.Data = shape;
        }
        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 VAM.Dom.ShapeList();

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

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


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

                        var r  = new VA.Geometry.Rectangle(x0, y0, x0 + w, y0 + h);
                        var n1 = domshapescol.Drop("Rectangle", "basic_u.vss", r);
                        if (i < chunk.Count)
                        {
                            n1.Text = new VAM.Text.Element(chunk[i]);
                        }
                        n1.CharFontName         = fontnames[j];
                        n1.Cells.CharSize       = "36pt";
                        n1.Cells.FillForeground = "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.Geometry.Size(0.5, 0.5);
                page.ResizeToFitContents(bordersize);
            }
        }
Пример #15
0
        public IVisio.Shape Oval(VisioAutomation.Geometry.Rectangle rect)
        {
            var surface = this.GetDrawingSurface();

            using (var undoscope = this._client.Application.NewUndoScope("Draw Oval"))
            {
                var shape = surface.DrawOval(rect);
                return(shape);
            }
        }
Пример #16
0
        public IVisio.Shape Rectangle(VisioAutomation.Geometry.Rectangle r)
        {
            var surface = this.GetDrawingSurface();

            using (var undoscope = this._client.Application.NewUndoScope("Draw Rectangle"))
            {
                var shape = surface.DrawRectangle(r.Left, r.Bottom, r.Right, r.Top);
                return(shape);
            }
        }
Пример #17
0
        public IVisio.Shape DrawOval(VisioAutomation.Geometry.Rectangle rect)
        {
            var surface = this.GetActiveDrawingSurface();

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(DrawOval)))
            {
                var shape = surface.DrawOval(rect);
                return(shape);
            }
        }
Пример #18
0
        public IVisio.Shape DrawRectangle(VisioAutomation.Geometry.Rectangle r)
        {
            var surface = this.GetActiveDrawingSurface();

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(DrawRectangle)))
            {
                var shape = surface.DrawRectangle(r.Left, r.Bottom, r.Right, r.Top);
                return(shape);
            }
        }
Пример #19
0
        public IVisio.Shape DrawOval(VisioScripting.TargetPage targetpage, VisioAutomation.Geometry.Rectangle rect)
        {
            targetpage = targetpage.ResolveToPage(this._client);
            var surface = new VisioAutomation.SurfaceTarget(targetpage.Page);

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(DrawOval)))
            {
                var shape = surface.DrawOval(rect);
                return(shape);
            }
        }
        public static void FontGlyphComparision3(IVisio.Document doc, string[] fontnames, List <string> samplechars)
        {
            var colors = new[] { "rgb(0,0,255)", "rgb(255,0,0)" };

            double w = 2.0;
            double h = 1;

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


            foreach (var chunk in chunks)
            {
                var domshapescol = new VAM.Dom.ShapeList();

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

                        var r  = new VA.Geometry.Rectangle(x0, y0, x0 + w, y0 + h);
                        var n1 = domshapescol.Drop("Rectangle", "basic_u.vss", r);
                        if (i < chunk.Count)
                        {
                            n1.Text = new VAM.Text.Element(chunk[i]);
                            n1.Text.CharacterFormatting.Color = colors[j];
                        }
                        n1.CharFontName = fontnames[j];

                        //n1.Cells.CharColor = "=RGB(255,0,0)";// colors[j];
                        n1.Cells.CharTransparency = 0.7;
                        n1.Cells.CharSize         = "36pt";
                        n1.Cells.FillPattern      = 0;
                        n1.Cells.LineWeight       = 0.0;
                        n1.Cells.LinePattern      = 0;
                    }
                }

                var page = doc.Pages.Add();

                domshapescol.Render(page);

                var bordersize = new VA.Geometry.Size(0.5, 0.5);
                page.ResizeToFitContents(bordersize);
            }
        }
Пример #21
0
        public void Scripting_Distribute_With_Spacing()
        {
            var client   = this.GetScriptingClient();
            var pagesize = new VA.Geometry.Size(4, 4);

            client.Document.NewDocument();
            client.Page.NewPage(pagesize, false);

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

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

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

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

            var targetshapes = new VisioScripting.TargetShapes();

            client.Distribute.DistributeSelectionOnAxis(targetshapes, VisioScripting.Models.Axis.XAxis, 0.25);
            client.Distribute.DistributeSelectionOnAxis(targetshapes, VisioScripting.Models.Axis.YAxis, 1.0);

            var shapes        = new[] { s1, s2, s3 };
            var shapeids      = shapes.Select(s => (int)s.ID16).ToList();
            var out_xfrms     = VisioAutomation.Shapes.ShapeXFormCells.GetCells(client.Page.GetActivePage(), shapeids, VA.ShapeSheet.CellValueType.Result);
            var out_positions = out_xfrms.Select(xfrm => TestExtensions.ToPoint(xfrm.PinX.Value, xfrm.PinY.Value)).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);

            var targetdoc = new VisioScripting.TargetDocument();

            client.Document.CloseDocument(targetdoc, true);
        }
Пример #22
0
        public void Scripting_Draw_BarChart()
        {
            var pagesize   = new VA.Geometry.Size(4, 4);
            var rect1      = new VA.Geometry.Rectangle(0, 0, 4, 4);
            var rect2      = new VA.Geometry.Rectangle(5, 0, 9, 4);
            var rect3      = new VA.Geometry.Rectangle(10, 0, 14, 4);
            var bordersize = new VA.Geometry.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);
        }
Пример #23
0
        public void Scripting_Draw_AreaChart()
        {
            var pagesize = new VA.Geometry.Size(4, 4);
            var rect1    = new VA.Geometry.Rectangle(0, 0, 4, 4);
            var rect2    = new VA.Geometry.Rectangle(5, 0, 9, 4);
            var rect3    = new VA.Geometry.Rectangle(10, 0, 14, 4);
            var padding  = new VA.Geometry.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);
        }
Пример #24
0
        public void Dom_DrawAndDrop()
        {
            var doc       = this.GetNewDoc();
            var page_node = new VADOM.Page();

            var rect0 = new VisioAutomation.Geometry.Rectangle(3, 4, 7, 8);
            var rect1 = new VisioAutomation.Geometry.Rectangle(8, 1, 9, 5);

            // Draw and Drop two rectangles in the same place
            var s0 = page_node.Shapes.Drop(this.node_master_name, this.node_stencil_name, rect0);
            var s1 = page_node.Shapes.DrawRectangle(rect0);

            // Draw and Drop two rectangles in the same place
            var s2 = page_node.Shapes.Drop(this.node_master_name, this.node_stencil_name, rect1);
            var s3 = page_node.Shapes.DrawRectangle(rect1);

            // Render the page
            var page = page_node.Render(doc);

            // Verify the locations and sizes

            var shapeids = new int[] {
                s0.VisioShapeID,
                s1.VisioShapeID,
                s2.VisioShapeID,
                s3.VisioShapeID
            };

            var xfrms = VA.Shapes.ShapeXFormCells.GetCells(page, shapeids, VA.ShapeSheet.CellValueType.Formula);

            Assert.AreEqual(xfrms[1].PinX, xfrms[0].PinX);
            Assert.AreEqual(xfrms[1].PinY, xfrms[0].PinY);

            Assert.AreEqual(xfrms[1].Width, xfrms[0].Width);
            Assert.AreEqual(xfrms[1].Height, xfrms[0].Height);

            Assert.AreEqual(xfrms[3].PinX, xfrms[2].PinX);
            Assert.AreEqual(xfrms[3].PinY, xfrms[2].PinY);
            Assert.AreEqual(xfrms[3].Width, xfrms[2].Width);
            Assert.AreEqual(xfrms[3].Height, xfrms[2].Height);

            doc.Close(true);
        }
Пример #25
0
        public IVisio.Shape DrawOval(VisioAutomation.Geometry.Rectangle rect)
        {
            if (this.Master != null)
            {
                var shape = this.Master.DrawOval(rect.Left, rect.Bottom, rect.Right, rect.Top);
                return(shape);
            }
            else if (this.Page != null)
            {
                var shape = this.Page.DrawOval(rect.Left, rect.Bottom, rect.Right, rect.Top);
                return(shape);
            }
            else if (this.Shape != null)
            {
                var shape = this.Shape.DrawOval(rect.Left, rect.Bottom, rect.Right, rect.Top);
                return(shape);
            }

            throw new System.ArgumentException("Unhandled Drawing Surface");
        }
Пример #26
0
        private void draw_shape()
        {
            var points = VisioAutomation.Geometry.Point.FromDoubles(this.Points).ToList();

            check_points_for_shape_type(points);

            if (this.Type == Models.ShapeType.Rectangle)
            {
                var r     = new VisioAutomation.Geometry.Rectangle(points[0], points[1]);
                var shape = this.Client.Draw.DrawRectangle(r);
                this.WriteObject(shape);
            }
            else if (this.Type == Models.ShapeType.Line)
            {
                var lineseg = new VisioAutomation.Models.Geometry.LineSegment(points[0], points[1]);
                var shape   = this.Client.Draw.DrawLine(lineseg.Start, lineseg.End);
                this.WriteObject(shape);
            }
            else if (this.Type == Models.ShapeType.Oval)
            {
                var r     = new VisioAutomation.Geometry.Rectangle(points[0], points[1]);
                var shape = this.Client.Draw.DrawOval(r);
                this.WriteObject(shape);
            }
            else if (this.Type == Models.ShapeType.Polyline)
            {
                var shape = this.Client.Draw.DrawPolyLine(points);
                this.WriteObject(shape);
            }
            else if (this.Type == Models.ShapeType.Bezier)
            {
                var shape = this.Client.Draw.DrawBezier(points);
                this.WriteObject(shape);
            }
            else
            {
                throw new System.ArgumentOutOfRangeException();
            }
        }
        public void Scripting_Nudge2()
        {
            var client = this.GetScriptingClient();

            client.Document.New();
            client.Page.New(new VA.Geometry.Size(4, 4), false);

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

            var r1 = new VA.Geometry.Rectangle(new VA.Geometry.Point(1, 1), size1);
            var r2 = new VA.Geometry.Rectangle(new VA.Geometry.Point(2, 2), size2);
            var r3 = new VA.Geometry.Rectangle(new VA.Geometry.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 VisioScripting.Models.TargetShapes();

            client.Arrange.Nudge(targets, 0.50, -0.25);

            var shapeids = new[] { s1.ID, s2.ID, s3.ID };
            var xforms   = VisioAutomation.Shapes.ShapeXFormCells.GetCells(client.Page.Get(), shapeids, VA.ShapeSheet.CellValueType.Result);

            AssertUtil.AreEqual((1.75, 1), xforms[0].GetPinPosResult(), 0.00001);
            AssertUtil.AreEqual((3, 2.25), xforms[1].GetPinPosResult(), 0.00001);
            AssertUtil.AreEqual((5.25, 4.5), xforms[2].GetPinPosResult(), 0.00001);
            client.Document.Close(true);
        }
Пример #28
0
        public IVisio.Shape DrawRectangle(double x0, double y0, double x1, double y1)
        {
            var rect = new VisioAutomation.Geometry.Rectangle(x0, y0, x1, y1);

            return(this.DrawRectangle(rect));
        }
Пример #29
0
        private MSAGL.Core.Layout.GeometryGraph CreateMsaglGraph(DirectedGraphLayout layout_diagram)
        {
            var mg_graph = new MSAGL.Core.Layout.GeometryGraph();

            // Create the nodes in MSAGL
            foreach (var layout_shape in layout_diagram.Shapes)
            {
                var nodesize       = this.ToMGCoordinates(layout_shape.Size ?? this.LayoutOptions.DefaultShapeSize);
                var node_user_data = new NodeUserData(layout_shape.ID, layout_shape);
                var center         = new MSAGL.Core.Geometry.Point();
                var rectangle      = MSAGL.Core.Geometry.Curves.CurveFactory.CreateRectangle(nodesize.Width, nodesize.Height, center);
                var mg_node        = new MSAGL.Core.Layout.Node(rectangle, node_user_data);
                mg_graph.Nodes.Add(mg_node);
            }

            this.validate_connectors(layout_diagram);

            var mg_coordinates = this.ToMGCoordinates(this.DefaultBezierConnectorLabelBoxSize);

            var map_id_to_ud = new Dictionary <string, MSAGL.Core.Layout.Node>();

            foreach (var n in mg_graph.Nodes)
            {
                var ud = (NodeUserData)n.UserData;
                if (ud != null)
                {
                    map_id_to_ud[ud.ID] = n;
                }
            }

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

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

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

                var new_edge = new MSAGL.Core.Layout.Edge(from_node, to_node);
                // TODO: MSAGL
                //new_edge.ArrowheadAtTarget = false;
                new_edge.UserData = new NodeUserData(layout_connector.ID, layout_connector);
                mg_graph.Edges.Add(new_edge);

                new_edge.Label = new MSAGL.Core.Layout.Label(mg_coordinates.Width, mg_coordinates.Height, new_edge);
            }

            var geom_graph_components = MSAGL.Core.Layout.GraphConnectedComponents.CreateComponents(mg_graph.Nodes, mg_graph.Edges);
            var settings = new MSAGL.Layout.Layered.SugiyamaLayoutSettings();

            foreach (var subgraph in geom_graph_components)
            {
                var layout = new Microsoft.Msagl.Layout.Layered.LayeredLayout(subgraph, settings);
                subgraph.Margins = settings.NodeSeparation / 2;
                layout.Run();
            }

            // Pack the graphs using Golden Aspect Ratio
            MSAGL.Layout.MDS.MdsGraphLayout.PackGraphs(geom_graph_components, settings);

            //Update the graphs bounding box
            mg_graph.UpdateBoundingBox();

            this._mg_bb = new VA.Geometry.Rectangle(
                mg_graph.BoundingBox.Left,
                mg_graph.BoundingBox.Bottom,
                mg_graph.BoundingBox.Right,
                mg_graph.BoundingBox.Top);

            this._layout_bb = new VA.Geometry.Rectangle(0, 0, this._mg_bb.Width, this._mg_bb.Height)
                              .Multiply(this.ScaleToDocument, this.ScaleToDocument);

            return(mg_graph);
        }
Пример #30
0
        private VA.Geometry.Rectangle ToDocumentCoordinates(VA.Geometry.Rectangle rect)
        {
            var nr = rect.Add(-this._mg_bb.Left, -this._mg_bb.Bottom).Multiply(this.ScaleToDocument, this.ScaleToDocument);

            return(nr);
        }