Ejemplo n.º 1
0
 private static double GetPositionOnShape(VA.Shapes.XFormCells xform, PositionOnShape pos)
 {
     if (pos == PositionOnShape.PinY)
     {
         return(xform.PinY.Result);
     }
     else if (pos == PositionOnShape.PinX)
     {
         return(xform.PinX.Result);
     }
     else
     {
         var r = GetRectangle(xform);
         if (pos == PositionOnShape.Left)
         {
             return(r.Left);
         }
         else if (pos == PositionOnShape.Right)
         {
             return(r.Right);
         }
         else if (pos == PositionOnShape.Top)
         {
             return(r.Top);
         }
         else if (pos == PositionOnShape.Right)
         {
             return(r.Bottom);
         }
         else
         {
             throw new System.ArgumentOutOfRangeException("pos");
         }
     }
 }
Ejemplo n.º 2
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");
            }
            }
        }
Ejemplo n.º 3
0
        private static void SnapSize(IVisio.Page page, IList <int> shapeids, VA.Drawing.Size snapsize, VA.Drawing.Size minsize)
        {
            var input_xfrms  = VA.Shapes.XFormCells.GetCells(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);
        }
Ejemplo n.º 4
0
        private static VA.Drawing.Rectangle GetRectangle(VA.Shapes.XFormCells xFormCells)
        {
            var pin    = new VA.Drawing.Point(xFormCells.PinX.Result, xFormCells.PinY.Result);
            var locpin = new VA.Drawing.Point(xFormCells.LocPinX.Result, xFormCells.LocPinY.Result);
            var size   = new VA.Drawing.Size(xFormCells.Width.Result, xFormCells.Height.Result);

            return(new VA.Drawing.Rectangle(pin - locpin, size));
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public static void ProgressBar()
        {
            var page_a = SampleEnvironment.Application.ActiveDocument.Pages.Add();


            // Draw some shapes
            var background = page_a.DrawRectangle(0, 0, 5, 1);
            var progress   = page_a.DrawRectangle(0, 0, 1, 1);

            var background_fmt = new VA.Shapes.ShapeFormatCells();

            background_fmt.FillForeground = "rgb(240,240,240)";
            background_fmt.LineColor      = "rgb(100,100,100)";


            var progress_fmt = new VA.Shapes.ShapeFormatCells();

            progress_fmt.FillForeground = "rgb(100,150,240)";
            progress_fmt.LineColor      = "rgb(100,100,100)";

            // group the two shapes together
            page_a.Application.ActiveWindow.SelectAll();
            var group = page_a.Application.ActiveWindow.Selection.Group();

            // Set the progress shape update itself based on its position
            string bkname = background.NameID;
            var    xform  = new VA.Shapes.XFormCells();

            xform.PinX   = string.Format("GUARD({0}!PinX-{0}!LocPinX+LocPinX)", bkname);
            xform.PinY   = string.Format("GUARD({0}!PinY)", bkname);
            xform.Width  = string.Format("GUARD({0}!Width*(PAGENUMBER()/PAGECOUNT()))", bkname);
            xform.Height = string.Format("GUARD({0}!Height)", bkname);

            var writer = new SidSrcWriter();

            xform.SetFormulas(progress.ID16, writer);
            background_fmt.SetFormulas(progress.ID16, writer);
            progress_fmt.SetFormulas(progress.ID16, writer);

            writer.Commit(page_a);

            var markup1 = new VisioAutomation.Models.Text.TextElement();

            markup1.AddField(VisioAutomation.Models.Text.FieldConstants.PageName);
            markup1.AddText(" (");
            markup1.AddField(VisioAutomation.Models.Text.FieldConstants.PageNumber);
            markup1.AddText(" of ");
            markup1.AddField(VisioAutomation.Models.Text.FieldConstants.NumberOfPages);
            markup1.AddText(") ");
            markup1.SetText(group);
        }
Ejemplo n.º 8
0
        public static void Spirograph()
        {
            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            page.Name = "Spirograph";

            var colors = new[]
            {
                0xf26420, 0xf7931c, 0xfec20d, 0xfff200,
                0xcada28, 0x8cc63e, 0x6c9d30, 0x288f39,
                0x006f3a, 0x006f71, 0x008eb0, 0x00adee,
                0x008ed3, 0x0071bb, 0x0053a6, 0x2e3091,
                0x5b57a6, 0x652d91, 0x92278e, 0xbd198c,
                0xec008b, 0xec1c23, 0xc1272c, 0x981a1e
            };

            var    origin             = new VA.Drawing.Point(4, 4);
            double radius             = 3.0;
            int    numpoints          = colors.Length;
            double angle_step         = (System.Math.PI * 2 / numpoints);
            var    angles             = Enumerable.Range(0, numpoints).Select(i => i * angle_step).ToList();
            var    centers            = angles.Select(a => PlaygroundSamples.GetPointAtRadius(origin, a, radius)).ToList();
            var    shapes             = centers.Select(p => PlaygroundSamples.draw_leaf(page, p)).ToList();
            var    angles_as_formulas = angles.Select(a => a.ToString(CultureInfo.InvariantCulture)).ToList();

            var color_formulas = colors.Select(x => new VA.Drawing.ColorRGB(x).ToFormula()).ToList();

            var shapeids = shapes.Select(s => s.ID16).ToList();

            var writer = new SidSrcWriter();
            var format = new VA.Shapes.ShapeFormatCells();
            var xfrm   = new VA.Shapes.XFormCells();

            foreach (int i in Enumerable.Range(0, shapeids.Count))
            {
                short shapeid = shapeids[i];

                xfrm.Angle                        = angles_as_formulas[i];
                format.FillForeground             = color_formulas[i];
                format.LineWeight                 = 0;
                format.LinePattern                = 0;
                format.FillForegroundTransparency = 0.5;

                xfrm.SetFormulas(shapeid, writer);
                format.SetFormulas(shapeid, writer);
            }

            writer.Commit(page);

            page.ResizeToFitContents(new VA.Drawing.Size(1.0, 1.0));
        }
 public VisioAutomation.Shapes.XFormCells GetCells(System.Collections.Generic.IList<ShapeSheet.CellData<double>> row)
 {
     var cells = new VisioAutomation.Shapes.XFormCells
     {
         PinX = row[this.PinX],
         PinY = row[this.PinY],
         LocPinX = row[this.LocPinX],
         LocPinY = row[this.LocPinY],
         Width = row[this.Width],
         Height = row[this.Height],
         Angle = row[this.Angle]
     };
     return cells;
 }
        public static void Spirograph()
        {
            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();
            page.Name = "Spirograph";

            var colors = new[]
                    {
                        0xf26420, 0xf7931c, 0xfec20d, 0xfff200, 
                        0xcada28, 0x8cc63e, 0x6c9d30, 0x288f39,
                        0x006f3a, 0x006f71, 0x008eb0, 0x00adee, 
                        0x008ed3, 0x0071bb, 0x0053a6, 0x2e3091, 
                        0x5b57a6, 0x652d91, 0x92278e, 0xbd198c, 
                        0xec008b, 0xec1c23, 0xc1272c, 0x981a1e
                    };

            var origin = new VA.Drawing.Point(4, 4);
            double radius = 3.0;
            int numpoints = colors.Length;
            double angle_step = (System.Math.PI*2/numpoints);
            var angles = Enumerable.Range(0, numpoints).Select(i => i*angle_step).ToList();
            var centers = angles.Select(a => PlaygroundSamples.GetPointAtRadius(origin, a, radius)).ToList();
            var shapes = centers.Select(p => PlaygroundSamples.draw_leaf(page, p)).ToList();
            var angles_as_formulas = angles.Select(a => a.ToString(CultureInfo.InvariantCulture)).ToList();

            var color_formulas = colors.Select(x => new VA.Drawing.ColorRGB(x).ToFormula()).ToList();

            var shapeids = shapes.Select(s => s.ID16).ToList();

            var update = new VA.ShapeSheet.Update();
            var format = new VA.Shapes.FormatCells();
            var xfrm = new VA.Shapes.XFormCells();

            foreach (int i in Enumerable.Range(0, shapeids.Count))
            {
                short shapeid = shapeids[i];

                xfrm.Angle = angles_as_formulas[i];
                format.FillForegnd = color_formulas[i];
                format.LineWeight = 0;
                format.LinePattern = 0;
                format.FillForegndTrans = 0.5;

                update.SetFormulas(shapeid, xfrm);
                update.SetFormulas(shapeid, format);
            }

            update.Execute(page);
            VA.Pages.PageHelper.ResizeToFitContents(page, new VA.Drawing.Size(1.0, 1.0));
        }
Ejemplo n.º 11
0
        public VisioAutomation.Shapes.XFormCells GetCells(System.Collections.Generic.IList <ShapeSheet.CellData <double> > row)
        {
            var cells = new VisioAutomation.Shapes.XFormCells
            {
                PinX    = row[this.PinX],
                PinY    = row[this.PinY],
                LocPinX = row[this.LocPinX],
                LocPinY = row[this.LocPinY],
                Width   = row[this.Width],
                Height  = row[this.Height],
                Angle   = row[this.Angle]
            };

            return(cells);
        }
Ejemplo n.º 12
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);
        }
        public static void ProgressBar()
        {
            var page_a = SampleEnvironment.Application.ActiveDocument.Pages.Add();


            // Draw some shapes
            var background = page_a.DrawRectangle(0, 0, 5, 1);
            var progress = page_a.DrawRectangle(0, 0, 1, 1);

            var background_fmt = new VA.Shapes.FormatCells();
            background_fmt.FillForegnd= "rgb(240,240,240)";
            background_fmt.LineColor = "rgb(100,100,100)";


            var progress_fmt = new VA.Shapes.FormatCells();
            progress_fmt.FillForegnd = "rgb(100,150,240)";
            progress_fmt.LineColor = "rgb(100,100,100)";

            // group the two shapes together
            page_a.Application.ActiveWindow.SelectAll();
            var group = page_a.Application.ActiveWindow.Selection.Group();

            // Set the progress shape update itself based on its position
            string bkname = background.NameID;
            var xform = new VA.Shapes.XFormCells();
            xform.PinX = string.Format("GUARD({0}!PinX-{0}!LocPinX+LocPinX)", bkname);
            xform.PinY = string.Format("GUARD({0}!PinY)", bkname);
            xform.Width = string.Format("GUARD({0}!Width*(PAGENUMBER()/PAGECOUNT()))", bkname);
            xform.Height = string.Format("GUARD({0}!Height)", bkname); 

            var update = new VA.ShapeSheet.Update();
            update.SetFormulas(progress.ID16, xform);
            update.SetFormulas(progress.ID16, background_fmt);
            update.SetFormulas(progress.ID16, progress_fmt);
            update.Execute(page_a);

            var markup1 = new VA.Text.Markup.TextElement();
            markup1.AddField(VA.Text.Markup.FieldConstants.PageName);
            markup1.AddText(" (");
            markup1.AddField(VA.Text.Markup.FieldConstants.PageNumber);
            markup1.AddText(" of ");
            markup1.AddField(VA.Text.Markup.FieldConstants.NumberOfPages);
            markup1.AddText(") ");
            markup1.SetText(group);
        }
Ejemplo n.º 14
0
        private static short[] DropManyU(
            IVisio.Page page,
            IList <IVisio.Master> masters,
            IList <VA.Drawing.Rectangle> rects)
        {
            var points   = rects.Select(r => r.Center).ToList();
            var shapeids = VA.Pages.PageHelper.DropManyU(page, masters, points);

            var xfrm = new VA.Shapes.XFormCells();

            var update = new VA.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);
        }
Ejemplo n.º 15
0
        private static short[] DropManyU(
            IVisio.Page page,
            IList<IVisio.Master> masters,
            IList<VA.Drawing.Rectangle> rects)
        {
            var points = rects.Select(r => r.Center).ToList();
            var shapeids = VA.Pages.PageHelper.DropManyU(page, masters, points);

            var xfrm = new VA.Shapes.XFormCells();

            var update = new VA.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;
        }
Ejemplo n.º 16
0
        private static void SnapSize(IVisio.Page page, IList<int> shapeids, VA.Drawing.Size snapsize, VA.Drawing.Size minsize)
        {
            var input_xfrms = VA.Shapes.XFormCells.GetCells(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);
        }
Ejemplo n.º 17
0
 public static VisioAutomation.Drawing.Point GetPinPosResult(this VisioAutomation.Shapes.XFormCells xform)
 {
     return(ToPoint(xform.PinX.Result, xform.PinY.Result));
 }
Ejemplo n.º 18
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;
        }