feat(nmNum): 完善 PEBI 结果显示与井位标注

- 新增四套固定色带及按属性保存的显示设置
- 支持线性与对数映射、手工范围和上下越界颜色
- 完善 Mesh 与 ScalarBar 的候选 LUT 原子提交
- 独立显示常量值及上下越界色块和说明文字
- 新增全部井的二维井位标记和井名图层
- 新增颜色设置对话框及控制条入口
- 保持属性、帧和显示设置切换时场景与相机稳定
- 更新中文翻译、qmake 配置
feature/nmNum-postprocessing-view-20260910
lh 2 months ago
parent 275f9c9c84
commit b088b31907

Binary file not shown.

@ -2814,6 +2814,15 @@ Reason: %1</source>
<message><source>The requested result property or frame is invalid.</source><translation>请求的结果属性或帧无效。</translation></message>
<message><source>The result property range is invalid.</source><translation>结果属性范围无效。</translation></message>
<message><source>Unable to apply the result property or frame.</source><translation>无法应用结果属性或帧。</translation></message>
<message><source>The color settings no longer match the current result.</source><translation>颜色设置已不再对应当前结果。</translation></message>
<message><source>The color settings are invalid.</source><translation>颜色设置无效。</translation></message>
<message><source>The selected color map is unavailable.</source><translation>所选色带不可用。</translation></message>
<message><source>The manual range must contain two finite increasing values.</source><translation>手工范围必须包含两个有限且递增的数值。</translation></message>
<message><source>Logarithmic scale requires positive property and display ranges.</source><translation>对数色标要求属性范围和显示范围均为正值。</translation></message>
<message><source>Unable to construct the color mapping.</source><translation>无法构造颜色映射。</translation></message>
<message><source>Unable to apply the color settings.</source><translation>无法应用颜色设置。</translation></message>
<message><source>Below min</source><translation>低于最小值</translation></message>
<message><source>Above max</source><translation>高于最大值</translation></message>
</context>
<context>
<name>nmPebiResultProperty</name>
@ -2832,6 +2841,7 @@ Reason: %1</source>
<context>
<name>nmWxPebiResultControlBar</name>
<message><source>Display property</source><translation>显示属性</translation></message>
<message><source>Color settings</source><translation>颜色设置</translation></message>
<message><source>First frame</source><translation>第一帧</translation></message>
<message><source>Previous frame</source><translation>上一帧</translation></message>
<message><source>Result time</source><translation>结果时间</translation></message>
@ -2842,6 +2852,31 @@ Reason: %1</source>
<message><source>Animation settings</source><translation>动画设置</translation></message>
<message><source>t = %1 h</source><translation>t = %1 h</translation></message>
</context>
<context>
<name>nmWxPebiResultColorScaleSettingsDlg</name>
<message><source>Rainbow</source><translation>彩虹</translation></message>
<message><source>Oil saturation</source><translation>油饱和度</translation></message>
<message><source>Gas saturation</source><translation>气饱和度</translation></message>
<message><source>Water saturation</source><translation>水饱和度</translation></message>
<message><source>The result color settings are unavailable.</source><translation>结果颜色设置不可用。</translation></message>
<message><source>Below minimum color</source><translation>低于最小值颜色</translation></message>
<message><source>Above maximum color</source><translation>高于最大值颜色</translation></message>
<message><source>Logarithmic scale requires a positive property range.</source><translation>对数色标要求属性范围为正值。</translation></message>
<message><source>Logarithmic scale requires a positive minimum.</source><translation>对数色标要求显示最小值为正值。</translation></message>
<message><source>Color settings for current property</source><translation>当前属性的颜色设置</translation></message>
<message><source>Restore property range</source><translation>恢复属性范围</translation></message>
<message><source>Logarithmic scale</source><translation>对数色标</translation></message>
<message><source>Below min</source><translation>低于最小值</translation></message>
<message><source>Above max</source><translation>高于最大值</translation></message>
<message><source>Color map</source><translation>色带</translation></message>
<message><source>Minimum</source><translation>最小值</translation></message>
<message><source>Maximum</source><translation>最大值</translation></message>
<message><source>Unit</source><translation>单位</translation></message>
<message><source>Dimensionless</source><translation>无量纲</translation></message>
<message><source>Minimum and maximum must be finite numbers.</source><translation>最小值和最大值必须是有限数。</translation></message>
<message><source>Minimum must be less than maximum.</source><translation>最小值必须小于最大值。</translation></message>
<message><source>Unable to read the committed color settings.</source><translation>无法读取已提交的颜色设置。</translation></message>
</context>
<context>
<name>nmWxPebiResultAnimationSettingsDlg</name>
<message><source>Animation settings</source><translation>动画设置</translation></message>

@ -0,0 +1,53 @@
#ifndef NMVTKCOLORMAPCATALOG_H
#define NMVTKCOLORMAPCATALOG_H
#include "nmRender_global.h"
#include <QColor>
#include <QPixmap>
#include <QSize>
#include <QString>
#include <QStringList>
#include <vtkSmartPointer.h>
class vtkLookupTable;
/**
* @brief 提供可复现的通用 VTK 色带目录。
*
* 稳定 ID 和 256 个颜色表项不包含 PEBI 属性语义,其他渲染视图也可以复用。
* 目录只负责颜色表本身;数值范围、线性/对数模式和越界颜色由调用方设置。
*/
class NM_RENDER_EXPORT nmVTKColorMapCatalog
{
public:
/** @brief 返回固定顺序的全部稳定色带 ID。 */
static QStringList getColorMapIds();
/** @brief 判断稳定 ID 是否属于本目录。 */
static bool contains(const QString& sColorMapId);
/**
* @brief 按归一化位置查询不透明颜色。
* @param dPosition 0 对应最小值颜色,1 对应最大值颜色。
* @note 查询失败时返回 false,且不修改 oColor。
*/
static bool getColor(const QString& sColorMapId,
double dPosition,
QColor& oColor);
/** @brief 生成界面下拉框或工具按钮使用的固定色带预览图。 */
static QPixmap createPreviewPixmap(const QString& sColorMapId,
const QSize& oSize);
/**
* @brief 创建包含 256 个固定 RGBA 表项的独立 LookupTable。
* @return 未知 ID 返回空智能指针;成功时 Alpha 始终为 1。
*/
static vtkSmartPointer<vtkLookupTable> createLookupTable(
const QString& sColorMapId);
private:
/** @brief 纯静态目录,不允许实例化。 */
nmVTKColorMapCatalog();
};
#endif // NMVTKCOLORMAPCATALOG_H

@ -61,6 +61,15 @@ public:
ScalarAssociation eAssociation,
double dMinimum,
double dMaximum);
/**
* @brief 原子提交管线输入、标量数组和完整候选颜色表。
* @note 候选 LookupTable 必须已包含范围、色带、比例和越界颜色;失败时
* 原输入、Mapper 和活动 LookupTable 均保持不变。
*/
bool setInputConnection(vtkAlgorithmOutput* pInputConnection,
const QString& sArrayName,
ScalarAssociation eAssociation,
vtkLookupTable* pCandidateLookupTable);
/** @brief 解除直接数据或管线连接,并清除当前标量选择。 */
void clearInput();
/** @brief 返回当前直接数据或管线输出数据集的非所有权指针。 */
@ -99,6 +108,13 @@ public:
ScalarAssociation eAssociation,
double dMinimum,
double dMaximum);
/**
* @brief 原子提交当前输入的标量数组和完整候选颜色表。
* @return 数组和候选颜色表全部有效时返回 true;失败不修改活动状态。
*/
bool setScalarArray(const QString& sArrayName,
ScalarAssociation eAssociation,
vtkLookupTable* pCandidateLookupTable);
/** @brief 返回当前选中的数组名称。 */
QString getScalarArrayName() const;
/** @brief 返回当前数组来自 CellData 还是 PointData。 */
@ -111,6 +127,12 @@ public:
/** @brief 返回当前范围是否由调用方显式指定。 */
bool isUsingExplicitScalarRange() const;
/**
* @brief 原子替换当前标量数组使用的完整颜色表。
* @note 成功后 Mapper 与外部 ScalarBar 可以共享同一对象;不主动 Render。
*/
bool setLookupTable(vtkLookupTable* pCandidateLookupTable);
/** 以下访问函数均返回图层持有对象的非所有权指针。 */
vtkDataSetMapper* getMapper() const;
vtkActor* getActor() const;
@ -129,11 +151,19 @@ private:
const QByteArray& aArrayName,
ScalarAssociation eAssociation,
double dDataRange[2]) const;
/** @brief 校验候选颜色表的表项、有限范围及 Log10 正下限。 */
bool validateLookupTable(vtkLookupTable* pLookupTable,
double dRange[2]) const;
/** @brief 提交已经完整验证的数组选择和范围;本函数内部没有失败分支。 */
void applyExplicitScalarState(const QByteArray& aArrayName,
ScalarAssociation eAssociation,
double dMinimum,
double dMaximum);
/** @brief 提交已验证的数组选择和候选颜色表;内部没有失败分支。 */
void applyLookupTableScalarState(const QByteArray& aArrayName,
ScalarAssociation eAssociation,
vtkLookupTable* pLookupTable,
const double dRange[2]);
/** @brief 对新输入重新应用已经验证的标量模式、名称和自动范围。 */
void applyRetainedScalarState(const double dScalarRange[2]);
/** @brief 从当前数据集解析已记录的数组选择。 */

@ -5,8 +5,12 @@
#include <vtkSmartPointer.h>
class vtkActor2D;
class vtkLookupTable;
class vtkPoints;
class vtkPropAssembly;
class vtkScalarBarActor;
class vtkTextActor;
/**
* @brief 通用色标图层。
@ -16,7 +20,7 @@ class vtkScalarBarActor;
class NM_RENDER_EXPORT nmVTKScalarBarLayer : public nmVTKRenderLayer
{
public:
/** @brief 创建空色标,并将二维 Actor 注册为本图层主 Prop。 */
/** @brief 创建空色标,并将色标及独立二维装饰加入稳定根 Assembly。 */
explicit nmVTKScalarBarLayer(const QString& sLayerId);
/** @brief 先解除 Renderer,再释放外部颜色表的共享引用。 */
virtual ~nmVTKScalarBarLayer();
@ -31,6 +35,28 @@ public:
/** @brief 返回调用方设置的标题。 */
QString getTitle() const;
/** @brief 设置普通刻度格式,例如 %.6g;空格式返回 false。 */
bool setLabelFormat(const QString& sFormat);
/** @brief 返回调用方最后设置的普通刻度格式。 */
QString getLabelFormat() const;
/** @brief 设置 0~64 个普通刻度;常量色标使用 0。 */
bool setNumberOfLabels(int nLabelCount);
/** @brief 返回当前普通刻度数量。 */
int getNumberOfLabels() const;
/** @brief 配置低于显示范围的独立二维色块和说明文字。 */
void setBelowRangeSwatch(bool bVisible, const QString& sText);
/** @brief 配置高于显示范围的独立二维色块和说明文字。 */
void setAboveRangeSwatch(bool bVisible, const QString& sText);
/**
* @brief 显示或隐藏常量属性的唯一业务值。
*
* 该文字由独立 vtkTextActor 绘制,不启用共享 LUT 的 IndexedLookup,
* 因而不会改变网格使用的连续颜色映射语义。
*/
void setConstantValueLabel(bool bVisible, const QString& sText);
/** @brief 设置归一化视口坐标中的左下角位置。 */
bool setPosition(double dX, double dY);
/** @brief 设置归一化视口坐标中的宽度和高度。 */
@ -42,9 +68,30 @@ public:
private:
Q_DISABLE_COPY(nmVTKScalarBarLayer)
/** @brief 根据当前色标位置和尺寸同步全部独立二维装饰的位置。 */
void updateOverlayLayout();
/** @brief 从活动 LookupTable 同步上下越界色块的实际颜色。 */
void updateRangeSwatchColors();
vtkSmartPointer<vtkLookupTable> m_pLookupTable; ///< 共享外部颜色表引用。
vtkSmartPointer<vtkScalarBarActor> m_pActor; ///< 图层独占的二维色标 Prop。
vtkSmartPointer<vtkPropAssembly> m_pRootAssembly; ///< Scene 挂载的稳定根 Prop。
vtkSmartPointer<vtkScalarBarActor> m_pActor; ///< 图层独占的二维色标 Actor。
vtkSmartPointer<vtkTextActor> m_pConstantValueActor; ///< 常量属性唯一值文字。
vtkSmartPointer<vtkPoints> m_pBelowRangeSwatchPoints; ///< 下越界色块四角坐标。
vtkSmartPointer<vtkActor2D> m_pBelowRangeSwatchActor; ///< 下越界独立色块。
vtkSmartPointer<vtkTextActor> m_pBelowRangeTextActor; ///< 下越界说明文字。
vtkSmartPointer<vtkPoints> m_pAboveRangeSwatchPoints; ///< 上越界色块四角坐标。
vtkSmartPointer<vtkActor2D> m_pAboveRangeSwatchActor; ///< 上越界独立色块。
vtkSmartPointer<vtkTextActor> m_pAboveRangeTextActor; ///< 上越界说明文字。
QString m_sTitle; ///< 保留无损 Qt 标题,避免从 VTK 窄字符串反向解析。
QString m_sLabelFormat; ///< 普通刻度的 printf 风格格式字符串。
QString m_sConstantValueText; ///< 保留常量值文字,避免从 VTK 反向解析。
QString m_sBelowRangeText; ///< 下越界说明文字状态。
QString m_sAboveRangeText; ///< 上越界说明文字状态。
double m_dPositionX; ///< 色标左下角的归一化视口 X 坐标。
double m_dPositionY; ///< 色标左下角的归一化视口 Y 坐标。
double m_dWidth; ///< 色标在归一化视口中的宽度。
double m_dHeight; ///< 色标在归一化视口中的高度。
};
#endif // NMVTKSCALARBARLAYER_H

@ -0,0 +1,51 @@
#ifndef NMPEBIRESULTDISPLAYSETTINGS_H
#define NMPEBIRESULTDISPLAYSETTINGS_H
#include "nmSubWxs_global.h"
#include <QColor>
#include <QString>
/** @brief PEBI 结果颜色比例模式。 */
enum NM_PEBI_COLOR_SCALE_MODE
{
NM_PebiColorScale_Linear = 0, ///< 线性颜色映射。
NM_PebiColorScale_Logarithmic ///< 以 10 为底的对数颜色映射。
};
/**
* @brief 一项结果属性的窗口级显示偏好纯值类型。
*
* 本类型不持有 VTK 或界面对象。业务范围和 Log 可用性依赖当前快照,统一由
* SceneController 校验;这里仅校验枚举、有限数和颜色对象的结构合法性。
*/
struct NM_SUB_WXS_EXPORT nmPebiResultDisplaySettings
{
/** @brief 初始化为 Rainbow、Linear、自动范围和关闭越界专用颜色。 */
nmPebiResultDisplaySettings();
/** @brief 返回枚举、数值和颜色是否具备可提交的基本结构。 */
bool isStructurallyValid() const;
/**
* @brief 返回规范化副本。
* @note 自动范围固定把手工值归零;越界颜色固定转换为不透明颜色。
*/
nmPebiResultDisplaySettings normalized() const;
bool operator==(const nmPebiResultDisplaySettings& oOther) const;
bool operator!=(const nmPebiResultDisplaySettings& oOther) const;
QString m_sColorMapId; ///< 通用色带目录中的稳定英文 ID。
NM_PEBI_COLOR_SCALE_MODE m_eScaleMode; ///< 线性或 Log10 映射。
bool m_bHasManualRange; ///< 为 true 时使用下方两个手工上下限。
double m_dManualMinimum; ///< 手工显示最小值;自动范围时规范为 0。
double m_dManualMaximum; ///< 手工显示最大值;自动范围时规范为 0。
bool m_bUseBelowRangeColor; ///< 是否显示低于范围值的专用颜色。
bool m_bUseAboveRangeColor; ///< 是否显示高于范围值的专用颜色。
QColor m_oBelowRangeColor; ///< 低于范围颜色,提交时强制 Alpha=255。
QColor m_oAboveRangeColor; ///< 高于范围颜色,提交时强制 Alpha=255。
};
#endif // NMPEBIRESULTDISPLAYSETTINGS_H

@ -2,6 +2,7 @@
#define NMPEBIRESULTSCENECONTROLLER_H
#include "nmSubWxs_global.h"
#include "nmPebiResultDisplaySettings.h"
#include <QSharedPointer>
#include <QString>
@ -14,7 +15,7 @@ class nmWxVTKRenderContainerWidget;
/**
* @brief 将不可变 PEBI 结果快照组合为独立的通用 VTK 场景。
*
* Scene 拥有 Mesh、ScalarBar 和平面比例网格图层;控制器独占活动
* Scene 拥有 Mesh、ScalarBar、平面比例网格和二维井标注图层;控制器独占活动
* RenderAdapter 和快照强引用,并通过稳定 ID 校验所观察的图层身份。
* 外部提前清空业务 Scene 时,控制器会丢弃活动结果而不会解引用旧图层。
*/
@ -49,14 +50,30 @@ public:
int nFrameIndex,
QString* pError = nullptr);
/**
* @brief 事务式提交当前属性的颜色、范围、比例和越界颜色设置。
* @param sExpectedSnapshotId 对话框打开时记录的快照 ID。
* @param sExpectedPropertyId 对话框打开时记录的属性 ID。
* @note 身份或设置校验失败时不修改场景且不 Render;相同设置直接成功。
*/
bool applyCurrentDisplaySettings(
const QString& sExpectedSnapshotId,
const QString& sExpectedPropertyId,
const nmPebiResultDisplaySettings& oSettings,
QString* pError = nullptr);
/** @brief 设置结果网格显隐;偏好跨快照保留。 */
void setMeshVisible(bool bVisible);
/** @brief 设置色标显隐;阶段 5A 默认隐藏,偏好跨快照保留。 */
/** @brief 设置色标显隐;默认显示,偏好跨快照保留。 */
void setScalarBarVisible(bool bVisible);
/** @brief 设置平面比例网格显隐;偏好跨快照保留。 */
void setScaleGridVisible(bool bVisible);
/** @brief 设置单元边线显隐;偏好跨快照保留。 */
void setCellEdgesVisible(bool bVisible);
/** @brief 设置二维井位标记显隐;偏好跨快照保留。 */
void setWellMarkersVisible(bool bVisible);
/** @brief 设置二维井名显隐;偏好跨快照保留。 */
void setWellNamesVisible(bool bVisible);
/** @brief 返回当前是否持有可用快照且稳定结果图层仍完整。 */
bool hasSnapshot() const;
@ -81,6 +98,11 @@ public:
double& dTime) const;
/** @brief 返回快照中的业务范围;常量属性保持 [c,c]。 */
bool getCurrentPropertyRange(double dRange[2]) const;
/** @brief 返回用户可见范围;自动常量属性保持业务值 [c,c]。 */
bool getCurrentDisplayRange(double dRange[2]) const;
/** @brief 返回当前属性最后一次成功提交的规范化显示设置。 */
bool getCurrentDisplaySettings(
nmPebiResultDisplaySettings& oSettings) const;
/** @brief 返回结果网格显示偏好,不要求当前存在快照。 */
bool isMeshVisible() const;
/** @brief 返回色标显示偏好,不要求当前存在快照。 */
@ -89,6 +111,10 @@ public:
bool isScaleGridVisible() const;
/** @brief 返回单元边线显示偏好,不要求当前存在快照。 */
bool areCellEdgesVisible() const;
/** @brief 返回二维井位标记显示偏好。 */
bool areWellMarkersVisible() const;
/** @brief 返回二维井名显示偏好。 */
bool areWellNamesVisible() const;
private:
Q_DISABLE_COPY(nmPebiResultSceneController)

@ -0,0 +1,69 @@
#ifndef NMPEBIRESULTWELLANNOTATIONLAYER_H
#define NMPEBIRESULTWELLANNOTATIONLAYER_H
#include "nmSubWxs_global.h"
#include "nmVTKRenderLayer.h"
#include <QSharedPointer>
#include <vtkSmartPointer.h>
class nmPebiResultSnapshot;
class vtkPropAssembly;
/**
* @brief 显示快照中全部二维井位和井名的业务图层。
*
* 图层只读取快照冻结的 XY 和井名,不访问 DataManager,不伪造井深或轨迹。
* 稳定根 Assembly 始终挂在 Scene 中;新快照通过候选子 Assembly 无失败交换。
*/
class NM_SUB_WXS_EXPORT nmPebiResultWellAnnotationLayer
: public nmVTKRenderLayer
{
public:
/** @brief 创建稳定根 Assembly,初始不包含任何快照井标注。 */
explicit nmPebiResultWellAnnotationLayer(const QString& sLayerId);
/** @brief 先解除 Renderer,再释放活动和候选子 Assembly。 */
virtual ~nmPebiResultWellAnnotationLayer();
/**
* @brief 在未挂载候选对象中构造快照全部井位和井名。
* @note 失败时活动子 Assembly 完全不变;再次准备会丢弃旧候选。
*/
bool prepareCandidate(
const QSharedPointer<const nmPebiResultSnapshot>& pSnapshot);
/** @brief 丢弃尚未提交的候选对象,不影响当前画面。 */
void discardCandidate();
/**
* @brief 将已经验证的候选子 Assembly 替换为活动对象。
* @note 仅可在 prepareCandidate() 成功后调用;只执行无失败 VTK setter。
*/
void commitCandidate();
/** @brief 移除活动和候选井标注,稳定根 Assembly 保持不变。 */
void clear();
/** @brief 返回活动快照是否已有完整井标注子树。 */
bool hasActiveAnnotations() const;
/** @brief 独立设置约 9px 的二维井位标记显隐。 */
void setWellMarkersVisible(bool bVisible);
/** @brief 独立设置约 12px 的二维井名显隐。 */
void setWellNamesVisible(bool bVisible);
bool areWellMarkersVisible() const;
bool areWellNamesVisible() const;
private:
Q_DISABLE_COPY(nmPebiResultWellAnnotationLayer)
vtkSmartPointer<vtkPropAssembly> m_pRootAssembly; ///< Scene 挂载的稳定根。
vtkSmartPointer<vtkPropAssembly> m_pActiveSnapshotAssembly; ///< 当前快照子树。
vtkSmartPointer<vtkPropAssembly> m_pActiveMarkerGroup; ///< 当前井位组。
vtkSmartPointer<vtkPropAssembly> m_pActiveNameGroup; ///< 当前井名组。
vtkSmartPointer<vtkPropAssembly> m_pCandidateSnapshotAssembly; ///< 待提交子树。
vtkSmartPointer<vtkPropAssembly> m_pCandidateMarkerGroup; ///< 候选井位组。
vtkSmartPointer<vtkPropAssembly> m_pCandidateNameGroup; ///< 候选井名组。
bool m_bWellMarkersVisible; ///< 跨快照保留的井位显隐偏好。
bool m_bWellNamesVisible; ///< 跨快照保留的井名显隐偏好。
};
#endif // NMPEBIRESULTWELLANNOTATIONLAYER_H

@ -0,0 +1,117 @@
#ifndef NMWXPEBIRESULTCOLORSCALESETTINGSDLG_H
#define NMWXPEBIRESULTCOLORSCALESETTINGSDLG_H
#include "nmSubWxs_global.h"
#include "nmPebiResultDisplaySettings.h"
#include <QDialog>
#include <QString>
class QCheckBox;
class QComboBox;
class QLabel;
class QLineEdit;
class QPushButton;
class QToolButton;
class nmPebiResultSceneController;
/**
* @brief Saphir 风格的当前结果属性颜色设置对话框。
*
* 对话框保存打开时的 Snapshot ID 和 Property ID,每次 Apply/OK 都交给
* SceneController 原子复核。Cancel 只丢弃尚未 Apply 的编辑,不回滚已提交状态。
*/
class NM_SUB_WXS_EXPORT nmWxPebiResultColorScaleSettingsDlg
: public QDialog
{
Q_OBJECT
public:
/**
* @param pSceneController 非所有权指针,必须比模态对话框生命周期更长。
* @param pParent 所属窗口,用于对象树和模态定位。
*/
explicit nmWxPebiResultColorScaleSettingsDlg(
nmPebiResultSceneController* pSceneController,
QWidget* pParent = nullptr);
/** @brief 子控件由 Qt 对象树自动释放,不修改 Scene 生命周期。 */
virtual ~nmWxPebiResultColorScaleSettingsDlg();
signals:
/** @brief Apply 或 OK 成功提交后发出,供底部按钮刷新色带预览。 */
void displaySettingsApplied();
/** @brief 转发具体提交错误,供后续组合窗口显示非阻塞提示。 */
void operationFailed(const QString& sError);
private slots:
/** @brief 提交当前编辑并保持对话框打开。 */
void onApplyClicked();
/** @brief 提交成功后关闭对话框,失败时保持打开。 */
void onOkClicked();
/** @brief 恢复快照属性完整范围,不改变色带、Log 或越界颜色。 */
void onRestorePropertyRangeClicked();
/** @brief 用户编辑任一上下限后显式进入手工范围模式。 */
void onManualRangeEdited(const QString& sText);
/** @brief 根据复选框同步低于范围颜色按钮状态。 */
void onBelowRangeToggled(bool bChecked);
/** @brief 根据复选框同步高于范围颜色按钮状态。 */
void onAboveRangeToggled(bool bChecked);
/** @brief 选择低于范围的不透明专用颜色。 */
void onChooseBelowRangeColor();
/** @brief 选择高于范围的不透明专用颜色。 */
void onChooseAboveRangeColor();
/** @brief 范围文字变化后刷新 Log 可用性说明。 */
void refreshLogAvailability();
private:
Q_DISABLE_COPY(nmWxPebiResultColorScaleSettingsDlg)
/** @brief 创建全部编辑控件和 Apply/OK/Cancel 按钮。 */
void createUi();
/** @brief 从 Scene 读取初值并记录不可变的预期身份。 */
bool initializeFromScene();
/** @brief 将设置和值域写入控件,不触发手工范围编辑状态。 */
void populateEditor(const nmPebiResultDisplaySettings& oSettings,
const double dVisibleRange[2]);
/** @brief 解析编辑值并构造待提交纯值设置。 */
bool collectEditedSettings(
nmPebiResultDisplaySettings& oSettings,
QString& sError) const;
/** @brief 执行公共 Apply 逻辑;成功后更新对话框基线。 */
bool applyEditor();
/** @brief 使用最多 12 位有效数字格式化业务值。 */
QString formatValue(double dValue) const;
/** @brief 使用 C locale 严格解析有限 double。 */
bool parseFiniteValue(const QString& sText, double& dValue) const;
/** @brief 更新颜色按钮色块。 */
void updateColorButton(QPushButton* pButton,
const QColor& oColor);
/** @brief 在对话框中显示或清除具体错误。 */
void setErrorText(const QString& sError);
nmPebiResultSceneController* m_pSceneController; ///< 非所有权 Scene 真源。
QString m_sExpectedSnapshotId; ///< 打开时捕获的快照稳定 ID。
QString m_sExpectedPropertyId; ///< 打开时捕获的属性稳定 ID。
QString m_sDisplayUnit; ///< 当前属性默认显示单位,仅用于标签。
double m_dPropertyRange[2]; ///< 快照完整业务范围,回退按钮使用。
nmPebiResultDisplaySettings m_oBaselineSettings; ///< 最近成功 Apply 的基线。
bool m_bManualRangeEdited; ///< 仅用户编辑或已有手工范围时为 true。
bool m_bInitialized; ///< Scene 初值是否完整读取成功。
QComboBox* m_pColorMapCombo; ///< 带渐变预览和稳定 ID 的色带框。
QLineEdit* m_pMinimumEdit; ///< 支持科学计数法的最小值文字框。
QLineEdit* m_pMaximumEdit; ///< 支持科学计数法的最大值文字框。
QLabel* m_pUnitLabel; ///< 当前属性默认显示单位;无量纲时显示“无量纲”。
QToolButton* m_pRestoreRangeButton; ///< 恢复完整业务范围按钮。
QCheckBox* m_pLogarithmicCheck; ///< Log10 映射开关。
QLabel* m_pLogReasonLabel; ///< Log 不可用时的明确原因。
QCheckBox* m_pBelowRangeCheck; ///< 低于范围专用颜色开关。
QPushButton* m_pBelowColorButton; ///< 低于范围颜色按钮。
QCheckBox* m_pAboveRangeCheck; ///< 高于范围专用颜色开关。
QPushButton* m_pAboveColorButton; ///< 高于范围颜色按钮。
QLabel* m_pErrorLabel; ///< 提交或解析失败说明。
QPushButton* m_pApplyButton; ///< 应用但不关闭按钮。
QPushButton* m_pOkButton; ///< 应用成功后关闭按钮。
};
#endif // NMWXPEBIRESULTCOLORSCALESETTINGSDLG_H

@ -50,6 +50,8 @@ private slots:
void onPropertyIndexChanged(int nIndex);
/** @brief 用户选择时间时提交 itemData 中的零基帧。 */
void onTimeIndexChanged(int nIndex);
/** @brief 暂停后打开当前属性的 Saphir 风格颜色设置对话框。 */
void onColorSettingsClicked();
/** @brief 响应首帧按钮。 */
void onFirstFrameClicked();
/** @brief 响应上一帧按钮。 */
@ -66,6 +68,8 @@ private slots:
void refreshFromController();
/** @brief 将控制器错误转发给后续组合窗口。 */
void forwardOperationFailure(const QString& sError);
/** @brief 从 Scene 当前设置刷新颜色按钮的色带预览。 */
void refreshColorPreview();
private:
Q_DISABLE_COPY(nmWxPebiResultControlBar)
@ -84,8 +88,12 @@ private:
/** @brief 本控制条独占的 QObject 子对象,负责全部回放业务状态。 */
nmPebiResultPlaybackController* m_pPlaybackController;
/** @brief 已渲染属性、帧和显示设置的唯一真源;本控件不拥有。 */
nmPebiResultSceneController* m_pSceneController;
/** @brief 属性选择框,条目数据保存稳定英文属性 ID。 */
QComboBox* m_pPropertyCombo;
/** @brief 显示当前色带预览并打开颜色设置对话框。 */
QToolButton* m_pColorSettingsButton;
/** @brief 跳到第 0 帧的图标按钮。 */
QToolButton* m_pFirstButton;
/** @brief 跳到上一帧的图标按钮。 */

@ -0,0 +1,134 @@
#include "nmVTKColorMapCatalog.h"
#include <QtGlobal>
#include <QPainter>
#include <vtkLookupTable.h>
#include <vtkMath.h>
namespace {
const char* const COLOR_MAP_RAINBOW = "rainbow";
const char* const COLOR_MAP_OIL_SATURATION = "oil-saturation";
const char* const COLOR_MAP_GAS_SATURATION = "gas-saturation";
const char* const COLOR_MAP_WATER_SATURATION = "water-saturation";
const int COLOR_TABLE_SIZE = 256;
QString stableId(const char* pId)
{
return QString::fromLatin1(pId);
}
QColor interpolateRgb(const QColor& oStart,
const QColor& oEnd,
double dPosition)
{
const double dInverse = 1.0 - dPosition;
return QColor(qRound(oStart.red() * dInverse +
oEnd.red() * dPosition),
qRound(oStart.green() * dInverse +
oEnd.green() * dPosition),
qRound(oStart.blue() * dInverse +
oEnd.blue() * dPosition),
255);
}
}
QStringList nmVTKColorMapCatalog::getColorMapIds()
{
QStringList listIds;
listIds << stableId(COLOR_MAP_RAINBOW)
<< stableId(COLOR_MAP_OIL_SATURATION)
<< stableId(COLOR_MAP_GAS_SATURATION)
<< stableId(COLOR_MAP_WATER_SATURATION);
return listIds;
}
bool nmVTKColorMapCatalog::contains(const QString& sColorMapId)
{
return getColorMapIds().contains(sColorMapId);
}
bool nmVTKColorMapCatalog::getColor(const QString& sColorMapId,
double dPosition,
QColor& oColor)
{
if(!vtkMath::IsFinite(dPosition) || dPosition < 0.0 ||
dPosition > 1.0 || !contains(sColorMapId)) {
return false;
}
QColor oCandidate;
if(sColorMapId == stableId(COLOR_MAP_RAINBOW)) {
// Saphir 风格 Rainbow:色相从蓝色 240 度连续过渡到红色 0 度。
oCandidate = QColor::fromHsvF(
(1.0 - dPosition) * (240.0 / 360.0),
1.0, 1.0, 1.0);
} else if(sColorMapId == stableId(COLOR_MAP_OIL_SATURATION)) {
oCandidate = interpolateRgb(
QColor(255, 255, 255), QColor(0, 255, 0), dPosition);
} else if(sColorMapId == stableId(COLOR_MAP_GAS_SATURATION)) {
oCandidate = interpolateRgb(
QColor(255, 255, 255), QColor(255, 0, 0), dPosition);
} else {
oCandidate = interpolateRgb(
QColor(255, 255, 255), QColor(0, 0, 255), dPosition);
}
oCandidate.setAlpha(255);
oColor = oCandidate;
return true;
}
QPixmap nmVTKColorMapCatalog::createPreviewPixmap(
const QString& sColorMapId,
const QSize& oSize)
{
if(!contains(sColorMapId) || oSize.width() <= 0 ||
oSize.height() <= 0) {
return QPixmap();
}
QPixmap oPixmap(oSize);
oPixmap.fill(Qt::transparent);
QPainter oPainter(&oPixmap);
for(int nX = 0; nX < oSize.width(); ++nX) {
QColor oColor;
const double dPosition = oSize.width() == 1 ? 0.0 :
static_cast<double>(nX) /
static_cast<double>(oSize.width() - 1);
if(getColor(sColorMapId, dPosition, oColor)) {
oPainter.setPen(oColor);
oPainter.drawLine(nX, 0, nX, oSize.height() - 1);
}
}
oPainter.setPen(QColor(96, 96, 96));
oPainter.drawRect(0, 0, oSize.width() - 1, oSize.height() - 1);
oPainter.end();
return oPixmap;
}
vtkSmartPointer<vtkLookupTable>
nmVTKColorMapCatalog::createLookupTable(const QString& sColorMapId)
{
if(!contains(sColorMapId)) {
return vtkSmartPointer<vtkLookupTable>();
}
vtkSmartPointer<vtkLookupTable> pLookupTable =
vtkSmartPointer<vtkLookupTable>::New();
pLookupTable->SetNumberOfTableValues(COLOR_TABLE_SIZE);
for(int nIndex = 0; nIndex < COLOR_TABLE_SIZE; ++nIndex) {
QColor oColor;
const double dPosition = static_cast<double>(nIndex) /
static_cast<double>(COLOR_TABLE_SIZE - 1);
if(!getColor(sColorMapId, dPosition, oColor)) {
return vtkSmartPointer<vtkLookupTable>();
}
pLookupTable->SetTableValue(
nIndex,
oColor.redF(), oColor.greenF(), oColor.blueF(), 1.0);
}
pLookupTable->Build();
return pLookupTable;
}

@ -155,6 +155,42 @@ bool nmVTKMeshLayer::setInputConnection(
return true;
}
bool nmVTKMeshLayer::setInputConnection(
vtkAlgorithmOutput* pInputConnection,
const QString& sArrayName,
ScalarAssociation eAssociation,
vtkLookupTable* pCandidateLookupTable)
{
Q_ASSERT(isMeshLayerGuiThread());
if(!isMeshLayerGuiThread() || pInputConnection == nullptr ||
pInputConnection->GetProducer() == nullptr ||
pInputConnection->GetIndex() < 0 || sArrayName.isEmpty()) {
return false;
}
vtkAlgorithm* pProducer = pInputConnection->GetProducer();
const int nOutputPort = pInputConnection->GetIndex();
pProducer->Update(nOutputPort);
vtkDataSet* pCandidateDataSet = vtkDataSet::SafeDownCast(
pProducer->GetOutputDataObject(nOutputPort));
const QByteArray aArrayName = sArrayName.toUtf8();
double dDataRange[2] = { 0.0, 0.0 };
double dLookupRange[2] = { 0.0, 0.0 };
if(validateScalarArray(pCandidateDataSet, aArrayName,
eAssociation, dDataRange) == nullptr ||
!validateLookupTable(pCandidateLookupTable, dLookupRange)) {
return false;
}
// 输入、数组和候选 LUT 已全部验证;以下 VTK setter 均无失败返回值。
m_pMapper->SetInputConnection(pInputConnection);
m_pInputConnection = pInputConnection;
m_pDataSet = nullptr;
applyLookupTableScalarState(aArrayName, eAssociation,
pCandidateLookupTable, dLookupRange);
return true;
}
void nmVTKMeshLayer::clearInput()
{
Q_ASSERT(isMeshLayerGuiThread());
@ -272,6 +308,32 @@ bool nmVTKMeshLayer::setScalarArray(
return true;
}
bool nmVTKMeshLayer::setScalarArray(
const QString& sArrayName,
ScalarAssociation eAssociation,
vtkLookupTable* pCandidateLookupTable)
{
Q_ASSERT(isMeshLayerGuiThread());
vtkDataSet* pDataSet = getInputDataSet(true);
if(!isMeshLayerGuiThread() || sArrayName.isEmpty() ||
pDataSet == nullptr || m_pMapper == nullptr) {
return false;
}
const QByteArray aArrayName = sArrayName.toUtf8();
double dDataRange[2] = { 0.0, 0.0 };
double dLookupRange[2] = { 0.0, 0.0 };
if(validateScalarArray(pDataSet, aArrayName,
eAssociation, dDataRange) == nullptr ||
!validateLookupTable(pCandidateLookupTable, dLookupRange)) {
return false;
}
applyLookupTableScalarState(aArrayName, eAssociation,
pCandidateLookupTable, dLookupRange);
return true;
}
bool nmVTKMeshLayer::setScalarArray(
const QString& sArrayName,
ScalarAssociation eAssociation,
@ -344,6 +406,24 @@ bool nmVTKMeshLayer::isUsingExplicitScalarRange() const
return m_bUsingExplicitScalarRange;
}
bool nmVTKMeshLayer::setLookupTable(
vtkLookupTable* pCandidateLookupTable)
{
Q_ASSERT(isMeshLayerGuiThread());
double dLookupRange[2] = { 0.0, 0.0 };
if(!isMeshLayerGuiThread() || getSelectedScalarArray() == nullptr ||
!validateLookupTable(pCandidateLookupTable, dLookupRange)) {
return false;
}
// 候选对象由智能指针共享,Mapper 与 MeshLayer 始终引用同一 LUT。
m_pLookupTable = pCandidateLookupTable;
m_pMapper->SetLookupTable(m_pLookupTable);
m_pMapper->SetScalarRange(dLookupRange);
m_bUsingExplicitScalarRange = true;
return true;
}
vtkDataSetMapper* nmVTKMeshLayer::getMapper() const
{
return m_pMapper;
@ -419,6 +499,25 @@ vtkDataArray* nmVTKMeshLayer::validateScalarArray(
? pArray : nullptr;
}
bool nmVTKMeshLayer::validateLookupTable(
vtkLookupTable* pLookupTable,
double dRange[2]) const
{
if(pLookupTable == nullptr || dRange == nullptr ||
pLookupTable->GetNumberOfTableValues() <= 0) {
return false;
}
const double* pRange = pLookupTable->GetTableRange();
if(pRange == nullptr || !vtkMath::IsFinite(pRange[0]) ||
!vtkMath::IsFinite(pRange[1]) || pRange[0] >= pRange[1] ||
(pLookupTable->GetScale() == VTK_SCALE_LOG10 && pRange[0] <= 0.0)) {
return false;
}
dRange[0] = pRange[0];
dRange[1] = pRange[1];
return true;
}
void nmVTKMeshLayer::applyExplicitScalarState(
const QByteArray& aArrayName,
ScalarAssociation eAssociation,
@ -439,6 +538,27 @@ void nmVTKMeshLayer::applyExplicitScalarState(
m_bUsingExplicitScalarRange = true;
}
void nmVTKMeshLayer::applyLookupTableScalarState(
const QByteArray& aArrayName,
ScalarAssociation eAssociation,
vtkLookupTable* pLookupTable,
const double dRange[2])
{
m_aScalarArrayName = aArrayName;
m_eScalarAssociation = eAssociation;
if(eAssociation == ScalarAssociation_CellData) {
m_pMapper->SetScalarModeToUseCellFieldData();
} else {
m_pMapper->SetScalarModeToUsePointFieldData();
}
m_pMapper->SelectColorArray(m_aScalarArrayName.constData());
m_pLookupTable = pLookupTable;
m_pMapper->SetLookupTable(m_pLookupTable);
// VTK 7.1 的数组重载要求可写 double*,这里使用双参数重载保留 const 契约。
m_pMapper->SetScalarRange(dRange[0], dRange[1]);
m_bUsingExplicitScalarRange = true;
}
void nmVTKMeshLayer::applyRetainedScalarState(
const double dScalarRange[2])
{

@ -4,9 +4,19 @@
#include <QCoreApplication>
#include <QThread>
#include <vtkActor2D.h>
#include <vtkCellArray.h>
#include <vtkCoordinate.h>
#include <vtkLookupTable.h>
#include <vtkMath.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper2D.h>
#include <vtkPropAssembly.h>
#include <vtkProperty2D.h>
#include <vtkScalarBarActor.h>
#include <vtkTextActor.h>
#include <vtkTextProperty.h>
namespace {
@ -18,16 +28,125 @@ bool isScalarBarGuiThread()
pApplication->thread() == QThread::currentThread();
}
// 独立色块使用归一化视口坐标,避免依赖仅支持 IndexedLookup 的 ScalarBar Annotation。
vtkSmartPointer<vtkActor2D> createRangeSwatchActor(vtkPoints* pPoints)
{
vtkSmartPointer<vtkCellArray> pPolygons =
vtkSmartPointer<vtkCellArray>::New();
pPolygons->InsertNextCell(4);
pPolygons->InsertCellPoint(0);
pPolygons->InsertCellPoint(1);
pPolygons->InsertCellPoint(2);
pPolygons->InsertCellPoint(3);
vtkSmartPointer<vtkPolyData> pData =
vtkSmartPointer<vtkPolyData>::New();
pData->SetPoints(pPoints);
pData->SetPolys(pPolygons);
vtkSmartPointer<vtkCoordinate> pViewportCoordinate =
vtkSmartPointer<vtkCoordinate>::New();
pViewportCoordinate->SetCoordinateSystemToNormalizedViewport();
vtkSmartPointer<vtkPolyDataMapper2D> pMapper =
vtkSmartPointer<vtkPolyDataMapper2D>::New();
pMapper->SetInputData(pData);
pMapper->SetTransformCoordinate(pViewportCoordinate);
pMapper->ScalarVisibilityOff();
vtkSmartPointer<vtkActor2D> pActor =
vtkSmartPointer<vtkActor2D>::New();
pActor->SetMapper(pMapper);
pActor->GetProperty()->SetDisplayLocationToForeground();
pActor->PickableOff();
pActor->SetVisibility(0);
return pActor;
}
// 统一独立文本样式,使常量值和越界说明与普通色标刻度保持一致。
void configureOverlayTextActor(vtkTextActor* pActor)
{
pActor->SetInput("");
pActor->SetTextScaleModeToNone();
pActor->GetTextProperty()->SetFontSize(11);
pActor->GetTextProperty()->BoldOff();
pActor->GetTextProperty()->ItalicOff();
pActor->GetTextProperty()->ShadowOff();
pActor->GetTextProperty()->SetJustificationToLeft();
pActor->GetTextProperty()->SetVerticalJustificationToCentered();
pActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
pActor->PickableOff();
pActor->SetVisibility(0);
}
// 更新矩形四角并显式标记 Points 已修改,Mapper 会在下一次 Render 使用新位置。
void updateRectangle(vtkPoints* pPoints,
double dX, double dY,
double dWidth, double dHeight)
{
pPoints->SetPoint(0, dX, dY, 0.0);
pPoints->SetPoint(1, dX + dWidth, dY, 0.0);
pPoints->SetPoint(2, dX + dWidth, dY + dHeight, 0.0);
pPoints->SetPoint(3, dX, dY + dHeight, 0.0);
pPoints->Modified();
}
}
nmVTKScalarBarLayer::nmVTKScalarBarLayer(const QString& sLayerId)
: nmVTKRenderLayer(sLayerId),
m_pLookupTable(nullptr),
m_pActor(vtkSmartPointer<vtkScalarBarActor>::New())
m_pRootAssembly(vtkSmartPointer<vtkPropAssembly>::New()),
m_pActor(vtkSmartPointer<vtkScalarBarActor>::New()),
m_pConstantValueActor(vtkSmartPointer<vtkTextActor>::New()),
m_pBelowRangeSwatchPoints(vtkSmartPointer<vtkPoints>::New()),
m_pBelowRangeSwatchActor(nullptr),
m_pBelowRangeTextActor(vtkSmartPointer<vtkTextActor>::New()),
m_pAboveRangeSwatchPoints(vtkSmartPointer<vtkPoints>::New()),
m_pAboveRangeSwatchActor(nullptr),
m_pAboveRangeTextActor(vtkSmartPointer<vtkTextActor>::New()),
m_sLabelFormat(QString::fromLatin1("%.6g")),
m_dPositionX(0.0),
m_dPositionY(0.0),
m_dWidth(0.1),
m_dHeight(0.8)
{
Q_ASSERT(isScalarBarGuiThread());
// vtkScalarBarActor 是二维 Prop,仍通过图层基类统一完成挂载和显隐。
setRenderProp(m_pActor);
m_pActor->SetNumberOfLabels(5);
m_pActor->SetLabelFormat("%.6g");
m_pActor->UnconstrainedFontSizeOn();
m_pActor->GetLabelTextProperty()->SetFontSize(11);
m_pActor->GetLabelTextProperty()->BoldOff();
m_pActor->GetLabelTextProperty()->ItalicOff();
m_pActor->GetLabelTextProperty()->ShadowOff();
m_pActor->GetTitleTextProperty()->SetFontSize(12);
m_pActor->GetTitleTextProperty()->BoldOff();
m_pActor->GetTitleTextProperty()->ItalicOff();
m_pActor->GetTitleTextProperty()->ShadowOff();
m_pActor->DrawAnnotationsOff();
m_pActor->DrawBelowRangeSwatchOff();
m_pActor->DrawAboveRangeSwatchOff();
// 这些二维装饰必须独立显示,不能为网格共享 LUT 开启 IndexedLookup。
m_pBelowRangeSwatchPoints->SetNumberOfPoints(4);
m_pAboveRangeSwatchPoints->SetNumberOfPoints(4);
m_pBelowRangeSwatchActor =
createRangeSwatchActor(m_pBelowRangeSwatchPoints);
m_pAboveRangeSwatchActor =
createRangeSwatchActor(m_pAboveRangeSwatchPoints);
configureOverlayTextActor(m_pConstantValueActor);
configureOverlayTextActor(m_pBelowRangeTextActor);
configureOverlayTextActor(m_pAboveRangeTextActor);
updateOverlayLayout();
// 根 Assembly 只在构造时注册,运行期仅更新子 Actor 状态。
m_pRootAssembly->AddPart(m_pActor);
m_pRootAssembly->AddPart(m_pConstantValueActor);
m_pRootAssembly->AddPart(m_pBelowRangeSwatchActor);
m_pRootAssembly->AddPart(m_pBelowRangeTextActor);
m_pRootAssembly->AddPart(m_pAboveRangeSwatchActor);
m_pRootAssembly->AddPart(m_pAboveRangeTextActor);
setRenderProp(m_pRootAssembly);
}
nmVTKScalarBarLayer::~nmVTKScalarBarLayer()
@ -36,6 +155,15 @@ nmVTKScalarBarLayer::~nmVTKScalarBarLayer()
// 先移除二维 Prop,再释放对外部 LookupTable 的共享引用。
detach();
m_pLookupTable = nullptr;
m_pAboveRangeTextActor = nullptr;
m_pAboveRangeSwatchActor = nullptr;
m_pAboveRangeSwatchPoints = nullptr;
m_pBelowRangeTextActor = nullptr;
m_pBelowRangeSwatchActor = nullptr;
m_pBelowRangeSwatchPoints = nullptr;
m_pConstantValueActor = nullptr;
m_pActor = nullptr;
m_pRootAssembly = nullptr;
}
void nmVTKScalarBarLayer::setLookupTable(vtkLookupTable* pLookupTable)
@ -47,6 +175,7 @@ void nmVTKScalarBarLayer::setLookupTable(vtkLookupTable* pLookupTable)
// 智能指针共享 LookupTable,保证外部释放原指针后色标仍可安全显示。
m_pLookupTable = pLookupTable;
m_pActor->SetLookupTable(pLookupTable);
updateRangeSwatchColors();
}
vtkLookupTable* nmVTKScalarBarLayer::getLookupTable() const
@ -71,6 +200,86 @@ QString nmVTKScalarBarLayer::getTitle() const
return m_sTitle;
}
bool nmVTKScalarBarLayer::setLabelFormat(const QString& sFormat)
{
Q_ASSERT(isScalarBarGuiThread());
if(!isScalarBarGuiThread() || sFormat.isEmpty()) {
return false;
}
m_sLabelFormat = sFormat;
const QByteArray aFormat = sFormat.toLatin1();
m_pActor->SetLabelFormat(aFormat.constData());
return true;
}
QString nmVTKScalarBarLayer::getLabelFormat() const
{
return m_sLabelFormat;
}
bool nmVTKScalarBarLayer::setNumberOfLabels(int nLabelCount)
{
Q_ASSERT(isScalarBarGuiThread());
if(!isScalarBarGuiThread() || nLabelCount < 0 || nLabelCount > 64) {
return false;
}
m_pActor->SetNumberOfLabels(nLabelCount);
return true;
}
int nmVTKScalarBarLayer::getNumberOfLabels() const
{
return m_pActor != nullptr ? m_pActor->GetNumberOfLabels() : 0;
}
void nmVTKScalarBarLayer::setBelowRangeSwatch(
bool bVisible,
const QString& sText)
{
Q_ASSERT(isScalarBarGuiThread());
if(!isScalarBarGuiThread()) {
return;
}
m_sBelowRangeText = bVisible ? sText : QString();
const QByteArray aText = m_sBelowRangeText.toUtf8();
m_pBelowRangeTextActor->SetInput(aText.constData());
m_pBelowRangeSwatchActor->SetVisibility(bVisible ? 1 : 0);
m_pBelowRangeTextActor->SetVisibility(
bVisible && !m_sBelowRangeText.isEmpty() ? 1 : 0);
}
void nmVTKScalarBarLayer::setAboveRangeSwatch(
bool bVisible,
const QString& sText)
{
Q_ASSERT(isScalarBarGuiThread());
if(!isScalarBarGuiThread()) {
return;
}
m_sAboveRangeText = bVisible ? sText : QString();
const QByteArray aText = m_sAboveRangeText.toUtf8();
m_pAboveRangeTextActor->SetInput(aText.constData());
m_pAboveRangeSwatchActor->SetVisibility(bVisible ? 1 : 0);
m_pAboveRangeTextActor->SetVisibility(
bVisible && !m_sAboveRangeText.isEmpty() ? 1 : 0);
}
void nmVTKScalarBarLayer::setConstantValueLabel(
bool bVisible,
const QString& sText)
{
Q_ASSERT(isScalarBarGuiThread());
if(!isScalarBarGuiThread()) {
return;
}
m_sConstantValueText = bVisible ? sText : QString();
const QByteArray aText = m_sConstantValueText.toUtf8();
m_pConstantValueActor->SetInput(aText.constData());
m_pConstantValueActor->SetVisibility(
bVisible && !m_sConstantValueText.isEmpty() ? 1 : 0);
}
bool nmVTKScalarBarLayer::setPosition(double dX, double dY)
{
Q_ASSERT(isScalarBarGuiThread());
@ -79,7 +288,10 @@ bool nmVTKScalarBarLayer::setPosition(double dX, double dY)
return false;
}
// vtkScalarBarActor 默认使用归一化视口坐标,位置值由上层布局策略决定。
m_dPositionX = dX;
m_dPositionY = dY;
m_pActor->SetPosition(dX, dY);
updateOverlayLayout();
return true;
}
@ -91,11 +303,67 @@ bool nmVTKScalarBarLayer::setSize(double dWidth, double dHeight)
return false;
}
// 这里只拒绝非正尺寸,不替业务层限制色标是否超出视口。
m_dWidth = dWidth;
m_dHeight = dHeight;
m_pActor->SetWidth(dWidth);
m_pActor->SetHeight(dHeight);
updateOverlayLayout();
return true;
}
void nmVTKScalarBarLayer::updateOverlayLayout()
{
// 常量值放在色带右侧的垂直中心,视觉位置与普通刻度标签一致。
const double dLabelX = m_dPositionX + m_dWidth + 0.01;
const double dLabelY = m_dPositionY + m_dHeight * 0.5;
m_pConstantValueActor->GetPositionCoordinate()->SetValue(
dLabelX, dLabelY, 0.0);
// 越界色块位于色带上下两端外侧,避免覆盖连续色带和普通刻度。
double dSwatchWidth = m_dWidth * 0.25;
if(dSwatchWidth < 0.012) {
dSwatchWidth = 0.012;
} else if(dSwatchWidth > 0.025) {
dSwatchWidth = 0.025;
}
const double dSwatchHeight = 0.018;
const double dSwatchGap = 0.012;
const double dTextGap = 0.008;
const double dBelowY =
m_dPositionY - dSwatchGap - dSwatchHeight;
const double dAboveY =
m_dPositionY + m_dHeight + dSwatchGap;
updateRectangle(m_pBelowRangeSwatchPoints,
m_dPositionX, dBelowY,
dSwatchWidth, dSwatchHeight);
updateRectangle(m_pAboveRangeSwatchPoints,
m_dPositionX, dAboveY,
dSwatchWidth, dSwatchHeight);
m_pBelowRangeTextActor->GetPositionCoordinate()->SetValue(
m_dPositionX + dSwatchWidth + dTextGap,
dBelowY + dSwatchHeight * 0.5, 0.0);
m_pAboveRangeTextActor->GetPositionCoordinate()->SetValue(
m_dPositionX + dSwatchWidth + dTextGap,
dAboveY + dSwatchHeight * 0.5, 0.0);
}
void nmVTKScalarBarLayer::updateRangeSwatchColors()
{
if(m_pLookupTable == nullptr) {
return;
}
// 读取 LookupTable 的业务颜色属性,不直接访问内部特殊表项索引。
const double* pBelowColor = m_pLookupTable->GetBelowRangeColor();
const double* pAboveColor = m_pLookupTable->GetAboveRangeColor();
m_pBelowRangeSwatchActor->GetProperty()->SetColor(
pBelowColor[0], pBelowColor[1], pBelowColor[2]);
m_pBelowRangeSwatchActor->GetProperty()->SetOpacity(pBelowColor[3]);
m_pAboveRangeSwatchActor->GetProperty()->SetColor(
pAboveColor[0], pAboveColor[1], pAboveColor[2]);
m_pAboveRangeSwatchActor->GetProperty()->SetOpacity(pAboveColor[3]);
}
vtkScalarBarActor* nmVTKScalarBarLayer::getActor() const
{
return m_pActor;

@ -0,0 +1,90 @@
#include "nmPebiResultDisplaySettings.h"
#include <QtGlobal>
#include <float.h>
#if !defined(_MSC_VER)
#include <cmath>
#endif
namespace {
// Qt 4.8 未统一提供 qIsFinite,保持值类型不依赖 VTK。
bool isFiniteDisplayValue(double dValue)
{
#if defined(_MSC_VER)
return _finite(dValue) != 0;
#else
return std::isfinite(dValue);
#endif
}
}
nmPebiResultDisplaySettings::nmPebiResultDisplaySettings()
: m_sColorMapId(QString::fromLatin1("rainbow")),
m_eScaleMode(NM_PebiColorScale_Linear),
m_bHasManualRange(false),
m_dManualMinimum(0.0),
m_dManualMaximum(0.0),
m_bUseBelowRangeColor(false),
m_bUseAboveRangeColor(false),
m_oBelowRangeColor(Qt::black),
m_oAboveRangeColor(Qt::black)
{
}
bool nmPebiResultDisplaySettings::isStructurallyValid() const
{
const bool bScaleModeValid =
m_eScaleMode == NM_PebiColorScale_Linear ||
m_eScaleMode == NM_PebiColorScale_Logarithmic;
return bScaleModeValid &&
isFiniteDisplayValue(m_dManualMinimum) &&
isFiniteDisplayValue(m_dManualMaximum) &&
m_oBelowRangeColor.isValid() &&
m_oAboveRangeColor.isValid();
}
nmPebiResultDisplaySettings
nmPebiResultDisplaySettings::normalized() const
{
nmPebiResultDisplaySettings oResult(*this);
if(!oResult.m_bHasManualRange) {
// 自动范围不携带历史手工值,避免相等比较出现不可见差异。
oResult.m_dManualMinimum = 0.0;
oResult.m_dManualMaximum = 0.0;
}
if(oResult.m_oBelowRangeColor.isValid()) {
oResult.m_oBelowRangeColor.setAlpha(255);
}
if(oResult.m_oAboveRangeColor.isValid()) {
oResult.m_oAboveRangeColor.setAlpha(255);
}
return oResult;
}
bool nmPebiResultDisplaySettings::operator==(
const nmPebiResultDisplaySettings& oOther) const
{
const nmPebiResultDisplaySettings oLeft = normalized();
const nmPebiResultDisplaySettings oRight = oOther.normalized();
return oLeft.m_sColorMapId == oRight.m_sColorMapId &&
oLeft.m_eScaleMode == oRight.m_eScaleMode &&
oLeft.m_bHasManualRange == oRight.m_bHasManualRange &&
oLeft.m_dManualMinimum == oRight.m_dManualMinimum &&
oLeft.m_dManualMaximum == oRight.m_dManualMaximum &&
oLeft.m_bUseBelowRangeColor ==
oRight.m_bUseBelowRangeColor &&
oLeft.m_bUseAboveRangeColor ==
oRight.m_bUseAboveRangeColor &&
oLeft.m_oBelowRangeColor == oRight.m_oBelowRangeColor &&
oLeft.m_oAboveRangeColor == oRight.m_oAboveRangeColor;
}
bool nmPebiResultDisplaySettings::operator!=(
const nmPebiResultDisplaySettings& oOther) const
{
return !(*this == oOther);
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,250 @@
#include "nmPebiResultWellAnnotationLayer.h"
#include "nmPebiResultSnapshot.h"
#include <QCoreApplication>
#include <QSet>
#include <QThread>
#include <vtkActor2D.h>
#include <vtkCellArray.h>
#include <vtkCoordinate.h>
#include <vtkLabeledDataMapper.h>
#include <vtkMath.h>
#include <vtkPointData.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper2D.h>
#include <vtkPropAssembly.h>
#include <vtkProperty2D.h>
#include <vtkStringArray.h>
#include <vtkTextProperty.h>
namespace {
bool isWellAnnotationGuiThread()
{
QCoreApplication* pApplication = QCoreApplication::instance();
return pApplication == nullptr ||
pApplication->thread() == QThread::currentThread();
}
}
nmPebiResultWellAnnotationLayer::nmPebiResultWellAnnotationLayer(
const QString& sLayerId)
: nmVTKRenderLayer(sLayerId),
m_pRootAssembly(vtkSmartPointer<vtkPropAssembly>::New()),
m_pActiveSnapshotAssembly(nullptr),
m_pActiveMarkerGroup(nullptr),
m_pActiveNameGroup(nullptr),
m_pCandidateSnapshotAssembly(nullptr),
m_pCandidateMarkerGroup(nullptr),
m_pCandidateNameGroup(nullptr),
m_bWellMarkersVisible(true),
m_bWellNamesVisible(true)
{
Q_ASSERT(isWellAnnotationGuiThread());
// setRenderProp 只在未挂载时可调用,因此根 Assembly 在构造时一次固定。
setRenderProp(m_pRootAssembly);
}
nmPebiResultWellAnnotationLayer::~nmPebiResultWellAnnotationLayer()
{
Q_ASSERT(isWellAnnotationGuiThread());
detach();
clear();
m_pRootAssembly = nullptr;
}
bool nmPebiResultWellAnnotationLayer::prepareCandidate(
const QSharedPointer<const nmPebiResultSnapshot>& pSnapshot)
{
Q_ASSERT(isWellAnnotationGuiThread());
discardCandidate();
if(!isWellAnnotationGuiThread() || pSnapshot.isNull() ||
!pSnapshot->isComplete()) {
return false;
}
vtkSmartPointer<vtkPoints> pMarkerPoints =
vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkCellArray> pMarkerVertices =
vtkSmartPointer<vtkCellArray>::New();
vtkSmartPointer<vtkPoints> pNamePoints =
vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkStringArray> pWellNames =
vtkSmartPointer<vtkStringArray>::New();
pWellNames->SetName("WellName");
QSet<QString> setWellIds;
for(int nIndex = 0; nIndex < pSnapshot->getWellCount(); ++nIndex) {
const nmPebiResultWellSnapshot* pWell = pSnapshot->getWellAt(nIndex);
if(pWell == nullptr || pWell->m_sWellInstanceId.isEmpty() ||
pWell->m_sWellName.isEmpty() ||
!vtkMath::IsFinite(pWell->m_oLocation.x()) ||
!vtkMath::IsFinite(pWell->m_oLocation.y()) ||
setWellIds.contains(pWell->m_sWellInstanceId)) {
discardCandidate();
return false;
}
setWellIds.insert(pWell->m_sWellInstanceId);
// 保持快照存储顺序;二维 Overlay 不向业务位置写入虚构 Z 值。
const vtkIdType nPointId = pMarkerPoints->InsertNextPoint(
pWell->m_oLocation.x(), pWell->m_oLocation.y(), 0.0);
pMarkerVertices->InsertNextCell(1);
pMarkerVertices->InsertCellPoint(nPointId);
pNamePoints->InsertNextPoint(
pWell->m_oLocation.x(), pWell->m_oLocation.y(), 0.0);
const QByteArray aWellName = pWell->m_sWellName.toUtf8();
pWellNames->InsertNextValue(aWellName.constData());
}
vtkSmartPointer<vtkPropAssembly> pSnapshotAssembly =
vtkSmartPointer<vtkPropAssembly>::New();
vtkSmartPointer<vtkPropAssembly> pMarkerGroup =
vtkSmartPointer<vtkPropAssembly>::New();
vtkSmartPointer<vtkPropAssembly> pNameGroup =
vtkSmartPointer<vtkPropAssembly>::New();
if(pSnapshot->getWellCount() > 0) {
vtkSmartPointer<vtkPolyData> pMarkerData =
vtkSmartPointer<vtkPolyData>::New();
pMarkerData->SetPoints(pMarkerPoints);
pMarkerData->SetVerts(pMarkerVertices);
vtkSmartPointer<vtkCoordinate> pWorldCoordinate =
vtkSmartPointer<vtkCoordinate>::New();
pWorldCoordinate->SetCoordinateSystemToWorld();
vtkSmartPointer<vtkPolyDataMapper2D> pMarkerMapper =
vtkSmartPointer<vtkPolyDataMapper2D>::New();
pMarkerMapper->SetInputData(pMarkerData);
pMarkerMapper->SetTransformCoordinate(pWorldCoordinate);
pMarkerMapper->ScalarVisibilityOff();
vtkSmartPointer<vtkActor2D> pMarkerActor =
vtkSmartPointer<vtkActor2D>::New();
pMarkerActor->SetMapper(pMarkerMapper);
pMarkerActor->GetProperty()->SetColor(0.12, 0.12, 0.12);
pMarkerActor->GetProperty()->SetPointSize(9.0);
pMarkerGroup->AddPart(pMarkerActor);
vtkSmartPointer<vtkPolyData> pNameData =
vtkSmartPointer<vtkPolyData>::New();
pNameData->SetPoints(pNamePoints);
pNameData->GetPointData()->AddArray(pWellNames);
vtkSmartPointer<vtkLabeledDataMapper> pNameMapper =
vtkSmartPointer<vtkLabeledDataMapper>::New();
pNameMapper->SetInputData(pNameData);
pNameMapper->SetLabelModeToLabelFieldData();
pNameMapper->SetFieldDataName("WellName");
pNameMapper->SetLabelFormat("%s");
pNameMapper->GetLabelTextProperty()->SetFontSize(12);
pNameMapper->GetLabelTextProperty()->SetColor(0.10, 0.10, 0.10);
pNameMapper->GetLabelTextProperty()->BoldOff();
pNameMapper->GetLabelTextProperty()->ItalicOff();
pNameMapper->GetLabelTextProperty()->ShadowOff();
pNameMapper->GetLabelTextProperty()->SetJustificationToLeft();
pNameMapper->GetLabelTextProperty()->SetVerticalJustificationToBottom();
vtkSmartPointer<vtkActor2D> pNameActor =
vtkSmartPointer<vtkActor2D>::New();
pNameActor->SetMapper(pNameMapper);
// Actor2D 的显示坐标偏移固定为像素,不随相机缩放改变。
pNameActor->SetDisplayPosition(7, 6);
pNameGroup->AddPart(pNameActor);
}
pMarkerGroup->SetVisibility(m_bWellMarkersVisible ? 1 : 0);
pNameGroup->SetVisibility(m_bWellNamesVisible ? 1 : 0);
pSnapshotAssembly->AddPart(pMarkerGroup);
pSnapshotAssembly->AddPart(pNameGroup);
// 所有校验和 VTK 对象构造成功后才记录候选;活动子树仍未触碰。
m_pCandidateSnapshotAssembly = pSnapshotAssembly;
m_pCandidateMarkerGroup = pMarkerGroup;
m_pCandidateNameGroup = pNameGroup;
return true;
}
void nmPebiResultWellAnnotationLayer::discardCandidate()
{
Q_ASSERT(isWellAnnotationGuiThread());
m_pCandidateNameGroup = nullptr;
m_pCandidateMarkerGroup = nullptr;
m_pCandidateSnapshotAssembly = nullptr;
}
void nmPebiResultWellAnnotationLayer::commitCandidate()
{
Q_ASSERT(isWellAnnotationGuiThread());
Q_ASSERT(m_pCandidateSnapshotAssembly != nullptr);
if(m_pActiveSnapshotAssembly != nullptr) {
m_pRootAssembly->RemovePart(m_pActiveSnapshotAssembly);
}
m_pActiveSnapshotAssembly = m_pCandidateSnapshotAssembly;
m_pActiveMarkerGroup = m_pCandidateMarkerGroup;
m_pActiveNameGroup = m_pCandidateNameGroup;
m_pRootAssembly->AddPart(m_pActiveSnapshotAssembly);
discardCandidate();
}
void nmPebiResultWellAnnotationLayer::clear()
{
Q_ASSERT(isWellAnnotationGuiThread());
discardCandidate();
if(m_pRootAssembly != nullptr &&
m_pActiveSnapshotAssembly != nullptr) {
m_pRootAssembly->RemovePart(m_pActiveSnapshotAssembly);
}
m_pActiveNameGroup = nullptr;
m_pActiveMarkerGroup = nullptr;
m_pActiveSnapshotAssembly = nullptr;
}
bool nmPebiResultWellAnnotationLayer::hasActiveAnnotations() const
{
return m_pActiveSnapshotAssembly != nullptr;
}
void nmPebiResultWellAnnotationLayer::setWellMarkersVisible(bool bVisible)
{
Q_ASSERT(isWellAnnotationGuiThread());
if(!isWellAnnotationGuiThread()) {
return;
}
m_bWellMarkersVisible = bVisible;
if(m_pActiveMarkerGroup != nullptr) {
m_pActiveMarkerGroup->SetVisibility(bVisible ? 1 : 0);
}
if(m_pCandidateMarkerGroup != nullptr) {
m_pCandidateMarkerGroup->SetVisibility(bVisible ? 1 : 0);
}
}
void nmPebiResultWellAnnotationLayer::setWellNamesVisible(bool bVisible)
{
Q_ASSERT(isWellAnnotationGuiThread());
if(!isWellAnnotationGuiThread()) {
return;
}
m_bWellNamesVisible = bVisible;
if(m_pActiveNameGroup != nullptr) {
m_pActiveNameGroup->SetVisibility(bVisible ? 1 : 0);
}
if(m_pCandidateNameGroup != nullptr) {
m_pCandidateNameGroup->SetVisibility(bVisible ? 1 : 0);
}
}
bool nmPebiResultWellAnnotationLayer::areWellMarkersVisible() const
{
return m_bWellMarkersVisible;
}
bool nmPebiResultWellAnnotationLayer::areWellNamesVisible() const
{
return m_bWellNamesVisible;
}

@ -0,0 +1,484 @@
#include "nmWxPebiResultColorScaleSettingsDlg.h"
#include "nmPebiResultPropertyDisplayText.h"
#include "nmPebiResultSceneController.h"
#include "nmVTKColorMapCatalog.h"
#include <QCheckBox>
#include <QColorDialog>
#include <QComboBox>
#include <QCoreApplication>
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QHBoxLayout>
#include <QIcon>
#include <QLabel>
#include <QLineEdit>
#include <QLocale>
#include <QPushButton>
#include <QSize>
#include <QToolButton>
#include <QVariant>
#include <QVBoxLayout>
#include <QtGlobal>
#include <float.h>
#if !defined(_MSC_VER)
#include <cmath>
#endif
namespace {
/* Qt 4.8 lupdate 无法追踪按稳定 ID 选择的运行时色带名称,固定登记源文字。 */
static const char* const s_pColorDialogTranslationMarkers[] =
{
QT_TRANSLATE_NOOP("nmWxPebiResultColorScaleSettingsDlg", "Rainbow"),
QT_TRANSLATE_NOOP("nmWxPebiResultColorScaleSettingsDlg", "Oil saturation"),
QT_TRANSLATE_NOOP("nmWxPebiResultColorScaleSettingsDlg", "Gas saturation"),
QT_TRANSLATE_NOOP("nmWxPebiResultColorScaleSettingsDlg", "Water saturation")
};
// Qt 4.8 未统一提供 qIsFinite,解析后必须显式拒绝 NaN 和无穷值。
bool isFiniteEditorValue(double dValue)
{
#if defined(_MSC_VER)
return _finite(dValue) != 0;
#else
return std::isfinite(dValue);
#endif
}
QString colorMapDisplayName(const QString& sColorMapId)
{
Q_UNUSED(s_pColorDialogTranslationMarkers);
const char* pSourceText = "Rainbow";
if(sColorMapId == QString::fromLatin1("oil-saturation")) {
pSourceText = "Oil saturation";
} else if(sColorMapId == QString::fromLatin1("gas-saturation")) {
pSourceText = "Gas saturation";
} else if(sColorMapId == QString::fromLatin1("water-saturation")) {
pSourceText = "Water saturation";
}
return QCoreApplication::translate(
"nmWxPebiResultColorScaleSettingsDlg", pSourceText);
}
QString resultColorIconPath(const QString& sFileName)
{
const QString sApplicationDir = QCoreApplication::applicationDirPath();
return sApplicationDir.section('/', 0, -2) +
"/Res/Icon/" + sFileName;
}
}
nmWxPebiResultColorScaleSettingsDlg::
nmWxPebiResultColorScaleSettingsDlg(
nmPebiResultSceneController* pSceneController,
QWidget* pParent)
: QDialog(pParent),
m_pSceneController(pSceneController),
m_bManualRangeEdited(false),
m_bInitialized(false),
m_pColorMapCombo(nullptr),
m_pMinimumEdit(nullptr),
m_pMaximumEdit(nullptr),
m_pUnitLabel(nullptr),
m_pRestoreRangeButton(nullptr),
m_pLogarithmicCheck(nullptr),
m_pLogReasonLabel(nullptr),
m_pBelowRangeCheck(nullptr),
m_pBelowColorButton(nullptr),
m_pAboveRangeCheck(nullptr),
m_pAboveColorButton(nullptr),
m_pErrorLabel(nullptr),
m_pApplyButton(nullptr),
m_pOkButton(nullptr)
{
Q_ASSERT(m_pSceneController != nullptr);
m_dPropertyRange[0] = 0.0;
m_dPropertyRange[1] = 0.0;
createUi();
m_bInitialized = initializeFromScene();
m_pApplyButton->setEnabled(m_bInitialized);
m_pOkButton->setEnabled(m_bInitialized);
if(!m_bInitialized) {
setErrorText(tr("The result color settings are unavailable."));
}
}
nmWxPebiResultColorScaleSettingsDlg::
~nmWxPebiResultColorScaleSettingsDlg()
{
}
void nmWxPebiResultColorScaleSettingsDlg::onApplyClicked()
{
applyEditor();
}
void nmWxPebiResultColorScaleSettingsDlg::onOkClicked()
{
if(applyEditor()) {
accept();
}
}
void nmWxPebiResultColorScaleSettingsDlg::onRestorePropertyRangeClicked()
{
m_bManualRangeEdited = false;
m_pMinimumEdit->setText(formatValue(m_dPropertyRange[0]));
m_pMaximumEdit->setText(formatValue(m_dPropertyRange[1]));
refreshLogAvailability();
setErrorText(QString());
}
void nmWxPebiResultColorScaleSettingsDlg::onManualRangeEdited(
const QString& sText)
{
Q_UNUSED(sText);
m_bManualRangeEdited = true;
refreshLogAvailability();
}
void nmWxPebiResultColorScaleSettingsDlg::onBelowRangeToggled(bool bChecked)
{
m_pBelowColorButton->setEnabled(bChecked);
}
void nmWxPebiResultColorScaleSettingsDlg::onAboveRangeToggled(bool bChecked)
{
m_pAboveColorButton->setEnabled(bChecked);
}
void nmWxPebiResultColorScaleSettingsDlg::onChooseBelowRangeColor()
{
QColor oColor = QColorDialog::getColor(
m_oBaselineSettings.m_oBelowRangeColor, this,
tr("Below minimum color"));
if(oColor.isValid()) {
oColor.setAlpha(255);
m_oBaselineSettings.m_oBelowRangeColor = oColor;
updateColorButton(m_pBelowColorButton, oColor);
}
}
void nmWxPebiResultColorScaleSettingsDlg::onChooseAboveRangeColor()
{
QColor oColor = QColorDialog::getColor(
m_oBaselineSettings.m_oAboveRangeColor, this,
tr("Above maximum color"));
if(oColor.isValid()) {
oColor.setAlpha(255);
m_oBaselineSettings.m_oAboveRangeColor = oColor;
updateColorButton(m_pAboveColorButton, oColor);
}
}
void nmWxPebiResultColorScaleSettingsDlg::refreshLogAvailability()
{
double dMinimum = 0.0;
const bool bMinimumValid =
parseFiniteValue(m_pMinimumEdit->text(), dMinimum);
const bool bPropertyPositive = m_dPropertyRange[0] > 0.0;
const bool bDisplayPositive = bMinimumValid && dMinimum > 0.0;
const bool bAvailable = bPropertyPositive && bDisplayPositive;
if(!bAvailable && m_pLogarithmicCheck->isChecked()) {
// 禁用前先清除不可提交的 Log 状态,避免用户被锁在失败循环中。
const bool bSignalsBlocked =
m_pLogarithmicCheck->blockSignals(true);
m_pLogarithmicCheck->setChecked(false);
m_pLogarithmicCheck->blockSignals(bSignalsBlocked);
}
m_pLogarithmicCheck->setEnabled(bAvailable);
if(!bPropertyPositive) {
m_pLogReasonLabel->setText(
tr("Logarithmic scale requires a positive property range."));
} else if(!bDisplayPositive) {
m_pLogReasonLabel->setText(
tr("Logarithmic scale requires a positive minimum."));
} else {
m_pLogReasonLabel->clear();
}
}
void nmWxPebiResultColorScaleSettingsDlg::createUi()
{
setWindowTitle(tr("Color settings for current property"));
setModal(true);
m_pColorMapCombo = new QComboBox(this);
m_pColorMapCombo->setIconSize(QSize(128, 16));
m_pColorMapCombo->setMinimumWidth(260);
const QStringList listColorMapIds =
nmVTKColorMapCatalog::getColorMapIds();
for(int nIndex = 0; nIndex < listColorMapIds.size(); ++nIndex) {
const QString& sId = listColorMapIds[nIndex];
m_pColorMapCombo->addItem(
QIcon(nmVTKColorMapCatalog::createPreviewPixmap(
sId, QSize(128, 16))),
colorMapDisplayName(sId), sId);
}
m_pMinimumEdit = new QLineEdit(this);
m_pMaximumEdit = new QLineEdit(this);
m_pUnitLabel = new QLabel(this);
m_pMinimumEdit->setAlignment(Qt::AlignRight);
m_pMaximumEdit->setAlignment(Qt::AlignRight);
m_pRestoreRangeButton = new QToolButton(this);
m_pRestoreRangeButton->setAutoRaise(true);
m_pRestoreRangeButton->setFixedSize(24, 24);
m_pRestoreRangeButton->setIconSize(QSize(16, 16));
m_pRestoreRangeButton->setIcon(QIcon(resultColorIconPath(
QString::fromLatin1("Undo.png"))));
m_pRestoreRangeButton->setToolTip(tr("Restore property range"));
QHBoxLayout* pMinimumLayout = new QHBoxLayout();
pMinimumLayout->setContentsMargins(0, 0, 0, 0);
pMinimumLayout->addWidget(m_pMinimumEdit, 1);
pMinimumLayout->addWidget(m_pRestoreRangeButton);
QWidget* pMinimumWidget = new QWidget(this);
pMinimumWidget->setLayout(pMinimumLayout);
m_pLogarithmicCheck = new QCheckBox(tr("Logarithmic scale"), this);
m_pLogReasonLabel = new QLabel(this);
m_pLogReasonLabel->setWordWrap(true);
m_pLogReasonLabel->setStyleSheet(
QString::fromLatin1("color: #666666;"));
m_pBelowRangeCheck = new QCheckBox(tr("Below min"), this);
m_pBelowColorButton = new QPushButton(this);
m_pBelowColorButton->setFixedSize(44, 22);
QHBoxLayout* pBelowLayout = new QHBoxLayout();
pBelowLayout->setContentsMargins(0, 0, 0, 0);
pBelowLayout->addWidget(m_pBelowRangeCheck);
pBelowLayout->addWidget(m_pBelowColorButton);
pBelowLayout->addStretch();
QWidget* pBelowWidget = new QWidget(this);
pBelowWidget->setLayout(pBelowLayout);
m_pAboveRangeCheck = new QCheckBox(tr("Above max"), this);
m_pAboveColorButton = new QPushButton(this);
m_pAboveColorButton->setFixedSize(44, 22);
QHBoxLayout* pAboveLayout = new QHBoxLayout();
pAboveLayout->setContentsMargins(0, 0, 0, 0);
pAboveLayout->addWidget(m_pAboveRangeCheck);
pAboveLayout->addWidget(m_pAboveColorButton);
pAboveLayout->addStretch();
QWidget* pAboveWidget = new QWidget(this);
pAboveWidget->setLayout(pAboveLayout);
QFormLayout* pFormLayout = new QFormLayout();
pFormLayout->addRow(tr("Color map"), m_pColorMapCombo);
pFormLayout->addRow(tr("Minimum"), pMinimumWidget);
pFormLayout->addRow(tr("Maximum"), m_pMaximumEdit);
pFormLayout->addRow(tr("Unit"), m_pUnitLabel);
pFormLayout->addRow(QString(), m_pLogarithmicCheck);
pFormLayout->addRow(QString(), m_pLogReasonLabel);
pFormLayout->addRow(QString(), pBelowWidget);
pFormLayout->addRow(QString(), pAboveWidget);
m_pErrorLabel = new QLabel(this);
m_pErrorLabel->setWordWrap(true);
m_pErrorLabel->setStyleSheet(QString::fromLatin1("color: #b42318;"));
m_pErrorLabel->hide();
QDialogButtonBox* pButtonBox = new QDialogButtonBox(
QDialogButtonBox::Apply | QDialogButtonBox::Ok |
QDialogButtonBox::Cancel,
Qt::Horizontal, this);
m_pApplyButton = pButtonBox->button(QDialogButtonBox::Apply);
m_pOkButton = pButtonBox->button(QDialogButtonBox::Ok);
connect(m_pApplyButton, SIGNAL(clicked()),
this, SLOT(onApplyClicked()));
connect(m_pOkButton, SIGNAL(clicked()),
this, SLOT(onOkClicked()));
connect(pButtonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()),
this, SLOT(reject()));
QVBoxLayout* pMainLayout = new QVBoxLayout(this);
pMainLayout->addLayout(pFormLayout);
pMainLayout->addWidget(m_pErrorLabel);
pMainLayout->addWidget(pButtonBox);
setMinimumWidth(420);
connect(m_pRestoreRangeButton, SIGNAL(clicked()),
this, SLOT(onRestorePropertyRangeClicked()));
connect(m_pMinimumEdit, SIGNAL(textEdited(QString)),
this, SLOT(onManualRangeEdited(QString)));
connect(m_pMaximumEdit, SIGNAL(textEdited(QString)),
this, SLOT(onManualRangeEdited(QString)));
connect(m_pBelowRangeCheck, SIGNAL(toggled(bool)),
this, SLOT(onBelowRangeToggled(bool)));
connect(m_pAboveRangeCheck, SIGNAL(toggled(bool)),
this, SLOT(onAboveRangeToggled(bool)));
connect(m_pBelowColorButton, SIGNAL(clicked()),
this, SLOT(onChooseBelowRangeColor()));
connect(m_pAboveColorButton, SIGNAL(clicked()),
this, SLOT(onChooseAboveRangeColor()));
}
bool nmWxPebiResultColorScaleSettingsDlg::initializeFromScene()
{
if(m_pSceneController == nullptr || !m_pSceneController->hasSnapshot()) {
return false;
}
m_sExpectedSnapshotId = m_pSceneController->getCurrentSnapshotId();
m_sExpectedPropertyId = m_pSceneController->getCurrentPropertyId();
m_sDisplayUnit = nmPebiResultPropertyDisplayText::getDefaultDisplayUnit(
m_sExpectedPropertyId);
m_pUnitLabel->setText(m_sDisplayUnit.isEmpty()
? tr("Dimensionless") : m_sDisplayUnit);
double dVisibleRange[2] = { 0.0, 0.0 };
if(m_sExpectedSnapshotId.isEmpty() || m_sExpectedPropertyId.isEmpty() ||
!m_pSceneController->getCurrentPropertyRange(m_dPropertyRange) ||
!m_pSceneController->getCurrentDisplayRange(dVisibleRange) ||
!m_pSceneController->getCurrentDisplaySettings(
m_oBaselineSettings)) {
return false;
}
populateEditor(m_oBaselineSettings, dVisibleRange);
return true;
}
void nmWxPebiResultColorScaleSettingsDlg::populateEditor(
const nmPebiResultDisplaySettings& oSettings,
const double dVisibleRange[2])
{
const int nColorIndex = m_pColorMapCombo->findData(
oSettings.m_sColorMapId);
m_pColorMapCombo->setCurrentIndex(nColorIndex);
m_pMinimumEdit->setText(formatValue(dVisibleRange[0]));
m_pMaximumEdit->setText(formatValue(dVisibleRange[1]));
m_bManualRangeEdited = oSettings.m_bHasManualRange;
m_pLogarithmicCheck->setChecked(
oSettings.m_eScaleMode == NM_PebiColorScale_Logarithmic);
m_pBelowRangeCheck->setChecked(oSettings.m_bUseBelowRangeColor);
m_pAboveRangeCheck->setChecked(oSettings.m_bUseAboveRangeColor);
updateColorButton(m_pBelowColorButton, oSettings.m_oBelowRangeColor);
updateColorButton(m_pAboveColorButton, oSettings.m_oAboveRangeColor);
onBelowRangeToggled(oSettings.m_bUseBelowRangeColor);
onAboveRangeToggled(oSettings.m_bUseAboveRangeColor);
refreshLogAvailability();
const QString sUnitSuffix = m_sDisplayUnit.isEmpty()
? QString() : QString::fromLatin1(" (") +
m_sDisplayUnit + QString::fromLatin1(")");
m_pMinimumEdit->setToolTip(tr("Minimum") + sUnitSuffix);
m_pMaximumEdit->setToolTip(tr("Maximum") + sUnitSuffix);
}
bool nmWxPebiResultColorScaleSettingsDlg::collectEditedSettings(
nmPebiResultDisplaySettings& oSettings,
QString& sError) const
{
sError.clear();
double dMinimum = 0.0;
double dMaximum = 0.0;
if(!parseFiniteValue(m_pMinimumEdit->text(), dMinimum) ||
!parseFiniteValue(m_pMaximumEdit->text(), dMaximum)) {
sError = tr("Minimum and maximum must be finite numbers.");
return false;
}
// 提交值与界面最多 12 位有效数字保持一致,重复 Apply 不产生隐藏精度差异。
double dCanonicalMinimum = 0.0;
double dCanonicalMaximum = 0.0;
if(!parseFiniteValue(formatValue(dMinimum), dCanonicalMinimum) ||
!parseFiniteValue(formatValue(dMaximum), dCanonicalMaximum)) {
sError = tr("Minimum and maximum must be finite numbers.");
return false;
}
dMinimum = dCanonicalMinimum;
dMaximum = dCanonicalMaximum;
if(m_bManualRangeEdited && dMinimum >= dMaximum) {
sError = tr("Minimum must be less than maximum.");
return false;
}
oSettings = m_oBaselineSettings;
oSettings.m_sColorMapId =
m_pColorMapCombo->itemData(
m_pColorMapCombo->currentIndex()).toString();
oSettings.m_eScaleMode = m_pLogarithmicCheck->isChecked()
? NM_PebiColorScale_Logarithmic : NM_PebiColorScale_Linear;
oSettings.m_bHasManualRange = m_bManualRangeEdited;
oSettings.m_dManualMinimum = m_bManualRangeEdited ? dMinimum : 0.0;
oSettings.m_dManualMaximum = m_bManualRangeEdited ? dMaximum : 0.0;
oSettings.m_bUseBelowRangeColor = m_pBelowRangeCheck->isChecked();
oSettings.m_bUseAboveRangeColor = m_pAboveRangeCheck->isChecked();
oSettings.m_oBelowRangeColor.setAlpha(255);
oSettings.m_oAboveRangeColor.setAlpha(255);
return true;
}
bool nmWxPebiResultColorScaleSettingsDlg::applyEditor()
{
if(!m_bInitialized || m_pSceneController == nullptr) {
return false;
}
nmPebiResultDisplaySettings oSettings;
QString sError;
if(!collectEditedSettings(oSettings, sError) ||
!m_pSceneController->applyCurrentDisplaySettings(
m_sExpectedSnapshotId, m_sExpectedPropertyId,
oSettings, &sError)) {
setErrorText(sError);
emit operationFailed(sError);
return false;
}
double dVisibleRange[2] = { 0.0, 0.0 };
nmPebiResultDisplaySettings oCommittedSettings;
if(!m_pSceneController->getCurrentDisplaySettings(oCommittedSettings) ||
!m_pSceneController->getCurrentDisplayRange(dVisibleRange)) {
sError = tr("Unable to read the committed color settings.");
setErrorText(sError);
emit operationFailed(sError);
return false;
}
m_oBaselineSettings = oCommittedSettings;
populateEditor(oCommittedSettings, dVisibleRange);
setErrorText(QString());
emit displaySettingsApplied();
return true;
}
QString nmWxPebiResultColorScaleSettingsDlg::formatValue(double dValue) const
{
return QLocale::c().toString(dValue, 'g', 12);
}
bool nmWxPebiResultColorScaleSettingsDlg::parseFiniteValue(
const QString& sText,
double& dValue) const
{
bool bOk = false;
const double dCandidate = QLocale::c().toDouble(
sText.trimmed(), &bOk);
if(!bOk || !isFiniteEditorValue(dCandidate)) {
return false;
}
dValue = dCandidate;
return true;
}
void nmWxPebiResultColorScaleSettingsDlg::updateColorButton(
QPushButton* pButton,
const QColor& oColor)
{
if(pButton == nullptr || !oColor.isValid()) {
return;
}
pButton->setStyleSheet(QString::fromLatin1(
"QPushButton { background-color: rgb(%1,%2,%3); border: 1px solid #666; }")
.arg(oColor.red()).arg(oColor.green()).arg(oColor.blue()));
}
void nmWxPebiResultColorScaleSettingsDlg::setErrorText(
const QString& sError)
{
m_pErrorLabel->setText(sError);
m_pErrorLabel->setVisible(!sError.isEmpty());
}

@ -4,6 +4,8 @@
#include "nmPebiResultPropertyDisplayText.h"
#include "nmPebiResultSceneController.h"
#include "nmWxPebiResultAnimationSettingsDlg.h"
#include "nmWxPebiResultColorScaleSettingsDlg.h"
#include "nmVTKColorMapCatalog.h"
#include <QComboBox>
#include <QCoreApplication>
@ -43,7 +45,9 @@ nmWxPebiResultControlBar::nmWxPebiResultControlBar(
QWidget* pParent)
: QWidget(pParent),
m_pPlaybackController(nullptr),
m_pSceneController(pSceneController),
m_pPropertyCombo(nullptr),
m_pColorSettingsButton(nullptr),
m_pFirstButton(nullptr),
m_pPreviousButton(nullptr),
m_pTimeCombo(nullptr),
@ -111,6 +115,25 @@ void nmWxPebiResultControlBar::onTimeIndexChanged(int nIndex)
m_pTimeCombo->itemData(nIndex).toInt());
}
void nmWxPebiResultControlBar::onColorSettingsClicked()
{
if(m_pPlaybackController == nullptr || m_pSceneController == nullptr ||
!m_pSceneController->hasSnapshot()) {
return;
}
// 打开任何结果设置都属于手动操作;关闭后不自动恢复播放。
m_pPlaybackController->pause();
nmWxPebiResultColorScaleSettingsDlg oDialog(
m_pSceneController, this);
connect(&oDialog, SIGNAL(displaySettingsApplied()),
this, SLOT(refreshColorPreview()));
connect(&oDialog, SIGNAL(operationFailed(QString)),
this, SLOT(forwardOperationFailure(QString)));
oDialog.exec();
refreshColorPreview();
}
void nmWxPebiResultControlBar::onFirstFrameClicked()
{
m_pPlaybackController->selectFirstFrame();
@ -163,6 +186,8 @@ void nmWxPebiResultControlBar::refreshFromController()
m_sDisplayedSnapshotId.clear();
m_listDisplayedPropertyIds.clear();
m_pPropertyCombo->setEnabled(false);
m_pColorSettingsButton->setEnabled(false);
m_pColorSettingsButton->setIcon(QIcon());
m_pFirstButton->setEnabled(false);
m_pPreviousButton->setEnabled(false);
m_pNextButton->setEnabled(false);
@ -202,6 +227,8 @@ void nmWxPebiResultControlBar::refreshFromController()
m_pPropertyCombo->setCurrentIndex(nPropertyIndex);
m_pPropertyCombo->blockSignals(bPropertyBlocked);
m_pPropertyCombo->setEnabled(true);
m_pColorSettingsButton->setEnabled(true);
refreshColorPreview();
const bool bTimeDependent =
m_pPlaybackController->isPropertyTimeDependent(sPropertyId);
@ -255,6 +282,19 @@ void nmWxPebiResultControlBar::forwardOperationFailure(
emit operationFailed(sError);
}
void nmWxPebiResultControlBar::refreshColorPreview()
{
nmPebiResultDisplaySettings oSettings;
if(m_pSceneController == nullptr ||
!m_pSceneController->getCurrentDisplaySettings(oSettings)) {
m_pColorSettingsButton->setIcon(QIcon());
return;
}
m_pColorSettingsButton->setIcon(QIcon(
nmVTKColorMapCatalog::createPreviewPixmap(
oSettings.m_sColorMapId, QSize(44, 14))));
}
void nmWxPebiResultControlBar::createUi()
{
QHBoxLayout* pLayout = new QHBoxLayout(this);
@ -268,6 +308,11 @@ void nmWxPebiResultControlBar::createUi()
QSizePolicy::Preferred, QSizePolicy::Fixed);
m_pPropertyCombo->setToolTip(tr("Display property"));
m_pColorSettingsButton = createControlButton(
this, QString(), tr("Color settings"));
m_pColorSettingsButton->setFixedSize(52, 24);
m_pColorSettingsButton->setIconSize(QSize(44, 14));
m_pFirstButton = createControlButton(
this, QString::fromLatin1("First.png"), tr("First frame"));
m_pPreviousButton = createControlButton(
@ -289,6 +334,7 @@ void nmWxPebiResultControlBar::createUi()
tr("Animation settings"));
pLayout->addWidget(m_pPropertyCombo);
pLayout->addWidget(m_pColorSettingsButton);
pLayout->addWidget(m_pFirstButton);
pLayout->addWidget(m_pPreviousButton);
pLayout->addWidget(m_pTimeCombo, 1);
@ -299,6 +345,8 @@ void nmWxPebiResultControlBar::createUi()
connect(m_pPropertyCombo, SIGNAL(currentIndexChanged(int)),
this, SLOT(onPropertyIndexChanged(int)));
connect(m_pColorSettingsButton, SIGNAL(clicked()),
this, SLOT(onColorSettingsClicked()));
connect(m_pTimeCombo, SIGNAL(currentIndexChanged(int)),
this, SLOT(onTimeIndexChanged(int)));
connect(m_pFirstButton, SIGNAL(clicked()),

@ -16,6 +16,7 @@ include(../../vtk.pri)
INCLUDEPATH += $${wtInclude}/nmNum/nmRender
SOURCES += $${wtSrc}/nmNum/nmRender/nmVTKCameraController.cpp \
$${wtSrc}/nmNum/nmRender/nmVTKColorMapCatalog.cpp \
$${wtSrc}/nmNum/nmRender/nmVTKBoundsGridLayer.cpp \
$${wtSrc}/nmNum/nmRender/nmVTKImageExporter.cpp \
$${wtSrc}/nmNum/nmRender/nmVTKInteractionManager.cpp \
@ -33,6 +34,7 @@ SOURCES += $${wtSrc}/nmNum/nmRender/nmVTKCameraController.cpp \
HEADERS += $${wtInclude}/nmNum/nmRender/nmRender_global.h \
$${wtInclude}/nmNum/nmRender/nmVTKCameraController.h \
$${wtInclude}/nmNum/nmRender/nmVTKColorMapCatalog.h \
$${wtInclude}/nmNum/nmRender/nmVTKBoundsGridLayer.h \
$${wtInclude}/nmNum/nmRender/nmVTKImageExporter.h \
$${wtInclude}/nmNum/nmRender/nmVTKInteractionManager.h \

Loading…
Cancel
Save