コード例 #1
0
        public void Page_Query()
        {
            var size           = new VA.Geometry.Size(4, 3);
            var page1          = this.GetNewPage(size);
            var page_fmt_cells = VA.Pages.PageFormatCells.GetCells(page1.PageSheet, CellValueType.Formula);

            Assert.AreEqual("4 in", page_fmt_cells.Width.Value);
            Assert.AreEqual("3 in", page_fmt_cells.Height.Value);

            // Double each side
            var page_fmt_cells1 = page_fmt_cells;

            page_fmt_cells1.Width  = "8";
            page_fmt_cells1.Height = "6";

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

            writer.SetValues(page_fmt_cells1);

            writer.CommitFormulas(page1.PageSheet);

            var actual_page_format_cells = VA.Pages.PageFormatCells.GetCells(page1.PageSheet, CellValueType.Result);

            Assert.AreEqual("8.0000 in.", actual_page_format_cells.Width.Value);
            Assert.AreEqual("6.0000 in.", actual_page_format_cells.Height.Value);
            page1.Delete(0);
        }
コード例 #2
0
        /// <summary>
        /// Remove all tab stops on the shape
        /// </summary>
        /// <param name="shape"></param>
        private static void _clear_tab_stops(IVisio.Shape shape)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            int num_existing_tabstops = _get_tab_stop_count(shape);

            if (num_existing_tabstops < 1)
            {
                return;
            }

            var cell_tabstopcount = shape.CellsSRC[ShapeSheet.SrcConstants.TabStopCount.Section, ShapeSheet.SrcConstants.TabStopCount.Row, ShapeSheet.SrcConstants.TabStopCount.Cell];

            cell_tabstopcount.FormulaForce = "0";

            const string formula = "0";

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

            for (int i = 1; i < num_existing_tabstops * 3; i++)
            {
                var src = new ShapeSheet.Src(tab_section, (short)IVisio.VisRowIndices.visRowTab,
                                             (short)i);
                writer.SetValue(src, formula);
            }

            writer.CommitFormulas(shape);
        }
コード例 #3
0
        public static int Set(IVisio.Shape shape, short row, ControlCells ctrl)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }


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

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

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

            writer.SetValues(ctrl, row);

            writer.CommitFormulas(shape);

            return(row);
        }
コード例 #4
0
        public static int Add(
            IVisio.Shape shape,
            ConnectionPointCells connection_point_cells)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            if (connection_point_cells.X.Value == null)
            {
                string msg = "Must provide an X Formula";
                throw new System.ArgumentException(msg, nameof(connection_point_cells));
            }

            if (connection_point_cells.Y.Value == null)
            {
                string msg = "Must provide an Y Formula";
                throw new System.ArgumentException(msg, nameof(connection_point_cells));
            }

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

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

            writer.SetValues(connection_point_cells, n);

            writer.CommitFormulas(shape);

            return(n);
        }
コード例 #5
0
        public short Render(IVisio.Shape shape)
        {
            short sec_index = ShapeGeometryHelper.AddSection(shape);
            short row_count = shape.RowCount[sec_index];

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

            var src_nofill      = new VA.ShapeSheet.Src(sec_index, 0, ShapeSheet.SrcConstants.GeometryNoFill.Cell);
            var src_noline      = new VA.ShapeSheet.Src(sec_index, 0, ShapeSheet.SrcConstants.GeometryNoLine.Cell);
            var src_noshow      = new VA.ShapeSheet.Src(sec_index, 0, ShapeSheet.SrcConstants.GeometryNoShow.Cell);
            var src_nosnap      = new VA.ShapeSheet.Src(sec_index, 0, ShapeSheet.SrcConstants.GeometryNoSnap.Cell);
            var src_noquickdrag = new VA.ShapeSheet.Src(sec_index, 0, ShapeSheet.SrcConstants.GeometryNoQuickDrag.Cell);

            writer.SetValue(src_nofill, this.NoFill);
            writer.SetValue(src_noline, this.NoLine);
            writer.SetValue(src_noshow, this.NoShow);
            writer.SetValue(src_nosnap, this.NoSnap);
            writer.SetValue(src_noquickdrag, this.NoQuickDrag);

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

            writer.CommitFormulas(shape);

            return(0);
        }
コード例 #6
0
        private static void VerifyPageSizeToFit(IVisio.Document doc,
                                                VA.Geometry.Size bottomleft_margin,
                                                VA.Geometry.Size upperright_margin,
                                                VA.Geometry.Size shape_size,
                                                VA.Geometry.Size padding_size,
                                                double expected_pinx,
                                                double expected_piny)
        {
            var page = doc.Pages.Add();

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

            pagecells.TopMargin    = upperright_margin.Height;
            pagecells.BottomMargin = bottomleft_margin.Height;
            pagecells.LeftMargin   = bottomleft_margin.Width;
            pagecells.RightMargin  = upperright_margin.Width;

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

            page_writer.SetValues(pagecells);

            page_writer.CommitFormulas(page.PageSheet);


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

            page.ResizeToFitContents(padding_size);
            var xform  = VA.Shapes.ShapeXFormCells.GetCells(shape, CellValueType.Result);
            var pinpos = xform.GetPinPosResult();

            Assert.AreEqual(expected_pinx, pinpos.X, 0.1);
            Assert.AreEqual(expected_piny, pinpos.Y, 0.1);
            page.Delete(0);
        }
コード例 #7
0
        internal static void SetSize(IVisio.Page page, Geometry.Size size)
        {
            var writer = new VASS.Writers.SrcWriter();

            writer.SetValue(VASS.SrcConstants.PageWidth, size.Width);
            writer.SetValue(VASS.SrcConstants.PageHeight, size.Height);

            writer.CommitFormulas(page.PageSheet);
        }
コード例 #8
0
        public static void Set(IVisio.Shape shape, string name, UserDefinedCellCells cells)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

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

            UserDefinedCellHelper.CheckValidName(name);

            if (UserDefinedCellHelper.Contains(shape, name))
            {
                // The user-defined cell already exists
                string full_udcell_name = UserDefinedCellHelper.__GetRowName(name);

                if (cells.Value.HasValue)
                {
                    string value_cell_name = full_udcell_name;
                    var    cell            = shape.CellsU[value_cell_name];
                    cell.FormulaU = cells.Value.Value;
                }

                if (cells.Prompt.HasValue)
                {
                    string prompt_cell_name = full_udcell_name + ".Prompt";
                    var    cell             = shape.CellsU[prompt_cell_name];
                    cell.FormulaU = cells.Prompt.Value;
                }
            }
            else
            {
                // The user-defined cell doesn't already exist
                short row        = shape.AddNamedRow(_udcell_section, name, (short)IVisio.VisRowIndices.visRowUser);
                var   src_value  = new ShapeSheet.Src(_udcell_section, row, (short)IVisio.VisCellIndices.visUserValue);
                var   src_prompt = new ShapeSheet.Src(_udcell_section, row, (short)IVisio.VisCellIndices.visUserPrompt);

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

                if (cells.Value.HasValue)
                {
                    writer.SetValue(src_value, cells.Value.Value);
                }

                if (cells.Prompt.HasValue)
                {
                    writer.SetValue(src_prompt, cells.Prompt.Value);
                }

                writer.CommitFormulas(shape);
            }
        }
コード例 #9
0
        public void Apply(IVisio.Page page)
        {
            var page_layout_cells = new VisioAutomation.Pages.PageLayoutCells();

            this.SetPageCells(page_layout_cells);

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

            writer.SetValues(page_layout_cells);

            writer.CommitFormulas(page.PageSheet);
            page.Layout();
        }
コード例 #10
0
        public static void Set(IVisio.Shape shape, short row, CustomPropertyCells cp)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

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

            writer.SetValues(cp, row);

            writer.CommitFormulas(shape);
        }
コード例 #11
0
        public static void SetTabStops(IVisio.Shape shape, IList <TabStop> stops)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

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

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

            const short row                = 0;
            var         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(culture);

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

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

            // add tab properties for each stop
            var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();

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

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

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

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

            writer.CommitFormulas(shape);
        }
コード例 #12
0
        public void SetPageFormatCells(Models.TargetPages targetpages, VisioAutomation.Pages.PageFormatCells cells)
        {
            var pages = targetpages.Resolve(this._client);

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetPageFormatCells)))
            {
                foreach (var page in pages)
                {
                    var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();
                    writer.SetValues(cells);
                    writer.BlastGuards = true;
                    writer.CommitFormulas(page);
                }
            }
        }
コード例 #13
0
        public void SetPageSize(Models.TargetPages targetpages, VisioAutomation.Geometry.Size new_size)
        {
            var pages = targetpages.Resolve(this._client);

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetPageSize)))
            {
                foreach (var page in pages)
                {
                    var page_sheet = page.PageSheet;
                    var writer     = new VisioAutomation.ShapeSheet.Writers.SrcWriter();
                    writer.SetValue(VisioAutomation.ShapeSheet.SrcConstants.PageWidth, new_size.Width);
                    writer.SetValue(VisioAutomation.ShapeSheet.SrcConstants.PageHeight, new_size.Height);
                    writer.CommitFormulas(page_sheet);
                }
            }
        }
コード例 #14
0
        public static void SetPageSize(IVisio.Page page, VA.Geometry.Size size)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException(nameof(page));
            }

            var page_sheet = page.PageSheet;

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

            writer.SetValue(VA.ShapeSheet.SrcConstants.PageWidth, size.Width);
            writer.SetValue(VA.ShapeSheet.SrcConstants.PageHeight, size.Height);

            writer.CommitFormulas(page_sheet);
        }
コード例 #15
0
        public static int Set(
            IVisio.Shape shape,
            short row,
            ConnectionPointCells cpcells)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

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

            writer.SetValues(cpcells, row);

            writer.CommitFormulas(shape);

            return(row);
        }
コード例 #16
0
        public static int Set(
            IVisio.Shape shape,
            short row,
            HyperlinkCells hyperlink)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

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

            writer.SetValues(hyperlink, row);

            writer.CommitFormulas(shape);

            return(row);
        }
コード例 #17
0
        public IVisio.Document NewDocumentFromTemplate(VisioAutomation.Geometry.Size size, string template)
        {
            var cmdtarget = this._client.GetCommandTargetApplication();

            var doc       = this.NewDocumentFromTemplate(template);
            var pagecells = new VisioAutomation.Pages.PageFormatCells();

            pagecells.Width  = size.Width;
            pagecells.Height = size.Height;

            var pages = doc.Pages;
            var page  = pages[1];

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

            writer.SetValues(pagecells);
            writer.CommitFormulas(page.PageSheet);

            return(doc);
        }
コード例 #18
0
        public static void Set(
            IVisio.Shape shape,
            string name,
            CustomPropertyCells cp)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            CustomPropertyHelper.__CheckValidCustomPropertyName(name);

            if (CustomPropertyHelper.Contains(shape, name))
            {
                string full_prop_name = CustomPropertyHelper.__GetRowName(name);
                var    cell_propname  = shape.CellsU[full_prop_name];

                if (cell_propname == null)
                {
                    string msg = string.Format("Could not retrieve cell for custom property \"{0}\"", full_prop_name);
                    throw new Exceptions.InternalAssertionException(msg);
                }

                var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();
                writer.SetValues(cp, cell_propname.Row);

                writer.CommitFormulas(shape);

                return;
            }

            short row = shape.AddNamedRow(
                vis_sec_prop,
                name,
                (short)IVisio.VisRowIndices.visRowProp);

            CustomPropertyHelper.Set(shape, row, cp);
        }
コード例 #19
0
        public void SetPageOrientation(Models.TargetPages target_pages, Models.PageOrientation orientation)
        {
            if (orientation != VisioScripting.Models.PageOrientation.Landscape && orientation != VisioScripting.Models.PageOrientation.Portrait)
            {
                throw new System.ArgumentOutOfRangeException(nameof(orientation), "must be either Portrait or Landscape");
            }

            var pages = target_pages.Resolve(this._client);

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetPageOrientation)))
            {
                foreach (var page in pages)
                {
                    var old_orientation = PageCommands._GetPageOrientation(page);

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

                    var page_tp  = new VisioScripting.Models.TargetPages(page);
                    var old_size = this.GetPageSize(page_tp);

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

                    var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();
                    writer.SetValue(VisioAutomation.ShapeSheet.SrcConstants.PageWidth, new_width);
                    writer.SetValue(VisioAutomation.ShapeSheet.SrcConstants.PageHeight, new_height);
                    writer.SetValue(VisioAutomation.ShapeSheet.SrcConstants.PrintPageOrientation, (int)orientation);

                    writer.CommitFormulas(page.PageSheet);
                }
            }
        }
コード例 #20
0
        public void SetText(IVisio.Shape shape)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(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 writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();

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

                    if (rownum < 0)
                    {
                        throw new VisioAutomation.Exceptions.VisioOperationException("Could not create Character row");
                    }

                    writer.Clear();
                    charcells.ApplyFormulas(writer, rownum);

                    writer.CommitFormulas(shape);
                }

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

                    if (rownum < 0)
                    {
                        throw new VisioAutomation.Exceptions.VisioOperationException("Could not create Paragraph row");
                    }

                    writer.Clear();
                    paracells.ApplyFormulas(writer, rownum);

                    writer.CommitFormulas(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;
            }
        }
コード例 #21
0
        public static void Duplicate(
            IVisio.Page src_page,
            IVisio.Page dest_page)
        {
            init_page_srcs();

            var   app = src_page.Application;
            short copy_paste_flags = (short)IVisio.VisCutCopyPasteCodes.visCopyPasteNoTranslate;

            // handle the source page
            if (src_page == null)
            {
                throw new System.ArgumentNullException(nameof(src_page));
            }

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

            if (dest_page == src_page)
            {
                throw new System.ArgumentException("Destination Page cannot be Source Page");
            }


            if (src_page != app.ActivePage)
            {
                throw new System.ArgumentException("Source page must be active page.");
            }

            var src_page_shapes = src_page.Shapes;
            int num_src_shapes  = src_page_shapes.Count;

            if (num_src_shapes > 0)
            {
                var active_window = app.ActiveWindow;
                active_window.SelectAll();
                var selection = active_window.Selection;
                selection.Copy(copy_paste_flags);
                active_window.DeselectAll();
            }

            // Get the Cells from the Source
            var query = new VASS.Query.CellQuery();
            int i     = 0;

            foreach (var src in _static_page_srcs)
            {
                query.Columns.Add(src, "Col" + i.ToString());
                i++;
            }

            var src_formulas = query.GetFormulas(src_page.PageSheet);

            // Set the Cells on the Destination

            var writer = new VASS.Writers.SrcWriter();

            for (i = 0; i < _static_page_srcs.Count; i++)
            {
                int row = 0;
                writer.SetValue(_static_page_srcs[i], src_formulas[row][i]);
            }

            writer.CommitFormulas(dest_page.PageSheet);

            // make sure the new page looks like the old page
            dest_page.Background = src_page.Background;

            // then paste any contents from the first page
            if (num_src_shapes > 0)
            {
                dest_page.Paste(copy_paste_flags);
            }
        }