i0mapmon.cpp 6.5 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

        // plot
Giacomo Strangolino's avatar
Giacomo Strangolino committed
62
63
64
65
        ui->plot->setYLowerBound(-1.0);
        ui->plot->setYUpperBound(1.0);
        ui->plot->setXLowerBound(-1.0);
        ui->plot->setXUpperBound(1.0);
66
        // autoscale
Giacomo Strangolino's avatar
Giacomo Strangolino committed
67
        ui->plot->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
    qDebug() << __PRETTY_FUNCTION__ << n;
Giacomo Strangolino's avatar
Giacomo Strangolino committed
83
84
    ui->qucby->clear();
    ui->qucby->insertItems(0, n);
85
    if(n.size()) {
Giacomo Strangolino's avatar
Giacomo Strangolino committed
86
//        onYChanged(n.first());
87
        // X combo box
Giacomo Strangolino's avatar
Giacomo Strangolino committed
88
        connect(ui->qucby, SIGNAL(currentTextChanged(QString)), this, SLOT(onYChanged(QString)));
89
90
91
92
93
94
95
    }
}

void I0mapmon::applyWavelenX() {
    bool ok;
    QString tgt, txt;
    QVector<double> vals;
Giacomo Strangolino's avatar
Giacomo Strangolino committed
96
    txt = ui->quleWlenWei->text();
97
98
99
100
101
102
103
    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
104
void I0mapmon::onYChanged(const QString &y) {
Giacomo Strangolino's avatar
Giacomo Strangolino committed
105

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
}

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(","));
Giacomo Strangolino's avatar
Giacomo Strangolino committed
128
    ui->qucblambda->setItemText(0, ui->quleWlens->text());
Giacomo Strangolino's avatar
Giacomo Strangolino committed
129
130
131
132
133
134
135
136
137
138
139
140
141
142
}

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.)");
Giacomo Strangolino's avatar
Giacomo Strangolino committed
143
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/diagnostics/photo_current_pos.01->GetArea3", Qt::UserRole + 1);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
144
    ui->qucbx->insertItem(ui->qucbx->count(), "PM2a Ca Photocurrent (a.u.)");
Giacomo Strangolino's avatar
Giacomo Strangolino committed
145
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/diagnostics/photo_current_pos.01->GetArea2", Qt::UserRole + 1);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
146
    ui->qucbx->insertItem(ui->qucbx->count(), "PM2a OLD Photocurrent");
Giacomo Strangolino's avatar
Giacomo Strangolino committed
147
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "srv-tf-srf:20000/ec-tf-esa-01/v1720/1000000->GetArea4", Qt::UserRole + 1);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
148
    ui->qucbx->insertItem(ui->qucbx->count(), "PRESTO Intensity");
Giacomo Strangolino's avatar
Giacomo Strangolino committed
149
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/pesp/ccd-pesp_pos.01/Intensity", Qt::UserRole + 1);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
150
    ui->qucbx->insertItem(ui->qucbx->count(), "DPI Photodiode (Beamline Transmission)");
Giacomo Strangolino's avatar
Giacomo Strangolino committed
151
    ui->qucbx->setItemData(ui->qucbx->count() - 1, "pos/diagnostics/pico_pos.01/GetIc", Qt::UserRole + 1);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
152
    ui->qucbx->insertItem(ui->qucbx->count(), "LDM Photodiode (Beamline Transmission)");
Giacomo Strangolino's avatar
Giacomo Strangolino committed
153
154
155
156
157
158
159
160
    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;
    for(int i = 0; i < m_cb_model->rowCount(); i++)
        if(m_cb_model->item(i)->data(Qt::CheckStateRole).toBool()) idxs << i;
    return idxs;
Giacomo Strangolino's avatar
Giacomo Strangolino committed
161
162
163
}

void I0mapmon::m_plot_reconf() {
Giacomo Strangolino's avatar
Giacomo Strangolino committed
164
165
166
    const QString& srcx = ui->qucbx->itemData(ui->qucbx->currentIndex(), Qt::UserRole + 1).toString();
    const QString& devy = ui->quionSamples->source().section('/', 0, 2);
    ui->plot->setSources(srcx, devy + '/' + ui->qucby->currentText(), m_selected_wlens(), ui->quionSamples->findChild<QuLabel *>()->text().toInt());
167
}