예제 #1
0
    def __init__(self, a_normalize_value, a_error_limit, a_signal_type, a_init_points: List[MeasuredPoint],
                 a_parent=None):
        super().__init__(a_parent)

        self.__row_count = 0
        self.__column_count = MeasureModel.Column.COUNT
        self.__raw_columns = (MeasureModel.Column.SCALE_POINT, MeasureModel.Column.FREQUENCY,
                              MeasureModel.Column.DOWN_DEVIATION_PERCENT, MeasureModel.Column.UP_DEVIATION_PERCENT)

        self.__points = []

        self.AVERAGE_SUM_IDX = 0
        self.AVERAGE_COUNT_IDX = 1
        self.__average_data = [[[0, 1]] * MeasureModel.Column.COUNT]

        self.signal_type = a_signal_type
        self.value_to_user = utils.value_to_user_with_units(clb.signal_type_to_units[self.signal_type])
        self.normalize_value = a_normalize_value
        self.error_limit = a_error_limit
        self.__good_color = QColor(0, 255, 0, 127)
        self.__bad_color = QColor(255, 0, 0, 127)

        assert a_init_points is not None, "a_init_points must not be None!"

        if a_init_points:
            # Формат a_init_points - кортеж, который формируется в self.exportPoints
            for s_p, a, f, up_v, down_v in a_init_points:
                self.appendPoint(PointData(a_scale_point=s_p, a_point=a, a_frequency=f, a_value=up_v,
                                           a_approach_side=PointData.ApproachSide.UP), a_average=False)

                self.appendPoint(PointData(a_scale_point=s_p, a_point=a, a_frequency=f, a_value=down_v,
                                           a_approach_side=PointData.ApproachSide.DOWN), a_average=False)
예제 #2
0
    def __init__(self,
                 a_settings: Settings,
                 a_calibrator: clb_dll.ClbDrv,
                 a_network_variables: NetworkVariables,
                 a_parent=None):
        super().__init__(a_parent)

        self.ui = SourceModeForm()
        self.ui.setupUi(self)

        self.pause_icon = QtGui.QIcon(QtGui.QPixmap(":/icons/icons/play.png"))
        self.play_icon = QtGui.QIcon(QtGui.QPixmap(":/icons/icons/pause.png"))
        self.ui.enable_button.setIconSize(QtCore.QSize(25, 25))

        self.settings = a_settings

        self.calibrator = a_calibrator
        self.clb_state = clb.State.DISCONNECTED
        self.signal_type = clb.SignalType.ACI
        self.mode = clb.Mode.SOURCE

        self.netvars = a_network_variables

        self.units = clb.signal_type_to_units[self.signal_type]
        self.value_to_user = utils.value_to_user_with_units(self.units)

        self.connect_signals()

        self.update_signal_enable_state(self.calibrator.signal_enable)

        self.signal_type_to_radio = {
            clb.SignalType.ACI: self.ui.aci_radio,
            clb.SignalType.ACV: self.ui.acv_radio,
            clb.SignalType.DCI: self.ui.dci_radio,
            clb.SignalType.DCV: self.ui.dcv_radio,
        }
        self.mode_to_radio = {
            clb.Mode.SOURCE: self.ui.source_mode_radio,
            clb.Mode.FIXED_RANGE: self.ui.fixed_mode_radio,
            clb.Mode.DETUNING: self.ui.detuning_radio,
        }

        self.clb_check_timer = QTimer()
        self.clb_check_timer.timeout.connect(self.sync_clb_parameters)
        self.clb_check_timer.start(10)

        self.update_netvars_timer = QTimer()
        self.update_netvars_timer.timeout.connect(self.update_netvars)
        self.update_netvars_timer.start(self.settings.tstlan_update_time *
                                        1000)

        self.next_error_timer = QTimer()
        self.next_error_timer.timeout.connect(self.show_next_error)
        self.next_error_index = 0

        self.ui.errors_out_button.clicked.connect(self.start_errors_output)
예제 #3
0
    def update_signal_type(self, a_signal_type: clb.SignalType):
        if not self.calibrator.signal_enable:
            self.calibrator.signal_type = a_signal_type
            self.signal_type = a_signal_type

            self.units = clb.signal_type_to_units[self.signal_type]
            self.value_to_user = utils.value_to_user_with_units(self.units)

            self.set_amplitude(self.calibrator.amplitude)
            self.set_frequency(self.calibrator.frequency)
예제 #4
0
    def __init__(self, a_case: Measure.Case):
        self.value_to_user = utils.value_to_user_with_units(
            clb.signal_type_to_units[a_case.signal_type])

        self.limit = self.value_to_user(a_case.limit)
        self.signal_type = clb.enum_to_signal_type[a_case.signal_type]
        self.error_limit = self.value_to_user(
            utils.absolute_error_limit(a_normalize_value=a_case.limit,
                                       a_error_percent=a_case.device_class))
        self.points = defaultdict(list)
예제 #5
0
    def update_case_params(self):
        self.units_text = clb.signal_type_to_units[
            self.current_case.signal_type]
        self.value_to_user = utils.value_to_user_with_units(self.units_text)
        self.current_point = PointData()

        self.highest_amplitude = clb.bound_amplitude(
            utils.increase_by_percent(self.current_case.limit,
                                      cfg.FIRST_POINT_START_DEVIATION_PERCENT),
            self.current_case.signal_type)
        self.lowest_amplitude = -self.highest_amplitude if clb.is_dc_signal[
            self.current_case.signal_type] else 0
예제 #6
0
    def signal_type_changed(self, a_idx):
        try:
            sender_table_row = self.ui.limits_table.currentRow()
            row_limit_item = self.ui.limits_table.item(
                sender_table_row, ScaleLimitsDialog.Column.LIMIT)

            value_f = utils.parse_input(row_limit_item.text())
            signal_type = clb.SignalType(a_idx)
            units = clb.signal_type_to_units[signal_type]

            value_str = utils.value_to_user_with_units(units)(value_f)
            row_limit_item.setText(value_str)
        except Exception as err:
            utils.exception_handler(err)
예제 #7
0
    def __init__(self,
                 parent=None,
                 units: str = "В",
                 a_init_items=(),
                 a_min_value=None,
                 a_max_value=None,
                 a_optional_widget=None):
        self.value_to_user = utils.value_to_user_with_units(units)
        items_with_units = (self.value_to_user(item) for item in a_init_items)
        super().__init__(parent, items_with_units, a_min_value, a_max_value,
                         a_optional_widget)

        delegator = QRegExpDelegator(self,
                                     utils.check_input_no_python_re.pattern)
        delegator.editing_finished.connect(self.item_editing_finished)
        self.ui.list_widget.setItemDelegate(delegator)
예제 #8
0
    def __init__(self, a_fast_params=None, a_parent=None):
        super().__init__(a_parent)

        self.ui = NewFastMeasureForm()
        self.ui.setupUi(self)
        self.ui.invisible_default_button.hide()

        self.fast_params = a_fast_params if a_fast_params is not None else FastMeasureParams(
        )
        self.value_to_user = utils.value_to_user_with_units("А")

        self.connect_signals()
        self.restore_config()

        self.normalize_edit_value(self.ui.upper_bound_edit)
        self.normalize_edit_value(self.ui.lower_bound_edit)
        self.normalize_edit_value(self.ui.step_edit)

        self.edit_frequency_widget = None
예제 #9
0
    def set_value_to_user(self, a_item: QtWidgets.QTableWidgetItem):
        self.ui.limits_table.blockSignals(True)
        try:
            if a_item.column() == ScaleLimitsDialog.Column.LIMIT:
                value_f = utils.parse_input(a_item.text())
                signal_type = clb.SignalType(
                    self.ui.limits_table.cellWidget(
                        a_item.row(),
                        ScaleLimitsDialog.Column.SIGNAL_TYPE).currentIndex())
                units = clb.signal_type_to_units[signal_type]
                value_f = clb.bound_amplitude(value_f, signal_type)
                value_str = utils.value_to_user_with_units(units)(value_f)

                a_item.setText(value_str)
                a_item.setData(QtCore.Qt.UserRole, value_str)

        except ValueError:
            a_item.setText(a_item.data(QtCore.Qt.UserRole))
        self.ui.limits_table.blockSignals(False)
예제 #10
0
 def set_units(self, a_units_str: str):
     self.value_to_user = utils.value_to_user_with_units(a_units_str)
     self.normalize_edit_value(self.ui.upper_bound_edit)
     self.normalize_edit_value(self.ui.lower_bound_edit)
     self.normalize_edit_value(self.ui.step_edit)
     self.normalize_edit_value(self.ui.minimal_discrete)
예제 #11
0
 def create_tab_name(a_case: Measure.Case):
     return " " + clb.enum_to_signal_type_short[a_case.signal_type] + "; " + \
            utils.value_to_user_with_units(clb.signal_type_to_units[a_case.signal_type])(a_case.limit)
예제 #12
0
    def __init__(self,
                 a_calibrator: clb_dll.ClbDrv,
                 a_measure_config: Measure,
                 a_db_connection: Connection,
                 a_settings: Settings,
                 a_parent=None):
        super().__init__(a_parent)

        self.ui = MeasureForm()
        self.ui.setupUi(self)
        self.setWindowTitle("Калибратор N4-25. Измерение")

        self.parent = a_parent

        self.warning_animation = None
        self.pause_icon = QtGui.QIcon(QtGui.QPixmap(":/icons/icons/pause.png"))
        self.play_icon = QtGui.QIcon(QtGui.QPixmap(":/icons/icons/play.png"))
        self.ui.pause_button.setIconSize(QtCore.QSize(21, 21))

        self.set_up_icons()

        self.settings = a_settings

        self.parent.show()
        geometry = self.settings.get_last_geometry(self.__class__.__name__)
        if not geometry.isEmpty():
            self.parent.restoreGeometry(geometry)
        else:
            self.parent.resize(self.size())

        # Вызывать после self.parent.show() !!! Иначе состояние столбцов не восстановится
        self.ui.measure_table.horizontalHeader().restoreState(
            self.settings.get_last_header_state(self.__class__.__name__))

        self.db_connection = a_db_connection

        self.calibrator = a_calibrator
        self.calibrator.signal_enable = False
        self.clb_state = clb.State.DISCONNECTED

        self.measure_config = a_measure_config
        self.measures_db = MeasuresDB(self.db_connection)
        # Нужно создать заранее, чтобы было id для сохранения меток
        self.measure_config.id = self.measures_db.new_measure(
            self.measure_config)

        self.measure_manager = MeasureCases(self.ui.measure_table,
                                            self.measure_config.cases,
                                            a_allow_editing=True)
        self.ui.cases_bar_layout.addWidget(self.measure_manager.cases_bar)

        # --------------------Создение переменных
        self.started = False

        self.soft_approach_points = []
        self.soft_approach_timer = QTimer(self)
        soft_approach_time_ms = 4000
        # Минимум стабильной передачи - 200 мс
        self.NEXT_SOFT_POINT_TIME_MS = 200
        self.SOFT_APPROACH_POINTS_COUNT = int(soft_approach_time_ms //
                                              self.NEXT_SOFT_POINT_TIME_MS)
        # Нужен, чтобы убедиться, что фиксированный диапазон выставлен, после чего включить сигнал
        self.start_measure_timer = QTimer(self)
        # Нужен, чтобы убедиться, что сигнал выключен, после чего менять параметры сигнала
        self.stop_measure_timer = QTimer(self)
        self.wait_dialog = None

        self.units_text = "В"
        self.value_to_user = utils.value_to_user_with_units(self.units_text)
        self.current_point = PointData()
        self.highest_amplitude = 0
        self.lowest_amplitude = 0

        self.fixed_step = 0
        self.fixed_step_list = self.settings.fixed_step_list
        # --------------------Создение переменных

        # Вызывать после создания self.measure_manager
        self.connect_signals()

        self.current_case = self.measure_manager.current_case()
        self.current_case_changed()

        self.clb_check_timer = QTimer(self)
        self.clb_check_timer.timeout.connect(self.sync_clb_parameters)
        self.clb_check_timer.start(10)