Changeset 2339 in josm for trunk/src


Ignore:
Timestamp:
2009-10-28T08:53:48+01:00 (14 years ago)
Author:
jttt
Message:

Fixed #3785

File:
1 edited

Legend:

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

    r2264 r2339  
    127127                        return;
    128128                    switch(c) {
    129                         case way:
    130                             Main.map.mapView.setCursor(cursorJoinWay);
    131                             break;
    132                         case node:
    133                             Main.map.mapView.setCursor(cursorJoinNode);
    134                             break;
    135                         default:
    136                             Main.map.mapView.setCursor(cursorCrosshair);
    137                             break;
     129                    case way:
     130                        Main.map.mapView.setCursor(cursorJoinWay);
     131                        break;
     132                    case node:
     133                        Main.map.mapView.setCursor(cursorJoinNode);
     134                        break;
     135                    default:
     136                        Main.map.mapView.setCursor(cursorCrosshair);
     137                        break;
    138138                    }
    139139                }
     
    328328        Collection<OsmPrimitive> selection = ds.getSelected();
    329329        Collection<Command> cmds = new LinkedList<Command>();
     330        Collection<OsmPrimitive> newSelection = ds.getSelected();
    330331
    331332        ArrayList<Way> reuseWays = new ArrayList<Way>(),
     
    344345                // (this is just a convenience option so that people don't
    345346                // have to switch modes)
    346                 getCurrentDataSet().setSelected(n);
    347                 DataSet.fireSelectionChanged(getCurrentDataSet().getSelected());
    348                 selection = getCurrentDataSet().getSelected();
     347                newSelection.clear();
     348                newSelection.add(n);
    349349                // The user explicitly selected a node, so let him continue drawing
    350350                wayIsFinished = false;
     
    406406                    // here so /only/ the new way will be selected after this method finishes.
    407407                    if(alt) {
    408                         ds.addSelected(wnew);
     408                        newSelection.add(insertPoint.getKey());
    409409                    }
    410410
     
    477477                // user wants a new way.
    478478                Way way = alt ? null : (selectedWay != null) ? selectedWay : getWayForNode(n0);
     479                Way wayToSelect;
    479480
    480481                // Don't allow creation of self-overlapping ways
     
    494495                    way.addNode(n0);
    495496                    cmds.add(new AddCommand(way));
     497                    wayToSelect = way;
    496498                } else {
    497499                    int i;
    498500                    if ((i = replacedWays.indexOf(way)) != -1) {
    499501                        way = reuseWays.get(i);
     502                        wayToSelect = way;
    500503                    } else {
     504                        wayToSelect = way;
    501505                        Way wnew = new Way(way);
    502506                        cmds.add(new ChangeCommand(way, wnew));
     
    519523
    520524                extendedWay = true;
    521                 getCurrentDataSet().setSelected(way);
    522                 DataSet.fireSelectionChanged(ds.getSelected());
     525                newSelection.clear();
     526                newSelection.add(wayToSelect);
    523527            }
    524528        }
     
    533537                title = tr("Add node into way");
    534538                for (Way w : reuseWays) {
    535                     ds.clearSelection(w);
    536                 }
    537             }
    538             getCurrentDataSet().setSelected(n);
    539             DataSet.fireSelectionChanged(getCurrentDataSet().getSelected());
     539                    newSelection.remove(w);
     540                }
     541            }
     542            newSelection.add(n);
    540543        } else if (!newNode) {
    541544            title = tr("Connect existing way to node");
     
    552555            lastUsedNode = n;
    553556        }
     557
     558        getCurrentDataSet().setSelected(newSelection);
    554559
    555560        computeHelperLine();
     
    815820
    816821        switch (segs.size()) {
    817             case 0:
     822        case 0:
     823            return;
     824        case 2:
     825            // This computes the intersection between
     826            // the two segments and adjusts the node position.
     827            Iterator<Pair<Node,Node>> i = segs.iterator();
     828            Pair<Node,Node> seg = i.next();
     829            EastNorth A = seg.a.getEastNorth();
     830            EastNorth B = seg.b.getEastNorth();
     831            seg = i.next();
     832            EastNorth C = seg.a.getEastNorth();
     833            EastNorth D = seg.b.getEastNorth();
     834
     835            double u=det(B.east() - A.east(), B.north() - A.north(), C.east() - D.east(), C.north() - D.north());
     836
     837            // Check for parallel segments and do nothing if they are
     838            // In practice this will probably only happen when a way has been duplicated
     839
     840            if (u == 0) return;
     841
     842            // q is a number between 0 and 1
     843            // It is the point in the segment where the intersection occurs
     844            // if the segment is scaled to lenght 1
     845
     846            double q = det(B.north() - C.north(), B.east() - C.east(), D.north() - C.north(), D.east() - C.east()) / u;
     847            EastNorth intersection = new EastNorth(
     848                    B.east() + q * (A.east() - B.east()),
     849                    B.north() + q * (A.north() - B.north()));
     850
     851            int snapToIntersectionThreshold
     852            = Main.pref.getInteger("edit.snap-intersection-threshold",10);
     853
     854            // only adjust to intersection if within snapToIntersectionThreshold pixel of mouse click; otherwise
     855            // fall through to default action.
     856            // (for semi-parallel lines, intersection might be miles away!)
     857            if (Main.map.mapView.getPoint(n).distance(Main.map.mapView.getPoint(intersection)) < snapToIntersectionThreshold) {
     858                n.setEastNorth(intersection);
    818859                return;
    819             case 2:
    820                 // This computes the intersection between
    821                 // the two segments and adjusts the node position.
    822                 Iterator<Pair<Node,Node>> i = segs.iterator();
    823                 Pair<Node,Node> seg = i.next();
    824                 EastNorth A = seg.a.getEastNorth();
    825                 EastNorth B = seg.b.getEastNorth();
    826                 seg = i.next();
    827                 EastNorth C = seg.a.getEastNorth();
    828                 EastNorth D = seg.b.getEastNorth();
    829 
    830                 double u=det(B.east() - A.east(), B.north() - A.north(), C.east() - D.east(), C.north() - D.north());
    831 
    832                 // Check for parallel segments and do nothing if they are
    833                 // In practice this will probably only happen when a way has been duplicated
    834 
    835                 if (u == 0) return;
    836 
    837                 // q is a number between 0 and 1
    838                 // It is the point in the segment where the intersection occurs
    839                 // if the segment is scaled to lenght 1
    840 
    841                 double q = det(B.north() - C.north(), B.east() - C.east(), D.north() - C.north(), D.east() - C.east()) / u;
    842                 EastNorth intersection = new EastNorth(
    843                         B.east() + q * (A.east() - B.east()),
    844                         B.north() + q * (A.north() - B.north()));
    845 
    846                 int snapToIntersectionThreshold
    847                 = Main.pref.getInteger("edit.snap-intersection-threshold",10);
    848 
    849                 // only adjust to intersection if within snapToIntersectionThreshold pixel of mouse click; otherwise
    850                 // fall through to default action.
    851                 // (for semi-parallel lines, intersection might be miles away!)
    852                 if (Main.map.mapView.getPoint(n).distance(Main.map.mapView.getPoint(intersection)) < snapToIntersectionThreshold) {
    853                     n.setEastNorth(intersection);
    854                     return;
    855                 }
    856 
    857             default:
    858                 EastNorth P = n.getEastNorth();
    859                 seg = segs.iterator().next();
    860                 A = seg.a.getEastNorth();
    861                 B = seg.b.getEastNorth();
    862                 double a = P.distanceSq(B);
    863                 double b = P.distanceSq(A);
    864                 double c = A.distanceSq(B);
    865                 q = (a - b + c) / (2*c);
    866                 n.setEastNorth(new EastNorth(B.east() + q * (A.east() - B.east()), B.north() + q * (A.north() - B.north())));
     860            }
     861
     862        default:
     863            EastNorth P = n.getEastNorth();
     864            seg = segs.iterator().next();
     865            A = seg.a.getEastNorth();
     866            B = seg.b.getEastNorth();
     867            double a = P.distanceSq(B);
     868            double b = P.distanceSq(A);
     869            double c = A.distanceSq(B);
     870            q = (a - b + c) / (2*c);
     871            n.setEastNorth(new EastNorth(B.east() + q * (A.east() - B.east()), B.north() + q * (A.north() - B.north())));
    867872        }
    868873    }
Note: See TracChangeset for help on using the changeset viewer.