예제 #1
0
    def executeUpload(self):
        '''Post process the current Path.Job and upload the resulting g-code into MK.
        Tag the uploaded g-code with the job and a hash so we can determine if the uploaded
        version is consistent with what is currently in FC.'''

        job = self.job
        if job:
            currTool = None
            postlist = []
            for obj in job.Operations.Group:
                tc = PathUtil.toolControllerForOp(obj)
                if tc is not None:
                    if tc.ToolNumber != currTool:
                        postlist.append(tc)
                        currTool = tc.ToolNumber
                postlist.append(obj)

            post = PathPost.CommandPathPost()
            fail, gcode = post.exportObjectsWith(postlist, job, False)
            if not fail:
                print("POST: ", fail)
                preamble = "(FreeCAD.Job: %s)\n(FreeCAD.File: %s)\n(FreeCAD.Signature: %d)\n" % (
                    job.Name, job.Document.FileName,
                    MKUtils.pathSignature(job.Path))
                buf = io.BytesIO((preamble + gcode).encode())
                endpoint = self.mk.instance.endpoint.get('file')
                if endpoint:
                    ftp = ftplib.FTP()
                    ftp.connect(endpoint.address(), endpoint.port())
                    ftp.login()
                    ftp.storbinary("STOR %s" % self.mk.RemoteFilename, buf)
                    ftp.quit()
                    sequence = MKUtils.taskModeMDI(self.mk)
                    for tc in job.ToolController:
                        t = tc.Tool
                        radius = float(t.Diameter) / 2 if hasattr(
                            t, 'Diameter') else 0.
                        offset = t.LengthOffset if hasattr(
                            t, 'LengthOffset') else 0.
                        sequence.append(
                            MKCommandTaskExecute(
                                "G10 L1 P%d R%g Z%g" %
                                (tc.ToolNumber, radius, offset)))
                    sequence.extend(MKUtils.taskModeAuto(self.mk))
                    sequence.append(MKCommandTaskReset(False))
                    sequence.extend([
                        MKCommandOpenFile(self.mk.remoteFilePath(), True),
                        MKCommandOpenFile(self.mk.remoteFilePath(), False)
                    ])
                    sequence.append(MKCommandTaskRun(True))
                    self.mk['command'].sendCommands(sequence)
                else:
                    PathLog.error('No endpoint found')
            else:
                PathLog.error('Post processing failed')
예제 #2
0
    def updateJob(self):
        '''Download the g-code currently loaded into MK, check if it could be a FC Path.Job.
        If the Path.Job is currently loaded trigger an update to everyone caring about these
        things.'''
        job = None
        path = self['status.task.file']
        rpath = self.remoteFilePath()
        endpoint = self.instance.endpoint.get('file')
        PathLog.info("%s, %s, %s" % (path, rpath, endpoint))
        if path is None or rpath is None or endpoint is None:
            self.needUpdateJob = True
        else:
            self.needUpdateJob = False
            if rpath == path:
                buf = io.BytesIO()
                ftp = ftplib.FTP()
                ftp.connect(endpoint.address(), endpoint.port())
                ftp.login()
                ftp.retrbinary("RETR %s" % self.RemoteFilename, buf.write)
                ftp.quit()
                buf.seek(0)
                line1 = buf.readline().decode()
                line2 = buf.readline().decode()
                line3 = buf.readline().decode()
                if line1.startswith('(FreeCAD.Job: ') and line2.startswith(
                        '(FreeCAD.File: ') and line3.startswith(
                            '(FreeCAD.Signature: '):
                    title = line1[14:-2]
                    filename = line2[15:-2]
                    signature = line3[20:-2]
                    PathLog.debug("Loaded document: '%s' - '%s'" %
                                  (filename, title))
                    for docName, doc in FreeCAD.listDocuments().items():
                        PathLog.debug("Document: '%s' - '%s'" %
                                      (docName, doc.FileName))
                        if doc.FileName == filename:
                            job = doc.getObject(title)
                            if job:
                                sign = MKUtils.pathSignature(job.Path)
                                if str(sign) == signature:
                                    PathLog.info(
                                        "Job %s.%s loaded." %
                                        (job.Document.Label, job.Label))
                                else:
                                    PathLog.warning(
                                        "Job %s.%s is out of date!" %
                                        (job.Document.Label, job.Label))

        self.setJob(job)
예제 #3
0
    def executeUpload(self):
        job = self.job
        if job:
            currTool = None
            postlist = []
            for obj in job.Operations.Group:
                tc = PathUtil.toolControllerForOp(obj)
                if tc is not None:
                    if tc.ToolNumber != currTool:
                        postlist.append(tc)
                        currTool = tc.ToolNumber
                postlist.append(obj)

            post = PathPost.CommandPathPost()
            fail, gcode = post.exportObjectsWith(postlist, job, False)
            if not fail:
                print("POST: ", fail)
                preamble = "(FreeCAD.Job: %s)\n(FreeCAD.File: %s)\n(FreeCAD.Signature: %d)\n" % (
                    job.Name, job.Document.FileName,
                    MKUtils.pathSignature(job.Path))
                buf = io.BytesIO((preamble + gcode).encode())
                endpoint = self.mk.instance.endpoint.get('file')
                if endpoint:
                    ftp = ftplib.FTP()
                    ftp.connect(endpoint.address(), endpoint.port())
                    ftp.login()
                    ftp.storbinary("STOR %s" % self.mk.RemoteFilename, buf)
                    ftp.quit()
                    sequence = MKUtils.taskModeMDI(self.mk)
                    for tc in job.ToolController:
                        t = tc.Tool
                        sequence.append(
                            MKCommandTaskExecute("G10 L1 P%d R%g Z%g" %
                                                 (tc.ToolNumber, t.Diameter /
                                                  2., t.LengthOffset)))
                    sequence.extend(MKUtils.taskModeAuto(self.mk))
                    sequence.append(MKCommandTaskReset(False))
                    sequence.append(
                        MKCommandOpenFile(self.mk.remoteFilePath(), False))
                    self.mk['command'].sendCommands(sequence)
                else:
                    PathLog.error('No endpoint found')
            else:
                PathLog.error('Post processing failed')