Changeset 5287 in josm for trunk


Ignore:
Timestamp:
2012-06-20T21:57:46+02:00 (12 years ago)
Author:
Don-vip
Message:

fix #5764, fix #5773 - Do not create delete commands for objects that already have been deleted, silently drop the related error in validator dialog

Location:
trunk/src/org/openstreetmap/josm
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/Test.java

    r5269 r5287  
    1212import javax.swing.JPanel;
    1313
     14import org.openstreetmap.josm.Main;
    1415import org.openstreetmap.josm.command.Command;
     16import org.openstreetmap.josm.command.DeleteCommand;
    1517import org.openstreetmap.josm.data.osm.Node;
    1618import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    223225        return progressMonitor.isCanceled();
    224226    }
     227   
     228    /**
     229     * Build a Delete command on all primitives that have not yet been deleted manually by user, or by another error fix.
     230     * If all primitives have already been deleted, null is returned.
     231     * @param primitives The primitives wanted for deletion
     232     * @return a Delete command on all primitives that have not yet been deleted, or null otherwise
     233     */
     234    protected final Command deletePrimitivesIfNeeded(Collection<? extends OsmPrimitive> primitives) {
     235        Collection<OsmPrimitive> primitivesToDelete = new ArrayList<OsmPrimitive>();
     236        for (OsmPrimitive p : primitives) {
     237            if (!p.isDeleted()) {
     238                primitivesToDelete.add(p);
     239            }
     240        }
     241        if (!primitivesToDelete.isEmpty()) {
     242            return DeleteCommand.delete(Main.map.mapView.getEditLayer(), primitivesToDelete);
     243        } else {
     244            return null;
     245        }
     246    }
    225247}
  • trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateNode.java

    r5060 r5287  
    373373        LinkedHashSet<Node> nodes = new LinkedHashSet<Node>(OsmPrimitive.getFilteredList(sel, Node.class));
    374374
    375         // Use first existing node or first node if all nodes are new
    376         Node target = null;
    377         for (Node n: nodes) {
    378             if (!n.isNew()) {
    379                 target = n;
    380                 break;
    381             }
    382         }
    383         if (target == null) {
    384             target = nodes.iterator().next();
    385         }
    386 
    387         if (DeleteCommand.checkAndConfirmOutlyingDelete(Main.main.getCurrentDataSet().getDataSourceArea(), nodes, Collections.singleton(target)))
    388             return MergeNodesAction.mergeNodes(Main.main.getEditLayer(), nodes, target);
     375        // Filter nodes that have already been deleted (see #5764 and #5773)
     376        for (Iterator<Node> it = nodes.iterator(); it.hasNext();) {
     377            if (it.next().isDeleted()) {
     378                it.remove();
     379            }
     380        }
     381
     382        // Merge only if at least 2 nodes remain
     383        if (nodes.size() >= 2) {
     384            // Use first existing node or first node if all nodes are new
     385            Node target = null;
     386            for (Node n: nodes) {
     387                if (!n.isNew()) {
     388                    target = n;
     389                    break;
     390                }
     391            }
     392            if (target == null) {
     393                target = nodes.iterator().next();
     394            }
     395   
     396            if (DeleteCommand.checkAndConfirmOutlyingDelete(Main.main.getCurrentDataSet().getDataSourceArea(), nodes, Collections.singleton(target)))
     397                return MergeNodesAction.mergeNodes(Main.main.getEditLayer(), nodes, target);
     398        }
    389399
    390400        return null;// undoRedo handling done in mergeNodes
  • trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicatedWayNodes.java

    r4869 r5287  
    77import java.util.Collections;
    88
    9 import org.openstreetmap.josm.Main;
    109import org.openstreetmap.josm.command.ChangeCommand;
    1110import org.openstreetmap.josm.command.Command;
    12 import org.openstreetmap.josm.command.DeleteCommand;
    1311import org.openstreetmap.josm.data.osm.Node;
    1412import org.openstreetmap.josm.data.osm.Way;
     
    6159        if (wnew.getNodesCount() < 2)
    6260            // Empty way, delete
    63             return DeleteCommand.delete(Main.map.mapView.getEditLayer(), Collections.singleton(w));
     61            return deletePrimitivesIfNeeded(Collections.singleton(w));
    6462        else
    6563            return new ChangeCommand(w, wnew);
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UntaggedNode.java

    r4806 r5287  
    88import java.util.Map;
    99
    10 import org.openstreetmap.josm.Main;
    1110import org.openstreetmap.josm.command.Command;
    12 import org.openstreetmap.josm.command.DeleteCommand;
    1311import org.openstreetmap.josm.data.osm.Node;
    1412import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    110108    @Override
    111109    public Command fixError(TestError testError) {
    112         return DeleteCommand.delete(Main.map.mapView.getEditLayer(), testError.getPrimitives());
     110        return deletePrimitivesIfNeeded(testError.getPrimitives());
    113111    }
    114112
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UntaggedWay.java

    r4806 r5287  
    1111import org.openstreetmap.josm.Main;
    1212import org.openstreetmap.josm.command.Command;
    13 import org.openstreetmap.josm.command.DeleteCommand;
    1413import org.openstreetmap.josm.data.osm.Relation;
    1514import org.openstreetmap.josm.data.osm.RelationMember;
     
    142141    @Override
    143142    public Command fixError(TestError testError) {
    144         return DeleteCommand.delete(Main.map.mapView.getEditLayer(), testError.getPrimitives());
     143        return deletePrimitivesIfNeeded(testError.getPrimitives());
    145144    }
    146145}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java

    r5266 r5287  
    2525import javax.swing.JOptionPane;
    2626import javax.swing.JPopupMenu;
    27 import javax.swing.KeyStroke;
    2827import javax.swing.SwingUtilities;
    2928import javax.swing.event.TreeSelectionEvent;
     
    570569                    if (this.canceled)
    571570                        return;
    572                     final Command fixCommand = error.getFix();
    573                     if (fixCommand != null) {
    574                         SwingUtilities.invokeAndWait(new Runnable() {
    575                             @Override
    576                             public void run() {
    577                                 Main.main.undoRedo.addNoRedraw(fixCommand);
    578                             }
    579                         });
     571                    if (error.isFixable()) {
     572                        final Command fixCommand = error.getFix();
     573                        if (fixCommand != null) {
     574                            SwingUtilities.invokeAndWait(new Runnable() {
     575                                @Override
     576                                public void run() {
     577                                    Main.main.undoRedo.addNoRedraw(fixCommand);
     578                                }
     579                            });
     580                        }
     581                        // It is wanted to ignore an error if it said fixable, even if fixCommand was null
     582                        // This is to fix #5764 and #5773: a delete command, for example, may be null if all concerned primitives have already been deleted
    580583                        error.setIgnored(true);
    581584                    }
Note: See TracChangeset for help on using the changeset viewer.