diff --git a/Bin/Config/Lang/cn/nmNum_cn.qm b/Bin/Config/Lang/cn/nmNum_cn.qm
index 10778061..53099f7b 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 026cd99c..3551f2d0 100644
--- a/Bin/Config/Lang/cn/nmNum_cn.ts
+++ b/Bin/Config/Lang/cn/nmNum_cn.ts
@@ -3454,6 +3454,10 @@ No valid error was returned; keep the last accepted result and reduce the step.<
nmWxPebiResultViewWidget
+
+ Load Slice Test Model
+ 加载切片测试模型
+
No result data.暂无结果数据。
Color Scale色标
Scale Grid比例网格
@@ -8955,6 +8959,22 @@ Average pressure in contour: %2 MPa
nmVolumeData
+
+ Slice Test Model
+ 切片测试模型
+
+
+ Test Layers
+ 测试分层
+
+
+ Test Gradient
+ 测试渐变
+
+
+ Not enough memory to create the slice test model.
+ 内存不足,无法创建切片测试模型。
+
Not enough memory to import the volume mesh.
内存不足,无法导入三维网格。
@@ -9062,8 +9082,8 @@ Average pressure in contour: %2 MPa
nmVolumeImportTask
- An unexpected error occurred while importing the volume mesh.
- 导入三维网格时发生意外错误。
+ An unexpected error occurred while loading the volume mesh.
+ 加载三维网格时发生意外错误。
@@ -9139,8 +9159,8 @@ Average pressure in contour: %2 MPa
应用
- Reset
- 重置
+ Restore
+ 还原
Close
@@ -9154,6 +9174,18 @@ Average pressure in contour: %2 MPa
Drag the center or outline to move the plane; drag arrows to rotate.
拖动中心手柄或平面轮廓移动平面,拖动箭头旋转平面。
+
+ Move the plane origin to the model center without changing its normal.
+ 将切片原点移到模型中心,保持法向不变。
+
+
+ Set the plane parallel to %1 without changing its origin.
+ 将切片方向设为平行于 %1 平面,保持原点不变。
+
+
+ Restore the last applied plane parameters.
+ 恢复上次应用的平面参数。
+
nmDfnSession
diff --git a/Include/nmNum/nmData/nmVolumeDataBuilder.h b/Include/nmNum/nmData/nmVolumeDataBuilder.h
index ecc5f378..58300fea 100644
--- a/Include/nmNum/nmData/nmVolumeDataBuilder.h
+++ b/Include/nmNum/nmData/nmVolumeDataBuilder.h
@@ -3,10 +3,18 @@
#include "nmVolumeData.h"
-/** @brief 文件导入和未来三维求解器共用的发布入口,不保留输入对象的可写别名。 */
+/** @brief 文件导入、内置测试模型和未来三维求解器共用的发布入口,不保留输入对象的可写别名。 */
class NM_DATA_EXPORT nmVolumeDataBuilder
{
public:
+ /**
+ * @brief 在内存中生成切片测试模型,不读取文件,也不依赖分析或求解器。
+ * @note 模型为三层六面体网格,附带单元分层与节点渐变两种无量纲测试属性。
+ * 通过 buildFromGrid 校验并发布;失败或取消返回空指针,可在工作线程调用。
+ */
+ static QSharedPointer buildSliceTestModel(
+ QString* pError = nullptr, nmVolumeImportFeedback* pFeedback = nullptr);
+
/**
* @brief 完整复制、校验后返回只读数据;失败或取消返回空指针。
* @note 调用期间输入网格必须由调用方独占,不能被其他线程修改。
diff --git a/Include/nmNum/nmSubWxs/nmVolumeImportTask.h b/Include/nmNum/nmSubWxs/nmVolumeImportTask.h
index f3f0d235..c6f1c1f9 100644
--- a/Include/nmNum/nmSubWxs/nmVolumeImportTask.h
+++ b/Include/nmNum/nmSubWxs/nmVolumeImportTask.h
@@ -7,16 +7,24 @@
#include
/**
- * @brief 每个结果窗口独占的导入任务。
- * 工作线程只操作局部 Reader 和数据候选,不访问 QWidget、Renderer 或 Manager。
+ * @brief 每个结果窗口独占的三维模型加载任务,支持文件和内置切片测试模型。
+ * 工作线程只操作局部 Reader、测试网格和数据候选,不访问 QWidget、Renderer 或 Manager。
* 结果只允许在 finished 后读取;取消标志是唯一由两个线程同时访问的成员。
*/
class NM_SUB_WXS_EXPORT nmVolumeImportTask : public QThread, public nmVolumeImportFeedback
{
Q_OBJECT
public:
- /** @brief 保存输入路径,线程由调用方显式 start;父对象通常为结果窗口。 */
- explicit nmVolumeImportTask(const QString& sFilePath, QObject* pParent = nullptr);
+ /** @brief 显式区分数据来源,避免用特殊文件路径触发内置模型。 */
+ enum SourceType
+ {
+ FileSource, ///< 从指定的 VTK 文件读取体网格。
+ SliceTestModelSource ///< 在内存中生成固定的切片测试模型。
+ };
+
+ /** @brief 固定来源及输入路径(仅文件来源使用);线程由调用方显式 start。 */
+ explicit nmVolumeImportTask(SourceType eSourceType, const QString& sFilePath,
+ QObject* pParent = nullptr);
/** @brief 请求取消并等待安全退出,禁止释放仍运行的 VTK 代码资源。 */
virtual ~nmVolumeImportTask();
/** @brief 原子请求取消,可由 GUI 线程调用,不阻塞等待 Reader。 */
@@ -40,7 +48,8 @@ protected:
private:
Q_DISABLE_COPY(nmVolumeImportTask)
- QString m_sFilePath; ///< 创建时固定的输入路径,运行期间不再改写。
+ SourceType m_eSourceType; ///< 创建时固定的数据来源,工作线程据此选择加载方式。
+ QString m_sFilePath; ///< 文件来源的输入路径;内置测试模型不使用此字段。
mutable QAtomicInt m_nCancelRequested; ///< GUI 写入、工作线程读取的原子取消标志。
QSharedPointer m_pResult; ///< 工作线程写入,finished 后 GUI 才读取。
QString m_sError; ///< 工作线程写入的失败原因,finished 后读取。
diff --git a/Include/nmNum/nmSubWxs/nmWxPebiResultViewWidget.h b/Include/nmNum/nmSubWxs/nmWxPebiResultViewWidget.h
index 15bb1184..58e7286d 100644
--- a/Include/nmNum/nmSubWxs/nmWxPebiResultViewWidget.h
+++ b/Include/nmNum/nmSubWxs/nmWxPebiResultViewWidget.h
@@ -25,6 +25,7 @@ class iUnitGroup;
class nmDataAnalyzeManager;
class nmWxPebiResultRegionState;
class nmWxPebiVolumeState;
+class nmVolumeImportTask;
struct nmVolumeSliceSettings;
class nmPebiResultSceneController;
class nmPebiResultSnapshot;
@@ -210,7 +211,7 @@ public:
* @return 已启动任务返回 true;忙碌或路径为空返回 false,当前画面不变。
*/
bool importVolumeFile(const QString& sFilePath);
- /** @brief 返回当前是否正在显示外部三维数据,而非正式计算结果。 */
+ /** @brief 返回当前是否显示独立三维模型(文件导入或内置测试模型),而非正式计算结果。 */
bool isImportedVolumeMode() const;
private slots:
@@ -236,9 +237,11 @@ private slots:
void refreshVolumeSliceView();
/** @brief 从切片菜单选择文件,再启动可取消后台导入。 */
void onImportVolumeRequested();
+ /** @brief 从切片菜单启动内置测试模型加载,无需选择外部文件。 */
+ void onLoadSliceTestModelRequested();
/** @brief 原子标记取消;不等待或强行终止 Reader。 */
void onCancelVolumeImport();
- /** @brief 在线程结束后准备候选场景,成功才提交外部模型画面。 */
+ /** @brief 在线程结束后准备候选场景,成功才提交三维模型画面。 */
void onVolumeImportFinished();
/** @brief 返回仍有效的原结果或最新结果;绑定失败保留外部模型。 */
void onReturnToCalculationResult();
@@ -295,6 +298,11 @@ private:
void disconnectDataManager();
/** @brief 汇总播放、导出、绘制和导入任务状态,判定是否允许开始导入。 */
bool canImportVolume() const;
+ /**
+ * @brief 接管未启动的加载任务,统一连接进度、取消及场景提交回调。
+ * @note 调用者须先在 GUI 线程检查 canImportVolume;任务的父对象应为本窗口。
+ */
+ void startVolumeLoad(nmVolumeImportTask* pTask);
/** @brief 同步切片菜单及外部模式下的业务动作,不触发渲染。 */
void synchronizeVolumeActions();
/** @brief 关闭参数窗口并解绑平面,不渲染;释放数据时同时解除对旧模型的引用。 */
diff --git a/Include/nmNum/nmSubWxs/nmWxVolumeSliceSettingsDlg.h b/Include/nmNum/nmSubWxs/nmWxVolumeSliceSettingsDlg.h
index d281855b..a8e9d9f2 100644
--- a/Include/nmNum/nmSubWxs/nmWxVolumeSliceSettingsDlg.h
+++ b/Include/nmNum/nmSubWxs/nmWxVolumeSliceSettingsDlg.h
@@ -21,7 +21,7 @@ public:
explicit nmWxVolumeSliceSettingsDlg(QWidget* pParent = nullptr);
/** @brief 更换当前模型及已应用参数,清除前一模型的草稿和错误。 */
void setData(const QSharedPointer& pData, const nmVolumeSliceSettings& oApplied);
- /** @brief 提交成功后同步归一化参数,同时更新重置目标。 */
+ /** @brief 提交成功后同步归一化参数,同时更新“还原”操作的目标。 */
void setAppliedSettings(const nmVolumeSliceSettings& oSettings);
/** @brief 同步底栏已应用的着色属性,保留原点和法向的未应用草稿。 */
void setAppliedProperty(const QString& sPropertyId);
@@ -53,15 +53,18 @@ private slots:
void onAxisRequested();
/** @brief 将草稿原点移到模型中心,保持法向与属性。 */
void onCenterRequested();
- /** @brief 恢复最后已应用参数并同步辅助平面。 */
- void onResetRequested();
+ /** @brief 撤销未应用的平面编辑,恢复最近一次成功应用的参数并同步辅助平面。 */
+ void onRestoreRequested();
/** @brief 校验有效后请求宿主提交当前草稿。 */
void onApplyRequested();
/** @brief 更新已应用状态中的显示偏好,不提交原点和法向草稿。 */
void onDisplayOptionsChanged();
private:
- /** @brief 按现有参数窗口样式创建分组、对齐的编辑控件及固定顺序的底部按钮。 */
+ /**
+ * @brief 按统一参数窗口样式创建分组、编辑控件及“还原、应用、关闭”按钮。
+ * @note 字体和主题决定推荐尺寸,输入列横向伸展;参数与快捷操作沿用原有预览、应用流程。
+ */
void createUi();
/** @brief 阻止信号递归地把值对象写入所有控件,然后更新校验提示。 */
void writeSettings(const nmVolumeSliceSettings& oSettings);
diff --git a/Src/nmNum/nmData/nmVolumeDataBuilder.cpp b/Src/nmNum/nmData/nmVolumeDataBuilder.cpp
index 2aae981c..236d79d3 100644
--- a/Src/nmNum/nmData/nmVolumeDataBuilder.cpp
+++ b/Src/nmNum/nmData/nmVolumeDataBuilder.cpp
@@ -30,6 +30,10 @@ static const char* const s_pVolumeTranslationMarkers[] = {
QT_TRANSLATE_NOOP("nmVolumeData", "The mesh contains non-finite coordinates."),
QT_TRANSLATE_NOOP("nmVolumeData", "The mesh contains repeated cell vertices."),
QT_TRANSLATE_NOOP("nmVolumeData", "The mesh must have a finite extent in all three directions."),
+ QT_TRANSLATE_NOOP("nmVolumeData", "Slice Test Model"),
+ QT_TRANSLATE_NOOP("nmVolumeData", "Test Layers"),
+ QT_TRANSLATE_NOOP("nmVolumeData", "Test Gradient"),
+ QT_TRANSLATE_NOOP("nmVolumeData", "Not enough memory to create the slice test model."),
QT_TRANSLATE_NOOP("nmVolumeData", "Volume import canceled.")
};
@@ -57,6 +61,90 @@ int expectedPointCount(int nCellType)
}
}
+QSharedPointer nmVolumeDataBuilder::buildSliceTestModel(
+ QString* pError, nmVolumeImportFeedback* pFeedback)
+{
+ if(pError != nullptr) pError->clear();
+ QString sError;
+ try {
+ do {
+ if(canceled(pFeedback)) break;
+ if(pFeedback != nullptr) pFeedback->reportProgress(0);
+
+ // 固定小网格便于重复测试:5184 个六面体、6175 个共享节点。
+ // 三轴范围为 [-120,120]、[-90,90]、[-60,60],初始截面经过原点。
+ const int nXCells = 24;
+ const int nYCells = 18;
+ const int nZCells = 12;
+ const double dSpacing = 10.0;
+ const vtkIdType nRowStride = nXCells + 1;
+ const vtkIdType nPlaneStride = nRowStride * (nYCells + 1);
+ const vtkIdType nPointCount = nPlaneStride * (nZCells + 1);
+ const vtkIdType nCellCount = nXCells * nYCells * nZCells;
+ vtkSmartPointer pPoints = vtkSmartPointer::New();
+ pPoints->SetDataTypeToDouble();
+ pPoints->SetNumberOfPoints(nPointCount);
+ vtkSmartPointer pGradient = vtkSmartPointer::New();
+ pGradient->SetName(volumeText("Test Gradient").toUtf8().constData());
+ pGradient->SetNumberOfComponents(1);
+ pGradient->SetNumberOfTuples(nPointCount);
+ for(int nZ = 0; nZ <= nZCells; ++nZ) {
+ if(canceled(pFeedback)) break;
+ for(int nY = 0; nY <= nYCells; ++nY) {
+ for(int nX = 0; nX <= nXCells; ++nX) {
+ const vtkIdType nPoint = nZ * nPlaneStride + nY * nRowStride + nX;
+ pPoints->SetPoint(nPoint, (nX - nXCells / 2) * dSpacing,
+ (nY - nYCells / 2) * dSpacing, (nZ - nZCells / 2) * dSpacing);
+ // 三个方向权重不同,斜切时也能辨认方向;范围 0~100,原点值为 50。
+ const double dGradient = 100.0 * (double(nX) / nXCells +
+ 2.0 * nY / nYCells + 3.0 * nZ / nZCells) / 6.0;
+ pGradient->SetValue(nPoint, dGradient);
+ }
+ }
+ if(pFeedback != nullptr) pFeedback->reportProgress(25 * (nZ + 1) / (nZCells + 1));
+ }
+ if(canceled(pFeedback)) break;
+
+ vtkSmartPointer pGrid = vtkSmartPointer::New();
+ pGrid->SetPoints(pPoints);
+ pGrid->Allocate(nCellCount);
+ vtkSmartPointer pLayers = vtkSmartPointer::New();
+ pLayers->SetName(volumeText("Test Layers").toUtf8().constData());
+ pLayers->SetNumberOfComponents(1);
+ pLayers->SetNumberOfTuples(nCellCount);
+ for(int nZ = 0; nZ < nZCells; ++nZ) {
+ if(canceled(pFeedback)) break;
+ for(int nY = 0; nY < nYCells; ++nY) {
+ for(int nX = 0; nX < nXCells; ++nX) {
+ const vtkIdType nBase = nZ * nPlaneStride + nY * nRowStride + nX;
+ // 按 VTK_HEXAHEDRON 的底面、顶面顺序连接;相邻单元共享节点。
+ vtkIdType aPoints[8] = {
+ nBase, nBase + 1, nBase + nRowStride + 1, nBase + nRowStride,
+ nBase + nPlaneStride, nBase + nPlaneStride + 1,
+ nBase + nPlaneStride + nRowStride + 1, nBase + nPlaneStride + nRowStride
+ };
+ const vtkIdType nCell = pGrid->InsertNextCell(VTK_HEXAHEDRON, 8, aPoints);
+ // 自下而上分为 1、2、3 层,界面位于 Z=-20、Z=20;仅供显示测试。
+ pLayers->SetValue(nCell, 1 + nZ / (nZCells / 3));
+ }
+ }
+ if(pFeedback != nullptr) pFeedback->reportProgress(25 + 30 * (nZ + 1) / nZCells);
+ }
+ if(canceled(pFeedback)) break;
+ // 默认按单元分层着色;用户可在现有属性下拉框中改选连续的节点渐变。
+ pGrid->GetCellData()->SetScalars(pLayers);
+ pGrid->GetPointData()->SetScalars(pGradient);
+ return buildFromGrid(pGrid, volumeText("Slice Test Model"), pError, pFeedback);
+ } while(false);
+ } catch(const std::bad_alloc&) {
+ sError = volumeText("Not enough memory to create the slice test model.");
+ }
+ if(pError != nullptr) {
+ *pError = canceled(pFeedback) ? volumeText("Volume import canceled.") : sError;
+ }
+ return QSharedPointer();
+}
+
QSharedPointer nmVolumeDataBuilder::buildFromGrid(
vtkUnstructuredGrid* pGrid, const QString& sSourceName,
QString* pError, nmVolumeImportFeedback* pFeedback)
diff --git a/Src/nmNum/nmSubWxs/nmVolumeImportTask.cpp b/Src/nmNum/nmSubWxs/nmVolumeImportTask.cpp
index 7aeb5477..7c27c2ac 100644
--- a/Src/nmNum/nmSubWxs/nmVolumeImportTask.cpp
+++ b/Src/nmNum/nmSubWxs/nmVolumeImportTask.cpp
@@ -1,8 +1,10 @@
#include "nmVolumeImportTask.h"
#include "nmVolumeDataImporter.h"
+#include "nmVolumeDataBuilder.h"
-nmVolumeImportTask::nmVolumeImportTask(const QString& sFilePath, QObject* pParent)
- : QThread(pParent), m_sFilePath(sFilePath), m_nCancelRequested(0), m_nLastProgress(-1)
+nmVolumeImportTask::nmVolumeImportTask(SourceType eSourceType, const QString& sFilePath, QObject* pParent)
+ : QThread(pParent), m_eSourceType(eSourceType), m_sFilePath(sFilePath),
+ m_nCancelRequested(0), m_nLastProgress(-1)
{
}
nmVolumeImportTask::~nmVolumeImportTask()
@@ -24,11 +26,16 @@ void nmVolumeImportTask::reportProgress(int nPercent)
void nmVolumeImportTask::run()
{
try {
- m_pResult = nmVolumeDataImporter::loadFile(m_sFilePath, &m_sError, this);
+ // 两种来源都只发布只读候选,场景切换仍由 GUI 在线程结束后统一处理。
+ if(m_eSourceType == SliceTestModelSource) {
+ m_pResult = nmVolumeDataBuilder::buildSliceTestModel(&m_sError, this);
+ } else {
+ m_pResult = nmVolumeDataImporter::loadFile(m_sFilePath, &m_sError, this);
+ }
} catch(...) {
- // C++ 异常不得越过 QThread::run 边界,否则一次导入可能终止整个进程。
+ // C++ 异常不得越过 QThread::run 边界,否则一次加载可能终止整个进程。
m_pResult.clear();
- m_sError = tr("An unexpected error occurred while importing the volume mesh.");
+ m_sError = tr("An unexpected error occurred while loading the volume mesh.");
}
if(isCanceled()) m_pResult.clear();
}
diff --git a/Src/nmNum/nmSubWxs/nmWxPebiResultViewWidget.cpp b/Src/nmNum/nmSubWxs/nmWxPebiResultViewWidget.cpp
index ea25750f..e112205d 100644
--- a/Src/nmNum/nmSubWxs/nmWxPebiResultViewWidget.cpp
+++ b/Src/nmNum/nmSubWxs/nmWxPebiResultViewWidget.cpp
@@ -1104,22 +1104,23 @@ void nmWxPebiRegionPressureStatisticsDlg::refreshValues()
}
}
-/** @brief 外部三维模式的窗口私有状态,所有成员仅由 GUI 线程管理。 */
+/** @brief 独立三维模型(文件或内置测试模型)的窗口私有状态,仅由 GUI 线程管理。 */
class nmWxPebiVolumeState
{
public:
/** @brief 初始化为空模式;控制器在通用渲染容器创建后绑定。 */
nmWxPebiVolumeState()
: m_pController(nullptr), m_pTask(nullptr), m_pProgress(nullptr),
- m_pImportAction(nullptr), m_pReturnAction(nullptr), m_pButton(nullptr),
+ m_pImportAction(nullptr), m_pTestModelAction(nullptr), m_pReturnAction(nullptr), m_pButton(nullptr),
m_pSliceAction(nullptr), m_pSliceSettingsAction(nullptr),
m_pSliceDialog(nullptr), m_pSliceInteraction(nullptr),
m_bImported(false), m_bPendingSync(false), m_bRegionVisible(false),
m_bRegionDialogVisible(false) {}
nmVolumeSceneController* m_pController; ///< 窗口独占,必须在渲染容器之前析构。
- nmVolumeImportTask* m_pTask; ///< 当前唯一导入线程,结束后才允许读取结果。
+ nmVolumeImportTask* m_pTask; ///< 当前唯一模型加载线程,结束后才允许读取结果。
QProgressDialog* m_pProgress; ///< 临时进度框,窗口对象树拥有。
QAction* m_pImportAction; ///< 切片按钮菜单中的三维模型导入动作。
+ QAction* m_pTestModelAction; ///< 直接加载内置切片测试模型,复用现有三维显示流程。
QAction* m_pReturnAction; ///< 仅外部模型模式启用的返回动作。
QToolButton* m_pButton; ///< 唯一新增的常驻切片工具按钮。
QAction* m_pSliceAction; ///< 切片按钮菜单中的切片显隐动作。
@@ -1128,7 +1129,7 @@ public:
nmVolumeSliceInteraction* m_pSliceInteraction; ///< 窗口独占,负责辅助平面及安全事件转发。
nmVTKViewState m_oSavedView; ///< 第一次进入外部模式前捕获的计算结果视图。
nmVTKViewCommandController::ViewCommands m_eSavedCommands; ///< 原结果提供的视图命令能力。
- bool m_bImported; ///< 当前画面是否为外部三维模型。
+ bool m_bImported; ///< 当前是否显示独立三维模型,包含文件导入和内置测试模型。
bool m_bPendingSync; ///< 外部模式期间发生 Manager 变化,返回时重新读取。
bool m_bRegionVisible; ///< 原区域轮廓的实际可见状态。
bool m_bRegionDialogVisible; ///< 原区域统计面板是否可见。
@@ -1988,6 +1989,8 @@ void nmWxPebiResultViewWidget::createUi()
QMenu* pSliceMenu = new QMenu(m_pVolumeState->m_pButton);
m_pVolumeState->m_pImportAction = new QAction(tr("Import 3D Model..."), this);
m_pVolumeState->m_pImportAction->setObjectName(QLatin1String("importVolumeAction"));
+ m_pVolumeState->m_pTestModelAction = new QAction(tr("Load Slice Test Model"), this);
+ m_pVolumeState->m_pTestModelAction->setObjectName(QLatin1String("loadSliceTestModelAction"));
m_pVolumeState->m_pReturnAction = new QAction(tr("Return to Calculation Result"), this);
m_pVolumeState->m_pReturnAction->setObjectName(QLatin1String("returnCalculationAction"));
m_pVolumeState->m_pSliceAction = new QAction(tr("Show Slice"), this);
@@ -1996,6 +1999,7 @@ void nmWxPebiResultViewWidget::createUi()
m_pVolumeState->m_pSliceSettingsAction = new QAction(tr("Slice Settings..."), this);
m_pVolumeState->m_pSliceSettingsAction->setObjectName(QLatin1String("volumeSliceSettingsAction"));
pSliceMenu->addAction(m_pVolumeState->m_pImportAction);
+ pSliceMenu->addAction(m_pVolumeState->m_pTestModelAction);
pSliceMenu->addSeparator();
pSliceMenu->addAction(m_pVolumeState->m_pSliceAction);
pSliceMenu->addAction(m_pVolumeState->m_pSliceSettingsAction);
@@ -2004,6 +2008,7 @@ void nmWxPebiResultViewWidget::createUi()
m_pVolumeState->m_pButton->setMenu(pSliceMenu);
m_pToolBar->addWidget(m_pVolumeState->m_pButton);
connect(m_pVolumeState->m_pImportAction, SIGNAL(triggered()), this, SLOT(onImportVolumeRequested()));
+ connect(m_pVolumeState->m_pTestModelAction, SIGNAL(triggered()), this, SLOT(onLoadSliceTestModelRequested()));
connect(m_pVolumeState->m_pReturnAction, SIGNAL(triggered()), this, SLOT(onReturnToCalculationResult()));
connect(m_pVolumeState->m_pSliceAction, SIGNAL(toggled(bool)), this, SLOT(onVolumeSliceToggled(bool)));
connect(m_pVolumeState->m_pSliceSettingsAction, SIGNAL(triggered()), this, SLOT(onShowVolumeSliceSettings()));
@@ -2649,7 +2654,9 @@ bool nmWxPebiResultViewWidget::canImportVolume() const
void nmWxPebiResultViewWidget::synchronizeVolumeActions()
{
if(m_pVolumeState == nullptr || m_pVolumeState->m_pImportAction == nullptr) return;
- m_pVolumeState->m_pImportAction->setEnabled(canImportVolume());
+ const bool bCanLoad = canImportVolume();
+ m_pVolumeState->m_pImportAction->setEnabled(bCanLoad);
+ m_pVolumeState->m_pTestModelAction->setEnabled(bCanLoad);
m_pVolumeState->m_pImportAction->setText(isImportedVolumeMode()
? tr("Replace 3D Model...") : tr("Import 3D Model..."));
m_pVolumeState->m_pReturnAction->setEnabled(isImportedVolumeMode() && m_pVolumeState->m_pTask == nullptr);
@@ -2685,7 +2692,20 @@ void nmWxPebiResultViewWidget::onImportVolumeRequested()
bool nmWxPebiResultViewWidget::importVolumeFile(const QString& sFilePath)
{
if(!isResultViewGuiThread() || sFilePath.isEmpty() || !canImportVolume()) return false;
- m_pVolumeState->m_pTask = new nmVolumeImportTask(sFilePath, this);
+ startVolumeLoad(new nmVolumeImportTask(nmVolumeImportTask::FileSource, sFilePath, this));
+ return true;
+}
+
+void nmWxPebiResultViewWidget::onLoadSliceTestModelRequested()
+{
+ if(!isResultViewGuiThread() || !canImportVolume()) return;
+ // 与文件导入共享取消和提交路径,生成失败时保留原模型及其切片。
+ startVolumeLoad(new nmVolumeImportTask(nmVolumeImportTask::SliceTestModelSource, QString(), this));
+}
+
+void nmWxPebiResultViewWidget::startVolumeLoad(nmVolumeImportTask* pTask)
+{
+ m_pVolumeState->m_pTask = pTask;
m_pVolumeState->m_pProgress = new QProgressDialog(tr("Loading 3D model..."), tr("Cancel"), 0, 100, this);
m_pVolumeState->m_pProgress->setObjectName(QLatin1String("volumeImportProgress"));
m_pVolumeState->m_pProgress->setWindowModality(Qt::WindowModal);
@@ -2700,7 +2720,6 @@ bool nmWxPebiResultViewWidget::importVolumeFile(const QString& sFilePath)
m_pVolumeState->m_pProgress->show();
synchronizeBusinessActions();
m_pVolumeState->m_pTask->start();
- return true;
}
void nmWxPebiResultViewWidget::onCancelVolumeImport()
diff --git a/Src/nmNum/nmSubWxs/nmWxVolumeSliceSettingsDlg.cpp b/Src/nmNum/nmSubWxs/nmWxVolumeSliceSettingsDlg.cpp
index ca09c452..7ea41dd8 100644
--- a/Src/nmNum/nmSubWxs/nmWxVolumeSliceSettingsDlg.cpp
+++ b/Src/nmNum/nmSubWxs/nmWxVolumeSliceSettingsDlg.cpp
@@ -1,5 +1,4 @@
#include "nmWxVolumeSliceSettingsDlg.h"
-#include "nmParameterField.h"
#include "nmNumericDisplayFormat.h"
#include
#include
@@ -21,7 +20,8 @@ nmWxVolumeSliceSettingsDlg::nmWxVolumeSliceSettingsDlg(QWidget* pParent)
{
createUi();
writeSettings(m_oApplied);
- resize(minimumWidth(), sizeHint().height());
+ // 与测量工具一致,由字体、主题和布局计算初始大小,后续仍允许用户调整窗口。
+ adjustSize();
}
void nmWxVolumeSliceSettingsDlg::createUi()
@@ -36,8 +36,6 @@ void nmWxVolumeSliceSettingsDlg::createUi()
setIgnoreEsc(false);
// 六个分量各占一行,共用标签列和输入列;原点区与法向区分别放置对应快捷操作。
- const int nEditorHeight = nmParameterField::editorHeight();
- const int nEditorMinimumWidth = nmParameterField::editorMinimumWidth();
QGroupBox* pPlaneGroup = new QGroupBox(tr("Plane Parameters"), this);
pPlaneGroup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
QGridLayout* pPlaneLayout = new QGridLayout(pPlaneGroup);
@@ -45,15 +43,15 @@ void nmWxVolumeSliceSettingsDlg::createUi()
pPlaneLayout->setHorizontalSpacing(6);
pPlaneLayout->setVerticalSpacing(6);
pPlaneLayout->setColumnStretch(1, 1);
- int nFieldLabelWidth = 0;
const char* pAxes[3] = { "X", "Y", "Z" };
for(int nAxis = 0; nAxis < 3; ++nAxis) {
QLabel* pOriginLabel = new QLabel(tr("Origin %1").arg(QLatin1String(pAxes[nAxis])), pPlaneGroup);
QLabel* pNormalLabel = new QLabel(tr("Normal %1").arg(QLatin1String(pAxes[nAxis])), pPlaneGroup);
pOriginLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
pNormalLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
- nFieldLabelWidth = qMax(nFieldLabelWidth,
- qMax(pOriginLabel->sizeHint().width(), pNormalLabel->sizeHint().width()));
+ // 标签列由布局按文字自然取宽;不缓存像素尺寸,便于适应字体和主题变化。
+ pOriginLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+ pNormalLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
pPlaneLayout->addWidget(pOriginLabel, nAxis, 0);
pPlaneLayout->addWidget(pNormalLabel, nAxis + 5, 0);
m_pOriginEdits[nAxis] = new QLineEdit(pPlaneGroup);
@@ -62,10 +60,7 @@ void nmWxVolumeSliceSettingsDlg::createUi()
m_pNormalEdits[nAxis]->setObjectName(QString::fromLatin1("sliceNormal") + QLatin1String(pAxes[nAxis]));
m_pOriginEdits[nAxis]->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
m_pNormalEdits[nAxis]->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
- m_pOriginEdits[nAxis]->setMinimumWidth(nEditorMinimumWidth);
- m_pNormalEdits[nAxis]->setMinimumWidth(nEditorMinimumWidth);
- m_pOriginEdits[nAxis]->setFixedHeight(nEditorHeight);
- m_pNormalEdits[nAxis]->setFixedHeight(nEditorHeight);
+ // 横向随输入列伸展;纵向 Fixed 使用主题推荐高度,不指定固定像素高度。
m_pOriginEdits[nAxis]->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
m_pNormalEdits[nAxis]->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
pPlaneLayout->addWidget(m_pOriginEdits[nAxis], nAxis, 1);
@@ -77,9 +72,9 @@ void nmWxVolumeSliceSettingsDlg::createUi()
// 模型中心仅调整原点,放在原点 Z 下方,保持按钮紧凑并与输入框右边界对齐。
QToolButton* pCenterButton = new QToolButton(pPlaneGroup);
pCenterButton->setText(tr("Model Center"));
+ pCenterButton->setToolTip(tr("Move the plane origin to the model center without changing its normal."));
pCenterButton->setAutoRaise(true);
- pCenterButton->setMinimumWidth(72);
- pCenterButton->setFixedHeight(nEditorHeight);
+ // 工具按钮按文字与主题计算尺寸,保持紧凑且不裁剪翻译后的标题。
pCenterButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
pPlaneLayout->addWidget(pCenterButton, 3, 1, Qt::AlignRight);
pPlaneLayout->setRowMinimumHeight(4, 6);
@@ -102,10 +97,10 @@ void nmWxVolumeSliceSettingsDlg::createUi()
for(int nPlane = 0; nPlane < 3; ++nPlane) {
QToolButton* pButton = new QToolButton(pPlaneGroup);
pButton->setText(QString::fromLatin1(pPlanes[nPlane]));
+ pButton->setToolTip(tr("Set the plane parallel to %1 without changing its origin.")
+ .arg(QString::fromLatin1(pPlanes[nPlane])));
pButton->setProperty("normalAxis", 2 - nPlane);
pButton->setAutoRaise(true);
- pButton->setMinimumWidth(44);
- pButton->setFixedHeight(nEditorHeight);
pButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
pShortcutLayout->addWidget(pButton, 1);
setTabOrder(pPreviousShortcutWidget, pButton);
@@ -117,26 +112,19 @@ void nmWxVolumeSliceSettingsDlg::createUi()
// 着色属性及渲染模式统一使用旧底栏;浮动窗口只保留平面相关的显示选项。
QGroupBox* pDisplayGroup = new QGroupBox(tr("Display Options"), this);
pDisplayGroup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
- QGridLayout* pDisplayLayout = new QGridLayout(pDisplayGroup);
+ // 显示选项没有标签列,直接从分组左边距排列,避免沿用参数区的空列缩进。
+ QHBoxLayout* pDisplayLayout = new QHBoxLayout(pDisplayGroup);
pDisplayLayout->setContentsMargins(8, 15, 8, 10);
- pDisplayLayout->setHorizontalSpacing(6);
- pDisplayLayout->setVerticalSpacing(6);
- pPlaneLayout->setColumnMinimumWidth(0, nFieldLabelWidth);
- pDisplayLayout->setColumnMinimumWidth(0, nFieldLabelWidth);
- pDisplayLayout->setColumnStretch(1, 1);
+ pDisplayLayout->setSpacing(12);
m_pShowPlaneCheck = new QCheckBox(tr("Show Plane"), pDisplayGroup);
m_pShowSourceCheck = new QCheckBox(tr("Show Original Model"), pDisplayGroup);
m_pShowPlaneCheck->setObjectName(QLatin1String("sliceShowPlane"));
m_pShowSourceCheck->setObjectName(QLatin1String("sliceShowSource"));
// 拖动说明放在显示平面的悬停提示中,减少常驻文字对参数布局的干扰。
m_pShowPlaneCheck->setToolTip(tr("Drag the center or outline to move the plane; drag arrows to rotate."));
- QHBoxLayout* pDisplayOptionsLayout = new QHBoxLayout;
- pDisplayOptionsLayout->setContentsMargins(0, 0, 0, 0);
- pDisplayOptionsLayout->setSpacing(12);
- pDisplayOptionsLayout->addWidget(m_pShowPlaneCheck);
- pDisplayOptionsLayout->addWidget(m_pShowSourceCheck);
- pDisplayOptionsLayout->addStretch();
- pDisplayLayout->addLayout(pDisplayOptionsLayout, 0, 1);
+ pDisplayLayout->addWidget(m_pShowPlaneCheck);
+ pDisplayLayout->addWidget(m_pShowSourceCheck);
+ pDisplayLayout->addStretch();
setTabOrder(pPreviousShortcutWidget, m_pShowPlaneCheck);
setTabOrder(m_pShowPlaneCheck, m_pShowSourceCheck);
connect(m_pShowPlaneCheck, SIGNAL(toggled(bool)), this, SLOT(onDisplayOptionsChanged()));
@@ -154,24 +142,25 @@ void nmWxVolumeSliceSettingsDlg::createUi()
pFooterLayout->setContentsMargins(4, 5, 4, 5);
pFooterLayout->setSpacing(8);
pFooterLayout->addStretch();
- QPushButton* pResetButton = new QPushButton(tr("Reset"), this);
+ QPushButton* pRestoreButton = new QPushButton(tr("Restore"), this);
+ // 还原仅撤销未应用的平面编辑,恢复最近一次成功应用的参数,不恢复初始截面。
+ pRestoreButton->setToolTip(tr("Restore the last applied plane parameters."));
m_pApplyButton = new QPushButton(tr("Apply"), this);
QPushButton* pCloseButton = new QPushButton(tr("Close"), this);
m_pApplyButton->setObjectName(QLatin1String("sliceApplyButton"));
m_pApplyButton->setDefault(true);
- pResetButton->setAutoDefault(false);
+ pRestoreButton->setAutoDefault(false);
pCloseButton->setAutoDefault(false);
- pResetButton->setMinimumWidth(72);
- m_pApplyButton->setMinimumWidth(72);
- pCloseButton->setMinimumWidth(72);
pCloseButton->setIcon(zxLoadIcon("Cancel"));
- pCloseButton->setIconSize(QSize(16, 16));
- pFooterLayout->addWidget(pResetButton);
+ pFooterLayout->addWidget(pRestoreButton);
pFooterLayout->addWidget(m_pApplyButton);
pFooterLayout->addWidget(pCloseButton);
connect(m_pApplyButton, SIGNAL(clicked()), this, SLOT(onApplyRequested()));
- connect(pResetButton, SIGNAL(clicked()), this, SLOT(onResetRequested()));
+ connect(pRestoreButton, SIGNAL(clicked()), this, SLOT(onRestoreRequested()));
connect(pCloseButton, SIGNAL(clicked()), this, SLOT(close()));
+ setTabOrder(m_pShowSourceCheck, pRestoreButton);
+ setTabOrder(pRestoreButton, m_pApplyButton);
+ setTabOrder(m_pApplyButton, pCloseButton);
QVBoxLayout* pMainLayout = new QVBoxLayout(this);
pMainLayout->setContentsMargins(12, 10, 12, 0);
@@ -179,9 +168,9 @@ void nmWxVolumeSliceSettingsDlg::createUi()
pMainLayout->addWidget(pPlaneGroup);
pMainLayout->addWidget(pDisplayGroup);
pMainLayout->addWidget(m_pErrorLabel);
+ // 初始高度按内容收紧;手动纵向拉伸的余量留在底部,不拉长输入框或分组行距。
pMainLayout->addStretch();
pMainLayout->addLayout(pFooterLayout);
- setMinimumWidth(400);
}
void nmWxVolumeSliceSettingsDlg::setData(const QSharedPointer& pData, const nmVolumeSliceSettings& oApplied)
@@ -198,7 +187,7 @@ void nmWxVolumeSliceSettingsDlg::setAppliedSettings(const nmVolumeSliceSettings&
void nmWxVolumeSliceSettingsDlg::setAppliedProperty(const QString& sPropertyId)
{
- // 底栏属性立即生效;重置、关闭窗口及再次应用平面时也应继续使用此属性。
+ // 底栏属性立即生效;还原、关闭窗口及再次应用平面时也应继续使用此属性。
m_oApplied.m_sPropertyId = sPropertyId;
}
@@ -313,7 +302,7 @@ void nmWxVolumeSliceSettingsDlg::onCenterRequested()
onDraftChanged();
}
-void nmWxVolumeSliceSettingsDlg::onResetRequested()
+void nmWxVolumeSliceSettingsDlg::onRestoreRequested()
{
writeSettings(m_oApplied);
emit previewChanged();