Ignore:
Timestamp:
2010-01-30T20:04:10+01:00 (12 years ago)
Author:
jttt
Message:

Gpx refactoring - GpxTrack and GpxTrackSegment is now interface, implementations for specific use can be provided (currently JOSM supports immutable gpx track, livegps plugin supports append only track).

  • track length and bounds are precalculated
  • GpxLayer paints only currently visible segments
Location:
trunk/src/org/openstreetmap/josm/io
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/GpxReader.java

    r2801 r2907  
    1111import java.util.ArrayList;
    1212import java.util.Collection;
     13import java.util.HashMap;
    1314import java.util.LinkedList;
    1415import java.util.List;
     
    2324import org.openstreetmap.josm.data.gpx.GpxLink;
    2425import org.openstreetmap.josm.data.gpx.GpxRoute;
    25 import org.openstreetmap.josm.data.gpx.GpxTrack;
     26import org.openstreetmap.josm.data.gpx.ImmutableGpxTrack;
    2627import org.openstreetmap.josm.data.gpx.WayPoint;
    2728import org.xml.sax.Attributes;
     
    4748
    4849        private GpxData currentData;
    49         private GpxTrack currentTrack;
     50        private Collection<Collection<WayPoint>> currentTrack;
     51        private Map<String, Object> currentTrackAttr;
    5052        private Collection<WayPoint> currentTrackSeg;
    5153        private GpxRoute currentRoute;
     
    100102                    states.push(currentState);
    101103                    currentState = State.trk;
    102                     currentTrack = new GpxTrack();
     104                    currentTrack = new ArrayList<Collection<WayPoint>>();
     105                    currentTrackAttr = new HashMap<String, Object>();
    103106                } else if (qName.equals("extensions")) {
    104107                    states.push(currentState);
     
    207210            case metadata: return currentData.attr;
    208211            case wpt: return currentWayPoint.attr;
    209             case trk: return currentTrack.attr;
     212            case trk: return currentTrackAttr;
    210213            default: return null;
    211214            }
     
    303306                if (qName.equals("trkseg")) {
    304307                    currentState = states.pop();
    305                     currentTrack.trackSegs.add(currentTrackSeg);
     308                    currentTrack.add(currentTrackSeg);
    306309                }
    307310                break;
     
    309312                if (qName.equals("trk")) {
    310313                    currentState = states.pop();
    311                     currentData.tracks.add(currentTrack);
     314                    currentData.tracks.add(new ImmutableGpxTrack(currentTrack, currentTrackAttr));
    312315                } else if (qName.equals("name") || qName.equals("cmt")
    313316                        || qName.equals("desc") || qName.equals("src")
    314317                        || qName.equals("type") || qName.equals("number")
    315318                        || qName.equals("url")) {
    316                     currentTrack.attr.put(qName, accumulator.toString());
     319                    currentTrackAttr.put(qName, accumulator.toString());
    317320                }
    318321                break;
  • trunk/src/org/openstreetmap/josm/io/GpxWriter.java

    r2620 r2907  
    1818import org.openstreetmap.josm.data.gpx.GpxRoute;
    1919import org.openstreetmap.josm.data.gpx.GpxTrack;
     20import org.openstreetmap.josm.data.gpx.GpxTrackSegment;
    2021import org.openstreetmap.josm.data.gpx.WayPoint;
    2122
     
    161162        for (GpxTrack trk : data.tracks) {
    162163            open("trk");
    163             writeAttr(trk.attr);
    164             for (Collection<WayPoint> seg : trk.trackSegs) {
     164            writeAttr(trk.getAttributes());
     165            for (GpxTrackSegment seg : trk.getSegments()) {
    165166                openln("trkseg");
    166                 for (WayPoint pnt : seg) {
     167                for (WayPoint pnt : seg.getWayPoints()) {
    167168                    wayPoint(pnt, TRACK_POINT);
    168169                }
  • trunk/src/org/openstreetmap/josm/io/NmeaReader.java

    r2676 r2907  
    1212import java.util.ArrayList;
    1313import java.util.Collection;
     14import java.util.Collections;
    1415import java.util.Date;
    1516
    1617import org.openstreetmap.josm.data.coor.LatLon;
    1718import org.openstreetmap.josm.data.gpx.GpxData;
    18 import org.openstreetmap.josm.data.gpx.GpxTrack;
     19import org.openstreetmap.josm.data.gpx.ImmutableGpxTrack;
    1920import org.openstreetmap.josm.data.gpx.WayPoint;
    2021import org.openstreetmap.josm.tools.DateUtils;
     
    173174        // create the data tree
    174175        data = new GpxData();
    175         GpxTrack currentTrack = new GpxTrack();
    176         data.tracks.add(currentTrack);
     176        Collection<Collection<WayPoint>> currentTrack = new ArrayList<Collection<WayPoint>>();
    177177
    178178        try {
     
    207207            }
    208208            rd.close();
    209             currentTrack.trackSegs.add(ps.waypoints);
     209            currentTrack.add(ps.waypoints);
     210            data.tracks.add(new ImmutableGpxTrack(currentTrack, Collections.<String, Object>emptyMap()));
    210211            data.recalculateBounds();
    211212
Note: See TracChangeset for help on using the changeset viewer.