- 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
This commit is contained in:
Thomas Krijnen
2011-08-07 10:21:22 +00:00
parent 5a475bfa66
commit c99633eb90
7 changed files with 29 additions and 17 deletions
+2 -2
View File
@@ -78,7 +78,7 @@ ADD_LIBRARY(IfcParse STATIC
LINK_DIRECTORIES (${IfcOpenShell_BINARY_DIR} /usr/lib) LINK_DIRECTORIES (${IfcOpenShell_BINARY_DIR} /usr/lib)
ADD_EXECUTABLE(IfcObj ../src/ifcobj/IfcObj.cpp) 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 # Build python wrapper using separate CMakeLists.txt
ADD_SUBDIRECTORY(../src/ifcwrap .) ADD_SUBDIRECTORY(../src/ifcwrap ifcwrap)
+1 -1
View File
@@ -52,7 +52,7 @@ int main ( int argc, char** argv ) {
// Parse the file supplied in argv[1]. Returns true on succes. // 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. // 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; std::cout << "[Error] unable to parse .ifc file or no geometrical entities found" << std::endl;
return 1; return 1;
} }
+4 -1
View File
@@ -23,6 +23,8 @@
* * * *
********************************************************************************/ ********************************************************************************/
#include <new>
#include <gp_Pnt.hxx> #include <gp_Pnt.hxx>
#include <gp_Vec.hxx> #include <gp_Vec.hxx>
#include <gp_Dir.hxx> #include <gp_Dir.hxx>
@@ -85,7 +87,8 @@ bool IfcGeom::convert(const Ifc2x3::IfcFace::ptr& l, TopoDS_Face& face) {
if ( er == BRepBuilderAPI_NotPlanar ) { if ( er == BRepBuilderAPI_NotPlanar ) {
ShapeFix_ShapeTolerance FTol; ShapeFix_ShapeTolerance FTol;
FTol.SetTolerance(wire, 0.01, TopAbs_WIRE); FTol.SetTolerance(wire, 0.01, TopAbs_WIRE);
mf = BRepBuilderAPI_MakeFace(wire, false); mf.~BRepBuilderAPI_MakeFace();
new (&mf) BRepBuilderAPI_MakeFace(wire);
er = mf.Error(); er = mf.Error();
} }
if ( er != BRepBuilderAPI_FaceDone ) return false; if ( er != BRepBuilderAPI_FaceDone ) return false;
+2 -2
View File
@@ -257,8 +257,8 @@ extern bool IfcGeomObjects::Next() {
extern const IfcGeomObjects::IfcGeomObject* IfcGeomObjects::Get() { extern const IfcGeomObjects::IfcGeomObject* IfcGeomObjects::Get() {
return currentGeomObj; return currentGeomObj;
} }
extern bool IfcGeomObjects::Init(char* fn, bool world_coords, std::ostream* log) { extern bool IfcGeomObjects::Init(const char* fn, bool world_coords, std::ostream* log1, std::ostream* log2) {
if ( log ) Ifc::SetOutput(log); if ( log1 || log2 ) Ifc::SetOutput(log1,log2);
use_world_coords = world_coords; use_world_coords = world_coords;
if ( !Ifc::Init(fn) ) return false; if ( !Ifc::Init(fn) ) return false;
+1 -1
View File
@@ -97,7 +97,7 @@ namespace IfcGeomObjects {
IfcGeomObject( const std::string& n, const std::string& t, gp_Trsf trsf, IfcMesh* m ); 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 const IfcGeomObject* Get();
extern bool Next(); extern bool Next();
extern int Progress(); extern int Progress();
+15 -8
View File
@@ -31,6 +31,11 @@ using namespace IfcParse;
File::File(const std::string& fn) { File::File(const std::string& fn) {
eof = false; eof = false;
stream.open(fn.c_str(),std::ios_base::binary); stream.open(fn.c_str(),std::ios_base::binary);
if ( ! stream.good() ) {
valid = false;
return;
}
valid = true;
stream.seekg(0,std::ios_base::end); stream.seekg(0,std::ios_base::end);
size = (unsigned int) stream.tellg(); size = (unsigned int) stream.tellg();
stream.seekg(0,std::ios_base::beg); stream.seekg(0,std::ios_base::beg);
@@ -492,6 +497,7 @@ unsigned int Entity::id() { return _id; }
// //
bool Ifc::Init(const std::string& fn) { bool Ifc::Init(const std::string& fn) {
file = new File (fn); file = new File (fn);
if ( ! file->valid ) return false;
tokens = new Tokens (file); tokens = new Tokens (file);
Token token = 0; Token token = 0;
Token previous = 0; Token previous = 0;
@@ -500,12 +506,12 @@ bool Ifc::Init(const std::string& fn) {
int x = 0; int x = 0;
EntityPtr e; EntityPtr e;
IfcUtil::IfcSchemaEntity entity; IfcUtil::IfcSchemaEntity entity;
if ( log ) std::cout << "Scanning file..." << std::endl; if ( log1 ) std::cout << "Scanning file..." << std::endl;
while ( true ) { while ( true ) {
if ( currentId ) { if ( currentId ) {
e = EntityPtr(new Entity(currentId,tokens)); e = EntityPtr(new Entity(currentId,tokens));
entity = Ifc2x3::SchemaEntity(e); 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()); IfcEntities L = EntitiesByType(entity->type());
if ( L == 0 ) { if ( L == 0 ) {
L = IfcEntities(new IfcEntityList()); L = IfcEntities(new IfcEntityList());
@@ -532,7 +538,7 @@ bool Ifc::Init(const std::string& fn) {
previous = token; 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<Ifc2x3::IfcUnitAssignment>()->begin(); Ifc2x3::IfcUnitAssignment::ptr unit_assignment = *EntitiesByType<Ifc2x3::IfcUnitAssignment>()->begin();
IfcUtil::IfcAbstractSelect::list units = unit_assignment->Units(); 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 if ( v == Ifc2x3::IfcSIPrefix::ATTO ) return (float) 1e-18;
else return 1.0f; 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<IfcAbstractEntity>& entity) { void Ifc::LogMessage(const std::string& type, const std::string& message, const SHARED_PTR<IfcAbstractEntity>& entity) {
if ( log ) { if ( log2 ) {
(*log) << "[" << type << "] " << message << std::endl; (*log2) << "[" << type << "] " << message << std::endl;
if ( entity ) (*log) << entity->toString() << std::endl; if ( entity ) (*log2) << entity->toString() << std::endl;
} }
} }
File* Ifc::file = 0; File* Ifc::file = 0;
std::ostream* Ifc::log = 0; std::ostream* Ifc::log1 = 0;
std::ostream* Ifc::log2 = 0;
unsigned int Ifc::lastId = 0; unsigned int Ifc::lastId = 0;
Tokens* Ifc::tokens = 0; Tokens* Ifc::tokens = 0;
float Ifc::LengthUnit = 1.0f; float Ifc::LengthUnit = 1.0f;
+4 -2
View File
@@ -62,6 +62,7 @@ namespace IfcParse {
unsigned int offset; unsigned int offset;
void ReadBuffer(bool inc=true); void ReadBuffer(bool inc=true);
public: public:
bool valid;
bool eof; bool eof;
unsigned int size; unsigned int size;
File(const std::string& fn); File(const std::string& fn);
@@ -247,9 +248,10 @@ private:
static MapEntitiesByRef byref; static MapEntitiesByRef byref;
static MapOffsetById offsets; static MapOffsetById offsets;
static unsigned int lastId; static unsigned int lastId;
static std::ostream* log; static std::ostream* log1;
static std::ostream* log2;
public: 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<IfcAbstractEntity>& entity=SHARED_PTR<IfcAbstractEntity>()); static void LogMessage(const std::string& type, const std::string& message, const SHARED_PTR<IfcAbstractEntity>& entity=SHARED_PTR<IfcAbstractEntity>());
static IfcParse::File* file; static IfcParse::File* file;
static IfcParse::Tokens* tokens; static IfcParse::Tokens* tokens;