Last minute refactoring

This commit is contained in:
Thomas Krijnen
2026-08-08 07:42:45 +02:00
parent 8870ffb018
commit af58eaf79f
300 changed files with 5230 additions and 5150 deletions
+24 -25
View File
@@ -161,9 +161,8 @@ def main(
# Initialize serializer
buffer = ifcopenshell.geom.serializers.buffer()
serialiser_settings = ifcopenshell.geom.serializer_settings()
if settings.auto_floorplan:
serialiser_settings.set("section-height-from-storeys", True)
geom_settings.set("section-height-from-storeys", True)
# elevation-ref-guid and elevation-ref are also mutually exclusive in C-code.
# Note that guid or object type are not checked anywhere to be valid,
@@ -172,38 +171,38 @@ def main(
if settings.drawing_guid:
if not by_guid(settings.drawing_guid):
raise ValueError(f"Unable to find guid {settings.drawing_guid!r}")
serialiser_settings.set("elevation-ref-guid", settings.drawing_guid)
geom_settings.set("elevation-ref-guid", settings.drawing_guid)
elif settings.drawing_object_type:
serialiser_settings.set("elevation-ref", settings.drawing_object_type)
serialiser_settings.set("svg-without-storeys", True)
geom_settings.set("elevation-ref", settings.drawing_object_type)
geom_settings.set("svg-without-storeys", True)
# required for svgfill
serialiser_settings.set("svg-write-poly", True)
serialiser_settings.set("svg-xmlns", True)
geom_settings.set("svg-write-poly", True)
geom_settings.set("svg-xmlns", True)
serialiser_settings.set("svg-project", settings.include_projection)
serialiser_settings.set("profile-threshold", settings.profile_threshold)
serialiser_settings.set("bounds", f"{settings.width}x{settings.height}")
serialiser_settings.set("scale", str(settings.scale))
serialiser_settings.set("auto-elevation", settings.auto_elevation)
serialiser_settings.set("auto-section", settings.auto_section)
serialiser_settings.set("print-space-names", settings.space_names)
serialiser_settings.set("print-space-areas", settings.space_areas)
serialiser_settings.set("door-arcs", settings.door_arcs)
serialiser_settings.set("svg-no-css", bool(settings.css))
geom_settings.set("svg-project", settings.include_projection)
geom_settings.set("profile-threshold", settings.profile_threshold)
geom_settings.set("bounds", f"{settings.width}x{settings.height}")
geom_settings.set("scale", str(settings.scale))
geom_settings.set("auto-elevation", settings.auto_elevation)
geom_settings.set("auto-section", settings.auto_section)
geom_settings.set("print-space-names", settings.space_names)
geom_settings.set("print-space-areas", settings.space_areas)
geom_settings.set("door-arcs", settings.door_arcs)
geom_settings.set("svg-no-css", bool(settings.css))
if settings.subtract_before_hlr:
serialiser_settings.set("svg-subtract-before", "always")
geom_settings.set("svg-subtract-before", "always")
serialiser_settings.set("svg-poly", settings.hlr_poly)
serialiser_settings.set("svg-prefilter", settings.prefilter)
serialiser_settings.set("svg-unify-inputs", settings.unify_inputs)
serialiser_settings.set("svg-mirror-y", settings.mirror_y)
geom_settings.set("svg-poly", settings.hlr_poly)
geom_settings.set("svg-prefilter", settings.prefilter)
geom_settings.set("svg-unify-inputs", settings.unify_inputs)
geom_settings.set("svg-mirror-y", settings.mirror_y)
if settings.storey_heights not in {"none", "full", "left"}:
raise ValueError("storey_heights should be one of {'none', 'full', 'left'}")
serialiser_settings.set("draw-storey-heights", settings.storey_heights)
geom_settings.set("draw-storey-heights", settings.storey_heights)
sr = ifcopenshell.geom.serializers.svg(buffer, geom_settings, serialiser_settings)
sr = ifcopenshell.geom.serializers.svg(buffer, geom_settings)
sr.setFile(files[0])
"""
@@ -378,7 +377,7 @@ def main(
# Put the IFC element entity type on the path for CSS-based styling
p.setAttribute("class", elements[0].instance.is_a())
# Obtain style (IfcOpenShell IfcGeom::Material)
# Obtain style (IfcOpenShell ifcopenshell::geom::Material)
style = tree.styles()[elements[0].style_index]
# This is just a demonstration. We compose a factor of using:
@@ -102,7 +102,7 @@ class Header(codegen.Base):
all_superclasses.append(superclass)
superclass = mapping.simple_type_parent(superclass)
else:
superclasses.append("express::DeclaredType")
superclasses.append("express::declared_type")
# This is no longer used, previously virtual inheritance was used, now
# a variant-like approach is used instead, so the definition of selects
@@ -110,7 +110,7 @@ class Header(codegen.Base):
# superclasses.extend(get_select_super_types(name, bases=all_superclasses))
is_emitted = (
lambda nm: nm == "express::DeclaredType"
lambda nm: nm == "express::declared_type"
or nm in mapping.schema.selects
or nm.lower() in emitted_simpletypes
)
@@ -191,7 +191,7 @@ class Header(codegen.Base):
all_supertypes.append(tt.supertypes[0])
tt = mapping.schema.entities[tt.supertypes[0]]
supertypes = list(type.supertypes) if len(type.supertypes) else ["express::Entity"]
supertypes = list(type.supertypes) if len(type.supertypes) else ["express::entity"]
# supertypes.extend(get_select_super_types(name, bases=all_supertypes))
supertypes = list(map(case_normalize, supertypes))
assert len(supertypes) == 1
@@ -239,12 +239,12 @@ class Implementation(codegen.Base):
for i in type.inverse
]
superclass = "%s(e)" % type.supertypes[0] if len(type.supertypes) == 1 else "express::Entity(e)"
superclass = "%s(e)" % type.supertypes[0] if len(type.supertypes) == 1 else "express::entity(e)"
superclass_num_attrs = (
"%s(const std::weak_ptr<instance_data>&(in_memory_attribute_storage(%%d)))" % type.supertypes[0]
if len(type.supertypes) == 1
else "express::Entity(const std::weak_ptr<instance_data>&(in_memory_attribute_storage(%d)))"
else "express::entity(const std::weak_ptr<instance_data>&(in_memory_attribute_storage(%d)))"
) % len(constructor_arguments)
write(
@@ -309,7 +309,7 @@ class Implementation(codegen.Base):
for class_name, type in mapping.schema.simpletypes.items():
type_str = mapping.make_type_string(mapping.flatten_type_string(type))
attr_type = mapping.make_argument_type(type)
superclass = mapping.simple_type_parent(class_name) or "express::DeclaredType"
superclass = mapping.simple_type_parent(class_name) or "express::declared_type"
simpletype_impl_is = (
templates.simpletype_impl_is_with_supertype
@@ -378,7 +378,7 @@ class Implementation(codegen.Base):
("%s v" % type_str,),
(
"set_attribute_value(0, %s(v));"
% ("cast_vector<express::Base>" if mapping.is_templated_list(type) else "")
% ("cast_vector<express::base>" if mapping.is_templated_list(type) else "")
),
),
# ("v", "", constructor, "", ("%s v" % type_str,), ""),
@@ -130,10 +130,10 @@ simpletype_impl_type = "return *((ifcopenshell::type_declaration*)%(schema_name_
simpletype_impl_class = "return *((ifcopenshell::type_declaration*)%(schema_name_upper)s_types[%(index_in_schema)d]);"
simpletype_impl_explicit_constructor = "data_ = e;"
simpletype_impl_constructor = "data_ = new const std::weak_ptr<instance_data>&(%(schema_name_upper)s_types[%(index_in_schema)d]); set_attribute_value(0, v);"
simpletype_impl_constructor_templated = "data_ = new const std::weak_ptr<instance_data>&(%(schema_name_upper)s_types[%(index_in_schema)d]); set_attribute_value(0, cast_vector<express::Base>(v));"
simpletype_impl_constructor_templated = "data_ = new const std::weak_ptr<instance_data>&(%(schema_name_upper)s_types[%(index_in_schema)d]); set_attribute_value(0, cast_vector<express::base>(v));"
simpletype_impl_cast = "return get_attribute_value(0);"
simpletype_impl_cast_templated = (
"std::vector<express::Base> es = get_attribute_value(0); return cast_vector<%(underlying_type)s>(es);"
"std::vector<express::base> es = get_attribute_value(0); return cast_vector<%(underlying_type)s>(es);"
)
simpletype_impl_declaration = (
@@ -141,9 +141,9 @@ simpletype_impl_declaration = (
)
select = """%(documentation)s
class IFC_SCHEMA_API %(name)s : public express::Select {
class IFC_SCHEMA_API %(name)s : public express::select {
public:
using express::Select::Select;
using express::select::select;
static const ifcopenshell::select_type& Class();
%(template_items)s
@@ -153,16 +153,16 @@ public:
select_list_item = """ // let's just use the as<>() from Base instead directly...
// template<class T, std::enable_if_t<std::is_same_v<T, %(item_name)s>, int> = 0>
// %(item_name)s as() const { return express::Base::as<%(item_name)s>(); }
// %(item_name)s as() const { return express::base::as<%(item_name)s>(); }
"""
select_cast_function = """ %(name)s(const %(item_name)s& c) : express::Select(c) {};
select_cast_function = """ %(name)s(const %(item_name)s& c) : express::select(c) {};
"""
enumeration = """%(documentation)s
class IFC_SCHEMA_API %(name)s : public express::DeclaredType {
class IFC_SCHEMA_API %(name)s : public express::declared_type {
public:
using express::DeclaredType::DeclaredType;
using express::declared_type::declared_type;
typedef enum {%(values)s} Value;
static const char* ToString(Value v);
@@ -196,7 +196,7 @@ const ifcopenshell::enumeration_type& %(schema_name)s::%(name)s::Class() { retur
/*
%(schema_name)s::%(name)s::%(name)s(const std::weak_ptr<instance_data>& e)
: express::DeclaredType(e)
: express::declared_type(e)
{}
%(schema_name)s::%(name)s::%(name)s(Value v) {
@@ -259,22 +259,22 @@ optional_attr_stmt = "return !get_attribute_value(%(index)d).isNull();"
get_attr_stmt = "%(null_check)s %(non_optional_type)s v = get_attribute_value(%(index)d); return v;"
get_attr_stmt_enum = "%(null_check)s return %(non_optional_type)s::FromString(get_attribute_value(%(index)d));"
get_attr_stmt_entity = (
"%(null_check)s return ((express::Base)(get_attribute_value(%(index)d))).as<%(non_optional_type_no_pointer)s>();"
"%(null_check)s return ((express::base)(get_attribute_value(%(index)d))).as<%(non_optional_type_no_pointer)s>();"
)
get_attr_stmt_array = "%(null_check)s std::vector<express::Base> es = get_attribute_value(%(index)d); return cast_vector<%(list_instance_type)s>(es);"
get_attr_stmt_nested_array = "%(null_check)s std::vector<std::vector<express::Base>> es = get_attribute_value(%(index)d); return cast_vector<%(list_instance_type)s>(es);"
get_attr_stmt_array = "%(null_check)s std::vector<express::base> es = get_attribute_value(%(index)d); return cast_vector<%(list_instance_type)s>(es);"
get_attr_stmt_nested_array = "%(null_check)s std::vector<std::vector<express::base>> es = get_attribute_value(%(index)d); return cast_vector<%(list_instance_type)s>(es);"
get_inverse = "return cast_vector<%(type)s>(file()->get_inverse(data()->id(), %(schema_name_upper)s_types[%(type_index)d], %(index)d));"
set_attr_stmt = "%(check_optional_set_begin)sset_attribute_value(%(index)d, %(star_if_optional)sv);%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s"
set_attr_instance = "%(check_optional_set_begin)sset_attribute_value(%(index)d, v);%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s"
set_attr_stmt_enum = "%(check_optional_set_begin)sset_attribute_value(%(index)d, enumeration_reference(&%(non_optional_type)s::Class(), (size_t) %(star_if_optional)sv));%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s"
set_attr_stmt_array = "%(check_optional_set_begin)sset_attribute_value(%(index)d, cast_vector<express::Base>(%(star_if_optional)sv));%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s"
set_attr_stmt_nested_array = "%(check_optional_set_begin)sset_attribute_value(%(index)d, cast_vector<express::Base>(%(star_if_optional)sv));%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s"
set_attr_stmt_array = "%(check_optional_set_begin)sset_attribute_value(%(index)d, cast_vector<express::base>(%(star_if_optional)sv));%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s"
set_attr_stmt_nested_array = "%(check_optional_set_begin)sset_attribute_value(%(index)d, cast_vector<express::base>(%(star_if_optional)sv));%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s"
constructor_stmt = "set_attribute_value(%(index)d, (%(name)s));"
constructor_stmt_enum = "set_attribute_value(%(index)d, (enumeration_reference(&%(type)s::Class(),(size_t)%(name)s)));"
constructor_stmt_array = "set_attribute_value(%(index)d, cast_vector<express::Base>(%(name)s));"
constructor_stmt_array = "set_attribute_value(%(index)d, cast_vector<express::base>(%(name)s));"
constructor_stmt_derived = ""
constructor_stmt_instance = "set_attribute_value(%(index)d, %(name)s);"
@@ -65,8 +65,12 @@ SETTING = Literal[
"angle-unit",
"apply-default-materials",
"apply-offset",
"auto-elevation",
"auto-section",
"base-uri",
"boolean-attempt-2d",
"building-local-placement",
"bounds",
"cache-shapes",
"cgal-original-edges",
"cgal-smooth-angle-degrees",
@@ -80,9 +84,13 @@ SETTING = Literal[
"debug",
"defer-processing-first-element",
"dimensionality",
"digits",
"disable-boolean-result",
"disable-opening-subtractions",
"edge-arrows",
"ecef",
"elevation-ref",
"elevation-ref-guid",
"element-hierarchy",
"enable-layerset-slicing",
"force-space-transparency",
@@ -107,65 +115,55 @@ SETTING = Literal[
"no-wire-intersection-check",
"no-wire-intersection-tolerance",
"permissive-shape-reuse",
"print-space-areas",
"print-space-names",
"precision-factor",
"precision",
"profile-threshold",
"reorient-shells",
"site-local-placement",
"scale",
"section-height",
"section-height-from-storeys",
"section-ref",
"separate-z-up-node",
"space-name-transform",
"storey-height-line-length",
"surface-colour",
"svg-emit-flush-edges",
"svg-mirror-x",
"svg-mirror-y",
"svg-no-css",
"svg-poly",
"svg-prefilter",
"svg-project",
"svg-render-crease-edges",
"svg-render-sharp-edges",
"svg-ridge-angle-min-degrees",
"svg-segment-projection",
"svg-subtract-before",
"svg-unify-inputs",
"svg-use-edge-classification",
"svg-valley-angle-min-degrees",
"svg-without-storeys",
"svg-write-poly",
"svg-xmlns",
"triangulation-type",
"unify-shapes",
"use-material-names",
"use-element-guids",
"use-element-names",
"use-element-step-ids",
"use-element-types",
"use-python-opencascade",
"use-world-coords",
"validate",
"weld-vertices",
]
SERIALIZER_SETTING = Literal[
"base-uri",
"use-element-names",
"use-element-guids",
"use-element-step-ids",
"use-element-types",
"y-up",
"ecef",
"digits",
"wkt-use-section",
"separate-z-up-node",
"bounds",
"scale",
"center",
"section-ref",
"elevation-ref",
"elevation-ref-guid",
"auto-section",
"auto-elevation",
"draw-storey-heights",
"profile-threshold",
"storey-height-line-length",
"svg-xmlns",
"svg-poly",
"svg-prefilter",
"svg-unify-inputs",
"svg-segment-projection",
"svg-subtract-before",
"svg-write-poly",
"svg-project",
"svg-without-storeys",
"svg-no-css",
"svg-mirror-y",
"svg-mirror-x",
"door-arcs",
"section-height",
"section-height-from-storeys",
"print-space-names",
"print-space-areas",
"space-name-transform",
]
# NOTE: hybrid-cgal-simple-opencascade is added just as an example
@@ -203,18 +201,14 @@ class settings_mixin:
return "%s(%s)" % (type(self).__name__, ", ".join(map(fmt_pair, self.setting_names())))
@staticmethod
def name(k: str) -> Union[SETTING, SERIALIZER_SETTING]:
def name(k: str) -> SETTING:
return k.lower().replace("_", "-")
@staticmethod
def rname(k: Union[SETTING, SERIALIZER_SETTING]) -> str:
def rname(k: SETTING) -> str:
return k.upper().replace("-", "_")
@overload
def set(self: settings, k: SETTING, v: Any) -> None: ...
@overload
def set(self: serializer_settings, k: SERIALIZER_SETTING, v: Any) -> None: ...
def set(self, k: Union[SETTING, SERIALIZER_SETTING], v: Any) -> None:
def set(self, k: SETTING, v: Any) -> None:
"""
Set value of the setting named `k` to `v`.
@@ -231,10 +225,6 @@ class settings_mixin:
else:
self.set_(self.name(k), v)
@overload
def get(self: settings, k: SETTING) -> Any: ...
@overload
def get(self: serializer_settings, k: SERIALIZER_SETTING) -> Any: ...
def get(self, k: str) -> Any:
"""
Return value of the setting named `k`.
@@ -246,20 +236,12 @@ class settings_mixin:
return self.use_python_opencascade
return self.get_(k)
@overload
def setting_names(self: settings) -> tuple[SETTING, ...]: ...
@overload
def setting_names(self: serializer_settings) -> tuple[SERIALIZER_SETTING, ...]: ...
def setting_names(self) -> tuple[str, ...]:
setting_names = super().setting_names()
if isinstance(self, settings):
setting_names += ("use-python-opencascade",)
return setting_names
@overload
def __getattr__(self: settings, k: str) -> SETTING: ...
@overload
def __getattr__(self: serializer_settings, k: str) -> SERIALIZER_SETTING: ...
def __getattr__(self, k: str) -> str:
# Swig wrapper will try to access "this",
# ensure we won't accidentally call any c-extension methods
@@ -322,10 +304,6 @@ class settings_mixin:
self.set(k.replace("_", "-"), v)
class serializer_settings(settings_mixin, ifcopenshell_wrapper.SerializerSettings):
pass
class settings(settings_mixin, ifcopenshell_wrapper.Settings):
use_python_opencascade = False
@@ -687,18 +665,18 @@ class _serializer_factory:
self.__name__ = name
def __call__(self, out_filename: Union[str, PathLike[str]], *args: Any) -> ifcopenshell_wrapper.GeometrySerializer:
if self.name == "obj" and len(args) == 3:
if self.name == "obj" and len(args) == 2:
output_filename = args[0]
output_temp_filename = out_filename
geometry_settings, serializer_settings = args[1], args[2]
elif len(args) == 2:
settings = args[1]
elif len(args) == 1:
output_filename = out_filename
output_temp_filename = out_filename
geometry_settings, serializer_settings = args
settings = args[0]
else:
obj_signature = " or (out_filename, mtl_filename, geometry_settings, serializer_settings)"
obj_signature = " or (out_filename, mtl_filename, settings)"
raise TypeError(
f"serializers.{self.name}() expects (out_filename, geometry_settings, serializer_settings)"
f"serializers.{self.name}() expects (out_filename, settings)"
+ (obj_signature if self.name == "obj" else "")
)
@@ -711,9 +689,7 @@ class _serializer_factory:
output_filename = self._path(output_filename)
output_temp_filename = self._path(output_temp_filename)
return ifcopenshell_wrapper.create_geometry_serializer(
self.extension, output_filename, output_temp_filename, geometry_settings, serializer_settings
)
return ifcopenshell_wrapper.create_geometry_serializer(self.extension, output_filename, output_temp_filename, settings)
def _is_buffer(self, value: Any) -> bool:
return isinstance(value, ifcopenshell_wrapper.buffer)
@@ -257,7 +257,6 @@ class GeometrySerializer:
READ_TRIANGULATION: Any
def __init__(self, *args, **kwargs): ...
def finalize(self): ...
def geometry_settings(self, *args): ...
def isTesselated(self): ...
def is_streaming(self) -> bool: ...
def object_id(self, o): ...
@@ -265,7 +264,7 @@ class GeometrySerializer:
def ready(self): ...
def setFile(self, file: file) -> None: ...
def setUnitNameAndMagnitude(self, name, magnitude): ...
def settings(self, *args): ...
def settings(self, *args) -> "Settings": ...
def write(self, *args): ...
def writeHeader(self): ...
@@ -370,7 +369,7 @@ class Representation:
- 2468 - IfcRelVoidsElement
"""
def settings(self): ...
def settings(self) -> "Settings": ...
class RocksDBPrefixIterator:
def __init__(self, storage, prefix): ...
@@ -401,12 +400,6 @@ class SerializedElement(Element):
@property
def geometry(self) -> Serialization: ...
class SerializerSettings:
def get_(self, name): ...
def get_type(self, name): ...
def set_(self, *args): ...
def setting_names(self): ...
class Settings:
def get_(self, name): ...
def get_type(self, name): ...