Exemple #1
0
        public void Set(IList <IVisio.Shape> target_shapes, string name, CP.CustomPropertyCells customprop)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            if (customprop == null)
            {
                throw new System.ArgumentNullException("customprop");
            }

            var shapes = GetTargetShapes(target_shapes);

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

            var application = this.Client.VisioApplication;

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Set Custom Property"))
            {
                foreach (var shape in shapes)
                {
                    CP.CustomPropertyHelper.Set(shape, name, customprop);
                }
            }
        }
Exemple #2
0
        public void Delete(IList <IVisio.Shape> target_shapes, string name)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            if (name == null)
            {
                throw new System.ArgumentNullException("name");
            }

            if (name.Length < 1)
            {
                throw new System.ArgumentException("name");
            }

            var shapes = GetTargetShapes(target_shapes);

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

            var application = this.Client.VisioApplication;

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Delete Custom Property"))
            {
                foreach (var shape in shapes)
                {
                    CP.CustomPropertyHelper.Delete(shape, name);
                }
            }
        }
Exemple #3
0
        public IVisio.Page New(VA.Drawing.Size?size, bool isbackgroundpage)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var application     = this.Client.VisioApplication;
            var active_document = application.ActiveDocument;
            var pages           = active_document.Pages;

            IVisio.Page page = pages.Add();

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "New Page"))
            {
                if (size.HasValue)
                {
                    this.Client.WriteVerbose("Setting page size to {0}", size.Value);
                    this.SetSize(size.Value);
                }

                if (isbackgroundpage)
                {
                    page.Background = 1;
                }
            }

            return(page);
        }
        public void Application_UndoScope_AbortOuter()
        {
            var page1 = this.GetNewPage();
            var app   = page1.Application;

            Assert.AreEqual(0, page1.Shapes.Count);

            // create a shape without undoing it
            using (var undoscope0 = new VA.Application.UndoScope(app, "UndoScope1"))
            {
                var s1 = page1.DrawRectangle(0, 0, 1, 1);
                Assert.AreEqual(1, page1.Shapes.Count);
                using (var undoscope1 = new VA.Application.UndoScope(app, "UndoScope2"))
                {
                    var s2 = page1.DrawRectangle(1, 1, 2, 2);
                    var s3 = page1.DrawRectangle(2, 2, 3, 3);
                    Assert.AreEqual(3, page1.Shapes.Count);
                }
                Assert.AreEqual(3, page1.Shapes.Count);

                undoscope0.Commit = false;
            }
            Assert.AreEqual(0, page1.Shapes.Count);

            page1.Delete(0);
        }
        public void Application_UndoScope_AbortOuter()
        {
            var page1 = GetNewPage();
            var app = page1.Application;

            Assert.AreEqual(0, page1.Shapes.Count);

            // create a shape without undoing it
            using (var undoscope0 = new VA.Application.UndoScope(app, "UndoScope1"))
            {
                var s1 = page1.DrawRectangle(0, 0, 1, 1);
                Assert.AreEqual(1, page1.Shapes.Count);
                using (var undoscope1 = new VA.Application.UndoScope(app, "UndoScope2"))
                {
                    var s2 = page1.DrawRectangle(1, 1, 2, 2);
                    var s3 = page1.DrawRectangle(2, 2, 3, 3);
                    Assert.AreEqual(3, page1.Shapes.Count);

                }
                Assert.AreEqual(3, page1.Shapes.Count);

                undoscope0.Commit = false;
            }
            Assert.AreEqual(0, page1.Shapes.Count);

            page1.Delete(0);
        }
Exemple #6
0
        public void Duplicate(int n)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            if (n < 1)
            {
                throw new System.ArgumentOutOfRangeException("n");
            }
            if (!this.Client.HasSelectedShapes())
            {
                return;
            }

            // TODO: Add ability to duplicate all the selected shapes, not just the first one
            // this dupicates exactly 1 shape N - times what it
            // it should do is duplicate all M selected shapes N times so that M*N shapes are created

            var application = this.Client.VisioApplication;

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, string.Format("Duplicate Shape {0} Times", n)))
            {
                var active_window = application.ActiveWindow;
                var selection     = active_window.Selection;
                var active_page   = application.ActivePage;
                DrawCommands.CreateDuplicates(active_page, selection[1], n);
            }
        }
        public void Delete(IList<IVisio.Shape> target_shapes, string name)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = GetTargetShapes(target_shapes);
            if (shapes.Count < 1)
            {
                return;
            }

            if (name == null)
            {
                throw new System.ArgumentNullException("name");
            }

            if (name.Length < 1)
            {
                throw new System.ArgumentException("name");
            }

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication,"Delete User-Defined Cell"))
            {
                foreach (var shape in shapes)
                {
                    UserDefinedCellsHelper.Delete(shape, name);
                }
            }
        }
Exemple #8
0
        public IList <int> Add(IList <IVisio.Shape> target_shapes, CTRLS.ControlCells ctrl)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            if (ctrl == null)
            {
                throw new System.ArgumentNullException("ctrl");
            }

            var shapes = GetTargetShapes(target_shapes);

            if (shapes.Count < 1)
            {
                return(new List <int>(0));
            }


            var control_indices = new List <int>();

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Add Control"))
            {
                foreach (var shape in shapes)
                {
                    int ci = CTRLS.ControlHelper.Add(shape, ctrl);
                    control_indices.Add(ci);
                }
            }

            return(control_indices);
        }
        public void Application_UndoScope_Simple()
        {
            var page1 = this.GetNewPage();
            var app = page1.Application;

            Assert.AreEqual(0, page1.Shapes.Count);

            // create a shape without undoing it
            using (var undoscope0 = new VA.Application.UndoScope(app, "UndoScope1"))
            {
                var s1 = page1.DrawRectangle(0, 0, 2, 2);
                Assert.AreEqual(1, page1.Shapes.Count);
            }
            Assert.AreEqual(1, page1.Shapes.Count);

            // create a shape and undo it
            using (var undoscope1 = new VA.Application.UndoScope(app, "UndoScope2"))
            {
                var s1 = page1.DrawRectangle(1, 1, 3, 3);
                Assert.AreEqual(2, page1.Shapes.Count);
            }
            app.Undo();

            Assert.AreEqual(1, page1.Shapes.Count);
            page1.Delete(0);
        }
        public IList<int> Add(IList<IVisio.Shape> target_shapes, CTRLS.ControlCells ctrl)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            if (ctrl == null)
            {
                throw new System.ArgumentNullException("ctrl");
            }

            var shapes = GetTargetShapes(target_shapes);
            if (shapes.Count < 1)
            {
                return new List<int>(0);
            }

            var control_indices = new List<int>();
            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication,"Add Control"))
            {
                foreach (var shape in shapes)
                {
                    int ci = CTRLS.ControlHelper.Add(shape, ctrl);
                    control_indices.Add(ci);
                }
            }

            return control_indices;
        }
Exemple #11
0
        public void Set(IList <IVisio.Shape> target_shapes, UserDefinedCell userdefinedcell)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = GetTargetShapes(target_shapes);

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

            if (userdefinedcell == null)
            {
                throw new System.ArgumentNullException("userdefinedcell");
            }

            var application = this.Client.VisioApplication;

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Set User-Defined Cell"))
            {
                foreach (var shape in shapes)
                {
                    UserDefinedCellsHelper.Set(shape, userdefinedcell.Name, userdefinedcell.Value.Formula.Value, userdefinedcell.Prompt.Formula.Value);
                }
            }
        }
Exemple #12
0
        public void Set(IList <IVisio.Shape> target_shapes, IList <string> texts)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            if (texts == null || texts.Count < 1)
            {
                // do nothing
                return;
            }

            var shapes = this.GetTargetShapes(target_shapes);

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

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Set Shape Text"))
            {
                int numtexts = texts.Count;
                for (int i = 0; i < shapes.Count; i++)
                {
                    var shape = shapes[i];
                    var text  = texts[i % numtexts];
                    shape.Text = text;
                }
            }
        }
        public void Application_UndoScope_NestedOuter()
        {
            var page1 = this.GetNewPage();
            var app   = page1.Application;

            Assert.AreEqual(0, page1.Shapes.Count);

            // Test that outter does affect inner
            using (var undoscope0 = new VA.Application.UndoScope(app, "UndoScope1"))
            {
                var s1 = page1.DrawRectangle(0, 0, 2, 2);
                Assert.AreEqual(1, page1.Shapes.Count);

                // create a shape and undo it
                using (var undoscope1 = new VA.Application.UndoScope(app, "UndoScope2"))
                {
                    var s2 = page1.DrawRectangle(1, 1, 3, 3);
                    Assert.AreEqual(2, page1.Shapes.Count);
                }
            }
            app.Undo();

            Assert.AreEqual(0, page1.Shapes.Count);
            page1.Delete(0);
        }
        public void Application_UndoScope_Simple()
        {
            var page1 = this.GetNewPage();
            var app   = page1.Application;

            Assert.AreEqual(0, page1.Shapes.Count);

            // create a shape without undoing it
            using (var undoscope0 = new VA.Application.UndoScope(app, "UndoScope1"))
            {
                var s1 = page1.DrawRectangle(0, 0, 2, 2);
                Assert.AreEqual(1, page1.Shapes.Count);
            }
            Assert.AreEqual(1, page1.Shapes.Count);

            // create a shape and undo it
            using (var undoscope1 = new VA.Application.UndoScope(app, "UndoScope2"))
            {
                var s1 = page1.DrawRectangle(1, 1, 3, 3);
                Assert.AreEqual(2, page1.Shapes.Count);
            }
            app.Undo();

            Assert.AreEqual(1, page1.Shapes.Count);
            page1.Delete(0);
        }
 public IVisio.Shape Bezier(IEnumerable<VA.Drawing.Point> points)
 {
     var surface = this.GetDrawingSurfaceSafe();
     using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Draw Bezier"))
     {
         var shape = surface.DrawBezier(points.ToList());
         return shape;
     }
 }
Exemple #16
0
        public IVisio.Shape Line(double x0, double y0, double x1, double y1)
        {
            var surface = this.GetDrawingSurfaceSafe();

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Draw Line"))
            {
                var shape = surface.DrawLine(x0, y0, x1, y1);
                return(shape);
            }
        }
Exemple #17
0
        public IVisio.Shape PolyLine(IList <VA.Drawing.Point> points)
        {
            var surface = this.GetDrawingSurfaceSafe();

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Draw PolyLine"))
            {
                var shape = surface.DrawPolyLine(points);
                return(shape);
            }
        }
Exemple #18
0
        public IVisio.Shape Bezier(IEnumerable <VA.Drawing.Point> points)
        {
            var surface = this.GetDrawingSurfaceSafe();

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Draw Bezier"))
            {
                var shape = surface.DrawBezier(points.ToList());
                return(shape);
            }
        }
Exemple #19
0
        public IVisio.Shape Oval(VA.Drawing.Point center, double radius)
        {
            var surface = this.GetDrawingSurfaceSafe();

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Draw Oval"))
            {
                var shape = surface.DrawOval(center, radius);
                return(shape);
            }
        }
Exemple #20
0
        public void ToogleCase(IList <IVisio.Shape> target_shapes)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = this.GetTargetShapes(target_shapes);

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

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Toggle Shape Text Case"))
            {
                var shapeids = shapes.Select(s => s.ID).ToList();

                var page = this.Client.VisioApplication.ActivePage;
                // Store all the formatting
                var formats = VA.Text.TextFormat.GetFormat(page, shapeids);

                // Change the text - this will wipe out all the character and paragraph formatting
                foreach (var shape in shapes)
                {
                    string t = shape.Text;
                    if (t.Length < 1)
                    {
                        continue;
                    }
                    shape.Text = TextCommandsUtil.toggle_case(t);
                }

                // Now restore all the formatting - based on any initial formatting from the text

                var update = new VA.ShapeSheet.Update();
                for (int i = 0; i < shapes.Count; i++)
                {
                    var format = formats[i];

                    if (format.CharacterFormats.Count > 0)
                    {
                        var fmt = format.CharacterFormats[0];
                        update.SetFormulas((short)shapeids[i], fmt, 0);
                    }

                    if (format.ParagraphFormats.Count > 0)
                    {
                        var fmt = format.ParagraphFormats[0];
                        update.SetFormulas((short)shapeids[i], fmt, 0);
                    }
                }

                update.Execute(page);
            }
        }
Exemple #21
0
        public IVisio.Shape Oval(double x0, double y0, double x1, double y1)
        {
            var surface = this.GetDrawingSurfaceSafe();
            var rect    = new VA.Drawing.Rectangle(x0, y0, x1, y1);

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Draw Oval"))
            {
                var shape = surface.DrawOval(rect);
                return(shape);
            }
        }
 public void Update()
 {
     this.Client.WriteVerbose("Staring ShapeSheet Update");
     var application = this.Client.VisioApplication;
     using (var undoscope = new VA.Application.UndoScope(application, "Update ShapeSheet Formulas"))
     {
         this.update.BlastGuards = this.BlastGuards;
         this.update.TestCircular = this.TestCircular;
         this.update.Execute(this.TargetPage);
     }
     this.Client.WriteVerbose("Ending ShapeSheet Update");
 }
Exemple #23
0
        public void Update()
        {
            this.Client.WriteVerbose("Staring ShapeSheet Update");
            var application = this.Client.VisioApplication;

            using (var undoscope = new VA.Application.UndoScope(application, "Update ShapeSheet Formulas"))
            {
                this.update.BlastGuards  = this.BlastGuards;
                this.update.TestCircular = this.TestCircular;
                this.update.Execute(this.TargetPage);
            }
            this.Client.WriteVerbose("Ending ShapeSheet Update");
        }
        private void buttonScrambleText_Click(object sender, RibbonControlEventArgs e)
        {
            var app = Globals.ThisAddIn.Application;
            var doc = app.ActiveDocument;

            if (doc == null)
            {
                return;
            }

            if (doc.Type != IVisio.VisDocumentTypes.visTypeDrawing)
            {
                MessageBox.Show("Currently Active Document is not a Drawing");
                return;
            }

            var activewindow = app.ActiveWindow;
            var sb           = new StringBuilder();
            var pages        = doc.Pages.AsEnumerable().ToList();

            using (var scope = new VA.Application.UndoScope(app, "Scramble Text"))
            {
                // Begin Undo Scope
                doc.Company  = VPTRibbon.Scramble(sb, doc.Company);
                doc.Category = VPTRibbon.Scramble(sb, doc.Category);
                doc.Title    = VPTRibbon.Scramble(sb, doc.Title);
                doc.Subject  = VPTRibbon.Scramble(sb, doc.Subject);
                doc.Creator  = VPTRibbon.Scramble(sb, doc.Creator);
                doc.Manager  = VPTRibbon.Scramble(sb, doc.Manager);
                doc.Keywords = VPTRibbon.Scramble(sb, doc.Keywords);
                foreach (var page in pages)
                {
                    activewindow.Page = page;
                    var shapes = page.Shapes.AsEnumerable().ToList();
                    foreach (var shape in shapes)
                    {
                        VPTRibbon.Scramble(sb, shape);

                        var shape_shapes = shape.Shapes;
                        if (shape_shapes != null && shape_shapes.Count > 0)
                        {
                            foreach (var nested_shape in VA.Shapes.ShapeHelper.GetNestedShapes(shape))
                            {
                                VPTRibbon.Scramble(sb, nested_shape);
                            }
                        }
                    }
                }
                // End Undo Scope
            }
        }
 public void FitShapeToText()
 {
     if (!this.Client.HasSelectedShapes())
     {
         return;
     }
     var shapes_2d = this.Client.Selection.GetShapes();
     var application = this.Client.VisioApplication;
     using (var undoscope = new VA.Application.UndoScope(application,"FitShapeToText"))
     {
         var active_page = application.ActivePage;
         VA.Text.TextHelper.FitShapeToText(active_page, shapes_2d);
     }
 }
Exemple #26
0
        public void FitShapeToText()
        {
            if (!this.Client.HasSelectedShapes())
            {
                return;
            }
            var shapes_2d   = this.Client.Selection.GetShapes();
            var application = this.Client.VisioApplication;

            using (var undoscope = new VA.Application.UndoScope(application, "FitShapeToText"))
            {
                var active_page = application.ActivePage;
                VA.Text.TextHelper.FitShapeToText(active_page, shapes_2d);
            }
        }
Exemple #27
0
        public void Grid(GRIDLAYOUT.GridLayout layout)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            //Create a new page to hold the grid
            var application = this.Client.VisioApplication;
            var page        = application.ActivePage;

            layout.PerformLayout();

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Draw Grid"))
            {
                layout.Render(page);
            }
        }
Exemple #28
0
        public void SetSize(VA.Drawing.Size new_size)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var application = this.Client.VisioApplication;

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Set Page Size"))
            {
                var active_page = application.ActivePage;
                var page_sheet  = active_page.PageSheet;
                var update      = new VA.ShapeSheet.Update(2);
                update.SetFormula(VA.ShapeSheet.SRCConstants.PageWidth, new_size.Width);
                update.SetFormula(VA.ShapeSheet.SRCConstants.PageHeight, new_size.Height);
                update.Execute(page_sheet);
            }
        }
Exemple #29
0
        public void ResizeToFitContents(VA.Drawing.Size bordersize, bool zoom_to_page)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var application = this.Client.VisioApplication;

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Resize Page to Fit Contents"))
            {
                var active_page = application.ActivePage;
                active_page.ResizeToFitContents(bordersize);
                if (zoom_to_page)
                {
                    this.Client.View.Zoom(VA.Scripting.Zoom.ToPage);
                }
            }
        }
Exemple #30
0
        public void SetTextWrapping(bool wrap)
        {
            if (!this.Client.HasSelectedShapes())
            {
                return;
            }

            var selection   = this.Client.Selection.Get();
            var shapeids    = selection.GetIDs();
            var application = this.Client.VisioApplication;

            using (var undoscope = new VA.Application.UndoScope(application, "SetTextWrapping"))
            {
                var active_page = application.ActivePage;
                TextCommandsUtil.set_text_wrapping(active_page, shapeids, wrap);
            }
        }
Exemple #31
0
        public IVisio.Shape PieSlice(VA.Drawing.Point center,
                                     double radius,
                                     double start_angle,
                                     double end_angle)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var application = this.Client.VisioApplication;

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Draw Pie Slice"))
            {
                var active_page = application.ActivePage;
                var slice       = new VA.Models.Charting.PieSlice(center, radius, start_angle, end_angle);
                var shape       = slice.Render(active_page);
                return(shape);
            }
        }
Exemple #32
0
        public void SetBackgroundPage(string background_page_name)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            if (background_page_name == null)
            {
                throw new System.ArgumentNullException("background_page_name");
            }

            var application     = this.Client.VisioApplication;
            var active_document = application.ActiveDocument;
            var pages           = active_document.Pages;
            var names           = new HashSet <string>(pages.GetNamesU());

            if (!names.Contains(background_page_name))
            {
                string msg = string.Format("Could not find page with name \"{0}\"", background_page_name);
                throw new VA.Scripting.ScriptingException(msg);
            }

            var bgpage = pages.ItemU[background_page_name];
            var fgpage = application.ActivePage;

            // Set the background page
            // Check that the intended background is indeed a background page
            if (bgpage.Background == 0)
            {
                string msg = string.Format("Page \"{0}\" is not a background page", bgpage.Name);
                throw new ScriptingException(msg);
            }

            // don't allow the page to be set as a background to itself
            if (fgpage == bgpage)
            {
                string msg = string.Format("Cannot set page as its own background page");
                throw new VA.Scripting.ScriptingException(msg);
            }

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Set Background Page"))
            {
                fgpage.BackPage = bgpage;
            }
        }
        public void Delete(IList<IVisio.Shape> target_shapes, int n)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = GetTargetShapes(target_shapes);
            if (shapes.Count < 1)
            {
                return;
            }

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Delete Control"))
            {
                foreach (var shape in shapes)
                {
                    CTRLS.ControlHelper.Delete(shape, n);
                }
            }
        }
Exemple #34
0
        public void Update(ShapeSheetUpdate update, bool blastguards, bool testcircular)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            this.Client.WriteVerbose("Staring ShapeSheet Update");
            var surface = this.Client.Draw.GetDrawingSurfaceSafe();

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Update ShapeSheet Formulas"))
            {
                var internal_update = update.update;
                internal_update.BlastGuards  = blastguards;
                internal_update.TestCircular = testcircular;
                this.Client.WriteVerbose("BlastGuards={0}", blastguards);
                this.Client.WriteVerbose("TestCircular={0}", testcircular);
                internal_update.Execute(surface);
            }
            this.Client.WriteVerbose("Ending ShapeSheet Update");
        }
Exemple #35
0
        public IVisio.Shape NURBSCurve(IList <VA.Drawing.Point> controlpoints,
                                       IList <double> knots,
                                       IList <double> weights, int degree)
        {
            // flags:
            // None = 0,
            // IVisio.VisDrawSplineFlags.visSpline1D

            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var application = this.Client.VisioApplication;

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Draw NURBS Curve"))
            {
                var page  = application.ActivePage;
                var shape = page.DrawNURBS(controlpoints, knots, weights, degree);
                return(shape);
            }
        }
Exemple #36
0
        public void Delete(IList <IVisio.Shape> target_shapes, int n)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = GetTargetShapes(target_shapes);

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

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Delete Control"))
            {
                foreach (var shape in shapes)
                {
                    CTRLS.ControlHelper.Delete(shape, n);
                }
            }
        }
        public IVisio.Page Duplicate()
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var application = this.Client.VisioApplication;
            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication,"Duplicate Page"))
            {
                var doc = application.ActiveDocument;
                var pages = doc.Pages;
                var src_page = application.ActivePage;
                var new_page = pages.Add();

                var win = application.ActiveWindow;
                win.Page = src_page;
                VA.Pages.PageHelper.Duplicate(src_page, new_page);
                win.Page = new_page;
                return new_page;
            }
        }
        public void Delete(List<IVisio.Shape> target_shapes0, int index)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = GetTargetShapes(target_shapes0);
            if (shapes.Count < 1)
            {
                return;
            }

            var target_shapes = shapes.Where(shape => CONS.ConnectionPointHelper.GetCount(shape) > index);

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Delete Connection Point"))
            {
                foreach (var shape in target_shapes)
                {
                    CONS.ConnectionPointHelper.Delete(shape, index);
                }
            }
        }
Exemple #39
0
        public IVisio.Page Duplicate()
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var application = this.Client.VisioApplication;

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Duplicate Page"))
            {
                var doc      = application.ActiveDocument;
                var pages    = doc.Pages;
                var src_page = application.ActivePage;
                var new_page = pages.Add();

                var win = application.ActiveWindow;
                win.Page = src_page;
                VA.Pages.PageHelper.Duplicate(src_page, new_page);
                win.Page = new_page;
                return(new_page);
            }
        }
        public IList<IVisio.Shape> Connect(IList<IVisio.Shape> fromshapes, IList<IVisio.Shape> toshapes, IVisio.Master master)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var active_page = this.Client.VisioApplication.ActivePage;

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, undoname_connectShapes))
            {
                if (master == null)
                {
                    var connectors = ConnectorHelper.ConnectShapes(active_page, fromshapes, toshapes, null, false);
                    return connectors;
                }
                else
                {
                    var connectors = ConnectorHelper.ConnectShapes(active_page, fromshapes, toshapes, master);
                    return connectors;
                }
            }
        }
Exemple #41
0
        public IList <IVisio.Shape> Connect(IList <IVisio.Shape> fromshapes, IList <IVisio.Shape> toshapes, IVisio.Master master)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var active_page = this.Client.VisioApplication.ActivePage;

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, undoname_connectShapes))
            {
                if (master == null)
                {
                    var connectors = ConnectorHelper.ConnectShapes(active_page, fromshapes, toshapes, null, false);
                    return(connectors);
                }
                else
                {
                    var connectors = ConnectorHelper.ConnectShapes(active_page, fromshapes, toshapes, master);
                    return(connectors);
                }
            }
        }
        public IList<int> Add( IList<IVisio.Shape> target_shapes, 
            string fx,
            string fy,
            CONS.ConnectionPointType type)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = GetTargetShapes(target_shapes);
            if (shapes.Count < 1)
            {
                return new List<int>(0);
            }

            int dirx = 0;
            int diry = 0;

            var indices = new List<int>(shapes.Count);

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Add Connection Point"))
            {
                var cp = new CONS.ConnectionPointCells();
                cp.X = fx;
                cp.Y = fy;
                cp.DirX = dirx;
                cp.DirY = diry;
                cp.Type = (int)type;

                foreach (var shape in shapes)
                {
                    int index = CONS.ConnectionPointHelper.Add(shape, cp);
                    indices.Add(index);
                }
            }

            return indices;
        }
        public void Application_UndoScope_NestedInner()
        {
            var page1 = this.GetNewPage();
            var app = page1.Application;

            Assert.AreEqual(0, page1.Shapes.Count);

            // Test that inner undo doesn't affect outer
            using (var undoscope0 = new VA.Application.UndoScope(app, "UndoScope1"))
            {
                var s1 = page1.DrawRectangle(0, 0, 2, 2);
                Assert.AreEqual(1, page1.Shapes.Count);

                // create a shape and undo it
                using (var undoscope1 = new VA.Application.UndoScope(app, "UndoScope2"))
                {
                    var s2 = page1.DrawRectangle(1, 1, 3, 3);
                    Assert.AreEqual(2, page1.Shapes.Count);
                }
                app.Undo();
            }
            Assert.AreEqual(1, page1.Shapes.Count);
            page1.Delete(0);
        }
        private void buttonScrambleText_Click(object sender, RibbonControlEventArgs e)
        {
            var app = Globals.ThisAddIn.Application;
            var doc = app.ActiveDocument;
            if (doc == null)
            {
                return;
            }

            if (doc.Type != IVisio.VisDocumentTypes.visTypeDrawing )
            {
                MessageBox.Show("Currently Active Document is not a Drawing");
                return;
            }

            var activewindow = app.ActiveWindow;
            var sb = new StringBuilder();
            var pages = doc.Pages.AsEnumerable().ToList();

            using (var scope = new VA.Application.UndoScope(app, "Scramble Text"))
            {
                // Begin Undo Scope
                doc.Company = VPTRibbon.Scramble(sb, doc.Company);
                doc.Category = VPTRibbon.Scramble(sb,doc.Category);
                doc.Title = VPTRibbon.Scramble(sb, doc.Title);
                doc.Subject = VPTRibbon.Scramble(sb, doc.Subject);
                doc.Creator = VPTRibbon.Scramble(sb, doc.Creator);
                doc.Manager = VPTRibbon.Scramble(sb, doc.Manager);
                doc.Keywords = VPTRibbon.Scramble(sb, doc.Keywords);
                foreach (var page in pages)
                {
                    activewindow.Page = page;
                    var shapes = page.Shapes.AsEnumerable().ToList();
                    foreach (var shape in shapes)
                    {
                        VPTRibbon.Scramble(sb, shape);

                        var shape_shapes = shape.Shapes;
                        if (shape_shapes!=null && shape_shapes.Count>0)
                        {
                            foreach (var nested_shape in VA.Shapes.ShapeHelper.GetNestedShapes(shape))
                            {
                                VPTRibbon.Scramble(sb,nested_shape);                                
                            }
                        }
                    }
                }
                // End Undo Scope
            }
        }
        public void SetBackgroundPage(string background_page_name)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            if (background_page_name == null)
            {
                throw new System.ArgumentNullException("background_page_name");
            }

            var application = this.Client.VisioApplication;
            var active_document = application.ActiveDocument;
            var pages = active_document.Pages;
            var names = new HashSet<string>(pages.GetNamesU());
            if (!names.Contains(background_page_name))
            {
                string msg = string.Format("Could not find page with name \"{0}\"", background_page_name);
                throw new VA.Scripting.ScriptingException(msg);
            }

            var bgpage = pages.ItemU[background_page_name];
            var fgpage = application.ActivePage;

            // Set the background page
            // Check that the intended background is indeed a background page
            if (bgpage.Background == 0)
            {
                string msg = string.Format("Page \"{0}\" is not a background page", bgpage.Name);
                throw new ScriptingException(msg);
            }

            // don't allow the page to be set as a background to itself
            if (fgpage == bgpage)
            {
                string msg = string.Format("Cannot set page as its own background page");
                throw new VA.Scripting.ScriptingException(msg);
            }

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication,"Set Background Page"))
            {
                fgpage.BackPage = bgpage;
            }
        }
        public IList<IVisio.Shape> Table(System.Data.DataTable datatable,
            IList<double> widths,
            IList<double> heights,
            VA.Drawing.Size cellspacing)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

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

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

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

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

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

            var application = this.Client.VisioApplication;
            var active_document = application.ActiveDocument;
            var pages = active_document.Pages;

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

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

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

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

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

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Draw Table"))
            {
                layout.Render(page);
                page.ResizeToFitContents();
            }

            var page_shapes = page.Shapes;
            var shapes = layout.Nodes.Select(n => n.Shape).ToList();
            return shapes;
        }
 public IVisio.Shape Rectangle(double x0, double y0, double x1, double y1)
 {
     var surface = this.GetDrawingSurfaceSafe();
     using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Draw Rectangle"))
     {
         var shape = surface.DrawRectangle(x0, y0, x1, y1);
         return shape;
     }
 }
 public IVisio.Shape PolyLine(IList<VA.Drawing.Point> points)
 {
     var surface = this.GetDrawingSurfaceSafe();
     using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Draw PolyLine"))
     {
         var shape = surface.DrawPolyLine(points);
         return shape;
     }
 }
        public IVisio.Shape PieSlice(VA.Drawing.Point center,
            double radius,
            double start_angle,
            double end_angle)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var application = this.Client.VisioApplication;
            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Draw Pie Slice"))
            {
                var active_page = application.ActivePage;
                var slice = new VA.Models.Charting.PieSlice(center, radius, start_angle, end_angle);
                var shape = slice.Render(active_page);
                return shape;
            }
        }
        public void Set(IList<IVisio.Shape> target_shapes, string name, CP.CustomPropertyCells customprop)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            if (customprop == null)
            {
                throw new System.ArgumentNullException("customprop");
            }

            var shapes = GetTargetShapes(target_shapes);
            if (shapes.Count < 1)
            {
                return;
            }

            var application = this.Client.VisioApplication;
            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Set Custom Property"))
            {
                foreach (var shape in shapes)
                {
                    CP.CustomPropertyHelper.Set(shape, name, customprop);
                }
            }
        }
        public void Duplicate(int n)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            if (n < 1)
            {
                throw new System.ArgumentOutOfRangeException("n");
            }
            if (!this.Client.HasSelectedShapes())
            {
                return;
            }

            // TODO: Add ability to duplicate all the selected shapes, not just the first one
            // this dupicates exactly 1 shape N - times what it
            // it should do is duplicate all M selected shapes N times so that M*N shapes are created

            var application = this.Client.VisioApplication;
            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, string.Format("Duplicate Shape {0} Times", n)))
            {
                var active_window = application.ActiveWindow;
                var selection = active_window.Selection;
                var active_page = application.ActivePage;
                DrawCommands.CreateDuplicates(active_page, selection[1], n);
            }
        }
        public void ResizeToFitContents(VA.Drawing.Size bordersize, bool zoom_to_page)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var application = this.Client.VisioApplication;
            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication,"Resize Page to Fit Contents"))
            {
                var active_page = application.ActivePage;
                active_page.ResizeToFitContents(bordersize);
                if (zoom_to_page)
                {
                    this.Client.View.Zoom(VA.Scripting.Zoom.ToPage);
                }
            }
        }
        public void Set(IList<IVisio.Shape> target_shapes, UserDefinedCell userdefinedcell)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = GetTargetShapes(target_shapes);
            if (shapes.Count < 1)
            {
                return;
            }

            if (userdefinedcell == null)
            {
                throw new System.ArgumentNullException("userdefinedcell");
            }

            var application = this.Client.VisioApplication;
            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication,"Set User-Defined Cell"))
            {
                foreach (var shape in shapes)
                {
                    UserDefinedCellsHelper.Set(shape, userdefinedcell.Name, userdefinedcell.Value.Formula.Value, userdefinedcell.Prompt.Formula.Value);
                }
            }
        }
        public void SetSize(VA.Drawing.Size new_size)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var application = this.Client.VisioApplication;
            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication,"Set Page Size"))
            {
                var active_page = application.ActivePage;
                var page_sheet = active_page.PageSheet;
                var update = new VA.ShapeSheet.Update(2);
                update.SetFormula(VA.ShapeSheet.SRCConstants.PageWidth, new_size.Width);
                update.SetFormula(VA.ShapeSheet.SRCConstants.PageHeight, new_size.Height);
                update.Execute(page_sheet);
            }
        }
        public void Grid(GRIDLAYOUT.GridLayout layout)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            //Create a new page to hold the grid
            var application = this.Client.VisioApplication;
            var page = application.ActivePage;
            layout.PerformLayout();

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Draw Grid"))
            {
                layout.Render(page);
            }
        }
        public void ResetOrigin(IVisio.Page page)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var application = this.Client.VisioApplication;
            if (page == null)
            {
                page = application.ActivePage;
            }

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

            update.SetFormula(VA.ShapeSheet.SRCConstants.XGridOrigin, "0.0");
            update.SetFormula(VA.ShapeSheet.SRCConstants.YGridOrigin, "0.0");
            update.SetFormula(VA.ShapeSheet.SRCConstants.XRulerOrigin, "0.0");
            update.SetFormula(VA.ShapeSheet.SRCConstants.YRulerOrigin, "0.0");

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication,"Reset Page Origin"))
            {
                update.Execute(page.PageSheet);
            }
        }
        public IVisio.Shape NURBSCurve(IList<VA.Drawing.Point> controlpoints,
            IList<double> knots,
            IList<double> weights, int degree)
        {
            // flags:
            // None = 0,
            // IVisio.VisDrawSplineFlags.visSpline1D

            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var application = this.Client.VisioApplication;
            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Draw NURBS Curve"))
            {

                var page = application.ActivePage;
                var shape = page.DrawNURBS(controlpoints, knots, weights, degree);
                return shape;
            }
        }
 public IVisio.Shape Oval(VA.Drawing.Point center, double radius)
 {
     var surface = this.GetDrawingSurfaceSafe();
     using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Draw Oval"))
     {
         var shape = surface.DrawOval(center, radius);
         return shape;
     }
 }
        public IVisio.Page New(VA.Drawing.Size? size, bool isbackgroundpage)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var application = this.Client.VisioApplication;
            var active_document = application.ActiveDocument;
            var pages = active_document.Pages;
            IVisio.Page page = pages.Add();

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication,"New Page"))
            {
                if (size.HasValue)
                {
                    this.Client.WriteVerbose("Setting page size to {0}", size.Value);
                    this.SetSize(size.Value);
                }

                if (isbackgroundpage)
                {
                    page.Background = 1;
                }
            }

            return page;
        }
        public void SetOrientation(VA.Pages.PrintPageOrientation orientation)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var application = this.Client.VisioApplication;

            var active_page = application.ActivePage;

            if (orientation != VA.Pages.PrintPageOrientation.Landscape && orientation != VA.Pages.PrintPageOrientation.Portrait)
            {
                throw new System.ArgumentOutOfRangeException("orientation", "must be either Portrait or Landscape");
            }

            var old_orientation = GetOrientation(active_page);

            if (old_orientation == orientation)
            {
                // don't need to do anything
                return;
            }

            var old_size = this.GetSize();

            double new_height = old_size.Width;
            double new_width = old_size.Height;

            var update = new VA.ShapeSheet.Update(3);
            update.SetFormula(VA.ShapeSheet.SRCConstants.PageWidth, new_width);
            update.SetFormula(VA.ShapeSheet.SRCConstants.PageHeight, new_height);
            update.SetFormula(VA.ShapeSheet.SRCConstants.PrintPageOrientation, (int)orientation);

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication,"Set Page Orientation"))
            {
                update.Execute(active_page.PageSheet);
            }
        }