Skip to content

Commit 21e53d2

Browse files
committed
Fixes to examples
1 parent f5d6f4f commit 21e53d2

File tree

3 files changed

+35
-24
lines changed

3 files changed

+35
-24
lines changed

src/examples/IfcAdvancedHouse.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@
4040

4141
#ifdef USE_IFC4
4242
#include "../ifcparse/Ifc4.h"
43+
#define IfcSchema Ifc4
4344
#else
4445
#include "../ifcparse/Ifc2x3.h"
46+
#define IfcSchema Ifc2x3
4547
#endif
4648

4749
#include "../ifcparse/IfcBaseClass.h"
4850
#include "../ifcparse/IfcHierarchyHelper.h"
4951
#include "../ifcgeom/IfcGeom.h"
52+
#include "../ifcgeom_schema_agnostic/Serialization.h"
5053

5154
#if USE_VLD
5255
#include <vld.h>
@@ -59,7 +62,7 @@ int main() {
5962

6063
// The IfcHierarchyHelper is a subclass of the regular IfcFile that provides several
6164
// convenience functions for working with geometry in IFC files.
62-
IfcHierarchyHelper file;
65+
IfcHierarchyHelper<IfcSchema> file;
6366
file.header().file_name().name("IfcAdvancedHouse.ifc");
6467

6568
IfcSchema::IfcBuilding* building = file.addBuilding();
@@ -91,7 +94,7 @@ int main() {
9194
// IfcFacetedBRep. If it would not be a polyhedron, serialise() can only be successful when linked
9295
// to the IFC4 model and with `advanced` set to `true` which introduces IfcAdvancedFace. It would
9396
// return `0` otherwise.
94-
IfcSchema::IfcProductDefinitionShape* building_shape = IfcGeom::serialise(building_shell, false);
97+
IfcSchema::IfcProductDefinitionShape* building_shape = IfcGeom::serialise(STRINGIFY(IfcSchema), building_shell, false)->as<IfcSchema::IfcProductDefinitionShape>();
9598

9699
file.addEntity(building_shape);
97100
IfcSchema::IfcRepresentation* rep = *building_shape->Representations()->begin();
@@ -108,9 +111,9 @@ int main() {
108111
TopoDS_Shape shape;
109112
createGroundShape(shape);
110113

111-
IfcSchema::IfcProductDefinitionShape* ground_representation = IfcGeom::serialise(shape, true);
114+
IfcSchema::IfcProductDefinitionShape* ground_representation = IfcGeom::serialise(STRINGIFY(IfcSchema), shape, true)->as<IfcSchema::IfcProductDefinitionShape>();
112115
if (!ground_representation) {
113-
ground_representation = IfcGeom::tesselate(shape, 100.);
116+
ground_representation = IfcGeom::tesselate(STRINGIFY(IfcSchema), shape, 100.)->as<IfcSchema::IfcProductDefinitionShape>();
114117
}
115118
file.getSingle<IfcSchema::IfcSite>()->setRepresentation(ground_representation);
116119

src/examples/IfcOpenHouse.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,23 @@
2828

2929
#include <Geom_BSplineSurface.hxx>
3030
#include <BRepBuilderAPI_MakeFace.hxx>
31-
3231
#include <Standard_Version.hxx>
3332

33+
#include <BRepGProp.hxx>
34+
#include <GProp_GProps.hxx>
35+
3436
#ifdef USE_IFC4
3537
#include "../ifcparse/Ifc4.h"
38+
#define IfcSchema Ifc4
3639
#else
3740
#include "../ifcparse/Ifc2x3.h"
41+
#define IfcSchema Ifc2x3
3842
#endif
3943

4044
#include "../ifcparse/IfcBaseClass.h"
4145
#include "../ifcparse/IfcHierarchyHelper.h"
4246
#include "../ifcgeom/IfcGeom.h"
47+
#include "../ifcgeom_schema_agnostic/Serialization.h"
4348

4449
#if USE_VLD
4550
#include <vld.h>
@@ -58,7 +63,7 @@ int main() {
5863

5964
// The IfcHierarchyHelper is a subclass of the regular IfcFile that provides several
6065
// convenience functions for working with geometry in IFC files.
61-
IfcHierarchyHelper file;
66+
IfcHierarchyHelper<IfcSchema> file;
6267
file.header().file_name().name("IfcOpenHouse.ifc");
6368

6469
// Start by adding a wall to the file, initially leaving most attributes blank.
@@ -262,11 +267,13 @@ int main() {
262267
// will be tesselated using the deflection specified.
263268
TopoDS_Shape shape;
264269
createGroundShape(shape);
265-
IfcSchema::IfcProductDefinitionShape* ground_representation = IfcGeom::tesselate(shape, 100.);
270+
IfcSchema::IfcProductDefinitionShape* ground_representation = IfcGeom::tesselate(STRINGIFY(IfcSchema), shape, 100.)->as<IfcSchema::IfcProductDefinitionShape>();
266271
file.getSingle<IfcSchema::IfcSite>()->setRepresentation(ground_representation);
267272

268-
// Relate a property set to the IfcSite
269-
const double site_area = IfcGeom::Kernel::face_area(TopoDS::Face(shape)) / 1000 / 1000;
273+
GProp_GProps prop;
274+
BRepGProp::SurfaceProperties(shape, prop);
275+
const double site_area = prop.Mass() / 1000 / 1000;
276+
270277
IfcSchema::IfcProperty::list::ptr properties(new IfcSchema::IfcProperty::list);
271278
properties->push(new IfcSchema::IfcPropertySingleValue("TotalArea", null, new IfcSchema::IfcAreaMeasure(site_area), 0));
272279
IfcSchema::IfcPropertySet* pset = new IfcSchema::IfcPropertySet(guid(), file.getSingle<IfcSchema::IfcOwnerHistory>(), S("Pset_SiteCommon"), null, properties);
@@ -334,9 +341,9 @@ int main() {
334341
null,
335342
null,
336343
#ifdef USE_IFC4
337-
file.entitiesByType<IfcSchema::IfcWallStandardCase>()->generalize(),
344+
file.instances_by_type<IfcSchema::IfcWallStandardCase>()->generalize(),
338345
#else
339-
file.entitiesByType<IfcSchema::IfcWallStandardCase>()->as<IfcSchema::IfcRoot>(),
346+
file.instances_by_type<IfcSchema::IfcWallStandardCase>()->as<IfcSchema::IfcRoot>(),
340347
#endif
341348
layer_usage);
342349

@@ -391,7 +398,7 @@ int main() {
391398
IfcSchema::IfcShapeRepresentation* door_body = 0;
392399
for (IfcSchema::IfcRepresentation::list::it i = door_representations->begin(); i != door_representations->end(); ++i) {
393400
IfcSchema::IfcRepresentation* rep = *i;
394-
if (rep->is(IfcSchema::Type::IfcShapeRepresentation) && rep->RepresentationIdentifier() == "Body") {
401+
if (rep->declaration().is(IfcSchema::IfcShapeRepresentation::Class()) && rep->RepresentationIdentifier() == "Body") {
395402
door_body = (IfcSchema::IfcShapeRepresentation*) rep;
396403
}
397404
}

src/examples/IfcParseExamples.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
* *
1818
********************************************************************************/
1919

20+
// TODO: Multiple schemas
21+
#define IfcSchema Ifc2x3
22+
2023
#include "../ifcparse/IfcFile.h"
24+
#include "../ifcparse/Ifc2x3.h"
2125

2226
#if USE_VLD
2327
#include <vld.h>
2428
#endif
2529

26-
using namespace IfcSchema;
27-
2830
int main(int argc, char** argv) {
2931

3032
if ( argc != 2 ) {
@@ -36,8 +38,8 @@ int main(int argc, char** argv) {
3638
Logger::SetOutput(&std::cout,&std::cout);
3739

3840
// Parse the IFC file provided in argv[1]
39-
IfcParse::IfcFile file;
40-
if ( ! file.Init(argv[1]) ) {
41+
IfcParse::IfcFile file(argv[1]);
42+
if (!file.good()) {
4143
std::cout << "Unable to parse .ifc file" << std::endl;
4244
return 1;
4345
}
@@ -58,19 +60,18 @@ int main(int argc, char** argv) {
5860
// we need to cast them to IfcWindows. Since these properties
5961
// are optional we need to make sure the properties are
6062
// defined for the window in question before accessing them.
61-
IfcBuildingElement::list::ptr elements = file.entitiesByType<IfcBuildingElement>();
63+
IfcSchema::IfcBuildingElement::list::ptr elements = file.instances_by_type<IfcSchema::IfcBuildingElement>();
6264

6365
std::cout << "Found " << elements->size() << " elements in " << argv[1] << ":" << std::endl;
6466

65-
for ( IfcBuildingElement::list::it it = elements->begin(); it != elements->end(); ++ it ) {
67+
for (IfcSchema::IfcBuildingElement::list::it it = elements->begin(); it != elements->end(); ++it) {
6668

67-
const IfcBuildingElement* element = *it;
68-
std::cout << element->entity->toString() << std::endl;
69+
const IfcSchema::IfcBuildingElement* element = *it;
70+
std::cout << element->data().toString() << std::endl;
6971

70-
if ( element->is(IfcWindow::Class()) ) {
71-
const IfcWindow* window = (IfcWindow*)element;
72-
73-
if ( window->hasOverallWidth() && window->hasOverallHeight() ) {
72+
const IfcSchema::IfcWindow* window;
73+
if ((window = element->as<IfcSchema::IfcWindow>()) != 0) {
74+
if (window->hasOverallWidth() && window->hasOverallHeight()) {
7475
const double area = window->OverallWidth()*window->OverallHeight();
7576
std::cout << "The area of this window is " << area << std::endl;
7677
}

0 commit comments

Comments
 (0)