Changeset 5401 in josm


Ignore:
Timestamp:
Aug 6, 2012 8:15:36 PM (10 months ago)
Author:
Don-vip
Message:

fix #7918 - Trying to split a way at the end node should not throw an error

File:
1 edited

Legend:

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

    r5266 r5401  
    4444public class SplitWayAction extends JosmAction { 
    4545 
    46  
     46    /** 
     47     * Represents the result of a {@link SplitWayAction} 
     48     * @see SplitWayAction#splitWay 
     49     * @see SplitWayAction#split 
     50     */ 
    4751    public static class SplitWayResult { 
    4852        private final Command command; 
     
    5155        private List<Way> newWays; 
    5256 
     57        /** 
     58         * @param command The command to be performed to split the way (which is saved for later retrieval by the {@link #getCommand} method) 
     59         * @param newSelection The new list of selected primitives ids (which is saved for later retrieval by the {@link #getNewSelection} method) 
     60         * @param originalWay The original way being split (which is saved for later retrieval by the {@link #getOriginalWay} method) 
     61         * @param newWays The resulting new ways (which is saved for later retrieval by the {@link #getOriginalWay} method) 
     62         */ 
    5363        public SplitWayResult(Command command, List<? extends PrimitiveId> newSelection, Way originalWay, List<Way> newWays) { 
    5464            this.command = command; 
     
    5868        } 
    5969 
     70        /** 
     71         * Replies the command to be performed to split the way 
     72         * @return The command to be performed to split the way 
     73         */ 
    6074        public Command getCommand() { 
    6175            return command; 
    6276        } 
    6377 
     78        /** 
     79         * Replies the new list of selected primitives ids 
     80         * @return The new list of selected primitives ids 
     81         */ 
    6482        public List<? extends PrimitiveId> getNewSelection() { 
    6583            return newSelection; 
    6684        } 
    6785 
     86        /** 
     87         * Replies the original way being split 
     88         * @return The original way being split 
     89         */ 
    6890        public Way getOriginalWay() { 
    6991            return originalWay; 
    7092        } 
    7193 
     94        /** 
     95         * Replies the resulting new ways 
     96         * @return The resulting new ways 
     97         */ 
    7298        public List<Way> getNewWays() { 
    7399            return newWays; 
     
    114140        } 
    115141 
    116         { // Remove ways that doesn't have selected node in the middle 
    117             Iterator<Way> it = applicableWays.iterator(); 
     142        // If several ways have been found, remove ways that doesn't have selected node in the middle 
     143        if (applicableWays.size() > 1) { 
    118144            WAY_LOOP: 
    119                 while (it.hasNext()) { 
     145                for (Iterator<Way> it = applicableWays.iterator(); it.hasNext();) { 
    120146                    Way w = it.next(); 
    121147                    for (Node n : selectedNodes) { 
    122                         if(!w.isInnerNode(n)) { 
     148                        if (!w.isInnerNode(n)) { 
    123149                            it.remove(); 
    124150                            continue WAY_LOOP; 
     
    167193        List<Way> result = new ArrayList<Way>(OsmPrimitive.getFilteredList(selectedNodes.get(0).getReferrers(), Way.class)); 
    168194        for (int i=1; i<selectedNodes.size(); i++) { 
    169             Iterator<Way> it = result.iterator(); 
    170195            List<OsmPrimitive> ref = selectedNodes.get(i).getReferrers(); 
    171             while (it.hasNext()) { 
     196            for (Iterator<Way> it = result.iterator(); it.hasNext(); ) { 
    172197                if (!ref.contains(it.next())) { 
    173198                    it.remove(); 
     
    176201        } 
    177202 
    178         { // Remove broken ways 
    179             Iterator<Way> it = result.iterator(); 
    180             while (it.hasNext()) { 
    181                 if (it.next().getNodesCount() <= 2) { 
    182                     it.remove(); 
    183                 } 
     203        // Remove broken ways 
     204        for (Iterator<Way> it = result.iterator(); it.hasNext(); ) { 
     205            if (it.next().getNodesCount() <= 2) { 
     206                it.remove(); 
    184207            } 
    185208        } 
     
    189212        else { 
    190213            // Return only selected ways 
    191             Iterator<Way> it = result.iterator(); 
    192             while (it.hasNext()) { 
     214            for (Iterator<Way> it = result.iterator(); it.hasNext(); ) { 
    193215                if (!selectedWays.contains(it.next())) { 
    194216                    it.remove(); 
     
    197219            return result; 
    198220        } 
    199  
    200221    } 
    201222 
     
    277298 
    278299    /** 
    279      * Splits a way 
    280      * @param layer 
    281      * @param way 
    282      * @param wayChunks 
    283      * @return 
     300     * Splits the way {@code way} into chunks of {@code wayChunks} and replies 
     301     * the result of this process in an instance of {@link SplitWayResult}. 
     302     * 
     303     * Note that changes are not applied to the data yet. You have to 
     304     * submit the command in {@link SplitWayResult#getCommand()} first, 
     305     * i.e. {@code Main.main.undoredo.add(result.getCommand())}. 
     306     * 
     307     * @param layer the layer which the way belongs to. Must not be null. 
     308     * @param way the way to split. Must not be null. 
     309     * @param wayChunks the list of way chunks into the way is split. Must not be null. 
     310     * @param selection The list of currently selected primitives 
     311     * @return the result from the split operation 
    284312     */ 
    285313    public static SplitWayResult splitWay(OsmDataLayer layer, Way way, List<List<Node>> wayChunks, Collection<? extends OsmPrimitive> selection) { 
     
    479507     * @param way the way to split. Must not be null. 
    480508     * @param atNodes the list of nodes where the way is split. Must not be null. 
     509     * @param selection The list of currently selected primitives 
    481510     * @return the result from the split operation 
    482511     */ 
    483     static public SplitWayResult split(OsmDataLayer layer, Way way, List<Node> atNodes, Collection<? extends OsmPrimitive> selection){ 
     512    static public SplitWayResult split(OsmDataLayer layer, Way way, List<Node> atNodes, Collection<? extends OsmPrimitive> selection) { 
    484513        List<List<Node>> chunks = buildSplitChunks(way, atNodes); 
    485514        if (chunks == null) return null; 
Note: See TracChangeset for help on using the changeset viewer.