예제 #1
0
        private static Drawing.Size GetSize(IVisio.Page page)
        {
            var query      = new ShapeSheet.Queries.Query();
            var col_height = query.AddCell(ShapeSheet.SRCConstants.PageHeight, "PageHeight");
            var col_width  = query.AddCell(ShapeSheet.SRCConstants.PageWidth, "PageWidth");

            var    page_surface = new ShapeSheetSurface(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);
        }
예제 #2
0
        public QueryResult <T> GetResults <T>(IVisio.Shape shape)
        {
            this.Freeze();

            var surface = new ShapeSheetSurface(shape);

            var srcstream = this.BuildSRCStream(surface);
            var unitcodes = this.BuildUnitCodeArray(1);
            var values    = surface.GetResults_SRC <T>(srcstream, unitcodes);
            var r         = new QueryResult <T>(shape.ID);

            this.FillValuesForShape <T>(values, r, 0, 0);
            return(r);
        }
        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);
        }
예제 #4
0
        public static List <TabStop> GetTabStops(IVisio.Shape shape)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            int num_stops = GetTabStopCount(shape);

            if (num_stops < 1)
            {
                return(new List <TabStop>(0));
            }

            const short row = 0;


            var srcs = new List <ShapeSheet.SRC>(num_stops * 3);

            for (int stop_index = 0; stop_index < num_stops; stop_index++)
            {
                int i = stop_index * 3;

                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));

                srcs.Add(src_tabpos);
                srcs.Add(src_tabalign);
                srcs.Add(src_tabother);
            }

            var surface = new ShapeSheetSurface(shape);

            var stream    = ShapeSheet.SRC.ToStream(srcs);
            var unitcodes = srcs.Select(i => IVisio.VisUnitCodes.visNumber).ToList();
            var results   = QueryHelpers.GetResults_SRC <double>(surface, stream, unitcodes);

            var stops_list = new List <TabStop>(num_stops);

            for (int stop_index = 0; stop_index < num_stops; stop_index++)
            {
                var pos   = results[(stop_index * 3) + 1];
                var align = (TabStopAlignment)((int)results[(stop_index * 3) + 2]);
                var ts    = new TabStop(pos, align);
                stops_list.Add(ts);
            }

            return(stops_list);
        }
예제 #5
0
        public static List <TabStop> GetTabStops(IVisio.Shape shape)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            int num_stops = GetTabStopCount(shape);

            if (num_stops < 1)
            {
                return(new List <TabStop>(0));
            }

            const short row = 0;

            var stream = new VisioAutomation.ShapeSheet.Streams.SrcStreamBuilder(num_stops * 3);

            for (int stop_index = 0; stop_index < num_stops; stop_index++)
            {
                int i = stop_index * 3;

                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));

                stream.Add(src_tabpos);
                stream.Add(src_tabalign);
                stream.Add(src_tabother);
            }

            var surface = new ShapeSheetSurface(shape);

            const object[] unitcodes = null;

            var results = surface.GetResults <double>(stream.ToStream(), unitcodes);

            var stops_list = new List <TabStop>(num_stops);

            for (int stop_index = 0; stop_index < num_stops; stop_index++)
            {
                var pos   = results[(stop_index * 3) + 1];
                var align = (TabStopAlignment)((int)results[(stop_index * 3) + 2]);
                var ts    = new TabStop(pos, align);
                stops_list.Add(ts);
            }

            return(stops_list);
        }
예제 #6
0
        public void ShapeSheet_Query_Demo_MultipleShapes()
        {
            var page1 = this.GetNewPage(new VisioAutomation.Drawing.Size(10, 10));

            // draw a simple shape
            var s1 = page1.DrawRectangle(0, 0, 2, 2);
            var s2 = page1.DrawRectangle(4, 4, 6, 6);
            var s3 = page1.DrawRectangle(5, 5, 7, 7);

            var shapeids = new List <int> {
                s1.ID, s2.ID, s3.ID
            };

            Assert.AreEqual(3, page1.Shapes.Count);

            var query    = new VisioAutomation.ShapeSheet.Queries.Query();
            var col_pinx = query.AddCell(VA.ShapeSheet.SRCConstants.PinX, "PinX");
            var col_piny = query.AddCell(VA.ShapeSheet.SRCConstants.PinY, "PinY");

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

            var expected_formulas = new[, ]
            {
                { "1 in", "1 in" },
                { "5 in", "5 in" },
                { "6 in", "6 in" }
            };

            var expected_results = new[, ]
            {
                { 1.0, 1.0 },
                { 5.0, 5.0 },
                { 6.0, 6.0 }
            };


            for (int row = 0; row < data_results.Count; row++)
            {
                for (int col = 0; col < query.Cells.Count; col++)
                {
                    Assert.AreEqual(expected_formulas[row, col], data_formulas[row].Cells[col]);
                    Assert.AreEqual(expected_results[row, col], data_results[row].Cells[col]);
                }
            }

            page1.Delete(0);
        }
예제 #7
0
        public void ShapeSheet_Query_SectionRowHandling()
        {
            var page1 = this.GetNewPage();
            var s1    = page1.DrawRectangle(0, 0, 2, 2);
            var s2    = page1.DrawRectangle(2, 1, 3, 3);
            var s3    = page1.DrawRectangle(3, 1, 4, 2);
            var s4    = page1.DrawRectangle(4, -1, 5, 1);

            VACUSTPROP.CustomPropertyHelper.Set(s1, "S1P1", "1");
            VACUSTPROP.CustomPropertyHelper.Set(s2, "S2P1", "2");
            VACUSTPROP.CustomPropertyHelper.Set(s2, "S2P2", "3");
            //set nothing for s3
            VACUSTPROP.CustomPropertyHelper.Set(s4, "S3P1", "4");
            VACUSTPROP.CustomPropertyHelper.Set(s4, "S3P2", "5");
            VACUSTPROP.CustomPropertyHelper.Set(s4, "S3P3", "6");

            var query = new VisioAutomation.ShapeSheet.Queries.Query();

            var prop_sec  = query.AddSubQuery(IVisio.VisSectionIndices.visSectionProp);
            var value_col = prop_sec.AddCell(VA.ShapeSheet.SRCConstants.Prop_Value, "Value");

            var shapeids = new[] { s1.ID, s2.ID, s3.ID, s4.ID };

            var surface = new ShapeSheetSurface(page1);
            var data    = query.GetFormulasAndResults(surface, shapeids);

            Assert.AreEqual(4, data.Count);
            Assert.AreEqual(1, data[0].Sections[prop_sec].Rows.Count);
            Assert.AreEqual(2, data[1].Sections[prop_sec].Rows.Count);
            Assert.AreEqual(0, data[2].Sections[prop_sec].Rows.Count);
            Assert.AreEqual(3, data[3].Sections[prop_sec].Rows.Count);

            Assert.AreEqual("\"1\"", data[0].Sections[prop_sec].Rows[0].Cells[0].Formula);
            Assert.AreEqual("\"2\"", data[1].Sections[prop_sec].Rows[0].Cells[0].Formula);
            Assert.AreEqual("\"3\"", data[1].Sections[prop_sec].Rows[1].Cells[0].Formula);
            Assert.AreEqual("\"4\"", data[3].Sections[prop_sec].Rows[0].Cells[0].Formula);
            Assert.AreEqual("\"5\"", data[3].Sections[prop_sec].Rows[1].Cells[0].Formula);
            Assert.AreEqual("\"6\"", data[3].Sections[prop_sec].Rows[2].Cells[0].Formula);


            Assert.AreEqual("1", data[0].Sections[prop_sec].Rows[0].Cells[0].Result);
            Assert.AreEqual("2", data[1].Sections[prop_sec].Rows[0].Cells[0].Result);
            Assert.AreEqual("3", data[1].Sections[prop_sec].Rows[1].Cells[0].Result);
            Assert.AreEqual("4", data[3].Sections[prop_sec].Rows[0].Cells[0].Result);
            Assert.AreEqual("5", data[3].Sections[prop_sec].Rows[1].Cells[0].Result);
            Assert.AreEqual("6", data[3].Sections[prop_sec].Rows[2].Cells[0].Result);

            page1.Delete(0);
        }
예제 #8
0
        public QueryOutputCollection <TResult> GetResults <TResult>(ShapeSheetSurface surface, IList <int> shapeids)
        {
            var shapes = new List <IVisio.Shape>(shapeids.Count);

            shapes.AddRange(shapeids.Select(shapeid => surface.Target.Shapes.ItemFromID16[(short)shapeid]));

            this.cache_section_info(shapes);
            var            srcstream   = this._build_sidsrc_stream(shapeids);
            const object[] unitcodes   = null;
            var            values      = surface.GetResults <TResult>(srcstream, unitcodes);
            var            seg_builder = new VisioAutomation.Utilities.ArraySegmentReader <TResult>(values);
            var            list        = this._create_outputs_for_shapes(shapeids, _cache, seg_builder);

            return(list);
        }
예제 #9
0
        public Output <ShapeSheet.CellData> GetFormulasAndResults(ShapeSheetSurface surface)
        {
            var srcstream     = this._build_src_stream(surface);
            var unitcodes     = this._build_unit_code_array(1);
            var formulas      = QueryHelpers.GetFormulasU_SRC(surface, srcstream);
            var results       = QueryHelpers.GetResults_SRC <string>(surface, srcstream, unitcodes);
            var combined_data = CellData.Combine(formulas, results);

            var shape_index      = 0;
            var cursor           = 0;
            var subqueryinfo     = this._safe_get_subquery_output_for_shape(shape_index);
            var output_for_shape = this._create_output_for_shape <ShapeSheet.CellData>(surface.Target.ID16, combined_data, subqueryinfo, ref cursor);

            return(output_for_shape);
        }
예제 #10
0
        private short[] BuildSIDSRCStream(ShapeSheetSurface surface, IList <int> shapeids)
        {
            this.CalculatePerShapeInfo(surface, shapeids);

            int total = this.GetTotalCellCount(shapeids.Count);

            var stream_builder = new StreamBuilder(4, total);

            for (int i = 0; i < shapeids.Count; i++)
            {
                // For each shape add the cells to query
                var shapeid = shapeids[i];
                foreach (var col in this.CellColumns)
                {
                    var src = col.SRC;
                    stream_builder.Add((short)shapeid, src.Section, src.Row, src.Cell);
                }

                // And then the sections if any exist
                if (this._per_shape_section_info.Count > 0)
                {
                    var data_for_shape = this._per_shape_section_info[i];
                    foreach (var section in data_for_shape)
                    {
                        foreach (int rowindex in section.RowIndexes)
                        {
                            foreach (var col in section.SectionColumn.CellColumns)
                            {
                                stream_builder.Add(
                                    (short)shapeid,
                                    (short)section.SectionColumn.SectionIndex,
                                    (short)rowindex,
                                    col.SRC.Cell);
                            }
                        }
                    }
                }
            }

            if (stream_builder.ChunksWrittenCount != total)
            {
                string msg = String.Format("Expected {0} Chunks to be written. Actual = {1}", total,
                                           stream_builder.ChunksWrittenCount);
                throw new AutomationException(msg);
            }

            return(stream_builder.Stream);
        }
예제 #11
0
        protected override void _commit_to_surface(ShapeSheetSurface surface)
        {
            // Do nothing if there aren't any updates
            if (this.ValueItems.Count < 1)
            {
                return;
            }

            var stream = SIDSRC.ToStream(this.StreamItems);

            var unitcodes = WriterHelper.build_results_arrays_unitcode(this.ValueItems);
            var results   = WriterHelper.build_results_arrays_results(this.ValueItems);
            var flags     = this.ComputeGetResultFlags(this.ValueItems[0].ResultType);

            surface.SetResults(stream, unitcodes, results, (short)flags);
        }
예제 #12
0
        private short[] _build_sidsrc_stream(ShapeSheetSurface surface, IList <int> shapeids)
        {
            this._calcualte_per_shape_info(surface, shapeids);

            int total = this._get_total_cell_count(shapeids.Count);

            var stream_builder = new StreamBuilderSIDSRC(total);

            for (int i = 0; i < shapeids.Count; i++)
            {
                // For each shape add the cells to query
                var shapeid = shapeids[i];
                foreach (var col in this.Cells)
                {
                    var src = col.SRC;
                    stream_builder.Add((short)shapeid, src.Section, src.Row, src.Cell);
                }

                // And then the sections if any exist
                if (this._subquery_shape_info.Count > 0)
                {
                    var data_for_shape = this._subquery_shape_info[i];
                    foreach (var section in data_for_shape)
                    {
                        foreach (int rowindex in section.RowIndexes)
                        {
                            foreach (var col in section.SubQuery.Columns)
                            {
                                stream_builder.Add(
                                    (short)shapeid,
                                    (short)section.SubQuery.SectionIndex,
                                    (short)rowindex,
                                    col.CellIndex);
                            }
                        }
                    }
                }
            }

            if (!stream_builder.IsFull)
            {
                string msg = string.Format("StreamBuilder is not full");
                throw new InternalAssertionException(msg);
            }

            return(stream_builder.Stream);
        }
예제 #13
0
        public QueryOutputCollection <ShapeSheet.CellData> GetFormulasAndResults(ShapeSheetSurface surface, IList <int> shapeids)
        {
            var shapes = new List <IVisio.Shape>(shapeids.Count);

            shapes.AddRange(shapeids.Select(shapeid => surface.Target.Shapes.ItemFromID16[(short)shapeid]));

            this.cache_section_info(shapes);
            var            srcstream     = this._build_sidsrc_stream(shapeids);
            const object[] unitcodes     = null;
            var            results       = surface.GetResults <string>(srcstream, unitcodes);
            var            formulas      = surface.GetFormulasU(srcstream);
            var            combined_data = CellData.Combine(formulas, results);

            var seg_builder = new VisioAutomation.Utilities.ArraySegmentReader <CellData>(combined_data);
            var r           = this._create_outputs_for_shapes(shapeids, _cache, seg_builder);

            return(r);
        }
예제 #14
0
        protected static IList <T> _GetCells <T, RT>(
            IVisio.Page page, IList <int> shapeids,
            Query.CellQuery query,
            RowToObject <T, RT> row_to_object)
        {
            CellGroup.check_query(query);

            var surface         = new ShapeSheetSurface(page);
            var data_for_shapes = query.GetCellData <RT>(surface, shapeids);
            var list            = new List <T>(shapeids.Count);

            foreach (var data_for_shape in data_for_shapes)
            {
                var cells = row_to_object(data_for_shape.Cells);
                list.Add(cells);
            }
            return(list);
        }
예제 #15
0
        public QueryOutput <string> GetFormulas(ShapeSheetSurface surface)
        {
            RestrictToShapesOnly(surface);

            var shapes = new List <IVisio.Shape> {
                surface.Target.Shape
            };

            this.cache_section_info(shapes);
            var srcstream        = this._build_src_stream();
            var values           = surface.GetFormulasU(srcstream);
            var shape_index      = 0;
            var sectioninfo      = this.GetSectionInfoForShape(shape_index, _cache);
            var seg_builder      = new VisioAutomation.Utilities.ArraySegmentReader <string>(values);
            var output_for_shape = this._create_output_for_shape(surface.Target.ID16, sectioninfo, seg_builder);

            return(output_for_shape);
        }
예제 #16
0
        public static TResult[] _GetResults <TResult>(ShapeSheetSurface surface, short[] stream, IList <IVisio.VisUnitCodes> unitcodes, int numitems)
        {
            EnforceValidResultType(typeof(TResult));

            if (numitems < 1)
            {
                return(new TResult[0]);
            }

            var result_type         = typeof(TResult);
            var unitcodes_obj_array = get_unit_code_obj_array(unitcodes);
            var flags = get_VisGetSetArgs(result_type);

            System.Array results_sa = null;

            if (surface.Target.Master != null)
            {
                surface.Target.Master.GetResults(stream, (short)flags, unitcodes_obj_array, out results_sa);
            }
            else if (surface.Target.Page != null)
            {
                surface.Target.Page.GetResults(stream, (short)flags, unitcodes_obj_array, out results_sa);
            }
            else if (surface.Target.Shape != null)
            {
                surface.Target.Shape.GetResults(stream, (short)flags, unitcodes_obj_array, out results_sa);
            }
            else
            {
                throw new System.ArgumentException("Unhandled Target");
            }

            if (results_sa.Length != numitems)
            {
                string msg = string.Format("Expected {0} items from GetResults but only received {1}", numitems,
                                           results_sa.Length);
                throw new InternalAssertionException(msg);
            }

            var results = new TResult[results_sa.Length];

            results_sa.CopyTo(results, 0);
            return(results);
        }
예제 #17
0
        private void CalculatePerShapeInfo(ShapeSheetSurface surface, IList <int> shapeids)
        {
            this._per_shape_section_info = new List <List <SectionColumnDetails> >();

            if (this.SectionColumns.Count < 1)
            {
                return;
            }

            var pageshapes = surface.Shapes;

            // For each shapeid fetch the corresponding shape from the page
            // this is needed because we'll need to get per shape section information
            var shapes = new List <IVisio.Shape>(shapeids.Count);

            foreach (int shapeid in shapeids)
            {
                var shape = pageshapes.ItemFromID16[(short)shapeid];
                shapes.Add(shape);
            }

            for (int n = 0; n < shapeids.Count; n++)
            {
                var shapeid = (short)shapeids[n];
                var shape   = shapes[n];

                var section_infos = new List <SectionColumnDetails>(this.SectionColumns.Count);
                foreach (var sec in this.SectionColumns)
                {
                    int num_rows     = CellQuery.GetNumRowsForSection(shape, sec);
                    var section_info = new SectionColumnDetails(sec, shapeid, num_rows);
                    section_infos.Add(section_info);
                }
                this._per_shape_section_info.Add(section_infos);
            }

            if (shapeids.Count != this._per_shape_section_info.Count)
            {
                string msg = String.Format("Expected {0} PerShape structs. Actual = {1}", shapeids.Count,
                                           this._per_shape_section_info.Count);
                throw new AutomationException(msg);
            }
        }
예제 #18
0
        private void CommitFormulas(ShapeSheetSurface surface)
        {
            if ((this._formulaRecords == null || this._formulaRecords.Count < 1))
            {
                return;
            }

            var stream   = this.buildstream_sidsrc(this._formulaRecords);
            var formulas = this._formulaRecords.BuildValues();

            if (stream.Array.Length == 0)
            {
                throw new VisioAutomation.Exceptions.InternalAssertionException();
            }

            var flags = this.ComputeGetFormulaFlags();

            int c = surface.SetFormulas(stream, formulas, (short)flags);
        }
예제 #19
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);
        }
예제 #20
0
        protected override void ProcessRecord()
        {
            var cellmap = VisioAutomation.Scripting.ShapeSheet.CellSRCDictionary.GetCellMapForPages();

            if (this.Cells == null || this.Cells.Length < 1 || this.Cells.Contains("*"))
            {
                this.Cells = cellmap.GetNames().ToArray();
            }
            Get_VisioPageCell.EnsureEnoughCellNames(this.Cells);
            var target_page = this.Page ?? this.Client.Page.Get();

            this.WriteVerbose("Valid Names: " + string.Join(",", cellmap.GetNames()));
            var query           = cellmap.ToQuery(this.Cells);
            var surface         = new ShapeSheetSurface(target_page);
            var target_shapeids = new[] { surface.Target.Page.PageSheet.ID };
            var dt = Helpers.QueryToDataTable(query, this.GetResults, this.ResultType, target_shapeids, surface);

            this.WriteObject(dt);
        }
예제 #21
0
        private void _calcualte_per_shape_info(ShapeSheetSurface surface, IList <int> shapeids)
        {
            this._subquery_shape_info = new List <List <SubQuerySectionDetails> >();

            if (this.SubQueries.Count < 1)
            {
                return;
            }

            var pageshapes = surface.Target.Shapes;

            // For each shapeid fetch the corresponding shape from the page
            // this is needed because we'll need to get per shape section information
            var shapes = new List <IVisio.Shape>(shapeids.Count);

            foreach (int shapeid in shapeids)
            {
                var shape = pageshapes.ItemFromID16[(short)shapeid];
                shapes.Add(shape);
            }

            for (int n = 0; n < shapeids.Count; n++)
            {
                var shape = shapes[n];

                var section_infos = new List <SubQuerySectionDetails>(this.SubQueries.Count);
                foreach (var sec in this.SubQueries)
                {
                    int num_rows     = _get_num_rows_for_section(shape, sec);
                    var section_info = new SubQuerySectionDetails(sec, num_rows);
                    section_infos.Add(section_info);
                }
                this._subquery_shape_info.Add(section_infos);
            }

            if (shapeids.Count != this._subquery_shape_info.Count)
            {
                string msg = string.Format("Expected {0} PerShape structs. Actual = {1}", shapeids.Count,
                                           this._subquery_shape_info.Count);
                throw new InternalAssertionException(msg);
            }
        }
예제 #22
0
        private void CommitResults(ShapeSheetSurface surface)
        {
            if ((this._resultRecords == null || this._resultRecords.Count < 1))
            {
                return;
            }

            var            stream    = this.buildstream_sidsrc(this._resultRecords);
            var            results   = this._resultRecords.BuildValues();
            const object[] unitcodes = null;

            if (stream.Array.Length == 0)
            {
                throw new VisioAutomation.Exceptions.InternalAssertionException();
            }

            var flags = this.ComputeGetResultFlags();

            surface.SetResults(stream, unitcodes, results, (short)flags);
        }
예제 #23
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 static IList <List <T> > _GetCells <T, RT>(
            IVisio.Page page,
            IList <int> shapeids,
            VAQUERY.CellQuery query,
            RowToObject <T, RT> row_to_object)
        {
            CellGroupMultiRow.check_query(query);

            var list            = new List <List <T> >(shapeids.Count);
            var surface         = new ShapeSheetSurface(page);
            var data_for_shapes = query.GetCellData <RT>(surface, shapeids);

            foreach (var data_for_shape in data_for_shapes)
            {
                var sec         = data_for_shape.Sections[0];
                var sec_objects = CellGroupMultiRow.SectionToObjectList(sec, row_to_object);
                list.Add(sec_objects);
            }

            return(list);
        }
        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);
        }
예제 #26
0
        public QueryOutput <ShapeSheet.CellData> GetFormulasAndResults(ShapeSheetSurface surface)
        {
            RestrictToShapesOnly(surface);

            var shapes = new List <IVisio.Shape> {
                surface.Target.Shape
            };

            this.cache_section_info(shapes);
            var            srcstream     = this._build_src_stream();
            const object[] unitcodes     = null;
            var            formulas      = surface.GetFormulasU(srcstream);
            var            results       = surface.GetResults <string>(srcstream, unitcodes);
            var            combined_data = CellData.Combine(formulas, results);

            var shape_index      = 0;
            var sectioninfo      = this.GetSectionInfoForShape(shape_index, _cache);
            var seg_builder      = new VisioAutomation.Utilities.ArraySegmentReader <CellData>(combined_data);
            var output_for_shape = this._create_output_for_shape(surface.Target.ID16, sectioninfo, seg_builder);

            return(output_for_shape);
        }
예제 #27
0
        public QueryResultList <CellData <T> > GetCellData <T>(ShapeSheetSurface surface, IList <int> shapeids)
        {
            this.Freeze();

            var srcstream = this.BuildSIDSRCStream(surface, shapeids);
            var unitcodes = this.BuildUnitCodeArray(shapeids.Count);

            T[]      results  = surface.GetResults_SIDSRC <T>(srcstream, unitcodes);
            string[] formulas = surface.GetFormulasU_SIDSRC(srcstream);

            // Merge the results and formulas
            var combined_data = new CellData <T> [results.Length];

            for (int i = 0; i < results.Length; i++)
            {
                combined_data[i] = new CellData <T>(formulas[i], results[i]);
            }

            var r = this.FillValuesForMultipleShapes(shapeids, combined_data);

            return(r);
        }
예제 #28
0
        private static string[] _GetFormulasU(ShapeSheetSurface surface, short[] stream, int numitems)
        {
            if (numitems < 1)
            {
                return(new string[0]);
            }

            System.Array formulas_sa = null;

            if (surface.Target.Master != null)
            {
                surface.Target.Master.GetFormulasU(stream, out formulas_sa);
            }
            else if (surface.Target.Page != null)
            {
                surface.Target.Page.GetFormulasU(stream, out formulas_sa);
            }
            else if (surface.Target.Shape != null)
            {
                surface.Target.Shape.GetFormulasU(stream, out formulas_sa);
            }
            else
            {
                throw new System.ArgumentException("Unhandled Drawing Surface");
            }

            object[] formulas_obj_array = (object[])formulas_sa;

            if (formulas_obj_array.Length != numitems)
            {
                string msg = string.Format("Expected {0} items from GetFormulas but only received {1}", numitems,
                                           formulas_obj_array.Length);
                throw new InternalAssertionException(msg);
            }

            string[] formulas = new string[formulas_obj_array.Length];
            formulas_obj_array.CopyTo(formulas, 0);
            return(formulas);
        }
예제 #29
0
        public QueryResult <CellData <T> > GetCellData <T>(IVisio.Shape shape)
        {
            this.Freeze();

            var surface = new ShapeSheetSurface(shape);

            var srcstream = this.BuildSRCStream(surface);
            var unitcodes = this.BuildUnitCodeArray(1);
            var formulas  = surface.GetFormulasU_SRC(srcstream);
            var results   = surface.GetResults_SRC <T>(srcstream, unitcodes);

            var combineddata = new CellData <T> [results.Length];

            for (int i = 0; i < results.Length; i++)
            {
                combineddata[i] = new CellData <T>(formulas[i], results[i]);
            }

            var r = new QueryResult <CellData <T> >(shape.ID16);

            this.FillValuesForShape <CellData <T> >(combineddata, r, 0, 0);
            return(r);
        }
예제 #30
0
        public QueryOutput <TResult> GetResults <TResult>(IVisio.Shape shape)
        {
            var surface = new ShapeSheetSurface(shape);

            return(GetResults <TResult>(surface));
        }