Changeset 19857 in osm for applications/editors/josm
- Timestamp:
- 2010-02-04T15:44:49+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/tracer/src/tracer/TracerAction.java
r19856 r19857 39 39 import org.xml.sax.SAXException; 40 40 import org.openstreetmap.josm.data.osm.BBox; 41 import org.openstreetmap.josm.data.osm.OsmPrimitive; 41 42 42 43 /** … … 153 154 } 154 155 156 private boolean isBuilding(Way w){ 157 return (w.getKeys().get("building") == null ? false : w.getKeys().get("building").equals("yes")); 158 } 159 160 private boolean isInBuilding(Node n){ 161 for(OsmPrimitive op :n.getReferrers()) 162 if(op instanceof Way) 163 if(isBuilding((Way) op)) 164 return true; 165 return false; 166 } 167 168 155 169 private Command connectObjects(Way way){ 156 170 List<Command> cmds = new LinkedList<Command>(); 157 171 Way newWay = new Way(way); 158 for (int i = 0; i < newWay.getNodesCount(); i++) {159 Node n = newWay.getNode(i);172 for (int i = 1; i < way.getNodesCount(); i++) { 173 Node n = way.getNode(i); 160 174 if (cancel) { 161 175 return null; 162 176 } 163 177 164 try {165 178 LatLon ll = n.getCoor(); 166 179 167 double minDistanceSq = 0.00001 ;180 double minDistanceSq = 0.000015; 168 181 List<Node> nodes = Main.main.getCurrentDataSet().searchNodes(new BBox( 169 182 ll.getX() - minDistanceSq, … … 174 187 Node nearestNode = null; 175 188 for (Node nn : nodes) { 176 if (!nn.isUsable() || way.containsNode(nn) || newWay.containsNode(nn) ) {189 if (!nn.isUsable() || way.containsNode(nn) || newWay.containsNode(nn) || !isInBuilding(nn)) { 177 190 continue; 178 191 } … … 184 197 } 185 198 199 //System.out.println("Nearest: " + nearestNode); 200 //System.out.println("-------"); 186 201 if (nearestNode == null) { 187 202 // hledani blizke usecky, kam bod pridat ... nebo vytvorit samostatny bod? … … 198 213 199 214 for (Way ww : ways) { 200 if (!ww.isUsable() || ww == way || ww == newWay ) {215 if (!ww.isUsable() || ww == way || ww == newWay || !isBuilding(ww)) { 201 216 continue; 202 217 } … … 214 229 } 215 230 216 if (minDist < 0.00001) { 231 //System.out.println("Nearest way:" + nearestWay); 232 if (minDist < 0.000015) { 217 233 Way newNWay = new Way(nearestWay); 218 234 newNWay.addNode(nearestNodeIndex + 1, n); 235 //System.out.println("New way:" + newNWay); 219 236 cmds.add(new ChangeCommand(nearestWay, newNWay)); 220 237 } 221 238 } else { 239 nearestNode.setCoor(ll.getCenter(nearestNode.getCoor())); 222 240 int j = newWay.getNodes().indexOf(n); 223 241 newWay.addNode(j, nearestNode); … … 225 243 newWay.removeNode(n); 226 244 cmds.add(new DeleteCommand(n)); 227 i--;228 245 } 229 230 } catch (Exception ex) { 231 ex.printStackTrace(); 232 } 233 } 234 /**/ 235 // projdi kazdou novou usecku a zjisti, zda by nemela vest pres existujici body 246 } 247 // projdi kazdou novou usecku a zjisti, zda by nemela vest pres existujici body 236 248 int i = 0; 237 249 while (i < newWay.getNodesCount()) { … … 245 257 LatLon n1 = newWay.getNodes().get(i).getCoor(); 246 258 LatLon n2 = newWay.getNodes().get((i + 1) % newWay.getNodesCount()).getCoor(); 247 248 double minDistanceSq = 0.00001; 249 double maxAngle = 10; 259 //System.out.println(newWay.getNodes().get(i) + "-----" + newWay.getNodes().get((i + 1) % newWay.getNodesCount())); 260 261 double minDistanceSq = 0.000015; 262 double maxAngle = 15; 250 263 List<Node> nodes = Main.main.getCurrentDataSet().searchNodes(new BBox( 251 264 Math.min(n1.getX(), n2.getX()) - minDistanceSq, … … 256 269 Node nearestNode = null; 257 270 for (Node nod : nodes) { 258 if (!nod.isUsable() || way.containsNode(nod) || newWay.containsNode(nod) ) {271 if (!nod.isUsable() || way.containsNode(nod) || newWay.containsNode(nod) || !isInBuilding(nod)) { 259 272 continue; 260 273 } … … 277 290 } 278 291 279 System.out.println("Nearest_: " + nearestNode);280 System.out.println("");292 //System.out.println("Nearest_: " + nearestNode); 293 //System.out.println(""); 281 294 if (nearestNode == null) { 282 295 // tato usecka se nerozdeli … … 291 304 } 292 305 293 cmds.add(new ChangeCommand(way, newWay));306 cmds.add(new ChangeCommand(way, newWay)); 294 307 295 308 Command cmd = new SequenceCommand(tr("Merge objects nodes"), cmds); … … 338 351 commands.add(new AddCommand(way)); 339 352 if(!ctrl) commands.add(connectObjects(way)); 340 353 341 354 if (!commands.isEmpty()) { 342 355 Main.main.undoRedo.add(new SequenceCommand(tr("Tracer building"), commands)); 343 356 344 357 if(shift) Main.main.getCurrentDataSet().addSelected(way); 345 358 else Main.main.getCurrentDataSet().setSelected(way);
Note:
See TracChangeset
for help on using the changeset viewer.