Drastic settings refactoring

This commit is contained in:
Thomas Krijnen
2023-11-15 10:32:20 +01:00
parent d2a2e0d7a0
commit 65e874c67f
80 changed files with 1057 additions and 723 deletions
+75 -44
View File
@@ -23,45 +23,69 @@
#include "../ifcgeom/Serializer.h"
#include "../ifcgeom/IfcGeomElement.h"
class SerializerSettings : public IfcGeom::IteratorSettings
{
public:
enum Setting : uint64_t
{
/// Use entity names instead of unique IDs for naming elements.
/// Applicable for OBJ, DAE, and SVG output.
USE_ELEMENT_NAMES = 1U << (IfcGeom::IteratorSettings::NUM_SETTINGS + 1U),
/// Use entity GUIDs instead of unique IDs for naming elements.
/// Applicable for OBJ, DAE, and SVG output.
USE_ELEMENT_GUIDS = 1U << (IfcGeom::IteratorSettings::NUM_SETTINGS + 2U),
/// Use material names instead of unique IDs for naming materials.
/// Applicable for OBJ and DAE output.
USE_MATERIAL_NAMES = 1U << (IfcGeom::IteratorSettings::NUM_SETTINGS + 3U),
/// Use element types instead of unique IDs for naming elements.
/// Applicable for DAE output.
USE_ELEMENT_TYPES = 1U << (IfcGeom::IteratorSettings::NUM_SETTINGS + 4U),
/// Order the elements using their IfcBuildingStorey parent
/// Applicable for DAE output
USE_ELEMENT_HIERARCHY = 1U << (IfcGeom::IteratorSettings::NUM_SETTINGS + 5U),
/// Use step ids for naming elements.
/// Applicable for OBJ, DAE, and SVG output.
USE_ELEMENT_STEPIDS = 1U << (IfcGeom::IteratorSettings::NUM_SETTINGS + 6U),
/// Use Y UP .
/// Applicable for OBJ output.
USE_Y_UP = 1ULL << (IfcGeom::IteratorSettings::NUM_SETTINGS + 7ULL),
/// Number of different setting flags.
NUM_SETTINGS = 7
};
namespace ifcopenshell {
namespace geometry {
inline namespace settings {
SerializerSettings()
: precision(DEFAULT_PRECISION) { }
struct UseElementNames : public SettingBase<UseElementNames, bool> {
static constexpr const char* const name = "use-element-names";
static constexpr const char* const description = "Use entity instance IfcRoot.Name instead of unique IDs for naming elements upon serialization. "
"Applicable for OBJ, DAE, STP, and SVG output.";
static constexpr bool defaultvalue = false;
};
/// Sets the precision used to format floating-point values, 15 by default.
/// Use a negative value to use the system's default precision (should be 6 typically).
short precision;
struct UseElementGuids : public SettingBase<UseElementGuids, bool> {
static constexpr const char* const name = "use-element-guids";
static constexpr const char* const description = "Use entity instance IfcRoot.GlobalId instead of unique IDs for naming elements upon serialization. "
"Applicable for OBJ, DAE, STP, and SVG output.";
static constexpr bool defaultvalue = false;
};
enum { DEFAULT_PRECISION = 15 };
};
struct UseElementStepIds : public SettingBase<UseElementStepIds, bool> {
static constexpr const char* const name = "use-element-step-ids";
static constexpr const char* const description = "Use the numeric step identifier (entity instance name) for naming elements upon serialization. "
"Applicable for OBJ, DAE, STP, and SVG output.";
static constexpr bool defaultvalue = false;
};
struct UseMaterialNames : public SettingBase<UseMaterialNames, bool> {
static constexpr const char* const name = "use-material-names";
static constexpr const char* const description = "Use material names instead of unique IDs for naming materials upon serialization. "
"Applicable for OBJ and DAE output.";
static constexpr bool defaultvalue = false;
};
struct UseElementTypes : public SettingBase<UseElementTypes, bool> {
static constexpr const char* const name = "use-element-types";
static constexpr const char* const description = "Use element types instead of unique IDs for naming elements upon serialization. "
"Applicable to DAE output.";
static constexpr bool defaultvalue = false;
};
struct UseYUp : public SettingBase<UseYUp, bool> {
static constexpr const char* const name = "y-up";
static constexpr const char* const description = "Change the 'up' axis to positive Y, default is Z UP. Applicable to OBJ output.";
static constexpr bool defaultvalue = false;
};
struct FloatingPointDigits : public SettingBase<FloatingPointDigits, int> {
static constexpr const char* const name = "digits";
static constexpr const char* const description = "Sets the precision to be used to format floating-point values, 15 by default. "
"Use a negative value to use the system's default precision (should be 6 typically). "
"Applicable for OBJ and DAE output. For DAE output, value >= 15 means that up to 16 decimals are used, "
" and any other value means that 6 or 7 decimals are used.";
static constexpr bool defaultvalue = 15;
};
}
class SerializerSettings : public SettingsContainer <
// @todo should we use tuple_cat here to unify the settings into a single class?
std::tuple<UseElementNames, UseElementGuids, UseElementStepIds, UseMaterialNames, UseElementTypes, UseYUp, FloatingPointDigits>
>
{};
}
}
class stream_or_filename {
private:
@@ -103,7 +127,10 @@ class GeometrySerializer : public Serializer {
public:
enum read_type { READ_BREP, READ_TRIANGULATION };
GeometrySerializer(const SerializerSettings& settings) : settings_(settings) {}
GeometrySerializer(const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings)
: geometry_settings_(geometry_settings)
, settings_(settings)
{}
virtual ~GeometrySerializer() {}
virtual bool isTesselated() const = 0;
@@ -112,25 +139,29 @@ public:
virtual void setUnitNameAndMagnitude(const std::string& name, float magnitude) = 0;
virtual IfcGeom::Element* read(IfcParse::IfcFile& f, const std::string& guid, const std::string& representation_id, read_type rt = READ_BREP) = 0;
const SerializerSettings& settings() const { return settings_; }
SerializerSettings& settings() { return settings_; }
const ifcopenshell::geometry::SerializerSettings& settings() const { return settings_; }
ifcopenshell::geometry::SerializerSettings& settings() { return settings_; }
const ifcopenshell::geometry::Settings& geometry_settings() const { return geometry_settings_; }
ifcopenshell::geometry::Settings& geometry_settings() { return geometry_settings_; }
/// Returns ID for the object depending on the used setting.
virtual std::string object_id(const IfcGeom::Element* o)
{
if (settings_.get(SerializerSettings::USE_ELEMENT_GUIDS)) return o->guid();
if (settings_.get(SerializerSettings::USE_ELEMENT_NAMES)) return o->name();
if (settings_.get(SerializerSettings::USE_ELEMENT_STEPIDS)) return "id-" + boost::lexical_cast<std::string>(o->id());
if (settings_.get<ifcopenshell::geometry::settings::UseElementGuids>().get()) return o->guid();
if (settings_.get<ifcopenshell::geometry::settings::UseElementNames>().get()) return o->name();
if (settings_.get<ifcopenshell::geometry::settings::UseElementStepIds>().get()) return "id-" + boost::lexical_cast<std::string>(o->id());
return o->unique_id();
}
protected:
SerializerSettings settings_;
ifcopenshell::geometry::Settings geometry_settings_;
ifcopenshell::geometry::SerializerSettings settings_;
};
class WriteOnlyGeometrySerializer : public GeometrySerializer {
public:
WriteOnlyGeometrySerializer(const SerializerSettings& settings) : GeometrySerializer(settings) {}
WriteOnlyGeometrySerializer(const ifcopenshell::geometry::Settings& geometry_settings, const ifcopenshell::geometry::SerializerSettings& settings) : GeometrySerializer(geometry_settings, settings) {}
virtual IfcGeom::Element* read(IfcParse::IfcFile&, const std::string&, const std::string&, read_type = READ_BREP) {
throw std::runtime_error("Not supported");