Example #1
0
    def setData(self, index: QModelIndex, value: str, role=Qt.EditRole):
        if not index.isValid() or role != Qt.EditRole or self.rowCount() <= index.row():
            return False
        try:
            float_value = utils.parse_input(value)

            if index.column() in (self.Column.AMPLITUDE, self.Column.DOWN_VALUE, self.Column.UP_VALUE):
                float_value = clb.bound_amplitude(float_value, self.signal_type)
            elif index.column() == self.Column.FREQUENCY:
                float_value = clb.bound_frequency(float_value, self.signal_type)

            self.__points[index.row()][index.column()] = float_value
            self.dataChanged.emit(index, index)

            if index.column() in (self.Column.AMPLITUDE, self.Column.DOWN_VALUE, self.Column.UP_VALUE):
                if index.column() != self.Column.DOWN_VALUE:
                    self.__recalculate_parameters(index.row(), PointData.ApproachSide.UP)

                if index.column() != self.Column.UP_VALUE:
                    self.__recalculate_parameters(index.row(), PointData.ApproachSide.DOWN)

                if index.column() == self.Column.AMPLITUDE:
                    # Это нужно, чтобы цвета ячеек Нижнее значение и Верхнее значение обновлялись сразу после изменения
                    # ячейки Поверяемая точка
                    up_value_index = self.index(index.row(), self.Column.UP_VALUE)
                    down_value_index = self.index(index.row(), self.Column.DOWN_VALUE)

                    self.dataChanged.emit(up_value_index, up_value_index)
                    self.dataChanged.emit(down_value_index, down_value_index)

            return True
        except ValueError:
            return False
Example #2
0
 def limit_amplitude(self, a_amplitude, a_lower, a_upper):
     """
     Обрезает значение амплитуды с учетом типа сигнала и параметров пользователя
     :param a_amplitude: Заданная амплитуда
     :param a_lower: Нижняя граница
     :param a_upper: Верхняя граница
     """
     return utils.bound(clb.bound_amplitude(a_amplitude, self.__signal_type), a_lower, a_upper)
Example #3
0
 def normalize_edit_value(self, edit: QtWidgets.QLineEdit):
     try:
         value = utils.parse_input(edit.text())
         value = clb.bound_amplitude(value, self.fast_params.signal_type)
         edit.setText(self.value_to_user(value))
         self.update_edit_color(edit)
     except ValueError:
         pass
Example #4
0
    def amplitude_changed(self):
        actual_amplitude = clb.bound_amplitude(self.__clb_dll.get_amplitude(), self.__signal_type)
        signed_amplitude = actual_amplitude if self.__clb_dll.get_polarity() == clb.Polatiry.POS else -actual_amplitude

        if self.__amplitude != signed_amplitude:
            self.__amplitude = signed_amplitude
            return True
        else:
            return False
Example #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
Example #6
0
    def from_template(cls, a_params: TemplateParams,
                      a_var_params: VariableTemplateParams):
        measure_cases = []
        for scale in a_params.scales:
            for limit in scale.limits:
                if limit.frequency:
                    frequency_list = (float(f)
                                      for f in limit.frequency.split(';'))
                else:
                    frequency_list = [
                        0
                    ] if clb.is_dc_signal[limit.signal_type] else [50]

                if scale.points:
                    scale_coef = limit.limit / max(scale.points)
                    minimal_discrete = round(
                        utils.get_array_min_diff(sorted(scale.points)) *
                        scale_coef, 9)

                    points = [
                        MeasuredPoint(scale_point=p,
                                      amplitude=clb.bound_amplitude(
                                          p * scale_coef, limit.signal_type),
                                      frequency=clb.bound_frequency(
                                          float(f), limit.signal_type),
                                      up_value=0,
                                      down_value=0) for f in frequency_list
                        for p in scale.points
                    ]
                else:
                    scale_coef = 1
                    minimal_discrete = 1
                    points = []

                measure_cases.append(
                    Measure.Case(a_id=0,
                                 a_limit=limit.limit,
                                 a_class=limit.device_class,
                                 a_signal_type=limit.signal_type,
                                 a_minimal_discrete=minimal_discrete,
                                 a_scale_coef=scale_coef,
                                 a_points=points))

        return cls(measure_cases,
                   a_device_name=a_params.device_name,
                   a_device_creator=a_params.device_creator,
                   a_device_system=a_params.device_system,
                   a_user=a_var_params.user_name,
                   a_date=a_var_params.date,
                   a_serial_num=a_var_params.serial_num,
                   a_owner=a_var_params.owner)
Example #7
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)
Example #8
0
    def appendPoint(self, a_point_data: PointData, a_average: bool) -> int:
        """
        Добавляет точку в таблицу
        :param a_point_data: Данные точки
        :param a_average: Если равно True, то существующее значение не перезаписывается, а усредняется
        """
        a_point_data.amplitude = clb.bound_amplitude(a_point_data.amplitude, self.signal_type)
        a_point_data.frequency = clb.bound_frequency(a_point_data.frequency, self.signal_type)
        a_point_data.round_data()

        value_column = self.__side_to_value_column[a_point_data.approach_side]
        value = a_point_data.value

        row_idx = self.__find_point(a_point_data.amplitude, a_point_data.frequency)
        point_row = self.rowCount() if row_idx is None else row_idx

        if point_row == self.rowCount():
            assert not a_average, "appendPoint must be called only for existing points"
            # Добавляемой точки еще нет в списке
            point_data = [a_point_data.scale_point, a_point_data.amplitude, a_point_data.frequency, 0, 0, 0, 0, 0, 0, 0]
            assert len(point_data) == MeasureModel.Column.COUNT, "Размер point_data не соответствует количеству " \
                                                                 "колонок таблицы"
            self.__average_data += [[[a_point_data.amplitude, 1]] * MeasureModel.Column.COUNT]

            new_row = self.rowCount()
            self.beginInsertRows(QModelIndex(), new_row, new_row)
            self.__points.append(point_data)
            self.endInsertRows()
        elif a_average:
            self.__average_data[point_row][value_column][self.AVERAGE_SUM_IDX] += value
            self.__average_data[point_row][value_column][self.AVERAGE_COUNT_IDX] += 1

            value = self.__average_data[point_row][value_column][self.AVERAGE_SUM_IDX] / \
                self.__average_data[point_row][value_column][self.AVERAGE_COUNT_IDX]

        if not a_average:
            self.__average_data[point_row][self.__side_to_value_column[a_point_data.approach_side]] = [value, 1]

        self.setData(self.index(point_row, value_column), str(value))
        self.__recalculate_parameters(point_row, a_point_data.approach_side)
        return point_row
Example #9
0
 def set_amplitude(self, a_amplitude: float):
     self.calibrator.amplitude = clb.bound_amplitude(
         a_amplitude, self.signal_type)
     self.ui.amplitude_edit.setText(
         self.value_to_user(self.calibrator.amplitude))
     self.amplitude_edit_text_changed()
Example #10
0
 def amplitude(self, a_amplitude: float):
     self.__amplitude = clb.bound_amplitude(a_amplitude, self.__signal_type)
     self.__clb_dll.set_amplitude(abs(self.__amplitude))
     self.__set_polarity_by_amplitude_sign(self.__amplitude)