Skip to content

Commit

Permalink
plugins/dac: add dds mode widgets for all separate modes.
Browse files Browse the repository at this point in the history
Signed-off-by: AlexandraTrifan <Alexandra.Trifan@analog.com>
  • Loading branch information
AlexandraTrifan committed Jun 28, 2024
1 parent 3791b97 commit 82c419f
Show file tree
Hide file tree
Showing 6 changed files with 430 additions and 100 deletions.
221 changes: 121 additions & 100 deletions plugins/dac/src/ddsdacaddon.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ddsdacaddon.h"
#include "dacdatamodel.h"
#include "txnode.h"
#include "txchannel.h"

#include <gui/widgets/menucontrolbutton.h>
#include <gui/widgets/menucombo.h>
Expand Down Expand Up @@ -29,6 +30,7 @@ DdsDacAddon::DdsDacAddon(DacDataModel *model, QWidget *parent)
QVBoxLayout *txsContainerLayout = new QVBoxLayout(this);
txsContainerLayout->setMargin(0);
txsContainerLayout->setSpacing(10);
txsContainerLayout->setContentsMargins(0, 0, 10, 0);
txsContainer->setLayout(txsContainerLayout);

QScrollArea *scrollArea = new QScrollArea(this);
Expand All @@ -38,113 +40,132 @@ DdsDacAddon::DdsDacAddon(DacDataModel *model, QWidget *parent)

for (int i = 0; i < model->getDdsTxs().size(); i++) {
TxNode *txNode = model->getDdsTxs().value(model->getDdsTxs().keys().at(i));
QWidget *tx = new QWidget(this);
// StyleHelper::BackgroundWidget(tx);
QVBoxLayout *txLay = new QVBoxLayout(this);
txLay->setMargin(10);
txLay->setSpacing(10);
txLay->setMargin(0);
txLay->setSpacing(10);
tx->setLayout(txLay);

MapStackedWidget *ddsModeStack = new MapStackedWidget(this);
QWidget *txChns = new QWidget(this);
QHBoxLayout *txChnsLay = new QHBoxLayout(this);
txChnsLay->setContentsMargins(0, 0, 10, 0);
txChnsLay->setSpacing(10);
txChns->setLayout(txChnsLay);
StyleHelper::BackgroundWidget(txChns);

ddsModeStack->add("0", txChns);

auto txNodeChildren = txNode->getTones();
int key = 0;

for (TxNode *nodeChildren : txNodeChildren) {
QWidget *chnIQ = new QWidget(this);
QVBoxLayout *chnIqLay = new QVBoxLayout(this);
chnIqLay->setMargin(10);
chnIqLay->setSpacing(10);
chnIQ->setLayout(chnIqLay);
QLabel *chnIqLbl = new QLabel(this);
chnIqLbl->setText("Channel " + nodeChildren->getUuid());

QWidget *toneList = new QWidget(this);
QHBoxLayout *toneListLay = new QHBoxLayout(this);
toneListLay->setMargin(0);
toneListLay->setSpacing(10);
toneList->setLayout(toneListLay);
chnIqLay->addWidget(chnIqLbl);
chnIqLay->addWidget(toneList);

for (int j = 0; j < nodeChildren->getTones().size(); j++){
TxNode *nodeTone = nodeChildren->getTones().value(nodeChildren->getTones().keys().at(j));
QWidget *tone = new QWidget(this);
QVBoxLayout *toneLay = new QVBoxLayout(this);
toneLay->setMargin(0);
toneLay->setSpacing(10);
tone->setLayout(toneLay);

auto frequency = IIOWidgetBuilder()
.channel(nodeTone->getChannel())
.attribute("frequency").uiStrategy(IIOWidgetBuilder::UIS::EditableUi)
.parent(this).buildSingle();

auto scale = IIOWidgetBuilder()
.channel(nodeTone->getChannel())
.attribute("scale").uiStrategy(IIOWidgetBuilder::UIS::EditableUi)
.parent(this).buildSingle();

auto phase = IIOWidgetBuilder()
.channel(nodeTone->getChannel())
.attribute("phase").uiStrategy(IIOWidgetBuilder::UIS::EditableUi)
.parent(this).buildSingle();
toneLay->addWidget(frequency);
toneLay->addWidget(scale);
toneLay->addWidget(phase);
toneListLay->addWidget(tone);
}
txChnsLay->addWidget(chnIQ);
}

QWidget *txHeader = new QWidget(this);
QHBoxLayout *txHeaderLay = new QHBoxLayout(this);
txHeaderLay->setMargin(0);
txHeaderLay->setSpacing(10);
txHeader->setLayout(txHeaderLay);

MenuControlButton *txBtn = new MenuControlButton(this);
txBtn->setName(txNode->getUuid());
txBtn->setOpenMenuChecksThis(true);
txBtn->setDoubleClickToOpenMenu(true);
txBtn->checkBox()->setVisible(false);
txBtn->button()->setVisible(true);

MenuCombo *combo = new MenuCombo("DDS MODE", this);
StyleHelper::IIOComboBox(combo->combo());
auto cb = combo->combo();
combo->combo()->addItem("Disabled", 0);
combo->combo()->addItem("One CW Tone", 1);
combo->combo()->addItem("Two CW Tones", 2);
combo->combo()->addItem("Independent I/Q Control", 3);
connect(cb, qOverload<int>(&QComboBox::currentIndexChanged), this, [=](int idx) {
auto mode = cb->itemData(idx).toInt();
ddsModeStack->show(QString::number(mode));
});

txHeaderLay->addWidget(txBtn);
txHeaderLay->addWidget(combo);

txLay->addWidget(txHeader);
txLay->addWidget(ddsModeStack);

QWidget *tx = setupDdsTx(txNode);
txsContainerLayout->addWidget(tx);
}
QSpacerItem *spacer = new QSpacerItem(10, 10, QSizePolicy::Preferred, QSizePolicy::Expanding);
txsContainerLayout->addItem(spacer);
}

QWidget *DdsDacAddon::setupDdsTx(TxNode *txNode)
{
QWidget *tx = new QWidget(this);
QVBoxLayout *txLay = new QVBoxLayout(this);
txLay->setMargin(0);
txLay->setSpacing(5);
tx->setLayout(txLay);

MapStackedWidget *ddsModeStack = new MapStackedWidget(this);
ddsModeStack->add(QString::number(TxMode::DISABLED), setupTxMode(txNode, TxMode::DISABLED));
ddsModeStack->add(QString::number(TxMode::ONE_TONE), setupTxMode(txNode, TxMode::ONE_TONE));
ddsModeStack->add(QString::number(TxMode::TWO_TONES), setupTxMode(txNode, TxMode::TWO_TONES));
ddsModeStack->add(QString::number(TxMode::INDEPENDENT_IQ_CTRL), setupTxMode(txNode, TxMode::INDEPENDENT_IQ_CTRL));

QWidget *txHeader = new QWidget(this);
QHBoxLayout *txHeaderLay = new QHBoxLayout(this);
txHeaderLay->setMargin(0);
txHeaderLay->setSpacing(10);
txHeader->setLayout(txHeaderLay);

MenuControlButton *txBtn = new MenuControlButton(this);
txBtn->setName(txNode->getUuid());
txBtn->setOpenMenuChecksThis(true);
txBtn->setDoubleClickToOpenMenu(true);
txBtn->checkBox()->setVisible(false);
txBtn->button()->setVisible(true);

MenuCombo *combo = new MenuCombo("DDS MODE", this);
StyleHelper::IIOComboBox(combo->combo());
StyleHelper::BackgroundWidget(combo);
auto cb = combo->combo();
combo->combo()->addItem("Disabled", TxMode::DISABLED);
combo->combo()->addItem("One CW Tone", TxMode::ONE_TONE);
combo->combo()->addItem("Two CW Tones", TxMode::TWO_TONES);
combo->combo()->addItem("Independent I/Q Control", TxMode::INDEPENDENT_IQ_CTRL);
connect(cb, qOverload<int>(&QComboBox::currentIndexChanged), this, [=](int idx) {
auto mode = cb->itemData(idx).toInt();
TxMode *current = dynamic_cast<TxMode*>(ddsModeStack->get(QString::number(mode)));
if (current) {
current->read();
}
ddsModeStack->show(QString::number(mode));
});

txHeaderLay->addWidget(txBtn);
txHeaderLay->addWidget(combo);

txLay->addWidget(txHeader);
txLay->addWidget(ddsModeStack);

return tx;

}

QWidget *DdsDacAddon::setupTxMode(TxNode *txNode, unsigned int mode)
{
TxMode *txModeWidget = new TxMode(txNode, mode, this);
return txModeWidget;
// m_txModes.append(txModeWidget);
}

DdsDacAddon::~DdsDacAddon()
{

}

TxMode::TxMode(TxNode *node, unsigned int mode, QWidget *parent)
: QWidget(parent)
, m_mode(mode)
, m_node(node)
{
// return new QWidget(this);
QVBoxLayout *txChnsLay = new QVBoxLayout(this);
txChnsLay->setSpacing(10);
this->setLayout(txChnsLay);
StyleHelper::BackgroundWidget(this);
if (mode != DISABLED) {
auto txNodeChildren = m_node->getTones();
for (TxNode *child : txNodeChildren) {
TxChannel *txChn = new TxChannel(child, mode, this);
m_txChannels.append(txChn);
txChnsLay->addWidget(txChn);
}

// if (txChannels.size() == 0) {
// return nullptr;
// TBD handle nullwidget or set to disabled?
// }

auto emitterChannel = m_txChannels.at(0);
switch (mode) {
case ONE_TONE:
for (int i = 1; i < m_txChannels.size(); i++) {
m_txChannels.at(i)->setVisible(false);
}
case TWO_TONES:
for (int i = 1; i < m_txChannels.size(); i++) {
connect(emitterChannel, &TxChannel::frequencyUpdated,
m_txChannels[i], &TxChannel::updateFrequency);
connect(emitterChannel, &TxChannel::phaseUpdated,
m_txChannels[i], &TxChannel::updatePhase);
connect(emitterChannel, &TxChannel::scaleUpdated,
m_txChannels[i], &TxChannel::updateScale);
}
break;
default:
break;
}
}
}

TxMode::~TxMode()
{

}

void TxMode::read()
{
for (TxChannel* chn : m_txChannels) {
chn->read();
}
}
28 changes: 28 additions & 0 deletions plugins/dac/src/ddsdacaddon.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace scopy {
class DacDataModel;
class TxNode;
class TxChannel;
class DdsDacAddon : public DacAddon
{
Q_OBJECT
Expand All @@ -15,6 +17,32 @@ class DdsDacAddon : public DacAddon

private:
DacDataModel *m_model;
QWidget *setupDdsTx(TxNode *txNode);
// QWidget *setupTxChannel(TxNode *node, unsigned int mode);
// TxTone *setupTxTone(TxNode *nodeTone, unsigned int index);
QWidget *setupTxMode(TxNode *txNode, unsigned int mode);
};

class TxMode : public QWidget
{
Q_OBJECT
public:
TxMode(TxNode *node, unsigned int mode, QWidget *parent = nullptr);
virtual ~TxMode();

typedef enum
{
DISABLED,
ONE_TONE,
TWO_TONES,
INDEPENDENT_IQ_CTRL
} DdsMode;

void read();
private:
TxNode *m_node;
unsigned int m_mode;
QList<TxChannel*> m_txChannels;
};
} // namespace scopy

Expand Down
87 changes: 87 additions & 0 deletions plugins/dac/src/txchannel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include "txchannel.h"
#include "txtone.h"
#include "txnode.h"

using namespace scopy;

TxChannel::TxChannel(TxNode *node, unsigned int nbTonesMode, QWidget *parent)
: QWidget(parent)
, m_node(node)
, m_linkTones(false)
{
// txChnWidget = new QWidget(this);
QVBoxLayout *chnIqLay = new QVBoxLayout(this);
chnIqLay->setMargin(10);
chnIqLay->setSpacing(10);
this->setLayout(chnIqLay);

auto children = m_node->getTones();
bool isTone = (children.size() == 0);
QWidget *txChnWidget = nullptr;
if (!isTone) {
unsigned int i = 1;
QLabel *chnIqLbl = new QLabel(this);
chnIqLbl->setText("Channel " + node->getUuid());
StyleHelper::MenuComboLabel(chnIqLbl);

QWidget *toneList = new QWidget(this);
QHBoxLayout *toneListLay = new QHBoxLayout(this);
toneListLay->setMargin(0);
toneListLay->setSpacing(10);
toneList->setLayout(toneListLay);
chnIqLay->addWidget(chnIqLbl);
chnIqLay->addWidget(toneList);

for (TxNode *nodeTone : children) {
QWidget *tone = setupTxTone(nodeTone, i);
if (i == nbTonesMode) {
break;
}
i++;
}
} else {
txChnWidget = setupTxTone(node, 1);
// toneListLay->addWidget(tone);
}
}

TxChannel::~TxChannel()
{

}

void TxChannel::updateFrequency(int toneIdx, QString frequency)
{
m_tones.at(toneIdx)->updateFrequency(frequency);
}

void TxChannel::updatePhase(int toneIdx, QString phase)
{
m_tones.at(toneIdx)->updatePhase(phase);
}

void TxChannel::updateScale(int toneIdx, QString scale)
{
m_tones.at(toneIdx)->updateScale(scale);
}

TxTone *TxChannel::setupTxTone(TxNode *nodeTone, unsigned int index)
{
TxTone *tone = new TxTone(nodeTone, index, this);
// if (m_linkTones) {
connect(tone, &TxTone::frequencyUpdated, this, &TxChannel::frequencyUpdated);
connect(tone, &TxTone::scaleUpdated, this, &TxChannel::scaleUpdated);
connect(tone, &TxTone::phaseUpdated, this, &TxChannel::phaseUpdated);
// }
m_tones.append(tone);
this->layout()->addWidget(tone);
return tone;
}

void TxChannel::read()
{
for (TxTone* tone : m_tones) {
tone->read();
}
}

Loading

0 comments on commit 82c419f

Please sign in to comment.