diff --git a/src/Train/ErgFile.cpp b/src/Train/ErgFile.cpp index a109a859b..91173a056 100644 --- a/src/Train/ErgFile.cpp +++ b/src/Train/ErgFile.cpp @@ -685,6 +685,9 @@ ErgFile::save(QStringList &errors) out << "[COURSE DATA]\n"; bool first=true; + long lastLap = 0; + double lastPointX = 0; + foreach(ErgFilePoint p, Points) { // output @@ -694,6 +697,22 @@ ErgFile::save(QStringList &errors) // we scale back if needed if (Ftp && CP) watts = (double(p.y)/CP) * Ftp; + // check if a lap marker should be inserted + foreach(ErgFileLap l, Laps) { + bool addLap = false; + if (l.x == p.x && lastLap != l.x) { + // this is the case where a lap marker matches a load marker + addLap = true; + } else if (l.x > lastPointX && l.x < p.x) { + // this is the case when a lap marker exist between two load markers + addLap = true; + } + if (addLap) { + out <Duration = p->x * 1000; // whatever the last is } + f->Laps = laps_; + // update METADATA too // XXX missing! } @@ -1475,6 +1477,7 @@ WorkoutWidget::save() ergFile->Points.append(ErgFilePoint(p->x * 1000, p->y, p->y)); ergFile->Duration = p->x * 1000; // whatever the last is } + ergFile->Laps = laps_; // // SAVE @@ -1783,6 +1786,16 @@ WorkoutWidget::qwkcode() // how long is this section ? int duration = points_[i+1]->x - points_[i]->x; + bool hasStartLapMarker, hasEndLapMarker; + hasStartLapMarker = hasEndLapMarker = false; + + foreach(ErgFileLap l, laps_) { + if (l.x == points_[i]->x*1000) + hasStartLapMarker = true; + if (l.x == points_[i+1]->x*1000) + hasEndLapMarker = true; + } + // if duration is 0 its a rise, so move on 1 if (duration <=0) { @@ -1817,6 +1830,9 @@ WorkoutWidget::qwkcode() ap = ((points_[i]->y + points_[i+1]->y) / 2) / CP * 100.0f; } + if (hasEndLapMarker && hasStartLapMarker) { + section.append("L"); + } blocks << section; blockp << i; aps << ap; @@ -1834,6 +1850,7 @@ WorkoutWidget::qwkcode() // if we were above recovery and next is below recovery we have // an effort followed by some recovery so join together if ((i < aps.count() -1) && aps[i] > RECOVERY && aps[i+1] 0) { if (w3 != watts) { index++; new WWPoint(this, secs, w3); + bool addLap = laps_.isEmpty() ? true : (laps_.last().x != secs*1000); + if (insertLapMarkers && addLap) + { + ErgFileLap lap; + lap.x = secs*1000; + lap.LapNum = laps_.length() + 1; + lap.selected = false; + lap.name = ""; + laps_.append(lap); + } } // end of recovery block @@ -2105,6 +2161,16 @@ WorkoutWidget::apply(QString code) watts = w4 >0 ? w4 : w3; index++; new WWPoint(this,secs,watts); + bool addLap = laps_.isEmpty() ? true : (laps_.last().x != secs*1000); + if (insertLapMarkers && addLap) + { + ErgFileLap lap; + lap.x = secs*1000; + lap.LapNum = laps_.length() + 1; + lap.selected = false; + lap.name = ""; + laps_.append(lap); + } } } }