Changeset 4461 in josm for trunk/src/org
- Timestamp:
- 2011-09-24T22:09:19+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/SimplifyWayAction.java
r3952 r4461 22 22 import org.openstreetmap.josm.command.DeleteCommand; 23 23 import org.openstreetmap.josm.command.SequenceCommand; 24 import org.openstreetmap.josm.data.Bounds;25 24 import org.openstreetmap.josm.data.osm.DataSet; 26 import org.openstreetmap.josm.data.osm.DataSource;27 25 import org.openstreetmap.josm.data.osm.Node; 28 26 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 31 29 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; 32 30 import org.openstreetmap.josm.gui.help.HelpUtil; 33 import org.openstreetmap.josm.gui.layer.OsmDataLayer;34 31 import org.openstreetmap.josm.tools.ImageProvider; 35 32 import org.openstreetmap.josm.tools.Shortcut; … … 42 39 } 43 40 44 protected List<Bounds> getCurrentEditBounds() { 45 LinkedList<Bounds> bounds = new LinkedList<Bounds>(); 46 OsmDataLayer dataLayer = Main.map.mapView.getEditLayer(); 47 for (DataSource ds : dataLayer.data.dataSources) { 48 if (ds.bounds != null) { 49 bounds.add(ds.bounds); 50 } 51 } 52 return bounds; 53 } 54 55 protected boolean isInBounds(Node node, List<Bounds> bounds) { 56 for (Bounds b : bounds) { 57 if (b.contains(node.getCoor())) 58 return true; 59 } 60 return false; 61 } 62 63 protected boolean confirmWayWithNodesOutsideBoundingBox() { 64 ButtonSpec[] options = new ButtonSpec[] { 65 new ButtonSpec( 66 tr("Yes, delete nodes"), 67 ImageProvider.get("ok"), 68 tr("Delete nodes outside of downloaded data regions"), 69 null 70 ), 71 new ButtonSpec( 72 tr("No, abort"), 73 ImageProvider.get("cancel"), 74 tr("Cancel operation"), 75 null 76 ) 77 }; 78 int ret = HelpAwareOptionPane.showOptionDialog( 79 Main.parent, 80 "<html>" 81 + trn("The selected way has nodes outside of the downloaded data region.", 82 "The selected ways have nodes outside of the downloaded data region.", 83 getCurrentDataSet().getSelectedWays().size()) 84 85 + "<br>" 86 + tr("This can lead to nodes being deleted accidentally.") + "<br>" 87 + tr("Do you want to delete them anyway?") 88 + "</html>", 89 tr("Delete nodes outside of data regions?"), 90 JOptionPane.WARNING_MESSAGE, 91 null, // no special icon 92 options, 93 options[0], 94 HelpUtil.ht("/Action/SimplifyWay#ConfirmDeleteNodesOutsideBoundingBoxes") 95 ); 96 return ret == 0; 41 protected boolean confirmWayWithNodesOutsideBoundingBox(List<? extends OsmPrimitive> primitives) { 42 System.out.println(primitives); 43 return DeleteCommand.checkAndConfirmOutlyingDelete(Main.map.mapView.getEditLayer(), primitives, null); 97 44 } 98 45 … … 143 90 try 144 91 { 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 } 163 } 164 } 165 } 166 List<Way> ways = OsmPrimitive.getFilteredList(selection, Way.class); 92 List<Way> ways = OsmPrimitive.getFilteredList(ds.getSelected(), Way.class); 167 93 if (ways.isEmpty()) { 168 94 alertSelectAtLeastOneWay(); 169 95 return; 170 } else if (ways.size() > 10) { 96 } else if (!confirmWayWithNodesOutsideBoundingBox(ways)) { 97 return; 98 } 99 else if (ways.size() > 10) { 171 100 if (!confirmSimplifyManyWays(ways.size())) 172 101 return; -
trunk/src/org/openstreetmap/josm/command/Command.java
r4458 r4461 183 183 * Request confirmation if he is. 184 184 * 185 * @param layer the layer in whose context data is deleted 185 * @param operation the operation name which is used for setting some preferences 186 * @param dialogTitle the title of the dialog being displayed 187 * @param outsideDialogMessage the message text to be displayed when data is outside of the download area 188 * @param incompleteDialogMessage the message text to be displayed when data is incomplete 189 * @param area the area used to determine whether data is outlying 186 190 * @param primitives the primitives to operate on 187 * @return true, if deleting outlying primitives is OK; false, otherwise 191 * @param ignore {@code null} or a primitive to be ignored 192 * @return true, if operating on outlying primitives is OK; false, otherwise 188 193 */ 189 194 public static boolean checkAndConfirmOutlyingOperation(String operation, … … 196 201 if (osm.isIncomplete()) { 197 202 incomplete = true; 198 } else if (osm instanceof Node && !osm.isNewOrUndeleted() 199 && !area.contains(((Node) osm).getCoor()) 203 } else if (isOutlying(osm, area) 200 204 && (ignore == null || !ignore.equals(osm))) { 201 205 outside = true; … … 240 244 } 241 245 246 private static boolean isOutlying(OsmPrimitive osm, Area area) { 247 if (osm instanceof Node) { 248 return !osm.isNewOrUndeleted() && !area.contains(((Node) osm).getCoor()); 249 } else if (osm instanceof Way) { 250 for (Node n : ((Way) osm).getNodes()) { 251 if (isOutlying(n, area)) { 252 return true; 253 } 254 } 255 return false; 256 } 257 return false; 258 } 242 259 }
Note:
See TracChangeset
for help on using the changeset viewer.