| 1 | package UtilsPlugin;
|
|---|
| 2 |
|
|---|
| 3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 4 |
|
|---|
| 5 | import java.util.ArrayList;
|
|---|
| 6 | import java.util.LinkedList;
|
|---|
| 7 | import java.util.List;
|
|---|
| 8 | import java.util.Collection;
|
|---|
| 9 |
|
|---|
| 10 | import java.awt.event.ActionEvent;
|
|---|
| 11 |
|
|---|
| 12 | import org.openstreetmap.josm.Main;
|
|---|
| 13 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
|---|
| 14 | import org.openstreetmap.josm.data.osm.Node;
|
|---|
| 15 | import org.openstreetmap.josm.data.osm.Segment;
|
|---|
| 16 | import org.openstreetmap.josm.data.osm.Way;
|
|---|
| 17 | import org.openstreetmap.josm.gui.MapFrame;
|
|---|
| 18 | import org.openstreetmap.josm.command.Command;
|
|---|
| 19 | import org.openstreetmap.josm.command.ChangeCommand;
|
|---|
| 20 | import org.openstreetmap.josm.command.SequenceCommand;
|
|---|
| 21 |
|
|---|
| 22 | import javax.swing.AbstractAction;
|
|---|
| 23 |
|
|---|
| 24 | class DeduplicateWayAction extends AbstractAction {
|
|---|
| 25 | public DeduplicateWayAction() {
|
|---|
| 26 | super("Deduplicate Way");
|
|---|
| 27 | }
|
|---|
| 28 | public void actionPerformed(ActionEvent e) {
|
|---|
| 29 | Collection<OsmPrimitive> sel = Main.ds.getSelected();
|
|---|
| 30 | Collection<Way> ways = new ArrayList<Way>();
|
|---|
| 31 | for (OsmPrimitive osm : sel)
|
|---|
| 32 | if (osm instanceof Way)
|
|---|
| 33 | ways.add((Way)osm);
|
|---|
| 34 |
|
|---|
| 35 | Collection<Command> cmds = new LinkedList<Command>();
|
|---|
| 36 | for ( Way w : ways )
|
|---|
| 37 | {
|
|---|
| 38 | List<Segment> segs = new ArrayList<Segment>();
|
|---|
| 39 |
|
|---|
| 40 | for ( Segment s : w.segments )
|
|---|
| 41 | {
|
|---|
| 42 | if( !segs.contains(s) )
|
|---|
| 43 | segs.add(s);
|
|---|
| 44 | }
|
|---|
| 45 | if( segs.size() != w.segments.size() )
|
|---|
| 46 | {
|
|---|
| 47 | Way newway = new Way(w);
|
|---|
| 48 | newway.segments.clear();
|
|---|
| 49 | newway.segments.addAll(segs);
|
|---|
| 50 | cmds.add(new ChangeCommand(w,newway));
|
|---|
| 51 | }
|
|---|
| 52 | }
|
|---|
| 53 | if( cmds.size() != 0 )
|
|---|
| 54 | Main.main.editLayer().add(new SequenceCommand(tr("Deduplicate Ways"), cmds));
|
|---|
| 55 | Main.map.repaint();
|
|---|
| 56 | }
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|