Changeset 36217 in osm for applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/ReconstructPolygonAction.java
- Timestamp:
- 2024-03-03T10:25:25+01:00 (9 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/ReconstructPolygonAction.java
r36142 r36217 8 8 import java.util.ArrayList; 9 9 import java.util.Arrays; 10 import java.util.Collection; 10 11 import java.util.Collections; 11 12 import java.util.HashSet; … … 19 20 import org.openstreetmap.josm.command.AddCommand; 20 21 import org.openstreetmap.josm.command.ChangeCommand; 22 import org.openstreetmap.josm.command.ChangeMembersCommand; 21 23 import org.openstreetmap.josm.command.Command; 22 24 import org.openstreetmap.josm.command.DeleteCommand; … … 43 45 */ 44 46 public class ReconstructPolygonAction extends JosmAction implements ChosenRelationListener { 45 private final ChosenRelation rel;47 private final transient ChosenRelation rel; 46 48 47 49 private static final List<String> IRRELEVANT_KEYS = Arrays.asList("source", "created_by", "note"); 48 50 51 /** 52 * Reconstruct one or more polygons from multipolygon relation. 53 * @param rel the multipolygon relation 54 */ 49 55 public ReconstructPolygonAction(ChosenRelation rel) { 50 56 super(tr("Reconstruct polygon"), "dialogs/filter", tr("Reconstruct polygon from multipolygon relation"), 51 57 Shortcut.registerShortcut("reltoolbox:reconstructpoly", tr("Relation Toolbox: {0}", 52 58 tr("Reconstruct polygon from multipolygon relation")), 53 KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false );59 KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false, false); 54 60 this.rel = rel; 55 61 rel.addChosenRelationListener(this); … … 72 78 if (wont) { 73 79 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 74 tr("Multipolygon must consist only of ways with one referring relation"),80 tr("Multipolygon must consist only of ways"), 75 81 tr("Reconstruct polygon"), JOptionPane.ERROR_MESSAGE); 76 82 return; … … 85 91 86 92 rel.clear(); 87 List<OsmPrimitive> newSelection = new ArrayList<>();88 93 List<Command> commands = new ArrayList<>(); 89 94 Command relationDeleteCommand = DeleteCommand.delete(Collections.singleton(r), true, true); … … 108 113 // this ring has inner rings, so we leave a multipolygon in 109 114 // place and don't reconstruct the rings. 115 List<RelationMember> members = new ArrayList<>(); 110 116 Relation n; 117 for (Way w : p.ways) { 118 members.add(new RelationMember("outer", w)); 119 } 120 for (JoinedPolygon i : myInnerWays) { 121 for (Way w : i.ways) { 122 members.add(new RelationMember("inner", w)); 123 } 124 } 111 125 if (relationReused) { 112 126 n = new Relation(); 113 127 n.setKeys(r.getKeys()); 114 } else { 115 n = new Relation(r); 116 n.setMembers(null); 117 } 118 for (Way w : p.ways) { 119 n.addMember(new RelationMember("outer", w)); 120 } 121 for (JoinedPolygon i : myInnerWays) { 122 for (Way w : i.ways) { 123 n.addMember(new RelationMember("inner", w)); 124 } 125 } 126 if (relationReused) { 128 n.setMembers(members); 127 129 commands.add(new AddCommand(ds, n)); 128 130 } else { 129 131 relationReused = true; 130 commands.add(new ChangeCommand(r, n)); 131 } 132 newSelection.add(n); 132 commands.add(new ChangeMembersCommand(r, members)); 133 } 133 134 continue; 134 135 } … … 186 187 result.addNode(result.firstNode()); 187 188 result.setKeys(tags); 188 newSelection.add(candidateWay == null ? result : candidateWay);189 189 commands.add(candidateWay == null ? new AddCommand(ds, result) : new ChangeCommand(candidateWay, result)); 190 190 } … … 195 195 commands.add(0, relationDeleteCommand); 196 196 } 197 198 197 UndoRedoHandler.getInstance().add(new SequenceCommand(tr("Reconstruct polygons from relation {0}", 199 198 r.getDisplayName(DefaultNameFormatter.getInstance())), commands)); 199 Collection<? extends OsmPrimitive> newSelection = UndoRedoHandler.getInstance().getLastCommand().getParticipatingPrimitives(); 200 newSelection.removeIf(p -> p.isDeleted()); 200 201 ds.setSelected(newSelection); 201 202 }
Note:
See TracChangeset
for help on using the changeset viewer.