#include "radial_vibration.h" #include "ui_radial_vibration.h" #include #include #include #include #include #include "data_config.h" #include "vibrationdata.h" #include "config_mgr.h" Radial_vibration::Radial_vibration(int slot_no_, int channel_, bool active, QWidget *parent) : QWidget(parent) , ui(new Ui::Radial_vibration) { ui->setupUi(this); slot_no = slot_no_; channel = channel_; QString chan = QString("%1").arg(channel); QString slot = QString("%1").arg(slot_no); ui->label_channel->setText(chan); ui->label_slot->setText(slot); if (active) { ui->label_active->setText("(启用)"); } else { ui->label_active->setText("(停用)"); } // QString filePath_filter = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\filter_%2.json").arg(slot_no).arg(channel); // readJsonFile(filePath_filter); // QString filePath_variables = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\radial_vibration_variables_%2.json").arg(slot_no).arg(channel); // readJsonFile(filePath_variables); Init(); } Radial_vibration::~Radial_vibration() { delete ui; } void Radial_vibration::on_pushButton_cancel_clicked() { this->close(); } void Radial_vibration::on_checkBox_1x_ampl_toggled(bool checked) { if (checked) { ui->comboBox_1x_value_range->setEnabled(true); ui->doubleSpinBox_1x_ampl_clamp->setEnabled(true); ui->doubleSpinBox_1x_phase_lag_clamp->setEnabled(true); return; } ui->comboBox_1x_value_range->setEnabled(false); ui->doubleSpinBox_1x_ampl_clamp->setEnabled(false); ui->doubleSpinBox_1x_phase_lag_clamp->setEnabled(false); } void Radial_vibration::on_checkBox_2x_ampl_toggled(bool checked) { if (checked) { ui->comboBox_2x_value_range->setEnabled(true); ui->doubleSpinBox_2x_ampl_clamp->setEnabled(true); ui->doubleSpinBox_2x_phase_lag_clamp->setEnabled(true); return; } ui->comboBox_2x_value_range->setEnabled(false); ui->doubleSpinBox_2x_ampl_clamp->setEnabled(false); ui->doubleSpinBox_2x_phase_lag_clamp->setEnabled(false); } void Radial_vibration::on_checkBox_not_1x_ampl_toggled(bool checked) { if (checked) { ui->comboBox_not_1x_ampl->setEnabled(true); ui->doubleSpinBox_not_1x_ampl_clamp->setEnabled(true); return; } ui->comboBox_not_1x_ampl->setEnabled(false); ui->doubleSpinBox_not_1x_ampl_clamp->setEnabled(false); } void Radial_vibration::on_checkBox_smax_ampl_toggled(bool checked) { if (checked) { ui->comboBox_smax_range->setEnabled(true); ui->doubleSpinBox_smax_clamp->setEnabled(true); return; } ui->comboBox_smax_range->setEnabled(false); ui->doubleSpinBox_smax_clamp->setEnabled(false); } //void Radial_vibration::readJsonFile(const QString &filePath) { // // 创建文件对象 // QFile file(filePath); // if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { // qDebug() << "Cannot open file for reading:" << filePath; // return; // } // QString content = file.readAll(); // file.close(); // QByteArray jsonData = content.toUtf8(); // QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData); // if (jsonDoc.isNull()) { // qDebug() << "Cannot parse JSON document"; // return; // } // if (!jsonDoc.isObject() && !jsonDoc.isArray()) { // qDebug() << "JSON document is not an object or an array"; // return; // } // QJsonObject json_obj = jsonDoc.object(); // if (filePath.contains("filter_")) { // QJsonArray filter_array = json_obj["filter"].toArray(); // for (int i = 0; i < filter_array.size(); i++) { // QJsonObject temp_obj = filter_array[i].toObject(); // filter[i].type = temp_obj["type"].toString(); // filter[i].low = temp_obj["low"].toInt(); // filter[i].high = temp_obj["high"].toInt(); // filter[i].checked = temp_obj["checked"].toBool(); // } // } else if (filePath.contains("radial_vibration_variables_")) { // QJsonArray variables_array = json_obj["variables"].toArray(); // for (int i = 0; i < variables_array.size(); i++) { // QJsonObject temp_obj = variables_array[i].toObject(); // variables[i].type = temp_obj["type"].toString(); // if (variables[i].type == "direct") { // variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt(); // variables[i].clamp_value = temp_obj["clamp_value"].toDouble(); // } else if (variables[i].type == "bias_volt") { // variables[i].clamp_value = temp_obj["clamp_value"].toDouble(); // variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt(); // } else if (variables[i].type == "1x_ampl" || variables[i].type == "2x_ampl") { // variables[i].checked = temp_obj["checked"].toBool(); // variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt(); // variables[i].clamp_value = temp_obj["clamp_value"].toDouble(); // variables[i].phase_lag = temp_obj["phase_lag"].toDouble(); // } else if (variables[i].type == "not_1x_ampl") { // variables[i].clamp_value = temp_obj["clamp_value"].toDouble(); // variables[i].checked = temp_obj["checked"].toBool(); // variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt(); // } else if (variables[i].type == "smax_ampl") { // variables[i].clamp_value = temp_obj["clamp_value"].toDouble(); // variables[i].checked = temp_obj["checked"].toBool(); // variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt(); // } // } // QJsonObject delay_obj = json_obj["delay"].toObject(); // delay.alert = delay_obj["alert"].toInt(); // delay.danger = delay_obj["danger"].toDouble(); // delay.active_100ms = delay_obj["active_100ms"].toBool(); // alert_variables.alert_latching = json_obj["alert_latching"].toBool(); // alert_variables.danger_latching = json_obj["danger_latching"].toBool(); // alert_variables.timed_ok = json_obj["timed_ok"].toBool(); // alert_variables.recorder_output = json_obj["recorder_output"].toInt(); // alert_variables.two_ma_clamp = json_obj["two_ma_clamp"].toBool(); // alert_variables.trip_multiply = json_obj["trip_multiply"].toDouble(); // alert_variables.comparision = json_obj["comparision"].toString(); // alert_variables.comparision_percentage = json_obj["comparision_percentage"].toInt(); // } //} void Radial_vibration::Init() { std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); if (base_ptr == nullptr) { qCritical() << "[Velocity::Init] should not be here"; return; } std::shared_ptr ptr = std::dynamic_pointer_cast(base_ptr); if (ptr->base_config_[channel - 1].channel_type != kVibRadial) { qDebug() << " channel type changes"; return; } std::shared_ptr variable_base = ptr->GetChannelPtr(channel); if (variable_base == nullptr) { qDebug() << "no channel ptr"; return; } std::shared_ptr variable_ptr = std::dynamic_pointer_cast(variable_base); ui->checkBox_low_pass->setChecked(variable_ptr->filter_[0].checked); ui->spinBox_low_pass_low->setValue(variable_ptr->filter_[0].low); ui->spinBox_low_pass_high->setValue(variable_ptr->filter_[0].high); ui->checkBox_high_pass->setChecked(variable_ptr->filter_[1].checked); ui->spinBox_high_pass_low->setValue(variable_ptr->filter_[1].low); ui->spinBox_high_pass_high->setValue(variable_ptr->filter_[1].high); ui->checkBox_band_pass->setChecked(variable_ptr->filter_[2].checked); ui->spinBox_band_pass_low->setValue(variable_ptr->filter_[2].low); ui->spinBox_band_pass_high->setValue(variable_ptr->filter_[2].high); ui->comboBox_direct_value_range->setCurrentIndex(variable_ptr->direct_.full_scale_range); ui->doubleSpinBox_direct_clamp->setValue(variable_ptr->direct_.clamp_value); // ui->label_bias_voltage->setText(QString::number(variable_ptr->direct_.bias_voltage)); // ui->doubleSpinBox_bias_volt_clamp->setValue(variables[i].clamp_value); // ui->comboBox_bias_volt_range->setCurrentIndex(); ui->checkBox_1x_ampl->setChecked(variable_ptr->x1_.checked); ui->comboBox_1x_value_range->setCurrentIndex(variable_ptr->x1_.full_scale_range); ui->doubleSpinBox_1x_ampl_clamp->setValue(variable_ptr->x1_.clamp_value); ui->doubleSpinBox_1x_phase_lag_clamp->setValue(variable_ptr->x1_.phase_lag); ui->checkBox_2x_ampl->setChecked(variable_ptr->x2_.checked); ui->comboBox_2x_value_range->setCurrentIndex(variable_ptr->x2_.full_scale_range); ui->doubleSpinBox_2x_ampl_clamp->setValue(variable_ptr->x2_.clamp_value); ui->doubleSpinBox_2x_phase_lag_clamp->setValue(variable_ptr->x2_.phase_lag); ui->checkBox_not_1x_ampl->setChecked(variable_ptr->not1x_.checked); ui->comboBox_not_1x_ampl->setCurrentIndex(variable_ptr->not1x_.full_scale_range); ui->doubleSpinBox_not_1x_ampl_clamp->setValue(variable_ptr->not1x_.clamp_value); // ui->doubleSpinBox_2x_phase_lag_clamp->setValue(variable_ptr->not1x_.custom); ui->checkBox_smax_ampl->setChecked(variable_ptr->smax_.checked); ui->comboBox_smax_range->setCurrentIndex(variable_ptr->smax_.full_scale_range); ui->doubleSpinBox_smax_clamp->setValue(variable_ptr->smax_.clamp_value); // ui->doubleSpinBox_2x_phase_lag_clamp->setValue(variable_ptr->smax_.custom); ui->spinBox_alert->setValue(variable_ptr->delay_.alert); ui->doubleSpinBox_danger->setValue(variable_ptr->delay_.danger); ui->checkBox_100ms->setChecked(variable_ptr->delay_.active_100ms); ui->checkBox_alert_latching->setChecked(variable_ptr->alert_latching_); ui->checkBox_danger_latching->setChecked(variable_ptr->danger_latching_); ui->comboBox_recorder_output->setCurrentIndex(variable_ptr->recorder_out_.recorder_output); ui->checkBox_two_ma_clamp->setChecked(variable_ptr->recorder_out_.two_ma_clamp); ui->doubleSpinBox_trip_multiply->setValue(variable_ptr->recorder_out_.trip_multiply); ui->comboBox_comparision->setCurrentIndex(variable_ptr->recorder_out_.comparision); ui->spinBox_comparision_percentage->setValue(variable_ptr->recorder_out_.percentage); } void Radial_vibration::on_pushButton_confirm_clicked() { std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); if (base_ptr == nullptr) { qCritical() << "[Acceleration::Init] should not be here"; return; } std::shared_ptr ptr = std::dynamic_pointer_cast(base_ptr); std::shared_ptr variable_base = ptr->GetChannelPtr(channel); if (variable_base == nullptr || variable_base->type_ != kVibRadial) { if (variable_base == nullptr) { qDebug() << "no channel ptr"; } else { ptr->RemoveChannel(channel); qDebug() << "channel type change"; } std::shared_ptr variable = std::make_shared(); variable->id_ = channel; variable->type_ = kVibRadial; variable->filter_[0].checked = ui->checkBox_low_pass->isChecked(); variable->filter_[0].low = ui->spinBox_low_pass_low->value(); variable->filter_[0].high = ui->spinBox_low_pass_high->value(); variable->filter_[1].checked = ui->checkBox_high_pass->isChecked(); variable->filter_[1].low = ui->spinBox_high_pass_low->value(); variable->filter_[1].high = ui->spinBox_high_pass_high->value(); variable->filter_[2].checked = ui->checkBox_band_pass->isChecked(); variable->filter_[2].low = ui->spinBox_band_pass_low->value(); variable->filter_[2].high = ui->spinBox_band_pass_high->value(); variable->direct_.full_scale_range = ui->comboBox_direct_value_range->currentIndex(); variable->direct_.clamp_value = ui->doubleSpinBox_direct_clamp->value(); variable->direct_.custom = 0; // TODO: variable->x1_.checked = ui->checkBox_1x_ampl->isChecked(); variable->x1_.full_scale_range = ui->comboBox_1x_value_range->currentIndex(); variable->x1_.clamp_value = ui->doubleSpinBox_1x_ampl_clamp->value(); variable->x1_.custom = 0; // TODO: variable->x1_.phase_lag = ui->doubleSpinBox_1x_phase_lag_clamp->value(); variable->x2_.checked = ui->checkBox_2x_ampl->isChecked(); variable->x2_.full_scale_range = ui->comboBox_2x_value_range->currentIndex(); variable->x2_.clamp_value = ui->doubleSpinBox_2x_ampl_clamp->value(); variable->x2_.custom = 0; // TODO: variable->x2_.phase_lag = ui->doubleSpinBox_2x_phase_lag_clamp->value(); variable->recorder_out_.recorder_output = ui->comboBox_recorder_output->currentIndex(); variable->recorder_out_.two_ma_clamp = ui->checkBox_two_ma_clamp->isChecked(); variable->recorder_out_.trip_multiply = ui->doubleSpinBox_trip_multiply->value(); variable->recorder_out_.comparision = ui->comboBox_comparision->currentIndex(); variable->recorder_out_.percentage = ui->spinBox_comparision_percentage->value(); variable->not1x_.checked = ui->checkBox_not_1x_ampl->isChecked(); variable->not1x_.full_scale_range = ui->comboBox_not_1x_ampl->currentIndex(); variable->not1x_.clamp_value = ui->doubleSpinBox_1x_ampl_clamp->value(); variable->not1x_.custom = 0; // TODO: variable->smax_.checked = ui->checkBox_smax_ampl->isChecked(); variable->smax_.full_scale_range = ui->comboBox_smax_range->currentIndex(); variable->smax_.clamp_value = ui->doubleSpinBox_smax_clamp->value(); variable->smax_.custom = 0; // TODO: variable->delay_.alert = ui->spinBox_alert->value(); variable->delay_.danger = ui->doubleSpinBox_danger->value(); variable->delay_.active_100ms = ui->checkBox_100ms->isChecked(); variable->alert_latching_ = ui->checkBox_alert_latching->isChecked(); variable->danger_latching_ = ui->checkBox_danger_latching->isChecked(); ptr->variables_.push_back(variable); return; } std::shared_ptr variable = std::dynamic_pointer_cast(variable_base); variable->filter_[0].checked = ui->checkBox_low_pass->isChecked(); variable->filter_[0].low = ui->spinBox_low_pass_low->value(); variable->filter_[0].high = ui->spinBox_low_pass_high->value(); variable->filter_[1].checked = ui->checkBox_high_pass->isChecked(); variable->filter_[1].low = ui->spinBox_high_pass_low->value(); variable->filter_[1].high = ui->spinBox_high_pass_high->value(); variable->filter_[2].checked = ui->checkBox_band_pass->isChecked(); variable->filter_[2].low = ui->spinBox_band_pass_low->value(); variable->filter_[2].high = ui->spinBox_band_pass_high->value(); variable->direct_.full_scale_range = ui->comboBox_direct_value_range->currentIndex(); variable->direct_.clamp_value = ui->doubleSpinBox_direct_clamp->value(); variable->direct_.custom = 0; // TODO: variable->x1_.checked = ui->checkBox_1x_ampl->isChecked(); variable->x1_.full_scale_range = ui->comboBox_1x_value_range->currentIndex(); variable->x1_.clamp_value = ui->doubleSpinBox_1x_ampl_clamp->value(); variable->x1_.custom = 0; // TODO: variable->x1_.phase_lag = ui->doubleSpinBox_1x_phase_lag_clamp->value(); variable->x2_.checked = ui->checkBox_2x_ampl->isChecked(); variable->x2_.full_scale_range = ui->comboBox_2x_value_range->currentIndex(); variable->x2_.clamp_value = ui->doubleSpinBox_2x_ampl_clamp->value(); variable->x2_.custom = 0; // TODO: variable->x2_.phase_lag = ui->doubleSpinBox_2x_phase_lag_clamp->value(); variable->recorder_out_.recorder_output = ui->comboBox_recorder_output->currentIndex(); variable->recorder_out_.two_ma_clamp = ui->checkBox_two_ma_clamp->isChecked(); variable->recorder_out_.trip_multiply = ui->doubleSpinBox_trip_multiply->value(); variable->recorder_out_.comparision = ui->comboBox_comparision->currentIndex(); variable->recorder_out_.percentage = ui->spinBox_comparision_percentage->value(); variable->not1x_.checked = ui->checkBox_not_1x_ampl->isChecked(); variable->not1x_.full_scale_range = ui->comboBox_not_1x_ampl->currentIndex(); variable->not1x_.clamp_value = ui->doubleSpinBox_1x_ampl_clamp->value(); variable->not1x_.custom = 0; // TODO: variable->smax_.checked = ui->checkBox_smax_ampl->isChecked(); variable->smax_.full_scale_range = ui->comboBox_smax_range->currentIndex(); variable->smax_.clamp_value = ui->doubleSpinBox_smax_clamp->value(); variable->smax_.custom = 0; // TODO: variable->delay_.alert = ui->spinBox_alert->value(); variable->delay_.danger = ui->doubleSpinBox_danger->value(); variable->delay_.active_100ms = ui->checkBox_100ms->isChecked(); variable->alert_latching_ = ui->checkBox_alert_latching->isChecked(); variable->danger_latching_ = ui->checkBox_danger_latching->isChecked(); this->close(); } void Radial_vibration::on_pushButton_set_default_clicked() { }