Skip to content

Commit 5b85a2c

Browse files
committed
Fix examples
1 parent bc46a8f commit 5b85a2c

File tree

2 files changed

+47
-34
lines changed

2 files changed

+47
-34
lines changed

src/examples/IfcParseExamples.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ void get_psets_s(element_properties& props, const typename Schema::IfcObjectDefi
196196
auto rels = ob.IsDefinedBy();
197197
for (auto& rel : rels) {
198198
if (auto bytype = rel.template as<typename Schema::IfcRelDefinesByType>()) {
199-
get_psets_s<Schema>(props, bytype->RelatingType());
199+
get_psets_s<Schema>(props, bytype.RelatingType());
200200
} else if (auto byprops = rel.template as<typename Schema::IfcRelDefinesByProperties>()) {
201-
process_pset<Schema>(props, byprops->RelatingPropertyDefinition());
201+
process_pset<Schema>(props, byprops.RelatingPropertyDefinition());
202202
}
203203
}
204204
}

src/examples/IfcSimplifiedAlignment.cpp

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,37 +39,49 @@
3939

4040
// performs basic project setup including created the IfcProject object
4141
// and initializing the project units to FEET
42-
Schema::IfcProject* setup_project(IfcHierarchyHelper<Schema>& file) {
42+
Schema::IfcProject setup_project(IfcHierarchyHelper<Schema>& file) {
4343
std::vector<std::string> file_description;
4444
file_description.push_back("ViewDefinition[Alignment-basedReferenceView]");
45-
file.header().file_description()->setdescription(file_description);
45+
file.header().file_description().setdescription(file_description);
4646

4747
auto project = file.addProject();
48-
project->setName(std::string("FHWA Bridge Geometry Manual Example Alignment"));
49-
project->setDescription(std::string("C++ Example - Simplified"));
48+
project.setName(std::string("FHWA Bridge Geometry Manual Example Alignment"));
49+
project.setDescription(std::string("C++ Example - Simplified"));
5050

5151
// set up project units for feet
5252
// the call to file.addProject() sets up length units as millimeter.
53-
auto units_in_context = project->UnitsInContext();
54-
auto units = units_in_context->Units();
55-
auto begin = units->begin();
53+
auto units_in_context = project.UnitsInContext();
54+
auto units = units_in_context.Units();
55+
auto begin = units.begin();
5656
auto iter = begin;
57-
auto end = units->end();
57+
auto end = units.end();
5858
for (; iter != end; iter++) {
5959
auto unit = *iter;
60-
if (unit->as<Schema::IfcSIUnit>() && unit->as<Schema::IfcSIUnit>()->UnitType() == Schema::IfcUnitEnum::IfcUnit_LENGTHUNIT) {
61-
auto dimensions = new Schema::IfcDimensionalExponents(1, 0, 0, 0, 0, 0, 0);
62-
file.addEntity(dimensions);
63-
64-
auto conversion_factor = new Schema::IfcMeasureWithUnit(new Schema::IfcLengthMeasure(304.80), unit->as<Schema::IfcSIUnit>());
65-
file.addEntity(conversion_factor);
66-
67-
auto conversion_based_unit = new Schema::IfcConversionBasedUnit(dimensions, Schema::IfcUnitEnum::IfcUnit_LENGTHUNIT, "FEET", conversion_factor);
68-
file.addEntity(conversion_based_unit);
69-
70-
units->remove(unit); // remove the millimeter unit
71-
units->push(conversion_based_unit); // add the feet unit
72-
units_in_context->setUnits(units); // update the UnitsInContext
60+
if (unit.as<Schema::IfcSIUnit>() && unit.as<Schema::IfcSIUnit>().UnitType() == Schema::IfcUnitEnum::IfcUnit_LENGTHUNIT) {
61+
auto dimensions = file.create<Schema::IfcDimensionalExponents>();
62+
dimensions.setLengthExponent(1);
63+
dimensions.setMassExponent(0);
64+
dimensions.setTimeExponent(0);
65+
dimensions.setElectricCurrentExponent(0);
66+
dimensions.setThermodynamicTemperatureExponent(0);
67+
dimensions.setAmountOfSubstanceExponent(0);
68+
dimensions.setLuminousIntensityExponent(0);
69+
70+
auto conversion_factor = file.create<Schema::IfcMeasureWithUnit>();
71+
auto length = file.create<Schema::IfcLengthMeasure>();
72+
length.set_attribute_value(0, 304.80);
73+
conversion_factor.setValueComponent(length);
74+
conversion_factor.setUnitComponent(unit);
75+
76+
auto conversion_based_unit = file.create<Schema::IfcConversionBasedUnit>();
77+
conversion_based_unit.setDimensions(dimensions);
78+
conversion_based_unit.setUnitType(Schema::IfcUnitEnum::IfcUnit_LENGTHUNIT);
79+
conversion_based_unit.setName("FEET");
80+
conversion_based_unit.setConversionFactor(conversion_factor);
81+
82+
units.erase(std::remove(units.begin(), units.end(), unit)); // remove the millimeter unit
83+
units.push_back(conversion_based_unit); // add the feet unit
84+
units_in_context.setUnits(units); // update the UnitsInContext
7385

7486
break; // Done!, the length unit was found, so break out of the loop
7587
}
@@ -129,10 +141,11 @@ int main() {
129141
// IFC 4.1.4.1.1 "Every IfcAlignment must be related to IfcProject using the IfcRelAggregates relationship"
130142
// https://standards.buildingsmart.org/IFC/RELEASE/IFC4_3/HTML/concepts/Object_Composition/Aggregation/Alignment_Aggregation_To_Project/content.html
131143
// IfcProject <-> IfcRelAggregates <-> IfcAlignment
132-
typename aggregate_of<typename Schema::IfcObjectDefinition>::ptr list_of_alignments_in_project(new aggregate_of<typename Schema::IfcObjectDefinition>());
133-
list_of_alignments_in_project->push(alignment);
134-
auto aggregate_alignments_with_project = new Schema::IfcRelAggregates(IfcParse::IfcGlobalId(), nullptr, std::string("Alignments in project"), boost::none, project, list_of_alignments_in_project);
135-
file.addEntity(aggregate_alignments_with_project);
144+
auto aggregate_alignments_with_project = file.create<Schema::IfcRelAggregates>();
145+
aggregate_alignments_with_project.setGlobalId(IfcParse::IfcGlobalId());
146+
aggregate_alignments_with_project.setName("Alignments in project");
147+
aggregate_alignments_with_project.setRelatingObject(project);
148+
aggregate_alignments_with_project.setRelatedObjects({alignment});
136149

137150
// Define the spatial structure of the alignment with respect to the site
138151

@@ -141,21 +154,21 @@ int main() {
141154
// IfcSite <-> IfcRelReferencedInSpatialStructure <-> IfcAlignment
142155
// This means IfcAlignment is not part of the IfcSite (it is not an aggregate component) but instead IfcAlignment is used within
143156
// the IfcSite by reference. This implies an IfcAlignment can traverse many IfcSite instances within an IfcProject
144-
typename Schema::IfcSpatialReferenceSelect::list::ptr list_alignments_referenced_in_site(new Schema::IfcSpatialReferenceSelect::list);
145-
list_alignments_referenced_in_site->push(alignment);
146-
147157
// Complete the model by creating sites for the 3 bridges
148158
for (int i = 1; i <= 3; i++) {
149159
std::ostringstream os;
150160
os << "Site of Bridge " << i;
151-
auto site = file.addSite(project, nullptr);
152-
site->setName(os.str());
161+
auto site = file.addSite(project);
162+
site.setName(os.str());
153163

154164
std::ostringstream description;
155165
description << "Alignments referenced into the spatial structure of Bridge Site " << i;
156166

157-
auto rel_referenced_in_spatial_structure = new Schema::IfcRelReferencedInSpatialStructure(IfcParse::IfcGlobalId(), nullptr, boost::none, description.str(), list_alignments_referenced_in_site, site);
158-
file.addEntity(rel_referenced_in_spatial_structure);
167+
auto rel_referenced_in_spatial_structure = file.create<Schema::IfcRelReferencedInSpatialStructure>();
168+
rel_referenced_in_spatial_structure.setGlobalId(IfcParse::IfcGlobalId());
169+
rel_referenced_in_spatial_structure.setDescription(description.str());
170+
rel_referenced_in_spatial_structure.setRelatedElements(std::vector<Schema::IfcSpatialReferenceSelect>{alignment});
171+
rel_referenced_in_spatial_structure.setRelatingStructure(site);
159172
}
160173

161174
// That's it - save the model to a file

0 commit comments

Comments
 (0)