File size: 2,975 Bytes
985c397 | 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 | # SPDX-License-Identifier: LGPL-2.1-or-later
import FreeCAD
import FreeCADGui
import Path
import Path.Dressup.Array as DressupArray
import Path.Dressup.Utils as PathDressup
from PySide.QtCore import QT_TRANSLATE_NOOP
translate = FreeCAD.Qt.translate
class DressupArrayViewProvider(object):
def __init__(self, vobj):
self.attach(vobj)
def dumps(self):
return None
def loads(self, state):
return None
def attach(self, vobj):
self.vobj = vobj
self.obj = vobj.Object
self.panel = None
def claimChildren(self):
return [self.obj.Base]
def onDelete(self, vobj, args=None):
if vobj.Object and vobj.Object.Proxy:
vobj.Object.Proxy.onDelete(vobj.Object, args)
return True
def setEdit(self, vobj, mode=0):
return True
def unsetEdit(self, vobj, mode=0):
pass
def setupTaskPanel(self, panel):
pass
def clearTaskPanel(self):
pass
def getIcon(self):
if getattr(PathDressup.baseOp(self.obj), "Active", True):
return ":/icons/CAM_Dressup.svg"
else:
return ":/icons/CAM_OpActive.svg"
class CommandPathDressupArray:
def GetResources(self):
return {
"Pixmap": "CAM_Dressup",
"MenuText": QT_TRANSLATE_NOOP("CAM_DressupArray", "Array"),
"ToolTip": QT_TRANSLATE_NOOP(
"CAM_DressupArray",
"Creates an array from a selected toolpath",
),
}
def IsActive(self):
if FreeCAD.ActiveDocument is not None:
for o in FreeCAD.ActiveDocument.Objects:
if o.Name[:3] == "Job":
return True
return False
def Activated(self):
# check that the selection contains exactly what we want
selection = FreeCADGui.Selection.getSelection()
if len(selection) != 1:
Path.Log.error(translate("CAM_DressupArray", "Select one toolpath object") + "\n")
return
baseObject = selection[0]
# everything ok!
FreeCAD.ActiveDocument.openTransaction("Create Path Array Dress-up")
FreeCADGui.addModule("Path.Dressup.Gui.Array")
FreeCADGui.doCommand(
"Path.Dressup.Gui.Array.Create(App.ActiveDocument.%s)" % baseObject.Name
)
# FreeCAD.ActiveDocument.commitTransaction() # Final `commitTransaction()` called via TaskPanel.accept()
FreeCAD.ActiveDocument.recompute()
def Create(base, name="DressupPathArray"):
FreeCAD.ActiveDocument.openTransaction("Create an Array dressup")
obj = DressupArray.Create(base, name)
obj.ViewObject.Proxy = DressupArrayViewProvider(obj.ViewObject)
obj.Base.ViewObject.Visibility = False
FreeCAD.ActiveDocument.commitTransaction()
return obj
if FreeCAD.GuiUp:
# register the FreeCAD command
FreeCADGui.addCommand("CAM_DressupArray", CommandPathDressupArray())
|