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 <stdio.h>
00031
00032 #include <QColor>
00033 #include <QApplication>
00034 #include <QFont>
00035
00036 #include <yaml-cpp/node.h>
00037 #include <yaml-cpp/emitter.h>
00038
00039 #include "rviz/display_context.h"
00040 #include "rviz/properties/yaml_helpers.h"
00041 #include "rviz/properties/property_tree_model.h"
00042 #include "rviz/properties/status_list.h"
00043
00044 #include "display.h"
00045
00046 namespace rviz
00047 {
00048
00049 Display::Display()
00050 : status_( 0 )
00051 , initialized_( false )
00052 {
00053
00054 setValue( false );
00055
00056 connect( this, SIGNAL( changed() ), this, SLOT( onEnableChanged() ));
00057 }
00058
00059 void Display::initialize( DisplayContext* context )
00060 {
00061 context_ = context;
00062 scene_manager_ = context_->getSceneManager();
00063 update_nh_.setCallbackQueue( context_->getUpdateQueue() );
00064 threaded_nh_.setCallbackQueue( context_->getThreadedQueue() );
00065 fixed_frame_ = context_->getFixedFrame();
00066
00067 onInitialize();
00068
00069 initialized_ = true;
00070 }
00071
00072 QVariant Display::getViewData( int column, int role ) const
00073 {
00074 if( column == 0 )
00075 {
00076 switch( role )
00077 {
00078 case Qt::BackgroundRole:
00079 {
00080 QColor status_color = StatusProperty::statusColor( status_ ? status_->getLevel() : StatusProperty::Ok );
00081 return status_color.isValid() ? status_color : QColor( 4, 89, 127 );
00082 }
00083 case Qt::ForegroundRole: return QColor( Qt::white );
00084 case Qt::FontRole:
00085 {
00086 QFont font = QApplication::font( "PropertyTreeWidget" );
00087 font.setBold( true );
00088 return font;
00089 }
00090 }
00091 }
00092 return Property::getViewData( column, role );
00093 }
00094
00095 Qt::ItemFlags Display::getViewFlags( int column ) const
00096 {
00097 return Property::getViewFlags( column ) | Qt::ItemIsDragEnabled;
00098 }
00099
00100 void Display::setStatus( StatusProperty::Level level, const QString& name, const QString& text )
00101 {
00102 if( !status_ )
00103 {
00104 status_ = new StatusList( "Status" );
00105 addChild( status_, 0 );
00106 }
00107 StatusProperty::Level old_level = status_->getLevel();
00108 status_->setStatus( level, name, text );
00109 if( old_level != status_->getLevel() )
00110 {
00111 model_->emitDataChanged( this );
00112 }
00113 }
00114
00115 void Display::deleteStatus( const QString& name )
00116 {
00117 status_->deleteStatus( name );
00118 }
00119
00120 void Display::clearStatuses()
00121 {
00122 if( status_ )
00123 {
00124 StatusProperty::Level old_level = status_->getLevel();
00125 status_->clear();
00126 if( old_level != StatusProperty::Ok )
00127 {
00128 model_->emitDataChanged( this );
00129 }
00130 }
00131 }
00132
00133 void Display::load( const YAML::Node& yaml_node )
00134 {
00135 loadChildren( yaml_node );
00136 }
00137
00138 void Display::loadChildren( const YAML::Node& yaml_node )
00139 {
00140 if( yaml_node.Type() != YAML::NodeType::Map )
00141 {
00142 printf( "Display::load() TODO: error handling - unexpected non-map YAML type at line %d column %d.\n",
00143 yaml_node.GetMark().line, yaml_node.GetMark().column );
00144 return;
00145 }
00146
00147
00148
00149 if( const YAML::Node *name_node = yaml_node.FindValue( "Name" ))
00150 {
00151 QString name;
00152 *name_node >> name;
00153 setName( name );
00154 }
00155
00156
00157 Property::loadChildren( yaml_node );
00158
00159
00160 if( const YAML::Node *enabled_node = yaml_node.FindValue( "Enabled" ))
00161 {
00162 bool enabled;
00163 *enabled_node >> enabled;
00164 setEnabled( enabled );
00165 }
00166 }
00167
00168 void Display::save( YAML::Emitter& emitter )
00169 {
00170 emitter << YAML::BeginMap;
00171 saveChildren( emitter );
00172 emitter << YAML::EndMap;
00173 }
00174
00175 void Display::saveChildren( YAML::Emitter& emitter )
00176 {
00177 emitter << YAML::Key << "Class";
00178 emitter << YAML::Value << getClassId();
00179
00180 emitter << YAML::Key << "Name";
00181 emitter << YAML::Value << getName();
00182
00183 emitter << YAML::Key << "Enabled";
00184 emitter << YAML::Value << isEnabled();
00185
00186 Property::saveChildren( emitter );
00187 }
00188
00189 void Display::setEnabled( bool enabled )
00190 {
00191 setValue( enabled );
00192 }
00193
00194 bool Display::isEnabled() const
00195 {
00196 return getValue().toBool();
00197 }
00198
00199 void Display::setFixedFrame( const QString& fixed_frame )
00200 {
00201 fixed_frame_ = fixed_frame;
00202 if( initialized_ )
00203 {
00204 fixedFrameChanged();
00205 }
00206 }
00207
00208 void Display::reset()
00209 {
00210 clearStatuses();
00211 }
00212
00213 void Display::onEnableChanged()
00214 {
00215 if( isEnabled() )
00216 {
00217 onEnable();
00218 }
00219 else
00220 {
00221 onDisable();
00222 }
00223 }
00224
00225 }