-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugins/dac/bufferdacaddon: initial version + read strategy for file
Signed-off-by: AlexandraTrifan <Alexandra.Trifan@analog.com>
- Loading branch information
1 parent
4926651
commit 9ee73b4
Showing
17 changed files
with
725 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,173 @@ | ||
#include "bufferdacaddon.h" | ||
#include "dacdatamodel.h" | ||
#include "txnode.h" | ||
#include "databufferbuilder.h" | ||
#include "databuffer.h" | ||
#include "filebrowser.h" | ||
#include "dac_logging_categories.h" | ||
|
||
#include <menusectionwidget.h> | ||
#include <menucollapsesection.h> | ||
#include <progresslineedit.h> | ||
#include <titlespinbox.h> | ||
#include <menulineedit.h> | ||
#include <menuonoffswitch.h> | ||
#include <menucontrolbutton.h> | ||
|
||
#include <QHBoxLayout> | ||
#include <QLabel> | ||
#include <QFileDialog> | ||
#include <QString> | ||
|
||
using namespace scopy; | ||
BufferDacAddon::BufferDacAddon(DacDataModel *model, QWidget *parent) | ||
: DacAddon("blue", parent) | ||
: DacAddon(parent) | ||
, m_model(model) | ||
, m_dataBuffer(nullptr) | ||
{ | ||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | ||
auto m_layout = new QHBoxLayout(this); | ||
auto m_layout = new QVBoxLayout(); | ||
m_layout->setMargin(0); | ||
m_layout->setSpacing(10); | ||
setLayout(m_layout); | ||
|
||
QLabel *name = new QLabel("BUFFER DAC ADDON", this); | ||
m_layout->addWidget(name); | ||
QWidget *bufferConfigContainer = new QWidget(this); | ||
auto bufferConfigLay = new QHBoxLayout(); | ||
bufferConfigLay->setMargin(0); | ||
bufferConfigLay->setSpacing(10); | ||
bufferConfigContainer->setLayout(bufferConfigLay); | ||
|
||
MenuSectionWidget *scaleContainer = new MenuSectionWidget(this); | ||
TitleSpinBox *scaleSpin = new TitleSpinBox("Scale (DBFS)", this); | ||
StyleHelper::BackgroundWidget(scaleSpin); | ||
scaleContainer->contentLayout()->addWidget(scaleSpin); | ||
|
||
MenuSectionWidget *buffersizeContainer = new MenuSectionWidget(this); | ||
QLabel *buffersizeLbl = new QLabel("Buffersize"); | ||
MenuLineEdit *buffersizeEdit = new MenuLineEdit(this); | ||
StyleHelper::MenuSmallLabel(buffersizeLbl); | ||
StyleHelper::MenuLineEditWidget(buffersizeEdit); | ||
buffersizeContainer->contentLayout()->addWidget(buffersizeLbl); | ||
buffersizeContainer->contentLayout()->addWidget(buffersizeEdit); | ||
|
||
MenuSectionWidget *cyclicContainer = new MenuSectionWidget(this); | ||
MenuOnOffSwitch *cyclicBtn = new MenuOnOffSwitch("Cyclic", this); | ||
cyclicContainer->contentLayout()->addWidget(cyclicBtn); | ||
|
||
m_runBtn = new RunBtn(this); | ||
connect(m_runBtn, &QPushButton::toggled, this, &BufferDacAddon::runBtnToggled); | ||
|
||
bufferConfigLay->addWidget(scaleContainer); | ||
bufferConfigLay->addWidget(buffersizeContainer); | ||
bufferConfigLay->addWidget(cyclicContainer); | ||
bufferConfigLay->addWidget(m_runBtn); | ||
|
||
FileBrowser *fm = new FileBrowser(this); | ||
connect(fm, &FileBrowser::load, this, &BufferDacAddon::load); | ||
|
||
MenuSectionWidget *channelsSection = new MenuSectionWidget(this); | ||
// channelsSection->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); | ||
QLabel *channelsLbl = new QLabel("Channels"); | ||
StyleHelper::MenuSmallLabel(channelsLbl); | ||
|
||
QString color; | ||
if (color == "") { | ||
// is disabled | ||
name->setText("DISABLED"); | ||
color = "grey"; | ||
QWidget *channelsContainer = new QWidget(this); | ||
channelsContainer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); | ||
QVBoxLayout *channelsContainerLayout = new QVBoxLayout(); | ||
channelsContainerLayout->setMargin(0); | ||
channelsContainerLayout->setSpacing(0); | ||
channelsContainer->setLayout(channelsContainerLayout); | ||
|
||
QScrollArea *scrollArea = new QScrollArea(channelsSection); | ||
// scrollArea->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | ||
scrollArea->setWidgetResizable(true); | ||
scrollArea->setWidget(channelsContainer); | ||
|
||
channelsSection->contentLayout()->addWidget(channelsLbl); | ||
channelsSection->contentLayout()->addWidget(scrollArea); | ||
|
||
int i = 0; | ||
auto lst = m_model->getBufferTxs(); | ||
for (TxNode *node : lst) { | ||
MenuControlButton *chnBtn = new MenuControlButton(this); | ||
chnBtn->setName(node->getUuid()); | ||
chnBtn->setCheckBoxStyle(MenuControlButton::CS_CIRCLE); | ||
chnBtn->setColor(StyleHelper::getColor("CH" + QString::number(i))); | ||
chnBtn->setDoubleClickToOpenMenu(true); | ||
chnBtn->setOpenMenuChecksThis(true); | ||
chnBtn->setCheckable(true); | ||
chnBtn->setChecked(false); | ||
channelsContainerLayout->addWidget(chnBtn); | ||
i++; | ||
} | ||
for (TxNode *node : lst) { | ||
MenuControlButton *chnBtn = new MenuControlButton(this); | ||
chnBtn->setName(node->getUuid()); | ||
chnBtn->setCheckBoxStyle(MenuControlButton::CS_CIRCLE); | ||
chnBtn->setColor(StyleHelper::getColor("CH" + QString::number(i))); | ||
chnBtn->setDoubleClickToOpenMenu(true); | ||
chnBtn->setOpenMenuChecksThis(true); | ||
chnBtn->setCheckable(true); | ||
chnBtn->setChecked(false); | ||
channelsContainerLayout->addWidget(chnBtn); | ||
i++; | ||
} | ||
|
||
|
||
setStyleSheet("background-color:" + color); | ||
QWidget *topSection = new QWidget(this); | ||
auto topLayout = new QHBoxLayout(); | ||
topSection->setLayout(topLayout); | ||
topSection->setFixedHeight(190); | ||
topLayout->setMargin(0); | ||
topLayout->setSpacing(10); | ||
topLayout->addWidget(fm, 3); | ||
topLayout->addWidget(channelsSection, 2); | ||
|
||
m_layout->addWidget(topSection); | ||
m_layout->addWidget(bufferConfigContainer); | ||
} | ||
|
||
BufferDacAddon::~BufferDacAddon() | ||
{ | ||
|
||
} | ||
|
||
void BufferDacAddon::load(QString path) | ||
{ | ||
if (m_dataBuffer) { | ||
// handle deletion and cleanup | ||
delete m_dataBuffer; | ||
} | ||
m_dataBuffer = DataBufferBuilder() | ||
.dataStrategy(DataBufferBuilder::FileStrategy) | ||
.file(path).ui(true).parent(this).build(); | ||
|
||
|
||
// test | ||
loadData(); | ||
} | ||
|
||
void BufferDacAddon::enable(bool enable) | ||
{ | ||
m_model->enableBuffer(enable); | ||
} | ||
|
||
void BufferDacAddon::chooseFile() | ||
{ | ||
QString selectedFilter; | ||
m_filename = QFileDialog::getSaveFileName( | ||
this, tr("Export"), "", tr("Comma-separated values files (*.csv);;All Files(*)"), &selectedFilter, | ||
QFileDialog::Options(QFileDialog::DontUseNativeDialog)); | ||
m_fileBufferPath->getLineEdit()->setText(m_filename); | ||
} | ||
|
||
void BufferDacAddon::runBtnToggled(bool toggled) | ||
{ | ||
// data buffer already configured buffersize and other stuff | ||
m_model->push(m_dataBuffer->getDataBufferStrategy()->data()); | ||
} | ||
|
||
void BufferDacAddon::loadData() | ||
{ | ||
qDebug(CAT_DAC_BUFFER) << m_dataBuffer->getDataBufferStrategy()->data()[0]; | ||
} | ||
|
||
//void BufferDacAddon::setupFileSection() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "csvfilestrategy.h" | ||
#include "dac_logging_categories.h" | ||
|
||
#include <QString> | ||
#include <QVector> | ||
#include <QFile> | ||
|
||
using namespace scopy; | ||
CSVFileStrategy::CSVFileStrategy(QString filename, QWidget *parent) | ||
: QWidget(parent) | ||
{ | ||
m_filename = filename; | ||
m_separator = ","; | ||
loadFile(); | ||
// tbd thread? | ||
} | ||
|
||
QVector<QVector<double>> CSVFileStrategy::data() | ||
{ | ||
return m_data; | ||
} | ||
|
||
void CSVFileStrategy::loadFile() | ||
{ | ||
QVector<QVector<QString>> raw_data; | ||
bool dataOk = true; | ||
QFile file(m_filename); | ||
if(!file.open(QIODevice::ReadOnly)) { | ||
qDebug(CAT_DAC_DATASTRATEGY) << "Can't open selected file"; | ||
return; | ||
} | ||
|
||
QTextStream in(&file); | ||
|
||
while(!in.atEnd()) { | ||
QVector<QString> line_data; | ||
QString line = in.readLine(); | ||
if (line.isEmpty()) { | ||
continue; | ||
} | ||
QStringList list = line.split(m_separator, Qt::SkipEmptyParts); | ||
for(const QString &list_item : qAsConst(list)) { | ||
line_data.push_back(list_item); | ||
} | ||
if(line_data.size() > 0) { | ||
raw_data.push_back(line_data); | ||
} | ||
} | ||
|
||
// suppose no m_data in the file | ||
m_data.resize(raw_data.size()); | ||
for(int i = 0; i < m_data.size(); ++i) { | ||
m_data[i].resize(raw_data[i].size()); | ||
} | ||
|
||
for(int i = 0; i < raw_data.size(); ++i) { | ||
for(int j = 0; j < raw_data[i].size(); ++j) { | ||
m_data[i][j] = raw_data[i][j].toDouble(&dataOk); | ||
if(!dataOk) { | ||
qDebug(CAT_DAC_DATASTRATEGY) << "File is corrupted"; | ||
return; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef CSVFILESTRATEGY_H | ||
#define CSVFILESTRATEGY_H | ||
|
||
#include <QWidget> | ||
#include "databufferstrategyinterface.h" | ||
#include "scopy-dac_export.h" | ||
|
||
namespace scopy { | ||
class SCOPY_DAC_EXPORT CSVFileStrategy : public QWidget, public DataBufferStrategyInterface | ||
{ | ||
Q_OBJECT | ||
Q_INTERFACES(scopy::DataBufferStrategyInterface) | ||
public: | ||
explicit CSVFileStrategy(QString filename, QWidget *parent = nullptr); | ||
|
||
QVector<QVector<double>> data() override; | ||
|
||
Q_SIGNALS: | ||
void loadFinished(); | ||
|
||
private: | ||
QString m_filename; | ||
QString m_separator; | ||
QVector<QVector<double>> m_data; | ||
void loadFile(); | ||
}; | ||
} //namespace scopy | ||
#endif // CSVFILESTRATEGY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.