示例#1
0
        public void DOM_DrawAndDrop()
        {
            var doc       = this.GetNewDoc();
            var page_node = new VA.DOM.Page();

            var rect0          = new VisioAutomation.Drawing.Rectangle(3, 4, 7, 8);
            var rect1          = new VisioAutomation.Drawing.Rectangle(8, 1, 9, 5);
            var dropped_shape0 = page_node.Shapes.Drop(this.rectangle, this.basic_u_vss, rect0);
            var drawn_shape0   = page_node.Shapes.DrawRectangle(rect0);

            var dropped_shape1 = page_node.Shapes.Drop(this.rectangle, this.basic_u_vss, rect1);
            var drawn_shape1   = page_node.Shapes.DrawRectangle(rect1);

            var page = page_node.Render(doc);

            var xfrms = VA.Shapes.XFormCells.GetCells(page,
                                                      new int[] { dropped_shape0.VisioShapeID,
                                                                  drawn_shape0.VisioShapeID,
                                                                  dropped_shape1.VisioShapeID,
                                                                  drawn_shape1.VisioShapeID });

            Assert.AreEqual(xfrms[1].PinX, xfrms[0].PinX);
            Assert.AreEqual(xfrms[1].PinY, xfrms[0].PinY);

            Assert.AreEqual(xfrms[1].Width, xfrms[0].Width);
            Assert.AreEqual(xfrms[1].Height, xfrms[0].Height);

            Assert.AreEqual(xfrms[3].PinX, xfrms[2].PinX);
            Assert.AreEqual(xfrms[3].PinY, xfrms[2].PinY);
            Assert.AreEqual(xfrms[3].Width, xfrms[2].Width);
            Assert.AreEqual(xfrms[3].Height, xfrms[2].Height);

            doc.Close(true);
        }
示例#2
0
        public void Render(IVisio.Page page)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException("page");
            }

            var    page_node = new VA.DOM.Page();
            double x         = 0;
            double y         = 1;

            foreach (var shape in this.Shapes)
            {
                var shape_nodes = page_node.Shapes.Drop(shape.MasterName, shape.StencilName, x, y);
                shape.DOMNode      = shape_nodes;
                shape.DOMNode.Text = new VA.Text.Markup.TextElement(shape.Label);
                x += 1.0;
            }

            foreach (var connector in this.Connectors)
            {
                var connector_node = page_node.Shapes.Connect("Dynamic Connector", "basic_u.vss", connector.From.DOMNode, connector.To.DOMNode);
                connector.DOMNode      = connector_node;
                connector.DOMNode.Text = new VA.Text.Markup.TextElement(connector.Label);
            }
            page_node.ResizeToFit       = true;
            page_node.ResizeToFitMargin = new VA.Drawing.Size(0.5, 0.5);
            page_node.Render(page);
        }
示例#3
0
        public void DOM_VerifyThatUnknownStencilsAreDetected()
        {
            string non_existent_stencil = "foobar.vss";

            var doc           = this.GetNewDoc();
            var page_node     = new VA.DOM.Page();
            var master_node_0 = page_node.Shapes.Drop(this.rectangle, non_existent_stencil, 3, 3);

            IVisio.Page page   = null;
            bool        caught = false;

            try
            {
                page = page_node.Render(doc);
            }
            catch (VA.AutomationException)
            {
                caught = true;
            }

            if (caught == false)
            {
                Assert.Fail("Expected an AutomationException");
            }

            if (page != null)
            {
                page.Delete(0);
            }
            doc.Close(true);
        }
示例#4
0
        public void DOM_DrawOrgChart()
        {
            var app     = this.GetVisioApplication();
            var vis_ver = VA.Application.ApplicationHelper.GetVersion(app);

            // How to draw using a Template instead of a doc and a stencil
            string orgchart_vst         = "orgchart.vst";
            string position_master_name = vis_ver.Major >= 15 ? "Position Belt" : "Position";

            var doc_node  = new VA.DOM.Document(orgchart_vst, IVisio.VisMeasurementSystem.visMSUS);
            var page_node = new VA.DOM.Page();

            doc_node.Pages.Add(page_node);

            // Have to be smart about selecting the right master with Visio 2013

            var s1 = new VA.DOM.Shape(position_master_name, null, new VA.Drawing.Point(3, 8));

            page_node.Shapes.Add(s1);

            var s2 = new VA.DOM.Shape(position_master_name, null, new VA.Drawing.Point(0, 4));

            page_node.Shapes.Add(s2);

            var s3 = new VA.DOM.Shape(position_master_name, null, new VA.Drawing.Point(6, 4));

            page_node.Shapes.Add(s3);

            page_node.Shapes.Connect(this.dynamicconnector, this.connec_u_vss, s1, s2);
            page_node.Shapes.Connect(this.dynamicconnector, this.connec_u_vss, s1, s3);

            var doc = doc_node.Render(app);

            //doc.Close(true);
        }
示例#5
0
        public void Render(IVisio.Page page)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException("page");
            }

            var page_node = new VA.DOM.Page();
            double x = 0;
            double y = 1;
            foreach (var shape in this.Shapes)
            {
                var shape_nodes = page_node.Shapes.Drop(shape.MasterName, shape.StencilName, x, y);
                shape.DOMNode = shape_nodes;
                shape.DOMNode.Text = new VA.Text.Markup.TextElement( shape.Label ) ;
                x += 1.0;
            }

            foreach (var connector in this.Connectors)
            {

                var connector_node = page_node.Shapes.Connect("Dynamic Connector", "basic_u.vss", connector.From.DOMNode, connector.To.DOMNode);
                connector.DOMNode = connector_node;
                connector.DOMNode.Text = new VA.Text.Markup.TextElement( connector.Label );
            }
            page_node.ResizeToFit = true;
            page_node.ResizeToFitMargin = new VA.Drawing.Size(0.5, 0.5);
            page_node.Render(page);
        }
示例#6
0
        public VA.DOM.Page CreateDOMPage(DGMODEL.Drawing layout_diagram, IVisio.Application vis)
        {
            var page_node = new VA.DOM.Page();

            ResolveMasters(layout_diagram, vis);

            var msagl_graph = this.CreateMSAGLGraph(layout_diagram);

            CreateDOMShapes(page_node.Shapes, msagl_graph, vis);

            if (this.LayoutOptions.UseDynamicConnectors)
            {
                CreateDynamicConnectorEdges(page_node.Shapes, msagl_graph);
            }
            else
            {
                CreateBezierEdges(page_node.Shapes, msagl_graph);
            }

            // Additional Page properties
            page_node.PageCells.PlaceStyle   = 1;
            page_node.PageCells.RouteStyle   = 5;
            page_node.PageCells.AvenueSizeX  = 2.0;
            page_node.PageCells.AvenueSizeY  = 2.0;
            page_node.PageCells.LineRouteExt = 2;
            page_node.Size = this.layout_bb.Size;

            return(page_node);
        }
示例#7
0
        public void DOM_VerifyThatUnknownMastersAreDetected()
        {
            var doc           = this.GetNewDoc();
            var page_node     = new VA.DOM.Page();
            var master_node_0 = page_node.Shapes.Drop("XXX", this.basic_u_vss, 3, 3);

            IVisio.Page page   = null;
            bool        caught = false;

            try
            {
                page = page_node.Render(doc);
            }
            catch (VA.AutomationException)
            {
                caught = true;
            }

            if (caught == false)
            {
                Assert.Fail("Expected an AutomationException");
            }

            if (page != null)
            {
                page.Delete(0);
            }
            doc.Close(true);
        }
 public void DOM_RenderPageToDocument()
 {
     // Rendering a dom page to a document should create a new page
     var app = this.GetVisioApplication();
     var page_node = new VA.DOM.Page();
     var visdoc = this.GetNewDoc();
     Assert.AreEqual(1, visdoc.Pages.Count);
     var page = page_node.Render(app.ActiveDocument);
     Assert.AreEqual(2, visdoc.Pages.Count);
     app.ActiveDocument.Close(true);
 }
        public void DOM_EmptyRendering()
        {
            // Rendering a DOM should not change the page count
            // Empty DOMs do not add any shapes
            var app = this.GetVisioApplication();

            var page_node = new VA.DOM.Page();
            var doc = this.GetNewDoc();
            page_node.Render(app.ActiveDocument);
            Assert.AreEqual(0, app.ActivePage.Shapes.Count);
            app.ActiveDocument.Close(true);
        }
示例#10
0
        public void DOM_RenderPageToDocument()
        {
            // Rendering a dom page to a document should create a new page
            var app       = this.GetVisioApplication();
            var page_node = new VA.DOM.Page();
            var visdoc    = this.GetNewDoc();

            Assert.AreEqual(1, visdoc.Pages.Count);
            var page = page_node.Render(app.ActiveDocument);

            Assert.AreEqual(2, visdoc.Pages.Count);
            app.ActiveDocument.Close(true);
        }
示例#11
0
        public void DOM_EmptyRendering()
        {
            // Rendering a DOM should not change the page count
            // Empty DOMs do not add any shapes
            var app = this.GetVisioApplication();

            var page_node = new VA.DOM.Page();
            var doc       = this.GetNewDoc();

            page_node.Render(app.ActiveDocument);
            Assert.AreEqual(0, app.ActivePage.Shapes.Count);
            app.ActiveDocument.Close(true);
        }
 public void DOM_RenderDocumentToApplication()
 {
     // Rendering a dom document to an appliction instance should create a new document
     var app = this.GetVisioApplication();
     var doc_node = new VA.DOM.Document();
     var page_node = new VA.DOM.Page();
     doc_node.Pages.Add(page_node);
     int old_count = app.Documents.Count;
     var newdoc = doc_node.Render(app);
     Assert.AreEqual(old_count + 1, app.Documents.Count);
     Assert.AreEqual(1, newdoc.Pages.Count);
     app.ActiveDocument.Close(true);
 }
示例#13
0
        public void DOM_DrawLine()
        {
            var doc         = this.GetNewDoc();
            var page_node   = new VA.DOM.Page();
            var line_node_0 = page_node.Shapes.DrawLine(1, 1, 3, 3);
            var page        = page_node.Render(doc);

            Assert.AreEqual(1, page.Shapes.Count);
            Assert.AreNotEqual(0, line_node_0.VisioShapeID);
            Assert.IsNotNull(line_node_0.VisioShape);
            Assert.AreEqual(2.0, line_node_0.VisioShape.CellsU["PinX"].Result[IVisio.VisUnitCodes.visNumber]);
            page.Delete(0);
            doc.Close(true);
        }
示例#14
0
        public void DOM_DrawBezier()
        {
            var doc        = this.GetNewDoc();
            var page_node  = new VA.DOM.Page();
            var bez_node_0 = page_node.Shapes.DrawBezier(new double[] { 1, 2, 3, 3, 6, 3, 3, 4 });

            var page = page_node.Render(doc);

            Assert.AreEqual(1, page.Shapes.Count);
            Assert.AreNotEqual(0, bez_node_0.VisioShapeID);
            Assert.IsNotNull(bez_node_0.VisioShape);

            page.Delete(0);
            doc.Close(true);
        }
示例#15
0
        public void DOM_DrawEmpty()
        {
            // Verify that an empty DOM page can be created and rendered
            var doc       = this.GetNewDoc();
            var page_node = new VA.DOM.Page();

            page_node.Size = new VA.Drawing.Size(5, 5);
            var page = page_node.Render(doc);

            Assert.AreEqual(0, page.Shapes.Count);
            Assert.AreEqual(new VA.Drawing.Size(5, 5), VisioAutomationTest.GetPageSize(page));

            page.Delete(0);
            doc.Close(true);
        }
示例#16
0
        public void DOM_RenderDocumentToApplication()
        {
            // Rendering a dom document to an appliction instance should create a new document
            var app       = this.GetVisioApplication();
            var doc_node  = new VA.DOM.Document();
            var page_node = new VA.DOM.Page();

            doc_node.Pages.Add(page_node);
            int old_count = app.Documents.Count;
            var newdoc    = doc_node.Render(app);

            Assert.AreEqual(old_count + 1, app.Documents.Count);
            Assert.AreEqual(1, newdoc.Pages.Count);
            app.ActiveDocument.Close(true);
        }
示例#17
0
        public void DOM_ConnectShapes2()
        {
            // Deferred means that the stencils (and thus masters) are loaded when rendering
            // and are no loaded by the caller before Render() is called

            var doc           = this.GetNewDoc();
            var page_node     = new VA.DOM.Page();
            var master_node_0 = page_node.Shapes.Drop(this.rectangle, this.basic_u_vss, 3, 3);
            var master_node_1 = page_node.Shapes.Drop(this.rectangle, this.basic_u_vss, 6, 5);
            var dc            = page_node.Shapes.Connect(this.dynamicconnector, this.connec_u_vss, master_node_0, master_node_1);
            var page          = page_node.Render(doc);

            Assert.AreEqual(3, page.Shapes.Count);

            page.Delete(0);
            doc.Close(true);
        }
示例#18
0
        public void DOM_ConnectShapes2()
        {
            // Deferred means that the stencils (and thus masters) are loaded when rendering
            // and are no loaded by the caller before Render() is called

            var doc = this.GetNewDoc();
            var page_node = new VA.DOM.Page();
            var master_node_0 = page_node.Shapes.Drop("Rectangle", "basic_u.vss", 3, 3);
            var master_node_1 = page_node.Shapes.Drop("Rectangle", "basic_u.vss", 6, 5);
            var dc = page_node.Shapes.Connect("Dynamic Connector", "connec_u.vss", master_node_0, master_node_1);
            var page = page_node.Render(doc);

            Assert.AreEqual(3, page.Shapes.Count);

            page.Delete(0);
            doc.Close(true);
        }
示例#19
0
        public void Render(IVisio.Page page)
        {
            if (page == null)
            {
                throw new ArgumentNullException("page");
            }

            var nodes_to_draw = this.Nodes.Where(n => n.Draw).ToList();

            var page_node = new VA.DOM.Page();

            var shape_nodes = new List <VA.DOM.Shape>(nodes_to_draw.Count);

            foreach (var node in nodes_to_draw)
            {
                var shape_node = page_node.Shapes.Drop(node.Master, node.Rectangle.Center);

                if (node.Cells != null)
                {
                    shape_node.Cells = node.Cells.ShallowCopy();
                }

                shape_node.Cells.Width  = node.Rectangle.Width;
                shape_node.Cells.Height = node.Rectangle.Height;

                if (!string.IsNullOrEmpty(node.Text))
                {
                    shape_node.Text = new VA.Text.Markup.TextElement(node.Text);
                }

                shape_nodes.Add(shape_node);
            }

            page_node.Shapes.Render(page);

            for (int i = 0; i < nodes_to_draw.Count; i++)
            {
                var node       = nodes_to_draw[i];
                var shape_node = shape_nodes[i];

                node.Shape   = shape_node.VisioShape;
                node.ShapeID = shape_node.VisioShapeID;
            }
        }
示例#20
0
        public void DOM_FormatShape()
        {
            var doc       = this.GetNewDoc();
            var page_node = new VA.DOM.Page();
            var stencil   = doc.Application.Documents.OpenStencil(this.basic_u_vss);
            var master1   = stencil.Masters[this.rectangle];

            var master_node_0 = page_node.Shapes.Drop(master1, 3, 3);
            var bez_node_0    = page_node.Shapes.DrawBezier(new double[] { 1, 2, 3, 3, 6, 3, 3, 4 });
            var line_node_0   = page_node.Shapes.DrawLine(1, 1, 3, 3);

            master_node_0.Cells.LineWeight = 0.1;
            bez_node_0.Cells.LineWeight    = 0.3;
            line_node_0.Cells.LineWeight   = 0.5;

            var page = page_node.Render(doc);

            Assert.AreEqual(3, page.Shapes.Count);
            page.Delete(0);
            doc.Close(true);
        }
示例#21
0
        public void DOM_DropMaster()
        {
            var doc       = this.GetNewDoc();
            var page_node = new VA.DOM.Page();
            var stencil   = doc.Application.Documents.OpenStencil(this.basic_u_vss);
            var master1   = stencil.Masters[this.rectangle];

            var master_node_0 = page_node.Shapes.Drop(master1, 3, 3);
            var master_node_1 = page_node.Shapes.Drop(this.rectangle, this.basic_u_vss, 5, 5);

            var page = page_node.Render(doc);

            Assert.AreEqual(2, page.Shapes.Count);

            // Verify that the shapes created both have IDs and shape objects associated with them
            Assert.AreNotEqual(0, master_node_0.VisioShapeID);
            Assert.AreNotEqual(0, master_node_1.VisioShapeID);
            Assert.IsNotNull(master_node_0.VisioShape);
            Assert.IsNotNull(master_node_1.VisioShape);
            page.Delete(0);
            doc.Close(true);
        }
        public void DOM_DrawSimpleShape()
        {
            // Create the doc
            var page_node = new VA.DOM.Page();
            var vrect1 = new VisioAutomation.DOM.Rectangle(1, 1, 9, 9);
            vrect1.Text = new VA.Text.Markup.TextElement("HELLO WORLD");
            vrect1.Cells.FillForegnd = "rgb(255,0,0)";
            page_node.Shapes.Add(vrect1);

            // Render it
            var app = this.GetVisioApplication();
            var doc = this.GetNewDoc();
            this.pagesize = new VA.Drawing.Size(10, 10);
            VisioAutomationTest.SetPageSize(app.ActivePage, this.pagesize);
            var page = page_node.Render(app.ActiveDocument);

            // Verify
            Assert.IsNotNull(vrect1.VisioShape);
            Assert.AreEqual("HELLO WORLD", vrect1.VisioShape.Text);

            app.ActiveDocument.Close(true);
        }
示例#23
0
        public void DOM_DrawOrgChart()
        {
            // How to draw using a Template instead of a doc and a stencil
            const string orgchart_vst = "orgch_u.vst" +
                                        "";

            var app       = this.GetVisioApplication();
            var doc_node  = new VA.DOM.Document(orgchart_vst, IVisio.VisMeasurementSystem.visMSUS);
            var page_node = new VA.DOM.Page();

            doc_node.Pages.Add(page_node);

            // Have to be smart about selecting the right master with Visio 2013
            int    vis_ver = int.Parse(app.Version.Split('.')[0]);
            string position_master_name = vis_ver >= 15 ? "Position Belt" : "Position";

            var s1 = new VisioAutomation.DOM.Shape(position_master_name, null, new VA.Drawing.Point(3, 4));

            page_node.Shapes.Add(s1);
            var doc = doc_node.Render(app);

            doc.Close(true);
        }
示例#24
0
        public void DOM_DrawSimpleShape()
        {
            // Create the doc
            var page_node = new VA.DOM.Page();
            var vrect1    = new VA.DOM.Rectangle(1, 1, 9, 9);

            vrect1.Text = new VA.Text.Markup.TextElement("HELLO WORLD");
            vrect1.Cells.FillForegnd = "rgb(255,0,0)";
            page_node.Shapes.Add(vrect1);

            // Render it
            var app = this.GetVisioApplication();
            var doc = this.GetNewDoc();

            VisioAutomationTest.SetPageSize(app.ActivePage, new VA.Drawing.Size(10, 10));
            var page = page_node.Render(app.ActiveDocument);

            // Verify
            Assert.IsNotNull(vrect1.VisioShape);
            Assert.AreEqual("HELLO WORLD", vrect1.VisioShape.Text);

            app.ActiveDocument.Close(true);
        }
示例#25
0
        public void DOM_ConnectShapes()
        {
            var doc       = this.GetNewDoc();
            var page_node = new VA.DOM.Page();

            var basic_stencil      = doc.Application.Documents.OpenStencil(this.basic_u_vss);
            var basic_masters      = basic_stencil.Masters;
            var connectors_stencil = doc.Application.Documents.OpenStencil(this.connec_u_vss);
            var connectors_masters = connectors_stencil.Masters;

            var master1 = basic_masters[this.rectangle];
            var master2 = connectors_masters[this.dynamicconnector];

            var master_node_0 = page_node.Shapes.Drop(master1, 3, 3);
            var master_node_1 = page_node.Shapes.Drop(master1, 6, 5);
            var dc            = page_node.Shapes.Connect(master2, master_node_0, master_node_1);

            var page = page_node.Render(doc);

            Assert.AreEqual(3, page.Shapes.Count);

            page.Delete(0);
            doc.Close(true);
        }
示例#26
0
        public void DOM_ConnectShapes()
        {
            var doc = this.GetNewDoc();
            var page_node = new VA.DOM.Page();
            var basic_stencil = doc.Application.Documents.OpenStencil("basic_u.vss");
            var basic_masters = basic_stencil.Masters;

            var connectors_stencil = doc.Application.Documents.OpenStencil("connec_u.vss");
            var connectors_masters = connectors_stencil.Masters;

            var master1 = basic_masters["Rectangle"];
            var master2 = connectors_masters["Dynamic Connector"];

            var master_node_0 = page_node.Shapes.Drop(master1, 3, 3);
            var master_node_1 = page_node.Shapes.Drop(master1, 6, 5);
            var dc = page_node.Shapes.Connect(master2, master_node_0, master_node_1);

            var page = page_node.Render(doc);

            Assert.AreEqual(3, page.Shapes.Count);

            page.Delete(0);
            doc.Close(true);
        }
示例#27
0
        public void DOM_FormatShape()
        {
            var doc = this.GetNewDoc();
            var page_node = new VA.DOM.Page();
            var stencil = doc.Application.Documents.OpenStencil("basic_u.vss");
            var master1 = stencil.Masters["Rectangle"];

            var master_node_0 = page_node.Shapes.Drop(master1, 3, 3);
            var bez_node_0 = page_node.Shapes.DrawBezier(new double[] { 1, 2, 3, 3, 6, 3, 3, 4 });
            var line_node_0 = page_node.Shapes.DrawLine(1, 1, 3, 3);

            master_node_0.Cells.LineWeight = 0.1;
            bez_node_0.Cells.LineWeight = 0.3;
            line_node_0.Cells.LineWeight = 0.5;

            var page = page_node.Render(doc);

            Assert.AreEqual(3, page.Shapes.Count);
            page.Delete(0);
            doc.Close(true);
        }
示例#28
0
        public void DOM_DropMaster()
        {
            var doc = this.GetNewDoc();
            var page_node = new VA.DOM.Page();
            var stencil = doc.Application.Documents.OpenStencil("basic_u.vss");
            var master1 = stencil.Masters["Rectangle"];

            var master_node_0 = page_node.Shapes.Drop(master1, 3, 3);
            var master_node_1 = page_node.Shapes.Drop("Rectangle", "basic_u.vss", 5, 5);

            var page = page_node.Render(doc);

            Assert.AreEqual(2, page.Shapes.Count);

            // Verify that the shapes created both have IDs and shape objects associated with them
            Assert.AreNotEqual(0, master_node_0.VisioShapeID);
            Assert.AreNotEqual(0, master_node_1.VisioShapeID);
            Assert.IsNotNull(master_node_0.VisioShape);
            Assert.IsNotNull(master_node_1.VisioShape);
            page.Delete(0);
            doc.Close(true);
        }
示例#29
0
        public void DOM_DrawOrgChart()
        {
            // How to draw using a Template instead of a doc and a stencil
            const string orgchart_vst = "orgch_u.vst" +
                                        "";

            var app = this.GetVisioApplication();
            var doc_node = new VA.DOM.Document(orgchart_vst, IVisio.VisMeasurementSystem.visMSUS);
            var page_node = new VA.DOM.Page();
            doc_node.Pages.Add(page_node);

            // Have to be smart about selecting the right master with Visio 2013
            int vis_ver = int.Parse(app.Version.Split('.')[0]);
            string position_master_name = vis_ver >= 15 ? "Position Belt" : "Position";

            var s1 = new VisioAutomation.DOM.Shape(position_master_name, null, new VA.Drawing.Point(3, 4));
            page_node.Shapes.Add(s1);
            var doc = doc_node.Render(app);

            doc.Close(true);
        }
示例#30
0
        public void DOM_DrawEmpty()
        {
            // Verify that an empty DOM page can be created and rendered
            var doc = this.GetNewDoc();
            var page_node = new VA.DOM.Page();
            page_node.Size = new VA.Drawing.Size(5, 5);
            var page = page_node.Render(doc);

            Assert.AreEqual(0, page.Shapes.Count);
            Assert.AreEqual(new VA.Drawing.Size(5, 5), VisioAutomationTest.GetPageSize(page));

            page.Delete(0);
            doc.Close(true);
        }
示例#31
0
        public void DOM_DrawLine()
        {
            var doc = this.GetNewDoc();
            var page_node = new VA.DOM.Page();
            var line_node_0 = page_node.Shapes.DrawLine(1, 1, 3, 3);
            var page = page_node.Render(doc);

            Assert.AreEqual(1, page.Shapes.Count);
            Assert.AreNotEqual(0, line_node_0.VisioShapeID);
            Assert.IsNotNull(line_node_0.VisioShape);
            Assert.AreEqual(2.0, line_node_0.VisioShape.CellsU["PinX"].Result[IVisio.VisUnitCodes.visNumber]);
            page.Delete(0);
            doc.Close(true);
        }
示例#32
0
        private static void draw_colors(List <System.Drawing.Color> colors)
        {
            if (colors.Count < 1)
            {
                return;
            }

            var app = Globals.ThisAddIn.Application;

            var domdoc    = new VA.DOM.Document();
            var page_node = new VA.DOM.Page();

            domdoc.Pages.Add(page_node);


            double y         = 8;
            double col0_w    = 3.0;
            double col0_x    = 0;
            double sep       = 0.5;
            double col1_x    = col0_x + col0_w + sep;
            double cellwidth = 1.0;
            double col2_x    = col1_x + cellwidth + sep;
            double col3_x    = col2_x + cellwidth + sep;
            var    sb        = new StringBuilder();

            foreach (var color in colors)
            {
                var    shape0               = page_node.Shapes.DrawRectangle(col0_x, y, col0_x + col0_w, y + cellwidth);
                var    shape1               = page_node.Shapes.DrawRectangle(col1_x, y, col1_x + cellwidth, y + cellwidth);
                var    shape2               = page_node.Shapes.DrawRectangle(col2_x, y, col2_x + cellwidth, y + cellwidth);
                var    shape3               = page_node.Shapes.DrawRectangle(col3_x, y, col3_x + cellwidth, y + cellwidth);
                var    fill                 = new VisioAutomation.Drawing.ColorRGB(color.R, color.G, color.B);
                string color_formula        = fill.ToFormula();
                double trans                = (color.A / 255.0);
                string transparency_formula = trans.ToString(System.Globalization.CultureInfo.InvariantCulture);


                shape1.Cells.FillForegnd = color_formula;
                shape1.Cells.LinePattern = "0";
                shape1.Cells.LineWeight  = "0";
                shape2.Cells.LineColor   = color_formula;
                shape2.Cells.LineWeight  = "0.25in";
                shape2.Cells.FillPattern = "0";
                shape3.Cells.CharColor   = color_formula;
                shape3.Cells.FillPattern = "0";
                shape3.Cells.LinePattern = "0";
                shape3.Cells.LineWeight  = "0";
                shape3.Text           = new VA.Text.Markup.TextElement("ABC");
                shape3.CharFontName   = "Segoe UI";
                shape3.Cells.CharSize = "24pt";

                sb.Clear();
                sb.AppendFormat("rgb({0},{1},{2})\n", color.R, color.G, color.B);
                sb.AppendFormat("{0}\n", System.Drawing.ColorTranslator.ToHtml(color));

                if (color.A != 255)
                {
                    sb.AppendFormat("transparency={0:0.00}", trans);
                }

                shape0.Text         = new VA.Text.Markup.TextElement(sb.ToString());
                shape0.CharFontName = "Segoe UI";
                shape0.Cells.ParaHorizontalAlign = "0";
                shape0.Cells.VerticalAlign       = "0";
                shape0.Cells.LinePattern         = "0";
                shape0.Cells.LineWeight          = "0";
                shape0.Cells.FillForegnd         = "rgb(240,240,240)";

                if (color.A != 255)
                {
                    shape1.Cells.FillForegndTrans = transparency_formula;
                    shape2.Cells.LineColorTrans   = transparency_formula;
                    shape3.Cells.CharTransparency = transparency_formula;
                }


                y -= cellwidth + sep;
            }

            page_node.ResizeToFit       = true;
            page_node.ResizeToFitMargin = new VA.Drawing.Size(cellwidth, cellwidth);

            domdoc.Render(app);

            var window = app.ActiveWindow;

            window.ShowPageBreaks = 0;
            window.ShowGuides     = 0;
            window.DeselectAll();
        }
示例#33
0
        public void DOM_DrawBezier()
        {
            var doc = this.GetNewDoc();
            var page_node = new VA.DOM.Page();
            var bez_node_0 = page_node.Shapes.DrawBezier(new double[] { 1, 2, 3, 3, 6, 3, 3, 4 });

            var page = page_node.Render(doc);

            Assert.AreEqual(1, page.Shapes.Count);
            Assert.AreNotEqual(0, bez_node_0.VisioShapeID);
            Assert.IsNotNull(bez_node_0.VisioShape);

            page.Delete(0);
            doc.Close(true);
        }
示例#34
0
        internal void RenderToVisio(Drawing drawing, IVisio.Page page)
        {
            if (drawing == null)
            {
                throw new System.ArgumentNullException("drawing");
            }

            if (page == null)
            {
                throw new System.ArgumentNullException("page");
            }

            if (drawing.Root == null)
            {
                throw new System.ArgumentException("Tree has root node set to null", "drawing");
            }

            const double border_width = 0.5;

            // Construct a layout tree from the hierarchy
            var treenodes = VA.Internal.TreeOps.CopyTree(
                drawing.Root,
                n => n.Children,
                n => node_to_layout_node(n),
                (p, c) => p.AddChild(c));

            // Perform the layout
            var layout = new VA.Models.InternalTree.TreeLayout <object>();

            layout.Options.Direction         = map_direction2(this.LayoutOptions.Direction);
            layout.Options.LevelSeparation   = 1;
            layout.Options.SiblingSeparation = 0.25;
            layout.Options.SubtreeSeparation = 1;

            layout.Root.AddChild(treenodes[0]);
            layout.PerformLayout();

            // Render the Document in Visio
            var bb = layout.GetBoundingBoxOfTree();

            var app                = page.Application;
            var documents          = app.Documents;
            var basic_stencil      = documents.OpenStencil(basic_stencil_name);
            var connectors_stencil = documents.OpenStencil(connectors_stencil_name);
            var basic_masters      = basic_stencil.Masters;
            var connectors_masters = connectors_stencil.Masters;

            var node_master      = basic_masters[rect_master_name];
            var connector_master = connectors_masters[dc_master_name];

            var page_node = new VA.DOM.Page();

            var page_size = bb.Size.Add(border_width * 2, border_width * 2.0);

            // fixup the nodes so that they render on the page
            foreach (var i in treenodes)
            {
                i.Position = i.Position.Add(border_width, border_width);
            }

            var centerpoints = treenodes.Select(tn => tn.Rect.Center).ToList();
            var master_nodes = centerpoints.Select(cp => page_node.Shapes.Drop(node_master, cp)).ToList();

            // For each OrgChart object, attach the shape that corresponds to it
            foreach (int i in Enumerable.Range(0, treenodes.Count))
            {
                var       tree_node   = (VA.Models.Tree.Node)treenodes[i].Data;
                DOM.Shape master_node = master_nodes[i];
                tree_node.DOMNode = master_node;

                if (tree_node.Cells != null)
                {
                    master_node.Cells = tree_node.Cells.ShallowCopy();
                }

                master_node.Cells.Width  = treenodes[i].Size.Width;
                master_node.Cells.Height = treenodes[i].Size.Height;
                master_node.Text         = tree_node.Text;
            }

            if (this.LayoutOptions.ConnectorType == ConnectorType.DynamicConnector)
            {
                var orgchart_nodes = treenodes.Select(tn => tn.Data).Cast <Node>();

                foreach (var parent in orgchart_nodes)
                {
                    foreach (var child in parent.Children)
                    {
                        var parent_shape = (VA.DOM.BaseShape)parent.DOMNode;
                        var child_shape  = (VA.DOM.BaseShape)child.DOMNode;
                        var connector    = page_node.Shapes.Connect(connector_master, parent_shape, child_shape);
                        connector.Cells = this.LayoutOptions.ConnectorCells;
                    }
                }
            }
            else if (this.LayoutOptions.ConnectorType == ConnectorType.CurvedBezier)
            {
                foreach (var connection in layout.EnumConnections())
                {
                    var bez   = layout.GetConnectionBezier(connection);
                    var shape = page_node.Shapes.DrawBezier(bez);
                    shape.Cells = this.LayoutOptions.ConnectorCells;
                }
            }
            else if (this.LayoutOptions.ConnectorType == ConnectorType.PolyLine)
            {
                foreach (var connection in layout.EnumConnections())
                {
                    var polyline = layout.GetConnectionPolyline(connection);
                    var shape    = page_node.Shapes.DrawPolyLine(polyline);
                    shape.Cells = this.LayoutOptions.ConnectorCells;
                }
            }
            else
            {
                string msg = "Unsupported Connector Type";
                throw new VA.AutomationException(msg);
            }

            page_node.Size = page_size;
            page_node.Render(page);

            // Attach all the orgchart nodes to the Visio shapes that were created
            foreach (int i in Enumerable.Range(0, treenodes.Count))
            {
                var orgnode = (Node)treenodes[i].Data;
                var shape   = (VA.DOM.BaseShape)orgnode.DOMNode;
                orgnode.VisioShape = shape.VisioShape;
            }
        }
示例#35
0
        public void DOM_VerifyThatUnknownStencilsAreDetected()
        {
            var doc = this.GetNewDoc();
            var page_node = new VA.DOM.Page();
            var master_node_0 = page_node.Shapes.Drop("Rectangle", "basic_uXXX.vss", 3, 3);

            IVisio.Page page = null;
            bool caught = false;
            try
            {
                page = page_node.Render(doc);
            }
            catch (VA.AutomationException)
            {
                caught = true;
            }

            if (caught == false)
            {
                Assert.Fail("Expected an AutomationException");
            }

            if (page!=null)
            {
                page.Delete(0);
            }
            doc.Close(true);
        }
        public void Render(IVisio.Application app)
        {
            var orgchartdrawing = this;

            if (orgchartdrawing == null)
            {
                throw new System.ArgumentNullException("orgchartdrawing");
            }

            if (app == null)
            {
                throw new System.ArgumentNullException("app");
            }

            if (orgchartdrawing.OrgCharts.Count < 1)
            {
                throw new System.ArgumentException("orgchart must have at least one root");
            }

            foreach (var root in orgchartdrawing.OrgCharts)
            {
                if (root == null)
                {
                    throw new System.ArgumentException("Org chart has root node set to null", "orgchartdrawing");
                }
            }

            int majorver = int.Parse(app.Version.Split('.')[0]);
            bool is_visio_2013 = majorver >= 15;

            const string orgchart_vst = "orgch_u.vst";
            string orgchart_master_node_name = is_visio_2013 ? "Position Belt" : "Position";
            const string dyncon_master_name = "Dynamic connector";
            const double border_width = 0.5;

            var doc_node = new VA.DOM.Document(orgchart_vst, IVisio.VisMeasurementSystem.visMSUS);

            var trees = new List<IList<VisioAutomation.Models.InternalTree.Node<object>>>();

            foreach (var root in orgchartdrawing.OrgCharts)
            {
                // Construct a layout tree from the hierarchy
                var treenodes = VA.Internal.TreeOps.CopyTree(
                    orgchartdrawing.OrgCharts[0],
                    n => n.Children,
                    n => node_to_layout_node(n),
                    (p, c) => p.AddChild(c));

                trees.Add(treenodes);

                // Perform the layout
                var layout = new VA.Models.InternalTree.TreeLayout<object>();

                layout.Options.Direction = map_direction2(this.LayoutOptions.Direction);
                layout.Options.LevelSeparation = 1;
                layout.Options.SiblingSeparation = 0.25;
                layout.Options.SubtreeSeparation = 1;

                layout.Root.AddChild(treenodes[0]);
                layout.PerformLayout();

                // Render the Document in Visio
                var bb = layout.GetBoundingBoxOfTree();

                // vis.ActiveWindow.ShowConnectPoints = 0;

                var page_node = new VA.DOM.Page();
                doc_node.Pages.Add(page_node);

                // fixup the nodes so that they render on the page
                foreach (var i in treenodes)
                {
                    i.Position = i.Position.Add(border_width, border_width);
                }

                var centerpoints = new VA.Drawing.Point[treenodes.Count];
                foreach (int i in Enumerable.Range(0, treenodes.Count))
                {
                    centerpoints[i] = treenodes[i].Rect.Center;
                }

                // TODO: Add support for Left to right , Right to Left, and Bottom to Top Layouts

                var vmasters = centerpoints
                    .Select(centerpoint => page_node.Shapes.Drop(orgchart_master_node_name, null, centerpoint))
                    .ToList();

                // For each OrgChart object, attach the shape that corresponds to it
                foreach (int i in Enumerable.Range(0, treenodes.Count))
                {
                    var orgnode = (Node)treenodes[i].Data;
                    orgnode.DOMNode = vmasters[i];
                    vmasters[i].Cells.Width = treenodes[i].Size.Width;
                    vmasters[i].Cells.Height = treenodes[i].Size.Height;
                }

                if (this.LayoutOptions.UseDynamicConnectors)
                {
                    var orgchart_nodes = treenodes.Select(tn => tn.Data).Cast<Node>();

                    foreach (var parent in orgchart_nodes)
                    {
                        foreach (var child in parent.Children)
                        {
                            var parent_shape = (VA.DOM.BaseShape)parent.DOMNode;
                            var child_shape = (VA.DOM.BaseShape)child.DOMNode;
                            var connector = page_node.Shapes.Connect(dyncon_master_name, null, parent_shape, child_shape);
                        }
                    }
                }
                else
                {
                    foreach (var connection in layout.EnumConnections())
                    {
                        var bez = layout.GetConnectionBezier(connection);
                        page_node.Shapes.DrawBezier(bez);
                    }
                }

                // Set the Text Labels on each Org node
                foreach (int i in Enumerable.Range(0, treenodes.Count))
                {
                    var orgnode = (Node)treenodes[i].Data;
                    var shape = (VA.DOM.BaseShape)orgnode.DOMNode;
                    shape.Text = new VA.Text.Markup.TextElement(orgnode.Text);
                }

                var page_size_with_border = bb.Size.Add(border_width * 2, border_width * 2.0);
                page_node.Size = page_size_with_border;
                page_node.ResizeToFit = true;
                page_node.ResizeToFitMargin = new VA.Drawing.Size(border_width * 2, border_width * 2.0);
            } // finish handling root node

            var doc = doc_node.Render(app);

            foreach (var treenodes in trees)
            {
                var orgnodes = treenodes.Select(i => i.Data).Cast<Node>();
                var orgnodes_with_urls = orgnodes.Where(n => n.URL != null);
                var all_urls = orgnodes_with_urls.Select(n => new { orgnode = n, shape = (VA.DOM.BaseShape)n.DOMNode, url = n.URL.Trim() });

                foreach (var url in all_urls)
                {
                    var hlink = url.orgnode.VisioShape.Hyperlinks.Add();
                    hlink.Name = "Row_1";
                    hlink.Address = url.orgnode.URL;
                }

                // Attach all the orgchart nodes to the Visio shapes that were created
                foreach (int i in Enumerable.Range(0, treenodes.Count))
                {
                    var orgnode = (Node)treenodes[i].Data;
                    var shape = (VA.DOM.BaseShape)orgnode.DOMNode;
                    orgnode.VisioShape = shape.VisioShape;
                }
            }
        }
示例#37
0
        public void Render(IVisio.Page page)
        {
            if (page == null)
            {
                throw new ArgumentNullException("page");
            }

            var nodes_to_draw = this.Nodes.Where(n => n.Draw).ToList();

            var page_node = new VA.DOM.Page();

            var shape_nodes = new List<VA.DOM.Shape>(nodes_to_draw.Count);
            foreach (var node in nodes_to_draw)
            {
                var shape_node = page_node.Shapes.Drop(node.Master, node.Rectangle.Center);

                if (node.Cells != null)
                {
                    shape_node.Cells = node.Cells.ShallowCopy();
                }

                shape_node.Cells.Width = node.Rectangle.Width;
                shape_node.Cells.Height = node.Rectangle.Height;

                if (!string.IsNullOrEmpty(node.Text))
                {
                    shape_node.Text = new VA.Text.Markup.TextElement( node.Text );
                }

                shape_nodes.Add(shape_node);
            }

            page_node.Shapes.Render(page);

            for (int i = 0; i < nodes_to_draw.Count; i++)
            {
                var node = nodes_to_draw[i];
                var shape_node = shape_nodes[i];

                node.Shape = shape_node.VisioShape;
                node.ShapeID = shape_node.VisioShapeID;
            }
        }
示例#38
0
        private static void draw_colors(List<System.Drawing.Color> colors)
        {
            if (colors.Count < 1)
            {
                return;
            }

            var app = Globals.ThisAddIn.Application;

            var domdoc = new VA.DOM.Document();
            var page_node = new VA.DOM.Page();
            domdoc.Pages.Add(page_node);
          

            double y = 8;
            double col0_w = 3.0;
            double col0_x = 0;
            double sep = 0.5;
            double col1_x = col0_x + col0_w + sep;
            double cellwidth = 1.0;
            double col2_x = col1_x + cellwidth + sep;
            double col3_x = col2_x + cellwidth + sep;
            var sb = new StringBuilder();
            foreach (var color in colors)
            {
                var shape0 = page_node.Shapes.DrawRectangle(col0_x, y, col0_x + col0_w, y + cellwidth);
                var shape1 = page_node.Shapes.DrawRectangle(col1_x, y, col1_x + cellwidth, y + cellwidth);
                var shape2 = page_node.Shapes.DrawRectangle(col2_x, y, col2_x + cellwidth, y + cellwidth);
                var shape3 = page_node.Shapes.DrawRectangle(col3_x, y, col3_x + cellwidth, y + cellwidth);
                var fill = new VisioAutomation.Drawing.ColorRGB(color.R, color.G, color.B);
                string color_formula = fill.ToFormula();
                double trans = (color.A / 255.0);
                string transparency_formula = trans.ToString(System.Globalization.CultureInfo.InvariantCulture);


                shape1.Cells.FillForegnd = color_formula;
                shape1.Cells.LinePattern = "0";
                shape1.Cells.LineWeight = "0";
                shape2.Cells.LineColor = color_formula;
                shape2.Cells.LineWeight = "0.25in";
                shape2.Cells.FillPattern = "0";
                shape3.Cells.CharColor = color_formula;
                shape3.Cells.FillPattern = "0";
                shape3.Cells.LinePattern = "0";
                shape3.Cells.LineWeight = "0";
                shape3.Text = new VA.Text.Markup.TextElement("ABC");
                shape3.CharFontName = "Segoe UI";
                shape3.Cells.CharSize = "24pt";

                sb.Clear();
                sb.AppendFormat("rgb({0},{1},{2})\n", color.R, color.G, color.B);
                sb.AppendFormat("{0}\n", System.Drawing.ColorTranslator.ToHtml(color));

                if (color.A != 255)
                {
                    sb.AppendFormat("transparency={0:0.00}", trans);
                }

                shape0.Text = new VA.Text.Markup.TextElement(sb.ToString());
                shape0.CharFontName = "Segoe UI";
                shape0.Cells.ParaHorizontalAlign = "0";
                shape0.Cells.VerticalAlign = "0";
                shape0.Cells.LinePattern = "0";
                shape0.Cells.LineWeight = "0";
                shape0.Cells.FillForegnd = "rgb(240,240,240)";

                if (color.A != 255)
                {
                    shape1.Cells.FillForegndTrans = transparency_formula;
                    shape2.Cells.LineColorTrans = transparency_formula;
                    shape3.Cells.CharTransparency = transparency_formula;
                }


                y -= cellwidth + sep;
            }

            page_node.ResizeToFit = true;
            page_node.ResizeToFitMargin = new VA.Drawing.Size(cellwidth, cellwidth);

            domdoc.Render(app);

            var window = app.ActiveWindow;
            window.ShowPageBreaks = 0;
            window.ShowGuides = 0;
            window.DeselectAll();
        }
示例#39
0
        public void Render(IVisio.Application app)
        {
            var orgchartdrawing = this;

            if (orgchartdrawing == null)
            {
                throw new System.ArgumentNullException("orgchartdrawing");
            }

            if (app == null)
            {
                throw new System.ArgumentNullException("app");
            }

            if (orgchartdrawing.OrgCharts.Count < 1)
            {
                throw new System.ArgumentException("orgchart must have at least one root");
            }

            foreach (var root in orgchartdrawing.OrgCharts)
            {
                if (root == null)
                {
                    throw new System.ArgumentException("Org chart has root node set to null", "orgchartdrawing");
                }
            }

            int  majorver      = int.Parse(app.Version.Split('.')[0]);
            bool is_visio_2013 = majorver >= 15;

            const string orgchart_vst = "orgch_u.vst";
            string       orgchart_master_node_name = is_visio_2013 ? "Position Belt" : "Position";
            const string dyncon_master_name        = "Dynamic connector";
            const double border_width = 0.5;

            var doc_node = new VA.DOM.Document(orgchart_vst, IVisio.VisMeasurementSystem.visMSUS);

            var trees = new List <IList <VisioAutomation.Models.InternalTree.Node <object> > >();

            foreach (var root in orgchartdrawing.OrgCharts)
            {
                // Construct a layout tree from the hierarchy
                var treenodes = VA.Internal.TreeOps.CopyTree(
                    orgchartdrawing.OrgCharts[0],
                    n => n.Children,
                    n => node_to_layout_node(n),
                    (p, c) => p.AddChild(c));

                trees.Add(treenodes);

                // Perform the layout
                var layout = new VA.Models.InternalTree.TreeLayout <object>();

                layout.Options.Direction         = map_direction2(this.LayoutOptions.Direction);
                layout.Options.LevelSeparation   = 1;
                layout.Options.SiblingSeparation = 0.25;
                layout.Options.SubtreeSeparation = 1;

                layout.Root.AddChild(treenodes[0]);
                layout.PerformLayout();

                // Render the Document in Visio
                var bb = layout.GetBoundingBoxOfTree();

                // vis.ActiveWindow.ShowConnectPoints = 0;

                var page_node = new VA.DOM.Page();
                doc_node.Pages.Add(page_node);

                // fixup the nodes so that they render on the page
                foreach (var i in treenodes)
                {
                    i.Position = i.Position.Add(border_width, border_width);
                }

                var centerpoints = new VA.Drawing.Point[treenodes.Count];
                foreach (int i in Enumerable.Range(0, treenodes.Count))
                {
                    centerpoints[i] = treenodes[i].Rect.Center;
                }

                // TODO: Add support for Left to right , Right to Left, and Bottom to Top Layouts

                var vmasters = centerpoints
                               .Select(centerpoint => page_node.Shapes.Drop(orgchart_master_node_name, null, centerpoint))
                               .ToList();


                // For each OrgChart object, attach the shape that corresponds to it
                foreach (int i in Enumerable.Range(0, treenodes.Count))
                {
                    var orgnode = (Node)treenodes[i].Data;
                    orgnode.DOMNode          = vmasters[i];
                    vmasters[i].Cells.Width  = treenodes[i].Size.Width;
                    vmasters[i].Cells.Height = treenodes[i].Size.Height;
                }

                if (this.LayoutOptions.UseDynamicConnectors)
                {
                    var orgchart_nodes = treenodes.Select(tn => tn.Data).Cast <Node>();

                    foreach (var parent in orgchart_nodes)
                    {
                        foreach (var child in parent.Children)
                        {
                            var parent_shape = (VA.DOM.BaseShape)parent.DOMNode;
                            var child_shape  = (VA.DOM.BaseShape)child.DOMNode;
                            var connector    = page_node.Shapes.Connect(dyncon_master_name, null, parent_shape, child_shape);
                        }
                    }
                }
                else
                {
                    foreach (var connection in layout.EnumConnections())
                    {
                        var bez = layout.GetConnectionBezier(connection);
                        page_node.Shapes.DrawBezier(bez);
                    }
                }

                // Set the Text Labels on each Org node
                foreach (int i in Enumerable.Range(0, treenodes.Count))
                {
                    var orgnode = (Node)treenodes[i].Data;
                    var shape   = (VA.DOM.BaseShape)orgnode.DOMNode;
                    shape.Text = new VA.Text.Markup.TextElement(orgnode.Text);
                }

                var page_size_with_border = bb.Size.Add(border_width * 2, border_width * 2.0);
                page_node.Size              = page_size_with_border;
                page_node.ResizeToFit       = true;
                page_node.ResizeToFitMargin = new VA.Drawing.Size(border_width * 2, border_width * 2.0);
            } // finish handling root node

            var doc = doc_node.Render(app);

            foreach (var treenodes in trees)
            {
                var orgnodes           = treenodes.Select(i => i.Data).Cast <Node>();
                var orgnodes_with_urls = orgnodes.Where(n => n.URL != null);
                var all_urls           = orgnodes_with_urls.Select(n => new { orgnode = n, shape = (VA.DOM.BaseShape)n.DOMNode, url = n.URL.Trim() });

                foreach (var url in all_urls)
                {
                    var hlink = url.orgnode.VisioShape.Hyperlinks.Add();
                    hlink.Name    = "Row_1";
                    hlink.Address = url.orgnode.URL;
                }

                // Attach all the orgchart nodes to the Visio shapes that were created
                foreach (int i in Enumerable.Range(0, treenodes.Count))
                {
                    var orgnode = (Node)treenodes[i].Data;
                    var shape   = (VA.DOM.BaseShape)orgnode.DOMNode;
                    orgnode.VisioShape = shape.VisioShape;
                }
            }
        }
示例#40
0
        public void DOM_DrawOrgChart()
        {
            var app = this.GetVisioApplication();
            var vis_ver = VA.Application.ApplicationHelper.GetVersion(app);

            // How to draw using a Template instead of a doc and a stencil
            string orgchart_vst = "orgchart.vst";
            string position_master_name = vis_ver.Major >= 15 ? "Position Belt" : "Position";

            var doc_node = new VA.DOM.Document(orgchart_vst, IVisio.VisMeasurementSystem.visMSUS);
            var page_node = new VA.DOM.Page();
            doc_node.Pages.Add(page_node);

            // Have to be smart about selecting the right master with Visio 2013

            var s1 = new VA.DOM.Shape(position_master_name, null, new VA.Drawing.Point(3, 8));
            page_node.Shapes.Add(s1);

            var s2 = new VA.DOM.Shape(position_master_name, null, new VA.Drawing.Point(0, 4));
            page_node.Shapes.Add(s2);

            var s3 = new VA.DOM.Shape(position_master_name, null, new VA.Drawing.Point(6, 4));
            page_node.Shapes.Add(s3);

            page_node.Shapes.Connect(this.dynamicconnector, this.connec_u_vss, s1, s2);
            page_node.Shapes.Connect(this.dynamicconnector, this.connec_u_vss, s1, s3);

            var doc = doc_node.Render(app);

            //doc.Close(true);
        }
示例#41
0
        internal void RenderToVisio(Drawing drawing, IVisio.Page page)
        {
            if (drawing == null)
            {
                throw new System.ArgumentNullException("drawing");
            }

            if (page== null)
            {
                throw new System.ArgumentNullException("page");
            }

            if (drawing.Root == null)
            {
                throw new System.ArgumentException("Tree has root node set to null", "drawing");
            }

            const double border_width = 0.5;

            // Construct a layout tree from the hierarchy
            var treenodes = VA.Internal.TreeOps.CopyTree(
                drawing.Root,
                n => n.Children,
                n => node_to_layout_node(n),
                (p, c) => p.AddChild(c));

            // Perform the layout
            var layout = new VA.Models.InternalTree.TreeLayout<object>();

            layout.Options.Direction = map_direction2(this.LayoutOptions.Direction);
            layout.Options.LevelSeparation = 1;
            layout.Options.SiblingSeparation = 0.25;
            layout.Options.SubtreeSeparation = 1;

            layout.Root.AddChild(treenodes[0]);
            layout.PerformLayout();

            // Render the Document in Visio
            var bb = layout.GetBoundingBoxOfTree();

            var app = page.Application;
            var documents = app.Documents;
            var basic_stencil = documents.OpenStencil(basic_stencil_name);
            var connectors_stencil = documents.OpenStencil(connectors_stencil_name);
            var basic_masters = basic_stencil.Masters;
            var connectors_masters = connectors_stencil.Masters;

            var node_master = basic_masters[rect_master_name];
            var connector_master = connectors_masters[dc_master_name];

            var page_node = new VA.DOM.Page();

            var page_size = bb.Size.Add(border_width*2, border_width*2.0);

            // fixup the nodes so that they render on the page
            foreach (var i in treenodes)
            {
                i.Position = i.Position.Add(border_width, border_width);
            }

            var centerpoints = treenodes.Select(tn => tn.Rect.Center).ToList();
            var master_nodes = centerpoints.Select(cp => page_node.Shapes.Drop(node_master, cp)).ToList();

            // For each OrgChart object, attach the shape that corresponds to it
            foreach (int i in Enumerable.Range(0, treenodes.Count))
            {
                var tree_node = (VA.Models.Tree.Node)treenodes[i].Data;
                DOM.Shape master_node = master_nodes[i];
                tree_node.DOMNode = master_node;

                if (tree_node.Cells!=null)
                {
                    master_node.Cells = tree_node.Cells.ShallowCopy();
                }

                master_node.Cells.Width = treenodes[i].Size.Width;
                master_node.Cells.Height = treenodes[i].Size.Height;
                master_node.Text = tree_node.Text;
            }

            if (this.LayoutOptions.ConnectorType  == ConnectorType.DynamicConnector)
            {
                var orgchart_nodes = treenodes.Select(tn => tn.Data).Cast<Node>();

                foreach (var parent in orgchart_nodes)
                {
                    foreach (var child in parent.Children)
                    {
                        var parent_shape = (VA.DOM.BaseShape)parent.DOMNode;
                        var child_shape = (VA.DOM.BaseShape)child.DOMNode;
                        var connector = page_node.Shapes.Connect(connector_master, parent_shape, child_shape);
                        connector.Cells = this.LayoutOptions.ConnectorCells;
                    }
                }
            }
            else if  (this.LayoutOptions.ConnectorType == ConnectorType.CurvedBezier)
            {
                foreach (var connection in layout.EnumConnections())
                {
                    var bez = layout.GetConnectionBezier(connection);
                    var shape = page_node.Shapes.DrawBezier(bez);
                    shape.Cells = this.LayoutOptions.ConnectorCells;
                }
            }
            else if (this.LayoutOptions.ConnectorType == ConnectorType.PolyLine)
            {
                foreach (var connection in layout.EnumConnections())
                {
                    var polyline = layout.GetConnectionPolyline(connection);
                    var shape = page_node.Shapes.DrawPolyLine(polyline);
                    shape.Cells = this.LayoutOptions.ConnectorCells;
                }
            }
            else
            {
                string msg = "Unsupported Connector Type";
                throw new VA.AutomationException(msg);
            }

            page_node.Size = page_size;
            page_node.Render(page);

            // Attach all the orgchart nodes to the Visio shapes that were created
            foreach (int i in Enumerable.Range(0, treenodes.Count))
            {
                var orgnode = (Node) treenodes[i].Data;
                var shape = (VA.DOM.BaseShape)orgnode.DOMNode;
                orgnode.VisioShape = shape.VisioShape;
            }
        }
示例#42
0
        public void DOM_DrawAndDrop()
        {
            var doc = this.GetNewDoc();
            var page_node = new VA.DOM.Page();

            var rect0 = new VA.Drawing.Rectangle(3, 4, 7, 8);
            var rect1 = new VA.Drawing.Rectangle(8, 1, 9, 5);
            var dropped_shape0 = page_node.Shapes.Drop("Rectangle", "basic_u.vss", rect0);
            var drawn_shape0 = page_node.Shapes.DrawRectangle(rect0);

            var dropped_shape1 = page_node.Shapes.Drop("Rectangle", "basic_u.vss", rect1);
            var drawn_shape1 = page_node.Shapes.DrawRectangle(rect1);

            var page = page_node.Render(doc);

            var xfrms = VA.Shapes.XFormCells.GetCells(page,
                                                        new int[] { dropped_shape0.VisioShapeID,
                                                            drawn_shape0.VisioShapeID,
                                                            dropped_shape1.VisioShapeID,
                                                            drawn_shape1.VisioShapeID });

            Assert.AreEqual(xfrms[1].PinX, xfrms[0].PinX);
            Assert.AreEqual(xfrms[1].PinY, xfrms[0].PinY);

            Assert.AreEqual(xfrms[1].Width, xfrms[0].Width);
            Assert.AreEqual(xfrms[1].Height, xfrms[0].Height);

            Assert.AreEqual(xfrms[3].PinX,   xfrms[2].PinX);
            Assert.AreEqual(xfrms[3].PinY,   xfrms[2].PinY);
            Assert.AreEqual(xfrms[3].Width,  xfrms[2].Width);
            Assert.AreEqual(xfrms[3].Height, xfrms[2].Height);

            doc.Close(true);
        }