奥特QT DDS 插件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

570 lines
23KB

  1. #include "AQTSampleMachinePlug.hpp"
  2. #include <QDebug>
  3. #include <fastdds/dds/domain/DomainParticipantFactory.hpp>
  4. #include <QQmlComponent>
  5. #include <QQmlContext>
  6. #include <QUrl>
  7. /**
  8. * @brief 构造函数
  9. * @param parent 父对象指针
  10. *
  11. * 初始化插件对象,包括:
  12. * - 初始化所有指针为空
  13. * - 创建DDS类型支持对象
  14. * - 初始化数据点信息
  15. */
  16. AQTSampleMachinePlug::AQTSampleMachinePlug(QObject *parent)
  17. : QObject(parent)
  18. , participant_(nullptr)
  19. , publisher_(nullptr)
  20. , subscriber_(nullptr)
  21. , commandTopic_(nullptr)
  22. , commandWriter_(nullptr)
  23. , statusTopic_(nullptr)
  24. , statusReader_(nullptr)
  25. , configTopic_(nullptr)
  26. , configWriter_(nullptr)
  27. , pointsTopic_(nullptr)
  28. , pointsWriter_(nullptr)
  29. , pointsReader_(nullptr)
  30. , m_configWindow(nullptr)
  31. {
  32. // 初始化类型支持
  33. commandType_ = TypeSupport(new SampleCommandPubSubType());
  34. statusType_ = TypeSupport(new SampleMachineInfoPubSubType());
  35. configType_ = TypeSupport(new SampleConfigPubSubType());
  36. pointsType_ = TypeSupport(new SamplePointsPubSubType());
  37. }
  38. /**
  39. * @brief 析构函数
  40. *
  41. * 清理插件对象,主要是清理所有DDS相关的资源。
  42. */
  43. AQTSampleMachinePlug::~AQTSampleMachinePlug()
  44. {
  45. // 清理DDS资源
  46. cleanupDDSEntities();
  47. if (m_configWindow) {
  48. m_configWindow->deleteLater();
  49. }
  50. }
  51. /**
  52. * @brief 初始化插件
  53. * @param domainId DDS域ID
  54. * @param domainName DDS域名称
  55. * @return 初始化是否成功
  56. *
  57. * 初始化DDS通信环境,包括:
  58. * - 创建DDS参与者
  59. * - 初始化所有DDS实体
  60. */
  61. bool AQTSampleMachinePlug::init(uint32_t domainId, const QString& domainName)
  62. {
  63. // 创建DDS参与者
  64. DomainParticipantQos participantQos;
  65. participantQos.name(domainName.toStdString());
  66. participant_ = DomainParticipantFactory::get_instance()->create_participant(domainId, participantQos);
  67. if (!participant_) {
  68. qDebug() << "Failed to create participant";
  69. return false;
  70. }
  71. // 初始化其他DDS实体
  72. return initDDSEntities();
  73. }
  74. /**
  75. * @brief 获取数据点信息列表
  76. * @return 所有支持的数据点信息列表
  77. */
  78. QList<DataPointInfo> AQTSampleMachinePlug::getDataPoints()
  79. {
  80. // 在函数调用时创建并返回数据点列表
  81. return {
  82. // ===== SampleConfigData 相关数据点 (1-9) =====
  83. {1, "UnifiedDepth", "uint16"}, // 统一深度(全段面采样时使用)
  84. {2, "SampleOrder", "uint8"}, // 大车行进顺序(1:原点往外,2:往原点采)
  85. // ===== SampleCommand 相关数据点 (10-29) =====
  86. {10, "CommandMaskBits", "uint32"}, // 命令掩码,表示哪些字段被修改
  87. {11, "ControlType", "uint8"}, // 控制类型(1:就地,2:远程)
  88. {12, "StartSample", "int32"}, // 启动采样命令 (CommandState: STOP=0, START=1)
  89. {13, "StopSample", "int32"}, // 停止采样命令 (CommandState: STOP=0, START=1)
  90. {14, "Reset", "int32"}, // 系统复位命令 (CommandState: STOP=0, START=1)
  91. {15, "PositionCheck", "int32"}, // 位置确认命令 (CommandState: STOP=0, START=1)
  92. {16, "EmergencyUp", "int32"}, // 紧急提升命令 (CommandState: STOP=0, START=1)
  93. {17, "EmergencyStop", "int32"}, // 系统急停命令 (CommandState: STOP=0, START=1)
  94. {18, "ControlBelt1", "int32"}, // 启停皮带1 (CommandState: STOP=0, START=1)
  95. {19, "ControlBelt2", "int32"}, // 启停皮带2 (CommandState: STOP=0, START=1)
  96. {20, "ControlCrush1", "int32"}, // 启停破碎机1 (CommandState: STOP=0, START=1)
  97. {21, "ControlCrush2", "int32"}, // 启停破碎机2 (CommandState: STOP=0, START=1)
  98. {22, "ControlDivider", "int32"}, // 启停缩分器 (CommandState: STOP=0, START=1)
  99. {23, "ControlCoalDistributor", "int32"}, // 启停布煤器 (CommandState: STOP=0, START=1)
  100. {24, "ReductionRatio", "uint16"}, // 缩分比
  101. {25, "CommandVersion", "uint8"}, // 命令结构体版本号
  102. // ===== SampleInfo 相关数据点 (30-49) =====
  103. {30, "StatusMaskBits", "uint32"}, // 状态掩码,表示哪些字段被修改
  104. {31, "BigPoint", "uint16"}, // 大车位置
  105. {32, "SmallPoint", "uint16"}, // 小车位置
  106. {33, "DepthPoint", "uint16"}, // 深度位置
  107. {34, "HasToXY", "uint8"}, // 到达坐标点(0:未到达,1:已到达)
  108. {35, "HasSamplePoints", "uint8"}, // 已采样点数
  109. {36, "GameOver", "uint8"}, // 采样完成(0:未完成,1:完成)
  110. {37, "BackState", "uint16"}, // 采样状态返回
  111. {38, "SampleState", "int32"}, // 采样机状态 (DeviceState: OFF=0, ON=1, ERROR=2)
  112. {39, "Belt1State", "int32"}, // 皮带1状态 (DeviceState: OFF=0, ON=1, ERROR=2)
  113. {40, "Belt2State", "int32"}, // 皮带2状态 (DeviceState: OFF=0, ON=1, ERROR=2)
  114. {41, "Crush1State", "int32"}, // 破碎机1状态 (DeviceState: OFF=0, ON=1, ERROR=2)
  115. {42, "Crush2State", "int32"}, // 破碎机2状态 (DeviceState: OFF=0, ON=1, ERROR=2)
  116. {43, "DividerState", "int32"}, // 缩分器状态 (DeviceState: OFF=0, ON=1, ERROR=2)
  117. {44, "BigLimit", "uint8"}, // 大车限位(0:未限位,1:已限位)
  118. {45, "BigZeroLimit", "uint8"}, // 大车零点限位(0:未限位,1:已限位)
  119. {46, "SmallLimit", "uint8"}, // 小车限位(0:未限位,1:已限位)
  120. {47, "SmallZeroLimit", "uint8"}, // 小车零点限位(0:未限位,1:已限位)
  121. {48, "UpLimit", "uint8"}, // 升高限位(0:未限位,1:已限位)
  122. {49, "DownLimit", "uint8"}, // 降低限位(0:未限位,1:已限位)
  123. {50, "StatusVersion", "uint8"}, // 状态结构体版本号
  124. // ===== SamplePoints 相关数据点 (51-99) =====
  125. {51, "TotalPoints", "uint8"}, // 采样点数量
  126. // 点1
  127. {52, "Point1X", "uint16"}, // 采样点1 X坐标
  128. {53, "Point1Y", "uint16"}, // 采样点1 Y坐标
  129. {54, "Point1Z", "uint16"}, // 采样点1 Z坐标
  130. {55, "Point1Drop", "int32"}, // 采样点1 落料选择 (DropChoice: BYPASS=0, CRUSHER=1)
  131. // 点2
  132. {56, "Point2X", "uint16"}, // 采样点2 X坐标
  133. {57, "Point2Y", "uint16"}, // 采样点2 Y坐标
  134. {58, "Point2Z", "uint16"}, // 采样点2 Z坐标
  135. {59, "Point2Drop", "int32"}, // 采样点2 落料选择 (DropChoice: BYPASS=0, CRUSHER=1)
  136. // 点3
  137. {60, "Point3X", "uint16"}, // 采样点3 X坐标
  138. {61, "Point3Y", "uint16"}, // 采样点3 Y坐标
  139. {62, "Point3Z", "uint16"}, // 采样点3 Z坐标
  140. {63, "Point3Drop", "int32"}, // 采样点3 落料选择 (DropChoice: BYPASS=0, CRUSHER=1)
  141. // 点4
  142. {64, "Point4X", "uint16"}, // 采样点4 X坐标
  143. {65, "Point4Y", "uint16"}, // 采样点4 Y坐标
  144. {66, "Point4Z", "uint16"}, // 采样点4 Z坐标
  145. {67, "Point4Drop", "int32"}, // 采样点4 落料选择 (DropChoice: BYPASS=0, CRUSHER=1)
  146. // 点5
  147. {68, "Point5X", "uint16"}, // 采样点5 X坐标
  148. {69, "Point5Y", "uint16"}, // 采样点5 Y坐标
  149. {70, "Point5Z", "uint16"}, // 采样点5 Z坐标
  150. {71, "Point5Drop", "int32"}, // 采样点5 落料选择 (DropChoice: BYPASS=0, CRUSHER=1)
  151. // 点6
  152. {72, "Point6X", "uint16"}, // 采样点6 X坐标
  153. {73, "Point6Y", "uint16"}, // 采样点6 Y坐标
  154. {74, "Point6Z", "uint16"}, // 采样点6 Z坐标
  155. {75, "Point6Drop", "int32"} // 采样点6 落料选择 (DropChoice: BYPASS=0, CRUSHER=1)
  156. };
  157. }
  158. /**
  159. * @brief 发布数据到DDS网络
  160. * @param dataList 要发布的数据项列表
  161. * @return 发布是否成功
  162. *
  163. * 将数据项列表转换为相应的DDS消息并发布:
  164. * - 检查写入器是否可用
  165. * - 转换数据格式
  166. * - 发送数据
  167. */
  168. bool AQTSampleMachinePlug::publishData(const QList<DataItem>& dataList)
  169. {
  170. if (dataList.isEmpty()) {
  171. qDebug() << "Empty data list received";
  172. return false;
  173. }
  174. try {
  175. // 根据第一个数据项的ID判断主题类型
  176. int firstId = dataList.first().ID;
  177. if (firstId >= 1 && firstId <= 9) { // 配置数据
  178. if (!configWriter_) {
  179. qDebug() << "Config writer not initialized";
  180. return false;
  181. }
  182. auto config = dataItemsToConfig(dataList);
  183. return configWriter_->write(&config);
  184. }
  185. else if (firstId >= 10 && firstId <= 29) { // 命令数据
  186. if (!commandWriter_) {
  187. qDebug() << "Command writer not initialized";
  188. return false;
  189. }
  190. auto command = dataItemsToCommand(dataList);
  191. return commandWriter_->write(&command);
  192. }
  193. else if (firstId >= 51 && firstId <= 99) { // 采样点数据
  194. if (!pointsWriter_) {
  195. qDebug() << "Points writer not initialized";
  196. return false;
  197. }
  198. auto points = dataItemsToPoints(dataList);
  199. return pointsWriter_->write(&points);
  200. }
  201. else {
  202. qDebug() << "Invalid data ID range:" << firstId;
  203. return false;
  204. }
  205. }
  206. catch (const std::exception& e) {
  207. qDebug() << "Error publishing data:" << e.what();
  208. return false;
  209. }
  210. }
  211. /**
  212. * @brief 初始化DDS实体
  213. * @return 初始化是否成功
  214. *
  215. * 创建并初始化所有DDS通信所需的实体,包括:
  216. * - 注册数据类型
  217. * - 创建发布者和订阅者
  218. * - 创建主题
  219. * - 创建数据写入器和读取器
  220. * - 设置数据监听器
  221. */
  222. bool AQTSampleMachinePlug::initDDSEntities()
  223. {
  224. try {
  225. // 注册所有类型
  226. commandType_.register_type(participant_);
  227. statusType_.register_type(participant_);
  228. configType_.register_type(participant_);
  229. pointsType_.register_type(participant_);
  230. // 创建发布者和订阅者
  231. publisher_ = participant_->create_publisher(PUBLISHER_QOS_DEFAULT);
  232. subscriber_ = participant_->create_subscriber(SUBSCRIBER_QOS_DEFAULT);
  233. if (!publisher_ || !subscriber_) {
  234. qDebug() << "Failed to create publisher or subscriber";
  235. return false;
  236. }
  237. // 创建所有主题
  238. commandTopic_ = participant_->create_topic("SampleMachine/Command",
  239. commandType_.get_type_name(), TOPIC_QOS_DEFAULT);
  240. statusTopic_ = participant_->create_topic("SampleMachine/Status",
  241. statusType_.get_type_name(), TOPIC_QOS_DEFAULT);
  242. configTopic_ = participant_->create_topic("SampleMachine/Config",
  243. configType_.get_type_name(), TOPIC_QOS_DEFAULT);
  244. pointsTopic_ = participant_->create_topic("SampleMachine/Points",
  245. pointsType_.get_type_name(), TOPIC_QOS_DEFAULT);
  246. if (!commandTopic_ || !statusTopic_ || !configTopic_ || !pointsTopic_) {
  247. qDebug() << "Failed to create topics";
  248. return false;
  249. }
  250. // 创建写入器和读取器
  251. commandWriter_ = publisher_->create_datawriter(commandTopic_, DATAWRITER_QOS_DEFAULT);
  252. statusReader_ = subscriber_->create_datareader(statusTopic_, DATAREADER_QOS_DEFAULT);
  253. configWriter_ = publisher_->create_datawriter(configTopic_, DATAWRITER_QOS_DEFAULT);
  254. pointsWriter_ = publisher_->create_datawriter(pointsTopic_, DATAWRITER_QOS_DEFAULT);
  255. pointsReader_ = subscriber_->create_datareader(pointsTopic_, DATAREADER_QOS_DEFAULT);
  256. if (!commandWriter_ || !statusReader_ || !configWriter_ ||
  257. !pointsWriter_ || !pointsReader_) {
  258. qDebug() << "Failed to create writers or readers";
  259. return false;
  260. }
  261. // 设置状态和采样点的监听器
  262. statusReader_->set_listener(this, StatusMask::data_available());
  263. pointsReader_->set_listener(this, StatusMask::data_available());
  264. return true;
  265. }
  266. catch (const std::exception& e) {
  267. qDebug() << "Error initializing DDS entities:" << e.what();
  268. return false;
  269. }
  270. }
  271. /**
  272. * @brief 清理DDS实体
  273. *
  274. * 清理所有已创建的DDS资源,包括:
  275. * - 删除所有包含的实体(主题、读写器等)
  276. * - 删除参与者
  277. */
  278. void AQTSampleMachinePlug::cleanupDDSEntities()
  279. {
  280. // 清理所有DDS资源
  281. if (participant_) {
  282. participant_->delete_contained_entities();
  283. DomainParticipantFactory::get_instance()->delete_participant(participant_);
  284. }
  285. }
  286. /**
  287. * @brief 数据可用性回调函数
  288. * @param reader 触发回调的数据读取器
  289. *
  290. * 当订阅的主题收到新数据时被调用。根据读取器类型分别处理状态数据和采样点数据,
  291. * 将DDS数据转换为DataItem列表并通过信号和回调函数通知外部。
  292. */
  293. void AQTSampleMachinePlug::on_data_available(DataReader* reader)
  294. {
  295. // if (reader == statusReader_) {
  296. // SampleStatus status;
  297. // SampleInfo info; // 添加正确的SampleInfo声明
  298. // // 问题3: while循环中的info变量未声明
  299. // while (reader->take_next_sample(&status, &info) == ReturnCode_t::RETCODE_OK) {
  300. // if (info.valid_data) {
  301. // auto dataItems = convertStatusToDataItems(status);
  302. // emit onDataUpdated(dataItems);
  303. // }
  304. // }
  305. // }
  306. // else if (reader == pointsReader_) {
  307. // // 这部分代码正确
  308. // SamplePoints points;
  309. // SampleInfo info;
  310. // while (reader->take_next_sample(&points, &info) == ReturnCode_t::RETCODE_OK) {
  311. // if (info.valid_data) {
  312. // auto dataItems = convertPointsToDataItems(points);
  313. // emit onDataUpdated(dataItems);
  314. // }
  315. // }
  316. // }
  317. }
  318. /**
  319. * @brief 将采样机状态转换为数据项列表
  320. * @param infos 采样机状态数据
  321. * @return 转换后的数据项列表
  322. *
  323. * 按照预定义的数据点ID,将SampleInfo结构体中的状态信息转换为DataItem列表。
  324. * 包括设备状态、位置信息、限位信息等。
  325. */
  326. QList<DataItem> AQTSampleMachinePlug::infoToDataItems(const SampleMachineInfo& infos)
  327. {
  328. QList<DataItem> items;
  329. // 按照数据点定义的顺序转换状态数据
  330. items.append(DataItem(30, infos.maskBits()));
  331. items.append(DataItem(31, infos.bigPoint()));
  332. items.append(DataItem(32, infos.smallPoint()));
  333. items.append(DataItem(33, infos.depthPoint()));
  334. items.append(DataItem(34, infos.hasToXY()));
  335. items.append(DataItem(35, infos.hasSamplePoints()));
  336. items.append(DataItem(36, infos.gameOver()));
  337. items.append(DataItem(37, infos.backState()));
  338. items.append(DataItem(38, static_cast<int32_t>(infos.sampleState())));
  339. items.append(DataItem(39, static_cast<int32_t>(infos.belt1State())));
  340. items.append(DataItem(40, static_cast<int32_t>(infos.belt2State())));
  341. items.append(DataItem(41, static_cast<int32_t>(infos.crush1State())));
  342. items.append(DataItem(42, static_cast<int32_t>(infos.crush2State())));
  343. items.append(DataItem(43, static_cast<int32_t>(infos.dividerState())));
  344. items.append(DataItem(44, infos.bigLimit()));
  345. items.append(DataItem(45, infos.bigZeroLimit()));
  346. items.append(DataItem(46, infos.smallLimit()));
  347. items.append(DataItem(47, infos.smallZeroLimit()));
  348. items.append(DataItem(48, infos.upLimit()));
  349. items.append(DataItem(49, infos.downLimit()));
  350. items.append(DataItem(50, infos.version()));
  351. return items;
  352. }
  353. SampleCommand AQTSampleMachinePlug::dataItemsToCommand(const QList<DataItem>& items)
  354. {
  355. // 初始化命令对象
  356. SampleCommand command;
  357. command.maskBits(0); // 初始化掩码为0
  358. // 遍历输入的数据项列表
  359. for (const auto& item : items) {
  360. // 根据数据项的ID进行不同的处理
  361. switch (item.ID) {
  362. case 11: // 控制类型
  363. command.controlType(item.value.toUInt());
  364. command.maskBits(command.maskBits() | 0x00000002); // 设置对应的掩码位
  365. break;
  366. case 12: // 开始采样
  367. command.startSample(static_cast<SampleModule::CommandState>(item.value.toInt()));
  368. command.maskBits(command.maskBits() | 0x00000004);
  369. break;
  370. case 13: // 停止采样
  371. command.stopSample(static_cast<SampleModule::CommandState>(item.value.toInt()));
  372. command.maskBits(command.maskBits() | 0x00000008);
  373. break;
  374. case 14: // 复位
  375. command.reset(static_cast<SampleModule::CommandState>(item.value.toInt()));
  376. command.maskBits(command.maskBits() | 0x00000010);
  377. break;
  378. case 15: // 位置检查
  379. command.positionCheck(static_cast<SampleModule::CommandState>(item.value.toInt()));
  380. command.maskBits(command.maskBits() | 0x00000020);
  381. break;
  382. case 16: // 紧急上升
  383. command.emergencyUp(static_cast<SampleModule::CommandState>(item.value.toInt()));
  384. command.maskBits(command.maskBits() | 0x00000040);
  385. break;
  386. case 17: // 紧急停止
  387. command.emergencyStop(static_cast<SampleModule::CommandState>(item.value.toInt()));
  388. command.maskBits(command.maskBits() | 0x00000080);
  389. break;
  390. case 18: // 控制传送带1
  391. command.controlBelt1(static_cast<SampleModule::CommandState>(item.value.toInt()));
  392. command.maskBits(command.maskBits() | 0x00000100);
  393. break;
  394. case 19: // 控制传送带2
  395. command.controlBelt2(static_cast<SampleModule::CommandState>(item.value.toInt()));
  396. command.maskBits(command.maskBits() | 0x00000200);
  397. break;
  398. case 20: // 控制破碎机1
  399. command.controlCrush1(static_cast<SampleModule::CommandState>(item.value.toInt()));
  400. command.maskBits(command.maskBits() | 0x00000400);
  401. break;
  402. case 21: // 控制破碎机2
  403. command.controlCrush2(static_cast<SampleModule::CommandState>(item.value.toInt()));
  404. command.maskBits(command.maskBits() | 0x00000800);
  405. break;
  406. case 22: // 控制分流器
  407. command.controlDivider(static_cast<SampleModule::CommandState>(item.value.toInt()));
  408. command.maskBits(command.maskBits() | 0x00001000);
  409. break;
  410. case 23: // 控制分煤器
  411. command.controlCoalDistributor(static_cast<SampleModule::CommandState>(item.value.toInt()));
  412. command.maskBits(command.maskBits() | 0x00002000);
  413. break;
  414. case 24: // 减速比
  415. command.reductionRatio(item.value.toUInt());
  416. command.maskBits(command.maskBits() | 0x00004000);
  417. break;
  418. case 25: // 版本号
  419. command.version(item.value.toUInt());
  420. command.maskBits(command.maskBits() | 0x00008000);
  421. break;
  422. default: // 未知ID
  423. qWarning() << "Unknown command ID:" << item.ID;
  424. break;
  425. }
  426. }
  427. // 返回构建好的命令对象
  428. return command;
  429. }
  430. SampleConfig AQTSampleMachinePlug::dataItemsToConfig(const QList<DataItem>& items)
  431. {
  432. SampleConfig config;
  433. for (const auto& item : items) {
  434. switch (item.ID) {
  435. case 1: config.unifiedDepth(item.value.toUInt()); break;
  436. case 2: config.sampleOrder(item.value.toUInt()); break;
  437. // 添加其他配置项的转换
  438. default: break;
  439. }
  440. }
  441. return config;
  442. }
  443. SamplePoints AQTSampleMachinePlug::dataItemsToPoints(const QList<DataItem>& items)
  444. {
  445. SamplePoints points;
  446. for (const auto& item : items) {
  447. switch (item.ID) {
  448. // 从51开始添加新的数据项
  449. case 51: points.totalPoints(item.value.toUInt()); break;
  450. case 52: points.x1(item.value.toUInt()); break;
  451. case 53: points.y1(item.value.toUInt()); break;
  452. case 54: points.z1(item.value.toUInt()); break;
  453. case 55: points.o1(static_cast<SampleModule::DropChoice>(item.value.toInt())); break;
  454. case 56: points.x2(item.value.toUInt()); break;
  455. case 57: points.y2(item.value.toUInt()); break;
  456. case 58: points.z2(item.value.toUInt()); break;
  457. case 59: points.o2(static_cast<SampleModule::DropChoice>(item.value.toInt())); break;
  458. case 60: points.x3(item.value.toUInt()); break;
  459. case 61: points.y3(item.value.toUInt()); break;
  460. case 62: points.z3(item.value.toUInt()); break;
  461. case 63: points.o3(static_cast<SampleModule::DropChoice>(item.value.toInt())); break;
  462. case 64: points.x4(item.value.toUInt()); break;
  463. case 65: points.y4(item.value.toUInt()); break;
  464. case 66: points.z4(item.value.toUInt()); break;
  465. case 67: points.o4(static_cast<SampleModule::DropChoice>(item.value.toInt())); break;
  466. case 68: points.x5(item.value.toUInt()); break;
  467. case 69: points.y5(item.value.toUInt()); break;
  468. case 70: points.z5(item.value.toUInt()); break;
  469. case 71: points.o5(static_cast<SampleModule::DropChoice>(item.value.toInt())); break;
  470. case 72: points.x6(item.value.toUInt()); break;
  471. case 73: points.y6(item.value.toUInt()); break;
  472. case 74: points.z6(item.value.toUInt()); break;
  473. case 75: points.o6(static_cast<SampleModule::DropChoice>(item.value.toInt())); break;
  474. default:
  475. qWarning() << "Unknown command ID:" << item.ID;
  476. break;
  477. }
  478. }
  479. return points;
  480. }
  481. void AQTSampleMachinePlug::createConfigWindow()
  482. {
  483. if (!m_configWindow) {
  484. QQmlEngine *engine = new QQmlEngine(this);
  485. QQmlComponent component(engine, QUrl::fromLocalFile("plugins/AQTSampleMachinePlug/ConfigWindow.qml"));
  486. if (component.isError()) {
  487. qDebug() << "Error loading QML:" << component.errors();
  488. return;
  489. }
  490. QObject *object = component.create();
  491. m_configWindow = qobject_cast<QQuickWindow*>(object);
  492. if (!m_configWindow) {
  493. qDebug() << "Failed to create config window";
  494. delete object;
  495. return;
  496. }
  497. }
  498. }
  499. bool AQTSampleMachinePlug::config()
  500. {
  501. createConfigWindow();
  502. if (m_configWindow) {
  503. m_configWindow->show();
  504. }
  505. return true;
  506. }