Ignore:
Timestamp:
2012-08-15T15:03:00+02:00 (12 years ago)
Author:
larry0ua
Message:

'Utilsplugin2: SplitObjects now can use line as a splitter'

Location:
applications/editors/josm/plugins/utilsplugin2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/utilsplugin2/README

    r27618 r28551  
    88 * Add nodes on intersections action (by Upliner)
    99 
    10  * Split Object Action (anonymous)
     10 * Split Object Action (anonymous, Larry0ua updated)
    1111
    1212 * Selection actions (by akks)
  • applications/editors/josm/plugins/utilsplugin2/build.xml

    r28222 r28551  
    3030<project name="utilsplugin2" default="dist" basedir=".">
    3131    <!-- enter the SVN commit message -->
    32     <property name="commit.message" value="Utilsplugin2: all inside multipolygon selection - fixed"/>
     32    <property name="commit.message" value="Utilsplugin2: SplitObjects now can use line as a splitter"/>
    3333    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    3434    <property name="plugin.main.version" value="4980"/>
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SplitObjectAction.java

    r28028 r28551  
    2121import org.openstreetmap.josm.actions.JosmAction;
    2222import org.openstreetmap.josm.actions.SplitWayAction;
     23import org.openstreetmap.josm.command.DeleteCommand;
    2324import org.openstreetmap.josm.data.osm.Node;
    2425import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    3132 * The closed ways are just split at the selected nodes (which must be exactly two).
    3233 * The nodes remain in their original order.
    33  * 
     34 *
    3435 * This is similar to SplitWayAction with the addition that the split ways are closed
    3536 * immediately.
     
    5455     * of the split actions outlined above, and if yes, calls the splitObject method.
    5556     */
     57    @Override
    5658    public void actionPerformed(ActionEvent e) {
    5759        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
     
    7274
    7375        Way selectedWay = null;
    74         if (!selectedWays.isEmpty()){
    75             selectedWay = selectedWays.get(0);
     76        Way splitWay = null;
     77
     78        if (selectedNodes.isEmpty()) {              // if no nodes are selected - try to find split way
     79            for (Way selWay : selectedWays) {       // we assume not more 2 ways in the list
     80                if (selWay != null &&               // If one of selected ways is not closed we have it to get split points
     81                    selWay.isUsable() &&
     82                    !selWay.isClosed() &&
     83                    selWay.getKeys().isEmpty()) {
     84                        selectedNodes.add(selWay.firstNode());
     85                        selectedNodes.add(selWay.lastNode());
     86                        splitWay = selWay;
     87                } else {
     88                    selectedWay = selWay;           // use another way as selected way
     89                }
     90            }
    7691        }
    7792
     
    189204        if (wayChunks != null) {
    190205            // close the chunks
    191             for (List<Node> wayChunk : wayChunks) {
    192                 wayChunk.add(wayChunk.get(0));
     206            // update the logic - if we have splitWay not null, we have to add points from it to both chunks (in the correct direction)
     207            if (splitWay == null) {
     208                for (List<Node> wayChunk : wayChunks) {
     209                    wayChunk.add(wayChunk.get(0));
     210                }
     211            } else {
     212                for (List<Node> wayChunk : wayChunks) {
     213                    // check direction of the chunk and add splitWay nodes in the correct order
     214                    List<Node> way = splitWay.getNodes();
     215                    if (wayChunk.get(0).equals(splitWay.firstNode())) {
     216                        // add way to the end in the opposite direction.
     217                        way.remove(way.size()-1); // remove the last node
     218                        Collections.reverse(way);
     219                    } else {
     220                        // add way to the end in the given direction, remove the first node
     221                        way.remove(0);
     222                    }
     223                    wayChunk.addAll(way);
     224                }
    193225            }
    194226            SplitWayAction.SplitWayResult result = SplitWayAction.splitWay(getEditLayer(), selectedWay, wayChunks, Collections.<OsmPrimitive>emptyList());
    195227            //            SplitObjectResult result = splitObject(getEditLayer(),selectedWay, wayChunks);
    196228            Main.main.undoRedo.add(result.getCommand());
     229            if (splitWay != null)
     230                Main.main.undoRedo.add(new DeleteCommand(splitWay));
    197231            getCurrentDataSet().setSelected(result.getNewSelection());
    198232        }
     
    207241     */
    208242    private boolean checkSelection(Collection<? extends OsmPrimitive> selection) {
    209         boolean way = false;
    210243        int node = 0;
     244        int ways = 0;
    211245        for (OsmPrimitive p : selection) {
    212             if (p instanceof Way && !way) {
    213                 way = true;
     246            if (p instanceof Way) {
     247                ways++;
    214248            } else if (p instanceof Node) {
    215249                node++;
     
    217251                return false;
    218252        }
    219         return node == 2;
     253        return node == 2 || ways == 1 || ways == 2; //only 2 nodes selected. one split-way selected. split-way + way to split.
    220254    }
    221255
Note: See TracChangeset for help on using the changeset viewer.