2016-11-22 02:31:48 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2016 Statoil ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
|
|
|
// 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>
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_CMD_SOURCE_INIT( RicPasteWellLogPlotFeature, "RicPasteWellLogPlotFeature" );
|
2016-11-22 02:31:48 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-11-22 02:31:48 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RicPasteWellLogPlotFeature::isCommandEnabled()
|
|
|
|
{
|
2020-02-12 04:43:15 -06:00
|
|
|
caf::PdmObjectHandle* destinationObject =
|
|
|
|
dynamic_cast<caf::PdmObjectHandle*>( caf::SelectionManager::instance()->selectedItem() );
|
2019-11-27 03:17:31 -06:00
|
|
|
if ( !destinationObject ) return false;
|
2016-11-22 02:31:48 -06:00
|
|
|
|
|
|
|
RimWellLogPlotCollection* wellLogPlotCollection = nullptr;
|
2019-09-06 03:40:57 -05:00
|
|
|
destinationObject->firstAncestorOrThisOfType( wellLogPlotCollection );
|
|
|
|
if ( !wellLogPlotCollection )
|
2016-11-22 02:31:48 -06:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RicPasteWellLogPlotFeature::plots().size() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-11-22 02:31:48 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicPasteWellLogPlotFeature::onActionTriggered( bool isChecked )
|
2016-11-22 02:31:48 -06:00
|
|
|
{
|
2020-02-12 04:43:15 -06:00
|
|
|
caf::PdmObjectHandle* destinationObject =
|
|
|
|
dynamic_cast<caf::PdmObjectHandle*>( caf::SelectionManager::instance()->selectedItem() );
|
2019-11-27 03:17:31 -06:00
|
|
|
if ( !destinationObject ) return;
|
2016-11-22 02:31:48 -06:00
|
|
|
|
|
|
|
RimWellLogPlotCollection* wellLogPlotCollection = nullptr;
|
2019-09-06 03:40:57 -05:00
|
|
|
destinationObject->firstAncestorOrThisOfType( wellLogPlotCollection );
|
|
|
|
if ( !wellLogPlotCollection )
|
2016-11-22 02:31:48 -06:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
std::vector<caf::PdmPointer<RimWellLogPlot>> sourceObjects = RicPasteWellLogPlotFeature::plots();
|
2016-11-22 02:31:48 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( size_t i = 0; i < sourceObjects.size(); i++ )
|
2016-11-22 02:31:48 -06:00
|
|
|
{
|
|
|
|
RimWellLogPlot* fileCurve = sourceObjects[i];
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( fileCurve )
|
2016-11-22 02:31:48 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05: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();
|
|
|
|
|
2020-01-16 05:32:40 -06:00
|
|
|
QString customName = "Copy of " + newObject->nameConfig()->customName();
|
|
|
|
newObject->nameConfig()->setCustomName( customName );
|
2016-11-22 02:31:48 -06:00
|
|
|
|
|
|
|
newObject->loadDataAndUpdate();
|
|
|
|
|
|
|
|
wellLogPlotCollection->updateConnectedEditors();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-11-22 02:31:48 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicPasteWellLogPlotFeature::setupActionLook( QAction* actionToSetup )
|
2016-11-22 02:31:48 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
actionToSetup->setText( "Paste Well Log Plot" );
|
2016-11-24 01:22:36 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
RicPasteFeatureImpl::setIconAndShortcuts( actionToSetup );
|
2016-11-22 02:31:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-11-22 02:31:48 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
std::vector<caf::PdmPointer<RimWellLogPlot>> RicPasteWellLogPlotFeature::plots()
|
2016-11-22 02:31:48 -06:00
|
|
|
{
|
|
|
|
caf::PdmObjectGroup objectGroup;
|
2019-09-06 03:40:57 -05:00
|
|
|
RicPasteFeatureImpl::findObjectsFromClipboardRefs( &objectGroup );
|
2016-11-22 02:31:48 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
std::vector<caf::PdmPointer<RimWellLogPlot>> typedObjects;
|
|
|
|
objectGroup.objectsByType( &typedObjects );
|
2016-11-22 02:31:48 -06:00
|
|
|
|
|
|
|
return typedObjects;
|
|
|
|
}
|