1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.routing.algorithm1;
14 import java.awt.geom.Path2D;
15 import java.awt.geom.Rectangle2D;
16 import java.util.ArrayList;
17 import java.util.Arrays;
18 import java.util.Comparator;
19 import java.util.HashMap;
20 import java.util.HashSet;
24 import org.simantics.g2d.routing.Connection;
25 import org.simantics.g2d.routing.IRouterOld;
26 import org.simantics.g2d.routing.Obstacle;
28 public class RouterOld implements IRouterOld {
30 Map<Connection, Path2D> connections = new HashMap<Connection, Path2D>();
31 Set<Obstacle> obstacles = new HashSet<Obstacle>();
32 boolean dirty = false;
35 public void addObstacle(Obstacle obstacle) {
36 obstacles.add(obstacle);
41 public void removeObstacle(Obstacle obstacle) {
42 obstacles.remove(obstacle);
47 public void addConnection(Connection connection) {
48 connections.put(connection, null);
53 public void removeConnection(Connection connection) {
54 connections.remove(connection);
59 public Path2D getPath(Connection connection) {
63 long beginTime = System.nanoTime();
65 long endTime = System.nanoTime();
66 System.out.println((endTime-beginTime)*1e-6 + "ms");
71 return connections.get(connection);
74 private void update() {
75 ArrayList<Rectangle> rectangles = new ArrayList<Rectangle>(obstacles.size());
76 for(Obstacle obs : obstacles) {
77 Rectangle2D shape = obs.shape;
78 rectangles.add(new Rectangle(
85 connections.keySet().toArray(new Connection[connections.size()]);
86 Arrays.sort(carray, new Comparator<Connection>() {
89 public int compare(Connection o1, Connection o2) {
90 double l1 = o1.minLength();
91 double l2 = o2.minLength();
96 if(o1.routePath.length < o2.routePath.length)
98 if(o1.routePath.length > o2.routePath.length)
100 for(int i=0;i<o1.routePath.length;++i) {
101 if(o1.routePath[i] < o2.routePath[i])
103 if(o1.routePath[i] > o2.routePath[i])
110 //System.out.println("----------------------------------------------------------");
111 ArrayList<Path2D> lines = new ArrayList<Path2D>(connections.size());
112 for(Connection c : carray) {
113 // StaticRouter router = new StaticRouter(rectangles, lines);
114 // Path2D path = router.route(c);
115 // connections.put(c, path);