Esempio n. 1
0
        public IList <int> Add(IList <IVisio.Shape> target_shapes, CTRLS.ControlCells ctrl)
        {
            this.Client.Application.AssertApplicationAvailable();
            this.Client.Document.AssertDocumentAvailable();

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

            var shapes = this.GetTargetShapes(target_shapes);

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


            var control_indices = new List <int>();
            var application     = this.Client.Application.Get();

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

            return(control_indices);
        }
        public static int Set(
            IVisio.Shape shape,
            short row,
            ControlCells ctrl)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            if (!ctrl.XDynamics.Formula.HasValue)
            {
                ctrl.XDynamics = $"Controls.Row_{row + 1}";
            }

            if (!ctrl.YDynamics.Formula.HasValue)
            {
                ctrl.YDynamics = $"Controls.Row_{row + 1}.Y";
            }

            var update = new ShapeSheet.Update();
            update.SetFormulas(ctrl, row);
            update.Execute(shape);

            return row;
        }
        public static int Set(
            IVisio.Shape shape,
            short row,
            ControlCells ctrl)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }


            if (!ctrl.XDynamics.Formula.HasValue)
            {
                ctrl.XDynamics = $"Controls.Row_{row + 1}";
            }

            if (!ctrl.YDynamics.Formula.HasValue)
            {
                ctrl.YDynamics = $"Controls.Row_{row + 1}.Y";
            }

            var update = new ShapeSheet.Update();
            update.SetFormulas(ctrl, row);
            update.Execute(shape);

            return row;
        }
Esempio n. 4
0
        public static int Set(IVisio.Shape shape, short row, ControlCells ctrl)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }


            if (!ctrl.XDynamics.Formula.HasValue)
            {
                ctrl.XDynamics = string.Format("Controls.Row_{0}", row + 1);
            }

            if (!ctrl.YDynamics.Formula.HasValue)
            {
                ctrl.YDynamics = string.Format("Controls.Row_{0}.Y", row + 1);
            }

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

            ctrl.SetFormulas(writer, row);

            writer.Commit(shape);

            return(row);
        }
Esempio n. 5
0
        public List <int> Add(TargetShapes targets, VACONTROL.ControlCells ctrl)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

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

            targets = targets.ResolveShapes(this._client);

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


            var control_indices = new List <int>();

            using (var undoscope = this._client.Application.NewUndoScope("Add Control"))
            {
                foreach (var shape in targets.Shapes)
                {
                    int ci = VACONTROL.ControlHelper.Add(shape, ctrl);
                    control_indices.Add(ci);
                }
            }

            return(control_indices);
        }
Esempio n. 6
0
        public static int Set(
            IVisio.Shape shape,
            short row,
            VACONTROL.ControlCells ctrl)
        {
            if (shape == null)
            {
                throw new ArgumentNullException("shape");
            }


            if (!ctrl.XDynamics.Formula.HasValue)
            {
                ctrl.XDynamics = String.Format("Controls.Row_{0}", row + 1);
            }

            if (!ctrl.YDynamics.Formula.HasValue)
            {
                ctrl.YDynamics = String.Format("Controls.Row_{0}.Y", row + 1);
            }

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

            update.SetFormulas(ctrl, row);
            update.Execute(shape);

            return(row);
        }
        public static int Add(IVisio.Shape shape)
        {
            if (shape == null)
            {
                throw new ArgumentNullException("shape");
            }

            var ctrl = new VACONTROL.ControlCells();

            return Add(shape, ctrl);
        }
Esempio n. 8
0
        public static int Add(IVisio.Shape shape)
        {
            if (shape == null)
            {
                throw new ArgumentNullException("shape");
            }

            var ctrl = new VACONTROL.ControlCells();

            return(Add(shape, ctrl));
        }
        public static int Add(IVisio.Shape shape)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            var ctrl = new ControlCells();

            return ControlHelper.Add(shape, ctrl);
        }
Esempio n. 10
0
        public static int Add(IVisio.Shape shape)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            var ctrl = new ControlCells();

            return ControlHelper.Add(shape, ctrl);
        }
        public void Scripting_Controls_Scenarios()
        {
            var client = this.GetScriptingClient();

            client.Document.New();
            client.Page.New(new VisioAutomation.Drawing.Size(4, 4), false);

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

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

            var s3 = client.Draw.Rectangle(1.5, 3.5, 2, 4.0);

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

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

            var controls0      = client.Control.Get(targets);
            int found_controls = controls0.Count;

            Assert.AreEqual(3, controls0.Count);
            Assert.AreEqual(0, controls0[s1].Count);
            Assert.AreEqual(0, controls0[s2].Count);
            Assert.AreEqual(0, controls0[s3].Count);

            var ctrl = new VACONTROL.ControlCells();

            ctrl.X = "Width*0.5";
            ctrl.Y = "0";
            client.Control.Add(targets, ctrl);

            var controls1 = client.Control.Get(targets);

            Assert.AreEqual(3, controls1.Count);
            Assert.AreEqual(1, controls1[s1].Count);
            Assert.AreEqual(1, controls1[s2].Count);
            Assert.AreEqual(1, controls1[s3].Count);

            client.Control.Delete(targets, 0);
            var controls2 = client.Control.Get(targets);

            Assert.AreEqual(3, controls0.Count);
            Assert.AreEqual(0, controls2[s1].Count);
            Assert.AreEqual(0, controls2[s2].Count);
            Assert.AreEqual(0, controls2[s3].Count);

            client.Document.Close(true);
        }
Esempio n. 12
0
            public ControlCells GetCells(VA.ShapeSheet.CellData <double>[] row)
            {
                var cells = new ControlCells();

                cells.CanGlue   = row[CanGlue.Ordinal].ToInt();
                cells.Tip       = row[Tip.Ordinal].ToInt();
                cells.X         = row[X.Ordinal];
                cells.Y         = row[Y.Ordinal];
                cells.YBehavior = row[YBehavior.Ordinal].ToInt();
                cells.XBehavior = row[XBehavior.Ordinal].ToInt();
                cells.XDynamics = row[XDynamics.Ordinal].ToInt();
                cells.YDynamics = row[YDynamics.Ordinal].ToInt();
                return(cells);
            }
Esempio n. 13
0
        public static int Add(IVisio.Shape shape, ControlCells ctrl)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            short row = shape.AddRow((short)IVisio.VisSectionIndices.visSectionControls,
                                     (short)IVisio.VisRowIndices.visRowLast,
                                     (short)IVisio.VisRowTags.visTagDefault);

            ControlHelper.Set(shape, row, ctrl);

            return(row);
        }
        public static int Add(
            IVisio.Shape shape,
            ControlCells ctrl)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            short row = shape.AddRow((short)IVisio.VisSectionIndices.visSectionControls,
                                     (short)IVisio.VisRowIndices.visRowLast,
                                     (short)IVisio.VisRowTags.visTagDefault);

            ControlHelper.Set(shape, row, ctrl);

            return row;
        }
        public void Scripting_Controls_Scenarios()
        {
            var client = this.GetScriptingClient();
            client.Document.New();
            client.Page.New(new VisioAutomation.Drawing.Size(4, 4), false);

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

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

            var s3 = client.Draw.Rectangle(1.5, 3.5, 2, 4.0);

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

            var controls0 = client.Control.Get(null);
            int found_controls = controls0.Count;
            Assert.AreEqual(3, controls0.Count);
            Assert.AreEqual(0, controls0[s1].Count);
            Assert.AreEqual(0, controls0[s2].Count);
            Assert.AreEqual(0, controls0[s3].Count);

            var ctrl = new VACONTROL.ControlCells();
            ctrl.X = "Width*0.5";
            ctrl.Y = "0";
            client.Control.Add(null,ctrl);

            var controls1 = client.Control.Get(null);
            Assert.AreEqual(3, controls1.Count);
            Assert.AreEqual(1, controls1[s1].Count);
            Assert.AreEqual(1, controls1[s2].Count);
            Assert.AreEqual(1, controls1[s3].Count);

            client.Control.Delete(null,0);
            var controls2 = client.Control.Get(null);
            Assert.AreEqual(3, controls0.Count);
            Assert.AreEqual(0, controls2[s1].Count);
            Assert.AreEqual(0, controls2[s2].Count);
            Assert.AreEqual(0, controls2[s3].Count);

            client.Document.Close(true);
        }
Esempio n. 16
0
 public ControlCells GetCells(VA.ShapeSheet.CellData<double>[] row)
 {
     var cells = new ControlCells();
     cells.CanGlue = row[CanGlue.Ordinal].ToInt();
     cells.Tip = row[Tip.Ordinal].ToInt();
     cells.X = row[X.Ordinal];
     cells.Y = row[Y.Ordinal];
     cells.YBehavior = row[YBehavior.Ordinal].ToInt();
     cells.XBehavior = row[XBehavior.Ordinal].ToInt();
     cells.XDynamics = row[XDynamics.Ordinal].ToInt();
     cells.YDynamics = row[YDynamics.Ordinal].ToInt();
     return cells;
 }
        public void ShapeSheet_Query_NonExistentSections()
        {
            var page1 = this.GetNewPage();
            var s1 = page1.DrawRectangle(0, 0, 2, 2);
            var s2 = page1.DrawRectangle(2, 1, 3, 3);
            var s3 = page1.DrawRectangle(3, 1, 4, 2);
            var s4 = page1.DrawRectangle(4, -1, 5, 1);

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

            // First verify that none of the shapes have the controls section locally or otherwise
            foreach (var s in shapes)
            {
                Assert.AreEqual(0, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 1]);
                Assert.AreEqual(0, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 0]);
            }

            // Try to retrieve the control cells rows for each shape, every shape should return zero rows
            foreach (var s in shapes)
            {
                var r1 = VACONT.ControlCells.GetCells(s);
                Assert.AreEqual(0,r1.Count);
            }

            // Try to retrieve the control cells rows for all shapes at once, every shape should return a collection of zero rows
            var r2 = VACONT.ControlCells.GetCells(page1, shapeids);
            Assert.AreEqual(shapes.Count(),r2.Count);
            for (int i = 0; i < shapes.Count();i++)
            {
                Assert.AreEqual(0,r2[i].Count);
            }

            // Add a Controls row to shape2
            var cc = new VACONT.ControlCells();
            VACONT.ControlHelper.Add(s2, cc);

            // Now verify that none of the shapes *except s2* have the controls section locally or otherwise
            foreach (var s in shapes)
            {
                if (s != s2)
                {
                    Assert.AreEqual(0, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 1]);
                    Assert.AreEqual(0, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 0]);
                }
                else
                {
                    Assert.AreEqual(-1, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 1]);
                    Assert.AreEqual(-1, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 0]);
                }
            }

            // Try to retrieve the control cells rows for each shape, every shape should return zero rows *except for s2*
            foreach (var s in shapes)
            {
                if (s != s2)
                {
                    var r1 = VACONT.ControlCells.GetCells(s);
                    Assert.AreEqual(0, r1.Count);
                }
                else
                {
                    var r1 = VACONT.ControlCells.GetCells(s);
                    Assert.AreEqual(1, r1.Count);
                }
            }

            // Try to retrieve the control cells rows for all shapes at once, every shape *except s2* should return a collection of zero rows
            var r3 = VACONT.ControlCells.GetCells(page1, shapeids);
            Assert.AreEqual(shapes.Count(), r3.Count);
            for (int i = 0; i < shapes.Count(); i++)
            {
                if (shapes[i] != s2)
                {
                    Assert.AreEqual(0, r3[i].Count);
                }
                else
                {
                    Assert.AreEqual(1, r3[i].Count);
                }
            }

            page1.Delete(0);
        }
Esempio n. 18
0
        public void ShapeSheet_Query_NonExistentSections()
        {
            var page1 = GetNewPage();
            var s1    = page1.DrawRectangle(0, 0, 2, 2);
            var s2    = page1.DrawRectangle(2, 1, 3, 3);
            var s3    = page1.DrawRectangle(3, 1, 4, 2);
            var s4    = page1.DrawRectangle(4, -1, 5, 1);

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

            // First verify that none of the shapes have the controls section locally or otherwise
            foreach (var s in shapes)
            {
                Assert.AreEqual(0, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 1]);
                Assert.AreEqual(0, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 0]);
            }

            // Try to retrieve the control cells rows for each shape, every shape should return zero rows
            foreach (var s in shapes)
            {
                var r1 = VACONT.ControlCells.GetCells(s);
                Assert.AreEqual(0, r1.Count);
            }

            // Try to retrieve the control cells rows for all shapes at once, every shape should return a collection of zero rows
            var r2 = VACONT.ControlCells.GetCells(page1, shapeids);

            Assert.AreEqual(shapes.Count(), r2.Count);
            for (int i = 0; i < shapes.Count(); i++)
            {
                Assert.AreEqual(0, r2[i].Count);
            }

            // Add a Controls row to shape2
            var cc = new VACONT.ControlCells();

            VACONT.ControlHelper.Add(s2, cc);

            // Now verify that none of the shapes *except s2* have the controls section locally or otherwise
            foreach (var s in shapes)
            {
                if (s != s2)
                {
                    Assert.AreEqual(0, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 1]);
                    Assert.AreEqual(0, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 0]);
                }
                else
                {
                    Assert.AreEqual(-1, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 1]);
                    Assert.AreEqual(-1, s.SectionExists[(short)IVisio.VisSectionIndices.visSectionControls, 0]);
                }
            }

            // Try to retrieve the control cells rows for each shape, every shape should return zero rows *except for s2*
            foreach (var s in shapes)
            {
                if (s != s2)
                {
                    var r1 = VACONT.ControlCells.GetCells(s);
                    Assert.AreEqual(0, r1.Count);
                }
                else
                {
                    var r1 = VACONT.ControlCells.GetCells(s);
                    Assert.AreEqual(1, r1.Count);
                }
            }

            // Try to retrieve the control cells rows for all shapes at once, every shape *except s2* should return a collection of zero rows
            var r3 = VACONT.ControlCells.GetCells(page1, shapeids);

            Assert.AreEqual(shapes.Count(), r3.Count);
            for (int i = 0; i < shapes.Count(); i++)
            {
                if (shapes[i] != s2)
                {
                    Assert.AreEqual(0, r3[i].Count);
                }
                else
                {
                    Assert.AreEqual(1, r3[i].Count);
                }
            }

            page1.Delete(0);
        }