Ignore:
Timestamp:
2013-04-13T14:19:56+02:00 (11 years ago)
Author:
akks
Message:

fix #8599: Remote control command add_way now creates closed ways correctly
Show old values and tooltips in add_tags dialog
All nodes added by add_node and add_way are merged with existing ones

Location:
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java

    r5844 r5845  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.Point;
    67import java.util.HashMap;
    78import org.openstreetmap.josm.Main;
     
    1011import org.openstreetmap.josm.data.coor.LatLon;
    1112import org.openstreetmap.josm.data.osm.Node;
     13import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1214import org.openstreetmap.josm.gui.util.GuiHelper;
    1315import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault;
     
    6466        // Create a new node
    6567        LatLon ll = new LatLon(lat, lon);
    66         Node nnew = new Node(ll);
    6768
    68         // Now execute the commands to add this node.
    69         Main.main.undoRedo.add(new AddCommand(nnew));
    70         Main.main.getCurrentDataSet().setSelected(nnew);
     69        Node nd = null;
     70       
     71        if (Main.map != null &&  Main.map.mapView != null) {
     72            Point p = Main.map.mapView.getPoint(ll);
     73            nd = Main.map.mapView.getNearestNode(p, OsmPrimitive.isUsablePredicate);
     74            if (nd!=null && nd.getCoor().greatCircleDistance(ll) > Main.pref.getDouble("remotecontrol.tolerance", 0.1)) {
     75                nd = null; // node is too far
     76            }
     77        }
     78
     79        if (nd==null) {
     80            nd = new Node(ll);
     81            // Now execute the commands to add this node.
     82            Main.main.undoRedo.add(new AddCommand(nd));
     83        }
     84       
     85        Main.main.getCurrentDataSet().setSelected(nd);
    7186        if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) {
    7287            AutoScaleAction.autoScale("selection");
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java

    r5844 r5845  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
     5import java.awt.Point;
    56import java.util.ArrayList;
    67import java.util.Arrays;
     8import java.util.HashMap;
    79import java.util.LinkedList;
    810import java.util.List;
     
    1517import org.openstreetmap.josm.data.coor.LatLon;
    1618import org.openstreetmap.josm.data.osm.Node;
     19import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1720import org.openstreetmap.josm.data.osm.Way;
    1821import org.openstreetmap.josm.gui.util.GuiHelper;
     
    3134   
    3235    private final List<LatLon> allCoordinates = new ArrayList<LatLon>();
     36
     37    /**
     38     * The place to remeber already added nodes (they are reused if needed @since 5845
     39     */
     40    HashMap<LatLon, Node> addedNodes;
    3341
    3442    @Override
     
    8492        }
    8593    }
     94   
     95    /**
     96     * Find the node with almost the same ccords in dataset or in already added nodes
     97     * @since 5845
     98     **/
     99    Node findOrCreateNode(LatLon ll,  List<Command> commands) {
     100        Node nd = null;     
     101         
     102        if (Main.map != null && Main.map.mapView != null) {
     103            Point p = Main.map.mapView.getPoint(ll);
     104            nd = Main.map.mapView.getNearestNode(p, OsmPrimitive.isUsablePredicate);
     105            if (nd!=null && nd.getCoor().greatCircleDistance(ll) > Main.pref.getDouble("remote.tolerance", 0.1)) {
     106                nd = null; // node is too far
     107            }
     108        }
     109       
     110        Node prev = null;
     111        for (LatLon lOld: addedNodes.keySet()) {
     112            if (lOld.greatCircleDistance(ll) < Main.pref.getDouble("remotecontrol.tolerance", 0.1)) {
     113                prev = addedNodes.get(lOld);
     114                break;
     115            }
     116        }
    86117
     118        if (prev!=null) {
     119            nd = prev;
     120        } else if (nd==null) {
     121            nd = new Node(ll);
     122            // Now execute the commands to add this node.
     123            commands.add(new AddCommand(nd));
     124            addedNodes.put(ll, nd);
     125        }
     126        return nd;
     127    }
     128   
    87129    /*
    88130     * This function creates the way with given coordinates of nodes
    89131     */
    90132    private void addWay() {
     133        addedNodes = new HashMap<LatLon, Node>();
    91134        Way way = new Way();
    92135        List<Command> commands = new LinkedList<Command>();
    93136        for (LatLon ll : allCoordinates) {
    94             Node node = new Node(ll);
     137            Node node = findOrCreateNode(ll, commands);
    95138            way.addNode(node);
    96             commands.add(new AddCommand(node));
    97139        }
    98140        allCoordinates.clear();
Note: See TracChangeset for help on using the changeset viewer.