public static List <XFormData> Get(Microsoft.Office.Interop.Visio.Page page, TargetShapeIDs target) { if (query == null) { query = new ShapeSheetQuery(); ColPinX = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.XFormPinX, nameof(VisioAutomation.ShapeSheet.SrcConstants.XFormPinX)); ColPinY = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.XFormPinY, nameof(VisioAutomation.ShapeSheet.SrcConstants.XFormPinY)); ColLocPinX = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.XFormLocPinX, nameof(VisioAutomation.ShapeSheet.SrcConstants.XFormLocPinX)); ColLocPinY = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.XFormLocPinY, nameof(VisioAutomation.ShapeSheet.SrcConstants.XFormLocPinY)); ColWidth = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.XFormWidth, nameof(VisioAutomation.ShapeSheet.SrcConstants.XFormWidth)); ColHeight = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.XFormHeight, nameof(VisioAutomation.ShapeSheet.SrcConstants.XFormHeight)); } var results = 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 <XFormData>(target.ShapeIDs.Count); foreach (var row in results) { var xform = new XFormData(); 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 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.FillForeground; var src_bg = VA.ShapeSheet.SrcConstants.FillBackground; var src_filpat = VA.ShapeSheet.SrcConstants.FillPattern; // now retrieve the formulas with GetFormulas var query = new ShapeSheetQuery(); 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].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 Check_Consistent_ResultTypes() { var page1 = this.GetNewPage(); var shape1 = page1.DrawRectangle(0, 0, 1, 1); // Setup the modifications to the cell values var writer = new SrcWriter(); writer.SetResult(ShapeSheetWriterTests.src_linepat, "7"); writer.SetResult(VA.ShapeSheet.SrcConstants.XFormPinX, 2); writer.Commit(shape1); // Build the query var query = new ShapeSheetQuery(); var col_linepat = query.AddCell(ShapeSheetWriterTests.src_linepat, "LinePattern"); var col_pinx = query.AddCell(VA.ShapeSheet.SrcConstants.XFormPinX, "PinX"); // Retrieve the values var data_formulas = query.GetFormulas(shape1); var data_results = query.GetResults <double>(shape1); // Verify Assert.AreEqual("7", data_formulas.Cells[col_linepat]); Assert.AreEqual(7, data_results.Cells[col_linepat]); Assert.AreEqual("2 in", data_formulas.Cells[col_pinx]); Assert.AreEqual(2, data_results.Cells[col_pinx]); page1.Delete(0); }
private static DataTable querytable_to_datatable <T>(ShapeSheetQuery cellQuery, QueryOutputCollection <T> query_output) { // First Construct a Datatable with a compatible schema var dt = new DataTable(); dt.Columns.Add("ShapeID", typeof(int)); foreach (var col in cellQuery.Cells) { dt.Columns.Add(col.Name, typeof(T)); } // Then populate the rows of the datatable dt.BeginLoadData(); int colcount = cellQuery.Cells.Count; var rowbuf = new object[colcount + 1]; for (int r = 0; r < query_output.Count; r++) { // populate the row buffer rowbuf[0] = query_output[r].ShapeID; for (int i = 0; i < colcount; i++) { rowbuf[i + 1] = query_output[r].Cells[i]; } // load it into the table dt.Rows.Add(rowbuf); } dt.EndLoadData(); return(dt); }
public void CopyFormat(IVisio.Shape shape, FormatPaintCategory paint_category) { // Build the Query var query = new ShapeSheetQuery(); var desired_cells = this.Cells.Where(cell => cell.MatchesCategory(paint_category)).ToList(); foreach (var cell in desired_cells) { query.AddCell(cell.Src, null); } // Retrieve the values for the cells var dataset = query.GetFormulasAndResults(shape); // Now store the values for (int col = 0; col < query.Cells.Count; col++) { var result = dataset.Cells[col].Result; var formula = dataset.Cells[col].Formula; var cellrec = desired_cells[col]; cellrec.Result = result; cellrec.Formula = formula.Value; } }
public void ShapeSheet_Writer_ResultsInt_SingleShape() { var page1 = this.GetNewPage(); var shape1 = page1.DrawRectangle(0, 0, 1, 1); // Setup the modifications to the cell values var writer = new SrcWriter(); writer.SetResult(ShapeSheetWriterTests.src_linepat, 7); writer.Commit(shape1); // Build the query var query = new ShapeSheetQuery(); var col_linepat = query.AddCell(ShapeSheetWriterTests.src_linepat, "LinePattern"); // Retrieve the values var data_formulas = query.GetFormulas(shape1); var data_results = query.GetResults <double>(shape1); // Verify Assert.AreEqual("7", data_formulas.Cells[col_linepat]); Assert.AreEqual(7, data_results.Cells[col_linepat]); page1.Delete(0); }
public void ShapeSheet_Query_TestDuplicates() { // Ensure that duplicate cells are caught var q1 = new ShapeSheetQuery(); q1.AddCell(VA.ShapeSheet.SrcConstants.XFormPinX, "PinX"); bool caught_exc1 = false; try { q1.AddCell(VA.ShapeSheet.SrcConstants.XFormPinX, "PinX"); } catch (System.ArgumentException) { caught_exc1 = true; } Assert.IsTrue(caught_exc1); // Ensure that duplicate sections are caught var q2 = new ShapeSheetQuery(); q2.AddSubQuery(IVisio.VisSectionIndices.visSectionObject); bool caught_exc2 = false; try { q2.AddSubQuery(IVisio.VisSectionIndices.visSectionObject); } catch (System.ArgumentException) { caught_exc2 = true; } Assert.IsTrue(caught_exc2); // Ensure that Duplicates in Section Queries Are caught - var q3 = new ShapeSheetQuery(); var sec = q3.AddSubQuery(IVisio.VisSectionIndices.visSectionObject); sec.AddCell(VA.ShapeSheet.SrcConstants.XFormPinX, "PinX"); bool caught_exc3 = false; try { sec.AddCell(VA.ShapeSheet.SrcConstants.XFormPinX, "PinX"); } catch (System.ArgumentException) { caught_exc3 = true; } Assert.IsTrue(caught_exc3); }
public void ShapeSheet_Query_SectionCells_have_names() { var query = new ShapeSheetQuery(); var sec_char = query.AddSubQuery(IVisio.VisSectionIndices.visSectionCharacter); Assert.AreEqual("Character", sec_char.Name); var sec_obj = query.AddSubQuery(IVisio.VisSectionIndices.visSectionObject); Assert.AreEqual("Object", sec_obj.Name); }
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 ShapeSheetQuery(); var col_pinx = query.AddCell(VA.ShapeSheet.SrcConstants.XFormPinX, "PinX"); var col_piny = query.AddCell(VA.ShapeSheet.SrcConstants.XFormPinY, "PinY"); 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.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); }
internal static Drawing.Size GetSize(IVisio.Page page) { var query = new ShapeSheetQuery(); var col_height = query.AddCell(ShapeSheet.SrcConstants.PageHeight, nameof(ShapeSheet.SrcConstants.PageHeight)); var col_width = query.AddCell(ShapeSheet.SrcConstants.PageWidth, nameof(ShapeSheet.SrcConstants.PageWidth)); var results = query.GetResults <double>(page.PageSheet); double height = results.Cells[col_height]; double width = results.Cells[col_width]; var s = new Drawing.Size(width, height); return(s); }
public static VisioAutomation.Drawing.Size GetSize(IVisio.Shape shape) { var query = new ShapeSheetQuery(); var col_w = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.XFormWidth, "Width"); var col_h = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.XFormHeight, "Height"); var table = query.GetResults <double>(shape); double w = table.Cells[col_w]; double h = table.Cells[col_h]; var size = new VisioAutomation.Drawing.Size(w, h); return(size); }
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 ShapeSheetQuery(); var prop_sec = query.AddSubQuery(IVisio.VisSectionIndices.visSectionProp); var value_col = prop_sec.AddCell(VA.ShapeSheet.SrcConstants.CustomPropValue, "Value"); var shapeids = new[] { s1.ID, s2.ID, s3.ID, s4.ID }; var data = query.GetFormulasAndResults(page1, 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); }
public static VisioAutomation.Drawing.Size GetPageSize(IVisio.Page page) { if (page == null) { throw new System.ArgumentNullException(nameof(page)); } var query = new ShapeSheetQuery(); var col_height = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.PageHeight, "PageHeight"); var col_width = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.PageWidth, "PageWidth"); var results = query.GetResults <double>(page.PageSheet); double height = results.Cells[col_height]; double width = results.Cells[col_width]; var s = new VisioAutomation.Drawing.Size(width, height); return(s); }
private ShapeSheetQuery create_query_for_all_cells_and_sections() { var query = new ShapeSheetQuery(); // Dictionary of Cell Names to Srcs (excluding invalid sections) var name_to_src = GetSrcDictionary(); name_to_src = name_to_src.Where(pair => !section_is_skippable(pair.Value)) .ToDictionary(pair => pair.Key, pair => pair.Value); // Create a dictionary of the subqueries for each section, this // will be reused as fill in the query var unique_section_ids = name_to_src.Select(pair => pair.Value).Select(src => src.Section).Distinct().ToList(); var section_to_subquery = new Dictionary <short, SubQuery>(unique_section_ids.Count); foreach (short section_id in unique_section_ids.Where(i => i != (short)IVisio.VisSectionIndices.visSectionObject)) { section_to_subquery[section_id] = query.AddSubQuery((IVisio.VisSectionIndices)section_id); } // Now for each src add it as a top level cell, or as a cell in // a subquery depending on its section index 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 { // the subquery will always be in the dictionary // because the dictionary was populated in a previous // step var subquery = section_to_subquery[src.Section]; subquery.AddCell(src, name); } } return(query); }
public VisioAutomation.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 ShapeSheetQuery(); var col_height = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.PageHeight, nameof(VisioAutomation.ShapeSheet.SrcConstants.PageHeight)); var col_width = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.PageWidth, nameof(VisioAutomation.ShapeSheet.SrcConstants.PageWidth)); var results = query.GetResults <double>(active_page.PageSheet); double height = results.Cells[col_height]; double width = results.Cells[col_width]; var s = new VisioAutomation.Drawing.Size(width, height); return(s); }
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.UserDefinedCellHelper.Set(s1, "foo", "bar", null); var query = new ShapeSheetQuery(); var sec = query.AddSubQuery(IVisio.VisSectionIndices.visSectionUser); var Value = sec.AddCell(VisioAutomation.ShapeSheet.SrcConstants.UserDelCellValue, "Value"); var Prompt = sec.AddCell(VisioAutomation.ShapeSheet.SrcConstants.UserDefCellPrompt, "Prompt"); var formulas = query.GetFormulas(page1, shapes.Select(s => s.ID).ToList()); page1.Delete(0); }
public void ShapeSheet_Writer_Formulas_MultipleShapes() { var page1 = this.GetNewPage(); var shape1 = page1.DrawRectangle(-1, -1, 0, 0); var shape2 = page1.DrawRectangle(-1, -1, 0, 0); var shape3 = page1.DrawRectangle(-1, -1, 0, 0); // Set the formulas var writer = new SidSrcWriter(); 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 ShapeSheetQuery(); 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 data_formulas = query.GetFormulas(page1, shapeids); var data_results = query.GetResults <double>(page1, 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); }
public ShapeSheetQuery ToQuery(IList <string> Cells) { var invalid_names = Cells.Where(cellname => !this.ContainsKey(cellname)).ToList(); if (invalid_names.Count > 0) { string msg = "Invalid cell names: " + string.Join(",", invalid_names); throw new ArgumentException(msg); } var query = new ShapeSheetQuery(); foreach (string resolved_cellname in this.ResolveNames(Cells)) { if (!query.Cells.Contains(resolved_cellname)) { var resolved_src = this[resolved_cellname]; query.AddCell(resolved_src, resolved_cellname); } } return(query); }
public static DataTable QueryToDataTable(ShapeSheetQuery cellQuery, bool getresults, ResultType ResultType, IList <int> shapeids, ShapeSheetSurface surface) { if (!getresults) { var output = cellQuery.GetFormulas(surface, shapeids); return(DataTableHelpers.querytable_to_datatable(cellQuery, output)); } switch (ResultType) { case ResultType.String: { var output = cellQuery.GetResults <string>(surface, shapeids); return(DataTableHelpers.querytable_to_datatable(cellQuery, output)); } case ResultType.Boolean: { var output = cellQuery.GetResults <bool>(surface, shapeids); return(DataTableHelpers.querytable_to_datatable(cellQuery, output)); } case ResultType.Double: { var output = cellQuery.GetResults <double>(surface, shapeids); return(DataTableHelpers.querytable_to_datatable(cellQuery, output)); } case ResultType.Integer: { var output = cellQuery.GetResults <int>(surface, shapeids); return(DataTableHelpers.querytable_to_datatable(cellQuery, output)); } } throw new System.ArgumentOutOfRangeException("Unsupported Result type"); }
/// <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 ShapeSheetQuery(); var width_col = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.XFormWidth, nameof(VisioAutomation.ShapeSheet.SrcConstants.XFormWidth)); var height_col = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.XFormHeight, nameof(VisioAutomation.ShapeSheet.SrcConstants.XFormWidth)); var queryresults = query.GetResults <double>(shape); this.cached_size_width = queryresults.Cells[width_col]; this.cached_size_height = queryresults.Cells[height_col]; }
/// <summary> /// Returns all the directed,connected pairs of shapes in the page /// </summary> /// <param name="page"></param> /// <param name="flag"></param> /// <returns></returns> public static List <ConnectorEdge> GetDirectedEdges( IVisio.Page page, ConnectorHandling flag) { if (page == null) { throw new System.ArgumentNullException(nameof(page)); } var edges = ConnectionAnalyzer.GetDirectedEdgesRaw(page); if (flag.DirectionSource == DirectionSource.UseConnectionOrder) { return(edges); } // At this point we know we need to analyze the connetor arrows to produce the correct results var connnector_ids = edges.Select(e => e.Connector.ID).ToList(); // Get the arrows for each connector var src_beginarrow = ShapeSheet.SrcConstants.LineBeginArrow; var src_endarrow = ShapeSheet.SrcConstants.LineEndArrow; var query = new ShapeSheetQuery(); var col_beginarrow = query.AddCell(src_beginarrow, nameof(ShapeSheet.SrcConstants.LineBeginArrow)); var col_endarrow = query.AddCell(src_endarrow, nameof(ShapeSheet.SrcConstants.LineEndArrow)); var arrow_table = query.GetResults <int>(page, connnector_ids); var directed_edges = new List <ConnectorEdge>(); int connector_index = 0; foreach (var e in edges) { int beginarrow = arrow_table[connector_index].Cells[col_beginarrow]; int endarrow = arrow_table[connector_index].Cells[col_endarrow]; if ((beginarrow < 1) && (endarrow < 1)) { // the line has no arrows if (flag.NoArrowsHandling == NoArrowsHandling.TreatEdgeAsBidirectional) { // in this case treat the connector as pointing in both directions var de1 = new ConnectorEdge(e.Connector, e.To, e.From); var de2 = new ConnectorEdge(e.Connector, e.From, e.To); directed_edges.Add(de1); directed_edges.Add(de2); } else if (flag.NoArrowsHandling == NoArrowsHandling.ExcludeEdge) { // in this case ignore the connector completely } else { throw new System.ArgumentOutOfRangeException(nameof(flag)); } } else { // The connector has either a from-arrow, a to-arrow, or both // handle if it has a from arrow if (beginarrow > 0) { var de = new ConnectorEdge(e.Connector, e.To, e.From); directed_edges.Add(de); } // handle if it has a to arrow if (endarrow > 0) { var de = new ConnectorEdge(e.Connector, e.From, e.To); directed_edges.Add(de); } } connector_index++; } return(directed_edges); }
protected ReaderBase() { this.query = new ShapeSheetQuery(); }
public static void Duplicate( IVisio.Page src_page, IVisio.Page dest_page) { init_page_srcs(); var app = src_page.Application; short copy_paste_flags = (short)IVisio.VisCutCopyPasteCodes.visCopyPasteNoTranslate; // handle the source page if (src_page == null) { throw new System.ArgumentNullException(nameof(src_page)); } if (dest_page == null) { throw new System.ArgumentNullException(nameof(dest_page)); } if (dest_page == src_page) { throw new System.ArgumentException("Destination Page cannot be Source Page"); } if (src_page != app.ActivePage) { throw new System.ArgumentException("Source page must be active page."); } var src_page_shapes = src_page.Shapes; int num_src_shapes = src_page_shapes.Count; if (num_src_shapes > 0) { var active_window = app.ActiveWindow; active_window.SelectAll(); var selection = active_window.Selection; selection.Copy(copy_paste_flags); active_window.DeselectAll(); } // Get the Cells from the Source var query = new ShapeSheetQuery(); int i = 0; foreach (var src in page_srcs) { query.AddCell(src, "Col" + i.ToString()); i++; } var src_formulas = query.GetFormulas(src_page.PageSheet); // Set the Cells on the Destination var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter(); for (i = 0; i < page_srcs.Count; i++) { writer.SetFormula(page_srcs[i], src_formulas.Cells[i]); } writer.Commit(dest_page.PageSheet); // make sure the new page looks like the old page dest_page.Background = src_page.Background; // then paste any contents from the first page if (num_src_shapes > 0) { dest_page.Paste(copy_paste_flags); } }
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.FillForeground; var src_bg = VA.ShapeSheet.SrcConstants.FillBackground; var src_filpat = VA.ShapeSheet.SrcConstants.FillPattern; var query = new ShapeSheetQuery(); 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.AddSubQuery(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.CharColorTransparency, "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].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); }