Modif dans le parsing IFC suppressions des espaces avant traitement de la chaine

pull/261/head
guillaume 2014-01-15 17:12:04 +01:00 committed by Léo Terziman
parent e6c5095e5b
commit 8267d93537
5 changed files with 1215 additions and 1251 deletions

View File

@ -192,24 +192,17 @@ void IFCImporter::InternReadFile( const std::string& pFile,
} }
// search file (same name as the IFCZIP except for the file extension) and place file pointer there // search file (same name as the IFCZIP except for the file extension) and place file pointer there
if(UNZ_OK == unzGoToFirstFile(zip)) { if(UNZ_OK == unzGoToFirstFile(zip)) {
do { do {
//
// get file size, etc. // get file size, etc.
unz_file_info fileInfo; unz_file_info fileInfo;
char filename[256]; char filename[256];
unzGetCurrentFileInfo( zip , &fileInfo, filename, sizeof(filename), 0, 0, 0, 0 ); unzGetCurrentFileInfo( zip , &fileInfo, filename, sizeof(filename), 0, 0, 0, 0 );
if (GetExtension(filename) != "ifc") { if (GetExtension(filename) != "ifc") {
continue; continue;
} }
uint8_t* buff = new uint8_t[fileInfo.uncompressed_size]; uint8_t* buff = new uint8_t[fileInfo.uncompressed_size];
LogInfo("Decompressing IFCZIP file"); LogInfo("Decompressing IFCZIP file");
unzOpenCurrentFile( zip ); unzOpenCurrentFile( zip );
const int ret = unzReadCurrentFile( zip, buff, fileInfo.uncompressed_size); const int ret = unzReadCurrentFile( zip, buff, fileInfo.uncompressed_size);
size_t filesize = fileInfo.uncompressed_size; size_t filesize = fileInfo.uncompressed_size;
@ -271,7 +264,6 @@ void IFCImporter::InternReadFile( const std::string& pFile,
// feed the IFC schema into the reader and pre-parse all lines // feed the IFC schema into the reader and pre-parse all lines
STEP::ReadFile(*db, schema, types_to_track, inverse_indices_to_track); STEP::ReadFile(*db, schema, types_to_track, inverse_indices_to_track);
const STEP::LazyObject* proj = db->GetObject("ifcproject"); const STEP::LazyObject* proj = db->GetObject("ifcproject");
if (!proj) { if (!proj) {
ThrowException("missing IfcProject entity"); ThrowException("missing IfcProject entity");
@ -287,9 +279,9 @@ void IFCImporter::InternReadFile( const std::string& pFile,
// in a build with no entities disabled. See // in a build with no entities disabled. See
// scripts/IFCImporter/CPPGenerator.py // scripts/IFCImporter/CPPGenerator.py
// for more information. // for more information.
#ifdef ASSIMP_IFC_TEST #ifdef ASSIMP_IFC_TEST
db->EvaluateAll(); db->EvaluateAll();
#endif #endif
// do final data copying // do final data copying
if (conv.meshes.size()) { if (conv.meshes.size()) {
@ -565,21 +557,16 @@ void ProcessProductRepresentation(const IfcProduct& el, aiNode* nd, std::vector<
if(!el.Representation) { if(!el.Representation) {
return; return;
} }
std::vector<unsigned int> meshes; std::vector<unsigned int> meshes;
// we want only one representation type, so bring them in a suitable order (i.e try those // we want only one representation type, so bring them in a suitable order (i.e try those
// that look as if we could read them quickly at first). This way of reading // that look as if we could read them quickly at first). This way of reading
// representation is relatively generic and allows the concrete implementations // representation is relatively generic and allows the concrete implementations
// for the different representation types to make some sensible choices what // for the different representation types to make some sensible choices what
// to load and what not to load. // to load and what not to load.
const STEP::ListOf< STEP::Lazy< IfcRepresentation >, 1, 0 >& src = el.Representation.Get()->Representations; const STEP::ListOf< STEP::Lazy< IfcRepresentation >, 1, 0 >& src = el.Representation.Get()->Representations;
std::vector<const IfcRepresentation*> repr_ordered(src.size()); std::vector<const IfcRepresentation*> repr_ordered(src.size());
std::copy(src.begin(),src.end(),repr_ordered.begin()); std::copy(src.begin(),src.end(),repr_ordered.begin());
std::sort(repr_ordered.begin(),repr_ordered.end(),RateRepresentationPredicate()); std::sort(repr_ordered.begin(),repr_ordered.end(),RateRepresentationPredicate());
BOOST_FOREACH(const IfcRepresentation* repr, repr_ordered) { BOOST_FOREACH(const IfcRepresentation* repr, repr_ordered) {
bool res = false; bool res = false;
BOOST_FOREACH(const IfcRepresentationItem& item, repr->Items) { BOOST_FOREACH(const IfcRepresentationItem& item, repr->Items) {
@ -595,7 +582,6 @@ void ProcessProductRepresentation(const IfcProduct& el, aiNode* nd, std::vector<
break; break;
} }
} }
AssignAddedMeshes(meshes,nd,conv); AssignAddedMeshes(meshes,nd,conv);
} }

View File

@ -103,13 +103,10 @@ public:
swallow = false; swallow = false;
return *this; return *this;
} }
if (!*this) { if (!*this) {
throw std::logic_error("End of file, no more lines to be retrieved."); throw std::logic_error("End of file, no more lines to be retrieved.");
} }
char s; char s;
cur.clear(); cur.clear();
while(stream.GetRemainingSize() && (s = stream.GetI1(),1)) { while(stream.GetRemainingSize() && (s = stream.GetI1(),1)) {
if (s == '\n' || s == '\r') { if (s == '\n' || s == '\r') {
@ -124,7 +121,6 @@ public:
if (stream.GetRemainingSize() && (s == '\r' && stream.GetI1() != '\n')) { if (stream.GetRemainingSize() && (s == '\r' && stream.GetI1() != '\n')) {
stream.IncPtr(-1); stream.IncPtr(-1);
} }
if (trim) { if (trim) {
while (stream.GetRemainingSize() && ((s = stream.GetI1()) == ' ' || s == '\t')); while (stream.GetRemainingSize() && ((s = stream.GetI1()) == ' ' || s == '\t'));
if (stream.GetRemainingSize()) { if (stream.GetRemainingSize()) {
@ -132,12 +128,10 @@ public:
} }
} }
} }
break; break;
} }
cur += s; cur += s;
} }
++idx; ++idx;
return *this; return *this;
} }
@ -174,7 +168,9 @@ public:
SkipSpaces(&s); SkipSpaces(&s);
for(size_t i = 0; i < N; ++i) { for(size_t i = 0; i < N; ++i) {
if(IsLineEnd(*s)) { if(IsLineEnd(*s)) {
throw std::range_error("Token count out of range, EOL reached"); throw std::range_error("Token count out of range, EOL reached");
} }
tokens[i] = s; tokens[i] = s;

View File

@ -175,7 +175,7 @@ bool IsEntityDef(const std::string& snext)
if (*it == '=') { if (*it == '=') {
return true; return true;
} }
if (*it < '0' || *it > '9') { if ((*it < '0' || *it > '9') && *it != ' ') {
break; break;
} }
} }
@ -197,16 +197,17 @@ void STEP::ReadFile(DB& db,const EXPRESS::ConversionSchema& scheme,
const DB::ObjectMap& map = db.GetObjects(); const DB::ObjectMap& map = db.GetObjects();
LineSplitter& splitter = db.GetSplitter(); LineSplitter& splitter = db.GetSplitter();
while (splitter) { while (splitter) {
bool has_next = false; bool has_next = false;
std::string s = *splitter; std::string s = *splitter;
if (s == "ENDSEC;") { if (s == "ENDSEC;") {
break; break;
} }
s.erase(std::remove(s.begin(), s.end(), ' '), s.end());
// want one-based line numbers for human readers, so +1 // want one-based line numbers for human readers, so +1
const uint64_t line = splitter.get_index()+1; const uint64_t line = splitter.get_index()+1;
// LineSplitter already ignores empty lines // LineSplitter already ignores empty lines
ai_assert(s.length()); ai_assert(s.length());
if (s[0] != '#') { if (s[0] != '#') {
@ -214,12 +215,10 @@ void STEP::ReadFile(DB& db,const EXPRESS::ConversionSchema& scheme,
++splitter; ++splitter;
continue; continue;
} }
// --- // ---
// extract id, entity class name and argument string, // extract id, entity class name and argument string,
// but don't create the actual object yet. // but don't create the actual object yet.
// --- // ---
const std::string::size_type n0 = s.find_first_of('='); const std::string::size_type n0 = s.find_first_of('=');
if (n0 == std::string::npos) { if (n0 == std::string::npos) {
DefaultLogger::get()->warn(AddLineNumber("expected token \'=\'",line)); DefaultLogger::get()->warn(AddLineNumber("expected token \'=\'",line));
@ -233,13 +232,10 @@ void STEP::ReadFile(DB& db,const EXPRESS::ConversionSchema& scheme,
++splitter; ++splitter;
continue; continue;
} }
std::string::size_type n1 = s.find_first_of('(',n0); std::string::size_type n1 = s.find_first_of('(',n0);
if (n1 == std::string::npos) { if (n1 == std::string::npos) {
has_next = true; has_next = true;
bool ok = false; bool ok = false;
for( ++splitter; splitter; ++splitter) { for( ++splitter; splitter; ++splitter) {
const std::string& snext = *splitter; const std::string& snext = *splitter;
if (snext.empty()) { if (snext.empty()) {
@ -269,13 +265,11 @@ void STEP::ReadFile(DB& db,const EXPRESS::ConversionSchema& scheme,
has_next = true; has_next = true;
bool ok = false; bool ok = false;
for( ++splitter; splitter; ++splitter) { for( ++splitter; splitter; ++splitter) {
const std::string& snext = *splitter; const std::string& snext = *splitter;
if (snext.empty()) { if (snext.empty()) {
continue; continue;
} }
// the next line doesn't start an entity, so maybe it is // the next line doesn't start an entity, so maybe it is
// just a continuation for this line, keep going // just a continuation for this line, keep going
if (!IsEntityDef(snext)) { if (!IsEntityDef(snext)) {
@ -287,7 +281,6 @@ void STEP::ReadFile(DB& db,const EXPRESS::ConversionSchema& scheme,
break; break;
} }
} }
if(!ok) { if(!ok) {
DefaultLogger::get()->warn(AddLineNumber("expected token \')\'",line)); DefaultLogger::get()->warn(AddLineNumber("expected token \')\'",line));
continue; continue;
@ -300,24 +293,18 @@ void STEP::ReadFile(DB& db,const EXPRESS::ConversionSchema& scheme,
std::string::size_type ns = n0; std::string::size_type ns = n0;
do ++ns; while( IsSpace(s.at(ns))); do ++ns; while( IsSpace(s.at(ns)));
std::string::size_type ne = n1; std::string::size_type ne = n1;
do --ne; while( IsSpace(s.at(ne))); do --ne; while( IsSpace(s.at(ne)));
std::string type = s.substr(ns,ne-ns+1); std::string type = s.substr(ns,ne-ns+1);
std::transform( type.begin(), type.end(), type.begin(), &Assimp::ToLower<char> ); std::transform( type.begin(), type.end(), type.begin(), &Assimp::ToLower<char> );
const char* sz = scheme.GetStaticStringForToken(type); const char* sz = scheme.GetStaticStringForToken(type);
if(sz) { if(sz) {
const std::string::size_type len = n2-n1+1; const std::string::size_type len = n2-n1+1;
char* const copysz = new char[len+1]; char* const copysz = new char[len+1];
std::copy(s.c_str()+n1,s.c_str()+n2+1,copysz); std::copy(s.c_str()+n1,s.c_str()+n2+1,copysz);
copysz[len] = '\0'; copysz[len] = '\0';
db.InternInsert(new LazyObject(db,id,line,sz,copysz)); db.InternInsert(new LazyObject(db,id,line,sz,copysz));
} }
if(!has_next) { if(!has_next) {
++splitter; ++splitter;
} }
@ -327,7 +314,7 @@ void STEP::ReadFile(DB& db,const EXPRESS::ConversionSchema& scheme,
DefaultLogger::get()->warn("STEP: ignoring unexpected EOF"); DefaultLogger::get()->warn("STEP: ignoring unexpected EOF");
} }
if ( !DefaultLogger::isNullLogger() ){ if ( !DefaultLogger::isNullLogger()){
DefaultLogger::get()->debug((Formatter::format(),"STEP: got ",map.size()," object records with ", DefaultLogger::get()->debug((Formatter::format(),"STEP: got ",map.size()," object records with ",
db.GetRefs().size()," inverse index entries")); db.GetRefs().size()," inverse index entries"));
} }
@ -338,7 +325,6 @@ boost::shared_ptr<const EXPRESS::DataType> EXPRESS::DataType::Parse(const char*&
{ {
const char* cur = inout; const char* cur = inout;
SkipSpaces(&cur); SkipSpaces(&cur);
if (*cur == ',' || IsSpaceOrNewLine(*cur)) { if (*cur == ',' || IsSpaceOrNewLine(*cur)) {
throw STEP::SyntaxError("unexpected token, expected parameter",line); throw STEP::SyntaxError("unexpected token, expected parameter",line);
} }

View File

@ -47,12 +47,10 @@ namespace Assimp {
namespace STEP { namespace STEP {
// ### Parsing a STEP file is a twofold procedure ### // ### Parsing a STEP file is a twofold procedure ###
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// 1) read file header and return to caller, who checks if the // 1) read file header and return to caller, who checks if the
// file is of a supported schema .. // file is of a supported schema ..
DB* ReadFileHeader(boost::shared_ptr<IOStream> stream); DB* ReadFileHeader(boost::shared_ptr<IOStream> stream);
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// 2) read the actual file contents using a user-supplied set of // 2) read the actual file contents using a user-supplied set of
// conversion functions to interpret the data. // conversion functions to interpret the data.
@ -60,8 +58,6 @@ namespace STEP {
template <size_t N, size_t N2> inline void ReadFile(DB& db,const EXPRESS::ConversionSchema& scheme, const char* const (&arr)[N], const char* const (&arr2)[N2]) { template <size_t N, size_t N2> inline void ReadFile(DB& db,const EXPRESS::ConversionSchema& scheme, const char* const (&arr)[N], const char* const (&arr2)[N2]) {
return ReadFile(db,scheme,arr,N,arr2,N2); return ReadFile(db,scheme,arr,N,arr2,N2);
} }
} // ! STEP } // ! STEP
} // ! Assimp } // ! Assimp