ResInsight/ApplicationLibCode/Commands/CompletionCommands/RicWellPathImportCompletionsFileFeature.cpp
2021-01-11 15:27:45 +01:00

129 lines
4.9 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil 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 "RicWellPathImportCompletionsFileFeature.h"
#include "RiaApplication.h"
#include "RimFishboneWellPathCollection.h"
#include "RimFishbonesCollection.h"
#include "RimProject.h"
#include "RimWellPath.h"
#include "RimWellPathCollection.h"
#include "RimWellPathCompletions.h"
#include "Riu3DMainWindowTools.h"
#include "RiuFileDialogTools.h"
#include "cafSelectionManager.h"
#include <QAction>
#include <QFileInfo>
CAF_CMD_SOURCE_INIT( RicWellPathImportCompletionsFileFeature, "RicWellPathImportCompletionsFileFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicWellPathImportCompletionsFileFeature::isCommandEnabled()
{
if ( RicWellPathImportCompletionsFileFeature::selectedWellPathCollection() != nullptr )
{
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicWellPathImportCompletionsFileFeature::onActionTriggered( bool isChecked )
{
RimFishboneWellPathCollection* fishbonesWellPathCollection =
RicWellPathImportCompletionsFileFeature::selectedWellPathCollection();
CVF_ASSERT( fishbonesWellPathCollection );
// Open dialog box to select well path files
RiaApplication* app = RiaApplication::instance();
QString defaultDir = app->lastUsedDialogDirectory( "WELLPATH_DIR" );
QStringList wellPathFilePaths = RiuFileDialogTools::getOpenFileNames( Riu3DMainWindowTools::mainWindowWidget(),
"Import Fishbone Laterals",
defaultDir,
"Well Path Laterals (*.json *.asc *.asci "
"*.ascii *.dev);;All Files (*.*)" );
if ( wellPathFilePaths.size() < 1 ) return;
// Remember the path to next time
app->setLastUsedDialogDirectory( "WELLPATH_DIR", QFileInfo( wellPathFilePaths.last() ).absolutePath() );
fishbonesWellPathCollection->importCompletionsFromFile( wellPathFilePaths );
RimWellPathCollection* wellPathCollection;
fishbonesWellPathCollection->firstAncestorOrThisOfType( wellPathCollection );
if ( wellPathCollection )
{
wellPathCollection->updateConnectedEditors();
}
if ( app->project() )
{
app->project()->scheduleCreateDisplayModelAndRedrawAllViews();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicWellPathImportCompletionsFileFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Import Fishbone Laterals" );
actionToSetup->setIcon( QIcon( ":/FishBoneGroupFromFile16x16.png" ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFishboneWellPathCollection* RicWellPathImportCompletionsFileFeature::selectedWellPathCollection()
{
RimFishbonesCollection* objToFind = nullptr;
caf::PdmUiItem* pdmUiItem = caf::SelectionManager::instance()->selectedItem();
caf::PdmObjectHandle* objHandle = dynamic_cast<caf::PdmObjectHandle*>( pdmUiItem );
if ( objHandle )
{
objHandle->firstAncestorOrThisOfType( objToFind );
}
if ( objToFind == nullptr )
{
std::vector<RimWellPath*> wellPaths;
caf::SelectionManager::instance()->objectsByType( &wellPaths );
if ( !wellPaths.empty() )
{
return wellPaths[0]->fishbonesCollection()->wellPathCollection();
}
}
else
{
return objToFind->wellPathCollection();
}
return nullptr;
}