From 29e714da02df398a8fd6377298d85b261af26d5a Mon Sep 17 00:00:00 2001 From: sliptonic Date: Mon, 15 Feb 2021 11:36:08 -0600 Subject: [PATCH 1/7] remove deprecated preference setting --- .../Path/Gui/Resources/preferences/PathJob.ui | 18 ++++-------------- src/Mod/Path/PathScripts/PathPreferences.py | 10 +++++----- .../Path/PathScripts/PathPreferencesPathJob.py | 3 +-- .../Path/PathScripts/PathToolBitLibraryCmd.py | 16 ++-------------- 4 files changed, 12 insertions(+), 35 deletions(-) diff --git a/src/Mod/Path/Gui/Resources/preferences/PathJob.ui b/src/Mod/Path/Gui/Resources/preferences/PathJob.ui index 15c9cfcb30..a97cc76815 100644 --- a/src/Mod/Path/Gui/Resources/preferences/PathJob.ui +++ b/src/Mod/Path/Gui/Resources/preferences/PathJob.ui @@ -142,8 +142,8 @@ 0 0 - 366 - 330 + 424 + 537 @@ -348,8 +348,8 @@ 0 0 - 319 - 528 + 424 + 537 @@ -653,16 +653,6 @@ - - - - <html><head/><body><p>Causes the toollibrary manager to remember last directory. This ONLY affects legacy tools. </p><p>This control is deprecated and will be removed in a future version</p></body></html> - - - Remember last library (legacy) - - - diff --git a/src/Mod/Path/PathScripts/PathPreferences.py b/src/Mod/Path/PathScripts/PathPreferences.py index ff07fc1cbb..caf86212cd 100644 --- a/src/Mod/Path/PathScripts/PathPreferences.py +++ b/src/Mod/Path/PathScripts/PathPreferences.py @@ -51,7 +51,7 @@ LastFileToolShape = "LastFileToolShape" UseLegacyTools = "UseLegacyTools" UseAbsoluteToolPaths = "UseAbsoluteToolPaths" -OpenLastLibrary = "OpenLastLibrary" +# OpenLastLibrary = "OpenLastLibrary" # Linear tolerance to use when generating Paths, eg when tessellating geometry GeometryTolerance = "GeometryTolerance" @@ -166,15 +166,15 @@ def toolsStoreAbsolutePaths(): return preferences().GetBool(UseAbsoluteToolPaths, False) -def toolsOpenLastLibrary(): - return preferences().GetBool(OpenLastLibrary, False) +# def toolsOpenLastLibrary(): +# return preferences().GetBool(OpenLastLibrary, False) -def setToolsSettings(legacy, relative, lastlibrary): +def setToolsSettings(legacy, relative): pref = preferences() pref.SetBool(UseLegacyTools, legacy) pref.SetBool(UseAbsoluteToolPaths, relative) - pref.SetBool(OpenLastLibrary, lastlibrary) + # pref.SetBool(OpenLastLibrary, lastlibrary) def defaultJobTemplate(): diff --git a/src/Mod/Path/PathScripts/PathPreferencesPathJob.py b/src/Mod/Path/PathScripts/PathPreferencesPathJob.py index e684415288..eba1549363 100644 --- a/src/Mod/Path/PathScripts/PathPreferencesPathJob.py +++ b/src/Mod/Path/PathScripts/PathPreferencesPathJob.py @@ -108,8 +108,7 @@ class JobPreferencesPage: def saveToolsSettings(self): PathPreferences.setToolsSettings(self.form.toolsUseLegacy.isChecked(), - self.form.toolsAbsolutePaths.isChecked(), - self.form.toolsOpenLastLibrary.isChecked()) + self.form.toolsAbsolutePaths.isChecked()) def selectComboEntry(self, widget, text): index = widget.findText(text, QtCore.Qt.MatchFixedString) diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py b/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py index 6c3d82b834..f47bedf520 100644 --- a/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py +++ b/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py @@ -47,13 +47,7 @@ class CommandToolBitSelectorOpen: def Activated(self): import PathScripts.PathToolBitLibraryGui as PathToolBitLibraryGui dock = PathToolBitLibraryGui.ToolBitSelector() - - lastlib = PathPreferences.lastPathToolLibrary() - - if PathPreferences.toolsOpenLastLibrary(): - dock.open(lastlib) - else: - dock.open() + dock.open() class CommandToolBitLibraryOpen: @@ -76,13 +70,7 @@ class CommandToolBitLibraryOpen: def Activated(self): import PathScripts.PathToolBitLibraryGui as PathToolBitLibraryGui library = PathToolBitLibraryGui.ToolBitLibrary() - - lastlib = PathPreferences.lastPathToolLibrary() - - if PathPreferences.toolsOpenLastLibrary(): - library.open(lastlib) - else: - library.open() + library.open() # class CommandToolBitLibraryLoad: # ''' From 42c769d635935ef824ca4ddd06f4f2140aa78a05 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Wed, 17 Feb 2021 09:19:00 -0600 Subject: [PATCH 2/7] fix #4572 --- src/Mod/Path/PathScripts/PathPropertyBag.py | 16 ++++++++++++++++ src/Mod/Path/PathScripts/PathPropertyBagGui.py | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathPropertyBag.py b/src/Mod/Path/PathScripts/PathPropertyBag.py index 2b21be2c6b..eefee2ed30 100644 --- a/src/Mod/Path/PathScripts/PathPropertyBag.py +++ b/src/Mod/Path/PathScripts/PathPropertyBag.py @@ -67,6 +67,18 @@ class PropertyBag(object): def __setstate__(self, state): return None + def __sanitizePropertyName(self, name): + if(len(name) == 0): + return + clean = name[0].lower() + for i in range(1, len(name)): + if (name[i] == ' '): + clean += name[i + 1].upper() + i += 1 + elif(name[i - 1] != ' '): + clean += name[i] + return clean + def onDocumentRestored(self, obj): self.obj = obj obj.setEditorMode(self.CustomPropertyGroups, 2) # hide @@ -82,10 +94,14 @@ class PropertyBag(object): if group is None: group = self.CustomPropertyGroupDefault groups = self.obj.CustomPropertyGroups + + name = self.__sanitizePropertyName(name) + if not group in groups: groups.append(group) self.obj.CustomPropertyGroups = groups self.obj.addProperty(propertyType, name, group, desc) + return name def refreshCustomPropertyGroups(self): '''refreshCustomPropertyGroups() ... removes empty property groups, should be called after deleting properties.''' diff --git a/src/Mod/Path/PathScripts/PathPropertyBagGui.py b/src/Mod/Path/PathScripts/PathPropertyBagGui.py index 6140e3540f..a0e1b03fb4 100644 --- a/src/Mod/Path/PathScripts/PathPropertyBagGui.py +++ b/src/Mod/Path/PathScripts/PathPropertyBagGui.py @@ -299,10 +299,10 @@ class TaskPanel(object): typ = dialog.propertyType() grp = dialog.propertyGroup() info = dialog.propertyInfo() - self.obj.Proxy.addCustomProperty(typ, name, grp, info) + propname = self.obj.Proxy.addCustomProperty(typ, name, grp, info) if dialog.propertyIsEnumeration(): setattr(self.obj, name, dialog.propertyEnumerations()) - return (name, info) + return (propname, info) def propertyAdd(self): PathLog.track() From 0dfa61150379aed89df2ecb8a0f4f13a8330e6da Mon Sep 17 00:00:00 2001 From: sliptonic Date: Wed, 3 Feb 2021 12:00:07 -0600 Subject: [PATCH 3/7] fix typos --- src/Mod/Path/PathScripts/PathDressupTag.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathDressupTag.py b/src/Mod/Path/PathScripts/PathDressupTag.py index bbfc349358..30e2243a52 100644 --- a/src/Mod/Path/PathScripts/PathDressupTag.py +++ b/src/Mod/Path/PathScripts/PathDressupTag.py @@ -224,7 +224,7 @@ class ObjectDressup: def toolRadius(self): return float(PathDressup.toolController(self.obj.Base).Tool.Diameter) / 2.0 - def addTagsToDocuemnt(self): + def addTagsToDocument(self): for i, solid in enumerate(self.solids): obj = FreeCAD.ActiveDocument.addObject('Part::Compound', "tag_%02d" % i) obj.Shape = solid @@ -256,7 +256,7 @@ def Create(baseObject, name='DressupTag'): obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", name) dbo = ObjectDressup(obj, baseObject) job = PathUtils.findParentJob(baseObject) - job.adddOperation(obj) + job.addOperation(obj) dbo.assignDefaultValues() return obj From 257159fc1ba44d56815b8c7863b9fa586b908272 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Wed, 3 Feb 2021 12:00:29 -0600 Subject: [PATCH 4/7] fix lgtm error --- .../Path/PathScripts/PathToolBitLibraryCmd.py | 46 +------------------ 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py b/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py index f47bedf520..5d03f72fe0 100644 --- a/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py +++ b/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py @@ -70,53 +70,9 @@ class CommandToolBitLibraryOpen: def Activated(self): import PathScripts.PathToolBitLibraryGui as PathToolBitLibraryGui library = PathToolBitLibraryGui.ToolBitLibrary() + library.open() -# class CommandToolBitLibraryLoad: -# ''' -# Command used to load an entire ToolBitLibrary (or part of it) from a file into a job. -# ''' - -# def __init__(self): -# pass - -# def GetResources(self): -# return {'Pixmap': 'Path_ToolTable', -# 'MenuText': QtCore.QT_TRANSLATE_NOOP("PathToolBitLibrary", "Load ToolBit Library"), -# 'ToolTip': QtCore.QT_TRANSLATE_NOOP("PathToolBitLibrary", "Load an entire ToolBit library or part of it into a job")} - -# def selectedJob(self): -# if FreeCAD.ActiveDocument: -# sel = FreeCADGui.Selection.getSelectionEx() -# if sel and sel[0].Object.Name[:3] == 'Job': -# return sel[0].Object -# jobs = [o for o in FreeCAD.ActiveDocument.Objects if o.Name[:3] == 'Job'] -# if 1 == len(jobs): -# return jobs[0] -# return None - -# def IsActive(self): -# return not self.selectedJob() is None - -# def Activated(self): -# job = self.selectedJob() -# self.Execute(job) - -# @classmethod -# def Execute(cls, job): -# import PathScripts.PathToolBitLibraryGui as PathToolBitLibraryGui -# import PathScripts.PathToolControllerGui as PathToolControllerGui - -# library = PathToolBitLibraryGui.ToolBitLibrary() - -# if 1 == library.open() and job: -# for nr, tool in library.selectedOrAllTools(): -# tc = PathToolControllerGui.Create("TC: {}".format(tool.Label), tool, nr) -# job.Proxy.addToolController(tc) -# FreeCAD.ActiveDocument.recompute() -# return True -# return False - if FreeCAD.GuiUp: FreeCADGui.addCommand('Path_ToolBitLibraryOpen', CommandToolBitLibraryOpen()) From 9ab32df92668fce9eac225b76583b8210e7841d3 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Sun, 7 Feb 2021 06:28:47 -0600 Subject: [PATCH 5/7] Fixes #4555 --- src/Mod/Path/PathScripts/post/gcode_pre.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Mod/Path/PathScripts/post/gcode_pre.py b/src/Mod/Path/PathScripts/post/gcode_pre.py index f6707fd3cd..3110b892b8 100644 --- a/src/Mod/Path/PathScripts/post/gcode_pre.py +++ b/src/Mod/Path/PathScripts/post/gcode_pre.py @@ -112,11 +112,9 @@ def insert(filename, docname): # Create a custom and viewobject obj = PathCustom.Create("Custom") - res = PathOpGui.CommandResources('Custom', - PathCustom.Create, PathCustomGui.TaskPanelOpPage, - 'Path_Custom', - QtCore.QT_TRANSLATE_NOOP('Path_Custom', 'Custom'), '', '' - ) + res = PathOpGui.CommandResources('Custom', PathCustom.Create, + PathCustomGui.TaskPanelOpPage, + 'Path_Custom', 'Custom', '', '') obj.ViewObject.Proxy = PathOpGui.ViewProvider(obj.ViewObject, res) obj.ViewObject.Proxy.setDeleteObjectsOnReject(False) @@ -127,6 +125,7 @@ def insert(filename, docname): FreeCAD.ActiveDocument.recompute() + def parse(inputstring): "parse(inputstring): returns a parsed output string" From 63f0e7aad485c8f1466eaf7e5875cb727defdda5 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Wed, 17 Feb 2021 17:59:25 -0600 Subject: [PATCH 6/7] Fix unit test with property name sanitize. --- src/Mod/Path/Gui/Resources/panels/PropertyCreate.ui | 2 +- src/Mod/Path/PathScripts/PathPropertyBag.py | 5 ++++- src/Mod/Path/PathScripts/PathPropertyBagGui.py | 9 +++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Mod/Path/Gui/Resources/panels/PropertyCreate.ui b/src/Mod/Path/Gui/Resources/panels/PropertyCreate.ui index c65c02ea82..38a4b3057f 100644 --- a/src/Mod/Path/Gui/Resources/panels/PropertyCreate.ui +++ b/src/Mod/Path/Gui/Resources/panels/PropertyCreate.ui @@ -24,7 +24,7 @@ - <html><head/><body><p>Name of property.</p></body></html> + <html><head/><body><p>Name of property. Can only contain letters, numbers, and underscores. MixedCase names will display with spaces &quot;Mixed Case&quot;</p></body></html> diff --git a/src/Mod/Path/PathScripts/PathPropertyBag.py b/src/Mod/Path/PathScripts/PathPropertyBag.py index eefee2ed30..2142457ed1 100644 --- a/src/Mod/Path/PathScripts/PathPropertyBag.py +++ b/src/Mod/Path/PathScripts/PathPropertyBag.py @@ -22,6 +22,7 @@ import FreeCAD import PySide +import re __title__ = 'Generic property container to store some values.' __author__ = 'sliptonic (Brad Collette)' @@ -70,7 +71,7 @@ class PropertyBag(object): def __sanitizePropertyName(self, name): if(len(name) == 0): return - clean = name[0].lower() + clean = name[0] for i in range(1, len(name)): if (name[i] == ' '): clean += name[i + 1].upper() @@ -96,6 +97,8 @@ class PropertyBag(object): groups = self.obj.CustomPropertyGroups name = self.__sanitizePropertyName(name) + if not re.match("^[A-Za-z0-9_]*$", name): + raise ValueError('Property Name can only contain letters and numbers') if not group in groups: groups.append(group) diff --git a/src/Mod/Path/PathScripts/PathPropertyBagGui.py b/src/Mod/Path/PathScripts/PathPropertyBagGui.py index a0e1b03fb4..7446379b53 100644 --- a/src/Mod/Path/PathScripts/PathPropertyBagGui.py +++ b/src/Mod/Path/PathScripts/PathPropertyBagGui.py @@ -22,12 +22,13 @@ import FreeCAD import FreeCADGui -import PathGui +#import PathGui import PathScripts.PathIconViewProvider as PathIconViewProvider import PathScripts.PathLog as PathLog import PathScripts.PathPropertyBag as PathPropertyBag import PathScripts.PathPropertyEditor as PathPropertyEditor import PathScripts.PathUtil as PathUtil +import re from PySide import QtCore, QtGui @@ -153,6 +154,7 @@ class PropertyCreate(object): self.form.propertyEnum.textChanged.connect(self.updateUI) def updateUI(self): + typeSet = True if self.propertyIsEnumeration(): self.form.labelEnum.setEnabled(True) @@ -166,7 +168,10 @@ class PropertyCreate(object): ok = self.form.buttonBox.button(QtGui.QDialogButtonBox.Ok) - if typeSet and self.propertyName() and self.propertyGroup(): + if not re.match("^[A-Za-z0-9_]*$", self.form.propertyName.text()): + typeSet = False + + if typeSet and self.propertyGroup(): ok.setEnabled(True) else: ok.setEnabled(False) From 586b2e6aa7b8b3d4ce56c3bbfee020f7ee53c546 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Fri, 19 Feb 2021 17:50:56 -0600 Subject: [PATCH 7/7] add back translation string --- src/Mod/Path/PathScripts/post/gcode_pre.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Mod/Path/PathScripts/post/gcode_pre.py b/src/Mod/Path/PathScripts/post/gcode_pre.py index 3110b892b8..e3e2303b3f 100644 --- a/src/Mod/Path/PathScripts/post/gcode_pre.py +++ b/src/Mod/Path/PathScripts/post/gcode_pre.py @@ -50,6 +50,7 @@ import re import PathScripts.PathCustom as PathCustom import PathScripts.PathCustomGui as PathCustomGui import PathScripts.PathOpGui as PathOpGui +from PySide import QtCore # LEVEL = PathLog.Level.DEBUG LEVEL = PathLog.Level.INFO @@ -114,7 +115,8 @@ def insert(filename, docname): obj = PathCustom.Create("Custom") res = PathOpGui.CommandResources('Custom', PathCustom.Create, PathCustomGui.TaskPanelOpPage, - 'Path_Custom', 'Custom', '', '') + 'Path_Custom', + QtCore.QT_TRANSLATE_NOOP('Path_Custom', 'Custom'), '', '') obj.ViewObject.Proxy = PathOpGui.ViewProvider(obj.ViewObject, res) obj.ViewObject.Proxy.setDeleteObjectsOnReject(False)