Exemplo n.º 1
0
        public static void SnapSize(IVisio.Page page, TargetShapeIDs target, Drawing.Size snapsize, Drawing.Size minsize)
        {
            var input_xfrms = XFormData.Get(page, target);
            var sizes       = new List <VisioAutomation.Drawing.Size>(input_xfrms.Count);

            var grid = new SnappingGrid(snapsize);

            foreach (var input_xfrm in input_xfrms)
            {
                // First snap the size to the grid
                double old_w        = input_xfrm.Width;
                double old_h        = input_xfrm.Height;
                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);

                sizes.Add(new VisioAutomation.Drawing.Size(new_w, new_h));
            }

            // Now apply the updates to the sizes
            ModifySizes(page, target.ShapeIDs, sizes);
        }
Exemplo n.º 2
0
        public static List <XFormData> Get(Microsoft.Office.Interop.Visio.Page page, TargetShapeIDs target)
        {
            if (query == null)
            {
                query      = new ShapeSheetQuery();
                ColPinX    = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.XFormPinX, nameof(VisioAutomation.ShapeSheet.SrcConstants.XFormPinX));
                ColPinY    = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.XFormPinY, nameof(VisioAutomation.ShapeSheet.SrcConstants.XFormPinY));
                ColLocPinX = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.XFormLocPinX, nameof(VisioAutomation.ShapeSheet.SrcConstants.XFormLocPinX));
                ColLocPinY = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.XFormLocPinY, nameof(VisioAutomation.ShapeSheet.SrcConstants.XFormLocPinY));
                ColWidth   = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.XFormWidth, nameof(VisioAutomation.ShapeSheet.SrcConstants.XFormWidth));
                ColHeight  = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.XFormHeight, nameof(VisioAutomation.ShapeSheet.SrcConstants.XFormHeight));
            }

            var results = query.GetResults <double>(page, target.ShapeIDs);

            if (results.Count != target.ShapeIDs.Count)
            {
                throw new VisioAutomation.Exceptions.InternalAssertionException("Didn't get as many rows back as expected");
            }
            var list = new List <XFormData>(target.ShapeIDs.Count);

            foreach (var row in results)
            {
                var xform = new XFormData();
                xform.PinX    = row.Cells[ColPinX];
                xform.PinY    = row.Cells[ColPinY];
                xform.LocPinX = row.Cells[ColLocPinX];
                xform.LocPinY = row.Cells[ColLocPinY];
                xform.Width   = row.Cells[ColWidth];
                xform.Height  = row.Cells[ColHeight];
                list.Add(xform);
            }
            return(list);
        }
Exemplo n.º 3
0
        private static Drawing.Point GetPinPositionForCorner(XFormData input_xfrm, Drawing.Point new_lower_left, VisioAutomation.Scripting.Layout.SnapCornerPosition corner)
        {
            var size   = new Drawing.Size(input_xfrm.Width, input_xfrm.Height);
            var locpin = new Drawing.Point(input_xfrm.LocPinX, input_xfrm.LocPinY);

            switch (corner)
            {
            case VisioAutomation.Scripting.Layout.SnapCornerPosition.LowerLeft:
            {
                return(new_lower_left.Add(locpin.X, locpin.Y));
            }

            case VisioAutomation.Scripting.Layout.SnapCornerPosition.UpperRight:
            {
                return(new_lower_left.Subtract(size.Width, size.Height).Add(locpin.X, locpin.Y));
            }

            case VisioAutomation.Scripting.Layout.SnapCornerPosition.LowerRight:
            {
                return(new_lower_left.Subtract(size.Width, 0).Add(locpin.X, locpin.Y));
            }

            case VisioAutomation.Scripting.Layout.SnapCornerPosition.UpperLeft:
            {
                return(new_lower_left.Subtract(0, size.Height).Add(locpin.X, locpin.Y));
            }

            default:
            {
                throw new System.ArgumentOutOfRangeException(nameof(corner), "Unsupported corner");
            }
            }
        }
Exemplo n.º 4
0
        private static double GetPositionOnShape(XFormData xform, VisioAutomation.Scripting.Layout.RelativePosition pos)
        {
            var r = xform.GetRectangle();

            switch (pos)
            {
            case VisioAutomation.Scripting.Layout.RelativePosition.PinY:
                return(xform.PinY);

            case VisioAutomation.Scripting.Layout.RelativePosition.PinX:
                return(xform.PinX);

            case VisioAutomation.Scripting.Layout.RelativePosition.Left:
                return(r.Left);

            case VisioAutomation.Scripting.Layout.RelativePosition.Right:
                return(r.Right);

            case VisioAutomation.Scripting.Layout.RelativePosition.Top:
                return(r.Top);

            case VisioAutomation.Scripting.Layout.RelativePosition.Bottom:
                return(r.Bottom);
            }

            throw new System.ArgumentOutOfRangeException(nameof(pos));
        }
Exemplo n.º 5
0
        internal static List <int> SortShapesByPosition(IVisio.Page page, TargetShapeIDs targets, VisioAutomation.Scripting.Layout.RelativePosition pos)
        {
            // First get the transforms of the shapes on the given axis
            var xforms = XFormData.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);
        }
Exemplo n.º 6
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
                ? VisioAutomation.Scripting.Layout.RelativePosition.PinX
                : VisioAutomation.Scripting.Layout.RelativePosition.PinY;

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


            var input_xfrms = XFormData.Get(page, target);
            var bb          = XFormData.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);
        }
Exemplo n.º 7
0
        public static void SnapCorner(IVisio.Page page, TargetShapeIDs target, Drawing.Size snapsize, VisioAutomation.Scripting.Layout.SnapCornerPosition corner)
        {
            // First caculate the new transforms
            var snap_grid    = new SnappingGrid(snapsize);
            var input_xfrms  = XFormData.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);
        }