Changeset 52 in josm


Ignore:
Timestamp:
2006-02-14T00:52:11+01:00 (19 years ago)
Author:
imi
Message:
  • fixed data merge (sometime set modified unnecessary)
  • fixed rounding (now compare with epsilon instead of round everything)
  • Fix: upload does not clear all changes if only some thing got uploaded
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/actions/SaveAction.java

    r51 r52  
    7373                        }
    7474                        fileWriter.close();
    75                         Main.main.getMapFrame().mapView.editLayer().cleanData(false, false);
     75                        Main.main.getMapFrame().mapView.editLayer().cleanData(null, false);
    7676                } catch (IOException e) {
    7777                        e.printStackTrace();
  • src/org/openstreetmap/josm/actions/UploadAction.java

    r51 r52  
    8484                                        JOptionPane.showMessageDialog(Main.main, x.getMessage());
    8585                                }
    86                                 Main.main.getMapFrame().mapView.editLayer().cleanData(true, !add.isEmpty());
     86                                Main.main.getMapFrame().mapView.editLayer().cleanData(server.processed, !add.isEmpty());
    8787                        }
    8888                }).start();
  • src/org/openstreetmap/josm/data/GeoPoint.java

    r41 r52  
    8080
    8181        /**
     82         * @return <code>true</code>, if the other GeoPoint has almost the same lat/lon
     83         * values, only differ by no more than 1/Projection.MAX_SERVER_PRECISION.
     84         */
     85        public boolean equalsLatLonEpsilon(GeoPoint other) {
     86                final double p = 1/Projection.MAX_SERVER_PRECISION;
     87                return Math.abs(lat-other.lat) <= p && Math.abs(lon-other.lon) <= p &&
     88                                !Double.isNaN(lat) && !Double.isNaN(lon);
     89        }
     90
     91        /**
    8292         * @return <code>true</code>, if the coordinate is outside the world, compared
    8393         * by using lat/lon.
  • src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java

    r50 r52  
    4242                        if (myNode.modified && !otherNode.modified)
    4343                                return;
    44                         if (!myNode.coor.equalsLatLon(otherNode.coor)) {
     44                        if (!myNode.coor.equalsLatLonEpsilon(otherNode.coor)) {
    4545                                myNode.coor = otherNode.coor;
    4646                                myNode.modified = otherNode.modified;
     
    5151        /**
    5252         * Merge the line segment if id matches or if both nodes are the same (and the
    53          * id is zero of either segment). Nodes are equal when they @see match
     53         * id is zero of either segment). Nodes are the "same" when they @see match
    5454         */
    5555        public void visit(LineSegment otherLs) {
     
    120120        private boolean match(Node n1, Node n2) {
    121121                if (n1.id == 0 || n2.id == 0)
    122                         return n1.coor.equalsLatLon(n2.coor);
     122                        return n1.coor.equalsLatLonEpsilon(n2.coor);
    123123                return n1.id == n2.id;
    124124        }
     
    153153         */
    154154        private void mergeCommon(OsmPrimitive myOsm, OsmPrimitive otherOsm) {
    155                 if (otherOsm.modified)
    156                         myOsm.modified = true;
    157155                if (otherOsm.isDeleted())
    158156                        myOsm.setDeleted(true);
    159157                if (!myOsm.modified || otherOsm.modified) {
    160                         if (otherOsm.id != 0 && myOsm.id == 0)
     158                        if (myOsm.id == 0 && otherOsm.id != 0)
    161159                                myOsm.id = otherOsm.id; // means not ncessary the object is now modified
     160                        else if (myOsm.id != 0 && otherOsm.id != 0 && otherOsm.modified)
     161                                myOsm.modified = true;
    162162                }
    163163                if (myOsm.modifiedProperties && !otherOsm.modifiedProperties)
    164164                        return;
    165                 if (myOsm.keys != null && !myOsm.keys.equals(otherOsm.keys)) {
    166                         if (myOsm.keys == null)
    167                                 myOsm.keys = otherOsm.keys;
    168                         else if (otherOsm.keys != null)
    169                                 myOsm.keys.putAll(otherOsm.keys);
    170                         myOsm.modifiedProperties = true;
    171                 }
     165                if (otherOsm.keys == null)
     166                        return;
     167                if (myOsm.keys != null && myOsm.keys.entrySet().containsAll(otherOsm.keys.entrySet()))
     168                        return;
     169                if (myOsm.keys == null)
     170                        myOsm.keys = otherOsm.keys;
     171                else
     172                        myOsm.keys.putAll(otherOsm.keys);
     173                myOsm.modifiedProperties = true;
    172174        }
    173175}
  • src/org/openstreetmap/josm/data/projection/Epsg4263.java

    r51 r52  
    1616
    1717        public void xy2latlon(GeoPoint p) {
    18                 p.lat = Math.round(p.y*MAX_SERVER_PRECISION)/MAX_SERVER_PRECISION;
    19                 p.lon = Math.round(p.x*MAX_SERVER_PRECISION)/MAX_SERVER_PRECISION;
     18                p.lat = p.y;
     19                p.lon = p.x;
    2020        }
    2121
  • src/org/openstreetmap/josm/data/projection/Mercator.java

    r51 r52  
    2222                p.lon = p.x*180/Math.PI;
    2323                p.lat = Math.atan(Math.sinh(p.y))*180/Math.PI;
    24                 // round values to maximum server precision
    25                 p.lon = Math.round(p.lon*MAX_SERVER_PRECISION)/MAX_SERVER_PRECISION;
    26                 p.lat = Math.round(p.lat*MAX_SERVER_PRECISION)/MAX_SERVER_PRECISION;
    2724        }
    2825
  • src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r51 r52  
    55import java.beans.PropertyChangeListener;
    66import java.util.Collection;
     7import java.util.HashSet;
    78import java.util.Iterator;
    89import java.util.LinkedList;
     10import java.util.Set;
    911import java.util.Stack;
    1012
     
    218220         * really deleting all deleted objects and reset the modified flags. This is done
    219221         * after a successfull upload.
     222         *
    220223         * @param uploaded <code>true</code>, if the data was uploaded, false if saved to disk
    221          * @param dataAdded <code>true</code>, if data was added during the upload process.
    222          */
    223         public void cleanData(boolean uploaded, boolean dataAdded) {
     224         * @param processed A list of all objects, that were actually uploaded.
     225         *              May be <code>null</code>, which means nothing has been uploaded but
     226         *              saved to disk instead.
     227         */
     228        public void cleanData(Collection<OsmPrimitive> processed, boolean dataAdded) {
    224229                redoCommands.clear();
    225230                commands.clear();
    226                
     231
    227232                // if uploaded, clean the modified flags as well
    228                 if (uploaded) {
     233                if (processed != null) {
     234                        Set<OsmPrimitive> processedSet = new HashSet<OsmPrimitive>(processed);
    229235                        for (Iterator<Node> it = data.nodes.iterator(); it.hasNext();)
    230                                 cleanModifiedFlag(it);
     236                                cleanIterator(it, processedSet);
    231237                        for (Iterator<LineSegment> it = data.lineSegments.iterator(); it.hasNext();)
    232                                 cleanModifiedFlag(it);
     238                                cleanIterator(it, processedSet);
    233239                        for (Iterator<Track> it = data.tracks.iterator(); it.hasNext();)
    234                                 cleanModifiedFlag(it);
     240                                cleanIterator(it, processedSet);
    235241                }
    236                
     242
    237243                // update the modified flag
    238244               
    239                 if (fromDisk && uploaded && !dataAdded)
     245                if (fromDisk && processed != null && !dataAdded)
    240246                        return; // do nothing when uploading non-harmful changes.
    241247               
    242248                // modified if server changed the data (esp. the id).
    243                 uploadedModified = fromDisk && uploaded && dataAdded;
     249                uploadedModified = fromDisk && processed != null && dataAdded;
    244250                setModified(uploadedModified);
    245251                //TODO: Replace with listener scheme
     
    248254        }
    249255
    250         private void cleanModifiedFlag(Iterator<? extends OsmPrimitive> it) {
     256        /**
     257         * Clean the modified flag for the given iterator over a collection if it is in the
     258         * list of processed entries.
     259         *
     260         * @param it The iterator to change the modified and remove the items if deleted.
     261         * @param processed A list of all objects that have been successfully progressed.
     262         *              If the object in the iterator is not in the list, nothing will be changed on it.
     263         */
     264        private void cleanIterator(Iterator<? extends OsmPrimitive> it, Collection<OsmPrimitive> processed) {
    251265                OsmPrimitive osm = it.next();
     266                if (!processed.remove(osm))
     267                        return;
    252268                osm.modified = false;
    253269                osm.modifiedProperties = false;
  • src/org/openstreetmap/josm/io/OsmServerWriter.java

    r43 r52  
    1111import java.util.Collection;
    1212import java.util.HashMap;
     13import java.util.LinkedList;
    1314
    1415import org.jdom.Document;
     
    4142
    4243        /**
     44         * This list contain all sucessfull processed objects. The caller of
     45         * upload* has to check this after the call and update its dataset.
     46         *
     47         * If a server connection error occours, this may contain fewer entries
     48         * than where passed in the list to upload*.
     49         */
     50        public Collection<OsmPrimitive> processed;
     51       
     52        /**
    4353         * Send the dataset to the server. Ask the user first and does nothing if he
    4454         * does not want to send the data.
    4555         */
    4656        public void uploadOsm(Collection<OsmPrimitive> list) throws JDOMException {
     57                processed = new LinkedList<OsmPrimitive>();
    4758                initAuthentication();
    4859
     
    6778                        sendRequest("PUT", "node/" + n.id, n, true);
    6879                }
     80                processed.add(n);
    6981        }
    7082
     
    8193                        sendRequest("PUT", "segment/" + ls.id, ls, true);
    8294                }
     95                processed.add(ls);
    8396        }
    8497
     
    103116
    104117        /**
    105          * Read an long from the input stream and return it.
     118         * Read a long from the input stream and return it.
    106119         */
    107120        private long readId(InputStream inputStream) throws IOException {
     
    118131        }
    119132
     133        /**
     134         * Send the request. The objects id will be replaced if it was 0 before
     135         * (on add requests).
     136         *
     137         * @param requestMethod The http method used when talking with the server.
     138         * @param urlSuffix The suffix to add at the server url.
     139         * @param osm The primitive to encode to the server.
     140         * @param addBody <code>true</code>, if the whole primitive body should be added.
     141         *              <code>false</code>, if only the id is encoded.
     142         */
    120143        @SuppressWarnings("unchecked")
    121144        private void sendRequest(String requestMethod, String urlSuffix,
  • test/org/openstreetmap/josm/test/framework/DataSetTestCaseHelper.java

    r49 r52  
    4343         * Create a line segment with out of the given nodes.
    4444         */
    45         private static LineSegment createLineSegment(DataSet ds, Node n1, Node n2) {
     45        public static LineSegment createLineSegment(DataSet ds, Node n1, Node n2) {
    4646                LineSegment ls = new LineSegment(n1, n2);
    4747                ds.lineSegments.add(ls);
     
    5252         * Add a random node.
    5353         */
    54         private static Node createNode(DataSet ds) {
     54        public static Node createNode(DataSet ds) {
    5555                Node node = new Node();
    5656                node.coor = new GeoPoint(Math.random(), Math.random());
Note: See TracChangeset for help on using the changeset viewer.