2012-07-19 18:26:47 +00:00
|
|
|
/********************************************************************************
|
2011-08-24 12:21:07 +00:00
|
|
|
* *
|
|
|
|
|
* This file is part of IfcOpenShell. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the Lesser GNU General Public License as published by *
|
|
|
|
|
* the Free Software Foundation, either version 3.0 of the License, or *
|
|
|
|
|
* (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* Lesser GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the Lesser GNU General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "../ifcparse/IfcParse.h"
|
|
|
|
|
|
2014-02-17 22:13:55 +00:00
|
|
|
using namespace IfcSchema;
|
2011-08-24 12:21:07 +00:00
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
|
|
|
|
|
|
if ( argc != 2 ) {
|
|
|
|
|
std::cout << "usage: IfcParseExamples <filename.ifc>" << std::endl;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Redirect the output (both progress and log) to stdout
|
2012-08-11 13:24:08 +00:00
|
|
|
Logger::SetOutput(&std::cout,&std::cout);
|
2011-08-24 12:21:07 +00:00
|
|
|
|
|
|
|
|
// Parse the IFC file provided in argv[1]
|
2012-08-11 13:24:08 +00:00
|
|
|
IfcParse::IfcFile file;
|
|
|
|
|
if ( ! file.Init(argv[1]) ) {
|
2011-08-24 12:21:07 +00:00
|
|
|
std::cout << "Unable to parse .ifc file" << std::endl;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Lets get a list of IfcBuildingElements, this is the parent
|
|
|
|
|
// type of things like walls, windows and doors.
|
|
|
|
|
// EntitiesByType is a templated function and returns a
|
|
|
|
|
// templated class that behaves like a std::vector.
|
|
|
|
|
// Note that the return types are all typedef'ed as members of
|
|
|
|
|
// the generated classes, ::list for the templated vector class,
|
|
|
|
|
// ::ptr for a shared pointer and ::it for an iterator.
|
|
|
|
|
// We will simply iterate over the vector and print a string
|
|
|
|
|
// representation of the entity to stdout.
|
|
|
|
|
//
|
|
|
|
|
// Secondly, lets find out which of them are IfcWindows.
|
|
|
|
|
// In order to access the additional properties that windows
|
|
|
|
|
// have on top af the properties of building elements,
|
|
|
|
|
// we need to cast them to IfcWindows. Since these properties
|
|
|
|
|
// are optional we need to make sure the properties are
|
|
|
|
|
// defined for the window in question before accessing them.
|
2014-05-12 13:56:41 +00:00
|
|
|
IfcBuildingElement::list::ptr elements = file.EntitiesByType<IfcBuildingElement>();
|
2011-08-24 12:21:07 +00:00
|
|
|
|
|
|
|
|
std::cout << "Found " << elements->Size() << " elements in " << argv[1] << ":" << std::endl;
|
|
|
|
|
|
2014-05-12 13:56:41 +00:00
|
|
|
for ( IfcBuildingElement::list::it it = elements->begin(); it != elements->end(); ++ it ) {
|
2011-08-24 12:21:07 +00:00
|
|
|
|
2014-05-12 13:56:41 +00:00
|
|
|
const IfcBuildingElement* element = *it;
|
2011-08-24 12:21:07 +00:00
|
|
|
std::cout << element->entity->toString() << std::endl;
|
|
|
|
|
|
|
|
|
|
if ( element->is(IfcWindow::Class()) ) {
|
2014-05-12 13:56:41 +00:00
|
|
|
const IfcWindow* window = (IfcWindow*)element;
|
2011-08-24 12:21:07 +00:00
|
|
|
|
|
|
|
|
if ( window->hasOverallWidth() && window->hasOverallHeight() ) {
|
2012-08-11 13:24:08 +00:00
|
|
|
const double area = window->OverallWidth()*window->OverallHeight();
|
|
|
|
|
std::cout << "The area of this window is " << area << std::endl;
|
2011-08-24 12:21:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|