123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- #include "WindowAppBlockWait.h"
- #include "DialogWait.h"
- #include "TaskManager.h"
- #include "GvlManager.h"
- WindowAppBlockWait::WindowAppBlockWait(TOOL* pNewTool, POU* Pou, bool bShowOnly /*= false*/, QGraphicsObject* parent /*= nullptr*/)
- : WindowAppBlockStandardBase(pNewTool, Pou, bShowOnly, parent)
- , m_selVariable(nullptr)
- , m_nTimeout(DEFAULT_WAIT_TIMEOUT)
- {
- // 更新矩形区域的尺寸
- this->updateRect();
- }
- WindowAppBlockWait::~WindowAppBlockWait()
- {
- }
- /// <summary>
- /// 添加接口(Wait工具需要添加两个ToolInerface以及两个输出接口)
- /// </summary>
- void WindowAppBlockWait::addItemInterfaces()
- {
- // 添加标准接口
- WindowAppBlockStandardBase::addItemInterfaces();
- // 添加ToolStart和ToolEnd接口
- WindowAppBlockStandardBase::addItemToolInterfaces();
- }
- /// <summary>
- /// 更新矩形区域的尺寸
- /// </summary>
- void WindowAppBlockWait::updateRect()
- {
- // 计算高度
- int blockHeight = WAIT_BASIC_HEIGHT;
- // 计算宽度
- int blockWidth = WAIT_BASIC_WIDTH;
- // 主体矩形区域
- blockRect.setRect(
- -blockWidth / 2,
- -blockHeight / 2,
- blockWidth,
- blockHeight
- );
- // 序号矩形区域
- blockIndexRect.setRect(
- blockRect.right() - TBD_INDEX_WIDTH,
- blockRect.top() - TBD_INDEX_HEIGHT / 2,
- TBD_INDEX_WIDTH,
- TBD_INDEX_HEIGHT
- );
- // 总体矩形边界
- blockBoundingRect.setRect(
- blockRect.left(),
- blockRect.top() - TBD_INDEX_HEIGHT / 2,
- blockRect.width() + TBD_SHADOW_COUNT * PEN_LINE_WIDTH,
- blockRect.height() + TBD_INDEX_HEIGHT / 2 + TBD_SHADOW_COUNT * PEN_LINE_WIDTH
- );
- }
- /// <summary>
- /// 根据Wait工具当前的事件绑定信息,初始化变量
- /// </summary>
- void WindowAppBlockWait::initVariable()
- {
- if (m_selVariable != nullptr)
- {
- return;
- }
- // 到TaskManager中查询ToolEvent信息
- ToolEvent* event = g_pTaskManager->getEventByTool(m_toolInfo);
- if (event == nullptr)
- {
- return;
- }
- QString groupName = event->groupName();
- QString name = event->name();
- // 如果确实绑定了Event,则此处重新到TaskManager注册一下
- if (!groupName.isEmpty() && !name.isEmpty())
- {
- // 首先检查是否是系统内置事件
- m_selVariable = g_pTaskManager->getSysEventByName(name);
- // 如果不是的话,再判断是否是某一个变量
- if (m_selVariable == nullptr)
- {
- // 转换成对应的Variable(此处不应该为空)
- m_selVariable = g_pGvlManager->getVariableByName(groupName, name);
- // 校验是否有异常
- if (m_selVariable == nullptr)
- {
- vDebug() << "[Error] Load event[" << groupName << "," << name << "] failed.";
- }
- }
- }
- }
- /// <summary>
- /// 双击弹出配置对话框
- /// </summary>
- /// <param name="event"></param>
- void WindowAppBlockWait::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
- {
- if (event->button() != Qt::LeftButton || m_bShowOnly == true)
- {
- return;
- }
- // 如果当前Tool已经绑定了事件,则提前初始化一下
- this->initVariable();
- // 弹出Wait设置对话框
- DialogWait dialogWait(m_selVariable, m_bSkipWait, &m_WaitValue, m_nTimeout);
- if (dialogWait.exec() != DialogWait::Accepted)
- {
- return;
- }
- // 保存用户设置的参数信息
- this->m_selVariable = dialogWait.m_selVariable;
- this->m_bSkipWait = dialogWait.m_bSkipWait;
- this->m_nTimeout = dialogWait.m_nTimeout;
- // 2022-9-26,将用户设定的等待值输出到WaitTool的0号接口中(值可能是nullptr)
- m_toolInfo->Interfaces[0]->value = m_WaitValue;
- // 到TaskManager中绑定用户选择的触发事件和Tool之间的关系
- g_pTaskManager->registerToolEvent(m_selVariable->eventTrigger, m_toolInfo);
-
- QGraphicsItem::mouseDoubleClickEvent(event);
- }
|