protected GeometryGraph LoadGraph(string geometryGraphFileName, out LayoutAlgorithmSettings settings)
        {
            if (string.IsNullOrEmpty(geometryGraphFileName))
            {
                throw new ArgumentNullException("geometryGraphFileName");
            }

            GeometryGraph graph = null;

            settings = null;
            if (geometryGraphFileName.EndsWith(".geom"))
            {
                graph = GeometryGraphReader.CreateFromFile(geometryGraphFileName, out settings);
                SetupPorts(graph);
            }
            else if (geometryGraphFileName.EndsWith(".dot"))
            {
                int           line;
                string        msg;
                int           col;
                Drawing.Graph drawingGraph = Parser.Parse(geometryGraphFileName, out line, out col, out msg);
                drawingGraph.CreateGeometryGraph();
                graph    = drawingGraph.GeometryGraph;
                settings = drawingGraph.CreateLayoutSettings();
                GraphGenerator.SetRandomNodeShapes(graph, new Random(1));
            }
            else
            {
                Assert.Fail("Unknown graph format for file: " + geometryGraphFileName);
            }

            TestContext.WriteLine("Loaded graph: {0} Nodes, {1} Edges", graph.Nodes.Count, graph.Edges.Count);
            return(graph);
        }
Exemplo n.º 2
0
        internal RectilinearEdgeRouterWrapper RunGeomGraphWithFreePorts(string fileName, bool loadOnly)
        {
            var geomGraph = GeometryGraphReader.CreateFromFile(fileName);

            if (loadOnly)
            {
                return(null);
            }

            var router = createRouterFunc(geomGraph.Nodes.Select(node => new Shape(node.BoundaryCurve)));

            foreach (var edge in geomGraph.Edges)
            {
                // Use a null curve, for consistency with RectilinearVerifier.MakeAbsoluteObstaclePort
                // treatment of UseFreePortsForObstaclePorts.
                EdgeGeometry edgeGeom = edge.EdgeGeometry;
                edgeGeom.SourcePort = new FloatingPort(null, edge.Source.Center);
                edgeGeom.TargetPort = new FloatingPort(null, edge.Target.Center);
                router.AddEdgeGeometryToRoute(edgeGeom);
            }
            router.Run();
            if (null != ShowGraph)
            {
                ShowGraph(router);
            }
            return(router);
        }
Exemplo n.º 3
0
        void ReadGeomGraph()
        {
            geometryGraphReader = new GeometryGraphReader();
            geometryGraphReader.SetXmlReader(this.xmlReader);
            GeometryGraph geomGraph = geometryGraphReader.Read();

            BindTheGraphs(this.graph, geomGraph, graph.LayoutAlgorithmSettings);
        }
        public void BundlingWithGroups()
        {
            var graph    = GeometryGraphReader.CreateFromFile(GetGeomGraphFileName("graphWithGroups.msagl.geom"));
            var settings = new BundlingSettings();
            var router   = new SplineRouter(graph, 3, 1, Math.PI / 6, settings);

            router.Run();
        }
        public void ComplexGeomGraph()
        {
            var graph    = GeometryGraphReader.CreateFromFile(GetGeomGraphFileName("complex.msagl.geom"));
            var settings = new BundlingSettings();
            var br       = new SplineRouter(graph, 1, 1.5, Math.PI / 6, settings);

            br.Run();
        }
        public void BundlingBug1GeomGraph()
        {
#if TEST_MSAGL && TEST_MSAGL
            DisplayGeometryGraph.SetShowFunctions();
#endif
            var graph    = GeometryGraphReader.CreateFromFile(GetGeomGraphFileName("bug1.msagl.geom"));
            var settings = new BundlingSettings();
            var router   = new SplineRouter(graph, 0.1, 0.75, Math.PI / 6, settings);
            router.Run();
        }
Exemplo n.º 7
0
 private void ReadGeomGraph()
 {
     if (ReadBooleanElement(Tokens.GeometryGraphIsPresent))
     {
         GeometryGraphReader ggr = new GeometryGraphReader();
         ggr.SetXmlReader(this.xmlReader);
         GeometryGraph geomGraph = ggr.Read();
         BindTheGraphs(this.graph, geomGraph);
     }
 }
Exemplo n.º 8
0
        internal RectilinearEdgeRouterWrapper RunGeomGraph(string fileName, bool loadOnly)
        {
            var geomGraph = GeometryGraphReader.CreateFromFile(fileName);

            if (loadOnly)
            {
                return(null);
            }

            var nodeShapeMap = new Dictionary <Node, Shape>();

            foreach (Node node in geomGraph.Nodes)
            {
                Shape shape = RectilinearInteractiveEditor.CreateShapeWithRelativeNodeAtCenter(node);
                nodeShapeMap.Add(node, shape);
            }
            if (null != ShowShapes)
            {
                ShowShapes(nodeShapeMap.Values);
            }

            var router = createRouterFunc(nodeShapeMap.Values);

            if (!this.NoPorts)
            {
                foreach (var edge in geomGraph.Edges)
                {
                    EdgeGeometry edgeGeom = edge.EdgeGeometry;
                    edgeGeom.SourcePort = nodeShapeMap[edge.Source].Ports.First();
                    edgeGeom.TargetPort = nodeShapeMap[edge.Target].Ports.First();

                    // Remove any path results retrieved from the geom file.
                    edgeGeom.Curve = null;
                    if (edgeGeom.SourceArrowhead != null)
                    {
                        edgeGeom.SourceArrowhead.TipPosition = new Point();
                    }
                    if (edgeGeom.TargetArrowhead != null)
                    {
                        edgeGeom.TargetArrowhead.TipPosition = new Point();
                    }
                    router.AddEdgeGeometryToRoute(edgeGeom);
                }
            }
            if (null != ShowInitialObstacles)
            {
                ShowInitialObstacles(router);
            }
            router.Run();
            if (null != ShowGraph)
            {
                ShowGraph(router);
            }
            return(router);
        }
Exemplo n.º 9
0
        public void SerializeDeserialize()
        {
            // Create settings that are different from the defaults
            SugiyamaLayoutSettings oldSettings = new SugiyamaLayoutSettings();

            oldSettings.AspectRatio++;
            oldSettings.LayerSeparation++;
            oldSettings.RepetitionCoefficientForOrdering++;
            oldSettings.RandomSeedForOrdering++;
            oldSettings.NoGainAdjacentSwapStepsBound++;
            oldSettings.MaxNumberOfPassesInOrdering++;
            oldSettings.GroupSplit++;
            oldSettings.LabelCornersPreserveCoefficient++;
            oldSettings.BrandesThreshold++;
            oldSettings.MinimalWidth++;
            oldSettings.MinimalHeight++;
            oldSettings.NodeSeparation++;
            oldSettings.MinNodeHeight++;
            oldSettings.MinNodeWidth++;
            oldSettings.LayeringOnly = !oldSettings.LayeringOnly;

            // Serialize
            GeometryGraph oldGraph = new GeometryGraph();

            oldGraph.Nodes.Add(new Node());
            GeometryGraphWriter.Write(oldGraph, oldSettings, "settings.msagl.geom");

            // Deserialize
            LayoutAlgorithmSettings baseSettings;

            GeometryGraphReader.CreateFromFile("settings.msagl.geom", out baseSettings);
            SugiyamaLayoutSettings newSettings = (SugiyamaLayoutSettings)baseSettings;

            // Verify
            Assert.AreEqual(oldSettings.AspectRatio, newSettings.AspectRatio, "AspectRatio was not serialized correctly.");
            Assert.AreEqual(oldSettings.LayerSeparation, newSettings.LayerSeparation, "LayerSeparation was not serialized correctly.");
            Assert.AreEqual(oldSettings.LayeringOnly, newSettings.LayeringOnly, "LayeringOnly was not serialized correctly.");
            Assert.AreEqual(oldSettings.RepetitionCoefficientForOrdering, newSettings.RepetitionCoefficientForOrdering, "RepetitionCoefficientForOrdering was not serialized correctly.");
            Assert.AreEqual(oldSettings.RandomSeedForOrdering, newSettings.RandomSeedForOrdering, "RandomSeedForOrdering was not serialized correctly.");
            Assert.AreEqual(oldSettings.NoGainAdjacentSwapStepsBound, newSettings.NoGainAdjacentSwapStepsBound, "NoGainAdjacentSwapStepsBound was not serialized correctly.");
            Assert.AreEqual(oldSettings.MaxNumberOfPassesInOrdering, newSettings.MaxNumberOfPassesInOrdering, "MaxNumberOfPassesInOrdering was not serialized correctly.");
            Assert.AreEqual(oldSettings.GroupSplit, newSettings.GroupSplit, "GroupSplit was not serialized correctly.");
            Assert.AreEqual(oldSettings.LabelCornersPreserveCoefficient, newSettings.LabelCornersPreserveCoefficient, "LabelCornersPreserveCoefficient was not serialized correctly.");
            Assert.AreEqual(oldSettings.BrandesThreshold, newSettings.BrandesThreshold, "BrandesThreshold was not serialized correctly.");
            Assert.AreEqual(oldSettings.MinimalWidth, newSettings.MinimalWidth, "MinimalWidth was not serialized correctly.");
            Assert.AreEqual(oldSettings.MinimalHeight, newSettings.MinimalHeight, "MinimalHeight was not serialized correctly.");
            Assert.AreEqual(oldSettings.NodeSeparation, newSettings.NodeSeparation, "NodeSeparation was not serialized correctly.");
            Assert.AreEqual(oldSettings.MinNodeHeight, newSettings.MinNodeHeight, "MinNodeHeight was not serialized correctly.");
            Assert.AreEqual(oldSettings.MinNodeWidth, newSettings.MinNodeWidth, "MinNodeWidth was not serialized correctly.");
        }
Exemplo n.º 10
0
 int ProcessMsaglFile(string inputFile)
 {
     try {
         LayoutAlgorithmSettings ls;
         var geomGraph = GeometryGraphReader.CreateFromFile(inputFile, out ls);
         if (ls == null)
         {
             ls = PickLayoutAlgorithmSettings(geomGraph.Edges.Count, geomGraph.Nodes.Count);
         }
         LayoutHelpers.CalculateLayout(geomGraph, ls, null);
         inputFile = SetMsaglOutputFileName(inputFile);
         WriteGeomGraph(inputFile, geomGraph);
         DumpFileToConsole(inputFile);
     }
     catch (Exception e) {
         //Console.WriteLine(e.ToString());
         Console.WriteLine(e.Message);
         return(-1);
     }
     return(0);
 }
Exemplo n.º 11
0
        public static void RsmContentFromDisc()
        {
            int ntest  = 10000;
            int iStart = 1; // 470;

#if TEST_MSAGL && TEST_MSAGL
            DisplayGeometryGraph.SetShowFunctions();
#endif
            var graph = GeometryGraphReader.CreateFromFile(@"c:\tmp\graph0.msagl.geom");

            for (int i = iStart; i < ntest; i++)
            {
                Random random = new Random(i);

                double edgeSeparation = 5 * random.NextDouble();
                System.Diagnostics.Debug.WriteLine("i={0} es={1}", i, edgeSeparation);
                RouteEdges(graph, edgeSeparation);
                // DisplayGeometryGraph.ShowGraph(graph);

                //TODO: try to move it
            }
        }
Exemplo n.º 12
0
        static void Main()
        {
#if TEST
            DisplayGeometryGraph.SetShowFunctions();
#else
            System.Diagnostics.Debug.WriteLine("run the Debug version to see the edge routes");
#endif
            var graph = GeometryGraphReader.CreateFromFile("channel.msagl.geom");
            foreach (var edge in graph.Edges)
            {
                if (edge.SourcePort == null)
                {
                    edge.SourcePort = new FloatingPort(edge.Source.BoundaryCurve, edge.Source.Center);
                }
                if (edge.TargetPort == null)
                {
                    edge.TargetPort = new FloatingPort(edge.Target.BoundaryCurve, edge.Target.Center);
                }
            }

            DemoEdgeRouterHelper(graph);
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
#if TEST_MSAGL
            DisplayGeometryGraph.SetShowFunctions();
#endif
            ArgsParser.ArgsParser argsParser = SetArgsParser(args);
            if (argsParser.OptionIsUsed("-help"))
            {
                Console.WriteLine(argsParser.UsageString());
                Environment.Exit(0);
            }
            if (argsParser.OptionIsUsed(PolygonDistanceTestOption))
            {
                TestPolygonDistance();
            }
            else if (argsParser.OptionIsUsed(TestCdtThreaderOption))
            {
                TestCdtThreader();
            }
            else if (argsParser.OptionIsUsed(RandomBundlingTest))
            {
                RandomBundlingTests.RsmContent();
            }


            bundling = argsParser.OptionIsUsed(BundlingOption);

            var gviewer = new GViewer();
            gviewer.MouseMove += Draw.GviewerMouseMove;
            if (argsParser.OptionIsUsed(FdOption))
            {
                TestFD();
                gviewer.CurrentLayoutMethod = LayoutMethod.IcrementalLayout;
            }
            Form form = CreateForm(null, gviewer);
            if (argsParser.OptionIsUsed(AsyncLayoutOption))
            {
                gviewer.AsyncLayout = true;
            }

            string listOfFilesFile = argsParser.GetStringOptionValue(ListOfFilesOption);
            if (listOfFilesFile != null)
            {
                ProcessListOfFiles(listOfFilesFile, argsParser);
                return;
            }
            string fileName = argsParser.GetStringOptionValue(FileOption);
            string ext      = Path.GetExtension(fileName);
            if (ext != null)
            {
                ext = ext.ToLower();
                if (ext == ".dot")
                {
                    ProcessDotFile(gviewer, argsParser, fileName);
                }
                else
                {
                    if (ext == ".geom")
                    {
                        GeometryGraph geometryGraph = GeometryGraphReader.CreateFromFile(fileName);
                        geometryGraph.Margins = 10;

                        FixHookPorts(geometryGraph);
                        // if (argsParser.OptionIsUsed(BundlingOption)) {
                        for (int i = 0; i < 1; i++)
                        {
#if TEST_MSAGL
                            /*DisplayGeometryGraph.ShowGraph(geometryGraph);
                             *  var l = new List<DebugCurve>(); l.AddRange(geometryGraph.Nodes.Select(n=>new DebugCurve(100,1,"black",n.BoundaryCurve)));
                             *  l.AddRange(geometryGraph.Edges.Select(e=>new DebugCurve(100,1,"black", new LineSegment(e.Source.Center,e.Target.Center))));
                             *  foreach (var cl in geometryGraph.RootCluster.AllClustersDepthFirst()) {
                             *      l.Add(new DebugCurve(100,2,"blue",cl.BoundaryCurve));
                             *      foreach (var node in cl.Nodes)
                             *          l.Add(new DebugCurve(100, 2, "brown", node.BoundaryCurve));
                             *
                             *      foreach (var e in cl.Edges)
                             *          l.Add(new DebugCurve(100, 2, "pink", new LineSegment(e.Source.Center, e.Target.Center)));
                             *
                             *  }
                             *
                             *  DisplayGeometryGraph.ShowDebugCurves(l.ToArray());*/
#endif
                            BundlingSettings bs = GetBundlingSettings(argsParser);

                            double loosePadding;
                            double tightPadding = GetPaddings(argsParser, out loosePadding);
                            if (argsParser.OptionIsUsed(MdsOption))
                            {
                                var mdsLayoutSettings = new MdsLayoutSettings {
                                    RemoveOverlaps = true, NodeSeparation = loosePadding * 3
                                };
                                var mdsLayout = new MdsGraphLayout(mdsLayoutSettings, geometryGraph);
                                mdsLayout.Run();
                            }
                            else
                            {
                                if (argsParser.OptionIsUsed(FdOption))
                                {
                                    var settings = new FastIncrementalLayoutSettings {
                                        AvoidOverlaps = true
                                    };
                                    (new InitialLayout(geometryGraph, settings)).Run();
                                }
                            }
                            var splineRouter = new SplineRouter(geometryGraph, geometryGraph.Edges, tightPadding,
                                                                loosePadding,
                                                                Math.PI / 6, bs);
                            splineRouter.Run();
                        }
#if TEST_MSAGL
                        DisplayGeometryGraph.ShowGraph(geometryGraph);
#endif
                        return;
                    }
                    else
                    {
                        if (ext == ".msagl")
                        {
                            Graph graph = Graph.Read(fileName);
                            //           DisplayGeometryGraph.ShowGraph(graph.GeometryGraph);
                            if (graph != null)
                            {
                                if (argsParser.OptionIsUsed(BundlingOption))
                                {
                                    BundlingSettings bs = GetBundlingSettings(argsParser);

                                    double loosePadding;
                                    double tightPadding = GetPaddings(argsParser, out loosePadding);
                                    var    br           = new SplineRouter(graph.GeometryGraph, tightPadding, loosePadding, Math.PI / 6,
                                                                           bs);
                                    br.Run();
                                    //                 DisplayGeometryGraph.ShowGraph(graph.GeometryGraph);
                                }
                            }
                            gviewer.NeedToCalculateLayout = false;
                            gviewer.Graph = graph;
                            gviewer.NeedToCalculateLayout = true;
                        }
                    }
                }
            }
            else if (argsParser.OptionIsUsed(TestCdtOption))
            {
                Triangulation(argsParser.OptionIsUsed(ReverseXOption));
                Environment.Exit(0);
            }
            else if (argsParser.OptionIsUsed(TestCdtOption0))
            {
                TestTriangulationOnSmallGraph(argsParser);
                Environment.Exit(0);
            }
            else if (argsParser.OptionIsUsed(TestCdtOption2))
            {
                TestTriangulationOnPolys();
                Environment.Exit(0);
            }
            else if (argsParser.OptionIsUsed(TestCdtOption1))
            {
                ThreadThroughCdt();
                Environment.Exit(0);
            }
            else if (argsParser.OptionIsUsed(ConstraintsTestOption))
            {
                TestGraphWithConstraints();
            }
            if (!argsParser.OptionIsUsed(QuietOption))
            {
                Application.Run(form);
            }
        }