#3285 Make context menu for well path attributes a bit more robust

This commit is contained in:
Gaute Lindkvist
2018-08-29 13:43:48 +02:00
parent 8e73f132cf
commit 9262873846
2 changed files with 32 additions and 32 deletions

View File

@@ -54,13 +54,11 @@ void RicDeleteWellPathAttributeFeature::onActionTriggered(bool isChecked)
{ {
RimWellPathAttributeCollection* wellPathAttributeCollection = nullptr; RimWellPathAttributeCollection* wellPathAttributeCollection = nullptr;
attributes[0]->firstAncestorOrThisOfTypeAsserted(wellPathAttributeCollection); attributes[0]->firstAncestorOrThisOfTypeAsserted(wellPathAttributeCollection);
RimWellPath* wellPath = nullptr;
wellPathAttributeCollection->firstAncestorOrThisOfTypeAsserted(wellPath);
for (RimWellPathAttribute* attributeToDelete : attributes) for (RimWellPathAttribute* attributeToDelete : attributes)
{ {
wellPathAttributeCollection->deleteAttribute(attributeToDelete); wellPathAttributeCollection->deleteAttribute(attributeToDelete);
} }
wellPath->updateConnectedEditors(); wellPathAttributeCollection->updateAllRequiredEditors();
} }
} }

View File

@@ -17,10 +17,12 @@
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
#include "RicNewWellPathAttributeFeature.h" #include "RicNewWellPathAttributeFeature.h"
#include "RimWellPath.h"
#include "RimWellPathAttribute.h"
#include "RimWellPathAttributeCollection.h" #include "RimWellPathAttributeCollection.h"
#include "RimWellPathTarget.h"
#include "RimModeledWellPath.h"
#include "cafSelectionManager.h" #include "cafSelectionManager.h"
#include <QAction> #include <QAction>
CAF_CMD_SOURCE_INIT(RicNewWellPathAttributeFeature, "RicNewWellPathAttributeFeature"); CAF_CMD_SOURCE_INIT(RicNewWellPathAttributeFeature, "RicNewWellPathAttributeFeature");
@@ -30,25 +32,22 @@ CAF_CMD_SOURCE_INIT(RicNewWellPathAttributeFeature, "RicNewWellPathAttributeFeat
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool RicNewWellPathAttributeFeature::isCommandEnabled() bool RicNewWellPathAttributeFeature::isCommandEnabled()
{ {
{
std::vector<RimWellPath*> objects;
caf::SelectionManager::instance()->objectsByType(&objects);
if ( objects.size() > 0 )
{
return true;
}
}
{ {
std::vector<RimWellPathAttribute*> objects; std::vector<RimWellPathAttribute*> objects;
caf::SelectionManager::instance()->objectsByType(&objects, caf::SelectionManager::FIRST_LEVEL); caf::SelectionManager::instance()->objectsByType(&objects, caf::SelectionManager::FIRST_LEVEL);
if ( objects.size() > 0 ) if (objects.size() > 0)
{ {
return true; return true;
} }
} }
{
if (caf::SelectionManager::instance()->selectedItemAncestorOfType<RimWellPath>())
{
return true;
}
}
return false; return false;
} }
@@ -59,30 +58,23 @@ void RicNewWellPathAttributeFeature::onActionTriggered(bool isChecked)
{ {
std::vector<RimWellPathAttribute*> attributes; std::vector<RimWellPathAttribute*> attributes;
caf::SelectionManager::instance()->objectsByType(&attributes, caf::SelectionManager::FIRST_LEVEL); caf::SelectionManager::instance()->objectsByType(&attributes, caf::SelectionManager::FIRST_LEVEL);
if (attributes.size() > 0) if (attributes.size() == 1u)
{ {
RimWellPathAttributeCollection* attributeCollection = nullptr; RimWellPathAttributeCollection* attributeCollection = nullptr;
attributes[0]->firstAncestorOrThisOfTypeAsserted(attributeCollection); attributes[0]->firstAncestorOrThisOfTypeAsserted(attributeCollection);
RimWellPath* wellPath = nullptr;
attributeCollection->firstAncestorOrThisOfTypeAsserted(wellPath);
attributes[0]->updateConnectedEditors();
attributeCollection->insertAttribute(attributes[0], new RimWellPathAttribute); attributeCollection->insertAttribute(attributes[0], new RimWellPathAttribute);
wellPath->updateConnectedEditors(); attributeCollection->updateAllRequiredEditors();
return; return;
} }
std::vector<RimWellPath*> wellPaths; RimWellPath* wellPath = caf::SelectionManager::instance()->selectedItemAncestorOfType<RimWellPath>();
caf::SelectionManager::instance()->objectsByType(&wellPaths); if (wellPath)
if (wellPaths.size() > 0)
{ {
std::vector<RimWellPathAttributeCollection*> attributeCollections; std::vector<RimWellPathAttributeCollection*> attributeCollections;
wellPaths[0]->descendantsIncludingThisOfType(attributeCollections); wellPath->descendantsIncludingThisOfType(attributeCollections);
if (attributeCollections.size() > 0)
{ attributeCollections[0]->insertAttribute(nullptr, new RimWellPathAttribute);
attributeCollections[0]->insertAttribute(nullptr, new RimWellPathAttribute); attributeCollections[0]->updateAllRequiredEditors();
}
wellPaths[0]->updateConnectedEditors();
} }
} }
@@ -91,8 +83,18 @@ void RicNewWellPathAttributeFeature::onActionTriggered(bool isChecked)
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicNewWellPathAttributeFeature::setupActionLook(QAction* actionToSetup) void RicNewWellPathAttributeFeature::setupActionLook(QAction* actionToSetup)
{ {
actionToSetup->setText("New Attribute"); std::vector<RimWellPathAttribute*> attributes;
actionToSetup->setIcon(QIcon(":/Well.png")); 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"));
}
} }