Cleanup: remove "Tweak" event type
[blender-addons.git] / precision_drawing_tools / pdt_menus.py
blobe4b9b1098aa762a67c5d72a04944a8aff8699fc1
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 # -----------------------------------------------------------------------
4 # Author: Alan Odom (Clockmender), Rune Morling (ermo) Copyright (c) 2019
5 # -----------------------------------------------------------------------
7 import bpy
8 from bpy.types import Panel
9 from .pdt_msg_strings import (
10 PDT_LAB_ABS,
11 PDT_LAB_AD2D,
12 PDT_LAB_AD3D,
13 PDT_LAB_ALLACTIVE,
14 PDT_LAB_ANGLEVALUE,
15 PDT_LAB_ARCCENTRE,
16 PDT_LAB_BISECT,
17 PDT_LAB_CVALUE,
18 PDT_LAB_DEL,
19 PDT_LAB_DIR,
20 PDT_LAB_DISVALUE,
21 PDT_LAB_EDGETOEFACE,
22 PDT_LAB_FILLET,
23 PDT_LAB_FLIPANGLE,
24 PDT_LAB_FLIPPERCENT,
25 PDT_LAB_INTERSECT,
26 PDT_LAB_INTERSETALL,
27 PDT_LAB_JOIN2VERTS,
28 PDT_LAB_MODE,
29 PDT_LAB_NOR,
30 PDT_LAB_OPERATION,
31 PDT_LAB_ORDER,
32 PDT_LAB_ORIGINCURSOR,
33 PDT_LAB_PERCENT,
34 PDT_LAB_PERCENTS,
35 PDT_LAB_PIVOTALPHA,
36 PDT_LAB_PIVOTLOC,
37 PDT_LAB_PIVOTLOCH,
38 PDT_LAB_PIVOTSIZE,
39 PDT_LAB_PIVOTWIDTH,
40 PDT_LAB_PLANE,
41 PDT_LAB_PROFILE,
42 PDT_LAB_RADIUS,
43 PDT_LAB_SEGMENTS,
44 PDT_LAB_TAPER,
45 PDT_LAB_TAPERAXES,
46 PDT_LAB_TOOLS,
47 PDT_LAB_USEVERTS,
48 PDT_LAB_VARIABLES,
49 PDT_LAB_VIEW
52 def ui_width():
53 """Return the Width of the UI Panel.
55 Args:
56 None.
58 Returns:
59 UI Width.
60 """
62 area = bpy.context.area
63 resolution = bpy.context.preferences.system.ui_scale
65 for reg in area.regions:
66 if reg.type == "UI":
67 region_width = reg.width
68 return region_width
70 # PDT Panel menus
72 class PDT_PT_PanelDesign(Panel):
73 bl_idname = "PDT_PT_PanelDesign"
74 bl_label = "PDT Design Operations"
75 bl_space_type = "VIEW_3D"
76 bl_region_type = "UI"
77 bl_category = "PDT"
78 bl_options = {'DEFAULT_CLOSED'}
80 def draw(self, context):
81 ui_cutoff = bpy.context.preferences.addons[__package__].preferences.pdt_ui_width
82 layout = self.layout
83 pdt_pg = context.scene.pdt_pg
85 # Working Plane
86 row = layout.row()
87 row.label(text=f"Working {PDT_LAB_PLANE}:")
88 row.prop(pdt_pg, "plane", text="")
90 # Move Mode
91 row = layout.row()
92 row.label(text=f"Move {PDT_LAB_MODE}:")
93 row.prop(pdt_pg, "select", text="")
95 # Active or All Selected
96 row = layout.row()
97 #row.label(text="")
98 row.prop(pdt_pg, "extend", text="All Selected Entities (Off: Active Only)")
100 # --------------------
101 # (1) Select Operation
102 row = layout.row()
103 box_1 = row.box()
104 row = box_1.row()
105 row.label(text=f"(1) Select {PDT_LAB_OPERATION}:")
106 row.prop(pdt_pg, "operation", text="")
108 # -----------------------
109 # (a) Set Coordinates box
110 row = box_1.row()
111 box_1a = row.box()
112 box_1a.label(text=f"(a) Either Set Coordinates + [Place »]")
113 # ^ was PDT_LAB_VARIABLES
115 # cartesian input coordinates in a box
116 row = box_1a.row()
117 box = row.box()
118 row = box.row()
119 split = row.split(factor=0.35, align=True)
120 split.label(text=PDT_LAB_CVALUE)
121 split.prop(pdt_pg, "cartesian_coords", text="")
122 row = box.row()
123 row.operator("pdt.absolute", icon="EMPTY_AXIS", text=f"{PDT_LAB_ABS} »")
124 row.operator("pdt.delta", icon="EMPTY_AXIS", text=f"{PDT_LAB_DEL} »")
126 # directional input coordinates in a box
127 row = box_1a.row()
128 box = row.box()
129 #box.label(text="Directional/Polar Coordinates:")
130 row = box.row()
131 row.prop(pdt_pg, "distance", text=PDT_LAB_DISVALUE)
132 row.prop(pdt_pg, "angle", text=PDT_LAB_ANGLEVALUE)
133 row = box.row()
134 row.operator("pdt.distance", icon="EMPTY_AXIS", text=f"{PDT_LAB_DIR} »")
135 row.operator("pdt.view_axis", icon="EMPTY_AXIS", text=f"{PDT_LAB_VIEW} »")
136 row = box.row()
137 row.prop(pdt_pg, "flip_angle", text=PDT_LAB_FLIPANGLE)
139 # ---------------------
140 # (b) Miscellaneous box
141 row = box_1.row()
142 box_1b = row.box()
143 box_1b.label(text="(b) Or Select |n| Entities + [Place »]")
145 # normal or arc centre
146 row = box_1b.row()
147 row.operator("pdt.normal", text=f"|3| {PDT_LAB_NOR} »")
148 row.operator("pdt.centre", text=f"|3| {PDT_LAB_ARCCENTRE} »")
150 # Intersect
151 box = box_1b.box()
152 row = box.row()
153 row.operator("pdt.intersect", text=f"|4| {PDT_LAB_INTERSECT} »")
154 if ui_width() < ui_cutoff:
155 row = box.row()
156 row.prop(pdt_pg, "object_order", text=PDT_LAB_ORDER)
158 # percentage row
159 row = box_1b.row()
160 box = row.box()
161 box.label(text=f"Do (1) at % between selected points")
162 row = box.row()
163 row.operator("pdt.percent", text=f"|2| % »")
164 row.prop(pdt_pg, "percent", text=PDT_LAB_PERCENTS)
165 if ui_width() < ui_cutoff:
166 row = box.row()
167 row.prop(pdt_pg, "flip_percent", text=PDT_LAB_FLIPPERCENT)
169 class PDT_PT_PanelTools(Panel):
170 bl_idname = "PDT_PT_PanelTools"
171 bl_label = "PDT Design Tools"
172 bl_space_type = "VIEW_3D"
173 bl_region_type = "UI"
174 bl_category = "PDT"
175 bl_options = {'DEFAULT_CLOSED'}
177 def draw(self, context):
178 ui_cutoff = bpy.context.preferences.addons[__package__].preferences.pdt_ui_width
179 layout = self.layout
180 pdt_pg = context.scene.pdt_pg
181 # -----
182 # Tools
183 row = layout.row()
184 row.label(text=PDT_LAB_TOOLS)
185 row = layout.row()
186 row.operator("pdt.origin", text=PDT_LAB_ORIGINCURSOR)
187 row = layout.row()
188 row.operator("pdt.angle2", text=PDT_LAB_AD2D)
189 row.operator("pdt.angle3", text=PDT_LAB_AD3D)
190 row = layout.row()
191 row.operator("pdt.join", text=PDT_LAB_JOIN2VERTS)
192 row.operator("pdt.linetobisect", text=PDT_LAB_BISECT)
193 row = layout.row()
194 row.operator("pdt.edge_to_face", text=PDT_LAB_EDGETOEFACE)
195 row.operator("pdt.intersectall", text=PDT_LAB_INTERSETALL)
197 # Taper tool
198 box = layout.box()
199 row = box.row()
200 row.operator("pdt.taper", text=PDT_LAB_TAPER)
201 row.prop(pdt_pg, "taper", text=PDT_LAB_TAPERAXES)
203 # Fillet tool
204 box = layout.box()
205 row = box.row()
206 row.operator("pdt.fillet", text=f"{PDT_LAB_FILLET}")
207 row.prop(pdt_pg, "fillet_intersect", text="Intersect")
208 row = box.row()
209 row.prop(pdt_pg, "fillet_radius", text=PDT_LAB_RADIUS)
210 row.prop(pdt_pg, "fillet_profile", text=PDT_LAB_PROFILE)
211 row = box.row()
212 row.prop(pdt_pg, "fillet_segments", text=PDT_LAB_SEGMENTS)
213 row.prop(pdt_pg, "fillet_vertices_only", text=PDT_LAB_USEVERTS)
216 class PDT_PT_PanelPivotPoint(Panel):
217 bl_idname = "PDT_PT_PanelPivotPoint"
218 bl_label = "PDT Pivot Point"
219 bl_space_type = "VIEW_3D"
220 bl_region_type = "UI"
221 bl_category = "PDT"
222 bl_options = {'DEFAULT_CLOSED'}
224 def draw(self, context):
225 ui_cutoff = bpy.context.preferences.addons[__package__].preferences.pdt_ui_width
226 pdt_pg = context.scene.pdt_pg
227 layout = self.layout
228 row = layout.row()
229 col = row.column()
230 if context.window_manager.pdt_run_opengl is False:
231 icon = "PLAY"
232 txt = "Show"
233 else:
234 icon = "PAUSE"
235 txt = "Hide"
236 col.operator("pdt.modaldraw", icon=icon, text=txt)
237 col = row.column()
238 col.prop(pdt_pg, "pivot_size", text=PDT_LAB_PIVOTSIZE)
239 if ui_width() < ui_cutoff:
240 row = layout.row()
241 col = row.column()
242 col.prop(pdt_pg, "pivot_width", text=PDT_LAB_PIVOTWIDTH)
243 col = row.column()
244 col.prop(pdt_pg, "pivot_alpha", text=PDT_LAB_PIVOTALPHA)
245 row = layout.row()
246 split = row.split(factor=0.35, align=True)
247 split.label(text=PDT_LAB_PIVOTLOCH)
248 split.prop(pdt_pg, "pivot_loc", text=PDT_LAB_PIVOTLOC)
249 row = layout.row()
250 col = row.column()
251 col.operator("pdt.pivotselected", icon="EMPTY_AXIS", text="Selection")
252 col = row.column()
253 col.operator("pdt.pivotcursor", icon="EMPTY_AXIS", text="Cursor")
254 col = row.column()
255 col.operator("pdt.pivotorigin", icon="EMPTY_AXIS", text="Origin")
256 row = layout.row()
257 col = row.column()
258 col.operator("pdt.viewplanerot", icon="EMPTY_AXIS", text="Rotate")
259 col = row.column()
260 col.prop(pdt_pg, "pivot_ang", text="Angle")
261 row = layout.row()
262 col = row.column()
263 col.operator("pdt.viewscale", icon="EMPTY_AXIS", text="Scale")
264 col = row.column()
265 col.operator("pdt.cursorpivot", icon="EMPTY_AXIS", text="Cursor To Pivot")
266 row = layout.row()
267 col = row.column()
268 col.prop(pdt_pg, "pivot_dis", text="Scale Distance")
269 col = row.column()
270 col.prop(pdt_pg, "distance", text="System Distance")
271 row = layout.row()
272 split = row.split(factor=0.35, align=True)
273 split.label(text="Scale")
274 split.prop(pdt_pg, "pivot_scale", text="")
275 row = layout.row()
276 col = row.column()
277 col.operator("pdt.pivotwrite", icon="FILE_TICK", text="PP Write")
278 col = row.column()
279 col.operator("pdt.pivotread", icon="FILE", text="PP Read")
282 class PDT_PT_PanelPartsLibrary(Panel):
283 bl_idname = "PDT_PT_PanelPartsLibrary"
284 bl_label = "PDT Parts Library"
285 bl_space_type = "VIEW_3D"
286 bl_region_type = "UI"
287 bl_category = "PDT"
288 bl_options = {'DEFAULT_CLOSED'}
290 def draw(self, context):
291 ui_cutoff = context.preferences.addons[__package__].preferences.pdt_ui_width
292 layout = self.layout
293 pdt_pg = context.scene.pdt_pg
294 row = layout.row()
295 row.prop(pdt_pg, "pdt_library_path")
296 row = layout.row()
297 col = row.column()
298 col.operator("pdt.append", text="Append")
299 col = row.column()
300 col.operator("pdt.link", text="Link")
301 if ui_width() < ui_cutoff:
302 row = layout.row()
303 col = row.column()
304 col.prop(pdt_pg, "lib_mode", text="")
305 box = layout.box()
306 row = box.row()
307 col = row.column()
308 col.label(text="Objects")
309 col = row.column()
310 col.prop(pdt_pg, "object_search_string")
311 row = box.row()
312 row.prop(pdt_pg, "lib_objects", text="")
313 box = layout.box()
314 row = box.row()
315 col = row.column()
316 col.label(text="Collections")
317 col = row.column()
318 col.prop(pdt_pg, "collection_search_string")
319 row = box.row()
320 row.prop(pdt_pg, "lib_collections", text="")
321 box = layout.box()
322 row = box.row()
323 col = row.column()
324 col.label(text="Materials")
325 col = row.column()
326 col.prop(pdt_pg, "material_search_string")
327 row = box.row()
328 row.prop(pdt_pg, "lib_materials", text="")
329 row = box.row()
330 #row.operator("pdt.lib_show", text="Load Library File", icon='INFO')
333 class PDT_PT_PanelViewControl(Panel):
334 bl_idname = "PDT_PT_PanelViewControl"
335 bl_label = "PDT View Control"
336 bl_space_type = "VIEW_3D"
337 bl_region_type = "UI"
338 bl_category = "PDT"
339 bl_options = {'DEFAULT_CLOSED'}
341 # Sub-layout highlight states
342 _ui_groups = [False, False]
344 def draw(self, context):
345 ui_cutoff = context.preferences.addons[__package__].preferences.pdt_ui_width
346 layout = self.layout
347 ui_groups = self._ui_groups
348 pdt_pg = context.scene.pdt_pg
349 box = layout.box()
350 row = box.row()
351 col = row.column()
352 col.label(text="View Rotation")
353 col = row.column()
354 col.operator("pdt.viewrot", text="Rotate Abs")
355 row = box.row()
356 split = row.split(factor=0.35, align=True)
357 split.label(text="Rotation")
358 split.prop(pdt_pg, "rotation_coords", text="")
359 row = box.row()
360 col = row.column()
361 col.prop(pdt_pg, "vrotangle", text="Angle")
362 if ui_width() < ui_cutoff:
363 row = box.row()
364 col = row.column()
365 col.operator("pdt.viewleft", text="", icon="TRIA_LEFT")
366 col = row.column()
367 col.operator("pdt.viewright", text="", icon="TRIA_RIGHT")
368 col = row.column()
369 col.operator("pdt.viewup", text="", icon="TRIA_UP")
370 col = row.column()
371 col.operator("pdt.viewdown", text="", icon="TRIA_DOWN")
372 col = row.column()
373 col.operator("pdt.viewroll", text="", icon="RECOVER_LAST")
374 row = box.row()
375 col = row.column()
376 col.operator("pdt.viewiso", text="Isometric")
377 col = row.column()
378 col.operator("pdt.reset_3d_view", text="Reset View")
381 class PDT_PT_PanelCommandLine(Panel):
382 bl_idname = "PDT_PT_PanelCommandLine"
383 bl_label = "PDT Command Line (? for help)"
384 bl_space_type = "VIEW_3D"
385 bl_region_type = "UI"
386 bl_category = "PDT"
387 bl_options = {'DEFAULT_CLOSED'}
389 def draw(self, context):
390 layout = self.layout
391 pdt_pg = context.scene.pdt_pg
392 row = layout.row()
393 col = row.column()
394 col.prop(pdt_pg, "plane", text="Plane")
395 col = row.column()
396 col.prop(pdt_pg, "select", text="Mode")
397 row = layout.row()
398 row.label(text="Command Line, uses Plane & Mode Options")
399 row = layout.row()
400 row.prop(pdt_pg, "command", text="")
401 # Try Re-run
402 row.operator("pdt.command_rerun", text="", icon="LOOP_BACK")
403 row = layout.row()
404 row.prop(pdt_pg, "maths_output", text="Maths Output")
406 class PDT_PT_PanelTangent(Panel):
407 bl_idname = "PDT_PT_PanelTangent"
408 bl_label = "PDT Tangents"
409 bl_space_type = "VIEW_3D"
410 bl_region_type = "UI"
411 bl_category = "PDT"
412 bl_options = {'DEFAULT_CLOSED'}
414 def draw(self,context):
415 layout = self.layout
416 pdt_pg = context.scene.pdt_pg
418 if pdt_pg.menu_expand:
419 icon_e = "EVENT_C"
420 else:
421 icon_e = "EVENT_E"
422 row = layout.row()
423 row.label(text=f"Working {PDT_LAB_PLANE}:")
424 row.prop(pdt_pg, "plane", text="")
425 row = layout.row()
426 row.label(text="Tangent Mode")
427 row.prop(pdt_pg, "tangent_mode", text="")
428 row = layout.row()
429 row.operator("pdt.tangentoperatesel", text="Tangents from Selection", icon="NONE")
430 row = layout.row()
431 row.label(text="Or Use Tangents From Inputs")
432 row.operator("pdt.tangentexpandmenu", text="", icon=icon_e)
434 box = layout.box()
435 row = box.row()
436 split = row.split(factor=0.35, align=True)
437 split.label(text="Tangent Point")
438 split.prop(pdt_pg, "tangent_point2", text="")
439 row = box.row()
440 row.operator("pdt.tangentset3", text="from Cursor")
441 row.operator("pdt.tangentset4", text="from Vertex")
443 if pdt_pg.menu_expand:
444 box = layout.box()
445 row = box.row()
446 split = row.split(factor=0.35, align=True)
447 split.label(text="Centre 1")
448 split.prop(pdt_pg, "tangent_point0", text="")
449 row = box.row()
450 split = row.split(factor=0.45, align=False)
451 split.operator("pdt.tangentset1", text="Set From Arc")
452 split.prop(pdt_pg, "tangent_radius0", text="")
454 # Second Centre & Radius
455 row = box.row()
456 split = row.split(factor=0.35, align=True)
457 split.label(text="Centre 2")
458 split.prop(pdt_pg, "tangent_point1", text="")
459 row = box.row()
460 split = row.split(factor=0.45, align=False)
461 split.operator("pdt.tangentset2", text="Set From Arc")
462 split.prop(pdt_pg, "tangent_radius1", text="")
463 row = box.row()
464 row.operator("pdt.tangentoperate", text="Tangents From Inputs", icon="NONE")
466 class PDT_PT_PanelTrig(Panel):
467 bl_idname = "PDT_PT_PanelTrig"
468 bl_label = "PDT Trigonometrical Waves"
469 bl_space_type = "VIEW_3D"
470 bl_region_type = "UI"
471 bl_category = "PDT"
472 bl_options = {'DEFAULT_CLOSED'}
474 def draw(self,context):
475 layout = self.layout
476 pdt_pg = context.scene.pdt_pg
477 row = layout.row()
478 row.label(text=f"Working {PDT_LAB_PLANE}:")
479 row.prop(pdt_pg, "plane", text="")
481 row = layout.row()
482 split = row.split(factor=0.5, align=True)
483 split.prop(pdt_pg, "trig_type")
484 split.prop(pdt_pg, "trig_cycles")
485 row = layout.row()
486 split = row.split(factor=0.5, align=True)
487 split.prop(pdt_pg, "trig_amp")
488 split.prop(pdt_pg, "trig_len")
489 row = layout.row()
490 split = row.split(factor=0.5, align=True)
491 split.prop(pdt_pg, "trig_obj", text="")
492 split.prop(pdt_pg, "trig_del")
493 row = layout.row()
494 split = row.split(factor=0.5, align=True)
495 split.prop(pdt_pg, "trig_res")
496 split.prop(pdt_pg, "trig_tanmax")
497 row = layout.row()
498 row.prop(pdt_pg, "trig_off")
499 row = layout.row()
500 row.operator("pdt.wave_generator", icon="SEQ_LUMA_WAVEFORM")
501 row.prop(pdt_pg, "trig_abs")