i0mapmon.cpp 8.46 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()));
Giacomo Strangolino's avatar
Giacomo Strangolino committed
77
78
79
80
81
82
83
84
85
86

        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)));
        ui->cbYAuto->setChecked(true); // disable y bounds line edits
87
    }
Giacomo Strangolino's avatar
Giacomo Strangolino committed
88
89
90
91
92
93
}

I0mapmon::~I0mapmon()
{
    delete ui;
}
94
95

void I0mapmon::onNamesReady(const QStringList &n) {
Giacomo Strangolino's avatar
Giacomo Strangolino committed
96
    qDebug() << __PRETTY_FUNCTION__ << n;
Giacomo Strangolino's avatar
Giacomo Strangolino committed
97
98
    ui->qucby->clear();
    ui->qucby->insertItems(0, n);
99
    if(n.size()) {
100
        //        onYChanged(n.first());
101
        // X combo box
Giacomo Strangolino's avatar
Giacomo Strangolino committed
102
        connect(ui->qucby, SIGNAL(currentTextChanged(QString)), this, SLOT(onYChanged(QString)));
103
104
105
106
107
108
109
    }
}

void I0mapmon::applyWavelenX() {
    bool ok;
    QString tgt, txt;
    QVector<double> vals;
110
    sender()->objectName() == "pbApplyWlens" ? txt = ui->quleWlens->text() : txt = ui->quleWlenWei->text();
111
112
113
114
    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);
115
116
117
118
119
120
121
    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;
    }
122
123
}

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

Giacomo Strangolino's avatar
Giacomo Strangolino committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
}

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());
    }
147
148
    ui->labelleWlens->setText(wlens.join(","));
    ui->qucblambda->setItemText(0, ui->labelleWlens->text());
Giacomo Strangolino's avatar
Giacomo Strangolino committed
149
150
}

Giacomo Strangolino's avatar
Giacomo Strangolino committed
151
152
153
154
void I0mapmon::setYMinMax() {
    ui->plot->setYBounds(ui->leyMin->text().toDouble(), ui->leyMax->text().toDouble());
}

Giacomo Strangolino's avatar
Giacomo Strangolino committed
155
156
void I0mapmon::m_setup_x_list() {
    ui->qucbx->insertItem(0, "time");
157
    ui->qucbx->setItemData(0, "time", Qt::UserRole + 1);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
158
159
160
161
162
163

    // "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
164
    //  "DPI Photodiode (Beamline Transmission)" pos/diagnostics/pico_pos.01    None    GetIc
Giacomo Strangolino's avatar
Giacomo Strangolino committed
165
166
167
    // "LDM Photodiode (Beamline Transmission)" pos/diagnostics/pico_pos.01    None    GetId

    ui->qucbx->insertItem(ui->qucbx->count(), "PM2a Ni Photocurrent (a.u.)");
168
    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
169
    ui->qucbx->insertItem(ui->qucbx->count(), "PM2a Ca Photocurrent (a.u.)");
170
    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
171
    ui->qucbx->insertItem(ui->qucbx->count(), "PM2a OLD Photocurrent");
172
    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
173
    ui->qucbx->insertItem(ui->qucbx->count(), "PRESTO Intensity");
Giacomo Strangolino's avatar
Giacomo Strangolino committed
174
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/pesp/ccd-pesp_pos.01/Intensity", Qt::UserRole + 1);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
175
    ui->qucbx->insertItem(ui->qucbx->count(), "DPI Photodiode (Beamline Transmission)");
Giacomo Strangolino's avatar
Giacomo Strangolino committed
176
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/diagnostics/pico_pos.01->GetIc", Qt::UserRole + 1);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
177
    ui->qucbx->insertItem(ui->qucbx->count(), "LDM Photodiode (Beamline Transmission)");
Giacomo Strangolino's avatar
Giacomo Strangolino committed
178
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/diagnostics/pico_pos.01->GetId", Qt::UserRole + 1);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
179
180
}

Giacomo Strangolino's avatar
Giacomo Strangolino committed
181
182
183
184
185
186
187
188
189
190
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
191
192
193
}

void I0mapmon::m_plot_reconf() {
Giacomo Strangolino's avatar
Giacomo Strangolino committed
194
    const QString& srcx = ui->qucbx->itemData(ui->qucbx->currentIndex(), Qt::UserRole + 1).toString();
195
196
    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
197
    ui->plot->setSources(srcx, devy + '/' + ui->qucby->currentText(), m_selected_wlens(), ui->quionSamples->findChild<QuLabel *>()->text().toInt());
198
}