Repository navigation
Expand file tree
/
Copy pathlogo_command.py
More file actions
634 lines (556 loc) · 23.7 KB
/
Copy pathlogo_command.py
File metadata and controls
634 lines (556 loc) · 23.7 KB
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
"""FreeCAD command and task-panel UI for the TrailCurrent Logo Deboss tool."""
import os
import FreeCAD
import FreeCADGui
import Part
from PySide import QtWidgets, QtCore
_plugin_dir = os.path.dirname(os.path.abspath(__file__))
# ---------------------------------------------------------------------------
# FeaturePython proxy & ViewProvider (enables double-click re-edit)
# ---------------------------------------------------------------------------
class _LogoDebossProxy:
"""Data proxy for a LogoDeboss PartDesign::FeatureSubtractivePython."""
def __init__(self, obj):
obj.Proxy = self
def execute(self, obj):
"""Recompute the debossed shape.
For PartDesign integration the Shape must be the cumulative solid
(base + our cuts) and AddSubShape the isolated cutting tool.
Shapes are stored in the feature's local coordinate system.
"""
FreeCAD.Console.PrintMessage(
"LogoDeboss.execute() called for {}\n".format(obj.Name))
if not hasattr(obj, "Logo_Diameter"):
FreeCAD.Console.PrintWarning(
"LogoDeboss.execute(): no Logo_Diameter property yet\n")
return
# Determine the base shape to cut into
if hasattr(obj, "BaseFeature") and obj.BaseFeature is not None:
base_shape = obj.BaseFeature.Shape
FreeCAD.Console.PrintMessage(
"LogoDeboss.execute(): using BaseFeature '{}'\n"
.format(obj.BaseFeature.Name))
elif hasattr(obj, "Logo_OriginalBody") and obj.Logo_OriginalBody:
original = FreeCAD.ActiveDocument.getObject(obj.Logo_OriginalBody)
if original is None or original.Shape.isNull():
return
base_shape = original.Shape
else:
return
try:
from logo_deboss import apply_logo
face_name = getattr(obj, "Logo_FaceName", "")
if not face_name:
return
face_idx = int(face_name.replace("Face", "")) if face_name.startswith("Face") else -1
if face_idx < 1 or face_idx > len(base_shape.Faces):
FreeCAD.Console.PrintWarning(
"Logo Deboss: {} not found on base shape "
"(has {} faces), keeping existing shape.\n"
.format(face_name, len(base_shape.Faces)))
return
face = base_shape.Faces[face_idx - 1]
new_shape = apply_logo(
base_shape, face,
diameter=obj.Logo_Diameter,
total_depth=obj.Logo_TotalDepth,
mountain_ratio=obj.Logo_MountainPct / 100.0,
trail_ratio=obj.Logo_TrailPct / 100.0,
bolt_ratio=obj.Logo_BoltPct / 100.0,
x_offset=getattr(obj, "Logo_XOffset", 0.0),
y_offset=getattr(obj, "Logo_YOffset", 0.0),
rotation=getattr(obj, "Logo_Rotation", 0.0),
)
if new_shape and not new_shape.isNull():
FreeCAD.Console.PrintMessage(
"LogoDeboss.execute(): shape computed OK, "
"{} faces, transforming to local coords\n"
.format(len(new_shape.Faces)))
# Transform to feature-local coordinates
new_shape.transformShape(
obj.Placement.inverse().toMatrix(), True)
obj.Shape = new_shape
# AddSubShape = the isolated cutting tool for pattern support
if hasattr(obj, "AddSubShape"):
tool = base_shape.cut(new_shape)
tool.transformShape(
obj.Placement.inverse().toMatrix(), True)
obj.AddSubShape = tool
FreeCAD.Console.PrintMessage(
"LogoDeboss.execute(): Shape and AddSubShape set OK\n")
else:
FreeCAD.Console.PrintWarning(
"LogoDeboss.execute(): apply_logo returned null shape\n")
except Exception as e:
FreeCAD.Console.PrintError(
"Logo Deboss recompute failed: {}\n".format(e))
def __getstate__(self):
return None
def __setstate__(self, state):
return None
class _LogoDebossViewProvider:
"""ViewProvider that enables double-click re-editing of LogoDeboss objects."""
def __init__(self, vobj):
vobj.Proxy = self
def attach(self, vobj):
self.Object = vobj.Object
def _open_edit_panel(self, obj):
"""Open the task panel pre-filled with the object's stored parameters."""
if not hasattr(obj, "Logo_Diameter"):
return False
original = _get_logo_base_object(obj)
if original is None:
QtWidgets.QMessageBox.warning(
None, "Logo Deboss",
"Cannot re-edit: the original body object was deleted.",
)
return True
prefill = {
"diameter": obj.Logo_Diameter,
"total_depth": obj.Logo_TotalDepth,
"mountain_pct": obj.Logo_MountainPct,
"trail_pct": obj.Logo_TrailPct,
"bolt_pct": obj.Logo_BoltPct,
"x_offset": obj.Logo_XOffset if hasattr(obj, "Logo_XOffset") else 0.0,
"y_offset": obj.Logo_YOffset if hasattr(obj, "Logo_YOffset") else 0.0,
"rotation": getattr(obj, "Logo_Rotation", 0.0),
}
panel = DebossLogoTaskPanel(
original, obj.Logo_FaceName,
edit_obj=obj, prefill=prefill,
)
FreeCADGui.Control.showDialog(panel)
return True
def doubleClicked(self, vobj):
try:
return self._open_edit_panel(vobj.Object)
except Exception as e:
FreeCAD.Console.PrintError(
"Logo Deboss doubleClicked error: {}\n".format(e))
return False
def setEdit(self, vobj, mode=0):
if mode != 0:
return False
try:
return self._open_edit_panel(vobj.Object)
except Exception as e:
FreeCAD.Console.PrintError(
"Logo Deboss setEdit error: {}\n".format(e))
return False
def unsetEdit(self, vobj, mode=0):
FreeCADGui.Control.closeDialog()
return True
def getIcon(self):
return os.path.join(
_plugin_dir, "resources", "icons", "TrailCurrentLogo.svg"
)
def __getstate__(self):
return None
def __setstate__(self, state):
return None
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
def _find_body(obj):
"""Return the PartDesign::Body that *obj* belongs to, or None.
Works whether *obj* is the Body itself or a feature inside it.
"""
if hasattr(obj, "TypeId") and obj.TypeId == "PartDesign::Body":
return obj
if hasattr(obj, "getParentGeoFeatureGroup"):
parent = obj.getParentGeoFeatureGroup()
if (parent is not None
and hasattr(parent, "TypeId")
and parent.TypeId == "PartDesign::Body"):
return parent
return None
def _add_logo_properties(obj):
"""Add custom storage properties to a LogoDeboss feature object."""
obj.addProperty(
"App::PropertyFloat", "Logo_Diameter", "Logo Deboss",
"Logo diameter (mm)")
obj.addProperty(
"App::PropertyFloat", "Logo_TotalDepth", "Logo Deboss",
"Total deboss depth (mm)")
obj.addProperty(
"App::PropertyFloat", "Logo_MountainPct", "Logo Deboss",
"Mountain depth (%)")
obj.addProperty(
"App::PropertyFloat", "Logo_TrailPct", "Logo Deboss",
"Trail depth (%)")
obj.addProperty(
"App::PropertyFloat", "Logo_BoltPct", "Logo Deboss",
"Bolt depth (%)")
obj.addProperty(
"App::PropertyFloat", "Logo_XOffset", "Logo Deboss",
"Horizontal offset from face centre (mm)")
obj.addProperty(
"App::PropertyFloat", "Logo_YOffset", "Logo Deboss",
"Vertical offset from face centre (mm)")
obj.addProperty(
"App::PropertyFloat", "Logo_Rotation", "Logo Deboss",
"Rotation angle on the face (degrees)")
obj.addProperty(
"App::PropertyString", "Logo_FaceName", "Logo Deboss",
"Face used on the original body")
obj.addProperty(
"App::PropertyString", "Logo_OriginalBody", "Logo Deboss",
"Original body object name")
def _get_logo_base_object(obj):
"""Return the base object that a LogoDeboss result was derived from.
For PartDesign features this is the BaseFeature; for document-level
Part objects it is looked up by the stored Logo_OriginalBody name.
Returns None if the base cannot be found.
"""
if hasattr(obj, "BaseFeature") and obj.BaseFeature is not None:
return obj.BaseFeature
orig_name = getattr(obj, "Logo_OriginalBody", None)
if orig_name:
return FreeCAD.ActiveDocument.getObject(orig_name)
return None
# ---------------------------------------------------------------------------
# Task Panel (sidebar UI)
# ---------------------------------------------------------------------------
class DebossLogoTaskPanel:
"""Task panel shown in the FreeCAD sidebar when the command is active."""
def __init__(self, body_obj, face_name, edit_obj=None, prefill=None):
self.body_obj = body_obj
self.face_name = face_name
self.edit_obj = edit_obj # existing result being re-edited
self.form = self._build_ui()
if prefill:
self._apply_prefill(prefill)
# -- UI construction ---------------------------------------------------
def _build_ui(self):
widget = QtWidgets.QWidget()
layout = QtWidgets.QFormLayout(widget)
layout.setFieldGrowthPolicy(
QtWidgets.QFormLayout.AllNonFixedFieldsGrow
)
# Header
header = QtWidgets.QLabel("<b>TrailCurrent Logo Deboss</b>")
header.setAlignment(QtCore.Qt.AlignCenter)
layout.addRow(header)
# Logo diameter
self.diameter_spin = QtWidgets.QDoubleSpinBox()
self.diameter_spin.setRange(5.0, 100.0)
self.diameter_spin.setValue(18.0)
self.diameter_spin.setSingleStep(1.0)
self.diameter_spin.setDecimals(1)
self.diameter_spin.setSuffix(" mm")
layout.addRow("Logo Diameter:", self.diameter_spin)
# Total depth
self.depth_spin = QtWidgets.QDoubleSpinBox()
self.depth_spin.setRange(0.10, 5.00)
self.depth_spin.setValue(0.80)
self.depth_spin.setSingleStep(0.05)
self.depth_spin.setDecimals(2)
self.depth_spin.setSuffix(" mm")
self.depth_spin.setToolTip(
"Maximum deboss depth (circle background).\n"
"Adjust based on your lid/wall thickness."
)
layout.addRow("Total Depth:", self.depth_spin)
# Placement offsets
self.x_offset_spin = QtWidgets.QDoubleSpinBox()
self.x_offset_spin.setRange(-500.0, 500.0)
self.x_offset_spin.setValue(0.0)
self.x_offset_spin.setSingleStep(1.0)
self.x_offset_spin.setDecimals(1)
self.x_offset_spin.setSuffix(" mm")
self.x_offset_spin.setToolTip(
"Horizontal offset from the face centre."
)
layout.addRow("X Offset:", self.x_offset_spin)
self.y_offset_spin = QtWidgets.QDoubleSpinBox()
self.y_offset_spin.setRange(-500.0, 500.0)
self.y_offset_spin.setValue(0.0)
self.y_offset_spin.setSingleStep(1.0)
self.y_offset_spin.setDecimals(1)
self.y_offset_spin.setSuffix(" mm")
self.y_offset_spin.setToolTip(
"Vertical offset from the face centre."
)
layout.addRow("Y Offset:", self.y_offset_spin)
# Rotation
self.rotation_spin = QtWidgets.QDoubleSpinBox()
self.rotation_spin.setRange(-180.0, 180.0)
self.rotation_spin.setValue(0.0)
self.rotation_spin.setSingleStep(5.0)
self.rotation_spin.setDecimals(1)
self.rotation_spin.setSuffix(" deg")
self.rotation_spin.setToolTip(
"Rotation angle on the face (degrees)."
)
layout.addRow("Rotation:", self.rotation_spin)
# Separator
sep = QtWidgets.QFrame()
sep.setFrameShape(QtWidgets.QFrame.HLine)
layout.addRow(sep)
depth_label = QtWidgets.QLabel(
"<i>Depth ratios (% of total depth)</i>"
)
depth_label.setAlignment(QtCore.Qt.AlignCenter)
layout.addRow(depth_label)
# Mountain depth ratio
self.mountain_spin = QtWidgets.QDoubleSpinBox()
self.mountain_spin.setRange(10, 90)
self.mountain_spin.setValue(55)
self.mountain_spin.setSingleStep(5)
self.mountain_spin.setDecimals(0)
self.mountain_spin.setSuffix(" %")
self.mountain_spin.setToolTip(
"Mountain silhouette cut depth as % of total.\n"
"Higher = deeper cut, lower = more raised."
)
layout.addRow("Mountain Depth:", self.mountain_spin)
# Trail depth ratio
self.trail_spin = QtWidgets.QDoubleSpinBox()
self.trail_spin.setRange(5, 80)
self.trail_spin.setValue(30)
self.trail_spin.setSingleStep(5)
self.trail_spin.setDecimals(0)
self.trail_spin.setSuffix(" %")
self.trail_spin.setToolTip(
"Winding trail path cut depth as % of total."
)
layout.addRow("Trail Depth:", self.trail_spin)
# Bolt depth ratio
self.bolt_spin = QtWidgets.QDoubleSpinBox()
self.bolt_spin.setRange(5, 70)
self.bolt_spin.setValue(15)
self.bolt_spin.setSingleStep(5)
self.bolt_spin.setDecimals(0)
self.bolt_spin.setSuffix(" %")
self.bolt_spin.setToolTip(
"Lightning bolt cut depth as % of total.\n"
"Shallowest element — appears most raised."
)
layout.addRow("Bolt Depth:", self.bolt_spin)
return widget
def _apply_prefill(self, p):
"""Set widget values from a saved-parameter dict."""
if "diameter" in p:
self.diameter_spin.setValue(p["diameter"])
if "total_depth" in p:
self.depth_spin.setValue(p["total_depth"])
if "mountain_pct" in p:
self.mountain_spin.setValue(p["mountain_pct"])
if "trail_pct" in p:
self.trail_spin.setValue(p["trail_pct"])
if "bolt_pct" in p:
self.bolt_spin.setValue(p["bolt_pct"])
if "x_offset" in p:
self.x_offset_spin.setValue(p["x_offset"])
if "y_offset" in p:
self.y_offset_spin.setValue(p["y_offset"])
if "rotation" in p:
self.rotation_spin.setValue(p["rotation"])
# -- Task panel interface ----------------------------------------------
def accept(self):
"""Called when the user presses OK."""
from logo_deboss import apply_logo
doc = FreeCAD.ActiveDocument
body_shape = self.body_obj.Shape
face = getattr(body_shape, self.face_name)
diameter = self.diameter_spin.value()
total_depth = self.depth_spin.value()
mountain_ratio = self.mountain_spin.value() / 100.0
trail_ratio = self.trail_spin.value() / 100.0
bolt_ratio = self.bolt_spin.value() / 100.0
x_offset = self.x_offset_spin.value()
y_offset = self.y_offset_spin.value()
rotation = self.rotation_spin.value()
try:
new_shape = apply_logo(
body_shape,
face,
diameter=diameter,
total_depth=total_depth,
mountain_ratio=mountain_ratio,
trail_ratio=trail_ratio,
bolt_ratio=bolt_ratio,
x_offset=x_offset,
y_offset=y_offset,
rotation=rotation,
)
except Exception as e:
FreeCAD.Console.PrintError(
"Logo deboss failed: {}\n".format(e)
)
QtWidgets.QMessageBox.critical(
None,
"Logo Deboss Error",
"Boolean operation failed:\n\n{}\n\n"
"Make sure you selected a flat face with enough "
"room for the logo.".format(e),
)
return False
# Detect whether we are working inside a PartDesign::Body
body = _find_body(self.body_obj)
is_pd_edit = (self.edit_obj is not None
and hasattr(self.edit_obj, "BaseFeature"))
if is_pd_edit:
# Re-editing an existing feature — update properties and
# let doc.recompute() → execute() recompute the shape.
result_obj = self.edit_obj
result_obj.Logo_Diameter = diameter
result_obj.Logo_TotalDepth = total_depth
result_obj.Logo_MountainPct = self.mountain_spin.value()
result_obj.Logo_TrailPct = self.trail_spin.value()
result_obj.Logo_BoltPct = self.bolt_spin.value()
result_obj.Logo_XOffset = x_offset
result_obj.Logo_YOffset = y_offset
result_obj.Logo_Rotation = rotation
elif body is not None:
# New operation inside a PartDesign::Body.
# Set parameter properties, then let body.addObject() set
# BaseFeature and doc.recompute() call execute() for Shape.
result_obj = doc.addObject(
"PartDesign::FeatureSubtractivePython", "LogoDeboss")
_LogoDebossProxy(result_obj)
_LogoDebossViewProvider(result_obj.ViewObject)
_add_logo_properties(result_obj)
result_obj.Logo_Diameter = diameter
result_obj.Logo_TotalDepth = total_depth
result_obj.Logo_MountainPct = self.mountain_spin.value()
result_obj.Logo_TrailPct = self.trail_spin.value()
result_obj.Logo_BoltPct = self.bolt_spin.value()
result_obj.Logo_XOffset = x_offset
result_obj.Logo_YOffset = y_offset
result_obj.Logo_Rotation = rotation
result_obj.Logo_FaceName = self.face_name
result_obj.Logo_OriginalBody = body.Name
# Do NOT set BaseFeature, Shape, or AddSubShape manually —
# body.addObject() sets BaseFeature, and doc.recompute()
# calls execute() which computes Shape and AddSubShape.
body.addObject(result_obj)
else:
# Non-PartDesign: standalone Part::FeaturePython at doc root
if self.edit_obj is not None:
doc.removeObject(self.edit_obj.Name)
result_obj = doc.addObject("Part::FeaturePython", "LogoDeboss")
_LogoDebossProxy(result_obj)
_LogoDebossViewProvider(result_obj.ViewObject)
_add_logo_properties(result_obj)
result_obj.Logo_Diameter = diameter
result_obj.Logo_TotalDepth = total_depth
result_obj.Logo_MountainPct = self.mountain_spin.value()
result_obj.Logo_TrailPct = self.trail_spin.value()
result_obj.Logo_BoltPct = self.bolt_spin.value()
result_obj.Logo_XOffset = x_offset
result_obj.Logo_YOffset = y_offset
result_obj.Logo_Rotation = rotation
result_obj.Logo_FaceName = self.face_name
result_obj.Logo_OriginalBody = self.body_obj.Name
result_obj.Shape = new_shape
self.body_obj.ViewObject.Visibility = False
# Copy visual properties
if hasattr(self.body_obj, "ViewObject"):
src_vo = self.body_obj.ViewObject
dst_vo = result_obj.ViewObject
if hasattr(src_vo, "ShapeColor"):
dst_vo.ShapeColor = src_vo.ShapeColor
if hasattr(src_vo, "Transparency"):
dst_vo.Transparency = src_vo.Transparency
doc.recompute()
FreeCADGui.Control.closeDialog()
FreeCAD.Console.PrintMessage(
"Logo debossed onto {}.{} "
"(diameter={}mm, depth={}mm)\n"
.format(self.body_obj.Label, self.face_name,
diameter, total_depth)
)
return True
def reject(self):
"""Called when the user presses Cancel."""
FreeCADGui.Control.closeDialog()
return True
def getStandardButtons(self):
return (
QtWidgets.QDialogButtonBox.Ok
| QtWidgets.QDialogButtonBox.Cancel
)
# ---------------------------------------------------------------------------
# FreeCAD Command
# ---------------------------------------------------------------------------
class DebossLogoCommand:
"""FreeCAD command that debosses the TrailCurrent logo onto a face."""
def GetResources(self):
return {
"Pixmap": os.path.join(
_plugin_dir, "resources", "icons", "TrailCurrentLogo.svg"
),
"MenuText": "Deboss TrailCurrent Logo",
"ToolTip": (
"Deboss the TrailCurrent brand logo onto the selected "
"flat face with configurable multi-level depth.\n"
"Select an existing LogoDeboss result to re-edit."
),
}
def IsActive(self):
"""Active when a planar face or an existing logo result is selected."""
sel = FreeCADGui.Selection.getSelectionEx()
if len(sel) != 1:
return False
obj = sel[0].Object
# Re-edit mode: existing logo result selected
if hasattr(obj, "Logo_Diameter"):
return True
# New mode: a face is selected
if not sel[0].SubElementNames:
return False
return sel[0].SubElementNames[0].startswith("Face")
def Activated(self):
"""Called when the user clicks the command."""
sel = FreeCADGui.Selection.getSelectionEx()
if not sel:
return
obj = sel[0].Object
# --- Re-edit an existing logo deboss result ---
if hasattr(obj, "Logo_Diameter"):
original = _get_logo_base_object(obj)
if original is None:
QtWidgets.QMessageBox.warning(
None, "Logo Deboss",
"Cannot re-edit: the original body object was deleted.",
)
return
prefill = {
"diameter": obj.Logo_Diameter,
"total_depth": obj.Logo_TotalDepth,
"mountain_pct": obj.Logo_MountainPct,
"trail_pct": obj.Logo_TrailPct,
"bolt_pct": obj.Logo_BoltPct,
"x_offset": obj.Logo_XOffset if hasattr(obj, "Logo_XOffset") else 0.0,
"y_offset": obj.Logo_YOffset if hasattr(obj, "Logo_YOffset") else 0.0,
"rotation": getattr(obj, "Logo_Rotation", 0.0),
}
panel = DebossLogoTaskPanel(
original, obj.Logo_FaceName,
edit_obj=obj, prefill=prefill,
)
FreeCADGui.Control.showDialog(panel)
return
# --- New logo on a selected face ---
if not sel[0].SubElementNames:
return
face_name = sel[0].SubElementNames[0]
face = getattr(obj.Shape, face_name)
# Validate: face must be planar
surface = face.Surface
is_planar = hasattr(surface, "Axis") or isinstance(
surface, Part.Plane
)
if not is_planar:
QtWidgets.QMessageBox.warning(
None,
"Non-Planar Face",
"Please select a flat (planar) face.\n"
"The logo can only be debossed onto flat surfaces.",
)
return
panel = DebossLogoTaskPanel(obj, face_name)
FreeCADGui.Control.showDialog(panel)
# Register the command with FreeCAD
FreeCADGui.addCommand("TrailCurrent_DebossLogo", DebossLogoCommand())