mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-29 16:22:53 +00:00
typing
This commit is contained in:
@@ -32,6 +32,7 @@ class BIM_PT_ifccsv(Panel):
|
||||
bl_parent_id = "BIM_PT_tab_collaboration"
|
||||
|
||||
def draw(self, context):
|
||||
assert self.layout
|
||||
layout = self.layout
|
||||
props = tool.Blender.get_csv_props()
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
from collections import defaultdict
|
||||
import bpy
|
||||
import ifcopenshell.util.attribute
|
||||
import ifcopenshell.util.element
|
||||
import ifcopenshell.util.schema
|
||||
from ifcopenshell.util.doc import get_entity_doc, get_predefined_type_doc, get_class_suggestions
|
||||
@@ -83,14 +84,15 @@ class IfcClassData:
|
||||
types_enum = []
|
||||
rprops = tool.Root.get_root_props()
|
||||
ifc_class = rprops.ifc_class
|
||||
declaration = tool.Ifc.schema().declaration_by_name(ifc_class)
|
||||
declaration = tool.Ifc.schema().declaration_by_name(ifc_class).as_entity()
|
||||
assert declaration
|
||||
version = tool.Ifc.get_schema()
|
||||
for attribute in declaration.attributes():
|
||||
if attribute.name() == "PredefinedType":
|
||||
types_enum.extend(
|
||||
[
|
||||
(e, e, get_predefined_type_doc(version, ifc_class, e) or "")
|
||||
for e in attribute.type_of_attribute().declared_type().enumeration_items()
|
||||
for e in ifcopenshell.util.attribute.get_enum_items(attribute)
|
||||
]
|
||||
)
|
||||
break
|
||||
|
||||
@@ -86,7 +86,7 @@ class Sequence(bonsai.core.tool.Sequence):
|
||||
def get_work_plan_attributes(cls) -> dict[str, Any]:
|
||||
import bonsai.bim.module.sequence.helper as helper
|
||||
|
||||
def callback(attributes, prop):
|
||||
def callback(attributes: dict[str, Any], prop: Attribute) -> bool:
|
||||
if "Date" in prop.name or "Time" in prop.name:
|
||||
if prop.is_null:
|
||||
attributes[prop.name] = None
|
||||
@@ -99,14 +99,16 @@ class Sequence(bonsai.core.tool.Sequence):
|
||||
return True
|
||||
attributes[prop.name] = helper.parse_duration(prop.string_value)
|
||||
return True
|
||||
return False
|
||||
|
||||
props = cls.get_work_plan_props()
|
||||
return bonsai.bim.helper.export_attributes(props.work_plan_attributes, callback)
|
||||
|
||||
@classmethod
|
||||
def load_work_plan_attributes(cls, work_plan: ifcopenshell.entity_instance) -> None:
|
||||
def callback(name, prop, data):
|
||||
def callback(name: str, prop: Union[Attribute, None], data: dict[str, Any]) -> None | Literal[True]:
|
||||
if name in ["CreationDate", "StartTime", "FinishTime"]:
|
||||
assert prop
|
||||
prop.string_value = "" if prop.is_null else data[name]
|
||||
return True
|
||||
|
||||
@@ -137,7 +139,7 @@ class Sequence(bonsai.core.tool.Sequence):
|
||||
def get_work_schedule_attributes(cls) -> dict[str, Any]:
|
||||
import bonsai.bim.module.sequence.helper as helper
|
||||
|
||||
def callback(attributes, prop):
|
||||
def callback(attributes: dict[str, Any], prop: Attribute) -> bool:
|
||||
if "Date" in prop.name or "Time" in prop.name:
|
||||
if prop.is_null:
|
||||
attributes[prop.name] = None
|
||||
@@ -150,14 +152,16 @@ class Sequence(bonsai.core.tool.Sequence):
|
||||
return True
|
||||
attributes[prop.name] = helper.parse_duration(prop.string_value)
|
||||
return True
|
||||
return False
|
||||
|
||||
props = cls.get_work_schedule_props()
|
||||
return bonsai.bim.helper.export_attributes(props.work_schedule_attributes, callback)
|
||||
|
||||
@classmethod
|
||||
def load_work_schedule_attributes(cls, work_schedule: ifcopenshell.entity_instance) -> None:
|
||||
def callback(name, prop, data):
|
||||
def callback(name: str, prop: Union[Attribute, None], data: dict[str, Any]) -> None | Literal[True]:
|
||||
if name in ["CreationDate", "StartTime", "FinishTime"]:
|
||||
assert prop
|
||||
prop.string_value = "" if prop.is_null else data[name]
|
||||
return True
|
||||
|
||||
@@ -419,6 +423,7 @@ class Sequence(bonsai.core.tool.Sequence):
|
||||
duration_props[key] = value
|
||||
return True
|
||||
if isinstance(data[name], datetime):
|
||||
assert prop
|
||||
prop.string_value = "" if prop.is_null else data[name].isoformat()
|
||||
return True
|
||||
|
||||
@@ -635,13 +640,14 @@ class Sequence(bonsai.core.tool.Sequence):
|
||||
def get_work_time_attributes(cls) -> dict[str, Any]:
|
||||
import bonsai.bim.module.sequence.helper as helper
|
||||
|
||||
def callback(attributes, prop):
|
||||
def callback(attributes: dict[str, Any], prop: Attribute) -> bool:
|
||||
if "Start" in prop.name or "Finish" in prop.name:
|
||||
if prop.is_null:
|
||||
attributes[prop.name] = None
|
||||
return True
|
||||
attributes[prop.name] = helper.parse_datetime(prop.string_value)
|
||||
return True
|
||||
return False
|
||||
|
||||
props = bpy.context.scene.BIMWorkCalendarProperties
|
||||
return bonsai.bim.helper.export_attributes(props.work_time_attributes, callback)
|
||||
@@ -725,7 +731,7 @@ class Sequence(bonsai.core.tool.Sequence):
|
||||
def load_lag_time_attributes(cls, lag_time: ifcopenshell.entity_instance) -> None:
|
||||
props = cls.get_work_schedule_props()
|
||||
|
||||
def callback(name, prop, data):
|
||||
def callback(name: str, prop: Union[Attribute, None], data: dict[str, Any]) -> None | Literal[True]:
|
||||
if name == "LagValue":
|
||||
prop = props.lag_time_attributes.add()
|
||||
prop.name = name
|
||||
|
||||
@@ -161,7 +161,7 @@ class Structural(bonsai.core.tool.Structural):
|
||||
new.is_null = data[attribute.name()] is None
|
||||
new.is_optional = attribute.optional()
|
||||
if attribute.name() == "PredefinedType":
|
||||
new.enum_items = json.dumps(attribute.type_of_attribute().declared_type().enumeration_items())
|
||||
new.enum_items = json.dumps(ifcopenshell.util.attribute.get_enum_items(attribute))
|
||||
new.data_type = "enum"
|
||||
if data[attribute.name()]:
|
||||
new.enum_value = data[attribute.name()]
|
||||
|
||||
Reference in New Issue
Block a user