MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / main

Function main

src/examples/IfcAdvancedHouse.cpp:58–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56void createGroundShape(TopoDS_Shape& shape);
57
58int main() {
59
60 // The IfcHierarchyHelper is a subclass of the regular IfcFile that provides several
61 // convenience functions for working with geometry in IFC files.
62 IfcHierarchyHelper<IfcSchema> file;
63 file.header().file_name()->setname("IfcAdvancedHouse.ifc");
64
65 IfcSchema::IfcBuilding* building = file.addBuilding();
66 // By adding a building, a hierarchy has been automatically created that consists of the following
67 // structure: IfcProject > IfcSite > IfcBuilding
68
69 // Lateron changing the name of the IfcProject can be done by obtaining a reference to the
70 // project, which has been created automatically.
71 file.getSingle<IfcSchema::IfcProject>()->setName("IfcAdvancedHouse"s);
72
73 // To demonstrate the ability to serialize arbitrary opencascade solids a building envelope is
74 // constructed by applying boolean operations. Naturally, in IFC, building elements should be
75 // modeled separately, with rich parametric and relational semantics. Creating geometry in this
76 // way does not preserve any history and is merely a demonstration of technical capabilities.
77 TopoDS_Shape outer = BRepPrimAPI_MakeBox(gp_Pnt(-5000., -180., -2000.), gp_Pnt(5000., 5180., 3000.)).Shape();
78 TopoDS_Shape inner = BRepPrimAPI_MakeBox(gp_Pnt(-4640., 180., 0.), gp_Pnt(4640., 4820., 3000.)).Shape();
79 TopoDS_Shape window1 = BRepPrimAPI_MakeBox(gp_Pnt(-5000., -180., 400.), gp_Pnt( 500., 1180., 2000.)).Shape();
80 TopoDS_Shape window2 = BRepPrimAPI_MakeBox(gp_Pnt( 2070., -180., 400.), gp_Pnt(3930., 180., 2000.)).Shape();
81
82 TopoDS_Shape building_shell = BRepAlgoAPI_Cut(
83 BRepAlgoAPI_Cut(
84 BRepAlgoAPI_Cut(outer, inner),
85 window1
86 ),
87 window2
88 );
89
90 // Since the solid consists only of planar faces and straight edges it can be serialized as an
91 // IfcFacetedBRep. If it would not be a polyhedron, serialise() can only be successful when linked
92 // to the IFC4 model and with `advanced` set to `true` which introduces IfcAdvancedFace. It would
93 // return `0` otherwise.
94 IfcSchema::IfcProductDefinitionShape* building_shape = IfcGeom::serialise(STRINGIFY(IfcSchema), building_shell, false)->as<IfcSchema::IfcProductDefinitionShape>();
95
96 file.addEntity(building_shape);
97 IfcSchema::IfcRepresentation* rep = *building_shape->Representations()->begin();
98 rep->setContextOfItems(file.getRepresentationContext("model"));
99
100 building->setRepresentation(building_shape);
101
102 // A pale white colour is assigned to the building.
103 setSurfaceColour(file, building_shape, 0.75, 0.73, 0.68);
104
105 // For the ground mesh of the IfcSite we will use a Nurbs surface created in Open Cascade. Only
106 // in IFC4 the surface can be directly serialized. In IFC2X3 the it will have to be tessellated.
107 TopoDS_Shape shape;
108 createGroundShape(shape);
109
110 auto ground_representation = IfcGeom::serialise(STRINGIFY(IfcSchema), shape, true);
111 if (!ground_representation) {
112 ground_representation = IfcGeom::tesselate(STRINGIFY(IfcSchema), shape, 100.);
113 }
114 file.getSingle<IfcSchema::IfcSite>()->setRepresentation(ground_representation->as<IfcSchema::IfcProductDefinitionShape>());
115

Callers

nothing calls this directly

Calls 10

setSurfaceColourFunction · 0.85
setnameMethod · 0.80
addBuildingMethod · 0.80
addEntityMethod · 0.80
createGroundShapeFunction · 0.70
file_nameMethod · 0.45
headerMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected