Skip to content

Commit f2f4d62

Browse files
committed
Fix examples mostly
1 parent 572a565 commit f2f4d62

13 files changed

Lines changed: 572 additions & 601 deletions

src/examples/IfcAdvancedHouse.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#define IfcSchema Ifc2x3
4242
#include "../ifcparse/macros.h"
4343
#include "../ifcparse/Ifc2x3.h"
44-
#include "../ifcparse/IfcBaseClass.h"
4544
#include "../ifcparse/IfcHierarchyHelper.h"
4645

4746
#include "../ifcgeom/Serialization/Serialization.h"
@@ -60,15 +59,15 @@ int main() {
6059
// The IfcHierarchyHelper is a subclass of the regular IfcFile that provides several
6160
// convenience functions for working with geometry in IFC files.
6261
IfcHierarchyHelper<IfcSchema> file;
63-
file.header().file_name()->setname("IfcAdvancedHouse.ifc");
62+
file.header().file_name().setname("IfcAdvancedHouse.ifc");
6463

65-
IfcSchema::IfcBuilding* building = file.addBuilding();
64+
auto building = file.addBuilding();
6665
// By adding a building, a hierarchy has been automatically created that consists of the following
6766
// structure: IfcProject > IfcSite > IfcBuilding
6867

6968
// Lateron changing the name of the IfcProject can be done by obtaining a reference to the
7069
// project, which has been created automatically.
71-
file.getSingle<IfcSchema::IfcProject>()->setName("IfcAdvancedHouse"s);
70+
file.getSingle<IfcSchema::IfcProject>().setName("IfcAdvancedHouse"s);
7271

7372
// To demonstrate the ability to serialize arbitrary opencascade solids a building envelope is
7473
// constructed by applying boolean operations. Naturally, in IFC, building elements should be
@@ -91,13 +90,13 @@ int main() {
9190
// IfcFacetedBRep. If it would not be a polyhedron, serialise() can only be successful when linked
9291
// to the IFC4 model and with `advanced` set to `true` which introduces IfcAdvancedFace. It would
9392
// return `0` otherwise.
94-
IfcSchema::IfcProductDefinitionShape* building_shape = IfcGeom::serialise(STRINGIFY(IfcSchema), building_shell, false)->as<IfcSchema::IfcProductDefinitionShape>();
93+
auto building_shape = IfcGeom::serialise(file, building_shell, false).as<IfcSchema::IfcProductDefinitionShape>();
9594

9695
file.addEntity(building_shape);
97-
IfcSchema::IfcRepresentation* rep = *building_shape->Representations()->begin();
96+
auto rep = building_shape.Representations().begin();
9897
rep->setContextOfItems(file.getRepresentationContext("model"));
9998

100-
building->setRepresentation(building_shape);
99+
building.setRepresentation(building_shape);
101100

102101
// A pale white colour is assigned to the building.
103102
setSurfaceColour(file, building_shape, 0.75, 0.73, 0.68);
@@ -107,18 +106,18 @@ int main() {
107106
TopoDS_Shape shape;
108107
createGroundShape(shape);
109108

110-
auto ground_representation = IfcGeom::serialise(STRINGIFY(IfcSchema), shape, true);
109+
auto ground_representation = IfcGeom::serialise(file, shape, true);
111110
if (!ground_representation) {
112-
ground_representation = IfcGeom::tesselate(STRINGIFY(IfcSchema), shape, 100.);
111+
ground_representation = IfcGeom::tesselate(file, shape, 100.);
113112
}
114-
file.getSingle<IfcSchema::IfcSite>()->setRepresentation(ground_representation->as<IfcSchema::IfcProductDefinitionShape>());
113+
file.getSingle<IfcSchema::IfcSite>().setRepresentation(ground_representation.as<IfcSchema::IfcProductDefinitionShape>());
115114

116-
IfcSchema::IfcRepresentation::list::ptr ground_reps = file.getSingle<IfcSchema::IfcSite>()->Representation()->Representations();
117-
for (IfcSchema::IfcRepresentation::list::it it = ground_reps->begin(); it != ground_reps->end(); ++it) {
118-
(*it)->setContextOfItems(file.getRepresentationContext("Model"));
115+
auto ground_reps = file.getSingle<IfcSchema::IfcSite>().Representation().Representations();
116+
for (auto& rep : ground_reps) {
117+
rep.setContextOfItems(file.getRepresentationContext("Model"));
119118
}
120119
file.addEntity(ground_representation);
121-
setSurfaceColour(file, ground_representation->as<IfcSchema::IfcProductDefinitionShape>(), 0.15, 0.25, 0.05);
120+
setSurfaceColour(file, ground_representation.as<IfcSchema::IfcProductDefinitionShape>(), 0.15, 0.25, 0.05);
122121

123122
/*
124123
// Note that IFC lacks elementary surfaces that STEP does have, such as spherical_surface.

src/examples/IfcOpenHouse.cpp

Lines changed: 382 additions & 342 deletions
Large diffs are not rendered by default.

src/examples/IfcParseExamples.cpp

Lines changed: 43 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -114,44 +114,42 @@ std::string format_string(const AttributeValue& argument) {
114114
}
115115

116116
template <typename Schema, typename T>
117-
void process_pset(element_properties& props, const T* inst) {
117+
void process_pset(element_properties& props, const T& inst) {
118118
// Process an individual Property or Quantity set.
119-
if (auto pset = inst->template as<typename Schema::IfcPropertySet>()) {
119+
if (auto pset = inst.template as<typename Schema::IfcPropertySet>()) {
120120
if (!pset->Name()) {
121121
return;
122122
}
123123
auto ps = pset->HasProperties();
124-
for (auto it = ps->begin(); it != ps->end(); ++it) {
125-
auto& p = *it;
126-
if (auto singleval = p->template as<typename Schema::IfcPropertySingleValue>()) {
124+
for (auto& p : ps) {
125+
if (auto singleval = p.template as<typename Schema::IfcPropertySingleValue>()) {
127126
std::string propname, propvalue;
128127
if constexpr (is_ifc4_or_higher<Schema>::value) {
129-
if (!singleval->Name()) {
128+
if (!singleval.Name()) {
130129
continue;
131130
}
132-
propname = *singleval->Name();
131+
propname = *singleval.Name();
133132
}
134133
if constexpr (!is_ifc4_or_higher<Schema>::value) {
135-
propname = singleval->Name();
134+
propname = singleval.Name();
136135
}
137-
if (!singleval->NominalValue()) {
136+
if (!singleval.NominalValue()) {
138137
propvalue = "-";
139138
} else {
140-
props[*pset->Name()][propname] = format_string(singleval->NominalValue()->template as<IfcUtil::IfcBaseClass>()->get_attribute_value(0));
139+
props[*pset.Name()][propname] = format_string(singleval.NominalValue().concrete().get_attribute_value(0));
141140
}
142141
}
143142
}
144143
}
145-
if (auto qset = inst->template as<typename Schema::IfcElementQuantity>()) {
146-
if (!qset->Name()) {
144+
if (auto qset = inst.template as<typename Schema::IfcElementQuantity>()) {
145+
if (!qset.Name()) {
147146
return;
148147
}
149-
auto qs = qset->Quantities();
150-
for (auto it = qs->begin(); it != qs->end(); ++it) {
151-
auto& q = *it;
152-
if (q->template as<typename Schema::IfcPhysicalSimpleQuantity>() && q->get_attribute_value(3).type() == IfcUtil::Argument_DOUBLE) {
153-
double v = q->get_attribute_value(3);
154-
props[*qset->Name()][q->Name()] = std::to_string(v);
148+
auto qs = qset.Quantities();
149+
for (auto& q : qs) {
150+
if (q.template as<typename Schema::IfcPhysicalSimpleQuantity>() && q.get_attribute_value(3).type() == IfcUtil::Argument_DOUBLE) {
151+
double v = q.get_attribute_value(3);
152+
props[*qset.Name()][q.Name()] = std::to_string(v);
155153
}
156154
}
157155
}
@@ -163,48 +161,43 @@ void process_pset(element_properties& props, const T* inst) {
163161
}
164162

165163
template <typename Schema>
166-
void get_psets_s(element_properties& props, const typename Schema::IfcObjectDefinition* inst) {
164+
void get_psets_s(element_properties& props, const typename Schema::IfcObjectDefinition& inst) {
167165
// Extracts the property definitions for an IFC instance.
168-
if (auto tyob = inst->template as<typename Schema::IfcTypeObject>()) {
169-
if (tyob->HasPropertySets()) {
170-
auto defs = *tyob->HasPropertySets();
171-
for (auto it = defs->begin(); it != defs->end(); ++it) {
172-
auto& def = *it;
166+
if (auto tyob = inst.template as<typename Schema::IfcTypeObject>()) {
167+
if (tyob.HasPropertySets()) {
168+
auto defs = *tyob.HasPropertySets();
169+
for (auto& def : defs) {
173170
process_pset<Schema>(props, def);
174171
}
175172
}
176173
}
177174
if constexpr (is_ifc4_or_higher<Schema>::value) {
178-
if (auto mdef = inst->template as<typename Schema::IfcMaterialDefinition>()) {
179-
auto defs = mdef->HasProperties();
180-
for (auto it = defs->begin(); it != defs->end(); ++it) {
181-
auto& def = *it;
175+
if (auto mdef = inst.template as<typename Schema::IfcMaterialDefinition>()) {
176+
auto defs = mdef.HasProperties();
177+
for (auto& def : defs) {
182178
process_pset<Schema>(props, def);
183179
}
184180
}
185-
if (auto pdef = inst->template as<typename Schema::IfcProfileDef>()) {
181+
if (auto pdef = inst.template as<typename Schema::IfcProfileDef>()) {
186182
auto defs = pdef->HasProperties();
187-
for (auto it = defs->begin(); it != defs->end(); ++it) {
188-
auto& def = *it;
183+
for (auto& def : defs) {
189184
process_pset<Schema>(props, def);
190185
}
191186
}
192187
}
193-
if (auto ob = inst->template as<typename Schema::IfcObject>()) {
188+
if (auto ob = inst.template as<typename Schema::IfcObject>()) {
194189
if constexpr (is_ifc4_or_higher<Schema>::value) {
195-
auto rels = ob->IsTypedBy();
196-
for (auto it = rels->begin(); it != rels->end(); ++it) {
197-
auto& rel = *it;
190+
auto rels = ob.IsTypedBy();
191+
for (auto& rel : rels) {
198192
get_psets_s<Schema>(props, rel->RelatingType());
199193
}
200194
}
201195
{
202-
auto rels = ob->IsDefinedBy();
203-
for (auto it = rels->begin(); it != rels->end(); ++it) {
204-
auto& rel = *it;
205-
if (auto bytype = rel->template as<typename Schema::IfcRelDefinesByType>()) {
196+
auto rels = ob.IsDefinedBy();
197+
for (auto& rel : rels) {
198+
if (auto bytype = rel.template as<typename Schema::IfcRelDefinesByType>()) {
206199
get_psets_s<Schema>(props, bytype->RelatingType());
207-
} else if (auto byprops = rel->template as<typename Schema::IfcRelDefinesByProperties>()) {
200+
} else if (auto byprops = rel.template as<typename Schema::IfcRelDefinesByProperties>()) {
208201
process_pset<Schema>(props, byprops->RelatingPropertyDefinition());
209202
}
210203
}
@@ -220,10 +213,10 @@ void get_psets_s(element_properties& props, const typename Schema::IfcObjectDefi
220213
#define GENERATE_LITERAL_STRING(elem) "Ifc" # elem
221214

222215
#define TEST_AND_DISPATCH(r, data, elem) \
223-
if (strcasecmp(schema_name, GENERATE_LITERAL_STRING(elem)) == 0) { get_psets_s<EXPAND_AND_CONCATENATE(elem)>(props, inst->as<EXPAND_AND_CONCATENATE(elem)::IfcObjectDefinition>()); }
216+
if (strcasecmp(schema_name, GENERATE_LITERAL_STRING(elem)) == 0) { get_psets_s<EXPAND_AND_CONCATENATE(elem)>(props, inst.as<EXPAND_AND_CONCATENATE(elem)::IfcObjectDefinition>()); }
224217

225-
void get_psets(element_properties& props, const IfcUtil::IfcBaseClass* inst) {
226-
auto schema_name = inst->declaration().schema()->name().c_str();
218+
void get_psets(element_properties& props, const express::Base& inst) {
219+
auto schema_name = inst.declaration().schema()->name().c_str();
227220
BOOST_PP_SEQ_FOR_EACH(TEST_AND_DISPATCH, , SCHEMA_SEQ)
228221
}
229222

@@ -259,19 +252,17 @@ int main(int argc, char** argv) {
259252
// we need to cast them to IfcWindows. Since these properties
260253
// are optional we need to make sure the properties are
261254
// defined for the window in question before accessing them.
262-
IfcSchema::IfcBuildingElement::list::ptr elements = file.instances_by_type<IfcSchema::IfcBuildingElement>();
255+
auto elements = file.instances_by_type<IfcSchema::IfcBuildingElement>();
263256

264-
std::cout << "Found " << elements->size() << " elements in " << argv[1] << ":" << std::endl;
257+
std::cout << "Found " << elements.size() << " elements in " << argv[1] << ":" << std::endl;
265258

266-
for (auto it = elements->begin(); it != elements->end(); ++it) {
267-
const auto* element = *it;
268-
element->toString(std::cout);
259+
for (auto& element : elements) {
260+
element.toString(std::cout);
269261
std::cout << std::endl;
270262

271-
const IfcSchema::IfcWindow* window;
272-
if ((window = element->as<IfcSchema::IfcWindow>()) != 0) {
273-
if (window->OverallWidth() && window->OverallHeight()) {
274-
const double area = *window->OverallWidth() * *window->OverallHeight();
263+
if (auto window = element.as<IfcSchema::IfcWindow>()) {
264+
if (window.OverallWidth() && window.OverallHeight()) {
265+
const double area = *window.OverallWidth() * *window.OverallHeight();
275266
std::cout << "The area of this window is " << area << std::endl;
276267
}
277268
}

src/ifcparse/IfcFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,8 @@ express::Base IfcParse::impl::in_memory_file_storage::create(const IfcParse::dec
780780
}
781781
auto ptr = byid_.insert({instance_name, std::make_shared<InstanceData>(file, decl, instance_name, decl->as_entity() ? in_memory_attribute_storage(decl->as_entity()->attribute_count()) : in_memory_attribute_storage(1))}).first;
782782
express::Base inst(ptr->second);
783-
// @todo addEntity should only be used for copying behaviour now, not during creation
784-
file->addEntity(inst);
783+
784+
add_type_ref(inst);
785785

786786
return inst;
787787
}

src/ifcparse/IfcFile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <map>
3737

3838
#ifdef IFOPSH_WITH_ROCKSDB
39+
3940
#include <rocksdb/merge_operator.h>
4041

4142
namespace {

0 commit comments

Comments
 (0)