Example #1
0
        private void connect(IVisio.Shape a, IVisio.Shape b, bool a_arrow, bool b_arrow)
        {
            var page = a.ContainingPage;
            var connectors_stencil = page.Application.Documents.OpenStencil("connec_u.vss");
            var connectors_masters = connectors_stencil.Masters;

            var dcm = connectors_masters["Dynamic Connector"];

            var c1 = page.Drop(dcm, new VA.Drawing.Point(-2, -2));

            VACXN.ConnectorHelper.ConnectShapes(a, b, c1);

            //a.AutoConnect(b, connect_dir_none, null);

            if (a_arrow || b_arrow)
            {
                var update = new VA.ShapeSheet.Update();
                if (a_arrow)
                {
                    update.SetFormula(c1.ID16, VA.ShapeSheet.SRCConstants.BeginArrow, "13");
                }
                if (b_arrow)
                {
                    update.SetFormula(c1.ID16, VA.ShapeSheet.SRCConstants.EndArrow, "13");
                }
                update.Execute(page);
            }
        }
        public static int Add(
            IVisio.Shape shape,
            ConnectionPointCells cp)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException("shape");
            }

            if (!cp.X.Formula.HasValue)
            {
                throw new System.ArgumentException("Must provide an X Formula");
            }

            if (!cp.Y.Formula.HasValue)
            {
                throw new System.ArgumentException("Must provide an Y Formula");
            }

            var n = shape.AddRow((short)IVisio.VisSectionIndices.visSectionConnectionPts,
                                 (short)IVisio.VisRowIndices.visRowLast,
                                 (short)IVisio.VisRowTags.visTagCnnctPt);

            var update = new VA.ShapeSheet.Update();
            update.SetFormulas(cp,n);
            update.Execute(shape);

            return n;
        }
Example #3
0
        public void PasteFormat(IVisio.Page page, IList <int> shapeids, FormatCategory category, bool applyformulas)
        {
            var update = new VA.ShapeSheet.Update();

            foreach (var shape_id in shapeids)
            {
                foreach (var cellrec in this.Cells)
                {
                    if (!cellrec.MatchesCategory(category))
                    {
                        continue;
                    }

                    var sidsrc = new VA.ShapeSheet.SIDSRC((short)shape_id, cellrec.SRC);

                    if (applyformulas)
                    {
                        update.SetFormula(sidsrc, cellrec.Formula);
                    }
                    else
                    {
                        if (cellrec.Result != null)
                        {
                            update.SetFormula(sidsrc, cellrec.Result);
                        }
                    }
                }
            }

            update.Execute(page);
        }
        private static void TestResize(IVisio.Document doc, 
            VA.Drawing.Size bottomleft_margin, 
            VA.Drawing.Size upperright_margin, 
            VA.Drawing.Size shape_size, 
            VA.Drawing.Size padding_size,  
            double expected_pinx, 
            double expected_piny)
        {
            var page = doc.Pages.Add();

            var pagecells = new VA.Pages.PageCells();
            pagecells.PageTopMargin = upperright_margin.Height;
            pagecells.PageBottomMargin = bottomleft_margin.Height;
            pagecells.PageLeftMargin = bottomleft_margin.Width;
            pagecells.PageRightMargin = upperright_margin.Width;

            var pageupdate = new VA.ShapeSheet.Update();
            pageupdate.SetFormulas(pagecells);
            pageupdate.Execute(page.PageSheet);

            var shape = page.DrawRectangle(5, 5, 5 + shape_size.Width, 5+shape_size.Height);
            page.ResizeToFitContents(padding_size);
            var xform = VA.Shapes.XFormCells.GetCells(shape);
            AssertVA.AreEqual(expected_pinx, expected_piny, xform.Pin(), 0.1);
            page.Delete(0);
        }
Example #5
0
        public short Render(IVisio.Shape shape)
        {
            short sec_index = GeometryHelper.AddSection(shape);
            short row_count = shape.RowCount[sec_index];

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

            var src_nofill = VA.ShapeSheet.SRCConstants.Geometry_NoFill.ForSectionAndRow(sec_index, 0);
            var src_noline = VA.ShapeSheet.SRCConstants.Geometry_NoLine.ForSectionAndRow(sec_index, 0);
            var src_noshow = VA.ShapeSheet.SRCConstants.Geometry_NoShow.ForSectionAndRow(sec_index, 0);
            var src_nosnap = VA.ShapeSheet.SRCConstants.Geometry_NoSnap.ForSectionAndRow(sec_index, 0);

            //var src_noquickdrag = VA.ShapeSheet.SRCConstants.Geometry_NoQuickDrag.ForSectionAndRow(sec_index, 0);

            update.SetFormulaIgnoreNull(src_nofill, this.NoFill);
            update.SetFormulaIgnoreNull(src_noline, this.NoLine);
            update.SetFormulaIgnoreNull(src_noshow, this.NoShow);
            update.SetFormulaIgnoreNull(src_nosnap, this.NoSnap);
            //update.SetFormulaIgnoreNull(src_noquickdrag, this.NoQuickDrag);

            foreach (var row in this.Rows)
            {
                row.AddTo(shape, update, row_count, sec_index);
                row_count++;
            }

            update.Execute(shape);
            return(0);
        }
        public void CheckHomogenousUpdates_ResultTypes()
        {
            var page1  = this.GetNewPage();
            var shape1 = page1.DrawRectangle(0, 0, 1, 1);

            // Setup the modifications to the cell values
            var update = new VA.ShapeSheet.Update();

            update.SetResult(ShapeSheet_Update_Tests.src_linepat, "7", IVisio.VisUnitCodes.visNumber);
            update.SetResult(VA.ShapeSheet.SRCConstants.PinX, 2, IVisio.VisUnitCodes.visNumber);
            update.Execute(shape1);

            // Build the query
            var query       = new VA.ShapeSheet.Query.CellQuery();
            var col_linepat = query.AddCell(ShapeSheet_Update_Tests.src_linepat, "LinePattern");
            var col_pinx    = query.AddCell(VA.ShapeSheet.SRCConstants.PinX, "PinX");

            // Retrieve the values
            var data = query.GetCellData <double>(shape1);

            // Verify
            AssertVA.AreEqual("7", 7, data[col_linepat]);
            AssertVA.AreEqual("2 in", 2, data[col_pinx]);

            page1.Delete(0);
        }
        public void CheckHomogenousUpdates_ResultTypes()
        {
            var page1 = GetNewPage();
            var shape1 = page1.DrawRectangle(0, 0, 1, 1);

            // Setup the modifications to the cell values
            var update = new VA.ShapeSheet.Update();
            update.SetResult(src_linepat, "7", IVisio.VisUnitCodes.visNumber);
            update.SetResult(VA.ShapeSheet.SRCConstants.PinX, 2, IVisio.VisUnitCodes.visNumber);
            update.Execute(shape1);

            // Build the query
            var query = new VA.ShapeSheet.Query.CellQuery();
            var col_linepat = query.Columns.Add(src_linepat,"LinePattern");
            var col_pinx = query.Columns.Add(VA.ShapeSheet.SRCConstants.PinX,"PinX");

            // Retrieve the values
            var data = query.GetFormulasAndResults<double>(shape1);

            // Verify
            AssertVA.AreEqual("7", 7, data[col_linepat.Ordinal]);
            AssertVA.AreEqual("2 in", 2, data[col_pinx.Ordinal]);

            page1.Delete(0);
        }
Example #8
0
        private static void TestResize(IVisio.Document doc,
                                       VA.Drawing.Size bottomleft_margin,
                                       VA.Drawing.Size upperright_margin,
                                       VA.Drawing.Size shape_size,
                                       VA.Drawing.Size padding_size,
                                       double expected_pinx,
                                       double expected_piny)
        {
            var page = doc.Pages.Add();

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

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

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

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


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

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

            AssertVA.AreEqual(expected_pinx, expected_piny, xform.Pin(), 0.1);
            page.Delete(0);
        }
Example #9
0
        /// <summary>
        /// Remove all tab stops on the shape
        /// </summary>
        /// <param name="shape"></param>
        private static void ClearTabStops(IVisio.Shape shape)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException("shape");
            }

            int num_existing_tabstops = GetTabStopCount(shape);

            if (num_existing_tabstops < 1)
            {
                return;
            }

            var cell_tabstopcount = shape.CellsSRC[src_tabstopcount.Section, src_tabstopcount.Row, src_tabstopcount.Cell];

            cell_tabstopcount.FormulaForce = "0";

            const string formula = "0";

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

            for (int i = 1; i < num_existing_tabstops * 3; i++)
            {
                var src = new VA.ShapeSheet.SRC(tab_section, (short)IVisio.VisRowIndices.visRowTab,
                                                (short)i);
                update.SetFormula(src, formula);
            }

            update.Execute(shape);
        }
Example #10
0
        public static int Add(
            IVisio.Shape shape,
            ConnectionPointCells cp)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException("shape");
            }

            if (!cp.X.Formula.HasValue)
            {
                throw new System.ArgumentException("Must provide an X Formula");
            }

            if (!cp.Y.Formula.HasValue)
            {
                throw new System.ArgumentException("Must provide an Y Formula");
            }

            var n = shape.AddRow((short)IVisio.VisSectionIndices.visSectionConnectionPts,
                                 (short)IVisio.VisRowIndices.visRowLast,
                                 (short)IVisio.VisRowTags.visTagCnnctPt);

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

            update.SetFormulas(cp, n);
            update.Execute(shape);

            return(n);
        }
Example #11
0
        protected override void ProcessRecord()
        {
            if (this.FitContents)
            {
                var bordersize = new VisioAutomation.Drawing.Size(this.BorderWidth, this.BorderWidth);
                this.Client.Page.ResizeToFitContents(bordersize, true);
            }

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

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

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

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

                var update = new VisioAutomation.ShapeSheet.Update();
                update.SetFormulas(newpagecells);
                update.BlastGuards = true;
                update.Execute(page);
            }
        }
Example #12
0
        public void SetSize(IList <IVisio.Shape> target_shapes, double?w, double?h)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = GetTargetShapes(target_shapes);

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

            var shapeids = shapes.Select(s => s.ID).ToList();
            var update   = new VA.ShapeSheet.Update();

            foreach (int shapeid in shapeids)
            {
                if (w.HasValue && w.Value >= 0)
                {
                    update.SetFormula((short)shapeid, VA.ShapeSheet.SRCConstants.Width, w.Value);
                }
                if (h.HasValue && h.Value >= 0)
                {
                    update.SetFormula((short)shapeid, VA.ShapeSheet.SRCConstants.Height, h.Value);
                }
            }

            var application = this.Client.VisioApplication;

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Set Shape Size"))
            {
                var active_page = application.ActivePage;
                update.Execute(active_page);
            }
        }
Example #13
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);
        }
        protected override void ProcessRecord()
        {
            if (this.FitContents)
            {
                var bordersize = new VisioAutomation.Drawing.Size(this.BorderWidth, this.BorderWidth);
                this.client.Page.ResizeToFitContents(bordersize, true);
            }

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

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

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

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

                var update = new VisioAutomation.ShapeSheet.Update();
                update.SetFormulas(newpagecells);
                update.BlastGuards = true;
                update.Execute(page);
            }
        }
Example #15
0
        public void SetLock(IList <IVisio.Shape> target_shapes, VA.Shapes.LockCells lockcells)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = GetTargetShapes(target_shapes);

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

            var selection = this.Client.Selection.Get();
            var shapeids  = selection.GetIDs();
            var update    = new VA.ShapeSheet.Update();

            foreach (int shapeid in shapeids)
            {
                update.SetFormulas((short)shapeid, lockcells);
            }

            var application = this.Client.VisioApplication;

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Set Shape Lock Properties"))
            {
                var active_page = application.ActivePage;
                update.Execute(active_page);
            }
        }
        public static void ColorGrid()
        {
            // Draws a grid rectangles and then formats the shapes
            // with different colors

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

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

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

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

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

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

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

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

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

            update.Execute(page);

            var bordersize = new VA.Drawing.Size(1,1);
            page.ResizeToFitContents(bordersize);
        }
Example #17
0
        public void Render(IVisio.Page page)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException("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 VA.Application.PerfScope(app, PerfSettings))
            {
                if (this.Size.HasValue)
                {
                    this.PageCells.PageHeight = this.Size.Value.Height;
                    this.PageCells.PageWidth  = this.Size.Value.Width;
                }

                var update = new VA.ShapeSheet.Update();
                update.SetFormulas((short)page_sheet.ID, this.PageCells);
                update.Execute(page);

                // 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();
                    }
                }
            }
        }
Example #18
0
        public void Apply(IVisio.Page page)
        {
            var pagecells = new VA.Pages.PageCells();
            this.SetPageCells(pagecells);

            var update = new VA.ShapeSheet.Update();
            update.SetFormulas(pagecells);
            var pagesheet = page.PageSheet;
            update.Execute(pagesheet);
            page.Layout();
        }
Example #19
0
        public static void Set(IVisio.Shape shape, string name, string value, string prompt)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException("shape");
            }

            CheckValidName(name);

            if (Contains(shape, name))
            {
                string full_prop_name = GetRowName(name);

                if (value != null)
                {
                    string value_cell_name = full_prop_name;
                    var    cell            = shape.CellsU[value_cell_name];
                    string value_formula   = Convert.StringToFormulaString(value);
                    cell.FormulaU = value_formula;
                }

                if (prompt != null)
                {
                    string prompt_cell_name = full_prop_name + ".Prompt";
                    var    cell             = shape.CellsU[prompt_cell_name];
                    var    prompt_formula   = Convert.StringToFormulaString(prompt);
                    cell.FormulaU = prompt_formula;
                }
                return;
            }

            short row = shape.AddNamedRow(
                _userdefinedcell_section,
                name,
                (short)IVisio.VisRowIndices.visRowUser);

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

            if (value != null)
            {
                string value_formula = Convert.StringToFormulaString(value);
                var    src           = new VA.ShapeSheet.SRC(_userdefinedcell_section, row, (short)IVisio.VisCellIndices.visUserValue);
                update.SetFormula(src, value_formula);
            }

            if (prompt != null)
            {
                string prompt_formula = Convert.StringToFormulaString(prompt);
                var    src            = new VA.ShapeSheet.SRC(_userdefinedcell_section, row, (short)IVisio.VisCellIndices.visUserPrompt);
                update.SetFormula(src, prompt_formula);
            }

            update.Execute(shape);
        }
Example #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);
            }
        }
Example #21
0
        private static void SetSize(IVisio.Page page, VA.Drawing.Size size)
        {
            var page_cells = new VA.Pages.PageCells();

            page_cells.PageHeight = size.Height;
            page_cells.PageWidth  = size.Width;
            var pageupdate = new VA.ShapeSheet.Update();

            pageupdate.SetFormulas(page_cells);
            pageupdate.Execute(page.PageSheet);
        }
Example #22
0
        private static void update_xfrms(IVisio.Page page, IList <int> shapeids, IList <VA.Shapes.XFormCells> xfrms)
        {
            var update = new VA.ShapeSheet.Update();

            for (int i = 0; i < shapeids.Count; i++)
            {
                var shape_id = shapeids[i];
                var xfrm     = xfrms[i];
                update.SetFormulas((short)shape_id, xfrm);
            }
            update.Execute(page);
        }
Example #23
0
        public static void SetTabStops(IVisio.Shape shape, IList <TabStop> stops)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException("shape");
            }

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

            ClearTabStops(shape);
            if (stops.Count < 1)
            {
                return;
            }

            const short row = 0;
            var         invariant_culture  = System.Globalization.CultureInfo.InvariantCulture;
            var         vis_tab_stop_count = (short)IVisio.VisCellIndices.visTabStopCount;
            var         tabstopcountcell   = shape.CellsSRC[tab_section, row, vis_tab_stop_count];

            tabstopcountcell.FormulaU = stops.Count.ToString(invariant_culture);

            // set the number of tab stobs allowed for the shape
            var tagtab = GetTabTagForStops(stops.Count);

            shape.RowType[tab_section, (short)IVisio.VisRowIndices.visRowTab] = (short)tagtab;

            // add tab properties for each stop
            var update = new VA.ShapeSheet.Update();

            for (int stop_index = 0; stop_index < stops.Count; stop_index++)
            {
                int i = stop_index * 3;

                var alignment = ((int)stops[stop_index].Alignment).ToString(invariant_culture);
                var position  = ((int)stops[stop_index].Position).ToString(invariant_culture);

                var src_tabpos   = new VA.ShapeSheet.SRC(tab_section, row, (short)(i + 1));
                var src_tabalign = new VA.ShapeSheet.SRC(tab_section, row, (short)(i + 2));
                var src_tabother = new VA.ShapeSheet.SRC(tab_section, row, (short)(i + 3));

                update.SetFormula(src_tabpos, position);    // tab position
                update.SetFormula(src_tabalign, alignment); // tab alignment
                update.SetFormula(src_tabother, "0");       // tab unknown
            }

            update.Execute(shape);
        }
        public static void SetPageSize(IVisio.Page page, VA.Drawing.Size size)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException("page");
            }

            var page_sheet = page.PageSheet;

            var update = new VA.ShapeSheet.Update(2);
            update.SetFormula(VA.ShapeSheet.SRCConstants.PageWidth, size.Width);
            update.SetFormula(VA.ShapeSheet.SRCConstants.PageHeight, size.Height);
            update.Execute(page_sheet);
        }
Example #25
0
        public void Apply(IVisio.Page page)
        {
            var pagecells = new VA.Pages.PageCells();

            this.SetPageCells(pagecells);

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

            update.SetFormulas(pagecells);
            var pagesheet = page.PageSheet;

            update.Execute(pagesheet);
            page.Layout();
        }
Example #26
0
        public static void Spirograph()
        {
            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            page.Name = "Spirograph";

            var colors = new[]
            {
                0xf26420, 0xf7931c, 0xfec20d, 0xfff200,
                0xcada28, 0x8cc63e, 0x6c9d30, 0x288f39,
                0x006f3a, 0x006f71, 0x008eb0, 0x00adee,
                0x008ed3, 0x0071bb, 0x0053a6, 0x2e3091,
                0x5b57a6, 0x652d91, 0x92278e, 0xbd198c,
                0xec008b, 0xec1c23, 0xc1272c, 0x981a1e
            };

            var    origin             = new VA.Drawing.Point(4, 4);
            double radius             = 3.0;
            int    numpoints          = colors.Length;
            double angle_step         = (System.Math.PI * 2 / numpoints);
            var    angles             = Enumerable.Range(0, numpoints).Select(i => i * angle_step).ToList();
            var    centers            = angles.Select(a => GetPointAtRadius(origin, a, radius)).ToList();
            var    shapes             = centers.Select(p => draw_leaf(page, p)).ToList();
            var    angles_as_formulas = angles.Select(a => a.ToString()).ToList();

            var color_formulas = colors.Select(x => new VA.Drawing.ColorRGB(x).ToFormula()).ToList();

            var shapeids = shapes.Select(s => s.ID16).ToList();

            var update = new VA.ShapeSheet.Update();
            var format = new VA.Shapes.FormatCells();
            var xfrm   = new VA.Shapes.XFormCells();

            foreach (int i in Enumerable.Range(0, shapeids.Count))
            {
                short shapeid = shapeids[i];

                xfrm.Angle              = angles_as_formulas[i];
                format.FillForegnd      = color_formulas[i];
                format.LineWeight       = 0;
                format.LinePattern      = 0;
                format.FillForegndTrans = 0.5;

                update.SetFormulas(shapeid, xfrm);
                update.SetFormulas(shapeid, format);
            }

            update.Execute(page);
            VA.Pages.PageHelper.ResizeToFitContents(page, new VA.Drawing.Size(1.0, 1.0));
        }
Example #27
0
        public static void ProgressBar()
        {
            var page_a = SampleEnvironment.Application.ActiveDocument.Pages.Add();


            // Draw some shapes
            var background = page_a.DrawRectangle(0, 0, 5, 1);
            var progress   = page_a.DrawRectangle(0, 0, 1, 1);

            var background_fmt = new VA.Shapes.FormatCells();

            background_fmt.FillForegnd = "rgb(240,240,240)";
            background_fmt.LineColor   = "rgb(100,100,100)";


            var progress_fmt = new VA.Shapes.FormatCells();

            progress_fmt.FillForegnd = "rgb(100,150,240)";
            progress_fmt.LineColor   = "rgb(100,100,100)";

            // group the two shapes together
            page_a.Application.ActiveWindow.SelectAll();
            var group = page_a.Application.ActiveWindow.Selection.Group();

            // Set the progress shape update itself based on its position
            string bkname = background.NameID;
            var    xform  = new VA.Shapes.XFormCells();

            xform.PinX   = string.Format("GUARD({0}!PinX-{0}!LocPinX+LocPinX)", bkname);
            xform.PinY   = string.Format("GUARD({0}!PinY)", bkname);
            xform.Width  = string.Format("GUARD({0}!Width*(PAGENUMBER()/PAGECOUNT()))", bkname);
            xform.Height = string.Format("GUARD({0}!Height)", bkname);

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

            update.SetFormulas(progress.ID16, xform);
            update.SetFormulas(progress.ID16, background_fmt);
            update.SetFormulas(progress.ID16, progress_fmt);
            update.Execute(page_a);

            var markup1 = new VA.Text.Markup.TextElement();

            markup1.AddField(VA.Text.Markup.FieldConstants.PageName);
            markup1.AddText(" (");
            markup1.AddField(VA.Text.Markup.FieldConstants.PageNumber);
            markup1.AddText(" of ");
            markup1.AddField(VA.Text.Markup.FieldConstants.NumberOfPages);
            markup1.AddText(") ");
            markup1.SetText(group);
        }
        public static void Spirograph()
        {
            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();
            page.Name = "Spirograph";

            var colors = new[]
                    {
                        0xf26420, 0xf7931c, 0xfec20d, 0xfff200, 
                        0xcada28, 0x8cc63e, 0x6c9d30, 0x288f39,
                        0x006f3a, 0x006f71, 0x008eb0, 0x00adee, 
                        0x008ed3, 0x0071bb, 0x0053a6, 0x2e3091, 
                        0x5b57a6, 0x652d91, 0x92278e, 0xbd198c, 
                        0xec008b, 0xec1c23, 0xc1272c, 0x981a1e
                    };

            var origin = new VA.Drawing.Point(4, 4);
            double radius = 3.0;
            int numpoints = colors.Length;
            double angle_step = (System.Math.PI*2/numpoints);
            var angles = Enumerable.Range(0, numpoints).Select(i => i*angle_step).ToList();
            var centers = angles.Select(a => PlaygroundSamples.GetPointAtRadius(origin, a, radius)).ToList();
            var shapes = centers.Select(p => PlaygroundSamples.draw_leaf(page, p)).ToList();
            var angles_as_formulas = angles.Select(a => a.ToString(CultureInfo.InvariantCulture)).ToList();

            var color_formulas = colors.Select(x => new VA.Drawing.ColorRGB(x).ToFormula()).ToList();

            var shapeids = shapes.Select(s => s.ID16).ToList();

            var update = new VA.ShapeSheet.Update();
            var format = new VA.Shapes.FormatCells();
            var xfrm = new VA.Shapes.XFormCells();

            foreach (int i in Enumerable.Range(0, shapeids.Count))
            {
                short shapeid = shapeids[i];

                xfrm.Angle = angles_as_formulas[i];
                format.FillForegnd = color_formulas[i];
                format.LineWeight = 0;
                format.LinePattern = 0;
                format.FillForegndTrans = 0.5;

                update.SetFormulas(shapeid, xfrm);
                update.SetFormulas(shapeid, format);
            }

            update.Execute(page);
            VA.Pages.PageHelper.ResizeToFitContents(page, new VA.Drawing.Size(1.0, 1.0));
        }
Example #29
0
        private void UpdateCells(RenderContext ctx)
        {
            UpdateCellsWithDropSizes(ctx);

            var update            = new VA.ShapeSheet.Update();
            var shapes_with_cells = this.shapes.Where(s => s.Cells != null);

            foreach (var shape in shapes_with_cells)
            {
                var   fmt = shape.Cells;
                short id  = shape.VisioShapeID;
                fmt.Apply(update, id);
            }
            update.Execute(ctx.VisioPage);
        }
Example #30
0
        public static void SetPageSize(IVisio.Page page, VA.Drawing.Size size)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException("page");
            }

            var page_sheet = page.PageSheet;

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

            update.SetFormula(VA.ShapeSheet.SRCConstants.PageWidth, size.Width);
            update.SetFormula(VA.ShapeSheet.SRCConstants.PageHeight, size.Height);
            update.Execute(page_sheet);
        }
        public static void set_text_wrapping(IVisio.Page page,
            IList<int> shapeids,
            bool wrap)
        {
            const string formula_wrap = "WIDTH*1";
            const string formula_no_wrap = "TEXTWIDTH(TheText)";
            string formula = wrap ? formula_wrap : formula_no_wrap;
            var update = new VA.ShapeSheet.Update();

            foreach (int shapeid in shapeids)
            {
                update.SetFormula((short)shapeid, VA.ShapeSheet.SRCConstants.TxtWidth, formula);
            }

            update.Execute(page);
        }
Example #32
0
        public static void set_text_wrapping(IVisio.Page page,
                                             IList <int> shapeids,
                                             bool wrap)
        {
            const string formula_wrap    = "WIDTH*1";
            const string formula_no_wrap = "TEXTWIDTH(TheText)";
            string       formula         = wrap ? formula_wrap : formula_no_wrap;
            var          update          = new VA.ShapeSheet.Update();

            foreach (int shapeid in shapeids)
            {
                update.SetFormula((short)shapeid, VA.ShapeSheet.SRCConstants.TxtWidth, formula);
            }

            update.Execute(page);
        }
Example #33
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);
            }
        }
        public static void ProgressBar()
        {
            var page_a = SampleEnvironment.Application.ActiveDocument.Pages.Add();


            // Draw some shapes
            var background = page_a.DrawRectangle(0, 0, 5, 1);
            var progress = page_a.DrawRectangle(0, 0, 1, 1);

            var background_fmt = new VA.Shapes.FormatCells();
            background_fmt.FillForegnd= "rgb(240,240,240)";
            background_fmt.LineColor = "rgb(100,100,100)";


            var progress_fmt = new VA.Shapes.FormatCells();
            progress_fmt.FillForegnd = "rgb(100,150,240)";
            progress_fmt.LineColor = "rgb(100,100,100)";

            // group the two shapes together
            page_a.Application.ActiveWindow.SelectAll();
            var group = page_a.Application.ActiveWindow.Selection.Group();

            // Set the progress shape update itself based on its position
            string bkname = background.NameID;
            var xform = new VA.Shapes.XFormCells();
            xform.PinX = string.Format("GUARD({0}!PinX-{0}!LocPinX+LocPinX)", bkname);
            xform.PinY = string.Format("GUARD({0}!PinY)", bkname);
            xform.Width = string.Format("GUARD({0}!Width*(PAGENUMBER()/PAGECOUNT()))", bkname);
            xform.Height = string.Format("GUARD({0}!Height)", bkname); 

            var update = new VA.ShapeSheet.Update();
            update.SetFormulas(progress.ID16, xform);
            update.SetFormulas(progress.ID16, background_fmt);
            update.SetFormulas(progress.ID16, progress_fmt);
            update.Execute(page_a);

            var markup1 = new VA.Text.Markup.TextElement();
            markup1.AddField(VA.Text.Markup.FieldConstants.PageName);
            markup1.AddText(" (");
            markup1.AddField(VA.Text.Markup.FieldConstants.PageNumber);
            markup1.AddText(" of ");
            markup1.AddField(VA.Text.Markup.FieldConstants.NumberOfPages);
            markup1.AddText(") ");
            markup1.SetText(group);
        }
        public void Page_Query()
        {
            var page1 = this.GetNewPage(new VA.Drawing.Size(4, 3));
            var pagecells = VA.Pages.PageCells.GetCells(page1.PageSheet);
            Assert.AreEqual(new VA.Drawing.Size(4, 3), new VA.Drawing.Size(pagecells.PageWidth.Result,pagecells.PageHeight.Result));

            // Double each side
            pagecells.PageWidth = pagecells.PageWidth.Result * 2.0;
            pagecells.PageHeight = pagecells.PageHeight.Result * 2.0;

            var update = new VA.ShapeSheet.Update();
            update.SetFormulas(pagecells);
            update.Execute(page1.PageSheet);

            var pagecells2 = VA.Pages.PageCells.GetCells(page1.PageSheet);
            Assert.AreEqual(new VA.Drawing.Size(8, 6), new VA.Drawing.Size(pagecells2.PageWidth.Result, pagecells2.PageHeight.Result));
            page1.Delete(0);
        }
Example #36
0
        public static void FitShapeToText(IVisio.Page page, IEnumerable <IVisio.Shape> shapes)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException("page");
            }

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

            var shapeids = shapes.Select(s => s.ID).ToList();

            // Calculate the new sizes for each shape
            var new_sizes = new List <VA.Drawing.Size>(shapeids.Count);

            foreach (var shape in shapes)
            {
                var text_bounding_box = shape.GetBoundingBox(IVisio.VisBoundingBoxArgs.visBBoxUprightText).Size;
                var wh_bounding_box   = shape.GetBoundingBox(IVisio.VisBoundingBoxArgs.visBBoxUprightWH).Size;

                double max_w    = System.Math.Max(text_bounding_box.Width, wh_bounding_box.Width);
                double max_h    = System.Math.Max(text_bounding_box.Height, wh_bounding_box.Height);
                var    max_size = new VA.Drawing.Size(max_w, max_h);
                new_sizes.Add(max_size);
            }

            var src_width  = VA.ShapeSheet.SRCConstants.Width;
            var src_height = VA.ShapeSheet.SRCConstants.Height;

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

            for (int i = 0; i < new_sizes.Count; i++)
            {
                var shapeid  = shapeids[i];
                var new_size = new_sizes[i];
                update.SetFormula((short)shapeid, src_width, new_size.Width);
                update.SetFormula((short)shapeid, src_height, new_size.Height);
            }

            update.Execute(page);
        }
Example #37
0
        public void Page_Query()
        {
            var page1     = GetNewPage(new VA.Drawing.Size(4, 3));
            var pagecells = VA.Pages.PageCells.GetCells(page1.PageSheet);

            Assert.AreEqual(new VA.Drawing.Size(4, 3), new VA.Drawing.Size(pagecells.PageWidth.Result, pagecells.PageHeight.Result));

            // Double each side
            pagecells.PageWidth  = pagecells.PageWidth.Result * 2.0;
            pagecells.PageHeight = pagecells.PageHeight.Result * 2.0;

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

            update.SetFormulas(pagecells);
            update.Execute(page1.PageSheet);

            var pagecells2 = VA.Pages.PageCells.GetCells(page1.PageSheet);

            Assert.AreEqual(new VA.Drawing.Size(8, 6), new VA.Drawing.Size(pagecells2.PageWidth.Result, pagecells2.PageHeight.Result));
            page1.Delete(0);
        }
        public void ShapeSheet_Update_ResultsString_SingleShape()
        {
            var page1 = this.GetNewPage();
            var shape1 = page1.DrawRectangle(0, 0, 1, 1);

            // Setup the modifications to the cell values
            var update = new VA.ShapeSheet.Update();
            update.SetResult(ShapeSheet_Update_Tests.src_linepat, "7", IVisio.VisUnitCodes.visNumber);
            update.Execute(shape1);

            // Build the query
            var query = new VA.ShapeSheet.Query.CellQuery();
            var col_linepat = query.AddCell(ShapeSheet_Update_Tests.src_linepat, "LinePattern");

            // Retrieve the values
            var data = query.GetCellData<double>(shape1);

            // Verify
            AssertVA.AreEqual("7", 7, data[col_linepat]);
            page1.Delete(0);
        }
        protected override void ProcessRecord()
        {
            var update = new VisioAutomation.ShapeSheet.Update();

            update.BlastGuards  = this.BlastGuards;
            update.TestCircular = this.TestCircular;

            var cellmap  = CellSRCDictionary.GetCellMapForShapes();
            var valuemap = new CellValueDictionary(cellmap, this.Hashtable);

            var target_shapes = this.Shapes ?? this.Client.Selection.GetShapes();

            this.DumpValues(valuemap);

            foreach (var shape in target_shapes)
            {
                var id = shape.ID16;

                foreach (var cellname in valuemap.CellNames)
                {
                    string cell_value = valuemap[cellname];
                    var    cell_src   = valuemap.GetSRC(cellname);
                    update.SetFormulaIgnoreNull(id, cell_src, cell_value);
                }
            }

            var surface = this.Client.ShapeSheet.GetShapeSheetSurface();

            this.WriteVerbose("BlastGuards: {0}", this.BlastGuards);
            this.WriteVerbose("TestCircular: {0}", this.TestCircular);
            this.WriteVerbose("Number of Shapes : {0}", target_shapes.Count);
            this.WriteVerbose("Number of Total Updates: {0}", update.Count());

            using (var undoscope = this.Client.Application.NewUndoScope("SetShapeCells"))
            {
                this.WriteVerbose("Start Update");
                update.Execute(surface);
                this.WriteVerbose("End Update");
            }
        }
Example #40
0
        private void buttonSetFillGradient_Click(object sender, System.EventArgs e)
        {
            var client    = VisioPowerToolsAddIn.Client;
            var selection = client.Selection.Get();

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

            var format = new VA.Shapes.FormatCells();

            format.FillPattern          = (int)this.fillGradient1.FillDef.FillPattern;
            format.FillForegnd          = VA.Convert.ColorToFormulaRGB(this.fillGradient1.FillDef.ForegroundColor);
            format.FillBkgnd            = VA.Convert.ColorToFormulaRGB(this.fillGradient1.FillDef.BackgroundColor);
            format.FillForegndTrans     = this.fillGradient1.FillDef.ForegroundTransparency / 100.0;
            format.FillBkgndTrans       = this.fillGradient1.FillDef.BackgroundTransparency / 100.0;
            format.ShdwPattern          = (int)this.fillGradient1.ShadowDef.FillPattern;
            format.ShdwForegnd          = VA.Convert.ColorToFormulaRGB(this.fillGradient1.ShadowDef.ForegroundColor);
            format.ShdwBkgnd            = VA.Convert.ColorToFormulaRGB(this.fillGradient1.ShadowDef.BackgroundColor);
            format.ShdwForegndTrans     = this.fillGradient1.ShadowDef.ForegroundTransparency / 100.0;
            format.ShdwBkgndTrans       = this.fillGradient1.ShadowDef.BackgroundTransparency / 100.0;
            format.ShapeShdwOffsetX     = 0.0;
            format.ShapeShdwOffsetY     = 0.0;
            format.ShapeShdwScaleFactor = 1.0;
            format.ShapeShdwType        = 5;


            var update   = new VA.ShapeSheet.Update();
            var shapes   = client.Selection.GetShapes().ToList();
            var shapeids = shapes.Select(s => s.ID).ToList();

            foreach (int shapeid in shapeids)
            {
                update.SetFormulas((short)shapeid, format);
            }

            update.Execute(client.VisioApplication.ActivePage);
        }
Example #41
0
        public void Set(IList <IVisio.Shape> target_shapes, VA.Shapes.FormatCells format)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = this.GetTargetShapes(target_shapes);

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

            var update   = new VA.ShapeSheet.Update();
            var shapeids = shapes.Select(s => s.ID).ToList();

            foreach (int shapeid in shapeids)
            {
                update.SetFormulas((short)shapeid, format);
            }

            update.Execute(this.Client.VisioApplication.ActivePage);
        }
        protected override void ProcessRecord()
        {
            var update = new VisioAutomation.ShapeSheet.Update();
            update.BlastGuards = this.BlastGuards;
            update.TestCircular = this.TestCircular;

            var cellmap = CellSRCDictionary.GetCellMapForShapes();
            var valuemap = new CellValueDictionary(cellmap, this.Hashtable);

            var target_shapes = this.Shapes ?? this.client.Selection.GetShapes();

            this.DumpValues(valuemap);

            foreach (var shape in target_shapes)
            {
                var id = shape.ID16;

                foreach (var cellname in valuemap.CellNames)
                {
                    string cell_value = valuemap[cellname];
                    var cell_src = valuemap.GetSRC(cellname);
                    update.SetFormulaIgnoreNull(id,cell_src, cell_value);
                }
            }

            var surface = this.client.ShapeSheet.GetShapeSheetSurface();

            this.WriteVerbose("BlastGuards: {0}", this.BlastGuards);
            this.WriteVerbose("TestCircular: {0}", this.TestCircular);
            this.WriteVerbose("Number of Shapes : {0}", target_shapes.Count);
            this.WriteVerbose("Number of Total Updates: {0}", update.Count());

            using (var undoscope = this.client.Application.NewUndoScope( "SetShapeCells"))
            {
                this.WriteVerbose("Start Update");
                update.Execute(surface);
                this.WriteVerbose("End Update");
            }
        }
        public void ShapeSheet_Update_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 update = new VA.ShapeSheet.Update();

            update.SetFormula(shape1.ID16, ShapeSheet_Update_Tests.src_pinx, 0.5);
            update.SetFormula(shape1.ID16, ShapeSheet_Update_Tests.src_piny, 0.5);
            update.SetFormula(shape2.ID16, ShapeSheet_Update_Tests.src_pinx, 1.5);
            update.SetFormula(shape2.ID16, ShapeSheet_Update_Tests.src_piny, 1.5);
            update.SetFormula(shape3.ID16, ShapeSheet_Update_Tests.src_pinx, 2.5);
            update.SetFormula(shape3.ID16, ShapeSheet_Update_Tests.src_piny, 2.5);
            update.Execute(page1);

            // Verify that the formulas were set
            var query    = new VA.ShapeSheet.Query.CellQuery();
            var col_pinx = query.AddCell(ShapeSheet_Update_Tests.src_pinx, "PinX");
            var col_piny = query.AddCell(ShapeSheet_Update_Tests.src_piny, "PinY");

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

            var rf = query.GetFormulas(page1, shapeids);
            var rr = query.GetResults <double>(page1, shapeids);

            AssertVA.AreEqual("0.5 in", 0.5, rf[0][col_pinx], rr[0][col_pinx]);
            AssertVA.AreEqual("0.5 in", 0.5, rf[0][col_piny], rr[0][col_piny]);
            AssertVA.AreEqual("1.5 in", 1.5, rf[1][col_pinx], rr[1][col_pinx]);
            AssertVA.AreEqual("1.5 in", 1.5, rf[1][col_piny], rr[1][col_piny]);
            AssertVA.AreEqual("2.5 in", 2.5, rf[2][col_pinx], rr[2][col_pinx]);
            AssertVA.AreEqual("2.5 in", 2.5, rf[2][col_piny], rr[2][col_piny]);

            page1.Delete(0);
        }
        public void ShapeSheet_Update_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 update = new VA.ShapeSheet.Update();
            update.SetFormula(shape1.ID16, ShapeSheet_Update_Tests.src_pinx, 0.5);
            update.SetFormula(shape1.ID16, ShapeSheet_Update_Tests.src_piny, 0.5);
            update.SetFormula(shape2.ID16, ShapeSheet_Update_Tests.src_pinx, 1.5);
            update.SetFormula(shape2.ID16, ShapeSheet_Update_Tests.src_piny, 1.5);
            update.SetFormula(shape3.ID16, ShapeSheet_Update_Tests.src_pinx, 2.5);
            update.SetFormula(shape3.ID16, ShapeSheet_Update_Tests.src_piny, 2.5);
            update.Execute(page1);

            // Verify that the formulas were set
            var query = new VA.ShapeSheet.Query.CellQuery();
            var col_pinx = query.AddCell(ShapeSheet_Update_Tests.src_pinx, "PinX");
            var col_piny = query.AddCell(ShapeSheet_Update_Tests.src_piny, "PinY");

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

            var rf = query.GetFormulas(page1, shapeids);
            var rr = query.GetResults<double>(page1, shapeids);

            AssertVA.AreEqual("0.5 in", 0.5, rf[0][col_pinx], rr[0][col_pinx]);
            AssertVA.AreEqual("0.5 in", 0.5, rf[0][col_piny], rr[0][col_piny]);
            AssertVA.AreEqual("1.5 in", 1.5, rf[1][col_pinx], rr[1][col_pinx]);
            AssertVA.AreEqual("1.5 in", 1.5, rf[1][col_piny], rr[1][col_piny]);
            AssertVA.AreEqual("2.5 in", 2.5, rf[2][col_pinx], rr[2][col_pinx]);
            AssertVA.AreEqual("2.5 in", 2.5, rf[2][col_piny], rr[2][col_piny]);

            page1.Delete(0);
        }
        private void buttonSetFillGradient_Click(object sender, System.EventArgs e)
        {
            var client = VisioPowerToolsAddIn.Client;
            var selection = client.Selection.Get();
            if (selection.Count < 1)
            {
                return;
            }

            var format = new VA.Shapes.FormatCells();
            format.FillPattern = (int) this.fillGradient1.FillDef.FillPattern;
            format.FillForegnd= VA.Convert.ColorToFormulaRGB(this.fillGradient1.FillDef.ForegroundColor);
            format.FillBkgnd= VA.Convert.ColorToFormulaRGB(this.fillGradient1.FillDef.BackgroundColor);
            format.FillForegndTrans= this.fillGradient1.FillDef.ForegroundTransparency/100.0;
            format.FillBkgndTrans= this.fillGradient1.FillDef.BackgroundTransparency / 100.0;
            format.ShdwPattern= (int) this.fillGradient1.ShadowDef.FillPattern;
            format.ShdwForegnd= VA.Convert.ColorToFormulaRGB(this.fillGradient1.ShadowDef.ForegroundColor);
            format.ShdwBkgnd = VA.Convert.ColorToFormulaRGB(this.fillGradient1.ShadowDef.BackgroundColor);
            format.ShdwForegndTrans = this.fillGradient1.ShadowDef.ForegroundTransparency/100.0;
            format.ShdwBkgndTrans= this.fillGradient1.ShadowDef.BackgroundTransparency/100.0;
            format.ShapeShdwOffsetX = 0.0;
            format.ShapeShdwOffsetY = 0.0;
            format.ShapeShdwScaleFactor = 1.0;
            format.ShapeShdwType= 5;

            var update = new VA.ShapeSheet.Update();
            var shapes = client.Selection.GetShapes().ToList();
            var shapeids = shapes.Select(s => s.ID).ToList();

            foreach (int shapeid in shapeids)
            {
                update.SetFormulas((short)shapeid,format);
            }

            update.Execute(client.VisioApplication.ActivePage);
        }
        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 SetLock(IList<IVisio.Shape> target_shapes, VA.Shapes.LockCells lockcells)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

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

            var selection = this.Client.Selection.Get();
            var shapeids = selection.GetIDs();
            var update = new VA.ShapeSheet.Update();

            foreach (int shapeid in shapeids)
            {
                update.SetFormulas((short)shapeid, lockcells);
            }

            var application = this.Client.VisioApplication;
            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication,"Set Shape Lock Properties"))
            {
                var active_page = application.ActivePage;
                update.Execute(active_page);
            }
        }
        public void Set(IList<IVisio.Shape> target_shapes, VA.Shapes.FormatCells format)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = this.GetTargetShapes(target_shapes);

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

            var update = new VA.ShapeSheet.Update();
            var shapeids = shapes.Select(s => s.ID).ToList();

            foreach (int shapeid in shapeids)
            {
                update.SetFormulas((short)shapeid, format);
            }

            update.Execute(this.Client.VisioApplication.ActivePage);
        }
        public void PasteSize(IList<IVisio.Shape> target_shapes, bool paste_width, bool paste_height)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = this.GetTargetShapes(target_shapes);

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

            if ((!cached_size_width.HasValue) && (!cached_size_height.HasValue))
            {
                return;
            }

            var update = new VA.ShapeSheet.Update();
            var shapeids = shapes.Select(s => s.ID).ToList();

            foreach (var shapeid in shapeids)
            {
                if (paste_width)
                {
                    update.SetFormula((short)shapeid, VA.ShapeSheet.SRCConstants.Width, cached_size_width.Value);
                }

                if (paste_height)
                {
                    update.SetFormula((short)shapeid, VA.ShapeSheet.SRCConstants.Height, cached_size_height.Value);
                }
            }

            var application = this.Client.VisioApplication;
            var active_page = application.ActivePage;
            update.Execute(active_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);
            }
        }
        public void PasteFormat(IVisio.Page page, IList<int> shapeids, FormatCategory category, bool applyformulas)
        {
            var update = new VA.ShapeSheet.Update();

            foreach (var shape_id in shapeids)
            {
                foreach (var cellrec in this.Cells)
                {
                    if (!cellrec.MatchesCategory(category))
                    {
                        continue;
                    }

                    var sidsrc = new VA.ShapeSheet.SIDSRC((short)shape_id, cellrec.SRC);

                    if (applyformulas)
                    {
                        update.SetFormula(sidsrc, cellrec.Formula);

                    }
                    else
                    {
                        if (cellrec.Result != null)
                        {
                            update.SetFormula(sidsrc, cellrec.Result);
                        }
                    }
                }
            }

            update.Execute(page);
        }
        public static void DrawAllGradients()
        {
            var app = SampleEnvironment.Application;
            var docs = app.Documents;
            var stencil = docs.OpenStencil("basic_u.vss");
            var master = stencil.Masters["Rectangle"];
            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            int num_cols = 7;
            int num_rows = 7;

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

            var lowerleft = new VA.Drawing.Point(0, 0);
            var actual_page_size = SampleEnvironment.GetPageSize(page);
            var page_rect = new VA.Drawing.Rectangle(lowerleft, actual_page_size);

            var layout = new GRIDMODEL.GridLayout(num_cols, num_rows, new VA.Drawing.Size(1, 1), master);
            layout.RowDirection = GRIDMODEL.RowDirection.TopToBottom;
            layout.Origin = page_rect.UpperLeft;
            layout.CellSpacing = new VA.Drawing.Size(0, 0);
            layout.PerformLayout();

            int max_grad_id = 40;
            int n = 0;

            foreach (var node in layout.Nodes)
            {
                int grad_id = n%max_grad_id;
                node.Text = grad_id.ToString();
                n++;
            }

            layout.Render(page);

            var color1 = new VA.Drawing.ColorRGB(0xffdddd);
            var color2 = new VA.Drawing.ColorRGB(0x00ffff);

            var format = new VA.Shapes.FormatCells();

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

            string color1_formula = color1.ToFormula();
            string color2_formula = color2.ToFormula();

            n = 0;

            foreach (var node in layout.Nodes)
            {
                short shapeid = node.ShapeID;
                int grad_id = n%max_grad_id;

                format.FillPattern = grad_id;
                format.FillForegnd = color1_formula;
                format.FillBkgnd = color2_formula;
                format.LinePattern = 0;
                format.LineWeight = 0;
                update.SetFormulas(shapeid, format);

                n++;
            }

            update.Execute(page);

            var bordersize = new VA.Drawing.Size(1, 1);
            page.ResizeToFitContents(bordersize);
        }
        public static void Set(IVisio.Shape shape, string name, string value, string prompt)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException("shape");
            }

            CheckValidName(name);

            if (Contains(shape, name))
            {
                string full_prop_name = GetRowName(name);

                if (value != null)
                {
                    string value_cell_name = full_prop_name;
                    var cell = shape.CellsU[value_cell_name];
                    string value_formula = Convert.StringToFormulaString(value);
                    cell.FormulaU = value_formula;
                }

                if (prompt != null)
                {
                    string prompt_cell_name = full_prop_name+".Prompt";
                    var cell = shape.CellsU[prompt_cell_name];
                    var prompt_formula = Convert.StringToFormulaString(prompt);
                    cell.FormulaU = prompt_formula;
                }
                return;
            }

            short row = shape.AddNamedRow(
                _userdefinedcell_section,
                name,
                (short)IVisio.VisRowIndices.visRowUser);

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

            if (value != null)
            {
                string value_formula = Convert.StringToFormulaString(value);
                var src = new VA.ShapeSheet.SRC(_userdefinedcell_section, row, (short)IVisio.VisCellIndices.visUserValue);
                update.SetFormula(src, value_formula);
            }

            if (prompt != null)
            {
                string prompt_formula = Convert.StringToFormulaString(prompt);
                var src = new VA.ShapeSheet.SRC(_userdefinedcell_section, row, (short)IVisio.VisCellIndices.visUserPrompt);
                update.SetFormula(src, prompt_formula);
            }

            update.Execute(shape);
        }
        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);
            }
        }
 private static void update_xfrms(IVisio.Page page, IList<int> shapeids, IList<VA.Shapes.XFormCells> xfrms)
 {
     var update = new VA.ShapeSheet.Update();
     for (int i = 0; i < shapeids.Count; i++)
     {
         var shape_id = shapeids[i];
         var xfrm = xfrms[i];
         update.SetFormulas((short)shape_id, xfrm);
     }
     update.Execute(page);
 }
        public void SetSize(IList<IVisio.Shape> target_shapes, double? w, double? h)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

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

            var shapeids = shapes.Select(s=>s.ID).ToList();
            var update = new VA.ShapeSheet.Update();
            foreach (int shapeid in shapeids)
            {
                if (w.HasValue && w.Value>=0)
                {
                    update.SetFormula((short)shapeid, VA.ShapeSheet.SRCConstants.Width, w.Value);
                }
                if (h.HasValue && h.Value >= 0)
                {
                    update.SetFormula((short)shapeid, VA.ShapeSheet.SRCConstants.Height, h.Value);
                }
            }

            var application = this.Client.VisioApplication;
            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication,"Set Shape Size"))
            {
                var active_page = application.ActivePage;
                update.Execute(active_page);
            }
        }
        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 void SetText(IVisio.Shape shape)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException("shape");
            }

            // First just set all the text
            string full_doc_inner_text = this.GetInnerText();
            shape.Text = full_doc_inner_text;

            // Find all the regions needing formatting
            var markupinfo = this.GetMarkupInfo();
            var regions_to_format = markupinfo.FormatRegions.Where(region => region.Length >= 1).ToList();

            var default_chars_bias = IVisio.VisCharsBias.visBiasLeft;

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

            foreach (var region in regions_to_format)
            {

                // Apply character formatting
                var charcells = region.Element.CharacterCells;
                if (charcells != null)
                {
                    var chars = shape.Characters;
                    chars.Begin = region.Start;
                    chars.End = region.End;
                    chars.CharProps[VA.ShapeSheet.SRCConstants.CharColor.Cell] = 0;
                    short rownum = chars.CharPropsRow[(short) default_chars_bias];

                    if (rownum < 0)
                    {
                        throw new VA.AutomationException("Could not create Character row");
                    }

                    update.Clear();
                    charcells.ApplyFormulas(update, rownum);
                    update.Execute(shape);
                }

                // Apply paragraph formatting
                var paracells = region.Element.ParagraphCells;
                if (paracells != null)
                {
                    var chars = shape.Characters;
                    chars.Begin = region.Start;
                    chars.End = region.End;
                    chars.ParaProps[VA.ShapeSheet.SRCConstants.Para_Bullet.Cell] = 0;
                    short rownum = chars.ParaPropsRow[(short) default_chars_bias];

                    if (rownum < 0)
                    {
                        throw new VA.AutomationException("Could not create Paragraph row");
                    }

                    update.Clear();
                    paracells.ApplyFormulas(update, rownum);
                    update.Execute(shape);
                }
            }

            // Insert the fields
            // note: Fields are added in reverse because it is simpler to keep track of the insertion positions
            foreach (var field_region in markupinfo.FieldRegions.Where(region => region.Length >= 1).Reverse())
            {
                var chars = shape.Characters;
                chars.Begin = field_region.Start;
                chars.End = field_region.End;
                chars.AddField((short) field_region.Field.Category, (short) field_region.Field.Code,
                               (short) field_region.Field.Format);
                var fr = field_region;
            }
        }
        public void ShapeSheet_Update_ResultsDouble_MultipleShapes()
        {
            var page1 = 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 update = new VA.ShapeSheet.Update();
            update.SetResult(shape1.ID16, src_pinx, 0.5, IVisio.VisUnitCodes.visNumber);
            update.SetResult(shape1.ID16, src_piny, 0.5, IVisio.VisUnitCodes.visNumber);
            update.SetResult(shape2.ID16, src_pinx, 1.5, IVisio.VisUnitCodes.visNumber);
            update.SetResult(shape2.ID16, src_piny, 1.5, IVisio.VisUnitCodes.visNumber);
            update.SetResult(shape3.ID16, src_pinx, 2.5, IVisio.VisUnitCodes.visNumber);
            update.SetResult(shape3.ID16, src_piny, 2.5, IVisio.VisUnitCodes.visNumber);
            update.Execute(page1);

            // Verify that the formulas were set
            var query = new VA.ShapeSheet.Query.CellQuery();
            var col_pinx = query.Columns.Add(src_pinx,"PinX");
            var col_piny = query.Columns.Add(src_piny,"PinY");

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

            var rf = query.GetFormulas(page1, shapeids);
            var rr = query.GetResults<double>(page1, shapeids);

            AssertVA.AreEqual("0.5 in", 0.5, rf[0][col_pinx.Ordinal], rr[0][col_pinx.Ordinal]);
            AssertVA.AreEqual("0.5 in", 0.5, rf[0][col_piny.Ordinal], rr[0][col_piny.Ordinal]);
            AssertVA.AreEqual("1.5 in", 1.5, rf[1][col_pinx.Ordinal], rr[1][col_pinx.Ordinal]);
            AssertVA.AreEqual("1.5 in", 1.5, rf[1][col_piny.Ordinal], rr[1][col_piny.Ordinal]);
            AssertVA.AreEqual("2.5 in", 2.5, rf[2][col_pinx.Ordinal], rr[2][col_pinx.Ordinal]);
            AssertVA.AreEqual("2.5 in", 2.5, rf[2][col_piny.Ordinal], rr[2][col_piny.Ordinal]);

            page1.Delete(0);
        }
        public void ShapeSheet_Update_ResultsInt_SingleShape()
        {
            var page1 = GetNewPage();
            var shape1 = page1.DrawRectangle(0, 0, 1, 1);

            // Setup the modifications to the cell values
            var update = new VA.ShapeSheet.Update();
            update.SetResult(src_linepat, 7, IVisio.VisUnitCodes.visNumber);
            update.Execute(shape1);

            // Build the query
            var query = new VA.ShapeSheet.Query.CellQuery();
            var col_linepat = query.Columns.Add(src_linepat,"LinePattern");

            // Retrieve the values
            var data = query.GetFormulasAndResults<double>(shape1);

            // Verify
            AssertVA.AreEqual("7", 7, data[col_linepat.Ordinal]);
            page1.Delete(0);
        }