i0mapmon.cpp 7.25 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
#include <qustring.h>
14
#include <quwriter.h>
Giacomo Strangolino's avatar
Giacomo Strangolino committed
15
16

#include "checkablecomboboxmodel.h"
17

Giacomo Strangolino's avatar
Giacomo Strangolino committed
18
19
20
21
22
23
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
24

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

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

    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
41
42
        m_cb_model = new CheckableComboBoxModel(ui->qucby);
        connect(m_cb_model, SIGNAL(itemChecked(QString,bool)), this, SLOT(onWlenSelectionChanged(QString, bool)));
43
        ui->qucblambda->setEditable(true);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
44
45
        ui->qucblambda->setModel(m_cb_model);

46
47
48
49
50
51
52
53
        // 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()));
54
        connect(ui->pbApplyWlens, SIGNAL(clicked()), this, SLOT(applyWavelenX()));
55
56

        // qu-line edit for wavelen / wavelen weights
57
        ui->quleWlens->setTarget(QString("$2/FEL0%1_IOM_wavelengths").arg(m_fel0x));
58
59
60
61
62
        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
63
        connect(ui->qulWlens, SIGNAL(newData(CuData)), this, SLOT(onWlensChanged(CuData)));
64
65

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

        m_setup_x_list();

        // trigger plot reconf
        connect(ui->pbPlotReconf, SIGNAL(clicked()), this, SLOT(m_plot_reconf()));
77
    }
Giacomo Strangolino's avatar
Giacomo Strangolino committed
78
79
80
81
82
83
}

I0mapmon::~I0mapmon()
{
    delete ui;
}
84
85

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

void I0mapmon::applyWavelenX() {
    bool ok;
    QString tgt, txt;
    QVector<double> vals;
100
    sender()->objectName() == "pbApplyWlens" ? txt = ui->quleWlens->text() : txt = ui->quleWlenWei->text();
101
102
103
104
    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);
105
106
107
108
109
110
111
    if(vals.size() > 0) {
        QuWriter *w = new QuWriter(this, cu_pool, m_ctrl_factory_pool);
        w->setAutoDestroy(true);
        w->setTarget(tgt);
        w->execute(vals);
        qDebug() << __PRETTY_FUNCTION__ << "*WOULD WRITE ON* target" << w->target() << "values" << vals;
    }
112
113
}

Giacomo Strangolino's avatar
Giacomo Strangolino committed
114
void I0mapmon::onYChanged(const QString &y) {
Giacomo Strangolino's avatar
Giacomo Strangolino committed
115

Giacomo Strangolino's avatar
Giacomo Strangolino committed
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
}

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());
    }
137
138
    ui->labelleWlens->setText(wlens.join(","));
    ui->qucblambda->setItemText(0, ui->labelleWlens->text());
Giacomo Strangolino's avatar
Giacomo Strangolino committed
139
140
141
142
}

void I0mapmon::m_setup_x_list() {
    ui->qucbx->insertItem(0, "time");
143
    ui->qucbx->setItemData(0, "time", Qt::UserRole + 1);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
144
145
146
147
148
149

    // "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
150
    //  "DPI Photodiode (Beamline Transmission)" pos/diagnostics/pico_pos.01    None    GetIc
Giacomo Strangolino's avatar
Giacomo Strangolino committed
151
152
153
    // "LDM Photodiode (Beamline Transmission)" pos/diagnostics/pico_pos.01    None    GetId

    ui->qucbx->insertItem(ui->qucbx->count(), "PM2a Ni Photocurrent (a.u.)");
154
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/diagnostics/photo_current_pos.01->GetArea3(0,%1)", Qt::UserRole + 1);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
155
    ui->qucbx->insertItem(ui->qucbx->count(), "PM2a Ca Photocurrent (a.u.)");
156
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/diagnostics/photo_current_pos.01->GetArea2(0,%1)", Qt::UserRole + 1);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
157
    ui->qucbx->insertItem(ui->qucbx->count(), "PM2a OLD Photocurrent");
158
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "srv-tf-srf:20000/ec-tf-esa-01/v1720/1000000->GetArea4(0,%1)", Qt::UserRole + 1);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
159
    ui->qucbx->insertItem(ui->qucbx->count(), "PRESTO Intensity");
Giacomo Strangolino's avatar
Giacomo Strangolino committed
160
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/pesp/ccd-pesp_pos.01/Intensity", Qt::UserRole + 1);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
161
    ui->qucbx->insertItem(ui->qucbx->count(), "DPI Photodiode (Beamline Transmission)");
Giacomo Strangolino's avatar
Giacomo Strangolino committed
162
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/diagnostics/pico_pos.01/GetIc", Qt::UserRole + 1);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
163
    ui->qucbx->insertItem(ui->qucbx->count(), "LDM Photodiode (Beamline Transmission)");
Giacomo Strangolino's avatar
Giacomo Strangolino committed
164
165
166
167
168
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/diagnostics/pico_pos.01/GetId", Qt::UserRole + 1);
}

QList<int> I0mapmon::m_selected_wlens() const {
    QList<int> idxs;
169
170
    for(int i = 0; i < m_cb_model->rowCount(); i++) // i - 1: item 0: "time"
        if(m_cb_model->item(i)->data(Qt::CheckStateRole).toBool()) idxs << i - 1;
Giacomo Strangolino's avatar
Giacomo Strangolino committed
171
    return idxs;
Giacomo Strangolino's avatar
Giacomo Strangolino committed
172
173
174
}

void I0mapmon::m_plot_reconf() {
Giacomo Strangolino's avatar
Giacomo Strangolino committed
175
    const QString& srcx = ui->qucbx->itemData(ui->qucbx->currentIndex(), Qt::UserRole + 1).toString();
176
177
    const QString devy = ui->quionSamples->source().remove("/" + ui->quionSamples->source().section('/',- 1));
    printf("\e[1;32mI0mapmon.m_plot_reconf x \"%s\" y \"%s\"\e[0m\n", qstoc(srcx), qstoc(devy));
Giacomo Strangolino's avatar
Giacomo Strangolino committed
178
    ui->plot->setSources(srcx, devy + '/' + ui->qucby->currentText(), m_selected_wlens(), ui->quionSamples->findChild<QuLabel *>()->text().toInt());
179
}