Example #1
0
        protected override void ProcessRecord()
        {
            var targetdoc = new VisioScripting.TargetDocument(this.Document);

            this.Client.Output.WriteVerbose("Creating a new page");
            var page = this.Client.Page.NewPage(targetdoc, null, false);

            if (this.Name != null)
            {
                if (this.Name.Length == 0)
                {
                    throw new System.ArgumentException("Name can't be empty");
                }

                string n = this.Name.Trim();

                if (n.Length == 0)
                {
                    throw new System.ArgumentException("Name can't be empty");
                }

                this.Client.Output.WriteVerbose("Setting page name \"{0}\"", n);
                page.NameU = n;
            }

            if (this.Width > 0 || this.Height > 0)
            {
                // width and height are used and there isn't a PageCells object
                // then create one
                this.Cells = this.Cells ?? new Models.PageCells();
                if (this.Width > 0)
                {
                    this.Cells.PageWidth = this.Width.ToString(CultureInfo.InvariantCulture);
                }
                if (this.Height > 0)
                {
                    this.Cells.PageHeight = this.Height.ToString(CultureInfo.InvariantCulture);
                }
            }

            if (this.Cells != null)
            {
                var targetpage_shapesheet   = page.PageSheet;
                int targetpage_shapesheetid = targetpage_shapesheet.ID;

                var writer = new VisioAutomation.ShapeSheet.Writers.SidSrcWriter();
                writer.BlastGuards  = true;
                writer.TestCircular = true;
                this.Cells.Apply(writer, (short)targetpage_shapesheetid);

                this.Client.Output.WriteVerbose("Updating Cells for new page");
                writer.Commit(page, VisioAutomation.ShapeSheet.CellValueType.Formula);
            }

            this.WriteObject(page);
        }
Example #2
0
        public void Render(IVisio.Page page)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException(nameof(page));
            }

            // First handle any page properties
            if (this.Name != null)
            {
                page.NameU = this.Name;
            }

            this.VisioPage = page;
            var page_sheet = page.PageSheet;
            var app        = page.Application;

            using (var perfscope = new RenderPerformanceScope(app, this.RenderPerformanceSettings))
            {
                if (this.Size.HasValue)
                {
                    this.PageFormatCells.Height = this.Size.Value.Height;
                    this.PageFormatCells.Width  = this.Size.Value.Width;
                }

                var writer = new VASS.Writers.SidSrcWriter();
                writer.SetValues((short)page_sheet.ID, this.PageFormatCells);
                writer.SetValues((short)page_sheet.ID, this.PageLayoutCells);
                writer.Commit(page, ShapeSheet.CellValueType.Formula);

                // Then render the shapes
                this.Shapes.Render(page);

                // Perform any additional layout
                if (this.Layout != null)
                {
                    this.Layout.Apply(page);
                }

                // Optionally, perform page resizing to fit contents
                if (this.ResizeToFit)
                {
                    if (this.ResizeToFitMargin.HasValue)
                    {
                        page.ResizeToFitContents(this.ResizeToFitMargin.Value);
                    }
                    else
                    {
                        page.ResizeToFitContents();
                    }
                }
            }
        }
        internal void __SetCells(TargetShapes targetshapes, VASS.CellGroups.CellGroup cellgroup, IVisio.Page page)
        {
            targetshapes = targetshapes.Resolve(this._client);
            var targetshapeids = targetshapes.ToShapeIDs();
            var writer         = new VASS.Writers.SidSrcWriter();

            foreach (var shapeid in targetshapeids)
            {
                var cells_mr = (VASS.CellGroups.CellGroup)cellgroup;
                writer.SetValues((short)shapeid, cells_mr, 0);
            }

            writer.Commit(page, VASS.CellValueType.Formula);
        }
        protected override void ProcessRecord()
        {
            var targetpages = new VisioScripting.TargetPages(this.Page).ResolveToPages(this.Client);

            if (targetpages.Pages.Count < 1)
            {
                return;
            }

            if (this.Cells == null || this.Cells.Length < 1)
            {
                return;
            }

            this.Client.Output.WriteVerbose("BlastGuards: {0}", this.BlastGuards);
            this.Client.Output.WriteVerbose("TestCircular: {0}", this.TestCircular);

            using (var undoscope = this.Client.Undo.NewUndoScope(nameof(SetVisioPageCells)))
            {
                foreach (int i in Enumerable.Range(0, targetpages.Pages.Count))
                {
                    int page_index  = i;
                    int cells_index = i % this.Cells.Length;

                    var page  = targetpages.Pages[page_index];
                    var cells = this.Cells[cells_index];

                    this.Client.Output.WriteVerbose("Start Update Page Name={0}", page.NameU);

                    var shapesheet = page.PageSheet;
                    int shapeid    = shapesheet.ID;

                    var writer = new VisioAutomation.ShapeSheet.Writers.SidSrcWriter();
                    writer.BlastGuards  = this.BlastGuards;
                    writer.TestCircular = this.TestCircular;
                    cells.Apply(writer, (short)shapeid);
                    writer.Commit(page, VisioAutomation.ShapeSheet.CellValueType.Formula);

                    this.Client.Output.WriteVerbose("End Update Page Name={0}", page.NameU);
                }
            }
        }
        public void ShapeSheet_Writer_Formulas_MultipleShapes()
        {
            var page1 = this.GetNewPage();

            var shape1 = page1.DrawRectangle(-1, -1, 0, 0);
            var shape2 = page1.DrawRectangle(-1, -1, 0, 0);
            var shape3 = page1.DrawRectangle(-1, -1, 0, 0);


            // Set the formulas
            var writer = new VASS.Writers.SidSrcWriter();

            writer.SetValue(shape1.ID16, XFormPinX, 0.5);
            writer.SetValue(shape1.ID16, XFormPinY, 0.5);
            writer.SetValue(shape2.ID16, XFormPinX, 1.5);
            writer.SetValue(shape2.ID16, XFormPinY, 1.5);
            writer.SetValue(shape3.ID16, XFormPinX, 2.5);
            writer.SetValue(shape3.ID16, XFormPinY, 2.5);

            writer.Commit(page1, VASS.CellValueType.Formula);

            // Verify that the formulas were set
            var query    = new VASS.Query.CellQuery();
            var col_pinx = query.Columns.Add(XFormPinX, nameof(XFormPinX));
            var col_piny = query.Columns.Add(XFormPinY, nameof(XFormPinY));

            var shapeids = new[] { shape1.ID, shape2.ID, shape3.ID };

            var data_formulas = query.GetFormulas(page1, shapeids);
            var data_results  = query.GetResults <double>(page1, shapeids);

            AssertUtil.AreEqual(("0.5 in", 0.5), (data_formulas[0][col_pinx], data_results[0][col_pinx]));
            AssertUtil.AreEqual(("0.5 in", 0.5), (data_formulas[0][col_piny], data_results[0][col_piny]));
            AssertUtil.AreEqual(("1.5 in", 1.5), (data_formulas[1][col_pinx], data_results[1][col_pinx]));
            AssertUtil.AreEqual(("1.5 in", 1.5), (data_formulas[1][col_piny], data_results[1][col_piny]));
            AssertUtil.AreEqual(("2.5 in", 2.5), (data_formulas[2][col_pinx], data_results[2][col_pinx]));
            AssertUtil.AreEqual(("2.5 in", 2.5), (data_formulas[2][col_piny], data_results[2][col_piny]));

            page1.Delete(0);
        }
        public void SetLockCells(TargetShapes targetshapes, VA.Shapes.LockCells lockcells)
        {
            targetshapes = targetshapes.Resolve(this._client);
            if (targetshapes.Shapes.Count < 1)
            {
                return;
            }

            var page           = targetshapes.Shapes[0].ContainingPage;
            var targetshapeids = targetshapes.ToShapeIDs();
            var writer         = new VASS.Writers.SidSrcWriter();

            foreach (int shapeid in targetshapeids)
            {
                writer.SetValues((short)shapeid, lockcells);
            }

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetLockCells)))
            {
                writer.Commit(page, VASS.CellValueType.Formula);
            }
        }
Example #7
0
        protected override void ProcessRecord()
        {
            if (this.Cells == null)
            {
                return;
            }

            if (this.Cells.Length < 1)
            {
                return;
            }

            var targetpages = new VisioScripting.TargetPages(this.Pages);

            this.Client.Output.WriteVerbose("BlastGuards: {0}", this.BlastGuards);
            this.Client.Output.WriteVerbose("TestCircular: {0}", this.TestCircular);

            using (var undoscope = this.Client.Undo.NewUndoScope(nameof(SetVisioPageCells)))
            {
                for (int i = 0; i < targetpages.Pages.Count; i++)
                {
                    var targetpage = targetpages.Pages[i];
                    this.Client.Output.WriteVerbose("Start Update Page Name={0}", targetpage.NameU);

                    var targetpage_shapesheet   = targetpage.PageSheet;
                    int targetpage_shapesheetid = targetpage_shapesheet.ID;
                    var target_cells            = this.Cells[i % this.Cells.Length];
                    var writer = new VisioAutomation.ShapeSheet.Writers.SidSrcWriter();
                    writer.BlastGuards  = this.BlastGuards;
                    writer.TestCircular = this.TestCircular;
                    target_cells.Apply(writer, (short)targetpage_shapesheetid);
                    writer.Commit(targetpage, VisioAutomation.ShapeSheet.CellValueType.Formula);

                    this.Client.Output.WriteVerbose("End Update Page Name={0}", targetpage.NameU);
                }
            }
        }