Ignore:
Timestamp:
2010-01-30T19:04:31+01:00 (16 years ago)
Author:
bastik
Message:

'josm terracer plugin: fixed reverse terrace, minor updates'

Location:
applications/editors/josm/plugins/terracer/src/terracer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/terracer/src/terracer/ReverseTerraceAction.java

    r19658 r19678  
    66import java.awt.event.KeyEvent;
    77import java.util.Collection;
     8import java.util.Collections;
    89import java.util.HashSet;
    910import java.util.LinkedList;
     11
     12import javax.swing.JOptionPane;
    1013
    1114import org.openstreetmap.josm.Main;
     
    4952     */
    5053    public void actionPerformed(ActionEvent e) {
    51         Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
     54        Collection<Way> selectedWays = Main.main.getCurrentDataSet().getSelectedWays();
    5255
    53         // set to keep track of all the nodes that have been visited - that is: if
     56        // Set to keep track of all the nodes that have been visited - that is: if
    5457        // we encounter them again we will not follow onto the connected ways.
    5558        HashSet<Node> visitedNodes = new HashSet<Node>();
    5659
    57         // set to keep track of the ways the algorithm has seen, but not yet visited.
    58         // since when a way is visited all of its nodes are marked as visited, there
     60        // Set to keep track of the ways the algorithm has seen, but not yet visited.
     61        // Since when a way is visited all of its nodes are marked as visited, there
    5962        // is no need to keep a visitedWays set.
    6063        HashSet<Way> front = new HashSet<Way>();
    6164
    62         // initialise the set with all the buildings in the selection. this means
    63         // there is undefined behaviour when there is a multiple selection, as the
    64         // ordering will be based on the hash.
    65         for (OsmPrimitive prim : sel) {
    66             if (prim.keySet().contains("building") && prim instanceof Way) {
    67                 front.add((Way)prim);
     65        // Find the first or last way from the teracced houses.
     66        // It should be connected to exactly one other way.
     67        for (Way w : selectedWays) {
     68            int conn = 0;
     69            for (Way v : selectedWays) {
     70                if (w.equals(v)) continue;
     71                if (!Collections.disjoint(w.getNodes(), v.getNodes())) {
     72                    ++conn;
     73                }
     74            }
     75            if (conn == 1) {
     76                front.add(w);
     77                break;
    6878            }
    6979        }
     80       
     81        if (front.isEmpty()) {
     82            JOptionPane.showMessageDialog(Main.parent,
     83                    tr("Cannot reverse!"));
     84            return;
     85        }               
    7086
    71         // this is like a visitedWays set, but in a linear order.
     87        // This is like a visitedWays set, but in a linear order.
    7288        LinkedList<Way> orderedWays = new LinkedList<Way>();
    7389
    74         // and the tags to reverse on the orderedWays.
     90        // And the tags to reverse on the orderedWays.
    7591        LinkedList<String> houseNumbers = new LinkedList<String>();
    7692
     
    7995            Way w = front.iterator().next();
    8096
    81             // visit all the nodes in the way, adding the building's they're members of
     97            // Visit all the nodes in the way, adding the building's they're members of
    8298            // to the front.
    8399            for (Node n : w.getNodes()) {
     
    92108            }
    93109
    94             // we've finished visiting this way, so record the attributes we're interested
     110            // We've finished visiting this way, so record the attributes we're interested
    95111            // in for re-writing.
    96112            front.remove(w);
     
    100116
    101117        Collection<Command> commands = new LinkedList<Command>();
    102         // what, no zipWith?
    103118        for (int i = 0; i < orderedWays.size(); ++i) {
    104119            commands.add(new ChangePropertyCommand(
     
    112127    }
    113128
     129    @Override
     130    protected void updateEnabledState() {
     131        setEnabled(getCurrentDataSet() != null);
     132    }   
    114133}
  • applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java

    r19658 r19678  
    3434import org.openstreetmap.josm.data.osm.Relation;
    3535import org.openstreetmap.josm.data.osm.RelationMember;
     36import org.openstreetmap.josm.data.osm.TagCollection;
    3637import org.openstreetmap.josm.data.osm.Way;
    3738import org.openstreetmap.josm.tools.Pair;
     
    209210            terr.addNode(new_nodes[1][i]);
    210211            terr.addNode(new_nodes[0][i]);
     212           
     213            // add the tags of the outline to each building (e.g. source=*)
     214            TagCollection.from(outline).applyTo(terr);
     215           
    211216            if (from != null) {
    212217                // only, if the user has specified house numbers
     
    459464        return n;
    460465    }
     466
     467    @Override
     468    protected void updateEnabledState() {
     469        setEnabled(getCurrentDataSet() != null);
     470    }   
    461471}
Note: See TracChangeset for help on using the changeset viewer.