Changeset 19855 in osm for applications/editors
- Timestamp:
- 2010-02-04T12:48:57+01:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/tracer/src/tracer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/tracer/src/tracer/TracerAction.java
r19830 r19855 11 11 import java.awt.Point; 12 12 import java.awt.event.ActionEvent; 13 import java.awt.event.InputEvent; 13 14 import java.awt.event.KeyEvent; 14 15 import java.awt.event.MouseEvent; … … 20 21 import java.io.InputStreamReader; 21 22 import java.net.URL; 22 import java.util.HashMap;23 23 import java.util.List; 24 import java.util.Map;25 24 import org.openstreetmap.josm.Main; 26 25 import org.openstreetmap.josm.actions.mapmode.MapMode; … … 28 27 import org.openstreetmap.josm.command.ChangeCommand; 29 28 import org.openstreetmap.josm.command.Command; 29 import org.openstreetmap.josm.command.DeleteCommand; 30 30 import org.openstreetmap.josm.command.SequenceCommand; 31 31 import org.openstreetmap.josm.data.coor.LatLon; … … 50 50 protected Thread executeThread; 51 51 protected boolean cancel; 52 protected Collection<Command> commands = new LinkedList<Command>(); 53 protected Collection<Way> ways = new ArrayList<Way>(); 54 52 private boolean ctrl; 53 private boolean alt; 54 private boolean shift; 55 55 56 public TracerAction(MapFrame mapFrame) { 56 57 super(tr("Tracer"), "tracer-sml", tr("Tracer."), Shortcut.registerShortcut("tools:tracer", tr("Tool: {0}", tr("Tracer")), KeyEvent.VK_T, Shortcut.GROUP_EDIT), mapFrame, getCursor()); … … 107 108 } 108 109 }; 109 Thread executeThread = new Thread(tracerTask); 110 executeThread.start(); 110 Thread executeTraceThread = new Thread(tracerTask); 111 executeTraceThread.start(); 111 112 } catch (Exception e) { 112 113 e.printStackTrace(); … … 152 153 } 153 154 154 private void processnodelist(LatLon pos, LatLon topLeft, LatLon botRight, ProgressMonitor progressMonitor) { 155 progressMonitor.beginTask(null, 3); 156 try { 157 ArrayList<double[]> nodelist = new ArrayList<double[]>(); 158 nodelist = getNodeList(pos); 159 160 if (nodelist.size() == 0) { 161 return; 162 } 163 164 /** 165 * Turn the arraylist into osm nodes 166 */ 167 Way way = new Way(); 168 Node n = null; 169 Node fn = null; 170 171 double eastOffset = 0; 172 double northOffset = 0; 173 174 175 int nodesinway = 0; 176 177 for (int i = 0; i < nodelist.size(); i++) { 155 private Command connectObjects(Way way){ 156 List<Command> cmds = new LinkedList<Command>(); 157 Way newWay = new Way(way); 158 for (int i = 0; i < newWay.getNodesCount(); i++) { 159 Node n = newWay.getNode(i); 178 160 if (cancel) { 179 return; 161 return null; 180 162 } 181 163 182 164 try { 183 LatLon ll = n ew LatLon(nodelist.get(i)[0] + northOffset, nodelist.get(i)[1] + eastOffset);165 LatLon ll = n.getCoor(); 184 166 185 167 double minDistanceSq = 0.00001; … … 192 174 Node nearestNode = null; 193 175 for (Node nn : nodes) { 194 if (!nn.isUsable()) { 176 if (!nn.isUsable() || way.containsNode(nn) || newWay.containsNode(nn)) { 195 177 continue; 196 178 } 197 LatLon ll2 = nn.getCoor(); 198 double dist = ll2.distance(ll); 179 double dist = nn.getCoor().distance(ll); 199 180 if (dist < minDistanceSq) { 200 181 minDistanceSq = dist; … … 217 198 218 199 for (Way ww : ways) { 200 if (!ww.isUsable() || ww == way || ww == newWay) { 201 continue; 202 } 219 203 for (int nindex = 0; nindex < ww.getNodesCount(); nindex++) { 220 204 Node n1 = ww.getNode(nindex); … … 231 215 232 216 if (minDist < 0.00001) { 233 n = new Node(ll); 234 commands.add(new AddCommand(n)); 235 Way newWay = new Way(nearestWay); 236 newWay.addNode(nearestNodeIndex + 1, n); 237 commands.add(new ChangeCommand(nearestWay, newWay)); 238 } else { 239 n = new Node(ll); 240 commands.add(new AddCommand(n)); 217 Way newNWay = new Way(nearestWay); 218 newNWay.addNode(nearestNodeIndex + 1, n); 219 cmds.add(new ChangeCommand(nearestWay, newNWay)); 241 220 } 242 221 } else { 243 n = nearestNode; 244 } 245 246 if (fn == null) { 247 fn = n; 222 int j = newWay.getNodes().indexOf(n); 223 newWay.addNode(j, nearestNode); 224 if(j == 0)newWay.addNode(newWay.getNodesCount(), nearestNode); 225 newWay.removeNode(n); 226 cmds.add(new DeleteCommand(n)); 227 i--; 248 228 } 249 229 … … 251 231 ex.printStackTrace(); 252 232 } 253 254 way.addNode(n); 255 nodesinway++; 256 } 257 /**/ 258 // projdi kazdou novou usecku a zjisti, zda by nemela vest pres existujici body 233 } 234 /**/ 235 // projdi kazdou novou usecku a zjisti, zda by nemela vest pres existujici body 259 236 int i = 0; 260 while (i < n odelist.size()) {237 while (i < newWay.getNodesCount()) { 261 238 if (cancel) { 262 return; 239 return null; 263 240 } 264 241 … … 266 243 267 244 // usecka n1, n2 268 double d[] = nodelist.get(i); 269 LatLon n1 = new LatLon(d[0], d[1]); 270 d = nodelist.get((i + 1) % nodelist.size()); 271 LatLon n2 = new LatLon(d[0], d[1]); 245 LatLon n1 = newWay.getNodes().get(i).getCoor(); 246 LatLon n2 = newWay.getNodes().get((i + 1) % newWay.getNodesCount()).getCoor(); 272 247 273 248 double minDistanceSq = 0.00001; … … 281 256 Node nearestNode = null; 282 257 for (Node nod : nodes) { 283 if (!nod.isUsable()) { 258 if (!nod.isUsable() || way.containsNode(nod) || newWay.containsNode(nod)) { 284 259 continue; 285 260 } … … 302 277 } 303 278 279 System.out.println("Nearest_: " + nearestNode); 280 System.out.println(""); 304 281 if (nearestNode == null) { 305 282 // tato usecka se nerozdeli … … 308 285 } else { 309 286 // rozdeleni usecky 310 nodelist.add(i+1, new double[] { nearestNode.getCoor().getY(), nearestNode.getCoor().getX() }); 311 way.addNode(i+1, nearestNode); 287 newWay.addNode(i+1, nearestNode); 312 288 continue; // i nezvetsuji, treba bude treba rozdelit usecku znovu 313 289 } 314 290 315 291 } 316 /**/ 292 293 cmds.add(new ChangeCommand(way, newWay)); 294 295 Command cmd = new SequenceCommand(tr("Merge objects nodes"), cmds); 296 return cmd; 297 } 298 299 private void processnodelist(LatLon pos, LatLon topLeft, LatLon botRight, ProgressMonitor progressMonitor) { 300 Collection<Command> commands = new LinkedList<Command>(); 301 302 progressMonitor.beginTask(null, 3); 303 try { 304 ArrayList<double[]> nodelist = new ArrayList<double[]>(); 305 nodelist = getNodeList(pos); 306 307 if (nodelist.size() == 0) { 308 return; 309 } 310 311 /** 312 * Turn the arraylist into osm nodes 313 */ 314 Way way = new Way(); 315 Node n = null; 316 Node fn = null; 317 318 double eastOffset = 0; 319 double northOffset = 0; 320 321 for (double[] node : nodelist) { 322 if (cancel) { 323 return; 324 } 325 LatLon ll = new LatLon(node[0] + northOffset, node[1] + eastOffset); 326 327 n = new Node(ll); 328 if(fn == null) fn = n; 329 commands.add(new AddCommand(n)); 330 way.addNode(n); 331 } 332 317 333 way.put("building", "yes"); 318 334 way.put("source", "cuzk:km"); … … 321 337 322 338 commands.add(new AddCommand(way)); 339 if(!ctrl) commands.add(connectObjects(way)); 323 340 324 341 if (!commands.isEmpty()) { 325 342 Main.main.undoRedo.add(new SequenceCommand(tr("Tracer building"), commands)); 326 Main.main.getCurrentDataSet().setSelected(way s);343 Main.main.getCurrentDataSet().setSelected(way); 327 344 } else { 328 345 System.out.println("Failed"); 329 346 } 330 347 331 commands = new LinkedList<Command>();332 ways = new ArrayList<Way>();333 348 } finally { 334 349 progressMonitor.finishTask(); … … 368 383 } 369 384 385 @Override 370 386 public void mouseClicked(MouseEvent e) { 371 387 } 372 388 389 @Override 373 390 public void mouseEntered(MouseEvent e) { 374 391 } 375 392 393 @Override 376 394 public void mouseExited(MouseEvent e) { 377 395 } 378 396 397 @Override 379 398 public void mousePressed(MouseEvent e) { 380 399 if(!Main.map.mapView.isActiveLayerDrawable()) 381 400 return; 382 401 402 updateKeyModifiers(e); 383 403 if (e.getButton() == MouseEvent.BUTTON1) { 384 404 trace(e.getPoint()); 385 405 } 386 406 } 387 407 408 private void updateKeyModifiers(MouseEvent e) { 409 ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 410 alt = (e.getModifiers() & (ActionEvent.ALT_MASK|InputEvent.ALT_GRAPH_MASK)) != 0; 411 shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 412 } 413 414 415 @Override 388 416 public void mouseReleased(MouseEvent e) { 389 417 } -
applications/editors/josm/plugins/tracer/src/tracer/TracerPlugin.java
r19830 r19855 7 7 package tracer; 8 8 9 import static org.openstreetmap.josm.tools.I18n.tr;10 11 9 import org.openstreetmap.josm.Main; 12 10 import org.openstreetmap.josm.gui.MainMenu; 13 import org.openstreetmap.josm.gui.preferences.PreferenceSetting;14 11 import org.openstreetmap.josm.plugins.Plugin; 15 12 import org.openstreetmap.josm.plugins.PluginInformation; … … 17 14 public class TracerPlugin extends Plugin { 18 15 19 public TracerPlugin() { 20 MainMenu.add(Main.main.menu.toolsMenu, new TracerAction(Main.main.map)); 16 public TracerPlugin(PluginInformation info) { 17 super(info); 18 MainMenu.add(Main.main.menu.toolsMenu, new TracerAction(Main.map)); 21 19 } 22 20 }
Note:
See TracChangeset
for help on using the changeset viewer.