TSI_Config/seismic_monitor.cpp

433 lines
22 KiB
C++

#include "seismic_monitor.h"
#include "ui_seismic_monitor.h"
#include <QDebug>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include <QFile>
#include <QListView>
#include "acceleration.h"
#include "velocity.h"
#include "radial_vibration.h"
#include "data_config.h"
#include "config_mgr.h"
#include "vibrationdata.h"
#include "trust.h"
Seismic_monitor::Seismic_monitor(int slot,int cardtype, QWidget *parent) :
QWidget(parent),
ui(new Ui::Seismic_monitor) {
ui->setupUi(this);
ui->widget_body->setProperty("flag", "body");
ui->comboBox_chan_type_1->setView(new QListView());
ui->comboBox_chan_type_2->setView(new QListView());
ui->comboBox_chan_type_3->setView(new QListView());
ui->comboBox_chan_type_4->setView(new QListView());
ui->comboBox_transducer_name_1->setView(new QListView());
ui->comboBox_transducer_name_2->setView(new QListView());
ui->comboBox_transducer_name_3->setView(new QListView());
ui->comboBox_transducer_name_4->setView(new QListView());
ui->comboBox_sample_rate_1->setView(new QListView());
ui->comboBox_sample_rate_2->setView(new QListView());
ui->comboBox_sample_rate_3->setView(new QListView());
ui->comboBox_sample_rate_4->setView(new QListView());
slot_no = slot;
car_type = static_cast<CardType>(cardtype);
QString slot_no_ = QString("%1").arg(slot_no);
ui->label_slot_no->setText(slot_no_);
Init();
}
Seismic_monitor::~Seismic_monitor() {
delete ui;
}
void Seismic_monitor::Init() {
// for (int var = 0; var < vec_transducer.size(); ++var) {
// ui->comboBox_transducer_name_1->addItem(vec_transducer[var].transducer_name);
// ui->comboBox_transducer_name_2->addItem(vec_transducer[var].transducer_name);
// ui->comboBox_transducer_name_3->addItem(vec_transducer[var].transducer_name);
// ui->comboBox_transducer_name_4->addItem(vec_transducer[var].transducer_name);
// }
int slot = 0;
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
if (base_ptr == nullptr) {
qDebug() << "base_ptr";
// do nothing or use template to init it.
std::shared_ptr<VibrationData> vib_data = std::make_shared<VibrationData>();
vib_data->slot_ = slot_no;
vib_data->card_type_ = car_type;
ConfigMgr::Instance()->AddCard(vib_data);
UpdateData(vib_data);
return;
}
for (int i = 0; i < SLOT_NUM; ++i) {
if (ConfigMgr::Instance()->card_type_[i] == kCardNone) {
continue;
}
QJsonObject card_item;
slot = i + 1;
card_item["type"] = ConfigMgr::Instance()->card_type_[i];
card_item["slot"] = slot;
if (ConfigMgr::Instance()->card_type_[i] == kCardKeyphaseSingle ) {
ui->comboBox_keyphase_slot->addItem(QString::number(slot));
}
}
std::shared_ptr<VibrationData> vib_data = std::dynamic_pointer_cast<VibrationData>(base_ptr);
for (int i = 0; i < CHANNEL_COUNT; i++) {
if (i + 1 == 1) {
qDebug() << vib_data->base_config_[i].channel_type ;
ui->comboBox_chan_type_1->setCurrentIndex(vib_data->base_config_[i].channel_type);
ui->checkBox_standby_1->setChecked(vib_data->base_config_[i].standby);
ui->comboBox_transducer_name_1->setCurrentIndex(vib_data->base_config_[i].transducer_id);
ui->doubleSpinBox_scale_factor_1->setValue(vib_data->base_config_[i].scale_factor);
ui->checkBox_enable_1->setChecked(vib_data->base_config_[i].active);
ui->doubleSpinBox_low_1->setValue(vib_data->base_config_[i].normal_voltage_low);
ui->doubleSpinBox_high_1->setValue(vib_data->base_config_[i].normal_voltage_high);
ui->comboBox_sample_rate_1->setCurrentIndex(vib_data->base_config_[i].sampling_rate);
ui->checkBox_power_1->setChecked(vib_data->base_config_[i].power);
} else if (i + 1 == 2) {
ui->comboBox_chan_type_2->setCurrentIndex(vib_data->base_config_[i].channel_type);
ui->comboBox_transducer_name_2->setCurrentIndex(vib_data->base_config_[i].transducer_id);
ui->doubleSpinBox_scale_factor_2->setValue(vib_data->base_config_[i].scale_factor);
ui->checkBox_enable_2->setChecked(vib_data->base_config_[i].active);
ui->doubleSpinBox_low_2->setValue(vib_data->base_config_[i].normal_voltage_low);
ui->doubleSpinBox_high_2->setValue(vib_data->base_config_[i].normal_voltage_high);
ui->comboBox_sample_rate_2->setCurrentIndex(vib_data->base_config_[i].sampling_rate);
ui->checkBox_power_2->setChecked(vib_data->base_config_[i].power);
} else if (i + 1 == 3) {
ui->checkBox_standby_2->setChecked(vib_data->base_config_[i].standby);
ui->comboBox_chan_type_3->setCurrentIndex(vib_data->base_config_[i].channel_type);
ui->comboBox_transducer_name_3->setCurrentIndex(vib_data->base_config_[i].transducer_id);
ui->doubleSpinBox_scale_factor_3->setValue(vib_data->base_config_[i].scale_factor);
ui->checkBox_enable_3->setChecked(vib_data->base_config_[i].active);
ui->doubleSpinBox_low_3->setValue(vib_data->base_config_[i].normal_voltage_low);
ui->doubleSpinBox_high_3->setValue(vib_data->base_config_[i].normal_voltage_high);
ui->comboBox_sample_rate_3->setCurrentIndex(vib_data->base_config_[i].sampling_rate);
ui->checkBox_power_3->setChecked(vib_data->base_config_[i].power);
} else if (i + 1 == 4) {
ui->comboBox_chan_type_4->setCurrentIndex(vib_data->base_config_[i].channel_type);
ui->comboBox_transducer_name_4->setCurrentIndex(vib_data->base_config_[i].transducer_id);
ui->doubleSpinBox_scale_factor_4->setValue(vib_data->base_config_[i].scale_factor);
ui->checkBox_enable_4->setChecked(vib_data->base_config_[i].active);
ui->doubleSpinBox_low_4->setValue(vib_data->base_config_[i].normal_voltage_low);
ui->doubleSpinBox_high_4->setValue(vib_data->base_config_[i].normal_voltage_high);
ui->comboBox_sample_rate_4->setCurrentIndex(vib_data->base_config_[i].sampling_rate);
ui->checkBox_power_4->setChecked(vib_data->base_config_[i].power);
}
}
}
void Seismic_monitor::UpdateData(std::shared_ptr<VibrationData> vib_data) {
for (int var = 0; var < CHANNEL_COUNT; ++var) {
if (var + 1 == 1) {
vib_data->base_config_[var].standby = ui->checkBox_standby_1->isChecked();
vib_data->base_config_[var].active = ui->checkBox_enable_1->isChecked();
vib_data->base_config_[var].rack_type = 0;
vib_data->base_config_[var].channel_type = ui->comboBox_chan_type_1->currentIndex();
vib_data->base_config_[var].transducer_id = ui->comboBox_transducer_name_1->currentIndex();
vib_data->base_config_[var].scale_factor = ui->doubleSpinBox_scale_factor_1->value();
vib_data->base_config_[var].sampling_rate = ui->comboBox_sample_rate_1->currentIndex();
vib_data->base_config_[var].normal_voltage_low = ui->doubleSpinBox_low_1->value();
vib_data->base_config_[var].normal_voltage_high = ui->doubleSpinBox_high_1->value();
vib_data->base_config_[var].power = ui->checkBox_power_1->isChecked();
vib_data->base_config_[var].chan_id = QString("S%1C%2").arg(QString::number(slot_no, 10).rightJustified(2, '0')).arg(QString::number(var+1, 10).rightJustified(2, '0'));
vib_data->base_config_[var].keyphase = ui->checkBox_keyphase->isChecked();
vib_data->base_config_[var].keyphase_slot = ui->comboBox_keyphase_slot->currentText().toInt();
vib_data->base_config_[var].keyphase_ch = ui->comboBox_keyphase_ch->currentText().toInt();
} else if (var + 1 == 2) {
vib_data->base_config_[var].standby = ui->checkBox_standby_1->isChecked();
vib_data->base_config_[var].active = ui->checkBox_enable_2->isChecked();
vib_data->base_config_[var].rack_type = 0;
vib_data->base_config_[var].channel_type = ui->comboBox_chan_type_2->currentIndex();
vib_data->base_config_[var].transducer_id = ui->comboBox_transducer_name_2->currentIndex();
vib_data->base_config_[var].scale_factor = ui->doubleSpinBox_scale_factor_2->value();
vib_data->base_config_[var].sampling_rate = ui->comboBox_sample_rate_2->currentIndex();
vib_data->base_config_[var].normal_voltage_low = ui->doubleSpinBox_low_2->value();
vib_data->base_config_[var].normal_voltage_high = ui->doubleSpinBox_high_2->value();
vib_data->base_config_[var].power = ui->checkBox_power_2->isChecked();
vib_data->base_config_[var].chan_id = QString("S%1C%2").arg(QString::number(slot_no, 10).rightJustified(2, '0')).arg(QString::number(var+1, 10).rightJustified(2, '0'));
vib_data->base_config_[var].keyphase = ui->checkBox_keyphase_2->isChecked();
vib_data->base_config_[var].keyphase_slot = ui->comboBox_keyphase_slot_2->currentText().toInt();
vib_data->base_config_[var].keyphase_ch = ui->comboBox_keyphase_ch_2->currentText().toInt();
} else if (var + 1 == 3) {
vib_data->base_config_[var].standby = ui->checkBox_standby_2->isChecked();
vib_data->base_config_[var].active = ui->checkBox_enable_3->isChecked();
vib_data->base_config_[var].rack_type = 0;
vib_data->base_config_[var].channel_type = ui->comboBox_chan_type_3->currentIndex();
vib_data->base_config_[var].transducer_id = ui->comboBox_transducer_name_3->currentIndex();
vib_data->base_config_[var].scale_factor = ui->doubleSpinBox_scale_factor_3->value();
vib_data->base_config_[var].sampling_rate = ui->comboBox_sample_rate_3->currentIndex();
vib_data->base_config_[var].normal_voltage_low = ui->doubleSpinBox_low_3->value();
vib_data->base_config_[var].normal_voltage_high = ui->doubleSpinBox_high_3->value();
vib_data->base_config_[var].power = ui->checkBox_power_3->isChecked();
vib_data->base_config_[var].chan_id = QString("S%1C%2").arg(QString::number(slot_no, 10).rightJustified(2, '0')).arg(QString::number(var+1, 10).rightJustified(2, '0'));
vib_data->base_config_[var].keyphase = ui->checkBox_keyphase_3->isChecked();
vib_data->base_config_[var].keyphase_slot = ui->comboBox_keyphase_slot_3->currentText().toInt();
vib_data->base_config_[var].keyphase_ch = ui->comboBox_keyphase_ch_3->currentText().toInt();
} else if (var + 1 == 4) {
vib_data->base_config_[var].standby = ui->checkBox_standby_2->isChecked();
vib_data->base_config_[var].active = ui->checkBox_enable_4->isChecked();
vib_data->base_config_[var].rack_type = 0;
vib_data->base_config_[var].channel_type = ui->comboBox_chan_type_4->currentIndex();
vib_data->base_config_[var].transducer_id = ui->comboBox_transducer_name_4->currentIndex();
vib_data->base_config_[var].scale_factor = ui->doubleSpinBox_scale_factor_4->value();
vib_data->base_config_[var].sampling_rate = ui->comboBox_sample_rate_4->currentIndex();
vib_data->base_config_[var].normal_voltage_low = ui->doubleSpinBox_low_4->value();
vib_data->base_config_[var].normal_voltage_high = ui->doubleSpinBox_high_4->value();
vib_data->base_config_[var].power = ui->checkBox_power_4->isChecked();
vib_data->base_config_[var].chan_id = QString("S%1C%2").arg(QString::number(slot_no, 10).rightJustified(2, '0')).arg(QString::number(var+1, 10).rightJustified(2, '0'));
vib_data->base_config_[var].keyphase = ui->checkBox_keyphase_4->isChecked();
vib_data->base_config_[var].keyphase_slot = ui->comboBox_keyphase_slot_4->currentText().toInt();
vib_data->base_config_[var].keyphase_ch = ui->comboBox_keyphase_ch_4->currentText().toInt();
}
}
}
void Seismic_monitor::on_pushButton_confirm_clicked() {
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
if (base_ptr == nullptr) {
qCritical() << " should not be here";
// std::shared_ptr<VibrationData> vib_data = std::make_shared<VibrationData>();
// ConfigMgr::Instance()->AddCard(vib_data);
// UpdateData(vib_data);
return;
}
std::shared_ptr<VibrationData> vib_data = std::dynamic_pointer_cast<VibrationData>(base_ptr);
UpdateData(vib_data);
this->close();
}
void Seismic_monitor::on_pushButton_set_default_clicked() {
}
void Seismic_monitor::on_pushButton_config_1_clicked() {
channel = 1;
if (ui->comboBox_chan_type_1->currentIndex() == kVibAcc) {
Acceleration *acceleration = new Acceleration(slot_no, channel, ui->checkBox_enable_1->isChecked());
acceleration->setWindowModality(Qt::ApplicationModal);
acceleration->show();
} else if (ui->comboBox_chan_type_1->currentIndex() == kVibRadial) {
Radial *radial_vibration = new Radial(slot_no, channel, ui->checkBox_enable_1->isChecked());
radial_vibration->setWindowModality(Qt::ApplicationModal);
radial_vibration->show();
} else if (ui->comboBox_chan_type_1->currentIndex() == kVibVelocity) {
Velocity *velocity = new Velocity(slot_no, channel, ui->checkBox_enable_1->isChecked());
velocity->setWindowModality(Qt::ApplicationModal);
velocity->show();
}else if (ui->comboBox_chan_type_1->currentIndex() == kVibThrust) {
Trust *trust = new Trust(slot_no, channel, ui->checkBox_enable_1->isChecked());
trust->setWindowModality(Qt::ApplicationModal);
trust->show();
}
}
void Seismic_monitor::on_pushButton_config_2_clicked() {
channel = 2;
if (ui->comboBox_chan_type_2->currentIndex() == kVibAcc) {
Acceleration *acceleration = new Acceleration(slot_no, channel, ui->checkBox_enable_2->isChecked());
acceleration->setWindowModality(Qt::ApplicationModal);
acceleration->show();
} else if (ui->comboBox_chan_type_2->currentIndex() == kVibRadial) {
Radial *radial_vibration = new Radial(slot_no, channel, ui->checkBox_enable_2->isChecked());
radial_vibration->setWindowModality(Qt::ApplicationModal);
radial_vibration->show();
} else if (ui->comboBox_chan_type_2->currentIndex() == kVibVelocity) {
Velocity *velocity = new Velocity(slot_no, channel, ui->checkBox_enable_2->isChecked());
velocity->setWindowModality(Qt::ApplicationModal);
velocity->show();
}else if (ui->comboBox_chan_type_2->currentIndex() == kVibThrust) {
Trust *trust = new Trust(slot_no, channel, ui->checkBox_enable_1->isChecked());
trust->setWindowModality(Qt::ApplicationModal);
trust->show();
}
}
void Seismic_monitor::on_pushButton_config_3_clicked() {
channel = 3;
if (ui->comboBox_chan_type_3->currentIndex() == kVibAcc) {
Acceleration *acceleration = new Acceleration(slot_no, channel, ui->checkBox_enable_3->isChecked());
acceleration->setWindowModality(Qt::ApplicationModal);
acceleration->show();
} else if (ui->comboBox_chan_type_3->currentIndex() == kVibRadial) {
Radial *radial_vibration = new Radial(slot_no, channel, ui->checkBox_enable_3->isChecked());
radial_vibration->setWindowModality(Qt::ApplicationModal);
radial_vibration->show();
} else if (ui->comboBox_chan_type_3->currentIndex() == kVibVelocity) {
Velocity *velocity = new Velocity(slot_no, channel, ui->checkBox_enable_3->isChecked());
velocity->setWindowModality(Qt::ApplicationModal);
velocity->show();
}else if (ui->comboBox_chan_type_3->currentIndex() == kVibThrust) {
Trust *trust = new Trust(slot_no, channel, ui->checkBox_enable_1->isChecked());
trust->setWindowModality(Qt::ApplicationModal);
trust->show();
}
}
void Seismic_monitor::on_pushButton_config_4_clicked() {
channel = 4;
if (ui->comboBox_chan_type_4->currentIndex() == kVibAcc) {
Acceleration *acceleration = new Acceleration(slot_no, channel, ui->checkBox_enable_4->isChecked());
acceleration->setWindowModality(Qt::ApplicationModal);
acceleration->show();
} else if (ui->comboBox_chan_type_4->currentIndex() == kVibRadial) {
Radial *radial_vibration = new Radial(slot_no, channel, ui->checkBox_enable_4->isChecked());
radial_vibration->setWindowModality(Qt::ApplicationModal);
radial_vibration->show();
} else if (ui->comboBox_chan_type_4->currentIndex() == kVibVelocity) {
Velocity *velocity = new Velocity(slot_no, channel, ui->checkBox_enable_4->isChecked());
velocity->setWindowModality(Qt::ApplicationModal);
velocity->show();
}else if (ui->comboBox_chan_type_4->currentIndex() == kVibThrust) {
Trust *trust = new Trust(slot_no, channel, ui->checkBox_enable_1->isChecked());
trust->setWindowModality(Qt::ApplicationModal);
trust->show();
}
}
void Seismic_monitor::on_comboBox_chan_type_1_currentTextChanged(const QString &arg1) {
switch (ui->comboBox_chan_type_1->currentIndex()) {
case kVibRadial:
ui->label_unit_1->setText("mV / mm");
break;
case kVibAcc:
ui->label_unit_1->setText("mV / m/s^2");
break;
case kVibVelocity:
ui->label_unit_1->setText("mV / mm/s");
break;
case kVibThrust:
ui->label_unit_1->setText("mV / mil");
break;
}
}
void Seismic_monitor::on_comboBox_chan_type_2_currentTextChanged(const QString &arg1) {
switch (ui->comboBox_chan_type_2->currentIndex()) {
case kVibRadial:
ui->label_unit_2->setText("mV / mm");
break;
case kVibAcc:
ui->label_unit_2->setText("mV / m/s^2");
break;
case kVibVelocity:
ui->label_unit_2->setText("mV / mm/s");
break;
case kVibThrust:
ui->label_unit_2->setText("mV / mil");
break;
}
}
void Seismic_monitor::on_comboBox_chan_type_3_currentTextChanged(const QString &arg1) {
switch (ui->comboBox_chan_type_3->currentIndex()) {
case kVibRadial:
ui->label_unit_3->setText("mV / mm");
break;
case kVibAcc:
ui->label_unit_3->setText("mV / m/s^2");
break;
case kVibVelocity:
ui->label_unit_3->setText("mV / mm/s");
break;
case kVibThrust:
ui->label_unit_3->setText("mV / mil");
break;
}
}
void Seismic_monitor::on_comboBox_chan_type_4_currentTextChanged(const QString &arg1) {
switch (ui->comboBox_chan_type_4->currentIndex()) {
case kVibRadial:
ui->label_unit_4->setText("mV / mm");
break;
case kVibAcc:
ui->label_unit_4->setText("mV / m/s^2");
break;
case kVibVelocity:
ui->label_unit_4->setText("mV / mm/s");
break;
case kVibThrust:
ui->label_unit_4->setText("mV / mil");
break;
}
}
void Seismic_monitor::on_pushButton_cancel_clicked() {
this->close();
}
void Seismic_monitor::on_comboBox_transducer_name_1_currentTextChanged(const QString &arg1) {
for (int var = 0; var < vec_transducer.size(); ++var) {
if (ui->comboBox_transducer_name_1->currentText() == vec_transducer[var].transducer_name) {
ui->doubleSpinBox_scale_factor_1->setValue(vec_transducer[var].scale_factor);
}
}
}
void Seismic_monitor::on_comboBox_transducer_name_2_currentTextChanged(const QString &arg1) {
for (int var = 0; var < vec_transducer.size(); ++var) {
if (ui->comboBox_transducer_name_2->currentText() == vec_transducer[var].transducer_name) {
ui->doubleSpinBox_scale_factor_2->setValue(vec_transducer[var].scale_factor);
}
}
}
void Seismic_monitor::on_comboBox_transducer_name_3_currentTextChanged(const QString &arg1) {
for (int var = 0; var < vec_transducer.size(); ++var) {
if (ui->comboBox_transducer_name_3->currentText() == vec_transducer[var].transducer_name) {
ui->doubleSpinBox_scale_factor_3->setValue(vec_transducer[var].scale_factor);
}
}
}
void Seismic_monitor::on_comboBox_transducer_name_4_currentTextChanged(const QString &arg1) {
for (int var = 0; var < vec_transducer.size(); ++var) {
if (ui->comboBox_transducer_name_4->currentText() == vec_transducer[var].transducer_name) {
ui->doubleSpinBox_scale_factor_4->setValue(vec_transducer[var].scale_factor);
}
}
}
void Seismic_monitor::EnableKeyphase(){
ui->checkBox_keyphase->setCheckable(true);
ui->checkBox_keyphase->setEnabled(true);
ui->comboBox_keyphase_ch->setEnabled(true);
ui->comboBox_keyphase_slot->setEnabled(true);
ui->checkBox_keyphase_2->setCheckable(true);
ui->checkBox_keyphase_2->setEnabled(true);
ui->comboBox_keyphase_ch_2->setEnabled(true);
ui->comboBox_keyphase_slot_2->setEnabled(true);
ui->checkBox_keyphase_3->setCheckable(true);
ui->checkBox_keyphase_3->setEnabled(true);
ui->comboBox_keyphase_ch_3->setEnabled(true);
ui->comboBox_keyphase_slot_3->setEnabled(true);
ui->checkBox_keyphase_4->setCheckable(true);
ui->checkBox_keyphase_4->setEnabled(true);
ui->comboBox_keyphase_ch_4->setEnabled(true);
ui->comboBox_keyphase_slot_4->setEnabled(true);
}
void Seismic_monitor::DisableKeyphase(){
ui->checkBox_keyphase->setCheckable(false);
ui->checkBox_keyphase->setEnabled(false);
ui->comboBox_keyphase_ch->setEnabled(false);
ui->comboBox_keyphase_slot->setEnabled(false);
ui->checkBox_keyphase_2->setCheckable(false);
ui->checkBox_keyphase_2->setEnabled(false);
ui->comboBox_keyphase_ch_2->setEnabled(false);
ui->comboBox_keyphase_slot_2->setEnabled(false);
ui->checkBox_keyphase_3->setCheckable(false);
ui->checkBox_keyphase_3->setEnabled(false);
ui->comboBox_keyphase_ch_3->setEnabled(false);
ui->comboBox_keyphase_slot_3->setEnabled(false);
ui->checkBox_keyphase_4->setCheckable(false);
ui->checkBox_keyphase_4->setEnabled(false);
ui->comboBox_keyphase_ch_4->setEnabled(false);
ui->comboBox_keyphase_slot_4->setEnabled(false);
}