def Activate(self): self.taskForm = CAMoticsUI(self) FreeCADGui.Control.showDialog(self.taskForm) self.job = FreeCADGui.Selection.getSelectionEx()[0].Object self.SIM.set_metric() self.SIM.set_resolution("high") bb = self.job.Stock.Shape.BoundBox self.SIM.set_workpiece( min=(bb.XMin, bb.YMin, bb.ZMin), max=(bb.XMax, bb.YMax, bb.ZMax) ) for t in self.job.Tools.Group: self.SIM.set_tool( t.ToolNumber, metric=True, shape=self.SHAPEMAP.get(t.Tool.ShapeName, "Cylindrical"), length=t.Tool.Length.Value, diameter=t.Tool.Diameter.Value, ) postlist = PathPost.buildPostList(self.job) PathLog.track(postlist) # self.filenames = [PathPost.resolveFileName(self.job)] success = True finalgcode = "" for idx, section in enumerate(postlist): partname = section[0] sublist = section[1] result, gcode, name = PathPost.CommandPathPost().exportObjectsWith( sublist, partname, self.job, idx, extraargs="--no-show-editor", ) self.filenames.append(name) PathLog.track(result, gcode, name) if result is None: success = False else: finalgcode += gcode if not success: return self.SIM.compute_path(finalgcode) self.SIM.wait() tot = sum([step["time"] for step in self.SIM.get_path()]) PathLog.debug("sim time: {}".format(tot)) self.taskForm.setRunTime(tot)
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')
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')