#include "WindowAppBlockGoto.h" #include "DialogGoto.h" #include "Pou.h" #include "WindowAppPouScene.h" WindowAppBlockGoto::WindowAppBlockGoto(TOOL* pNewTool, POU* Pou, bool bShowOnly, QGraphicsObject* parent) : WindowAppBlockStandardBase(pNewTool, Pou, bShowOnly, parent) , m_bNegation(false) { m_bNegation = false; // 更新矩形区域的尺寸 this->updateRect(); m_pGotoInf = m_toolInfo->Interfaces[GOTO_OUTPUT_INDX]; } WindowAppBlockGoto::~WindowAppBlockGoto() { } /// /// 双击弹出配置对话框 /// /// void WindowAppBlockGoto::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) { if (event->button() != Qt::LeftButton || m_bShowOnly==true ) { return; } // _INTERFACE* pGotoInf = m_toolInfo->Interfaces[GOTO_OUTPUT_INDX]; // 初始化Goto设置对话框中的内容 QString selToolName; _INTERFACE* pBindInf = m_pGotoInf->pBindInterface; if (pBindInf != nullptr) { selToolName = pBindInf->strName; } // 弹出Goto设置对话框 DialogGoto dialogGoto(this->m_pPou, this->m_toolInfo, selToolName, m_bNegation); if (dialogGoto.exec() != DialogGoto::Accepted) { return; } // 执行输出接口的Tool绑定操作 TOOL* pTool = this->m_pPou->GetToolByName(dialogGoto.m_selToolInstName); m_bNegation = dialogGoto.m_bNegation; // 绑定用户选择的工具 this->bindOutputInterface(pTool); // 2022-4-7,此处增加Goto和绑定的ToolStart接口之间的Link // pTool->TopInterface->pUpLinkInterface = m_toolInfo->Interfaces[GOTO_OUTPUT_INDX]; // 重绘本功能块,用于绑定接口文字的及时更新 this->update(); QGraphicsItem::mouseDoubleClickEvent(event); } /// /// 绘制Goto控件 /// /// /// /// void WindowAppBlockGoto::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { // WindowAppBlockStandardBase::paint(painter, option, widget); Q_UNUSED(option); Q_UNUSED(widget); painter->save(); painter->setRenderHint(QPainter::Antialiasing, true); // 绘制功能块 this->DrawBlock(painter); // 绘制索引号 WindowAppBlockStandardBase::DrawIndex(painter); painter->restore(); } /// /// 绘制功能块 /// /// void WindowAppBlockGoto::DrawBlock(QPainter* painter) { // 调用基类绘制功能块(不绘制实例名) WindowAppBlockStandardBase::DrawBlock(painter, false); } /// /// 更新矩形区域的尺寸 /// void WindowAppBlockGoto::updateRect() { // 计算高度 int blockHeight = GBD_BASIC_HEIGHT; // 计算宽度 int blockWidth = GBD_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 ); // 总体矩形边界(未计算Interface的范围) 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 ); } /// /// 绑定输出接口(注意此处是Go的Output绑定到Tool中) /// NOTICE: /// /// void WindowAppBlockGoto::bindOutputInterface(const TOOL* pTool) { (qobject_cast(this->scene()))->addGotoLink(m_pGotoInf, pTool); // 根据新的名字长度信息更新本矩形框 updateRect(); // 更新接口的位置及尺寸 WindowAppBlockBase::updateInterfacesPostion(); }