Exemplo n.º 1
0
bool TcxLap::isEmpty() {
    vector<TcxTrack*>::iterator it;
    for ( it=trackList.begin() ; it < trackList.end(); ++it )
    {
        TcxTrack* track = *it;
        if (!track->isEmpty()) {
            return false;
        }
    }
    return true;
}
Exemplo n.º 2
0
TiXmlElement * TcxLap::getTiXml(bool readTrackData) {
    TiXmlElement * xmlLap = new TiXmlElement("Lap");

    xmlLap->SetAttribute("StartTime",getStartTime());

    if (this->totalTimeSeconds.length() == 0) {
        calculateTotalTimeSeconds();
    }
    TiXmlElement * xmlTotalTimeSeconds = new TiXmlElement("TotalTimeSeconds");
    xmlTotalTimeSeconds->LinkEndChild(new TiXmlText(this->totalTimeSeconds));
    xmlLap->LinkEndChild(xmlTotalTimeSeconds);

    if (this->distanceMeters.length() == 0) {
        calculateDistanceMeters();
    }
    TiXmlElement * xmlDistanceMeters = new TiXmlElement("DistanceMeters");
    xmlDistanceMeters->LinkEndChild(new TiXmlText(this->distanceMeters));
    xmlLap->LinkEndChild(xmlDistanceMeters);

    if (this->maximumSpeed.length() > 0) {
        TiXmlElement * xmlMaxSpeed = new TiXmlElement("MaximumSpeed");
        xmlMaxSpeed->LinkEndChild(new TiXmlText(this->maximumSpeed));
        xmlLap->LinkEndChild(xmlMaxSpeed);
    }

    if (this->calories.length() == 0) {
        calculateCalories();
    }
    TiXmlElement * xmlCalories = new TiXmlElement("Calories");
    xmlCalories->LinkEndChild(new TiXmlText(this->calories));
    xmlLap->LinkEndChild(xmlCalories);

    if (this->averageHeartRateBpm.length() > 0) {
        //TODO: Think about calculating averageHeartRateBpm value
        TiXmlElement * xmlAvgHeart = new TiXmlElement("AverageHeartRateBpm");
        //xmlAvgHeart->SetAttribute("xsi:type","HeartRateInBeatsPerMinute_t");
        TiXmlElement * xmlValue = new TiXmlElement("Value");
        this->averageHeartRateBpm = TrainingCenterDatabase::limitIntValue(this->averageHeartRateBpm, 0,255);
        xmlValue->LinkEndChild(new TiXmlText(this->averageHeartRateBpm));
        xmlAvgHeart->LinkEndChild(xmlValue);
        xmlLap->LinkEndChild(xmlAvgHeart);
    }

    if (this->maximumHeartRateBpm.length() == 0) {
    	calculateMaximumHeartRateBpm();
    }

    if (this->maximumHeartRateBpm.length() > 0) {
        TiXmlElement * xmlAvgHeart = new TiXmlElement("MaximumHeartRateBpm");
        //xmlAvgHeart->SetAttribute("xsi:type","HeartRateInBeatsPerMinute_t");
        TiXmlElement * xmlValue = new TiXmlElement("Value");
        this->maximumHeartRateBpm = TrainingCenterDatabase::limitIntValue(this->maximumHeartRateBpm, 0,255);
        xmlValue->LinkEndChild(new TiXmlText(this->maximumHeartRateBpm));
        xmlAvgHeart->LinkEndChild(xmlValue);
        xmlLap->LinkEndChild(xmlAvgHeart);
    }

    TiXmlElement * xmlIntensity = new TiXmlElement("Intensity");
    xmlIntensity->LinkEndChild(new TiXmlText(getIntensity(this->intensity)));
    xmlLap->LinkEndChild(xmlIntensity);

    if ((this->cadence.length() > 0) && (this->cadenceSensorType != TrainingCenterDatabase::UndefinedCadenceType)) {
        this->cadence = TrainingCenterDatabase::limitIntValue(this->cadence, 0,255);
        if (this->cadence != "255") {
            if (this->cadenceSensorType == TrainingCenterDatabase::Bike) {
                TiXmlElement * xmlCadence = new TiXmlElement("Cadence");
                xmlCadence->LinkEndChild(new TiXmlText(this->cadence));
                xmlLap->LinkEndChild(xmlCadence);
            }
        }
    }

    TiXmlElement * xmlTriggerMethod = new TiXmlElement("TriggerMethod");
    xmlTriggerMethod->LinkEndChild(new TiXmlText(getTriggerMethod(this->triggerMethod)));
    xmlLap->LinkEndChild(xmlTriggerMethod);

    if (readTrackData) {
        vector<TcxTrack*>::iterator it;
        for ( it=trackList.begin() ; it < trackList.end(); ++it )
        {
            TcxTrack* track = *it;
            if (!track->isEmpty()) {
                xmlLap->LinkEndChild(track->getTiXml());
            }
        }
    }

    TiXmlElement * xmlLapExtensions = NULL;
    if ((this->cadence.length() > 0) && (this->cadenceSensorType != TrainingCenterDatabase::UndefinedCadenceType)) {
        if (this->cadence != "255") {
            if (this->cadenceSensorType != TrainingCenterDatabase::Bike) {
                if (xmlLapExtensions == NULL) {
                    xmlLapExtensions = new TiXmlElement("Extensions");
                    xmlLap->LinkEndChild(xmlLapExtensions);
                }

                TiXmlElement * xmlLX = new TiXmlElement("LX");
                xmlLX->SetAttribute("xmlns","http://www.garmin.com/xmlschemas/ActivityExtension/v2");
                xmlLapExtensions->LinkEndChild(xmlLX);
                TiXmlElement * xmlAvgRunCadence = new TiXmlElement("AvgRunCadence");
                xmlAvgRunCadence->LinkEndChild(new TiXmlText(this->cadence));
                xmlLX->LinkEndChild(xmlAvgRunCadence);
            }
        }
    }

    if ((this->maxCadence.length() > 0) && (this->maxCadence != "255")) {
        if (xmlLapExtensions == NULL) {
            xmlLapExtensions = new TiXmlElement("Extensions");
            xmlLap->LinkEndChild(xmlLapExtensions);
        }

        string name = "MaxBikeCadence";
        if (this->cadenceSensorType == TrainingCenterDatabase::Footpod) {
        	name = "MaxRunCadence";
        }

        TiXmlElement * xmlLX = new TiXmlElement("LX");
        xmlLX->SetAttribute("xmlns","http://www.garmin.com/xmlschemas/ActivityExtension/v2");
        xmlLapExtensions->LinkEndChild(xmlLX);
        TiXmlElement * xmlMaxCadence = new TiXmlElement(name);
        xmlMaxCadence->LinkEndChild(new TiXmlText(this->maxCadence));
        xmlLX->LinkEndChild(xmlMaxCadence);
    }

    if (this->avgSpeed.length() > 0) {
        if (xmlLapExtensions == NULL) {
            xmlLapExtensions = new TiXmlElement("Extensions");
            xmlLap->LinkEndChild(xmlLapExtensions);
        }

        TiXmlElement * xmlLX = new TiXmlElement("LX");
        xmlLX->SetAttribute("xmlns","http://www.garmin.com/xmlschemas/ActivityExtension/v2");
        xmlLapExtensions->LinkEndChild(xmlLX);
        TiXmlElement * xmlAvgSpeed = new TiXmlElement("AvgSpeed");
        xmlAvgSpeed->LinkEndChild(new TiXmlText(this->avgSpeed));
        xmlLX->LinkEndChild(xmlAvgSpeed);
    }

    if ((this->avgPower.length() > 0) && (this->avgPower != "65535")) {
        if (xmlLapExtensions == NULL) {
            xmlLapExtensions = new TiXmlElement("Extensions");
            xmlLap->LinkEndChild(xmlLapExtensions);
        }

        TiXmlElement * xmlLX = new TiXmlElement("LX");
        xmlLX->SetAttribute("xmlns","http://www.garmin.com/xmlschemas/ActivityExtension/v2");
        xmlLapExtensions->LinkEndChild(xmlLX);

        TiXmlElement * xmlAvgPower = new TiXmlElement("AvgWatts");
        xmlAvgPower->LinkEndChild(new TiXmlText(this->avgPower));
        xmlLX->LinkEndChild(xmlAvgPower);
    }

    if ((this->maxPower.length() > 0) && (this->maxPower != "65535")) {
        if (xmlLapExtensions == NULL) {
            xmlLapExtensions = new TiXmlElement("Extensions");
            xmlLap->LinkEndChild(xmlLapExtensions);
        }

        TiXmlElement * xmlLX = new TiXmlElement("LX");
        xmlLX->SetAttribute("xmlns","http://www.garmin.com/xmlschemas/ActivityExtension/v2");
        xmlLapExtensions->LinkEndChild(xmlLX);

        TiXmlElement * xmlMaxPower = new TiXmlElement("MaxWatts");
        xmlMaxPower->LinkEndChild(new TiXmlText(this->maxPower));
        xmlLX->LinkEndChild(xmlMaxPower);
    }

    if (this->steps.length() > 0) {
        if (xmlLapExtensions == NULL) {
            xmlLapExtensions = new TiXmlElement("Extensions");
            xmlLap->LinkEndChild(xmlLapExtensions);
        }

        TiXmlElement * xmlLX = new TiXmlElement("LX");
        xmlLX->SetAttribute("xmlns","http://www.garmin.com/xmlschemas/ActivityExtension/v2");
        xmlLapExtensions->LinkEndChild(xmlLX);
        TiXmlElement * xmlSteps = new TiXmlElement("Steps");
        xmlSteps->LinkEndChild(new TiXmlText(this->steps));
        xmlLX->LinkEndChild(xmlSteps);
    }

    return xmlLap;
}