Changeset 25908 in osm for applications/editors
- Timestamp:
- 2011-04-27T16:25:41+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes/gui/JunctionPane.java
r25783 r25908 123 123 124 124 private Point2D translateCoords(int x, int y) { 125 return new Point2D.Double(-translationX + x / scale, -translationY + y / scale); 125 final double c = Math.cos(-rotation); 126 final double s = Math.sin(-rotation); 127 128 final double x2 = -translationX + x / scale; 129 final double y2 = -translationY + y / scale; 130 131 return new Point2D.Double(x2 * c - y2 * s, x2 * s + y2 * c); 126 132 } 127 133 } … … 137 143 private int width = 0; 138 144 private int height = 0; 145 private double rotation = 0; 139 146 private double scale = 10; 140 147 private double translationX = 0; … … 200 207 public void actionPerformed(ActionEvent e) { 201 208 toggleAllTurns(); 209 } 210 }); 211 212 getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_DOWN_MASK), "rotateLeft"); 213 getActionMap().put("rotateLeft", new AbstractAction() { 214 private static final long serialVersionUID = 1L; 215 216 @Override 217 public void actionPerformed(ActionEvent e) { 218 rotation -= Math.PI / 180; 219 setState(new State.Dirty(state)); 220 } 221 }); 222 223 getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK), "rotateRight"); 224 getActionMap().put("rotateRight", new AbstractAction() { 225 private static final long serialVersionUID = 1L; 226 227 @Override 228 public void actionPerformed(ActionEvent e) { 229 rotation += Math.PI / 180; 230 setState(new State.Dirty(state)); 202 231 } 203 232 }); … … 227 256 private void center() { 228 257 final Rectangle2D bounds = container.getBounds(); 258 259 rotation = 0; 260 229 261 scale = Math.min(getHeight() / 2 / bounds.getHeight(), getWidth() / 2 / bounds.getWidth()); 230 262 … … 323 355 324 356 g2d.scale(scale, scale); 325 326 357 g2d.translate(translationX, translationY); 358 g2d.rotate(rotation); 327 359 328 360 g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0.7f)); … … 356 388 g2d.scale(scale, scale); 357 389 g2d.translate(translationX, translationY); 390 g2d.rotate(rotation); 358 391 359 392 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); -
applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes/model/Lane.java
r25783 r25908 66 66 67 67 if (countStr != null) { 68 return Integer.parseInt(countStr); 69 } 70 71 // TODO default lane counts based on "highway" tag 72 return 2; 68 try { 69 return Integer.parseInt(countStr); 70 } catch (NumberFormatException e) { 71 throw UnexpectedDataException.Kind.INVALID_TAG_FORMAT.chuck("lanes", countStr); 72 } 73 } 74 75 throw UnexpectedDataException.Kind.MISSING_TAG.chuck("lanes"); 73 76 } 74 77 -
applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes/model/Utils.java
r25783 r25908 52 52 final List<RelationMember> candidates = getMembers(r, role, type); 53 53 if (candidates.isEmpty()) { 54 throw new IllegalStateException("No member with given role and type.");54 throw UnexpectedDataException.Kind.NO_MEMBER.chuck(role); 55 55 } else if (candidates.size() > 1) { 56 throw new IllegalStateException(candidates.size() + " members with given role and type.");56 throw UnexpectedDataException.Kind.MULTIPLE_MEMBERS.chuck(role); 57 57 } 58 58 return candidates.get(0); … … 63 63 for (RelationMember m : getMembers(r, role)) { 64 64 if (m.getType() != type) { 65 throw new IllegalArgumentException("Member has the specified role, but wrong type.");65 throw UnexpectedDataException.Kind.WRONG_MEMBER_TYPE.chuck(role, m.getType(), type); 66 66 } 67 67 } -
applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes/model/Validator.java
r25606 r25908 17 17 import org.openstreetmap.josm.data.osm.Node; 18 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;20 19 import org.openstreetmap.josm.data.osm.Relation; 21 20 import org.openstreetmap.josm.data.osm.RelationMember; … … 109 108 final List<Relation> turns = new ArrayList<Relation>(); 110 109 111 for (OsmPrimitive p : dataSet.allPrimitives()) { 112 if (p.getType() != OsmPrimitiveType.RELATION) { 113 continue; 114 } 115 116 final Relation r = (Relation) p; 117 final String type = p.get("type"); 110 for (Relation r : OsmPrimitive.getFilteredList(dataSet.allPrimitives(), Relation.class)) { 111 final String type = r.get("type"); 118 112 119 113 if (Constants.TYPE_LENGTHS.equals(type)) { … … 153 147 final List<Issue> issues = new ArrayList<Issue>(); 154 148 155 final Node end = validateLengthsEnd(r, issues); 156 157 if (end == null) { 149 try { 150 final Node end = Utils.getMemberNode(r, Constants.LENGTHS_ROLE_END); 151 final Route route = validateLengthsWays(r, end, issues); 152 153 if (route == null) { 154 return issues; 155 } 156 157 final List<Double> left = Lane.loadLengths(r, Constants.LENGTHS_KEY_LENGTHS_LEFT, 0); 158 final List<Double> right = Lane.loadLengths(r, Constants.LENGTHS_KEY_LENGTHS_RIGHT, 0); 159 160 int tooLong = 0; 161 for (Double l : left) { 162 if (l > route.getLength()) { 163 ++tooLong; 164 } 165 } 166 for (Double l : right) { 167 if (l > route.getLength()) { 168 ++tooLong; 169 } 170 } 171 172 if (tooLong > 0) { 173 issues.add(Issue.newError(r, end, "The lengths-relation specifies " + tooLong 174 + " extra-lanes which are longer than its ways.")); 175 } 176 177 putIncomingLanes(route, left, right, incomingLanes); 178 158 179 return issues; 159 } 160 161 final Route route = validateLengthsWays(r, end, issues); 162 163 if (route == null) { 180 181 } catch (UnexpectedDataException e) { 182 issues.add(Issue.newError(r, e.getMessage())); 164 183 return issues; 165 184 } 166 167 final List<Double> left = Lane.loadLengths(r, Constants.LENGTHS_KEY_LENGTHS_LEFT, 0);168 final List<Double> right = Lane.loadLengths(r, Constants.LENGTHS_KEY_LENGTHS_RIGHT, 0);169 170 int tooLong = 0;171 for (Double l : left) {172 if (l > route.getLength()) {173 ++tooLong;174 }175 }176 for (Double l : right) {177 if (l > route.getLength()) {178 ++tooLong;179 }180 }181 182 if (tooLong > 0) {183 issues.add(Issue.newError(r, end, "The lengths-relation specifies " + tooLong184 + " extra-lanes which are longer than its ways."));185 }186 187 putIncomingLanes(route, left, right, incomingLanes);188 189 return issues;190 185 } 191 186 … … 206 201 } 207 202 208 final double length = route.getLastSegment().getLength(); 209 final List<Double> newLeft = reduceLengths(left, length); 210 final List<Double> newRight = new ArrayList<Double>(right.size()); 211 212 if (route.getSegments().size() > 1) { 213 final Route subroute = route.subRoute(0, route.getSegments().size() - 1); 214 putIncomingLanes(subroute, newLeft, newRight, incomingLanes); 215 } 203 // TODO this tends to produce a bunch of useless errors 204 // turn lanes really should not span from one junction past another, remove?? 205 // final double length = route.getLastSegment().getLength(); 206 // final List<Double> newLeft = reduceLengths(left, length); 207 // final List<Double> newRight = new ArrayList<Double>(right.size()); 208 // 209 // if (route.getSegments().size() > 1) { 210 // final Route subroute = route.subRoute(0, route.getSegments().size() - 1); 211 // putIncomingLanes(subroute, newLeft, newRight, incomingLanes); 212 // } 216 213 } 217 214 … … 240 237 for (Way w : ways) { 241 238 if (!w.isFirstLastNode(current)) { 242 return orderWays(r, ways, current, issues );239 return orderWays(r, ways, current, issues, "ways", "lengths"); 243 240 } 244 241 … … 249 246 } 250 247 251 private Route orderWays(final Relation r, List<Way> ways, Node end, List<Issue> issues ) {248 private Route orderWays(final Relation r, List<Way> ways, Node end, List<Issue> issues, String role, String type) { 252 249 final List<Way> unordered = new ArrayList<Way>(ways); 253 250 final List<Way> ordered = new ArrayList<Way>(ways.size()); … … 257 254 findNext: while (!unordered.isEmpty()) { 258 255 if (!ends.add(current)) { 259 issues.add(Issue.newError(r, ways, "The ways of the lengths-relation are unordered (and contain cycles).")); 256 issues.add(Issue.newError(r, ways, "The " + role + " of the " + type 257 + "-relation are unordered (and contain cycles).")); 260 258 return null; 261 259 } … … 273 271 } 274 272 275 issues.add(Issue.newError(r, ways, "The ways of the lengths-relation are disconnected."));273 issues.add(Issue.newError(r, ways, "The " + role + " of the " + type + "-relation are disconnected.")); 276 274 return null; 277 275 } … … 301 299 } 302 300 303 private Node validateLengthsEnd(Relation r, List<Issue> issues) {304 final List<Node> endNodes = Utils.getMemberNodes(r, Constants.LENGTHS_ROLE_END);305 306 if (endNodes.size() != 1) {307 issues.add(Issue.newError(r, endNodes, "A lengths-relation requires exactly one member-node with role \""308 + Constants.LENGTHS_ROLE_END + "\"."));309 return null;310 }311 312 return endNodes.get(0);313 }314 315 301 private List<Issue> validateTurns(List<Relation> turns, Map<IncomingLanes.Key, IncomingLanes> incomingLanes) { 316 302 final List<Issue> issues = new ArrayList<Issue>(); … … 326 312 final List<Issue> issues = new ArrayList<Issue>(); 327 313 328 final List<Way> fromWays = Utils.getMemberWays(r, Constants.TURN_ROLE_FROM); 329 final List<Node> viaNodes = Utils.getMemberNodes(r, Constants.TURN_ROLE_VIA); 330 final List<Way> toWays = Utils.getMemberWays(r, Constants.TURN_ROLE_TO); 331 332 if (fromWays.size() != 1) { 333 issues.add(Issue.newError(r, fromWays, "A turns-relation requires exactly one member-way with role \"" 334 + Constants.TURN_ROLE_FROM + "\".")); 335 } 336 if (viaNodes.size() != 1) { 337 issues.add(Issue.newError(r, viaNodes, "A turns-relation requires exactly one member-node with role \"" 338 + Constants.TURN_ROLE_VIA + "\".")); 339 } 340 if (toWays.size() != 1) { 341 issues.add(Issue.newError(r, toWays, "A turns-relation requires exactly one member-way with role \"" 342 + Constants.TURN_ROLE_TO + "\".")); 343 } 344 345 if (!issues.isEmpty()) { 314 try { 315 final Way from = Utils.getMemberWay(r, Constants.TURN_ROLE_FROM); 316 final Way to = Utils.getMemberWay(r, Constants.TURN_ROLE_TO); 317 318 if (from.firstNode().equals(from.lastNode())) { 319 issues.add(Issue.newError(r, from, "The from-way both starts as well as ends at the via-node.")); 320 } 321 if (to.firstNode().equals(to.lastNode())) { 322 issues.add(Issue.newError(r, to, "The to-way both starts as well as ends at the via-node.")); 323 } 324 if (!issues.isEmpty()) { 325 return issues; 326 } 327 328 final Node fromJunctionNode; 329 final List<RelationMember> viaMembers = Utils.getMembers(r, Constants.TURN_ROLE_VIA); 330 if (viaMembers.isEmpty()) { 331 throw UnexpectedDataException.Kind.NO_MEMBER.chuck(Constants.TURN_ROLE_VIA); 332 } else if (viaMembers.get(0).isWay()) { 333 final List<Way> vias = Utils.getMemberWays(r, Constants.TURN_ROLE_VIA); 334 335 fromJunctionNode = Utils.lineUp(from, vias.get(0)); 336 Node current = fromJunctionNode; 337 for (Way via : vias) { 338 if (!via.isFirstLastNode(current)) { 339 orderWays(r, vias, current, issues, "via-ways", "turns"); 340 break; 341 } 342 343 current = Utils.getOppositeEnd(via, current); 344 } 345 } else { 346 final Node via = Utils.getMemberNode(r, Constants.TURN_ROLE_VIA); 347 348 if (!from.isFirstLastNode(via)) { 349 issues.add(Issue.newError(r, from, "The from-way does not start or end at the via-node.")); 350 } 351 if (!to.isFirstLastNode(via)) { 352 issues.add(Issue.newError(r, to, "The to-way does not start or end at the via-node.")); 353 } 354 355 fromJunctionNode = via; 356 } 357 358 if (!issues.isEmpty()) { 359 return issues; 360 } 361 final IncomingLanes lanes = get(incomingLanes, fromJunctionNode, from); 362 363 for (int l : splitInts(r, Constants.TURN_KEY_LANES, issues)) { 364 if (!lanes.existsRegular(l)) { 365 issues.add(Issue.newError(r, tr("Relation references non-existent (regular) lane {0}", l))); 366 } 367 } 368 369 for (int l : splitInts(r, Constants.TURN_KEY_EXTRA_LANES, issues)) { 370 if (!lanes.existsExtra(l)) { 371 issues.add(Issue.newError(r, tr("Relation references non-existent extra lane {0}", l))); 372 } 373 } 374 346 375 return issues; 347 } 348 349 final Way from = fromWays.get(0); 350 final Node via = viaNodes.get(0); 351 final Way to = toWays.get(0); 352 353 if (!from.isFirstLastNode(via)) { 354 issues.add(Issue.newError(r, from, "The from-way does not start or end at the via-node.")); 355 } else if (from.firstNode().equals(from.lastNode())) { 356 issues.add(Issue.newError(r, from, "The from-way both starts as well as ends at the via-node.")); 357 } 358 if (!to.isFirstLastNode(via)) { 359 issues.add(Issue.newError(r, to, "The to-way does not start or end at the via-node.")); 360 } else if (to.firstNode().equals(to.lastNode())) { 361 issues.add(Issue.newError(r, to, "The to-way both starts as well as ends at the via-node.")); 362 } 363 364 if (!issues.isEmpty()) { 376 } catch (UnexpectedDataException e) { 377 issues.add(Issue.newError(r, e.getMessage())); 365 378 return issues; 366 379 } 367 368 final IncomingLanes lanes = get(incomingLanes, via, from);369 370 for (int l : splitInts(r, Constants.TURN_KEY_LANES, issues)) {371 if (!lanes.existsRegular(l)) {372 issues.add(Issue.newError(r, tr("Relation references non-existent (regular) lane {0}", l)));373 }374 }375 376 for (int l : splitInts(r, Constants.TURN_KEY_EXTRA_LANES, issues)) {377 if (!lanes.existsExtra(l)) {378 issues.add(Issue.newError(r, tr("Relation references non-existent extra lane {0}", l)));379 }380 }381 382 return issues;383 380 } 384 381
Note:
See TracChangeset
for help on using the changeset viewer.