Newer
Older
layout.operator("view3d.create_all_qcd_slots")
layout.separator()
layout.operator("view3d.enable_all_qcd_slots")
layout.operator("view3d.enable_all_qcd_slots_isolated")
layout.separator()
layout.operator("view3d.isolate_selected_objects_collections")
if context.mode == 'OBJECT':
layout.operator("view3d.disable_selected_objects_collections")
layout.separator()
layout.operator("view3d.disable_all_non_qcd_slots")
layout.operator("view3d.disable_all_collections")
if context.mode == 'OBJECT':
layout.separator()
layout.operator("view3d.select_all_qcd_objects")
layout.separator()
layout.operator("view3d.discard_qcd_history")
def view3d_header_qcd_slots(self, context):
update_collection_tree(context)
view_layer = context.view_layer
layout = self.layout
idx = 1
check_state(context, qcd=True)
main_row = layout.row(align=True)
current_qcd_history = internals.qcd_history.get(context.view_layer.name, [])
main_row.operator_menu_hold("view3d.enable_all_qcd_slots_meta",
text="",
icon='HIDE_OFF',
depress=bool(current_qcd_history),
menu="VIEW3D_MT_CM_qcd_enable_all_menu")
split = main_row.split()
col = split.column(align=True)
row = col.row(align=True)
row.scale_y = 0.5
selected_objects = get_move_selection()
active_object = get_move_active()
qcd_slot_name = internals.qcd_slots.get_name(str(x+1))
qcd_laycol = internals.layer_collections[qcd_slot_name]["ptr"]
collection_objects = qcd_laycol.collection.objects
icon_value = 0
# if the active object is in the current collection use a custom icon
if (active_object and active_object in selected_objects and
active_object.name in collection_objects):
icon = 'LAYER_ACTIVE'
# if there are selected objects use LAYER_ACTIVE
elif not selected_objects.isdisjoint(collection_objects):
icon = 'LAYER_USED'
# If there are objects use LAYER_USED
elif collection_objects:
icon = 'NONE'
active_icon = get_active_icon(context, qcd_laycol)
icon_value = active_icon.icon_id
else:
icon = 'BLANK1'
prop = row.operator("view3d.view_move_qcd_slot", text="", icon=icon,
icon_value=icon_value, depress=not qcd_laycol.exclude)
prop.slot = str(x+1)
else:
prop = row.operator("view3d.unassigned_qcd_slot", text="", icon='X', emboss=False)
prop.slot = str(x+1)
if idx%5==0:
row.separator()
if idx == 10:
row = col.row(align=True)
row.scale_y = 0.5
idx += 1
def view_layer_update(self, context):
if context.view_layer.name != CollectionManager.last_view_layer:
bpy.app.timers.register(update_qcd_header)
CollectionManager.last_view_layer = context.view_layer.name
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
def get_active_icon(context, qcd_laycol):
global last_icon_theme_text
global last_icon_theme_text_sel
tool_theme = context.preferences.themes[0].user_interface.wcol_tool
pcoll = preview_collections["icons"]
if qcd_laycol.exclude:
theme_color = tool_theme.text
last_theme_color = last_icon_theme_text
icon = pcoll["active_icon_text"]
else:
theme_color = tool_theme.text_sel
last_theme_color = last_icon_theme_text_sel
icon = pcoll["active_icon_text_sel"]
if last_theme_color == None or theme_color.hsv != last_theme_color:
update_icon(pcoll["active_icon_base"], icon, theme_color)
if qcd_laycol.exclude:
last_icon_theme_text = theme_color.hsv
else:
last_icon_theme_text_sel = theme_color.hsv
return icon
def update_icon(base, icon, theme_color):
icon.icon_pixels = base.icon_pixels
colored_icon = []
for offset in range(len(icon.icon_pixels)):
idx = offset * 4
r = icon.icon_pixels_float[idx]
g = icon.icon_pixels_float[idx+1]
b = icon.icon_pixels_float[idx+2]
a = icon.icon_pixels_float[idx+3]
# add back some brightness and opacity blender takes away from the custom icon
r = min(r+r*0.2,1)
g = min(g+g*0.2,1)
b = min(b+b*0.2,1)
a = min(a+a*0.2,1)
# make the icon follow the theme color (assuming the icon is white)
r *= theme_color.r
g *= theme_color.g
b *= theme_color.b
colored_icon.append(r)
colored_icon.append(g)
colored_icon.append(b)
colored_icon.append(a)
icon.icon_pixels_float = colored_icon
def filter_items_by_name_custom(pattern, bitflag, items, propname="name", flags=None, reverse=False):
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
"""
Set FILTER_ITEM for items which name matches filter_name one (case-insensitive).
pattern is the filtering pattern.
propname is the name of the string property to use for filtering.
flags must be a list of integers the same length as items, or None!
return a list of flags (based on given flags if not None),
or an empty list if no flags were given and no filtering has been done.
"""
import fnmatch
if not pattern or not items: # Empty pattern or list = no filtering!
return flags or []
if flags is None:
flags = [0] * len(items)
# Make pattern case-insensitive
pattern = pattern.lower()
# Implicitly add heading/trailing wildcards.
pattern = "*" + pattern + "*"
for i, item in enumerate(items):
name = getattr(item, propname, None)
# Make name case-insensitive
name = name.lower()
# This is similar to a logical xor
if bool(name and fnmatch.fnmatch(name, pattern)) is not bool(reverse):
flags[i] |= bitflag
# add in any recently created collections
if item.name in CM_UL_items.new_collections:
flags[i] |= bitflag