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 Project Download Mailing lists
|
icestormelement3d.h00001 /* 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_ICESTORM_ELEMENT_3D_H 00012 #define ORCAGUI3D_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/icestormlistener.h> 00020 00021 // forward declarations 00022 class QPainter; 00023 00024 namespace orcaqgui3d { 00025 00033 template<class PainterType, class DataType, class ProxyType, class ConsumerType, class ConsumerPrxType> 00034 class IceStormElement3d : public GuiElement3d 00035 { 00036 00037 public: 00038 00041 IceStormElement3d( 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 DataType data_; 00067 00068 bool needToUpdate(); 00069 00071 orcaqgui::IceStormListener<DataType, 00072 ProxyType, 00073 ConsumerType, 00074 ConsumerPrxType> listener_; 00075 00076 00078 PainterType &painter_; 00079 00080 double timeoutMs_; 00081 bool isConnected_; 00082 }; 00083 00084 template<class PainterType, class DataType, class ProxyType, class ConsumerType, class ConsumerPrxType> 00085 bool 00086 IceStormElement3d<PainterType,DataType,ProxyType,ConsumerType,ConsumerPrxType>::needToUpdate() 00087 { 00088 if ( !listener_.buffer().isEmpty() ) 00089 { 00090 // An object has arrived in our buffer. We need to update. 00091 return true; 00092 } 00093 00094 if ( !isConnected_ ) 00095 { 00096 if ( listener_.connect() == 0 ) 00097 { 00098 actionOnConnection(); 00099 isConnected_ = true; 00100 } 00101 return false; 00102 } 00103 00104 // The buffer is empty. How long since we last received something? 00105 if ( timeoutMs_ != -1 && listener_.msSinceReceipt() >= timeoutMs_ ) 00106 { 00107 std::cout<<"TRACE(icestormelement.h): Haven't received anything from " 00108 << listener_.interfaceName() << " for " << listener_.msSinceReceipt() << "ms" << std::endl; 00109 std::cout<<"TRACE(icestormelement.h): Timing out..." << std::endl; 00110 00111 painter_.clear(); 00112 listener_.resetTimer(); 00113 if ( listener_.connect() == 0 ) 00114 actionOnConnection(); 00115 } 00116 return false; 00117 } 00118 00119 template<class PainterType, class DataType, class ProxyType, class ConsumerType, class ConsumerPrxType> 00120 void 00121 IceStormElement3d<PainterType,DataType,ProxyType,ConsumerType,ConsumerPrxType>::update() 00122 { 00123 if ( !needToUpdate() ) { 00124 return; 00125 } 00126 00127 assert( !listener_.buffer().isEmpty() ); 00128 00129 // get data from the buffer 00130 listener_.buffer().getAndPop( data_ ); 00131 00132 // transfer data into painter 00133 painter_.setData( data_ ); 00134 } 00135 00136 } 00137 00138 #endif |
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)