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