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 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 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(unicode(template), 'rb') as fp: attrs = json.load(fp) if attrs.get(JobTemplate.Version) and 1 == int( attrs[JobTemplate.Version]): 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)) else: PathLog.error( translate('PathJob', "Unsupported PathJob template version %s") % attrs.get(JobTemplate.Version)) tcs.append(PathToolController.Create()) else: tcs.append(PathToolController.Create()) PathLog.debug("setting tool controllers (%d)" % len(tcs)) obj.ToolController = tcs
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 Create(name='Default Tool', tool=None, toolNumber=1): PathLog.track(tool, toolNumber) obj = PathToolController.Create(name, tool, toolNumber) ViewProvider(obj.ViewObject) return obj