Fixed up ToolController template arguments and loading for the switch to JSON.

This commit is contained in:
Markus Lampert
2017-09-14 12:40:14 -07:00
committed by wmayer
parent ce43e688fa
commit 1263aecdaf
5 changed files with 121 additions and 31 deletions

View File

@@ -121,6 +121,7 @@ SET(PathTests_SRCS
PathTests/TestPathPost.py
PathTests/TestPathStock.py
PathTests/TestPathTool.py
PathTests/TestPathToolController.py
PathTests/TestPathTooltable.py
PathTests/TestPathUtil.py
)

View File

@@ -115,7 +115,7 @@ class ObjectJob:
obj.Base = createResourceClone(obj, base, 'Base', 'BaseGeometry')
obj.Proxy = self
self.assignTemplate(obj, template)
self.setFromTemplate(obj, template)
if not obj.Stock:
obj.Stock = PathStock.CreateFromBase(obj)
if obj.Stock.ViewObject:
@@ -165,8 +165,8 @@ class ObjectJob:
return obj.Base.Objects[0]
return obj.Base
def assignTemplate(self, obj, template):
'''assignTemplate(obj, template) ... extract the properties from the given template file and assign to receiver.
def setFromTemplate(self, obj, template):
'''setFromTemplate(obj, template) ... extract the properties from the given template file and assign to receiver.
This will also create any TCs stored in the template.'''
tcs = []
if template:

View File

@@ -56,7 +56,7 @@ class ToolControllerTemplate:
HorizRapid = 'hrapid'
SpindleSpeed = 'speed'
SpindleDir = 'dir'
Tool = 'Tool'
Tool = 'tool'
class ToolController:
def __init__(self, obj, tool=1):
@@ -77,8 +77,8 @@ class ToolController:
mode = 2
obj.setEditorMode('Placement', mode)
def assignTemplate(self, obj, template):
'''assignTemplate(obj, xmlItem) ... extract properties from xmlItem and assign to receiver.'''
def setFromTemplate(self, obj, template):
'''setFromTemplate(obj, xmlItem) ... extract properties from xmlItem and assign to receiver.'''
PathLog.track(obj.Name, template)
if template.get(ToolControllerTemplate.Label):
obj.Label = template.get(ToolControllerTemplate.Label)
@@ -97,23 +97,27 @@ class ToolController:
if template.get(ToolControllerTemplate.ToolNumber):
obj.ToolNumber = int(template.get(ToolControllerTemplate.ToolNumber))
for t in template.iter(ToolControllerTemplate.Tool):
tool = Path.Tool()
tool.setFromTemplate(xml.tostring(t))
obj.Tool = tool
if hasattr(template, 'iter'):
for t in template.iter(ToolControllerTemplate.Tool):
tool = Path.Tool()
tool.setFromTemplate(xml.tostring(t))
obj.Tool = tool
elif template.get(ToolControllerTemplate.Tool):
obj.Tool.setFromTemplate(template.get(ToolControllerTemplate.Tool))
def templateAttrs(self, obj):
'''templateAttrs(obj) ... answer a dictionary with all properties that should be stored for a template.'''
attrs = {}
attrs[ToolControllerTemplate.Name] = ("%s" % (obj.Name))
attrs[ToolControllerTemplate.Label] = ("%s" % (obj.Label))
attrs[ToolControllerTemplate.ToolNumber] = ("%d" % (obj.ToolNumber))
attrs[ToolControllerTemplate.Name] = obj.Name
attrs[ToolControllerTemplate.Label] = obj.Label
attrs[ToolControllerTemplate.ToolNumber] = obj.ToolNumber
attrs[ToolControllerTemplate.VertFeed] = ("%s" % (obj.VertFeed))
attrs[ToolControllerTemplate.HorizFeed] = ("%s" % (obj.HorizFeed))
attrs[ToolControllerTemplate.VertRapid] = ("%s" % (obj.VertRapid))
attrs[ToolControllerTemplate.HorizRapid] = ("%s" % (obj.HorizRapid))
attrs[ToolControllerTemplate.SpindleSpeed] = ("%f" % (obj.SpindleSpeed))
attrs[ToolControllerTemplate.SpindleDir] = ("%s" % (obj.SpindleDir))
attrs[ToolControllerTemplate.SpindleSpeed] = obj.SpindleSpeed
attrs[ToolControllerTemplate.SpindleDir] = obj.SpindleDir
attrs[ToolControllerTemplate.Tool] = obj.Tool.templateAttrs()
return attrs
def execute(self, obj):
@@ -223,7 +227,7 @@ def FromTemplate(template, assignViewProvider=True):
if FreeCAD.GuiUp and assignViewProvider:
ViewProvider(obj.ViewObject)
tc.assignTemplate(obj, template)
tc.setFromTemplate(obj, template)
return obj
@@ -410,14 +414,11 @@ class DlgToolControllerEdit:
def exec_(self):
restoreTC = self.obj.Proxy.templateAttrs(self.obj)
restoreTool = self.obj.Tool.Content
rc = False
if not self.editor.form.exec_():
PathLog.info("revert")
root = xml.Element('ToolController', restoreTC)
root.append(xml.fromstring(restoreTool))
self.obj.Proxy.assignTemplate(self.obj, root)
self.obj.Proxy.setFromTemplate(self.obj, restoreTC)
rc = True
return rc

View File

@@ -0,0 +1,87 @@
# -*- coding: utf-8 -*-
# ***************************************************************************
# * *
# * Copyright (c) 2017 sliptonic <shopinthewoods@gmail.com> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
import FreeCAD
import Path
import PathScripts.PathToolController as PathToolController
from PathTests.PathTestUtils import PathTestBase
class TestPathToolController(PathTestBase):
def setUp(self):
self.doc = FreeCAD.newDocument("TestPathToolController")
def tearDown(self):
FreeCAD.closeDocument(self.doc.Name)
def createTool(self, name='t1', diameter=1.75):
return Path.Tool(name=name, diameter=diameter)
def test00(self):
'''Verify ToolController templateAttrs'''
t = self.createTool('T1')
tc = PathToolController.Create('TC0', t)
tc.Label = 'ToolController'
tc.ToolNumber = 7
tc.VertFeed = '3 in/s'
tc.HorizFeed = '10 mm/s'
tc.VertRapid = 40
tc.HorizRapid = 28
tc.SpindleDir = 'Reverse'
tc.SpindleSpeed = 12000
attrs = tc.Proxy.templateAttrs(tc)
self.assertEqual(attrs['name'], 'TC0')
self.assertEqual(attrs['label'], 'ToolController')
self.assertEqual(attrs['nr'], 7)
self.assertEqual(attrs['vfeed'], '76.2 mm/s')
self.assertEqual(attrs['hfeed'], '10 mm/s')
self.assertEqual(attrs['vrapid'], '40 mm/s')
self.assertEqual(attrs['hrapid'], '28 mm/s')
self.assertEqual(attrs['dir'], 'Reverse')
self.assertEqual(attrs['speed'], 12000)
self.assertEqual(attrs['tool'], t.templateAttrs())
return tc
def test01(self):
'''Verify ToolController template roundtrip.'''
tc0 = self.test00()
tc1 = PathToolController.FromTemplate(tc0.Proxy.templateAttrs(tc0))
self.assertNotEqual(tc0.Name, tc1.Name)
self.assertNotEqual(tc0.Label, tc1.Label)
self.assertEqual(tc0.ToolNumber, tc1.ToolNumber)
self.assertRoughly(tc0.VertFeed, tc1.VertFeed)
self.assertRoughly(tc0.HorizFeed, tc1.HorizFeed)
self.assertRoughly(tc0.VertRapid, tc1.VertRapid)
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)
self.assertRoughly(tc0.Tool.Diameter, tc1.Tool.Diameter)

View File

@@ -24,14 +24,15 @@
import TestApp
from PathTests.TestPathLog import TestPathLog
from PathTests.TestPathCore import TestPathCore
#from PathTests.TestPathPost import PathPostTestCases
from PathTests.TestPathGeom import TestPathGeom
from PathTests.TestPathUtil import TestPathUtil
from PathTests.TestPathDepthParams import depthTestCases
from PathTests.TestPathDressupHoldingTags import TestHoldingTags
from PathTests.TestPathDressupDogbone import TestDressupDogbone
from PathTests.TestPathStock import TestPathStock
from PathTests.TestPathTool import TestPathTool
from PathTests.TestPathTooltable import TestPathTooltable
#from PathTests.TestPathLog import TestPathLog
#from PathTests.TestPathCore import TestPathCore
##from PathTests.TestPathPost import PathPostTestCases
#from PathTests.TestPathGeom import TestPathGeom
#from PathTests.TestPathUtil import TestPathUtil
#from PathTests.TestPathDepthParams import depthTestCases
#from PathTests.TestPathDressupHoldingTags import TestHoldingTags
#from PathTests.TestPathDressupDogbone import TestDressupDogbone
#from PathTests.TestPathStock import TestPathStock
#from PathTests.TestPathTool import TestPathTool
#from PathTests.TestPathTooltable import TestPathTooltable
from PathTests.TestPathToolController import TestPathToolController