123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- #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()
- {
- }
- /// <summary>
- /// 双击弹出配置对话框
- /// </summary>
- /// <param name="event"></param>
- 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);
- }
- /// <summary>
- /// 绘制Goto控件
- /// </summary>
- /// <param name="painter"></param>
- /// <param name="option"></param>
- /// <param name="widget"></param>
- 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();
- }
- /// <summary>
- /// 绘制功能块
- /// </summary>
- /// <param name="painter"></param>
- void WindowAppBlockGoto::DrawBlock(QPainter* painter)
- {
- // 调用基类绘制功能块(不绘制实例名)
- WindowAppBlockStandardBase::DrawBlock(painter, false);
- }
- /// <summary>
- /// 更新矩形区域的尺寸
- /// </summary>
- 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
- );
- }
- /// <summary>
- /// 绑定输出接口(注意此处是Go的Output绑定到Tool中)
- /// NOTICE:
- /// </summary>
- /// <param name="pTool"></param>
- void WindowAppBlockGoto::bindOutputInterface(const TOOL* pTool)
- {
- (qobject_cast<WindowAppPouScene*>(this->scene()))->addGotoLink(m_pGotoInf, pTool);
- // 根据新的名字长度信息更新本矩形框
- updateRect();
- // 更新接口的位置及尺寸
- WindowAppBlockBase::updateInterfacesPostion();
- }
|