fun_display.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 <stdlib.h> // for random
00031 #include <stdio.h> // for printf
00032 
00033 #include <QTimer>
00034 
00035 #include "fun_display.h"
00036 
00037 // static member
00038 FunDisplay* FunDisplay::previous_fun_ = NULL;
00039 
00040 FunDisplay::FunDisplay()
00041   : count_( 0 )
00042 {
00043   size_ = new Property( "Size", 10, "How big, in units", this );
00044   connect( size_, SIGNAL( changed() ), this, SLOT( onSizeChanged() ));
00045 
00046   master_ = new Property( "Master", "chunky", "Type of butter.", this );
00047   connect( master_, SIGNAL( changed() ), this, SLOT( onMasterChanged() ));
00048 
00049   if( previous_fun_ )
00050   {
00051     connect( previous_fun_->master_, SIGNAL( changed() ), this, SLOT( onMasterChanged() ));
00052   }
00053   previous_fun_ = this;
00054 
00055   new Property( "Double", 1.0, "double", this );
00056   new Property( "Float", 1.0f, "float", this );
00057 
00058   slave_ = new Property( "Slave", "chunky", "Slave to the butter.", this );
00059 
00060   mood_ = new EnumProperty( "Mood", "sad", "Feelings, nothing more than feelings...", this );
00061   mood_->addOption( "sad", 0 );
00062   mood_->addOption( "happy", 1 );
00063   mood_->addOption( "angry", 2 );
00064   mood_->addOption( "jumpy", 3 );
00065   mood_->addOption( "squirmy", 4 );
00066   connect( mood_, SIGNAL( changed() ), this, SLOT( onMoodChanged() ));
00067 
00068   dance_ = new EditableEnumProperty( "Dance", "clown", "Stomple stomple", this );
00069   connect( dance_, SIGNAL( requestOptions( EditableEnumProperty* )), this, SLOT( makeDances( EditableEnumProperty* )));
00070 
00071   QTimer* timer = new QTimer( this );
00072   connect( timer, SIGNAL( timeout() ), this, SLOT( onTimerTick() ));
00073   timer->start( 1000 );
00074 }
00075 
00076 void FunDisplay::onTimerTick()
00077 {
00078   count_++;
00079   slave_->setValue( count_ );
00080   if( (count_ / 10) % 2 )
00081   {
00082     setStatus( StatusProperty::Warn, "Slave", "Too odd." );
00083   }
00084   else
00085   {
00086     setStatus( StatusProperty::Ok, "Slave", "Even enough." );
00087   }
00088 }
00089 
00090 void FunDisplay::onMasterChanged()
00091 {
00092   slave_->setValue( master_->getValue() );
00093 }
00094 
00095 void FunDisplay::onSizeChanged()
00096 {
00097   if( size_->getValue().toInt() > 10 )
00098   {
00099     setStatus( StatusProperty::Error, "Size", "Too large." );
00100   }
00101   else if( size_->getValue().toInt() < 5 )
00102   {
00103     setStatus( StatusProperty::Warn, "Size", "Too small." );
00104   }
00105   else
00106   {
00107     setStatus( StatusProperty::Ok, "Size", "Just fine." );
00108   }
00109 }
00110 
00111 void FunDisplay::onMoodChanged()
00112 {
00113   printf( "Mood is now %d.\n", mood_->getOptionInt() );
00114 }
00115 
00116 void FunDisplay::makeDances( EditableEnumProperty* prop )
00117 {
00118   QStringList dances;
00119   dances.push_back( "Robot/Turtlebot" );
00120   dances.push_back( "Robot/PR2" );
00121   dances.push_back( "Macarena/Fast" );
00122   dances.push_back( "Macarena/Slow" );
00123   dances.push_back( "Twist" );
00124   dances.push_back( "Tango" );
00125   dances.push_back( "Swing/Lindy" );
00126   dances.push_back( "Swing/Hop/Small" );
00127   dances.push_back( "Swing/Hop/Big" );
00128   dances.push_back( "Stumble" );
00129   dances.push_back( "Stomple" );
00130 
00131   prop->clearOptions();
00132   for( int i = 0; i < 9; i++ )
00133   {
00134     int index = random() % dances.size();
00135     prop->addOption( dances[ index ]);
00136   }
00137 }


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