Ticket #4115: JoinAreasOutsideBoundary2.patch
| File JoinAreasOutsideBoundary2.patch, 7.3 KB (added by , 16 years ago) |
|---|
-
src/org/openstreetmap/josm/actions/JoinAreasAction.java
8 8 import java.awt.Polygon; 9 9 import java.awt.event.ActionEvent; 10 10 import java.awt.event.KeyEvent; 11 import java.awt.geom.Area; 11 12 import java.awt.geom.Line2D; 12 13 import java.util.ArrayList; 13 14 import java.util.Collection; … … 33 34 import org.openstreetmap.josm.command.Command; 34 35 import org.openstreetmap.josm.command.DeleteCommand; 35 36 import org.openstreetmap.josm.command.SequenceCommand; 36 import org.openstreetmap.josm.data.Bounds;37 37 import org.openstreetmap.josm.data.UndoRedoHandler; 38 38 import org.openstreetmap.josm.data.coor.EastNorth; 39 39 import org.openstreetmap.josm.data.coor.LatLon; 40 40 import org.openstreetmap.josm.data.osm.DataSet; 41 import org.openstreetmap.josm.data.osm.DataSource;42 41 import org.openstreetmap.josm.data.osm.Node; 43 42 import org.openstreetmap.josm.data.osm.OsmPrimitive; 44 43 import org.openstreetmap.josm.data.osm.Relation; … … 46 45 import org.openstreetmap.josm.data.osm.TigerUtils; 47 46 import org.openstreetmap.josm.data.osm.Way; 48 47 import org.openstreetmap.josm.gui.ExtendedDialog; 49 import org.openstreetmap.josm.gui.layer.OsmDataLayer;50 48 import org.openstreetmap.josm.tools.GBC; 51 49 import org.openstreetmap.josm.tools.Shortcut; 52 50 … … 108 106 * Checks whether the selected objects are suitable to join and joins them if so 109 107 */ 110 108 public void actionPerformed(ActionEvent e) { 111 Collection<OsmPrimitive> selection = Main.main.getCurrentDataSet().getSelectedWays();109 LinkedList<Way> ways = new LinkedList<Way>(Main.main.getCurrentDataSet().getSelectedWays()); 112 110 113 int ways = 0; 114 Way[] selWays = new Way[2]; 111 if (ways.isEmpty()) { 112 JOptionPane.showMessageDialog(Main.parent, tr("Please select at least one closed way that should be joined.")); 113 return; 114 } 115 115 116 LinkedList<Bounds> bounds = new LinkedList<Bounds>(); 117 OsmDataLayer dataLayer = Main.map.mapView.getEditLayer(); 118 for (DataSource ds : dataLayer.data.dataSources) { 119 if (ds.bounds != null) { 120 bounds.add(ds.bounds); 121 } 116 // Too many ways 117 if(ways.size() > 2) { 118 JOptionPane.showMessageDialog(Main.parent, tr("Only up to two areas can be joined at the moment.")); 119 return; 122 120 } 123 121 124 boolean askedAlready = false; 125 for (OsmPrimitive prim : selection) { 126 Way way = (Way) prim; 127 128 // Too many ways 129 if(ways == 2) { 130 JOptionPane.showMessageDialog(Main.parent, tr("Only up to two areas can be joined at the moment.")); 131 return; 132 } 133 122 List<Node> allNodes = new ArrayList<Node>(); 123 for (Way way: ways) { 134 124 if(!way.isClosed()) { 135 125 JOptionPane.showMessageDialog(Main.parent, tr("\"{0}\" is not closed and therefore can't be joined.", way.getName())); 136 126 return; 137 127 } 138 128 139 // This is copied from SimplifyAction and should be probably ported to tools 140 for (Node node : way.getNodes()) { 141 if(askedAlready) { 142 break; 143 } 144 boolean isInsideOneBoundingBox = false; 145 for (Bounds b : bounds) { 146 if (b.contains(node.getCoor())) { 147 isInsideOneBoundingBox = true; 148 break; 149 } 150 } 129 allNodes.addAll(way.getNodes()); 130 } 151 131 152 if (!isInsideOneBoundingBox) { 132 // TODO: Only display this warning when nodes outside dataSourceArea are deleted 133 Area dataSourceArea = Main.main.getCurrentDataSet().getDataSourceArea(); 134 if (dataSourceArea != null) { 135 for (Node node: allNodes) { 136 if (!dataSourceArea.contains(node.getCoor())) { 153 137 int option = JOptionPane.showConfirmDialog(Main.parent, 154 138 tr("The selected way(s) have nodes outside of the downloaded data region.\n" 155 139 + "This can lead to nodes being deleted accidentally.\n" … … 158 142 JOptionPane.WARNING_MESSAGE); 159 143 160 144 if (option != JOptionPane.YES_OPTION) return; 161 askedAlready = true;162 145 break; 163 146 } 164 147 } 165 166 selWays[ways] = way;167 ways++;168 148 } 169 149 170 if (ways < 1) { 171 JOptionPane.showMessageDialog(Main.parent, tr("Please select at least one closed way the should be joined.")); 172 return; 173 } 174 175 if(joinAreas(selWays[0], selWays[ways == 2 ? 1 : 0])) { 150 if(joinAreas(ways.getFirst(), ways.getLast())) { 176 151 Main.map.mapView.repaint(); 177 152 DataSet ds = Main.main.getCurrentDataSet(); 178 153 ds.fireSelectionChanged(); … … 458 433 private ArrayList<RelationRole> removeFromRelations(OsmPrimitive osm) { 459 434 ArrayList<RelationRole> result = new ArrayList<RelationRole>(); 460 435 for (Relation r : Main.main.getCurrentDataSet().getRelations()) { 461 if (r.isDeleted()) 436 if (r.isDeleted()) { 462 437 continue; 438 } 463 439 for (RelationMember rm : r.getMembers()) { 464 440 if (rm.getMember() != osm) { 465 441 continue; -
src/org/openstreetmap/josm/data/osm/DataSet.java
292 292 /** 293 293 * Return selected nodes. 294 294 */ 295 public Collection< OsmPrimitive> getSelectedNodes() {295 public Collection<Node> getSelectedNodes() { 296 296 return getSelected(nodes); 297 297 } 298 298 299 299 /** 300 300 * Return selected ways. 301 301 */ 302 public Collection< OsmPrimitive> getSelectedWays() {302 public Collection<Way> getSelectedWays() { 303 303 return getSelected(ways); 304 304 } 305 305 306 306 /** 307 307 * Return selected relations. 308 308 */ 309 public Collection< OsmPrimitive> getSelectedRelations() {309 public Collection<Relation> getSelectedRelations() { 310 310 return getSelected(relations); 311 311 } 312 312 … … 314 314 * Return all selected items in the collection. 315 315 * @param list The collection from which the selected items are returned. 316 316 */ 317 private Collection<OsmPrimitive> getSelected(Collection<? extends OsmPrimitive> list) {317 private <T extends OsmPrimitive> Collection<T> getSelected(Collection<T> list) { 318 318 if (list == null) 319 return new LinkedList< OsmPrimitive>();319 return new LinkedList<T>(); 320 320 // getSelected() is called with large lists, so 321 321 // creating the return list from the selection 322 322 // should be faster most of the time. 323 Collection< OsmPrimitive> sel = new LinkedHashSet<OsmPrimitive>(selectedPrimitives);324 sel.retainAll( list);323 Collection<T> sel = new LinkedHashSet<T>(list); 324 sel.retainAll(selectedPrimitives); 325 325 return sel; 326 326 } 327 327
