Changeset 12279 in osm


Ignore:
Timestamp:
2008-12-09T23:53:05+01:00 (16 years ago)
Author:
pieren
Message:

Trac#1807 use josm action to merge nodes (to avoid ways corruption).
Create plugin directory if missing used to store ignorederrors file.

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  
    44
    55import java.io.BufferedReader;
     6import java.io.File;
    67import java.io.FileNotFoundException;
    78import java.io.FileReader;
     
    101102    public OSMValidatorPlugin() {
    102103        plugin = this;
     104        checkPluginDir();
    103105        initializeGridDetail();
    104106        initializeTests(getTests());
     
    106108    }
    107109
     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   
    108123    private void loadIgnoredErrors() {
    109124        ignoredErrors.clear();
  • applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/DuplicateNode.java

    r10774 r12279  
    55import java.util.*;
    66
    7 import javax.swing.JOptionPane;
    8 
    9 import org.openstreetmap.josm.Main;
     7import org.openstreetmap.josm.actions.MergeNodesAction;
    108import org.openstreetmap.josm.command.*;
    119import org.openstreetmap.josm.data.coor.LatLon;
     
    7270        {
    7371                Collection<? extends OsmPrimitive> sel = testError.getPrimitives();
    74                 Collection<OsmPrimitive> nodes = new ArrayList<OsmPrimitive>();
     72                LinkedList<Node> nodes = new LinkedList<Node>();
    7573
    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);
    7977
    80                 if( nodes.size() < 2 )
    81                         return null;
     78        if( nodes.size() < 2 )
     79            return null;
    8280
    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();
    9891
    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);
    10293
    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
    14395        }
    14496
Note: See TracChangeset for help on using the changeset viewer.