diff --git a/Bin/Config/Lang/cn/nmNum_cn.qm b/Bin/Config/Lang/cn/nmNum_cn.qm index 619d2e75..fda58f0f 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 34e4bd06..c74a90d6 100644 --- a/Bin/Config/Lang/cn/nmNum_cn.ts +++ b/Bin/Config/Lang/cn/nmNum_cn.ts @@ -3245,6 +3245,9 @@ No valid error was returned; keep the last accepted result and reduce the step.< Logarithmic scale requires positive property and display ranges.对数色标要求属性范围和显示范围均为正值。 Unable to construct the color mapping.无法构造颜色映射。 Unable to apply the color settings.无法应用颜色设置。 + The filter settings no longer match the current result.筛选设置已不再对应当前结果。 + The filter settings are invalid.筛选设置无效。 + Unable to apply the filter settings.无法应用筛选设置。 Below min低于最小值 Above max高于最大值 @@ -3397,12 +3400,31 @@ No valid error was returned; keep the last accepted result and reduce the step.< Loop enabled启用循环 Speed (steps/second)速度(步/秒) + + nmWxPebiResultFilterSettingsDlg + Filtering settings筛选设置 + Enable filtering启用筛选 + Filter on筛选属性 + Above min (>=)下限 (>=) + Below max (<=)上限 (<=) + Apply应用 + OK确定 + Cancel取消 + Unable to read the current result filter settings.无法读取当前结果筛选设置。 + A filter property must be selected.必须选择筛选属性。 + Filter limits must be finite numbers.筛选上下限必须是有限数。 + Unable to convert the filter limits to the selected unit.无法将筛选上下限换算为所选单位。 + The minimum filter limit cannot exceed the maximum.筛选下限不能大于上限。 + Filtering is unavailable during playback or export.播放或导出期间无法设置筛选。 + Unable to apply the filter settings.无法应用筛选设置。 + nmWxPebiResultViewWidget No result data.暂无结果数据。 Color Scale色标 Scale Grid比例网格 Well Names井名 + Data Filtering...数据筛选... Unable to display the latest result.无法显示最新结果。 Unable to display the latest result: %1无法显示最新结果:%1 Current inputs have changed. Showing the last successful result.当前输入已修改,正在显示上一次成功求解的结果。 @@ -5253,7 +5275,7 @@ Supported types: Vertical, Vertical Fractured, and Horizontal Multi-Fractured We N/A - + 未知来源 Origin @@ -5494,6 +5516,26 @@ Please choose a smaller length. nmWxDFNLoadFromFile + + Column + 列 + + + Type + 字段类型 + + + Unit + 单位 + + + Column %1 + 第 %1 列 + + + UnDefined + 忽略 + Load from file... 从文件加载… @@ -5536,11 +5578,11 @@ Please choose a smaller length. Open Text File - 打开Text文件 + 打开文本文件 Text Files (*.txt);;All Files (*) - + 文本文件 (*.txt);;所有文件 (*) Error @@ -5552,11 +5594,11 @@ Please choose a smaller length. Open Excel File - 打开Excel文件 + 打开 Excel 文件 Excel Files (*.xls *.xlsx);;All Files (*) - + Excel 文件 (*.xls *.xlsx);;所有文件 (*) Please select an Excel file (.xls or .xlsx) @@ -5593,7 +5635,8 @@ Please choose a smaller length. Failed to import Excel : - 无法导入Excel文件: + 无法导入 Excel 文件: + diff --git a/Include/nmNum/nmData/nmPebiResultSnapshotRenderAdapter.h b/Include/nmNum/nmData/nmPebiResultSnapshotRenderAdapter.h index 19595ed2..352ac44a 100644 --- a/Include/nmNum/nmData/nmPebiResultSnapshotRenderAdapter.h +++ b/Include/nmNum/nmData/nmPebiResultSnapshotRenderAdapter.h @@ -59,6 +59,15 @@ public: /** @brief 事务式发布指定属性帧,失败时保持原画面和状态不变。 */ bool setPropertyFrame(const QString& sPropertyId, int nFrameIndex); + /** + * @brief 原子发布着色属性帧和可选筛选属性帧。 + * @param sFilterPropertyId 为空时移除筛选数组;非空时必须提供合法帧。 + * @note 同一属性不能同时绑定不同帧,避免同名 CellData 数组产生歧义。 + */ + bool setPropertyFrames(const QString& sDisplayPropertyId, + int nDisplayFrameIndex, + const QString& sFilterPropertyId, + int nFilterFrameIndex); /** @brief 将指定压力帧发布到当前 VTK 输出端口。 */ bool setPressureFrame(int nFrameIndex); /** @brief 返回供 Mapper 或过滤器建立连接的 VTK 输出端口。 */ @@ -69,6 +78,12 @@ public: QString getCurrentPropertyId() const; /** @brief 返回当前属性对应的稳定 VTK 数组名,尚未绑定时为空。 */ QString getCurrentScalarArrayName() const; + /** @brief 返回当前辅助筛选数组名;未绑定筛选属性时为空。 */ + QString getFilterScalarArrayName() const; + /** @brief 返回当前辅助筛选属性 ID;未绑定时为空。 */ + QString getFilterPropertyId() const; + /** @brief 返回当前辅助筛选帧;未绑定时为 -1。 */ + int getFilterFrameIndex() const; /** @brief 返回适配器渲染网格的单元数。 */ vtkIdType getCellCount() const; /** @brief 返回当前是否使用零整帧复制的共享压力模式。 */ @@ -89,10 +104,16 @@ private: QSharedPointer m_pSnapshot; /** @brief 适配器独占的渲染网格,结构可与快照基础网格共享。 */ vtkSmartPointer m_pRenderGrid; + /** @brief 共享模式中只用于预取候选数组,不接入下游渲染管线。 */ + vtkSmartPointer m_pBindingGrid; /** @brief 复制模式当前绑定到 CellData 的活动缓冲。 */ vtkSmartPointer m_pActiveBuffer; /** @brief 复制模式在切换成功前独立填充和校验的备用缓冲。 */ vtkSmartPointer m_pStandbyBuffer; + /** @brief 复制模式当前绑定的辅助筛选缓冲。 */ + vtkSmartPointer m_pFilterActiveBuffer; + /** @brief 复制模式用于事务准备的辅助筛选备用缓冲。 */ + vtkSmartPointer m_pFilterStandbyBuffer; /** @brief 将独立渲染网格接入 VTK 管道的生产者。 */ vtkSmartPointer m_pProducer; /** @brief 当前属性数组绑定方式。 */ @@ -101,6 +122,10 @@ private: QString m_sCurrentPropertyId; /** @brief 当前已经绑定的属性帧下标。 */ int m_nCurrentFrameIndex; + /** @brief 当前辅助筛选属性 ID;为空表示未绑定。 */ + QString m_sFilterPropertyId; + /** @brief 当前辅助筛选属性帧;未绑定时为 -1。 */ + int m_nFilterFrameIndex; }; #endif // NMPEBIRESULTSNAPSHOTRENDERADAPTER_H diff --git a/Include/nmNum/nmSubWxs/nmPebiResultAnimationExporter.h b/Include/nmNum/nmSubWxs/nmPebiResultAnimationExporter.h index 25f20ec1..86c55744 100644 --- a/Include/nmNum/nmSubWxs/nmPebiResultAnimationExporter.h +++ b/Include/nmNum/nmSubWxs/nmPebiResultAnimationExporter.h @@ -4,6 +4,7 @@ #include "nmSubWxs_global.h" #include "nmPebiResultAnimationExportSettings.h" #include "nmPebiResultDisplaySettings.h" +#include "nmPebiResultFilterSettings.h" #include "nmVTKMeshLayer.h" #include @@ -63,6 +64,10 @@ public: vtkSmartPointer m_pCamera; /** @brief 开始导出前冻结的网格显示模式。 */ nmVTKMeshLayer::DisplayMode m_eMeshDisplayMode; + /** @brief 开始导出前冻结的独立单元筛选条件。 */ + nmPebiResultFilterSettings m_oFilterSettings; + /** @brief 筛选属性不随导出属性变化时使用的冻结评估帧。 */ + int m_nFilterFrameIndex; }; /** @param pParent Qt父对象,不参与VTK资源所有权。 */ diff --git a/Include/nmNum/nmSubWxs/nmPebiResultPlaybackController.h b/Include/nmNum/nmSubWxs/nmPebiResultPlaybackController.h index 5214408e..b00cc4c3 100644 --- a/Include/nmNum/nmSubWxs/nmPebiResultPlaybackController.h +++ b/Include/nmNum/nmSubWxs/nmPebiResultPlaybackController.h @@ -15,7 +15,7 @@ class nmPebiResultSceneController; * @brief 管理结果属性选择、压力帧请求和回放定时器。 * * SceneController 是已渲染属性和帧的唯一真实来源。本控制器只保存播放状态、 - * 速度、循环偏好、最后压力帧和已观察的快照 ID,不持有任何 VTK 对象。 + * 速度、循环偏好和已观察的快照 ID,不持有任何 VTK 对象。 */ class NM_SUB_WXS_EXPORT nmPebiResultPlaybackController : public QObject { @@ -44,7 +44,7 @@ public: */ void synchronizeFromScene(); - /** @brief 暂停后选择属性;动态压力恢复最后一次成功帧,失败返回 false。 */ + /** @brief 暂停后选择属性;动态属性固定从第 0 帧开始。 */ bool selectProperty(const QString& sPropertyId); /** @brief 暂停后请求当前动态属性切换到指定零基帧,失败返回 false。 */ bool selectFrame(int nFrameIndex); @@ -91,8 +91,6 @@ public: bool isCurrentPropertyTimeDependent() const; /** @brief 返回 Scene 当前属性的帧数。 */ int getCurrentPropertyFrameCount() const; - /** @brief 返回同一快照内最后一次成功提交的压力帧记忆。 */ - int getLastPressureFrameIndex() const; /** @brief 返回当前窗口回放速度,单位为步/秒。 */ int getPlaybackSpeed() const; /** @brief 返回当前速度对应的整数毫秒间隔。 */ @@ -109,7 +107,7 @@ signals: void operationFailed(const QString& sError); private slots: - /** @brief 计算下一目标帧,Scene 成功提交后才更新压力帧记忆。 */ + /** @brief 计算下一目标帧并交给 Scene 原子提交。 */ void onPlaybackTimeout(); private: @@ -134,8 +132,6 @@ private: quint64 m_nObservedBindingRevision; /** @brief 当前活动 Timer 启动时捕获的 Scene 成功绑定序号。 */ quint64 m_nPlaybackBindingRevision; - /** @brief 同一快照内最后一次成功提交的 pressure 零基帧。 */ - int m_nLastPressureFrameIndex; /** @brief 当前窗口播放速度,单位为步/秒。 */ int m_nStepsPerSecond; /** @brief 末帧之后是否回到第 0 帧。 */ diff --git a/Include/nmNum/nmSubWxs/nmPebiResultSceneController.h b/Include/nmNum/nmSubWxs/nmPebiResultSceneController.h index c8324ddb..e6d449b4 100644 --- a/Include/nmNum/nmSubWxs/nmPebiResultSceneController.h +++ b/Include/nmNum/nmSubWxs/nmPebiResultSceneController.h @@ -3,6 +3,7 @@ #include "nmSubWxs_global.h" #include "nmPebiResultDisplaySettings.h" +#include "nmPebiResultFilterSettings.h" #include "nmVTKMeshLayer.h" #include @@ -72,6 +73,18 @@ public: const nmPebiResultDisplaySettings& oSettings, QString* pError = nullptr); + /** + * @brief 按对话框打开时的场景身份原子提交独立单元筛选条件。 + * @note 动态筛选属性与当前显示属性相同时跟随当前帧,否则冻结最近评估帧。 + */ + bool applyFilterSettings( + quint64 nExpectedBindingRevision, + const QString& sExpectedSnapshotId, + const QString& sExpectedDisplayPropertyId, + int nExpectedDisplayFrameIndex, + const nmPebiResultFilterSettings& oSettings, + QString* pError = nullptr); + /** @brief 设置本窗口网格显示模式;无有效快照时只保存偏好。 */ void setMeshDisplayMode(nmVTKMeshLayer::DisplayMode eMode); /** @brief 返回本窗口网格显示模式偏好。 */ @@ -117,6 +130,13 @@ public: /** @brief 返回当前属性最后一次成功提交的规范化显示设置。 */ bool getCurrentDisplaySettings( nmPebiResultDisplaySettings& oSettings) const; + /** @brief 返回当前快照指定属性的完整业务范围。 */ + bool getPropertyRange(const QString& sPropertyId, + double dRange[2]) const; + /** @brief 返回当前窗口已经提交的筛选条件。 */ + bool getFilterSettings(nmPebiResultFilterSettings& oSettings) const; + /** @brief 返回动态筛选最后一次实际评估帧;未启用时为 -1。 */ + int getFilterFrameIndex() const; /** @brief 返回色标显示偏好,不要求当前存在快照。 */ bool isScalarBarVisible() const; /** @brief 返回比例网格显示偏好,不要求当前存在快照。 */ diff --git a/Include/nmNum/nmSubWxs/nmWxPebiResultControlBar.h b/Include/nmNum/nmSubWxs/nmWxPebiResultControlBar.h index 5164aeeb..99d965e3 100644 --- a/Include/nmNum/nmSubWxs/nmWxPebiResultControlBar.h +++ b/Include/nmNum/nmSubWxs/nmWxPebiResultControlBar.h @@ -47,6 +47,8 @@ public: QAction* getExportAnimationAction() const; /** @brief 设置当前窗口的导出锁定状态并立即刷新全部控件。 */ void setExportInProgress(bool bInProgress); + /** @brief 返回同步动画导出是否正在占用结果控制条。 */ + bool isExportInProgress() const; signals: /** @brief 一次明确的用户操作已经成功提交,供组合窗口清除旧普通错误。 */ @@ -55,6 +57,8 @@ signals: void operationFailed(const QString& sError); /** @brief 用户从共用QAction请求导出当前动态属性。 */ void exportAnimationRequested(); + /** @brief 导出锁状态变化,供结果窗口同步其他业务动作。 */ + void exportInProgressChanged(bool bInProgress); private slots: /** @brief 用户选择显示模式时提交 itemData 中的 DisplayMode 枚举值。 */ diff --git a/Include/nmNum/nmSubWxs/nmWxPebiResultViewWidget.h b/Include/nmNum/nmSubWxs/nmWxPebiResultViewWidget.h index 1feeebb1..b69f3fdb 100644 --- a/Include/nmNum/nmSubWxs/nmWxPebiResultViewWidget.h +++ b/Include/nmNum/nmSubWxs/nmWxPebiResultViewWidget.h @@ -1,24 +1,98 @@ #ifndef NMWXPEBIRESULTVIEWWIDGET_H #define NMWXPEBIRESULTVIEWWIDGET_H +#include "iDlgBase.h" #include "nmSubWxs_global.h" +#include "nmPebiResultFilterSettings.h" +#include #include #include #include #include class QAction; +class QCheckBox; +class QComboBox; class QLabel; +class QLineEdit; class QMenu; +class QPushButton; class QToolBar; +class iUnitGroup; class nmDataAnalyzeManager; class nmPebiResultSceneController; class nmPebiResultSnapshot; class nmWxPebiResultControlBar; class nmWxVTKRenderContainerWidget; +/** @brief 编辑并原子提交当前结果窗口的独立单元筛选条件。 */ +class NM_SUB_WXS_EXPORT nmWxPebiResultFilterSettingsDlg : public iDlgBase +{ + Q_OBJECT + +public: + /** @param pSceneController 与 pControlBar 均为模态对话框期间有效的非所有权指针。 */ + explicit nmWxPebiResultFilterSettingsDlg( + nmPebiResultSceneController* pSceneController, + nmWxPebiResultControlBar* pControlBar, + QWidget* pParent = nullptr); + virtual ~nmWxPebiResultFilterSettingsDlg(); + +signals: + /** @brief Apply 或 OK 已成功提交筛选条件。 */ + void filterSettingsApplied(); + +private slots: + void onApplyClicked(); ///< 提交但保持对话框打开。 + void onOkClicked(); ///< 提交成功后关闭对话框。 + void onPropertyChanged(int nIndex); ///< 载入属性完整范围和单位。 + void onDisplayUnitChanged(int nIndex); ///< 换算上下限的临时显示单位。 + void refreshEditorEnabledState(); ///< 同步条件编辑控件可用性。 + +private: + Q_DISABLE_COPY(nmWxPebiResultFilterSettingsDlg) + + void createUi(); + bool initializeFromScene(); + bool initializeUnitEditor(const QString& sPropertyId); + bool populateSettings(const nmPebiResultFilterSettings& oSettings); + bool collectSettings(nmPebiResultFilterSettings& oSettings, + QString& sError) const; + bool applyEditor(); + bool setPropertyRange(const QString& sPropertyId); + QString formatValue(double dValue) const; + bool parseFiniteValue(const QString& sText, double& dValue) const; + bool convertUnitValue(double dSourceValue, + const QString& sSourceUnit, + const QString& sDestinationUnit, + double& dDestinationValue) const; + + nmPebiResultSceneController* m_pSceneController; ///< 非所有权 Scene 真源。 + nmWxPebiResultControlBar* m_pControlBar; ///< 非所有权播放和导出状态源。 + quint64 m_nExpectedBindingRevision; ///< 打开时的成功绑定序号。 + QString m_sExpectedSnapshotId; ///< 打开时的快照稳定 ID。 + QString m_sExpectedDisplayPropertyId; ///< 打开时的着色属性 ID。 + int m_nExpectedDisplayFrameIndex; ///< 打开时的着色帧。 + QMap > m_mapPropertyRanges; ///< 冻结范围。 + QString m_sBaseUnit; ///< 当前筛选属性的数据层基础单位。 + QString m_sDisplayUnit; ///< 当前对话框选择的临时显示单位。 + iUnitGroup* m_pUnitGroup; ///< 全局单位框架拥有,未找到时为空。 + nmPebiResultFilterSettings m_oBaselineSettings; ///< 最近成功 Apply 条件。 + bool m_bInitialized; ///< 是否完整取得初始 Scene 状态。 + + QCheckBox* m_pEnableCheck; + QComboBox* m_pPropertyCombo; + QCheckBox* m_pMinimumCheck; + QLineEdit* m_pMinimumEdit; + QCheckBox* m_pMaximumCheck; + QLineEdit* m_pMaximumEdit; + QComboBox* m_pUnitCombo; ///< 上下限共用的临时显示单位。 + QPushButton* m_pApplyButton; + QPushButton* m_pOkButton; +}; + /** * @brief 独立的 PEBI 结果场景组合窗口。 * @@ -66,6 +140,8 @@ private slots: void onViewportSizeChanged(int nWidth, int nHeight); /** @brief 冻结当前显示状态并执行独立离屏动画导出。 */ void onExportAnimationRequested(); + /** @brief 在播放和导出状态防御后打开数据筛选对话框。 */ + void onShowFilterSettings(); /** @brief 切换色标显隐。 */ void onScalarBarToggled(bool bVisible); @@ -73,6 +149,8 @@ private slots: void onScaleGridToggled(bool bVisible); /** @brief 切换二维井名显隐。 */ void onWellNamesToggled(bool bVisible); + /** @brief 从 Scene、播放和导出状态统一刷新业务动作。 */ + void synchronizeBusinessActions(); private: Q_DISABLE_COPY(nmWxPebiResultViewWidget) @@ -88,8 +166,6 @@ private: const QSharedPointer& pSnapshot, const QString& sSnapshotId, bool bCurrent); - /** @brief 从 SceneController 镜像三个业务 QAction 的勾选和可用状态。 */ - void synchronizeBusinessActions(); /** @brief 按绑定失败、操作错误的优先级刷新提示栏,无错误时隐藏。 */ void refreshStatusBar(); /** @brief 断开当前 Manager 的两个连接,不访问已经析构的对象。 */ @@ -105,6 +181,7 @@ private: QAction* m_pScalarBarAction; ///< 色标显隐动作。 QAction* m_pScaleGridAction; ///< 比例网格显隐动作。 QAction* m_pWellNamesAction; ///< 二维井名显隐动作。 + QAction* m_pFilterAction; ///< 打开数据筛选设置的共享动作。 /** @brief Manager 最近一次通知后观察到的快照强引用。 */ QSharedPointer m_pObservedSnapshot; diff --git a/Src/nmNum/nmData/nmPebiResultSnapshotRenderAdapter.cpp b/Src/nmNum/nmData/nmPebiResultSnapshotRenderAdapter.cpp index 006f883b..c44044a8 100644 --- a/Src/nmNum/nmData/nmPebiResultSnapshotRenderAdapter.cpp +++ b/Src/nmNum/nmData/nmPebiResultSnapshotRenderAdapter.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -51,11 +52,15 @@ bool isValidCopiedScalars(vtkDoubleArray* pScalars, nmPebiResultSnapshotRenderAdapter::nmPebiResultSnapshotRenderAdapter() : m_pRenderGrid(vtkSmartPointer::New()), + m_pBindingGrid(vtkSmartPointer::New()), m_pActiveBuffer(vtkSmartPointer::New()), m_pStandbyBuffer(vtkSmartPointer::New()), + m_pFilterActiveBuffer(vtkSmartPointer::New()), + m_pFilterStandbyBuffer(vtkSmartPointer::New()), m_pProducer(vtkSmartPointer::New()), m_eBindingMode(SharedPropertyArray), - m_nCurrentFrameIndex(-1) + m_nCurrentFrameIndex(-1), + m_nFilterFrameIndex(-1) { } @@ -83,6 +88,17 @@ bool nmPebiResultSnapshotRenderAdapter::initialize( clear(); return false; } + // 事务预取只需要共享点和单元拓扑;不重复深拷贝原始单元映射元数据。 + m_pBindingGrid->Initialize(); + m_pBindingGrid->CopyStructure(m_pRenderGrid); + m_pBindingGrid->GetCellData()->Initialize(); + m_pBindingGrid->GetFieldData()->Initialize(); + if(m_pBindingGrid->GetNumberOfCells() != + m_pRenderGrid->GetNumberOfCells()) + { + clear(); + return false; + } // TrivialProducer 只负责把适配器网格接入管道,不会主动修改输出对象。 m_pProducer->SetOutput(m_pRenderGrid); @@ -117,6 +133,11 @@ void nmPebiResultSnapshotRenderAdapter::clear() m_pRenderGrid->GetCellData()->Initialize(); m_pRenderGrid->Initialize(); } + if(m_pBindingGrid != NULL) + { + m_pBindingGrid->GetCellData()->Initialize(); + m_pBindingGrid->Initialize(); + } if(m_pActiveBuffer != NULL) { m_pActiveBuffer->Initialize(); @@ -125,63 +146,197 @@ void nmPebiResultSnapshotRenderAdapter::clear() { m_pStandbyBuffer->Initialize(); } + if(m_pFilterActiveBuffer != NULL) + { + m_pFilterActiveBuffer->Initialize(); + } + if(m_pFilterStandbyBuffer != NULL) + { + m_pFilterStandbyBuffer->Initialize(); + } m_pSnapshot.clear(); m_eBindingMode = SharedPropertyArray; m_sCurrentPropertyId.clear(); m_nCurrentFrameIndex = -1; + m_sFilterPropertyId.clear(); + m_nFilterFrameIndex = -1; } bool nmPebiResultSnapshotRenderAdapter::setPropertyFrame( const QString& sPropertyId, int nFrameIndex) { + return setPropertyFrames( + sPropertyId, nFrameIndex, QString(), -1); +} + +bool nmPebiResultSnapshotRenderAdapter::setPropertyFrames( + const QString& sDisplayPropertyId, + int nDisplayFrameIndex, + const QString& sFilterPropertyId, + int nFilterFrameIndex) +{ + const bool bHasFilter = !sFilterPropertyId.isEmpty(); if(m_pSnapshot.isNull() || m_pRenderGrid == NULL || - nFrameIndex < 0 || !m_pSnapshot->hasProperty(sPropertyId) || - nFrameIndex >= m_pSnapshot->getPropertyFrameCount(sPropertyId)) + m_pBindingGrid == NULL || nDisplayFrameIndex < 0 || + !m_pSnapshot->hasProperty(sDisplayPropertyId) || + nDisplayFrameIndex >= + m_pSnapshot->getPropertyFrameCount(sDisplayPropertyId) || + (bHasFilter && + (nFilterFrameIndex < 0 || + !m_pSnapshot->hasProperty(sFilterPropertyId) || + nFilterFrameIndex >= + m_pSnapshot->getPropertyFrameCount(sFilterPropertyId))) || + (bHasFilter && sDisplayPropertyId == sFilterPropertyId && + nDisplayFrameIndex != nFilterFrameIndex)) { return false; } + if(sDisplayPropertyId == m_sCurrentPropertyId && + nDisplayFrameIndex == m_nCurrentFrameIndex && + sFilterPropertyId == m_sFilterPropertyId && + (!bHasFilter || nFilterFrameIndex == m_nFilterFrameIndex)) + { + return true; + } + + const QString sDisplayArrayName = + sDisplayPropertyId == QString::fromLatin1("pressure") + ? QString::fromLatin1("p") : sDisplayPropertyId; + const QString sFilterArrayName = + sFilterPropertyId == QString::fromLatin1("pressure") + ? QString::fromLatin1("p") : sFilterPropertyId; + vtkSmartPointer pDisplayCandidate; + vtkSmartPointer pFilterCandidate; + const vtkIdType nCellCount = m_pSnapshot->getResultCellCount(); - bool bBound = false; if(m_eBindingMode == SharedPropertyArray) { - bBound = m_pSnapshot->bindPropertyFrame( - sPropertyId, nFrameIndex, m_pRenderGrid); + m_pBindingGrid->GetCellData()->Initialize(); + if(!m_pSnapshot->bindPropertyFrame( + sDisplayPropertyId, nDisplayFrameIndex, m_pBindingGrid)) + { + return false; + } + pDisplayCandidate = vtkDoubleArray::SafeDownCast( + m_pBindingGrid->GetCellData()->GetScalars()); + if(!isValidCopiedScalars( + pDisplayCandidate, nCellCount, sDisplayArrayName)) + { + m_pBindingGrid->GetCellData()->Initialize(); + return false; + } + if(bHasFilter && sFilterPropertyId != sDisplayPropertyId) + { + m_pBindingGrid->GetCellData()->Initialize(); + if(!m_pSnapshot->bindPropertyFrame( + sFilterPropertyId, nFilterFrameIndex, m_pBindingGrid)) + { + return false; + } + pFilterCandidate = vtkDoubleArray::SafeDownCast( + m_pBindingGrid->GetCellData()->GetScalars()); + if(!isValidCopiedScalars( + pFilterCandidate, nCellCount, sFilterArrayName)) + { + m_pBindingGrid->GetCellData()->Initialize(); + return false; + } + } + m_pBindingGrid->GetCellData()->Initialize(); } else { - // 活动缓冲在整个准备阶段保持不变;只有备用缓冲完整有效后才切换。 - bBound = m_pSnapshot->copyPropertyFrame( - sPropertyId, nFrameIndex, m_pStandbyBuffer) && - isValidCopiedScalars( - m_pStandbyBuffer, m_pSnapshot->getResultCellCount(), - sPropertyId == QString::fromLatin1("pressure") - ? QString::fromLatin1("p") : sPropertyId); - if(bBound) + if(!m_pSnapshot->copyPropertyFrame( + sDisplayPropertyId, nDisplayFrameIndex, m_pStandbyBuffer) || + !isValidCopiedScalars( + m_pStandbyBuffer, nCellCount, sDisplayArrayName)) { - vtkDataArray* pPreviousScalars = - m_pRenderGrid->GetCellData()->GetScalars(); - m_pRenderGrid->GetCellData()->SetScalars(m_pStandbyBuffer); - if(m_pRenderGrid->GetCellData()->GetScalars() != - m_pStandbyBuffer.GetPointer()) - { - m_pRenderGrid->GetCellData()->SetScalars(pPreviousScalars); - bBound = false; - } - else + return false; + } + pDisplayCandidate = m_pStandbyBuffer; + if(bHasFilter && sFilterPropertyId != sDisplayPropertyId) + { + if(!m_pSnapshot->copyPropertyFrame( + sFilterPropertyId, nFilterFrameIndex, + m_pFilterStandbyBuffer) || + !isValidCopiedScalars( + m_pFilterStandbyBuffer, nCellCount, sFilterArrayName)) { - qSwap(m_pActiveBuffer, m_pStandbyBuffer); - m_pRenderGrid->Modified(); + return false; } + pFilterCandidate = m_pFilterStandbyBuffer; } } + if(bHasFilter && sFilterPropertyId == sDisplayPropertyId) + { + pFilterCandidate = pDisplayCandidate; + } - if(!bBound) + vtkCellData* pCellData = m_pRenderGrid->GetCellData(); + vtkSmartPointer pPreviousDisplay = pCellData->GetScalars(); + vtkSmartPointer pPreviousFilter; + const QString sPreviousDisplayName = getCurrentScalarArrayName(); + const QString sPreviousFilterName = getFilterScalarArrayName(); + if(!sPreviousFilterName.isEmpty() && + sPreviousFilterName != sPreviousDisplayName) { + pPreviousFilter = pCellData->GetArray( + sPreviousFilterName.toLatin1().constData()); + } + + if(!sPreviousDisplayName.isEmpty()) + { + pCellData->RemoveArray(sPreviousDisplayName.toLatin1().constData()); + } + if(!sPreviousFilterName.isEmpty() && + sPreviousFilterName != sPreviousDisplayName) + { + pCellData->RemoveArray(sPreviousFilterName.toLatin1().constData()); + } + pCellData->SetScalars(pDisplayCandidate); + if(bHasFilter && sFilterArrayName != sDisplayArrayName) + { + pCellData->AddArray(pFilterCandidate); + } + + const bool bCommitted = pCellData->GetScalars() == + pDisplayCandidate.GetPointer() && + (!bHasFilter || sFilterArrayName == sDisplayArrayName || + pCellData->GetArray(sFilterArrayName.toLatin1().constData()) == + pFilterCandidate.GetPointer()); + if(!bCommitted) + { + pCellData->RemoveArray(sDisplayArrayName.toLatin1().constData()); + if(!sFilterArrayName.isEmpty() && + sFilterArrayName != sDisplayArrayName) + { + pCellData->RemoveArray(sFilterArrayName.toLatin1().constData()); + } + if(pPreviousDisplay != NULL) + { + pCellData->SetScalars(pPreviousDisplay); + } + if(pPreviousFilter != NULL) + { + pCellData->AddArray(pPreviousFilter); + } return false; } - m_sCurrentPropertyId = sPropertyId; - m_nCurrentFrameIndex = nFrameIndex; + + if(m_eBindingMode == CopiedPropertyArray) + { + qSwap(m_pActiveBuffer, m_pStandbyBuffer); + if(bHasFilter && sFilterPropertyId != sDisplayPropertyId) + { + qSwap(m_pFilterActiveBuffer, m_pFilterStandbyBuffer); + } + } + m_sCurrentPropertyId = sDisplayPropertyId; + m_nCurrentFrameIndex = nDisplayFrameIndex; + m_sFilterPropertyId = sFilterPropertyId; + m_nFilterFrameIndex = bHasFilter ? nFilterFrameIndex : -1; + m_pRenderGrid->Modified(); m_pProducer->Modified(); return true; } @@ -218,6 +373,26 @@ QString nmPebiResultSnapshotRenderAdapter::getCurrentScalarArrayName() const ? QString::fromLatin1("p") : m_sCurrentPropertyId; } +QString nmPebiResultSnapshotRenderAdapter::getFilterScalarArrayName() const +{ + if(m_sFilterPropertyId.isEmpty()) + { + return QString(); + } + return m_sFilterPropertyId == QString::fromLatin1("pressure") + ? QString::fromLatin1("p") : m_sFilterPropertyId; +} + +QString nmPebiResultSnapshotRenderAdapter::getFilterPropertyId() const +{ + return m_sFilterPropertyId; +} + +int nmPebiResultSnapshotRenderAdapter::getFilterFrameIndex() const +{ + return m_nFilterFrameIndex; +} + vtkIdType nmPebiResultSnapshotRenderAdapter::getCellCount() const { return m_pRenderGrid == NULL ? 0 : diff --git a/Src/nmNum/nmRender/nmVTKMeshLayer.cpp b/Src/nmNum/nmRender/nmVTKMeshLayer.cpp index 44d943cd..229ba1a9 100644 --- a/Src/nmNum/nmRender/nmVTKMeshLayer.cpp +++ b/Src/nmNum/nmRender/nmVTKMeshLayer.cpp @@ -519,6 +519,16 @@ vtkDataArray* nmVTKMeshLayer::validateScalarArray( if(pArray == nullptr) { return nullptr; } + const vtkIdType nAssociatedCount = + eAssociation == ScalarAssociation_CellData + ? pDataSet->GetNumberOfCells() + : pDataSet->GetNumberOfPoints(); + if(nAssociatedCount == 0 && pArray->GetNumberOfTuples() == 0) { + // vtkThreshold 合法地筛掉全部元素时仍保留零元组命名数组。 + dDataRange[0] = 0.0; + dDataRange[1] = 0.0; + return pArray; + } pArray->GetRange(dDataRange); return vtkMath::IsFinite(dDataRange[0]) && vtkMath::IsFinite(dDataRange[1]) && diff --git a/Src/nmNum/nmSubWxs/nmPebiResultAnimationExporter.cpp b/Src/nmNum/nmSubWxs/nmPebiResultAnimationExporter.cpp index 3b257928..bd6e94e3 100644 --- a/Src/nmNum/nmSubWxs/nmPebiResultAnimationExporter.cpp +++ b/Src/nmNum/nmSubWxs/nmPebiResultAnimationExporter.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #include #include @@ -86,6 +88,35 @@ bool getAdapterBounds(nmPebiResultSnapshotRenderAdapter& oAdapter, dBounds[4] <= dBounds[5]; } +bool isValidFilterRequest( + const nmPebiResultAnimationExporter::Request& oRequest) +{ + const nmPebiResultFilterSettings& oSettings = + oRequest.m_oFilterSettings; + if(!oSettings.m_bEnabled) { + return oRequest.m_nFilterFrameIndex == -1; + } + + nmPebiResultPropertyDescriptor oDescriptor; + const int nFilterFrameCount = oRequest.m_pSnapshot.isNull() + ? 0 : oRequest.m_pSnapshot->getPropertyFrameCount( + oSettings.m_sPropertyId); + return !oSettings.m_sPropertyId.isEmpty() && + !oRequest.m_pSnapshot.isNull() && + oRequest.m_pSnapshot->hasProperty(oSettings.m_sPropertyId) && + nmPebiResultPropertyCatalog::findDescriptor( + oSettings.m_sPropertyId, oDescriptor) && + oDescriptor.m_eAssociation == + NM_PebiResultPropertyAssociation_CellData && + oRequest.m_nFilterFrameIndex >= 0 && + oRequest.m_nFilterFrameIndex < nFilterFrameCount && + vtkMath::IsFinite(oSettings.m_dMinimum) && + vtkMath::IsFinite(oSettings.m_dMaximum) && + (!oSettings.m_bMinimumEnabled || + !oSettings.m_bMaximumEnabled || + oSettings.m_dMinimum <= oSettings.m_dMaximum); +} + QString createTemporaryPath(const QString& sTargetPath) { // 临时文件保留目标扩展名,Muxer才能按最终容器格式生成完整文件。 @@ -257,7 +288,8 @@ nmPebiResultAnimationExporter::Request::Request() m_bGradientBackground(false), m_pCamera(nullptr), m_eMeshDisplayMode( - nmVTKMeshLayer::DisplayMode_SurfaceWithEdges) + nmVTKMeshLayer::DisplayMode_SurfaceWithEdges), + m_nFilterFrameIndex(-1) { m_dBackground[0] = m_dBackground[1] = m_dBackground[2] = 0.0; m_dBackground2[0] = m_dBackground2[1] = m_dBackground2[2] = 0.0; @@ -296,6 +328,7 @@ nmPebiResultAnimationExporter::exportAnimation( NM_PebiResultPropertyAssociation_CellData || !nmVTKMeshLayer::isValidDisplayMode( oRequest.m_eMeshDisplayMode) || + !isValidFilterRequest(oRequest) || !oRequest.m_oExportSettings.isValid(nAvailableFrameCount) || oRequest.m_sTargetFilePath.isEmpty() || oRequest.m_pCamera == nullptr) { @@ -330,8 +363,15 @@ nmPebiResultAnimationExporter::exportAnimation( !oAdapter.initialize( oRequest.m_pSnapshot, nmPebiResultSnapshotRenderAdapter::CopiedPropertyArray) || - !oAdapter.setPropertyFrame( - oRequest.m_sPropertyId, vecFrameIndices.first())) { + !oAdapter.setPropertyFrames( + oRequest.m_sPropertyId, vecFrameIndices.first(), + oRequest.m_oFilterSettings.m_bEnabled + ? oRequest.m_oFilterSettings.m_sPropertyId : QString(), + oRequest.m_oFilterSettings.m_bEnabled && + oRequest.m_oFilterSettings.m_sPropertyId == + oRequest.m_sPropertyId + ? vecFrameIndices.first() + : oRequest.m_nFilterFrameIndex)) { if(pError != nullptr) { *pError = exporterText("Unable to prepare the animation result data."); } @@ -372,13 +412,33 @@ nmPebiResultAnimationExporter::exportAnimation( pRenderer->GetActiveCamera()->DeepCopy(oRequest.m_pCamera); nmVTKScene oScene(pRenderer); + vtkSmartPointer pThreshold; + vtkAlgorithmOutput* pMeshInput = oAdapter.getOutputPort(); + if(oRequest.m_oFilterSettings.m_bEnabled) { + const QString sFilterArrayName = + oAdapter.getFilterScalarArrayName(); + pThreshold = vtkSmartPointer::New(); + pThreshold->SetInputConnection(oAdapter.getOutputPort()); + pThreshold->SetInputArrayToProcess( + 0, 0, 0, + vtkDataObject::FIELD_ASSOCIATION_CELLS, + sFilterArrayName.toLatin1().constData()); + pThreshold->ThresholdBetween( + oRequest.m_oFilterSettings.m_bMinimumEnabled + ? oRequest.m_oFilterSettings.m_dMinimum + : -VTK_DOUBLE_MAX, + oRequest.m_oFilterSettings.m_bMaximumEnabled + ? oRequest.m_oFilterSettings.m_dMaximum + : VTK_DOUBLE_MAX); + pMeshInput = pThreshold->GetOutputPort(); + } nmVTKMeshLayer* pMeshLayer = new nmVTKMeshLayer( QString::fromLatin1(EXPORT_MESH_LAYER_ID)); pMeshLayer->setDisplayMode(oRequest.m_eMeshDisplayMode); pMeshLayer->getActor()->GetProperty()->SetEdgeColor(0.0, 0.0, 0.0); pMeshLayer->getActor()->GetProperty()->LightingOff(); if(!pMeshLayer->setInputConnection( - oAdapter.getOutputPort(), + pMeshInput, oAdapter.getCurrentScalarArrayName(), nmVTKMeshLayer::ScalarAssociation_CellData, oDisplayState.m_pLookupTable)) { @@ -493,8 +553,17 @@ nmPebiResultAnimationExporter::exportAnimation( for(int nOutputIndex = 0; nOutputIndex < vecFrameIndices.size(); ++nOutputIndex) { - if(!oAdapter.setPropertyFrame( - oRequest.m_sPropertyId, vecFrameIndices[nOutputIndex])) { + const int nDisplayFrameIndex = vecFrameIndices[nOutputIndex]; + const int nFilterFrameIndex = + oRequest.m_oFilterSettings.m_bEnabled && + oRequest.m_oFilterSettings.m_sPropertyId == + oRequest.m_sPropertyId + ? nDisplayFrameIndex : oRequest.m_nFilterFrameIndex; + if(!oAdapter.setPropertyFrames( + oRequest.m_sPropertyId, nDisplayFrameIndex, + oRequest.m_oFilterSettings.m_bEnabled + ? oRequest.m_oFilterSettings.m_sPropertyId : QString(), + nFilterFrameIndex)) { oWriter.cancel(); if(pError != nullptr) { *pError = exporterText("Unable to load an animation frame."); diff --git a/Src/nmNum/nmSubWxs/nmPebiResultPlaybackController.cpp b/Src/nmNum/nmSubWxs/nmPebiResultPlaybackController.cpp index 1be0e102..f6decd3c 100644 --- a/Src/nmNum/nmSubWxs/nmPebiResultPlaybackController.cpp +++ b/Src/nmNum/nmSubWxs/nmPebiResultPlaybackController.cpp @@ -8,8 +8,6 @@ namespace { -const char* const PRESSURE_PROPERTY_ID = "pressure"; - /* Qt 4.8 的 lupdate 无法从变量参数中推导翻译原文,必须显式登记。 */ static const char* const s_pPlaybackTranslationMarkers[] = { @@ -30,11 +28,6 @@ QString playbackText(const char* pText) "nmPebiResultPlaybackController", pText); } -bool isPressureProperty(const QString& sPropertyId) -{ - return sPropertyId == QString::fromLatin1(PRESSURE_PROPERTY_ID); -} - } nmPebiResultPlaybackController::nmPebiResultPlaybackController( @@ -45,7 +38,6 @@ nmPebiResultPlaybackController::nmPebiResultPlaybackController( m_pTimer(new QTimer(this)), m_nObservedBindingRevision(0), m_nPlaybackBindingRevision(0), - m_nLastPressureFrameIndex(0), m_nStepsPerSecond(DefaultPlaybackSpeed), m_bLoopEnabled(false), m_bPlaying(false) @@ -80,12 +72,6 @@ void nmPebiResultPlaybackController::synchronizeFromScene() stopTimerWithoutSignal(); } - // 同一快照的显式同步以 Scene 的最后成功压力帧校正记忆值; - // 静态属性同步则保留此前压力帧,便于切回压力时恢复。 - if(isPressureProperty(sPropertyId) && - getCurrentFrameIndex() >= 0) { - m_nLastPressureFrameIndex = getCurrentFrameIndex(); - } } emit stateChanged(); @@ -101,37 +87,16 @@ bool nmPebiResultPlaybackController::selectProperty( "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); + if(getPropertyFrameCount(sPropertyId) <= 0) { + return finishFailedOperation(playbackText( + "The selected result property is unavailable.")); } QString sError; if(!m_pSceneController->applyPropertyFrame( - sPropertyId, nTargetFrame, &sError)) { + sPropertyId, 0, &sError)) { return finishFailedOperation(sError); } - - // 属性和帧均已由 Scene 原子提交,此时才提交最后压力帧候选。 - if(isPressureProperty(sPropertyId)) { - m_nLastPressureFrameIndex = nTargetFrame; - } else if(isPressureProperty(sPreviousPropertyId)) { - m_nLastPressureFrameIndex = nCandidateLastPressureFrame; - } emit stateChanged(); return true; } @@ -158,9 +123,6 @@ bool nmPebiResultPlaybackController::selectFrame(int nFrameIndex) return finishFailedOperation(sError); } - if(isPressureProperty(sPropertyId)) { - m_nLastPressureFrameIndex = nFrameIndex; - } emit stateChanged(); return true; } @@ -211,9 +173,6 @@ bool nmPebiResultPlaybackController::togglePlayback() sPropertyId, 0, &sError)) { return finishFailedOperation(sError); } - if(isPressureProperty(sPropertyId)) { - m_nLastPressureFrameIndex = 0; - } } const quint64 nBindingRevision = @@ -334,11 +293,6 @@ int nmPebiResultPlaybackController::getCurrentPropertyFrameCount() const return getPropertyFrameCount(getCurrentPropertyId()); } -int nmPebiResultPlaybackController::getLastPressureFrameIndex() const -{ - return m_nLastPressureFrameIndex; -} - int nmPebiResultPlaybackController::getPlaybackSpeed() const { return m_nStepsPerSecond; @@ -410,9 +364,6 @@ void nmPebiResultPlaybackController::onPlaybackTimeout() return; } - if(isPressureProperty(sPropertyId)) { - m_nLastPressureFrameIndex = nTargetFrame; - } if(!m_bLoopEnabled && nTargetFrame == nFrameCount - 1) { // 末帧已经成功显示,立即切换为暂停图标并保留该帧。 stopTimerWithoutSignal(); @@ -439,7 +390,6 @@ bool nmPebiResultPlaybackController::synchronizeSceneIdentity() stopTimerWithoutSignal(); m_sObservedSnapshotId.clear(); m_nObservedBindingRevision = 0; - m_nLastPressureFrameIndex = 0; return false; } @@ -451,7 +401,6 @@ bool nmPebiResultPlaybackController::synchronizeSceneIdentity() stopTimerWithoutSignal(); m_sObservedSnapshotId.clear(); m_nObservedBindingRevision = 0; - m_nLastPressureFrameIndex = 0; return false; } @@ -460,11 +409,6 @@ bool nmPebiResultPlaybackController::synchronizeSceneIdentity() stopTimerWithoutSignal(); m_sObservedSnapshotId = sSnapshotId; m_nObservedBindingRevision = nBindingRevision; - // 新快照由 SceneController 固定提交压力第 0 帧;无压力分支仍从 0 开始。 - m_nLastPressureFrameIndex = - isPressureProperty(getCurrentPropertyId()) && - getCurrentFrameIndex() >= 0 - ? getCurrentFrameIndex() : 0; } return true; } diff --git a/Src/nmNum/nmSubWxs/nmPebiResultSceneController.cpp b/Src/nmNum/nmSubWxs/nmPebiResultSceneController.cpp index bba5d943..d20e15c3 100644 --- a/Src/nmNum/nmSubWxs/nmPebiResultSceneController.cpp +++ b/Src/nmNum/nmSubWxs/nmPebiResultSceneController.cpp @@ -22,12 +22,15 @@ #include #include #include +#include #include #include #include #include #include #include +#include +#include namespace { @@ -70,7 +73,13 @@ static const char* const s_pResultSceneTranslationMarkers[] = QT_TRANSLATE_NOOP("nmPebiResultSceneController", "Unable to construct the color mapping."), QT_TRANSLATE_NOOP("nmPebiResultSceneController", - "Unable to apply the color settings.") + "Unable to apply the color settings."), + QT_TRANSLATE_NOOP("nmPebiResultSceneController", + "The filter settings no longer match the current result."), + QT_TRANSLATE_NOOP("nmPebiResultSceneController", + "The filter settings are invalid."), + QT_TRANSLATE_NOOP("nmPebiResultSceneController", + "Unable to apply the filter settings.") }; bool isResultSceneGuiThread() @@ -177,6 +186,34 @@ bool validateAdapterOutput( dActualRange[0] <= dActualRange[1]; } +bool validateFilterSettings( + const QSharedPointer& pSnapshot, + const nmPebiResultFilterSettings& oSettings) +{ + if(!vtkMath::IsFinite(oSettings.m_dMinimum) || + !vtkMath::IsFinite(oSettings.m_dMaximum) || + (oSettings.m_bMinimumEnabled && + oSettings.m_bMaximumEnabled && + oSettings.m_dMinimum > oSettings.m_dMaximum)) { + return false; + } + + if(!oSettings.m_bEnabled && oSettings.m_sPropertyId.isEmpty()) { + return true; + } + nmPebiResultPropertyDescriptor oDescriptor; + if(pSnapshot.isNull() || oSettings.m_sPropertyId.isEmpty() || + !pSnapshot->hasProperty(oSettings.m_sPropertyId) || + pSnapshot->getPropertyFrameCount(oSettings.m_sPropertyId) <= 0 || + !nmPebiResultPropertyCatalog::findDescriptor( + oSettings.m_sPropertyId, oDescriptor) || + oDescriptor.m_eAssociation != + NM_PebiResultPropertyAssociation_CellData) { + return false; + } + return true; +} + } class nmPebiResultSceneControllerPrivate @@ -190,9 +227,11 @@ public: m_pScaleGridLayer(nullptr), m_pWellLayer(nullptr), m_pAdapter(nullptr), + m_pThreshold(vtkSmartPointer::New()), m_eMeshDisplayMode( nmVTKMeshLayer::DisplayMode_SurfaceWithEdges), m_nCurrentFrameIndex(-1), + m_nFilterFrameIndex(-1), m_nSnapshotBindingRevision(0), m_nViewportWidth(0), m_nViewportHeight(0), @@ -482,17 +521,42 @@ public: } } - bool bindMeshAdapter(nmPebiResultSnapshotRenderAdapter* pAdapter, - vtkLookupTable* pLookupTable) + bool bindMeshAdapter( + nmPebiResultSnapshotRenderAdapter* pAdapter, + vtkLookupTable* pLookupTable, + const nmPebiResultFilterSettings& oFilterSettings) { if(m_pMeshLayer == nullptr || pAdapter == nullptr || - pLookupTable == nullptr) { + pLookupTable == nullptr || m_pThreshold == nullptr) { return false; } + vtkAlgorithmOutput* pMeshInput = pAdapter->getOutputPort(); + if(oFilterSettings.m_bEnabled) { + const QString sFilterArrayName = + pAdapter->getFilterScalarArrayName(); + if(sFilterArrayName.isEmpty()) { + return false; + } + const double dMinimum = oFilterSettings.m_bMinimumEnabled + ? oFilterSettings.m_dMinimum : -VTK_DOUBLE_MAX; + const double dMaximum = oFilterSettings.m_bMaximumEnabled + ? oFilterSettings.m_dMaximum : VTK_DOUBLE_MAX; + m_pThreshold->SetInputConnection(pAdapter->getOutputPort()); + m_pThreshold->SetInputArrayToProcess( + 0, 0, 0, + vtkDataObject::FIELD_ASSOCIATION_CELLS, + sFilterArrayName.toLatin1().constData()); + m_pThreshold->ThresholdBetween(dMinimum, dMaximum); + m_pThreshold->Modified(); + pMeshInput = m_pThreshold->GetOutputPort(); + } else { + m_pThreshold->SetInputConnection(nullptr); + } + // MeshLayer 在触碰旧 Mapper 前完成全部校验,失败不会破坏旧画面。 if(!m_pMeshLayer->setInputConnection( - pAdapter->getOutputPort(), + pMeshInput, pAdapter->getCurrentScalarArrayName(), nmVTKMeshLayer::ScalarAssociation_CellData, pLookupTable)) { @@ -585,7 +649,9 @@ public: } const bool bMeshRestored = m_pMeshLayer->getLookupTable() != nullptr && - bindMeshAdapter(m_pAdapter, m_pMeshLayer->getLookupTable()); + bindMeshAdapter( + m_pAdapter, m_pMeshLayer->getLookupTable(), + m_oFilterSettings); bool bGridRestored = !m_bHasBounds; bool bBoundsRestored = !m_bHasBounds; if(m_bHasBounds && m_pScaleGridLayer != nullptr) { @@ -637,6 +703,8 @@ public: m_listAvailablePropertyIds.clear(); m_sCurrentPropertyId.clear(); m_nCurrentFrameIndex = -1; + m_oFilterSettings = nmPebiResultFilterSettings(); + m_nFilterFrameIndex = -1; m_bHasPropertyRange = false; m_bHasBounds = false; // clear()保留窗口样式,但任何活动快照相关的手工范围都必须失效。 @@ -697,6 +765,7 @@ public: nmVTKPlanarScaleGridLayer* m_pScaleGridLayer; ///< Scene 所有。 nmPebiResultWellAnnotationLayer* m_pWellLayer; ///< Scene 所有。 nmPebiResultSnapshotRenderAdapter* m_pAdapter; ///< 控制器独占。 + vtkSmartPointer m_pThreshold; ///< 筛选启用时的单元阈值管线。 QSharedPointer m_pSnapshot; QStringList m_listAvailablePropertyIds; QString m_sCurrentPropertyId; @@ -706,6 +775,8 @@ public: nmPebiResultDisplayState m_oCurrentDisplayState; nmVTKMeshLayer::DisplayMode m_eMeshDisplayMode; ///< 本窗口显示偏好。 int m_nCurrentFrameIndex; + nmPebiResultFilterSettings m_oFilterSettings; ///< 当前快照的筛选条件。 + int m_nFilterFrameIndex; ///< 动态筛选最后一次实际评估帧。 /** @brief 不同快照对象完整提交成功后的单调序号,clear 和失败均不回退。 */ quint64 m_nSnapshotBindingRevision; int m_nViewportWidth; ///< 最近一次有效 QVTK 视口像素宽度。 @@ -900,7 +971,8 @@ bool nmPebiResultSceneController::setSnapshot( dBounds[3], dBounds[4]) && m_pPrivate->m_pContainer->setPrimaryViewBounds(dBounds) && m_pPrivate->bindMeshAdapter( - pCandidateAdapter, oDisplayCandidate.m_pLookupTable); + pCandidateAdapter, oDisplayCandidate.m_pLookupTable, + nmPebiResultFilterSettings()); if(!bCommitted) { m_pPrivate->m_pWellLayer->discardCandidate(); const bool bRestored = m_pPrivate->restorePreviousScene(); @@ -931,6 +1003,8 @@ bool nmPebiResultSceneController::setSnapshot( m_pPrivate->m_sCurrentPropertyId = sInitialProperty; m_pPrivate->m_mapDisplaySettings = mapCandidateSettings; m_pPrivate->m_nCurrentFrameIndex = 0; + m_pPrivate->m_oFilterSettings = nmPebiResultFilterSettings(); + m_pPrivate->m_nFilterFrameIndex = -1; m_pPrivate->m_dBusinessRange[0] = oDisplayCandidate.m_dBusinessRange[0]; m_pPrivate->m_dBusinessRange[1] = @@ -1056,8 +1130,20 @@ bool nmPebiResultSceneController::applyPropertyFrame( const QString sPreviousProperty = m_pPrivate->m_sCurrentPropertyId; const int nPreviousFrame = m_pPrivate->m_nCurrentFrameIndex; - bool bApplied = m_pPrivate->m_pAdapter->setPropertyFrame( - sPropertyId, nFrameIndex); + const int nPreviousFilterFrame = + m_pPrivate->m_nFilterFrameIndex; + int nCandidateFilterFrame = nPreviousFilterFrame; + QString sFilterPropertyId; + if(m_pPrivate->m_oFilterSettings.m_bEnabled) { + sFilterPropertyId = + m_pPrivate->m_oFilterSettings.m_sPropertyId; + if(sFilterPropertyId == sPropertyId) { + nCandidateFilterFrame = nFrameIndex; + } + } + bool bApplied = m_pPrivate->m_pAdapter->setPropertyFrames( + sPropertyId, nFrameIndex, + sFilterPropertyId, nCandidateFilterFrame); double dCurrentBounds[6]; if(bApplied) { bApplied = validateAdapterOutput( @@ -1071,8 +1157,12 @@ bool nmPebiResultSceneController::applyPropertyFrame( } if(!bApplied) { const bool bAdapterRestored = - m_pPrivate->m_pAdapter->setPropertyFrame( - sPreviousProperty, nPreviousFrame); + m_pPrivate->m_pAdapter->setPropertyFrames( + sPreviousProperty, nPreviousFrame, + m_pPrivate->m_oFilterSettings.m_bEnabled + ? m_pPrivate->m_oFilterSettings.m_sPropertyId + : QString(), + nPreviousFilterFrame); if(!bAdapterRestored) { // 极端恢复失败时清空逻辑和 VTK 状态,保证查询结果与实际画面一致。 m_pPrivate->releaseActiveData(); @@ -1086,6 +1176,9 @@ bool nmPebiResultSceneController::applyPropertyFrame( m_pPrivate->m_sCurrentPropertyId = sPropertyId; m_pPrivate->m_nCurrentFrameIndex = nFrameIndex; + m_pPrivate->m_nFilterFrameIndex = + m_pPrivate->m_oFilterSettings.m_bEnabled + ? nCandidateFilterFrame : -1; if(!bReuseDisplayState) { m_pPrivate->m_mapDisplaySettings.insert( sPropertyId, oDisplayCandidate.m_oSettings); @@ -1176,6 +1269,128 @@ bool nmPebiResultSceneController::applyCurrentDisplaySettings( return true; } +bool nmPebiResultSceneController::applyFilterSettings( + quint64 nExpectedBindingRevision, + const QString& sExpectedSnapshotId, + const QString& sExpectedDisplayPropertyId, + int nExpectedDisplayFrameIndex, + const nmPebiResultFilterSettings& oSettings, + QString* pError) +{ + Q_ASSERT(isResultSceneGuiThread()); + if(pError != nullptr) { + pError->clear(); + } + if(isResultSceneGuiThread() && m_pPrivate != nullptr) { + m_pPrivate->discardActiveDataIfLayersLost(); + } + + if(!isResultSceneGuiThread() || !hasSnapshot() || + nExpectedBindingRevision == 0 || + nExpectedBindingRevision != getSnapshotBindingRevision() || + sExpectedSnapshotId.isEmpty() || + sExpectedSnapshotId != getCurrentSnapshotId() || + sExpectedDisplayPropertyId.isEmpty() || + sExpectedDisplayPropertyId != getCurrentPropertyId() || + nExpectedDisplayFrameIndex != getCurrentFrameIndex()) { + if(pError != nullptr) { + *pError = controllerText( + "The filter settings no longer match the current result."); + } + return false; + } + if(!validateFilterSettings(m_pPrivate->m_pSnapshot, oSettings)) { + if(pError != nullptr) { + *pError = controllerText("The filter settings are invalid."); + } + return false; + } + if(oSettings == m_pPrivate->m_oFilterSettings) { + return true; + } + + // 筛选关闭时仍保存对话框选择,但不触碰 VTK 管线或重复渲染。 + if(!oSettings.m_bEnabled && + !m_pPrivate->m_oFilterSettings.m_bEnabled) { + m_pPrivate->m_oFilterSettings = oSettings; + m_pPrivate->m_nFilterFrameIndex = -1; + return true; + } + + int nCandidateFilterFrame = -1; + if(oSettings.m_bEnabled) { + nmPebiResultPropertyDescriptor oFilterDescriptor; + nmPebiResultPropertyCatalog::findDescriptor( + oSettings.m_sPropertyId, oFilterDescriptor); + if(oFilterDescriptor.m_eTimeType == + NM_PebiResultProperty_Static) { + nCandidateFilterFrame = 0; + } else if(oSettings.m_sPropertyId == + m_pPrivate->m_sCurrentPropertyId) { + nCandidateFilterFrame = m_pPrivate->m_nCurrentFrameIndex; + } else if(m_pPrivate->m_oFilterSettings.m_bEnabled && + m_pPrivate->m_oFilterSettings.m_sPropertyId == + oSettings.m_sPropertyId && + m_pPrivate->m_nFilterFrameIndex >= 0) { + // 在静态着色属性上编辑现有动态筛选时,继续使用冻结帧。 + nCandidateFilterFrame = m_pPrivate->m_nFilterFrameIndex; + } else { + nCandidateFilterFrame = 0; + } + } + + const nmPebiResultFilterSettings oPreviousSettings = + m_pPrivate->m_oFilterSettings; + const int nPreviousFilterFrame = + m_pPrivate->m_nFilterFrameIndex; + bool bApplied = m_pPrivate->m_pAdapter->setPropertyFrames( + m_pPrivate->m_sCurrentPropertyId, + m_pPrivate->m_nCurrentFrameIndex, + oSettings.m_bEnabled + ? oSettings.m_sPropertyId : QString(), + nCandidateFilterFrame); + double dCurrentBounds[6]; + if(bApplied) { + bApplied = validateAdapterOutput( + m_pPrivate->m_pAdapter, + m_pPrivate->m_pSnapshot->getResultCellCount(), + dCurrentBounds) && + m_pPrivate->m_pMeshLayer->getLookupTable() != nullptr && + m_pPrivate->bindMeshAdapter( + m_pPrivate->m_pAdapter, + m_pPrivate->m_pMeshLayer->getLookupTable(), + oSettings); + } + if(!bApplied) { + const bool bAdapterRestored = + m_pPrivate->m_pAdapter->setPropertyFrames( + m_pPrivate->m_sCurrentPropertyId, + m_pPrivate->m_nCurrentFrameIndex, + oPreviousSettings.m_bEnabled + ? oPreviousSettings.m_sPropertyId : QString(), + nPreviousFilterFrame); + const bool bPipelineRestored = bAdapterRestored && + m_pPrivate->m_pMeshLayer->getLookupTable() != nullptr && + m_pPrivate->bindMeshAdapter( + m_pPrivate->m_pAdapter, + m_pPrivate->m_pMeshLayer->getLookupTable(), + oPreviousSettings); + if(!bPipelineRestored) { + m_pPrivate->releaseActiveData(); + } + if(pError != nullptr) { + *pError = controllerText("Unable to apply the filter settings."); + } + return false; + } + + m_pPrivate->m_oFilterSettings = oSettings; + m_pPrivate->m_nFilterFrameIndex = oSettings.m_bEnabled + ? nCandidateFilterFrame : -1; + m_pPrivate->m_pContainer->renderView(); + return true; +} + void nmPebiResultSceneController::setMeshDisplayMode( nmVTKMeshLayer::DisplayMode eMode) { @@ -1369,6 +1584,31 @@ bool nmPebiResultSceneController::getCurrentDisplaySettings( return true; } +bool nmPebiResultSceneController::getPropertyRange( + const QString& sPropertyId, + double dRange[2]) const +{ + return hasSnapshot() && dRange != nullptr && + m_pPrivate->m_pSnapshot->getPropertyRange( + sPropertyId, dRange); +} + +bool nmPebiResultSceneController::getFilterSettings( + nmPebiResultFilterSettings& oSettings) const +{ + if(!hasSnapshot()) { + return false; + } + oSettings = m_pPrivate->m_oFilterSettings; + return true; +} + +int nmPebiResultSceneController::getFilterFrameIndex() const +{ + return hasSnapshot() && m_pPrivate->m_oFilterSettings.m_bEnabled + ? m_pPrivate->m_nFilterFrameIndex : -1; +} + bool nmPebiResultSceneController::isScalarBarVisible() const { return m_pPrivate != nullptr && m_pPrivate->m_bScalarBarVisible; diff --git a/Src/nmNum/nmSubWxs/nmWxPebiResultControlBar.cpp b/Src/nmNum/nmSubWxs/nmWxPebiResultControlBar.cpp index aae7fd53..ebba185a 100644 --- a/Src/nmNum/nmSubWxs/nmWxPebiResultControlBar.cpp +++ b/Src/nmNum/nmSubWxs/nmWxPebiResultControlBar.cpp @@ -126,6 +126,12 @@ void nmWxPebiResultControlBar::setExportInProgress(bool bInProgress) } m_bExportInProgress = bInProgress; refreshFromController(); + emit exportInProgressChanged(bInProgress); +} + +bool nmWxPebiResultControlBar::isExportInProgress() const +{ + return m_bExportInProgress; } void nmWxPebiResultControlBar::onDisplayModeIndexChanged(int nIndex) diff --git a/Src/nmNum/nmSubWxs/nmWxPebiResultViewWidget.cpp b/Src/nmNum/nmSubWxs/nmWxPebiResultViewWidget.cpp index 01b38ea1..467c10b0 100644 --- a/Src/nmNum/nmSubWxs/nmWxPebiResultViewWidget.cpp +++ b/Src/nmNum/nmSubWxs/nmWxPebiResultViewWidget.cpp @@ -1,10 +1,14 @@ #include "nmWxPebiResultViewWidget.h" +#include "iUnitGroup.h" +#include "iUnitHelper.h" #include "nmDataAnalyzeManager.h" #include "nmFFmpegVideoWriter.h" #include "nmPebiResultAnimationExporter.h" #include "nmPebiResultDisplaySettings.h" #include "nmPebiResultPlaybackController.h" +#include "nmPebiResultPropertyCatalog.h" +#include "nmPebiResultPropertyDisplayText.h" #include "nmPebiResultSceneController.h" #include "nmPebiResultSnapshot.h" #include "nmVTKMeshLayer.h" @@ -15,15 +19,21 @@ #include #include +#include +#include #include #include +#include #include #include #include +#include +#include #include #include #include #include +#include #include #include #include @@ -33,6 +43,12 @@ #include #include +#include + +#if !defined(_MSC_VER) +#include +#endif + namespace { QAtomicInt g_nPebiAnimationExportActive(0); @@ -61,6 +77,15 @@ void setActionCheckedWithoutSignal(QAction* pAction, bool bChecked) pAction->blockSignals(bBlocked); } +bool isFiniteFilterEditorValue(double dValue) +{ +#if defined(_MSC_VER) + return _finite(dValue) != 0; +#else + return std::isfinite(dValue); +#endif +} + class AnimationExportGuard { public: @@ -102,6 +127,524 @@ private: } +nmWxPebiResultFilterSettingsDlg::nmWxPebiResultFilterSettingsDlg( + nmPebiResultSceneController* pSceneController, + nmWxPebiResultControlBar* pControlBar, + QWidget* pParent) + : iDlgBase(pParent), + m_pSceneController(pSceneController), + m_pControlBar(pControlBar), + m_nExpectedBindingRevision(0), + m_nExpectedDisplayFrameIndex(-1), + m_pUnitGroup(nullptr), + m_bInitialized(false), + m_pEnableCheck(nullptr), + m_pPropertyCombo(nullptr), + m_pMinimumCheck(nullptr), + m_pMinimumEdit(nullptr), + m_pMaximumCheck(nullptr), + m_pMaximumEdit(nullptr), + m_pUnitCombo(nullptr), + m_pApplyButton(nullptr), + m_pOkButton(nullptr) +{ + createUi(); + m_bInitialized = initializeFromScene(); + if(!m_bInitialized) { + m_pApplyButton->setEnabled(false); + m_pOkButton->setEnabled(false); + QMessageBox::warning( + this, tr("Filtering settings"), + tr("Unable to read the current result filter settings.")); + } +} + +nmWxPebiResultFilterSettingsDlg::~nmWxPebiResultFilterSettingsDlg() +{ +} + +void nmWxPebiResultFilterSettingsDlg::createUi() +{ + setWindowTitle(tr("Filtering settings")); + setModal(true); + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); + + m_pEnableCheck = new QCheckBox(tr("Enable filtering"), this); + m_pPropertyCombo = new QComboBox(this); + m_pPropertyCombo->setSizeAdjustPolicy( + QComboBox::AdjustToContentsOnFirstShow); + m_pPropertyCombo->setMinimumWidth(220); + + m_pMinimumCheck = new QCheckBox(tr("Above min (>=)"), this); + m_pMinimumEdit = new QLineEdit(this); + m_pMinimumEdit->setAlignment(Qt::AlignRight); + m_pMaximumCheck = new QCheckBox(tr("Below max (<=)"), this); + m_pMaximumEdit = new QLineEdit(this); + m_pMaximumEdit->setAlignment(Qt::AlignRight); + m_pUnitCombo = new QComboBox(this); + m_pUnitCombo->setMinimumWidth(80); + m_pUnitCombo->setMaximumWidth(140); + m_pUnitCombo->hide(); + m_pMinimumEdit->setMinimumWidth(150); + m_pMaximumEdit->setMinimumWidth(150); + + QGridLayout* pFieldsLayout = new QGridLayout(); + pFieldsLayout->setContentsMargins(0, 0, 0, 0); + pFieldsLayout->setHorizontalSpacing(8); + pFieldsLayout->setVerticalSpacing(6); + pFieldsLayout->addWidget(m_pEnableCheck, 0, 0, 1, 3); + QLabel* pPropertyLabel = new QLabel(tr("Filter on"), this); + pPropertyLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); + pFieldsLayout->addWidget(pPropertyLabel, 1, 0); + pFieldsLayout->addWidget(m_pPropertyCombo, 1, 1, 1, 2); + pFieldsLayout->addWidget(m_pMinimumCheck, 2, 0); + pFieldsLayout->addWidget(m_pMinimumEdit, 2, 1); + pFieldsLayout->addWidget(m_pUnitCombo, 2, 2, 2, 1, + Qt::AlignVCenter); + pFieldsLayout->addWidget(m_pMaximumCheck, 3, 0); + pFieldsLayout->addWidget(m_pMaximumEdit, 3, 1); + pFieldsLayout->setColumnStretch(1, 1); + + // 普通布局不受平台按钮顺序策略影响,始终保持应用、确定、取消。 + QHBoxLayout* pButtonLayout = new QHBoxLayout(); + pButtonLayout->addStretch(); + m_pApplyButton = new QPushButton(tr("Apply"), this); + m_pOkButton = new QPushButton(tr("OK"), this); + QPushButton* pCancelButton = new QPushButton(tr("Cancel"), this); + const QSize oFooterIconSize(16, 16); + m_pOkButton->setIcon(QIcon(resultViewIconPath("OK.png"))); + pCancelButton->setIcon(QIcon(resultViewIconPath("Cancel.png"))); + m_pOkButton->setIconSize(oFooterIconSize); + pCancelButton->setIconSize(oFooterIconSize); + m_pApplyButton->setMinimumWidth(72); + m_pOkButton->setMinimumWidth(72); + pCancelButton->setMinimumWidth(72); + m_pApplyButton->setAutoDefault(false); + m_pOkButton->setDefault(true); + pCancelButton->setAutoDefault(false); + pButtonLayout->setContentsMargins(4, 2, 4, 5); + pButtonLayout->setSpacing(6); + pButtonLayout->addWidget(m_pApplyButton); + pButtonLayout->addWidget(m_pOkButton); + pButtonLayout->addWidget(pCancelButton); + + QVBoxLayout* pMainLayout = new QVBoxLayout(this); + pMainLayout->setContentsMargins(12, 10, 12, 0); + pMainLayout->setSpacing(8); + pMainLayout->addLayout(pFieldsLayout); + pMainLayout->addLayout(pButtonLayout); + setMinimumWidth(430); + + connect(m_pApplyButton, SIGNAL(clicked()), + this, SLOT(onApplyClicked())); + connect(m_pOkButton, SIGNAL(clicked()), + this, SLOT(onOkClicked())); + connect(pCancelButton, SIGNAL(clicked()), + this, SLOT(reject())); + connect(m_pPropertyCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(onPropertyChanged(int))); + connect(m_pUnitCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(onDisplayUnitChanged(int))); + connect(m_pEnableCheck, SIGNAL(toggled(bool)), + this, SLOT(refreshEditorEnabledState())); + connect(m_pMinimumCheck, SIGNAL(toggled(bool)), + this, SLOT(refreshEditorEnabledState())); + connect(m_pMaximumCheck, SIGNAL(toggled(bool)), + this, SLOT(refreshEditorEnabledState())); +} + +bool nmWxPebiResultFilterSettingsDlg::initializeFromScene() +{ + if(m_pSceneController == nullptr || m_pControlBar == nullptr || + !m_pSceneController->hasSnapshot()) { + return false; + } + m_nExpectedBindingRevision = + m_pSceneController->getSnapshotBindingRevision(); + m_sExpectedSnapshotId = m_pSceneController->getCurrentSnapshotId(); + m_sExpectedDisplayPropertyId = + m_pSceneController->getCurrentPropertyId(); + m_nExpectedDisplayFrameIndex = + m_pSceneController->getCurrentFrameIndex(); + if(m_nExpectedBindingRevision == 0 || + m_sExpectedSnapshotId.isEmpty() || + m_sExpectedDisplayPropertyId.isEmpty() || + m_nExpectedDisplayFrameIndex < 0 || + !m_pSceneController->getFilterSettings(m_oBaselineSettings)) { + return false; + } + + const bool bSignalsBlocked = m_pPropertyCombo->blockSignals(true); + const QStringList listPropertyIds = + m_pSceneController->getAvailablePropertyIds(); + for(int nIndex = 0; nIndex < listPropertyIds.size(); ++nIndex) { + const QString& sPropertyId = listPropertyIds[nIndex]; + double dRange[2] = { 0.0, 0.0 }; + if(!m_pSceneController->getPropertyRange(sPropertyId, dRange)) { + m_pPropertyCombo->blockSignals(bSignalsBlocked); + return false; + } + m_mapPropertyRanges.insert( + sPropertyId, qMakePair(dRange[0], dRange[1])); + QString sDisplayName = + nmPebiResultPropertyDisplayText::getDisplayName(sPropertyId); + if(sDisplayName.isEmpty()) { + sDisplayName = sPropertyId; + } + m_pPropertyCombo->addItem(sDisplayName, sPropertyId); + } + m_pPropertyCombo->blockSignals(bSignalsBlocked); + if(m_pPropertyCombo->count() <= 0) { + return false; + } + + if(m_oBaselineSettings.m_sPropertyId.isEmpty() || + !m_mapPropertyRanges.contains( + m_oBaselineSettings.m_sPropertyId)) { + m_oBaselineSettings.m_sPropertyId = + m_sExpectedDisplayPropertyId; + const QPair oRange = + m_mapPropertyRanges.value( + m_oBaselineSettings.m_sPropertyId); + m_oBaselineSettings.m_bMinimumEnabled = true; + m_oBaselineSettings.m_dMinimum = oRange.first; + m_oBaselineSettings.m_bMaximumEnabled = true; + m_oBaselineSettings.m_dMaximum = oRange.second; + } + return populateSettings(m_oBaselineSettings); +} + +bool nmWxPebiResultFilterSettingsDlg::initializeUnitEditor( + const QString& sPropertyId) +{ + nmPebiResultPropertyDescriptor oDescriptor; + if(!nmPebiResultPropertyCatalog::findDescriptor( + sPropertyId, oDescriptor)) { + return false; + } + + const bool bSignalsBlocked = m_pUnitCombo->blockSignals(true); + m_pUnitCombo->clear(); + m_pUnitGroup = nullptr; + m_sBaseUnit = oDescriptor.m_sBaseUnit; + m_sDisplayUnit = oDescriptor.m_sDefaultDisplayUnit.isEmpty() + ? m_sBaseUnit : oDescriptor.m_sDefaultDisplayUnit; + if(m_sBaseUnit.isEmpty()) { + m_sDisplayUnit.clear(); + m_pUnitCombo->setEnabled(false); + m_pUnitCombo->hide(); + m_pUnitCombo->blockSignals(bSignalsBlocked); + return true; + } + + m_pUnitGroup = iUnitHelper::getUnitGroupByUnit(m_sBaseUnit); + QStringList listUnits; + if(m_pUnitGroup != nullptr && + m_pUnitGroup->indexOf(m_sBaseUnit) >= 0) { + listUnits = m_pUnitGroup->getAllUnitNames(); + } + const bool bHasUnitGroup = !listUnits.isEmpty() && + listUnits.contains(m_sBaseUnit); + if(!bHasUnitGroup) { + m_pUnitGroup = nullptr; + listUnits.clear(); + listUnits.append(m_sBaseUnit); + m_sDisplayUnit = m_sBaseUnit; + } else if(!listUnits.contains(m_sDisplayUnit)) { + m_sDisplayUnit = m_sBaseUnit; + } + + m_pUnitCombo->addItems(listUnits); + m_pUnitCombo->setCurrentIndex( + m_pUnitCombo->findText(m_sDisplayUnit)); + m_pUnitCombo->setEnabled(bHasUnitGroup); + m_pUnitCombo->show(); + m_pUnitCombo->blockSignals(bSignalsBlocked); + return true; +} + +bool nmWxPebiResultFilterSettingsDlg::populateSettings( + const nmPebiResultFilterSettings& oSettings) +{ + const bool bPropertySignalsBlocked = + m_pPropertyCombo->blockSignals(true); + const int nPropertyIndex = m_pPropertyCombo->findData( + oSettings.m_sPropertyId); + if(nPropertyIndex < 0 || + !initializeUnitEditor(oSettings.m_sPropertyId)) { + m_pPropertyCombo->blockSignals(bPropertySignalsBlocked); + return false; + } + m_pPropertyCombo->setCurrentIndex(nPropertyIndex); + m_pPropertyCombo->blockSignals(bPropertySignalsBlocked); + + double dDisplayMinimum = 0.0; + double dDisplayMaximum = 0.0; + if(!convertUnitValue( + oSettings.m_dMinimum, m_sBaseUnit, + m_sDisplayUnit, dDisplayMinimum) || + !convertUnitValue( + oSettings.m_dMaximum, m_sBaseUnit, + m_sDisplayUnit, dDisplayMaximum)) { + return false; + } + m_pEnableCheck->setChecked(oSettings.m_bEnabled); + m_pMinimumCheck->setChecked(oSettings.m_bMinimumEnabled); + m_pMaximumCheck->setChecked(oSettings.m_bMaximumEnabled); + m_pMinimumEdit->setText(formatValue(dDisplayMinimum)); + m_pMaximumEdit->setText(formatValue(dDisplayMaximum)); + refreshEditorEnabledState(); + return true; +} + +void nmWxPebiResultFilterSettingsDlg::onApplyClicked() +{ + applyEditor(); +} + +void nmWxPebiResultFilterSettingsDlg::onOkClicked() +{ + if(applyEditor()) { + accept(); + } +} + +void nmWxPebiResultFilterSettingsDlg::onPropertyChanged(int nIndex) +{ + if(nIndex >= 0 && + !setPropertyRange( + m_pPropertyCombo->itemData(nIndex).toString())) { + QMessageBox::warning( + this, tr("Filtering settings"), + tr("Unable to convert the filter limits " + "to the selected unit.")); + } +} + +void nmWxPebiResultFilterSettingsDlg::onDisplayUnitChanged(int nIndex) +{ + if(nIndex < 0) { + return; + } + const QString sNewUnit = m_pUnitCombo->itemText(nIndex); + if(sNewUnit == m_sDisplayUnit) { + return; + } + + double dOldDisplayMinimum = 0.0; + double dOldDisplayMaximum = 0.0; + double dBaseMinimum = 0.0; + double dBaseMaximum = 0.0; + double dNewDisplayMinimum = 0.0; + double dNewDisplayMaximum = 0.0; + const bool bConverted = + parseFiniteValue( + m_pMinimumEdit->text(), dOldDisplayMinimum) && + parseFiniteValue( + m_pMaximumEdit->text(), dOldDisplayMaximum) && + convertUnitValue( + dOldDisplayMinimum, m_sDisplayUnit, + m_sBaseUnit, dBaseMinimum) && + convertUnitValue( + dOldDisplayMaximum, m_sDisplayUnit, + m_sBaseUnit, dBaseMaximum) && + convertUnitValue( + dBaseMinimum, m_sBaseUnit, + sNewUnit, dNewDisplayMinimum) && + convertUnitValue( + dBaseMaximum, m_sBaseUnit, + sNewUnit, dNewDisplayMaximum); + if(!bConverted) { + const bool bSignalsBlocked = m_pUnitCombo->blockSignals(true); + m_pUnitCombo->setCurrentIndex( + m_pUnitCombo->findText(m_sDisplayUnit)); + m_pUnitCombo->blockSignals(bSignalsBlocked); + QMessageBox::warning( + this, tr("Filtering settings"), + tr("Unable to convert the filter limits " + "to the selected unit.")); + return; + } + + m_sDisplayUnit = sNewUnit; + m_pMinimumEdit->setText(formatValue(dNewDisplayMinimum)); + m_pMaximumEdit->setText(formatValue(dNewDisplayMaximum)); +} + +void nmWxPebiResultFilterSettingsDlg::refreshEditorEnabledState() +{ + const bool bEnabled = m_pEnableCheck->isChecked(); + m_pPropertyCombo->setEnabled(bEnabled); + m_pMinimumCheck->setEnabled(bEnabled); + m_pMaximumCheck->setEnabled(bEnabled); + m_pMinimumEdit->setEnabled( + bEnabled && m_pMinimumCheck->isChecked()); + m_pMaximumEdit->setEnabled( + bEnabled && m_pMaximumCheck->isChecked()); + m_pUnitCombo->setEnabled( + bEnabled && m_pUnitGroup != nullptr); +} + +bool nmWxPebiResultFilterSettingsDlg::collectSettings( + nmPebiResultFilterSettings& oSettings, + QString& sError) const +{ + sError.clear(); + const int nPropertyIndex = m_pPropertyCombo->currentIndex(); + if(nPropertyIndex < 0) { + sError = tr("A filter property must be selected."); + return false; + } + oSettings.m_bEnabled = m_pEnableCheck->isChecked(); + oSettings.m_sPropertyId = + m_pPropertyCombo->itemData(nPropertyIndex).toString(); + oSettings.m_bMinimumEnabled = m_pMinimumCheck->isChecked(); + oSettings.m_bMaximumEnabled = m_pMaximumCheck->isChecked(); + // 复选框只控制边界是否参与筛选;未启用边界的编辑值仍需保留, + // 避免重新打开对话框时退回设置对象的默认 0。 + double dDisplayMinimum = 0.0; + double dDisplayMaximum = 0.0; + if(!parseFiniteValue( + m_pMinimumEdit->text(), dDisplayMinimum) || + !parseFiniteValue( + m_pMaximumEdit->text(), dDisplayMaximum)) { + sError = tr("Filter limits must be finite numbers."); + return false; + } + if(!convertUnitValue( + dDisplayMinimum, m_sDisplayUnit, + m_sBaseUnit, oSettings.m_dMinimum) || + !convertUnitValue( + dDisplayMaximum, m_sDisplayUnit, + m_sBaseUnit, oSettings.m_dMaximum)) { + sError = tr( + "Unable to convert the filter limits " + "to the selected unit."); + return false; + } + if(oSettings.m_bMinimumEnabled && + oSettings.m_bMaximumEnabled && + oSettings.m_dMinimum > oSettings.m_dMaximum) { + sError = tr("The minimum filter limit cannot exceed the maximum."); + return false; + } + return true; +} + +bool nmWxPebiResultFilterSettingsDlg::applyEditor() +{ + nmPebiResultPlaybackController* pPlaybackController = + m_pControlBar == nullptr ? nullptr : + m_pControlBar->getPlaybackController(); + if(!m_bInitialized || m_pSceneController == nullptr || + m_pControlBar == nullptr || pPlaybackController == nullptr || + pPlaybackController->isPlaying() || + m_pControlBar->isExportInProgress()) { + const QString sError = tr( + "Filtering is unavailable during playback or export."); + QMessageBox::warning(this, tr("Filtering settings"), sError); + return false; + } + + nmPebiResultFilterSettings oSettings; + QString sError; + if(!collectSettings(oSettings, sError) || + !m_pSceneController->applyFilterSettings( + m_nExpectedBindingRevision, + m_sExpectedSnapshotId, + m_sExpectedDisplayPropertyId, + m_nExpectedDisplayFrameIndex, + oSettings, &sError)) { + if(sError.isEmpty()) { + sError = tr("Unable to apply the filter settings."); + } + QMessageBox::warning(this, tr("Filtering settings"), sError); + return false; + } + + m_oBaselineSettings = oSettings; + emit filterSettingsApplied(); + return true; +} + +bool nmWxPebiResultFilterSettingsDlg::setPropertyRange( + const QString& sPropertyId) +{ + if(!m_mapPropertyRanges.contains(sPropertyId) || + !initializeUnitEditor(sPropertyId)) { + return false; + } + const QPair oRange = + m_mapPropertyRanges.value(sPropertyId); + double dDisplayMinimum = 0.0; + double dDisplayMaximum = 0.0; + if(!convertUnitValue( + oRange.first, m_sBaseUnit, + m_sDisplayUnit, dDisplayMinimum) || + !convertUnitValue( + oRange.second, m_sBaseUnit, + m_sDisplayUnit, dDisplayMaximum)) { + return false; + } + m_pMinimumCheck->setChecked(true); + m_pMaximumCheck->setChecked(true); + m_pMinimumEdit->setText(formatValue(dDisplayMinimum)); + m_pMaximumEdit->setText(formatValue(dDisplayMaximum)); + refreshEditorEnabledState(); + return true; +} + +QString nmWxPebiResultFilterSettingsDlg::formatValue(double dValue) const +{ + return QLocale::c().toString(dValue, 'g', 12); +} + +bool nmWxPebiResultFilterSettingsDlg::parseFiniteValue( + const QString& sText, + double& dValue) const +{ + bool bOk = false; + const double dCandidate = QLocale::c().toDouble( + sText.trimmed(), &bOk); + if(!bOk || !isFiniteFilterEditorValue(dCandidate)) { + return false; + } + dValue = dCandidate; + return true; +} + +bool nmWxPebiResultFilterSettingsDlg::convertUnitValue( + double dSourceValue, + const QString& sSourceUnit, + const QString& sDestinationUnit, + double& dDestinationValue) const +{ + if(!isFiniteFilterEditorValue(dSourceValue)) { + return false; + } + if(sSourceUnit == sDestinationUnit) { + dDestinationValue = dSourceValue; + return true; + } + if(sSourceUnit.isEmpty() || sDestinationUnit.isEmpty() || + m_pUnitGroup == nullptr || + m_pUnitGroup->indexOf(sSourceUnit) < 0 || + m_pUnitGroup->indexOf(sDestinationUnit) < 0) { + return false; + } + + int nDigit = 12; + double dCandidate = 0.0; + if(!m_pUnitGroup->convert( + sSourceUnit, dSourceValue, + sDestinationUnit, dCandidate, nDigit) || + !isFiniteFilterEditorValue(dCandidate)) { + return false; + } + dDestinationValue = dCandidate; + return true; +} + nmWxPebiResultViewWidget::nmWxPebiResultViewWidget( nmDataAnalyzeManager* pDataManager, QWidget* pParent) @@ -114,6 +657,7 @@ nmWxPebiResultViewWidget::nmWxPebiResultViewWidget( m_pScalarBarAction(nullptr), m_pScaleGridAction(nullptr), m_pWellNamesAction(nullptr), + m_pFilterAction(nullptr), m_bObservedSnapshotCurrent(false), m_bObservedStateValid(false), m_bSynchronizing(false), @@ -225,6 +769,8 @@ void nmWxPebiResultViewWidget::appendContextMenuActions(QMenu* pMenu) if(pMenu == nullptr) { return; } + pMenu->addAction(m_pFilterAction); + pMenu->addSeparator(); pMenu->addAction(m_pScalarBarAction); pMenu->addAction(m_pScaleGridAction); pMenu->addAction(m_pWellNamesAction); @@ -266,6 +812,27 @@ void nmWxPebiResultViewWidget::onViewportSizeChanged( } } +void nmWxPebiResultViewWidget::onShowFilterSettings() +{ + nmPebiResultPlaybackController* pPlaybackController = + m_pControlBar == nullptr ? nullptr : + m_pControlBar->getPlaybackController(); + if(m_pSceneController == nullptr || m_pControlBar == nullptr || + pPlaybackController == nullptr || + !m_pSceneController->hasSnapshot() || + pPlaybackController->isPlaying() || + m_pControlBar->isExportInProgress()) { + return; + } + + nmWxPebiResultFilterSettingsDlg oDialog( + m_pSceneController, m_pControlBar, this); + connect(&oDialog, SIGNAL(filterSettingsApplied()), + this, SLOT(onControlOperationSucceeded())); + oDialog.exec(); + synchronizeBusinessActions(); +} + void nmWxPebiResultViewWidget::onExportAnimationRequested() { nmPebiResultPlaybackController* pPlaybackController = @@ -302,11 +869,23 @@ void nmWxPebiResultViewWidget::onExportAnimationRequested() m_pSceneController->getCurrentPropertyId(); const nmVTKMeshLayer::DisplayMode eFrozenMeshDisplayMode = m_pSceneController->getMeshDisplayMode(); + nmPebiResultDisplaySettings oFrozenDisplaySettings; + nmPebiResultFilterSettings oFrozenFilterSettings; + if(!m_pSceneController->getCurrentDisplaySettings( + oFrozenDisplaySettings) || + !m_pSceneController->getFilterSettings( + oFrozenFilterSettings)) { + return; + } + const int nFrozenFilterFrameIndex = + m_pSceneController->getFilterFrameIndex(); const int nFrameCount = pFrozenSnapshot->getPropertyFrameCount( sFrozenPropertyId); if(nFrozenBindingRevision == 0 || sFrozenSnapshotId.isEmpty() || sFrozenPropertyId.isEmpty() || nFrameCount <= 1 || !nmVTKMeshLayer::isValidDisplayMode(eFrozenMeshDisplayMode) || + (oFrozenFilterSettings.m_bEnabled && + nFrozenFilterFrameIndex < 0) || !m_pSceneController->isPropertyTimeDependent(sFrozenPropertyId)) { return; } @@ -344,11 +923,23 @@ void nmWxPebiResultViewWidget::onExportAnimationRequested() tr("The displayed result changed before export started.")); return; } + nmPebiResultDisplaySettings oCurrentDisplaySettings; + nmPebiResultFilterSettings oCurrentFilterSettings; + if(!m_pSceneController->getCurrentDisplaySettings( + oCurrentDisplaySettings) || + oCurrentDisplaySettings != oFrozenDisplaySettings || + !m_pSceneController->getFilterSettings(oCurrentFilterSettings) || + oCurrentFilterSettings != oFrozenFilterSettings || + m_pSceneController->getFilterFrameIndex() != + nFrozenFilterFrameIndex) { + QMessageBox::warning( + this, tr("Export Animation"), + tr("The displayed result changed before export started.")); + return; + } - nmPebiResultDisplaySettings oDisplaySettings; vtkRenderer* pRenderer = m_pRenderContainer->getRenderer(); - if(!m_pSceneController->getCurrentDisplaySettings(oDisplaySettings) || - pRenderer == nullptr || pRenderer->GetActiveCamera() == nullptr) { + if(pRenderer == nullptr || pRenderer->GetActiveCamera() == nullptr) { QMessageBox::warning( this, tr("Export Animation"), tr("Unable to freeze the current result display.")); @@ -358,8 +949,10 @@ void nmWxPebiResultViewWidget::onExportAnimationRequested() nmPebiResultAnimationExporter::Request oRequest; oRequest.m_pSnapshot = pFrozenSnapshot; oRequest.m_sPropertyId = sFrozenPropertyId; - oRequest.m_oDisplaySettings = oDisplaySettings; + oRequest.m_oDisplaySettings = oFrozenDisplaySettings; oRequest.m_eMeshDisplayMode = eFrozenMeshDisplayMode; + oRequest.m_oFilterSettings = oFrozenFilterSettings; + oRequest.m_nFilterFrameIndex = nFrozenFilterFrameIndex; oRequest.m_oExportSettings = oSettingsDialog.getSettings(); oRequest.m_sTargetFilePath = oSettingsDialog.getTargetFilePath(); oRequest.m_bScalarBarVisible = @@ -487,6 +1080,10 @@ void nmWxPebiResultViewWidget::createUi() m_pWellNamesAction = new QAction( QIcon(resultViewIconPath("NmShowWellNames.png")), tr("Well Names"), this); + m_pFilterAction = new QAction( + QIcon(resultViewIconPath("NmFilter.png")), + tr("Data Filtering..."), this); + m_pFilterAction->setToolTip(m_pFilterAction->text()); QAction* const pBusinessActions[] = { m_pScalarBarAction, m_pScaleGridAction, m_pWellNamesAction @@ -523,6 +1120,7 @@ void nmWxPebiResultViewWidget::createUi() if(pFrontAction != nullptr) m_pToolBar->addAction(pFrontAction); if(pPickCenterAction != nullptr) m_pToolBar->addAction(pPickCenterAction); m_pToolBar->addSeparator(); + m_pToolBar->addAction(m_pFilterAction); for(int nIndex = 0; nIndex < 3; ++nIndex) { m_pToolBar->addAction(pBusinessActions[nIndex]); } @@ -536,6 +1134,8 @@ void nmWxPebiResultViewWidget::createUi() this, SLOT(onScaleGridToggled(bool))); connect(m_pWellNamesAction, SIGNAL(toggled(bool)), this, SLOT(onWellNamesToggled(bool))); + connect(m_pFilterAction, SIGNAL(triggered()), + this, SLOT(onShowFilterSettings())); connect(m_pRenderContainer, SIGNAL(contextMenuAboutToShow(QMenu*)), this, SLOT(appendContextMenuActions(QMenu*))); @@ -557,6 +1157,12 @@ void nmWxPebiResultViewWidget::createUi() this, SLOT(onControlOperationSucceeded())); connect(m_pControlBar, SIGNAL(exportAnimationRequested()), this, SLOT(onExportAnimationRequested())); + connect(m_pControlBar, SIGNAL(exportInProgressChanged(bool)), + this, SLOT(synchronizeBusinessActions())); + if(m_pControlBar->getPlaybackController() != nullptr) { + connect(m_pControlBar->getPlaybackController(), SIGNAL(stateChanged()), + this, SLOT(synchronizeBusinessActions())); + } pMainLayout->addWidget(m_pControlBar); synchronizeBusinessActions(); @@ -702,6 +1308,16 @@ void nmWxPebiResultViewWidget::synchronizeBusinessActions() m_pScalarBarAction->setEnabled(bEnabled); m_pScaleGridAction->setEnabled(bEnabled); m_pWellNamesAction->setEnabled(bEnabled); + nmPebiResultPlaybackController* pPlaybackController = + m_pControlBar == nullptr ? nullptr : + m_pControlBar->getPlaybackController(); + const bool bFilterEnabled = bEnabled && + pPlaybackController != nullptr && + !pPlaybackController->isPlaying() && + !m_pControlBar->isExportInProgress(); + if(m_pFilterAction != nullptr) { + m_pFilterAction->setEnabled(bFilterEnabled); + } } void nmWxPebiResultViewWidget::refreshStatusBar()