From d00d402efd59f0e9e2f31e03772af7ea34fd5e25 Mon Sep 17 00:00:00 2001 From: markus Date: Wed, 29 Apr 2020 14:27:51 -0700 Subject: [PATCH] Fixed ToolBit template generation and adapted TC unit test to deal with Tool and ToolBit. --- src/Mod/Path/PathScripts/PathToolBit.py | 4 ++-- .../Path/PathTests/TestPathToolController.py | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathToolBit.py b/src/Mod/Path/PathScripts/PathToolBit.py index 1286349fd4..fa1b1fcffb 100644 --- a/src/Mod/Path/PathScripts/PathToolBit.py +++ b/src/Mod/Path/PathScripts/PathToolBit.py @@ -310,7 +310,7 @@ class ToolBit(object): 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 @@ -318,7 +318,7 @@ class ToolBit(object): 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 diff --git a/src/Mod/Path/PathTests/TestPathToolController.py b/src/Mod/Path/PathTests/TestPathToolController.py index bd7af1e71d..35fe171997 100644 --- a/src/Mod/Path/PathTests/TestPathToolController.py +++ b/src/Mod/Path/PathTests/TestPathToolController.py @@ -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 @@ -37,7 +39,10 @@ class TestPathToolController(PathTestBase): 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''' @@ -65,7 +70,10 @@ class TestPathToolController(PathTestBase): 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 @@ -84,5 +92,8 @@ class TestPathToolController(PathTestBase): 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)