Changeset 12279 in osm for applications/editors
- Timestamp:
- 2008-12-09T23:53:05+01:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/OSMValidatorPlugin.java
r12257 r12279 4 4 5 5 import java.io.BufferedReader; 6 import java.io.File; 6 7 import java.io.FileNotFoundException; 7 8 import java.io.FileReader; … … 101 102 public OSMValidatorPlugin() { 102 103 plugin = this; 104 checkPluginDir(); 103 105 initializeGridDetail(); 104 106 initializeTests(getTests()); … … 106 108 } 107 109 110 /** 111 * Check if plugin directory exists (store ignored errors file) 112 */ 113 private void checkPluginDir() { 114 try { 115 File pathDir = new File(Util.getPluginDir()); 116 if (!pathDir.exists()) 117 pathDir.mkdirs(); 118 } catch (Exception e){ 119 e.printStackTrace(); 120 } 121 } 122 108 123 private void loadIgnoredErrors() { 109 124 ignoredErrors.clear(); -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/DuplicateNode.java
r10774 r12279 5 5 import java.util.*; 6 6 7 import javax.swing.JOptionPane; 8 9 import org.openstreetmap.josm.Main; 7 import org.openstreetmap.josm.actions.MergeNodesAction; 10 8 import org.openstreetmap.josm.command.*; 11 9 import org.openstreetmap.josm.data.coor.LatLon; … … 72 70 { 73 71 Collection<? extends OsmPrimitive> sel = testError.getPrimitives(); 74 Collection<OsmPrimitive> nodes = new ArrayList<OsmPrimitive>();72 LinkedList<Node> nodes = new LinkedList<Node>(); 75 73 76 Node target = null; 77 for (OsmPrimitive osm : sel)78 nodes.add(osm);74 for (OsmPrimitive osm : sel) 75 if (osm instanceof Node) 76 nodes.add((Node)osm); 79 77 80 81 78 if( nodes.size() < 2 ) 79 return null; 82 80 83 for ( OsmPrimitive o : nodes ) 84 { 85 Node n = (Node)o; 86 if( target == null || target.id == 0 ) 87 { 88 target = n; 89 continue; 90 } 91 if( n.id == 0 ) 92 continue; 93 if( n.id < target.id ) 94 target = n; 95 } 96 if( target == null ) 97 return null; 81 Node target = null; 82 // select the target node in the same way as in the core action MergeNodesAction, rev.1084 83 for (Node n: nodes) { 84 if (n.id > 0) { 85 target = n; 86 break; 87 } 88 } 89 if (target == null) 90 target = nodes.iterator().next(); 98 91 99 // target is what we're merging into 100 // nodes is the list of nodes to be removed 101 nodes.remove(target); 92 MergeNodesAction.mergeNodes(nodes, target); 102 93 103 // Merge all properties 104 Node newtarget = new Node(target); 105 for (final OsmPrimitive o : nodes) 106 { 107 Node n = (Node)o; 108 for ( String key : n.keySet() ) 109 { 110 if( newtarget.keySet().contains(key) && !newtarget.get(key).equals(n.get(key)) ) 111 { 112 JOptionPane.showMessageDialog(Main.parent, tr("Nodes have conflicting key: {0} [{1}, {2}]", 113 key, newtarget.get(key), n.get(key))); 114 return null; 115 } 116 newtarget.put( key, n.get(key) ); 117 } 118 } 119 120 Collection<Command> cmds = new LinkedList<Command>(); 121 122 // Now search the ways for occurences of the nodes we are about to 123 // merge and replace them with the 'target' node 124 for (Way w : Main.ds.ways) { 125 if (w.deleted || w.incomplete) continue; 126 // FIXME: use some fancy method from java.util.Collections and 127 // List.replace 128 Way wnew = null; 129 int len = w.nodes.size(); 130 for (int i = 0; i < len; i++) { 131 if (!nodes.contains(w.nodes.get(i))) continue; 132 if (wnew == null) wnew = new Way(w); 133 wnew.nodes.set(i, target); 134 } 135 if (wnew != null) { 136 cmds.add(new ChangeCommand(w, wnew)); 137 } 138 } 139 140 cmds.add(DeleteCommand.delete(nodes)); 141 cmds.add(new ChangeCommand(target, newtarget)); 142 return new SequenceCommand(tr("Merge Nodes"), cmds); 94 return null; // undoRedo handling done in mergeNodes 143 95 } 144 96
Note:
See TracChangeset
for help on using the changeset viewer.