| 65 | self._currentFile = None |
| 66 | |
| 67 | class GcodeInterpreter(object): |
| 68 | def __init__(self,loadedCallback,currentFile): |
| 69 | self._logger = logging.getLogger(__name__) |
| 70 | |
| 71 | self.layerList = None |
| 72 | self.extrusionAmount = [0] |
| 73 | self.extrusionVolume = [0] |
| 74 | self.totalMoveTimeMinute = 0 |
| 75 | self.filename = None |
| 76 | self.progressCallback = None |
| 77 | self._loadedCallback = loadedCallback |
| 78 | self._currentFile = currentFile |
| 79 | self._abort = False |
| 80 | self._filamentDiameter = 0 |
| 81 | |
| 82 | def cbGCodeAnalyzerReady(self,timePerLayers,totalPrintTime,layerCount,size,layer_height,total_filament,parent): |
| 83 | |
| 84 | self.progressCallback(100.0) |
| 85 | |
| 86 | self.layerList = timePerLayers |
| 87 | |
| 88 | self.totalMoveTimeMinute = totalPrintTime/60 |
| 89 | |
| 90 | self.layerCount = layerCount |
| 91 | |
| 92 | self.size = size |
| 93 | |
| 94 | self.layer_height = layer_height |
| 95 | |
| 96 | self.total_filament = None#total_filament has not got any information |
| 97 | |
| 98 | self._logger.debug("Analysis of file %s finished, notifying callback" % self.filename) |
| 99 | |
| 100 | parent._loadedCallback(parent._currentFile, parent) |
| 101 | |
| 102 | def cbGCodeAnalyzerException(self,parameters): |
| 103 | self._logger.warn("There was a problem using /usr/bin/astroprint/GCodeAnalyzer... using alternative algorithm") |
| 104 | |
| 105 | with open(parameters['filename'], "r") as f: |
| 106 | self._load(f) |
| 107 | |
| 108 | self._logger.debug("Analysis of file %s finished, notifying callback" % parameters['filename']) |
| 109 | |
| 110 | parameters['parent']._loadedCallback(parameters['parent']._currentFile, parameters['parent']) |
| 111 | |
| 112 | def load(self, filename): |
| 113 | if os.path.isfile(filename): |
| 114 | self.filename = filename |
| 115 | self._fileSize = os.stat(filename).st_size |
| 116 | |
| 117 | self.progressCallback(0.0) |
| 118 | GCodeAnalyzer(self.filename, False, self.cbGCodeAnalyzerReady, self.cbGCodeAnalyzerException, self).makeCalcs() |
| 119 | |
| 120 | def abort(self): |
| 121 | self._abort = True |
| 122 | |
| 123 | def _load(self, gcodeFile): |
| 124 | filePos = 0 |