Changeset 23 in josm for src/org/openstreetmap/josm/actions/mapmode/AddTrackAction.java
- Timestamp:
- 2005-10-27T00:38:03+02:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/mapmode/AddTrackAction.java
r22 r23 4 4 import java.awt.event.KeyEvent; 5 5 import java.util.Collection; 6 import java.util.Iterator; 6 7 import java.util.LinkedList; 7 8 8 9 import org.openstreetmap.josm.Main; 9 10 import org.openstreetmap.josm.command.AddCommand; 10 import org.openstreetmap.josm.command.Command;11 11 import org.openstreetmap.josm.data.osm.LineSegment; 12 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 98 98 for (OsmPrimitive osm : selection) { 99 99 if (osm instanceof Track) 100 lineSegments.addAll(((Track)osm).segments ());100 lineSegments.addAll(((Track)osm).segments); 101 101 else if (osm instanceof LineSegment) 102 102 lineSegments.add((LineSegment)osm); 103 103 } 104 105 // sort the line segments in best possible order. This is done by: 106 // 0 if no elements in list, quit 107 // 1 taking the first ls as pivot, remove it from list 108 // 2 searching for a connection at start or end of pivot 109 // 3 if found, attach it, remove it from list, goto 2 110 // 4 if not found, save the pivot-string and goto 0 111 LinkedList<LineSegment> sortedLineSegments = new LinkedList<LineSegment>(); 112 while (!lineSegments.isEmpty()) { 113 LinkedList<LineSegment> pivotList = new LinkedList<LineSegment>(); 114 pivotList.add(lineSegments.getFirst()); 115 lineSegments.removeFirst(); 116 for (boolean found = true; found;) { 117 found = false; 118 for (Iterator<LineSegment> it = lineSegments.iterator(); it.hasNext();) { 119 LineSegment ls = it.next(); 120 if (ls.start == pivotList.getLast().end) { 121 pivotList.addLast(ls); 122 it.remove(); 123 found = true; 124 } else if (ls.end == pivotList.getFirst().start) { 125 pivotList.addFirst(ls); 126 it.remove(); 127 found = true; 128 } 129 } 130 } 131 sortedLineSegments.addAll(pivotList); 132 } 133 104 134 Track t = new Track(); 105 for (LineSegment ls : lineSegments)135 for (LineSegment ls : sortedLineSegments) 106 136 t.add(ls); 107 Command c = new AddCommand(t); 108 c.executeCommand(); 109 Main.main.commands.add(c); 137 mv.editLayer().add(new AddCommand(t)); 110 138 Main.main.ds.clearSelection(); 111 139 } 112 113 @Override114 protected boolean isEditMode() {115 return true;116 }117 140 }
Note:
See TracChangeset
for help on using the changeset viewer.