Browse Source

CURA-4552 Change names as indicated in the review and making Marlin the
default flavor. Also fix the case in which the read flavor was not in
the dict.

Diego Prado Gesto 7 years ago
parent
commit
8054bc3d7d

+ 2 - 3
plugins/GCodeReader/GCodeFlavor.py → 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)

+ 11 - 6
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):

+ 0 - 9
plugins/GCodeReader/GriffinFlavor.py

@@ -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__()

+ 10 - 0
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__()

+ 3 - 2
plugins/GCodeReader/RepRapFlavor.py → 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__()