Changeset 813 in josm for trunk/src


Ignore:
Timestamp:
2008-08-21T00:34:53+02:00 (16 years ago)
Author:
stoecker
Message:

support of Garmin time stamps in GPX import. patch by Roland Ramthun

Location:
trunk/src/org/openstreetmap/josm
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r805 r813  
    206206        private Collection<OsmPrimitive> getNearestCollectionVirtual(Point p) {
    207207                MapView c = Main.map.mapView;
     208                int snapDistance = Main.pref.getInteger("mappaint.node.virtual-snap-distance", 8);
     209                snapDistance *= snapDistance;
    208210                OsmPrimitive osm = c.getNearestNode(p);
    209211                if (osm == null)
     
    220222                                        int xd = p2.x-p1.x; if(xd < 0) xd = -xd;
    221223                                        int yd = p2.y-p1.y; if(yd < 0) yd = -yd;
    222                                         if(xd+yd > Main.pref.getInteger("mappaint.node.virtual-space", 50))
     224                                        if(xd+yd > Main.pref.getInteger("mappaint.node.virtual-space", 70))
    223225                                        {
    224226                                                Point pc = new Point((p1.x+p2.x)/2, (p1.y+p2.y)/2);
    225                                                 if(p.distanceSq(pc) < Main.map.mapView.snapDistance)
     227                                                if(p.distanceSq(pc) < snapDistance)
    226228                                                {
    227229                                                        Collection<Command> cmds = new LinkedList<Command>();
  • trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java

    r748 r813  
    3535         * Convert the time stamp of the waypoint into seconds from the epoch
    3636         */
    37         public void setTime () {
     37        public void setTime() {
    3838                if (! attr.containsKey("time")) {
    39                         time = 0.0;
    4039                        return;
    4140                }
    4241                SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); // ignore timezone
    4342                Date d = f.parse(attr.get("time").toString(), new ParsePosition(0));
    44                 if (d == null /* failed to parse */) {
    45                         time = 0.0;
    46                 } else {
     43                if (d != null /* parsing ok */) {
     44                        time = d.getTime() / 1000.0; /* ms => seconds */
     45                }
     46        }
     47
     48        /**
     49         * Convert a time stamp of the waypoint from the <cmt> or <desc> field
     50         * into seconds from the epoch. Handles the date format as it is used by
     51         * Garmin handhelds. Does not overwrite an existing timestamp (!= 0.0).
     52         * A value of <time> fields overwrites values set with by method.
     53         * Does nothing if specified key does not exist or text cannot be parsed.
     54         *
     55         * @param key The key that contains the text to convert.
     56         */
     57        public void setGarminCommentTime(String key) {
     58                // do not overwrite time if already set
     59                if (time != 0.0) {
     60                        return;
     61                }
     62                if (! attr.containsKey(key)) {
     63                        return;
     64                }
     65                // example date format "18-AUG-08 13:33:03"
     66                SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yy HH:mm:ss"); // Garmin wpts have no timezone
     67                Date d = f.parse(attr.get(key).toString(), new ParsePosition(0));
     68                if (d != null /* parsing OK */) {
    4769                        time = d.getTime() / 1000.0; /* ms => seconds */
    4870                }
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java

    r805 r813  
    108108                fillUnselectedNode = Main.pref.getBoolean("mappaint.node.fill-unselected", false);
    109109                virtualNodeSize = virtual ? Main.pref.getInteger("mappaint.node.virtual-size", 4) / 2 : 0;
    110                 virtualNodeSpace = Main.pref.getInteger("mappaint.node.virtual-space", 50);
     110                virtualNodeSpace = Main.pref.getInteger("mappaint.node.virtual-space", 70);
    111111
    112112                ((Graphics2D)g)
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r804 r813  
    8181        private Color computeCacheColorUsed;
    8282        private boolean computeCacheColored;
    83        
     83
    8484        public GpxLayer(GpxData d) {
    8585                super((String) d.attr.get("name"));
     
    162162                                        for (Collection<WayPoint> seg : track.trackSegs)
    163163                                                for (WayPoint point : seg)
    164                                                         if (point.attr.containsKey("name") || point.attr.containsKey("desc")) 
     164                                                        if (point.attr.containsKey("name") || point.attr.containsKey("desc"))
    165165                                                                namedTrackPoints.waypoints.add(point);
    166166
    167                     MarkerLayer ml = new MarkerLayer(namedTrackPoints, tr("Named Trackpoints from {0}", name), associatedFile, me);
    168                     if (ml.data.size() > 0) {
    169                         Main.main.addLayer(ml);
    170                     }
     167                                MarkerLayer ml = new MarkerLayer(namedTrackPoints, tr("Named Trackpoints from {0}", name), associatedFile, me);
     168                                if (ml.data.size() > 0) {
     169                                        Main.main.addLayer(ml);
     170                                }
    171171                        }
    172172                });
     
    191191                                if(fc.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) {
    192192                                        if (!fc.getCurrentDirectory().getAbsolutePath().equals(dir))
    193                                                 Main.pref.put("markers.lastaudiodirectory", fc
    194                                                                 .getCurrentDirectory().getAbsolutePath());
    195                                        
    196                                         // FIXME: properly support multi-selection here.
     193                                                Main.pref.put("markers.lastaudiodirectory", fc.getCurrentDirectory().getAbsolutePath());
     194
     195                                        // FIXME: properly support multi-selection here.
    197196                                        // Calling importAudio several times just creates N maker layers, which
    198197                                        // is sub-optimal.
    199198                                        File sel[] = fc.getSelectedFiles();
    200199                                        if(sel != null)
    201                                                 for (int i = 0; i < sel.length; i++) 
     200                                                for (int i = 0; i < sel.length; i++)
    202201                                                        importAudio(sel[i]);
    203                                        
     202
    204203                                        Main.map.repaint();
    205204                                }
     
    256255                                new JMenuItem(new LayerListPopup.InfoAction(this))};
    257256                return new Component[] {
    258                                 new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
    259                                 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
    260                                 new JSeparator(),
    261                                 new JMenuItem(new SaveAction(this)),
    262                                 new JMenuItem(new SaveAsAction(this)),
    263                                 // new JMenuItem(new UploadTraceAction()),
    264                                 color,
    265                                 line,
    266                                 tagimage,
    267                                 importAudio,
    268                                 markersFromNamedTrackpoints,
    269                                 new JMenuItem(new ConvertToDataLayerAction()),
    270                                 new JSeparator(),
    271                                 new JMenuItem(new RenameLayerAction(associatedFile, this)),
    272                                 new JSeparator(),
    273                                 new JMenuItem(new LayerListPopup.InfoAction(this))};
     257                        new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
     258                        new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
     259                        new JSeparator(),
     260                        new JMenuItem(new SaveAction(this)),
     261                        new JMenuItem(new SaveAsAction(this)),
     262                        // new JMenuItem(new UploadTraceAction()),
     263                        color,
     264                        line,
     265                        tagimage,
     266                        importAudio,
     267                        markersFromNamedTrackpoints,
     268                        new JMenuItem(new ConvertToDataLayerAction()),
     269                        new JSeparator(),
     270                        new JMenuItem(new RenameLayerAction(associatedFile, this)),
     271                        new JSeparator(),
     272                        new JMenuItem(new LayerListPopup.InfoAction(this))};
    274273        }
    275274
     
    278277
    279278                info.append(trn("{0} track, ", "{0} tracks, ",
    280                                 data.tracks.size(), data.tracks.size()))
    281                         .append(trn("{0} route, ", "{0} routes, ",
    282                                 data.routes.size(), data.routes.size()))
    283                         .append(trn("{0} waypoint", "{0} waypoints",
    284                                 data.waypoints.size(), data.waypoints.size()))
    285                         .append("<br>");
     279                data.tracks.size(), data.tracks.size())).append(trn("{0} route, ", "{0} routes, ",
     280                data.routes.size(), data.routes.size())).append(trn("{0} waypoint", "{0} waypoints",
     281                data.waypoints.size(), data.waypoints.size())).append("<br>");
    286282
    287283                if (data.attr.containsKey("name"))
    288                         info.append(tr("Name: {0}", data.attr.get("name")))
    289                                 .append("<br>");
     284                        info.append(tr("Name: {0}", data.attr.get("name"))).append("<br>");
    290285
    291286                if (data.attr.containsKey("desc"))
    292                         info.append(tr("Description: {0}", data.attr.get("desc")))
    293                                 .append("<br>");
    294 
    295                 if(data.tracks.size() > 0){
    296                     boolean first = true;
    297                     WayPoint earliest = null, latest = null;
    298 
    299                     for(GpxTrack trk: data.tracks){
    300                         for(Collection<WayPoint> seg:trk.trackSegs){
    301                             for(WayPoint pnt:seg){
    302                                 if(first){
    303                                     latest = earliest = pnt;
    304                                     first = false;
    305                                 }else{
    306                                     if(pnt.compareTo(earliest) < 0){
    307                                         earliest = pnt;
    308                                     }else{
    309                                         latest = pnt;
    310                                     }
    311                                 }
    312                             }
    313                         }
    314                     }
    315                     if(earliest != null && latest != null){
    316                         DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
    317                         info.append(tr("Timespan: ") + df.format(new Date((long)(earliest.time * 1000))) + " - " + df.format(new Date((long)(latest.time * 1000))));
    318                         int diff = (int)(latest.time - earliest.time);
    319                         info.append(" (" + (diff / 3600) + ":" + ((diff % 3600)/60) + ")");
    320                         info.append("<br>");
    321                     }
    322                 }
    323                 info.append(tr("Length: ") + new DecimalFormat("#0.00").format(data.length() / 1000) + "km");
    324                 info.append("<br>");
    325                
     287                        info.append(tr("Description: {0}", data.attr.get("desc"))).append("<br>");
     288
     289                if(data.tracks.size() > 0){
     290                        boolean first = true;
     291                        WayPoint earliest = null, latest = null;
     292
     293                        for(GpxTrack trk: data.tracks){
     294                                for(Collection<WayPoint> seg:trk.trackSegs){
     295                                        for(WayPoint pnt:seg){
     296                                                if(first){
     297                                                        latest = earliest = pnt;
     298                                                        first = false;
     299                                                }else{
     300                                                        if(pnt.compareTo(earliest) < 0){
     301                                                                earliest = pnt;
     302                                                        }else{
     303                                                                latest = pnt;
     304                                                        }
     305                                                }
     306                                        }
     307                                }
     308                        }
     309                        if(earliest != null && latest != null){
     310                                DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
     311                                info.append(tr("Timespan: ") + df.format(new Date((long)(earliest.time * 1000))) + " - "
     312                                + df.format(new Date((long)(latest.time * 1000))));
     313                                int diff = (int)(latest.time - earliest.time);
     314                                info.append(" (" + (diff / 3600) + ":" + ((diff % 3600)/60) + ")");
     315                                info.append("<br>");
     316                        }
     317                }
     318                info.append(tr("Length: ") + new DecimalFormat("#0.00").format(data.length() / 1000) + "km");
     319                info.append("<br>");
     320
    326321                return info.append("</html>").toString();
    327322        }
     
    389384                 ****************************************************************/
    390385                if (computeCacheInSync && ((computeCacheMaxLineLengthUsed != maxLineLength) ||
    391                                            (!neutralColor.equals(computeCacheColorUsed)) ||
    392                                            (computeCacheColored != colored))) {
    393 //                      System.out.println("(re-)computing gpx line styles, reason: CCIS=" + computeCacheInSync + " CCMLLU=" + (computeCacheMaxLineLengthUsed != maxLineLength) + " CCCU=" +  (!neutralColor.equals(computeCacheColorUsed)) + " CCC=" + (computeCacheColored != colored));
     386                                                                   (!neutralColor.equals(computeCacheColorUsed)) ||
     387                                                                   (computeCacheColored != colored))) {
     388//          System.out.println("(re-)computing gpx line styles, reason: CCIS=" + computeCacheInSync + " CCMLLU=" + (computeCacheMaxLineLengthUsed != maxLineLength) + " CCCU=" +  (!neutralColor.equals(computeCacheColorUsed)) + " CCC=" + (computeCacheColored != colored));
    394389                        computeCacheMaxLineLengthUsed = maxLineLength;
    395390                        computeCacheInSync = false;
     
    440435                        computeCacheInSync = true;
    441436                }
    442                                                
     437
    443438                /****************************************************************
    444439                 ********** STEP 3a - DRAW LINES ********************************
     
    453448                                        Point screen = mv.getPoint(trkPnt.eastNorth);
    454449                                                if (trkPnt.drawLine) {
    455                                                         if (old != null && ((old.x != screen.x) || (old.y != screen.y))) { // skip points that are on the same screenposition
     450                                                        // skip points that are on the same screenposition
     451                                                        if (old != null && ((old.x != screen.x) || (old.y != screen.y))) {
    456452                                                                g.setColor(trkPnt.speedLineColor);
    457                                                 g.drawLine(old.x, old.y, screen.x, screen.y);
     453                                                                g.drawLine(old.x, old.y, screen.x, screen.y);
    458454                                                        }
    459455                                                }
     
    476472                                                if (trkPnt.drawLine) {
    477473                                                        Point screen = mv.getPoint(trkPnt.eastNorth);
    478                                                         if (old != null && ((old.x != screen.x) || (old.y != screen.y))) { // skip points that are on the same screenposition
     474                                                        // skip points that are on the same screenposition
     475                                                        if (old != null && ((old.x != screen.x) || (old.y != screen.y))) {
    479476                                                                g.setColor(trkPnt.speedLineColor);
    480                                                     double t = Math.atan2(screen.y-old.y, screen.x-old.x) + Math.PI;
    481                                                     g.drawLine(screen.x,screen.y, (int)(screen.x + 10*Math.cos(t-PHI)), (int)(screen.y + 10*Math.sin(t-PHI)));
    482                                                     g.drawLine(screen.x,screen.y, (int)(screen.x + 10*Math.cos(t+PHI)), (int)(screen.y + 10*Math.sin(t+PHI)));
    483                                                 }
     477                                                                double t = Math.atan2(screen.y-old.y, screen.x-old.x) + Math.PI;
     478                                                                g.drawLine(screen.x,screen.y, (int)(screen.x + 10*Math.cos(t-PHI)), (int)(screen.y
     479                                                                + 10*Math.sin(t-PHI)));
     480                                                                g.drawLine(screen.x,screen.y, (int)(screen.x + 10*Math.cos(t+PHI)), (int)(screen.y
     481                                                                + 10*Math.sin(t+PHI)));
     482                                                        }
    484483                                                        old = screen;
    485                                                         }
     484                                                }
    486485                                        } // end for trkpnt
    487486                                } // end for segment
     
    501500                                                if (trkPnt.drawLine) {
    502501                                                        Point screen = mv.getPoint(trkPnt.eastNorth);
    503                                                         if (old != null && ((old.x != screen.x) || (old.y != screen.y))) { // skip points that are on the same screenposition
     502                                                        // skip points that are on the same screenposition
     503                                                        if (old != null && ((old.x != screen.x) || (old.y != screen.y))) {
    504504                                                                g.setColor(trkPnt.speedLineColor);
    505505                                                                g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][0], screen.y + dir[trkPnt.dir][1]);
    506506                                                                g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][2], screen.y + dir[trkPnt.dir][3]);
    507                                                 }
     507                                                        }
    508508                                                        old = screen;
    509                                             }
     509                                                }
    510510                                        } // end for trkpnt
    511511                                } // end for segment
     
    566566                } // end if large
    567567
    568         Long duration = System.currentTimeMillis() - startTime;
    569         //System.out.println(duration);
    570 
     568                //Long duration = System.currentTimeMillis() - startTime;
     569                //System.out.println(duration);
    571570        } // end paint
    572571
     
    634633                                try {
    635634                                        String version = Main.pref.get("osm-server.version", "0.5");
    636                                         URL url = new URL(Main.pref.get("osm-server.url") +
    637                                                         "/" + version + "/gpx/create");
     635                                        URL url = new URL(Main.pref.get("osm-server.url") + "/" + version + "/gpx/create");
    638636
    639637                                        // create a boundary string
     
    641639                                        URLConnection urlConn = MultiPartFormOutputStream.createConnection(url);
    642640                                        urlConn.setRequestProperty("Accept", "*/*");
    643                                         urlConn.setRequestProperty("Content-Type",
    644                                                         MultiPartFormOutputStream.getContentType(boundary));
     641                                        urlConn.setRequestProperty("Content-Type", MultiPartFormOutputStream.getContentType(boundary));
    645642                                        // set some other request headers...
    646643                                        urlConn.setRequestProperty("Connection", "Keep-Alive");
    647644                                        urlConn.setRequestProperty("Cache-Control", "no-cache");
    648645                                        // no need to connect cuz getOutputStream() does it
    649                                         MultiPartFormOutputStream out =
    650                                                 new MultiPartFormOutputStream(urlConn.getOutputStream(), boundary);
     646                                        MultiPartFormOutputStream out = new MultiPartFormOutputStream(urlConn.getOutputStream(), boundary);
    651647                                        out.writeField("description", description.getText());
    652648                                        out.writeField("tags", tags.getText());
     
    655651                                        // out.writeFile("gpx_file", "text/xml", associatedFile);
    656652                                        // can also write bytes directly
    657                                         // out.writeFile("myFile", "text/plain", "C:\\test.txt", 
     653                                        // out.writeFile("myFile", "text/plain", "C:\\test.txt",
    658654                                        // "This is some file text.".getBytes("ASCII"));
    659655                                        File tmp = File.createTempFile("josm", "tmp.gpx");
     
    667663                                        tmp.delete();
    668664                                        // read response from server
    669                                         BufferedReader in = new BufferedReader(
    670                                                         new InputStreamReader(urlConn.getInputStream()));
     665                                        BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
    671666                                        String line = "";
    672667                                        while((line = in.readLine()) != null) {
     
    676671
    677672                                        //TODO check response
    678                                         /*                                      int retCode = urlConn.getResponseCode();
     673                                        /*                  int retCode = urlConn.getResponseCode();
    679674                                        System.out.println("got return: " + retCode);
    680675                                        String retMsg = urlConn.getResponseMessage();
     
    695690                                } catch (Exception ex) {
    696691                                        //if (cancel)
    697                                         //      return; // assume cancel
     692                                        //  return; // assume cancel
    698693                                        if (ex instanceof RuntimeException)
    699694                                                throw (RuntimeException)ex;
    700695                                        throw new RuntimeException(ex.getMessage(), ex);
    701                                 }       
     696                                }
    702697                        }
    703698                }
     
    736731                }
    737732        }
    738        
     733
    739734        /**
    740          * Makes a new marker layer derived from this GpxLayer containing at least one 
     735         * Makes a new marker layer derived from this GpxLayer containing at least one
    741736         * audio marker which the given audio file is associated with.
    742737         * Markers are derived from the following
     
    749744        private void importAudio(File wavFile) {
    750745                String uri = "file:".concat(wavFile.getAbsolutePath());
    751             MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Audio markers from {0}", name), associatedFile, me);
    752            
    753             Collection<WayPoint> waypoints = new ArrayList<WayPoint>();
    754             boolean timedMarkersOmitted = false;
    755             boolean untimedMarkersOmitted = false;
    756            
    757             // determine time of first point in track
    758             double firstTime = -1.0;
    759         if (data.tracks != null && ! data.tracks.isEmpty()) {
    760                 for (GpxTrack track : data.tracks) {
    761                         if (track.trackSegs == null) continue;
    762                         for (Collection<WayPoint> seg : track.trackSegs) {
    763                                 for (WayPoint w : seg) {
    764                                         firstTime = w.time;
    765                                         break;
    766                                 }
    767                                 if (firstTime >= 0.0) break;
    768                         }
    769                         if (firstTime >= 0.0) break;
    770                 }
    771         }
    772         if (firstTime < 0.0) {
     746                MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Audio markers from {0}", name), associatedFile, me);
     747
     748                Collection<WayPoint> waypoints = new ArrayList<WayPoint>();
     749                boolean timedMarkersOmitted = false;
     750                boolean untimedMarkersOmitted = false;
     751                double snapDistance = Main.pref.getDouble("marker.audiofromuntimedwaypoints.distance", 1.0e-3); /* about 25m */
     752
     753                // determine time of first point in track
     754                double firstTime = -1.0;
     755                if (data.tracks != null && ! data.tracks.isEmpty()) {
     756                        for (GpxTrack track : data.tracks) {
     757                                if (track.trackSegs == null) continue;
     758                                for (Collection<WayPoint> seg : track.trackSegs) {
     759                                        for (WayPoint w : seg) {
     760                                                firstTime = w.time;
     761                                                break;
     762                                        }
     763                                        if (firstTime >= 0.0) break;
     764                                }
     765                                if (firstTime >= 0.0) break;
     766                        }
     767                }
     768                if (firstTime < 0.0) {
    773769                        JOptionPane.showMessageDialog(Main.parent, tr("No GPX track available in layer to associate audio with."));
    774770                        return;
    775         }
    776            
    777             // (a) try explicit timestamped waypoints - unless suppressed
    778             if (Main.pref.getBoolean("marker.audiofromexplicitwaypoints", true) &&
    779                 data.waypoints != null && ! data.waypoints.isEmpty())
    780             {
    781                 for (WayPoint w : data.waypoints) {
    782                         if (w.time > firstTime) {
    783                                 waypoints.add(w);
    784                         } else if (w.time > 0.0) {
    785                                 timedMarkersOmitted = true;
    786                         }
    787                 }
    788             }
    789 
    790             // (b) try explicit waypoints without timestamps - unless suppressed
    791             if (Main.pref.getBoolean("marker.audiofromuntimedwaypoints", true) &&
    792                 data.waypoints != null && ! data.waypoints.isEmpty())
    793             {
    794                 for (WayPoint w : data.waypoints) {
    795                         if (waypoints.contains(w)) { continue; }
    796                         WayPoint wNear = nearestPointOnTrack(w.eastNorth, 10.0e-7 /* about 25m */);
    797                         if (wNear != null) {
    798                                 WayPoint wc = new WayPoint(w.latlon);
    799                                 wc.time = wNear.time;
    800                                 if (w.attr.containsKey("name")) wc.attr.put("name", w.getString("name"));
    801                                 waypoints.add(wc);
    802                         } else {
    803                                 untimedMarkersOmitted = true;
    804                         }
    805                 }
    806             }
    807            
    808             // (c) use explicitly named track points, again unless suppressed
    809             if ((Main.pref.getBoolean("marker.audiofromnamedtrackpoints", Main.pref.getBoolean("marker.namedtrackpoints") /* old name */)) &&
    810                 data.tracks != null && ! data.tracks.isEmpty())
    811             {
    812                 for (GpxTrack track : data.tracks) {
    813                         if (track.trackSegs == null) continue;
    814                         for (Collection<WayPoint> seg : track.trackSegs) {
    815                                 for (WayPoint w : seg) {
    816                                         if (w.attr.containsKey("name") || w.attr.containsKey("desc")) {
    817                                                 waypoints.add(w);
    818                                         }
    819                                 }
    820                         }
    821                 }
    822             }
    823 
    824             // (d) analyse audio for spoken markers here, in due course
    825            
    826             // (e) simply add a single marker at the start of the track
    827             if ((Main.pref.getBoolean("marker.audiofromstart") || waypoints.isEmpty()) &&
    828                 data.tracks != null && ! data.tracks.isEmpty())
     771                }
     772
     773                // (a) try explicit timestamped waypoints - unless suppressed
     774                if (Main.pref.getBoolean("marker.audiofromexplicitwaypoints", true) &&
     775                        data.waypoints != null && ! data.waypoints.isEmpty())
    829776                {
    830                 boolean gotOne = false;
    831                 for (GpxTrack track : data.tracks) {
    832                         if (track.trackSegs == null) continue;
    833                         for (Collection<WayPoint> seg : track.trackSegs) {
    834                                 for (WayPoint w : seg) {
    835                                         WayPoint wStart = new WayPoint(w.latlon);
    836                                         wStart.attr.put("name", "start");
    837                                         wStart.time = w.time;
    838                                         waypoints.add(wStart);
    839                                         gotOne = true;
    840                                         break;
    841                                 }
    842                                 if (gotOne) break;
    843                         }
    844                         if (gotOne) break;
    845                 }
    846                 }
    847 
    848             /* we must have got at least one waypoint now */
    849            
    850             Collections.sort((ArrayList<WayPoint>) waypoints, new Comparator<WayPoint>() {
    851                 public int compare(WayPoint a, WayPoint b) {
    852                         return a.time <= b.time ? -1 : 1;
    853                 }
    854             });
    855 
    856             firstTime = -1.0; /* this time of the first waypoint, not first trackpoint */
    857             for (WayPoint w : waypoints) {
    858                 if (firstTime < 0.0) firstTime = w.time;
    859                 double offset = w.time - firstTime;
     777                        for (WayPoint w : data.waypoints) {
     778                                if (w.time > firstTime) {
     779                                        waypoints.add(w);
     780                                } else if (w.time > 0.0) {
     781                                        timedMarkersOmitted = true;
     782                                }
     783                        }
     784                }
     785
     786                // (b) try explicit waypoints without timestamps - unless suppressed
     787                if (Main.pref.getBoolean("marker.audiofromuntimedwaypoints", true) &&
     788                        data.waypoints != null && ! data.waypoints.isEmpty())
     789                {
     790                        for (WayPoint w : data.waypoints) {
     791                                if (waypoints.contains(w)) { continue; }
     792                                WayPoint wNear = nearestPointOnTrack(w.eastNorth, snapDistance);
     793                                if (wNear != null) {
     794                                        WayPoint wc = new WayPoint(w.latlon);
     795                                        wc.time = wNear.time;
     796                                        if (w.attr.containsKey("name")) wc.attr.put("name", w.getString("name"));
     797                                        waypoints.add(wc);
     798                                } else {
     799                                        untimedMarkersOmitted = true;
     800                                }
     801                        }
     802                }
     803
     804                // (c) use explicitly named track points, again unless suppressed
     805                if ((Main.pref.getBoolean("marker.audiofromnamedtrackpoints", false)) &&
     806                        data.tracks != null && ! data.tracks.isEmpty())
     807                {
     808                        for (GpxTrack track : data.tracks) {
     809                                if (track.trackSegs == null) continue;
     810                                for (Collection<WayPoint> seg : track.trackSegs) {
     811                                        for (WayPoint w : seg) {
     812                                                if (w.attr.containsKey("name") || w.attr.containsKey("desc")) {
     813                                                        waypoints.add(w);
     814                                                }
     815                                        }
     816                                }
     817                        }
     818                }
     819
     820                // (d) analyse audio for spoken markers here, in due course
     821
     822                // (e) simply add a single marker at the start of the track
     823                if ((Main.pref.getBoolean("marker.audiofromstart") || waypoints.isEmpty()) &&
     824                        data.tracks != null && ! data.tracks.isEmpty())
     825                {
     826                        boolean gotOne = false;
     827                        for (GpxTrack track : data.tracks) {
     828                                if (track.trackSegs == null) continue;
     829                                for (Collection<WayPoint> seg : track.trackSegs) {
     830                                        for (WayPoint w : seg) {
     831                                                WayPoint wStart = new WayPoint(w.latlon);
     832                                                wStart.attr.put("name", "start");
     833                                                wStart.time = w.time;
     834                                                waypoints.add(wStart);
     835                                                gotOne = true;
     836                                                break;
     837                                        }
     838                                        if (gotOne) break;
     839                                }
     840                                if (gotOne) break;
     841                        }
     842                }
     843
     844                /* we must have got at least one waypoint now */
     845
     846                Collections.sort((ArrayList<WayPoint>) waypoints, new Comparator<WayPoint>() {
     847                        public int compare(WayPoint a, WayPoint b) {
     848                                return a.time <= b.time ? -1 : 1;
     849                        }
     850                });
     851
     852                firstTime = -1.0; /* this time of the first waypoint, not first trackpoint */
     853                for (WayPoint w : waypoints) {
     854                        if (firstTime < 0.0) firstTime = w.time;
     855                        double offset = w.time - firstTime;
    860856                        String name;
    861857                        if (w.attr.containsKey("name"))
     
    865861                        else
    866862                                name = AudioMarker.inventName(offset);
    867                         AudioMarker am = AudioMarker.create(w.latlon, 
     863                        AudioMarker am = AudioMarker.create(w.latlon,
    868864                                        name, uri, ml, w.time, offset);
    869                         ml.data.add(am);                                       
    870             }
    871             Main.main.addLayer(ml);
    872            
    873             if (timedMarkersOmitted) {
    874                         JOptionPane.showMessageDialog(Main.parent, tr("Some waypoints with timestamps from before the start of the track were omitted."));
    875             }
    876             if (untimedMarkersOmitted) {
    877                         JOptionPane.showMessageDialog(Main.parent, tr("Some waypoints which were too far from the track to sensibly estimate their time were omitted."));
    878             }
     865                        ml.data.add(am);
     866                }
     867                Main.main.addLayer(ml);
     868
     869                if (timedMarkersOmitted) {
     870                        JOptionPane.showMessageDialog(Main.parent,
     871                        tr("Some waypoints with timestamps from before the start of the track were omitted."));
     872                }
     873                if (untimedMarkersOmitted) {
     874                        JOptionPane.showMessageDialog(Main.parent,
     875                        tr("Some waypoints which were too far from the track to sensibly estimate their time were omitted."));
     876                }
    879877        }
    880878
    881879        /**
    882          * Makes a WayPoint at the projection of point P onto the track providing P is 
    883          * less than tolerance away from the track 
     880         * Makes a WayPoint at the projection of point P onto the track providing P is
     881         * less than tolerance away from the track
    884882
    885883         * @param P : the point to determine the projection for
    886884         * @param tolerance : must be no further than this from the track
    887          * @return the closest point on the track to P, which may be the 
    888          * first or last point if off the end of a segment, or may be null if 
     885         * @return the closest point on the track to P, which may be the
     886         * first or last point if off the end of a segment, or may be null if
    889887         * nothing close enough
    890888         */
    891889        public WayPoint nearestPointOnTrack(EastNorth P, double tolerance) {
    892890                /*
    893                  * assume the coordinates of P are xp,yp, and those of a section of track 
     891                 * assume the coordinates of P are xp,yp, and those of a section of track
    894892                 * between two trackpoints are R=xr,yr and S=xs,ys. Let N be the projected point.
    895                  * 
     893                 *
    896894                 * The equation of RS is Ax + By + C = 0 where
    897895                 * A = ys - yr
    898896                 * B = xr - xs
    899897                 * C = - Axr - Byr
    900                  * 
     898                 *
    901899                 * Also, note that the distance RS^2 is A^2 + B^2
    902                  * 
     900                 *
    903901                 * If RS^2 == 0.0 ignore the degenerate section of track
    904                  * 
     902                 *
    905903                 * PN^2 = (Axp + Byp + C)^2 / RS^2
    906904                 * that is the distance from P to the line
    907                  * 
    908                  * so if PN^2 is less than PNmin^2 (initialized to tolerance) we can reject 
     905                 *
     906                 * so if PN^2 is less than PNmin^2 (initialized to tolerance) we can reject
    909907                 * the line; otherwise...
    910908                 * determine if the projected poijnt lies within the bounds of the line:
    911909                 * PR^2 - PN^2 <= RS^2 and PS^2 - PN^2 <= RS^2
    912                  * 
     910                 *
    913911                 * where PR^2 = (xp - xr)^2 + (yp-yr)^2
    914912                 * and   PS^2 = (xp - xs)^2 + (yp-ys)^2
    915                  * 
     913                 *
    916914                 * If so, calculate N as
    917915                 * xn = xr + (RN/RS) B
    918916                 * yn = y1 + (RN/RS) A
    919                  * 
     917                 *
    920918                 * where RN = sqrt(PR^2 - PN^2)
    921919                 */
    922                
     920
    923921                double PNminsq = tolerance * tolerance;
    924922                EastNorth bestEN = null;
     
    929927                if (data.tracks == null) return null;
    930928                for (GpxTrack track : data.tracks) {
    931                         if (track.trackSegs == null) continue;                 
     929                        if (track.trackSegs == null) continue;
    932930                        for (Collection<WayPoint> seg : track.trackSegs) {
    933931                                WayPoint R = null;
     
    988986                                                bestTime = R.time;
    989987                                        }
    990                                        
    991988                                }
    992989                        }
  • trunk/src/org/openstreetmap/josm/gui/preferences/AudioPreference.java

    r795 r813  
    120120                        }
    121121                });
    122                 audioMarkersFromNamedTrackpoints.setSelected(Main.pref.getBoolean("marker.audiofromnamedtrackpoints", Main.pref.getBoolean("marker.namedtrackpoints")));
     122                audioMarkersFromNamedTrackpoints.setSelected(Main.pref.getBoolean("marker.audiofromnamedtrackpoints", false));
    123123                audioMarkersFromNamedTrackpoints.setToolTipText(tr("Automatically create audio markers from trackpoints (rather than explicit waypoints) with names or descriptions."));
    124124                gui.audio.add(audioMarkersFromNamedTrackpoints, GBC.eol().insets(10,0,0,0));
  • trunk/src/org/openstreetmap/josm/io/GpxReader.java

    r627 r813  
    224224                                break;
    225225                        case wpt:
    226                                 if (qName.equals("ele") || qName.equals("desc")
    227                                                 || qName.equals("magvar") || qName.equals("geoidheight")
    228                                                 || qName.equals("name") || qName.equals("sym")
    229                                                 || qName.equals("cmt") || qName.equals("type")) {
     226                                if (qName.equals("ele") || qName.equals("magvar")
     227                                                || qName.equals("geoidheight") || qName.equals("name")
     228                                                || qName.equals("sym") || qName.equals("type")) {
    230229                                        currentWayPoint.attr.put(qName, accumulator.toString());
    231230                                } else if (qName.equals("time")) {
    232231                                        currentWayPoint.attr.put(qName, accumulator.toString());
    233232                                        currentWayPoint.setTime();                                     
     233                                } else if (qName.equals("cmt") || qName.equals("desc")) {
     234                                        currentWayPoint.attr.put(qName, accumulator.toString());
     235                                        currentWayPoint.setGarminCommentTime(qName);                                   
    234236                                } else if (qName.equals("rtept")) {
    235237                                        currentState = states.pop();
Note: See TracChangeset for help on using the changeset viewer.