2012-07-19 18:26:47 +00:00
|
|
|
/********************************************************************************
|
2011-08-24 12:35:42 +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 "IfcGeom.h"
|
2015-04-22 09:15:48 +00:00
|
|
|
#include "IfcGeomShapeType.h"
|
2011-08-24 12:35:42 +00:00
|
|
|
|
2014-02-17 22:13:55 +00:00
|
|
|
using namespace IfcSchema;
|
2011-08-24 12:35:42 +00:00
|
|
|
using namespace IfcUtil;
|
|
|
|
|
|
2014-12-19 12:14:36 +00:00
|
|
|
bool IfcGeom::Kernel::convert_shapes(const IfcBaseClass* l, IfcRepresentationShapeItems& r) {
|
2015-10-22 12:04:49 +02:00
|
|
|
if (shape_type(l) != ST_SHAPELIST) {
|
|
|
|
|
TopoDS_Shape shp;
|
|
|
|
|
if (convert_shape(l, shp)) {
|
|
|
|
|
r.push_back(IfcGeom::IfcRepresentationShapeItem(shp, get_style(l->as<IfcSchema::IfcRepresentationItem>())));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-23 17:11:06 +00:00
|
|
|
#include "IfcRegisterConvertShapes.h"
|
2012-08-11 13:24:08 +00:00
|
|
|
Logger::Message(Logger::LOG_ERROR,"No operation defined for:",l->entity);
|
2011-10-23 17:11:06 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2014-12-19 12:14:36 +00:00
|
|
|
|
2015-04-22 09:15:48 +00:00
|
|
|
IfcGeom::ShapeType IfcGeom::Kernel::shape_type(const IfcBaseClass* l) {
|
|
|
|
|
#include "IfcRegisterShapeType.h"
|
|
|
|
|
return ST_OTHER;
|
2011-10-23 17:11:06 +00:00
|
|
|
}
|
2014-12-19 12:14:36 +00:00
|
|
|
|
|
|
|
|
bool IfcGeom::Kernel::convert_shape(const IfcBaseClass* l, TopoDS_Shape& r) {
|
2011-08-24 12:35:42 +00:00
|
|
|
const unsigned int id = l->entity->id();
|
2013-11-24 15:44:27 +00:00
|
|
|
bool success = false;
|
|
|
|
|
bool processed = false;
|
2015-04-22 09:15:48 +00:00
|
|
|
bool ignored = false;
|
|
|
|
|
|
2014-12-19 12:14:36 +00:00
|
|
|
std::map<int,TopoDS_Shape>::const_iterator it = cache.Shape.find(id);
|
|
|
|
|
if ( it != cache.Shape.end() ) { r = it->second; return true; }
|
2015-04-22 09:15:48 +00:00
|
|
|
const bool include_curves = getValue(GV_DIMENSIONALITY) != +1;
|
|
|
|
|
const bool include_solids_and_surfaces = getValue(GV_DIMENSIONALITY) != -1;
|
|
|
|
|
|
|
|
|
|
IfcGeom::ShapeType st = shape_type(l);
|
|
|
|
|
ignored = (!include_solids_and_surfaces && (st == ST_SHAPE || st == ST_FACE)) || (!include_curves && (st == ST_WIRE || st == ST_CURVE));
|
|
|
|
|
if (st == ST_SHAPELIST) {
|
|
|
|
|
processed = true;
|
|
|
|
|
IfcRepresentationShapeItems items;
|
|
|
|
|
success = convert_shapes(l, items) && flatten_shape_list(items, r, false);
|
|
|
|
|
} else if (st == ST_SHAPE && include_solids_and_surfaces) {
|
2011-08-24 12:35:42 +00:00
|
|
|
#include "IfcRegisterConvertShape.h"
|
2015-04-22 09:15:48 +00:00
|
|
|
} else if (st == ST_FACE && include_solids_and_surfaces) {
|
|
|
|
|
processed = true;
|
|
|
|
|
success = convert_face(l, r);
|
|
|
|
|
} else if (st == ST_WIRE && include_curves) {
|
|
|
|
|
processed = true;
|
|
|
|
|
TopoDS_Wire w;
|
|
|
|
|
success = convert_wire(l, w);
|
|
|
|
|
if (success) {
|
|
|
|
|
r = w;
|
|
|
|
|
}
|
|
|
|
|
} else if (st == ST_CURVE && include_curves) {
|
|
|
|
|
processed = true;
|
|
|
|
|
Handle(Geom_Curve) crv;
|
|
|
|
|
TopoDS_Wire w;
|
|
|
|
|
success = convert_curve(l, crv) && convert_curve_to_wire(crv, w);
|
|
|
|
|
if (success) {
|
|
|
|
|
r = w;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( processed && success ) {
|
2014-12-19 12:14:36 +00:00
|
|
|
const double precision = getValue(GV_PRECISION);
|
|
|
|
|
apply_tolerance(r, precision);
|
|
|
|
|
cache.Shape[id] = r;
|
2015-04-22 09:15:48 +00:00
|
|
|
} else if (!ignored) {
|
|
|
|
|
const char* const msg = processed
|
|
|
|
|
? "Failed to convert:"
|
|
|
|
|
: "No operation defined for:";
|
|
|
|
|
Logger::Message(Logger::LOG_ERROR, msg, l->entity);
|
2013-11-24 15:44:27 +00:00
|
|
|
}
|
|
|
|
|
return success;
|
2011-08-24 12:35:42 +00:00
|
|
|
}
|
2014-12-19 12:14:36 +00:00
|
|
|
|
|
|
|
|
bool IfcGeom::Kernel::convert_wire(const IfcBaseClass* l, TopoDS_Wire& r) {
|
2011-08-24 12:35:42 +00:00
|
|
|
#include "IfcRegisterConvertWire.h"
|
2014-03-15 11:51:23 +00:00
|
|
|
Handle(Geom_Curve) curve;
|
2014-12-19 12:14:36 +00:00
|
|
|
if (IfcGeom::Kernel::convert_curve(l, curve)) {
|
|
|
|
|
return IfcGeom::Kernel::convert_curve_to_wire(curve, r);
|
2014-03-15 11:51:23 +00:00
|
|
|
}
|
2012-08-11 13:24:08 +00:00
|
|
|
Logger::Message(Logger::LOG_ERROR,"No operation defined for:",l->entity);
|
2011-08-24 12:35:42 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2014-12-19 12:14:36 +00:00
|
|
|
|
|
|
|
|
bool IfcGeom::Kernel::convert_face(const IfcBaseClass* l, TopoDS_Shape& r) {
|
2011-08-24 12:35:42 +00:00
|
|
|
#include "IfcRegisterConvertFace.h"
|
2012-08-11 13:24:08 +00:00
|
|
|
Logger::Message(Logger::LOG_ERROR,"No operation defined for:",l->entity);
|
2011-08-24 12:35:42 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2014-12-19 12:14:36 +00:00
|
|
|
|
|
|
|
|
bool IfcGeom::Kernel::convert_curve(const IfcBaseClass* l, Handle(Geom_Curve)& r) {
|
2011-08-24 12:35:42 +00:00
|
|
|
#include "IfcRegisterConvertCurve.h"
|
2012-08-11 13:24:08 +00:00
|
|
|
Logger::Message(Logger::LOG_ERROR,"No operation defined for:",l->entity);
|
2011-08-24 12:35:42 +00:00
|
|
|
return false;
|
|
|
|
|
}
|