public static IList <int> SortShapesByPosition(IVisio.Page page, IList <int> shapeids, PositionOnShape pos) { if (page == null) { throw new System.ArgumentNullException("page"); } if (shapeids == null) { throw new System.ArgumentNullException("shapeids"); } // First get the transforms of the shapes on the given axis var xforms = ArrangeHelper.GetXForm(page, shapeids); // Then, sort the shapeids pased on the corresponding value in the results var sorted_shape_ids = Enumerable.Range(0, shapeids.Count) .Select(i => new { index = i, shapeid = shapeids[i], pos = GetPositionOnShape(xforms[i], pos) }) .OrderBy(i => i.pos) .Select(i => i.shapeid) .ToList(); return(sorted_shape_ids); }
private static double GetPositionOnShape(Shapes.XFormCells xform, RelativePosition pos) { switch (pos) { case RelativePosition.PinY: return(xform.PinY.Result); case RelativePosition.PinX: return(xform.PinX.Result); } var r = ArrangeHelper.GetRectangle(xform); switch (pos) { case RelativePosition.Left: return(r.Left); case RelativePosition.Right: return(r.Right); case RelativePosition.Top: return(r.Top); case RelativePosition.Bottom: return(r.Bottom); } throw new System.ArgumentOutOfRangeException(nameof(pos)); }
public static void SnapSize(IVisio.Page page, IList <int> shapeids, VA.Drawing.Size snapsize, VA.Drawing.Size minsize) { var input_xfrms = ArrangeHelper.GetXForm(page, shapeids); var output_xfrms = new List <VA.Shapes.XFormCells>(input_xfrms.Count); var grid = new VA.Drawing.SnappingGrid(snapsize); foreach (var input_xfrm in input_xfrms) { var inut_size = new VA.Drawing.Size(input_xfrm.Width.Result, input_xfrm.Height.Result); var snapped_size = grid.Snap(inut_size); double max_w = System.Math.Max(snapped_size.Width, minsize.Width); double max_h = System.Math.Max(snapped_size.Height, minsize.Height); var new_size = new VA.Drawing.Size(max_w, max_h); var output_xfrm = new VA.Shapes.XFormCells(); output_xfrm.Width = new_size.Width; output_xfrm.Height = new_size.Height; output_xfrms.Add(output_xfrm); } // Now apply them update_xfrms(page, shapeids, output_xfrms); }
public static void DistributeWithSpacing(IVisio.Page page, IList <int> shapeids, VA.Drawing.Axis axis, double spacing) { if (page == null) { throw new System.ArgumentNullException("page"); } if (shapeids == null) { throw new System.ArgumentNullException("shapeids"); } if (spacing < 0.0) { throw new System.ArgumentOutOfRangeException("spacing"); } if (shapeids.Count < 2) { return; } // Calculate the new Xfrms var sortpos = axis == VA.Drawing.Axis.XAxis ? PositionOnShape.PinX : PositionOnShape.PinY; var delta = axis == VA.Drawing.Axis.XAxis ? new VA.Drawing.Size(spacing, 0) : new VA.Drawing.Size(0, spacing); var sorted_shape_ids = ArrangeHelper.SortShapesByPosition(page, shapeids, sortpos); var input_xfrms = ArrangeHelper.GetXForm(page, sorted_shape_ids);; var output_xfrms = new List <VA.Shapes.XFormCells>(input_xfrms.Count); var bb = GetBoundingBox(input_xfrms); var cur_pos = new VA.Drawing.Point(bb.Left, bb.Bottom); foreach (var input_xfrm in input_xfrms) { var new_pinpos = axis == VA.Drawing.Axis.XAxis ? new VA.Drawing.Point(cur_pos.X + input_xfrm.LocPinX.Result, input_xfrm.PinY.Result) : new VA.Drawing.Point(input_xfrm.PinX.Result, cur_pos.Y + input_xfrm.LocPinY.Result); var output_xfrm = new VA.Shapes.XFormCells(); output_xfrm.PinX = new_pinpos.X; output_xfrm.PinY = new_pinpos.Y; output_xfrms.Add(output_xfrm); cur_pos = cur_pos.Add(input_xfrm.Width.Result, input_xfrm.Height.Result).Add(delta); } // Apply the changes update_xfrms(page, sorted_shape_ids, output_xfrms); }
public static VA.Drawing.Rectangle GetBoundingBox(IEnumerable <VA.Shapes.XFormCells> xfrms) { var bb = new VA.Drawing.BoundingBox(xfrms.Select(i => ArrangeHelper.GetRectangle(i))); if (!bb.HasValue) { throw new System.ArgumentException("Could not calculate bounding box"); } else { return(bb.Rectangle); } }
private static Shapes.XFormCells _SnapCorner(SnapCornerPosition corner, Drawing.Point new_lower_left, Shapes.XFormCells input_xfrm) { var new_pin_position = ArrangeHelper.GetPinPositionForCorner(input_xfrm, new_lower_left, corner); var output_xfrm = new Shapes.XFormCells(); if (new_pin_position.X != input_xfrm.PinX.Result) { output_xfrm.PinX = new_pin_position.X; } if (new_pin_position.Y != input_xfrm.PinY.Result) { output_xfrm.PinY = new_pin_position.Y; } return(output_xfrm); }
public static void SnapCorner(IVisio.Page page, IList <int> shapeids, VA.Drawing.Size snapsize, VA.Arrange.SnapCornerPosition corner) { // First caculate the new transforms var snap_grid = new VA.Drawing.SnappingGrid(snapsize); var input_xfrms = ArrangeHelper.GetXForm(page, shapeids); var output_xfrms = new List <VA.Shapes.XFormCells>(input_xfrms.Count); foreach (var input_xfrm in input_xfrms) { var old_lower_left = ArrangeHelper.GetRectangle(input_xfrm).LowerLeft; var new_lower_left = snap_grid.Snap(old_lower_left); var output_xfrm = _SnapCorner(corner, new_lower_left, input_xfrm); output_xfrms.Add(output_xfrm); } // Now apply them update_xfrms(page, shapeids, output_xfrms); }
public static void SnapSize(IVisio.Page page, IList <int> shapeids, Drawing.Size snapsize, Drawing.Size minsize) { var input_xfrms = Shapes.XFormCells.GetCells(page, shapeids); var output_xfrms = new List <Shapes.XFormCells>(input_xfrms.Count); var grid = new Drawing.SnappingGrid(snapsize); foreach (var input_xfrm in input_xfrms) { // First snap the size to the grid double old_w = input_xfrm.Width.Result; double old_h = input_xfrm.Height.Result; var input_size = new Drawing.Size(old_w, old_h); var snapped_size = grid.Snap(input_size); // then account for any minum size requirements double new_w = System.Math.Max(snapped_size.Width, minsize.Width); double new_h = System.Math.Max(snapped_size.Height, minsize.Height); var output_size = new Drawing.Size(new_w, new_h); // Output the new size for the shape if the size of the shape changed bool different_widths = (old_w != new_w); bool different_heights = (old_h != new_h); if (different_widths || different_heights) { var output_xfrm = new Shapes.XFormCells(); if (different_widths) { output_xfrm.Width = output_size.Width; } if (different_heights) { output_xfrm.Height = output_size.Height; } output_xfrms.Add(output_xfrm); } } // Now apply the updates to the sizes ArrangeHelper.update_xfrms(page, shapeids, output_xfrms); }
internal static IList <int> SortShapesByPosition(IVisio.Page page, IList <int> shapeids, RelativePosition pos) { // First get the transforms of the shapes on the given axis var xforms = Shapes.XFormCells.GetCells(page, shapeids); // Then, sort the shapeids pased on the corresponding value in the results var sorted_shape_ids = Enumerable.Range(0, shapeids.Count) .Select(i => new { index = i, shapeid = shapeids[i], pos = ArrangeHelper.GetPositionOnShape(xforms[i], pos) }) .OrderBy(i => i.pos) .Select(i => i.shapeid) .ToList(); return(sorted_shape_ids); }