Skip to content

Commit 2561f94

Browse files
committed
- Fixed a bug regarding IfcUnitAssignment
- Separate IFC parsing library and geometry libraries [#3395025] - Added example for IfcParse usage without geometry or Open CASCADE functionality - Cleanup of vcproj Open CASCADE dependencies - Added function to query parent class type in IfcExpressParser.py
1 parent 0b45066 commit 2561f94

36 files changed

Lines changed: 986 additions & 197 deletions

cmake/CMakeLists.txt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,28 @@ ADD_DEFINITIONS(-fPIC)
6565

6666
INCLUDE_DIRECTORIES(${OCC_INCLUDE_DIR})
6767
ADD_LIBRARY(IfcParse STATIC
68-
../src/ifcparse/IfcGeomWires.cpp
6968
../src/ifcparse/Ifc2x3.cpp
70-
../src/ifcparse/IfcGeomHelpers.cpp
71-
../src/ifcparse/IfcGeomFunctions.cpp
72-
../src/ifcparse/IfcGeomObjects.cpp
73-
../src/ifcparse/IfcGeomShapes.cpp
74-
../src/ifcparse/IfcGeomFaces.cpp
75-
../src/ifcparse/IfcRegister.cpp
7669
../src/ifcparse/IfcUtil.cpp
77-
../src/ifcparse/IfcGeomCurves.cpp
7870
../src/ifcparse/IfcParse.cpp
7971
)
8072

73+
ADD_LIBRARY(IfcGeom STATIC
74+
../src/ifcgeom/IfcGeomCurves.cpp
75+
../src/ifcgeom/IfcGeomFaces.cpp
76+
../src/ifcgeom/IfcGeomFunctions.cpp
77+
../src/ifcgeom/IfcGeomHelpers.cpp
78+
../src/ifcgeom/IfcGeomObjects.cpp
79+
../src/ifcgeom/IfcGeomShapes.cpp
80+
../src/ifcgeom/IfcGeomWires.cpp
81+
../src/ifcgeom/IfcRegister.cpp
82+
)
83+
8184
LINK_DIRECTORIES (${IfcOpenShell_BINARY_DIR} /usr/lib)
8285
ADD_EXECUTABLE(IfcObj ../src/ifcobj/IfcObj.cpp)
83-
TARGET_LINK_LIBRARIES (IfcObj IfcParse TKernel TKMath TKBRep TKGeomBase TKGeomAlgo TKG3d TKG2d TKShHealing TKTopAlgo TKMesh TKPrim TKBool TKBO TKFillet)
86+
TARGET_LINK_LIBRARIES (IfcObj IfcParse IfcGeom TKernel TKMath TKBRep TKGeomBase TKGeomAlgo TKG3d TKG2d TKShHealing TKTopAlgo TKMesh TKPrim TKBool TKBO TKFillet)
8487

8588
# Build python wrapper using separate CMakeLists.txt
8689
ADD_SUBDIRECTORY(../src/ifcwrap ifcwrap)
90+
91+
# Build IfcParseExamples using separate CMakeLists.txt
92+
ADD_SUBDIRECTORY(../src/examples examples)

src/examples/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ADD_EXECUTABLE(IfcParseExamples ../src/examples/IfcParseExamples.cpp)
2+
TARGET_LINK_LIBRARIES (IfcParseExamples IfcParse)

src/examples/IfcParseExamples.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/********************************************************************************
2+
* *
3+
* This file is part of IfcOpenShell. *
4+
* *
5+
* IfcOpenShell is free software: you can redistribute it and/or modify *
6+
* it under the terms of the Lesser GNU General Public License as published by *
7+
* the Free Software Foundation, either version 3.0 of the License, or *
8+
* (at your option) any later version. *
9+
* *
10+
* IfcOpenShell is distributed in the hope that it will be useful, *
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13+
* Lesser GNU General Public License for more details. *
14+
* *
15+
* You should have received a copy of the Lesser GNU General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
* *
18+
********************************************************************************/
19+
20+
#include "../ifcparse/IfcParse.h"
21+
22+
using namespace Ifc2x3;
23+
24+
int main(int argc, char** argv) {
25+
26+
if ( argc != 2 ) {
27+
std::cout << "usage: IfcParseExamples <filename.ifc>" << std::endl;
28+
return 1;
29+
}
30+
31+
// Redirect the output (both progress and log) to stdout
32+
Ifc::SetOutput(&std::cout,&std::cout);
33+
34+
// Parse the IFC file provided in argv[1]
35+
if ( ! Ifc::Init(argv[1]) ) {
36+
std::cout << "Unable to parse .ifc file" << std::endl;
37+
return 1;
38+
}
39+
40+
// Lets get a list of IfcBuildingElements, this is the parent
41+
// type of things like walls, windows and doors.
42+
// EntitiesByType is a templated function and returns a
43+
// templated class that behaves like a std::vector.
44+
// Note that the return types are all typedef'ed as members of
45+
// the generated classes, ::list for the templated vector class,
46+
// ::ptr for a shared pointer and ::it for an iterator.
47+
// We will simply iterate over the vector and print a string
48+
// representation of the entity to stdout.
49+
//
50+
// Secondly, lets find out which of them are IfcWindows.
51+
// In order to access the additional properties that windows
52+
// have on top af the properties of building elements,
53+
// we need to cast them to IfcWindows. Since these properties
54+
// are optional we need to make sure the properties are
55+
// defined for the window in question before accessing them.
56+
//
57+
// Since we are accessing properties that represent a length
58+
// measure we can multiply the value by Ifc::LengthUnit, which
59+
// contains the ratio of the unit defined in the IfcUnitAssignment
60+
// to the standard SI Unit, the meter.
61+
IfcBuildingElement::list elements = Ifc::EntitiesByType<IfcBuildingElement>();
62+
63+
std::cout << "Found " << elements->Size() << " elements in " << argv[1] << ":" << std::endl;
64+
65+
for ( IfcBuildingElement::it it = elements->begin(); it != elements->end(); ++ it ) {
66+
67+
const IfcBuildingElement::ptr element = *it;
68+
std::cout << element->entity->toString() << std::endl;
69+
70+
if ( element->is(IfcWindow::Class()) ) {
71+
const IfcWindow::ptr window = reinterpret_pointer_cast<IfcBuildingElement,IfcWindow>(element);
72+
73+
if ( window->hasOverallWidth() && window->hasOverallHeight() ) {
74+
const float area = window->OverallWidth()*window->OverallHeight() * (Ifc::LengthUnit*Ifc::LengthUnit);
75+
std::cout << "This window has an area of " << area << "m2" << std::endl;
76+
}
77+
}
78+
79+
}
80+
81+
}

src/ifcexpressparser/IfcExpressParser.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ def __str__(self):
381381
typedef enum {
382382
%(enum)s
383383
} Enum;
384+
Enum Parent(Enum v);
384385
Enum FromString(const std::string& s);
385386
std::string ToString(Enum v);
386387
}
@@ -450,6 +451,14 @@ def __str__(self):
450451
print >>cpp_file, " throw;"
451452
print >>cpp_file, "}"
452453

454+
print >>cpp_file, "Type::Enum Type::Parent(Enum v){"
455+
print >>cpp_file, " if (v < 0 || v >= %d) return -1;"%len(all_enumerations)
456+
for e in entity_enumerations:
457+
if e not in parent_relations: continue
458+
print >>cpp_file, ' if(v==%s%s) { return %s; }'%(e," "*(maxlen-len(e)),parent_relations[e])
459+
print >>cpp_file, " return -1;"
460+
print >>cpp_file, "}"
461+
453462
for t in [T for T in types if isinstance(T.type,EnumType)]:
454463
print >>cpp_file, t
455464
for e in entities: print >>cpp_file, e,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272

7373
#include <TopLoc_Location.hxx>
7474

75-
#include "../ifcparse/IfcGeom.h"
75+
#include "../ifcgeom/IfcGeom.h"
7676

7777
bool IfcGeom::convert(const Ifc2x3::IfcCircle::ptr& l, Handle(Geom_Curve)& curve) {
7878
const float r = l->Radius() * Ifc::LengthUnit;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474

7575
#include <TopLoc_Location.hxx>
7676

77-
#include "../ifcparse/IfcGeom.h"
77+
#include "../ifcgeom/IfcGeom.h"
7878

7979
bool IfcGeom::convert(const Ifc2x3::IfcFace::ptr& l, TopoDS_Face& face) {
8080
Ifc2x3::IfcFaceBound::list bounds = l->Bounds();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272

7373
#include <TopLoc_Location.hxx>
7474

75-
#include "../ifcparse/IfcGeom.h"
75+
#include "../ifcgeom/IfcGeom.h"
7676

7777
bool IfcGeom::convert_openings(const Ifc2x3::IfcProduct::ptr& entity,
7878
const Ifc2x3::IfcRelVoidsElement::list& openings, TopoDS_Shape& result, const gp_Trsf& trsf2) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272

7373
#include <TopLoc_Location.hxx>
7474

75-
#include "../ifcparse/IfcGeom.h"
75+
#include "../ifcgeom/IfcGeom.h"
7676

7777

7878
namespace IfcGeom {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
#include <Poly_Array1OfTriangle.hxx>
3434
#include <StdFail_NotDone.hxx>
3535

36-
#include "../ifcparse/IfcGeomObjects.h"
37-
#include "../ifcparse/IfcGeom.h"
36+
#include "../ifcgeom/IfcGeomObjects.h"
37+
#include "../ifcgeom/IfcGeom.h"
3838

3939
// Welds vertices that belong to different faces
4040
int IfcGeomObjects::IfcMesh::addvert(gp_Pnt p) {

0 commit comments

Comments
 (0)