i0mapmon.cpp 8.88 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
        // continue setup
        QuWatcher *w = new QuWatcher(this, cumbia_pool, m_ctrl_factory_pool);
        w->setSingleShot(true);
        w->setAutoDestroy(true);
50
51
52
53
54
55
56
57
        w->attach(this, SLOT(onLabelReady(QStringList)));
        w->setSource("$1/label");

        QuWatcher *nw = new QuWatcher(this, cumbia_pool, m_ctrl_factory_pool);
        nw->setSingleShot(true);
        nw->setAutoDestroy(true);
        nw->attach(&m_ynames);
        nw->setSource("$1/name");
58
59

        connect(ui->pbApplyWlenWei, SIGNAL(clicked()), this, SLOT(applyWavelenX()));
60
        connect(ui->pbApplyWlens, SIGNAL(clicked()), this, SLOT(applyWavelenX()));
61
62

        // qu-line edit for wavelen / wavelen weights
63
        ui->quleWlens->setTarget(QString("$2/FEL0%1_IOM_wavelengths").arg(m_fel0x));
64
65
66
67
68
        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
69
        connect(ui->qulWlens, SIGNAL(newData(CuData)), this, SLOT(onWlensChanged(CuData)));
70
71

        // plot
Giacomo Strangolino's avatar
Giacomo Strangolino committed
72
73
74
75
        ui->plot->setYLowerBound(-1.0);
        ui->plot->setYUpperBound(1.0);
        ui->plot->setXLowerBound(-1.0);
        ui->plot->setXUpperBound(1.0);
76
        // autoscale
Giacomo Strangolino's avatar
Giacomo Strangolino committed
77
        ui->plot->setYAxisAutoscaleEnabled(true);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
78
79
80
81
82

        m_setup_x_list();

        // trigger plot reconf
        connect(ui->pbPlotReconf, SIGNAL(clicked()), this, SLOT(m_plot_reconf()));
Giacomo Strangolino's avatar
Giacomo Strangolino committed
83
84
85
86
87
88
89
90
91

        ui->gbConfPlot->setVisible(false);
        connect(ui->pbConfPlot, SIGNAL(toggled(bool)), ui->gbConfPlot, SLOT(setChecked(bool)));
        connect(ui->pbConfPlot, SIGNAL(toggled(bool)), ui->gbConfPlot, SLOT(setVisible(bool)));
        connect(ui->gbConfPlot, SIGNAL(toggled(bool)), ui->pbConfPlot, SLOT(setChecked(bool)));
        connect(ui->cbYAuto, SIGNAL(toggled(bool)), ui->leyMin, SLOT(setDisabled(bool)));
        connect(ui->cbYAuto, SIGNAL(toggled(bool)), ui->leyMax, SLOT(setDisabled(bool)));
        connect(ui->pbApplyBounds, SIGNAL(clicked()), this, SLOT(setYMinMax()));
        connect(ui->cbYAuto, SIGNAL(toggled(bool)), ui->plot, SLOT(setYBoundsAuto(bool)));
92
        connect(ui->cbLogScale, SIGNAL(toggled(bool)), ui->plot, SLOT(setYLogScale(bool)));
Giacomo Strangolino's avatar
Giacomo Strangolino committed
93
        ui->cbYAuto->setChecked(true); // disable y bounds line edits
94
    }
Giacomo Strangolino's avatar
Giacomo Strangolino committed
95
96
97
98
99
100
}

I0mapmon::~I0mapmon()
{
    delete ui;
}
101

102
void I0mapmon::onLabelReady(const QStringList &n) {
Giacomo Strangolino's avatar
Giacomo Strangolino committed
103
    qDebug() << __PRETTY_FUNCTION__ << n;
Giacomo Strangolino's avatar
Giacomo Strangolino committed
104
105
    ui->qucby->clear();
    ui->qucby->insertItems(0, n);
106
    if(n.size()) {
107
        //        onYChanged(n.first());
108
        // X combo box
Giacomo Strangolino's avatar
Giacomo Strangolino committed
109
        connect(ui->qucby, SIGNAL(currentTextChanged(QString)), this, SLOT(onYChanged(QString)));
110
111
112
113
114
115
116
    }
}

void I0mapmon::applyWavelenX() {
    bool ok;
    QString tgt, txt;
    QVector<double> vals;
117
    sender()->objectName() == "pbApplyWlens" ? txt = ui->quleWlens->text() : txt = ui->quleWlenWei->text();
118
119
120
121
    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);
122
123
124
125
126
    if(vals.size() > 0) {
        QuWriter *w = new QuWriter(this, cu_pool, m_ctrl_factory_pool);
        w->setAutoDestroy(true);
        w->setTarget(tgt);
        w->execute(vals);
127
        qDebug() << __PRETTY_FUNCTION__ << "*WRITING ON* target" << w->target() << "values" << vals;
128
    }
129
130
}

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

Giacomo Strangolino's avatar
Giacomo Strangolino committed
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
}

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());
    }
154
155
    ui->labelleWlens->setText(wlens.join(","));
    ui->qucblambda->setItemText(0, ui->labelleWlens->text());
Giacomo Strangolino's avatar
Giacomo Strangolino committed
156
157
}

Giacomo Strangolino's avatar
Giacomo Strangolino committed
158
159
160
161
void I0mapmon::setYMinMax() {
    ui->plot->setYBounds(ui->leyMin->text().toDouble(), ui->leyMax->text().toDouble());
}

Giacomo Strangolino's avatar
Giacomo Strangolino committed
162
163
void I0mapmon::m_setup_x_list() {
    ui->qucbx->insertItem(0, "time");
164
    ui->qucbx->setItemData(0, "time", Qt::UserRole + 1);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
165
166
167
168
169
170

    // "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
171
    //  "DPI Photodiode (Beamline Transmission)" pos/diagnostics/pico_pos.01    None    GetIc
Giacomo Strangolino's avatar
Giacomo Strangolino committed
172
173
174
    // "LDM Photodiode (Beamline Transmission)" pos/diagnostics/pico_pos.01    None    GetId

    ui->qucbx->insertItem(ui->qucbx->count(), "PM2a Ni Photocurrent (a.u.)");
175
    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
176
    ui->qucbx->insertItem(ui->qucbx->count(), "PM2a Ca Photocurrent (a.u.)");
177
    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
178
    ui->qucbx->insertItem(ui->qucbx->count(), "PM2a OLD Photocurrent");
179
    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
180
    ui->qucbx->insertItem(ui->qucbx->count(), "PRESTO Intensity");
Giacomo Strangolino's avatar
Giacomo Strangolino committed
181
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/pesp/ccd-pesp_pos.01/Intensity", Qt::UserRole + 1);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
182
    ui->qucbx->insertItem(ui->qucbx->count(), "DPI Photodiode (Beamline Transmission)");
183
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/diagnostics/pico_pos.01->GetIc(0,%1)", Qt::UserRole + 1);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
184
    ui->qucbx->insertItem(ui->qucbx->count(), "LDM Photodiode (Beamline Transmission)");
185
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/diagnostics/pico_pos.01->GetId(0,%1)", Qt::UserRole + 1);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
186
187
}

Giacomo Strangolino's avatar
Giacomo Strangolino committed
188
189
190
191
192
193
194
195
196
197
QMap<int, double> I0mapmon::m_selected_wlens() const {
    QMap<int, double> m;
    for(int i = 1; i < m_cb_model->rowCount(); i++) {// item 0: "time"
        qDebug() << __PRETTY_FUNCTION__ << "model row count" << m_cb_model->rowCount() << "row" << i << "checked" << m_cb_model->item(i)->data(Qt::CheckStateRole).toBool()
                 << "text " << m_cb_model->item(i)->data(Qt::DisplayRole).toString() << ui->qucblambda->itemText(i).toDouble();
        if(m_cb_model->item(i)->data(Qt::CheckStateRole).toBool())  {
            m[i - 1] = ui->qucblambda->itemText(i).toDouble();
        }
    }
    return m;
Giacomo Strangolino's avatar
Giacomo Strangolino committed
198
199
200
}

void I0mapmon::m_plot_reconf() {
Giacomo Strangolino's avatar
Giacomo Strangolino committed
201
    const QString& srcx = ui->qucbx->itemData(ui->qucbx->currentIndex(), Qt::UserRole + 1).toString();
202
203
    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));
204
205
206
    qDebug() << __PRETTY_FUNCTION__ << m_ynames;
    if(m_ynames.size() > ui->qucby->currentIndex())
        ui->plot->setSources(srcx, devy + '/' + m_ynames[ui->qucby->currentIndex()], m_selected_wlens(), ui->quionSamples->findChild<QuLabel *>()->text().toInt());
207
}