Changeset 4917 in josm for trunk/src/org


Ignore:
Timestamp:
2012-02-11T18:28:41+01:00 (8 years ago)
Author:
akks
Message:

AngleSnapping mode: precize intersections, Tab key customizable, "Disable" option in context menu (status bar)

File:
1 edited

Legend:

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

    r4805 r4917  
    6969import org.openstreetmap.josm.tools.Shortcut;
    7070import org.openstreetmap.josm.tools.Utils;
     71import org.openstreetmap.josm.tools.Geometry;
    7172
    7273/**
     
    9899    private Shortcut extraShortcut;
    99100    private Shortcut backspaceShortcut;
     101    private int snappingKeyCode;
    100102   
    101103    private JCheckBoxMenuItem snapCheckboxMenuItem;
     
    110112        extraShortcut = Shortcut.registerShortcut("mapmode:drawfocus", tr("Mode: Draw Focus"), KeyEvent.VK_N, Shortcut.GROUP_EDIT);
    111113        Main.registerActionShortcut(this, extraShortcut);
    112        
     114
     115        snappingKeyCode = Shortcut.registerShortcut("mapmode:drawanglesnapping", tr("Mode: Draw Angle snapping"), KeyEvent.VK_TAB, Shortcut.GROUP_EDIT)
     116                .getKeyStroke().getKeyCode();
    113117        snapCheckboxMenuItem = MainMenu.addWithCheckbox(Main.main.menu.editMenu, new SnapChangeAction(),  MainMenu.WINDOW_MENU_GROUP.VOLATILE);
    114118        snapHelper.setMenuCheckBox(snapCheckboxMenuItem);
     
    224228    private Timer timer;
    225229    void processKeyEvent(KeyEvent e) {
    226         if (e.getKeyCode() != KeyEvent.VK_TAB) return;
     230        if (e.getKeyCode() != snappingKeyCode) return;
    227231        //e.consume(); // ticket #7250 -  TAB should work in other windows
    228232
     
    250254   
    251255    private void doKeyPressEvent(KeyEvent e) {
    252         if (e.getKeyCode() != KeyEvent.VK_TAB) return;
     256        if (e.getKeyCode() != snappingKeyCode) return;
    253257        snapHelper.setFixedMode();
    254258        computeHelperLine(); redrawIfRequired();
    255259    }
    256260    private void doKeyReleaseEvent(KeyEvent e) {
    257         if (e.getKeyCode() != KeyEvent.VK_TAB) return;
     261        if (e.getKeyCode() != snappingKeyCode) return;
    258262        snapHelper.unFixOrTurnOff();
    259263        computeHelperLine(); redrawIfRequired();
     
    414418                    List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(
    415419                            Main.map.mapView.getPoint(n), OsmPrimitive.isSelectablePredicate);
     420                    if (snapHelper.isActive()) { //
     421                        tryToMoveNodeOnIntersection(wss,n);
     422                    }
    416423                    insertNodeIntoAllNearbySegments(wss, n, newSelection, cmds, replacedWays, reuseWays);
    417424                    }
     
    952959        return a * d - b * c;
    953960    }
     961
     962    private void tryToMoveNodeOnIntersection(List<WaySegment> wss, Node n) {
     963        if (wss.isEmpty()) return;
     964        WaySegment ws = wss.get(0);
     965        EastNorth p1=ws.getFirstNode().getEastNorth();
     966        EastNorth p2=ws.getSecondNode().getEastNorth();
     967        if (snapHelper.dir2!=null && currentBaseNode!=null) {
     968            EastNorth xPoint = Geometry.getSegmentSegmentIntersection(p1, p2, snapHelper.dir2, currentBaseNode.getEastNorth());
     969            if (xPoint!=null) n.setEastNorth(xPoint);
     970        }
     971    }
    954972/**
    955973     * Takes the data from computeHelperLine to determine which ways/nodes should be highlighted
     
    14471465                    }
    14481466               }));
     1467               add(new AbstractAction(tr("Disable")) {
     1468                public void actionPerformed(ActionEvent e) {
     1469                    saveAngles("180");
     1470                    init(); enableSnapping();
     1471                }
     1472               });
    14491473               add(new AbstractAction(tr("0,90,...")) {
    14501474                public void actionPerformed(ActionEvent e) {
Note: See TracChangeset for help on using the changeset viewer.