Changeset 23571 in osm for applications/editors/josm/plugins/turnrestrictions
- Timestamp:
- 2010-10-12T16:31:47+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/turnrestrictions
- Files:
-
- 5 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/turnrestrictions/build.xml
r23559 r23571 39 39 ** should not be necessary to change the following properties 40 40 --> 41 <property name="josm" location="../../core/dist/josm-custom.jar"/>42 <property name="plugin.build.dir" value="build"/>43 <property name="plugin.src.dir" value="src"/>41 <property name="josm" location="../../core/dist/josm-custom.jar" /> 42 <property name="plugin.build.dir" value="build" /> 43 <property name="plugin.src.dir" value="src" /> 44 44 <!-- this is the directory where the plugin jar is copied to --> 45 <property name="plugin.dist.dir" value="dist"/>46 <property name="ant.build.javac.target" value="1.6" />47 <property name="plugin.jar" value="../../dist/${ant.project.name}.jar"/>48 <property name="test.build.dir"value="test/build" />45 <property name="plugin.dist.dir" value="dist" /> 46 <property name="ant.build.javac.target" value="1.6" /> 47 <property name="plugin.jar" value="../../dist/${ant.project.name}.jar" /> 48 <property name="test.build.dir" value="test/build" /> 49 49 <!-- 50 50 ********************************************************** … … 53 53 --> 54 54 <target name="init"> 55 <mkdir dir="${plugin.build.dir}" />56 <mkdir dir="${test.build.dir}" />55 <mkdir dir="${plugin.build.dir}" /> 56 <mkdir dir="${test.build.dir}" /> 57 57 </target> 58 58 … … 63 63 --> 64 64 <target name="compile" depends="init"> 65 <echo message="compiling sources for ${plugin.jar} ... " />65 <echo message="compiling sources for ${plugin.jar} ... " /> 66 66 <javac srcdir="src" classpath="${josm}" debug="true" destdir="${plugin.build.dir}"> 67 <compilerarg value="-Xlint:deprecation" />68 <compilerarg value="-Xlint:unchecked" />67 <compilerarg value="-Xlint:deprecation" /> 68 <compilerarg value="-Xlint:unchecked" /> 69 69 </javac> 70 70 </target> … … 76 76 --> 77 77 <target name="dist" depends="compile,revision"> 78 <echo message="creating ${ant.project.name}.jar ... " />78 <echo message="creating ${ant.project.name}.jar ... " /> 79 79 <copy todir="${plugin.build.dir}/resources"> 80 <fileset dir="resources" />80 <fileset dir="resources" /> 81 81 </copy> 82 82 <copy todir="${plugin.build.dir}/images"> 83 <fileset dir="images" />83 <fileset dir="images" /> 84 84 </copy> 85 85 <copy todir="${plugin.build.dir}"> … … 99 99 --> 100 100 <manifest> 101 <attribute name="Author" value="Karl Guggisberg" />102 <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.turnrestrictions.TurnRestrictionsPlugin" />103 <attribute name="Plugin-Date" value="${version.entry.commit.date}" />104 <attribute name="Plugin-Description" value="The turnrestrictions plugin allows to enter maintain information about turn restrictions in the OpenStreetMap database." />105 <attribute name="Plugin-Icon" value="images/preferences/turnrestrictions.png" />106 <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/wiki/JOSM/Plugins/turnrestrictions" />107 <attribute name="Plugin-Mainversion" value="${plugin.main.version}" />108 <attribute name="Plugin-Version" value="${version.entry.commit.revision}" />101 <attribute name="Author" value="Karl Guggisberg" /> 102 <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.turnrestrictions.TurnRestrictionsPlugin" /> 103 <attribute name="Plugin-Date" value="${version.entry.commit.date}" /> 104 <attribute name="Plugin-Description" value="The turnrestrictions plugin allows to enter maintain information about turn restrictions in the OpenStreetMap database." /> 105 <attribute name="Plugin-Icon" value="images/preferences/turnrestrictions.png" /> 106 <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/wiki/JOSM/Plugins/turnrestrictions" /> 107 <attribute name="Plugin-Mainversion" value="${plugin.main.version}" /> 108 <attribute name="Plugin-Version" value="${version.entry.commit.revision}" /> 109 109 </manifest> 110 110 </jar> … … 121 121 122 122 <exec append="false" output="REVISION" executable="svn" failifexecutionfails="false"> 123 <env key="LANG" value="C" />124 <arg value="info" />125 <arg value="--xml" />126 <arg value="." />127 </exec> 128 <xmlproperty file="REVISION" prefix="version" keepRoot="false" collapseAttributes="true" />129 <delete file="REVISION" />123 <env key="LANG" value="C" /> 124 <arg value="info" /> 125 <arg value="--xml" /> 126 <arg value="." /> 127 </exec> 128 <xmlproperty file="REVISION" prefix="version" keepRoot="false" collapseAttributes="true" /> 129 <delete file="REVISION" /> 130 130 </target> 131 131 … … 136 136 --> 137 137 <target name="clean"> 138 <delete dir="${plugin.build.dir}" />139 <delete file="${plugin.jar}" />138 <delete dir="${plugin.build.dir}" /> 139 <delete file="${plugin.jar}" /> 140 140 </target> 141 141 … … 146 146 --> 147 147 <target name="install" depends="dist"> 148 <property environment="env" />148 <property environment="env" /> 149 149 <condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins" else="${user.home}/.josm/plugins"> 150 150 <and> 151 <os family="windows" />151 <os family="windows" /> 152 152 </and> 153 153 </condition> 154 <copy file="${plugin.jar}" todir="${josm.plugins.dir}" />154 <copy file="${plugin.jar}" todir="${josm.plugins.dir}" /> 155 155 </target> 156 156 … … 165 165 <target name="core-info"> 166 166 <exec append="false" output="core.info.xml" executable="svn" failifexecutionfails="false"> 167 <env key="LANG" value="C" />168 <arg value="info" />169 <arg value="--xml" />170 <arg value="../../core" />171 </exec> 172 <xmlproperty file="core.info.xml" prefix="coreversion" keepRoot="true" collapseAttributes="true" />167 <env key="LANG" value="C" /> 168 <arg value="info" /> 169 <arg value="--xml" /> 170 <arg value="../../core" /> 171 </exec> 172 <xmlproperty file="core.info.xml" prefix="coreversion" keepRoot="true" collapseAttributes="true" /> 173 173 <echo>Building against core revision ${coreversion.info.entry.revision}.</echo> 174 174 <echo>Plugin-Mainversion is set to ${plugin.main.version}.</echo> … … 182 182 <echo>Commiting the plugin source with message '${commit.message}' ...</echo> 183 183 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 184 <env key="LANG" value="C" />185 <arg value="commit" />186 <arg value="-m '${commit.message}'" />187 <arg value="." />184 <env key="LANG" value="C" /> 185 <arg value="commit" /> 186 <arg value="-m '${commit.message}'" /> 187 <arg value="." /> 188 188 </exec> 189 189 </target> … … 195 195 <echo>Updating plugin source ...</echo> 196 196 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 197 <env key="LANG" value="C" />198 <arg value="up" />199 <arg value="." />197 <env key="LANG" value="C" /> 198 <arg value="up" /> 199 <arg value="." /> 200 200 </exec> 201 201 <echo>Updating ${plugin.jar} ...</echo> 202 202 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 203 <env key="LANG" value="C" />204 <arg value="up" />205 <arg value="../dist/${plugin.jar}" />203 <env key="LANG" value="C" /> 204 <arg value="up" /> 205 <arg value="../dist/${plugin.jar}" /> 206 206 </exec> 207 207 </target> … … 222 222 </echo> 223 223 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 224 <env key="LANG" value="C" />225 <arg value="-m '${commit.message}'" />226 <arg value="commit" />227 <arg value="${plugin.jar}" />224 <env key="LANG" value="C" /> 225 <arg value="-m '${commit.message}'" /> 226 <arg value="commit" /> 227 <arg value="${plugin.jar}" /> 228 228 </exec> 229 229 </target> … … 261 261 262 262 <path id="groovy.path"> 263 <pathelement location="${eclipse.plugin.dir}/org.codehaus.groovy_1.7.5.xx-20100926-2000-e36-RC1\lib\groovy-all-1.7.5.jar" />263 <pathelement location="${eclipse.plugin.dir}/org.codehaus.groovy_1.7.5.xx-20100926-2000-e36-RC1\lib\groovy-all-1.7.5.jar" /> 264 264 </path> 265 265 … … 269 269 270 270 <path id="test.class.path"> 271 <pathelement location="${josm}" />271 <pathelement location="${josm}" /> 272 272 <pathelement location="${plugin.build.dir}" /> 273 <path refid="groovy.path" />274 <path refid="junit.path" />273 <path refid="groovy.path" /> 274 <path refid="junit.path" /> 275 275 </path> 276 276 … … 287 287 288 288 <target name="test-clean"> 289 <delete dir="${test.build.dir}" />290 <mkdir dir="${test.build.dir}" />291 289 <delete dir="${test.build.dir}" /> 290 <mkdir dir="${test.build.dir}" /> 291 </target> 292 292 293 293 <target name="test-compile" depends="compile,test-clean" description="Compiles the test files"> 294 294 295 <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpathref="groovy.path" />296 297 <echo message="compiling java test cases for ${plugin.jar} ... "/>298 <javac srcdir="test/src" classpathref="test.class.path" debug="true" destdir="${test.build.dir}">299 <compilerarg value="-Xlint:deprecation"/>300 <compilerarg value="-Xlint:unchecked"/>301 302 303 <echo message="compiling groovy test cases for ${plugin.jar} ... " />295 <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpathref="groovy.path" /> 296 297 <echo message="compiling test infrastructor for ${plugin.jar} ... " /> 298 <javac srcdir="test/src" classpathref="test.class.path" debug="true" destdir="${test.build.dir}" includes="org/openstreetmap/josm/plugins/turnrestrictions/fixtures/**/*"> 299 <compilerarg value="-Xlint:deprecation" /> 300 <compilerarg value="-Xlint:unchecked" /> 301 </javac> 302 303 <echo message="compiling groovy test cases for ${plugin.jar} ... " /> 304 304 <groovyc srcdir="test/src" destdir="${test.build.dir}" classpathref="groovyc.path"> 305 305 </groovyc> 306 307 <echo message="compiling java test cases for ${plugin.jar} ... " /> 308 <javac srcdir="test/src" classpathref="test.class.path" debug="true" destdir="${test.build.dir}"> 309 <compilerarg value="-Xlint:deprecation" /> 310 <compilerarg value="-Xlint:unchecked" /> 311 </javac> 306 312 </target> 307 313 308 314 <target name="test-run" depends="test-compile" description="Runs the junit tests"> 309 <delete dir="test/output" />310 <mkdir dir="test/output" />315 <delete dir="test/output" /> 316 <mkdir dir="test/output" /> 311 317 312 318 <junit printsummary="true" failureproperty="junit.failure"> 313 <classpath> 314 <path refid="groovyc.path" /> 315 <pathelement location="test/config"/> <!-- required for test config file --> 316 <pathelement location="."/> <!-- required to load images from subdir 'images/' --> 317 </classpath> 318 319 <test todir="test/output" name='org.openstreetmap.josm.plugins.turnrestrictions.AllUnitTests'> 320 <formatter type="xml"/> 321 </test> 319 <classpath> 320 <path refid="groovyc.path" /> 321 <pathelement location="test/config" /> 322 <!-- required for test config file --> 323 <pathelement location="." /> 324 <!-- required to load images from subdir 'images/' --> 325 </classpath> 326 327 <test todir="test/output" name='org.openstreetmap.josm.plugins.turnrestrictions.AllUnitTests'> 328 <formatter type="xml" /> 329 </test> 322 330 </junit> 323 331 </target> -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/TurnRestrictionBuilder.java
r23510 r23571 2 2 3 3 import java.util.ArrayList; 4 import java.util.Collections; 4 5 import java.util.HashSet; 5 6 import java.util.List; … … 11 12 import org.openstreetmap.josm.data.osm.Way; 12 13 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 14 import org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionType; 13 15 import org.openstreetmap.josm.tools.CheckParameterUtil; 14 16 … … 20 22 */ 21 23 public class TurnRestrictionBuilder { 22 23 private Way from;24 private Way to;25 private final ArrayList<OsmPrimitive> vias = new ArrayList<OsmPrimitive>();26 24 27 25 public TurnRestrictionBuilder(){ 28 }29 30 /**31 * Initializes the 'from' leg. Proposes the first element32 * in {@code primitives} as 'from' leg if this element is a33 * non-deleted, visible way.34 *35 * @param primitives36 */37 protected void initFromLeg(List<OsmPrimitive> primitives){38 if (primitives == null || primitives.isEmpty()) return;39 OsmPrimitive p = primitives.get(0);40 if (! (p instanceof Way)) return;41 Way fromLeg = (Way)p;42 if (fromLeg.isDeleted() || ! fromLeg.isVisible()) return;43 this.from = fromLeg;44 }45 46 /**47 * Initializes the 'to' leg. Proposes the last element48 * in {@code primitives} as 'to' leg if this element is a49 * non-deleted, visible way.50 *51 * @param primitives52 */53 protected void initToLeg(List<OsmPrimitive> primitives){54 if (primitives == null || primitives.isEmpty()) return;55 if (primitives.size() < 2) return;56 OsmPrimitive p = primitives.get(primitives.size()-1);57 if (! (p instanceof Way)) return;58 Way toLeg = (Way)p;59 if (toLeg.isDeleted() || ! toLeg.isVisible()) return;60 this.to = toLeg;61 }62 63 /**64 * Initializes the vias from the two turn restriction legs. The two65 * legs have to be defined, otherwise no via is proposed. This methods66 * proposes exactly one node as via, if the two turn restriction67 * legs intersect at exactly one node.68 */69 protected void initViaFromLegs(){70 if (from == null || to == null) return;71 // check whether 'from' and 'to' have exactly one intersecting72 // node. This node is proposed as via node. The turn restriction73 // node will also provide functionality to split either or both74 // of 'from' and 'to' way if they aren't connected from tail to75 // head76 //77 HashSet<Node> nodes = new HashSet<Node>();78 nodes.addAll(from.getNodes());79 nodes.retainAll(to.getNodes());80 if (nodes.size() == 1){81 vias.add(nodes.iterator().next());82 }83 }84 85 /**86 * Initializes the vias with the primitives (1..size-2), provided87 * these primitives aren't relations and they are visible and non-deleted.88 *89 * @param primitives90 */91 protected void initViasFromPrimitives(List<OsmPrimitive> primitives) {92 if (primitives == null || primitives.size() <=2) return;93 // if we didn't find a from or a to way, we don't propose via objects94 // either95 if (from == null || to == null) return;96 for(int i=1; i< primitives.size() -2;i++){97 OsmPrimitive p = primitives.get(i);98 if (p == null) continue;99 if (p instanceof Relation) continue;100 if (p.isDeleted() || ! p.isVisible()) continue;101 vias.add(p);102 }103 }104 105 /**106 * Resets the builder107 */108 protected void reset() {109 this.from = null;110 this.to = null;111 this.vias.clear();112 26 } 113 27 … … 128 42 129 43 /** 44 * Tries to initialize a No-U-Turn restriction from the primitives in 45 * <code>primitives</code>. If successful, replies true, otherwise false. 46 * 47 * @param primitives the primitives 48 * @return true, if we can propose a U-turn restriction for the primitives 49 * in <code>primitives</code> 50 */ 51 protected Relation initNoUTurnRestriction(List<OsmPrimitive> primitives) { 52 if (primitives.size() != 2) return null; 53 54 // we need exactly one node and one way in the selection ... 55 List<Node> nodes = OsmPrimitive.getFilteredList(primitives, Node.class); 56 List<Way> ways = OsmPrimitive.getFilteredList(primitives, Way.class); 57 if (nodes.size() != 1 || ways.size() != 1) return null; 58 59 // .. and the node has to be the start or the node of the way 60 Way way = ways.get(0); 61 Node node = nodes.get(0); 62 List<Node> wayNodes = way.getNodes(); 63 if (wayNodes.size() < 2) return null; // shouldn't happen - just in case 64 if (! (wayNodes.get(0).equals(node) ||wayNodes.get(wayNodes.size()-1).equals(node))) return null; 65 66 Relation tr = new Relation(); 67 tr.put("type", "restriction"); 68 tr.addMember(new RelationMember("from", way)); 69 tr.addMember(new RelationMember("to", way)); 70 tr.addMember(new RelationMember("via", node)); 71 tr.put("restriction", TurnRestrictionType.NO_U_TURN.getTagValue()); 72 return tr; 73 } 74 75 /** 76 * Replies the unique common node of two ways, or null, if either no 77 * such node or multiple common nodes exist. 78 * 79 * @param w1 the first way 80 * @param w2 the second way 81 * @return the common node 82 */ 83 protected Node getUniqueCommonNode(Way w1, Way w2){ 84 List<Node> w1Nodes = w1.getNodes(); 85 w1Nodes.retainAll(w2.getNodes()); 86 if (w1Nodes.size() != 1) return null; 87 return w1Nodes.get(0); 88 } 89 90 /** 91 * Replies true, if {@code n} is the start node of the way {@code w}. 92 * 93 * @param w the way 94 * @param n the node 95 * @return true, if {@code n} is the start node of the way {@code w}. 96 */ 97 protected boolean isStartNode(Way w, Node n) { 98 if (w.getNodesCount() == 0) return false; 99 return w.getNode(0).equals(n); 100 } 101 102 103 /** 104 * Replies true, if {@code n} is the end node of the way {@code w}. 105 * 106 * @param w the way 107 * @param n the node 108 * @return true, if {@code n} is the end node of the way {@code w}. 109 */ 110 protected boolean isEndNode(Way w, Node n){ 111 if (w.getNodesCount() == 0) return false; 112 return w.getNode(w.getNodesCount()-1).equals(n); 113 } 114 115 /** 116 * <p>Replies true, if the ways {@code w1} and {@code w2} are connected 117 * at the node {@code n}.</p> 118 * 119 * <p>If {@code w1} and {@code w2} <em>intersect</em> at the node {@code n}, 120 * this method replies false.</p> 121 * 122 * @param w1 the first way 123 * @param w2 the second way 124 * @param n the node 125 * @return 126 */ 127 protected boolean isConnectingNode(Way w1, Way w2, Node n){ 128 if (isStartNode(w1, n)) { 129 return isStartNode(w2, n) | isEndNode(w2, n); 130 } else if (isEndNode(w1, n)){ 131 return isStartNode(w2, n) | isEndNode(w2, n); 132 } 133 return false; 134 } 135 136 /** 137 * Replies true, if the way {@code w} is closed at the node {@code n}. 138 * 139 * @param w the way 140 * @param n the node 141 * @return true, if the way {@code w} is closed at the node {@code n}. 142 */ 143 protected boolean isClosedAt(Way w, Node n){ 144 List<Node> nodes = w.getNodes(); 145 nodes.retainAll(Collections.singletonList(n)); 146 return nodes.size() >= 2; 147 } 148 149 protected double phi(Way w) { 150 return phi(w, false /* not inverse */); 151 } 152 153 protected double phi(Way w, boolean doInvert) { 154 double x1 = w.getNode(0).getCoor().getX(); 155 double y1 = w.getNode(0).getCoor().getY(); 156 double x2 = w.getNode(w.getNodesCount()-1).getCoor().getX(); 157 double y2 = w.getNode(w.getNodesCount()-1).getCoor().getY(); 158 if (doInvert){ 159 double t = x1; x1 = x2; x2 = t; 160 t = y1; y1 = y2; y2 = t; 161 } 162 x2-=x1; 163 y2-=y1; 164 return phi(x2,y2); 165 } 166 167 protected double phi(double x, double y) { 168 return Math.atan2(y, x); 169 } 170 171 /** 172 * <p>Determines the standard turn restriction between from way {@code w1} to 173 * way {@code w2}.</p> 174 * 175 * <p>Replies {@link TurnRestrictionType#NO_LEFT_TURN no_left_turn} or 176 * {@link TurnRestrictionType#NO_RIGHT_TURN no_right_turn}, if applicable. Or 177 * null, if neither of these restrictions is applicable, for instance because 178 * the passed in via node {@code via} isn't a node where the two ways are 179 * connected.</p> 180 * 181 * @param w1 the "from"-way 182 * @param w2 the "to"-way 183 * @param via the via node 184 * @return an applicable turn restriction, or null, if no turn restriction is 185 * applicable 186 */ 187 protected String determineRestriction(Way w1, Way w2, Node via){ 188 if (via == null) return null; 189 if (!isConnectingNode(w1, w2, via)) return null; 190 // if either w1 or w2 are closed at the via node, we can't determine automatically 191 // whether the connection at "via" is a "left turn" or a "right turn" 192 if (isClosedAt(w1, via)) return null; 193 if (isClosedAt(w2, via)) return null; 194 195 double phi1 = 0, phi2 = 0; 196 if (isEndNode(w1, via)){ 197 if (isStartNode(w2, via)) { 198 phi1 = phi(w1); 199 phi2 = phi(w2); 200 } else if (isEndNode(w2, via)){ 201 phi1 = phi(w1); 202 phi2 = phi(w2, true /* reverse it */); 203 } else { 204 assert false: "Unexpected state: via node is expected to be a start or and end node"; 205 } 206 } else if (isStartNode(w1,via)) { 207 if (isStartNode(w2, via)) { 208 phi1 = phi(w1, true /* reverse it */); 209 phi2 = phi(w2); 210 } else if (isEndNode(w2, via)){ 211 phi1 = phi(w1, true /* reverse it */); 212 phi2 = phi(w2, true /* reverse it */); 213 } else { 214 assert false: "Unexpected state: via node is expected to be a start or and end node"; 215 } 216 } else { 217 assert false: "Unexpected state: via node is expected to be a start or and end node of w1"; 218 } 219 220 double phi = phi1-phi2; 221 if (phi >=0 && phi <= Math.PI) { 222 // looks like a right turn 223 return TurnRestrictionType.NO_RIGHT_TURN.getTagValue(); 224 } else { 225 // looks like a left turn 226 return TurnRestrictionType.NO_LEFT_TURN.getTagValue(); 227 } 228 } 229 230 protected Relation initTurnRestrictionFromTwoWays(List<OsmPrimitive> primitives) { 231 Way w1 = null; 232 Way w2 = null; 233 Node via = null; 234 if (primitives.size() == 2) { 235 // if we have exactly two selected primitives, we expect two ways. 236 // See initNoUTurnRestriction() for the case where we have a selected way 237 // and a selected node 238 List<Way> selWays = OsmPrimitive.getFilteredList(primitives, Way.class); 239 if (selWays.size() != 2) return null; 240 w1 = selWays.get(0); 241 w2 = selWays.get(1); 242 via = getUniqueCommonNode(w1, w2); 243 } else if (primitives.size() == 3){ 244 // if we have exactly three selected primitives, we need two ways and a 245 // node, which should be an acceptable via node 246 List<Way> selWays = OsmPrimitive.getFilteredList(primitives, Way.class); 247 List<Node> selNodes = OsmPrimitive.getFilteredList(primitives, Node.class); 248 if (selWays.size() != 2) return null; 249 if (selNodes.size() != 1) return null; 250 w1 = selWays.get(0); 251 w2 = selWays.get(1); 252 via = selNodes.get(0); 253 if (! w1.getNodes().contains(via) || ! w2.getNodes().contains(via)){ 254 // the selected node is not an acceptable via node 255 via = null; 256 } 257 } else { 258 // the selection doesn't consists of primitives for which we can build 259 // a turn restriction 260 return null; 261 } 262 263 // if we get here, we know the two "legs" of the turn restriction. We may 264 // or may not know a via node, though 265 assert w1 != null; 266 assert w2 != null; 267 268 Relation tr = new Relation(); 269 tr.put("type", "restriction"); 270 tr.addMember(new RelationMember("from", w1)); 271 tr.addMember(new RelationMember("to", w2)); 272 273 if (via != null){ 274 tr.addMember(new RelationMember("via", via)); 275 String restriction = determineRestriction(w1, w2, via); 276 if (restriction != null){ 277 tr.put("restriction", restriction); 278 } 279 } 280 return tr; 281 } 282 283 protected Relation initEmptyTurnRestriction() { 284 Relation tr = new Relation(); 285 tr.put("type", "restriction"); 286 return tr; 287 } 288 289 /** 130 290 * Creates and initializes a new turn restriction based on primitives 131 291 * in {@code primitives}. … … 136 296 */ 137 297 public synchronized Relation build(List<OsmPrimitive> primitives){ 138 Relation tr = new Relation(); 139 tr.put("type", "restriction"); 140 if (primitives == null || primitives.isEmpty()) return tr; 141 if (primitives.size() <=2){ 142 initFromLeg(primitives); 143 initToLeg(primitives); 144 initViaFromLegs(); 145 } else if (primitives.size() > 2) { 146 initFromLeg(primitives); 147 initToLeg(primitives); 148 initViasFromPrimitives(primitives); 298 if (primitives == null || primitives.isEmpty()) { 299 return initEmptyTurnRestriction(); 149 300 } 150 151 if (from != null){ 152 tr.addMember(new RelationMember("from", from)); 301 Relation tr; 302 switch(primitives.size()){ 303 // case 0 already handled 304 case 1: 305 tr = initEmptyTurnRestriction(); 306 if (OsmPrimitive.getFilteredList(primitives, Way.class).size() == 1) { 307 // we have exactly one selected way? -> init the "from" leg 308 // of the turn restriction with it 309 tr.addMember(new RelationMember("from", primitives.get(0))); 310 } 311 return tr; 312 313 case 2: 314 tr = initNoUTurnRestriction(primitives); 315 if (tr != null) return tr; 316 tr = initTurnRestrictionFromTwoWays(primitives); 317 if (tr != null) return tr; 318 return initEmptyTurnRestriction(); 319 320 default: 321 tr = initTurnRestrictionFromTwoWays(primitives); 322 if (tr != null) return tr; 323 return initEmptyTurnRestriction(); 153 324 } 154 if (to != null){155 tr.addMember(new RelationMember("to", to));156 }157 for(OsmPrimitive via: vias){158 tr.addMember(new RelationMember("via", via));159 }160 return tr;161 325 } 162 326 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModel.java
r23510 r23571 10 10 import javax.swing.AbstractListModel; 11 11 import javax.swing.DefaultListSelectionModel; 12 import javax.swing.ListSelectionModel; 12 13 13 14 import org.openstreetmap.josm.Main; … … 38 39 39 40 private final List<OsmPrimitive> selection = new ArrayList<OsmPrimitive>(); 40 private DefaultListSelectionModel selectionModel;41 private final DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); 41 42 private OsmDataLayer layer; 42 43 … … 46 47 * @param selectionModel the selection model used in the list. Must not be null. 47 48 * @param layer the layer this model is displaying the selection from. Must not be null. 48 * @throws IllegalArgumentException thrown if {@code selectionModel} is null49 49 * @throws IllegalArgumentException thrown if {@code layer} is null 50 50 */ 51 public JosmSelectionListModel(OsmDataLayer layer, DefaultListSelectionModel selectionModel) { 52 CheckParameterUtil.ensureParameterNotNull(selectionModel, "selectionModel"); 51 public JosmSelectionListModel(OsmDataLayer layer) throws IllegalArgumentException{ 53 52 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 54 53 this.layer = layer; 55 this.selectionModel = selectionModel;56 54 setJOSMSelection(layer.data.getSelected()); 57 55 } … … 118 116 this.selection.addAll(selection); 119 117 fireContentsChanged(this, 0, getSize()); 120 setSelected(sel); 118 setSelected(sel); 119 // if the user selects exactly one primitive (i.e. a way), we automatically 120 // select it in the list of selected JOSM objects too. 121 if (getSelected().isEmpty() && this.selection.size() == 1) { 122 setSelected(this.selection); 123 } 121 124 } 122 125 … … 138 141 } 139 142 setSelected(sel); 143 } 144 145 public ListSelectionModel getListSelectionModel() { 146 return selectionModel; 140 147 } 141 148 -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionPanel.java
r23510 r23571 54 54 protected void build(OsmDataLayer layer) { 55 55 setLayout(new BorderLayout()); 56 DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();57 model = new JosmSelectionListModel(layer,selectionModel);58 56 lstSelection = new JList(model); 59 57 lstSelection.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 60 lstSelection.setSelectionModel( selectionModel);58 lstSelection.setSelectionModel(model.getListSelectionModel()); 61 59 lstSelection.setCellRenderer(new OsmPrimitivRenderer()); 62 60 lstSelection.setTransferHandler(transferHandler = new JosmSelectionTransferHandler(model)); … … 77 75 * @exception IllegalArgumentException thrown if {@code layer} is null 78 76 */ 79 public JosmSelectionPanel(OsmDataLayer layer ) throws IllegalArgumentException{77 public JosmSelectionPanel(OsmDataLayer layer, JosmSelectionListModel model) throws IllegalArgumentException{ 80 78 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 79 this.model = model; 81 80 build(layer); 82 81 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditor.java
r23510 r23571 114 114 */ 115 115 protected JPanel buildJOSMSelectionPanel() { 116 pnlJosmSelection = new JosmSelectionPanel(layer );116 pnlJosmSelection = new JosmSelectionPanel(layer,editorModel.getJosmSelectionListModel()); 117 117 return pnlJosmSelection; 118 118 } 119 119 120 120 /** 121 * Builds the panel with the editor masks (the left panel in the split pane of121 * Builds the panel with the editor forms (the left panel in the split pane of 122 122 * this dialog) 123 123 * -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditorModel.java
r23510 r23571 69 69 private IssuesModel issuesModel; 70 70 private NavigationControler navigationControler; 71 private JosmSelectionListModel selectionModel; 71 72 72 73 /** … … 87 88 addObserver(issuesModel); 88 89 tagEditorModel.addTableModelListener(new TagEditorModelObserver()); 90 selectionModel = new JosmSelectionListModel(layer); 91 } 92 93 /** 94 * Replies the model for the currently selected JOSM primitives 95 */ 96 public JosmSelectionListModel getJosmSelectionListModel() { 97 return selectionModel; 89 98 } 90 99 … … 211 220 CheckParameterUtil.ensureParameterNotNull(turnRestriction, "turnRestriction"); 212 221 TagCollection tags = tagEditorModel.getTagCollection(); 222 logger.info(tags.toString()); 213 223 turnRestriction.removeAll(); 214 224 tags.applyTo(turnRestriction); -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionLegEditor.java
r23192 r23571 4 4 5 5 import java.awt.BorderLayout; 6 import java.awt.FlowLayout; 6 7 import java.awt.Font; 7 8 import java.awt.Toolkit; … … 38 39 import javax.swing.TransferHandler; 39 40 import javax.swing.UIManager; 41 import javax.swing.event.ListSelectionEvent; 42 import javax.swing.event.ListSelectionListener; 40 43 41 44 import org.openstreetmap.josm.data.osm.OsmPrimitive; 42 45 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 43 46 import org.openstreetmap.josm.data.osm.PrimitiveId; 47 import org.openstreetmap.josm.data.osm.Way; 44 48 import org.openstreetmap.josm.gui.DefaultNameFormatter; 45 49 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; … … 64 68 private CopyAction actCopy; 65 69 private PasteAction actPaste; 70 private AcceptAction actAccept; 66 71 private TransferHandler transferHandler; 67 72 … … 81 86 ); 82 87 88 JPanel pnlButtons = new JPanel(new FlowLayout(FlowLayout.LEFT,0,0)); 89 pnlButtons.setBorder(null); 83 90 JButton btn; 84 91 actDelete = new DeleteAction(); 85 add(btn = new JButton(actDelete), BorderLayout.EAST);92 pnlButtons.add(btn = new JButton(actDelete)); 86 93 btn.setFocusable(false); 87 94 btn.setText(null); 88 95 btn.setBorder(BorderFactory.createRaisedBevelBorder()); 96 97 actAccept = new AcceptAction(); 98 pnlButtons.add(btn = new JButton(actAccept)); 99 btn.setFocusable(false); 100 btn.setText(null); 101 btn.setBorder(BorderFactory.createRaisedBevelBorder()); 102 add(pnlButtons, BorderLayout.EAST); 89 103 90 104 // focus handling … … 260 274 261 275 /** 276 * Accepts the currently selected way as turn restriction leg. Only enabled, 277 * if there is exactly one way selected 278 */ 279 class AcceptAction extends AbstractAction implements ListSelectionListener { 280 281 public AcceptAction() { 282 putValue(SHORT_DESCRIPTION, tr("Accept the currently selected way")); 283 putValue(NAME, tr("Accept")); 284 putValue(SMALL_ICON, ImageProvider.get("accept")); 285 model.getJosmSelectionListModel().getListSelectionModel().addListSelectionListener(this); 286 updateEnabledState(); 287 } 288 289 public void actionPerformed(ActionEvent e) { 290 List<Way> selWays = OsmPrimitive.getFilteredList(model.getJosmSelectionListModel().getSelected(), Way.class); 291 if (selWays.size() != 1) return; 292 Way w = selWays.get(0); 293 model.setTurnRestrictionLeg(role, w); 294 } 295 296 public void updateEnabledState() { 297 setEnabled(OsmPrimitive.getFilteredList(model.getJosmSelectionListModel().getSelected(), Way.class).size() == 1); 298 } 299 300 @Override 301 public void valueChanged(ListSelectionEvent e) { 302 updateEnabledState(); 303 } 304 } 305 306 /** 262 307 * The transfer handler for Drag-and-Drop. 263 308 */ … … 366 411 } 367 412 } 413 414 368 415 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/VehicleExceptionEditor.java
r23192 r23571 51 51 private ExceptValueModel exceptValue = new ExceptValueModel(); 52 52 53 private StandardVehicleTypeChangeListener svtChangeListener; 54 53 55 private JPanel buildMessagePanel() { 54 56 JPanel pnl = new JPanel(new BorderLayout()); … … 67 69 return pnlStandard; 68 70 69 StandardVehicleTypeChangeListener changeHandler = new StandardVehicleTypeChangeListener();71 svtChangeListener = new StandardVehicleTypeChangeListener(); 70 72 71 73 GridBagConstraints gc = new GridBagConstraints(); … … 78 80 JLabel lbl; 79 81 cbPsv = new JCheckBox(); 80 cbPsv.addItemListener( changeHandler);82 cbPsv.addItemListener(svtChangeListener); 81 83 lbl = new JLabel(); 82 84 lbl.setText(tr("Public Service Vehicles")); … … 91 93 92 94 cbHgv = new JCheckBox(); 93 cbHgv.addItemListener( changeHandler);95 cbHgv.addItemListener(svtChangeListener); 94 96 lbl = new JLabel(); 95 97 lbl.setText(tr("Heavy Goods Vehicles")); … … 104 106 105 107 cbMotorcar = new JCheckBox(); 106 cbMotorcar.addItemListener( changeHandler);108 cbMotorcar.addItemListener(svtChangeListener); 107 109 lbl = new JLabel(); 108 110 lbl.setText(tr("Motorcars")); … … 118 120 119 121 cbBicyle = new JCheckBox(); 120 cbBicyle.addItemListener( changeHandler);122 cbBicyle.addItemListener(svtChangeListener); 121 123 lbl = new JLabel(); 122 124 lbl.setText(tr("Bicycles")); … … 212 214 bgStandardOrNonStandard.add(rbStandardException); 213 215 214 StandardNonStandardChangeHand er changeHandler = new StandardNonStandardChangeHander();216 StandardNonStandardChangeHandler changeHandler = new StandardNonStandardChangeHandler(); 215 217 rbNonStandardException.addItemListener(changeHandler); 216 218 rbStandardException.addItemListener(changeHandler); … … 231 233 232 234 protected void init() { 233 cbPsv.setSelected(exceptValue.isVehicleException("psv")); 234 cbBicyle.setSelected(exceptValue.isVehicleException("bicycle")); 235 cbMotorcar.setSelected(exceptValue.isVehicleException("motorcar")); 236 cbHgv.setSelected(exceptValue.isVehicleException("hgv")); 235 try { 236 // temporarily disable the checkbox listeners while initializing the 237 // checkboxes with the input value 238 this.svtChangeListener.setEnabled(false); 239 cbPsv.setSelected(exceptValue.isVehicleException("psv")); 240 cbBicyle.setSelected(exceptValue.isVehicleException("bicycle")); 241 cbMotorcar.setSelected(exceptValue.isVehicleException("motorcar")); 242 cbHgv.setSelected(exceptValue.isVehicleException("hgv")); 243 } finally { 244 this.svtChangeListener.setEnabled(true); 245 } 237 246 if (!exceptValue.isStandard()){ 238 247 rbNonStandardException.setSelected(true); … … 285 294 /* inner classes */ 286 295 /* ------------------------------------------------------------------------------------ */ 287 class StandardNonStandardChangeHand er implements ItemListener {296 class StandardNonStandardChangeHandler implements ItemListener { 288 297 public void itemStateChanged(ItemEvent e) { 289 298 if (rbNonStandardException.isSelected()){ … … 301 310 302 311 class StandardVehicleTypeChangeListener implements ItemListener { 303 public void itemStateChanged(ItemEvent e) { 312 private boolean enabled = true; 313 314 public void setEnabled(boolean enabled){ 315 this.enabled = enabled; 316 } 317 318 public void itemStateChanged(ItemEvent e) { 319 if (!enabled) return; 304 320 exceptValue.setVehicleException("bicycle", cbBicyle.isSelected()); 305 321 exceptValue.setVehicleException("hgv", cbHgv.isSelected()); 306 322 exceptValue.setVehicleException("psv", cbPsv.isSelected()); 307 exceptValue.setVehicleException("motorcar", cbMotorcar.isSelected()); 323 exceptValue.setVehicleException("motorcar", cbMotorcar.isSelected()); 308 324 model.setExcept(exceptValue); 309 325 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IssuesModel.java
r23192 r23571 22 22 23 23 /** 24 * IssuesModel is a model for an observable list of {@code Issues}25 * related to turn restriction. 24 * <p>IssuesModel is a model for an observable list of {@code Issues} 25 * related to turn restriction.</p> 26 26 * 27 * It is also an {@see Observer} to an {@seeTurnRestrictionEditorModel}27 * <p>It is also an {@link Observer} to an {@link TurnRestrictionEditorModel} 28 28 * and populates itself with issues it derives from the current state 29 * in the {@ see TurnRestrictionEditorModel}.29 * in the {@link TurnRestrictionEditorModel}.</p> 30 30 * 31 31 */ … … 36 36 /** 37 37 * Creates the model 38 *39 * {@code controler} is used in resolution actions for issues in40 * this model to direct the user to a specific input field in one41 * of the editor tabs in order to fix an issue.42 38 * 43 39 * @param editorModel the editor model. Must not be null. … … 224 220 issues.add(new IntersectionMissingAsViaError(this, from, to, intersect)); 225 221 } 226 } 227 228 // 'from' intersects with 'to' - should be split 229 if (intersect != null && from.getNode(0) != intersect && from.getNode(from.getNodesCount()-1) != intersect){ 230 issues.add(new TurnRestrictionLegSplitRequiredError(this, TurnRestrictionLegRole.FROM, from, to, intersect)); 231 } 232 // 'to' intersects with 'from' - should be split 233 if (intersect != null && to.getNode(0) != intersect && to.getNode(to.getNodesCount()-1) != intersect){ 234 issues.add(new TurnRestrictionLegSplitRequiredError(this, TurnRestrictionLegRole.TO, from, to, intersect)); 235 } 222 // 'from' intersects with 'to' - should be split 223 if (from.getNode(0) != intersect && from.getNode(from.getNodesCount()-1) != intersect){ 224 issues.add(new TurnRestrictionLegSplitRequiredError(this, TurnRestrictionLegRole.FROM, from, to, intersect)); 225 } 226 // 'to' intersects with 'from' - should be split 227 if (to.getNode(0) != intersect && to.getNode(to.getNodesCount()-1) != intersect){ 228 issues.add(new TurnRestrictionLegSplitRequiredError(this, TurnRestrictionLegRole.TO, from, to, intersect)); 229 } 230 } else { 231 if (editorModel.getVias().isEmpty() && ! from.equals(to)){ 232 // the two turn restriction legs aren't connected and we don't have configured 233 // via objects 234 issues.add(new MissingViaError(this)); 235 } 236 } 236 237 } 237 238 -
applications/editors/josm/plugins/turnrestrictions/test/src/org/openstreetmap/josm/plugins/turnrestrictions/AllUnitTests.java
r23510 r23571 1 1 package org.openstreetmap.josm.plugins.turnrestrictions; 2 2 3 import org.junit.runner.RunWith; 4 import org.junit.runners.Suite; 3 5 import org.openstreetmap.josm.plugins.turnrestrictions.editor.AllEditorTests; 4 6 5 import junit.framework.Test; 6 import junit.framework.TestSuite; 7 8 public class AllUnitTests { 9 public static Test suite() throws Exception { 10 TestSuite suite = new TestSuite(AllUnitTests.class.getName()); 11 suite.addTest(AllEditorTests.suite()); 12 return suite; 13 } 14 } 7 @RunWith(Suite.class) 8 @Suite.SuiteClasses({ 9 AllEditorTests.class, 10 TurnRestrictionBuilderTest.class 11 }) 12 public class AllUnitTests {} -
applications/editors/josm/plugins/turnrestrictions/test/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/AllEditorTests.java
r23510 r23571 1 1 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 2 3 import groovy.util.GroovyTestSuite;4 import junit.framework.Test;5 3 import junit.framework.TestCase; 6 import junit.framework.TestSuite;7 4 8 public class AllEditorTests extends TestCase{ 5 import org.junit.runner.RunWith; 6 import org.junit.runners.Suite; 9 7 10 private static final String TEST_ROOT = "test/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/"; 11 private static final GroovyTestSuite gsuite = new GroovyTestSuite(); 12 13 private static <T extends TestCase> Class<T> groovyts(String className) throws Exception { 14 return gsuite.compile(TEST_ROOT + className + ".groovy"); 15 } 16 17 public static Test suite() throws Exception { 18 TestSuite suite = new TestSuite(AllEditorTests.class.getName()); 19 suite.addTestSuite(groovyts("JosmSelectionListModelTest")); 20 suite.addTestSuite(groovyts("TurnRestrictionEditorModelUnitTest")); 21 suite.addTestSuite(groovyts("TurnRestrictionLegEditorUnitTest")); 22 suite.addTestSuite(groovyts("TurnRestrictionTypeRendererTest")); 23 suite.addTestSuite(groovyts("TurnRestrictionTypeTest")); 24 return suite; 25 } 26 } 8 @RunWith(Suite.class) 9 @Suite.SuiteClasses({ 10 JosmSelectionListModelTest.class, 11 TurnRestrictionEditorModelUnitTest.class, 12 TurnRestrictionLegEditorUnitTest.class, 13 TurnRestrictionTypeRendererTest.class, 14 TurnRestrictionTypeTest.class, 15 ExceptValueModelTest.class 16 }) 17 public class AllEditorTests extends TestCase{} -
applications/editors/josm/plugins/turnrestrictions/test/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModelTest.groovy
r23510 r23571 33 33 DataSet ds = new DataSet() 34 34 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 35 JosmSelectionListModel model = new JosmSelectionListModel(layer , new DefaultListSelectionModel());35 JosmSelectionListModel model = new JosmSelectionListModel(layer); 36 36 37 37 shouldFail(IllegalArgumentException){ 38 model = new JosmSelectionListModel(layer, null) 39 } 40 41 shouldFail(IllegalArgumentException){ 42 model = new JosmSelectionListModel(null, new DefaultListSelectionModel()) 38 model = new JosmSelectionListModel(null) 43 39 } 44 40 } … … 48 44 DataSet ds = new DataSet() 49 45 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 50 JosmSelectionListModel model = new JosmSelectionListModel(layer , new DefaultListSelectionModel());46 JosmSelectionListModel model = new JosmSelectionListModel(layer); 51 47 52 48 // set a selection with three objects … … 70 66 DataSet ds = new DataSet() 71 67 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 72 JosmSelectionListModel model = new JosmSelectionListModel(layer , new DefaultListSelectionModel());68 JosmSelectionListModel model = new JosmSelectionListModel(layer); 73 69 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()] 74 70 model.setJOSMSelection(objects) … … 88 84 DataSet ds = new DataSet() 89 85 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 90 DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();91 86 92 JosmSelectionListModel model = new JosmSelectionListModel(layer, selectionModel); 87 JosmSelectionListModel model = new JosmSelectionListModel(layer); 88 DefaultListSelectionModel selectionModel = model.getListSelectionModel() 89 93 90 assert model.getSelected() != null 94 91 assert model.getSelected().isEmpty() … … 109 106 DataSet ds = new DataSet() 110 107 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 111 DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();112 108 113 109 // set selected with null is OK - nothing selected thereafter 114 JosmSelectionListModel model = new JosmSelectionListModel(layer, selectionModel); 110 JosmSelectionListModel model = new JosmSelectionListModel(layer); 111 DefaultListSelectionModel selectionModel = model.getListSelectionModel() 115 112 model.setSelected(null) 116 113 assert model.getSelected().isEmpty() … … 135 132 public void test_editLayerChanged() { 136 133 DataSet ds = new DataSet() 137 DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();134 138 135 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()] 139 136 objects.each {ds.addPrimitive(it)} … … 142 139 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(),"layer2", null) 143 140 144 JosmSelectionListModel model = new JosmSelectionListModel(layer1 , selectionModel);145 141 JosmSelectionListModel model = new JosmSelectionListModel(layer1); 142 DefaultListSelectionModel selectionModel = model.getListSelectionModel() 146 143 // switch from edit layer1 to edit layer2. content of the JOSM selection 147 144 // should be empty thereafter
Note:
See TracChangeset
for help on using the changeset viewer.