Changeset 26520 in osm for applications/editors/josm/plugins/FastDraw/src
- Timestamp:
- 2011-08-11T16:16:40+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawingMode.java
r26501 r26520 76 76 private final Cursor cursorNode; 77 77 private final Cursor cursorDrawing; 78 private boolean near point;78 private boolean nearSomeNode; 79 79 private LatLon highlighted; 80 80 private int nearestIdx; … … 218 218 g.setColor(lineColor); 219 219 g.drawLine(p1.x, p1.y, p2.x, p2.y); 220 // g.fillOval(p2.x - 5, p2.y - 5, 11, 11);221 220 if (line.isFixed(pp2)) { 222 221 lineColor=initLineColor; … … 246 245 } 247 246 } 248 if (settings.drawLastSegment && !drawing && !shift && nearestIdx<0 && !line.wasSimplified()) { 247 if (settings.drawLastSegment && !drawing && dragNode<0 && !shift && 248 nearestIdx<=0 && !line.wasSimplified()) { 249 249 // draw line to current point 250 250 g.setColor(lineColor); … … 259 259 if (lp!=null) g.drawOval(lp.x-r,lp.y-r,2*r,2*r); 260 260 } 261 262 261 } 263 262 … … 299 298 if (e.getButton() != MouseEvent.BUTTON1) return; 300 299 301 302 300 int idx=line.findClosestPoint(e.getPoint(),settings.maxDist); 303 301 if (idx==0 && !line.isClosed()) { … … 339 337 } 340 338 341 342 339 LatLon p = mv.getLatLon(point.x, point.y); 343 340 if (settings.snapNodes) { // find existing node near point and use it … … 384 381 deltaChanged=false; 385 382 Node nd1 = getNearestNode(e.getPoint(), settings.maxDist); 386 boolean near point2=nd1!=null;383 boolean nearSomeNode2=nd1!=null; 387 384 boolean needRepaint=false; 388 if (near point!=nearpoint2) {nearpoint=nearpoint2;updateCursor();needRepaint=true;}385 if (nearSomeNode!=nearSomeNode2) {nearSomeNode=nearSomeNode2;updateCursor();needRepaint=true;} 389 386 390 387 int nearestIdx2=line.findClosestPoint(e.getPoint(),settings.maxDist); … … 402 399 // find line fragment to highlight 403 400 LatLon h2=line.findBigSegment(e.getPoint()); 404 if (highlighted!=h2) { 405 highlighted=h2; 406 repaint(); 407 } 401 if (highlighted!=h2) { highlighted=h2; repaint(); } 408 402 } else if (needRepaint) { 409 403 repaint(); … … 418 412 Point lastP = line.getLastPoint(); // last point of line fragment being edited 419 413 420 if (nearpoint){ 421 if ( Math.hypot(e.getX() - lastP.x, e.getY() - lastP.y) > 1e-2) { 414 // free mouse-drawing 415 if (nearSomeNode){ 416 if (settings.snapNodes && Math.hypot(e.getX() - lastP.x, e.getY() - lastP.y) > 1e-2) { 422 417 line.addFixed(nd1.getCoor()); // snap to node coords 423 418 repaint(); … … 426 421 } else { 427 422 if (Math.hypot(e.getX() - lastP.x, e.getY() - lastP.y) > settings.minPixelsBetweenPoints) { 428 line.addLast(getLatLon(e)); // free mouse-drawing423 line.addLast(getLatLon(e)); // add new point 429 424 repaint(); 430 425 return; 431 426 } 432 427 } 433 if (nearpoint!=nearpoint2) {nearpoint=nearpoint2;updateCursor();}434 435 436 428 //statusText = getLatLon(e).toString(); updateStatusLine(); 437 429 } … … 488 480 e.consume(); 489 481 Point lastPoint = line.getLastPoint(); 490 line.moveToTheEnd();482 if (!line.isClosed()) line.moveToTheEnd(); 491 483 if (lastPoint==null || lastPoint.equals(line.getLastPoint())) { 492 484 if (line.getPoints().size()>5) { … … 562 554 List<LatLon> pts=line.getPoints(); 563 555 int n = pts.size(); 564 if (n == 0) return; 556 if (n < 2) return; //do not save oversimplified lines 557 if (line.isClosed() && n==2) return; 558 if (line.isClosed() && n==3) pts.remove(2); // two-point way can not be closed 565 559 566 560 Collection<Command> cmds = new LinkedList<Command>(); … … 574 568 //if (line.isFixed(p)) { 575 569 // there may be a node with same ccoords! 576 nd = Main.map.mapView.getNearestNode(line.getPoint(p), OsmPrimitive.is UsablePredicate);570 nd = Main.map.mapView.getNearestNode(line.getPoint(p), OsmPrimitive.isSelectablePredicate); 577 571 //} 578 572 if (nd!=null) if (p.greatCircleDistance(nd.getCoor())>0.01) nd=null; … … 646 640 deltaChanged=true; 647 641 648 setStatusLine(tr("min distance={0} p ixels or {1} m",(int)settings.minPixelsBetweenPoints,642 setStatusLine(tr("min distance={0} px ({1} m)",(int)settings.minPixelsBetweenPoints, 649 643 mv.getDist100Pixel()/100*settings.minPixelsBetweenPoints)); 650 644 repaint(); … … 705 699 private void updateCursor() { 706 700 if (shift) Main.map.mapView.setCursor(cursorShift); else 707 if (line.isClosed() ) Main.map.mapView.setCursor(cursorReady); else701 if (line.isClosed() || (nearestIdx==0)) Main.map.mapView.setCursor(cursorReady); else 708 702 if (ctrl) Main.map.mapView.setCursor(cursorCtrl); else 709 if (near point) Main.map.mapView.setCursor(cursorCtrl); else703 if (nearSomeNode && settings.snapNodes) Main.map.mapView.setCursor(cursorCtrl); else 710 704 if (drawing) Main.map.mapView.setCursor(cursorDrawing); else 711 705 Main.map.mapView.setCursor(cursorDraw); 712 713 714 706 } 715 707 … … 722 714 723 715 private Node getNearestNode(Point point, double maxDist) { 724 Node nd = Main.map.mapView.getNearestNode(point, OsmPrimitive.is UsablePredicate);716 Node nd = Main.map.mapView.getNearestNode(point, OsmPrimitive.isSelectablePredicate); 725 717 if (nd!=null && line.getPoint(nd.getCoor()).distance(point)<=maxDist) return nd; 726 718 else return null;
Note:
See TracChangeset
for help on using the changeset viewer.