From c99633eb90d004883dda23826ab2d1f27d8fb1b3 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Sun, 7 Aug 2011 10:21:22 +0000 Subject: [PATCH] - Fixed CMake errors, added missing libraries - Basic checks for valid file stream, seperated logging to stdout and stderr - Use placement new to reconstruct MakeFace for non-planar face --- cmake/CMakeLists.txt | 4 ++-- src/ifcobj/IfcObj.cpp | 2 +- src/ifcparse/IfcGeomFaces.cpp | 5 ++++- src/ifcparse/IfcGeomObjects.cpp | 4 ++-- src/ifcparse/IfcGeomObjects.h | 2 +- src/ifcparse/IfcParse.cpp | 23 +++++++++++++++-------- src/ifcparse/IfcParse.h | 6 ++++-- 7 files changed, 29 insertions(+), 17 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 10511ac2c6..d974864528 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -78,7 +78,7 @@ ADD_LIBRARY(IfcParse STATIC LINK_DIRECTORIES (${IfcOpenShell_BINARY_DIR} /usr/lib) ADD_EXECUTABLE(IfcObj ../src/ifcobj/IfcObj.cpp) -TARGET_LINK_LIBRARIES (IfcObj IfcParse TKAdvTools TKMath TKernel TKBRep TKGeomBase TKGeomAlgo TKBool TKMesh TKShHealing TKFillet) +TARGET_LINK_LIBRARIES (IfcObj IfcParse TKernel TKMath TKBRep TKGeomBase TKGeomAlgo TKG3d TKG2d TKShHealing TKTopAlgo TKMesh TKPrim TKBool TKBO TKFillet) # Build python wrapper using separate CMakeLists.txt -ADD_SUBDIRECTORY(../src/ifcwrap .) +ADD_SUBDIRECTORY(../src/ifcwrap ifcwrap) diff --git a/src/ifcobj/IfcObj.cpp b/src/ifcobj/IfcObj.cpp index c6b94efe20..687290c72d 100644 --- a/src/ifcobj/IfcObj.cpp +++ b/src/ifcobj/IfcObj.cpp @@ -52,7 +52,7 @@ int main ( int argc, char** argv ) { // Parse the file supplied in argv[1]. Returns true on succes. // The second argument defines whether geometry will be defined using global or local coordinates. - if ( ! IfcGeomObjects::Init(argv[1],true,&ss) ) { + if ( ! IfcGeomObjects::Init(argv[1],true,&std::cout,&ss) ) { std::cout << "[Error] unable to parse .ifc file or no geometrical entities found" << std::endl; return 1; } diff --git a/src/ifcparse/IfcGeomFaces.cpp b/src/ifcparse/IfcGeomFaces.cpp index e5e9763df3..eb2a56a5fd 100644 --- a/src/ifcparse/IfcGeomFaces.cpp +++ b/src/ifcparse/IfcGeomFaces.cpp @@ -23,6 +23,8 @@ * * ********************************************************************************/ +#include + #include #include #include @@ -85,7 +87,8 @@ bool IfcGeom::convert(const Ifc2x3::IfcFace::ptr& l, TopoDS_Face& face) { if ( er == BRepBuilderAPI_NotPlanar ) { ShapeFix_ShapeTolerance FTol; FTol.SetTolerance(wire, 0.01, TopAbs_WIRE); - mf = BRepBuilderAPI_MakeFace(wire, false); + mf.~BRepBuilderAPI_MakeFace(); + new (&mf) BRepBuilderAPI_MakeFace(wire); er = mf.Error(); } if ( er != BRepBuilderAPI_FaceDone ) return false; diff --git a/src/ifcparse/IfcGeomObjects.cpp b/src/ifcparse/IfcGeomObjects.cpp index 9039d261c1..1082a5e471 100644 --- a/src/ifcparse/IfcGeomObjects.cpp +++ b/src/ifcparse/IfcGeomObjects.cpp @@ -257,8 +257,8 @@ extern bool IfcGeomObjects::Next() { extern const IfcGeomObjects::IfcGeomObject* IfcGeomObjects::Get() { return currentGeomObj; } -extern bool IfcGeomObjects::Init(char* fn, bool world_coords, std::ostream* log) { - if ( log ) Ifc::SetOutput(log); +extern bool IfcGeomObjects::Init(const char* fn, bool world_coords, std::ostream* log1, std::ostream* log2) { + if ( log1 || log2 ) Ifc::SetOutput(log1,log2); use_world_coords = world_coords; if ( !Ifc::Init(fn) ) return false; diff --git a/src/ifcparse/IfcGeomObjects.h b/src/ifcparse/IfcGeomObjects.h index 8749c3c786..1b986de5ca 100644 --- a/src/ifcparse/IfcGeomObjects.h +++ b/src/ifcparse/IfcGeomObjects.h @@ -97,7 +97,7 @@ namespace IfcGeomObjects { IfcGeomObject( const std::string& n, const std::string& t, gp_Trsf trsf, IfcMesh* m ); }; - extern bool Init(char* fn, bool world_coords = false, std::ostream* log= 0); + extern bool Init(const char* fn, bool world_coords = false, std::ostream* log1= 0, std::ostream* log2= 0); extern const IfcGeomObject* Get(); extern bool Next(); extern int Progress(); diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index 149f4e8edc..0068e31346 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -31,6 +31,11 @@ using namespace IfcParse; File::File(const std::string& fn) { eof = false; stream.open(fn.c_str(),std::ios_base::binary); + if ( ! stream.good() ) { + valid = false; + return; + } + valid = true; stream.seekg(0,std::ios_base::end); size = (unsigned int) stream.tellg(); stream.seekg(0,std::ios_base::beg); @@ -492,6 +497,7 @@ unsigned int Entity::id() { return _id; } // bool Ifc::Init(const std::string& fn) { file = new File (fn); + if ( ! file->valid ) return false; tokens = new Tokens (file); Token token = 0; Token previous = 0; @@ -500,12 +506,12 @@ bool Ifc::Init(const std::string& fn) { int x = 0; EntityPtr e; IfcUtil::IfcSchemaEntity entity; - if ( log ) std::cout << "Scanning file..." << std::endl; + if ( log1 ) std::cout << "Scanning file..." << std::endl; while ( true ) { if ( currentId ) { e = EntityPtr(new Entity(currentId,tokens)); entity = Ifc2x3::SchemaEntity(e); - if ( log && !((++x)%1000) ) std::cout << "\r#" << currentId << " " << std::flush; + if ( log1 && !((++x)%1000) ) std::cout << "\r#" << currentId << " " << std::flush; IfcEntities L = EntitiesByType(entity->type()); if ( L == 0 ) { L = IfcEntities(new IfcEntityList()); @@ -532,7 +538,7 @@ bool Ifc::Init(const std::string& fn) { previous = token; } - if ( log ) std::cout << "\rDone scanning file " << std::endl; + if ( log1 ) std::cout << "\rDone scanning file " << std::endl; Ifc2x3::IfcUnitAssignment::ptr unit_assignment = *EntitiesByType()->begin(); IfcUtil::IfcAbstractSelect::list units = unit_assignment->Units(); @@ -626,16 +632,17 @@ float UnitPrefixToValue( Ifc2x3::IfcSIPrefix::IfcSIPrefix v ) { else if ( v == Ifc2x3::IfcSIPrefix::ATTO ) return (float) 1e-18; else return 1.0f; } -void Ifc::SetOutput(std::ostream* l) { log = l; } +void Ifc::SetOutput(std::ostream* l1, std::ostream* l2) { log1 = l1; log2 = l2; } void Ifc::LogMessage(const std::string& type, const std::string& message, const SHARED_PTR& entity) { - if ( log ) { - (*log) << "[" << type << "] " << message << std::endl; - if ( entity ) (*log) << entity->toString() << std::endl; + if ( log2 ) { + (*log2) << "[" << type << "] " << message << std::endl; + if ( entity ) (*log2) << entity->toString() << std::endl; } } File* Ifc::file = 0; -std::ostream* Ifc::log = 0; +std::ostream* Ifc::log1 = 0; +std::ostream* Ifc::log2 = 0; unsigned int Ifc::lastId = 0; Tokens* Ifc::tokens = 0; float Ifc::LengthUnit = 1.0f; diff --git a/src/ifcparse/IfcParse.h b/src/ifcparse/IfcParse.h index 46a5de2da5..4f0cdb8d39 100644 --- a/src/ifcparse/IfcParse.h +++ b/src/ifcparse/IfcParse.h @@ -62,6 +62,7 @@ namespace IfcParse { unsigned int offset; void ReadBuffer(bool inc=true); public: + bool valid; bool eof; unsigned int size; File(const std::string& fn); @@ -247,9 +248,10 @@ private: static MapEntitiesByRef byref; static MapOffsetById offsets; static unsigned int lastId; - static std::ostream* log; + static std::ostream* log1; + static std::ostream* log2; public: - static void SetOutput(std::ostream* l); + static void SetOutput(std::ostream* l1, std::ostream* l2); static void LogMessage(const std::string& type, const std::string& message, const SHARED_PTR& entity=SHARED_PTR()); static IfcParse::File* file; static IfcParse::Tokens* tokens;