Changeset 3952 in josm for trunk/src/org


Ignore:
Timestamp:
2011-03-04T22:58:42+01:00 (13 years ago)
Author:
stoecker
Message:

fix #5909 - remove deleted nodes from selection after simplify way call - maybe we should additionally modify DeleteAction directly?

File:
1 edited

Legend:

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

    r3757 r3952  
    2323import org.openstreetmap.josm.command.SequenceCommand;
    2424import org.openstreetmap.josm.data.Bounds;
     25import org.openstreetmap.josm.data.osm.DataSet;
    2526import org.openstreetmap.josm.data.osm.DataSource;
    2627import org.openstreetmap.josm.data.osm.Node;
     
    138139
    139140    public void actionPerformed(ActionEvent e) {
    140         Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
    141 
    142         List<Bounds> bounds = getCurrentEditBounds();
    143         for (OsmPrimitive prim : selection) {
    144             if (! (prim instanceof Way)) {
    145                 continue;
    146             }
    147             if (bounds.size() > 0) {
    148                 Way way = (Way) prim;
    149                 // We check if each node of each way is at least in one download
    150                 // bounding box. Otherwise nodes may get deleted that are necessary by
    151                 // unloaded ways (see Ticket #1594)
    152                 for (Node node : way.getNodes()) {
    153                     if (!isInBounds(node, bounds)) {
    154                         if (!confirmWayWithNodesOutsideBoundingBox())
    155                             return;
    156                         break;
     141        DataSet ds = getCurrentDataSet();
     142        ds.beginUpdate();
     143        try
     144        {
     145            Collection<OsmPrimitive> selection = ds.getSelected();
     146
     147            List<Bounds> bounds = getCurrentEditBounds();
     148            for (OsmPrimitive prim : selection) {
     149                if (! (prim instanceof Way)) {
     150                    continue;
     151                }
     152                if (bounds.size() > 0) {
     153                    Way way = (Way) prim;
     154                    // We check if each node of each way is at least in one download
     155                    // bounding box. Otherwise nodes may get deleted that are necessary by
     156                    // unloaded ways (see Ticket #1594)
     157                    for (Node node : way.getNodes()) {
     158                        if (!isInBounds(node, bounds)) {
     159                            if (!confirmWayWithNodesOutsideBoundingBox())
     160                                return;
     161                            break;
     162                        }
    157163                    }
    158164                }
    159165            }
    160         }
    161         List<Way> ways = OsmPrimitive.getFilteredList(selection, Way.class);
    162         if (ways.isEmpty()) {
    163             alertSelectAtLeastOneWay();
    164             return;
    165         } else if (ways.size() > 10) {
    166             if (!confirmSimplifyManyWays(ways.size()))
     166            List<Way> ways = OsmPrimitive.getFilteredList(selection, Way.class);
     167            if (ways.isEmpty()) {
     168                alertSelectAtLeastOneWay();
    167169                return;
    168         }
    169 
    170         Collection<Command> allCommands = new LinkedList<Command>();
    171         for (Way way: ways) {
    172             SequenceCommand simplifyCommand = simplifyWay(way);
    173             if (simplifyCommand == null) {
    174                 continue;
    175             }
    176             allCommands.add(simplifyCommand);
    177         }
    178         if (allCommands.isEmpty()) return;
    179         SequenceCommand rootCommand = new SequenceCommand(
    180                 trn("Simplify {0} way", "Simplify {0} ways", allCommands.size(), allCommands.size()),
    181                 allCommands
    182         );
    183         Main.main.undoRedo.add(rootCommand);
     170            } else if (ways.size() > 10) {
     171                if (!confirmSimplifyManyWays(ways.size()))
     172                    return;
     173            }
     174
     175            Collection<Command> allCommands = new LinkedList<Command>();
     176            for (Way way: ways) {
     177                SequenceCommand simplifyCommand = simplifyWay(way, ds);
     178                if (simplifyCommand == null) {
     179                    continue;
     180                }
     181                allCommands.add(simplifyCommand);
     182            }
     183            if (allCommands.isEmpty()) return;
     184            SequenceCommand rootCommand = new SequenceCommand(
     185                    trn("Simplify {0} way", "Simplify {0} ways", allCommands.size(), allCommands.size()),
     186                    allCommands
     187            );
     188            Main.main.undoRedo.add(rootCommand);
     189        } finally {
     190            ds.endUpdate();
     191        }
    184192        Main.map.repaint();
    185193    }
     
    213221     * @param w the way to simplify
    214222     */
    215     public SequenceCommand simplifyWay(Way w) {
     223    public SequenceCommand simplifyWay(Way w, DataSet ds) {
    216224        double threshold = Double.parseDouble(Main.pref.get("simplify-way.max-error", "3"));
    217225        int lower = 0;
     
    249257        cmds.add(new ChangeCommand(w, newWay));
    250258        cmds.add(new DeleteCommand(delNodes));
     259        ds.clearSelection(delNodes);
    251260        return new SequenceCommand(trn("Simplify Way (remove {0} node)", "Simplify Way (remove {0} nodes)", delNodes.size(), delNodes.size()), cmds);
    252261    }
Note: See TracChangeset for help on using the changeset viewer.