Changeset 1287 in josm


Ignore:
Timestamp:
2009-01-17T22:49:05+01:00 (16 years ago)
Author:
stoecker
Message:

close #381 and #696. Patch by xeen

File:
1 edited

Legend:

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

    r1262 r1287  
    3434
    3535import org.openstreetmap.josm.Main;
     36import org.openstreetmap.josm.actions.mapmode.SelectAction;
    3637import org.openstreetmap.josm.command.AddCommand;
    3738import org.openstreetmap.josm.command.ChangeCommand;
     
    167168        boolean newNode = false;
    168169        Node n = null;
     170        boolean wayIsFinished = false;
    169171
    170172        if (!ctrl) {
     
    280282            // existing way or make a new way of its own? The "alt" modifier means that the
    281283            // user wants a new way.
    282 
    283284            Way way = alt ? null : (selectedWay != null) ? selectedWay : getWayForNode(n0);
     285
     286            // Don't allow creation of self-overlapping ways
     287            if(way != null) {
     288                int nodeCount=0;
     289                for (Node p : way.nodes)
     290                    if(p.equals(n0)) nodeCount++;
     291                if(nodeCount > 1) way = null;
     292            }
     293
    284294            if (way == null) {
    285295                way = new Way();
     
    297307            }
    298308
     309            // Connected to a node that's already in the way
     310            if(way != null && way.nodes.contains(n)) {
     311                System.out.println("Stop drawing, node is part of current way");
     312                wayIsFinished = true;
     313                selection.clear();
     314                //Main.map.selectMapMode(new SelectAction(Main.map));
     315            }
     316           
     317            // Add new node to way
    299318            if (way.nodes.get(way.nodes.size() - 1) == n0) {
    300319                way.nodes.add(n);
     
    329348
    330349        Main.main.undoRedo.add(c);
    331         lastUsedNode = n;
     350        if(!wayIsFinished) lastUsedNode = n;
    332351        computeHelperLine();
    333352        Main.map.mapView.repaint();
Note: See TracChangeset for help on using the changeset viewer.