27 , buttonGroup(new QGroupBox)
28 , inputBlock(new QComboBox)
29 , inputChannel(new QComboBox)
30 , outputBlock(new QComboBox)
31 , outputFlag(new QComboBox)
32 , outputChannel(new QComboBox)
33 , connectionBox(new QListWidget)
36 "<p><b>Connector:</b><br>The Connector panel allows you to make " 37 "connections between " 38 "signals and slots in your workspace. Signals are generated by the DAQ " 40 "with input channels) and by user modules. Available signals are listed " 42 "Block\" drop-down box and available slots are listed in the \"Input " 43 "Block\" drop-down box. " 44 "The arrow button is a toggle button that turns connections on and off. " 45 "Clicking the toggle " 46 "button immediately makes a connection active or inactive in real-time. " 47 "Current connections " 48 "are listed in the \"Connections\" box.</p>");
51 auto* layout =
new QGridLayout;
54 outputGroup =
new QGroupBox(tr(
"Source"));
55 auto* outputLayout =
new QVBoxLayout;
58 outputLayout->addWidget(
new QLabel(tr(
"Block:")), 1, Qt::Alignment());
59 outputLayout->addWidget(outputBlock);
60 outputLayout->addWidget(
new QLabel(tr(
"Flag:")), 2, Qt::Alignment());
61 outputLayout->addWidget(outputFlag);
62 buildOutputFlagList();
64 QObject::connect(outputBlock,
65 SIGNAL(activated(
int)),
67 SLOT(buildOutputChannelList(
void)));
68 QObject::connect(outputBlock,
69 SIGNAL(activated(
int)),
71 SLOT(updateConnectionButton(
void)));
72 QObject::connect(outputFlag,
73 SIGNAL(activated(
int)),
75 SLOT(buildOutputChannelList(
void)));
76 QObject::connect(outputFlag,
77 SIGNAL(activated(
int)),
79 SLOT(updateConnectionButton(
void)));
81 outputLayout->addWidget(
new QLabel(tr(
"Channel:")), 3, Qt::Alignment());
82 outputLayout->addWidget(outputChannel);
83 QObject::connect(outputChannel,
84 SIGNAL(activated(
int)),
86 SLOT(updateConnectionButton(
void)));
89 outputGroup->setLayout(outputLayout);
92 auto* buttonLayout =
new QVBoxLayout;
95 connectionButton =
new QPushButton(
"Connect");
96 connectionButton->setCheckable(
true);
97 buttonLayout->addWidget(connectionButton);
98 QObject::connect(connectionButton,
99 SIGNAL(clicked(
bool)),
101 SLOT(toggleConnection(
bool)));
104 buttonGroup->setLayout(buttonLayout);
107 inputGroup =
new QGroupBox(tr(
"Destination"));
108 auto* inputLayout =
new QVBoxLayout;
111 inputLayout->addWidget(
new QLabel(tr(
"Block:")), 1, Qt::Alignment());
112 inputLayout->addWidget(inputBlock);
113 QObject::connect(inputBlock,
114 SIGNAL(activated(
int)),
116 SLOT(buildInputChannelList(
void)));
117 QObject::connect(inputBlock,
118 SIGNAL(activated(
int)),
120 SLOT(updateConnectionButton(
void)));
122 inputLayout->addWidget(
new QLabel(tr(
"Channel:")), 2, Qt::Alignment());
123 inputLayout->addWidget(inputChannel);
124 QObject::connect(inputChannel,
125 SIGNAL(activated(
int)),
127 SLOT(updateConnectionButton(
void)));
130 inputGroup->setLayout(inputLayout);
133 connectionGroup =
new QGroupBox(tr(
"Connections"));
134 auto* connectionLayout =
new QVBoxLayout;
137 connectionLayout->addWidget(connectionBox);
144 connectionGroup->setLayout(connectionLayout);
147 layout->addWidget(outputGroup, 1, 0, 1, 2);
148 layout->addWidget(buttonGroup, 2, 0, 1, 4);
149 layout->addWidget(inputGroup, 1, 2, 1, 2);
150 layout->addWidget(connectionGroup, 3, 0, 1, 4);
153 layout->setRowStretch(0, 0);
154 layout->setRowStretch(2, 0);
155 layout->setRowStretch(3, 1);
159 setWindowTitle(QString(this->
getName().c_str()));
162 this->
getMdiWindow()->resize(500, this->sizeHint().height());
165 this->syncBlockInfo();
171 QObject::connect(inputBlock,
172 SIGNAL(currentTextChanged(
const QString&)),
174 SLOT(highlightConnectionBox(
const QString&)));
175 QObject::connect(outputBlock,
176 SIGNAL(currentTextChanged(
const QString&)),
178 SLOT(highlightConnectionBox(
const QString&)));
179 QObject::connect(inputChannel,
180 SIGNAL(currentTextChanged(
const QString&)),
182 SLOT(highlightConnectionBox(
const QString&)));
183 QObject::connect(outputChannel,
184 SIGNAL(currentTextChanged(
const QString&)),
186 SLOT(highlightConnectionBox(
const QString&)));
187 QObject::connect(outputFlag,
188 SIGNAL(currentTextChanged(
const QString&)),
190 SLOT(highlightConnectionBox(
const QString&)));
193 void Connector::Panel::buildBlockList()
195 auto prev_input_block = inputBlock->currentData();
196 auto prev_output_block = outputBlock->currentData();
198 outputBlock->clear();
200 this->getRTXIEventManager()->postEvent(&event);
202 std::any_cast<std::vector<IO::Block*>>(
event.getParam(
"blockList"));
203 for (
auto* block : this->blocks) {
204 if (block->getName().find(
"Probe") != std::string::npos
205 || block->getName().find(
"Recording") != std::string::npos)
209 this->inputBlock->addItem(QString(block->getName().c_str()) +
" " 210 + QString::number(block->getID()),
211 QVariant::fromValue(block));
212 this->outputBlock->addItem(QString(block->getName().c_str()) +
" " 213 + QString::number(block->getID()),
214 QVariant::fromValue(block));
216 inputBlock->setCurrentIndex(inputBlock->findData(prev_input_block));
217 outputBlock->setCurrentIndex(outputBlock->findData(prev_output_block));
220 void Connector::Panel::buildConnectionList()
223 this->getRTXIEventManager()->postEvent(&event);
224 this->links = std::any_cast<std::vector<RT::block_connection_t>>(
225 event.getParam(
"connections"));
237 this->updatePanelInfo();
244 void Connector::Plugin::updatePanelInfo()
251 void Connector::Panel::syncBlockInfo()
253 this->buildBlockList();
254 this->buildInputChannelList();
255 this->buildOutputChannelList();
256 this->buildConnectionList();
258 connectionBox->clear();
259 QString temp_list_text;
260 QListWidgetItem* temp_list_item =
nullptr;
261 for (
auto conn : this->links) {
262 if (conn.dest->getName().find(
"Probe") != std::string::npos) {
266 QString::number(conn.src->getID()) +
" " 267 + QString(conn.src->getName().c_str()) +
" " 269 conn.src->getChannelName(conn.src_port_type, conn.src_port).c_str())
270 +
" ==> " + QString::number(conn.dest->getID()) +
" " 271 + QString(conn.dest->getName().c_str()) +
" " 272 + QString(conn.dest->getChannelName(
IO::INPUT, conn.dest_port).c_str());
273 temp_list_item =
new QListWidgetItem(temp_list_text);
274 temp_list_item->setData(Qt::UserRole, QVariant::fromValue(conn));
275 connectionBox->addItem(temp_list_item);
279 void Connector::Panel::buildInputChannelList()
281 auto prev_channel = inputChannel->currentData();
282 inputChannel->clear();
283 if (inputBlock->count() == 0) {
288 if (!inputBlock->currentData().isValid()) {
291 auto* block = inputBlock->currentData().value<
IO::Block*>();
294 for (
size_t i = 0; i < block->getCount(
IO::INPUT); ++i) {
295 inputChannel->addItem(QString(block->getChannelName(
IO::INPUT, i).c_str()),
296 QVariant::fromValue(i));
298 inputChannel->setCurrentIndex(inputChannel->findData(prev_channel));
299 updateConnectionButton();
302 void Connector::Panel::buildOutputChannelList()
304 auto prev_channel = outputChannel->currentData();
305 outputChannel->clear();
306 if (outputBlock->count() == 0) {
311 if (!outputBlock->currentData().isValid()
312 || !outputFlag->currentData().isValid())
316 auto* block = outputBlock->currentData().value<
IO::Block*>();
317 auto direction = outputFlag->currentData().value<
IO::flags_t>();
320 for (
size_t i = 0; i < block->getCount(direction); ++i) {
321 outputChannel->addItem(QString(block->getChannelName(direction, i).c_str()),
322 QVariant::fromValue(i));
324 outputChannel->setCurrentIndex(outputChannel->findData(prev_channel));
325 updateConnectionButton();
328 void Connector::Panel::buildOutputFlagList()
330 outputFlag->addItem(QString(
"OUTPUT"), QVariant::fromValue(
IO::OUTPUT));
331 outputFlag->addItem(QString(
"INPUT"), QVariant::fromValue(
IO::INPUT));
334 void Connector::Panel::highlightConnectionBox(
const QString& )
337 const QVariant src_variant = this->outputBlock->currentData();
338 const QVariant src_type_variant = this->outputFlag->currentData();
339 const QVariant src_chan_variant = this->outputChannel->currentData();
340 const QVariant dest_variant = this->inputBlock->currentData();
341 const QVariant dest_chan_variant = this->inputChannel->currentData();
342 if (!src_variant.isValid() || !src_type_variant.isValid()
343 || !dest_variant.isValid() || !src_chan_variant.isValid()
344 || !dest_chan_variant.isValid())
346 connectionBox->setCurrentRow(-1);
351 current_connection.
src = src_variant.value<
IO::Block*>();
353 current_connection.
src_port = src_chan_variant.value<
size_t>();
355 current_connection.
dest_port = dest_chan_variant.value<
size_t>();
356 QVariant temp_conn_variant;
358 for (
int row = 0; row < connectionBox->count(); ++row) {
359 temp_conn_variant = this->connectionBox->item(row)->data(Qt::UserRole);
362 connectionBox->setCurrentRow(row);
366 connectionBox->setCurrentRow(-1);
369 void Connector::Panel::reverseHighlightConnectionBox(
370 const QListWidgetItem* item)
372 const auto connection =
374 outputBlock->setCurrentIndex(
375 outputBlock->findData(QVariant::fromValue(connection.src)));
376 outputFlag->setCurrentIndex(
377 outputFlag->findData(QVariant::fromValue(connection.src_port_type)));
378 outputChannel->setCurrentIndex(
379 outputChannel->findData(QVariant::fromValue(connection.src_port)));
380 inputBlock->setCurrentIndex(
381 inputBlock->findData(QVariant::fromValue(connection.dest)));
382 inputChannel->setCurrentIndex(
383 inputChannel->findData(QVariant::fromValue(connection.dest_port)));
384 updateConnectionButton();
387 void Connector::Panel::toggleConnection(
bool down)
390 const QVariant src_block = outputBlock->currentData();
391 const QVariant src_type = outputFlag->currentData();
392 const QVariant src_port = outputChannel->currentData();
393 const QVariant dest_block = inputBlock->currentData();
394 const QVariant dest_port = inputChannel->currentData();
395 if (!src_block.isValid() || !src_type.isValid() || !src_port.isValid()
396 || !dest_block.isValid() || !dest_port.isValid())
398 connectionButton->setDown(
false);
401 connectionButton->setEnabled(
false);
406 connection.
src_port = src_port.value<
size_t>();
408 connection.
dest_port = dest_port.value<
size_t>();
412 event.setParam(
"connection", std::any(connection));
413 this->getRTXIEventManager()->postEvent(&event);
416 event.setParam(
"connection", std::any(connection));
417 this->getRTXIEventManager()->postEvent(&event);
419 connectionButton->setDown(down);
420 connectionButton->setChecked(down);
424 void Connector::Panel::updateConnectionButton()
426 if (inputChannel->count() == 0 || outputChannel->count() == 0) {
427 connectionButton->setEnabled(
false);
432 const QVariant src_block = outputBlock->currentData();
433 const QVariant src_type = outputFlag->currentData();
434 const QVariant src_port = outputChannel->currentData();
435 const QVariant dest_block = inputBlock->currentData();
436 const QVariant dest_port = inputChannel->currentData();
437 if (!src_block.isValid() || !src_type.isValid() || !src_port.isValid()
438 || !dest_block.isValid() || !dest_port.isValid())
440 connectionButton->setDown(
false);
441 connectionButton->setChecked(
false);
442 connectionButton->setEnabled(
false);
445 connectionButton->setEnabled(
true);
449 connection.
src_port = src_port.value<
size_t>();
451 connection.
dest_port = dest_port.value<
size_t>();
453 QListWidgetItem* temp_item =
nullptr;
454 for (
int i = 0; i < connectionBox->count(); i++) {
455 temp_item = connectionBox->item(i);
458 connectionButton->setDown(
true);
459 connectionButton->setChecked(
true);
463 connectionButton->setDown(
false);
464 connectionButton->setChecked(
false);
475 return std::make_unique<Connector::Plugin>(ev_manager);
Panel(QMainWindow *mw, Event::Manager *ev_manager)
void receiveEvent(Event::Object *event) override
Plugin(Event::Manager *ev_manager)
Event::Type getType() const
std::unique_ptr< Widgets::Component > createRTXIComponent(Widgets::Plugin *host_plugin)
constexpr std::string_view MODULE_NAME
std::unique_ptr< Widgets::Plugin > createRTXIPlugin(Event::Manager *ev_manager)
Widgets::Panel * createRTXIPanel(QMainWindow *main_window, Event::Manager *ev_manager)
Widgets::FactoryMethods getFactories()
@ IO_ALL_CONNECTIONS_QUERY_EVENT
IO::flags_t src_port_type