checkpoint

This commit is contained in:
sliptonic
2020-03-16 12:28:16 -05:00
parent e26f57b48f
commit 7d04aa5028
10 changed files with 127 additions and 89 deletions

View File

@@ -47,6 +47,7 @@ LastPathToolShape = "LastPathToolShape"
UseLegacyTools = "UseLegacyTools"
UseAbsoluteToolPaths = "UseAbsoluteToolPaths"
OpenLastLibrary = "OpenLastLibrary"
# Linear tolerance to use when generating Paths, eg when tessellating geometry
GeometryTolerance = "GeometryTolerance"
@@ -161,11 +162,11 @@ def toolsStoreAbsolutePaths():
def toolsOpenLastLibrary():
return preferences().GetBool(OpenLastLibrary, False)
def setToolsSettings(legacy, relative):
def setToolsSettings(legacy, relative, lastlibrary):
pref = preferences()
pref.SetBool(UseLegacyTools, legacy)
pref.SetBool(UseAbsoluteToolPaths, relative)
pref.SetBool(OpenLastLibrary, False)
pref.SetBool(OpenLastLibrary, lastlibrary)
def defaultJobTemplate():
template = preferences().GetString(DefaultJobTemplate)

View File

@@ -109,7 +109,9 @@ class JobPreferencesPage:
PathPreferences.setDefaultStockTemplate('')
def saveToolsSettings(self):
PathPreferences.setToolsSettings(self.form.toolsUseLegacy.isChecked(), self.form.toolsAbsolutePaths.isChecked())
PathPreferences.setToolsSettings(self.form.toolsUseLegacy.isChecked(),
self.form.toolsAbsolutePaths.isChecked(),
self.form.toolsOpenLastLibrary.isChecked())
def selectComboEntry(self, widget, text):
index = widget.findText(text, QtCore.Qt.MatchFixedString)

View File

@@ -142,6 +142,13 @@ class PropertyString(Property):
def typeString(self):
return "String"
class PropertyMap(Property):
def typeString(self)
return "Map"
def displayString(self, value):
return str(value)
class OpPrototype(object):
PropertyType = {
@@ -159,6 +166,7 @@ class OpPrototype(object):
'App::PropertyLink': Property,
'App::PropertyLinkList': Property,
'App::PropertyLinkSubListGlobal': Property,
'App::PropertyMap': PropertyMap,
'App::PropertyPercent': PropertyPercent,
'App::PropertyString': PropertyString,
'App::PropertyStringList': Property,

View File

@@ -195,6 +195,7 @@ class ToolBit(object):
def onDelete(self, obj, arg2=None):
PathLog.track(obj.Label)
self.unloadBitBody(obj)
obj.Document.removeObject(obj.Name)
def _updateBitShape(self, obj, properties=None):
if not obj.BitBody is None:
@@ -230,6 +231,7 @@ class ToolBit(object):
return (doc, docOpened)
def _removeBitBody(self, obj):
print('in _removebitbody')
if obj.BitBody:
obj.BitBody.removeObjectsFromDocument()
obj.Document.removeObject(obj.BitBody.Name)
@@ -326,6 +328,7 @@ class ToolBit(object):
attrs['parameter'] = params
params = {}
for name in self.propertyNamesAttribute(obj):
print(f"shapeattr {name}")
params[name] = PathUtil.getPropertyValueString(obj, name)
attrs['attribute'] = params
return attrs
@@ -343,6 +346,7 @@ class AttributePrototype(PathSetupSheetOpPrototype.OpPrototype):
self.addProperty('App::PropertyDistance', 'LengthOffset', PropertyGroupAttribute, translate('PathToolBit', 'Length offset in Z direction'))
self.addProperty('App::PropertyInteger', 'Flutes', PropertyGroupAttribute, translate('PathToolBit', 'The number of flutes'))
self.addProperty('App::PropertyDistance', 'ChipLoad', PropertyGroupAttribute, translate('PathToolBit', 'Chipload as per manufacturer'))
# self.addProperty('App::PropertyMap', 'UserAttributes', PropertyGroupAttribute, translate('PathTooolBit', 'User Defined Values'))
class ToolBitFactory(object):
@@ -358,11 +362,21 @@ class ToolBitFactory(object):
obj.Proxy.unloadBitBody(obj)
params = attrs['attribute']
proto = AttributePrototype()
uservals = {}
for pname in params:
prop = proto.getProperty(pname)
val = prop.valueFromString(params[pname])
try:
prop = proto.getProperty(pname)
val = prop.valueFromString(params[pname])
prop.setupProperty(obj, pname, PropertyGroupAttribute, prop.valueFromString(params[pname]))
except:
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 = .setupPropertyobj, pname, "UserAttributes", prop.valueFromString(params[pname]))
print("prop[%s] = %s (%s)" % (pname, params[pname], type(val)))
prop.setupProperty(obj, pname, PropertyGroupAttribute, prop.valueFromString(params[pname]))
#prop.setupProperty(obj, pname, PropertyGroupAttribute, prop.valueFromString(params[pname]))
return obj
def CreateFrom(self, path, name='ToolBit'):

View File

@@ -88,6 +88,7 @@ class ToolBitEditor(object):
self.model.setHorizontalHeaderLabels(['Set', 'Property', 'Value'])
for i, name in enumerate(self.props):
print(f"propname: {name}")
prop = self.proto.getProperty(name)
isset = hasattr(tool, name)
if isset:

View File

@@ -25,6 +25,7 @@
import FreeCAD
import FreeCADGui
import PySide.QtCore as QtCore
import PathScripts.PathPreferences as PathPreferences
class CommandToolBitLibraryOpen:
'''
@@ -45,7 +46,13 @@ class CommandToolBitLibraryOpen:
def Activated(self):
import PathScripts.PathToolBitLibraryGui as PathToolBitLibraryGui
library = PathToolBitLibraryGui.ToolBitLibrary()
library.open()
lastlib = PathPreferences.lastPathToolLibrary()
if PathPreferences.toolsOpenLastLibrary() and lastlib.endswith('.fctl'):
library.open(lastlib)
else:
library.open()
class CommandToolBitLibraryLoad:
'''
@@ -83,6 +90,7 @@ class CommandToolBitLibraryLoad:
import PathScripts.PathToolControllerGui as PathToolControllerGui
library = PathToolBitLibraryGui.ToolBitLibrary()
if 1 == library.open(dialog=True) and job:
for nr, tool in library.selectedOrAllTools():
tc = PathToolControllerGui.Create("TC: {}".format(tool.Label), tool, nr)

View File

@@ -30,6 +30,8 @@ import PathScripts.PathPreferences as PathPreferences
import PathScripts.PathToolBit as PathToolBit
import PathScripts.PathToolBitGui as PathToolBitGui
import PathScripts.PathToolBitEdit as PathToolBitEdit
import PathScripts.PathToolControllerGui as PathToolControllerGui
import PathScripts.PathUtilsGui as PathUtilsGui
import PySide
import json
import os
@@ -192,6 +194,17 @@ class ToolBitLibrary(object):
tools.append((toolNr, PathToolBit.Factory.CreateFrom(toolPath)))
return tools
def selectedOrAllToolControllers(self):
tools = self.selectedOrAllTools()
userinput = PathUtilsGui.PathUtilsUserInput()
job = userinput.chooseJob(PathUtilsGui.PathUtils.GetJobs())
for tool in tools:
print(tool)
tc = PathToolControllerGui.Create(tool[1].Label, tool[1], tool[0])
job.Proxy.addToolController(tc)
FreeCAD.ActiveDocument.recompute()
def toolDelete(self):
PathLog.track()
selectedRows = set([index.row() for index in self.toolTableView.selectedIndexes()])
@@ -205,7 +218,17 @@ class ToolBitLibrary(object):
def toolSelect(self, selected, deselected):
# pylint: disable=unused-argument
self.form.toolDelete.setEnabled(len(self.toolTableView.selectedIndexes()) > 0)
sel = len(self.toolTableView.selectedIndexes()) > 0
self.form.toolDelete.setEnabled(sel)
addTCSelectedText = translate("PathToolLibraryManager", "Add SELECTED as Tool Controllers in the Job")
addTCAllText = translate("PathToolLibraryManager", "Add ALL as Tool Controllers in the Job")
if sel:
self.form.addToolController.setText(addTCSelectedText)
else:
self.form.addToolController.setText(addTCAllText)
def open(self, path=None, dialog=False):
'''open(path=None, dialog=False) ... load library stored in path and bring up ui.
@@ -230,11 +253,14 @@ class ToolBitLibrary(object):
PathLog.track()
filename = PySide.QtGui.QFileDialog.getOpenFileName(self.form, 'Tool Library', PathPreferences.lastPathToolLibrary(), '*.fctl')
if filename and filename[0]:
print(filename)
print(filename[0])
path = filename[0]
PathPreferences.setLastPathToolLibrary(filename[0])
if not PathPreferences.toolsOpenLastLibrary():
path = os.path.dirname(path)
PathPreferences.setLastPathToolLibrary(os.path.dirname(filename[0]))
#path = os.path.dirname(path)
self.libraryLoad(path)
@@ -264,20 +290,20 @@ class ToolBitLibrary(object):
def libraryNew(self):
self.libraryLoad(None)
def createToolBit(self):
tool = PathToolBit.ToolBitFactory().Create()
#def createToolBit(self):
# tool = PathToolBit.ToolBitFactory().Create()
#self.dialog = PySide.QtGui.QDialog(self.form)
#layout = PySide.QtGui.QVBoxLayout(self.dialog)
self.editor = PathToolBitEdit.ToolBitEditor(tool, self.form.toolTableGroup)
self.editor.setupUI()
self.buttons = PySide.QtGui.QDialogButtonBox(
PySide.QtGui.QDialogButtonBox.Ok | PySide.QtGui.QDialogButtonBox.Cancel,
PySide.QtCore.Qt.Horizontal, self.dialog)
layout.addWidget(self.buttons)
#self.buttons.accepted.connect(accept)
#self.buttons.rejected.connect(reject)
print(self.dialog.exec_())
# #self.dialog = PySide.QtGui.QDialog(self.form)
# #layout = PySide.QtGui.QVBoxLayout(self.dialog)
# self.editor = PathToolBitEdit.ToolBitEditor(tool, self.form.toolTableGroup)
# self.editor.setupUI()
# self.buttons = PySide.QtGui.QDialogButtonBox(
# PySide.QtGui.QDialogButtonBox.Ok | PySide.QtGui.QDialogButtonBox.Cancel,
# PySide.QtCore.Qt.Horizontal, self.dialog)
# layout.addWidget(self.buttons)
# #self.buttons.accepted.connect(accept)
# #self.buttons.rejected.connect(reject)
# print(self.dialog.exec_())
def librarySave(self):
library = {}
@@ -367,12 +393,22 @@ class ToolBitLibrary(object):
self.librarySave()
self.updateToolbar()
def libraryCancel(self):
self.form.close()
def columnNames(self):
return ['Nr', 'Tool', 'Shape', 'Diameter']
def toolEdit(self, selected):
print('here')
print(selected)
if selected.column() == 0:
print('nope')
else:
print('yep')
def setupUI(self):
PathLog.track('+')
self.model = PySide.QtGui.QStandardItemModel(0, len(self.columnNames()), self.toolTableView)
@@ -381,11 +417,12 @@ class ToolBitLibrary(object):
self.toolTableView.setModel(self.model)
self.toolTableView.resizeColumnsToContents()
self.toolTableView.selectionModel().selectionChanged.connect(self.toolSelect)
self.toolTableView.doubleClicked.connect(self.toolEdit)
self.form.toolAdd.clicked.connect(self.toolAdd)
self.form.toolDelete.clicked.connect(self.toolDelete)
self.form.toolEnumerate.clicked.connect(self.toolEnumerate)
self.form.createToolBit.clicked.connect(self.createToolBit)
# self.form.createToolBit.clicked.connect(self.createToolBit)
#self.form.libraryNew.clicked.connect(self.libraryNew)
self.form.libraryOpen.clicked.connect(self.libraryOpen)
@@ -393,6 +430,8 @@ class ToolBitLibrary(object):
self.form.librarySaveAs.clicked.connect(self.librarySaveAs)
self.form.libraryCancel.clicked.connect(self.libraryCancel)
self.form.addToolController.clicked.connect(self.selectedOrAllToolControllers)
self.toolSelect([], [])
self.updateToolbar()
PathLog.track('-')