Pass around non-static logger instances and programmatic access to messages in-memory

This commit is contained in:
Thomas Krijnen
2026-06-10 18:30:54 +02:00
parent a751fb956d
commit a7738eeb64
132 changed files with 1029 additions and 884 deletions
+18 -18
View File
@@ -139,13 +139,13 @@ void SvgSerializer::write(path_object& p, const TopoDS_Shape& comp_or_wire, boos
BRep_Tool::CurveOnSurface(edge, curve2d, surf, loc, u1, u2);
if (curve2d.IsNull()) {
Logger::Error("SER", 20, "Failed to obtain 2d and 3d curve from edge");
logger_.Error("SER", 20, "Failed to obtain 2d and 3d curve from edge");
continue;
}
Handle(Standard_Type) sty = surf->DynamicType();
if (sty != STANDARD_TYPE(Geom_Plane)) {
Logger::Error("SER", 21, "Non-planar p-curves are not supported by this serializer");
logger_.Error("SER", 21, "Non-planar p-curves are not supported by this serializer");
continue;
}
@@ -222,7 +222,7 @@ void SvgSerializer::write(path_object& p, const TopoDS_Shape& comp_or_wire, boos
std::stringstream ss;
ss << "Skipping full circle/ellipse inside aggregated <path> (id "
<< p.first << ")";
Logger::Warning("SER", 22, ss.str());
logger_.Warning("SER", 22, ss.str());
}
}
@@ -650,7 +650,7 @@ void SvgSerializer::write(const IfcGeom::BRepElement* brep_obj) {
BRepBndLib::AddOBB(compound_unmirrored, *view_box_3d_, false, false, false);
#endif
} else {
Logger::Error("SER", 23, "Failed to box or edge from drawing annotation");
logger_.Error("SER", 23, "Failed to box or edge from drawing annotation");
}
std::vector<string_property> props;
@@ -797,7 +797,7 @@ void SvgSerializer::write(const geometry_data& data) {
if (data.storey) {
section_heights_storage.push_back(horizontal_plan{ data.storey, data.storey_elevation, +1. });
} else {
Logger::Warning("SER", 24, "No global section height and unable to determine building storey for:", data.product);
logger_.Warning("SER", 24, "No global section height and unable to determine building storey for:", data.product);
return;
}
}
@@ -812,7 +812,7 @@ void SvgSerializer::write(const geometry_data& data) {
Bnd_OBB obb;
BRepBndLib::AddOBB(compound_unmirrored, obb, false, false, false);
if (view_box_3d_->IsOut(obb)) {
Logger::Notice("SER", 25, "Not including element due to viewBox", data.product);
logger_.Notice("SER", 25, "Not including element due to viewBox", data.product);
return;
}
}
@@ -859,7 +859,7 @@ void SvgSerializer::write(const geometry_data& data) {
}
}
} catch (std::exception& e) {
Logger::Error("SER", 26, e);
logger_.Error("SER", 26, e);
}
if (operation_type && ((*operation_type == "SINGLE_SWING_LEFT") || (*operation_type == "SINGLE_SWING_RIGHT"))) {
@@ -1112,7 +1112,7 @@ void SvgSerializer::write(const geometry_data& data) {
compound_to_hlr = &subtracted_shape;
} catch (...) {
Logger::Error("SER", 27, "Failed to cut element for HLR", data.product);
logger_.Error("SER", 27, "Failed to cut element for HLR", data.product);
}
}
}
@@ -1204,11 +1204,11 @@ void SvgSerializer::write(const geometry_data& data) {
if (storey) {
auto it = storey_hlr.find(storey);
if (it == storey_hlr.end()) {
it = storey_hlr.insert({ storey, hlr_t(use_prefiltering_, use_hlr_poly_, segment_projection_, projection_plane) }).first;
it = storey_hlr.insert({ storey, hlr_t(logger_, use_prefiltering_, use_hlr_poly_, segment_projection_, projection_plane) }).first;
}
it->second.add(*compound_to_hlr, data.product);
} else {
Logger::Warning("SER", 28, "Unable to invoke HLR due to absence of storey containment", data.product);
logger_.Warning("SER", 28, "Unable to invoke HLR due to absence of storey containment", data.product);
}
} else if (hlr) {
hlr->add(*compound_to_hlr, data.product);
@@ -1681,7 +1681,7 @@ void SvgSerializer::write(const geometry_data& data) {
}
if (!emitted) {
Logger::Warning("SER", 29, "Element not written to SVG due to section heights", data.product);
logger_.Warning("SER", 29, "Element not written to SVG due to section heights", data.product);
}
}
@@ -1862,7 +1862,7 @@ void SvgSerializer::addTextAnnotations(const drawing_key& k) {
auto desc = (std::string) ds;
if (object_type == "Text") {
auto mapping = ifcopenshell::geometry::impl::mapping_implementations().construct(file, geometry_settings_);
auto mapping = ifcopenshell::geometry::impl::mapping_implementations().construct(file, geometry_settings_, logger_);
auto item = mapping->map(pl);
auto matrix = ifcopenshell::geometry::taxonomy::cast<ifcopenshell::geometry::taxonomy::matrix4>(item);
delete mapping;
@@ -2066,7 +2066,7 @@ void SvgSerializer::finalize() {
// @todo do we have always have pln here?
if (use_hlr && pln) {
hlr = new hlr_t(use_prefiltering_, use_hlr_poly_, segment_projection_, *pln);
hlr = new hlr_t(logger_, use_prefiltering_, use_hlr_poly_, segment_projection_, *pln);
}
section_data_ = std::vector<section_data>{ sd };
@@ -2317,7 +2317,7 @@ void SvgSerializer::setFile(IfcParse::IfcFile* f) {
auto storeys = f->instances_by_type("IfcBuildingStorey");
if (!storeys || storeys->size() == 0) {
auto mapping = ifcopenshell::geometry::impl::mapping_implementations().construct(file, geometry_settings_);
auto mapping = ifcopenshell::geometry::impl::mapping_implementations().construct(file, geometry_settings_, logger_);
std::vector<const IfcParse::declaration*> to_derive_from;
to_derive_from.push_back(f->schema()->declaration_by_name("IfcBuilding"));
@@ -2337,7 +2337,7 @@ void SvgSerializer::setFile(IfcParse::IfcFile* f) {
#ifdef TAXONOMY_USE_NAKED_PTR
delete matrix;
#endif
Logger::Warning("SER", 30, "No building storeys encountered, used for reference:", product);
logger_.Warning("SER", 30, "No building storeys encountered, used for reference:", product);
return;
}
}
@@ -2347,7 +2347,7 @@ void SvgSerializer::setFile(IfcParse::IfcFile* f) {
delete mapping;
Logger::Warning("SER", 31, "No building storeys encountered, output might be invalid or missing");
logger_.Warning("SER", 31, "No building storeys encountered, output might be invalid or missing");
}
}
@@ -2358,7 +2358,7 @@ void SvgSerializer::setSectionHeight(double h, const IfcUtil::IfcBaseEntity* sto
void SvgSerializer::setSectionHeightsFromStoreys(double offset) {
if (!file) {
Logger::Error("SER", 32, "No file specified");
logger_.Error("SER", 32, "No file specified");
return;
}
with_section_heights_from_storey_ = true;
@@ -2373,7 +2373,7 @@ void SvgSerializer::setSectionHeightsFromStoreys(double offset) {
try {
elev = attr_value;
} catch (std::exception& e) {
Logger::Error("SER", 33, e);
logger_.Error("SER", 33, e);
continue;
}
if (!section_data_->empty()) {