mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-17 10:59:17 +00:00
Pass around non-static logger instances and programmatic access to messages in-memory
This commit is contained in:
+27
-27
@@ -31,7 +31,7 @@ bool IfcGeom::Iterator::initialize() {
|
||||
try {
|
||||
converter_->mapping()->get_representations(reps, filters_);
|
||||
} catch (const std::exception& e) {
|
||||
Logger::Error("GEO", 50, e);
|
||||
logger_.Error("GEO", 50, e);
|
||||
}
|
||||
time_points[1] = high_resolution_clock::now();
|
||||
|
||||
@@ -94,7 +94,7 @@ bool IfcGeom::Iterator::initialize() {
|
||||
tasks_.back().item = p.first;
|
||||
tasks_.back().products = p.second;
|
||||
}
|
||||
Logger::Notice("SYS", 26, "Merged " + std::to_string(old_size) + " tasks into " + std::to_string(tasks_.size()) + " tasks due to permissive shape reuse");
|
||||
logger_.Notice("SYS", 26, "Merged " + std::to_string(old_size) + " tasks into " + std::to_string(tasks_.size()) + " tasks due to permissive shape reuse");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,10 +139,10 @@ bool IfcGeom::Iterator::initialize() {
|
||||
}
|
||||
*/
|
||||
|
||||
Logger::Notice("SYS", 27, "Created " + boost::lexical_cast<std::string>(tasks_.size()) + " tasks for " + boost::lexical_cast<std::string>(num_products) + " products");
|
||||
logger_.Notice("SYS", 27, "Created " + boost::lexical_cast<std::string>(tasks_.size()) + " tasks for " + boost::lexical_cast<std::string>(num_products) + " products");
|
||||
|
||||
if (tasks_.size() == 0) {
|
||||
Logger::Warning("GEO", 51, "No representations encountered, aborting");
|
||||
logger_.Warning("GEO", 51, "No representations encountered, aborting");
|
||||
initialization_outcome_.reset(false);
|
||||
} else if (!settings_.get<ifcopenshell::geometry::settings::DeferProcessingFirstElement>().get()) {
|
||||
|
||||
@@ -194,7 +194,7 @@ void IfcGeom::Iterator::process_concurrently() {
|
||||
|
||||
kernel_pool.reserve(conc_threads);
|
||||
for (unsigned i = 0; i < conc_threads; ++i) {
|
||||
kernel_pool.push_back(new ifcopenshell::geometry::Converter(std::unique_ptr<ifcopenshell::geometry::kernels::AbstractKernel>(converter_->kernel()->clone()), ifc_file, settings_));
|
||||
kernel_pool.push_back(new ifcopenshell::geometry::Converter(std::unique_ptr<ifcopenshell::geometry::kernels::AbstractKernel>(converter_->kernel()->clone()), ifc_file, settings_, logger_));
|
||||
}
|
||||
|
||||
std::vector<std::future<geometry_conversion_result*>> threadpool;
|
||||
@@ -231,14 +231,14 @@ void IfcGeom::Iterator::process_concurrently() {
|
||||
try {
|
||||
this->create_element_(kernel, settings, rep);
|
||||
} catch (const std::exception& e) {
|
||||
Logger::Error("GEO", 52,
|
||||
logger_.Error("GEO", 52,
|
||||
std::string("Exception '") + e.what() +
|
||||
std::string("' occurred while iterator was creating a shape: "),
|
||||
rep->item->instance
|
||||
);
|
||||
had_error_processing_elements_ = true;
|
||||
} catch (...) {
|
||||
Logger::Error("GEO", 53,
|
||||
logger_.Error("GEO", 53,
|
||||
"Unknown exception occurred while iteartor was creating a shape: ",
|
||||
rep->item->instance
|
||||
);
|
||||
@@ -263,10 +263,10 @@ void IfcGeom::Iterator::process_concurrently() {
|
||||
|
||||
finished_ = true;
|
||||
|
||||
Logger::SetProduct(boost::none);
|
||||
logger_.SetProduct(boost::none);
|
||||
|
||||
if (!terminating_) {
|
||||
Logger::Status("\rDone creating geometry (" + boost::lexical_cast<std::string>(all_processed_elements_.size()) +
|
||||
logger_.Status("\rDone creating geometry (" + boost::lexical_cast<std::string>(all_processed_elements_.size()) +
|
||||
" objects) ");
|
||||
}
|
||||
}
|
||||
@@ -360,20 +360,20 @@ void IfcGeom::Iterator::create_element_(ifcopenshell::geometry::Converter* kerne
|
||||
const IfcUtil::IfcBaseEntity* product = product_node.first;
|
||||
const auto& place = product_node.second;
|
||||
|
||||
Logger::SetProduct(product);
|
||||
logger_.SetProduct(product);
|
||||
|
||||
IfcGeom::BRepElement* brep = static_cast<IfcGeom::BRepElement*>(decorate_with_cache_(GeometrySerializer::READ_BREP, (std::string)product->get("GlobalId"), std::to_string(rep->item->instance->as<IfcUtil::IfcBaseEntity>()->id()), [kernel, settings, product, place, rep]() {
|
||||
return kernel->create_brep_for_representation_and_product(rep->item, product, place);
|
||||
}));
|
||||
|
||||
if (!brep) {
|
||||
Logger::SetProduct(boost::none);
|
||||
logger_.SetProduct(boost::none);
|
||||
return;
|
||||
}
|
||||
|
||||
auto elem = process_based_on_settings(settings, brep);
|
||||
if (!elem) {
|
||||
Logger::SetProduct(boost::none);
|
||||
logger_.SetProduct(boost::none);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -397,7 +397,7 @@ void IfcGeom::Iterator::create_element_(ifcopenshell::geometry::Converter* kerne
|
||||
}
|
||||
}
|
||||
|
||||
Logger::SetProduct(boost::none);
|
||||
logger_.SetProduct(boost::none);
|
||||
}
|
||||
|
||||
IfcGeom::Element* IfcGeom::Iterator::process_based_on_settings(ifcopenshell::geometry::Settings settings, IfcGeom::BRepElement* elem, IfcGeom::TriangulationElement* previous)
|
||||
@@ -406,7 +406,7 @@ IfcGeom::Element* IfcGeom::Iterator::process_based_on_settings(ifcopenshell::geo
|
||||
try {
|
||||
return new IfcGeom::SerializedElement(*elem);
|
||||
} catch (...) {
|
||||
Logger::Message(Logger::LOG_ERROR, "GEO", 54, "Getting a serialized element from model failed.");
|
||||
logger_.Message(Logger::LOG_ERROR, "GEO", 54, "Getting a serialized element from model failed.");
|
||||
return nullptr;
|
||||
}
|
||||
} else if (settings.get<ifcopenshell::geometry::settings::IteratorOutput>().get() == ifcopenshell::geometry::settings::TRIANGULATED) {
|
||||
@@ -417,7 +417,7 @@ IfcGeom::Element* IfcGeom::Iterator::process_based_on_settings(ifcopenshell::geo
|
||||
gid2 = gid2.substr(0, hyphen);
|
||||
}
|
||||
|
||||
return decorate_with_cache_(GeometrySerializer::READ_TRIANGULATION, elem->guid(), gid2, [elem, previous]() {
|
||||
return decorate_with_cache_(GeometrySerializer::READ_TRIANGULATION, elem->guid(), gid2, [this, elem, previous]() {
|
||||
try {
|
||||
if (!previous) {
|
||||
return new TriangulationElement(*elem);
|
||||
@@ -425,7 +425,7 @@ IfcGeom::Element* IfcGeom::Iterator::process_based_on_settings(ifcopenshell::geo
|
||||
return new TriangulationElement(*elem, previous->geometry_pointer());
|
||||
}
|
||||
} catch (...) {
|
||||
Logger::Message(Logger::LOG_ERROR, "GEO", 55, "Getting a triangulation element from model failed.");
|
||||
logger_.Message(Logger::LOG_ERROR, "GEO", 55, "Getting a triangulation element from model failed.");
|
||||
}
|
||||
return (TriangulationElement*)nullptr;
|
||||
});
|
||||
@@ -466,7 +466,7 @@ void IfcGeom::Iterator::log_timepoints() const {
|
||||
for (auto it = time_points.begin() + 1; it != time_points.end(); ++it) {
|
||||
auto jt = it - 1;
|
||||
duration<double, std::milli> ms_double = (*it) - (*jt);
|
||||
Logger::Notice("SYS", 28, labels[std::distance(time_points.begin(), jt)] + " took " + std::to_string(ms_double.count()) + "ms");
|
||||
logger_.Notice("SYS", 28, labels[std::distance(time_points.begin(), jt)] + " took " + std::to_string(ms_double.count()) + "ms");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -501,7 +501,7 @@ const IfcUtil::IfcBaseClass* IfcGeom::Iterator::next() {
|
||||
|
||||
if (num_threads_ != 1) {
|
||||
if (!wait_for_element()) {
|
||||
Logger::SetProduct(boost::none);
|
||||
logger_.SetProduct(boost::none);
|
||||
time_points[3] = high_resolution_clock::now();
|
||||
log_timepoints();
|
||||
task_result_ptr_exhausted = true;
|
||||
@@ -517,7 +517,7 @@ const IfcUtil::IfcBaseClass* IfcGeom::Iterator::next() {
|
||||
// shape representation
|
||||
if (task_result_iterator_ == --all_processed_elements_.end()) {
|
||||
if (!create()) {
|
||||
Logger::SetProduct(boost::none);
|
||||
logger_.SetProduct(boost::none);
|
||||
time_points[3] = high_resolution_clock::now();
|
||||
log_timepoints();
|
||||
task_result_ptr_exhausted = true;
|
||||
@@ -554,7 +554,7 @@ IfcGeom::Element* IfcGeom::Iterator::get()
|
||||
try {
|
||||
parent_object = get_object(ret->parent_id());
|
||||
} catch (const std::exception& e) {
|
||||
Logger::Error("GEO", 56, e);
|
||||
logger_.Error("GEO", 56, e);
|
||||
hasParent = false;
|
||||
}
|
||||
|
||||
@@ -572,7 +572,7 @@ IfcGeom::Element* IfcGeom::Iterator::get()
|
||||
try {
|
||||
parent_object = get_object(pid);
|
||||
} catch (const std::exception& e) {
|
||||
Logger::Error("GEO", 57, e);
|
||||
logger_.Error("GEO", 57, e);
|
||||
hasParent = false;
|
||||
}
|
||||
}
|
||||
@@ -619,9 +619,9 @@ const IfcGeom::Element* IfcGeom::Iterator::get_object(int id) {
|
||||
m4 = casted->matrix;
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Logger::Error("GEO", 58, e);
|
||||
logger_.Error("GEO", 58, e);
|
||||
} catch (...) {
|
||||
Logger::Error("GEO", 59, "Unknown error returning product");
|
||||
logger_.Error("GEO", 59, "Unknown error returning product");
|
||||
}
|
||||
|
||||
Element* ifc_object = new Element(settings_, id, parent_id, product_name, instance_type, product_guid, "", m4, ifc_product);
|
||||
@@ -633,10 +633,10 @@ const IfcUtil::IfcBaseClass* IfcGeom::Iterator::create() {
|
||||
try {
|
||||
product = create_shape_model_for_next_entity();
|
||||
} catch (const std::exception& e) {
|
||||
Logger::Error("GEO", 60, e);
|
||||
logger_.Error("GEO", 60, e);
|
||||
had_error_processing_elements_ = true;
|
||||
} catch (...) {
|
||||
Logger::Error("GEO", 61, "Unknown error creating geometry");
|
||||
logger_.Error("GEO", 61, "Unknown error creating geometry");
|
||||
had_error_processing_elements_ = true;
|
||||
}
|
||||
return product;
|
||||
@@ -808,8 +808,8 @@ ifcopenshell::geometry::taxonomy::direction3::ptr IfcGeom::Iterator::remove_offs
|
||||
}
|
||||
}
|
||||
|
||||
Logger::Notice("SYS", 29, "Removed large offsets within " + std::to_string(num_offset_applied) + " products");
|
||||
Logger::Notice("SYS", 30, "Offset applied (" + std::to_string(vec(0)) + "," + std::to_string(vec(1)) + "," + std::to_string(vec(2)) + ")");
|
||||
logger_.Notice("SYS", 29, "Removed large offsets within " + std::to_string(num_offset_applied) + " products");
|
||||
logger_.Notice("SYS", 30, "Offset applied (" + std::to_string(vec(0)) + "," + std::to_string(vec(1)) + "," + std::to_string(vec(2)) + ")");
|
||||
|
||||
return make<direction3>(vec);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user