Add basic thread milling op

This commit is contained in:
Markus Lampert
2019-08-12 22:19:27 -07:00
parent dadac36234
commit b29d168132
12 changed files with 2403 additions and 6 deletions

View File

@@ -765,6 +765,23 @@ class ObjectOp(PathOp.ObjectOp):
PathLog.debug(translate("Path", "Rotated to inverse angle."))
return (clnBase, clnStock, angle)
def calculateStartFinalDepths(self, obj, shape, stock):
'''calculateStartFinalDepths(obj, shape, stock)
Calculate correct start and final depths for the shape(face) object provided.'''
finDep = max(obj.FinalDepth.Value, shape.BoundBox.ZMin)
stockTop = stock.Shape.BoundBox.ZMax
if obj.EnableRotation == 'Off':
strDep = obj.StartDepth.Value
if strDep <= finDep:
strDep = stockTop
else:
strDep = min(obj.StartDepth.Value, stockTop)
if strDep <= finDep:
strDep = stockTop
msg = translate('Path', "Start depth <= face depth.\nIncreased to stock top.")
PathLog.error(msg)
return (strDep, finDep)
def sortTuplesByIndex(self, TupleList, tagIdx):
'''sortTuplesByIndex(TupleList, tagIdx)
sort list of tuples based on tag index provided

View File

@@ -73,6 +73,7 @@ def Startup():
from PathScripts import PathSlotGui
from PathScripts import PathStop
# from PathScripts import PathSurfaceGui # Added in initGui.py due to OCL dependency
from PathScripts import PathThreadMillingGui
from PathScripts import PathToolController
from PathScripts import PathToolControllerGui
from PathScripts import PathToolLibraryManager

View File

@@ -98,19 +98,16 @@ class ENGRAVEGate(PathBaseGate):
class CHAMFERGate(PathBaseGate):
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
try:
shape = obj.Shape
except Exception: # pylint: disable=broad-except
except Exception: # pylint: disable=broad-except
return False
if math.fabs(shape.Volume) < 1e-9 and len(shape.Wires) > 0:
return True
if shape.ShapeType == 'Edge':
return True
if (shape.ShapeType == 'Face' and shape.normalAt(0, 0) == FreeCAD.Vector(0, 0, 1)):
if 'Edge' == shape.ShapeType or 'Face' == shape.ShapeType:
return True
if sub:
@@ -385,6 +382,7 @@ def select(op):
opsel['Vcarve'] = vcarveselect
opsel['Probe'] = probeselect
opsel['Custom'] = customselect
opsel['Thread Milling'] = drillselect
opsel['TurnFace'] = turnselect
opsel['TurnProfile'] = turnselect
opsel['TurnPartoff'] = turnselect

View File

@@ -0,0 +1,121 @@
# -*- coding: utf-8 -*-
# ***************************************************************************
# * *
# * Copyright (c) 2019 sliptonic <shopinthewoods@gmail.com> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
from __future__ import print_function
import FreeCAD
import Path
import PathScripts.PathCircularHoleBase as PathCircularHoleBase
import PathScripts.PathLog as PathLog
import PathScripts.PathOp as PathOp
import PathScripts.PathUtils as PathUtils
from PySide import QtCore
__title__ = "Path Thread Milling Operation"
__author__ = "sliptonic (Brad Collette)"
__url__ = "http://www.freecadweb.org"
__doc__ = "Path thread milling operation."
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())
# Qt translation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
class ObjectThreadMilling(PathCircularHoleBase.ObjectOp):
'''Proxy object for thread milling operation.'''
LeftHand = 'LeftHand'
RightHand = 'RightHand'
ThreadTypeCustom = 'Custom'
ThreadTypeMetricInternal = 'Metric - internal'
DirectionClimb = 'Climb'
ThreadOrientations = [LeftHand, RightHand]
ThreadTypes = [ThreadTypeCustom, ThreadTypeMetricInternal]
Directions = [DirectionClimb]
def circularHoleFeatures(self, obj):
return PathOp.FeatureBaseGeometry
def initCircularHoleOperation(self, obj):
obj.addProperty("App::PropertyEnumeration", "ThreadOrientation", "Thread", QtCore.QT_TRANSLATE_NOOP("App::Property", "Set thread orientation"))
obj.ThreadOrientation = self.ThreadOrientations
obj.addProperty("App::PropertyEnumeration", "ThreadType", "Thread", QtCore.QT_TRANSLATE_NOOP("App::Property", "Currently only internal"))
obj.ThreadType = self.ThreadTypes
obj.addProperty("App::PropertyString", "ThreadName", "Thread", QtCore.QT_TRANSLATE_NOOP("App::Property", "Devfines which standard thread was chosen"))
obj.addProperty("App::PropertyLength", "MajorDiameter", "Thread", QtCore.QT_TRANSLATE_NOOP("App::Property", "Set thread's major diameter"))
obj.addProperty("App::PropertyLength", "MinorDiameter", "Thread", QtCore.QT_TRANSLATE_NOOP("App::Property", "Set thread's minor diameter"))
obj.addProperty("App::PropertyLength", "Pitch", "Thread", QtCore.QT_TRANSLATE_NOOP("App::Property", "Set thread's pitch"))
obj.addProperty("App::PropertyInteger", "ThreadFit", "Thread", QtCore.QT_TRANSLATE_NOOP("App::Property", "Set how many passes are used to cut the thread"))
obj.addProperty("App::PropertyInteger", "Passes", "Mill", QtCore.QT_TRANSLATE_NOOP("App::Property", "Set how many passes are used to cut the thread"))
obj.addProperty("App::PropertyEnumeration", "Direction", "Mill", QtCore.QT_TRANSLATE_NOOP("App::Property", "Direction of thread cutting operation"))
obj.Direction = self.Directions
def circularHoleExecute(self, obj, holes):
PathLog.track()
self.commandlist.append(Path.Command("(Begin Thread Milling)"))
# rapid to clearance height
self.commandlist.append(Path.Command('G0', {'Z': obj.ClearanceHeight.Value, 'F': self.vertRapid}))
def opSetDefaultValues(self, obj, job):
obj.ThreadOrientation = self.RightHand
obj.ThreadType = self.ThreadTypeMetricInternal
obj.ThreadFit = 50
obj.Pitch = 1
obj.Passes = 1
obj.Direction = self.DirectionClimb
def SetupProperties():
setup = []
setup.append("ThreadOrientation")
setup.append("ThreadType")
setup.append("ThreadName")
setup.append("ThreadFit")
setup.append("MajorDiameter")
setup.append("MinorDiameter")
setup.append("Pitch")
setup.append("Passes")
setup.append("Direction")
return setup
def Create(name, obj=None):
'''Create(name) ... Creates and returns a thread milling operation.'''
if obj is None:
obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", name)
obj.Proxy = ObjectThreadMilling(obj, name)
if obj.Proxy:
obj.Proxy.findAllHoles(obj)
return obj

View File

@@ -0,0 +1,167 @@
# -*- coding: utf-8 -*-
# ***************************************************************************
# * *
# * Copyright (c) 2019 sliptonic <shopinthewoods@gmail.com> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
import FreeCAD
import FreeCADGui
import PathScripts.PathCircularHoleBaseGui as PathCircularHoleBaseGui
import PathScripts.PathThreadMilling as PathThreadMilling
import PathScripts.PathGui as PathGui
import PathScripts.PathLog as PathLog
import PathScripts.PathOpGui as PathOpGui
import csv
from PySide import QtCore
__title__ = "Path Thread Milling Operation UI."
__author__ = "sliptonic (Brad Collette)"
__url__ = "http://www.freecadweb.org"
__doc__ = "UI and Command for Path Thread Milling Operation."
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())
def setupCombo(combo, selections):
combo.clear()
for item in selections:
combo.addItem(item)
def fillThreads(combo, dataFile):
combo.blockSignals(True)
combo.clear()
with open("{}Mod/Path/Data/Threads/{}.csv".format(FreeCAD.getHomePath(), dataFile)) as fp:
reader = csv.DictReader(fp)
for row in reader:
combo.addItem(row['name'], row)
combo.setEnabled(True)
combo.blockSignals(False)
class TaskPanelOpPage(PathCircularHoleBaseGui.TaskPanelOpPage):
'''Controller for the thread milling operation's page'''
def initPage(self, obj):
self.majorDia = PathGui.QuantitySpinBox(self.form.threadMajor, obj, 'MajorDiameter') # pylint: disable=attribute-defined-outside-init
self.minorDia = PathGui.QuantitySpinBox(self.form.threadMinor, obj, 'MinorDiameter') # pylint: disable=attribute-defined-outside-init
self.pitch = PathGui.QuantitySpinBox(self.form.threadPitch, obj, 'Pitch') # pylint: disable=attribute-defined-outside-init
setupCombo(self.form.threadOrientation, obj.Proxy.ThreadOrientations)
setupCombo(self.form.threadType, obj.Proxy.ThreadTypes)
setupCombo(self.form.opDirection, obj.Proxy.Directions)
def getForm(self):
'''getForm() ... return UI'''
return FreeCADGui.PySideUic.loadUi(":/panels/PageOpThreadMillingEdit.ui")
def getFields(self, obj):
'''getFields(obj) ... update obj's properties with values from the UI'''
PathLog.track()
self.majorDia.updateProperty()
self.minorDia.updateProperty()
self.pitch.updateProperty()
obj.ThreadOrientation = self.form.threadOrientation.currentText()
obj.ThreadType = self.form.threadType.currentText()
obj.ThreadName = self.form.threadName.currentText()
obj.Direction = self.form.opDirection.currentText()
obj.Passes = self.form.opPasses.value()
self.updateToolController(obj, self.form.toolController)
def setFields(self, obj):
'''setFields(obj) ... update UI with obj properties' values'''
PathLog.track()
self.form.threadOrientation.setCurrentText(obj.ThreadOrientation)
self.form.threadType.blockSignals(True)
self.form.threadName.blockSignals(True)
self.form.threadType.setCurrentText(obj.ThreadType)
self._updateFromThreadType()
self.form.threadName.setCurrentText(obj.ThreadName)
self.form.threadType.blockSignals(False)
self.form.threadName.blockSignals(False)
self.form.opPasses.setValue(obj.Passes)
self.form.opDirection.setCurrentText(obj.Direction)
self.majorDia.updateSpinBox()
self.minorDia.updateSpinBox()
self.pitch.updateSpinBox()
self.setupToolController(obj, self.form.toolController)
def _updateFromThreadType(self):
if self.form.threadType.currentIndex() == 0:
PathLog.track(self.form.threadType.currentIndex())
self.form.threadName.setEnabled(False)
self.form.threadFit.setEnabled(False)
self.form.threadFitLabel.setEnabled(False)
else:
PathLog.track(self.form.threadType.currentIndex())
self.form.threadFit.setEnabled(True)
self.form.threadFitLabel.setEnabled(True)
fillThreads(self.form.threadName, 'metric-internal')
def _updateFromThreadName(self):
thread = self.form.threadName.currentData()
mamin = float(thread['dMajorMin'])
mamax = float(thread['dMajorMax'])
mimin = float(thread['dMinorMin'])
mimax = float(thread['dMinorMax'])
pitch = float(thread['pitch'])
self.pitch.updateSpinBox(pitch)
self.majorDia.updateSpinBox((mamin + mamax) / 2)
self.minorDia.updateSpinBox((mimin + mimax) / 2)
self.setDirty()
def getSignalsForUpdate(self, obj):
'''getSignalsForUpdate(obj) ... return list of signals which cause the receiver to update the model'''
signals = []
signals.append(self.form.threadMajor.editingFinished)
signals.append(self.form.threadMinor.editingFinished)
signals.append(self.form.threadPitch.editingFinished)
signals.append(self.form.toolController.currentIndexChanged)
return signals
def registerSignalHandlers(self, obj):
self.form.threadType.currentIndexChanged.connect(self._updateFromThreadType)
self.form.threadName.currentIndexChanged.connect(self._updateFromThreadName)
Command = PathOpGui.SetupOperation('Thread Milling',
PathThreadMilling.Create,
TaskPanelOpPage,
'Path-ThreadMilling',
QtCore.QT_TRANSLATE_NOOP("PathThreadMilling", "Thread Milling"),
QtCore.QT_TRANSLATE_NOOP("PathThreadMilling", "Creates a Path Thread Milling operation from features of a base object"),
PathThreadMilling.SetupProperties)
FreeCAD.Console.PrintLog("Loading PathThreadMillingGui ... done\n")