playground.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2012, Willow Garage, Inc.
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 #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   std::stringstream input(
00083     "Enabled: true\n"
00084     "Displays:\n"
00085     " -\n"
00086     "   Class: MockDisplay\n"
00087     "   Name: Steven\n"
00088     "   Enabled: false\n"
00089     "   Count: 17\n"
00090     " -\n"
00091     "   Name: sub group\n"
00092     "   Class: DisplayGroup\n"
00093     "   Enabled: true\n"
00094     "   Displays:\n"
00095     "    -\n"
00096     "      Class: MockDisplay\n"
00097     "      Name: Curly\n"
00098     "      Enabled: false\n"
00099     "      Count: 900\n"
00100     " -\n"
00101     "   Class: BrokenDisplay\n"
00102     "   Name: Joe\n"
00103     "   Enabled: true\n"
00104     "   Count: 33\n"
00105     );
00106 
00107   YAML::Parser parser( input );
00108   YAML::Node node;
00109   parser.GetNextDocument( node );
00110 
00111   root_->initialize( vis_man_ );
00112   root_->load( node );
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 //  makeBigTree( cruft );
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 }


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Mon Oct 6 2014 07:26:35