]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/routing/TrivialRouter.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / routing / TrivialRouter.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g2d.routing;\r
13 \r
14 import java.awt.geom.Path2D;\r
15 \r
16 public class TrivialRouter implements IRouter {\r
17 \r
18     @Override\r
19     public void update(IGraphModel model) {\r
20         for(Object c : model.getConnections()) {\r
21             Terminal begin = model.getBeginTerminal(c);            \r
22             Terminal end = model.getEndTerminal(c);\r
23             double[] routePoints = model.getRoutePoints(c);\r
24             \r
25             Path2D path = new Path2D.Double();\r
26             int i=0;\r
27             if(begin != null)\r
28                 path.moveTo(begin.x, begin.y);\r
29             else if(routePoints.length >= 2) {\r
30                 path.moveTo(routePoints[0], routePoints[1]);\r
31                 i = 2;\r
32             }\r
33             for(;i<routePoints.length;i += 2)\r
34                 path.lineTo(routePoints[i], routePoints[i+1]);\r
35             if(end != null)\r
36                 path.lineTo(end.x, end.y);\r
37             \r
38             model.setPath(c, path);\r
39         }\r
40     }\r
41 \r
42 }\r