Ignore:
Timestamp:
2017-07-19T00:15:47+02:00 (7 years ago)
Author:
giackserva
Message:

[pt_assistant] CreatePlatformNodeAction finished implementation

Location:
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
Files:
2 edited

Legend:

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

    r33459 r33461  
    1818import org.openstreetmap.josm.plugins.PluginInformation;
    1919import org.openstreetmap.josm.plugins.pt_assistant.actions.AddStopPositionAction;
     20import org.openstreetmap.josm.plugins.pt_assistant.actions.CreatePlatformNodeAction;
    2021import org.openstreetmap.josm.plugins.pt_assistant.actions.EdgeSelectionAction;
    2122import org.openstreetmap.josm.plugins.pt_assistant.actions.EditHighlightedRelationsAction;
     
    6869        MainMenu.add(Main.main.menu.toolsMenu, new SplitRoundaboutAction());
    6970        MainMenu.add(Main.main.menu.toolsMenu, new SortPTStopsAction());
     71        MainMenu.add(Main.main.menu.toolsMenu, new CreatePlatformNodeAction());
    7072    }
    7173
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/CreatePlatformNodeAction.java

    r33459 r33461  
    44
    55import java.awt.event.ActionEvent;
     6import java.util.ArrayList;
    67import java.util.Collection;
    7 import java.util.HashMap;
     8import java.util.Collections;
    89import java.util.List;
    9 import java.util.Map;
    1010import java.util.Map.Entry;
    1111
     12import org.openstreetmap.josm.Main;
    1213import org.openstreetmap.josm.actions.JosmAction;
     14import org.openstreetmap.josm.command.AddCommand;
     15import org.openstreetmap.josm.command.Command;
     16import org.openstreetmap.josm.command.DeleteCommand;
     17import org.openstreetmap.josm.command.SequenceCommand;
    1318import org.openstreetmap.josm.data.osm.Node;
    1419import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1520import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    16 import org.openstreetmap.josm.data.osm.Relation;
     21import org.openstreetmap.josm.data.osm.TagCollection;
    1722import org.openstreetmap.josm.data.osm.Way;
    18 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils;
     23import org.openstreetmap.josm.gui.conflict.tags.CombinePrimitiveResolverDialog;
     24import org.openstreetmap.josm.tools.UserCancelException;
    1925
    2026/**
     
    2733
    2834    private static final String ACTION_NAME = "Transfer details of stop to platform node";
     35
     36    private Node dummy1;
     37    private Node dummy2;
     38    private Node dummy3;
    2939
    3040    /**
     
    3949        Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected();
    4050        Node platformNode = null;
    41         Node stopPostionNode = null;
    42         Way  platformWay = null;
    43         Map<String, List<String>> tagsToCompare = new HashMap<>();
     51        Node stopPositionNode = null;
     52        Way platformWay = null;
     53
    4454        for (OsmPrimitive item: selection) {
    45             if (item.getType() == OsmPrimitiveType.NODE &&
    46                     (item.hasTag("amenity", "shelter") || item.hasTag("public_transport", "pole"))) {
    47                 platformNode = (Node) item;
    48             }
    49             if (item.getType() == OsmPrimitiveType.NODE &&
    50                     item.hasTag("public_transport", "stop_position")) {
    51                 stopPostionNode = (Node) item;
    52                 }
    53             if (item.getType() == OsmPrimitiveType.WAY &&
     55            if (item.getType() == OsmPrimitiveType.NODE) {
     56                if (item.hasTag("public_transport", "stop_position"))
     57                    stopPositionNode = (Node) item;
     58                else
     59                    platformNode = (Node) item;
     60            } else if (item.getType() == OsmPrimitiveType.WAY &&
    5461                    item.hasTag("public_transport", "platform")) {
    5562                platformWay = (Way) item;
    5663            }
    5764        }
    58         if (platformNode == null && stopPostionNode == null && platformWay == null) {
     65
     66        if (platformNode == null || stopPositionNode == null) {
    5967            return;
    6068        }
    61     }
    62     public void populateMap(OsmPrimitive prim, Map<String, List<String>> tagsToCompare) {
    63         for ( Entry<String, String> tag: prim.getKeys().entrySet()) {
    64             //tagsToCompare.put(tag.getKey(), tag.getValue());
     69
     70        dummy1 = new Node(platformNode.getEastNorth());
     71        dummy2 = new Node(platformNode.getEastNorth());
     72        dummy3 = new Node(platformNode.getEastNorth());
     73
     74        Main.main.undoRedo.add(new AddCommand(dummy1));
     75        Main.main.undoRedo.add(new AddCommand(dummy2));
     76        Main.main.undoRedo.add(new AddCommand(dummy3));
     77
     78        populateMap(stopPositionNode);
     79        populateMap(platformNode);
     80
     81        if (platformWay != null) {
     82            populateMap(platformWay);
     83            platformWay.removeAll();
     84            platformWay.put("public_transport", "platform");
     85            platformWay.put(" highway", "platform");
     86        }
     87
     88        stopPositionNode.removeAll();
     89        stopPositionNode.put("bus", "yes");
     90        stopPositionNode.put("public_transport", "stop_position");
     91
     92        platformNode.removeAll();
     93        platformNode.put("public_transport", "platform");
     94        platformNode.put("highway", "bus_stop");
     95
     96        List<OsmPrimitive> prims = new ArrayList<>();
     97        prims.add(platformNode);
     98        prims.add(dummy1);
     99        prims.add(dummy2);
     100        prims.add(dummy3);
     101
     102        try {
     103            TagCollection tagColl = TagCollection.unionOfAllPrimitives(prims);
     104            List<Command> cmds = CombinePrimitiveResolverDialog.launchIfNecessary(
     105                    tagColl, prims, Collections.singleton(platformNode));
     106            Main.main.undoRedo.add(new SequenceCommand("merging", cmds));
     107        } catch (UserCancelException ex) {
     108            Main.trace(ex);
     109        } finally {
     110            Main.main.undoRedo.add(new DeleteCommand(dummy1));
     111            Main.main.undoRedo.add(new DeleteCommand(dummy2));
     112            Main.main.undoRedo.add(new DeleteCommand(dummy3));
    65113        }
    66114    }
     115
     116    public void populateMap(OsmPrimitive prim) {
     117        List<String> unInterestingTags = new ArrayList<>();
     118        unInterestingTags.add("public_transport");
     119        unInterestingTags.add("highway");
     120        unInterestingTags.add("source");
     121
     122        for (Entry<String, String> tag: prim.getKeys().entrySet()) {
     123            if (unInterestingTags.contains(tag.getKey())) {
     124                continue;
     125            }
     126            if (dummy1.get(tag.getKey()) == null) {
     127                dummy1.put(tag.getKey(), tag.getValue());
     128            } else if (dummy2.get(tag.getKey()) == null) {
     129                dummy2.put(tag.getKey(), tag.getValue());
     130            } else if (dummy3.get(tag.getKey()) == null) {
     131                dummy3.put(tag.getKey(), tag.getValue());
     132            }
     133        }
     134    }
     135
    67136    @Override
    68137    protected void updateEnabledState(
    69138            Collection<? extends OsmPrimitive> selection) {
    70139        setEnabled(false);
    71         if (selection == null || selection.size() != 1)
    72             return;
    73         OsmPrimitive selected = selection.iterator().next();
    74         if (selected.getType() == OsmPrimitiveType.RELATION &&
    75                 RouteUtils.isPTRoute((Relation) selected)) {
     140
     141        if (selection.size() > 1) {
    76142            setEnabled(true);
    77143        }
Note: See TracChangeset for help on using the changeset viewer.