def Create(name='TC: Default Tool', tool=None, toolNumber=1, assignViewProvider=True, assignTool=True): legacyTool = PathPreferences.toolsUseLegacyTools( ) if tool is None else isinstance(tool, Path.Tool) PathLog.track(tool, toolNumber, legacyTool) obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", name) obj.Label = name obj.Proxy = ToolController(obj, legacyTool, assignTool) if FreeCAD.GuiUp and assignViewProvider: ViewProvider(obj.ViewObject) if assignTool: if not tool: if legacyTool: tool = Path.Tool() tool.Diameter = 5.0 tool.Name = "Default Tool" tool.CuttingEdgeHeight = 15.0 tool.ToolType = "EndMill" tool.Material = "HighSpeedSteel" else: tool = PathToolBit.Factory.Create() if tool.ViewObject: tool.ViewObject.Visibility = False obj.Tool = tool obj.ToolNumber = toolNumber return obj
def test00(self): '''Verify ToolController templateAttrs''' t = self.createTool('T1') tc = PathToolController.Create('TC0', t) tc.Label = 'ToolController' tc.ToolNumber = 7 tc.VertFeed = '3 in/s' tc.VertFeed = round(tc.VertFeed, 1) tc.HorizFeed = '10 mm/s' tc.VertRapid = 40 tc.HorizRapid = 28 tc.SpindleDir = 'Reverse' tc.SpindleSpeed = 12000 attrs = tc.Proxy.templateAttrs(tc) self.assertEqual(attrs['name'], 'TC0') self.assertEqual(attrs['label'], 'ToolController') self.assertEqual(attrs['nr'], 7) self.assertEqual(attrs['vfeed'], '76.2 mm/s') self.assertEqual(attrs['hfeed'], '10.0 mm/s') self.assertEqual(attrs['vrapid'], '40.0 mm/s') self.assertEqual(attrs['hrapid'], '28.0 mm/s') self.assertEqual(attrs['dir'], 'Reverse') self.assertEqual(attrs['speed'], 12000) if PathPreferences.toolsUseLegacyTools(): self.assertEqual(attrs['tool'], t.templateAttrs()) else: self.assertEqual(attrs['tool'], t.Proxy.templateAttrs(t)) return tc
def edit(self, job=None, cb=None): if PathPreferences.toolsUseLegacyTools(): editor = EditorPanel(job, cb) editor.setupUi() editor.form.exec_() else: if PathToolBitLibraryCmd.CommandToolBitLibraryLoad.Execute(job): if cb: cb()
def createTool(self, name='t1', diameter=1.75): if PathPreferences.toolsUseLegacyTools(): return Path.Tool(name=name, diameter=diameter) attrs = { 'shape': None, 'name': name, 'parameter': { 'Diameter': diameter }, 'attribute': [] } return PathToolBit.Factory.CreateFromAttrs(attrs, name)
def Initialize(self): global PathCommandGroup # Add preferences pages - before loading PathGui to properly order pages of Path group from PathScripts import PathPreferencesPathJob, PathPreferencesPathDressup FreeCADGui.addPreferencePage(PathPreferencesPathJob.JobPreferencesPage, "Path") FreeCADGui.addPreferencePage( PathPreferencesPathDressup.DressupPreferencesPage, "Path" ) # Check enablement of experimental features from PathScripts import PathPreferences # load the builtin modules import Path import PathScripts import PathGui from PySide import QtCore, QtGui FreeCADGui.addLanguagePath(":/translations") FreeCADGui.addIconPath(":/icons") from PathScripts import PathGuiInit from PathScripts import PathJobCmd from PathScripts import PathToolBitCmd from PathScripts import PathToolBitLibraryCmd from PySide.QtCore import QT_TRANSLATE_NOOP import PathCommands PathGuiInit.Startup() # build commands list projcmdlist = ["Path_Job", "Path_Post"] toolcmdlist = [ "Path_Inspect", "Path_Simulator", "Path_SelectLoop", "Path_OpActiveToggle", ] prepcmdlist = [ "Path_Fixture", "Path_Comment", "Path_Stop", "Path_Custom", "Path_Probe", ] twodopcmdlist = [ "Path_Profile", "Path_Pocket_Shape", "Path_Drilling", "Path_MillFace", "Path_Helix", "Path_Adaptive", ] threedopcmdlist = ["Path_Pocket3D"] engravecmdlist = ["Path_Engrave", "Path_Deburr", "Path_Vcarve"] modcmdlist = ["Path_OperationCopy", "Path_Array", "Path_SimpleCopy"] dressupcmdlist = [ "Path_DressupAxisMap", "Path_DressupPathBoundary", "Path_DressupDogbone", "Path_DressupDragKnife", "Path_DressupLeadInOut", "Path_DressupRampEntry", "Path_DressupTag", "Path_DressupZCorrect", ] extracmdlist = [] # modcmdmore = ["Path_Hop",] # remotecmdlist = ["Path_Remote"] specialcmdlist = [] if PathPreferences.toolsUseLegacyTools(): toolcmdlist.append("Path_ToolLibraryEdit") toolbitcmdlist = [] else: toolcmdlist.extend(PathToolBitLibraryCmd.BarList) toolbitcmdlist = PathToolBitLibraryCmd.MenuList engravecmdgroup = ["Path_EngraveTools"] FreeCADGui.addCommand( "Path_EngraveTools", PathCommandGroup( engravecmdlist, QT_TRANSLATE_NOOP("Path_EngraveTools", "Engraving Operations") ), ) threedcmdgroup = threedopcmdlist if PathPreferences.experimentalFeaturesEnabled(): projcmdlist.append("Path_Sanity") prepcmdlist.append("Path_Shape") extracmdlist.extend(["Path_Area", "Path_Area_Workplane"]) specialcmdlist.append("Path_ThreadMilling") twodopcmdlist.append("Path_Slot") if PathPreferences.advancedOCLFeaturesEnabled(): try: import ocl # pylint: disable=unused-variable from PathScripts import PathSurfaceGui from PathScripts import PathWaterlineGui threedopcmdlist.extend(["Path_Surface", "Path_Waterline"]) threedcmdgroup = ["Path_3dTools"] FreeCADGui.addCommand( "Path_3dTools", PathCommandGroup( threedopcmdlist, QT_TRANSLATE_NOOP("Path_3dTools", "3D Operations"), ), ) except ImportError: if not PathPreferences.suppressOpenCamLibWarning(): FreeCAD.Console.PrintError("OpenCamLib is not working!\n") self.appendToolbar( QT_TRANSLATE_NOOP("Path", "Project Setup"), projcmdlist ) self.appendToolbar( QT_TRANSLATE_NOOP("Path", "Tool Commands"), toolcmdlist ) self.appendToolbar( QT_TRANSLATE_NOOP("Path", "New Operations"), twodopcmdlist + engravecmdgroup + threedcmdgroup, ) self.appendToolbar( QT_TRANSLATE_NOOP("Path", "Path Modification"), modcmdlist ) if extracmdlist: self.appendToolbar( QT_TRANSLATE_NOOP("Path", "Helpful Tools"), extracmdlist ) self.appendMenu( [QT_TRANSLATE_NOOP("Path", "&Path")], projcmdlist + ["Path_ExportTemplate", "Separator"] + toolcmdlist + toolbitcmdlist + ["Separator"] + twodopcmdlist + engravecmdlist + ["Separator"] + threedopcmdlist + ["Separator"], ) self.appendMenu( [ QT_TRANSLATE_NOOP("Path", "&Path"), QT_TRANSLATE_NOOP("Path", "Path Dressup"), ], dressupcmdlist, ) self.appendMenu( [ QT_TRANSLATE_NOOP("Path", "&Path"), QT_TRANSLATE_NOOP("Path", "Supplemental Commands"), ], prepcmdlist, ) self.appendMenu( [ QT_TRANSLATE_NOOP("Path", "&Path"), QT_TRANSLATE_NOOP("Path", "Path Modification"), ], modcmdlist, ) if specialcmdlist: self.appendMenu( [ QT_TRANSLATE_NOOP("Path", "&Path"), QT_TRANSLATE_NOOP("Path", "Specialty Operations"), ], specialcmdlist, ) if extracmdlist: self.appendMenu([QT_TRANSLATE_NOOP("Path", "&Path")], extracmdlist) self.appendMenu([QT_TRANSLATE_NOOP("Path", "&Path")], ["Separator"]) self.appendMenu( [ QT_TRANSLATE_NOOP("Path", "&Path"), QT_TRANSLATE_NOOP("Path", "Utils"), ], ["Path_PropertyBag"], ) self.dressupcmds = dressupcmdlist curveAccuracy = PathPreferences.defaultLibAreaCurveAccuracy() if curveAccuracy: Path.Area.setDefaultParams(Accuracy=curveAccuracy) # keep this one the last entry in the preferences import PathScripts.PathPreferencesAdvanced as PathPreferencesAdvanced FreeCADGui.addPreferencePage( PathPreferencesAdvanced.AdvancedPreferencesPage, "Path" ) Log("Loading Path workbench... done\n")
def Initialize(self): global PathCommandGroup # Add preferences pages - before loading PathGui to properly order pages of Path group from PathScripts import PathPreferencesPathJob, PathPreferencesPathDressup translate = FreeCAD.Qt.translate FreeCADGui.addPreferencePage(PathPreferencesPathJob.JobPreferencesPage, "Path") FreeCADGui.addPreferencePage( PathPreferencesPathDressup.DressupPreferencesPage, "Path") # Check enablement of experimental features from PathScripts import PathPreferences # load the builtin modules import Path import PathScripts import PathGui from PySide import QtCore, QtGui FreeCADGui.addLanguagePath(":/translations") FreeCADGui.addIconPath(":/icons") from PathScripts import PathGuiInit from PathScripts import PathJobCmd from PathScripts import PathToolBitCmd from PathScripts import PathToolBitLibraryCmd from PySide.QtCore import QT_TRANSLATE_NOOP import PathCommands PathGuiInit.Startup() # build commands list projcmdlist = ["Path_Job", "Path_Post"] toolcmdlist = [ "Path_Inspect", "Path_Simulator", "Path_SelectLoop", "Path_OpActiveToggle", ] prepcmdlist = [ "Path_Fixture", "Path_Comment", "Path_Stop", "Path_Custom", "Path_Probe", ] twodopcmdlist = [ "Path_Profile", "Path_Pocket_Shape", "Path_Drilling", "Path_MillFace", "Path_Helix", "Path_Adaptive", ] threedopcmdlist = ["Path_Pocket3D"] engravecmdlist = ["Path_Engrave", "Path_Deburr", "Path_Vcarve"] modcmdlist = ["Path_OperationCopy", "Path_Array", "Path_SimpleCopy"] dressupcmdlist = [ "Path_DressupAxisMap", "Path_DressupPathBoundary", "Path_DressupDogbone", "Path_DressupDragKnife", "Path_DressupLeadInOut", "Path_DressupRampEntry", "Path_DressupTag", "Path_DressupZCorrect", ] extracmdlist = [] # modcmdmore = ["Path_Hop",] # remotecmdlist = ["Path_Remote"] specialcmdlist = [] if PathPreferences.toolsUseLegacyTools(): toolcmdlist.append("Path_ToolLibraryEdit") toolbitcmdlist = [] else: toolcmdlist.extend(PathToolBitLibraryCmd.BarList) toolbitcmdlist = PathToolBitLibraryCmd.MenuList engravecmdgroup = ["Path_EngraveTools"] FreeCADGui.addCommand( "Path_EngraveTools", PathCommandGroup( engravecmdlist, QT_TRANSLATE_NOOP("Path_EngraveTools", "Engraving Operations"), ), ) threedcmdgroup = threedopcmdlist if PathPreferences.experimentalFeaturesEnabled(): projcmdlist.append("Path_Sanity") prepcmdlist.append("Path_Shape") extracmdlist.extend(["Path_Area", "Path_Area_Workplane"]) specialcmdlist.append("Path_ThreadMilling") twodopcmdlist.append("Path_Slot") if PathPreferences.advancedOCLFeaturesEnabled(): try: import ocl from PathScripts import PathSurfaceGui from PathScripts import PathWaterlineGui threedopcmdlist.extend(["Path_Surface", "Path_Waterline"]) threedcmdgroup = ["Path_3dTools"] FreeCADGui.addCommand( "Path_3dTools", PathCommandGroup( threedopcmdlist, QT_TRANSLATE_NOOP("Path_3dTools", "3D Operations"), ), ) except ImportError: if not PathPreferences.suppressOpenCamLibWarning(): FreeCAD.Console.PrintError("OpenCamLib is not working!\n") self.appendToolbar(QT_TRANSLATE_NOOP("Workbench", "Project Setup"), projcmdlist) self.appendToolbar(QT_TRANSLATE_NOOP("Workbench", "Tool Commands"), toolcmdlist) self.appendToolbar( QT_TRANSLATE_NOOP("Workbench", "New Operations"), twodopcmdlist + engravecmdgroup + threedcmdgroup, ) self.appendToolbar(QT_TRANSLATE_NOOP("Workbench", "Path Modification"), modcmdlist) if extracmdlist: self.appendToolbar(QT_TRANSLATE_NOOP("Workbench", "Helpful Tools"), extracmdlist) self.appendMenu( [QT_TRANSLATE_NOOP("Workbench", "&Path")], projcmdlist + ["Path_ExportTemplate", "Separator"] + toolcmdlist + toolbitcmdlist + ["Separator"] + twodopcmdlist + engravecmdlist + ["Separator"] + threedopcmdlist + ["Separator"], ) self.appendMenu( [ QT_TRANSLATE_NOOP("Workbench", "&Path"), QT_TRANSLATE_NOOP("Workbench", "Path Dressup"), ], dressupcmdlist, ) self.appendMenu( [ QT_TRANSLATE_NOOP("Workbench", "&Path"), QT_TRANSLATE_NOOP("Workbench", "Supplemental Commands"), ], prepcmdlist, ) self.appendMenu( [ QT_TRANSLATE_NOOP("Workbench", "&Path"), QT_TRANSLATE_NOOP("Workbench", "Path Modification"), ], modcmdlist, ) if specialcmdlist: self.appendMenu( [ QT_TRANSLATE_NOOP("Workbench", "&Path"), QT_TRANSLATE_NOOP("Workbench", "Specialty Operations"), ], specialcmdlist, ) if extracmdlist: self.appendMenu([QT_TRANSLATE_NOOP("Workbench", "&Path")], extracmdlist) self.appendMenu([QT_TRANSLATE_NOOP("Workbench", "&Path")], ["Separator"]) self.appendMenu( [ QT_TRANSLATE_NOOP("Workbench", "&Path"), QT_TRANSLATE_NOOP("Workbench", "Utils"), ], ["Path_PropertyBag"], ) self.dressupcmds = dressupcmdlist curveAccuracy = PathPreferences.defaultLibAreaCurveAccuracy() if curveAccuracy: Path.Area.setDefaultParams(Accuracy=curveAccuracy) # keep this one the last entry in the preferences import PathScripts.PathPreferencesAdvanced as PathPreferencesAdvanced from PathScripts.PathPreferences import preferences FreeCADGui.addPreferencePage( PathPreferencesAdvanced.AdvancedPreferencesPage, "Path") Log("Loading Path workbench... done\n") # Warn user if current schema doesn't use minute for time in velocity if not PathPreferences.suppressVelocity(): velString = FreeCAD.Units.Quantity( 1, FreeCAD.Units.Velocity).getUserPreferred()[2][3:] if velString != "min": current_schema = FreeCAD.Units.listSchemas( FreeCAD.Units.getSchema()) msg = translate( "Path", f"The currently selected unit schema: \n '{current_schema}'\n Does not use 'minutes' for velocity values. \n \nCNC machines require feed rate to be expressed in \nunit/minute. To ensure correct gcode: \nSelect a minute-based schema in preferences.\nFor example:\n 'Metric, Small Parts & CNC'\n 'US Customary'\n 'Imperial Decimal'", ) header = translate("Path", "Warning") msgbox = QtGui.QMessageBox(QtGui.QMessageBox.Warning, header, msg) msgbox.addButton(translate("Path", "Ok"), QtGui.QMessageBox.AcceptRole) msgbox.addButton(translate("Path", "Don't Show This Anymore"), QtGui.QMessageBox.ActionRole) if msgbox.exec_() == 1: preferences().SetBool("WarningSuppressVelocity", True)
def loadToolSettings(self): self.form.toolsUseLegacy.setChecked( PathPreferences.toolsUseLegacyTools()) self.form.toolsAbsolutePaths.setChecked( PathPreferences.toolsStoreAbsolutePaths())