mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
typing
This commit is contained in:
@@ -170,7 +170,8 @@ def import_attribute(
|
||||
if isinstance(data_type, tuple) or data_type == "entity":
|
||||
callback(attribute.name(), None, data) if callback else None
|
||||
return
|
||||
new: bonsai.bim.prop.Attribute = props.add()
|
||||
|
||||
new = props.add()
|
||||
new.name = attribute.name()
|
||||
new.is_null = data[attribute.name()] is None
|
||||
new.is_optional = attribute.optional()
|
||||
|
||||
@@ -47,7 +47,7 @@ class LoadGroups(bpy.types.Operator, tool.Ifc.Operator):
|
||||
bpy.ops.bim.disable_editing_group()
|
||||
return {"FINISHED"}
|
||||
|
||||
def load_group(self, group, tree_depth=0):
|
||||
def load_group(self, group: ifcopenshell.entity_instance, tree_depth: int = 0) -> None:
|
||||
new = self.props.groups.add()
|
||||
new.ifc_definition_id = group.id()
|
||||
new.name = group.Name or "Unnamed"
|
||||
|
||||
@@ -129,7 +129,7 @@ class BIM_UL_groups(UIList):
|
||||
active_data,
|
||||
active_propname,
|
||||
index: int,
|
||||
):
|
||||
) -> None:
|
||||
if item:
|
||||
row = layout.row(align=True)
|
||||
for i in range(0, item.tree_depth):
|
||||
|
||||
@@ -103,19 +103,19 @@ def get_pset_name(self: "PsetProperties", context: bpy.types.Context) -> tool.Bl
|
||||
return items
|
||||
|
||||
|
||||
def get_object_pset_name(self, context):
|
||||
def get_object_pset_name(self: "PsetProperties", context: object) -> tool.Blender.BLENDER_ENUM_ITEMS:
|
||||
if not ObjectPsetsData.is_loaded:
|
||||
ObjectPsetsData.load()
|
||||
return ObjectPsetsData.data["pset_name"]
|
||||
|
||||
|
||||
def get_material_pset_names(self, context):
|
||||
def get_material_pset_names(self: "PsetProperties", context: object) -> tool.Blender.BLENDER_ENUM_ITEMS:
|
||||
if not MaterialPsetsData.is_loaded:
|
||||
MaterialPsetsData.load()
|
||||
return MaterialPsetsData.data["pset_name"]
|
||||
|
||||
|
||||
def get_material_set_pset_names(self, context):
|
||||
def get_material_set_pset_names(self: "PsetProperties", context: object):
|
||||
global psetnames
|
||||
if not ObjectMaterialData.is_loaded:
|
||||
ObjectMaterialData.load()
|
||||
@@ -128,7 +128,7 @@ def get_material_set_pset_names(self, context):
|
||||
return psetnames[ifc_class]
|
||||
|
||||
|
||||
def get_material_set_item_pset_names(self, context) -> list[tuple[str, str, str]]:
|
||||
def get_material_set_item_pset_names(self: "PsetProperties", context: object) -> tool.Blender.BLENDER_ENUM_ITEMS:
|
||||
global psetnames
|
||||
obj = context.active_object
|
||||
assert obj
|
||||
@@ -142,7 +142,7 @@ def get_material_set_item_pset_names(self, context) -> list[tuple[str, str, str]
|
||||
return psetnames[ifc_class]
|
||||
|
||||
|
||||
def get_task_qto_names(self, context):
|
||||
def get_task_qto_names(self: "PsetProperties", context: object) -> tool.Blender.BLENDER_ENUM_ITEMS:
|
||||
global qtonames
|
||||
ifc_class = "IfcTask"
|
||||
if ifc_class not in qtonames:
|
||||
@@ -151,7 +151,7 @@ def get_task_qto_names(self, context):
|
||||
return qtonames[ifc_class]
|
||||
|
||||
|
||||
def get_resource_pset_names(self, context):
|
||||
def get_resource_pset_names(self: "PsetProperties", context: object) -> tool.Blender.BLENDER_ENUM_ITEMS:
|
||||
global psetnames
|
||||
rprops = context.scene.BIMResourceProperties
|
||||
rtprops = context.scene.BIMResourceTreeProperties
|
||||
@@ -162,7 +162,7 @@ def get_resource_pset_names(self, context):
|
||||
return psetnames[ifc_class]
|
||||
|
||||
|
||||
def get_resource_qto_names(self, context):
|
||||
def get_resource_qto_names(self: "PsetProperties", context: object) -> tool.Blender.BLENDER_ENUM_ITEMS:
|
||||
global qtonames
|
||||
rprops = context.scene.BIMResourceProperties
|
||||
rtprops = context.scene.BIMResourceTreeProperties
|
||||
@@ -173,7 +173,7 @@ def get_resource_qto_names(self, context):
|
||||
return qtonames[ifc_class]
|
||||
|
||||
|
||||
def get_group_pset_names(self, context):
|
||||
def get_group_pset_names(self: "PsetProperties", context: object) -> tool.Blender.BLENDER_ENUM_ITEMS:
|
||||
global psetnames
|
||||
ifc_class = "IfcGroup"
|
||||
if ifc_class not in psetnames:
|
||||
@@ -182,7 +182,7 @@ def get_group_pset_names(self, context):
|
||||
return psetnames[ifc_class]
|
||||
|
||||
|
||||
def get_group_qto_names(self, context):
|
||||
def get_group_qto_names(self: "PsetProperties", context: object) -> tool.Blender.BLENDER_ENUM_ITEMS:
|
||||
global qtonames
|
||||
ifc_class = "IfcGroup"
|
||||
if ifc_class not in qtonames:
|
||||
@@ -191,7 +191,7 @@ def get_group_qto_names(self, context):
|
||||
return qtonames[ifc_class]
|
||||
|
||||
|
||||
def get_profile_pset_names(self, context):
|
||||
def get_profile_pset_names(self: "PsetProperties", context: object) -> tool.Blender.BLENDER_ENUM_ITEMS:
|
||||
global psetnames
|
||||
pprops = tool.Profile.get_profile_props()
|
||||
ifc_class = tool.Ifc.get().by_id(pprops.profiles[pprops.active_profile_index].ifc_definition_id).is_a()
|
||||
@@ -201,7 +201,7 @@ def get_profile_pset_names(self, context):
|
||||
return psetnames[ifc_class]
|
||||
|
||||
|
||||
def get_work_schedule_pset_names(self, context):
|
||||
def get_work_schedule_pset_names(self: "PsetProperties", context: object) -> tool.Blender.BLENDER_ENUM_ITEMS:
|
||||
global psetnames
|
||||
ifc_class = "IfcWorkSchedule"
|
||||
if ifc_class not in psetnames:
|
||||
@@ -211,7 +211,7 @@ def get_work_schedule_pset_names(self, context):
|
||||
|
||||
|
||||
# TODO: unsafe?
|
||||
def get_qto_name(self, context):
|
||||
def get_qto_name(self: "PsetProperties", context: bpy.types.Context) -> tool.Blender.BLENDER_ENUM_ITEMS:
|
||||
pset_type = repr(self)
|
||||
prop_type = pset_type.split(".")[-1]
|
||||
if "bpy.data.objects" in pset_type:
|
||||
@@ -226,21 +226,21 @@ def get_qto_name(self, context):
|
||||
return [("BBIM_CUSTOM", "Custom Qto", "Create a quantity set without using a template."), None] + results
|
||||
|
||||
|
||||
def get_object_qto_name(self, context):
|
||||
def get_object_qto_name(self: "PsetProperties", context: object) -> tool.Blender.BLENDER_ENUM_ITEMS:
|
||||
if not ObjectPsetsData.is_loaded:
|
||||
ObjectPsetsData.load()
|
||||
return ObjectPsetsData.data["qto_name"]
|
||||
|
||||
|
||||
# TODO: unsafe?
|
||||
def get_template_type(self, context):
|
||||
def get_template_type(self: "AddEditProperties", context: object) -> tool.Blender.BLENDER_ENUM_ITEMS:
|
||||
version = tool.Ifc.get_schema()
|
||||
for t in ("IfcPropertySingleValue", "IfcPropertyEnumeratedValue"):
|
||||
yield (t, t, ifcopenshell.util.doc.get_entity_doc(version, t).get("description", ""))
|
||||
|
||||
|
||||
# TODO: unsafe?
|
||||
def get_primary_measure_type(self, context):
|
||||
def get_primary_measure_type(self: "AddEditProperties", context: object) -> tool.Blender.BLENDER_ENUM_ITEMS:
|
||||
if not AddEditCustomPropertiesData.is_loaded:
|
||||
AddEditCustomPropertiesData.load()
|
||||
return AddEditCustomPropertiesData.data["primary_measure_type"]
|
||||
@@ -249,6 +249,9 @@ def get_primary_measure_type(self, context):
|
||||
class IfcPropertyEnumeratedValue(PropertyGroup):
|
||||
enumerated_values: CollectionProperty(type=Attribute)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
enumerated_values: bpy.types.bpy_prop_collection_idprop[Attribute]
|
||||
|
||||
|
||||
IfcPropertyValueType = Literal["IfcPropertySingleValue", "IfcPropertyEnumeratedValue"]
|
||||
|
||||
@@ -297,6 +300,11 @@ class RenameProperties(PropertyGroup):
|
||||
existing_property_name: StringProperty(name="Existing Property Name")
|
||||
new_property_name: StringProperty(name="New Property Name")
|
||||
|
||||
if TYPE_CHECKING:
|
||||
pset_name: str
|
||||
existing_property_name: str
|
||||
new_property_name: str
|
||||
|
||||
|
||||
class AddEditProperties(PropertyGroup):
|
||||
pset_name: StringProperty(name="Pset")
|
||||
@@ -309,6 +317,17 @@ class AddEditProperties(PropertyGroup):
|
||||
template_type: EnumProperty(items=get_template_type, name="Template Type")
|
||||
enum_values: CollectionProperty(name="Enum Values", type=Attribute)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
pset_name: str
|
||||
property_name: str
|
||||
string_value: str
|
||||
bool_value: bool
|
||||
int_value: int
|
||||
float_value: float
|
||||
primary_measure_type: str
|
||||
template_type: str
|
||||
enum_values: bpy.types.bpy_prop_collection_idprop[Attribute]
|
||||
|
||||
def get_value_name(self) -> Union[Literal["string_value", "bool_value", "int_value", "float_value"], None]:
|
||||
schema = tool.Ifc.schema()
|
||||
ifc_data_type = schema.declaration_by_name(self.primary_measure_type)
|
||||
@@ -326,7 +345,14 @@ class AddEditProperties(PropertyGroup):
|
||||
class DeletePsets(PropertyGroup):
|
||||
pset_name: StringProperty(name="Pset")
|
||||
|
||||
if TYPE_CHECKING:
|
||||
pset_name: str
|
||||
|
||||
|
||||
class GlobalPsetProperties(PropertyGroup):
|
||||
pset_filter: StringProperty(name="Pset Filter", options={"TEXTEDIT_UPDATE"})
|
||||
qto_filter: StringProperty(name="Qto Filter", options={"TEXTEDIT_UPDATE"})
|
||||
|
||||
if TYPE_CHECKING:
|
||||
pset_filter: str
|
||||
qto_filter: str
|
||||
|
||||
@@ -263,7 +263,7 @@ class Pset(bonsai.core.tool.Pset):
|
||||
pset_template: ifcopenshell.entity_instance,
|
||||
prop_template: ifcopenshell.entity_instance,
|
||||
data: dict[str, Any],
|
||||
props: bpy.types.PropertyGroup,
|
||||
props: PsetProperties,
|
||||
) -> None:
|
||||
prop = props.properties.add()
|
||||
prop.name = prop_template.Name
|
||||
@@ -293,7 +293,7 @@ class Pset(bonsai.core.tool.Pset):
|
||||
cls,
|
||||
pset_template: ifcopenshell.entity_instance,
|
||||
pset: Union[ifcopenshell.entity_instance, None],
|
||||
props: bpy.types.PropertyGroup,
|
||||
props: PsetProperties,
|
||||
) -> None:
|
||||
if pset:
|
||||
data = ifcopenshell.util.element.get_property_definition(pset, verbose=True)
|
||||
|
||||
@@ -143,6 +143,7 @@ class Usecase:
|
||||
else:
|
||||
vx = vz.cross(X_AXIS)
|
||||
vy = vx.cross(vz)
|
||||
assert isinstance(vy, Vector)
|
||||
tM = Matrix(
|
||||
[[vx.x, vy.x, vz.x, co.x], [vx.y, vy.y, vz.y, co.y], [vx.z, vy.z, vz.z, co.z], [0, 0, 0, 1]]
|
||||
).inverted()
|
||||
|
||||
@@ -568,6 +568,8 @@ class entity_instance:
|
||||
) -> dict[str, Any]:
|
||||
"""Return a dictionary of the entity_instance's properties (Python and IFC) and their values.
|
||||
|
||||
Resulting dictionary keys: 'id', 'type', all entity attribute names.
|
||||
|
||||
:param include_identifier: Whether or not to include the STEP numerical identifier
|
||||
:param recursive: Whether or not to convert referenced IFC elements into dictionaries too. All attributes also apply recursively
|
||||
:param return_type: The return data type to be casted into
|
||||
|
||||
@@ -584,7 +584,7 @@ class aggregation_type(parameter_type):
|
||||
bag_type: Any
|
||||
list_type: Any
|
||||
set_type: Any
|
||||
def as_aggregation_type(self): ...
|
||||
def as_aggregation_type(self) -> aggregation_type: ...
|
||||
def bound1(self): ...
|
||||
def bound2(self): ...
|
||||
def type_of_aggregation(self): ...
|
||||
@@ -1120,8 +1120,8 @@ class matrix4(item):
|
||||
|
||||
class named_type(parameter_type):
|
||||
def _is(self, *args): ...
|
||||
def as_named_type(self): ...
|
||||
def declared_type(self): ...
|
||||
def as_named_type(self) -> named_type: ...
|
||||
def declared_type(self) -> declaration: ...
|
||||
|
||||
class node(item):
|
||||
def calc_hash(self): ...
|
||||
@@ -1146,10 +1146,16 @@ class offset_function(function_item):
|
||||
def start(self): ...
|
||||
|
||||
class parameter_type:
|
||||
def _is(self, *args): ...
|
||||
def as_aggregation_type(self): ...
|
||||
def as_named_type(self): ...
|
||||
def as_simple_type(self): ...
|
||||
def _is(self, *args: Union[str, declaration]) -> bool:
|
||||
"""
|
||||
:param args: IFC class name or declaration to check.
|
||||
Argument accepts only 1 value.
|
||||
"""
|
||||
...
|
||||
|
||||
def as_aggregation_type(self) -> Union[aggregation_type, None]: ...
|
||||
def as_named_type(self) -> Union[named_type, None]: ...
|
||||
def as_simple_type(self) -> Union[simple_type, None]: ...
|
||||
|
||||
class piecewise_function(function_item):
|
||||
def calc_hash(self): ...
|
||||
@@ -1268,7 +1274,7 @@ class simple_type(parameter_type):
|
||||
real_type: Any
|
||||
string_type: Any
|
||||
datatype_COUNT: Any
|
||||
def as_simple_type(self): ...
|
||||
def as_simple_type(self) -> simple_type: ...
|
||||
def declared_type(self): ...
|
||||
|
||||
class solid:
|
||||
|
||||
@@ -17,13 +17,22 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import ifcopenshell.ifcopenshell_wrapper as ifcopenshell_wrapper
|
||||
from typing import Union
|
||||
from typing import Union, Literal
|
||||
|
||||
PrimitiveType = Literal["entity", "string", "float", "integer", "boolean", "enum", "binary"]
|
||||
ComplexPrimitiveType = Literal["list", "array", "set"]
|
||||
PrimitiveTypeOutput = Union[
|
||||
PrimitiveType,
|
||||
tuple[ComplexPrimitiveType, "PrimitiveTypeOutput"],
|
||||
tuple[Literal["select"], tuple["PrimitiveTypeOutput", ...]],
|
||||
None,
|
||||
]
|
||||
|
||||
|
||||
def get_primitive_type(
|
||||
attribute_or_data_type: Union[ifcopenshell_wrapper.attribute, ifcopenshell_wrapper.parameter_type],
|
||||
) -> Union[str, tuple[str, list[str]]]:
|
||||
if hasattr(attribute_or_data_type, "type_of_attribute"):
|
||||
) -> PrimitiveTypeOutput:
|
||||
if isinstance(attribute_or_data_type, ifcopenshell_wrapper.attribute):
|
||||
data_type = str(attribute_or_data_type.type_of_attribute())
|
||||
else:
|
||||
data_type = str(attribute_or_data_type)
|
||||
@@ -56,8 +65,16 @@ def get_primitive_type(
|
||||
|
||||
|
||||
def get_enum_items(attribute: ifcopenshell_wrapper.attribute) -> tuple[str, ...]:
|
||||
return attribute.type_of_attribute().declared_type().enumeration_items()
|
||||
named_type = attribute.type_of_attribute().as_named_type()
|
||||
assert named_type
|
||||
enumeration = named_type.declared_type().as_enumeration_type()
|
||||
assert enumeration
|
||||
return enumeration.enumeration_items()
|
||||
|
||||
|
||||
def get_select_items(attribute: ifcopenshell_wrapper.attribute) -> tuple[ifcopenshell_wrapper.entity, ...]:
|
||||
return attribute.type_of_attribute().declared_type().select_list()
|
||||
def get_select_items(attribute: ifcopenshell_wrapper.attribute) -> tuple[ifcopenshell_wrapper.declaration, ...]:
|
||||
named_type = attribute.type_of_attribute().as_named_type()
|
||||
assert named_type
|
||||
select_type = named_type.declared_type().as_select_type()
|
||||
assert select_type
|
||||
return select_type.select_list()
|
||||
|
||||
Reference in New Issue
Block a user