- def load(self, filename):
- fileSize = os.stat(filename).st_size
- filePos = 0
- gcodeFile = open(filename, 'r')
- pos = util3d.Vector3()
- posOffset = util3d.Vector3()
+ def load(self, data):
+ self.filename = None
+ if type(data) in types.StringTypes and os.path.isfile(data):
+ self.filename = data
+ self._fileSize = os.stat(data).st_size
+ gcodeFile = open(data, 'r')
+ self._load(gcodeFile)
+ gcodeFile.close()
+ elif type(data) is list:
+ self._load(data)
+ else:
+ self._fileSize = len(data.getvalue())
+ self._load(StringIO.StringIO(data.getvalue()))
+
+ def calculateWeight(self):
+ #Calculates the weight of the filament in kg
+ radius = float(profile.getProfileSetting('filament_diameter')) / 2
+ volumeM3 = (self.extrusionAmount * (math.pi * radius * radius)) / (1000*1000*1000)
+ return volumeM3 * profile.getPreferenceFloat('filament_physical_density')
+
+ def calculateCost(self):
+ cost_kg = profile.getPreferenceFloat('filament_cost_kg')
+ cost_meter = profile.getPreferenceFloat('filament_cost_meter')
+ if cost_kg > 0.0 and cost_meter > 0.0:
+ return "%.2f / %.2f" % (self.calculateWeight() * cost_kg, self.extrusionAmount / 1000 * cost_meter)
+ elif cost_kg > 0.0:
+ return "%.2f" % (self.calculateWeight() * cost_kg)
+ elif cost_meter > 0.0:
+ return "%.2f" % (self.extrusionAmount / 1000 * cost_meter)
+ return None
+
+ def _load(self, gcodeFile):
+ self.layerList = []
+ pos = [0.0,0.0,0.0]
+ posOffset = [0.0, 0.0, 0.0]