plotting GPS and Baro altitude
authorHeiko Schlittermann (JUMPER) <hs@schlittermann.de>
Fri, 27 Jan 2012 17:21:51 +0100
changeset 23 8396f7857013
parent 22 fa3d7ce5d0a7
child 24 5c479f099652
plotting GPS and Baro altitude
igc.cc
igc.h
mainwindow.cc
plot.cc
plot.h
--- a/igc.cc	Fri Jan 27 17:16:26 2012 +0100
+++ b/igc.cc	Fri Jan 27 17:21:51 2012 +0100
@@ -24,8 +24,12 @@
 		    }
 		}
 		break;
-	    case 'B': 
-		fixes_ << in.readLine(); 
+	    case 'B':  {
+		Fix fix(in.readLine());
+		if (!fixes_.count()) start_ = fix;
+		landing_ = fix;
+		fixes_ << fix;
+		}
 		break;
 	    default:
 		(void) in.readLine();
@@ -43,9 +47,9 @@
     gps_.lat = s.mid(pos, 8); pos += 8;	// DDMMmmm[NS]
     gps_.lon = s.mid(pos, 9); pos += 9;	// DDDMMmmm[EW]
 
-    fix3d_ = s.mid(pos, 1) == "A"; 
+    is3d_ = s.mid(pos, 1) == "A"; 
     pos += 1;
 
-    alt_.baro = s.mid(pos, 5).toInt(); pos += 5;
-    alt_.gps = s.mid(pos, 5).toInt(); pos += 5;
+    alt_[baro] = s.mid(pos, 5).toInt(); pos += 5;
+    alt_[gps]  = s.mid(pos, 5).toInt(); pos += 5;
 }
--- a/igc.h	Fri Jan 27 17:16:26 2012 +0100
+++ b/igc.h	Fri Jan 27 17:21:51 2012 +0100
@@ -5,18 +5,24 @@
 
 class Fix {
   public: 
+    enum Source { baro, gps };
+
+    Fix() { }
     Fix(const QString&);
+
+    int altitude(Source s = gps) const { return alt_[s]; }
+    QTime time() const { return time_; }
+    bool is3d() const { return is3d_; }
+    QPair<QTime, int> altitudeFix(Source s) const { return qMakePair(time_, alt_[s]); }
+
+    QString longitude() const { return gps_.lon; }
+    QString latitude() const { return gps_.lat; };
+
   private:
     QTime time_;
-    bool fix3d_;
-    struct {
-	QString lon;
-	QString lat;
-    } gps_;
-    struct {
-	int baro;
-	int gps;
-    } alt_;
+    bool is3d_;
+    struct { QString lon, lat; } gps_;
+    int alt_[2];
 };
 
 typedef QList<Fix> Fixes;
@@ -28,10 +34,20 @@
     QString pilot() const { return pilot_; }
     QString glider() const { return glider_; }
     QDate date() const { return date_; }
+    
+    Fixes fixes() const { return fixes_; }
+    Fixes fixes() { return fixes_; }
+
+    Fix start() const { return start_; }
+    Fix landing() const { return landing_; }
+
   private:
     QString device_, pilot_, glider_;
     QDate date_;
     Fixes fixes_;
 
+    Fix start_;
+    Fix landing_;
+
 };
 #endif
--- a/mainwindow.cc	Fri Jan 27 17:16:26 2012 +0100
+++ b/mainwindow.cc	Fri Jan 27 17:21:51 2012 +0100
@@ -85,16 +85,47 @@
     t->setItem(r, V, new QTableWidgetItem(igc_.glider()));
     ++r;
 
+    t->setRowCount(t->rowCount() + 1);
+    t->setItem(r, K, new QTableWidgetItem(tr("Place")));
+    t->setItem(r, V, new QTableWidgetItem(igc_.start().longitude() + " / " + igc_.start().latitude()));
+    ++r;
+
+
     showProfile();
 
 }
 
 void MainWindow::showProfile()
 {
-    Plot *plot = new Plot(tr("Altitude"), this);
+    Plot *plot = new Plot(this);
+
+    /*
+    for (IGC::Iterator i = igc_.begin()
+	 i != igc_.end();
+	 ++i) {
+	 qDebug() << *i;
+    }
+    */
 
+    // get all the altitudes
+    const Fixes f = igc_.fixes();
+    QList< QPair<QTime, int> > altitudesBaro;
+    QList< QPair<QTime, int> > altitudesGPS;
+
+    for (Fixes::const_iterator i = f.begin();
+	 i != f.end();
+	 i++) {
+	 altitudesBaro << i->altitudeFix(Fix::baro);
+	 altitudesGPS << i->altitudeFix(Fix::gps);
+    }
+
+    /*
     plot->setXAxis(0, 100, 10);
     plot->setYAxis(0, 200, 10);
+    */
+    plot->draw(altitudesBaro.begin(), altitudesBaro.end());
+    plot->draw(altitudesGPS.begin(), altitudesGPS.end());
     ui->altitude->setScene(plot);
+
    // ui->altitude->show();
 }
--- a/plot.cc	Fri Jan 27 17:16:26 2012 +0100
+++ b/plot.cc	Fri Jan 27 17:21:51 2012 +0100
@@ -28,3 +28,21 @@
     addLine(QLineF(zero, QPointF(0, -1 * (max - min))));
     if (!step) return;
 }
+
+void Plot::draw(QList< QPair<QTime, int> >::const_iterator current,
+    QList< QPair<QTime, int> >::const_iterator end)
+{
+    QTime t0 = current->first;
+    int offset = current->second;
+
+    QPolygonF poly;
+    QPainterPath path;
+
+    while (current != end) {
+	QPoint p(t0.secsTo(current->first), -1 * (current->second - offset));
+	path.lineTo(p);
+	++current;
+    }
+
+    addPath(path);
+}
--- a/plot.h	Fri Jan 27 17:16:26 2012 +0100
+++ b/plot.h	Fri Jan 27 17:21:51 2012 +0100
@@ -12,6 +12,8 @@
     void setXAxis(qreal max, qreal step = 0);
     void setXAxis(qreal min, qreal max, qreal step = 0);
     void setYAxis(qreal min, qreal max, qreal step = 0);
+    void draw(QList< QPair<QTime, int> >::const_iterator begin,
+	      QList< QPair<QTime, int> >::const_iterator end);
   private:
     static const QPointF zero;