Commits

"Nat...@gmail.com>"  committed 5719787

Updates

  • Participants
  • Parent commits e2f2a4c
  • Branches sensor_vis

Comments (0)

Files changed (2)

File gazebo/gui/viewers/TextView.cc

 {
   this->setWindowTitle(tr("Gazebo: Text View"));
 
+  this->bufferSize = 10;
+  this->paused = false;
+
   // Create the text list
   // {
   QVBoxLayout *frameLayout = new QVBoxLayout;
 
-  this->textView = new QListView();
+  this->msgList = new QListWidget();
 
-  frameLayout->addWidget(this->textView);
+  QHBoxLayout *controlLayout = new QHBoxLayout;
+
+  QSpinBox *bufferSpin = new QSpinBox();
+  bufferSpin->setMinimum(1);
+  bufferSpin->setValue(this->bufferSize);
+  connect(bufferSpin, SIGNAL(valueChanged(int)), this, SLOT(OnBuffer(int)));
+
+  controlLayout->addWidget(new QLabel(tr("Buffer: ")));
+  controlLayout->addWidget(bufferSpin);
+
+  QCheckBox *pauseCheck = new QCheckBox();
+  pauseCheck->setChecked(this->paused);
+  connect(pauseCheck, SIGNAL(clicked(bool)), this, SLOT(OnPause(bool)));
+
+  controlLayout->addWidget(new QLabel(tr("Pause: ")));
+  controlLayout->addWidget(pauseCheck);
+
+  frameLayout->addWidget(this->msgList);
+  frameLayout->addLayout(controlLayout);
+
   this->frame->setObjectName("blackBorderFrame");
   this->frame->setLayout(frameLayout);
   // }
 {
   TopicView::SetTopic(_topicName);
 
-  // Subscribe to the new topic.
-  this->sub.reset();
-  this->sub = this->node->Subscribe(_topicName, &TextView::OnText, this);
+  this->msg = msgs::MsgFactory::NewMsg(this->msgTypeName);
+
+  this->msgList->clear();
+
+  // Subscribe to the new topic if we have generated an appropriate message
+  if (this->msg)
+  {
+    this->sub.reset();
+    this->sub = this->node->Subscribe(_topicName, &TextView::OnText, this);
+  }
+  else
+  {
+    this->msgList->addItem(new QListWidgetItem(QString::fromStdString(
+          std::string("Unable to parse message of type[") +
+          this->msgTypeName + "]")));
+  }
 }
 
 /////////////////////////////////////////////////
 void TextView::OnText(const std::string &_msg)
 {
-  // Update the Hz and Bandwidth info
+  if (this->paused)
+    return;
+
+  // Update the Hz and Bandwidth info.
   this->OnMsg(common::Time::GetWallTime(), _msg.size());
 
-  google::protobuf::Message *msg = msgs::MsgFactory::NewMsg(this->msgTypeName);
-  if (msg)
+  // Convert the raw data to a message.
+  msg->ParseFromString(_msg);
+
   {
-    msg->ParseFromString(_msg);
-    std::cout << msg->DebugString() << "\n";
+    boost::mutex::scoped_lock lock(this->mutex);
+
+    // Create a new list item.
+    QListWidgetItem *item = new QListWidgetItem(
+        QString::fromStdString(msg->DebugString()));
+
+    // Add the new text to the output view.
+    this->msgList->addItem(item);
+
+    // Remove items if the list is too long.
+    while (this->msgList->count() > this->bufferSize)
+      delete this->msgList->takeItem(0);
   }
-  else
-    gzerr << "Unable to parse message of type[" << this->msgTypeName << "]\n";
+}
 
-  // Add the new text to the output view.
+/////////////////////////////////////////////////
+void TextView::OnPause(bool _value)
+{
+  boost::mutex::scoped_lock lock(this->mutex);
+  this->paused = _value;
 }
+
+/////////////////////////////////////////////////
+void TextView::OnBuffer(int _value)
+{
+  boost::mutex::scoped_lock lock(this->mutex);
+
+  this->bufferSize = _value;
+
+  // Remove and item if the list is too long.
+  while (this->msgList->count() > this->bufferSize)
+    delete this->msgList->takeItem(0);
+}

File gazebo/gui/viewers/TextView.hh

 #define _TEXTVIEW_HH_
 
 #include <string>
+#include <boost/thread/mutex.hpp>
 
 #include "gazebo/common/Time.hh"
 #include "gazebo/msgs/msgs.hh"
       /// \param[in] _msg New text message.
       private: void OnText(const std::string &_msg);
 
+      /// \brief QT callback when the buffer spin box has been changed.
+      /// \param[in] _value New value of the spin box.
+      private slots: void OnBuffer(int _value);
+
+      /// \brief QT callback when the pause check box has been changed.
+      /// \param[in] _value New value of the check box.
+      private slots: void OnPause(bool _value);
+
       /// \brief A scolling list of text data.
-      private: QListView *textView;
+      private: QListWidget *msgList;
+
+      /// \brief Size of the text buffer. The size is the number of
+      /// messages.
+      private: int bufferSize;
+
+      /// \brief The protobuf message used to decode incoming message data.
+      private: google::protobuf::Message *msg;
+      private: boost::mutex mutex;
+
+      private: bool paused;
     };
   }
 }