static void TransferHorizontalConstraints(HorizontalConstraintsForLayeredLayout horizontalConstraints,
                                                  SugiyamaLayoutSettings sugiyamaLayoutSettings) {
            foreach (var couple in horizontalConstraints.UpDownVerticalConstraints)
                sugiyamaLayoutSettings.AddUpDownVerticalConstraint(couple.Item1.GeometryNode,
                                                                   couple.Item2.GeometryNode);
            foreach (var couple in horizontalConstraints.LeftRightConstraints)
                sugiyamaLayoutSettings.AddLeftRightConstraint(couple.Item1.GeometryNode,
                                                              couple.Item2.GeometryNode);

            foreach (var couple in horizontalConstraints.LeftRightNeighbors)
                sugiyamaLayoutSettings.AddSameLayerNeighbors(couple.Item1.GeometryNode,
                                                             couple.Item2.GeometryNode);
        }
Example #2
0
                public static void TreeWithConstraints() {
            var graph = new GeometryGraph();

            var closed = new Node(CreateEllipse(), "clos");
            var line = new Node(CreateEllipse(), "line");
            var bezier = new Node(CreateEllipse(), "bezi");
            var arc = new Node(CreateEllipse(), "arc");
            var rectangle = new Node(CreateEllipse(), "rect");
            var ellipse = new Node(CreateEllipse(), "elli");
            var polygon = new Node(CreateEllipse(), "poly");
            var shapes = new Node(CreateEllipse(), "shap");
            var open = new Node(CreateEllipse(), "open");
            graph.Nodes.Add(closed);
            graph.Nodes.Add(line);
            graph.Nodes.Add(bezier);
            graph.Nodes.Add(arc);
            graph.Nodes.Add(rectangle);
            graph.Nodes.Add(ellipse);
            graph.Nodes.Add(polygon);
            graph.Nodes.Add(shapes);
            graph.Nodes.Add(open);

            var so = new Edge(shapes, open);
            var sc = new Edge(shapes, closed);
            var ol = new Edge(open, line);
            var ob = new Edge(open, bezier);
            var oa = new Edge(open, arc);
            var cr = new Edge(closed, rectangle);
            var ce = new Edge(closed, ellipse);
            var cp = new Edge(closed, polygon);
            graph.Edges.Add(so);
            graph.Edges.Add(sc);
            graph.Edges.Add(ol);
            graph.Edges.Add(ob);
            graph.Edges.Add(oa);
            graph.Edges.Add(cr);
            graph.Edges.Add(ce);
            graph.Edges.Add(cp);

            var settings = new SugiyamaLayoutSettings();
            settings.AddUpDownVerticalConstraint(closed, ellipse);
            settings.AddUpDownVerticalConstraint(open, bezier);
            settings.AddUpDownConstraint(closed, open);
            settings.AddSameLayerNeighbors(polygon, open);
            settings.AddLeftRightConstraint(closed, open);

            settings.AddUpDownConstraint(closed, open);
            //settings.AddSameLayerNeighbors(polygon, open);
            settings.AddLeftRightConstraint(closed, open);

            //To verify 444585, just turn on this following commented line
            settings.AddLeftRightConstraint(ellipse, rectangle);
            settings.AddLeftRightConstraint(ellipse, bezier);

            var layeredLayout = new LayeredLayout(graph, settings);
            layeredLayout.Run();
#if DEBUG
            LayoutAlgorithmSettings.ShowGraph(graph);
#endif

            Debug.Assert(Math.Abs(closed.Center.X - ellipse.Center.X) < 0.01);
            Debug.Assert(Math.Abs(open.Center.X - bezier.Center.X) < 0.01);

            foreach (Node n0 in graph.Nodes) {
                foreach (Node n1 in graph.Nodes) {
                    if (n0 == n1) {
                        continue;
                    }
                    Debug.Assert(!n0.BoundingBox.Intersects(n1.BoundingBox));
                }
            }

            ValidateUpDownVerticalConstraint(closed, ellipse);
            ValidateUpDownVerticalConstraint(open, bezier);
            ValidateUpDownConstraint(closed, open);
            ValidateNeighborConstraint(graph, polygon, open);
            ValidateLeftRightConstraint(closed, open);

            //To verify 444585, also turn on this following commented line
            ValidateLeftRightConstraint(ellipse, rectangle);
            ValidateLeftRightConstraint(ellipse, bezier);
        }
        static void TestGraphWithConstraints() {
            var graph = new GeometryGraph();

            var closed = new Node(CreateEllipse(), "closed");
            var line = new Node(CreateEllipse(), "line");
            var bezier = new Node(CreateEllipse(), "bezier");
            var arc = new Node(CreateEllipse(), "arc");
            var rectangle = new Node(CreateEllipse(), "rectangle");
            var ellipse = new Node(CreateEllipse(), "ellipse");
            var polygon = new Node(CreateEllipse(), "polygon");
            var shapes = new Node(CreateEllipse(), "shapes");
            var open = new Node(CreateEllipse(), "open");
            graph.Nodes.Add(closed);
            graph.Nodes.Add(line);
            graph.Nodes.Add(bezier);
            graph.Nodes.Add(arc);
            graph.Nodes.Add(rectangle);
            graph.Nodes.Add(ellipse);
            graph.Nodes.Add(polygon);
            graph.Nodes.Add(shapes);
            graph.Nodes.Add(open);

            var so = new Edge(shapes, open);
            var sc = new Edge(shapes, closed);
            var ol = new Edge(open, line);
            var ob = new Edge(open, bezier);
            var oa = new Edge(open, arc);
            var cr = new Edge(closed, rectangle);
            var ce = new Edge(closed, ellipse);
            var cp = new Edge(closed, polygon);
            graph.Edges.Add(so);
            graph.Edges.Add(sc);
            graph.Edges.Add(ol);
            graph.Edges.Add(ob);
            graph.Edges.Add(oa);
            graph.Edges.Add(cr);
            graph.Edges.Add(ce);
            graph.Edges.Add(cp);

            var settings = new SugiyamaLayoutSettings();
            settings.AddUpDownVerticalConstraint(closed, ellipse);
            settings.AddUpDownVerticalConstraint(open, bezier);
            settings.AddUpDownConstraint(closed, open);
            settings.AddSameLayerNeighbors(polygon, open);
            settings.AddLeftRightConstraint(closed, open);
            settings.AddLeftRightConstraint(open, closed);

            ////To verify 444585, just turn on this following commented line
            settings.AddLeftRightConstraint(ellipse, rectangle);
            settings.AddLeftRightConstraint(ellipse, bezier);

            var layeredLayout = new LayeredLayout(graph, settings);
            layeredLayout.Run();
#if DEBUG
            DisplayGeometryGraph.ShowGraph(graph);
#endif
        }
        public void ConstraintWithTransformation()
        {
            Random random = new Random(999);

            GeometryGraph graph = GraphGenerator.GenerateOneSimpleGraph();            
            GraphGenerator.SetRandomNodeShapes(graph, random);
            SugiyamaLayoutSettings settings = new SugiyamaLayoutSettings();

            //layer direction to be left to right
            settings.Transformation = PlaneTransformation.Rotation(Math.PI / 2);

            List<Node> nodes = graph.Nodes.ToList();

            settings.AddUpDownConstraint(nodes[0], nodes[1]);
            settings.AddLeftRightConstraint(nodes[3], nodes[4]);
            settings.AddUpDownVerticalConstraint(nodes[0], nodes[3]);
            settings.AddSameLayerNeighbors(nodes[2], nodes[4]);

            LayeredLayout layeredLayout = new LayeredLayout(graph, settings);
            layeredLayout.Run();

            ShowGraphInDebugViewer(graph);

            SugiyamaValidation.ValidateUpDownConstraint(nodes[0], nodes[1]);
            SugiyamaValidation.ValidateLeftRightConstraint(nodes[3], nodes[4]);
            SugiyamaValidation.ValidateUpDownVerticalConstraint(nodes[0], nodes[3]);
            SugiyamaValidation.ValidateNeighborConstraint(graph, nodes[2], nodes[4], settings);
        }