Add copy/paste of cell filters

This commit is contained in:
Magne Sjaastad
2023-12-07 13:20:34 +01:00
parent f421c43450
commit cf9a9d4bad
7 changed files with 155 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicPasteEclipseViewsFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicPasteGeoMechViewsFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicPasteIntersectionsFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicPasteCellFiltersFeature.h
)
set(SOURCE_GROUP_SOURCE_FILES
@@ -16,6 +17,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicPasteEclipseViewsFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicPasteGeoMechViewsFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicPasteIntersectionsFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicPasteCellFiltersFeature.cpp
)
list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})

View File

@@ -20,6 +20,7 @@
#include "RicCopyReferencesToClipboardFeature.h"
#include "RimBoxIntersection.h"
#include "RimCellFilter.h"
#include "RimEclipseCase.h"
#include "RimEclipseView.h"
#include "RimEnsembleCurveSet.h"
@@ -136,6 +137,7 @@ bool RicCopyReferencesToClipboardFeature::isCopyOfObjectSupported( caf::PdmObjec
if ( dynamic_cast<RimGridCrossPlotDataSet*>( pdmObject ) ) return true;
if ( dynamic_cast<RimModeledWellPath*>( pdmObject ) ) return true;
if ( dynamic_cast<RimSummaryMultiPlot*>( pdmObject ) ) return true;
if ( dynamic_cast<RimCellFilter*>( pdmObject ) ) return true;
// Copy support based combined logic
RimWellAllocationPlot* wellAllocPlot = pdmObject->firstAncestorOrThisOfType<RimWellAllocationPlot>();

View File

@@ -0,0 +1,99 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2023- 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 "RicPasteCellFiltersFeature.h"
#include "RicPasteFeatureImpl.h"
#include "RimCase.h"
#include "RimCellFilter.h"
#include "RimCellFilterCollection.h"
#include "cafPdmObjectGroup.h"
#include "cafPdmPointer.h"
#include "cafSelectionManager.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicPasteCellFiltersFeature, "RicPasteCellFiltersFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicPasteCellFiltersFeature::isCommandEnabled() const
{
caf::PdmObjectGroup objectGroup;
RicPasteFeatureImpl::findObjectsFromClipboardRefs( &objectGroup );
std::vector<caf::PdmPointer<RimCellFilter>> typedObjects;
objectGroup.objectsByType( &typedObjects );
if ( typedObjects.empty() )
{
return false;
}
if ( dynamic_cast<RimCellFilterCollection*>( caf::SelectionManager::instance()->selectedItem() ) )
{
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicPasteCellFiltersFeature::onActionTriggered( bool isChecked )
{
auto cellFilterCollection = dynamic_cast<RimCellFilterCollection*>( caf::SelectionManager::instance()->selectedItem() );
if ( !cellFilterCollection ) return;
auto eclipseCase = cellFilterCollection->firstAncestorOfType<RimCase>();
caf::PdmObjectGroup objectGroup;
RicPasteFeatureImpl::findObjectsFromClipboardRefs( &objectGroup );
for ( auto obj : objectGroup.objects )
{
auto duplicatedObject =
dynamic_cast<RimCellFilter*>( obj->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
if ( duplicatedObject )
{
cellFilterCollection->addFilterAndNotifyChanges( duplicatedObject, eclipseCase );
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicPasteCellFiltersFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Paste Filter" );
RicPasteFeatureImpl::setIconAndShortcuts( actionToSetup );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicPasteCellFiltersFeature::pasteGeometryCellFilters( RimCellFilterCollection* cellFilterCollection )
{
if ( !cellFilterCollection ) return;
}

View File

@@ -0,0 +1,39 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2023- 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 RimCellFilterCollection;
//==================================================================================================
///
//==================================================================================================
class RicPasteCellFiltersFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
bool isCommandEnabled() const override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
private:
void pasteGeometryCellFilters( RimCellFilterCollection* cellFilterCollection );
};

View File

@@ -292,6 +292,16 @@ RimUserDefinedIndexFilter* RimCellFilterCollection::addNewUserDefinedIndexFilter
return pFilter;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCellFilterCollection::addFilterAndNotifyChanges( RimCellFilter* pFilter, RimCase* srcCase )
{
addFilter( pFilter );
pFilter->setCase( srcCase );
onFilterUpdated( pFilter );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -58,6 +58,7 @@ public:
RimUserDefinedFilter* addNewUserDefinedFilter( RimCase* srcCase );
RimUserDefinedIndexFilter* addNewUserDefinedIndexFilter( RimCase* srcCase, const std::vector<size_t>& defCellIndexes = {} );
void addFilterAndNotifyChanges( RimCellFilter* pFilter, RimCase* srcCase );
void removeFilter( RimCellFilter* filter );
void notifyGridReload();

View File

@@ -1034,6 +1034,8 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
}
else if ( dynamic_cast<RimCellFilterCollection*>( firstUiItem ) )
{
menuBuilder << "RicPasteCellFiltersFeature";
menuBuilder << "Separator";
menuBuilder << "RicNewPolygonFilterFeature";
menuBuilder << "RicNewUserDefinedFilterFeature";
menuBuilder << "RicNewUserDefinedIndexFilterFeature";