from PyQt5.QtGui import QMovie import logging from ui.test_test import Test_Test from components import PipeCutterComponent logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) class Test_Pipe_Cutter(Test_Test): """ A class to manage and operate a pipe cutter machine in a test environment. """ def __init__(self, config, components, recipe=None, run_once=False, reset_on_start=False, enable_override=False, bench_name="generic", step=None,): super().__init__(components=components, recipe=recipe, step=None, run_once=run_once, reset_on_start=reset_on_start, enable_override=enable_override,) self.bench_name = bench_name self.cutter = PipeCutterComponent() self.current_cut_length = 0.0 self.max_cut_length = config.get("max_cut_length", 10.0) self.movie = QMovie(config.get("config/instruction_images/st-ten-10/pipe.gif ")) # Animation Path self.current_status = None def start(self, recipe=None, step=None, pieces=None): if step is not None : self.start_cutting() self.display_cutting_animation(True) self.stop_cutting() def start_cutting(self,recipe=None,step=None): """ Start the pipe cutting process and activate the pipe cutter component. """ self.current_status = self.cutter.read_machine_status() if self.current_status == 102 : # ready for operation try: self.reset_machine() self.cutter.write_total_length(self.recipe.spec.get("length", None)) self.cutter.write_od_of_pipe(self.recipe.spec.get("diameter", None)) self.cutter.write_bit_with_delay(600,0,100) except Exception as e: logger.error(f"Failed to start the pipe cutting process: {e}") else: try: self.cutter.write_bit_with_delay(600, 1, 100) # resetting except Exception as e: logger.error(f"Failed to reset the pipe cutting process: {e}") def stop_cutting(self): """ Stop the pipe cutting process and deactivate the pipe cutter component. """ try: self.current_status = self.cutter.read_machine_status() if self.current_status in(106,107): self.cutter.write_bit_with_delay(600, 2, 100) self.reset_machine() except Exception as e: logger.error(f"Failed to stop the pipe cutting process: {e}") def reset_machine(self): """ Reset the pipe cutter machine to its initial state. """ try: self.cutter.write_bit_with_delay(600, 1, 100) except Exception as e: logger.error(f"Failed to reset the pipe cutter machine: {e}") def display_cutting_animation(self, show: bool): """ Show or hide the cutting animation GIF. Args: show (bool): Whether to display or stop the animation. """ if show: self.pipe_gif.setVisible(True) self.movie.start() logger.info("Cutting animation started.") else: self.movie.stop() self.pipe_gif.setVisible(False) logger.info("Cutting animation stopped.")