TSI_Config/radial_vibration.cpp

344 lines
17 KiB
C++
Raw Normal View History

2025-03-20 15:06:41 +08:00
#include "radial_vibration.h"
#include "ui_radial_vibration.h"
#include <QFile>
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
2025-03-28 10:17:18 +08:00
Radial_vibration::Radial_vibration(int slot_no_, int channel_, bool active, QWidget *parent)
2025-03-20 15:06:41 +08:00
: QWidget(parent)
2025-03-28 10:17:18 +08:00
, ui(new Ui::Radial_vibration) {
2025-03-20 15:06:41 +08:00
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);
2025-03-28 10:17:18 +08:00
if (active) {
2025-03-20 15:06:41 +08:00
ui->label_active->setText("(启用)");
2025-03-28 10:17:18 +08:00
} else {
2025-03-20 15:06:41 +08:00
ui->label_active->setText("(停用)");
2025-03-28 10:17:18 +08:00
}
2025-03-20 15:06:41 +08:00
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);
2025-03-23 14:03:48 +08:00
Init();
2025-03-28 10:17:18 +08:00
connect(ui->checkBox_1x_ampl, &QCheckBox::toggled, this, &Radial_vibration::on_1x_ampl_toggled);
connect(ui->checkBox_2x_ampl, &QCheckBox::toggled, this, &Radial_vibration::on_2x_ampl_toggled);
connect(ui->checkBox_not_1x_ampl, &QCheckBox::toggled, this, &Radial_vibration::on_not1x_ampl_toggled);
connect(ui->checkBox_smax_ampl, &QCheckBox::toggled, this, &Radial_vibration::on_smax_ampl_toggled);
2025-03-20 15:06:41 +08:00
}
2025-03-28 10:17:18 +08:00
Radial_vibration::~Radial_vibration() {
2025-03-20 15:06:41 +08:00
delete ui;
}
2025-03-28 10:17:18 +08:00
void Radial_vibration::on_pushButton_cancel_clicked() {
this->close();
}
void Radial_vibration::on_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_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_not1x_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_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) {
2025-03-20 15:06:41 +08:00
// 创建文件对象
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();
2025-03-28 10:17:18 +08:00
if (filePath.contains("filter_")) {
2025-03-20 15:06:41 +08:00
QJsonArray filter_array = json_obj["filter"].toArray();
2025-03-28 10:17:18 +08:00
for (int i = 0; i < filter_array.size(); i++) {
2025-03-20 15:06:41 +08:00
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();
}
2025-03-28 10:17:18 +08:00
} else if (filePath.contains("radial_vibration_variables_")) {
2025-03-20 15:06:41 +08:00
QJsonArray variables_array = json_obj["variables"].toArray();
2025-03-28 10:17:18 +08:00
for (int i = 0; i < variables_array.size(); i++) {
2025-03-20 15:06:41 +08:00
QJsonObject temp_obj = variables_array[i].toObject();
variables[i].type = temp_obj["type"].toString();
2025-03-28 10:17:18 +08:00
if (variables[i].type == "direct") {
2025-03-20 15:06:41 +08:00
variables[i].full_sacle_range = temp_obj["full_sacle_range"].toString();
variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
2025-03-28 10:17:18 +08:00
} else if (variables[i].type == "bias_volt") {
2025-03-20 15:06:41 +08:00
variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
variables[i].full_sacle_range = temp_obj["full_sacle_range"].toString();
2025-03-28 10:17:18 +08:00
} else if (variables[i].type == "1x_ampl" || variables[i].type == "2x_ampl") {
2025-03-20 15:06:41 +08:00
variables[i].checked = temp_obj["checked"].toBool();
variables[i].full_sacle_range = temp_obj["full_sacle_range"].toString();
variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
variables[i].phase_lag = temp_obj["phase_lag"].toDouble();
2025-03-28 10:17:18 +08:00
} else if (variables[i].type == "not_1x_ampl") {
2025-03-20 15:06:41 +08:00
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"].toString();
2025-03-28 10:17:18 +08:00
} else if (variables[i].type == "smax_ampl") {
2025-03-20 15:06:41 +08:00
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"].toString();
}
}
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"].toString();
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();
}
}
2025-03-28 10:17:18 +08:00
void Radial_vibration::Init() {
2025-03-20 15:06:41 +08:00
for (int i = 0; i < 3; i++) {
2025-03-28 10:17:18 +08:00
if (filter[i].type == "band_pass") {
2025-03-23 14:03:48 +08:00
ui->checkBox_band_pass->setChecked(filter[i].checked);
ui->spinBox_band_pass_low->setValue(filter[i].low);
ui->spinBox_band_pass_high->setValue(filter[i].high);
2025-03-28 10:17:18 +08:00
} else if (filter[i].type == "low_pass") {
2025-03-23 14:03:48 +08:00
ui->checkBox_low_pass->setChecked(filter[i].checked);
ui->spinBox_low_pass_low->setValue(filter[i].low);
ui->spinBox_low_pass_high->setValue(filter[i].high);
2025-03-28 10:17:18 +08:00
} else if (filter[i].type == "high_pass") {
2025-03-23 14:03:48 +08:00
ui->checkBox_high_pass->setChecked(filter[i].checked);
ui->spinBox_high_pass_low->setValue(filter[i].low);
ui->spinBox_high_pass_high->setValue(filter[i].high);
2025-03-20 15:06:41 +08:00
}
}
for (int i = 0; i < 6; i++) {
2025-03-28 10:17:18 +08:00
if (variables[i].type == "direct") {
2025-03-20 15:06:41 +08:00
ui->comboBox_direct_value_range->setCurrentText(variables[i].full_sacle_range);
ui->doubleSpinBox_direct_clamp->setValue(variables[i].clamp_value);
2025-03-28 10:17:18 +08:00
} else if (variables[i].type == "gap") {
2025-03-20 15:06:41 +08:00
ui->comboBox_gap_range->setCurrentText(variables[i].full_sacle_range);
ui->doubleSpinBox_gap_clamp->setValue(variables[i].clamp_value);
2025-03-28 10:17:18 +08:00
} else if (variables[i].type == "1x_ampl") {
2025-03-23 14:03:48 +08:00
ui->checkBox_1x_ampl->setChecked(variables[i].checked);
2025-03-20 15:06:41 +08:00
ui->comboBox_1x_value_range->setCurrentText(variables[i].full_sacle_range);
ui->doubleSpinBox_1x_ampl_clamp->setValue(variables[i].clamp_value);
ui->doubleSpinBox_1x_phase_lag_clamp->setValue(variables[i].phase_lag);
2025-03-28 10:17:18 +08:00
} else if (variables[i].type == "2x_ampl") {
2025-03-23 14:03:48 +08:00
ui->checkBox_2x_ampl->setChecked(variables[i].checked);
2025-03-20 15:06:41 +08:00
ui->comboBox_2x_value_range->setCurrentText(variables[i].full_sacle_range);
ui->doubleSpinBox_2x_ampl_clamp->setValue(variables[i].clamp_value);
ui->doubleSpinBox_2x_phase_lag_clamp->setValue(variables[i].phase_lag);
2025-03-28 10:17:18 +08:00
} else if (variables[i].type == "not_1x_ampl") {
2025-03-23 14:03:48 +08:00
ui->checkBox_not_1x_ampl->setChecked(variables[i].checked);
2025-03-20 15:06:41 +08:00
ui->comboBox_not_1x_ampl->setCurrentText(variables[i].full_sacle_range);
ui->doubleSpinBox_not_1x_ampl_clamp->setValue(variables[i].clamp_value);
2025-03-28 10:17:18 +08:00
} else if (variables[i].type == "smax_ampl") {
2025-03-23 14:03:48 +08:00
ui->checkBox_smax_ampl->setChecked(variables[i].checked);
2025-03-20 15:06:41 +08:00
ui->comboBox_smax_range->setCurrentText(variables[i].full_sacle_range);
ui->doubleSpinBox_smax_clamp->setValue(variables[i].clamp_value);
}
}
ui->spinBox_alert_delay->setValue(delay.alert);
ui->doubleSpinBox_danger_delay->setValue(delay.danger);
ui->checkBox_100ms_delay->setChecked(delay.active_100ms);
ui->checkBox_alert_latching->setChecked(alert_variables.alert_latching);
ui->checkBox_danger_latching->setChecked(alert_variables.danger_latching);
ui->comboBox_recorder_output->setCurrentText(alert_variables.recorder_output);
ui->checkBox_two_ma_clamp->setChecked(alert_variables.two_ma_clamp);
ui->doubleSpinBox_trip_multiply->setValue(alert_variables.trip_multiply);
ui->comboBox_comparision->setCurrentText(alert_variables.comparision);
ui->spinBox_comparision_percentage->setValue(alert_variables.comparision_percentage);
}
2025-03-28 10:17:18 +08:00
void Radial_vibration::on_pushButton_confirm_clicked() {
2025-03-20 15:06:41 +08:00
for (int i = 0; i < 3; i++) {
2025-03-28 10:17:18 +08:00
if (filter[i].checked) {
if (filter[i].type == "band_pass") {
2025-03-20 15:06:41 +08:00
filter[i].checked = ui->checkBox_band_pass->isChecked();
filter[i].low = ui->spinBox_band_pass_low->value();
filter[i].high = ui->spinBox_band_pass_high->value();
2025-03-28 10:17:18 +08:00
} else if (filter[i].type == "low_pass") {
2025-03-20 15:06:41 +08:00
filter[i].checked = ui->checkBox_low_pass->isChecked();
filter[i].low = ui->spinBox_low_pass_low->value();
filter[i].high = ui->spinBox_low_pass_high->value();
2025-03-28 10:17:18 +08:00
} else if (filter[i].type == "high_pass") {
2025-03-20 15:06:41 +08:00
filter[i].checked = ui->checkBox_high_pass->isChecked();
filter[i].low = ui->spinBox_high_pass_low->value();
filter[i].high = ui->spinBox_high_pass_high->value();
}
}
}
for (int i = 0; i < 6; i++) {
2025-03-28 10:17:18 +08:00
if (variables[i].type == "direct") {
2025-03-20 15:06:41 +08:00
variables[i].full_sacle_range = ui->comboBox_direct_value_range->currentText();
variables[i].clamp_value = ui->doubleSpinBox_direct_clamp->value();
2025-03-28 10:17:18 +08:00
} else if (variables[i].type == "gap") {
2025-03-20 15:06:41 +08:00
variables[i].full_sacle_range = ui->comboBox_gap_range->currentText();
variables[i].clamp_value = ui->doubleSpinBox_gap_clamp->value();
2025-03-28 10:17:18 +08:00
} else if (variables[i].type == "1x_ampl") {
2025-03-20 15:06:41 +08:00
variables[i].checked = ui->checkBox_1x_ampl->isChecked();
variables[i].full_sacle_range = ui->comboBox_1x_value_range->currentText();
variables[i].clamp_value = ui->doubleSpinBox_1x_ampl_clamp->value();
variables[i].phase_lag = ui->doubleSpinBox_1x_phase_lag_clamp->value();
2025-03-28 10:17:18 +08:00
} else if (variables[i].type == "2x_ampl") {
2025-03-20 15:06:41 +08:00
variables[i].checked = ui->checkBox_2x_ampl->isChecked();
variables[i].full_sacle_range = ui->comboBox_2x_value_range->currentText();
variables[i].clamp_value = ui->doubleSpinBox_2x_ampl_clamp->value();
variables[i].phase_lag = ui->doubleSpinBox_2x_phase_lag_clamp->value();
2025-03-28 10:17:18 +08:00
} else if (variables[i].type == "not_1x_ampl") {
2025-03-20 15:06:41 +08:00
variables[i].checked = ui->checkBox_not_1x_ampl->isChecked();
variables[i].full_sacle_range = ui->comboBox_not_1x_ampl->currentText();
variables[i].clamp_value = ui->doubleSpinBox_not_1x_ampl_clamp->value();
2025-03-28 10:17:18 +08:00
} else if (variables[i].type == "smax_ampl") {
2025-03-20 15:06:41 +08:00
variables[i].checked = ui->checkBox_smax_ampl->isChecked();
variables[i].full_sacle_range = ui->comboBox_smax_range->currentText();
variables[i].clamp_value = ui->doubleSpinBox_smax_clamp->value();
}
}
delay.alert = ui->spinBox_alert_delay->value();
delay.danger = ui->doubleSpinBox_danger_delay->value();
delay.active_100ms = ui->checkBox_100ms_delay->isChecked();
alert_variables.alert_latching = ui->checkBox_alert_latching->isChecked();
alert_variables.danger_latching = ui->checkBox_danger_latching->isChecked();
alert_variables.recorder_output = ui->comboBox_recorder_output->currentText();
alert_variables.two_ma_clamp = ui->checkBox_two_ma_clamp->isChecked();
alert_variables.trip_multiply = ui->doubleSpinBox_trip_multiply->value();
alert_variables.comparision = ui->comboBox_comparision->currentText();
alert_variables.comparision_percentage = ui->spinBox_comparision_percentage->value();
2025-03-28 10:17:18 +08:00
QJsonObject filter_obj, variables_obj;
2025-03-20 15:06:41 +08:00
QJsonArray filter_array;
2025-03-28 10:17:18 +08:00
for (int i = 0; i < 3; i++) {
2025-03-20 15:06:41 +08:00
QJsonObject temp_obj;
2025-03-28 10:17:18 +08:00
temp_obj.insert("type", filter[i].type);
temp_obj.insert("low", filter[i].low);
temp_obj.insert("high", filter[i].high);
temp_obj.insert("checked", filter[i].checked);
2025-03-20 15:06:41 +08:00
filter_array.append(temp_obj);
}
2025-03-28 10:17:18 +08:00
filter_obj.insert("filter", filter_array);
filter_obj.insert("slot", slot_no);
filter_obj.insert("id", channel);
filter_obj.insert("version", 1);
2025-03-20 15:06:41 +08:00
QJsonArray variables_array;
2025-03-28 10:17:18 +08:00
for (int i = 0; i < 6; i++) {
2025-03-20 15:06:41 +08:00
QJsonObject temp_obj;
2025-03-28 10:17:18 +08:00
temp_obj.insert("type", variables[i].type);
if (variables[i].type == "direct") {
temp_obj.insert("full_sacle_range", variables[i].full_sacle_range);
temp_obj.insert("clamp_value", variables[i].clamp_value);
} else if (variables[i].type == "gap") {
temp_obj.insert("clamp_value", variables[i].clamp_value);
temp_obj.insert("full_sacle_range", variables[i].full_sacle_range);
} else if (variables[i].type == "1x_ampl" || variables[i].type == "2x_ampl") {
temp_obj.insert("checked", variables[i].checked);
temp_obj.insert("full_sacle_range", variables[i].full_sacle_range);
temp_obj.insert("clamp_value", variables[i].clamp_value);
temp_obj.insert("phase_lag", variables[i].phase_lag);
} else if (variables[i].type == "not_1x_ampl" || variables[i].type == "smax_ampl") {
temp_obj.insert("checked", variables[i].checked);
temp_obj.insert("full_sacle_range", variables[i].full_sacle_range);
temp_obj.insert("clamp_value", variables[i].clamp_value);
2025-03-23 14:03:48 +08:00
}
2025-03-20 15:06:41 +08:00
variables_array.append(temp_obj);
}
2025-03-28 10:17:18 +08:00
variables_obj.insert("variables", variables_array);
2025-03-20 15:06:41 +08:00
QJsonObject delay_obj;
2025-03-28 10:17:18 +08:00
delay_obj.insert("alert", delay.alert);
delay_obj.insert("danger", delay.danger);
delay_obj.insert("100ms", delay.active_100ms);
variables_obj.insert("delay", delay_obj);
variables_obj.insert("alert_latching", alert_variables.alert_latching);
variables_obj.insert("danger_latching", alert_variables.danger_latching);
variables_obj.insert("recorder_output", alert_variables.recorder_output);
variables_obj.insert("two_ma_clamp", alert_variables.two_ma_clamp);
variables_obj.insert("trip_multiply", alert_variables.trip_multiply);
variables_obj.insert("comparision", alert_variables.comparision);
variables_obj.insert("comparision_percentage", alert_variables.comparision_percentage);
variables_obj.insert("slot", slot_no);
variables_obj.insert("id", channel);
variables_obj.insert("version", 1);
2025-03-20 15:06:41 +08:00
QString filePath_filter = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\filter_%2.json").arg(slot_no).arg(channel);
QString filePath_variables = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\radial_vibration_variables_%2.json").arg(slot_no).arg(channel);
QFile file_filter(filePath_filter);
QFile file_variables(filePath_variables);
if (!file_filter.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug() << "Cannot open file for writing:" << filePath_filter;
return;
}
if (!file_variables.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug() << "Cannot open file for writing:" << filePath_variables;
return;
}
QJsonDocument jsonDoc_filter(filter_obj);
QJsonDocument jsonDoc_variables(variables_obj);
file_filter.write(jsonDoc_filter.toJson());
file_variables.write(jsonDoc_variables.toJson());
file_filter.close();
file_variables.close();
this->close();
2025-03-20 15:06:41 +08:00
}
2025-03-28 10:17:18 +08:00
void Radial_vibration::on_pushButton_set_default_clicked() {
2025-03-20 15:06:41 +08:00
}