feat: execute parallel workflow branches and render device SVG icons
@ -30,7 +30,7 @@ set(PROTO_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/protos")
|
||||
set(GENERATED_ROOT "${CMAKE_CURRENT_BINARY_DIR}/generated_cpp")
|
||||
|
||||
find_package(Qt5 5.12 REQUIRED COMPONENTS
|
||||
Core Gui Widgets Network Multimedia 3DCore 3DRender 3DExtras 3DInput 3DAnimation)
|
||||
Core Gui Widgets Svg Network Multimedia 3DCore 3DRender 3DExtras 3DInput 3DAnimation)
|
||||
|
||||
get_target_property(CMVR_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)
|
||||
if(CMVR_QMAKE_EXECUTABLE)
|
||||
@ -187,6 +187,7 @@ set(CMVR_SOURCES
|
||||
src/demosimulator.h
|
||||
src/workflowcanvas.h
|
||||
src/workflowgraph.h
|
||||
src/workflowruntime.h
|
||||
src/freescaninteropui.h
|
||||
src/freescaninterop.cpp
|
||||
src/freescaninterop.h
|
||||
@ -289,7 +290,7 @@ if(CMVR_WITH_MSQUIC)
|
||||
endif()
|
||||
|
||||
target_link_libraries(CmvrControlStation PRIVATE
|
||||
Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Network Qt5::Multimedia
|
||||
Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Svg Qt5::Network Qt5::Multimedia
|
||||
Qt5::3DCore Qt5::3DRender Qt5::3DExtras Qt5::3DInput Qt5::3DAnimation)
|
||||
|
||||
# Generate every project-local CMVR message. This avoids source-tree generated
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
QT += core gui widgets network multimedia 3dcore 3drender 3dextras 3dinput 3danimation
|
||||
QT += core gui widgets svg network multimedia 3dcore 3drender 3dextras 3dinput 3danimation
|
||||
|
||||
CONFIG += c++17 warn_on debug_and_release
|
||||
win32-g++: QMAKE_CXXFLAGS += -Wa,-mbig-obj
|
||||
@ -421,3 +421,4 @@ win32:CONFIG(release, debug|release) {
|
||||
DISTFILES += scripts/repair_qt3d_release.ps1
|
||||
|
||||
HEADERS += src/workflowgraph.h src/freescaninteropui.h
|
||||
HEADERS += src/workflowruntime.h
|
||||
|
||||
@ -341,7 +341,7 @@ Proto 约定和目录说明见 [protos/README.md](protos/README.md)。
|
||||
|
||||
工作流工作区以 `am-freescan` 的组件库、端口连线、循环容器、右侧参数面板和图数据结构为依据,以原生 Qt 实现。参考仓库位于 `am-freescan/`,独立管理 Git;来源提交为 `6ace9b1`。两个编辑入口均独立全屏打开。
|
||||
|
||||
点位库支持搜索、拖入、重命名、行号排序、组复制和组内多流程。循环和等待可添加到画布;节点可自由移动,循环标题移动时带动容器内节点。任务编排左侧可搜索设备组件,右侧可直接编辑接口参数、超时和等待。端口连线决定执行顺序,Delete 删除选中的连线;不连通、环路、跨容器连线和不支持的分支在运行前报错。右键/中键或空白处平移,Ctrl+滚轮缩放,工具栏可显示全部。
|
||||
点位库支持搜索、拖入、重命名、行号排序、组复制和组内多流程。循环和等待可添加到画布;节点可自由移动,循环标题移动时带动容器内节点。任务编排左侧可搜索设备组件,右侧可直接编辑接口参数、超时和等待。端口连线决定执行顺序,Delete 删除选中的连线;不连通、环路和跨容器连线在运行前报错。右键/中键或空白处平移,Ctrl+滚轮缩放,工具栏可显示全部。
|
||||
|
||||
两个画布均支持 Ctrl+C / Ctrl+V 复制粘贴选中节点。循环连同其内部节点一起复制,多节点保留内部连线;粘贴生成新的节点 ID 并偏移位置,外部连线不复制。点位流程粘贴时要求当前点位库中存在所引用的点位。执行期间禁用粘贴,文本输入框继续使用原有文本复制粘贴。
|
||||
|
||||
@ -349,4 +349,4 @@ Proto 约定和目录说明见 [protos/README.md](protos/README.md)。
|
||||
|
||||
两个入口均能导入/导出 am-freescan 图 JSON。导出保留 cmvr-es 的服务全名、方法名、完整请求、接口超时及 protobuf 描述集;循环和等待使用原生 loop/sleep 节点。组合点位保留多臂并行运动和逐臂关节顺序校验。网页侧通过自身 gRPC 连接调用 cmvr-es,上位机无需保持运行。资源使用参考项目的机器人角色和设备用途绑定,网页导出后在上位机导入时选择实际设备。
|
||||
|
||||
克隆仓库包含对应的网页 JSON 导入/导出、参数面板和 `CMVR_GRPC_UNARY` / `CMVR_ARM_POINT_BATCH` 后端执行适配。这些改动必须由网页项目单独构建部署后才生效,本地修改不代表线上已支持。组合调用先校验所有机械臂,再并行下发同步 MoveJ;失败或取消时取消剩余调用并请求停止。当前 Qt 执行器支持单路径及嵌套循环;条件分支、运行时参数引用、扫描仪等其他领域动作不能无损转换时明确报错。等待可位于开始之后、任务之后或循环内部。
|
||||
克隆仓库包含对应的网页 JSON 导入/导出、参数面板和 `CMVR_GRPC_UNARY` / `CMVR_ARM_POINT_BATCH` 后端执行适配。这些改动必须由网页项目单独构建部署后才生效,本地修改不代表线上已支持。组合调用先校验所有机械臂,再并行下发同步 MoveJ;失败或取消时取消剩余调用并请求停止。任务编排使用图执行器,支持并行分支、汇合屏障及嵌套循环;每次循环独立记录前驱完成状态,各 RPC 以独立调用标识收取结果。失败和停止会取消全部在途 RPC;已执行的调用不会自动重试。点位执行器保留单路径与组合点位调用。条件分支、运行时参数引用、扫描仪等其他领域动作不能无损转换时明确报错。等待可位于开始之后、任务之后或循环内部。
|
||||
|
||||
@ -42,4 +42,21 @@
|
||||
<file>icons/trash-2.svg</file>
|
||||
<file>icons/plus.svg</file>
|
||||
</qresource>
|
||||
<qresource prefix="/workflow-icons">
|
||||
<file alias="arm.svg">resources/workflow-icons/arm.svg</file>
|
||||
<file alias="agv.svg">resources/workflow-icons/agv.svg</file>
|
||||
<file alias="hand.svg">resources/workflow-icons/hand.svg</file>
|
||||
<file alias="camera.svg">resources/workflow-icons/camera.svg</file>
|
||||
<file alias="video.svg">resources/workflow-icons/video.svg</file>
|
||||
<file alias="microphone.svg">resources/workflow-icons/microphone.svg</file>
|
||||
<file alias="audio.svg">resources/workflow-icons/audio.svg</file>
|
||||
<file alias="expression.svg">resources/workflow-icons/expression.svg</file>
|
||||
<file alias="motor.svg">resources/workflow-icons/motor.svg</file>
|
||||
<file alias="start.svg">resources/workflow-icons/start.svg</file>
|
||||
<file alias="end.svg">resources/workflow-icons/end.svg</file>
|
||||
<file alias="sleep.svg">resources/workflow-icons/sleep.svg</file>
|
||||
<file alias="loop.svg">resources/workflow-icons/loop.svg</file>
|
||||
<file alias="plan.svg">resources/workflow-icons/plan.svg</file>
|
||||
<file alias="touch.svg">resources/workflow-icons/touch.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
8
resources/workflow-icons/README.md
Normal file
@ -0,0 +1,8 @@
|
||||
The original web SVGs are copied without rasterization from the local am-freescan
|
||||
reference project: am-web/src/cmvr/common/views/flow/icon/. The additional arm.svg,
|
||||
agv.svg and hand.svg use device-specific shapes in the same palette; the arm is
|
||||
not represented by the web project's legacy video-camera icon.
|
||||
|
||||
The Qt workflow canvas renders the source paths with QSvgRenderer, preserving
|
||||
their original colors and geometry at the current canvas zoom and screen DPI.
|
||||
The workflow node style follows NodeTitle.vue (36px badge, 22px icon, 15px title).
|
||||
1
resources/workflow-icons/agv.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect width="24" height="24" rx="7" fill="#65bee0"/><g fill="none" stroke="#fff" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><rect x="5" y="9" width="14" height="8" rx="2"/><path d="M8 9V6h8v3M8 17v2m8-2v2M8 13h1m6 0h1M10 6V4h4v2"/></g></svg>
|
||||
|
After Width: | Height: | Size: 325 B |
1
resources/workflow-icons/arm.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect width="24" height="24" rx="7" fill="#65bee0"/><g fill="none" stroke="#fff" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="M5 19h14M8 19v-3l5-5-4-4M13 11l3 2 3-3M16 13v3m3-6 1 2"/><circle cx="8" cy="6" r="2"/><circle cx="13" cy="11" r="1.5"/><path d="M8 16h5v3"/></g></svg>
|
||||
|
After Width: | Height: | Size: 367 B |
1
resources/workflow-icons/audio.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg t="1758526814700" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="11094" width="200" height="200"><path d="M983.779623 312.719408a510.292483 510.292483 0 0 0-109.795373-162.701951A511.088926 511.088926 0 0 0 512.000853 0.001707a508.756485 508.756485 0 0 0-361.983396 150.01575A511.088926 511.088926 0 0 0 0.001707 512.000853a508.756485 508.756485 0 0 0 150.01575 361.983397 511.088926 511.088926 0 0 0 162.701951 109.738484c63.089673 26.680844 130.161561 40.163489 199.281445 40.163488a508.756485 508.756485 0 0 0 199.281446-40.163488 508.358264 508.358264 0 0 0 162.701951-109.738484 511.088926 511.088926 0 0 0 109.738484-162.701951c26.680844-63.089673 40.163489-130.161561 40.163488-199.281446a508.642708 508.642708 0 0 0-40.106599-199.281445z m-55.295908 375.181597a451.583247 451.583247 0 0 1-96.881617 143.701093 451.583247 451.583247 0 0 1-143.701093 96.881617c-55.751018 23.60885-114.915364 35.498608-175.900152 35.498607a448.397475 448.397475 0 0 1-175.900151-35.498607 451.583247 451.583247 0 0 1-143.701094-96.881617 451.583247 451.583247 0 0 1-96.881616-143.701093A448.397475 448.397475 0 0 1 60.019384 512.000853c0-60.984787 11.889758-120.206022 35.498608-175.900151 22.755518-53.816799 55.409685-102.172274 96.881616-143.701094a451.583247 451.583247 0 0 1 143.701094-96.881616A448.397475 448.397475 0 0 1 512.000853 60.019384c60.984787 0 120.206022 11.889758 175.900152 35.498608 53.816799 22.755518 102.172274 55.409685 143.701093 96.881616 41.52882 41.52882 74.126099 89.884295 96.881617 143.701094 23.60885 55.751018 35.498608 114.915364 35.498607 175.900151s-11.889758 120.206022-35.498607 175.900152z" fill="#65BEE0" p-id="11095"></path><path d="M263.965711 416.029458a30.094172 30.094172 0 0 0-29.980394 29.980394v131.982002a30.094172 30.094172 0 0 0 60.017677 0V446.009852a30.094172 30.094172 0 0 0-29.980394-29.980394z m124.017571-63.999894a30.094172 30.094172 0 0 0-29.980394 29.980395v259.981789c0 16.49775 13.482644 29.980394 29.980394 29.980394 16.49775 0 30.037283-13.482644 30.037284-29.980394v-259.981789a30.094172 30.094172 0 0 0-30.037284-29.980395zM512.000853 256.00128a30.094172 30.094172 0 0 0-29.980394 29.980394v452.038358c0 16.49775 13.482644 29.980394 29.980394 29.980395 16.49775 0 29.980394-13.482644 29.980395-29.980395V285.981674A30.094172 30.094172 0 0 0 512.000853 256.00128z m248.035142 160.028178a30.094172 30.094172 0 0 0-30.037283 29.980394v131.982002c0 16.49775 13.482644 29.980394 29.980395 29.980395 16.49775 0 30.037283-13.482644 30.037283-29.980395V446.009852a30.094172 30.094172 0 0 0-30.037283-29.980394z m-124.017571-63.999894a30.094172 30.094172 0 0 0-30.037283 29.980395v259.981789a30.094172 30.094172 0 0 0 60.017678 0v-259.981789a30.094172 30.094172 0 0 0-29.980395-29.980395z" fill="#65BEE0" p-id="11096"></path></svg>
|
||||
|
After Width: | Height: | Size: 2.8 KiB |
1
resources/workflow-icons/camera.svg
Normal file
@ -0,0 +1 @@
|
||||
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1751611040437" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="11706" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M721.6896 390.4512H629.952c-7.36-0.059733-13.9008-3.8912-17.117867-9.992533l-33.9072-62.916267H445.073067L411.144533 380.501333c-3.2 6.058667-9.736533 9.890133-17.0496 9.949867H302.3104c-25.984 0-46.3488 18.875733-46.3488 42.973867v230.8736c0 24.085333 20.356267 42.965333 46.3488 42.965333h419.383467c26.001067 0 46.357333-18.884267 46.357333-42.965333V433.425067c-0.008533-24.098133-20.360533-42.973867-46.3616-42.973867zM512 688.1152c-82.824533 0-150.212267-62.468267-150.212267-139.2512C361.787733 472.072533 429.175467 409.6 512 409.6c82.833067 0 150.2336 62.472533 150.2336 139.268267 0 76.782933-67.400533 139.246933-150.2336 139.246933z" fill="#65BEE0" p-id="11707"></path><path d="M512 0C229.2224 0 0 229.230933 0 512c0 282.7648 229.2224 512 512 512 282.781867 0 512-229.2352 512-512C1024 229.230933 794.781867 0 512 0zM292.974933 298.734933c0-3.106133 2.722133-5.6192 6.058667-5.6192h24.840533c3.3536 0 6.058667 2.5088 6.058667 5.6192v23.022934c0 3.106133-2.7136 5.614933-6.058667 5.614933h-24.840533c-3.336533 0-6.058667-2.513067-6.058667-5.614933v-23.022934zM806.4 664.298667c0 43.285333-37.998933 78.4896-84.7104 78.4896H302.3104C255.598933 742.792533 217.6 707.584 217.6 664.298667V433.425067C217.6 390.126933 255.598933 354.901333 302.3104 354.901333h79.803733l34.154667-63.1552c2.999467-5.504 8.708267-9.122133 15.291733-9.710933a15.581867 15.581867 0 0 1 1.979734-0.0256h157.102933c7.240533 0 13.768533 3.720533 17.066667 9.7024l34.176 63.189333h79.799466c46.715733 0 84.714667 35.2256 84.714667 78.523734v230.8736z" fill="#65BEE0" p-id="11708"></path><path d="M512 445.124267c-29.9776 0-58.0864 10.773333-79.189333 30.331733-21.085867 19.549867-32.699733 45.623467-32.699734 73.408s11.613867 53.8496 32.699734 73.399467c21.098667 19.5584 49.207467 30.331733 79.189333 30.331733 29.981867 0 58.082133-10.773333 79.185067-30.331733s32.7168-45.623467 32.7168-73.399467c0-27.784533-11.618133-53.8496-32.7168-73.408-21.085867-19.554133-49.2032-30.331733-79.185067-30.331733zM609.809067 549.333333c-0.174933 9.642667-8.759467 17.493333-19.1488 17.493334h-0.290134c-5.1328-0.0768-9.915733-1.992533-13.482666-5.410134-3.549867-3.383467-5.474133-7.867733-5.4016-12.599466 0-14.784-6.173867-28.6336-17.348267-39.0016-11.157333-10.333867-26.048-16.055467-41.9456-16.1024-10.487467 0.580267-19.524267-6.8864-20.2496-16.520534-0.3584-4.7232 1.288533-9.309867 4.650667-12.898133 3.362133-3.605333 8.021333-5.764267 13.141333-6.097067 0.827733-0.059733 1.646933-0.059733 2.466133-0.017066 53.853867 0.093867 97.621333 40.7296 97.621334 90.670933v0.482133h-0.0128z" fill="#65BEE0" p-id="11709"></path></svg>
|
||||
|
After Width: | Height: | Size: 2.9 KiB |
1
resources/workflow-icons/end.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg class="llm-icon llm-icon-workflow-end " width="1em" height="1em" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20"><rect width="20" height="20" fill="#65BEE0" rx="6"></rect><path fill="#fff" d="M13.143 5.858c.368.261.695.557.98.888.287.331.532.689.736 1.073a5.41 5.41 0 0 1 .625 2.524 5.3 5.3 0 0 1-.435 2.139 5.594 5.594 0 0 1-1.176 1.74 5.597 5.597 0 0 1-1.74 1.176 5.296 5.296 0 0 1-2.14.435c-.75 0-1.46-.145-2.125-.435a5.67 5.67 0 0 1-1.747-1.176 5.459 5.459 0 0 1-1.176-1.74 5.36 5.36 0 0 1-.429-2.139c0-.433.051-.858.153-1.274a5.65 5.65 0 0 1 .435-1.189c.188-.376.421-.727.699-1.054.278-.327.588-.62.931-.882a.755.755 0 0 1 .582-.147.769.769 0 0 1 .509.306c.13.172.18.364.147.576a.773.773 0 0 1-.306.515 3.804 3.804 0 0 0-1.183 1.384 3.892 3.892 0 0 0-.41 1.765c0 .54.101 1.048.306 1.526a3.937 3.937 0 0 0 2.09 2.095c.477.209.985.313 1.525.313.539 0 1.047-.104 1.525-.313.478-.208.895-.49 1.25-.845.356-.356.638-.772.846-1.25.208-.478.313-.987.313-1.526 0-.637-.148-1.24-.442-1.807a3.823 3.823 0 0 0-1.237-1.404.738.738 0 0 1-.325-.502.774.774 0 0 1 .129-.588.75.75 0 0 1 .502-.313.774.774 0 0 1 .588.129Zm-3.15 4.522a.743.743 0 0 1-.544-.227.744.744 0 0 1-.227-.545V4.95a.76.76 0 0 1 .227-.551.733.733 0 0 1 .545-.233c.22 0 .406.077.557.232a.763.763 0 0 1 .227.552v4.657a.743.743 0 0 1-.227.545.758.758 0 0 1-.557.227Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
1
resources/workflow-icons/expression.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg t="1762999534829" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4760" width="200" height="200"><path d="M512 979C263.472 979 62 777.528 62 529S263.472 79 512 79s450 201.472 450 450-201.472 450-450 450zM337 479c41.421 0 75-33.579 75-75s-33.579-75-75-75-75 33.579-75 75 33.579 75 75 75z m350 0c41.421 0 75-33.579 75-75s-33.579-75-75-75-75 33.579-75 75 33.579 75 75 75zM312 629c0 110.457 89.543 200 200 200s200-89.543 200-200H312z" fill="#65BEE0" p-id="4761"></path></svg>
|
||||
|
After Width: | Height: | Size: 520 B |
1
resources/workflow-icons/hand.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect width="24" height="24" rx="7" fill="#65bee0"/><path d="M8 12V7a1 1 0 0 1 2 0v4-6a1 1 0 0 1 2 0v6-5a1 1 0 0 1 2 0v5-3a1 1 0 0 1 2 0v6l1-2a1.2 1.2 0 0 1 2 1l-2 5a4 4 0 0 1-4 2h-2a4 4 0 0 1-4-3l-2-4a1 1 0 0 1 2-1l1 2" fill="none" stroke="#fff" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
|
||||
|
After Width: | Height: | Size: 381 B |
1
resources/workflow-icons/loop.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg class="llm-icon llm-icon-cycle-vertices " width="1em" height="1em" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20"><rect width="20" height="20" fill="#65BEE0" rx="6"></rect><path fill="#fff" fill-rule="evenodd" d="M15.7028 9.15436C15.7418 9.67543 15.7028 10.8288 15.5783 11.3128L17.5 11.5591L15.447 12.8685L13.3941 14.1797L11.8043 12.3341L10.2135 10.4894L12.6676 10.748C12.7142 10.4456 12.739 10.1376 12.7371 9.82282C12.7199 7.26403 10.3951 5.10365 8.10917 4.31062C11.1453 3.53947 15.4252 5.38796 15.7028 9.15436ZM4.23534 10.689C4.21062 10.1679 4.27718 9.01452 4.41505 8.53528L2.5 8.23956L4.58621 6.98061L6.67147 5.72356L8.21378 7.60913L9.75609 9.49186L7.3095 9.17427C7.2553 9.47379 7.22297 9.78187 7.21632 10.0966C7.16877 12.6545 9.43755 14.8719 11.7035 15.7239C8.64928 16.417 4.41695 14.4621 4.23534 10.689Z" clip-rule="evenodd"></path></svg>
|
||||
|
After Width: | Height: | Size: 868 B |
4
resources/workflow-icons/microphone.svg
Normal file
@ -0,0 +1,4 @@
|
||||
<svg t="1754641759358" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6343" width="200" height="200">
|
||||
<path d="M512 512m-512 0a512 512 0 1 0 1024 0 512 512 0 1 0-1024 0Z" fill="#65BEE0" p-id="6344"></path>
|
||||
<path d="M512 691.2c-112.64 0-204.8-92.16-204.8-204.8v-25.6c0-7.68 5.12-12.8 12.8-12.8s12.8 5.12 12.8 12.8V485.12c0 98.56 80.64 179.2 179.2 179.2s179.2-80.64 179.2-179.2v-23.04-1.28c0-7.68 5.12-12.8 12.8-12.8s12.8 5.12 12.8 12.8v25.6c0 112.64-92.16 204.8-204.8 204.8z m12.8 38.4h38.4c7.68 0 12.8 5.12 12.8 12.8s-5.12 12.8-12.8 12.8h-102.4c-7.68 0-12.8-5.12-12.8-12.8s5.12-12.8 12.8-12.8h38.4v-38.4h25.6v38.4z m-12.8-89.6c-84.48 0-153.6-69.12-153.6-153.6v-64c0-84.48 69.12-153.6 153.6-153.6s153.6 69.12 153.6 153.6v64c0 84.48-69.12 153.6-153.6 153.6z" fill="#fff" p-id="6345">
|
||||
</path></svg>
|
||||
|
After Width: | Height: | Size: 840 B |
1
resources/workflow-icons/motor.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" fill="none" stroke="#1677ff" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><rect x="8" y="13" width="27" height="24" rx="5"/><path d="M35 21h8v8h-8M13 37v5h17v-5M14 8h14M15 20v10M22 20v10M29 20v10"/></svg>
|
||||
|
After Width: | Height: | Size: 284 B |
1
resources/workflow-icons/plan.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg t="1758526128932" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2666" width="200" height="200"><path d="M512 575.146667c-10.922667 0-21.845333-2.730667-31.402667-8.192L352.426667 494.933333l-48.810667 27.477334L512 639.658667l208.384-117.248L671.573333 494.933333l-128.170666 72.192c-9.557333 5.290667-20.48 8.021333-31.402667 8.021334z" fill="#65BEE0" p-id="2667"></path><path d="M512 708.437333c-10.922667 0-21.845333-2.730667-31.402667-8.192l-146.432-82.432-30.378666 17.237334L512 752.128l208.384-117.248-30.378667-17.237333-146.432 82.432c-9.728 5.632-20.650667 8.362667-31.573333 8.362666z" fill="#65BEE0" p-id="2668"></path><path d="M512 34.133333C248.149333 34.133333 34.133333 248.149333 34.133333 512s214.016 477.866667 477.866667 477.866667 477.866667-214.016 477.866667-477.866667S775.850667 34.133333 512 34.133333z m248.149333 432.128c20.138667 11.434667 32.768 32.768 32.768 55.978667 0 23.210667-12.458667 44.544-32.597333 55.978667l-0.853333 0.341333 0.682666 0.341333c20.138667 11.264 32.768 32.768 32.768 55.808 0 23.210667-12.458667 44.544-32.768 55.978667l-216.746666 122.026667a64.529067 64.529067 0 0 1-62.976 0l-216.746667-122.026667a64.494933 64.494933 0 0 1-32.768-55.978667c0-23.210667 12.629333-44.544 32.768-55.978666l0.682667-0.341334-0.682667-0.341333a64.494933 64.494933 0 0 1-32.768-55.978667c0-23.210667 12.629333-44.544 32.768-55.978666l18.944-10.581334-18.944-10.752a64.494933 64.494933 0 0 1-32.768-55.978666c0-23.210667 12.458667-44.544 32.768-55.978667l216.746667-122.026667c19.456-10.922667 43.52-10.922667 62.976 0l216.746666 122.026667c20.138667 11.434667 32.768 32.768 32.768 55.978667 0 23.210667-12.629333 44.544-32.768 55.978666l-18.944 10.752 18.944 10.752z" fill="#65BEE0" p-id="2669"></path><path d="M720.384 389.12L512 271.701333 303.616 389.12 512 506.368z" fill="#65BEE0" p-id="2670"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.9 KiB |
1
resources/workflow-icons/sleep.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg t="1754883869250" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6366" width="200" height="200"><path d="M511.942201 0.978972C230.218595 0.978972 1.018709 229.934416 1.018709 511.356985c0 281.420161 229.199886 510.373196 510.923492 510.373197 281.726014 0 510.921084-228.953036 510.921084-510.373197C1022.863285 229.934416 793.668215 0.978972 511.942201 0.978972z m84.587765 239.952925h133.102877c8.273699 0 15.674391 4.957476 18.846116 12.63151 3.140417 7.601785 1.293255 16.53054-4.591415 22.216526l-95.881467 94.255867h105.926467c11.23229 0 20.366955 9.139481 20.366955 20.366954 0 11.23229-9.134665 20.371771-20.366955 20.371772H598.204936c-8.273699 0-15.66837-4.957476-18.836483-12.624285-3.146438-7.604193-1.299275-16.532948 4.591415-22.218934l95.882671-94.260684h-83.312573c-11.226269 0-20.366955-9.139481-20.366955-20.366954 0-11.23229 9.140685-20.371771 20.366955-20.371772z m134.256451 490.555334c-58.528804 58.436085-136.258948 90.615729-218.863482 90.615728-82.637046 0-160.333474-32.182052-218.770763-90.615728-58.430064-58.5276-90.614525-136.222824-90.614525-218.770763 0-164.332448 128.456071-300.023039 292.439317-308.918078 0.356428-0.016858 0.704426-0.025287 1.048812-0.025287 5.907549 0 11.47312 2.498607 15.266185 6.862438 4.10494 4.721463 5.882262 10.910783 4.873186 16.980891a321.126932 321.126932 0 0 0-4.350586 52.586335c0 90.50856 20.866676 158.725936 60.345863 197.283951 27.012646 26.394918 63.881241 39.780224 109.590689 39.780224 1.812242 0 3.659405-0.025287 5.494526-0.065024 36.498922-0.829658 70.802682-15.056663 99.19769-41.144523 3.738879-3.472762 8.649393-5.386153 13.816391-5.386153a20.238111 20.238111 0 0 1 7.465716 1.414873c7.185149 2.834564 12.222099 9.665694 12.833806 17.408364 0.558725 7.670421 0.838087 15.479319 0.842903 23.221989 0 82.641862-32.179644 160.340699-90.615728 218.770763z" fill="#64bee0" p-id="6367"></path><path d="M681.386256 557.917765c-56.540756 0-102.916098-17.292765-137.829157-51.395433-25.397884-24.834343-44.40656-58.383102-56.496203-99.710656-10.669953-36.404998-16.078985-79.036644-16.078984-126.710057 0.089107-11.544164 0.60689-22.433272 1.570209-33.232069C341.690162 266.020315 243.273965 379.91222 243.273965 512.711651c0 148.134253 120.514717 268.64897 268.64897 268.64897 141.259774 0 258.335445-109.519644 267.978259-249.956985-28.292655 16.821944-59.169411 25.714575-91.830714 26.438268-2.231286 0.054187-4.480634 0.075861-6.684224 0.075861z" fill="#64bee0" p-id="6368"></path></svg>
|
||||
|
After Width: | Height: | Size: 2.5 KiB |
6
resources/workflow-icons/start.svg
Normal file
@ -0,0 +1,6 @@
|
||||
<svg class="llm-icon llm-icon-workflow-start " width="1em" height="1em" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20">
|
||||
<rect width="20" height="20" fill="#65BEE0" rx="6"></rect>
|
||||
<g clip-path="url(#svg_7692d94d0f__a)">
|
||||
<path fill="#fff" d="M13.448 8.979c.736.483.736 1.692 0 2.176l-5.793 3.808C6.92 15.447 6 14.843 6 13.875V6.258c0-.967.92-1.571 1.655-1.088l5.793 3.809Z"></path>
|
||||
</g>
|
||||
<defs><clipPath id="svg_7692d94d0f__a"><path fill="#fff" d="M3 3h14v14H3z"></path></clipPath></defs></svg>
|
||||
|
After Width: | Height: | Size: 515 B |
1
resources/workflow-icons/touch.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg t="1762762024042" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7115" width="200" height="200"><path d="M512 512m-512 0a512 512 0 1 0 1024 0 512 512 0 1 0-1024 0Z" fill="#65BEE0" p-id="7116" data-spm-anchor-id="a313x.search_index.0.i4.2cb83a81yhcKKA" class="selected"></path><path d="M440.018824 310.452706c6.625882 0 13.703529 2.198588 20.781176 7.68 11.294118 8.884706 17.709176 22.588235 17.769412 36.954353l0.391529 108.242823 0.120471 43.248942 0.150588 31.442823s20.239059-27.648 49.935059-27.648c15.932235 0 34.484706 7.890824 54.091294 32.165647 0 0 18.191059-30.539294 47.435294-30.539294 15.36 0 33.731765 8.342588 54.091294 33.912471 0 0 17.588706-34.424471 41.562353-34.424471 8.071529 0 16.865882 3.915294 25.99153 14.486588 10.752 12.739765 16.564706 29.063529 16.564705 45.808941v230.098824s-0.722824 5.963294-7.168 14.938353a63.608471 63.608471 0 0 1-51.83247 26.352941l-239.555765 0.060235a73.396706 73.396706 0 0 1-57.313882-27.557647l-131.373177-164.111059a46.019765 46.019765 0 0 1-6.595764-46.983529c4.517647-10.390588 13.251765-19.275294 29.635764-19.275294 8.432941 0 18.763294 2.349176 31.62353 7.951059 42.736941 19.154824 58.006588 59.542588 58.006588 59.542588l0.692706-146.100706 0.210823-43.158588 0.512-105.682824c0.060235-14.546824 6.716235-28.400941 18.31153-37.255529 7.228235-5.571765 16.263529-10.149647 25.961412-10.149647zM436.705882 180.705882a165.647059 165.647059 0 0 1 123.723294 275.787294 38.068706 38.068706 0 0 1-29.455058 12.468706h-1.987765a8.794353 8.794353 0 0 1-8.734118-8.734117l-0.090353-15.450353a15.058824 15.058824 0 0 1 4.336942-10.541177l0.090352-0.090353a123.392 123.392 0 0 0 36.352-87.792941c0-33.189647-12.950588-64.391529-36.352-87.883294A123.663059 123.663059 0 0 0 436.705882 222.117647c-33.189647 0-64.391529 12.950588-87.883294 36.352a123.663059 123.663059 0 0 0-36.352 87.883294c0 33.189647 12.950588 64.391529 36.352 87.883294l0.090353 0.060236c3.162353 3.162353 4.969412 7.499294 4.909177 11.956705a21.353412 21.353412 0 0 1-36.74353 14.697412A165.647059 165.647059 0 0 1 436.705882 180.705882z" fill="#ffffff" p-id="7117" data-spm-anchor-id="a313x.search_index.0.i3.2cb83a81yhcKKA" class=""></path></svg>
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
3
resources/workflow-icons/video.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg t="1752214385087" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="22912" id="mx_n_1752214385087" width="200" height="200">
|
||||
<path d="M22.658333 502.958333c0 79.929167 12.929167 142.658333 44.195834 212.2375 23.866667 53.104167 53.633333 94.970833 92.716666 137.2125 39.466667 42.645833 92.1125 77.8375 143.766667 103.866667 44.129167 22.2375 126.375 47.141667 191.6625 47.141667h40.6875c89.683333 0 200.170833-41.408333 265.1125-90.433334l25.291667-18.933333c3.383333-2.754167 4.916667-4.875 8.308333-7.604167 48.625-39.1375 106.620833-114.6 129.158333-169.75 31.991667-78.2875 44.475-123.704167 44.475-213.733333 0-107.270833-39.370833-208.329167-101.341666-291.2875-4.275-5.729167-8.595833-11.6375-13.2375-16.829167-65.329167-73.079167-121.3-113.216667-215.470834-148.9-46.554167-17.641667-96.358333-26.429167-146.5625-27.525h-21.558333c-53.033333 1.141667-106.058333 10.654167-155.725 27.195834-8.720833 2.904167-14.5875 4.85-21.945833 8.125-41.483333 18.475-80.633333 37.0875-116.158334 66.029166l-24.075 20.141667C114.5125 205.3875 61.308333 296.270833 36.454167 394.729167c-7.570833 29.975-13.795833 70.329167-13.795834 108.229166z" fill="#65BEE0" p-id="22913"></path>
|
||||
<path d="M677.225 610.004167c9.7 2.791667 58.783333 32.220833 71.15 39.3375 23.420833 13.475 46.275 26.466667 69.804167 39.845833 42.375 24.1 32.45-40.475 32.45-67.75V400.391667c0-27.479167 8.641667-90.616667-31.95-67.2375a9526.625 9526.625 0 0 1-69.891667 39.745833c-11.554167 6.525-63.3125 37.641667-71.145833 39.829167-0.591667-61.695833 6.2-118.329167-88.875-118.291667H277.404167c-38.979167 0-60.320833 1.220833-80.0625 24.183333-21.291667 24.758333-17.229167 49.6125-17.229167 87.075v206.904167c0 38.2-4.554167 61.533333 15.345833 88.9875 15.979167 22.054167 41.204167 26.425 78.404167 26.420833h311.358333c38.166667 0.004167 58.758333-3.583333 77.6-27.204166 18.229167-22.845833 15.033333-57.375 14.404167-90.8z" fill="#fff" p-id="22914" data-spm-anchor-id="a313x.search_index.0.i4.7c873a81tBoiJp" class=""></path></svg>
|
||||
|
After Width: | Height: | Size: 2.0 KiB |
@ -84,9 +84,9 @@ void layoutFreshGraph(QJsonObject &graph) {
|
||||
qreal cursor=left;QSet<QString> seen;
|
||||
while(!id.isEmpty()&&!seen.contains(id)) {
|
||||
seen.insert(id);auto n=lookup.value(id);const QString type=n.value("type").toString();
|
||||
qreal width=type=="serviceNode"||type=="loop"?270:90;
|
||||
qreal width=type=="serviceNode"||type=="loop"?300:260;
|
||||
if(type=="loop")width=qMax(width,place(id,cursor+60,y+240)+120);
|
||||
n.insert("x",cursor+(type=="loop"?135:width/2));n.insert("y",y);lookup[id]=n;
|
||||
n.insert("x",cursor+(type=="loop"?150:width/2));n.insert("y",y);lookup[id]=n;
|
||||
cursor+=width+100;id=next.value(id);
|
||||
}return qMax(0.,cursor-left-100);
|
||||
};
|
||||
@ -231,7 +231,7 @@ bool importGraph(const QJsonObject &input,QJsonObject &document,QString &error,b
|
||||
const auto e=v.toObject();const QString from=e.value("sourceNodeId").toString(),to=e.value("targetNodeId").toString();
|
||||
require(lookup.contains(from)&&lookup.contains(to),QStringLiteral("连线引用不存在的节点"));
|
||||
require(parent[from]==parent[to],QStringLiteral("不支持跨循环容器连线"));
|
||||
require(!next.contains(from)&&!previous.contains(to),QStringLiteral("存在分支或汇合,上位机不能将其转换为顺序流程"));
|
||||
require(draft||(!next.contains(from)&&!previous.contains(to)),QStringLiteral("并行图不能转换为旧版顺序流程,请使用图执行器"));
|
||||
next[from]=to;previous[to]=from;
|
||||
}
|
||||
QSet<QString> visited;
|
||||
@ -266,6 +266,7 @@ bool importGraph(const QJsonObject &input,QJsonObject &document,QString &error,b
|
||||
result.append(QJsonObject{{"id",id},{"kind","loop"},{"name",name},{"count",int(count)},
|
||||
{"collapsed",p.value("collapsed")},{"children",read(id,depth+1)}});
|
||||
} else if(type=="sleep") {
|
||||
if(draft&&!pointMode){id=next.value(id);continue;}
|
||||
const double delay=numeric(params.value("delayMs"));
|
||||
require(delay>=0&&delay<=2147483647&&delay==std::floor(delay),
|
||||
QStringLiteral("等待节点只能跟在任务或循环之后,且时长不超过2147483647毫秒"));
|
||||
|
||||
@ -35,8 +35,8 @@
|
||||
#include <functional>
|
||||
|
||||
namespace {
|
||||
constexpr qreal kNodeWidth = 190.0;
|
||||
constexpr qreal kNodeHeight = 76.0;
|
||||
constexpr qreal kNodeWidth = 300.0;
|
||||
constexpr qreal kNodeHeight = 110.0;
|
||||
|
||||
using FlowGraphicsView = WorkflowCanvas;
|
||||
|
||||
@ -63,49 +63,14 @@ public:
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
|
||||
{
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
const QColor fill = m_loop ? QColor("#f4efff") : QColor("#ffffff");
|
||||
const QColor border = m_active ? QColor("#20a36a")
|
||||
: (isSelected() ? QColor("#1b6ef3") : QColor("#cbd6e2"));
|
||||
painter->setPen(QPen(border, m_active ? 3.0 : 1.5));
|
||||
painter->setBrush(fill);
|
||||
painter->drawRoundedRect(boundingRect().adjusted(1, 1, -1, -1), 10, 10);
|
||||
painter->setPen(QColor("#25313d"));
|
||||
QFont titleFont = painter->font();
|
||||
titleFont.setBold(true);
|
||||
painter->setFont(titleFont);
|
||||
painter->drawText(QRectF(14, 10, kNodeWidth - (m_loop ? 58 : 28), 25),
|
||||
Qt::AlignLeft | Qt::AlignVCenter,
|
||||
painter->fontMetrics().elidedText(m_title,Qt::ElideRight,int(kNodeWidth-(m_loop?58:28))));
|
||||
if (m_loop) {
|
||||
const QColor buttonFill = m_collapsePressed ? QColor("#d8e9ff")
|
||||
: m_collapseHovered ? QColor("#e8f2ff") : QColor("#ffffff");
|
||||
const QColor buttonBorder = m_collapseHovered || m_collapsePressed
|
||||
? QColor("#1b6ef3") : QColor("#b8c7d8");
|
||||
painter->setPen(QPen(buttonBorder, 1.4));
|
||||
painter->setBrush(buttonFill);
|
||||
painter->drawRoundedRect(collapseButtonRect(), 5, 5);
|
||||
painter->setPen(QPen(QColor("#286fc2"), 1.8,
|
||||
Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
const QPointF center = collapseButtonRect().center();
|
||||
QPolygonF arrow;
|
||||
if (m_collapsed) {
|
||||
arrow << QPointF(center.x() - 3.5, center.y() - 5)
|
||||
<< QPointF(center.x() + 2.0, center.y())
|
||||
<< QPointF(center.x() - 3.5, center.y() + 5);
|
||||
} else {
|
||||
arrow << QPointF(center.x() - 5, center.y() - 3.0)
|
||||
<< QPointF(center.x(), center.y() + 2.5)
|
||||
<< QPointF(center.x() + 5, center.y() - 3.0);
|
||||
}
|
||||
painter->drawPolyline(arrow);
|
||||
workflowCardPaint(painter,boundingRect(),m_title,m_subtitle,
|
||||
m_active?QColor("#20a36a"):m_loop?QColor("#a086d7"):QColor("#557799"),isSelected(),m_loop?25:0,
|
||||
m_loop?QStringLiteral("loop"):QStringLiteral("arm"));
|
||||
if(m_loop) {
|
||||
painter->setPen(QColor("#73849a"));
|
||||
painter->drawText(collapseButtonRect(),Qt::AlignCenter,m_collapsed?QStringLiteral("+"):QStringLiteral("−"));
|
||||
}
|
||||
painter->setFont(QFont());
|
||||
painter->setPen(QColor("#687684"));
|
||||
painter->drawText(QRectF(14, 38, kNodeWidth - 28, 26), Qt::AlignLeft | Qt::AlignVCenter,
|
||||
painter->fontMetrics().elidedText(m_subtitle,Qt::ElideRight,int(kNodeWidth-28)));
|
||||
}
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
|
||||
{
|
||||
@ -248,10 +213,14 @@ JointFlowEditor::JointFlowEditor(QWidget *parent) : QWidget(parent)
|
||||
inspectorScroll->setFrameShape(QFrame::NoFrame);
|
||||
inspectorScroll->setWidget(inspector);
|
||||
auto *toggleInspector = new QPushButton(QStringLiteral("节点参数"),canvasTools);
|
||||
toggleInspector->setCheckable(true);toggleInspector->setChecked(true);
|
||||
toggleInspector->setCheckable(true);toggleInspector->setChecked(false);
|
||||
toggleInspector->setObjectName(QStringLiteral("secondaryButton"));
|
||||
static_cast<QHBoxLayout *>(canvasTools->layout())->insertWidget(0,toggleInspector);
|
||||
connect(toggleInspector,&QPushButton::toggled,inspectorScroll,&QWidget::setVisible);
|
||||
inspectorScroll->hide();
|
||||
connect(m_scene,&QGraphicsScene::selectionChanged,this,[this,toggleInspector] {
|
||||
if(!m_scene->selectedItems().isEmpty())toggleInspector->setChecked(true);
|
||||
});
|
||||
workspace->addWidget(m_view);workspace->addWidget(inspectorScroll);
|
||||
workspace->setStretchFactor(0,1);workspace->setSizes({800,240});
|
||||
inspector->setMinimumWidth(210);
|
||||
@ -769,7 +738,7 @@ void JointFlowEditor::rebuildScene()
|
||||
const QString title = node.nodeName;
|
||||
const QString executionUnit = node.type == LoopNode
|
||||
? QStringLiteral("循环 × %1").arg(node.loopCount) : node.pointName;
|
||||
const QString subtitle = QStringLiteral("执行:%1 · 等待 %2 s")
|
||||
const QString subtitle = QStringLiteral("执行点位:%1\n完成后等待 %2 s")
|
||||
.arg(executionUnit).arg(node.intervalSeconds, 0, 'f', 1);
|
||||
auto *card = new FlowCardItem(node.id, title, subtitle, node.type == LoopNode,
|
||||
node.id == m_activeNodeId, node.collapsed,
|
||||
|
||||
@ -715,6 +715,18 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
this, &MainWindow::appendLog);
|
||||
auto* taskRpcRunner=new TaskRpcRunner(m_client,this);
|
||||
connect(m_taskOrchestration,&TaskOrchestrationWidget::executionStopped,taskRpcRunner,&TaskRpcRunner::cancel);
|
||||
connect(m_taskOrchestration,&TaskOrchestrationWidget::workflowCallRequested,this,
|
||||
[this,taskRpcRunner](const QString &token,const QJsonObject &execution) {
|
||||
const auto generation=m_taskOrchestration->executionGeneration();
|
||||
taskRpcRunner->runConcurrent(execution,[this,token,generation,execution](bool ok,const QString &response) {
|
||||
if(generation!=m_taskOrchestration->executionGeneration())return;
|
||||
QString detail;const bool success=TaskApi::responseSucceeded(ok,response,detail);
|
||||
const auto method=execution.value("method").toString();
|
||||
if(execution.value("service")=="cmvr.api.ArmService"&&(method=="torqueOn"||method=="torqueOff"))
|
||||
emit m_client->torqueFinished(execution.value("request").toObject().value("device_id").toString(),method=="torqueOn",success,detail);
|
||||
m_taskOrchestration->completeWorkflowCall(token,success,detail);
|
||||
});
|
||||
});
|
||||
connect(m_taskOrchestration, &TaskOrchestrationWidget::taskRequested, this,
|
||||
[this,taskRpcRunner](const QString &deviceType, const QString &deviceId,
|
||||
const QString &action, const QJsonObject ¶meters) {
|
||||
|
||||
@ -20,6 +20,9 @@ public:
|
||||
m_table=new QTableWidget(0,3,this);m_table->setObjectName("taskJointTable");
|
||||
m_table->setHorizontalHeaderLabels({QStringLiteral("关节名称"),QStringLiteral("目标角度(°)"),QStringLiteral("允许范围(°)")});
|
||||
m_table->verticalHeader()->hide();m_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
m_table->horizontalHeader()->setSectionResizeMode(0,QHeaderView::ResizeToContents);
|
||||
m_table->horizontalHeader()->setSectionResizeMode(2,QHeaderView::ResizeToContents);
|
||||
m_table->setTextElideMode(Qt::ElideNone);
|
||||
m_table->setMinimumHeight(150);m_table->setMaximumHeight(400);layout->addWidget(m_table);
|
||||
}
|
||||
void setDevice(const QVariantMap& info,const QJsonArray& values={},bool checkLimits=true) {
|
||||
@ -34,7 +37,7 @@ public:
|
||||
QStringLiteral("逐关节填写角速度;保存时换算为弧度/秒。")));
|
||||
if(mismatched)m_hint->setText(QStringLiteral("原目标数量与设备关节数不一致,请按当前关节列表重新填写。"));
|
||||
for(int i=0;i<m_names.size();++i){
|
||||
auto* name=new QTableWidgetItem(m_names[i]);name->setFlags(Qt::ItemIsEnabled);m_table->setItem(i,0,name);
|
||||
auto* name=new QTableWidgetItem(m_names[i]);name->setFlags(Qt::ItemIsEnabled);name->setToolTip(m_names[i]);m_table->setItem(i,0,name);
|
||||
auto* edit=new QLineEdit(m_table);edit->setObjectName(QString("jointTarget_%1").arg(i));
|
||||
edit->setProperty("taskJointName",m_names[i]);
|
||||
edit->setValidator(new QDoubleValidator(-1e12,1e12,9,edit));edit->setPlaceholderText(QStringLiteral("输入角度"));
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include "freescaninterop.h"
|
||||
#include "freescaninteropui.h"
|
||||
#include "workflowgraph.h"
|
||||
#include "workflowruntime.h"
|
||||
#include "taskapi.h"
|
||||
#include "taskprotoeditor.h"
|
||||
#include "taskuilabels.h"
|
||||
@ -74,8 +75,8 @@ void captureTaskExpansion(QTreeWidgetItem *item)
|
||||
for (int i = 0; i < item->childCount(); ++i) captureTaskExpansion(item->child(i));
|
||||
}
|
||||
|
||||
constexpr qreal kTaskCardWidth = 270.0;
|
||||
constexpr qreal kTaskCardHeight = 94.0;
|
||||
constexpr qreal kTaskCardWidth = 300.0;
|
||||
constexpr qreal kTaskCardHeight = 110.0;
|
||||
|
||||
using TaskFlowView = WorkflowCanvas;
|
||||
|
||||
@ -102,39 +103,16 @@ public:
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
|
||||
{
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
const QString state = m_source->data(0, RunStateRole).toString();
|
||||
QColor stateColor = state == QStringLiteral("running") ? QColor("#1b6ef3")
|
||||
: state == QStringLiteral("success") ? QColor("#20a36a")
|
||||
: state == QStringLiteral("failed") ? QColor("#d44343") : QColor("#cbd6e2");
|
||||
painter->setPen(QPen(isSelected() ? QColor("#1b6ef3") : stateColor,
|
||||
isSelected() || !state.isEmpty() ? 2.0 : 1.4));
|
||||
painter->setBrush(state == QStringLiteral("running") ? QColor("#eef5ff")
|
||||
: state == QStringLiteral("success") ? QColor("#effaf5")
|
||||
: state == QStringLiteral("failed") ? QColor("#fff2f2")
|
||||
: m_loop ? QColor("#f4efff") : QColor("#ffffff"));
|
||||
painter->drawRoundedRect(boundingRect().adjusted(1, 1, -1, -1), 10, 10);
|
||||
QFont titleFont = painter->font(); titleFont.setBold(true);
|
||||
painter->setFont(titleFont); painter->setPen(QColor("#25313d"));
|
||||
painter->drawText(QRectF(14, 9, kTaskCardWidth - (m_loop ? 52 : 28), 27),
|
||||
Qt::AlignLeft | Qt::AlignVCenter,
|
||||
painter->fontMetrics().elidedText(m_title, Qt::ElideRight,
|
||||
int(kTaskCardWidth - (m_loop ? 52 : 28))));
|
||||
painter->setFont(QFont()); painter->setPen(QColor("#687684"));
|
||||
painter->drawText(QRectF(14, 38, kTaskCardWidth - (m_loop ? 52 : 28), 45),
|
||||
Qt::AlignLeft | Qt::AlignVCenter | Qt::TextWordWrap, m_subtitle);
|
||||
if (m_loop) {
|
||||
painter->setPen(QPen(QColor("#b8c7d8"), 1.2)); painter->setBrush(Qt::white);
|
||||
painter->drawRoundedRect(toggleRect(), 5, 5);
|
||||
painter->setPen(QPen(QColor("#286fc2"), 1.8));
|
||||
const QPointF c = toggleRect().center();
|
||||
if (m_source->isExpanded())
|
||||
painter->drawPolyline(QPolygonF() << QPointF(c.x()-5,c.y()-3) << QPointF(c.x(),c.y()+3) << QPointF(c.x()+5,c.y()-3));
|
||||
else
|
||||
painter->drawPolyline(QPolygonF() << QPointF(c.x()-3,c.y()-5) << QPointF(c.x()+3,c.y()) << QPointF(c.x()-3,c.y()+5));
|
||||
const QString state=m_source->data(0,RunStateRole).toString();
|
||||
const QColor accent=state=="failed"?QColor("#e05b64"):state=="success"?QColor("#20a36a"):
|
||||
state=="running"?QColor("#357dff"):m_loop?QColor("#a086d7"):QColor("#557799");
|
||||
workflowCardPaint(painter,boundingRect(),m_title,m_subtitle,accent,isSelected(),m_loop?25:0,
|
||||
m_loop?QStringLiteral("loop"):workflowDeviceIcon(m_source->data(0,DeviceTypeRole).toString()));
|
||||
if(m_loop) {
|
||||
painter->setPen(QColor("#73849a"));
|
||||
painter->drawText(toggleRect(),Qt::AlignCenter,m_source->isExpanded()?QStringLiteral("−"):QStringLiteral("+"));
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
|
||||
{
|
||||
@ -373,13 +351,13 @@ bool editNameDialog(QWidget *parent, const QString &title, const QString &label,
|
||||
TaskOrchestrationWidget::TaskOrchestrationWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
QVBoxLayout *root = new QVBoxLayout(this);
|
||||
root->setContentsMargins(24, 20, 24, 20);
|
||||
root->setContentsMargins(8, 6, 8, 6);
|
||||
root->setSpacing(12);
|
||||
QFrame *panel = new QFrame(this);
|
||||
panel->setObjectName(QStringLiteral("panel"));
|
||||
QVBoxLayout *layout = new QVBoxLayout(panel);
|
||||
layout->setContentsMargins(18, 16, 18, 16);
|
||||
layout->setSpacing(10);
|
||||
layout->setContentsMargins(10, 8, 10, 8);
|
||||
layout->setSpacing(6);
|
||||
QHBoxLayout *groups = new QHBoxLayout;
|
||||
QLabel *title = new QLabel(QStringLiteral("任务方案"), panel);
|
||||
title->setObjectName(QStringLiteral("sectionTitle"));
|
||||
@ -418,16 +396,10 @@ TaskOrchestrationWidget::TaskOrchestrationWidget(QWidget *parent) : QWidget(pare
|
||||
auto *validateButton = new QPushButton(QStringLiteral("校验流程"), panel);
|
||||
toolbar->addWidget(validateButton);
|
||||
connect(validateButton,&QPushButton::clicked,this,[this] {
|
||||
QJsonObject document;QString error;
|
||||
if(m_graph.isEmpty()||!FreeScanInterop::importGraph(m_graph,document,error)) {
|
||||
showTaskNotice(this,QStringLiteral("流程校验"),error.isEmpty()?QStringLiteral("当前方案没有可执行工作流。"):error);return;
|
||||
}
|
||||
QList<RunStep> steps;
|
||||
const auto groups=document.value(QStringLiteral("groups")).toArray();
|
||||
if(!groups.isEmpty())appendCompiledSteps(groups.first().toObject().value(QStringLiteral("nodes")).toArray(),steps,&error);
|
||||
if(error.isEmpty() && steps.isEmpty())error=QStringLiteral("当前方案没有可执行任务。");
|
||||
showTaskNotice(this,QStringLiteral("流程校验"),error.isEmpty()
|
||||
? QStringLiteral("结构校验通过,共 %1 个执行步骤;尚未调用设备。").arg(steps.size()) : error);
|
||||
QHash<QString,QJsonObject> executions;QString error;
|
||||
const bool ok=prepareWorkflow(executions,error);
|
||||
showTaskNotice(this,QStringLiteral("流程校验"),ok
|
||||
?QStringLiteral("图结构与接口参数校验通过,共 %1 个接口节点;分支并行执行,汇合节点等待所有前驱完成。").arg(executions.size()):error);
|
||||
});
|
||||
layout->addLayout(toolbar);
|
||||
auto *insertionToolbar = new QHBoxLayout;
|
||||
@ -468,7 +440,7 @@ TaskOrchestrationWidget::TaskOrchestrationWidget(QWidget *parent) : QWidget(pare
|
||||
m_flowView->setObjectName(QStringLiteral("jointFlowCanvas"));
|
||||
m_flowView->setRenderHint(QPainter::Antialiasing);
|
||||
m_flowView->setDragMode(QGraphicsView::RubberBandDrag);
|
||||
layout->addWidget(static_cast<WorkflowCanvas *>(m_flowView)->tools(panel));
|
||||
toolbar->addWidget(static_cast<WorkflowCanvas *>(m_flowView)->tools(panel));
|
||||
auto *workspace = new QSplitter(Qt::Horizontal, panel);
|
||||
workspace->setObjectName(QStringLiteral("workflowWorkspace"));
|
||||
auto *libraryPanel = new QWidget(workspace);
|
||||
@ -493,31 +465,39 @@ TaskOrchestrationWidget::TaskOrchestrationWidget(QWidget *parent) : QWidget(pare
|
||||
auto *controlGroup = new QTreeWidgetItem(library, {QStringLiteral("流程控制")});
|
||||
auto *loopComponent = new QTreeWidgetItem(controlGroup, {QStringLiteral("循环")});
|
||||
loopComponent->setData(0, Qt::UserRole, QStringLiteral("loop"));
|
||||
loopComponent->setData(0,Qt::UserRole+1,QStringLiteral("重复执行循环体内的流程"));
|
||||
auto *sleepComponent=new QTreeWidgetItem(controlGroup,{QStringLiteral("等待")});sleepComponent->setData(0,Qt::UserRole,QStringLiteral("sleep"));
|
||||
auto *devicesGroup = new QTreeWidgetItem(library, {QStringLiteral("服务端接口节点")});
|
||||
sleepComponent->setData(0,Qt::UserRole+1,QStringLiteral("延迟指定时长后继续执行"));
|
||||
for (const auto &type : {QStringLiteral("机械臂"),QStringLiteral("相机"),QStringLiteral("AGV"),
|
||||
QStringLiteral("灵巧手"),QStringLiteral("麦克风"),QStringLiteral("扬声器"),
|
||||
QStringLiteral("仿生头"),QStringLiteral("电机")}) {
|
||||
auto *serviceGroup=new QTreeWidgetItem(devicesGroup,{type});
|
||||
auto *serviceGroup=new QTreeWidgetItem(library,{type+QStringLiteral(" · %1").arg(TaskApi::actions(type).size())});
|
||||
for(const auto &action:TaskApi::actions(type)) {
|
||||
const auto op=TaskApi::operation(type,action);
|
||||
const auto method=op.value("method").toString();
|
||||
if(method.isEmpty())continue;
|
||||
auto *item=new QTreeWidgetItem(serviceGroup,{action.mid(QStringLiteral("接口 · ").size())});
|
||||
auto *item=new QTreeWidgetItem(serviceGroup,{TaskUi::text("operations",method)});
|
||||
item->setData(0,Qt::UserRole,QStringLiteral("rpc|")+type+QStringLiteral("|")+method);
|
||||
item->setData(0,Qt::UserRole+1,TaskUi::operationDescription(type,method));
|
||||
item->setData(0,Qt::UserRole+2,method);
|
||||
item->setData(0,Qt::UserRole+3,workflowDeviceIcon(type));
|
||||
item->setToolTip(0,op.value("service").toString()+QStringLiteral(".")+method);
|
||||
}
|
||||
}
|
||||
library->expandAll();
|
||||
controlGroup->setExpanded(true);
|
||||
libraryLayout->addWidget(libraryTitle); libraryLayout->addWidget(search); libraryLayout->addWidget(library, 1);
|
||||
connect(search, &QLineEdit::textChanged, this, [library](const QString &text) {
|
||||
for (int i=0;i<library->topLevelItemCount();++i) {
|
||||
auto *group=library->topLevelItem(i); bool visible=false;
|
||||
for(int j=0;j<group->childCount();++j) {
|
||||
const bool match=group->child(j)->text(0).contains(text,Qt::CaseInsensitive);
|
||||
group->child(j)->setHidden(!match); visible |= match;
|
||||
const bool match=group->text(0).contains(text,Qt::CaseInsensitive)
|
||||
||group->child(j)->text(0).contains(text,Qt::CaseInsensitive)
|
||||
||group->child(j)->data(0,Qt::UserRole+1).toString().contains(text,Qt::CaseInsensitive);
|
||||
const bool methodMatch=group->child(j)->data(0,Qt::UserRole+2).toString().contains(text,Qt::CaseInsensitive);
|
||||
group->child(j)->setHidden(!match&&!methodMatch); visible |= match||methodMatch;
|
||||
}
|
||||
group->setHidden(!visible);
|
||||
if(!text.isEmpty())group->setExpanded(visible);
|
||||
}
|
||||
});
|
||||
const auto createComponent = [this](const QString &key) {
|
||||
@ -547,7 +527,7 @@ TaskOrchestrationWidget::TaskOrchestrationWidget(QWidget *parent) : QWidget(pare
|
||||
item->setData(0,KindRole,"task");item->setData(0,DeviceTypeRole,type);item->setData(0,DeviceIdRole,deviceId);item->setData(0,ActionRole,action);
|
||||
item->setData(0,ParametersRole,QString::fromUtf8(QJsonDocument(params).toJson(QJsonDocument::Compact)));
|
||||
item->setData(0,WaitRole,0);item->setData(0,WaitUnitRole,"ms");
|
||||
item->setText(0,QString::fromStdString(method.toStdString()));item->setText(1,type);item->setText(2,type);item->setText(3,deviceId);item->setText(4,action);item->setText(5,"0 ms");
|
||||
item->setText(0,TaskUi::text("operations",method));item->setText(1,type);item->setText(2,type);item->setText(3,deviceId);item->setText(4,action);item->setText(5,"0 ms");
|
||||
insertNode(item);
|
||||
QString graphError;
|
||||
if(syncGraph(graphError)) {
|
||||
@ -705,7 +685,9 @@ TaskOrchestrationWidget::TaskOrchestrationWidget(QWidget *parent) : QWidget(pare
|
||||
if(WorkflowGraph::postWait(m_graph,item->data(0,NodeIdRole).toString())!=wait->value())WorkflowGraph::setWait(m_graph,item->data(0,NodeIdRole).toString(),wait->value());save();
|
||||
});
|
||||
updateInspector();
|
||||
auto *inspectorScroll=new QScrollArea(workspace);inspectorScroll->setWidgetResizable(true);inspectorScroll->setFrameShape(QFrame::NoFrame);inspectorScroll->setWidget(inspector);inspector->setMinimumWidth(300);
|
||||
auto *inspectorScroll=new QScrollArea(workspace);inspectorScroll->setWidgetResizable(true);inspectorScroll->setFrameShape(QFrame::NoFrame);inspectorScroll->setWidget(inspector);inspector->setMinimumWidth(460);
|
||||
inspectorScroll->setMinimumWidth(540);
|
||||
inspectorScroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
inspectorScroll->setStyleSheet(QStringLiteral(
|
||||
"QScrollArea{border:0;background:#f3f6fa;}"
|
||||
"QScrollBar:vertical{width:8px;background:transparent;margin:4px 2px;}"
|
||||
@ -714,7 +696,7 @@ TaskOrchestrationWidget::TaskOrchestrationWidget(QWidget *parent) : QWidget(pare
|
||||
"QScrollBar::add-line:vertical,QScrollBar::sub-line:vertical{height:0;background:transparent;}"
|
||||
"QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical{background:transparent;}"));
|
||||
workspace->addWidget(libraryPanel); workspace->addWidget(m_flowView); workspace->addWidget(inspectorScroll);
|
||||
workspace->setStretchFactor(1,1); workspace->setSizes({190,850,360});
|
||||
workspace->setStretchFactor(1,1); workspace->setSizes({270,1000,340});
|
||||
workspace->setChildrenCollapsible(false);
|
||||
layout->addWidget(workspace, 1);
|
||||
m_editControls << libraryPanel << inspector;
|
||||
@ -725,6 +707,12 @@ TaskOrchestrationWidget::TaskOrchestrationWidget(QWidget *parent) : QWidget(pare
|
||||
toggle->setCheckable(true);toggle->setChecked(true);
|
||||
toolbar->insertWidget(0,toggle);
|
||||
connect(toggle,&QPushButton::toggled,entry.second,&QWidget::setVisible);
|
||||
if(entry.second==inspectorScroll) {
|
||||
toggle->setChecked(false);inspectorScroll->hide();
|
||||
connect(m_flowScene,&QGraphicsScene::selectionChanged,this,[this,toggle] {
|
||||
if(!m_flowScene->selectedItems().isEmpty())toggle->setChecked(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
QLabel *historyTitle = new QLabel(QStringLiteral("执行反馈"), panel);
|
||||
historyTitle->setObjectName(QStringLiteral("sectionTitle"));
|
||||
@ -735,6 +723,13 @@ TaskOrchestrationWidget::TaskOrchestrationWidget(QWidget *parent) : QWidget(pare
|
||||
m_history->setMaximumHeight(64);
|
||||
m_history->setMinimumHeight(42);
|
||||
m_history->addItem(QStringLiteral("尚未执行任务"));
|
||||
auto *historyToggle=new QPushButton(QStringLiteral("执行反馈"),panel);
|
||||
historyToggle->setObjectName(QStringLiteral("secondaryButton"));historyToggle->setCheckable(true);
|
||||
toolbar->insertWidget(2,historyToggle);
|
||||
connect(historyToggle,&QPushButton::toggled,historyTitle,&QWidget::setVisible);
|
||||
connect(historyToggle,&QPushButton::toggled,m_history,&QWidget::setVisible);
|
||||
historyTitle->hide();m_history->hide();
|
||||
connect(m_history->model(),&QAbstractItemModel::rowsInserted,this,[historyToggle]{historyToggle->setChecked(true);});
|
||||
connect(m_history->model(),&QAbstractItemModel::rowsInserted,this,[this]{while(m_history->count()>200)delete m_history->takeItem(0);});
|
||||
connect(m_history,&QListWidget::itemDoubleClicked,this,[this](QListWidgetItem* item){
|
||||
const QString detail=item->data(Qt::UserRole).toString();if(detail.isEmpty())return;
|
||||
@ -925,44 +920,74 @@ bool TaskOrchestrationWidget::appendCompiledSteps(const QJsonArray &nodes,
|
||||
return true;
|
||||
}
|
||||
|
||||
void TaskOrchestrationWidget::startRun()
|
||||
bool TaskOrchestrationWidget::prepareWorkflow(QHash<QString,QJsonObject> &executions,QString &error) const
|
||||
{
|
||||
if (!m_runSteps.isEmpty()) return;
|
||||
QJsonObject compiledDocument;
|
||||
if(!m_graph.isEmpty()) {
|
||||
QString error;
|
||||
if(!FreeScanInterop::importGraph(m_graph,compiledDocument,error)||!restoreGraph(m_graph,error)) {
|
||||
showTaskNotice(this,QStringLiteral("无法执行工作流"),error);return;
|
||||
if(!WorkflowRuntime::validate(m_graph,error))return false;
|
||||
for(QTreeWidgetItemIterator it(m_tree);*it;++it) {
|
||||
auto *item=*it;if(item->data(0,KindRole)!=QStringLiteral("task"))continue;
|
||||
const auto parameters=QJsonDocument::fromJson(item->data(0,ParametersRole).toString().toUtf8()).object();
|
||||
const auto execution=TaskApi::execution(item->data(0,DeviceTypeRole).toString(),item->data(0,ActionRole).toString(),item->data(0,DeviceIdRole).toString(),parameters);
|
||||
if(execution.value("timeoutMs").toInt()<100||execution.value("timeoutMs").toInt()>1800000) {
|
||||
error=QStringLiteral("接口超时应为100至1800000毫秒:")+item->text(0);return false;
|
||||
}
|
||||
if(execution.value("kind")!="grpc_unary"||!TaskApi::validateRequest(execution.value("service").toString(),execution.value("method").toString(),execution.value("request").toObject(),error)) {
|
||||
if(error.isEmpty())error=QStringLiteral("节点未转换为独立服务端接口:")+item->text(0);
|
||||
return false;
|
||||
}
|
||||
if(item->data(0,DeviceIdRole).toString().isEmpty()||item->data(0,DeviceIdRole)==QStringLiteral("未绑定设备")) {
|
||||
error=QStringLiteral("节点尚未绑定设备:")+item->text(0);return false;
|
||||
}
|
||||
executions[item->data(0,NodeIdRole).toString()]=execution;
|
||||
}
|
||||
for(const auto &v:m_graph.value("nodes").toArray()) {
|
||||
const auto n=v.toObject();if(n.value("type")=="serviceNode"&&!executions.contains(n.value("id").toString())) {
|
||||
error=QStringLiteral("接口节点未能解析:")+n.value("id").toString();return false;
|
||||
}
|
||||
}
|
||||
++m_executionGeneration;
|
||||
m_runSteps.clear();
|
||||
const int initial=WorkflowGraph::leadingWait(m_graph,QString());if(initial){RunStep delay;delay.name=QStringLiteral("等待");delay.action="__workflow_wait__";delay.waitMs=initial;m_runSteps.append(delay);}
|
||||
QString error;
|
||||
const QJsonArray compiledGroups=compiledDocument.value(QStringLiteral("groups")).toArray();
|
||||
const QJsonArray compiledNodes=compiledGroups.isEmpty()?QJsonArray():
|
||||
compiledGroups.first().toObject().value(QStringLiteral("nodes")).toArray();
|
||||
if (!appendCompiledSteps(compiledNodes, m_runSteps, &error)) {
|
||||
m_runSteps.clear();
|
||||
showTaskNotice(this, QStringLiteral("无法执行工作流"), error);
|
||||
return;
|
||||
}
|
||||
if (m_runSteps.isEmpty()) {
|
||||
showTaskNotice(this, QStringLiteral("任务编排"),
|
||||
QStringLiteral("当前方案没有可执行任务。"));
|
||||
return;
|
||||
}
|
||||
std::function<void(QTreeWidgetItem *)> clearState = [&](QTreeWidgetItem *item) {
|
||||
item->setData(0, RunStateRole, QString());
|
||||
for (int i = 0; i < item->childCount(); ++i) clearState(item->child(i));
|
||||
};
|
||||
for (int i = 0; i < m_tree->topLevelItemCount(); ++i) clearState(m_tree->topLevelItem(i));
|
||||
m_history->clear();
|
||||
for (auto *control : m_editControls) control->setEnabled(false);
|
||||
m_flowView->setInteractive(false);
|
||||
m_runIndex = 0; m_runButton->setEnabled(false); m_stopButton->setEnabled(true); runNext();
|
||||
return true;
|
||||
}
|
||||
|
||||
void TaskOrchestrationWidget::startRun()
|
||||
{
|
||||
if(!m_runSteps.isEmpty())return;
|
||||
QHash<QString,QJsonObject> executions;QString error;
|
||||
if(!prepareWorkflow(executions,error)){showTaskNotice(this,QStringLiteral("无法执行工作流"),error);return;}
|
||||
if(!m_runtime)m_runtime=new WorkflowRuntime(this);
|
||||
++m_executionGeneration;
|
||||
m_workflowCalls.clear();m_runSteps.append(RunStep{});
|
||||
for(QTreeWidgetItemIterator it(m_tree);*it;++it)(*it)->setData(0,RunStateRole,QString());
|
||||
m_history->clear();
|
||||
for(auto *control:m_editControls)control->setEnabled(false);
|
||||
m_flowView->setInteractive(false);m_runButton->setEnabled(false);m_stopButton->setEnabled(true);
|
||||
m_status->setText(QStringLiteral("工作流运行中 · 分支并行,汇合等待全部前驱"));
|
||||
m_runtime->nodeState=[this](const QString &id,const QString &state) {
|
||||
for(QTreeWidgetItemIterator it(m_tree);*it;++it)if((*it)->data(0,NodeIdRole)==id)(*it)->setData(0,RunStateRole,state);
|
||||
rebuildFlowScene();
|
||||
};
|
||||
m_runtime->dispatch=[this,executions](const QString &token,const QString &id) {
|
||||
if(!executions.contains(id)){m_runtime->complete(token,false,QStringLiteral("缺少接口请求"));return;}
|
||||
m_workflowCalls[token]=id;
|
||||
const auto n=WorkflowGraph::node(m_graph,id);
|
||||
m_history->addItem(QStringLiteral("▶ %1").arg(n.value("properties").toObject().value("name").toString(id)));
|
||||
m_history->scrollToBottom();
|
||||
emit workflowCallRequested(token,executions.value(id));
|
||||
};
|
||||
m_runtime->finished=[this](bool ok,const QString &message) {
|
||||
stopRun(ok?QStringLiteral("执行完成"):QStringLiteral("执行失败:")+message);
|
||||
if(!ok)emit statusMessage(QStringLiteral("ERROR"),message);
|
||||
};
|
||||
if(!m_runtime->start(m_graph,error))stopRun(error);
|
||||
}
|
||||
|
||||
void TaskOrchestrationWidget::completeWorkflowCall(const QString &token,bool success,const QString &detail)
|
||||
{
|
||||
if(!m_runtime||!m_workflowCalls.contains(token)||m_runSteps.isEmpty())return;
|
||||
const auto id=m_workflowCalls.take(token);
|
||||
const auto name=WorkflowGraph::node(m_graph,id).value("properties").toObject().value("name").toString(id);
|
||||
m_history->addItem(QStringLiteral("%1 %2 · %3").arg(success?QStringLiteral("✓"):QStringLiteral("✕"),name,detail.left(2048)));
|
||||
m_history->item(m_history->count()-1)->setData(Qt::UserRole,detail.left(1048576));
|
||||
m_history->scrollToBottom();m_runtime->complete(token,success,detail);
|
||||
}
|
||||
void TaskOrchestrationWidget::runNext()
|
||||
{
|
||||
if (m_runIndex >= m_runSteps.size()) { stopRun(QStringLiteral("执行完成")); return; }
|
||||
@ -1179,6 +1204,8 @@ void TaskOrchestrationWidget::completeActionTask(const QString &deviceType,
|
||||
|
||||
void TaskOrchestrationWidget::stopRun(const QString &reason)
|
||||
{
|
||||
if(m_runtime)m_runtime->cancel();
|
||||
m_workflowCalls.clear();
|
||||
++m_executionGeneration;emit executionStopped();
|
||||
m_runTimer->stop(); m_runSteps.clear(); m_runIndex = 0; m_waitingForResult = false;
|
||||
for (auto *control : m_editControls) control->setEnabled(true);
|
||||
@ -1288,7 +1315,9 @@ void TaskOrchestrationWidget::rebuildFlowScene()
|
||||
: QStringLiteral("%1 · %2\n等待 %3")
|
||||
.arg(item->data(0, DeviceIdRole).toString(), TaskUi::operationTitle(item->data(0,DeviceTypeRole).toString(),item->data(0, ActionRole).toString()))
|
||||
.arg(waitDisplayText(item->data(0, WaitRole).toInt(), item->data(0, WaitUnitRole).toString()));
|
||||
TaskFlowCard *card = new TaskFlowCard(item, item->text(0), subtitle, loop,
|
||||
const QString method=item->data(0,ActionRole).toString().mid(QStringLiteral("接口 · ").size());
|
||||
const QString cardTitle=!loop&&item->text(0)==method?TaskUi::text("operations",method):item->text(0);
|
||||
TaskFlowCard *card = new TaskFlowCard(item, cardTitle, subtitle, loop,
|
||||
[this, revision](QTreeWidgetItem *source, const QPointF &position) {
|
||||
QTimer::singleShot(0, this, [this, source, position, revision]() {
|
||||
if(revision!=m_sceneRevision||!m_runSteps.isEmpty())return;
|
||||
@ -1522,20 +1551,16 @@ void TaskOrchestrationWidget::save()
|
||||
}
|
||||
|
||||
void TaskOrchestrationWidget::exportDocument(){
|
||||
if(!m_graph.isEmpty()) {
|
||||
QJsonObject compiled;QString error;
|
||||
if(!FreeScanInterop::importGraph(m_graph,compiled,error)||!restoreGraph(m_graph,error)){showTaskNotice(this,QStringLiteral("无法导出未连通流程"),error);return;}
|
||||
}
|
||||
storeCurrentGroup();QJsonArray groups;for(const auto& g:m_groups)groups.append(g);
|
||||
QJsonObject document{{"groups",groups}};QString error;
|
||||
if(!TaskApi::serverDocument(document,error)){showTaskNotice(this,QStringLiteral("无法导出"),error);return;}
|
||||
const QString path=QFileDialog::getSaveFileName(this,QStringLiteral("导出任务"),"task_flow.json",QStringLiteral("JSON (*.json)"));if(path.isEmpty())return;
|
||||
QSaveFile output(path);const auto bytes=QJsonDocument(document).toJson(QJsonDocument::Indented);
|
||||
if(!output.open(QIODevice::WriteOnly)||output.write(bytes)!=bytes.size()||!output.commit()){showTaskNotice(this,QStringLiteral("导出失败"),output.errorString());return;}
|
||||
if(!m_runSteps.isEmpty())return;
|
||||
QString error;
|
||||
if(!syncGraph(error)){showTaskNotice(this,QStringLiteral("无法导出"),error);return;}
|
||||
const QString path=QFileDialog::getSaveFileName(this,QStringLiteral("导出工作流图"),"workflow.json",QStringLiteral("JSON (*.json)"));if(path.isEmpty())return;
|
||||
if(!FreeScanInterop::writeGraph(path,m_graph,error)){showTaskNotice(this,QStringLiteral("导出失败"),error);return;}
|
||||
QSaveFile catalog(QFileInfo(path).absolutePath()+"/task_operations.json");const auto definitions=QJsonDocument(TaskApi::catalog()).toJson(QJsonDocument::Indented);
|
||||
if(!catalog.open(QIODevice::WriteOnly)||catalog.write(definitions)!=definitions.size()||!catalog.commit())showTaskNotice(this,QStringLiteral("接口清单导出失败"),catalog.errorString());
|
||||
else emit statusMessage("OK",QStringLiteral("已导出任务和 task_operations.json;未发送任何设备操作"));
|
||||
emit statusMessage(QStringLiteral("INFO"),QStringLiteral("已导出完整工作流图(保留并行分支、循环、接口与参数)及接口清单"));
|
||||
}
|
||||
|
||||
void TaskOrchestrationWidget::importDocument(){
|
||||
if(!m_runSteps.isEmpty())return;
|
||||
const QString path=QFileDialog::getOpenFileName(this,QStringLiteral("导入任务"),{},QStringLiteral("JSON (*.json)"));if(path.isEmpty())return;
|
||||
|
||||
@ -15,6 +15,7 @@ class QGraphicsScene;
|
||||
class QGraphicsView;
|
||||
class QPointF;
|
||||
class QListWidget;
|
||||
class WorkflowRuntime;
|
||||
|
||||
class TaskOrchestrationWidget final : public QWidget
|
||||
{
|
||||
@ -42,9 +43,11 @@ public:
|
||||
const QString &detail);
|
||||
|
||||
quint64 executionGeneration() const { return m_executionGeneration; }
|
||||
void completeWorkflowCall(const QString &token,bool success,const QString &detail);
|
||||
|
||||
signals:
|
||||
void executionStopped();
|
||||
void workflowCallRequested(const QString &token,const QJsonObject &execution);
|
||||
void cameraCapabilitiesChanged();
|
||||
void availableDevicesChanged();
|
||||
void deviceInfoChanged(const QString &deviceId);
|
||||
@ -91,6 +94,9 @@ private:
|
||||
void updateInsertionHint();
|
||||
bool syncGraph(QString &error);
|
||||
bool restoreGraph(const QJsonObject &graph, QString &error);
|
||||
bool prepareWorkflow(QHash<QString,QJsonObject> &executions,QString &error) const;
|
||||
WorkflowRuntime *m_runtime=nullptr;
|
||||
QHash<QString,QString> m_workflowCalls;
|
||||
|
||||
QComboBox *m_groupCombo = nullptr;
|
||||
QTreeWidget *m_tree = nullptr;
|
||||
|
||||
@ -20,8 +20,15 @@ TaskRpcRunner::TaskRpcRunner(RobotClient* client,QObject* parent):QObject(parent
|
||||
connect(client,&RobotClient::connectRequested,this,[this](const QString& host,int port,bool demo){m_connected=false;cancel();m_demo=demo;m_endpoint=host.trimmed()+":"+QString::number(port);});
|
||||
connect(client,&RobotClient::connectionChanged,this,[this](bool ok,int,const QString&){m_connected=ok;if(!ok)cancel();});
|
||||
}
|
||||
TaskRpcRunner::~TaskRpcRunner(){if(m_demoCompletion){DemoSimulator::instance().stop(m_demoDevice);m_demoCompletion={};++m_demoGeneration;}cancel();if(m_thread){m_thread->wait();delete m_thread;}}
|
||||
void TaskRpcRunner::cancel(){if(m_context)m_context->TryCancel();if(m_demoCompletion){++m_demoGeneration;DemoSimulator::instance().stop(m_demoDevice);m_busy=false;auto done=std::move(m_demoCompletion);done(false,QStringLiteral("演示调用已取消"));}}
|
||||
TaskRpcRunner::~TaskRpcRunner(){const auto parallel=m_parallel;m_parallel.clear();for(auto *runner:parallel){QObject::disconnect(runner,nullptr,this,nullptr);delete runner;}if(m_demoCompletion){DemoSimulator::instance().stop(m_demoDevice);m_demoCompletion={};++m_demoGeneration;}cancel();if(m_thread){m_thread->wait();delete m_thread;}}
|
||||
void TaskRpcRunner::cancel(){const auto parallel=m_parallel;for(auto *runner:parallel)runner->cancel();if(m_context)m_context->TryCancel();if(m_demoCompletion){++m_demoGeneration;DemoSimulator::instance().stop(m_demoDevice);m_busy=false;auto done=std::move(m_demoCompletion);done(false,QStringLiteral("演示调用已取消"));}}
|
||||
void TaskRpcRunner::runConcurrent(const QJsonObject &execution,std::function<void(bool,const QString&)> done) {
|
||||
auto *runner=new TaskRpcRunner(m_client,this);
|
||||
runner->m_endpoint=m_endpoint;runner->m_connected=m_connected;runner->m_demo=m_demo;
|
||||
m_parallel.append(runner);
|
||||
connect(runner,&QObject::destroyed,this,[this,runner]{m_parallel.removeAll(runner);});
|
||||
runner->run(execution,[runner,done](bool ok,const QString &detail){done(ok,detail);runner->deleteLater();});
|
||||
}
|
||||
void TaskRpcRunner::run(const QJsonObject& ex,std::function<void(bool,const QString&)> done){
|
||||
if(!m_connected||m_busy){done(false,QStringLiteral("接口未连接或上次调用仍未结束,未发送请求"));return;}
|
||||
QString error;const QString service=ex.value("service").toString(),method=ex.value("method").toString();
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include <QJsonObject>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <QList>
|
||||
class RobotClient;class QThread;
|
||||
namespace grpc {class ClientContext;}
|
||||
class TaskRpcRunner final:public QObject {
|
||||
@ -10,9 +11,11 @@ public:
|
||||
explicit TaskRpcRunner(RobotClient*,QObject* parent=nullptr);
|
||||
~TaskRpcRunner()override;
|
||||
void run(const QJsonObject& execution,std::function<void(bool,const QString&)> done);
|
||||
void runConcurrent(const QJsonObject& execution,std::function<void(bool,const QString&)> done);
|
||||
void cancel();
|
||||
private:
|
||||
friend struct TaskRpcTestAccess;
|
||||
QList<TaskRpcRunner*> m_parallel;
|
||||
quint64 m_demoGeneration=0;
|
||||
QString m_demoDevice;
|
||||
std::function<void(bool,const QString&)> m_demoCompletion;
|
||||
|
||||
@ -2,8 +2,27 @@
|
||||
#include <QFile>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QHash>
|
||||
namespace TaskUi {
|
||||
inline QJsonObject metadata(){static const QJsonObject data=[] {QFile file(":/resources/task_ui.json");file.open(QIODevice::ReadOnly);return QJsonDocument::fromJson(file.readAll()).object();}();return data;}
|
||||
inline QString text(const QString& section,const QString& key){return metadata().value(section).toObject().value(key).toString(key);}
|
||||
inline QString operationDescription(const QString &type,const QString &method) {
|
||||
static const QHash<QString,QString> descriptions{
|
||||
{"StartCamera",QStringLiteral("采集图像前启动相机")},
|
||||
{"StopCamera",QStringLiteral("采集完成后关闭相机")},
|
||||
{"GetRGBImage",QStringLiteral("获取相机拍摄的彩色图像")},
|
||||
{"GetDepthImage",QStringLiteral("获取相机拍摄的深度图像")},
|
||||
{"GetRGBDImages",QStringLiteral("同时采集彩色图像与深度图像")},
|
||||
{"moveJ",QStringLiteral("按关节角度移动至目标位置")},
|
||||
{"moveL",QStringLiteral("沿直线路径移动至目标位姿")},
|
||||
{"moveJPose",QStringLiteral("通过关节运动到达目标末端位姿")},
|
||||
{"torqueOn",QStringLiteral("使能设备,为后续运动做准备")},
|
||||
{"torqueOff",QStringLiteral("关闭设备使能")},
|
||||
{"clearFault",QStringLiteral("清除设备当前故障")},
|
||||
{"stopMotion",QStringLiteral("停止当前运动")},
|
||||
{"GetStatus",QStringLiteral("读取设备当前运行状态")}
|
||||
};
|
||||
return descriptions.value(method,QStringLiteral("%1 · %2").arg(type,text("operations",method)));
|
||||
}
|
||||
inline QString operationTitle(const QString&,const QString& action){const QString prefix=QStringLiteral("接口 · ");if(!action.startsWith(prefix))return action=="MoveJ"?QStringLiteral("关节角度运动"):action;return text("operations",action.mid(prefix.size()))+QStringLiteral("(接口)");}
|
||||
}
|
||||
|
||||
@ -4,6 +4,55 @@
|
||||
#include <functional>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QSvgRenderer>
|
||||
|
||||
inline QString workflowDeviceIcon(const QString &type) {
|
||||
if(type==QStringLiteral("相机"))return QStringLiteral("camera");
|
||||
if(type==QStringLiteral("机械臂"))return QStringLiteral("arm");
|
||||
if(type==QStringLiteral("AGV"))return QStringLiteral("agv");
|
||||
if(type==QStringLiteral("灵巧手"))return QStringLiteral("hand");
|
||||
if(type==QStringLiteral("仿生头"))return QStringLiteral("expression");
|
||||
if(type==QStringLiteral("麦克风"))return QStringLiteral("microphone");
|
||||
if(type==QStringLiteral("扬声器"))return QStringLiteral("audio");
|
||||
if(type==QStringLiteral("电机"))return QStringLiteral("motor");
|
||||
return QStringLiteral("plan");
|
||||
}
|
||||
inline void workflowVectorIcon(QPainter *p,const QRectF &rect,const QString &name) {
|
||||
static QHash<QString,QSharedPointer<QSvgRenderer>> renderers;
|
||||
if(!renderers.contains(name))
|
||||
renderers.insert(name,QSharedPointer<QSvgRenderer>::create(QStringLiteral(":/workflow-icons/")+name+QStringLiteral(".svg")));
|
||||
renderers.value(name)->render(p,rect);
|
||||
}
|
||||
|
||||
inline void workflowCardPaint(QPainter *p,const QRectF &bounds,const QString &title,
|
||||
const QString &detail,const QColor &accent,bool selected,
|
||||
qreal reserved=0,const QString &iconName={}) {
|
||||
p->save();p->setRenderHint(QPainter::Antialiasing);
|
||||
const QRectF body=bounds.adjusted(1.5,1.5,-1.5,-1.5);
|
||||
p->setPen(Qt::NoPen);p->setBrush(QColor(25,45,75,9));
|
||||
p->drawRoundedRect(body.translated(0,2),6,6);
|
||||
p->setPen(QPen(selected?QColor("#357dff"):QColor("#e1e7ef"),selected?2:1));
|
||||
p->setBrush(Qt::white);p->drawRoundedRect(body,6,6);
|
||||
p->setPen(QPen(accent,3,Qt::SolidLine,Qt::RoundCap));
|
||||
p->drawLine(QPointF(3,9),QPointF(3,bounds.height()-9));
|
||||
QRectF badge(15,14,36,36);
|
||||
p->setPen(Qt::NoPen);p->setBrush(QColor("#edf6fc"));p->drawRoundedRect(badge,6,6);
|
||||
const QString icon=!iconName.isEmpty()?iconName:
|
||||
title.contains(QStringLiteral("相机"))||title.contains(QStringLiteral("图像"))?QStringLiteral("camera"):
|
||||
title.contains(QStringLiteral("开始"))?QStringLiteral("start"):title.contains(QStringLiteral("结束"))?QStringLiteral("end"):
|
||||
title.contains(QStringLiteral("循环"))?QStringLiteral("loop"):title.contains(QStringLiteral("等待"))?QStringLiteral("sleep"):QStringLiteral("video");
|
||||
workflowVectorIcon(p,badge.adjusted(7,7,-7,-7),icon);
|
||||
QFont font=QApplication::font();font.setPixelSize(15);font.setBold(true);
|
||||
p->setFont(font);p->setPen(QColor("#19334d"));
|
||||
p->drawText(QRectF(61,14,bounds.width()-76-reserved,32),Qt::AlignVCenter,
|
||||
p->fontMetrics().elidedText(title,Qt::ElideRight,int(bounds.width()-76-reserved)));
|
||||
font.setPixelSize(12);font.setBold(false);p->setFont(font);p->setPen(QColor("#738297"));
|
||||
const QStringList lines=detail.split('\n');
|
||||
for(int i=0;i<qMin(2,lines.size());++i)
|
||||
p->drawText(QRectF(16,58+i*19,bounds.width()-32,19),Qt::AlignVCenter,
|
||||
p->fontMetrics().elidedText(lines[i],Qt::ElideRight,int(bounds.width()-32)));
|
||||
p->restore();
|
||||
}
|
||||
|
||||
inline void workflowContainers(QGraphicsScene *scene,const QJsonObject &graph,const QHash<QString,QRectF> &bounds) {
|
||||
QHash<QString,QString> parents;
|
||||
@ -53,17 +102,22 @@ inline void workflowPorts(QGraphicsItem *card,const QString &id,bool input=true,
|
||||
port->setToolTip(out?QStringLiteral("拖动到下一节点的输入端,建立执行连线"):QStringLiteral("节点输入端"));
|
||||
}
|
||||
}
|
||||
class WorkflowTerminal final : public QGraphicsEllipseItem {
|
||||
class WorkflowTerminal final : public QGraphicsRectItem {
|
||||
public:
|
||||
QString title,detail;
|
||||
QColor accent;
|
||||
std::function<void(const QPointF &)> moved;
|
||||
WorkflowTerminal():QGraphicsEllipseItem(0,0,90,42) {
|
||||
setPen(QPen(QColor("#91a9c7"),1.5));setBrush(QColor("#edf4ff"));
|
||||
WorkflowTerminal():QGraphicsRectItem(0,0,260,88) {
|
||||
setPen(Qt::NoPen);
|
||||
setFlags(ItemIsSelectable|ItemIsMovable);
|
||||
}
|
||||
void paint(QPainter *p,const QStyleOptionGraphicsItem *,QWidget *) override {
|
||||
workflowCardPaint(p,rect(),title,detail,accent,isSelected());
|
||||
}
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override { m_start=pos();QGraphicsEllipseItem::mousePressEvent(event); }
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override { m_start=pos();QGraphicsRectItem::mousePressEvent(event); }
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override {
|
||||
QGraphicsEllipseItem::mouseReleaseEvent(event);if(pos()!=m_start&&moved)moved(pos()+QPointF(45,21));
|
||||
QGraphicsRectItem::mouseReleaseEvent(event);if(pos()!=m_start&&moved)moved(pos()+rect().center());
|
||||
}
|
||||
private: QPointF m_start;
|
||||
};
|
||||
@ -71,11 +125,11 @@ inline WorkflowTerminal *workflowTerminal(QGraphicsScene *scene,const QString &i
|
||||
const QPointF ¢er) {
|
||||
auto *item=new WorkflowTerminal;scene->addItem(item);
|
||||
item->setData(0,id);item->setData(7010,id);item->setData(7000,type);
|
||||
item->setPos(center-QPointF(45,21));
|
||||
item->setPos(center-item->rect().center());
|
||||
const bool start=type=="start"||type=="subStart";
|
||||
auto *label=new QGraphicsSimpleTextItem(type=="sleep"?QStringLiteral("等待"):start?QStringLiteral("开始"):QStringLiteral("结束"),item);
|
||||
label->setAcceptedMouseButtons(Qt::NoButton);
|
||||
label->setPos(45-label->boundingRect().width()/2,21-label->boundingRect().height()/2);
|
||||
item->title=type=="sleep"?QStringLiteral("睡眠等待"):start?QStringLiteral("流程开始"):QStringLiteral("流程结束");
|
||||
item->detail=type=="sleep"?QStringLiteral("等待指定时长后继续执行"):start?QStringLiteral("从此节点进入工作流"):QStringLiteral("当前工作流执行完成");
|
||||
item->accent=type=="sleep"?QColor("#55b9db"):start?QColor("#20a36a"):QColor("#e05b64");
|
||||
workflowPorts(item,id,!start,start||type=="sleep");return item;
|
||||
}
|
||||
|
||||
@ -126,7 +180,8 @@ public:
|
||||
auto *bar = new QWidget(parent); auto *layout = new QHBoxLayout(bar);
|
||||
layout->setContentsMargins(0,0,0,0);
|
||||
auto *hint = new QLabel(QStringLiteral("右键平移 · Ctrl+滚轮缩放"), bar);
|
||||
hint->setObjectName("mutedLabel"); layout->addWidget(hint); layout->addStretch();
|
||||
hint->setObjectName("mutedLabel");hint->hide();bar->setToolTip(hint->text()+QStringLiteral(" · Ctrl+C / Ctrl+V 复制粘贴"));
|
||||
layout->addStretch();
|
||||
for (int i=0;i<4;++i) {
|
||||
auto *button = new QPushButton(QStringList{QStringLiteral("-"),QStringLiteral("+"),QStringLiteral("回到起点"),QStringLiteral("显示全部")}[i],bar);
|
||||
button->setObjectName("secondaryButton"); layout->addWidget(button);
|
||||
@ -142,9 +197,9 @@ protected:
|
||||
if(m_firstShow){m_firstShow=false;QTimer::singleShot(0,this,[this]{fitAll();});}
|
||||
}
|
||||
void drawBackground(QPainter *painter, const QRectF &rect) override {
|
||||
painter->fillRect(rect,QColor("#f6f8fc"));
|
||||
painter->fillRect(rect,QColor("#ffffff"));
|
||||
if(transform().m11()<.3) return;
|
||||
painter->setPen(QPen(QColor("#d9dee8"),0));
|
||||
painter->setPen(QPen(QColor("#e5ebf3"),0));
|
||||
const int gap=24;
|
||||
for(qreal x=std::floor(rect.left()/gap)*gap;x<rect.right();x+=gap)
|
||||
for(qreal y=std::floor(rect.top()/gap)*gap;y<rect.bottom();y+=gap) painter->drawPoint(QPointF(x,y));
|
||||
@ -249,9 +304,32 @@ private:
|
||||
QString m_connecting;QPointF m_wireStart;QGraphicsPathItem *m_preview=nullptr;
|
||||
};
|
||||
|
||||
class WorkflowComponentDelegate : public QStyledItemDelegate {
|
||||
public:
|
||||
using QStyledItemDelegate::QStyledItemDelegate;
|
||||
QSize sizeHint(const QStyleOptionViewItem &,const QModelIndex &index) const override {
|
||||
return QSize(240,index.data(Qt::UserRole).toString().isEmpty()?44:86);
|
||||
}
|
||||
void paint(QPainter *p,const QStyleOptionViewItem &option,const QModelIndex &index) const override {
|
||||
if(index.data(Qt::UserRole).toString().isEmpty()) {
|
||||
QStyledItemDelegate::paint(p,option,index);return;
|
||||
}
|
||||
p->save();p->setClipRect(option.rect);
|
||||
const QRectF body=QRectF(option.rect).adjusted(4,4,-6,-4);
|
||||
p->translate(body.topLeft());
|
||||
workflowCardPaint(p,QRectF(QPointF(),body.size()),index.data().toString(),
|
||||
index.data(Qt::UserRole+1).toString(),QColor("#58b9dc"),option.state&QStyle::State_Selected,
|
||||
0,index.data(Qt::UserRole+3).toString());
|
||||
p->restore();
|
||||
}
|
||||
};
|
||||
class WorkflowLibrary : public QTreeWidget {
|
||||
public:
|
||||
explicit WorkflowLibrary(QWidget *parent=nullptr):QTreeWidget(parent){setHeaderHidden(true);setDragEnabled(true);setMinimumWidth(180);}
|
||||
explicit WorkflowLibrary(QWidget *parent=nullptr):QTreeWidget(parent){
|
||||
setHeaderHidden(true);setDragEnabled(true);setMinimumWidth(250);
|
||||
setItemDelegate(new WorkflowComponentDelegate(this));setIndentation(10);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
}
|
||||
protected:
|
||||
void startDrag(Qt::DropActions) override {
|
||||
if(!currentItem() || currentItem()->data(0,Qt::UserRole).toString().isEmpty())return;
|
||||
|
||||
@ -196,17 +196,17 @@ inline QJsonObject merge(QJsonObject fresh,const QJsonObject &previous) {
|
||||
inline bool connect(QJsonObject &graph,const QString &from,const QString &to,QString &error) {
|
||||
const auto a=node(graph,from),b=node(graph,to);
|
||||
if(a.isEmpty()||b.isEmpty()||from==to){error=QStringLiteral("请选择不同节点的输出端和输入端");return false;}
|
||||
if(a.value("properties").toObject().value("parentId")!=b.value("properties").toObject().value("parentId")) {
|
||||
if(a.value("properties").toObject().value("parentId").toString()!=b.value("properties").toObject().value("parentId").toString()) {
|
||||
error=QStringLiteral("循环内外不能直接连线,请连接同一容器内的节点");return false;
|
||||
}
|
||||
QJsonArray edges;
|
||||
for(const auto &v:graph.value("edges").toArray()) {
|
||||
const auto e=v.toObject();if(e.value("sourceNodeId")!=from&&e.value("targetNodeId")!=to)edges.append(e);
|
||||
}
|
||||
QString cursor=to;QSet<QString> seen;
|
||||
while(!cursor.isEmpty()&&!seen.contains(cursor)) {
|
||||
if(cursor==from){error=QStringLiteral("该连线会形成环路,请使用循环组件");return false;}seen.insert(cursor);
|
||||
QString next;for(const auto &v:edges)if(v.toObject().value("sourceNodeId")==cursor)next=v.toObject().value("targetNodeId").toString();cursor=next;
|
||||
QJsonArray edges=graph.value("edges").toArray();
|
||||
for(const auto &v:edges)if(v.toObject().value("sourceNodeId")==from&&v.toObject().value("targetNodeId")==to)return true;
|
||||
QStringList pending{to};QSet<QString> seen;
|
||||
while(!pending.isEmpty()) {
|
||||
const QString cursor=pending.takeLast();
|
||||
if(cursor==from){error=QStringLiteral("该连线会形成环路,请使用循环组件");return false;}
|
||||
if(seen.contains(cursor))continue;seen.insert(cursor);
|
||||
for(const auto &v:edges)if(v.toObject().value("sourceNodeId")==cursor)pending.append(v.toObject().value("targetNodeId").toString());
|
||||
}
|
||||
edges.append(QJsonObject{{"id",from+"__"+to},{"type","bezier"},{"sourceNodeId",from},{"targetNodeId",to},
|
||||
{"sourceAnchorId",from+"_1"},{"targetAnchorId",to+"_3"},{"properties",QJsonObject{}}});
|
||||
@ -253,42 +253,40 @@ inline void removeNode(QJsonObject &graph,const QString &id) {
|
||||
graph.insert("nodes",nodes);graph.insert("edges",edges);
|
||||
}
|
||||
inline int postWait(const QJsonObject &graph,const QString &source) {
|
||||
QString cursor=source;QSet<QString> seen;double result=0;
|
||||
while(!cursor.isEmpty()&&!seen.contains(cursor)) {
|
||||
seen.insert(cursor);QString next;
|
||||
for(const auto &v:graph.value("edges").toArray())if(v.toObject().value("sourceNodeId")==cursor)next=v.toObject().value("targetNodeId").toString();
|
||||
const auto n=node(graph,next);if(n.value("type")!="sleep")break;
|
||||
for(const auto &v:n.value("properties").toObject().value("nodeParams").toArray())if(v.toObject().value("name")=="delayMs") {
|
||||
const auto value=v.toObject().value("input");result+=value.isString()?value.toString().toDouble():value.toDouble();
|
||||
}cursor=next;
|
||||
}
|
||||
return int(qBound(0.,result,2147483647.));
|
||||
}
|
||||
inline int leadingWait(const QJsonObject &graph,const QString &container) {
|
||||
QStringList targets;
|
||||
for(const auto &v:graph.value("edges").toArray())if(v.toObject().value("sourceNodeId")==source)targets.append(v.toObject().value("targetNodeId").toString());
|
||||
if(targets.size()!=1)return 0;
|
||||
const auto wait=node(graph,targets.first());
|
||||
return wait.value("type")=="sleep"&&wait.value("properties").toObject().value("cmvrAfterNodeId")==source?delay(wait):0;
|
||||
}inline int leadingWait(const QJsonObject &graph,const QString &container) {
|
||||
for(const auto &v:graph.value("nodes").toArray()) {
|
||||
const auto n=v.toObject();if((n.value("type")=="start"||n.value("type")=="subStart")&&n.value("properties").toObject().value("parentId").toString()==container)return postWait(graph,n.value("id").toString());
|
||||
}return 0;
|
||||
}
|
||||
inline void setWait(QJsonObject &graph,const QString &source,int milliseconds) {
|
||||
QString cursor=source,next;QSet<QString> removed;
|
||||
while(true) {
|
||||
next.clear();for(const auto &v:graph.value("edges").toArray())if(v.toObject().value("sourceNodeId")==cursor)next=v.toObject().value("targetNodeId").toString();
|
||||
if(node(graph,next).value("type")!="sleep"||removed.contains(next))break;
|
||||
removed.insert(next);cursor=next;
|
||||
QStringList targets;
|
||||
for(const auto &v:graph.value("edges").toArray())if(v.toObject().value("sourceNodeId")==source)targets.append(v.toObject().value("targetNodeId").toString());
|
||||
if(targets.size()==1) {
|
||||
const auto wait=node(graph,targets.first());
|
||||
if(wait.value("type")=="sleep"&&wait.value("properties").toObject().value("cmvrAfterNodeId")==source) {
|
||||
const QString id=targets.first();targets.clear();
|
||||
for(const auto &v:graph.value("edges").toArray())if(v.toObject().value("sourceNodeId")==id)targets.append(v.toObject().value("targetNodeId").toString());
|
||||
removeNode(graph,id);
|
||||
}
|
||||
}
|
||||
for(const auto &id:removed)removeNode(graph,id);
|
||||
QJsonArray edges;for(const auto &v:graph.value("edges").toArray())if(v.toObject().value("sourceNodeId")!=source)edges.append(v);
|
||||
graph.insert("edges",edges);QString error;
|
||||
graph.insert("edges",edges);QString error;QString tail=source;
|
||||
if(milliseconds>0) {
|
||||
QString id=source+"_after";if(!node(graph,id).isEmpty())id=QUuid::createUuid().toString(QUuid::WithoutBraces);
|
||||
const auto previous=node(graph,source);QJsonObject properties{{"name",QStringLiteral("完成后等待")},{"action","SLEEP"},{"nodeType","NONE"},
|
||||
const QString id=QUuid::createUuid().toString(QUuid::WithoutBraces);
|
||||
const auto previous=node(graph,source);
|
||||
QJsonObject properties{{"name",QStringLiteral("完成后等待")},{"action","SLEEP"},{"nodeType","NONE"},
|
||||
{"nodeParams",QJsonArray{QJsonObject{{"name","delayMs"},{"type","input"},{"input",milliseconds}}}},{"cmvrAfterNodeId",source}};
|
||||
const auto parent=previous.value("properties").toObject().value("parentId");if(parent.isString())properties.insert("parentId",parent);
|
||||
replaceNode(graph,QJsonObject{{"id",id},{"type","sleep"},{"x",previous.value("x").toDouble()+230},{"y",previous.value("y")},{"properties",properties}});
|
||||
connect(graph,source,id,error);if(!next.isEmpty())connect(graph,id,next,error);
|
||||
}else if(!next.isEmpty())connect(graph,source,next,error);
|
||||
}
|
||||
inline QHash<QString,QStringList> order(const QJsonObject &graph,QString &error) {
|
||||
connect(graph,source,id,error);tail=id;
|
||||
}
|
||||
for(const auto &target:targets)connect(graph,tail,target,error);
|
||||
}inline QHash<QString,QStringList> order(const QJsonObject &graph,QString &error) {
|
||||
QHash<QString,QJsonObject> nodes;QHash<QString,QString> parent,next,previous;QSet<QString> seen;
|
||||
QHash<QString,QStringList> result;
|
||||
const auto fail=[&](const QString &message){if(error.isEmpty())error=message;};
|
||||
|
||||
176
src/workflowruntime.h
Normal file
@ -0,0 +1,176 @@
|
||||
#pragma once
|
||||
#include <QtCore>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <cmath>
|
||||
|
||||
// Each scope/loop iteration owns independent predecessor counters. RPC replies
|
||||
// are correlated by invocation token, never by method name or completion order.
|
||||
class WorkflowRuntime final : public QObject {
|
||||
public:
|
||||
using QObject::QObject;
|
||||
std::function<void(const QString &,const QString &)> dispatch;
|
||||
std::function<void(const QString &,const QString &)> nodeState;
|
||||
std::function<void(bool,const QString &)> finished;
|
||||
static QJsonObject inputs(const QJsonObject &node) {
|
||||
QJsonObject result;
|
||||
for(const auto &v:node.value("properties").toObject().value("nodeParams").toArray()) {
|
||||
const auto p=v.toObject();result.insert(p.value("name").toString(),p.value("input"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
static bool validate(const QJsonObject &graph,QString &error) {
|
||||
QHash<QString,QJsonObject> nodes;QHash<QString,QStringList> scopes,out,in;
|
||||
const auto fail=[&](const QString &message){error=message;return false;};
|
||||
for(const auto &v:graph.value("nodes").toArray()) {
|
||||
const auto n=v.toObject();const QString id=n.value("id").toString();
|
||||
if(id.isEmpty()||nodes.contains(id))return fail(QStringLiteral("节点 ID 为空或重复"));
|
||||
nodes[id]=n;scopes[n.value("properties").toObject().value("parentId").toString()].append(id);
|
||||
}
|
||||
if(nodes.isEmpty()||nodes.size()>10000)return fail(QStringLiteral("流程节点数量无效"));
|
||||
for(auto it=nodes.begin();it!=nodes.end();++it) {
|
||||
QString parent=it.value().value("properties").toObject().value("parentId").toString();
|
||||
QSet<QString> ancestors{it.key()};
|
||||
while(!parent.isEmpty()) {
|
||||
if(!nodes.contains(parent)||nodes[parent].value("type")!="loop"||ancestors.contains(parent)||ancestors.size()>16)
|
||||
return fail(QStringLiteral("循环容器引用无效或嵌套过深"));
|
||||
ancestors.insert(parent);parent=nodes[parent].value("properties").toObject().value("parentId").toString();
|
||||
}
|
||||
const QString type=it.value().value("type").toString();
|
||||
if(!QStringList{"start","end","subStart","subEnd","sleep","loop","serviceNode"}.contains(type))
|
||||
return fail(QStringLiteral("不支持的节点类型:")+type);
|
||||
const auto params=inputs(it.value());
|
||||
if(type=="sleep"||type=="loop") {
|
||||
const auto value=params.value(type=="sleep"?"delayMs":"loopNum");
|
||||
bool ok=false;const double number=value.isString()?value.toString().toDouble(&ok):value.toDouble(-1);
|
||||
if(!value.isString())ok=value.isDouble();
|
||||
if(!ok||!std::isfinite(number)||number!=std::floor(number)||number<(type=="sleep"?0:1)||number>(type=="sleep"?2147483647:100000))
|
||||
return fail(QStringLiteral("等待时长或循环次数无效:")+it.key());
|
||||
}
|
||||
}
|
||||
QSet<QString> edges;
|
||||
for(const auto &v:graph.value("edges").toArray()) {
|
||||
const auto e=v.toObject();const QString a=e.value("sourceNodeId").toString(),b=e.value("targetNodeId").toString();
|
||||
if(!nodes.contains(a)||!nodes.contains(b)||a==b||edges.contains(a+"\n"+b))
|
||||
return fail(QStringLiteral("连线引用无效或重复"));
|
||||
if(nodes[a].value("properties").toObject().value("parentId").toString()!=nodes[b].value("properties").toObject().value("parentId").toString())
|
||||
return fail(QStringLiteral("循环内外不能直接连线"));
|
||||
edges.insert(a+"\n"+b);out[a].append(b);in[b].append(a);
|
||||
}
|
||||
for(auto it=scopes.begin();it!=scopes.end();++it) {
|
||||
QString start,end;
|
||||
for(const auto &id:it.value()) {
|
||||
const QString type=nodes[id].value("type").toString();
|
||||
if(type==(it.key().isEmpty()?"start":"subStart")) {
|
||||
if(!start.isEmpty())return fail(QStringLiteral("一个流程容器只能有一个开始节点"));start=id;
|
||||
}
|
||||
if(type==(it.key().isEmpty()?"end":"subEnd")) {
|
||||
if(!end.isEmpty())return fail(QStringLiteral("一个流程容器只能有一个结束节点"));end=id;
|
||||
}
|
||||
}
|
||||
if(start.isEmpty()||end.isEmpty()||!in[start].isEmpty()||!out[end].isEmpty())
|
||||
return fail(QStringLiteral("流程容器缺少有效的开始或结束节点"));
|
||||
const auto reachable=[&](const QString &first,const QHash<QString,QStringList> &links) {
|
||||
QSet<QString> seen;QStringList todo{first};
|
||||
while(!todo.isEmpty()){const auto id=todo.takeLast();if(seen.contains(id))continue;seen.insert(id);todo.append(links.value(id));}
|
||||
return seen;
|
||||
};
|
||||
if(reachable(start,out).size()!=it.value().size()||reachable(end,in).size()!=it.value().size())
|
||||
return fail(QStringLiteral("存在未连接节点或未汇入结束节点的分支"));
|
||||
QHash<QString,int> degree;QStringList ready;int visited=0;
|
||||
for(const auto &id:it.value()){degree[id]=in[id].size();if(!degree[id])ready.append(id);}
|
||||
while(!ready.isEmpty()){const auto id=ready.takeLast();++visited;for(const auto &next:out[id])if(--degree[next]==0)ready.append(next);}
|
||||
if(visited!=it.value().size())return fail(QStringLiteral("连线形成环路,请使用循环组件"));
|
||||
}
|
||||
for(auto it=nodes.begin();it!=nodes.end();++it)if(it.value().value("type")=="loop"&&!scopes.contains(it.key()))
|
||||
return fail(QStringLiteral("循环没有内部流程"));
|
||||
return true;
|
||||
}
|
||||
bool start(const QJsonObject &graph,QString &error) {
|
||||
cancel();if(!validate(graph,error))return false;
|
||||
m_graph=graph;m_running=true;m_count=0;
|
||||
const auto generation=m_generation;
|
||||
QTimer::singleShot(0,this,[this,generation] {
|
||||
if(!active(generation))return;
|
||||
scope({},[this,generation] {if(active(generation)){m_running=false;if(finished)finished(true,QStringLiteral("执行完成"));}});
|
||||
});
|
||||
return true;
|
||||
}
|
||||
void cancel(){++m_generation;m_running=false;m_pending.clear();}
|
||||
void complete(const QString &token,bool success,const QString &detail) {
|
||||
if(!m_running||!m_pending.contains(token))return;
|
||||
const auto pending=m_pending.take(token);
|
||||
if(!success){if(nodeState)nodeState(pending.id,"failed");fail(detail);return;}
|
||||
finishNode(pending.scope,pending.id);
|
||||
}
|
||||
private:
|
||||
struct Scope {
|
||||
QHash<QString,int> degree;
|
||||
QHash<QString,QStringList> out;
|
||||
QSet<QString> done,scheduled;
|
||||
int size=0;
|
||||
std::function<void()> finished;
|
||||
};
|
||||
struct Pending {std::shared_ptr<Scope> scope;QString id;};
|
||||
QHash<QString,Pending> m_pending;
|
||||
QJsonObject m_graph;
|
||||
quint64 m_generation=0;
|
||||
int m_count=0;
|
||||
bool m_running=false;
|
||||
bool active(quint64 generation)const{return m_running&&generation==m_generation;}
|
||||
QJsonObject node(const QString &id)const {
|
||||
for(const auto &v:m_graph.value("nodes").toArray())if(v.toObject().value("id")==id)return v.toObject();
|
||||
return {};
|
||||
}
|
||||
void fail(const QString &message) {
|
||||
if(!m_running)return;cancel();if(finished)finished(false,message);
|
||||
}
|
||||
void scope(const QString &parent,const std::function<void()> &done) {
|
||||
auto state=std::make_shared<Scope>();state->finished=done;
|
||||
for(const auto &v:m_graph.value("nodes").toArray()) {
|
||||
const auto n=v.toObject();if(n.value("properties").toObject().value("parentId").toString()==parent)
|
||||
state->degree[n.value("id").toString()]=0;
|
||||
}
|
||||
state->size=state->degree.size();
|
||||
for(const auto &v:m_graph.value("edges").toArray()) {
|
||||
const auto e=v.toObject();const QString from=e.value("sourceNodeId").toString(),to=e.value("targetNodeId").toString();
|
||||
if(state->degree.contains(from)){++state->degree[to];state->out[from].append(to);}
|
||||
}
|
||||
for(auto it=state->degree.begin();it!=state->degree.end();++it)if(it.value()==0)schedule(state,it.key());
|
||||
}
|
||||
void schedule(const std::shared_ptr<Scope> &state,const QString &id) {
|
||||
if(!m_running||state->scheduled.contains(id))return;
|
||||
state->scheduled.insert(id);const auto generation=m_generation;
|
||||
QTimer::singleShot(0,this,[this,state,id,generation] {
|
||||
if(!active(generation))return;
|
||||
if(++m_count>100000){fail(QStringLiteral("流程展开超过100000步"));return;}
|
||||
const auto n=node(id);const QString type=n.value("type").toString();
|
||||
if(nodeState)nodeState(id,"running");
|
||||
if(type=="sleep") {
|
||||
const auto delay=inputs(n).value("delayMs");
|
||||
const int ms=delay.isString()?delay.toString().toInt():delay.toInt();
|
||||
QTimer::singleShot(ms,this,[this,state,id,generation]{if(active(generation))finishNode(state,id);});
|
||||
}else if(type=="loop") {
|
||||
const auto value=inputs(n).value("loopNum");
|
||||
iteration(state,id,value.isString()?value.toString().toInt():value.toInt(),generation);
|
||||
}else if(type=="serviceNode") {
|
||||
const QString token=QUuid::createUuid().toString(QUuid::WithoutBraces);
|
||||
m_pending.insert(token,Pending{state,id});
|
||||
if(dispatch)dispatch(token,id);else fail(QStringLiteral("未连接接口执行器"));
|
||||
}else finishNode(state,id);
|
||||
});
|
||||
}
|
||||
void iteration(const std::shared_ptr<Scope> &state,const QString &id,int left,quint64 generation) {
|
||||
if(!active(generation))return;
|
||||
if(!left){finishNode(state,id);return;}
|
||||
scope(id,[this,state,id,left,generation] {
|
||||
QTimer::singleShot(0,this,[this,state,id,left,generation]{iteration(state,id,left-1,generation);});
|
||||
});
|
||||
}
|
||||
void finishNode(const std::shared_ptr<Scope> &state,const QString &id) {
|
||||
if(!m_running||state->done.contains(id))return;
|
||||
state->done.insert(id);if(nodeState)nodeState(id,"success");
|
||||
for(const auto &next:state->out.value(id))if(--state->degree[next]==0)schedule(state,next);
|
||||
if(state->done.size()==state->size&&state->finished)state->finished();
|
||||
}
|
||||
};
|
||||