Changeset 7414 in josm


Ignore:
Timestamp:
2014-08-16T04:29:00+02:00 (10 years ago)
Author:
Don-vip
Message:

fix #10165 - Wrong waypoint order in exported GPX

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

Legend:

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

    r6643 r7414  
    2525/**
    2626 * Exports data to gpx.
     27 * @since 78
    2728 */
    2829public class GpxExportAction extends DiskAccessAction {
    2930
     31    /**
     32     * Constructs a new {@code GpxExportAction}.
     33     */
    3034    public GpxExportAction() {
    3135        super(tr("Export to GPX..."), "exportgpx", tr("Export the data to GPX file."),
     
    9599    /**
    96100     * Refreshes the enabled state
    97      *
    98101     */
    99102    @Override
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r7402 r7414  
    2323import java.util.Arrays;
    2424import java.util.Collection;
     25import java.util.Collections;
    2526import java.util.HashMap;
    2627import java.util.HashSet;
     
    9596 *
    9697 * @author imi
     98 * @since 17
    9799 */
    98100public class OsmDataLayer extends AbstractModifiableLayer implements Listener, SelectionChangedListener {
     101    /** Property used to know if this layer has to be saved on disk */
    99102    public static final String REQUIRES_SAVE_TO_DISK_PROP = OsmDataLayer.class.getName() + ".requiresSaveToDisk";
     103    /** Property used to know if this layer has to be uploaded */
    100104    public static final String REQUIRES_UPLOAD_TO_SERVER_PROP = OsmDataLayer.class.getName() + ".requiresUploadToServer";
    101105
     
    232236    }
    233237
     238    /**
     239     * Replies background color for downloaded areas.
     240     * @return background color for downloaded areas. Black by default
     241     */
    234242    public static Color getBackgroundColor() {
    235243        return Main.pref.getColor(marktr("background"), Color.BLACK);
    236244    }
    237245
     246    /**
     247     * Replies background color for non-downloaded areas.
     248     * @return background color for non-downloaded areas. Yellow by default
     249     */
    238250    public static Color getOutsideColor() {
    239251        return Main.pref.getColor(marktr("outside downloaded area"), Color.YELLOW);
     
    257269
    258270    /**
    259      * Construct a OsmDataLayer.
     271     * Construct a new {@code OsmDataLayer}.
     272     * @param data OSM data
     273     * @param name Layer name
     274     * @param associatedFile Associated .osm file (can be null)
    260275     */
    261276    public OsmDataLayer(final DataSet data, final String name, final File associatedFile) {
     
    524539    }
    525540
     541    /**
     542     * Converts given OSM dataset to GPX data.
     543     * @param data OSM dataset
     544     * @param file output .gpx file
     545     * @return GPX data
     546     */
    526547    public static GpxData toGpxData(DataSet data, File file) {
    527548        GpxData gpxData = new GpxData();
    528549        gpxData.storageFile = file;
    529550        HashSet<Node> doneNodes = new HashSet<>();
    530         for (Way w : data.getWays()) {
     551        waysToGpxData(data.getWays(), gpxData, doneNodes);
     552        nodesToGpxData(data.getNodes(), gpxData, doneNodes);
     553        return gpxData;
     554    }
     555
     556    private static void waysToGpxData(Collection<Way> ways, GpxData gpxData, HashSet<Node> doneNodes) {
     557        for (Way w : ways) {
    531558            if (!w.isUsable()) {
    532559                continue;
     
    562589            gpxData.tracks.add(new ImmutableGpxTrack(trk, trkAttr));
    563590        }
    564 
    565         for (Node n : data.getNodes()) {
    566             if (n.isIncomplete() || n.isDeleted() || doneNodes.contains(n)) {
     591    }
     592
     593    private static void nodesToGpxData(Collection<Node> nodes, GpxData gpxData, HashSet<Node> doneNodes) {
     594        List<Node> sortedNodes = new ArrayList<>(nodes);
     595        sortedNodes.removeAll(doneNodes);
     596        Collections.sort(sortedNodes);
     597        for (Node n : sortedNodes) {
     598            if (n.isIncomplete() || n.isDeleted()) {
    567599                continue;
    568600            }
     
    583615            gpxData.waypoints.add(wpt);
    584616        }
    585         return gpxData;
    586     }
    587 
     617    }
     618
     619    /**
     620     * Converts OSM data behind this layer to GPX data.
     621     * @return GPX data
     622     */
    588623    public GpxData toGpxData() {
    589624        return toGpxData(data, getAssociatedFile());
    590625    }
    591626
     627    /**
     628     * Action that converts this OSM layer to a GPX layer.
     629     */
    592630    public class ConvertToGpxLayerAction extends AbstractAction {
     631        /**
     632         * Constructs a new {@code ConvertToGpxLayerAction}.
     633         */
    593634        public ConvertToGpxLayerAction() {
    594635            super(tr("Convert to GPX layer"), ImageProvider.get("converttogpx"));
     
    602643    }
    603644
     645    /**
     646     * Determines if this layer contains data at the given coordinate.
     647     * @param coor the coordinate
     648     * @return {@code true} if data sources bounding boxes contain {@code coor}
     649     */
    604650    public boolean containsPoint(LatLon coor) {
    605651        // we'll assume that if this has no data sources
     
    619665
    620666    /**
    621      * replies the set of conflicts currently managed in this layer
     667     * Replies the set of conflicts currently managed in this layer.
    622668     *
    623669     * @return the set of conflicts currently managed in this layer
     
    643689    }
    644690
     691    /**
     692     * Actions run after data has been downloaded to this layer.
     693     */
    645694    public void onPostDownloadFromServer() {
    646695        setRequiresSaveToFile(true);
     
    708757    @Override
    709758    public void projectionChanged(Projection oldValue, Projection newValue) {
    710         /*
    711          * No reprojection required. The dataset itself is registered as projection
    712          * change listener and already got notified.
    713          */
     759         // No reprojection required. The dataset itself is registered as projection
     760         // change listener and already got notified.
    714761    }
    715762
     
    719766    }
    720767
     768    /**
     769     * Sets the "discouraged upload" flag.
     770     * @param uploadDiscouraged {@code true} if upload of data managed by this layer is discouraged. This feature allows to use "private" data layers.
     771     */
    721772    public final void setUploadDiscouraged(boolean uploadDiscouraged) {
    722773        if (uploadDiscouraged ^ isUploadDiscouraged()) {
  • trunk/src/org/openstreetmap/josm/io/GpxExporter.java

    r7037 r7414  
    3737import org.openstreetmap.josm.tools.GBC;
    3838
     39/**
     40 * Exports data to a .gpx file. Data may be native GPX or OSM data which will be converted.
     41 * @since 1949
     42 */
    3943public class GpxExporter extends FileExporter implements GpxConstants {
    40     private static final String warningGpl = "<html><font color='red' size='-2'>"
     44
     45    private static final String GPL_WARNING = "<html><font color='red' size='-2'>"
    4146        + tr("Note: GPL is not compatible with the OSM license. Do not upload GPL licensed tracks.") + "</html>";
    4247
     
    7479        GpxData gpxData;
    7580        // At this moment, we only need to know the attributes of the GpxData,
    76         // conversion of OsmDataLayer (if needed) will be done after the dialog
    77         // is closed.
     81        // conversion of OsmDataLayer (if needed) will be done after the dialog is closed.
    7882        if (layer instanceof GpxLayer) {
    7983            gpxData = ((GpxLayer) layer).data;
     
    175179        }
    176180
    177        
    178181        try (OutputStream fo = Compression.getCompressedFileOutputStream(file)) {
    179182            new GpxWriter(fo).write(gpxData);
     
    194197        copyrightLabel.setEnabled(enable);
    195198        copyrightYearLabel.setEnabled(enable);
    196         warning.setText(enable ? warningGpl : "<html><font size='-2'>&nbsp;</html");
     199        warning.setText(enable ? GPL_WARNING : "<html><font size='-2'>&nbsp;</html");
    197200
    198201        if (enable) {
     
    220223    /**
    221224     * Add all those listeners to handle the enable state of the fields.
    222      * @param copyrightYearLabel
    223      * @param copyrightLabel
    224      * @param emailLabel
    225      * @param nameLabel
    226      * @param warning
    227225     */
    228226    private static void addDependencies(
     
    299297                    return;
    300298                final String[] urls = {
    301                         "https://creativecommons.org/licenses/by-sa/2.5",
     299                        "https://creativecommons.org/licenses/by-sa/3.0",
    302300                        "http://opendatacommons.org/licenses/odbl/1.0",
    303301                        "public domain",
     
    329327        return Main.main.getCurrentDataSet();
    330328    }
    331 
    332329}
Note: See TracChangeset for help on using the changeset viewer.