diff --git a/acceleration.cpp b/acceleration.cpp index 4c533b1..ea05b85 100644 --- a/acceleration.cpp +++ b/acceleration.cpp @@ -228,9 +228,6 @@ void Acceleration::on_pushButton_confirm_clicked() { } std::shared_ptr ptr = std::dynamic_pointer_cast(base_ptr); std::shared_ptr variable_base = ptr->GetChannelPtr(channel); - if (variable_base->type_ != kVibAcc) { - return; - } if (variable_base == nullptr || variable_base->type_ != kVibAcc) { if (variable_base == nullptr) { qDebug() << "no channel ptr"; diff --git a/radial_vibration.cpp b/radial_vibration.cpp index 776f0f1..4d4caab 100644 --- a/radial_vibration.cpp +++ b/radial_vibration.cpp @@ -6,6 +6,10 @@ #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) { @@ -21,10 +25,10 @@ Radial_vibration::Radial_vibration(int slot_no_, int channel_, bool active, QWid } 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); +// 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(); } @@ -80,256 +84,221 @@ void Radial_vibration::on_checkBox_smax_ampl_toggled(bool checked) { 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::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() { - for (int i = 0; i < 3; i++) { - if (filter[i].type == "band_pass") { - 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); - } else if (filter[i].type == "low_pass") { - 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); - } else if (filter[i].type == "high_pass") { - 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); - } + std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); + if (base_ptr == nullptr) { + qCritical() << "[Velocity::Init] should not be here"; + return; } - for (int i = 0; i < 6; i++) { - if (variables[i].type == "direct") { - ui->comboBox_direct_value_range->setCurrentIndex(variables[i].full_sacle_range); - ui->doubleSpinBox_direct_clamp->setValue(variables[i].clamp_value); - } else if (variables[i].type == "gap") { - ui->comboBox_gap_range->setCurrentIndex(variables[i].full_sacle_range); - ui->doubleSpinBox_gap_clamp->setValue(variables[i].clamp_value); - } else if (variables[i].type == "1x_ampl") { - ui->checkBox_1x_ampl->setChecked(variables[i].checked); - ui->comboBox_1x_value_range->setCurrentIndex(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); - } else if (variables[i].type == "2x_ampl") { - ui->checkBox_2x_ampl->setChecked(variables[i].checked); - ui->comboBox_2x_value_range->setCurrentIndex(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); - } else if (variables[i].type == "not_1x_ampl") { - ui->checkBox_not_1x_ampl->setChecked(variables[i].checked); - ui->comboBox_not_1x_ampl->setCurrentIndex(variables[i].full_sacle_range); - ui->doubleSpinBox_not_1x_ampl_clamp->setValue(variables[i].clamp_value); - } else if (variables[i].type == "smax_ampl") { - ui->checkBox_smax_ampl->setChecked(variables[i].checked); - ui->comboBox_smax_range->setCurrentIndex(variables[i].full_sacle_range); - ui->doubleSpinBox_smax_clamp->setValue(variables[i].clamp_value); - } + std::shared_ptr ptr = std::dynamic_pointer_cast(base_ptr); + if (ptr->base_config_[channel - 1].channel_type != kVibRadial) { + qDebug() << " channel type changes"; + return; } - 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->setCurrentIndex(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); + 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() { - for (int i = 0; i < 3; i++) { - if (filter[i].checked) { - if (filter[i].type == "band_pass") { - 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(); - } else if (filter[i].type == "low_pass") { - 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(); - } else if (filter[i].type == "high_pass") { - 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++) { - if (variables[i].type == "direct") { - variables[i].full_sacle_range = ui->comboBox_direct_value_range->currentIndex(); - variables[i].clamp_value = ui->doubleSpinBox_direct_clamp->value(); - } else if (variables[i].type == "gap") { - variables[i].full_sacle_range = ui->comboBox_gap_range->currentIndex(); - variables[i].clamp_value = ui->doubleSpinBox_gap_clamp->value(); - } else if (variables[i].type == "1x_ampl") { - variables[i].checked = ui->checkBox_1x_ampl->isChecked(); - variables[i].full_sacle_range = ui->comboBox_1x_value_range->currentIndex(); - variables[i].clamp_value = ui->doubleSpinBox_1x_ampl_clamp->value(); - variables[i].phase_lag = ui->doubleSpinBox_1x_phase_lag_clamp->value(); - } else if (variables[i].type == "2x_ampl") { - variables[i].checked = ui->checkBox_2x_ampl->isChecked(); - variables[i].full_sacle_range = ui->comboBox_2x_value_range->currentIndex(); - variables[i].clamp_value = ui->doubleSpinBox_2x_ampl_clamp->value(); - variables[i].phase_lag = ui->doubleSpinBox_2x_phase_lag_clamp->value(); - } else if (variables[i].type == "not_1x_ampl") { - variables[i].checked = ui->checkBox_not_1x_ampl->isChecked(); - variables[i].full_sacle_range = ui->comboBox_not_1x_ampl->currentIndex(); - variables[i].clamp_value = ui->doubleSpinBox_not_1x_ampl_clamp->value(); - } else if (variables[i].type == "smax_ampl") { - variables[i].checked = ui->checkBox_smax_ampl->isChecked(); - variables[i].full_sacle_range = ui->comboBox_smax_range->currentIndex(); - 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->currentIndex(); - 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(); - QJsonObject filter_obj, variables_obj; - QJsonArray filter_array; - for (int i = 0; i < 3; i++) { - QJsonObject temp_obj; - 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); - filter_array.append(temp_obj); - } - filter_obj.insert("filter", filter_array); - filter_obj.insert("slot", slot_no); - filter_obj.insert("id", channel); - filter_obj.insert("version", 1); - QJsonArray variables_array; - for (int i = 0; i < 6; i++) { - QJsonObject temp_obj; - 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); - } - variables_array.append(temp_obj); - } - variables_obj.insert("variables", variables_array); - QJsonObject delay_obj; - 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); - 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; + std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); + if (base_ptr == nullptr) { + qCritical() << "[Acceleration::Init] should not be here"; return; } - if (!file_variables.open(QIODevice::WriteOnly | QIODevice::Text)) { - qDebug() << "Cannot open file for writing:" << filePath_variables; + 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->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; } - 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(); + 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->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(); } diff --git a/radial_vibration.ui b/radial_vibration.ui index 443de7a..84eee4e 100644 --- a/radial_vibration.ui +++ b/radial_vibration.ui @@ -872,7 +872,7 @@ 危险 - + 60 @@ -891,7 +891,7 @@ 99.900000000000006 - + 60 @@ -930,7 +930,7 @@ 1.0 - 60.0s - + 60 diff --git a/velocity.cpp b/velocity.cpp index e778809..7e5c935 100644 --- a/velocity.cpp +++ b/velocity.cpp @@ -6,6 +6,9 @@ #include #include #include "velocity_ds.h" +#include "data_config.h" +#include "vibrationdata.h" +#include "config_mgr.h" Velocity::Velocity(int slot_no_, int channel_, bool active, QWidget *parent) : QWidget(parent) @@ -22,10 +25,10 @@ Velocity::Velocity(int slot_no_, int channel_, bool active, QWidget *parent) } 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\\velocity_variables_%2.json").arg(slot_no).arg(channel); - readJsonFile(filePath_variables); +// 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\\velocity_variables_%2.json").arg(slot_no).arg(channel); +// readJsonFile(filePath_variables); Init(); } @@ -119,255 +122,151 @@ void Velocity::on_checkBox_2x_ampl_toggled(bool checked) { ui->doubleSpinBox_2x_phase_lag_clamp->setEnabled(false); } -void Velocity::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("velocity_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(); - variables[i].custom = temp_obj["custom"].toDouble(); - } else if (variables[i].type == "bias_volt") { - variables[i].clamp_value = temp_obj["clamp_value"].toDouble(); - variables[i].bias_voltage = temp_obj["bias_voltage"].toInt(); - } else if (variables[i].type == "1x_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(); - variables[i].custom = temp_obj["custom"].toDouble(); - } else if (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(); - variables[i].custom = temp_obj["custom"].toDouble(); - } - } - QJsonObject delay_obj = json_obj["delay"].toObject(); - delay.alert = delay_obj["alert"].toInt(); - delay.danger = delay_obj["danger"].toDouble(); - delay.active_100ms = delay_obj["100ms"].toBool(); - alert_variables.rms_active = json_obj["rms_active"].toBool(); - alert_variables.integrate_active = json_obj["integrate_active"].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 Velocity::Init() { - for (int i = 0; i < 3; i++) { - if (filter[i].checked) { - if (filter[i].type == "band_pass") { - 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); - } else if (filter[i].type == "low_pass") { - 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); - } else if (filter[i].type == "high_pass") { - 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); - } - } + std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); + if (base_ptr == nullptr) { + qCritical() << "[Velocity::Init] should not be here"; + return; } - for (int i = 0; i < 4; i++) { - if (variables[i].type == "direct") { - ui->comboBox_direct_value_range->setCurrentIndex(variables[i].full_sacle_range); - ui->doubleSpinBox_direct_clamp->setValue(variables[i].clamp_value); - } else if (variables[i].type == "bias_volt") { - ui->label_bias_voltage->setText(QString::number(variables[i].bias_voltage)); - ui->doubleSpinBox_bias_volt_clamp->setValue(variables[i].clamp_value); - } else if (variables[i].type == "1x_ampl") { - ui->checkBox_1x_ampl->setChecked(variables[i].checked); - ui->comboBox_1x_value_range->setCurrentIndex(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); - } else if (variables[i].type == "2x_ampl") { - ui->checkBox_2x_ampl->setChecked(variables[i].checked); - ui->comboBox_2x_value_range->setCurrentIndex(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); - } + std::shared_ptr ptr = std::dynamic_pointer_cast(base_ptr); + if (ptr->base_config_[channel - 1].channel_type != kVibVelocity) { + qDebug() << " channel type changes"; + return; } - ui->spinBox_alert->setValue(delay.alert); - ui->doubleSpinBox_danger->setValue(delay.danger); - ui->checkBox_100ms->setChecked(delay.active_100ms); - ui->checkBox_alert_latching->setChecked(alert_variables.alert_latching); - ui->checkBox_danger_latching->setChecked(alert_variables.danger_latching); - ui->checkBox_timed_ok->setChecked(alert_variables.timed_ok); - ui->comboBox_recorder_output->setCurrentIndex(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); + 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->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_rms->setChecked(variable_ptr->rms_active_); + ui->checkBox_integrate->setChecked(variable_ptr->integrate_active_); + ui->checkBox_alert_latching->setChecked(variable_ptr->alert_latching_); + ui->checkBox_danger_latching->setChecked(variable_ptr->danger_latching_); + ui->checkBox_timed_ok->setChecked(variable_ptr->timed_ok_); + 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 Velocity::on_pushButton_confirm_clicked() { - for (int i = 0; i < 3; i++) { - if (filter[i].type == "band_pass") { - 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(); - } else if (filter[i].type == "low_pass") { - 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(); - } else if (filter[i].type == "high_pass") { - 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 < 4; i++) { - if (variables[i].type == "direct") { - variables[i].full_sacle_range = ui->comboBox_direct_value_range->currentIndex(); - variables[i].clamp_value = ui->doubleSpinBox_direct_clamp->value(); - // TODO: custom - } else if (variables[i].type == "bias_volt") { - variables[i].clamp_value = ui->doubleSpinBox_bias_volt_clamp->value(); - } else if (variables[i].type == "1x_ampl") { - variables[i].checked = ui->checkBox_1x_ampl->isChecked(); - variables[i].full_sacle_range = ui->comboBox_1x_value_range->currentIndex(); - variables[i].clamp_value = ui->doubleSpinBox_1x_ampl_clamp->value(); - variables[i].phase_lag = ui->doubleSpinBox_1x_phase_lag_clamp->value(); - // TODO: custom - } else if (variables[i].type == "2x_ampl") { - variables[i].checked = ui->checkBox_2x_ampl->isChecked(); - variables[i].full_sacle_range = ui->comboBox_2x_value_range->currentIndex(); - variables[i].clamp_value = ui->doubleSpinBox_2x_ampl_clamp->value(); - variables[i].phase_lag = ui->doubleSpinBox_2x_phase_lag_clamp->value(); - // TODO: custom - } - } - delay.alert = ui->spinBox_alert->value(); - delay.danger = ui->doubleSpinBox_danger->value(); - delay.active_100ms = ui->checkBox_100ms->isChecked(); - alert_variables.alert_latching = ui->checkBox_alert_latching->isChecked(); - alert_variables.danger_latching = ui->checkBox_danger_latching->isChecked(); - alert_variables.timed_ok = ui->checkBox_timed_ok->isChecked(); - alert_variables.recorder_output = ui->comboBox_recorder_output->currentIndex(); - 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(); - // 保存到文件 - QString filePath_filter = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\filter_%2.json").arg(slot_no).arg(channel); - QJsonObject filter_obj; - QJsonArray filter_array; - for (int i = 0; i < 3; i++) { - QJsonObject temp_obj; - 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); - filter_array.append(temp_obj); - } - filter_obj.insert("filter", filter_array); - filter_obj.insert("slot", slot_no); - filter_obj.insert("id", channel); - filter_obj.insert("version", 1); - QJsonDocument filter_doc; - filter_doc.setObject(filter_obj); - QByteArray filter_data = filter_doc.toJson(); - QFile filter_file(filePath_filter); - if (!filter_file.open(QIODevice::WriteOnly | QIODevice::Text)) { - qDebug() << "Cannot open file for writing:" << filePath_filter; + std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); + if (base_ptr == nullptr) { + qCritical() << "[Acceleration::Init] should not be here"; return; } - filter_file.write(filter_data); - filter_file.close(); - QString filePath_variables = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\velocity_variables_%2.json").arg(slot_no).arg(channel); - QJsonObject variables_obj; - QJsonArray variables_array; - for (int i = 0; i < 4; i++) { - QJsonObject temp_obj; - 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 == "bias_volt") { - temp_obj.insert("clamp_value", variables[i].clamp_value); - temp_obj.insert("bias_voltage", variables[i].bias_voltage); - } else if (variables[i].type == "1x_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 == "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); + 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_ != kVibVelocity) { + if (variable_base == nullptr) { + qDebug() << "no channel ptr"; + } else { + ptr->RemoveChannel(channel); + qDebug() << "channel type change"; } - variables_array.append(temp_obj); - } - variables_obj.insert("variables", variables_array); - QJsonObject delay_obj; - 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("rms_active", alert_variables.rms_active); - variables_obj.insert("integrate_active", alert_variables.integrate_active); - variables_obj.insert("alert_latching", alert_variables.alert_latching); - variables_obj.insert("danger_latching", alert_variables.danger_latching); - variables_obj.insert("timed_ok", alert_variables.timed_ok); - 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("channel", channel); - variables_obj.insert("version", 1); - QJsonDocument variables_doc; - variables_doc.setObject(variables_obj); - QByteArray variables_data = variables_doc.toJson(); - QFile variables_file(filePath_variables); - if (!variables_file.open(QIODevice::WriteOnly | QIODevice::Text)) { - qDebug() << "Cannot open file for writing:" << filePath_variables; + std::shared_ptr variable = std::make_shared(); + variable->id_ = channel; + variable->type_ = kVibVelocity; + 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->delay_.alert = ui->spinBox_alert->value(); + variable->delay_.danger = ui->doubleSpinBox_danger->value(); + variable->delay_.active_100ms = ui->checkBox_100ms->isChecked(); + variable->rms_active_ = ui->checkBox_rms->isChecked(); + variable->integrate_active_ = ui->checkBox_integrate->isChecked(); + variable->alert_latching_ = ui->checkBox_alert_latching->isChecked(); + variable->danger_latching_ = ui->checkBox_danger_latching->isChecked(); + variable->timed_ok_ = ui->checkBox_timed_ok->isChecked(); + ptr->variables_.push_back(variable); return; } - variables_file.write(variables_data); - variables_file.close(); + 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->delay_.alert = ui->spinBox_alert->value(); + variable->delay_.danger = ui->doubleSpinBox_danger->value(); + variable->delay_.active_100ms = ui->checkBox_100ms->isChecked(); + variable->rms_active_ = ui->checkBox_rms->isChecked(); + variable->integrate_active_ = ui->checkBox_integrate->isChecked(); + variable->alert_latching_ = ui->checkBox_alert_latching->isChecked(); + variable->danger_latching_ = ui->checkBox_danger_latching->isChecked(); + variable->timed_ok_ = ui->checkBox_timed_ok->isChecked(); this->close(); }