Changeset 4461 in josm for trunk


Ignore:
Timestamp:
2011-09-24T22:09:19+02:00 (13 years ago)
Author:
simon04
Message:

fix #5407 - simplify way: dialog asking to delete nodes outside boundary is missing "never ask again" checkbox

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/SimplifyWayAction.java

    r3952 r4461  
    2222import org.openstreetmap.josm.command.DeleteCommand;
    2323import org.openstreetmap.josm.command.SequenceCommand;
    24 import org.openstreetmap.josm.data.Bounds;
    2524import org.openstreetmap.josm.data.osm.DataSet;
    26 import org.openstreetmap.josm.data.osm.DataSource;
    2725import org.openstreetmap.josm.data.osm.Node;
    2826import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    3129import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
    3230import org.openstreetmap.josm.gui.help.HelpUtil;
    33 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    3431import org.openstreetmap.josm.tools.ImageProvider;
    3532import org.openstreetmap.josm.tools.Shortcut;
     
    4239    }
    4340
    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);
    9744    }
    9845
     
    14390        try
    14491        {
    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);
    16793            if (ways.isEmpty()) {
    16894                alertSelectAtLeastOneWay();
    16995                return;
    170             } else if (ways.size() > 10) {
     96            } else if (!confirmWayWithNodesOutsideBoundingBox(ways)) {
     97                return;
     98            }
     99             else if (ways.size() > 10) {
    171100                if (!confirmSimplifyManyWays(ways.size()))
    172101                    return;
  • trunk/src/org/openstreetmap/josm/command/Command.java

    r4458 r4461  
    183183     * Request confirmation if he is.
    184184     *
    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
    186190     * @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
    188193     */
    189194    public static boolean checkAndConfirmOutlyingOperation(String operation,
     
    196201                if (osm.isIncomplete()) {
    197202                    incomplete = true;
    198                 } else if (osm instanceof Node && !osm.isNewOrUndeleted()
    199                         && !area.contains(((Node) osm).getCoor())
     203                } else if (isOutlying(osm, area)
    200204                        && (ignore == null || !ignore.equals(osm))) {
    201205                    outside = true;
     
    240244    }
    241245
     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    }
    242259}
Note: See TracChangeset for help on using the changeset viewer.