From 5b83cece9ab88d0f5d7ceb7388e59980c8d7ba73 Mon Sep 17 00:00:00 2001 From: Russell Johnson <47639332+Russ4262@users.noreply.github.com> Date: Fri, 2 Jul 2021 13:54:13 -0500 Subject: [PATCH 1/5] Path: Add tools `README.md` file to tools working directory on install This code copies all files in the default (program install location) Path\Tools folder to the user's working tools folder when they setup the ToolBit working directories for the first time. --- src/Mod/Path/CMakeLists.txt | 12 ++++++++++++ src/Mod/Path/PathScripts/PathToolBitLibraryGui.py | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Mod/Path/CMakeLists.txt b/src/Mod/Path/CMakeLists.txt index 6b78b5ea38..4c6589a9ad 100644 --- a/src/Mod/Path/CMakeLists.txt +++ b/src/Mod/Path/CMakeLists.txt @@ -164,6 +164,10 @@ SET(PathScripts_post_SRCS PathScripts/post/uccnc_post.py ) +SET(Tools_SRCS + Tools/README.md +) + SET(Tools_Bit_SRCS Tools/Bit/45degree_chamfer.fctb Tools/Bit/5mm-thread-cutter.fctb @@ -254,6 +258,7 @@ SET(Path_Data SET(all_files ${PathScripts_SRCS} ${PathScripts_post_SRCS} + ${Tools_SRCS} ${Tools_Bit_SRCS} ${Tools_Library_SRCS} ${Tools_Shape_SRCS} @@ -306,6 +311,13 @@ INSTALL( Mod/Path/PathScripts/post ) +INSTALL( + FILES + ${Tools_SRCS} + DESTINATION + Mod/Path/Tools +) + INSTALL( FILES ${Tools_Bit_SRCS} diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py index 7a70425944..2a7b8ed182 100644 --- a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py +++ b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py @@ -85,6 +85,14 @@ def checkWorkingDir(): PathPreferences.setLastPathToolBit("{}{}Bit".format(workingdir, os.path.sep)) PathLog.debug('setting workingdir to: {}'.format(workingdir)) + # Copy only files of default Path\Tools folder to working directory (targeting the README.md help file) + src_toolfiles = os.listdir(defaultdir) + for file_name in src_toolfiles: + if file_name in ["README.md"]: + full_file_name = os.path.join(defaultdir, file_name) + if os.path.isfile(full_file_name): + shutil.copy(full_file_name, workingdir) + subdirlist = ['Bit', 'Library', 'Shape'] mode = 0o777 for dir in subdirlist.copy(): From b6b08a5a2e096bfa558effd69634d664b49bfcf3 Mon Sep 17 00:00:00 2001 From: Russell Johnson <47639332+Russ4262@users.noreply.github.com> Date: Fri, 2 Jul 2021 12:29:05 -0500 Subject: [PATCH 2/5] Path: Add internal comments to code --- src/Mod/Path/PathScripts/PathToolBitLibraryGui.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py index 2a7b8ed182..e05fa1d4c6 100644 --- a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py +++ b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py @@ -93,6 +93,7 @@ def checkWorkingDir(): if os.path.isfile(full_file_name): shutil.copy(full_file_name, workingdir) + # Determine which subdirectories are missing subdirlist = ['Bit', 'Library', 'Shape'] mode = 0o777 for dir in subdirlist.copy(): @@ -100,6 +101,7 @@ def checkWorkingDir(): if os.path.exists(subdir): subdirlist.remove(dir) + # Query user for creation permission of any missing subdirectories if len(subdirlist) >= 1: needed = ', '.join([str(d) for d in subdirlist]) qm = PySide.QtGui.QMessageBox @@ -108,9 +110,11 @@ def checkWorkingDir(): if ret == qm.No: return False else: + # Create missing subdirectories if user agrees to creation for dir in subdirlist: subdir = "{}{}{}".format(workingdir, os.path.sep, dir) os.mkdir(subdir, mode) + # Query user to copy example files into subdirectories created if dir != 'Shape': qm = PySide.QtGui.QMessageBox ret = qm.question(None,'', "Copy example files to new {} directory?".format(dir), qm.Yes | qm.No) From 71f8007bab5ea3a2038d321b42afa0ad4efa8a04 Mon Sep 17 00:00:00 2001 From: Russell Johnson <47639332+Russ4262@users.noreply.github.com> Date: Fri, 2 Jul 2021 22:35:14 -0500 Subject: [PATCH 3/5] Path: Fixes #0004647, relative shape file locations This solution restricts relative shape files to filename only within the toolbit file. --- src/Mod/Path/PathScripts/PathToolBit.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Mod/Path/PathScripts/PathToolBit.py b/src/Mod/Path/PathScripts/PathToolBit.py index 44da128a61..c87d4cd6a2 100644 --- a/src/Mod/Path/PathScripts/PathToolBit.py +++ b/src/Mod/Path/PathScripts/PathToolBit.py @@ -380,7 +380,10 @@ class ToolBit(object): if PathPreferences.toolsStoreAbsolutePaths(): attrs['shape'] = obj.BitShape else: - attrs['shape'] = findRelativePathShape(obj.BitShape) + # attrs['shape'] = findRelativePathShape(obj.BitShape) + # Extract the name of the shape file + __, filShp = os.path.split(obj.BitShape) # __ is an ignored placeholder acknowledged by LGTM + attrs['shape'] = str(filShp) params = {} for name in obj.BitPropertyNames: params[name] = PathUtil.getPropertyValueString(obj, name) From aec0bb132910fcc99f12acd261741e7da680c648 Mon Sep 17 00:00:00 2001 From: Russell Johnson <47639332+Russ4262@users.noreply.github.com> Date: Mon, 5 Jul 2021 14:45:12 -0500 Subject: [PATCH 4/5] Path: Fix relative paths for bit path attributes in library files --- src/Mod/Path/PathScripts/PathToolBitLibraryGui.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py index e05fa1d4c6..750c2eeb38 100644 --- a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py +++ b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py @@ -632,9 +632,13 @@ class ToolBitLibrary(object): toolNr = self.toolModel.data(self.toolModel.index(row, 0), PySide.QtCore.Qt.EditRole) toolPath = self.toolModel.data(self.toolModel.index(row, 0), _PathRole) if PathPreferences.toolsStoreAbsolutePaths(): - tools.append({'nr': toolNr, 'path': toolPath}) + bitPath = toolPath else: - tools.append({'nr': toolNr, 'path': PathToolBit.findRelativePathTool(toolPath)}) + # bitPath = PathToolBit.findRelativePathTool(toolPath) + # Extract the name of the shape file + __, filShp = os.path.split(toolPath) # __ is an ignored placeholder acknowledged by LGTM + bitPath = str(filShp) + tools.append({'nr': toolNr, 'path': bitPath}) if self.path is not None: with open(self.path, 'w') as fp: From 16489777d216d38a79fd2c7e9444cd9ac7a8c14c Mon Sep 17 00:00:00 2001 From: Russell Johnson <47639332+Russ4262@users.noreply.github.com> Date: Mon, 5 Jul 2021 14:45:36 -0500 Subject: [PATCH 5/5] Path: Add debug comments and comment out unused code --- src/Mod/Path/PathScripts/PathToolBit.py | 4 ++++ src/Mod/Path/PathScripts/PathToolBitLibraryGui.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Mod/Path/PathScripts/PathToolBit.py b/src/Mod/Path/PathScripts/PathToolBit.py index c87d4cd6a2..6d6032abfd 100644 --- a/src/Mod/Path/PathScripts/PathToolBit.py +++ b/src/Mod/Path/PathScripts/PathToolBit.py @@ -96,6 +96,7 @@ def findToolBit(name, path=None): return _findToolFile("{}.fctb".format(name), path, 'Bit') +# Only used in ToolBit unit test module: TestPathToolBit.py def findToolLibrary(name, path=None): '''findToolLibrary(name, path) ... search for name, if relative path look in path''' PathLog.track(name, path) @@ -117,12 +118,15 @@ def _findRelativePath(path, typ): return relative +# Unused due to bug fix related to relative paths +""" def findRelativePathShape(path): return _findRelativePath(path, 'Shape') def findRelativePathTool(path): return _findRelativePath(path, 'Bit') +""" def findRelativePathLibrary(path): diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py index 750c2eeb38..693d954c0c 100644 --- a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py +++ b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py @@ -464,6 +464,7 @@ class ToolBitLibrary(object): if shapefile is None: # user canceled return + # select the bit file location and filename filename = PathToolBitGui.GetNewToolFile() if filename is None: return @@ -472,7 +473,7 @@ class ToolBitLibrary(object): loc, fil = os.path.split(filename) fname = os.path.splitext(fil)[0] fullpath = "{}{}{}.fctb".format(loc, os.path.sep, fname) - PathLog.debug(fullpath) + PathLog.debug("fullpath: {}".format(fullpath)) self.temptool = PathToolBit.ToolBitFactory().Create(name=fname) self.temptool.BitShape = shapefile @@ -577,6 +578,7 @@ class ToolBitLibrary(object): self.form.librarySave.setEnabled(True) def toolEdit(self, selected): + PathLog.track() item = self.toolModel.item(selected.row(), 0) if self.temptool is not None: