Skip to content

Commit

Permalink
ignore invalid gps coordinate even if there seems to be a fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Feb 10, 2012
1 parent 549d96c commit 1d09182
Showing 1 changed file with 22 additions and 168 deletions.
190 changes: 22 additions & 168 deletions src/app/gps/qgsgpsinformationwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include "qgsgpsdetector.h"
#include "info.h"
#include "qgscoordinatetransform.h"
#include <qgspoint.h>
#include <qgsrubberband.h>
#include "qgspoint.h"
#include "qgsrubberband.h"
#include "qgsmaprenderer.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
Expand All @@ -30,7 +30,7 @@
#include "qgslogger.h"
#include "qgsfeatureaction.h"
#include "qgsgeometry.h"
#include <qgisapp.h>
#include "qgisapp.h"

//for avoid intersections static method
#include "qgsmaptooladdfeature.h"
Expand Down Expand Up @@ -59,10 +59,10 @@
#include <QPixmap>
#include <QPen>

QgsGPSInformationWidget::QgsGPSInformationWidget( QgsMapCanvas * thepCanvas, QWidget * parent, Qt::WindowFlags f ):
QWidget( parent, f ),
mNmea( 0 ),
mpCanvas( thepCanvas )
QgsGPSInformationWidget::QgsGPSInformationWidget( QgsMapCanvas * thepCanvas, QWidget * parent, Qt::WindowFlags f )
: QWidget( parent, f )
, mNmea( 0 )
, mpCanvas( thepCanvas )
{
setupUi( this );

Expand Down Expand Up @@ -323,20 +323,6 @@ void QgsGPSInformationWidget::on_mBtnTrackColor_clicked( )
}
}

#if 0 //no longer used
void QgsGPSInformationWidget::setTrackColor( )
{
QSettings mySettings;
QColor myColor( mySettings.value( "/qgis/gps/line_color_red", 255 ).toInt(),
mySettings.value( "/qgis/gps/line_color_green", 0 ).toInt(),
mySettings.value( "/qgis/gps/line_color_blue", 0 ).toInt() );
if ( mpRubberBand )
{
mpRubberBand->setColor( myColor );
}
}
#endif

void QgsGPSInformationWidget::on_mBtnPosition_clicked( )
{
mStackedWidget->setCurrentIndex( 0 );
Expand Down Expand Up @@ -444,8 +430,8 @@ void QgsGPSInformationWidget::timedout()
void QgsGPSInformationWidget::connected( QgsGPSConnection *conn )
{
mNmea = conn;
QObject::connect( mNmea, SIGNAL( stateChanged( const QgsGPSInformation& ) ),
this, SLOT( displayGPSInformation( const QgsGPSInformation& ) ) );
connect( mNmea, SIGNAL( stateChanged( const QgsGPSInformation& ) ),
this, SLOT( displayGPSInformation( const QgsGPSInformation& ) ) );
mGPSPlainTextEdit->appendPlainText( tr( "Connected!" ) );
mConnectButton->setText( tr( "Dis&connect" ) );
//insert connection into registry such that it can also be used by other dialogs or plugins
Expand All @@ -466,7 +452,7 @@ void QgsGPSInformationWidget::connected( QgsGPSConnection *conn )
// crude way to separate chunks - use when manually editing file - NMEA parsers should discard
mLogFileTextStream << "====" << "\r\n";

QObject::connect( mNmea, SIGNAL( nmeaSentenceReceived( const QString& ) ), this, SLOT( logNmeaSentence( const QString& ) ) ); // added to handle raw data
connect( mNmea, SIGNAL( nmeaSentenceReceived( const QString& ) ), this, SLOT( logNmeaSentence( const QString& ) ) ); // added to handle raw data
}
else // error opening file
{
Expand All @@ -483,7 +469,7 @@ void QgsGPSInformationWidget::disconnectGps()
{
if ( mLogFile && mLogFile->isOpen() )
{
QObject::disconnect( mNmea, SIGNAL( nmeaSentenceReceived( const QString& ) ), this, SLOT( logNmeaSentence( const QString& ) ) );
disconnect( mNmea, SIGNAL( nmeaSentenceReceived( const QString& ) ), this, SLOT( logNmeaSentence( const QString& ) ) );
mLogFile->close();
delete mLogFile;
mLogFile = 0;
Expand Down Expand Up @@ -585,34 +571,6 @@ void QgsGPSInformationWidget::displayGPSInformation( const QgsGPSInformation& in
#endif
} //signal

#if 0
if ( mStackedWidget->currentIndex() == 4 ) //debug
{
#if 0 // temporarily removed as the info isn't being set in GSA/GSV processing
// mGPSPlainTextEdit->appendPlainText( "Satellite" );
if ( currentInfo.inUse )
{
mGPSPlainTextEdit->appendPlainText( "Satellite In use" );
}
else
{
mGPSPlainTextEdit->appendPlainText( "Satellite Not in use" );
}
#endif
#if 0
mGPSPlainTextEdit->appendPlainText( "id: " + QString::number( currentInfo.id ) );
mGPSPlainTextEdit->appendPlainText( "elevation: " + QString::number( currentInfo.elevation ) );
mGPSPlainTextEdit->appendPlainText( "azimuth: " + QString::number( currentInfo.azimuth ) );
mGPSPlainTextEdit->appendPlainText( "signal: " + QString::number( currentInfo.signal ) );
#else // as a single line per satellite - easier to read
mGPSPlainTextEdit->appendPlainText( "sat: " + QString::number( currentInfo.id )
+ ", elev: " + QString::number( currentInfo.elevation )
+ ", azimuth: " + QString::number( currentInfo.azimuth )
+ ", signal: " + QString::number( currentInfo.signal ) );
#endif
} //debug
#endif

if ( mStackedWidget->currentIndex() == 2 && info.satInfoComplete ) //satellites
{
QColor bg( Qt::white ); // moved several items outside of the following if block to minimize loop time
Expand Down Expand Up @@ -671,6 +629,11 @@ void QgsGPSInformationWidget::displayGPSInformation( const QgsGPSInformation& in
mpSatellitesWidget->replot();
} //satellites

if ( validFlag )
{
validFlag = info.longitude >= -180.0 && info.longitude <= 180.0 && info.latitude >= -90.0 && info.latitude <= 90.0;
}

QgsPoint myNewCenter;
if ( validFlag )
{
Expand Down Expand Up @@ -708,32 +671,6 @@ void QgsGPSInformationWidget::displayGPSInformation( const QgsGPSInformation& in
mTxtStatus->setText( info.status == 'A' ? tr( "Valid" ) : info.status == 'V' ? tr( "Invalid" ) : "" );
} //position

#if 0
if ( mStackedWidget->currentIndex() == 4 ) //debug
{
QString s;
for ( int i = 0; i < info.satPrn.size(); i++ )
{
if ( info.satPrn.at( i ) > 0 ) //don't show 0 (no satellite)
{
s.append( QString::number( info.satPrn.at( i ) ).append( " " ) );
}
}
mGPSPlainTextEdit->appendPlainText( "UTC date/time: " + info.utcDateTime.toString() );
mGPSPlainTextEdit->appendPlainText( "longitude: " + QString::number( info.longitude, 'f', 8 ) );
mGPSPlainTextEdit->appendPlainText( "latitude: " + QString::number( info.latitude, 'f', 8 ) );
mGPSPlainTextEdit->appendPlainText( "elevation: " + QString::number( info.elevation ) );
mGPSPlainTextEdit->appendPlainText( "speed (knots): " + QString::number( info.speed ) );
mGPSPlainTextEdit->appendPlainText( "direction: " + QString::number( info.direction ) );
mGPSPlainTextEdit->appendPlainText( "pdop: " + QString::number( info.pdop ) );
mGPSPlainTextEdit->appendPlainText( "hdop: " + QString::number( info.hdop ) );
mGPSPlainTextEdit->appendPlainText( "vdop: " + QString::number( info.vdop ) );
mGPSPlainTextEdit->appendPlainText( "satellites in use: " + s );
mGPSPlainTextEdit->appendPlainText( "fix mode: " + QString( info.fixMode ) );
mGPSPlainTextEdit->appendPlainText( "fix type: " + QString::number( info.fixType ) );
} //debug
#endif

// Avoid refreshing / panning if we havent moved
if ( mLastGpsPosition != myNewCenter )
{
Expand Down Expand Up @@ -792,28 +729,15 @@ void QgsGPSInformationWidget::displayGPSInformation( const QgsGPSInformation& in
} // show marker
}

#if 0 // not needed - signals/slots set up in UI file; may be needed in the future if GPS valid is used to control whether button is available (should use enable/disable instead of show/hide)
void QgsGPSInformationWidget::on_mCbxAutoAddVertices_toggled( bool theFlag )
{
if ( theFlag )
{
mBtnAddVertex->hide();
}
else
{
mBtnAddVertex->show();
}
}
#endif

void QgsGPSInformationWidget::on_mBtnAddVertex_clicked( )
{
addVertex();
}

void QgsGPSInformationWidget::addVertex( )
void QgsGPSInformationWidget::addVertex()
{
QgsDebugMsg( "Adding Vertex" );

if ( !mpRubberBand )
{
createRubberBand( );
Expand All @@ -822,6 +746,7 @@ void QgsGPSInformationWidget::addVertex( )
// we store the capture list in wgs84 and then transform to layer crs when
// calling close feature
mCaptureList.push_back( mLastGpsPosition );

// we store the rubber band points in map canvas CRS so transform to map crs
// potential problem with transform errors and wrong coordinates if map CRS is changed after points are stored - SLM
// should catch map CRS change and transform the points
Expand All @@ -835,6 +760,7 @@ void QgsGPSInformationWidget::addVertex( )
{
myPoint = mLastGpsPosition;
}

mpRubberBand->addPoint( myPoint );
}

Expand All @@ -853,58 +779,6 @@ void QgsGPSInformationWidget::on_mBtnCloseFeature_clicked( )

// -------------- preconditions ------------------------
// most of these preconditions are already handled due to the button being enabled/disabled based on layer geom type and editing capabilities, but not on valid GPS data
#if 0
if ( !vlayer )
{
QMessageBox::information( 0, tr( "Not a vector layer" ),
tr( "The current layer is not a vector layer" ) );
return;
}
QGis::WkbType layerWKBType = vlayer->wkbType();

//no support for adding features to 2.5D types yet
if ( layerWKBType == QGis::WKBPoint25D ||
layerWKBType == QGis::WKBLineString25D ||
layerWKBType == QGis::WKBPolygon25D ||
layerWKBType == QGis::WKBMultiPoint25D ||
layerWKBType == QGis::WKBMultiLineString25D ||
layerWKBType == QGis::WKBMultiPolygon25D )
{
QMessageBox::critical( 0, tr( "2.5D shape type not supported" ), tr(
"Adding features to 2.5D shapetypes is not supported yet. Please "
"select a different editable, non 2.5D layer and try again." ) );
return;
}

// Multipart features not supported
if ( layerWKBType == QGis::WKBMultiPoint ||
layerWKBType == QGis::WKBMultiLineString ||
layerWKBType == QGis::WKBMultiPolygon )
{
QMessageBox::critical( 0, tr( "Multipart shape type not supported" ), tr(
"Adding features to multipart shapetypes is not supported yet. Please "
"select a different editable, non 2.5D layer and try again." ) );
return;

}

QgsVectorDataProvider* provider = vlayer->dataProvider();

if ( !( provider->capabilities() & QgsVectorDataProvider::AddFeatures ) )
{
QMessageBox::information( 0, tr( "Layer cannot be added to" ),
tr( "The data provider for this layer does not support the addition of features." ) );
return;
}

if ( !vlayer->isEditable() )
{
QMessageBox::information( 0, tr( "Layer not editable" ),
tr( "Cannot edit the vector layer. Use 'Toggle Editing' to make it editable." )
);
return;
}
#endif

//lines: bail out if there are not at least two vertices
if ( layerWKBType == QGis::WKBLineString && mCaptureList.size() < 2 )
Expand Down Expand Up @@ -1114,7 +988,8 @@ void QgsGPSInformationWidget::on_mBtnCloseFeature_clicked( )

void QgsGPSInformationWidget::connectGpsSlot( )
{
QObject::connect( mNmea, SIGNAL( stateChanged( const QgsGPSInformation& ) ), this, SLOT( displayGPSInformation( const QgsGPSInformation& ) ) );
connect( mNmea, SIGNAL( stateChanged( const QgsGPSInformation& ) ),
this, SLOT( displayGPSInformation( const QgsGPSInformation& ) ) );
}

void QgsGPSInformationWidget::on_mBtnRefreshDevices_clicked( )
Expand Down Expand Up @@ -1155,27 +1030,6 @@ void QgsGPSInformationWidget::createRubberBand( )
mpRubberBand->show();
}

#if 0 // this function isn't used
QPointF QgsGPSInformationWidget::gpsToPixelPosition( const QgsPoint& point )
{
//transform to map crs
QgsPoint myCenter;
if ( mpCanvas && mpCanvas->mapRenderer() )
{
QgsCoordinateTransform t( mWgs84CRS, mpCanvas->mapRenderer()->destinationCrs() );
myCenter = t.transform( point );
}
else
{
myCenter = point;
}

double x = myCenter.x(), y = myCenter.y();
mpCanvas->getCoordinateTransform()->transformInPlace( x, y );
return QPointF( x, y ) ;
}
#endif

void QgsGPSInformationWidget::on_mBtnLogFile_clicked()
{
//=========================
Expand Down

0 comments on commit 1d09182

Please sign in to comment.