public static void NURBS1()
        {
            // Draw a simple NURBS
            // Example from this page:http://www.robthebloke.org/opengl_programming.html

            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            var points = new[]
                             {
                                 new VA.Drawing.Point(10, 10),
                                 new VA.Drawing.Point(5, 10),
                                 new VA.Drawing.Point(-5, 5),
                                 new VA.Drawing.Point(-10, 5),
                                 new VA.Drawing.Point(-4, 10),
                                 new VA.Drawing.Point(-4, 5),
                                 new VA.Drawing.Point(-8, 1)
                             };

            var origin = new VA.Drawing.Point(4, 4);
            var scale = new VA.Drawing.Size(1.0/4.0, 1.0/4.0);

            var controlpoints = points.Select(x => (x*scale) + origin).ToList();
            var knots = new double[] {0, 0, 0, 0, 1, 2, 3, 4, 4, 4, 4};
            var degree = 3;
            var weights = controlpoints.Select(i => 1.0).ToList();

            var s0 = page.DrawNURBS(controlpoints, knots, weights, degree);
            s0.Text = "Generic NURBS shape";
        }
        public static void FontCompare()
        {
            var visapp = new IVisio.Application();
            var doc = visapp.Documents.Add("");

            var fontnames = new[] {"Arial", "Calibri"};

            var sampletext = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" +
                             "<>[](),./|\\:;\'\"1234567890!@#$%^&*()`~";
            var samplechars = sampletext.Select(c => new string(new[] {c})).ToList();

            BoxLayoutSamples.FontGlyphComparision(doc, fontnames, samplechars);
            BoxLayoutSamples.FontGlyphComparision2(doc, fontnames, samplechars);
            BoxLayoutSamples.FontGlyphComparision3(doc, fontnames, samplechars);
        }
        public static void BezierSimple()
        {
            // Draw a Simple Bezier curve

            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            var points = new[] {0.0, 0.0, 1.0, 2.0, 3.0, 0.5, 4.0, 0.5};
            var cpoints = VA.Drawing.Point.FromDoubles(points).ToList();
            var s0 = page.DrawBezier(cpoints);
            s0.Text = "Bezier curve";
            foreach (var p in cpoints)
            {
                var p1 = p.Subtract(0.1, 0.1);
                var p2 = p.Add(0.1, 0.1);
                page.DrawRectangle(p1.X, p1.Y, p2.X, p2.Y);
            }
        }
        public static void DrawGridOfMasters()
        {
            // http://blogs.msdn.com/saveenr/archive/2008/08/06/visioautoext-simplifying-dropmany-to-quickly-draw-a-grid.aspx

            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            // Resize the page to a sqaure
            var page_size = new VA.Drawing.Size(4, 4);
            SampleEnvironment.SetPageSize(page,page_size);

            // Load the Stencil
            var application = page.Application;
            var documents = application.Documents;
            var stencil = documents.OpenStencil("basic_u.vss");
            var stencil_masters = stencil.Masters;
            var master = stencil_masters["Rectangle"];

            // Calculate where to drop the masters
            int num_cols = 10;
            int num_rows = 10;

            var centerpoints = new List<VA.Drawing.Point>(num_rows*num_cols);
            foreach (var row in Enumerable.Range(0, num_rows))
            {
                foreach (var col in Enumerable.Range(0, num_cols))
                {
                    var p = new VA.Drawing.Point(row*1.0, col*1.0);
                    centerpoints.Add(p);
                }
            }

            var masters = new[] {master};

            // Draw the masters
            var shapeids = page.DropManyU(masters, centerpoints);

            var bordersize = new VA.Drawing.Size(1,1);
            page.ResizeToFitContents(bordersize);
        }
        public static void NURBS2()
        {
            // Draw a simple NURBS
            // Example from Graham Wideman's book

            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            var points = new[]
                             {
                                 new VA.Drawing.Point(0.2500, 0.2500),
                                 new VA.Drawing.Point(0.2500, 0.7500),
                                 new VA.Drawing.Point(0.4063, 0.8125),
                                 new VA.Drawing.Point(0.5625, 0.3750),
                                 new VA.Drawing.Point(0.5538, 0.8125),
                                 new VA.Drawing.Point(0.7600, 0.7500),
                                 new VA.Drawing.Point(0.7600, 0.2500)
                             };

            var origin = new VA.Drawing.Point(4, 4);
            var scale = new VA.Drawing.Size(4, 4);

            var controlpoints = points.Select(x => (x*scale) + origin).ToList();
            var knots = new double[] {0, 0, 0, 0, 25, 50, 75, 100, 100, 100, 100};
            var degree = 3;
            var Weights = controlpoints.Select(i => 1.0).ToList();

            var s0 = page.DrawNURBS(controlpoints, knots, Weights, degree);
            s0.Text = "Generic NURBS shape";
        }
        public static void BoxLayout_TwoLevelGrouping()
        {
            int num_types = 10;
            int max_properties = 50;

            var types = typeof(VAUDCELLS.UserDefinedCell).Assembly.GetExportedTypes().Take(num_types).ToList();

            var data = new List<string[]>();
            foreach (var type in types)
            {
                var properties = type.GetProperties().Take(max_properties).ToList();
                foreach (var property in properties)
                {
                    var item = new[] {type.Name, property.Name[0].ToString().ToUpper(), property.Name};
                    data.Add(item);
                }
            }

            var layout1 = BoxLayout2Samples.CreateTwoLevelLayout(data);


            layout1.PerformLayout();

            // Create a blank canvas in Visio 
            var app = SampleEnvironment.Application;
            var documents = app.Documents;
            var doc = documents.Add(string.Empty);
            var page = app.ActivePage;


            var domshapescol = new VA.DOM.ShapeList();
            //var rect_master = dom.m
            foreach (var item in layout1.Nodes)
            {
                if (item.Data ==null)
                {
                    continue;
                }
                var info = (TwoLevelInfo) item.Data;

                if (!info.Render)
                {
                    continue;
                }

                var shape = domshapescol.Drop("Rectangle", "Basic_U.VSS",item.Rectangle);

                if (info.Text!=null)
                {
                    shape.Text = new VA.Text.Markup.TextElement(info.Text);                    
                }
                
                shape.Cells = info.ShapeCells.ShallowCopy();
            }
            domshapescol.Render(page);

            var bordersize = new VA.Drawing.Size(0.5, 0.5);
            page.ResizeToFitContents(bordersize);

        }
        public static void FontGlyphComparision3(IVisio.Document doc, string[] fontnames, List<string> samplechars)
        {
            var colors = new[] {"rgb(0,0,255)", "rgb(255,0,0)"};

            double w = 2.0;
            double h = 1;

            int chunksize = 12;
            var chunks = LinqUtil.Split(samplechars, chunksize);


            foreach (var chunk in chunks)
            {
                var domshapescol = new VA.DOM.ShapeList();

                for (int j = 0; j < fontnames.Count(); j++)
                {
                    for (int i = 0; i < chunksize; i++)
                    {
                        double x0 = 0;
                        double y0 = i*h*-1;

                        var r = new VA.Drawing.Rectangle(x0, y0, x0 + w, y0 + h);
                        var n1 = domshapescol.Drop("Rectangle", "basic_u.vss", r);
                        if (i < chunk.Count)
                        {
                            n1.Text = new VA.Text.Markup.TextElement(chunk[i]);
                            n1.Text.CharacterCells.Color = colors[j];

                        }
                        n1.CharFontName = fontnames[j];
    
                        //n1.Cells.CharColor = "=RGB(255,0,0)";// colors[j];
                        n1.Cells.CharTransparency = 0.7;
                        n1.Cells.CharSize = "36pt";
                        n1.Cells.FillPattern = 0;
                        n1.Cells.LineWeight = 0.0;
                        n1.Cells.LinePattern = 0;
                    }
                }

                var page = doc.Pages.Add();

                domshapescol.Render(page);

                var bordersize = new VA.Drawing.Size(0.5, 0.5);
                page.ResizeToFitContents(bordersize);
            }
        }