Ignore:
Timestamp:
2010-08-15T17:31:20+02:00 (9 years ago)
Author:
jttt
Message:

Fix #5333 "Merge selection" tool is broken

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java

    r3262 r3440  
    1212
    1313import org.openstreetmap.josm.data.osm.Node;
     14import org.openstreetmap.josm.data.osm.NodeData;
    1415import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1516import org.openstreetmap.josm.data.osm.PrimitiveData;
     
    2324    }
    2425
     26    @SuppressWarnings("null")
    2527    @Override public boolean executeCommand() {
    2628
     
    2830
    2931        for (PrimitiveData pd:data) {
    30             createdPrimitives.add(getLayer().data.getPrimitiveById(pd, true));
     32            OsmPrimitive primitive = getLayer().data.getPrimitiveById(pd);
     33            boolean created = primitive == null;
     34            if (created) {
     35                primitive = pd.getType().newInstance(pd.getUniqueId(), true);
     36            }
     37            if (pd instanceof NodeData) { // Load nodes immediately because they can't be added to dataset without coordinates
     38                primitive.load(pd);
     39            }
     40            if (created) {
     41                getLayer().data.addPrimitive(primitive);
     42            }
     43            createdPrimitives.add(primitive);
    3144        }
    3245
    33         // Load nodes first to prevent ways with null coordinates
    34         for (int i=0; i<createdPrimitives.size(); i++) {
    35             if (createdPrimitives.get(i) instanceof Node) {
    36                 createdPrimitives.get(i).load(data.get(i));
    37             }
    38         }
    39 
    40         // Now load ways and relations
     46        //Then load ways and relations
    4147        for (int i=0; i<createdPrimitives.size(); i++) {
    4248            if (!(createdPrimitives.get(i) instanceof Node)) {
     
    5763    @Override public JLabel getDescription() {
    5864        return new JLabel(trn("Added {0} object", "Added {0} objects", data.size(), data.size()), null,
    59                             JLabel.HORIZONTAL
     65                JLabel.HORIZONTAL
    6066        );
    6167    }
Note: See TracChangeset for help on using the changeset viewer.