2018-01-24 04:44:20 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2019-01-09 08:21:38 -06:00
|
|
|
// Copyright (C) 2018- Equinor ASA
|
2018-01-24 04:44:20 -06:00
|
|
|
//
|
|
|
|
// 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 "RimIntersection.h"
|
|
|
|
#include "RimIntersectionBox.h"
|
|
|
|
#include "RimIntersectionCollection.h"
|
|
|
|
|
|
|
|
#include "RiuMainWindow.h"
|
|
|
|
|
|
|
|
#include "cafPdmObjectGroup.h"
|
|
|
|
#include "cafSelectionManager.h"
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_CMD_SOURCE_INIT( RicPasteIntersectionsFeature, "RicPasteIntersectionsFeature" );
|
2018-01-24 04:44:20 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RicPasteIntersectionsFeature::isCommandEnabled()
|
|
|
|
{
|
|
|
|
caf::PdmObjectGroup objectGroup;
|
2019-09-06 03:40:57 -05:00
|
|
|
RicPasteFeatureImpl::findObjectsFromClipboardRefs( &objectGroup );
|
2018-01-24 04:44:20 -06:00
|
|
|
|
|
|
|
std::vector<caf::PdmPointer<RimIntersection>> intersectionObjects;
|
2019-09-06 03:40:57 -05:00
|
|
|
objectGroup.objectsByType( &intersectionObjects );
|
2018-01-24 04:44:20 -06:00
|
|
|
|
|
|
|
std::vector<caf::PdmPointer<RimIntersectionBox>> intersectionBoxObjects;
|
2019-09-06 03:40:57 -05:00
|
|
|
objectGroup.objectsByType( &intersectionBoxObjects );
|
2018-01-24 04:44:20 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( intersectionObjects.empty() && intersectionBoxObjects.empty() )
|
2018-01-24 04:44:20 -06:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::PdmObjectHandle* destinationObject = dynamic_cast<caf::PdmObjectHandle*>(
|
|
|
|
caf::SelectionManager::instance()->selectedItem() );
|
2018-01-24 04:44:20 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( findIntersectionCollection( destinationObject ) )
|
2018-01-24 04:44:20 -06:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicPasteIntersectionsFeature::onActionTriggered( bool isChecked )
|
2018-01-24 04:44:20 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::PdmObjectHandle* destinationObject = dynamic_cast<caf::PdmObjectHandle*>(
|
|
|
|
caf::SelectionManager::instance()->selectedItem() );
|
2018-01-24 04:44:20 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
RimIntersectionCollection* intersectionCollection = RicPasteIntersectionsFeature::findIntersectionCollection(
|
|
|
|
destinationObject );
|
2018-01-24 04:44:20 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_ASSERT( intersectionCollection );
|
2018-01-24 04:44:20 -06:00
|
|
|
|
|
|
|
caf::PdmObjectGroup objectGroup;
|
2019-09-06 03:40:57 -05:00
|
|
|
RicPasteFeatureImpl::findObjectsFromClipboardRefs( &objectGroup );
|
2018-01-24 04:44:20 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( objectGroup.objects.size() == 0 ) return;
|
2018-01-24 04:44:20 -06:00
|
|
|
|
|
|
|
std::vector<caf::PdmPointer<RimIntersection>> intersectionObjects;
|
2019-09-06 03:40:57 -05:00
|
|
|
objectGroup.objectsByType( &intersectionObjects );
|
2018-01-24 04:44:20 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( size_t i = 0; i < intersectionObjects.size(); i++ )
|
2018-01-24 04:44:20 -06:00
|
|
|
{
|
|
|
|
RimIntersection* intersection = dynamic_cast<RimIntersection*>(
|
2019-09-06 03:40:57 -05:00
|
|
|
intersectionObjects[i]->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
2018-01-24 04:44:20 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
QString nameOfCopy = QString( "Copy of " ) + intersection->name;
|
2018-01-24 04:44:20 -06:00
|
|
|
intersection->name = nameOfCopy;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( i == intersectionObjects.size() - 1 )
|
2018-01-24 04:44:20 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
intersectionCollection->appendIntersectionAndUpdate( intersection );
|
2018-01-24 04:44:20 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
intersectionCollection->appendIntersectionNoUpdate( intersection );
|
2018-01-24 04:44:20 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<caf::PdmPointer<RimIntersectionBox>> intersectionBoxObjects;
|
2019-09-06 03:40:57 -05:00
|
|
|
objectGroup.objectsByType( &intersectionBoxObjects );
|
2018-01-24 04:44:20 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( size_t i = 0; i < intersectionBoxObjects.size(); i++ )
|
2018-01-24 04:44:20 -06:00
|
|
|
{
|
|
|
|
RimIntersectionBox* intersectionBox = dynamic_cast<RimIntersectionBox*>(
|
2019-09-06 03:40:57 -05:00
|
|
|
intersectionBoxObjects[i]->xmlCapability()->copyByXmlSerialization(
|
|
|
|
caf::PdmDefaultObjectFactory::instance() ) );
|
2018-01-24 04:44:20 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
QString nameOfCopy = QString( "Copy of " ) + intersectionBox->name;
|
2018-01-24 04:44:20 -06:00
|
|
|
intersectionBox->name = nameOfCopy;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( i == intersectionBoxObjects.size() - 1 )
|
2018-01-24 04:44:20 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
intersectionCollection->appendIntersectionBoxAndUpdate( intersectionBox );
|
2018-01-24 04:44:20 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
intersectionCollection->appendIntersectionBoxNoUpdate( intersectionBox );
|
2018-01-24 04:44:20 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicPasteIntersectionsFeature::setupActionLook( QAction* actionToSetup )
|
2018-01-24 04:44:20 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
actionToSetup->setText( "Paste (Intersections)" );
|
2018-01-24 04:44:20 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
RicPasteFeatureImpl::setIconAndShortcuts( actionToSetup );
|
2018-01-24 04:44:20 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
RimIntersectionCollection* RicPasteIntersectionsFeature::findIntersectionCollection( caf::PdmObjectHandle* objectHandle )
|
2018-01-24 04:44:20 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
RimIntersectionCollection* intersectionCollection = dynamic_cast<RimIntersectionCollection*>( objectHandle );
|
|
|
|
if ( intersectionCollection )
|
2018-01-24 04:44:20 -06:00
|
|
|
{
|
|
|
|
return intersectionCollection;
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
RimIntersection* intersection = dynamic_cast<RimIntersection*>( objectHandle );
|
|
|
|
if ( intersection )
|
2018-01-24 04:44:20 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
intersection->firstAncestorOrThisOfType( intersectionCollection );
|
2018-01-24 04:44:20 -06:00
|
|
|
return intersectionCollection;
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
RimIntersectionBox* intersectionBox = dynamic_cast<RimIntersectionBox*>( objectHandle );
|
|
|
|
if ( intersectionBox )
|
2018-01-24 04:44:20 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
intersectionBox->firstAncestorOrThisOfType( intersectionCollection );
|
2018-01-24 04:44:20 -06:00
|
|
|
return intersectionCollection;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|