Skip to content

Commit c99633e

Browse files
committed
- 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
1 parent 5a475bf commit c99633e

7 files changed

Lines changed: 29 additions & 17 deletions

File tree

cmake/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ ADD_LIBRARY(IfcParse STATIC
7878

7979
LINK_DIRECTORIES (${IfcOpenShell_BINARY_DIR} /usr/lib)
8080
ADD_EXECUTABLE(IfcObj ../src/ifcobj/IfcObj.cpp)
81-
TARGET_LINK_LIBRARIES (IfcObj IfcParse TKAdvTools TKMath TKernel TKBRep TKGeomBase TKGeomAlgo TKBool TKMesh TKShHealing TKFillet)
81+
TARGET_LINK_LIBRARIES (IfcObj IfcParse TKernel TKMath TKBRep TKGeomBase TKGeomAlgo TKG3d TKG2d TKShHealing TKTopAlgo TKMesh TKPrim TKBool TKBO TKFillet)
8282

8383
# Build python wrapper using separate CMakeLists.txt
84-
ADD_SUBDIRECTORY(../src/ifcwrap .)
84+
ADD_SUBDIRECTORY(../src/ifcwrap ifcwrap)

src/ifcobj/IfcObj.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int main ( int argc, char** argv ) {
5252

5353
// Parse the file supplied in argv[1]. Returns true on succes.
5454
// The second argument defines whether geometry will be defined using global or local coordinates.
55-
if ( ! IfcGeomObjects::Init(argv[1],true,&ss) ) {
55+
if ( ! IfcGeomObjects::Init(argv[1],true,&std::cout,&ss) ) {
5656
std::cout << "[Error] unable to parse .ifc file or no geometrical entities found" << std::endl;
5757
return 1;
5858
}

src/ifcparse/IfcGeomFaces.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
* *
2424
********************************************************************************/
2525

26+
#include <new>
27+
2628
#include <gp_Pnt.hxx>
2729
#include <gp_Vec.hxx>
2830
#include <gp_Dir.hxx>
@@ -85,7 +87,8 @@ bool IfcGeom::convert(const Ifc2x3::IfcFace::ptr& l, TopoDS_Face& face) {
8587
if ( er == BRepBuilderAPI_NotPlanar ) {
8688
ShapeFix_ShapeTolerance FTol;
8789
FTol.SetTolerance(wire, 0.01, TopAbs_WIRE);
88-
mf = BRepBuilderAPI_MakeFace(wire, false);
90+
mf.~BRepBuilderAPI_MakeFace();
91+
new (&mf) BRepBuilderAPI_MakeFace(wire);
8992
er = mf.Error();
9093
}
9194
if ( er != BRepBuilderAPI_FaceDone ) return false;

src/ifcparse/IfcGeomObjects.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ extern bool IfcGeomObjects::Next() {
257257
extern const IfcGeomObjects::IfcGeomObject* IfcGeomObjects::Get() {
258258
return currentGeomObj;
259259
}
260-
extern bool IfcGeomObjects::Init(char* fn, bool world_coords, std::ostream* log) {
261-
if ( log ) Ifc::SetOutput(log);
260+
extern bool IfcGeomObjects::Init(const char* fn, bool world_coords, std::ostream* log1, std::ostream* log2) {
261+
if ( log1 || log2 ) Ifc::SetOutput(log1,log2);
262262
use_world_coords = world_coords;
263263
if ( !Ifc::Init(fn) ) return false;
264264

src/ifcparse/IfcGeomObjects.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ namespace IfcGeomObjects {
9797
IfcGeomObject( const std::string& n, const std::string& t, gp_Trsf trsf, IfcMesh* m );
9898
};
9999

100-
extern bool Init(char* fn, bool world_coords = false, std::ostream* log= 0);
100+
extern bool Init(const char* fn, bool world_coords = false, std::ostream* log1= 0, std::ostream* log2= 0);
101101
extern const IfcGeomObject* Get();
102102
extern bool Next();
103103
extern int Progress();

src/ifcparse/IfcParse.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ using namespace IfcParse;
3131
File::File(const std::string& fn) {
3232
eof = false;
3333
stream.open(fn.c_str(),std::ios_base::binary);
34+
if ( ! stream.good() ) {
35+
valid = false;
36+
return;
37+
}
38+
valid = true;
3439
stream.seekg(0,std::ios_base::end);
3540
size = (unsigned int) stream.tellg();
3641
stream.seekg(0,std::ios_base::beg);
@@ -492,6 +497,7 @@ unsigned int Entity::id() { return _id; }
492497
//
493498
bool Ifc::Init(const std::string& fn) {
494499
file = new File (fn);
500+
if ( ! file->valid ) return false;
495501
tokens = new Tokens (file);
496502
Token token = 0;
497503
Token previous = 0;
@@ -500,12 +506,12 @@ bool Ifc::Init(const std::string& fn) {
500506
int x = 0;
501507
EntityPtr e;
502508
IfcUtil::IfcSchemaEntity entity;
503-
if ( log ) std::cout << "Scanning file..." << std::endl;
509+
if ( log1 ) std::cout << "Scanning file..." << std::endl;
504510
while ( true ) {
505511
if ( currentId ) {
506512
e = EntityPtr(new Entity(currentId,tokens));
507513
entity = Ifc2x3::SchemaEntity(e);
508-
if ( log && !((++x)%1000) ) std::cout << "\r#" << currentId << " " << std::flush;
514+
if ( log1 && !((++x)%1000) ) std::cout << "\r#" << currentId << " " << std::flush;
509515
IfcEntities L = EntitiesByType(entity->type());
510516
if ( L == 0 ) {
511517
L = IfcEntities(new IfcEntityList());
@@ -532,7 +538,7 @@ bool Ifc::Init(const std::string& fn) {
532538
previous = token;
533539
}
534540

535-
if ( log ) std::cout << "\rDone scanning file " << std::endl;
541+
if ( log1 ) std::cout << "\rDone scanning file " << std::endl;
536542

537543
Ifc2x3::IfcUnitAssignment::ptr unit_assignment = *EntitiesByType<Ifc2x3::IfcUnitAssignment>()->begin();
538544
IfcUtil::IfcAbstractSelect::list units = unit_assignment->Units();
@@ -626,16 +632,17 @@ float UnitPrefixToValue( Ifc2x3::IfcSIPrefix::IfcSIPrefix v ) {
626632
else if ( v == Ifc2x3::IfcSIPrefix::ATTO ) return (float) 1e-18;
627633
else return 1.0f;
628634
}
629-
void Ifc::SetOutput(std::ostream* l) { log = l; }
635+
void Ifc::SetOutput(std::ostream* l1, std::ostream* l2) { log1 = l1; log2 = l2; }
630636
void Ifc::LogMessage(const std::string& type, const std::string& message, const SHARED_PTR<IfcAbstractEntity>& entity) {
631-
if ( log ) {
632-
(*log) << "[" << type << "] " << message << std::endl;
633-
if ( entity ) (*log) << entity->toString() << std::endl;
637+
if ( log2 ) {
638+
(*log2) << "[" << type << "] " << message << std::endl;
639+
if ( entity ) (*log2) << entity->toString() << std::endl;
634640
}
635641
}
636642

637643
File* Ifc::file = 0;
638-
std::ostream* Ifc::log = 0;
644+
std::ostream* Ifc::log1 = 0;
645+
std::ostream* Ifc::log2 = 0;
639646
unsigned int Ifc::lastId = 0;
640647
Tokens* Ifc::tokens = 0;
641648
float Ifc::LengthUnit = 1.0f;

src/ifcparse/IfcParse.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ namespace IfcParse {
6262
unsigned int offset;
6363
void ReadBuffer(bool inc=true);
6464
public:
65+
bool valid;
6566
bool eof;
6667
unsigned int size;
6768
File(const std::string& fn);
@@ -247,9 +248,10 @@ class Ifc {
247248
static MapEntitiesByRef byref;
248249
static MapOffsetById offsets;
249250
static unsigned int lastId;
250-
static std::ostream* log;
251+
static std::ostream* log1;
252+
static std::ostream* log2;
251253
public:
252-
static void SetOutput(std::ostream* l);
254+
static void SetOutput(std::ostream* l1, std::ostream* l2);
253255
static void LogMessage(const std::string& type, const std::string& message, const SHARED_PTR<IfcAbstractEntity>& entity=SHARED_PTR<IfcAbstractEntity>());
254256
static IfcParse::File* file;
255257
static IfcParse::Tokens* tokens;

0 commit comments

Comments
 (0)