コード例 #1
0
        public void ShapeSheet_Writer_ResultsString_SingleShape()
        {
            var page1  = this.GetNewPage();
            var shape1 = page1.DrawRectangle(0, 0, 1, 1);

            // Setup the modifications to the cell values
            var writer = new ResultWriterSRC();

            writer.SetResult(ShapeSheetWriterTests.src_linepat, "7", IVisio.VisUnitCodes.visNumber);
            writer.Commit(shape1);

            // Build the query
            var query       = new VisioAutomation.ShapeSheet.Queries.Query();
            var col_linepat = query.AddCell(ShapeSheetWriterTests.src_linepat, "LinePattern");

            // Retrieve the values
            var surface       = new ShapeSheetSurface(shape1);
            var data_formulas = query.GetFormulas(surface);
            var data_results  = query.GetResults <double>(surface);

            // Verify
            Assert.AreEqual("7", data_formulas.Cells[col_linepat]);
            Assert.AreEqual(7, data_results.Cells[col_linepat]);
            page1.Delete(0);
        }
コード例 #2
0
        /// <summary>
        /// Caches the resize (the results, not formulas) of a the first currently selected shape
        /// </summary>
        public void CopySize()
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

            if (!this._client.Selection.HasShapes())
            {
                return;
            }

            var application   = this._client.Application.Get();
            var active_window = application.ActiveWindow;
            var selection     = active_window.Selection;
            var shape         = selection[1];

            var query      = new VisioAutomation.ShapeSheet.Queries.Query();
            var width_col  = query.AddCell(VisioAutomation.ShapeSheet.SRCConstants.Width, "Width");
            var height_col = query.AddCell(VisioAutomation.ShapeSheet.SRCConstants.Height, "Height");

            var ss = new ShapeSheetSurface(shape);

            var queryresults = query.GetResults <double>(ss);

            this.cached_size_width  = queryresults.Cells[width_col];
            this.cached_size_height = queryresults.Cells[height_col];
        }
コード例 #3
0
        private static DataTable querytable_to_datatable <T>(VisioAutomation.ShapeSheet.Queries.Query cellQuery, ListOutput <T> query_output)
        {
            // First Construct a Datatable with a compatible schema
            var dt = new DataTable();

            dt.Columns.Add("ShapeID", typeof(int));
            foreach (var col in cellQuery.Cells)
            {
                dt.Columns.Add(col.Name, typeof(T));
            }

            // Then populate the rows of the datatable
            dt.BeginLoadData();
            int colcount = cellQuery.Cells.Count;
            var rowbuf   = new object[colcount + 1];

            for (int r = 0; r < query_output.Count; r++)
            {
                // populate the row buffer

                rowbuf[0] = query_output[r].ShapeID;

                for (int i = 0; i < colcount; i++)
                {
                    rowbuf[i + 1] = query_output[r].Cells[i];
                }

                // load it into the table
                dt.Rows.Add(rowbuf);
            }
            dt.EndLoadData();
            return(dt);
        }
コード例 #4
0
        public void CopyFormat(IVisio.Shape shape, FormatCategory category)
        {
            // Build the Query
            var query         = new VisioAutomation.ShapeSheet.Queries.Query();
            var desired_cells = this.Cells.Where(cell => cell.MatchesCategory(category)).ToList();

            foreach (var cell in desired_cells)
            {
                query.AddCell(cell.SRC, null);
            }

            // Retrieve the values for the cells
            var surface = new ShapeSheetSurface(shape);
            var dataset = query.GetFormulasAndResults(surface);

            // Now store the values
            for (int col = 0; col < query.Cells.Count; col++)
            {
                var result  = dataset.Cells[col].Result;
                var formula = dataset.Cells[col].Formula;

                var cellrec = desired_cells[col];
                cellrec.Result  = result;
                cellrec.Formula = formula.Value;
            }
        }
コード例 #5
0
            public static List <XForm> Get(IVisio.Page page, TargetShapeIDs target)
            {
                if (query == null)
                {
                    query      = new VisioAutomation.ShapeSheet.Queries.Query();
                    ColPinX    = query.AddCell(VisioAutomation.ShapeSheet.SRCConstants.PinX, "PinX");
                    ColPinY    = query.AddCell(VisioAutomation.ShapeSheet.SRCConstants.PinY, "PinY");
                    ColLocPinX = query.AddCell(VisioAutomation.ShapeSheet.SRCConstants.LocPinX, "LocPinX");
                    ColLocPinY = query.AddCell(VisioAutomation.ShapeSheet.SRCConstants.LocPinY, "LocPinY");
                    ColWidth   = query.AddCell(VisioAutomation.ShapeSheet.SRCConstants.Width, "Width");
                    ColHeight  = query.AddCell(VisioAutomation.ShapeSheet.SRCConstants.Height, "Height");
                }

                var surface = new VisioAutomation.ShapeSheet.ShapeSheetSurface(page);
                var results = query.GetResults <double>(surface, target.ShapeIDs);

                if (results.Count != target.ShapeIDs.Count)
                {
                    throw new VisioAutomation.Exceptions.InternalAssertionException("Didn't get as many rows back as expected");
                }
                var list = new List <XForm>(target.ShapeIDs.Count);

                foreach (var row in results)
                {
                    var xform = new XForm();
                    xform.PinX    = row.Cells[ColPinX];
                    xform.PinY    = row.Cells[ColPinY];
                    xform.LocPinX = row.Cells[ColLocPinX];
                    xform.LocPinY = row.Cells[ColLocPinY];
                    xform.Width   = row.Cells[ColWidth];
                    xform.Height  = row.Cells[ColHeight];
                    list.Add(xform);
                }
                return(list);
            }
コード例 #6
0
        public static VisioAutomation.Drawing.Size GetSize(IVisio.Shape shape)
        {
            var query = new VisioAutomation.ShapeSheet.Queries.Query();
            var col_w = query.AddCell(VisioAutomation.ShapeSheet.SRCConstants.Width, "Width");
            var col_h = query.AddCell(VisioAutomation.ShapeSheet.SRCConstants.Height, "Height");

            var    ss    = new ShapeSheetSurface(shape);
            var    table = query.GetResults <double>(ss);
            double w     = table.Cells[col_w];
            double h     = table.Cells[col_h];
            var    size  = new VisioAutomation.Drawing.Size(w, h);

            return(size);
        }
コード例 #7
0
        public static VA.Drawing.Size GetPageSize(IVisio.Page page)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException(nameof(page));
            }

            var query      = new VisioAutomation.ShapeSheet.Queries.Query();
            var col_height = query.AddCell(VA.ShapeSheet.SRCConstants.PageHeight, "PageHeight");
            var col_width  = query.AddCell(VA.ShapeSheet.SRCConstants.PageWidth, "PageWidth");

            var    ss      = new ShapeSheetSurface(page.PageSheet);
            var    results = query.GetResults <double>(ss);
            double height  = results.Cells[col_height];
            double width   = results.Cells[col_width];
            var    s       = new VA.Drawing.Size(width, height);

            return(s);
        }
コード例 #8
0
        public Drawing.Size GetSize()
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

            var application = this._client.Application.Get();
            var active_page = application.ActivePage;


            var query        = new VisioAutomation.ShapeSheet.Queries.Query();
            var col_height   = query.AddCell(VisioAutomation.ShapeSheet.SRCConstants.PageHeight, "PageHeight");
            var col_width    = query.AddCell(VisioAutomation.ShapeSheet.SRCConstants.PageWidth, "PageWidth");
            var page_surface = new ShapeSheetSurface(active_page.PageSheet);

            var    results = query.GetResults <double>(page_surface);
            double height  = results.Cells[col_height];
            double width   = results.Cells[col_width];
            var    s       = new Drawing.Size(width, height);

            return(s);
        }
コード例 #9
0
        public void ShapeSheet_Writer_Formulas_MultipleShapes()
        {
            var page1 = this.GetNewPage();

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


            // Set the formulas
            var writer = new FormulaWriterSIDSRC();

            writer.SetFormula(shape1.ID16, ShapeSheetWriterTests.src_pinx, 0.5);
            writer.SetFormula(shape1.ID16, ShapeSheetWriterTests.src_piny, 0.5);
            writer.SetFormula(shape2.ID16, ShapeSheetWriterTests.src_pinx, 1.5);
            writer.SetFormula(shape2.ID16, ShapeSheetWriterTests.src_piny, 1.5);
            writer.SetFormula(shape3.ID16, ShapeSheetWriterTests.src_pinx, 2.5);
            writer.SetFormula(shape3.ID16, ShapeSheetWriterTests.src_piny, 2.5);
            writer.Commit(page1);

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

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

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

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

            page1.Delete(0);
        }
コード例 #10
0
        public static DataTable QueryToDataTable(VisioAutomation.ShapeSheet.Queries.Query cellQuery, bool getresults, Model.ResultType ResultType, IList <int> shapeids, ShapeSheetSurface surface)
        {
            if (!getresults)
            {
                var output = cellQuery.GetFormulas(surface, shapeids);
                return(Helpers.querytable_to_datatable(cellQuery, output));
            }

            switch (ResultType)
            {
            case Model.ResultType.String:
            {
                var output = cellQuery.GetResults <string>(surface, shapeids);
                return(Helpers.querytable_to_datatable(cellQuery, output));
            }

            case Model.ResultType.Boolean:
            {
                var output = cellQuery.GetResults <bool>(surface, shapeids);
                return(Helpers.querytable_to_datatable(cellQuery, output));
            }

            case Model.ResultType.Double:
            {
                var output = cellQuery.GetResults <double>(surface, shapeids);
                return(Helpers.querytable_to_datatable(cellQuery, output));
            }

            case Model.ResultType.Integer:
            {
                var output = cellQuery.GetResults <int>(surface, shapeids);
                return(Helpers.querytable_to_datatable(cellQuery, output));
            }
            }

            throw new VisioApplicationException("Unsupported Result type");
        }
コード例 #11
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 VisioAutomation.ShapeSheet.Queries.Query();
            int i     = 0;

            foreach (var src in page_srcs)
            {
                query.AddCell(src, "Col" + i.ToString());
                i++;
            }
            var src_surface  = new VisioAutomation.ShapeSheet.ShapeSheetSurface(src_page.PageSheet);
            var src_formulas = query.GetFormulas(src_surface);

            // Set the Cells on the Destination

            var writer = new FormulaWriterSRC();

            for (i = 0; i < page_srcs.Count; i++)
            {
                writer.SetFormula(page_srcs[i], src_formulas.Cells[i]);
            }
            writer.Commit(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);
            }
        }