mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-05 21:53:27 -06:00
a0ebb6e496
New syntax to copy an object auto curveCopy = curve->copyObject<RimSummaryCurve>(); Previous deprecated syntax RimColorLegend* customLegend = dynamic_cast<RimColorLegend*>( standardLegend->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
150 lines
5.6 KiB
C++
150 lines
5.6 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2018- 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 "RicPasteIntersectionsFeature.h"
|
|
|
|
#include "RicPasteFeatureImpl.h"
|
|
|
|
#include "RimBoxIntersection.h"
|
|
#include "RimExtrudedCurveIntersection.h"
|
|
#include "RimIntersectionCollection.h"
|
|
|
|
#include "RiuMainWindow.h"
|
|
|
|
#include "cafPdmObjectGroup.h"
|
|
#include "cafSelectionManager.h"
|
|
|
|
#include <QAction>
|
|
|
|
CAF_CMD_SOURCE_INIT( RicPasteIntersectionsFeature, "RicPasteIntersectionsFeature" );
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
bool RicPasteIntersectionsFeature::isCommandEnabled() const
|
|
{
|
|
caf::PdmObjectGroup objectGroup;
|
|
RicPasteFeatureImpl::findObjectsFromClipboardRefs( &objectGroup );
|
|
|
|
std::vector<caf::PdmPointer<RimExtrudedCurveIntersection>> intersectionObjects;
|
|
objectGroup.objectsByType( &intersectionObjects );
|
|
|
|
std::vector<caf::PdmPointer<RimBoxIntersection>> intersectionBoxObjects;
|
|
objectGroup.objectsByType( &intersectionBoxObjects );
|
|
|
|
if ( intersectionObjects.empty() && intersectionBoxObjects.empty() )
|
|
{
|
|
return false;
|
|
}
|
|
|
|
caf::PdmObjectHandle* destinationObject = dynamic_cast<caf::PdmObjectHandle*>( caf::SelectionManager::instance()->selectedItem() );
|
|
|
|
return findIntersectionCollection( destinationObject ) != nullptr;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RicPasteIntersectionsFeature::onActionTriggered( bool isChecked )
|
|
{
|
|
caf::PdmObjectHandle* destinationObject = dynamic_cast<caf::PdmObjectHandle*>( caf::SelectionManager::instance()->selectedItem() );
|
|
|
|
RimIntersectionCollection* intersectionCollection = RicPasteIntersectionsFeature::findIntersectionCollection( destinationObject );
|
|
|
|
CAF_ASSERT( intersectionCollection );
|
|
|
|
caf::PdmObjectGroup objectGroup;
|
|
RicPasteFeatureImpl::findObjectsFromClipboardRefs( &objectGroup );
|
|
|
|
if ( objectGroup.objects.empty() ) return;
|
|
|
|
std::vector<caf::PdmPointer<RimExtrudedCurveIntersection>> intersectionObjects;
|
|
objectGroup.objectsByType( &intersectionObjects );
|
|
|
|
for ( size_t i = 0; i < intersectionObjects.size(); i++ )
|
|
{
|
|
auto intersection = intersectionObjects[i]->copyObject<RimExtrudedCurveIntersection>();
|
|
QString nameOfCopy = QString( "Copy of " ) + intersection->name();
|
|
intersection->setName( nameOfCopy );
|
|
|
|
if ( i == intersectionObjects.size() - 1 )
|
|
{
|
|
intersectionCollection->appendIntersectionAndUpdate( intersection, false );
|
|
}
|
|
else
|
|
{
|
|
intersectionCollection->appendIntersectionNoUpdate( intersection );
|
|
}
|
|
}
|
|
|
|
std::vector<caf::PdmPointer<RimBoxIntersection>> intersectionBoxObjects;
|
|
objectGroup.objectsByType( &intersectionBoxObjects );
|
|
|
|
for ( size_t i = 0; i < intersectionBoxObjects.size(); i++ )
|
|
{
|
|
RimBoxIntersection* intersectionBox = intersectionBoxObjects[i]->copyObject<RimBoxIntersection>();
|
|
QString nameOfCopy = QString( "Copy of " ) + intersectionBox->name();
|
|
intersectionBox->setName( nameOfCopy );
|
|
|
|
if ( i == intersectionBoxObjects.size() - 1 )
|
|
{
|
|
intersectionCollection->appendIntersectionBoxAndUpdate( intersectionBox );
|
|
}
|
|
else
|
|
{
|
|
intersectionCollection->appendIntersectionBoxNoUpdate( intersectionBox );
|
|
}
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RicPasteIntersectionsFeature::setupActionLook( QAction* actionToSetup )
|
|
{
|
|
actionToSetup->setText( "Paste (Intersections)" );
|
|
|
|
RicPasteFeatureImpl::setIconAndShortcuts( actionToSetup );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimIntersectionCollection* RicPasteIntersectionsFeature::findIntersectionCollection( caf::PdmObjectHandle* objectHandle )
|
|
{
|
|
RimIntersectionCollection* intersectionCollection = dynamic_cast<RimIntersectionCollection*>( objectHandle );
|
|
if ( intersectionCollection )
|
|
{
|
|
return intersectionCollection;
|
|
}
|
|
|
|
RimExtrudedCurveIntersection* intersection = dynamic_cast<RimExtrudedCurveIntersection*>( objectHandle );
|
|
if ( intersection )
|
|
{
|
|
return intersection->firstAncestorOrThisOfType<RimIntersectionCollection>();
|
|
}
|
|
|
|
RimBoxIntersection* intersectionBox = dynamic_cast<RimBoxIntersection*>( objectHandle );
|
|
if ( intersectionBox )
|
|
{
|
|
return intersectionBox->firstAncestorOrThisOfType<RimIntersectionCollection>();
|
|
}
|
|
|
|
return nullptr;
|
|
}
|