From 6797e813ac7bcfec600254cb173fa12ca1fcbcc8 Mon Sep 17 00:00:00 2001 From: lvjunjie Date: Thu, 22 Oct 2026 16:44:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(nmNum):=20=E8=B0=83=E6=95=B4=E6=8B=9F?= =?UTF-8?q?=E5=90=88=E7=AA=97=E5=8F=A3=E5=B8=83=E5=B1=80=E5=8F=8A=E7=9B=AE?= =?UTF-8?q?=E6=A0=87=E4=BA=95=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 恢复设置和运行窗口布局,调整参数表格及单位显示。 - 普通拟合绑定当前结果井,同步参数选择和初值。 - 调整拟合进度及日志显示。 --- Include/nmNum/nmSubWxs/nmWxAutomaticFitting.h | 5 +- .../nmSubWxs/nmWxAutomaticFittingStart.h | 36 +- Src/nmNum/nmSubWxs/nmWxAutomaticFitting.cpp | 203 +++---- .../nmSubWxs/nmWxAutomaticFittingStart.cpp | 524 ++++++------------ 4 files changed, 282 insertions(+), 486 deletions(-) diff --git a/Include/nmNum/nmSubWxs/nmWxAutomaticFitting.h b/Include/nmNum/nmSubWxs/nmWxAutomaticFitting.h index 511eebe0..0c3d4172 100644 --- a/Include/nmNum/nmSubWxs/nmWxAutomaticFitting.h +++ b/Include/nmNum/nmSubWxs/nmWxAutomaticFitting.h @@ -55,13 +55,13 @@ private: void setupUI(); void setupParameterTable(); void setupControlPanel(); - void setupButtons(); + QHBoxLayout* setupButtons(); void updateSelectAllState(); void setAutomaticFittingValue(); void saveModelParameters(); void initializeModelParameters(bool restoreRanges = true); void addParameter(QTreeWidgetItem* group, int type, nmDataWellBase* well, double initial); - QVector primaryInitialValues() const; + QVector targetInitialValues() const; QStringList selectedParameterLabels(bool units) const; void updateRangeForParameter(int parameterIndex, double centerValue); void setParameterRange(int parameterIndex, double minValue, double maxValue); @@ -86,6 +86,7 @@ private: QLabel* m_iterationLabel; QLineEdit* m_errorLimitEdit; QString m_targetWellName; + QString m_targetWellCode; QComboBox* m_algorithmCombo; // 按钮 diff --git a/Include/nmNum/nmSubWxs/nmWxAutomaticFittingStart.h b/Include/nmNum/nmSubWxs/nmWxAutomaticFittingStart.h index 1c8dce13..025ab5ab 100644 --- a/Include/nmNum/nmSubWxs/nmWxAutomaticFittingStart.h +++ b/Include/nmNum/nmSubWxs/nmWxAutomaticFittingStart.h @@ -7,11 +7,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -29,7 +31,6 @@ class nmCalculationAutoFitLM; class QPainter; class QColor; class QPaintEvent; -class QScrollArea; class nmAutomaticFittingCurveChart : public QWidget { @@ -74,7 +75,6 @@ class nmWxAutomaticfittingStart : public iDlgBase public: explicit nmWxAutomaticfittingStart(QWidget *parent = 0); ~nmWxAutomaticfittingStart(); - virtual QSize sizeHint() const; // 算法接口 void setAutoFitter(nmCalculationAutoFitPSO* autoFitter); @@ -92,8 +92,6 @@ public: public slots: void onFittingProgress(int iteration, double fitness); - void onLMStageChanged(int stage); - void onToggleLog(); void onFittingFinished(bool success, const QString& message); void onFinalizingStarted(); void onStopButtonClicked(); @@ -105,28 +103,28 @@ public: protected: void closeEvent(QCloseEvent *event); - bool eventFilter(QObject* watched, QEvent* event); private: void setupUI(); void setupParameterArea(); - void setupParameterStrip(); - void updateParameterAreaHeight(); + void setupTableArea(); void setupChartArea(); void setupLogArea(); void setupControlArea(); - void updateAlgorithmDisplay(); - void updateParameterValues(); - void updateCurrentError(double fitness); + void updateParameterTable(); void addLogMessage(const QString& message); QString formatScientific(double value); // UI组件 + QHBoxLayout* mainLayout; + QVBoxLayout* leftLayout; + QVBoxLayout* rightLayout; QSplitter* rightSplitter; // 参数显示区域 QGroupBox* parameterGroup; QLabel* currentIterationLabel; + QLabel* maxIterationLabel; QLabel* currentComfortLabel; QLabel* bestComfortLabel; QLabel* targetPrecisionLabel; @@ -134,33 +132,25 @@ private: QLabel* algorithmTypeLabel; QLabel* currentIterationValue; + QLabel* maxIterationValue; QLabel* currentComfortValue; QLabel* bestComfortValue; QLabel* targetPrecisionValue; QLabel* targetWellValue; QLabel* algorithmTypeValue; - // 参数每行最多六个,可见两行,其余通过垂直滚动查看。 - QWidget* parameterStrip; - QScrollArea* parameterScrollArea; - QWidget* parameterContent; - QGridLayout* parameterLayout; - QVector parameterValues; + // 参数表格区域 + QGroupBox* tableGroup; + QTableWidget* tableWidget; // 日志区域 QGroupBox* chartGroup; nmAutomaticFittingCurveChart* curveChart; QGroupBox* logGroup; QTextEdit* logTextEdit; - QPushButton* logToggle; - QList expandedLogSizes; // 控制区域 QProgressBar* progressBar; - QLabel* stageStatus; - QLabel* stateBadge; - QLabel* resultSummary; - QLabel* runSummary; QPushButton* stopButton; // 算法实例 @@ -172,6 +162,8 @@ private: int m_maxIterations; double m_targetError; QString m_wellName; + QStringList m_selectedParameters; + QStringList m_parameterUnits; bool m_isFinished; bool m_isFinalizing; double m_bestFitnessEver; diff --git a/Src/nmNum/nmSubWxs/nmWxAutomaticFitting.cpp b/Src/nmNum/nmSubWxs/nmWxAutomaticFitting.cpp index 2ae046aa..27c726da 100644 --- a/Src/nmNum/nmSubWxs/nmWxAutomaticFitting.cpp +++ b/Src/nmNum/nmSubWxs/nmWxAutomaticFitting.cpp @@ -8,6 +8,7 @@ #include "iSubWndFitting.h" #include "iSysParaHelper.h" #include "iParameter.h" +#include "ZxSupSubHelper.h" #include "mModuleDefines.h" #include "mGui/mGuiAnal/iAnalRun.h" #include "mAlgDefines.h" @@ -15,8 +16,9 @@ #pragma comment(lib, "mGuiAnal.lib") #include -#include #include +#include +#include #include #include #include @@ -28,17 +30,45 @@ namespace { +// 拟合窗口与系统参数表共用参数编码,单位读取 XML 解析后的上标文本。 +const char* const fitParameterNames[] = {"Result_K", "Result_W_Skin", "Result_W_C", + "Result_phi", "Result_W_Dfc", "W_FractureHalfLength"}; + +QString nmAutoFitDisplayUnit(const nmFitParameter& parameter) +{ + iSysParaHelper* helper = _paraHelper; + iParameter* definition = helper + ? helper->getPara(QString::fromLatin1(fitParameterNames[parameter.type]), s_Nm_Serie) : nullptr; + // 配置不可用时仍沿用基准单位,并复用主软件的上标转换。 + const QString unit = definition ? definition->m_sUnit : parameter.unit(); + QString displayUnit; + return ZxSupSubHelper::checkRichText(unit, displayUnit) ? displayUnit : unit; +} + // 树节点和名称、单位列只读,仅允许编辑参数的三个数值列。 class nmFitParameterDelegate : public QStyledItemDelegate { public: explicit nmFitParameterDelegate(QObject* parent) : QStyledItemDelegate(parent) {} - QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const + void paint(QPainter* painter, const QStyleOptionViewItem& option, + const QModelIndex& index) const { - // 分组和参数统一增高,字号变化时也保留上下留白。 - QSize size = QStyledItemDelegate::sizeHint(option, index); - size.setHeight(qMax(size.height(), qMax(32, option.fontMetrics.height() + 12))); - return size; + QStyledItemDelegate::paint(painter, option, index); + // 仅为具体参数绘制网格,分组标题保留原生树样式;线色沿用全局表格配置。 + if(!index.sibling(index.row(), 0).data(Qt::UserRole).isValid()) return; + const QTreeWidget* tree = qobject_cast(parent()); + const int gridColor = tree->style()->styleHint(QStyle::SH_Table_GridLineColor, + &option, tree); + painter->save(); + painter->setPen(QPen(QColor::fromRgb(gridColor), 1)); + painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight()); + painter->drawLine(option.rect.topRight(), option.rect.bottomRight()); + // 每组首行补上顶边,名称列的左边随树层级缩进,保留折叠区域。 + if(index.row() == 0) + painter->drawLine(option.rect.topLeft(), option.rect.topRight()); + if(index.column() == 0) + painter->drawLine(option.rect.topLeft(), option.rect.bottomLeft()); + painter->restore(); } QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, @@ -96,10 +126,8 @@ bool nmWxAutomaticFitting::getPhysicalParameterRange(int parameterIndex, double& minValue, double& maxValue) { // 参数行按实际类型查询边界,不依赖它位于哪口井的分组。 - static const char* names[] = {"Result_K", "Result_W_Skin", "Result_W_C", - "Result_phi", "Result_W_Dfc", "W_FractureHalfLength"}; const int type = automaticFittingData.getModelParameters()[parameterIndex].type; - if(!nmAutoFitReadPhysicalRange(names[type], minValue, maxValue)) return false; + if(!nmAutoFitReadPhysicalRange(fitParameterNames[type], minValue, maxValue)) return false; if(type == 1) minValue = 0.0; return true; } @@ -280,15 +308,18 @@ nmWxAutomaticFitting::nmWxAutomaticFitting(QWidget *parent, nmSensitivityFitSett if(m_sensitivitySettings->confirmed) automaticFittingData = m_sensitivitySettings->parameters; else automaticFittingData.getModelParameters().clear(); } - nmDataWellBase* primary = pManager->findWellByCode(pManager->getPrimaryWellCode()); - m_targetWellName = primary ? primary->getWellName() : QString(); + // 普通拟合绑定打开窗口时的结果井;敏感性设置仍沿用主分析井。 + const QString resultWellId = pManager->getCurrentResultWellInstanceId(); + nmDataWellBase* targetWell = !m_sensitivitySettings && !resultWellId.isEmpty() + ? pManager->findWellByInstanceId(resultWellId) + : pManager->findWellByCode(pManager->getPrimaryWellCode()); + m_targetWellName = targetWell ? targetWell->getWellName() : QString(); + m_targetWellCode = targetWell ? targetWell->getWellCode() : QString(); setupUI(); - // 敏感性入口使用“确定”保存设置,普通入口仍直接开始拟合。 - if(m_sensitivitySettings) m_okBtn->setText(tr("OK")); setWindowTitle(tr("Automatic fitting")); setModal(true); - // 初始尺寸随所在屏幕变化,最小尺寸交给实际控件布局决定。 + // 恢复旧版默认尺寸,多井参数在右侧树表中滚动查看。 resize(sizeHint()); initializeModelParameters(); @@ -300,11 +331,8 @@ nmWxAutomaticFitting::nmWxAutomaticFitting(QWidget *parent, nmSensitivityFitSett QSize nmWxAutomaticFitting::sizeHint() const { - // 沿用项目的可用屏幕尺寸计算方式,优先取父窗口所在屏幕,支持多显示器。 - QDesktopWidget* desktop = QApplication::desktop(); - if(desktop == nullptr) return iDlgBase::sizeHint(); - const QRect available = desktop->availableGeometry(parentWidget() ? parentWidget()->window() : this); - return QSize(available.width() * 45 / 100, available.height() * 55 / 100); + // 与改版前设置窗口保持相同推荐尺寸,仍允许手动放大。 + return QSize(800, 480); } nmWxAutomaticFitting::~nmWxAutomaticFitting() @@ -330,48 +358,24 @@ nmWxAutomaticFitting::~nmWxAutomaticFitting() void nmWxAutomaticFitting::setupUI() { - // 用浅底色区分白色设置区和参数区,避免所有内容铺在同一平面。 + // 恢复旧版左右布局,右侧保留当前储层和各井参数分类。 setObjectName("autoFittingSettings"); - setFont(QFont("Microsoft YaHei", 9)); - setStyleSheet( - "#autoFittingSettings { background: #f3f5f8; color: #273449; }" - "#autoFittingSettings QFrame#fittingControls, #autoFittingSettings QFrame#fittingParameters { background: #ffffff; border: 1px solid #dce2ea; border-radius: 7px; }" - "#autoFittingSettings QLabel { color: #667487; background: transparent; border: none; }" - "#autoFittingSettings QLabel#parameterHeading { color: #273449; font-weight: bold; }" - "#autoFittingSettings QLineEdit, #autoFittingSettings QComboBox { background: #ffffff; color: #273449; border: 1px solid #cfd7e2; border-radius: 4px; padding: 5px 8px; min-height: 20px; selection-background-color: #dceafb; selection-color: #273449; }" - "#autoFittingSettings QLineEdit:focus, #autoFittingSettings QComboBox:focus { border-color: #3978c6; }" - "#autoFittingSettings QComboBox::drop-down { border: none; width: 24px; }" - "#autoFittingSettings QComboBox QAbstractItemView { background: #ffffff; color: #273449; selection-background-color: #eaf1fb; selection-color: #273449; }" - "#autoFittingSettings QTreeWidget { border: none; background: #ffffff; color: #273449; selection-background-color: #eaf1fb; selection-color: #273449; }" - "#autoFittingSettings QHeaderView::section { background: #f5f7fa; color: #667487; border: none; border-bottom: 1px solid #e5eaf1; padding: 7px; }" - "#autoFittingSettings QTreeWidget::item { border-bottom: 1px solid #eef1f5; padding: 5px 8px; }" - "#autoFittingSettings QPushButton { background: #ffffff; color: #46556b; border: 1px solid #cfd7e2; border-radius: 4px; padding: 6px 18px; min-width: 64px; min-height: 20px; }" - "#autoFittingSettings QPushButton:hover { background: #edf3fc; border-color: #9bb7db; }" - "#autoFittingSettings QPushButton:pressed { background: #dce8f8; }" - "#autoFittingSettings QPushButton#startFitting { background: #3978c6; color: #ffffff; border-color: #3978c6; }" - "#autoFittingSettings QPushButton#startFitting:hover { background: #306bb5; }" - "#autoFittingSettings QPushButton#startFitting:pressed { background: #285b9c; }"); m_mainLayout = new QVBoxLayout(this); - m_mainLayout->setContentsMargins(16, 16, 16, 14); - m_mainLayout->setSpacing(12); + QGridLayout* contentLayout = new QGridLayout(); + contentLayout->setContentsMargins(20, 0, 20, 0); + contentLayout->setColumnMinimumWidth(1, 30); + contentLayout->setColumnStretch(2, 1); + contentLayout->setRowStretch(0, 1); setupControlPanel(); - QFrame* controlsPanel = new QFrame(this); - controlsPanel->setObjectName("fittingControls"); - m_controlLayout->setContentsMargins(16, 14, 16, 14); + QWidget* controlsPanel = new QWidget(this); + controlsPanel->setFixedWidth(160); controlsPanel->setLayout(m_controlLayout); - m_mainLayout->addWidget(controlsPanel); + contentLayout->addWidget(controlsPanel, 0, 0); setupParameterTable(); - QFrame* tablePanel = new QFrame(this); - tablePanel->setObjectName("fittingParameters"); - QVBoxLayout* tableLayout = new QVBoxLayout(tablePanel); - tableLayout->setContentsMargins(12, 12, 12, 8); - tableLayout->setSpacing(10); - QLabel* tableHeading = new QLabel(tr("Fitting parameters"), tablePanel); - tableHeading->setObjectName("parameterHeading"); - tableLayout->addWidget(tableHeading); - tableLayout->addWidget(m_parameterTable, 1); - m_mainLayout->addWidget(tablePanel, 1); - setupButtons(); + contentLayout->addWidget(m_parameterTable, 0, 2); + // 底部操作区与参数表共用一列,全选始终对齐表格左边缘。 + contentLayout->addLayout(setupButtons(), 1, 2); + m_mainLayout->addLayout(contentLayout, 1); setLayout(m_mainLayout); } @@ -380,32 +384,34 @@ void nmWxAutomaticFitting::setupParameterTable() { // 用可折叠分组直接展示各井参数,数值列沿用原来的编辑方式。 m_parameterTable = new QTreeWidget(this); - m_parameterTable->setFont(QFont("Microsoft YaHei", 10)); m_parameterTable->setColumnCount(5); m_parameterTable->setHeaderLabels(QStringList() << tr("Parameter") << tr("Initial value") << tr("Min") << tr("Max") << tr("Unit")); m_parameterTable->setItemDelegate(new nmFitParameterDelegate(m_parameterTable)); m_parameterTable->setSelectionBehavior(QAbstractItemView::SelectItems); + // 全局树控件的交替底色为蓝色;关闭条纹,保留原生背景和选中效果。 + m_parameterTable->setAlternatingRowColors(false); m_parameterTable->setUniformRowHeights(true); m_parameterTable->setIndentation(18); QHeaderView* header = m_parameterTable->header(); - header->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter); + header->setDefaultAlignment(Qt::AlignCenter); header->setStretchLastSection(false); header->setResizeMode(0, QHeaderView::Interactive); - m_parameterTable->setColumnWidth(0, 230); + m_parameterTable->setColumnWidth(0, 190); for(int column = 1; column <= 3; ++column) header->setResizeMode(column, QHeaderView::Stretch); header->setResizeMode(4, QHeaderView::Fixed); - m_parameterTable->setColumnWidth(4, 120); + m_parameterTable->setColumnWidth(4, 80); + // 只调整显示顺序为最小值、初始值、最大值,保留现有列索引和校验逻辑。 + header->moveSection(2, 1); connect(m_parameterTable, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(onParameterTableItemChanged(QTreeWidgetItem*, int))); } void nmWxAutomaticFitting::setupControlPanel() { - // 上方仅保留算法、目标误差和迭代上限。 + // 三项设置从顶部排列,与右侧参数表顶端对齐,剩余空间留在底部。 m_controlLayout = new QGridLayout(); - m_controlLayout->setHorizontalSpacing(16); - m_controlLayout->setVerticalSpacing(6); + m_controlLayout->setContentsMargins(0, 0, 0, 0); // 算法选择 QLabel* algorithmLabel = new QLabel(tr("Algorithm:")); @@ -416,33 +422,35 @@ void nmWxAutomaticFitting::setupControlPanel() m_algorithmCombo->setCurrentIndex(m_sensitivitySettings || nmDataAnalyzeManager::getCurrentInstance()->getEffectiveCalculationWells().size() > 1 ? 1 : 0); m_algorithmCombo->setEnabled(!m_sensitivitySettings); + m_algorithmCombo->setFixedWidth(160); connect(m_algorithmCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onAlgorithmChanged(int))); // 迭代次数 m_iterationLabel = new QLabel(); m_iterationEdit = new QLineEdit(QString::number(automaticFittingData.getIterationCount().getValue().toInt())); + m_iterationEdit->setFixedWidth(100); // 误差上限 QLabel* errorLabel = new QLabel(tr("Target error:")); m_errorLimitEdit = new QLineEdit(QString::number(automaticFittingData.getErrorTolerance().getValue().toDouble())); - - - m_controlLayout->addWidget(algorithmLabel, 0, 0); - m_controlLayout->addWidget(m_algorithmCombo, 1, 0); - m_controlLayout->addWidget(errorLabel, 0, 1); - m_controlLayout->addWidget(m_errorLimitEdit, 1, 1); - m_controlLayout->addWidget(m_iterationLabel, 0, 2); - m_controlLayout->addWidget(m_iterationEdit, 1, 2); - // 右侧预留一列空白,三个输入框不再铺满整行。 - for(int column = 0; column < 4; ++column) m_controlLayout->setColumnStretch(column, 1); + m_errorLimitEdit->setFixedWidth(100); + + m_controlLayout->addWidget(algorithmLabel, 0, 0); + m_controlLayout->addWidget(m_algorithmCombo, 1, 0); + m_controlLayout->setRowMinimumHeight(2, 15); + m_controlLayout->addWidget(m_iterationLabel, 3, 0); + m_controlLayout->addWidget(m_iterationEdit, 4, 0); + m_controlLayout->setRowMinimumHeight(5, 15); + m_controlLayout->addWidget(errorLabel, 6, 0); + m_controlLayout->addWidget(m_errorLimitEdit, 7, 0); + m_controlLayout->setRowStretch(8, 1); } void nmWxAutomaticFitting::onAlgorithmChanged(int index) { - // 多井联合拟合使用 LM;PSO 仍只开放主井和共享储层参数。 + // 多井联合拟合使用 LM;PSO 只开放本次目标井和共享储层参数。 const bool usePSO = index == 0; - const QString primaryCode = nmDataAnalyzeManager::getCurrentInstance()->getPrimaryWellCode(); const bool updating = m_updatingParameterRanges; m_updatingParameterRanges = true; const QVector& parameters = automaticFittingData.getModelParameters(); @@ -451,7 +459,7 @@ void nmWxAutomaticFitting::onAlgorithmChanged(int index) nmDataWellBase* well = p.wellCode.isEmpty() ? nullptr : nmDataAnalyzeManager::getCurrentInstance()->findWellByCode(p.wellCode); const bool unavailable = (m_sensitivitySettings && m_sampledParameters.contains(p.samplingKey())) - || (usePSO && !p.wellCode.isEmpty() && p.wellCode != primaryCode) + || (usePSO && !p.wellCode.isEmpty() && p.wellCode != m_targetWellCode) || (p.type == 1 && (!well || well->getPerforationCount() == 0)); m_parameterItems[i]->setDisabled(unavailable); if(unavailable) m_parameterItems[i]->setCheckState(0, Qt::Unchecked); @@ -462,12 +470,13 @@ void nmWxAutomaticFitting::onAlgorithmChanged(int index) m_iterationEdit->setToolTip(usePSO ? QString() : tr("Height, shape and total-error adjustments share this iteration limit; one iteration may call the solver multiple times.")); } -void nmWxAutomaticFitting::setupButtons() +QHBoxLayout* nmWxAutomaticFitting::setupButtons() { QHBoxLayout* buttonLayout = new QHBoxLayout(); - m_selectAllCheckBox = new QCheckBox(tr("Select All")); - m_okBtn = new QPushButton(tr("Start fitting")); + connect(m_selectAllCheckBox, SIGNAL(clicked(bool)), this, SLOT(onSelectAll(bool))); + + m_okBtn = new QPushButton(tr("OK")); m_okBtn->setObjectName("startFitting"); m_okBtn->setDefault(true); m_cancelBtn = new QPushButton(tr("Cancel")); @@ -476,17 +485,16 @@ void nmWxAutomaticFitting::setupButtons() m_okBtn->setMinimumWidth(80); m_cancelBtn->setMinimumWidth(80); + // 全选位于表格左下方,确定和取消保持在同一行右侧。 buttonLayout->addWidget(m_selectAllCheckBox); buttonLayout->addStretch(); - buttonLayout->addWidget(m_cancelBtn); buttonLayout->addWidget(m_okBtn); - - m_mainLayout->addLayout(buttonLayout); + buttonLayout->addWidget(m_cancelBtn); // 连接信号槽 - connect(m_selectAllCheckBox, SIGNAL(clicked(bool)), this, SLOT(onSelectAll(bool))); connect(m_okBtn, SIGNAL(clicked()), this, SLOT(onAccept())); connect(m_cancelBtn, SIGNAL(clicked()), this, SLOT(onReject())); + return buttonLayout; } void nmWxAutomaticFitting::onSelectAll(bool checked) @@ -543,7 +551,7 @@ void nmWxAutomaticFitting::onAccept() // 仅提交给敏感性窗口;取消、关闭及普通拟合均不经过此分支。 m_sensitivitySettings->parameters = automaticFittingData; m_sensitivitySettings->targetWell = m_targetWellName; - m_sensitivitySettings->initialValues = primaryInitialValues(); + m_sensitivitySettings->initialValues = targetInitialValues(); m_sensitivitySettings->confirmed = true; accept(); return; @@ -646,11 +654,11 @@ void nmWxAutomaticFitting::setAutomaticFittingValue() automaticFittingData.setPorositySelected(false); automaticFittingData.setFractureConductivitySelected(false); automaticFittingData.setFractureHalfLengthSelected(false); - const QString primaryCode = nmDataAnalyzeManager::getCurrentInstance()->getPrimaryWellCode(); + // 旧六参数字段也必须对应本次目标井,避免把主井参数写入所选结果井。 const QVector& parameters = automaticFittingData.getModelParameters(); for(int i = 0; i < parameters.size(); ++i) { const nmFitParameter& p = parameters[i]; - if(!p.wellCode.isEmpty() && p.wellCode != primaryCode) continue; + if(!p.wellCode.isEmpty() && p.wellCode != m_targetWellCode) continue; switch(p.type) { case 0: automaticFittingData.setPermeabilitySelected(p.selected); @@ -694,7 +702,7 @@ void nmWxAutomaticFitting::setAutomaticFittingValue() nmDataAnalyzeManager::getCurrentInstance()->updateAutomaticFittingData(automaticFittingData); return; } - const QVector initial = primaryInitialValues(); + const QVector initial = targetInitialValues(); // 只写回可拟合的渗透率、孔隙度,含水饱和度沿用模型当前值。 reservoirData.getPermeability().setValue(initial[0]); // 渗透率 reservoirData.getPorosity().setValue(initial[3]); // 孔隙度 @@ -806,8 +814,8 @@ void nmWxAutomaticFitting::startAutoFitting(const QVector>& targ int maxIterations = m_iterationEdit->text().toInt(); double targetError = m_errorLimitEdit->text().toDouble(); - QString wellName = m_targetWellName; - m_progressMonitor->setFittingParameters(maxIterations, targetError, wellName); + // 进程窗口与优化器使用同一目标井名称。 + m_progressMonitor->setFittingParameters(maxIterations, targetError, targetWellName); // 名称和单位均按实际优化向量的顺序展示。 m_progressMonitor->setSelectedParameters(selectedParams, selectedParameterLabels(true)); @@ -1087,38 +1095,37 @@ void nmWxAutomaticFitting::addParameter(QTreeWidgetItem* group, int type, item->setData(0, Qt::UserRole, index); item->setText(0, name); item->setText(1, QString::number(initial, 'g', 10)); - item->setText(4, parameter.unit()); + item->setText(4, nmAutoFitDisplayUnit(parameter)); item->setCheckState(0, !m_sensitivitySettings - && (!well || well->getWellCode() == nmDataAnalyzeManager::getCurrentInstance()->getPrimaryWellCode()) + && (!well || well->getWellCode() == m_targetWellCode) ? Qt::Checked : Qt::Unchecked); m_parameterItems.append(item); } -QVector nmWxAutomaticFitting::primaryInitialValues() const +QVector nmWxAutomaticFitting::targetInitialValues() const { - // 旧六参数接口仅提取主井与共享储层,其他井不会覆盖主井初值。 + // 旧六参数接口仅提取目标井与共享储层,其他井不会覆盖目标井初值。 QVector values(6, 0.0); - const QString primaryCode = nmDataAnalyzeManager::getCurrentInstance()->getPrimaryWellCode(); const QVector& parameters = automaticFittingData.getModelParameters(); for(int i = 0; i < parameters.size(); ++i) - if(parameters[i].wellCode.isEmpty() || parameters[i].wellCode == primaryCode) + if(parameters[i].wellCode.isEmpty() || parameters[i].wellCode == m_targetWellCode) values[parameters[i].type] = parameters[i].initial; return values; } QStringList nmWxAutomaticFitting::selectedParameterLabels(bool units) const { - // LM 按完整向量顺序显示,PSO 沿用旧六参数类型顺序。 + // 单位与设置表格共用 XML 定义;LM 按完整向量顺序,PSO 按旧六参数顺序。 QStringList labels; const QVector& parameters = automaticFittingData.getModelParameters(); if(m_algorithmCombo->currentIndex() == 1) { for(int i = 0; i < parameters.size(); ++i) - if(parameters[i].selected) labels << (units ? parameters[i].unit() : parameters[i].name()); + if(parameters[i].selected) labels << (units ? nmAutoFitDisplayUnit(parameters[i]) : parameters[i].name()); } else { for(int type = 0; type < 6; ++type) for(int i = 0; i < parameters.size(); ++i) if(parameters[i].selected && parameters[i].type == type) - labels << (units ? parameters[i].unit() : parameters[i].name()); + labels << (units ? nmAutoFitDisplayUnit(parameters[i]) : parameters[i].name()); } return labels; } diff --git a/Src/nmNum/nmSubWxs/nmWxAutomaticFittingStart.cpp b/Src/nmNum/nmSubWxs/nmWxAutomaticFittingStart.cpp index 9b001382..be59f969 100644 --- a/Src/nmNum/nmSubWxs/nmWxAutomaticFittingStart.cpp +++ b/Src/nmNum/nmSubWxs/nmWxAutomaticFittingStart.cpp @@ -1,13 +1,9 @@ #include "nmWxAutomaticfittingStart.h" #include -#include #include #include #include #include -#include -#include -#include #include #include #include @@ -37,8 +33,7 @@ nmAutomaticFittingCurveChart::nmAutomaticFittingCurveChart(QWidget* parent) , m_bestFitness(0.0) , m_pseudoPressureMode(false) { - // 保留绘图空间,同时允许小屏幕压缩曲线区域的高度。 - setMinimumHeight(160); + setMinimumHeight(220); setMinimumWidth(420); } @@ -186,8 +181,7 @@ void nmAutomaticFittingCurveChart::paintEvent(QPaintEvent* event) QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); - // 保持全宽白色绘图区,曲线和实测标记沿用原有红绿配色。 - painter.fillRect(rect(), Qt::white); + painter.fillRect(rect(), QColor(240, 240, 240)); const int marginLeft = 62; const int marginTop = 18; @@ -197,7 +191,7 @@ void nmAutomaticFittingCurveChart::paintEvent(QPaintEvent* event) qMax(10, width() - marginLeft - marginRight), qMax(10, height() - marginTop - marginBottom)); - painter.fillRect(m_chartRect, Qt::white); + painter.fillRect(m_chartRect, QColor(252, 252, 252)); drawGrid(painter); drawAxes(painter); drawCurveLine(painter, m_bestPressure, QColor(250, 74, 74)); @@ -216,7 +210,7 @@ void nmAutomaticFittingCurveChart::drawGrid(QPainter& painter) int yStart = static_cast(qFloor(m_logRange.top())); int yEnd = static_cast(qCeil(m_logRange.bottom())); - painter.setPen(QPen(QColor(247, 248, 250), 1, Qt::SolidLine)); + painter.setPen(QPen(QColor(236, 236, 236), 1, Qt::SolidLine)); for(int decade = xStart; decade <= xEnd; ++decade) { for(int multiplier = 2; multiplier <= 9; ++multiplier) { double value = decade + qLn(static_cast(multiplier)) / qLn(10.0); @@ -243,7 +237,7 @@ void nmAutomaticFittingCurveChart::drawGrid(QPainter& painter) } } - painter.setPen(QPen(QColor(228, 232, 238), 1, Qt::SolidLine)); + painter.setPen(QPen(QColor(214, 214, 214), 1, Qt::SolidLine)); for(int x = xStart; x <= xEnd; ++x) { if(x < m_logRange.left() || x > m_logRange.right()) { continue; @@ -403,291 +397,167 @@ nmWxAutomaticfittingStart::nmWxAutomaticfittingStart(QWidget *parent) // 设置窗口属性 setWindowTitle(tr("Auto Fitting Progress")); - // 初始尺寸随所在屏幕变化,最小尺寸交给实际控件布局决定。 - resize(sizeHint()); + setMinimumSize(1000, 650); setModal(false); } -QSize nmWxAutomaticfittingStart::sizeHint() const -{ - // 默认窗口适当收紧,大屏限制推荐尺寸;仍由布局自适应并允许手动缩放。 - QDesktopWidget* desktop = QApplication::desktop(); - if(desktop == nullptr) return iDlgBase::sizeHint(); - const QRect available = desktop->availableGeometry(parentWidget() ? parentWidget()->window() : this); - return QSize(qMin(1440, available.width() * 65 / 100), - qMin(820, available.height() * 50 / 100)); -} - nmWxAutomaticfittingStart::~nmWxAutomaticfittingStart() { } void nmWxAutomaticfittingStart::setupUI() { - // 曲线和日志左右并排,参数横排占满下方整行,底部使用一行汇总。 - setObjectName("autoFittingProgress"); - setFont(QFont("Microsoft YaHei", 9)); - setStyleSheet( - "#autoFittingProgress { background: #ffffff; color: #233247; }" - "#autoFittingProgress QGroupBox { background: #ffffff; color: #233247; border: none; margin-top: 0; padding-top: 0; font-weight: bold; }" - "#autoFittingProgress QLabel { color: #66768a; background: transparent; font-weight: normal; }" - "#autoFittingProgress QGroupBox#fittingSummary { padding-top: 0; }" - "#autoFittingProgress QGroupBox#fittingSummary QLabel { font-size: 14px; color: #46556b; }" - "#autoFittingProgress QWidget#parameterStrip { background: #ffffff; border-top: 1px solid #e3e8ef; }" - "#autoFittingProgress QWidget#parameterContent { background: #ffffff; }" - "#autoFittingProgress QWidget#parameterSeparator { background: #e3e8ef; }" - "#autoFittingProgress QLabel#parameterName { font-size: 12px; }" - "#autoFittingProgress QLabel#parameterValue { color: #233247; font-size: 18px; font-weight: 500; }" - "#autoFittingProgress QGroupBox#fittingSummary QLabel#summaryValue { color: #233247; }" - "#autoFittingProgress QGroupBox#fittingSummary QLabel#stateBadge { background: #edf3fc; color: #366baf; border-radius: 5px; padding: 4px 10px; font-size: 12px; }" - "#autoFittingProgress QGroupBox#fittingLog { padding-top: 0; }" - "#autoFittingProgress QLabel#sectionHeading { color: #233247; font-size: 13px; font-weight: bold; }" - "#autoFittingProgress QWidget#fittingFooter { background: #ffffff; border-top: 1px solid #e3e8ef; }" - "#autoFittingProgress QLabel#resultSummary { color: #66768a; font-size: 14px; }" - "#autoFittingProgress QLabel#stageStatus { color: #66768a; font-size: 12px; }" - "#autoFittingProgress QLabel#runSummary { color: #46556b; font-size: 14px; }" - "#autoFittingProgress QTextEdit { border: none; background: #ffffff; color: #233247; font-size: 13px; font-weight: normal; selection-background-color: #eaf1fb; selection-color: #233247; }" - "#autoFittingProgress QPushButton { background: #ffffff; color: #46556b; border: 1px solid #cfd7e2; border-radius: 5px; padding: 8px 22px; min-width: 64px; min-height: 20px; }" - "#autoFittingProgress QPushButton:hover { background: #edf3fc; border-color: #9bb7db; }" - "#autoFittingProgress QPushButton:pressed { background: #dce8f8; }" - "#autoFittingProgress QPushButton:disabled { background: #f0f2f5; color: #98a2b1; border-color: #e0e5ec; }" - "#autoFittingProgress QPushButton#logToggle { border: none; background: transparent; color: #738091; min-width: 0; padding: 3px 8px; }" - "#autoFittingProgress QPushButton#logToggle:hover { color: #396fc0; }" - "#autoFittingProgress QSplitter::handle { background: #ffffff; }"); - - // 控件复用原有数据更新逻辑,仅重新组织所属区域。 + // 创建主要布局 + mainLayout = new QHBoxLayout(); + leftLayout = new QVBoxLayout(); + rightLayout = new QVBoxLayout(); + + // 设置左右布局 setupParameterArea(); - setupParameterStrip(); + setupTableArea(); setupChartArea(); - setupControlArea(); setupLogArea(); - // 日志只占右侧较窄区域,两侧底边对齐,分隔条允许调整宽度。 - rightSplitter = new QSplitter(Qt::Horizontal, this); - rightSplitter->setHandleWidth(4); + setupControlArea(); + + // 左侧布局 + leftLayout->addWidget(parameterGroup); + leftLayout->addStretch(); + leftLayout->addWidget(tableGroup); + + // 右侧布局 + rightSplitter = new QSplitter(Qt::Vertical, this); rightSplitter->addWidget(chartGroup); rightSplitter->addWidget(logGroup); - rightSplitter->setStretchFactor(0, 1); - rightSplitter->setStretchFactor(1, 1); - rightSplitter->setChildrenCollapsible(false); - rightSplitter->setSizes(QList() << 650 << 350); + rightSplitter->setStretchFactor(0, 3); + rightSplitter->setStretchFactor(1, 2); + rightSplitter->setSizes(QList() << 320 << 260); + rightLayout->addWidget(rightSplitter); + + // 主布局 + mainLayout->addLayout(leftLayout, 1); + mainLayout->addLayout(rightLayout, 2); // 控制区域布局 - QWidget* footer = new QWidget(this); - footer->setObjectName("fittingFooter"); - footer->setAttribute(Qt::WA_StyledBackground, true); - QHBoxLayout *controlLayout = new QHBoxLayout(footer); - controlLayout->setContentsMargins(22, 14, 22, 14); - controlLayout->setSpacing(24); - controlLayout->addWidget(resultSummary); - controlLayout->addWidget(runSummary); - controlLayout->addStretch(); - controlLayout->addWidget(progressBar, 1); + QHBoxLayout *controlLayout = new QHBoxLayout(); + controlLayout->addWidget(progressBar); controlLayout->addWidget(stopButton); QVBoxLayout *overallLayout = new QVBoxLayout(); - overallLayout->setContentsMargins(0, 0, 0, 0); - overallLayout->setSpacing(0); - overallLayout->addWidget(parameterGroup); - overallLayout->addWidget(rightSplitter, 1); - overallLayout->addWidget(parameterStrip); - overallLayout->addWidget(footer); + overallLayout->addLayout(mainLayout); + overallLayout->addLayout(controlLayout); setLayout(overallLayout); } void nmWxAutomaticfittingStart::setupParameterArea() { - parameterGroup = new QGroupBox(this); - parameterGroup->setObjectName("fittingSummary"); + parameterGroup = new QGroupBox(tr("Parameter Display"), this); + parameterGroup->setFixedWidth(280); QGridLayout *paramLayout = new QGridLayout(parameterGroup); - paramLayout->setContentsMargins(22, 19, 22, 17); - paramLayout->setHorizontalSpacing(12); - paramLayout->setVerticalSpacing(8); // 创建标签 algorithmTypeLabel = new QLabel(tr("Algorithm:")); - currentIterationLabel = new QLabel(tr("Iterations:")); + currentIterationLabel = new QLabel(tr("Current Iteration:")); + maxIterationLabel = new QLabel(tr("Max Iteration:")); currentComfortLabel = new QLabel(tr("Current Error:")); bestComfortLabel = new QLabel(tr("Best Error:")); - targetPrecisionLabel = new QLabel(tr("Target error:")); + targetPrecisionLabel = new QLabel(tr("Target Precision:")); targetWellLabel = new QLabel(tr("Target Well:")); // 创建数值显示标签 algorithmTypeValue = new QLabel("PSO"); - stateBadge = new QLabel(tr("Waiting for fitting to start")); - stateBadge->setObjectName("stateBadge"); - currentIterationValue = new QLabel("0 / 100"); - currentIterationValue->setObjectName("summaryValue"); + currentIterationValue = new QLabel("0"); + maxIterationValue = new QLabel("100"); currentComfortValue = new QLabel("N/A"); bestComfortValue = new QLabel("N/A"); targetPrecisionValue = new QLabel("0.001"); targetWellValue = new QLabel("N/A"); - algorithmTypeValue->setObjectName("summaryValue"); - targetWellValue->setObjectName("summaryValue"); - targetPrecisionValue->setObjectName("summaryValue"); - - // 顶部统一显示累计迭代数和上限;PSO 的额外误差信息放在第二行。 - paramLayout->addWidget(targetWellLabel, 0, 0); - paramLayout->addWidget(targetWellValue, 0, 1); - paramLayout->addWidget(algorithmTypeLabel, 0, 2); - paramLayout->addWidget(algorithmTypeValue, 0, 3); - paramLayout->addWidget(targetPrecisionLabel, 0, 4); - paramLayout->addWidget(targetPrecisionValue, 0, 5); - paramLayout->addWidget(currentIterationLabel, 0, 6); - paramLayout->addWidget(currentIterationValue, 0, 7); - paramLayout->addWidget(stateBadge, 0, 9, Qt::AlignRight | Qt::AlignVCenter); - paramLayout->addWidget(currentComfortLabel, 1, 0); - paramLayout->addWidget(currentComfortValue, 1, 1); - paramLayout->addWidget(bestComfortLabel, 1, 2); - paramLayout->addWidget(bestComfortValue, 1, 3); - paramLayout->setColumnStretch(8, 1); - targetWellValue->setWordWrap(true); + + // 添加到布局 + paramLayout->addWidget(algorithmTypeLabel, 0, 0); + paramLayout->addWidget(algorithmTypeValue, 0, 1); + paramLayout->addWidget(currentIterationLabel, 1, 0); + paramLayout->addWidget(currentIterationValue, 1, 1); + paramLayout->addWidget(maxIterationLabel, 2, 0); + paramLayout->addWidget(maxIterationValue, 2, 1); + paramLayout->addWidget(currentComfortLabel, 3, 0); + paramLayout->addWidget(currentComfortValue, 3, 1); + paramLayout->addWidget(bestComfortLabel, 4, 0); + paramLayout->addWidget(bestComfortValue, 4, 1); + paramLayout->addWidget(targetPrecisionLabel, 5, 0); + paramLayout->addWidget(targetPrecisionValue, 5, 1); + paramLayout->addWidget(targetWellLabel, 6, 0); + paramLayout->addWidget(targetWellValue, 6, 1); parameterGroup->setLayout(paramLayout); } -void nmWxAutomaticfittingStart::setupParameterStrip() +void nmWxAutomaticfittingStart::setupTableArea() { - // 标题固定,参数网格放入滚动区,避免参数数量撑大整个窗口。 - parameterStrip = new QWidget(this); - parameterStrip->setObjectName("parameterStrip"); - parameterStrip->setAttribute(Qt::WA_StyledBackground, true); - parameterStrip->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - QVBoxLayout* stripLayout = new QVBoxLayout(parameterStrip); - stripLayout->setContentsMargins(22, 4, 22, 4); - stripLayout->setSpacing(2); - QLabel* heading = new QLabel(tr("Current parameters"), parameterStrip); - heading->setObjectName("sectionHeading"); - stripLayout->addWidget(heading); - parameterScrollArea = new QScrollArea(parameterStrip); - parameterScrollArea->setFrameShape(QFrame::NoFrame); - parameterScrollArea->setWidgetResizable(true); - parameterScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - parameterScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); - parameterContent = new QWidget; - parameterContent->setObjectName("parameterContent"); - parameterContent->setAttribute(Qt::WA_StyledBackground, true); - parameterLayout = new QGridLayout(parameterContent); - parameterLayout->setContentsMargins(0, 0, 0, 0); - parameterLayout->setHorizontalSpacing(0); - parameterLayout->setVerticalSpacing(8); - parameterLayout->setAlignment(Qt::AlignTop); - parameterScrollArea->setWidget(parameterContent); - stripLayout->addWidget(parameterScrollArea); - parameterScrollArea->viewport()->installEventFilter(this); - parameterStrip->hide(); -} + tableGroup = new QGroupBox(tr("Parameter Table"), this); + tableGroup->setFixedWidth(300); -bool nmWxAutomaticfittingStart::eventFilter(QObject* watched, QEvent* event) -{ - // 按滚动区的实际宽度重新计算换行高度,窗口缩放后仍只显示两行。 - if(watched == parameterScrollArea->viewport() && event->type() == QEvent::Resize) { - updateParameterAreaHeight(); - } - return iDlgBase::eventFilter(watched, event); -} + QVBoxLayout *tableLayout = new QVBoxLayout(tableGroup); -void nmWxAutomaticfittingStart::updateParameterAreaHeight() -{ - if(parameterValues.isEmpty()) return; - const int columns = qMin(6, parameterValues.size()); - const int rows = (parameterValues.size() + 5) / 6; - const int scrollWidth = rows > 2 - ? parameterScrollArea->style()->pixelMetric(QStyle::PM_ScrollBarExtent) : 0; - const int cellWidth = qMax(1, - (parameterScrollArea->width() - scrollWidth - (columns - 1)) / columns); - int rowHeight = 0; - foreach(QLabel* value, parameterValues) { - QLayout* layout = value->parentWidget()->layout(); - rowHeight = qMax(rowHeight, qMax(layout->totalMinimumSize().height(), - layout->totalHeightForWidth(cellWidth))); - } - // 所有行使用相同高度,使第十三个参数开始完整地位于可滚动区域。 - foreach(QLabel* value, parameterValues) value->parentWidget()->setFixedHeight(rowHeight); - for(int row = 0; row < rows; ++row) parameterLayout->setRowMinimumHeight(row, rowHeight); - const int spacing = parameterLayout->verticalSpacing(); - parameterContent->setMinimumHeight(rows * rowHeight + (rows - 1) * spacing); - const int visibleRows = qMin(2, rows); - parameterScrollArea->setFixedHeight(visibleRows * rowHeight + (visibleRows - 1) * spacing); - parameterScrollArea->verticalScrollBar()->setSingleStep(rowHeight + spacing); + tableWidget = new QTableWidget(0, 2, this); + tableWidget->setHorizontalHeaderLabels(QStringList() << tr("Parameter Name") << tr("Optimal Value")); + + // 设置表格属性 + tableWidget->setAlternatingRowColors(true); + tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); + tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); + tableWidget->verticalHeader()->setVisible(false); + tableWidget->setMinimumHeight(310); + + // 设置列宽 + QHeaderView* header = tableWidget->horizontalHeader(); + header->setResizeMode(0, QHeaderView::ResizeToContents); + header->setResizeMode(1, QHeaderView::Stretch); + + // 设置表格填充整个区域 + tableWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + // 隐藏滚动条 + tableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + tableLayout->addWidget(tableWidget); + tableGroup->setLayout(tableLayout); } void nmWxAutomaticfittingStart::setupChartArea() { - // 曲线上方仅保留标题。 - chartGroup = new QGroupBox(this); + chartGroup = new QGroupBox(tr("Fitting Curve"), this); QVBoxLayout* chartLayout = new QVBoxLayout(chartGroup); - QLabel* heading = new QLabel(tr("Fitting Curve"), chartGroup); - heading->setObjectName("sectionHeading"); - chartLayout->addWidget(heading); curveChart = new nmAutomaticFittingCurveChart(chartGroup); curveChart->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - chartLayout->setContentsMargins(22, 17, 22, 12); + chartLayout->setMargin(6); chartLayout->addWidget(curveChart); chartGroup->setLayout(chartLayout); - chartGroup->setMinimumHeight(200); + chartGroup->setMinimumHeight(240); } void nmWxAutomaticfittingStart::setupLogArea() { - // 日志标题始终可见,正文收起时仍继续接收日志。 - logGroup = new QGroupBox(this); - logGroup->setObjectName("fittingLog"); + logGroup = new QGroupBox(tr("Log Window"), this); QVBoxLayout *logLayout = new QVBoxLayout(logGroup); - logLayout->setContentsMargins(18, 13, 22, 16); - logLayout->setSpacing(8); - logLayout->setAlignment(Qt::AlignTop); - QHBoxLayout* logHeader = new QHBoxLayout(); - QLabel* heading = new QLabel(tr("Fitting process"), logGroup); - heading->setObjectName("sectionHeading"); - logToggle = new QPushButton(tr("Collapse"), logGroup); - logToggle->setObjectName("logToggle"); - logToggle->setAutoDefault(false); - logHeader->addWidget(heading); - logHeader->addStretch(); - logHeader->addWidget(logToggle); - logLayout->addLayout(logHeader); - // 阶段状态放到标题下方,避免挤占窄日志区的标题和按钮。 - logLayout->addWidget(stageStatus); - connect(logToggle, SIGNAL(clicked()), this, SLOT(onToggleLog())); logTextEdit = new QTextEdit(this); logTextEdit->setReadOnly(true); - // 小屏幕允许缩短可见日志区域,完整内容仍可通过滚动查看。 - logTextEdit->setMinimumHeight(48); - logTextEdit->setMinimumWidth(180); - logTextEdit->setFont(font()); - // 正文与标题左对齐,沿用窗口白底,不额外绘制日志底色。 - logTextEdit->document()->setDocumentMargin(0); + logTextEdit->setFont(QFont("Consolas", 9)); // 添加初始日志 addLogMessage(tr("System initialization completed")); addLogMessage(tr("Waiting for fitting to start")); - logLayout->addWidget(logTextEdit, 1); + logLayout->addWidget(logTextEdit); logGroup->setLayout(logLayout); } void nmWxAutomaticfittingStart::setupControlArea() { - // 运行状态放在拟合过程标题下方;底部汇总保持单行。 - stageStatus = new QLabel(tr("Waiting for fitting to start"), this); - stageStatus->setObjectName("stageStatus"); - stageStatus->setWordWrap(true); - stageStatus->hide(); - resultSummary = new QLabel(this); - resultSummary->setObjectName("resultSummary"); - resultSummary->setTextFormat(Qt::RichText); - resultSummary->setWordWrap(false); - resultSummary->hide(); - runSummary = new QLabel(this); - runSummary->setObjectName("runSummary"); - runSummary->setWordWrap(false); - runSummary->hide(); // 进度条 progressBar = new QProgressBar(this); progressBar->setRange(0, 100); @@ -701,6 +571,7 @@ void nmWxAutomaticfittingStart::setupControlArea() // 停止按钮 stopButton = new QPushButton(tr("Stop"), this); + stopButton->setFixedSize(80, 30); stopButton->setEnabled(false); // 连接信号槽 @@ -712,10 +583,10 @@ void nmWxAutomaticfittingStart::setAutoFitter(nmCalculationAutoFitPSO* autoFitte m_autoFitterPSO = autoFitter; m_autoFitterLM = nullptr; m_algorithmName = "PSO"; - updateAlgorithmDisplay(); // 更新算法类型显示 algorithmTypeValue->setText("PSO"); + algorithmTypeValue->setStyleSheet("QLabel { color: blue; font-weight: bold; }"); if (m_autoFitterPSO) { connect(m_autoFitterPSO, SIGNAL(progressUpdated(int, double)), @@ -741,15 +612,13 @@ void nmWxAutomaticfittingStart::setAutoFitter(nmCalculationAutoFitLM* autoFitter m_autoFitterPSO = nullptr; m_autoFitterLM = autoFitter; m_algorithmName = "LM"; - updateAlgorithmDisplay(); // LM 日志由优化器统一组织,清除通用初始化提示。 logTextEdit->clear(); algorithmTypeValue->setText(m_algorithmName); + algorithmTypeValue->setStyleSheet("QLabel { color: blue; font-weight: bold; }"); if (m_autoFitterLM) { - connect(m_autoFitterLM, SIGNAL(fittingStageChanged(int)), - this, SLOT(onLMStageChanged(int))); connect(m_autoFitterLM, SIGNAL(progressUpdated(int, double)), this, SLOT(onFittingProgress(int, double))); connect(m_autoFitterLM, SIGNAL(fittingFinished(bool, QString)), @@ -765,48 +634,14 @@ void nmWxAutomaticfittingStart::setAutoFitter(nmCalculationAutoFitLM* autoFitter } } -void nmWxAutomaticfittingStart::updateAlgorithmDisplay() -{ - // 迭代数始终在顶部显示,PSO 保留原有额外误差和进度条。 - const bool lm = m_autoFitterLM != nullptr; - QLabel* psoLabels[] = { currentComfortLabel, currentComfortValue, - bestComfortLabel, bestComfortValue }; - for(int i = 0; i < 4; ++i) psoLabels[i]->setVisible(!lm); - progressBar->setVisible(!lm); - stageStatus->setVisible(lm); - resultSummary->setVisible(lm); - if(lm) updateCurrentError(m_autoFitterLM->getBestFitness()); - if(lm) onLMStageChanged(0); -} - -void nmWxAutomaticfittingStart::onLMStageChanged(int stage) -{ - // 仅更新拟合过程区域的运行状态,不在曲线上方增加阶段栏。 - const QString stages[] = { tr("Calculating initial error..."), tr("Height alignment"), - tr("Shape adjustment"), tr("Total-error adjustment") }; - stageStatus->setText(stages[stage]); -} - -void nmWxAutomaticfittingStart::onToggleLog() -{ - // 收起正文时把横向空间让给曲线,保留标题和按钮以便重新展开。 - const bool collapse = !logTextEdit->isHidden(); - if(collapse) expandedLogSizes = rightSplitter->sizes(); - logTextEdit->setVisible(!collapse); - logToggle->setText(collapse ? tr("Expand") : tr("Collapse")); - logGroup->layout()->activate(); - logGroup->setMaximumWidth(collapse ? logGroup->minimumSizeHint().width() : QWIDGETSIZE_MAX); - if(!collapse && !expandedLogSizes.isEmpty()) rightSplitter->setSizes(expandedLogSizes); -} - void nmWxAutomaticfittingStart::setFittingParameters(int maxIterations, double targetError, const QString& wellName) { m_maxIterations = maxIterations; m_targetError = targetError; m_wellName = wellName; - currentIterationValue->setText(QString("0 / %1").arg(maxIterations)); - targetPrecisionValue->setText(QString::number(targetError, 'g', 6)); + maxIterationValue->setText(QString::number(maxIterations)); + targetPrecisionValue->setText(formatScientific(targetError)); targetWellValue->setText(wellName); progressBar->setRange(0, maxIterations); @@ -819,7 +654,6 @@ void nmWxAutomaticfittingStart::setFittingParameters(int maxIterations, double t void nmWxAutomaticfittingStart::markFittingStarted() { m_startTime = QDateTime::currentDateTime(); - stateBadge->setText(tr("Fitting in progress")); const QString algorithmName = m_algorithmName; QString timestamp = m_startTime.toString("yyyy-MM-dd hh:mm:ss"); @@ -832,61 +666,24 @@ void nmWxAutomaticfittingStart::markFittingStarted() void nmWxAutomaticfittingStart::setSelectedParameters(const QStringList& parameterNames, const QStringList& parameterUnits) { - // 仅在选择变化时重建标签,拟合期间只更新数值,避免布局反复抖动。 - QLayoutItem* item = nullptr; - while((item = parameterLayout->takeAt(0)) != nullptr) { - delete item->widget(); - delete item; - } - parameterValues.clear(); - for(int column = 0; column < parameterLayout->columnCount(); ++column) { - parameterLayout->setColumnStretch(column, 0); - } - for(int row = 0; row < parameterLayout->rowCount(); ++row) { - parameterLayout->setRowMinimumHeight(row, 0); - } - parameterContent->setMinimumHeight(0); - for(int i = 0; i < parameterNames.size(); ++i) { - // 名称和单位在上、数值在下,相邻参数用细竖线分隔。 - const int row = i / 6; - const int column = i % 6; - QWidget* cell = new QWidget(parameterContent); - cell->setAttribute(Qt::WA_StyledBackground, true); - QVBoxLayout* cellLayout = new QVBoxLayout(cell); - cellLayout->setContentsMargins(12, 0, 12, 0); - cellLayout->setSpacing(2); - const QString unit = parameterUnits.value(i); - QLabel* name = new QLabel(parameterNames[i] + (unit.isEmpty() ? QString() : " / " + unit), cell); - name->setObjectName("parameterName"); - name->setWordWrap(true); - name->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred); - name->setAlignment(Qt::AlignCenter); - QLabel* value = new QLabel("--", cell); - value->setObjectName("parameterValue"); - value->setAlignment(Qt::AlignCenter); - value->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred); - value->setTextInteractionFlags(Qt::TextSelectableByMouse); - cellLayout->addWidget(name, 1); - cellLayout->addWidget(value); - parameterLayout->addWidget(cell, row, column * 2); - parameterLayout->setColumnStretch(column * 2, 1); - if(column > 0) { - // 分隔线独立于参数单元格,避免标题导致上下间距不一致。 - QWidget* separator = new QWidget(parameterContent); - separator->setObjectName("parameterSeparator"); - separator->setAttribute(Qt::WA_StyledBackground, true); - separator->setFixedWidth(1); - parameterLayout->addWidget(separator, row, column * 2 - 1); + m_selectedParameters = parameterNames; + m_parameterUnits = parameterUnits; + // 适配当前多井参数接口:单井恢复旧版简短名称,多井保留井名前缀以免混淆。 + QStringList wellNames; + foreach(const QString& name, parameterNames) { + const int separator = name.indexOf(" / "); + if(separator >= 0 && !wellNames.contains(name.left(separator))) + wellNames.append(name.left(separator)); + } + if(wellNames.size() == 1) { + for(int i = 0; i < m_selectedParameters.size(); ++i) { + const int separator = m_selectedParameters[i].indexOf(" / "); + if(separator >= 0) m_selectedParameters[i] = m_selectedParameters[i].mid(separator + 3); } - parameterValues.append(value); } - parameterStrip->setVisible(!parameterNames.isEmpty()); - // 立即显示当前已接受的参数值。 - updateParameterValues(); - parameterContent->ensurePolished(); - updateParameterAreaHeight(); - parameterScrollArea->verticalScrollBar()->setValue(0); + // 立即更新参数表格 + updateParameterTable(); const QString algorithmName = m_algorithmName; if(!m_autoFitterLM) addLogMessage(tr("%1 selected parameters: %2").arg(algorithmName).arg(parameterNames.join(", "))); @@ -908,17 +705,17 @@ void nmWxAutomaticfittingStart::setPseudoPressureMode(bool enabled) void nmWxAutomaticfittingStart::onFittingProgress(int iteration, double fitness) { - // LM 各阶段显示累计迭代次数;达到上限之前仍可能提前收敛,不显示完成百分比。 - currentIterationValue->setText(QString("%1 / %2").arg(qMax(0, iteration)).arg(m_maxIterations)); - if(m_autoFitterLM) { - updateCurrentError(fitness); - return; + // LM 预调整没有固定总步数,单独显示阶段;整体阶段从局部迭代 0 开始计进度。 + if (m_autoFitterLM && iteration < 0) { + progressBar->setValue(0); + progressBar->setFormat(tr("Pre-adjustment")); + currentIterationValue->setText(tr("Pre-adjustment")); } else { - int displayIteration = qMax(1, qMin(iteration, m_maxIterations)); + int displayIteration = qMax(m_autoFitterLM ? 0 : 1, qMin(iteration, m_maxIterations)); progressBar->setValue(displayIteration); double progress = (double)displayIteration / m_maxIterations * 100; progressBar->setFormat(QString("%1%").arg(progress, 0, 'f', 1)); - currentIterationValue->setText(QString("%1 / %2").arg(displayIteration).arg(m_maxIterations)); + currentIterationValue->setText(QString::number(displayIteration)); } currentComfortValue->setText(formatScientific(fitness)); @@ -931,8 +728,8 @@ void nmWxAutomaticfittingStart::onFittingProgress(int iteration, double fitness) if(!m_autoFitterLM) addLogMessage(tr("Better solution found: %1").arg(formatScientific(fitness))); - // 更新参数值。 - updateParameterValues(); + // 更新参数表格 + updateParameterTable(); } else { bestComfortValue->setStyleSheet("QLabel { color: black; }"); } @@ -942,20 +739,11 @@ void nmWxAutomaticfittingStart::onFittingFinished(bool success, const QString& m { m_isFinished = true; m_isFinalizing = false; - stateBadge->setText(success ? tr("Fitting ended") : tr("Fitting failed")); - stateBadge->setStyleSheet(success - ? "QLabel { color: #28765f; background: #edf7f2; }" - : "QLabel { color: #a04438; background: #fff0ed; }"); const QString algorithmName = m_algorithmName; // 更新状态 - if(m_autoFitterLM) { - stageStatus->setText(success ? tr("Fitting ended") : tr("Fitting failed")); - // 完成区直接读取优化器数值,失败评价显示占位符,不暴露惩罚值。 - updateCurrentError(m_autoFitterLM->getBestFitness()); - stageStatus->hide(); - } else if (success) { + if (success) { progressBar->setValue(m_maxIterations); // 区分正常完成和用户停止 @@ -1008,8 +796,8 @@ void nmWxAutomaticfittingStart::onFittingFinished(bool success, const QString& m disconnect(stopButton, SIGNAL(clicked()), this, SLOT(onStopButtonClicked())); connect(stopButton, SIGNAL(clicked()), this, SLOT(close())); - // 同步最终参数值。 - updateParameterValues(); + // 最终更新参数表格 + updateParameterTable(); // 添加完成时间戳 QDateTime endTime = QDateTime::currentDateTime(); @@ -1030,13 +818,9 @@ void nmWxAutomaticfittingStart::onFittingFinished(bool success, const QString& m // LM 的调用次数由优化器汇总,这里只在结束时显示一次总耗时。 if(m_autoFitterLM) { - // 不足一分钟只显示秒,窗口汇总和完成日志共用同一耗时文本。 - const QString elapsed = minutes == 0 ? tr("%1 s").arg(seconds, 0, 'f', 1) - : tr("%1 min %2 s").arg(minutes).arg(remainSec, 0, 'f', 1); - addLogMessage(tr("Total time: %1").arg(elapsed)); - runSummary->setText(tr("Solver calls: %1 | Total time: %2") - .arg(m_autoFitterLM->getSolverCallCount()).arg(elapsed)); - runSummary->show(); + // 复用现有翻译词条,避免拼成新原文后中文语言包无法匹配。 + addLogMessage(tr("Total time: %1").arg( + tr("%1 min %2 s").arg(minutes).arg(remainSec, 0, 'f', 1))); } else { addLogMessage(tr("Total fitting time: %1 s (%2 min %3 s), total solver calls: %4") .arg(seconds, 0, 'f', 2).arg(minutes).arg(remainSec, 0, 'f', 2).arg(totalEvaluations)); @@ -1049,8 +833,6 @@ void nmWxAutomaticfittingStart::onFinalizingStarted() { // 最终完整求解负责生成正式快照,此阶段不能再次停止或关闭进度窗口。 m_isFinalizing = true; - stateBadge->setText(tr("Finalizing...")); - if(m_autoFitterLM) stageStatus->setText(tr("Generating final result...")); stopButton->setEnabled(false); stopButton->setText(tr("Finalizing...")); addLogMessage(tr("Generating the final result with the current best parameters...")); @@ -1072,8 +854,6 @@ void nmWxAutomaticfittingStart::onStopButtonClicked() // 先锁定按钮,等优化循环退出后由 finalizingStarted() 切换到最终求解状态。 stopButton->setEnabled(false); stopButton->setText(tr("Stopping...")); - stateBadge->setText(tr("Stopping...")); - if(m_autoFitterLM) stageStatus->setText(tr("Stopping...")); if (m_autoFitterPSO) { m_autoFitterPSO->stopFitting(); } else if (m_autoFitterLM) { @@ -1084,25 +864,41 @@ void nmWxAutomaticfittingStart::onStopButtonClicked() } } -void nmWxAutomaticfittingStart::updateParameterValues() +void nmWxAutomaticfittingStart::updateParameterTable() { - // 使用当前已接受参数,普通数值优先显示十进制,极小数仍保留有效位。 - const QVector values = m_autoFitterLM ? m_autoFitterLM->getBestSolution() - : (m_autoFitterPSO ? m_autoFitterPSO->getBestSolution() : QVector()); - for(int i = 0; i < parameterValues.size(); ++i) { - parameterValues[i]->setText(i < values.size() ? QString::number(values[i], 'g', 6) : "--"); - parameterValues[i]->setToolTip(i < values.size() ? QString::number(values[i], 'g', 15) : QString()); - } -} + // 设置表格行数 + tableWidget->setRowCount(m_selectedParameters.size()); -void nmWxAutomaticfittingStart::updateCurrentError(double fitness) -{ - // 仅展示当前已接受参数对应的总误差,未获得有效结果时显示占位符。 - const QString value = nmAutoFitChartIsFinite(fitness) && fitness >= 0.0 && fitness < 1.0e9 - ? QString::number(fitness, 'f', 6) : "--"; - resultSummary->setText(tr("Current error: %1") - .arg(QString("%1").arg(value))); - resultSummary->show(); + // 更新表格内容 + for (int i = 0; i < m_selectedParameters.size(); ++i) { + // 参数名 + QTableWidgetItem* nameItem = new QTableWidgetItem(m_selectedParameters.at(i)); + // 单位只放入提示,保留旧版两列表格的名称和列宽。 + nameItem->setToolTip(m_selectedParameters.at(i) + + (m_parameterUnits.value(i).isEmpty() ? QString() : " / " + m_parameterUnits.value(i))); + nameItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); + tableWidget->setItem(i, 0, nameItem); + + // 最优参数值 + QString valueText = "N/A"; + + if (m_autoFitterPSO) { + QVector bestSolution = m_autoFitterPSO->getBestSolution(); + if (i < bestSolution.size()) { + valueText = formatScientific(bestSolution[i]); + } + } else if (m_autoFitterLM) { + QVector bestSolution = m_autoFitterLM->getBestSolution(); + if (i < bestSolution.size()) { + valueText = formatScientific(bestSolution[i]); + } + } + + QTableWidgetItem* valueItem = new QTableWidgetItem(valueText); + valueItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); + valueItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); + tableWidget->setItem(i, 1, valueItem); + } } void nmWxAutomaticfittingStart::addLogMessage(const QString& message) @@ -1181,9 +977,9 @@ void nmWxAutomaticfittingStart::onBestCurveUpdated(QVector > tar } curveChart->setBestLogLogData(bestData, iteration, fitness); - // 形状改善时总误差可能上升,参数值仍须同步到当前已接受曲线。 + // 当前 LM 的形状阶段可能提高总误差,参数仍需与已接受曲线同步。 if(m_autoFitterLM) { - updateParameterValues(); - updateCurrentError(fitness); + updateParameterTable(); + currentComfortValue->setText(formatScientific(fitness)); } }