Exemplo n.º 1
0
        public void BoxLayout_Test_single_node_padding()
        {
            var layout = new BoxL.BoxLayout();

            layout.Root = new BoxL.Container(BoxL.Direction.BottomToTop);
            var root = layout.Root;
            var n1   = root.AddBox(10, 5);

            root.PaddingBottom = 1.0;
            root.PaddingLeft   = 1.0;
            root.PaddingRight  = 1.0;
            root.PaddingTop    = 1.0;

            layout.PerformLayout();
            double delta = 0.00000001;

            AssertUtil.AreEqual(1.0, 1.0, 11, 6, n1.Rectangle, delta);
        }
        public void BoxLayout_Test_single_node()
        {
            var layout = new VABOX.BoxLayout();

            layout.Root = new VABOX.Container(VABOX.Direction.BottomToTop);
            var root = layout.Root;

            root.PaddingBottom = 0.0;
            root.PaddingLeft   = 0.0;
            root.PaddingRight  = 0.0;
            root.PaddingTop    = 0.0;
            var n1 = root.AddBox(10, 5);

            layout.PerformLayout();
            double delta = 0.00000001;

            AssertUtil.AreEqual((0, 0, 10, 5), n1.Rectangle, delta);
            AssertUtil.AreEqual((0, 0, 10, 5), root.Rectangle, delta);
        }
Exemplo n.º 3
0
        public static void Render(VABOXMODEL.BoxLayout layout, IVisio.Document doc)
        {
            layout.PerformLayout();
            var page1 = doc.Pages.Add();
            // and tinker with it
            // render
            var nodes = layout.Nodes.ToList();

            foreach (var node in nodes)
            {
                var shape = page1.DrawRectangle(node.Rectangle);
                node.Data = shape;
            }

            var root_shape = (IVisio.Shape)layout.Root.Data;

            root_shape.CellsU["FillForegnd"].FormulaForceU = "rgb(240,240,240)";
            var margin = new VA.Drawing.Size(0.5, 0.5);

            page1.ResizeToFitContents(margin);
        }
Exemplo n.º 4
0
        public void BoxLayout_Test_empty()
        {
            var layout = new BoxL.BoxLayout();

            layout.Root = new BoxL.Container(BoxL.Direction.BottomToTop);
            Assert.IsNotNull(layout.Root);

            bool thrown = false;

            try
            {
                layout.PerformLayout();
            }
            catch (AutomationException)
            {
                thrown = true;
            }

            if (!thrown)
            {
                Assert.Fail();
            }
        }
        public void BoxLayout_Test_empty()
        {
            var layout = new VABOX.BoxLayout();

            layout.Root = new VABOX.Container(VABOX.Direction.BottomToTop);
            Assert.IsNotNull(layout.Root);

            bool thrown = false;

            try
            {
                layout.PerformLayout();
            }
            catch (System.ArgumentException)
            {
                thrown = true;
            }

            if (!thrown)
            {
                Assert.Fail();
            }
        }
Exemplo n.º 6
0
        public static void FontGlyphComparision(IVisio.Document doc, string[] fontnames, List <string> samplechars)
        {
            var layout = new BoxL.BoxLayout();

            var root = new BoxL.Container(BoxL.Direction.TopToBottom);

            layout.Root       = root;
            root.ChildSpacing = 0.5;

            var nodedata = new NodeData();

            nodedata.Render = false;
            root.Data       = nodedata;

            var fontname_cells = new ShapeCells();

            fontname_cells.FillPattern         = 0;
            fontname_cells.LinePattern         = 0;
            fontname_cells.LineWeight          = 0.0;
            fontname_cells.ParaHorizontalAlign = 0;
            fontname_cells.CharSize            = "36pt";

            var charbox_cells = new ShapeCells();

            charbox_cells.FillPattern         = 0;
            charbox_cells.LinePattern         = 1;
            charbox_cells.LineWeight          = 0.0;
            charbox_cells.LineColor           = "rgb(150,150,150)";
            charbox_cells.ParaHorizontalAlign = 1;
            charbox_cells.CharSize            = "24pt";

            foreach (string fontname in fontnames)
            {
                var fontname_box      = root.AddNodeEx(5, 0.5, fontname);
                var fontname_box_data = (NodeData)fontname_box.Data;
                fontname_box_data.Cells = fontname_cells;

                var font_box = root.AddContainer(BoxL.Direction.TopToBottom);
                font_box.ChildSpacing = 0.25;
                var font_vox_data = (NodeData)font_box.Data;
                if (font_vox_data != null)
                {
                    font_vox_data.Render = false;
                }

                int numcols  = 17;
                int numrows  = 5;
                int numcells = numcols * numrows;


                foreach (int row in Enumerable.Range(0, numrows))
                {
                    var row_box = font_box.AddContainer(BoxL.Direction.LeftToRight);
                    row_box.ChildSpacing = 0.25;
                    var row_box_data = new NodeData();
                    row_box_data.Render = false;

                    row_box.Data = row_box_data;

                    foreach (int col in Enumerable.Range(0, numcols))
                    {
                        int    charindex     = (col + (numcols * row)) % numcells;
                        string curchar       = samplechars[charindex];
                        var    cell_box      = row_box.AddNodeEx(0.50, 0.50, curchar);
                        var    cell_box_data = (NodeData)cell_box.Data;
                        cell_box_data.Font  = fontname;
                        cell_box_data.Cells = charbox_cells;
                    }
                }
            }

            layout.PerformLayout();

            var page = doc.Pages.Add();

            var domshapescol = new ShapeList();

            foreach (var node in layout.Nodes)
            {
                if (node.Data == null)
                {
                    continue;
                }
                var node_data = (NodeData)node.Data;

                if (node_data.Render == false)
                {
                    continue;
                }

                var shape_node = domshapescol.Drop("Rectangle", "basic_u.vss", node.Rectangle);

                var cells = node_data.Cells;
                if (cells == null)
                {
                    cells = new ShapeCells();
                }
                else
                {
                    cells = node_data.Cells.ShallowCopy();
                }

                if (node_data.Font != null)
                {
                    shape_node.CharFontName = node_data.Font;
                }

                shape_node.Cells = cells;
                shape_node.Text  = new VisioAutomation.Models.Text.TextElement(node_data.Text);
            }

            domshapescol.Render(page);

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

            page.ResizeToFitContents(bordersize);
        }
Exemplo n.º 7
0
        private static VABOXMODEL.BoxLayout CreateTwoLevelLayout(List <string[]> data)
        {
            double itemsep = 0.0;
            var    major_group_direction = VABOXMODEL.Direction.LeftToRight;
            var    minor_group_direction = VABOXMODEL.Direction.TopToBottom;

            var name_to_major_group = new Dictionary <string, VABOXMODEL.Container>();
            var name_to_minor_group = new Dictionary <string, VABOXMODEL.Container>();

            var layout1 = new VABOXMODEL.BoxLayout();

            layout1.Root = new VABOXMODEL.Container(major_group_direction);

            var major_cells = new ShapeCells();

            major_cells.FillForegnd         = "rgb(245,245,245)";
            major_cells.CharFont            = 0;
            major_cells.CharSize            = "12pt";
            major_cells.ParaHorizontalAlign = "0";
            major_cells.VerticalAlign       = "0";
            major_cells.LineWeight          = "0";
            major_cells.LinePattern         = "0";

            var minor_cells = new ShapeCells();

            minor_cells.FillForegnd         = "rgb(230,230,230)";
            minor_cells.CharFont            = 0;
            minor_cells.CharSize            = "10pt";
            minor_cells.ParaHorizontalAlign = "0";
            minor_cells.VerticalAlign       = "0";
            minor_cells.LineWeight          = "0";
            minor_cells.LinePattern         = "0";

            var item_cells = new ShapeCells();

            item_cells.CharFont            = 0;
            item_cells.FillPattern         = "0";
            item_cells.CharSize            = "8pt";
            item_cells.ParaHorizontalAlign = "0";
            item_cells.VerticalAlign       = "0";
            item_cells.LineWeight          = "0";
            item_cells.LinePattern         = "0";


            foreach (var row in data)
            {
                var majorname = row[0];
                var minorname = row[1];
                var itemname  = row[2];

                VABOXMODEL.Container majorcnt;
                if (name_to_major_group.ContainsKey(majorname))
                {
                    majorcnt = name_to_major_group[majorname];
                }
                else
                {
                    majorcnt = layout1.Root.AddContainer(minor_group_direction, 1, 1);

                    var major_info = new TwoLevelInfo();
                    major_info.Text       = majorname;
                    major_info.Render     = true;
                    major_info.ShapeCells = major_cells;
                    majorcnt.Data         = major_info;


                    name_to_major_group[majorname] = majorcnt;

                    VABOXMODEL.Box headerbox = majorcnt.AddBox(2, 0.25);
                }

                VABOXMODEL.Container minorcnt;
                var minorkey = majorname + "___" + minorname;
                if (name_to_minor_group.ContainsKey(minorkey))
                {
                    minorcnt = name_to_minor_group[minorkey];
                }
                else
                {
                    minorcnt = majorcnt.AddContainer(minor_group_direction);
                    minorcnt.ChildSpacing = itemsep;
                    var minor_info = new TwoLevelInfo();
                    minor_info.Text               = minorname;
                    minor_info.Render             = true;
                    minor_info.ShapeCells         = minor_cells;
                    minorcnt.Data                 = minor_info;
                    name_to_minor_group[minorkey] = minorcnt;

                    VABOXMODEL.Box headerbox = minorcnt.AddBox(2, 0.25);
                }

                VABOXMODEL.Box itembox = minorcnt.AddBox(2, 0.25);

                var item_info = new TwoLevelInfo();
                item_info.Text   = itemname;
                item_info.Render = true;


                item_info.ShapeCells = item_cells;

                itembox.Data = item_info;
            }
            return(layout1);
        }
Exemplo n.º 8
0
        public static void BoxLayout_SimpleCases()
        {
            // Create a blank canvas in Visio
            var app       = SampleEnvironment.Application;
            var documents = app.Documents;
            var doc       = documents.Add(string.Empty);

            // Create a simple Column
            var layout1 = new VABOXMODEL.BoxLayout();

            layout1.Root = new VABOXMODEL.Container(VABOXMODEL.Direction.BottomToTop);
            layout1.Root.AddBox(1, 2);
            layout1.Root.AddBox(1, 1);
            layout1.Root.AddBox(0.5, 0.5);

            // You can set the min height and width of a container
            var layout2 = new VABOXMODEL.BoxLayout();

            layout2.Root = new VABOXMODEL.Container(VABOXMODEL.Direction.BottomToTop, 3, 5);
            layout2.Root.AddBox(1, 2);
            layout2.Root.AddBox(1, 1);
            layout2.Root.AddBox(0.5, 0.5);

            // For vertical containers, you can layout shapes bottom-to-top or top-to-bottom
            var layout3 = new VABOXMODEL.BoxLayout();

            layout3.Root = new VABOXMODEL.Container(VABOXMODEL.Direction.TopToBottom, 3, 5);
            layout3.Root.AddBox(1, 2);
            layout3.Root.AddBox(1, 1);
            layout3.Root.AddBox(0.5, 0.5);

            // Now switch to horizontal containers
            var layout4 = new VABOXMODEL.BoxLayout();

            layout4.Root = new VABOXMODEL.Container(VABOXMODEL.Direction.RightToLeft, 3, 5);
            layout4.Root.AddBox(1, 2);
            layout4.Root.AddBox(1, 1);
            layout4.Root.AddBox(0.5, 0.5);


            // For Columns, you can tell the children how to horizontally align
            var layout5 = new VABOXMODEL.BoxLayout();

            layout5.Root = new VABOXMODEL.Container(VABOXMODEL.Direction.BottomToTop, 3, 0);
            var b51 = layout5.Root.AddBox(1, 2);
            var b52 = layout5.Root.AddBox(1, 1);
            var b53 = layout5.Root.AddBox(0.5, 0.5);

            b51.HAlignToParent = VABOXMODEL.AlignmentHorizontal.Left;
            b52.HAlignToParent = VABOXMODEL.AlignmentHorizontal.Center;
            b53.HAlignToParent = VABOXMODEL.AlignmentHorizontal.Right;

            // For Rows , you can tell the children how to vertially align
            var layout6 = new VABOXMODEL.BoxLayout();

            layout6.Root = new VABOXMODEL.Container(VABOXMODEL.Direction.LeftToRight, 0, 5);
            var b61 = layout6.Root.AddBox(1, 2);
            var b62 = layout6.Root.AddBox(1, 1);
            var b63 = layout6.Root.AddBox(0.5, 0.5);

            b61.VAlignToParent = VABOXMODEL.AlignmentVertical.Bottom;
            b62.VAlignToParent = VABOXMODEL.AlignmentVertical.Center;
            b63.VAlignToParent = VABOXMODEL.AlignmentVertical.Top;

            Util.Render(layout1, doc);
            Util.Render(layout2, doc);
            Util.Render(layout3, doc);
            Util.Render(layout4, doc);
            Util.Render(layout5, doc);
            Util.Render(layout6, doc);
        }