Пример #1
0
        public static void SnapSize(IVisio.Page page, IList <int> shapeids, VA.Drawing.Size snapsize, VA.Drawing.Size minsize)
        {
            var input_xfrms  = ArrangeHelper.GetXForm(page, shapeids);
            var output_xfrms = new List <VA.Shapes.XFormCells>(input_xfrms.Count);

            var grid = new VA.Drawing.SnappingGrid(snapsize);

            foreach (var input_xfrm in input_xfrms)
            {
                var    inut_size    = new VA.Drawing.Size(input_xfrm.Width.Result, input_xfrm.Height.Result);
                var    snapped_size = grid.Snap(inut_size);
                double max_w        = System.Math.Max(snapped_size.Width, minsize.Width);
                double max_h        = System.Math.Max(snapped_size.Height, minsize.Height);
                var    new_size     = new VA.Drawing.Size(max_w, max_h);

                var output_xfrm = new VA.Shapes.XFormCells();
                output_xfrm.Width  = new_size.Width;
                output_xfrm.Height = new_size.Height;

                output_xfrms.Add(output_xfrm);
            }

            // Now apply them
            update_xfrms(page, shapeids, output_xfrms);
        }
Пример #2
0
        public static IList <int> SortShapesByPosition(IVisio.Page page, IList <int> shapeids, PositionOnShape pos)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException("page");
            }

            if (shapeids == null)
            {
                throw new System.ArgumentNullException("shapeids");
            }

            // First get the transforms of the shapes on the given axis
            var xforms = ArrangeHelper.GetXForm(page, shapeids);

            // Then, sort the shapeids pased on the corresponding value in the results


            var sorted_shape_ids = Enumerable.Range(0, shapeids.Count)
                                   .Select(i => new { index = i, shapeid = shapeids[i], pos = GetPositionOnShape(xforms[i], pos) })
                                   .OrderBy(i => i.pos)
                                   .Select(i => i.shapeid)
                                   .ToList();

            return(sorted_shape_ids);
        }
Пример #3
0
        public static void DistributeWithSpacing(IVisio.Page page, IList <int> shapeids, VA.Drawing.Axis axis, double spacing)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException("page");
            }

            if (shapeids == null)
            {
                throw new System.ArgumentNullException("shapeids");
            }

            if (spacing < 0.0)
            {
                throw new System.ArgumentOutOfRangeException("spacing");
            }

            if (shapeids.Count < 2)
            {
                return;
            }

            // Calculate the new Xfrms
            var sortpos = axis == VA.Drawing.Axis.XAxis
                ? PositionOnShape.PinX
                : PositionOnShape.PinY;

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


            var sorted_shape_ids = ArrangeHelper.SortShapesByPosition(page, shapeids, sortpos);
            var input_xfrms      = ArrangeHelper.GetXForm(page, sorted_shape_ids);;
            var output_xfrms     = new List <VA.Shapes.XFormCells>(input_xfrms.Count);
            var bb      = GetBoundingBox(input_xfrms);
            var cur_pos = new VA.Drawing.Point(bb.Left, bb.Bottom);

            foreach (var input_xfrm in input_xfrms)
            {
                var new_pinpos = axis == VA.Drawing.Axis.XAxis
                    ? new VA.Drawing.Point(cur_pos.X + input_xfrm.LocPinX.Result, input_xfrm.PinY.Result)
                    : new VA.Drawing.Point(input_xfrm.PinX.Result, cur_pos.Y + input_xfrm.LocPinY.Result);

                var output_xfrm = new VA.Shapes.XFormCells();
                output_xfrm.PinX = new_pinpos.X;
                output_xfrm.PinY = new_pinpos.Y;
                output_xfrms.Add(output_xfrm);

                cur_pos = cur_pos.Add(input_xfrm.Width.Result, input_xfrm.Height.Result).Add(delta);
            }

            // Apply the changes
            update_xfrms(page, sorted_shape_ids, output_xfrms);
        }
Пример #4
0
        public static void SnapCorner(IVisio.Page page, IList <int> shapeids, VA.Drawing.Size snapsize, VA.Arrange.SnapCornerPosition corner)
        {
            // First caculate the new transforms
            var snap_grid    = new VA.Drawing.SnappingGrid(snapsize);
            var input_xfrms  = ArrangeHelper.GetXForm(page, shapeids);
            var output_xfrms = new List <VA.Shapes.XFormCells>(input_xfrms.Count);

            foreach (var input_xfrm in input_xfrms)
            {
                var old_lower_left = ArrangeHelper.GetRectangle(input_xfrm).LowerLeft;
                var new_lower_left = snap_grid.Snap(old_lower_left);
                var output_xfrm    = _SnapCorner(corner, new_lower_left, input_xfrm);
                output_xfrms.Add(output_xfrm);
            }

            // Now apply them
            update_xfrms(page, shapeids, output_xfrms);
        }