Ignore:
Timestamp:
2011-06-08T20:57:27+02:00 (13 years ago)
Author:
akks
Message:

FastDraw: added node dragging, repaired closed line improvements

Location:
applications/editors/josm/plugins/turbopen/src/org/openstreetmap/josm/plugins/fastdraw
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/turbopen/src/org/openstreetmap/josm/plugins/fastdraw/DrawnPolyLine.java

    r26106 r26111  
    2020   
    2121    private int lastIdx;
    22 
     22    private boolean closedFlag;
     23
     24    public DrawnPolyLine() {
     25        clear();
     26    }
    2327    public void setMv(MapView mv) {
    2428        this.mv = mv;
     
    5660        used=null;
    5761        lastIdx=0;
     62        closedFlag=false;
    5863        fixed.clear();
    5964        simplePoints=null;
     
    6671        lastIdx--;
    6772        }
    68        
    6973    }
    7074   
     
    7882    }
    7983    void addLast(LatLon coor) {
     84        if (closedFlag && lastIdx>points.size()-1) return;
    8085        if (lastIdx>=points.size()-1) {
    8186            //System.out.println("add last "+points.size());
     
    177182    void closeLine() {
    178183        points.add(points.getFirst());
     184        closedFlag=true;
     185    }
     186    boolean isClosed() {
     187        return closedFlag;
    179188    }
    180189   
     
    201210            }if (f &&(!it.hasNext())) {
    202211                // if end of whole line reached
     212                closedFlag=false;
    203213                it.remove();
    204214                lastIdx=points.size()-1;
     
    273283    }
    274284
     285    void moveNode(int dragNode, LatLon coor) {
     286        LatLon dragged = points.get(dragNode);
     287        // points.getLast().equals(points.getFirst()
     288        if (closedFlag && points.getFirst().equals(dragged)) {
     289            // move both ends
     290            points.set(0, coor);
     291            points.set(points.size()-1, coor);
     292        } else {
     293            points.set(dragNode, coor);
     294        }
     295        if (fixed.contains(dragged)) {
     296                fixed.remove(dragged);
     297                fixed.add(coor);
     298         }
     299    }
     300
    275301}
  • applications/editors/josm/plugins/turbopen/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawingMode.java

    r26106 r26111  
    8282    private final Stroke strokeForSimplified;
    8383    private final Stroke strokeForOriginal;
    84     private boolean ready;
    8584    private final Cursor cursorDraw;
    8685    private final Cursor cursorCtrl;
     
    9291    private int nearestIdx;
    9392    private Stroke strokeForDelete;
     93    private int dragNode=-1;
    9494   
    9595
     
    195195                p2 = line.getPoint(pp2);
    196196                if (shift && highlighted==pp1 && nearestIdx<0) {lineColor=COLOR_SELECTEDFRAGMENT;}
    197                 if (line.isLastPoint(i)) { lineColor=COLOR_EDITEDFRAGMENT; }
     197                if (!shift && line.isLastPoint(i)) { lineColor=COLOR_EDITEDFRAGMENT; }
    198198                g.setColor(lineColor);
    199199                g.drawLine(p1.x, p1.y, p2.x, p2.y);
     
    206206                    g.fillRect(p2.x - 1, p2.y - 1, 3, 3);
    207207                }
    208                 if (shift && !line.wasSimplified() && nearestIdx==i+1 ) {
    209                     // highlight node to delete
    210                     g.setStroke(strokeForDelete);
    211                     g.setColor(COLOR_DELETE);
    212                     g.drawLine(p2.x - 5, p2.y - 5,p2.x + 5, p2.y + 5);
    213                     g.drawLine(p2.x - 5, p2.y + 5,p2.x + 5, p2.y - 5);
    214                     g.setStroke(strokeForOriginal);
    215                 }
    216                 if (ctrl && !line.wasSimplified() && nearestIdx==i+1 ) {
    217                     // highlight node to toggle fixation
    218                     g.setStroke(strokeForDelete);
    219                     g.setColor( line.isFixed(pp2) ? COLOR_NORMAL: COLOR_FIXED);
    220                     g.drawOval(p2.x - 5, p2.y - 5, 11, 11);
    221                     g.setStroke(strokeForOriginal);
     208                if (!drawing) {
     209                    if (shift && !line.wasSimplified() && nearestIdx==i+1 ) {
     210                        // highlight node to delete
     211                        g.setStroke(strokeForDelete);
     212                        g.setColor(COLOR_DELETE);
     213                        g.drawLine(p2.x - 5, p2.y - 5,p2.x + 5, p2.y + 5);
     214                        g.drawLine(p2.x - 5, p2.y + 5,p2.x + 5, p2.y - 5);
     215                        g.setStroke(strokeForOriginal);
     216                    }
     217                    if (ctrl && !line.wasSimplified() && nearestIdx==i+1 ) {
     218                        // highlight node to toggle fixation
     219                        g.setStroke(strokeForDelete);
     220                        g.setColor( line.isFixed(pp2) ? COLOR_NORMAL: COLOR_FIXED);
     221                        g.drawOval(p2.x - 5, p2.y - 5, 11, 11);
     222                        g.setStroke(strokeForOriginal);
     223                    }
    222224                }
    223225            }
     
    247249       
    248250        int idx=line.findClosestPoint(e.getPoint(),maxDist);
    249         if (idx==0) {
     251        if (idx==0 && !line.isClosed()) {
    250252            line.closeLine();
    251253            // the way should become closed
    252254            drawing=false;
    253             ready=true;
     255            dragNode=0;
    254256            updateCursor();
    255257            return;
     
    267269                line.toggleFixed(idx);               
    268270            }
     271            // node dragging
     272            dragNode=idx;
    269273            return;
    270274        }
    271        
    272         if (ready) { setStatusLine(tr(SIMPLIFYMODE_MESSAGE)); return;  }
     275
     276        //if (line.isClosed()) { setStatusLine(tr(SIMPLIFYMODE_MESSAGE));return;  }
    273277        drawing = true;
    274278       
     
    295299        if (!isEnabled()) return;
    296300        if (e.getButton() != MouseEvent.BUTTON1) return;
     301        dragNode = -1;
    297302        drawing = false;
    298303        highlighted=null;
    299         if (!ready) setStatusLine(tr(DRAWINGMODE_MESSAGE));
     304        if (!line.isClosed()) setStatusLine(tr(DRAWINGMODE_MESSAGE));
    300305        repaint();
    301306    }
     
    316321       
    317322        if (!drawing) {
     323            if (dragNode>=0) {
     324                line.moveNode(dragNode,getLatLon(e));
     325                repaint();
     326                return;
     327            }
     328
    318329            if (shift) {
    319330                // find line fragment to highlight
     
    326337            return;
    327338        }
    328         if (ready) setStatusLine(tr(SIMPLIFYMODE_MESSAGE));
     339        if (line.isClosed()) setStatusLine(tr(SIMPLIFYMODE_MESSAGE));
    329340       
    330341        // do not draw points close to existing points - we do not want self-intersections
     
    404415    public void newDrawing() {
    405416        eps=startingEps;
    406         ready=false;
    407417        line.clear();
    408418    }
     
    532542    private void updateCursor() {
    533543        if (shift) Main.map.mapView.setCursor(cursorShift); else
    534         if (ready) Main.map.mapView.setCursor(cursorReady); else
     544        if (line.isClosed()) Main.map.mapView.setCursor(cursorReady); else
    535545        if (ctrl) Main.map.mapView.setCursor(cursorCtrl); else
    536546        if (nearpoint) Main.map.mapView.setCursor(cursorCtrl); else
Note: See TracChangeset for help on using the changeset viewer.