SegmentPanel.cpp
Go to the documentation of this file.
00001 
00012 // RAIL Pick and Place Tools
00013 #include "rail_pick_and_place_tools/SegmentPanel.h"
00014 
00015 // ROS
00016 #include <pluginlib/class_list_macros.h>
00017 #include <std_srvs/Empty.h>
00018 
00019 // Qt
00020 #include <QBoxLayout>
00021 
00022 using namespace std;
00023 using namespace rail::pick_and_place;
00024 
00025 SegmentPanel::SegmentPanel(QWidget *parent) : rviz::Panel(parent)
00026 {
00027   // set defaults
00028   string segment_service("/segmentation/segment");
00029 
00030   // get the segmentation service
00031   node_.getParam("/rviz/segment_panel/segment_service", segment_service);
00032 
00033   // setup the segmentation service
00034   segment_srv_ = node_.serviceClient<std_srvs::Empty>(segment_service);
00035 
00036   // main segmentation button
00037   segment_button_ = new QPushButton("Segment");
00038 
00039   // service label
00040   string service_label_text = "Calling on " + segment_service;
00041   QLabel *segment_label = new QLabel(service_label_text.c_str());
00042   segment_label->setAlignment(Qt::AlignCenter);
00043 
00044   // service feedback
00045   segment_status_ = new QLabel("Ready to segment.");
00046   segment_status_->setAlignment(Qt::AlignCenter);
00047 
00048   // build the final layout
00049   QVBoxLayout *layout = new QVBoxLayout();
00050   layout->addWidget(segment_button_);
00051   layout->addWidget(segment_label);
00052   layout->addWidget(segment_status_);
00053 
00054   // connect the segmentation button
00055   QObject::connect(segment_button_, SIGNAL(clicked()), this, SLOT(executeSegment()));
00056 
00057   // set the final layout
00058   this->setLayout(layout);
00059 }
00060 
00061 void SegmentPanel::executeSegment()
00062 {
00063   // disable the button first
00064   segment_button_->setEnabled(false);
00065 
00066   // check if the service exists
00067   if (!segment_srv_.exists())
00068   {
00069     segment_status_->setText("Failed to call segmentation service.");
00070   } else
00071   {
00072     // attempt to call the service
00073     std_srvs::Empty srv;
00074     if (!segment_srv_.call(srv))
00075     {
00076       segment_status_->setText("Segmentation failed.");
00077     }
00078     else
00079     {
00080       segment_status_->setText("Segmentation complete.");
00081     }
00082   }
00083 
00084   // re-enable the button
00085   segment_button_->setEnabled(true);
00086 }
00087 
00088 void SegmentPanel::save(rviz::Config config) const
00089 {
00090   // simply call the super class
00091   rviz::Panel::save(config);
00092 }
00093 
00094 void SegmentPanel::load(const rviz::Config &config)
00095 {
00096   // simply call the super class
00097   rviz::Panel::load(config);
00098 }
00099 
00100 // tell pluginlib about this class (must outside of any namespace scope)
00101 PLUGINLIB_EXPORT_CLASS(rail::pick_and_place::SegmentPanel, rviz::Panel)


rail_pick_and_place_tools
Author(s): Russell Toris , David Kent
autogenerated on Thu Jun 6 2019 19:44:16