Generate the gcode for extrusion. Args: point1 (Point): The point at the end of the extrusion. state: The current state of the printer. Returns: str: The gcode component for extrusion.
(self, point1: Point, state)
| 89 | return ret_val |
| 90 | |
| 91 | def e_gcode(self, point1: Point, state) -> str: |
| 92 | '''Generate the gcode for extrusion. |
| 93 | |
| 94 | Args: |
| 95 | point1 (Point): The point at the end of the extrusion. |
| 96 | state: The current state of the printer. |
| 97 | |
| 98 | Returns: |
| 99 | str: The gcode component for extrusion. |
| 100 | ''' |
| 101 | def distance_forgiving(point1: Point, point2: Point) -> float: |
| 102 | '''Calculate the distance between two points. x, y or z components are ignored unless defined in both points |
| 103 | |
| 104 | Args: |
| 105 | point1 (Point): The first point. |
| 106 | point2 (Point): The second point. |
| 107 | |
| 108 | Returns: |
| 109 | float: The distance between the two points. |
| 110 | ''' |
| 111 | dist_x = 0 if point1.x == None or point2.x == None else point1.x - point2.x |
| 112 | dist_y = 0 if point1.y == None or point2.y == None else point1.y - point2.y |
| 113 | dist_z = 0 if point1.z == None or point2.z == None else point1.z - point2.z |
| 114 | return ((dist_x)**2+(dist_y)**2+(dist_z)**2)**0.5 |
| 115 | if self.on: |
| 116 | # length = pt1.distance_to_self(pt2) |
| 117 | length = distance_forgiving(point1, state.point) |
| 118 | return f'E{self.get_and_update_volume(length*state.extrusion_geometry.area)*self.volume_to_e:.6f}'.rstrip('0').rstrip('.') |
| 119 | else: |
| 120 | if state.extruder.travel_format == 'G1_E0': |
| 121 | # return 'E0' for relative extrusion or E(previous extrusion) for absolute extrusion |
| 122 | return f'E{self.get_and_update_volume(0)*self.volume_to_e:.6f}'.rstrip('0').rstrip('.') |
| 123 | else: |
| 124 | # return nothing if travel format does not require am E value |
| 125 | return '' |
| 126 | |
| 127 | def update_e_ratio(self): |
| 128 | '''Calculate the ratio for conversion from mm3 extrusion to units for E in gcode.''' |
no test coverage detected