CurveCalibrator.cc 3.82 KB
Newer Older
1 2 3
#include "CurveCalibrator.h"

CurveCalibrator::CurveCalibrator(QString titleString, QWidget *parent) :
4
    AbstractCalibrator(parent),
5 6
    setpoints(new QVector<uint16_t>(5)),
    positions(new QVector<uint16_t>())
7 8 9 10 11 12 13 14 15 16 17 18 19
{
    QGridLayout *grid = new QGridLayout(this);
    QLabel *title = new QLabel(titleString);
    grid->addWidget(title, 0, 0, 1, 5, Qt::AlignHCenter);

    QLabel *pulseWidthTitle = new QLabel(tr("Pulse Width (us)"));
    pulseWidth = new QLabel();
    QHBoxLayout *pulseLayout = new QHBoxLayout();
    pulseLayout->addWidget(pulseWidthTitle);
    pulseLayout->addWidget(pulseWidth);
    grid->addLayout(pulseLayout, 1, 0, 1, 5, Qt::AlignHCenter);

    for (int i=0; i<=100; i=i+100/4)
20
        positions->append(static_cast<double>(i));
21 22


23
    setpoints->fill(1500);
24 25 26 27 28 29 30

    plot = new QwtPlot();

    grid->addWidget(plot, 2, 0, 1, 5, Qt::AlignHCenter);


    plot->setAxisScale(QwtPlot::yLeft, 1000, 2000, 200);
31
    plot->setAxisScale(QwtPlot::xBottom, 0, 100, 25);
32 33

    curve = new QwtPlotCurve();
34
    curve->setPen(QPen(QColor(QString("lime"))));
35 36 37 38 39 40 41 42 43 44 45

    QVector<double> pos(positions->size());
    QVector<double> set(setpoints->size());

    for (int i=0; i<positions->size()&&i<setpoints->size(); i++)
    {
        pos[i] = static_cast<double>((*positions)[i]);
        set[i] = static_cast<double>((*setpoints)[i]);
    }

    curve->setData(pos, set);
46 47 48 49
    curve->attach(plot);

    plot->replot();

50 51 52 53 54 55 56 57 58 59 60
    QPushButton *zero = new QPushButton(tr("0 %"));
    QPushButton *twentyfive = new QPushButton(tr("25 %"));
    QPushButton *fifty = new QPushButton(tr("50 %"));
    QPushButton *seventyfive = new QPushButton(tr("75 %"));
    QPushButton *hundred = new QPushButton(tr("100 %"));

    grid->addWidget(zero, 3, 0);
    grid->addWidget(twentyfive, 3, 1);
    grid->addWidget(fifty, 3, 2);
    grid->addWidget(seventyfive, 3, 3);
    grid->addWidget(hundred, 3, 4);
61 62

    this->setLayout(grid);
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85

    signalMapper = new QSignalMapper(this);
    signalMapper->setMapping(zero, 0);
    signalMapper->setMapping(twentyfive, 1);
    signalMapper->setMapping(fifty, 2);
    signalMapper->setMapping(seventyfive, 3);
    signalMapper->setMapping(hundred, 4);

    connect(zero, SIGNAL(clicked()), signalMapper, SLOT(map()));
    connect(twentyfive, SIGNAL(clicked()), signalMapper, SLOT(map()));
    connect(fifty, SIGNAL(clicked()), signalMapper, SLOT(map()));
    connect(seventyfive, SIGNAL(clicked()), signalMapper, SLOT(map()));
    connect(hundred, SIGNAL(clicked()), signalMapper, SLOT(map()));
    connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(setSetpoint(int)));
}

CurveCalibrator::~CurveCalibrator()
{
    delete setpoints;
    delete positions;
}

void CurveCalibrator::setSetpoint(int setpoint)
86 87
{
    if (setpoint == 0 || setpoint == 4) {
88
        setpoints->replace(setpoint,logExtrema());
89
    } else {
90
        setpoints->replace(setpoint, logAverage());
91
    }
92 93 94 95 96 97 98 99 100 101 102

    QVector<double> pos(positions->size());
    QVector<double> set(setpoints->size());

    for (int i=0; i<positions->size()&&i<setpoints->size(); i++)
    {
        pos[i] = static_cast<double>((*positions)[i]);
        set[i] = static_cast<double>((*setpoints)[i]);
    }

    curve->setData(pos, set);
103 104
    plot->replot();

105
    emit setpointChanged(setpoint, setpoints->value(setpoint));
106
}
107

108
void CurveCalibrator::set(const QVector<uint16_t> &data)
109
{
110
    if (data.size() == 5) {
111
        for (int i=0; i<data.size(); ++i)
112 113 114 115 116 117 118 119 120 121
            setpoints->replace(i, data[i]);
        QVector<double> pos(positions->size());
        QVector<double> set(setpoints->size());

        for (int i=0; i<positions->size()&&i<setpoints->size(); i++)
        {
            pos[i] = static_cast<double>((*positions)[i]);
            set[i] = static_cast<double>((*setpoints)[i]);
        }
        curve->setData(pos, set);
122
        plot->replot();
123
    } else {
124 125
        qDebug() << __FILE__ << __LINE__ << ": wrong data vector size";
    }
126
}