Skip to content

Commit

Permalink
Re #39: Added popup label to publisher table widget. Updated prefix f…
Browse files Browse the repository at this point in the history
…or publisher node names from sub to pub.
  • Loading branch information
LauraConnolly committed Dec 5, 2022
1 parent 3ca8589 commit 05e5e1f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion MRML/vtkMRMLROS2PublisherNode.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bool vtkMRMLROS2PublisherNode::AddToROS2Node(const char * nodeId,
const std::string & topic)
{
mTopic = topic;
mMRMLNodeName = "ros2:sub:" + topic;
mMRMLNodeName = "ros2:pub:" + topic;
this->SetName(mMRMLNodeName.c_str());
vtkMRMLScene * scene = this->GetScene();
if (!this->GetScene()) {
Expand Down
37 changes: 35 additions & 2 deletions qSlicerRos2ModuleWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void qSlicerRos2ModuleWidget::setup(void)
// Note: All of the QLineEdits are triggered by pressing enter in the edit box - the slot functions access the text that was entered themselves
this->connect(d->loadVisualizationButton, SIGNAL(clicked(bool)), this, SLOT(onNodeOrParameterNameEntered()));
this->connect(d->rosSubscriberTableWidget, SIGNAL(cellClicked(int,int)), this, SLOT(subscriberClicked(int, int)));
// this->connect(d->rosPublisherTableWidget, SIGNAL(cellClicked(int,int)), this, SLOT(publisherClicked(int, int)));
this->connect(d->rosPublisherTableWidget, SIGNAL(cellClicked(int,int)), this, SLOT(publisherClicked(int, int)));
// file dialog signals are weird so using the button as a place holder just so you can print the name of the file you selected

// Set default, assuming defaults are:
Expand Down Expand Up @@ -252,7 +252,7 @@ void qSlicerRos2ModuleWidget::updateSubscriberTable(vtkMRMLROS2SubscriberNode* s

QString topicName = sub->GetTopic();
QString typeName = sub->GetROSType();

QTableWidgetItem *topic_item = d->rosSubscriberTableWidget->item(row, 0);
QTableWidgetItem *type_item = d->rosSubscriberTableWidget->item(row, 1);

Expand Down Expand Up @@ -281,6 +281,7 @@ void qSlicerRos2ModuleWidget::updatePublisherTable(vtkMRMLROS2PublisherNode* sub

QString topicName = sub->GetTopic();
QString typeName = sub->GetROSType();

QTableWidgetItem *topic_item = d->rosPublisherTableWidget->item(row, 0);
QTableWidgetItem *type_item = d->rosPublisherTableWidget->item(row, 2);

Expand Down Expand Up @@ -345,6 +346,10 @@ void qSlicerRos2ModuleWidget::subscriberClicked(int row, int col)
QString subName = d->rosSubscriberTableWidget->item(row,0)->text();
std::string referenceRole = subName.toStdString();
vtkMRMLROS2SubscriberNode *sub = vtkMRMLROS2SubscriberNode::SafeDownCast(logic->GetMRMLScene()->GetFirstNodeByName(("ros2:sub:" + referenceRole).c_str()));
if (!sub){
std::cerr << "No subscriber by this name in the scene" << std::endl;
return;
}
QString message = sub->GetLastMessageYAML().c_str();
QString numMessages = QVariant(static_cast<int>(sub->GetNumberOfMessages())).toString(); // to convert to an int and then string
QLabel *popupLabel = new QLabel();
Expand All @@ -355,6 +360,34 @@ void qSlicerRos2ModuleWidget::subscriberClicked(int row, int col)
}
}

void qSlicerRos2ModuleWidget::publisherClicked(int row, int col)
{
// Row is a reference to the message index
Q_D(qSlicerRos2ModuleWidget);
vtkSlicerRos2Logic* logic = vtkSlicerRos2Logic::SafeDownCast(this->logic());
if (!logic) {
qWarning() << Q_FUNC_INFO << " failed: Invalid SlicerROS2 logic";
return;
}
if (col == 1){ // only invoked when users click the number of messages cell
QString pubName = d->rosPublisherTableWidget->item(row,0)->text();
std::string referenceRole = pubName.toStdString();
vtkMRMLROS2PublisherNode *pub = vtkMRMLROS2PublisherNode::SafeDownCast(logic->GetMRMLScene()->GetFirstNodeByName(("ros2:pub:" + referenceRole).c_str()));
if (!pub){
std::cerr << "No publisher by this name in the scene" << std::endl;
return;
}
// QString message = pub->GetLastMessageYAML().c_str();
QString numMessages = QVariant(static_cast<int>(pub->GetNumberOfMessages())).toString(); // to convert to an int and then string
std::cerr << pub->GetNumberOfMessages() << std::endl;
QLabel *popupLabel = new QLabel();
QString numMess = "Num messages: ";
// QString mess = " Message: ";
popupLabel->setText(numMess + numMessages); //+ mess + message);
popupLabel->show();
}
}

void qSlicerRos2ModuleWidget::stopTimer(void) // Shouldn't be on quit - look here: https://doc.qt.io/qt-5/qapplication.html
{
mTimer->stop();
Expand Down
1 change: 1 addition & 0 deletions qSlicerRos2ModuleWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ protected slots:
void onLoadModelButtonSelected(void);
void onBroadcastButtonPressed();
void subscriberClicked(int row, int col);
void publisherClicked(int row, int col);

private:
Q_DECLARE_PRIVATE(qSlicerRos2ModuleWidget);
Expand Down

0 comments on commit 05e5e1f

Please sign in to comment.