Changeset 2339 in josm for trunk/src/org/openstreetmap/josm/actions/mapmode
- Timestamp:
- 2009-10-28T08:53:48+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r2264 r2339 127 127 return; 128 128 switch(c) { 129 130 131 132 133 134 135 136 137 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; 138 138 } 139 139 } … … 328 328 Collection<OsmPrimitive> selection = ds.getSelected(); 329 329 Collection<Command> cmds = new LinkedList<Command>(); 330 Collection<OsmPrimitive> newSelection = ds.getSelected(); 330 331 331 332 ArrayList<Way> reuseWays = new ArrayList<Way>(), … … 344 345 // (this is just a convenience option so that people don't 345 346 // have to switch modes) 346 getCurrentDataSet().setSelected(n); 347 DataSet.fireSelectionChanged(getCurrentDataSet().getSelected()); 348 selection = getCurrentDataSet().getSelected(); 347 newSelection.clear(); 348 newSelection.add(n); 349 349 // The user explicitly selected a node, so let him continue drawing 350 350 wayIsFinished = false; … … 406 406 // here so /only/ the new way will be selected after this method finishes. 407 407 if(alt) { 408 ds.addSelected(wnew);408 newSelection.add(insertPoint.getKey()); 409 409 } 410 410 … … 477 477 // user wants a new way. 478 478 Way way = alt ? null : (selectedWay != null) ? selectedWay : getWayForNode(n0); 479 Way wayToSelect; 479 480 480 481 // Don't allow creation of self-overlapping ways … … 494 495 way.addNode(n0); 495 496 cmds.add(new AddCommand(way)); 497 wayToSelect = way; 496 498 } else { 497 499 int i; 498 500 if ((i = replacedWays.indexOf(way)) != -1) { 499 501 way = reuseWays.get(i); 502 wayToSelect = way; 500 503 } else { 504 wayToSelect = way; 501 505 Way wnew = new Way(way); 502 506 cmds.add(new ChangeCommand(way, wnew)); … … 519 523 520 524 extendedWay = true; 521 getCurrentDataSet().setSelected(way);522 DataSet.fireSelectionChanged(ds.getSelected());525 newSelection.clear(); 526 newSelection.add(wayToSelect); 523 527 } 524 528 } … … 533 537 title = tr("Add node into way"); 534 538 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); 540 543 } else if (!newNode) { 541 544 title = tr("Connect existing way to node"); … … 552 555 lastUsedNode = n; 553 556 } 557 558 getCurrentDataSet().setSelected(newSelection); 554 559 555 560 computeHelperLine(); … … 815 820 816 821 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); 818 859 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()))); 867 872 } 868 873 }
Note:
See TracChangeset
for help on using the changeset viewer.