#include "copy_channel.h" #include "ui_copy_channel.h" #include "data_config.h" #include "config_mgr.h" #include "vibrationdata.h" #include CopyChannel::CopyChannel(int slot_no_,QWidget *parent) : QWidget(parent), ui(new Ui::CopyChannel) { ui->setupUi(this); slot_no = slot_no_; radio_btn.reserve(4); check_ch.reserve(4); radio_btn.push_back(ui->radioButton_ch1); radio_btn.push_back(ui->radioButton_ch2); radio_btn.push_back(ui->radioButton_ch3); radio_btn.push_back(ui->radioButton_ch4); check_ch.push_back(ui->checkBox_ch1); check_ch.push_back(ui->checkBox_ch2); check_ch.push_back(ui->checkBox_ch3); check_ch.push_back(ui->checkBox_ch4); ui->checkBox_ch1->setEnabled(false); } CopyChannel::~CopyChannel() { delete ui; } void CopyChannel::on_radioButton_ch1_clicked(bool checked) { if(checked){ ui->checkBox_ch1->setChecked(false); ui->checkBox_ch1->setEnabled(false); } ui->checkBox_ch2->setEnabled(true); ui->checkBox_ch3->setEnabled(true); ui->checkBox_ch4->setEnabled(true); } void CopyChannel::on_radioButton_ch2_clicked(bool checked) { if(checked){ ui->checkBox_ch2->setChecked(false); ui->checkBox_ch2->setEnabled(false); } ui->checkBox_ch1->setEnabled(true); ui->checkBox_ch3->setEnabled(true); ui->checkBox_ch4->setEnabled(true); } void CopyChannel::on_radioButton_ch3_clicked(bool checked) { if(checked){ ui->checkBox_ch3->setChecked(false); ui->checkBox_ch3->setEnabled(false); } ui->checkBox_ch2->setEnabled(true); ui->checkBox_ch1->setEnabled(true); ui->checkBox_ch4->setEnabled(true); } void CopyChannel::on_radioButton_ch4_clicked(bool checked) { if(checked){ ui->checkBox_ch4->setChecked(false); ui->checkBox_ch4->setEnabled(false); } ui->checkBox_ch2->setEnabled(true); ui->checkBox_ch3->setEnabled(true); ui->checkBox_ch1->setEnabled(true); } void CopyChannel::on_pushButton_cancel_clicked() { this->close(); } void CopyChannel::on_pushButton_confirm_clicked() { int var = 0; for( ; var < 4; var ++){ if(radio_btn[var]->isChecked()) break; } std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); if (base_ptr == nullptr) { qDebug() << "base_ptr"; return; } std::shared_ptr vib_data = std::dynamic_pointer_cast(base_ptr); for (int i = 0; i < 4; i++) { if(i != var && check_ch[i]->isChecked()){ QString point_name = vib_data->base_config_[i].point_name; vib_data->base_config_[i] = vib_data->base_config_[var]; vib_data->base_config_[i].point_name = point_name; vib_data->dc_output[i] = vib_data->dc_output[var]; auto variable_base_old = vib_data->GetChannelPtr(var + 1); if(vib_data->base_config_[var].channel_type == kVibRadial){ std::shared_ptr variable = std::dynamic_pointer_cast(variable_base_old); std::shared_ptr variable_new = std::make_shared(); *variable_new = *variable; variable_new->id_ = i + 1; vib_data->RemoveChannel(i + 1); vib_data->InsertChannelPtr(variable_new); }else if(vib_data->base_config_[var].channel_type == kVibAcc || vib_data->base_config_[var].channel_type == kVibVelocity){ std::shared_ptr variable = std::dynamic_pointer_cast(variable_base_old); std::shared_ptr variable_new = std::make_shared(); *variable_new = *variable; variable_new->id_ = i + 1; vib_data->RemoveChannel(i + 1); vib_data->InsertChannelPtr(variable_new); }else if(vib_data->base_config_[var].channel_type == kVibThrust){ std::shared_ptr variable = std::dynamic_pointer_cast(variable_base_old); std::shared_ptr variable_new = std::make_shared(); *variable_new = *variable; variable_new->id_ = i + 1; vib_data->RemoveChannel(i + 1); vib_data->InsertChannelPtr(variable_new); }else if(vib_data->base_config_[var].channel_type == kVibPressurePulsation){ std::shared_ptr variable = std::dynamic_pointer_cast(variable_base_old); std::shared_ptr variable_new = std::make_shared(); *variable_new = *variable; variable_new->id_ = i + 1; vib_data->RemoveChannel(i + 1); vib_data->InsertChannelPtr(variable_new); } } } emit copy_end_sg(); this->close(); }