orca-robotics


INTRODUCTION
Overview
Download and Install
Quick Start
Documentation
Publications

REPOSITORY
Interfaces
Components
Libraries
Utilities
Software Map

DEVELOPER
Tutorials
Examples
Dev Guide
Dashboard
Wiki
login/pass: orca/orca

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         

ptricestormelement3d.h

00001 /*
00002  * Orca-Robotics Project: Components for robotics 
00003  *               http://orca-robotics.sf.net/
00004  * Copyright (c) 2004-2008 Alex Brooks, Alexei Makarenko, Tobias Kaupp
00005  *
00006  * This copy of Orca is licensed to you under the terms described in
00007  * the LICENSE file included in this distribution.
00008  *
00009  */
00010 
00011 #ifndef ORCAGUI3D_PTR_ICESTORM_ELEMENT_3D_H
00012 #define ORCAGUI3D_PTR_ICESTORM_ELEMENT_3D_H
00013 
00014 #include <assert.h>
00015 #include <Ice/Ice.h>
00016 #include <IceStorm/IceStorm.h>
00017 
00018 #include <orcaqgui3d/guielement3d.h>
00019 #include <orcaqgui/ptricestormlistener.h>
00020 
00021 // forward declarations
00022 class QPainter;
00023 
00024 namespace orcaqgui3d {
00025 
00033 template<class PainterType, class DataType, class DataPtrType, class ProxyType, class ConsumerType, class ConsumerPrxType>
00034 class PtrIceStormElement3d : public GuiElement3d
00035 {
00036   
00037 public:
00038 
00041     PtrIceStormElement3d( const orcaice::Context  &context,
00042                        const std::string       &proxyString,
00043                        PainterType             &painter,
00044                        const double            timeoutMs=5000.0 )
00045         : context_(context),
00046           listener_(context,proxyString),
00047           painter_(painter),
00048           timeoutMs_(timeoutMs),
00049           isConnected_(false)
00050         {};
00051 
00053     virtual void actionOnConnection()=0;
00054 
00056     virtual void update();
00057 
00059     void paint( QGLWidget *p )
00060         { painter_.paint( p ); }
00061 
00062 protected:
00063 
00064     orcaice::Context              context_;
00065     
00066     DataPtrType                       data_;
00067     
00068     bool needToUpdate();
00069     
00071     orcaqgui::PtrIceStormListener<DataType,
00072                      DataPtrType,
00073                      ProxyType,
00074                      ConsumerType,
00075                      ConsumerPrxType> listener_;
00076     
00077 
00079     PainterType                     &painter_;
00080     
00081     double                           timeoutMs_;
00082     bool                             isConnected_;
00083 };
00084 
00085 template<class PainterType, class DataType, class DataPtrType, class ProxyType, class ConsumerType, class ConsumerPrxType>
00086 bool 
00087 PtrIceStormElement3d<PainterType,DataType,DataPtrType,ProxyType,ConsumerType,ConsumerPrxType>::needToUpdate()
00088 {
00089     if ( !listener_.buffer().isEmpty() )
00090     {
00091         // An object has arrived in our buffer.  We need to update.
00092         return true;
00093     }
00094 
00095     if ( !isConnected_ )
00096     {
00097         if ( listener_.connect() == 0 )
00098         {
00099             actionOnConnection();
00100             isConnected_ = true;
00101         }
00102         return false;
00103     }
00104 
00105     // The buffer is empty.  How long since we last received something?
00106     if ( timeoutMs_ != -1 && listener_.msSinceReceipt() >= timeoutMs_ )
00107     {
00108         std::cout<<"TRACE(icestormelement.h): Haven't received anything from " 
00109                  << listener_.interfaceName() << " for " << listener_.msSinceReceipt() << "ms" << std::endl;
00110         std::cout<<"TRACE(icestormelement.h): Timing out..." << std::endl;
00111 
00112         painter_.clear();
00113         listener_.resetTimer();
00114         if ( listener_.connect() == 0 )
00115             actionOnConnection();
00116     }
00117     return false;
00118 }
00119 
00120 template<class PainterType, class DataType, class DataPtrType, class ProxyType, class ConsumerType, class ConsumerPrxType>
00121 void 
00122 PtrIceStormElement3d<PainterType,DataType,DataPtrType,ProxyType,ConsumerType,ConsumerPrxType>::update()
00123 {
00124     if ( !needToUpdate() ) {
00125         return;
00126     }
00127     
00128     assert( !listener_.buffer().isEmpty() );
00129 
00130     // get data from the buffer
00131     listener_.buffer().getAndPop( data_ );
00132 
00133     // transfer data into painter
00134     painter_.setData( data_ );
00135 }
00136 
00137 }
00138 
00139 
00140 
00141 #endif
 

Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)


Generated for Orca Robotics by  doxygen 1.4.5