Extend generic class with gcode methods to convert the object to gcode
| 3 | |
| 4 | |
| 5 | class Point(BasePoint): |
| 6 | 'Extend generic class with gcode methods to convert the object to gcode' |
| 7 | |
| 8 | def XYZ_gcode(self, p) -> float: |
| 9 | ''' |
| 10 | Generate XYZ gcode string to move from a point p to this point. |
| 11 | |
| 12 | Args: |
| 13 | p (Point): The point to move from. |
| 14 | |
| 15 | Returns: |
| 16 | str: The XYZ gcode string. |
| 17 | |
| 18 | ''' |
| 19 | s = '' |
| 20 | if self.x != None and self.x != p.x: |
| 21 | s += f'X{self.x:.6f}'.rstrip('0').rstrip('.') + ' ' |
| 22 | if self.y != None and self.y != p.y: |
| 23 | s += f'Y{self.y:.6f}'.rstrip('0').rstrip('.') + ' ' |
| 24 | if self.z != None and self.z != p.z: |
| 25 | s += f'Z{self.z:.6f}'.rstrip('0').rstrip('.') + ' ' |
| 26 | return s if s != '' else None |
| 27 | |
| 28 | def gcode(self, state): |
| 29 | ''' |
| 30 | Process this instance in a list of steps supplied by the designer to generate and return a line of gcode. |
| 31 | |
| 32 | Args: |
| 33 | state (State): The state object containing printer and extruder information. |
| 34 | |
| 35 | Returns: |
| 36 | str: The generated line of gcode. |
| 37 | |
| 38 | ''' |
| 39 | XYZ_str = self.XYZ_gcode(state.point) |
| 40 | if XYZ_str != None: # only write a line of gcode if movement occurs |
| 41 | G_str = 'G1 ' if state.extruder.on or state.extruder.travel_format == "G1_E0" else 'G0 ' |
| 42 | F_str = state.printer.f_gcode(state) |
| 43 | E_str = state.extruder.e_gcode(self, state) |
| 44 | gcode_str = f'{G_str}{F_str}{XYZ_str}{E_str}' |
| 45 | state.printer.speed_changed = False |
| 46 | state.point.update_from(self) |
| 47 | return gcode_str.strip() # strip the final space |
no outgoing calls
no test coverage detected