Example #1
0
 public PieSlice(VA.Drawing.Point p0, double r, double start, double end)
 {
     this.Center = p0;
     this.Radius = r;
     this.Start = start;
     this.End = end;
 }
 public VA.Drawing.Size Snap(VA.Drawing.Size size)
 {
     double x;
     double y;
     this.SnapXY(size.Width,size.Height,out x, out y);
     return new VA.Drawing.Size(x, y);
 }
 public VA.Drawing.Point Snap(VA.Drawing.Point point)
 {
     double x;
     double y;
     this.SnapXY(point.X,point.Y,out x, out y);
     return new VA.Drawing.Point(x, y);
 }
        public static VA.Text.Markup.TextElement AddElementEx(this VA.Text.Markup.TextElement p, string text,
                                                              int? font, double? size, int? color,
                                                              VA.Drawing.AlignmentHorizontal? halign,
                                                              VA.Text.CharStyle? cs)
        {
            var el = p.AddElement(text);
            if (font != null)
            {
                el.CharacterCells.Font = font.Value;
            }
            if (size.HasValue)
            {
                el.CharacterCells.Size = string.Format("{0}pt",size.Value);
            }
            if (color.HasValue)
            {
                var c = new VA.Drawing.ColorRGB(color.Value);
                el.CharacterCells.Color = c.ToFormula();
            }
            if (halign.HasValue)
            {
                el.ParagraphCells.HorizontalAlign = (int) halign.Value;
            }

            if (cs.HasValue)
            {
                el.CharacterCells.Style = (int) cs;
            }

            return el;
        }
 public static VA.Drawing.Point GetPointAtRadius(VA.Drawing.Point origin, double angle, double radius)
 {
     var new_point = new VA.Drawing.Point(radius*System.Math.Cos(angle),
                                  radius*System.Math.Sin(angle));
     new_point = origin + new_point;
     return new_point;
 }
        public static BezierCurve FromEllipse(VA.Drawing.Point center, VA.Drawing.Size radius)
        {
            var pt1 = new VA.Drawing.Point(0, radius.Height); // top
            var pt2 = new VA.Drawing.Point(radius.Width, 0); // right
            var pt3 = new VA.Drawing.Point(0, -radius.Height); // bottom
            var pt4 = new VA.Drawing.Point(-radius.Width, 0); // left

            double dx = radius.Width * 4.0 * (System.Math.Sqrt(2) - 1) / 3;
            double dy = radius.Height * 4.0 * (System.Math.Sqrt(2) - 1) / 3;

            var curve_ControlPoints = new []
                                      {
                                          pt1,
                                          pt1.Add(dx, 0),
                                          pt2.Add(0, dy),
                                          pt2,
                                          pt2.Add(0, -dy),
                                          pt3.Add(dx, 0),
                                          pt3,
                                          pt3.Add(-dx, 0),
                                          pt4.Add(0, -dy),
                                          pt4,
                                          pt4.Add(0, dy),
                                          pt1.Add(-dx, 0),
                                          pt1
                                      }
                .Select(p => p + center).ToArray();
            var curve_Degree = 3;

            var curve = new BezierCurve(curve_ControlPoints, curve_Degree);
            return curve;
        }
 public static void SetViewRect(
     this IVisio.Window window,
     VA.Drawing.Rectangle rect)
 {
     // MSDN: http://msdn.microsoft.com/en-us/library/office/ms367542(v=office.14).aspx
     window.SetViewRect(rect.Left, rect.Top, rect.Width, rect.Height);
 }
 public static void DrawNode(
     BoxL.Node node,
     VA.Drawing.Rectangle rect, IVisio.Page page)
 {           
     var shape = page.DrawRectangle(rect);
     node.Data = shape;
 }
        private static void TestResize(IVisio.Document doc, 
            VA.Drawing.Size bottomleft_margin, 
            VA.Drawing.Size upperright_margin, 
            VA.Drawing.Size shape_size, 
            VA.Drawing.Size padding_size,  
            double expected_pinx, 
            double expected_piny)
        {
            var page = doc.Pages.Add();

            var pagecells = new VA.Pages.PageCells();
            pagecells.PageTopMargin = upperright_margin.Height;
            pagecells.PageBottomMargin = bottomleft_margin.Height;
            pagecells.PageLeftMargin = bottomleft_margin.Width;
            pagecells.PageRightMargin = upperright_margin.Width;

            var pageupdate = new VA.ShapeSheet.Update();
            pageupdate.SetFormulas(pagecells);
            pageupdate.Execute(page.PageSheet);

            var shape = page.DrawRectangle(5, 5, 5 + shape_size.Width, 5+shape_size.Height);
            page.ResizeToFitContents(padding_size);
            var xform = VA.Shapes.XFormCells.GetCells(shape);
            AssertVA.AreEqual(expected_pinx, expected_piny, xform.Pin(), 0.1);
            page.Delete(0);
        }
 public void Apply(VA.ShapeSheet.Update update, short shapeid_label, short shapeid_box)
 {
     update.SetFormulas(shapeid_label, this.CharacterCells, 0);
     update.SetFormulas(shapeid_label, this.ParagraphCells, 0);
     update.SetFormulas(shapeid_box, this.FormatCells);
     update.SetFormulas(shapeid_label, this.TextCells);
 }
Example #11
0
        public Connector AddConnection(string id, Shape from, Shape to, string label,
            VA.Shapes.Connections.ConnectorType type, int beginArrow, int endArrow, string hyperlink)
        {
            var new_connector = new Connector(from, to);
            new_connector.ID = id;
            new_connector.Label = label;
            new_connector.ConnectorType = type;
            new_connector.Cells = new VA.DOM.ShapeCells();
            new_connector.Cells.BeginArrow = beginArrow;
            new_connector.Cells.BeginArrowSize = beginArrow;
            new_connector.Cells.EndArrow = endArrow;
            new_connector.Cells.EndArrowSize = endArrow;

            if (!string.IsNullOrEmpty(hyperlink))
            {

                //new_connector.VisioShape = IVisio.Shape; // IVisio.Shape();
                var h = new_connector.VisioShape.Hyperlinks.Add();

                h.Name = hyperlink; // Name of Hyperlink
                h.Address = hyperlink; // Address of Hyperlink
            }

            this.Connectors.Add(id, new_connector);
            return new_connector;
        }
        public static IList<DGMODEL.Drawing> LoadFromXML(VA.Scripting.Client client, SXL.XDocument xmldoc)
        {
            var pagedatas = LoadPageDataFromXML(client, xmldoc);

            // STOP IF ANY ERRORS
            int num_errors = pagedatas.Select(pagedata => pagedata.Errors.Count).Sum();
            if (num_errors > 1)
            {
                foreach (var pagedata in pagedatas)
                {
                    foreach (var error in pagedata.Errors)
                    {
                        client.WriteVerbose( error.Text);
                    }
                    client.WriteVerbose( "Errors encountered in shape data. Stopping.");
                }
            }

            // DRAW EACH PAGE
            foreach (var pagedata in pagedatas)
            {
                client.WriteVerbose( "Creating shape AutoLayout nodes");
                foreach (var shape_info in pagedata.ShapeInfos)
                {
                    var dg_shape = pagedata.DirectedGraph.AddShape(shape_info.ID, shape_info.Label, shape_info.Stencil, shape_info.Master);
                    dg_shape.URL = shape_info.URL;
                    dg_shape.CustomProperties = new Dictionary<string, VACUSTPROP.CustomPropertyCells>();
                    foreach (var kv in shape_info.custprops)
                    {
                        dg_shape.CustomProperties[kv.Key] = kv.Value;
                    }
                }

                client.WriteVerbose( "Creating connector AutoLayout nodes");
                foreach (var con_info in pagedata.ConnectorInfos)
                {
                    var def_connector_type = VACXN.ConnectorType.Curved;
                    var connectory_type = def_connector_type;

                    var from_shape = pagedata.DirectedGraph.Shapes.Find(con_info.From);
                    var to_shape = pagedata.DirectedGraph.Shapes.Find(con_info.To);

                    var def_con_color = new VA.Drawing.ColorRGB(0x000000);
                    var def_con_weight = 1.0/72.0;
                    var def_end_arrow = 2;
                    var dg_connector = pagedata.DirectedGraph.Connect(con_info.ID, from_shape, to_shape, con_info.Label, connectory_type);

                    dg_connector.Cells = new VA.DOM.ShapeCells();
                    dg_connector.Cells.LineColor = con_info.Element.AttributeAsColor("color", def_con_color).ToFormula();
                    dg_connector.Cells.LineWeight = con_info.Element.AttributeAsInches("weight", def_con_weight);
                    dg_connector.Cells.EndArrow = def_end_arrow;
                }
                client.WriteVerbose( "Rendering AutoLayout...");
            }
            client.WriteVerbose( "Finished rendering AutoLayout");

            var directedgraphs = pagedatas.Select(pagedata => pagedata.DirectedGraph).ToList();
            return directedgraphs;
        }
Example #13
0
 public PieChart(VA.Drawing.Rectangle rect)
 {
     var center = rect.Center;
     var radius = System.Math.Min(rect.Width,rect.Height)/2.0;
     this.DataPoints = new DataPointList();
     this.Center = center;
     this.Radius = radius;
 }
 public BezierSegment(VA.Drawing.Point start, VA.Drawing.Point handle1, VA.Drawing.Point handle2, VA.Drawing.Point end)
     : this()
 {
     this.Start = start;
     this.Handle1 = handle1;
     this.Handle2 = handle2;
     this.End = end;
 }
Example #15
0
 public void ApplyFormus(VA.ShapeSheet.Update update)
 {
     short titleshape_id = this.VisioShape.ID16;
     update.SetFormulas(titleshape_id, this.Textcells);
     update.SetFormulas(titleshape_id, this.ParagraphCells, 0);
     update.SetFormulas(titleshape_id, this.CharacterCells, 0);
     update.SetFormulas(titleshape_id, this.FormatCells);
 }
Example #16
0
 public Arc(VA.Drawing.Point p0, double ri, double ro, double start, double end)
 {
     this.Center = p0;
     this.InnerRadius = ri;
     this.OuterRadius = ro;
     this.StartAngle = start;
     this.EndAngle = end;
 }
 public static IVisio.Shape Drop(
     this IVisio.Page page,
     IVisio.Master master,
     VA.Drawing.Point point)
 {
     var surface = new VA.Drawing.DrawingSurface(page);
     return surface.Drop(master, point);
 }
 public static VA.Drawing.Point XYToPage(this IVisio.Shape shape, VA.Drawing.Point xy)
 {
     // MSDN: http://msdn.microsoft.com/en-us/library/office/ff766239.aspx
     double xprime;
     double yprime;
     shape.XYToPage(xy.X, xy.Y, out xprime, out yprime);
     return new VA.Drawing.Point(xprime, yprime);
 }
 public FormatPaintCell(VA.ShapeSheet.SRC src, string name, FormatCategory category)
 {
     this.Category = category;
     this.Name = name;
     this.SRC = src;
     this.Formula = null;
     this.Result = null;
 }
 internal ConnectionPointValues(int shapeid, VA.Shapes.Connections.ConnectionPointCells point)
 {
     this.ShapeID = shapeid;
     this.Type = point.Type.Formula.Value;
     this.X = point.X.Formula.Value;
     this.Y = point.Y.Formula.Value;
     this.DirX = point.DirX.Formula.Value;
     this.DirY = point.DirY.Formula.Value;
 }
        public void BarChart(VA.Models.Charting.BarChart chart)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var application = this.Client.VisioApplication;
            var page = application.ActivePage;
            chart.Render(page);
        }
Example #22
0
 public TextBlock(VA.Drawing.Size size, string text)
 {
     this.Text = text;
     this.Size = size;
     this.Textcells = new VA.Text.TextCells();
     this.ParagraphCells = new VA.Text.ParagraphCells();
     this.FormatCells = new VA.Shapes.FormatCells();
     this.CharacterCells = new VA.Text.CharacterCells();
 }
Example #23
0
        public PieSlice(VA.Drawing.Point center, double radius, double start, double end)
            : this(center,start,end)
        {
            if (radius < 0.0)
            {
                throw new System.ArgumentOutOfRangeException("radius","must be non-negative");
            }

            this.Radius = radius;
        }
        public static GeometryRow CreateArcTo(VA.ShapeSheet.FormulaLiteral x, VA.ShapeSheet.FormulaLiteral y,
                                              VA.ShapeSheet.FormulaLiteral a)
        {
            // http://msdn.microsoft.com/en-us/library/aa195698(v=office.11).aspx

            var row = new GeometryRow(IVisio.VisRowTags.visTagArcTo);
            row.X = x;
            row.Y = y;
            row.A = a;
            return row;
        }
        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);
        }
Example #26
0
        public PerfScope(IVisio.Application vis, VA.Application.PerfSettings new_settings)
        {
            this.app = vis;

            // save the old settings
            this.old_settings = new VA.Application.PerfSettings();
            this.old_settings.Load(this.app);

            // Set the new settings
            new_settings.Apply(app);
        }
Example #27
0
        public PieSlice(VA.Drawing.Point center, double start, double end)
        {
            this.Center = center;

            if (end < start)
            {
                throw new System.ArgumentException("end","end angle must be greater than or equal to start angle");
            }

            this.SectorStartAngle = start;
            this.SectorEndAngle = end;
        }
Example #28
0
        public static List<VA.DOM.BaseShape> DrawOvals(VA.DOM.ShapeList dom, IList<VA.Drawing.Rectangle> rects)
        {
            var dom_shapes = new List<VA.DOM.BaseShape>();
            foreach (var rect in rects)
            {
                var dom_shape = dom.DrawOval(rect);
                dom_shape.Cells.Width = rect.Width;
                dom_shape.Cells.Height = rect.Height;
                dom_shapes.Add(dom_shape);
            }

            return dom_shapes;
        }
Example #29
0
        public static List<VA.DOM.Shape> DrawRects(VA.DOM.ShapeList dom, IList<VA.Drawing.Rectangle> rects, IVisio.Master rectmaster)
        {
            var dom_shapes = new List<VA.DOM.Shape>();
            foreach (var rect in rects)
            {
                var dom_shape = dom.Drop(rectmaster, rect.Center);
                dom_shape.Cells.Width = rect.Width;
                dom_shape.Cells.Height = rect.Height;
                dom_shapes.Add(dom_shape);
            }

            return dom_shapes;
        }
        private static IVisio.Shape draw_leaf(IVisio.Page page, VA.Drawing.Point p0)
        {
            var p1 = p0.Add(1, 1);
            var p2 = p1.Add(1, 0);
            var p3 = p2.Add(1, -1);
            var p4 = p3.Add(-1, -1);
            var p5 = p4.Add(-1, 0);
            var p6 = p5.Add(-1, 1);
            var bezier_points = new[] {p0, p1, p2, p3, p4, p5, p6};

            var s = page.DrawBezier(bezier_points);
            return s;
        }