123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- #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()
- {
- }
- /// <summary>
- /// 对话框初始化
- /// </summary>
- 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);
- }
- /// <summary>
- /// OK按钮
- /// </summary>
- 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();
- }
- /// <summary>
- /// ... 按钮
- /// </summary>
- 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!");
- }
- /// <summary>
- /// 进行死循环检测
- /// </summary>
- /// <param name="selToolName"></param>
- /// <returns></returns>
- bool DialogGoto::checkInfiniteLoop()
- {
- const TOOL* pBindTool = (const_cast<POU*>(m_pou))->GetToolByName(m_selToolInstName);
- // 如果连接的工具序号比当前Goto工具的小,那么说明会出现死循环的情况
- if( pBindTool->nIndex<m_gotoTool->nIndex)
- {
- return true;
- }
- // 不存在死循环
- return false;
- }
|