mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-25 06:38:13 -05:00
Add validation to sector model export wizard (#13348)
* Add validation to sector model export wizard
This commit is contained in:
8 files changed
+204
-57
No files matched your search
@@ -83,7 +83,9 @@ void RicExportSectorModelFeature::onActionTriggered( bool isChecked )
|
||||
|
||||
if ( wizard.exec() == QDialog::Accepted )
|
||||
{
|
||||
QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
|
||||
doExport( exportSettings, view );
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,25 +61,37 @@ RicExportSectorModelUi::RicExportSectorModelUi()
|
||||
m_gridBoxSelection.uiCapability()->setUiEditorTypeName( caf::PdmUiRadioButtonEditor::uiEditorTypeName() );
|
||||
|
||||
CAF_PDM_InitField( &m_visibleWellsPadding, "VisibleWellsPadding", 2, "Well Padding", "", "Number of cells to add around visible wells", "" );
|
||||
m_visibleWellsPadding.setRange( 0, 100 );
|
||||
|
||||
CAF_PDM_InitField( &m_minI, "MinI", std::numeric_limits<int>::max(), "Min I, J, K" );
|
||||
CAF_PDM_InitField( &m_minJ, "MinJ", std::numeric_limits<int>::max(), "" );
|
||||
CAF_PDM_InitField( &m_minI, "MinI", 1, "Min I, J, K" );
|
||||
CAF_PDM_InitField( &m_minJ, "MinJ", 1, "" );
|
||||
m_minJ.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
|
||||
CAF_PDM_InitField( &m_minK, "MinK", std::numeric_limits<int>::max(), "" );
|
||||
CAF_PDM_InitField( &m_minK, "MinK", 1, "" );
|
||||
m_minK.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
|
||||
m_minI.setMinValue( 1 );
|
||||
m_minJ.setMinValue( 1 );
|
||||
m_minK.setMinValue( 1 );
|
||||
|
||||
CAF_PDM_InitField( &m_maxI, "MaxI", -std::numeric_limits<int>::max(), "Max I, J, K" );
|
||||
CAF_PDM_InitField( &m_maxJ, "MaxJ", -std::numeric_limits<int>::max(), "" );
|
||||
CAF_PDM_InitField( &m_maxI, "MaxI", 1, "Max I, J, K" );
|
||||
CAF_PDM_InitField( &m_maxJ, "MaxJ", 1, "" );
|
||||
m_maxJ.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
|
||||
CAF_PDM_InitField( &m_maxK, "MaxK", -std::numeric_limits<int>::max(), "" );
|
||||
CAF_PDM_InitField( &m_maxK, "MaxK", 1, "" );
|
||||
m_maxK.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
|
||||
|
||||
m_maxI.setMinValue( 1 );
|
||||
m_maxJ.setMinValue( 1 );
|
||||
m_maxK.setMinValue( 1 );
|
||||
|
||||
CAF_PDM_InitField( &m_refineGrid, "RefineGrid", false, "Enable Grid Refinement" );
|
||||
caf::PdmUiNativeCheckBoxEditor::configureFieldForEditor( &m_refineGrid );
|
||||
CAF_PDM_InitField( &m_refinementCountI, "RefinementCountI", 1, "Cell Count I, J, K" );
|
||||
CAF_PDM_InitField( &m_refinementCountJ, "RefinementCountJ", 1, "" );
|
||||
CAF_PDM_InitField( &m_refinementCountK, "RefinementCountK", 1, "" );
|
||||
|
||||
m_refinementCountI.setRange( 1, 10 );
|
||||
m_refinementCountJ.setRange( 1, 10 );
|
||||
m_refinementCountK.setRange( 1, 10 );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_bcpropKeywords, "BcpropKeywords", "BCPROP Keywords" );
|
||||
m_bcpropKeywords.uiCapability()->setUiEditorTypeName( caf::PdmUiTableViewEditor::uiEditorTypeName() );
|
||||
m_bcpropKeywords.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
|
||||
@@ -132,9 +144,9 @@ RicExportSectorModelUi::~RicExportSectorModelUi()
|
||||
void RicExportSectorModelUi::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
||||
{
|
||||
// must be kept in sync with the page names defined in the constructor
|
||||
CAF_ASSERT( m_pageNames.size() == 5 );
|
||||
CAF_ASSERT( m_pageNames.size() == (size_t)WizardPageEnum::TotalPages );
|
||||
|
||||
if ( uiConfigName == m_pageNames[0] )
|
||||
if ( uiConfigName == m_pageNames[WizardPageEnum::ExportSettings] )
|
||||
{
|
||||
uiOrdering.add( &m_exportDeckName );
|
||||
uiOrdering.add( &m_exportFolder );
|
||||
@@ -143,7 +155,7 @@ void RicExportSectorModelUi::defineUiOrdering( QString uiConfigName, caf::PdmUiO
|
||||
infoGrp->addNewLabel( QString( "Source Folder: " ) + m_eclipseCase->locationOnDisc() );
|
||||
infoGrp->addNewLabel( QString( "Source Case Name: " ) + m_eclipseCase->caseUserDescription() );
|
||||
}
|
||||
else if ( uiConfigName == m_pageNames[1] )
|
||||
else if ( uiConfigName == m_pageNames[WizardPageEnum::GridBoxSelection] )
|
||||
{
|
||||
uiOrdering.add( &m_gridBoxSelection, { .newRow = true, .totalColumnSpan = 4, .leftLabelColumnSpan = 1 } );
|
||||
|
||||
@@ -177,7 +189,7 @@ void RicExportSectorModelUi::defineUiOrdering( QString uiConfigName, caf::PdmUiO
|
||||
uiOrdering.addNewLabel( QString( "Total cells to export: %1" ).arg( m_totalCells ) );
|
||||
}
|
||||
}
|
||||
else if ( uiConfigName == m_pageNames[2] )
|
||||
else if ( uiConfigName == m_pageNames[WizardPageEnum::GridRefinement] )
|
||||
{
|
||||
uiOrdering.add( &m_refineGrid );
|
||||
uiOrdering.addNewLabel( "" );
|
||||
@@ -190,7 +202,7 @@ void RicExportSectorModelUi::defineUiOrdering( QString uiConfigName, caf::PdmUiO
|
||||
m_refinementCountJ.uiCapability()->setUiReadOnly( !m_refineGrid() );
|
||||
m_refinementCountK.uiCapability()->setUiReadOnly( !m_refineGrid() );
|
||||
}
|
||||
else if ( uiConfigName == m_pageNames[3] )
|
||||
else if ( uiConfigName == m_pageNames[WizardPageEnum::BoundaryConditions] )
|
||||
{
|
||||
uiOrdering.add( &m_boundaryCondition );
|
||||
uiOrdering.addNewLabel( "", { .newRow = false } ); // needed to get proper visual layout in BCCON/BCPROP case
|
||||
@@ -205,7 +217,7 @@ void RicExportSectorModelUi::defineUiOrdering( QString uiConfigName, caf::PdmUiO
|
||||
uiOrdering.add( &m_bcpropKeywords );
|
||||
}
|
||||
}
|
||||
else if ( uiConfigName == m_pageNames[4] )
|
||||
else if ( uiConfigName == m_pageNames[WizardPageEnum::SimulationJob] )
|
||||
{
|
||||
auto simGrp = uiOrdering.addNewGroup( "OPM Flow Simulation" );
|
||||
simGrp->add( &m_createSimulationJob );
|
||||
@@ -285,13 +297,6 @@ void RicExportSectorModelUi::setEclipseView( RimEclipseView* view )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicExportSectorModelUi::defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute )
|
||||
{
|
||||
if ( ( m_eclipseCase == nullptr ) || ( m_eclipseCase->eclipseCaseData() == nullptr ) ||
|
||||
( m_eclipseCase->eclipseCaseData()->mainGrid() == nullptr ) )
|
||||
return;
|
||||
|
||||
const RigMainGrid* mainGrid = m_eclipseCase->eclipseCaseData()->mainGrid();
|
||||
const cvf::Vec3st gridDimensions = mainGrid->cellCounts();
|
||||
|
||||
if ( field == &m_bcpropKeywords )
|
||||
{
|
||||
auto* tvAttr = dynamic_cast<caf::PdmUiTableViewEditorAttribute*>( attribute );
|
||||
@@ -301,43 +306,6 @@ void RicExportSectorModelUi::defineEditorAttribute( const caf::PdmFieldHandle* f
|
||||
tvAttr->alwaysEnforceResizePolicy = true;
|
||||
}
|
||||
}
|
||||
else if ( field == &m_visibleWellsPadding )
|
||||
{
|
||||
if ( auto lineEditorAttr = dynamic_cast<caf::PdmUiLineEditorAttribute*>( attribute ) )
|
||||
{
|
||||
// Wells padding should be between 0 and 100 cells
|
||||
lineEditorAttr->validator = new QIntValidator( 0, 100, nullptr );
|
||||
}
|
||||
}
|
||||
else if ( field == &m_refinementCountI || field == &m_refinementCountJ || field == &m_refinementCountK )
|
||||
{
|
||||
if ( auto lineEditorAttr = dynamic_cast<caf::PdmUiLineEditorAttribute*>( attribute ) )
|
||||
{
|
||||
auto* validator = new QIntValidator( 1, 10, nullptr );
|
||||
lineEditorAttr->validator = validator;
|
||||
}
|
||||
}
|
||||
else if ( field == &m_minI || field == &m_maxI )
|
||||
{
|
||||
if ( auto lineEditorAttr = dynamic_cast<caf::PdmUiLineEditorAttribute*>( attribute ) )
|
||||
{
|
||||
lineEditorAttr->validator = new QIntValidator( 1, (int)gridDimensions.x(), nullptr );
|
||||
}
|
||||
}
|
||||
else if ( field == &m_minJ || field == &m_maxJ )
|
||||
{
|
||||
if ( auto lineEditorAttr = dynamic_cast<caf::PdmUiLineEditorAttribute*>( attribute ) )
|
||||
{
|
||||
lineEditorAttr->validator = new QIntValidator( 1, (int)gridDimensions.y(), nullptr );
|
||||
}
|
||||
}
|
||||
else if ( field == &m_minK || field == &m_maxK )
|
||||
{
|
||||
if ( auto lineEditorAttr = dynamic_cast<caf::PdmUiLineEditorAttribute*>( attribute ) )
|
||||
{
|
||||
lineEditorAttr->validator = new QIntValidator( 1, (int)gridDimensions.z(), nullptr );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ( field == &m_exportFolder ) || ( field == &m_simulationJobFolder ) )
|
||||
{
|
||||
@@ -581,3 +549,124 @@ QString RicExportSectorModelUi::newSimulationJobName() const
|
||||
{
|
||||
return m_simulationJobName();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<QString, QString> RicExportSectorModelUi::validate( const QString& configName ) const
|
||||
{
|
||||
std::map<QString, QString> fieldErrors;
|
||||
|
||||
if ( configName == m_pageNames[WizardPageEnum::ExportSettings] )
|
||||
{
|
||||
if ( m_exportDeckName().trimmed().isEmpty() )
|
||||
{
|
||||
fieldErrors[m_exportDeckName.keyword()] = "Output sector model name cannot be empty.";
|
||||
}
|
||||
if ( m_exportFolder().path().trimmed().isEmpty() )
|
||||
{
|
||||
fieldErrors[m_exportFolder.keyword()] = "Export folder cannot be empty.";
|
||||
}
|
||||
if ( m_exportFolder().path() == m_eclipseCase->locationOnDisc() )
|
||||
{
|
||||
fieldErrors[m_exportFolder.keyword()] = "Export folder cannot be the same as the source case folder.";
|
||||
}
|
||||
}
|
||||
else if ( configName == m_pageNames[WizardPageEnum::GridBoxSelection] )
|
||||
{
|
||||
if ( ( m_eclipseCase == nullptr ) || ( m_eclipseCase->eclipseCaseData() == nullptr ) ||
|
||||
( m_eclipseCase->eclipseCaseData()->mainGrid() == nullptr ) )
|
||||
return {};
|
||||
|
||||
const RigMainGrid* mainGrid = m_eclipseCase->eclipseCaseData()->mainGrid();
|
||||
const cvf::Vec3st gridDimensions = mainGrid->cellCounts();
|
||||
|
||||
for ( auto& field : { &m_minI, &m_minJ, &m_minK, &m_maxI, &m_maxJ, &m_maxK } )
|
||||
{
|
||||
auto errStr = field->validate();
|
||||
if ( !errStr.isEmpty() )
|
||||
{
|
||||
fieldErrors[field->keyword()] = errStr;
|
||||
}
|
||||
}
|
||||
|
||||
if ( m_gridBoxSelection() == RiaModelExportDefines::MANUAL_SELECTION )
|
||||
{
|
||||
if ( m_minI() > m_maxI() )
|
||||
{
|
||||
fieldErrors[m_minI.keyword()] = "Min I cannot be larger than Max I.";
|
||||
}
|
||||
if ( m_minJ() > m_maxJ() )
|
||||
{
|
||||
fieldErrors[m_minJ.keyword()] = "Min J cannot be larger than Max J.";
|
||||
}
|
||||
if ( m_minK() > m_maxK() )
|
||||
{
|
||||
fieldErrors[m_minK.keyword()] = "Min K cannot be larger than Max K.";
|
||||
}
|
||||
if ( m_maxI() > (int)gridDimensions.x() )
|
||||
{
|
||||
fieldErrors[m_maxI.keyword()] = QString( "Max I cannot be larger than %1." ).arg( gridDimensions.x() );
|
||||
}
|
||||
if ( m_maxJ() > (int)gridDimensions.y() )
|
||||
{
|
||||
fieldErrors[m_maxJ.keyword()] = QString( "Max J cannot be larger than %1." ).arg( gridDimensions.y() );
|
||||
}
|
||||
if ( m_maxK() > (int)gridDimensions.z() )
|
||||
{
|
||||
fieldErrors[m_maxK.keyword()] = QString( "Max K cannot be larger than %1." ).arg( gridDimensions.z() );
|
||||
}
|
||||
}
|
||||
else if ( m_gridBoxSelection() == RiaModelExportDefines::VISIBLE_WELLS_BOX )
|
||||
{
|
||||
auto errStr = m_visibleWellsPadding.validate();
|
||||
if ( !errStr.isEmpty() )
|
||||
{
|
||||
fieldErrors[m_visibleWellsPadding.keyword()] = errStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( configName == m_pageNames[WizardPageEnum::GridRefinement] )
|
||||
{
|
||||
if ( m_refineGrid() )
|
||||
{
|
||||
for ( auto& field : { &m_refinementCountI, &m_refinementCountJ, &m_refinementCountK } )
|
||||
{
|
||||
auto errStr = field->validate();
|
||||
if ( !errStr.isEmpty() )
|
||||
{
|
||||
fieldErrors[field->keyword()] = errStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( configName == m_pageNames[WizardPageEnum::BoundaryConditions] )
|
||||
{
|
||||
// no validation needed
|
||||
}
|
||||
else if ( configName == m_pageNames[WizardPageEnum::SimulationJob] )
|
||||
{
|
||||
if ( m_createSimulationJob() )
|
||||
{
|
||||
if ( m_simulationJobName().trimmed().isEmpty() )
|
||||
{
|
||||
fieldErrors[m_simulationJobName.keyword()] = "Simulation job name cannot be empty.";
|
||||
}
|
||||
if ( m_simulationJobFolder().path().trimmed().isEmpty() )
|
||||
{
|
||||
fieldErrors[m_simulationJobFolder.keyword()] = "Simulation job working folder cannot be empty.";
|
||||
}
|
||||
if ( m_simulationJobFolder().path() == m_exportFolder().path() )
|
||||
{
|
||||
fieldErrors[m_simulationJobFolder.keyword()] = "Simulation job working folder cannot be the same as the export folder.";
|
||||
}
|
||||
if ( m_simulationJobFolder().path() == m_eclipseCase->locationOnDisc() )
|
||||
{
|
||||
fieldErrors[m_simulationJobFolder.keyword()] =
|
||||
"Simulation job working folder cannot be the same as the source case folder.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fieldErrors;
|
||||
}
|
||||
@@ -29,6 +29,8 @@
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
#include <map>
|
||||
|
||||
class RimKeywordBcprop;
|
||||
class RimEclipseCase;
|
||||
class RimEclipseView;
|
||||
@@ -77,8 +79,19 @@ protected:
|
||||
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
|
||||
void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override;
|
||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
||||
std::map<QString, QString> validate( const QString& configName ) const override;
|
||||
|
||||
private:
|
||||
enum WizardPageEnum : unsigned int
|
||||
{
|
||||
ExportSettings = 0,
|
||||
GridBoxSelection = 1,
|
||||
GridRefinement = 2,
|
||||
BoundaryConditions = 3,
|
||||
SimulationJob = 4,
|
||||
TotalPages = 5
|
||||
};
|
||||
|
||||
void applyBoundaryDefaults();
|
||||
static QString defaultFolder();
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ std::expected<void, QString> RigSimulationInputTool::exportSimulationInput( RimE
|
||||
deckFile.removeKeywords( "MAPAXES" );
|
||||
|
||||
// Save the modified deck file to the export directory
|
||||
if ( !deckFile.saveDeckInline( outputFolder.toStdString(), outputFile.toStdString() ) )
|
||||
if ( !deckFile.saveDeck( outputFolder.toStdString(), outputFile.toStdString() ) )
|
||||
{
|
||||
return std::unexpected( QString( "Failed to save modified deck file to '%1/%2'" ).arg( outputFolder ).arg( outputFile ) );
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "cafPdmUiPropertyView.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QMessageBox>
|
||||
#include <QStringList>
|
||||
#include <QWidget>
|
||||
|
||||
@@ -106,3 +107,33 @@ QSize RiuPropertyViewWizard::sizeHint() const
|
||||
|
||||
return maxSizeHint;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuPropertyViewWizard::validateCurrentPage()
|
||||
{
|
||||
int currentPageId = currentId();
|
||||
if ( currentPageId < 0 || currentPageId >= (int)m_pageWidgets.size() )
|
||||
{
|
||||
return QWizard::validateCurrentPage();
|
||||
}
|
||||
|
||||
caf::PdmUiPropertyView* pageWidget = m_pageWidgets[currentPageId];
|
||||
auto object = pageWidget->currentObject();
|
||||
|
||||
auto resultMap = object->validate( pageWidget->uiConfigurationName() );
|
||||
|
||||
if ( !resultMap.empty() )
|
||||
{
|
||||
QString errorMessages;
|
||||
for ( const auto& [fieldName, message] : resultMap )
|
||||
{
|
||||
errorMessages += QString( "Field '%1': %2\n" ).arg( fieldName, message );
|
||||
}
|
||||
QMessageBox::critical( this, "Input Error", errorMessages );
|
||||
return false;
|
||||
}
|
||||
|
||||
return QWizard::validateCurrentPage();
|
||||
}
|
||||
@@ -42,6 +42,9 @@ public:
|
||||
QSize minimumSizeHint() const override;
|
||||
QSize sizeHint() const override;
|
||||
|
||||
protected:
|
||||
bool validateCurrentPage() override;
|
||||
|
||||
private:
|
||||
std::vector<caf::PdmUiPropertyView*> m_pageWidgets;
|
||||
};
|
||||
@@ -138,6 +138,14 @@ void PdmUiPropertyView::setUiConfigurationName( QString uiConfigName )
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString PdmUiPropertyView::uiConfigurationName() const
|
||||
{
|
||||
return m_uiConfigName;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -74,6 +74,7 @@ public:
|
||||
~PdmUiPropertyView() override;
|
||||
|
||||
void setUiConfigurationName( QString uiConfigName );
|
||||
QString uiConfigurationName() const;
|
||||
PdmObjectHandle* currentObject();
|
||||
|
||||
QSize sizeHint() const override;
|
||||
|
||||
Reference in new issue
Block a user