Esempio n. 1
0
 void AmplitudePlot::updateSeriesVisibility(bool state) {
     QObject* srcObj = QObject::sender();
     PointSampler* src = qobject_cast<PointSampler*>(srcObj);
     if(src) {
         QwtPlotCurve* curve = _sources.value(src);
         if(curve)  {
             qDebug() << "Setting visibility of" << curve << "to" << state;
             curve->setVisible(state);
         }
     }
 }
Esempio n. 2
0
bool plotsDialog::loadXml(bool init)
{
    tabs->clear();
    QFile file;
#ifdef Q_OS_WIN32
    if(init)
    {
        QFile ofile(globalpara.caseName);
        file.setFileName("plotTemp.xml");
        if(file.exists())
            file.remove();
        if(!ofile.copy("plotTemp.xml"))
        {
            globalpara.reportError("Fail to generate temporary file for plots.",this);
            return false;
        }
        else file.setFileName("plotTemp.xml");
    }
    else file.setFileName("plotTemp.xml");
#endif
#ifdef Q_OS_MAC
    QDir dir = qApp->applicationDirPath();
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    QString bundleDir(dir.absolutePath());
    if(init)
    {
        QFile ofile(globalpara.caseName);
        file.setFileName(bundleDir+"/plotTemp.xml");
        if(file.exists())
            file.remove();
        if(!ofile.copy(bundleDir+"/plotTemp.xml"))
        {
            globalpara.reportError("Fail to generate temporary file for plots.",this);
            return false;
        }
        else file.setFileName(bundleDir+"/plotTemp.xml");
    }
    else file.setFileName(bundleDir+"/plotTemp.xml");
#endif
    QDomDocument doc;
    QDomElement plotData, currentPlot;
    int plotCount=0;
    Plot*newPlot;

    if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        globalpara.reportError("Fail to open the xml file for plots!",this);
        return false;
    }
    else
    {
        if(!doc.setContent(&file))
        {
            globalpara.reportError("Fail to set DomDoc to file content when loading xml file for plots!",this);
            file.close();
            return false;
        }
        else
        {
            if(doc.elementsByTagName("plotData").count()==0)
            {
                globalpara.reportError("Error! There is no <plotData> branch in the case xml file!",this);
                file.close();
                return false;
            }
            else
                plotData = doc.elementsByTagName("plotData").at(0).toElement();

            plotCount = plotData.childNodes().count();
            for(int i = 0; i < plotCount; i++)
            {
                currentPlot = plotData.childNodes().at(i).toElement();
                if(currentPlot.attribute("plotType")=="parametric")
                {
                    QDomElement currentRun,runInput,runOutput;
                    double currentInput;
                    int axis_info[8];
                    QStringList currentOutput, xValues, axis_name, info;
                    QMultiMap<double,double> allData;
                    axis_name.append(currentPlot.attribute("xAxisName"));
                    axis_name= axis_name + currentPlot.attribute("yAxisName").split(",");
                    info = currentPlot.attribute("scaleInfo").split(",");
                    for(int j = 0; j < 8; j++)
                        axis_info[j] = info.at(j).toInt();
                    int nRuns = currentPlot.elementsByTagName("Run").count(), nOutputs = currentPlot.attribute("outputs").toInt();
                    for(int j = 0; j < nRuns; j++)
                    {
                        currentOutput.clear();
                        currentRun = currentPlot.elementsByTagName("Run").at(j).toElement();
                        runInput = currentRun.elementsByTagName("Input").at(0).toElement();
                        currentInput = runInput.elementsByTagName("value").at(0).toElement().text().toDouble();
                        xValues.append(QString::number(currentInput));
                        for(int p = 0; p < nOutputs; p++)
                        {
                            runOutput = currentRun.elementsByTagName("Output").at(p).toElement();
                            currentOutput.append(runOutput.elementsByTagName("value").at(0).toElement().text());
                            allData.insert(currentInput,currentOutput.at(p).toDouble());
                        }
                    }


                    newPlot = new Plot(allData,xValues,nOutputs,axis_info,axis_name);


                }
                else if(currentPlot.attribute("plotType")=="property")
                {
                    QString fluid = currentPlot.attribute("fluid"),
                            subType = currentPlot.attribute("subType"),
                            unit = currentPlot.attribute("unitSystem");

                    newPlot = new Plot(fluid,subType,unit);
                    QDomElement currentCurve, currentPoint;

                    newPlot->curvePoints.clear();
                    for(int i = 0; i < currentPlot.childNodes().count(); i++)
                    {
                        if(currentPlot.childNodes().at(i).toElement().attribute("type")=="custom")
                        {
                            addvalue*value;
                            newPlot->addvaluelist.clear();
                            currentCurve = currentPlot.childNodes().at(i).toElement();
                            QString title = currentCurve.tagName();
                            for(int j = 0; j < currentCurve.childNodes().count(); j++)
                            {
                                if(currentCurve.childNodes().at(j).toElement().attribute("order")==QString::number(j))
                                {
                                    value = new addvalue;
                                    currentPoint = currentCurve.childNodes().at(j).toElement();
                                    value->index = currentPoint.attribute("index").toInt();
                                    value->add_temperature = currentPoint.attribute("t").toDouble();
                                    value->add_pressure = currentPoint.attribute("p").toDouble();
                                    value->add_concentration = currentPoint.attribute("c").toDouble();
                                    value->add_enthalpy = currentPoint.attribute("h").toDouble();
//                                    qDebug()<<"adding a new point"<<currentPoint.attribute("index")<<"t"<<currentPoint.attribute("t")<<"p"<<currentPoint.attribute("p")<<"c"<<currentPoint.attribute("c");
                                    newPlot->addvaluelist<<value;
                                }
                            }

                            if(subType == "Duhring")
                                newPlot->setupNewPropertyCurve(title,true);
                            else if(subType == "Clapeyron")
                                newPlot->setupNewPropertyCurve(title,false);
                        }
                    }


                }
                newPlot->setTitle(currentPlot.tagName());

                //load the plot settings
                QDomElement general, legend, grid, curve;

                //general
                if(currentPlot.elementsByTagName("general").count()>0)
                {
                    general = currentPlot.elementsByTagName("general").at(0).toElement();
                    QString bgColor, lMargin, rMargin, tMargin, bMargin, plotTitle, xTitle, yTitle;
                    bgColor = general.attribute("bgColor");
                    newPlot->setCanvasBackground(QColor(bgColor));
                    lMargin = general.attribute("lMargin");
                    rMargin = general.attribute("rMargin");
                    tMargin = general.attribute("tMargin");
                    bMargin = general.attribute("bMargin");
                    newPlot->setContentsMargins(lMargin.toInt(),tMargin.toInt(),rMargin.toInt(),bMargin.toInt());
                    plotTitle = general.attribute("plotTitle");
                    newPlot->setTitle(plotTitle);
                    xTitle = general.attribute("xTitle");
                    yTitle = general.attribute("yTitle");
                    newPlot->setAxisTitle(QwtPlot::xBottom,xTitle);
                    newPlot->setAxisTitle(QwtPlot::yLeft,yTitle);

                }

                //legend
                if(currentPlot.elementsByTagName("legend").count()>0)
                {
                    legend = currentPlot.elementsByTagName("legend").at(0).toElement();
                    QString plotLegend, extInt, extPos, nCol, legendSize;
                    plotLegend = legend.attribute("plotLegend");
                    if(plotLegend == "on")
                    {
                        QwtLegend* externalLegend=NULL;
                        LegendItem* internalLegend = new LegendItem();
                        newPlot->externalLegend = externalLegend;
                        newPlot->internalLegend = internalLegend;
                        internalLegend->attach(newPlot);
                        internalLegend->setBorderRadius( 4 );
                        internalLegend->setMargin( 0 );
                        internalLegend->setSpacing( 4 );
                        internalLegend->setItemMargin( 2 );
                        internalLegend->setMaxColumns(4);
                        internalLegend->setAlignment(Qt::AlignBottom|Qt::AlignRight);
                        extInt = legend.attribute("extInt");
                        if(extInt == "ext")
                        {
                            internalLegend->setVisible(false);
                            externalLegend = new QwtLegend();
                            extPos = legend.attribute("extPos");//0=L, 1=R, 2=B, 3=T
                            newPlot->insertLegend(externalLegend,QwtPlot::LegendPosition(extPos.toInt()));
                        }
                        else if(extInt == "int")
                        {
                            internalLegend->setVisible(true);
                            nCol = legend.attribute("nCol");
                            legendSize = legend.attribute("legendSize");

                            // other setting
                            newPlot->internalLegend->setMaxColumns(nCol.toInt());
                            QFont font = newPlot->internalLegend->font();
                            font.setPointSize( legendSize.toInt());
                            newPlot->internalLegend->setFont( font );
                        }
                    }
                }

                //grid
                if(currentPlot.elementsByTagName("grid").count()>0)
                {
                    grid = currentPlot.elementsByTagName("grid").at(0).toElement();
                    QString xMaj, yMaj, xMin, yMin, majColor, minColor, majSize, minSize, majStyle, minStyle;
                    xMaj = grid.attribute("xMaj");
                    yMaj = grid.attribute("yMaj");
                    xMin = grid.attribute("xMin");
                    yMin = grid.attribute("yMin");
                    majColor = grid.attribute("majColor");
                    minColor = grid.attribute("minColor");
                    majSize = grid.attribute("majSize");
                    minSize = grid.attribute("minSize");
                    majStyle = grid.attribute("majStyle");
                    minStyle = grid.attribute("minStyle");
                    newPlot->grid->enableX(xMaj=="on");
                    newPlot->grid->enableY(yMaj == "on");
                    newPlot->grid->enableXMin(xMin=="on");
                    newPlot->grid->enableYMin(yMin=="on");
                    if(newPlot->grid->xEnabled()||newPlot->grid->yEnabled())
                        newPlot->grid->setMajorPen(QColor(majColor),majSize.toInt(),Qt::PenStyle(majStyle.toInt()));
                    if(newPlot->grid->xMinEnabled()||newPlot->grid->yMinEnabled())
                        newPlot->grid->setMinorPen(QColor(minColor),minSize.toInt(),Qt::PenStyle(minStyle.toInt()));
                }

                //curve
                if(currentPlot.elementsByTagName("curve").count()>0)
                {
                    curve = currentPlot.elementsByTagName("curve").at(0).toElement();
                    if(curve.childNodes().count()==newPlot->curvelist.count())
                    {
                        QDomElement currentCurve;
                        QwtPlotCurve *thisCurve;
                        QString lineColor, lineSize, lineType, isVisible;
                        for(int i = 0; i < newPlot->curvelist.count(); i++)
                        {
                            currentCurve = curve.elementsByTagName(newPlot->curvelist[i]->title().text().replace(" ","")).at(0).toElement();
                            thisCurve = newPlot->curvelist[i];
                            lineColor = currentCurve.attribute("lineColor");
                            lineSize = currentCurve.attribute("lineSize");
                            lineType = currentCurve.attribute("lineType");
                            isVisible = currentCurve.attribute("isVisible");
                            thisCurve->setPen(QColor(lineColor),lineSize.toInt(),Qt::PenStyle(lineType.toInt()));
                            if(isVisible=="true")
                                thisCurve->setVisible(true);
                            else if(isVisible=="false")
                                thisCurve->setVisible(false);
                        }
                    }
                }


                tabs->insertTab(-1,newPlot,currentPlot.tagName());
                newPlot->replot();
            }
            file.close();
            return true;
        }
    }
}
Esempio n. 3
0
void
PfPvPlot::refreshZoneItems()
{
    // clear out any zone curves which are presently defined
    if (zoneCurves.size()) {

        QListIterator<QwtPlotCurve *> i(zoneCurves);
        while (i.hasNext()) {
            QwtPlotCurve *curve = i.next();
            curve->detach();
            //delete curve;
        }
    }
    zoneCurves.clear();

    // delete any existing power zone labels
    if (zoneLabels.size()) {

        QListIterator<PfPvPlotZoneLabel *> i(zoneLabels);
        while (i.hasNext()) {
            PfPvPlotZoneLabel *label = i.next();
            label->detach();
            delete label;
        }
    }
    zoneLabels.clear();

    // set zones from ride or athlete and date of
    // first item in the compare set
    const Zones *zones;
    int zone_range = -1;

    // comparing does zones for items selected not current ride
    if (context->isCompareIntervals) {

        zones = context->athlete->zones();

        // no athlete zones anyway!
        if (!zones) return;

        // use first compare interval date
        if (context->compareIntervals.count()) {
            zone_range = zones->whichRange(context->compareIntervals[0].data->startTime().date());
        }

        // still not set 
        if (zone_range == -1) {
            zone_range = zones->whichRange(QDate::currentDate());
        }

    } else if (rideItem) {

        zones = rideItem->zones;
        zone_range = rideItem->zoneRange();

    } else {

        return; // null ride and not compare etc
    }

    if (zone_range >= 0) {
        setCP(zones->getCP(zone_range));

        // populate the zone curves
        QList <int> zone_power = zones->getZoneLows(zone_range);
        QList <QString> zone_name = zones->getZoneNames(zone_range);
        int num_zones = zone_power.size();
        if (zone_name.size() != num_zones) return;

        if (num_zones > 0) {
            QPen *pen = new QPen();
            pen->setStyle(Qt::NoPen);

            QwtArray<double> yvalues;

            // generate x values
            for (int z = 0; z < num_zones; z ++) {

                QwtPlotCurve *curve = new QwtPlotCurve(zone_name[z]);

                curve->setPen(*pen);
                QColor brush_color = zoneColor(z, num_zones);
                brush_color.setHsv(brush_color.hue(), brush_color.saturation() / 4, brush_color.value());
                curve->setBrush(brush_color);   // fill below the line
                curve->setZ(1 - 1e-6 * zone_power[z]);

                // generate data for curve
                if (z < num_zones - 1) {
                    QwtArray <double> contour_yvalues;
                    int watts = zone_power[z + 1];
                    int dwatts = (double) watts;
                    for (int i = 0; i < contour_xvalues.size(); i ++) {
                        contour_yvalues.append( (1e6 * contour_xvalues[i] < watts) ?  1e6 : dwatts / contour_xvalues[i]);
                    }
                    curve->setSamples(contour_xvalues, contour_yvalues);

                } else {

                    // top zone has a curve at "infinite" power
                    QwtArray <double> contour_x;
                    QwtArray <double> contour_y;
                    contour_x.append(contour_xvalues[0]);
                    contour_x.append(contour_xvalues[contour_xvalues.size() - 1]);
                    contour_y.append(1e6);
                    contour_y.append(1e6);
                    curve->setSamples(contour_x, contour_y);
                }

                curve->setVisible(shade_zones);
                curve->attach(this);
                zoneCurves.append(curve);
            }

            delete pen;

            // generate labels for existing zones
            for (int z = 0; z < num_zones; z ++) {
                PfPvPlotZoneLabel *label = new PfPvPlotZoneLabel(this, z);
                label->setVisible(shade_zones);
                label->attach(this);
                zoneLabels.append(label);
            }
        }
    }
}
Esempio n. 4
0
void
PfPvPlot::refreshZoneItems()
{
    // clear out any zone curves which are presently defined
    if (zoneCurves.size()) {

        QListIterator<QwtPlotCurve *> i(zoneCurves);
        while (i.hasNext()) {
            QwtPlotCurve *curve = i.next();
            curve->detach();
            delete curve;
        }
    }
    zoneCurves.clear();

    // delete any existing power zone labels
    if (zoneLabels.size()) {

        QListIterator<PfPvPlotZoneLabel *> i(zoneLabels);
        while (i.hasNext()) {
            PfPvPlotZoneLabel *label = i.next();
            label->detach();
            delete label;
        }
    }
    zoneLabels.clear();

    // give up for a null ride
    if (! rideItem) return;

    const Zones *zones = rideItem->zones;
    int zone_range = rideItem->zoneRange();

    if (zone_range >= 0) {
        setCP(zones->getCP(zone_range));

        // populate the zone curves
        QList <int> zone_power = zones->getZoneLows(zone_range);
        QList <QString> zone_name = zones->getZoneNames(zone_range);
        int num_zones = zone_power.size();
        assert(zone_name.size() == num_zones);

        if (num_zones > 0) {
            QPen *pen = new QPen();
            pen->setStyle(Qt::NoPen);

            QwtArray<double> yvalues;

            // generate x values
            for (int z = 0; z < num_zones; z ++) {

                QwtPlotCurve *curve = new QwtPlotCurve(zone_name[z]);

                curve->setPen(*pen);
                QColor brush_color = zoneColor(z, num_zones);
                brush_color.setHsv(brush_color.hue(), brush_color.saturation() / 4, brush_color.value());
                curve->setBrush(brush_color);   // fill below the line
                curve->setZ(1 - 1e-6 * zone_power[z]);

                // generate data for curve
                if (z < num_zones - 1) {
                    QwtArray <double> contour_yvalues;
                    int watts = zone_power[z + 1];
                    int dwatts = (double) watts;
                    for (int i = 0; i < contour_xvalues.size(); i ++) {
                        contour_yvalues.append( (1e6 * contour_xvalues[i] < watts) ?  1e6 : dwatts / contour_xvalues[i]);
                    }
                    curve->setData(contour_xvalues, contour_yvalues);

                } else {

                    // top zone has a curve at "infinite" power
                    QwtArray <double> contour_x;
                    QwtArray <double> contour_y;
                    contour_x.append(contour_xvalues[0]);
                    contour_x.append(contour_xvalues[contour_xvalues.size() - 1]);
                    contour_y.append(1e6);
                    contour_y.append(1e6);
                    curve->setData(contour_x, contour_y);
                }

                curve->setVisible(shade_zones);
                curve->attach(this);
                zoneCurves.append(curve);
            }

            delete pen;

            // generate labels for existing zones
            for (int z = 0; z < num_zones; z ++) {
                PfPvPlotZoneLabel *label = new PfPvPlotZoneLabel(this, z);
                label->setVisible(shade_zones);
                label->attach(this);
                zoneLabels.append(label);
            }
        }
    }
}