mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-06 07:51:47 +00:00
- 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:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <gp_Vec.hxx>
|
||||
#include <gp_Dir.hxx>
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<Ifc2x3::IfcUnitAssignment>()->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<IfcAbstractEntity>& 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;
|
||||
|
||||
@@ -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<IfcAbstractEntity>& entity=SHARED_PTR<IfcAbstractEntity>());
|
||||
static IfcParse::File* file;
|
||||
static IfcParse::Tokens* tokens;
|
||||
|
||||
Reference in New Issue
Block a user