diff --git a/ApplicationCode/Commands/WellPathCommands/RicDeleteWellPathAttributeFeature.cpp b/ApplicationCode/Commands/WellPathCommands/RicDeleteWellPathAttributeFeature.cpp index 1e4ba8f8a8..115d733946 100644 --- a/ApplicationCode/Commands/WellPathCommands/RicDeleteWellPathAttributeFeature.cpp +++ b/ApplicationCode/Commands/WellPathCommands/RicDeleteWellPathAttributeFeature.cpp @@ -42,6 +42,13 @@ bool RicDeleteWellPathAttributeFeature::isCommandEnabled() return true; } } + { + if (caf::SelectionManager::instance()->selectedItemOfType()) + { + return true; + } + + } return false; } @@ -53,24 +60,32 @@ void RicDeleteWellPathAttributeFeature::onActionTriggered(bool isChecked) { std::vector attributes; caf::SelectionManager::instance()->objectsByType(&attributes, caf::SelectionManager::FIRST_LEVEL); + RimWellPathAttributeCollection* wellPathAttributeCollection = nullptr; if (attributes.size() > 0) - { - RimWellPathAttributeCollection* wellPathAttributeCollection = nullptr; + { attributes[0]->firstAncestorOrThisOfTypeAsserted(wellPathAttributeCollection); for (RimWellPathAttribute* attributeToDelete : attributes) { wellPathAttributeCollection->deleteAttribute(attributeToDelete); } wellPathAttributeCollection->updateAllRequiredEditors(); - - if (wellPathAttributeCollection->attributes().empty()) + } + else + { + wellPathAttributeCollection = caf::SelectionManager::instance()->selectedItemOfType(); + if (wellPathAttributeCollection) { - RimWellPath* wellPath = nullptr; - wellPathAttributeCollection->firstAncestorOrThisOfTypeAsserted(wellPath); - wellPath->updateConnectedEditors(); - Riu3DMainWindowTools::selectAsCurrentItem(wellPath); + wellPathAttributeCollection->deleteAllAttributes(); } } + + if (wellPathAttributeCollection->attributes().empty()) + { + RimWellPath* wellPath = nullptr; + wellPathAttributeCollection->firstAncestorOrThisOfTypeAsserted(wellPath); + wellPath->updateConnectedEditors(); + Riu3DMainWindowTools::selectAsCurrentItem(wellPath); + } } //-------------------------------------------------------------------------------------------------- @@ -78,6 +93,16 @@ void RicDeleteWellPathAttributeFeature::onActionTriggered(bool isChecked) //-------------------------------------------------------------------------------------------------- void RicDeleteWellPathAttributeFeature::setupActionLook(QAction* actionToSetup) { - actionToSetup->setText("Delete Attribute"); - actionToSetup->setIcon(QIcon(":/Erase.png")); + std::vector attributes; + caf::SelectionManager::instance()->objectsByType(&attributes, caf::SelectionManager::FIRST_LEVEL); + if (attributes.size() > 0) + { + actionToSetup->setText("Delete Attribute"); + actionToSetup->setIcon(QIcon(":/Erase.png")); + } + else if (caf::SelectionManager::instance()->selectedItemOfType()) + { + actionToSetup->setText("Delete Casing Design"); + actionToSetup->setIcon(QIcon(":/Erase.png")); + } } diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index 4aeda18a8f..5be779e978 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -82,6 +82,7 @@ #include "RimWellLogPlotCollection.h" #include "RimWellLogTrack.h" #include "RimWellPath.h" +#include "RimWellPathAttributeCollection.h" #include "RimWellPathCollection.h" #include "RimWellPltPlot.h" #include "RimWellRftPlot.h" @@ -312,6 +313,10 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "Separator"; } + else if (dynamic_cast(uiItem)) + { + menuBuilder << "RicDeleteWellPathAttributeFeature"; + } else if (dynamic_cast(uiItem) || dynamic_cast(uiItem) || dynamic_cast(uiItem) || diff --git a/ApplicationCode/ProjectDataModel/RimWellPathAttributeCollection.cpp b/ApplicationCode/ProjectDataModel/RimWellPathAttributeCollection.cpp index 5aff64f6f8..0f05e936ce 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPathAttributeCollection.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellPathAttributeCollection.cpp @@ -100,6 +100,15 @@ void RimWellPathAttributeCollection::deleteAttribute(RimWellPathAttribute* attri this->updateAllReferringTracks(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellPathAttributeCollection::deleteAllAttributes() +{ + m_attributes.deleteAllChildObjects(); + this->updateAllReferringTracks(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimWellPathAttributeCollection.h b/ApplicationCode/ProjectDataModel/RimWellPathAttributeCollection.h index 0f3d02e9a0..0fce98c610 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPathAttributeCollection.h +++ b/ApplicationCode/ProjectDataModel/RimWellPathAttributeCollection.h @@ -36,7 +36,7 @@ public: std::vector attributes() const; void insertAttribute(RimWellPathAttribute* insertBefore, RimWellPathAttribute* attribute); void deleteAttribute(RimWellPathAttribute* attributeToDelete); - + void deleteAllAttributes(); protected: void defineCustomContextMenu(const caf::PdmFieldHandle* fieldNeedingMenu, QMenu* menu, QWidget* fieldEditorWidget) override; void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute) override;