Changeset 5922 in josm for trunk/src


Ignore:
Timestamp:
2013-05-03T17:35:04+02:00 (12 years ago)
Author:
akks
Message:

Avoid duplicate and very near points in Angle snapping draw mode
(will reuse existing nodes in mappaint.node.snap-distance pixel radius if possible)
+DrawAction minor code cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r5909 r5922  
    6666import org.openstreetmap.josm.gui.MapFrame;
    6767import org.openstreetmap.josm.gui.MapView;
     68import org.openstreetmap.josm.gui.NavigatableComponent;
    6869import org.openstreetmap.josm.gui.layer.Layer;
    6970import org.openstreetmap.josm.gui.layer.MapViewPaintable;
     
    8687    private Node lastUsedNode = null;
    8788    private double PHI=Math.toRadians(90);
     89    private double toleranceMultiplier;
    8890
    8991    private Node mouseOnExistingNode;
     
    215217        wayIsFinished = currentBaseNode == null;
    216218
     219        toleranceMultiplier = 0.01 * NavigatableComponent.PROP_SNAP_DISTANCE.get();
     220
    217221        snapHelper.init();
    218222        snapCheckboxMenuItem.getAction().setEnabled(true);
     
    276280     * redraw to (possibly) get rid of helper line if selection changes.
    277281     */
     282    @Override
    278283    public void eventDispatched(AWTEvent event) {
    279284        if(Main.map == null || Main.map.mapView == null || !Main.map.mapView.isActiveLayerDrawable())
     
    335340     * redraw to (possibly) get rid of helper line if selection changes.
    336341     */
     342    @Override
    337343    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    338344        if(!Main.map.mapView.isActiveLayerDrawable())
     
    450456                // project found node to snapping line
    451457                newEN = snapHelper.getSnapPoint(foundPoint);
    452                 if (foundPoint.distance(newEN) > 1e-4) {
     458                // do not add new node if there is some node within snapping distance
     459                double tolerance = Main.map.mapView.getDist100Pixel() * toleranceMultiplier;
     460                if (foundPoint.distance(newEN) > tolerance) {
    453461                    n = new Node(newEN); // point != projected, so we create new node
    454462                    newNode = true;
     
    631639        if (n != null && Main.map.mapView.viewportFollowing) {
    632640            Main.map.mapView.smoothScrollTo(n.getEastNorth());
    633         };
     641        }
    634642        computeHelperLine();
    635643        removeHighlighting();
     
    10821090
    10831091        // This happens when nothing is selected, but we still want to highlight the "target node"
    1084         if (mouseOnExistingNode == null && getCurrentDataSet().getSelected().size() == 0
     1092        if (mouseOnExistingNode == null && getCurrentDataSet().getSelected().isEmpty()
    10851093                && mousePos != null) {
    10861094            mouseOnExistingNode = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isSelectablePredicate);
     
    10951103
    10961104        // Insert the node into all the nearby way segments
    1097         if (mouseOnExistingWays.size() == 0) {
     1105        if (mouseOnExistingWays.isEmpty()) {
    10981106            Main.map.mapView.setNewCursor(cursor, this);
    10991107            redrawIfRequired();
     
    11151123    }
    11161124
     1125    @Override
    11171126    public void paint(Graphics2D g, MapView mv, Bounds box) {
    11181127        // sanity checks
     
    16851694        MouseListener anglePopupListener = new PopupMenuLauncher( new JPopupMenu() {
    16861695            JCheckBoxMenuItem repeatedCb = new JCheckBoxMenuItem(new AbstractAction(tr("Toggle snapping by {0}", getShortcut().getKeyText())){
    1687                 public void actionPerformed(ActionEvent e) {
     1696                @Override public void actionPerformed(ActionEvent e) {
    16881697                    boolean sel=((JCheckBoxMenuItem) e.getSource()).getState();
    16891698                    Main.pref.put("draw.anglesnap.toggleOnRepeatedA", sel);
     
    16921701            });
    16931702            JCheckBoxMenuItem helperCb = new JCheckBoxMenuItem(new AbstractAction(tr("Show helper geometry")){
    1694                 public void actionPerformed(ActionEvent e) {
     1703                @Override public void actionPerformed(ActionEvent e) {
    16951704                    boolean sel=((JCheckBoxMenuItem) e.getSource()).getState();
    16961705                    Main.pref.put("draw.anglesnap.drawConstructionGeometry", sel);
     
    17021711            });
    17031712            JCheckBoxMenuItem projectionCb = new JCheckBoxMenuItem(new AbstractAction(tr("Snap to node projections")){
    1704                 public void actionPerformed(ActionEvent e) {
     1713                @Override public void actionPerformed(ActionEvent e) {
    17051714                    boolean sel=((JCheckBoxMenuItem) e.getSource()).getState();
    17061715                    Main.pref.put("draw.anglesnap.projectionsnap", sel);
     
    17171726                add(projectionCb);;
    17181727                add(new AbstractAction(tr("Disable")) {
    1719                     public void actionPerformed(ActionEvent e) {
     1728                    @Override public void actionPerformed(ActionEvent e) {
    17201729                        saveAngles("180");
    17211730                        init();
     
    17241733                });
    17251734                add(new AbstractAction(tr("0,90,...")) {
    1726                     public void actionPerformed(ActionEvent e) {
     1735                    @Override public void actionPerformed(ActionEvent e) {
    17271736                        saveAngles("0","90","180");
    17281737                        init();
     
    17311740                });
    17321741                add(new AbstractAction(tr("0,45,90,...")) {
    1733                     public void actionPerformed(ActionEvent e) {
     1742                    @Override public void actionPerformed(ActionEvent e) {
    17341743                        saveAngles("0","45","90","135","180");
    17351744                        init();
     
    17381747                });
    17391748                add(new AbstractAction(tr("0,30,45,60,90,...")) {
    1740                     public void actionPerformed(ActionEvent e) {
     1749                    @Override public void actionPerformed(ActionEvent e) {
    17411750                        saveAngles("0","30","45","60","90","120","135","150","180");
    17421751                        init();
Note: See TracChangeset for help on using the changeset viewer.