aride_playerhandlers.h

00001 /* -- 2007-05-07 -- 
00002  *  ardev - an augmented reality library for robot developers
00003  *  Copyright 2005-2007 - Toby Collett (ardev _at_ plan9.net.nz)
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU Lesser General Public
00016  *  License along with this library; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
00018  *
00019  */
00020 #ifndef ARIDE_PLAYERHANDLERS_H
00021 #define ARIDE_PLAYERHANDLERS_H
00022 
00023 //#include <ardev/render_player.h> 
00024 #include <ardev/player.h>
00025 
00026 #include "aride_objecthandler.h"
00027 #include "aride_parameter.h"
00028 
00029 /* --------------------------------------------
00030     Player Object Handlers
00031    -------------------------------------------- */
00032 class CaptureStage;
00033 class Position3dPlayerHandler;
00034 class PositionPlayerPTZHandler;
00035 
00036 // --- PlayerClientInterfaceHandler Handler ---
00037 class PlayerClientInterfaceHandler : public ArideObjectHandler<PlayerClientInterface>
00038 {
00039         public:
00040                 PlayerClientInterfaceHandler() :
00041                         ServerName("PlayerServer","Player Server Address","localhost"),
00042                         ServerPort("PlayerPort","Player Server Port","6665")
00043                 {
00044                         PlayerInterface=NULL;
00045                         Parameters.push_back(&ServerName);
00046                         Parameters.push_back(&ServerPort);
00047                 };
00048 
00049                 virtual ~PlayerClientInterfaceHandler() {delete PlayerInterface;};
00050                         
00051                 PlayerClientInterface & GetObject() 
00052                 { 
00053                         printf("playerclient inteface handler get object called\n");
00054                         if (PlayerInterface == NULL) 
00055                         {
00056                                 PlayerInterface = new PlayerClientInterface(ServerName.Value.toAscii(), ServerPort.Value);  
00057                                 if (PlayerInterface == NULL)
00058                                         throw aride_exception(ARIDE_ALLOC_ERROR,__FUNCTION__,__LINE__);
00059                         }
00060                         theMainWindow->InitialiseObject(PlayerInterface);
00061                         return *PlayerInterface;
00062                 };
00063                 void RemoveObject() { delete PlayerInterface; PlayerInterface = NULL;};
00064 
00065                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new PlayerClientInterfaceHandler);};
00066                 
00067         protected:
00068                 StringParameter ServerName;
00069                 IntParameter ServerPort;        
00070                 PlayerClientInterface * PlayerInterface;
00071 };
00072 
00073 // --- CapturePlayer Handler ---
00074 class CapturePlayerHandler : public CaptureObjectHandler
00075 {
00076         public:
00077                 CapturePlayerHandler() :
00078                         ServerName("PlayerServer","Player Server Address","localhost"),
00079                         ServerPort("PlayerPort","Player Server Port","6665"),
00080                         CameraIndex("CameraIndex","Player Camera Index","0")
00081                 {
00082                         Parameters.push_back(&ServerName);
00083                         Parameters.push_back(&ServerPort);
00084                         Parameters.push_back(&CameraIndex);
00085                         Obj=NULL;
00086                 };
00087 
00088                 virtual ~CapturePlayerHandler() {delete Obj;};
00089                         
00090                 CaptureObject & GetObject() 
00091                 { 
00092                         if (Obj == NULL) 
00093                         {
00094                                 Obj = new CapturePlayer(ServerName.Value.toAscii(), ServerPort.Value, CameraIndex.Value);  
00095                                 if (Obj == NULL)
00096                                         throw aride_exception(ARIDE_ALLOC_ERROR,__FUNCTION__,__LINE__);
00097                         }
00098                         theMainWindow->InitialiseObject(Obj);
00099                         return *Obj;
00100                 };
00101                 void RemoveObject() { delete Obj; Obj = NULL;};
00102 
00103                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new CapturePlayerHandler);};
00104                 
00105         protected:
00106                 StringParameter ServerName;
00107                 IntParameter ServerPort;        
00108                 IntParameter CameraIndex;
00109                 CapturePlayer * Obj;
00110                 
00111 };
00112 
00113 // --- PlayerClientInterface Parameter ---
00114 class PlayerClientInterfaceParameter : public StringParameter
00115 {
00116 public: 
00117                 PlayerClientInterfaceParameter(QString _Name, QString _Description, QString _DefaultValue="") : StringParameter(_Name,_Description,_DefaultValue) {Type="PlayerClientInterface";};
00118                 virtual ~PlayerClientInterfaceParameter() {};
00119 
00120                 PlayerClientInterfaceHandler * GetClass() 
00121                 {
00122                         if (Value == "")
00123                                 throw aride_exception(ARIDE_CLASS_NOT_FOUND, __FILE__, __LINE__);
00124                         aride_object * temp = theMainWindow->GetObjectByName(Value);
00125                         if (temp == NULL)
00126                                 throw aride_exception(ARIDE_CLASS_NOT_FOUND, __FILE__, __LINE__);
00127                         if (temp->Section == ARIDE_MISC && temp->Type == "PlayerClientInterface")
00128                                 return reinterpret_cast<PlayerClientInterfaceHandler *> (temp->Handler);
00129                         throw aride_exception(ARIDE_CLASS_NOT_FOUND, __FILE__, __LINE__);
00130                 };                      
00131 
00132                 virtual void ExternalNameChange(const QString & OldName, const QString & NewName) 
00133                 {
00134                         if (Value == OldName)
00135                                 fromString(NewName);
00136                 };
00137 };
00138 
00139 // --- PlayerPosition3d Parameter ---
00140 class PlayerPosition3dParameter : public StringParameter
00141 {
00142 public: 
00143                 PlayerPosition3dParameter(QString _Name, QString _Description, QString _DefaultValue="") : StringParameter(_Name,_Description,_DefaultValue) {Type="Position3d";};
00144                 virtual ~PlayerPosition3dParameter() {};
00145 
00146                 Position3dPlayerHandler * GetClass() 
00147                 {
00148                         if (Value == "")
00149                                 throw aride_exception(ARIDE_CLASS_NOT_FOUND, __FILE__, __LINE__);
00150                         aride_object * temp = theMainWindow->GetObjectByName(Value);
00151                         if (temp == NULL)
00152                                 throw aride_exception(ARIDE_CLASS_NOT_FOUND, __FILE__, __LINE__);
00153                         if (temp->Section == ARIDE_POSITION && temp->Type == "Position3dPlayer")
00154                                 return reinterpret_cast<Position3dPlayerHandler *> (temp->Handler);
00155                         throw aride_exception(ARIDE_CLASS_NOT_FOUND, __FILE__, __LINE__);
00156                 };                              
00157 };
00158 
00159 
00160 template<class Base>
00161 class PlayerHandlerBase : public Base
00162 {
00163         public:
00164                 PlayerHandlerBase() : PlayerClient("PlayerClient","Player Client Object","playerclient")
00165                 {
00166                         Base::Parameters.push_back(&PlayerClient);
00167                 };
00168 
00169                 virtual ~PlayerHandlerBase() {};
00170         
00171         protected:
00172                 PlayerClientInterfaceParameter PlayerClient;
00173 };
00174 
00175 template <class T, class Base>
00176 class PlayerHandler : public PlayerHandlerBase<Base>
00177 {
00178         public:
00179                 PlayerHandler() {Obj=NULL;};
00180                 ~PlayerHandler() {delete Obj;};
00181         
00182                 void RemoveObject() {delete Obj; Obj=NULL;};
00183         
00184         protected:
00185                 T * Obj;
00186 };
00187 
00188 // --- Position Object Handlers ---
00189 class PositionPlayerHandler : public PlayerHandlerBase<PositionObjectHandler>
00190 {
00191         public:
00192                 PositionPlayerHandler() {Obj=NULL;};
00193                 ~PositionPlayerHandler() {delete Obj;};
00194         
00195                 PositionObject & GetObject()
00196                 {
00197                         if (Obj == NULL)
00198                         {       
00199                                 if ((Obj = new PositionPlayer(PlayerClient.GetClass()->GetObject())) == NULL)
00200                                         throw aride_exception(ARIDE_ALLOC_ERROR,__FUNCTION__,__LINE__);
00201                         }
00202 
00203                         theMainWindow->InitialiseObject(Obj);   
00204                         return *Obj;                    
00205                 }
00206         
00207                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new PositionPlayerHandler);};
00208 
00209         protected:
00210                 PositionPlayer * Obj;
00211 };
00212 
00213 class Position3dPlayerHandler : public PlayerHandlerBase<PositionObjectHandler>
00214 {
00215         public:
00216                 Position3dPlayerHandler() {Obj=NULL;};
00217                 ~Position3dPlayerHandler() {delete Obj;};
00218         
00219                 PositionObject & GetObject()
00220                 {
00221                         if (Obj == NULL)
00222                                 if ((Obj = new PositionPlayer3d(PlayerClient.GetClass()->GetObject())) == NULL)
00223                                         throw aride_exception(ARIDE_ALLOC_ERROR,__FUNCTION__,__LINE__);
00224                         
00225                         theMainWindow->InitialiseObject(Obj);
00226                         
00227                         return *Obj;                    
00228                 }
00229         
00230                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new Position3dPlayerHandler);};
00231 
00232         protected:
00233                 PositionPlayer3d * Obj;
00234                 
00235 };
00236 
00237 class PositionPlayerPTZHandler : public PlayerHandlerBase<PositionObjectHandler>
00238 {
00239         public:
00240                 PositionPlayerPTZHandler() {Obj=NULL;};
00241                 ~PositionPlayerPTZHandler() {delete Obj;};
00242         
00243                 PositionObject & GetObject()
00244                 {
00245                         if (Obj == NULL)
00246                                 if ((Obj = new PositionPlayerPTZ(PlayerClient.GetClass()->GetObject())) == NULL)
00247                                         throw aride_exception(ARIDE_ALLOC_ERROR,__FUNCTION__,__LINE__);
00248                         
00249                         theMainWindow->InitialiseObject(Obj);
00250                         
00251                         return *Obj;                    
00252                 }
00253         
00254                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new PositionPlayerPTZHandler);};
00255 
00256         protected:
00257                 PositionPlayerPTZ * Obj;
00258                 
00259 };
00260 
00261 // --- Render Object Handlers ---
00262 class RenderPlayerBumperHandler : public PlayerHandler<RenderPlayerBumper,RenderObjectHandler>
00263 {
00264         public:
00265                 RenderPlayerBumperHandler() : 
00266                         Index("Index","Interface Index","0"),
00267                         Height("Height","Bumper Panel Height","0.1")                    
00268                 {
00269                         Obj=NULL;
00270                         Parameters.push_back(&Index);
00271                         Parameters.push_back(&Height);
00272                 };
00273                 ~RenderPlayerBumperHandler() 
00274                 {
00275                         delete Obj;
00276                 };
00277 
00278                 RenderPlayerBumper & GetObject()
00279                 {
00280                         if (Obj == NULL)
00281                         {
00282                                 if ((Obj = new RenderPlayerBumper(PlayerClient.GetClass()->GetObject(),Index.Value, Height.Value)) == NULL)
00283                                         throw aride_exception(ARIDE_ALLOC_ERROR,__FUNCTION__,__LINE__);
00284                         }
00285 
00286                         theMainWindow->InitialiseObject(Obj);
00287                         BaseObject = Obj;
00288                         return *Obj;                    
00289                 };              
00290                 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00291                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderPlayerBumperHandler);};
00292 
00293         protected:
00294                 IntParameter Index;
00295                 DoubleParameter Height;
00296 };
00297 
00298 class RenderPlayerLaserHandler : public PlayerHandler<RenderPlayerLaser,RenderObjectHandler>
00299 {
00300         public:
00301                 RenderPlayerLaser & GetObject()
00302                 {
00303                         if (Obj == NULL)
00304                         {
00305                                 if ((Obj = new RenderPlayerLaser(PlayerClient.GetClass()->GetObject())) == NULL)
00306                                         throw aride_exception(ARIDE_ALLOC_ERROR,__FUNCTION__,__LINE__);
00307                         }
00308 
00309                         theMainWindow->InitialiseObject(Obj);
00310                         BaseObject = Obj;
00311                         return *Obj;                    
00312                 };              
00313                 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00314                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderPlayerLaserHandler);};
00315 
00316 };
00317 
00318 class RenderPlayerSonarHandler : public PlayerHandler<RenderPlayerSonar,RenderObjectHandler>
00319 {
00320         public:
00321                 RenderPlayerSonar & GetObject()
00322                 {
00323                         if (Obj == NULL)
00324                                 if ((Obj = new RenderPlayerSonar(PlayerClient.GetClass()->GetObject())) == NULL)
00325                                         throw aride_exception(ARIDE_ALLOC_ERROR,__FUNCTION__,__LINE__);
00326 
00327                         theMainWindow->InitialiseObject(Obj);
00328                         BaseObject = Obj;
00329                         return *Obj;                    
00330                 };              
00331                 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00332                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderPlayerSonarHandler);};
00333                 
00334 };
00335 
00336 class RenderPlayerIrHandler : public PlayerHandler<RenderPlayerIr,RenderObjectHandler>
00337 {
00338         public:
00339                 RenderPlayerIr & GetObject()
00340                 {
00341                         if (Obj == NULL)
00342                                 if ((Obj = new RenderPlayerIr(PlayerClient.GetClass()->GetObject())) == NULL)
00343                                         throw aride_exception(ARIDE_ALLOC_ERROR,__FUNCTION__,__LINE__);
00344                         
00345                         theMainWindow->InitialiseObject(Obj);
00346                         BaseObject = Obj;
00347                         return *Obj;                    
00348                 };              
00349                 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00350                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderPlayerIrHandler);};
00351 };
00352 
00353 
00354 class RenderPlayerLocaliseHandler : public PlayerHandler<RenderPlayerLocalise,RenderObjectHandler>
00355 {
00356         public:
00357                 RenderPlayerLocalise & GetObject()
00358                 {
00359                         if (Obj == NULL)
00360                                 if ((Obj = new RenderPlayerLocalise(PlayerClient.GetClass()->GetObject())) == NULL)
00361                                         throw aride_exception(ARIDE_ALLOC_ERROR,__FUNCTION__,__LINE__);
00362                         
00363                         theMainWindow->InitialiseObject(Obj);
00364                         BaseObject = Obj;
00365                         return *Obj;                    
00366                 };              
00367                 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00368                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderPlayerLocaliseHandler);};
00369 };
00370 
00371 
00372 class RenderPlayerMapHandler : public PlayerHandlerBase<RenderObjectHandler>
00373 {
00374         public:
00375                 RenderPlayerMapHandler() : Height("Height","Height of map blocks, 0 for 2d","0") {Obj=NULL;Parameters.push_back(&Height);};
00376                 ~RenderPlayerMapHandler() {delete Obj;};
00377 
00378                 RenderPlayerMap & GetObject()
00379                 {
00380                         if (Obj == NULL)
00381                                 if ((Obj = new RenderPlayerMap(PlayerClient.GetClass()->GetObject(), Height.Value)) == NULL)
00382                                         throw aride_exception(ARIDE_ALLOC_ERROR,__FUNCTION__,__LINE__);
00383                         
00384                         theMainWindow->InitialiseObject(Obj);
00385                         BaseObject = Obj;
00386                         return *Obj;                    
00387                 };              
00388                 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00389                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderPlayerMapHandler);};
00390         protected:
00391                 RenderPlayerMap * Obj;
00392                 DoubleParameter Height;
00393 };
00394 
00395 
00396 class RenderPlayerPathHandler : public PlayerHandlerBase<RenderObjectHandler>
00397 {
00398         public:
00399                 RenderPlayerPathHandler() : Colour("Colour","Path Colour","1 0 0 ") {Obj=NULL;Parameters.push_back(&Colour);};
00400                 ~RenderPlayerPathHandler() {delete Obj;};
00401         
00402                 RenderObject & GetObject()
00403                 {
00404                         if (Obj == NULL)
00405                                 if ((Obj = new RenderPlayerPath(PlayerClient.GetClass()->GetObject(),Colour.Value.x,Colour.Value.y,Colour.Value.z)) == NULL)
00406                                         throw aride_exception(ARIDE_ALLOC_ERROR,__FUNCTION__,__LINE__);
00407                         
00408                         theMainWindow->InitialiseObject(Obj);
00409                         BaseObject = Obj;
00410                         return *Obj;                    
00411                 }
00412                 
00413                 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00414                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderPlayerPathHandler);};
00415 
00416         protected:
00417                 RenderPlayerPath * Obj;
00418                 ColourParameter Colour;
00419 };
00420 
00421 class RenderPlayerPTZHandler : public PlayerHandlerBase<RenderObjectHandler>
00422 {
00423         public:
00424                 RenderPlayerPTZHandler() : 
00425                         Aspect("Aspect","Aspect Ratio","1.3333"),
00426                         FOV("FOV","FOV (deg). 0 to read from player","0")               
00427                 {Obj=NULL;Parameters.push_back(&Aspect);Parameters.push_back(&FOV);};
00428                 ~RenderPlayerPTZHandler() {delete Obj;};
00429         
00430                 RenderObject & GetObject()
00431                 {
00432                         if (Obj == NULL)
00433                                 if ((Obj = new RenderPlayerPTZ(PlayerClient.GetClass()->GetObject(),Aspect.Value, FOV.Value*M_PI/180.0)) == NULL)
00434                                         throw aride_exception(ARIDE_ALLOC_ERROR,__FUNCTION__,__LINE__);
00435                         
00436                         theMainWindow->InitialiseObject(Obj);
00437                         BaseObject = Obj;
00438                         return *Obj;                    
00439                 }
00440                 
00441                 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00442                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderPlayerPTZHandler);};
00443 
00444         protected:
00445                 RenderPlayerPTZ * Obj;
00446                 DoubleParameter Aspect;
00447                 DoubleParameter FOV;
00448 };
00449 
00450 class RenderGraphics2DHandler : public RenderObjectHandler
00451 {
00452         public:
00453                 RenderGraphics2DHandler() {Obj=NULL;};
00454                 ~RenderGraphics2DHandler() {delete Obj;};
00455         
00456                 RenderObject & GetObject()
00457                 {
00458                         if (Obj == NULL)
00459                                 if ((Obj = new Graphics2DRenderer) == NULL)
00460                                         throw aride_exception(ARIDE_ALLOC_ERROR,__FUNCTION__,__LINE__);
00461                         
00462                         theMainWindow->InitialiseObject(Obj);
00463                         BaseObject = Obj;
00464                         return *Obj;                    
00465                 }
00466                 
00467                 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00468                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderGraphics2DHandler);};
00469 
00470         protected:
00471                 Graphics2DRenderer * Obj;
00472 };
00473 
00474 // --- Capture Object Handlers ---
00475 
00476 class CaptureStageHandler : public PlayerHandlerBase<CaptureObjectHandler>
00477 {
00478         public:
00479                 CaptureStageHandler();
00480                 ~CaptureStageHandler();
00481         
00482                 CaptureObject & GetObject();
00483                 void RemoveObject();
00484         
00485                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new CaptureStageHandler);};
00486         protected:
00487                 CaptureStage * Capture;
00488                 CameraObjectParameter *CameraObject;
00489                 PositionObjectParameter *CameraPositionObject;
00490                 StringParameter *RobotName;
00491 };
00492 
00493 
00494 // ----------------------------------------------
00495 
00496 void RegisterPlayerObjectHandlers();
00497 
00498 #endif

SourceForge.net Logo Generated on Sat May 12 15:25:43 2007 for ardev by doxygen 1.5.1