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

CurveCalibrator::CurveCalibrator(QString titleString, QWidget *parent) :
4
    AbstractCalibrator(parent),
5 6
    setpoints(new QVector<double>(5)),
    positions(new QVector<double>())
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 35
    curve->setPen(QPen(QColor(QString("lime"))));
    curve->setData(*positions, *setpoints);    
36 37 38 39
    curve->attach(plot);

    plot->replot();

40 41 42 43 44 45 46 47 48 49 50
    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);
51 52

    this->setLayout(grid);
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

    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)
{   
    if (setpoint == 0 || setpoint == 4)
    {
        setpoints->replace(setpoint, static_cast<double>(logExtrema()));
    }
    else
    {
        setpoints->replace(setpoint, static_cast<double>(logAverage()));
    }
85
    curve->setData(*positions, *setpoints);
86 87 88
    plot->replot();

    emit setpointChanged(setpoint, static_cast<float>(setpoints->value(setpoint)));
89
}
90 91 92 93 94 95

void CurveCalibrator::set(const QVector<float> &data)
{
    if (data.size() == 5)
    {
        for (int i=0; i<data.size(); ++i)
96
            setpoints->replace(i, static_cast<double>(data[i]));
97 98 99
        curve->setData(*positions, *setpoints);
        plot->replot();
    }
100 101 102 103
    else
    {
        qDebug() << __FILE__ << __LINE__ << ": wrong data vector size";
    }
104
}