You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nmWTAI-Platform/Include/nmNum/nmSubWxs/nmVolumeImportTask.h

51 lines
2.3 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#ifndef NMVOLUMEIMPORTTASK_H
#define NMVOLUMEIMPORTTASK_H
#include "nmSubWxs_global.h"
#include "nmVolumeData.h"
#include <QAtomicInt>
#include <QThread>
/**
* @brief 每个结果窗口独占的导入任务。
* 工作线程只操作局部 Reader 和数据候选,不访问 QWidget、Renderer 或 Manager。
* 结果只允许在 finished 后读取;取消标志是唯一由两个线程同时访问的成员。
*/
class NM_SUB_WXS_EXPORT nmVolumeImportTask : public QThread, public nmVolumeImportFeedback
{
Q_OBJECT
public:
/** @brief 保存输入路径,线程由调用方显式 start;父对象通常为结果窗口。 */
explicit nmVolumeImportTask(const QString& sFilePath, QObject* pParent = nullptr);
/** @brief 请求取消并等待安全退出,禁止释放仍运行的 VTK 代码资源。 */
virtual ~nmVolumeImportTask();
/** @brief 原子请求取消,可由 GUI 线程调用,不阻塞等待 Reader。 */
void requestCancel();
/** @brief 线程安全查询取消标记,供导入器的处理循环调用。 */
virtual bool isCanceled() const;
/** @brief 工作线程发出单调去重的进度信号,GUI 使用队列连接接收。 */
virtual void reportProgress(int nPercent);
/** @brief 仅在线程结束且未取消时返回结果,否则返回空指针。 */
QSharedPointer<const nmVolumeData> getResult() const;
/** @brief 在线程结束后返回错误文本;运行期间不读取跨线程字符串。 */
QString getError() const;
signals:
/** @brief 已完成的加载百分比,不包含 GUI 场景提交耗时。 */
void progressChanged(int nPercent);
protected:
/** @brief 工作线程入口,构建局部候选;取消后丢弃候选而不发布。 */
virtual void run();
private:
Q_DISABLE_COPY(nmVolumeImportTask)
QString m_sFilePath; ///< 创建时固定的输入路径,运行期间不再改写。
mutable QAtomicInt m_nCancelRequested; ///< GUI 写入、工作线程读取的原子取消标志。
QSharedPointer<const nmVolumeData> m_pResult; ///< 工作线程写入,finished 后 GUI 才读取。
QString m_sError; ///< 工作线程写入的失败原因,finished 后读取。
int m_nLastProgress; ///< 仅工作线程写入,减少重复的队列事件。
};
#endif // NMVOLUMEIMPORTTASK_H