private bool FindRoot()
        {
            HashSet <Representation.node> visitedLeaves = new HashSet <Representation.node>();

            Representation.designGraph copiedgraph = graph.copy();
            bool istree = true;

            while (istree == true && copiedgraph.nodes.Count > 1)
            {
                istree = false;
                for (var i = 0; i < copiedgraph.nodes.Count; i++)
                {
                    if (copiedgraph.nodes[i].arcsFrom.Count == 0)
                    {
                        for (var j = 0; (i < copiedgraph.nodes.Count) && (j < copiedgraph.nodes[i].arcsTo.Count); j++)
                        {
                            string removedname = copiedgraph.nodes[i].arcsTo[j].To.name;
                            copiedgraph.removeNode(copiedgraph.nodes[i].arcsTo[j].To, false);

                            for (var l = 0; l < copiedgraph.arcs.Count; l++)
                            {
                                if (copiedgraph.arcs[l].To != null)
                                {
                                    if (copiedgraph.arcs[l].To.name == removedname)
                                    {
                                        copiedgraph.removeArc(copiedgraph.arcs[l]);
                                    }
                                }
                            }
                            istree = true;
                        }
                        break;
                    }
                }
            }

            if (istree == false)
            {
                throw new Exception("This graph layout can only be run on trees.");
                //return false;
            }
            var k = 0;

            for (k = 0; copiedgraph.nodes[0].name != graph.nodes[k].name; k++)
            {
            }
            root = k;

            return(true);
        }
Beispiel #2
0
        protected override bool RunLayout()
        {
            HashSet <Representation.node> visitedLeaves = new HashSet <Representation.node>();

            Representation.designGraph copiedgraph = graph.copy();
            bool istree = true;


            while (istree == true && copiedgraph.nodes.Count > 1)
            {
                backgroundWorker.ReportProgress(100 - copiedgraph.nodes.Count);
                if (backgroundWorker.CancellationPending)
                {
                    return(false);
                }
                istree = false;
                for (var i = 0; i < copiedgraph.nodes.Count; i++)
                {
                    if (copiedgraph.nodes[i].arcsFrom.Count == 0)
                    {
                        for (var j = 0; (i < copiedgraph.nodes.Count) && (j < copiedgraph.nodes[i].arcsTo.Count); j++)
                        {
                            string removedname = copiedgraph.nodes[i].arcsTo[j].To.name;
                            copiedgraph.removeNode(copiedgraph.nodes[i], false);

                            for (var l = 0; l < copiedgraph.arcs.Count; l++)
                            {
                                if (copiedgraph.arcs[l].To != null)
                                {
                                    if (copiedgraph.arcs[l].To.name == removedname)
                                    {
                                        copiedgraph.removeArc(copiedgraph.arcs[l]);
                                    }
                                }
                            }
                            istree = true;
                        }
                        break;
                    }
                }
            }

            if (istree == false)
            {
                backgroundWorker.ReportProgress(100);
                throw new Exception("The input graph is not a tree. This layout only works on tree structures.");
            }
            //return;

            var k      = 0;
            var x_dist = 0;

            for (k = 0; k < copiedgraph.nodes.Count; k++)
            {
                for (var l = 0; l < graph.nodes.Count; l++)
                {
                    if (copiedgraph.nodes[k].name == graph.nodes[l].name)
                    {
                        graph.nodes[l].X = x_dist;
                        graph.nodes[l].Y = 0;
                        outputchild(graph.nodes[l], x_dist, 0);
                        x_dist = x_dist + (int)HorizontalSpacing;
                        break;
                    }
                }
            }
            return(true);
        }