1+ /* *******************************************************************************
2+ * *
3+ * This file is part of IfcOpenShell. *
4+ * *
5+ * IfcOpenShell is free software: you can redistribute it and/or modify *
6+ * it under the terms of the Lesser GNU General Public License as published by *
7+ * the Free Software Foundation, either version 3.0 of the License, or *
8+ * (at your option) any later version. *
9+ * *
10+ * IfcOpenShell is distributed in the hope that it will be useful, *
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13+ * Lesser GNU General Public License for more details. *
14+ * *
15+ * You should have received a copy of the Lesser GNU General Public License *
16+ * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+ * *
18+ ********************************************************************************/
19+
20+ /* *******************************************************************************
21+ * *
22+ * Example that generates various forms of IfcFace *
23+ * *
24+ ********************************************************************************/
25+
26+ #include " ../ifcparse/Ifc2x3.h"
27+ #include " ../ifcparse/IfcUtil.h"
28+ #include " ../ifcparse/IfcHierarchyHelper.h"
29+
30+ typedef std::string S;
31+ typedef IfcParse::IfcGlobalId guid;
32+ boost::none_t const null = (static_cast <boost::none_t >(0 ));
33+
34+ static int x = 0 ;
35+
36+ void create_testcase (IfcHierarchyHelper& file, IfcSchema::IfcFace* face, const std::string& name) {
37+ IfcSchema::IfcFace::list::ptr faces (new IfcSchema::IfcFace::list);
38+ faces->push (face);
39+ IfcSchema::IfcOpenShell* shell = new IfcSchema::IfcOpenShell (faces);
40+
41+ IfcSchema::IfcConnectedFaceSet::list::ptr shells (new IfcSchema::IfcConnectedFaceSet::list);
42+ shells->push (shell);
43+ IfcSchema::IfcFaceBasedSurfaceModel* model = new IfcSchema::IfcFaceBasedSurfaceModel (shells);
44+
45+ IfcSchema::IfcBuildingElementProxy* product = new IfcSchema::IfcBuildingElementProxy (
46+ guid (), 0 , name, null, null, 0 , 0 , null, null);
47+ file.addBuildingProduct (product);
48+ product->setOwnerHistory (file.getSingle <IfcSchema::IfcOwnerHistory>());
49+
50+ product->setObjectPlacement (file.addLocalPlacement (0 , 1000 * x++, 0 ));
51+
52+ IfcSchema::IfcRepresentation::list::ptr reps (new IfcSchema::IfcRepresentation::list);
53+ IfcSchema::IfcRepresentationItem::list::ptr items (new IfcSchema::IfcRepresentationItem::list);
54+
55+ items->push (model);
56+ IfcSchema::IfcShapeRepresentation* rep = new IfcSchema::IfcShapeRepresentation (
57+ file.getRepresentationContext (" Model" ), S (" Body" ), S (" SurfaceModel" ), items);
58+ reps->push (rep);
59+
60+ IfcSchema::IfcProductDefinitionShape* shape = new IfcSchema::IfcProductDefinitionShape (0 , 0 , reps);
61+ file.addEntity (shape);
62+
63+ product->setRepresentation (shape);
64+ }
65+
66+ int main (int argc, char ** argv) {
67+ IfcHierarchyHelper file;
68+ {
69+ IfcSchema::IfcCartesianPoint::list::ptr points (new IfcSchema::IfcCartesianPoint::list);
70+ points->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(-400 , -400 , 0 ));
71+ points->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(+400 , -400 , 0 ));
72+ points->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(+400 , +400 , 0 ));
73+ points->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(-400 , +400 , 0 ));
74+ IfcSchema::IfcPolyLoop* loop = new IfcSchema::IfcPolyLoop (points);
75+ IfcSchema::IfcFaceOuterBound* bound = new IfcSchema::IfcFaceOuterBound (loop, true );
76+
77+ IfcSchema::IfcFaceBound::list::ptr bounds (new IfcSchema::IfcFaceBound::list);
78+ bounds->push (bound);
79+ IfcSchema::IfcFace* face = new IfcSchema::IfcFace (bounds);
80+ create_testcase (file, face, " polyloop" );
81+ }
82+ {
83+ IfcSchema::IfcCartesianPoint* point1 = file.addTriplet <IfcSchema::IfcCartesianPoint>(+400 , 0 ., 0 .);
84+ IfcSchema::IfcCartesianPoint* point2 = file.addTriplet <IfcSchema::IfcCartesianPoint>(-400 , 0 ., 0 .);
85+ IfcSchema::IfcVertexPoint* vertex1 = new IfcSchema::IfcVertexPoint (point1);
86+ IfcSchema::IfcVertexPoint* vertex2 = new IfcSchema::IfcVertexPoint (point2);
87+ IfcSchema::IfcCircle* circle = new IfcSchema::IfcCircle (file.addPlacement2d (), 400 .);
88+ IfcSchema::IfcEdgeCurve* edge1 = new IfcSchema::IfcEdgeCurve (vertex1, vertex2, circle, true );
89+ IfcSchema::IfcEdgeCurve* edge2 = new IfcSchema::IfcEdgeCurve (vertex2, vertex1, circle, true );
90+ IfcSchema::IfcOrientedEdge* oriented_edge1 = new IfcSchema::IfcOrientedEdge (edge1, true );
91+ IfcSchema::IfcOrientedEdge* oriented_edge2 = new IfcSchema::IfcOrientedEdge (edge2, true );
92+ IfcSchema::IfcOrientedEdge::list::ptr edges (new IfcSchema::IfcOrientedEdge::list);
93+ edges->push (oriented_edge1);
94+ edges->push (oriented_edge2);
95+ IfcSchema::IfcEdgeLoop* loop = new IfcSchema::IfcEdgeLoop (edges);
96+ IfcSchema::IfcFaceOuterBound* bound = new IfcSchema::IfcFaceOuterBound (loop, true );
97+
98+ IfcSchema::IfcFaceBound::list::ptr bounds (new IfcSchema::IfcFaceBound::list);
99+ bounds->push (bound);
100+ IfcSchema::IfcFace* face = new IfcSchema::IfcFace (bounds);
101+ create_testcase (file, face, " circle" );
102+ }
103+ {
104+ IfcSchema::IfcCartesianPoint::list::ptr points (new IfcSchema::IfcCartesianPoint::list);
105+ points->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(-400 , -400 , 0 ));
106+ points->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(+400 , -400 , 0 ));
107+ points->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(+400 , +400 , 0 ));
108+ points->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(-400 , +400 , 0 ));
109+ IfcSchema::IfcPolyLoop* loop = new IfcSchema::IfcPolyLoop (points);
110+ IfcSchema::IfcFaceOuterBound* outer_bound = new IfcSchema::IfcFaceOuterBound (loop, true );
111+
112+ IfcSchema::IfcCartesianPoint::list::ptr points2 (new IfcSchema::IfcCartesianPoint::list);
113+ points2->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(-300 , -300 , 0 ));
114+ points2->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(-100 , -300 , 0 ));
115+ points2->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(-100 , +300 , 0 ));
116+ points2->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(-300 , +300 , 0 ));
117+ IfcSchema::IfcPolyLoop* loop2 = new IfcSchema::IfcPolyLoop (points2);
118+ IfcSchema::IfcFaceBound* inner_bound1 = new IfcSchema::IfcFaceBound (loop2, false );
119+
120+ IfcSchema::IfcCartesianPoint::list::ptr points3 (new IfcSchema::IfcCartesianPoint::list);
121+ points3->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(+100 , +300 , 0 ));
122+ points3->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(+300 , +300 , 0 ));
123+ points3->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(+300 , -300 , 0 ));
124+ points3->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(+100 , -300 , 0 ));
125+ IfcSchema::IfcPolyLoop* loop3 = new IfcSchema::IfcPolyLoop (points3);
126+ IfcSchema::IfcFaceBound* inner_bound2 = new IfcSchema::IfcFaceBound (loop3, true );
127+
128+ IfcSchema::IfcFaceBound::list::ptr bounds (new IfcSchema::IfcFaceBound::list);
129+ bounds->push (inner_bound1);
130+ bounds->push (outer_bound);
131+ bounds->push (inner_bound2);
132+ IfcSchema::IfcFace* face = new IfcSchema::IfcFace (bounds);
133+ create_testcase (file, face, " polyloop with holes" );
134+ }
135+ {
136+ IfcSchema::IfcCartesianPoint::list::ptr points (new IfcSchema::IfcCartesianPoint::list);
137+ points->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(-400 , -400 , 0 ));
138+ points->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(-100 , -400 , 0 ));
139+ points->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(-100 , +400 , 0 ));
140+ points->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(-400 , +400 , 0 ));
141+ IfcSchema::IfcPolyLoop* loop = new IfcSchema::IfcPolyLoop (points);
142+ IfcSchema::IfcFaceOuterBound* bound1 = new IfcSchema::IfcFaceOuterBound (loop, true );
143+
144+ IfcSchema::IfcCartesianPoint::list::ptr points2 (new IfcSchema::IfcCartesianPoint::list);
145+ points2->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(+100 , +400 , 0 ));
146+ points2->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(+400 , +400 , 0 ));
147+ points2->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(+400 , -400 , 0 ));
148+ points2->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(+100 , -400 , 0 ));
149+ IfcSchema::IfcPolyLoop* loop2 = new IfcSchema::IfcPolyLoop (points2);
150+ IfcSchema::IfcFaceOuterBound* bound2 = new IfcSchema::IfcFaceOuterBound (loop2, false );
151+
152+ IfcSchema::IfcFaceBound::list::ptr bounds (new IfcSchema::IfcFaceBound::list);
153+ bounds->push (bound1);
154+ bounds->push (bound2);
155+ IfcSchema::IfcFace* face = new IfcSchema::IfcFace (bounds);
156+ create_testcase (file, face, " multiple outer boundaries (invalid)" );
157+ }
158+ {
159+ IfcSchema::IfcCartesianPoint::list::ptr points (new IfcSchema::IfcCartesianPoint::list);
160+ points->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(-400 , -400 , 1e-6 ));
161+ points->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(+400 , -400 , 0 ));
162+ points->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(+400 , +400 , 0 ));
163+ points->push (file.addTriplet <IfcSchema::IfcCartesianPoint>(-400 , +400 , 0 ));
164+ IfcSchema::IfcPolyLoop* loop = new IfcSchema::IfcPolyLoop (points);
165+ IfcSchema::IfcFaceOuterBound* bound = new IfcSchema::IfcFaceOuterBound (loop, true );
166+
167+ IfcSchema::IfcFaceBound::list::ptr bounds (new IfcSchema::IfcFaceBound::list);
168+ bounds->push (bound);
169+ IfcSchema::IfcFace* face = new IfcSchema::IfcFace (bounds);
170+ create_testcase (file, face, " imprecise polyloop" );
171+ }
172+ const std::string filename = " faces.ifc" ;
173+ file.header ().file_name ().name (filename);
174+ std::ofstream f (filename.c_str ());
175+ f << file;
176+ }
0 commit comments