WindowAppBlockWait.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #include "WindowAppBlockWait.h"
  2. #include "DialogWait.h"
  3. #include "TaskManager.h"
  4. #include "GvlManager.h"
  5. WindowAppBlockWait::WindowAppBlockWait(TOOL* pNewTool, POU* Pou, bool bShowOnly /*= false*/, QGraphicsObject* parent /*= nullptr*/)
  6. : WindowAppBlockStandardBase(pNewTool, Pou, bShowOnly, parent)
  7. , m_selVariable(nullptr)
  8. , m_nTimeout(DEFAULT_WAIT_TIMEOUT)
  9. {
  10. // 更新矩形区域的尺寸
  11. this->updateRect();
  12. }
  13. WindowAppBlockWait::~WindowAppBlockWait()
  14. {
  15. }
  16. /// <summary>
  17. /// 添加接口(Wait工具需要添加两个ToolInerface以及两个输出接口)
  18. /// </summary>
  19. void WindowAppBlockWait::addItemInterfaces()
  20. {
  21. // 添加标准接口
  22. WindowAppBlockStandardBase::addItemInterfaces();
  23. // 添加ToolStart和ToolEnd接口
  24. WindowAppBlockStandardBase::addItemToolInterfaces();
  25. }
  26. /// <summary>
  27. /// 更新矩形区域的尺寸
  28. /// </summary>
  29. void WindowAppBlockWait::updateRect()
  30. {
  31. // 计算高度
  32. int blockHeight = WAIT_BASIC_HEIGHT;
  33. // 计算宽度
  34. int blockWidth = WAIT_BASIC_WIDTH;
  35. // 主体矩形区域
  36. blockRect.setRect(
  37. -blockWidth / 2,
  38. -blockHeight / 2,
  39. blockWidth,
  40. blockHeight
  41. );
  42. // 序号矩形区域
  43. blockIndexRect.setRect(
  44. blockRect.right() - TBD_INDEX_WIDTH,
  45. blockRect.top() - TBD_INDEX_HEIGHT / 2,
  46. TBD_INDEX_WIDTH,
  47. TBD_INDEX_HEIGHT
  48. );
  49. // 总体矩形边界
  50. blockBoundingRect.setRect(
  51. blockRect.left(),
  52. blockRect.top() - TBD_INDEX_HEIGHT / 2,
  53. blockRect.width() + TBD_SHADOW_COUNT * PEN_LINE_WIDTH,
  54. blockRect.height() + TBD_INDEX_HEIGHT / 2 + TBD_SHADOW_COUNT * PEN_LINE_WIDTH
  55. );
  56. }
  57. /// <summary>
  58. /// 根据Wait工具当前的事件绑定信息,初始化变量
  59. /// </summary>
  60. void WindowAppBlockWait::initVariable()
  61. {
  62. if (m_selVariable != nullptr)
  63. {
  64. return;
  65. }
  66. // 到TaskManager中查询ToolEvent信息
  67. ToolEvent* event = g_pTaskManager->getEventByTool(m_toolInfo);
  68. if (event == nullptr)
  69. {
  70. return;
  71. }
  72. QString groupName = event->groupName();
  73. QString name = event->name();
  74. // 如果确实绑定了Event,则此处重新到TaskManager注册一下
  75. if (!groupName.isEmpty() && !name.isEmpty())
  76. {
  77. // 首先检查是否是系统内置事件
  78. m_selVariable = g_pTaskManager->getSysEventByName(name);
  79. // 如果不是的话,再判断是否是某一个变量
  80. if (m_selVariable == nullptr)
  81. {
  82. // 转换成对应的Variable(此处不应该为空)
  83. m_selVariable = g_pGvlManager->getVariableByName(groupName, name);
  84. // 校验是否有异常
  85. if (m_selVariable == nullptr)
  86. {
  87. vDebug() << "[Error] Load event[" << groupName << "," << name << "] failed.";
  88. }
  89. }
  90. }
  91. }
  92. /// <summary>
  93. /// 双击弹出配置对话框
  94. /// </summary>
  95. /// <param name="event"></param>
  96. void WindowAppBlockWait::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
  97. {
  98. if (event->button() != Qt::LeftButton || m_bShowOnly == true)
  99. {
  100. return;
  101. }
  102. // 如果当前Tool已经绑定了事件,则提前初始化一下
  103. this->initVariable();
  104. // 弹出Wait设置对话框
  105. DialogWait dialogWait(m_selVariable, m_bSkipWait, &m_WaitValue, m_nTimeout);
  106. if (dialogWait.exec() != DialogWait::Accepted)
  107. {
  108. return;
  109. }
  110. // 保存用户设置的参数信息
  111. this->m_selVariable = dialogWait.m_selVariable;
  112. this->m_bSkipWait = dialogWait.m_bSkipWait;
  113. this->m_nTimeout = dialogWait.m_nTimeout;
  114. // 2022-9-26,将用户设定的等待值输出到WaitTool的0号接口中(值可能是nullptr)
  115. m_toolInfo->Interfaces[0]->value = m_WaitValue;
  116. // 到TaskManager中绑定用户选择的触发事件和Tool之间的关系
  117. g_pTaskManager->registerToolEvent(m_selVariable->eventTrigger, m_toolInfo);
  118. QGraphicsItem::mouseDoubleClickEvent(event);
  119. }