Пример #1
0
        private void CreateDynamicConnectorEdges(VA.DOM.ShapeList shape_nodes, MG.GeometryGraph msagl_graph)
        {
            // CREATE EDGES
            foreach (var i in msagl_graph.Edges)
            {
                var layoutconnector = (DGMODEL.Connector)i.UserData;
                var vconnector      = new VA.DOM.Connector(
                    layoutconnector.From.DOMNode,
                    layoutconnector.To.DOMNode, "Dynamic Connector", "connec_u.vss");
                layoutconnector.DOMNode = vconnector;
                shape_nodes.Add(vconnector);
            }

            var edge_pairs = from n in msagl_graph.Edges
                             let lc = (DGMODEL.Connector)n.UserData
                                      select
                                      new { msagl_edge = n, layout_connector = lc, vconnector = (VA.DOM.Connector)lc.DOMNode };

            foreach (var i in edge_pairs)
            {
                int con_route_style   = (int)ConnectorTypeToCellVal_Appearance(i.layout_connector.ConnectorType);
                int shape_route_style = (int)ConnectorTypeToCellVal_Style(i.layout_connector.ConnectorType);

                i.vconnector.Text = new VA.Text.Markup.TextElement(i.layout_connector.Label);

                i.vconnector.Cells = i.layout_connector.Cells != null?
                                     i.layout_connector.Cells.ShallowCopy()
                                         : new VA.DOM.ShapeCells();

                i.vconnector.Cells.ConLineRouteExt = con_route_style;
                i.vconnector.Cells.ShapeRouteStyle = shape_route_style;
            }
        }
Пример #2
0
        private MG.GeometryGraph CreateMSAGLGraph(DGMODEL.Drawing layout_diagram)
        {
            var msagl_graph = new MG.GeometryGraph();
            var defsize     = new VA.Drawing.Size(this.LayoutOptions.DefaultShapeSize.Width,
                                                  this.LayoutOptions.DefaultShapeSize.Height);

            // Create the nodes in MSAGL
            foreach (var layout_shape in layout_diagram.Shapes)
            {
                var nodesize   = ToMSAGLCoordinates(layout_shape.Size ?? defsize);
                var msagl_node = new MG.Node(layout_shape.ID,
                                             MG.Splines.CurveFactory.CreateBox(nodesize.Width, nodesize.Height,
                                                                               new MG.Point()));
                msagl_graph.AddNode(msagl_node);
                msagl_node.UserData = layout_shape;
            }

            bool connectors_ok = this.validate_connectors(layout_diagram);
            // TODO: What to do if connectors_ok is false?

            var msagl_size = this.ToMSAGLCoordinates(DefaultBezierConnectorLabelBoxSize);

            // Create the MSAGL Connectors
            foreach (var layout_connector in layout_diagram.Connectors)
            {
                if (layout_connector.From == null)
                {
                    throw new System.ArgumentException("Connector's From node is null");
                }

                if (layout_connector.To == null)
                {
                    throw new System.ArgumentException("Connector's To node is null");
                }

                var from_node = msagl_graph.NodeMap[layout_connector.From.ID];
                var to_node   = msagl_graph.NodeMap[layout_connector.To.ID];

                var new_edge = new MG.Edge(from_node, to_node);
                new_edge.ArrowheadAtTarget = false;
                new_edge.UserData          = layout_connector;
                msagl_graph.AddEdge(new_edge);

                new_edge.Label = new Microsoft.Msagl.Label(msagl_size.Width, msagl_size.Height, new_edge);
            }

            msagl_graph.CalculateLayout();

            this.msagl_bb = new VA.Drawing.Rectangle(
                msagl_graph.BoundingBox.Left,
                msagl_graph.BoundingBox.Bottom,
                msagl_graph.BoundingBox.Right,
                msagl_graph.BoundingBox.Top);

            this.layout_bb = new VA.Drawing.Rectangle(0, 0, this.msagl_bb.Width, msagl_bb.Height)
                             .Multiply(ScaleToDocument, ScaleToDocument);

            return(msagl_graph);
        }
Пример #3
0
        private void CreateBezierEdges(VA.DOM.ShapeList domshapes, MG.GeometryGraph msagl_graph)
        {
            // DRAW EDGES WITH BEZIERS
            foreach (var msagl_edge in msagl_graph.Edges)
            {
                var layoutconnector = (DGMODEL.Connector)msagl_edge.UserData;
                var vconnector      = draw_edge_bezier(domshapes, layoutconnector, msagl_edge);
                layoutconnector.DOMNode = vconnector;
                domshapes.Add(vconnector);
            }

            var edge_pairs = from n in msagl_graph.Edges
                             let lc = (DGMODEL.Connector)n.UserData
                                      select new { msagl_edge       = n,
                                                   layout_connector = lc,
                                                   bezier_node      = (VA.DOM.BezierCurve)lc.DOMNode };

            foreach (var i in edge_pairs)
            {
                if (i.layout_connector.Cells != null)
                {
                    i.bezier_node.Cells = i.layout_connector.Cells.ShallowCopy();
                }
            }

            foreach (var i in edge_pairs.Where(item => !string.IsNullOrEmpty(item.layout_connector.Label)))
            {
                // this is a bezier connector
                // draw a manual box instead
                var label_bb = ToDocumentCoordinates(VA.Internal.MSAGLUtil.ToVARectangle(i.msagl_edge.Label.BoundingBox));
                var vshape   = new VA.DOM.Rectangle(label_bb);
                domshapes.Add(vshape);

                vshape.Cells = DefaultBezierConnectorShapeCells.ShallowCopy();
                vshape.Text  = new VA.Text.Markup.TextElement(i.layout_connector.Label);
            }
        }
Пример #4
0
        private void CreateDOMShapes(VA.DOM.ShapeList domshapeslist, MG.GeometryGraph msagl_graph, IVisio.Application app)
        {
            var node_centerpoints = msagl_graph.NodeMap.Values
                                    .Select(n => ToDocumentCoordinates(VA.Internal.MSAGLUtil.ToVAPoint(n.Center)))
                                    .ToArray();

            // Load up all the stencil docs
            var app_documents = app.Documents;
            var nodes         = msagl_graph.NodeMap.Values.Select(get_shape);
            var stencil_names = nodes.Select(s => s.StencilName.ToUpper()).Distinct().ToList();

            var stencil_map = new Dictionary <string, IVisio.Document>();

            foreach (var stencil_name in stencil_names)
            {
                if (!stencil_map.ContainsKey(stencil_name))
                {
                    var stencil = app_documents.OpenStencil(stencil_name);
                    stencil_map[stencil_name] = stencil;
                }
            }

            var master_map = new Dictionary <string, IVisio.Master>();

            foreach (var nv in nodes)
            {
                var key = nv.StencilName.ToLower() + "+" + nv.MasterName;
                if (!master_map.ContainsKey(key))
                {
                    var stencil = stencil_map[nv.StencilName.ToUpper()];
                    var masters = stencil.Masters;
                    var master  = masters[nv.MasterName];
                    master_map[key] = master;
                }
            }

            // Create DOM Shapes for each AutoLayoutShape

            int count = 0;

            foreach (var layout_shape in nodes)
            {
                var key        = layout_shape.StencilName.ToLower() + "+" + layout_shape.MasterName;
                var master     = master_map[key];
                var shape_node = new VA.DOM.Shape(master, node_centerpoints[count]);
                layout_shape.DOMNode = shape_node;
                domshapeslist.Add(shape_node);
                count++;
            }

            var shape_pairs = from n in msagl_graph.NodeMap.Values
                              let layout_shape = (DGMODEL.Shape)n.UserData
                                                 select new
            {
                layout_shape,
                shape_node = (VA.DOM.BaseShape)layout_shape.DOMNode
            };

            // FORMAT EACH SHAPE
            foreach (var i in shape_pairs)
            {
                format_shape(i.layout_shape, i.shape_node);
            }
        }