Changeset 5953 in josm for trunk/src/org


Ignore:
Timestamp:
2013-05-10T17:13:24+02:00 (11 years ago)
Author:
Don-vip
Message:

fix #8690 - After copying some primitives, only select those that have been directly selected (and not all that have been created) -> Copying a way only selects the new way

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/CopyAction.java

    r4982 r5953  
    1818import org.openstreetmap.josm.tools.Utils;
    1919
     20/**
     21 * Copy OSM primitives to clipboard in order to paste them, or their tags, somewhere else. 
     22 * @since 404
     23 */
    2024public final class CopyAction extends JosmAction {
    2125
     26    /**
     27     * Constructs a new {@code CopyAction}.
     28     */
    2229    public CopyAction() {
    2330        super(tr("Copy"), "copy",
     
    3542    }
    3643
     44    /**
     45     * Copies the given primitive ids to the clipboard.
     46     * @param source The OSM data layer source
     47     * @param primitives The OSM primitives to copy
     48     */
    3749    public static void copy(OsmDataLayer source, Collection<OsmPrimitive> primitives) {
    3850        /* copy ids to the clipboard */
  • trunk/src/org/openstreetmap/josm/actions/PasteAction.java

    r5096 r5953  
    3030import org.openstreetmap.josm.tools.Shortcut;
    3131
     32/**
     33 * Paste OSM primitives from clipboard to the current edit layer.
     34 * @since 404
     35 */
    3236public final class PasteAction extends JosmAction implements PasteBufferChangedListener {
    3337
     38    /**
     39     * Constructs a new {@code PasteAction}.
     40     */
    3441    public PasteAction() {
    3542        super(tr("Paste"), "paste", tr("Paste contents of paste buffer."),
     
    4552    }
    4653
    47     public  void pasteData(PrimitiveDeepCopy pasteBuffer, Layer source, ActionEvent e) {
     54    /**
     55     * Paste OSM primitives from the given paste buffer and OSM data layer source to the current edit layer.
     56     * @param pasteBuffer The paste buffer containing primitive ids to copy
     57     * @param source The OSM data layer used to look for primitive ids
     58     * @param e The ActionEvent that triggered this operation
     59     */
     60    public void pasteData(PrimitiveDeepCopy pasteBuffer, Layer source, ActionEvent e) {
    4861        /* Find the middle of the pasteBuffer area */
    4962        double maxEast = -1E100, minEast = 1E100, maxNorth = -1E100, minNorth = 1E100;
     
    87100        // Make a copy of pasteBuffer and map from old id to copied data id
    88101        List<PrimitiveData> bufferCopy = new ArrayList<PrimitiveData>();
     102        List<PrimitiveData> toSelect = new ArrayList<PrimitiveData>();
    89103        Map<Long, Long> newNodeIds = new HashMap<Long, Long>();
    90104        Map<Long, Long> newWayIds = new HashMap<Long, Long>();
     
    104118            }
    105119            bufferCopy.add(copy);
     120            if (pasteBuffer.getDirectlyAdded().contains(data)) {
     121                toSelect.add(copy);
     122            }
    106123        }
    107124
     
    148165        /* Now execute the commands to add the duplicated contents of the paste buffer to the map */
    149166
    150         Main.main.undoRedo.add(new AddPrimitivesCommand(bufferCopy));
     167        Main.main.undoRedo.add(new AddPrimitivesCommand(bufferCopy, toSelect));
    151168        Main.map.mapView.repaint();
    152169    }
  • trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java

    r5926 r5953  
    1616import org.openstreetmap.josm.data.osm.PrimitiveData;
    1717import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     18import org.openstreetmap.josm.tools.CheckParameterUtil;
    1819
    1920/**
    2021 * Add primitives to a data layer.
    21  *
     22 * @since 2305
    2223 */
    2324public class AddPrimitivesCommand extends Command {
    2425
    2526    private List<PrimitiveData> data = new ArrayList<PrimitiveData>();
     27    private Collection<PrimitiveData> toSelect = new ArrayList<PrimitiveData>();
    2628
    2729    // only filled on undo
    2830    private List<OsmPrimitive> createdPrimitives = null;
     31    private Collection<OsmPrimitive> createdPrimitivesToSelect = null;
    2932
     33    /**
     34     * Constructs a new {@code AddPrimitivesCommand} to add data to the current edit layer.
     35     * @param data The OSM primitives data to add. Must not be {@code null}
     36     */
    3037    public AddPrimitivesCommand(List<PrimitiveData> data) {
    31         this.data.addAll(data);
     38        this(data, data);
     39    }
     40
     41    /**
     42     * Constructs a new {@code AddPrimitivesCommand} to add data to the current edit layer.
     43     * @param data The OSM primitives to add. Must not be {@code null}
     44     * @param toSelect The OSM primitives to select at the end. Can be {@code null}
     45     * @since 5953
     46     */
     47    public AddPrimitivesCommand(List<PrimitiveData> data, List<PrimitiveData> toSelect) {
     48        init(data, toSelect);
     49    }
     50
     51    /**
     52     * Constructs a new {@code AddPrimitivesCommand} to add data to the given layer.
     53     * @param data The OSM primitives data to add. Must not be {@code null}
     54     * @param toSelect The OSM primitives to select at the end. Can be {@code null}
     55     * @param layer The target data layer. Must not be {@code null}
     56     */
     57    public AddPrimitivesCommand(List<PrimitiveData> data, List<PrimitiveData> toSelect, OsmDataLayer layer) {
     58        super(layer);
     59        init(data, toSelect);
    3260    }
    3361   
    34     public AddPrimitivesCommand(List<PrimitiveData> data, OsmDataLayer layer) {
    35         super(layer);
     62    private final void init(List<PrimitiveData> data, List<PrimitiveData> toSelect) {
     63        CheckParameterUtil.ensureParameterNotNull(data, "data");
    3664        this.data.addAll(data);
     65        if (toSelect != null) {
     66            this.toSelect.addAll(toSelect);
     67        }
    3768    }
    3869
    39     @SuppressWarnings("null")
    4070    @Override public boolean executeCommand() {
    41         List<OsmPrimitive> newPrimitives;
     71        Collection<OsmPrimitive> primitivesToSelect;
    4272        if (createdPrimitives == null) { // first time execution
    43             newPrimitives = new ArrayList<OsmPrimitive>(data.size());
     73            List<OsmPrimitive> newPrimitives = new ArrayList<OsmPrimitive>(data.size());
     74            primitivesToSelect = new ArrayList<OsmPrimitive>(toSelect.size());
    4475
    4576            for (PrimitiveData pd : data) {
     
    5687                }
    5788                newPrimitives.add(primitive);
     89                if (toSelect.contains(pd)) {
     90                    primitivesToSelect.add(primitive);
     91                }
    5892            }
    5993
    60             //Then load ways and relations
     94            // Then load ways and relations
    6195            for (int i=0; i<newPrimitives.size(); i++) {
    6296                if (!(newPrimitives.get(i) instanceof Node)) {
     
    70104                getLayer().data.addPrimitive(osm);
    71105            }
    72             newPrimitives = createdPrimitives;
     106            primitivesToSelect = createdPrimitivesToSelect;
    73107        }
    74108
    75         getLayer().data.setSelected(newPrimitives);
     109        getLayer().data.setSelected(primitivesToSelect);
    76110        return true;
    77111    }
     
    82116        if (createdPrimitives == null) {
    83117            createdPrimitives = new ArrayList<OsmPrimitive>(data.size());
     118            createdPrimitivesToSelect = new ArrayList<OsmPrimitive>(toSelect.size());
    84119           
    85             for (PrimitiveData p : data) {
    86                 createdPrimitives.add(ds.getPrimitiveById(p));
     120            for (PrimitiveData pd : data) {
     121                OsmPrimitive p = ds.getPrimitiveById(pd);
     122                createdPrimitives.add(p);
     123                if (toSelect.contains(pd)) {
     124                    createdPrimitivesToSelect.add(p);
     125                }
    87126            }
    88127            createdPrimitives = PurgeCommand.topoSort(createdPrimitives);
     
    92131            }
    93132            data = null;
     133            toSelect = null;
    94134           
    95135        } else {
Note: See TracChangeset for help on using the changeset viewer.