Changeset 184 in josm
- Timestamp:
- 2006-12-31T21:24:56+01:00 (18 years ago)
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/ReverseSegmentAction.java
r178 r184 20 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 21 import org.openstreetmap.josm.data.osm.Segment; 22 import org.openstreetmap.josm.data.osm.Way; 23 import org.openstreetmap.josm.data.osm.visitor.Visitor; 22 24 23 25 public final class ReverseSegmentAction extends JosmAction { … … 28 30 29 31 public void actionPerformed(ActionEvent e) { 30 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 31 boolean hasSegments = false; 32 for (OsmPrimitive osm : sel) { 33 if (osm instanceof Segment) { 34 hasSegments = true; 35 break; 36 } 37 } 38 if (!hasSegments) { 32 final Collection<Segment> sel = new LinkedList<Segment>(); 33 new Visitor(){ 34 public void visit(Node n) {} 35 public void visit(Segment s) {sel.add(s);} 36 public void visit(Way w) {sel.addAll(w.segments);} 37 public void visitAll() { 38 for (OsmPrimitive osm : Main.ds.getSelected()) 39 osm.visit(this); 40 } 41 }.visitAll(); 42 43 if (sel.isEmpty()) { 39 44 JOptionPane.showMessageDialog(Main.parent, tr("Please select at least one segment.")); 40 45 return; 41 46 } 42 47 Collection<Command> c = new LinkedList<Command>(); 43 for (OsmPrimitive osm : sel) { 44 if (!(osm instanceof Segment)) 45 continue; 46 Segment s = (Segment)osm; 48 for (Segment s : sel) { 47 49 Segment snew = new Segment(s); 48 50 Node n = snew.from; -
src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java
r170 r184 149 149 if (way != null) { 150 150 Way newWay = new Way(way); 151 if (way.segments.get(0).from == n1) 151 if (way.segments.get(0).from == n1) { 152 Node tmp = s.from; 153 s.from = s.to; 154 s.to = tmp; 152 155 newWay.segments.add(0, s); 153 else156 } else 154 157 newWay.segments.add(s); 155 158 cmds.add(new ChangeCommand(way, newWay)); -
src/org/openstreetmap/josm/actions/mapmode/AddWayAction.java
r113 r184 9 9 import java.util.Collection; 10 10 import java.util.HashSet; 11 import java.util.Iterator;12 11 import java.util.LinkedList; 13 12 … … 15 14 16 15 import org.openstreetmap.josm.Main; 16 import org.openstreetmap.josm.actions.ReorderAction; 17 17 import org.openstreetmap.josm.command.AddCommand; 18 18 import org.openstreetmap.josm.command.ChangeCommand; … … 189 189 return null; 190 190 191 // sort the segments in best possible order. This is done by: 192 // 0 if no elements in list, quit 193 // 1 taking the first ls as pivot, remove it from list 194 // 2 searching for a connection at from or to of pivot 195 // 3 if found, attach it, remove it from list, goto 2 196 // 4 if not found, save the pivot-string and goto 0 197 LinkedList<Segment> sortedSegments = new LinkedList<Segment>(); 198 LinkedList<Segment> segments = new LinkedList<Segment>(segmentSet); 199 while (!segments.isEmpty()) { 200 LinkedList<Segment> pivotList = new LinkedList<Segment>(); 201 pivotList.add(segments.getFirst()); 202 segments.removeFirst(); 203 for (boolean found = true; found;) { 204 found = false; 205 for (Iterator<Segment> it = segments.iterator(); it.hasNext();) { 206 Segment ls = it.next(); 207 if (ls.incomplete) 208 continue; // incomplete segments are never added to a new way 209 if (ls.from == pivotList.getLast().to) { 210 pivotList.addLast(ls); 211 it.remove(); 212 found = true; 213 } else if (ls.to == pivotList.getFirst().from) { 214 pivotList.addFirst(ls); 215 it.remove(); 216 found = true; 217 } 218 } 219 } 220 sortedSegments.addAll(pivotList); 221 } 191 LinkedList<Segment> sortedSegments = ReorderAction.sortSegments(segmentSet); 222 192 223 193 if (wayToAdd != null) { -
src/org/openstreetmap/josm/gui/MainMenu.java
r181 r184 20 20 import org.openstreetmap.josm.actions.PreferencesAction; 21 21 import org.openstreetmap.josm.actions.RedoAction; 22 import org.openstreetmap.josm.actions.ReorderAction; 22 23 import org.openstreetmap.josm.actions.ReverseSegmentAction; 23 24 import org.openstreetmap.josm.actions.SaveAction; … … 48 49 public final Action alignInCircle = new AlignInCircleAction(); 49 50 public final Action alignInLine = new AlignInLineAction(); 51 public final Action reorder = new ReorderAction(); 50 52 public final Action upload = new UploadAction(); 51 53 public final Action save = new SaveAction(); … … 87 89 editMenu.add(alignInCircle); 88 90 editMenu.add(alignInLine); 91 editMenu.add(reorder); 89 92 editMenu.addSeparator(); 90 93 editMenu.add(preferences);
Note:
See TracChangeset
for help on using the changeset viewer.