jlo_topic_display.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010, Lorenz Moesenlechner
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  *
00029  *
00030  */
00031 
00032 #include "jlo_topic_display.h"
00033 #include "rviz/properties/property.h"
00034 #include "rviz/properties/property_manager.h"
00035 
00036 #include "rviz/common.h"
00037 
00038 #include <sstream>
00039 
00040 using namespace vision_srvs;
00041 namespace rviz_shows_cop
00042 {
00043 
00044 JloTopicDisplay::JloTopicDisplay(const std::string & name,
00045                                          rviz::VisualizationManager * manager)
00046   : JloDisplayBase(name, manager),
00047   inited(false)
00048 {
00049 }
00050 
00051 JloTopicDisplay::~JloTopicDisplay()
00052 {
00053   unsubscribe();
00054 }
00055 
00056 void JloTopicDisplay::setTopic(const std::string & topic)
00057 {
00058   unsubscribe();
00059   JloDisplayBase::setTopic(topic);
00060   inited = false;
00061   subscribe();
00062 }
00063 
00064 
00065 void JloTopicDisplay::subscribe()
00066 {
00067   if (!isEnabled() || topic_.length() < 2)
00068   {
00069     m_binited = false;
00070     return;
00071   }
00072   m_binited = true;
00073   jlo_subscriber = update_nh_.subscribe<std_msgs::UInt32>(topic_,1, boost::bind(&JloTopicDisplay::incomingMessage, this, _1));
00074 }
00075 
00076 void JloTopicDisplay::unsubscribe()
00077 {
00078   jlo_subscriber.shutdown();
00079 }
00080 
00081 void JloTopicDisplay::incomingMessage (const std_msgs::UInt32ConstPtr& msg)
00082 {
00083   JloDisplayBase::JloDescription jlo_descr[1];
00084 
00085   m_currMessage = msg;
00086   inited = true;
00087 
00088   std::stringstream strm;
00089 
00090   jlo_descr[0].pose = msg->data;
00091   strm << msg->data;
00092   jlo_descr[0].label = strm.str();
00093   try
00094   {
00095   displayJloSet(&jlo_descr[0], &jlo_descr[1]);
00096   }
00097   catch(...)
00098   {
00099     ROS_INFO("tf sucks, please start a state publisher or similar stuff\n");
00100   }
00101 }
00102 
00103 void JloTopicDisplay::createProperties()
00104 {
00105   /*lor_property_ = property_manager_->createProperty<rviz::ColorProperty> ("Color", property_prefix_, boost::bind(&CopAnswerDisplay::getColor, this),
00106                                                                       boost::bind(&CopAnswerDisplay::setColor, this, _1), parent_category_, this);*/
00107   JloDisplayBase::createProperties();
00108 
00109   topic_property_ = property_manager_->createProperty<rviz::ROSTopicStringProperty> ("Topic", property_prefix_, boost::bind(&JloDisplayBase::getTopic, this),
00110                                                                                boost::bind(&JloDisplayBase::setTopic, this, _1), parent_category_, this);
00111   rviz::ROSTopicStringPropertyPtr topic_prop = topic_property_.lock();
00112   topic_prop->setMessageType(std_msgs::UInt32::__s_getDataType());
00113 
00114 }
00115 
00116 
00117 } // namespace mapping_rviz_plugin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


cop_rviz_plugin
Author(s): U. Klank, Josh Faust
autogenerated on Thu May 23 2013 10:50:43