- incorrect RegEx to read some CRS files
- all files were assumed to be metric - (UNITS = ENGLISH) now converts
- scaling adjusted to not clip the top when some graphs were longer
This commit is contained in:
Marc Boudreau
2012-03-12 22:41:28 -04:00
committed by Mark Liversedge
parent 0430568d99
commit c1d8c1ca51
2 changed files with 26 additions and 16 deletions

View File

@@ -19,6 +19,7 @@
#include "ErgFile.h"
#include <stdint.h>
#include "Units.h"
ErgFile::ErgFile(QString filename, int &mode, double Cp, MainWindow *main) :
Cp(Cp), filename(filename), main(main), mode(mode)
@@ -239,6 +240,9 @@ void ErgFile::parseComputrainer(QString p)
format = ERG; // either ERG or MRC
Points.clear();
// start by assuming the input file is Metric
bool bIsMetric = true;
// running totals for CRS file format
long rdist = 0; // running total for distance
long ralt = 200; // always start at 200 meters just to prettify the graph
@@ -268,7 +272,7 @@ void ErgFile::parseComputrainer(QString p)
QRegExp relativeWatts("^[ \\t]*([0-9\\.]+)[ \\t]*([0-9\\.]+)%[ \\t\\n]*$", Qt::CaseInsensitive);
// distance slope wind records
QRegExp absoluteSlope("^[ \\t]*([0-9\\.]+)[ \\t]*([-0-9\\.]+)[ \\t\\n]([-0-9\\.]+)[ \\t\\n]*$",
QRegExp absoluteSlope("^[ \\t]*([0-9\\.]+)[ \\t]*([-0-9\\.]+)[ \\t\\n]*([-0-9\\.]+)[ \\t\\n]*$",
Qt::CaseInsensitive);
// Lap marker in an ERG/MRC file
@@ -346,10 +350,14 @@ void ErgFile::parseComputrainer(QString p)
QRegExp punit("^UNITS *", Qt::CaseInsensitive);
if (punit.exactMatch(settings.cap(1))) {
Units = settings.cap(2);
// UNITS can be ENGLISH or METRIC (miles/km)
// XXX FIXME XXX
}
Units = settings.cap(2);
// UNITS can be ENGLISH or METRIC (miles/km)
QRegExp penglish(" ENGLISH$", Qt::CaseInsensitive);
if (penglish.exactMatch(Units)) { // Units <> METRIC
//qDebug("Setting conversion to ENGLISH");
bIsMetric = false;
}
}
QRegExp pftp("^FTP *", Qt::CaseInsensitive);
if (pftp.exactMatch(settings.cap(1))) Ftp = settings.cap(2).toInt();
@@ -376,7 +384,7 @@ void ErgFile::parseComputrainer(QString p)
case MRC: // its a percent relative to CP (mrc file)
add.y *= Cp;
add.y /= 100.00;
add.val = add.y;
add.val = add.y;
break;
}
Points.append(add);
@@ -395,15 +403,17 @@ void ErgFile::parseComputrainer(QString p)
// dist, grade, wind strength
ErgFilePoint add;
// distance guff
// distance guff
add.x = rdist;
int distance = absoluteSlope.cap(1).toDouble() * 1000; // convert to meters
rdist += distance;
int distance = absoluteSlope.cap(1).toDouble() * 1000; // convert to meters
// gradient and altitude
if (!bIsMetric) distance *= KM_PER_MILE;
rdist += distance;
// gradient and altitude
add.val = absoluteSlope.cap(2).toDouble();
add.y = ralt;
ralt += distance * add.val / 100; /* paused */
ralt += distance * add.val / 100; /* paused */
Points.append(add);
if (add.y > MaxWatts) MaxWatts=add.y;
@@ -412,9 +422,9 @@ void ErgFile::parseComputrainer(QString p)
} else if (ignore.exactMatch(line)) {
// do nothing for this line
} else {
// ignore bad lines for now. just bark.
//qDebug()<<"huh?" << line;
}
// ignore bad lines for now. just bark.
//qDebug()<<"huh?" << line;
}
}

View File

@@ -50,10 +50,10 @@ QRectF ErgFileData::boundingRect() const
foreach(ErgFilePoint x, main->currentErgFile()->Points) {
if (x.y > maxY) maxY = x.y;
if (x.x > maxX) maxX = x.x;
if (x.y < minY) minY = x.x;
if (x.y < minY) minY = x.y;
if (x.x < minX) minX = x.x;
}
maxY *= 1.1f; // always need a bit of headroom
maxY *= 1.3f; // always need a bit of headroom
return QRectF(minX, minY, maxX, maxY);
}
return QRectF(0,0,0,0);