Пример #1
0
	def _do_analysis(self, high_priority=False):
		try:
			def throttle():
				time.sleep(0.01)

			throttle_callback = throttle
			if high_priority:
				throttle_callback = None

			self._gcode = gcodeInterpreter.gcode()
			self._gcode.load(self._current.absolute_path, self._current.printer_profile, throttle=throttle_callback)

			result = dict()
			if self._gcode.totalMoveTimeMinute:
				result["estimatedPrintTime"] = self._gcode.totalMoveTimeMinute * 60
			if self._gcode.extrusionAmount:
				result["filament"] = dict()
				for i in range(len(self._gcode.extrusionAmount)):
					result["filament"]["tool%d" % i] = {
						"length": self._gcode.extrusionAmount[i],
						"volume": self._gcode.extrusionVolume[i]
					}
			return result
		finally:
			self._gcode = None
Пример #2
0
    def _do_analysis(self, high_priority=False):
        try:

            def throttle():
                time.sleep(0.01)

            throttle_callback = throttle
            if high_priority:
                throttle_callback = None

            self._gcode = gcodeInterpreter.gcode()
            self._gcode.load(self._current.absolute_path,
                             self._current.printer_profile,
                             throttle=throttle_callback)

            result = dict()
            result["printingArea"] = self._gcode.printing_area
            result["dimensions"] = self._gcode.dimensions
            if self._gcode.totalMoveTimeMinute:
                result[
                    "estimatedPrintTime"] = self._gcode.totalMoveTimeMinute * 60
            if self._gcode.extrusionAmount:
                result["filament"] = dict()
                for i in range(len(self._gcode.extrusionAmount)):
                    result["filament"]["tool%d" % i] = {
                        "length": self._gcode.extrusionAmount[i],
                        "volume": self._gcode.extrusionVolume[i]
                    }
            return result
        finally:
            self._gcode = None
Пример #3
0
	def _do_analysis(self, high_priority=False):
		try:
			throttle = settings().getFloat(["gcodeAnalysis", "throttle_highprio"]) if high_priority else settings().getFloat(["gcodeAnalysis", "throttle_normalprio"])
			if throttle > 0:
				def throttle_callback():
					time.sleep(throttle)
			else:
				throttle_callback = None

			self._gcode = gcodeInterpreter.gcode()
			self._gcode.load(self._current.absolute_path, self._current.printer_profile, throttle=throttle_callback)

			result = dict()
			result["printingArea"] = self._gcode.printing_area
			result["dimensions"] = self._gcode.dimensions
			if self._gcode.totalMoveTimeMinute:
				result["estimatedPrintTime"] = self._gcode.totalMoveTimeMinute * 60
			if self._gcode.extrusionAmount:
				result["filament"] = dict()
				for i in range(len(self._gcode.extrusionAmount)):
					result["filament"]["tool%d" % i] = {
						"length": self._gcode.extrusionAmount[i],
						"volume": self._gcode.extrusionVolume[i]
					}
			return result
		except gcodeInterpreter.AnalysisAborted as ex:
			raise AnalysisAborted(reenqueue=ex.reenqueue)
		finally:
			self._gcode = None
Пример #4
0
    def run(self):
        # Send an initial M110 to reset the line counter to zero.
        prevLineType = lineType = "CUSTOM"
        gcodeList = ["M110"]
        filesize = os.stat(self._filename).st_size
        with open(self._filename, "r") as file:
            for line in file:
                if line.startswith(";TYPE:"):
                    lineType = line[6:].strip()
                if ";" in line:
                    line = line[0 : line.find(";")]
                line = line.strip()
                if len(line) > 0:
                    if prevLineType != lineType:
                        gcodeList.append((line, lineType))
                    else:
                        gcodeList.append(line)
                    prevLineType = lineType
                self._onLoadingProgress(float(file.tell()) / float(filesize))

        self._gcodeList = gcodeList
        if settings().getBoolean("feature", "analyzeGcode"):
            self._gcode = gcodeInterpreter.gcode()
            self._gcode.progressCallback = self._onParsingProgress
            self._gcode.loadList(self._gcodeList)

        self._loadedCallback(self._filename, self._gcode, self._gcodeList)
Пример #5
0
def gcode_command(path, speedx, speedy, speedz, offset, maxt, throttle,
                  throttle_lines, g90_extruder, progress):
    """Runs a GCODE file analysis."""

    import time
    import yaml
    from octoprint.util import monotonic_time
    from octoprint.util.gcodeInterpreter import gcode

    throttle_callback = None
    if throttle:

        def throttle_callback(filePos, readBytes):
            if filePos % throttle_lines == 0:
                # only apply throttle every $throttle_lines lines
                time.sleep(throttle)

    offsets = offset
    if offsets is None:
        offsets = []
    elif isinstance(offset, tuple):
        offsets = list(offsets)
    offsets = [(0, 0)] + offsets
    if len(offsets) < maxt:
        offsets += [(0, 0)] * (maxt - len(offsets))

    start_time = monotonic_time()

    progress_callback = None
    if progress:

        def progress_callback(percentage):
            click.echo("PROGRESS:{}".format(percentage))

    interpreter = gcode(progress_callback=progress_callback)

    interpreter.load(path,
                     speedx=speedx,
                     speedy=speedy,
                     offsets=offsets,
                     throttle=throttle_callback,
                     max_extruders=maxt,
                     g90_extruder=g90_extruder)

    click.echo("DONE:{}s".format(monotonic_time() - start_time))
    click.echo("RESULTS:")
    click.echo(
        yaml.safe_dump(interpreter.get_result(),
                       default_flow_style=False,
                       indent=4,
                       allow_unicode=True))
Пример #6
0
	def _do_analysis(self):
		try:
			self._gcode = gcodeInterpreter.gcode()
			self._gcode.load(self._current.absolute_path, self._current.printer_profile)

			result = dict()
			if self._gcode.totalMoveTimeMinute:
				result["estimatedPrintTime"] = self._gcode.totalMoveTimeMinute * 60
			if self._gcode.extrusionAmount:
				result["filament"] = dict()
				for i in range(len(self._gcode.extrusionAmount)):
					result["filament"]["tool%d" % i] = {
						"length": self._gcode.extrusionAmount[i],
						"volume": self._gcode.extrusionVolume[i]
					}
			return result
		finally:
			self._gcode = None
Пример #7
0
    def _analyzeGcode(self, filename):
        path = self._getPathCallback(filename)
        if path is None:
            return

        self._currentFile = filename
        self._currentProgress = 0

        try:
            self._logger.debug("Starting analysis of file %s" % filename)
            self._gcode = gcodeInterpreter.gcode()
            self._gcode.progressCallback = self._onParsingProgress
            self._gcode.load(path)
            self._logger.debug("Analysis of file %s finished, notifying callback" % filename)
            self._loadedCallback(self._currentFile, self._gcode)
        finally:
            self._gcode = None
            self._currentProgress = None
            self._currentFile = None
Пример #8
0
	def _analyzeGcode(self, filename):
		path = self._getPathCallback(filename)
		if path is None:
			return

		self._currentFile = filename
		self._currentProgress = 0

		try:
			self._logger.debug("Starting analysis of file %s" % filename)
			self._gcode = gcodeInterpreter.gcode()
			self._gcode.progressCallback = self._onParsingProgress
			self._gcode.load(path)
			self._logger.debug("Analysis of file %s finished, notifying callback" % filename)
			self._loadedCallback(self._currentFile, self._gcode)
		finally:
			self._gcode = None
			self._currentProgress = None
			self._currentFile = None
Пример #9
0
def gcode_command(path, speedx, speedy, speedz, offset, maxt, throttle, throttle_lines, g90_extruder, progress):
	"""Runs a GCODE file analysis."""

	import time
	import yaml
	from octoprint.util.gcodeInterpreter import gcode

	throttle_callback = None
	if throttle:
		def throttle_callback(filePos, readBytes):
			if filePos % throttle_lines == 0:
				# only apply throttle every $throttle_lines lines
				time.sleep(throttle)

	offsets = offset
	if offsets is None:
		offsets = []
	elif isinstance(offset, tuple):
		offsets = list(offsets)
	offsets = [(0, 0)] + offsets
	if len(offsets) < maxt:
		offsets += [(0, 0)] * (maxt - len(offsets))

	start_time = time.time()

	progress_callback = None
	if progress:
		def progress_callback(percentage):
			click.echo("PROGRESS:{}".format(percentage))
	interpreter = gcode(progress_callback=progress_callback)

	interpreter.load(path,
					 speedx=speedx,
					 speedy=speedy,
					 offsets=offsets,
					 throttle=throttle_callback,
					 max_extruders=maxt,
					 g90_extruder=g90_extruder)

	click.echo("DONE:{}s".format(time.time() - start_time))
	click.echo("RESULTS:")
	click.echo(yaml.safe_dump(interpreter.get_result(), default_flow_style=False, indent="    ", allow_unicode=True))
Пример #10
0
	def _analyzeGcode(self, filename):
		path = self._getPathCallback(filename)
		if path is None or not os.path.exists(path):
			return

		self._currentFile = filename
		self._currentProgress = 0

		try:
			self._logger.debug("Starting analysis of file %s" % filename)
			eventManager().fire(Events.METADATA_ANALYSIS_STARTED, {"file": filename})
			self._gcode = gcodeInterpreter.gcode()
			self._gcode.progressCallback = self._onParsingProgress
			self._gcode.load(path)
			self._logger.debug("Analysis of file %s finished, notifying callback" % filename)
			self._loadedCallback(self._currentFile, self._gcode)
		finally:
			self._gcode = None
			self._currentProgress = None
			self._currentFile = None
Пример #11
0
    def _do_analysis(self):
        try:
            self._gcode = gcodeInterpreter.gcode()
            self._gcode.load(self._current.absolute_path,
                             self._current.printer_profile)

            result = dict()
            if self._gcode.totalMoveTimeMinute:
                result[
                    "estimatedPrintTime"] = self._gcode.totalMoveTimeMinute * 60
            if self._gcode.extrusionAmount:
                result["filament"] = dict()
                for i in range(len(self._gcode.extrusionAmount)):
                    result["filament"]["tool%d" % i] = {
                        "length": self._gcode.extrusionAmount[i],
                        "volume": self._gcode.extrusionVolume[i]
                    }
            return result
        finally:
            self._gcode = None
Пример #12
0
    def _analyzeGcode(self, filename):
        path = self._getPathCallback(filename)
        if path is None or not os.path.exists(path):
            return

        self._currentFile = filename
        self._currentProgress = 0

        try:
            self._logger.debug("Starting analysis of file %s" % filename)
            eventManager().fire(Events.METADATA_ANALYSIS_STARTED,
                                {"file": filename})
            self._gcode = gcodeInterpreter.gcode()
            self._gcode.progressCallback = self._onParsingProgress
            self._gcode.load(path)
            self._logger.debug(
                "Analysis of file %s finished, notifying callback" % filename)
            self._loadedCallback(self._currentFile, self._gcode)
        finally:
            self._gcode = None
            self._currentProgress = None
            self._currentFile = None
Пример #13
0
def gcode_command(
    path,
    speedx,
    speedy,
    speedz,
    offset,
    maxt,
    throttle,
    throttle_lines,
    g90_extruder,
    bedz,
    progress,
    layers,
):
    """Runs a GCODE file analysis."""

    import time

    import yaml

    from octoprint.util import monotonic_time
    from octoprint.util.gcodeInterpreter import gcode

    throttle_callback = None
    if throttle:

        def throttle_callback(filePos, readBytes):
            if filePos % throttle_lines == 0:
                # only apply throttle every $throttle_lines lines
                time.sleep(throttle)

    offsets = offset
    if offsets is None:
        offsets = []
    elif isinstance(offset, tuple):
        offsets = list(offsets)
    offsets = [(0, 0)] + offsets
    if len(offsets) < maxt:
        offsets += [(0, 0)] * (maxt - len(offsets))

    start_time = monotonic_time()

    progress_callback = None
    if progress:

        def progress_callback(percentage):
            click.echo("PROGRESS:{}".format(percentage))

    interpreter = gcode(progress_callback=progress_callback,
                        incl_layers=layers)

    interpreter.load(
        path,
        speedx=speedx,
        speedy=speedy,
        offsets=offsets,
        throttle=throttle_callback,
        max_extruders=maxt,
        g90_extruder=g90_extruder,
        bed_z=bedz,
    )

    click.echo("DONE:{}s".format(monotonic_time() - start_time))

    result = interpreter.get_result()
    if empty_result(result):
        click.echo(
            "EMPTY:There are no extrusions in the file, nothing to analyse")
        sys.exit(0)

    if not validate_result(result):
        click.echo(
            "ERROR:Invalid analysis result, please create a bug report in OctoPrint's "
            "issue tracker and be sure to also include the GCODE file with which this "
            "happened")
        sys.exit(-1)

    click.echo("RESULTS:")
    click.echo(
        yaml.safe_dump(
            interpreter.get_result(),
            default_flow_style=False,
            indent=2,
            allow_unicode=True,
        ))