Changeset 26440 in osm for applications/editors
- Timestamp:
- 2011-08-03T18:47:42+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawingMode.java
r26309 r26440 36 36 import org.openstreetmap.josm.actions.mapmode.MapMode; 37 37 import org.openstreetmap.josm.command.AddCommand; 38 import org.openstreetmap.josm.command.ChangeCommand; 39 import org.openstreetmap.josm.command.ChangeNodesCommand; 38 40 import org.openstreetmap.josm.command.Command; 41 import org.openstreetmap.josm.command.DeleteCommand; 39 42 import org.openstreetmap.josm.command.SequenceCommand; 40 43 import org.openstreetmap.josm.data.Bounds; … … 53 56 AWTEventListener { 54 57 private static final String SIMPLIFYMODE_MESSAGE= 55 tr(" Press Enter to simplify or save, Ctrl-Enter to save with tags, Up/Down to tune simplification");58 tr("Q=Options, Enter=save, Ctrl-Enter=save with tags, Up/Down=tune"); 56 59 private static final String DRAWINGMODE_MESSAGE= 57 60 tr("Click or Click&drag to continue, Ctrl-Click to add fixed node, Shift-Click to delete, Enter to simplify or save, Ctrl-Shift-Click to start new line"); … … 65 68 private boolean ctrl; 66 69 private boolean shift; 67 private boolean oldCtrl;68 private boolean oldShift;69 70 private double eps; 70 71 private final Stroke strokeForSimplified; … … 75 76 private final Cursor cursorReady; 76 77 private final Cursor cursorNode; 78 private final Cursor cursorDrawing; 77 79 private boolean nearpoint; 78 80 private LatLon highlighted; … … 80 82 private Stroke strokeForDelete; 81 83 private int dragNode=-1; 84 private SequenceCommand delCmd; 85 private List<Node> oldNodes; 82 86 83 87 … … 97 101 cursorReady = ImageProvider.getCursor("crosshair", "ready"); 98 102 cursorNode = ImageProvider.getCursor("crosshair", "joinnode"); 103 cursorDrawing = ImageProvider.getCursor("crosshair", "mode"); 99 104 //loadPrefs(); 100 105 } … … 120 125 Main.map.mapView.addTemporaryLayer(this); 121 126 122 Main.map.mapView.setCursor(cursorDraw); 127 updateCursor(); 128 Collection<Way> selectedWays = Main.main.getCurrentDataSet().getSelectedWays(); 129 if (selectedWays!=null // if there is a selection 130 && selectedWays.size()==1 // and one way is selected 131 && line.getPoints().size()==0) /* and ther is no already drawn line */ { 132 // we can start drawing new way starting from old one 133 Way w = selectedWays.iterator().next(); 134 135 if (w.isNew()) loadFromWay(w); 136 } 123 137 124 138 try { … … 229 243 doKeyEvent((KeyEvent) event); 230 244 } 245 if (event.getID() == KeyEvent.KEY_RELEASED) { 246 doKeyReleaseEvent((KeyEvent) event); 247 } 231 248 updateCursor(); 232 249 // updateStatusLine(); … … 265 282 return; 266 283 } 267 284 startDrawing(e.getPoint()); 285 } 286 287 private void startDrawing(Point point) { 268 288 //if (line.isClosed()) { setStatusLine(tr(SIMPLIFYMODE_MESSAGE));return; } 269 289 drawing = true; 270 290 271 LatLon p = getLatLon(e);272 Node nd1 = getNearestNode( e.getPoint(), settings.maxDist);291 LatLon p = mv.getLatLon(point.x, point.y); 292 Node nd1 = getNearestNode(point, settings.maxDist); 273 293 if (nd1!=null) { 274 294 // found node, make it fixed point of the line … … 284 304 setStatusLine(tr("Please move the mouse to draw new way")); 285 305 repaint(); 286 287 306 } 288 307 289 308 @Override 290 309 public void mouseReleased(MouseEvent e) { 310 if (e.getButton() != MouseEvent.BUTTON1) return; 311 stopDrawing(); 312 } 313 314 private void stopDrawing() { 291 315 if (!isEnabled()) return; 292 if (e.getButton() != MouseEvent.BUTTON1) return;293 316 dragNode = -1; 294 317 drawing = false; 295 318 highlighted=null; 296 319 if (!line.isClosed()) setStatusLine(DRAWINGMODE_MESSAGE); 320 updateCursor(); 297 321 repaint(); 298 322 } … … 311 335 312 336 nearestIdx=line.findClosestPoint(e.getPoint(),settings.maxDist); 313 337 314 338 if (!drawing) { 315 339 if (dragNode>=0) { … … 329 353 return; 330 354 } 355 updateCursor(); 331 356 if (line.isClosed()) setStatusLine(SIMPLIFYMODE_MESSAGE); 332 357 … … 336 361 Point lastP = line.getLastPoint(); // last point of line fragment being edited 337 362 338 if (nearpoint){363 if (nearpoint){ 339 364 if ( Math.hypot(e.getX() - lastP.x, e.getY() - lastP.y) > 1e-2) { 340 365 line.addFixed(nd1.getCoor()); // snap to node coords … … 343 368 } else { 344 369 if (Math.hypot(e.getX() - lastP.x, e.getY() - lastP.y) > settings.minPixelsBetweenPoints) { 345 line.addLast(getLatLon(e)); // free mouse-drawing370 line.addLast(getLatLon(e)); // free mouse-drawing 346 371 repaint(); 347 372 } … … 353 378 private void doKeyEvent(KeyEvent e) { 354 379 /// System.out.println(e); 355 if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { 380 switch(e.getKeyCode()) { 381 case KeyEvent.VK_BACK_SPACE: 356 382 if (line.wasSimplified()) { 357 383 line.clearSimplifiedVersion(); … … 360 386 } 361 387 back(); 362 }363 if (e.getKeyCode() == KeyEvent.VK_ENTER) {388 break; 389 case KeyEvent.VK_ENTER: 364 390 // first Enter = simplify, second = save the way 365 391 if (!line.wasSimplified()) { … … 370 396 showSimplifyHint(); 371 397 } else saveAsWay(); 372 }373 if (e.getKeyCode() == KeyEvent.VK_DOWN) {398 break; 399 case KeyEvent.VK_DOWN: 374 400 // more details 375 401 e.consume(); 376 402 changeEpsilon(settings.epsilonMult); 377 }378 if (e.getKeyCode() == KeyEvent.VK_UP) {403 break; 404 case KeyEvent.VK_UP: 379 405 // less details 380 406 e.consume(); 381 407 changeEpsilon(1/settings.epsilonMult); 382 }383 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {408 break; 409 case KeyEvent.VK_ESCAPE: 384 410 // less details 385 411 e.consume(); 386 412 line.moveToTheEnd(); 387 }388 if (e.getKeyCode() == KeyEvent.VK_Q) {413 break; 414 case KeyEvent.VK_Q: 389 415 // less details 390 416 e.consume(); … … 398 424 } catch (SecurityException ex) { } 399 425 repaint(); 400 } 401 } 402 426 break; 427 case KeyEvent.VK_SPACE: 428 if (!drawing) { 429 Point p = Main.map.mapView.getMousePosition(); 430 if (p!=null) startDrawing(p); 431 } 432 break; 433 } 434 } 435 436 private void doKeyReleaseEvent(KeyEvent keyEvent) { 437 if (keyEvent.getKeyCode()==KeyEvent.VK_SPACE) stopDrawing(); 438 } 403 439 /** 404 440 * Updates shift and ctrl key states 405 441 */ 406 442 private void updateKeyModifiers(InputEvent e) { 407 oldCtrl = ctrl;408 oldShift = shift;409 443 ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 410 444 shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; … … 420 454 // <editor-fold defaultstate="collapsed" desc="Different action helper methods"> 421 455 public void newDrawing() { 456 delCmd=null; oldNodes=null; 422 457 eps=settings.startingEps; 423 458 line.clear(); … … 436 471 for (LatLon p : pts) { 437 472 Node nd=null; 438 if (line.isFixed(p)) {473 //if (line.isFixed(p)) { 439 474 // there may be a node with same ccoords! 440 475 nd = Main.map.mapView.getNearestNode(line.getPoint(p), OsmPrimitive.isUsablePredicate); 441 }476 //} 442 477 if (nd==null) { 443 478 if (i>0 && p.equals(first)) nd=firstNode; else { … … 466 501 } 467 502 } 468 cmds.add(new AddCommand(w)); 503 if (delCmd!=null) { 504 List<Node> nodes = w.getNodes(); 505 for (Node nd: oldNodes) { 506 // node from old way but not in new way 507 if (!nodes.contains(nd)) { 508 List<OsmPrimitive> refs = nd.getReferrers(); 509 // does someone need this node? if no-delete it. 510 if (refs.isEmpty()) cmds.add(new DeleteCommand(nd)); 511 } 512 } 513 cmds.add(new AddCommand(w)); 514 } else cmds.add(new AddCommand(w)); 469 515 Command c = new SequenceCommand(tr("Draw the way by mouse"), cmds); 470 516 Main.main.undoRedo.add(c); … … 524 570 if (ctrl) Main.map.mapView.setCursor(cursorCtrl); else 525 571 if (nearpoint) Main.map.mapView.setCursor(cursorCtrl); else 572 if (drawing) Main.map.mapView.setCursor(cursorDrawing); else 526 573 Main.map.mapView.setCursor(cursorDraw); 527 574 … … 548 595 +SIMPLIFYMODE_MESSAGE); 549 596 } 597 598 private void loadFromWay(Way w) { 599 List<LatLon> pts=line.getPoints(); 600 601 Collection<Command> cmds = new LinkedList<Command>(); 602 603 Node firstNode=null; 604 Object[] nodes = w.getNodes().toArray(); 605 int n=nodes.length; 606 if (w.isClosed()) n--; 607 for (int i=0;i<n;i++) { 608 Node nd=(Node) nodes[i]; 609 line.addLast(nd.getCoor()); 610 } 611 if (w.isClosed()) line.closeLine(); 612 oldNodes = w.getNodes(); 613 cmds.add(new DeleteCommand(w)); 614 delCmd = new SequenceCommand(tr("Convert way to FastDraw line"), cmds); 615 Main.main.undoRedo.add(delCmd); 616 } 617 550 618 } -
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawingPlugin.java
r26081 r26440 5 5 * Licence: GPL v2 or later 6 6 * Author: Alexei Kasatkin, 2011 7 * Ideas: Kotelnikov, Michael Barabanov (ticket #3840) 7 8 */ 8 9
Note:
See TracChangeset
for help on using the changeset viewer.