From 9262873846aa7692eba798fb85ec1ab95b4f9b52 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Wed, 29 Aug 2018 13:43:48 +0200 Subject: [PATCH] #3285 Make context menu for well path attributes a bit more robust --- .../RicDeleteWellPathAttributeFeature.cpp | 4 +- .../RicNewWellPathAttributeFeature.cpp | 60 ++++++++++--------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/ApplicationCode/Commands/WellPathCommands/RicDeleteWellPathAttributeFeature.cpp b/ApplicationCode/Commands/WellPathCommands/RicDeleteWellPathAttributeFeature.cpp index 8306b7847e..0a236911ef 100644 --- a/ApplicationCode/Commands/WellPathCommands/RicDeleteWellPathAttributeFeature.cpp +++ b/ApplicationCode/Commands/WellPathCommands/RicDeleteWellPathAttributeFeature.cpp @@ -54,13 +54,11 @@ void RicDeleteWellPathAttributeFeature::onActionTriggered(bool isChecked) { RimWellPathAttributeCollection* wellPathAttributeCollection = nullptr; attributes[0]->firstAncestorOrThisOfTypeAsserted(wellPathAttributeCollection); - RimWellPath* wellPath = nullptr; - wellPathAttributeCollection->firstAncestorOrThisOfTypeAsserted(wellPath); for (RimWellPathAttribute* attributeToDelete : attributes) { wellPathAttributeCollection->deleteAttribute(attributeToDelete); } - wellPath->updateConnectedEditors(); + wellPathAttributeCollection->updateAllRequiredEditors(); } } diff --git a/ApplicationCode/Commands/WellPathCommands/RicNewWellPathAttributeFeature.cpp b/ApplicationCode/Commands/WellPathCommands/RicNewWellPathAttributeFeature.cpp index 3aae604ded..85eff5d2e8 100644 --- a/ApplicationCode/Commands/WellPathCommands/RicNewWellPathAttributeFeature.cpp +++ b/ApplicationCode/Commands/WellPathCommands/RicNewWellPathAttributeFeature.cpp @@ -17,10 +17,12 @@ ///////////////////////////////////////////////////////////////////////////////// #include "RicNewWellPathAttributeFeature.h" +#include "RimWellPath.h" +#include "RimWellPathAttribute.h" #include "RimWellPathAttributeCollection.h" -#include "RimWellPathTarget.h" -#include "RimModeledWellPath.h" + #include "cafSelectionManager.h" + #include CAF_CMD_SOURCE_INIT(RicNewWellPathAttributeFeature, "RicNewWellPathAttributeFeature"); @@ -30,25 +32,22 @@ CAF_CMD_SOURCE_INIT(RicNewWellPathAttributeFeature, "RicNewWellPathAttributeFeat //-------------------------------------------------------------------------------------------------- bool RicNewWellPathAttributeFeature::isCommandEnabled() { - { - std::vector objects; - caf::SelectionManager::instance()->objectsByType(&objects); - - if ( objects.size() > 0 ) - { - return true; - } - } { std::vector objects; caf::SelectionManager::instance()->objectsByType(&objects, caf::SelectionManager::FIRST_LEVEL); - if ( objects.size() > 0 ) + if (objects.size() > 0) { return true; } } + { + if (caf::SelectionManager::instance()->selectedItemAncestorOfType()) + { + return true; + } + } return false; } @@ -59,30 +58,23 @@ void RicNewWellPathAttributeFeature::onActionTriggered(bool isChecked) { std::vector attributes; caf::SelectionManager::instance()->objectsByType(&attributes, caf::SelectionManager::FIRST_LEVEL); - if (attributes.size() > 0) + if (attributes.size() == 1u) { RimWellPathAttributeCollection* attributeCollection = nullptr; attributes[0]->firstAncestorOrThisOfTypeAsserted(attributeCollection); - RimWellPath* wellPath = nullptr; - attributeCollection->firstAncestorOrThisOfTypeAsserted(wellPath); - attributes[0]->updateConnectedEditors(); attributeCollection->insertAttribute(attributes[0], new RimWellPathAttribute); - wellPath->updateConnectedEditors(); + attributeCollection->updateAllRequiredEditors(); return; } - std::vector wellPaths; - caf::SelectionManager::instance()->objectsByType(&wellPaths); - - if (wellPaths.size() > 0) + RimWellPath* wellPath = caf::SelectionManager::instance()->selectedItemAncestorOfType(); + if (wellPath) { std::vector attributeCollections; - wellPaths[0]->descendantsIncludingThisOfType(attributeCollections); - if (attributeCollections.size() > 0) - { - attributeCollections[0]->insertAttribute(nullptr, new RimWellPathAttribute); - } - wellPaths[0]->updateConnectedEditors(); + wellPath->descendantsIncludingThisOfType(attributeCollections); + + attributeCollections[0]->insertAttribute(nullptr, new RimWellPathAttribute); + attributeCollections[0]->updateAllRequiredEditors(); } } @@ -91,8 +83,18 @@ void RicNewWellPathAttributeFeature::onActionTriggered(bool isChecked) //-------------------------------------------------------------------------------------------------- void RicNewWellPathAttributeFeature::setupActionLook(QAction* actionToSetup) { - actionToSetup->setText("New Attribute"); - actionToSetup->setIcon(QIcon(":/Well.png")); + std::vector attributes; + caf::SelectionManager::instance()->objectsByType(&attributes, caf::SelectionManager::FIRST_LEVEL); + if (attributes.size() == 1u) + { + actionToSetup->setText(QString("Insert New Attribute before %1").arg(attributes[0]->label())); + actionToSetup->setIcon(QIcon(":/Well.png")); + } + else + { + actionToSetup->setText("Append New Attribute"); + actionToSetup->setIcon(QIcon(":/Well.png")); + } }