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.
This commit is contained in:
Diego Prado Gesto 2017-11-28 11:47:34 +01:00
parent cab2e14728
commit 8054bc3d7d
5 changed files with 26 additions and 20 deletions

View file

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

View file

@ -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):

View file

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

View file

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

View file

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