00001 #include <assert.h>
00002 #include "kinematics\dh_link.h"
00003 #include "robots\r_openchain.h"
00004 #include "robots\RobotBase.h"
00005 #include "OpenGL\GL_Range_Sensor.h"
00006 #include <stdio.h>
00007
00008 RobotBase::RobotBase (FrameManager* frameManager)
00009 : Entity( frameManager )
00010 {
00011
00012 }
00013
00014 RobotBase::RobotBase (const RobotBase& right)
00015 : Entity( right )
00016 {
00017
00018 }
00019
00020
00021 RobotBase::~RobotBase()
00022 {
00023
00024 }
00025
00026
00027
00028
00029
00030 bool RobotBase::Deserialize( IfstreamWithComments& is )
00031 {
00032 return Entity::DeserializeEntity( is ) ;
00033 };
00034
00035 RobotBase* RobotBase::DeserializeAbstract (IfstreamWithComments& is, FrameManager* frameManager)
00036 {
00037 is.eatwhite() ;
00038
00039
00040 char header[ 256 ] = "" ;
00041 is.GetSolidLine( header, 256 ) ;
00042 if( stricmp( header, "#robot" ) != 0 )
00043 {
00044 ::printf( "RobotBase::DeserializeAbstract - Bad Header '%s'\n", header );
00045 ::printf( "RobotBase::DeserializeAbstract - header length %d'\n", strlen( header ) );
00046 return NULL ;
00047 }
00048
00049
00050 char robotType[ 256 ] = "" ;
00051 is.GetSolidLine( robotType, 256 ) ;
00052
00053
00054 RobotBase* robot = NULL ;
00055 if( stricmp( robotType, "#r_open_chain" ) == 0 )
00056 {
00057 robot = new R_OpenChain( frameManager ) ;
00058 }
00059 else
00060 {
00061 bool undefindedRobotType = false ;
00062 assert( undefindedRobotType ) ;
00063 }
00064 if (robot->Deserialize( is ) == false)
00065 {
00066 delete robot;
00067 return NULL;
00068 }
00069
00071 eatwhite( is ) ;
00072 is.getline( robotType, 300, ' ' ) ;
00073 assert( strcmp( robotType, "#cameras" ) == 0 ) ;
00074 int numcameras = -1 ;
00075 is >> numcameras ;
00076
00077 for (int i = 0; i < numcameras; i++)
00078 {
00079 GL_Range_Sensor* camera = NULL ;
00080 eatwhite( is ) ;
00081 is.getline( robotType, 300 ) ;
00082 if( stricmp( robotType, "#camera_jonathan" ) == 0 )
00083 {
00084 camera = new GL_Range_Sensor( frameManager ) ;
00085 }
00086 else
00087 {
00088 bool undefindedRobotType = false ;
00089 assert( undefindedRobotType ) ;
00090 }
00091 camera->Deserialize( is );
00092 std::list< LinkBase*> links = robot->GetAllLinks() ;
00093 std::list< LinkBase*>::iterator it = links.begin() ;
00094 int linknum = camera->BaseFrame() ;
00095
00096 for( int j = 0; j < linknum; j++ )
00097 {
00098 it++ ;
00099 }
00100 LinkBase* theLink = *it ;
00101 DH_Link* dhLink = dynamic_cast< DH_Link* >( theLink ) ;
00102 assert( dhLink != NULL ) ;
00103 dhLink->AddObject( camera ) ;
00104 delete camera;
00105 }
00106
00107 return robot ;
00108 }
00109
00110
00111
00112
00113