✨ analysis: New --layers parameter
Analysis subcommand now has a new --layers parameter that allows us to export information on all detected layers. Also recognizes zhop. Helpful for comparing analysis with gcv results, see #4086
This commit is contained in:
1 parent
7bbecc9587
commit
643dcba468
2 files changed
+52
-5
No files matched your search
@@ -77,6 +77,7 @@ def util():
|
||||
@click.option("--g90-extruder", "g90_extruder", is_flag=True)
|
||||
@click.option("--bed-z", "bedz", type=float, default=0)
|
||||
@click.option("--progress", "progress", is_flag=True)
|
||||
@click.option("--layers", "layers", is_flag=True)
|
||||
@click.argument("path", type=click.Path())
|
||||
def gcode_command(
|
||||
path,
|
||||
@@ -90,6 +91,7 @@ def gcode_command(
|
||||
g90_extruder,
|
||||
bedz,
|
||||
progress,
|
||||
layers,
|
||||
):
|
||||
"""Runs a GCODE file analysis."""
|
||||
|
||||
@@ -125,7 +127,7 @@ def gcode_command(
|
||||
def progress_callback(percentage):
|
||||
click.echo("PROGRESS:{}".format(percentage))
|
||||
|
||||
interpreter = gcode(progress_callback=progress_callback)
|
||||
interpreter = gcode(progress_callback=progress_callback, incl_layers=layers)
|
||||
|
||||
interpreter.load(
|
||||
path,
|
||||
|
||||
@@ -211,9 +211,8 @@ regex_command = re.compile(
|
||||
|
||||
|
||||
class gcode(object):
|
||||
def __init__(self, progress_callback=None):
|
||||
def __init__(self, incl_layers=False, progress_callback=None):
|
||||
self._logger = logging.getLogger(__name__)
|
||||
self.layerList = None
|
||||
self.extrusionAmount = [0]
|
||||
self.extrusionVolume = [0]
|
||||
self.totalMoveTimeMinute = 0
|
||||
@@ -224,6 +223,25 @@ class gcode(object):
|
||||
self._minMax = MinMax3D()
|
||||
self._progress_callback = progress_callback
|
||||
|
||||
self._incl_layers = incl_layers
|
||||
self._layers = []
|
||||
self._current_layer = None
|
||||
|
||||
def _track_layer(self, pos):
|
||||
if not self._incl_layers:
|
||||
return
|
||||
|
||||
if self._current_layer is None or self._current_layer["z"] != pos.z:
|
||||
self._current_layer = {"z": pos.z, "minmax": MinMax3D(), "commands": 1}
|
||||
self._layers.append(self._current_layer)
|
||||
|
||||
elif self._current_layer:
|
||||
self._current_layer["minmax"].record(pos)
|
||||
|
||||
def _track_command(self):
|
||||
if self._current_layer:
|
||||
self._current_layer["commands"] += 1
|
||||
|
||||
@property
|
||||
def dimensions(self):
|
||||
size = self._minMax.size
|
||||
@@ -240,6 +258,23 @@ class gcode(object):
|
||||
"maxZ": None if math.isinf(self._minMax.max.z) else self._minMax.max.z,
|
||||
}
|
||||
|
||||
@property
|
||||
def layers(self):
|
||||
return [
|
||||
{
|
||||
"num": num + 1,
|
||||
"z": layer["z"],
|
||||
"commands": layer["commands"],
|
||||
"bounds": {
|
||||
"minX": layer["minmax"].min.x,
|
||||
"maxX": layer["minmax"].max.x,
|
||||
"minY": layer["minmax"].min.y,
|
||||
"maxY": layer["minmax"].max.y,
|
||||
},
|
||||
}
|
||||
for num, layer in enumerate(self._layers)
|
||||
]
|
||||
|
||||
def load(
|
||||
self,
|
||||
filename,
|
||||
@@ -453,6 +488,10 @@ class gcode(object):
|
||||
# time to add is maximum of both
|
||||
totalMoveTimeMinute += max(moveTimeXYZ, extrudeTime)
|
||||
|
||||
# process layers if there's extrusion
|
||||
if e:
|
||||
self._track_layer(pos)
|
||||
|
||||
elif gcode == "G4": # Delay
|
||||
S = getCodeFloat(line, "S")
|
||||
if S is not None:
|
||||
@@ -513,7 +552,6 @@ class gcode(object):
|
||||
pos.y = y
|
||||
if z is not None:
|
||||
pos.z = z
|
||||
|
||||
# M codes
|
||||
elif gcode == "M82": # Absolute E
|
||||
relativeE = False
|
||||
@@ -581,6 +619,9 @@ class gcode(object):
|
||||
for _ in range(len(totalExtrusion), currentExtruder + 1):
|
||||
totalExtrusion.append(0.0)
|
||||
|
||||
if gcode or tool:
|
||||
self._track_command()
|
||||
|
||||
if throttle is not None:
|
||||
throttle(lineNo, readBytes)
|
||||
if self._progress_callback is not None:
|
||||
@@ -605,13 +646,17 @@ class gcode(object):
|
||||
}
|
||||
|
||||
def get_result(self):
|
||||
return {
|
||||
result = {
|
||||
"total_time": self.totalMoveTimeMinute,
|
||||
"extrusion_length": self.extrusionAmount,
|
||||
"extrusion_volume": self.extrusionVolume,
|
||||
"dimensions": self.dimensions,
|
||||
"printing_area": self.printing_area,
|
||||
}
|
||||
if self._incl_layers:
|
||||
result["layers"] = self.layers
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def getCodeInt(line, code):
|
||||
|
||||
Reference in new issue
Block a user