From: daid Date: Mon, 12 Jan 2015 06:46:13 +0000 (+0100) Subject: Fixing issue #850 as well as fixing plugins with UltiGCode. X-Git-Tag: 15.01-RC8~9 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=a2e59280e4f215060b91acc689892c62b17e0790;p=cura.git Fixing issue #850 as well as fixing plugins with UltiGCode. --- diff --git a/Cura/util/bigDataStorage.py b/Cura/util/bigDataStorage.py index cfd34736..d1c4c86b 100644 --- a/Cura/util/bigDataStorage.py +++ b/Cura/util/bigDataStorage.py @@ -35,14 +35,16 @@ class BigDataStorage(object): ret = self.activeRead(size) return ret - def replaceAtStart(self, key, value): + def replaceAtStart(self, dictionary): data = self._list[0].getvalue() block0 = data[0:2048] - value = (value + ' ' * len(key))[:len(key)] - block0 = block0.replace(key, value) + block1 = StringIO.StringIO() + block1.write(data[2048:]) + self._list.insert(1, block1) + for key, value in dictionary.items(): + block0 = block0.replace(key, str(value)) self._list[0] = StringIO.StringIO() self._list[0].write(block0) - self._list[0].write(data[2048:]) def __len__(self): ret = 0 diff --git a/Cura/util/sliceEngine.py b/Cura/util/sliceEngine.py index 1a4e904c..5490390c 100644 --- a/Cura/util/sliceEngine.py +++ b/Cura/util/sliceEngine.py @@ -100,6 +100,9 @@ class EngineResult(object): return None return _('%0.2f meter %0.0f gram') % (float(self._filamentMM[e]) / 1000.0, self.getFilamentWeight(e) * 1000.0) + def getFilamentAmountMeters(self, e=0): + return float(self._filamentMM[e]) / 1000.0 + def getLog(self): return self._engineLog @@ -118,10 +121,13 @@ class EngineResult(object): def setHash(self, hash): self._modelHash = hash + def addReplaceTag(self, key, value): + self._replaceInfo[key] = value + + def applyReplaceTags(self): + self._gcodeData.replaceAtStart(self._replaceInfo) + def setFinished(self, result): - if result: - for k, v in self._replaceInfo.items(): - self._gcodeData.replaceAtStart(k, v) self._finished = result def isFinished(self): @@ -404,6 +410,11 @@ class Engine(object): returnCode = self._process.wait() logThread.join() if returnCode == 0: + self._result.addReplaceTag('#P_TIME#', self._result.getPrintTime()) + self._result.addReplaceTag('#F_AMNT#', self._result.getFilamentAmountMeters(0)) + self._result.addReplaceTag('#F_WGHT#', math.round(self._result.getFilamentWeight(0) * 1000.0)) + self._result.addReplaceTag('#F_COST#', self._result.getFilamentCost(0)) + self._result.applyReplaceTags() plugin_error = pluginInfo.runPostProcessingPlugins(self._result) if plugin_error is not None: print plugin_error @@ -452,7 +463,7 @@ class Engine(object): radius = profile.getProfileSettingFloat('filament_diameter') / 2.0 self._result._filamentMM[1] /= (math.pi * radius * radius) elif line.startswith('Replace:'): - self._result._replaceInfo[line.split(':')[1].strip()] = line.split(':')[2].strip() + self._result.addReplaceTag(line.split(':')[1].strip(), line.split(':')[2].strip()) else: self._result.addLog(line) line = stderr.readline()