WindowAppBlockGoto.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #include "WindowAppBlockGoto.h"
  2. #include "DialogGoto.h"
  3. #include "Pou.h"
  4. #include "WindowAppPouScene.h"
  5. WindowAppBlockGoto::WindowAppBlockGoto(TOOL* pNewTool, POU* Pou, bool bShowOnly, QGraphicsObject* parent)
  6. : WindowAppBlockStandardBase(pNewTool, Pou, bShowOnly, parent)
  7. , m_bNegation(false)
  8. {
  9. m_bNegation = false;
  10. // 更新矩形区域的尺寸
  11. this->updateRect();
  12. m_pGotoInf = m_toolInfo->Interfaces[GOTO_OUTPUT_INDX];
  13. }
  14. WindowAppBlockGoto::~WindowAppBlockGoto()
  15. {
  16. }
  17. /// <summary>
  18. /// 双击弹出配置对话框
  19. /// </summary>
  20. /// <param name="event"></param>
  21. void WindowAppBlockGoto::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
  22. {
  23. if (event->button() != Qt::LeftButton || m_bShowOnly==true )
  24. {
  25. return;
  26. }
  27. // _INTERFACE* pGotoInf = m_toolInfo->Interfaces[GOTO_OUTPUT_INDX];
  28. // 初始化Goto设置对话框中的内容
  29. QString selToolName;
  30. _INTERFACE* pBindInf = m_pGotoInf->pBindInterface;
  31. if (pBindInf != nullptr)
  32. {
  33. selToolName = pBindInf->strName;
  34. }
  35. // 弹出Goto设置对话框
  36. DialogGoto dialogGoto(this->m_pPou, this->m_toolInfo, selToolName, m_bNegation);
  37. if (dialogGoto.exec() != DialogGoto::Accepted)
  38. {
  39. return;
  40. }
  41. // 执行输出接口的Tool绑定操作
  42. TOOL* pTool = this->m_pPou->GetToolByName(dialogGoto.m_selToolInstName);
  43. m_bNegation = dialogGoto.m_bNegation;
  44. // 绑定用户选择的工具
  45. this->bindOutputInterface(pTool);
  46. // 2022-4-7,此处增加Goto和绑定的ToolStart接口之间的Link
  47. // pTool->TopInterface->pUpLinkInterface = m_toolInfo->Interfaces[GOTO_OUTPUT_INDX];
  48. // 重绘本功能块,用于绑定接口文字的及时更新
  49. this->update();
  50. QGraphicsItem::mouseDoubleClickEvent(event);
  51. }
  52. /// <summary>
  53. /// 绘制Goto控件
  54. /// </summary>
  55. /// <param name="painter"></param>
  56. /// <param name="option"></param>
  57. /// <param name="widget"></param>
  58. void WindowAppBlockGoto::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
  59. {
  60. // WindowAppBlockStandardBase::paint(painter, option, widget);
  61. Q_UNUSED(option);
  62. Q_UNUSED(widget);
  63. painter->save();
  64. painter->setRenderHint(QPainter::Antialiasing, true);
  65. // 绘制功能块
  66. this->DrawBlock(painter);
  67. // 绘制索引号
  68. WindowAppBlockStandardBase::DrawIndex(painter);
  69. painter->restore();
  70. }
  71. /// <summary>
  72. /// 绘制功能块
  73. /// </summary>
  74. /// <param name="painter"></param>
  75. void WindowAppBlockGoto::DrawBlock(QPainter* painter)
  76. {
  77. // 调用基类绘制功能块(不绘制实例名)
  78. WindowAppBlockStandardBase::DrawBlock(painter, false);
  79. }
  80. /// <summary>
  81. /// 更新矩形区域的尺寸
  82. /// </summary>
  83. void WindowAppBlockGoto::updateRect()
  84. {
  85. // 计算高度
  86. int blockHeight = GBD_BASIC_HEIGHT;
  87. // 计算宽度
  88. int blockWidth = GBD_BASIC_WIDTH;
  89. // 主体矩形区域
  90. blockRect.setRect(
  91. -blockWidth / 2,
  92. -blockHeight / 2,
  93. blockWidth,
  94. blockHeight
  95. );
  96. // 序号矩形区域
  97. blockIndexRect.setRect(
  98. blockRect.right() - TBD_INDEX_WIDTH,
  99. blockRect.top() - TBD_INDEX_HEIGHT / 2,
  100. TBD_INDEX_WIDTH,
  101. TBD_INDEX_HEIGHT
  102. );
  103. // 总体矩形边界(未计算Interface的范围)
  104. blockBoundingRect.setRect(
  105. blockRect.left(),
  106. blockRect.top() - TBD_INDEX_HEIGHT / 2,
  107. blockRect.width() + TBD_SHADOW_COUNT * PEN_LINE_WIDTH,
  108. blockRect.height() + TBD_INDEX_HEIGHT / 2 + TBD_SHADOW_COUNT * PEN_LINE_WIDTH
  109. );
  110. }
  111. /// <summary>
  112. /// 绑定输出接口(注意此处是Go的Output绑定到Tool中)
  113. /// NOTICE:
  114. /// </summary>
  115. /// <param name="pTool"></param>
  116. void WindowAppBlockGoto::bindOutputInterface(const TOOL* pTool)
  117. {
  118. (qobject_cast<WindowAppPouScene*>(this->scene()))->addGotoLink(m_pGotoInf, pTool);
  119. // 根据新的名字长度信息更新本矩形框
  120. updateRect();
  121. // 更新接口的位置及尺寸
  122. WindowAppBlockBase::updateInterfacesPostion();
  123. }