Changeset 18759 in josm


Ignore:
Timestamp:
2023-06-14T20:58:53+02:00 (18 months ago)
Author:
taylor.smock
Message:

Fix #22279: Add new split mode for quick splitting of ways (patch by Woazboat, modified)

Modifications are as follows:

  • Simplify/inline some variables
  • Move an inner class used only in a class that it is not in into the appropriate class
  • Fix a pre-existing bug where InputEvent.META_MASK would not be mapped to InputEvent.META_DOWN_MASK
  • Override some additional methods in SplitMode (layerIsSupported and getModeHelpText)
Location:
trunk
Files:
1 added
4 edited
1 moved

Legend:

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

    r18442 r18759  
    6565     */
    6666    public SplitWayAction() {
    67         super(tr("Split Way"), "splitway", tr("Split a way at the selected node."),
     67        super(tr("Split Way"), "mapmode/splitway", tr("Split a way at the selected node."),
    6868                Shortcut.registerShortcut("tools:splitway", tr("Tools: {0}", tr("Split Way")), KeyEvent.VK_P, Shortcut.DIRECT), true);
    6969        setHelpId(ht("/Action/SplitWay"));
     
    147147        // Finally, applicableWays contains only one perfect way
    148148        final Way selectedWay = applicableWays.get(0);
    149         final List<List<Node>> wayChunks = SplitWayCommand.buildSplitChunks(selectedWay, selectedNodes);
     149        final List<OsmPrimitive> sel = new ArrayList<>(ds.getSelectedRelations());
     150        sel.addAll(selectedWays);
     151        doSplitWayShowSegmentSelection(selectedWay, selectedNodes, sel);
     152    }
     153
     154    /**
     155     * Perform way splitting after presenting the user with a choice which way segment history should be preserved (in expert mode)
     156     * @param splitWay The way to split
     157     * @param splitNodes The nodes at which the way should be split
     158     * @param selection (Optional) selection which should be updated
     159     *
     160     * @since 18759
     161     */
     162    public static void doSplitWayShowSegmentSelection(Way splitWay, List<Node> splitNodes, List<OsmPrimitive> selection) {
     163        final List<List<Node>> wayChunks = SplitWayCommand.buildSplitChunks(splitWay, splitNodes);
    150164        if (wayChunks != null) {
    151             final List<OsmPrimitive> sel = new ArrayList<>(ds.getSelectedRelations());
    152             sel.addAll(selectedWays);
    153 
    154             final List<Way> newWays = SplitWayCommand.createNewWaysFromChunks(selectedWay, wayChunks);
     165            final List<Way> newWays = SplitWayCommand.createNewWaysFromChunks(splitWay, wayChunks);
    155166            final Way wayToKeep = SplitWayCommand.Strategy.keepLongestChunk().determineWayToKeep(newWays);
    156167
    157             if (ExpertToggleAction.isExpert() && !selectedWay.isNew()) {
    158                 final ExtendedDialog dialog = new SegmentToKeepSelectionDialog(selectedWay, newWays, wayToKeep, selectedNodes, sel);
     168            if (ExpertToggleAction.isExpert() && !splitWay.isNew()) {
     169                final ExtendedDialog dialog = new SegmentToKeepSelectionDialog(splitWay, newWays, wayToKeep, splitNodes, selection);
    159170                dialog.toggleEnable("way.split.segment-selection-dialog");
    160171                if (!dialog.toggleCheckState()) {
     
    165176            }
    166177            if (wayToKeep != null) {
    167                 doSplitWay(selectedWay, wayToKeep, newWays, sel);
     178                doSplitWay(splitWay, wayToKeep, newWays, selection);
    168179            }
    169180        }
  • trunk/src/org/openstreetmap/josm/actions/mapmode/MapMode.java

    r18458 r18759  
    185185     * @return extended modifiers
    186186     */
    187     @SuppressWarnings("deprecation")
    188187    private static int mapOldModifiers(int modifiers) {
    189188        if ((modifiers & InputEvent.CTRL_MASK) != 0) {
    190189            modifiers |= InputEvent.CTRL_DOWN_MASK;
     190        }
     191        if ((modifiers & InputEvent.META_MASK) != 0) {
     192            modifiers |= InputEvent.META_DOWN_MASK;
    191193        }
    192194        if ((modifiers & InputEvent.ALT_MASK) != 0) {
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r18755 r18759  
    5252import org.openstreetmap.josm.actions.mapmode.SelectAction;
    5353import org.openstreetmap.josm.actions.mapmode.SelectLassoAction;
     54import org.openstreetmap.josm.actions.mapmode.SplitMode;
    5455import org.openstreetmap.josm.actions.mapmode.ZoomAction;
    5556import org.openstreetmap.josm.data.ViewportData;
     
    246247        mapModeDelete = new DeleteAction();
    247248
    248         addMapMode(new IconToggleButton(mapModeSelect));
     249        addMapMode(new IconToggleButton(mapModeSelect, false));
    249250        addMapMode(new IconToggleButton(mapModeSelectLasso, true));
    250         addMapMode(new IconToggleButton(mapModeDraw));
     251        addMapMode(new IconToggleButton(mapModeDraw, false));
    251252        addMapMode(new IconToggleButton(mapModeZoom, true));
    252253        addMapMode(new IconToggleButton(mapModeDelete, true));
     
    254255        addMapMode(new IconToggleButton(new ExtrudeAction(), true));
    255256        addMapMode(new IconToggleButton(new ImproveWayAccuracyAction(), false));
     257        addMapMode(new IconToggleButton(new SplitMode(), false));
    256258        toolBarActionsGroup.setSelected(allMapModeButtons.get(0).getModel(), true);
    257259        toolBarActions.setFloatable(false);
  • trunk/src/org/openstreetmap/josm/gui/util/HighlightHelper.java

    r13434 r18759  
    8080     */
    8181    public boolean setHighlight(OsmPrimitive p, boolean flag) {
    82         return setHighlight(p, flag, new HashSet<Relation>());
     82        return setHighlight(p, flag, new HashSet<>());
    8383    }
    8484
     
    109109
    110110    /**
     111     * Returns an (unmodifiable) set of currently highlighted primitives
     112     * @return Currently highlighted primitives
     113     *
     114     * @since 18759
     115     */
     116    public Set<OsmPrimitive> getHighlighted() {
     117        return Collections.unmodifiableSet(highlightedPrimitives);
     118    }
     119
     120    /**
    111121     * Clear highlighting of all remembered primitives
    112122     */
     
    116126        }
    117127        highlightedPrimitives.clear();
     128    }
     129
     130    /**
     131     * Check whether there are any primitives highlighted
     132     * @return true when there are highlighted primitives
     133     *
     134     * @since 18759
     135     */
     136    public boolean anyHighlighted() {
     137        return !highlightedPrimitives.isEmpty();
    118138    }
    119139
Note: See TracChangeset for help on using the changeset viewer.