Files
ResInsight/ApplicationLibCode/Commands/JobCommands/RicDuplicateJobFeature.cpp
T
JJ e0c1f23e6e Support for ensemble jobs (#14773)
Initial support for running well planning opm flow jobs for ensembles
2026-09-17 14:03:54 +02:00

91 lines
3.1 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2025 Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicDuplicateJobFeature.h"
#include "RicNewOpmFlowJobFeature.h"
#include "Jobs/RimEnsembleJob.h"
#include "Jobs/RimJobCollection.h"
#include "Jobs/RimOpmFlowJob.h"
#include "RimTools.h"
#include "Riu3DMainWindowTools.h"
#include "cafSelectionManager.h"
#include <QAction>
#include <QDir>
#include <QFileInfo>
CAF_CMD_SOURCE_INIT( RicDuplicateJobFeature, "RicDuplicateJobFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicDuplicateJobFeature::onActionTriggered( bool isChecked )
{
if ( auto job = dynamic_cast<RimOpmFlowJob*>( caf::SelectionManager::instance()->selectedItem() ) )
{
QString defaultDir = job->mainWorkingDirectory();
QFileInfo fi( defaultDir );
defaultDir = fi.dir().absolutePath();
QString workDir = RicNewOpmFlowJobFeature::workingFolder( defaultDir );
if ( workDir.isEmpty() ) return;
if ( auto copiedJob = job->copyObject<RimOpmFlowJob>() )
{
copiedJob->setWorkingDirectory( workDir );
copiedJob->setName( job->name() + " (copy)" );
auto jobColl = RimTools::jobCollection();
jobColl->addNewJob( copiedJob );
copiedJob->resolveReferencesRecursively();
copiedJob->initAfterCopy();
Riu3DMainWindowTools::selectAsCurrentItem( copiedJob );
}
}
else if ( auto job = dynamic_cast<RimEnsembleJob*>( caf::SelectionManager::instance()->selectedItem() ) )
{
if ( auto copiedJob = job->copyObject<RimEnsembleJob>() )
{
copiedJob->setName( job->name() + " (copy)" );
auto jobColl = RimTools::jobCollection();
jobColl->addNewJob( copiedJob );
copiedJob->resolveReferencesRecursively();
copiedJob->initAfterCopy();
Riu3DMainWindowTools::selectAsCurrentItem( copiedJob );
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicDuplicateJobFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setIcon( QIcon( ":/Copy.svg" ) );
actionToSetup->setText( "Duplicate..." );
}