Changeset 1400 in josm for trunk/src/org
- Timestamp:
- 2009-02-14T12:53:37+01:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r1379 r1400 142 142 } 143 143 144 private void tryAgain(MouseEvent e) { 145 Main.ds.setSelected(); 146 mouseClicked(e); 147 } 148 144 149 /** 145 150 * If user clicked with the left button, add a node at the current mouse … … 149 154 */ 150 155 @Override public void mouseClicked(MouseEvent e) { 151 if (e.getButton() != MouseEvent.BUTTON1 || e.getClickCount() > 1)156 if (e.getButton() != MouseEvent.BUTTON1) 152 157 return; 153 158 if(!Main.map.mapView.isDrawableLayer()) 154 159 return; 155 160 if(e.getClickCount() > 1) { 161 // A double click equals "user clicked last node again, finish way" 162 lastUsedNode = null; 163 return; 164 } 156 165 // we copy ctrl/alt/shift from the event just in case our global 157 166 // AWTEvent didn't make it through the security manager. Unclear … … 171 180 boolean wayIsFinished = false; 172 181 173 if (!ctrl) {182 if (!ctrl) 174 183 n = Main.map.mapView.getNearestNode(mousePos); 175 } 176 184 177 185 if (n != null) { 178 186 // user clicked on node … … 184 192 return; 185 193 } 186 187 194 } else { 188 195 // no node found in clicked area … … 243 250 // he must have a way and a node selected (connection is made to the selected node). 244 251 252 // If the above does not apply, the selection is cleared and a new try is started 245 253 boolean extendedWay = false; 246 247 if (!shift && selection.size() > 0 && selection.size() < 3) { 248 254 if (!shift && selection.size() > 0) { 249 255 Node selectedNode = null; 250 256 Way selectedWay = null; 251 257 252 258 for (OsmPrimitive p : selection) { 253 259 if (p instanceof Node) { 254 if (selectedNode != null) return; 260 if (selectedNode != null) { 261 // Too many nodes selected to do something useful 262 tryAgain(e); 263 return; 264 } 255 265 selectedNode = (Node) p; 256 266 } else if (p instanceof Way) { 257 if (selectedWay != null) return; 267 if (selectedWay != null) { 268 // Too many ways selected to do something useful 269 tryAgain(e); 270 return; 271 } 258 272 selectedWay = (Way) p; 259 273 } 260 274 } 275 276 // No nodes or ways have been selected, try again with no selection 277 // This occurs when a relation has been selected 278 if(selectedNode == null && selectedWay == null) { 279 tryAgain(e); 280 return; 281 } 261 282 262 283 // the node from which we make a connection … … 264 285 265 286 if (selectedNode == null) { 266 if (selectedWay == null) return; 267 if (lastUsedNode == selectedWay.nodes.get(0) || lastUsedNode == selectedWay.nodes.get(selectedWay.nodes.size()-1)) { 287 if (selectedWay.isFirstLastNode(lastUsedNode)) { 268 288 n0 = lastUsedNode; 289 } else { 290 // We have a way selected, but no suitable node to continue from. Start anew. 291 tryAgain(e); 292 return; 269 293 } 270 294 } else if (selectedWay == null) { 271 295 n0 = selectedNode; 272 296 } else { 273 if (selected Node == selectedWay.nodes.get(0) || selectedNode == selectedWay.nodes.get(selectedWay.nodes.size()-1)) {297 if (selectedWay.isFirstLastNode(selectedNode)) { 274 298 n0 = selectedNode; 299 } else { 300 // We have a way and node selected, but it's not at the start/end of the way. Start anew. 301 tryAgain(e); 302 return; 275 303 } 276 304 } 277 305 278 if (n0 == null || n0 == n) { 279 return; // Don't create zero length way segments. 306 // Prevent creation of ways that look like this: <----> 307 // This happens if users want to draw a no-exit-sideway from the main way like this: 308 // ^ 309 // |<----> 310 // | 311 // The solution isn't ideal because the main way will end in the side way, which is bad for 312 // navigation software ("drive straight on") but at least easier to fix. Maybe users will fix 313 // it on their own, too. At least it's better than producing an error. 314 if(selectedWay != null && selectedWay.nodes != null) { 315 int posn0 = selectedWay.nodes.indexOf(n0); 316 if( posn0 != -1 && // n0 is part of way 317 (posn0 >= 1 && n.equals(selectedWay.nodes.get(posn0-1))) || // previous node 318 (posn0 < selectedWay.nodes.size()-1) && n.equals(selectedWay.nodes.get(posn0+1))) { // next node 319 Main.ds.setSelected(n); 320 lastUsedNode = n; 321 return; 322 } 323 } 324 325 // User clicked last node again, finish way 326 if(n0 == n) { 327 lastUsedNode = null; 328 return; 280 329 } 281 330 … … 309 358 310 359 // Connected to a node that's already in the way 311 if(way != null && way.nodes.contains(n)) {360 if(way.nodes.contains(n)) { 312 361 //System.out.println("Stop drawing, node is part of current way"); 313 362 wayIsFinished = true; 314 363 selection.clear(); 315 //Main.map.selectMapMode(new SelectAction(Main.map));316 364 } 317 365 … … 325 373 Main.ds.setSelected(way); 326 374 } 327 375 328 376 String title; 329 377 if (!extendedWay) { 330 if (!newNode) 331 return; // We didn't do anything.332 else if (reuseWays.isEmpty())378 if (!newNode) { 379 return; // We didn't do anything. 380 } else if (reuseWays.isEmpty()) { 333 381 title = tr("Add node"); 334 else382 } else { 335 383 title = tr("Add node into way"); 336 for (Way w : reuseWays) w.selected = false; 384 for (Way w : reuseWays) w.selected = false; 385 } 337 386 Main.ds.setSelected(n); 338 387 } else if (!newNode) { -
trunk/src/org/openstreetmap/josm/data/osm/Way.java
r1313 r1400 145 145 146 146 public Boolean isClosed() { 147 int s = nodes.size(); 148 return s >= 3 && nodes.get(0) == nodes.get(s-1); 147 return nodes.size() >= 3 && lastNode() == firstNode(); 148 } 149 150 public Node lastNode() { 151 return nodes.get(nodes.size()-1); 152 } 153 154 public Node firstNode() { 155 return nodes.get(0); 156 } 157 158 public boolean isFirstLastNode(Node n) { 159 return n == firstNode() || n == lastNode(); 149 160 } 150 161 }
Note:
See TracChangeset
for help on using the changeset viewer.