Changeset 25893 in osm for applications/editors


Ignore:
Timestamp:
2011-04-25T16:27:45+02:00 (13 years ago)
Author:
upliner
Message:

Add ability to use address nodes (requested by Polyglot)

Location:
applications/editors/josm/plugins/buildings_tools/src/buildings_tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/buildings_tools/src/buildings_tools/AdvancedSettingsDialog.java

    r24243 r25893  
    1717    private final JCheckBox cBigMode = new JCheckBox(tr("Big buildings mode"));
    1818    private final JCheckBox cSoftCur = new JCheckBox(tr("Rotate crosshair"));
     19    private final JCheckBox cAddrNode = new JCheckBox(tr("Use address nodes under buildings"));
    1920
    2021    public AdvancedSettingsDialog() {
     
    3031        panel.add(cBigMode, GBC.eol().fill(GBC.HORIZONTAL));
    3132        panel.add(cSoftCur, GBC.eol().fill(GBC.HORIZONTAL));
     33        panel.add(cAddrNode, GBC.eol().fill(GBC.HORIZONTAL));
    3234
    3335        cBigMode.setSelected(ToolSettings.isBBMode());
    3436        cSoftCur.setSelected(ToolSettings.isSoftCursor());
     37        cAddrNode.setSelected(ToolSettings.PROP_USE_ADDR_NODE.get());
    3538
    3639        setupDialog();
     
    3841    }
    3942
    40     public boolean isBBMode() {
    41         return cBigMode.isSelected();
    42     }
    43 
    44     public boolean isSoftCursor() {
    45         return cSoftCur.isSelected();
    46     }
    47 
    4843    public void saveSettings() {
    4944        tagsModel.applyToTags(ToolSettings.getTags());
    5045        ToolSettings.saveTags();
    51         ToolSettings.setBBMode(isBBMode());
    52         ToolSettings.setSoftCursor(isSoftCursor());
     46        ToolSettings.setBBMode(cBigMode.isSelected());
     47        ToolSettings.setSoftCursor(cSoftCur.isSelected());
     48        ToolSettings.PROP_USE_ADDR_NODE.put(cAddrNode.isSelected());
    5349    }
    5450}
  • applications/editors/josm/plugins/buildings_tools/src/buildings_tools/Building.java

    r25469 r25893  
    1717import org.openstreetmap.josm.Main;
    1818import org.openstreetmap.josm.command.AddCommand;
     19import org.openstreetmap.josm.command.ChangeCommand;
    1920import org.openstreetmap.josm.command.Command;
     21import org.openstreetmap.josm.command.DeleteCommand;
    2022import org.openstreetmap.josm.command.SequenceCommand;
    2123import org.openstreetmap.josm.data.coor.*;
     
    2426import org.openstreetmap.josm.data.osm.Node;
    2527import org.openstreetmap.josm.data.osm.OsmPrimitive;
     28import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     29import org.openstreetmap.josm.data.osm.Relation;
     30import org.openstreetmap.josm.data.osm.RelationMember;
    2631import org.openstreetmap.josm.data.osm.Way;
    2732import org.openstreetmap.josm.gui.MapView;
     
    214219    }
    215220
     221    /**
     222     * Returns a node with "building=yes" tag under the building
     223     *
     224     * @return
     225     */
     226    private Node getAddressNode() {
     227        BBox bbox = new BBox(eastNorth2latlon(en[0]), eastNorth2latlon(en[1]));
     228        bbox.add(eastNorth2latlon(en[2]));
     229        bbox.add(eastNorth2latlon(en[3]));
     230        List<Node> nodes = new LinkedList<Node>();
     231        nodesloop:
     232        for (Node n : Main.main.getCurrentDataSet().searchNodes(bbox)) {
     233            if (!n.isUsable() || n.getKeys().get("building") == null)
     234                continue;
     235            double x = projection1(latlon2eastNorth(n.getCoor()));
     236            double y = projection2(latlon2eastNorth(n.getCoor()));
     237            if (Math.signum(x) != Math.signum(len) || Math.signum(y) != Math.signum(width))
     238                continue;
     239            if (Math.abs(x) > Math.abs(len) || Math.abs(y) > Math.abs(width))
     240                continue;
     241            for (OsmPrimitive p : n.getReferrers()) {
     242                // Don't use nodes if they're referenced by ways
     243                if (p.getType() == OsmPrimitiveType.WAY)
     244                    continue nodesloop;
     245            }
     246            nodes.add(n);
     247        }
     248        if (nodes.size() != 1)
     249            return null;
     250        return nodes.get(0);
     251    }
     252
    216253    public Way create() {
    217254        if (len == 0)
     
    247284        }
    248285        w.addNode(nodes[0]);
    249         w.setKeys(ToolSettings.getTags());
    250286        Collection<Command> cmds = new LinkedList<Command>();
    251287        for (int i = 0; i < 4; i++) {
     
    254290        }
    255291        cmds.add(new AddCommand(w));
     292        Node addrNode;
     293        if (ToolSettings.PROP_USE_ADDR_NODE.get() && (addrNode = getAddressNode()) != null) {
     294            w.setKeys(addrNode.getKeys());
     295            for (OsmPrimitive p : addrNode.getReferrers()) {
     296                Relation r = (Relation) p;
     297                Relation rnew = new Relation(r);
     298                for (int i = 0; i < r.getMembersCount(); i++) {
     299                    RelationMember member = r.getMember(i);
     300                    if (member.getMember() == addrNode) {
     301                        rnew.removeMember(i);
     302                        rnew.addMember(i, new RelationMember(member.getRole(), w));
     303                    }
     304                }
     305                cmds.add(new ChangeCommand(r, rnew));
     306            }
     307            cmds.add(new DeleteCommand(addrNode));
     308        } else {
     309            w.setKeys(ToolSettings.getTags());
     310        }
    256311        Command c = new SequenceCommand(tr("Create building"), cmds);
    257312        Main.main.undoRedo.add(c);
  • applications/editors/josm/plugins/buildings_tools/src/buildings_tools/ToolSettings.java

    r23330 r25893  
    1111
    1212import org.openstreetmap.josm.Main;
     13import org.openstreetmap.josm.data.preferences.BooleanProperty;
    1314
    1415public class ToolSettings {
     16    public static BooleanProperty PROP_USE_ADDR_NODE = new BooleanProperty("buildings_tools.addrNode", true);
    1517    private static double width = 0;
    1618    private static double lenstep = 0;
Note: See TracChangeset for help on using the changeset viewer.