Example #1
0
        public void SnapCorner(double w, double h, VA.Arrange.SnapCornerPosition corner)
        {
            if (!this.Client.HasSelectedShapes())
            {
                return;
            }
            var shapes_2d   = Client.Selection.EnumShapes2D().ToList();
            var shapeids    = shapes_2d.Select(s => s.ID).ToList();
            var application = this.Client.VisioApplication;

            using (var undoscope = new VA.Application.UndoScope(application, "SnapCorner"))
            {
                var active_page = application.ActivePage;
                ArrangeHelper.SnapCorner(active_page, shapeids, new VA.Drawing.Size(w, h), corner);
            }
        }
Example #2
0
        private static VA.Shapes.XFormCells _SnapCorner(VA.Arrange.SnapCornerPosition corner, VA.Drawing.Point new_lower_left, VA.Shapes.XFormCells input_xfrm)
        {
            var new_pin_position = GetPinPositionForCorner(input_xfrm, new_lower_left, corner);

            var output_xfrm = new VA.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);
        }
Example #3
0
        private static VA.Drawing.Point GetPinPositionForCorner(VA.Shapes.XFormCells input_xfrm, VA.Drawing.Point new_lower_left, VA.Arrange.SnapCornerPosition corner)
        {
            var size   = new VA.Drawing.Size(input_xfrm.Width.Result, input_xfrm.Height.Result);
            var locpin = new VA.Drawing.Point(input_xfrm.LocPinX.Result, input_xfrm.LocPinY.Result);

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

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

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

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

            default:
            {
                throw new System.ArgumentOutOfRangeException("corner", "Unsupported corner");
            }
            }
        }
Example #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);
        }