def assignTemplate(self, obj, template): '''assignTemplate(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: tree = xml.parse(template) for job in tree.getroot().iter(JobTemplate.Job): if job.get(JobTemplate.GeometryTolerance): obj.GeometryTolerance = float( job.get(JobTemplate.GeometryTolerance)) if job.get(JobTemplate.PostProcessor): obj.PostProcessor = job.get(JobTemplate.PostProcessor) if job.get(JobTemplate.PostProcessorArgs): obj.PostProcessorArgs = job.get( JobTemplate.PostProcessorArgs) else: obj.PostProcessorArgs = '' if job.get(JobTemplate.PostProcessorOutputFile): obj.PostProcessorOutputFile = job.get( JobTemplate.PostProcessorOutputFile) if job.get(JobTemplate.Description): obj.Description = job.get(JobTemplate.Description) for tc in tree.getroot().iter(JobTemplate.ToolController): tcs.append(PathToolController.FromTemplate(tc)) for stock in tree.getroot().iter(JobTemplate.Stock): obj.Stock = PathStock.CreateFromTemplate(self, stock) else: tcs.append(PathToolController.Create()) PathLog.debug("setting tool controllers (%d)" % len(tcs)) obj.ToolController = tcs
def setFromTemplateFile(self, obj, template): """setFromTemplateFile(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: with open(PathUtil.toUnicode(template), "rb") as fp: attrs = json.load(fp) if attrs.get(JobTemplate.Version) and 1 == int(attrs[JobTemplate.Version]): attrs = self.setupSheet.decodeTemplateAttributes(attrs) if attrs.get(JobTemplate.SetupSheet): self.setupSheet.setFromTemplate(attrs[JobTemplate.SetupSheet]) if attrs.get(JobTemplate.GeometryTolerance): obj.GeometryTolerance = float( attrs.get(JobTemplate.GeometryTolerance) ) if attrs.get(JobTemplate.PostProcessor): obj.PostProcessor = attrs.get(JobTemplate.PostProcessor) if attrs.get(JobTemplate.PostProcessorArgs): obj.PostProcessorArgs = attrs.get(JobTemplate.PostProcessorArgs) else: obj.PostProcessorArgs = "" if attrs.get(JobTemplate.PostProcessorOutputFile): obj.PostProcessorOutputFile = attrs.get( JobTemplate.PostProcessorOutputFile ) if attrs.get(JobTemplate.Description): obj.Description = attrs.get(JobTemplate.Description) if attrs.get(JobTemplate.ToolController): for tc in attrs.get(JobTemplate.ToolController): tcs.append(PathToolController.FromTemplate(tc)) if attrs.get(JobTemplate.Stock): obj.Stock = PathStock.CreateFromTemplate( obj, attrs.get(JobTemplate.Stock) ) if attrs.get(JobTemplate.Fixtures): obj.Fixtures = [ x for y in attrs.get(JobTemplate.Fixtures) for x in y ] if attrs.get(JobTemplate.OrderOutputBy): obj.OrderOutputBy = attrs.get(JobTemplate.OrderOutputBy) if attrs.get(JobTemplate.SplitOutput): obj.SplitOutput = attrs.get(JobTemplate.SplitOutput) PathLog.debug("setting tool controllers (%d)" % len(tcs)) obj.Tools.Group = tcs else: PathLog.error( "Unsupported PathJob template version {}".format( attrs.get(JobTemplate.Version) ) ) if not tcs: self.addToolController(PathToolController.Create())
def toolControllerEdit(self): for item in self.form.toolControllerList.selectedItems(): tc = item.data(self.DataObject) dlg = PathToolController.DlgToolControllerEdit(tc) dlg.exec_() self.setFields() self.toolControllerSelect()
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.VertFeed = round(tc.VertFeed, 1) 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.0 mm/s') self.assertEqual(attrs['vrapid'], '40.0 mm/s') self.assertEqual(attrs['hrapid'], '28.0 mm/s') self.assertEqual(attrs['dir'], 'Reverse') self.assertEqual(attrs['speed'], 12000) if PathPreferences.toolsReallyUseLegacyTools(): self.assertEqual(attrs['tool'], t.templateAttrs()) else: self.assertEqual(attrs['tool'], t.Proxy.templateAttrs(t)) return tc
def setFromTemplateFile(self, obj, template): '''setFromTemplateFile(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: with open(PathUtil.toUnicode(template), 'rb') as fp: attrs = json.load(fp) if attrs.get(JobTemplate.Version) and 1 == int( attrs[JobTemplate.Version]): attrs = self.setupSheet.decodeTemplateAttributes(attrs) if attrs.get(JobTemplate.SetupSheet): self.setupSheet.setFromTemplate( attrs[JobTemplate.SetupSheet]) if attrs.get(JobTemplate.GeometryTolerance): obj.GeometryTolerance = float( attrs.get(JobTemplate.GeometryTolerance)) if attrs.get(JobTemplate.PostProcessor): obj.PostProcessor = attrs.get(JobTemplate.PostProcessor) if attrs.get(JobTemplate.PostProcessorArgs): obj.PostProcessorArgs = attrs.get( JobTemplate.PostProcessorArgs) else: obj.PostProcessorArgs = '' if attrs.get(JobTemplate.PostProcessorOutputFile): obj.PostProcessorOutputFile = attrs.get( JobTemplate.PostProcessorOutputFile) if attrs.get(JobTemplate.Description): obj.Description = attrs.get(JobTemplate.Description) if attrs.get(JobTemplate.ToolController): for tc in attrs.get(JobTemplate.ToolController): tcs.append(PathToolController.FromTemplate(tc)) if attrs.get(JobTemplate.Stock): obj.Stock = PathStock.CreateFromTemplate( obj, attrs.get(JobTemplate.Stock)) PathLog.debug("setting tool controllers (%d)" % len(tcs)) obj.ToolController = tcs else: PathLog.error( translate('PathJob', "Unsupported PathJob template version %s") % attrs.get(JobTemplate.Version)) if not tcs: self.addToolController(PathToolController.Create())
def test00(self): """Test that FeedRate Helper populates horiz and vert feed rate based on TC""" t = Path.Tool("test", "5.0") tc = PathToolController.Create("TC0", t) tc.VertRapid = 5 tc.HorizRapid = 10 tc.VertFeed = 15 tc.HorizFeed = 20 resultlist = PathFeedRate.setFeedRate(self.commandlist, tc) print(resultlist) self.assertTrue(resultlist[0].Parameters["F"] == 5) self.assertTrue(resultlist[1].Parameters["F"] == 10) self.assertTrue(resultlist[2].Parameters["F"] == 15) self.assertTrue(resultlist[3].Parameters["F"] == 20)
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)
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) # 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)
def Create(name='Default Tool', tool=None, toolNumber=1): PathLog.track(tool, toolNumber) obj = PathToolController.Create(name, tool, toolNumber) ViewProvider(obj.ViewObject) return obj