ResInsight/ApplicationLibCode/Commands/WellLogCommands/RicPasteWellLogTrackFeature.cpp

118 lines
4.2 KiB
C++
Raw Normal View History

2016-11-22 02:11:25 -06:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016 Statoil ASA
//
2016-11-22 02:11:25 -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:11:25 -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:11:25 -06:00
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicPasteWellLogTrackFeature.h"
#include "OperationsUsingObjReferences/RicPasteFeatureImpl.h"
#include "RicWellLogPlotCurveFeatureImpl.h"
2016-11-22 02:11:25 -06:00
#include "RimWellLogPlot.h"
#include "RimWellLogTrack.h"
#include "RimWellRftPlot.h"
2016-11-22 02:11:25 -06:00
#include "cafPdmObjectGroup.h"
#include "cafPdmObjectHandle.h"
#include "cafSelectionManager.h"
#include "cafSelectionManagerTools.h"
2016-11-22 02:11:25 -06:00
#include "cvfAssert.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicPasteWellLogTrackFeature, "RicPasteWellLogTrackFeature" );
2016-11-22 02:11:25 -06:00
//--------------------------------------------------------------------------------------------------
///
2016-11-22 02:11:25 -06:00
//--------------------------------------------------------------------------------------------------
bool RicPasteWellLogTrackFeature::isCommandEnabled()
{
if ( RicWellLogPlotCurveFeatureImpl::parentWellAllocationPlot() ) return false;
RimWellLogPlot* wellLogPlot = caf::firstAncestorOfTypeFromSelectedObject<RimWellLogPlot>();
RimWellRftPlot* rftPlot = caf::firstAncestorOfTypeFromSelectedObject<RimWellRftPlot>();
if ( !wellLogPlot || rftPlot )
2016-11-22 02:11:25 -06:00
{
return false;
}
return RicPasteWellLogTrackFeature::tracks().size() > 0;
}
//--------------------------------------------------------------------------------------------------
///
2016-11-22 02:11:25 -06:00
//--------------------------------------------------------------------------------------------------
void RicPasteWellLogTrackFeature::onActionTriggered( bool isChecked )
2016-11-22 02:11:25 -06:00
{
if ( RicWellLogPlotCurveFeatureImpl::parentWellAllocationPlot() ) return;
RimWellLogPlot* wellLogPlot = caf::SelectionManager::instance()->selectedItemAncestorOfType<RimWellLogPlot>();
if ( !wellLogPlot )
2016-11-22 02:11:25 -06:00
{
return;
}
std::vector<caf::PdmPointer<RimWellLogTrack>> sourceObjects = RicPasteWellLogTrackFeature::tracks();
2016-11-22 02:11:25 -06:00
for ( size_t i = 0; i < sourceObjects.size(); i++ )
2016-11-22 02:11:25 -06:00
{
RimWellLogTrack* fileCurve = sourceObjects[i];
if ( fileCurve )
2016-11-22 02:11:25 -06:00
{
RimWellLogTrack* newObject = dynamic_cast<RimWellLogTrack*>(
fileCurve->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
CVF_ASSERT( newObject );
2016-11-22 02:11:25 -06:00
wellLogPlot->addPlot( newObject );
2016-11-22 02:11:25 -06:00
newObject->setDescription( QString( "Track %1" ).arg( wellLogPlot->plotCount() ) );
2016-11-22 02:11:25 -06:00
// Resolve references after object has been inserted into the project data model
newObject->resolveReferencesRecursively();
newObject->initAfterReadRecursively();
newObject->loadDataAndUpdate();
wellLogPlot->updateConnectedEditors();
}
}
}
//--------------------------------------------------------------------------------------------------
///
2016-11-22 02:11:25 -06:00
//--------------------------------------------------------------------------------------------------
void RicPasteWellLogTrackFeature::setupActionLook( QAction* actionToSetup )
2016-11-22 02:11:25 -06:00
{
actionToSetup->setText( "Paste Well Log Track" );
RicPasteFeatureImpl::setIconAndShortcuts( actionToSetup );
2016-11-22 02:11:25 -06:00
}
//--------------------------------------------------------------------------------------------------
///
2016-11-22 02:11:25 -06:00
//--------------------------------------------------------------------------------------------------
std::vector<caf::PdmPointer<RimWellLogTrack>> RicPasteWellLogTrackFeature::tracks()
2016-11-22 02:11:25 -06:00
{
caf::PdmObjectGroup objectGroup;
RicPasteFeatureImpl::findObjectsFromClipboardRefs( &objectGroup );
2016-11-22 02:11:25 -06:00
std::vector<caf::PdmPointer<RimWellLogTrack>> typedObjects;
objectGroup.objectsByType( &typedObjects );
2016-11-22 02:11:25 -06:00
return typedObjects;
}