Changeset 7226 in josm for trunk


Ignore:
Timestamp:
2014-06-09T13:50:48+02:00 (10 years ago)
Author:
akks
Message:

see #7991:patch by AlfonZ mod. Show and correctly handle segment collapsing in X mode

File:
1 edited

Legend:

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

    r7223 r7226  
    5555import org.openstreetmap.josm.tools.ImageProvider;
    5656import org.openstreetmap.josm.tools.Shortcut;
     57import org.openstreetmap.josm.tools.Utils;
    5758
    5859/**
     
    8081    private boolean ignoreSharedNodes;
    8182
    82     private final boolean keepSegmentDirection;
    83    
     83    private boolean keepSegmentDirection;
     84
    8485    /**
    8586     * drawing settings for helper lines
     
    100101     * Collection of nodes that is moved
    101102     */
    102     private ArrayList<OsmPrimitive> movingNodeList;
     103    private ArrayList<Node> movingNodeList;
    103104
    104105    /**
     
    150151    /** The cursor for the 'alwaysCreateNodes' submode. */
    151152    private final Cursor cursorCreateNodes;
    152 
    153     private boolean ignoreNextKeyRelease;
    154153
    155154    private static class ReferenceSegment {
     
    179178    /** Dual alignment reference segments */
    180179    private ReferenceSegment dualAlignSegment1, dualAlignSegment2;
     180    /** {@code true}, if new segment was collapsed */
     181    private boolean dualAlignSegmentCollapsed;
    181182    // Dual alignment UI stuff
    182183    private final DualAlignChangeAction dualAlignChangeAction;
     
    184185    private final Shortcut dualAlignShortcut;
    185186    private boolean useRepeatedShortcut;
     187    private boolean ignoreNextKeyRelease;
    186188
    187189    private class DualAlignChangeAction extends JosmAction {
     
    219221        dualAlignShortcut = Shortcut.registerShortcut("mapmode:extrudedualalign",
    220222                tr("Mode: {0}", tr("Extrude Dual alignment")), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE);
    221         useRepeatedShortcut = Main.pref.getBoolean("extrude.dualalign.toggleOnRepeatedX", true);
    222         keepSegmentDirection = Main.pref.getBoolean("extrude.dualalign.keep-segment-direction", true);
     223        readPreferences(); // to show prefernces in table before entering the mode
    223224    }
    224225
     
    250251            rv = new StringBuilder(tr("Drag a way segment to make a rectangle. Ctrl-drag to move a segment along its normal, " +
    251252                "Alt-drag to create a new rectangle, double click to add a new node."));
    252             if (dualAlignEnabled)
     253            if (dualAlignEnabled) {
    253254                rv.append(" ").append(tr("Dual alignment active."));
     255                if (dualAlignSegmentCollapsed) {
     256                    rv.append(" ").append(tr("Segment collapsed due to its direction reversing."));
     257                }
     258            }
    254259        } else {
    255260            if (mode == Mode.translate)
     
    281286        Main.map.mapView.addMouseListener(this);
    282287        Main.map.mapView.addMouseMotionListener(this);
     288        readPreferences();
     289        ignoreNextKeyRelease = true;
     290        Main.map.keyDetector.addKeyListener(this);
     291        Main.map.keyDetector.addModifierListener(this);
     292    }
     293
     294    private void readPreferences() {
    283295        initialMoveDelay = Main.pref.getInteger("edit.initial-move-delay",200);
    284296        initialMoveThreshold = Main.pref.getInteger("extrude.initial-move-threshold", 1);
     
    295307        ignoreSharedNodes = Main.pref.getBoolean("extrude.ignore-shared-nodes", true);
    296308        dualAlignCheckboxMenuItem.getAction().setEnabled(true);
    297         ignoreNextKeyRelease = true;
    298         Main.map.keyDetector.addKeyListener(this);
    299         Main.map.keyDetector.addModifierListener(this);
     309        useRepeatedShortcut = Main.pref.getBoolean("extrude.dualalign.toggleOnRepeatedX", true);
     310        keepSegmentDirection = Main.pref.getBoolean("extrude.dualalign.keep-segment-direction", true);
    300311    }
    301312
     
    392403                dualAlignActive = true;
    393404                calculatePossibleDirectionsForDualAlign();
     405                dualAlignSegmentCollapsed = false;
    394406            } else {
    395407                dualAlignActive = false;
     
    451463            EastNorth mouseEn = Main.map.mapView.getEastNorth(e.getPoint().x, e.getPoint().y);
    452464            EastNorth bestMovement = calculateBestMovementAndNewNodes(mouseEn);
    453            
     465
    454466            Main.map.mapView.setNewCursor(Cursor.MOVE_CURSOR, this);
    455467
     
    480492                    if (moveCommand == null) {
    481493                        //make a new move command
    482                         moveCommand = new MoveCommand(movingNodeList, bestMovement.getX(), bestMovement.getY());
     494                        moveCommand = new MoveCommand(new ArrayList<OsmPrimitive>(movingNodeList), bestMovement);
    483495                        Main.main.undoRedo.add(moveCommand);
    484496                    } else {
     
    522534                //Commit translate
    523535                //the move command is already committed in mouseDragged
     536                joinNodesIfCollapsed(movingNodeList);
    524537            }
    525538
     
    531544            moveCommand = null;
    532545            mode = Mode.select;
    533 
    534546            updateStatusLine();
    535547            Main.map.mapView.repaint();
     
    589601     * Does actual extrusion of {@link #selectedSegment}.
    590602     * Uses {@link #initialN1en}, {@link #initialN2en} saved in calculatePossibleDirections* call
    591      * Uses {@link #newN1en}, {@link #newN2en} calculated by {@link #calculateBestMovementAndNewNodes} 
     603     * Uses {@link #newN1en}, {@link #newN2en} calculated by {@link #calculateBestMovementAndNewNodes}
    592604     */
    593605    private void performExtrusion() {
     
    671683        Command c = new SequenceCommand(tr("Extrude Way"), cmds);
    672684        Main.main.undoRedo.add(c);
     685        joinNodesIfCollapsed(changedNodes);
     686    }
     687
     688    private void joinNodesIfCollapsed(List<Node> changedNodes) {
    673689        if (newN1en.distance(newN2en) < 1e-6) {
    674690            // If the dual alignment created moved two nodes  to the same point, merge them
    675691            Node targetNode = MergeNodesAction.selectTargetNode(changedNodes);
    676             Command mergeCmd = MergeNodesAction.mergeNodes(Main.main.getEditLayer(), changedNodes, targetNode, changedNodes.get(0));
    677             Main.main.undoRedo.add(mergeCmd);
     692            Node locNode = MergeNodesAction.selectTargetLocationNode(changedNodes);
     693            Command mergeCmd = MergeNodesAction.mergeNodes(Main.main.getEditLayer(), changedNodes, targetNode, locNode);
     694            if (mergeCmd!=null) {
     695                Main.main.undoRedo.add(mergeCmd);
     696            } else {
     697                // undo extruding command itself
     698                Main.main.undoRedo.undo();
     699            }
    678700        }
    679701    }
     
    866888            ), initialN2en,  nextNodeEn, false);
    867889    }
    868    
     890
    869891    /**
    870892     * Calculate newN1en, newN2en best suitable for given mouse coordinates
     
    881903        Main.map.statusLine.setDist(distance);
    882904        updateStatusLine();
    883        
     905
    884906        if (dualAlignActive) {
    885907            // new positions of selected segment's nodes, without applying dual alignment
     
    895917                newN1en = collapsedSegmentPosition;
    896918                newN2en = collapsedSegmentPosition;
     919                dualAlignSegmentCollapsed = true;
     920            } else {
     921                dualAlignSegmentCollapsed = false;
    897922            }
    898923        } else {
     
    10641089        return normalUnitVector;
    10651090    }
    1066    
     1091
    10671092    /**
    10681093     * Returns true if from1-to1 and from2-to2 vertors directions are opposite
Note: See TracChangeset for help on using the changeset viewer.