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 <QApplication>
00031 #include <QPushButton>
00032 #include <QVBoxLayout>
00033 #include <QFileDialog>
00034
00035 #include <fstream>
00036 #include <sstream>
00037
00038 #include <yaml-cpp/yaml.h>
00039
00040 #include "rviz/properties/color_property.h"
00041 #include "rviz/properties/property.h"
00042 #include "rviz/properties/quaternion_property.h"
00043 #include "rviz/properties/vector_property.h"
00044 #include "rviz/properties/property_tree_model.h"
00045 #include "rviz/properties/property_tree_widget.h"
00046 #include "rviz/properties/status_list.h"
00047 #include "rviz/display.h"
00048 #include "rviz/display_group.h"
00049 #include "rviz/visualization_manager.h"
00050
00051 #include "fun_display.h"
00052 #include "mock_display_factory.h"
00053
00054 #include "playground.h"
00055
00056 void makeBigTree( DisplayGroup* parent )
00057 {
00058 Display* disp;
00059 for( int i = 0; i < 100; i++ )
00060 {
00061 disp = new FunDisplay();
00062 disp->setName( "D" + QString::number( i ));
00063 disp->setParentProperty( parent );
00064
00065 for( int j = 0; j < 100; j++ )
00066 {
00067 new Property( "prop" + QString::number( j ), j, "how many", disp );
00068 }
00069 }
00070 }
00071
00072 Playground::Playground( QWidget* parent )
00073 : QWidget( parent )
00074 {
00075 factory_ = new MockDisplayFactory;
00076 vis_man_ = new VisualizationManager;
00077 vis_man_->setDisplayFactory( factory_ );
00078
00079 root_ = new DisplayGroup;
00080 model_ = new PropertyTreeModel( root_ );
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 Display* display = new Display();
00116 display->setName( "Test" );
00117 display->setParentProperty( root_ );
00118 new Property( "Alpha", 0.5, "The amount of transparency to apply to the grid lines.", display );
00119 new Property( "Beta Band", 10, "The number of betas to apply to the grid lines.", display );
00120 new Property( "Gamma Topic", "chubby", "The topic on which to listen for Gamma messages.", display );
00121 Property* position = new Property( "Position", QVariant(), "Position of the chub.", display );
00122 new Property( "X", 1.1, "X component of the position of the chub.", position );
00123 new Property( "Y", 0.717, "Y component of the position of the chub.", position );
00124 DisplayGroup* group = new DisplayGroup();
00125 group->setName( "Group" );
00126 group->setParentProperty( root_ );
00127 DisplayGroup* sub_group = new DisplayGroup();
00128 sub_group->setName( "SubGroup" );
00129 sub_group->setParentProperty( group );
00130 Display* display2 = new Display();
00131 display2->setName( "Taste" );
00132 display2->setParentProperty( group );
00133 DisplayGroup* cruft = new DisplayGroup();
00134 cruft->setName( "Cruft" );
00135 cruft->setParentProperty( root_ );
00136 new VectorProperty( "Vector", Ogre::Vector3( 1, 2, 3 ), "3 numbers in a row.", display2 );
00137 new QuaternionProperty( "Quaternion", Ogre::Quaternion( 1, 0, 0, 0 ), "4 numbers in a row!", display2 );
00138 Display* display3 = new Display();
00139 display3->setName( "Toast" );
00140 display3->setParentProperty( group );
00141 new ColorProperty( "Color", QColor( 1, 2, 3 ), "Better than black and white.", display3 );
00142 Display* display4 = new Display();
00143 display4->setName( "Lamby" );
00144 display4->setParentProperty( group );
00145 StatusList* stat = new StatusList( display4 );
00146 stat->setStatus( StatusProperty::Warn, "Topic", "No messages received." );
00147 stat->setStatus( StatusProperty::Error, "Size", "Size is too large." );
00148 stat->setStatus( StatusProperty::Ok, "Cheese", "Cheese is tasty." );
00149 stat = new StatusList( display );
00150 stat->setStatus( StatusProperty::Warn, "Topic", "No messages received." );
00151 stat->setStatus( StatusProperty::Error, "Size", "Size is too large." );
00152 stat->setStatus( StatusProperty::Ok, "Cheese", "Cheese is tasty." );
00153
00154 FunDisplay* fun = new FunDisplay();
00155 fun->setName( "Fun" );
00156 fun->setParentProperty( group );
00157
00158 fun = new FunDisplay();
00159 fun->setName( "Funner" );
00160 fun->setParentProperty( group );
00161
00162 PropertyTreeWidget* w = new PropertyTreeWidget;
00163 w->setModel( model_ );
00164
00165
00166
00167 QPushButton* load_button = new QPushButton( "load" );
00168 connect( load_button, SIGNAL( clicked() ), this, SLOT( openLoadFileDialog() ));
00169
00170 QVBoxLayout* main_layout = new QVBoxLayout;
00171 main_layout->addWidget( w );
00172 main_layout->addWidget( load_button );
00173
00174 setLayout( main_layout );
00175
00176 setWindowTitle("fun");
00177 }
00178
00179 void Playground::openLoadFileDialog()
00180 {
00181 QString filename = QFileDialog::getOpenFileName( this );
00182 std::ifstream in( filename.toStdString().c_str() );
00183 if( in )
00184 {
00185 YAML::Parser parser( in );
00186 YAML::Node node;
00187 parser.GetNextDocument( node );
00188 root_->initialize( vis_man_ );
00189 root_->load( node );
00190 }
00191 else
00192 {
00193 printf("Failed to read file %s.\n", qPrintable( filename ));
00194 }
00195 }
00196
00197 int main( int argc, char **argv )
00198 {
00199 QApplication app( argc, argv );
00200
00201 Playground w;
00202 w.resize( 400, 600 );
00203 w.show();
00204
00205 return app.exec();
00206 }