Пример #1
0
        public static void DistributeWithSpacing(IVisio.Page page, TargetShapeIDs target, 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 == Axis.XAxis
                ? ShapeRelativePosition.PinX
                : ShapeRelativePosition.PinY;

            var delta = axis == Axis.XAxis
                ? new Drawing.Size(spacing, 0)
                : new Drawing.Size(0, spacing);


            var input_xfrms = ShapeXFormData.Get(page, target);
            var bb          = ShapeXFormData.GetBoundingBox(input_xfrms);
            var cur_pos     = new Drawing.Point(bb.Left, bb.Bottom);

            var newpositions = new List <VisioAutomation.Drawing.Point>(target.ShapeIDs.Count);

            foreach (var input_xfrm in input_xfrms)
            {
                var new_pinpos = axis == Axis.XAxis
                    ? new Drawing.Point(cur_pos.X + input_xfrm.LocPinX, input_xfrm.PinY)
                    : new Drawing.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);
        }
Пример #2
0
        public static void SnapCorner(IVisio.Page page, TargetShapeIDs target, Drawing.Size snapsize, SnapCornerPosition corner)
        {
            // First caculate the new transforms
            var snap_grid    = new SnappingGrid(snapsize);
            var input_xfrms  = ShapeXFormData.Get(page, target);
            var output_xfrms = new List <VisioAutomation.Drawing.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.GetPinPositionForCorner(input_xfrm, new_lower_left, corner);
                var output_xfrm      = new VisioAutomation.Drawing.Point(new_pin_position.X, new_pin_position.Y);
                output_xfrms.Add(output_xfrm);
            }

            ModifyPinPositions(page, target.ShapeIDs, output_xfrms);
        }
Пример #3
0
        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);
        }