Added support for relative/absolute path mgmt for stored files.

This commit is contained in:
Markus Lampert
2019-11-09 19:57:58 -08:00
parent a2935d5ff0
commit c6f14b9836
16 changed files with 94 additions and 45 deletions

View File

@@ -46,7 +46,7 @@ LastPathToolLibrary = "LastPathToolLibrary"
LastPathToolShape = "LastPathToolShape"
UseLegacyTools = "UseLegacyTools"
UseRelativeToolPaths = "UseRelativeToolPaths"
UseAbsoluteToolPaths = "UseAbsoluteToolPaths"
# Linear tolerance to use when generating Paths, eg when tessellating geometry
GeometryTolerance = "GeometryTolerance"
@@ -152,13 +152,13 @@ def searchPathsTool(sub='Bit'):
def toolsUseLegacyTools():
return preferences().GetBool(UseLegacyTools, True)
def toolsStoreRelativePaths():
return preferences().GetBool(UseRelativeToolPaths, True)
def toolsStoreAbsolutePaths():
return preferences().GetBool(UseAbsoluteToolPaths, False)
def setToolsSettings(legacy, relative):
pref = preferences()
pref.SetBool(UseLegacyTools, legacy)
pref.SetBool(UseRelativeToolPaths, relative)
pref.SetBool(UseAbsoluteToolPaths, relative)
def defaultJobTemplate():
template = preferences().GetString(DefaultJobTemplate)

View File

@@ -109,7 +109,7 @@ class JobPreferencesPage:
PathPreferences.setDefaultStockTemplate('')
def saveToolsSettings(self):
PathPreferences.setToolsSettings(self.form.toolsUseLegacy.isChecked(), self.form.toolsRelativePaths.isChecked())
PathPreferences.setToolsSettings(self.form.toolsUseLegacy.isChecked(), self.form.toolsAbsolutePaths.isChecked())
def selectComboEntry(self, widget, text):
index = widget.findText(text, QtCore.Qt.MatchFixedString)
@@ -251,7 +251,7 @@ class JobPreferencesPage:
def loadToolSettings(self):
self.form.toolsUseLegacy.setChecked(PathPreferences.toolsUseLegacyTools())
self.form.toolsRelativePaths.setChecked(PathPreferences.toolsStoreRelativePaths())
self.form.toolsAbsolutePaths.setChecked(PathPreferences.toolsStoreAbsolutePaths())
def getPostProcessor(self, name):
if not name in self.processor.keys():

View File

@@ -96,6 +96,26 @@ def findLibrary(path, dbg=False):
return _findTool(path, 'Library', dbg)
return _findTool("{}.fctl".format(path), 'Library', dbg)
def _findRelativePath(path, typ):
relative = path
for p in PathPreferences.searchPathsTool(typ):
if path.startswith(p):
p = path[len(p):]
if '/' == p[0]:
p = p[1:]
if len(p) < len(relative):
relative = p
return relative
def findRelativePathShape(path):
return _findRelativePath(path, 'Shape')
def findRelativePathTool(path):
return _findRelativePath(path, 'Bit')
def findRelativePathLibrary(path):
return _findRelativePath(path, 'Library')
def updateConstraint(sketch, name, value):
for i, constraint in enumerate(sketch.Constraints):
if constraint.Name.split(';')[0] == name:
@@ -116,6 +136,7 @@ def updateConstraint(sketch, name, value):
PathLog.track(name, constraint.Type, 'unchanged')
break
PropertyGroupBit = 'Bit'
PropertyGroupAttribute = 'Attribute'
@@ -124,9 +145,9 @@ class ToolBit(object):
def __init__(self, obj, shapeFile):
PathLog.track(obj.Label, shapeFile)
self.obj = obj
obj.addProperty('App::PropertyFile', 'BitShape', 'Base', translate('PathToolBit', 'Shape for bit shape'))
obj.addProperty('App::PropertyLink', 'BitBody', 'Base', translate('PathToolBit', 'The parametrized body representing the tool bit'))
obj.addProperty('App::PropertyFile', 'File', 'Base', translate('PathToolBit', 'The file of the tool'))
obj.addProperty('App::PropertyFile', 'BitShape', 'Base', translate('PathToolBit', 'Shape for bit shape'))
obj.addProperty('App::PropertyLink', 'BitBody', 'Base', translate('PathToolBit', 'The parametrized body representing the tool bit'))
obj.addProperty('App::PropertyFile', 'File', 'Base', translate('PathToolBit', 'The file of the tool'))
if shapeFile is not None:
obj.BitShape = shapeFile
self._setupBitShape(obj)
@@ -283,7 +304,10 @@ class ToolBit(object):
attrs = {}
attrs['version'] = 2 # Path.Tool is version 1
attrs['name'] = obj.Label
attrs['shape'] = obj.BitShape
if PathPreferences.toolsStoreAbsolutePaths():
attrs['shape'] = obj.BitShape
else:
attrs['shape'] = findRelativePathShape(obj.BitShape)
params = {}
for name in self.propertyNamesBit(obj):
params[name] = PathUtil.getPropertyValueString(obj, name)
@@ -332,7 +356,9 @@ class ToolBitFactory(object):
def CreateFrom(self, path, name='ToolBit'):
try:
data = Declaration(path)
return Factory.CreateFromAttrs(data, name)
bit = Factory.CreateFromAttrs(data, name)
bit.File = path
return bit
except (OSError, IOError) as e:
PathLog.error("%s not a valid tool file (%s)" % (path, e))
raise

View File

@@ -263,7 +263,10 @@ class ToolBitLibrary(object):
for row in range(self.model.rowCount()):
toolNr = self.model.data(self.model.index(row, 0), PySide.QtCore.Qt.EditRole)
toolPath = self.model.data(self.model.index(row, 0), _PathRole)
tools.append({'nr': toolNr, 'path': toolPath})
if PathPreferences.toolsStoreAbsolutePaths():
tools.append({'nr': toolNr, 'path': toolPath})
else:
tools.append({'nr': toolNr, 'path': PathToolBit.findRelativePathTool(toolPath)})
with open(self.path, 'w') as fp:
json.dump(library, fp, sort_keys=True, indent=2)