diff --git a/MRML/vtkMRMLROS2PublisherNode.cxx b/MRML/vtkMRMLROS2PublisherNode.cxx index 135d4f6..cd14125 100644 --- a/MRML/vtkMRMLROS2PublisherNode.cxx +++ b/MRML/vtkMRMLROS2PublisherNode.cxx @@ -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()) { diff --git a/qSlicerRos2ModuleWidget.cxx b/qSlicerRos2ModuleWidget.cxx index f3158f7..4c550bc 100644 --- a/qSlicerRos2ModuleWidget.cxx +++ b/qSlicerRos2ModuleWidget.cxx @@ -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: @@ -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); @@ -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); @@ -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(sub->GetNumberOfMessages())).toString(); // to convert to an int and then string QLabel *popupLabel = new QLabel(); @@ -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(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(); diff --git a/qSlicerRos2ModuleWidget.h b/qSlicerRos2ModuleWidget.h index f23d832..bde1f87 100644 --- a/qSlicerRos2ModuleWidget.h +++ b/qSlicerRos2ModuleWidget.h @@ -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);