mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 14:02:27 +00:00
Move macro logic into template function; mark failures as intended #4915
This commit is contained in:
@@ -101,7 +101,7 @@ bool OpenCascadeKernel::convert(const taxonomy::solid::ptr solid, TopoDS_Shape&
|
|||||||
return !result.IsNull();
|
return !result.IsNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenCascadeKernel::convert_impl(const taxonomy::solid::ptr solid , IfcGeom::ConversionResults& results) {
|
bool OpenCascadeKernel::convert_impl(const taxonomy::solid::ptr solid, IfcGeom::ConversionResults& results) {
|
||||||
TopoDS_Shape shape;
|
TopoDS_Shape shape;
|
||||||
if (!convert(solid, shape)) {
|
if (!convert(solid, shape)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcMappedItem* inst) {
|
|||||||
// @todo allow for multiple levels of matrix?
|
// @todo allow for multiple levels of matrix?
|
||||||
auto shapes = taxonomy::dcast<taxonomy::collection>(map(rmap->MappedRepresentation()));
|
auto shapes = taxonomy::dcast<taxonomy::collection>(map(rmap->MappedRepresentation()));
|
||||||
if (shapes == nullptr) {
|
if (shapes == nullptr) {
|
||||||
|
if (failed_on_purpose_.find(rmap->MappedRepresentation()) != failed_on_purpose_.end()) {
|
||||||
|
// propagate
|
||||||
|
failed_on_purpose_.insert(inst);
|
||||||
|
}
|
||||||
return shapes;
|
return shapes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,16 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcRepresentation* inst) {
|
|||||||
|
|
||||||
auto items = map_to_collection(this, inst->Items());
|
auto items = map_to_collection(this, inst->Items());
|
||||||
if (!items) {
|
if (!items) {
|
||||||
|
auto its = inst->Items();
|
||||||
|
bool empty_on_purpose = true;
|
||||||
|
for (auto& itm : *its) {
|
||||||
|
if (failed_on_purpose_.find(itm) == failed_on_purpose_.end()) {
|
||||||
|
empty_on_purpose = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty_on_purpose) {
|
||||||
|
failed_on_purpose_.insert(inst);
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,37 +63,9 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcRepresentation* inst) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (filtered->children.empty()) {
|
if (filtered->children.empty()) {
|
||||||
|
failed_on_purpose_.insert(inst);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return filtered;
|
return filtered;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
taxonomy::ptr mapping::map_impl(const IfcSchema::IfcRepresentation* l, ConversionResults& shapes) {
|
|
||||||
IfcSchema::IfcRepresentationItem::list::ptr items = inst->Items();
|
|
||||||
bool part_succes = false;
|
|
||||||
if ( items->size() ) {
|
|
||||||
for ( IfcSchema::IfcRepresentationItem::list::it it = items->begin(); it != items->end(); ++ it ) {
|
|
||||||
IfcSchema::IfcRepresentationptr representation_item = *it;
|
|
||||||
if ( shape_type(representation_item) == ST_SHAPELIST ) {
|
|
||||||
part_succes |= convert_shapes(*it, shapes);
|
|
||||||
} else {
|
|
||||||
TopoDS_Shape s;
|
|
||||||
if (convert_shape(representation_item, s)) {
|
|
||||||
if (s.ShapeType() == TopAbs_COMPOUND && TopoDS_Iterator(s).More() && TopoDS_Iterator(s).Value().ShapeType() == TopAbs_SOLID) {
|
|
||||||
TopoDS_Iterator topo_it(s);
|
|
||||||
for (; topo_it.More(); topo_it.Next()) {
|
|
||||||
shapes.push_back(ConversionResult(representation_item->data().id(), topo_it.Value(), get_style(representation_item)));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
shapes.push_back(ConversionResult(representation_item->data().id(), s, get_style(representation_item)));
|
|
||||||
}
|
|
||||||
part_succes |= true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return part_succes;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
@@ -3,33 +3,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define BIND(T) \
|
#define BIND(T) \
|
||||||
if (!item && inst->as<IfcSchema::T>()) { \
|
process_mapping<IfcSchema::T>(matched, item, inst);
|
||||||
matched = true; \
|
|
||||||
try { \
|
|
||||||
item = map_impl(inst->as<IfcSchema::T>()); \
|
|
||||||
if (item != nullptr) { \
|
|
||||||
if (item->instance == nullptr) { \
|
|
||||||
item->instance = inst; \
|
|
||||||
} \
|
|
||||||
try { \
|
|
||||||
if (inst->as<IfcSchema::IfcRepresentationItem>() && !inst->as<IfcSchema::IfcStyledItem>() && \
|
|
||||||
/* @todo */ \
|
|
||||||
(item->kind() == taxonomy::SOLID || item->kind() == taxonomy::SHELL || item->kind() == taxonomy::COLLECTION || item->kind() == taxonomy::EXTRUSION) \
|
|
||||||
) { \
|
|
||||||
auto style = find_style(inst->as<IfcSchema::IfcRepresentationItem>()); \
|
|
||||||
if (style) { \
|
|
||||||
taxonomy::cast<taxonomy::geom_item>(item)->surface_style = taxonomy::cast<taxonomy::style>(map(style)); \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
} catch (const std::exception& e) { \
|
|
||||||
Logger::Message(Logger::LOG_ERROR, std::string(e.what()) + "\nFailed to convert:", inst); \
|
|
||||||
} \
|
|
||||||
} else {\
|
|
||||||
Logger::Message(Logger::LOG_ERROR,"Failed to convert:", inst);\
|
|
||||||
} \
|
|
||||||
} catch (const std::exception& e) { \
|
|
||||||
Logger::Message(Logger::LOG_ERROR, std::string(e.what()) + "\nFailed to convert:", inst); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "mapping.i"
|
#include "mapping.i"
|
||||||
|
|||||||
@@ -416,24 +416,6 @@ namespace {
|
|||||||
return std::make_pair<IfcSchema::IfcSurfaceStyle*, T*>(nullptr, nullptr);
|
return std::make_pair<IfcSchema::IfcSurfaceStyle*, T*>(nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
const IfcSchema::IfcStyledItem* find_style(const IfcSchema::IfcRepresentationItem* representation_item) {
|
|
||||||
// For certain representation items, most notably boolean operands,
|
|
||||||
// a style definition might reside on one of its operands.
|
|
||||||
representation_item = find_item_carrying_style(representation_item);
|
|
||||||
|
|
||||||
if (representation_item->as<IfcSchema::IfcStyledItem>()) {
|
|
||||||
return representation_item->as<IfcSchema::IfcStyledItem>();
|
|
||||||
}
|
|
||||||
|
|
||||||
IfcSchema::IfcStyledItem::list::ptr styled_items = representation_item->StyledByItem();
|
|
||||||
if (styled_items->size()) {
|
|
||||||
// StyledByItem is a SET [0:1] OF IfcStyledItem, so we return after the first IfcStyledItem:
|
|
||||||
return *styled_items->begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool process_colour(IfcSchema::IfcColourRgb* colour, double* rgb) {
|
bool process_colour(IfcSchema::IfcColourRgb* colour, double* rgb) {
|
||||||
if (colour != 0) {
|
if (colour != 0) {
|
||||||
rgb[0] = colour->Red();
|
rgb[0] = colour->Red();
|
||||||
@@ -464,6 +446,24 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const IfcSchema::IfcStyledItem* mapping::find_style(const IfcSchema::IfcRepresentationItem* representation_item) {
|
||||||
|
// For certain representation items, most notably boolean operands,
|
||||||
|
// a style definition might reside on one of its operands.
|
||||||
|
representation_item = find_item_carrying_style(representation_item);
|
||||||
|
|
||||||
|
if (representation_item->as<IfcSchema::IfcStyledItem>()) {
|
||||||
|
return representation_item->as<IfcSchema::IfcStyledItem>();
|
||||||
|
}
|
||||||
|
|
||||||
|
IfcSchema::IfcStyledItem::list::ptr styled_items = representation_item->StyledByItem();
|
||||||
|
if (styled_items->size()) {
|
||||||
|
// StyledByItem is a SET [0:1] OF IfcStyledItem, so we return after the first IfcStyledItem:
|
||||||
|
return *styled_items->begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
taxonomy::ptr mapping::map_impl(const IfcSchema::IfcMaterial* material) {
|
taxonomy::ptr mapping::map_impl(const IfcSchema::IfcMaterial* material) {
|
||||||
IfcSchema::IfcMaterialDefinitionRepresentation::list::ptr defs = material->HasRepresentation();
|
IfcSchema::IfcMaterialDefinitionRepresentation::list::ptr defs = material->HasRepresentation();
|
||||||
for (IfcSchema::IfcMaterialDefinitionRepresentation::list::it jt = defs->begin(); jt != defs->end(); ++jt) {
|
for (IfcSchema::IfcMaterialDefinitionRepresentation::list::it jt = defs->begin(); jt != defs->end(); ++jt) {
|
||||||
@@ -500,6 +500,9 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcStyledItem* inst) {
|
|||||||
IfcSchema::IfcSurfaceStyleShading* shading = style_pair.second;
|
IfcSchema::IfcSurfaceStyleShading* shading = style_pair.second;
|
||||||
|
|
||||||
if (style == nullptr) {
|
if (style == nullptr) {
|
||||||
|
// @todo we should probably log something that the kind of style,
|
||||||
|
// such as IfcCurveStyle, in this collections are unsupported.
|
||||||
|
failed_on_purpose_.insert(inst);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,46 @@ namespace geometry {
|
|||||||
void initialize_units_();
|
void initialize_units_();
|
||||||
void addRepresentationsFromContextIds(IfcSchema::IfcRepresentation::list::ptr&);
|
void addRepresentationsFromContextIds(IfcSchema::IfcRepresentation::list::ptr&);
|
||||||
void addRepresentationsFromDefaultContexts(IfcSchema::IfcRepresentation::list::ptr&);
|
void addRepresentationsFromDefaultContexts(IfcSchema::IfcRepresentation::list::ptr&);
|
||||||
|
|
||||||
|
// Set of instances to mark failures that are intended, such as representations not
|
||||||
|
// resulting in any items due to dimensionality filters.
|
||||||
|
std::set<const IfcUtil::IfcBaseInterface*> failed_on_purpose_;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void process_mapping(bool& matched, taxonomy::ptr& item, IfcUtil::IfcBaseInterface const * inst) {
|
||||||
|
if (!item && inst->as<T>()) {
|
||||||
|
matched = true;
|
||||||
|
try {
|
||||||
|
item = map_impl(inst->as<T>());
|
||||||
|
if (item != nullptr) {
|
||||||
|
if (item->instance == nullptr) {
|
||||||
|
item->instance = inst;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (inst->as<IfcSchema::IfcRepresentationItem>() && !inst->as<IfcSchema::IfcStyledItem>() &&
|
||||||
|
/* @todo */
|
||||||
|
(item->kind() == taxonomy::SOLID || item->kind() == taxonomy::SHELL || item->kind() == taxonomy::COLLECTION || item->kind() == taxonomy::EXTRUSION)
|
||||||
|
) {
|
||||||
|
auto style = find_style(inst->as<IfcSchema::IfcRepresentationItem>());
|
||||||
|
if (style) {
|
||||||
|
auto mstyle = map(style);
|
||||||
|
if (mstyle) {
|
||||||
|
taxonomy::cast<taxonomy::geom_item>(item)->surface_style = taxonomy::cast<taxonomy::style>(mstyle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
Logger::Message(Logger::LOG_ERROR, std::string(e.what()) + "\nFailed to convert:", inst);
|
||||||
|
}
|
||||||
|
} else if (failed_on_purpose_.find(inst) == failed_on_purpose_.end()) {
|
||||||
|
Logger::Message(Logger::LOG_ERROR, "Failed to convert:", inst);
|
||||||
|
}
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
Logger::Message(Logger::LOG_ERROR, std::string(e.what()) + "\nFailed to convert:", inst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const IfcSchema::IfcStyledItem* find_style(const IfcSchema::IfcRepresentationItem*);
|
||||||
public:
|
public:
|
||||||
POSTFIX_SCHEMA(mapping)(IfcParse::IfcFile* file, Settings& settings) : abstract_mapping(settings), file_(file), placement_rel_to_type_(0), placement_rel_to_instance_(0) {
|
POSTFIX_SCHEMA(mapping)(IfcParse::IfcFile* file, Settings& settings) : abstract_mapping(settings), file_(file), placement_rel_to_type_(0), placement_rel_to_instance_(0) {
|
||||||
initialize_units_();
|
initialize_units_();
|
||||||
|
|||||||
Reference in New Issue
Block a user