Changeset 4461 in josm for trunk/src/org/openstreetmap/josm/actions
- Timestamp:
- 2011-09-24T22:09:19+02:00 (13 years ago)
- File:
-
- 1 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;
Note:
See TracChangeset
for help on using the changeset viewer.