#include "DialogGoto.h" #include "Common.h" #include "DialogGotoSelection.h" #include "Pou.h" DialogGoto::DialogGoto( const POU* pou, const TOOL* pGoto, const QString& selToolName, bool bNegation, QWidget *parent ) : QDialog(parent) , m_pou(pou) , m_bNegation(bNegation) , m_gotoTool(pGoto) , m_selToolInstName(selToolName) { ui.setupUi(this); // 对话框初始化 this->initUI(); } DialogGoto::~DialogGoto() { } /// /// 对话框初始化 /// void DialogGoto::initUI() { this->setWindowTitle(("Goto Option")); // 设置对话框风格 this->setAttribute(Qt::WA_QuitOnClose); this->setWindowModality(Qt::ApplicationModal); // 初始化绑定显示 ui.editTool->setText(m_selToolInstName); // 设置Edit控件不可编辑 ui.editTool->setReadOnly(true); // 初始化取反的选中状态 ui.checkBool->setChecked(m_bNegation); // 槽函数 connect(ui.okButton, SIGNAL(clicked()), this, SLOT(onButtonOKClicked())); connect(ui.buttonTool, SIGNAL(clicked()), this, SLOT(onButtonToolClicked())); connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(reject())); // 设置固定窗体大小 this->setFixedSize(363, 216); } /// /// OK按钮 /// void DialogGoto::onButtonOKClicked() { if (ui.editTool->text().isEmpty()) { CRITICAL_MESSAGE("Please select tool first!"); return; } // 获取用户输入 m_selToolInstName = ui.editTool->text(); m_bNegation = ui.checkBool->isChecked(); // 检查一下是否死循环,给予用户提示 // NOTICE:此处只能检查当前状态是否处于死循环,如果POU中调整了工具Index顺序,可能死循环就消失了 if (checkInfiniteLoop()) { if (QMessageBox::Yes != QUESTION_MESSAGE( "There is an infinite loop with tool[" + m_selToolInstName + "], are you sure?") ) { return; } } this->accept(); } /// /// ... 按钮 /// void DialogGoto::onButtonToolClicked() { // (2022 - 4 - 18, Goto的工具绑定选择对话框废弃,统一通过连线来绑定Tool) //DialogGotoSelection dialogGotoSel(m_pou); //if (dialogGotoSel.exec() == DialogGoto::Accepted) //{ // // 获取用户选择的Tool信息 // ui.editTool->setText(dialogGotoSel.m_selToolInstName); //} CRITICAL_MESSAGE("Goto Tool Selection is deprecated, please binding tool with LINK!"); } /// /// 进行死循环检测 /// /// /// bool DialogGoto::checkInfiniteLoop() { const TOOL* pBindTool = (const_cast(m_pou))->GetToolByName(m_selToolInstName); // 如果连接的工具序号比当前Goto工具的小,那么说明会出现死循环的情况 if( pBindTool->nIndexnIndex) { return true; } // 不存在死循环 return false; }