Commit db44cb90 authored by Giacomo Strangolino's avatar Giacomo Strangolino
Browse files

fixes and new features

parent c8775fc2
No preview for this file type
......@@ -74,6 +74,16 @@ I0mapmon::I0mapmon(CumbiaPool *cumbia_pool, QWidget *parent) :
// trigger plot reconf
connect(ui->pbPlotReconf, SIGNAL(clicked()), this, SLOT(m_plot_reconf()));
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
}
}
......@@ -138,6 +148,10 @@ void I0mapmon::onWlenSelectionChanged(const QString& , bool ) {
ui->qucblambda->setItemText(0, ui->labelleWlens->text());
}
void I0mapmon::setYMinMax() {
ui->plot->setYBounds(ui->leyMin->text().toDouble(), ui->leyMax->text().toDouble());
}
void I0mapmon::m_setup_x_list() {
ui->qucbx->insertItem(0, "time");
ui->qucbx->setItemData(0, "time", Qt::UserRole + 1);
......
......@@ -30,6 +30,7 @@ private slots:
void onYChanged(const QString& y);
void onWlensChanged(const CuData &s);
void onWlenSelectionChanged(const QString &wl, bool enab);
void setYMinMax();
void m_plot_reconf();
......
......@@ -6,14 +6,99 @@
<rect>
<x>0</x>
<y>0</y>
<width>776</width>
<width>830</width>
<height>563</height>
</rect>
</property>
<property name="windowTitle">
<string>I0mapmon</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout_2">
<item row="3" column="0" colspan="8">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lTitle">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Real time</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Wavelengths:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="QPushButton" name="pbApplyWlens">
<property name="text">
<string>APPLY</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QuLabel" name="qulWlens"/>
</item>
<item row="4" column="5">
<widget class="QuLabel" name="qulWlenWei"/>
</item>
<item row="4" column="6">
<widget class="QuLineEdit" name="quleWlenWei"/>
</item>
<item row="4" column="7">
<widget class="QPushButton" name="pbApplyWlenWei">
<property name="text">
<string>APPLY</string>
</property>
</widget>
</item>
<item row="4" column="4">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Wavelen weights:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QuLineEdit" name="quleWlens"/>
</item>
<item row="4" column="8">
<widget class="QPushButton" name="pbConfPlot">
<property name="text">
<string>Configure Plot</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0" colspan="9">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
......@@ -78,6 +163,12 @@
</item>
<item>
<widget class="QLabel" name="labelleWlens">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
......@@ -86,7 +177,7 @@
<item>
<widget class="QPushButton" name="pbPlotReconf">
<property name="text">
<string>APPLY</string>
<string>PLOT</string>
</property>
</widget>
</item>
......@@ -115,83 +206,79 @@
</item>
</layout>
</item>
<item row="4" column="6">
<widget class="QuLabel" name="qulWlenWei"/>
</item>
<item row="4" column="8">
<widget class="QPushButton" name="pbApplyWlenWei">
<property name="text">
<string>APPLY</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QuLineEdit" name="quleWlens"/>
</item>
<item row="4" column="1">
<widget class="QuLabel" name="qulWlens"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Wavelengths:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="0" colspan="9">
<widget class="I0MMonPlot" name="plot" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="4" column="7">
<widget class="QuLineEdit" name="quleWlenWei"/>
</item>
<item row="4" column="4">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Wavelen weights:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="QPushButton" name="pbApplyWlens">
<property name="text">
<string>APPLY</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="9">
<widget class="QLabel" name="lTitle">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Real time</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="I0MMonPlot" name="plot" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbConfPlot">
<property name="title">
<string>Plot configuration</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QCheckBox" name="cbYAuto">
<property name="text">
<string>Y auto scale</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Y min:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="leyMin">
<property name="text">
<string>-10</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Y max:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QLineEdit" name="leyMax">
<property name="text">
<string>10</string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QPushButton" name="pbApplyBounds">
<property name="text">
<string>APPLY BOUNDS</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
......
......@@ -20,11 +20,12 @@
I0MMonPlot::I0MMonPlot(QWidget *parent, CumbiaPool *cup, const CuControlsFactoryPool &fpoo)
: QuPlotBase(parent),
m_symstyles (QList<QwtSymbol::Style> () << QwtSymbol::XCross << QwtSymbol::Cross
<< QwtSymbol::Rect << QwtSymbol::Triangle << QwtSymbol::Star1 << QwtSymbol::Diamond << QwtSymbol::Ellipse) {
<< QwtSymbol::Rect << QwtSymbol::Triangle << QwtSymbol::Star1 << QwtSymbol::Diamond << QwtSymbol::Ellipse) {
m_ctrl_fpool = fpoo;
m_cu_poo = cup;
m_time_mode = m_empty = true;
m_numsamples = 1;
m_ymin = m_ymax = 0;
CuPluginLoader plo;
QObject *plugin_qob;
m_multiread_plu_i = plo.get<QuMultiReaderPluginInterface>("libcumbia-multiread-plugin.so", &plugin_qob);
......@@ -39,29 +40,23 @@ I0MMonPlot::I0MMonPlot(QWidget *parent, CumbiaPool *cup, const CuControlsFactory
connect(m_multiread_plu_i->get_qobject(), SIGNAL(onSeqReadComplete(const QList<CuData> &)),
this, SLOT(onDataReady(const QList<CuData> &)));
}
setXAxisAutoscaleEnabled(false);
setYAxisAutoscaleEnabled(false);
}
bool I0MMonPlot::pluginLoaded() const {
return m_multiread_plu_i != nullptr;
}
bool I0MMonPlot::yAutoScale() const {
return m_ymax == m_ymin;
}
void I0MMonPlot::onDataReady(const QList<CuData> &dl) {
qDebug() << __PRETTY_FUNCTION__ << "data szi" << dl.size();
double x = 0.0;
foreach(QString cn, m_curvesymap.keys()) {
QuPlotCurve *c = curve(cn);
if(c && c->style() != QwtPlotCurve::Dots) {
c->setStyle(QwtPlotCurve::Dots);
QPen p = c->pen();
p.setWidthF(2.0f);
c->setPen(p);
}
#if CUMBIA_QTCONTROLS_VERSION > 0x010202
c->setMaxDataSizeForSymbol(0); // disable first points symbol
#endif
if(!c->symbol() || c->symbol()->style() != m_curvesymap[cn])
c->setSymbol(new QwtSymbol(m_curvesymap[cn], c->brush(), c->pen(), QSize(10, 10)));
}
if(!m_time_mode && dl.size() == 2) { // correlate
QVector<double> yv, xv;
const CuData& xd = dl[0];
......@@ -81,9 +76,7 @@ void I0MMonPlot::onDataReady(const QList<CuData> &dl) {
// y
const std::vector<double> &yt = yd["value"].toDoubleVector();
foreach(int i, m_lambdas.keys()) {
printf("lambda key %d yt size %ld\n", i, yt.size());
if(i < static_cast<int>(yt.size()) ) {
printf("\e[0;35m - appending to curve %f %f %f\e[0m\n", m_lambdas[i], x, yt[i]);
appendData(QString("lambda %1").arg(m_lambdas[i]), x, yt[i]);
yv << yt[i];
xv << x;
......@@ -91,27 +84,31 @@ void I0MMonPlot::onDataReady(const QList<CuData> &dl) {
}
m_set_bounds(xv, yv);
}
else { // trend in time
else if(m_time_mode) { // trend in time
const CuData &da = dl[0];
const std::vector<double> &ystdv = da["value"].toDoubleVector();
QList<double> lambdas = m_lambdas.values();
std::sort(lambdas.begin(), lambdas.end());
const QVector<double> xv = lambdas.toVector();
QVector<double> xv {0.0}; // m_set_bounds needs a vector, say 0 and data size
#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
const QVector<double> yv = QVector<double>::fromStdVector(ystdv);
#else
const QVector<double> yv(ystdv.begin(), ystdv.end());
const QVector<double> yv(ystdv.begin(), ystdv.end());
#endif
printf("\e[0;33mdata %s -- timestamp %f\e[0m\n", datos(da), x);
foreach(int idx, m_lambdas.keys()) {
const QString curveName = QString("lambda %1").arg(m_lambdas[idx]);
const QuPlotCurve *c = curve(curveName);
xv << c->data()->size();
if(idx < static_cast<int>(yv.size()) && curve(curveName) != nullptr ) {
m_set_bounds(xv, yv);
appendData(curveName, m_lambdas[idx], yv[idx]);
appendData(curveName, xv[1], yv[idx]);
}
}
refresh();
m_curves_style();
}
else {
printf("\e[1;31mI0MMonPlot::onDataReady: no time mode: data size %d\e[0m\n", dl.size());
for(int i = 0; i < dl.size(); i++)
printf("\e[1;31mI0MMonPlot::onDataReady: %s\e[0m\n", datos(dl[i]));
}
m_empty = false;
}
......@@ -150,19 +147,54 @@ void I0MMonPlot::setSources(const QString &x, const QString &y, const QMap<int,
}
}
void I0MMonPlot::setYBounds(double ymi, double yma) {
if(ymi != yma && ymi < yma) {
m_ymin = ymi;
m_ymax = yma;
setYLowerBound(ymi);
setYUpperBound(yma);
}
}
void I0MMonPlot::setYBoundsAuto(bool a) {
if(a) {
m_ymin = m_ymax = 0;
m_empty = true;
}
}
void I0MMonPlot::m_set_bounds(const QVector<double> &xv, const QVector<double> &yv)
{
// scales
const auto [xm, xM] = std::minmax_element(begin(xv), end(xv));
const auto [ym, yM] = std::minmax_element(begin(yv), end(yv));
if(m_ymin == m_ymax) { // auto scale Y
double ylb, yub;
const auto [ym, yM] = std::minmax_element(begin(yv), end(yv));
ylb = m_empty ? (*ym) : yLowerBound();
yub = m_empty ? (*yM) : yUpperBound();
// y auto scale?
if(*yM == *ym) {
if(ylb >= *ym)
ylb = (*ym - 0.5);
if(yub <= *yM)
yub = (*yM + 0.5);
} else {
if(ylb >= *ym)
ylb = (*ym - 0.15 * (*yM - *ym));
if(yub <= *yM)
yub = (*yM + 0.15 * (*yM - *ym));
}
double xlb, xub, ylb, yub;
xlb = m_empty ? (*xm) : xLowerBound();
xub = m_empty ? (*xM) : xUpperBound();
ylb = m_empty ? (*ym) : yLowerBound();
yub = m_empty ? (*yM) : yUpperBound();
if(ylb != yLowerBound())
setYLowerBound(ylb);
if(yub != yUpperBound())
setYUpperBound(yub);
}
const auto [xm, xM] = std::minmax_element(begin(xv), end(xv));
double xlb, xub;
xlb = m_empty ? (*xm) : xLowerBound();
xub = m_empty ? (*xM) : xUpperBound();
if(*xm == *xM) {
if(*xm == *xM) {
if(xlb >= *xm)
xlb = (*xm - 0.5);
if(xub <= *xM)
......@@ -173,42 +205,36 @@ void I0MMonPlot::m_set_bounds(const QVector<double> &xv, const QVector<double> &
if(xub <= *xM)
xub = (*xM + 0.15 * (*xM - *xm));
}
if(*yM == *ym) {
if(ylb >= *ym)
ylb = (*ym - 0.5);
if(yub <= *yM)
yub = (*yM + 0.5);
} else {
if(ylb >= *ym)
ylb = (*ym - 0.15 * (*yM - *ym));
if(yub <= *yM)
yub = (*yM + 0.15 * (*yM - *ym));
}
if(xlb != xLowerBound())
setXLowerBound(xlb);
if(xub != xUpperBound())
setXUpperBound(xub);
if(ylb != yLowerBound())
setYLowerBound(ylb);
if(yub != yUpperBound())
setYUpperBound(yub);
}
void I0MMonPlot::m_reset_scales() {
setAxisScaleDraw(QwtPlot::xBottom, new QwtScaleDraw());
setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine());
setXAxisAutoscaleEnabled(false);
setYAxisAutoscaleEnabled(false);
setXLowerBound(-0.5); setXUpperBound(0.5);
setYLowerBound(-0.5); setYUpperBound(0.5);
setXLowerBound(-0.5);
setXUpperBound(0.5);
if(m_ymin == m_ymax) {
setYLowerBound(-0.5);
setYUpperBound(0.5);
}
}
void I0MMonPlot::m_set_x_trend_scale() {
setXAxisAutoscaleEnabled(true);
QuTimeScaleDraw *tsd = new QuTimeScaleDraw();
tsd->setDateEnabled(false);
setAxisScaleDraw(QwtPlot::xBottom, tsd);
setAxisLabelRotation(QwtPlot::xBottom, -50.0);
setAxisScaleEngine(QwtPlot::xBottom, new QwtDateScaleEngine(Qt::LocalTime));
setAxisLabelAlignment( QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom );
void I0MMonPlot::m_curves_style() {
foreach(QString cn, m_curvesymap.keys()) {
QuPlotCurve *c = curve(cn);
if(c && c->style() != QwtPlotCurve::Dots) {
c->setStyle(QwtPlotCurve::Dots);
// QPen p = c->pen();
// p.setWidthF(2.0f);
// c->setPen(p);
}
#if CUMBIA_QTCONTROLS_VERSION > 0x010202
c->setMaxDataSizeForSymbol(0); // disable first points symbol
#endif
if(!c->symbol() || c->symbol()->style() != m_curvesymap[cn])
c->setSymbol(new QwtSymbol(m_curvesymap[cn], c->brush(), c->pen(), QSize(6, 6)));
}
}
......@@ -18,17 +18,21 @@ public:
bool pluginLoaded() const;
bool yAutoScale() const;
signals:
public slots:
void onDataReady(const QList<CuData> & dl);
void setSources(const QString& x, const QString& y, const QMap<int, double> lambdamap, int nsamples);
void setYBounds(double ymi, double yma);
void setYBoundsAuto(bool a);
private:
void m_set_bounds(const QVector<double> &xv, const QVector<double> &yv);
void m_reset_scales();
void m_set_x_trend_scale();
void m_curves_style();
CumbiaPool *m_cu_poo;
CuControlsFactoryPool m_ctrl_fpool;
......@@ -41,6 +45,8 @@ private:
const QList<QwtSymbol::Style> m_symstyles;
bool m_time_mode, m_empty;
double m_ymin, m_ymax;
};
#endif // I0MMONPLOT_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment