2017-12-12 06:22:16 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2016- Statoil ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-12-12 06:22:16 -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
|
|
|
//
|
2017-12-12 06:22:16 -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>
|
2017-12-12 06:22:16 -06:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RicPasteSummaryCrossPlotFeature.h"
|
|
|
|
|
|
|
|
#include "OperationsUsingObjReferences/RicPasteFeatureImpl.h"
|
|
|
|
|
|
|
|
#include "RimSummaryCrossPlot.h"
|
|
|
|
#include "RimSummaryCrossPlotCollection.h"
|
|
|
|
|
|
|
|
#include "cafPdmDefaultObjectFactory.h"
|
|
|
|
#include "cafPdmDocument.h"
|
|
|
|
#include "cafPdmObjectGroup.h"
|
|
|
|
#include "cafSelectionManagerTools.h"
|
|
|
|
|
|
|
|
#include "cvfAssert.h"
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_CMD_SOURCE_INIT( RicPasteSummaryCrossPlotFeature, "RicPasteSummaryCrossPlotFeature" );
|
2017-12-12 06:22:16 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-12-12 06:22:16 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicPasteSummaryCrossPlotFeature::copyPlotAndAddToCollection( RimSummaryCrossPlot* sourcePlot )
|
2017-12-12 06:22:16 -06:00
|
|
|
{
|
2023-05-12 14:41:34 -05:00
|
|
|
RimSummaryCrossPlotCollection* plotColl = caf::firstAncestorOfTypeFromSelectedObject<RimSummaryCrossPlotCollection>();
|
2017-12-12 06:22:16 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( plotColl )
|
2017-12-12 06:22:16 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
RimSummaryCrossPlot* newSummaryPlot = dynamic_cast<RimSummaryCrossPlot*>(
|
|
|
|
sourcePlot->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
|
|
|
CVF_ASSERT( newSummaryPlot );
|
2017-12-12 06:22:16 -06:00
|
|
|
|
2020-09-16 12:33:44 -05:00
|
|
|
plotColl->addPlot( newSummaryPlot );
|
2017-12-12 06:22:16 -06:00
|
|
|
|
|
|
|
// Resolve references after object has been inserted into the data model
|
|
|
|
newSummaryPlot->resolveReferencesRecursively();
|
|
|
|
newSummaryPlot->initAfterReadRecursively();
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
QString nameOfCopy = QString( "Copy of " ) + newSummaryPlot->description();
|
|
|
|
newSummaryPlot->setDescription( nameOfCopy );
|
2017-12-12 06:22:16 -06:00
|
|
|
|
|
|
|
plotColl->updateConnectedEditors();
|
|
|
|
|
|
|
|
newSummaryPlot->loadDataAndUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-12-12 06:22:16 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-06-26 07:28:46 -05:00
|
|
|
bool RicPasteSummaryCrossPlotFeature::isCommandEnabled() const
|
2017-12-12 06:22:16 -06:00
|
|
|
{
|
2023-02-26 03:48:40 -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;
|
2017-12-12 06:22:16 -06:00
|
|
|
|
2023-05-12 14:41:34 -05:00
|
|
|
RimSummaryCrossPlotCollection* plotColl = destinationObject->firstAncestorOrThisOfType<RimSummaryCrossPlotCollection>();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !plotColl )
|
2017-12-12 06:22:16 -06:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RicPasteSummaryCrossPlotFeature::summaryPlots().size() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-12-12 06:22:16 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicPasteSummaryCrossPlotFeature::onActionTriggered( bool isChecked )
|
2017-12-12 06:22:16 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
std::vector<caf::PdmPointer<RimSummaryCrossPlot>> sourceObjects = RicPasteSummaryCrossPlotFeature::summaryPlots();
|
2017-12-12 06:22:16 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( size_t i = 0; i < sourceObjects.size(); i++ )
|
2017-12-12 06:22:16 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
copyPlotAndAddToCollection( sourceObjects[i] );
|
2017-12-12 06:22:16 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-12-12 06:22:16 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicPasteSummaryCrossPlotFeature::setupActionLook( QAction* actionToSetup )
|
2017-12-12 06:22:16 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
actionToSetup->setText( "Paste Summary Cross Plot" );
|
2017-12-12 06:22:16 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
RicPasteFeatureImpl::setIconAndShortcuts( actionToSetup );
|
2017-12-12 06:22:16 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-12-12 06:22:16 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
std::vector<caf::PdmPointer<RimSummaryCrossPlot>> RicPasteSummaryCrossPlotFeature::summaryPlots()
|
2017-12-12 06:22:16 -06:00
|
|
|
{
|
|
|
|
caf::PdmObjectGroup objectGroup;
|
2019-09-06 03:40:57 -05:00
|
|
|
RicPasteFeatureImpl::findObjectsFromClipboardRefs( &objectGroup );
|
2017-12-12 06:22:16 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
std::vector<caf::PdmPointer<RimSummaryCrossPlot>> typedObjects;
|
|
|
|
objectGroup.objectsByType( &typedObjects );
|
2017-12-12 06:22:16 -06:00
|
|
|
|
|
|
|
return typedObjects;
|
|
|
|
}
|