TSI_Config/velocity.cpp

131 lines
4.9 KiB
C++

#include "velocity.h"
#include "ui_velocity.h"
#include <QDebug>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include <QFile>
#include "velocity_ds.h"
#include "data_config.h"
#include "vibrationdata.h"
#include "config_mgr.h"
Velocity::Velocity(int slot_no_, int channel_, bool active, QWidget *parent)
: QWidget(parent)
, ui(new Ui::Velocity) {
ui->setupUi(this);
slot_no = slot_no_;
channel = channel_;
QString chan = QString("%1").arg(channel);
QString slot = QString("%1").arg(slot_no);
ui->label_channel->setText(chan);
ui->label_slot->setText(slot);
if (active) {
ui->label_active->setText("(启用)");
} else {
ui->label_active->setText("(停用)");
}
Init();
}
Velocity::~Velocity() {
delete ui;
}
void Velocity::on_checkBox_rms_toggled(bool checked) {
// TODO: 自定义的回调
}
void Velocity::on_checkBox_integrate_toggled(bool checked) {
// TODO: 自定义的回调
}
void Velocity::on_pushButton_cancel_clicked() {
this->close();
}
void Velocity::on_checkBox_1x_ampl_toggled(bool checked) {
}
void Velocity::on_checkBox_2x_ampl_toggled(bool checked) {
}
void Velocity::Init() {
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
if (base_ptr == nullptr) {
qCritical() << "[Velocity::Init] should not be here";
return;
}
std::shared_ptr<VibrationData> ptr = std::dynamic_pointer_cast<VibrationData>(base_ptr);
if (ptr->base_config_[channel - 1].channel_type != kVibVelocity) {
qDebug() << "[Velocity::Init] channel type changes";
return;
}
std::shared_ptr<VariableBase> variable_base = ptr->GetChannelPtr(channel);
if (variable_base == nullptr) {
qDebug() << "[Velocity::Init] no channel ptr";
return;
}
std::shared_ptr<AccVelVariable> variable_ptr = std::dynamic_pointer_cast<AccVelVariable>(variable_base);
ui->checkBox_low_pass->setChecked(variable_ptr->filter_[0].checked);
ui->spinBox_low_pass_low->setValue(variable_ptr->filter_[0].low);
ui->spinBox_low_pass_high->setValue(variable_ptr->filter_[0].high);
ui->checkBox_high_pass->setChecked(variable_ptr->filter_[1].checked);
ui->spinBox_high_pass_low->setValue(variable_ptr->filter_[1].low);
ui->spinBox_high_pass_high->setValue(variable_ptr->filter_[1].high);
ui->checkBox_band_pass->setChecked(variable_ptr->filter_[2].checked);
ui->spinBox_band_pass_low->setValue(variable_ptr->filter_[2].low);
ui->spinBox_band_pass_high->setValue(variable_ptr->filter_[2].high);
}
void Velocity::on_pushButton_confirm_clicked() {
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
if (base_ptr == nullptr) {
qCritical() << "[Acceleration::Init] should not be here";
return;
}
std::shared_ptr<VibrationData> ptr = std::dynamic_pointer_cast<VibrationData>(base_ptr);
std::shared_ptr<VariableBase> variable_base = ptr->GetChannelPtr(channel);
if (variable_base == nullptr || variable_base->type_ != kVibVelocity) {
if (variable_base == nullptr) {
qDebug() << "no channel ptr";
} else {
ptr->RemoveChannel(channel);
qDebug() << "channel type change";
}
std::shared_ptr<AccVelVariable> variable = std::make_shared<AccVelVariable>();
variable->id_ = channel;
variable->type_ = kVibVelocity;
variable->filter_[0].checked = ui->checkBox_low_pass->isChecked();
variable->filter_[0].low = ui->spinBox_low_pass_low->value();
variable->filter_[0].high = ui->spinBox_low_pass_high->value();
variable->filter_[1].checked = ui->checkBox_high_pass->isChecked();
variable->filter_[1].low = ui->spinBox_high_pass_low->value();
variable->filter_[1].high = ui->spinBox_high_pass_high->value();
variable->filter_[2].checked = ui->checkBox_band_pass->isChecked();
variable->filter_[2].low = ui->spinBox_band_pass_low->value();
variable->filter_[2].high = ui->spinBox_band_pass_high->value();
ptr->variables_.push_back(variable);
this->close();
return;
}
std::shared_ptr<AccVelVariable> variable = std::dynamic_pointer_cast<AccVelVariable>(variable_base);
variable->filter_[0].checked = ui->checkBox_low_pass->isChecked();
variable->filter_[0].low = ui->spinBox_low_pass_low->value();
variable->filter_[0].high = ui->spinBox_low_pass_high->value();
variable->filter_[1].checked = ui->checkBox_high_pass->isChecked();
variable->filter_[1].low = ui->spinBox_high_pass_low->value();
variable->filter_[1].high = ui->spinBox_high_pass_high->value();
variable->filter_[2].checked = ui->checkBox_band_pass->isChecked();
variable->filter_[2].low = ui->spinBox_band_pass_low->value();
variable->filter_[2].high = ui->spinBox_band_pass_high->value();
this->close();
}