Changeset 6164 in osm


Ignore:
Timestamp:
2007-12-26T23:48:57+01:00 (17 years ago)
Author:
christofd
Message:

do not use RawGpsLayer but GpxLayer now (add wpt to gpx, so markers do not need to be saved anymore)

Location:
applications/editors/josm/plugins/surveyor
Files:
1 added
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/surveyor/build.xml

    r6100 r6164  
    2121 
    2222  <!-- plugin meta data (enter new version number if anything changed!) -->
    23   <property name="plugin.version" value="1.3.3"/>
     23  <property name="plugin.version" value="1.4"/>
    2424  <property name="plugin.description" value="Allow adding markers/nodes on current gps positions (V${plugin.version})."/>
    2525  <property name="plugin.stage" value="60"/>
  • applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/AutoSaveAction.java

    r5429 r6164  
    5757           
    5858            String gpxFilename = MessageFormat.format(GPS_FILE_NAME_PATTERN, new Date());
    59             task = new AutoSaveGpsAndMarkerLayerTimeTask(gpxFilename,
    60                 LiveGpsLayer.LAYER_NAME, SetWaypointAction.MARKER_LAYER_NAME);
     59            task = new AutoSaveGpsLayerTimerTask(gpxFilename, LiveGpsLayer.LAYER_NAME);
    6160            gpsDataTimer.schedule(task, 1000, AUTO_SAVE_PERIOD_SEC * 1000);
    6261           
  • applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/AutoSaveGpsLayerTimerTask.java

    r5270 r6164  
    77import static org.openstreetmap.josm.tools.I18n.tr;
    88
     9import java.io.BufferedWriter;
    910import java.io.File;
    10 import java.io.FileOutputStream;
     11import java.io.FileWriter;
    1112import java.io.IOException;
     13import java.io.PrintWriter;
    1214import java.util.TimerTask;
    1315
     
    1719
    1820import org.openstreetmap.josm.Main;
    19 import org.openstreetmap.josm.gui.layer.Layer;
    20 import org.openstreetmap.josm.gui.layer.RawGpsLayer;
     21import org.openstreetmap.josm.gui.layer.GpxLayer;
    2122import org.openstreetmap.josm.io.GpxWriter;
    22 import org.openstreetmap.josm.io.XmlWriter;
     23
     24import at.dallermassl.josm.plugin.surveyor.util.LayerUtil;
    2325
    2426/**
    25  * TimerTask that writes the data of a {@link RawGpsLayer} to a gpx file.
     27 * TimerTask that writes the data of a {@link GpxLayer} to a gpx file.
    2628 * Every time the task is run, the layer is retrieved from the map view so it even works
    2729 * if the layer does not exist at the start of the timer task. If the layer does not exist,
     
    6163
    6264        try {           
    63             XmlWriter.OsmWriterInterface writer = getXmlWriter();
    64             if(writer != null) {
    65                 // write to temporary file, on success, rename tmp file to target file:
    66                 File tmpFile = new File(file.getAbsoluteFile()+".tmp");
    67                 System.out.println("AutoSaving data to file " + file.getAbsolutePath());
    68                 // synchronize on layer to prevent concurrent adding of data to the layer
    69                 // quite a hack, but no other object to sync available :-(
    70                 // @see LiveGpsLayer
    71                 synchronized(LiveGpsLock.class) {
    72                     XmlWriter.output(new FileOutputStream(tmpFile), writer);
    73                 }   
    74                 tmpFile.renameTo(file);
     65
     66            GpxLayer gpsLayer = LayerUtil.findGpsLayer(gpsLayerName, GpxLayer.class);
     67            if(gpsLayer == null) {
     68                return;
    7569            }
    76         } catch (IOException x) {
    77             x.printStackTrace();
     70            // write to temporary file, on success, rename tmp file to target file:
     71            File tmpFile = new File(file.getAbsoluteFile()+".tmp");
     72            System.out.println("AutoSaving data to file " + file.getAbsolutePath());
     73            // synchronize on layer to prevent concurrent adding of data to the layer
     74            // quite a hack, but no other object to sync available :-(
     75            // @see LiveGpsLayer
     76            PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(tmpFile)));
     77            GpxWriter gpxWriter = new GpxWriter(out);
     78            synchronized(LiveGpsLock.class) {
     79                gpxWriter.write(gpsLayer.data);
     80            }   
     81            tmpFile.renameTo(file);
     82        } catch (IOException ioExc) {
     83            ioExc.printStackTrace();
    7884            JOptionPane.showMessageDialog(Main.parent,
    79                 tr("Error while exporting {0}: {1}", file.getAbsoluteFile(), x.getMessage()),
     85                tr("Error while exporting {0}: {1}", file.getAbsoluteFile(), ioExc.getMessage()),
    8086                tr("Error"),
    8187                JOptionPane.ERROR_MESSAGE);
    8288        }       
    8389    }
    84    
    85     /**
    86      * Returns the layer with the given name and type from the map view or <code>null</code>.
    87      * @param <LayerType> the type of the layer.
    88      * @param layerName the name of the layer.
    89      * @param layerType the type of the layer.
    90      * @return the layer or <code>null</code>.
    91      */
    92     public <LayerType extends Layer> LayerType findGpsLayer(String layerName, Class<LayerType> layerType) {
    93         LayerType result = null;
    94         if(Main.map != null && Main.map.mapView != null) {
    95             for(Layer layer : Main.map.mapView.getAllLayers()) {
    96                 if(layerName.equals(layer.name) && layerType.isAssignableFrom(layer.getClass())) {
    97                     result = (LayerType) layer;
    98                     break;
    99                 }
    100             }
    101         }
    102         return result;
    103     }
    104    
    105    
    106     /**
    107      * Returns the writer that writes the data. Override this method, if another type
    108      * of writer should be used.
    109      * @return the writer.
    110      */
    111     public XmlWriter.OsmWriterInterface getXmlWriter() {
    112         return null;
    113 
    114         /*
    115          * FIXME! this disables auto-save. need to work with new GPX writing code in JOSM.
    116          *
    117         RawGpsLayer gpsLayer = findGpsLayer(gpsLayerName, RawGpsLayer.class);
    118         if(gpsLayer == null) {
    119             return null;
    120         }
    121         return new GpxWriter.Trk(gpsLayer.data);
    122         */
    123     }
    124 
    125 
    12690}
  • applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/action/SetWaypointAction.java

    r5270 r6164  
    77import static org.openstreetmap.josm.tools.I18n.tr;
    88
    9 import java.util.ArrayList;
    109import java.util.Collection;
    1110
    1211import javax.swing.JToggleButton;
    1312
     13import livegps.LiveGpsLayer;
    1414import livegps.LiveGpsLock;
    1515
     
    1717import org.openstreetmap.josm.data.coor.LatLon;
    1818import org.openstreetmap.josm.data.gpx.GpxData;
     19import org.openstreetmap.josm.data.gpx.WayPoint;
     20import org.openstreetmap.josm.gui.layer.GpxLayer;
    1921import org.openstreetmap.josm.gui.layer.Layer;
    2022import org.openstreetmap.josm.gui.layer.markerlayer.Marker;
     
    2426import at.dallermassl.josm.plugin.surveyor.SurveyorPlugin;
    2527import at.dallermassl.josm.plugin.surveyor.action.gui.WaypointDialog;
     28import at.dallermassl.josm.plugin.surveyor.util.LayerUtil;
    2629
    2730/**
     
    3336 */
    3437public class SetWaypointAction extends AbstractSurveyorAction {
     38    private LiveGpsLayer liveGpsLayer;
    3539    private MarkerLayer markerLayer;
    3640    public static final String MARKER_LAYER_NAME = "surveyorwaypointlayer";
     
    3842   
    3943    /**
    40      * Default Condstructor
     44     * Default Constructor.
    4145     */
    4246    public SetWaypointAction() {
     
    5155        LatLon coordinates = event.getCoordinates();
    5256        System.out.println(getClass().getSimpleName() + " KOORD: " + coordinates.lat() + ", " + coordinates.lon());
    53         MarkerLayer layer = getGpsLayer();
    5457        String markerTitle = getParameters().get(0);
    5558        Object source = event.getSource();
     
    7477       
    7578        String iconName = getParameters().size() > 1 ? getParameters().get(1) : null;
     79       
     80        // add the waypoint to the marker layer AND to the gpx layer
     81        // (easy export of data + waypoints):
     82        MarkerLayer layer = getMarkerLayer();
     83        GpxLayer gpsLayer = getGpxLayer();
     84        WayPoint waypoint = new WayPoint(event.getCoordinates());
     85        waypoint.attr.put("name", markerText);
     86        waypoint.attr.put("sym", iconName);
    7687        synchronized(LiveGpsLock.class) {
    7788            layer.data.add(new Marker(event.getCoordinates(), markerText, iconName));
     89            if(gpsLayer != null) {
     90                gpsLayer.data.waypoints.add(waypoint);
     91            }
    7892        }
     93       
    7994        Main.map.repaint();
    8095    }
    8196   
    82     public MarkerLayer getGpsLayer() {
     97    /**
     98     * Returns the marker layer with the name {@link #MARKER_LAYER_NAME}.
     99     * @return the marker layer with the name {@link #MARKER_LAYER_NAME}.
     100     */
     101    public MarkerLayer getMarkerLayer() {
    83102        if(markerLayer == null) {
    84             Collection<Layer> layers = Main.map.mapView.getAllLayers();
    85             for (Layer layer : layers) {
    86                 if(MARKER_LAYER_NAME.equals(layer.name)) {
    87                     markerLayer = (MarkerLayer) layer;
    88                     break;
    89                 }
    90             }
    91             // not found:
     103            markerLayer = LayerUtil.findGpsLayer(MARKER_LAYER_NAME, MarkerLayer.class);
     104           
    92105            if(markerLayer == null) {
     106                // not found, add a new one
    93107                markerLayer = new MarkerLayer(new GpxData(), MARKER_LAYER_NAME, null);
    94108                Main.main.addLayer(markerLayer);
     
    97111        return markerLayer;
    98112    }
     113   
     114    /**
     115     * Returns the gpx layer that is filled by the live gps data.
     116     * @return the gpx layer that is filled by the live gps data.
     117     */
     118    public GpxLayer getGpxLayer() {
     119        if(liveGpsLayer == null) {
     120            Collection<Layer> layers = Main.map.mapView.getAllLayers();
     121            for (Layer layer : layers) {
     122                if(layer instanceof LiveGpsLayer) {
     123                    liveGpsLayer = (LiveGpsLayer) layer;
     124                    break;
     125                }
     126            }
     127        }
     128        return liveGpsLayer;
     129    }
    99130
    100131}
Note: See TracChangeset for help on using the changeset viewer.