#include "nmWxDFNGenerateDlg.h" #include "nmDfnUiSupport.h" #include #include #include #include nmWxDFNGenerateDlg::nmWxDFNGenerateDlg(const nmDfnBoundary& oBoundary, QWidget* pParent) : iDlgBase(pParent), m_oBoundary(oBoundary) { initUI(); updateState(); if (!m_oBoundary.isValid()) { m_pErrorLabel->setText(tr("A valid model boundary is required.")); m_pErrorLabel->show(); } adjustSize(); } nmWxDFNGenerateDlg::~nmWxDFNGenerateDlg() { qDeleteAll(m_vecFields); } void nmWxDFNGenerateDlg::initUI() { setWindowTitle(tr("Generate DFN")); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); QVBoxLayout* pMain = new QVBoxLayout(this); pMain->setContentsMargins(12, 10, 12, 0); pMain->setSpacing(8); QGroupBox* pGeometry = new QGroupBox(tr("Geometry"), this); pGeometry->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); QGridLayout* pGrid = nmDfnUi::form(pGeometry); m_pCountSpin = new QSpinBox(pGeometry); m_pCountSpin->setRange(1, 1000); m_pCountSpin->setValue(5); nmDfnUi::label(pGrid, 0, tr("Fracture count"), pGeometry); pGrid->addWidget(m_pCountSpin, 0, 1, 1, 2); m_vecFields << new nmDfnValueField(pGrid, 1, tr("Minimum length"), "m", 100.0, pGeometry) << new nmDfnValueField(pGrid, 2, tr("Maximum length"), "m", 250.0, pGeometry) << new nmDfnValueField(pGrid, 3, tr("Minimum angle"), "deg", 0.0, pGeometry) << new nmDfnValueField(pGrid, 4, tr("Maximum angle"), "deg", 180.0, pGeometry) << new nmDfnValueField(pGrid, 5, tr("Minimum spacing"), "m", 20.0, pGeometry); m_pDistributionCombo = new QComboBox(pGeometry); m_pDistributionCombo->addItems(QStringList() << tr("Uniform distribution") << tr("Exponential distribution") << tr("Normal distribution")); nmDfnUi::label(pGrid, 6, tr("Distribution"), pGeometry); pGrid->addWidget(m_pDistributionCombo, 6, 1, 1, 2); pMain->addWidget(pGeometry); QGroupBox* pPhysical = new QGroupBox(tr("Physical parameters"), this); pPhysical->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); QGridLayout* pPhysicalGrid = nmDfnUi::form(pPhysical); m_pFlowModelCombo = new QComboBox(pPhysical); m_pFlowModelCombo->addItems(QStringList() << tr("Finite conductivity") << tr("Infinite conductivity")); nmDfnUi::label(pPhysicalGrid, 0, tr("Flow model"), pPhysical); pPhysicalGrid->addWidget(m_pFlowModelCombo, 0, 1, 1, 2); m_vecFields << new nmDfnValueField(pPhysicalGrid, 1, tr("Conductivity"), "mD.m", 1.0, pPhysical); m_pStorageEdit = new QLineEdit("1", pPhysical); nmDfnUi::label(pPhysicalGrid, 2, tr("Storage ratio"), pPhysical); pPhysicalGrid->addWidget(m_pStorageEdit, 2, 1, 1, 2); pMain->addWidget(pPhysical); pMain->addStretch(1); m_pErrorLabel = new QLabel(this); m_pErrorLabel->setWordWrap(true); m_pErrorLabel->hide(); pMain->addWidget(m_pErrorLabel); QDialogButtonBox* pButtons = nmDfnUi::buttons(this, tr("Generate"), tr("Cancel")); m_pGenerateButton = pButtons->button(QDialogButtonBox::Ok); pMain->addWidget(pButtons); connect(pButtons, SIGNAL(accepted()), this, SLOT(accept())); connect(pButtons, SIGNAL(rejected()), this, SLOT(reject())); connect(m_pCountSpin, SIGNAL(valueChanged(int)), this, SLOT(updateState())); connect(m_pStorageEdit, SIGNAL(textChanged(QString)), this, SLOT(updateState())); connect(m_pFlowModelCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateState())); for (int i = 0; i < m_vecFields.size(); ++i) { connect(m_vecFields[i]->editor(), SIGNAL(textChanged(QString)), this, SLOT(updateState())); connect(m_vecFields[i]->unitCombo(), SIGNAL(currentIndexChanged(int)), this, SLOT(onUnitChanged())); } } bool nmWxDFNGenerateDlg::readOptions(nmDfnGenerationOptions& oOptions, double& dConductivity, double& dStorage) { double values[6]; for (int i = 0; i < 5; ++i) if (!m_vecFields[i]->read(values[i])) return false; const bool bFinite = m_pFlowModelCombo->currentIndex() == 0; const bool bConductivityValid = m_vecFields[5]->read(values[5]) && values[5] >= 0.0; if (bFinite && !bConductivityValid) return false; if (!bConductivityValid) values[5] = 0.0; bool bOk = false; dStorage = m_pStorageEdit->text().toDouble(&bOk); if (!bOk || !qIsFinite(dStorage) || dStorage < 0.0 || values[0] <= 0.0 || values[1] < values[0] || values[2] < 0.0 || values[3] > 360.0 || values[3] < values[2] || values[4] < 0.0 || values[5] < 0.0) return false; oOptions.m_nCount = m_pCountSpin->value(); oOptions.m_dMinLength = values[0]; oOptions.m_dMaxLength = values[1]; if (!nmDfnUi::convert(values[2], "deg", "rad", oOptions.m_dMinAngle) || !nmDfnUi::convert(values[3], "deg", "rad", oOptions.m_dMaxAngle)) return false; oOptions.m_dSpacing = values[4]; oOptions.m_nDistribution = m_pDistributionCombo->currentIndex(); dConductivity = values[5]; return m_oBoundary.isValid(); } void nmWxDFNGenerateDlg::onUnitChanged() { for (int i = 0; i < m_vecFields.size(); ++i) if (sender() == m_vecFields[i]->unitCombo()) { m_vecFields[i]->changeUnit(); break; } updateState(); } void nmWxDFNGenerateDlg::updateState() { nmDfnGenerationOptions oOptions; double dConductivity = 0.0, dStorage = 0.0; m_pGenerateButton->setEnabled(readOptions(oOptions, dConductivity, dStorage)); // 无限导流仍保留已输入的有限导流参数,切回时无需重新录入。 const bool bFinite = m_pFlowModelCombo->currentIndex() == 0; m_vecFields[5]->editor()->setEnabled(bFinite); m_vecFields[5]->unitCombo()->setEnabled(bFinite && m_vecFields[5]->unitCombo()->count() > 1); if (m_oBoundary.isValid()) m_pErrorLabel->hide(); } void nmWxDFNGenerateDlg::accept() { nmDfnGenerationOptions oOptions; double dConductivity = 0.0, dStorage = 0.0; if (!readOptions(oOptions, dConductivity, dStorage)) return; nmDfnGenerator oGenerator(static_cast(QDateTime::currentMSecsSinceEpoch())); QVector vecGenerated; int nPlaced = 0; m_pGenerateButton->setEnabled(false); const bool bGenerated = oGenerator.generate(m_oBoundary, oOptions, vecGenerated, nPlaced); m_pGenerateButton->setEnabled(true); if (!bGenerated) { m_pErrorLabel->setText(tr("Only %1 of %2 fractures could be placed. Reduce the count, length or spacing.").arg(nPlaced).arg(oOptions.m_nCount)); m_pErrorLabel->show(); return; } for (int i = 0; i < vecGenerated.size(); ++i) { vecGenerated[i].m_dConductivity = dConductivity; vecGenerated[i].m_dStorageRatio = dStorage; vecGenerated[i].m_bFiniteConductivity = m_pFlowModelCombo->currentIndex() == 0; } m_vecRecords = vecGenerated; iDlgBase::accept(); } const QVector& nmWxDFNGenerateDlg::records() const { return m_vecRecords; }