fix(nmNum): 修复 PEBI 网格划分时的 VTK 灰屏并简化底栏状态提示

feature/fix-result-persistence-20261118
lh 4 hours ago
parent 5efb2668d9
commit 66d01e3a99

Binary file not shown.

@ -3230,14 +3230,6 @@ No valid error was returned; keep the last accepted result and reduce the step.<
<source>Grid generation failed</source>
<translation>网格生成失败</translation>
</message>
<message>
<source>Grid generation failed.</source>
<translation>网格生成失败。</translation>
</message>
<message>
<source>Grid generation failed. Current view is the last successful grid.</source>
<translation>网格生成失败。当前显示的是上一次成功网格。</translation>
</message>
</context>
<context>
<name>nmPebiGridViewDataBuilder</name>
@ -3566,11 +3558,13 @@ No valid error was returned; keep the last accepted result and reduce the step.<
<message><source>Wireframe</source><translation>线框</translation></message>
<message><source>Surface</source><translation>表面</translation></message>
<message><source>Contour</source><translation>轮廓</translation></message>
<message><source>No grid data.</source><translation>暂无网格数据。</translation></message>
<message><source>Scale Grid</source><translation>比例网格</translation></message>
<message><source>The grid preview data is invalid.</source><translation>网格预览数据无效。</translation></message>
<message><source>PEBI | %1 valid cells | XY planar grid</source><translation>PEBI | %1 个有效单元 | XY 平面网格</translation></message>
<message><source>Generating grid...</source><translation>正在生成网格...</translation></message>
<message><source>Generating PEBI grid</source><translation>PEBI 网格划分中</translation></message>
<message><source>Regenerating PEBI grid</source><translation>PEBI 网格重划中</translation></message>
<message><source>PEBI grid generation failed.</source><translation>PEBI 网格划分失败。</translation></message>
<message><source>Showing the last successful grid.</source><translation>当前显示上一次成功划分的网格。</translation></message>
</context>
<context>
<name>nmSubWndMain</name>

@ -71,6 +71,8 @@ public:
/** @brief 设置工具栏和右键菜单可使用的通用命令集合。 */
void setViewCommandCapabilities(
nmVTKViewCommandController::ViewCommands eCommands);
/** @brief 启停工具栏和右键菜单的通用视图命令,保持当前视口页面。 */
void setViewCommandsAvailable(bool bAvailable);
/** @brief 设置相机适配、标准视图和重置中心优先使用的主内容边界。 */
bool setPrimaryViewBounds(const double dBounds[6]);

@ -3,6 +3,7 @@
#include "nmSubWxs_global.h"
#include <QString>
#include <QWidget>
class QAction;
@ -23,9 +24,8 @@ class nmWxVTKRenderContainerWidget;
* 右键菜单复用同一批 QAction;通用导航、旋转中心、截图和打印能力由
* 内部 nmRender 容器提供,不继承业务视图基类。
*
* 窗口状态由 setViewData/showLoading/showFailure/clearView 统一切换。
* 建网失败且存在旧数据时,场景继续显示上一次成功网格,黄色状态栏
* 单独提示失败原因;底部信息栏始终只描述当前保留的 PEBI 二维网格。
* VTK 视口持续显示当前网格或空场景。底栏左侧显示当前网格信息,
* 右侧显示划分状态或失败原因。
*/
class NM_SUB_WXS_EXPORT nmWxPebiGridViewWidget : public QWidget
{
@ -38,16 +38,20 @@ public:
/** @brief 装入完整数据并复用现有 Renderer、Scene、图层和工具栏。 */
bool setViewData(const nmPebiGridViewData& oViewData,
QString* pError = nullptr);
/** @brief 保留当前成功数据,只切换到渲染中状态页。 */
/** @brief 保留当前场景,在底栏显示划分进度。 */
void showLoading();
/** @brief 有旧数据时恢复画面并显示提示,否则显示错误状态页。 */
/** @brief 保留当前场景,在底栏显示失败原因。 */
void showFailure(const QString& sMessage);
/** @brief 清除旧分析网格和视图命令状态。 */
/** @brief 清除旧分析网格并重绘空场景。 */
void clearView();
/** @brief 当前场景是否保留一份绑定成功的网格数据。 */
bool hasViewData() const;
protected:
/** @brief 状态标签宽度变化时重新计算单行文字。 */
virtual bool eventFilter(QObject* pWatched, QEvent* pEvent);
private slots:
/** @brief 从 itemData 读取并提交当前窗口的网格显示模式。 */
void onDisplayModeIndexChanged(int nIndex);
@ -65,8 +69,13 @@ private:
void resetControls();
/** @brief 从 SceneController 镜像显示模式,且不触发用户选择槽。 */
void synchronizeDisplayModeFromScene();
/** @brief 统一启停依赖有效网格的业务动作。 */
/** @brief 统一启停网格显示控件和视图命令,保持 VTK 视口可见。 */
void setControlsEnabled(bool bEnabled);
/** @brief 更新底栏右侧状态,完整诊断通过悬停查看。 */
void setStatusMessage(const QString& sMessage,
const QString& sDetails = QString());
/** @brief 按标签当前宽度省略状态文字。 */
void updateStatusLabel();
nmWxVTKRenderContainerWidget* m_pRenderContainer; ///< Qt 父对象拥有的通用渲染容器。
nmPebiGridSceneController* m_pSceneController; ///< 本类独占,必须先于容器销毁。
@ -74,7 +83,8 @@ private:
QAction* m_pBoundsGridAction; ///< 工具栏和右键菜单共享的比例网格动作。
QComboBox* m_pDisplayModeCombo; ///< 显示模式框,itemData 保存 DisplayMode 枚举值。
QLabel* m_pGridInfoLabel; ///< 底栏左侧的网格类型、单元数和平面信息。
QLabel* m_pStatusLabel; ///< 建网失败且保留旧网格时使用的黄色提示栏。
QLabel* m_pStatusLabel; ///< 底栏右侧的单行状态标签。
QString m_sStatusMessage; ///< 省略前的单行状态文字。
bool m_bHasViewData; ///< 与场景控制器的成功数据状态保持同步。
};

@ -488,6 +488,13 @@ bool nmWxVTKRenderContainerWidget::restoreViewState(const nmVTKViewState& oState
return true;
}
void nmWxVTKRenderContainerWidget::setViewCommandsAvailable(bool bAvailable)
{
if(m_pViewCommandController != nullptr) {
m_pViewCommandController->setViewAvailable(bAvailable);
}
}
void nmWxVTKRenderContainerWidget::showReadyState()
{
Q_ASSERT(isGuiThread());
@ -496,9 +503,7 @@ void nmWxVTKRenderContainerWidget::showReadyState()
}
// 状态页与 VTK 页尺寸稳定,切换页面不会重建 RenderWindow 或 Renderer。
m_pStateStack->setCurrentWidget(m_pVtkWidget);
if(m_pViewCommandController != nullptr) {
m_pViewCommandController->setViewAvailable(true);
}
setViewCommandsAvailable(true);
updateRotationCenterMarkerVisibility();
if(m_pOrientationMarkerController != nullptr) {
m_pOrientationMarkerController->setViewAvailable(true);
@ -936,9 +941,7 @@ void nmWxVTKRenderContainerWidget::showMessageState(
// 非就绪状态先结束临时工具并清除手工标记,再禁用和取消 QAction。
cancelRotationCenterPicking();
hideRotationCenterMarker();
if(m_pViewCommandController != nullptr) {
m_pViewCommandController->setViewAvailable(false);
}
setViewCommandsAvailable(false);
if(m_pOrientationMarkerController != nullptr) {
m_pOrientationMarkerController->setViewAvailable(false);
}

@ -227,7 +227,7 @@ void nmSubWndGrid::initUI()
{
QWidget* mainWidget = new QWidget(this);
// 设置 mainWidget 的布局和尺寸策略
mainWidget->setLayout(new QStackedLayout(mainWidget)); // 加载背景和网格共用稳定显示区域。
mainWidget->setLayout(new QStackedLayout(mainWidget)); // 网格窗口复用同一视口。
mainWidget->layout()->setContentsMargins(0, 0, 0, 0); // 移除边距
mainWidget->layout()->setSpacing(0); // 移除间距
mainWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // 扩展策略
@ -237,8 +237,7 @@ void nmSubWndGrid::initUI()
// m_pMainLayout 应该直接是 mainWidget 的布局
m_pMainLayout = qobject_cast<QStackedLayout*>(mainWidget->layout());
// 通用渲染容器随窗口创建,但没有有效数据时不会创建业务 Mapper 或 Actor。
// 因此空数据、加载和失败都能复用同一状态页,不会落回黑色原生窗口。
// 通用渲染容器随窗口创建,空数据、加载和失败都保留 VTK 视口。
m_pGridView = new nmWxPebiGridViewWidget(mainWidget);
m_pGridView->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Expanding);
@ -395,7 +394,7 @@ void nmSubWndGrid::onPebiGridGenerated(bool success)
success = false;
}
// 第二步:提交成功后创建绑定最新网格的 VTK 页。失败或版本过期时,如果
// 第二步:提交成功后在现有 VTK 场景中绑定最新网格。失败或版本过期时,如果
// 没有排队中的更新,则恢复旧网格或显示失败状态,不能永久停留在加载文字。
if(success) {
showGridResult();
@ -437,7 +436,7 @@ void nmSubWndGrid::showGridLoading()
return;
}
// 已有成功视图时只切换其内部状态页,网格、Scene、Renderer 和相机均保留。
// 加载时仅更新底栏提示,保留当前 VTK 场景和相机。
m_pMainLayout->setCurrentWidget(m_pGridView);
m_pGridView->showLoading();
}
@ -485,17 +484,9 @@ void nmSubWndGrid::showGridFailure(const QString& reason)
return;
}
// 更新失败但旧网格仍可显示时保留旧成果;首次生成失败时在正常背景上给出
// 明确状态,避免用户把空白或黑屏误认为程序仍在计算。
// 将原始诊断交给视图,供底栏显示具体原因和悬停查看完整说明。
m_pMainLayout->setCurrentWidget(m_pGridView);
if(m_pGridView->hasViewData()) {
m_pGridView->showFailure(tr(
"Grid generation failed. Current view is the last successful grid.")
+ (reason.isEmpty() ? QString() : "\n" + reason));
} else {
m_pGridView->showFailure(tr("Grid generation failed.")
+ (reason.isEmpty() ? QString() : "\n" + reason));
}
m_pGridView->showFailure(reason);
}
bool nmSubWndGrid::rejectInvalidGridBoundary(nmDataAnalyzeManager* pDataManager)

@ -10,6 +10,7 @@
#include <QAction>
#include <QComboBox>
#include <QCoreApplication>
#include <QEvent>
#include <QHBoxLayout>
#include <QIcon>
#include <QLabel>
@ -48,7 +49,6 @@ nmWxPebiGridViewWidget::nmWxPebiGridViewWidget(QWidget* pParent)
synchronizeDisplayModeFromScene();
resetControls();
setControlsEnabled(false);
m_pRenderContainer->showEmptyState(tr("No grid data."));
}
nmWxPebiGridViewWidget::~nmWxPebiGridViewWidget()
@ -172,17 +172,6 @@ void nmWxPebiGridViewWidget::createUi()
pRenderLayout->addWidget(m_pToolBar);
pMainLayout->addWidget(pRenderArea, 1);
m_pStatusLabel = new QLabel(this);
m_pStatusLabel->setWordWrap(true);
m_pStatusLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
m_pStatusLabel->setStyleSheet(
"QLabel { color: rgb(126, 76, 0); "
"background-color: rgb(255, 244, 204); "
"border-top: 1px solid rgb(220, 190, 105); "
"padding: 4px 8px; }");
m_pStatusLabel->hide();
pMainLayout->addWidget(m_pStatusLabel);
// 显示模式属于当前预览窗口,业务控件不下沉到通用渲染容器。
QWidget* pControlBar = new QWidget(this);
QHBoxLayout* pControlLayout = new QHBoxLayout(pControlBar);
@ -215,11 +204,17 @@ void nmWxPebiGridViewWidget::createUi()
m_pGridInfoLabel = new QLabel(pControlBar);
m_pGridInfoLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
m_pStatusLabel = new QLabel(pControlBar);
m_pStatusLabel->setTextFormat(Qt::PlainText);
m_pStatusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
// 状态文字使用底栏剩余宽度,长诊断不撑宽底栏或挤占左侧控件。
m_pStatusLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred);
m_pStatusLabel->installEventFilter(this);
pControlLayout->addWidget(pDisplayLabel, 0, Qt::AlignVCenter);
pControlLayout->addWidget(m_pDisplayModeCombo);
pControlLayout->addSpacing(2);
pControlLayout->addWidget(m_pGridInfoLabel);
pControlLayout->addStretch(1);
pControlLayout->addWidget(m_pStatusLabel, 1);
pMainLayout->addWidget(pControlBar);
connect(m_pDisplayModeCombo, SIGNAL(currentIndexChanged(int)),
@ -252,7 +247,7 @@ bool nmWxPebiGridViewWidget::setViewData(
tr("PEBI | %1 valid cells | XY planar grid")
.arg(static_cast<qlonglong>(
oViewData.getValidCellCount())));
m_pStatusLabel->hide();
setStatusMessage(QString());
m_bHasViewData = true;
synchronizeDisplayModeFromScene();
setControlsEnabled(true);
@ -261,26 +256,32 @@ bool nmWxPebiGridViewWidget::setViewData(
void nmWxPebiGridViewWidget::showLoading()
{
m_pStatusLabel->hide();
// 保留当前 VTK 画面,建网状态只在底栏更新。
m_pRenderContainer->setRotationCenterPickingEnabled(false);
setControlsEnabled(false);
m_pRenderContainer->showRenderingState(tr("Generating grid..."));
setStatusMessage(m_bHasViewData
? tr("Regenerating PEBI grid")
: tr("Generating PEBI grid"));
}
void nmWxPebiGridViewWidget::showFailure(const QString& sMessage)
{
if(m_bHasViewData) {
// 失败时旧网格引用保持不变,状态条明确说明当前画面并非本次成果。
m_pRenderContainer->setRotationCenterPickingEnabled(false);
m_pStatusLabel->setText(sMessage);
m_pStatusLabel->show();
setControlsEnabled(true);
m_pRenderContainer->showReadyState();
} else {
m_pStatusLabel->hide();
m_pRenderContainer->setRotationCenterPickingEnabled(false);
if(!m_bHasViewData) {
resetControls();
setControlsEnabled(false);
m_pRenderContainer->showErrorState(sMessage);
}
QString sDetails = sMessage.trimmed();
if(sDetails.isEmpty()) {
sDetails = tr("PEBI grid generation failed.");
}
const QString sStatus = sDetails.section('\n', 0, 0).trimmed();
if(m_bHasViewData) {
sDetails += "\n" + tr("Showing the last successful grid.");
}
setStatusMessage(sStatus, sDetails);
setControlsEnabled(m_bHasViewData);
// 图层提交失败时,场景控制器已回滚,重绘当前场景。
m_pRenderContainer->renderView();
}
void nmWxPebiGridViewWidget::clearView()
@ -289,10 +290,10 @@ void nmWxPebiGridViewWidget::clearView()
m_pSceneController->clear();
}
m_bHasViewData = false;
m_pStatusLabel->hide();
resetControls();
setControlsEnabled(false);
m_pRenderContainer->showEmptyState(tr("No grid data."));
setStatusMessage(QString());
m_pRenderContainer->renderView();
}
bool nmWxPebiGridViewWidget::hasViewData() const
@ -313,6 +314,30 @@ void nmWxPebiGridViewWidget::setControlsEnabled(bool bEnabled)
{
m_pBoundsGridAction->setEnabled(bEnabled);
m_pDisplayModeCombo->setEnabled(bEnabled);
m_pRenderContainer->setViewCommandsAvailable(bEnabled);
}
bool nmWxPebiGridViewWidget::eventFilter(QObject* pWatched, QEvent* pEvent)
{
if(pWatched == m_pStatusLabel && pEvent->type() == QEvent::Resize) {
updateStatusLabel();
}
return QWidget::eventFilter(pWatched, pEvent);
}
void nmWxPebiGridViewWidget::setStatusMessage(const QString& sMessage,
const QString& sDetails)
{
m_sStatusMessage = sMessage;
m_pStatusLabel->setToolTip(sDetails.isEmpty() ? sMessage : sDetails);
updateStatusLabel();
}
void nmWxPebiGridViewWidget::updateStatusLabel()
{
m_pStatusLabel->setText(m_pStatusLabel->fontMetrics().elidedText(
m_sStatusMessage, Qt::ElideRight,
m_pStatusLabel->contentsRect().width()));
}
void nmWxPebiGridViewWidget::synchronizeDisplayModeFromScene()

Loading…
Cancel
Save