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 "COLLADASaxFWLIFilePartLoader.h" 13 #include "COLLADASaxFWLLoader.h" 14 #include "COLLADASaxFWLFileLoader.h" 15 #include "COLLADASaxFWLIErrorHandler.h" 16 #include "COLLADASaxFWLIParserImpl.h" 17 #include "COLLADASaxFWLIParserImpl14.h" 18 #include "COLLADASaxFWLIParserImpl15.h" 19 #include "COLLADASaxFWLIExtraDataCallbackHandler.h" 20 21 22 namespace COLLADASaxFWL 23 { 24 25 //------------------------------ IFilePartLoader()26 IFilePartLoader::IFilePartLoader () 27 : mPartLoader(0) 28 , mParserImpl(0) 29 { 30 } 31 32 //------------------------------ ~IFilePartLoader()33 IFilePartLoader::~IFilePartLoader() 34 { 35 deleteFilePartLoader(); 36 if ( mParserImpl ) 37 { 38 delete mParserImpl; 39 mParserImpl = 0; 40 } 41 } 42 43 //----------------------------- writer()44 COLLADAFW::IWriter* IFilePartLoader::writer() 45 { 46 return getColladaLoader()->writer(); 47 } 48 49 //----------------------------- createUniqueId(const String & uriString,COLLADAFW::ClassId classId)50 const COLLADAFW::UniqueId& IFilePartLoader::createUniqueId( const String& uriString, COLLADAFW::ClassId classId ) 51 { 52 COLLADABU_ASSERT( getColladaLoader() ); 53 54 COLLADABU::URI uri(getFileUri(), uriString); 55 56 return getColladaLoader()->getUniqueId(uri, classId); 57 } 58 59 //----------------------------- getUniqueIdByUrl(const String & uriString)60 const COLLADAFW::UniqueId& IFilePartLoader::getUniqueIdByUrl( const String& uriString) 61 { 62 COLLADABU_ASSERT( getColladaLoader() ); 63 64 COLLADABU::URI uri(getFileUri(), uriString); 65 66 return getColladaLoader()->getUniqueId(uri); 67 } 68 69 //----------------------------- createUniqueIdFromId(const ParserChar * colladaId,COLLADAFW::ClassId classId)70 COLLADAFW::UniqueId IFilePartLoader::createUniqueIdFromId( const ParserChar* colladaId, COLLADAFW::ClassId classId ) 71 { 72 COLLADABU_ASSERT( getColladaLoader() ); 73 74 if ( !colladaId || !(*colladaId) ) 75 return createUniqueId(classId); 76 77 COLLADABU::URI uri(getFileUri(), String("#") + String((const char *)colladaId)); 78 79 COLLADAFW::UniqueId createdUniqueId = createUniqueIdFromUrl(uri, classId, true); 80 return createdUniqueId; 81 } 82 83 //------------------------------ getUniqueIdById(const ParserChar * colladaId)84 const COLLADAFW::UniqueId& IFilePartLoader::getUniqueIdById( const ParserChar* colladaId ) 85 { 86 COLLADABU_ASSERT( getColladaLoader() ); 87 88 if ( !colladaId || !(*colladaId) ) 89 return COLLADAFW::UniqueId::INVALID; 90 91 COLLADABU::URI uri(getFileUri(), String("#") + String((const char *)colladaId)); 92 93 return getColladaLoader()->getUniqueId(uri); 94 } 95 96 97 //----------------------------- createUniqueIdFromUrl(const ParserChar * url,COLLADAFW::ClassId classId)98 const COLLADAFW::UniqueId& IFilePartLoader::createUniqueIdFromUrl( const ParserChar* url, COLLADAFW::ClassId classId ) 99 { 100 COLLADABU_ASSERT( getColladaLoader() ); 101 if ( !url || !(*url) ) 102 return COLLADAFW::UniqueId::INVALID; 103 104 COLLADABU::URI uri(getFileUri(), String((const char *)url)); 105 106 return getColladaLoader()->getUniqueId(uri, classId); 107 } 108 109 //----------------------------- createUniqueIdFromUrl(const COLLADABU::URI & url,COLLADAFW::ClassId classId,bool isAbsolute)110 const COLLADAFW::UniqueId& IFilePartLoader::createUniqueIdFromUrl( const COLLADABU::URI& url, COLLADAFW::ClassId classId, bool isAbsolute ) 111 { 112 COLLADABU_ASSERT( getColladaLoader() ); 113 114 if ( isAbsolute ) 115 { 116 return getColladaLoader()->getUniqueId(url, classId); 117 } 118 else 119 { 120 COLLADABU::URI absoluteUri(getFileUri(), url.getURIString()); 121 122 return getColladaLoader()->getUniqueId(absoluteUri, classId); 123 } 124 } 125 126 //----------------------------- getUniqueIdByUrl(const COLLADABU::URI & url,bool isAbsolute)127 const COLLADAFW::UniqueId& IFilePartLoader::getUniqueIdByUrl( const COLLADABU::URI& url, bool isAbsolute ) 128 { 129 COLLADABU_ASSERT( getColladaLoader() ); 130 131 if ( isAbsolute ) 132 { 133 return getColladaLoader()->getUniqueId(url); 134 } 135 else 136 { 137 COLLADABU::URI absoluteUri(getFileUri(), url.getURIString()); 138 139 return getColladaLoader()->getUniqueId(absoluteUri); 140 } 141 } 142 143 144 //----------------------------- createUniqueId(COLLADAFW::ClassId classId)145 COLLADAFW::UniqueId IFilePartLoader::createUniqueId( COLLADAFW::ClassId classId ) 146 { 147 COLLADABU_ASSERT( getColladaLoader() ); 148 return getColladaLoader()->getUniqueId(classId); 149 } 150 151 //----------------------------- deleteFilePartLoader()152 void IFilePartLoader::deleteFilePartLoader() 153 { 154 if ( mPartLoader ) 155 { 156 delete mPartLoader; 157 mPartLoader = 0; 158 } 159 } 160 161 //------------------------------ setMeAsParser()162 void IFilePartLoader::setMeAsParser() 163 { 164 COLLADABU_ASSERT(mParserImpl); 165 switch ( mParserImpl->getCOLLADAVersion() ) 166 { 167 case COLLADA_14: 168 { 169 IParserImpl14* impl14 = (IParserImpl14*)mParserImpl; 170 setParser( impl14->getGeneratedParser() ); 171 break; 172 } 173 case COLLADA_15: 174 { 175 IParserImpl15* impl15 = (IParserImpl15*)mParserImpl; 176 setParser( impl15->getGeneratedParser() ); 177 break; 178 } 179 default: 180 break; 181 } 182 } 183 184 //------------------------------ getMeshMaterialIdInfo()185 GeometryMaterialIdInfo& IFilePartLoader::getMeshMaterialIdInfo( ) 186 { 187 COLLADABU_ASSERT(getColladaLoader()); 188 return getColladaLoader()->getMeshMaterialIdInfo(); 189 } 190 191 //------------------------------ getTextureMapIdBySematic(const String & semantic)192 COLLADAFW::TextureMapId IFilePartLoader::getTextureMapIdBySematic( const String& semantic ) 193 { 194 COLLADABU_ASSERT( getColladaLoader() ); 195 return getColladaLoader()->getTextureMapIdBySematic(semantic); 196 } 197 198 //------------------------------ addToSidTree(const char * colladaId,const char * colladaSid)199 SidTreeNode* IFilePartLoader::addToSidTree( const char* colladaId, const char* colladaSid ) 200 { 201 return getFileLoader()->addToSidTree( colladaId, colladaSid ); 202 } 203 204 //------------------------------ addToSidTree(const char * colladaId,const char * colladaSid,COLLADAFW::Object * target)205 SidTreeNode* IFilePartLoader::addToSidTree( const char* colladaId, const char* colladaSid, COLLADAFW::Object* target ) 206 { 207 return getFileLoader()->addToSidTree( colladaId, colladaSid, target ); 208 } 209 210 //------------------------------ addToSidTree(const char * colladaId,const char * colladaSid,COLLADAFW::Animatable * target)211 SidTreeNode* IFilePartLoader::addToSidTree( const char* colladaId, const char* colladaSid, COLLADAFW::Animatable* target ) 212 { 213 return getFileLoader()->addToSidTree( colladaId, colladaSid, target ); 214 } 215 216 //------------------------------ addToSidTree(const char * colladaId,const char * colladaSid,IntermediateTargetable * target)217 SidTreeNode* IFilePartLoader::addToSidTree( const char* colladaId, const char* colladaSid, IntermediateTargetable* target ) 218 { 219 return getFileLoader()->addToSidTree( colladaId, colladaSid, target ); 220 } 221 222 //------------------------------ moveUpInSidTree()223 void IFilePartLoader::moveUpInSidTree() 224 { 225 getFileLoader()->moveUpInSidTree(); 226 } 227 228 //------------------------------ resolveSid(const SidAddress & sidAddress)229 const SidTreeNode* IFilePartLoader::resolveSid( const SidAddress& sidAddress ) 230 { 231 return getFileLoader()->resolveSid(sidAddress); 232 } 233 234 //------------------------------ addToAnimationSidAddressBindings(const AnimationInfo & animationInfo,const SidAddress & targetSidAddress)235 void IFilePartLoader::addToAnimationSidAddressBindings( const AnimationInfo& animationInfo, const SidAddress& targetSidAddress ) 236 { 237 getFileLoader()->addToAnimationSidAddressBindings( animationInfo, targetSidAddress ); 238 } 239 240 //------------------------------ getAnimationListByUniqueId(const COLLADAFW::UniqueId & animationListUniqueId)241 COLLADAFW::AnimationList*& IFilePartLoader::getAnimationListByUniqueId( const COLLADAFW::UniqueId& animationListUniqueId ) 242 { 243 return getFileLoader()->getAnimationListByUniqueId( animationListUniqueId ); 244 } 245 246 //----------------------------- addSkinDataJointSidsPair(const COLLADAFW::UniqueId & skinDataUniqueId,const StringList & sidsOrIds,bool areIds)247 void IFilePartLoader::addSkinDataJointSidsPair( const COLLADAFW::UniqueId& skinDataUniqueId, const StringList& sidsOrIds, bool areIds ) 248 { 249 getFileLoader()->addSkinDataJointSidsPair( skinDataUniqueId, sidsOrIds, areIds ); 250 } 251 252 //----------------------------- addSkinDataSkinSourcePair(const COLLADAFW::UniqueId & skinDataUniqueId,const COLLADABU::URI & skinSource)253 void IFilePartLoader::addSkinDataSkinSourcePair( const COLLADAFW::UniqueId& skinDataUniqueId, const COLLADABU::URI& skinSource ) 254 { 255 getFileLoader()->addSkinDataSkinSourcePair( skinDataUniqueId, skinSource ); 256 } 257 258 //----------------------------- addMorphController(COLLADAFW::MorphController * morphController)259 void IFilePartLoader::addMorphController( COLLADAFW::MorphController* morphController ) 260 { 261 getColladaLoader()->getMorphControllerList().push_back(morphController); 262 } 263 264 //----------------------------- getJointSidsOrIdsBySkinDataUniqueId(const COLLADAFW::UniqueId & skinDataUniqueId) const265 const Loader::JointSidsOrIds& IFilePartLoader::getJointSidsOrIdsBySkinDataUniqueId( const COLLADAFW::UniqueId& skinDataUniqueId ) const 266 { 267 return getFileLoader()->getJointSidsOrIdsBySkinDataUniqueId( skinDataUniqueId ); 268 } 269 270 //------------------------------ getInstanceControllerDataListMap() const271 const Loader::InstanceControllerDataListMap& IFilePartLoader::getInstanceControllerDataListMap() const 272 { 273 return getFileLoader()->getInstanceControllerDataListMap(); 274 } 275 276 //------------------------------ getInstanceControllerDataListByControllerUniqueId(const COLLADAFW::UniqueId & controllerUniqueId) const277 const Loader::InstanceControllerDataList& IFilePartLoader::getInstanceControllerDataListByControllerUniqueId( const COLLADAFW::UniqueId& controllerUniqueId ) const 278 { 279 return getFileLoader()->getInstanceControllerDataListByControllerUniqueId(controllerUniqueId); 280 } 281 282 //------------------------------ getInstanceControllerDataListByControllerUniqueId(const COLLADAFW::UniqueId & controllerUniqueId)283 Loader::InstanceControllerDataList& IFilePartLoader::getInstanceControllerDataListByControllerUniqueId( const COLLADAFW::UniqueId& controllerUniqueId ) 284 { 285 return getFileLoader()->getInstanceControllerDataListByControllerUniqueId(controllerUniqueId); 286 } 287 288 //------------------------------ begin__technique(const technique__AttributeData & attributeData)289 bool IFilePartLoader::begin__technique( const technique__AttributeData& attributeData ) 290 { 291 //SaxVirtualFunctionTest(begin__technique(attributeData)) 292 return getFileLoader()->base__begin__technique( attributeData, getUniqueId(), getObject() ); 293 } 294 295 //------------------------------ end__technique()296 bool IFilePartLoader::end__technique() 297 { 298 return true; 299 } 300 301 //------------------------------ handleFWLError(const SaxFWLError & saxFWLError)302 bool IFilePartLoader::handleFWLError( const SaxFWLError& saxFWLError ) 303 { 304 IErrorHandler* errorHandler = getColladaLoader()->getErrorHandler(); 305 bool stopParsing = false; 306 if ( errorHandler ) 307 { 308 stopParsing = errorHandler->handleError( &saxFWLError ); 309 } 310 return (saxFWLError.getSeverity() == IError::SEVERITY_CRITICAL) ? true : stopParsing; 311 } 312 313 //------------------------------ handleFWLError(SaxFWLError::ErrorType errorType,String errorMessage,IError::Severity severity)314 bool IFilePartLoader::handleFWLError( SaxFWLError::ErrorType errorType, String errorMessage, IError::Severity severity /*= IError::SEVERITY_ERROR_NONCRITICAL */ ) 315 { 316 SaxFWLError saxFWLError(errorType, errorMessage, severity); 317 if ( getFileLoader() && (getFileLoader()->getParsingStatus() == FileLoader::PARSING_PARSING) ) 318 { 319 const GeneratedSaxParser::SaxParser* saxParser = getFileLoader()->getSaxParser(); 320 if ( saxParser ) 321 { 322 saxFWLError.setLineNumber( saxParser->getLineNumer() ); 323 saxFWLError.setColumnNumber( saxParser->getColumnNumer() ); 324 } 325 } 326 return handleFWLError( saxFWLError ); 327 } 328 329 } // namespace COLLADASaxFWL 330