Skip to content

Commit

Permalink
datamonitor: data loading and dummy monitors
Browse files Browse the repository at this point in the history
Signed-off-by: Ionut Muthi <[email protected]>
  • Loading branch information
IonutMuthi committed Apr 3, 2024
1 parent 4bb2a2c commit 31f44e7
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SCOPY_DATAMONITORPLUGIN_EXPORT DataAcquisitionManager : public QObject
public:
explicit DataAcquisitionManager(QObject *parent = nullptr);

void addMonitor(DataMonitorModel *monitor);
void clearMonitorsData();
QList<QString> getMonitors();

Expand All @@ -26,10 +27,11 @@ class SCOPY_DATAMONITORPLUGIN_EXPORT DataAcquisitionManager : public QObject
void updateActiveMonitors(bool toggled, QString monitorName);
QMap<QString, DataMonitorModel *> *getDataMonitorMap() const;

signals:
Q_SIGNALS:
void requestUpdateActiveMonitors();
void requestRead();
void activeMonitorsUpdated();
void monitorAdded(DataMonitorModel *monito);

private:
QMap<QString, int> *m_activeMonitorsMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class SCOPY_DATAMONITORPLUGIN_EXPORT DataMonitorModel : public QObject
QString getDeviceName() const;
void setDeviceName(const QString &newDeviceName);

bool isDummyMonitor() const;
void setIsDummyMonitor(bool newIsDummyMonitor);

void setYdata(const QVector<double> &newYdata);

void setXdata(const QVector<double> &newXdata);

Q_SIGNALS:
void valueUpdated(double time, double value);
void minValueUpdated(double value);
Expand All @@ -75,6 +82,8 @@ class SCOPY_DATAMONITORPLUGIN_EXPORT DataMonitorModel : public QObject

IReadStrategy *readStrategy;
UnitOfMeasurement *unitOfMeasure;

bool m_isDummyMonitor = false;
};
} // namespace datamonitor
} // namespace scopy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LogDataToFile : public QObject

void continuousLogData(QString path);
void logData(QString path);
void loadData(QString path);
void loadData(QString path, bool override);

Q_SIGNALS:
void startLogData();
Expand All @@ -25,6 +25,8 @@ class LogDataToFile : public QObject
private:
DataAcquisitionManager *m_dataAcquisitionManager;
QString *currentFileHeader;

void addDataToCorespondingMonitor(QString monitorName, QVector<double> *time, QVector<double> *val);
};
} // namespace datamonitor
} // namespace scopy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class MonitorSelectionMenu : public QWidget
public:
explicit MonitorSelectionMenu(QMap<QString, DataMonitorModel *> *monitorList, QWidget *parent = nullptr);

void addMonitor(DataMonitorModel *monitor);

Q_SIGNALS:
void monitorToggled(bool toggled, QString monitorName);
void removeMonitor();
Expand All @@ -26,7 +28,6 @@ class MonitorSelectionMenu : public QWidget
QMap<QString, MenuCollapseSection *> deviceMap;

void generateDeviceSection(QString device);
void addMonitor(DataMonitorModel *monitor);
};
} // namespace datamonitor
} // namespace scopy
Expand Down
6 changes: 6 additions & 0 deletions plugins/datamonitorPlugin/src/dataacquisitionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ DataAcquisitionManager::DataAcquisitionManager(QObject *parent)
m_dataMonitorMap = new QMap<QString, DataMonitorModel *>();
}

void DataAcquisitionManager::addMonitor(DataMonitorModel *monitor)
{
getDataMonitorMap()->insert(monitor->getName(), monitor);
Q_EMIT monitorAdded(monitor);
}

void DataAcquisitionManager::clearMonitorsData()
{
foreach(QString monKey, m_activeMonitorsMap->keys()) {
Expand Down
25 changes: 24 additions & 1 deletion plugins/datamonitorPlugin/src/datamonitor/datamonitormodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ void DataMonitorModel::setDataStorageSize()
}
}

bool DataMonitorModel::isDummyMonitor() const { return m_isDummyMonitor; }

void DataMonitorModel::setIsDummyMonitor(bool newIsDummyMonitor) { m_isDummyMonitor = newIsDummyMonitor; }

void DataMonitorModel::setYdata(const QVector<double> &newYdata)
{
ydata.erase(ydata.begin(), ydata.end());
ydata.append(newYdata);
Q_EMIT dataCleared();
}

void DataMonitorModel::setXdata(const QVector<double> &newXdata)
{
xdata.erase(xdata.begin(), xdata.end());
xdata.append(newXdata);
Q_EMIT dataCleared();
}

void DataMonitorModel::setReadStrategy(IReadStrategy *newReadStrategy)
{
readStrategy = newReadStrategy;
Expand All @@ -139,7 +157,12 @@ void DataMonitorModel::clearMonitorData()
Q_EMIT dataCleared();
}

void DataMonitorModel::read() { readStrategy->read(); }
void DataMonitorModel::read()
{
if(!m_isDummyMonitor) {
readStrategy->read();
}
}

double DataMonitorModel::minValue() const { return m_minValue; }

Expand Down
2 changes: 0 additions & 2 deletions plugins/datamonitorPlugin/src/datamonitor/dmmreadstrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ void DMMReadStrategy::read()
double result = (raw + m_offset) * scale * m_umScale;
qDebug() << "dmm read success ";

// double currentTime = QwtDate::toDouble(QDateTime::currentDateTime());

auto &&timeTracker = TimeManager::GetInstance();
double currentTime = QwtDate::toDouble(timeTracker->lastReadValue());

Expand Down
1 change: 1 addition & 0 deletions plugins/datamonitorPlugin/src/datamonitorstylehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ void DataMonitorStyleHelper::DataLoggingMenuStyle(DataLoggingMenu *menu)
StyleHelper::BlueButton(menu->dataLoggingBrowseBtn);
StyleHelper::BlueButton(menu->dataLoggingBtn);
StyleHelper::BlueButton(menu->dataLoadingBtn);
StyleHelper::BlueSquareCheckbox(menu->loadDataOverride);
}

QString DataMonitorStyleHelper::RemoveButtonStyle()
Expand Down
3 changes: 3 additions & 0 deletions plugins/datamonitorPlugin/src/datamonitortool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ DatamonitorTool::DatamonitorTool(DataAcquisitionManager *dataAcquisitionManager,
m_monitorSelectionMenu = new MonitorSelectionMenu(dataAcquisitionManager->getDataMonitorMap());
tool->leftStack()->add("Monitors", m_monitorSelectionMenu);

connect(m_dataAcquisitionManager, &DataAcquisitionManager::monitorAdded, m_monitorSelectionMenu,
&MonitorSelectionMenu::addMonitor);

connect(m_monitorSelectionMenu, &MonitorSelectionMenu::monitorToggled, m_monitorPlot,
[=, this](bool toggled, QString monitorName) {
// toggle monitor active inside data acquisiton manager
Expand Down
38 changes: 23 additions & 15 deletions plugins/datamonitorPlugin/src/menus/dataloggingmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,26 @@ DataLoggingMenu::DataLoggingMenu(QWidget *parent)
dataLoadingBtn = new QPushButton("Load data", logDataSection);
connect(dataLoadingBtn, &QPushButton::clicked, this, [=, this]() {
updateDataLoggingStatus(ProgressBarState::BUSSY);
Q_EMIT requestDataLoading(dataLoggingFilePath->getLineEdit()->text());
Q_EMIT requestDataLoading(dataLoggingFilePath->getLineEdit()->text(), loadDataOverride->isChecked());
});

MenuOnOffSwitch *liveDataLogging = new MenuOnOffSwitch("Live data logging", logDataSection);
connect(liveDataLogging->onOffswitch(), &QAbstractButton::toggled, this, [=, this](bool toggled) {
liveDataLoggingButton = new MenuOnOffSwitch("Live data logging", logDataSection);
connect(liveDataLoggingButton->onOffswitch(), &QAbstractButton::toggled, this, [=, this](bool toggled) {
m_liveDataLogging = toggled;
dataLoggingBtn->setEnabled(!toggled);
dataLoadingBtn->setEnabled(!toggled);
});

dataLoggingBtn->setEnabled(false);
dataLoadingBtn->setEnabled(false);
liveDataLogging->setEnabled(false);
loadDataOverride = new QCheckBox(logDataSection);
loadDataOverride->setText("Override data on load");
loadDataOverride->setChecked(true);

///// time manager
/// ??? is this the best solution
toggleButtonsEnabled(false);

///// time manager timeout used for requesting continuous data logging
auto &&timeTracker = TimeManager::GetInstance();
connect(timeTracker, &TimeManager::timeout, this, [=, this]() {
if(liveDataLogging->onOffswitch()->isChecked()) {
if(liveDataLoggingButton->onOffswitch()->isChecked()) {
Q_EMIT requestLiveDataLogging(dataLoggingFilePath->getLineEdit()->text());
}
});
Expand All @@ -67,20 +68,17 @@ DataLoggingMenu::DataLoggingMenu(QWidget *parent)

} else {
dataLoggingFilePath->getLineEdit()->setStyleSheet("color:white");

dataLoggingBtn->setEnabled(true);
dataLoadingBtn->setEnabled(true);
liveDataLogging->setEnabled(true);

toggleButtonsEnabled(true);
Q_EMIT pathChanged(path);
}
});

logDataSection->contentLayout()->addWidget(new QLabel("Choose file"));
logDataSection->contentLayout()->addWidget(dataLoggingFilePath);
logDataSection->contentLayout()->addWidget(dataLoggingBrowseBtn);
logDataSection->contentLayout()->addWidget(liveDataLogging);
logDataSection->contentLayout()->addWidget(liveDataLoggingButton);
logDataSection->contentLayout()->addWidget(dataLoggingBtn);
logDataSection->contentLayout()->addWidget(loadDataOverride);
logDataSection->contentLayout()->addWidget(dataLoadingBtn);

logDataContainer->contentLayout()->addWidget(logDataSection);
Expand All @@ -106,6 +104,8 @@ void DataLoggingMenu::updateDataLoggingStatus(ProgressBarState status)

bool DataLoggingMenu::liveDataLogging() const { return m_liveDataLogging; }

bool DataLoggingMenu::isLoadDataOverrideOn() { return loadDataOverride->isChecked(); }

void DataLoggingMenu::chooseFile()
{
QString selectedFilter;
Expand All @@ -114,3 +114,11 @@ void DataLoggingMenu::chooseFile()
QFileDialog::Options(QFileDialog::DontUseNativeDialog));
dataLoggingFilePath->getLineEdit()->setText(filename);
}

void DataLoggingMenu::toggleButtonsEnabled(bool en)
{
dataLoggingBtn->setEnabled(en);
dataLoadingBtn->setEnabled(en);
liveDataLoggingButton->setEnabled(en);
loadDataOverride->setEnabled(en);
}
Loading

0 comments on commit 31f44e7

Please sign in to comment.