Skip to content

Commit 7fa6cc8

Browse files
committed
Rework Fixture Name to be not dependent on PropertyGroup
1 parent 3121742 commit 7fa6cc8

File tree

7 files changed

+117
-88
lines changed

7 files changed

+117
-88
lines changed

dmx.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ def reset_live_dmx_data(self, context):
480480

481481
data_version: IntProperty(
482482
name = "BlenderDMX data version, bump when changing RNA structure and provide migration script",
483-
default = 12,
483+
default = 13,
484484
)
485485

486486
def get_fixture_by_index(self, index):
@@ -957,6 +957,14 @@ def findGroupUuidDuplicates(uuid):
957957
del fixture_["address"]
958958
del fixture_["universe"]
959959

960+
if file_data_version < 13:
961+
DMX_Log.log.info("Running migration 12→13")
962+
dmx = bpy.context.scene.dmx
963+
964+
# we added proper fixture name
965+
for fixture_ in dmx.fixtures:
966+
fixture_.user_fixture_name = fixture_.name
967+
960968
# add here another if statement for next migration condition... like:
961969
# if file_data_version < 6:
962970
# ...
@@ -991,7 +999,7 @@ def onDisplayLabel(self, context):
991999
if self.display_device_label == "NONE":
9921000
obj.show_name = False
9931001
elif self.display_device_label == "NAME":
994-
obj.name = f"{fixture_.name}"
1002+
obj.name = f"{fixture_.user_fixture_name}"
9951003
obj.show_name = self.enable_device_label
9961004
elif self.display_device_label == "DMX":
9971005
obj.name = f"{fixture_.dmx_breaks[0].universe}.{fixture_.dmx_breaks[0].address}"
@@ -1044,7 +1052,7 @@ def onDisplay2D(self, context):
10441052
if self.display_device_label == "NONE":
10451053
obj.show_name = False
10461054
elif self.display_device_label == "NAME":
1047-
obj.name = f"{fixture_.name}"
1055+
obj.name = f"{fixture_.user_fixture_name}"
10481056
obj.show_name = True
10491057
elif self.display_device_label == "DMX":
10501058
obj.name = f"{fixture_.dmx_breaks[0].universe}.{fixture_.dmx_breaks[0].address}"
@@ -2020,7 +2028,6 @@ def syncProgrammer(self):
20202028
# # Fixtures
20212029
def addFixture(
20222030
self,
2023-
name,
20242031
profile,
20252032
mode,
20262033
dmx_breaks,
@@ -2035,14 +2042,14 @@ def addFixture(
20352042
fixture_id_numeric=0,
20362043
unit_number=0,
20372044
classing=None,
2045+
user_fixture_name="",
20382046
):
20392047
# TODO: fix order of attributes to match fixture.build()
20402048
dmx = bpy.context.scene.dmx
20412049
new_fixture = dmx.fixtures.add()
20422050
new_fixture.uuid = str(py_uuid.uuid4()) # ensure clean uuid
20432051
try:
20442052
new_fixture.build(
2045-
name,
20462053
profile,
20472054
mode,
20482055
dmx_breaks,
@@ -2057,6 +2064,7 @@ def addFixture(
20572064
fixture_id_numeric,
20582065
unit_number,
20592066
classing=classing,
2067+
user_fixture_name=user_fixture_name,
20602068
)
20612069
except Exception as e:
20622070
DMX_Log.log.error(f"Error while adding fixture {e}")

fixture.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
getGeometryNodes,
5858
set_light_nodes,
5959
)
60+
from .util import generate_fixture_name
6061
from .model import DMX_Model
6162
from .osc_utils import DMX_OSC_Handlers
6263
from .color_utils import (
@@ -413,6 +414,18 @@ class DMX_Fixture(PropertyGroup):
413414
type = DMX_Fixture_Channel
414415
)
415416

417+
user_fixture_name: StringProperty(
418+
name = "Fixture name",
419+
description="User definable fixture name, can be non-unique, is for MVR export and all UI",
420+
default = "")
421+
422+
name: StringProperty(
423+
name = "Collection name",
424+
description="Not for the user",
425+
default = "")
426+
# this used to be the fixture name, we now only use it for the collection and we rename it
427+
# if the gdtf_profile changes
428+
416429
gdtf_long_name: StringProperty(
417430
name = "Fixture > Name",
418431
default = "")
@@ -515,7 +528,6 @@ def on_use_target(self, context):
515528

516529
def build(
517530
self,
518-
name,
519531
profile,
520532
mode,
521533
dmx_breaks,
@@ -530,6 +542,7 @@ def build(
530542
fixture_id_numeric=0,
531543
unit_number=0,
532544
classing="",
545+
user_fixture_name="",
533546
):
534547
bpy.ops.object.select_all(action="DESELECT")
535548
for obj in bpy.data.objects:
@@ -548,8 +561,7 @@ def build(
548561
bpy.data.collections.remove(bpy.data.collections[self.name])
549562

550563
# Data Properties
551-
self.name = name
552-
self.profile = profile
564+
553565
self.mode = mode
554566
if fixture_id is not None:
555567
self.fixture_id = fixture_id
@@ -588,13 +600,24 @@ def build(
588600
self["blender_control_playmode"] = None
589601
self["blender_control_recording"] = None
590602

591-
# Create clean Collection
592-
self.collection = bpy.data.collections.new(name)
593-
594603
# Import and deep copy Fixture Model Collection
595604
gdtf_profile = DMX_GDTF_File.load_gdtf_profile(profile)
596605
self.gdtf_long_name = gdtf_profile.long_name
597606
self.gdtf_manufacturer = gdtf_profile.manufacturer
607+
if user_fixture_name is None:
608+
user_fixture_name = gdtf_profile.name
609+
610+
self.user_fixture_name = user_fixture_name
611+
612+
regenerate_name = self.profile is not None and self.profile != profile
613+
614+
self.profile = profile
615+
616+
if self.name is None or regenerate_name:
617+
self.name = generate_fixture_name(gdtf_profile.name)
618+
619+
# Create clean Collection
620+
self.collection = bpy.data.collections.new(self.name)
598621

599622
# Handle if dmx mode doesn't exist (maybe this is MVR import and GDTF files were replaced)
600623
# use mode[0] as default
@@ -2750,7 +2773,7 @@ def to_mvr_fixture(self, universe_add=False):
27502773
]
27512774

27522775
return pymvr.Fixture(
2753-
name=self.name,
2776+
name=self.user_fixture_name,
27542777
uuid=self.uuid,
27552778
gdtf_spec=self.profile,
27562779
gdtf_mode=self.mode,
@@ -2775,7 +2798,7 @@ def focus_to_mvr_focus_point(self):
27752798
return pymvr.FocusPoint(
27762799
matrix=pymvr.Matrix(matrix),
27772800
uuid=uuid_,
2778-
name=f"Target for {self.name}",
2801+
name=f"Target for {self.user_fixture_name}",
27792802
)
27802803

27812804
def follow_target_constraint_enable(self, enabled):

in_gdtf.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
from .i18n import DMX_Lang
3838
from .panels import profiles as Profiles
39-
from .util import create_unique_fixture_name
4039
from .gdtf_file import DMX_GDTF_File
4140
from .logging_setup import DMX_Log
4241

@@ -232,17 +231,15 @@ def execute(self, context):
232231
new_break.channels_count = 0
233232

234233
for count in range(1, 1 + self.units):
235-
new_name = f"{profile.name} {count}"
236-
new_name = create_unique_fixture_name(new_name)
237234
dmx.addFixture(
238-
new_name,
239235
file.name,
240236
dmx_mode.name,
241237
self.dmx_breaks,
242238
self.gel_color,
243239
self.display_beams,
244240
self.add_target,
245241
fixture_id=fixture_id,
242+
user_fixture_name=None,
246243
)
247244
fixture = dmx.fixtures[-1]
248245
DMX_Log.log.debug(f"Added fixture {fixture}")

mvr.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
from .group import FixtureGroup
3333
from .logging_setup import DMX_Log
34-
from .util import create_unique_fixture_name
3534
from .color_utils import xyY2rgbaa
3635

3736
auxData = {}
@@ -784,16 +783,12 @@ def add_mvr_fixture(
784783
fixture_matrix = get_matrix(fixture, mscale)
785784

786785
if existing_fixture is not None:
787-
# TODO: we should not rename the fixture on import unless if the user wants it
788-
# but we must ensure that the name is unique in the collection
789-
unique_name = create_unique_fixture_name(fixture.name)
790786
if isinstance(fixture.color, str):
791787
fixture.color = pymvr.Color(str_repr=fixture.color)
792788

793789
color_rgb = xyY2rgbaa(fixture.color)
794790
gel_color = [c / 255 for c in color_rgb] + [1]
795791
existing_fixture.build(
796-
unique_name,
797792
fixture.gdtf_spec,
798793
fixture.gdtf_mode or "",
799794
addresses,
@@ -808,16 +803,14 @@ def add_mvr_fixture(
808803
fixture_id_numeric=fixture.fixture_id_numeric,
809804
unit_number=fixture.unit_number,
810805
classing=fixture.classing,
806+
user_fixture_name=fixture.name,
811807
)
812808
else:
813-
unique_name = f"{fixture.name} {layer_idx}-{fixture_idx}"
814-
unique_name = create_unique_fixture_name(unique_name)
815809
if isinstance(fixture.color, str):
816810
fixture.color = pymvr.Color(str_repr=fixture.color)
817811
color_rgb = xyY2rgbaa(fixture.color)
818812
gel_color = [c / 255 for c in color_rgb] + [1]
819813
dmx.addFixture(
820-
unique_name,
821814
fixture.gdtf_spec,
822815
fixture.gdtf_mode or "",
823816
addresses,
@@ -832,6 +825,7 @@ def add_mvr_fixture(
832825
fixture_id_numeric=fixture.fixture_id_numeric,
833826
unit_number=fixture.unit_number,
834827
classing=fixture.classing,
828+
user_fixture_name=fixture.name,
835829
)
836830

837831
if parent_object is not None:

0 commit comments

Comments
 (0)