metadata: add support for unknown PrusaSlicer forks
Match any slicer conforming to the original identifier provided used by PrusaSlicer. This allows Moonraker to process metadata for the numerous PS forks that are created. Create a derivative class for BambuStudio, as it is sufficiently different that it requires its own implementation to correctly process all metadata. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
1 parent
343bba4c60
commit
4637d70ac1
1 file changed
+103
-32
@@ -360,23 +360,41 @@ class UnknownSlicer(BaseSlicer):
|
||||
|
||||
class PrusaSlicer(BaseSlicer):
|
||||
def check_identity(self, data: str) -> bool:
|
||||
aliases = {
|
||||
known_aliases = {
|
||||
'PrusaSlicer': r"PrusaSlicer\s(.*)\son",
|
||||
'SuperSlicer': r"SuperSlicer\s(.*)\son",
|
||||
'OrcaSlicer': r"OrcaSlicer\s(.*)\son",
|
||||
'MomentSlicer': r"MomentSlicer\s(.*)\son",
|
||||
'SliCR-3D': r"SliCR-3D\s(.*)\son",
|
||||
'BambuStudio': r"BambuStudio[^ ]*\s(.*)\n",
|
||||
'A3dp-Slicer': r"A3dp-Slicer\s(.*)\son",
|
||||
'QIDISlicer': r"QIDISlicer\s(.*)\son",
|
||||
}
|
||||
for name, expr in aliases.items():
|
||||
match = re.search(expr, data)
|
||||
if match:
|
||||
self.slicer_name = name
|
||||
self.slicer_version = match.group(1)
|
||||
return True
|
||||
return False
|
||||
excluded_aliases = ("slic3r, slic3r prusa edition")
|
||||
# Default base pattern for PrusaSlicer and its forks
|
||||
pattern = r"; generated by (.+?) on \d{4}-\d{2}-\d{2} at \d{2}:\d{2}:\d{2}"
|
||||
match = re.search(pattern, data)
|
||||
if match is None:
|
||||
# Fall back to search by known alias
|
||||
for name, expr in known_aliases.items():
|
||||
match = re.search(expr, data)
|
||||
if match:
|
||||
logging.info(
|
||||
f"Detected PrusaSlicer fork via fallback: {name}"
|
||||
)
|
||||
self.slicer_name = name
|
||||
self.slicer_version = match.group(1)
|
||||
return True
|
||||
return False
|
||||
name, _, version = match.group(1).rpartition(" ")
|
||||
if name.lower() in excluded_aliases:
|
||||
return False
|
||||
self.slicer_name = name
|
||||
self.slicer_version = version
|
||||
return True
|
||||
|
||||
@property
|
||||
def config_data(self) -> str:
|
||||
return self.footer_data
|
||||
|
||||
def has_objects(self) -> bool:
|
||||
return self._check_has_objects(
|
||||
@@ -384,18 +402,18 @@ class PrusaSlicer(BaseSlicer):
|
||||
|
||||
def parse_first_layer_height(self) -> Optional[float]:
|
||||
# Check percentage
|
||||
pct = regex_find_float(r"; first_layer_height = (%F)%", self.footer_data)
|
||||
pct = regex_find_float(r"; first_layer_height = (%F)%", self.config_data)
|
||||
if pct is not None:
|
||||
if self.layer_height is None:
|
||||
# Failed to parse the original layer height, so it is not
|
||||
# possible to calculate a percentage
|
||||
return None
|
||||
return round(pct / 100. * self.layer_height, 6)
|
||||
return regex_find_float(r"; first_layer_height = (%F)", self.footer_data)
|
||||
return regex_find_float(r"; first_layer_height = (%F)", self.config_data)
|
||||
|
||||
def parse_layer_height(self) -> Optional[float]:
|
||||
self.layer_height = regex_find_float(
|
||||
r"; layer_height = (%F)", self.footer_data
|
||||
r"; layer_height = (%F)", self.config_data
|
||||
)
|
||||
return self.layer_height
|
||||
|
||||
@@ -412,7 +430,7 @@ class PrusaSlicer(BaseSlicer):
|
||||
return regex_find_max_float(r"G1\sZ(%F)\sF", self.footer_data)
|
||||
|
||||
def parse_filament_total(self) -> Optional[float]:
|
||||
line = regex_find_string(r'filament\sused\s\[mm\]\s=\s(%S)\n', self.footer_data)
|
||||
line = regex_find_string(r'filament\sused\s\[mm\]\s=\s(%S)\n', self.config_data)
|
||||
if line:
|
||||
filament = regex_find_floats(
|
||||
r"(%F)", line
|
||||
@@ -424,11 +442,11 @@ class PrusaSlicer(BaseSlicer):
|
||||
def parse_filament_weight_total(self) -> Optional[float]:
|
||||
return regex_find_float(
|
||||
r"total\sfilament\sused\s\[g\]\s=\s(%F)",
|
||||
self.footer_data
|
||||
self.config_data
|
||||
)
|
||||
|
||||
def parse_filament_weights(self) -> Optional[List[float]]:
|
||||
line = regex_find_string(r'filament\sused\s\[g\]\s=\s(%S)\n', self.footer_data)
|
||||
line = regex_find_string(r'filament\sused\s\[g\]\s=\s(%S)\n', self.config_data)
|
||||
if line:
|
||||
weights = regex_find_floats(
|
||||
r"(%F)", line
|
||||
@@ -439,7 +457,7 @@ class PrusaSlicer(BaseSlicer):
|
||||
|
||||
def parse_filament_type(self) -> Optional[str]:
|
||||
result = regex_find_strings(
|
||||
r";\sfilament_type\s=\s(%S)", ",;", self.footer_data
|
||||
r";\sfilament_type\s=\s(%S)", ",;", self.config_data
|
||||
)
|
||||
if len(result) > 1:
|
||||
return json.dumps(result)
|
||||
@@ -449,7 +467,7 @@ class PrusaSlicer(BaseSlicer):
|
||||
|
||||
def parse_filament_name(self) -> Optional[str]:
|
||||
result = regex_find_strings(
|
||||
r";\sfilament_settings_id\s=\s(%S)", ",;", self.footer_data
|
||||
r";\sfilament_settings_id\s=\s(%S)", ",;", self.config_data
|
||||
)
|
||||
if len(result) > 1:
|
||||
return json.dumps(result)
|
||||
@@ -459,17 +477,17 @@ class PrusaSlicer(BaseSlicer):
|
||||
|
||||
def parse_filament_colors(self) -> Optional[List[str]]:
|
||||
return regex_find_strings(
|
||||
r";\sfilament_colour\s=\s(%S)", ",;", self.footer_data
|
||||
r";\sfilament_colour\s=\s(%S)", ",;", self.config_data
|
||||
)
|
||||
|
||||
def parse_extruder_colors(self) -> Optional[List[str]]:
|
||||
return regex_find_strings(
|
||||
r";\sextruder_colour\s=\s(%S)", ",;", self.footer_data
|
||||
r";\sextruder_colour\s=\s(%S)", ",;", self.config_data
|
||||
)
|
||||
|
||||
def parse_filament_temps(self) -> Optional[List[int]]:
|
||||
temps = regex_find_strings(
|
||||
r";\s(?:nozzle_)?temperature\s=\s(%S)", ",;", self.footer_data
|
||||
r";\s(?:nozzle_)?temperature\s=\s(%S)", ",;", self.config_data
|
||||
)
|
||||
try:
|
||||
return [int(t) for t in temps]
|
||||
@@ -478,7 +496,7 @@ class PrusaSlicer(BaseSlicer):
|
||||
|
||||
def parse_referenced_tools(self) -> Optional[List[int]]:
|
||||
tools = regex_find_strings(
|
||||
r";\sreferenced_tools\s=\s(%S)", ",;", self.footer_data
|
||||
r";\sreferenced_tools\s=\s(%S)", ",;", self.config_data
|
||||
)
|
||||
try:
|
||||
return [int(t) for t in tools]
|
||||
@@ -487,12 +505,13 @@ class PrusaSlicer(BaseSlicer):
|
||||
|
||||
def parse_mmu_print(self) -> Optional[int]:
|
||||
return regex_find_int(
|
||||
r";\ssingle_extruder_multi_material\s=\s(%D)", self.footer_data
|
||||
r";\ssingle_extruder_multi_material\s=\s(%D)", self.config_data
|
||||
)
|
||||
|
||||
def parse_estimated_time(self) -> Optional[float]:
|
||||
time_match = re.search(
|
||||
r';\sestimated\sprinting\stime.*', self.footer_data)
|
||||
r';\sestimated\sprinting\stime.*', self.config_data
|
||||
)
|
||||
if not time_match:
|
||||
return None
|
||||
total_time = 0
|
||||
@@ -510,32 +529,32 @@ class PrusaSlicer(BaseSlicer):
|
||||
|
||||
def parse_first_layer_extr_temp(self) -> Optional[float]:
|
||||
return regex_find_float(
|
||||
r"; first_layer_temperature = (%F)", self.footer_data
|
||||
r"; first_layer_temperature = (%F)", self.config_data
|
||||
)
|
||||
|
||||
def parse_first_layer_bed_temp(self) -> Optional[float]:
|
||||
return regex_find_float(
|
||||
r"; first_layer_bed_temperature = (%F)", self.footer_data
|
||||
r"; first_layer_bed_temperature = (%F)", self.config_data
|
||||
)
|
||||
|
||||
def parse_chamber_temp(self) -> Optional[float]:
|
||||
return regex_find_float(
|
||||
r"; chamber_temperature = (%F)", self.footer_data
|
||||
r"; chamber_temperature = (%F)", self.config_data
|
||||
)
|
||||
|
||||
def parse_nozzle_diameter(self) -> Optional[float]:
|
||||
return regex_find_float(
|
||||
r";\snozzle_diameter\s=\s(%F)", self.footer_data
|
||||
r";\snozzle_diameter\s=\s(%F)", self.config_data
|
||||
)
|
||||
|
||||
def parse_layer_count(self) -> Optional[int]:
|
||||
return regex_find_int(r"; total layers count = (%D)", self.footer_data)
|
||||
return regex_find_int(r"; total layers count = (%D)", self.config_data)
|
||||
|
||||
def parse_filament_change_count(self) -> Optional[int]:
|
||||
res = regex_find_int(r"; total toolchanges = (%D)", self.footer_data)
|
||||
res = regex_find_int(r"; total toolchanges = (%D)", self.config_data)
|
||||
if res is not None:
|
||||
return res
|
||||
return regex_find_int(r"; total filament change = (%D)", self.footer_data)
|
||||
return regex_find_int(r"; total filament change = (%D)", self.config_data)
|
||||
|
||||
class Slic3rPE(PrusaSlicer):
|
||||
def check_identity(self, data: str) -> bool:
|
||||
@@ -575,6 +594,58 @@ class Slic3r(Slic3rPE):
|
||||
def parse_estimated_time(self) -> Optional[float]:
|
||||
return None
|
||||
|
||||
class BambuStudio(PrusaSlicer):
|
||||
def check_identity(self, data: str) -> bool:
|
||||
match = re.search(r"; BambuStudio[^ ]* ([^\n]+)", data)
|
||||
if match is not None:
|
||||
self.slicer_name = "BambuStudio"
|
||||
self.slicer_version = match.group(1)
|
||||
return True
|
||||
return False
|
||||
|
||||
@property
|
||||
def config_data(self) -> str:
|
||||
return self.header_data
|
||||
|
||||
def parse_first_layer_height(self) -> Optional[float]:
|
||||
return regex_find_float(
|
||||
r"; initial_layer_print_height = (%F)", self.config_data
|
||||
)
|
||||
|
||||
def parse_object_height(self) -> float | None:
|
||||
return regex_find_float(r"; max_z_height: (%F)", self.config_data)
|
||||
|
||||
def parse_filament_total(self) -> float | None:
|
||||
return regex_find_float(
|
||||
r"; total filament length \[mm\] : (%F)", self.config_data
|
||||
)
|
||||
|
||||
def parse_filament_weight_total(self) -> float | None:
|
||||
return regex_find_float(
|
||||
r"; total filament weight \[g\] : (%F)", self.config_data
|
||||
)
|
||||
|
||||
def parse_filament_weights(self) -> Optional[List[float]]:
|
||||
return None
|
||||
|
||||
def parse_first_layer_extr_temp(self) -> Optional[float]:
|
||||
return regex_find_float(
|
||||
r"; nozzle_temperature_initial_layer = (%F)", self.config_data
|
||||
)
|
||||
|
||||
def parse_first_layer_bed_temp(self) -> Optional[float]:
|
||||
return regex_find_float(
|
||||
r"; hot_plate_temp_initial_layer = (%F)", self.config_data
|
||||
)
|
||||
|
||||
def parse_chamber_temp(self) -> Optional[float]:
|
||||
return regex_find_float(
|
||||
r"; chamber_temperatures = (%F)", self.config_data
|
||||
)
|
||||
|
||||
def parse_layer_count(self) -> Optional[int]:
|
||||
return regex_find_int(r"; total layer number: (%D)", self.config_data)
|
||||
|
||||
class Cura(BaseSlicer):
|
||||
def check_identity(self, data: str) -> bool:
|
||||
match = re.search(r"Cura_SteamEngine\s(.*)", data)
|
||||
@@ -1046,8 +1117,8 @@ class KiriMoto(BaseSlicer):
|
||||
|
||||
|
||||
SUPPORTED_SLICERS: List[Type[BaseSlicer]] = [
|
||||
PrusaSlicer, Slic3rPE, Slic3r, Cura, Simplify3D,
|
||||
KISSlicer, IdeaMaker, IceSL, KiriMoto
|
||||
Slic3rPE, Slic3r, PrusaSlicer, BambuStudio, Cura,
|
||||
Simplify3D, KISSlicer, IdeaMaker, IceSL, KiriMoto
|
||||
]
|
||||
SUPPORTED_DATA = [
|
||||
'gcode_start_byte',
|
||||
|
||||
Reference in new issue
Block a user