extract_metadata: parse slicer version during identifcation

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2020-09-09 08:27:41 -04:00
parent ec86c7bfda
commit 57fe71c800
1 changed files with 83 additions and 33 deletions

View File

@ -50,9 +50,7 @@ def _regex_find_first(pattern, data, cast=float):
# Slicer parsing implementations
class BaseSlicer(object):
def __init__(self, name, id_pattern):
self.name = name
self.id_pattern = id_pattern
def __init__(self):
self.header_data = self.footer_data = self.log = None
def set_data(self, header_data, footer_data, log):
@ -60,12 +58,6 @@ class BaseSlicer(object):
self.footer_data = footer_data
self.log = log
def get_name(self):
return self.name
def get_id_pattern(self):
return self.id_pattern
def _parse_min_float(self, pattern, data, strict=False):
result = _regex_find_floats(pattern, data, strict)
if result:
@ -80,6 +72,9 @@ class BaseSlicer(object):
else:
return None
def check_identity(self, data):
return None
def parse_first_layer_height(self):
return None
@ -105,8 +100,8 @@ class BaseSlicer(object):
return None
class UnknownSlicer(BaseSlicer):
def __init__(self, name="Unknown", id_pattern=r""):
super(UnknownSlicer, self).__init__(name, id_pattern)
def check_identity(self, data):
return {'slicer': "Unknown"}
def parse_first_layer_height(self):
return self._parse_min_float(r"G1\sZ\d+\.\d*", self.header_data)
@ -123,8 +118,14 @@ class UnknownSlicer(BaseSlicer):
r"M190 S(\d+\.?\d*)", self.header_data)
class PrusaSlicer(BaseSlicer):
def __init__(self, name="PrusaSlicer", id_pattern=r"PrusaSlicer\s.*\son"):
super().__init__(name, id_pattern)
def check_identity(self, data):
match = re.search(r"PrusaSlicer\s(.*)\son", data)
if match:
return {
'slicer': "PrusaSlicer",
'slicer_version': match.group(1)
}
return None
def parse_first_layer_height(self):
return _regex_find_first(
@ -193,9 +194,14 @@ class PrusaSlicer(BaseSlicer):
r"; first_layer_bed_temperature = (\d+\.?\d*)", self.footer_data)
class Slic3rPE(PrusaSlicer):
def __init__(self, name="Slic3r PE",
id_pattern=r"Slic3r\sPrusa\sEdition\s.*\son"):
super().__init__(name, id_pattern)
def check_identity(self, data):
match = re.search(r"Slic3r\sPrusa\sEdition\s(.*)\son", data)
if match:
return {
'slicer': "Slic3r PE",
'slicer_version': match.group(1)
}
return None
def parse_filament_total(self):
return _regex_find_first(
@ -205,25 +211,44 @@ class Slic3rPE(PrusaSlicer):
return None
class Slic3r(Slic3rPE):
def __init__(self, name="Slic3r", id_pattern=r"Slic3r\s\d.*\son"):
super().__init__(name, id_pattern)
def check_identity(self, data):
match = re.search(r"Slic3r\s(\d.*)\son", data)
if match:
return {
'slicer': "Slic3r",
'slicer_version': match.group(1)
}
return None
def parse_estimated_time(self):
return None
class SuperSlicer(PrusaSlicer):
def __init__(self, name="SuperSlicer", id_pattern=r"SuperSlicer\s.*\son"):
super().__init__(name, id_pattern)
def check_identity(self, data):
match = re.search(r"SuperSlicer\s(.*)\son", data)
if match:
return {
'slicer': "SuperSlicer",
'slicer_version': match.group(1)
}
return None
class Cura(BaseSlicer):
def __init__(self, name="Cura", id_pattern=r"Cura_SteamEngine.*"):
super().__init__(name, id_pattern)
def check_identity(self, data):
match = re.search(r"Cura_SteamEngine\s(.*)", data)
if match:
return {
'slicer': "Cura",
'slicer_version': match.group(1)
}
return None
def parse_first_layer_height(self):
return _regex_find_first(r";MINZ:(\d+\.?\d*)", self.header_data)
def parse_layer_height(self):
return _regex_find_first(r";Layer\sheight:\s(\d+\.?\d*)", self.header_data)
return _regex_find_first(
r";Layer\sheight:\s(\d+\.?\d*)", self.header_data)
def parse_object_height(self):
return _regex_find_first(r";MAXZ:(\d+\.?\d*)", self.header_data)
@ -248,8 +273,14 @@ class Cura(BaseSlicer):
class Simplify3D(BaseSlicer):
def __init__(self, name="Simplify3D", id_pattern=r"Simplify3D\(R\)"):
super().__init__(name, id_pattern)
def check_identity(self, data):
match = re.search(r"Simplify3D\(R\)\sVersion\s(.*)", data)
if match:
return {
'slicer': "Simplify3D",
'slicer_version': match.group(1)
}
return None
def parse_first_layer_height(self):
return self._parse_min_float(r"G1\sZ\d+\.\d*", self.header_data)
@ -307,8 +338,16 @@ class Simplify3D(BaseSlicer):
return self._get_first_layer_temp("Heated Bed")
class KISSlicer(BaseSlicer):
def __init__(self, name="KISSlicer", id_pattern=r";\sKISSlicer"):
super().__init__(name, id_pattern)
def check_identity(self, data):
match = re.search(r";\sKISSlicer", data)
if match:
ident = {'slicer': "KISSlicer"}
vmatch = re.search(r";\sversion\s(.*)", data)
if vmatch:
version = vmatch.group(1).replace(" ", "-")
ident['slicer_version'] = version
return ident
return None
def parse_first_layer_height(self):
return _regex_find_first(
@ -348,8 +387,14 @@ class KISSlicer(BaseSlicer):
class IdeaMaker(BaseSlicer):
def __init__(self, name="IdeaMaker", id_pattern=r"\sideaMaker\s.*,",):
super().__init__(name, id_pattern)
def check_identity(self, data):
match = re.search(r"\sideaMaker\s(.*),", data)
if match:
return {
'slicer': "IdeaMaker",
'slicer_version': match.group(1)
}
return None
def parse_first_layer_height(self):
layer_info = _regex_find_floats(
@ -392,8 +437,11 @@ class IdeaMaker(BaseSlicer):
r"M190 S(\d+\.?\d*)", self.header_data)
class IceSL(BaseSlicer):
def __init__(self, name="IceSL", id_pattern=r"; <IceSL.*>",):
super().__init__(name, id_pattern)
def check_identity(self, data):
match = re.search(r"; <IceSL.*>", data)
if match:
return {'slicer': "IceSL"}
return None
def parse_first_layer_height(self):
return _regex_find_first(
@ -439,12 +487,14 @@ def extract_metadata(file_path, log):
# identify the slicer
header_data = f.read(READ_SIZE)
for s in slicers:
if re.search(s.get_id_pattern(), header_data) is not None:
ident = s.check_identity(header_data)
if ident is not None:
slicer = s
metadata.update(ident)
break
if slicer is None:
slicer = UnknownSlicer()
metadata['slicer'] = slicer.get_name()
metadata['slicer'] = "Unknown"
if size > READ_SIZE * 2:
f.seek(size - READ_SIZE)
footer_data = f.read()