- Timestamp:
- 2011-03-04T22:58:42+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/SimplifyWayAction.java
r3757 r3952 23 23 import org.openstreetmap.josm.command.SequenceCommand; 24 24 import org.openstreetmap.josm.data.Bounds; 25 import org.openstreetmap.josm.data.osm.DataSet; 25 26 import org.openstreetmap.josm.data.osm.DataSource; 26 27 import org.openstreetmap.josm.data.osm.Node; … … 138 139 139 140 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 } 157 163 } 158 164 } 159 165 } 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(); 167 169 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 } 184 192 Main.map.repaint(); 185 193 } … … 213 221 * @param w the way to simplify 214 222 */ 215 public SequenceCommand simplifyWay(Way w) { 223 public SequenceCommand simplifyWay(Way w, DataSet ds) { 216 224 double threshold = Double.parseDouble(Main.pref.get("simplify-way.max-error", "3")); 217 225 int lower = 0; … … 249 257 cmds.add(new ChangeCommand(w, newWay)); 250 258 cmds.add(new DeleteCommand(delNodes)); 259 ds.clearSelection(delNodes); 251 260 return new SequenceCommand(trn("Simplify Way (remove {0} node)", "Simplify Way (remove {0} nodes)", delNodes.size(), delNodes.size()), cmds); 252 261 }
Note:
See TracChangeset
for help on using the changeset viewer.