From 3461aa9e4a1801b87c2bee52f0b5c9bcd1394d3a Mon Sep 17 00:00:00 2001 From: zhangsheng Date: Sat, 19 Apr 2025 19:54:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TSI_Config.pro | 2 ++ config_mgr.cpp | 38 ++++++++++++++------ data_config.h | 9 +++++ mainwindow.cpp | 2 -- singlerelay.cpp | 29 ++++++++++++++++ singlerelay.ui | 32 ++++++++--------- tmrrelayassociation.cpp | 77 ++++++++++++++++++++++++++++++++++++----- tmrrelayassociation.h | 2 ++ tmrrelayassociation.ui | 65 ++++++++++++++++++++-------------- 9 files changed, 193 insertions(+), 63 deletions(-) diff --git a/TSI_Config.pro b/TSI_Config.pro index 704e81f..642c3b5 100644 --- a/TSI_Config.pro +++ b/TSI_Config.pro @@ -30,6 +30,7 @@ SOURCES += \ tachometer.cpp \ tachometer_data.cpp \ tmrrelayassociation.cpp \ + tmrrelayassociation_data.cpp \ velocity.cpp \ vibrationdata.cpp @@ -57,6 +58,7 @@ HEADERS += \ tachometer.h \ tachometer_data.h \ tmrrelayassociation.h \ + tmrrelayassociation_data.h \ velocity.h \ velocity_ds.h \ vibrationdata.h diff --git a/config_mgr.cpp b/config_mgr.cpp index 35f255d..0836337 100644 --- a/config_mgr.cpp +++ b/config_mgr.cpp @@ -9,6 +9,7 @@ #include "tachometer_data.h" #include "keyphase_data.h" #include "singlerelay_data.h" +#include "tmrrelayassociation_data.h" #include @@ -282,10 +283,14 @@ void ConfigMgr::Save(QString & file_path) { std::shared_ptr ptr = std::dynamic_pointer_cast(base_ptr); channel_item.insert("logic_expression", ptr->single_relay_nok[ch].logic_expression); - }else if(card_type_[i] == kCardRelaySingle){ - - }else if(card_type_[i] == kCardRelayTMRPrimary){ - + }else if(card_type_[i] == kCardRelaySingle || card_type_[i] == kCardRelayTMRPrimary){ + std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot); + if (base_ptr == nullptr) { + continue; + } + std::shared_ptr ptr = std::dynamic_pointer_cast(base_ptr); + channel_item.insert("logic_expression", ptr->tmr_relay[ch].logic_expression); + channel_item.insert("sgcc_enable", ptr->tmr_relay[ch].sgcc_enable); } slot_item[QString::number(ch + 1)] = channel_item; } @@ -540,16 +545,27 @@ void ConfigMgr::Load(QString filename) { keyphase_data->variables_[j].events_per_revolution = channel["events_per_revolution"].toInt(); } cards_.push_back(keyphase_data); - }else if (card_type_[i] == kCardRelaySingleNOK || card_type_[i] == kCardRelayTMRPrimary || card_type_[i] == kCardRelaySingle){ - std::shared_ptr singlereay_data = std::make_shared(); - singlereay_data->slot_ = slot; - singlereay_data->card_type_ = static_cast(card_type_[i]); - singlereay_data->version_ = temp_obj["version"].toInt(); + }else if (card_type_[i] == kCardRelaySingleNOK ){ + std::shared_ptr singlerelay_data = std::make_shared(); + singlerelay_data->slot_ = slot; + singlerelay_data->card_type_ = static_cast(card_type_[i]); + singlerelay_data->version_ = temp_obj["version"].toInt(); for (int j = 0; j < RELAY_COUNT; ++j) { channel = temp_obj[QString::number(j + 1)].toObject(); - singlereay_data->single_relay_nok[j].logic_expression = channel["logic_expression"].toString(); + singlerelay_data->single_relay_nok[j].logic_expression = channel["logic_expression"].toString(); } - cards_.push_back(singlereay_data); + cards_.push_back(singlerelay_data); + }else if(card_type_[i] == kCardRelayTMRPrimary || card_type_[i] == kCardRelaySingle){ + std::shared_ptr relay_data = std::make_shared(); + relay_data->slot_ = slot; + relay_data->card_type_ = static_cast(card_type_[i]); + relay_data->version_ = temp_obj["version"].toInt(); + for (int j = 0; j < RELAY_COUNT; ++j) { + channel = temp_obj[QString::number(j + 1)].toObject(); + relay_data->tmr_relay[j].logic_expression = channel["logic_expression"].toString(); + relay_data->tmr_relay[j].sgcc_enable = channel["sgcc_enable"].toBool(); + } + cards_.push_back(relay_data); } } } diff --git a/data_config.h b/data_config.h index c4c75a5..b284173 100644 --- a/data_config.h +++ b/data_config.h @@ -274,6 +274,15 @@ typedef struct SingleRelayNOK_{ } } SingleRelayNOK; +typedef struct TMRRelay_{ + QString logic_expression; + bool sgcc_enable; + TMRRelay_(){ + logic_expression = ""; + sgcc_enable = false; + } +} TMRRelay; + #pragma pack(1) typedef struct { uint8_t head[3]; // 固定值:0xAA55AA diff --git a/mainwindow.cpp b/mainwindow.cpp index a3dc761..00ce3be 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -637,9 +637,7 @@ void MainWindow::on_pushButton_open_clicked() { qWarning() << "Failed to open update file."; return; } - ConfigMgr::Instance()->Load(filepath); - QList buttonList = btnGroup_slot->buttons(); for (int i = 0; i < buttonList.count(); i++) { std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(i + 1); diff --git a/singlerelay.cpp b/singlerelay.cpp index 22177d3..0251061 100644 --- a/singlerelay.cpp +++ b/singlerelay.cpp @@ -50,6 +50,34 @@ SingleRelay::~SingleRelay() { } void SingleRelay::Init(){ + QList buttonList = btnGroup_slot->buttons(); + for (int i = 1; i < buttonList.count() + 1; i++) { + std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(i); + if(base_ptr != nullptr){ + switch (base_ptr->card_type_) { + case kCardVibSingle :{ + buttonList[i - 1]->setText("振动"); + break; + } + case kCardKeyphaseSingle:{ + buttonList[i - 1]->setText("键相"); + break; + } + case kCardSpeedSingle:{ + buttonList[i - 1]->setText("转速"); + break; + } + case kCardRelaySingle: + case kCardRelaySingleNOK: + case kCardRelayTMRPrimary:{ + buttonList[i - 1]->setText("继电器"); + break; + } + default: + break; + } + } + } std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); if (base_ptr == nullptr) { // do nothing or use template to init it. @@ -60,6 +88,7 @@ void SingleRelay::Init(){ return; } single_relay_nok_data = std::dynamic_pointer_cast(base_ptr); + } void SingleRelay::on_pushButton_cancel_clicked() { this->close(); diff --git a/singlerelay.ui b/singlerelay.ui index 57f59c0..a1c8028 100644 --- a/singlerelay.ui +++ b/singlerelay.ui @@ -690,7 +690,7 @@ - PushButton + @@ -709,7 +709,7 @@ - PushButton + @@ -728,7 +728,7 @@ - PushButton + @@ -747,7 +747,7 @@ - PushButton + @@ -766,7 +766,7 @@ - PushButton + @@ -785,7 +785,7 @@ - PushButton + @@ -804,7 +804,7 @@ - PushButton + @@ -823,7 +823,7 @@ - PushButton + @@ -842,7 +842,7 @@ - PushButton + @@ -861,7 +861,7 @@ - PushButton + @@ -880,7 +880,7 @@ - PushButton + @@ -899,7 +899,7 @@ - PushButton + @@ -918,7 +918,7 @@ - PushButton + @@ -937,7 +937,7 @@ - PushButton + @@ -956,7 +956,7 @@ - PushButton + @@ -975,7 +975,7 @@ - PushButton + diff --git a/tmrrelayassociation.cpp b/tmrrelayassociation.cpp index b103b13..0044650 100644 --- a/tmrrelayassociation.cpp +++ b/tmrrelayassociation.cpp @@ -6,6 +6,7 @@ + TMRRelayAssociation::TMRRelayAssociation(int slot,int cardtype,QWidget *parent) : QDialog(parent) , ui(new Ui::TMRRelayAssociation) @@ -65,6 +66,45 @@ TMRRelayAssociation::~TMRRelayAssociation() delete ui; } void TMRRelayAssociation::Init(){ + QList buttonList = btnGroup_slot->buttons(); + for (int i = 1; i < buttonList.count() + 1; i++) { + std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(i); + if(base_ptr != nullptr){ + switch (base_ptr->card_type_) { + case kCardVibSingle :{ + buttonList[i - 1]->setText("振动"); + break; + } + case kCardKeyphaseSingle:{ + buttonList[i - 1]->setText("键相"); + break; + } + case kCardSpeedSingle:{ + buttonList[i - 1]->setText("转速"); + break; + } + case kCardRelaySingle: + case kCardRelaySingleNOK: + case kCardRelayTMRPrimary:{ + buttonList[i - 1]->setText("继电器"); + break; + } + default: + break; + } + } + } + std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); + if (base_ptr == nullptr) { + // do nothing or use template to init it. + relay_data = std::make_shared(); + relay_data->card_type_ = car_type; + relay_data->slot_ = slot_no; + ConfigMgr::Instance()->AddCard(relay_data); + return; + } + relay_data = std::dynamic_pointer_cast(base_ptr); + setExpressionToTreeView(treeView_relay, relay_data->tmr_relay[current_index].logic_expression); } ExprNode* TMRRelayAssociation::parseExpression(const QString& expr, int& pos) { @@ -128,13 +168,12 @@ QStandardItem* TMRRelayAssociation::buildItemTree(ExprNode* node) { } void TMRRelayAssociation::setExpressionToTreeView(QTreeView* treeView, const QString& expr) { int pos = 0; + model_Relay->clear(); ExprNode* root = parseExpression(expr, pos); QStandardItem* rootItem = buildItemTree(root); - QStandardItemModel* model = new QStandardItemModel(); - model->appendRow(rootItem); - treeView->setModel(model); - treeView->expandAll(); + model_Relay->appendRow(rootItem); + treeView_relay->expandAll(); } QString TMRRelayAssociation::buildLogicExpression(QStandardItem *item) { if (!item) return ""; @@ -294,17 +333,39 @@ void TMRRelayAssociation::on_pushButton_confirm_clicked() for (int i = 0; i < root->rowCount(); ++i) { QStandardItem *topItem = root->child(i); QString expr = buildLogicExpression(topItem); - if (!finalExpr.isEmpty()) { - finalExpr += " OR "; - } +// if (!finalExpr.isEmpty()) { +// finalExpr += " OR "; +// } finalExpr += expr; } - + relay_data->tmr_relay[current_index].logic_expression = finalExpr; + relay_data->tmr_relay[current_index].sgcc_enable = ui->checkBox_sgcc->checkState(); qDebug() << "逻辑表达式:" << finalExpr; this->close(); } void TMRRelayAssociation::onComboBoxIndexChanged(int index){ + QStandardItemModel *model = qobject_cast(treeView_relay->model()); + if (!model) return; + QStandardItem *root = model->invisibleRootItem(); + QString finalExpr; + for (int i = 0; i < root->rowCount(); ++i) { + QStandardItem *topItem = root->child(i); + QString expr = buildLogicExpression(topItem); +// if (!finalExpr.isEmpty()) { +// finalExpr += " OR "; +// } + finalExpr += expr; + } + relay_data->tmr_relay[current_index].logic_expression = finalExpr; + relay_data->tmr_relay[current_index].sgcc_enable = ui->checkBox_sgcc->checkState(); + current_index = index; + + if(relay_data->tmr_relay[index].logic_expression != "") + setExpressionToTreeView(treeView_relay, relay_data->tmr_relay[index].logic_expression); + else + model_Relay->clear(); + ui->checkBox_sgcc->setChecked(relay_data->tmr_relay[index].sgcc_enable); } void TMRRelayAssociation::on_pushButton_and_clicked() diff --git a/tmrrelayassociation.h b/tmrrelayassociation.h index 1f198ae..66c01c9 100644 --- a/tmrrelayassociation.h +++ b/tmrrelayassociation.h @@ -8,6 +8,7 @@ #include "config_mgr.h" #include //数据模型类 #include +#include "tmrrelayassociation_data.h" namespace Ui { class TMRRelayAssociation; @@ -85,6 +86,7 @@ private: int current_index; QTreeView *treeView_relay; QStandardItemModel *model_Relay; + std::shared_ptr relay_data = nullptr; void Init(); void buildTreeFromExpression(QTreeView *treeView, const QString &expr); diff --git a/tmrrelayassociation.ui b/tmrrelayassociation.ui index fc3e1eb..853d1a2 100644 --- a/tmrrelayassociation.ui +++ b/tmrrelayassociation.ui @@ -181,12 +181,12 @@ 告警驱动逻辑: - + - 230 + 110 540 - 551 + 691 31 @@ -197,8 +197,8 @@ - 520 - 590 + 450 + 580 71 32 @@ -211,7 +211,7 @@ 240 - 590 + 580 71 32 @@ -226,8 +226,8 @@ - 610 - 590 + 550 + 580 81 32 @@ -240,7 +240,7 @@ 350 - 590 + 580 71 32 @@ -262,7 +262,7 @@ NCT6100T - + 30 @@ -661,7 +661,7 @@ - PushButton + @@ -680,7 +680,7 @@ - PushButton + @@ -699,7 +699,7 @@ - PushButton + @@ -718,7 +718,7 @@ - PushButton + @@ -737,7 +737,7 @@ - PushButton + @@ -756,7 +756,7 @@ - PushButton + @@ -775,7 +775,7 @@ - PushButton + @@ -794,7 +794,7 @@ - PushButton + @@ -813,7 +813,7 @@ - PushButton + @@ -832,7 +832,7 @@ - PushButton + @@ -851,7 +851,7 @@ - PushButton + @@ -870,7 +870,7 @@ - PushButton + @@ -889,7 +889,7 @@ - PushButton + @@ -908,7 +908,7 @@ - PushButton + @@ -927,7 +927,7 @@ - PushButton + @@ -946,7 +946,7 @@ - PushButton + @@ -1014,6 +1014,19 @@ + + + + 30 + 550 + 71 + 16 + + + + 逻辑表达式: + +