internal static void _distribute_with_spacing(IVisio.Page page, IList <int> shapeids, Models.Axis axis, double spacing) { if (spacing < 0.0) { throw new System.ArgumentOutOfRangeException(nameof(spacing)); } if (shapeids.Count < 2) { return; } // Calculate the new Xfrms var sortpos = axis == VisioScripting.Models.Axis.XAxis ? VisioScripting.Models.ShapeRelativePosition.PinX : VisioScripting.Models.ShapeRelativePosition.PinY; var delta = axis == VisioScripting.Models.Axis.XAxis ? new VisioAutomation.Geometry.Size(spacing, 0) : new VisioAutomation.Geometry.Size(0, spacing); var input_xfrms = VisioScripting.Models.ShapeXFormData._get_xfrms(page, shapeids); var bb = VisioScripting.Models.ShapeXFormData.GetBoundingBox(input_xfrms); var cur_pos = new VisioAutomation.Geometry.Point(bb.Left, bb.Bottom); var newpositions = new List <VisioAutomation.Geometry.Point>(shapeids.Count); foreach (var input_xfrm in input_xfrms) { var new_pinpos = axis == VisioScripting.Models.Axis.XAxis ? new VisioAutomation.Geometry.Point(cur_pos.X + input_xfrm.XFormLocPinX, input_xfrm.XFormPinY) : new VisioAutomation.Geometry.Point(input_xfrm.XFormPinX, cur_pos.Y + input_xfrm.XFormLocPinY); newpositions.Add(new_pinpos); cur_pos = cur_pos.Add(input_xfrm.XFormWidth, input_xfrm.XFormHeight).Add(delta); } // Apply the changes var sorted_shapeids = ArrangeHelper._sort_shapes_by_position(page, shapeids, sortpos); _modify_pin_positions(page, sorted_shapeids, newpositions); }
public static void DistributeWithSpacing(IVisio.Page page, VisioScripting.Models.TargetShapeIDs target, VisioScripting.Models.Axis axis, double spacing) { if (spacing < 0.0) { throw new System.ArgumentOutOfRangeException(nameof(spacing)); } if (target.ShapeIDs.Count < 2) { return; } // Calculate the new Xfrms var sortpos = axis == VisioScripting.Models.Axis.XAxis ? VisioScripting.Models.ShapeRelativePosition.PinX : VisioScripting.Models.ShapeRelativePosition.PinY; var delta = axis == VisioScripting.Models.Axis.XAxis ? new VisioAutomation.Geometry.Size(spacing, 0) : new VisioAutomation.Geometry.Size(0, spacing); var input_xfrms = VisioScripting.Models.ShapeXFormData.Get(page, target); var bb = VisioScripting.Models.ShapeXFormData.GetBoundingBox(input_xfrms); var cur_pos = new VisioAutomation.Geometry.Point(bb.Left, bb.Bottom); var newpositions = new List <VisioAutomation.Geometry.Point>(target.ShapeIDs.Count); foreach (var input_xfrm in input_xfrms) { var new_pinpos = axis == VisioScripting.Models.Axis.XAxis ? new VisioAutomation.Geometry.Point(cur_pos.X + input_xfrm.LocPinX, input_xfrm.PinY) : new VisioAutomation.Geometry.Point(input_xfrm.PinX, cur_pos.Y + input_xfrm.LocPinY); newpositions.Add(new_pinpos); cur_pos = cur_pos.Add(input_xfrm.Width, input_xfrm.Height).Add(delta); } // Apply the changes var sorted_shape_ids = ArrangeHelper.SortShapesByPosition(page, target, sortpos); ModifyPinPositions(page, sorted_shape_ids, newpositions); }
public static void SnapCorner(IVisio.Page page, Models.TargetShapeIDs target, VisioAutomation.Geometry.Size snapsize, Models.SnapCornerPosition corner) { // First caculate the new transforms var snap_grid = new Models.SnappingGrid(snapsize); var input_xfrms = VisioScripting.Models.ShapeXFormData.Get(page, target); var output_xfrms = new List <VisioAutomation.Geometry.Point>(input_xfrms.Count); foreach (var input_xfrm in input_xfrms) { var old_rect = input_xfrm.GetRectangle(); var old_lower_left = old_rect.LowerLeft; var new_lower_left = snap_grid.Snap(old_lower_left); var new_pin_position = ArrangeHelper._get_pin_position_for_corner(input_xfrm, new_lower_left, corner); var output_xfrm = new VisioAutomation.Geometry.Point(new_pin_position.X, new_pin_position.Y); output_xfrms.Add(output_xfrm); } _modify_pin_positions(page, target.ShapeIDs, output_xfrms); }
internal static List <int> _sort_shapes_by_position(IVisio.Page page, IList <int> shapeids, Models.ShapeRelativePosition pos) { // First get the transforms of the shapes on the given axis var xforms = VisioScripting.Models.ShapeXFormData._get_xfrms(page, shapeids); // Then, sort the shapeids pased on the corresponding value in the results var sorted_shapeids = Enumerable.Range(0, shapeids.Count) .Select(i => new { index = i, shapeid = shapeids[i], pos = ArrangeHelper._get_position_on_shape(xforms[i], pos) }) .OrderBy(i => i.pos) .Select(i => i.shapeid) .ToList(); return(sorted_shapeids); }
internal static List <int> SortShapesByPosition(IVisio.Page page, VisioScripting.Models.TargetShapeIDs targets, VisioScripting.Models.ShapeRelativePosition pos) { // First get the transforms of the shapes on the given axis var xforms = VisioScripting.Models.ShapeXFormData.Get(page, targets); // Then, sort the shapeids pased on the corresponding value in the results var sorted_shape_ids = Enumerable.Range(0, targets.ShapeIDs.Count) .Select(i => new { index = i, shapeid = targets.ShapeIDs[i], pos = ArrangeHelper.GetPositionOnShape(xforms[i], pos) }) .OrderBy(i => i.pos) .Select(i => i.shapeid) .ToList(); return(sorted_shape_ids); }