Ticket #4115: JoinAreasOutsideBoundary.patch

File JoinAreasOutsideBoundary.patch, 4.7 KB (added by mjulius, 16 years ago)
  • src/org/openstreetmap/josm/actions/JoinAreasAction.java

     
    88import java.awt.Polygon;
    99import java.awt.event.ActionEvent;
    1010import java.awt.event.KeyEvent;
     11import java.awt.geom.Area;
    1112import java.awt.geom.Line2D;
    1213import java.util.ArrayList;
    1314import java.util.Collection;
     
    3334import org.openstreetmap.josm.command.Command;
    3435import org.openstreetmap.josm.command.DeleteCommand;
    3536import org.openstreetmap.josm.command.SequenceCommand;
    36 import org.openstreetmap.josm.data.Bounds;
    3737import org.openstreetmap.josm.data.UndoRedoHandler;
    3838import org.openstreetmap.josm.data.coor.EastNorth;
    3939import org.openstreetmap.josm.data.coor.LatLon;
    4040import org.openstreetmap.josm.data.osm.DataSet;
    41 import org.openstreetmap.josm.data.osm.DataSource;
    4241import org.openstreetmap.josm.data.osm.Node;
    4342import org.openstreetmap.josm.data.osm.OsmPrimitive;
    4443import org.openstreetmap.josm.data.osm.Relation;
     
    4645import org.openstreetmap.josm.data.osm.TigerUtils;
    4746import org.openstreetmap.josm.data.osm.Way;
    4847import org.openstreetmap.josm.gui.ExtendedDialog;
    49 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    5048import org.openstreetmap.josm.tools.GBC;
    5149import org.openstreetmap.josm.tools.Shortcut;
    5250
     
    113111        int ways = 0;
    114112        Way[] selWays = new Way[2];
    115113
    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             }
    122         }
     114        Area dataSourceArea = Main.main.getCurrentDataSet().getDataSourceArea();
    123115
    124116        boolean askedAlready = false;
    125117        for (OsmPrimitive prim : selection) {
     
    136128                return;
    137129            }
    138130
    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;
     131            // TODO: Only display this warning when nodes outside dataSourceArea are deleted
     132            if (dataSourceArea != null) {
     133                for (Node node : way.getNodes()) {
     134                    if(askedAlready) {
    148135                        break;
    149136                    }
    150                 }
     137                    if (!dataSourceArea.contains(node.getCoor())) {
     138                        int option = JOptionPane.showConfirmDialog(Main.parent,
     139                                tr("The selected way(s) have nodes outside of the downloaded data region.\n"
     140                                        + "This can lead to nodes being deleted accidentally.\n"
     141                                        + "Are you really sure to continue?"),
     142                                        tr("Please abort if you are not sure"), JOptionPane.YES_NO_OPTION,
     143                                        JOptionPane.WARNING_MESSAGE);
    151144
    152                 if (!isInsideOneBoundingBox) {
    153                     int option = JOptionPane.showConfirmDialog(Main.parent,
    154                             tr("The selected way(s) have nodes outside of the downloaded data region.\n"
    155                                     + "This can lead to nodes being deleted accidentally.\n"
    156                                     + "Are you really sure to continue?"),
    157                                     tr("Please abort if you are not sure"), JOptionPane.YES_NO_OPTION,
    158                                     JOptionPane.WARNING_MESSAGE);
    159 
    160                     if (option != JOptionPane.YES_OPTION) return;
    161                     askedAlready = true;
    162                     break;
     145                        if (option != JOptionPane.YES_OPTION) return;
     146                        askedAlready = true;
     147                        break;
     148                    }
    163149                }
    164150            }
    165151
     
    458444    private ArrayList<RelationRole> removeFromRelations(OsmPrimitive osm) {
    459445        ArrayList<RelationRole> result = new ArrayList<RelationRole>();
    460446        for (Relation r : Main.main.getCurrentDataSet().getRelations()) {
    461             if (r.isDeleted())
     447            if (r.isDeleted()) {
    462448                continue;
     449            }
    463450            for (RelationMember rm : r.getMembers()) {
    464451                if (rm.getMember() != osm) {
    465452                    continue;