ResInsight/ApplicationLibCode/Commands/WellLogCommands/RicPasteWellLogPlotFeature.cpp

121 lines
4.4 KiB
C++
Raw Normal View History

2016-11-22 02:31:48 -06:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016 Statoil ASA
//
2016-11-22 02:31:48 -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.
//
2016-11-22 02:31:48 -06:00
// 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>
2016-11-22 02:31:48 -06:00
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicPasteWellLogPlotFeature.h"
#include "OperationsUsingObjReferences/RicPasteFeatureImpl.h"
#include "RimWellLogPlot.h"
#include "RimWellLogPlotCollection.h"
#include "cafPdmObjectGroup.h"
#include "cafPdmObjectHandle.h"
#include "cafSelectionManager.h"
#include "cvfAssert.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicPasteWellLogPlotFeature, "RicPasteWellLogPlotFeature" );
2016-11-22 02:31:48 -06:00
//--------------------------------------------------------------------------------------------------
///
2016-11-22 02:31:48 -06:00
//--------------------------------------------------------------------------------------------------
bool RicPasteWellLogPlotFeature::isCommandEnabled()
{
caf::PdmObjectHandle* destinationObject =
dynamic_cast<caf::PdmObjectHandle*>( caf::SelectionManager::instance()->selectedItem() );
if ( !destinationObject ) return false;
2016-11-22 02:31:48 -06:00
RimWellLogPlotCollection* wellLogPlotCollection = nullptr;
destinationObject->firstAncestorOrThisOfType( wellLogPlotCollection );
if ( !wellLogPlotCollection )
2016-11-22 02:31:48 -06:00
{
return false;
}
return RicPasteWellLogPlotFeature::plots().size() > 0;
}
//--------------------------------------------------------------------------------------------------
///
2016-11-22 02:31:48 -06:00
//--------------------------------------------------------------------------------------------------
void RicPasteWellLogPlotFeature::onActionTriggered( bool isChecked )
2016-11-22 02:31:48 -06:00
{
caf::PdmObjectHandle* destinationObject =
dynamic_cast<caf::PdmObjectHandle*>( caf::SelectionManager::instance()->selectedItem() );
if ( !destinationObject ) return;
2016-11-22 02:31:48 -06:00
RimWellLogPlotCollection* wellLogPlotCollection = nullptr;
destinationObject->firstAncestorOrThisOfType( wellLogPlotCollection );
if ( !wellLogPlotCollection )
2016-11-22 02:31:48 -06:00
{
return;
}
std::vector<caf::PdmPointer<RimWellLogPlot>> sourceObjects = RicPasteWellLogPlotFeature::plots();
2016-11-22 02:31:48 -06:00
for ( size_t i = 0; i < sourceObjects.size(); i++ )
2016-11-22 02:31:48 -06:00
{
RimWellLogPlot* fileCurve = sourceObjects[i];
if ( fileCurve )
2016-11-22 02:31:48 -06:00
{
RimWellLogPlot* newObject = dynamic_cast<RimWellLogPlot*>(
fileCurve->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
CVF_ASSERT( newObject );
2016-11-22 02:31:48 -06:00
2020-10-06 05:37:16 -05:00
wellLogPlotCollection->addWellLogPlot( newObject );
2016-11-22 02:31:48 -06:00
// Resolve references after object has been inserted into the project data model
newObject->resolveReferencesRecursively();
newObject->initAfterReadRecursively();
QString customName = "Copy of " + newObject->nameConfig()->customName();
newObject->nameConfig()->setCustomName( customName );
2016-11-22 02:31:48 -06:00
newObject->loadDataAndUpdate();
wellLogPlotCollection->updateConnectedEditors();
}
}
}
//--------------------------------------------------------------------------------------------------
///
2016-11-22 02:31:48 -06:00
//--------------------------------------------------------------------------------------------------
void RicPasteWellLogPlotFeature::setupActionLook( QAction* actionToSetup )
2016-11-22 02:31:48 -06:00
{
actionToSetup->setText( "Paste Well Log Plot" );
RicPasteFeatureImpl::setIconAndShortcuts( actionToSetup );
2016-11-22 02:31:48 -06:00
}
//--------------------------------------------------------------------------------------------------
///
2016-11-22 02:31:48 -06:00
//--------------------------------------------------------------------------------------------------
std::vector<caf::PdmPointer<RimWellLogPlot>> RicPasteWellLogPlotFeature::plots()
2016-11-22 02:31:48 -06:00
{
caf::PdmObjectGroup objectGroup;
RicPasteFeatureImpl::findObjectsFromClipboardRefs( &objectGroup );
2016-11-22 02:31:48 -06:00
std::vector<caf::PdmPointer<RimWellLogPlot>> typedObjects;
objectGroup.objectsByType( &typedObjects );
2016-11-22 02:31:48 -06:00
return typedObjects;
}