Example #1
0
    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())
Example #2
0
    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)