diff --git a/src/Mod/Path/PathScripts/PathDrilling.py b/src/Mod/Path/PathScripts/PathDrilling.py index dfd2cc0766ce..b6e39a5025ad 100644 --- a/src/Mod/Path/PathScripts/PathDrilling.py +++ b/src/Mod/Path/PathScripts/PathDrilling.py @@ -108,7 +108,7 @@ def execute(self, obj): toolLoad = obj.ToolController if toolLoad is None or toolLoad.ToolNumber == 0: FreeCAD.Console.PrintError("No Tool Controller is selected. We need a tool to build a Path.") - #return + return else: self.vertFeed = toolLoad.VertFeed.Value self.horizFeed = toolLoad.HorizFeed.Value @@ -317,6 +317,7 @@ def Activated(self): FreeCADGui.doCommand('obj.RetractHeight= ' + str(ztop)) FreeCADGui.doCommand('obj.FinalDepth=' + str(zbottom)) FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)') + FreeCADGui.doCommand('obj.ToolController = PathScripts.PathUtils.findToolController(obj)') FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() @@ -380,6 +381,7 @@ def setFields(self): self.form.uiToolController.blockSignals(True) self.form.uiToolController.addItems(labels) self.form.uiToolController.blockSignals(False) + if self.obj.ToolController is not None: index = self.form.uiToolController.findText( self.obj.ToolController.Label, QtCore.Qt.MatchFixedString) @@ -388,9 +390,6 @@ def setFields(self): self.form.uiToolController.blockSignals(True) self.form.uiToolController.setCurrentIndex(index) self.form.uiToolController.blockSignals(False) - else: - self.obj.ToolController = PathUtils.findToolController(self.obj) - def open(self): self.s = SelObserver() diff --git a/src/Mod/Path/PathScripts/PathEngrave.py b/src/Mod/Path/PathScripts/PathEngrave.py index 89fd6a587c24..0e61efaa3d75 100644 --- a/src/Mod/Path/PathScripts/PathEngrave.py +++ b/src/Mod/Path/PathScripts/PathEngrave.py @@ -82,8 +82,7 @@ def __setstate__(self, state): return None def onChanged(self, obj, prop): - if prop == "UserLabel": - obj.Label = obj.UserLabel + " :" + obj.ToolDescription + pass def execute(self, obj): PathLog.track() @@ -118,45 +117,51 @@ def execute(self, obj): if baseobject is None: return - if isinstance(baseobject.Proxy, Draft._ShapeString): - output += "G0 Z" + PathUtils.fmt(obj.ClearanceHeight.Value) + "F " + PathUtils.fmt(self.vertRapid) + "\n" - - # we only consider the outer wire if this is a Face - for w in baseobject.Shape.Wires: - tempedges = PathUtils.cleanedges(w.Edges, 0.5) - wires.append(Part.Wire(tempedges)) - - if obj.Algorithm == "OCC Native": - output += self.buildpathocc(obj, wires) - - elif isinstance(baseobject.Proxy, ArchPanel.PanelSheet): # process the sheet - baseobject.Proxy.execute(baseobject) - ss = baseobject.Proxy.sheettag - ss.Placement = baseobject.Placement.multiply(ss.Placement) + try: + if isinstance(baseobject.Proxy, Draft._ShapeString): + output += "G0 Z" + PathUtils.fmt(obj.ClearanceHeight.Value) + "F " + PathUtils.fmt(self.vertRapid) + "\n" + + # we only consider the outer wire if this is a Face + for w in baseobject.Shape.Wires: + tempedges = PathUtils.cleanedges(w.Edges, 0.5) + wires.append(Part.Wire(tempedges)) + + if obj.Algorithm == "OCC Native": + output += self.buildpathocc(obj, wires) + + elif isinstance(baseobject.Proxy, ArchPanel.PanelSheet): # process the sheet + baseobject.Proxy.execute(baseobject) + ss = baseobject.Proxy.sheettag + ss.Placement = baseobject.Placement.multiply(ss.Placement) + + output += "G0 Z" + PathUtils.fmt(obj.ClearanceHeight.Value) + "F " + PathUtils.fmt(self.vertRapid) + "\n" + for w in ss.Wires: + tempedges = PathUtils.cleanedges(w.Edges, 0.5) + wires.append(Part.Wire(tempedges)) + if obj.Algorithm == "OCC Native": + output += self.buildpathocc(obj, wires) + + for subobj in baseobject.Group: # process the group of panels + if isinstance(subobj.Proxy, ArchPanel.PanelCut): + subobj.Proxy.execute(subobj) + + if hasattr(subobj.Proxy, "tag"): + ss = subobj.Proxy.tag + ss.Placement = subobj.Placement.multiply(ss.Placement) + + output += "G0 Z" + PathUtils.fmt(obj.ClearanceHeight.Value) + "F " + PathUtils.fmt(self.vertRapid) + "\n" + for w in ss.Wires: + tempedges = PathUtils.cleanedges(w.Edges, 0.5) + wires.append(Part.Wire(tempedges)) + if obj.Algorithm == "OCC Native": + output += self.buildpathocc(obj, wires) + else: + raise ValueError('Unknown baseobject type for engraving') output += "G0 Z" + PathUtils.fmt(obj.ClearanceHeight.Value) + "F " + PathUtils.fmt(self.vertRapid) + "\n" - for w in ss.Wires: - tempedges = PathUtils.cleanedges(w.Edges, 0.5) - wires.append(Part.Wire(tempedges)) - if obj.Algorithm == "OCC Native": - output += self.buildpathocc(obj, wires) - for subobj in baseobject.Group: # process the group of panels - if isinstance(subobj.Proxy, ArchPanel.PanelCut): - subobj.Proxy.execute(subobj) - - if hasattr(subobj.Proxy, "tag"): - ss = subobj.Proxy.tag - ss.Placement = subobj.Placement.multiply(ss.Placement) - - output += "G0 Z" + PathUtils.fmt(obj.ClearanceHeight.Value) + "F " + PathUtils.fmt(self.vertRapid) + "\n" - for w in ss.Wires: - tempedges = PathUtils.cleanedges(w.Edges, 0.5) - wires.append(Part.Wire(tempedges)) - if obj.Algorithm == "OCC Native": - output += self.buildpathocc(obj, wires) - - output += "G0 Z" + PathUtils.fmt(obj.ClearanceHeight.Value) + "F " + PathUtils.fmt(self.vertRapid) + "\n" + except: + FreeCAD.Console.PrintError("The Job Base Object has no engraveable element. Engraving operation will produce no output.") # print output if output == "": @@ -248,8 +253,8 @@ def __getstate__(self): def __setstate__(self, state): return None - def onDelete(self): - return None + # def onDelete(self): + # return None class CommandPathEngrave: diff --git a/src/Mod/Path/PathScripts/PathLoadTool.py b/src/Mod/Path/PathScripts/PathLoadTool.py index 891d96024766..53f4e7d72eb0 100644 --- a/src/Mod/Path/PathScripts/PathLoadTool.py +++ b/src/Mod/Path/PathScripts/PathLoadTool.py @@ -34,8 +34,8 @@ import PathScripts.PathLog as PathLog LOG_MODULE = 'PathLoadTool' -PathLog.setLevel(PathLog.Level.DEBUG, LOG_MODULE) -PathLog.trackModule('PathLoadTool') +PathLog.setLevel(PathLog.Level.INFO, LOG_MODULE) +#PathLog.trackModule('PathLoadTool') # Qt tanslation handling try: diff --git a/src/Mod/Path/PathScripts/PathPocket.py b/src/Mod/Path/PathScripts/PathPocket.py index 81773d034a24..03cd52bb72c5 100644 --- a/src/Mod/Path/PathScripts/PathPocket.py +++ b/src/Mod/Path/PathScripts/PathPocket.py @@ -503,6 +503,7 @@ def Activated(self): FreeCADGui.doCommand('obj.RampSize = 0.75') FreeCADGui.doCommand('obj.HelixSize = 0.75') FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)') + FreeCADGui.doCommand('obj.ToolController = PathScripts.PathUtils.findToolController(obj)') FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() @@ -556,7 +557,6 @@ def getFields(self): self.obj.ZigZagAngle = FreeCAD.Units.Quantity(self.form.zigZagAngle.text()).Value if hasattr(self.obj, "StepOver"): self.obj.StepOver = self.form.stepOverPercent.value() - if hasattr(self.obj, "ToolController"): PathLog.debug("name: {}".format(self.form.uiToolController.currentText())) tc = PathUtils.findToolController(self.obj, self.form.uiToolController.currentText()) diff --git a/src/Mod/Path/PathScripts/PathToolLibraryManager.py b/src/Mod/Path/PathScripts/PathToolLibraryManager.py index 2ecc73dbb325..8c155f0c07ef 100644 --- a/src/Mod/Path/PathScripts/PathToolLibraryManager.py +++ b/src/Mod/Path/PathScripts/PathToolLibraryManager.py @@ -556,7 +556,8 @@ def copyTools(self): newtool = tool.copy() obj.Tooltable.setTool(int(toolnum), newtool) obj.ToolNumber = int(toolnum) - obj.recompute() + #obj.recompute() + FreeCAD.ActiveDocument.recompute() def getStandardButtons(self): return int(QtGui.QDialogButtonBox.Ok) diff --git a/src/Mod/Path/PathScripts/PathUtils.py b/src/Mod/Path/PathScripts/PathUtils.py index 3bf150a11642..23e5a6055020 100644 --- a/src/Mod/Path/PathScripts/PathUtils.py +++ b/src/Mod/Path/PathScripts/PathUtils.py @@ -233,14 +233,25 @@ def findToolController(obj, name=None): if no controller is found, returns None''' PathLog.track('name: {}'.format(name)) + + #First check if a user has selected a tool controller in the tree. + for sel in FreeCADGui.Selection.getSelectionEx(): + if hasattr(sel.Object, 'Proxy'): + if isinstance(sel.Object.Proxy, PathScripts.PathLoadTool.LoadTool): + return sel.Object + controllers = getToolControllers(obj) + if len(controllers) == 0: + return None + + #If there's only one in the job, use it. if len(controllers) == 1: if name is None or name == controllers[0].Label: tc = controllers[0] else: tc = None - elif name is not None: + elif name is not None: #More than one, make the user choose. tc = [i for i in controllers if i.Label == name][0] else: #form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Path/DlgTCChooser.ui") @@ -254,14 +265,6 @@ def findToolController(obj, name=None): tc = [i for i in controllers if i.Label == form.uiToolController.currentText()][0] return tc - # for c in controllers: - # if c.Label == name: - # return c - # if len(controllers) > 0: - # return controllers[0] - # else: - # return None - def findParentJob(obj): '''retrieves a parent job object for an operation or other Path object''' PathLog.track()