Ignore:
Timestamp:
2023-07-24T17:55:34+02:00 (16 months ago)
Author:
taylor.smock
Message:

reltoolbox: Preferentially use the source relation dataset

If the source relation does not have a dataset, use the current edit dataset instead.

This also adds some basic tests.

Location:
applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/AssociatedStreetFixer.java

    r36102 r36103  
    1212import org.openstreetmap.josm.command.Command;
    1313import org.openstreetmap.josm.command.SequenceCommand;
     14import org.openstreetmap.josm.data.osm.DataSet;
    1415import org.openstreetmap.josm.data.osm.Node;
    1516import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    1819import org.openstreetmap.josm.data.osm.Way;
    1920import org.openstreetmap.josm.gui.MainApplication;
     21import org.openstreetmap.josm.tools.Utils;
    2022
    2123public class AssociatedStreetFixer extends RelationFixer {
     
    135137        List<Command> commandList = new ArrayList<>();
    136138        if (fixed) {
    137             commandList.add(new ChangeCommand(MainApplication.getLayerManager().getEditDataSet(), source, rel));
     139            final DataSet ds = Utils.firstNonNull(source.getDataSet(), MainApplication.getLayerManager().getEditDataSet());
     140            commandList.add(new ChangeCommand(ds, source, rel));
    138141        }
    139142
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/BoundaryFixer.java

    r36102 r36103  
    66import org.openstreetmap.josm.command.ChangeCommand;
    77import org.openstreetmap.josm.command.Command;
     8import org.openstreetmap.josm.data.osm.DataSet;
    89import org.openstreetmap.josm.data.osm.Node;
    910import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    1112import org.openstreetmap.josm.data.osm.RelationMember;
    1213import org.openstreetmap.josm.gui.MainApplication;
     14import org.openstreetmap.josm.tools.Utils;
    1315
    1416/**
     
    6668            r = rr;
    6769        }
    68         return fixed ? new ChangeCommand(MainApplication.getLayerManager().getEditDataSet(), rel, r) : null;
     70        if (fixed) {
     71            final DataSet ds = Utils.firstNonNull(rel.getDataSet(), MainApplication.getLayerManager().getEditDataSet());
     72            return new ChangeCommand(ds, rel, r);
     73        }
     74        return null;
    6975    }
    7076
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/MultipolygonFixer.java

    r36102 r36103  
    1111import org.openstreetmap.josm.command.ChangeCommand;
    1212import org.openstreetmap.josm.command.Command;
     13import org.openstreetmap.josm.data.osm.DataSet;
    1314import org.openstreetmap.josm.data.osm.MultipolygonBuilder;
    14 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1515import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1616import org.openstreetmap.josm.data.osm.Relation;
     
    1818import org.openstreetmap.josm.data.osm.Way;
    1919import org.openstreetmap.josm.gui.MainApplication;
     20import org.openstreetmap.josm.tools.Utils;
    2021
    2122/**
     
    4748    public Command fixRelation(Relation rel) {
    4849        Relation rr = fixMultipolygonRoles(rel);
    49         return rr != null ? new ChangeCommand(MainApplication.getLayerManager().getEditDataSet(), rel, rr) : null;
     50        if (rr != null) {
     51            final DataSet ds = Utils.firstNonNull(rel.getDataSet(), MainApplication.getLayerManager().getEditDataSet());
     52            return new ChangeCommand(ds, rel, rr);
     53        }
     54        return null;
    5055    }
    5156
     
    5459     */
    5560    protected Relation fixMultipolygonRoles(Relation source) {
    56         Collection<Way> ways = new ArrayList<>();
    57         for (OsmPrimitive p : source.getMemberPrimitives()) {
    58             if (p instanceof Way) {
    59                 ways.add((Way) p);
    60             }
    61         }
     61        Collection<Way> ways = new ArrayList<>(source.getMemberPrimitives(Way.class));
    6262        MultipolygonBuilder mpc = new MultipolygonBuilder();
    6363        String error = mpc.makeFromWays(ways);
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/PublicTransportFixer.java

    r36102 r36103  
    66import org.openstreetmap.josm.command.ChangeCommand;
    77import org.openstreetmap.josm.command.Command;
     8import org.openstreetmap.josm.data.osm.DataSet;
    89import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    910import org.openstreetmap.josm.data.osm.Relation;
     
    1112import org.openstreetmap.josm.gui.MainApplication;
    1213
     14import org.openstreetmap.josm.tools.Utils;
    1315import relcontext.actions.PublicTransportHelper;
    1416
     
    6163            r = rr;
    6264        }
    63         return fixed ? new ChangeCommand(MainApplication.getLayerManager().getEditDataSet(), rel, r) : null;
     65        if (fixed) {
     66            final DataSet ds = Utils.firstNonNull(rel.getDataSet(), MainApplication.getLayerManager().getEditDataSet());
     67            return new ChangeCommand(ds, rel, r);
     68        }
     69        return null;
    6470    }
    6571
Note: See TracChangeset for help on using the changeset viewer.