[Marble-commits] KDE/kdeedu/marble/src/lib

Thibaut Gridel tgridel at free.fr
Sat Jun 19 18:13:37 CEST 2010


SVN commit 1139954 by tgridel:

PositionTracking: rely on geometryModel to draw track

 M  +1 -3      MarbleModel.cpp  
 M  +11 -0     Projections/AbstractProjection.cpp  
 M  +4 -0      Projections/AbstractProjection.h  
 M  +44 -46    gps/PositionTracking.cpp  
 M  +8 -13     gps/PositionTracking.h  


--- trunk/KDE/kdeedu/marble/src/lib/MarbleModel.cpp #1139953:1139954
@@ -211,9 +211,7 @@
              this,            SIGNAL( modelChanged() ) );
 
     d->m_gpxFileModel = new GpxFileModel( this );
-    GpxFile *gpxFile = new GpxFile();
-    d->m_gpxFileModel->addFile( gpxFile );
-    d->m_positionTracking = new PositionTracking( gpxFile, this );
+    d->m_positionTracking = new PositionTracking( d->m_dataFacade->geometryModel(), this );
 
     d->m_layerManager = new LayerManager( d->m_dataFacade, d->m_pluginManager, this );
 
--- trunk/KDE/kdeedu/marble/src/lib/Projections/AbstractProjection.cpp #1139953:1139954
@@ -112,6 +112,17 @@
     return screenCoordinates( geopoint, viewport, x, y, globeHidesPoint );
 }
 
+bool AbstractProjection::screenCoordinates( const GeoDataCoordinates &geopoint,
+                                            const ViewportParams *viewport,
+                                            QPointF &screenpoint )
+{
+    bool visible;
+    qreal x(0), y(0);
+    visible = screenCoordinates( geopoint, viewport, x, y );
+    screenpoint = QPointF( x,y );
+    return visible;
+}
+
 bool AbstractProjection::screenCoordinates( const GeoDataCoordinates &coordinates,
                                     const ViewportParams *viewport,
                                     qreal *x, qreal &y, int &pointRepeatNum, bool &globeHidesPoint )
--- trunk/KDE/kdeedu/marble/src/lib/Projections/AbstractProjection.h #1139953:1139954
@@ -141,6 +141,10 @@
                             const ViewportParams *viewport,
                             qreal &x, qreal &y );
 
+    bool screenCoordinates( const GeoDataCoordinates &geopoint,
+                            const ViewportParams *viewport,
+                            QPointF &screenpoint );
+
     /**
      * @brief Get the coordinates of screen points for geographical coordinates in the map.
      *
--- trunk/KDE/kdeedu/marble/src/lib/gps/PositionTracking.cpp #1139953:1139954
@@ -11,38 +11,39 @@
 
 #include "PositionTracking.h"
 
+#include "GeoDataDocument.h"
+#include "GeoDataPlacemark.h"
 #include "ClipPainter.h"
-#include "GpxFile.h"
-#include "Track.h"
-#include "TrackPoint.h"
-#include "TrackSegment.h"
+#include "AbstractProjection.h"
 #include "MarbleMath.h"
 #include "MarbleDebug.h"
+#include "MarbleGeometryModel.h"
 #include "ViewParams.h"
 
 using namespace Marble;
 
-PositionTracking::PositionTracking( GpxFile *currentGpx,
+PositionTracking::PositionTracking( MarbleGeometryModel *geometryModel,
                           QObject *parent ) 
-     : QObject( parent ), m_positionProvider(0)
+     : QObject( parent ), m_geometryModel(geometryModel), m_positionProvider(0)
 {
-    m_gpsCurrentPosition  = new TrackPoint( 0,0 );
-    m_gpsPreviousPosition = new TrackPoint( 0,0 );
-    m_gpsTracking         = new TrackPoint( 0,0 );
+    m_document     = new GeoDataDocument();
 
-    m_gpsTrack    = new Track();
-    currentGpx->addTrack( m_gpsTrack );
-    m_gpsTrackSeg = 0;
+    GeoDataPlacemark placemark;
+    GeoDataMultiGeometry multiGeometry;
+    GeoDataLineString lineString;
+
+    multiGeometry.append(lineString);
+    placemark.setGeometry(multiGeometry);
+    m_document->append(placemark);
+
+    m_geometryModel->setGeoDataRoot(m_document);
+    connect(this, SIGNAL(gpsLocation(GeoDataCoordinates,qreal)),
+            m_geometryModel, SLOT(update()));
 }
 
 
 PositionTracking::~PositionTracking()
 {
-    delete m_gpsCurrentPosition;
-    delete m_gpsPreviousPosition;
-    delete m_gpsTracking;
-
-    delete m_gpsTrack;
 }
 
 
@@ -52,10 +53,13 @@
     QPointF position;
     QPointF previousPosition;
 
-    m_gpsCurrentPosition->getPixelPos( canvasSize, viewParams, &position );
-    m_gpsPreviousPosition->getPixelPos( canvasSize, viewParams, &previousPosition );
+    viewParams->currentProjection()->screenCoordinates(m_gpsCurrentPosition,
+                                                       viewParams->viewport(),
+                                                       position);
+    viewParams->currentProjection()->screenCoordinates(m_gpsPreviousPosition,
+                                                       viewParams->viewport(),
+                                                       previousPosition);
 
-
     QPointF unitVector = ( position - previousPosition  ) ;
 
     if( unitVector.x() || unitVector.y() ) {
@@ -76,14 +80,12 @@
 }
 
 
-void PositionTracking::updateSpeed( TrackPoint* previous, TrackPoint* next )
+void PositionTracking::updateSpeed( GeoDataCoordinates& previous, GeoDataCoordinates next )
 {
     //This function makes the assumption that the update stage happens once
     //every second.
-    qreal distance = distanceSphere( previous->position().longitude(),
-                                     previous->position().latitude(),
-                                     next->position().longitude(),
-                                     next->position().latitude() );
+    qreal distance = distanceSphere( previous,
+                                     next );
     m_speed = distance * 60 * 60;
 }
 
@@ -93,32 +95,28 @@
     if ( m_positionProvider && m_positionProvider->status() ==
         PositionProviderStatusAvailable )
     {
-        m_gpsTracking->setPosition( position );
-        m_gpsTracking->setPosition( GeoDataCoordinates ( m_gpsTracking->position().longitude(GeoDataCoordinates::Degree),
-                                                         m_gpsTracking->position().latitude( GeoDataCoordinates::Degree ),
-                                                         m_gpsTracking->position().altitude(), GeoDataCoordinates::Degree ) );
 
+        GeoDataPlacemark placemark = m_document->features().last();
+        GeoDataMultiGeometry *geometry = static_cast<GeoDataMultiGeometry*>(placemark.geometry());
+        GeoDataLineString &lineString = static_cast<GeoDataLineString&>(geometry->last());
+        lineString.append(position);
 
-        if (m_gpsTrackSeg == 0 ) {
-            m_gpsTrackSeg = new TrackSegment();
-            m_gpsTrack->append( m_gpsTrackSeg );
+        if (m_geometryModel->geoDataRoot() != m_document) {
+            mDebug() << "setting geometrymodel";
+            m_geometryModel->setGeoDataRoot(m_document);
         }
+        mDebug() << "geometry size " << lineString.size();
 
         //if the position has moved then update the current position
-        if ( !( m_gpsPreviousPosition->position() ==
-                m_gpsTracking->position() ) )
+        if ( !( m_gpsCurrentPosition ==
+                position ) )
         {
-            m_gpsTrackSeg->append( m_gpsPreviousPosition );
-            m_gpsPreviousPosition = m_gpsCurrentPosition;
-            m_gpsCurrentPosition = new TrackPoint( *m_gpsTracking );
-            emit gpsLocation( m_gpsTracking->position(), m_speed );
+
+            m_gpsCurrentPosition = position;
+            emit gpsLocation( position, m_speed );
         }
-    } else {
-        if ( m_gpsTrackSeg && m_gpsTrackSeg->count() > 0 ) {
-            m_gpsTrackSeg = 0;
         }
     }
-}
 
 bool PositionTracking::update(const QSize &canvasSize, ViewParams *viewParams,
                          QRegion &reg) 
@@ -128,12 +126,12 @@
     {
         //updateSpeed updates the speed to radians and needs
         //to be multiplied by the radius
-        updateSpeed( m_gpsPreviousPosition, m_gpsTracking );
+        updateSpeed( m_gpsPreviousPosition, m_gpsCurrentPosition );
         m_speed *= viewParams->radius();
 
         //if the position has moved then update the current position
-        if ( !( m_gpsPreviousPosition->position() ==
-                m_gpsTracking->position() ) )
+        if ( !( m_gpsPreviousPosition ==
+                m_gpsCurrentPosition ) )
         {
             construct( canvasSize, viewParams );
 
@@ -145,7 +143,7 @@
                 rect.adjust( -5, -5, 10, 10 );
                 reg |= rect ;
             }
-
+            m_gpsPreviousPosition = m_gpsCurrentPosition;
             return true;
         } else {
             return false;
--- trunk/KDE/kdeedu/marble/src/lib/gps/PositionTracking.h #1139953:1139954
@@ -23,15 +23,12 @@
 namespace Marble
 {
 
+class GeoDataDocument;
 class ClipPainter;
-class GpxFile;
-class Track;
-class TrackPoint;
-class TrackSegment;
 class ViewParams;
-class Waypoint;
 class GeoDataCoordinates;
 class PluginManager;
+class MarbleGeometryModel;
 
 class PositionTracking : public QObject 
 {
@@ -39,7 +36,7 @@
 
 public:
 
-    explicit PositionTracking( GpxFile *currentGpx,
+    explicit PositionTracking( MarbleGeometryModel *geometryModel,
                           QObject *parent = 0 );
     ~PositionTracking();
 
@@ -87,7 +84,7 @@
                           GeoDataAccuracy accuracy );
 
  private:
-    void updateSpeed( TrackPoint* previous, TrackPoint* next );
+    void updateSpeed( GeoDataCoordinates& previous, GeoDataCoordinates next );
 
     qreal               m_speed;
     //used to draw the arrow in gps tracking
@@ -97,13 +94,11 @@
     QPolygonF           m_currentDraw;
     QPolygonF           m_previousDraw;
 
-    Waypoint            *m_currentPosition;
-    TrackPoint          *m_gpsCurrentPosition;
-    TrackPoint          *m_gpsPreviousPosition;
+    GeoDataDocument     *m_document;
+    MarbleGeometryModel *m_geometryModel;
 
-    TrackPoint          *m_gpsTracking;
-    Track               *m_gpsTrack;
-    TrackSegment        *m_gpsTrackSeg;
+    GeoDataCoordinates  m_gpsCurrentPosition;
+    GeoDataCoordinates  m_gpsPreviousPosition;
 
     PositionProviderPlugin* m_positionProvider;
 };


More information about the Marble-commits mailing list