Changeset 36142 in osm for applications/editors/josm/plugins
- Timestamp:
- 2023-09-18T19:27:57+02:00 (14 months ago)
- Location:
- applications/editors/josm/plugins/reltoolbox
- Files:
-
- 4 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/ReconstructPolygonAction.java
r36136 r36142 64 64 boolean wont = false; 65 65 for (RelationMember m : r.getMembers()) { 66 if (m.isWay() && m.getWay().getReferrers().size() == 1) {66 if (m.isWay()) { 67 67 ways.add(m.getWay()); 68 68 } else { … … 157 157 tags.remove("type"); 158 158 159 // then delete ways that are not relevant (do not take part in other relations o fhave strange tags)159 // then delete ways that are not relevant (do not take part in other relations or have strange tags) 160 160 Way candidateWay = null; 161 161 for (Way w : p.ways) { 162 if (w.getReferrers(). equals(relations)) {162 if (w.getReferrers().size() == 1) { 163 163 // check tags that remain 164 164 Set<String> keys = new HashSet<>(w.keySet()); … … 192 192 // only delete the relation if it hasn't been re-used 193 193 if (!relationReused) { 194 commands.add(relationDeleteCommand); 194 // The relation needs to be deleted first, so that undo/redo continue to work properly 195 commands.add(0, relationDeleteCommand); 195 196 } 196 197 -
applications/editors/josm/plugins/reltoolbox/test/unit/relcontext/actions/ReconstructPolygonActionTest.java
r36136 r36142 5 5 import static org.junit.jupiter.api.Assertions.assertEquals; 6 6 import static org.junit.jupiter.api.Assertions.assertTrue; 7 import static org.openstreetmap.josm.tools.I18n.tr;8 7 9 import java.awt.Component; 10 import java.util.Arrays; 8 import java.io.IOException; 11 9 import java.util.Collection; 12 import java.util.concurrent.atomic.AtomicBoolean;13 import java.util.concurrent.atomic.AtomicReference;14 import java.util.function.Predicate;15 10 import java.util.stream.Stream; 16 17 import javax.swing.JOptionPane;18 11 19 12 import org.junit.jupiter.api.AfterEach; … … 23 16 import org.openstreetmap.josm.actions.DeleteAction; 24 17 import org.openstreetmap.josm.command.DeleteCommand; 18 import org.openstreetmap.josm.data.UndoRedoHandler; 25 19 import org.openstreetmap.josm.data.osm.DataSet; 26 20 import org.openstreetmap.josm.data.osm.DatasetConsistencyTest; 27 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 28 23 import org.openstreetmap.josm.data.osm.Relation; 29 24 import org.openstreetmap.josm.data.osm.RelationMember; 30 25 import org.openstreetmap.josm.data.osm.RelationToChildReference; 26 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 31 27 import org.openstreetmap.josm.data.osm.Way; 32 28 import org.openstreetmap.josm.gui.MainApplication; 33 29 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 30 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 34 31 import org.openstreetmap.josm.gui.util.GuiHelper; 32 import org.openstreetmap.josm.io.IllegalDataException; 33 import org.openstreetmap.josm.io.OsmReader; 35 34 import org.openstreetmap.josm.testutils.annotations.Main; 36 35 import org.openstreetmap.josm.testutils.annotations.Projection; 37 36 38 37 import junit.framework.AssertionFailedError; 39 import mockit.Mock;40 import mockit.MockUp;41 38 import relcontext.ChosenRelation; 42 39 … … 108 105 assertEquals(1, keptWay.getNodes().stream().distinct().filter(n -> "3".equals(n.get("name"))).count()); 109 106 assertEmpty(DatasetConsistencyTest.runTests(ds)); 107 assertDoesNotThrow(() -> UndoRedoHandler.getInstance().undo()); 108 assertEmpty(DatasetConsistencyTest.runTests(ds)); 110 109 } 111 110 … … 115 114 @Test 116 115 void testPolygonReconstructComplex() { 117 final AtomicReference<String> shownMessage = new AtomicReference<>();118 new MockUp<JOptionPane>() {119 @Mock120 void showMessageDialog(Component parentComponent,121 Object message, String title, int messageType) {122 shownMessage.set((String) message);123 }124 };125 116 final Relation otherRelation = TestUtils.newRelation("type=multipolygon landuse=retail", 126 117 new RelationMember("outer", way1), … … 131 122 assertDoesNotThrow(() -> GuiHelper.runInEDTAndWait(() -> action.actionPerformed(null))); 132 123 assertEmpty(DatasetConsistencyTest.runTests(ds)); 133 assertEquals(tr("Multipolygon must consist only of ways with one referring relation"), shownMessage.get()); 124 assertDoesNotThrow(() -> UndoRedoHandler.getInstance().undo()); 125 assertEmpty(DatasetConsistencyTest.runTests(ds)); 126 } 127 128 /** 129 * Ensure that we bail if a way in the relation to be simplified will be deleted from another relation. 130 */ 131 @Test 132 void testPolygonReconstructDuplicate() { 133 final Relation otherRelation = TestUtils.newRelation("type=multipolygon landuse=retail", 134 new RelationMember("outer", way1), 135 new RelationMember("outer", way2), 136 new RelationMember("outer", way3)); 137 ds.addPrimitiveRecursive(otherRelation); 138 assertDoesNotThrow(() -> GuiHelper.runInEDTAndWait(() -> action.actionPerformed(null))); 139 assertEmpty(DatasetConsistencyTest.runTests(ds)); 140 assertDoesNotThrow(() -> UndoRedoHandler.getInstance().undo()); 141 assertEmpty(DatasetConsistencyTest.runTests(ds)); 142 } 143 144 @Test 145 void testPolygonReconstructR1585888() throws IOException, IllegalDataException { 146 ds.clear(); 147 ds.mergeFrom(OsmReader.parseDataSet(TestUtils.getRegressionDataStream(23170, "r1585888.osm"), NullProgressMonitor.INSTANCE)); 148 assertEmpty(DatasetConsistencyTest.runTests(ds)); 149 150 ds.setSelected(new SimplePrimitiveId(1585888, OsmPrimitiveType.RELATION)); 151 chosenRelation.set((Relation) ds.getPrimitiveById(1585888, OsmPrimitiveType.RELATION)); 152 assertDoesNotThrow(() -> GuiHelper.runInEDTAndWait(() -> action.actionPerformed(null))); 153 assertEmpty(DatasetConsistencyTest.runTests(ds)); 154 155 final Collection<Way> selectedWays = ds.getSelectedWays(); 156 assertEquals(selectedWays.size(), ds.getSelected().size()); 157 assertTrue(selectedWays.stream().allMatch(Way::isClosed)); 158 assertTrue(selectedWays.stream().mapToInt(Way::getNodesCount).anyMatch(i -> i == 15)); 159 assertTrue(selectedWays.stream().mapToInt(Way::getNodesCount).anyMatch(i -> i == 23)); 160 assertTrue(selectedWays.stream().mapToInt(Way::getNodesCount).anyMatch(i -> i == 37)); 161 assertTrue(selectedWays.stream().allMatch(way -> "residential".equals(way.get("landuse")))); 162 assertDoesNotThrow(() -> UndoRedoHandler.getInstance().undo()); 163 assertEmpty(DatasetConsistencyTest.runTests(ds)); 134 164 } 135 165
Note:
See TracChangeset
for help on using the changeset viewer.