-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathui.py
198 lines (151 loc) · 6.65 KB
/
ui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import bpy
from bpy.props import *
from bpy.types import Panel
from .operators_modal import *
from bpy.app.handlers import persistent
@persistent
def load_handler(dummy):
addon_prefs = bpy.context.preferences.addons[__package__.split('.')[
0]].preferences
addon_prefs.use_n_panel = addon_prefs.use_n_panel
return
def update_panel(self, context):
addon_prefs = bpy.context.preferences.addons[__package__.split('.')[
0]].preferences
if addon_prefs.use_n_panel:
ABN_PT_abnormal_panel.bl_category = 'BNPR Abnormal'
ABN_PT_abnormal_panel.bl_region_type = 'UI'
ABN_PT_abnormal_panel.menu_remove()
else:
ABN_PT_abnormal_panel.bl_category = ''
ABN_PT_abnormal_panel.bl_region_type = 'HEADER'
ABN_PT_abnormal_panel.menu_add()
try:
bpy.utils.unregister_class(ABN_PT_abnormal_panel)
except:
pass
bpy.utils.register_class(ABN_PT_abnormal_panel)
return
class ABN_OT_switch_panel_loc(Operator):
bl_idname = "abnormal.switch_panel_loc"
bl_label = ""
bl_options = {"REGISTER", "UNDO", "INTERNAL"}
bl_description = 'Switch location of Abnormal panel'
val: BoolProperty(default=True)
def execute(self, context):
addon_prefs = bpy.context.preferences.addons[__package__.split('.')[
0]].preferences
addon_prefs.use_n_panel = self.val
return {'FINISHED'}
class ABN_PT_abnormal_panel(Panel):
"""Creates a Panel in the scene context of the properties editor"""
# bl_label = "Tools"
bl_label = "BNPR Abnormal"
bl_space_type = 'VIEW_3D'
# bl_region_type = 'UI'
bl_region_type = 'HEADER'
# bl_category = 'BNPR Abnormal'
def draw(self, context):
layout = self.layout
data = bpy.data
addon_prefs = bpy.context.preferences.addons[__package__.split('.')[
0]].preferences
row = layout.row(align=True)
row.alignment = 'CENTER'
row.operator("abnormal.normal_editor_modal")
row.alignment = 'CENTER'
row.scale_y = 2
ob = context.active_object
if addon_prefs.object != '':
if addon_prefs.object in data.objects:
ob = data.objects[addon_prefs.object]
if ob != None:
row = layout.row(align=True)
row.alignment = 'CENTER'
row.prop_search(addon_prefs, 'vertex_group', ob,
'vertex_groups', text='Filter Vertex Group')
row.alignment = 'CENTER'
if bpy.app.version[0] >= 3 and bpy.app.version[1] >= 0:
row = layout.row(align=True)
row.alignment = 'CENTER'
row.prop_search(addon_prefs, 'attribute', ob.data,
'attributes', text='Face Corner Attribute')
row.alignment = 'CENTER'
row = layout.row(align=True)
row.alignment = 'CENTER'
row.operator("abnormal.convert_attr_to_norms")
row.alignment = 'CENTER'
row.scale_y = 2
row = layout.row(align=True)
row.alignment = 'CENTER'
row.operator("abnormal.store_norms_in_attr")
row.alignment = 'CENTER'
row.scale_y = 2
else:
row = layout.row(align=True)
row.alignment = 'CENTER'
row.prop_search(addon_prefs, 'vcol', ob.data,
'vertex_colors', text='Vertex Color')
row.alignment = 'CENTER'
row = layout.row(align=True)
row.alignment = 'CENTER'
row.operator("abnormal.convert_vcol_to_norms")
row.alignment = 'CENTER'
row.scale_y = 2
row = layout.row(align=True)
row.alignment = 'CENTER'
row.operator("abnormal.store_norms_in_vcol")
row.alignment = 'CENTER'
row.scale_y = 2
row = layout.row(align=True)
row.alignment = 'CENTER'
if addon_prefs.use_n_panel:
row.operator("abnormal.switch_panel_loc",
text='Move to Header Tab').val = False
else:
row.operator("abnormal.switch_panel_loc",
text='Move to N Panel Tab').val = True
row.alignment = 'CENTER'
row.scale_y = 1.5
#############################################################################
# the following two methods add/remove RF to/from the main 3D View menu
# NOTE: this is a total hack: hijacked the draw function!
@staticmethod
def menu_add():
# for more icon options, see:
# https://docs.blender.org/api/current/bpy.types.UILayout.html#bpy.types.UILayout.operator
ABN_PT_abnormal_panel.menu_remove()
ABN_PT_abnormal_panel._menu_original = bpy.types.VIEW3D_MT_editor_menus.draw_collapsible
def hijacked(context, layout):
obj = context.active_object
# mode_string = context.mode
# edit_object = context.edit_object
# gp_edit = obj and obj.mode in {'EDIT_GPENCIL', 'PAINT_GPENCIL', 'SCULPT_GPENCIL', 'WEIGHT_GPENCIL'}
ABN_PT_abnormal_panel._menu_original(context, layout)
# if context.mode in {'EDIT_MESH', 'OBJECT'}:
if context.mode in 'OBJECT':
row = layout.row(align=True)
# row.menu("ABN_PT_abnormal_panel", text="BNPR Abnormal")
row.popover(panel="ABN_PT_abnormal_panel",
text=ABN_PT_abnormal_panel.bl_label)
bpy.types.VIEW3D_MT_editor_menus.draw_collapsible = hijacked
@staticmethod
def menu_remove():
if not hasattr(ABN_PT_abnormal_panel, '_menu_original'):
return
bpy.types.VIEW3D_MT_editor_menus.draw_collapsible = ABN_PT_abnormal_panel._menu_original
del ABN_PT_abnormal_panel._menu_original
def register():
bpy.utils.register_class(ABN_OT_switch_panel_loc)
ABN_PT_abnormal_panel.bl_category = 'BNPR Abnormal'
ABN_PT_abnormal_panel.bl_region_type = 'UI'
ABN_PT_abnormal_panel.menu_remove()
bpy.utils.register_class(ABN_PT_abnormal_panel)
bpy.app.handlers.load_post.append(load_handler)
return
def unregister():
bpy.utils.unregister_class(ABN_OT_switch_panel_loc)
ABN_PT_abnormal_panel.menu_remove()
bpy.utils.unregister_class(ABN_PT_abnormal_panel)
bpy.app.handlers.load_post.remove(load_handler)
return