add some callbacks.

This commit is contained in:
pandx 2025-03-28 10:17:18 +08:00
parent f7cf832d9a
commit 306db57a47
12 changed files with 561 additions and 285 deletions

View File

@ -6,10 +6,9 @@
#include <QJsonObject>
#include <QFile>
Acceleration::Acceleration(int slot_no_,int channel_,bool active,QWidget *parent) :
Acceleration::Acceleration(int slot_no_, int channel_, bool active, QWidget *parent) :
QWidget(parent),
ui(new Ui::Acceleration)
{
ui(new Ui::Acceleration) {
ui->setupUi(this);
slot_no = slot_no_;
channel = channel_;
@ -17,23 +16,49 @@ Acceleration::Acceleration(int slot_no_,int channel_,bool active,QWidget *parent
QString slot = QString("%1").arg(slot_no);
ui->label_channel->setText(chan);
ui->label_slot->setText(slot);
if(active)
if (active) {
ui->label_active->setText("(启用)");
else
} 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\\acceleration_variables_%2.json").arg(slot_no).arg(channel);
readJsonFile(filePath_variables);
Init();
connect(ui->checkBox_1x_ampl, &QCheckBox::toggled, this, &Acceleration::on_1x_ampl_toggled);
connect(ui->checkBox_2x_ampl, &QCheckBox::toggled, this, &Acceleration::on_2x_ampl_toggled);
}
Acceleration::~Acceleration()
{
Acceleration::~Acceleration() {
delete ui;
}
void Acceleration::readJsonFile(const QString &filePath)
{
void Acceleration::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 Acceleration::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 Acceleration::readJsonFile(const QString &filePath) {
// 创建文件对象
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -53,33 +78,32 @@ void Acceleration::readJsonFile(const QString &filePath)
return;
}
QJsonObject json_obj = jsonDoc.object();
if(filePath.contains("filter_")){
if (filePath.contains("filter_")) {
QJsonArray filter_array = json_obj["filter"].toArray();
for(int i = 0; i < filter_array.size(); i++){
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("acceleration_variables_")){
} else if (filePath.contains("acceleration_variables_")) {
QJsonArray variables_array = json_obj["variables"].toArray();
for(int i = 0; i < variables_array.size(); i++){
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"){
if (variables[i].type == "direct") {
variables[i].full_sacle_range = temp_obj["full_sacle_range"].toString();
variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
}else if(variables[i].type == "bias_volt"){
} 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"){
} else if (variables[i].type == "1x_ampl") {
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();
}else if(variables[i].type == "2x_ampl"){
} else if (variables[i].type == "2x_ampl") {
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();
@ -102,19 +126,18 @@ void Acceleration::readJsonFile(const QString &filePath)
alert_variables.comparision_percentage = json_obj["comparision_percentage"].toInt();
}
}
void Acceleration::Init()
{
void Acceleration::Init() {
for (int i = 0; i < 3; i++) {
if(filter[i].checked){
if(filter[i].type == "band_pass"){
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"){
} 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"){
} 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);
@ -122,17 +145,17 @@ void Acceleration::Init()
}
}
for (int i = 0; i < 4; i++) {
if(variables[i].type == "direct"){
if (variables[i].type == "direct") {
ui->comboBox_direct_value_range->setCurrentText(variables[i].full_sacle_range);
ui->doubleSpinBox_direct_clamp->setValue(variables[i].clamp_value);
}else if(variables[i].type == "bias_volt"){
} 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"){
} else if (variables[i].type == "1x_ampl") {
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].clamp_value);
}else if(variables[i].type == "2x_ampl"){
} else if (variables[i].type == "2x_ampl") {
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].clamp_value);
@ -153,35 +176,34 @@ void Acceleration::Init()
ui->spinBox_comparision_percentage->setValue(alert_variables.comparision_percentage);
}
void Acceleration::on_pushButton_confirm_clicked()
{
void Acceleration::on_pushButton_confirm_clicked() {
for (int i = 0; i < 3; i++) {
if(filter[i].type == "band_pass"){
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"){
} 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"){
} 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"){
if (variables[i].type == "direct") {
variables[i].full_sacle_range = ui->comboBox_direct_value_range->currentText();
variables[i].clamp_value = ui->doubleSpinBox_direct_clamp->value();
}else if(variables[i].type == "bias_volt"){
} else if (variables[i].type == "bias_volt") {
variables[i].clamp_value = ui->doubleSpinBox_bias_volt_clamp->value();
}else if(variables[i].type == "1x_ampl"){
} 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->currentText();
variables[i].clamp_value = ui->doubleSpinBox_1x_ampl_clamp->value();
variables[i].clamp_value = ui->doubleSpinBox_1x_phase_lag_clamp->value();
}else if(variables[i].type == "2x_ampl"){
} 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->currentText();
variables[i].clamp_value = ui->doubleSpinBox_2x_ampl_clamp->value();
@ -201,58 +223,57 @@ void Acceleration::on_pushButton_confirm_clicked()
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;
QJsonObject filter_obj, variables_obj;
QJsonArray filter_array;
for(int i = 0; i < 3; i++){
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);
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);
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 < 4; i++){
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("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);
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("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);
}
variables_array.append(temp_obj);
}
variables_obj.insert("variables",variables_array);
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("id",channel);
variables_obj.insert("version",1);
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("id", channel);
variables_obj.insert("version", 1);
QJsonDocument jsonDoc_filter(filter_obj);
QString filePath = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\filter_%2.json").arg(slot_no).arg(channel);
QFile file(filePath);
@ -275,14 +296,11 @@ void Acceleration::on_pushButton_confirm_clicked()
}
void Acceleration::on_pushButton_set_default_clicked()
{
void Acceleration::on_pushButton_set_default_clicked() {
}
void Acceleration::on_pushButton_cancel_clicked()
{
void Acceleration::on_pushButton_cancel_clicked() {
this->close();
}

View File

@ -8,24 +8,25 @@ namespace Ui {
class Acceleration;
}
class Acceleration : public QWidget
{
class Acceleration : public QWidget {
Q_OBJECT
public:
explicit Acceleration(int slot_no_,int channel_,bool active,QWidget *parent = nullptr);
public:
explicit Acceleration(int slot_no_, int channel_, bool active, QWidget *parent = nullptr);
~Acceleration();
int slot_no;
int channel;
private slots:
private slots:
void on_pushButton_confirm_clicked();
void on_pushButton_set_default_clicked();
void on_pushButton_cancel_clicked();
void on_1x_ampl_toggled(bool checked);
void on_2x_ampl_toggled(bool checked);
private:
private:
Ui::Acceleration *ui;
Filter filter[3];

View File

@ -18,6 +18,10 @@ KeyPhase::KeyPhase(int slot_no_, QWidget *parent)
QString filePath_keyphase = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\keyphase.json").arg(slot_no);
readJsonFile(filePath_keyphase);
Init();
connect(ui->radioButton_manual_threshold_1, &QRadioButton::toggled, this, &KeyPhase::on_manual_threshold_1_clicked);
connect(ui->radioButton_manual_threshold_2, &QRadioButton::toggled, this, &KeyPhase::on_manual_threshold_2_clicked);
connect(ui->radioButton_manual_threshold_3, &QRadioButton::toggled, this, &KeyPhase::on_manual_threshold_3_clicked);
connect(ui->radioButton_manual_threshold_4, &QRadioButton::toggled, this, &KeyPhase::on_manual_threshold_4_clicked);
}
KeyPhase::~KeyPhase() {
@ -28,6 +32,46 @@ void KeyPhase::on_pushButton_cancel_clicked() {
this->close();
}
void KeyPhase::on_manual_threshold_1_clicked(bool checked) {
if (checked) {
ui->doubleSpinBox_threshold_1->setEnabled(true);
ui->doubleSpinBox_hysteresis_1->setEnabled(true);
return;
}
ui->doubleSpinBox_threshold_1->setEnabled(false);
ui->doubleSpinBox_hysteresis_1->setEnabled(false);
}
void KeyPhase::on_manual_threshold_2_clicked(bool checked) {
if (checked) {
ui->doubleSpinBox_threshold_2->setEnabled(true);
ui->doubleSpinBox_hysteresis_2->setEnabled(true);
return;
}
ui->doubleSpinBox_threshold_2->setEnabled(false);
ui->doubleSpinBox_hysteresis_2->setEnabled(false);
}
void KeyPhase::on_manual_threshold_3_clicked(bool checked) {
if (checked) {
ui->doubleSpinBox_threshold_3->setEnabled(true);
ui->doubleSpinBox_hysteresis_3->setEnabled(true);
return;
}
ui->doubleSpinBox_threshold_3->setEnabled(false);
ui->doubleSpinBox_hysteresis_3->setEnabled(false);
}
void KeyPhase::on_manual_threshold_4_clicked(bool checked) {
if (checked) {
ui->doubleSpinBox_threshold_4->setEnabled(true);
ui->doubleSpinBox_hysteresis_4->setEnabled(true);
return;
}
ui->doubleSpinBox_threshold_4->setEnabled(false);
ui->doubleSpinBox_hysteresis_4->setEnabled(false);
}
void KeyPhase::readJsonFile(const QString &filePath) {
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {

View File

@ -18,7 +18,10 @@ class KeyPhase : public QDialog {
private slots:
void on_pushButton_confirm_clicked();
void on_pushButton_cancel_clicked();
void on_manual_threshold_1_clicked(bool checked);
void on_manual_threshold_2_clicked(bool checked);
void on_manual_threshold_3_clicked(bool checked);
void on_manual_threshold_4_clicked(bool checked);
private:
Ui::KeyPhase *ui;
Tachometer_Variables keyphase_variables[4];

View File

@ -387,6 +387,15 @@
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>-50.000000000000000</double>
</property>
<property name="maximum">
<double>50.000000000000000</double>
</property>
<property name="value">
<double>-5.000000000000000</double>
</property>
</widget>
<widget class="QLabel" name="label_24">
<property name="geometry">
@ -442,6 +451,9 @@
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>50.000000000000000</double>
</property>
<property name="value">
<double>2.000000000000000</double>
</property>
@ -782,6 +794,15 @@
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>-50.000000000000000</double>
</property>
<property name="maximum">
<double>50.000000000000000</double>
</property>
<property name="value">
<double>-5.000000000000000</double>
</property>
</widget>
<widget class="QLabel" name="label_33">
<property name="geometry">
@ -837,6 +858,9 @@
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>50.000000000000000</double>
</property>
<property name="value">
<double>2.000000000000000</double>
</property>
@ -1229,6 +1253,15 @@
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>-50.000000000000000</double>
</property>
<property name="maximum">
<double>50.000000000000000</double>
</property>
<property name="value">
<double>-5.000000000000000</double>
</property>
</widget>
<widget class="QLabel" name="label_48">
<property name="geometry">
@ -1284,6 +1317,9 @@
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>50.000000000000000</double>
</property>
<property name="value">
<double>2.000000000000000</double>
</property>
@ -1579,6 +1615,15 @@
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>-50.000000000000000</double>
</property>
<property name="maximum">
<double>50.000000000000000</double>
</property>
<property name="value">
<double>-5.000000000000000</double>
</property>
</widget>
<widget class="QLabel" name="label_55">
<property name="geometry">
@ -1634,6 +1679,9 @@
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>50.000000000000000</double>
</property>
<property name="value">
<double>2.000000000000000</double>
</property>

View File

@ -6,10 +6,9 @@
#include <QJsonObject>
#include <QJsonArray>
Radial_vibration::Radial_vibration(int slot_no_,int channel_,bool active,QWidget *parent)
Radial_vibration::Radial_vibration(int slot_no_, int channel_, bool active, QWidget *parent)
: QWidget(parent)
, ui(new Ui::Radial_vibration)
{
, ui(new Ui::Radial_vibration) {
ui->setupUi(this);
slot_no = slot_no_;
channel = channel_;
@ -17,23 +16,75 @@ Radial_vibration::Radial_vibration(int slot_no_,int channel_,bool active,QWidget
QString slot = QString("%1").arg(slot_no);
ui->label_channel->setText(chan);
ui->label_slot->setText(slot);
if(active)
if (active) {
ui->label_active->setText("(启用)");
else
} 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();
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);
}
Radial_vibration::~Radial_vibration()
{
Radial_vibration::~Radial_vibration() {
delete ui;
}
void Radial_vibration::readJsonFile(const QString &filePath)
{
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) {
// 创建文件对象
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -53,36 +104,36 @@ void Radial_vibration::readJsonFile(const QString &filePath)
return;
}
QJsonObject json_obj = jsonDoc.object();
if(filePath.contains("filter_")){
if (filePath.contains("filter_")) {
QJsonArray filter_array = json_obj["filter"].toArray();
for(int i = 0; i < filter_array.size(); i++){
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_")){
} else if (filePath.contains("radial_vibration_variables_")) {
QJsonArray variables_array = json_obj["variables"].toArray();
for(int i = 0; i < variables_array.size(); i++){
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"){
if (variables[i].type == "direct") {
variables[i].full_sacle_range = temp_obj["full_sacle_range"].toString();
variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
}else if(variables[i].type == "bias_volt"){
} 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"].toString();
}else if(variables[i].type == "1x_ampl" || variables[i].type == "2x_ampl"){
} 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"].toString();
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"){
} 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"].toString();
}else if(variables[i].type == "smax_ampl"){
} 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"].toString();
@ -103,45 +154,44 @@ void Radial_vibration::readJsonFile(const QString &filePath)
}
}
void Radial_vibration::Init()
{
void Radial_vibration::Init() {
for (int i = 0; i < 3; i++) {
if(filter[i].type == "band_pass"){
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"){
} 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"){
} 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);
}
}
for (int i = 0; i < 6; i++) {
if(variables[i].type == "direct"){
if (variables[i].type == "direct") {
ui->comboBox_direct_value_range->setCurrentText(variables[i].full_sacle_range);
ui->doubleSpinBox_direct_clamp->setValue(variables[i].clamp_value);
}else if(variables[i].type == "gap"){
} else if (variables[i].type == "gap") {
ui->comboBox_gap_range->setCurrentText(variables[i].full_sacle_range);
ui->doubleSpinBox_gap_clamp->setValue(variables[i].clamp_value);
}else if(variables[i].type == "1x_ampl"){
} else if (variables[i].type == "1x_ampl") {
ui->checkBox_1x_ampl->setChecked(variables[i].checked);
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);
}else if(variables[i].type == "2x_ampl"){
} else if (variables[i].type == "2x_ampl") {
ui->checkBox_2x_ampl->setChecked(variables[i].checked);
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);
}else if(variables[i].type == "not_1x_ampl"){
} else if (variables[i].type == "not_1x_ampl") {
ui->checkBox_not_1x_ampl->setChecked(variables[i].checked);
ui->comboBox_not_1x_ampl->setCurrentText(variables[i].full_sacle_range);
ui->doubleSpinBox_not_1x_ampl_clamp->setValue(variables[i].clamp_value);
}else if(variables[i].type == "smax_ampl"){
} else if (variables[i].type == "smax_ampl") {
ui->checkBox_smax_ampl->setChecked(variables[i].checked);
ui->comboBox_smax_range->setCurrentText(variables[i].full_sacle_range);
ui->doubleSpinBox_smax_clamp->setValue(variables[i].clamp_value);
@ -159,19 +209,18 @@ void Radial_vibration::Init()
ui->spinBox_comparision_percentage->setValue(alert_variables.comparision_percentage);
}
void Radial_vibration::on_pushButton_confirm_clicked()
{
void Radial_vibration::on_pushButton_confirm_clicked() {
for (int i = 0; i < 3; i++) {
if(filter[i].checked){
if(filter[i].type == "band_pass"){
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"){
} 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"){
} 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();
@ -179,27 +228,27 @@ void Radial_vibration::on_pushButton_confirm_clicked()
}
}
for (int i = 0; i < 6; i++) {
if(variables[i].type == "direct"){
if (variables[i].type == "direct") {
variables[i].full_sacle_range = ui->comboBox_direct_value_range->currentText();
variables[i].clamp_value = ui->doubleSpinBox_direct_clamp->value();
}else if(variables[i].type == "gap"){
} else if (variables[i].type == "gap") {
variables[i].full_sacle_range = ui->comboBox_gap_range->currentText();
variables[i].clamp_value = ui->doubleSpinBox_gap_clamp->value();
}else if(variables[i].type == "1x_ampl"){
} 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->currentText();
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"){
} 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->currentText();
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"){
} 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->currentText();
variables[i].clamp_value = ui->doubleSpinBox_not_1x_ampl_clamp->value();
}else if(variables[i].type == "smax_ampl"){
} else if (variables[i].type == "smax_ampl") {
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();
@ -215,58 +264,58 @@ void Radial_vibration::on_pushButton_confirm_clicked()
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;
QJsonObject filter_obj, variables_obj;
QJsonArray filter_array;
for(int i = 0; i < 3; i++){
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);
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);
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++){
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);
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);
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);
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);
@ -289,8 +338,6 @@ void Radial_vibration::on_pushButton_confirm_clicked()
}
void Radial_vibration::on_pushButton_set_default_clicked()
{
void Radial_vibration::on_pushButton_set_default_clicked() {
}

View File

@ -7,21 +7,25 @@ namespace Ui {
class Radial_vibration;
}
class Radial_vibration : public QWidget
{
class Radial_vibration : public QWidget {
Q_OBJECT
public:
explicit Radial_vibration(int slot_no_,int channel_,bool active,QWidget *parent = nullptr);
public:
explicit Radial_vibration(int slot_no_, int channel_, bool active, QWidget *parent = nullptr);
~Radial_vibration();
int slot_no;
int channel;
private slots:
private slots:
void on_pushButton_confirm_clicked();
void on_pushButton_cancel_clicked();
void on_pushButton_set_default_clicked();
private:
void on_1x_ampl_toggled(bool checked);
void on_2x_ampl_toggled(bool checked);
void on_not1x_ampl_toggled(bool checked);
void on_smax_ampl_toggled(bool checked);
private:
Ui::Radial_vibration *ui;
Filter filter[3];

View File

@ -19,11 +19,56 @@ Tachometer::Tachometer(int slot_no_, QWidget *parent)
QString filePath_tachometer = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\tachometer.json").arg(slot_no);
readJsonFile(filePath_tachometer);
Init();
connect(ui->radioButton_manual_threshold_1, &QRadioButton::toggled, this, &Tachometer::on_manual_threshold_1_clicked);
connect(ui->radioButton_manual_threshold_2, &QRadioButton::toggled, this, &Tachometer::on_manual_threshold_2_clicked);
connect(ui->radioButton_manual_threshold_3, &QRadioButton::toggled, this, &Tachometer::on_manual_threshold_3_clicked);
connect(ui->radioButton_manual_threshold_4, &QRadioButton::toggled, this, &Tachometer::on_manual_threshold_4_clicked);
}
Tachometer::~Tachometer() {
delete ui;
}
void Tachometer::on_manual_threshold_1_clicked(bool checked) {
if (checked) {
ui->doubleSpinBox_threshold_1->setEnabled(true);
ui->doubleSpinBox_hysteresis_1->setEnabled(true);
return;
}
ui->doubleSpinBox_threshold_1->setEnabled(false);
ui->doubleSpinBox_hysteresis_1->setEnabled(false);
}
void Tachometer::on_manual_threshold_2_clicked(bool checked) {
if (checked) {
ui->doubleSpinBox_threshold_2->setEnabled(true);
ui->doubleSpinBox_hysteresis_2->setEnabled(true);
return;
}
ui->doubleSpinBox_threshold_2->setEnabled(false);
ui->doubleSpinBox_hysteresis_2->setEnabled(false);
}
void Tachometer::on_manual_threshold_3_clicked(bool checked) {
if (checked) {
ui->doubleSpinBox_threshold_3->setEnabled(true);
ui->doubleSpinBox_hysteresis_3->setEnabled(true);
return;
}
ui->doubleSpinBox_threshold_3->setEnabled(false);
ui->doubleSpinBox_hysteresis_3->setEnabled(false);
}
void Tachometer::on_manual_threshold_4_clicked(bool checked) {
if (checked) {
ui->doubleSpinBox_threshold_4->setEnabled(true);
ui->doubleSpinBox_hysteresis_4->setEnabled(true);
return;
}
ui->doubleSpinBox_threshold_4->setEnabled(false);
ui->doubleSpinBox_hysteresis_4->setEnabled(false);
}
void Tachometer::readJsonFile(const QString &filePath) {
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -167,7 +212,6 @@ void Tachometer::Init() {
}
}
}
void Tachometer::on_pushButton_confirm_clicked() {
for (int i = 0; i < CHANNLE_COUNT; i++) {
if (tachometer_variables[i].id == 1) {
@ -262,8 +306,6 @@ void Tachometer::on_pushButton_confirm_clicked() {
file.write(byte_array);
file.close();
}
void Tachometer::on_pushButton_cancel_clicked() {
this->close();
}

View File

@ -17,7 +17,10 @@ class Tachometer : public QDialog {
private slots:
void on_pushButton_confirm_clicked();
void on_pushButton_cancel_clicked();
void on_manual_threshold_1_clicked(bool checked);
void on_manual_threshold_2_clicked(bool checked);
void on_manual_threshold_3_clicked(bool checked);
void on_manual_threshold_4_clicked(bool checked);
private:
Ui::Tachometer *ui;

View File

@ -435,6 +435,15 @@
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>-50.000000000000000</double>
</property>
<property name="maximum">
<double>50.000000000000000</double>
</property>
<property name="value">
<double>-5.000000000000000</double>
</property>
</widget>
<widget class="QLabel" name="label_24">
<property name="geometry">
@ -490,6 +499,9 @@
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>50.000000000000000</double>
</property>
<property name="value">
<double>2.000000000000000</double>
</property>
@ -1237,6 +1249,15 @@
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>-50.000000000000000</double>
</property>
<property name="maximum">
<double>50.000000000000000</double>
</property>
<property name="value">
<double>-5.000000000000000</double>
</property>
</widget>
<widget class="QLabel" name="label_29">
<property name="geometry">
@ -1292,6 +1313,9 @@
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>50.000000000000000</double>
</property>
<property name="value">
<double>2.000000000000000</double>
</property>
@ -1791,6 +1815,15 @@
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>-50.000000000000000</double>
</property>
<property name="maximum">
<double>50.000000000000000</double>
</property>
<property name="value">
<double>-5.000000000000000</double>
</property>
</widget>
<widget class="QLabel" name="label_36">
<property name="geometry">
@ -1846,6 +1879,9 @@
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>50.000000000000000</double>
</property>
<property name="value">
<double>2.000000000000000</double>
</property>
@ -2348,6 +2384,15 @@
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>-50.000000000000000</double>
</property>
<property name="maximum">
<double>50.000000000000000</double>
</property>
<property name="value">
<double>-5.000000000000000</double>
</property>
</widget>
<widget class="QLabel" name="label_41">
<property name="geometry">
@ -2403,6 +2448,9 @@
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>50.000000000000000</double>
</property>
<property name="value">
<double>2.000000000000000</double>
</property>

View File

@ -6,10 +6,9 @@
#include <QJsonObject>
#include <QFile>
Velocity::Velocity(int slot_no_,int channel_,bool active,QWidget *parent)
Velocity::Velocity(int slot_no_, int channel_, bool active, QWidget *parent)
: QWidget(parent)
, ui(new Ui::Velocity)
{
, ui(new Ui::Velocity) {
ui->setupUi(this);
slot_no = slot_no_;
channel = channel_;
@ -17,23 +16,53 @@ Velocity::Velocity(int slot_no_,int channel_,bool active,QWidget *parent)
QString slot = QString("%1").arg(slot_no);
ui->label_channel->setText(chan);
ui->label_slot->setText(slot);
if(active)
if (active) {
ui->label_active->setText("(启用)");
else
} 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);
Init();
connect(ui->checkBox_1x_ampl, &QCheckBox::toggled, this, &Velocity::on_1x_ampl_toggled);
connect(ui->checkBox_2x_ampl, &QCheckBox::toggled, this, &Velocity::on_2x_ampl_toggled);
}
Velocity::~Velocity()
{
Velocity::~Velocity() {
delete ui;
}
void Velocity::readJsonFile(const QString &filePath)
{
void Velocity::on_pushButton_cancel_clicked() {
this->close();
}
void Velocity::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 Velocity::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 Velocity::readJsonFile(const QString &filePath) {
// 创建文件对象
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -53,33 +82,32 @@ void Velocity::readJsonFile(const QString &filePath)
return;
}
QJsonObject json_obj = jsonDoc.object();
if(filePath.contains("filter_")){
if (filePath.contains("filter_")) {
QJsonArray filter_array = json_obj["filter"].toArray();
for(int i = 0; i < filter_array.size(); i++){
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_")){
} else if (filePath.contains("velocity_variables_")) {
QJsonArray variables_array = json_obj["variables"].toArray();
for(int i = 0; i < variables_array.size(); i++){
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"){
if (variables[i].type == "direct") {
variables[i].full_sacle_range = temp_obj["full_sacle_range"].toString();
variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
}else if(variables[i].type == "bias_volt"){
} 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"){
} else if (variables[i].type == "1x_ampl") {
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();
}else if(variables[i].type == "2x_ampl"){
} else if (variables[i].type == "2x_ampl") {
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();
@ -102,19 +130,18 @@ void Velocity::readJsonFile(const QString &filePath)
alert_variables.comparision_percentage = json_obj["comparision_percentage"].toInt();
}
}
void Velocity::Init()
{
void Velocity::Init() {
for (int i = 0; i < 3; i++) {
if(filter[i].checked){
if(filter[i].type == "band_pass"){
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"){
} 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"){
} 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);
@ -122,18 +149,18 @@ void Velocity::Init()
}
}
for (int i = 0; i < 4; i++) {
if(variables[i].type == "direct"){
if (variables[i].type == "direct") {
ui->comboBox_direct_value_range->setCurrentText(variables[i].full_sacle_range);
ui->doubleSpinBox_direct_clamp->setValue(variables[i].clamp_value);
}else if(variables[i].type == "bias_volt"){
} 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"){
} else if (variables[i].type == "1x_ampl") {
ui->checkBox_1x_ampl->setChecked(variables[i].checked);
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);
}else if(variables[i].type == "2x_ampl"){
} else if (variables[i].type == "2x_ampl") {
ui->checkBox_2x_ampl->setChecked(variables[i].checked);
ui->comboBox_2x_value_range->setCurrentText(variables[i].full_sacle_range);
ui->doubleSpinBox_2x_ampl_clamp->setValue(variables[i].clamp_value);
@ -151,37 +178,35 @@ void Velocity::Init()
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);
}
void Velocity::on_pushButton_confirm_clicked()
{
void Velocity::on_pushButton_confirm_clicked() {
for (int i = 0; i < 3; i++) {
if(filter[i].type == "band_pass"){
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"){
} 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"){
} 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"){
if (variables[i].type == "direct") {
variables[i].full_sacle_range = ui->comboBox_direct_value_range->currentText();
variables[i].clamp_value = ui->doubleSpinBox_direct_clamp->value();
}else if(variables[i].type == "bias_volt"){
} else if (variables[i].type == "bias_volt") {
variables[i].clamp_value = ui->doubleSpinBox_bias_volt_clamp->value();
}else if(variables[i].type == "1x_ampl"){
} 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->currentText();
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"){
} 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->currentText();
variables[i].clamp_value = ui->doubleSpinBox_2x_ampl_clamp->value();
@ -203,18 +228,18 @@ void Velocity::on_pushButton_confirm_clicked()
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++){
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);
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);
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();
@ -228,47 +253,47 @@ void Velocity::on_pushButton_confirm_clicked()
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++){
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);
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);
}
variables_array.append(temp_obj);
}
variables_obj.insert("variables",variables_array);
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);
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();
@ -281,10 +306,3 @@ void Velocity::on_pushButton_confirm_clicked()
variables_file.close();
this->close();
}
void Velocity::on_pushButton_cancel_clicked()
{
this->close();
}

View File

@ -8,22 +8,22 @@ namespace Ui {
class Velocity;
}
class Velocity : public QWidget
{
class Velocity : public QWidget {
Q_OBJECT
public:
explicit Velocity(int slot_no_,int channel_,bool active,QWidget *parent = nullptr);
public:
explicit Velocity(int slot_no_, int channel_, bool active, QWidget *parent = nullptr);
~Velocity();
int slot_no;
int channel;
private slots:
private slots:
void on_pushButton_confirm_clicked();
void on_pushButton_cancel_clicked();
void on_1x_ampl_toggled(bool checked);
void on_2x_ampl_toggled(bool checked);
private:
private:
Ui::Velocity *ui;
Filter filter[3];