diff --git a/Bin/Config/Lang/cn/nmNum_cn.qm b/Bin/Config/Lang/cn/nmNum_cn.qm
index eee352b4..fcbffeb3 100644
Binary files a/Bin/Config/Lang/cn/nmNum_cn.qm and b/Bin/Config/Lang/cn/nmNum_cn.qm differ
diff --git a/Bin/Config/Lang/cn/nmNum_cn.ts b/Bin/Config/Lang/cn/nmNum_cn.ts
index d9e76056..60b82abe 100644
--- a/Bin/Config/Lang/cn/nmNum_cn.ts
+++ b/Bin/Config/Lang/cn/nmNum_cn.ts
@@ -2815,6 +2815,39 @@ Reason: %1
The result property range is invalid.结果属性范围无效。
Unable to apply the result property or frame.无法应用结果属性或帧。
+
+ nmPebiResultProperty
+ Permeability渗透率
+ Porosity孔隙度
+ Thickness厚度
+ Pressure压力
+
+
+ nmPebiResultPlaybackController
+ Result playback is unavailable.结果回放不可用。
+ The selected result property is unavailable.所选结果属性不可用。
+ The selected result frame is unavailable.所选结果帧不可用。
+ Playback speed must be between 1 and 60 steps per second.回放速度必须介于每秒 1 到 60 步之间。
+
+
+ nmWxPebiResultControlBar
+ Display property显示属性
+ First frame第一帧
+ Previous frame上一帧
+ Result time结果时间
+ Next frame下一帧
+ Last frame末帧
+ Play播放
+ Pause暂停
+ Animation settings动画设置
+ t = %1 ht = %1 h
+
+
+ nmWxPebiResultAnimationSettingsDlg
+ Animation settings动画设置
+ Loop enabled启用循环
+ Speed (steps/second)速度(步/秒)
+
nmWxPebiGridViewWidget
No grid data.暂无网格数据。
diff --git a/Include/nmNum/nmData/nmPebiResultSnapshot.h b/Include/nmNum/nmData/nmPebiResultSnapshot.h
index b8f5b0b2..a7f59b7c 100644
--- a/Include/nmNum/nmData/nmPebiResultSnapshot.h
+++ b/Include/nmNum/nmData/nmPebiResultSnapshot.h
@@ -292,7 +292,7 @@ public:
/** @brief 返回属性帧数;未知属性返回 0,静态属性固定返回 1。 */
int getPropertyFrameCount(const QString& sPropertyId) const;
/**
- * @brief 返回动态属性指定帧的时间。
+ * @brief 返回动态属性指定帧的求解时间,单位固定为小时。
* @note 静态属性、未知属性或越界帧返回 false,且不修改 dTime。
*/
bool getPropertyTimeAt(const QString& sPropertyId,
@@ -303,7 +303,7 @@ public:
double aRange[2]) const;
/** @brief 返回压力时间步数量。 */
int getPressureFrameCount() const;
- /** @brief 返回指定压力帧的时间,越界时返回 0。 */
+ /** @brief 返回指定压力帧的求解时间,单位固定为小时;越界时返回 0。 */
double getPressureTimeAt(int nIndex) const;
/** @brief 返回全部压力帧的全局标量范围。 */
bool getScalarRange(double aRange[2]) const;
@@ -321,7 +321,7 @@ private:
/** @brief 初始化空压力帧。 */
PressureFrame();
- /** @brief 该压力帧对应的求解时间。 */
+ /** @brief 该压力帧对应的求解时间,单位固定为小时。 */
double m_dTime;
/** @brief 快照规范持有的单分量单元压力数组。 */
vtkSmartPointer m_pPressure;
diff --git a/Include/nmNum/nmData/nmPebiResultSnapshotBuilder.h b/Include/nmNum/nmData/nmPebiResultSnapshotBuilder.h
index 8c4037ed..66dcb8ae 100644
--- a/Include/nmNum/nmData/nmPebiResultSnapshotBuilder.h
+++ b/Include/nmNum/nmData/nmPebiResultSnapshotBuilder.h
@@ -34,7 +34,10 @@ public:
* @note 失败时调用方三个数组保持不变;成功后通过 qSwap 清空调用方。
*/
bool takeStaticProperties(nmPebiStaticPropertyValues& oValues);
- /** @brief 成功后接管压力数组且清空调用方智能指针,不复制整帧数据。 */
+ /**
+ * @brief 按小时记录求解时间,成功后接管压力数组并清空调用方智能指针。
+ * @note 不复制整帧数据。
+ */
bool addPressureFrame(
double dTime,
vtkSmartPointer& pPressure);
diff --git a/Include/nmNum/nmSubWxs/nmPebiResultPlaybackController.h b/Include/nmNum/nmSubWxs/nmPebiResultPlaybackController.h
new file mode 100644
index 00000000..3e3022a4
--- /dev/null
+++ b/Include/nmNum/nmSubWxs/nmPebiResultPlaybackController.h
@@ -0,0 +1,140 @@
+#ifndef NMPEBIRESULTPLAYBACKCONTROLLER_H
+#define NMPEBIRESULTPLAYBACKCONTROLLER_H
+
+#include "nmSubWxs_global.h"
+
+#include
+#include
+#include
+
+class QTimer;
+class nmPebiResultSceneController;
+
+/**
+ * @brief 管理结果属性选择、压力帧请求和回放定时器。
+ *
+ * SceneController 是已渲染属性和帧的唯一真实来源。本控制器只保存播放状态、
+ * 速度、循环偏好、最后压力帧和已观察的快照 ID,不持有任何 VTK 对象。
+ */
+class NM_SUB_WXS_EXPORT nmPebiResultPlaybackController : public QObject
+{
+ Q_OBJECT
+
+public:
+ /** @brief 回放速度的合法下限、上限和窗口默认值,单位均为步/秒。 */
+ enum
+ {
+ MinimumPlaybackSpeed = 1,
+ MaximumPlaybackSpeed = 60,
+ DefaultPlaybackSpeed = 5
+ };
+
+ /** @param pSceneController 非所有权指针,必须比本控制器生命周期更长。 */
+ explicit nmPebiResultPlaybackController(
+ nmPebiResultSceneController* pSceneController,
+ QObject* pParent = nullptr);
+ /** @brief 停止定时器;QTimer 随 QObject 子对象树自动销毁。 */
+ virtual ~nmPebiResultPlaybackController();
+
+ /**
+ * @brief 按 Snapshot ID 同步场景状态。
+ *
+ * 新快照和无快照会停止播放;同快照普通重同步保留有效播放状态。
+ */
+ void synchronizeFromScene();
+
+ /** @brief 暂停后选择属性;动态压力恢复最后一次成功帧,失败返回 false。 */
+ bool selectProperty(const QString& sPropertyId);
+ /** @brief 暂停后请求当前动态属性切换到指定零基帧,失败返回 false。 */
+ bool selectFrame(int nFrameIndex);
+ /** @brief 暂停并请求当前动态属性的第一帧。 */
+ bool selectFirstFrame();
+ /** @brief 暂停并请求当前动态属性的上一帧。 */
+ bool selectPreviousFrame();
+ /** @brief 暂停并请求当前动态属性的下一帧。 */
+ bool selectNextFrame();
+ /** @brief 暂停并请求当前动态属性的末帧。 */
+ bool selectLastFrame();
+ /** @brief 在播放和暂停之间切换;末帧开始播放时先提交第 0 帧。 */
+ bool togglePlayback();
+ /** @brief 只停止 Timer,不改变 Scene 当前帧。 */
+ void pause();
+
+ /**
+ * @brief 事务式提交回放速度和循环偏好。
+ * @note 速度非法时两个设置均保持不变。
+ */
+ bool setPlaybackSettings(int nStepsPerSecond, bool bLoopEnabled);
+
+ /** @brief 返回 Scene 是否仍有完整可渲染快照。 */
+ bool isAvailable() const;
+ /** @brief 返回控制器最近一次同步到的快照 ID。 */
+ QString getObservedSnapshotId() const;
+ /** @brief 直接转发 Scene 中按 Catalog 排序的可用属性 ID。 */
+ QStringList getAvailablePropertyIds() const;
+ /** @brief 直接转发 Scene 已成功渲染的当前属性 ID。 */
+ QString getCurrentPropertyId() const;
+ /** @brief 直接转发 Scene 已成功渲染的当前零基帧。 */
+ int getCurrentFrameIndex() const;
+ /** @brief 直接查询 Scene 中指定属性是否为动态属性。 */
+ bool isPropertyTimeDependent(const QString& sPropertyId) const;
+ /** @brief 直接查询 Scene 中指定属性的帧数。 */
+ int getPropertyFrameCount(const QString& sPropertyId) const;
+ /** @brief 返回指定动态帧的求解时间,单位固定为小时。 */
+ bool getPropertyTimeAt(const QString& sPropertyId,
+ int nFrameIndex,
+ double& dTime) const;
+ /** @brief 返回 Scene 当前属性是否为动态属性。 */
+ bool isCurrentPropertyTimeDependent() const;
+ /** @brief 返回 Scene 当前属性的帧数。 */
+ int getCurrentPropertyFrameCount() const;
+ /** @brief 返回同一快照内最后一次成功提交的压力帧记忆。 */
+ int getLastPressureFrameIndex() const;
+ /** @brief 返回当前窗口回放速度,单位为步/秒。 */
+ int getPlaybackSpeed() const;
+ /** @brief 返回当前速度对应的整数毫秒间隔。 */
+ int getPlaybackIntervalMilliseconds() const;
+ /** @brief 返回当前窗口是否启用循环播放。 */
+ bool isLoopEnabled() const;
+ /** @brief 返回 Timer 和播放标志是否同时处于运行状态。 */
+ bool isPlaying() const;
+
+signals:
+ /** @brief 任一可观察状态完成提交或完成外部同步后发出。 */
+ void stateChanged();
+ /** @brief 操作失败且状态已恢复到最后成功值后发出。 */
+ void operationFailed(const QString& sError);
+
+private slots:
+ /** @brief 计算下一目标帧,Scene 成功提交后才更新压力帧记忆。 */
+ void onPlaybackTimeout();
+
+private:
+ Q_DISABLE_COPY(nmPebiResultPlaybackController)
+
+ /** @brief 停止定时器但不发信号,供事务路径统一收尾。 */
+ bool stopTimerWithoutSignal();
+ /** @brief 同步快照身份;返回当前 Scene 是否仍有可用快照。 */
+ bool synchronizeSceneIdentity();
+ /** @brief 按固定顺序同步失败后的 Scene 状态并通知界面。 */
+ bool finishFailedOperation(const QString& sError);
+ /** @brief 使用当前速度计算至少 1ms 的定时器间隔。 */
+ int calculatePlaybackInterval() const;
+
+ /** @brief 已渲染属性和帧的唯一真实来源;本类不拥有。 */
+ nmPebiResultSceneController* m_pSceneController;
+ /** @brief 驱动帧请求的 QObject 子对象,由本控制器自动销毁。 */
+ QTimer* m_pTimer;
+ /** @brief 最近一次同步成功的 Snapshot ID,用于识别快照替换。 */
+ QString m_sObservedSnapshotId;
+ /** @brief 同一快照内最后一次成功提交的 pressure 零基帧。 */
+ int m_nLastPressureFrameIndex;
+ /** @brief 当前窗口播放速度,单位为步/秒。 */
+ int m_nStepsPerSecond;
+ /** @brief 末帧之后是否回到第 0 帧。 */
+ bool m_bLoopEnabled;
+ /** @brief 与 Timer 共同描述当前是否正在自动回放。 */
+ bool m_bPlaying;
+};
+
+#endif // NMPEBIRESULTPLAYBACKCONTROLLER_H
diff --git a/Include/nmNum/nmSubWxs/nmPebiResultPropertyDisplayText.h b/Include/nmNum/nmSubWxs/nmPebiResultPropertyDisplayText.h
new file mode 100644
index 00000000..9af9d8ac
--- /dev/null
+++ b/Include/nmNum/nmSubWxs/nmPebiResultPropertyDisplayText.h
@@ -0,0 +1,34 @@
+#ifndef NMPEBIRESULTPROPERTYDISPLAYTEXT_H
+#define NMPEBIRESULTPROPERTYDISPLAYTEXT_H
+
+#include "nmSubWxs_global.h"
+
+#include
+
+/**
+ * @brief 将结果属性目录中的稳定源文字转换为当前语言下的界面文字。
+ *
+ * 属性 ID、英文源文字和单位仍由 nmPebiResultPropertyCatalog 唯一维护;
+ * 本类只负责固定翻译上下文,避免各业务控件重复硬编码属性名称。
+ */
+class NM_SUB_WXS_EXPORT nmPebiResultPropertyDisplayText
+{
+public:
+ /**
+ * @brief 返回固定翻译上下文中的属性名称。
+ * @param sPropertyId Catalog 中的稳定英文属性 ID。
+ * @return 翻译后的名称;未知属性返回空字符串。
+ */
+ static QString getDisplayName(const QString& sPropertyId);
+ /**
+ * @brief 返回 Catalog 中的默认显示单位。
+ * @return 单位原文;未知属性或无量纲属性返回空字符串。
+ */
+ static QString getDefaultDisplayUnit(const QString& sPropertyId);
+
+private:
+ /** @brief 纯静态辅助类,不允许创建实例。 */
+ nmPebiResultPropertyDisplayText();
+};
+
+#endif // NMPEBIRESULTPROPERTYDISPLAYTEXT_H
diff --git a/Include/nmNum/nmSubWxs/nmPebiResultSceneController.h b/Include/nmNum/nmSubWxs/nmPebiResultSceneController.h
index 2ed71845..448c4652 100644
--- a/Include/nmNum/nmSubWxs/nmPebiResultSceneController.h
+++ b/Include/nmNum/nmSubWxs/nmPebiResultSceneController.h
@@ -27,6 +27,7 @@ public:
*/
explicit nmPebiResultSceneController(
nmWxVTKRenderContainerWidget* pContainer);
+ /** @brief 断开活动管线并移除本控制器创建的稳定 ID 图层。 */
~nmPebiResultSceneController();
/**
@@ -48,28 +49,52 @@ public:
int nFrameIndex,
QString* pError = nullptr);
- /** 以下显示设置会作为偏好保留,并在存在活动快照时渲染一次。 */
+ /** @brief 设置结果网格显隐;偏好跨快照保留。 */
void setMeshVisible(bool bVisible);
+ /** @brief 设置色标显隐;阶段 5A 默认隐藏,偏好跨快照保留。 */
void setScalarBarVisible(bool bVisible);
+ /** @brief 设置平面比例网格显隐;偏好跨快照保留。 */
void setScaleGridVisible(bool bVisible);
+ /** @brief 设置单元边线显隐;偏好跨快照保留。 */
void setCellEdgesVisible(bool bVisible);
+ /** @brief 返回当前是否持有可用快照且稳定结果图层仍完整。 */
bool hasSnapshot() const;
+ /** @brief 返回当前快照稳定 ID;无可用快照时返回空字符串。 */
QString getCurrentSnapshotId() const;
+ /** @brief 按 Catalog 顺序返回当前快照真实存在的属性 ID。 */
QStringList getAvailablePropertyIds() const;
+ /** @brief 返回最后一次成功渲染的属性 ID。 */
QString getCurrentPropertyId() const;
+ /** @brief 返回最后一次成功渲染的零基帧;无快照时返回 -1。 */
int getCurrentFrameIndex() const;
+ /** @brief 判断当前快照中的指定属性是否为动态属性。 */
+ bool isPropertyTimeDependent(const QString& sPropertyId) const;
+ /** @brief 返回当前快照中指定属性的帧数,不可用时返回 0。 */
+ int getPropertyFrameCount(const QString& sPropertyId) const;
+ /**
+ * @brief 返回动态属性指定帧的求解时间,单位固定为小时。
+ * @note 查询失败时返回 false,且不修改 dTime。
+ */
+ bool getPropertyTimeAt(const QString& sPropertyId,
+ int nFrameIndex,
+ double& dTime) const;
/** @brief 返回快照中的业务范围;常量属性保持 [c,c]。 */
bool getCurrentPropertyRange(double dRange[2]) const;
+ /** @brief 返回结果网格显示偏好,不要求当前存在快照。 */
bool isMeshVisible() const;
+ /** @brief 返回色标显示偏好,不要求当前存在快照。 */
bool isScalarBarVisible() const;
+ /** @brief 返回比例网格显示偏好,不要求当前存在快照。 */
bool isScaleGridVisible() const;
+ /** @brief 返回单元边线显示偏好,不要求当前存在快照。 */
bool areCellEdgesVisible() const;
private:
Q_DISABLE_COPY(nmPebiResultSceneController)
- nmPebiResultSceneControllerPrivate* m_pPrivate; ///< 独占实现对象。
+ /** @brief 独占实现对象,保存快照、Adapter 及 Scene 图层观察指针。 */
+ nmPebiResultSceneControllerPrivate* m_pPrivate;
};
#endif // NMPEBIRESULTSCENECONTROLLER_H
diff --git a/Include/nmNum/nmSubWxs/nmWxPebiResultAnimationSettingsDlg.h b/Include/nmNum/nmSubWxs/nmWxPebiResultAnimationSettingsDlg.h
new file mode 100644
index 00000000..7409e9aa
--- /dev/null
+++ b/Include/nmNum/nmSubWxs/nmWxPebiResultAnimationSettingsDlg.h
@@ -0,0 +1,50 @@
+#ifndef NMWXPEBIRESULTANIMATIONSETTINGSDLG_H
+#define NMWXPEBIRESULTANIMATIONSETTINGSDLG_H
+
+#include "nmSubWxs_global.h"
+
+#include
+
+class QCheckBox;
+class QSpinBox;
+
+/**
+ * @brief 临时编辑当前结果窗口的回放速度和循环偏好。
+ *
+ * 对话框不直接修改 PlaybackController;调用方仅在 accepted() 后读取
+ * 两个值并事务式提交,因此取消或关闭对话框不会改变窗口偏好。
+ */
+class NM_SUB_WXS_EXPORT nmWxPebiResultAnimationSettingsDlg
+ : public QDialog
+{
+ Q_OBJECT
+
+public:
+ /**
+ * @brief 使用当前窗口偏好初始化临时编辑值。
+ * @param nStepsPerSecond 初始速度,防御性限制到 1~60 步/秒。
+ * @param bLoopEnabled 初始循环开关。
+ * @param pParent 所属窗口,用于 Qt 对象树和模态定位。
+ */
+ explicit nmWxPebiResultAnimationSettingsDlg(
+ int nStepsPerSecond,
+ bool bLoopEnabled,
+ QWidget* pParent = nullptr);
+ /** @brief 子控件由 Qt 对象树自动释放。 */
+ virtual ~nmWxPebiResultAnimationSettingsDlg();
+
+ /** @brief 返回尚未提交的整数播放速度,单位为步/秒。 */
+ int getPlaybackSpeed() const;
+ /** @brief 返回尚未提交的循环播放选择。 */
+ bool isLoopEnabled() const;
+
+private:
+ Q_DISABLE_COPY(nmWxPebiResultAnimationSettingsDlg)
+
+ /** @brief 限制在 1~60 步/秒的速度输入框。 */
+ QSpinBox* m_pSpeedSpin;
+ /** @brief 是否在末帧之后回到第 0 帧。 */
+ QCheckBox* m_pLoopCheck;
+};
+
+#endif // NMWXPEBIRESULTANIMATIONSETTINGSDLG_H
diff --git a/Include/nmNum/nmSubWxs/nmWxPebiResultControlBar.h b/Include/nmNum/nmSubWxs/nmWxPebiResultControlBar.h
new file mode 100644
index 00000000..8770609a
--- /dev/null
+++ b/Include/nmNum/nmSubWxs/nmWxPebiResultControlBar.h
@@ -0,0 +1,113 @@
+#ifndef NMWXPEBIRESULTCONTROLBAR_H
+#define NMWXPEBIRESULTCONTROLBAR_H
+
+#include "nmSubWxs_global.h"
+
+#include
+#include
+
+class QComboBox;
+class QToolButton;
+class QVariant;
+
+class nmPebiResultPlaybackController;
+class nmPebiResultSceneController;
+
+/**
+ * @brief 结果属性选择与时间回放底部控制条。
+ *
+ * 控件只镜像 PlaybackController/SceneController 状态,不创建 Renderer、
+ * Actor、Mapper、Adapter 或任何额外 VTK 管线。
+ */
+class NM_SUB_WXS_EXPORT nmWxPebiResultControlBar : public QWidget
+{
+ Q_OBJECT
+
+public:
+ /** @param pSceneController 非所有权指针,必须比控制条生命周期更长。 */
+ explicit nmWxPebiResultControlBar(
+ nmPebiResultSceneController* pSceneController,
+ QWidget* pParent = nullptr);
+ /** @brief 析构前停止回放,随后由 Qt 对象树释放控制器和子控件。 */
+ virtual ~nmWxPebiResultControlBar();
+
+ /** @brief 立即停止当前窗口播放,保留 Scene 已显示帧。 */
+ void stopPlayback();
+ /** @brief 在外部完成 Scene 快照提交或清理后同步全部控件。 */
+ void synchronizeFromScene();
+ /**
+ * @brief 返回本控制条独占的回放控制器。
+ * @note 仅供组合窗口查询或配置,调用方不得保存到控制条生命周期之外。
+ */
+ nmPebiResultPlaybackController* getPlaybackController() const;
+
+signals:
+ /** @brief 转发回放控制器错误,供后续组合窗口显示非阻塞提示。 */
+ void operationFailed(const QString& sError);
+
+private slots:
+ /** @brief 用户选择属性时提交稳定属性 ID。 */
+ void onPropertyIndexChanged(int nIndex);
+ /** @brief 用户选择时间时提交 itemData 中的零基帧。 */
+ void onTimeIndexChanged(int nIndex);
+ /** @brief 响应首帧按钮。 */
+ void onFirstFrameClicked();
+ /** @brief 响应上一帧按钮。 */
+ void onPreviousFrameClicked();
+ /** @brief 响应下一帧按钮。 */
+ void onNextFrameClicked();
+ /** @brief 响应末帧按钮。 */
+ void onLastFrameClicked();
+ /** @brief 切换播放或暂停图标对应的回放状态。 */
+ void onPlayPauseClicked();
+ /** @brief 暂停后打开当前窗口独立的动画设置对话框。 */
+ void onAnimationSettingsClicked();
+ /** @brief 从 Controller getter 重建或刷新控件镜像状态。 */
+ void refreshFromController();
+ /** @brief 将控制器错误转发给后续组合窗口。 */
+ void forwardOperationFailure(const QString& sError);
+
+private:
+ Q_DISABLE_COPY(nmWxPebiResultControlBar)
+
+ /** @brief 按固定顺序创建属性、导航、时间、播放和设置控件。 */
+ void createUi();
+ /** @brief 按快照属性顺序重建属性项,itemData 保存稳定 ID。 */
+ void rebuildPropertyItems(const QStringList& listPropertyIds);
+ /** @brief 按小时制时间轴重建时间项,itemData 保存零基帧。 */
+ void rebuildTimeItems(const QString& sPropertyId, int nFrameCount);
+ /** @brief 清空并禁用不适用于静态属性的时间下拉框。 */
+ void clearTimeItems();
+ /** @brief 使用 QVariant 精确匹配 ComboBox 的稳定业务数据。 */
+ int findItemByData(QComboBox* pComboBox,
+ const QVariant& oData) const;
+
+ /** @brief 本控制条独占的 QObject 子对象,负责全部回放业务状态。 */
+ nmPebiResultPlaybackController* m_pPlaybackController;
+ /** @brief 属性选择框,条目数据保存稳定英文属性 ID。 */
+ QComboBox* m_pPropertyCombo;
+ /** @brief 跳到第 0 帧的图标按钮。 */
+ QToolButton* m_pFirstButton;
+ /** @brief 跳到上一帧的图标按钮。 */
+ QToolButton* m_pPreviousButton;
+ /** @brief 小时制时间选择框,条目数据保存零基帧。 */
+ QComboBox* m_pTimeCombo;
+ /** @brief 跳到下一帧的图标按钮。 */
+ QToolButton* m_pNextButton;
+ /** @brief 跳到末帧的图标按钮。 */
+ QToolButton* m_pLastButton;
+ /** @brief 根据回放状态切换播放和暂停图标。 */
+ QToolButton* m_pPlayPauseButton;
+ /** @brief 打开速度与循环设置对话框。 */
+ QToolButton* m_pSettingsButton;
+ /** @brief 当前属性项对应的 Snapshot ID,仅用于避免重复重建 UI。 */
+ QString m_sDisplayedSnapshotId;
+ /** @brief 当前属性框已展示的有序 ID,仅用于避免重复重建 UI。 */
+ QStringList m_listDisplayedPropertyIds;
+ /** @brief 当前时间框对应的动态属性 ID。 */
+ QString m_sDisplayedTimePropertyId;
+ /** @brief 当前时间框已完整构建的帧数,失败时为 -1。 */
+ int m_nDisplayedTimeFrameCount;
+};
+
+#endif // NMWXPEBIRESULTCONTROLBAR_H
diff --git a/Src/nmNum/nmSubWxs/nmPebiResultPlaybackController.cpp b/Src/nmNum/nmSubWxs/nmPebiResultPlaybackController.cpp
new file mode 100644
index 00000000..3b9b6dc8
--- /dev/null
+++ b/Src/nmNum/nmSubWxs/nmPebiResultPlaybackController.cpp
@@ -0,0 +1,454 @@
+#include "nmPebiResultPlaybackController.h"
+
+#include "nmPebiResultSceneController.h"
+
+#include
+#include
+#include
+
+namespace {
+
+const char* const PRESSURE_PROPERTY_ID = "pressure";
+
+/* Qt 4.8 的 lupdate 无法从变量参数中推导翻译原文,必须显式登记。 */
+static const char* const s_pPlaybackTranslationMarkers[] =
+{
+ QT_TRANSLATE_NOOP("nmPebiResultPlaybackController",
+ "Result playback is unavailable."),
+ QT_TRANSLATE_NOOP("nmPebiResultPlaybackController",
+ "The selected result property is unavailable."),
+ QT_TRANSLATE_NOOP("nmPebiResultPlaybackController",
+ "The selected result frame is unavailable."),
+ QT_TRANSLATE_NOOP("nmPebiResultPlaybackController",
+ "Playback speed must be between 1 and 60 steps per second.")
+};
+
+QString playbackText(const char* pText)
+{
+ Q_UNUSED(s_pPlaybackTranslationMarkers);
+ return QCoreApplication::translate(
+ "nmPebiResultPlaybackController", pText);
+}
+
+bool isPressureProperty(const QString& sPropertyId)
+{
+ return sPropertyId == QString::fromLatin1(PRESSURE_PROPERTY_ID);
+}
+
+}
+
+nmPebiResultPlaybackController::nmPebiResultPlaybackController(
+ nmPebiResultSceneController* pSceneController,
+ QObject* pParent)
+ : QObject(pParent),
+ m_pSceneController(pSceneController),
+ m_pTimer(new QTimer(this)),
+ m_nLastPressureFrameIndex(0),
+ m_nStepsPerSecond(DefaultPlaybackSpeed),
+ m_bLoopEnabled(false),
+ m_bPlaying(false)
+{
+ Q_ASSERT(m_pSceneController != nullptr);
+ m_pTimer->setInterval(calculatePlaybackInterval());
+ connect(m_pTimer, SIGNAL(timeout()),
+ this, SLOT(onPlaybackTimeout()));
+}
+
+nmPebiResultPlaybackController::~nmPebiResultPlaybackController()
+{
+ stopTimerWithoutSignal();
+ m_pSceneController = nullptr;
+}
+
+void nmPebiResultPlaybackController::synchronizeFromScene()
+{
+ const QString sPreviousSnapshotId = m_sObservedSnapshotId;
+ const bool bAvailable = synchronizeSceneIdentity();
+ const bool bSnapshotChanged = bAvailable &&
+ sPreviousSnapshotId != m_sObservedSnapshotId;
+
+ // 无快照或新快照必须终止旧回放;同快照同步只校正 Scene 已提交状态。
+ if(!bAvailable || bSnapshotChanged) {
+ stopTimerWithoutSignal();
+ } else {
+ const QString sPropertyId = getCurrentPropertyId();
+ const int nFrameCount = getPropertyFrameCount(sPropertyId);
+ if(!isPropertyTimeDependent(sPropertyId) || nFrameCount <= 1) {
+ stopTimerWithoutSignal();
+ }
+
+ // 同一快照的显式同步以 Scene 的最后成功压力帧校正记忆值;
+ // 静态属性同步则保留此前压力帧,便于切回压力时恢复。
+ if(isPressureProperty(sPropertyId) &&
+ getCurrentFrameIndex() >= 0) {
+ m_nLastPressureFrameIndex = getCurrentFrameIndex();
+ }
+ }
+
+ emit stateChanged();
+}
+
+bool nmPebiResultPlaybackController::selectProperty(
+ const QString& sPropertyId)
+{
+ stopTimerWithoutSignal();
+ if(!synchronizeSceneIdentity() ||
+ !getAvailablePropertyIds().contains(sPropertyId)) {
+ return finishFailedOperation(playbackText(
+ "The selected result property is unavailable."));
+ }
+
+ const QString sPreviousPropertyId = getCurrentPropertyId();
+ int nCandidateLastPressureFrame = m_nLastPressureFrameIndex;
+ if(isPressureProperty(sPreviousPropertyId) &&
+ getCurrentFrameIndex() >= 0) {
+ // 切换前只保存局部候选;Scene 提交失败时不改变正式记忆值。
+ nCandidateLastPressureFrame = getCurrentFrameIndex();
+ }
+
+ int nTargetFrame = 0;
+ if(isPressureProperty(sPropertyId)) {
+ const int nFrameCount = getPropertyFrameCount(sPropertyId);
+ if(nFrameCount <= 0) {
+ return finishFailedOperation(playbackText(
+ "The selected result property is unavailable."));
+ }
+ nTargetFrame = qBound(
+ 0, nCandidateLastPressureFrame, nFrameCount - 1);
+ }
+
+ QString sError;
+ if(!m_pSceneController->applyPropertyFrame(
+ sPropertyId, nTargetFrame, &sError)) {
+ return finishFailedOperation(sError);
+ }
+
+ // 属性和帧均已由 Scene 原子提交,此时才提交最后压力帧候选。
+ if(isPressureProperty(sPropertyId)) {
+ m_nLastPressureFrameIndex = nTargetFrame;
+ } else if(isPressureProperty(sPreviousPropertyId)) {
+ m_nLastPressureFrameIndex = nCandidateLastPressureFrame;
+ }
+ emit stateChanged();
+ return true;
+}
+
+bool nmPebiResultPlaybackController::selectFrame(int nFrameIndex)
+{
+ stopTimerWithoutSignal();
+ if(!synchronizeSceneIdentity()) {
+ return finishFailedOperation(playbackText(
+ "Result playback is unavailable."));
+ }
+
+ const QString sPropertyId = getCurrentPropertyId();
+ const int nFrameCount = getPropertyFrameCount(sPropertyId);
+ if(!isPropertyTimeDependent(sPropertyId) ||
+ nFrameIndex < 0 || nFrameIndex >= nFrameCount) {
+ return finishFailedOperation(playbackText(
+ "The selected result frame is unavailable."));
+ }
+
+ QString sError;
+ if(!m_pSceneController->applyPropertyFrame(
+ sPropertyId, nFrameIndex, &sError)) {
+ return finishFailedOperation(sError);
+ }
+
+ if(isPressureProperty(sPropertyId)) {
+ m_nLastPressureFrameIndex = nFrameIndex;
+ }
+ emit stateChanged();
+ return true;
+}
+
+bool nmPebiResultPlaybackController::selectFirstFrame()
+{
+ return selectFrame(0);
+}
+
+bool nmPebiResultPlaybackController::selectPreviousFrame()
+{
+ return selectFrame(qMax(0, getCurrentFrameIndex() - 1));
+}
+
+bool nmPebiResultPlaybackController::selectNextFrame()
+{
+ const int nLastFrame = getCurrentPropertyFrameCount() - 1;
+ return selectFrame(qMin(nLastFrame, getCurrentFrameIndex() + 1));
+}
+
+bool nmPebiResultPlaybackController::selectLastFrame()
+{
+ return selectFrame(getCurrentPropertyFrameCount() - 1);
+}
+
+bool nmPebiResultPlaybackController::togglePlayback()
+{
+ if(m_bPlaying) {
+ pause();
+ return true;
+ }
+
+ if(!synchronizeSceneIdentity()) {
+ return finishFailedOperation(playbackText(
+ "Result playback is unavailable."));
+ }
+
+ const QString sPropertyId = getCurrentPropertyId();
+ const int nFrameCount = getPropertyFrameCount(sPropertyId);
+ if(!isPropertyTimeDependent(sPropertyId) || nFrameCount <= 1) {
+ return finishFailedOperation(playbackText(
+ "Result playback is unavailable."));
+ }
+
+ if(getCurrentFrameIndex() == nFrameCount - 1) {
+ QString sError;
+ if(!m_pSceneController->applyPropertyFrame(
+ sPropertyId, 0, &sError)) {
+ return finishFailedOperation(sError);
+ }
+ if(isPressureProperty(sPropertyId)) {
+ m_nLastPressureFrameIndex = 0;
+ }
+ }
+
+ m_pTimer->setInterval(calculatePlaybackInterval());
+ m_pTimer->start();
+ m_bPlaying = true;
+ emit stateChanged();
+ return true;
+}
+
+void nmPebiResultPlaybackController::pause()
+{
+ if(stopTimerWithoutSignal()) {
+ emit stateChanged();
+ }
+}
+
+bool nmPebiResultPlaybackController::setPlaybackSettings(
+ int nStepsPerSecond,
+ bool bLoopEnabled)
+{
+ if(nStepsPerSecond < MinimumPlaybackSpeed ||
+ nStepsPerSecond > MaximumPlaybackSpeed) {
+ // 公开接口不能依赖设置对话框兜底;非法参数也执行统一失败收尾。
+ return finishFailedOperation(playbackText(
+ "Playback speed must be between 1 and 60 steps per second."));
+ }
+ if(m_nStepsPerSecond == nStepsPerSecond &&
+ m_bLoopEnabled == bLoopEnabled) {
+ return true;
+ }
+
+ // 两个设置在完整校验后一次提交,避免速度失败但循环开关已改变。
+ m_nStepsPerSecond = nStepsPerSecond;
+ m_bLoopEnabled = bLoopEnabled;
+ if(m_pTimer->isActive()) {
+ m_pTimer->setInterval(calculatePlaybackInterval());
+ }
+ emit stateChanged();
+ return true;
+}
+
+bool nmPebiResultPlaybackController::isAvailable() const
+{
+ return m_pSceneController != nullptr &&
+ m_pSceneController->hasSnapshot();
+}
+
+QString nmPebiResultPlaybackController::getObservedSnapshotId() const
+{
+ return m_sObservedSnapshotId;
+}
+
+QStringList nmPebiResultPlaybackController::getAvailablePropertyIds() const
+{
+ return isAvailable()
+ ? m_pSceneController->getAvailablePropertyIds() : QStringList();
+}
+
+QString nmPebiResultPlaybackController::getCurrentPropertyId() const
+{
+ return isAvailable()
+ ? m_pSceneController->getCurrentPropertyId() : QString();
+}
+
+int nmPebiResultPlaybackController::getCurrentFrameIndex() const
+{
+ return isAvailable()
+ ? m_pSceneController->getCurrentFrameIndex() : -1;
+}
+
+bool nmPebiResultPlaybackController::isPropertyTimeDependent(
+ const QString& sPropertyId) const
+{
+ return isAvailable() &&
+ m_pSceneController->isPropertyTimeDependent(sPropertyId);
+}
+
+int nmPebiResultPlaybackController::getPropertyFrameCount(
+ const QString& sPropertyId) const
+{
+ return isAvailable()
+ ? m_pSceneController->getPropertyFrameCount(sPropertyId) : 0;
+}
+
+bool nmPebiResultPlaybackController::getPropertyTimeAt(
+ const QString& sPropertyId,
+ int nFrameIndex,
+ double& dTime) const
+{
+ return isAvailable() &&
+ m_pSceneController->getPropertyTimeAt(
+ sPropertyId, nFrameIndex, dTime);
+}
+
+bool nmPebiResultPlaybackController::isCurrentPropertyTimeDependent() const
+{
+ return isPropertyTimeDependent(getCurrentPropertyId());
+}
+
+int nmPebiResultPlaybackController::getCurrentPropertyFrameCount() const
+{
+ return getPropertyFrameCount(getCurrentPropertyId());
+}
+
+int nmPebiResultPlaybackController::getLastPressureFrameIndex() const
+{
+ return m_nLastPressureFrameIndex;
+}
+
+int nmPebiResultPlaybackController::getPlaybackSpeed() const
+{
+ return m_nStepsPerSecond;
+}
+
+int nmPebiResultPlaybackController::getPlaybackIntervalMilliseconds() const
+{
+ return calculatePlaybackInterval();
+}
+
+bool nmPebiResultPlaybackController::isLoopEnabled() const
+{
+ return m_bLoopEnabled;
+}
+
+bool nmPebiResultPlaybackController::isPlaying() const
+{
+ return m_bPlaying && m_pTimer != nullptr && m_pTimer->isActive();
+}
+
+void nmPebiResultPlaybackController::onPlaybackTimeout()
+{
+ const QString sPreviousSnapshotId = m_sObservedSnapshotId;
+ if(!synchronizeSceneIdentity()) {
+ stopTimerWithoutSignal();
+ emit stateChanged();
+ return;
+ }
+ if(sPreviousSnapshotId != m_sObservedSnapshotId) {
+ // 旧 Timer 已排队的回调不得推进刚提交的新快照。
+ stopTimerWithoutSignal();
+ emit stateChanged();
+ return;
+ }
+
+ const QString sPropertyId = getCurrentPropertyId();
+ const int nFrameCount = getPropertyFrameCount(sPropertyId);
+ const int nCurrentFrame = getCurrentFrameIndex();
+ if(!isPropertyTimeDependent(sPropertyId) || nFrameCount <= 1 ||
+ nCurrentFrame < 0 || nCurrentFrame >= nFrameCount) {
+ finishFailedOperation(playbackText(
+ "Result playback is unavailable."));
+ return;
+ }
+
+ int nTargetFrame = nCurrentFrame + 1;
+ if(nTargetFrame >= nFrameCount) {
+ if(!m_bLoopEnabled) {
+ stopTimerWithoutSignal();
+ emit stateChanged();
+ return;
+ }
+ nTargetFrame = 0;
+ }
+
+ QString sError;
+ if(!m_pSceneController->applyPropertyFrame(
+ sPropertyId, nTargetFrame, &sError)) {
+ finishFailedOperation(sError);
+ return;
+ }
+
+ if(isPressureProperty(sPropertyId)) {
+ m_nLastPressureFrameIndex = nTargetFrame;
+ }
+ if(!m_bLoopEnabled && nTargetFrame == nFrameCount - 1) {
+ // 末帧已经成功显示,立即切换为暂停图标并保留该帧。
+ stopTimerWithoutSignal();
+ }
+ emit stateChanged();
+}
+
+bool nmPebiResultPlaybackController::stopTimerWithoutSignal()
+{
+ const bool bWasPlaying = m_bPlaying ||
+ (m_pTimer != nullptr && m_pTimer->isActive());
+ if(m_pTimer != nullptr) {
+ m_pTimer->stop();
+ }
+ m_bPlaying = false;
+ return bWasPlaying;
+}
+
+bool nmPebiResultPlaybackController::synchronizeSceneIdentity()
+{
+ if(m_pSceneController == nullptr ||
+ !m_pSceneController->hasSnapshot()) {
+ stopTimerWithoutSignal();
+ m_sObservedSnapshotId.clear();
+ m_nLastPressureFrameIndex = 0;
+ return false;
+ }
+
+ const QString sSnapshotId =
+ m_pSceneController->getCurrentSnapshotId();
+ if(sSnapshotId.isEmpty()) {
+ stopTimerWithoutSignal();
+ m_sObservedSnapshotId.clear();
+ m_nLastPressureFrameIndex = 0;
+ return false;
+ }
+
+ if(m_sObservedSnapshotId != sSnapshotId) {
+ stopTimerWithoutSignal();
+ m_sObservedSnapshotId = sSnapshotId;
+ // 新快照由 SceneController 固定提交压力第 0 帧;无压力分支仍从 0 开始。
+ m_nLastPressureFrameIndex =
+ isPressureProperty(getCurrentPropertyId()) &&
+ getCurrentFrameIndex() >= 0
+ ? getCurrentFrameIndex() : 0;
+ }
+ return true;
+}
+
+bool nmPebiResultPlaybackController::finishFailedOperation(
+ const QString& sError)
+{
+ stopTimerWithoutSignal();
+ // Scene 极端回滚失败时可能已经自清空,此处先同步为不可用状态。
+ synchronizeSceneIdentity();
+ emit stateChanged();
+ emit operationFailed(sError.isEmpty()
+ ? playbackText("Result playback is unavailable.")
+ : sError);
+ return false;
+}
+
+int nmPebiResultPlaybackController::calculatePlaybackInterval() const
+{
+ return qMax(1, qRound(1000.0 /
+ static_cast(m_nStepsPerSecond)));
+}
diff --git a/Src/nmNum/nmSubWxs/nmPebiResultPropertyDisplayText.cpp b/Src/nmNum/nmSubWxs/nmPebiResultPropertyDisplayText.cpp
new file mode 100644
index 00000000..424f4af8
--- /dev/null
+++ b/Src/nmNum/nmSubWxs/nmPebiResultPropertyDisplayText.cpp
@@ -0,0 +1,44 @@
+#include "nmPebiResultPropertyDisplayText.h"
+
+#include "nmPebiResultPropertyCatalog.h"
+
+#include
+#include
+
+namespace {
+
+/* Qt 4.8 的 lupdate 无法追踪运行时 Catalog 字符串,必须显式登记。 */
+static const char* const s_pPropertyTranslationMarkers[] =
+{
+ QT_TRANSLATE_NOOP("nmPebiResultProperty", "Permeability"),
+ QT_TRANSLATE_NOOP("nmPebiResultProperty", "Porosity"),
+ QT_TRANSLATE_NOOP("nmPebiResultProperty", "Thickness"),
+ QT_TRANSLATE_NOOP("nmPebiResultProperty", "Pressure")
+};
+
+}
+
+QString nmPebiResultPropertyDisplayText::getDisplayName(
+ const QString& sPropertyId)
+{
+ Q_UNUSED(s_pPropertyTranslationMarkers);
+ nmPebiResultPropertyDescriptor oDescriptor;
+ if(!nmPebiResultPropertyCatalog::findDescriptor(
+ sPropertyId, oDescriptor)) {
+ return QString();
+ }
+
+ const QByteArray baSourceText =
+ oDescriptor.m_sDisplayNameSourceText.toLatin1();
+ return QCoreApplication::translate(
+ "nmPebiResultProperty", baSourceText.constData());
+}
+
+QString nmPebiResultPropertyDisplayText::getDefaultDisplayUnit(
+ const QString& sPropertyId)
+{
+ nmPebiResultPropertyDescriptor oDescriptor;
+ return nmPebiResultPropertyCatalog::findDescriptor(
+ sPropertyId, oDescriptor)
+ ? oDescriptor.m_sDefaultDisplayUnit : QString();
+}
diff --git a/Src/nmNum/nmSubWxs/nmPebiResultSceneController.cpp b/Src/nmNum/nmSubWxs/nmPebiResultSceneController.cpp
index b5168c43..84eefdd5 100644
--- a/Src/nmNum/nmSubWxs/nmPebiResultSceneController.cpp
+++ b/Src/nmNum/nmSubWxs/nmPebiResultSceneController.cpp
@@ -998,6 +998,39 @@ int nmPebiResultSceneController::getCurrentFrameIndex() const
? m_pPrivate->m_nCurrentFrameIndex : -1;
}
+bool nmPebiResultSceneController::isPropertyTimeDependent(
+ const QString& sPropertyId) const
+{
+ if(!hasSnapshot() ||
+ !m_pPrivate->m_pSnapshot->hasProperty(sPropertyId)) {
+ return false;
+ }
+
+ nmPebiResultPropertyDescriptor oDescriptor;
+ return nmPebiResultPropertyCatalog::findDescriptor(
+ sPropertyId, oDescriptor) &&
+ oDescriptor.m_eTimeType == NM_PebiResultProperty_Dynamic;
+}
+
+int nmPebiResultSceneController::getPropertyFrameCount(
+ const QString& sPropertyId) const
+{
+ return hasSnapshot()
+ ? m_pPrivate->m_pSnapshot->getPropertyFrameCount(sPropertyId)
+ : 0;
+}
+
+bool nmPebiResultSceneController::getPropertyTimeAt(
+ const QString& sPropertyId,
+ int nFrameIndex,
+ double& dTime) const
+{
+ // 快照接口保证失败时不写输出参数,这里直接保持该事务语义。
+ return hasSnapshot() &&
+ m_pPrivate->m_pSnapshot->getPropertyTimeAt(
+ sPropertyId, nFrameIndex, dTime);
+}
+
bool nmPebiResultSceneController::getCurrentPropertyRange(
double dRange[2]) const
{
diff --git a/Src/nmNum/nmSubWxs/nmWxPebiResultAnimationSettingsDlg.cpp b/Src/nmNum/nmSubWxs/nmWxPebiResultAnimationSettingsDlg.cpp
new file mode 100644
index 00000000..222ec490
--- /dev/null
+++ b/Src/nmNum/nmSubWxs/nmWxPebiResultAnimationSettingsDlg.cpp
@@ -0,0 +1,64 @@
+#include "nmWxPebiResultAnimationSettingsDlg.h"
+
+#include "nmPebiResultPlaybackController.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+nmWxPebiResultAnimationSettingsDlg::
+nmWxPebiResultAnimationSettingsDlg(
+ int nStepsPerSecond,
+ bool bLoopEnabled,
+ QWidget* pParent)
+ : QDialog(pParent),
+ m_pSpeedSpin(new QSpinBox(this)),
+ m_pLoopCheck(new QCheckBox(tr("Loop enabled"), this))
+{
+ setWindowTitle(tr("Animation settings"));
+ setModal(true);
+
+ m_pSpeedSpin->setRange(
+ nmPebiResultPlaybackController::MinimumPlaybackSpeed,
+ nmPebiResultPlaybackController::MaximumPlaybackSpeed);
+ m_pSpeedSpin->setValue(qBound(
+ static_cast(
+ nmPebiResultPlaybackController::MinimumPlaybackSpeed),
+ nStepsPerSecond,
+ static_cast(
+ nmPebiResultPlaybackController::MaximumPlaybackSpeed)));
+ m_pLoopCheck->setChecked(bLoopEnabled);
+
+ QFormLayout* pFormLayout = new QFormLayout();
+ pFormLayout->addRow(tr("Speed (steps/second)"), m_pSpeedSpin);
+ pFormLayout->addRow(QString(), m_pLoopCheck);
+
+ QDialogButtonBox* pButtonBox = new QDialogButtonBox(
+ QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
+ Qt::Horizontal, this);
+ connect(pButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(pButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
+
+ QVBoxLayout* pMainLayout = new QVBoxLayout(this);
+ pMainLayout->addLayout(pFormLayout);
+ pMainLayout->addWidget(pButtonBox);
+ setMinimumWidth(320);
+}
+
+nmWxPebiResultAnimationSettingsDlg::
+~nmWxPebiResultAnimationSettingsDlg()
+{
+}
+
+int nmWxPebiResultAnimationSettingsDlg::getPlaybackSpeed() const
+{
+ return m_pSpeedSpin->value();
+}
+
+bool nmWxPebiResultAnimationSettingsDlg::isLoopEnabled() const
+{
+ return m_pLoopCheck->isChecked();
+}
diff --git a/Src/nmNum/nmSubWxs/nmWxPebiResultControlBar.cpp b/Src/nmNum/nmSubWxs/nmWxPebiResultControlBar.cpp
new file mode 100644
index 00000000..cc4a0332
--- /dev/null
+++ b/Src/nmNum/nmSubWxs/nmWxPebiResultControlBar.cpp
@@ -0,0 +1,384 @@
+#include "nmWxPebiResultControlBar.h"
+
+#include "nmPebiResultPlaybackController.h"
+#include "nmPebiResultPropertyDisplayText.h"
+#include "nmPebiResultSceneController.h"
+#include "nmWxPebiResultAnimationSettingsDlg.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+namespace {
+
+QString resultControlIconPath(const QString& sFileName)
+{
+ const QString sApplicationDir = QCoreApplication::applicationDirPath();
+ return sApplicationDir.section('/', 0, -2) +
+ "/Res/Icon/" + sFileName;
+}
+
+QToolButton* createControlButton(QWidget* pParent,
+ const QString& sIconFile,
+ const QString& sToolTip)
+{
+ QToolButton* pButton = new QToolButton(pParent);
+ pButton->setAutoRaise(true);
+ pButton->setFixedSize(24, 24);
+ pButton->setIconSize(QSize(16, 16));
+ pButton->setIcon(QIcon(resultControlIconPath(sIconFile)));
+ pButton->setToolTip(sToolTip);
+ return pButton;
+}
+
+}
+
+nmWxPebiResultControlBar::nmWxPebiResultControlBar(
+ nmPebiResultSceneController* pSceneController,
+ QWidget* pParent)
+ : QWidget(pParent),
+ m_pPlaybackController(nullptr),
+ m_pPropertyCombo(nullptr),
+ m_pFirstButton(nullptr),
+ m_pPreviousButton(nullptr),
+ m_pTimeCombo(nullptr),
+ m_pNextButton(nullptr),
+ m_pLastButton(nullptr),
+ m_pPlayPauseButton(nullptr),
+ m_pSettingsButton(nullptr),
+ m_nDisplayedTimeFrameCount(-1)
+{
+ Q_ASSERT(pSceneController != nullptr);
+ createUi();
+ m_pPlaybackController = new nmPebiResultPlaybackController(
+ pSceneController, this);
+ connect(m_pPlaybackController, SIGNAL(stateChanged()),
+ this, SLOT(refreshFromController()));
+ connect(m_pPlaybackController, SIGNAL(operationFailed(QString)),
+ this, SLOT(forwardOperationFailure(QString)));
+ m_pPlaybackController->synchronizeFromScene();
+}
+
+nmWxPebiResultControlBar::~nmWxPebiResultControlBar()
+{
+ // QObject 随后删除子控制器;先停表可保证析构期间不再排入超时请求。
+ if(m_pPlaybackController != nullptr) {
+ m_pPlaybackController->blockSignals(true);
+ m_pPlaybackController->pause();
+ }
+}
+
+void nmWxPebiResultControlBar::stopPlayback()
+{
+ if(m_pPlaybackController != nullptr) {
+ m_pPlaybackController->pause();
+ }
+}
+
+void nmWxPebiResultControlBar::synchronizeFromScene()
+{
+ if(m_pPlaybackController != nullptr) {
+ m_pPlaybackController->synchronizeFromScene();
+ }
+}
+
+nmPebiResultPlaybackController*
+nmWxPebiResultControlBar::getPlaybackController() const
+{
+ return m_pPlaybackController;
+}
+
+void nmWxPebiResultControlBar::onPropertyIndexChanged(int nIndex)
+{
+ if(m_pPlaybackController == nullptr || nIndex < 0) {
+ return;
+ }
+ m_pPlaybackController->selectProperty(
+ m_pPropertyCombo->itemData(nIndex).toString());
+}
+
+void nmWxPebiResultControlBar::onTimeIndexChanged(int nIndex)
+{
+ if(m_pPlaybackController == nullptr || nIndex < 0) {
+ return;
+ }
+ m_pPlaybackController->selectFrame(
+ m_pTimeCombo->itemData(nIndex).toInt());
+}
+
+void nmWxPebiResultControlBar::onFirstFrameClicked()
+{
+ m_pPlaybackController->selectFirstFrame();
+}
+
+void nmWxPebiResultControlBar::onPreviousFrameClicked()
+{
+ m_pPlaybackController->selectPreviousFrame();
+}
+
+void nmWxPebiResultControlBar::onNextFrameClicked()
+{
+ m_pPlaybackController->selectNextFrame();
+}
+
+void nmWxPebiResultControlBar::onLastFrameClicked()
+{
+ m_pPlaybackController->selectLastFrame();
+}
+
+void nmWxPebiResultControlBar::onPlayPauseClicked()
+{
+ m_pPlaybackController->togglePlayback();
+}
+
+void nmWxPebiResultControlBar::onAnimationSettingsClicked()
+{
+ // 打开设置属于明确的手动操作;关闭对话框后不自动恢复播放。
+ m_pPlaybackController->pause();
+ nmWxPebiResultAnimationSettingsDlg oDialog(
+ m_pPlaybackController->getPlaybackSpeed(),
+ m_pPlaybackController->isLoopEnabled(), this);
+ if(oDialog.exec() == QDialog::Accepted) {
+ m_pPlaybackController->setPlaybackSettings(
+ oDialog.getPlaybackSpeed(),
+ oDialog.isLoopEnabled());
+ }
+}
+
+void nmWxPebiResultControlBar::refreshFromController()
+{
+ // 控件状态严格镜像四类 Scene 状态:无快照、静态、单帧动态、多帧动态。
+ const bool bAvailable = m_pPlaybackController != nullptr &&
+ m_pPlaybackController->isAvailable();
+ if(!bAvailable) {
+ const bool bPropertyBlocked = m_pPropertyCombo->blockSignals(true);
+ m_pPropertyCombo->clear();
+ m_pPropertyCombo->blockSignals(bPropertyBlocked);
+ clearTimeItems();
+ m_sDisplayedSnapshotId.clear();
+ m_listDisplayedPropertyIds.clear();
+ m_pPropertyCombo->setEnabled(false);
+ m_pFirstButton->setEnabled(false);
+ m_pPreviousButton->setEnabled(false);
+ m_pNextButton->setEnabled(false);
+ m_pLastButton->setEnabled(false);
+ m_pPlayPauseButton->setEnabled(false);
+ m_pSettingsButton->setEnabled(false);
+ m_pPlayPauseButton->setIcon(QIcon(resultControlIconPath(
+ QString::fromLatin1("Continue.png"))));
+ m_pPlayPauseButton->setToolTip(tr("Play"));
+ return;
+ }
+
+ const QString sSnapshotId =
+ m_pPlaybackController->getObservedSnapshotId();
+ const QStringList listPropertyIds =
+ m_pPlaybackController->getAvailablePropertyIds();
+ const bool bSnapshotChanged =
+ m_sDisplayedSnapshotId != sSnapshotId;
+ if(bSnapshotChanged ||
+ m_listDisplayedPropertyIds != listPropertyIds) {
+ rebuildPropertyItems(listPropertyIds);
+ m_sDisplayedSnapshotId = sSnapshotId;
+ m_listDisplayedPropertyIds = listPropertyIds;
+
+ // 即使属性和帧数相同,新快照的真实时间值也可能不同,不能复用旧列表。
+ if(bSnapshotChanged) {
+ m_sDisplayedTimePropertyId.clear();
+ m_nDisplayedTimeFrameCount = -1;
+ }
+ }
+
+ const QString sPropertyId =
+ m_pPlaybackController->getCurrentPropertyId();
+ const int nPropertyIndex = findItemByData(
+ m_pPropertyCombo, QVariant(sPropertyId));
+ const bool bPropertyBlocked = m_pPropertyCombo->blockSignals(true);
+ m_pPropertyCombo->setCurrentIndex(nPropertyIndex);
+ m_pPropertyCombo->blockSignals(bPropertyBlocked);
+ m_pPropertyCombo->setEnabled(true);
+
+ const bool bTimeDependent =
+ m_pPlaybackController->isPropertyTimeDependent(sPropertyId);
+ const int nFrameCount = bTimeDependent
+ ? m_pPlaybackController->getPropertyFrameCount(sPropertyId) : 0;
+ if(!bTimeDependent) {
+ clearTimeItems();
+ } else if(m_sDisplayedTimePropertyId != sPropertyId ||
+ m_nDisplayedTimeFrameCount != nFrameCount) {
+ rebuildTimeItems(sPropertyId, nFrameCount);
+ }
+
+ const int nCurrentFrame =
+ m_pPlaybackController->getCurrentFrameIndex();
+ if(bTimeDependent) {
+ const int nTimeIndex = findItemByData(
+ m_pTimeCombo, QVariant(nCurrentFrame));
+ const bool bTimeBlocked = m_pTimeCombo->blockSignals(true);
+ m_pTimeCombo->setCurrentIndex(nTimeIndex);
+ m_pTimeCombo->blockSignals(bTimeBlocked);
+ }
+
+ const bool bHasCompleteTimeList = bTimeDependent &&
+ nFrameCount > 0 && m_pTimeCombo->count() == nFrameCount;
+ const bool bHasTime = bHasCompleteTimeList;
+ const bool bHasMultipleFrames = bHasCompleteTimeList &&
+ nFrameCount > 1;
+ m_pTimeCombo->setEnabled(bHasTime);
+ m_pFirstButton->setEnabled(
+ bHasMultipleFrames && nCurrentFrame > 0);
+ m_pPreviousButton->setEnabled(
+ bHasMultipleFrames && nCurrentFrame > 0);
+ m_pNextButton->setEnabled(
+ bHasMultipleFrames && nCurrentFrame < nFrameCount - 1);
+ m_pLastButton->setEnabled(
+ bHasMultipleFrames && nCurrentFrame < nFrameCount - 1);
+ m_pPlayPauseButton->setEnabled(bHasMultipleFrames);
+ m_pSettingsButton->setEnabled(bHasMultipleFrames);
+
+ const bool bPlaying = m_pPlaybackController->isPlaying();
+ m_pPlayPauseButton->setIcon(QIcon(resultControlIconPath(
+ bPlaying ? QString::fromLatin1("Pause.png")
+ : QString::fromLatin1("Continue.png"))));
+ m_pPlayPauseButton->setToolTip(
+ bPlaying ? tr("Pause") : tr("Play"));
+}
+
+void nmWxPebiResultControlBar::forwardOperationFailure(
+ const QString& sError)
+{
+ emit operationFailed(sError);
+}
+
+void nmWxPebiResultControlBar::createUi()
+{
+ QHBoxLayout* pLayout = new QHBoxLayout(this);
+ pLayout->setContentsMargins(4, 3, 4, 3);
+ pLayout->setSpacing(4);
+
+ m_pPropertyCombo = new QComboBox(this);
+ m_pPropertyCombo->setMinimumWidth(140);
+ m_pPropertyCombo->setFixedHeight(24);
+ m_pPropertyCombo->setSizePolicy(
+ QSizePolicy::Preferred, QSizePolicy::Fixed);
+ m_pPropertyCombo->setToolTip(tr("Display property"));
+
+ m_pFirstButton = createControlButton(
+ this, QString::fromLatin1("First.png"), tr("First frame"));
+ m_pPreviousButton = createControlButton(
+ this, QString::fromLatin1("Prev.png"), tr("Previous frame"));
+ m_pTimeCombo = new QComboBox(this);
+ m_pTimeCombo->setMinimumWidth(150);
+ m_pTimeCombo->setFixedHeight(24);
+ m_pTimeCombo->setSizePolicy(
+ QSizePolicy::Expanding, QSizePolicy::Fixed);
+ m_pTimeCombo->setToolTip(tr("Result time"));
+ m_pNextButton = createControlButton(
+ this, QString::fromLatin1("Next.png"), tr("Next frame"));
+ m_pLastButton = createControlButton(
+ this, QString::fromLatin1("Last.png"), tr("Last frame"));
+ m_pPlayPauseButton = createControlButton(
+ this, QString::fromLatin1("Continue.png"), tr("Play"));
+ m_pSettingsButton = createControlButton(
+ this, QString::fromLatin1("SysTools.png"),
+ tr("Animation settings"));
+
+ pLayout->addWidget(m_pPropertyCombo);
+ pLayout->addWidget(m_pFirstButton);
+ pLayout->addWidget(m_pPreviousButton);
+ pLayout->addWidget(m_pTimeCombo, 1);
+ pLayout->addWidget(m_pNextButton);
+ pLayout->addWidget(m_pLastButton);
+ pLayout->addWidget(m_pPlayPauseButton);
+ pLayout->addWidget(m_pSettingsButton);
+
+ connect(m_pPropertyCombo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(onPropertyIndexChanged(int)));
+ connect(m_pTimeCombo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(onTimeIndexChanged(int)));
+ connect(m_pFirstButton, SIGNAL(clicked()),
+ this, SLOT(onFirstFrameClicked()));
+ connect(m_pPreviousButton, SIGNAL(clicked()),
+ this, SLOT(onPreviousFrameClicked()));
+ connect(m_pNextButton, SIGNAL(clicked()),
+ this, SLOT(onNextFrameClicked()));
+ connect(m_pLastButton, SIGNAL(clicked()),
+ this, SLOT(onLastFrameClicked()));
+ connect(m_pPlayPauseButton, SIGNAL(clicked()),
+ this, SLOT(onPlayPauseClicked()));
+ connect(m_pSettingsButton, SIGNAL(clicked()),
+ this, SLOT(onAnimationSettingsClicked()));
+}
+
+void nmWxPebiResultControlBar::rebuildPropertyItems(
+ const QStringList& listPropertyIds)
+{
+ const bool bBlocked = m_pPropertyCombo->blockSignals(true);
+ m_pPropertyCombo->clear();
+ for(int nIndex = 0; nIndex < listPropertyIds.size(); ++nIndex) {
+ const QString& sPropertyId = listPropertyIds[nIndex];
+ QString sDisplayName =
+ nmPebiResultPropertyDisplayText::getDisplayName(sPropertyId);
+ if(sDisplayName.isEmpty()) {
+ sDisplayName = sPropertyId;
+ }
+ m_pPropertyCombo->addItem(sDisplayName, sPropertyId);
+ }
+ m_pPropertyCombo->blockSignals(bBlocked);
+}
+
+void nmWxPebiResultControlBar::rebuildTimeItems(
+ const QString& sPropertyId,
+ int nFrameCount)
+{
+ const bool bBlocked = m_pTimeCombo->blockSignals(true);
+ m_pTimeCombo->clear();
+ bool bComplete = true;
+ for(int nFrameIndex = 0; nFrameIndex < nFrameCount; ++nFrameIndex) {
+ double dTimeHours = 0.0;
+ if(!m_pPlaybackController->getPropertyTimeAt(
+ sPropertyId, nFrameIndex, dTimeHours)) {
+ // 时间轴来自完整快照;防御性失败时不留下索引错位的半列表。
+ m_pTimeCombo->clear();
+ bComplete = false;
+ break;
+ }
+ m_pTimeCombo->addItem(
+ tr("t = %1 h").arg(
+ QString::number(dTimeHours, 'g', 8)),
+ nFrameIndex);
+ }
+ m_pTimeCombo->blockSignals(bBlocked);
+ m_sDisplayedTimePropertyId = bComplete ? sPropertyId : QString();
+ m_nDisplayedTimeFrameCount = bComplete ? nFrameCount : -1;
+}
+
+void nmWxPebiResultControlBar::clearTimeItems()
+{
+ const bool bBlocked = m_pTimeCombo->blockSignals(true);
+ m_pTimeCombo->clear();
+ m_pTimeCombo->blockSignals(bBlocked);
+ m_pTimeCombo->setEnabled(false);
+ m_sDisplayedTimePropertyId.clear();
+ m_nDisplayedTimeFrameCount = -1;
+}
+
+int nmWxPebiResultControlBar::findItemByData(
+ QComboBox* pComboBox,
+ const QVariant& oData) const
+{
+ if(pComboBox == nullptr) {
+ return -1;
+ }
+ for(int nIndex = 0; nIndex < pComboBox->count(); ++nIndex) {
+ if(pComboBox->itemData(nIndex) == oData) {
+ return nIndex;
+ }
+ }
+ return -1;
+}