///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2015- Statoil ASA // Copyright (C) 2015- Ceetron Solutions AS // // 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 // for more details. // ///////////////////////////////////////////////////////////////////////////////// #include "RicWellLogFileCloseFeature.h" #include "RimViewWindow.h" #include "RimWellAllocationPlot.h" #include "RimWellLogFile.h" #include "RimWellLogPlot.h" #include "RimWellPath.h" #include "RimWellPltPlot.h" #include "RimWellRftPlot.h" #include "cafPdmObjectHandle.h" #include "cafPdmUiObjectEditorHandle.h" #include "cafSelectionManagerTools.h" #include CAF_CMD_SOURCE_INIT( RicWellLogFileCloseFeature, "RicWellLogFileCloseFeature" ); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RicWellLogFileCloseFeature::isCommandEnabled() const { std::vector objects = caf::selectedObjectsByType(); return !objects.empty(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicWellLogFileCloseFeature::onActionTriggered( bool isChecked ) { std::vector objects = caf::selectedObjectsByType(); if ( objects.empty() ) return; for ( const auto& wellLogFile : objects ) { RimWellPath* parentWellPath = wellLogFile->firstAncestorOrThisOfType(); if ( parentWellPath ) { std::set referringPlots = referringWellLogPlots( wellLogFile ); parentWellPath->deleteWellLog( wellLogFile ); for ( RimViewWindow* plot : referringPlots ) { plot->loadDataAndUpdate(); } parentWellPath->updateConnectedEditors(); } } caf::PdmUiObjectEditorHandle::updateUiAllObjectEditors(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicWellLogFileCloseFeature::setupActionLook( QAction* actionToSetup ) { actionToSetup->setText( "Close Well Log File(s)" ); actionToSetup->setIcon( QIcon( ":/Close.svg" ) ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::set RicWellLogFileCloseFeature::referringWellLogPlots( const RimWellLogFile* wellLogFile ) { // Remove all curves displaying data from the specified wellLogFile std::vector referringObjects = wellLogFile->objectsWithReferringPtrFields(); std::set plots; for ( const auto& obj : referringObjects ) { RimWellAllocationPlot* allocationPlot = obj->firstAncestorOrThisOfType(); RimWellPltPlot* pltPlot = obj->firstAncestorOrThisOfType(); RimWellRftPlot* rftPlot = obj->firstAncestorOrThisOfType(); RimWellLogPlot* wellLogPlot = obj->firstAncestorOrThisOfType(); RimViewWindow* plot = allocationPlot ? dynamic_cast( allocationPlot ) : pltPlot ? dynamic_cast( pltPlot ) : rftPlot ? dynamic_cast( rftPlot ) : wellLogPlot ? dynamic_cast( wellLogPlot ) : nullptr; if ( plot != nullptr ) { plots.insert( plot ); } } return plots; }