public VA.ShapeSheet.Query.CellQuery.QueryResultList <string> QueryFormulas(IList <IVisio.Shape> target_shapes, IVisio.VisSectionIndices section, IList <IVisio.VisCellIndices> cells) { this.AssertApplicationAvailable(); this.AssertDocumentAvailable(); var shapes = this.GetTargetShapes(target_shapes); var shapeids = shapes.Select(s => s.ID).ToList(); var surface = this.Client.Draw.GetDrawingSurfaceSafe(); var query = new VA.ShapeSheet.Query.CellQuery(); var sec = query.Sections.Add(section); int ci = 0; foreach (var cell in cells) { string name = string.Format("Cell{0}", ci); sec.Columns.Add((short)cell, name); ci++; } var formulas = query.GetFormulas(surface, shapeids); return(formulas); }
public static List <ShapeXFormData> Get(IVisio.Page page, TargetShapeIDs target) { if (_static_query == null) { _static_query = new VASS.Query.CellQuery(); var cols = _static_query.Columns; _static_col_x_form_pin_x = cols.Add(VASS.SrcConstants.XFormPinX, nameof(ShapeXFormData.XFormPinX)); _static_col_x_form_pin_y = cols.Add(VASS.SrcConstants.XFormPinY, nameof(ShapeXFormData.XFormPinY)); _static_col_x_form_loc_pin_x = cols.Add(VASS.SrcConstants.XFormLocPinX, nameof(ShapeXFormData.XFormLocPinX)); _static_col_x_form_loc_pin_y = cols.Add(VASS.SrcConstants.XFormLocPinY, nameof(ShapeXFormData.XFormLocPinY)); _static_col_x_form_width = cols.Add(VASS.SrcConstants.XFormWidth, nameof(ShapeXFormData.XFormWidth)); _static_col_x_form_height = cols.Add(VASS.SrcConstants.XFormHeight, nameof(ShapeXFormData.XFormHeight)); } var results = _static_query.GetResults <double>(page, 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 <ShapeXFormData>(target.ShapeIDs.Count); foreach (var row in results) { var xform = new ShapeXFormData(); xform.XFormPinX = row[_static_col_x_form_pin_x]; xform.XFormPinY = row[_static_col_x_form_pin_y]; xform.XFormLocPinX = row[_static_col_x_form_loc_pin_x]; xform.XFormLocPinY = row[_static_col_x_form_loc_pin_y]; xform.XFormWidth = row[_static_col_x_form_width]; xform.XFormHeight = row[_static_col_x_form_height]; list.Add(xform); } return(list); }
public VA.ShapeSheet.Query.CellQuery.QueryResultList <string> QueryFormulas(IList <IVisio.Shape> target_shapes, IList <VA.ShapeSheet.SRC> srcs) { this.AssertApplicationAvailable(); this.AssertDocumentAvailable(); var shapes = this.GetTargetShapes(target_shapes); var shapeids = shapes.Select(s => s.ID).ToList(); var surface = this.Client.Draw.GetDrawingSurfaceSafe(); var query = new VA.ShapeSheet.Query.CellQuery(); int ci = 0; foreach (var src in srcs) { string colname = string.Format("Col{0}", ci); query.Columns.Add(src, colname); ci++; } var formulas = query.GetFormulas(surface, shapeids); return(formulas); }
public static System.Data.DataTable QueryToDataTable(VA.ShapeSheet.Query.CellQuery cellQuery, bool getresults, ResultType ResultType, IList <int> shapeids, VA.Drawing.DrawingSurface surface) { if (getresults) { if (ResultType == ResultType.String) { var output = cellQuery.GetResults <string>(surface, shapeids); return(Helpers.querytable_to_datatable(cellQuery, output)); } else if (ResultType == ResultType.Boolean) { var output = cellQuery.GetResults <bool>(surface, shapeids); return(Helpers.querytable_to_datatable(cellQuery, output)); } else if (ResultType == ResultType.Double) { var output = cellQuery.GetResults <double>(surface, shapeids); return(Helpers.querytable_to_datatable(cellQuery, output)); } else if (ResultType == ResultType.Integer) { var output = cellQuery.GetResults <int>(surface, shapeids); return(Helpers.querytable_to_datatable(cellQuery, output)); } else { throw new VA.Scripting.VisioApplicationException("Unsupported Result type"); } } else { var output = cellQuery.GetFormulas(surface, shapeids); return(Helpers.querytable_to_datatable(cellQuery, output)); } }
public void CheckHomogenousUpdates_ResultTypes() { var page1 = this.GetNewPage(); var shape1 = page1.DrawRectangle(0, 0, 1, 1); // Setup the modifications to the cell values var update = new VA.ShapeSheet.Update(); update.SetResult(ShapeSheet_Update_Tests.src_linepat, "7", IVisio.VisUnitCodes.visNumber); update.SetResult(VA.ShapeSheet.SRCConstants.PinX, 2, IVisio.VisUnitCodes.visNumber); update.Execute(shape1); // Build the query var query = new VA.ShapeSheet.Query.CellQuery(); var col_linepat = query.AddCell(ShapeSheet_Update_Tests.src_linepat, "LinePattern"); var col_pinx = query.AddCell(VA.ShapeSheet.SRCConstants.PinX, "PinX"); // Retrieve the values var data = query.GetCellData <double>(shape1); // Verify AssertVA.AreEqual("7", 7, data[col_linepat]); AssertVA.AreEqual("2 in", 2, data[col_pinx]); page1.Delete(0); }
public void CheckHomogenousUpdates_ResultTypes() { var page1 = GetNewPage(); var shape1 = page1.DrawRectangle(0, 0, 1, 1); // Setup the modifications to the cell values var update = new VA.ShapeSheet.Update(); update.SetResult(src_linepat, "7", IVisio.VisUnitCodes.visNumber); update.SetResult(VA.ShapeSheet.SRCConstants.PinX, 2, IVisio.VisUnitCodes.visNumber); update.Execute(shape1); // Build the query var query = new VA.ShapeSheet.Query.CellQuery(); var col_linepat = query.Columns.Add(src_linepat,"LinePattern"); var col_pinx = query.Columns.Add(VA.ShapeSheet.SRCConstants.PinX,"PinX"); // Retrieve the values var data = query.GetFormulasAndResults<double>(shape1); // Verify AssertVA.AreEqual("7", 7, data[col_linepat.Ordinal]); AssertVA.AreEqual("2 in", 2, data[col_pinx.Ordinal]); page1.Delete(0); }
private static DataTable querytable_to_datatable <T>(VisioAutomation.ShapeSheet.Query.CellQuery cellQuery, VisioAutomation.ShapeSheet.Query.QueryResultList <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.CellColumns) { dt.Columns.Add(col.Name, typeof(T)); } // Then populate the rows of the datatable dt.BeginLoadData(); int colcount = cellQuery.CellColumns.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][i]; } // load it into the table dt.Rows.Add(rowbuf); } dt.EndLoadData(); return(dt); }
private VisioAutomation.ShapeSheet.Query.CellQuery _CreateQuery( VisioPowerShell.Models.NamedCellDictionary celldic, IList <string> cells) { var invalid_names = cells.Where(cellname => !celldic.ContainsKey(cellname)).ToList(); if (invalid_names.Count > 0) { string msg = "Invalid cell names: " + string.Join(",", invalid_names); throw new ArgumentException(msg); } var query = new VisioAutomation.ShapeSheet.Query.CellQuery(); foreach (string cell in cells) { foreach (var resolved_cellname in celldic.ExpandKeyWildcard(cell)) { if (!query.Columns.Contains(resolved_cellname)) { var resolved_src = celldic[resolved_cellname]; query.Columns.Add(resolved_src, resolved_cellname); } } } return(query); }
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 VASS.Writers.SrcWriter(); writer.SetValue(LinePattern, "7"); writer.Commit(shape1, VASS.CellValueType.Formula); // Build the query var query = new VASS.Query.CellQuery(); var col_linepat = query.Columns.Add(LinePattern, nameof(LinePattern)); // Retrieve the values var data_formulas = query.GetFormulas(shape1); var data_results = query.GetResults <double>(shape1); int rownum = 0; // Verify Assert.AreEqual("7", data_formulas[rownum][col_linepat]); Assert.AreEqual(7, data_results[rownum][col_linepat]); page1.Delete(0); }
private VisioAutomation.ShapeSheet.Query.CellQuery _create_query( VisioPowerShell.Internal.NamedSrcDictionary celldic, IList <string> cellnames) { var invalid_names = cellnames.Where(cellname => !celldic.ContainsKey(cellname)).ToList(); if (invalid_names.Count > 0) { var quoted_names = invalid_names.Select(s => string.Format("\"{0}\"", s)); string msg = "Invalid cell names: " + string.Join(",", quoted_names); throw new ArgumentException(nameof(cellnames), msg); } var query = new VisioAutomation.ShapeSheet.Query.CellQuery(); foreach (string cellname in cellnames) { // resolve any wildcards to the actual cell names var resolved_cellnames = celldic.ExpandKeyWildcard(cellname); foreach (var resolved_cellname in resolved_cellnames) { if (!query.Columns.Contains(resolved_cellname)) { var resolved_src = celldic[resolved_cellname]; query.Columns.Add(resolved_src, resolved_cellname); } } } return(query); }
private VisioAutomation.ShapeSheet.Query.CellQuery _create_query( VisioPowerShell.Internal.NamedSrcDictionary dicof_named_to_cell, IList <string> cellnames) { var invalid_names = cellnames.Where(cellname => !dicof_named_to_cell.ContainsKey(cellname)).ToList(); if (invalid_names.Count > 0) { string msg = "Invalid cell names: " + string.Join(",", invalid_names); throw new ArgumentException(msg); } var query = new VisioAutomation.ShapeSheet.Query.CellQuery(); foreach (string cellname in cellnames) { foreach (var resolved_cellname in dicof_named_to_cell.ExpandKeyWildcard(cellname)) { if (!query.Columns.Contains(resolved_cellname)) { var resolved_src = dicof_named_to_cell[resolved_cellname]; query.Columns.Add(resolved_src, resolved_cellname); } } } return(query); }
public void CopyFormat(IVisio.Shape shape, FormatCategory category) { // Build the Query var query = new VA.ShapeSheet.Query.CellQuery(); var desired_cells = this.Cells.Where(cell => cell.MatchesCategory(category)).ToList(); foreach (var cell in desired_cells) { query.Columns.Add(cell.SRC, null); } // Retrieve the values for the cells var dataset = query.GetFormulasAndResults <string>(shape); // Now store the values for (int col = 0; col < query.Columns.Count; col++) { var cellrec = desired_cells[col]; var result = dataset[col].Result; var formula = dataset[col].Formula; cellrec.Result = result; cellrec.Formula = formula.Value; } }
private static DataTable querytable_to_datatable <T>( VASS.Query.CellQuery query, VASS.Query.Rows <T> output) { // First Construct a Datatable with a compatible schema var dt = new DataTable(); foreach (var col in query.Columns) { dt.Columns.Add(col.Name, typeof(T)); } // Then populate the rows of the datatable dt.BeginLoadData(); int colcount = query.Columns.Count; var rowbuf = new object[colcount]; for (int row_index = 0; row_index < output.Count; row_index++) { // populate the row buffer for (int col_index = 0; col_index < colcount; col_index++) { rowbuf[col_index] = output[row_index][col_index]; } // load it into the table dt.Rows.Add(rowbuf); } dt.EndLoadData(); return(dt); }
public void ShapeSheet_Query_Demo_AllCellsAndSections() { var doc1 = this.GetNewDoc(); var page1 = doc1.Pages[1]; VisioAutomationTest.SetPageSize(page1, this.StandardPageSize); // draw simple shapes var s1 = page1.DrawRectangle(0, 0, 1, 1); var s2 = page1.DrawRectangle(2, 2, 3, 3); var query = new VA.ShapeSheet.Query.CellQuery(); var name_to_src = VA.ShapeSheet.SRCConstants.GetSRCDictionary(); var section_to_secquery = new Dictionary <short, VA.ShapeSheet.Query.CellQuery.SectionQuery>(); foreach (var kv in name_to_src) { var name = kv.Key; var src = kv.Value; if (src.Section == (short)IVisio.VisSectionIndices.visSectionObject) { query.Columns.Add(src, name); } else if ((src.Section == (short)IVisio.VisSectionIndices.visSectionFirst) || (src.Section == (short)IVisio.VisSectionIndices.visSectionFirstComponent) || (src.Section == (short)IVisio.VisSectionIndices.visSectionLast) || (src.Section == (short)IVisio.VisSectionIndices.visSectionInval) || (src.Section == (short)IVisio.VisSectionIndices.visSectionNone) || (src.Section == (short)IVisio.VisSectionIndices.visSectionFirst) || (src.Section == (short)IVisio.VisSectionIndices.visSectionLastComponent) ) { //skip } else { VA.ShapeSheet.Query.CellQuery.SectionQuery sec; if (!section_to_secquery.ContainsKey(src.Section)) { sec = query.Sections.Add((IVisio.VisSectionIndices)src.Section); section_to_secquery[src.Section] = sec; } else { sec = section_to_secquery[src.Section]; } sec.Columns.Add(src.Cell, name); } } var formulas1 = query.GetFormulas(s1); var formulas2 = query.GetFormulas(page1, new [] { s1.ID, s2.ID }); doc1.Close(true); }
public void ShapeSheet_Query_GetResults_SingleShape() { var doc1 = this.GetNewDoc(); var page1 = doc1.Pages[1]; VisioAutomationTest.SetPageSize(page1, this.StandardPageSize); // draw a simple shape var s1 = page1.DrawRectangle(this.StandardPageSizeRect); int s1_id = s1.ID; // format it with setformulas var fg_cell = s1.Cells["FillForegnd"]; var bg_cell = s1.Cells["FillBkgnd"]; var pat_cell = s1.Cells["FillPattern"]; fg_cell.FormulaU = "RGB(255,0,0)"; bg_cell.FormulaU = "RGB(0,0,255)"; pat_cell.FormulaU = "40"; // now retrieve the formulas with GetFormulas var query = new VA.ShapeSheet.Query.CellQuery(); var col_fg = query.Columns.Add(SrcConstants.FillForeground, nameof(SrcConstants.FillForeground)); var col_bg = query.Columns.Add(SrcConstants.FillBackground, nameof(SrcConstants.FillBackground)); var col_filpat = query.Columns.Add(SrcConstants.FillPattern, nameof(SrcConstants.FillPattern)); var shapeids = new[] { s1_id }; var formulas = query.GetFormulas(page1, shapeids); // now verify that the formulas were actually set Assert.AreEqual("RGB(255,0,0)", formulas[0].Cells[col_fg]); Assert.AreEqual("RGB(0,0,255)", formulas[0].Cells[col_bg]); Assert.AreEqual("40", formulas[0].Cells[col_filpat]); // now retrieve the results with GetResults as floats var float_results = query.GetResults <double>(page1, shapeids); Assert.IsNotNull(float_results); Assert.AreEqual(40.0, float_results[0].Cells[col_filpat]); // now retrieve the results with GetResults as ints var int_results = query.GetResults <int>(page1, shapeids); Assert.AreEqual(40, int_results[0].Cells[col_filpat]); // now retrieve the results with GetResults as strings var string_results = query.GetResults <string>(page1, shapeids); Assert.AreEqual("RGB(255, 0, 0)", string_results[0].Cells[col_fg]); Assert.AreEqual("RGB(0, 0, 255)", string_results[0].Cells[col_bg]); Assert.AreEqual("40", string_results[0].Cells[col_filpat]); page1.Delete(0); doc1.Close(true); }
public void ShapeSheet_Query_TestDuplicates() { // Ensure that duplicate cells are caught var q1 = new VA.ShapeSheet.Query.CellQuery(); q1.AddCell(VA.ShapeSheet.SRCConstants.PinX, "PinX"); bool caught_exc1 = false; try { q1.AddCell(VA.ShapeSheet.SRCConstants.PinX, "PinX"); } catch (VA.AutomationException) { caught_exc1 = true; } Assert.IsTrue(caught_exc1); // Ensure that duplicate sections are caught var q2 = new VA.ShapeSheet.Query.CellQuery(); q2.AddSection(IVisio.VisSectionIndices.visSectionObject); bool caught_exc2 = false; try { q2.AddSection(IVisio.VisSectionIndices.visSectionObject); } catch (VA.AutomationException) { caught_exc2 = true; } Assert.IsTrue(caught_exc2); // Ensure that Duplicates in Section Queries Are caught - var q3 = new VA.ShapeSheet.Query.CellQuery(); var sec = q3.AddSection(IVisio.VisSectionIndices.visSectionObject); sec.AddCell(VA.ShapeSheet.SRCConstants.PinX.Cell, "PinX"); bool caught_exc3 = false; try { sec.AddCell(VA.ShapeSheet.SRCConstants.PinX.Cell, "PinX"); } catch (VA.AutomationException) { caught_exc3 = true; } Assert.IsTrue(caught_exc3); }
private void addcell(VisioAutomation.ShapeSheet.Query.CellQuery q, bool b, string name) { var dic = GetShapeCellDictionary(); if (b) { q.Columns.Add(dic[name], name); } }
public void ShapeSheet_Query_TestDuplicates() { // Ensure that duplicate cells are caught var cell_query_1 = new VASS.Query.CellQuery(); cell_query_1.Columns.Add(VASS.SrcConstants.XFormPinX, nameof(VASS.SrcConstants.XFormPinX)); bool caught_exc1 = false; try { cell_query_1.Columns.Add(VASS.SrcConstants.XFormPinX, nameof(VASS.SrcConstants.XFormPinX)); } catch (System.ArgumentException) { caught_exc1 = true; } Assert.IsTrue(caught_exc1); // Ensure that duplicate sections are caught var sec_query_2 = new VASS.Query.SectionQuery(); sec_query_2.Add(IVisio.VisSectionIndices.visSectionObject); bool caught_exc2 = false; try { sec_query_2.Add(IVisio.VisSectionIndices.visSectionObject); } catch (System.ArgumentException) { caught_exc2 = true; } Assert.IsTrue(caught_exc2); // Ensure that Duplicates in Section Queries Are caught - var sec_query_3 = new VASS.Query.SectionQuery(); var sec_cols = sec_query_3.Add(IVisio.VisSectionIndices.visSectionObject); sec_cols.Add(VASS.SrcConstants.XFormPinX, nameof(VASS.SrcConstants.XFormPinX)); bool caught_exc3 = false; try { sec_cols.Add(VASS.SrcConstants.XFormPinX, nameof(VASS.SrcConstants.XFormPinX)); } catch (System.ArgumentException) { caught_exc3 = true; } Assert.IsTrue(caught_exc3); }
public void ShapeSheet_Query_TestDuplicates() { // Ensure that duplicate cells are caught var q1 = new VA.ShapeSheet.Query.CellQuery(); q1.Columns.Add(SrcConstants.XFormPinX, nameof(SrcConstants.XFormPinX)); bool caught_exc1 = false; try { q1.Columns.Add(SrcConstants.XFormPinX, nameof(SrcConstants.XFormPinX)); } catch (System.ArgumentException) { caught_exc1 = true; } Assert.IsTrue(caught_exc1); // Ensure that duplicate sections are caught var q2 = new VA.ShapeSheet.Query.SectionsQuery(); q2.SectionQueries.Add(IVisio.VisSectionIndices.visSectionObject); bool caught_exc2 = false; try { q2.SectionQueries.Add(IVisio.VisSectionIndices.visSectionObject); } catch (System.ArgumentException) { caught_exc2 = true; } Assert.IsTrue(caught_exc2); // Ensure that Duplicates in Section Queries Are caught - var q3 = new VA.ShapeSheet.Query.SectionsQuery(); var sec = q3.SectionQueries.Add(IVisio.VisSectionIndices.visSectionObject); sec.Columns.Add(SrcConstants.XFormPinX, nameof(SrcConstants.XFormPinX)); bool caught_exc3 = false; try { sec.Columns.Add(SrcConstants.XFormPinX, nameof(SrcConstants.XFormPinX)); } catch (System.ArgumentException) { caught_exc3 = true; } Assert.IsTrue(caught_exc3); }
private void addcell(VA.ShapeSheet.Query.CellQuery query, bool switchpar, string cellname) { var dic = Get_VisioPageCell.GetPageCellDictionary(); if (switchpar) { query.Columns.Add(dic[cellname], cellname); } }
public void ShapeSheet_Query_GetResults_MultipleShapes() { var page1 = this.GetNewPage(); // draw a simple shape var s1 = page1.DrawRectangle(this.StandardPageSizeRect); int s1_id = s1.ID; // format it with setformulas var fg_cell = s1.Cells["FillForegnd"]; var bg_cell = s1.Cells["FillBkgnd"]; var pat_cell = s1.Cells["FillPattern"]; fg_cell.ResultIU = 2.0; //red bg_cell.ResultIU = 3.0; //green pat_cell.ResultIU = 40.0; // now retrieve the formulas with GetFormulas var query = new VA.ShapeSheet.Query.CellQuery(); var col_fg = query.Columns.Add(SrcConstants.FillForeground, nameof(SrcConstants.FillForeground)); var col_bg = query.Columns.Add(SrcConstants.FillBackground, nameof(SrcConstants.FillBackground)); var col_filpat = query.Columns.Add(SrcConstants.FillPattern, nameof(SrcConstants.FillPattern)); var shapeids = new[] { s1_id }; var formulas = query.GetFormulas(page1, shapeids); // now verify that the formulas were actually set Assert.AreEqual("2", formulas[0].Cells[col_fg]); Assert.AreEqual("3", formulas[0].Cells[col_bg]); Assert.AreEqual("40", formulas[0].Cells[col_filpat]); // now retrieve the results with GetResults as floats var float_results = query.GetResults <double>(page1, shapeids); Assert.AreEqual(2.0, float_results[0].Cells[col_fg]); Assert.AreEqual(3.0, float_results[0].Cells[col_bg]); Assert.AreEqual(40.0, float_results[0].Cells[col_filpat]); // now retrieve the results with GetResults as ints var int_results = query.GetResults <int>(page1, shapeids); Assert.AreEqual(2, int_results[0].Cells[col_fg]); Assert.AreEqual(3, int_results[0].Cells[col_bg]); Assert.AreEqual(40, int_results[0].Cells[col_filpat]); // now retrieve the results with GetResults as strings var string_results = query.GetResults <string>(page1, shapeids); Assert.AreEqual("2", string_results[0].Cells[col_fg]); Assert.AreEqual("3", string_results[0].Cells[col_bg]); Assert.AreEqual("40", string_results[0].Cells[col_filpat]); page1.Delete(0); }
public void ShapeSheet_Query_Demo_AllCellsAndSections() { var doc1 = this.GetNewDoc(); var page1 = doc1.Pages[1]; VisioAutomationTest.SetPageSize(page1, this.StandardPageSize); // draw simple shapes var s1 = page1.DrawRectangle(0,0,1,1); var s2 = page1.DrawRectangle(2,2,3,3); var query = new VA.ShapeSheet.Query.CellQuery(); var name_to_src = VA.ShapeSheet.SRCConstants.GetSRCDictionary(); var section_to_secquery = new Dictionary<short,VA.ShapeSheet.Query.SectionColumn>(); foreach (var kv in name_to_src) { var name = kv.Key; var src = kv.Value; if (src.Section == (short) IVisio.VisSectionIndices.visSectionObject) { query.AddCell(src, name); } else if ((src.Section == (short) IVisio.VisSectionIndices.visSectionFirst) || (src.Section == (short) IVisio.VisSectionIndices.visSectionFirstComponent) || (src.Section == (short) IVisio.VisSectionIndices.visSectionLast) || (src.Section == (short) IVisio.VisSectionIndices.visSectionInval) || (src.Section == (short) IVisio.VisSectionIndices.visSectionNone) || (src.Section == (short) IVisio.VisSectionIndices.visSectionFirst) || (src.Section == (short) IVisio.VisSectionIndices.visSectionLastComponent) ) { //skip } else { VA.ShapeSheet.Query.SectionColumn sec; if (!section_to_secquery.ContainsKey(src.Section)) { sec = query.AddSection((IVisio.VisSectionIndices)src.Section); section_to_secquery[src.Section] = sec; } else { sec = section_to_secquery[src.Section]; } sec.AddCell(src.Cell, name); } } var formulas1 = query.GetFormulas(s1); var formulas2 = query.GetFormulas(page1,new [] {s1.ID,s2.ID}); doc1.Close(true); }
public void ShapeSheet_Query_SectionCells_have_names() { var query = new VA.ShapeSheet.Query.CellQuery(); var sec_char = query.AddSection(IVisio.VisSectionIndices.visSectionCharacter); Assert.AreEqual("Character", sec_char.Name); var sec_obj = query.AddSection(IVisio.VisSectionIndices.visSectionObject); Assert.AreEqual("Object", sec_obj.Name); }
protected static T _GetCells <T, RT>( IVisio.Shape shape, VA.ShapeSheet.Query.CellQuery query, RowToObject <T, RT> row_to_object) { check_query(query); var data_for_shape = query.GetFormulasAndResults <RT>(shape); var cells = row_to_object(data_for_shape.Cells); return(cells); }
private static VA.Drawing.Size GetSize(IVisio.Page page) { var query = new VA.ShapeSheet.Query.CellQuery(); var col_height = query.Columns.Add(VA.ShapeSheet.SRCConstants.PageHeight, "PageHeight"); var col_width = query.Columns.Add(VA.ShapeSheet.SRCConstants.PageWidth, "PageWidth"); var results = query.GetResults <double>(page.PageSheet); double height = results[col_height.Ordinal]; double width = results[col_width.Ordinal]; var s = new VA.Drawing.Size(width, height); return(s); }
public static VA.Drawing.Size GetSize(IVisio.Shape shape) { var query = new VA.ShapeSheet.Query.CellQuery(); var col_w = query.Columns.Add(VA.ShapeSheet.SRCConstants.Width,"Width"); var col_h = query.Columns.Add(VA.ShapeSheet.SRCConstants.Height,"Height"); var table = query.GetResults<double>(shape); double w = table[col_w.Ordinal]; double h = table[col_h.Ordinal]; var size = new VA.Drawing.Size(w, h); return size; }
public static VisioAutomation.Drawing.Size GetSize(IVisio.Shape shape) { var query = new VisioAutomation.ShapeSheet.Query.CellQuery(); var col_w = query.AddCell(VisioAutomation.ShapeSheet.SRCConstants.Width,"Width"); var col_h = query.AddCell(VisioAutomation.ShapeSheet.SRCConstants.Height,"Height"); var table = query.GetResults<double>(shape); double w = table[col_w]; double h = table[col_h]; var size = new VisioAutomation.Drawing.Size(w, h); return size; }
public void ShapeSheet_Query_Demo_AllCellsAndSections() { var doc1 = this.GetNewDoc(); var page1 = doc1.Pages[1]; VisioAutomationTest.SetPageSize(page1, this.StandardPageSize); // draw simple shapes var s1 = page1.DrawRectangle(0, 0, 1, 1); var s2 = page1.DrawRectangle(2, 2, 3, 3); var query = new VA.ShapeSheet.Query.CellQuery(); var name_to_src = VA.ShapeSheet.SRCConstants.GetSRCDictionary(); var section_to_secquery = new Dictionary <short, VA.ShapeSheet.Query.SectionColumn>(); foreach (var kv in name_to_src) { var name = kv.Key; var src = kv.Value; // Ignore Sections we don't care about if (section_is_skippable(src)) { continue; } if (src.Section == (short)IVisio.VisSectionIndices.visSectionObject) { query.AddCell(src, name); } else { VA.ShapeSheet.Query.SectionColumn sec_col; if (!section_to_secquery.ContainsKey(src.Section)) { sec_col = query.AddSection((IVisio.VisSectionIndices)src.Section); section_to_secquery[src.Section] = sec_col; } else { sec_col = section_to_secquery[src.Section]; } sec_col.AddCell(src.Cell, name); } } var formulas1 = query.GetFormulas(s1); var formulas2 = query.GetFormulas(page1, new [] { s1.ID, s2.ID }); doc1.Close(true); }
private static void check_query(VA.ShapeSheet.Query.CellQuery query) { if (query.Columns.Count < 1) { throw new VA.AutomationException("Query must contain at least 1 Column"); } if (query.Sections.Count != 0) { throw new VA.AutomationException("Query should not contain contain any sections"); } }
public void ShapeSheet_Query_Demo_MultipleShapes_Verify_Out_Of_order() { var page1 = this.GetNewPage(new VisioAutomation.Geometry.Size(10, 10)); // draw a simple shape var sa = page1.DrawRectangle(-1, -1, 0, 0); var s1 = page1.DrawRectangle(0, 0, 2, 2); var sb = page1.DrawRectangle(-1, -1, 0, 0); var s2 = page1.DrawRectangle(4, 4, 6, 6); var s3 = page1.DrawRectangle(5, 5, 7, 7); // notice that the shapes are created as 0, 1,2,3 // but are queried as 2, 3, 1 var shapeids = new List <int> { s2.ID, s3.ID, s1.ID }; Assert.AreEqual(5, page1.Shapes.Count); var query = new VA.ShapeSheet.Query.CellQuery(); var col_pinx = query.Columns.Add(SrcConstants.XFormPinX, nameof(SrcConstants.XFormPinX)); var col_piny = query.Columns.Add(SrcConstants.XFormPinY, nameof(SrcConstants.XFormPinY)); var data_formulas = query.GetFormulas(page1, shapeids); var data_results = query.GetResults <double>(page1, shapeids); var expected_formulas = new[, ] { { "5 in", "5 in" }, { "6 in", "6 in" }, { "1 in", "1 in" } }; var expected_results = new[, ] { { 5.0, 5.0 }, { 6.0, 6.0 }, { 1.0, 1.0 } }; for (int row = 0; row < data_results.Count; row++) { for (int col = 0; col < query.Columns.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); }
public static VisioAutomation.Drawing.Size GetSize(IVisio.Shape shape) { var query = new VisioAutomation.ShapeSheet.Query.CellQuery(); var col_w = query.AddCell(VisioAutomation.ShapeSheet.SRCConstants.Width, "Width"); var col_h = query.AddCell(VisioAutomation.ShapeSheet.SRCConstants.Height, "Height"); var table = query.GetResults <double>(shape); double w = table[col_w]; double h = table[col_h]; var size = new VisioAutomation.Drawing.Size(w, h); return(size); }
public static VA.Drawing.Size GetSize(IVisio.Shape shape) { var query = new VA.ShapeSheet.Query.CellQuery(); var col_w = query.Columns.Add(VA.ShapeSheet.SRCConstants.Width, "Width"); var col_h = query.Columns.Add(VA.ShapeSheet.SRCConstants.Height, "Height"); var table = query.GetResults <double>(shape); double w = table[col_w.Ordinal]; double h = table[col_h.Ordinal]; var size = new VA.Drawing.Size(w, h); return(size); }
public void T1() { var cd_props = getcelldataprops(typeof (G1)); Assert.AreEqual(4, cd_props.Count()); var x1 = new G1(); var q = new VA.ShapeSheet.Query.CellQuery(); foreach (var cd_prop in cd_props) { q.AddColumn() } }
internal static Geometry.Size GetSize(IVisio.Page page) { var query = new VASS.Query.CellQuery(); var col_height = query.Columns.Add(VASS.SrcConstants.PageHeight, nameof(VASS.SrcConstants.PageHeight)); var col_width = query.Columns.Add(VASS.SrcConstants.PageWidth, nameof(VASS.SrcConstants.PageWidth)); var cellqueryresult = query.GetResults <double>(page.PageSheet); var row = cellqueryresult[0]; double height = row[col_height]; double width = row[col_width]; var s = new Geometry.Size(width, height); return(s); }
public static void SetFromCellNames(VA.ShapeSheet.Query.CellQuery query, string[] Cells, CellMap dic) { if (Cells == null) { return; } foreach (string resolved_cellname in dic.ResolveNames(Cells)) { if (!query.Columns.Contains(resolved_cellname)) { query.Columns.Add(dic[resolved_cellname], resolved_cellname); } } }
public static VA.Drawing.Size GetPageSize(IVisio.Page page) { if (page == null) { throw new System.ArgumentNullException("page"); } var query = new VA.ShapeSheet.Query.CellQuery(); var col_height = query.AddCell(VA.ShapeSheet.SRCConstants.PageHeight,"PageHeight"); var col_width = query.AddCell(VA.ShapeSheet.SRCConstants.PageWidth, "PageWidth"); var results = query.GetResults<double>(page.PageSheet); double height = results[col_height]; double width = results[col_width]; var s = new VA.Drawing.Size(width, height); return s; }
private void update_from_selection() { var app = VisioPowerToolsAddIn.Client; if (!app.Selection.HasShapes()) { return; } var application = app.VisioApplication; var active_window = application.ActiveWindow; var selection = active_window.Selection; var s1 = selection[1]; var doc = application.ActiveDocument; var query = new VA.ShapeSheet.Query.CellQuery(); var col_fg = query.Columns.Add(VA.ShapeSheet.SRCConstants.FillForegnd); var col_bg = query.Columns.Add(VA.ShapeSheet.SRCConstants.FillBkgnd); var col_fgtrans = query.Columns.Add(VA.ShapeSheet.SRCConstants.FillForegndTrans); var col_bgtrans = query.Columns.Add(VA.ShapeSheet.SRCConstants.FillBkgndTrans); var col_fillpat = query.Columns.Add(VA.ShapeSheet.SRCConstants.FillPattern); var col_sfg = query.Columns.Add(VA.ShapeSheet.SRCConstants.ShdwForegnd); var col_sbg = query.Columns.Add(VA.ShapeSheet.SRCConstants.ShdwBkgnd); var col_sfgtrans = query.Columns.Add(VA.ShapeSheet.SRCConstants.ShdwForegndTrans); var col_bfgtrans = query.Columns.Add(VA.ShapeSheet.SRCConstants.ShdwBkgndTrans); var col_spat = query.Columns.Add(VA.ShapeSheet.SRCConstants.ShdwPattern); var table = query.GetResults<double>(s1); var colors = doc.Colors; double row = table[0]; // TODFO: fix //this.fillGradient1.FillDef.ForegroundColor = (System.Drawing.Color) colors[col_fg.Ordinal].ToColorRGB(); //this.fillGradient1.FillDef.BackgroundColor = (System.Drawing.Color)colors[col_bg.Ordinal].ToColorRGB(); //this.fillGradient1.FillDef.ForegroundTransparency = (int)(100.0 * row[col_fgtrans.Ordinal]); //this.fillGradient1.FillDef.BackgroundTransparency = (int)(100.0 * row[col_bgtrans]); //this.fillGradient1.FillDef.FillPattern = (VA.UI.FillPattern)(int)row[col_fillpat]; //this.fillGradient1.ShadowDef.ForegroundColor = (System.Drawing.Color)colors[(int)row[col_sfg]].ToColorRGB(); //this.fillGradient1.ShadowDef.BackgroundColor = (System.Drawing.Color)colors[(int)row[col_sbg]].ToColorRGB(); //this.fillGradient1.ShadowDef.ForegroundTransparency = (int)(100.0 * row[col_sfgtrans]); //this.fillGradient1.ShadowDef.BackgroundTransparency = (int)(100.0 * row[col_bfgtrans]); //this.fillGradient1.ShadowDef.FillPattern = (VA.UI.FillPattern)((int)row[col_spat]); }
public void UserDefinedCells_GetFromMultipleShapes_WithAdditionalProps() { var page1 = this.GetNewPage(); var s1 = page1.DrawRectangle(0, 0, 1, 1); var s2 = page1.DrawRectangle(1, 1, 2, 2); var shapes = new[] { s1, s2 }; VAUSERCELL.UserDefinedCellsHelper.Set(s1, "foo", "bar", null); var queryex = new VisioAutomation.ShapeSheet.Query.CellQuery(); var sec = queryex.AddSection(IVisio.VisSectionIndices.visSectionUser); var Value = sec.AddCell(VisioAutomation.ShapeSheet.SRCConstants.User_Value,"Value"); var Prompt = sec.AddCell(VisioAutomation.ShapeSheet.SRCConstants.User_Prompt,"Prompt"); var formulas = queryex.GetFormulas(page1, shapes.Select(s => s.ID).ToList()); page1.Delete(0); }
public void ShapeSheet_Update_ResultsInt_SingleShape() { var page1 = this.GetNewPage(); var shape1 = page1.DrawRectangle(0, 0, 1, 1); // Setup the modifications to the cell values var update = new VA.ShapeSheet.Update(); update.SetResult(ShapeSheet_Update_Tests.src_linepat, 7, IVisio.VisUnitCodes.visNumber); update.Execute(shape1); // Build the query var query = new VA.ShapeSheet.Query.CellQuery(); var col_linepat = query.AddCell(ShapeSheet_Update_Tests.src_linepat,"LinePattern"); // Retrieve the values var data = query.GetCellData<double>(shape1); // Verify AssertVA.AreEqual("7", 7, data[col_linepat]); page1.Delete(0); }
public void ShapeSheet_Update_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 update = new VA.ShapeSheet.Update(); update.SetFormula(shape1.ID16, ShapeSheet_Update_Tests.src_pinx, 0.5); update.SetFormula(shape1.ID16, ShapeSheet_Update_Tests.src_piny, 0.5); update.SetFormula(shape2.ID16, ShapeSheet_Update_Tests.src_pinx, 1.5); update.SetFormula(shape2.ID16, ShapeSheet_Update_Tests.src_piny, 1.5); update.SetFormula(shape3.ID16, ShapeSheet_Update_Tests.src_pinx, 2.5); update.SetFormula(shape3.ID16, ShapeSheet_Update_Tests.src_piny, 2.5); update.Execute(page1); // Verify that the formulas were set var query = new VA.ShapeSheet.Query.CellQuery(); var col_pinx = query.AddCell(ShapeSheet_Update_Tests.src_pinx, "PinX"); var col_piny = query.AddCell(ShapeSheet_Update_Tests.src_piny, "PinY"); var shapeids = new[] { shape1.ID, shape2.ID, shape3.ID }; var rf = query.GetFormulas(page1, shapeids); var rr = query.GetResults<double>(page1, shapeids); AssertVA.AreEqual("0.5 in", 0.5, rf[0][col_pinx], rr[0][col_pinx]); AssertVA.AreEqual("0.5 in", 0.5, rf[0][col_piny], rr[0][col_piny]); AssertVA.AreEqual("1.5 in", 1.5, rf[1][col_pinx], rr[1][col_pinx]); AssertVA.AreEqual("1.5 in", 1.5, rf[1][col_piny], rr[1][col_piny]); AssertVA.AreEqual("2.5 in", 2.5, rf[2][col_pinx], rr[2][col_pinx]); AssertVA.AreEqual("2.5 in", 2.5, rf[2][col_piny], rr[2][col_piny]); page1.Delete(0); }
/// <summary> /// Caches the resize (the results, not formulas) of a the first currently selected shape /// </summary> public void CopySize() { this.AssertApplicationAvailable(); this.AssertDocumentAvailable(); if (!this.Client.HasSelectedShapes()) { return; } var application = this.Client.VisioApplication; var active_window = application.ActiveWindow; var selection = active_window.Selection; var shape = selection[1]; var query = new VA.ShapeSheet.Query.CellQuery(); var width_col = query.Columns.Add(VA.ShapeSheet.SRCConstants.Width, "Width"); var height_col = query.Columns.Add(VA.ShapeSheet.SRCConstants.Height, "Height"); var queryresults = query.GetResults<double>(shape); cached_size_width = queryresults[width_col.Ordinal]; cached_size_height = queryresults[height_col.Ordinal]; }
public void ShapeSheet_Query_SectionRowHandling() { var page1 = 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); VACUSTOMPROP.CustomPropertyHelper.Set(s1, "S1P1", "1"); VACUSTOMPROP.CustomPropertyHelper.Set(s2, "S2P1", "2"); VACUSTOMPROP.CustomPropertyHelper.Set(s2, "S2P2", "3"); //set nothing for s3 VACUSTOMPROP.CustomPropertyHelper.Set(s4, "S3P1", "4"); VACUSTOMPROP.CustomPropertyHelper.Set(s4, "S3P2", "5"); VACUSTOMPROP.CustomPropertyHelper.Set(s4, "S3P3", "6"); var query = new VA.ShapeSheet.Query.CellQuery(); var sec = query.Sections.Add(IVisio.VisSectionIndices.visSectionProp); sec.Columns.Add(VA.ShapeSheet.SRCConstants.Prop_Value, "Value"); var shapeids = new[] { s1.ID, s2.ID, s3.ID, s4.ID }; var table = query.GetFormulasAndResults<double>( page1, shapeids); Assert.AreEqual(4, table.Count); Assert.AreEqual(1, table[0].SectionCells[sec.Ordinal].Count); Assert.AreEqual(2, table[1].SectionCells[sec.Ordinal].Count); Assert.AreEqual(0, table[2].SectionCells[sec.Ordinal].Count); Assert.AreEqual(3, table[3].SectionCells[sec.Ordinal].Count); AssertVA.AreEqual("\"1\"", 1.0, table[0].SectionCells[sec.Ordinal][0][0]); AssertVA.AreEqual("\"2\"", 2.0, table[1].SectionCells[sec.Ordinal][0][0]); AssertVA.AreEqual("\"3\"", 3.0, table[1].SectionCells[sec.Ordinal][1][0]); AssertVA.AreEqual("\"4\"", 4.0, table[3].SectionCells[sec.Ordinal][0][0]); AssertVA.AreEqual("\"5\"", 5.0, table[3].SectionCells[sec.Ordinal][1][0]); AssertVA.AreEqual("\"6\"", 6.0, table[3].SectionCells[sec.Ordinal][2][0]); page1.Delete(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 VA.ShapeSheet.Query.CellQuery(); var prop_sec = query.AddSection(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 data = query.GetCellData<double>( page1, shapeids); Assert.AreEqual(4, data.Count); Assert.AreEqual(1, data[0].Sections[prop_sec].Count); Assert.AreEqual(2, data[1].Sections[prop_sec].Count); Assert.AreEqual(0, data[2].Sections[prop_sec].Count); Assert.AreEqual(3, data[3].Sections[prop_sec].Count); AssertVA.AreEqual("\"1\"", 1.0, data[0].Sections[prop_sec][0][0]); AssertVA.AreEqual("\"2\"", 2.0, data[1].Sections[prop_sec][0][0]); AssertVA.AreEqual("\"3\"", 3.0, data[1].Sections[prop_sec][1][0]); AssertVA.AreEqual("\"4\"", 4.0, data[3].Sections[prop_sec][0][0]); AssertVA.AreEqual("\"5\"", 5.0, data[3].Sections[prop_sec][1][0]); AssertVA.AreEqual("\"6\"", 6.0, data[3].Sections[prop_sec][2][0]); page1.Delete(0); }
public void ShapeSheet_Query_Demo_MultipleShapes() { var page1 = GetNewPage(new VA.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 VA.ShapeSheet.Query.CellQuery(); var col_pinx = query.Columns.Add(VA.ShapeSheet.SRCConstants.PinX,"PinX"); var col_piny = query.Columns.Add(VA.ShapeSheet.SRCConstants.PinY,"PinY"); var rf = query.GetFormulas(page1, shapeids); var rr = query.GetResults<double>(page1, 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 < rr.Count; row++) { for (int col = 0; col < query.Columns.Count; col++) { Assert.AreEqual(expected_formulas[row,col], rf[row][col]); Assert.AreEqual(expected_results[row,col], rr[row][col]); } } page1.Delete(0); }
public void ShapeSheet_Query_Demo_MultipleShapes_Verify_Out_Of_order() { var page1 = this.GetNewPage(new VisioAutomation.Drawing.Size(10, 10)); // draw a simple shape var sa = page1.DrawRectangle(-1, -1, 0, 0); var s1 = page1.DrawRectangle(0, 0, 2, 2); var sb = page1.DrawRectangle(-1, -1, 0, 0); var s2 = page1.DrawRectangle(4, 4, 6, 6); var s3 = page1.DrawRectangle(5, 5, 7, 7); // notice that the shapes are created as 0, 1,2,3 // but are queried as 2, 3, 1 var shapeids = new List<int> { s2.ID, s3.ID, s1.ID }; Assert.AreEqual(5, page1.Shapes.Count); var query = new VA.ShapeSheet.Query.CellQuery(); var col_pinx = query.AddCell(VA.ShapeSheet.SRCConstants.PinX, "PinX"); var col_piny = query.AddCell(VA.ShapeSheet.SRCConstants.PinY, "PinY"); var rf = query.GetFormulas(page1, shapeids); var rr = query.GetResults<double>(page1, shapeids); var expected_formulas = new[,] { {"5 in", "5 in"}, {"6 in", "6 in"}, {"1 in", "1 in"} }; var expected_results = new[,] { {5.0, 5.0}, {6.0, 6.0}, {1.0, 1.0} }; for (int row = 0; row < rr.Count; row++) { for (int col = 0; col < query.CellColumns.Count; col++) { Assert.AreEqual(expected_formulas[row, col], rf[row][col]); Assert.AreEqual(expected_results[row, col], rr[row][col]); } } page1.Delete(0); }
public void ShapeSheet_Query_GetResults_SingleShape() { var doc1 = this.GetNewDoc(); var page1 = doc1.Pages[1]; VisioAutomationTest.SetPageSize(page1, this.StandardPageSize); // draw a simple shape var s1 = page1.DrawRectangle(this.StandardPageSizeRect); int s1_id = s1.ID; // format it with setformulas var fg_cell = s1.Cells["FillForegnd"]; var bg_cell = s1.Cells["FillBkgnd"]; var pat_cell = s1.Cells["FillPattern"]; fg_cell.FormulaU = "RGB(255,0,0)"; bg_cell.FormulaU = "RGB(0,0,255)"; pat_cell.FormulaU = "40"; // now retrieve the formulas with GetFormulas var src_fg = VA.ShapeSheet.SRCConstants.FillForegnd; var src_bg = VA.ShapeSheet.SRCConstants.FillBkgnd; var src_filpat = VA.ShapeSheet.SRCConstants.FillPattern; var query = new VA.ShapeSheet.Query.CellQuery(); var col_fg = query.AddCell(src_fg, "FillForegnd"); var col_bg = query.AddCell(src_bg, "FillBkgnd"); var col_filpat = query.AddCell(src_filpat, "FillPattern"); var sec_char = query.AddSection(IVisio.VisSectionIndices.visSectionCharacter); Assert.AreEqual("Character",sec_char.Name); var col_charcase = sec_char.AddCell(VA.ShapeSheet.SRCConstants.CharCase, "CharCase"); var col_charcolor = sec_char.AddCell(VA.ShapeSheet.SRCConstants.CharColor, "CharColor"); var col_chartrans = sec_char.AddCell(VA.ShapeSheet.SRCConstants.CharColorTrans, "CharColorTrans"); var shapeids = new[] {s1_id}; var formulas = query.GetFormulas(page1, shapeids); // now verify that the formulas were actually set Assert.AreEqual("RGB(255,0,0)", formulas[0][col_fg]); Assert.AreEqual("RGB(0,0,255)", formulas[0][col_bg]); Assert.AreEqual("40", formulas[0][col_filpat]); // now retrieve the results with GetResults as floats var float_results = query.GetResults<double>(page1,shapeids); Assert.IsNotNull(float_results); Assert.AreEqual(40.0, float_results[0][col_filpat]); // now retrieve the results with GetResults as ints var int_results = query.GetResults<int>(page1,shapeids); Assert.AreEqual(40, int_results[0][col_filpat]); // now retrieve the results with GetResults as strings var string_results = query.GetResults<string>(page1,shapeids); Assert.AreEqual("RGB(255, 0, 0)", string_results[0][col_fg]); Assert.AreEqual("RGB(0, 0, 255)", string_results[0][col_bg]); Assert.AreEqual("40", string_results[0][col_filpat]); page1.Delete(0); doc1.Close(true); }
public void ShapeSheet_Query_TestDuplicates() { // Ensure that duplicate cells are caught var q1 = new VA.ShapeSheet.Query.CellQuery(); q1.AddCell(VA.ShapeSheet.SRCConstants.PinX, "PinX"); bool caught_exc1 = false; try { q1.AddCell(VA.ShapeSheet.SRCConstants.PinX, "PinX"); } catch (VA.AutomationException) { caught_exc1 = true; } Assert.IsTrue(caught_exc1); // Ensure that duplicate sections are caught var q2 = new VA.ShapeSheet.Query.CellQuery(); q2.AddSection(IVisio.VisSectionIndices.visSectionObject); bool caught_exc2 = false; try { q2.AddSection(IVisio.VisSectionIndices.visSectionObject); } catch (VA.AutomationException) { caught_exc2 = true; } Assert.IsTrue(caught_exc2); // Ensure that Duplicates in Section Queries Are caught - var q3 = new VA.ShapeSheet.Query.CellQuery(); var sec = q3.AddSection(IVisio.VisSectionIndices.visSectionObject); sec.AddCell(VA.ShapeSheet.SRCConstants.PinX.Cell,"PinX"); bool caught_exc3 = false; try { sec.AddCell(VA.ShapeSheet.SRCConstants.PinX.Cell, "PinX"); } catch (VA.AutomationException) { caught_exc3 = true; } Assert.IsTrue(caught_exc3); }
public void ShapeSheet_Query_GetResults_MultipleShapes() { var page1 = this.GetNewPage(); // draw a simple shape var s1 = page1.DrawRectangle(this.StandardPageSizeRect); int s1_id = s1.ID; // format it with setformulas var fg_cell = s1.Cells["FillForegnd"]; var bg_cell = s1.Cells["FillBkgnd"]; var pat_cell = s1.Cells["FillPattern"]; fg_cell.ResultIU = 2.0; //red bg_cell.ResultIU = 3.0; //green pat_cell.ResultIU = 40.0; var src_fg = VA.ShapeSheet.SRCConstants.FillForegnd; var src_bg = VA.ShapeSheet.SRCConstants.FillBkgnd; var src_filpat = VA.ShapeSheet.SRCConstants.FillPattern; // now retrieve the formulas with GetFormulas var query = new VA.ShapeSheet.Query.CellQuery(); var col_fg = query.AddCell(src_fg, "FillForegnd"); var col_bg = query.AddCell(src_bg, "FillBkgnd"); var col_filpat = query.AddCell(src_filpat, "FillPattern"); var shapeids = new[] {s1_id}; var formulas = query.GetFormulas(page1, shapeids); // now verify that the formulas were actually set Assert.AreEqual("2", formulas[0][col_fg]); Assert.AreEqual("3", formulas[0][col_bg]); Assert.AreEqual("40", formulas[0][col_filpat]); // now retrieve the results with GetResults as floats var float_results = query.GetResults<double>(page1,shapeids); Assert.AreEqual(2.0, float_results[0][col_fg]); Assert.AreEqual(3.0, float_results[0][col_bg]); Assert.AreEqual(40.0, float_results[0][col_filpat]); // now retrieve the results with GetResults as ints var int_results = query.GetResults<int>(page1,shapeids); Assert.AreEqual(2, int_results[0][col_fg]); Assert.AreEqual(3, int_results[0][col_bg]); Assert.AreEqual(40, int_results[0][col_filpat]); // now retrieve the results with GetResults as strings var string_results = query.GetResults<string>(page1,shapeids); Assert.AreEqual("2", string_results[0][col_fg]); Assert.AreEqual("3", string_results[0][col_bg]); Assert.AreEqual("40", string_results[0][col_filpat]); page1.Delete(0); }
public void CopyFormat(IVisio.Shape shape, FormatCategory category) { // Build the Query var query = new VA.ShapeSheet.Query.CellQuery(); var desired_cells = this.Cells.Where(cell => cell.MatchesCategory(category)).ToList(); foreach (var cell in desired_cells) { query.Columns.Add(cell.SRC,null); } // Retrieve the values for the cells var dataset = query.GetFormulasAndResults<string>(shape); // Now store the values for (int col = 0; col < query.Columns.Count; col++) { var cellrec = desired_cells[col]; var result = dataset[col].Result; var formula = dataset[col].Formula; cellrec.Result = result; cellrec.Formula = formula.Value; } }
public VA.Drawing.Size GetSize() { this.AssertApplicationAvailable(); this.AssertDocumentAvailable(); var application = this.Client.VisioApplication; var active_page = application.ActivePage; var query = new VA.ShapeSheet.Query.CellQuery(); var col_height = query.Columns.Add(VA.ShapeSheet.SRCConstants.PageHeight,"PageHeight"); var col_width = query.Columns.Add(VA.ShapeSheet.SRCConstants.PageWidth,"PageWidth"); var results = query.GetResults<double>(active_page.PageSheet); double height = results[col_height.Ordinal]; double width = results[col_width.Ordinal]; var s = new VA.Drawing.Size(width, height); return s; }
public void ShapeSheet_Update_ResultsDouble_MultipleShapes() { var page1 = 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 update = new VA.ShapeSheet.Update(); update.SetResult(shape1.ID16, src_pinx, 0.5, IVisio.VisUnitCodes.visNumber); update.SetResult(shape1.ID16, src_piny, 0.5, IVisio.VisUnitCodes.visNumber); update.SetResult(shape2.ID16, src_pinx, 1.5, IVisio.VisUnitCodes.visNumber); update.SetResult(shape2.ID16, src_piny, 1.5, IVisio.VisUnitCodes.visNumber); update.SetResult(shape3.ID16, src_pinx, 2.5, IVisio.VisUnitCodes.visNumber); update.SetResult(shape3.ID16, src_piny, 2.5, IVisio.VisUnitCodes.visNumber); update.Execute(page1); // Verify that the formulas were set var query = new VA.ShapeSheet.Query.CellQuery(); var col_pinx = query.Columns.Add(src_pinx,"PinX"); var col_piny = query.Columns.Add(src_piny,"PinY"); var shapeids = new[] { shape1.ID, shape2.ID, shape3.ID }; var rf = query.GetFormulas(page1, shapeids); var rr = query.GetResults<double>(page1, shapeids); AssertVA.AreEqual("0.5 in", 0.5, rf[0][col_pinx.Ordinal], rr[0][col_pinx.Ordinal]); AssertVA.AreEqual("0.5 in", 0.5, rf[0][col_piny.Ordinal], rr[0][col_piny.Ordinal]); AssertVA.AreEqual("1.5 in", 1.5, rf[1][col_pinx.Ordinal], rr[1][col_pinx.Ordinal]); AssertVA.AreEqual("1.5 in", 1.5, rf[1][col_piny.Ordinal], rr[1][col_piny.Ordinal]); AssertVA.AreEqual("2.5 in", 2.5, rf[2][col_pinx.Ordinal], rr[2][col_pinx.Ordinal]); AssertVA.AreEqual("2.5 in", 2.5, rf[2][col_piny.Ordinal], rr[2][col_piny.Ordinal]); page1.Delete(0); }
private static VA.Drawing.Size GetSize(IVisio.Page page) { var query = new VA.ShapeSheet.Query.CellQuery(); var col_height = query.Columns.Add(VA.ShapeSheet.SRCConstants.PageHeight,"PageHeight"); var col_width = query.Columns.Add(VA.ShapeSheet.SRCConstants.PageWidth, "PageWidth"); var results = query.GetResults<double>(page.PageSheet); double height = results[col_height.Ordinal]; double width = results[col_width.Ordinal]; var s = new VA.Drawing.Size(width, height); return s; }
protected override void ProcessRecord() { var query = new VisioAutomation.ShapeSheet.Query.CellQuery(); var target_shapes = this.Shapes ?? this.client.Selection.GetShapes(); var target_shapeids = target_shapes.Select(s => s.ID).ToList(); addcell(query, this.Angle, "Angle"); addcell(query, this.BeginArrow, "BeginArrow"); addcell(query, this.BeginArrowSize, "BeginArrowSize"); addcell(query, this.BeginX, "BeginX"); addcell(query, this.BeginY, "BeginY"); addcell(query, this.CharCase, "CharCase"); addcell(query, this.CharColor, "CharColor"); addcell(query, this.CharColorTransparency, "CharColorTransparency"); addcell(query, this.CharFont, "CharFont"); addcell(query, this.CharFontScale, "CharFontScale"); addcell(query, this.CharLetterspace, "CharLetterspace"); addcell(query, this.CharSize, "CharSize"); addcell(query, this.CharStyle, "CharStyle"); addcell(query, this.EndArrow, "EndArrow"); addcell(query, this.EndArrowSize, "EndArrowSize"); addcell(query, this.EndX, "EndX"); addcell(query, this.EndY, "EndY"); addcell(query, this.FillBkgnd, "FillBkgnd"); addcell(query, this.FillBkgndTrans, "FillBkgndTrans"); addcell(query, this.FillForegnd, "FillForegnd"); addcell(query, this.FillForegndTrans, "FillForegndTrans"); addcell(query, this.FillPattern, "FillPattern"); addcell(query, this.Height, "Height"); addcell(query, this.HideText, "HideText"); addcell(query, this.LineCap, "LineCap"); addcell(query, this.LineColor, "LineColor"); addcell(query, this.LinePattern, "LinePattern"); addcell(query, this.LineWeight, "LineWeight"); addcell(query, this.LockAspect, "LockAspect"); addcell(query, this.LockBegin, "LockBegin"); addcell(query, this.LockCalcWH, "LockCalcWH"); addcell(query, this.LockCrop, "LockCrop"); addcell(query, this.LockCustProp, "LockCustProp"); addcell(query, this.LockDelete, "LockDelete"); addcell(query, this.LockEnd, "LockEnd"); addcell(query, this.LockFormat, "LockFormat"); addcell(query, this.LockFromGroupFormat, "LockFromGroupFormat"); addcell(query, this.LockGroup, "LockGroup"); addcell(query, this.LockHeight, "LockHeight"); addcell(query, this.LockMoveX, "LockMoveX"); addcell(query, this.LockMoveY, "LockMoveY"); addcell(query, this.LockRotate, "LockRotate"); addcell(query, this.LockSelect, "LockSelect"); addcell(query, this.LockTextEdit, "LockTextEdit"); addcell(query, this.LockThemeColors, "LockThemeColors"); addcell(query, this.LockThemeEffects, "LockThemeEffects"); addcell(query, this.LockVtxEdit, "LockVtxEdit"); addcell(query, this.LockWidth, "LockWidth"); addcell(query, this.LocPinX, "LocPinX"); addcell(query, this.LocPinY, "LocPinY"); addcell(query, this.PinX, "PinX"); addcell(query, this.PinY, "PinY"); addcell(query, this.Rounding, "Rounding"); addcell(query, this.SelectMode, "SelectMode"); addcell(query, this.ShdwBkgnd, "ShdwBkgnd"); addcell(query, this.ShdwBkgndTrans, "ShdwBkgndTrans"); addcell(query, this.ShdwForegnd, "ShdwForegnd"); addcell(query, this.ShdwForegndTrans, "ShdwForegndTrans"); addcell(query, this.ShdwObliqueAngle, "ShdwObliqueAngle"); addcell(query, this.ShdwOffsetX, "ShdwOffsetX"); addcell(query, this.ShdwOffsetY, "ShdwOffsetY"); addcell(query, this.ShdwPattern, "ShdwPattern"); addcell(query, this.ShdwScalefactor, "ShdwScalefactor"); addcell(query, this.ShdwType, "ShdwType"); addcell(query, this.TxtAngle, "TxtAngle"); addcell(query, this.TxtHeight, "TxtHeight"); addcell(query, this.TxtLocPinX, "TxtLocPinX"); addcell(query, this.TxtLocPinY, "TxtLocPinY"); addcell(query, this.TxtPinX, "TxtPinX"); addcell(query, this.TxtPinY, "TxtPinY"); addcell(query, this.TxtWidth, "TxtWidth"); addcell(query, this.Width, "Width"); var dic = GetShapeCellDictionary(); Get_VisioPageCell.SetFromCellNames(query, this.Cells, dic); var surface = this.client.Draw.GetDrawingSurfaceSafe(); this.WriteVerbose("Number of Shapes : {0}", target_shapes.Count); this.WriteVerbose("Number of Cells: {0}", query.Columns.Count); this.WriteVerbose("Start Query"); var dt = Helpers.QueryToDataTable(query, this.GetResults, this.ResultType, target_shapeids, surface); this.WriteObject(dt); this.WriteVerbose("End Query"); }
protected override void ProcessRecord() { var query = new VA.ShapeSheet.Query.CellQuery(); addcell(query, this.AvenueSizeX, "AvenueSizeX"); addcell(query, this.AvenueSizeY, "AvenueSizeY"); addcell(query, this.AvoidPageBreaks, "AvoidPageBreaks"); addcell(query, this.BlockSizeX, "BlockSizeX"); addcell(query, this.BlockSizeY, "BlockSizeY"); addcell(query, this.CenterX, "CenterX"); addcell(query, this.CenterY, "CenterY"); addcell(query, this.CtrlAsInput, "CtrlAsInput"); addcell(query, this.DrawingResizeType, "DrawingResizeType"); addcell(query, this.DrawingScale, "DrawingScale"); addcell(query, this.DrawingScaleType, "DrawingScaleType"); addcell(query, this.DrawingSizeType, "DrawingSizeType"); addcell(query, this.DynamicsOff, "DynamicsOff"); addcell(query, this.EnableGrid, "EnableGrid"); addcell(query, this.InhibitSnap, "InhibitSnap"); addcell(query, this.LineAdjustFrom, "LineAdjustFrom"); addcell(query, this.LineAdjustTo, "LineAdjustTo"); addcell(query, this.LineJumpCode, "LineJumpCode"); addcell(query, this.LineJumpFactorX, "LineJumpFactorX"); addcell(query, this.LineJumpFactorY, "LineJumpFactorY"); addcell(query, this.LineJumpStyle, "LineJumpStyle"); addcell(query, this.LineRouteExt, "LineRouteExt"); addcell(query, this.LineToLineX, "LineToLineX"); addcell(query, this.LineToLineY, "LineToLineY"); addcell(query, this.LineToNodeX, "LineToNodeX"); addcell(query, this.LineToNodeY, "LineToNodeY"); addcell(query, this.PageBottomMargin, "PageBottomMargin"); addcell(query, this.PageHeight, "PageHeight"); addcell(query, this.PageLeftMargin, "PageLeftMargin"); addcell(query, this.PageLineJumpDirX, "PageLineJumpDirX"); addcell(query, this.PageLineJumpDirY, "PageLineJumpDirY"); addcell(query, this.PageRightMargin, "PageRightMargin"); addcell(query, this.PageScale, "PageScale"); addcell(query, this.PageShapeSplit, "PageShapeSplit"); addcell(query, this.PageTopMargin, "PageTopMargin"); addcell(query, this.PageWidth, "PageWidth"); addcell(query, this.PaperKind, "PaperKind"); addcell(query, this.PaperSource, "PaperSource"); addcell(query, this.PlaceDepth, "PlaceDepth"); addcell(query, this.PlaceFlip, "PlaceFlip"); addcell(query, this.PlaceStyle, "PlaceStyle"); addcell(query, this.PlowCode, "PlowCode"); addcell(query, this.PrintGrid, "PrintGrid"); addcell(query, this.PrintPageOrientation, "PrintPageOrientation"); addcell(query, this.ResizePage, "ResizePage"); addcell(query, this.RouteStyle, "RouteStyle"); addcell(query, this.ScaleX, "ScaleX"); addcell(query, this.ScaleY, "ScaleY"); addcell(query, this.ShdwObliqueAngle, "ShdwObliqueAngle"); addcell(query, this.ShdwOffsetX, "ShdwOffsetX"); addcell(query, this.ShdwOffsetY, "ShdwOffsetY"); addcell(query, this.ShdwScaleFactor, "ShdwScaleFactor"); addcell(query, this.ShdwType, "ShdwType"); addcell(query, this.UIVisibility, "UIVisibility"); addcell(query, this.XGridDensity, "XGridDensity"); addcell(query, this.XGridOrigin, "XGridOrigin"); addcell(query, this.XGridSpacing, "XGridSpacing"); addcell(query, this.XRulerDensity, "XRulerDensity"); addcell(query, this.XRulerOrigin, "XRulerOrigin"); addcell(query, this.YGridDensity, "YGridDensity"); addcell(query, this.YGridOrigin, "YGridOrigin"); addcell(query, this.YGridSpacing, "YGridSpacing"); addcell(query, this.YRulerDensity, "YRulerDensity"); addcell(query, this.YRulerOrigin, "YRulerOrigin"); var dic = GetPageCellDictionary(); SetFromCellNames(query, this.Cells, dic); var surface = new VA.Drawing.DrawingSurface(this.client.Page.Get()); var target_shapeids = new[] { surface.Page.ID }; this.WriteVerbose("Number of Cells: {0}", query.Columns.Count); this.WriteVerbose("Start Query"); var dt = Helpers.QueryToDataTable(query, this.GetResults, this.ResultType, target_shapeids, surface); this.WriteObject(dt); this.WriteVerbose("End Query"); }