1 /* 2 Copyright (c) 2008-2009 NetAllied Systems GmbH 3 4 This file is part of COLLADASaxFrameworkLoader. 5 6 Licensed under the MIT Open Source License, 7 for details please see LICENSE file or the website 8 http://www.opensource.org/licenses/mit-license.php 9 */ 10 11 #include "COLLADASaxFWLStableHeaders.h" 12 #include "COLLADASaxFWLLibraryArticulatedSystemsLoader.h" 13 #include "COLLADASaxFWLKinematicsIntermediateData.h" 14 #include "COLLADASaxFWLFileLoader.h" 15 16 17 namespace COLLADASaxFWL 18 { 19 20 //------------------------------ LibraryArticulatedSystemsLoader(IFilePartLoader * callingFilePartLoader)21 LibraryArticulatedSystemsLoader::LibraryArticulatedSystemsLoader( IFilePartLoader* callingFilePartLoader ) 22 : FilePartLoader(callingFilePartLoader) 23 , mCurrentKinematicsController(0) 24 , mValueElementParentType(VALUE_ELEMENT_NONE) 25 , mCurrentAxisInfo(0) 26 { 27 28 } 29 30 //------------------------------ ~LibraryArticulatedSystemsLoader()31 LibraryArticulatedSystemsLoader::~LibraryArticulatedSystemsLoader() 32 { 33 } 34 35 //------------------------------ getUniqueId()36 const COLLADAFW::UniqueId& LibraryArticulatedSystemsLoader::getUniqueId () 37 { 38 // TODO No uniqueId! 39 return COLLADAFW::UniqueId::INVALID; 40 } 41 42 //------------------------------ end__library_articulated_systems()43 bool LibraryArticulatedSystemsLoader::end__library_articulated_systems() 44 { 45 moveUpInSidTree(); 46 finish(); 47 return true; 48 } 49 50 //------------------------------ begin__articulated_system(const articulated_system__AttributeData & attributeData)51 bool LibraryArticulatedSystemsLoader::begin__articulated_system( const articulated_system__AttributeData& attributeData ) 52 { 53 if ( attributeData.id ) 54 { 55 mCurrentArticulatedId = attributeData.id; 56 } 57 if ( attributeData.name ) 58 { 59 mCurrentArticulatedName = attributeData.name; 60 } 61 else if ( attributeData.id ) 62 { 63 mCurrentArticulatedName = attributeData.id; 64 } 65 66 addToSidTree( attributeData.id, 0); 67 return true; 68 } 69 70 //------------------------------ end__articulated_system()71 bool LibraryArticulatedSystemsLoader::end__articulated_system() 72 { 73 mCurrentArticulatedId.clear(); 74 mCurrentArticulatedName.clear(); 75 moveUpInSidTree(); 76 return true; 77 } 78 79 //------------------------------ begin__kinematics()80 bool LibraryArticulatedSystemsLoader::begin__kinematics() 81 { 82 COLLADABU::URI uri(getFileUri()); 83 uri.setFragment( mCurrentArticulatedId ); 84 mCurrentKinematicsController = new KinematicsController( uri, mCurrentArticulatedName ); 85 return true; 86 } 87 88 //------------------------------ end__kinematics()89 bool LibraryArticulatedSystemsLoader::end__kinematics() 90 { 91 getFileLoader()->addKinematicsController(mCurrentKinematicsController); 92 mCurrentKinematicsController = 0; 93 return true; 94 } 95 96 //------------------------------ begin__instance_kinematics_model(const instance_kinematics_model__AttributeData & attributeData)97 bool LibraryArticulatedSystemsLoader::begin__instance_kinematics_model( const instance_kinematics_model__AttributeData& attributeData ) 98 { 99 KinematicsInstanceKinematicsModels& instanceKinematicsModels = mCurrentKinematicsController->getKinematicsInstanceKinematicsModels(); 100 COLLADABU::URI absoluteUrl(getFileUri(), attributeData.url.getURIString()); 101 instanceKinematicsModels.push_back(KinematicsInstanceKinematicsModel(absoluteUrl)); 102 KinematicsInstanceKinematicsModel * instanceKinematicsModel = &instanceKinematicsModels.back(); 103 addToSidTree( 0, attributeData.sid, instanceKinematicsModel); 104 mInstanceKinematicsModelLoader.setCurrentInstanceKinematicsModel(instanceKinematicsModel); 105 return true; 106 } 107 108 //------------------------------ end__instance_kinematics_model()109 bool LibraryArticulatedSystemsLoader::end__instance_kinematics_model() 110 { 111 moveUpInSidTree(); 112 return true; 113 } 114 115 //------------------------------ begin__newparam____kinematics_newparam_type(const newparam____kinematics_newparam_type__AttributeData & attributeData)116 bool LibraryArticulatedSystemsLoader::begin__newparam____kinematics_newparam_type( const newparam____kinematics_newparam_type__AttributeData& attributeData ) 117 { 118 mValueElementParentType = VALUE_ELEMENT_NEWPARAM; 119 return mInstanceKinematicsModelLoader.begin__newparam____kinematics_newparam_type(attributeData); 120 } 121 122 //------------------------------ end__newparam____kinematics_newparam_type()123 bool LibraryArticulatedSystemsLoader::end__newparam____kinematics_newparam_type() 124 { 125 mValueElementParentType = VALUE_ELEMENT_NONE; 126 return mInstanceKinematicsModelLoader.end__newparam____kinematics_newparam_type(); 127 } 128 129 //----------------------------------------------------------------- begin__float()130 bool LibraryArticulatedSystemsLoader::begin__float() 131 { 132 if ( mValueElementParentType == VALUE_ELEMENT_NEWPARAM ) 133 { 134 return mInstanceKinematicsModelLoader.begin__float(); 135 } 136 return true; 137 } 138 139 //----------------------------------------------------------------- end__float()140 bool LibraryArticulatedSystemsLoader::end__float() 141 { 142 return mInstanceKinematicsModelLoader.end__float(); 143 } 144 145 //----------------------------------------------------------------- data__float(float value)146 bool LibraryArticulatedSystemsLoader::data__float( float value ) 147 { 148 if ( mValueElementParentType == VALUE_ELEMENT_NEWPARAM ) 149 { 150 mInstanceKinematicsModelLoader.data__float(value); 151 } 152 return true; 153 } 154 155 //----------------------------------------------------------------- begin__int()156 bool LibraryArticulatedSystemsLoader::begin__int() 157 { 158 if ( mValueElementParentType == VALUE_ELEMENT_NEWPARAM ) 159 { 160 mInstanceKinematicsModelLoader.begin__int(); 161 } 162 return true; 163 } 164 165 //----------------------------------------------------------------- end__int()166 bool LibraryArticulatedSystemsLoader::end__int() 167 { 168 mInstanceKinematicsModelLoader.end__int(); 169 return true; 170 } 171 172 //----------------------------------------------------------------- data__int(int value)173 bool LibraryArticulatedSystemsLoader::data__int( int value ) 174 { 175 switch ( mValueElementParentType ) 176 { 177 case VALUE_ELEMENT_NEWPARAM: 178 { 179 mInstanceKinematicsModelLoader.data__int(value); 180 break; 181 } 182 case VALUE_ELEMENT_INDEX: 183 { 184 mCurrentAxisInfo->setIndex(value); 185 break; 186 } 187 default: 188 break; 189 } 190 return true; 191 } 192 193 //----------------------------------------------------------------- begin__bool()194 bool LibraryArticulatedSystemsLoader::begin__bool() 195 { 196 if ( mValueElementParentType == VALUE_ELEMENT_NEWPARAM ) 197 { 198 mInstanceKinematicsModelLoader.begin__bool(); 199 } 200 return true; 201 } 202 203 //----------------------------------------------------------------- end__bool()204 bool LibraryArticulatedSystemsLoader::end__bool() 205 { 206 mInstanceKinematicsModelLoader.end__bool(); 207 return true; 208 } 209 210 //----------------------------------------------------------------- data__bool(bool value)211 bool LibraryArticulatedSystemsLoader::data__bool( bool value ) 212 { 213 switch ( mValueElementParentType ) 214 { 215 case VALUE_ELEMENT_NEWPARAM: 216 { 217 mInstanceKinematicsModelLoader.data__bool(value); 218 break; 219 } 220 case VALUE_ELEMENT_AKTIVE: 221 { 222 mCurrentAxisInfo->setIsActive(value); 223 break; 224 } 225 case VALUE_ELEMENT_LOCKED: 226 { 227 mCurrentAxisInfo->setIsLocked(value); 228 break; 229 } 230 default: 231 break; 232 } 233 return true; 234 } 235 236 //----------------------------------------------------------------- begin__SIDREF()237 bool LibraryArticulatedSystemsLoader::begin__SIDREF() 238 { 239 if ( mValueElementParentType == VALUE_ELEMENT_NEWPARAM ) 240 { 241 mInstanceKinematicsModelLoader.begin__SIDREF(); 242 } 243 return true; 244 } 245 246 //----------------------------------------------------------------- end__SIDREF()247 bool LibraryArticulatedSystemsLoader::end__SIDREF() 248 { 249 if ( mValueElementParentType == VALUE_ELEMENT_NEWPARAM ) 250 { 251 mInstanceKinematicsModelLoader.end__SIDREF(); 252 } 253 return true; 254 } 255 256 //----------------------------------------------------------------- data__SIDREF(const ParserChar * value,size_t length)257 bool LibraryArticulatedSystemsLoader::data__SIDREF( const ParserChar* value, size_t length ) 258 { 259 mInstanceKinematicsModelLoader.data__SIDREF(value, length); 260 return true; 261 } 262 263 //----------------------------------------------------------------- begin__axis_info____kinematics_axis_info_type(const axis_info____kinematics_axis_info_type__AttributeData & attributeData)264 bool LibraryArticulatedSystemsLoader::begin__axis_info____kinematics_axis_info_type( const axis_info____kinematics_axis_info_type__AttributeData& attributeData ) 265 { 266 if ( attributeData.axis ) 267 { 268 mCurrentKinematicsController->getAxisInfos().push_back(AxisInfo(SidAddress(String(attributeData.axis)))); 269 mCurrentAxisInfo = &mCurrentKinematicsController->getAxisInfos().back(); 270 addToSidTree( 0, attributeData.sid ); 271 } 272 return true; 273 } 274 275 //----------------------------------------------------------------- end__axis_info____kinematics_axis_info_type()276 bool LibraryArticulatedSystemsLoader::end__axis_info____kinematics_axis_info_type() 277 { 278 if ( mCurrentAxisInfo ) 279 { 280 moveUpInSidTree(); 281 } 282 mCurrentAxisInfo = 0; 283 return true; 284 } 285 286 //----------------------------------------------------------------- begin__active()287 bool LibraryArticulatedSystemsLoader::begin__active() 288 { 289 if ( mCurrentAxisInfo ) 290 { 291 mValueElementParentType = VALUE_ELEMENT_AKTIVE; 292 } 293 return true; 294 } 295 296 //----------------------------------------------------------------- end__active()297 bool LibraryArticulatedSystemsLoader::end__active() 298 { 299 mValueElementParentType = VALUE_ELEMENT_NONE; 300 return true; 301 } 302 303 //----------------------------------------------------------------- begin__locked()304 bool LibraryArticulatedSystemsLoader::begin__locked() 305 { 306 if ( mCurrentAxisInfo ) 307 { 308 mValueElementParentType = VALUE_ELEMENT_LOCKED; 309 } 310 return true; 311 } 312 313 //----------------------------------------------------------------- end__locked()314 bool LibraryArticulatedSystemsLoader::end__locked() 315 { 316 mValueElementParentType = VALUE_ELEMENT_NONE; 317 return true; 318 } 319 320 //----------------------------------------------------------------- begin__index(const index__AttributeData & attributeData)321 bool LibraryArticulatedSystemsLoader::begin__index( const index__AttributeData& attributeData ) 322 { 323 if ( mCurrentAxisInfo ) 324 { 325 mValueElementParentType = VALUE_ELEMENT_INDEX; 326 } 327 return true; 328 } 329 330 //----------------------------------------------------------------- end__index()331 bool LibraryArticulatedSystemsLoader::end__index() 332 { 333 mValueElementParentType = VALUE_ELEMENT_NONE; 334 return true; 335 } 336 337 338 } // namespace COLLADASaxFWL 339