MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / main

Function main

src/examples/IfcParseExamples.cpp:230–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

228}
229
230int main(int argc, char** argv) {
231 if (argc != 2) {
232 std::cout << "usage: IfcParseExamples <filename.ifc>" << std::endl;
233 return 1;
234 }
235
236 // Redirect the output (both progress and log) to stdout
237 Logger::SetOutput(&std::cout, &std::cout);
238
239 // Parse the IFC file provided in argv[1]
240 IfcParse::IfcFile file(argv[1]);
241 if (!file.good()) {
242 std::cout << "Unable to parse .ifc file" << std::endl;
243 return 1;
244 }
245
246 // Lets get a list of IfcBuildingElements, this is the parent
247 // type of things like walls, windows and doors.
248 // entitiesByType is a templated function and returns a
249 // templated class that behaves like a std::vector.
250 // Note that the return types are all typedef'ed as members of
251 // the generated classes, ::list for the templated vector class,
252 // ::ptr for a shared pointer and ::it for an iterator.
253 // We will simply iterate over the vector and print a string
254 // representation of the entity to stdout.
255 //
256 // Secondly, lets find out which of them are IfcWindows.
257 // In order to access the additional properties that windows
258 // have on top af the properties of building elements,
259 // we need to cast them to IfcWindows. Since these properties
260 // are optional we need to make sure the properties are
261 // defined for the window in question before accessing them.
262 IfcSchema::IfcBuildingElement::list::ptr elements = file.instances_by_type<IfcSchema::IfcBuildingElement>();
263
264 std::cout << "Found " << elements->size() << " elements in " << argv[1] << ":" << std::endl;
265
266 for (auto it = elements->begin(); it != elements->end(); ++it) {
267 const auto* element = *it;
268 element->toString(std::cout);
269 std::cout << std::endl;
270
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();
275 std::cout << "The area of this window is " << area << std::endl;
276 }
277 }
278
279 element_properties props;
280 get_psets(props, element);
281
282 for (auto& ps : props) {
283 std::cout << ps.first << std::endl;
284 std::cout << std::string(ps.first.size(), '=') << std::endl;
285 size_t max_key_len = 0;
286 for (auto& p : ps.second) {
287 if (p.first.size() > max_key_len) {

Callers

nothing calls this directly

Calls 5

toStringMethod · 0.80
get_psetsFunction · 0.70
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected