-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanels.py
401 lines (269 loc) · 14.7 KB
/
panels.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
import bpy
from . icons import i as icons
from . import misc_ot
from . import miscLay
from . import miscFunc
from bpy.props import (StringProperty, BoolProperty, IntProperty, FloatProperty, FloatVectorProperty, EnumProperty, PointerProperty)
from bpy.types import (Panel, Operator, AddonPreferences, PropertyGroup)
# -----------------------------------------------------------------------------
# Panel
# -----------------------------------------------------------------------------
class NTZSYM_PT_options(Panel):
bl_idname = "NTZSYM_PT_options"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_label = "Options"
def draw(self, context):
scn = context.scene
lay = self.layout
#determine if panel is inside of a popop/pie menu
panelInsidePopupOrPie = context.region.type == 'WINDOW'
miscLay.createPanelOptionsSection(self, context, scn, lay, panelInsidePopupOrPie=panelInsidePopupOrPie)
#END draw()
class NTZSYM_PT_optionscompactpopover(Panel):
bl_idname = "NTZSYM_PT_optionscompactpopover"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_label = "Options"
def draw(self, context):
scn = context.scene
lay = self.layout
miscLay.createPanelOptionsSection(self, context, scn, lay, panelInsidePopupOrPie=True)
#END draw()
class NTZSYM_PT_ntzsym(Panel):
bl_idname = "ntz_sym.panel"
bl_label = "Symmetry v1.0.1"
bl_category = "Neltulz"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bUseCompactSidebarPanel = BoolProperty(
name="Use Compact Panel",
description="Use Compact Panel",
default = False
)
bUseCompactPopupAndPiePanel = BoolProperty(
name="Use Compact Popup & Pie Panel",
description="Use Compact Popup & Pie Panel",
default = True
)
def draw(self, context):
scn = context.scene
lay = self.layout.column(align=True)
modeAtBegin = "OBJECT" #declare
try: modeAtBegin = bpy.context.object.mode
except: pass
selObjs = set(context.selected_objects)
activeObj = context.view_layer.objects.active
if modeAtBegin == "EDIT":
editModeObjs = set(bpy.context.objects_in_mode)
#combine selObjs and editModeObjs (useful for applying/removing modifiers in edit mode)
selObjs = selObjs.union(editModeObjs)
#determine if panel is inside of a popop/pie menu
panelInsidePopupOrPie = context.region.type == 'WINDOW'
if panelInsidePopupOrPie:
if self.bUseCompactPopupAndPiePanel:
lay.ui_units_x = 8
lay.label(text="Symmetry")
else:
lay.ui_units_x = 13
lay.label(text="Neltulz - Symmetry")
compactPanelConditions = (panelInsidePopupOrPie and self.bUseCompactPopupAndPiePanel) or (not panelInsidePopupOrPie and self.bUseCompactSidebarPanel)
if not compactPanelConditions:
sepFactor = 1
labelWidth = 2.75
else:
sepFactor = 0.25
labelWidth = 1.75
def opProperties(op, symType, axis, axisDir=None):
op.symType = symType
if not scn.ntzSym.cutLocation in ["UNSET"]: op.cutLocation = scn.ntzSym.cutLocation
if not scn.ntzSym.cutRotation in ["UNSET"]: op.cutRotation = scn.ntzSym.cutRotation
if scn.ntzSym.fillAfterCut == "FILL": op.use_fill = True
else: op.use_fill = False
if scn.ntzSym.keepModifiers == "YES": op.keepModifiers = True
else: op.keepModifiers = False
op.axis = axis
if axisDir is not None:
op.axisDir = axisDir
emboss=False
if not compactPanelConditions: labelHeight = 1.35
else: labelHeight = 1
# -----------------------------------------------------------------------------
# SLICE
# -----------------------------------------------------------------------------
sliceRow = lay.row(align=True)
sliceRowLabel = sliceRow.row(align=True)
sliceRowLabel.alignment="RIGHT"
sliceRowLabel.ui_units_x = labelWidth
sliceRowLabel.scale_y = labelHeight
if not compactPanelConditions: sliceRowLabel.label(text="Slice:")
else: sliceRowLabel.label(text="Slc:")
if not compactPanelConditions:
sliceRow = sliceRow.box()
sliceRowButtons = sliceRow.grid_flow(align=True, columns=3, even_columns=True, even_rows=True)
sliceRowButtons.scale_y = 1
# X (Slice)
#------------------------------------------------------------------------------------------------------
opRow = sliceRowButtons.grid_flow(align=True)
op = opRow.operator('ntz_sym.performsym', text='', icon_value=icons['xIcon'], emboss=emboss)
opProperties(op, "SLICE", "X")
op.tooltip = "Slice along the X axis"
# Y (Slice)
#------------------------------------------------------------------------------------------------------
opRow = sliceRowButtons.grid_flow(align=True)
op = opRow.operator('ntz_sym.performsym', text='', icon_value=icons['yIcon'], emboss=emboss)
opProperties(op, "SLICE", "Y")
op.tooltip = "Slice along the Y axis"
# Z (Slice)
#------------------------------------------------------------------------------------------------------
opRow = sliceRowButtons.grid_flow(align=True)
op = opRow.operator('ntz_sym.performsym', text='', icon_value=icons['zIcon'], emboss=emboss)
opProperties(op, "SLICE", "Z")
op.tooltip = "Slice along the Z axis"
lay.separator(factor=sepFactor)
# -----------------------------------------------------------------------------
# CUT
# -----------------------------------------------------------------------------
cutRow = lay.row(align=True)
cutRowLabel = cutRow.row(align=True)
cutRowLabel.alignment="RIGHT"
cutRowLabel.ui_units_x = labelWidth
cutRowLabel.scale_y = labelHeight
cutRowLabel.label(text="Cut:")
if not compactPanelConditions:
cutRow = cutRow.box()
cutRowButtons = cutRow.grid_flow(align=True, columns=3, even_columns=True, even_rows=True)
cutRowButtons.scale_y = 1
# X (Cut)
#------------------------------------------------------------------------------------------------------
xColRow = cutRowButtons.grid_flow(align=True, columns=2, even_columns=True)
op = xColRow.operator('ntz_sym.performsym', text='', icon_value=icons['xIconLeft'], emboss=emboss)
opProperties(op, "CUT", "X", axisDir="BACKWARD")
op.tooltip = "Cut backward along the X axis"
op = xColRow.operator('ntz_sym.performsym', text='', icon_value=icons['xIconRight'], emboss=emboss)
opProperties(op, "CUT", "X", axisDir="FORWARD")
op.tooltip = "Cut forward along the X axis"
# Y (Cut)
#------------------------------------------------------------------------------------------------------
yColRow = cutRowButtons.grid_flow(align=True, columns=2, even_columns=True)
op = yColRow.operator('ntz_sym.performsym', text='', icon_value=icons['yIconLeft'], emboss=emboss)
opProperties(op, "CUT", "Y", axisDir="BACKWARD")
op.tooltip = "Cut backward along the Y axis"
op = yColRow.operator('ntz_sym.performsym', text='', icon_value=icons['yIconRight'], emboss=emboss)
opProperties(op, "CUT", "Y", axisDir="FORWARD")
op.tooltip = "Cut forward along the Y axis"
# Z (Cut)
#------------------------------------------------------------------------------------------------------
zColRow = cutRowButtons.grid_flow(align=True, columns=2, even_columns=True)
op = zColRow.operator('ntz_sym.performsym', text='', icon_value=icons['zIconLeft'], emboss=emboss)
opProperties(op, "CUT", "Z", axisDir="BACKWARD")
op.tooltip = "Cut backward along the Z axis"
op = zColRow.operator('ntz_sym.performsym', text='', icon_value=icons['zIconRight'], emboss=emboss)
opProperties(op, "CUT", "Z", axisDir="FORWARD")
op.tooltip = "Cut forward along the Z axis"
lay.separator(factor=sepFactor)
# -----------------------------------------------------------------------------
# MIRROR
# -----------------------------------------------------------------------------
mirrorRow = lay.row(align=True)
mirrorRowLabel = mirrorRow.row(align=True)
mirrorRowLabel.alignment = "RIGHT"
mirrorRowLabel.ui_units_x = labelWidth
mirrorRowLabel.scale_y = labelHeight
if not compactPanelConditions: mirrorRowLabel.label(text="Mirror:")
else: mirrorRowLabel.label(text="Mir:")
if not compactPanelConditions:
mirrorRow = mirrorRow.box()
mirrorRowButtons = mirrorRow.grid_flow(align=True, columns=3, even_columns=True, even_rows=True)
mirrorRowButtons.scale_y = 1
# X (Mirror)
#------------------------------------------------------------------------------------------------------
xColRow = mirrorRowButtons.grid_flow(align=True, columns=2, even_columns=True)
op = xColRow.operator('ntz_sym.performsym', text='', icon_value=icons['xIconLeft'], emboss=emboss)
opProperties(op, "MIRROR", "X", axisDir="BACKWARD")
op.tooltip = "Mirror backward along the X axis. CTRL+Click to keep mirror modifier"
op = xColRow.operator('ntz_sym.performsym', text='', icon_value=icons['xIconRight'], emboss=emboss)
opProperties(op, "MIRROR", "X", axisDir="FORWARD")
op.tooltip = "Mirror forward along the X axis. CTRL+Click to keep mirror modifier"
# Y (Mirror)
#------------------------------------------------------------------------------------------------------
yColRow = mirrorRowButtons.grid_flow(align=True, columns=2, even_columns=True)
op = yColRow.operator('ntz_sym.performsym', text='', icon_value=icons['yIconLeft'], emboss=emboss)
opProperties(op, "MIRROR", "Y", axisDir="BACKWARD")
op.tooltip = "Mirror backward along the Y axis. CTRL+Click to keep mirror modifier"
op = yColRow.operator('ntz_sym.performsym', text='', icon_value=icons['yIconRight'], emboss=emboss)
opProperties(op, "MIRROR", "Y", axisDir="FORWARD")
op.tooltip = "Mirror forward along the Y axis. CTRL+Click to keep mirror modifier"
# Z (Mirror)
#------------------------------------------------------------------------------------------------------
zColRow = mirrorRowButtons.grid_flow(align=True, columns=2, even_columns=True)
op = zColRow.operator('ntz_sym.performsym', text='', icon_value=icons['zIconLeft'], emboss=emboss)
opProperties(op, "MIRROR", "Z", axisDir="BACKWARD")
op.tooltip = "Mirror backward along the Z axis. CTRL+Click to keep mirror modifier"
op = zColRow.operator('ntz_sym.performsym', text='', icon_value=icons['zIconRight'], emboss=emboss)
opProperties(op, "MIRROR", "Z", axisDir="FORWARD")
op.tooltip = "Mirror forward along the Z axis. CTRL+Click to keep mirror modifier"
# -----------------------------------------------------------------------------
# APPLY / REMOVE Mirror Modifiers
# -----------------------------------------------------------------------------
foundMirrorModifier = False #declare
for obj in selObjs:
if not foundMirrorModifier:
#check if mirrorParent exists on empty or bisectPlane
mirrorParent = getattr(obj, "mirrorParent", None)
if mirrorParent is not None:
foundMirrorModifier = True
break
#check if object has a mirror modifier
if miscFunc.findModifier(obj=obj, modifierType='MIRROR') is not None:
foundMirrorModifier = True
break
if foundMirrorModifier:
lay.separator(factor=sepFactor)
row = lay.row(align=True)
op = row.operator('ntz_sym.applyorremovemodifier', text='Apply', icon="CHECKMARK")
op.method = "APPLY"
op.tooltip = "Apply any mirror and bisect (boolean) modifiers from the selected objects. CTRL+Click to keep Empties & Bisect Planes"
op = row.operator('ntz_sym.applyorremovemodifier', text='Remove', icon="X")
op.method = "REMOVE"
op.tooltip = "Removes any mirror and bisect (boolean) modifiers from the selected objects. CTRL+Click to keep Empties & Bisect Planes"
# -----------------------------------------------------------------------------
# OPTIONS
# -----------------------------------------------------------------------------
lay.separator(factor=sepFactor)
optionsSection = lay.column(align=True)
if panelInsidePopupOrPie:
popoverRow = optionsSection.row(align=True)
popoverRow.scale_x = 1.2
popoverRow.alignment = "RIGHT"
if self.bUseCompactPopupAndPiePanel:
iconOnly = True
else:
iconOnly = False
popover = popoverRow.prop_with_popover(
scn.ntzSym,
"optionsPopoverEnum",
text="",
icon="SETTINGS",
icon_only=iconOnly,
panel="NTZSYM_PT_options",
)
elif (not panelInsidePopupOrPie and self.bUseCompactSidebarPanel):
popoverRow = optionsSection.row(align=True)
popoverRow.scale_x = 1.2
popoverRow.alignment = "CENTER"
popover = popoverRow.prop_with_popover(
scn.ntzSym,
"optionsPopoverEnum",
text="",
icon="SETTINGS",
icon_only=False,
panel="NTZSYM_PT_optionscompactpopover",
)
else:
#create show/hide toggle for options section
miscLay.createShowHide(self, context, scn, "ntzSym", "bShowOptions", None, "Options", optionsSection)
optionsSection.separator()
if scn.ntzSym.bShowOptions:
miscLay.createPanelOptionsSection(self, context, scn, lay, panelInsidePopupOrPie=panelInsidePopupOrPie)
#END draw()