Transform a fullcontrol design (a list of function class instances) into various output formats. Optionally, Controls can be passed to control how the output is generated.
(steps: list, result_type: str, controls: Union[ModelControls, GcodeControls, CodeControls] = None, show_tips: bool = True)
| 7 | |
| 8 | |
| 9 | def transform(steps: list, result_type: str, controls: Union[ModelControls, GcodeControls, CodeControls] = None, show_tips: bool = True): |
| 10 | ''' Transform a fullcontrol design (a list of function class instances) into various output formats. |
| 11 | Optionally, Controls can be passed to control how the output is generated. |
| 12 | ''' |
| 13 | |
| 14 | if result_type == 'control_code': |
| 15 | from lab.fullcontrol.controlcode_formats.steps2controlcode import controlcode |
| 16 | if controls is not None: |
| 17 | controlcode(steps, controls, show_tips) |
| 18 | else: |
| 19 | controlcode(steps, CodeControls(), show_tips) |
| 20 | elif result_type == '3d_model': |
| 21 | from lab.fullcontrol.geometry_model.steps2geometry import geometry_model |
| 22 | if controls is not None: |
| 23 | geometry_model(steps, controls) |
| 24 | else: |
| 25 | print("warning: no controls were supplied to fclab.transform(). it's advisable to supply fclab.ModelControls. the simulated extrusion width and height may be incorrect") |
| 26 | geometry_model(steps, ModelControls()) |
| 27 | elif result_type == 'laser_cutter_gcode': |
| 28 | import re |
| 29 | |
| 30 | def remove_terms_from_gcode(gcode, term_characters): |
| 31 | pattern = r'[' + ''.join(term_characters) + r']\d*\.?\d+ ?' |
| 32 | return re.sub(pattern, '', gcode) |
| 33 | |
| 34 | if controls is None: controls = GcodeControls() |
| 35 | |
| 36 | # don't allow the gcode function to save gcode since we will modify it after generation |
| 37 | if controls.save_as == True: |
| 38 | raise Exception("please set GcodeControl.save_as = False for 'laser_cutter_gcode'") |
| 39 | # force initialization data as first object in design |
| 40 | if not isinstance(steps[0], Laser): |
| 41 | raise Exception("first object in design must be an fclab.Laser() object") |
| 42 | else: |
| 43 | for attribute in ['cutting_speed', 'travel_speed', 'spotsize', 'on']: |
| 44 | if getattr(steps[0], attribute) is None: |
| 45 | raise Exception(f"first object in design (fclab.Laser) must have all attributes set - attribute '{attribute}' is missing") |
| 46 | if steps[0].constant_power == None and steps[0].dynamic_power == None: |
| 47 | raise Exception("first object in design (fclab.Laser) must have either 'constant_power' or 'dynamic_power' set") |
| 48 | gcode = transform_original(steps, 'gcode', controls, show_tips) |
| 49 | gcode = remove_terms_from_gcode(gcode, ['Z', 'E']) |
| 50 | # remove relative extrusion gcode command |
| 51 | gcode = gcode.replace("M83 ; relative extrusion\n", "") |
| 52 | return gcode |
| 53 | else: |
| 54 | raise ValueError(f"result_type '{result_type}' not recognized. Please use 'control_code', '3d_model', 'laser_cutter_gcode', or fc.transform()") |
| 55 | |
| 56 | |
| 57 |
nothing calls this directly
no test coverage detected