Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "rviz/display_group.h"
00031
00032 #include "rviz/display_factory.h"
00033
00034 #include <tinyxml.h>
00035
00036 namespace rviz
00037 {
00038
00039 static Display* newDisplayGroup()
00040 {
00041 return new DisplayGroup();
00042 }
00043
00044 DisplayFactory::DisplayFactory()
00045 : PluginlibFactory<Display>( "rviz", "rviz::Display" )
00046 {
00047 addBuiltInClass( "rviz", "Group", "A container for Displays", &newDisplayGroup );
00048 }
00049
00050 Display* DisplayFactory::makeRaw( const QString& class_id, QString* error_return )
00051 {
00052 Display* display = PluginlibFactory<Display>::makeRaw( class_id, error_return );
00053 if ( display )
00054 {
00055 display->setIcon( getIcon( class_id ));
00056 }
00057 return display;
00058 }
00059
00060 QSet<QString> DisplayFactory::getMessageTypes( const QString& class_id )
00061 {
00062
00063 if ( message_type_cache_.find( class_id ) != message_type_cache_.end() )
00064 {
00065 return message_type_cache_[class_id];
00066 }
00067
00068
00069
00070 message_type_cache_[ class_id ] = QSet<QString>();
00071
00072
00073 QString xml_file = getPluginManifestPath( class_id );
00074
00075 if ( !xml_file.isEmpty() )
00076 {
00077 ROS_DEBUG_STREAM("Parsing " << xml_file.toStdString());
00078 TiXmlDocument document;
00079 document.LoadFile(xml_file.toStdString());
00080 TiXmlElement * config = document.RootElement();
00081 if (config == NULL)
00082 {
00083 ROS_ERROR("Skipping XML Document \"%s\" which had no Root Element. This likely means the XML is malformed or missing.", xml_file.toStdString().c_str());
00084 return QSet<QString>();
00085 }
00086 if (config->ValueStr() != "library" &&
00087 config->ValueStr() != "class_libraries")
00088 {
00089 ROS_ERROR("The XML document \"%s\" given to add must have either \"library\" or \
00090 \"class_libraries\" as the root tag", xml_file.toStdString().c_str());
00091 return QSet<QString>();
00092 }
00093
00094 if (config->ValueStr() == "class_libraries")
00095 {
00096 config = config->FirstChildElement("library");
00097 }
00098
00099 TiXmlElement* library = config;
00100 while ( library != NULL)
00101 {
00102 TiXmlElement* class_element = library->FirstChildElement("class");
00103 while (class_element)
00104 {
00105 std::string derived_class = class_element->Attribute("type");
00106
00107 std::string current_class_id;
00108 if(class_element->Attribute("name") != NULL)
00109 {
00110 current_class_id = class_element->Attribute("name");
00111 ROS_DEBUG("XML file specifies lookup name (i.e. magic name) = %s.", current_class_id.c_str());
00112 }
00113 else
00114 {
00115 ROS_DEBUG("XML file has no lookup name (i.e. magic name) for class %s, assuming class_id == real class name.", derived_class.c_str());
00116 current_class_id = derived_class;
00117 }
00118
00119 QSet<QString> message_types;
00120 TiXmlElement* message_type = class_element->FirstChildElement("message_type");
00121
00122 while ( message_type )
00123 {
00124 if ( message_type->GetText() )
00125 {
00126 const char* message_type_str = message_type->GetText();
00127 ROS_DEBUG_STREAM(current_class_id << " supports message type " << message_type_str );
00128 message_types.insert( QString::fromAscii( message_type_str ) );
00129 }
00130 message_type = message_type->NextSiblingElement("message_type");
00131 }
00132
00133 message_type_cache_[ QString::fromStdString(current_class_id) ] = message_types;
00134
00135
00136 class_element = class_element->NextSiblingElement( "class" );
00137 }
00138 library = library->NextSiblingElement( "library" );
00139 }
00140 }
00141
00142
00143 if ( message_type_cache_.find( class_id ) != message_type_cache_.end() )
00144 {
00145 return message_type_cache_[class_id];
00146 }
00147
00148 return QSet<QString>();
00149 }
00150
00151
00152 }