Changeset 17406 in josm


Ignore:
Timestamp:
2020-12-13T16:04:00+01:00 (4 years ago)
Author:
GerdP
Message:

fix #20230: update multipolygon action removes tags from ways without adding them to relation

  • create ChangeCommand if tags of updated relation were changed

Todo: refactoring to remove class CreateUpdateMultipolygonTask

Location:
trunk
Files:
2 added
2 edited

Legend:

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

    r17358 r17406  
    2626import org.openstreetmap.josm.actions.relation.DownloadSelectedIncompleteMembersAction;
    2727import org.openstreetmap.josm.command.AddCommand;
     28import org.openstreetmap.josm.command.ChangeCommand;
    2829import org.openstreetmap.josm.command.ChangeMembersCommand;
    2930import org.openstreetmap.josm.command.ChangePropertyCommand;
     
    112113                return;
    113114            }
    114             final Command command = commandAndRelation.a;
    115115
    116116            // to avoid EDT violations
    117117            SwingUtilities.invokeLater(() -> {
    118                 if (multipolygonRelation != null) {
    119                     // rather ugly: update generated a ChangeMembersCommand with a copy of the member list, so clear the list now
    120                     commandAndRelation.b.setMembers(null); // #see 19885
    121                 }
    122                 UndoRedoHandler.getInstance().add(command);
     118                UndoRedoHandler.getInstance().add(commandAndRelation.a);
     119                Relation calculatedRel = commandAndRelation.b;
     120                if (calculatedRel.getDataSet() == null) {
     121                    calculatedRel.setMembers(null); // see #19885
     122                }
    123123                final Relation relation = (Relation) MainApplication.getLayerManager().getEditDataSet()
    124                         .getPrimitiveById(commandAndRelation.b);
     124                        .getPrimitiveById(calculatedRel);
    125125                if (relation == null || relation.getDataSet() == null)
    126126                    return; // should not happen
     
    350350        } else {
    351351            if (!unchanged) {
    352                 list.add(new ChangeMembersCommand(existingRelation, new ArrayList<>(relation.getMembers())));
     352                if (relation.getKeys().equals(existingRelation.getKeys()))
     353                    list.add(new ChangeMembersCommand(existingRelation, new ArrayList<>(relation.getMembers())));
     354                else
     355                    list.add(new ChangeCommand(existingRelation, relation));
    353356            }
    354357            if (list.isEmpty()) {
  • trunk/test/unit/org/openstreetmap/josm/actions/CreateMultipolygonActionTest.java

    r17343 r17406  
    174174        assertEquals(numCoastlineWays, ds.getWays().stream().filter(w -> "coastline".equals(w.get("natural"))).count());
    175175    }
     176
     177    /**
     178     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/20230">Bug #20230</a>.
     179     * @throws Exception if an error occurs
     180     */
     181    @Test
     182    void testTicket20230() throws Exception {
     183        DataSet ds = OsmReader.parseDataSet(TestUtils.getRegressionDataStream(20230, "data.osm"), null);
     184        assertEquals(1, ds.getRelations().size());
     185        Relation mp = ds.getRelations().iterator().next();
     186        Relation modMp = createMultipolygon(ds.getWays(), "type:way", mp, true);
     187        assertNotNull(modMp);
     188        assertEquals(1, ds.getRelations().size());
     189        modMp = ds.getRelations().iterator().next();
     190        assertTrue(modMp.hasTag("building", "yes"));
     191        assertEquals(0, ds.getWays().stream().filter(w -> w.hasTag("building", "yes")).count());
     192    }
    176193}
Note: See TracChangeset for help on using the changeset viewer.