Skip to content

Commit

Permalink
Add copy/paste of cell filters
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Dec 7, 2023
1 parent 614dc92 commit 6cb4a2a
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "RicCopyReferencesToClipboardFeature.h"

#include "RimBoxIntersection.h"
#include "RimCellFilter.h"
#include "RimEclipseCase.h"
#include "RimEclipseView.h"
#include "RimEnsembleCurveSet.h"
Expand Down Expand Up @@ -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>();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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 );
};
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,16 @@ RimUserDefinedIndexFilter* RimCellFilterCollection::addNewUserDefinedIndexFilter
return pFilter;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCellFilterCollection::addFilterAndNotifyChanges( RimCellFilter* pFilter, RimCase* srcCase )
{
addFilter( pFilter );
pFilter->setCase( srcCase );
onFilterUpdated( pFilter );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class RimCellFilterCollection : public caf::PdmObject
RimUserDefinedFilter* addNewUserDefinedFilter( RimCase* srcCase );
RimUserDefinedIndexFilter* addNewUserDefinedIndexFilter( RimCase* srcCase, const std::vector<size_t>& defCellIndexes = {} );

void addFilterAndNotifyChanges( RimCellFilter* pFilter, RimCase* srcCase );
void removeFilter( RimCellFilter* filter );

bool isEmpty() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,8 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
}
else if ( dynamic_cast<RimCellFilterCollection*>( firstUiItem ) )
{
menuBuilder << "RicPasteCellFiltersFeature";
menuBuilder << "Separator";
menuBuilder << "RicNewPolygonFilterFeature";
menuBuilder << "RicNewUserDefinedFilterFeature";
menuBuilder << "RicNewUserDefinedIndexFilterFeature";
Expand Down

0 comments on commit 6cb4a2a

Please sign in to comment.