Changeset 25136 in osm for applications/editors/josm/plugins/cadastre-fr/src
- Timestamp:
- 2011-01-25T00:34:15+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/Address.java
r22504 r25136 132 132 setNewSelection(currentMouseNode); 133 133 String num = currentMouseNode.get(tagHouseNumber); 134 if (num != null) { 135 try { 136 // add new address 137 Integer.parseInt(num); 138 inputNumber.setText(num); 139 applyInputNumberChange(); 140 } catch (NumberFormatException en) { 141 System.out.println("Unable to parse house number \"" + num + "\""); 134 if (num != null // 135 && currentMouseNode.get(tagHouseStreet) == null // 136 && findWayInRelationAddr(currentMouseNode) == null // 137 && !inputStreet.getText().equals("")) { 138 // address already present but not linked to a street 139 Collection<Command> cmds = new LinkedList<Command>(); 140 addStreetNameOrRelation(currentMouseNode, cmds); 141 Command c = new SequenceCommand("Add node address", cmds); 142 Main.main.undoRedo.add(c); 143 setNewSelection(currentMouseNode); 144 } else { 145 if (num != null) { 146 try { 147 // add new address 148 Integer.parseInt(num); 149 inputNumber.setText(num); 150 applyInputNumberChange(); 151 } catch (NumberFormatException en) { 152 System.out.println("Unable to parse house number \"" + num + "\""); 153 } 142 154 } 143 } 144 if (currentMouseNode.get(tagHouseStreet) != null) { 145 inputStreet.setText(currentMouseNode.get(tagHouseStreet)); 146 if (ctrl) { 147 Collection<Command> cmds = new LinkedList<Command>(); 148 addAddrToPrimitive(currentMouseNode, cmds); 149 if (num == null) 150 applyInputNumberChange(); 151 } 152 setSelectedWay((Way)null); 153 } else { 154 // check if the node belongs to an associatedStreet relation 155 Way wayInRelationAddr = findWayInRelationAddr(currentMouseNode); 156 if (wayInRelationAddr == null) { 157 // node exists but doesn't carry address information : add tags like a new node 155 if (currentMouseNode.get(tagHouseStreet) != null) { 156 inputStreet.setText(currentMouseNode.get(tagHouseStreet)); 158 157 if (ctrl) { 159 applyInputNumberChange(); 158 Collection<Command> cmds = new LinkedList<Command>(); 159 addAddrToPrimitive(currentMouseNode, cmds); 160 if (num == null) 161 applyInputNumberChange(); 160 162 } 161 Collection<Command> cmds = new LinkedList<Command>(); 162 addAddrToPrimitive(currentMouseNode, cmds); 163 setSelectedWay((Way)null); 163 164 } else { 164 inputStreet.setText(wayInRelationAddr.get(tagHighwayName)); 165 setSelectedWay(wayInRelationAddr); 165 // check if the node belongs to an associatedStreet relation 166 Way wayInRelationAddr = findWayInRelationAddr(currentMouseNode); 167 if (wayInRelationAddr == null) { 168 // node exists but doesn't carry address information : add tags like a new node 169 if (ctrl) { 170 applyInputNumberChange(); 171 } 172 Collection<Command> cmds = new LinkedList<Command>(); 173 addAddrToPrimitive(currentMouseNode, cmds); 174 } else { 175 inputStreet.setText(wayInRelationAddr.get(tagHighwayName)); 176 setSelectedWay(wayInRelationAddr); 177 } 166 178 } 167 179 } … … 234 246 235 247 } 236 cmds.add(new ChangePropertyCommand(osm, tagHouseNumber, inputNumber.getText())); 248 cmds.add(new ChangePropertyCommand(osm, tagHouseNumber, inputNumber.getText())); 249 addStreetNameOrRelation(osm, cmds); 250 try { 251 applyInputNumberChange(); 252 Command c = new SequenceCommand("Add node address", cmds); 253 Main.main.undoRedo.add(c); 254 setNewSelection(osm); 255 } catch (NumberFormatException en) { 256 System.out.println("Unable to parse house number \"" + inputNumber.getText() + "\""); 257 } 258 } 259 260 private Relation findRelationAddr(Way w) { 261 List<OsmPrimitive> l = w.getReferrers(); 262 for (OsmPrimitive osm : l) { 263 if (osm instanceof Relation && osm.hasKey("type") && osm.get("type").equals(relationAddrType)) { 264 return (Relation)osm; 265 } 266 } 267 return null; 268 } 269 270 private void addStreetNameOrRelation(OsmPrimitive osm, Collection<Command> cmds) { 237 271 if (Main.pref.getBoolean("cadastrewms.addr.dontUseRelation", false)) { 238 272 cmds.add(new ChangePropertyCommand(osm, tagHouseStreet, inputStreet.getText())); … … 255 289 } 256 290 } 257 try { 258 applyInputNumberChange(); 259 Command c = new SequenceCommand("Add node address", cmds); 260 Main.main.undoRedo.add(c); 261 setNewSelection(osm); 262 } catch (NumberFormatException en) { 263 System.out.println("Unable to parse house number \"" + inputNumber.getText() + "\""); 264 } 265 } 266 267 private Relation findRelationAddr(Way w) { 268 List<OsmPrimitive> l = w.getReferrers(); 269 for (OsmPrimitive osm : l) { 270 if (osm instanceof Relation && osm.hasKey("type") && osm.get("type").equals(relationAddrType)) { 271 return (Relation)osm; 272 } 273 } 274 return null; 275 } 276 291 } 292 277 293 private Node createNewNode(MouseEvent e, Collection<Command> cmds) { 278 294 // DrawAction.mouseReleased() but without key modifiers
Note:
See TracChangeset
for help on using the changeset viewer.