Ignore:
Timestamp:
2018-11-27T21:40:10+01:00 (5 years ago)
Author:
Don-vip
Message:

fix #16995 - de-duplicate storage of timestamp within WayPoint and refactor some methods, added documentation, added some robustness against legacy code (will also log a warning if detected). Patch by cmuelle8, modified

Location:
trunk/src/org/openstreetmap/josm/gui/layer
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r14434 r14456  
    801801                wpt.setTimeInMillis(time);
    802802            } else if (n.hasKey(GpxConstants.PT_TIME)) {
    803                 wpt.setTime(DateUtils.fromString(n.get(GpxConstants.PT_TIME)));
     803                wpt.setTimeInMillis(DateUtils.tsFromString(n.get(GpxConstants.PT_TIME)));
    804804            } else if (!n.isTimestampEmpty()) {
    805805                wpt.setTime(Integer.toUnsignedLong(n.getRawTimestamp()));
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java

    r14212 r14456  
    12301230            for (GpxTrackSegment segment : trk.getSegments()) {
    12311231                for (WayPoint curWp : segment.getWayPoints()) {
    1232                     final Date parsedTime = curWp.setTimeFromAttribute();
    1233                     if (parsedTime != null) {
    1234                         firstGPXDate = parsedTime.getTime();
     1232                    if (curWp.hasDate()) {
     1233                        firstGPXDate = curWp.getTimeInMillis();
    12351234                        break outer;
    12361235                    }
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java

    r14451 r14456  
    509509                            continue;
    510510                        }
    511                         if (oldWp != null && trkPnt.time > oldWp.time) {
     511                        if (oldWp != null && trkPnt.getTimeInMillis() > oldWp.getTimeInMillis()) {
    512512                            double vel = trkPnt.getCoor().greatCircleDistance(oldWp.getCoor())
    513                                     / (trkPnt.time - oldWp.time);
     513                                    / (trkPnt.getTime() - oldWp.getTime());
    514514                            velocities.add(vel);
    515515                        }
     
    587587                    switch (colored) {
    588588                    case VELOCITY:
    589                         double dtime = trkPnt.time - oldWp.time;
     589                        double dtime = trkPnt.getTime() - oldWp.getTime();
    590590                        if (dtime > 0) {
    591591                            color = velocityScale.getColor(dist / dtime);
     
    599599                        break;
    600600                    case TIME:
    601                         double t = trkPnt.time;
     601                        double t = trkPnt.getTime();
    602602                        // skip bad timestamps and very short tracks
    603603                        if (t > 0 && t <= now && maxval - minval > minTrackDurationForTimeColoring) {
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ImportAudioAction.java

    r14302 r14456  
    150150                for (GpxTrackSegment seg : track.getSegments()) {
    151151                    for (WayPoint w : seg.getWayPoints()) {
    152                         firstTime = w.time;
     152                        firstTime = w.getTime();
    153153                        break;
    154154                    }
     
    175175        if (hasWaypoints && Config.getPref().getBoolean("marker.audiofromexplicitwaypoints", true)) {
    176176            for (WayPoint w : layer.data.waypoints) {
    177                 if (w.time > firstTime) {
     177                if (w.getTime() > firstTime) {
    178178                    waypoints.add(w);
    179                 } else if (w.time > 0.0) {
     179                } else if (w.getTime() > 0.0) {
    180180                    timedMarkersOmitted = true;
    181181                }
     
    192192                if (wNear != null) {
    193193                    WayPoint wc = new WayPoint(w.getCoor());
    194                     wc.time = wNear.time;
     194                    wc.setTimeInMillis(wNear.getTimeInMillis());
    195195                    if (w.attr.containsKey(GpxConstants.GPX_NAME)) {
    196196                        wc.put(GpxConstants.GPX_NAME, w.getString(GpxConstants.GPX_NAME));
     
    230230                for (GpxTrackSegment seg : track.getSegments()) {
    231231                    for (WayPoint w : seg.getWayPoints()) {
    232                         if (startTime < w.time) {
     232                        if (startTime < w.getTime()) {
    233233                            w2 = w;
    234234                            break;
     
    246246            } else {
    247247                wayPointFromTimeStamp = new WayPoint(w1.getCoor().interpolate(w2.getCoor(),
    248                         (startTime - w1.time) / (w2.time - w1.time)));
    249                 wayPointFromTimeStamp.time = startTime;
     248                        (startTime - w1.getTime()) / (w2.getTime() - w1.getTime())));
     249                wayPointFromTimeStamp.setTimeInMillis((long) (startTime * 1000));
    250250                String name = audioFile.getName();
    251251                int dot = name.lastIndexOf('.');
     
    268268                        WayPoint wStart = new WayPoint(w.getCoor());
    269269                        wStart.put(GpxConstants.GPX_NAME, "start");
    270                         wStart.time = w.time;
     270                        wStart.setTimeInMillis(w.getTimeInMillis());
    271271                        waypoints.add(wStart);
    272272                        gotOne = true;
     
    284284
    285285        // we must have got at least one waypoint now
    286         ((ArrayList<WayPoint>) waypoints).sort(Comparator.comparingDouble(o -> o.time));
     286        ((ArrayList<WayPoint>) waypoints).sort((wp, other) -> wp.compareTo(other));
    287287
    288288        firstTime = -1.0; // this time of the first waypoint, not first trackpoint
    289289        for (WayPoint w : waypoints) {
    290290            if (firstTime < 0.0) {
    291                 firstTime = w.time;
    292             }
    293             double offset = w.time - firstTime;
    294             AudioMarker am = new AudioMarker(w.getCoor(), w, url, ml, w.time, offset);
     291                firstTime = w.getTime();
     292            }
     293            double offset = w.getTime() - firstTime;
     294            AudioMarker am = new AudioMarker(w.getCoor(), w, url, ml, w.getTime(), offset);
    295295            // timeFromAudio intended for future use to shift markers of this type on synchronization
    296296            if (w == wayPointFromTimeStamp) {
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java

    r14447 r14456  
    256256    public WayPoint convertToWayPoint() {
    257257        WayPoint wpt = new WayPoint(getCoor());
    258         wpt.setTime((long) (time*1000));
     258        wpt.setTimeInMillis((long) (time * 1000));
    259259        if (text != null) {
    260260            wpt.addExtension("text", text);
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java

    r14153 r14456  
    9797        for (WayPoint wpt : indata.waypoints) {
    9898            /* calculate time differences in waypoints */
    99             double time = wpt.time;
     99            double time = wpt.getTime();
    100100            boolean wptHasLink = wpt.attr.containsKey(GpxConstants.META_LINKS);
    101101            if (firstTime < 0 && wptHasLink) {
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/PlayHeadMarker.java

    r14153 r14456  
    167167                if (m instanceof AudioMarker) {
    168168                    AudioMarker a = (AudioMarker) m;
    169                     if (a.time > cw.time) {
     169                    if (a.time > cw.getTime()) {
    170170                        break;
    171171                    }
     
    188188            if (cw != null) {
    189189                setCoor(cw.getCoor());
    190                 ca.play(cw.time - ca.time);
     190                ca.play(cw.getTime() - ca.time);
    191191            }
    192192            endDrag(false);
     
    245245                return;
    246246            }
    247             ca = recent.parentLayer.addAudioMarker(cw.time, cw.getCoor());
     247            ca = recent.parentLayer.addAudioMarker(cw.getTime(), cw.getCoor());
    248248        }
    249249
     
    330330            for (GpxTrackSegment trackseg : track.getSegments()) {
    331331                for (WayPoint w: trackseg.getWayPoints()) {
    332                     if (audioTime < w.time) {
     332                    if (audioTime < w.getTime()) {
    333333                        w2 = w;
    334334                        break;
     
    350350                w1.getEastNorth(ProjectionRegistry.getProjection()) :
    351351                    w1.getEastNorth(ProjectionRegistry.getProjection()).interpolate(w2.getEastNorth(ProjectionRegistry.getProjection()),
    352                             (audioTime - w1.time)/(w2.time - w1.time)));
     352                            (audioTime - w1.getTime())/(w2.getTime() - w1.getTime())));
    353353        time = audioTime;
    354354        MapView mapView = MainApplication.getMap().mapView;
Note: See TracChangeset for help on using the changeset viewer.