Merge remote-tracking branch 'origin/v0.8.0' into ifcviewer-wgpu

This commit is contained in:
Thomas Krijnen
2026-07-09 13:21:39 +02:00
373 changed files with 22411 additions and 4242 deletions
+63 -62
View File
@@ -219,7 +219,7 @@ bool file_exists(const std::string& filename) {
static std::basic_stringstream<path_t::value_type> log_stream;
void write_log(bool);
void fix_quantities(ifcopenshell::file&, bool, bool, bool);
void fix_quantities(ifcopenshell::file&, bool, bool, bool, Logger& logger = Logger::Root());
std::string format_duration(time_t start, time_t end);
/// @todo make the filters non-global
@@ -249,7 +249,7 @@ size_t read_filters_from_file(const std::string&, inclusion_filter&, inclusion_t
void parse_filter(geom_filter &, const std::vector<std::string>&);
std::vector<ifcopenshell::geometry::filter_t> setup_filters(const std::vector<geom_filter>&, const std::string&);
bool init_input_file(const std::string& filename, ifcopenshell::file*& ifc_file, bool no_progress, bool mmap, bool bypass_properties=false);
bool init_input_file(const std::string& filename, ifcopenshell::file*& ifc_file, bool no_progress, bool mmap, bool bypass_properties=false, Logger& logger = Logger::Root());
// from https://stackoverflow.com/questions/31696328/boost-program-options-using-zero-parameter-options-multiple-times
struct verbosity_counter {
@@ -271,6 +271,7 @@ int main(int argc, char** argv) {
typedef po::command_line_parser command_line_parser;
typedef char char_t;
#endif
Logger logger;
inclusion_filter include_filter;
inclusion_traverse_filter include_traverse_filter;
@@ -463,15 +464,15 @@ int main(int argc, char** argv) {
if (num_threads <= 0) {
num_threads = std::thread::hardware_concurrency();
logger::notice("Using " + std::to_string(num_threads) + " threads");
logger.Notice("SYS", 7, "Using " + std::to_string(num_threads) + " threads");
}
if (vmap.count("log-format") == 1) {
boost::to_lower(log_format);
if (log_format == "plain") {
logger::output_format(logger::FMT_PLAIN);
logger.OutputFormat(Logger::FMT_PLAIN);
} else if (log_format == "json") {
logger::output_format(logger::FMT_JSON);
logger.OutputFormat(Logger::FMT_JSON);
} else {
cerr_ << "[error] --log-format should be either plain or json" << std::endl;
print_usage();
@@ -482,7 +483,7 @@ int main(int argc, char** argv) {
if (!filter_filename.empty()) {
size_t num_filters = read_filters_from_file(ifcopenshell::path::to_utf8(filter_filename), include_filter, include_traverse_filter, exclude_filter, exclude_traverse_filter);
if (num_filters) {
logger::notice(boost::lexical_cast<std::string>(num_filters) + " filters read from specifified file.");
logger.Notice("SYS", 8, boost::lexical_cast<std::string>(num_filters) + " filters read from specifified file.");
} else {
cerr_ << "[error] No filters read from specifified file.\n";
return EXIT_FAILURE;
@@ -546,27 +547,27 @@ int main(int argc, char** argv) {
if (vmap.count("log-file")) {
log_fs.open(log_file.c_str(), std::ios::app);
logger::set_output(quiet ? nullptr : &cout_, &log_fs);
logger.SetOutput(quiet ? nullptr : &cout_, &log_fs);
} else {
logger::set_output(quiet ? nullptr : &cout_, vcounter.count > 1 ? &cout_ : &log_stream);
logger.SetOutput(quiet ? nullptr : &cout_, vcounter.count > 1 ? &cout_ : &log_stream);
}
switch (vcounter.count) {
case 0:
logger::verbosity(logger::LOG_ERROR);
logger.Verbosity(Logger::LOG_ERROR);
break;
case 1:
logger::verbosity(logger::LOG_NOTICE);
logger.Verbosity(Logger::LOG_NOTICE);
break;
case 2:
logger::verbosity(logger::LOG_DEBUG);
logger.Verbosity(Logger::LOG_DEBUG);
break;
case 3:
logger::verbosity(logger::LOG_PERF);
logger.Verbosity(Logger::LOG_PERF);
break;
case 4:
logger::verbosity(logger::LOG_PERF);
logger::print_performance_stats_on_element(true);
logger.Verbosity(Logger::LOG_PERF);
logger.PrintPerformanceStatsOnElement(true);
break;
}
@@ -620,12 +621,12 @@ int main(int argc, char** argv) {
if (serializer->is_streaming() != use_input_filename) {
throw ifcopenshell::exception("Selected document serializer streaming mode does not match its registry metadata");
}
logger::status("Writing " + boost::to_upper_copy(document_serializer_info->format) + " output...");
logger.status("Writing " + boost::to_upper_copy(document_serializer_info->format) + " output...");
serializer->finalize();
serializer.reset();
time(&end);
logger::status("Done! Conversion took " + format_duration(start, end));
logger.status("Done! Conversion took " + format_duration(start, end));
if (!document_serializer_info->writes_final_output &&
!ifcopenshell::path::rename_file(ifcopenshell::path::to_utf8(output_temp_filename), ifcopenshell::path::to_utf8(output_filename))) {
@@ -636,7 +637,7 @@ int main(int argc, char** argv) {
exit_code = EXIT_SUCCESS;
}
} catch (const std::exception& e) {
logger::error(e);
logger.Error("SYS", 9, e);
}
write_log(!quiet);
return exit_code;
@@ -648,24 +649,24 @@ int main(int argc, char** argv) {
} else if (output_extension == IFC) {
int exit_code = EXIT_FAILURE;
try {
if (init_input_file(ifcopenshell::path::to_utf8(input_filename), ifc_file, no_progress || quiet, mmap)) {
if (init_input_file(ifcopenshell::path::to_utf8(input_filename), ifc_file, no_progress || quiet, mmap, false, logger)) {
time_t start, end;
time(&start);
std::ofstream fs(output_filename.c_str());
if (fs.is_open()) {
if (vmap.count("calculate-quantities")) {
fix_quantities(*ifc_file, no_progress, quiet, stderr_progress);
fix_quantities(*ifc_file, no_progress, quiet, stderr_progress, logger);
}
fs << *ifc_file;
exit_code = EXIT_SUCCESS;
} else {
logger::error("Unable to open output file for writing");
logger.Error("SYS", 10, "Unable to open output file for writing");
}
time(&end);
logger::status("Done! Writing IFC took " + format_duration(start, end));
logger.Status("Done! Writing IFC took " + format_duration(start, end));
}
} catch (const std::exception& e) {
logger::error(e);
logger.Error("SYS", 11, e);
}
write_log(!quiet);
return exit_code;
@@ -698,9 +699,9 @@ int main(int argc, char** argv) {
return EXIT_FAILURE;
}
if (!entity_filter.entity_names.empty()) { entity_filter.update_description(); logger::notice(entity_filter.description); }
if (!layer_filter.values.empty()) { layer_filter.update_description(); logger::notice(layer_filter.description); }
if (!attribute_filter.attribute_name.empty()) { attribute_filter.update_description(); logger::notice(attribute_filter.description); }
if (!entity_filter.entity_names.empty()) { entity_filter.update_description(); logger.Notice("SYS", 13, entity_filter.description); }
if (!layer_filter.values.empty()) { layer_filter.update_description(); logger.Notice("SYS", 14, layer_filter.description); }
if (!attribute_filter.attribute_name.empty()) { attribute_filter.update_description(); logger.Notice("SYS", 15, attribute_filter.description); }
if (geometry_serializer_info && geometry_serializer_info->requires_ascii_temp_file) {
// These serializers do not support opening unicode paths. Therefore
@@ -766,13 +767,13 @@ int main(int argc, char** argv) {
const bool is_tesselated = serializer->isTesselated(); // isTesselated() doesn't change at run-time
if (!is_tesselated) {
if (geometry_settings.get<ifcopenshell::geometry::settings::WeldVertices>().get()) {
logger::notice("Weld vertices setting ignored when writing non-tesselated output");
logger.Notice("SYS", 16, "Weld vertices setting ignored when writing non-tesselated output");
}
if (geometry_settings.get<ifcopenshell::geometry::settings::GenerateUvs>().get()) {
logger::notice("Generate UVs setting ignored when writing non-tesselated output");
logger.Notice("SYS", 17, "Generate UVs setting ignored when writing non-tesselated output");
}
if (center_model || center_model_geometry) {
logger::notice("Centering/offsetting model setting ignored when writing non-tesselated output");
logger.Notice("SYS", 18, "Centering/offsetting model setting ignored when writing non-tesselated output");
}
geometry_settings.get<ifcopenshell::geometry::settings::IteratorOutput>().value = ifcopenshell::geometry::settings::NATIVE;
@@ -790,7 +791,7 @@ int main(int argc, char** argv) {
// @nb last argument true -> bypass_properties which are not read by any of the geometry serializers
// Document serializers and IFC are already special-cased above
// SVG requires properties for IfcAnnotation/DRAWING properties
if (!init_input_file(ifcopenshell::path::to_utf8(input_filename), ifc_file, no_progress || quiet, mmap, geometry_serializer_info->bypass_properties)) {
if (!init_input_file(ifcopenshell::path::to_utf8(input_filename), ifc_file, no_progress || quiet, mmap, geometry_serializer_info->bypass_properties, logger)) {
write_log(!quiet);
serializer.reset();
ifcopenshell::path::delete_file(ifcopenshell::path::to_utf8(output_temp_filename)); /**< @todo Windows Unicode support */
@@ -798,9 +799,9 @@ int main(int argc, char** argv) {
}
if (vmap.count("log-file")) {
logger::set_output(quiet ? nullptr : &cout_, &log_fs);
logger.SetOutput(quiet ? nullptr : &cout_, &log_fs);
} else {
logger::set_output(quiet ? nullptr : &cout_, vcounter.count > 1 ? &cout_ : &log_stream);
logger.SetOutput(quiet ? nullptr : &cout_, vcounter.count > 1 ? &cout_ : &log_stream);
}
if (model_rotation) {
@@ -815,13 +816,13 @@ int main(int argc, char** argv) {
std::stringstream msg;
msg << "Using model rotation (" << rotation[0] << "," << rotation[1] << "," << rotation[2] << "," << rotation[3] << ")";
logger::notice(msg.str());
logger.Notice("SYS", 19, msg.str());
geometry_settings.get<ifcopenshell::geometry::settings::ModelRotation>().value = rotation;
}
if (model_offset && (center_model || center_model_geometry)) {
logger::notice("--model-offset ignored with --center-model or --center-model-geometry");
logger.Notice("GEO", 22, "--model-offset ignored with --center-model or --center-model-geometry");
}
if (model_offset && !(center_model || center_model_geometry)) {
@@ -836,7 +837,7 @@ int main(int argc, char** argv) {
std::stringstream msg;
msg << std::setprecision(std::numeric_limits<double>::max_digits10) << "Using model offset (" << offset[0] << "," << offset[1] << "," << offset[2] << ")";
logger::notice(msg.str());
logger.Notice("SYS", 20, msg.str());
geometry_settings.get<ifcopenshell::geometry::settings::ModelOffset>().value = offset;
}
@@ -844,17 +845,17 @@ int main(int argc, char** argv) {
if (is_tesselated && (center_model || center_model_geometry)) {
std::vector<double> offset(3);
IfcGeom::Iterator tmp_context_iterator(ifcopenshell::geometry::kernels::construct(ifc_file, geometry_kernel, geometry_settings), geometry_settings, ifc_file, filter_funcs, num_threads);
IfcGeom::Iterator tmp_context_iterator(ifcopenshell::geometry::kernels::construct(ifc_file, geometry_kernel, geometry_settings, logger), geometry_settings, ifc_file, filter_funcs, num_threads, logger);
time_t start, end;
time(&start);
if (!quiet) logger::status("Computing bounds...");
if (!quiet) logger.Status("Computing bounds...");
if (center_model_geometry) {
if (!tmp_context_iterator.initialize()) {
/// @todo It would be nice to know and print separate error prints for a case where we found no entities
/// and for a case we found no entities that satisfy our filtering criteria.
logger::notice("No geometrical elements found or none successfully converted");
logger.Notice("GEO", 23, "No geometrical elements found or none successfully converted");
serializer.reset();
ifcopenshell::path::delete_file(ifcopenshell::path::to_utf8(output_temp_filename));
write_log(!quiet);
@@ -865,7 +866,7 @@ int main(int argc, char** argv) {
tmp_context_iterator.compute_bounds(center_model_geometry);
time(&end);
if (!quiet) logger::status("Done ! Bounds computed in " + format_duration(start, end));
if (!quiet) logger.Status("Done ! Bounds computed in " + format_duration(start, end));
auto center = (tmp_context_iterator.bounds_min().ccomponents() + tmp_context_iterator.bounds_max().ccomponents()) * 0.5;
offset[0] = -center(0);
@@ -874,7 +875,7 @@ int main(int argc, char** argv) {
std::stringstream msg;
msg << std::setprecision (std::numeric_limits<double>::max_digits10) << "Using model offset (" << offset[0] << "," << offset[1] << "," << offset[2] << ")";
logger::notice(msg.str());
logger.Notice("SYS", 21, msg.str());
geometry_settings.get<ifcopenshell::geometry::settings::ModelOffset>().value = offset;
}
@@ -890,15 +891,15 @@ int main(int argc, char** argv) {
std::unique_ptr<IfcGeom::Iterator> context_iterator;
if (!elems_from_adaptor) {
context_iterator.reset(new IfcGeom::Iterator(ifcopenshell::geometry::kernels::construct(ifc_file, geometry_kernel, geometry_settings), geometry_settings, ifc_file, filter_funcs, num_threads));
context_iterator.reset(new IfcGeom::Iterator(ifcopenshell::geometry::kernels::construct(ifc_file, geometry_kernel, geometry_settings, logger), geometry_settings, ifc_file, filter_funcs, num_threads, logger));
}
logger::message(logger::LOG_PERF, "file geometry conversion");
logger.message(logger::LOG_PERF, "file geometry conversion");
if (context_iterator && !context_iterator->initialize()) {
/// @todo It would be nice to know and print separate error prints for a case where we found no entities
/// and for a case we found no entities that satisfy our filtering criteria.
logger::notice("No geometrical elements found or none successfully converted");
logger.Notice("GEO", 25, "No geometrical elements found or none successfully converted");
serializer.reset();
ifcopenshell::path::delete_file(ifcopenshell::path::to_utf8(output_temp_filename));
write_log(!quiet);
@@ -918,7 +919,7 @@ int main(int argc, char** argv) {
int old_progress = quiet ? 0 : -1;
if (!quiet) {
logger::status("Creating geometry...");
logger.Status("Creating geometry...");
}
// The functions IfcGeom::Iterator::get() and IfcGeom::Iterator::next()
@@ -963,10 +964,10 @@ int main(int argc, char** argv) {
if (stderr_progress)
cerr_ << std::flush;
} else if (vcounter.count == 2) {
logger::message(logger::LOG_DEBUG, "Progress " + boost::lexical_cast<std::string>(progress));
logger.Message(Logger::LOG_DEBUG, "SYS", 23, "Progress " + boost::lexical_cast<std::string>(progress));
} else {
progress = progress / 2;
if (old_progress != progress) logger::progress_bar(progress);
if (old_progress != progress) logger.ProgressBar(progress);
old_progress = progress;
}
}
@@ -995,7 +996,7 @@ int main(int argc, char** argv) {
}
} else {
const std::string task = ((num_threads == 1) ? "creating" : "writing");
logger::status("\rDone " + task + " geometry (" + boost::lexical_cast<std::string>(num_created) +
logger.Status("\rDone " + task + " geometry (" + boost::lexical_cast<std::string>(num_created) +
" objects) ");
}
@@ -1003,7 +1004,7 @@ int main(int argc, char** argv) {
// Make sure the dtor is explicitly run here (e.g. output files are closed before renaming them).
serializer.reset();
logger::message(logger::LOG_PERF, "done file geometry conversion");
logger.Message(Logger::LOG_PERF, "GEO", 26, "done file geometry conversion");
bool successful;
if (geometry_serializer_info->writes_final_output) {
@@ -1021,13 +1022,13 @@ int main(int argc, char** argv) {
output_temp_filename << "' for the conversion result.";
}
if (geometry_settings.get<ifcopenshell::geometry::settings::ValidateQuantities>().get() && logger::max_severity() >= logger::LOG_ERROR) {
logger::error("Errors encountered during processing.");
if (geometry_settings.get<ifcopenshell::geometry::settings::ValidateQuantities>().get() && logger.MaxSeverity() >= Logger::LOG_ERROR) {
logger.Error("SYS", 24, "Errors encountered during processing.");
successful = false;
}
if (logger::verbosity() == logger::LOG_PERF) {
logger::print_performance_stats();
if (logger.Verbosity() == Logger::LOG_PERF) {
logger.PrintPerformanceStats();
}
write_log(!quiet);
@@ -1035,7 +1036,7 @@ int main(int argc, char** argv) {
time(&end);
if (!quiet) {
logger::status("\nConversion took " + format_duration(start, end));
logger.Status("\nConversion took " + format_duration(start, end));
}
return successful ? EXIT_SUCCESS : EXIT_FAILURE;
@@ -1073,18 +1074,18 @@ void write_log(bool header) {
#include <boost/algorithm/string/predicate.hpp>
bool init_input_file(const std::string& filename, ifcopenshell::file*& ifc_file, bool no_progress, bool mmap, bool bypass_properties) {
bool init_input_file(const std::string& filename, ifcopenshell::file*& ifc_file, bool no_progress, bool mmap, bool bypass_properties, Logger& logger) {
time_t start, end;
// Prevent file::Init() prints by setting output to null temporarily
if (no_progress) { logger::set_output(NULL, &log_stream); }
if (no_progress) { logger.set_output(NULL, &log_stream); }
time(&start);
bool requires_init = false;
{
ifc_file = new ifcopenshell::file(ifcopenshell::uninitialized_tag{});
ifc_file = new ifcopenshell::file(ifcopenshell::uninitialized_tag{}, logger);
requires_init = true;
}
@@ -1110,13 +1111,13 @@ bool init_input_file(const std::string& filename, ifcopenshell::file*& ifc_file,
}
if (!ifc_file || !ifc_file->good()) {
logger::error("Unable to parse input file '" + filename + "'");
logger.Error("SYN", 1, "Unable to parse input file '" + filename + "'");
return false;
}
time(&end);
if (no_progress) { logger::set_output(&cout_, &log_stream); }
else { logger::status("Parsing input file took " + format_duration(start, end)); }
if (no_progress) { logger.SetOutput(&cout_, &log_stream); }
else { logger.Status("Parsing input file took " + format_duration(start, end)); }
return true;
@@ -1329,7 +1330,7 @@ namespace latebound_access {
}
}
void fix_quantities(ifcopenshell::file& f, bool no_progress, bool quiet, bool stderr_progress) {
void fix_quantities(ifcopenshell::file& f, bool no_progress, bool quiet, bool stderr_progress, Logger& logger) {
{
auto delete_reversed = [&f](const std::vector<express::Base>& insts) {
// Lists are traversed back to front as the list may be mutated when
@@ -1380,7 +1381,7 @@ void fix_quantities(ifcopenshell::file& f, bool no_progress, bool quiet, bool st
settings.get<ifcopenshell::geometry::settings::ConvertBackUnits>().value = true;
settings.get<ifcopenshell::geometry::settings::IteratorOutput>().value = ifcopenshell::geometry::settings::NATIVE;
IfcGeom::Iterator context_iterator(ifcopenshell::geometry::kernels::construct(&f, "opencascade", settings), settings, &f, {}, 1);
IfcGeom::Iterator context_iterator(ifcopenshell::geometry::kernels::construct(&f, "opencascade", settings, logger), settings, &f, {}, 1, logger);
if (!context_iterator.initialize()) {
return;
@@ -1507,7 +1508,7 @@ void fix_quantities(ifcopenshell::file& f, bool no_progress, bool quiet, bool st
cerr_ << std::flush;
} else {
const int progress = context_iterator.progress() / 2;
if (old_progress != progress) logger::progress_bar(progress);
if (old_progress != progress) logger.ProgressBar(progress);
old_progress = progress;
}
}
@@ -1523,7 +1524,7 @@ void fix_quantities(ifcopenshell::file& f, bool no_progress, bool quiet, bool st
if (stderr_progress)
cerr_ << std::flush;
} else {
logger::status("\rDone writing quantities for " + boost::lexical_cast<std::string>(num_created) +
logger.Status("\rDone writing quantities for " + boost::lexical_cast<std::string>(num_created) +
" objects ");
}