Ignore:
Timestamp:
2011-08-11T16:16:40+02:00 (13 years ago)
Author:
akks
Message:

'FastDraw: snapping fixed, do not save degenerate lines'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawingMode.java

    r26501 r26520  
    7676    private final Cursor cursorNode;
    7777    private final Cursor cursorDrawing;
    78     private boolean nearpoint;
     78    private boolean nearSomeNode;
    7979    private LatLon highlighted;
    8080    private int nearestIdx;
     
    218218                g.setColor(lineColor);
    219219                g.drawLine(p1.x, p1.y, p2.x, p2.y);
    220   //                  g.fillOval(p2.x - 5, p2.y - 5, 11, 11);
    221220                if (line.isFixed(pp2)) {
    222221                    lineColor=initLineColor;
     
    246245            }
    247246        }
    248         if (settings.drawLastSegment && !drawing && !shift && nearestIdx<0 && !line.wasSimplified()) {
     247        if (settings.drawLastSegment && !drawing && dragNode<0  && !shift &&
     248                nearestIdx<=0 && !line.wasSimplified()) {
    249249            // draw line to current point
    250250            g.setColor(lineColor);
     
    259259            if (lp!=null) g.drawOval(lp.x-r,lp.y-r,2*r,2*r);
    260260        }
    261 
    262261    }
    263262
     
    299298        if (e.getButton() != MouseEvent.BUTTON1) return;
    300299
    301 
    302300        int idx=line.findClosestPoint(e.getPoint(),settings.maxDist);
    303301        if (idx==0 && !line.isClosed()) {
     
    339337        }
    340338
    341 
    342339        LatLon p = mv.getLatLon(point.x, point.y);
    343340        if (settings.snapNodes) { // find existing node near point and use it
     
    384381        deltaChanged=false;
    385382        Node nd1 = getNearestNode(e.getPoint(), settings.maxDist);
    386         boolean nearpoint2=nd1!=null;
     383        boolean nearSomeNode2=nd1!=null;
    387384        boolean needRepaint=false;
    388         if (nearpoint!=nearpoint2) {nearpoint=nearpoint2;updateCursor();needRepaint=true;}
     385        if (nearSomeNode!=nearSomeNode2) {nearSomeNode=nearSomeNode2;updateCursor();needRepaint=true;}
    389386
    390387        int nearestIdx2=line.findClosestPoint(e.getPoint(),settings.maxDist);
     
    402399                // find line fragment to highlight
    403400                LatLon h2=line.findBigSegment(e.getPoint());
    404                 if (highlighted!=h2) {
    405                     highlighted=h2;
    406                     repaint();
    407                 }
     401                if (highlighted!=h2) { highlighted=h2; repaint(); }
    408402            } else if (needRepaint) {
    409403                repaint();
     
    418412        Point lastP = line.getLastPoint(); // last point of line fragment being edited
    419413
    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) {
    422417                line.addFixed(nd1.getCoor()); // snap to node coords
    423418                repaint();
     
    426421        } else {
    427422            if (Math.hypot(e.getX() - lastP.x, e.getY() - lastP.y) > settings.minPixelsBetweenPoints) {
    428                 line.addLast(getLatLon(e)); // free mouse-drawing
     423                line.addLast(getLatLon(e)); // add new point
    429424                repaint();
    430425                return;
    431426            }
    432427        }
    433         if (nearpoint!=nearpoint2) {nearpoint=nearpoint2;updateCursor();}
    434 
    435 
    436428        //statusText = getLatLon(e).toString();        updateStatusLine();
    437429    }
     
    488480            e.consume();
    489481            Point lastPoint = line.getLastPoint();
    490             line.moveToTheEnd();
     482            if (!line.isClosed()) line.moveToTheEnd();
    491483            if (lastPoint==null || lastPoint.equals(line.getLastPoint())) {
    492484                 if (line.getPoints().size()>5) {
     
    562554        List<LatLon> pts=line.getPoints();
    563555        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
    565559
    566560        Collection<Command> cmds = new LinkedList<Command>();
     
    574568            //if (line.isFixed(p)) {
    575569                // there may be a node with same ccoords!
    576                 nd = Main.map.mapView.getNearestNode(line.getPoint(p), OsmPrimitive.isUsablePredicate);
     570                nd = Main.map.mapView.getNearestNode(line.getPoint(p), OsmPrimitive.isSelectablePredicate);
    577571            //}
    578572            if (nd!=null) if (p.greatCircleDistance(nd.getCoor())>0.01) nd=null;
     
    646640        deltaChanged=true;
    647641       
    648         setStatusLine(tr("min distance={0} pixels or {1} m",(int)settings.minPixelsBetweenPoints,
     642        setStatusLine(tr("min distance={0} px ({1} m)",(int)settings.minPixelsBetweenPoints,
    649643                mv.getDist100Pixel()/100*settings.minPixelsBetweenPoints));
    650644        repaint();
     
    705699    private void updateCursor() {
    706700        if (shift) Main.map.mapView.setCursor(cursorShift); else
    707         if (line.isClosed()) Main.map.mapView.setCursor(cursorReady); else
     701        if (line.isClosed() || (nearestIdx==0)) Main.map.mapView.setCursor(cursorReady); else
    708702        if (ctrl) Main.map.mapView.setCursor(cursorCtrl); else
    709         if (nearpoint) Main.map.mapView.setCursor(cursorCtrl); else
     703        if (nearSomeNode && settings.snapNodes) Main.map.mapView.setCursor(cursorCtrl); else
    710704        if (drawing) Main.map.mapView.setCursor(cursorDrawing); else
    711705        Main.map.mapView.setCursor(cursorDraw);
    712 
    713 
    714706    }
    715707
     
    722714
    723715    private Node getNearestNode(Point point, double maxDist) {
    724        Node nd = Main.map.mapView.getNearestNode(point, OsmPrimitive.isUsablePredicate);
     716       Node nd = Main.map.mapView.getNearestNode(point, OsmPrimitive.isSelectablePredicate);
    725717       if (nd!=null && line.getPoint(nd.getCoor()).distance(point)<=maxDist) return nd;
    726718       else return null;
Note: See TracChangeset for help on using the changeset viewer.