Changeset 29453 in osm


Ignore:
Timestamp:
2013-04-01T18:02:44+02:00 (11 years ago)
Author:
akks
Message:

JOSM/FastDraw: changed default parameters, fix duplicate point issue, corrected ESC behavior

Location:
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw
Files:
5 edited

Legend:

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

    r29263 r29453  
    99import java.util.Set;
    1010import org.openstreetmap.josm.data.coor.LatLon;
    11 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1211import org.openstreetmap.josm.gui.MapView;
    1312
     
    9493
    9594    void addFixed(LatLon coor) {
    96          addLast(coor);
     95        addLast(coor);
    9796        fixed.add(coor);
    9897    }
     
    10099        if (closedFlag && lastIdx>points.size()-1) return;
    101100        if (lastIdx>=points.size()-1) {
    102             //System.out.println("add last "+points.size());
    103             points.addLast(coor);if (points.size()>1) lastIdx++;
    104             //System.out.println("lastIdx="+lastIdx);
    105             }
    106         else {points.add(lastIdx+1, coor); lastIdx++;
    107             //System.out.println("add at "+lastIdx+"/"+points.size());
     101            //
     102            if (points.isEmpty() || !coor.equals(points.getLast())) {
     103                points.addLast(coor);
     104                if (points.size()>1) lastIdx++;
     105                }
     106        } else {
     107            // insert point into midlle of the line
     108            if (points.isEmpty() || !coor.equals(points.get(lastIdx))) {
     109                points.add(lastIdx+1, coor);
     110                lastIdx++;
     111            }
    108112        }
    109113    }
  • applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FDSettings.java

    r29303 r29453  
    5050        //deltaLatLon = Main.pref.getDouble("fastdraw.deltasearch", 0.01);
    5151        minPixelsBetweenPoints = Main.pref.getDouble("fastdraw.mindelta", 20);
    52         startingEps = Main.pref.getDouble("fastdraw.startingEps", 0.1);
    53         maxPointsPerKm = Main.pref.getDouble("fastdraw.maxpkm", 20);
     52        startingEps = Main.pref.getDouble("fastdraw.startingEps", 5);
     53        maxPointsPerKm = Main.pref.getDouble("fastdraw.maxpkm", 150);
    5454        pkmBlockSize = Main.pref.getInteger("fastdraw.pkmblocksize", 10);
    5555        drawLastSegment = Main.pref.getBoolean("fastdraw.drawlastsegment", true);
  • applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawConfigDialog.java

    r29317 r29453  
    1 /*
    2  * To change this template, choose Tools | Templates
    3  * and open the template in the editor.
    4  */
    51package org.openstreetmap.josm.plugins.fastdraw;
    62
  • applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawingMode.java

    r29303 r29453  
    11/*
    2  * This file is part of ImproveWayAccuracy plugin for JOSM.
    3  * http://wiki.openstreetmap.org/wiki/JOSM/Plugins/ImproveWayAccuracy
    4  *
    52 * Licence: GPL v2 or later
    63 * Author:  Alexei Kasatkin, 2011
     
    1310import java.awt.BasicStroke;
    1411import java.awt.Color;
    15 import java.awt.Point;
    16 import java.awt.event.MouseEvent;
    17 import org.openstreetmap.josm.data.coor.LatLon;
    18 import org.openstreetmap.josm.data.osm.Tag;
    19 import static org.openstreetmap.josm.tools.I18n.tr;
    20 
    2112import java.awt.Cursor;
    2213import java.awt.Graphics2D;
     14import java.awt.Point;
    2315import java.awt.Stroke;
    2416import java.awt.Toolkit;
    25 import java.awt.event.AWTEventListener;
    26 import java.awt.event.ActionEvent;
    27 import java.awt.event.ActionListener;
    28 import java.awt.event.InputEvent;
    29 import java.awt.event.KeyEvent;
     17import java.awt.event.*;
    3018import java.util.*;
    3119import javax.swing.JOptionPane;
     
    4028import org.openstreetmap.josm.command.SequenceCommand;
    4129import org.openstreetmap.josm.data.Bounds;
     30import org.openstreetmap.josm.data.coor.LatLon;
     31import org.openstreetmap.josm.data.osm.Tag;
    4232import org.openstreetmap.josm.data.osm.Node;
    4333import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    5242import org.openstreetmap.josm.tools.Shortcut;
    5343import org.openstreetmap.josm.tools.TextTagParser;
     44
     45import static org.openstreetmap.josm.tools.I18n.tr;
    5446
    5547class FastDrawingMode extends MapMode implements MapViewPaintable,
     
    9183    private boolean lineWasSaved;
    9284    private boolean deltaChanged;
    93     private final int mainKeyCode;
     85    /**
     86     * used for skipping keyboard AWTTevents while dialogs are active
     87     */
     88    private boolean listenKeys = false;
    9489   
    9590    FastDrawingMode(MapFrame mapFrame) {
     
    105100        cursorDrawing = ImageProvider.getCursor("crosshair", "mode");
    106101        //loadPrefs();
    107         mainKeyCode = getShortcut().getKeyStroke().getKeyCode();
    108102    }
    109103
     
    147141        });
    148142       
     143        listenKeys = true;
    149144        try {
    150145            Toolkit.getDefaultToolkit().addAWTEventListener(this,
     
    265260    @Override
    266261    public void eventDispatched(AWTEvent event) {
    267         if (Main.map == null || Main.map.mapView == null
     262        if (!listenKeys || Main.map == null || Main.map.mapView == null
    268263                || !Main.map.mapView.isActiveLayerDrawable()) {
    269264            return;
     
    485480        break;
    486481        case KeyEvent.VK_ESCAPE:
    487             // less details
    488482            e.consume();
    489483            Point lastPoint = line.getLastPoint();
     
    491485            if (lastPoint==null || lastPoint.equals(line.getLastPoint())) {
    492486                 if (line.getPoints().size()>5) {
    493                  boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
    494                     "delete_drawn_line", Main.parent,
    495                     tr("Are you sure you do not want to save the line containing {0} points?",
    496                          line.getPoints().size()), tr("Delete confirmation"),
    497                     JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_OPTION );
    498                  if(!answer) break;
     487                    // no key events while the dialog is active!
     488                    listenKeys = false;
     489                    boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
     490                       "delete_drawn_line", Main.parent,
     491                       tr("Are you sure you do not want to save the line containing {0} points?",
     492                            line.getPoints().size()), tr("Delete confirmation"),
     493                       JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_OPTION );
     494                    listenKeys = true;
     495                    if(!answer) break;
    499496                }
    500497                newDrawing(); // stop drawing
     
    505502       
    506503        case KeyEvent.VK_I:
     504           listenKeys = false;
    507505           JOptionPane.showMessageDialog(Main.parent,
    508506                        tr("{0} m - length of the line\n{1} nodes\n{2} points per km (maximum)\n{3} points per km (average)",
     
    510508                        line.getNodesPerKm(1000000)),
    511509                        tr("Line information"),JOptionPane.INFORMATION_MESSAGE);
     510           listenKeys = true;
    512511        break;           
    513512        case KeyEvent.VK_Q:
     
    515514            e.consume();
    516515            try {
    517                 Toolkit.getDefaultToolkit().removeAWTEventListener(this);
     516                listenKeys = false;
    518517                new FastDrawConfigDialog(settings);
    519518                if (line.wasSimplified()) {
     
    522521                }
    523522                //System.out.println("final eps="+eps);
    524                 Toolkit.getDefaultToolkit().addAWTEventListener(this,
    525                     AWTEvent.KEY_EVENT_MASK);
     523                listenKeys = true;
    526524            } catch (SecurityException ex) {  }
    527525            repaint();
     
    560558// <editor-fold defaultstate="collapsed" desc="Different action helper methods">
    561559    public void newDrawing() {
     560        if (delCmd!=null) delCmd.undoCommand();
    562561        delCmd=null; oldNodes=null;
    563562        eps=settings.startingEps;
     
    580579        for (LatLon p : pts) {
    581580            Node nd=null;
    582             //if (line.isFixed(p)) {
    583                 // there may be a node with same ccoords!
    584                 nd = Main.map.mapView.getNearestNode(line.getPoint(p), OsmPrimitive.isSelectablePredicate);
    585             //}
    586             if (nd!=null) if (p.greatCircleDistance(nd.getCoor())>0.01) nd=null;
     581 
     582            nd = Main.map.mapView.getNearestNode(line.getPoint(p), OsmPrimitive.isSelectablePredicate);
     583            // there may be a node with the same coords!
     584           
     585            if (nd!=null && p.greatCircleDistance(nd.getCoor())>0.01) nd=null;
    587586            if (nd==null) {
    588587                if (i>0 && p.equals(first)) nd=firstNode; else {
     
    627626                }
    628627            }
     628            delCmd = null; // that is all with this command
    629629            cmds.add(new AddCommand(w));
    630630        } else cmds.add(new AddCommand(w));
  • applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawingPlugin.java

    r26440 r29453  
    11/*
    2  * This file is part of ImproveWayAccuracy plugin for JOSM.
    3  * http://wiki.openstreetmap.org/wiki/JOSM/Plugins/ImproveWayAccuracy
    4  *
    52 * Licence: GPL v2 or later
    63 * Author:  Alexei Kasatkin, 2011
Note: See TracChangeset for help on using the changeset viewer.