public void Scripting_Connects_Scenario_1()
        {
            var client = this.GetScriptingClient();

            client.Document.NewDocument();
            var pagesize = new VA.Geometry.Size(4, 4);

            client.Page.NewPage(pagesize, false);

            var s1 = client.Draw.DrawRectangle(1, 1, 1.25, 1.5);

            var s2 = client.Draw.DrawRectangle(2, 3, 2.5, 3.5);

            var s3 = client.Draw.DrawRectangle(4.5, 2.5, 6, 3.5);

            client.Selection.SelectNone();
            client.Selection.SelectShapesById(s1);
            client.Selection.SelectShapesById(s2);
            client.Selection.SelectShapesById(s3);

            client.Document.OpenStencilDocument("basic_u.vss");
            var connec_stencil        = client.Document.OpenStencilDocument("connec_u.vss");
            var connec_tdoc           = new VisioScripting.TargetDocument(connec_stencil);
            var master                = client.Master.GetMaster(connec_tdoc, "Dynamic Connector");
            var undirected_connectors = client.Connection.ConnectShapes(new [] { s1, s2 }, new [] { s2, s3 }, master);

            var options1 = new VisioAutomation.DocumentAnalysis.ConnectionAnalyzerOptions();

            options1.NoArrowsHandling = NoArrowsHandling.ExcludeEdge;

            var directed_edges0 = client.Connection.GetDirectedEdgesOnPage(new VisioScripting.TargetPage(), options1);

            Assert.AreEqual(0, directed_edges0.Count);

            var options2 = new VA.DocumentAnalysis.ConnectionAnalyzerOptions();

            options2.NoArrowsHandling = NoArrowsHandling.TreatEdgeAsBidirectional;

            var directed_edges1 = client.Connection.GetDirectedEdgesOnPage(new VisioScripting.TargetPage(), options2);

            Assert.AreEqual(4, directed_edges1.Count);

            var options3 = new VA.DocumentAnalysis.ConnectionAnalyzerOptions();

            options3.DirectionSource = DirectionSource.UseConnectionOrder;

            var undirected_edges0 = client.Connection.GetDirectedEdgesOnPage(new VisioScripting.TargetPage(), options3);

            Assert.AreEqual(2, undirected_edges0.Count);

            var targetdoc = new VisioScripting.TargetDocument();

            client.Document.CloseDocument(targetdoc, true);
        }
        public static List <ConnectorEdge> GetDirectedEdgesTransitive(
            IVisio.Page page,
            ConnectionAnalyzerOptions options)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException(nameof(page));
            }

            var directed_edges = ConnectionAnalyzer.GetDirectedEdges(page, options)
                                 .Select(e => new DirectedEdge <IVisio.Shape, IVisio.Shape>(e.From, e.To, e.Connector));

            var closure = ConnectionAnalyzer.GetClosureFromEdges(directed_edges)
                          .Select(x => new ConnectorEdge(null, x.From, x.To)).ToList();

            return(closure);
        }
        public void Scripting_Connects_Scenario_0()
        {
            var client = this.GetScriptingClient();

            client.Document.NewDocument();
            var pagesize = new VA.Geometry.Size(4, 4);

            client.Page.NewPage(pagesize, false);

            var s1 = client.Draw.DrawRectangle(1, 1, 1.25, 1.5);
            var s2 = client.Draw.DrawRectangle(2, 3, 2.5, 3.5);
            var s3 = client.Draw.DrawRectangle(4.5, 2.5, 6, 3.5);

            client.Selection.SelectNone();
            client.Selection.SelectShapesById(s1);
            client.Selection.SelectShapesById(s2);
            client.Selection.SelectShapesById(s3);

            client.Document.OpenStencilDocument("basic_u.vss");
            var connec_stencil = client.Document.OpenStencilDocument("connec_u.vss");

            var tdoc                = new VisioScripting.TargetDocument(connec_stencil);
            var master              = client.Master.GetMaster(tdoc, "Dynamic Connector");
            var fromshapes          = new [] { s1, s2 };
            var toshapes            = new [] { s2, s3 };
            var directed_connectors = client.Connection.ConnectShapes(fromshapes, toshapes, master);

            client.Selection.SelectNone();
            client.Selection.SelectShapes(directed_connectors);

            var page   = new VisioScripting.TargetPage();
            var writer = client.ShapeSheet.GetWriterForPage(page);

            var shapes = client.Selection.GetShapesInSelection();

            foreach (var shape in shapes)
            {
                writer.SetFormula(shape.ID16, VA.ShapeSheet.SrcConstants.LineEndArrow, "13");
            }
            writer.Commit();

            var options0 = new VA.DocumentAnalysis.ConnectionAnalyzerOptions();

            options0.DirectionSource = DirectionSource.UseConnectionOrder;
            var undirected_edges0 = client.Connection.GetDirectedEdgesOnPage(new VisioScripting.TargetPage(), options0);

            Assert.AreEqual(2, undirected_edges0.Count);

            var options1 = new VA.DocumentAnalysis.ConnectionAnalyzerOptions();

            options1.NoArrowsHandling = NoArrowsHandling.ExcludeEdge;

            var options2 = new VA.DocumentAnalysis.ConnectionAnalyzerOptions();

            options2.NoArrowsHandling = NoArrowsHandling.TreatEdgeAsBidirectional;

            var directed_edges0 = client.Connection.GetDirectedEdgesOnPage(new VisioScripting.TargetPage(), options1);

            Assert.AreEqual(2, directed_edges0.Count);

            var directed_edges1 = client.Connection.GetDirectedEdgesOnPage(new VisioScripting.TargetPage(), options2);

            Assert.AreEqual(2, directed_edges1.Count);

            var targetdoc = new VisioScripting.TargetDocument();

            client.Document.CloseDocument(targetdoc, true);
        }
        /// <summary>
        /// Returns all the directed,connected pairs of shapes in the  page
        /// </summary>
        /// <param name="page"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static List <ConnectorEdge> GetDirectedEdges(
            IVisio.Page page,
            ConnectionAnalyzerOptions options)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException(nameof(page));
            }

            var edges = ConnectionAnalyzer._get_directed_edges_raw(page);

            if (options.DirectionSource == DirectionSource.UseConnectionOrder)
            {
                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 = ShapeSheet.SrcConstants.LineBeginArrow;
            var src_endarrow   = ShapeSheet.SrcConstants.LineEndArrow;

            var query                = new VASS.Query.CellQuery();
            var col_beginarrow       = query.Columns.Add(src_beginarrow, nameof(VASS.SrcConstants.LineBeginArrow));
            var col_endarrow         = query.Columns.Add(src_endarrow, nameof(VASS.SrcConstants.LineEndArrow));
            var listof_connectorinfo = query.GetResults <int>(page, connnector_ids);

            var directed_edges = new List <ConnectorEdge>();

            int connector_index = 0;

            foreach (var edge in edges)
            {
                var connector_info = listof_connectorinfo[connector_index];
                int beginarrow     = connector_info[col_beginarrow];
                int endarrow       = connector_info[col_endarrow];

                if ((beginarrow < 1) && (endarrow < 1))
                {
                    // the line has no arrows
                    if (options.NoArrowsHandling == NoArrowsHandling.TreatEdgeAsBidirectional)
                    {
                        // in this case treat the connector as pointing in both directions
                        var de1 = new ConnectorEdge(edge.Connector, edge.To, edge.From);
                        var de2 = new ConnectorEdge(edge.Connector, edge.From, edge.To);
                        directed_edges.Add(de1);
                        directed_edges.Add(de2);
                    }
                    else if (options.NoArrowsHandling == NoArrowsHandling.ExcludeEdge)
                    {
                        // in this case ignore the connector completely
                    }
                    else
                    {
                        throw new System.ArgumentOutOfRangeException(nameof(options));
                    }
                }
                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(edge.Connector, edge.To, edge.From);
                        directed_edges.Add(de);
                    }

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

                connector_index++;
            }

            return(directed_edges);
        }