2014-12-19 12:14:36 +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/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
|
* *
|
|
|
|
|
* Geometrical data in an IFC file consists of shapes (IfcShapeRepresentation) *
|
|
|
|
|
* and instances (SUBTYPE OF IfcBuildingElement e.g. IfcWindow). *
|
|
|
|
|
* *
|
|
|
|
|
* IfcGeom::Representation::Triangulation is a class that represents a *
|
|
|
|
|
* triangulated IfcShapeRepresentation. *
|
|
|
|
|
* Triangulation.verts is a 1 dimensional vector of float defining the *
|
|
|
|
|
* cartesian coordinates of the vertices of the triangulated shape in the *
|
|
|
|
|
* format of [x1,y1,z1,..,xn,yn,zn] *
|
|
|
|
|
* Triangulation.faces is a 1 dimensional vector of int containing the *
|
|
|
|
|
* indices of the triangles referencing positions in Triangulation.verts *
|
|
|
|
|
* Triangulation.edges is a 1 dimensional vector of int in {0,1} that dictates*
|
|
|
|
|
* the visibility of the edges that span the faces in Triangulation.faces *
|
|
|
|
|
* *
|
|
|
|
|
* IfcGeom::Element represents the actual IfcBuildingElements. *
|
|
|
|
|
* IfcGeomObject.name is the GUID of the element *
|
|
|
|
|
* IfcGeomObject.type is the datatype of the element e.g. IfcWindow *
|
|
|
|
|
* IfcGeomObject.mesh is a pointer to an IfcMesh *
|
|
|
|
|
* IfcGeomObject.transformation.matrix is a 4x3 matrix that defines the *
|
|
|
|
|
* orientation and translation of the mesh in relation to the world origin *
|
|
|
|
|
* *
|
2015-04-22 09:15:48 +00:00
|
|
|
* IfcGeom::Iterator::initialize() *
|
2014-12-19 12:14:36 +00:00
|
|
|
* finds the most suitable representation contexts. Returns true iff *
|
|
|
|
|
* at least a single representation will process successfully *
|
|
|
|
|
* *
|
|
|
|
|
* IfcGeom::Iterator::get() *
|
|
|
|
|
* returns a pointer to the current IfcGeom::Element *
|
|
|
|
|
* *
|
|
|
|
|
* IfcGeom::Iterator::next() *
|
|
|
|
|
* returns true iff a following entity is available for a successive call to *
|
|
|
|
|
* IfcGeom::Iterator::get() *
|
|
|
|
|
* *
|
|
|
|
|
* IfcGeom::Iterator::progress() *
|
|
|
|
|
* returns an int in [0..100] that indicates the overall progress *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef IFCGEOMITERATOR_H
|
|
|
|
|
#define IFCGEOMITERATOR_H
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <set>
|
|
|
|
|
#include <vector>
|
2014-12-19 12:36:06 +00:00
|
|
|
#include <limits>
|
2014-12-19 12:14:36 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
2015-09-13 15:00:21 +02:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
|
2014-12-19 12:14:36 +00:00
|
|
|
#include <gp_Mat.hxx>
|
|
|
|
|
#include <gp_Mat2d.hxx>
|
|
|
|
|
#include <gp_GTrsf.hxx>
|
|
|
|
|
#include <gp_GTrsf2d.hxx>
|
|
|
|
|
#include <gp_Trsf.hxx>
|
|
|
|
|
#include <gp_Trsf2d.hxx>
|
|
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
#include "../ifcparse/IfcFile.h"
|
2014-12-19 12:14:36 +00:00
|
|
|
|
|
|
|
|
#include "../ifcgeom/IfcGeom.h"
|
|
|
|
|
#include "../ifcgeom/IfcGeomElement.h"
|
|
|
|
|
#include "../ifcgeom/IfcGeomMaterial.h"
|
|
|
|
|
#include "../ifcgeom/IfcGeomIteratorSettings.h"
|
|
|
|
|
#include "../ifcgeom/IfcRepresentationShapeItem.h"
|
|
|
|
|
|
|
|
|
|
namespace IfcGeom {
|
|
|
|
|
|
|
|
|
|
template <typename P>
|
|
|
|
|
class Iterator {
|
|
|
|
|
private:
|
|
|
|
|
Kernel kernel;
|
|
|
|
|
IteratorSettings settings;
|
|
|
|
|
|
|
|
|
|
IfcParse::IfcFile* ifc_file;
|
|
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
// A container and iterator for IfcRepresentations
|
2014-12-19 12:14:36 +00:00
|
|
|
IfcSchema::IfcRepresentation::list::ptr representations;
|
2015-01-05 14:11:42 +00:00
|
|
|
IfcSchema::IfcRepresentation::list::it representation_iterator;
|
2014-12-19 12:14:36 +00:00
|
|
|
|
|
|
|
|
// The object is fetched beforehand to be sure that get() returns a valid element
|
|
|
|
|
TriangulationElement<P>* current_triangulation;
|
2015-01-05 14:11:42 +00:00
|
|
|
BRepElement<P>* current_shape_model;
|
2014-12-19 12:14:36 +00:00
|
|
|
SerializedElement<P>* current_serialization;
|
|
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
// A container and iterator for IfcBuildingElements for the current IfcRepresentation referenced by *representation_iterator
|
2015-02-05 11:55:25 +00:00
|
|
|
IfcSchema::IfcProduct::list::ptr ifcproducts;
|
2014-12-19 12:14:36 +00:00
|
|
|
IfcSchema::IfcProduct::list::it ifcproduct_iterator;
|
|
|
|
|
|
|
|
|
|
int done;
|
|
|
|
|
int total;
|
|
|
|
|
|
|
|
|
|
std::string unit_name;
|
|
|
|
|
// double?
|
|
|
|
|
P unit_magnitude;
|
|
|
|
|
|
|
|
|
|
void initUnits() {
|
2015-02-17 20:07:09 +00:00
|
|
|
IfcSchema::IfcProject::list::ptr projects = ifc_file->entitiesByType<IfcSchema::IfcProject>();
|
2015-01-10 22:13:52 +00:00
|
|
|
if (projects->size() == 1) {
|
2015-01-05 14:11:42 +00:00
|
|
|
IfcSchema::IfcProject* project = *projects->begin();
|
|
|
|
|
std::pair<std::string, double> length_unit = kernel.initializeUnits(project->UnitsInContext());
|
|
|
|
|
unit_name = length_unit.first;
|
|
|
|
|
unit_magnitude = static_cast<P>(length_unit.second);
|
2014-12-19 12:14:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-05 11:55:25 +00:00
|
|
|
std::set<IfcSchema::Type::Enum> entities_to_include_or_exclude;
|
|
|
|
|
bool include_entities_in_processing;
|
|
|
|
|
|
|
|
|
|
void populate_set(const std::set<std::string>& include_or_ignore) {
|
|
|
|
|
entities_to_include_or_exclude.clear();
|
|
|
|
|
for (std::set<std::string>::const_iterator it = include_or_ignore.begin(); it != include_or_ignore.end(); ++it) {
|
2015-09-13 15:00:21 +02:00
|
|
|
const std::string uppercase_type = boost::to_upper_copy(*it);
|
2015-02-05 11:55:25 +00:00
|
|
|
IfcSchema::Type::Enum ty;
|
|
|
|
|
try {
|
|
|
|
|
ty = IfcSchema::Type::FromString(uppercase_type);
|
|
|
|
|
} catch (const IfcParse::IfcException&) {
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << "'" << *it << "' does not name a valid IFC entity";
|
|
|
|
|
throw IfcParse::IfcException(ss.str());
|
|
|
|
|
}
|
|
|
|
|
entities_to_include_or_exclude.insert(ty);
|
|
|
|
|
// TODO: Add child classes so that containment in set can be in O(log n)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-19 12:14:36 +00:00
|
|
|
public:
|
2015-04-22 09:15:48 +00:00
|
|
|
bool initialize() {
|
2014-12-19 12:14:36 +00:00
|
|
|
try {
|
|
|
|
|
initUnits();
|
|
|
|
|
} catch (...) {}
|
|
|
|
|
|
|
|
|
|
std::set<std::string> context_types;
|
2015-04-22 09:15:48 +00:00
|
|
|
if (!settings.exclude_solids_and_surfaces()) {
|
|
|
|
|
// Really this should only be 'Model', as per
|
|
|
|
|
// the standard 'Design' is deprecated. So,
|
|
|
|
|
// just for backwards compatibility:
|
|
|
|
|
context_types.insert("model");
|
|
|
|
|
context_types.insert("design");
|
|
|
|
|
// DDS likes to output 'model view'
|
|
|
|
|
context_types.insert("model view");
|
|
|
|
|
}
|
|
|
|
|
if (settings.include_curves()) {
|
|
|
|
|
context_types.insert("plan");
|
|
|
|
|
}
|
2014-12-19 12:14:36 +00:00
|
|
|
|
|
|
|
|
double lowest_precision_encountered = std::numeric_limits<double>::infinity();
|
|
|
|
|
bool any_precision_encountered = false;
|
|
|
|
|
|
|
|
|
|
representations = IfcSchema::IfcRepresentation::list::ptr(new IfcSchema::IfcRepresentation::list);
|
|
|
|
|
|
|
|
|
|
IfcSchema::IfcGeometricRepresentationContext::list::it it;
|
|
|
|
|
IfcSchema::IfcGeometricRepresentationSubContext::list::it jt;
|
|
|
|
|
IfcSchema::IfcGeometricRepresentationContext::list::ptr contexts =
|
2015-02-17 20:07:09 +00:00
|
|
|
ifc_file->entitiesByType<IfcSchema::IfcGeometricRepresentationContext>();
|
2014-12-19 12:14:36 +00:00
|
|
|
|
|
|
|
|
IfcSchema::IfcGeometricRepresentationContext::list::ptr filtered_contexts (new IfcSchema::IfcGeometricRepresentationContext::list);
|
|
|
|
|
|
|
|
|
|
for (it = contexts->begin(); it != contexts->end(); ++it) {
|
|
|
|
|
IfcSchema::IfcGeometricRepresentationContext* context = *it;
|
|
|
|
|
if (context->is(IfcSchema::Type::IfcGeometricRepresentationSubContext)) {
|
|
|
|
|
// Continue, as the list of subcontexts will be considered
|
|
|
|
|
// by the parent's context inverse attributes.
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-11-30 23:41:27 +01:00
|
|
|
try {
|
|
|
|
|
if (context->hasContextType()) {
|
|
|
|
|
std::string context_type = context->ContextType();
|
|
|
|
|
boost::to_lower(context_type);
|
|
|
|
|
if (context_types.find(context_type) != context_types.end()) {
|
|
|
|
|
filtered_contexts->push(context);
|
|
|
|
|
}
|
2015-01-22 10:38:35 +00:00
|
|
|
}
|
2015-11-30 23:41:27 +01:00
|
|
|
} catch (const IfcParse::IfcException&) {}
|
2014-12-19 12:14:36 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-22 13:13:16 +00:00
|
|
|
// In case no contexts are identified based on their ContextType, all contexts are
|
|
|
|
|
// considered. Note that sub contexts are excluded as they are considered later on.
|
2015-01-10 22:13:52 +00:00
|
|
|
if (filtered_contexts->size() == 0) {
|
2015-05-22 13:13:16 +00:00
|
|
|
for (it = contexts->begin(); it != contexts->end(); ++it) {
|
|
|
|
|
IfcSchema::IfcGeometricRepresentationContext* context = *it;
|
|
|
|
|
if (!context->is(IfcSchema::Type::IfcGeometricRepresentationSubContext)) {
|
|
|
|
|
filtered_contexts->push(context);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-19 12:14:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (it = filtered_contexts->begin(); it != filtered_contexts->end(); ++it) {
|
|
|
|
|
IfcSchema::IfcGeometricRepresentationContext* context = *it;
|
|
|
|
|
|
|
|
|
|
representations->push(context->RepresentationsInContext());
|
2015-11-30 23:41:27 +01:00
|
|
|
try {
|
|
|
|
|
if (context->hasPrecision() && context->Precision() < lowest_precision_encountered) {
|
|
|
|
|
lowest_precision_encountered = context->Precision();
|
|
|
|
|
any_precision_encountered = true;
|
|
|
|
|
}
|
|
|
|
|
} catch (const IfcParse::IfcException&) {}
|
2014-12-19 12:14:36 +00:00
|
|
|
IfcSchema::IfcGeometricRepresentationSubContext::list::ptr sub_contexts = context->HasSubContexts();
|
|
|
|
|
for (jt = sub_contexts->begin(); jt != sub_contexts->end(); ++jt) {
|
|
|
|
|
representations->push((*jt)->RepresentationsInContext());
|
|
|
|
|
}
|
|
|
|
|
// There is no need for full recursion as the following is governed by the schema:
|
|
|
|
|
// WR31: The parent context shall not be another geometric representation sub context.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (any_precision_encountered) {
|
2015-01-06 14:09:28 +00:00
|
|
|
// Some arbitrary factor that has proven to work better for the models in the set of test files.
|
|
|
|
|
lowest_precision_encountered *= 10.;
|
|
|
|
|
|
|
|
|
|
lowest_precision_encountered *= unit_magnitude;
|
|
|
|
|
if (lowest_precision_encountered < 1.e-7) {
|
|
|
|
|
Logger::Message(Logger::LOG_WARNING, "Precision lower than 0.0000001 meter not enforced");
|
|
|
|
|
kernel.setValue(IfcGeom::Kernel::GV_PRECISION, 1.e-7);
|
|
|
|
|
} else {
|
|
|
|
|
kernel.setValue(IfcGeom::Kernel::GV_PRECISION, lowest_precision_encountered);
|
|
|
|
|
}
|
2014-12-19 12:14:36 +00:00
|
|
|
} else {
|
|
|
|
|
kernel.setValue(IfcGeom::Kernel::GV_PRECISION, 1.e-5);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-10 22:13:52 +00:00
|
|
|
if (representations->size() == 0) return false;
|
2014-12-19 12:14:36 +00:00
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
representation_iterator = representations->begin();
|
2015-02-05 11:55:25 +00:00
|
|
|
ifcproducts.reset();
|
2014-12-19 12:14:36 +00:00
|
|
|
|
|
|
|
|
if (!create()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
done = 0;
|
2015-01-10 22:13:52 +00:00
|
|
|
total = representations->size();
|
2014-12-19 12:14:36 +00:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int progress() {
|
|
|
|
|
return 100 * done / total;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::string& getUnitName() {
|
|
|
|
|
return unit_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const P getUnitMagnitude() {
|
|
|
|
|
return unit_magnitude;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::string getLog() {
|
|
|
|
|
return Logger::GetLog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IfcParse::IfcFile* getFile() {
|
|
|
|
|
return ifc_file;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-05 11:55:25 +00:00
|
|
|
void includeEntities(const std::set<std::string>& entities) {
|
|
|
|
|
populate_set(entities);
|
|
|
|
|
include_entities_in_processing = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void excludeEntities(const std::set<std::string>& entities) {
|
|
|
|
|
populate_set(entities);
|
|
|
|
|
include_entities_in_processing = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-19 12:14:36 +00:00
|
|
|
private:
|
2015-01-05 14:11:42 +00:00
|
|
|
// Move to the next IfcRepresentation
|
2014-12-19 12:14:36 +00:00
|
|
|
void _nextShape() {
|
2015-02-05 11:55:25 +00:00
|
|
|
ifcproducts.reset();
|
2015-01-05 14:11:42 +00:00
|
|
|
++ representation_iterator;
|
2014-12-19 12:14:36 +00:00
|
|
|
++ done;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
BRepElement<P>* create_shape_model_for_next_entity() {
|
2015-11-21 23:05:28 +02:00
|
|
|
for (;;) {
|
2015-01-05 14:11:42 +00:00
|
|
|
IfcSchema::IfcRepresentation* representation;
|
2014-12-19 12:14:36 +00:00
|
|
|
|
|
|
|
|
// Have we reached the end of our list of representations?
|
2015-01-05 14:11:42 +00:00
|
|
|
if ( representation_iterator == representations->end() ) {
|
2014-12-19 12:14:36 +00:00
|
|
|
representations.reset();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2015-01-05 14:11:42 +00:00
|
|
|
representation = *representation_iterator;
|
2014-12-19 12:14:36 +00:00
|
|
|
|
|
|
|
|
// Has the list of IfcProducts for this representation been initialized?
|
2015-02-05 11:55:25 +00:00
|
|
|
if (!ifcproducts) {
|
2014-12-19 12:14:36 +00:00
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
IfcSchema::IfcProductRepresentation::list::ptr prodreps = representation->OfProductRepresentation();
|
2015-02-05 11:55:25 +00:00
|
|
|
ifcproducts = IfcSchema::IfcProduct::list::ptr(new IfcSchema::IfcProduct::list);
|
|
|
|
|
IfcSchema::IfcProduct::list::ptr unfiltered_products(new IfcSchema::IfcProduct::list);
|
|
|
|
|
|
2014-12-19 12:14:36 +00:00
|
|
|
for ( IfcSchema::IfcProductRepresentation::list::it it = prodreps->begin(); it != prodreps->end(); ++it ) {
|
|
|
|
|
if ( (*it)->is(IfcSchema::Type::IfcProductDefinitionShape) ) {
|
|
|
|
|
IfcSchema::IfcProductDefinitionShape* pds = (IfcSchema::IfcProductDefinitionShape*)*it;
|
2015-02-05 11:55:25 +00:00
|
|
|
unfiltered_products->push(pds->ShapeOfProduct());
|
2014-12-19 12:14:36 +00:00
|
|
|
} else {
|
|
|
|
|
// http://buildingsmart-tech.org/ifc/IFC2x3/TC1/html/ifcrepresentationresource/lexical/ifcproductrepresentation.htm
|
|
|
|
|
// IFC2x Edition 3 NOTE Users should not instantiate the entity IfcProductRepresentation from IFC2x Edition 3 onwards.
|
|
|
|
|
// It will be changed into an ABSTRACT supertype in future releases of IFC.
|
|
|
|
|
|
|
|
|
|
// IfcProductRepresentation also lacks the INVERSE relation to IfcProduct
|
|
|
|
|
// Let's find the IfcProducts that reference the IfcProductRepresentation anyway
|
2015-02-05 11:55:25 +00:00
|
|
|
unfiltered_products->push((*it)->entity->getInverse(IfcSchema::Type::IfcProduct, -1)->as<IfcSchema::IfcProduct>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filter the products based on the set of entities being included or excluded for
|
|
|
|
|
// processing. The set is iterated over te able to filter on subtypes.
|
2015-11-21 23:05:28 +02:00
|
|
|
for ( IfcSchema::IfcProduct::list::it jt = unfiltered_products->begin(); jt != unfiltered_products->end(); ++jt ) {
|
2015-02-05 11:55:25 +00:00
|
|
|
bool found = false;
|
2015-11-21 23:05:28 +02:00
|
|
|
for (std::set<IfcSchema::Type::Enum>::const_iterator kt = entities_to_include_or_exclude.begin(); kt != entities_to_include_or_exclude.end(); ++kt) {
|
|
|
|
|
if ((*jt)->is(*kt)) {
|
2015-02-05 11:55:25 +00:00
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (found == include_entities_in_processing) {
|
2015-11-21 23:05:28 +02:00
|
|
|
ifcproducts->push(*jt);
|
2014-12-19 12:14:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
2015-02-05 11:55:25 +00:00
|
|
|
|
2014-12-19 12:14:36 +00:00
|
|
|
}
|
|
|
|
|
// Does this representation have any IfcProducts?
|
2015-02-05 11:55:25 +00:00
|
|
|
if (!ifcproducts->size()) {
|
2014-12-19 12:14:36 +00:00
|
|
|
_nextShape();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-02-05 11:55:25 +00:00
|
|
|
ifcproduct_iterator = ifcproducts->begin();
|
2014-12-19 12:14:36 +00:00
|
|
|
}
|
|
|
|
|
// Have we reached the end of our list of IfcProducts?
|
2015-02-05 11:55:25 +00:00
|
|
|
if ( ifcproduct_iterator == ifcproducts->end() ) {
|
2014-12-19 12:14:36 +00:00
|
|
|
_nextShape();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
IfcSchema::IfcProduct* product = *ifcproduct_iterator;
|
2014-12-19 12:14:36 +00:00
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
BRepElement<P>* element = kernel.create_brep_for_representation_and_product<P>(settings, representation, product);
|
2014-12-19 12:14:36 +00:00
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
if ( !element ) {
|
|
|
|
|
_nextShape();
|
|
|
|
|
continue;
|
2014-12-19 12:14:36 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
return element;
|
2014-12-19 12:14:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
bool next() {
|
|
|
|
|
// Free all possible representations of the current geometrical entity
|
|
|
|
|
delete current_triangulation;
|
|
|
|
|
current_triangulation = 0;
|
2015-01-05 14:11:42 +00:00
|
|
|
delete current_serialization;
|
|
|
|
|
current_serialization = 0;
|
|
|
|
|
delete current_shape_model;
|
|
|
|
|
current_shape_model = 0;
|
2014-12-19 12:14:36 +00:00
|
|
|
|
|
|
|
|
// Increment the iterator over the list of products using the current
|
|
|
|
|
// shape representation
|
2015-02-05 11:55:25 +00:00
|
|
|
if (ifcproducts) {
|
2014-12-19 12:14:36 +00:00
|
|
|
++ifcproduct_iterator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return create();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Element<P>* get() {
|
|
|
|
|
// TODO: Test settings and throw
|
|
|
|
|
if (current_triangulation) return current_triangulation;
|
|
|
|
|
else if (current_serialization) return current_serialization;
|
|
|
|
|
else if (current_shape_model) return current_shape_model;
|
|
|
|
|
else return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Element<P>* getObject(int id) {
|
|
|
|
|
|
|
|
|
|
gp_Trsf trsf;
|
|
|
|
|
int parent_id = -1;
|
|
|
|
|
std::string instance_type, product_name, product_guid;
|
|
|
|
|
|
|
|
|
|
try {
|
2015-02-17 20:07:09 +00:00
|
|
|
const IfcUtil::IfcBaseClass* ifc_entity = ifc_file->entityById(id);
|
2014-12-19 12:14:36 +00:00
|
|
|
instance_type = IfcSchema::Type::ToString(ifc_entity->type());
|
|
|
|
|
if ( ifc_entity->is(IfcSchema::Type::IfcProduct) ) {
|
|
|
|
|
IfcSchema::IfcProduct* ifc_product = (IfcSchema::IfcProduct*)ifc_entity;
|
|
|
|
|
|
|
|
|
|
product_guid = ifc_product->GlobalId();
|
|
|
|
|
product_name = ifc_product->hasName() ? ifc_product->Name() : "";
|
|
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
parent_id = -1;
|
2014-12-19 12:14:36 +00:00
|
|
|
try {
|
2015-01-05 14:11:42 +00:00
|
|
|
IfcSchema::IfcObjectDefinition* parent_object = kernel.get_decomposing_entity(ifc_product);
|
|
|
|
|
if (parent_object) {
|
|
|
|
|
parent_id = parent_object->entity->id();
|
|
|
|
|
}
|
2014-12-19 12:14:36 +00:00
|
|
|
} catch (...) {}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
kernel.convert(ifc_product->ObjectPlacement(), trsf);
|
|
|
|
|
} catch (...) {}
|
|
|
|
|
}
|
|
|
|
|
} catch(...) {}
|
|
|
|
|
|
|
|
|
|
ElementSettings element_settings(settings, unit_magnitude, instance_type);
|
2015-04-22 09:15:48 +00:00
|
|
|
Element<P>* ifc_object = new Element<P>(element_settings, id, parent_id, product_name, instance_type, product_guid, "", trsf);
|
2014-12-19 12:14:36 +00:00
|
|
|
|
|
|
|
|
return ifc_object;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool create() {
|
|
|
|
|
try {
|
|
|
|
|
current_shape_model = create_shape_model_for_next_entity();
|
|
|
|
|
} catch (...) {}
|
|
|
|
|
if (!current_shape_model) return false;
|
|
|
|
|
if (settings.use_brep_data()) {
|
|
|
|
|
try {
|
|
|
|
|
current_serialization = new SerializedElement<P>(*current_shape_model);
|
|
|
|
|
} catch (...) {}
|
|
|
|
|
return !!current_serialization;
|
|
|
|
|
} else if (!settings.disable_triangulation()) {
|
|
|
|
|
try {
|
|
|
|
|
current_triangulation = new TriangulationElement<P>(*current_shape_model);
|
|
|
|
|
} catch (...) {}
|
|
|
|
|
return !!current_triangulation;
|
|
|
|
|
} else {
|
2015-02-03 09:40:17 +00:00
|
|
|
return true;
|
2014-12-19 12:14:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private:
|
2015-04-22 09:15:48 +00:00
|
|
|
void _initialize() {
|
2014-12-19 12:14:36 +00:00
|
|
|
current_triangulation = 0;
|
|
|
|
|
current_shape_model = 0;
|
|
|
|
|
current_serialization = 0;
|
2015-02-19 20:17:53 +00:00
|
|
|
|
|
|
|
|
// Upon initialisation, the (empty) set of entity names,
|
|
|
|
|
// should be excluded, or no products would be processed.
|
|
|
|
|
include_entities_in_processing = false;
|
2014-12-19 12:14:36 +00:00
|
|
|
|
|
|
|
|
unit_name = "METER";
|
|
|
|
|
unit_magnitude = 1.f;
|
|
|
|
|
|
|
|
|
|
kernel.setValue(IfcGeom::Kernel::GV_MAX_FACES_TO_SEW, settings.sew_shells() ? 1000 : -1);
|
2015-04-22 09:15:48 +00:00
|
|
|
kernel.setValue(IfcGeom::Kernel::GV_DIMENSIONALITY, (settings.include_curves() ? (settings.exclude_solids_and_surfaces() ? -1. : 0.) : +1.));
|
2014-12-19 12:14:36 +00:00
|
|
|
}
|
2015-06-20 14:23:59 +00:00
|
|
|
|
|
|
|
|
bool owns_ifc_file;
|
2014-12-19 12:14:36 +00:00
|
|
|
public:
|
|
|
|
|
Iterator(const IteratorSettings& settings, IfcParse::IfcFile* file)
|
|
|
|
|
: settings(settings)
|
|
|
|
|
, ifc_file(file)
|
2015-06-20 14:23:59 +00:00
|
|
|
, owns_ifc_file(false)
|
2014-12-19 12:14:36 +00:00
|
|
|
{
|
2015-04-22 09:15:48 +00:00
|
|
|
_initialize();
|
2014-12-19 12:14:36 +00:00
|
|
|
}
|
|
|
|
|
Iterator(const IteratorSettings& settings, const std::string& filename)
|
|
|
|
|
: settings(settings)
|
|
|
|
|
, ifc_file(new IfcParse::IfcFile)
|
2015-06-20 14:23:59 +00:00
|
|
|
, owns_ifc_file(true)
|
2014-12-19 12:14:36 +00:00
|
|
|
{
|
|
|
|
|
ifc_file->Init(filename);
|
2015-04-22 09:15:48 +00:00
|
|
|
_initialize();
|
2014-12-19 12:14:36 +00:00
|
|
|
}
|
|
|
|
|
Iterator(const IteratorSettings& settings, void* data, int length)
|
|
|
|
|
: settings(settings)
|
|
|
|
|
, ifc_file(new IfcParse::IfcFile)
|
2015-06-20 14:23:59 +00:00
|
|
|
, owns_ifc_file(true)
|
2014-12-19 12:14:36 +00:00
|
|
|
{
|
|
|
|
|
ifc_file->Init(data, length);
|
2015-04-22 09:15:48 +00:00
|
|
|
_initialize();
|
2014-12-19 12:14:36 +00:00
|
|
|
}
|
|
|
|
|
Iterator(const IteratorSettings& settings, std::istream& filestream, int length)
|
|
|
|
|
: settings(settings)
|
|
|
|
|
, ifc_file(new IfcParse::IfcFile)
|
2015-06-20 14:23:59 +00:00
|
|
|
, owns_ifc_file(true)
|
2014-12-19 12:14:36 +00:00
|
|
|
{
|
|
|
|
|
ifc_file->Init(filestream, length);
|
2015-04-22 09:15:48 +00:00
|
|
|
_initialize();
|
2014-12-19 12:14:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~Iterator() {
|
2015-06-20 14:23:59 +00:00
|
|
|
if (owns_ifc_file) {
|
|
|
|
|
delete ifc_file;
|
|
|
|
|
}
|
2014-12-19 12:14:36 +00:00
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
delete current_triangulation;
|
|
|
|
|
current_triangulation = 0;
|
|
|
|
|
delete current_serialization;
|
|
|
|
|
current_serialization = 0;
|
|
|
|
|
delete current_shape_model;
|
|
|
|
|
current_shape_model = 0;
|
2014-12-19 12:14:36 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|