2025-07-31 19:38:06 +08:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include "diagramEditor/diagramEditorTransSettingDlg.h"
|
|
|
|
|
#include "diagramEditor/diagramEditorWizard.h"
|
|
|
|
|
#include "diagramEditor/diagramEditorBaseBlock.h"
|
|
|
|
|
#include "ui_diagramEditorTransSettingDlg.h"
|
|
|
|
|
#include "diagramEditor/diagramEditorStructContainer.h"
|
|
|
|
|
#include "diagramEditor/wizardBayContentDlg.h"
|
|
|
|
|
|
|
|
|
|
DiagramEditorTransSettingDlg::DiagramEditorTransSettingDlg(QWidget *parent)
|
|
|
|
|
: QDialog(parent)
|
|
|
|
|
, ui(new Ui::diagramEditorTransSettingDlg)
|
|
|
|
|
,_curOperateBlock(nullptr)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
|
|
|
|
|
this->setWindowModality(Qt::WindowModal);
|
|
|
|
|
initial();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DiagramEditorTransSettingDlg::~DiagramEditorTransSettingDlg()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiagramEditorTransSettingDlg::showDlg()
|
|
|
|
|
{
|
|
|
|
|
_curModel = 0;
|
|
|
|
|
show();
|
|
|
|
|
addNewTrans();
|
|
|
|
|
if(_pWizard){
|
|
|
|
|
ui->le_name->setText("#主变");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiagramEditorTransSettingDlg::showDlg(DiagramEditorTransformerBlock* p)
|
|
|
|
|
{
|
|
|
|
|
_curModel = 1;
|
|
|
|
|
if(_curOperateBlock == nullptr)
|
|
|
|
|
_curOperateBlock = p;
|
|
|
|
|
show();
|
|
|
|
|
addNewTrans();
|
|
|
|
|
if(_pWizard){
|
|
|
|
|
ui->le_name->setText(p->getName());
|
|
|
|
|
if(p){
|
|
|
|
|
auto lstCon = p->getConnect();
|
2025-08-15 18:21:20 +08:00
|
|
|
/*QStringList lst;
|
2025-08-06 20:10:10 +08:00
|
|
|
for(auto& conId:lstCon){
|
|
|
|
|
if(_pWizard->getConnection().contains(conId)){
|
|
|
|
|
auto con = _pWizard->getConnection().value(conId);
|
|
|
|
|
QString sOpposite = con.getOppositeName(p->getName());
|
|
|
|
|
lst.append(sOpposite);
|
|
|
|
|
}
|
2025-07-31 19:38:06 +08:00
|
|
|
}
|
2025-08-15 18:21:20 +08:00
|
|
|
ui->listWidget->addItems(lst);*/
|
|
|
|
|
|
|
|
|
|
for(auto& conId:lstCon){
|
|
|
|
|
if(_pWizard->getConnection().contains(conId)){
|
|
|
|
|
auto con = _pWizard->getConnection().value(conId);
|
2025-09-12 17:28:47 +08:00
|
|
|
QString sOpposite = con.getOpposite(p->getName()).sName;
|
2025-08-15 18:21:20 +08:00
|
|
|
|
|
|
|
|
QString sPos;
|
|
|
|
|
if(con.nPara == 0){
|
|
|
|
|
sPos = "高压侧";
|
|
|
|
|
}
|
|
|
|
|
else if(con.nPara == 1){
|
|
|
|
|
sPos = "中压侧";
|
|
|
|
|
}
|
|
|
|
|
else if(con.nPara == 2){
|
|
|
|
|
sPos = "低压侧";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int row = ui->tableWidget->rowCount();
|
|
|
|
|
ui->tableWidget->insertRow(row);
|
|
|
|
|
|
|
|
|
|
//名称
|
|
|
|
|
QTableWidgetItem* nameItem = new QTableWidgetItem(sOpposite);
|
|
|
|
|
ui->tableWidget->setItem(row, 0, nameItem);
|
|
|
|
|
|
|
|
|
|
//位置
|
|
|
|
|
QTableWidgetItem* posItem = new QTableWidgetItem(sPos);
|
|
|
|
|
ui->tableWidget->setItem(row, 1, posItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-31 19:38:06 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiagramEditorTransSettingDlg::addNewTrans()
|
|
|
|
|
{
|
|
|
|
|
ui->cb_type->setCurrentIndex(0);
|
|
|
|
|
ui->cb_level->clear();
|
|
|
|
|
ui->cb_target->clear();
|
2025-08-15 18:21:20 +08:00
|
|
|
ui->tableWidget->clearContents();
|
|
|
|
|
ui->tableWidget->setRowCount(0);
|
2025-07-31 19:38:06 +08:00
|
|
|
if(_pWizard){
|
2025-08-06 20:10:10 +08:00
|
|
|
auto mapAllCon = _pWizard->getContainerStruct();
|
2025-07-31 19:38:06 +08:00
|
|
|
for(auto iter = mapAllCon.begin();iter != mapAllCon.end();++iter){
|
|
|
|
|
if(iter.key() == g_transformerLevel)
|
|
|
|
|
continue;
|
|
|
|
|
ui->cb_level->addItem("第"+QString::number(iter.key()+1)+"层",iter.key());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiagramEditorTransSettingDlg::initial()
|
|
|
|
|
{
|
|
|
|
|
_curModel = 0;
|
|
|
|
|
connect(ui->btn_add,&QPushButton::clicked,this,&DiagramEditorTransSettingDlg::onAddClicked);
|
|
|
|
|
connect(ui->btn_delete,&QPushButton::clicked,this,&DiagramEditorTransSettingDlg::onDeleteClicked);
|
|
|
|
|
connect(ui->btn_ok,&QPushButton::clicked,this,&DiagramEditorTransSettingDlg::onOkClicked);
|
|
|
|
|
connect(ui->btn_cancel,&QPushButton::clicked,this,&DiagramEditorTransSettingDlg::onCancelClicked);
|
|
|
|
|
connect(ui->cb_level,&QComboBox::currentTextChanged,this,&DiagramEditorTransSettingDlg::onConnectLevelChanged);
|
|
|
|
|
connect(ui->cb_bayType,&QComboBox::currentIndexChanged,this,&DiagramEditorTransSettingDlg::onBayTypeChanged);
|
|
|
|
|
ui->cb_bayType->setItemData(0,3); //将类型与item关联
|
|
|
|
|
ui->cb_bayType->setItemData(1,4);
|
2025-08-15 18:21:20 +08:00
|
|
|
|
|
|
|
|
QStringList headerText;
|
|
|
|
|
headerText<<"间隔名称"<<"连接对象";
|
|
|
|
|
ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
ui->tableWidget->setColumnCount(headerText.count());
|
|
|
|
|
ui->tableWidget->setHorizontalHeaderLabels(headerText);
|
|
|
|
|
ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
|
|
|
ui->tableWidget->verticalHeader()->setVisible(false);
|
2025-07-31 19:38:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiagramEditorTransSettingDlg::onAddClicked()
|
|
|
|
|
{
|
|
|
|
|
QString str = ui->cb_target->currentText();
|
2025-08-15 18:21:20 +08:00
|
|
|
|
|
|
|
|
for(int i = 0;i < ui->tableWidget->rowCount();++i){
|
|
|
|
|
QString sName = ui->tableWidget->item(i,0)->text();
|
|
|
|
|
if(str == sName)
|
|
|
|
|
return;
|
2025-07-31 19:38:06 +08:00
|
|
|
}
|
2025-08-15 18:21:20 +08:00
|
|
|
|
|
|
|
|
int row = ui->tableWidget->rowCount();
|
|
|
|
|
ui->tableWidget->insertRow(row);
|
|
|
|
|
|
|
|
|
|
//名称
|
|
|
|
|
QTableWidgetItem* nameItem = new QTableWidgetItem(str);
|
|
|
|
|
ui->tableWidget->setItem(row, 0, nameItem);
|
|
|
|
|
|
|
|
|
|
//位置
|
|
|
|
|
QTableWidgetItem* posItem = new QTableWidgetItem(ui->cb_toPos->currentText());
|
|
|
|
|
ui->tableWidget->setItem(row, 1, posItem);
|
2025-07-31 19:38:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiagramEditorTransSettingDlg::onDeleteClicked()
|
|
|
|
|
{
|
2025-08-15 18:21:20 +08:00
|
|
|
// 获取当前选中的索引
|
|
|
|
|
QModelIndexList selectedIndexes = ui->tableWidget->selectionModel()->selectedRows();
|
|
|
|
|
if (selectedIndexes.isEmpty()) {
|
|
|
|
|
return; // 没有选中任何行
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取当前选中的第一项索引
|
|
|
|
|
QModelIndex index = selectedIndexes.first();
|
|
|
|
|
if (!index.isValid()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex indexName = index.sibling(index.row(),0);
|
|
|
|
|
/*QString sName = indexName.data().toString();
|
|
|
|
|
if(_pWizard){
|
|
|
|
|
//delete con?
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
int currentRow = ui->tableWidget->currentRow();
|
|
|
|
|
if (currentRow == -1) {
|
|
|
|
|
return; // 没有选中行
|
2025-07-31 19:38:06 +08:00
|
|
|
}
|
2025-08-15 18:21:20 +08:00
|
|
|
|
|
|
|
|
ui->tableWidget->removeRow(currentRow);
|
2025-07-31 19:38:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiagramEditorTransSettingDlg::onOkClicked()
|
|
|
|
|
{
|
|
|
|
|
QString sName = ui->le_name->text();
|
|
|
|
|
TransformerType nType = TransformerType(ui->cb_type->currentIndex());
|
|
|
|
|
if(_curModel == 0){
|
|
|
|
|
auto lstBlock = _pWizard->getTargetLevelBlocks(g_transformerLevel,3);
|
|
|
|
|
for(auto bay:lstBlock)
|
|
|
|
|
{
|
|
|
|
|
if(bay->getName() == sName){ //判断间隔存在
|
|
|
|
|
QMessageBox::information(NULL, QString("提示"), QString::fromWCharArray(L"变压器已存在"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-15 18:21:20 +08:00
|
|
|
QList<EditorTransConnection> lst;
|
|
|
|
|
for(int i = 0;i < ui->tableWidget->rowCount();++i){
|
|
|
|
|
QString sPos = ui->tableWidget->item(i,1)->text();
|
|
|
|
|
int nVal = 0;
|
|
|
|
|
if(sPos == "高压侧"){
|
|
|
|
|
nVal = 0;
|
|
|
|
|
}
|
|
|
|
|
else if(sPos == "中压侧")
|
|
|
|
|
{
|
|
|
|
|
nVal = 1;
|
|
|
|
|
}
|
|
|
|
|
else if(sPos == "低压侧")
|
|
|
|
|
{
|
|
|
|
|
nVal = 2;
|
|
|
|
|
}
|
|
|
|
|
EditorTransConnection con;
|
|
|
|
|
con.sName = ui->tableWidget->item(i,0)->text();
|
|
|
|
|
con.nPara = nVal;
|
|
|
|
|
lst.append(con);
|
2025-07-31 19:38:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DiagramEditorWizardTransformerInfo info;
|
|
|
|
|
info.sName = sName;
|
|
|
|
|
info.nType = nType;
|
|
|
|
|
info.lstBindObj = lst;
|
|
|
|
|
|
|
|
|
|
_pWizard->onAddTransFinished(info);
|
|
|
|
|
}
|
|
|
|
|
else if(_curModel == 1){
|
|
|
|
|
if(_curOperateBlock){
|
|
|
|
|
_curOperateBlock->setName(sName);
|
|
|
|
|
_curOperateBlock->setTransType(nType);
|
|
|
|
|
_curOperateBlock->clearConnect();
|
|
|
|
|
|
2025-08-15 18:21:20 +08:00
|
|
|
for(int i = 0;i < ui->tableWidget->rowCount();++i){
|
|
|
|
|
QString sPos = ui->tableWidget->item(i,1)->text();
|
|
|
|
|
int nVal = 0;
|
|
|
|
|
if(sPos == "高压侧"){
|
|
|
|
|
nVal = 0;
|
|
|
|
|
}
|
|
|
|
|
else if(sPos == "中压侧")
|
|
|
|
|
{
|
|
|
|
|
nVal = 1;
|
|
|
|
|
}
|
|
|
|
|
else if(sPos == "低压侧")
|
|
|
|
|
{
|
|
|
|
|
nVal = 2;
|
|
|
|
|
}
|
|
|
|
|
QUuid uid = _pWizard->addConnection(_curOperateBlock->getName(),ui->tableWidget->item(i,0)->text(),3,2,nVal);
|
2025-08-06 20:10:10 +08:00
|
|
|
_curOperateBlock->addConnect(uid);
|
2025-07-31 19:38:06 +08:00
|
|
|
}
|
2025-08-15 18:21:20 +08:00
|
|
|
//todo: may delete
|
2025-07-31 19:38:06 +08:00
|
|
|
|
|
|
|
|
_pWizard->flushTransPage();
|
|
|
|
|
_curOperateBlock = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiagramEditorTransSettingDlg::onCancelClicked()
|
|
|
|
|
{
|
|
|
|
|
hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiagramEditorTransSettingDlg::onConnectLevelChanged(const QString& str)
|
|
|
|
|
{
|
|
|
|
|
if(_pWizard){
|
|
|
|
|
int n = ui->cb_level->findText(str);
|
|
|
|
|
BayType nType = BayType(ui->cb_bayType->currentData().toInt());
|
|
|
|
|
if(n != -1){
|
|
|
|
|
ui->cb_target->clear();
|
|
|
|
|
int nIndex = ui->cb_level->itemData(n).toInt();
|
|
|
|
|
auto lstBlock = _pWizard->getTargetLevelBlocks(nIndex,2);
|
|
|
|
|
for(auto& block:lstBlock){
|
|
|
|
|
auto pBay = dynamic_cast<DiagramEditorBayBlock*>(block);
|
|
|
|
|
if(pBay){
|
|
|
|
|
BayType tpe = pBay->getBayType();
|
|
|
|
|
if(nType == tpe)
|
|
|
|
|
ui->cb_target->addItem(pBay->getName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiagramEditorTransSettingDlg::onBayTypeChanged(int idx)
|
|
|
|
|
{
|
|
|
|
|
BayType nType = BayType(ui->cb_bayType->currentData().toInt());
|
|
|
|
|
int n = ui->cb_level->currentIndex();
|
|
|
|
|
if(n != -1){
|
|
|
|
|
ui->cb_target->clear();
|
|
|
|
|
int nIndex = ui->cb_level->itemData(n).toInt();
|
|
|
|
|
auto lstBlock = _pWizard->getTargetLevelBlocks(nIndex,2);
|
|
|
|
|
for(auto& block:lstBlock){
|
|
|
|
|
auto pBay = dynamic_cast<DiagramEditorBayBlock*>(block);
|
|
|
|
|
if(pBay){
|
|
|
|
|
BayType tpe = pBay->getBayType();
|
|
|
|
|
if(nType == tpe)
|
|
|
|
|
ui->cb_target->addItem(pBay->getName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|