i0mapmon.cpp 6.29 KB
Newer Older
Giacomo Strangolino's avatar
Giacomo Strangolino committed
1
2
3
4
5
6
7
8
9
10
#include "i0mapmon.h"
#include "ui_i0mapmon.h"

// cumbia
#include <cumbiapool.h>
#include <cuserviceprovider.h>
#include <cumacros.h>
#include <quapps.h>
// cumbia

11
12
#include <quwatcher.h>
#include <qulineedit.h>
Giacomo Strangolino's avatar
Giacomo Strangolino committed
13
14
15
#include <qustring.h>

#include "checkablecomboboxmodel.h"
16

Giacomo Strangolino's avatar
Giacomo Strangolino committed
17
18
19
20
21
22
I0mapmon::I0mapmon(CumbiaPool *cumbia_pool, QWidget *parent) :
    QWidget(parent)
{
    // cumbia
    CuModuleLoader mloader(cumbia_pool, &m_ctrl_factory_pool, &m_log_impl);
    cu_pool = cumbia_pool;
Giacomo Strangolino's avatar
Giacomo Strangolino committed
23

Giacomo Strangolino's avatar
Giacomo Strangolino committed
24
25
26
27
28
    ui = new Ui::I0mapmon;
    ui->setupUi(this, cu_pool, m_ctrl_factory_pool);

    // mloader.modules() to get the list of loaded modules
    // cumbia
29
30
31
32
33
34
35
36
37
38
39

    m_fel0x = 0;
    for(int i = 1; i < qApp->arguments().size() && m_fel0x < 1; i++) {
        if(qApp->arguments()[i].contains("f01")) m_fel0x = 1;
        else if(qApp->arguments()[i].contains("f02")) m_fel0x = 2;
    }
    if(m_fel0x < 1)
        ui->lTitle->setText("Unknown operation mode FEL01 / FEL02 from command line args");
    else {
        ui->lTitle->setText(ui->lTitle->text() + QString(" FEL0%1").arg(m_fel0x));

Giacomo Strangolino's avatar
Giacomo Strangolino committed
40
41
42
43
        m_cb_model = new CheckableComboBoxModel(ui->qucby);
        connect(m_cb_model, SIGNAL(itemChecked(QString,bool)), this, SLOT(onWlenSelectionChanged(QString, bool)));
        ui->qucblambda->setModel(m_cb_model);

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
        // continue setup
        QuWatcher *w = new QuWatcher(this, cumbia_pool, m_ctrl_factory_pool);
        w->setSingleShot(true);
        w->setAutoDestroy(true);
        w->attach(this, SLOT(onNamesReady(QStringList)));
        w->setSource("$1/name");

        connect(ui->pbApplyWlenWei, SIGNAL(clicked()), this, SLOT(applyWavelenX()));

        // qu-line edit for wavelen / wavelen weights
        ui->quleWlenWei->setTarget(QString("$2/FEL0%1_IOM_wavelength_weights").arg(m_fel0x));

        // label
        ui->qulWlens->setSource(QString("$2/FEL0%1_IOM_wavelengths").arg(m_fel0x));
        ui->qulWlenWei->setSource(QString("$2/FEL0%1_IOM_wavelength_weights").arg(m_fel0x));
Giacomo Strangolino's avatar
Giacomo Strangolino committed
59
        connect(ui->qulWlens, SIGNAL(newData(CuData)), this, SLOT(onWlensChanged(CuData)));
60
61
62
63

        // plot
        ui->quSpectrumPlot->setYLowerBound(-1.0);
        ui->quSpectrumPlot->setYUpperBound(1.0);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
64
65
        ui->quSpectrumPlot->setXLowerBound(-1.0);
        ui->quSpectrumPlot->setXUpperBound(1.0);
66
67
        // autoscale
        ui->quSpectrumPlot->setYAxisAutoscaleEnabled(true);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
68
69
70
71
72

        m_setup_x_list();

        // trigger plot reconf
        connect(ui->pbPlotReconf, SIGNAL(clicked()), this, SLOT(m_plot_reconf()));
73
    }
Giacomo Strangolino's avatar
Giacomo Strangolino committed
74
75
76
77
78
79
}

I0mapmon::~I0mapmon()
{
    delete ui;
}
80
81

void I0mapmon::onNamesReady(const QStringList &n) {
Giacomo Strangolino's avatar
Giacomo Strangolino committed
82
83
    ui->qucby->clear();
    ui->qucby->insertItems(0, n);
84
    if(n.size()) {
Giacomo Strangolino's avatar
Giacomo Strangolino committed
85
//        onYChanged(n.first());
86
        // X combo box
Giacomo Strangolino's avatar
Giacomo Strangolino committed
87
        connect(ui->qucby, SIGNAL(currentTextChanged(QString)), this, SLOT(onYChanged(QString)));
88
89
90
91
92
93
94
    }
}

void I0mapmon::applyWavelenX() {
    bool ok;
    QString tgt, txt;
    QVector<double> vals;
Giacomo Strangolino's avatar
Giacomo Strangolino committed
95
    txt = ui->quleWlenWei->text();
96
97
98
99
100
101
102
    foreach(const QString& v, txt.split(QRegularExpression(",\\s*")))
        if(v.toDouble(&ok) && ok) vals.push_back(v.toDouble());
    sender()->objectName() == "pbApplyWlens" ? tgt = QString("$2/FEL0%1_IOM_wavelengths").arg(m_fel0x) :
            tgt = QString("$2/FEL0%1_IOM_wavelength_weights").arg(m_fel0x);
    qDebug() << __PRETTY_FUNCTION__ << "*WOULD WRITE ON* target" << tgt << "values" << vals;
}

Giacomo Strangolino's avatar
Giacomo Strangolino committed
103
void I0mapmon::onYChanged(const QString &y) {
104
105
    ui->quSpectrumPlot->unsetSources();
    ui->quSpectrumPlot->clearPlot();
Giacomo Strangolino's avatar
Giacomo Strangolino committed
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
    ui->quSpectrumPlot->setSource("$1/" + y);
}

void I0mapmon::onWlensChanged(const CuData &da) {
    ui->qucblambda->setEnabled(!da["err"].toBool());
    if(ui->qucblambda->isEnabled()) {
        m_cb_model->clear();
        m_cb_model->addItem("select...", false);
        foreach(const QString& wl, QuString(da["value"].toString()).split(",")) {
            m_cb_model->addItem(wl);
        }
    }
    ui->qucblambda->setCurrentIndex(0);
}

void I0mapmon::onWlenSelectionChanged(const QString& , bool ) {
    QStringList wlens;
    for(int i = 0; i < m_cb_model->rowCount(); i++) {
        QStandardItem *it = m_cb_model->item(i);
        if(it->data(Qt::CheckStateRole).toBool())
            wlens.append(it->text());
    }
    ui->quleWlens->setText(wlens.join(","));
}

void I0mapmon::m_setup_x_list() {
    ui->qucbx->insertItem(0, "time");

    // "PM2a Ni Photocurrent (a.u.)" /pos/diagnostics/photo_current_pos.01    None    GetArea3
    // "PM2a Ca Photocurrent (a.u.)" pos/diagnostics/photo_current_pos.01    None    GetArea2
    // "PM2a OLD Photocurrent" srv-tf-srf:20000/ec-tf-esa-01/v1720/1000000     None GetArea4
    // "PRESTO Intensity"      pos/pesp/ccd-pesp_pos.01  Intensity      None
    // "TARDI Intensity"   pos_mag/pesp/ccd-pesp_pos_mag.01  Intensity      None
   //  "DPI Photodiode (Beamline Transmission)" pos/diagnostics/pico_pos.01    None    GetIc
    // "LDM Photodiode (Beamline Transmission)" pos/diagnostics/pico_pos.01    None    GetId

    ui->qucbx->insertItem(ui->qucbx->count(), "PM2a Ni Photocurrent (a.u.)");
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/diagnostics/photo_current_pos.01/GetArea3", CheckableComboBoxModel::SrcRole);
    ui->qucbx->insertItem(ui->qucbx->count(), "PM2a Ca Photocurrent (a.u.)");
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/diagnostics/photo_current_pos.01/GetArea2", CheckableComboBoxModel::SrcRole);
    ui->qucbx->insertItem(ui->qucbx->count(), "PM2a OLD Photocurrent");
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "srv-tf-srf:20000/ec-tf-esa-01/v1720/1000000/GetArea4", CheckableComboBoxModel::SrcRole);
    ui->qucbx->insertItem(ui->qucbx->count(), "PRESTO Intensity");
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/pesp/ccd-pesp_pos.01/Intensity", CheckableComboBoxModel::SrcRole);
    ui->qucbx->insertItem(ui->qucbx->count(), "DPI Photodiode (Beamline Transmission)");
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/diagnostics/pico_pos.01/GetIc", CheckableComboBoxModel::SrcRole);
    ui->qucbx->insertItem(ui->qucbx->count(), "LDM Photodiode (Beamline Transmission)");
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/diagnostics/pico_pos.01/GetId", CheckableComboBoxModel::SrcRole);
}

void I0mapmon::m_plot_reconf() {
    qDebug() << __PRETTY_FUNCTION__ << "reconfiguring plot with X " << ui->qucbx->currentText()
             << ui->qucby->currentText() << ui->quleWlens->text();
159
}