Changeset 7232 in josm for trunk


Ignore:
Timestamp:
2014-06-09T17:21:00+02:00 (10 years ago)
Author:
akks
Message:

see #7991: more fixes to X DualAlign mode (fix exceptions, Alt-drag can create triangles)

File:
1 edited

Legend:

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

    r7226 r7232  
    2222import java.awt.geom.Point2D;
    2323import java.util.ArrayList;
     24import java.util.Arrays;
    2425import java.util.Collection;
    2526import java.util.LinkedList;
     
    253254            if (dualAlignEnabled) {
    254255                rv.append(" ").append(tr("Dual alignment active."));
    255                 if (dualAlignSegmentCollapsed) {
     256                if (dualAlignSegmentCollapsed)
    256257                    rv.append(" ").append(tr("Segment collapsed due to its direction reversing."));
    257                 }
    258258            }
    259259        } else {
     
    270270                rv = new StringBuilder();
    271271            }
    272             if (dualAlignActive)
     272            if (dualAlignActive) {
    273273                rv.append(" ").append(tr("Dual alignment active."));
     274                if (dualAlignSegmentCollapsed) {
     275                    rv.append(" ").append(tr("Segment collapsed due to its direction reversing."));
     276                }
     277            }
    274278        }
    275279        return rv.toString();
     
    586590        wnew.addNode(selectedSegment.getSecondNode());
    587591        wnew.addNode(third);
    588         wnew.addNode(fourth);
     592        if (newN1en.distance(newN2en)>1e-6) {
     593            wnew.addNode(fourth); // rectangle can degrade to triangle for dual alignment
     594        }
    589595        // ... and close the way
    590596        wnew.addNode(selectedSegment.getFirstNode());
     
    687693
    688694    private void joinNodesIfCollapsed(List<Node> changedNodes) {
    689         if (newN1en.distance(newN2en) < 1e-6) {
    690             // If the dual alignment created moved two nodes  to the same point, merge them
    691             Node targetNode = MergeNodesAction.selectTargetNode(changedNodes);
    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             }
     695        if (!dualAlignActive || newN1en == null || newN2en == null) return;
     696        if (newN1en.distance(newN2en) > 1e-6) return;
     697        // If the dual alignment moved two nodes to the same point, merge them
     698        Node targetNode = MergeNodesAction.selectTargetNode(changedNodes);
     699        Node locNode = MergeNodesAction.selectTargetLocationNode(changedNodes);
     700        Command mergeCmd = MergeNodesAction.mergeNodes(Main.main.getEditLayer(), changedNodes, targetNode, locNode);
     701        if (mergeCmd!=null) {
     702            Main.main.undoRedo.add(mergeCmd);
     703        } else {
     704            // undo extruding command itself
     705            Main.main.undoRedo.undo();
    700706        }
    701707    }
     
    848854        EastNorth n1en = selectedSegment.getFirstNode().getEastNorth();
    849855        EastNorth n2en = selectedSegment.getSecondNode().getEastNorth();
     856        if (n1en.distance(prevNode.getEastNorth())<1e-4 ||
     857            n2en.distance(nextNode.getEastNorth())<1e-4 ) {
     858            return false;
     859        }
     860
    850861        boolean prevSegmentParallel = Geometry.segmentsParallel(n1en, prevNode.getEastNorth(), n1en, n2en);
    851862        boolean nextSegmentParallel = Geometry.segmentsParallel(n2en, nextNode.getEastNorth(), n1en, n2en);
Note: See TracChangeset for help on using the changeset viewer.