public static List <ShapeXFormData> Get(Microsoft.Office.Interop.Visio.Page page, TargetShapeIDs target) { if (query == null) { query = new CellQuery(); ColPinX = query.Columns.Add(VisioAutomation.ShapeSheet.SrcConstants.XFormPinX, nameof(VisioAutomation.ShapeSheet.SrcConstants.XFormPinX)); ColPinY = query.Columns.Add(VisioAutomation.ShapeSheet.SrcConstants.XFormPinY, nameof(VisioAutomation.ShapeSheet.SrcConstants.XFormPinY)); ColLocPinX = query.Columns.Add(VisioAutomation.ShapeSheet.SrcConstants.XFormLocPinX, nameof(VisioAutomation.ShapeSheet.SrcConstants.XFormLocPinX)); ColLocPinY = query.Columns.Add(VisioAutomation.ShapeSheet.SrcConstants.XFormLocPinY, nameof(VisioAutomation.ShapeSheet.SrcConstants.XFormLocPinY)); ColWidth = query.Columns.Add(VisioAutomation.ShapeSheet.SrcConstants.XFormWidth, nameof(VisioAutomation.ShapeSheet.SrcConstants.XFormWidth)); ColHeight = query.Columns.Add(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 <ShapeXFormData>(target.ShapeIDs.Count); foreach (var row in results) { var xform = new ShapeXFormData(); 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_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.SetValue(LinePattern, 7); writer.CommitResults(shape1); // Build the query var query = new 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); }
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(LinePattern, "7"); writer.SetResult(XFormPinX, 2); writer.Commit(shape1); // Build the query var query = new CellQuery(); var col_linepat = query.Columns.Add(LinePattern, nameof(LinePattern)); var col_pinx = query.Columns.Add(XFormPinX, nameof(XFormPinX)); // 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); }
internal static Geometry.Size GetSize(IVisio.Page page) { var query = new CellQuery(); var col_height = query.Columns.Add(ShapeSheet.SrcConstants.PageHeight, nameof(ShapeSheet.SrcConstants.PageHeight)); var col_width = query.Columns.Add(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 Geometry.Size(width, height); return(s); }
public static VisioAutomation.Geometry.Size GetSize(IVisio.Shape shape) { var query = new CellQuery(); var col_w = query.Columns.Add(VisioAutomation.ShapeSheet.SrcConstants.XFormWidth, "Width"); var col_h = query.Columns.Add(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.Geometry.Size(w, h); return(size); }
public static DataTable QueryToDataTable(CellQuery cell_query, bool getresults, ResultType result_type, IList <int> shapeids, VisioAutomation.SurfaceTarget surface) { if (!getresults) { var output = cell_query.GetFormulas(surface, shapeids); return(DataTableHelpers.querytable_to_datatable(cell_query, output)); } switch (result_type) { case ResultType.String: { var output = cell_query.GetResults <string>(surface, shapeids); return(DataTableHelpers.querytable_to_datatable(cell_query, output)); } case ResultType.Boolean: { var output = cell_query.GetResults <bool>(surface, shapeids); return(DataTableHelpers.querytable_to_datatable(cell_query, output)); } case ResultType.Double: { var output = cell_query.GetResults <double>(surface, shapeids); return(DataTableHelpers.querytable_to_datatable(cell_query, output)); } case ResultType.Integer: { var output = cell_query.GetResults <int>(surface, shapeids); return(DataTableHelpers.querytable_to_datatable(cell_query, output)); } } throw new System.ArgumentOutOfRangeException("Unsupported Result type"); }
public static VA.Geometry.Size GetPageSize(IVisio.Page page) { if (page == null) { throw new System.ArgumentNullException(nameof(page)); } var query = new CellQuery(); var col_height = query.Columns.Add(VA.ShapeSheet.SrcConstants.PageHeight, nameof(VA.ShapeSheet.SrcConstants.PageHeight)); var col_width = query.Columns.Add(VA.ShapeSheet.SrcConstants.PageWidth, nameof(VA.ShapeSheet.SrcConstants.PageHeight)); var results = query.GetResults <double>(page.PageSheet); double height = results.Cells[col_height]; double width = results.Cells[col_width]; var s = new VA.Geometry.Size(width, height); return(s); }
public VisioAutomation.Geometry.Size GetSize() { this._client.Application.AssertApplicationAvailable(); this._client.Document.AssertDocumentAvailable(); var application = this._client.Application.Get(); var active_page = application.ActivePage; var query = new CellQuery(); var col_height = query.Columns.Add(VisioAutomation.ShapeSheet.SrcConstants.PageHeight, nameof(VisioAutomation.ShapeSheet.SrcConstants.PageHeight)); var col_width = query.Columns.Add(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.Geometry.Size(width, height); return(s); }
public void ShapeSheet_Writer_Formulas_MultipleShapes() { var page1 = this.GetNewPage(); var shape1 = page1.DrawRectangle(-1, -1, 0, 0); var shape2 = page1.DrawRectangle(-1, -1, 0, 0); var shape3 = page1.DrawRectangle(-1, -1, 0, 0); // Set the formulas var writer = new SidSrcWriter(); writer.SetValue(shape1.ID16, XFormPinX, 0.5); writer.SetValue(shape1.ID16, XFormPinY, 0.5); writer.SetValue(shape2.ID16, XFormPinX, 1.5); writer.SetValue(shape2.ID16, XFormPinY, 1.5); writer.SetValue(shape3.ID16, XFormPinX, 2.5); writer.SetValue(shape3.ID16, XFormPinY, 2.5); writer.CommitFormulas(page1); // Verify that the formulas were set var query = new CellQuery(); var col_pinx = query.Columns.Add(XFormPinX, nameof(XFormPinX)); var col_piny = query.Columns.Add(XFormPinY, nameof(XFormPinY)); 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][col_pinx], data_results[0][col_pinx])); AssertUtil.AreEqual(("0.5 in", 0.5), (data_formulas[0][col_piny], data_results[0][col_piny])); AssertUtil.AreEqual(("1.5 in", 1.5), (data_formulas[1][col_pinx], data_results[1][col_pinx])); AssertUtil.AreEqual(("1.5 in", 1.5), (data_formulas[1][col_piny], data_results[1][col_piny])); AssertUtil.AreEqual(("2.5 in", 2.5), (data_formulas[2][col_pinx], data_results[2][col_pinx])); AssertUtil.AreEqual(("2.5 in", 2.5), (data_formulas[2][col_piny], data_results[2][col_piny])); page1.Delete(0); }
/// <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._get_directed_edges_raw(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 CellQuery(); var col_beginarrow = query.Columns.Add(src_beginarrow, nameof(ShapeSheet.SrcConstants.LineBeginArrow)); var col_endarrow = query.Columns.Add(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][col_beginarrow]; int endarrow = arrow_table[connector_index][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); }