metadata.py: add parsing of filament type

This commit will add parsing of optional filament type metadata for:
- PrusaSlicer and it's derivatives
- Cura
- IdeaMaker

For Cura and IdeaMaker it is necessary to add a custom start g-code comment.
Cura:
;Filament type = {material_type}
IdeaMaker:
;Filament type = {filament_name_abbreviation1}

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
th33xitus 2021-12-27 23:05:48 +01:00 committed by Eric Callahan
parent 20d3c9961d
commit d145442d4b
1 changed files with 23 additions and 0 deletions

View File

@ -26,6 +26,7 @@ from typing import (
Dict,
List,
Type,
Union
)
if TYPE_CHECKING:
pass
@ -83,6 +84,12 @@ def _regex_find_first(pattern: str, data: str) -> Optional[float]:
return None
return val
def _regex_find_string(pattern: str, data: str) -> Optional[str]:
match = re.search(pattern, data)
if match:
return match.group(1)
return None
# Slicer parsing implementations
class BaseSlicer(object):
def __init__(self, file_path: str) -> None:
@ -172,6 +179,9 @@ class BaseSlicer(object):
def parse_filament_weight_total(self) -> Optional[float]:
return None
def parse_filament_type(self) -> Optional[str]:
return None
def parse_estimated_time(self) -> Optional[float]:
return None
@ -336,6 +346,10 @@ class PrusaSlicer(BaseSlicer):
return _regex_find_first(
r"total\sfilament\sused\s\[g\]\s=\s(\d+\.\d*)", self.footer_data)
def parse_filament_type(self) -> Optional[str]:
return _regex_find_string(
r";\sfilament_type\s=\s(.*)", self.footer_data)
def parse_estimated_time(self) -> Optional[float]:
time_match = re.search(
r';\sestimated\sprinting\stime.*', self.footer_data)
@ -453,6 +467,10 @@ class Cura(BaseSlicer):
return _regex_find_first(
r";Filament\sweight\s=\s.(\d+\.\d+).", self.header_data)
def parse_filament_type(self) -> Optional[str]:
return _regex_find_string(
r";Filament\stype\s=\s(.*)", self.header_data)
def parse_estimated_time(self) -> Optional[float]:
return self._parse_max_float(r";TIME:.*", self.header_data)
@ -671,6 +689,10 @@ class IdeaMaker(BaseSlicer):
return sum(filament)
return None
def parse_filament_type(self) -> Optional[str]:
return _regex_find_string(
r";Filament\stype\s=\s(.*)", self.header_data)
def parse_filament_weight_total(self) -> Optional[float]:
pi = 3.141592653589793
length = _regex_find_floats(
@ -751,6 +773,7 @@ SUPPORTED_DATA = [
'first_layer_bed_temp',
'filament_total',
'filament_weight_total',
'filament_type',
'thumbnails']
def process_objects(file_path: str) -> None: