Changeset 35 in josm


Ignore:
Timestamp:
2005-12-28T01:29:01+01:00 (18 years ago)
Author:
imi
Message:
  • fixed bug in UTM
  • upload of nodes and segments
  • fixed bugs in display the selection
Location:
src/org/openstreetmap/josm
Files:
1 added
1 deleted
19 edited

Legend:

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

    r34 r35  
    77import java.awt.event.InputEvent;
    88import java.awt.event.KeyEvent;
     9import java.io.FileNotFoundException;
    910import java.io.IOException;
    1011
     
    169170                        x.printStackTrace();
    170171                        JOptionPane.showMessageDialog(Main.main, x.getMessage());
     172                } catch (FileNotFoundException x) {
     173                        x.printStackTrace();
     174                        JOptionPane.showMessageDialog(Main.main, "URL nicht gefunden: "+x.getMessage());
    171175                } catch (IOException x) {
    172176                        x.printStackTrace();
  • src/org/openstreetmap/josm/actions/UploadAction.java

    r34 r35  
    1818import org.openstreetmap.josm.Main;
    1919import org.openstreetmap.josm.data.osm.OsmPrimitive;
     20import org.openstreetmap.josm.data.osm.Track;
    2021import org.openstreetmap.josm.gui.GBC;
    2122import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
     
    4142                Collection<OsmPrimitive> update = new LinkedList<OsmPrimitive>();
    4243                Collection<OsmPrimitive> delete = new LinkedList<OsmPrimitive>();
    43                 for (OsmPrimitive osm : Main.main.ds.nodes)
    44                         if (osm.id == 0)
     44                for (OsmPrimitive osm : Main.main.ds.allPrimitives()) {
     45                        if (osm instanceof Track) {
     46                                int answer = JOptionPane.showConfirmDialog(Main.main,
     47                                                "The server currently does not understand the concept of Tracks.\n" +
     48                                                "All tracks will be ignored on upload. Continue anyway?",
     49                                                "No Track support", JOptionPane.YES_NO_OPTION);
     50                                if (answer != JOptionPane.YES_OPTION)
     51                                        return;
     52                        }
     53                        if (osm.id == 0 && !osm.isDeleted())
    4554                                add.add(osm);
    46                         else if (osm.modified)
     55                        else if ((osm.modified || osm.modifiedProperties) && !osm.isDeleted())
    4756                                update.add(osm);
    48                 for (OsmPrimitive osm : Main.main.ds.lineSegments)
    49                         if (osm.id == 0)
    50                                 add.add(osm);
    51                         else if (osm.modified)
    52                                 update.add(osm);
    53                 for (OsmPrimitive osm : Main.main.ds.tracks)
    54                         if (osm.id == 0)
    55                                 add.add(osm);
    56                         else if (osm.modified)
    57                                 update.add(osm);
    58                 for (OsmPrimitive osm : Main.main.ds.deleted)
    59                         if (osm.id != 0)
     57                        else if (osm.isDeleted() && osm.id != 0)
    6058                                delete.add(osm);
     59                }
    6160
    6261                if (!displayUploadScreen(add, update, delete))
    6362                        return;
    64                
     63
    6564                OsmServerWriter server = new OsmServerWriter();
    6665                try {
     
    7069                        all.addAll(delete);
    7170                        server.uploadOsm(all);
     71                        // finished without errors -> clean dataset
     72                        Main.main.getMapFrame().mapView.editLayer().cleanData();
    7273                } catch (JDOMException x) {
    7374                        x.printStackTrace();
     
    8788                        return false;
    8889                }
    89                
     90
    9091                JPanel p = new JPanel(new GridBagLayout());
    9192
  • src/org/openstreetmap/josm/command/AddCommand.java

    r31 r35  
    66import org.openstreetmap.josm.data.osm.OsmPrimitive;
    77import org.openstreetmap.josm.data.osm.visitor.AddVisitor;
    8 import org.openstreetmap.josm.data.osm.visitor.DeleteVisitor;
    98
    109/**
     
    3938
    4039        public void undoCommand() {
    41                 osm.visit(new DeleteVisitor(ds));
     40                osm.setDeleted(true);
    4241        }
    4342
  • src/org/openstreetmap/josm/command/ChangeKeyValueCommand.java

    r33 r35  
    5555                for (OsmPrimitive osm : objects) {
    5656                        oldProperties.add(osm.keys == null ? null : new HashMap<Key, String>(osm.keys));
    57                         oldModified.add(osm.modified);
    58                         osm.modified = true;
     57                        oldModified.add(osm.modifiedProperties);
     58                        osm.modifiedProperties = true;
    5959                }
    6060
     
    8181                for (OsmPrimitive osm : objects) {
    8282                        osm.keys = it.next();
    83                         osm.modified = itMod.next();
     83                        osm.modifiedProperties = itMod.next();
    8484                }
    8585        }
  • src/org/openstreetmap/josm/command/DeleteCommand.java

    r31 r35  
    88import org.openstreetmap.josm.data.osm.visitor.AddVisitor;
    99import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor;
    10 import org.openstreetmap.josm.data.osm.visitor.DeleteVisitor;
    1110import org.openstreetmap.josm.data.osm.visitor.Visitor;
    1211
     
    3534       
    3635        public void executeCommand() {
    37                 Visitor v = new DeleteVisitor(ds);
    3836                for (OsmPrimitive osm : data)
    39                         osm.visit(v);
     37                        osm.setDeleted(true);
    4038        }
    4139
  • src/org/openstreetmap/josm/data/osm/DataSet.java

    r32 r35  
    22
    33import java.util.Collection;
    4 import java.util.HashMap;
    54import java.util.HashSet;
    65import java.util.LinkedList;
    7 import java.util.Map;
    86
    97import org.openstreetmap.josm.data.Bounds;
     
    4442
    4543        /**
    46          * All deleted objects goes here.
     44         * @return A collection containing all primitives (except keys) of the
     45         * dataset.
    4746         */
    48         public Collection<OsmPrimitive> deleted = new LinkedList<OsmPrimitive>();
    49 
     47        public Collection<OsmPrimitive> allPrimitives() {
     48                Collection<OsmPrimitive> o = new LinkedList<OsmPrimitive>();
     49                o.addAll(nodes);
     50                o.addAll(lineSegments);
     51                o.addAll(tracks);
     52                return o;
     53        }
     54       
    5055        /**
    5156         * Return the bounds of this DataSet, depending on X/Y values.
     
    133138
    134139        /**
    135          * Import the given dataset by merging all data with this dataset.
    136          * The objects imported are not cloned, so from now on, these data belong
    137          * to both datasets. So use mergeFrom only if you are about to abandon the
    138          * other dataset.
    139          *
    140          * Elements are tried to merged.
    141          * Nodes are merged first, if their lat/lon are equal.
    142          * Line segments are merged, if they have the same nodes.
    143          * Tracks are merged, if they consist of the same line segments.
    144          *
    145          * TODO Additional to that, every two objects with the same id are merged.
    146          *
    147          * @param ds    The DataSet to merge into this one.
    148          */
    149         public void mergeFrom(DataSet ds) {
    150                 // merge nodes
    151                
    152                 Map<Node, Node> nodeMap = new HashMap<Node, Node>();
    153 
    154                 // find mergable
    155                 for (Node otherNode : ds.nodes)
    156                         for (Node myNode : nodes)
    157                                 if (otherNode.coor.equalsLatLon(myNode.coor))
    158                                         nodeMap.put(otherNode, myNode);
    159                 // add
    160                 for (Node n : ds.nodes)
    161                         if (!nodeMap.containsKey(n))
    162                                 nodes.add(n);
    163                 // reassign
    164                 for (LineSegment ls : ds.lineSegments) {
    165                         Node n = nodeMap.get(ls.start);
    166                         if (n != null)
    167                                 ls.start = n;
    168                         n = nodeMap.get(ls.end);
    169                         if (n != null)
    170                                 ls.end = n;
    171                 }
    172 
    173 
    174                 // merge line segments
    175 
    176                 Map<LineSegment, LineSegment> lsMap = new HashMap<LineSegment, LineSegment>();
    177                 // find mergable
    178                 for (LineSegment otherLS : ds.lineSegments)
    179                         for (LineSegment myLS : lineSegments)
    180                                 if (otherLS.start == myLS.start && otherLS.end == myLS.end)
    181                                         lsMap.put(otherLS, myLS);
    182                 // add ls
    183                 for (LineSegment ls : ds.lineSegments)
    184                         if (!lsMap.containsKey(ls))
    185                                 lineSegments.add(ls);
    186                 // reassign
    187                 for (Track t : ds.tracks) {
    188                         for (int i = 0; i < t.segments.size(); ++i) {
    189                                 LineSegment newLS = lsMap.get(t.segments.get(i));
    190                                 if (newLS != null)
    191                                         t.segments.set(i, newLS);
    192                         }
    193                 }
    194 
    195 
    196                 // merge tracks
    197                
    198                 LinkedList<Track> trackToAdd = new LinkedList<Track>();
    199                 for (Track otherTrack : ds.tracks) {
    200                         boolean found = false;
    201                         for (Track myTrack : tracks) {
    202                                 if (myTrack.segments.equals(otherTrack.segments)) {
    203                                         found = true;
    204                                         break;
    205                                 }
    206                         }
    207                         if (!found)
    208                                 trackToAdd.add(otherTrack);
    209                 }
    210                 tracks.addAll(trackToAdd);
    211         }
    212 
    213         /**
    214140         * Remove the selection from every value in the collection.
    215141         * @param list The collection to remove the selection from.
     
    234160                        return sel;
    235161                for (OsmPrimitive osm : list) {
    236                         if (osm.isSelected())
     162                        if (osm.isSelected() && !osm.isDeleted())
    237163                                sel.add(osm);
    238164                        if (osm.keys != null)
  • src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r33 r35  
    1515abstract public class OsmPrimitive {
    1616
     17
    1718        /**
    1819         * The key/value list for this primitive.
     
    2829
    2930        /**
    30          * <code>true</code>, if the object has been modified since it was loaded from
    31          * the server. In this case, on next upload, this object will be updated. Deleted
    32          * objects are deleted from the server, even if they are modified. If the objects
    33          * are added (id=0), the modified is ignored and the object is added to the server.
     31         * <code>true</code>, if the objects content (not the properties) has been
     32         * modified since it was loaded from the server. In this case, on next upload,
     33         * this object will be updated. Deleted objects are deleted from the server.
     34         * If the objects are added (id=0), the modified is ignored and the object is
     35         * added to the server.
    3436         */
    3537        public boolean modified = false;
     38
     39        /**
     40         * <code>true</code>, if the object's keys has been changed by JOSM since
     41         * last update.
     42         */
     43        public boolean modifiedProperties = false;
    3644       
     45        /**
     46         * <code>true</code>, if the object has been deleted.
     47         */
     48        private boolean deleted = false;
     49
    3750        /**
    3851         * If set to true, this object is currently selected.
     
    89102
    90103
     104        public void setDeleted(boolean deleted) {
     105                this.deleted = deleted;
     106                setSelected(false);
     107        }
     108
     109        public boolean isDeleted() {
     110                return deleted;
     111        }
     112
    91113        /**
    92          * Equal, if the id is equal. If both ids are 0, use the super classes equal
    93          * instead.
     114         * Equal, if the id (and class) is equal. If both ids are 0, use the super classes
     115         * equal instead.
    94116         */
    95117        @Override
    96118        public boolean equals(Object obj) {
    97                 if (!(obj instanceof OsmPrimitive))
    98                         return false;
    99                 OsmPrimitive osm = (OsmPrimitive)obj;
    100                 if (id == 0 && osm.id == 0)
     119                if (getClass() != obj.getClass() || id == 0 || obj == null || ((OsmPrimitive)obj).id == 0)
    101120                        return super.equals(obj);
    102                 return id == osm.id;
     121                return id == ((OsmPrimitive)obj).id;
    103122        }
    104123
  • src/org/openstreetmap/josm/data/osm/visitor/AddVisitor.java

    r32 r35  
    2626        public void visit(Node n) {
    2727                ds.nodes.add(n);
    28                 ds.deleted.remove(n); // remove if there.
     28                n.setDeleted(false);
    2929        }
    3030        public void visit(LineSegment ls) {
    3131                ds.lineSegments.add(ls);
    32                 ds.deleted.remove(ls); // remove if there.
     32                ls.setDeleted(false);
    3333        }
    3434        public void visit(Track t) {
    3535                ds.tracks.add(t);
    36                 ds.deleted.remove(t); // remove if there.
     36                t.setDeleted(false);
    3737        }
    3838        public void visit(Key k) {}
  • src/org/openstreetmap/josm/data/osm/visitor/BoundingVisitor.java

    r23 r35  
    2121         * Calculate regarding lat/lon or x/y?
    2222         */
    23         public static enum Type {LATLON, XY};
     23        public static enum Type {LATLON, XY}
    2424        private Type type;
    25        
    26        
     25
     26
    2727        public BoundingVisitor(Type type) {
    2828                this.type = type;
  • src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java

    r30 r35  
    3030         */
    3131        private final MapView mv;
    32         /**
    33          * Can be set to non-<code>null</code> and then replace every other color.
    34          */
    35         private final Color forceColor;
    3632       
    3733        /**
     
    3935         * @param g   The graphics to draw to.
    4036         * @param mv  The view to get screen coordinates from.
    41          * @param forceColor If non-<code>null</code>, always draw with this color.
    4237         */
    43         public SimplePaintVisitor(Graphics g, MapView mv, Color forceColor) {
     38        public SimplePaintVisitor(Graphics g, MapView mv) {
    4439                this.g = g;
    4540                this.mv = mv;
    46                 this.forceColor = forceColor;
    4741        }
    4842       
     
    7064         */
    7165        public void visit(Track t) {
     66                // only to overwrite with blue
    7267                for (LineSegment ls : t.segments)
    73                         drawLineSegment(ls, darkblue);
     68                        if (!ls.isSelected()) // selected already in good color
     69                                drawLineSegment(ls, t.isSelected() ? Color.WHITE : darkblue);
    7470        }
    7571
     
    8884        private void drawNode(Node n, Color color) {
    8985                Point p = mv.getScreenPoint(n.coor);
    90                 g.setColor(forceColor != null ? forceColor : color);
     86                g.setColor(color);
    9187                g.drawRect(p.x-1, p.y-1, 2, 2);
    9288        }
     
    9692         */
    9793        private void drawLineSegment(LineSegment ls, Color col) {
    98                 if (forceColor != null)
    99                         col = forceColor;
    100                 else if (ls.isSelected())
     94                if (ls.isSelected())
    10195                        col = Color.WHITE;
    10296                g.setColor(col);
  • src/org/openstreetmap/josm/data/projection/UTM.java

    r23 r35  
    3939        public final static double RAD_TO_DEG = 180 / Math.PI;
    4040
     41        public final static double k0 = 0.9996012717;
     42       
    4143        /**
    4244         * A reference ellipsoid used in Projections
     
    116118                // Written by Chuck Gantz- chuck.gantz@globalstar.com
    117119                // ported to Ruby by Ben Gimpert- ben@somethingmodern.com
    118                 double k0 = 0.9996012717;
    119                
    120120                double lat_rad = p.lat * DEG_TO_RAD;
    121121                double long_temp = (p.lon + 180) - (Math.floor((p.lon + 180) / 360) * 360) - 180;
     
    150150                // Written by Chuck Gantz- chuck.gantz@globalstar.com
    151151                // ported to Ruby by Ben Gimpert- ben@somethingmodern.com
    152                 double k0 = 0.9996;
    153152                double e1 = (1-Math.sqrt(1-ellipsoid.ecc_squared))/(1+Math.sqrt(1-ellipsoid.ecc_squared));
    154153                double x = p.x - 500000.0;
  • src/org/openstreetmap/josm/gui/MapView.java

    r30 r35  
    253253                        return minPrimitive;
    254254               
    255                 // pending line segments
     255                // for whole tracks, try the tracks first
     256                minDistanceSq = Double.MAX_VALUE;
     257                if (wholeTrack) {
     258                        for (Track t : Main.main.ds.tracks) {
     259                                for (LineSegment ls : t.segments) {
     260                                        Point A = getScreenPoint(ls.start.coor);
     261                                        Point B = getScreenPoint(ls.end.coor);
     262                                        double c = A.distanceSq(B);
     263                                        double a = p.distanceSq(B);
     264                                        double b = p.distanceSq(A);
     265                                        double perDist = a-(a-b+c)*(a-b+c)/4/c; // perpendicular distance squared
     266                                        if (perDist < 100 && minDistanceSq > perDist && a < c+100 && b < c+100) {
     267                                                minDistanceSq = perDist;
     268                                                minPrimitive = t;
     269                                        }
     270                                }                       
     271                        }
     272                        if (minPrimitive != null)
     273                                return minPrimitive;
     274                }
     275               
     276                minDistanceSq = Double.MAX_VALUE;
     277                // line segments
    256278                for (LineSegment ls : Main.main.ds.lineSegments) {
    257279                        Point A = getScreenPoint(ls.start.coor);
     
    267289                }
    268290
    269                 // tracks & line segments
    270                 minDistanceSq = Double.MAX_VALUE;
    271                 for (Track t : Main.main.ds.tracks) {
    272                         for (LineSegment ls : t.segments) {
    273                                 Point A = getScreenPoint(ls.start.coor);
    274                                 Point B = getScreenPoint(ls.end.coor);
    275                                 double c = A.distanceSq(B);
    276                                 double a = p.distanceSq(B);
    277                                 double b = p.distanceSq(A);
    278                                 double perDist = a-(a-b+c)*(a-b+c)/4/c; // perpendicular distance squared
    279                                 if (perDist < 100 && minDistanceSq > perDist && a < c+100 && b < c+100) {
    280                                         minDistanceSq = perDist;
    281                                         minPrimitive = wholeTrack ? t : ls;
    282                                 }
    283                         }                       
    284                 }
    285                 if (minPrimitive != null)
    286                         return minPrimitive;
    287                
    288                 // TODO areas
    289                
    290                 return null; // nothing found
     291                return minPrimitive;
    291292        }
    292293
  • src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r32 r35  
    22
    33import java.awt.Graphics;
     4import java.util.Iterator;
    45import java.util.LinkedList;
    56import java.util.Stack;
     
    1314import org.openstreetmap.josm.data.osm.LineSegment;
    1415import org.openstreetmap.josm.data.osm.Node;
     16import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1517import org.openstreetmap.josm.data.osm.Track;
    1618import org.openstreetmap.josm.data.osm.visitor.BoundingVisitor;
     19import org.openstreetmap.josm.data.osm.visitor.MergeVisitor;
    1720import org.openstreetmap.josm.data.osm.visitor.SimplePaintVisitor;
    1821import org.openstreetmap.josm.data.projection.Projection;
     
    7073        @Override
    7174        public void paint(Graphics g, MapView mv) {
    72                 SimplePaintVisitor visitor = new SimplePaintVisitor(g, mv, null);
    73 
    74                 for (LineSegment ls : data.lineSegments)
    75                         visitor.visit(ls);
    76                 for (Track t : data.tracks)
    77                         visitor.visit(t);
    78                 for (Node n : data.nodes)
    79                         visitor.visit(n);
     75                SimplePaintVisitor visitor = new SimplePaintVisitor(g, mv);
     76                for (OsmPrimitive osm : data.lineSegments)
     77                        if (!osm.isDeleted())
     78                                osm.visit(visitor);
     79                for (OsmPrimitive osm : data.tracks)
     80                        if (!osm.isDeleted())
     81                                osm.visit(visitor);
     82                for (OsmPrimitive osm : data.nodes)
     83                        if (!osm.isDeleted())
     84                                osm.visit(visitor);
    8085        }
    8186
     
    8792        @Override
    8893        public void mergeFrom(Layer from) {
    89                 data.mergeFrom(((OsmDataLayer)from).data);
     94                MergeVisitor visitor = new MergeVisitor(data);
     95                for (OsmPrimitive osm : ((OsmDataLayer)from).data.allPrimitives())
     96                        osm.visit(visitor);
    9097        }
    9198
     
    163170                Main.main.redoAction.setEnabled(!redoCommands.isEmpty());
    164171        }
     172
     173        /**
     174         * Clean out the data behind the layer. This means clearing the redo/undo lists,
     175         * really deleting all deleted objects and reset the modified flags. This is done
     176         * after a successfull upload.
     177         */
     178        public void cleanData() {
     179                redoCommands.clear();
     180                commands.clear();
     181                for (Iterator<Node> it = data.nodes.iterator(); it.hasNext();)
     182                        cleanIterator(it);
     183                for (Iterator<LineSegment> it = data.lineSegments.iterator(); it.hasNext();)
     184                        cleanIterator(it);
     185                for (Iterator<Track> it = data.tracks.iterator(); it.hasNext();)
     186                        cleanIterator(it);
     187        }
     188
     189        private void cleanIterator(Iterator<? extends OsmPrimitive> it) {
     190                OsmPrimitive osm = it.next();
     191                osm.modified = false;
     192                osm.modifiedProperties = false;
     193                if (osm.isDeleted())
     194                        it.remove();
     195        }
    165196}
  • src/org/openstreetmap/josm/io/GpxReader.java

    r33 r35  
    190190                                osm.id = Long.parseLong(idElement.getText());
    191191                        osm.modified = e.getChild("modified", JOSM) != null;
     192                        osm.modifiedProperties = e.getChild("modifiedProperties", JOSM) != null;
    192193                }
    193194        }
  • src/org/openstreetmap/josm/io/GpxWriter.java

    r33 r35  
    242242        @SuppressWarnings("unchecked")
    243243        private void addPropertyExtensions(Element e, Map<Key, String> keys, OsmPrimitive osm) {
    244                 if ((keys == null || keys.isEmpty()) && osm.id == 0 && !osm.modified)
     244                if ((keys == null || keys.isEmpty()) && osm.id == 0 && !osm.modified && !osm.modifiedProperties)
    245245                        return;
    246246                Element extensions = e.getChild("extensions", GPX);
     
    255255                        }
    256256                }
    257                 // id
    258257                if (osm.id != 0) {
    259258                        Element propElement = new Element("uid", JOSM);
     
    261260                        extensions.getChildren().add(propElement);
    262261                }
    263                 // modified
    264262                if (osm.modified) {
    265263                        Element modElement = new Element("modified", JOSM);
    266264                        extensions.getChildren().add(modElement);
    267265                }
     266                if (osm.modifiedProperties) {
     267                        Element modElement = new Element("modifiedProperties", JOSM);
     268                        extensions.getChildren().add(modElement);
     269                }
    268270        }
    269271}
  • src/org/openstreetmap/josm/io/OsmReader.java

    r33 r35  
    104104                for (Object o : e.getChildren()) {
    105105                        Element child = (Element)o;
    106                         if (child.getName().equals("deleted"))
    107                                 for (Object delObj : child.getChildren())
    108                                         data.deleted.add(parseObject((Element)delObj, data));
    109                         else {
     106                        if (child.getName().equals("deleted")) {
     107                                for (Object delObj : child.getChildren()) {
     108                                        OsmPrimitive osm = parseObject((Element)delObj, data);
     109                                        if (osm != null) {
     110                                                osm.visit(visitor);
     111                                                osm.setDeleted(true);
     112                                        }
     113                                }
     114                        } else {
    110115                                OsmPrimitive osm = parseObject(child, data);
    111116                                if (osm != null)
     
    200205                OsmPrimitive osm = findObject(data, id);
    201206                Key key = Key.get(e.getAttributeValue("key"));
    202                 String value =e.getAttributeValue("value");
     207                String value = e.getAttributeValue("value");
    203208                if (value != null) {
    204209                        if (osm.keys == null)
     
    221226                        if (osm.id == id)
    222227                                return osm;
    223                 for (OsmPrimitive osm : data.deleted)
    224                         if (osm.id == id)
    225                                 return osm;
    226228                throw new JDOMException("Unknown object reference: "+id);
    227229        }
  • src/org/openstreetmap/josm/io/OsmServerReader.java

    r34 r35  
    9393        private Reader getReader(String urlStr) throws IOException {
    9494                initAuthentication();
    95                 System.out.println(urlStr);
    9695                URL url = new URL(urlStr);
    9796                HttpURLConnection con = (HttpURLConnection)url.openConnection();
  • src/org/openstreetmap/josm/io/OsmServerWriter.java

    r34 r35  
    2727 * Class that uploades all changes to the osm server.
    2828 *
    29  * This is done like this:
    30  * - All objects with id = 0 are uploaded as new, except those in deleted,
    31  *   which are ignored
    32  * - All objects in deleted list are deleted.
    33  * - All remaining objects with modified flag set are updated.
     29 * This is done like this: - All objects with id = 0 are uploaded as new, except
     30 * those in deleted, which are ignored - All objects in deleted list are
     31 * deleted. - All remaining objects with modified flag set are updated.
    3432 *
    35  * This class implements visitor and will perform the correct upload action
    36  * on the visited element.
     33 * This class implements visitor and will perform the correct upload action on
     34 * the visited element.
    3735 *
    3836 * @author imi
     
    4139
    4240        /**
    43          * Send the dataset to the server. Ask the user first and does nothing if
    44          * he does not want to send the data.
     41         * Send the dataset to the server. Ask the user first and does nothing if he
     42         * does not want to send the data.
    4543         */
    4644        public void uploadOsm(Collection<OsmPrimitive> list) throws JDOMException {
     
    4846
    4947                try {
    50 //                      for (OsmPrimitive osm : list)
    51 //                              osm.visit(this);
     48                        for (OsmPrimitive osm : list)
     49                                osm.visit(this);
    5250                } catch (RuntimeException e) {
    5351                        throw new JDOMException("An error occoured: ", e);
     
    6058        @SuppressWarnings("unchecked")
    6159        public void visit(Node n) {
    62                 if (n.id == 0) {
    63                         sendRequest("PUT", "newnode", n);
    64                 } else if (Main.main.ds.deleted.contains(n)) {
    65                         sendRequest("DELETE", "node/"+n.id, n);
     60                if (n.id == 0 && !n.isDeleted()) {
     61                        sendRequest("PUT", "newnode", n, true);
     62                } else if (n.isDeleted()) {
     63                        sendRequest("DELETE", "node/" + n.id, n, false);
    6664                } else {
    67                         sendRequest("PUT", "node/"+n.id, n);
     65                        sendRequest("PUT", "node/" + n.id, n, true);
    6866                }
    6967        }
    7068
    7169        public void visit(LineSegment ls) {
     70                if (ls.id == 0 && !ls.isDeleted()) {
     71                        sendRequest("PUT", "newsegment", ls, true);
     72                } else if (ls.isDeleted()) {
     73                        sendRequest("DELETE", "segment/" + ls.id, ls, false);
     74                } else {
     75                        sendRequest("PUT", "segment/" + ls.id, ls, true);
     76                }
    7277        }
    7378
    7479        public void visit(Track t) {
     80                // not implemented in server
    7581        }
    7682
    7783        public void visit(Key k) {
     84                // not implemented in server
    7885        }
    7986
     
    8289         */
    8390        private long readId(InputStream inputStream) throws IOException {
    84                 BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
     91                BufferedReader in = new BufferedReader(new InputStreamReader(
     92                                inputStream));
    8593                String s = in.readLine();
    8694                if (s == null)
     
    92100                }
    93101        }
    94        
     102
    95103        @SuppressWarnings("unchecked")
    96         private void sendRequest(String requestMethod, String urlSuffix, OsmPrimitive osm) {
     104        private void sendRequest(String requestMethod, String urlSuffix,
     105                        OsmPrimitive osm, boolean addBody) {
    97106                try {
    98107                        URL url = new URL(Main.pref.osmDataServer + "/" + urlSuffix);
    99                         HttpURLConnection con = (HttpURLConnection)url.openConnection();
     108                        HttpURLConnection con = (HttpURLConnection) url.openConnection();
    100109                        con.setConnectTimeout(20000);
    101110                        con.setRequestMethod(requestMethod);
    102                         con.setDoOutput(true);
     111                        if (addBody)
     112                                con.setDoOutput(true);
    103113                        con.connect();
    104114
    105                         OsmXmlVisitor visitor = new OsmXmlVisitor(false);
    106                         osm.visit(visitor);
    107                         Element root = new Element("osm");
    108                         root.setAttribute("version", "0.2");
    109                         root.getChildren().add(visitor.element);
    110                         XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
    111                         OutputStream out = con.getOutputStream();
    112                         Document doc = new Document(root);
    113                         xmlOut.output(doc, out);
    114                         xmlOut.output(doc, System.out);
    115                         out.close();
    116                        
     115                        if (addBody) {
     116                                OsmXmlVisitor visitor = new OsmXmlVisitor(false);
     117                                osm.visit(visitor);
     118                                Element root = new Element("osm");
     119                                root.setAttribute("version", "0.2");
     120                                root.getChildren().add(visitor.element);
     121                                XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
     122                                OutputStream out = con.getOutputStream();
     123                                Document doc = new Document(root);
     124                                xmlOut.output(doc, out);
     125                                xmlOut.output(doc, System.out);
     126                                out.close();
     127                        }
     128
    117129                        int retCode = con.getResponseCode();
    118                         System.out.println(retCode+" "+con.getResponseMessage());
    119130                        if (retCode == 200 && osm.id == 0)
    120131                                osm.id = readId(con.getInputStream());
  • src/org/openstreetmap/josm/io/OsmWriter.java

    r33 r35  
    6363                List<Element> list = root.getChildren();
    6464                properties = new LinkedList<Element>();
    65                 for (Node n : ds.nodes) {
    66                         visit(n);
    67                         list.add(element);
    68                 }
    69                 for (LineSegment ls : ds.lineSegments) {
    70                         visit(ls);
    71                         list.add(element);
    72                 }
    73                 for (Track t : ds.tracks) {
    74                         visit(t);
    75                         list.add(element);
     65                for (OsmPrimitive osm : ds.allPrimitives()) {
     66                        if (!osm.isDeleted()) {
     67                                osm.visit(this);
     68                                list.add(element);
     69                        }
    7670                }
    7771                list.addAll(properties);
     
    7973                Element deleted = new Element("deleted");
    8074                Collection<Element> allDeleted = deleted.getChildren();
    81                 for (OsmPrimitive osm : ds.deleted) {
    82                         osm.visit(this);
    83                         allDeleted.add(element);
     75                for (OsmPrimitive osm : ds.allPrimitives()) {
     76                        if (osm.isDeleted()) {
     77                                osm.visit(this);
     78                                allDeleted.add(element);
     79                        }
    8480                }
    8581                allDeleted.addAll(properties);
Note: See TracChangeset for help on using the changeset viewer.