Changeset 27971 in osm
- Timestamp:
- 2012-03-02T06:02:28+01:00 (13 years ago)
- Location:
- applications/editors/josm/plugins
- Files:
-
- 3 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationCandidate.java
r27959 r27971 6 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 7 7 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 8 import static org.openstreetmap.josm.tools.I18n.tr; 8 9 9 10 /** … … 13 14 public class ConflationCandidate { 14 15 15 OsmPrimitive sourcePrimitive;16 OsmDataLayer sourceLayer;17 OsmPrimitive targetPrimitive;18 OsmDataLayer targetLayer;16 OsmPrimitive referenceObject; 17 OsmDataLayer referenceLayer; 18 OsmPrimitive subjectObject; 19 OsmDataLayer subjectLayer; 19 20 double cost; 20 21 double distance; 21 22 22 public ConflationCandidate(OsmPrimitive source, OsmDataLayer sourceLayer,23 OsmPrimitive target, OsmDataLayer targetLayer, double cost) {24 if ( source == null || target == null) {25 throw new IllegalArgumentException( "Invalid source or target");23 public ConflationCandidate(OsmPrimitive referenceObject, OsmDataLayer referenceLayer, 24 OsmPrimitive subjectObject, OsmDataLayer subjectLayer, double cost) { 25 if (referenceObject == null || subjectObject == null) { 26 throw new IllegalArgumentException(tr("Invalid reference or subject")); 26 27 } 27 this. sourcePrimitive = source;28 this. sourceLayer = sourceLayer;29 this. targetPrimitive = target;30 this. targetLayer = targetLayer;28 this.referenceObject = referenceObject; 29 this.referenceLayer = referenceLayer; 30 this.subjectObject = subjectObject; 31 this.subjectLayer = subjectLayer; 31 32 this.cost = cost; 32 33 // TODO: use distance calculated in cost function, and make sure it's in meters? 33 this.distance = ConflationUtils.getCenter( source).distance(ConflationUtils.getCenter(target));34 this.distance = ConflationUtils.getCenter(referenceObject).distance(ConflationUtils.getCenter(subjectObject)); 34 35 } 35 36 36 public OsmPrimitive get SourcePrimitive() {37 return sourcePrimitive;37 public OsmPrimitive getReferenceObject() { 38 return referenceObject; 38 39 } 39 40 40 public OsmDataLayer get SourceLayer() {41 return sourceLayer;41 public OsmDataLayer getReferenceLayer() { 42 return referenceLayer; 42 43 } 43 44 44 public OsmDataLayer get TargetLayer() {45 return targetLayer;45 public OsmDataLayer getSubjectLayer() { 46 return subjectLayer; 46 47 } 47 48 48 public OsmPrimitive get TargetPrimitive() {49 return targetPrimitive;49 public OsmPrimitive getSubjectObject() { 50 return subjectObject; 50 51 } 51 52 -
applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationCandidateList.java
r27959 r27971 5 5 package org.openstreetmap.josm.plugins.conflation; 6 6 7 import java.util.Collection;8 7 import java.util.Iterator; 9 8 import java.util.LinkedList; … … 25 24 26 25 public boolean hasCandidate(ConflationCandidate c) { 27 return hasCandidateFor Source(c.getSourcePrimitive());26 return hasCandidateForReference(c.getReferenceObject()); 28 27 } 29 28 30 public boolean hasCandidate(OsmPrimitive src, OsmPrimitive tgt) {31 return hasCandidateFor Source(src) || hasCandidateForTarget(tgt);29 public boolean hasCandidate(OsmPrimitive referenceObject, OsmPrimitive subjectObject) { 30 return hasCandidateForReference(referenceObject) || hasCandidateForSubject(subjectObject); 32 31 } 33 32 34 public boolean hasCandidateFor Source(OsmPrimitive src) {35 return getCandidateBy Source(src) != null;33 public boolean hasCandidateForReference(OsmPrimitive referenceObject) { 34 return getCandidateByReference(referenceObject) != null; 36 35 } 37 36 38 public boolean hasCandidateFor Target(OsmPrimitive tgt) {39 return getCandidateBy Target(tgt) != null;37 public boolean hasCandidateForSubject(OsmPrimitive subjectObject) { 38 return getCandidateBySubject(subjectObject) != null; 40 39 } 41 40 42 public ConflationCandidate getCandidateBy Source(OsmPrimitive src) {41 public ConflationCandidate getCandidateByReference(OsmPrimitive referenceObject) { 43 42 for (ConflationCandidate c : candidates) { 44 if (c.get SourcePrimitive() == src) {43 if (c.getReferenceObject() == referenceObject) { 45 44 return c; 46 45 } … … 49 48 } 50 49 51 public ConflationCandidate getCandidateBy Target(OsmPrimitive tgt) {50 public ConflationCandidate getCandidateBySubject(OsmPrimitive subjectObject) { 52 51 for (ConflationCandidate c : candidates) { 53 if (c.get TargetPrimitive() == tgt) {52 if (c.getSubjectObject() == subjectObject) { 54 53 return c; 55 54 } -
applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationLayer.java
r27959 r27971 60 60 g2.setColor(Color.cyan); 61 61 } 62 OsmPrimitive src = candidate.getSourcePrimitive();63 OsmPrimitive tgt = candidate.getTargetPrimitive();64 if ( src != null && tgt != null) {62 OsmPrimitive reference = candidate.getReferenceObject(); 63 OsmPrimitive subject = candidate.getSubjectObject(); 64 if (reference != null && subject != null) { 65 65 GeneralPath path = new GeneralPath(); 66 66 // we have a pair, so draw line between them, FIXME: not good to use getCenter() from here, move to utils? 67 Point p1 = mv.getPoint(ConflationUtils.getCenter( src));68 Point p2 = mv.getPoint(ConflationUtils.getCenter( tgt));67 Point p1 = mv.getPoint(ConflationUtils.getCenter(reference)); 68 Point p2 = mv.getPoint(ConflationUtils.getCenter(subject)); 69 69 path.moveTo(p1.x, p1.y); 70 70 path.lineTo(p2.x, p2.y); … … 118 118 for (Iterator<ConflationCandidate> it = this.candidates.iterator(); it.hasNext();) { 119 119 ConflationCandidate candidate = it.next(); 120 OsmPrimitive src = candidate.getSourcePrimitive();121 OsmPrimitive tgt = candidate.getTargetPrimitive();122 if ( src != null && srcinstanceof Node)123 v.visit((Node) src);124 if ( tgt != null && tgt instanceof Node)125 v.visit((Node) tgt);120 OsmPrimitive reference = candidate.getReferenceObject(); 121 OsmPrimitive subject = candidate.getSubjectObject(); 122 if (reference != null && reference instanceof Node) 123 v.visit((Node)reference); 124 if (subject != null && subject instanceof Node) 125 v.visit((Node)subject); 126 126 } 127 127 } -
applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationPlugin.java
r27959 r27971 26 26 if (oldFrame == null && newFrame != null) { 27 27 if (dialog == null) { 28 Shortcut shortcut = Shortcut.registerShortcut("Conflation", tr("Toggle: {0}", tr("Open Conflation")), 29 KeyEvent.VK_0, Shortcut.ALT_SHIFT); 28 // Shortcut shortcut = null; Shortcut.registerShortcut("Conflation", tr("Toggle: {0}", tr("Open Conflation")), 29 // KeyEvent.VK_0, Shortcut.ALT_SHIFT); 30 Shortcut shortcut = null; 30 31 String name = "Conflation"; 31 32 String tooltip = "Activates the conflation plugin"; -
applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationToggleDialog.java
r27959 r27971 1 /*2 * To change this template, choose Tools | Templates3 * and open the template in the editor.4 */5 1 package org.openstreetmap.josm.plugins.conflation; 6 2 … … 132 128 if (!lsm.isSelectionEmpty() && firstIndex == lastIndex && firstIndex < candidates.size()) { 133 129 ConflationCandidate c = candidates.get(firstIndex); 134 OsmPrimitive src = c.getSourcePrimitive();135 OsmPrimitive tgt = c.getTargetPrimitive();130 OsmPrimitive reference = c.getReferenceObject(); 131 OsmPrimitive subject = c.getSubjectObject(); 136 132 137 133 conflationLayer.setSelectedCandidate(c); 138 134 139 src.getDataSet().clearSelection();140 tgt.getDataSet().clearSelection();141 src.getDataSet().addSelected(src);142 tgt.getDataSet().addSelected(tgt);135 reference.getDataSet().clearSelection(); 136 subject.getDataSet().clearSelection(); 137 reference.getDataSet().addSelected(reference); 138 subject.getDataSet().addSelected(subject); 143 139 144 140 // zoom/center on pair 145 141 BoundingXYVisitor box = new BoundingXYVisitor(); 146 box.computeBoundingBox(Arrays.asList( src, tgt));142 box.computeBoundingBox(Arrays.asList(reference, subject)); 147 143 if (box.getBounds() == null) { 148 144 return; … … 212 208 ReplaceGeometryAction rg = new ReplaceGeometryAction(); 213 209 ConflationCandidate c = conflationLayer.getSelectedCandidate(); 214 if (rg.replace(c.get SourcePrimitive(), c.getTargetPrimitive())) {210 if (rg.replace(c.getReferenceObject(), c.getSubjectObject())) { 215 211 candidates.remove(c); 216 212 } … … 222 218 private JPanel costsPanel; 223 219 private JCheckBox distanceCheckBox; 224 private JButton freeze SourceButton;225 private JButton freeze TargetButton;220 private JButton freezeReferenceButton; 221 private JButton freezeSubjectButton; 226 222 private JPanel jPanel3; 227 223 private JPanel jPanel5; 228 private JButton restoreSourceButton; 229 private JButton restoreTargetButton; 230 private JLabel sourceLayerLabel; 231 private JPanel sourcePanel; 232 private JLabel sourceSelectionLabel; 233 private JLabel targetLayerLabel; 234 private JPanel targetPanel; 235 private JLabel targetSelectionLabel; 236 ArrayList<OsmPrimitive> tgtSelection = null; 237 ArrayList<OsmPrimitive> srcSelection = null; 238 OsmDataLayer srcLayer; 239 DataSet tgtDataSet; 240 OsmDataLayer tgtLayer; 241 DataSet srcDataSet; 242 private boolean canceled = false; 224 private JButton restoreReferenceButton; 225 private JButton restoreSubjectButton; 226 private JLabel referenceLayerLabel; 227 private JPanel referencePanel; 228 private JLabel referenceSelectionLabel; 229 private JLabel subjectLayerLabel; 230 private JPanel subjectPanel; 231 private JLabel subjectSelectionLabel; 232 ArrayList<OsmPrimitive> subjectSelection = null; 233 ArrayList<OsmPrimitive> referenceSelection = null; 234 OsmDataLayer referenceLayer; 235 DataSet subjectDataSet; 236 OsmDataLayer subjectLayer; 237 DataSet referenceDataSet; 243 238 244 239 public ConflationOptionsDialog() { … … 251 246 252 247 private void initComponents() { 253 sourcePanel = new JPanel();254 sourceLayerLabel = new JLabel();255 sourceSelectionLabel = new JLabel();248 referencePanel = new JPanel(); 249 referenceLayerLabel = new JLabel(); 250 referenceSelectionLabel = new JLabel(); 256 251 jPanel3 = new JPanel(); 257 restore SourceButton = new JButton(new RestoreSourceAction());258 freeze SourceButton = new JButton(new FreezeSourceAction());259 targetPanel = new JPanel();260 targetLayerLabel = new JLabel();261 targetSelectionLabel = new JLabel();252 restoreReferenceButton = new JButton(new RestoreReferenceAction()); 253 freezeReferenceButton = new JButton(new FreezeReferenceAction()); 254 subjectPanel = new JPanel(); 255 subjectLayerLabel = new JLabel(); 256 subjectSelectionLabel = new JLabel(); 262 257 jPanel5 = new JPanel(); 263 restore TargetButton = new JButton(new RestoreTargetAction());264 freeze TargetButton = new JButton(new FreezeTargetAction());258 restoreSubjectButton = new JButton(new RestoreSubjectAction()); 259 freezeSubjectButton = new JButton(new FreezeSubjectAction()); 265 260 costsPanel = new JPanel(); 266 261 distanceCheckBox = new JCheckBox(); … … 269 264 pnl.setLayout(new BoxLayout(pnl, BoxLayout.PAGE_AXIS)); 270 265 271 sourcePanel.setBorder(BorderFactory.createTitledBorder("Source"));272 sourcePanel.setLayout(new BoxLayout(sourcePanel, BoxLayout.PAGE_AXIS));273 274 sourceLayerLabel.setText("layer");275 sourcePanel.add(sourceLayerLabel);276 277 sourceSelectionLabel.setText("Rel.:0 / Ways:0 / Nodes: 0");278 sourcePanel.add(sourceSelectionLabel);266 referencePanel.setBorder(BorderFactory.createTitledBorder(tr("Reference"))); 267 referencePanel.setLayout(new BoxLayout(referencePanel, BoxLayout.PAGE_AXIS)); 268 269 referenceLayerLabel.setText("(none)"); 270 referencePanel.add(referenceLayerLabel); 271 272 referenceSelectionLabel.setText("Rel.:0 / Ways:0 / Nodes: 0"); 273 referencePanel.add(referenceSelectionLabel); 279 274 280 275 jPanel3.setLayout(new BoxLayout(jPanel3, BoxLayout.LINE_AXIS)); 281 276 282 restore SourceButton.setText("Restore");283 jPanel3.add(restore SourceButton);284 285 jPanel3.add(freeze SourceButton);286 287 sourcePanel.add(jPanel3);288 289 pnl.add( sourcePanel);290 291 targetPanel.setBorder(BorderFactory.createTitledBorder("Target"));292 targetPanel.setLayout(new BoxLayout(targetPanel, BoxLayout.PAGE_AXIS));293 294 targetLayerLabel.setText("layer");295 targetPanel.add(targetLayerLabel);296 297 targetSelectionLabel.setText("Rel.:0 / Ways:0 / Nodes: 0");298 targetPanel.add(targetSelectionLabel);277 restoreReferenceButton.setText(tr("Restore")); 278 jPanel3.add(restoreReferenceButton); 279 280 jPanel3.add(freezeReferenceButton); 281 282 referencePanel.add(jPanel3); 283 284 pnl.add(referencePanel); 285 286 subjectPanel.setBorder(BorderFactory.createTitledBorder(tr("Subject"))); 287 subjectPanel.setLayout(new BoxLayout(subjectPanel, BoxLayout.PAGE_AXIS)); 288 289 subjectLayerLabel.setText("(none)"); 290 subjectPanel.add(subjectLayerLabel); 291 292 subjectSelectionLabel.setText("Rel.:0 / Ways:0 / Nodes: 0"); 293 subjectPanel.add(subjectSelectionLabel); 299 294 300 295 jPanel5.setLayout(new BoxLayout(jPanel5, BoxLayout.LINE_AXIS)); 301 296 302 restore TargetButton.setText("Restore");303 jPanel5.add(restore TargetButton);304 305 freeze TargetButton.setText("Freeze");306 jPanel5.add(freeze TargetButton);307 308 targetPanel.add(jPanel5);309 310 pnl.add( targetPanel);311 312 costsPanel.setBorder(BorderFactory.createTitledBorder( "Costs"));297 restoreSubjectButton.setText(tr("Restore")); 298 jPanel5.add(restoreSubjectButton); 299 300 freezeSubjectButton.setText(tr("Freeze")); 301 jPanel5.add(freezeSubjectButton); 302 303 subjectPanel.add(jPanel5); 304 305 pnl.add(subjectPanel); 306 307 costsPanel.setBorder(BorderFactory.createTitledBorder(tr("Costs"))); 313 308 costsPanel.setLayout(new BoxLayout(costsPanel, BoxLayout.LINE_AXIS)); 314 309 315 310 distanceCheckBox.setSelected(true); 316 distanceCheckBox.setText( "Distance");311 distanceCheckBox.setText(tr("Distance")); 317 312 distanceCheckBox.setEnabled(false); 318 313 costsPanel.add(distanceCheckBox); … … 328 323 super.buttonAction(buttonIndex, evt); 329 324 if (buttonIndex == 0) { 330 criteriaTabConflateButtonActionPerformed();331 } 332 } 333 334 private void criteriaTabConflateButtonActionPerformed() {325 performConflation(); 326 } 327 } 328 329 private void performConflation() { 335 330 336 331 // some initialization 337 int n = tgtSelection.size();338 int m = srcSelection.size();332 int n = subjectSelection.size(); 333 int m = referenceSelection.size(); 339 334 int maxLen = Math.max(n, m); 340 335 double cost[][] = new double[maxLen][maxLen]; … … 343 338 for (int i = 0; i < n; i++) { 344 339 for (int j = 0; j < m; j++) { 345 cost[i][j] = ConflationUtils.calcCost( tgtSelection.get(i), srcSelection.get(j));340 cost[i][j] = ConflationUtils.calcCost(subjectSelection.get(i), referenceSelection.get(j)); 346 341 } 347 342 } … … 349 344 // perform assignment using Hungarian algorithm 350 345 int[][] assignment = HungarianAlgorithm.hgAlgorithm(cost, "min"); 351 OsmPrimitive tgt, src;346 OsmPrimitive subObject, refObject; 352 347 candidates.clear(); 353 348 for (int i = 0; i < maxLen; i++) { 354 int tgtIdx = assignment[i][0];355 int srcIdx = assignment[i][1];356 if ( tgtIdx < n) {357 tgt = tgtSelection.get(tgtIdx);349 int subIdx = assignment[i][0]; 350 int refIdx = assignment[i][1]; 351 if (subIdx < n) { 352 subObject = subjectSelection.get(subIdx); 358 353 } else { 359 tgt = null;360 } 361 if ( srcIdx < m) {362 src = srcSelection.get(srcIdx);354 subObject = null; 355 } 356 if (refIdx < m) { 357 refObject = referenceSelection.get(refIdx); 363 358 } else { 364 src= null;365 } 366 367 if ( tgt != null && src!= null) {359 refObject = null; 360 } 361 362 if (subObject != null && refObject != null) { 368 363 // TODO: do something! 369 if (!(candidates.hasCandidate( src, tgt) || candidates.hasCandidate(tgt, src))) {370 candidates.add(new ConflationCandidate( src, srcLayer, tgt, tgtLayer, cost[tgtIdx][srcIdx]));364 if (!(candidates.hasCandidate(refObject, subObject) || candidates.hasCandidate(subObject, refObject))) { 365 candidates.add(new ConflationCandidate(refObject, referenceLayer, subObject, subjectLayer, cost[subIdx][refIdx])); 371 366 } 372 367 } … … 375 370 // add conflation layer 376 371 try { 377 conflationLayer = new ConflationLayer( tgtLayer.data, candidates);372 conflationLayer = new ConflationLayer(subjectLayer.data, candidates); 378 373 Main.main.addLayer(conflationLayer); 379 374 } catch (Exception ex) { … … 390 385 } 391 386 392 class Restore TargetAction extends JosmAction {393 394 public Restore TargetAction() {395 super(tr("Restore"), null, tr("Restore target selection"), null, false);387 class RestoreSubjectAction extends JosmAction { 388 389 public RestoreSubjectAction() { 390 super(tr("Restore"), null, tr("Restore subject selection"), null, false); 396 391 } 397 392 398 393 @Override 399 394 public void actionPerformed(ActionEvent e) { 400 if ( tgtLayer != null && tgtDataSet != null && tgtSelection != null && !tgtSelection.isEmpty()) {401 Main.map.mapView.setActiveLayer( tgtLayer);402 tgtLayer.setVisible(true);403 tgtDataSet.setSelected(tgtSelection);404 } 405 } 406 } 407 408 class Restore SourceAction extends JosmAction {409 410 public Restore SourceAction() {411 super(tr("Restore"), null, tr("Restore source selection"), null, false);395 if (subjectLayer != null && subjectDataSet != null && subjectSelection != null && !subjectSelection.isEmpty()) { 396 Main.map.mapView.setActiveLayer(subjectLayer); 397 subjectLayer.setVisible(true); 398 subjectDataSet.setSelected(subjectSelection); 399 } 400 } 401 } 402 403 class RestoreReferenceAction extends JosmAction { 404 405 public RestoreReferenceAction() { 406 super(tr("Restore"), null, tr("Restore reference selection"), null, false); 412 407 } 413 408 414 409 @Override 415 410 public void actionPerformed(ActionEvent e) { 416 if ( srcLayer != null && srcDataSet != null && srcSelection != null && !srcSelection.isEmpty()) {417 Main.map.mapView.setActiveLayer( srcLayer);418 srcLayer.setVisible(true);419 srcDataSet.setSelected(srcSelection);420 } 421 } 422 } 423 424 class Freeze TargetAction extends JosmAction {425 426 public Freeze TargetAction() {427 super(tr("Freeze"), null, tr("Freeze target selection"), null, false);411 if (referenceLayer != null && referenceDataSet != null && referenceSelection != null && !referenceSelection.isEmpty()) { 412 Main.map.mapView.setActiveLayer(referenceLayer); 413 referenceLayer.setVisible(true); 414 referenceDataSet.setSelected(referenceSelection); 415 } 416 } 417 } 418 419 class FreezeSubjectAction extends JosmAction { 420 421 public FreezeSubjectAction() { 422 super(tr("Freeze"), null, tr("Freeze subject selection"), null, false); 428 423 } 429 424 430 425 @Override 431 426 public void actionPerformed(ActionEvent e) { 432 if ( tgtDataSet != null && tgtDataSet == Main.main.getCurrentDataSet()) {433 // targetDataSet.removeDataSetListener(this); FIXME:434 } 435 tgtDataSet = Main.main.getCurrentDataSet();436 // targetDataSet.addDataSetListener(tableModel); FIXME:437 tgtLayer = Main.main.getEditLayer();438 if ( tgtDataSet == null || tgtLayer == null) {427 if (subjectDataSet != null && subjectDataSet == Main.main.getCurrentDataSet()) { 428 // subjectDataSet.removeDataSetListener(this); FIXME: 429 } 430 subjectDataSet = Main.main.getCurrentDataSet(); 431 // subjectDataSet.addDataSetListener(tableModel); FIXME: 432 subjectLayer = Main.main.getEditLayer(); 433 if (subjectDataSet == null || subjectLayer == null) { 439 434 JOptionPane.showMessageDialog(Main.parent, tr("No valid OSM data layer present."), 440 435 tr("Error freezing selection"), JOptionPane.ERROR_MESSAGE); 441 436 return; 442 437 } 443 tgtSelection = new ArrayList<OsmPrimitive>(tgtDataSet.getSelected());444 if ( tgtSelection.isEmpty()) {438 subjectSelection = new ArrayList<OsmPrimitive>(subjectDataSet.getSelected()); 439 if (subjectSelection.isEmpty()) { 445 440 JOptionPane.showMessageDialog(Main.parent, tr("Nothing is selected, please try again."), 446 441 tr("Empty selection"), JOptionPane.ERROR_MESSAGE); … … 451 446 int numWays = 0; 452 447 int numRelations = 0; 453 for (OsmPrimitive p : tgtSelection) {448 for (OsmPrimitive p : subjectSelection) { 454 449 switch (p.getType()) { 455 450 case NODE: … … 466 461 467 462 // FIXME: translate correctly 468 targetLayerLabel.setText(tgtLayer.getName());469 targetSelectionLabel.setText(String.format("Rel.: %d / Ways: %d / Nodes: %d", numRelations, numWays, numNodes));470 } 471 } 472 473 class Freeze SourceAction extends JosmAction {474 475 public Freeze SourceAction() {476 super(tr("Freeze"), null, tr("Freeze target selection"), null, false);463 subjectLayerLabel.setText(subjectLayer.getName()); 464 subjectSelectionLabel.setText(String.format("Rel.: %d / Ways: %d / Nodes: %d", numRelations, numWays, numNodes)); 465 } 466 } 467 468 class FreezeReferenceAction extends JosmAction { 469 470 public FreezeReferenceAction() { 471 super(tr("Freeze"), null, tr("Freeze subject selection"), null, false); 477 472 } 478 473 479 474 @Override 480 475 public void actionPerformed(ActionEvent e) { 481 if ( srcDataSet != null && srcDataSet == Main.main.getCurrentDataSet()) {482 // sourceDataSet.removeDataSetListener(this); FIXME:483 } 484 srcDataSet = Main.main.getCurrentDataSet();485 // sourceDataSet.addDataSetListener(this); FIXME:486 srcLayer = Main.main.getEditLayer();487 if ( srcDataSet == null || srcLayer == null) {476 if (referenceDataSet != null && referenceDataSet == Main.main.getCurrentDataSet()) { 477 // referenceDataSet.removeDataSetListener(this); FIXME: 478 } 479 referenceDataSet = Main.main.getCurrentDataSet(); 480 // referenceDataSet.addDataSetListener(this); FIXME: 481 referenceLayer = Main.main.getEditLayer(); 482 if (referenceDataSet == null || referenceLayer == null) { 488 483 JOptionPane.showMessageDialog(Main.parent, tr("No valid OSM data layer present."), 489 484 tr("Error freezing selection"), JOptionPane.ERROR_MESSAGE); 490 485 return; 491 486 } 492 srcSelection = new ArrayList<OsmPrimitive>(srcDataSet.getSelected());493 if ( srcSelection.isEmpty()) {487 referenceSelection = new ArrayList<OsmPrimitive>(referenceDataSet.getSelected()); 488 if (referenceSelection.isEmpty()) { 494 489 JOptionPane.showMessageDialog(Main.parent, tr("Nothing is selected, please try again."), 495 490 tr("Empty selection"), JOptionPane.ERROR_MESSAGE); … … 500 495 int numWays = 0; 501 496 int numRelations = 0; 502 for (OsmPrimitive p : srcSelection) {497 for (OsmPrimitive p : referenceSelection) { 503 498 switch (p.getType()) { 504 499 case NODE: … … 515 510 516 511 // FIXME: translate correctly 517 sourceLayerLabel.setText(srcLayer.getName());518 sourceSelectionLabel.setText(String.format("Rel.: %d / Ways: %d / Nodes: %d", numRelations, numWays, numNodes));512 referenceLayerLabel.setText(referenceLayer.getName()); 513 referenceSelectionLabel.setText(String.format("Rel.: %d / Ways: %d / Nodes: %d", numRelations, numWays, numNodes)); 519 514 } 520 515 } … … 530 525 for (OsmPrimitive p : prims) { 531 526 for (ConflationCandidate c : candidates) { 532 if (c.get SourcePrimitive().equals(p) || c.getTargetPrimitive().equals(p)) {527 if (c.getReferenceObject().equals(p) || c.getSubjectObject().equals(p)) { 533 528 candidates.remove(c); 534 529 break; -
applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationUtils.java
r27959 r27971 1 /*2 * To change this template, choose Tools | Templates3 * and open the template in the editor.4 */5 1 package org.openstreetmap.josm.plugins.conflation; 6 2 … … 10 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 7 12 /**13 *14 * @author Josh15 */16 8 public final class ConflationUtils { 17 9 private final static double MAX_COST = Double.MAX_VALUE; … … 27 19 * now, later we can also use dissimilarity between tags. 28 20 * 29 * @param sourcethe reference <code>OsmPrimitive</code>.30 * @param target the non-reference <code>OsmPrimitive</code>.21 * @param referenceObject the reference <code>OsmPrimitive</code>. 22 * @param subjectObject the non-reference <code>OsmPrimitive</code>. 31 23 */ 32 public static double calcCost(OsmPrimitive source, OsmPrimitive target) {33 if ( source==target) {24 public static double calcCost(OsmPrimitive referenceObject, OsmPrimitive subjectObject) { 25 if (referenceObject==subjectObject) { 34 26 return MAX_COST; 35 27 } 36 28 37 29 try { 38 return getCenter( source).distance(getCenter(target));30 return getCenter(referenceObject).distance(getCenter(subjectObject)); 39 31 } catch (Exception e) { 40 32 return MAX_COST; -
applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/MatchTableModel.java
r27959 r27971 1 /*2 * To change this template, choose Tools | Templates3 * and open the template in the editor.4 */5 1 package org.openstreetmap.josm.plugins.conflation; 6 2 … … 10 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 7 import org.openstreetmap.josm.data.osm.TagCollection; 8 import static org.openstreetmap.josm.tools.I18n.tr; 12 9 13 10 /** … … 17 14 18 15 private ConflationCandidateList candidates = null; 19 private final static String[] columnNames = { "Mine", "Theirs", "Distance (m)", "Cost", "Tags"};16 private final static String[] columnNames = {tr("Reference"), tr("Subject"), "Distance (m)", "Cost", "Tags"}; 20 17 21 18 @Override … … 42 39 ConflationCandidate c = candidates.get(row); 43 40 if (col == 0) { 44 return c.get SourcePrimitive();41 return c.getReferenceObject(); 45 42 } else if (col == 1) { 46 return c.get TargetPrimitive();43 return c.getSubjectObject(); 47 44 } else if (col == 2) { 48 45 return c.getDistance(); … … 52 49 if (col == 4) { 53 50 HashSet<OsmPrimitive> set = new HashSet<OsmPrimitive>(); 54 set.add(c.get SourcePrimitive());55 set.add(c.get TargetPrimitive());51 set.add(c.getReferenceObject()); 52 set.add(c.getSubjectObject()); 56 53 TagCollection tags = TagCollection.unionOfAllPrimitives(set); 57 54 Set<String> keys = tags.getKeysWithMultipleValues(); -
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/dumbutils/ReplaceGeometryAction.java
r27937 r27971 80 80 * Replace or upgrade a node to a way or multipolygon 81 81 * 82 * @param node83 * @param target82 * @param subjectNode node to be replaced 83 * @param referenceObject object with greater spatial quality 84 84 */ 85 public boolean replaceNode(Node node, OsmPrimitive target) {86 if (!OsmPrimitive.getFilteredList( node.getReferrers(), Way.class).isEmpty()) {85 public boolean replaceNode(Node subjectNode, OsmPrimitive referenceObject) { 86 if (!OsmPrimitive.getFilteredList(subjectNode.getReferrers(), Way.class).isEmpty()) { 87 87 JOptionPane.showMessageDialog(Main.parent, tr("Node belongs to way(s), cannot replace."), 88 88 TITLE, JOptionPane.INFORMATION_MESSAGE); … … 90 90 } 91 91 92 if ( target instanceof Relation && !((Relation) target).isMultipolygon()) {92 if (referenceObject instanceof Relation && !((Relation) referenceObject).isMultipolygon()) { 93 93 JOptionPane.showMessageDialog(Main.parent, tr("Relation is not a multipolygon, cannot be used as a replacement."), 94 94 TITLE, JOptionPane.INFORMATION_MESSAGE); … … 98 98 Node nodeToReplace = null; 99 99 // see if we need to replace a node in the replacement way to preserve connection in history 100 if (! node.isNew()) {100 if (!subjectNode.isNew()) { 101 101 // Prepare a list of nodes that are not important 102 102 Collection<Node> nodePool = new HashSet<Node>(); 103 if ( target instanceof Way) {104 nodePool.addAll(getUnimportantNodes((Way) target));105 } else if ( target instanceof Relation) {106 for (RelationMember member : ((Relation) target).getMembers()) {103 if (referenceObject instanceof Way) { 104 nodePool.addAll(getUnimportantNodes((Way) referenceObject)); 105 } else if (referenceObject instanceof Relation) { 106 for (RelationMember member : ((Relation) referenceObject).getMembers()) { 107 107 if ((member.getRole().equals("outer") || member.getRole().equals("inner")) 108 108 && member.isWay()) { … … 115 115 assert false; 116 116 } 117 nodeToReplace = findNearestNode( node, nodePool);117 nodeToReplace = findNearestNode(subjectNode, nodePool); 118 118 } 119 119 120 120 List<Command> commands = new ArrayList<Command>(); 121 AbstractMap<String, String> nodeTags = (AbstractMap<String, String>) node.getKeys();121 AbstractMap<String, String> nodeTags = (AbstractMap<String, String>) subjectNode.getKeys(); 122 122 123 123 // merge tags 124 Collection<Command> tagResolutionCommands = getTagConflictResolutionCommands( node, target);124 Collection<Command> tagResolutionCommands = getTagConflictResolutionCommands(subjectNode, referenceObject); 125 125 if (tagResolutionCommands == null) { 126 126 // user canceled tag merge dialog … … 135 135 List<Node> wayNodes = parentWay.getNodes(); 136 136 int idx = wayNodes.indexOf(nodeToReplace); 137 wayNodes.set(idx, node);137 wayNodes.set(idx, subjectNode); 138 138 if (idx == 0 && parentWay.isClosed()) { 139 139 // node is at start/end of way 140 wayNodes.set(wayNodes.size() - 1, node);140 wayNodes.set(wayNodes.size() - 1, subjectNode); 141 141 } 142 142 commands.add(new ChangeNodesCommand(parentWay, wayNodes)); 143 commands.add(new MoveCommand( node, nodeToReplace.getCoor()));143 commands.add(new MoveCommand(subjectNode, nodeToReplace.getCoor())); 144 144 commands.add(new DeleteCommand(nodeToReplace)); 145 145 … … 147 147 if (!nodeTags.isEmpty()) { 148 148 for (String key : nodeTags.keySet()) { 149 commands.add(new ChangePropertyCommand( node, key, null));149 commands.add(new ChangePropertyCommand(subjectNode, key, null)); 150 150 } 151 151 … … 153 153 } else { 154 154 // no node to replace, so just delete the original node 155 commands.add(new DeleteCommand( node));156 } 157 158 getCurrentDataSet().setSelected( target);155 commands.add(new DeleteCommand(subjectNode)); 156 } 157 158 getCurrentDataSet().setSelected(referenceObject); 159 159 160 160 Main.main.undoRedo.add(new SequenceCommand( 161 tr("Replace geometry for node {0}", node.getDisplayName(DefaultNameFormatter.getInstance())),161 tr("Replace geometry for node {0}", subjectNode.getDisplayName(DefaultNameFormatter.getInstance())), 162 162 commands)); 163 163 return true; … … 184 184 } 185 185 } 186 Way geometry = selection.get(idxNew);187 Way way = selection.get(1 - idxNew);188 189 if( !overrideNewCheck && ( way.isNew() || !geometry.isNew()) ) {186 Way referenceWay = selection.get(idxNew); 187 Way subjectWay = selection.get(1 - idxNew); 188 189 if( !overrideNewCheck && (subjectWay.isNew() || !referenceWay.isNew()) ) { 190 190 JOptionPane.showMessageDialog(Main.parent, 191 191 tr("Please select one way that exists in the database and one new way with correct geometry."), … … 193 193 return false; 194 194 } 195 return replaceWayWithWay(subjectWay, referenceWay); 196 } 197 198 public static boolean replaceWayWithWay(Way subjectWay, Way referenceWay) { 195 199 196 200 Area a = getCurrentDataSet().getDataSourceArea(); 197 if (!isInArea( way, a) || !isInArea(geometry, a)) {201 if (!isInArea(subjectWay, a) || !isInArea(referenceWay, a)) { 198 202 JOptionPane.showMessageDialog(Main.parent, 199 203 tr("The ways must be entirely within the downloaded area."), … … 202 206 } 203 207 204 if (hasImportantNode( geometry, way)) {208 if (hasImportantNode(referenceWay, subjectWay)) { 205 209 JOptionPane.showMessageDialog(Main.parent, 206 210 tr("The way to be replaced cannot have any nodes with properties or relation memberships unless they belong to both ways."), … … 212 216 213 217 // merge tags 214 Collection<Command> tagResolutionCommands = getTagConflictResolutionCommands( geometry, way);218 Collection<Command> tagResolutionCommands = getTagConflictResolutionCommands(referenceWay, subjectWay); 215 219 if (tagResolutionCommands == null) { 216 220 // user canceled tag merge dialog … … 220 224 221 225 // Prepare a list of nodes that are not used anywhere except in the way 222 Collection<Node> nodePool = getUnimportantNodes( way);226 Collection<Node> nodePool = getUnimportantNodes(subjectWay); 223 227 224 228 // And the same for geometry, list nodes that can be freely deleted 225 229 Set<Node> geometryPool = new HashSet<Node>(); 226 for( Node node : geometry.getNodes() ) {230 for( Node node : referenceWay.getNodes() ) { 227 231 List<OsmPrimitive> referrers = node.getReferrers(); 228 232 if( node.isNew() && !node.isDeleted() && referrers.size() == 1 229 && referrers.get(0).equals( geometry) && !way.containsNode(node)233 && referrers.get(0).equals(referenceWay) && !subjectWay.containsNode(node) 230 234 && !hasInterestingKey(node)) 231 235 geometryPool.add(node); … … 248 252 249 253 // And prepare a list of nodes with all the replacements 250 List<Node> geometryNodes = geometry.getNodes();254 List<Node> geometryNodes = referenceWay.getNodes(); 251 255 for( int i = 0; i < geometryNodes.size(); i++ ) 252 256 if( nodeAssoc.containsKey(geometryNodes.get(i)) ) … … 254 258 255 259 // Now do the replacement 256 commands.add(new ChangeNodesCommand( way, geometryNodes));260 commands.add(new ChangeNodesCommand(subjectWay, geometryNodes)); 257 261 258 262 // Move old nodes to new positions … … 261 265 262 266 // Remove geometry way from selection 263 getCurrentDataSet().clearSelection( geometry);267 getCurrentDataSet().clearSelection(referenceWay); 264 268 265 269 // And delete old geometry way 266 commands.add(new DeleteCommand( geometry));270 commands.add(new DeleteCommand(referenceWay)); 267 271 268 272 // Delete nodes that are not used anymore … … 272 276 // Two items in undo stack: change original way and delete geometry way 273 277 Main.main.undoRedo.add(new SequenceCommand( 274 tr("Replace geometry for way {0}", way.getDisplayName(DefaultNameFormatter.getInstance())),278 tr("Replace geometry for way {0}", subjectWay.getDisplayName(DefaultNameFormatter.getInstance())), 275 279 commands)); 276 280 return true; … … 283 287 * @return 284 288 */ 285 protected Collection<Node> getUnimportantNodes(Way way) {289 protected static Collection<Node> getUnimportantNodes(Way way) { 286 290 Set<Node> nodePool = new HashSet<Node>(); 287 291 for (Node n : way.getNodes()) { … … 302 306 * @return 303 307 */ 304 protected boolean hasImportantNode(Way geometry, Way way) {308 protected static boolean hasImportantNode(Way geometry, Way way) { 305 309 for (Node n : way.getNodes()) { 306 310 // if original and replacement way share a node, it's safe to replace … … 321 325 } 322 326 323 protected boolean hasInterestingKey(OsmPrimitive object) {327 protected static boolean hasInterestingKey(OsmPrimitive object) { 324 328 for (String key : object.getKeys().keySet()) { 325 329 if (!OsmPrimitive.isUninterestingKey(key)) { … … 355 359 * needed. 356 360 * 357 * @param source 358 * @param target 361 * @param source object tags are merged from 362 * @param target object tags are merged to 359 363 * @return 360 364 */ 361 p ublic List<Command> getTagConflictResolutionCommands(OsmPrimitive source, OsmPrimitive target) {365 protected static List<Command> getTagConflictResolutionCommands(OsmPrimitive source, OsmPrimitive target) { 362 366 Collection<OsmPrimitive> primitives = Arrays.asList(source, target); 363 367 … … 394 398 * @return null if there is no such node. 395 399 */ 396 pr ivateNode findNearestNode( Node node, Collection<Node> nodes ) {400 protected static Node findNearestNode( Node node, Collection<Node> nodes ) { 397 401 if( nodes.contains(node) ) 398 402 return node;
Note:
See TracChangeset
for help on using the changeset viewer.