31 static void buildBlockList(
IO::Block *block,
void *arg)
36 info->
blocks->push_back(block);
43 "<p><b>Connector:</b><br>The Connector panel allows you to make connections between " 44 "signals and slots in your workspace. Signals are generated by the DAQ card (associated " 45 "with input channels) and by user modules. Available signals are listed in the \"Output " 46 "Block\" drop-down box and available slots are listed in the \"Input Block\" drop-down box. " 47 "The arrow button is a toggle button that turns connections on and off. Clicking the toggle " 48 "button immediately makes a connection active or inactive in real-time. Current connections " 49 "are listed in the \"Connections\" box.</p>");
52 subWindow =
new QMdiSubWindow;
53 subWindow->setWindowIcon(QIcon(
"/usr/local/share/rtxi/RTXI-widget-icon.png"));
54 subWindow->setAttribute(Qt::WA_DeleteOnClose);
55 subWindow->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint |
56 Qt::WindowMinimizeButtonHint);
60 QGridLayout *layout =
new QGridLayout;
63 outputGroup =
new QGroupBox(tr(
"Source"));
64 QVBoxLayout *outputLayout =
new QVBoxLayout;
67 outputLayout->addWidget(
new QLabel(tr(
"Block:")), 1, 0);
68 outputBlock =
new QComboBox;
69 outputLayout->addWidget(outputBlock);
70 QObject::connect(outputBlock,SIGNAL(activated(
int)),
this,SLOT(buildOutputChannelList(
void)));
72 outputLayout->addWidget(
new QLabel(tr(
"Channel:")), 2, 0);
73 outputChannel =
new QComboBox;
74 outputLayout->addWidget(outputChannel);
75 QObject::connect(outputChannel,SIGNAL(activated(
int)),
this,SLOT(updateConnectionButton(
void)));
78 outputGroup->setLayout(outputLayout);
81 buttonGroup =
new QGroupBox;
82 QVBoxLayout *buttonLayout =
new QVBoxLayout;
85 connectionButton =
new QPushButton(
"Connect");
86 connectionButton->setCheckable(
true);
87 buttonLayout->addWidget(connectionButton);
88 QObject::connect(connectionButton,SIGNAL(toggled(
bool)),
this,SLOT(toggleConnection(
bool)));
91 buttonGroup->setLayout(buttonLayout);
94 inputGroup =
new QGroupBox(tr(
"Destination"));
95 QVBoxLayout *inputLayout =
new QVBoxLayout;
98 inputLayout->addWidget(
new QLabel(tr(
"Block:")), 1, 0);
99 inputBlock =
new QComboBox;
100 inputLayout->addWidget(inputBlock);
101 QObject::connect(inputBlock,SIGNAL(activated(
int)),
this,SLOT(buildInputChannelList(
void)));
103 inputLayout->addWidget(
new QLabel(tr(
"Channel:")), 2, 0);
104 inputChannel =
new QComboBox;
105 inputLayout->addWidget(inputChannel);
106 QObject::connect(inputChannel,SIGNAL(activated(
int)),
this,SLOT(updateConnectionButton(
void)));
109 inputGroup->setLayout(inputLayout);
112 connectionGroup =
new QGroupBox(tr(
"Connections"));
113 QVBoxLayout *connectionLayout =
new QVBoxLayout;
116 connectionBox =
new QListWidget;
117 connectionLayout->addWidget(connectionBox);
118 QObject::connect(connectionBox,SIGNAL(itemClicked(QListWidgetItem *)),
this,SLOT(highlightConnectionBox(QListWidgetItem *)));
121 connectionGroup->setLayout(connectionLayout);
124 layout->addWidget(outputGroup, 1, 0, 1, 2);
125 layout->addWidget(buttonGroup, 2, 0, 1, 4);
126 layout->addWidget(inputGroup, 1, 2, 1, 2);
127 layout->addWidget(connectionGroup, 3, 0, 1, 4);
130 layout->setRowStretch(0, 0);
131 layout->setRowStretch(2, 0);
132 layout->setRowStretch(3, 1);
136 setWindowTitle(
"Connector Panel");
139 subWindow->setWidget(
this);
140 subWindow->resize(500, subWindow->sizeHint().height());
146 if(blocks.size() >= 1)
148 buildInputChannelList();
149 buildOutputChannelList();
153 for(
size_t i = 0, iend = links.size(); i < iend; ++i)
155 connectionBox->addItem(QString::number(links[i].src->getID())+
" "+QString::fromStdString(links[i].src->getName())+
" : "+QString::number(links[i].src_idx)+
" "+QString::fromStdString(links[i].src->getName(IO::OUTPUT,links[i].src_idx))+
" ==> "+
156 QString::number(links[i].dest->getID())+
" "+QString::fromStdString(links[i].dest->getName())+
" : "+QString::number(links[i].dest_idx)+
" "+QString::fromStdString(links[i].dest->getName(IO::INPUT,links[i].dest_idx)));
171 inputBlock->addItem(QString::fromStdString(block->
getName())+QString(
" ")+QString::number(block->
getID()));
172 outputBlock->addItem(QString::fromStdString(block->
getName())+QString(
" ")+QString::number(block->
getID()));
173 blocks.push_back(block);
175 if(blocks.size() == 1)
177 buildInputChannelList();
178 buildOutputChannelList();
186 for(index = 0; index < blocks.size() && blocks[index] != block; ++index);
187 if(index >= blocks.size())
190 size_t current0 = inputBlock->currentIndex();
191 size_t current1 = outputBlock->currentIndex();
193 inputBlock->removeItem(index);
194 outputBlock->removeItem(index);
195 blocks.erase(blocks.begin()+index);
197 if(current0 == index)
199 inputBlock->setCurrentIndex(0);
200 buildInputChannelList();
202 if(current1 == index)
204 outputBlock->setCurrentIndex(0);
205 buildOutputChannelList();
211 size_t src_idx = *
reinterpret_cast<size_t *
>(
event->getParam(
"src_num"));
213 size_t dest_idx = *
reinterpret_cast<size_t *
>(
event->getParam(
"dest_num"));
215 connectionBox->addItem(QString::number(src->
getID())+
" "+QString::fromStdString(src->
getName())+
" : "+
216 QString::number(src_idx)+
" "+QString::fromStdString(src->
getName(IO::OUTPUT,src_idx))+
" ==> "+
217 QString::number(dest->
getID())+
" "+QString::fromStdString(dest->
getName())+
" : "+
218 QString::number(dest_idx)+
" "+QString::fromStdString(dest->
getName(IO::INPUT,dest_idx)));
223 size_t src_idx = *
reinterpret_cast<size_t *
>(
event->getParam(
"src_num"));
225 size_t dest_idx = *
reinterpret_cast<size_t *
>(
event->getParam(
"dest_num"));
227 QString link_name = QString::number(src->
getID())+
" "+QString::fromStdString(src->
getName())+
" : "+
228 QString::number(src_idx)+
" "+QString::fromStdString(src->
getName(IO::OUTPUT,src_idx))+
" ==> "+
229 QString::number(dest->
getID())+
" "+QString::fromStdString(dest->
getName())+
" : "+
230 QString::number(dest_idx)+
" "+QString::fromStdString(dest->
getName(IO::INPUT,dest_idx));
233 for(index=0; index < (size_t) connectionBox->count() && connectionBox->item(index)->text() != link_name; ++index);
234 if(index >= (
size_t) connectionBox->count())
235 ERROR_MSG(
"Connector::Panel::receiveEvent : removing non-existant link.\n");
237 connectionBox->takeItem(index);
241 void Connector::Panel::buildInputChannelList(
void)
243 inputChannel->clear();
244 if(!inputBlock->count())
248 IO::Block *block = blocks[inputBlock->currentIndex()];
251 for(
size_t i = 0; i < block->
getCount(IO::INPUT); ++i)
252 inputChannel->addItem(QString::fromStdString(block->
getName(IO::INPUT,i)));
254 updateConnectionButton();
257 void Connector::Panel::buildOutputChannelList(
void)
259 outputChannel->clear();
260 if(!outputBlock->count())
264 IO::Block *block = blocks[outputBlock->currentIndex()];
267 for(
size_t i = 0; i < block->
getCount(IO::OUTPUT); ++i)
268 outputChannel->addItem(QString::fromStdString(block->
getName(IO::OUTPUT,i)));
270 updateConnectionButton();
273 void Connector::Panel::highlightConnectionBox(QListWidgetItem * item)
276 QString selection = item->text();
280 sep = selection.indexOf(
' ');
281 substr = selection.left(sep);
282 selection = selection.right(selection.length()-sep-1);
285 sep = selection.indexOf(
':');
286 selection = selection.right(selection.length()-sep-2);
288 sep = selection.indexOf(
' ');
289 substr = selection.left(sep);
290 selection = selection.right(selection.length()-sep-1);
291 size_t src_idx = substr.toULong();
293 sep = selection.indexOf(
"==>");
294 selection = selection.right(selection.length()-sep-4);
296 sep = selection.indexOf(
' ');
297 substr = selection.left(sep);
298 selection = selection.right(selection.length()-sep-1);
301 sep = selection.indexOf(
':');
302 selection = selection.right(selection.length()-sep-2);
304 sep = selection.indexOf(
' ');
305 substr = selection.left(sep);
306 selection = selection.right(selection.length()-sep-1);
307 size_t dest_idx = substr.toULong();
312 for(index = 0; index < blocks.size() && blocks[index] != src; ++index);
313 if(index >= blocks.size())
314 ERROR_MSG(
"Connector::Panel::highlightConnectionBox : highlighted source does not exist.\n");
316 outputBlock->setCurrentIndex(index);
317 buildOutputChannelList();
318 outputChannel->setCurrentIndex(src_idx);
321 for(index = 0; index < blocks.size() && blocks[index] != dest; ++index);
322 if(index >= blocks.size())
323 ERROR_MSG(
"Connector::Panel::highlightConnectionBox : highlighted destination does not exist.\n");
325 inputBlock->setCurrentIndex(index);
326 buildInputChannelList();
327 inputChannel->setCurrentIndex(dest_idx);
329 updateConnectionButton();
332 void Connector::Panel::toggleConnection(
bool on)
334 IO::Block *src = blocks[outputBlock->currentIndex()];
335 IO::Block *dest = blocks[inputBlock->currentIndex()];
336 size_t src_num = outputChannel->currentIndex();
337 size_t dest_num = inputChannel->currentIndex();
348 void Connector::Panel::updateConnectionButton(
void)
351 if(!inputChannel->count() || !outputChannel->count())
353 connectionButton->setEnabled(
false);
357 connectionButton->setEnabled(
true);
358 IO::Block *src = blocks[outputBlock->currentIndex()];
359 IO::Block *dest = blocks[inputBlock->currentIndex()];
360 size_t src_num = outputChannel->currentIndex();
361 size_t dest_num = inputChannel->currentIndex();
367 void Connector::Panel::buildConnectionList(
IO::Block *src,
size_t src_num,
IO::Block *dest,
size_t dest_num,
void *arg)
369 std::vector<link_t> &list = *
reinterpret_cast<std::vector<link_t> *
>(arg);
379 list.push_back(link);
387 Connector::Plugin::Plugin(
void) : panel(0)
392 Connector::Plugin::~Plugin(
void)