WindowAppBlockStandardBase.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  1. #include "WindowAppBlockStandardBase.h"
  2. #include "WindowAppPouFrame.h"
  3. #include "WindowAppItemInterface.h"
  4. #include "Pou.h"
  5. #include "DialogBlockProperty.h"
  6. #include "WindowAppPouScene.h"
  7. // bShowOnly 是否仅供展示使用,展示使用的话不提供右键菜单以及其他互动功能
  8. WindowAppBlockStandardBase::WindowAppBlockStandardBase(TOOL* pTool, POU* Pou, bool bShowOnly, QGraphicsObject* parent) :
  9. WindowAppBlockBase(pTool, Pou, bShowOnly, parent)
  10. {
  11. if (!bShowOnly)
  12. {
  13. setFlag(QGraphicsItem::ItemIsMovable);
  14. setFlag(QGraphicsItem::ItemSendsGeometryChanges);
  15. }
  16. else
  17. {
  18. setFlag(QGraphicsItem::ItemIsMovable, false);
  19. }
  20. setFlag(QGraphicsItem::ItemIsSelectable);
  21. this->m_toolInfo = pTool;
  22. // 创建菜单
  23. createContextMenu();
  24. // 更新矩形区域的尺寸
  25. this->updateRect();
  26. }
  27. ///////////////////////////////////////////////////////////
  28. //// 返回功能块图形的总体矩形区域
  29. //QRectF WIndowAppBlockStandardBase::boundingRect() const
  30. //{
  31. // return blockBoundingRect;
  32. //}
  33. /////////////////////////////////////////////////////////
  34. //// 显示右键菜单
  35. //void WIndowAppBlockStandardBase::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
  36. //{
  37. // scene()->clearSelection();
  38. // setSelected(true);
  39. //
  40. // blockMenu->exec(event->screenPos());
  41. //}
  42. /// <summary>
  43. /// 添加接口
  44. /// </summary>
  45. void WindowAppBlockStandardBase::addItemInterfaces()
  46. {
  47. // 为本Block添加新的ItemInterface
  48. for (_INTERFACE* pInf : qAsConst(m_toolInfo->Interfaces))
  49. {
  50. this->addItemInterface(pInf);
  51. }
  52. // 更新Interface的位置(注意此处坐标系需要转换一下)
  53. WindowAppBlockBase::updateInterfacesPostion();
  54. }
  55. /// <summary>
  56. /// 添加单个接口
  57. /// </summary>
  58. /// <param name="pInfInfo"></param>
  59. WindowAppItemInterface* WindowAppBlockStandardBase::addItemInterface(_INTERFACE* pInfInfo)
  60. {
  61. WindowAppItemInterface* pNewItemInf = new WindowAppItemInterface
  62. (
  63. pInfInfo,
  64. m_pPou,
  65. this->m_toolInfo,
  66. m_bShowOnly,
  67. this
  68. );
  69. if (!m_bShowOnly)
  70. {
  71. // Pou中保存此接口信息
  72. m_pPou->registerInterface(pNewItemInf, pInfInfo);
  73. }
  74. // 保存接口Item信息
  75. m_itemInterfaces.append(pNewItemInf);
  76. // 界面中添加此Interface(设置为从属关系之后,都不需要手工添加此Item了,真是方便啊)
  77. // scene()->addItem(pNewItemInf);
  78. return pNewItemInf;
  79. }
  80. /// <summary>
  81. /// 更新Block的相关位置和尺寸
  82. /// </summary>
  83. void WindowAppBlockStandardBase::updatePosition()
  84. {
  85. // 更新矩形区域的尺寸
  86. updateRect();
  87. // 更新所有的接口
  88. WindowAppBlockBase::updateInterfacesPostion();
  89. //// 重绘Block
  90. this->update();
  91. //// 重绘所有接口
  92. //this->redrawAllInterface();
  93. }
  94. /// <summary>
  95. /// 是否是StandardBase系列的Block,如果增加了新的工具类型,这里也需要补充
  96. /// </summary>
  97. /// <returns></returns>
  98. bool WindowAppBlockStandardBase::isStandardBasedBlock()
  99. {
  100. return (this->type() == ITEM_TYPE_STANDARD
  101. || this->type() == ITEM_TYPE_PORT
  102. || this->type() == ITEM_TYPE_GOTO
  103. || this->type() == ITEM_TYPE_PARALLEL
  104. );
  105. }
  106. /// <summary>
  107. /// MoveUp
  108. /// </summary>
  109. void WindowAppBlockStandardBase::onBlockMoveUp()
  110. {
  111. this->onMenuMoveUp();
  112. }
  113. /// <summary>
  114. /// MoveDown
  115. /// </summary>
  116. void WindowAppBlockStandardBase::onBlockMoveDown()
  117. {
  118. this->onMenuMoveDown();
  119. }
  120. /// <summary>
  121. /// MoveFirst
  122. /// </summary>
  123. void WindowAppBlockStandardBase::onBlockMoveFirst()
  124. {
  125. this->onMenuMoveFirst();
  126. }
  127. /// <summary>
  128. /// MoveLast
  129. /// </summary>
  130. void WindowAppBlockStandardBase::onBlockMoveLast()
  131. {
  132. this->onMenuMoveLast();
  133. }
  134. /// <summary>
  135. /// 2022-9-28,直接给工具设置一个新的Index
  136. /// </summary>
  137. /// <param name="newIndex"></param>
  138. void WindowAppBlockStandardBase::setToolIndex(const int& newIndex)
  139. {
  140. int nCurIndex = m_toolInfo->nIndex;
  141. int nFix = newIndex - nCurIndex;
  142. // 根据用户的索引号是增加还是减少了,进行数次前移或者后移
  143. if (nFix > 0)
  144. {
  145. // 后移
  146. for (int i = 0; i < nFix; i++)
  147. {
  148. this->onBlockMoveDown();
  149. }
  150. }
  151. else if (nFix < 0)
  152. {
  153. // 前移
  154. for (int i = 0; i < -nFix; i++)
  155. {
  156. this->onBlockMoveUp();
  157. }
  158. }
  159. }
  160. /// <summary>
  161. /// 更新矩形区域的尺寸
  162. /// </summary>
  163. void WindowAppBlockStandardBase::updateRect()
  164. {
  165. // 计算高度
  166. int blockHeight = TBD_BASIC_HEIGHT;
  167. // 根据接口计算实际需要的高度
  168. int nOutInfCount = 0;
  169. int nInInfCount = 0;
  170. for (_INTERFACE* pInf : m_toolInfo->Interfaces)
  171. {
  172. if (!m_bShowOnly && !pInf->bEnable)
  173. {
  174. continue;
  175. }
  176. // 仅绘制标准类型的端口
  177. if (pInf->Type == INF_TYPE::INF_TYPE_EVENT
  178. || pInf->Type == INF_TYPE::INF_TYPE_CONTROL
  179. )
  180. {
  181. continue;
  182. }
  183. // 2021-4-7增加,加入了接口启用与否的判断
  184. if (pInf->Direction == INF_DIRECTION::INF_DIR_OUT)
  185. {
  186. nOutInfCount++;
  187. }
  188. else if (pInf->Direction == INF_DIRECTION::INF_DIR_IN)
  189. {
  190. nInInfCount++;
  191. }
  192. }
  193. // 取更大的值作为整体高度
  194. int nInfCount = nOutInfCount > nInInfCount ? nOutInfCount : nInInfCount;
  195. // 2022-5-23,调整并排只有2个接口的情况下的高度
  196. if (nInfCount > 1)
  197. {
  198. blockHeight = TBD_BASIC_HEIGHT + TBD_INF_SPACING * (nInfCount - 1) - 5;
  199. }
  200. // 计算宽度
  201. int blockWidth = TBD_BASIC_WIDTH;
  202. // TODO : 根据工具名字字符的宽度计算实际需要的宽度
  203. // 主体矩形区域
  204. blockRect.setRect(
  205. -blockWidth / 2,
  206. -blockHeight / 2,
  207. blockWidth,
  208. blockHeight
  209. );
  210. // 序号矩形区域
  211. blockIndexRect.setRect(
  212. blockRect.right() - TBD_INDEX_WIDTH,
  213. blockRect.top() - TBD_INDEX_HEIGHT / 2,
  214. TBD_INDEX_WIDTH,
  215. TBD_INDEX_HEIGHT
  216. );
  217. //// 总体矩形边界
  218. //blockBoundingRect.setRect(
  219. // blockRect.left() - TBD_INF_LINE,
  220. // blockRect.top() - TBD_INDEX_HEIGHT / 2,
  221. // blockRect.width() + TBD_INF_LINE + TBD_INF_LINE,
  222. // blockRect.height() + TBD_INDEX_HEIGHT + TBD_SHADOW_COUNT * PEN_LINE_WIDTH + 12
  223. //);
  224. // 矩形边界(未计算Interface的范围)
  225. blockBoundingRect.setRect(
  226. blockRect.left(),
  227. blockRect.top() - TBD_INDEX_HEIGHT,
  228. blockRect.width() + TBD_SHADOW_COUNT * PEN_LINE_WIDTH,
  229. blockRect.height() + TBD_INDEX_HEIGHT + TBD_SHADOW_COUNT * PEN_LINE_WIDTH + 12
  230. );
  231. //// 总矩形边界(计算Interface的范围)
  232. //blockTotalRect.setRect(
  233. // blockRect.left() - TBD_INF_LINE * 2,
  234. // blockRect.top() - TBD_INDEX_HEIGHT,
  235. // blockRect.width() + TBD_INF_LINE * 4,
  236. //
  237. // blockRect.height() + TBD_INDEX_HEIGHT + TBD_SHADOW_COUNT * PEN_LINE_WIDTH + 15
  238. //);
  239. }
  240. /// <summary>
  241. /// 添加ToolStart、ToolEnd接口,2022-8-21更新,增加了ToolEnd接口支持
  242. /// </summary>
  243. void WindowAppBlockStandardBase::addItemToolInterfaces()
  244. {
  245. if (this->m_toolInfo->ToolInterfaces.size() <= 0 )
  246. {
  247. qDebug() << "[Error] WindowAppBlockStandardBase::addItemToolInterfaces - ignore.";
  248. //return nullptr;
  249. }
  250. // 添加所有的ToolInterface
  251. for (int i = 0; i < this->m_toolInfo->ToolInterfaces.size(); i++)
  252. {
  253. WindowAppItemInterface* pToolInfItem = this->addItemInterface(this->m_toolInfo->ToolInterfaces[i]);
  254. // 更新ToolInterface的位置
  255. QPointF pt = mapToScene(0, 0);
  256. QRectF rcBlock = blockRect;
  257. rcBlock.translate(pt);
  258. pToolInfItem->updateParentRect(rcBlock);
  259. // 更新ToolInterface的位置
  260. pToolInfItem->updateToolInterfacePostion();
  261. }
  262. //// 添加ToolStart接口
  263. //WindowAppItemInterface* pStartInfItem = this->addItemInterface(this->m_toolInfo->startInterface);
  264. //// 更新ToolStart接口的位置
  265. //QPointF pt = mapToScene(0, 0);
  266. //QRectF rcBlock = blockRect;
  267. //rcBlock.translate(pt);
  268. //pTopInfItem->updateParentRect(rcBlock);
  269. //// 添加ToolEnd接口
  270. //WindowAppItemInterface* pTopInfItem = this->addItemInterface(this->m_toolInfo->startInterface);
  271. //// 更新ToolInterface的位置
  272. //pTopInfItem->updateToolInterfacePostion();
  273. //return pTopInfItem;
  274. }
  275. ///// <summary>
  276. ///// 双击弹出设置对话框
  277. ///// </summary>
  278. ///// <param name="event"></param>
  279. //void WindowAppBlockStandardBase::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
  280. //{
  281. // // 只有鼠标左键才响应
  282. // if (event->button() == Qt::LeftButton && !m_bShowOnly)
  283. // {
  284. // // qDebug() << this->scenePos();
  285. //
  286. // m_pPou->ShowToolDialog(this);
  287. // }
  288. //}
  289. /// <summary>
  290. /// 绘制block
  291. /// </summary>
  292. /// <param name="painter"></param>
  293. /// <param name="option"></param>
  294. /// <param name="widget"></param>
  295. void WindowAppBlockStandardBase::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
  296. {
  297. painter->setRenderHint(QPainter::Antialiasing, true);
  298. WindowAppBlockBase::paint(painter, option, widget);
  299. painter->save();
  300. // 绘制功能块
  301. this->DrawBlock(painter, true);
  302. // 绘制序号
  303. this->DrawIndex(painter);
  304. painter->restore();
  305. }
  306. /// <summary>
  307. /// 绘制功能块
  308. /// </summary>
  309. /// <param name="painter"></param>
  310. void WindowAppBlockStandardBase::DrawBlock(QPainter* painter, bool withToolName /*= true*/)
  311. {
  312. WindowAppBlockBase::DrawBlock(painter);
  313. // 绘制功能块名字
  314. this->DrawBlockTitle(painter, withToolName);
  315. // 绘制断点标识
  316. this->DrawBreakPoint(painter);
  317. // 绘制程序指针
  318. this->DrawPointer(painter);
  319. }
  320. /// <summary>
  321. /// 绘制功能块名字
  322. /// </summary>
  323. /// <param name="painter"></param>
  324. /// <param name="withInstName">是否需要绘制工具基础名称</param>
  325. void WindowAppBlockStandardBase::DrawBlockTitle(QPainter* painter, bool withToolName /*= true*/)
  326. {
  327. // 实例名文字
  328. painter->setPen(QPen(COLOR_TEXT, PEN_LINE_WIDTH));
  329. painter->setFont(FONT_INSTANCENAME);
  330. QRect textRect = QFontMetrics(FONT_INSTANCENAME).boundingRect(m_toolInfo->strInstanceName);
  331. int textX = blockRect.left() + (blockRect.width() - textRect.width()) / 2;
  332. int textY = blockRect.top() - 4;
  333. painter->drawText(textX, textY, m_toolInfo->strInstanceName);
  334. // 工具基础名字
  335. if (withToolName)
  336. {
  337. painter->setFont(FONT_TOOLNAME);
  338. textRect = QFontMetrics(FONT_TOOLNAME).boundingRect(m_toolInfo->strName);
  339. textX = blockRect.left() + (blockRect.width() - textRect.width()) / 2;
  340. textY = blockRect.top() + textRect.height() - 3;
  341. painter->drawText(textX, textY, m_toolInfo->strName);
  342. }
  343. }
  344. ////////////////////////////////////////////////
  345. // 绘制序号
  346. void WindowAppBlockStandardBase::DrawIndex(QPainter* painter)
  347. {
  348. painter->setRenderHint(QPainter::Antialiasing);
  349. // 边框
  350. if (!this->isSelected())
  351. {
  352. painter->setPen(QPen(COLOR_TBD_INDEX_FRAME, PEN_LINE_WIDTH));
  353. }
  354. else
  355. {
  356. painter->setPen(QPen(COLOR_TBD_INDEX_FRAME, PEN_LINE_WIDTH_SEL));
  357. }
  358. // 绘制程序执行状态
  359. this->SetExecStatus(painter);
  360. // 绘制主体
  361. painter->drawRoundedRect(blockIndexRect, 3, 3);
  362. // 序号文字(最多可以容纳0-99)
  363. painter->setPen(QPen(COLOR_TBD_INDEX_TEXT, PEN_LINE_WIDTH));
  364. painter->setFont(FONT_INDEX);
  365. QString strIndex = QString::number(m_toolInfo->nIndex + 1);
  366. QRect textRect = QFontMetrics(FONT_INDEX).boundingRect(strIndex);
  367. int textX = blockIndexRect.left() + (blockIndexRect.width() - textRect.width()) / 2;
  368. int textY = blockIndexRect.top() + textRect.height() - 1;
  369. // 2022-5-6 增加,如果Tool被加入了并行组,则显示一个P,不显示序号了
  370. if (!this->m_toolInfo->isParallelSubTool())
  371. {
  372. painter->drawText(textX, textY, strIndex);
  373. }
  374. else
  375. {
  376. painter->drawText(textX, textY, TOOL_PARALLEL_LOGO);
  377. }
  378. }
  379. /// <summary>
  380. /// 绘制断点标识
  381. /// </summary>
  382. /// <param name="painter"></param>
  383. void WindowAppBlockStandardBase::DrawBreakPoint(QPainter* painter)
  384. {
  385. if (m_toolInfo->bEnableBreakPoint)
  386. {
  387. painter->setPen(QPen(Qt::red, 4, Qt::SolidLine));
  388. painter->drawEllipse(blockRect.left() + 2, blockRect.top() + 2, 4, 4);
  389. }
  390. }
  391. /// <summary>
  392. /// 绘制程序指针
  393. /// </summary>
  394. /// <param name="painter"></param>
  395. void WindowAppBlockStandardBase::DrawPointer(QPainter* painter)
  396. {
  397. if (m_toolInfo->execParams.nStatus == VPEnum::EXEC_STATUS::Busy)
  398. {
  399. double x = blockRect.left() - 10.0;
  400. double y = blockRect.top() + 4.0;
  401. double length = 2.0;//箭头斜着的投影到线上的长度
  402. QVector<QLineF> lines;
  403. lines.append(QLineF(x, y, x + 10, y));
  404. lines.append(QLineF(x + 5.0 + length, y + length, x + 10.0, y));
  405. lines.append(QLineF(x + 5.0 + length, y - length, x + 10.0, y));
  406. painter->setPen(QPen(Qt::yellow, 2, Qt::SolidLine));
  407. painter->drawLines(lines);
  408. }
  409. }
  410. /// <summary>
  411. /// 设置功能块执行状态
  412. /// </summary>
  413. /// <param name="painter"></param>
  414. void WindowAppBlockStandardBase::SetExecStatus(QPainter* painter)
  415. {
  416. // 填充 如果工具执行失败,将标签的背景色设置成红色
  417. switch (m_toolInfo->execParams.nRetValue)
  418. {
  419. case VPEnum::RETURN_VALUE::Success: painter->setBrush(COLOR_TBD_INDEX_BG); break;
  420. case VPEnum::RETURN_VALUE::Error: painter->setBrush(COLOR_TBD_INDEX_BG_ERROR); break;
  421. case VPEnum::RETURN_VALUE::Invalid: painter->setBrush(COLOR_TBD_INDEX_BG); break;
  422. case VPEnum::RETURN_VALUE::Timeout: painter->setBrush(COLOR_TBD_INDEX_BG); break;
  423. case VPEnum::RETURN_VALUE::Goto: painter->setBrush(COLOR_TBD_INDEX_BG); break;
  424. case VPEnum::RETURN_VALUE::None: painter->setBrush(COLOR_TBD_INDEX_BG); break;
  425. default:
  426. painter->setBrush(COLOR_TBD_INDEX_BG);
  427. break;
  428. }
  429. }
  430. //=================================================================
  431. //
  432. // Menu相关
  433. //
  434. //=================================================================
  435. /// <summary>
  436. /// 初始化功能块的右键菜单
  437. /// </summary>
  438. void WindowAppBlockStandardBase::createContextMenu()
  439. {
  440. WindowAppBlockBase::createContextMenu();
  441. // 硬件组态不显示右键菜单
  442. if (m_pPou->pouName() != GROUP_NAME_HARDWARE)
  443. {
  444. connect(executeAction, &QAction::triggered, this, &WindowAppBlockStandardBase::onMenuExecute);
  445. connect(executeSubAction, &QAction::triggered, this, &WindowAppBlockStandardBase::onMenuExecuteSub);
  446. connect(executeAllAction, &QAction::triggered, this, &WindowAppBlockStandardBase::onMenuExecuteAll);
  447. connect(executeBreakPoint, &QAction::triggered, this, &WindowAppBlockStandardBase::onMenuBreakPoint);
  448. connect(moveUpAction, &QAction::triggered, this, &WindowAppBlockStandardBase::onMenuMoveUp);
  449. connect(moveDownAction, &QAction::triggered, this, &WindowAppBlockStandardBase::onMenuMoveDown);
  450. connect(moveFirstAction, &QAction::triggered, this, &WindowAppBlockStandardBase::onMenuMoveFirst);
  451. connect(moveLastAction, &QAction::triggered, this, &WindowAppBlockStandardBase::onMenuMoveLast);
  452. }
  453. connect(deleteAction, &QAction::triggered, this, &WindowAppBlockStandardBase::onMenuDelete);
  454. connect(propertyAction, &QAction::triggered, this, &WindowAppBlockStandardBase::onMenuProperty);
  455. connect(copyBlockAction, &QAction::triggered, this, &WindowAppBlockStandardBase::onMenuCopyblock);
  456. connect(copyDataAction, &QAction::triggered, this, &WindowAppBlockStandardBase::onMenuCopydata);
  457. connect(pasteAction, &QAction::triggered, this, &WindowAppBlockStandardBase::onMenuPaste);
  458. contextMenu = new QMenu();
  459. if (m_pPou->pouName() != GROUP_NAME_HARDWARE)
  460. {
  461. contextMenu->addAction(executeAction);
  462. contextMenu->addAction(executeSubAction);
  463. contextMenu->addAction(executeAllAction);
  464. contextMenu->addSeparator();
  465. contextMenu->addAction(executeBreakPoint);
  466. contextMenu->addSeparator();
  467. contextMenu->addAction(moveUpAction);
  468. contextMenu->addAction(moveDownAction);
  469. contextMenu->addAction(moveFirstAction);
  470. contextMenu->addAction(moveLastAction);
  471. contextMenu->addSeparator();
  472. }
  473. contextMenu->addAction(deleteAction);
  474. contextMenu->addSeparator();
  475. contextMenu->addAction(copyBlockAction);
  476. contextMenu->addAction(copyDataAction);
  477. contextMenu->addAction(pasteAction);
  478. contextMenu->addSeparator();
  479. contextMenu->addAction(propertyAction);
  480. }
  481. /// <summary>
  482. /// 菜单 - Execute
  483. /// </summary>
  484. void WindowAppBlockStandardBase::onMenuExecute()
  485. {
  486. QFuture<void> Future = QtConcurrent::run(this, &WindowAppBlockStandardBase::MenuExecute);
  487. }
  488. /// <summary>
  489. /// 菜单 - ExecuteSubsequent
  490. /// </summary>
  491. void WindowAppBlockStandardBase::onMenuExecuteSub()
  492. {
  493. QFuture<void> Future = QtConcurrent::run(this, &WindowAppBlockStandardBase::MenuExecuteSub);
  494. }
  495. /// <summary>
  496. /// 菜单 - ExecuteAll
  497. /// </summary>
  498. void WindowAppBlockStandardBase::onMenuExecuteAll()
  499. {
  500. QFuture<void> Future = QtConcurrent::run(this, &WindowAppBlockStandardBase::MenuExecuteAll);
  501. }
  502. void WindowAppBlockStandardBase::MenuExecute()
  503. {
  504. m_pPou->ToolExecutionDispatcher(this->m_toolInfo, TOOL_RUN_MODE::STANDALONE);
  505. // m_pPou->ToolExecuteStandard(this->m_toolInfo);
  506. }
  507. /// <summary>
  508. /// - ExecuteSubsequent
  509. /// </summary>
  510. void WindowAppBlockStandardBase::MenuExecuteSub()
  511. {
  512. m_pPou->ToolExecuteSub(this);
  513. }
  514. /// <summary>
  515. /// - ExecuteAll
  516. /// </summary>
  517. void WindowAppBlockStandardBase::MenuExecuteAll()
  518. {
  519. m_pPou->ToolExecuteAll();
  520. }
  521. /// <summary>
  522. /// 菜单 - BreakPoint
  523. /// </summary>
  524. void WindowAppBlockStandardBase::onMenuBreakPoint()
  525. {
  526. m_pPou->ToolBreakPoint(this);
  527. this->update();
  528. }
  529. /// <summary>
  530. /// 菜单 - MoveUp
  531. /// </summary>
  532. void WindowAppBlockStandardBase::onMenuMoveUp()
  533. {
  534. // 获取当前选中的Block
  535. // QGraphicsItem* activeBlock = this->selectedItems().first();
  536. m_pPou->ToolMoveUp(this);
  537. update();
  538. }
  539. /// <summary>
  540. /// 菜单 - MoveDown
  541. /// </summary>
  542. void WindowAppBlockStandardBase::onMenuMoveDown()
  543. {
  544. // 获取当前选中的Block
  545. // QGraphicsItem* activeBlock = this->selectedItems().first();
  546. m_pPou->ToolMoveDown(this);
  547. update();
  548. }
  549. /// <summary>
  550. /// 菜单 - MoveFirst
  551. /// </summary>
  552. void WindowAppBlockStandardBase::onMenuMoveFirst()
  553. {
  554. // 获取当前选中的Block
  555. //QGraphicsItem* activeBlock = this->selectedItems().first();
  556. m_pPou->ToolMoveFirst(this);
  557. update();
  558. }
  559. /// <summary>
  560. /// 菜单 - MoveLast
  561. /// </summary>
  562. void WindowAppBlockStandardBase::onMenuMoveLast()
  563. {
  564. // 获取当前选中的Block
  565. //QGraphicsItem* activeBlock = this->selectedItems().first();
  566. m_pPou->ToolMoveLast(this);
  567. update();
  568. }
  569. /// <summary>
  570. /// 菜单 - Delete
  571. /// </summary>
  572. void WindowAppBlockStandardBase::onMenuDelete()
  573. {
  574. // 2022-10-4,调用基类函数进行删除
  575. WindowAppBlockBase::onDeleteItem();
  576. //// 检查是否可以被删除
  577. //if (!WindowAppBlockBase::couldBeDeleted())
  578. //{
  579. // return;
  580. //}
  581. //// 2022-3-5增加,如果此工具的Pou被Task选中,需要通知Task删除此工具
  582. //if (m_pPou->isSelByTask())
  583. //{
  584. // WindowAppTaskView* pTaskView = g_pTaskManager->getTaskViewByName(m_pPou->m_pParentTask->strName);
  585. // pTaskView->onDelPouTool(m_pPou, this->m_toolInfo);
  586. //}
  587. //// 逻辑数据删除
  588. //m_pPou->ToolDelete(this);
  589. //// 从界面中移除此功能块
  590. //scene()->removeItem(this);
  591. }
  592. /// <summary>
  593. /// 菜单 - Property
  594. /// </summary>
  595. void WindowAppBlockStandardBase::onMenuProperty()
  596. {
  597. // 显示工具属性对话框
  598. DialogBlockProperty dlgProperty(this->m_toolInfo, m_pPou);
  599. int res = dlgProperty.exec();
  600. if (res != QDialog::Accepted)
  601. {
  602. return;
  603. }
  604. // 保存用户设置
  605. BLOCK_PROPERTY settings = dlgProperty.getBlockSettings();
  606. // 根据用户设置更新工具信息
  607. if (!settings.strNewInstanceName.isEmpty())
  608. {
  609. m_pPou->setInstanceName(m_toolInfo, settings.strNewInstanceName, settings.strOldInstanceName);
  610. }
  611. m_pPou->setToolEnable(m_toolInfo, settings.bToolEnable);
  612. m_pPou->setToolInfo(m_toolInfo, settings.strInfo);
  613. m_pPou->setToolDelay(m_toolInfo, settings.nInDelay, settings.nOutDelay);
  614. for (int i = 0; i < settings.infEnables.size(); i++)
  615. {
  616. // 2021-4-18 增加了判断,只处理enable发生变化的接口
  617. if (m_toolInfo->Interfaces[i]->bEnable == settings.infEnables[i])
  618. {
  619. continue;
  620. }
  621. // 这里需要检查引用计数,不一定能成功
  622. bool bRet = m_pPou->setInterfaceEnable(m_toolInfo, i, settings.infEnables[i]);
  623. if (!bRet)
  624. {
  625. Utility::VPCriticalMessageBox(QString("Set ") + m_toolInfo->Interfaces[i]->strFullName + " failed!");
  626. }
  627. }
  628. // 更新用户配置的索引号(如果需要的话)
  629. if (this->m_toolInfo->nIndex != settings.nNewIndex && settings.nNewIndex != -1)
  630. {
  631. this->setToolIndex(settings.nNewIndex);
  632. }
  633. // 更新本工具(此处会自动完成工具重绘)
  634. this->updatePosition();
  635. }
  636. /// <summary>
  637. /// 菜单 - Copy block
  638. /// </summary>
  639. void WindowAppBlockStandardBase::onMenuCopyblock()
  640. {
  641. m_pPou->ToolCopyBlock(this);
  642. }
  643. /// <summary>
  644. /// 菜单 - Copy data
  645. /// </summary>
  646. void WindowAppBlockStandardBase::onMenuCopydata()
  647. {
  648. m_pPou->ToolCopyData(this);
  649. }
  650. /// <summary>
  651. /// 菜单 - Paste
  652. /// </summary>
  653. void WindowAppBlockStandardBase::onMenuPaste()
  654. {
  655. m_pPou->ToolPaste(this);
  656. }