Changeset 25893 in osm for applications/editors/josm
- Timestamp:
- 2011-04-25T16:27:45+02:00 (14 years ago)
- 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 17 17 private final JCheckBox cBigMode = new JCheckBox(tr("Big buildings mode")); 18 18 private final JCheckBox cSoftCur = new JCheckBox(tr("Rotate crosshair")); 19 private final JCheckBox cAddrNode = new JCheckBox(tr("Use address nodes under buildings")); 19 20 20 21 public AdvancedSettingsDialog() { … … 30 31 panel.add(cBigMode, GBC.eol().fill(GBC.HORIZONTAL)); 31 32 panel.add(cSoftCur, GBC.eol().fill(GBC.HORIZONTAL)); 33 panel.add(cAddrNode, GBC.eol().fill(GBC.HORIZONTAL)); 32 34 33 35 cBigMode.setSelected(ToolSettings.isBBMode()); 34 36 cSoftCur.setSelected(ToolSettings.isSoftCursor()); 37 cAddrNode.setSelected(ToolSettings.PROP_USE_ADDR_NODE.get()); 35 38 36 39 setupDialog(); … … 38 41 } 39 42 40 public boolean isBBMode() {41 return cBigMode.isSelected();42 }43 44 public boolean isSoftCursor() {45 return cSoftCur.isSelected();46 }47 48 43 public void saveSettings() { 49 44 tagsModel.applyToTags(ToolSettings.getTags()); 50 45 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()); 53 49 } 54 50 } -
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/Building.java
r25469 r25893 17 17 import org.openstreetmap.josm.Main; 18 18 import org.openstreetmap.josm.command.AddCommand; 19 import org.openstreetmap.josm.command.ChangeCommand; 19 20 import org.openstreetmap.josm.command.Command; 21 import org.openstreetmap.josm.command.DeleteCommand; 20 22 import org.openstreetmap.josm.command.SequenceCommand; 21 23 import org.openstreetmap.josm.data.coor.*; … … 24 26 import org.openstreetmap.josm.data.osm.Node; 25 27 import org.openstreetmap.josm.data.osm.OsmPrimitive; 28 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 29 import org.openstreetmap.josm.data.osm.Relation; 30 import org.openstreetmap.josm.data.osm.RelationMember; 26 31 import org.openstreetmap.josm.data.osm.Way; 27 32 import org.openstreetmap.josm.gui.MapView; … … 214 219 } 215 220 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 216 253 public Way create() { 217 254 if (len == 0) … … 247 284 } 248 285 w.addNode(nodes[0]); 249 w.setKeys(ToolSettings.getTags());250 286 Collection<Command> cmds = new LinkedList<Command>(); 251 287 for (int i = 0; i < 4; i++) { … … 254 290 } 255 291 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 } 256 311 Command c = new SequenceCommand(tr("Create building"), cmds); 257 312 Main.main.undoRedo.add(c); -
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/ToolSettings.java
r23330 r25893 11 11 12 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.data.preferences.BooleanProperty; 13 14 14 15 public class ToolSettings { 16 public static BooleanProperty PROP_USE_ADDR_NODE = new BooleanProperty("buildings_tools.addrNode", true); 15 17 private static double width = 0; 16 18 private static double lenstep = 0;
Note:
See TracChangeset
for help on using the changeset viewer.