Ejemplo n.º 1
0
        public static void DistributeWithSpacing(IVisio.Page page, TargetShapeIDs target, VisioAutomation.Drawing.Layout.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 == VisioAutomation.Drawing.Layout.Axis.XAxis
                ? VisioAutomation.Scripting.Layout.RelativePosition.PinX
                : VisioAutomation.Scripting.Layout.RelativePosition.PinY;

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


            var input_xfrms = XForm.Get(page, target);
            var bb          = XForm.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 == VisioAutomation.Drawing.Layout.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);
        }