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