Skip to content

Commit

Permalink
Fix for pre-processing (was skipping everything but tools used)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dendrowen committed Mar 14, 2024
1 parent dff55fc commit 706e95b
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 64 deletions.
114 changes: 56 additions & 58 deletions components/mmu_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,65 +113,63 @@ def parse_gcode_file(file_path):

with open(file_path, 'r') as in_file:
for line in in_file:
if line.startswith(";"):
# Discover slicer
if not slicer:
match = slicer_regex.match(line)
if match:
slicer = match.group(1).lower()
else:
# !referenced_tools! processing
if not has_tools_placeholder and METADATA_TOOL_DISCOVERY in line:
has_tools_placeholder = True

match = tools_regex.match(line)
# Discover slicer
if not slicer and line.startswith(";"):
match = slicer_regex.match(line)
if match:
slicer = match.group(1).lower()
# !referenced_tools! processing
if not has_tools_placeholder and METADATA_TOOL_DISCOVERY in line:
has_tools_placeholder = True

match = tools_regex.match(line)
if match:
tool = match.group("tool")
tools_used.add(int(tool))

# !colors! processing
if not has_colors_placeholder and METADATA_COLORS in line:
has_colors_placeholder = True

if not found_colors:
match = colors_regex.match(line)
if match:
colors_csv = [color.strip().lstrip('#') for color in match.group(1).split(';')]
colors.extend(colors_csv)
found_colors = all(len(c) > 0 for c in colors)

# !temperatures! processing
if not has_temps_placeholder and METADATA_TEMPS in line:
has_temps_placeholder = True

if not found_temps:
match = temps_regex.match(line)
if match:
temps_csv = re.split(';|,', match.group(2).strip())
temps.extend(temps_csv)
found_temps = True

# !materials! processing
if not has_materials_placeholder and METADATA_MATERIALS in line:
has_materials_placeholder = True

if not found_materials:
match = materials_regex.match(line)
if match:
materials_csv = match.group(1).strip().split(';')
materials.extend(materials_csv)
found_materials = True

# !purge_volumes! processing
if not has_purge_volumes_placeholder and METADATA_PURGE_VOLUMES in line:
has_purge_volumes_placeholder = True

if not found_purge_volumes:
match = purge_volumes_regex.match(line)
if match:
tool = match.group("tool")
tools_used.add(int(tool))

# !colors! processing
if not has_colors_placeholder and METADATA_COLORS in line:
has_colors_placeholder = True

if not found_colors:
match = colors_regex.match(line)
if match:
colors_csv = [color.strip().lstrip('#') for color in match.group(1).split(';')]
colors.extend(colors_csv)
found_colors = all(len(c) > 0 for c in colors)

# !temperatures! processing
if not has_temps_placeholder and METADATA_TEMPS in line:
has_temps_placeholder = True

if not found_temps:
match = temps_regex.match(line)
if match:
temps_csv = re.split(';|,', match.group(2).strip())
temps.extend(temps_csv)
found_temps = True

# !materials! processing
if not has_materials_placeholder and METADATA_MATERIALS in line:
has_materials_placeholder = True

if not found_materials:
match = materials_regex.match(line)
if match:
materials_csv = match.group(1).strip().split(';')
materials.extend(materials_csv)
found_materials = True

# !purge_volumes! processing
if not has_purge_volumes_placeholder and METADATA_PURGE_VOLUMES in line:
has_purge_volumes_placeholder = True

if not found_purge_volumes:
match = purge_volumes_regex.match(line)
if match:
purge_volumes_csv = match.group(2).strip().split(',')
purge_volumes.extend(purge_volumes_csv)
found_purge_volumes = True
purge_volumes_csv = match.group(2).strip().split(',')
purge_volumes.extend(purge_volumes_csv)
found_purge_volumes = True

return (has_tools_placeholder or has_colors_placeholder or has_temps_placeholder or has_materials_placeholder or has_purge_volumes_placeholder,
sorted(tools_used), colors, temps, materials, purge_volumes, slicer)
Expand Down
19 changes: 13 additions & 6 deletions extras/mmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,12 +1421,19 @@ def _track_gate_statistics(self, key, gate, count=1):

def _seconds_to_short_string(self, seconds):
if isinstance(seconds, float) or isinstance(seconds, int) or seconds.isnumeric():
seconds = int(seconds)
if seconds >= 3600:
return "{hour}:{min:0>2}:{sec:0>2}".format(hour=seconds // 3600, min=(seconds // 60) % 60, sec=seconds % 60)
if seconds >= 60:
return "{min}:{sec:0>2}".format(min=(seconds // 60) % 60, sec=seconds % 60)
return "0:{sec:0>2}".format(sec=seconds % 60)
s = int(round(seconds, 0))
h = s // 3600
m = (s // 60) % 60
ms = int(round((seconds * 1000) % 1000, 0))
s = s % 60

if h > 0:
return "{hour}:{min:0>2}:{sec:0>2}".format(hour=h, min=m, sec=s)
if m > 0:
return "{min}:{sec:0>2}".format(min=m, sec=s)
if s >= 10:
return "{sec}.{tenths}".format(sec=s, tenths=int(round(ms / 100, 0)))
return "{sec}.{hundreds}".format(sec=s, hundreds=int(round(ms / 10, 0)))
return seconds

def _seconds_to_string(self, seconds):
Expand Down

0 comments on commit 706e95b

Please sign in to comment.