diff --git a/plugins/GCodeReader/GCodeFlavor.py b/plugins/GCodeReader/FlavorParser.py similarity index 99% rename from plugins/GCodeReader/GCodeFlavor.py rename to plugins/GCodeReader/FlavorParser.py index 1d1ca4de8b..cd317027ee 100644 --- a/plugins/GCodeReader/GCodeFlavor.py +++ b/plugins/GCodeReader/FlavorParser.py @@ -25,9 +25,8 @@ import math import re from collections import namedtuple - -# Class for loading and parsing G-code files -class GCodeFlavor: +# This parser is intented for interpret the common firmware codes among all the different flavors +class FlavorParser: def __init__(self): Application.getInstance().hideMessageSignal.connect(self._onHideMessage) diff --git a/plugins/GCodeReader/GCodeReader.py b/plugins/GCodeReader/GCodeReader.py index 938be59151..cb2f5d99e0 100755 --- a/plugins/GCodeReader/GCodeReader.py +++ b/plugins/GCodeReader/GCodeReader.py @@ -7,14 +7,15 @@ from UM.i18n import i18nCatalog from UM.Preferences import Preferences catalog = i18nCatalog("cura") -from . import GriffinFlavor, RepRapFlavor +from . import MarlinFlavorParser, RepRapFlavorParser # Class for loading and parsing G-code files class GCodeReader(MeshReader): + _flavor_default = "Marlin" _flavor_keyword = ";FLAVOR:" - _flavor_readers_dict = {"Griffin" : GriffinFlavor.GriffinFlavor(), - "RepRap" : RepRapFlavor.RepRapFlavor()} + _flavor_readers_dict = {"RepRap" : RepRapFlavorParser.RepRapFlavorParser(), + "Marlin" : MarlinFlavorParser.MarlinFlavorParser()} def __init__(self): super(GCodeReader, self).__init__() @@ -28,11 +29,15 @@ class GCodeReader(MeshReader): with open(file_name, "r") as file: for line in file: if line[:len(self._flavor_keyword)] == self._flavor_keyword: - self._flavor_reader = self._flavor_readers_dict[line[len(self._flavor_keyword):].rstrip()] - return FileReader.PreReadResult.accepted + try: + self._flavor_reader = self._flavor_readers_dict[line[len(self._flavor_keyword):].rstrip()] + return FileReader.PreReadResult.accepted + except: + # If there is no entry in the dictionary for this flavor, just skip and select the by-default flavor + break # If no flavor is found in the GCode, then we use the by-default - self._flavor_reader = self._flavor_readers_dict["Griffin"] + self._flavor_reader = self._flavor_readers_dict[self._flavor_default] return FileReader.PreReadResult.accepted def read(self, file_name): diff --git a/plugins/GCodeReader/GriffinFlavor.py b/plugins/GCodeReader/GriffinFlavor.py deleted file mode 100644 index ba9853d5ce..0000000000 --- a/plugins/GCodeReader/GriffinFlavor.py +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2017 Ultimaker B.V. -# Cura is released under the terms of the LGPLv3 or higher. - -from . import GCodeFlavor - -class GriffinFlavor(GCodeFlavor.GCodeFlavor): - - def __init__(self): - super().__init__() \ No newline at end of file diff --git a/plugins/GCodeReader/MarlinFlavorParser.py b/plugins/GCodeReader/MarlinFlavorParser.py new file mode 100644 index 0000000000..482285a2c9 --- /dev/null +++ b/plugins/GCodeReader/MarlinFlavorParser.py @@ -0,0 +1,10 @@ +# Copyright (c) 2017 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. + +from . import FlavorParser + +# This parser is intented for interpret the Marlin/Sprinter Firmware flavor +class MarlinFlavorParser(FlavorParser.FlavorParser): + + def __init__(self): + super().__init__() \ No newline at end of file diff --git a/plugins/GCodeReader/RepRapFlavor.py b/plugins/GCodeReader/RepRapFlavorParser.py similarity index 84% rename from plugins/GCodeReader/RepRapFlavor.py rename to plugins/GCodeReader/RepRapFlavorParser.py index f96a2d7857..42853913d6 100644 --- a/plugins/GCodeReader/RepRapFlavor.py +++ b/plugins/GCodeReader/RepRapFlavorParser.py @@ -1,9 +1,10 @@ # Copyright (c) 2017 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. -from . import GCodeFlavor +from . import FlavorParser -class RepRapFlavor(GCodeFlavor.GCodeFlavor): +# This parser is intented for interpret the RepRap Firmware flavor +class RepRapFlavorParser(FlavorParser.FlavorParser): def __init__(self): super().__init__()