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