Restructure and rename

This commit is contained in:
Thomas Krijnen
2026-03-31 15:32:36 +02:00
parent 724cdb446e
commit a07f56db6f
237 changed files with 72532 additions and 72535 deletions
@@ -26,15 +26,15 @@
#include <nlohmann/json.hpp>
#include "../../ifcparse/IfcSIPrefix.h"
#include "../../ifcparse/si_prefix.h"
#include "../../ifcparse/utils.h"
#include "../../ifcparse/IfcLogger.h"
#include "../../ifcparse/logger.h"
using json = nlohmann::json;
namespace {
struct POSTFIX_SCHEMA(factory_t) {
JsonSerializer* operator()(IfcParse::IfcFile* file, const std::string& json_filename, JsonSerializer::Dialect dialect) const {
JsonSerializer* operator()(ifcopenshell::file* file, const std::string& json_filename, JsonSerializer::Dialect dialect) const {
POSTFIX_SCHEMA(JsonSerializer)* s = new POSTFIX_SCHEMA(JsonSerializer)(file, json_filename, dialect);
s->setFile(file);
return s;
@@ -56,14 +56,14 @@ class format_value_visitor : public boost::static_visitor<std::string> {
template <typename T>
json operator()(const T& t) const {
if constexpr (std::is_same_v<std::decay_t<T>, Derived> || std::is_same_v<std::decay_t<T>, boost::dynamic_bitset<>> || std::is_same_v<std::decay_t<T>, express::Base> || std::is_same_v<std::decay_t<T>, std::vector<int>> || std::is_same_v<std::decay_t<T>, std::vector<double>> || std::is_same_v<std::decay_t<T>, std::vector<std::string>> || std::is_same_v<std::decay_t<T>, std::vector<boost::dynamic_bitset<>>> || std::is_same_v<std::decay_t<T>, std::vector<express::Base>> || std::is_same_v<std::decay_t<T>, std::vector<std::vector<express::Base>>> || std::is_same_v<std::decay_t<T>, std::vector<std::vector<int>>> || std::is_same_v<std::decay_t<T>, std::vector<std::vector<double>>> || std::is_same_v<std::decay_t<T>, empty_aggregate_t> || std::is_same_v<std::decay_t<T>, empty_aggregate_of_aggregate_t> || std::is_same_v<std::decay_t<T>, Blank>) {
if constexpr (std::is_same_v<std::decay_t<T>, derived> || std::is_same_v<std::decay_t<T>, boost::dynamic_bitset<>> || std::is_same_v<std::decay_t<T>, express::Base> || std::is_same_v<std::decay_t<T>, std::vector<int>> || std::is_same_v<std::decay_t<T>, std::vector<double>> || std::is_same_v<std::decay_t<T>, std::vector<std::string>> || std::is_same_v<std::decay_t<T>, std::vector<boost::dynamic_bitset<>>> || std::is_same_v<std::decay_t<T>, std::vector<express::Base>> || std::is_same_v<std::decay_t<T>, std::vector<std::vector<express::Base>>> || std::is_same_v<std::decay_t<T>, std::vector<std::vector<int>>> || std::is_same_v<std::decay_t<T>, std::vector<std::vector<double>>> || std::is_same_v<std::decay_t<T>, empty_aggregate_t> || std::is_same_v<std::decay_t<T>, empty_aggregate_of_aggregate_t> || std::is_same_v<std::decay_t<T>, blank>) {
return "";
} else if constexpr (std::is_same_v<std::decay_t<T>, boost::logic::tribool>) {
// @todo handle indeterminate
return "";
} else if constexpr (std::is_same_v<std::decay_t<T>, std::string>) {
return t;
} else if constexpr (std::is_same_v<std::decay_t<T>, EnumerationReference>) {
} else if constexpr (std::is_same_v<std::decay_t<T>, enumeration_reference>) {
return t.value();
} else {
return t;
@@ -106,8 +106,8 @@ auto get_related(T t, F f, G g) {
}
}
}
} catch (IfcParse::IfcException& e) {
Logger::Error(e);
} catch (ifcopenshell::exception& e) {
logger::error(e);
}
}
return acc;
@@ -135,10 +135,10 @@ void format_entity_instance(express::Base instance, json& tree, express::Base pa
json child;
auto write_to_json = [&](const std::string& keyJson, const std::string& keyIfc) {
AttributeValue val;
attribute_value val;
try {
val = instance.as<express::Entity>().get(keyIfc);
} catch (const IfcParse::IfcException&) {
} catch (const ifcopenshell::exception&) {
// simply laziness like no attribute Tag on IfcProject
return;
}
@@ -278,7 +278,7 @@ void POSTFIX_SCHEMA(JsonSerializer)::finalize() {
auto projects = file->instances_by_type<IfcSchema::IfcProject>();
if (projects.size() != 1) {
Logger::Message(Logger::LOG_ERROR, "Expected a single IfcProject");
logger::message(logger::LOG_ERROR, "Expected a single IfcProject");
return;
}
IfcSchema::IfcProject project = projects.front();
@@ -287,7 +287,7 @@ void POSTFIX_SCHEMA(JsonSerializer)::finalize() {
try {
return fn();
} catch (const std::exception& e) {
Logger::Error(e);
logger::error(e);
static std::invoke_result_t<decltype(fn)> v;
return v;
}
@@ -594,7 +594,7 @@ void POSTFIX_SCHEMA(JsonSerializer)::finalize() {
descend(project, output["metaObjects"]);
std::ofstream f(IfcUtil::path::from_utf8(json_filename).c_str());
std::ofstream f(ifcopenshell::path::from_utf8(json_filename).c_str());
f << output.dump(4);
}
@@ -34,14 +34,14 @@
class POSTFIX_SCHEMA(JsonSerializer) : public JsonSerializer {
private:
IfcParse::IfcFile* file;
ifcopenshell::file* file;
// @todo
ifcopenshell::geometry::Settings settings_;
ifcopenshell::geometry::abstract_mapping* mapping_;
public:
POSTFIX_SCHEMA(JsonSerializer)(IfcParse::IfcFile* file, const std::string& json_filename, JsonSerializer::Dialect dialect)
POSTFIX_SCHEMA(JsonSerializer)(ifcopenshell::file* file, const std::string& json_filename, JsonSerializer::Dialect dialect)
: JsonSerializer(0, "", dialect), mapping_(ifcopenshell::geometry::impl::mapping_implementations().construct(file, settings_))
{
this->file = file;
@@ -50,7 +50,7 @@ class POSTFIX_SCHEMA(JsonSerializer) : public JsonSerializer {
}
void finalize();
void setFile(IfcParse::IfcFile*) {}
void setFile(ifcopenshell::file*) {}
};
#endif
@@ -26,9 +26,9 @@
#include <algorithm>
#include "../../ifcparse/IfcSIPrefix.h"
#include "../../ifcparse/si_prefix.h"
#include "../../ifcparse/utils.h"
#include "../../ifcparse/IfcLogger.h"
#include "../../ifcparse/logger.h"
using boost::property_tree::ptree;
@@ -36,7 +36,7 @@ using boost::property_tree::ptree;
namespace {
struct POSTFIX_SCHEMA(factory_t) {
XmlSerializer* operator()(IfcParse::IfcFile* file, const std::string& xml_filename) const {
XmlSerializer* operator()(ifcopenshell::file* file, const std::string& xml_filename) const {
POSTFIX_SCHEMA(XmlSerializer)* s = new POSTFIX_SCHEMA(XmlSerializer)(file, xml_filename);
s->setFile(file);
return s;
@@ -57,7 +57,7 @@ std::map<std::string, std::string> POSTFIX_SCHEMA(argument_name_map);
// Format an IFC attribute and maybe returns as string. Only literal scalar
// values are converted. Things like entity instances and lists are omitted.
std::optional<std::string> format_attribute(ifcopenshell::geometry::abstract_mapping* mapping, AttributeValue argument, IfcUtil::ArgumentType argument_type, const std::string& argument_name) {
std::optional<std::string> format_attribute(ifcopenshell::geometry::abstract_mapping* mapping, attribute_value argument, ifcopenshell::argument_type argument_type, const std::string& argument_name) {
std::optional<std::string> value;
// Hard-code lat-lon as it represents an array
@@ -82,28 +82,28 @@ std::optional<std::string> format_attribute(ifcopenshell::geometry::abstract_map
}
switch(argument_type) {
case IfcUtil::Argument_BOOL:
case IfcUtil::Argument_LOGICAL:{
case ifcopenshell::Argument_BOOL:
case ifcopenshell::Argument_LOGICAL:{
const boost::logic::tribool b = argument;
value = b.value == boost::logic::tribool::indeterminate_value ? "unknown" : b ? "true" : "false";
break; }
case IfcUtil::Argument_DOUBLE: {
case ifcopenshell::Argument_DOUBLE: {
const double d = argument;
std::stringstream stream;
stream << std::setprecision (std::numeric_limits< double >::max_digits10) << d;
value = stream.str();
break; }
case IfcUtil::Argument_STRING:
case IfcUtil::Argument_ENUMERATION: {
case ifcopenshell::Argument_STRING:
case ifcopenshell::Argument_ENUMERATION: {
value = static_cast<std::string>(argument);
break; }
case IfcUtil::Argument_INT: {
case ifcopenshell::Argument_INT: {
const int v = argument;
std::stringstream stream;
stream << v;
value = stream.str();
break; }
case IfcUtil::Argument_ENTITY_INSTANCE: {
case ifcopenshell::Argument_ENTITY_INSTANCE: {
express::Base e = argument;
if (e.declaration().as_entity() == nullptr) {
auto f = e.as<express::DeclaredType>();
@@ -155,7 +155,7 @@ ptree* format_entity_instance(ifcopenshell::geometry::abstract_mapping* mapping,
try {
instance.get_attribute_value(i);
} catch (const std::exception&) {
Logger::Error("Expected " + boost::lexical_cast<std::string>(n) + " attributes for:", instance);
logger::error("Expected " + boost::lexical_cast<std::string>(n) + " attributes for:", instance);
break;
}
auto argument = instance.get_attribute_value(i);
@@ -167,14 +167,14 @@ ptree* format_entity_instance(ifcopenshell::geometry::abstract_mapping* mapping,
if (argument_name_it != POSTFIX_SCHEMA(argument_name_map).end()) {
argument_name = argument_name_it->second;
}
const IfcUtil::ArgumentType argument_type = instance.get_attribute_value(i).type();
const ifcopenshell::argument_type argument_type = instance.get_attribute_value(i).type();
const std::string qualified_name = instance.declaration().name() + "." + argument_name;
std::optional<std::string> value;
try {
value = format_attribute(mapping, argument, argument_type, qualified_name);
} catch (const std::exception& e) {
Logger::Error(e);
logger::error(e);
}
if (value) {
@@ -238,8 +238,8 @@ auto get_related(T t, F f, G g) {
}
}
}
} catch (IfcParse::IfcException& e) {
Logger::Error(e);
} catch (ifcopenshell::exception& e) {
logger::error(e);
}
}
return acc;
@@ -545,7 +545,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
auto projects = file->instances_by_type<IfcSchema::IfcProject>();
if (projects.size() != 1) {
Logger::Message(Logger::LOG_ERROR, "Expected a single IfcProject");
logger::message(logger::LOG_ERROR, "Expected a single IfcProject");
return;
}
IfcSchema::IfcProject& project = projects.front();
@@ -556,7 +556,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
try {
return fn();
} catch(const std::exception& e) {
Logger::Error(e);
logger::error(e);
static std::invoke_result_t<decltype(fn)> v;
return v;
}
@@ -578,51 +578,51 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
try {
header.put("file_description.implementation_level", file->header().file_description().implementation_level());
}
catch (const IfcParse::IfcException& ex) {
catch (const ifcopenshell::exception& ex) {
std::stringstream ss;
ss << "Failed to get ifc file header file_description implementation_level, error: '" << ex.what() << "'";
Logger::Message(Logger::LOG_ERROR, ss.str());
logger::message(logger::LOG_ERROR, ss.str());
}
try {
header.put("file_name.name", file->header().file_name().name());
}
catch (const IfcParse::IfcException& ex) {
catch (const ifcopenshell::exception& ex) {
std::stringstream ss;
ss << "Failed to get ifc file header file_name name, error: '" << ex.what() << "'";
Logger::Message(Logger::LOG_ERROR, ss.str());
logger::message(logger::LOG_ERROR, ss.str());
}
try {
header.put("file_name.time_stamp", file->header().file_name().time_stamp());
}
catch (const IfcParse::IfcException& ex) {
catch (const ifcopenshell::exception& ex) {
std::stringstream ss;
ss << "Failed to get ifc file header file_name time_stamp, error: '" << ex.what() << "'";
Logger::Message(Logger::LOG_ERROR, ss.str());
logger::message(logger::LOG_ERROR, ss.str());
}
try {
header.put("file_name.preprocessor_version", file->header().file_name().preprocessor_version());
}
catch (const IfcParse::IfcException& ex) {
catch (const ifcopenshell::exception& ex) {
std::stringstream ss;
ss << "Failed to get ifc file header file_name preprocessor_version, error: '" << ex.what() << "'";
Logger::Message(Logger::LOG_ERROR, ss.str());
logger::message(logger::LOG_ERROR, ss.str());
}
try {
header.put("file_name.originating_system", file->header().file_name().originating_system());
}
catch (const IfcParse::IfcException& ex) {
catch (const ifcopenshell::exception& ex) {
std::stringstream ss;
ss << "Failed to get ifc file header file_name originating_system, error: '" << ex.what() << "'";
Logger::Message(Logger::LOG_ERROR, ss.str());
logger::message(logger::LOG_ERROR, ss.str());
}
try {
// @nb inconsistent spelling
header.put("file_name.authorization", file->header().file_name().authorization());
}
catch (const IfcParse::IfcException& ex) {
catch (const ifcopenshell::exception& ex) {
std::stringstream ss;
ss << "Failed to get ifc file header file_name authorization, error: '" << ex.what() << "'";
Logger::Message(Logger::LOG_ERROR, ss.str());
logger::message(logger::LOG_ERROR, ss.str());
}
// Descend into the decomposition structure of the IFC file.
@@ -756,7 +756,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
if (auto named_unit = unit.as<IfcSchema::IfcNamedUnit>()) {
ptree* node = format_entity_instance(mapping_, named_unit, units);
if (node) {
node->put("<xmlattr>.SI_equivalent", IfcParse::get_SI_equivalent<IfcSchema>(named_unit));
node->put("<xmlattr>.SI_equivalent", ifcopenshell::get_SI_equivalent<IfcSchema>(named_unit));
}
} else if (auto mon_unit = unit.as<IfcSchema::IfcMonetaryUnit>()) {
format_entity_instance(mapping_, mon_unit, units);
@@ -835,6 +835,6 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
boost::property_tree::xml_writer_settings<char> settings('\t', 1);
#endif
std::ofstream f(IfcUtil::path::from_utf8(xml_filename).c_str());
std::ofstream f(ifcopenshell::path::from_utf8(xml_filename).c_str());
boost::property_tree::write_xml(f, root, settings);
}
@@ -32,14 +32,14 @@
class POSTFIX_SCHEMA(XmlSerializer) : public XmlSerializer {
private:
IfcParse::IfcFile* file;
ifcopenshell::file* file;
// @todo
ifcopenshell::geometry::Settings settings_;
ifcopenshell::geometry::abstract_mapping* mapping_;
public:
POSTFIX_SCHEMA(XmlSerializer)(IfcParse::IfcFile* file, const std::string& xml_filename)
POSTFIX_SCHEMA(XmlSerializer)(ifcopenshell::file* file, const std::string& xml_filename)
: XmlSerializer(0, "")
, mapping_(ifcopenshell::geometry::impl::mapping_implementations().construct(file, settings_))
{
@@ -48,7 +48,7 @@ public:
}
void finalize();
void setFile(IfcParse::IfcFile*) {}
void setFile(ifcopenshell::file*) {}
};
#endif