]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/routing/algorithm1/RouterOld.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / routing / algorithm1 / RouterOld.java
index aa82c5c4b21e9e07d15fef2be8148180c9907188..881957e709e9745d94e4240c561f3cb2a5570bed 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.g2d.routing.algorithm1;\r
-\r
-import java.awt.geom.Path2D;\r
-import java.awt.geom.Rectangle2D;\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.Comparator;\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
-import java.util.Map;\r
-import java.util.Set;\r
-\r
-import org.simantics.g2d.routing.Connection;\r
-import org.simantics.g2d.routing.IRouterOld;\r
-import org.simantics.g2d.routing.Obstacle;\r
-\r
-public class RouterOld implements IRouterOld {\r
-\r
-       Map<Connection, Path2D> connections = new HashMap<Connection, Path2D>();\r
-       Set<Obstacle> obstacles = new HashSet<Obstacle>();\r
-       boolean dirty = false;  \r
-\r
-       @Override\r
-       public void addObstacle(Obstacle obstacle) {\r
-               obstacles.add(obstacle);\r
-               dirty = true;\r
-       }\r
-       \r
-       @Override\r
-       public void removeObstacle(Obstacle obstacle) {\r
-               obstacles.remove(obstacle);\r
-               dirty = true;           \r
-       }\r
-       \r
-       @Override\r
-       public void addConnection(Connection connection) {\r
-               connections.put(connection, null);\r
-               dirty = true;\r
-       }\r
-       \r
-       @Override\r
-       public void removeConnection(Connection connection) {\r
-               connections.remove(connection);\r
-               dirty = true;           \r
-       }       \r
-\r
-       @Override\r
-       public Path2D getPath(Connection connection) {\r
-               if(dirty) {\r
-                       synchronized(this) {\r
-                               if(dirty) {\r
-                                       long beginTime = System.nanoTime();\r
-                                       update();\r
-                                       long endTime = System.nanoTime();\r
-                                       System.out.println((endTime-beginTime)*1e-6 + "ms");\r
-                                       dirty = false;\r
-                               }\r
-                       }\r
-               }\r
-               return connections.get(connection);\r
-       }\r
-\r
-       private void update() {\r
-               ArrayList<Rectangle> rectangles = new ArrayList<Rectangle>(obstacles.size());\r
-               for(Obstacle obs : obstacles) {\r
-                       Rectangle2D shape = obs.shape;\r
-                       rectangles.add(new Rectangle(\r
-                               shape.getMinX(),\r
-                               shape.getMinY(),\r
-                               shape.getMaxX(),\r
-                               shape.getMaxY()));\r
-               }\r
-               Connection[] carray = \r
-                       connections.keySet().toArray(new Connection[connections.size()]);\r
-               Arrays.sort(carray, new Comparator<Connection>() {\r
-\r
-                       @Override\r
-                       public int compare(Connection o1, Connection o2) {\r
-                               double l1 = o1.minLength();\r
-                               double l2 = o2.minLength();\r
-                               if(l1 < l2)\r
-                                       return -1;\r
-                               if(l1 > l2)\r
-                                       return 1;\r
-                               if(o1.routePath.length < o2.routePath.length)\r
-                                       return -1;\r
-                               if(o1.routePath.length > o2.routePath.length)\r
-                                       return 1;\r
-                               for(int i=0;i<o1.routePath.length;++i) {\r
-                                       if(o1.routePath[i] < o2.routePath[i])\r
-                                               return -1;\r
-                                       if(o1.routePath[i] > o2.routePath[i])\r
-                                               return 1;\r
-                               }\r
-                               return 0;\r
-                       }\r
-                       \r
-               });\r
-               //System.out.println("----------------------------------------------------------");\r
-               ArrayList<Path2D> lines = new ArrayList<Path2D>(connections.size());            \r
-               for(Connection c : carray) {\r
-//                     StaticRouter router = new StaticRouter(rectangles, lines);\r
-//                     Path2D path = router.route(c);\r
-//                     connections.put(c, path);\r
-//                     if(path != null)\r
-//                             lines.add(path);\r
-               }\r
-       }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.g2d.routing.algorithm1;
+
+import java.awt.geom.Path2D;
+import java.awt.geom.Rectangle2D;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.simantics.g2d.routing.Connection;
+import org.simantics.g2d.routing.IRouterOld;
+import org.simantics.g2d.routing.Obstacle;
+
+public class RouterOld implements IRouterOld {
+
+       Map<Connection, Path2D> connections = new HashMap<Connection, Path2D>();
+       Set<Obstacle> obstacles = new HashSet<Obstacle>();
+       boolean dirty = false;  
+
+       @Override
+       public void addObstacle(Obstacle obstacle) {
+               obstacles.add(obstacle);
+               dirty = true;
+       }
+       
+       @Override
+       public void removeObstacle(Obstacle obstacle) {
+               obstacles.remove(obstacle);
+               dirty = true;           
+       }
+       
+       @Override
+       public void addConnection(Connection connection) {
+               connections.put(connection, null);
+               dirty = true;
+       }
+       
+       @Override
+       public void removeConnection(Connection connection) {
+               connections.remove(connection);
+               dirty = true;           
+       }       
+
+       @Override
+       public Path2D getPath(Connection connection) {
+               if(dirty) {
+                       synchronized(this) {
+                               if(dirty) {
+                                       long beginTime = System.nanoTime();
+                                       update();
+                                       long endTime = System.nanoTime();
+                                       System.out.println((endTime-beginTime)*1e-6 + "ms");
+                                       dirty = false;
+                               }
+                       }
+               }
+               return connections.get(connection);
+       }
+
+       private void update() {
+               ArrayList<Rectangle> rectangles = new ArrayList<Rectangle>(obstacles.size());
+               for(Obstacle obs : obstacles) {
+                       Rectangle2D shape = obs.shape;
+                       rectangles.add(new Rectangle(
+                               shape.getMinX(),
+                               shape.getMinY(),
+                               shape.getMaxX(),
+                               shape.getMaxY()));
+               }
+               Connection[] carray = 
+                       connections.keySet().toArray(new Connection[connections.size()]);
+               Arrays.sort(carray, new Comparator<Connection>() {
+
+                       @Override
+                       public int compare(Connection o1, Connection o2) {
+                               double l1 = o1.minLength();
+                               double l2 = o2.minLength();
+                               if(l1 < l2)
+                                       return -1;
+                               if(l1 > l2)
+                                       return 1;
+                               if(o1.routePath.length < o2.routePath.length)
+                                       return -1;
+                               if(o1.routePath.length > o2.routePath.length)
+                                       return 1;
+                               for(int i=0;i<o1.routePath.length;++i) {
+                                       if(o1.routePath[i] < o2.routePath[i])
+                                               return -1;
+                                       if(o1.routePath[i] > o2.routePath[i])
+                                               return 1;
+                               }
+                               return 0;
+                       }
+                       
+               });
+               //System.out.println("----------------------------------------------------------");
+               ArrayList<Path2D> lines = new ArrayList<Path2D>(connections.size());            
+               for(Connection c : carray) {
+//                     StaticRouter router = new StaticRouter(rectangles, lines);
+//                     Path2D path = router.route(c);
+//                     connections.put(c, path);
+//                     if(path != null)
+//                             lines.add(path);
+               }
+       }
+}