Skip to content

Commit

Permalink
fix 'add' button in Job task panel
Browse files Browse the repository at this point in the history
fix chamfer bit
lgtm cleanup
  • Loading branch information
sliptonic committed Nov 19, 2020
1 parent 26eac12 commit 634fce6
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 52 deletions.
2 changes: 0 additions & 2 deletions src/Mod/Path/PathScripts/PathJob.py
Expand Up @@ -103,7 +103,6 @@ class NotificationClass(QtCore.QObject):

class ObjectJob:


def __init__(self, obj, models, templateFile=None):
self.obj = obj
obj.addProperty("App::PropertyFile", "PostProcessorOutputFile", "Output", QtCore.QT_TRANSLATE_NOOP("PathJob", "The NC output file for this project"))
Expand Down Expand Up @@ -155,7 +154,6 @@ def __init__(self, obj, models, templateFile=None):
self.tooltip = None
self.tooltipArgs = None


obj.Proxy = self

self.setFromTemplateFile(obj, templateFile)
Expand Down
12 changes: 10 additions & 2 deletions src/Mod/Path/PathScripts/PathJobGui.py
Expand Up @@ -25,7 +25,6 @@
from contextlib import contextmanager
import math
import traceback

from pivy import coin
from PySide import QtCore, QtGui

Expand All @@ -45,6 +44,7 @@
import PathScripts.PathToolLibraryEditor as PathToolLibraryEditor
import PathScripts.PathUtil as PathUtil
import PathScripts.PathUtils as PathUtils
import PathScripts.PathToolBitGui as PathToolBitGui

# lazily loaded modules
from lazy_loader.lazy_loader import LazyLoader
Expand Down Expand Up @@ -866,7 +866,15 @@ def toolControllerEdit(self):
self.toolControllerSelect()

def toolControllerAdd(self):
PathToolLibraryEditor.CommandToolLibraryEdit().edit(self.obj, self.updateToolController)
if PathPreferences.toolsUseLegacyTools():
PathToolLibraryEditor.CommandToolLibraryEdit().edit(self.obj, self.updateToolController)
else:
tools = PathToolBitGui.LoadTools()
for tool in tools:
tc = PathToolControllerGui.Create(name=tool.Label, tool=tool)
self.obj.Proxy.addToolController(tc)
FreeCAD.ActiveDocument.recompute()
self.updateToolController()

def toolControllerDelete(self):
self.objectDelete(self.form.toolControllerList)
Expand Down
7 changes: 5 additions & 2 deletions src/Mod/Path/PathScripts/PathOpGui.py
Expand Up @@ -545,7 +545,7 @@ def selectionSupportedAsBaseGeometry(self, selection, ignoreErrors):
PathLog.error(translate("PathProject", "Faces are not supported"))
return False
else:
if not self.supportsPanels() or not 'Panel' in sel.Object.Name:
if not self.supportsPanels() or 'Panel' not in sel.Object.Name:
if not ignoreErrors:
PathLog.error(translate("PathProject", "Please select %s of a solid" % self.featureName()))
return False
Expand Down Expand Up @@ -636,6 +636,7 @@ def resizeBaseList(self):
row = (qList.count() + qList.frameWidth()) * 15
qList.setFixedSize(col, row)


class TaskPanelBaseLocationPage(TaskPanelPage):
'''Page controller for base locations. Uses PathGetPoint.'''

Expand Down Expand Up @@ -936,6 +937,7 @@ def updateSelection(self, obj, sel):
self.form.startDepthSet.setEnabled(False)
self.form.finalDepthSet.setEnabled(False)


class TaskPanelDiametersPage(TaskPanelPage):
'''Page controller for diameters.'''

Expand All @@ -960,7 +962,7 @@ def getFields(self, obj):
self.minDiameter.updateProperty()
self.maxDiameter.updateProperty()

def setFields(self, obj):
def setFields(self, obj):
self.minDiameter.updateSpinBox()
self.maxDiameter.updateSpinBox()

Expand All @@ -974,6 +976,7 @@ def pageUpdateData(self, obj, prop):
if prop in ['MinDiameter', 'MaxDiameter']:
self.setFields(obj)


class TaskPanel(object):
'''
Generic TaskPanel implementation handling the standard Path operation layout.
Expand Down
4 changes: 0 additions & 4 deletions src/Mod/Path/PathScripts/PathProfileGui.py
Expand Up @@ -128,8 +128,6 @@ def getSignalsForUpdate(self, obj):

def updateVisibility(self):
hasFace = False
# hasGeom = False
# fullModel = False
objBase = list()

if hasattr(self.obj, 'Base'):
Expand All @@ -141,8 +139,6 @@ def updateVisibility(self):
if sub[:4] == 'Face':
hasFace = True
break
else:
fullModel = True

if hasFace:
self.form.processCircles.show()
Expand Down
10 changes: 2 additions & 8 deletions src/Mod/Path/PathScripts/PathToolBit.py
Expand Up @@ -59,8 +59,7 @@ def translate(context, text, disambig=None):


def _findTool(path, typ, dbg=False):
# PathLog.track("Path: {} typ: {}".format(path, typ))
if os.path.exists(path): # absolute reference
if os.path.exists(path): # absolute reference
if dbg:
PathLog.debug("Found {} at {}".format(typ, path))
return path
Expand Down Expand Up @@ -397,6 +396,7 @@ def __init__(self):
PropertyGroupAttribute, translate('PathToolBit',
'Whether Spindle Power should be allowed'))


class ToolBitFactory(object):

def CreateFromAttrs(self, attrs, name='ToolBit'):
Expand All @@ -414,21 +414,15 @@ def CreateFromAttrs(self, attrs, name='ToolBit'):
for pname in params:
try:
prop = proto.getProperty(pname)
# val = prop.valueFromString(params[pname])
prop.setupProperty(obj, pname, PropertyGroupAttribute, prop.valueFromString(params[pname]))
except Exception:
# prop = obj.addProperty('App::PropertyString', pname, "Attribute", translate('PathTooolBit', 'User Defined Value'))
# setattr(obj, pname, params[pname])
prop = proto.getProperty("UserAttributes")
uservals.update({pname: params[pname]})
# prop.setupProperty(obj, pname, "UserAttributes", prop.valueFromString(params[pname]))

if len(uservals.items()) > 0:
prop.setupProperty(obj, "UserAttributes",
PropertyGroupAttribute, uservals)

# print("prop[%s] = %s (%s)" % (pname, params[pname], type(val)))
# prop.setupProperty(obj, pname, PropertyGroupAttribute, prop.valueFromString(params[pname]))
return obj

def CreateFrom(self, path, name='ToolBit'):
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Path/PathScripts/PathToolBitEdit.py
Expand Up @@ -31,8 +31,8 @@

from PySide import QtCore, QtGui

# PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
# PathLog.trackModule(PathLog.thisModule())
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())


# Qt translation handling
Expand Down
8 changes: 4 additions & 4 deletions src/Mod/Path/PathScripts/PathToolBitGui.py
Expand Up @@ -41,8 +41,9 @@
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)

# PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
# PathLog.trackModule(PathLog.thisModule())

PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())


class ViewProvider(object):
Expand Down Expand Up @@ -141,8 +142,7 @@ def reject(self):
self.editor.reject()
FreeCADGui.Control.closeDialog()
if self.deleteOnReject:
FreeCAD.ActiveDocument.openTransaction(translate('PathToolBit',
'Uncreate ToolBit'))
FreeCAD.ActiveDocument.openTransaction(translate('PathToolBit', 'Uncreate ToolBit'))
self.editor.reject()
FreeCAD.ActiveDocument.removeObject(self.obj.Name)
FreeCAD.ActiveDocument.commitTransaction()
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py
Expand Up @@ -129,6 +129,7 @@ def Activated(self):
# return True
# return False


if FreeCAD.GuiUp:
FreeCADGui.addCommand('Path_ToolBitLibraryOpen', CommandToolBitLibraryOpen())
FreeCADGui.addCommand('Path_ToolBitDock', CommandToolBitSelectorOpen())
Expand Down
17 changes: 3 additions & 14 deletions src/Mod/Path/PathScripts/PathToolBitLibraryGui.py
Expand Up @@ -36,7 +36,6 @@
import json
import os
import glob
import traceback
import uuid as UUID
from functools import partial

Expand Down Expand Up @@ -130,7 +129,6 @@ def __init__(self, path=None):
self.path = ""
# self.currentLib = ""


def __libraryLoad(self, path, datamodel):
PathLog.track(path)
PathPreferences.setLastFileToolLibrary(path)
Expand All @@ -153,7 +151,6 @@ def __libraryLoad(self, path, datamodel):
msg = "Error loading tool: {} : {}".format(toolBit['path'], e)
FreeCAD.Console.PrintError(msg)


def _toolAdd(self, nr, tool, path):

strShape = os.path.splitext(os.path.basename(tool['shape']))[0]
Expand All @@ -176,11 +173,6 @@ def _toolAdd(self, nr, tool, path):
toolShape.setData(strShape, PySide.QtCore.Qt.EditRole)
toolShape.setEditable(False)

# toolDiameter = PySide.QtGui.QStandardItem()
# toolDiameter.setData(strDiam, PySide.QtCore.Qt.EditRole)
# toolDiameter.setEditable(False)

#return [toolNr, toolName, toolShape, toolDiameter]
return [toolNr, toolName, toolShape]

def newTool(self, datamodel, path):
Expand All @@ -196,8 +188,8 @@ def newTool(self, datamodel, path):
nr = max(nr, itemNr)
nr += 1
tool = PathToolBit.Declaration(path)
except Exception:
PathLog.error(traceback.print_exc())
except Exception as e:
PathLog.error(e)

datamodel.appendRow(self._toolAdd(nr, tool, path))

Expand Down Expand Up @@ -388,7 +380,7 @@ def toolBitNew(self):
return

filename = PathToolBitGui.GetNewToolFile()
if filename == None:
if filename is None:
return

# Parse out the name of the file and write the structure
Expand Down Expand Up @@ -569,7 +561,6 @@ def libraryOk(self):
def libPaths(self):
lib = PathPreferences.lastFileToolLibrary()
loc = PathPreferences.lastPathToolLibrary()
#loc = os.path.split(lib)[0]

PathLog.track("lib: {} loc: {}".format(lib, loc))
return lib, loc
Expand All @@ -582,7 +573,6 @@ def loadData(self, path=None):
self.toolTableView.setUpdatesEnabled(False)
self.form.TableList.setUpdatesEnabled(False)


if path is None:
path, loc = self.libPaths()

Expand All @@ -600,7 +590,6 @@ def loadData(self, path=None):
self.toolModel.setHorizontalHeaderLabels(self.columnNames())
self.listModel.setHorizontalHeaderLabels(['Library'])


# Select the current library in the list of tables
curIndex = None
for i in range(self.listModel.rowCount()):
Expand Down
2 changes: 0 additions & 2 deletions src/Mod/Path/PathScripts/PathToolController.py
Expand Up @@ -98,7 +98,6 @@ def onDelete(self, obj, arg2=None):
if hasattr(obj.Tool, 'InList') and len(obj.Tool.InList) == 1:
if hasattr(obj.Tool.Proxy, 'onDelete'):
obj.Tool.Proxy.onDelete(obj.Tool)
#obj.Document.removeObject(obj.Name)

def setFromTemplate(self, obj, template):
'''
Expand Down Expand Up @@ -177,7 +176,6 @@ def execute(self, obj):
commands += "(" + obj.Label + ")"+'\n'
commands += 'M6 T'+str(obj.ToolNumber)+'\n'


# If a toolbit is used, check to see if spindlepower is allowed.
# This is to prevent accidentally spinning the spindle with an
# unpowered tool like probe or dragknife
Expand Down
36 changes: 24 additions & 12 deletions src/Mod/Path/PathScripts/PathToolControllerGui.py
Expand Up @@ -35,10 +35,12 @@
from lazy_loader.lazy_loader import LazyLoader
Part = LazyLoader('Part', globals(), 'Part')


# Qt translation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)


class ViewProvider:

def __init__(self, vobj):
Expand Down Expand Up @@ -122,7 +124,8 @@ def claimChildren(self):
return [obj.Tool]
return []

def Create(name = 'Default Tool', tool=None, toolNumber=1):

def Create(name='Default Tool', tool=None, toolNumber=1):
PathLog.track(tool, toolNumber)

obj = PathScripts.PathToolController.Create(name, tool, toolNumber)
Expand Down Expand Up @@ -172,6 +175,7 @@ def Activated(self):
job.Proxy.addToolController(tc)
FreeCAD.ActiveDocument.recompute()


class ToolControllerEditor(object):

def __init__(self, obj, asDialog):
Expand All @@ -180,13 +184,18 @@ def __init__(self, obj, asDialog):
self.form.buttonBox.hide()
self.obj = obj

self.vertFeed = PathGui.QuantitySpinBox(self.form.vertFeed, obj, 'VertFeed')
self.horizFeed = PathGui.QuantitySpinBox(self.form.horizFeed, obj, 'HorizFeed')
self.vertRapid = PathGui.QuantitySpinBox(self.form.vertRapid, obj, 'VertRapid')
self.horizRapid = PathGui.QuantitySpinBox(self.form.horizRapid, obj, 'HorizRapid')
self.vertFeed = PathGui.QuantitySpinBox(self.form.vertFeed, obj,
'VertFeed')
self.horizFeed = PathGui.QuantitySpinBox(self.form.horizFeed, obj,
'HorizFeed')
self.vertRapid = PathGui.QuantitySpinBox(self.form.vertRapid, obj,
'VertRapid')
self.horizRapid = PathGui.QuantitySpinBox(self.form.horizRapid, obj,
'HorizRapid')

if obj.Proxy.usesLegacyTool(obj):
self.editor = PathToolEdit.ToolEditor(obj.Tool, self.form.toolEditor)
self.editor = PathToolEdit.ToolEditor(obj.Tool,
self.form.toolEditor)
else:
self.editor = None
self.form.toolBox.widget(1).hide()
Expand All @@ -201,7 +210,8 @@ def updateUi(self):
self.vertFeed.updateSpinBox()
self.vertRapid.updateSpinBox()
self.form.spindleSpeed.setValue(tc.SpindleSpeed)
index = self.form.spindleDirection.findText(tc.SpindleDir, QtCore.Qt.MatchFixedString)
index = self.form.spindleDirection.findText(tc.SpindleDir,
QtCore.Qt.MatchFixedString)
if index >= 0:
self.form.spindleDirection.setCurrentIndex(index)

Expand All @@ -224,9 +234,9 @@ def updateToolController(self):
self.editor.updateTool()
tc.Tool = self.editor.tool

except Exception as e: # pylint: disable=broad-except
PathLog.error(translate("PathToolController", "Error updating TC: %s") % e)

except Exception as e:
PathLog.error(translate("PathToolController",
"Error updating TC: %s") % e)

def refresh(self):
self.form.blockSignals(True)
Expand Down Expand Up @@ -296,7 +306,8 @@ def resetObject(self, remove=None):
def setupUi(self):
if self.editor.editor:
t = Part.makeCylinder(1, 1)
self.toolrep = FreeCAD.ActiveDocument.addObject("Part::Feature", "tool")
self.toolrep = FreeCAD.ActiveDocument.addObject("Part::Feature",
"tool")
self.toolrep.Shape = t

self.setFields()
Expand All @@ -311,7 +322,7 @@ def __init__(self, obj):
self.obj = obj

def exec_(self):
restoreTC = self.obj.Proxy.templateAttrs(self.obj)
restoreTC = self.obj.Proxy.templateAttrs(self.obj)

rc = False
if not self.editor.form.exec_():
Expand All @@ -320,6 +331,7 @@ def exec_(self):
rc = True
return rc


if FreeCAD.GuiUp:
# register the FreeCAD command
FreeCADGui.addCommand('Path_ToolController', CommandPathToolController())
Expand Down
Binary file modified src/Mod/Path/Tools/Shape/chamfer.fcstd
Binary file not shown.

0 comments on commit 634fce6

Please sign in to comment.