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);
        }
        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);
        }
Exemplo n.º 3
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");
        }
Exemplo n.º 4
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);
            }
        }