Changeset 184 in josm for src


Ignore:
Timestamp:
2006-12-31T21:24:56+01:00 (17 years ago)
Author:
imi
Message:
  • added reorder action to order the segments in a way
Location:
src/org/openstreetmap/josm
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/actions/ReverseSegmentAction.java

    r178 r184  
    2020import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2121import org.openstreetmap.josm.data.osm.Segment;
     22import org.openstreetmap.josm.data.osm.Way;
     23import org.openstreetmap.josm.data.osm.visitor.Visitor;
    2224
    2325public final class ReverseSegmentAction extends JosmAction {
     
    2830
    2931        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()) {
    3944                JOptionPane.showMessageDialog(Main.parent, tr("Please select at least one segment."));
    4045                return;
    4146        }
    4247        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) {
    4749                Segment snew = new Segment(s);
    4850                Node n = snew.from;
  • src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java

    r170 r184  
    149149                                if (way != null) {
    150150                                        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;
    152155                                                newWay.segments.add(0, s);
    153                                         else
     156                                        } else
    154157                                                newWay.segments.add(s);
    155158                                        cmds.add(new ChangeCommand(way, newWay));
  • src/org/openstreetmap/josm/actions/mapmode/AddWayAction.java

    r113 r184  
    99import java.util.Collection;
    1010import java.util.HashSet;
    11 import java.util.Iterator;
    1211import java.util.LinkedList;
    1312
     
    1514
    1615import org.openstreetmap.josm.Main;
     16import org.openstreetmap.josm.actions.ReorderAction;
    1717import org.openstreetmap.josm.command.AddCommand;
    1818import org.openstreetmap.josm.command.ChangeCommand;
     
    189189                        return null;
    190190
    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);
    222192
    223193                if (wayToAdd != null) {
  • src/org/openstreetmap/josm/gui/MainMenu.java

    r181 r184  
    2020import org.openstreetmap.josm.actions.PreferencesAction;
    2121import org.openstreetmap.josm.actions.RedoAction;
     22import org.openstreetmap.josm.actions.ReorderAction;
    2223import org.openstreetmap.josm.actions.ReverseSegmentAction;
    2324import org.openstreetmap.josm.actions.SaveAction;
     
    4849        public final Action alignInCircle = new AlignInCircleAction();
    4950        public final Action alignInLine = new AlignInLineAction();
     51        public final Action reorder = new ReorderAction();
    5052        public final Action upload = new UploadAction();
    5153        public final Action save = new SaveAction();
     
    8789                editMenu.add(alignInCircle);
    8890                editMenu.add(alignInLine);
     91                editMenu.add(reorder);
    8992                editMenu.addSeparator();
    9093                editMenu.add(preferences);
Note: See TracChangeset for help on using the changeset viewer.