diff --git a/PythonicGcodeMachine/Gcode/Rs274/Ast.py b/PythonicGcodeMachine/Gcode/Rs274/Ast.py index 963964cb351a378e138fc0b50de5d7bf5f9bcdeb..7d492984652110c6ba7325f04e3ba43614b7f608 100644 --- a/PythonicGcodeMachine/Gcode/Rs274/Ast.py +++ b/PythonicGcodeMachine/Gcode/Rs274/Ast.py @@ -563,7 +563,12 @@ class Word(LineItem): def ansi_str(self): - if self._letter in 'GM': + if self._machine: + gm = self._machine.GM_LETTERS + else: + gm = 'GM' + + if self._letter in gm: return Line.ANSI_G(str(self)) else: return Line.ANSI_X(self._letter) + Line.ANSI_VALUE(str(self._value)) @@ -577,15 +582,24 @@ class Word(LineItem): ############################################## @property - def is_valid_gcode(self): + def is_gm_gcode(self): self._check_machine() - return str(self) in self._machine.config.gcodes + return self._machine.is_gm_word(self) + + ############################################## + + @property + def is_valid_gcode(self): + if self.is_gm_gcode: + return str(self) in self._machine.config.gcodes + else: + return True ############################################## @property def meaning(self): - if self.is_valid_gcode: + if self.is_gm_gcode: return self._machine.config.gcodes[str(self)].meaning else: return self._machine.config.letters[self.letter].meaning @@ -594,7 +608,7 @@ class Word(LineItem): @property def modal_group(self): - if self.is_valid_gcode: + if self.is_gm_gcode: return self._machine.config.modal_groups[str(self)] else: return None @@ -603,7 +617,7 @@ class Word(LineItem): @property def execution_order(self): - if self.is_valid_gcode: + if self.is_gm_gcode: return self._machine.config.execution_order[str(self)] else: return None diff --git a/PythonicGcodeMachine/Gcode/Rs274/Machine.py b/PythonicGcodeMachine/Gcode/Rs274/Machine.py index 96e6939c3941baebabe489148b4330fad28b7213..1864685cb6050496468cb011df905d26b7bbde0b 100644 --- a/PythonicGcodeMachine/Gcode/Rs274/Machine.py +++ b/PythonicGcodeMachine/Gcode/Rs274/Machine.py @@ -40,6 +40,8 @@ class GcodeMachine: PARSER_CLS = GcodeParser + GM_LETTERS = 'GM' + ############################################## def __init__(self): @@ -85,3 +87,11 @@ class GcodeMachine: pass ############################################## + + def is_gm_letter(self, letter): + return letter in self.GM_LETTERS + + ############################################## + + def is_gm_word(self, word): + return self.is_gm_letter(word.letter) diff --git a/examples/gcode/annotate-gcode.py b/examples/gcode/annotate-gcode.py index ab393e736e05850460584ba31e81b04d2b6aac8f..8e933df1bbb614d49d357b82f9cf3c003b9fce1b 100644 --- a/examples/gcode/annotate-gcode.py +++ b/examples/gcode/annotate-gcode.py @@ -69,11 +69,12 @@ for line in program: # print(line.ansi_str()) # Fixme: pyterate print(str(line)) for word in line.iter_on_word(): - if word.is_valid_gcode: + if word.is_gm_gcode: margin = ' '*9 print(meaning_format.format(str(word), word.meaning)) print(margin + 'Modal group: {}'.format(word.modal_group.meaning)) print(margin + 'Execution order: {}'.format(word.execution_order.index)) + print(margin + 'Valid G-code: {}'.format(word.is_valid_gcode)) else: print(meaning_format.format(word.letter, word.meaning)) #o#