ResInsight/ApplicationLibCode/Commands/OperationsUsingObjReferences/RicPasteIntersectionsFeature.cpp

161 lines
5.9 KiB
C++
Raw Normal View History

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