Ejemplo n.º 1
0
        /// <summary>
        /// Gets all the pairs of shapes that are connected by a connector
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        private static IList <ConnectorEdge> GetDirectedEdgesRaw(IVisio.Page page)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException("page");
            }

            var page_connects = page.Connects;
            var connects      = page_connects.AsEnumerable();

            var edges = new List <ConnectorEdge>();

            IVisio.Shape old_connect_shape = null;
            IVisio.Shape fromsheet         = null;

            foreach (var connect in connects)
            {
                var current_connect_shape = connect.FromSheet;

                if (current_connect_shape != old_connect_shape)
                {
                    // the currect connector is NOT same as the one we stored previously
                    // this means the previous connector is connected to only one shape (not two).
                    // So skip the previos connector and start remembering from the current connector
                    old_connect_shape = current_connect_shape;
                    fromsheet         = connect.ToSheet;
                }
                else
                {
                    // the currect connector is the same as the one we stored previously
                    // this means we have enountered it twice which means it connects two
                    // shapes and is thus an edge
                    var undirected_edge = new ConnectorEdge(current_connect_shape, fromsheet, connect.ToSheet);
                    edges.Add(undirected_edge);
                }
            }

            return(edges);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns all the directed,connected pairs of shapes in the  page
        /// </summary>
        /// <param name="page"></param>
        /// <param name="flag"></param>
        /// <returns></returns>
        public static IList <ConnectorEdge> GetDirectedEdges(
            IVisio.Page page,
            ConnectorEdgeHandling flag)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException("page");
            }

            var edges = GetDirectedEdgesRaw(page);

            if (flag == ConnectorEdgeHandling.Raw)
            {
                return(edges);
            }

            // At this point we know we need to analyze the connetor arrows to produce the correct results

            var connnector_ids = edges.Select(e => e.Connector.ID).ToList();

            // Get the arrows for each connector
            var src_beginarrow = VA.ShapeSheet.SRCConstants.BeginArrow;
            var src_endarrow   = VA.ShapeSheet.SRCConstants.EndArrow;

            var query          = new VA.ShapeSheet.Query.CellQuery();
            var col_beginarrow = query.Columns.Add(src_beginarrow, "BeginArrow");
            var col_endarrow   = query.Columns.Add(src_endarrow, "EndArrow");

            var arrow_table = query.GetResults <int>(page, connnector_ids);

            IList <ConnectorEdge> directed_edges = new List <ConnectorEdge>();

            int connector_index = 0;

            foreach (var e in edges)
            {
                int beginarrow = arrow_table[connector_index][col_beginarrow.Ordinal];
                int endarrow   = arrow_table[connector_index][col_endarrow.Ordinal];

                if ((beginarrow < 1) && (endarrow < 1))
                {
                    // the line has no arrows
                    if (flag == ConnectorEdgeHandling.Arrow_TreatConnectorsWithoutArrowsAsBidirectional)
                    {
                        // in this case treat the connector as pointing in both directions
                        var de1 = new ConnectorEdge(e.Connector, e.To, e.From);
                        var de2 = new ConnectorEdge(e.Connector, e.From, e.To);
                        directed_edges.Add(de1);
                        directed_edges.Add(de2);
                    }
                    else if (flag == ConnectorEdgeHandling.Arrow_ExcludeConnectorsWithoutArrows)
                    {
                        // in this case ignore the connector completely
                    }
                    else
                    {
                        throw new AutomationException("Internal error");
                    }
                }
                else
                {
                    // The connector has either a from-arrow, a to-arrow, or both

                    // handle if it has a from arrow
                    if (beginarrow > 0)
                    {
                        var de = new ConnectorEdge(e.Connector, e.To, e.From);
                        directed_edges.Add(de);
                    }

                    // handle if it has a to arrow
                    if (endarrow > 0)
                    {
                        var de = new ConnectorEdge(e.Connector, e.From, e.To);
                        directed_edges.Add(de);
                    }
                }

                connector_index++;
            }

            return(directed_edges);
        }