Source code for controllers.control_view_anypoint

"""
Module for managing Anypoint configuration.

This module contains the AnypointConfig class, which is responsible for handling the configuration
and user interface interactions related to the Anypoint mode.
"""


[docs] class AnypointConfig: """ Class for managing Anypoint configuration. Attributes: _controller: The controller object. _ui_object: The UI object. _model: The model object. Methods: __init__(self, controller): Initializes the AnypointConfig object. _connect_event(self): Connects UI signals to their respective slots. onclick_btn_anypoint(self): Handles the button click event for the Anypoint mode. change_mode_anypoint(self): Change the current Anypoint mode. change_properties_anypoint(self): Changes the properties of the Anypoint view mode. onclick_anypoint_navigator(self): Handles anypoint buttons click event. set_initial_value_to_ui_anypoint(self): Sets initial values to UI elements for Anypoint View. showing_config_mode_1(self): Reads the cached file to load the configuration data for Mode 1. showing_config_mode_2(self): Reads the cached file to load the configuration data for Mode 2. change_properties_mode_1(self): Updates the configuration data for Mode 1 and writes it to the cached file. change_properties_mode_2(self): Updates the configuration data for Mode 2 and writes it to the cached file. check_box_active_mode_anypoint(self): Checks and sets the active mode for Anypoint View. _get_alpha_beta_for_radio_mode(cls, button_name): Get alpha and beta angles for Anypoint View in radio mode. _get_pitch_yaw_for_non_radio_mode(cls, button_name): Get pitch and yaw angles for Anypoint View in non-radio mode. __block_signal(self): Blocks signals for alpha, beta, roll, and zoom double spin boxes. __unblock_signal(self): Unblock the signals of the alpha, beta, roll, and zoom double spin boxes in the GUI. """
[docs] def __init__(self, controller): super().__init__() self._controller = controller self._ui_object = controller.ui_object self._model = controller.model self._connect_event()
[docs] def _connect_event(self): """ Connect UI signals to their respective slots. Return: None. """ self._ui_object.btn_anypoint_view.clicked.connect(self.onclick_btn_anypoint) self._ui_object.btn_anypoint_view.setShortcut("Ctrl+A") self._ui_object.radio_mode_1.toggled.connect(self.change_mode_anypoint) self._ui_object.radio_mode_2.toggled.connect(self.change_mode_anypoint) self._ui_object.doubleSpinBox_alpha.valueChanged.connect(self.change_properties_anypoint) self._ui_object.doubleSpinBox_beta.valueChanged.connect(self.change_properties_anypoint) self._ui_object.doubleSpinBox_roll.valueChanged.connect(self.change_properties_anypoint) self._ui_object.doubleSpinBox_zoom.valueChanged.connect(self.change_properties_anypoint) self._ui_object.pushButton_any_up.clicked.connect(self.onclick_anypoint_navigator) self._ui_object.pushButton_any_up.setShortcut("Ctrl+Up") self._ui_object.pushButton_any_left.clicked.connect(self.onclick_anypoint_navigator) self._ui_object.pushButton_any_left.setShortcut("Ctrl+Left") self._ui_object.pushButton_any_center.clicked.connect(self.onclick_anypoint_navigator) self._ui_object.pushButton_any_bottom.clicked.connect(self.onclick_anypoint_navigator) self._ui_object.pushButton_any_bottom.setShortcut("Ctrl+Down") self._ui_object.pushButton_any_right.clicked.connect(self.onclick_anypoint_navigator) self._ui_object.pushButton_any_right.setShortcut("Ctrl+Right")
[docs] def onclick_btn_anypoint(self): """ Handle the button click event for the Anypoint mode. Change the application state to the Anypoint mode, shows the Anypoint widget, and sets the current index of the widget to 0. Return: None """ if self._model.image_original is not None: if self._model.source_usable: if self._model.set_moildev.moildev_main is not None: self._controller.ctrl_stylesheet.change_stylesheet_selected_menu() self._model.mode_view = "AnypointView" self.change_mode_anypoint() self._ui_object.widget_mode_view.show() self._ui_object.check_draw_poligon.setChecked(True) self._ui_object.frame_pointer_in_recenter_frame.show() self._ui_object.widget_mode_view.setCurrentIndex(0) else: self._model.mode_view = "FisheyeView" message = ("Source not usable to apply anypoint transformation, \n" "or cant access the parameter of the image on the database," "please select another source or or contact the developer if you are confused.") self._controller.ctrl_message_box.display_message_box(message, "information") else: self._controller.model.mode_view = "FisheyeView" message = ("Source not usable to apply Panorama transformation, \n" "or cant access the parameter of the image on the database," "please select another source or or contact the developer if you are confused.") self._controller.ctrl_message_box.display_message_box(message, "information") else: self._model.mode_view = "FisheyeView" message = "No media found, please select the file \nbefore you perform the operation!" self._controller.ctrl_message_box.display_message_box(message, "information")
[docs] def change_mode_anypoint(self): """ Change the current anypoint mode. Change the anypoint mode based on the selected radio button in the user interface. Shows or hides certain configuration options depending on the selected mode. Updates the anypoint maps and the anypoint mode in the model. Return: None """ self._model.view_zoom_area.state_rubberband = False if self._ui_object.radio_mode_1.isChecked(): self._ui_object.label_6.hide() self._ui_object.doubleSpinBox_roll.hide() self._ui_object.label.setText("Alpha:") self._ui_object.label_28.setText("Beta:") self._model.view_anypoint.anypoint_mode = "mode_1" self._model.view_anypoint.create_maps_anypoint_mode_1() self.showing_config_mode_1() else: self._ui_object.label_6.show() self._ui_object.doubleSpinBox_roll.show() self._ui_object.label.setText("Pitch:") self._ui_object.label_28.setText("Yaw:") self._model.view_anypoint.anypoint_mode = "mode_2" self._model.view_anypoint.create_maps_anypoint_mode_2() self.showing_config_mode_2() self.set_initial_value_to_ui_anypoint() self._controller.display_image_to_ui() self._model.save_main_config_update()
[docs] def change_properties_anypoint(self): """ Change the properties of the AnyPoint view mode. If an image result is available, this method changes the properties of the AnyPoint view mode according to the values set in the GUI. The changes are applied to the configuration object, and new maps are created. The configuration file is updated accordingly. Raise: None. Return: None. """ if self._ui_object.radio_mode_1.isChecked(): self.change_properties_mode_1() self._model.view_anypoint.create_maps_anypoint_mode_1() else: self.change_properties_mode_2() self._model.view_anypoint.create_maps_anypoint_mode_2() self._controller.display_image_to_ui()
[docs] def onclick_anypoint_navigator(self): """ Handle anypoint buttons click event. If radio_mode_1 is checked, set alpha and beta values based on the button clicked, then call showing_config_mode_1 and create_maps_anypoint_mode_1 methods. If radio_mode_1 is not checked, set alpha and beta values based on the button clicked, then call showing_config_mode_2 and create_maps_anypoint_mode_2 methods. Set state_rubberband attribute to False and update the file config. """ sender_name = self._controller.sender().objectName() if self._ui_object.radio_mode_1.isChecked(): mode = self._model.main_config["Mode_1"] if sender_name in ("pushButton_any_up", "pushButton_any_bottom", "pushButton_any_center", "pushButton_any_left", "pushButton_any_right"): mode["alpha"], mode["beta"] = self._get_alpha_beta_for_radio_mode(sender_name) self.showing_config_mode_1() self._model.view_anypoint.create_maps_anypoint_mode_1() else: mode = self._model.main_config["Mode_2"] if sender_name in ("pushButton_any_up", "pushButton_any_bottom", "pushButton_any_center", "pushButton_any_left", "pushButton_any_right"): mode["pitch"], mode["yaw"] = self._get_pitch_yaw_for_non_radio_mode(sender_name) self.showing_config_mode_2() self._model.view_anypoint.create_maps_anypoint_mode_2() mode["coord"] = self._model.view_anypoint.set_alpha_beta( mode["alpha"] if self._ui_object.radio_mode_1.isChecked() else mode["pitch"], mode["beta"] if self._ui_object.radio_mode_1.isChecked() else mode["yaw"]) self._model.view_zoom_area.state_rubberband = False self._model.save_main_config_update() self._controller.display_image_to_ui()
[docs] @classmethod def _get_alpha_beta_for_radio_mode(cls, button_name): """ Get alpha and beta angles for Anypoint View in radio mode. This method returns the alpha and beta angles based on the button name in radio mode of Anypoint View. Arg: button_name (str): The name of the button clicked in radio mode. Return: tuple: A tuple containing the alpha and beta angles. """ alpha, beta = 0, 0 if button_name == "pushButton_any_up": alpha = 75 elif button_name == "pushButton_any_bottom": alpha = 75 beta = 180 elif button_name == "pushButton_any_center": beta = 0 elif button_name == "pushButton_any_left": alpha = 75 beta = -90 elif button_name == "pushButton_any_right": alpha = 75 beta = 90 return alpha, beta
[docs] @classmethod def _get_pitch_yaw_for_non_radio_mode(cls, button_name): """ Get pitch and yaw angles for Anypoint View in non-radio mode. This method returns the pitch and yaw angles based on the button name in non-radio mode of Anypoint View. Arg: button_name (str): The name of the button clicked in non-radio mode. Return: tuple: A tuple containing the pitch and yaw angles. """ pitch, yaw = 0, 0 if button_name == "pushButton_any_up": pitch = 75 elif button_name == "pushButton_any_bottom": pitch = -75 elif button_name == "pushButton_any_center": pitch = 0 elif button_name == "pushButton_any_left": yaw = -75 elif button_name == "pushButton_any_right": yaw = 75 return pitch, yaw
def __block_signal(self): """ Blocks signals for alpha, beta, roll, and zoom double spin boxes. This function is used to temporarily block signals for the alpha, beta, roll, and zoom double spin boxes in the UI. This is useful when the user has changed one of the values programmatically, to prevent the signals from being emitted and triggering additional functions. """ self._ui_object.doubleSpinBox_alpha.blockSignals(True) self._ui_object.doubleSpinBox_beta.blockSignals(True) self._ui_object.doubleSpinBox_roll.blockSignals(True) self._ui_object.doubleSpinBox_zoom.blockSignals(True) def __unblock_signal(self): """ Unblock the signals of the alpha, beta, roll, and zoom double spin boxes in the GUI. """ self._ui_object.doubleSpinBox_alpha.blockSignals(False) self._ui_object.doubleSpinBox_beta.blockSignals(False) self._ui_object.doubleSpinBox_roll.blockSignals(False) self._ui_object.doubleSpinBox_zoom.blockSignals(False)
[docs] def set_initial_value_to_ui_anypoint(self): """ Set the initial values to UI elements for Anypoint View. This method sets initial values to spin boxes and double spin boxes for Anypoint View coordinates and angles. It first blocks signals of the UI elements to prevent emitting unnecessary signals while setting values. Then, it retrieves the initial values from the main configuration based on the active mode view. After setting the values, it unblocks signals of the UI elements. Returns: None """ self._ui_object.spinBox_icx.blockSignals(True) self._ui_object.spinBox_icy.blockSignals(True) self._ui_object.doubleSpinBox_alpha_rec.blockSignals(True) self._ui_object.doubleSpinBox_beta_rec.blockSignals(True) if self._ui_object.radio_mode_1.isChecked(): x = self._model.main_config["Mode_1"]["coord"][0] y = self._model.main_config["Mode_1"]["coord"][1] alpha = self._model.main_config["Mode_1"]["alpha"] beta = self._model.main_config["Mode_1"]["beta"] else: x = self._model.main_config["Mode_2"]["coord"][0] y = self._model.main_config["Mode_2"]["coord"][1] alpha = self._model.main_config["Mode_2"]["pitch"] beta = self._model.main_config["Mode_2"]["yaw"] self._ui_object.spinBox_icx.setValue(x) self._ui_object.spinBox_icy.setValue(y) self._ui_object.doubleSpinBox_alpha_rec.setValue(round(alpha, 2)) self._ui_object.doubleSpinBox_beta_rec.setValue(round(beta, 2)) self._ui_object.spinBox_icx.blockSignals(False) self._ui_object.spinBox_icy.blockSignals(False) self._ui_object.doubleSpinBox_alpha_rec.blockSignals(False) self._ui_object.doubleSpinBox_beta_rec.blockSignals(False)
[docs] def showing_config_mode_1(self): """ Read the cached file to load the configuration data for Mode 1. This function reads the YAML data from the cached file and loads it into the `self.__anypoint_config` attribute. It then sets the values of the zoom, alpha, and beta parameters for Mode 1 in the UI double spin boxes. The function blocks signals while updating the spin box values to prevent recursive updates. Once the values are set, the function unblocks signals. Return: None """ self.__block_signal() self._ui_object.doubleSpinBox_zoom.setValue(self._model.main_config["Mode_1"]["zoom"]) self._ui_object.doubleSpinBox_alpha.setValue(self._model.main_config["Mode_1"]["alpha"]) self._ui_object.doubleSpinBox_beta.setValue(self._model.main_config["Mode_1"]["beta"]) self.__unblock_signal()
[docs] def showing_config_mode_2(self): """ Read the cached file to load the configuration data for Mode 2. This function reads the YAML data from the cached file and loads it into the `self.__anypoint_config` attribute. It then sets the values of the pitch, yaw, roll, and zoom parameters for Mode 2 in the UI double spin boxes. The function blocks signals while updating the spin box values to prevent recursive updates. Once the values are set, the function unblocks signals. Return: None """ self.__block_signal() self._ui_object.doubleSpinBox_alpha.setValue(self._model.main_config["Mode_2"]["pitch"]) self._ui_object.doubleSpinBox_beta.setValue(self._model.main_config["Mode_2"]["yaw"]) self._ui_object.doubleSpinBox_roll.setValue(self._model.main_config["Mode_2"]["roll"]) self._ui_object.doubleSpinBox_zoom.setValue(self._model.main_config["Mode_2"]["zoom"]) self.__unblock_signal()
[docs] def change_properties_mode_1(self): """ Update the configuration data for Mode 1 and writes it to the cached file. This function updates the alpha, beta, and zoom parameters for Mode 1 using the values in the UI double spin boxes. It rounds the zoom value to three decimal places before updating the configuration data. The updated configuration data is then written to the cached file using YAML format. Return: None """ self._model.main_config["Mode_1"]["alpha"] = self._ui_object.doubleSpinBox_alpha.value() self._model.main_config["Mode_1"]["beta"] = self._ui_object.doubleSpinBox_beta.value() self._model.main_config["Mode_1"]["zoom"] = round(self._ui_object.doubleSpinBox_zoom.value(), 3) self._model.save_main_config_update()
[docs] def change_properties_mode_2(self): """ Update the configuration data for Mode 2 and writes it to the cached file. This function updates the pitch, yaw, roll, and zoom parameters for Mode 2 using the values in the UI double spin boxes. It creates a list of tuples to store the control names and their corresponding values, and then iterates through the list to update the configuration data for each control. The zoom value is rounded to three decimal places before updating the configuration data. The updated configuration data is then written to the cached file using YAML format. Return: None """ self._model.main_config["Mode_2"]["pitch"] = self._ui_object.doubleSpinBox_alpha.value() self._model.main_config["Mode_2"]["yaw"] = self._ui_object.doubleSpinBox_beta.value() self._model.main_config["Mode_2"]["roll"] = self._ui_object.doubleSpinBox_roll.value() self._model.main_config["Mode_2"]["zoom"] = round(self._ui_object.doubleSpinBox_zoom.value(), 3) self._model.save_main_config_update()
[docs] def check_box_active_mode_anypoint(self): """ Check and set the active mode for Anypoint View. If the current mode view is "AnypointView", this method blocks the signals of radio buttons to prevent emitting unnecessary signals while updating their states. It then sets the checked state of radio buttons based on the active view stored in the main configuration. Finally, it unblocks the signals of the radio buttons. Return: None """ if self._model.mode_view == "AnypointView": self._ui_object.radio_mode_1.blockSignals(True) self._ui_object.radio_mode_2.blockSignals(True) if self._model.main_config["Active_view"] == "mode_1": self._ui_object.radio_mode_1.setChecked(True) self._ui_object.radio_mode_2.setChecked(False) elif self._model.main_config["Active_view"] == "mode_2": self._ui_object.radio_mode_1.setChecked(False) self._ui_object.radio_mode_2.setChecked(True) self._ui_object.radio_mode_1.blockSignals(False) self._ui_object.radio_mode_2.blockSignals(False)