///////////////////////////////////////////////////////////////////////////////// // // 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 // for more details. // ///////////////////////////////////////////////////////////////////////////////// #include "RicDeleteSubItemsFeature.h" #include "RimProject.h" #include "RimSummaryPlotCollection.h" #include "RimWellPathCollection.h" #include "RimWellPathFractureCollection.h" #include "cafPdmUiItem.h" #include "cafSelectionManager.h" #include CAF_CMD_SOURCE_INIT( RicDeleteSubItemsFeature, "RicDeleteSubItemsFeature" ); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RicDeleteSubItemsFeature::isCommandEnabled() { std::vector items; caf::SelectionManager::instance()->selectedItems( items ); if ( items.empty() ) return false; for ( auto* item : items ) { if ( !RicDeleteSubItemsFeature::hasDeletableSubItems( item ) ) return false; } return true; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicDeleteSubItemsFeature::onActionTriggered( bool isChecked ) { std::vector items; caf::SelectionManager::instance()->selectedItems( items ); CVF_ASSERT( items.size() > 0 ); for ( auto item : items ) { if ( !RicDeleteSubItemsFeature::hasDeletableSubItems( item ) ) continue; { auto collection = dynamic_cast( item ); if ( collection ) { collection->deleteAllPlots(); collection->updateConnectedEditors(); } } { auto collection = dynamic_cast( item ); if ( collection ) { collection->deleteAllWellPaths(); collection->updateConnectedEditors(); collection->scheduleRedrawAffectedViews(); } } { auto collection = dynamic_cast( item ); if ( collection ) { collection->deleteFractures(); collection->updateConnectedEditors(); RimProject* proj = nullptr; collection->firstAncestorOrThisOfType( proj ); if ( proj ) proj->reloadCompletionTypeResultsInAllViews(); } } } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicDeleteSubItemsFeature::setupActionLook( QAction* actionToSetup ) { actionToSetup->setText( "Delete Sub Items" ); actionToSetup->setIcon( QIcon( ":/Erase.svg" ) ); applyShortcutWithHintToAction( actionToSetup, QKeySequence::Delete ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RicDeleteSubItemsFeature::hasDeletableSubItems( caf::PdmUiItem* uiItem ) { { auto collection = dynamic_cast( uiItem ); if ( collection && !collection->plots().empty() ) { return true; } } { auto collection = dynamic_cast( uiItem ); if ( collection && !collection->allWellPaths().empty() ) { return true; } } { auto collection = dynamic_cast( uiItem ); if ( collection && !collection->allFractures().empty() ) { return true; } } return false; }