diff --git a/Bin/Config/Lang/cn/nmNum_cn.qm b/Bin/Config/Lang/cn/nmNum_cn.qm index fe7f48bb..a2b8c22b 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 aeed24c5..d30a0533 100644 --- a/Bin/Config/Lang/cn/nmNum_cn.ts +++ b/Bin/Config/Lang/cn/nmNum_cn.ts @@ -3428,6 +3428,28 @@ No valid error was returned; keep the last accepted result and reduce the step.< Scale Grid比例网格 Well Names井名 Data Filtering...数据筛选... + Region Average Pressure区域平均压力 + Statistics统计结果 + Cancel Region Drawing取消区域绘制 + Switch to Top View or Isometric View before drawing a pressure region.请切换到顶视图或等轴视图后再绘制压力统计区域。 + Unable to start region pressure drawing.无法开始绘制压力统计区域。 + Draw a non-degenerate region with at least three points.请绘制一个至少包含三个点且非退化的区域。 + The displayed result changed while the region was drawn.绘制区域期间,当前显示结果已发生变化。 + Unable to prepare the selected pressure region.无法准备所选压力统计区域。 + Unable to calculate region pressure statistics.无法计算区域压力统计。 + Unable to preserve the selected pressure region.无法保留所选压力统计区域。 + Region average pressure区域平均压力 + Weighted by cell area, thickness and porosity.按单元面积、厚度和孔隙度加权。 + Minimum pressure压力下限 + Maximum pressure压力上限 + Pressure time压力时间 + Selected cells选中单元 + MPaMPa + Unable to calculate region average pressure.无法计算区域平均压力。 + No cells intersect the selected region.所选区域内没有相交单元。 + No valid cells are available for region average pressure.所选区域内没有可用于计算平均压力的有效单元。 + %1 selected cells were excluded because their data is invalid.有 %1 个选中单元因数据无效未参与统计。 + Close关闭 Unable to display the latest result.无法显示最新结果。 Unable to display the latest result: %1无法显示最新结果:%1 Current inputs have changed. Showing the last successful result.当前输入已修改,正在显示上一次成功求解的结果。 diff --git a/Include/nmNum/nmData/nmPebiRegionPressureCalculator.h b/Include/nmNum/nmData/nmPebiRegionPressureCalculator.h new file mode 100644 index 00000000..c21ae363 --- /dev/null +++ b/Include/nmNum/nmData/nmPebiRegionPressureCalculator.h @@ -0,0 +1,94 @@ +#ifndef NMPEBIREGIONPRESSURECALCULATOR_H +#define NMPEBIREGIONPRESSURECALCULATOR_H + +#include "nmData_global.h" + +#include +#include +#include +#include + +#include + +class nmPebiRegionPressureCalculatorPrivate; +class nmPebiResultSnapshot; + +/** + * @brief 一帧区域压力的孔隙体积加权统计结果。 + * + * 压力使用快照基础单位 MPa;面积和孔隙体积的单位分别为 m2 和 m3。 + * m_bAvailable 为 false 时,计数仍可用于解释没有有效加权结果的原因。 + */ +struct NM_DATA_EXPORT nmPebiRegionPressureStatistics +{ + /** @brief 初始化为空且不可用的统计结果。 */ + nmPebiRegionPressureStatistics(); + + /** @brief 清除所有计数和值,使对象恢复到默认状态。 */ + void clear(); + + bool m_bAvailable; ///< 是否存在至少一个可用于压力加权的有效单元。 + int m_nPressureFrameIndex; ///< 本结果对应的零基压力帧。 + double m_dPressureTimeHours; ///< 压力帧求解时间,单位 h。 + vtkIdType m_nIntersectingCellCount; ///< 与选区存在正面积交叠的二维单元数。 + vtkIdType m_nValidCellCount; ///< 实际参与本帧压力统计的单元数。 + vtkIdType m_nIgnoredCellCount; ///< 因权重或压力无效而忽略的相交单元数。 + double m_dSelectedCellAreaSquareMeters; ///< 相交单元完整面积之和,单位 m2。 + double m_dEffectivePoreVolumeCubicMeters; ///< 有效单元孔隙体积之和,单位 m3。 + double m_dMinimumPressureMpa; ///< 有效单元最小压力,单位 MPa。 + double m_dMaximumPressureMpa; ///< 有效单元最大压力,单位 MPa。 + double m_dPoreVolumeWeightedPressureMpa; ///< 孔隙体积加权压力,单位 MPa。 +}; + +/** + * @brief 在不可变 PEBI 快照上准备区域并逐帧计算压力统计。 + * + * 准备阶段基于基础网格执行真实二维多边形相交判定;只要交叠面积为正, + * 整个单元即被选中。相交基础 Cell ID、完整面积和 A*h*phi 权重会被缓存, + * 后续切帧只读取已缓存单元的压力,不依赖 Mapper 或显示筛选管线。 + */ +class NM_DATA_EXPORT nmPebiRegionPressureCalculator +{ +public: + /** @brief 创建尚未绑定快照和区域的计算器。 */ + nmPebiRegionPressureCalculator(); + /** @brief 释放快照强引用和全部区域缓存。 */ + ~nmPebiRegionPressureCalculator(); + + /** + * @brief 事务式准备一份简单二维多边形选区。 + * @param pSnapshot 只读结果快照,成功后由计算器保持强引用。 + * @param vecPolygonPoints 按边界顺序给出的 XY 世界坐标;首点无需重复。 + * @note 非有限、退化或自相交多边形会失败并保留旧区域缓存。 + */ + bool prepare( + const QSharedPointer& pSnapshot, + const QVector& vecPolygonPoints, + QString* pError = NULL); + + /** @brief 清除当前区域、快照引用和所有相交单元缓存。 */ + void clear(); + /** @brief 返回是否已经成功准备过一份快照区域。 */ + bool isPrepared() const; + /** @brief 返回当前区域所属快照 ID;未准备时为空。 */ + QString getSnapshotId() const; + /** @brief 返回规范化后的区域顶点,引用在下次 prepare 或 clear 前有效。 */ + const QVector& getPolygonPoints() const; + /** @brief 返回相交基础 VTK Cell ID,引用在下次 prepare 或 clear 前有效。 */ + const QVector& getIntersectingCellIds() const; + + /** + * @brief 使用缓存权重计算指定压力帧的最小、最大和加权平均值。 + * @note 无相交单元或无有效权重属于成功的不可用结果,不返回伪造的零压力。 + */ + bool calculateFrame(int nPressureFrameIndex, + nmPebiRegionPressureStatistics& oStatistics, + QString* pError = NULL) const; + +private: + Q_DISABLE_COPY(nmPebiRegionPressureCalculator) + + nmPebiRegionPressureCalculatorPrivate* m_pPrivate; ///< 独占区域缓存实现。 +}; + +#endif // NMPEBIREGIONPRESSURECALCULATOR_H diff --git a/Include/nmNum/nmData/nmPebiResultSnapshot.h b/Include/nmNum/nmData/nmPebiResultSnapshot.h index a7f59b7c..41cecfdd 100644 --- a/Include/nmNum/nmData/nmPebiResultSnapshot.h +++ b/Include/nmNum/nmData/nmPebiResultSnapshot.h @@ -16,6 +16,7 @@ class vtkDoubleArray; class vtkUnstructuredGrid; +class nmPebiRegionPressureCalculator; class nmPebiResultSnapshotBuilder; class nmPebiResultSnapshotRenderAdapter; class nmPebiResultSnapshotSerializer; @@ -392,7 +393,8 @@ private: /** @brief 求解时冻结的求解设置。 */ nmPebiResultSolverSettings m_oSolverSettings; - // 只有 Builder 和快照序列化器可以在发布前填充私有数据。 + // 只有发布构建、序列化和只读区域统计服务可访问私有快照数据。 + friend class nmPebiRegionPressureCalculator; friend class nmPebiResultSnapshotBuilder; friend class nmPebiResultSnapshotRenderAdapter; friend class nmPebiResultSnapshotSerializer; diff --git a/Include/nmNum/nmRender/nmVTKPlanarPolygonInteractorStyle.h b/Include/nmNum/nmRender/nmVTKPlanarPolygonInteractorStyle.h new file mode 100644 index 00000000..827b9589 --- /dev/null +++ b/Include/nmNum/nmRender/nmVTKPlanarPolygonInteractorStyle.h @@ -0,0 +1,77 @@ +#ifndef NMVTKPLANARPOLYGONINTERACTORSTYLE_H +#define NMVTKPLANARPOLYGONINTERACTORSTYLE_H + +#include "nmRender_global.h" + +#include +#include + +#include +#include + +/** + * @brief 在世界坐标 Z=0 平面逐点绘制多边形的临时 VTK 交互样式。 + * + * 本类不持有任何业务窗口或渲染图层。调用方通过 VTK Observer 监听点集变化、 + * 完成、取消和无效完成事件,并在回调中复制当前点集。样式不修改相机。 + */ +class NM_RENDER_EXPORT nmVTKPlanarPolygonInteractorStyle + : public vtkInteractorStyle +{ +public: + static nmVTKPlanarPolygonInteractorStyle* New(); + vtkTypeMacro(nmVTKPlanarPolygonInteractorStyle, vtkInteractorStyle); + + enum InteractionEvent + { + PolygonChangedEvent = vtkCommand::UserEvent + 310, + PolygonCompletedEvent, + PolygonCancelledEvent, + PolygonInvalidEvent + }; + + /** @brief 左键添加点;双击的第二次按下尝试完成当前多边形。 */ + virtual void OnLeftButtonDown(); + /** @brief 右键取消当前绘制。 */ + virtual void OnRightButtonDown(); + /** @brief Enter 完成、Backspace 撤销、Esc 取消。 */ + virtual void OnKeyPress(); + /** @brief 绘制期间屏蔽基类的退出、复位和拾取字符快捷键。 */ + virtual void OnChar(); + + /** @brief 清空节点并恢复未完成状态,不发出事件且不主动 Render。 */ + void reset(); + /** @brief 复制当前按绘制顺序保存的世界坐标点。 */ + QVector getPoints() const; + /** @brief 返回当前点数。 */ + int getPointCount() const; + /** @brief 返回是否已经成功发出完成事件。 */ + bool isCompleted() const; + +protected: + nmVTKPlanarPolygonInteractorStyle(); + virtual ~nmVTKPlanarPolygonInteractorStyle(); + +private: + nmVTKPlanarPolygonInteractorStyle( + const nmVTKPlanarPolygonInteractorStyle&); + void operator=(const nmVTKPlanarPolygonInteractorStyle&); + + /** @brief 把当前显示坐标射线与 Z=0 平面求交。 */ + bool projectEventPositionToPlane(QPointF& oPoint); + /** @brief 添加非重复有限点并同步发出变化事件。 */ + bool appendCurrentPoint(); + /** @brief 校验点数和面积,成功后依次发出变化及完成事件。 */ + bool completePolygon(); + /** @brief 撤销最后一个点并发出变化事件。 */ + void removeLastPoint(); + /** @brief 发出取消事件;点集保留到调用方回调结束。 */ + void cancelPolygon(); + /** @brief 请求 Interactor 重绘当前视图。 */ + void renderInteractor(); + + QVector m_vecPoints; ///< 当前候选多边形世界坐标。 + bool m_bCompleted; ///< 成功完成后阻止重复输入。 +}; + +#endif // NMVTKPLANARPOLYGONINTERACTORSTYLE_H diff --git a/Include/nmNum/nmRender/nmVTKPlanarPolygonLayer.h b/Include/nmNum/nmRender/nmVTKPlanarPolygonLayer.h new file mode 100644 index 00000000..c22485db --- /dev/null +++ b/Include/nmNum/nmRender/nmVTKPlanarPolygonLayer.h @@ -0,0 +1,47 @@ +#ifndef NMVTKPLANARPOLYGONLAYER_H +#define NMVTKPLANARPOLYGONLAYER_H + +#include "nmVTKRenderLayer.h" + +#include +#include + +class nmVTKPlanarPolygonLayerPrivate; + +/** + * @brief 在固定 XY 平面显示多边形绘制节点和折线的通用业务图层。 + * + * 图层不参与拾取和相机边界计算,也不主动触发 Render。调用方可以在绘制 + * 期间显示开放折线,在完成后显示闭合多边形。所有接口只能在 Qt GUI 线程调用。 + */ +class NM_RENDER_EXPORT nmVTKPlanarPolygonLayer + : public nmVTKRenderLayer +{ +public: + /** @brief 创建初始为空且可见的多边形图层。 */ + explicit nmVTKPlanarPolygonLayer(const QString& sLayerId); + /** @brief 释放独占的 PolyData、Mapper 和 Actor。 */ + virtual ~nmVTKPlanarPolygonLayer(); + + /** + * @brief 用有限 XY 点替换当前轮廓,不主动渲染。 + * @param vecPoints 按绘制顺序排列的世界坐标点。 + * @param bClosed 为 true 且至少有三个点时连接末点和首点。 + * @return 所有点有效且 VTK 几何更新成功时返回 true。 + */ + bool setPolygon(const QVector& vecPoints, bool bClosed); + + /** @brief 清空全部节点和线段,不主动渲染。 */ + void clear(); + /** @brief 返回当前保存的世界坐标点副本。 */ + QVector getPoints() const; + /** @brief 返回当前是否以闭合多边形显示。 */ + bool isClosed() const; + +private: + Q_DISABLE_COPY(nmVTKPlanarPolygonLayer) + + nmVTKPlanarPolygonLayerPrivate* m_pPrivate; ///< 独占实现对象。 +}; + +#endif // NMVTKPLANARPOLYGONLAYER_H diff --git a/Include/nmNum/nmRender/nmVTKViewCommandController.h b/Include/nmNum/nmRender/nmVTKViewCommandController.h index 7d09ef8a..4f396a06 100644 --- a/Include/nmNum/nmRender/nmVTKViewCommandController.h +++ b/Include/nmNum/nmRender/nmVTKViewCommandController.h @@ -83,6 +83,8 @@ private: void setCapabilities(ViewCommands eCommands); /** @brief 仅供容器同步就绪、空、错误和加载状态。 */ void setViewAvailable(bool bAvailable); + /** @brief 仅供容器在临时交互期间统一锁定全部公共命令。 */ + void setInteractionCommandsAvailable(bool bAvailable); QAction* createAction(ViewCommand eCommand, const QString& sText, const QString& sIconFile, @@ -101,6 +103,7 @@ private: QAction* m_pActions[ViewCommandCount]; ///< 本对象通过 Qt 父子关系拥有。 ViewCommands m_eCapabilities; bool m_bViewAvailable; + bool m_bInteractionCommandsAvailable; ///< 默认交互活动时公共命令才可用。 bool m_bRotationCenterPickingAvailable; bool m_bRotationCenterMarkerAvailable; ///< 标记开关当前是否具备操作条件。 }; diff --git a/Include/nmNum/nmSubWxs/nmWxPebiResultControlBar.h b/Include/nmNum/nmSubWxs/nmWxPebiResultControlBar.h index 99d965e3..617c0d66 100644 --- a/Include/nmNum/nmSubWxs/nmWxPebiResultControlBar.h +++ b/Include/nmNum/nmSubWxs/nmWxPebiResultControlBar.h @@ -49,6 +49,13 @@ public: void setExportInProgress(bool bInProgress); /** @brief 返回同步动画导出是否正在占用结果控制条。 */ bool isExportInProgress() const; + /** + * @brief 设置业务绘制等外部交互是否锁定全部结果身份控件。 + * @note 进入锁定时会停止正在运行的回放;解除后按 Scene 当前状态恢复。 + */ + void setExternalInteractionLocked(bool bLocked); + /** @brief 返回区域绘制等外部交互是否正在锁定控制条。 */ + bool isExternalInteractionLocked() const; signals: /** @brief 一次明确的用户操作已经成功提交,供组合窗口清除旧普通错误。 */ @@ -135,6 +142,8 @@ private: QToolButton* m_pExportButton; /** @brief 当前窗口是否正在执行参数选择、编码或文件发布事务。 */ bool m_bExportInProgress; + /** @brief 区域绘制等外部业务交互是否正在冻结结果身份。 */ + bool m_bExternalInteractionLocked; /** @brief 当前属性项对应的 Snapshot ID,仅用于避免重复重建 UI。 */ QString m_sDisplayedSnapshotId; /** @brief 属性和时间列表最近一次完整展示的 Scene 成功绑定序号。 */ diff --git a/Include/nmNum/nmSubWxs/nmWxPebiResultViewWidget.h b/Include/nmNum/nmSubWxs/nmWxPebiResultViewWidget.h index b69f3fdb..de631f7e 100644 --- a/Include/nmNum/nmSubWxs/nmWxPebiResultViewWidget.h +++ b/Include/nmNum/nmSubWxs/nmWxPebiResultViewWidget.h @@ -22,10 +22,12 @@ class QToolBar; class iUnitGroup; class nmDataAnalyzeManager; +class nmWxPebiResultRegionState; class nmPebiResultSceneController; class nmPebiResultSnapshot; class nmWxPebiResultControlBar; class nmWxVTKRenderContainerWidget; +class vtkObject; /** @brief 编辑并原子提交当前结果窗口的独立单元筛选条件。 */ class NM_SUB_WXS_EXPORT nmWxPebiResultFilterSettingsDlg : public iDlgBase @@ -142,7 +144,14 @@ private slots: void onExportAnimationRequested(); /** @brief 在播放和导出状态防御后打开数据筛选对话框。 */ void onShowFilterSettings(); - + /** @brief 开始、取消区域压力绘制,或重新显示既有统计面板。 */ + void onRegionPressureStatisticsTriggered(); + /** @brief 在 VTK 观察者返回后安全处理完成、取消或无效绘制事件。 */ + void processPendingRegionInteractionEvent(); + /** @brief 同步业务动作并按当前 pressure 帧至多重算一次区域统计。 */ + void onResultDisplayStateChanged(); + /** @brief 关闭面板并清除区域、统计缓存和闭合轮廓。 */ + void onCloseRegionPressureStatistics(); /** @brief 切换色标显隐。 */ void onScalarBarToggled(bool bVisible); /** @brief 切换比例网格显隐。 */ @@ -170,6 +179,31 @@ private: void refreshStatusBar(); /** @brief 断开当前 Manager 的两个连接,不访问已经析构的对象。 */ void disconnectDataManager(); + /** @brief 创建区域图层和临时交互样式,并冻结当前 pressure 显示身份。 */ + bool startRegionPressureDrawing(); + /** @brief 解除临时交互、观察者和控制条锁,不修改已准备的统计区域。 */ + void stopRegionPressureDrawing(); + /** @brief 清除区域计算与轮廓,可选择提交一次画面刷新。 */ + void clearRegionPressureSelection(bool bRenderView); + /** @brief 移除区域图层和面板,供析构在其他渲染对象之前安全收尾。 */ + void destroyRegionPressureState(); + /** @brief 确保业务 Scene 中存在本窗口独占的区域轮廓图层。 */ + bool ensureRegionPressureLayer(); + /** @brief 按当前 pressure 帧刷新缓存和面板,相同帧不重复计算。 */ + void updateRegionPressureStatistics(); + /** @brief 首次需要时创建非模态区域统计面板。 */ + void ensureRegionPressureStatisticsDialog(); + /** @brief 从最近一次统计结果刷新面板文字,不改变面板显隐。 */ + void refreshRegionPressureStatisticsDialog(); + /** @brief 显示、前置并激活已经创建的区域统计面板。 */ + void showRegionPressureStatisticsDialog(); + /** @brief 返回当前是否仍处于多边形绘制事务。 */ + bool isRegionPressureDrawing() const; + /** @brief 将 VTK 多边形事件复制到窗口状态并排队到 Qt 事件循环。 */ + static void handleRegionPolygonEvent(vtkObject* pCaller, + unsigned long nEventId, + void* pClientData, + void* pCallData); QPointer m_pDataManager; ///< 当前显式注入的 Manager。 nmWxVTKRenderContainerWidget* m_pRenderContainer; ///< 唯一通用 VTK 容器。 @@ -182,6 +216,9 @@ private: QAction* m_pScaleGridAction; ///< 比例网格显隐动作。 QAction* m_pWellNamesAction; ///< 二维井名显隐动作。 QAction* m_pFilterAction; ///< 打开数据筛选设置的共享动作。 + QAction* m_pRegionPressureAction; ///< 绘制区域或显示压力统计的共享动作。 + + nmWxPebiResultRegionState* m_pRegionState; ///< 独占区域交互、计算和面板状态。 /** @brief Manager 最近一次通知后观察到的快照强引用。 */ QSharedPointer m_pObservedSnapshot; diff --git a/Src/nmNum/nmData/nmPebiRegionPressureCalculator.cpp b/Src/nmNum/nmData/nmPebiRegionPressureCalculator.cpp new file mode 100644 index 00000000..8e42c0c7 --- /dev/null +++ b/Src/nmNum/nmData/nmPebiRegionPressureCalculator.cpp @@ -0,0 +1,774 @@ +#include "nmPebiRegionPressureCalculator.h" + +#include "nmPebiResultSnapshot.h" + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#if !defined(_MSC_VER) +#include +#endif + +namespace { + +// 所有区域统计几何均投影到 XY 平面,三角形是剪裁和求交的最小单元。 +struct Triangle2D +{ + QPointF m_a; + QPointF m_b; + QPointF m_c; +}; + +struct PreparedPolygon +{ + QVector m_vecPoints; + QVector m_vecTriangles; + QRectF m_oBounds; + double m_dArea; +}; + +struct CachedCell +{ + CachedCell() + : m_nCellId(-1), + m_dArea(0.0), + m_dPoreVolumeWeight(0.0), + m_bWeightValid(false) + { + } + + vtkIdType m_nCellId; + double m_dArea; + double m_dPoreVolumeWeight; + bool m_bWeightValid; +}; + +bool isFiniteValue(double dValue) +{ +#if defined(_MSC_VER) + return _finite(dValue) != 0; +#else + return std::isfinite(dValue); +#endif +} + +double crossProduct(const QPointF& a, + const QPointF& b, + const QPointF& c) +{ + return (b.x() - a.x()) * (c.y() - a.y()) - + (b.y() - a.y()) * (c.x() - a.x()); +} + +double squaredDistance(const QPointF& a, const QPointF& b) +{ + const double dX = a.x() - b.x(); + const double dY = a.y() - b.y(); + return dX * dX + dY * dY; +} + +double signedDoubleArea(const QVector& vecPoints) +{ + if(vecPoints.size() < 3) { + return 0.0; + } + + // 先平移到首点附近再做鞋带求和,避免大地坐标中的大数相减吞掉小区域面积。 + const QPointF oOrigin = vecPoints.first(); + double dArea = 0.0; + for(int nIndex = 0; nIndex < vecPoints.size(); ++nIndex) { + const QPointF& a = vecPoints[nIndex]; + const QPointF& b = vecPoints[(nIndex + 1) % vecPoints.size()]; + const double dAx = a.x() - oOrigin.x(); + const double dAy = a.y() - oOrigin.y(); + const double dBx = b.x() - oOrigin.x(); + const double dBy = b.y() - oOrigin.y(); + dArea += dAx * dBy - dBx * dAy; + } + return dArea; +} + +QRectF polygonBounds(const QVector& vecPoints) +{ + double dMinimumX = vecPoints[0].x(); + double dMaximumX = dMinimumX; + double dMinimumY = vecPoints[0].y(); + double dMaximumY = dMinimumY; + for(int nIndex = 1; nIndex < vecPoints.size(); ++nIndex) { + dMinimumX = qMin(dMinimumX, vecPoints[nIndex].x()); + dMaximumX = qMax(dMaximumX, vecPoints[nIndex].x()); + dMinimumY = qMin(dMinimumY, vecPoints[nIndex].y()); + dMaximumY = qMax(dMaximumY, vecPoints[nIndex].y()); + } + return QRectF(QPointF(dMinimumX, dMinimumY), + QPointF(dMaximumX, dMaximumY)); +} + +bool pointOnSegment(const QPointF& p, + const QPointF& a, + const QPointF& b, + double dLinearTolerance, + double dAreaTolerance) +{ + if(qAbs(crossProduct(a, b, p)) > dAreaTolerance) { + return false; + } + return p.x() >= qMin(a.x(), b.x()) - dLinearTolerance && + p.x() <= qMax(a.x(), b.x()) + dLinearTolerance && + p.y() >= qMin(a.y(), b.y()) - dLinearTolerance && + p.y() <= qMax(a.y(), b.y()) + dLinearTolerance; +} + +int orientationSign(const QPointF& a, + const QPointF& b, + const QPointF& c, + double dAreaTolerance) +{ + const double dCross = crossProduct(a, b, c); + if(dCross > dAreaTolerance) { + return 1; + } + if(dCross < -dAreaTolerance) { + return -1; + } + return 0; +} + +bool segmentsIntersect(const QPointF& a, + const QPointF& b, + const QPointF& c, + const QPointF& d, + double dLinearTolerance, + double dAreaTolerance) +{ + const int nAbC = orientationSign(a, b, c, dAreaTolerance); + const int nAbD = orientationSign(a, b, d, dAreaTolerance); + const int nCdA = orientationSign(c, d, a, dAreaTolerance); + const int nCdB = orientationSign(c, d, b, dAreaTolerance); + if(nAbC * nAbD < 0 && nCdA * nCdB < 0) { + return true; + } + return (nAbC == 0 && pointOnSegment(c, a, b, + dLinearTolerance, dAreaTolerance)) || + (nAbD == 0 && pointOnSegment(d, a, b, + dLinearTolerance, dAreaTolerance)) || + (nCdA == 0 && pointOnSegment(a, c, d, + dLinearTolerance, dAreaTolerance)) || + (nCdB == 0 && pointOnSegment(b, c, d, + dLinearTolerance, dAreaTolerance)); +} + +bool isSimplePolygon(const QVector& vecPoints, + double dLinearTolerance, + double dAreaTolerance) +{ + // 只检查非相邻边;相邻边共享端点是合法多边形的必要条件。 + const int nPointCount = vecPoints.size(); + for(int nFirst = 0; nFirst < nPointCount; ++nFirst) { + const int nFirstNext = (nFirst + 1) % nPointCount; + for(int nSecond = nFirst + 1; nSecond < nPointCount; ++nSecond) { + const int nSecondNext = (nSecond + 1) % nPointCount; + if(nFirst == nSecond || nFirstNext == nSecond || + nSecondNext == nFirst) { + continue; + } + if(segmentsIntersect(vecPoints[nFirst], vecPoints[nFirstNext], + vecPoints[nSecond], vecPoints[nSecondNext], + dLinearTolerance, dAreaTolerance)) { + return false; + } + } + } + return true; +} + +bool pointInsideTriangle(const QPointF& p, + const QPointF& a, + const QPointF& b, + const QPointF& c, + double dAreaTolerance) +{ + return crossProduct(a, b, p) >= -dAreaTolerance && + crossProduct(b, c, p) >= -dAreaTolerance && + crossProduct(c, a, p) >= -dAreaTolerance; +} + +bool triangulatePolygon(const QVector& vecPoints, + double dAreaTolerance, + QVector& vecTriangles) +{ + // 耳切法同时支持凸、凹简单多边形,无需依赖 VTK 的三维三角化管线。 + vecTriangles.clear(); + QVector vecIndices; + for(int nIndex = 0; nIndex < vecPoints.size(); ++nIndex) { + vecIndices.append(nIndex); + } + + while(vecIndices.size() > 3) { + bool bEarFound = false; + for(int nPosition = 0; nPosition < vecIndices.size(); ++nPosition) { + const int nPrevious = vecIndices[ + (nPosition + vecIndices.size() - 1) % vecIndices.size()]; + const int nCurrent = vecIndices[nPosition]; + const int nNext = vecIndices[(nPosition + 1) % vecIndices.size()]; + const QPointF& a = vecPoints[nPrevious]; + const QPointF& b = vecPoints[nCurrent]; + const QPointF& c = vecPoints[nNext]; + if(crossProduct(a, b, c) <= dAreaTolerance) { + continue; + } + + bool bContainsOtherPoint = false; + for(int nOtherPosition = 0; + nOtherPosition < vecIndices.size(); ++nOtherPosition) { + const int nOther = vecIndices[nOtherPosition]; + if(nOther == nPrevious || nOther == nCurrent || + nOther == nNext) { + continue; + } + if(pointInsideTriangle(vecPoints[nOther], a, b, c, + dAreaTolerance)) { + bContainsOtherPoint = true; + break; + } + } + if(bContainsOtherPoint) { + continue; + } + + Triangle2D oTriangle; + oTriangle.m_a = a; + oTriangle.m_b = b; + oTriangle.m_c = c; + vecTriangles.append(oTriangle); + vecIndices.remove(nPosition); + bEarFound = true; + break; + } + if(!bEarFound) { + vecTriangles.clear(); + return false; + } + } + + if(vecIndices.size() != 3) { + vecTriangles.clear(); + return false; + } + Triangle2D oTriangle; + oTriangle.m_a = vecPoints[vecIndices[0]]; + oTriangle.m_b = vecPoints[vecIndices[1]]; + oTriangle.m_c = vecPoints[vecIndices[2]]; + if(crossProduct(oTriangle.m_a, oTriangle.m_b, oTriangle.m_c) <= + dAreaTolerance) { + vecTriangles.clear(); + return false; + } + vecTriangles.append(oTriangle); + return true; +} + +bool preparePolygon(const QVector& vecInput, + PreparedPolygon& oPolygon) +{ + oPolygon = PreparedPolygon(); + if(vecInput.size() < 3) { + return false; + } + for(int nIndex = 0; nIndex < vecInput.size(); ++nIndex) { + if(!isFiniteValue(vecInput[nIndex].x()) || + !isFiniteValue(vecInput[nIndex].y())) { + return false; + } + } + + // 容差跟随当前多边形尺度,兼容小尺寸网格和大地坐标。 + const QRectF oInputBounds = polygonBounds(vecInput); + const double dScale = qMax(1.0, qMax(oInputBounds.width(), + oInputBounds.height())); + const double dLinearTolerance = dScale * 1.0e-10; + const double dAreaTolerance = dScale * dScale * 1.0e-12; + const double dSquaredTolerance = + dLinearTolerance * dLinearTolerance; + + // 先去掉相邻重复点及显式闭合点,避免产生零长边。 + QVector vecPoints; + for(int nIndex = 0; nIndex < vecInput.size(); ++nIndex) { + if(vecPoints.isEmpty() || + squaredDistance(vecPoints.last(), vecInput[nIndex]) > + dSquaredTolerance) { + vecPoints.append(vecInput[nIndex]); + } + } + if(vecPoints.size() > 1 && + squaredDistance(vecPoints.first(), vecPoints.last()) <= + dSquaredTolerance) { + vecPoints.remove(vecPoints.size() - 1); + } + + // 反复清理共线中间点,直到点集稳定,降低耳切法退化风险。 + bool bRemovedPoint = true; + while(bRemovedPoint && vecPoints.size() >= 3) { + bRemovedPoint = false; + for(int nIndex = 0; nIndex < vecPoints.size(); ++nIndex) { + const QPointF& a = vecPoints[ + (nIndex + vecPoints.size() - 1) % vecPoints.size()]; + const QPointF& p = vecPoints[nIndex]; + const QPointF& b = vecPoints[(nIndex + 1) % vecPoints.size()]; + if(pointOnSegment(p, a, b, + dLinearTolerance, dAreaTolerance)) { + vecPoints.remove(nIndex); + bRemovedPoint = true; + break; + } + } + } + if(vecPoints.size() < 3 || + !isSimplePolygon(vecPoints, + dLinearTolerance, dAreaTolerance)) { + return false; + } + + double dDoubleArea = signedDoubleArea(vecPoints); + if(!isFiniteValue(dDoubleArea) || + qAbs(dDoubleArea) <= dAreaTolerance) { + return false; + } + // 后续半平面剪裁约定顶点为逆时针顺序。 + if(dDoubleArea < 0.0) { + std::reverse(vecPoints.begin(), vecPoints.end()); + dDoubleArea = -dDoubleArea; + } + + QVector vecTriangles; + if(!triangulatePolygon(vecPoints, + dAreaTolerance, vecTriangles)) { + return false; + } + oPolygon.m_vecPoints = vecPoints; + oPolygon.m_vecTriangles = vecTriangles; + oPolygon.m_oBounds = polygonBounds(vecPoints); + oPolygon.m_dArea = dDoubleArea * 0.5; + return isFiniteValue(oPolygon.m_dArea) && oPolygon.m_dArea > 0.0; +} + +QPointF segmentLineIntersection(const QPointF& s, + const QPointF& e, + double dStartDistance, + double dEndDistance) +{ + const double dDenominator = dStartDistance - dEndDistance; + const double dT = dDenominator == 0.0 + ? 0.0 : dStartDistance / dDenominator; + return QPointF(s.x() + dT * (e.x() - s.x()), + s.y() + dT * (e.y() - s.y())); +} + +QVector clipByEdge(const QVector& vecSubject, + const QPointF& a, + const QPointF& b, + double dAreaTolerance) +{ + // Sutherland-Hodgman 半平面剪裁,裁剪边左侧视为三角形内部。 + QVector vecOutput; + if(vecSubject.isEmpty()) { + return vecOutput; + } + QPointF s = vecSubject.last(); + double dStartDistance = crossProduct(a, b, s); + bool bStartInside = dStartDistance >= -dAreaTolerance; + for(int nIndex = 0; nIndex < vecSubject.size(); ++nIndex) { + const QPointF e = vecSubject[nIndex]; + const double dEndDistance = crossProduct(a, b, e); + const bool bEndInside = dEndDistance >= -dAreaTolerance; + if(bEndInside) { + if(!bStartInside) { + vecOutput.append(segmentLineIntersection( + s, e, dStartDistance, dEndDistance)); + } + vecOutput.append(e); + } else if(bStartInside) { + vecOutput.append(segmentLineIntersection( + s, e, dStartDistance, dEndDistance)); + } + s = e; + dStartDistance = dEndDistance; + bStartInside = bEndInside; + } + return vecOutput; +} + +double triangleIntersectionArea(const Triangle2D& oSubject, + const Triangle2D& oClip, + double dAreaTolerance) +{ + QVector vecClipped; + vecClipped.append(oSubject.m_a); + vecClipped.append(oSubject.m_b); + vecClipped.append(oSubject.m_c); + vecClipped = clipByEdge(vecClipped, + oClip.m_a, oClip.m_b, dAreaTolerance); + vecClipped = clipByEdge(vecClipped, + oClip.m_b, oClip.m_c, dAreaTolerance); + vecClipped = clipByEdge(vecClipped, + oClip.m_c, oClip.m_a, dAreaTolerance); + return vecClipped.size() >= 3 + ? qAbs(signedDoubleArea(vecClipped)) * 0.5 : 0.0; +} + +bool rectanglesOverlap(const QRectF& a, + const QRectF& b, + double dTolerance) +{ + return a.right() >= b.left() - dTolerance && + b.right() >= a.left() - dTolerance && + a.bottom() >= b.top() - dTolerance && + b.bottom() >= a.top() - dTolerance; +} + +bool polygonsHavePositiveAreaIntersection( + const PreparedPolygon& a, + const PreparedPolygon& b) +{ + // 业务语义是“面积相交”:仅边界或顶点接触不把单元纳入统计。 + const double dFirstScale = + qMax(a.m_oBounds.width(), a.m_oBounds.height()); + const double dSecondScale = + qMax(b.m_oBounds.width(), b.m_oBounds.height()); + // 交叠容差跟随较小多边形,避免大选区吞掉小单元的真实窄交叠。 + const double dScale = qMax(1.0, qMin(dFirstScale, dSecondScale)); + const double dLinearTolerance = dScale * 1.0e-10; + if(!rectanglesOverlap(a.m_oBounds, b.m_oBounds, + dLinearTolerance)) { + return false; + } + const double dAreaTolerance = dScale * dScale * 1.0e-13; + const double dPositiveAreaThreshold = qMax( + dAreaTolerance, + qMin(a.m_dArea, b.m_dArea) * 1.0e-12); + for(int nA = 0; nA < a.m_vecTriangles.size(); ++nA) { + for(int nB = 0; nB < b.m_vecTriangles.size(); ++nB) { + if(triangleIntersectionArea( + a.m_vecTriangles[nA], b.m_vecTriangles[nB], + dAreaTolerance) > dPositiveAreaThreshold) { + return true; + } + } + } + return false; +} + +bool readCellPolygon(vtkCell* pCell, + QVector& vecPoints) +{ + // 当前 PEBI 结果只接受可直接解释为平面多边形的单元类型。 + vecPoints.clear(); + if(pCell == NULL || + (pCell->GetCellType() != VTK_TRIANGLE && + pCell->GetCellType() != VTK_QUAD && + pCell->GetCellType() != VTK_POLYGON) || + pCell->GetPoints() == NULL || + pCell->GetNumberOfPoints() < 3) { + return false; + } + double aPoint[3] = { 0.0, 0.0, 0.0 }; + for(vtkIdType nPointIndex = 0; + nPointIndex < pCell->GetNumberOfPoints(); ++nPointIndex) { + pCell->GetPoints()->GetPoint(nPointIndex, aPoint); + if(!isFiniteValue(aPoint[0]) || !isFiniteValue(aPoint[1])) { + vecPoints.clear(); + return false; + } + vecPoints.append(QPointF(aPoint[0], aPoint[1])); + } + return true; +} + +void addCompensated(double dValue, + double& dSum, + double& dCorrection) +{ + // Kahan 补偿求和用于缓解单元数量较多或权重差异较大时的累计误差。 + const double dAdjusted = dValue - dCorrection; + const double dCandidate = dSum + dAdjusted; + dCorrection = (dCandidate - dSum) - dAdjusted; + dSum = dCandidate; +} + +} + +class nmPebiRegionPressureCalculatorPrivate +{ +public: + nmPebiRegionPressureCalculatorPrivate() + : m_bPrepared(false), + m_dSelectedCellArea(0.0) + { + } + + bool m_bPrepared; + QSharedPointer m_pSnapshot; + QVector m_vecPolygonPoints; + QVector m_vecIntersectingCellIds; + QVector m_vecCells; + double m_dSelectedCellArea; +}; + +nmPebiRegionPressureStatistics::nmPebiRegionPressureStatistics() +{ + clear(); +} + +void nmPebiRegionPressureStatistics::clear() +{ + m_bAvailable = false; + m_nPressureFrameIndex = -1; + m_dPressureTimeHours = 0.0; + m_nIntersectingCellCount = 0; + m_nValidCellCount = 0; + m_nIgnoredCellCount = 0; + m_dSelectedCellAreaSquareMeters = 0.0; + m_dEffectivePoreVolumeCubicMeters = 0.0; + m_dMinimumPressureMpa = 0.0; + m_dMaximumPressureMpa = 0.0; + m_dPoreVolumeWeightedPressureMpa = 0.0; +} + +nmPebiRegionPressureCalculator::nmPebiRegionPressureCalculator() + : m_pPrivate(new nmPebiRegionPressureCalculatorPrivate) +{ +} + +nmPebiRegionPressureCalculator::~nmPebiRegionPressureCalculator() +{ + delete m_pPrivate; + m_pPrivate = NULL; +} + +bool nmPebiRegionPressureCalculator::prepare( + const QSharedPointer& pSnapshot, + const QVector& vecPolygonPoints, + QString* pError) +{ + if(pError != NULL) { + pError->clear(); + } + const vtkIdType nCellCount = pSnapshot.isNull() + ? 0 : pSnapshot->getResultCellCount(); + if(m_pPrivate == NULL || pSnapshot.isNull() || + !pSnapshot->m_bComplete || pSnapshot->m_pResultGrid == NULL || + nCellCount <= 0 || pSnapshot->m_pPorosity == NULL || + pSnapshot->m_pThickness == NULL || + pSnapshot->m_pPorosity->GetNumberOfComponents() != 1 || + pSnapshot->m_pThickness->GetNumberOfComponents() != 1 || + pSnapshot->m_pPorosity->GetNumberOfTuples() != nCellCount || + pSnapshot->m_pThickness->GetNumberOfTuples() != nCellCount || + pSnapshot->m_vecPressureFrames.isEmpty()) { + if(pError != NULL) { + *pError = QString::fromLatin1( + "The PEBI result snapshot is invalid."); + } + return false; + } + + PreparedPolygon oSelection; + if(!preparePolygon(vecPolygonPoints, oSelection)) { + if(pError != NULL) { + *pError = QString::fromLatin1( + "The region polygon is invalid or self-intersecting."); + } + return false; + } + + // 先在候选状态中完成全部校验和缓存,失败时不破坏上一个可用区域。 + nmPebiRegionPressureCalculatorPrivate oCandidate; + oCandidate.m_pSnapshot = pSnapshot; + oCandidate.m_vecPolygonPoints = oSelection.m_vecPoints; + + vtkUnstructuredGrid* pGrid = pSnapshot->m_pResultGrid; + QVector vecCellPoints; + double dAreaCorrection = 0.0; + for(vtkIdType nCellId = 0; + nCellId < pGrid->GetNumberOfCells(); ++nCellId) { + vtkCell* pCell = pGrid->GetCell(nCellId); + if(!readCellPolygon(pCell, vecCellPoints)) { + continue; + } + PreparedPolygon oCellPolygon; + if(!preparePolygon(vecCellPoints, oCellPolygon) || + !polygonsHavePositiveAreaIntersection( + oSelection, oCellPolygon)) { + continue; + } + + CachedCell oCell; + oCell.m_nCellId = nCellId; + // 选中规则是“有正面积相交即纳入”,纳入后使用整个单元面积计算孔隙体积权重。 + oCell.m_dArea = oCellPolygon.m_dArea; + const double dPorosity = + pSnapshot->m_pPorosity->GetValue(nCellId); + const double dThickness = + pSnapshot->m_pThickness->GetValue(nCellId); + const double dWeight = oCell.m_dArea * dThickness * dPorosity; + // 几何相交单元保留在计数中;非法物性只在压力统计时被忽略。 + oCell.m_bWeightValid = isFiniteValue(dPorosity) && + isFiniteValue(dThickness) && isFiniteValue(dWeight) && + dPorosity > 0.0 && dThickness > 0.0 && dWeight > 0.0; + oCell.m_dPoreVolumeWeight = oCell.m_bWeightValid ? dWeight : 0.0; + oCandidate.m_vecCells.append(oCell); + oCandidate.m_vecIntersectingCellIds.append(nCellId); + addCompensated(oCell.m_dArea, + oCandidate.m_dSelectedCellArea, + dAreaCorrection); + } + if(!isFiniteValue(oCandidate.m_dSelectedCellArea)) { + if(pError != NULL) { + *pError = QString::fromLatin1( + "The selected cell area is invalid."); + } + return false; + } + + oCandidate.m_bPrepared = true; + *m_pPrivate = oCandidate; + return true; +} + +void nmPebiRegionPressureCalculator::clear() +{ + if(m_pPrivate != NULL) { + *m_pPrivate = nmPebiRegionPressureCalculatorPrivate(); + } +} + +bool nmPebiRegionPressureCalculator::isPrepared() const +{ + return m_pPrivate != NULL && m_pPrivate->m_bPrepared && + !m_pPrivate->m_pSnapshot.isNull(); +} + +QString nmPebiRegionPressureCalculator::getSnapshotId() const +{ + return isPrepared() + ? m_pPrivate->m_pSnapshot->getSnapshotId() : QString(); +} + +const QVector& +nmPebiRegionPressureCalculator::getPolygonPoints() const +{ + return m_pPrivate->m_vecPolygonPoints; +} + +const QVector& +nmPebiRegionPressureCalculator::getIntersectingCellIds() const +{ + return m_pPrivate->m_vecIntersectingCellIds; +} + +bool nmPebiRegionPressureCalculator::calculateFrame( + int nPressureFrameIndex, + nmPebiRegionPressureStatistics& oStatistics, + QString* pError) const +{ + oStatistics.clear(); + if(pError != NULL) { + pError->clear(); + } + if(!isPrepared() || nPressureFrameIndex < 0 || + nPressureFrameIndex >= + m_pPrivate->m_pSnapshot->m_vecPressureFrames.size()) { + if(pError != NULL) { + *pError = QString::fromLatin1( + "The pressure frame is invalid."); + } + return false; + } + + const nmPebiResultSnapshot::PressureFrame& oFrame = + m_pPrivate->m_pSnapshot->m_vecPressureFrames[ + nPressureFrameIndex]; + vtkDoubleArray* pPressure = oFrame.m_pPressure; + if(pPressure == NULL || pPressure->GetNumberOfComponents() != 1 || + pPressure->GetNumberOfTuples() != + m_pPrivate->m_pSnapshot->getResultCellCount() || + !isFiniteValue(oFrame.m_dTime)) { + if(pError != NULL) { + *pError = QString::fromLatin1( + "The pressure frame data is invalid."); + } + return false; + } + + oStatistics.m_nPressureFrameIndex = nPressureFrameIndex; + oStatistics.m_dPressureTimeHours = oFrame.m_dTime; + oStatistics.m_nIntersectingCellCount = + m_pPrivate->m_vecCells.size(); + oStatistics.m_dSelectedCellAreaSquareMeters = + m_pPrivate->m_dSelectedCellArea; + + // 交集及静态权重已在 prepare() 缓存,逐帧只读压力并做线性汇总。 + double dPoreVolumeSum = 0.0; + double dPoreVolumeCorrection = 0.0; + double dWeightedPressureSum = 0.0; + double dWeightedPressureCorrection = 0.0; + double dMinimumPressure = DBL_MAX; + double dMaximumPressure = -DBL_MAX; + for(int nIndex = 0; + nIndex < m_pPrivate->m_vecCells.size(); ++nIndex) { + const CachedCell& oCell = m_pPrivate->m_vecCells[nIndex]; + const double dPressure = pPressure->GetValue(oCell.m_nCellId); + if(!oCell.m_bWeightValid || !isFiniteValue(dPressure)) { + continue; + } + addCompensated(oCell.m_dPoreVolumeWeight, + dPoreVolumeSum, dPoreVolumeCorrection); + addCompensated(oCell.m_dPoreVolumeWeight * dPressure, + dWeightedPressureSum, + dWeightedPressureCorrection); + dMinimumPressure = qMin(dMinimumPressure, dPressure); + dMaximumPressure = qMax(dMaximumPressure, dPressure); + ++oStatistics.m_nValidCellCount; + } + oStatistics.m_nIgnoredCellCount = + oStatistics.m_nIntersectingCellCount - + oStatistics.m_nValidCellCount; + // 空选区或全部权重无效都是可展示结果,不把它们当成计算错误。 + if(oStatistics.m_nValidCellCount == 0) { + return true; + } + if(!isFiniteValue(dPoreVolumeSum) || dPoreVolumeSum <= 0.0 || + !isFiniteValue(dWeightedPressureSum)) { + if(pError != NULL) { + *pError = QString::fromLatin1( + "The pore-volume weighted pressure is invalid."); + } + return false; + } + + const double dAveragePressure = + dWeightedPressureSum / dPoreVolumeSum; + if(!isFiniteValue(dMinimumPressure) || + !isFiniteValue(dMaximumPressure) || + !isFiniteValue(dAveragePressure)) { + if(pError != NULL) { + *pError = QString::fromLatin1( + "The regional pressure statistics are invalid."); + } + return false; + } + oStatistics.m_bAvailable = true; + oStatistics.m_dEffectivePoreVolumeCubicMeters = dPoreVolumeSum; + oStatistics.m_dMinimumPressureMpa = dMinimumPressure; + oStatistics.m_dMaximumPressureMpa = dMaximumPressure; + oStatistics.m_dPoreVolumeWeightedPressureMpa = dAveragePressure; + return true; +} diff --git a/Src/nmNum/nmRender/nmVTKPlanarPolygonInteractorStyle.cpp b/Src/nmNum/nmRender/nmVTKPlanarPolygonInteractorStyle.cpp new file mode 100644 index 00000000..fbc5332e --- /dev/null +++ b/Src/nmNum/nmRender/nmVTKPlanarPolygonInteractorStyle.cpp @@ -0,0 +1,301 @@ +#include "nmVTKPlanarPolygonInteractorStyle.h" + +#include + +#include +#include +#include +#include + +#include +#include +#include + +vtkStandardNewMacro(nmVTKPlanarPolygonInteractorStyle); + +namespace { + +const double PLANAR_POLYGON_RAY_EPSILON = 1.0e-12; + +bool isFinitePoint(const QPointF& oPoint) +{ + return vtkMath::IsFinite(oPoint.x()) && + vtkMath::IsFinite(oPoint.y()); +} + +bool displayToWorld(vtkRenderer* pRenderer, + double dX, + double dY, + double dZ, + double dWorld[3]) +{ + if(pRenderer == nullptr || dWorld == nullptr || + !vtkMath::IsFinite(dX) || !vtkMath::IsFinite(dY) || + !vtkMath::IsFinite(dZ)) { + return false; + } + + // VTK 返回齐次世界坐标,必须先除以 w 才能参与射线计算。 + pRenderer->SetDisplayPoint(dX, dY, dZ); + pRenderer->DisplayToWorld(); + const double* pHomogeneous = pRenderer->GetWorldPoint(); + if(pHomogeneous == nullptr || + !vtkMath::IsFinite(pHomogeneous[0]) || + !vtkMath::IsFinite(pHomogeneous[1]) || + !vtkMath::IsFinite(pHomogeneous[2]) || + !vtkMath::IsFinite(pHomogeneous[3]) || + std::fabs(pHomogeneous[3]) <= + std::numeric_limits::epsilon()) { + return false; + } + + const double dInverseW = 1.0 / pHomogeneous[3]; + dWorld[0] = pHomogeneous[0] * dInverseW; + dWorld[1] = pHomogeneous[1] * dInverseW; + dWorld[2] = pHomogeneous[2] * dInverseW; + return vtkMath::IsFinite(dWorld[0]) && + vtkMath::IsFinite(dWorld[1]) && + vtkMath::IsFinite(dWorld[2]); +} + +double coordinateScale(const QPointF& oLeft, const QPointF& oRight) +{ + double dScale = 1.0; + dScale = qMax(dScale, std::fabs(oLeft.x())); + dScale = qMax(dScale, std::fabs(oLeft.y())); + dScale = qMax(dScale, std::fabs(oRight.x())); + dScale = qMax(dScale, std::fabs(oRight.y())); + return dScale; +} + +bool isSamePoint(const QPointF& oLeft, const QPointF& oRight) +{ + const double dScale = coordinateScale(oLeft, oRight); + const double dTolerance = 1.0e-10 * dScale; + const double dX = oLeft.x() - oRight.x(); + const double dY = oLeft.y() - oRight.y(); + return dX * dX + dY * dY <= dTolerance * dTolerance; +} + +bool hasNonZeroArea(const QVector& vecPoints) +{ + if(vecPoints.size() < 3) { + return false; + } + + // 以首点为局部原点计算面积,避免大坐标下的精度损失。 + const QPointF oOrigin = vecPoints.first(); + double dMinimumX = oOrigin.x(); + double dMaximumX = oOrigin.x(); + double dMinimumY = oOrigin.y(); + double dMaximumY = oOrigin.y(); + double dTwiceArea = 0.0; + for(int nIndex = 0; nIndex < vecPoints.size(); ++nIndex) { + const QPointF& oCurrent = vecPoints[nIndex]; + const QPointF& oNext = + vecPoints[(nIndex + 1) % vecPoints.size()]; + const double dCurrentX = oCurrent.x() - oOrigin.x(); + const double dCurrentY = oCurrent.y() - oOrigin.y(); + const double dNextX = oNext.x() - oOrigin.x(); + const double dNextY = oNext.y() - oOrigin.y(); + dTwiceArea += dCurrentX * dNextY - dNextX * dCurrentY; + dMinimumX = qMin(dMinimumX, oCurrent.x()); + dMaximumX = qMax(dMaximumX, oCurrent.x()); + dMinimumY = qMin(dMinimumY, oCurrent.y()); + dMaximumY = qMax(dMaximumY, oCurrent.y()); + } + const double dScale = qMax(1.0, + qMax(dMaximumX - dMinimumX, dMaximumY - dMinimumY)); + return vtkMath::IsFinite(dTwiceArea) && + std::fabs(dTwiceArea) > 1.0e-12 * dScale * dScale; +} + +} + +nmVTKPlanarPolygonInteractorStyle:: +nmVTKPlanarPolygonInteractorStyle() + : m_bCompleted(false) +{ +} + +nmVTKPlanarPolygonInteractorStyle:: +~nmVTKPlanarPolygonInteractorStyle() +{ +} + +void nmVTKPlanarPolygonInteractorStyle::OnLeftButtonDown() +{ + if(m_bCompleted || this->Interactor == nullptr) { + return; + } + + // 单击追加顶点,VTK 将双击的第二次按下标记为 RepeatCount > 0。 + if(this->Interactor->GetRepeatCount() > 0) { + completePolygon(); + return; + } + appendCurrentPoint(); +} + +void nmVTKPlanarPolygonInteractorStyle::OnRightButtonDown() +{ + // 绘制模式下右键专用于取消,不传递给默认相机或右键菜单。 + if(!m_bCompleted) { + cancelPolygon(); + } +} + +void nmVTKPlanarPolygonInteractorStyle::OnKeyPress() +{ + if(m_bCompleted || this->Interactor == nullptr) { + return; + } + + const char* pKeySym = this->Interactor->GetKeySym(); + if(pKeySym == nullptr) { + return; + } + // Enter 完成、Backspace/Delete 撤回末点、Escape 取消,均由业务状态机收口。 + if(std::strcmp(pKeySym, "Return") == 0 || + std::strcmp(pKeySym, "KP_Enter") == 0) { + completePolygon(); + } else if(std::strcmp(pKeySym, "BackSpace") == 0 || + std::strcmp(pKeySym, "Delete") == 0) { + removeLastPoint(); + } else if(std::strcmp(pKeySym, "Escape") == 0) { + cancelPolygon(); + } +} + +void nmVTKPlanarPolygonInteractorStyle::OnChar() +{ + // 字符命令在绘制模式没有业务含义,不能触发基类的退出或相机复位。 +} + +void nmVTKPlanarPolygonInteractorStyle::reset() +{ + m_vecPoints.clear(); + m_bCompleted = false; +} + +QVector +nmVTKPlanarPolygonInteractorStyle::getPoints() const +{ + return m_vecPoints; +} + +int nmVTKPlanarPolygonInteractorStyle::getPointCount() const +{ + return m_vecPoints.size(); +} + +bool nmVTKPlanarPolygonInteractorStyle::isCompleted() const +{ + return m_bCompleted; +} + +bool nmVTKPlanarPolygonInteractorStyle::projectEventPositionToPlane( + QPointF& oPoint) +{ + if(this->Interactor == nullptr) { + return false; + } + int* pEventPosition = this->Interactor->GetEventPosition(); + if(pEventPosition == nullptr) { + return false; + } + + this->FindPokedRenderer(pEventPosition[0], pEventPosition[1]); + vtkRenderer* pRenderer = this->CurrentRenderer; + if(pRenderer == nullptr) { + return false; + } + + // 将同一屏幕点的近、远裁剪面坐标连成射线,再与 z=0 网格平面求交。 + double dNearPoint[3]; + double dFarPoint[3]; + if(!displayToWorld(pRenderer, + pEventPosition[0], pEventPosition[1], 0.0, + dNearPoint) || + !displayToWorld(pRenderer, + pEventPosition[0], pEventPosition[1], 1.0, + dFarPoint)) { + return false; + } + + const double dDirectionZ = dFarPoint[2] - dNearPoint[2]; + const double dRayScale = qMax(1.0, + qMax(std::fabs(dNearPoint[2]), std::fabs(dFarPoint[2]))); + if(std::fabs(dDirectionZ) <= + PLANAR_POLYGON_RAY_EPSILON * dRayScale) { + return false; + } + + const double dParameter = -dNearPoint[2] / dDirectionZ; + const QPointF oCandidate( + dNearPoint[0] + + dParameter * (dFarPoint[0] - dNearPoint[0]), + dNearPoint[1] + + dParameter * (dFarPoint[1] - dNearPoint[1])); + if(!isFinitePoint(oCandidate)) { + return false; + } + oPoint = oCandidate; + return true; +} + +bool nmVTKPlanarPolygonInteractorStyle::appendCurrentPoint() +{ + QPointF oPoint; + if(!projectEventPositionToPlane(oPoint) || + (!m_vecPoints.isEmpty() && + isSamePoint(m_vecPoints.last(), oPoint))) { + return false; + } + + // 连续重合点不入队,否则会生成零长边并干扰后续三角化。 + m_vecPoints.append(oPoint); + this->InvokeEvent(PolygonChangedEvent); + renderInteractor(); + return true; +} + +bool nmVTKPlanarPolygonInteractorStyle::completePolygon() +{ + if(m_bCompleted) { + return true; + } + if(!hasNonZeroArea(m_vecPoints)) { + this->InvokeEvent(PolygonInvalidEvent); + return false; + } + + // 先发变更事件绘制闭合边,再通知业务层离开 VTK 交互栈。 + m_bCompleted = true; + this->InvokeEvent(PolygonChangedEvent); + renderInteractor(); + this->InvokeEvent(PolygonCompletedEvent); + return true; +} + +void nmVTKPlanarPolygonInteractorStyle::removeLastPoint() +{ + if(m_vecPoints.isEmpty()) { + return; + } + m_vecPoints.remove(m_vecPoints.size() - 1); + this->InvokeEvent(PolygonChangedEvent); + renderInteractor(); +} + +void nmVTKPlanarPolygonInteractorStyle::cancelPolygon() +{ + this->InvokeEvent(PolygonCancelledEvent); +} + +void nmVTKPlanarPolygonInteractorStyle::renderInteractor() +{ + if(this->Interactor != nullptr) { + this->Interactor->Render(); + } +} diff --git a/Src/nmNum/nmRender/nmVTKPlanarPolygonLayer.cpp b/Src/nmNum/nmRender/nmVTKPlanarPolygonLayer.cpp new file mode 100644 index 00000000..a4a8c91f --- /dev/null +++ b/Src/nmNum/nmRender/nmVTKPlanarPolygonLayer.cpp @@ -0,0 +1,179 @@ +#include "nmVTKPlanarPolygonLayer.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + +bool isPlanarPolygonLayerGuiThread() +{ + // VTK Prop 和 Qt 视图的生命周期都由 GUI 线程统一管理。 + QCoreApplication* pApplication = QCoreApplication::instance(); + return pApplication == nullptr || + pApplication->thread() == QThread::currentThread(); +} + +bool isFinitePoint(const QPointF& oPoint) +{ + return vtkMath::IsFinite(oPoint.x()) && + vtkMath::IsFinite(oPoint.y()); +} + +} + +class nmVTKPlanarPolygonLayerPrivate +{ +public: + nmVTKPlanarPolygonLayerPrivate() + : m_pPoints(vtkSmartPointer::New()), + m_pVertices(vtkSmartPointer::New()), + m_pLines(vtkSmartPointer::New()), + m_pPolyData(vtkSmartPointer::New()), + m_pMapper(vtkSmartPointer::New()), + m_pActor(vtkSmartPointer::New()), + m_bClosed(false) + { + m_pPoints->SetDataTypeToDouble(); + m_pPolyData->SetPoints(m_pPoints); + m_pPolyData->SetVerts(m_pVertices); + m_pPolyData->SetLines(m_pLines); + m_pMapper->SetInputData(m_pPolyData); + + // 黄色点线只是业务覆盖层:不参与拾取,也不扩大相机自适应范围。 + m_pActor->SetMapper(m_pMapper); + m_pActor->GetProperty()->SetColor(1.0, 1.0, 0.0); + m_pActor->GetProperty()->SetLineWidth(2.0f); + m_pActor->GetProperty()->SetPointSize(7.0f); + m_pActor->GetProperty()->LightingOff(); + m_pActor->PickableOff(); + m_pActor->UseBoundsOff(); + } + + vtkActor* getActor() const + { + return m_pActor; + } + + bool setPolygon(const QVector& vecPoints, bool bClosed) + { + for(int nIndex = 0; nIndex < vecPoints.size(); ++nIndex) { + if(!isFinitePoint(vecPoints[nIndex])) { + return false; + } + } + + // 先构建完整候选 PolyData,成功后再一次替换,避免视图看到半更新状态。 + vtkSmartPointer pCandidatePoints = + vtkSmartPointer::New(); + vtkSmartPointer pCandidateVertices = + vtkSmartPointer::New(); + vtkSmartPointer pCandidateLines = + vtkSmartPointer::New(); + pCandidatePoints->SetDataTypeToDouble(); + + const vtkIdType nPointCount = + static_cast(vecPoints.size()); + pCandidatePoints->SetNumberOfPoints(nPointCount); + for(vtkIdType nPointId = 0; nPointId < nPointCount; ++nPointId) { + const QPointF& oPoint = vecPoints[static_cast(nPointId)]; + pCandidatePoints->SetPoint(nPointId, oPoint.x(), oPoint.y(), 0.0); + pCandidateVertices->InsertNextCell(1, &nPointId); + } + + const bool bCandidateClosed = bClosed && nPointCount >= 3; + if(nPointCount >= 2) { + // VTK 折线不会自动闭合,完成后需在索引尾部再写入首点。 + const vtkIdType nLinePointCount = + nPointCount + (bCandidateClosed ? 1 : 0); + pCandidateLines->InsertNextCell(nLinePointCount); + for(vtkIdType nPointId = 0; + nPointId < nPointCount; ++nPointId) { + pCandidateLines->InsertCellPoint(nPointId); + } + if(bCandidateClosed) { + pCandidateLines->InsertCellPoint(0); + } + } + + m_vecPoints = vecPoints; + m_bClosed = bCandidateClosed; + m_pPoints = pCandidatePoints; + m_pVertices = pCandidateVertices; + m_pLines = pCandidateLines; + m_pPolyData->SetPoints(m_pPoints); + m_pPolyData->SetVerts(m_pVertices); + m_pPolyData->SetLines(m_pLines); + m_pPolyData->Modified(); + return true; + } + + void clear() + { + setPolygon(QVector(), false); + } + + vtkSmartPointer m_pPoints; + vtkSmartPointer m_pVertices; + vtkSmartPointer m_pLines; + vtkSmartPointer m_pPolyData; + vtkSmartPointer m_pMapper; + vtkSmartPointer m_pActor; + QVector m_vecPoints; + bool m_bClosed; +}; + +nmVTKPlanarPolygonLayer::nmVTKPlanarPolygonLayer( + const QString& sLayerId) + : nmVTKRenderLayer(sLayerId), + m_pPrivate(new nmVTKPlanarPolygonLayerPrivate) +{ + Q_ASSERT(isPlanarPolygonLayerGuiThread()); + setRenderProp(m_pPrivate->getActor()); +} + +nmVTKPlanarPolygonLayer::~nmVTKPlanarPolygonLayer() +{ + Q_ASSERT(isPlanarPolygonLayerGuiThread()); + if(m_pPrivate != nullptr) { + detach(); + delete m_pPrivate; + m_pPrivate = nullptr; + } +} + +bool nmVTKPlanarPolygonLayer::setPolygon( + const QVector& vecPoints, + bool bClosed) +{ + Q_ASSERT(isPlanarPolygonLayerGuiThread()); + return isPlanarPolygonLayerGuiThread() && m_pPrivate != nullptr && + m_pPrivate->setPolygon(vecPoints, bClosed); +} + +void nmVTKPlanarPolygonLayer::clear() +{ + Q_ASSERT(isPlanarPolygonLayerGuiThread()); + if(isPlanarPolygonLayerGuiThread() && m_pPrivate != nullptr) { + m_pPrivate->clear(); + } +} + +QVector nmVTKPlanarPolygonLayer::getPoints() const +{ + return m_pPrivate != nullptr + ? m_pPrivate->m_vecPoints : QVector(); +} + +bool nmVTKPlanarPolygonLayer::isClosed() const +{ + return m_pPrivate != nullptr && m_pPrivate->m_bClosed; +} diff --git a/Src/nmNum/nmRender/nmVTKViewCommandController.cpp b/Src/nmNum/nmRender/nmVTKViewCommandController.cpp index fd583936..56ade1d2 100644 --- a/Src/nmNum/nmRender/nmVTKViewCommandController.cpp +++ b/Src/nmNum/nmRender/nmVTKViewCommandController.cpp @@ -28,6 +28,7 @@ nmVTKViewCommandController::nmVTKViewCommandController( m_pContainer(pContainer), m_eCapabilities(0), m_bViewAvailable(false), + m_bInteractionCommandsAvailable(true), m_bRotationCenterPickingAvailable(false), m_bRotationCenterMarkerAvailable(false) { @@ -228,6 +229,14 @@ bool nmVTKViewCommandController::isViewAvailable() const return m_bViewAvailable; } +void nmVTKViewCommandController::setInteractionCommandsAvailable( + bool bAvailable) +{ + // 临时业务交互只冻结动作可用性,不改写容器已公布的能力集。 + m_bInteractionCommandsAvailable = bAvailable; + updateActionStates(); +} + void nmVTKViewCommandController::setRotationCenterPickingAvailable( bool bAvailable) { @@ -338,7 +347,8 @@ void nmVTKViewCommandController::updateActionStates() QAction* pAction = m_pActions[nIndex]; if(pAction != nullptr) { const bool bSupported = supports(eCommands[nIndex]); - bool bEnabled = bSupported && m_bViewAvailable; + bool bEnabled = bSupported && m_bViewAvailable && + m_bInteractionCommandsAvailable; if(eCommands[nIndex] == ViewCommand_SetRotationCenter) { bEnabled = bEnabled && m_bRotationCenterPickingAvailable; diff --git a/Src/nmNum/nmRender/nmWxVTKRenderContainerWidget.cpp b/Src/nmNum/nmRender/nmWxVTKRenderContainerWidget.cpp index db01999b..c50fb424 100644 --- a/Src/nmNum/nmRender/nmWxVTKRenderContainerWidget.cpp +++ b/Src/nmNum/nmRender/nmWxVTKRenderContainerWidget.cpp @@ -384,6 +384,12 @@ bool nmWxVTKRenderContainerWidget::installInteractionStyle( const bool bSucceeded = isGuiThread() && m_pInteractionManager != nullptr && m_pInteractionManager->installInteractionStyle(pStyle); + // 自定义样式接管鼠标期间,禁用会切换相机或拾取模式的公共命令。 + if(m_pViewCommandController != nullptr) { + m_pViewCommandController->setInteractionCommandsAvailable( + m_pInteractionManager != nullptr && + m_pInteractionManager->isDefaultInteractionActive()); + } updateRotationCenterCommandAvailability(); return bSucceeded; } @@ -395,6 +401,11 @@ bool nmWxVTKRenderContainerWidget::restoreDefaultInteraction() const bool bSucceeded = isGuiThread() && m_pInteractionManager != nullptr && m_pInteractionManager->restoreDefaultInteraction(); + if(m_pViewCommandController != nullptr) { + m_pViewCommandController->setInteractionCommandsAvailable( + m_pInteractionManager != nullptr && + m_pInteractionManager->isDefaultInteractionActive()); + } updateRotationCenterCommandAvailability(); return bSucceeded; } @@ -406,6 +417,9 @@ void nmWxVTKRenderContainerWidget::clearInteractionStyle() if(isGuiThread() && m_pInteractionManager != nullptr) { m_pInteractionManager->clearInteractionStyle(); } + if(m_pViewCommandController != nullptr) { + m_pViewCommandController->setInteractionCommandsAvailable(false); + } updateRotationCenterCommandAvailability(); } @@ -786,6 +800,11 @@ bool nmWxVTKRenderContainerWidget::eventFilter( if(pEvent->type() == QEvent::MouseButtonPress) { QMouseEvent* pMouseEvent = static_cast(pEvent); if(pMouseEvent->button() == Qt::RightButton) { + // 临时交互样式拥有右键语义;公共菜单只在默认相机模式下弹出。 + if(m_pInteractionManager != nullptr && + !m_pInteractionManager->isDefaultInteractionActive()) { + return false; + } // 菜单引用命令控制器长期持有的 QAction,不在每次右键时重复创建。 QMenu oMenu(this); if(m_pViewCommandController != nullptr) { diff --git a/Src/nmNum/nmSubWxs/nmWxPebiResultControlBar.cpp b/Src/nmNum/nmSubWxs/nmWxPebiResultControlBar.cpp index 9005ed70..0c00ac64 100644 --- a/Src/nmNum/nmSubWxs/nmWxPebiResultControlBar.cpp +++ b/Src/nmNum/nmSubWxs/nmWxPebiResultControlBar.cpp @@ -70,6 +70,7 @@ nmWxPebiResultControlBar::nmWxPebiResultControlBar( m_pExportAction(nullptr), m_pExportButton(nullptr), m_bExportInProgress(false), + m_bExternalInteractionLocked(false), m_nDisplayedBindingRevision(0), m_nDisplayedTimeFrameCount(-1), m_bDisplayedPlaying(false) @@ -134,12 +135,32 @@ bool nmWxPebiResultControlBar::isExportInProgress() const return m_bExportInProgress; } +void nmWxPebiResultControlBar::setExternalInteractionLocked(bool bLocked) +{ + if(m_bExternalInteractionLocked == bLocked) { + return; + } + // 该锁只保护当前结果身份,不改变 SceneController 中已选属性和帧。 + m_bExternalInteractionLocked = bLocked; + if(bLocked && m_pPlaybackController != nullptr) { + // 防御外部调用顺序错误,绘制事务绝不能与仍在推进的 Timer 并存。 + m_pPlaybackController->pause(); + } + refreshFromController(); +} + +bool nmWxPebiResultControlBar::isExternalInteractionLocked() const +{ + return m_bExternalInteractionLocked; +} + void nmWxPebiResultControlBar::onDisplayModeIndexChanged(int nIndex) { if(m_pDisplayModeCombo == nullptr || !m_pDisplayModeCombo->isEnabled() || m_pPlaybackController == nullptr || m_pSceneController == nullptr || - m_bExportInProgress || m_pPlaybackController->isPlaying() || + m_bExportInProgress || m_bExternalInteractionLocked || + m_pPlaybackController->isPlaying() || !m_pSceneController->hasSnapshot() || nIndex < 0 || nIndex >= m_pDisplayModeCombo->count()) { return; @@ -165,6 +186,7 @@ void nmWxPebiResultControlBar::onDisplayModeIndexChanged(int nIndex) void nmWxPebiResultControlBar::onPropertyIndexChanged(int nIndex) { if(m_pPlaybackController == nullptr || m_bExportInProgress || + m_bExternalInteractionLocked || m_pPlaybackController->isPlaying() || nIndex < 0) { return; } @@ -177,6 +199,7 @@ void nmWxPebiResultControlBar::onPropertyIndexChanged(int nIndex) void nmWxPebiResultControlBar::onTimeIndexChanged(int nIndex) { if(m_pPlaybackController == nullptr || m_bExportInProgress || + m_bExternalInteractionLocked || m_pPlaybackController->isPlaying() || nIndex < 0) { return; } @@ -190,6 +213,7 @@ void nmWxPebiResultControlBar::onColorSettingsClicked() { if(m_pPlaybackController == nullptr || m_pSceneController == nullptr || m_bExportInProgress || + m_bExternalInteractionLocked || m_pPlaybackController->isPlaying() || !m_pSceneController->hasSnapshot()) { return; @@ -207,6 +231,7 @@ void nmWxPebiResultControlBar::onColorSettingsClicked() void nmWxPebiResultControlBar::onFirstFrameClicked() { if(m_pPlaybackController == nullptr || m_bExportInProgress || + m_bExternalInteractionLocked || m_pPlaybackController->isPlaying()) { return; } @@ -218,6 +243,7 @@ void nmWxPebiResultControlBar::onFirstFrameClicked() void nmWxPebiResultControlBar::onPreviousFrameClicked() { if(m_pPlaybackController == nullptr || m_bExportInProgress || + m_bExternalInteractionLocked || m_pPlaybackController->isPlaying()) { return; } @@ -229,6 +255,7 @@ void nmWxPebiResultControlBar::onPreviousFrameClicked() void nmWxPebiResultControlBar::onNextFrameClicked() { if(m_pPlaybackController == nullptr || m_bExportInProgress || + m_bExternalInteractionLocked || m_pPlaybackController->isPlaying()) { return; } @@ -240,6 +267,7 @@ void nmWxPebiResultControlBar::onNextFrameClicked() void nmWxPebiResultControlBar::onLastFrameClicked() { if(m_pPlaybackController == nullptr || m_bExportInProgress || + m_bExternalInteractionLocked || m_pPlaybackController->isPlaying()) { return; } @@ -250,7 +278,8 @@ void nmWxPebiResultControlBar::onLastFrameClicked() void nmWxPebiResultControlBar::onPlayPauseClicked() { - if(m_pPlaybackController == nullptr || m_bExportInProgress) { + if(m_pPlaybackController == nullptr || m_bExportInProgress || + m_bExternalInteractionLocked) { return; } if(m_pPlaybackController->togglePlayback()) { @@ -261,6 +290,7 @@ void nmWxPebiResultControlBar::onPlayPauseClicked() void nmWxPebiResultControlBar::onAnimationSettingsClicked() { if(m_pPlaybackController == nullptr || m_bExportInProgress || + m_bExternalInteractionLocked || m_pPlaybackController->isPlaying()) { return; } @@ -279,6 +309,7 @@ void nmWxPebiResultControlBar::onAnimationSettingsClicked() void nmWxPebiResultControlBar::onExportAnimationTriggered() { if(m_pPlaybackController == nullptr || m_bExportInProgress || + m_bExternalInteractionLocked || m_pPlaybackController->isPlaying() || !m_pPlaybackController->isCurrentPropertyTimeDependent() || m_pPlaybackController->getCurrentPropertyFrameCount() <= 1) { @@ -392,7 +423,9 @@ void nmWxPebiResultControlBar::refreshFromController() const bool bHasMultipleFrames = bHasCompleteTimeList && nFrameCount > 1; const bool bPlaying = m_pPlaybackController->isPlaying(); - const bool bLocked = bPlaying || m_bExportInProgress; + // 回放、导出和外部绘制互斥,三者共用同一套控件可用性规则。 + const bool bLocked = bPlaying || m_bExportInProgress || + m_bExternalInteractionLocked; m_pDisplayModeCombo->setEnabled(!bLocked); m_pPropertyCombo->setEnabled(!bLocked); m_pColorSettingsButton->setEnabled(!bLocked); @@ -408,7 +441,8 @@ void nmWxPebiResultControlBar::refreshFromController() bHasMultipleFrames && nCurrentFrame < nFrameCount - 1 && !bLocked); m_pPlayPauseButton->setEnabled( - bHasMultipleFrames && !m_bExportInProgress); + bHasMultipleFrames && !m_bExportInProgress && + !m_bExternalInteractionLocked); m_pSettingsButton->setEnabled(bHasMultipleFrames && !bLocked); QString sBackendError; diff --git a/Src/nmNum/nmSubWxs/nmWxPebiResultViewWidget.cpp b/Src/nmNum/nmSubWxs/nmWxPebiResultViewWidget.cpp index 467c10b0..21d4ce42 100644 --- a/Src/nmNum/nmSubWxs/nmWxPebiResultViewWidget.cpp +++ b/Src/nmNum/nmSubWxs/nmWxPebiResultViewWidget.cpp @@ -4,6 +4,7 @@ #include "iUnitHelper.h" #include "nmDataAnalyzeManager.h" #include "nmFFmpegVideoWriter.h" +#include "nmPebiRegionPressureCalculator.h" #include "nmPebiResultAnimationExporter.h" #include "nmPebiResultDisplaySettings.h" #include "nmPebiResultPlaybackController.h" @@ -12,6 +13,9 @@ #include "nmPebiResultSceneController.h" #include "nmPebiResultSnapshot.h" #include "nmVTKMeshLayer.h" +#include "nmVTKPlanarPolygonInteractorStyle.h" +#include "nmVTKPlanarPolygonLayer.h" +#include "nmVTKScene.h" #include "nmVTKViewCommandController.h" #include "nmWxPebiResultControlBar.h" #include "nmWxPebiResultAnimationExportDlg.h" @@ -22,8 +26,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -31,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -41,7 +48,11 @@ #include #include +#include +#include +#include #include +#include #include @@ -53,6 +64,9 @@ namespace { QAtomicInt g_nPebiAnimationExportActive(0); +const char* const PEBI_REGION_PRESSURE_LAYER_ID = + "PebiResult.RegionPressurePolygon"; + QString resultViewIconPath(const QString& sFileName) { const QString sApplicationDir = QCoreApplication::applicationDirPath(); @@ -86,6 +100,63 @@ bool isFiniteFilterEditorValue(double dValue) #endif } +QString formatRegionValue(double dValue) +{ + if(!isFiniteFilterEditorValue(dValue)) { + return QString(); + } + return QLocale().toString(dValue, 'g', 10); +} + +QLineEdit* addRegionStatisticsRow(QGridLayout* pLayout, + int nRow, + const QString& sName, + QWidget* pParent, + QWidget* pUnitWidget = nullptr) +{ + QLabel* pNameLabel = new QLabel(sName, pParent); + QLineEdit* pValueEdit = new QLineEdit(pParent); + pNameLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); + pValueEdit->setReadOnly(true); + pValueEdit->setAlignment(Qt::AlignRight | Qt::AlignVCenter); + pValueEdit->setMinimumWidth(150); + pLayout->addWidget(pNameLabel, nRow, 0); + pLayout->addWidget(pValueEdit, nRow, 1); + if(pUnitWidget != nullptr) { + pLayout->addWidget(pUnitWidget, nRow, 2); + } + return pValueEdit; +} + +QComboBox* createRegionUnitCombo(QWidget* pParent, + const QString& sUnit) +{ + QComboBox* pCombo = new QComboBox(pParent); + pCombo->addItem(sUnit); + pCombo->setEnabled(false); + pCombo->setMinimumWidth(80); + pCombo->setMaximumWidth(140); + pCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + pCombo->setSizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow); + return pCombo; +} + +bool canProjectRegionOntoXyPlane(vtkRenderer* pRenderer) +{ + vtkCamera* pCamera = pRenderer == nullptr + ? nullptr : pRenderer->GetActiveCamera(); + if(pCamera == nullptr) { + return false; + } + + double dDirection[3]; + pCamera->GetDirectionOfProjection(dDirection); + const double dLength = vtkMath::Norm(dDirection); + return vtkMath::IsFinite(dLength) && dLength > 0.0 && + vtkMath::IsFinite(dDirection[2]) && + qAbs(dDirection[2]) > 1.0e-10 * dLength; +} + class AnimationExportGuard { public: @@ -127,6 +198,93 @@ private: } +class nmWxPebiResultRegionState +{ +public: + enum State + { + State_Idle = 0, + State_Drawing, + State_Completed + }; + + enum PendingEvent + { + PendingEvent_None = 0, + PendingEvent_Completed, + PendingEvent_Cancelled, + PendingEvent_Invalid + }; + + nmWxPebiResultRegionState() + : m_eState(State_Idle), + m_ePendingEvent(PendingEvent_None), + m_bPendingEventQueued(false), + m_pLayer(nullptr), + m_nChangedObserverTag(0), + m_nCompletedObserverTag(0), + m_nCancelledObserverTag(0), + m_nInvalidObserverTag(0), + m_nFrozenBindingRevision(0), + m_nFrozenFrameIndex(-1), + m_nRegionBindingRevision(0), + m_nLastAttemptedFrameIndex(-1), + m_bStatisticsCalculated(false), + m_pDialog(nullptr), + m_pAveragePressureUnitCombo(nullptr), + m_pMinimumPressureUnitCombo(nullptr), + m_pMaximumPressureUnitCombo(nullptr), + m_pPressureTimeUnitCombo(nullptr), + m_pAveragePressureValue(nullptr), + m_pMinimumPressureValue(nullptr), + m_pMaximumPressureValue(nullptr), + m_pTimeValue(nullptr), + m_pSelectedCellValue(nullptr), + m_pWarningLabel(nullptr) + { + } + + State m_eState; ///< 当前窗口区域工具状态。 + PendingEvent m_ePendingEvent; ///< 等待 Qt 事件循环处理的 VTK 终止事件。 + bool m_bPendingEventQueued; ///< 是否已有一次安全收尾被排队。 + QVector m_vecPendingPoints; ///< 完成回调复制出的候选世界坐标。 + + nmPebiRegionPressureCalculator m_oCalculator; ///< 独占相交缓存和压力计算器。 + nmVTKPlanarPolygonLayer* m_pLayer; ///< 业务 Scene 所有的区域轮廓观察指针。 + vtkSmartPointer m_pStyle; ///< 临时绘制样式。 + vtkSmartPointer m_pCallback; ///< 不拥有窗口的 VTK 回调命令。 + unsigned long m_nChangedObserverTag; ///< 点集变化观察者标识。 + unsigned long m_nCompletedObserverTag; ///< 绘制完成观察者标识。 + unsigned long m_nCancelledObserverTag; ///< 绘制取消观察者标识。 + unsigned long m_nInvalidObserverTag; ///< 无效完成观察者标识。 + + QSharedPointer m_pFrozenSnapshot; ///< 绘制开始时的快照强引用。 + quint64 m_nFrozenBindingRevision; ///< 绘制开始时的成功绑定序号。 + QString m_sFrozenSnapshotId; ///< 绘制开始时的快照稳定 ID。 + QString m_sFrozenPropertyId; ///< 绘制开始时的显示属性 ID。 + int m_nFrozenFrameIndex; ///< 绘制开始时的 pressure 帧。 + + quint64 m_nRegionBindingRevision; ///< 已完成区域所属成功绑定序号。 + QString m_sRegionSnapshotId; ///< 已完成区域所属快照 ID。 + QString m_sLastObservedPropertyId; ///< 最近一次状态信号观察到的显示属性。 + int m_nLastAttemptedFrameIndex; ///< 最近一次尝试统计的 pressure 帧。 + bool m_bStatisticsCalculated; ///< 最近一次统计调用是否成功。 + QString m_sStatisticsError; ///< 最近一次统计调用失败说明。 + nmPebiRegionPressureStatistics m_oStatistics; ///< 最近一次成功统计结果。 + + QDialog* m_pDialog; ///< ViewWidget 子对象,关闭时同步结束本次统计。 + QComboBox* m_pAveragePressureUnitCombo; ///< 固定显示 MPa 的禁用单位框。 + QComboBox* m_pMinimumPressureUnitCombo; ///< 压力下限固定单位框。 + QComboBox* m_pMaximumPressureUnitCombo; ///< 压力上限固定单位框。 + QComboBox* m_pPressureTimeUnitCombo; ///< 固定显示 h 的禁用单位框。 + QLineEdit* m_pAveragePressureValue; ///< 只读区域平均压力。 + QLineEdit* m_pMinimumPressureValue; ///< 只读区域压力下限。 + QLineEdit* m_pMaximumPressureValue; ///< 只读区域压力上限。 + QLineEdit* m_pTimeValue; ///< 只读求解时间显示值。 + QLineEdit* m_pSelectedCellValue; ///< 只读相交单元数。 + QLabel* m_pWarningLabel; ///< 仅在无结果或有忽略单元时显示的说明。 +}; + nmWxPebiResultFilterSettingsDlg::nmWxPebiResultFilterSettingsDlg( nmPebiResultSceneController* pSceneController, nmWxPebiResultControlBar* pControlBar, @@ -658,6 +816,8 @@ nmWxPebiResultViewWidget::nmWxPebiResultViewWidget( m_pScaleGridAction(nullptr), m_pWellNamesAction(nullptr), m_pFilterAction(nullptr), + m_pRegionPressureAction(nullptr), + m_pRegionState(new nmWxPebiResultRegionState), m_bObservedSnapshotCurrent(false), m_bObservedStateValid(false), m_bSynchronizing(false), @@ -670,6 +830,7 @@ nmWxPebiResultViewWidget::nmWxPebiResultViewWidget( nmWxPebiResultViewWidget::~nmWxPebiResultViewWidget() { disconnectDataManager(); + destroyRegionPressureState(); if(m_pControlBar != nullptr) { m_pControlBar->stopPlayback(); delete m_pControlBar; @@ -770,6 +931,7 @@ void nmWxPebiResultViewWidget::appendContextMenuActions(QMenu* pMenu) return; } pMenu->addAction(m_pFilterAction); + pMenu->addAction(m_pRegionPressureAction); pMenu->addSeparator(); pMenu->addAction(m_pScalarBarAction); pMenu->addAction(m_pScaleGridAction); @@ -821,7 +983,8 @@ void nmWxPebiResultViewWidget::onShowFilterSettings() pPlaybackController == nullptr || !m_pSceneController->hasSnapshot() || pPlaybackController->isPlaying() || - m_pControlBar->isExportInProgress()) { + m_pControlBar->isExportInProgress() || + m_pControlBar->isExternalInteractionLocked()) { return; } @@ -833,6 +996,259 @@ void nmWxPebiResultViewWidget::onShowFilterSettings() synchronizeBusinessActions(); } +void nmWxPebiResultViewWidget::onRegionPressureStatisticsTriggered() +{ + if(m_pRegionState == nullptr || m_pControlBar == nullptr) { + return; + } + + // 共享 QAction 根据当前状态分别表示:取消绘制、重显结果或开始新绘制。 + if(isRegionPressureDrawing()) { + clearRegionPressureSelection(true); + onControlOperationSucceeded(); + return; + } + + if(m_pRegionState->m_eState == + nmWxPebiResultRegionState::State_Completed) { + showRegionPressureStatisticsDialog(); + return; + } + + nmPebiResultPlaybackController* pPlaybackController = + m_pControlBar->getPlaybackController(); + if(pPlaybackController == nullptr || + pPlaybackController->isPlaying() || + m_pControlBar->isExportInProgress() || + m_pControlBar->isExternalInteractionLocked()) { + return; + } + + if(m_pRenderContainer == nullptr || + !canProjectRegionOntoXyPlane( + m_pRenderContainer->getRenderer())) { + onControlOperationFailed(tr( + "Switch to Top View or Isometric View before drawing a pressure region.")); + return; + } + + if(!startRegionPressureDrawing()) { + onControlOperationFailed(tr( + "Unable to start region pressure drawing.")); + } else { + onControlOperationSucceeded(); + } +} + +void nmWxPebiResultViewWidget::handleRegionPolygonEvent( + vtkObject* pCaller, + unsigned long nEventId, + void* pClientData, + void* pCallData) +{ + Q_UNUSED(pCallData); + nmWxPebiResultViewWidget* pView = + static_cast(pClientData); + if(pView == nullptr || pView->m_pRegionState == nullptr || + pView->m_pRegionState->m_eState != + nmWxPebiResultRegionState::State_Drawing || + pCaller != pView->m_pRegionState->m_pStyle.GetPointer()) { + return; + } + + nmWxPebiResultRegionState* pState = pView->m_pRegionState; + if(nEventId == + nmVTKPlanarPolygonInteractorStyle::PolygonChangedEvent) { + nmVTKScene* pScene = pView->m_pRenderContainer == nullptr + ? nullptr : pView->m_pRenderContainer->getScene(); + if(pScene != nullptr && pState->m_pLayer != nullptr && + pScene->getLayer(QString::fromLatin1( + PEBI_REGION_PRESSURE_LAYER_ID)) == pState->m_pLayer) { + pState->m_pLayer->setPolygon( + pState->m_pStyle->getPoints(), + pState->m_pStyle->isCompleted()); + } + return; + } + + // VTK 回调内只复制小量状态;场景切换、对话框和统计计算延后到 Qt 事件循环。 + nmWxPebiResultRegionState::PendingEvent ePendingEvent = + nmWxPebiResultRegionState::PendingEvent_None; + if(nEventId == + nmVTKPlanarPolygonInteractorStyle::PolygonCompletedEvent) { + ePendingEvent = + nmWxPebiResultRegionState::PendingEvent_Completed; + pState->m_vecPendingPoints = pState->m_pStyle->getPoints(); + } else if(nEventId == + nmVTKPlanarPolygonInteractorStyle::PolygonCancelledEvent) { + ePendingEvent = + nmWxPebiResultRegionState::PendingEvent_Cancelled; + } else if(nEventId == + nmVTKPlanarPolygonInteractorStyle::PolygonInvalidEvent) { + ePendingEvent = + nmWxPebiResultRegionState::PendingEvent_Invalid; + } else { + return; + } + + // 完成或取消优先于尚未处理的无效提示,且每次只排一个 Qt 收尾任务。 + if(pState->m_bPendingEventQueued) { + if(pState->m_ePendingEvent == + nmWxPebiResultRegionState::PendingEvent_Invalid && + ePendingEvent != + nmWxPebiResultRegionState::PendingEvent_Invalid) { + pState->m_ePendingEvent = ePendingEvent; + } + return; + } + + pState->m_ePendingEvent = ePendingEvent; + pState->m_bPendingEventQueued = true; + QMetaObject::invokeMethod( + pView, "processPendingRegionInteractionEvent", + Qt::QueuedConnection); +} + +void nmWxPebiResultViewWidget::processPendingRegionInteractionEvent() +{ + if(m_pRegionState == nullptr) { + return; + } + + const nmWxPebiResultRegionState::PendingEvent ePendingEvent = + m_pRegionState->m_ePendingEvent; + const QVector vecPoints = + m_pRegionState->m_vecPendingPoints; + m_pRegionState->m_ePendingEvent = + nmWxPebiResultRegionState::PendingEvent_None; + m_pRegionState->m_bPendingEventQueued = false; + m_pRegionState->m_vecPendingPoints.clear(); + + if(!isRegionPressureDrawing()) { + return; + } + if(ePendingEvent == + nmWxPebiResultRegionState::PendingEvent_Invalid) { + onControlOperationFailed(tr( + "Draw a non-degenerate region with at least three points.")); + return; + } + if(ePendingEvent == + nmWxPebiResultRegionState::PendingEvent_Cancelled) { + clearRegionPressureSelection(true); + onControlOperationSucceeded(); + return; + } + if(ePendingEvent != + nmWxPebiResultRegionState::PendingEvent_Completed) { + return; + } + + // 绘制期间快照、属性或帧发生变化时,不能把旧坐标区域提交到新结果。 + const bool bIdentityMatches = + m_pSceneController != nullptr && + m_pSceneController->hasSnapshot() && + !m_pDisplayedSnapshot.isNull() && + m_pDisplayedSnapshot.data() == + m_pRegionState->m_pFrozenSnapshot.data() && + m_pSceneController->getSnapshotBindingRevision() == + m_pRegionState->m_nFrozenBindingRevision && + m_pSceneController->getCurrentSnapshotId() == + m_pRegionState->m_sFrozenSnapshotId && + m_sDisplayedSnapshotId == + m_pRegionState->m_sFrozenSnapshotId && + m_pSceneController->getCurrentPropertyId() == + m_pRegionState->m_sFrozenPropertyId && + m_pSceneController->getCurrentFrameIndex() == + m_pRegionState->m_nFrozenFrameIndex; + if(!bIdentityMatches) { + clearRegionPressureSelection(true); + onControlOperationFailed(tr( + "The displayed result changed while the region was drawn.")); + return; + } + + // Calculator::prepare() 事务式建立相交单元和静态权重缓存。 + QString sError; + if(!m_pRegionState->m_oCalculator.prepare( + m_pRegionState->m_pFrozenSnapshot, vecPoints, &sError)) { + clearRegionPressureSelection(true); + onControlOperationFailed(tr( + "Unable to prepare the selected pressure region.")); + return; + } + + nmPebiRegionPressureStatistics oStatistics; + if(!m_pRegionState->m_oCalculator.calculateFrame( + m_pRegionState->m_nFrozenFrameIndex, + oStatistics, &sError)) { + clearRegionPressureSelection(true); + onControlOperationFailed(tr( + "Unable to calculate region pressure statistics.")); + return; + } + + nmVTKScene* pScene = m_pRenderContainer == nullptr + ? nullptr : m_pRenderContainer->getScene(); + if(pScene == nullptr || m_pRegionState->m_pLayer == nullptr || + pScene->getLayer(QString::fromLatin1( + PEBI_REGION_PRESSURE_LAYER_ID)) != m_pRegionState->m_pLayer || + !m_pRegionState->m_pLayer->setPolygon( + m_pRegionState->m_oCalculator.getPolygonPoints(), true)) { + clearRegionPressureSelection(true); + onControlOperationFailed(tr( + "Unable to preserve the selected pressure region.")); + return; + } + + // 几何、计算和轮廓全部成功后才将窗口状态提交为 Completed。 + m_pRegionState->m_nRegionBindingRevision = + m_pRegionState->m_nFrozenBindingRevision; + m_pRegionState->m_sRegionSnapshotId = + m_pRegionState->m_sFrozenSnapshotId; + m_pRegionState->m_nLastAttemptedFrameIndex = + m_pRegionState->m_nFrozenFrameIndex; + m_pRegionState->m_bStatisticsCalculated = true; + m_pRegionState->m_sStatisticsError.clear(); + m_pRegionState->m_oStatistics = oStatistics; + m_pRegionState->m_sLastObservedPropertyId = + QString::fromLatin1("pressure"); + m_pRegionState->m_eState = + nmWxPebiResultRegionState::State_Completed; + stopRegionPressureDrawing(); + onControlOperationSucceeded(); + showRegionPressureStatisticsDialog(); + synchronizeBusinessActions(); +} + +void nmWxPebiResultViewWidget::onResultDisplayStateChanged() +{ + if(m_pRegionState != nullptr && m_pSceneController != nullptr && + m_pRegionState->m_eState == + nmWxPebiResultRegionState::State_Completed) { + const QString sCurrentPropertyId = + m_pSceneController->getCurrentPropertyId(); + if(sCurrentPropertyId == QString::fromLatin1("pressure") && + m_pRegionState->m_sLastObservedPropertyId != + sCurrentPropertyId) { + // 从静态属性切回 pressure 时必须重新评估第 0 帧,即使曾统计过该帧。 + m_pRegionState->m_nLastAttemptedFrameIndex = -1; + } + m_pRegionState->m_sLastObservedPropertyId = sCurrentPropertyId; + } + synchronizeBusinessActions(); + updateRegionPressureStatistics(); +} + +void nmWxPebiResultViewWidget::onCloseRegionPressureStatistics() +{ + if(m_pRegionState == nullptr) { + return; + } + clearRegionPressureSelection(true); + onControlOperationSucceeded(); +} + void nmWxPebiResultViewWidget::onExportAnimationRequested() { nmPebiResultPlaybackController* pPlaybackController = @@ -842,6 +1258,8 @@ void nmWxPebiResultViewWidget::onExportAnimationRequested() if(m_pSceneController == nullptr || m_pRenderContainer == nullptr || pPlaybackController == nullptr || pPlaybackController->isPlaying() || + (m_pControlBar != nullptr && + m_pControlBar->isExternalInteractionLocked()) || !m_pSceneController->hasSnapshot() || m_pDisplayedSnapshot.isNull() || !nmFFmpegVideoWriter::isBackendAvailable(&sBackendError)) { @@ -1008,6 +1426,11 @@ void nmWxPebiResultViewWidget::onExportAnimationRequested() void nmWxPebiResultViewWidget::onScalarBarToggled(bool bVisible) { + if(m_pControlBar != nullptr && + m_pControlBar->isExternalInteractionLocked()) { + synchronizeBusinessActions(); + return; + } if(m_pSceneController != nullptr && m_pSceneController->hasSnapshot()) { m_pSceneController->setScalarBarVisible(bVisible); } @@ -1015,6 +1438,11 @@ void nmWxPebiResultViewWidget::onScalarBarToggled(bool bVisible) void nmWxPebiResultViewWidget::onScaleGridToggled(bool bVisible) { + if(m_pControlBar != nullptr && + m_pControlBar->isExternalInteractionLocked()) { + synchronizeBusinessActions(); + return; + } if(m_pSceneController != nullptr && m_pSceneController->hasSnapshot()) { m_pSceneController->setScaleGridVisible(bVisible); } @@ -1022,6 +1450,11 @@ void nmWxPebiResultViewWidget::onScaleGridToggled(bool bVisible) void nmWxPebiResultViewWidget::onWellNamesToggled(bool bVisible) { + if(m_pControlBar != nullptr && + m_pControlBar->isExternalInteractionLocked()) { + synchronizeBusinessActions(); + return; + } if(m_pSceneController != nullptr && m_pSceneController->hasSnapshot()) { m_pSceneController->setWellNamesVisible(bVisible); } @@ -1084,6 +1517,11 @@ void nmWxPebiResultViewWidget::createUi() QIcon(resultViewIconPath("NmFilter.png")), tr("Data Filtering..."), this); m_pFilterAction->setToolTip(m_pFilterAction->text()); + m_pRegionPressureAction = new QAction( + QIcon(resultViewIconPath("NmPolygon.png")), + tr("Region Average Pressure"), this); + m_pRegionPressureAction->setToolTip( + m_pRegionPressureAction->text()); QAction* const pBusinessActions[] = { m_pScalarBarAction, m_pScaleGridAction, m_pWellNamesAction @@ -1121,6 +1559,7 @@ void nmWxPebiResultViewWidget::createUi() if(pPickCenterAction != nullptr) m_pToolBar->addAction(pPickCenterAction); m_pToolBar->addSeparator(); m_pToolBar->addAction(m_pFilterAction); + m_pToolBar->addAction(m_pRegionPressureAction); for(int nIndex = 0; nIndex < 3; ++nIndex) { m_pToolBar->addAction(pBusinessActions[nIndex]); } @@ -1136,6 +1575,8 @@ void nmWxPebiResultViewWidget::createUi() this, SLOT(onWellNamesToggled(bool))); connect(m_pFilterAction, SIGNAL(triggered()), this, SLOT(onShowFilterSettings())); + connect(m_pRegionPressureAction, SIGNAL(triggered()), + this, SLOT(onRegionPressureStatisticsTriggered())); connect(m_pRenderContainer, SIGNAL(contextMenuAboutToShow(QMenu*)), this, SLOT(appendContextMenuActions(QMenu*))); @@ -1161,7 +1602,7 @@ void nmWxPebiResultViewWidget::createUi() this, SLOT(synchronizeBusinessActions())); if(m_pControlBar->getPlaybackController() != nullptr) { connect(m_pControlBar->getPlaybackController(), SIGNAL(stateChanged()), - this, SLOT(synchronizeBusinessActions())); + this, SLOT(onResultDisplayStateChanged())); } pMainLayout->addWidget(m_pControlBar); @@ -1218,6 +1659,8 @@ void nmWxPebiResultViewWidget::synchronizeOnce() m_pDisplayedSnapshot = pSnapshot; m_sDisplayedSnapshotId = sSnapshotId; m_sBindingError.clear(); + // 只有新快照已经成功发布后才清旧区域;失败回滚必须完整保留旧统计。 + clearRegionPressureSelection(true); // 新成功绑定序号会让 Playback 和 ControlBar 同时重置各自缓存。 m_pControlBar->synchronizeFromScene(); synchronizeBusinessActions(); @@ -1258,6 +1701,7 @@ void nmWxPebiResultViewWidget::clearSceneAndControls( if(m_pControlBar != nullptr) { m_pControlBar->stopPlayback(); } + clearRegionPressureSelection(false); if(m_pSceneController != nullptr) { m_pSceneController->clear(); } @@ -1281,6 +1725,478 @@ void nmWxPebiResultViewWidget::clearSceneAndControls( } } +bool nmWxPebiResultViewWidget::startRegionPressureDrawing() +{ + nmPebiResultPlaybackController* pPlaybackController = + m_pControlBar == nullptr ? nullptr : + m_pControlBar->getPlaybackController(); + if(m_pRegionState == nullptr || m_pSceneController == nullptr || + m_pRenderContainer == nullptr || m_pControlBar == nullptr || + pPlaybackController == nullptr || + m_pRegionState->m_eState != + nmWxPebiResultRegionState::State_Idle || + !m_pSceneController->hasSnapshot() || + m_pDisplayedSnapshot.isNull() || + m_pSceneController->getCurrentPropertyId() != + QString::fromLatin1("pressure") || + m_pSceneController->getCurrentFrameIndex() < 0 || + pPlaybackController->isPlaying() || + m_pControlBar->isExportInProgress() || + m_pControlBar->isExternalInteractionLocked() || + !canProjectRegionOntoXyPlane( + m_pRenderContainer->getRenderer()) || + !ensureRegionPressureLayer()) { + return false; + } + + // 冻结绘制起点的完整显示身份,完成时会逐项复核。 + m_pRegionState->m_pFrozenSnapshot = m_pDisplayedSnapshot; + m_pRegionState->m_nFrozenBindingRevision = + m_pSceneController->getSnapshotBindingRevision(); + m_pRegionState->m_sFrozenSnapshotId = + m_pSceneController->getCurrentSnapshotId(); + m_pRegionState->m_sFrozenPropertyId = + m_pSceneController->getCurrentPropertyId(); + m_pRegionState->m_nFrozenFrameIndex = + m_pSceneController->getCurrentFrameIndex(); + if(m_pRegionState->m_nFrozenBindingRevision == 0 || + m_pRegionState->m_sFrozenSnapshotId.isEmpty() || + m_pRegionState->m_sFrozenSnapshotId != m_sDisplayedSnapshotId) { + m_pRegionState->m_pFrozenSnapshot.clear(); + return false; + } + + // 观察者只在本次绘制事务内有效,退出时必须在销毁回调前全部解除。 + m_pRegionState->m_pStyle = + vtkSmartPointer::New(); + m_pRegionState->m_pCallback = + vtkSmartPointer::New(); + m_pRegionState->m_pCallback->SetClientData(this); + m_pRegionState->m_pCallback->SetCallback( + &nmWxPebiResultViewWidget::handleRegionPolygonEvent); + m_pRegionState->m_nChangedObserverTag = + m_pRegionState->m_pStyle->AddObserver( + nmVTKPlanarPolygonInteractorStyle::PolygonChangedEvent, + m_pRegionState->m_pCallback); + m_pRegionState->m_nCompletedObserverTag = + m_pRegionState->m_pStyle->AddObserver( + nmVTKPlanarPolygonInteractorStyle::PolygonCompletedEvent, + m_pRegionState->m_pCallback); + m_pRegionState->m_nCancelledObserverTag = + m_pRegionState->m_pStyle->AddObserver( + nmVTKPlanarPolygonInteractorStyle::PolygonCancelledEvent, + m_pRegionState->m_pCallback); + m_pRegionState->m_nInvalidObserverTag = + m_pRegionState->m_pStyle->AddObserver( + nmVTKPlanarPolygonInteractorStyle::PolygonInvalidEvent, + m_pRegionState->m_pCallback); + + if(!m_pRenderContainer->installInteractionStyle( + m_pRegionState->m_pStyle)) { + stopRegionPressureDrawing(); + return false; + } + + m_pRegionState->m_oCalculator.clear(); + m_pRegionState->m_pLayer->clear(); + if(m_pRegionState->m_pDialog != nullptr) { + m_pRegionState->m_pDialog->hide(); + } + // 交互样式安装成功后再锁定底栏,避免失败路径遗留禁用控件。 + m_pRegionState->m_eState = + nmWxPebiResultRegionState::State_Drawing; + m_pControlBar->setExternalInteractionLocked(true); + synchronizeBusinessActions(); + m_pRenderContainer->renderView(); + return true; +} + +void nmWxPebiResultViewWidget::stopRegionPressureDrawing() +{ + if(m_pRegionState == nullptr) { + return; + } + + // 先移除 VTK 观察者并清空 ClientData,再恢复默认相机交互。 + if(m_pRegionState->m_pStyle != nullptr) { + if(m_pRegionState->m_nChangedObserverTag != 0) { + m_pRegionState->m_pStyle->RemoveObserver( + m_pRegionState->m_nChangedObserverTag); + } + if(m_pRegionState->m_nCompletedObserverTag != 0) { + m_pRegionState->m_pStyle->RemoveObserver( + m_pRegionState->m_nCompletedObserverTag); + } + if(m_pRegionState->m_nCancelledObserverTag != 0) { + m_pRegionState->m_pStyle->RemoveObserver( + m_pRegionState->m_nCancelledObserverTag); + } + if(m_pRegionState->m_nInvalidObserverTag != 0) { + m_pRegionState->m_pStyle->RemoveObserver( + m_pRegionState->m_nInvalidObserverTag); + } + } + if(m_pRegionState->m_pCallback != nullptr) { + m_pRegionState->m_pCallback->SetClientData(nullptr); + } + + m_pRegionState->m_nChangedObserverTag = 0; + m_pRegionState->m_nCompletedObserverTag = 0; + m_pRegionState->m_nCancelledObserverTag = 0; + m_pRegionState->m_nInvalidObserverTag = 0; + if(m_pRenderContainer != nullptr && + m_pRegionState->m_pStyle != nullptr) { + m_pRenderContainer->restoreDefaultInteraction(); + } + m_pRegionState->m_pStyle = nullptr; + m_pRegionState->m_pCallback = nullptr; + m_pRegionState->m_ePendingEvent = + nmWxPebiResultRegionState::PendingEvent_None; + m_pRegionState->m_bPendingEventQueued = false; + m_pRegionState->m_vecPendingPoints.clear(); + m_pRegionState->m_pFrozenSnapshot.clear(); + m_pRegionState->m_nFrozenBindingRevision = 0; + m_pRegionState->m_sFrozenSnapshotId.clear(); + m_pRegionState->m_sFrozenPropertyId.clear(); + m_pRegionState->m_nFrozenFrameIndex = -1; + if(m_pControlBar != nullptr) { + m_pControlBar->setExternalInteractionLocked(false); + } +} + +void nmWxPebiResultViewWidget::clearRegionPressureSelection( + bool bRenderView) +{ + if(m_pRegionState == nullptr) { + return; + } + + nmVTKScene* pScene = m_pRenderContainer == nullptr + ? nullptr : m_pRenderContainer->getScene(); + // 裸指针只在 Scene 仍持有同一图层时可用,失败回滚后不访问旧对象。 + const bool bLayerIsCurrent = pScene != nullptr && + m_pRegionState->m_pLayer != nullptr && + pScene->getLayer(QString::fromLatin1( + PEBI_REGION_PRESSURE_LAYER_ID)) == + m_pRegionState->m_pLayer; + const bool bHadVisibleRegion = + m_pRegionState->m_eState != + nmWxPebiResultRegionState::State_Idle || + (bLayerIsCurrent && + !m_pRegionState->m_pLayer->getPoints().isEmpty()); + stopRegionPressureDrawing(); + + if(bLayerIsCurrent) { + m_pRegionState->m_pLayer->clear(); + } else { + m_pRegionState->m_pLayer = nullptr; + } + + m_pRegionState->m_oCalculator.clear(); + m_pRegionState->m_eState = + nmWxPebiResultRegionState::State_Idle; + m_pRegionState->m_nRegionBindingRevision = 0; + m_pRegionState->m_sRegionSnapshotId.clear(); + m_pRegionState->m_sLastObservedPropertyId.clear(); + m_pRegionState->m_nLastAttemptedFrameIndex = -1; + m_pRegionState->m_bStatisticsCalculated = false; + m_pRegionState->m_sStatisticsError.clear(); + m_pRegionState->m_oStatistics.clear(); + if(m_pRegionState->m_pDialog != nullptr) { + m_pRegionState->m_pDialog->hide(); + } + synchronizeBusinessActions(); + if(bRenderView && bHadVisibleRegion && + m_pRenderContainer != nullptr) { + m_pRenderContainer->renderView(); + } +} + +void nmWxPebiResultViewWidget::destroyRegionPressureState() +{ + if(m_pRegionState == nullptr) { + return; + } + + clearRegionPressureSelection(false); + nmVTKScene* pScene = m_pRenderContainer == nullptr + ? nullptr : m_pRenderContainer->getScene(); + if(pScene != nullptr && m_pRegionState->m_pLayer != nullptr && + pScene->getLayer(QString::fromLatin1( + PEBI_REGION_PRESSURE_LAYER_ID)) == m_pRegionState->m_pLayer) { + pScene->removeLayer(QString::fromLatin1( + PEBI_REGION_PRESSURE_LAYER_ID)); + } + m_pRegionState->m_pLayer = nullptr; + if(m_pRegionState->m_pDialog != nullptr) { + delete m_pRegionState->m_pDialog; + m_pRegionState->m_pDialog = nullptr; + } + delete m_pRegionState; + m_pRegionState = nullptr; +} + +bool nmWxPebiResultViewWidget::ensureRegionPressureLayer() +{ + if(m_pRegionState == nullptr || m_pRenderContainer == nullptr || + m_pRenderContainer->getScene() == nullptr) { + return false; + } + + nmVTKScene* pScene = m_pRenderContainer->getScene(); + nmVTKRenderLayer* pExisting = pScene->getLayer( + QString::fromLatin1(PEBI_REGION_PRESSURE_LAYER_ID)); + if(pExisting != nullptr) { + return m_pRegionState->m_pLayer != nullptr && + pExisting == m_pRegionState->m_pLayer; + } + + m_pRegionState->m_pLayer = nullptr; + nmVTKPlanarPolygonLayer* pCandidate = + new nmVTKPlanarPolygonLayer(QString::fromLatin1( + PEBI_REGION_PRESSURE_LAYER_ID)); + if(!pScene->addLayer(pCandidate)) { + delete pCandidate; + return false; + } + m_pRegionState->m_pLayer = pCandidate; + return true; +} + +bool nmWxPebiResultViewWidget::isRegionPressureDrawing() const +{ + return m_pRegionState != nullptr && + m_pRegionState->m_eState == + nmWxPebiResultRegionState::State_Drawing; +} + +void nmWxPebiResultViewWidget::updateRegionPressureStatistics() +{ + // 静态属性下冻结最后一帧结果;只有显示 pressure 时才跟随帧变化重算。 + if(m_pRegionState == nullptr || m_pSceneController == nullptr || + m_pRegionState->m_eState != + nmWxPebiResultRegionState::State_Completed || + !m_pRegionState->m_oCalculator.isPrepared() || + !m_pSceneController->hasSnapshot() || + m_pSceneController->getSnapshotBindingRevision() != + m_pRegionState->m_nRegionBindingRevision || + m_pSceneController->getCurrentSnapshotId() != + m_pRegionState->m_sRegionSnapshotId || + m_pSceneController->getCurrentPropertyId() != + QString::fromLatin1("pressure")) { + return; + } + + const int nFrameIndex = m_pSceneController->getCurrentFrameIndex(); + if(nFrameIndex < 0 || + nFrameIndex == m_pRegionState->m_nLastAttemptedFrameIndex) { + return; + } + + // 先登记尝试帧,保证一个状态信号周期内同一帧最多进行一轮重计算。 + m_pRegionState->m_nLastAttemptedFrameIndex = nFrameIndex; + nmPebiRegionPressureStatistics oStatistics; + QString sError; + m_pRegionState->m_bStatisticsCalculated = + m_pRegionState->m_oCalculator.calculateFrame( + nFrameIndex, oStatistics, &sError); + m_pRegionState->m_sStatisticsError = sError; + if(m_pRegionState->m_bStatisticsCalculated) { + m_pRegionState->m_oStatistics = oStatistics; + } + refreshRegionPressureStatisticsDialog(); +} + +void nmWxPebiResultViewWidget::ensureRegionPressureStatisticsDialog() +{ + if(m_pRegionState == nullptr || m_pRegionState->m_pDialog != nullptr) { + return; + } + + iDlgBase* pDialog = new iDlgBase(this); + pDialog->setWindowTitle(tr("Region Average Pressure")); + pDialog->setWindowModality(Qt::NonModal); + pDialog->setModal(false); + pDialog->setAttribute(Qt::WA_DeleteOnClose, false); + pDialog->setWindowFlags( + pDialog->windowFlags() & + ~Qt::WindowContextHelpButtonHint); + + QVBoxLayout* pMainLayout = new QVBoxLayout(pDialog); + pMainLayout->setContentsMargins(12, 10, 12, 10); + pMainLayout->setSpacing(8); + + QGroupBox* pStatisticsGroup = new QGroupBox( + tr("Statistics"), pDialog); + QGridLayout* pStatisticsLayout = new QGridLayout(pStatisticsGroup); + pStatisticsLayout->setContentsMargins(8, 15, 8, 10); + pStatisticsLayout->setHorizontalSpacing(6); + pStatisticsLayout->setVerticalSpacing(6); + pStatisticsLayout->setColumnStretch(0, 0); + pStatisticsLayout->setColumnStretch(1, 8); + pStatisticsLayout->setColumnStretch(2, 5); + + m_pRegionState->m_pAveragePressureUnitCombo = + createRegionUnitCombo(pStatisticsGroup, + QString::fromLatin1("MPa")); + m_pRegionState->m_pMinimumPressureUnitCombo = + createRegionUnitCombo(pStatisticsGroup, + QString::fromLatin1("MPa")); + m_pRegionState->m_pMaximumPressureUnitCombo = + createRegionUnitCombo(pStatisticsGroup, + QString::fromLatin1("MPa")); + m_pRegionState->m_pPressureTimeUnitCombo = + createRegionUnitCombo(pStatisticsGroup, + QString::fromLatin1("h")); + + int nRow = 0; + m_pRegionState->m_pAveragePressureValue = addRegionStatisticsRow( + pStatisticsLayout, nRow++, tr("Region average pressure"), + pStatisticsGroup, + m_pRegionState->m_pAveragePressureUnitCombo); + m_pRegionState->m_pAveragePressureValue->setToolTip(tr( + "Weighted by cell area, thickness and porosity.")); + m_pRegionState->m_pMinimumPressureValue = addRegionStatisticsRow( + pStatisticsLayout, nRow++, tr("Minimum pressure"), + pStatisticsGroup, + m_pRegionState->m_pMinimumPressureUnitCombo); + m_pRegionState->m_pMaximumPressureValue = addRegionStatisticsRow( + pStatisticsLayout, nRow++, tr("Maximum pressure"), + pStatisticsGroup, + m_pRegionState->m_pMaximumPressureUnitCombo); + m_pRegionState->m_pTimeValue = addRegionStatisticsRow( + pStatisticsLayout, nRow++, tr("Pressure time"), + pStatisticsGroup, + m_pRegionState->m_pPressureTimeUnitCombo); + m_pRegionState->m_pSelectedCellValue = addRegionStatisticsRow( + pStatisticsLayout, nRow++, tr("Selected cells"), + pStatisticsGroup); + m_pRegionState->m_pWarningLabel = new QLabel(pStatisticsGroup); + m_pRegionState->m_pWarningLabel->setWordWrap(true); + m_pRegionState->m_pWarningLabel->setStyleSheet( + "QLabel { color: #a32626; }"); + m_pRegionState->m_pWarningLabel->hide(); + pStatisticsLayout->addWidget( + m_pRegionState->m_pWarningLabel, nRow++, 0, 1, 3); + pMainLayout->addWidget(pStatisticsGroup); + + QHBoxLayout* pButtonLayout = new QHBoxLayout; + pButtonLayout->setContentsMargins(0, 0, 0, 0); + pButtonLayout->setSpacing(6); + pButtonLayout->addStretch(1); + QPushButton* pCloseButton = new QPushButton(tr("Close"), pDialog); + const QSize oFooterIconSize(16, 16); + pCloseButton->setIcon(QIcon(resultViewIconPath("Close.png"))); + pCloseButton->setIconSize(oFooterIconSize); + pCloseButton->setMinimumWidth(72); + pCloseButton->setDefault(true); + pButtonLayout->addWidget(pCloseButton); + pMainLayout->addLayout(pButtonLayout); + + connect(pCloseButton, SIGNAL(clicked()), + this, SLOT(onCloseRegionPressureStatistics())); + connect(pDialog, SIGNAL(rejected()), + this, SLOT(onCloseRegionPressureStatistics())); + m_pRegionState->m_pDialog = pDialog; + pDialog->setMinimumWidth(460); + pDialog->adjustSize(); +} + +void nmWxPebiResultViewWidget::refreshRegionPressureStatisticsDialog() +{ + if(m_pRegionState == nullptr || m_pRegionState->m_pDialog == nullptr) { + return; + } + + const QString sUnavailable = QString::fromLatin1("--"); + if(!m_pRegionState->m_bStatisticsCalculated) { + QLineEdit* const pValues[] = { + m_pRegionState->m_pAveragePressureValue, + m_pRegionState->m_pMinimumPressureValue, + m_pRegionState->m_pMaximumPressureValue, + m_pRegionState->m_pTimeValue, + m_pRegionState->m_pSelectedCellValue + }; + const int nValueCount = sizeof(pValues) / sizeof(pValues[0]); + for(int nIndex = 0; nIndex < nValueCount; ++nIndex) { + pValues[nIndex]->setText(sUnavailable); + } + m_pRegionState->m_pWarningLabel->setText( + tr("Unable to calculate region average pressure.")); + m_pRegionState->m_pWarningLabel->show(); + return; + } + + const nmPebiRegionPressureStatistics& oStatistics = + m_pRegionState->m_oStatistics; + + m_pRegionState->m_pTimeValue->setText( + formatRegionValue(oStatistics.m_dPressureTimeHours)); + m_pRegionState->m_pSelectedCellValue->setText( + QString::number(static_cast( + oStatistics.m_nIntersectingCellCount))); + if(oStatistics.m_bAvailable) { + m_pRegionState->m_pAveragePressureValue->setText( + formatRegionValue( + oStatistics.m_dPoreVolumeWeightedPressureMpa)); + m_pRegionState->m_pMinimumPressureValue->setText( + formatRegionValue(oStatistics.m_dMinimumPressureMpa)); + m_pRegionState->m_pMaximumPressureValue->setText( + formatRegionValue(oStatistics.m_dMaximumPressureMpa)); + } else { + m_pRegionState->m_pAveragePressureValue->setText(sUnavailable); + m_pRegionState->m_pMinimumPressureValue->setText(sUnavailable); + m_pRegionState->m_pMaximumPressureValue->setText(sUnavailable); + } + + if(oStatistics.m_nIntersectingCellCount == 0) { + m_pRegionState->m_pWarningLabel->setText( + tr("No cells intersect the selected region.")); + m_pRegionState->m_pWarningLabel->show(); + } else if(!oStatistics.m_bAvailable) { + m_pRegionState->m_pWarningLabel->setText(tr( + "No valid cells are available for region average pressure.")); + m_pRegionState->m_pWarningLabel->show(); + } else if(oStatistics.m_nIgnoredCellCount > 0) { + m_pRegionState->m_pWarningLabel->setText(tr( + "%1 selected cells were excluded because their data is invalid.").arg( + static_cast( + oStatistics.m_nIgnoredCellCount))); + m_pRegionState->m_pWarningLabel->show(); + } else { + m_pRegionState->m_pWarningLabel->clear(); + m_pRegionState->m_pWarningLabel->hide(); + } +} + +void nmWxPebiResultViewWidget::showRegionPressureStatisticsDialog() +{ + nmVTKScene* pScene = m_pRenderContainer == nullptr + ? nullptr : m_pRenderContainer->getScene(); + if(m_pRegionState == nullptr || m_pSceneController == nullptr || + m_pRegionState->m_eState != + nmWxPebiResultRegionState::State_Completed || + !m_pRegionState->m_oCalculator.isPrepared() || + !m_pSceneController->hasSnapshot() || + m_pSceneController->getSnapshotBindingRevision() != + m_pRegionState->m_nRegionBindingRevision || + m_pSceneController->getCurrentSnapshotId() != + m_pRegionState->m_sRegionSnapshotId || + pScene == nullptr || m_pRegionState->m_pLayer == nullptr || + pScene->getLayer(QString::fromLatin1( + PEBI_REGION_PRESSURE_LAYER_ID)) != m_pRegionState->m_pLayer) { + return; + } + ensureRegionPressureStatisticsDialog(); + synchronizeBusinessActions(); + refreshRegionPressureStatisticsDialog(); + if(m_pRegionState->m_pDialog != nullptr) { + m_pRegionState->m_pDialog->show(); + m_pRegionState->m_pDialog->raise(); + m_pRegionState->m_pDialog->activateWindow(); + } +} + void nmWxPebiResultViewWidget::rememberObservedState( const QSharedPointer& pSnapshot, const QString& sSnapshotId, @@ -1305,19 +2221,55 @@ void nmWxPebiResultViewWidget::synchronizeBusinessActions() m_pWellNamesAction, m_pSceneController->areWellNamesVisible()); const bool bEnabled = m_pSceneController->hasSnapshot(); - m_pScalarBarAction->setEnabled(bEnabled); - m_pScaleGridAction->setEnabled(bEnabled); - m_pWellNamesAction->setEnabled(bEnabled); nmPebiResultPlaybackController* pPlaybackController = m_pControlBar == nullptr ? nullptr : m_pControlBar->getPlaybackController(); + const bool bPlaying = pPlaybackController != nullptr && + pPlaybackController->isPlaying(); + const bool bExporting = m_pControlBar != nullptr && + m_pControlBar->isExportInProgress(); + const bool bExternallyLocked = m_pControlBar != nullptr && + m_pControlBar->isExternalInteractionLocked(); + const bool bDrawing = isRegionPressureDrawing(); + nmVTKScene* pScene = m_pRenderContainer == nullptr + ? nullptr : m_pRenderContainer->getScene(); + const bool bCompleted = m_pRegionState != nullptr && + m_pRegionState->m_eState == + nmWxPebiResultRegionState::State_Completed && + m_pRegionState->m_oCalculator.isPrepared() && + bEnabled && + m_pSceneController->getSnapshotBindingRevision() == + m_pRegionState->m_nRegionBindingRevision && + m_pSceneController->getCurrentSnapshotId() == + m_pRegionState->m_sRegionSnapshotId && + pScene != nullptr && m_pRegionState->m_pLayer != nullptr && + pScene->getLayer(QString::fromLatin1( + PEBI_REGION_PRESSURE_LAYER_ID)) == + m_pRegionState->m_pLayer; + const bool bBusinessVisibilityEnabled = bEnabled && !bDrawing; + m_pScalarBarAction->setEnabled(bBusinessVisibilityEnabled); + m_pScaleGridAction->setEnabled(bBusinessVisibilityEnabled); + m_pWellNamesAction->setEnabled(bBusinessVisibilityEnabled); const bool bFilterEnabled = bEnabled && pPlaybackController != nullptr && - !pPlaybackController->isPlaying() && - !m_pControlBar->isExportInProgress(); + !bPlaying && !bExporting && !bExternallyLocked && !bDrawing; if(m_pFilterAction != nullptr) { m_pFilterAction->setEnabled(bFilterEnabled); } + if(m_pRegionPressureAction != nullptr) { + const bool bCanStart = bEnabled && + m_pSceneController->getCurrentPropertyId() == + QString::fromLatin1("pressure"); + const bool bRegionEnabled = bDrawing || bCompleted || + (!bExternallyLocked && !bPlaying && !bExporting && + bCanStart); + m_pRegionPressureAction->setEnabled(bRegionEnabled); + const QString sActionText = bDrawing + ? tr("Cancel Region Drawing") + : tr("Region Average Pressure"); + m_pRegionPressureAction->setText(sActionText); + m_pRegionPressureAction->setToolTip(sActionText); + } } void nmWxPebiResultViewWidget::refreshStatusBar() diff --git a/Src4/nmNum/nmRender/nmRender.pro b/Src4/nmNum/nmRender/nmRender.pro index 1a690f0b..dfd9fa32 100644 --- a/Src4/nmNum/nmRender/nmRender.pro +++ b/Src4/nmNum/nmRender/nmRender.pro @@ -21,6 +21,8 @@ SOURCES += $${wtSrc}/nmNum/nmRender/nmVTKCameraController.cpp \ $${wtSrc}/nmNum/nmRender/nmVTKImageExporter.cpp \ $${wtSrc}/nmNum/nmRender/nmVTKInteractionManager.cpp \ $${wtSrc}/nmNum/nmRender/nmVTKOrientationMarkerController.cpp \ + $${wtSrc}/nmNum/nmRender/nmVTKPlanarPolygonInteractorStyle.cpp \ + $${wtSrc}/nmNum/nmRender/nmVTKPlanarPolygonLayer.cpp \ $${wtSrc}/nmNum/nmRender/nmVTKPivotCameraInteractorStyle.cpp \ $${wtSrc}/nmNum/nmRender/nmVTKMeshLayer.cpp \ $${wtSrc}/nmNum/nmRender/nmVTKPlanarScaleGridLayer.cpp \ @@ -39,6 +41,8 @@ HEADERS += $${wtInclude}/nmNum/nmRender/nmRender_global.h \ $${wtInclude}/nmNum/nmRender/nmVTKImageExporter.h \ $${wtInclude}/nmNum/nmRender/nmVTKInteractionManager.h \ $${wtInclude}/nmNum/nmRender/nmVTKOrientationMarkerController.h \ + $${wtInclude}/nmNum/nmRender/nmVTKPlanarPolygonInteractorStyle.h \ + $${wtInclude}/nmNum/nmRender/nmVTKPlanarPolygonLayer.h \ $${wtInclude}/nmNum/nmRender/nmVTKPivotCameraInteractorStyle.h \ $${wtInclude}/nmNum/nmRender/nmVTKMeshLayer.h \ $${wtInclude}/nmNum/nmRender/nmVTKPlanarScaleGridLayer.h \