diff --git a/PythonicGcodeMachine/Gcode/Rs274/Ast.py b/PythonicGcodeMachine/Gcode/Rs274/Ast.py index 7d492984652110c6ba7325f04e3ba43614b7f608..c6670d83a56a036406501fb169943d13c907f605 100644 --- a/PythonicGcodeMachine/Gcode/Rs274/Ast.py +++ b/PythonicGcodeMachine/Gcode/Rs274/Ast.py @@ -381,11 +381,26 @@ class Line(MachineMixin): if isinstance(item, Word): yield item + def iter_on_gm_word(self): + for item in self: + if isinstance(item, Word) and item.is_gm_gcode: + yield item + + def iter_on_x_word(self): + for item in self: + if isinstance(item, Word) and not item.is_gm_gcode: + yield item + def iter_on_setting(self): for item in self: if isinstance(item, ParameterSetting): yield item + def iter_in_order(self): + words = [word for word in self.iter_on_gm_word()] + words.sort(key=lambda word: word.execution_order.index) + return words + ############################################## def toggle(self): diff --git a/examples/gcode/annotate-gcode.py b/examples/gcode/annotate-gcode.py index 8e933df1bbb614d49d357b82f9cf3c003b9fce1b..0fbf7504963406188d4dd5f97394c1e6bb0b4c63 100644 --- a/examples/gcode/annotate-gcode.py +++ b/examples/gcode/annotate-gcode.py @@ -63,6 +63,9 @@ program = machine.parser.parse_lines(lines) #r# We dump the annotated program +def str_list(a_list): + return ' '.join([str(item) for item in a_list]) + meaning_format = ' {:5}: {}' for line in program: print() @@ -77,4 +80,10 @@ for line in program: print(margin + 'Valid G-code: {}'.format(word.is_valid_gcode)) else: print(meaning_format.format(word.letter, word.meaning)) + print( + ' execution:', + str_list(line.iter_in_order()), '/', + str_list(line.iter_on_x_word()), '/', + str_list(line.iter_on_setting()), + ) #o#