#include "seismic_monitor.h" #include "ui_seismic_monitor.h" #include #include #include #include #include #include #include "acceleration.h" #include "velocity.h" #include "radial_vibration.h" #include "data_config.h" #include "config_mgr.h" #include "vibrationdata.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); 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); // } std::shared_ptr 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 vib_data = std::make_shared(); vib_data->slot_ = slot_no; vib_data->card_type_ = car_type; ConfigMgr::Instance()->AddCard(vib_data); UpdateData(vib_data); return; } std::shared_ptr vib_data = std::dynamic_pointer_cast(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 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')); } 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')); } 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')); } 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')); } } } void Seismic_monitor::on_pushButton_confirm_clicked() { std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); if (base_ptr == nullptr) { qCritical() << " should not be here"; // std::shared_ptr vib_data = std::make_shared(); // ConfigMgr::Instance()->AddCard(vib_data); // UpdateData(vib_data); return; } std::shared_ptr vib_data = std::dynamic_pointer_cast(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(); } } 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(); } } 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(); } } 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(); } } 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; } } void Seismic_monitor::on_comboBox_chan_type_2_currentTextChanged(const QString &arg1) { switch (ui->comboBox_chan_type_1->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; } } void Seismic_monitor::on_comboBox_chan_type_3_currentTextChanged(const QString &arg1) { switch (ui->comboBox_chan_type_1->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; } } void Seismic_monitor::on_comboBox_chan_type_4_currentTextChanged(const QString &arg1) { switch (ui->comboBox_chan_type_1->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; } } 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); } } }