Skip to content

Commit f725e05

Browse files
Merge pull request #7486 from EstebanDugueperoux2/TestAllExamples
cmake: Try to build and run others examples
2 parents 953c5fd + 8f3715c commit f725e05

File tree

14 files changed

+187
-169
lines changed

14 files changed

+187
-169
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,36 @@ jobs:
209209
210210
- name: Build standalone examples to test cmake package
211211
run: |
212+
set -x
212213
cd src/examples
213214
mkdir build && cd build
214215
cmake .. -DCMAKE_BUILD_TYPE=Release \
215216
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
216217
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
217218
cmake --build .
219+
./arbitrary_open_profile_def && test -f arbitrary_open_profile_def.ifc
220+
./composite_profile_def && test -f composite_profile_def.ifc
221+
./csg_primitive && test -f csg_primitive.ifc
222+
./ellipse_pies && test -f ellipse_pies.ifc
223+
./faces && test -f faces.ifc
224+
./ifc_curve_rebar && test -f ifc_curve_rebar.ifc
225+
./profiles
226+
test -f IfcUShapeProfileDef.ifc
227+
test -f IfcTShapeProfileDef.ifc
228+
test -f IfcZShapeProfileDef.ifc
229+
test -f IfcEllipseProfileDef.ifc
230+
test -f IfcIShapeProfileDef.ifc
231+
test -f IfcLShapeProfileDef.ifc
232+
test -f IfcCShapeProfileDef.ifc
233+
test -f IfcCircleProfileDef.ifc
234+
test -f IfcRectangleProfileDef.ifc
235+
test -f IfcTrapeziumProfileDef.ifc
218236
./IfcParseExamples "../IfcParseExamples_test.ifc"
219-
./IfcOpenHouse
220-
./IfcAdvancedHouse
221-
./IfcAlignment
222-
./IfcSimplifiedAlignment
237+
./IfcOpenHouse && test -f IfcOpenHouse.ifc
238+
./IfcAdvancedHouse && test -f IfcAdvancedHouse.ifc
239+
./IfcAlignment && test -f IfcAlignment.ifc
240+
./IfcSimplifiedAlignment && test -f IfcSimplifiedAlignment.ifc
241+
./triangulated_faceset && test -f triangulated_faceset.ifc
223242
224243
- name: Test ifcopenshell-python
225244
run: |

src/examples/CMakeLists.txt

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,51 +35,41 @@ else()
3535
include_directories("${CMAKE_SOURCE_DIR}/../src")
3636
endif()
3737

38-
if(SCHEMA_VERSIONS MATCHES "2x3")
39-
add_executable(IfcParseExamples IfcParseExamples.cpp)
38+
macro(build_example exe_name)
39+
set (additional_targets ${ARGN})
40+
add_executable(${exe_name} ${exe_name}.cpp)
4041

4142
if(STANDALONE_PROJECT)
42-
target_link_libraries(IfcParseExamples IfcOpenShell::IfcParse)
43+
target_link_libraries(${exe_name} IfcOpenShell::IfcParse $<$<BOOL:${additional_targets}>:IfcOpenShell::${additional_targets}>)
4344
else()
44-
target_include_directories(IfcParseExamples PRIVATE "${CMAKE_SOURCE_DIR}/../src")
45-
target_link_libraries(IfcParseExamples IfcParse)
46-
set_target_properties(IfcParseExamples PROPERTIES FOLDER Examples)
45+
target_include_directories(${exe_name} PRIVATE "${CMAKE_SOURCE_DIR}/../src")
46+
target_link_libraries(${exe_name} IfcParse ${additional_targets})
47+
set_target_properties(${exe_name} PROPERTIES FOLDER Examples)
4748
endif()
48-
install(TARGETS IfcParseExamples)
49+
install(TARGETS ${exe_name})
50+
endmacro()
4951

50-
if(WITH_OPENCASCADE)
51-
add_executable(IfcOpenHouse IfcOpenHouse.cpp)
52-
add_executable(IfcAdvancedHouse IfcAdvancedHouse.cpp)
53-
add_library(IfcHouseInterface INTERFACE)
54-
55-
if(STANDALONE_PROJECT)
56-
target_link_libraries(IfcHouseInterface INTERFACE IfcOpenShell::IfcParse IfcOpenShell::geometry_serializer)
57-
else()
58-
target_link_libraries(IfcHouseInterface INTERFACE IfcParse geometry_serializer)
59-
set_target_properties(IfcOpenHouse PROPERTIES FOLDER Examples)
60-
set_target_properties(IfcAdvancedHouse PROPERTIES FOLDER Examples)
61-
endif()
62-
target_link_libraries(IfcOpenHouse PRIVATE IfcHouseInterface)
63-
target_link_libraries(IfcAdvancedHouse PRIVATE IfcHouseInterface)
64-
install(TARGETS IfcOpenHouse IfcAdvancedHouse)
65-
endif()
52+
if("4" IN_LIST SCHEMA_VERSIONS)
53+
build_example(arbitrary_open_profile_def)
54+
build_example(triangulated_faceset)
6655
endif()
6756

68-
if(SCHEMA_VERSIONS MATCHES "4x3_add2")
69-
add_executable(IfcAlignment IfcAlignment.cpp)
70-
add_executable(IfcSimplifiedAlignment IfcSimplifiedAlignment.cpp)
71-
add_library(IfcAlignmentInterface INTERFACE)
57+
if("2x3" IN_LIST SCHEMA_VERSIONS)
58+
build_example(composite_profile_def)
59+
build_example(csg_primitive)
60+
build_example(ellipse_pies)
61+
build_example(faces)
62+
build_example(ifc_curve_rebar)
63+
build_example(profiles)
64+
build_example(IfcParseExamples)
7265

73-
if(STANDALONE_PROJECT)
74-
target_link_libraries(IfcAlignmentInterface INTERFACE IfcOpenShell::IfcParse)
75-
else()
76-
target_link_libraries(IfcAlignmentInterface INTERFACE IfcParse)
77-
set_target_properties(IfcAlignment PROPERTIES FOLDER Examples)
78-
set_target_properties(IfcSimplifiedAlignment PROPERTIES FOLDER Examples)
66+
if(WITH_OPENCASCADE)
67+
build_example(IfcOpenHouse geometry_serializer)
68+
build_example(IfcAdvancedHouse geometry_serializer)
7969
endif()
70+
endif()
8071

81-
target_link_libraries(IfcAlignment PRIVATE IfcAlignmentInterface)
82-
target_link_libraries(IfcSimplifiedAlignment PRIVATE IfcAlignmentInterface)
83-
84-
install(TARGETS IfcAlignment IfcSimplifiedAlignment)
72+
if("4x3_add2" IN_LIST SCHEMA_VERSIONS)
73+
build_example(IfcAlignment)
74+
build_example(IfcSimplifiedAlignment)
8575
endif()

src/examples/IfcAlignment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,6 @@ int main() {
489489
}
490490

491491
// That's it - save the model to a file
492-
std::ofstream ofs("FHWA_Bridge_Geometry_Alignment_Example.ifc");
492+
std::ofstream ofs("IfcAlignment.ifc");
493493
ofs << file;
494494
}

src/examples/IfcSimplifiedAlignment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,6 @@ int main() {
159159
}
160160

161161
// That's it - save the model to a file
162-
std::ofstream ofs("FHWA_Bridge_Geometry_Alignment_Example_Simplified.ifc");
162+
std::ofstream ofs("IfcSimplifiedAlignment.ifc");
163163
ofs << file;
164164
}

src/examples/arbitrary_open_profile_def.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@
2828
#include <iostream>
2929
#include <fstream>
3030

31-
#include "../ifcparse/Ifc2x3.h"
32-
#include "../ifcparse/IfcUtil.h"
33-
#include "../ifcparse/IfcHierarchyHelper.h"
31+
#define IfcSchema Ifc4
32+
#include "ifcparse/Ifc4.h"
33+
#include "ifcparse/IfcHierarchyHelper.h"
3434

3535
typedef std::string S;
3636
typedef IfcParse::IfcGlobalId guid;
3737
boost::none_t const null = boost::none;
3838
static int i = 0;
3939

40-
void create_product_from_item(IfcHierarchyHelper& file, IfcSchema::IfcRepresentationItem* item, const std::string& s) {
40+
void create_product_from_item(IfcHierarchyHelper<IfcSchema>& file, IfcSchema::IfcRepresentationItem* item, const std::string& s) {
4141
IfcSchema::IfcBuildingElementProxy* product = new IfcSchema::IfcBuildingElementProxy(
4242
guid(), 0, S("product"), null, null, 0, 0, null, null);
4343
file.addBuildingProduct(product);
@@ -50,7 +50,7 @@ void create_product_from_item(IfcHierarchyHelper& file, IfcSchema::IfcRepresenta
5050
items->push(item);
5151

5252
if (s == "GeometricSet") {
53-
IfcSchema::IfcGeometricSet* set = new IfcSchema::IfcGeometricSet(items->generalize());
53+
IfcSchema::IfcGeometricSet* set = new IfcSchema::IfcGeometricSet(items->as<IfcSchema::IfcGeometricSetSelect>());
5454
file.addEntity(set);
5555
items = IfcSchema::IfcRepresentationItem::list::ptr(new IfcSchema::IfcRepresentationItem::list());
5656
items->push(set);
@@ -67,7 +67,7 @@ void create_product_from_item(IfcHierarchyHelper& file, IfcSchema::IfcRepresenta
6767
product->setRepresentation(shape);
6868
}
6969

70-
void create_surfaces_from_profile(IfcHierarchyHelper& file, IfcSchema::IfcProfileDef* profile) {
70+
void create_surfaces_from_profile(IfcHierarchyHelper<IfcSchema>& file, IfcSchema::IfcProfileDef* profile) {
7171
IfcSchema::IfcSurfaceOfLinearExtrusion* extrusion = new IfcSchema::IfcSurfaceOfLinearExtrusion(profile, file.addPlacement3d(), file.addTriplet<IfcSchema::IfcDirection>(0, 0, 1), 100.);
7272
file.addEntity(extrusion);
7373

@@ -80,7 +80,7 @@ void create_surfaces_from_profile(IfcHierarchyHelper& file, IfcSchema::IfcProfil
8080
create_product_from_item(file, revolution, "GeometricSet");
8181
}
8282

83-
void create_solids_from_profile(IfcHierarchyHelper& file, IfcSchema::IfcProfileDef* profile) {
83+
void create_solids_from_profile(IfcHierarchyHelper<IfcSchema>& file, IfcSchema::IfcProfileDef* profile) {
8484
IfcSchema::IfcExtrudedAreaSolid* extrusion = new IfcSchema::IfcExtrudedAreaSolid(profile, file.addPlacement3d(), file.addTriplet<IfcSchema::IfcDirection>(0, 0, 1), 100.);
8585
file.addEntity(extrusion);
8686

@@ -96,7 +96,7 @@ void create_solids_from_profile(IfcHierarchyHelper& file, IfcSchema::IfcProfileD
9696
create_product_from_item(file, revolution2, "SweptSolid");
9797
}
9898

99-
void create_products_from_curve(IfcHierarchyHelper& file, IfcSchema::IfcBoundedCurve* curve) {
99+
void create_products_from_curve(IfcHierarchyHelper<IfcSchema>& file, IfcSchema::IfcBoundedCurve* curve) {
100100
IfcSchema::IfcArbitraryOpenProfileDef* open = new IfcSchema::IfcArbitraryOpenProfileDef(IfcSchema::IfcProfileTypeEnum::IfcProfileType_CURVE, null, curve);
101101
IfcSchema::IfcCenterLineProfileDef* center_line = new IfcSchema::IfcCenterLineProfileDef(IfcSchema::IfcProfileTypeEnum::IfcProfileType_AREA, null, curve, 10.);
102102
file.addEntity(open);
@@ -107,9 +107,9 @@ void create_products_from_curve(IfcHierarchyHelper& file, IfcSchema::IfcBoundedC
107107
}
108108

109109
int main(int argc, char** argv) {
110-
const char filename[] = "IfcArbitraryOpenProfileDef.ifc";
111-
IfcHierarchyHelper file;
112-
file.header().file_name().name(filename);
110+
const char filename[] = "arbitrary_open_profile_def.ifc";
111+
IfcHierarchyHelper<IfcSchema> file;
112+
file.header().file_name()->setname(filename);
113113

114114
double coords1[] = {-50.0, 0.0};
115115
double coords2[] = { 50.0, 0.0};
@@ -124,17 +124,18 @@ int main(int argc, char** argv) {
124124

125125
IfcSchema::IfcEllipse* ellipse = new IfcSchema::IfcEllipse(file.addPlacement2d(), 50., 25.);
126126
file.addEntity(ellipse);
127-
IfcEntityList::ptr trim1(new IfcEntityList);
128-
IfcEntityList::ptr trim2(new IfcEntityList);
127+
aggregate_of_instance::ptr trim1(new aggregate_of_instance);
128+
aggregate_of_instance::ptr trim2(new aggregate_of_instance);
129129
trim1->push(new IfcSchema::IfcParameterValue( 0.));
130130
trim2->push(new IfcSchema::IfcParameterValue(180.));
131-
IfcSchema::IfcTrimmedCurve* trim = new IfcSchema::IfcTrimmedCurve(ellipse, trim1, trim2, true, IfcSchema::IfcTrimmingPreference::IfcTrimmingPreference_PARAMETER);
131+
IfcSchema::IfcTrimmedCurve* trim = new IfcSchema::IfcTrimmedCurve(ellipse, trim1->as<IfcSchema::IfcTrimmingSelect>(), trim2->as<IfcSchema::IfcTrimmingSelect>(), true, IfcSchema::IfcTrimmingPreference::IfcTrimmingPreference_PARAMETER);
132132
file.addEntity(trim);
133133

134134
create_products_from_curve(file, trim);
135135

136-
file.getSingle<Ifc2x3::IfcProject>()->setName("IfcArbitraryOpenProfileDef");
136+
using namespace std::string_literals;
137+
file.getSingle<IfcSchema::IfcProject>()->setName("arbitrary_open_profile_def"s);
137138

138139
std::ofstream f(filename);
139140
f << file;
140-
}
141+
}

src/examples/composite_profile_def.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@
2727
#include <iostream>
2828
#include <fstream>
2929

30-
#include "../ifcparse/Ifc2x3.h"
31-
#include "../ifcparse/IfcUtil.h"
32-
#include "../ifcparse/IfcHierarchyHelper.h"
30+
#define IfcSchema Ifc2x3
31+
#include "ifcparse/Ifc2x3.h"
32+
#include "ifcparse/IfcHierarchyHelper.h"
3333

3434
typedef std::string S;
3535
typedef IfcParse::IfcGlobalId guid;
3636
boost::none_t const null = boost::none;
3737

3838
int main(int argc, char** argv) {
39-
const char filename[] = "IfcCompositeProfileDef.ifc";
40-
IfcHierarchyHelper file;
41-
file.header().file_name().name(filename);
39+
const char filename[] = "composite_profile_def.ifc";
40+
IfcHierarchyHelper<IfcSchema> file;
41+
file.header().file_name()->setname(filename);
4242

4343
double coords1[] = {100.0, 0.0};
4444
double coords2[] = {200.0, 0.0};
@@ -112,7 +112,8 @@ int main(int argc, char** argv) {
112112

113113
product->setRepresentation(shape);
114114

115-
file.getSingle<IfcSchema::IfcProject>()->setName("IfcCompositeProfileDef");
115+
using namespace std::string_literals;
116+
file.getSingle<IfcSchema::IfcProject>()->setName("composite_profile_def"s);
116117

117118
std::ofstream f(filename);
118119
f << file;

src/examples/csg_primitive.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
#include <iostream>
2828
#include <fstream>
2929

30-
#include "../ifcparse/Ifc2x3.h"
31-
#include "../ifcparse/IfcUtil.h"
32-
#include "../ifcparse/IfcHierarchyHelper.h"
30+
#define IfcSchema Ifc2x3
31+
#include "ifcparse/Ifc2x3.h"
32+
#include "ifcparse/IfcHierarchyHelper.h"
3333

3434
typedef std::string S;
3535
typedef IfcParse::IfcGlobalId guid;
@@ -101,7 +101,7 @@ class Node {
101101
return operate(OP_INTERSECT, p);
102102
}
103103

104-
IfcSchema::IfcRepresentationItem* serialize(IfcHierarchyHelper& file) const {
104+
IfcSchema::IfcRepresentationItem* serialize(IfcHierarchyHelper<IfcSchema>& file) const {
105105
IfcSchema::IfcRepresentationItem* my;
106106
if (op == OP_TERMINAL) {
107107
IfcSchema::IfcAxis2Placement3D* place = file.addPlacement3d(x,y,z,zx,zy,zz,xx,xy,xz);
@@ -117,25 +117,25 @@ class Node {
117117
my = new IfcSchema::IfcRightCircularCone(place, b, a);
118118
}
119119
} else {
120-
IfcSchema::IfcBooleanOperator::IfcBooleanOperator o;
120+
IfcSchema::IfcBooleanOperator o = IfcSchema::IfcBooleanOperator::IfcBooleanOperator_UNION;
121121
if (op == OP_ADD) {
122122
o = IfcSchema::IfcBooleanOperator::IfcBooleanOperator_UNION;
123123
} else if (op == OP_SUBTRACT) {
124124
o = IfcSchema::IfcBooleanOperator::IfcBooleanOperator_DIFFERENCE;
125125
} else if (op == OP_INTERSECT) {
126126
o = IfcSchema::IfcBooleanOperator::IfcBooleanOperator_INTERSECTION;
127127
}
128-
my = new IfcSchema::IfcBooleanResult(o, left->serialize(file), right->serialize(file));
128+
my = new IfcSchema::IfcBooleanResult(o, left->serialize(file)->as<IfcSchema::IfcBooleanOperand>(), right->serialize(file)->as<IfcSchema::IfcBooleanOperand>());
129129
}
130130
file.addEntity(my);
131131
return my;
132132
}
133133
};
134134

135135
int main(int argc, char** argv) {
136-
const char filename[] = "IfcCsgPrimitive.ifc";
137-
IfcHierarchyHelper file;
138-
file.header().file_name().name(filename);
136+
const char filename[] = "csg_primitive.ifc";
137+
IfcHierarchyHelper<IfcSchema> file;
138+
file.header().file_name()->setname(filename);
139139

140140
IfcSchema::IfcRepresentationItem* csg1 = Node::Box(8000.,6000.,3000.).subtract(
141141
Node::Box(7600.,5600.,2800.).move(200.,200.,200.)
@@ -186,7 +186,8 @@ int main(int argc, char** argv) {
186186

187187
product->setRepresentation(shape);
188188

189-
file.getSingle<IfcSchema::IfcProject>()->setName("IfcCompositeProfileDef");
189+
using namespace std::string_literals;
190+
file.getSingle<IfcSchema::IfcProject>()->setName("csg_primitive"s);
190191

191192
std::ofstream f(filename);
192193
f << file;

0 commit comments

Comments
 (0)