mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-14 11:24:19 +00:00
Pass around non-static logger instances and programmatic access to messages in-memory
This commit is contained in:
@@ -219,8 +219,8 @@ private:
|
||||
std::string unit_name;
|
||||
float unit_magnitude;
|
||||
public:
|
||||
ColladaSerializer(const std::string& dae_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings)
|
||||
: WriteOnlyGeometrySerializer(geometry_settings, settings)
|
||||
ColladaSerializer(const std::string& dae_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings, Logger& logger = Logger::Root())
|
||||
: WriteOnlyGeometrySerializer(geometry_settings, settings, logger)
|
||||
, exporter("IfcOpenShell", dae_filename, this, settings.get<ifcopenshell::geometry::settings::FloatingPointDigits>().get() >= 15)
|
||||
{
|
||||
exporter.serializer = this;
|
||||
|
||||
@@ -53,8 +53,8 @@ static const uint32_t PRIM_TRIANGLE_FAN = 6;
|
||||
static const uint32_t ELEMENT_ARRAY_BUFFER = 34963;
|
||||
static const uint32_t ARRAY_BUFFER = 34962;
|
||||
|
||||
GltfSerializer::GltfSerializer(const std::string& filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings)
|
||||
: WriteOnlyGeometrySerializer(geometry_settings, settings)
|
||||
GltfSerializer::GltfSerializer(const std::string& filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings, Logger& logger)
|
||||
: WriteOnlyGeometrySerializer(geometry_settings, settings, logger)
|
||||
, filename_(filename)
|
||||
, tmp_filename1_(filename + ".indices.tmp")
|
||||
, tmp_filename2_(filename + ".vertices.tmp")
|
||||
@@ -519,7 +519,7 @@ namespace {
|
||||
}
|
||||
|
||||
void proj_log(void *, int, const char* c) {
|
||||
Logger::Error("SER", 1, "PROJ: " + std::string(c));
|
||||
logger_.Error("SER", 1, "PROJ: " + std::string(c));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -650,7 +650,7 @@ void GltfSerializer::setFile(IfcParse::IfcFile* f) {
|
||||
NULL);
|
||||
|
||||
if (!P) {
|
||||
Logger::Error("SER", 2, "Failed to create PROJ transformation object");
|
||||
logger_.Error("SER", 2, "Failed to create PROJ transformation object");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -662,7 +662,7 @@ void GltfSerializer::setFile(IfcParse::IfcFile* f) {
|
||||
|
||||
wgs84_point = proj_trans(P, PJ_FWD, a);
|
||||
|
||||
Logger::Notice("SER", 3, "Calculated latitude: " + std::to_string(wgs84_point.lp.lam) + " longitude: " + std::to_string(wgs84_point.lp.phi));
|
||||
logger_.Notice("SER", 3, "Calculated latitude: " + std::to_string(wgs84_point.lp.lam) + " longitude: " + std::to_string(wgs84_point.lp.phi));
|
||||
}
|
||||
|
||||
std::swap(wgs84_point.lp.phi, wgs84_point.lp.lam);
|
||||
@@ -687,7 +687,7 @@ void GltfSerializer::setFile(IfcParse::IfcFile* f) {
|
||||
PJ *ellipsoid_crs = proj_create(C, ellipsoid_def);
|
||||
|
||||
if (!ellipsoid_crs) {
|
||||
Logger::Error("SER", 4, "Failed to create ellipsoid CRS");
|
||||
logger_.Error("SER", 4, "Failed to create ellipsoid CRS");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ private:
|
||||
|
||||
int writeMaterial(const ifcopenshell::geometry::taxonomy::style::ptr style);
|
||||
public:
|
||||
GltfSerializer(const std::string& filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings);
|
||||
GltfSerializer(const std::string& filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings, Logger& logger = Logger::Root());
|
||||
virtual ~GltfSerializer();
|
||||
bool ready();
|
||||
void writeHeader();
|
||||
|
||||
@@ -55,8 +55,8 @@ herr_t print_stack(hid_t /*estack*/, void*) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
HdfSerializer::HdfSerializer(const std::string& hdf_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings, bool read_only)
|
||||
: GeometrySerializer(geometry_settings, settings)
|
||||
HdfSerializer::HdfSerializer(const std::string& hdf_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings, bool read_only, Logger& logger)
|
||||
: GeometrySerializer(geometry_settings, settings, logger)
|
||||
, hdf_filename(hdf_filename)
|
||||
, settings_(settings)
|
||||
{
|
||||
@@ -726,4 +726,4 @@ const H5std_string HdfSerializer::DATASET_NAME_PLACEMENT = "placement";
|
||||
const H5std_string HdfSerializer::GROUP_NAME_MESH = "mesh";
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -96,7 +96,7 @@ private:
|
||||
void write_style(surface_style_serialization& data, const ifcopenshell::geometry::taxonomy::style::ptr& s);
|
||||
|
||||
public:
|
||||
HdfSerializer(const std::string& hdf_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings, bool read_only=false);
|
||||
HdfSerializer(const std::string& hdf_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings, bool read_only=false, Logger& logger = Logger::Root());
|
||||
virtual ~HdfSerializer() {}
|
||||
bool ready();
|
||||
void writeHeader();
|
||||
|
||||
@@ -40,8 +40,8 @@ private:
|
||||
public:
|
||||
/// @note IGESControl_Controller::Init() must be called prior to instantiating IgesSerializer.
|
||||
/// See http://tracker.dev.opencascade.org/view.php?id=23679 for more information.
|
||||
IgesSerializer(const std::string& out_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings)
|
||||
: OpenCascadeBasedSerializer(out_filename, geometry_settings, settings)
|
||||
IgesSerializer(const std::string& out_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings, Logger& logger = Logger::Root())
|
||||
: OpenCascadeBasedSerializer(out_filename, geometry_settings, settings, logger)
|
||||
{}
|
||||
virtual ~IgesSerializer() {}
|
||||
void writeShape(const std::string&, const TopoDS_Shape& shape) {
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
const char* symbol = getSymbolForUnitMagnitude(magnitude);
|
||||
if (symbol) {
|
||||
#ifdef HAVE_CONFIG_H
|
||||
Logger::Warning("SER", 5, "Setting IGES units not supported on OCE");
|
||||
logger_.Warning("SER", 5, "Setting IGES units not supported on OCE");
|
||||
#else
|
||||
Interface_Static::SetCVal("xstep.cascade.unit", symbol);
|
||||
Interface_Static::SetCVal("write.iges.unit", symbol);
|
||||
|
||||
@@ -42,18 +42,19 @@ void JsonSerializerFactory::Factory::bind(const std::string& schema_name, fn f)
|
||||
this->insert(std::make_pair(schema_name_lower, f));
|
||||
}
|
||||
|
||||
JsonSerializer* JsonSerializerFactory::Factory::construct(const std::string& schema_name, IfcParse::IfcFile* file, std::string json_filename, JsonSerializer::Dialect dialect) {
|
||||
JsonSerializer* JsonSerializerFactory::Factory::construct(const std::string& schema_name, IfcParse::IfcFile* file, std::string json_filename, JsonSerializer::Dialect dialect, Logger& logger) {
|
||||
const std::string schema_name_lower = boost::to_lower_copy(schema_name);
|
||||
auto it = this->find(schema_name_lower);
|
||||
if (it == this->end()) {
|
||||
throw IfcParse::IfcException("No Json serializer registered for " + schema_name);
|
||||
}
|
||||
return it->second(file, json_filename, dialect);
|
||||
return it->second(file, json_filename, dialect, logger);
|
||||
}
|
||||
|
||||
JsonSerializer::JsonSerializer(IfcParse::IfcFile* file, const std::string& json_filename, JsonSerializer::Dialect dialect) {
|
||||
JsonSerializer::JsonSerializer(IfcParse::IfcFile* file, const std::string& json_filename, JsonSerializer::Dialect dialect, Logger& logger)
|
||||
: Serializer(logger) {
|
||||
if (file) {
|
||||
implementation_ = JsonSerializerFactory::implementations().construct(file->schema()->name(), file, json_filename, dialect);
|
||||
implementation_ = JsonSerializerFactory::implementations().construct(file->schema()->name(), file, json_filename, dialect, logger_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class SERIALIZERS_API JsonSerializer : public Serializer {
|
||||
Dialect dialect_;
|
||||
|
||||
public:
|
||||
JsonSerializer(IfcParse::IfcFile* file, const std::string& json_filename, Dialect dialect = Dialect::JSON_DIALECT_CREOOX);
|
||||
JsonSerializer(IfcParse::IfcFile* file, const std::string& json_filename, Dialect dialect = Dialect::JSON_DIALECT_CREOOX, Logger& logger = Logger::Root());
|
||||
|
||||
virtual ~JsonSerializer() {}
|
||||
|
||||
@@ -35,13 +35,13 @@ class SERIALIZERS_API JsonSerializer : public Serializer {
|
||||
};
|
||||
|
||||
struct SERIALIZERS_API JsonSerializerFactory {
|
||||
typedef boost::function3<JsonSerializer*, IfcParse::IfcFile*, std::string, JsonSerializer::Dialect> fn;
|
||||
typedef boost::function4<JsonSerializer*, IfcParse::IfcFile*, std::string, JsonSerializer::Dialect, Logger&> fn;
|
||||
|
||||
class Factory : public std::map<std::string, fn> {
|
||||
public:
|
||||
Factory();
|
||||
void bind(const std::string& schema_name, fn);
|
||||
JsonSerializer* construct(const std::string& schema_name, IfcParse::IfcFile*, std::string, JsonSerializer::Dialect);
|
||||
JsonSerializer* construct(const std::string& schema_name, IfcParse::IfcFile*, std::string, JsonSerializer::Dialect, Logger& logger = Logger::Root());
|
||||
};
|
||||
|
||||
static Factory& implementations();
|
||||
|
||||
@@ -36,8 +36,8 @@ protected:
|
||||
const std::string out_filename;
|
||||
const char* getSymbolForUnitMagnitude(float mag);
|
||||
public:
|
||||
explicit OpenCascadeBasedSerializer(const std::string& out_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings)
|
||||
: WriteOnlyGeometrySerializer(geometry_settings, settings)
|
||||
explicit OpenCascadeBasedSerializer(const std::string& out_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings, Logger& logger = Logger::Root())
|
||||
: WriteOnlyGeometrySerializer(geometry_settings, settings, logger)
|
||||
, out_filename(out_filename)
|
||||
{}
|
||||
virtual ~OpenCascadeBasedSerializer() {}
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
|
||||
#include "../ifcparse/IfcLogger.h"
|
||||
|
||||
RocksDbSerializer::RocksDbSerializer(IfcParse::IfcFile* file, const std::string& rocksdb_filename)
|
||||
: file_(file)
|
||||
RocksDbSerializer::RocksDbSerializer(IfcParse::IfcFile* file, const std::string& rocksdb_filename, Logger& logger)
|
||||
: Serializer(logger)
|
||||
, file_(file)
|
||||
, rocksdb_filename_(rocksdb_filename)
|
||||
{
|
||||
/*rocksdb::Options options;
|
||||
@@ -26,8 +27,9 @@ RocksDbSerializer::RocksDbSerializer(IfcParse::IfcFile* file, const std::string&
|
||||
output_file_->calculate_unit_factors = false;
|
||||
}
|
||||
|
||||
RocksDbSerializer::RocksDbSerializer(const std::string& input_filename, const std::string& rocksdb_filename, bool stream)
|
||||
: file_(input_filename)
|
||||
RocksDbSerializer::RocksDbSerializer(const std::string& input_filename, const std::string& rocksdb_filename, bool stream, Logger& logger)
|
||||
: Serializer(logger)
|
||||
, file_(input_filename)
|
||||
, rocksdb_filename_(rocksdb_filename)
|
||||
{
|
||||
}
|
||||
@@ -378,4 +380,4 @@ void RocksDbSerializer::finalize() {
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -18,8 +18,8 @@ private:
|
||||
void write_streaming_();
|
||||
void write_non_streaming_();
|
||||
public:
|
||||
RocksDbSerializer(IfcParse::IfcFile* file, const std::string& rocksdb_filename);
|
||||
RocksDbSerializer(const std::string& input_filename, const std::string& rocksdb_filename, bool stream);
|
||||
RocksDbSerializer(IfcParse::IfcFile* file, const std::string& rocksdb_filename, Logger& logger = Logger::Root());
|
||||
RocksDbSerializer(const std::string& input_filename, const std::string& rocksdb_filename, bool stream, Logger& logger = Logger::Root());
|
||||
|
||||
virtual ~RocksDbSerializer() {}
|
||||
|
||||
@@ -31,4 +31,4 @@ public:
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -34,8 +34,8 @@ class StepSerializer : public OpenCascadeBasedSerializer
|
||||
private:
|
||||
STEPControl_Writer writer;
|
||||
public:
|
||||
explicit StepSerializer(const std::string& out_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& serializer_settings)
|
||||
: OpenCascadeBasedSerializer(out_filename, geometry_settings, serializer_settings)
|
||||
explicit StepSerializer(const std::string& out_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& serializer_settings, Logger& logger = Logger::Root())
|
||||
: OpenCascadeBasedSerializer(out_filename, geometry_settings, serializer_settings, logger)
|
||||
{}
|
||||
virtual ~StepSerializer() {}
|
||||
void writeShape(const std::string& name, const TopoDS_Shape& shape) {
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -368,10 +368,13 @@ namespace {
|
||||
std::multimap<double, face_info> large_ortho_faces_;
|
||||
std::list<std::pair<const IfcUtil::IfcBaseEntity*, TopoDS_Shape>> items_;
|
||||
|
||||
Logger& logger_;
|
||||
|
||||
public:
|
||||
|
||||
prefiltered_hlr(bool use_prefiltering, bool use_hlr_poly, bool segment_projection, const gp_Pln& view_direction)
|
||||
: use_prefiltering_(use_prefiltering)
|
||||
prefiltered_hlr(Logger& logger, bool use_prefiltering, bool use_hlr_poly, bool segment_projection, const gp_Pln& view_direction)
|
||||
: logger_(logger)
|
||||
, use_prefiltering_(use_prefiltering)
|
||||
, use_hlr_poly_(use_hlr_poly)
|
||||
, segment_projection_(segment_projection)
|
||||
// @nb negative z in accordance with occt projector convention (and opengl)
|
||||
@@ -468,7 +471,7 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
Logger::Notice("SER", 34, "Included " + std::to_string(n_faces_included) + " faces out of " + std::to_string(n_total) + " after prefiltering");
|
||||
logger_.Notice("SER", 34, "Included " + std::to_string(n_faces_included) + " faces out of " + std::to_string(n_total) + " after prefiltering");
|
||||
|
||||
auto it = items_.insert(items_.end(), { product, C });
|
||||
|
||||
@@ -517,7 +520,7 @@ namespace {
|
||||
}
|
||||
}
|
||||
if (use_prefiltering_) {
|
||||
Logger::Notice("SER", 35, "Included " + std::to_string(n_included) + " elements out of " + std::to_string(items_.size()) + " after prefiltering");
|
||||
logger_.Notice("SER", 35, "Included " + std::to_string(n_included) + " elements out of " + std::to_string(items_.size()) + " after prefiltering");
|
||||
}
|
||||
|
||||
hlr_calc vis(projector_);
|
||||
@@ -593,8 +596,8 @@ protected:
|
||||
subtract_before_project subtraction_settings_;
|
||||
|
||||
public:
|
||||
SvgSerializer(const stream_or_filename& out_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings)
|
||||
: WriteOnlyGeometrySerializer(geometry_settings, settings)
|
||||
SvgSerializer(const stream_or_filename& out_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings, Logger& logger = Logger::Root())
|
||||
: WriteOnlyGeometrySerializer(geometry_settings, settings, logger)
|
||||
, svg_file(out_filename)
|
||||
, xmin(+std::numeric_limits<double>::infinity())
|
||||
, ymin(+std::numeric_limits<double>::infinity())
|
||||
|
||||
@@ -225,8 +225,8 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
TtlWktSerializer::TtlWktSerializer(const stream_or_filename& filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings)
|
||||
: WriteOnlyGeometrySerializer(geometry_settings, settings)
|
||||
TtlWktSerializer::TtlWktSerializer(const stream_or_filename& filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings, Logger& logger)
|
||||
: WriteOnlyGeometrySerializer(geometry_settings, settings, logger)
|
||||
, filename_(filename)
|
||||
{
|
||||
const auto& tri_setting = geometry_settings.get<ifcopenshell::geometry::settings::TriangulationType>().get();
|
||||
@@ -473,11 +473,11 @@ void TtlWktSerializer::write(const IfcGeom::BRepElement* brep_obj) {
|
||||
if ((polygons_by_area.rbegin()->first > (0.6 * rectangle_area)) || (height < (1. + 1.e-5))) {
|
||||
// Found sufficiently large polygon
|
||||
if (emitted_warning) {
|
||||
Logger::Warning("SER", 36, "Found larger polygon area (" + std::to_string(polygons_by_area.rbegin()->first) + ").");
|
||||
logger_.Warning("SER", 36, "Found larger polygon area (" + std::to_string(polygons_by_area.rbegin()->first) + ").");
|
||||
}
|
||||
break;
|
||||
} else if (!emitted_warning) {
|
||||
Logger::Warning("SER", 37, "Section polygon area is small compared to bounding box area (" + std::to_string(polygons_by_area.rbegin()->first) + " < " + std::to_string(0.6 * rectangle_area) + "). Trying again with different section height.");
|
||||
logger_.Warning("SER", 37, "Section polygon area is small compared to bounding box area (" + std::to_string(polygons_by_area.rbegin()->first) + " < " + std::to_string(0.6 * rectangle_area) + "). Trying again with different section height.");
|
||||
emitted_warning = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class SERIALIZERS_API TtlWktSerializer : public WriteOnlyGeometrySerializer {
|
||||
private:
|
||||
stream_or_filename filename_;
|
||||
public:
|
||||
TtlWktSerializer(const stream_or_filename& filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings);
|
||||
TtlWktSerializer(const stream_or_filename& filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings, Logger& logger = Logger::Root());
|
||||
virtual ~TtlWktSerializer() {}
|
||||
bool ready();
|
||||
void writeHeader();
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
USDSerializer::USDSerializer(const std::string& out_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings):
|
||||
WriteOnlyGeometrySerializer(geometry_settings, settings),
|
||||
USDSerializer::USDSerializer(const std::string& out_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings, Logger& logger):
|
||||
WriteOnlyGeometrySerializer(geometry_settings, settings, logger),
|
||||
filename_(out_filename)
|
||||
{
|
||||
std::size_t found = filename_.find_last_of("/\\");
|
||||
|
||||
@@ -86,7 +86,7 @@ private:
|
||||
std::set<std::string> emitted_names_;
|
||||
std::map<int, std::string> element_names_;
|
||||
public:
|
||||
USDSerializer(const std::string&, const ifcopenshell::geometry::Settings&, const ifcopenshell::geometry::SerializerSettings&);
|
||||
USDSerializer(const std::string&, const ifcopenshell::geometry::Settings&, const ifcopenshell::geometry::SerializerSettings&, Logger& logger = Logger::Root());
|
||||
virtual ~USDSerializer();
|
||||
bool ready() { return ready_; }
|
||||
void writeHeader();
|
||||
@@ -101,4 +101,4 @@ public:
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <iomanip>
|
||||
|
||||
WaveFrontOBJSerializer::WaveFrontOBJSerializer(const stream_or_filename& obj_filename, const stream_or_filename& mtl_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings)
|
||||
: WriteOnlyGeometrySerializer(geometry_settings, settings)
|
||||
WaveFrontOBJSerializer::WaveFrontOBJSerializer(const stream_or_filename& obj_filename, const stream_or_filename& mtl_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings, Logger& logger)
|
||||
: WriteOnlyGeometrySerializer(geometry_settings, settings, logger)
|
||||
, obj_stream(obj_filename)
|
||||
, mtl_stream(mtl_filename)
|
||||
, vcount_total(1)
|
||||
|
||||
@@ -35,7 +35,7 @@ private:
|
||||
size_t vcount_total, ncount_total;
|
||||
std::set<std::string> materials;
|
||||
public:
|
||||
WaveFrontOBJSerializer(const stream_or_filename& obj_filename, const stream_or_filename& mtl_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings);
|
||||
WaveFrontOBJSerializer(const stream_or_filename& obj_filename, const stream_or_filename& mtl_filename, const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings, Logger& logger = Logger::Root());
|
||||
virtual ~WaveFrontOBJSerializer() {}
|
||||
bool ready();
|
||||
void writeHeader();
|
||||
|
||||
@@ -21,19 +21,20 @@ void XmlSerializerFactory::Factory::bind(const std::string& schema_name, fn f) {
|
||||
this->insert(std::make_pair(schema_name_lower, f));
|
||||
}
|
||||
|
||||
XmlSerializer* XmlSerializerFactory::Factory::construct(const std::string& schema_name, IfcParse::IfcFile* file, std::string xml_filename) {
|
||||
XmlSerializer* XmlSerializerFactory::Factory::construct(const std::string& schema_name, IfcParse::IfcFile* file, std::string xml_filename, Logger& logger) {
|
||||
const std::string schema_name_lower = boost::to_lower_copy(schema_name);
|
||||
typename std::map<std::string, fn>::const_iterator it;
|
||||
it = this->find(schema_name_lower);
|
||||
if (it == this->end()) {
|
||||
throw IfcParse::IfcException("No XML serializer registered for " + schema_name);
|
||||
}
|
||||
return it->second(file, xml_filename);
|
||||
return it->second(file, xml_filename, logger);
|
||||
}
|
||||
|
||||
XmlSerializer::XmlSerializer(IfcParse::IfcFile* file, const std::string& xml_filename) {
|
||||
XmlSerializer::XmlSerializer(IfcParse::IfcFile* file, const std::string& xml_filename, Logger& logger)
|
||||
: Serializer(logger) {
|
||||
if (file) {
|
||||
implementation_ = XmlSerializerFactory::implementations().construct(file->schema()->name(), file, xml_filename);
|
||||
implementation_ = XmlSerializerFactory::implementations().construct(file->schema()->name(), file, xml_filename, logger_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ protected:
|
||||
std::string xml_filename;
|
||||
|
||||
public:
|
||||
XmlSerializer(IfcParse::IfcFile* file, const std::string& xml_filename);
|
||||
XmlSerializer(IfcParse::IfcFile* file, const std::string& xml_filename, Logger& logger = Logger::Root());
|
||||
|
||||
virtual ~XmlSerializer() {}
|
||||
|
||||
@@ -28,13 +28,13 @@ public:
|
||||
};
|
||||
|
||||
struct SERIALIZERS_API XmlSerializerFactory {
|
||||
typedef boost::function2<XmlSerializer*, IfcParse::IfcFile*, std::string> fn;
|
||||
typedef boost::function3<XmlSerializer*, IfcParse::IfcFile*, std::string, Logger&> fn;
|
||||
|
||||
class Factory : public std::map<std::string, fn> {
|
||||
public:
|
||||
Factory();
|
||||
void bind(const std::string& schema_name, fn);
|
||||
XmlSerializer* construct(const std::string& schema_name, IfcParse::IfcFile*, std::string);
|
||||
XmlSerializer* construct(const std::string& schema_name, IfcParse::IfcFile*, std::string, Logger& logger = Logger::Root());
|
||||
};
|
||||
|
||||
static Factory& implementations();
|
||||
|
||||
@@ -34,8 +34,8 @@ using json = nlohmann::json;
|
||||
|
||||
namespace {
|
||||
struct POSTFIX_SCHEMA(factory_t) {
|
||||
JsonSerializer* operator()(IfcParse::IfcFile* file, const std::string& json_filename, JsonSerializer::Dialect dialect) const {
|
||||
POSTFIX_SCHEMA(JsonSerializer)* s = new POSTFIX_SCHEMA(JsonSerializer)(file, json_filename, dialect);
|
||||
JsonSerializer* operator()(IfcParse::IfcFile* file, const std::string& json_filename, JsonSerializer::Dialect dialect, Logger& logger) const {
|
||||
POSTFIX_SCHEMA(JsonSerializer)* s = new POSTFIX_SCHEMA(JsonSerializer)(file, json_filename, dialect, logger);
|
||||
s->setFile(file);
|
||||
return s;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ class get_type_visitor : public boost::static_visitor<std::string> {
|
||||
// Returns related entity instances using IFC's objectified relationship
|
||||
// model. The second and third argument require a member function pointer.
|
||||
template <typename T, typename U, typename V, typename F, typename G>
|
||||
auto get_related(T* t, F f, G g) {
|
||||
auto get_related(Logger& logger, T* t, F f, G g) {
|
||||
typename U::list::ptr li = (*t.*f)()->template as<U>();
|
||||
typename aggregate_of<V>::ptr acc(new aggregate_of<V>);
|
||||
for (typename U::list::it it = li->begin(); it != li->end(); ++it) {
|
||||
@@ -89,13 +89,13 @@ auto get_related(T* t, F f, G g) {
|
||||
try {
|
||||
acc->push((*u.*g)()->template as<V>());
|
||||
} catch (IfcParse::IfcException& e) {
|
||||
Logger::Error("SER", 6, e);
|
||||
logger.Error("SER", 6, e);
|
||||
}
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
|
||||
void format_entity_instance(IfcUtil::IfcBaseEntity* instance, json& tree, IfcUtil::IfcBaseEntity* parent = nullptr) {
|
||||
void format_entity_instance(IfcUtil::IfcBaseEntity* instance, json& tree, Logger& logger, IfcUtil::IfcBaseEntity* parent = nullptr) {
|
||||
/*
|
||||
{
|
||||
"id" : string, // Element GUID (IFC GloballyUniqueId)
|
||||
@@ -149,7 +149,7 @@ void format_entity_instance(IfcUtil::IfcBaseEntity* instance, json& tree, IfcUti
|
||||
}
|
||||
|
||||
if (auto* obj = instance->as<IfcSchema::IfcObject>()) {
|
||||
IfcSchema::IfcPropertySetDefinition::list::ptr property_sets = get_related<IfcSchema::IfcObject, IfcSchema::IfcRelDefinesByProperties, IfcSchema::IfcPropertySetDefinition>(obj, &IfcSchema::IfcObject::IsDefinedBy, &IfcSchema::IfcRelDefinesByProperties::RelatingPropertyDefinition);
|
||||
IfcSchema::IfcPropertySetDefinition::list::ptr property_sets = get_related<IfcSchema::IfcObject, IfcSchema::IfcRelDefinesByProperties, IfcSchema::IfcPropertySetDefinition>(logger, obj, &IfcSchema::IfcObject::IsDefinedBy, &IfcSchema::IfcRelDefinesByProperties::RelatingPropertyDefinition);
|
||||
if (!property_sets && property_sets->size()) {
|
||||
child["propertySetIds"] = json::array();
|
||||
for (IfcSchema::IfcPropertySetDefinition::list::it it = property_sets->begin(); it != property_sets->end(); ++it) {
|
||||
@@ -166,11 +166,11 @@ void format_entity_instance(IfcUtil::IfcBaseEntity* instance, json& tree, IfcUti
|
||||
// A function to be called recursively. Template specialization is used
|
||||
// to descend into decomposition, containment and property relationships.
|
||||
template <typename A>
|
||||
void descend(A* instance, json& tree, IfcUtil::IfcBaseEntity* parent = nullptr) {
|
||||
void descend(A* instance, json& tree, Logger& logger, IfcUtil::IfcBaseEntity* parent = nullptr) {
|
||||
if (instance->declaration().is(IfcSchema::IfcObjectDefinition::Class())) {
|
||||
descend(instance->template as<IfcSchema::IfcObjectDefinition>(), tree, parent);
|
||||
descend(instance->template as<IfcSchema::IfcObjectDefinition>(), tree, logger, parent);
|
||||
} else {
|
||||
format_entity_instance(instance, tree);
|
||||
format_entity_instance(instance, tree, logger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ void descend(A* instance, json& tree, IfcUtil::IfcBaseEntity* parent = nullptr)
|
||||
// Descends into the tree by recursing into IfcRelContainedInSpatialStructure,
|
||||
// IfcRelDecomposes, IfcRelDefinesByType, IfcRelDefinesByProperties relations.
|
||||
template <>
|
||||
void descend(IfcSchema::IfcObjectDefinition* product, json& tree, IfcUtil::IfcBaseEntity* parent) {
|
||||
void descend(IfcSchema::IfcObjectDefinition* product, json& tree, Logger& logger, IfcUtil::IfcBaseEntity* parent) {
|
||||
if (product->declaration().is(IfcSchema::IfcElement::Class())) {
|
||||
auto voids = product->as<IfcSchema::IfcElement>()->FillsVoids();
|
||||
if (voids && voids->size() == 1 && (*voids->begin())->RelatingOpeningElement() != parent) {
|
||||
@@ -188,49 +188,49 @@ void descend(IfcSchema::IfcObjectDefinition* product, json& tree, IfcUtil::IfcBa
|
||||
}
|
||||
}
|
||||
|
||||
format_entity_instance(product, tree, parent);
|
||||
format_entity_instance(product, tree, logger, parent);
|
||||
|
||||
if (product->declaration().is(IfcSchema::IfcOpeningElement::Class())) {
|
||||
IfcSchema::IfcOpeningElement* opening = product->as<IfcSchema::IfcOpeningElement>();
|
||||
IfcSchema::IfcElement::list::ptr fills = get_related<IfcSchema::IfcOpeningElement, IfcSchema::IfcRelFillsElement, IfcSchema::IfcElement>(
|
||||
opening, &IfcSchema::IfcOpeningElement::HasFillings, &IfcSchema::IfcRelFillsElement::RelatedBuildingElement);
|
||||
logger, opening, &IfcSchema::IfcOpeningElement::HasFillings, &IfcSchema::IfcRelFillsElement::RelatedBuildingElement);
|
||||
|
||||
for (IfcSchema::IfcElement::list::it it = fills->begin(); it != fills->end(); ++it) {
|
||||
descend(*it, tree, product);
|
||||
descend(*it, tree, logger, product);
|
||||
}
|
||||
}
|
||||
|
||||
if (product->declaration().is(IfcSchema::IfcSpatialStructureElement::Class())) {
|
||||
IfcSchema::IfcSpatialStructureElement* structure = product->as<IfcSchema::IfcSpatialStructureElement>();
|
||||
|
||||
IfcSchema::IfcObjectDefinition::list::ptr elements = get_related<IfcSchema::IfcSpatialStructureElement, IfcSchema::IfcRelContainedInSpatialStructure, IfcSchema::IfcObjectDefinition>(structure, &IfcSchema::IfcSpatialStructureElement::ContainsElements, &IfcSchema::IfcRelContainedInSpatialStructure::RelatedElements);
|
||||
IfcSchema::IfcObjectDefinition::list::ptr elements = get_related<IfcSchema::IfcSpatialStructureElement, IfcSchema::IfcRelContainedInSpatialStructure, IfcSchema::IfcObjectDefinition>(logger, structure, &IfcSchema::IfcSpatialStructureElement::ContainsElements, &IfcSchema::IfcRelContainedInSpatialStructure::RelatedElements);
|
||||
|
||||
for (IfcSchema::IfcObjectDefinition::list::it it = elements->begin(); it != elements->end(); ++it) {
|
||||
descend(*it, tree, product);
|
||||
descend(*it, tree, logger, product);
|
||||
}
|
||||
}
|
||||
|
||||
if (product->declaration().is(IfcSchema::IfcElement::Class())) {
|
||||
IfcSchema::IfcElement* element = static_cast<IfcSchema::IfcElement*>(product);
|
||||
IfcSchema::IfcOpeningElement::list::ptr openings = get_related<IfcSchema::IfcElement, IfcSchema::IfcRelVoidsElement, IfcSchema::IfcOpeningElement>(
|
||||
element, &IfcSchema::IfcElement::HasOpenings, &IfcSchema::IfcRelVoidsElement::RelatedOpeningElement);
|
||||
logger, element, &IfcSchema::IfcElement::HasOpenings, &IfcSchema::IfcRelVoidsElement::RelatedOpeningElement);
|
||||
|
||||
for (IfcSchema::IfcOpeningElement::list::it it = openings->begin(); it != openings->end(); ++it) {
|
||||
descend(*it, tree, product);
|
||||
descend(*it, tree, logger, product);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SCHEMA_IfcRelDecomposes_HAS_RelatedObjects
|
||||
IfcSchema::IfcObjectDefinition::list::ptr structures = get_related<IfcSchema::IfcObjectDefinition, IfcSchema::IfcRelDecomposes, IfcSchema::IfcObjectDefinition>(product, &IfcSchema::IfcObjectDefinition::IsDecomposedBy, &IfcSchema::IfcRelDecomposes::RelatedObjects);
|
||||
IfcSchema::IfcObjectDefinition::list::ptr structures = get_related<IfcSchema::IfcObjectDefinition, IfcSchema::IfcRelDecomposes, IfcSchema::IfcObjectDefinition>(logger, product, &IfcSchema::IfcObjectDefinition::IsDecomposedBy, &IfcSchema::IfcRelDecomposes::RelatedObjects);
|
||||
#else
|
||||
IfcSchema::IfcObjectDefinition::list::ptr structures = get_related<IfcSchema::IfcObjectDefinition, IfcSchema::IfcRelAggregates, IfcSchema::IfcObjectDefinition>(product, &IfcSchema::IfcObjectDefinition::IsDecomposedBy, &IfcSchema::IfcRelAggregates::RelatedObjects);
|
||||
IfcSchema::IfcObjectDefinition::list::ptr structures = get_related<IfcSchema::IfcObjectDefinition, IfcSchema::IfcRelAggregates, IfcSchema::IfcObjectDefinition>(logger, product, &IfcSchema::IfcObjectDefinition::IsDecomposedBy, &IfcSchema::IfcRelAggregates::RelatedObjects);
|
||||
|
||||
structures->push(get_related<IfcSchema::IfcObjectDefinition, IfcSchema::IfcRelNests, IfcSchema::IfcObjectDefinition>(product, &IfcSchema::IfcObjectDefinition::IsNestedBy, &IfcSchema::IfcRelNests::RelatedObjects));
|
||||
structures->push(get_related<IfcSchema::IfcObjectDefinition, IfcSchema::IfcRelNests, IfcSchema::IfcObjectDefinition>(logger, product, &IfcSchema::IfcObjectDefinition::IsNestedBy, &IfcSchema::IfcRelNests::RelatedObjects));
|
||||
#endif
|
||||
|
||||
for (IfcSchema::IfcObjectDefinition::list::it it = structures->begin(); it != structures->end(); ++it) {
|
||||
IfcSchema::IfcObjectDefinition* ob = *it;
|
||||
descend(ob, tree, product);
|
||||
descend(ob, tree, logger, product);
|
||||
}
|
||||
|
||||
// psets are handled as part of format_entity_instance()
|
||||
@@ -264,7 +264,7 @@ void POSTFIX_SCHEMA(JsonSerializer)::finalize() {
|
||||
|
||||
IfcSchema::IfcProject::list::ptr projects = file->instances_by_type<IfcSchema::IfcProject>();
|
||||
if (projects->size() != 1) {
|
||||
Logger::Message(Logger::LOG_ERROR, "SER", 7, "Expected a single IfcProject");
|
||||
logger_.Message(Logger::LOG_ERROR, "SER", 7, "Expected a single IfcProject");
|
||||
return;
|
||||
}
|
||||
IfcSchema::IfcProject* project = *projects->begin();
|
||||
@@ -273,7 +273,7 @@ void POSTFIX_SCHEMA(JsonSerializer)::finalize() {
|
||||
try {
|
||||
return fn();
|
||||
} catch (const std::exception& e) {
|
||||
Logger::Error("SER", 8, e);
|
||||
logger_.Error("SER", 8, e);
|
||||
static std::invoke_result_t<decltype(fn)> v;
|
||||
return v;
|
||||
}
|
||||
@@ -563,7 +563,7 @@ void POSTFIX_SCHEMA(JsonSerializer)::finalize() {
|
||||
}
|
||||
*/
|
||||
|
||||
descend(project, output["metaObjects"]);
|
||||
descend(project, output["metaObjects"], logger_);
|
||||
|
||||
std::ofstream f(IfcUtil::path::from_utf8(json_filename).c_str());
|
||||
f << output.dump(4);
|
||||
@@ -859,4 +859,4 @@ void POSTFIX_SCHEMA(JsonSerializer)::finalize() {
|
||||
boost::property_tree::write_xml(f, root, settings);
|
||||
*/
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -41,8 +41,8 @@ class POSTFIX_SCHEMA(JsonSerializer) : public JsonSerializer {
|
||||
ifcopenshell::geometry::abstract_mapping* mapping_;
|
||||
|
||||
public:
|
||||
POSTFIX_SCHEMA(JsonSerializer)(IfcParse::IfcFile* file, const std::string& json_filename, JsonSerializer::Dialect dialect)
|
||||
: JsonSerializer(0, "", dialect), mapping_(ifcopenshell::geometry::impl::mapping_implementations().construct(file, settings_))
|
||||
POSTFIX_SCHEMA(JsonSerializer)(IfcParse::IfcFile* file, const std::string& json_filename, JsonSerializer::Dialect dialect, Logger& logger = Logger::Root())
|
||||
: JsonSerializer(0, "", dialect, logger), mapping_(ifcopenshell::geometry::impl::mapping_implementations().construct(file, settings_, logger))
|
||||
{
|
||||
this->file = file;
|
||||
this->json_filename = json_filename;
|
||||
|
||||
@@ -36,8 +36,8 @@ using boost::property_tree::ptree;
|
||||
|
||||
namespace {
|
||||
struct POSTFIX_SCHEMA(factory_t) {
|
||||
XmlSerializer* operator()(IfcParse::IfcFile* file, const std::string& xml_filename) const {
|
||||
POSTFIX_SCHEMA(XmlSerializer)* s = new POSTFIX_SCHEMA(XmlSerializer)(file, xml_filename);
|
||||
XmlSerializer* operator()(IfcParse::IfcFile* file, const std::string& xml_filename, Logger& logger) const {
|
||||
POSTFIX_SCHEMA(XmlSerializer)* s = new POSTFIX_SCHEMA(XmlSerializer)(file, xml_filename, logger);
|
||||
s->setFile(file);
|
||||
return s;
|
||||
}
|
||||
@@ -151,13 +151,13 @@ boost::optional<std::string> format_attribute(ifcopenshell::geometry::abstract_m
|
||||
}
|
||||
|
||||
// Appends to a node with possibly existing attributes
|
||||
ptree* format_entity_instance(ifcopenshell::geometry::abstract_mapping* mapping, IfcUtil::IfcBaseEntity* instance, ptree& child, ptree& tree, bool as_link = false) {
|
||||
ptree* format_entity_instance(Logger& logger, ifcopenshell::geometry::abstract_mapping* mapping, IfcUtil::IfcBaseEntity* instance, ptree& child, ptree& tree, bool as_link = false) {
|
||||
const unsigned n = instance->declaration().as_entity()->attribute_count();
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
try {
|
||||
instance->get_attribute_value(i);
|
||||
} catch (const std::exception&) {
|
||||
Logger::Error("SER", 9, "Expected " + boost::lexical_cast<std::string>(n) + " attributes for:", instance);
|
||||
logger.Error("SER", 9, "Expected " + boost::lexical_cast<std::string>(n) + " attributes for:", instance);
|
||||
break;
|
||||
}
|
||||
auto argument = instance->get_attribute_value(i);
|
||||
@@ -176,7 +176,7 @@ ptree* format_entity_instance(ifcopenshell::geometry::abstract_mapping* mapping,
|
||||
try {
|
||||
value = format_attribute(mapping, argument, argument_type, qualified_name);
|
||||
} catch (const std::exception& e) {
|
||||
Logger::Error("SER", 10, e);
|
||||
logger.Error("SER", 10, e);
|
||||
}
|
||||
|
||||
if (value) {
|
||||
@@ -196,9 +196,9 @@ ptree* format_entity_instance(ifcopenshell::geometry::abstract_mapping* mapping,
|
||||
|
||||
// Formats an entity instances as a ptree node, and insert into the DOM. Recurses
|
||||
// over the entity attributes and writes them as xml attributes of the node.
|
||||
ptree* format_entity_instance(ifcopenshell::geometry::abstract_mapping* mapping, IfcUtil::IfcBaseEntity* instance, ptree& tree, bool as_link = false) {
|
||||
ptree* format_entity_instance(Logger& logger, ifcopenshell::geometry::abstract_mapping* mapping, IfcUtil::IfcBaseEntity* instance, ptree& tree, bool as_link = false) {
|
||||
ptree child;
|
||||
return format_entity_instance(mapping, instance, child, tree, as_link);
|
||||
return format_entity_instance(logger, mapping, instance, child, tree, as_link);
|
||||
}
|
||||
|
||||
std::string qualify_unrooted_instance(IfcUtil::IfcBaseInterface* inst) {
|
||||
@@ -208,18 +208,18 @@ std::string qualify_unrooted_instance(IfcUtil::IfcBaseInterface* inst) {
|
||||
// A function to be called recursively. Template specialization is used
|
||||
// to descend into decomposition, containment and property relationships.
|
||||
template <typename A>
|
||||
ptree* descend(ifcopenshell::geometry::abstract_mapping* mapping, A* instance, ptree& tree, IfcUtil::IfcBaseClass* parent=nullptr) {
|
||||
ptree* descend(Logger& logger, ifcopenshell::geometry::abstract_mapping* mapping, A* instance, ptree& tree, IfcUtil::IfcBaseClass* parent=nullptr) {
|
||||
if (instance->declaration().is(IfcSchema::IfcObjectDefinition::Class())) {
|
||||
return descend(mapping, instance->template as<IfcSchema::IfcObjectDefinition>(), tree, parent);
|
||||
return descend(logger, mapping, instance->template as<IfcSchema::IfcObjectDefinition>(), tree, parent);
|
||||
} else {
|
||||
return format_entity_instance(mapping, instance, tree);
|
||||
return format_entity_instance(logger, mapping, instance, tree);
|
||||
}
|
||||
}
|
||||
|
||||
// Returns related entity instances using IFC's objectified relationship
|
||||
// model. The second and third argument require a member function pointer.
|
||||
template <typename T, typename U, typename V, typename F, typename G>
|
||||
auto get_related(T* t, F f, G g) {
|
||||
auto get_related(Logger& logger, T* t, F f, G g) {
|
||||
typename U::list::ptr li = (*t.*f)()->template as<U>();
|
||||
typename aggregate_of<V>::ptr acc(new aggregate_of<V>);
|
||||
for (typename U::list::it it = li->begin(); it != li->end(); ++it) {
|
||||
@@ -227,7 +227,7 @@ auto get_related(T* t, F f, G g) {
|
||||
try {
|
||||
acc->push((*u.*g)()->template as<V>());
|
||||
} catch (IfcParse::IfcException& e) {
|
||||
Logger::Error("SER", 11, e);
|
||||
logger.Error("SER", 11, e);
|
||||
}
|
||||
}
|
||||
return acc;
|
||||
@@ -236,7 +236,7 @@ auto get_related(T* t, F f, G g) {
|
||||
// Descends into the tree by recursing into IfcRelContainedInSpatialStructure,
|
||||
// IfcRelDecomposes, IfcRelDefinesByType, IfcRelDefinesByProperties relations.
|
||||
template <>
|
||||
ptree* descend(ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::IfcObjectDefinition* product, ptree& tree, IfcUtil::IfcBaseClass* parent) {
|
||||
ptree* descend(Logger& logger, ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::IfcObjectDefinition* product, ptree& tree, IfcUtil::IfcBaseClass* parent) {
|
||||
if (product->declaration().is(IfcSchema::IfcElement::Class())) {
|
||||
auto voids = product->as<IfcSchema::IfcElement>()->FillsVoids();
|
||||
if (voids && voids->size() == 1 && (*voids->begin())->RelatingOpeningElement() != parent) {
|
||||
@@ -245,15 +245,15 @@ ptree* descend(ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::Ifc
|
||||
}
|
||||
}
|
||||
|
||||
ptree& child = *format_entity_instance(mapping, product, tree);
|
||||
ptree& child = *format_entity_instance(logger, mapping, product, tree);
|
||||
|
||||
if (product->declaration().is(IfcSchema::IfcOpeningElement::Class())) {
|
||||
IfcSchema::IfcOpeningElement* opening = product->as<IfcSchema::IfcOpeningElement>();
|
||||
IfcSchema::IfcElement::list::ptr fills = get_related<IfcSchema::IfcOpeningElement, IfcSchema::IfcRelFillsElement, IfcSchema::IfcElement>(
|
||||
opening, &IfcSchema::IfcOpeningElement::HasFillings, &IfcSchema::IfcRelFillsElement::RelatedBuildingElement);
|
||||
logger, opening, &IfcSchema::IfcOpeningElement::HasFillings, &IfcSchema::IfcRelFillsElement::RelatedBuildingElement);
|
||||
|
||||
for (IfcSchema::IfcElement::list::it it = fills->begin(); it != fills->end(); ++it) {
|
||||
descend(mapping, *it, child, product);
|
||||
descend(logger, mapping, *it, child, product);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,40 +262,40 @@ ptree* descend(ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::Ifc
|
||||
|
||||
IfcSchema::IfcObjectDefinition::list::ptr elements = get_related
|
||||
<IfcSchema::IfcSpatialStructureElement, IfcSchema::IfcRelContainedInSpatialStructure, IfcSchema::IfcObjectDefinition>
|
||||
(structure, &IfcSchema::IfcSpatialStructureElement::ContainsElements, &IfcSchema::IfcRelContainedInSpatialStructure::RelatedElements);
|
||||
(logger, structure, &IfcSchema::IfcSpatialStructureElement::ContainsElements, &IfcSchema::IfcRelContainedInSpatialStructure::RelatedElements);
|
||||
|
||||
for (IfcSchema::IfcObjectDefinition::list::it it = elements->begin(); it != elements->end(); ++it) {
|
||||
descend(mapping, *it, child, product);
|
||||
descend(logger, mapping, *it, child, product);
|
||||
}
|
||||
}
|
||||
|
||||
if (product->declaration().is(IfcSchema::IfcElement::Class())) {
|
||||
IfcSchema::IfcElement* element = static_cast<IfcSchema::IfcElement*>(product);
|
||||
IfcSchema::IfcOpeningElement::list::ptr openings = get_related<IfcSchema::IfcElement, IfcSchema::IfcRelVoidsElement, IfcSchema::IfcOpeningElement>(
|
||||
element, &IfcSchema::IfcElement::HasOpenings, &IfcSchema::IfcRelVoidsElement::RelatedOpeningElement);
|
||||
logger, element, &IfcSchema::IfcElement::HasOpenings, &IfcSchema::IfcRelVoidsElement::RelatedOpeningElement);
|
||||
|
||||
for (IfcSchema::IfcOpeningElement::list::it it = openings->begin(); it != openings->end(); ++it) {
|
||||
descend(mapping, *it, child, product);
|
||||
descend(logger, mapping, *it, child, product);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SCHEMA_IfcRelDecomposes_HAS_RelatedObjects
|
||||
IfcSchema::IfcObjectDefinition::list::ptr structures = get_related
|
||||
<IfcSchema::IfcObjectDefinition, IfcSchema::IfcRelDecomposes, IfcSchema::IfcObjectDefinition>
|
||||
(product, &IfcSchema::IfcObjectDefinition::IsDecomposedBy, &IfcSchema::IfcRelDecomposes::RelatedObjects);
|
||||
(logger, product, &IfcSchema::IfcObjectDefinition::IsDecomposedBy, &IfcSchema::IfcRelDecomposes::RelatedObjects);
|
||||
#else
|
||||
IfcSchema::IfcObjectDefinition::list::ptr structures = get_related
|
||||
<IfcSchema::IfcObjectDefinition, IfcSchema::IfcRelAggregates, IfcSchema::IfcObjectDefinition>
|
||||
(product, &IfcSchema::IfcObjectDefinition::IsDecomposedBy, &IfcSchema::IfcRelAggregates::RelatedObjects);
|
||||
(logger, product, &IfcSchema::IfcObjectDefinition::IsDecomposedBy, &IfcSchema::IfcRelAggregates::RelatedObjects);
|
||||
|
||||
structures->push(get_related
|
||||
<IfcSchema::IfcObjectDefinition, IfcSchema::IfcRelNests, IfcSchema::IfcObjectDefinition>
|
||||
(product, &IfcSchema::IfcObjectDefinition::IsNestedBy, &IfcSchema::IfcRelNests::RelatedObjects));
|
||||
(logger, product, &IfcSchema::IfcObjectDefinition::IsNestedBy, &IfcSchema::IfcRelNests::RelatedObjects));
|
||||
#endif
|
||||
|
||||
for (IfcSchema::IfcObjectDefinition::list::it it = structures->begin(); it != structures->end(); ++it) {
|
||||
IfcSchema::IfcObjectDefinition* ob = *it;
|
||||
descend(mapping, ob, child, product);
|
||||
descend(logger, mapping, ob, child, product);
|
||||
}
|
||||
|
||||
if (product->declaration().is(IfcSchema::IfcObject::Class())) {
|
||||
@@ -303,12 +303,12 @@ ptree* descend(ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::Ifc
|
||||
|
||||
IfcSchema::IfcPropertySetDefinition::list::ptr property_sets = get_related
|
||||
<IfcSchema::IfcObject, IfcSchema::IfcRelDefinesByProperties, IfcSchema::IfcPropertySetDefinition>
|
||||
(object, &IfcSchema::IfcObject::IsDefinedBy, &IfcSchema::IfcRelDefinesByProperties::RelatingPropertyDefinition);
|
||||
(logger, object, &IfcSchema::IfcObject::IsDefinedBy, &IfcSchema::IfcRelDefinesByProperties::RelatingPropertyDefinition);
|
||||
|
||||
#ifdef SCHEMAS_HAS_IfcPropertySetDefinitionSet
|
||||
aggregate_of<IfcSchema::IfcPropertySetDefinitionSet>::ptr property_set_sets = get_related
|
||||
<IfcSchema::IfcObject, IfcSchema::IfcRelDefinesByProperties, IfcSchema::IfcPropertySetDefinitionSet>
|
||||
(object, &IfcSchema::IfcObject::IsDefinedBy, &IfcSchema::IfcRelDefinesByProperties::RelatingPropertyDefinition);
|
||||
(logger, object, &IfcSchema::IfcObject::IsDefinedBy, &IfcSchema::IfcRelDefinesByProperties::RelatingPropertyDefinition);
|
||||
|
||||
for (auto& s : *property_set_sets) {
|
||||
property_sets->push((decltype(property_sets))*s);
|
||||
@@ -318,25 +318,25 @@ ptree* descend(ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::Ifc
|
||||
for (IfcSchema::IfcPropertySetDefinition::list::it it = property_sets->begin(); it != property_sets->end(); ++it) {
|
||||
IfcSchema::IfcPropertySetDefinition* pset = *it;
|
||||
if (pset->declaration().is(IfcSchema::IfcPropertySet::Class())) {
|
||||
format_entity_instance(mapping, pset, child, true);
|
||||
format_entity_instance(logger, mapping, pset, child, true);
|
||||
} else if (pset->declaration().is(IfcSchema::IfcElementQuantity::Class())) {
|
||||
format_entity_instance(mapping, pset, child, true);
|
||||
format_entity_instance(logger, mapping, pset, child, true);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SCHEMA_IfcObject_HAS_IsTypedBy
|
||||
IfcSchema::IfcTypeObject::list::ptr types = get_related
|
||||
<IfcSchema::IfcObject, IfcSchema::IfcRelDefinesByType, IfcSchema::IfcTypeObject>
|
||||
(object, &IfcSchema::IfcObject::IsTypedBy, &IfcSchema::IfcRelDefinesByType::RelatingType);
|
||||
(logger, object, &IfcSchema::IfcObject::IsTypedBy, &IfcSchema::IfcRelDefinesByType::RelatingType);
|
||||
#else
|
||||
IfcSchema::IfcTypeObject::list::ptr types = get_related
|
||||
<IfcSchema::IfcObject, IfcSchema::IfcRelDefinesByType, IfcSchema::IfcTypeObject>
|
||||
(object, &IfcSchema::IfcObject::IsDefinedBy, &IfcSchema::IfcRelDefinesByType::RelatingType);
|
||||
(logger, object, &IfcSchema::IfcObject::IsDefinedBy, &IfcSchema::IfcRelDefinesByType::RelatingType);
|
||||
#endif
|
||||
|
||||
for (IfcSchema::IfcTypeObject::list::it it = types->begin(); it != types->end(); ++it) {
|
||||
IfcSchema::IfcTypeObject* type = *it;
|
||||
format_entity_instance(mapping, type, child, true);
|
||||
format_entity_instance(logger, mapping, type, child, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,7 +348,7 @@ ptree* descend(ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::Ifc
|
||||
// for the format_entity_instance() call.
|
||||
ptree node;
|
||||
node.put("<xmlattr>.xlink:href", "#" + it->first);
|
||||
format_entity_instance(mapping, it->second, node, child, true);
|
||||
format_entity_instance(logger, mapping, it->second, node, child, true);
|
||||
}
|
||||
|
||||
IfcSchema::IfcRelAssociates::list::ptr associations = product->HasAssociations();
|
||||
@@ -357,7 +357,7 @@ ptree* descend(ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::Ifc
|
||||
IfcSchema::IfcMaterialSelect* mat = (*it)->as<IfcSchema::IfcRelAssociatesMaterial>()->RelatingMaterial();
|
||||
ptree node;
|
||||
node.put("<xmlattr>.xlink:href", "#" + qualify_unrooted_instance(mat));
|
||||
format_entity_instance(mapping, mat->as<IfcUtil::IfcBaseEntity>(), node, child, true);
|
||||
format_entity_instance(logger, mapping, mat->as<IfcUtil::IfcBaseEntity>(), node, child, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -365,7 +365,7 @@ ptree* descend(ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::Ifc
|
||||
#if defined(SCHEMA_HAS_IfcAlignmentSegment) && defined(SCHEMA_IfcAlignmentSegment_HAS_DesignParameters)
|
||||
if (auto* als = product->as<IfcSchema::IfcAlignmentSegment>()) {
|
||||
ptree node;
|
||||
format_entity_instance(mapping, als->DesignParameters(), node, child, false);
|
||||
format_entity_instance(logger, mapping, als->DesignParameters(), node, child, false);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -373,19 +373,19 @@ ptree* descend(ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::Ifc
|
||||
}
|
||||
|
||||
// Format IfcProperty instances and insert into the DOM. IfcComplexProperties are flattened out.
|
||||
void format_properties(ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::IfcProperty::list::ptr properties, ptree& node) {
|
||||
void format_properties(Logger& logger, ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::IfcProperty::list::ptr properties, ptree& node) {
|
||||
for (IfcSchema::IfcProperty::list::it it = properties->begin(); it != properties->end(); ++it) {
|
||||
IfcSchema::IfcProperty* p = *it;
|
||||
if (p->declaration().is(IfcSchema::IfcComplexProperty::Class())) {
|
||||
IfcSchema::IfcComplexProperty* complex = p->as<IfcSchema::IfcComplexProperty>();
|
||||
format_properties(mapping, complex->HasProperties(), node);
|
||||
format_properties(logger, mapping, complex->HasProperties(), node);
|
||||
} else {
|
||||
format_entity_instance(mapping, p, node);
|
||||
format_entity_instance(logger, mapping, p, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void writeGroupToNode(ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::IfcGroup* group, ptree& node, std::set<std::string>notRootGroups) {
|
||||
void writeGroupToNode(Logger& logger, ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::IfcGroup* group, ptree& node, std::set<std::string>notRootGroups) {
|
||||
// @todo tfk: instead of a set<string> shouldn't we just have a set<IfcGroup>, the current approach
|
||||
// might not work with non-unique or NIL group names.
|
||||
|
||||
@@ -398,7 +398,7 @@ void writeGroupToNode(ifcopenshell::geometry::abstract_mapping* mapping, IfcSche
|
||||
return;
|
||||
}
|
||||
// Write one group to root
|
||||
ptree* node2 = descend(mapping, group, node);
|
||||
ptree* node2 = descend(logger, mapping, group, node);
|
||||
auto father = group->IsGroupedBy();
|
||||
for (auto iter = father->begin(); iter != father->end(); iter++)
|
||||
{
|
||||
@@ -407,39 +407,39 @@ void writeGroupToNode(ifcopenshell::geometry::abstract_mapping* mapping, IfcSche
|
||||
for (auto objit = objs->begin(); objit != objs->end(); objit++) {
|
||||
auto entity = *objit;
|
||||
if (entity->declaration().is(IfcSchema::IfcGroup::Class()) && entity->Name()) {
|
||||
writeGroupToNode(mapping, entity->as<IfcSchema::IfcGroup>(), *node2, notRootGroups);
|
||||
writeGroupToNode(logger, mapping, entity->as<IfcSchema::IfcGroup>(), *node2, notRootGroups);
|
||||
notRootGroups.emplace(*entity->Name());
|
||||
}
|
||||
else {
|
||||
// Write child to father group
|
||||
descend(mapping, entity, *node2);
|
||||
descend(logger, mapping, entity, *node2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Format IfcElementQuantity instances and insert into the DOM.
|
||||
void format_quantities(ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::IfcPhysicalQuantity::list::ptr quantities, ptree& node) {
|
||||
void format_quantities(Logger& logger, ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::IfcPhysicalQuantity::list::ptr quantities, ptree& node) {
|
||||
for (IfcSchema::IfcPhysicalQuantity::list::it it = quantities->begin(); it != quantities->end(); ++it) {
|
||||
IfcSchema::IfcPhysicalQuantity* p = *it;
|
||||
ptree* node2 = format_entity_instance(mapping, p, node);
|
||||
ptree* node2 = format_entity_instance(logger, mapping, p, node);
|
||||
if (node2 && p->declaration().is(IfcSchema::IfcPhysicalComplexQuantity::Class())) {
|
||||
IfcSchema::IfcPhysicalComplexQuantity* complex = p->as<IfcSchema::IfcPhysicalComplexQuantity>();
|
||||
format_quantities(mapping, complex->HasQuantities(), *node2);
|
||||
format_quantities(logger, mapping, complex->HasQuantities(), *node2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Format IfcTask instances and insert into the DOM.
|
||||
void format_tasks(ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::IfcTask* task, ptree& node) {
|
||||
ptree* ntask = format_entity_instance(mapping, task, node);
|
||||
void format_tasks(Logger& logger, ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::IfcTask* task, ptree& node) {
|
||||
ptree* ntask = format_entity_instance(logger, mapping, task, node);
|
||||
|
||||
if (ntask) {
|
||||
#ifdef SCHEMA_IfcTask_HAS_TaskTime
|
||||
IfcSchema::IfcTaskTime* task_time = task->TaskTime();
|
||||
if (task_time)
|
||||
{
|
||||
format_entity_instance(mapping, task_time, *ntask);
|
||||
format_entity_instance(logger, mapping, task_time, *ntask);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -467,15 +467,15 @@ void format_tasks(ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::
|
||||
|
||||
IfcSchema::IfcPropertySetDefinition::list::ptr property_sets = get_related
|
||||
<IfcSchema::IfcObject, IfcSchema::IfcRelDefinesByProperties, IfcSchema::IfcPropertySetDefinition>
|
||||
(task, &IfcSchema::IfcObject::IsDefinedBy, &IfcSchema::IfcRelDefinesByProperties::RelatingPropertyDefinition);
|
||||
(logger, task, &IfcSchema::IfcObject::IsDefinedBy, &IfcSchema::IfcRelDefinesByProperties::RelatingPropertyDefinition);
|
||||
|
||||
for (IfcSchema::IfcPropertySetDefinition::list::it it = property_sets->begin(); it != property_sets->end(); ++it) {
|
||||
IfcSchema::IfcPropertySetDefinition* pset = *it;
|
||||
if (pset->declaration().is(IfcSchema::IfcPropertySet::Class())) {
|
||||
format_entity_instance(mapping, pset, *ntask, true);
|
||||
format_entity_instance(logger, mapping, pset, *ntask, true);
|
||||
}
|
||||
else if (pset->declaration().is(IfcSchema::IfcElementQuantity::Class())) {
|
||||
format_entity_instance(mapping, pset, *ntask, true);
|
||||
format_entity_instance(logger, mapping, pset, *ntask, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -538,7 +538,7 @@ void format_tasks(ifcopenshell::geometry::abstract_mapping* mapping, IfcSchema::
|
||||
continue;
|
||||
}
|
||||
IfcSchema::IfcTask* task2 = (*it2)->as<IfcSchema::IfcTask>();
|
||||
format_tasks(mapping, task2, *ntask);
|
||||
format_tasks(logger, mapping, task2, *ntask);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -552,7 +552,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
|
||||
IfcSchema::IfcProject::list::ptr projects = file->instances_by_type<IfcSchema::IfcProject>();
|
||||
if (projects->size() != 1) {
|
||||
Logger::Message(Logger::LOG_ERROR, "SER", 12, "Expected a single IfcProject");
|
||||
logger_.Message(Logger::LOG_ERROR, "SER", 12, "Expected a single IfcProject");
|
||||
return;
|
||||
}
|
||||
IfcSchema::IfcProject* project = *projects->begin();
|
||||
@@ -563,7 +563,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
try {
|
||||
return fn();
|
||||
} catch(const std::exception& e) {
|
||||
Logger::Error("SER", 13, e);
|
||||
logger_.Error("SER", 13, e);
|
||||
static std::invoke_result_t<decltype(fn)> v;
|
||||
return v;
|
||||
}
|
||||
@@ -588,7 +588,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
catch (const IfcParse::IfcException& ex) {
|
||||
std::stringstream ss;
|
||||
ss << "Failed to get ifc file header file_description implementation_level, error: '" << ex.what() << "'";
|
||||
Logger::Message(Logger::LOG_ERROR, "SER", 14, ss.str());
|
||||
logger_.Message(Logger::LOG_ERROR, "SER", 14, ss.str());
|
||||
}
|
||||
try {
|
||||
header.put("file_name.name", file->header().file_name()->name());
|
||||
@@ -596,7 +596,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
catch (const IfcParse::IfcException& ex) {
|
||||
std::stringstream ss;
|
||||
ss << "Failed to get ifc file header file_name name, error: '" << ex.what() << "'";
|
||||
Logger::Message(Logger::LOG_ERROR, "SER", 15, ss.str());
|
||||
logger_.Message(Logger::LOG_ERROR, "SER", 15, ss.str());
|
||||
}
|
||||
try {
|
||||
header.put("file_name.time_stamp", file->header().file_name()->time_stamp());
|
||||
@@ -604,7 +604,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
catch (const IfcParse::IfcException& ex) {
|
||||
std::stringstream ss;
|
||||
ss << "Failed to get ifc file header file_name time_stamp, error: '" << ex.what() << "'";
|
||||
Logger::Message(Logger::LOG_ERROR, "SER", 16, ss.str());
|
||||
logger_.Message(Logger::LOG_ERROR, "SER", 16, ss.str());
|
||||
}
|
||||
try {
|
||||
header.put("file_name.preprocessor_version", file->header().file_name()->preprocessor_version());
|
||||
@@ -612,7 +612,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
catch (const IfcParse::IfcException& ex) {
|
||||
std::stringstream ss;
|
||||
ss << "Failed to get ifc file header file_name preprocessor_version, error: '" << ex.what() << "'";
|
||||
Logger::Message(Logger::LOG_ERROR, "SER", 17, ss.str());
|
||||
logger_.Message(Logger::LOG_ERROR, "SER", 17, ss.str());
|
||||
}
|
||||
try {
|
||||
header.put("file_name.originating_system", file->header().file_name()->originating_system());
|
||||
@@ -620,7 +620,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
catch (const IfcParse::IfcException& ex) {
|
||||
std::stringstream ss;
|
||||
ss << "Failed to get ifc file header file_name originating_system, error: '" << ex.what() << "'";
|
||||
Logger::Message(Logger::LOG_ERROR, "SER", 18, ss.str());
|
||||
logger_.Message(Logger::LOG_ERROR, "SER", 18, ss.str());
|
||||
}
|
||||
try {
|
||||
// @nb inconsistent spelling
|
||||
@@ -629,19 +629,19 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
catch (const IfcParse::IfcException& ex) {
|
||||
std::stringstream ss;
|
||||
ss << "Failed to get ifc file header file_name authorization, error: '" << ex.what() << "'";
|
||||
Logger::Message(Logger::LOG_ERROR, "SER", 19, ss.str());
|
||||
}
|
||||
logger_.Message(Logger::LOG_ERROR, "SER", 19, ss.str());
|
||||
}
|
||||
|
||||
// Descend into the decomposition structure of the IFC file.
|
||||
descend(mapping_, project, decomposition);
|
||||
descend(logger_, mapping_, project, decomposition);
|
||||
|
||||
// Write all property sets and values as XML nodes.
|
||||
IfcSchema::IfcPropertySet::list::ptr psets = file->instances_by_type<IfcSchema::IfcPropertySet>();
|
||||
for (IfcSchema::IfcPropertySet::list::it it = psets->begin(); it != psets->end(); ++it) {
|
||||
IfcSchema::IfcPropertySet* pset = *it;
|
||||
ptree* node = format_entity_instance(mapping_, pset, properties);
|
||||
ptree* node = format_entity_instance(logger_, mapping_, pset, properties);
|
||||
if (node) {
|
||||
format_properties(mapping_, pset->HasProperties(), *node);
|
||||
format_properties(logger_, mapping_, pset->HasProperties(), *node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -649,7 +649,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
IfcSchema::IfcGroup::list::ptr gsets = file->instances_by_type<IfcSchema::IfcGroup>();
|
||||
std::set<std::string> notRootGroups; //selfname, fathername
|
||||
for (IfcSchema::IfcGroup::list::it it = gsets->begin(); it != gsets->end(); ++it) {
|
||||
writeGroupToNode(mapping_, *it, groups, notRootGroups);
|
||||
writeGroupToNode(logger_, mapping_, *it, groups, notRootGroups);
|
||||
}
|
||||
for (auto it = groups.begin(); it != groups.end();) {
|
||||
if (notRootGroups.find(it->second.get<std::string>("<xmlattr>.Name")) != notRootGroups.end()) {
|
||||
@@ -663,9 +663,9 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
IfcSchema::IfcElementQuantity::list::ptr qtosets = file->instances_by_type<IfcSchema::IfcElementQuantity>();
|
||||
for (IfcSchema::IfcElementQuantity::list::it it = qtosets->begin(); it != qtosets->end(); ++it) {
|
||||
IfcSchema::IfcElementQuantity* qto = *it;
|
||||
ptree* node = format_entity_instance(mapping_, qto, quantities);
|
||||
ptree* node = format_entity_instance(logger_, mapping_, qto, quantities);
|
||||
if (node) {
|
||||
format_quantities(mapping_, qto->Quantities(), *node);
|
||||
format_quantities(logger_, mapping_, qto->Quantities(), *node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -673,8 +673,8 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
ptree pwork_schedules;
|
||||
IfcSchema::IfcWorkSchedule::list::ptr pschedules = file->instances_by_type<IfcSchema::IfcWorkSchedule>();
|
||||
for (IfcSchema::IfcWorkSchedule::list::it it = pschedules->begin(); it != pschedules->end(); ++it) {
|
||||
IfcSchema::IfcWorkSchedule* schedule = *it;
|
||||
ptree* nschedule = format_entity_instance(mapping_, schedule, pwork_schedules);
|
||||
IfcSchema::IfcWorkSchedule* schedule = *it;
|
||||
ptree* nschedule = format_entity_instance(logger_, mapping_, schedule, pwork_schedules);
|
||||
|
||||
if(nschedule) {
|
||||
IfcSchema::IfcRelAssignsToControl::list::ptr controls = schedule->Controls();
|
||||
@@ -687,7 +687,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
|
||||
if (object && object->declaration().is(IfcSchema::IfcTask::Class())) {
|
||||
IfcSchema::IfcTask* task = object->as<IfcSchema::IfcTask>();
|
||||
format_tasks(mapping_, task, *nschedule);
|
||||
format_tasks(logger_, mapping_, task, *nschedule);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -700,7 +700,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
IfcSchema::IfcWorkPlan::list::ptr pplans = file->instances_by_type<IfcSchema::IfcWorkPlan>();
|
||||
for (IfcSchema::IfcWorkPlan::list::it it = pplans->begin(); it != pplans->end(); ++it) {
|
||||
IfcSchema::IfcWorkPlan* plan = *it;
|
||||
ptree* nschedule = format_entity_instance(mapping_, plan, pwork_plans);
|
||||
ptree* nschedule = format_entity_instance(logger_, mapping_, plan, pwork_plans);
|
||||
|
||||
if (nschedule) {
|
||||
#ifdef SCHEMA_IfcObjectDefinition_HAS_IsDecomposedBy
|
||||
@@ -725,8 +725,8 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
#ifdef SCHEMA_HAS_IfcWorkCalendar
|
||||
IfcSchema::IfcWorkCalendar::list::ptr pcalendars = file->instances_by_type<IfcSchema::IfcWorkCalendar>();
|
||||
for (IfcSchema::IfcWorkCalendar::list::it it = pcalendars->begin(); it != pcalendars->end(); ++it) {
|
||||
IfcSchema::IfcWorkCalendar* calendar = *it;
|
||||
ptree* ncalendar = format_entity_instance(mapping_, calendar, calendars);
|
||||
IfcSchema::IfcWorkCalendar* calendar = *it;
|
||||
ptree* ncalendar = format_entity_instance(logger_, mapping_, calendar, calendars);
|
||||
|
||||
if (ncalendar) {
|
||||
IfcSchema::IfcWorkTime::list::ptr working_times = calendar->WorkingTimes().value_or(nullptr);
|
||||
@@ -734,7 +734,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
for (IfcSchema::IfcWorkTime::list::it it2 = working_times->begin(); it2 != working_times->end(); ++it2)
|
||||
{
|
||||
IfcSchema::IfcWorkTime* working_time = *it2;
|
||||
format_entity_instance(mapping_, working_time, *ncalendar);
|
||||
format_entity_instance(logger_, mapping_, working_time, *ncalendar);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -745,13 +745,13 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
for (IfcSchema::IfcRelConnectsElements::list::it it = pconnections->begin(); it != pconnections->end(); ++it) {
|
||||
IfcSchema::IfcRelConnectsElements* connection = *it;
|
||||
|
||||
ptree* nconnection = format_entity_instance(mapping_, connection, connections);
|
||||
ptree* nconnection = format_entity_instance(logger_, mapping_, connection, connections);
|
||||
|
||||
ptree nrelatedElement;
|
||||
ptree nrelatingElement;
|
||||
|
||||
format_entity_instance(mapping_,connection->RelatedElement(), nrelatedElement, true);
|
||||
format_entity_instance(mapping_,connection->RelatingElement(), nrelatingElement, true);
|
||||
format_entity_instance(logger_, mapping_, connection->RelatedElement(), nrelatedElement, true);
|
||||
format_entity_instance(logger_, mapping_, connection->RelatingElement(), nrelatingElement, true);
|
||||
|
||||
nconnection->add_child("RelatedElement", nrelatedElement);
|
||||
nconnection->add_child("RelatingElement", nrelatingElement);
|
||||
@@ -761,14 +761,14 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
IfcSchema::IfcTypeObject::list::ptr type_objects = file->instances_by_type<IfcSchema::IfcTypeObject>();
|
||||
for (IfcSchema::IfcTypeObject::list::it it = type_objects->begin(); it != type_objects->end(); ++it) {
|
||||
IfcSchema::IfcTypeObject* type_object = *it;
|
||||
ptree* node = descend(mapping_, type_object, types);
|
||||
ptree* node = descend(logger_, mapping_, type_object, types);
|
||||
|
||||
if (node && type_object->HasPropertySets()) {
|
||||
IfcSchema::IfcPropertySetDefinition::list::ptr property_sets = *type_object->HasPropertySets();
|
||||
for (IfcSchema::IfcPropertySetDefinition::list::it jt = property_sets->begin(); jt != property_sets->end(); ++jt) {
|
||||
IfcSchema::IfcPropertySetDefinition* pset = *jt;
|
||||
if (pset->declaration().is(IfcSchema::IfcPropertySet::Class())) {
|
||||
format_entity_instance(mapping_, pset, *node, true);
|
||||
format_entity_instance(logger_, mapping_, pset, *node, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -779,12 +779,12 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
for (auto it = unit_assignments->begin(); it != unit_assignments->end(); ++it) {
|
||||
if ((*it)->declaration().is(IfcSchema::IfcNamedUnit::Class())) {
|
||||
IfcSchema::IfcNamedUnit* named_unit = (*it)->as<IfcSchema::IfcNamedUnit>();
|
||||
ptree* node = format_entity_instance(mapping_, named_unit, units);
|
||||
ptree* node = format_entity_instance(logger_, mapping_, named_unit, units);
|
||||
if (node) {
|
||||
node->put("<xmlattr>.SI_equivalent", IfcParse::get_SI_equivalent<IfcSchema>(named_unit));
|
||||
}
|
||||
} else if ((*it)->declaration().is(IfcSchema::IfcMonetaryUnit::Class())) {
|
||||
format_entity_instance(mapping_, (*it)->as<IfcSchema::IfcMonetaryUnit>(), units);
|
||||
format_entity_instance(logger_, mapping_, (*it)->as<IfcSchema::IfcMonetaryUnit>(), units);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -799,7 +799,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
layer_names.insert(name);
|
||||
ptree node;
|
||||
node.put("<xmlattr>.id", name);
|
||||
format_entity_instance(mapping_, *it, node, layers);
|
||||
format_entity_instance(logger_, mapping_, *it, node, layers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -825,16 +825,16 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
|
||||
if ((*jt)->Material()) {
|
||||
subnode.put("<xmlattr>.Name", (*jt)->Material()->Name());
|
||||
}
|
||||
format_entity_instance(mapping_, *jt, subnode, node);
|
||||
format_entity_instance(logger_, mapping_, *jt, subnode, node);
|
||||
}
|
||||
} else if (mat->as<IfcSchema::IfcMaterialList>()) {
|
||||
IfcSchema::IfcMaterial::list::ptr mats = mat->as<IfcSchema::IfcMaterialList>()->Materials();
|
||||
for (IfcSchema::IfcMaterial::list::it jt = mats->begin(); jt != mats->end(); ++jt) {
|
||||
ptree subnode;
|
||||
format_entity_instance(mapping_, *jt, subnode, node);
|
||||
format_entity_instance(logger_, mapping_, *jt, subnode, node);
|
||||
}
|
||||
}
|
||||
format_entity_instance(mapping_, mat->as<IfcUtil::IfcBaseEntity>(), node, materials);
|
||||
format_entity_instance(logger_, mapping_, mat->as<IfcUtil::IfcBaseEntity>(), node, materials);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,9 +39,9 @@ private:
|
||||
ifcopenshell::geometry::abstract_mapping* mapping_;
|
||||
|
||||
public:
|
||||
POSTFIX_SCHEMA(XmlSerializer)(IfcParse::IfcFile* file, const std::string& xml_filename)
|
||||
: XmlSerializer(0, "")
|
||||
, mapping_(ifcopenshell::geometry::impl::mapping_implementations().construct(file, settings_))
|
||||
POSTFIX_SCHEMA(XmlSerializer)(IfcParse::IfcFile* file, const std::string& xml_filename, Logger& logger = Logger::Root())
|
||||
: XmlSerializer(0, "", logger)
|
||||
, mapping_(ifcopenshell::geometry::impl::mapping_implementations().construct(file, settings_, logger))
|
||||
{
|
||||
this->file = file;
|
||||
this->xml_filename = xml_filename;
|
||||
@@ -51,4 +51,4 @@ public:
|
||||
void setFile(IfcParse::IfcFile*) {}
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user