Пример #1
0
        private static Drawing.Point GetPinPositionForCorner(Shapes.XFormCells input_xfrm, Drawing.Point new_lower_left, SnapCornerPosition corner)
        {
            var size   = new Drawing.Size(input_xfrm.Width.Result, input_xfrm.Height.Result);
            var locpin = new Drawing.Point(input_xfrm.LocPinX.Result, input_xfrm.LocPinY.Result);

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

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

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

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

            default:
            {
                throw new System.ArgumentOutOfRangeException(nameof(corner), "Unsupported corner");
            }
            }
        }
Пример #2
0
        private static void SnapSize(IVisio.Page page, IList <int> shapeids, Drawing.Size snapsize, Drawing.Size minsize)
        {
            var input_xfrms  = Shapes.XFormCells.GetCells(page, shapeids);
            var output_xfrms = new List <Shapes.XFormCells>(input_xfrms.Count);

            var grid = new Drawing.SnappingGrid(snapsize);

            foreach (var input_xfrm in input_xfrms)
            {
                var    inut_size    = new 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 Drawing.Size(max_w, max_h);

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

                output_xfrms.Add(output_xfrm);
            }

            // Now apply them
            ArrangeCommands.update_xfrms(page, shapeids, output_xfrms);
        }
Пример #3
0
        private static double GetPositionOnShape(Shapes.XFormCells xform, RelativePosition pos)
        {
            switch (pos)
            {
            case RelativePosition.PinY:
                return(xform.PinY.Result);

            case RelativePosition.PinX:
                return(xform.PinX.Result);
            }

            var r = ArrangeHelper.GetRectangle(xform);

            switch (pos)
            {
            case RelativePosition.Left:
                return(r.Left);

            case RelativePosition.Right:
                return(r.Right);

            case RelativePosition.Top:
                return(r.Top);

            case RelativePosition.Bottom:
                return(r.Bottom);
            }

            throw new System.ArgumentOutOfRangeException(nameof(pos));
        }
Пример #4
0
        private static Drawing.Rectangle GetRectangle(Shapes.XFormCells xFormCells)
        {
            var pin    = new Drawing.Point(xFormCells.PinX.Result, xFormCells.PinY.Result);
            var locpin = new Drawing.Point(xFormCells.LocPinX.Result, xFormCells.LocPinY.Result);
            var size   = new Drawing.Size(xFormCells.Width.Result, xFormCells.Height.Result);

            return(new Drawing.Rectangle(pin - locpin, size));
        }
Пример #5
0
        public override XFormCells CellDataToCellGroup(VisioAutomation.Utilities.ArraySegment <ShapeSheet.CellData> row)
        {
            var cells = new Shapes.XFormCells();

            cells.PinX    = row[this.PinX];
            cells.PinY    = row[this.PinY];
            cells.LocPinX = row[this.LocPinX];
            cells.LocPinY = row[this.LocPinY];
            cells.Width   = row[this.Width];
            cells.Height  = row[this.Height];
            cells.Angle   = row[this.Angle];
            return(cells);
        }
Пример #6
0
        public override XFormCells CellDataToCellGroup(CellData[] row)
        {
            var cells = new Shapes.XFormCells();

            cells.PinX    = row[this.PinX];
            cells.PinY    = row[this.PinY];
            cells.LocPinX = row[this.LocPinX];
            cells.LocPinY = row[this.LocPinY];
            cells.Width   = row[this.Width];
            cells.Height  = row[this.Height];
            cells.Angle   = row[this.Angle];
            return(cells);
        }
Пример #7
0
        private static Shapes.XFormCells _SnapCorner(SnapCornerPosition corner, Drawing.Point new_lower_left, Shapes.XFormCells input_xfrm)
        {
            var new_pin_position = ArrangeHelper.GetPinPositionForCorner(input_xfrm, new_lower_left, corner);

            var output_xfrm = new Shapes.XFormCells();

            if (new_pin_position.X != input_xfrm.PinX.Result)
            {
                output_xfrm.PinX = new_pin_position.X;
            }
            if (new_pin_position.Y != input_xfrm.PinY.Result)
            {
                output_xfrm.PinY = new_pin_position.Y;
            }
            return(output_xfrm);
        }
Пример #8
0
        public static void DistributeWithSpacing(IVisio.Page page, IList <int> shapeids, Drawing.Axis axis, double spacing)
        {
            if (spacing < 0.0)
            {
                throw new System.ArgumentOutOfRangeException(nameof(spacing));
            }

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

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

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


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

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

                var output_xfrm = new 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
            ArrangeHelper.update_xfrms(page, sorted_shape_ids, output_xfrms);
        }
Пример #9
0
        public static void SnapSize(IVisio.Page page, IList <int> shapeids, Drawing.Size snapsize, Drawing.Size minsize)
        {
            var input_xfrms  = Shapes.XFormCells.GetCells(page, shapeids);
            var output_xfrms = new List <Shapes.XFormCells>(input_xfrms.Count);

            var grid = new Drawing.SnappingGrid(snapsize);

            foreach (var input_xfrm in input_xfrms)
            {
                // First snap the size to the grid
                double old_w        = input_xfrm.Width.Result;
                double old_h        = input_xfrm.Height.Result;
                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);
                var    output_size = new Drawing.Size(new_w, new_h);

                // Output the new size for the shape if the size of the shape changed
                bool different_widths  = (old_w != new_w);
                bool different_heights = (old_h != new_h);
                if (different_widths || different_heights)
                {
                    var output_xfrm = new Shapes.XFormCells();
                    if (different_widths)
                    {
                        output_xfrm.Width = output_size.Width;
                    }
                    if (different_heights)
                    {
                        output_xfrm.Height = output_size.Height;
                    }
                    output_xfrms.Add(output_xfrm);
                }
            }

            // Now apply the updates to the sizes
            ArrangeHelper.update_xfrms(page, shapeids, output_xfrms);
        }
Пример #10
0
        private static short[] DropManyU(
            IVisio.Page page,
            IList <IVisio.Master> masters,
            IList <Drawing.Rectangle> rects)
        {
            var points   = rects.Select(r => r.Center).ToList();
            var shapeids = Pages.PageHelper.DropManyU(page, masters, points);

            var xfrm = new Shapes.XFormCells();

            var update = new ShapeSheet.Update(points.Count * 2);

            for (int i = 0; i < rects.Count(); i++)
            {
                xfrm.Width  = rects[i].Width;
                xfrm.Height = rects[i].Height;
                update.SetFormulas(shapeids[i], xfrm);
            }
            update.Execute(page);

            return(shapeids);
        }
        private static void SnapSize(IVisio.Page page, IList<int> shapeids, Drawing.Size snapsize, Drawing.Size minsize)
        {
            var input_xfrms = Shapes.XFormCells.GetCells(page, shapeids);
            var output_xfrms = new List<Shapes.XFormCells>(input_xfrms.Count);

            var grid = new Drawing.SnappingGrid(snapsize);
            foreach (var input_xfrm in input_xfrms)
            {
                var inut_size = new 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 Drawing.Size(max_w, max_h);

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

                output_xfrms.Add(output_xfrm);
            }

            // Now apply them
            ArrangeCommands.update_xfrms(page, shapeids, output_xfrms);
        }
        public static void DistributeWithSpacing(IVisio.Page page, IList<int> shapeids, Drawing.Axis axis, double spacing)
        {
            if (spacing < 0.0)
            {
                throw new System.ArgumentOutOfRangeException(nameof(spacing));
            }

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

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

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


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

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

                var output_xfrm = new 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
            ArrangeHelper.update_xfrms(page, sorted_shape_ids, output_xfrms);
        }
        public static void SnapSize(IVisio.Page page, IList<int> shapeids, Drawing.Size snapsize, Drawing.Size minsize)
        {
            var input_xfrms = Shapes.XFormCells.GetCells(page, shapeids);
            var output_xfrms = new List<Shapes.XFormCells>(input_xfrms.Count);

            var grid = new Drawing.SnappingGrid(snapsize);
            foreach (var input_xfrm in input_xfrms)
            {
                // First snap the size to the grid
                double old_w = input_xfrm.Width.Result;
                double old_h = input_xfrm.Height.Result;
                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);
                var output_size = new Drawing.Size(new_w, new_h);
                
                // Output the new size for the shape if the size of the shape changed
                bool different_widths = (old_w != new_w);
                bool different_heights = (old_h != new_h);
                if (different_widths || different_heights)
                {
                    var output_xfrm = new Shapes.XFormCells();
                    if (different_widths) 
                    {
                        output_xfrm.Width = output_size.Width;                    
                    }
                    if (different_heights)
                    {
                        output_xfrm.Height = output_size.Height;
                    }
                    output_xfrms.Add(output_xfrm);
                }
            }

            // Now apply the updates to the sizes
            ArrangeHelper.update_xfrms(page, shapeids, output_xfrms);
        }
        private static Shapes.XFormCells _SnapCorner(SnapCornerPosition corner, Drawing.Point new_lower_left, Shapes.XFormCells input_xfrm)
        {
            var new_pin_position = ArrangeHelper.GetPinPositionForCorner(input_xfrm, new_lower_left, corner);

            var output_xfrm = new Shapes.XFormCells();
            if (new_pin_position.X != input_xfrm.PinX.Result)
            {
                output_xfrm.PinX = new_pin_position.X;
            }
            if (new_pin_position.Y != input_xfrm.PinY.Result)
            {
                output_xfrm.PinY = new_pin_position.Y;
            }
            return output_xfrm;
        }
        private static short[] DropManyU(
            IVisio.Page page,
            IList<IVisio.Master> masters,
            IList<Drawing.Rectangle> rects)
        {
            var points = rects.Select(r => r.Center).ToList();
            var shapeids = Pages.PageHelper.DropManyU(page, masters, points);

            var xfrm = new Shapes.XFormCells();

            var update = new ShapeSheet.Update(points.Count*2);
            for (int i = 0; i < rects.Count(); i++)
            {
                xfrm.Width = rects[i].Width;
                xfrm.Height = rects[i].Height;
                update.SetFormulas(shapeids[i], xfrm);
            }
            update.Execute(page);

            return shapeids;
        }