DialogGoto.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #include "DialogGoto.h"
  2. #include "Common.h"
  3. #include "DialogGotoSelection.h"
  4. #include "Pou.h"
  5. DialogGoto::DialogGoto(
  6. const POU* pou,
  7. const TOOL* pGoto,
  8. const QString& selToolName,
  9. bool bNegation,
  10. QWidget *parent
  11. )
  12. : QDialog(parent)
  13. , m_pou(pou)
  14. , m_bNegation(bNegation)
  15. , m_gotoTool(pGoto)
  16. , m_selToolInstName(selToolName)
  17. {
  18. ui.setupUi(this);
  19. // 对话框初始化
  20. this->initUI();
  21. }
  22. DialogGoto::~DialogGoto()
  23. {
  24. }
  25. /// <summary>
  26. /// 对话框初始化
  27. /// </summary>
  28. void DialogGoto::initUI()
  29. {
  30. this->setWindowTitle(("Goto Option"));
  31. // 设置对话框风格
  32. this->setAttribute(Qt::WA_QuitOnClose);
  33. this->setWindowModality(Qt::ApplicationModal);
  34. // 初始化绑定显示
  35. ui.editTool->setText(m_selToolInstName);
  36. // 设置Edit控件不可编辑
  37. ui.editTool->setReadOnly(true);
  38. // 初始化取反的选中状态
  39. ui.checkBool->setChecked(m_bNegation);
  40. // 槽函数
  41. connect(ui.okButton, SIGNAL(clicked()), this, SLOT(onButtonOKClicked()));
  42. connect(ui.buttonTool, SIGNAL(clicked()), this, SLOT(onButtonToolClicked()));
  43. connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
  44. // 设置固定窗体大小
  45. this->setFixedSize(363, 216);
  46. }
  47. /// <summary>
  48. /// OK按钮
  49. /// </summary>
  50. void DialogGoto::onButtonOKClicked()
  51. {
  52. if (ui.editTool->text().isEmpty())
  53. {
  54. CRITICAL_MESSAGE("Please select tool first!");
  55. return;
  56. }
  57. // 获取用户输入
  58. m_selToolInstName = ui.editTool->text();
  59. m_bNegation = ui.checkBool->isChecked();
  60. // 检查一下是否死循环,给予用户提示
  61. // NOTICE:此处只能检查当前状态是否处于死循环,如果POU中调整了工具Index顺序,可能死循环就消失了
  62. if (checkInfiniteLoop())
  63. {
  64. if (QMessageBox::Yes != QUESTION_MESSAGE(
  65. "There is an infinite loop with tool[" + m_selToolInstName + "], are you sure?")
  66. )
  67. {
  68. return;
  69. }
  70. }
  71. this->accept();
  72. }
  73. /// <summary>
  74. /// ... 按钮
  75. /// </summary>
  76. void DialogGoto::onButtonToolClicked()
  77. {
  78. // (2022 - 4 - 18, Goto的工具绑定选择对话框废弃,统一通过连线来绑定Tool)
  79. //DialogGotoSelection dialogGotoSel(m_pou);
  80. //if (dialogGotoSel.exec() == DialogGoto::Accepted)
  81. //{
  82. // // 获取用户选择的Tool信息
  83. // ui.editTool->setText(dialogGotoSel.m_selToolInstName);
  84. //}
  85. CRITICAL_MESSAGE("Goto Tool Selection is deprecated, please binding tool with LINK!");
  86. }
  87. /// <summary>
  88. /// 进行死循环检测
  89. /// </summary>
  90. /// <param name="selToolName"></param>
  91. /// <returns></returns>
  92. bool DialogGoto::checkInfiniteLoop()
  93. {
  94. const TOOL* pBindTool = (const_cast<POU*>(m_pou))->GetToolByName(m_selToolInstName);
  95. // 如果连接的工具序号比当前Goto工具的小,那么说明会出现死循环的情况
  96. if( pBindTool->nIndex<m_gotoTool->nIndex)
  97. {
  98. return true;
  99. }
  100. // 不存在死循环
  101. return false;
  102. }