mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 06:58:56 +00:00
setOnlyValid() option that skips and logs invalid topology #4130
This commit is contained in:
@@ -41,6 +41,8 @@
|
|||||||
#include <ShapeFix_Shape.hxx>
|
#include <ShapeFix_Shape.hxx>
|
||||||
#include <BRepCheck_Analyzer.hxx>
|
#include <BRepCheck_Analyzer.hxx>
|
||||||
#include <BRepClass3d_SolidClassifier.hxx>
|
#include <BRepClass3d_SolidClassifier.hxx>
|
||||||
|
#include <BRepCheck.hxx>
|
||||||
|
#include <BRepTools.hxx>
|
||||||
|
|
||||||
#include <BRepAlgoAPI_Fuse.hxx>
|
#include <BRepAlgoAPI_Fuse.hxx>
|
||||||
|
|
||||||
@@ -822,3 +824,43 @@ bool IfcGeom::util::flatten_shape_list(const IfcGeom::ConversionResults& shapes,
|
|||||||
const bool success = !result.IsNull();
|
const bool success = !result.IsNull();
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IfcGeom::util::validate_shape(const TopoDS_Shape& s) {
|
||||||
|
BRepCheck_Analyzer ana(s);
|
||||||
|
if (ana.IsValid()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::stringstream str;
|
||||||
|
bool any_emitted = false;
|
||||||
|
|
||||||
|
std::function<void(const TopoDS_Shape&)> dump;
|
||||||
|
dump = [&ana, &str, &dump, &any_emitted](const TopoDS_Shape& s) {
|
||||||
|
if (!ana.Result(s).IsNull()) {
|
||||||
|
BRepCheck_ListIteratorOfListOfStatus itl;
|
||||||
|
itl.Initialize(ana.Result(s)->Status());
|
||||||
|
for (; itl.More(); itl.Next()) {
|
||||||
|
if (itl.Value() != BRepCheck_NoError) {
|
||||||
|
if (any_emitted) {
|
||||||
|
str << ", ";
|
||||||
|
}
|
||||||
|
BRepCheck::Print(itl.Value(), str);
|
||||||
|
str.seekp(str.tellp() - (std::streamoff)1);
|
||||||
|
str << " on ";
|
||||||
|
TopAbs::Print(s.ShapeType(), str);
|
||||||
|
BRepTools::Dump(s, str);
|
||||||
|
any_emitted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (TopoDS_Iterator it(s); it.More(); it.Next()) {
|
||||||
|
dump(it.Value());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
dump(s);
|
||||||
|
|
||||||
|
Logger::Warning(str.str());
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ namespace IfcGeom {
|
|||||||
TopoDS_Shape apply_transformation(const TopoDS_Shape&, const gp_GTrsf&);
|
TopoDS_Shape apply_transformation(const TopoDS_Shape&, const gp_GTrsf&);
|
||||||
|
|
||||||
bool flatten_shape_list(const IfcGeom::ConversionResults& shapes, TopoDS_Shape& result, bool fuse, double tol);
|
bool flatten_shape_list(const IfcGeom::ConversionResults& shapes, TopoDS_Shape& result, bool fuse, double tol);
|
||||||
|
bool validate_shape(const TopoDS_Shape&);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -742,6 +742,10 @@ void SvgSerializer::write(const IfcGeom::BRepElement* brep_obj) {
|
|||||||
compound_local = comp2;
|
compound_local = comp2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (only_valid_ && !IfcGeom::util::validate_shape(compound_local)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
geometry_data data{ compound_local, dash_arrays, trsf, brep_obj->product(), storey, elev, brep_obj->name(), nameElement(storey, brep_obj) };
|
geometry_data data{ compound_local, dash_arrays, trsf, brep_obj->product(), storey, elev, brep_obj->name(), nameElement(storey, brep_obj) };
|
||||||
|
|
||||||
if (auto_section_ || auto_elevation_ || section_ref_ || elevation_ref_ || elevation_ref_guid_ || deferred_section_data_) {
|
if (auto_section_ || auto_elevation_ || section_ref_ || elevation_ref_ || elevation_ref_guid_ || deferred_section_data_) {
|
||||||
|
|||||||
@@ -556,6 +556,7 @@ protected:
|
|||||||
bool unify_inputs_;
|
bool unify_inputs_;
|
||||||
bool mirror_y_;
|
bool mirror_y_;
|
||||||
bool mirror_x_;
|
bool mirror_x_;
|
||||||
|
bool only_valid_;
|
||||||
|
|
||||||
int profile_threshold_;
|
int profile_threshold_;
|
||||||
|
|
||||||
@@ -723,6 +724,14 @@ public:
|
|||||||
return unify_inputs_;
|
return unify_inputs_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setOnlyValid(bool b) {
|
||||||
|
only_valid_ = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getOnlyValid(bool b) const {
|
||||||
|
return only_valid_;
|
||||||
|
}
|
||||||
|
|
||||||
void setScale(double s) { scale_ = s; }
|
void setScale(double s) { scale_ = s; }
|
||||||
void setDrawingCenter(double x, double y) {
|
void setDrawingCenter(double x, double y) {
|
||||||
center_x_ = x; center_y_ = y;
|
center_x_ = x; center_y_ = y;
|
||||||
|
|||||||
Reference in New Issue
Block a user