Changeset 33416 in osm


Ignore:
Timestamp:
2017-06-28T17:40:23+02:00 (7 years ago)
Author:
giackserva
Message:

[pt_assistant] #josm14933 - downloading incomplete relations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/SplitRoundaboutAction.java

    r33415 r33416  
    2424import org.openstreetmap.josm.actions.SplitWayAction.SplitWayResult;
    2525import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
     26import org.openstreetmap.josm.actions.relation.DownloadSelectedIncompleteMembersAction;
    2627import org.openstreetmap.josm.command.ChangeCommand;
    2728import org.openstreetmap.josm.command.Command;
     
    3536import org.openstreetmap.josm.data.osm.RelationMember;
    3637import org.openstreetmap.josm.data.osm.Way;
     38import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask;
    3739import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils;
    3840import org.openstreetmap.josm.tools.Pair;
     
    7779                rbbox.getBottomRightLon() + lonOffset);
    7880        Future<?> future = task.download(false, area, null);
     81
    7982        Main.worker.submit(() -> {
    8083            try {
    8184                future.get();
    82                 continueAfterDownload(roundabout);
     85                downloadIncompleteRelations(roundabout);
    8386            } catch (InterruptedException | ExecutionException e1) {
    8487                 Main.error(e1);
     
    117120    }
    118121
     122    private void downloadIncompleteRelations(Way roundabout) {
     123
     124        List<Relation> parents = getPTRouteParents(roundabout);
     125        parents.removeIf(r -> !r.hasIncompleteMembers());
     126        if(parents.isEmpty())
     127            continueAfterDownload(roundabout);
     128
     129        Future <?>future = Main.worker.submit(new DownloadRelationMemberTask(
     130            parents,
     131            DownloadSelectedIncompleteMembersAction.buildSetOfIncompleteMembers(parents),
     132            Main.getLayerManager().getEditLayer()));
     133
     134        Main.worker.submit(() -> {
     135            try {
     136                future.get();
     137                continueAfterDownload(roundabout);
     138            } catch (InterruptedException | ExecutionException e1) {
     139                 Main.error(e1);
     140                return;
     141            }
     142        });
     143    }
     144
    119145    public Command getUpdateRelationsCommand(Map<Relation,
    120146            List<Integer>> savedPositions,
     
    151177                Way entryWay = entryExitWays.a;
    152178                Way exitWay = entryExitWays.b;
     179
     180                if(entryWay == null || exitWay == null)
     181                    return;
    153182
    154183                //get the entry and exit nodes, exit if not found
     
    195224        //the ways returned are the one exactly before and after the roundabout
    196225        Pair<Way, Way> ret = new Pair<>(null, null);
    197         ret.a = r.getMember(position-1).getWay();
    198         ret.b = r.getMember(position).getWay();
     226
     227        RelationMember before = r.getMember(position-1);
     228        if(before.isWay())
     229            ret.a = before.getWay();
     230
     231        RelationMember after = r.getMember(position);
     232        if(after.isWay())
     233            ret.b = after.getWay();
     234
    199235        return ret;
    200236    }
     
    212248            parents.remove(roundabout);
    213249            for(Way parent: parents) {
    214                 for(Relation r : OsmPrimitive.getFilteredList(
    215                         parent.getReferrers(), Relation.class)) {
    216                     if(RouteUtils.isPTRoute(r))
     250                if(!getPTRouteParents(parent).isEmpty()) {
    217251                        return false;
    218252                }
     
    225259
    226260    public Command getRemoveRoundaboutFromRelationsCommand(Way roundabout) {
    227         List <Relation> referrers = OsmPrimitive.getFilteredList(
    228                 roundabout.getReferrers(), Relation.class);
    229         referrers.removeIf(r -> !RouteUtils.isPTRoute(r));
    230 
    231261        List<Command> commands = new ArrayList<>();
    232         referrers.forEach(r -> {
     262        getPTRouteParents(roundabout).forEach(r -> {
    233263            Relation c = new Relation(r);
    234264            c.removeMembersFor(roundabout);
     
    244274
    245275        Map<Relation, List<Integer>> savedPositions = new HashMap<>();
    246         List <Relation> referrers = OsmPrimitive.getFilteredList(
    247                 roundabout.getReferrers(), Relation.class);
    248         referrers.removeIf(r -> !RouteUtils.isPTRoute(r));
    249 
    250         for(Relation curr : referrers) {
     276
     277        for(Relation curr : getPTRouteParents(roundabout)) {
    251278            for(int j = 0; j < curr.getMembersCount(); j++) {
    252279                if(curr.getMember(j).getUniqueId() == roundabout.getUniqueId()) {
     
    260287
    261288        return savedPositions;
     289    }
     290
     291    private List<Relation> getPTRouteParents(Way roundabout) {
     292        List <Relation> referrers = OsmPrimitive.getFilteredList(
     293                roundabout.getReferrers(), Relation.class);
     294        referrers.removeIf(r -> !RouteUtils.isPTRoute(r));
     295        return referrers;
    262296    }
    263297
Note: See TracChangeset for help on using the changeset viewer.