Skip to content

Commit

Permalink
WIP: add methods to add view
Browse files Browse the repository at this point in the history
  • Loading branch information
kriben committed Feb 19, 2024
1 parent 13f727d commit 0894dbe
Show file tree
Hide file tree
Showing 10 changed files with 268 additions and 13 deletions.
2 changes: 2 additions & 0 deletions ApplicationLibCode/Commands/CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicExportSummaryCalculationExpressionsFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicImportSummaryCalculationExpressionsFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicImportWellLogCsvFileFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicNewViewForGridEnsembleFeature.h
)

set(SOURCE_GROUP_SOURCE_FILES
Expand Down Expand Up @@ -191,6 +192,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicExportSummaryCalculationExpressionsFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicImportSummaryCalculationExpressionsFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicImportWellLogCsvFileFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicNewViewForGridEnsembleFeature.cpp
)

if(RESINSIGHT_USE_QT_CHARTS)
Expand Down
134 changes: 134 additions & 0 deletions ApplicationLibCode/Commands/RicNewViewForGridEnsembleFeature.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024- Equinor 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 "RicNewViewForGridEnsembleFeature.h"

#include "RiaLogging.h"

#include "Rim3dView.h"
#include "RimEclipseCase.h"
#include "RimEclipseCaseEnsemble.h"
#include "RimEclipseContourMapView.h"
#include "RimEclipseView.h"
#include "RimGeoMechCase.h"
#include "RimGeoMechView.h"

#include "Riu3DMainWindowTools.h"

#include "cafSelectionManager.h"

#include <QAction>

CAF_CMD_SOURCE_INIT( RicNewViewForGridEnsembleFeature, "RicNewViewForGridEnsembleFeature" );

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewViewForGridEnsembleFeature::addView( RimEclipseCaseEnsemble* eclipseCaseEnsemble )
{
std::vector<RimEclipseCase*> cases = eclipseCaseEnsemble->cases();
if ( cases.empty() ) return;

bool addToViews = false;
RimEclipseView* newView = cases[0]->createAndAddReservoirView( addToViews );

if ( newView )
{
eclipseCaseEnsemble->addView( newView );
eclipseCaseEnsemble->updateConnectedEditors();

Riu3DMainWindowTools::setExpanded( newView );

// Select the new view to make sure RiaApplication::setActiveReservoirView() is called
Riu3DMainWindowTools::selectAsCurrentItem( newView );
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicNewViewForGridEnsembleFeature::isCommandEnabled() const
{
return selectedEclipseCaseEnsemble() != nullptr;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewViewForGridEnsembleFeature::onActionTriggered( bool isChecked )
{
RimEclipseCaseEnsemble* eclipseCaseEnsemble = selectedEclipseCaseEnsemble();
addView( eclipseCaseEnsemble );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewViewForGridEnsembleFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "New View" );
actionToSetup->setIcon( QIcon( ":/3DView16x16.png" ) );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
// Rim3dView* RicNewViewForGridEnsembleFeature::createReservoirView( RimEclipseCase* eclipseCase, RimGeoMechCase* geomCase )
// {
// RimGridView* insertedView = nullptr;

// if ( eclipseCase )
// {
// insertedView = eclipseCase->createAndAddReservoirView();
// }
// else if ( geomCase )
// {
// insertedView = geomCase->createAndAddReservoirView();
// }

// // Must be run before buildViewItems, as wells are created in this function
// if ( insertedView ) insertedView->loadDataAndUpdate();

// if ( eclipseCase )
// {
// eclipseCase->updateConnectedEditors();
// }

// if ( geomCase )
// {
// geomCase->updateConnectedEditors();
// }

// return insertedView;
// }

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimEclipseCaseEnsemble* RicNewViewForGridEnsembleFeature::selectedEclipseCaseEnsemble()
{
std::vector<RimEclipseCaseEnsemble*> selection;
caf::SelectionManager::instance()->objectsByType( &selection );

if ( !selection.empty() )
{
return selection[0];
}

return nullptr;
}
42 changes: 42 additions & 0 deletions ApplicationLibCode/Commands/RicNewViewForGridEnsembleFeature.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024- Equinor 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.
//
/////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "cafCmdFeature.h"

class RimEclipseCaseEnsemble;
class RimEclipseView;

//==================================================================================================
///
//==================================================================================================
class RicNewViewForGridEnsembleFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;

public:
static void addView( RimEclipseCaseEnsemble* eclipseCaseEnsemble );

protected:
bool isCommandEnabled() const override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;

static RimEclipseCaseEnsemble* selectedEclipseCaseEnsemble();
};
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "RimCustomObjectiveFunctionCollection.h"
#include "RimEclipseCase.h"
#include "RimEclipseCaseCollection.h"
#include "RimEclipseCaseEnsemble.h"
#include "RimEclipseCellColors.h"
#include "RimEclipseContourMapView.h"
#include "RimEclipseContourMapViewCollection.h"
Expand Down Expand Up @@ -272,6 +273,10 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
menuBuilder << "Separator";
menuBuilder << "RicNewStatisticsCaseFeature";
}
else if ( dynamic_cast<RimEclipseCaseEnsemble*>( firstUiItem ) )
{
menuBuilder << "RicNewViewForGridEnsembleFeature";
}
else if ( dynamic_cast<RimGeoMechModels*>( firstUiItem ) )
{
menuBuilder << "RicImportGeoMechCaseFeature";
Expand Down
7 changes: 5 additions & 2 deletions ApplicationLibCode/ProjectDataModel/RimEclipseCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ void RimEclipseCase::initAfterRead()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimEclipseView* RimEclipseCase::createAndAddReservoirView()
RimEclipseView* RimEclipseCase::createAndAddReservoirView( bool addToViews )
{
RimEclipseView* rimEclipseView = new RimEclipseView();

Expand All @@ -313,7 +313,10 @@ RimEclipseView* RimEclipseCase::createAndAddReservoirView()

caf::PdmDocument::updateUiIconStateRecursively( rimEclipseView );

reservoirViews().push_back( rimEclipseView );
if ( addToViews )
{
reservoirViews().push_back( rimEclipseView );
}

return rimEclipseView;
}
Expand Down
2 changes: 1 addition & 1 deletion ApplicationLibCode/ProjectDataModel/RimEclipseCase.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class RimEclipseCase : public RimCase
RimReservoirCellResultsStorage* resultsStorage( RiaDefines::PorosityModelType porosityModel );
const RimReservoirCellResultsStorage* resultsStorage( RiaDefines::PorosityModelType porosityModel ) const;

RimEclipseView* createAndAddReservoirView();
RimEclipseView* createAndAddReservoirView( bool addToViews = true );
RimEclipseView* createCopyAndAddView( const RimEclipseView* sourceView );

const RigVirtualPerforationTransmissibilities* computeAndGetVirtualPerforationTransmissibilities();
Expand Down
58 changes: 58 additions & 0 deletions ApplicationLibCode/ProjectDataModel/RimEclipseCaseEnsemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "RimEclipseCase.h"
#include "RimEclipseCellColors.h"
#include "RimEclipseResultCase.h"
#include "RimEclipseView.h"

#include "cafPdmFieldScriptingCapability.h"
#include "cafPdmObjectScriptingCapability.h"
Expand All @@ -46,6 +47,10 @@ RimEclipseCaseEnsemble::RimEclipseCaseEnsemble()
m_caseCollection->uiCapability()->setUiName( "Cases" );
m_caseCollection->uiCapability()->setUiIconFromResourceString( ":/Cases16x16.png" );

CAF_PDM_InitFieldNoDefault( &m_selectedCase, "SelectedCase", "Selected Case" );

CAF_PDM_InitFieldNoDefault( &m_views, "Views", "Views" );

setDeletable( true );
}

Expand Down Expand Up @@ -99,3 +104,56 @@ bool RimEclipseCaseEnsemble::contains( RimEclipseCase* reservoir ) const

return false;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimEclipseCase*> RimEclipseCaseEnsemble::cases() const
{
return m_caseCollection->reservoirs.childrenByType();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEclipseCaseEnsemble::addView( RimEclipseView* view )
{
m_views.push_back( view );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QList<caf::PdmOptionItemInfo> RimEclipseCaseEnsemble::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions )
{
QList<caf::PdmOptionItemInfo> options;

if ( fieldNeedingOptions == &m_selectedCase )
{
for ( auto eclCase : cases() )
{
options.push_back( caf::PdmOptionItemInfo( eclCase->caseUserDescription(), eclCase, false, eclCase->uiIconProvider() ) );
}

return options;
}

return options;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEclipseCaseEnsemble::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
{
if ( changedField == &m_selectedCase )
{
for ( auto view : m_views )
{
view->setEclipseCase( m_selectedCase() );
view->loadDataAndUpdate();
view->updateGridBoxData();
view->updateAnnotationItems();
}
}
}
17 changes: 15 additions & 2 deletions ApplicationLibCode/ProjectDataModel/RimEclipseCaseEnsemble.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@

#include "RimNamedObject.h"

#include "cafPdmChildArrayField.h"
#include "cafPdmChildField.h"
#include "cafPdmField.h"
#include "cafPdmPtrField.h"

class RimCaseCollection;
class RimEclipseCase;
class RimEclipseView;

//==================================================================================================
//
Expand All @@ -43,7 +46,17 @@ class RimEclipseCaseEnsemble : public RimNamedObject
void removeCase( RimEclipseCase* reservoir );
bool contains( RimEclipseCase* reservoir ) const;

std::vector<RimEclipseCase*> cases() const;

void addView( RimEclipseView* view );

protected:
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override;
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;

private:
caf::PdmField<int> m_groupId;
caf::PdmChildField<RimCaseCollection*> m_caseCollection;
caf::PdmField<int> m_groupId;
caf::PdmChildField<RimCaseCollection*> m_caseCollection;
caf::PdmChildArrayField<RimEclipseView*> m_views;
caf::PdmPtrField<RimEclipseCase*> m_selectedCase;
};
Original file line number Diff line number Diff line change
Expand Up @@ -769,15 +769,15 @@ QList<caf::PdmOptionItemInfo> RimEclipseResultDefinition::calculateValueOptions(
{
options.push_back( caf::PdmOptionItemInfo( "None", nullptr ) );

auto eclipseCase = firstAncestorOrThisOfTypeAsserted<RimEclipseCase>();
if ( eclipseCase && eclipseCase->eclipseCaseData() && eclipseCase->eclipseCaseData()->mainGrid() )
auto currentCase = eclipseCase();
if ( currentCase && currentCase->eclipseCaseData() && currentCase->eclipseCaseData()->mainGrid() )
{
RimProject* proj = RimProject::current();

std::vector<RimEclipseCase*> allCases = proj->eclipseCases();
for ( RimEclipseCase* otherCase : allCases )
{
if ( otherCase == eclipseCase ) continue;
if ( otherCase == currentCase ) continue;

if ( otherCase->eclipseCaseData() && otherCase->eclipseCaseData()->mainGrid() )
{
Expand All @@ -792,7 +792,7 @@ QList<caf::PdmOptionItemInfo> RimEclipseResultDefinition::calculateValueOptions(
}
else if ( fieldNeedingOptions == &m_timeLapseBaseTimestep )
{
RimEclipseCase* currentCase = firstAncestorOrThisOfTypeAsserted<RimEclipseCase>();
RimEclipseCase* currentCase = eclipseCase();

RimEclipseCase* baseCase = currentCase;
if ( m_differenceCase )
Expand Down
6 changes: 2 additions & 4 deletions ApplicationLibCode/ProjectDataModel/RimEclipseView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1257,11 +1257,9 @@ QString RimEclipseView::createAutoName() const

QStringList generatedAutoTags;

RimCase* ownerCase = firstAncestorOrThisOfTypeAsserted<RimCase>();

if ( nameConfig()->addCaseName() )
if ( nameConfig()->addCaseName() && ownerCase() )
{
generatedAutoTags.push_back( ownerCase->caseUserDescription() );
generatedAutoTags.push_back( ownerCase()->caseUserDescription() );
}

if ( nameConfig()->addProperty() )
Expand Down

0 comments on commit 0894dbe

Please sign in to comment.