Skip to content

Commit e56281a

Browse files
committed
- Correctly format REALs according to ISO 10303-21 instead of C++ std::stream double formatting
- Add the IfcHierarchyHelper to assist in the creation of IFC files - Add the IfcOpenHouse example for writing topological geometry and tessellated Open Cascade shapes to IFC
1 parent db98906 commit e56281a

File tree

14 files changed

+1359
-96
lines changed

14 files changed

+1359
-96
lines changed

cmake/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ ADD_LIBRARY(IfcParse STATIC
102102

103103
../src/ifcparse/IfcWrite.cpp
104104
../src/ifcparse/IfcGuidHelper.cpp
105+
106+
../src/ifcparse/IfcHierarchyHelper.cpp
105107
)
106108

107109
ADD_LIBRARY(IfcGeom STATIC
@@ -159,6 +161,7 @@ SET(include_files_parse
159161
../src/ifcparse/IfcCharacterDecoder.h
160162
../src/ifcparse/IfcException.h
161163
../src/ifcparse/IfcFile.h
164+
../src/ifcparse/IfcHierarchyHelper.h
162165
../src/ifcparse/IfcParse.h
163166
../src/ifcparse/IfcUtil.h
164167
../src/ifcparse/SharedPointer.h

src/examples/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
ADD_EXECUTABLE(IfcParseExamples IfcParseExamples.cpp)
2-
TARGET_LINK_LIBRARIES (IfcParseExamples IfcParse)
2+
TARGET_LINK_LIBRARIES (IfcParseExamples IfcParse)
3+
4+
ADD_EXECUTABLE(IfcOpenHouse IfcOpenHouse.cpp)
5+
TARGET_LINK_LIBRARIES (IfcOpenHouse IfcParse IfcGeom TKernel TKMath TKBRep TKGeomBase TKGeomAlgo TKG3d TKG2d TKShHealing TKTopAlgo TKMesh TKPrim TKBool TKBO TKFillet)

src/examples/IfcOpenHouse.cpp

Lines changed: 374 additions & 0 deletions
Large diffs are not rendered by default.

src/ifcgeom/IfcGeom.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ namespace IfcGeom {
9696
double face_area(const TopoDS_Face& f);
9797
void SetValue(GeomValue var, double value);
9898
double GetValue(GeomValue var);
99+
Ifc2x3::IfcProductDefinitionShape* tesselate(TopoDS_Shape& shape, double deflection, IfcEntities es);
99100

100101
namespace Cache {
101102
void Purge();

src/ifcgeom/IfcGeomFunctions.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@
8686

8787
#include <BRepGProp_Face.hxx>
8888

89+
#include <BRepMesh.hxx>
90+
#include <BRepTools.hxx>
91+
92+
#include <Poly_Triangulation.hxx>
93+
#include <Poly_Array1OfTriangle.hxx>
94+
8995
#include "../ifcgeom/IfcGeom.h"
9096

9197
bool IfcGeom::create_solid_from_compound(const TopoDS_Shape& compound, TopoDS_Shape& shape) {
@@ -489,4 +495,68 @@ double IfcGeom::GetValue(GeomValue var) {
489495
}
490496
assert(!"never reach here");
491497
return 0;
498+
}
499+
500+
Ifc2x3::IfcProductDefinitionShape* IfcGeom::tesselate(TopoDS_Shape& shape, double deflection, IfcEntities es) {
501+
BRepMesh::Mesh(shape, deflection);
502+
503+
Ifc2x3::IfcFace::list faces (new IfcTemplatedEntityList<Ifc2x3::IfcFace>());
504+
505+
for (TopExp_Explorer exp(shape, TopAbs_FACE); exp.More(); exp.Next()) {
506+
const TopoDS_Face& face = TopoDS::Face(exp.Current());
507+
TopLoc_Location loc;
508+
Handle(Poly_Triangulation) tri = BRep_Tool::Triangulation(face, loc);
509+
510+
if (! tri.IsNull()) {
511+
const TColgp_Array1OfPnt& nodes = tri->Nodes();
512+
std::vector<Ifc2x3::IfcCartesianPoint*> vertices;
513+
for (int i = 1; i <= nodes.Length(); ++i) {
514+
const gp_Pnt& pnt = nodes(i);
515+
std::vector<double> xyz; xyz.push_back(pnt.X()); xyz.push_back(pnt.Y()); xyz.push_back(pnt.Z());
516+
Ifc2x3::IfcCartesianPoint* cpnt = new Ifc2x3::IfcCartesianPoint(xyz);
517+
vertices.push_back(cpnt);
518+
es->push(cpnt);
519+
}
520+
const Poly_Array1OfTriangle& triangles = tri->Triangles();
521+
for (int i = 1; i <= triangles.Length(); ++ i) {
522+
int n1, n2, n3;
523+
triangles(i).Get(n1, n2, n3);
524+
Ifc2x3::IfcCartesianPoint::list points (new IfcTemplatedEntityList<Ifc2x3::IfcCartesianPoint>());
525+
points->push(vertices[n1-1]);
526+
points->push(vertices[n2-1]);
527+
points->push(vertices[n3-1]);
528+
Ifc2x3::IfcPolyLoop* loop = new Ifc2x3::IfcPolyLoop(points);
529+
Ifc2x3::IfcFaceOuterBound* bound = new Ifc2x3::IfcFaceOuterBound(loop, face.Orientation() != TopAbs_REVERSED);
530+
Ifc2x3::IfcFaceBound::list bounds (new IfcTemplatedEntityList<Ifc2x3::IfcFaceBound>());
531+
bounds->push(bound);
532+
Ifc2x3::IfcFace* face = new Ifc2x3::IfcFace(bounds);
533+
es->push(loop);
534+
es->push(bound);
535+
es->push(face);
536+
faces->push(face);
537+
}
538+
}
539+
}
540+
Ifc2x3::IfcOpenShell* shell = new Ifc2x3::IfcOpenShell(faces);
541+
Ifc2x3::IfcConnectedFaceSet::list shells (new IfcTemplatedEntityList<Ifc2x3::IfcConnectedFaceSet>());
542+
shells->push(shell);
543+
Ifc2x3::IfcFaceBasedSurfaceModel* surface_model = new Ifc2x3::IfcFaceBasedSurfaceModel(shells);
544+
545+
Ifc2x3::IfcRepresentation::list reps (new IfcTemplatedEntityList<Ifc2x3::IfcRepresentation>());
546+
Ifc2x3::IfcRepresentationItem::list items (new IfcTemplatedEntityList<Ifc2x3::IfcRepresentationItem>());
547+
548+
items->push(surface_model);
549+
550+
Ifc2x3::IfcShapeRepresentation* rep = new Ifc2x3::IfcShapeRepresentation(
551+
0, std::string("Facetation"), std::string("SurfaceModel"), items);
552+
553+
reps->push(rep);
554+
Ifc2x3::IfcProductDefinitionShape* shapedef = new Ifc2x3::IfcProductDefinitionShape(0, 0, reps);
555+
556+
es->push(shell);
557+
es->push(surface_model);
558+
es->push(rep);
559+
es->push(shapedef);
560+
561+
return shapedef;
492562
}

0 commit comments

Comments
 (0)