Changeset 10 in josm


Ignore:
Timestamp:
2005-10-04T20:14:54+02:00 (19 years ago)
Author:
imi
Message:

GPX export added

Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • .classpath

    r1 r10  
    33        <classpathentry kind="src" path="src"/>
    44        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    5         <classpathentry sourcepath="/home/imi/download/jdom-1.0.zip" kind="lib" path="lib/jdom.jar"/>
     5        <classpathentry sourcepath="/home/imi/src/jdom-1.0/src" kind="lib" path="lib/jdom.jar"/>
    66        <classpathentry kind="output" path="bin"/>
    77</classpath>
  • src/org/openstreetmap/josm/actions/SaveGpxAction.java

    r1 r10  
    44import java.awt.event.KeyEvent;
    55import java.io.File;
     6import java.io.FileWriter;
     7import java.io.IOException;
    68
    79import javax.swing.AbstractAction;
    810import javax.swing.ImageIcon;
    911import javax.swing.JFileChooser;
     12import javax.swing.JOptionPane;
    1013
    1114import org.openstreetmap.josm.gui.Main;
     15import org.openstreetmap.josm.io.GpxWriter;
    1216
    1317/**
     
    2933       
    3034        @SuppressWarnings("unchecked")
    31         public void actionPerformed(ActionEvent e) {
     35        public void actionPerformed(ActionEvent event) {
     36                if (Main.main.getMapFrame() == null) {
     37                        JOptionPane.showMessageDialog(Main.main, "No document open so nothing to save.");
     38                        return;
     39                }
    3240                JFileChooser fc = new JFileChooser("data");
    3341                fc.showSaveDialog(Main.main);
     
    3543                if (gpxFile == null)
    3644                        return;
     45               
     46                try {
     47                        FileWriter fileWriter = new FileWriter(gpxFile);
     48                        GpxWriter out = new GpxWriter(fileWriter, Main.main.getMapFrame().mapView.dataSet);
     49                        out.output();
     50                        fileWriter.close();
     51                } catch (IOException e) {
     52                        e.printStackTrace();
     53                        JOptionPane.showMessageDialog(Main.main, "An error occoured while saving.\n"+e.getMessage());
     54                }
    3755        }
    3856
  • src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r9 r10  
    6666                return true;
    6767        }
    68        
     68
    6969        /**
    7070         * Mark the primitive as selected or not selected and fires a selection
  • src/org/openstreetmap/josm/io/GpxReader.java

    r9 r10  
    9292
    9393        /**
     94         * Read a data set from the element.
     95         * @param e     The element to parse
     96         * @return              The DataSet read from the element
     97         */
     98        private DataSet parseDataSet(Element e) {
     99                DataSet data = new DataSet();
     100                // read waypoints not contained in tracks or areas
     101                for (Object o : e.getChildren("wpt", GPX))
     102                        addNode(data, parseWaypoint((Element)o));
     103       
     104                // read tracks
     105                for (Object trackElement : e.getChildren("trk", GPX))
     106                        parseTrack((Element)trackElement, data);
     107       
     108                return data;
     109        }
     110
     111        /**
     112         * Parse and read a track from the element. Store it in the dataSet, as well
     113         * as all nodes in it.
     114         *
     115         * @param e             The element that contain the track.
     116         * @param ds    The DataSet to store the data in.
     117         */
     118        private void parseTrack(Element e, DataSet ds) {
     119                Track track = new Track();
     120                for (Object o : e.getChildren()) {
     121                        Element child = (Element)o;
     122                        if (child.getName().equals("extensions"))
     123                                parseKeyValueExtensions(track, child);
     124                        else if (child.getName().equals("link"))
     125                                parseKeyValueLink(track, child);
     126                        else if (child.getName().equals("trkseg")) {
     127                                Node start = null;
     128                                for (Object w : child.getChildren("trkpt", GPX)) {
     129                                        Node node = parseWaypoint((Element)w);
     130                                        node = addNode(ds, node);
     131                                        if (start == null)
     132                                                start = node;
     133                                        else {
     134                                                LineSegment lineSegment = new LineSegment(start, node);
     135                                                parseKeyValueExtensions(lineSegment, ((Element)w).getChild("extensions", GPX));
     136                                                track.add(lineSegment);
     137                                                start = null;
     138                                        }
     139                                }
     140                        } else
     141                                parseKeyValueTag(track, child);
     142                }
     143                ds.addTrack(track);
     144        }
     145       
     146
     147        /**
     148         * Adds the node to allNodes if it is not already listed. Does respect the
     149         * preference setting "mergeNodes". Return the node in the list that correspond
     150         * to the node in the list (either the new added or the old found).
     151         *
     152         * @param data The DataSet to add the node to.
     153         * @param node The node that should be added.
     154         * @return Either the parameter node or the old node found in the dataset.
     155         */
     156        private Node addNode (DataSet data, Node node) {
     157                if (Main.pref.mergeNodes)
     158                        for (Node n : data.nodes)
     159                                if (node.coor.lat == n.coor.lat && node.coor.lon == n.coor.lon)
     160                                        return n;
     161                data.nodes.add(node);
     162                return node;
     163        }
     164
     165        /**
    94166         * Parse the extensions tag and add all properties found as key/value.
    95167         * <code>osm.keys</code> may be <code>null</code>, in which case it is
     
    138210         * The format stored is: mimetype;url
    139211         * Example: text/html;http://www.openstreetmap.org
     212         *
    140213         * @param osm   The osm primitive to store the data in.
    141214         * @param e             The element in gpx:linkType - format.
    142215         */
    143         private void parseKeyValueLink(Node osm, Element e) {
     216        private void parseKeyValueLink(OsmPrimitive osm, Element e) {
    144217                if (e != null) {
    145218                        if (osm.keys == null)
     
    149222                }
    150223        }
    151 
    152         /**
    153          * Read a data set from the element.
    154          * @param e     The element to parse
    155          * @return              The DataSet read from the element
    156          */
    157         private DataSet parseDataSet(Element e) {
    158                 DataSet data = new DataSet();
    159                 // read waypoints not contained in tracks or areas
    160                 for (Object o : e.getChildren("wpt", GPX))
    161                         addNode(data, parseWaypoint((Element)o));
    162 
    163                 // read tracks
    164                 for (Object trackElement : e.getChildren("trk", GPX)) {
    165                         Track track = new Track();
    166                         for (Object trackSegmentElement : ((Element)trackElement).getChildren("trkseg", GPX)) {
    167                                 Node start = null;
    168                                 for (Object w : ((Element)trackSegmentElement).getChildren("trkpt", GPX)) {
    169                                         Node node = parseWaypoint((Element)w);
    170                                         node = addNode(data, node);
    171                                         if (start == null)
    172                                                 start = node;
    173                                         else {
    174                                                 LineSegment lineSegment = new LineSegment(start, node);
    175                                                 track.add(lineSegment);
    176                                                 start = null;
    177                                         }
    178                                 }
    179                         }
    180                         data.addTrack(track);
    181                 }
    182 
    183                 return data;
    184         }
    185        
    186         /**
    187          * Adds the node to allNodes if it is not already listed. Does respect the
    188          * preference setting "mergeNodes". Return the node in the list that correspond
    189          * to the node in the list (either the new added or the old found).
    190          *
    191          * @param data The DataSet to add the node to.
    192          * @param node The node that should be added.
    193          * @return Either the parameter node or the old node found in the dataset.
    194          */
    195         private Node addNode (DataSet data, Node node) {
    196                 if (Main.pref.mergeNodes)
    197                         for (Node n : data.nodes)
    198                                 if (node.coor.lat == n.coor.lat && node.coor.lon == n.coor.lon)
    199                                         return n;
    200                 data.nodes.add(node);
    201                 return node;
    202         }
    203224}
Note: See TracChangeset for help on using the changeset viewer.