2018-08-06 00:52:02 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2018-10-10 01:22:36 -05:00
|
|
|
// Copyright (C) 2018- Equinor ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2018-08-06 00:52:02 -05:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2018-08-06 00:52:02 -05:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2018-08-06 00:52:02 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "RicNewWellPathAttributeFeature.h"
|
|
|
|
|
2018-10-19 09:29:46 -05:00
|
|
|
#include "RimProject.h"
|
2018-08-29 06:43:48 -05:00
|
|
|
#include "RimWellPath.h"
|
|
|
|
#include "RimWellPathAttribute.h"
|
2018-08-06 00:52:02 -05:00
|
|
|
#include "RimWellPathAttributeCollection.h"
|
2018-10-19 09:29:46 -05:00
|
|
|
#include "Riu3DMainWindowTools.h"
|
2018-08-29 06:43:48 -05:00
|
|
|
|
2018-08-06 00:52:02 -05:00
|
|
|
#include "cafSelectionManager.h"
|
2018-08-29 06:43:48 -05:00
|
|
|
|
2018-08-06 00:52:02 -05:00
|
|
|
#include <QAction>
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_CMD_SOURCE_INIT( RicNewWellPathAttributeFeature, "RicNewWellPathAttributeFeature" );
|
2018-08-06 00:52:02 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-08-06 00:52:02 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RicNewWellPathAttributeFeature::isCommandEnabled()
|
|
|
|
{
|
|
|
|
{
|
2018-08-29 06:43:48 -05:00
|
|
|
std::vector<RimWellPathAttribute*> objects;
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::SelectionManager::instance()->objectsByType( &objects, caf::SelectionManager::FIRST_LEVEL );
|
2018-08-06 00:52:02 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( objects.size() > 0 )
|
2018-08-06 00:52:02 -05:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-29 06:43:48 -05:00
|
|
|
{
|
2020-08-26 08:52:47 -05:00
|
|
|
if ( caf::SelectionManager::instance()->selectedItemOfType<RimWellPath>() ||
|
|
|
|
caf::SelectionManager::instance()->selectedItemOfType<RimWellPathAttributeCollection>() )
|
2018-08-06 00:52:02 -05:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2020-08-26 08:52:47 -05:00
|
|
|
|
2018-08-06 00:52:02 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-08-06 00:52:02 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicNewWellPathAttributeFeature::onActionTriggered( bool isChecked )
|
2018-08-06 00:52:02 -05:00
|
|
|
{
|
|
|
|
std::vector<RimWellPathAttribute*> attributes;
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::SelectionManager::instance()->objectsByType( &attributes, caf::SelectionManager::FIRST_LEVEL );
|
2019-01-16 08:43:51 -06:00
|
|
|
|
|
|
|
RimWellPathAttribute* attribute = nullptr;
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( attributes.size() == 1u )
|
2018-08-06 00:52:02 -05:00
|
|
|
{
|
|
|
|
RimWellPathAttributeCollection* attributeCollection = nullptr;
|
2019-09-06 03:40:57 -05:00
|
|
|
attributes[0]->firstAncestorOrThisOfTypeAsserted( attributeCollection );
|
2018-10-05 03:26:26 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
attribute = new RimWellPathAttribute;
|
2018-10-05 03:26:26 -05:00
|
|
|
RimWellPath* wellPath = nullptr;
|
2019-09-06 03:40:57 -05:00
|
|
|
attributeCollection->firstAncestorOrThisOfTypeAsserted( wellPath );
|
2018-10-05 03:26:26 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
attribute->setDepthsFromWellPath( wellPath );
|
|
|
|
attributeCollection->insertAttribute( attributes[0], attribute );
|
2018-10-05 03:26:26 -05:00
|
|
|
|
2018-08-29 06:43:48 -05:00
|
|
|
attributeCollection->updateAllRequiredEditors();
|
2018-08-06 00:52:02 -05:00
|
|
|
}
|
2019-01-16 08:43:51 -06:00
|
|
|
else
|
2018-08-06 00:52:02 -05:00
|
|
|
{
|
2019-01-16 08:43:51 -06:00
|
|
|
RimWellPath* wellPath = caf::SelectionManager::instance()->selectedItemAncestorOfType<RimWellPath>();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( wellPath )
|
2018-08-30 02:37:10 -05:00
|
|
|
{
|
2019-01-16 08:43:51 -06:00
|
|
|
std::vector<RimWellPathAttributeCollection*> attributeCollections;
|
2019-09-06 03:40:57 -05:00
|
|
|
wellPath->descendantsIncludingThisOfType( attributeCollections );
|
|
|
|
if ( !attributeCollections.empty() )
|
2019-01-16 08:43:51 -06:00
|
|
|
{
|
|
|
|
attribute = new RimWellPathAttribute;
|
2019-09-06 03:40:57 -05:00
|
|
|
attribute->setDepthsFromWellPath( wellPath );
|
2019-01-16 08:43:51 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
attributeCollections[0]->insertAttribute( nullptr, attribute );
|
2019-01-16 08:43:51 -06:00
|
|
|
attributeCollections[0]->updateAllRequiredEditors();
|
|
|
|
|
|
|
|
wellPath->updateConnectedEditors();
|
2019-09-06 03:40:57 -05:00
|
|
|
Riu3DMainWindowTools::selectAsCurrentItem( attributeCollections[0] );
|
2019-01-16 08:43:51 -06:00
|
|
|
}
|
2018-08-30 02:37:10 -05:00
|
|
|
}
|
2018-08-06 00:52:02 -05:00
|
|
|
}
|
2019-01-16 08:43:51 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( attribute )
|
2019-01-16 08:43:51 -06:00
|
|
|
{
|
|
|
|
RimProject* project = nullptr;
|
2019-09-06 03:40:57 -05:00
|
|
|
attribute->firstAncestorOrThisOfTypeAsserted( project );
|
2019-01-16 08:43:51 -06:00
|
|
|
project->scheduleCreateDisplayModelAndRedrawAllViews();
|
|
|
|
}
|
2018-08-06 00:52:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-08-06 00:52:02 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicNewWellPathAttributeFeature::setupActionLook( QAction* actionToSetup )
|
2018-08-06 00:52:02 -05:00
|
|
|
{
|
2018-08-29 06:43:48 -05:00
|
|
|
std::vector<RimWellPathAttribute*> attributes;
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::SelectionManager::instance()->objectsByType( &attributes, caf::SelectionManager::FIRST_LEVEL );
|
|
|
|
if ( attributes.size() == 1u )
|
2018-08-29 06:43:48 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
actionToSetup->setText( QString( "Insert New Attribute before %1" ).arg( attributes[0]->componentTypeLabel() ) );
|
|
|
|
actionToSetup->setIcon( QIcon( ":/CasingDesign16x16.png" ) );
|
|
|
|
}
|
|
|
|
else if ( caf::SelectionManager::instance()->selectedItemOfType<RimWellPathAttributeCollection>() )
|
2018-08-29 06:43:48 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
actionToSetup->setText( "Append New Attribute" );
|
|
|
|
actionToSetup->setIcon( QIcon( ":/CasingDesign16x16.png" ) );
|
2018-08-29 06:43:48 -05:00
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
else if ( caf::SelectionManager::instance()->selectedItemOfType<RimWellPath>() )
|
2018-10-19 09:29:46 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
actionToSetup->setText( "Create Casing Design" );
|
|
|
|
actionToSetup->setIcon( QIcon( ":/CasingDesign16x16.png" ) );
|
2018-10-19 09:29:46 -05:00
|
|
|
}
|
2018-08-06 00:52:02 -05:00
|
|
|
}
|