Add keymaps, specials menu and auto center view checkbox #3

Merged
dupoxy merged 10 commits from add-keymaps into main 2024-09-21 20:42:48 +02:00
Showing only changes of commit db0b1f22fb - Show all commits

View File

@ -23,6 +23,7 @@ class C3DB_OT_save(bpy.types.Operator):
item.rotation = context.scene.cursor.rotation_euler
# Select the 3D cursor currently saving from the list
context.scene.C3DB_3Dcursors_index = len(context.scene.C3DB_3Dcursors_collection) - 1
context.area.tag_redraw() # Add this line to refresh the UI
return {'FINISHED'}
class C3DB_OT_restore(bpy.types.Operator):
@ -40,6 +41,56 @@ class C3DB_OT_restore(bpy.types.Operator):
item = context.scene.C3DB_3Dcursors_collection[context.scene.C3DB_3Dcursors_index]
context.scene.cursor.location = item.location
context.scene.cursor.rotation_euler = item.rotation
context.area.tag_redraw() # Add this line to refresh the UI
return {'FINISHED'}
class C3DB_OT_restore_and_next(bpy.types.Operator):
"""Restore selected 3D Cursor and go to next in the list"""
bl_idname = "c3db.restore_and_next"
bl_label = "Load & next"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return bool(context.scene.C3DB_3Dcursors_collection) and len(context.scene.C3DB_3Dcursors_collection) > 1
def execute(self, context):
if context.scene.C3DB_3Dcursors_collection:
item = context.scene.C3DB_3Dcursors_collection[context.scene.C3DB_3Dcursors_index]
context.scene.cursor.location = item.location
context.scene.cursor.rotation_euler = item.rotation
# Select the next valid 3D cursor in the list
C3DB_3Dcursors_collection = context.scene.C3DB_3Dcursors_collection
C3DB_3Dcursors_index = context.scene.C3DB_3Dcursors_index
if C3DB_3Dcursors_index < len(C3DB_3Dcursors_collection) - 1:
context.scene.C3DB_3Dcursors_index = C3DB_3Dcursors_index + 1
elif C3DB_3Dcursors_index == len(C3DB_3Dcursors_collection) - 1:
context.scene.C3DB_3Dcursors_index = 0
context.area.tag_redraw() # Add this line to refresh the UI
return {'FINISHED'}
class C3DB_OT_restore_and_previous(bpy.types.Operator):
"""Restore selected 3D Cursor and go to previous in the list"""
bl_idname = "c3db.restore_and_previous"
bl_label = "Load & previous"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return bool(context.scene.C3DB_3Dcursors_collection) and len(context.scene.C3DB_3Dcursors_collection) > 1
def execute(self, context):
if context.scene.C3DB_3Dcursors_collection:
item = context.scene.C3DB_3Dcursors_collection[context.scene.C3DB_3Dcursors_index]
context.scene.cursor.location = item.location
context.scene.cursor.rotation_euler = item.rotation
# Select the previous valid 3D cursor in the list
C3DB_3Dcursors_collection = context.scene.C3DB_3Dcursors_collection
C3DB_3Dcursors_index = context.scene.C3DB_3Dcursors_index
if C3DB_3Dcursors_index > 0:
context.scene.C3DB_3Dcursors_index = C3DB_3Dcursors_index - 1
elif C3DB_3Dcursors_index == 0:
context.scene.C3DB_3Dcursors_index = len(C3DB_3Dcursors_collection) - 1
context.area.tag_redraw() # Add this line to refresh the UI
return {'FINISHED'}
class C3DB_OT_remove_from_list(bpy.types.Operator):
@ -63,6 +114,7 @@ class C3DB_OT_remove_from_list(bpy.types.Operator):
context.scene.C3DB_3Dcursors_index = C3DB_3Dcursors_index
elif C3DB_3Dcursors_collection:
context.scene.C3DB_3Dcursors_index = len(C3DB_3Dcursors_collection) - 1
context.area.tag_redraw() # Add this line to refresh the UI
return {'FINISHED'}
class C3DB_OT_move_up_list(bpy.types.Operator):
@ -79,6 +131,7 @@ class C3DB_OT_move_up_list(bpy.types.Operator):
collection = context.scene.C3DB_3Dcursors_collection
collection.move(index, index - 1)
context.scene.C3DB_3Dcursors_index -= 1
context.area.tag_redraw() # Add this line to refresh the UI
return {'FINISHED'}
class C3DB_OT_move_down_list(bpy.types.Operator):
@ -95,6 +148,7 @@ class C3DB_OT_move_down_list(bpy.types.Operator):
collection = context.scene.C3DB_3Dcursors_collection
collection.move(index, index + 1)
context.scene.C3DB_3Dcursors_index += 1
context.area.tag_redraw() # Add this line to refresh the UI
return {'FINISHED'}
class C3DB_PT_panel(bpy.types.Panel):
@ -120,8 +174,12 @@ class C3DB_PT_panel(bpy.types.Panel):
row = layout.row()
row.operator("c3db.restore")
row.operator("view3d.view_center_cursor", text="Center View")
row = layout.row()
row.operator("c3db.restore_and_next")
row.operator("c3db.restore_and_previous")
classes = (C3DB_PG_properties, C3DB_UL_list, C3DB_OT_save, C3DB_OT_restore, C3DB_OT_remove_from_list, C3DB_OT_move_up_list, C3DB_OT_move_down_list, C3DB_PT_panel)
classes = (C3DB_PG_properties, C3DB_UL_list, C3DB_OT_save, C3DB_OT_restore, C3DB_OT_restore_and_next, C3DB_OT_restore_and_previous, C3DB_OT_remove_from_list, C3DB_OT_move_up_list, C3DB_OT_move_down_list, C3DB_PT_panel)
def register():
for cls in classes: