ResInsight/ApplicationLibCode/Commands/WellLogCommands/RicPasteWellLogCurveFeature.cpp

148 lines
5.8 KiB
C++
Raw Normal View History

2016-11-22 01:48:11 -06:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016 Statoil ASA
//
2016-11-22 01:48:11 -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 01:48:11 -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 01:48:11 -06:00
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicPasteWellLogCurveFeature.h"
#include "RicWellLogPlotCurveFeatureImpl.h"
2016-11-22 01:48:11 -06:00
#include "OperationsUsingObjReferences/RicPasteFeatureImpl.h"
#include "RimWellBoreStabilityPlot.h"
2016-11-22 01:48:11 -06:00
#include "RimWellLogCurve.h"
#include "RimWellLogExtractionCurve.h"
#include "RimWellLogFileCurve.h"
#include "RimWellLogRftCurve.h"
2016-11-22 01:48:11 -06:00
#include "RimWellLogTrack.h"
#include "RimWellMeasurementCurve.h"
2016-11-22 01:48:11 -06:00
#include "cafPdmObjectGroup.h"
#include "cafPdmObjectHandle.h"
#include "cafSelectionManager.h"
#include "cvfAssert.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicPasteWellLogCurveFeature, "RicPasteWellLogCurveFeature" );
2016-11-22 01:48:11 -06:00
//--------------------------------------------------------------------------------------------------
///
2016-11-22 01:48:11 -06:00
//--------------------------------------------------------------------------------------------------
bool RicPasteWellLogCurveFeature::isCommandEnabled()
{
if ( RicWellLogPlotCurveFeatureImpl::parentWellAllocationPlot() ) return false;
if ( RicWellLogPlotCurveFeatureImpl::parentWellRftPlot() ) return false;
auto* destinationObject = dynamic_cast<caf::PdmObjectHandle*>( caf::SelectionManager::instance()->selectedItem() );
if ( !destinationObject ) return false;
2016-11-22 01:48:11 -06:00
RimWellLogTrack* wellLogTrack = destinationObject->firstAncestorOrThisOfType<RimWellLogTrack>();
if ( !wellLogTrack )
2016-11-22 01:48:11 -06:00
{
return false;
}
RimWellBoreStabilityPlot* wbsPlotToPasteInto = wellLogTrack->firstAncestorOrThisOfType<RimWellBoreStabilityPlot>();
std::vector<caf::PdmPointer<RimWellLogCurve>> sourceObjects = RicPasteWellLogCurveFeature::curves();
for ( const auto& sourceObject : sourceObjects )
{
RimWellBoreStabilityPlot* originalWbsPlot = sourceObject->firstAncestorOrThisOfType<RimWellBoreStabilityPlot>();
if ( originalWbsPlot && originalWbsPlot != wbsPlotToPasteInto )
{
return false;
}
}
return !RicPasteWellLogCurveFeature::curves().empty();
2016-11-22 01:48:11 -06:00
}
//--------------------------------------------------------------------------------------------------
///
2016-11-22 01:48:11 -06:00
//--------------------------------------------------------------------------------------------------
void RicPasteWellLogCurveFeature::onActionTriggered( bool isChecked )
2016-11-22 01:48:11 -06:00
{
if ( RicWellLogPlotCurveFeatureImpl::parentWellAllocationPlot() ) return;
auto* destinationObject = dynamic_cast<caf::PdmObjectHandle*>( caf::SelectionManager::instance()->selectedItem() );
if ( !destinationObject ) return;
2016-11-22 01:48:11 -06:00
RimWellLogTrack* wellLogTrack = destinationObject->firstAncestorOrThisOfType<RimWellLogTrack>();
if ( !wellLogTrack )
2016-11-22 01:48:11 -06:00
{
return;
}
RimWellBoreStabilityPlot* wbsPlotToPasteInto = wellLogTrack->firstAncestorOrThisOfType<RimWellBoreStabilityPlot>();
std::vector<caf::PdmPointer<RimWellLogCurve>> sourceObjects = RicPasteWellLogCurveFeature::curves();
2016-11-22 01:48:11 -06:00
for ( const auto& sourceObject : sourceObjects )
2016-11-22 01:48:11 -06:00
{
RimWellBoreStabilityPlot* originalWbsPlot = sourceObject->firstAncestorOrThisOfType<RimWellBoreStabilityPlot>();
if ( originalWbsPlot && originalWbsPlot != wbsPlotToPasteInto )
{
continue;
}
auto* fileCurve = dynamic_cast<RimWellLogCurve*>( sourceObject.p() );
auto* measurementCurve = dynamic_cast<RimWellMeasurementCurve*>( sourceObject.p() );
auto* extractionCurve = dynamic_cast<RimWellLogExtractionCurve*>( sourceObject.p() );
auto* rftCurve = dynamic_cast<RimWellLogRftCurve*>( sourceObject.p() );
if ( fileCurve || measurementCurve || extractionCurve || rftCurve )
2016-11-22 01:48:11 -06:00
{
auto* newObject = dynamic_cast<RimWellLogCurve*>(
sourceObject->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
CVF_ASSERT( newObject );
2016-11-22 01:48:11 -06:00
wellLogTrack->addCurve( newObject );
2016-11-22 01:48:11 -06:00
// Resolve references after object has been inserted into the project data model
newObject->resolveReferencesRecursively();
newObject->initAfterReadRecursively();
newObject->loadDataAndUpdate( true );
2016-11-22 01:48:11 -06:00
wellLogTrack->updateConnectedEditors();
}
}
}
//--------------------------------------------------------------------------------------------------
///
2016-11-22 01:48:11 -06:00
//--------------------------------------------------------------------------------------------------
void RicPasteWellLogCurveFeature::setupActionLook( QAction* actionToSetup )
2016-11-22 01:48:11 -06:00
{
actionToSetup->setText( "Paste Well Log Curve" );
RicPasteFeatureImpl::setIconAndShortcuts( actionToSetup );
2016-11-22 01:48:11 -06:00
}
//--------------------------------------------------------------------------------------------------
///
2016-11-22 01:48:11 -06:00
//--------------------------------------------------------------------------------------------------
std::vector<caf::PdmPointer<RimWellLogCurve>> RicPasteWellLogCurveFeature::curves()
2016-11-22 01:48:11 -06:00
{
caf::PdmObjectGroup objectGroup;
RicPasteFeatureImpl::findObjectsFromClipboardRefs( &objectGroup );
2016-11-22 01:48:11 -06:00
std::vector<caf::PdmPointer<RimWellLogCurve>> typedObjects;
objectGroup.objectsByType( &typedObjects );
2016-11-22 01:48:11 -06:00
return typedObjects;
}