2004-03-22 23:38:26 +00:00
|
|
|
/***************************************************************************
|
2004-10-22 13:16:58 +00:00
|
|
|
qgsgpsplugin.cpp - GPS related tools
|
|
|
|
-------------------
|
|
|
|
Date : Jan 21, 2004
|
|
|
|
Copyright : (C) 2004 by Tim Sutton
|
|
|
|
Email : tim@linfiniti.com
|
2004-03-22 23:38:26 +00:00
|
|
|
|
2004-10-22 13:16:58 +00:00
|
|
|
***************************************************************************/
|
2004-03-22 23:38:26 +00:00
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************/
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
// includes
|
|
|
|
|
|
|
|
#include "../../src/qgisapp.h"
|
2004-06-14 22:37:38 +00:00
|
|
|
#include "../../src/qgsmaplayerregistry.h"
|
2004-03-22 23:38:26 +00:00
|
|
|
#include "../../src/qgsmaplayer.h"
|
2004-06-21 11:49:58 +00:00
|
|
|
#include "../../src/qgsvectorlayer.h"
|
2004-07-05 09:43:46 +00:00
|
|
|
#include "../../src/qgsdataprovider.h"
|
2004-10-22 13:16:58 +00:00
|
|
|
#include "qgsgpsplugin.h"
|
2004-03-22 23:38:26 +00:00
|
|
|
|
|
|
|
|
2004-07-05 09:43:46 +00:00
|
|
|
#include <qeventloop.h>
|
2004-05-08 12:08:20 +00:00
|
|
|
#include <qfiledialog.h>
|
2004-03-22 23:38:26 +00:00
|
|
|
#include <qtoolbar.h>
|
|
|
|
#include <qmenubar.h>
|
|
|
|
#include <qmessagebox.h>
|
|
|
|
#include <qpopupmenu.h>
|
|
|
|
#include <qlineedit.h>
|
|
|
|
#include <qaction.h>
|
|
|
|
#include <qapplication.h>
|
|
|
|
#include <qcursor.h>
|
2004-07-05 09:43:46 +00:00
|
|
|
#include <qprocess.h>
|
|
|
|
#include <qprogressdialog.h>
|
2004-10-21 22:24:31 +00:00
|
|
|
#include <qsettings.h>
|
|
|
|
#include <qstringlist.h>
|
2004-03-22 23:38:26 +00:00
|
|
|
|
|
|
|
//non qt includes
|
2004-07-05 09:43:46 +00:00
|
|
|
#include <cassert>
|
2004-11-02 19:09:35 +00:00
|
|
|
#include <fstream>
|
2004-03-22 23:38:26 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
//the gui subclass
|
2004-10-22 13:16:58 +00:00
|
|
|
#include "qgsgpsplugingui.h"
|
2004-03-22 23:38:26 +00:00
|
|
|
|
|
|
|
// xpm for creating the toolbar icon
|
|
|
|
#include "icon.xpm"
|
2004-08-16 18:28:29 +00:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
#define QGISEXTERN extern "C" __declspec( dllexport )
|
|
|
|
#else
|
|
|
|
#define QGISEXTERN extern "C"
|
|
|
|
#endif
|
|
|
|
|
2004-04-11 09:55:03 +00:00
|
|
|
|
2004-10-22 13:16:58 +00:00
|
|
|
static const char * const ident_ =
|
|
|
|
"$Id$";
|
2004-05-14 11:47:12 +00:00
|
|
|
static const char * const name_ = "GPS Tools";
|
2004-10-22 13:16:58 +00:00
|
|
|
static const char * const description_ =
|
|
|
|
"Tools for loading and importing GPS data.";
|
2004-04-11 09:55:03 +00:00
|
|
|
static const char * const version_ = "Version 0.1";
|
|
|
|
static const QgisPlugin::PLUGINTYPE type_ = QgisPlugin::UI;
|
2004-10-22 13:16:58 +00:00
|
|
|
|
|
|
|
|
2004-03-22 23:38:26 +00:00
|
|
|
/**
|
|
|
|
* Constructor for the plugin. The plugin is passed a pointer to the main app
|
|
|
|
* and an interface object that provides access to exposed functions in QGIS.
|
|
|
|
* @param qgis Pointer to the QGIS main window
|
|
|
|
* @param _qI Pointer to the QGIS interface object
|
|
|
|
*/
|
2004-10-22 13:16:58 +00:00
|
|
|
QgsGPSPlugin::QgsGPSPlugin(QgisApp * theQGisApp, QgisIface * theQgisInterFace):
|
|
|
|
mMainWindowPointer(theQGisApp),
|
|
|
|
mQGisInterface(theQgisInterFace),
|
|
|
|
QgisPlugin(name_,description_,version_,type_)
|
2004-03-22 23:38:26 +00:00
|
|
|
{
|
2004-10-21 22:24:31 +00:00
|
|
|
setupBabel();
|
2004-03-22 23:38:26 +00:00
|
|
|
}
|
|
|
|
|
2004-10-22 13:16:58 +00:00
|
|
|
QgsGPSPlugin::~QgsGPSPlugin()
|
2004-03-22 23:38:26 +00:00
|
|
|
{
|
2004-10-21 22:24:31 +00:00
|
|
|
// delete all our babel formats
|
|
|
|
BabelMap::iterator iter;
|
|
|
|
for (iter = mImporters.begin(); iter != mImporters.end(); ++iter)
|
|
|
|
delete iter->second;
|
|
|
|
for (iter = mDevices.begin(); iter != mDevices.end(); ++iter)
|
|
|
|
delete iter->second;
|
2004-03-22 23:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the GUI interface for the plugin
|
|
|
|
*/
|
2004-10-22 13:16:58 +00:00
|
|
|
void QgsGPSPlugin::initGui()
|
2004-03-22 23:38:26 +00:00
|
|
|
{
|
|
|
|
// add a menu with 2 items
|
2004-10-22 13:16:58 +00:00
|
|
|
QPopupMenu *pluginMenu = new QPopupMenu(mMainWindowPointer);
|
2004-05-13 23:53:20 +00:00
|
|
|
pluginMenu->insertItem(QIconSet(icon),"&Gps Tools", this, SLOT(run()));
|
2004-11-02 19:09:35 +00:00
|
|
|
pluginMenu->insertItem("&Create new GPX layer", this, SLOT(createGPX()));
|
2004-10-22 13:16:58 +00:00
|
|
|
mMenuBarPointer = ((QMainWindow *) mMainWindowPointer)->menuBar();
|
|
|
|
mMenuId = mQGisInterface->addMenu("&Gps", pluginMenu);
|
2004-03-22 23:38:26 +00:00
|
|
|
|
2004-10-21 22:24:31 +00:00
|
|
|
// add an action to the toolbar
|
2004-10-22 13:16:58 +00:00
|
|
|
mQActionPointer = new QAction("Gps Tools", QIconSet(icon), "&Wmi",0,
|
|
|
|
this, "run");
|
|
|
|
connect(mQActionPointer, SIGNAL(activated()), this, SLOT(run()));
|
|
|
|
mQGisInterface->addToolBarIcon(mQActionPointer);
|
2004-03-22 23:38:26 +00:00
|
|
|
}
|
|
|
|
|
2004-04-11 11:29:51 +00:00
|
|
|
//method defined in interface
|
2004-10-22 13:16:58 +00:00
|
|
|
void QgsGPSPlugin::help()
|
2004-04-11 11:29:51 +00:00
|
|
|
{
|
|
|
|
//implement me!
|
|
|
|
}
|
|
|
|
|
2004-03-22 23:38:26 +00:00
|
|
|
// Slot called when the buffer menu item is activated
|
2004-10-22 13:16:58 +00:00
|
|
|
void QgsGPSPlugin::run()
|
2004-03-22 23:38:26 +00:00
|
|
|
{
|
2004-06-21 11:49:58 +00:00
|
|
|
// find all GPX layers
|
|
|
|
std::vector<QgsVectorLayer*> gpxLayers;
|
2004-06-27 21:26:07 +00:00
|
|
|
std::map<QString, QgsMapLayer*>::const_iterator iter;
|
2004-10-22 13:16:58 +00:00
|
|
|
std::cerr<<"LAYERS: "<<mQGisInterface->getLayerRegistry()->
|
2004-10-21 22:24:31 +00:00
|
|
|
mapLayers().size()<<std::endl;
|
2004-10-22 13:16:58 +00:00
|
|
|
for (iter = mQGisInterface->getLayerRegistry()->mapLayers().begin();
|
|
|
|
iter != mQGisInterface->getLayerRegistry()->mapLayers().end(); ++iter) {
|
2004-10-21 22:24:31 +00:00
|
|
|
std::cerr<<iter->second->name()<<std::endl;
|
2004-06-27 21:26:07 +00:00
|
|
|
if (iter->second->type() == QgsMapLayer::VECTOR) {
|
2004-10-21 22:24:31 +00:00
|
|
|
QgsVectorLayer* vLayer = dynamic_cast<QgsVectorLayer*>(iter->second);
|
|
|
|
if (vLayer->providerType() == "gpx")
|
|
|
|
gpxLayers.push_back(vLayer);
|
2004-06-27 21:26:07 +00:00
|
|
|
}
|
|
|
|
}
|
2004-10-21 22:24:31 +00:00
|
|
|
std::cerr<<std::endl;
|
2004-06-21 11:49:58 +00:00
|
|
|
|
2004-10-22 13:16:58 +00:00
|
|
|
QgsGPSPluginGui *myPluginGui =
|
|
|
|
new QgsGPSPluginGui(mImporters, mDevices, gpxLayers, mMainWindowPointer,
|
|
|
|
"GPS Tools", true, 0);
|
2004-03-22 23:38:26 +00:00
|
|
|
//listen for when the layer has been made so we can draw it
|
2004-10-21 22:24:31 +00:00
|
|
|
connect(myPluginGui, SIGNAL(drawRasterLayer(QString)),
|
|
|
|
this, SLOT(drawRasterLayer(QString)));
|
|
|
|
connect(myPluginGui, SIGNAL(drawVectorLayer(QString,QString,QString)),
|
|
|
|
this, SLOT(drawVectorLayer(QString,QString,QString)));
|
2004-07-05 09:43:46 +00:00
|
|
|
connect(myPluginGui, SIGNAL(loadGPXFile(QString, bool, bool, bool)),
|
|
|
|
this, SLOT(loadGPXFile(QString, bool, bool, bool)));
|
2004-10-21 22:24:31 +00:00
|
|
|
connect(myPluginGui, SIGNAL(importGPSFile(QString, QgsBabelFormat*, bool,
|
|
|
|
bool, bool, QString, QString)),
|
|
|
|
this, SLOT(importGPSFile(QString, QgsBabelFormat*, bool, bool,
|
|
|
|
bool, QString, QString)));
|
2004-07-05 09:43:46 +00:00
|
|
|
connect(myPluginGui, SIGNAL(downloadFromGPS(QString, QString, bool, bool,
|
|
|
|
bool, QString, QString)),
|
|
|
|
this, SLOT(downloadFromGPS(QString, QString, bool, bool, bool,
|
|
|
|
QString, QString)));
|
|
|
|
connect(myPluginGui, SIGNAL(uploadToGPS(QgsVectorLayer*, QString, QString)),
|
|
|
|
this, SLOT(uploadToGPS(QgsVectorLayer*, QString, QString)));
|
2004-07-06 17:03:38 +00:00
|
|
|
connect(this, SIGNAL(closeGui()), myPluginGui, SLOT(close()));
|
|
|
|
|
2004-03-22 23:38:26 +00:00
|
|
|
myPluginGui->show();
|
|
|
|
}
|
2004-05-08 12:08:20 +00:00
|
|
|
|
2004-10-22 13:16:58 +00:00
|
|
|
|
2004-11-02 19:09:35 +00:00
|
|
|
void QgsGPSPlugin::createGPX() {
|
|
|
|
QString fileName =
|
|
|
|
QFileDialog::getSaveFileName("." , "GPS eXchange file (*.gpx)",
|
|
|
|
mMainWindowPointer, "OpenFileDialog",
|
|
|
|
"Save new GPX file as...");
|
|
|
|
if (!fileName.isEmpty()) {
|
|
|
|
QFileInfo fileInfo(fileName);
|
|
|
|
std::ofstream ofs((const char*)fileName);
|
|
|
|
if (!ofs) {
|
|
|
|
QMessageBox::warning(NULL, "Could not create file",
|
|
|
|
"Unable to create a GPX file with the given name. "
|
|
|
|
"Try again with another name or in another "
|
|
|
|
"directory.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ofs<<"<gpx></gpx>"<<std::endl;
|
|
|
|
|
|
|
|
emit drawVectorLayer(fileName + "?type=track",
|
|
|
|
fileInfo.baseName() + ", tracks", "gpx");
|
|
|
|
emit drawVectorLayer(fileName + "?type=route",
|
|
|
|
fileInfo.baseName() + ", routes", "gpx");
|
|
|
|
emit drawVectorLayer(fileName + "?type=waypoint",
|
|
|
|
fileInfo.baseName() + ", waypoints", "gpx");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-22 13:16:58 +00:00
|
|
|
void QgsGPSPlugin::drawVectorLayer(QString thePathNameQString,
|
|
|
|
QString theBaseNameQString,
|
|
|
|
QString theProviderQString)
|
2004-03-22 23:38:26 +00:00
|
|
|
{
|
2004-10-22 13:16:58 +00:00
|
|
|
mQGisInterface->addVectorLayer(thePathNameQString, theBaseNameQString,
|
|
|
|
theProviderQString);
|
2004-03-22 23:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unload the plugin by cleaning up the GUI
|
2004-10-22 13:16:58 +00:00
|
|
|
void QgsGPSPlugin::unload()
|
2004-03-22 23:38:26 +00:00
|
|
|
{
|
|
|
|
// remove the GUI
|
2004-10-22 13:16:58 +00:00
|
|
|
mMenuBarPointer->removeItem(mMenuId);
|
|
|
|
mQGisInterface->removeToolBarIcon(mQActionPointer);
|
|
|
|
delete mQActionPointer;
|
2004-03-22 23:38:26 +00:00
|
|
|
}
|
2004-07-05 09:43:46 +00:00
|
|
|
|
2004-10-22 13:16:58 +00:00
|
|
|
void QgsGPSPlugin::loadGPXFile(QString filename, bool loadWaypoints, bool loadRoutes,
|
|
|
|
bool loadTracks) {
|
2004-07-05 09:43:46 +00:00
|
|
|
|
|
|
|
//check if input file is readable
|
|
|
|
QFileInfo fileInfo(filename);
|
|
|
|
if (!fileInfo.isReadable()) {
|
2004-09-23 09:07:50 +00:00
|
|
|
QMessageBox::warning(NULL, "GPX Loader",
|
2004-07-05 09:43:46 +00:00
|
|
|
"Unable to read the selected file.\n"
|
|
|
|
"Please reselect a valid file." );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-10-21 22:24:31 +00:00
|
|
|
// remember the directory
|
|
|
|
QSettings settings;
|
|
|
|
settings.writeEntry("/qgis/gps/gpxdirectory", fileInfo.dirPath());
|
|
|
|
|
2004-10-22 13:16:58 +00:00
|
|
|
// add the requested layers
|
2004-07-05 09:43:46 +00:00
|
|
|
if (loadTracks)
|
|
|
|
emit drawVectorLayer(filename + "?type=track",
|
|
|
|
fileInfo.baseName() + ", tracks", "gpx");
|
|
|
|
if (loadRoutes)
|
|
|
|
emit drawVectorLayer(filename + "?type=route",
|
|
|
|
fileInfo.baseName() + ", routes", "gpx");
|
|
|
|
if (loadWaypoints)
|
|
|
|
emit drawVectorLayer(filename + "?type=waypoint",
|
|
|
|
fileInfo.baseName() + ", waypoints", "gpx");
|
2004-07-06 17:03:38 +00:00
|
|
|
|
|
|
|
emit closeGui();
|
2004-07-05 09:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-22 13:16:58 +00:00
|
|
|
void QgsGPSPlugin::importGPSFile(QString inputFilename, QgsBabelFormat* importer,
|
|
|
|
bool importWaypoints, bool importRoutes,
|
|
|
|
bool importTracks, QString outputFilename,
|
|
|
|
QString layerName) {
|
2004-07-05 09:43:46 +00:00
|
|
|
|
|
|
|
// what features does the user want to import?
|
|
|
|
QString typeArg;
|
|
|
|
if (importWaypoints)
|
|
|
|
typeArg = "-w";
|
|
|
|
else if (importRoutes)
|
|
|
|
typeArg = "-r";
|
|
|
|
else if (importTracks)
|
|
|
|
typeArg = "-t";
|
|
|
|
|
|
|
|
// try to start the gpsbabel process
|
2004-10-21 22:24:31 +00:00
|
|
|
QStringList babelArgs =
|
2004-10-22 13:16:58 +00:00
|
|
|
importer->importCommand(mBabelPath, typeArg,
|
2004-10-21 22:24:31 +00:00
|
|
|
inputFilename, outputFilename);
|
2004-07-05 09:43:46 +00:00
|
|
|
QProcess babelProcess(babelArgs);
|
|
|
|
if (!babelProcess.start()) {
|
|
|
|
QMessageBox::warning(NULL, "Could not start process",
|
|
|
|
"Could not start GPSBabel!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// wait for gpsbabel to finish (or the user to cancel)
|
|
|
|
QProgressDialog progressDialog("Importing data...", "Cancel", 0,
|
|
|
|
NULL, 0, true);
|
|
|
|
progressDialog.show();
|
|
|
|
for (int i = 0; babelProcess.isRunning(); ++i) {
|
|
|
|
QApplication::eventLoop()->processEvents(0);
|
|
|
|
progressDialog.setProgress(i/64);
|
|
|
|
if (progressDialog.wasCancelled())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// did we get any data?
|
|
|
|
if (babelProcess.exitStatus() != 0) {
|
|
|
|
QString babelError(babelProcess.readStderr());
|
|
|
|
QString errorMsg(QString("Could not import data from %1!\n\n")
|
|
|
|
.arg(inputFilename));
|
|
|
|
errorMsg += babelError;
|
|
|
|
QMessageBox::warning(NULL, "Error importing data", errorMsg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the layer
|
|
|
|
if (importTracks)
|
|
|
|
emit drawVectorLayer(outputFilename + "?type=track",
|
|
|
|
layerName, "gpx");
|
|
|
|
if (importRoutes)
|
|
|
|
emit drawVectorLayer(outputFilename + "?type=route",
|
|
|
|
layerName, "gpx");
|
|
|
|
if (importWaypoints)
|
|
|
|
emit drawVectorLayer(outputFilename + "?type=waypoint",
|
|
|
|
layerName, "gpx");
|
2004-07-06 17:03:38 +00:00
|
|
|
|
|
|
|
emit closeGui();
|
2004-07-05 09:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-22 13:16:58 +00:00
|
|
|
void QgsGPSPlugin::downloadFromGPS(QString device, QString port,
|
|
|
|
bool downloadWaypoints, bool downloadRoutes,
|
|
|
|
bool downloadTracks, QString outputFilename,
|
|
|
|
QString layerName) {
|
2004-10-21 22:24:31 +00:00
|
|
|
|
2004-07-05 09:43:46 +00:00
|
|
|
// what does the user want to download?
|
|
|
|
QString typeArg;
|
|
|
|
if (downloadWaypoints)
|
|
|
|
typeArg = "-w";
|
|
|
|
else if (downloadRoutes)
|
|
|
|
typeArg = "-r";
|
|
|
|
else if (downloadTracks)
|
|
|
|
typeArg = "-t";
|
|
|
|
|
|
|
|
// try to start the gpsbabel process
|
2004-10-21 22:24:31 +00:00
|
|
|
QStringList babelArgs =
|
2004-10-22 13:16:58 +00:00
|
|
|
mDevices[device]->importCommand(mBabelPath, typeArg,
|
2004-10-21 22:24:31 +00:00
|
|
|
port, outputFilename);
|
2004-07-05 09:43:46 +00:00
|
|
|
QProcess babelProcess(babelArgs);
|
|
|
|
if (!babelProcess.start()) {
|
|
|
|
QMessageBox::warning(NULL, "Could not start process",
|
|
|
|
"Could not start GPSBabel!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// wait for gpsbabel to finish (or the user to cancel)
|
|
|
|
QProgressDialog progressDialog("Downloading data...", "Cancel", 0,
|
|
|
|
NULL, 0, true);
|
|
|
|
progressDialog.show();
|
|
|
|
for (int i = 0; babelProcess.isRunning(); ++i) {
|
|
|
|
QApplication::eventLoop()->processEvents(0);
|
|
|
|
progressDialog.setProgress(i/64);
|
|
|
|
if (progressDialog.wasCancelled())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// did we get any data?
|
|
|
|
if (babelProcess.exitStatus() != 0) {
|
|
|
|
QString babelError(babelProcess.readStderr());
|
|
|
|
QString errorMsg("Could not download data from GPS!\n\n");
|
|
|
|
errorMsg += babelError;
|
|
|
|
QMessageBox::warning(NULL, "Error downloading data", errorMsg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the layer
|
|
|
|
if (downloadWaypoints)
|
|
|
|
emit drawVectorLayer(outputFilename + "?type=waypoint",
|
|
|
|
layerName, "gpx");
|
|
|
|
if (downloadRoutes)
|
|
|
|
emit drawVectorLayer(outputFilename + "?type=route",
|
|
|
|
layerName, "gpx");
|
|
|
|
if (downloadTracks)
|
|
|
|
emit drawVectorLayer(outputFilename + "?type=track",
|
|
|
|
layerName, "gpx");
|
2004-07-06 17:03:38 +00:00
|
|
|
|
2004-10-21 22:24:31 +00:00
|
|
|
// everything was OK, remember the device and port for next time
|
|
|
|
QSettings settings;
|
|
|
|
settings.writeEntry("/qgis/gps/lastdldevice", device);
|
|
|
|
settings.writeEntry("/qgis/gps/lastdlport", port);
|
|
|
|
|
2004-07-06 17:03:38 +00:00
|
|
|
emit closeGui();
|
2004-07-05 09:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-22 13:16:58 +00:00
|
|
|
void QgsGPSPlugin::uploadToGPS(QgsVectorLayer* gpxLayer, QString device,
|
|
|
|
QString port) {
|
2004-07-05 09:43:46 +00:00
|
|
|
|
|
|
|
const QString& source(gpxLayer->getDataProvider()->getDataSourceUri());
|
|
|
|
|
|
|
|
// what kind of data does the user want to upload?
|
|
|
|
QString typeArg;
|
|
|
|
if (source.right(8) == "waypoint")
|
|
|
|
typeArg = "-w";
|
|
|
|
else if (source.right(5) == "route")
|
|
|
|
typeArg = "-r";
|
|
|
|
else if (source.right(5) == "track")
|
|
|
|
typeArg = "-t";
|
|
|
|
else {
|
|
|
|
std::cerr<<source.right(8)<<std::endl;
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// try to start the gpsbabel process
|
2004-10-21 22:24:31 +00:00
|
|
|
QStringList babelArgs =
|
2004-10-22 13:16:58 +00:00
|
|
|
mDevices[device]->exportCommand(mBabelPath, typeArg,
|
2004-10-21 22:24:31 +00:00
|
|
|
source.left(source.findRev('?')), port);
|
2004-07-05 09:43:46 +00:00
|
|
|
QProcess babelProcess(babelArgs);
|
|
|
|
if (!babelProcess.start()) {
|
|
|
|
QMessageBox::warning(NULL, "Could not start process",
|
|
|
|
"Could not start GPSBabel!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// wait for gpsbabel to finish (or the user to cancel)
|
|
|
|
QProgressDialog progressDialog("Uploading data...", "Cancel", 0,
|
|
|
|
NULL, 0, true);
|
|
|
|
progressDialog.show();
|
|
|
|
for (int i = 0; babelProcess.isRunning(); ++i) {
|
|
|
|
QApplication::eventLoop()->processEvents(0);
|
|
|
|
progressDialog.setProgress(i/64);
|
|
|
|
if (progressDialog.wasCancelled())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// did we get an error?
|
|
|
|
if (babelProcess.exitStatus() != 0) {
|
|
|
|
QString babelError(babelProcess.readStderr());
|
|
|
|
QString errorMsg("Error while uploading data to GPS!\n\n");
|
|
|
|
errorMsg += babelError;
|
|
|
|
QMessageBox::warning(NULL, "Error uploading data", errorMsg);
|
|
|
|
return;
|
|
|
|
}
|
2004-07-06 17:03:38 +00:00
|
|
|
|
2004-10-21 22:24:31 +00:00
|
|
|
// everything was OK, remember this device for next time
|
|
|
|
QSettings settings;
|
|
|
|
settings.writeEntry("/qgis/gps/lastuldevice", device);
|
|
|
|
settings.writeEntry("/qgis/gps/lastulport", port);
|
|
|
|
|
2004-07-06 17:03:38 +00:00
|
|
|
emit closeGui();
|
2004-07-05 09:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-22 13:16:58 +00:00
|
|
|
void QgsGPSPlugin::setupBabel() {
|
2004-10-21 22:24:31 +00:00
|
|
|
|
|
|
|
// where is gpsbabel?
|
|
|
|
QSettings settings;
|
|
|
|
mBabelPath = settings.readEntry("/qgis/gps/gpsbabelpath");
|
|
|
|
if (mBabelPath.isEmpty())
|
|
|
|
mBabelPath = "gpsbabel";
|
|
|
|
// the importable formats
|
|
|
|
mImporters["Geocaching.com .loc"] =
|
|
|
|
new QgsSimpleBabelFormat("geo", true, false, false);
|
|
|
|
mImporters["Magellan Mapsend"] =
|
|
|
|
new QgsSimpleBabelFormat("mapsend", true, true, true);
|
|
|
|
mImporters["Garmin PCX5"] =
|
|
|
|
new QgsSimpleBabelFormat("pcx", true, false, true);
|
|
|
|
mImporters["Garmin Mapsource"] =
|
|
|
|
new QgsSimpleBabelFormat("mapsource", true, true, true);
|
|
|
|
mImporters["GPSUtil"] =
|
|
|
|
new QgsSimpleBabelFormat("gpsutil", true, false, false);
|
|
|
|
mImporters["PocketStreets 2002/2003 Pushpin"] =
|
|
|
|
new QgsSimpleBabelFormat("psp", true, false, false);
|
|
|
|
mImporters["CoPilot Flight Planner"] =
|
|
|
|
new QgsSimpleBabelFormat("copilot", true, false, false);
|
|
|
|
mImporters["Magellan Navigator Companion"] =
|
|
|
|
new QgsSimpleBabelFormat("magnav", true, false, false);
|
|
|
|
mImporters["Holux"] =
|
|
|
|
new QgsSimpleBabelFormat("holux", true, false, false);
|
|
|
|
mImporters["Topo by National Geographic"] =
|
|
|
|
new QgsSimpleBabelFormat("tpg", true, false, false);
|
|
|
|
mImporters["TopoMapPro"] =
|
|
|
|
new QgsSimpleBabelFormat("tmpro", true, false, false);
|
|
|
|
mImporters["GeocachingDB"] =
|
|
|
|
new QgsSimpleBabelFormat("gcdb", true, false, false);
|
|
|
|
mImporters["Tiger"] =
|
|
|
|
new QgsSimpleBabelFormat("tiger", true, false, false);
|
|
|
|
mImporters["EasyGPS Binary Format"] =
|
|
|
|
new QgsSimpleBabelFormat("easygps", true, false, false);
|
|
|
|
mImporters["Delorme Routes"] =
|
|
|
|
new QgsSimpleBabelFormat("saroute", false, false, true);
|
|
|
|
mImporters["Navicache"] =
|
|
|
|
new QgsSimpleBabelFormat("navicache", true, false, false);
|
|
|
|
mImporters["PSITrex"] =
|
|
|
|
new QgsSimpleBabelFormat("psitrex", true, true, true);
|
|
|
|
mImporters["Delorme GPS Log"] =
|
|
|
|
new QgsSimpleBabelFormat("gpl", false, false, true);
|
|
|
|
mImporters["OziExplorer"] =
|
|
|
|
new QgsSimpleBabelFormat("ozi", true, false, false);
|
|
|
|
mImporters["NMEA Sentences"] =
|
|
|
|
new QgsSimpleBabelFormat("nmea", true, false, true);
|
|
|
|
mImporters["Delorme Street Atlas 2004 Plus"] =
|
|
|
|
new QgsSimpleBabelFormat("saplus", true, false, false);
|
|
|
|
mImporters["Microsoft Streets and Trips"] =
|
|
|
|
new QgsSimpleBabelFormat("s_and_t", true, false, false);
|
|
|
|
mImporters["NIMA/GNIS Geographic Names"] =
|
|
|
|
new QgsSimpleBabelFormat("nima", true, false, false);
|
|
|
|
mImporters["Maptech"] =
|
|
|
|
new QgsSimpleBabelFormat("mxf", true, false, false);
|
|
|
|
mImporters["Mapopolis.com Mapconverter Application"] =
|
|
|
|
new QgsSimpleBabelFormat("mapconverter", true, false, false);
|
|
|
|
mImporters["GPSman"] =
|
|
|
|
new QgsSimpleBabelFormat("gpsman", true, false, false);
|
|
|
|
mImporters["GPSDrive"] =
|
|
|
|
new QgsSimpleBabelFormat("gpsdrive", true, false, false);
|
|
|
|
mImporters["Fugawi"] =
|
|
|
|
new QgsSimpleBabelFormat("fugawi", true, false, false);
|
|
|
|
mImporters["DNA"] =
|
|
|
|
new QgsSimpleBabelFormat("dna", true, false, false);
|
|
|
|
|
|
|
|
// and the GPS devices
|
|
|
|
mDevices["Garmin serial"] =
|
|
|
|
new QgsBabelCommand("%babel -i garmin -o gpx /dev/ttyS0 %out",
|
|
|
|
"%babel -i gpx -o garmin %in /dev/ttyS0");
|
|
|
|
QStringList deviceNames = settings.readListEntry("/qgis/gps/devicelist");
|
|
|
|
QStringList::iterator iter;
|
|
|
|
for (iter = deviceNames.begin(); iter != deviceNames.end(); ++iter) {
|
|
|
|
QString download = settings.
|
|
|
|
readEntry(QString("/qgis/gps/devices/%1/download").arg(*iter), "");
|
|
|
|
QString upload = settings.
|
|
|
|
readEntry(QString("/qgis/gps/devices/%1/upload").arg(*iter), "");
|
|
|
|
mDevices[*iter] = new QgsBabelCommand(download, upload);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-07-05 09:43:46 +00:00
|
|
|
|
2004-03-22 23:38:26 +00:00
|
|
|
/**
|
|
|
|
* Required extern functions needed for every plugin
|
|
|
|
* These functions can be called prior to creating an instance
|
|
|
|
* of the plugin class
|
|
|
|
*/
|
|
|
|
// Class factory to return a new instance of the plugin class
|
2004-10-22 13:16:58 +00:00
|
|
|
QGISEXTERN QgisPlugin * classFactory(QgisApp * theQGisAppPointer,
|
|
|
|
QgisIface * theQgisInterfacePointer)
|
2004-03-22 23:38:26 +00:00
|
|
|
{
|
2004-10-22 13:16:58 +00:00
|
|
|
return new QgsGPSPlugin(theQGisAppPointer, theQgisInterfacePointer);
|
2004-03-22 23:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the name of the plugin - note that we do not user class members as
|
|
|
|
// the class may not yet be insantiated when this method is called.
|
2004-08-16 18:28:29 +00:00
|
|
|
QGISEXTERN QString name()
|
2004-03-22 23:38:26 +00:00
|
|
|
{
|
2004-10-22 13:16:58 +00:00
|
|
|
return name_;
|
2004-03-22 23:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the description
|
2004-08-16 18:28:29 +00:00
|
|
|
QGISEXTERN QString description()
|
2004-03-22 23:38:26 +00:00
|
|
|
{
|
2004-10-22 13:16:58 +00:00
|
|
|
return description_;
|
2004-03-22 23:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the type (either UI or MapLayer plugin)
|
2004-08-16 18:28:29 +00:00
|
|
|
QGISEXTERN int type()
|
2004-03-22 23:38:26 +00:00
|
|
|
{
|
2004-10-22 13:16:58 +00:00
|
|
|
return type_;
|
2004-03-22 23:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the version number for the plugin
|
2004-08-16 18:28:29 +00:00
|
|
|
QGISEXTERN QString version()
|
2004-03-22 23:38:26 +00:00
|
|
|
{
|
2004-04-11 09:55:03 +00:00
|
|
|
return version_;
|
2004-03-22 23:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Delete ourself
|
2004-08-16 18:28:29 +00:00
|
|
|
QGISEXTERN void unload(QgisPlugin * thePluginPointer)
|
2004-03-22 23:38:26 +00:00
|
|
|
{
|
|
|
|
delete thePluginPointer;
|
|
|
|
}
|