Reuse draw_attributes for groups, layers, structures and systems

This commit is contained in:
Andrej730
2025-01-24 16:31:45 +05:00
parent f3fc55f246
commit d5b1b6f66a
5 changed files with 16 additions and 34 deletions
+3 -1
View File
@@ -54,7 +54,9 @@ def draw_attributes(
popup_active_attribute: Optional[bonsai.bim.prop.Attribute] = None, popup_active_attribute: Optional[bonsai.bim.prop.Attribute] = None,
callback: Optional[Callable[[bonsai.bim.prop.Attribute, bpy.types.UILayout], None]] = None, callback: Optional[Callable[[bonsai.bim.prop.Attribute, bpy.types.UILayout], None]] = None,
) -> None: ) -> None:
"""you can set attribute active in popup with `active_attribute` """Draw editable UI for prop.Attributes.
You can set attribute active in popup with `active_attribute`
meaning you will be able to type into attribute's field without having to click meaning you will be able to type into attribute's field without having to click
on it first on it first
""" """
+4 -6
View File
@@ -16,8 +16,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>. # along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
import bpy
from bpy.types import Panel, UIList from bpy.types import Panel, UIList
from bonsai.bim.ifc import IfcStore from bonsai.bim.ifc import IfcStore
from bonsai.bim.helper import draw_attributes
from bonsai.bim.module.group.data import GroupsData, ObjectGroupsData from bonsai.bim.module.group.data import GroupsData, ObjectGroupsData
@@ -60,12 +62,8 @@ class BIM_PT_groups(Panel):
if self.props.active_group_id: if self.props.active_group_id:
self.draw_editable_ui(context) self.draw_editable_ui(context)
def draw_editable_ui(self, context): def draw_editable_ui(self, context: bpy.types.Context) -> None:
for attribute in self.props.group_attributes: draw_attributes(self.props.group_attributes, self.layout)
row = self.layout.row(align=True)
row.prop(attribute, "string_value", text=attribute.name)
if attribute.is_optional:
row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
class BIM_PT_object_groups(Panel): class BIM_PT_object_groups(Panel):
+4 -6
View File
@@ -16,8 +16,10 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>. # along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
import bpy
from bpy.types import Panel, UIList, Mesh from bpy.types import Panel, UIList, Mesh
from bonsai.bim.ifc import IfcStore from bonsai.bim.ifc import IfcStore
from bonsai.bim.helper import draw_attributes
from bonsai.bim.module.layer.data import LayersData from bonsai.bim.module.layer.data import LayersData
@@ -61,12 +63,8 @@ class BIM_PT_layers(Panel):
if self.props.active_layer_id: if self.props.active_layer_id:
self.draw_editable_ui(context) self.draw_editable_ui(context)
def draw_editable_ui(self, context): def draw_editable_ui(self, context: bpy.types.Context) -> None:
for attribute in self.props.layer_attributes: draw_attributes(self.props.layer_attributes, self.layout)
row = self.layout.row(align=True)
row.prop(attribute, "string_value", text=attribute.name)
if attribute.is_optional:
row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
class BIM_UL_layers(UIList): class BIM_UL_layers(UIList):
+2 -14
View File
@@ -59,20 +59,8 @@ def draw_boundary_condition_ui(layout, boundary_condition, connection_id, props)
draw_boundary_condition_read_only_ui(layout, boundary_condition) draw_boundary_condition_read_only_ui(layout, boundary_condition)
def draw_boundary_condition_editable_ui(layout, props): def draw_boundary_condition_editable_ui(layout: bpy.types.UILayout, props: bpy.types.PropertyGroup) -> None:
for attribute in props.boundary_condition_attributes: draw_attributes(props.boundary_condition_attributes, layout)
if attribute.data_type == "string":
row = layout.row()
row.prop(attribute, "string_value", text=attribute["name"])
else:
row = layout.row(align=True)
row.prop(attribute, "enum_value", text=attribute["name"])
if attribute.enum_value == "IfcBoolean":
row.prop(attribute, "bool_value", text="")
else:
row.prop(attribute, "float_value", text="")
if attribute.is_optional:
row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
def draw_boundary_condition_read_only_ui(layout, boundary_condition): def draw_boundary_condition_read_only_ui(layout, boundary_condition):
+3 -7
View File
@@ -19,7 +19,7 @@
import bpy import bpy
import bonsai.bim.helper import bonsai.bim.helper
import bonsai.tool as tool import bonsai.tool as tool
from bonsai.bim.helper import prop_with_search from bonsai.bim.helper import prop_with_search, draw_attributes
from bpy.types import Panel, UIList from bpy.types import Panel, UIList
from bonsai.bim.module.system.data import SystemData, ZonesData, ActiveObjectZonesData, ObjectSystemData, PortData from bonsai.bim.module.system.data import SystemData, ZonesData, ActiveObjectZonesData, ObjectSystemData, PortData
@@ -113,12 +113,8 @@ class BIM_PT_systems(Panel):
if self.props.edited_system_id: if self.props.edited_system_id:
self.draw_editable_ui(context) self.draw_editable_ui(context)
def draw_editable_ui(self, context): def draw_editable_ui(self, context: bpy.types.Context) -> None:
for attribute in self.props.system_attributes: draw_attributes(self.props.system_attributes, self.layout)
row = self.layout.row(align=True)
row.prop(attribute, "string_value", text=attribute.name)
if attribute.is_optional:
row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
class BIM_PT_ports(Panel): class BIM_PT_ports(Panel):