2022-04-08 21:50:31 +08:00
|
|
|
import bpy
|
|
|
|
from . import UTILS_constants, UTILS_functions, UTILS_virtools_prop
|
|
|
|
|
2022-12-30 10:06:02 +08:00
|
|
|
class BALLANCE_OT_add_virtools_group(UTILS_virtools_prop.common_group_name_props):
|
2022-04-08 21:50:31 +08:00
|
|
|
"""Add a Virtools Group for Active Object."""
|
|
|
|
bl_idname = "ballance.add_virtools_group"
|
|
|
|
bl_label = "Add Virtools Group"
|
|
|
|
bl_options = {'UNDO'}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(self, context):
|
|
|
|
return context.object is not None
|
|
|
|
|
|
|
|
def execute(self, context):
|
2022-11-19 14:30:31 +08:00
|
|
|
# try adding
|
2022-04-08 21:50:31 +08:00
|
|
|
obj = context.object
|
2022-12-30 10:06:02 +08:00
|
|
|
if not UTILS_virtools_prop.add_virtools_group_data(obj, self.get_group_name_string()):
|
2022-11-19 14:30:31 +08:00
|
|
|
UTILS_functions.show_message_box(("Group name is duplicated!", ), "Duplicated Name", 'ERROR')
|
2022-04-09 14:41:32 +08:00
|
|
|
|
2022-04-08 21:50:31 +08:00
|
|
|
return {'FINISHED'}
|
2022-12-30 10:06:02 +08:00
|
|
|
|
2022-04-12 15:40:06 +08:00
|
|
|
def draw(self, context):
|
2022-12-30 10:06:02 +08:00
|
|
|
self.parent_draw(self.layout)
|
2022-11-19 14:30:31 +08:00
|
|
|
|
2022-04-12 15:40:06 +08:00
|
|
|
|
2022-04-08 21:50:31 +08:00
|
|
|
class BALLANCE_OT_rm_virtools_group(bpy.types.Operator):
|
|
|
|
"""Remove a Virtools Group for Active Object."""
|
|
|
|
bl_idname = "ballance.rm_virtools_group"
|
|
|
|
bl_label = "Remove Virtools Group"
|
|
|
|
bl_options = {'UNDO'}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(self, context):
|
2022-04-09 14:41:32 +08:00
|
|
|
if context.object is None:
|
|
|
|
return False
|
2022-04-08 21:50:31 +08:00
|
|
|
|
|
|
|
obj = context.object
|
2022-04-09 14:41:32 +08:00
|
|
|
gp = UTILS_virtools_prop.get_virtools_group(obj)
|
|
|
|
active_gp = UTILS_virtools_prop.get_active_virtools_group(obj)
|
2022-11-19 14:30:31 +08:00
|
|
|
return int(active_gp) >= 0 and int(active_gp) < len(gp)
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
obj = context.object
|
|
|
|
UTILS_virtools_prop.remove_virtools_group_data_by_index(obj, int(UTILS_virtools_prop.get_active_virtools_group(obj)))
|
2022-04-08 21:50:31 +08:00
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
class BALLANCE_UL_virtools_group(bpy.types.UIList):
|
|
|
|
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
2022-04-09 14:41:32 +08:00
|
|
|
layout.prop(item, 'group_name', icon='GROUP', emboss=False, text="")
|
2022-04-08 21:50:31 +08:00
|
|
|
|
|
|
|
class BALLANCE_PT_virtools_group(bpy.types.Panel):
|
|
|
|
"""Show Virtools Group Properties."""
|
|
|
|
bl_label = "Virtools Group"
|
|
|
|
bl_idname = "BALLANCE_PT_virtools_group"
|
|
|
|
bl_space_type = 'PROPERTIES'
|
|
|
|
bl_region_type = 'WINDOW'
|
|
|
|
bl_context = "object"
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
return context.object is not None
|
|
|
|
|
|
|
|
def draw(self, context):
|
|
|
|
layout = self.layout
|
|
|
|
target = bpy.context.active_object
|
|
|
|
|
|
|
|
row = layout.row()
|
|
|
|
row.template_list("BALLANCE_UL_virtools_group", "", target, "virtools_group",
|
|
|
|
target, "active_virtools_group")
|
|
|
|
|
|
|
|
col = row.column(align=True)
|
|
|
|
col.operator(BALLANCE_OT_add_virtools_group.bl_idname, icon='ADD', text="")
|
|
|
|
col.operator(BALLANCE_OT_rm_virtools_group.bl_idname, icon='REMOVE', text="")
|