Merge branch 'cura-integration' of https://github.com/hendricksonrw/OctoPrint into cura-integration

This commit is contained in:
Ross Hendrickson 2013-08-15 22:49:55 -05:00
commit 70b2325de0
7 changed files with 65 additions and 38 deletions

View file

@ -52,7 +52,7 @@ class CuraEngine(object):
logging.info("Subprocess args: %s" % str(call_args))
process = subprocess.call(call_args)
call_back(*call_back_args)
logging.info("Slicing call back complete")
logging.info("Slicing call back complete:%s" % str(call_back))
args = [self.cura_path, '-s', config, '-o', gcode, file_path]
logging.info('CuraEngine args:%s' % str(args))

View file

@ -0,0 +1,4 @@
class FileDestinations(object):
SDCARD = "sdcard"
LOCAL = "local"

View file

@ -117,14 +117,19 @@ class GcodeManager:
#~~ file handling
def addFile(self, file):
def addFile(self, file, destination):
from octoprint.util import isSTLFileName
from octoprint.util import isGcodeFileName
from octoprint.filemanager.destinations import FileDestinations
if not file:
if not file or not destination:
return None
local = True if destination == FileDestinations.LOCAL else False
absolutePath = self.getAbsolutePath(file.filename, mustExist=False)
logging.info("Adding file:%s" % absolutePath)
if absolutePath is None:
return None
@ -133,19 +138,22 @@ class GcodeManager:
filename = file.filename
if isGcodeFileName(filename):
logging.info("File is Gcode File")
return self.processGcode(absolutePath)
curaEnabled = self._settings.get(["curaEngine", "enabled"])
logging.info("Cura Enabled %s" % str(curaEnabled))
if isSTLFileName(filename) and curaEnabled:
if isSTLFileName(filename) and curaEnabled and local:
logging.info("File is STL - Needs to be sliced")
gcodePath = util.genGcodeFileName(absolutePath)
logging.info("FILENAME: %s" % filename)
callBackArgs = [gcodePath]
callBack = self.processGcode
return self.processSTL(
filename, absolutePath, callBack, callBackArgs)
self.processSTL(absolutePath, callBack, callBackArgs)
return filename
def getFutureFileName(self, file):
if not file:
@ -157,21 +165,19 @@ class GcodeManager:
return self._getBasicFilename(absolutePath)
def processSTL(self, filename, absolutePath, callBack, callBackArgs):
def processSTL(self, absolutePath, callBack, callBackArgs):
from octoprint.cura import CuraFactory
curaEngine = CuraFactory.create_slicer()
gcodePath = util.genGcodeFileName(absolutePath)
config = self._settings.get(["curaEngine", "config"])
curaEngine.process_file(
config, gcodePath, absolutePath, callBack, callBackArgs)
config, gcodePath, absolutePath, callBack, callBackArgs)
def processGcode(self, absolutePath):
if absolutePath is None:
return None
filename = self._getBasicFilename(absolutePath)
@ -185,19 +191,6 @@ class GcodeManager:
return filename
if absolutePath is None:
return None
basename = self._getBasicFilename(absolutePath)
if basename in self._metadata.keys():
# delete existing metadata entry, since the file is going to get overwritten
del self._metadata[basename]
self._metadataDirty = True
self._saveMetadata()
file.save(absolutePath)
self._metadataAnalyzer.addFileToQueue(basename)
return basename
def getFutureFilename(self, file):
if not file:
return None
@ -211,10 +204,16 @@ class GcodeManager:
def removeFile(self, filename):
filename = self._getBasicFilename(filename)
absolutePath = self.getAbsolutePath(filename)
stlPath = util.genStlFileName(absolutePath)
if absolutePath is None:
return
if stlPath:
os.remove(stlPath)
os.remove(absolutePath)
if filename in self._metadata.keys():
del self._metadata[filename]
self._metadataDirty = True

View file

@ -7,6 +7,7 @@ import datetime
import threading
import copy
import os
import logging
#import logging, logging.config
@ -463,27 +464,26 @@ class Printer():
from octoprint.util import isGcodeFileName
from octoprint.util import isSTLFileName
logging.info("Adding SD Card file:%s" % filename)
if not self._comm or self._comm.isBusy():
logging.error("No connection to printer or printer is busy")
return
if isGcodeFileName(filename):
logging.info("Sending Gcode to SD card")
self.streamSdFile(filename, absolutePath)
if isSTLFileName(filename):
logging.info("Slicing stl and then sending to SD card")
gcodePath = util.genGcodeFileName(absolutePath)
callBackArgs = [filename, absolutePath]
gcodeFileName = util.genGcodeFileName(filename)
callBackArgs = [gcodeFileName, gcodePath]
callBack = self.streamSdFile
gcodeManager = GcodeManager()
gcodeManager.processSTL(
filename, absolutePath, callBack, callBackArgs)
self._gcodeManager.processSTL(
absolutePath, callBack, callBackArgs)
def streamSdFile(filename, absolutePath):
self._sdStreamer = SdFileStreamer(self._comm, filename, absolutePath, self._onSdFileStreamProgress, self._onSdFileStreamFinish)
self._sdStreamer.start()
logging.info("Stream file to SD started")
def addSdFile(self, filename, path):
def streamSdFile(self, filename, path):
if not self._comm or self._comm.isBusy():
return
self._comm.startFileTransfer(path, filename[:8].lower() + ".gco")

View file

@ -19,6 +19,8 @@ import octoprint.timelapse
import octoprint.gcodefiles as gcodefiles
import octoprint.util as util
import octoprint.users as users
from octoprint.filemanager.destinations import FileDestinations
import octoprint.events as events
@ -311,12 +313,16 @@ def readGcodeFile(filename):
@login_required
def uploadGcodeFile():
if "gcode_file" in request.files.keys():
logging.info("Uploading Gcode File")
file = request.files["gcode_file"]
sd = "target" in request.values.keys() and request.values["target"] == "sd";
logging.info("SD:%s" % str(sd))
currentFilename = None
currentSd = None
currentJob = printer.getCurrentJob()
logging.info("Current Job:%s" % str(currentJob))
if currentJob is not None and "filename" in currentJob.keys() and "sd" in currentJob.keys():
currentFilename = currentJob["filename"]
currentSd = currentJob["sd"]
@ -329,13 +335,16 @@ def uploadGcodeFile():
# trying to overwrite currently selected file, but it is being printed
return make_response("Trying to overwrite file that is currently being printed: %s" % currentFilename, 403)
filename = gcodeManager.addFile(file)
destination = FileDestinations.SDCARD if sd else FileDestinations.LOCAL
filename = gcodeManager.addFile(file, destination)
if filename is None:
return make_response("Could not upload the file %s" % file.filename, 500)
absFilename = gcodeManager.getAbsolutePath(filename)
if sd:
logging.info("Add to SD file")
printer.addSdFile(filename, absFilename)
if currentFilename == filename and currentSd == sd:

View file

@ -82,7 +82,16 @@ def genGcodeFileName(filename):
return filename.replace('.stl', '.gcode')
def genStlFileName(filename):
if not filename:
return None
if "." not in filename:
return filename + ".stl"
return filename.replace('.gcode', '.stl')
def isDevVersion():
gitPath = os.path.abspath(os.path.join(os.path.split(os.path.abspath(__file__))[0], "../../.git"))
return os.path.exists(gitPath)

View file

@ -332,10 +332,13 @@ class MachineCom(object):
eventManager().fire("Error", self.getErrorString())
def startFileTransfer(self, filename, remoteFilename):
logging.info("Starting File Transfer:%s" % filename)
if not self.isOperational() or self.isBusy():
logging.info("Printer is not operation or busy")
return
self._currentFile = StreamingGcodeFileInformation(filename)
logging.info("Starting to send currentfile:%s" % str(self._currentFile))
self._currentFile.start()
self.sendCommand("M28 %s" % remoteFilename)
@ -405,6 +408,7 @@ class MachineCom(object):
def endSdFileTransfer(self, filename):
if not self.isOperational() or self.isBusy():
logging.info("endSdFile busy")
return
self.sendCommand("M29 %s" % filename.lower())
@ -595,6 +599,8 @@ class MachineCom(object):
self._callback.mcPrintjobDone()
self._changeState(self.STATE_OPERATIONAL)
eventManager().fire("PrintDone")
elif 'Done saving file' in line:
self.refreshSdFiles()
##~~ Message handling
elif line.strip() != '' and line.strip() != 'ok' and not line.startswith("wait") and not line.startswith('Resend:') and line != 'echo:Unknown command:""\n' and self.isOperational():
@ -674,8 +680,8 @@ class MachineCom(object):
startSeen = True
elif "ok" in line and startSeen:
self._changeState(self.STATE_OPERATIONAL)
if self._sdAvailable:
self.refreshSdFiles()
if not self._sdAvailable:
self.initSdCard()
eventManager().fire("Connected", "%s at %s baud" % (self._port, self._baudrate))
elif time.time() > timeout:
self.close()