Skip to content

Commit

Permalink
Fixed ToolBit template generation and adapted TC unit test to deal wi…
Browse files Browse the repository at this point in the history
…th Tool and ToolBit.
  • Loading branch information
mlampert committed Apr 29, 2020
1 parent bd86e1c commit a5ee581
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Mod/Path/PathScripts/PathToolBit.py
Expand Up @@ -310,15 +310,15 @@ def saveToFile(self, obj, path, setFile=True):
print('were saving now')
try:
with open(path, 'w') as fp:
json.dump(self.shapeAttrs(obj), fp, indent=' ')
json.dump(self.templateAttrs(obj), fp, indent=' ')
if setFile:
obj.File = path
return True
except (OSError, IOError) as e:
PathLog.error("Could not save tool %s to %s (%s)" % (obj.Label, path, e))
raise

def shapeAttrs(self, obj):
def templateAttrs(self, obj):
attrs = {}
attrs['version'] = 2 # Path.Tool is version 1
attrs['name'] = obj.Label
Expand Down
17 changes: 14 additions & 3 deletions src/Mod/Path/PathTests/TestPathToolController.py
Expand Up @@ -24,6 +24,8 @@

import FreeCAD
import Path
import PathScripts.PathPreferences as PathPreferences
import PathScripts.PathToolBit as PathToolBit
import PathScripts.PathToolController as PathToolController

from PathTests.PathTestUtils import PathTestBase
Expand All @@ -37,7 +39,10 @@ def tearDown(self):
FreeCAD.closeDocument(self.doc.Name)

def createTool(self, name='t1', diameter=1.75):
return Path.Tool(name=name, diameter=diameter)
if PathPreferences.toolsReallyUseLegacyTools():
return Path.Tool(name=name, diameter=diameter)
attrs = {'shape': None, 'name': name, 'parameter': {'Diameter': diameter}, 'attribute': []}
return PathToolBit.Factory.CreateFromAttrs(attrs, name)

def test00(self):
'''Verify ToolController templateAttrs'''
Expand Down Expand Up @@ -65,7 +70,10 @@ def test00(self):
self.assertEqual(attrs['hrapid'], '28.0 mm/s')
self.assertEqual(attrs['dir'], 'Reverse')
self.assertEqual(attrs['speed'], 12000)
self.assertEqual(attrs['tool'], t.templateAttrs())
if PathPreferences.toolsReallyUseLegacyTools():
self.assertEqual(attrs['tool'], t.templateAttrs())
else:
self.assertEqual(attrs['tool'], t.Proxy.templateAttrs(t))

return tc

Expand All @@ -84,5 +92,8 @@ def test01(self):
self.assertRoughly(tc0.HorizRapid, tc1.HorizRapid)
self.assertEqual(tc0.SpindleDir, tc1.SpindleDir)
self.assertRoughly(tc0.SpindleSpeed, tc1.SpindleSpeed)
self.assertEqual(tc0.Tool.Name, tc1.Tool.Name)
# These are not valid because the name & label get adjusted if there
# is a conflict. No idea how this could work with the C implementation
#self.assertEqual(tc0.Tool.Name, tc1.Tool.Name)
#self.assertEqual(tc0.Tool.Label, tc1.Tool.Label)
self.assertRoughly(tc0.Tool.Diameter, tc1.Tool.Diameter)

0 comments on commit a5ee581

Please sign in to comment.