2018-12-13 12:49:37 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2016- 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 <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RicNewValveTemplateFeature.h"
|
|
|
|
|
|
|
|
#include "RimEclipseView.h"
|
|
|
|
#include "RimOilField.h"
|
|
|
|
#include "RimProject.h"
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "RimValveTemplate.h"
|
|
|
|
#include "RimValveTemplateCollection.h"
|
2019-01-15 06:49:46 -06:00
|
|
|
#include "RimWellPathValve.h"
|
2018-12-13 12:49:37 -06:00
|
|
|
|
|
|
|
#include "Riu3DMainWindowTools.h"
|
|
|
|
|
|
|
|
#include "cafSelectionManager.h"
|
|
|
|
|
|
|
|
#include "cvfAssert.h"
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_CMD_SOURCE_INIT( RicNewValveTemplateFeature, "RicNewValveTemplateFeature" );
|
2018-12-13 12:49:37 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicNewValveTemplateFeature::selectValveTemplateAndUpdate( RimValveTemplate* valveTemplate )
|
2018-12-13 12:49:37 -06:00
|
|
|
{
|
|
|
|
valveTemplate->loadDataAndUpdate();
|
|
|
|
|
2023-05-12 14:41:34 -05:00
|
|
|
RimValveTemplateCollection* templateCollection = valveTemplate->firstAncestorOrThisOfType<RimValveTemplateCollection>();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( templateCollection )
|
2019-01-15 06:49:46 -06:00
|
|
|
{
|
|
|
|
templateCollection->updateConnectedEditors();
|
|
|
|
}
|
2018-12-13 12:49:37 -06:00
|
|
|
|
2020-05-12 02:50:38 -05:00
|
|
|
RimProject* project = RimProject::current();
|
2018-12-13 12:49:37 -06:00
|
|
|
|
|
|
|
std::vector<Rim3dView*> views;
|
2019-09-06 03:40:57 -05:00
|
|
|
project->allVisibleViews( views );
|
2018-12-13 12:49:37 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( Rim3dView* view : views )
|
2018-12-13 12:49:37 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( dynamic_cast<RimEclipseView*>( view ) )
|
2018-12-13 12:49:37 -06:00
|
|
|
{
|
|
|
|
view->updateConnectedEditors();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
Riu3DMainWindowTools::selectAsCurrentItem( valveTemplate );
|
2018-12-13 12:49:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicNewValveTemplateFeature::createNewValveTemplateForValveAndUpdate( RimWellPathValve* valve )
|
2019-01-15 06:49:46 -06:00
|
|
|
{
|
|
|
|
RimValveTemplate* valveTemplate = createNewValveTemplate();
|
2019-09-06 03:40:57 -05:00
|
|
|
valve->setValveTemplate( valveTemplate );
|
|
|
|
selectValveTemplateAndUpdate( valveTemplate );
|
2019-01-15 06:49:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimValveTemplate* RicNewValveTemplateFeature::createNewValveTemplate()
|
2018-12-13 12:49:37 -06:00
|
|
|
{
|
2020-05-12 02:50:38 -05:00
|
|
|
RimProject* project = RimProject::current();
|
2019-09-06 03:40:57 -05:00
|
|
|
CVF_ASSERT( project );
|
2018-12-13 12:49:37 -06:00
|
|
|
|
|
|
|
RimOilField* oilfield = project->activeOilField();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( oilfield == nullptr ) return nullptr;
|
2018-12-13 12:49:37 -06:00
|
|
|
|
|
|
|
RimValveTemplateCollection* valveTemplateColl = oilfield->valveTemplateCollection();
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( valveTemplateColl )
|
2018-12-13 12:49:37 -06:00
|
|
|
{
|
|
|
|
RimValveTemplate* valveTemplate = new RimValveTemplate();
|
2023-02-26 03:48:40 -06:00
|
|
|
QString userLabel = QString( "Valve Template #%1" ).arg( valveTemplateColl->valveTemplates().size() + 1 );
|
2019-09-06 03:40:57 -05:00
|
|
|
valveTemplate->setUserLabel( userLabel );
|
|
|
|
valveTemplateColl->addValveTemplate( valveTemplate );
|
|
|
|
valveTemplate->setUnitSystem( valveTemplateColl->defaultUnitSystemType() );
|
2018-12-13 12:49:37 -06:00
|
|
|
valveTemplate->setDefaultValuesFromUnits();
|
2019-01-15 06:49:46 -06:00
|
|
|
return valveTemplate;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-12-13 12:49:37 -06:00
|
|
|
|
2019-01-15 06:49:46 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicNewValveTemplateFeature::onActionTriggered( bool isChecked )
|
2019-01-15 06:49:46 -06:00
|
|
|
{
|
|
|
|
RimValveTemplate* valveTemplate = createNewValveTemplate();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( valveTemplate )
|
2019-01-15 06:49:46 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
selectValveTemplateAndUpdate( valveTemplate );
|
2018-12-13 12:49:37 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicNewValveTemplateFeature::setupActionLook( QAction* actionToSetup )
|
2018-12-13 12:49:37 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
actionToSetup->setIcon( QIcon( ":/ICDValve16x16.png" ) );
|
|
|
|
actionToSetup->setText( "New Valve Template" );
|
2018-12-13 12:49:37 -06:00
|
|
|
}
|