path: drilling asks for correct tc on create
This commit is contained in:
committed by
Yorik van Havre
parent
d24b7730de
commit
fa79e7d635
@@ -438,7 +438,9 @@ class TaskPanel:
|
||||
index = self.form.direction.findText(
|
||||
self.obj.Direction, QtCore.Qt.MatchFixedString)
|
||||
if index >= 0:
|
||||
self.form.direction.blockSignals(True)
|
||||
self.form.direction.setCurrentIndex(index)
|
||||
self.form.direction.blockSignals(False)
|
||||
|
||||
controllers = PathUtils.getToolControllers(self.obj)
|
||||
labels = [c.Label for c in controllers]
|
||||
@@ -447,7 +449,9 @@ class TaskPanel:
|
||||
index = self.form.uiToolController.findText(
|
||||
self.obj.ToolController.Label, QtCore.Qt.MatchFixedString)
|
||||
if index >= 0:
|
||||
self.form.uiToolController.blockSignals(True)
|
||||
self.form.uiToolController.setCurrentIndex(index)
|
||||
self.form.uiToolController.blockSignals(False)
|
||||
|
||||
def open(self):
|
||||
self.s = SelObserver()
|
||||
|
||||
@@ -35,8 +35,8 @@ from PathScripts.PathUtils import fmt
|
||||
|
||||
|
||||
LOG_MODULE = 'PathDrilling'
|
||||
PathLog.setLevel(PathLog.Level.DEBUG, LOG_MODULE)
|
||||
PathLog.trackModule('PathDrilling')
|
||||
PathLog.setLevel(PathLog.Level.INFO, LOG_MODULE)
|
||||
#PathLog.trackModule('PathDrilling')
|
||||
|
||||
FreeCADGui = None
|
||||
if FreeCAD.GuiUp:
|
||||
@@ -83,6 +83,10 @@ class ObjectDrilling:
|
||||
obj.addProperty("App::PropertyLink", "ToolController", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "The tool controller that will be used to calculate the path"))
|
||||
|
||||
obj.Proxy = self
|
||||
self.vertFeed = 0.0
|
||||
self.horizFeed = 0.0
|
||||
self.vertRapid = 0.0
|
||||
self.horizRapid = 0.0
|
||||
|
||||
def __getstate__(self):
|
||||
return None
|
||||
@@ -91,8 +95,9 @@ class ObjectDrilling:
|
||||
return None
|
||||
|
||||
def onChanged(self, obj, prop):
|
||||
if prop == "UserLabel":
|
||||
obj.Label = obj.UserLabel + " :" + obj.ToolDescription
|
||||
pass
|
||||
# if prop == "UserLabel":
|
||||
# obj.Label = obj.UserLabel + " :" + obj.ToolDescription
|
||||
|
||||
def execute(self, obj):
|
||||
PathLog.track()
|
||||
@@ -244,7 +249,7 @@ class ObjectDrilling:
|
||||
baselist.append(item)
|
||||
|
||||
obj.Base = baselist
|
||||
self.execute(obj)
|
||||
#self.execute(obj)
|
||||
|
||||
|
||||
class _ViewProviderDrill:
|
||||
@@ -312,7 +317,6 @@ class CommandPathDrilling:
|
||||
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()
|
||||
@@ -324,7 +328,7 @@ class TaskPanel:
|
||||
self.form = FreeCADGui.PySideUic.loadUi(":/panels/DrillingEdit.ui")
|
||||
|
||||
def accept(self):
|
||||
self.getFields()
|
||||
#self.getFields()
|
||||
|
||||
FreeCADGui.ActiveDocument.resetEdit()
|
||||
FreeCADGui.Control.closeDialog()
|
||||
@@ -337,6 +341,7 @@ class TaskPanel:
|
||||
FreeCADGui.Selection.removeObserver(self.s)
|
||||
|
||||
def getFields(self):
|
||||
PathLog.track()
|
||||
if self.obj:
|
||||
if hasattr(self.obj, "StartDepth"):
|
||||
self.obj.StartDepth = FreeCAD.Units.Quantity(self.form.startDepth.text()).Value
|
||||
@@ -351,11 +356,13 @@ class TaskPanel:
|
||||
if hasattr(self.obj, "RetractHeight"):
|
||||
self.obj.RetractHeight = FreeCAD.Units.Quantity(self.form.retractHeight.text()).Value
|
||||
if hasattr(self.obj, "ToolController"):
|
||||
PathLog.debug("name: {}".format(self.form.uiToolController.currentText()))
|
||||
tc = PathUtils.findToolController(self.obj, self.form.uiToolController.currentText())
|
||||
self.obj.ToolController = tc
|
||||
self.obj.Proxy.execute(self.obj)
|
||||
|
||||
def setFields(self):
|
||||
PathLog.track()
|
||||
self.form.startDepth.setText(FreeCAD.Units.Quantity(self.obj.StartDepth.Value, FreeCAD.Units.Length).UserString)
|
||||
self.form.finalDepth.setText(FreeCAD.Units.Quantity(self.obj.FinalDepth.Value, FreeCAD.Units.Length).UserString)
|
||||
self.form.peckDepth.setText(FreeCAD.Units.Quantity(self.obj.PeckDepth.Value, FreeCAD.Units.Length).UserString)
|
||||
@@ -370,12 +377,20 @@ class TaskPanel:
|
||||
|
||||
controllers = PathUtils.getToolControllers(self.obj)
|
||||
labels = [c.Label for c in controllers]
|
||||
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)
|
||||
PathLog.debug("searching for TC label {}. Found Index: {}".format(self.obj.ToolController.Label, index))
|
||||
if index >= 0:
|
||||
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()
|
||||
@@ -446,6 +461,7 @@ class TaskPanel:
|
||||
return int(QtGui.QDialogButtonBox.Ok)
|
||||
|
||||
def setupUi(self):
|
||||
PathLog.track()
|
||||
|
||||
# Connect Signals and Slots
|
||||
self.form.startDepth.editingFinished.connect(self.getFields)
|
||||
|
||||
@@ -72,12 +72,12 @@ class LoadTool():
|
||||
toolnum = obj.Tooltable.Tools.keys()[0]
|
||||
commands = ""
|
||||
commands += "(" + obj.Label + ")"+'\n'
|
||||
commands += 'M6T'+str(toolnum)+'\n'
|
||||
commands += 'M6 T'+str(toolnum)+'\n'
|
||||
|
||||
if obj.SpindleDir == 'Forward':
|
||||
commands += 'M3S' + str(obj.SpindleSpeed) + '\n'
|
||||
commands += 'M3 S' + str(obj.SpindleSpeed) + '\n'
|
||||
else:
|
||||
commands += 'M4S' + str(obj.SpindleSpeed) + '\n'
|
||||
commands += 'M4 S' + str(obj.SpindleSpeed) + '\n'
|
||||
|
||||
if commands == "":
|
||||
commands += "(No commands processed)"
|
||||
@@ -245,7 +245,6 @@ class TaskPanel:
|
||||
|
||||
def getFields(self):
|
||||
if self.obj:
|
||||
|
||||
if hasattr(self.obj, "Label"):
|
||||
self.obj.Label = self.form.tcoName.text()
|
||||
if hasattr(self.obj, "VertFeed"):
|
||||
|
||||
@@ -36,10 +36,9 @@ from FreeCAD import Vector
|
||||
|
||||
LOG_MODULE = 'PathUtils'
|
||||
PathLog.setLevel(PathLog.Level.INFO, LOG_MODULE)
|
||||
PathLog.trackModule('PathUtils')
|
||||
#PathLog.trackModule('PathUtils')
|
||||
|
||||
def cleanedges(splines, precision):
|
||||
PathLog.track()
|
||||
'''cleanedges([splines],precision). Convert BSpline curves, Beziers, to arcs that can be used for cnc paths.
|
||||
Returns Lines as is. Filters Circle and Arcs for over 180 degrees. Discretizes Ellipses. Ignores other geometry. '''
|
||||
edges = []
|
||||
@@ -76,7 +75,6 @@ def cleanedges(splines, precision):
|
||||
|
||||
def curvetowire(obj, steps):
|
||||
'''adapted from DraftGeomUtils, because the discretize function changed a bit '''
|
||||
PathLog.track()
|
||||
points = obj.copy().discretize(Distance=eval('steps'))
|
||||
p0 = points[0]
|
||||
edgelist = []
|
||||
@@ -87,7 +85,6 @@ def curvetowire(obj, steps):
|
||||
return edgelist
|
||||
|
||||
def isDrillable(obj, candidate):
|
||||
PathLog.track()
|
||||
PathLog.debug('obj: {} candidate {}')
|
||||
drillable = False
|
||||
if candidate.ShapeType == 'Face':
|
||||
@@ -100,11 +97,9 @@ def isDrillable(obj, candidate):
|
||||
v1 = edge.Vertexes[1].Point
|
||||
if (v1.sub(v0).x == 0) and (v1.sub(v0).y == 0):
|
||||
# vector of top center
|
||||
lsp = Vector(face.BoundBox.Center.x,
|
||||
face.BoundBox.Center.y, face.BoundBox.ZMax)
|
||||
lsp = Vector(face.BoundBox.Center.x,face.BoundBox.Center.y, face.BoundBox.ZMax)
|
||||
# vector of bottom center
|
||||
lep = Vector(face.BoundBox.Center.x,
|
||||
face.BoundBox.Center.y, face.BoundBox.ZMin)
|
||||
lep = Vector(face.BoundBox.Center.x,face.BoundBox.Center.y, face.BoundBox.ZMin)
|
||||
if obj.isInside(lsp, 0, False) or obj.isInside(lep, 0, False):
|
||||
drillable = False
|
||||
# eliminate elliptical holes
|
||||
@@ -112,11 +107,7 @@ def isDrillable(obj, candidate):
|
||||
drillable = False
|
||||
else:
|
||||
drillable = True
|
||||
else:
|
||||
print('here')
|
||||
drillable = False
|
||||
else:
|
||||
print ('looking at edges')
|
||||
for edge in candidate.Edges:
|
||||
if (isinstance(edge.Curve, Part.Circle)):
|
||||
if abs(edge.BoundBox.XLength - edge.BoundBox.YLength) > 0.05:
|
||||
@@ -223,8 +214,6 @@ def changeTool(obj, job):
|
||||
|
||||
def getToolControllers(obj):
|
||||
'''returns all the tool controllers'''
|
||||
|
||||
PathLog.track()
|
||||
controllers = []
|
||||
try:
|
||||
parent = obj.InList[0]
|
||||
@@ -238,20 +227,40 @@ def getToolControllers(obj):
|
||||
controllers.append(g)
|
||||
return controllers
|
||||
|
||||
def findToolController(obj, name=""):
|
||||
def findToolController(obj, name=None):
|
||||
'''returns a tool controller with a given name.
|
||||
If no name is specified, returns the first controller.
|
||||
if no controller is found, returns None'''
|
||||
|
||||
PathLog.track()
|
||||
PathLog.track('name: {}'.format(name))
|
||||
controllers = getToolControllers(obj)
|
||||
for c in controllers:
|
||||
if c.Label == name:
|
||||
return c
|
||||
if len(controllers) > 0:
|
||||
return controllers[0]
|
||||
|
||||
if len(controllers) == 1:
|
||||
if name is None or name == controllers[0].Label:
|
||||
tc = controllers[0]
|
||||
else:
|
||||
tc = None
|
||||
elif name is not None:
|
||||
tc = [i for i in controllers if i.Label == name][0]
|
||||
else:
|
||||
return None
|
||||
#form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Path/DlgTCChooser.ui")
|
||||
form = FreeCADGui.PySideUic.loadUi(":/panels/DlgTCChooser.ui")
|
||||
mylist = [i.Label for i in controllers]
|
||||
form.uiToolController.addItems(mylist)
|
||||
r = form.exec_()
|
||||
if r is False:
|
||||
tc = None
|
||||
else:
|
||||
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'''
|
||||
|
||||
Reference in New Issue
Block a user