private static double GetPositionOnShape(ShapeXFormData xform, ShapeRelativePosition pos) { var r = xform.GetRectangle(); switch (pos) { case ShapeRelativePosition.PinY: return(xform.PinY); case ShapeRelativePosition.PinX: return(xform.PinX); case ShapeRelativePosition.Left: return(r.Left); case ShapeRelativePosition.Right: return(r.Right); case ShapeRelativePosition.Top: return(r.Top); case ShapeRelativePosition.Bottom: return(r.Bottom); } throw new System.ArgumentOutOfRangeException(nameof(pos)); }
internal static List <int> SortShapesByPosition(IVisio.Page page, TargetShapeIDs targets, ShapeRelativePosition pos) { // First get the transforms of the shapes on the given axis var xforms = 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); }