⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qgsgpsplugin.cpp

📁 一个非常好的GIS开源新版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  }    // did we get any data?  if (babelProcess.exitStatus() != 0) {    QString babelError(babelProcess.readStderr());    QString errorMsg(tr("Could not convert data from %1!\n\n")		     .arg(inputFilename));    errorMsg += babelError;    QMessageBox::warning(NULL, tr("Error converting data"), errorMsg);    return;  }    // add the layer  switch ( convertType )  {  case 0:    emit drawVectorLayer(outputFilename + "?type=waypoint", 			 layerName, "gpx");    break;  case 1:    emit drawVectorLayer(outputFilename + "?type=route", 			 layerName, "gpx");    break;  default:    QgsDebugMsg("Illegal conversion index!");    return;  }    emit closeGui();}void QgsGPSPlugin::downloadFromGPS(QString device, QString port,				   bool downloadWaypoints, bool downloadRoutes,				   bool downloadTracks, QString outputFilename,				   QString layerName) {    // what does the user want to download?  QString typeArg, features;  if (downloadWaypoints) {    typeArg = "-w";    features = "waypoints";  }  else if (downloadRoutes) {    typeArg = "-r";    features = "routes";  }  else if (downloadTracks) {    typeArg = "-t";    features = "tracks";  }    // try to start the gpsbabel process  QStringList babelArgs =     mDevices[device]->importCommand(mBabelPath, typeArg, 				    port, outputFilename);  if (babelArgs.isEmpty()) {    QMessageBox::warning(NULL, tr("Not supported"),			 QString(tr("This device does not support downloading ") +				 tr("of ")) + features + ".");    return;  }  QgsDebugMsg(QString("Download command: ") + babelArgs.join("|"));  Q3Process babelProcess(babelArgs);  if (!babelProcess.start()) {    QMessageBox::warning(NULL, tr("Could not start process"),			 tr("Could not start GPSBabel!"));    return;  }    // wait for gpsbabel to finish (or the user to cancel)  Q3ProgressDialog progressDialog(tr("Downloading data..."), tr("Cancel"), 0,				 NULL, 0, true);  progressDialog.show();  for (int i = 0; babelProcess.isRunning(); ++i) {    QCoreApplication::processEvents();    progressDialog.setProgress(i/64);    if (progressDialog.wasCanceled())      return;  }    // did we get any data?  if (babelProcess.exitStatus() != 0) {    QString babelError(babelProcess.readStderr());    QString errorMsg(tr("Could not download data from GPS!\n\n"));    errorMsg += babelError;    QMessageBox::warning(NULL, tr("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");    // everything was OK, remember the device and port for next time  QSettings settings;  settings.writeEntry("/Plugin-GPS/lastdldevice", device);  settings.writeEntry("/Plugin-GPS/lastdlport", port);    emit closeGui();}void QgsGPSPlugin::uploadToGPS(QgsVectorLayer* gpxLayer, QString device,			       QString port) {    const QString& source(gpxLayer->getDataProvider()->dataSourceUri());    // what kind of data does the user want to upload?  QString typeArg, features;  if (source.right(8) == "waypoint") {    typeArg = "-w";    features = "waypoints";  }  else if (source.right(5) == "route") {    typeArg = "-r";    features = "routes";  }  else if (source.right(5) == "track") {    typeArg = "-t";    features = "tracks";  }  else {    std::cerr << source.right(8).toLocal8Bit().data() << std::endl;    assert(false);  }    // try to start the gpsbabel process  QStringList babelArgs =     mDevices[device]->exportCommand(mBabelPath, typeArg, 				       source.left(source.findRev('?')), port);  if (babelArgs.isEmpty()) {    QMessageBox::warning(NULL, tr("Not supported"),			 QString(tr("This device does not support uploading of "))+			 features + ".");    return;  }  QgsDebugMsg(QString("Upload command: ") + babelArgs.join("|"));  Q3Process babelProcess(babelArgs);  if (!babelProcess.start()) {    QMessageBox::warning(NULL, tr("Could not start process"),			 tr("Could not start GPSBabel!"));    return;  }    // wait for gpsbabel to finish (or the user to cancel)  Q3ProgressDialog progressDialog(tr("Uploading data..."), tr("Cancel"), 0,				 NULL, 0, true);  progressDialog.show();  for (int i = 0; babelProcess.isRunning(); ++i) {    QCoreApplication::processEvents();    progressDialog.setProgress(i/64);    if (progressDialog.wasCanceled())      return;  }    // did we get an error?  if (babelProcess.exitStatus() != 0) {    QString babelError(babelProcess.readStderr());    QString errorMsg(tr("Error while uploading data to GPS!\n\n"));    errorMsg += babelError;    QMessageBox::warning(NULL, tr("Error uploading data"), errorMsg);    return;  }    // everything was OK, remember this device for next time  QSettings settings;  settings.writeEntry("/Plugin-GPS/lastuldevice", device);  settings.writeEntry("/Plugin-GPS/lastulport", port);    emit closeGui();}void QgsGPSPlugin::setupBabel() {    // where is gpsbabel?  QSettings settings;  mBabelPath = settings.value("/Plugin-GPS/gpsbabelpath", "").toString();  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 QgsGPSDevice("%babel -w -i garmin -o gpx %in %out",		     "%babel -w -i gpx -o garmin %in %out",		     "%babel -r -i garmin -o gpx %in %out",		     "%babel -r -i gpx -o garmin %in %out",		     "%babel -t -i garmin -o gpx %in %out",		     "%babel -t -i gpx -o garmin %in %out");  QStringList deviceNames = settings.value("/Plugin-GPS/devicelist").                             toStringList();  QStringList::const_iterator iter;  for (iter = deviceNames.begin(); iter != deviceNames.end(); ++iter) {    QString wptDownload = settings.      value(QString("/Plugin-GPS/devices/%1/wptdownload").       arg(*iter), "").toString();    QString wptUpload = settings.      value(QString("/Plugin-GPS/devices/%1/wptupload").arg(*iter), "").       toString();    QString rteDownload = settings.      value(QString("/Plugin-GPS/devices/%1/rtedownload").arg(*iter), "").       toString();    QString rteUpload = settings.      value(QString("/Plugin-GPS/devices/%1/rteupload").arg(*iter), "").       toString();    QString trkDownload = settings.      value(QString("/Plugin-GPS/devices/%1/trkdownload").arg(*iter), "").       toString();    QString trkUpload = settings.      value(QString("/Plugin-GPS/devices/%1/trkupload").arg(*iter), "").       toString();    mDevices[*iter] = new QgsGPSDevice(wptDownload, wptUpload,				       rteDownload, rteUpload,				       trkDownload, trkUpload);  }}/**  * 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 classQGISEXTERN QgisPlugin * classFactory(QgisInterface * theQgisInterfacePointer){  return new QgsGPSPlugin(theQgisInterfacePointer);}// 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.QGISEXTERN QString name(){  return name_;}// Return the descriptionQGISEXTERN QString description(){  return description_;}// Return the type (either UI or MapLayer plugin)QGISEXTERN int type(){  return type_;}// Return the version number for the pluginQGISEXTERN QString version(){  return version_;}// Delete ourselfQGISEXTERN void unload(QgisPlugin * thePluginPointer){  delete thePluginPointer;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -