Skip to content

Commit

Permalink
Ctrl + LEFT_ARROW, RIGHT_ARROW allow selecting previous/next fixtures…
Browse files Browse the repository at this point in the history
… (even in groups)
  • Loading branch information
vanous committed Dec 17, 2023
1 parent 19e3375 commit 439a243
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 16 deletions.
37 changes: 37 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import time
import json
import uuid as py_uuid
import re

from dmx.pymvr import GeneralSceneDescription
from dmx.mvr import extract_mvr_textures, process_mvr_child_list
Expand Down Expand Up @@ -153,15 +154,30 @@ class DMX(PropertyGroup):
DMX_OT_Programmer_Unset_Ignore_Movement,
DMX_PT_DMX_OSC,
DMX_OT_Fixture_ForceRemove,
DMX_OT_Fixture_SelectNext,
DMX_OT_Fixture_SelectPrevious,
DMX_PT_Programmer)

linkedToFile = False
_keymaps = []

def register():
for cls in DMX.classes_setup:
bpy.utils.register_class(cls)

# register key shortcuts
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name='3D View Generic', space_type='VIEW_3D')
kmi = km.keymap_items.new('dmx.fixture_next', 'RIGHT_ARROW', 'PRESS', ctrl=True)
DMX._keymaps.append((km, kmi))
kmi = km.keymap_items.new('dmx.fixture_previous', 'LEFT_ARROW', 'PRESS', ctrl=True)
DMX._keymaps.append((km, kmi))

def unregister():
# unregister keymaps
for km, kmi in DMX._keymaps: km.keymap_items.remove(kmi)
DMX._keymaps.clear()

if (DMX.linkedToFile):
for cls in DMX.classes:
bpy.utils.unregister_class(cls)
Expand Down Expand Up @@ -1002,6 +1018,27 @@ def selectedFixtures(self):
break
return selected


def sortedFixtures(self):
def string_to_pairs(s, pairs=re.compile(r"(\D*)(\d*)").findall):
return [(text.lower(), int(digits or 0)) for (text, digits) in pairs(s)[:-1]]

sorting_order = self.fixtures_sorting_order

if sorting_order == "ADDRESS":
fixtures = sorted(self.fixtures, key=lambda c: string_to_pairs(str(c.universe*1000+c.address)))
elif sorting_order == "NAME":
fixtures = sorted(self.fixtures, key=lambda c: string_to_pairs(c.name))
elif sorting_order == "FIXTURE_ID":
fixtures = sorted(self.fixtures, key=lambda c: string_to_pairs(str(c.fixture_id)))
elif sorting_order == "UNIT_NUMBER":
fixtures = sorted(self.fixtures, key=lambda c: string_to_pairs(str(c.unit_number)))
else:
fixtures = self.fixtures

return fixtures


def addMVR(self, file_name):

bpy.app.handlers.depsgraph_update_post.clear()
Expand Down
5 changes: 4 additions & 1 deletion fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,8 @@ def get_mobile_type(self, mobile_type):


def get_root(self, model_collection):
if model_collection.objects is None:
return None
for obj in model_collection.objects:
if obj.get("geometry_root", False):
return obj
Expand Down Expand Up @@ -815,7 +817,8 @@ def select(self):

def unselect(self):
dmx = bpy.context.scene.dmx
self.objects["Root"].object.select_set(False)
if "Root" in self.objects:
self.objects["Root"].object.select_set(False)
if ('Target' in self.objects):
self.objects['Target'].object.select_set(False)
if "2D Symbol" in self.objects:
Expand Down
66 changes: 51 additions & 15 deletions panels/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,56 @@ def execute(self, context):

# Panel #

class DMX_OT_Fixture_SelectPrevious(Operator):
bl_label = " "
bl_idname = "dmx.fixture_previous"
bl_description = "Select Previous Fixture"
bl_options = {'UNDO'}

def execute(self, context):
scene = context.scene
dmx = scene.dmx
selected_all = dmx.selectedFixtures()
fixtures = dmx.sortedFixtures()

for fixture in fixtures:
fixture.unselect()

for selected in selected_all:
for idx, fixture in enumerate(fixtures):
if fixture == selected:
idx -= 1
if idx < 0:
idx = len(fixtures)-1
fixtures[idx].select()
break
return {'FINISHED'}

class DMX_OT_Fixture_SelectNext(Operator):
bl_label = " "
bl_idname = "dmx.fixture_next"
bl_description = "Select Next Fixture"
bl_options = {'UNDO'}

def execute(self, context):
scene = context.scene
dmx = scene.dmx
selected_all = dmx.selectedFixtures()
fixtures = dmx.sortedFixtures()

for fixture in fixtures:
fixture.unselect()

for selected in selected_all:
for idx, fixture in enumerate(fixtures):
if fixture == selected:
idx += 1
if idx > len(fixtures)-1:
idx = 0
fixtures[idx].select()
break
return {'FINISHED'}

class DMX_OT_Fixture_Item(Operator):
bl_label = "DMX > Fixture > Item"
bl_idname = "dmx.fixture_item"
Expand Down Expand Up @@ -543,28 +593,14 @@ class DMX_PT_Fixtures(Panel):
bl_context = "objectmode"

def draw(self, context):
def string_to_pairs(s, pairs=re.compile(r"(\D*)(\d*)").findall):
return [(text.lower(), int(digits or 0)) for (text, digits) in pairs(s)[:-1]]

layout = self.layout
scene = context.scene
dmx = scene.dmx

if (len(scene.dmx.fixtures)):
box = layout.box()
col = box.column()
sorting_order = dmx.fixtures_sorting_order

if sorting_order == "ADDRESS":
fixtures = sorted(dmx.fixtures, key=lambda c: string_to_pairs(str(c.universe*1000+c.address)))
elif sorting_order == "NAME":
fixtures = sorted(dmx.fixtures, key=lambda c: string_to_pairs(c.name))
elif sorting_order == "FIXTURE_ID":
fixtures = sorted(dmx.fixtures, key=lambda c: string_to_pairs(str(c.fixture_id)))
elif sorting_order == "UNIT_NUMBER":
fixtures = sorted(dmx.fixtures, key=lambda c: string_to_pairs(str(c.unit_number)))
else:
fixtures = dmx.fixtures
fixtures = dmx.sortedFixtures()

for fixture in fixtures:
selected = False
Expand Down

0 comments on commit 439a243

Please sign in to comment.