Skip to content

Commit

Permalink
Path: bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sliptonic authored and yorikvanhavre committed Mar 21, 2017
1 parent 424fb81 commit 57da9b7
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 57 deletions.
7 changes: 3 additions & 4 deletions src/Mod/Path/PathScripts/PathDrilling.py
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
85 changes: 45 additions & 40 deletions src/Mod/Path/PathScripts/PathEngrave.py
Expand Up @@ -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()
Expand Down Expand Up @@ -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 == "":
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Path/PathScripts/PathLoadTool.py
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Path/PathScripts/PathPocket.py
Expand Up @@ -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()
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/Path/PathScripts/PathToolLibraryManager.py
Expand Up @@ -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)
Expand Down
21 changes: 12 additions & 9 deletions src/Mod/Path/PathScripts/PathUtils.py
Expand Up @@ -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")
Expand All @@ -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()
Expand Down

0 comments on commit 57da9b7

Please sign in to comment.