mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-27 10:51:13 +00:00
Date picker UI for IfcDate type attributes
Example - https://imgchest.com/p/5xy2bekl3yl set_prop_from_path method got from https://blenderartists.org/t/set-property-using-path-from-path-from-id-prop-path-resolve/1559166
This commit is contained in:
@@ -95,6 +95,10 @@ def draw_attribute(
|
|||||||
if attribute.is_uri:
|
if attribute.is_uri:
|
||||||
op = layout.operator("bim.select_uri_attribute", text="", icon="FILE_FOLDER")
|
op = layout.operator("bim.select_uri_attribute", text="", icon="FILE_FOLDER")
|
||||||
op.data_path = attribute.path_from_id("string_value")
|
op.data_path = attribute.path_from_id("string_value")
|
||||||
|
elif attribute.special_type == "DATE":
|
||||||
|
op = layout.operator("bim.datepicker", text="", icon="TIME")
|
||||||
|
op.target_prop = attribute.path_from_id("string_value")
|
||||||
|
|
||||||
if attribute.is_optional:
|
if attribute.is_optional:
|
||||||
layout.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
|
layout.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
|
||||||
|
|
||||||
@@ -161,6 +165,8 @@ def import_attribute(
|
|||||||
new.string_value = "" if new.is_null else str(data[attribute.name()]).replace("\n", "\\n")
|
new.string_value = "" if new.is_null else str(data[attribute.name()]).replace("\n", "\\n")
|
||||||
if attribute.type_of_attribute().declared_type().name() == "IfcURIReference":
|
if attribute.type_of_attribute().declared_type().name() == "IfcURIReference":
|
||||||
new.is_uri = True
|
new.is_uri = True
|
||||||
|
elif attribute.type_of_attribute()._is("IfcDate"):
|
||||||
|
new.special_type = "DATE"
|
||||||
elif data_type == "boolean":
|
elif data_type == "boolean":
|
||||||
new.bool_value = False if new.is_null else bool(data[attribute.name()])
|
new.bool_value = False if new.is_null else bool(data[attribute.name()])
|
||||||
elif data_type == "integer":
|
elif data_type == "integer":
|
||||||
|
|||||||
@@ -1215,17 +1215,13 @@ class Bonsai_DatePicker(bpy.types.Operator):
|
|||||||
context.scene.DatePickerProperties.selected_date = self.display_date
|
context.scene.DatePickerProperties.selected_date = self.display_date
|
||||||
return context.window_manager.invoke_props_dialog(self)
|
return context.window_manager.invoke_props_dialog(self)
|
||||||
|
|
||||||
def get_scene_prop(self, prop_path):
|
def get_scene_prop(self, prop_path: str) -> str:
|
||||||
prop = bpy.context.scene.get(prop_path.split(".")[0])
|
scene = bpy.context.scene
|
||||||
for part in prop_path.split(".")[1:]:
|
return scene.path_resolve(prop_path)
|
||||||
if part:
|
|
||||||
prop = prop.get(part)
|
|
||||||
return prop
|
|
||||||
|
|
||||||
def set_scene_prop(self, prop_path, value):
|
def set_scene_prop(self, prop_path: str, value: str) -> None:
|
||||||
parent = self.get_scene_prop(prop_path[: prop_path.rfind(".")])
|
scene = bpy.context.scene
|
||||||
prop = prop_path.split(".")[-1]
|
tool.Blender.set_prop_from_path(scene, prop_path, value)
|
||||||
parent[prop] = value
|
|
||||||
|
|
||||||
|
|
||||||
class Bonsai_DatePickerSetDate(bpy.types.Operator):
|
class Bonsai_DatePickerSetDate(bpy.types.Operator):
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import importlib
|
|||||||
from mathutils import Vector
|
from mathutils import Vector
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from bonsai.bim.ifc import IFC_CONNECTED_TYPE
|
from bonsai.bim.ifc import IFC_CONNECTED_TYPE
|
||||||
from typing import Any, Optional, Union, Literal, Iterable, Callable
|
from typing import Any, Optional, Union, Literal, Iterable, Callable, TypeVar
|
||||||
from typing_extensions import assert_never
|
from typing_extensions import assert_never
|
||||||
|
|
||||||
|
|
||||||
@@ -1257,3 +1257,18 @@ class Blender(bonsai.core.tool.Blender):
|
|||||||
obj.constraints.clear()
|
obj.constraints.clear()
|
||||||
obj.matrix_world = matrix
|
obj.matrix_world = matrix
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_prop_from_path(cls, bpy_object: bpy.types.bpy_struct, prop_path: str, value: Any) -> None:
|
||||||
|
"""Set `data_block` property value using path from `path_from_id`."""
|
||||||
|
|
||||||
|
T = TypeVar("T", bound=bpy.types.bpy_struct)
|
||||||
|
|
||||||
|
def path_resolve(obj: T, prop_path: str) -> tuple[T, str]:
|
||||||
|
if "." in prop_path:
|
||||||
|
extra_path, prop_path = prop_path.rsplit(".", 1)
|
||||||
|
obj = obj.path_resolve(extra_path)
|
||||||
|
return obj, prop_path
|
||||||
|
|
||||||
|
obj, path = path_resolve(bpy_object, prop_path)
|
||||||
|
setattr(obj, path, value)
|
||||||
|
|||||||
@@ -506,15 +506,10 @@ class Sequence(bonsai.core.tool.Sequence):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load_work_time_attributes(cls, work_time: ifcopenshell.entity_instance) -> None:
|
def load_work_time_attributes(cls, work_time: ifcopenshell.entity_instance) -> None:
|
||||||
def callback(name, prop, data):
|
|
||||||
if name in ["Start", "Finish"]:
|
|
||||||
prop.string_value = "" if prop.is_null else data[name]
|
|
||||||
return True
|
|
||||||
|
|
||||||
props = bpy.context.scene.BIMWorkCalendarProperties
|
props = bpy.context.scene.BIMWorkCalendarProperties
|
||||||
props.work_time_attributes.clear()
|
props.work_time_attributes.clear()
|
||||||
|
|
||||||
bonsai.bim.helper.import_attributes2(work_time, props.work_time_attributes, callback)
|
bonsai.bim.helper.import_attributes2(work_time, props.work_time_attributes)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def enable_editing_work_time(cls, work_time: ifcopenshell.entity_instance) -> None:
|
def enable_editing_work_time(cls, work_time: ifcopenshell.entity_instance) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user