2015-08-14 03:17:18 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2015-08-13 13:22:49 -05:00
|
|
|
//
|
2015-08-14 03:17:18 -05:00
|
|
|
// Copyright (C) 2015- Statoil ASA
|
|
|
|
// Copyright (C) 2015- Ceetron Solutions AS
|
2019-03-12 08:46:51 -05:00
|
|
|
//
|
2015-08-14 03:17:18 -05: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-03-12 08:46:51 -05:00
|
|
|
//
|
2015-08-14 03:17:18 -05: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-03-12 08:46:51 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2015-08-14 03:17:18 -05:00
|
|
|
// for more details.
|
2015-08-13 13:22:49 -05:00
|
|
|
//
|
2015-08-14 03:17:18 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2015-08-13 13:22:49 -05:00
|
|
|
|
|
|
|
#include "RicCopyReferencesToClipboardFeature.h"
|
|
|
|
|
2019-11-26 06:56:02 -06:00
|
|
|
#include "RimBoxIntersection.h"
|
2023-12-07 06:20:34 -06:00
|
|
|
#include "RimCellFilter.h"
|
2017-02-06 06:33:56 -06:00
|
|
|
#include "RimEclipseCase.h"
|
|
|
|
#include "RimEclipseView.h"
|
2018-05-08 03:17:05 -05:00
|
|
|
#include "RimEnsembleCurveSet.h"
|
2019-11-26 06:56:02 -06:00
|
|
|
#include "RimExtrudedCurveIntersection.h"
|
2018-02-20 00:20:25 -06:00
|
|
|
#include "RimFractureTemplate.h"
|
2017-02-06 06:33:56 -06:00
|
|
|
#include "RimGeoMechView.h"
|
2019-04-12 06:25:25 -05:00
|
|
|
#include "RimGridCrossPlotCurve.h"
|
2019-03-29 07:17:39 -05:00
|
|
|
#include "RimGridCrossPlotDataSet.h"
|
2015-08-13 13:22:49 -05:00
|
|
|
#include "RimMimeData.h"
|
2021-06-24 06:17:43 -05:00
|
|
|
#include "RimModeledWellPath.h"
|
2022-05-23 07:25:53 -05:00
|
|
|
#include "RimSummaryMultiPlot.h"
|
2017-02-06 06:33:56 -06:00
|
|
|
#include "RimSummaryPlot.h"
|
|
|
|
#include "RimWellAllocationPlot.h"
|
|
|
|
#include "RimWellLogPlot.h"
|
|
|
|
#include "RimWellLogTrack.h"
|
2017-10-10 04:18:35 -05:00
|
|
|
#include "RimWellRftPlot.h"
|
2015-08-14 03:17:18 -05:00
|
|
|
|
2017-02-06 06:33:56 -06:00
|
|
|
#include "cafPdmObject.h"
|
2015-08-13 13:22:49 -05:00
|
|
|
#include "cafPdmUiItem.h"
|
|
|
|
#include "cafSelectionManager.h"
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QClipboard>
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_CMD_SOURCE_INIT( RicCopyReferencesToClipboardFeature, "RicCopyReferencesToClipboardFeature" );
|
2015-08-13 13:22:49 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-03-12 08:46:51 -05:00
|
|
|
///
|
2015-08-13 13:22:49 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-06-26 07:28:46 -05:00
|
|
|
bool RicCopyReferencesToClipboardFeature::isCommandEnabled() const
|
2015-08-13 13:22:49 -05:00
|
|
|
{
|
2017-02-06 06:33:56 -06:00
|
|
|
return isAnyCopyableObjectSelected();
|
2015-08-13 13:22:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-03-12 08:46:51 -05:00
|
|
|
///
|
2015-08-13 13:22:49 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicCopyReferencesToClipboardFeature::onActionTriggered( bool isChecked )
|
2015-08-13 13:22:49 -05:00
|
|
|
{
|
2023-08-04 02:04:14 -05:00
|
|
|
disableModelChangeContribution();
|
2017-04-20 03:38:58 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !isAnyCopyableObjectSelected() ) return;
|
2017-02-06 06:33:56 -06:00
|
|
|
|
2015-08-13 13:22:49 -05:00
|
|
|
std::vector<QString> referenceList;
|
2017-02-06 06:33:56 -06:00
|
|
|
|
2017-05-19 06:40:38 -05:00
|
|
|
std::vector<caf::PdmObject*> selectedFormationNamesCollObjs;
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::SelectionManager::instance()->objectsByType( &selectedFormationNamesCollObjs );
|
2017-02-06 06:33:56 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( caf::PdmObject* pdmObject : selectedFormationNamesCollObjs )
|
2017-02-06 06:33:56 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( RicCopyReferencesToClipboardFeature::isCopyOfObjectSupported( pdmObject ) )
|
2017-02-06 06:33:56 -06:00
|
|
|
{
|
2019-11-04 08:08:09 -06:00
|
|
|
QString itemRef =
|
2023-02-26 03:48:40 -06:00
|
|
|
caf::PdmReferenceHelper::referenceFromRootToObject( caf::SelectionManager::instance()->pdmRootObject(), pdmObject );
|
2019-03-12 08:46:51 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
referenceList.push_back( itemRef );
|
2017-02-06 06:33:56 -06:00
|
|
|
}
|
|
|
|
}
|
2015-08-13 13:22:49 -05:00
|
|
|
|
|
|
|
MimeDataWithReferences* myObject = new MimeDataWithReferences;
|
2019-09-06 03:40:57 -05:00
|
|
|
myObject->setReferences( referenceList );
|
2015-08-13 13:22:49 -05:00
|
|
|
|
|
|
|
QClipboard* clipboard = QApplication::clipboard();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( clipboard )
|
2015-08-13 13:22:49 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
clipboard->setMimeData( myObject );
|
2015-08-13 13:22:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-03-12 08:46:51 -05:00
|
|
|
///
|
2015-08-13 13:22:49 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicCopyReferencesToClipboardFeature::setupActionLook( QAction* actionToSetup )
|
2015-08-13 13:22:49 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
actionToSetup->setText( "Copy" );
|
2020-10-06 10:12:58 -05:00
|
|
|
actionToSetup->setIcon( QIcon( ":/Copy.svg" ) );
|
2019-09-06 03:40:57 -05:00
|
|
|
applyShortcutWithHintToAction( actionToSetup, QKeySequence::Copy );
|
2015-08-13 13:22:49 -05:00
|
|
|
}
|
|
|
|
|
2017-02-06 06:33:56 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-03-12 08:46:51 -05:00
|
|
|
///
|
2017-02-06 06:33:56 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RicCopyReferencesToClipboardFeature::isAnyCopyableObjectSelected()
|
|
|
|
{
|
2017-05-19 06:40:38 -05:00
|
|
|
std::vector<caf::PdmObject*> selectedFormationNamesCollObjs;
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::SelectionManager::instance()->objectsByType( &selectedFormationNamesCollObjs );
|
2017-02-06 06:33:56 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( caf::PdmObject* pdmObject : selectedFormationNamesCollObjs )
|
2017-02-06 06:33:56 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( RicCopyReferencesToClipboardFeature::isCopyOfObjectSupported( pdmObject ) )
|
2017-02-06 06:33:56 -06:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-03-12 08:46:51 -05:00
|
|
|
///
|
2017-02-06 06:33:56 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
bool RicCopyReferencesToClipboardFeature::isCopyOfObjectSupported( caf::PdmObject* pdmObject )
|
2017-02-06 06:33:56 -06:00
|
|
|
{
|
2022-05-23 07:25:53 -05:00
|
|
|
// Copy support based on direct dynamic cast
|
|
|
|
if ( dynamic_cast<RimGeoMechView*>( pdmObject ) ) return true;
|
|
|
|
if ( dynamic_cast<RimEclipseView*>( pdmObject ) ) return true;
|
|
|
|
if ( dynamic_cast<RimEclipseCase*>( pdmObject ) ) return true;
|
|
|
|
if ( dynamic_cast<RimExtrudedCurveIntersection*>( pdmObject ) ) return true;
|
|
|
|
if ( dynamic_cast<RimBoxIntersection*>( pdmObject ) ) return true;
|
|
|
|
if ( dynamic_cast<RimSummaryPlot*>( pdmObject ) ) return true;
|
|
|
|
if ( dynamic_cast<RimFractureTemplate*>( pdmObject ) ) return true;
|
|
|
|
if ( dynamic_cast<RimEnsembleCurveSet*>( pdmObject ) ) return true;
|
|
|
|
if ( dynamic_cast<RimGridCrossPlotDataSet*>( pdmObject ) ) return true;
|
|
|
|
if ( dynamic_cast<RimModeledWellPath*>( pdmObject ) ) return true;
|
|
|
|
if ( dynamic_cast<RimSummaryMultiPlot*>( pdmObject ) ) return true;
|
2023-12-07 06:20:34 -06:00
|
|
|
if ( dynamic_cast<RimCellFilter*>( pdmObject ) ) return true;
|
2022-05-23 07:25:53 -05:00
|
|
|
|
|
|
|
// Copy support based combined logic
|
2023-05-12 14:41:34 -05:00
|
|
|
RimWellAllocationPlot* wellAllocPlot = pdmObject->firstAncestorOrThisOfType<RimWellAllocationPlot>();
|
|
|
|
RimWellRftPlot* rftPlot = pdmObject->firstAncestorOrThisOfType<RimWellRftPlot>();
|
2017-02-06 06:33:56 -06:00
|
|
|
|
2022-05-23 07:25:53 -05:00
|
|
|
if ( dynamic_cast<RimPlotCurve*>( pdmObject ) && !dynamic_cast<RimGridCrossPlotCurve*>( pdmObject ) )
|
2017-02-06 06:33:56 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !rftPlot ) return true;
|
2017-02-06 06:33:56 -06:00
|
|
|
}
|
2022-05-23 07:25:53 -05:00
|
|
|
if ( dynamic_cast<RimWellLogTrack*>( pdmObject ) )
|
2017-02-06 06:33:56 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !wellAllocPlot && !rftPlot ) return true;
|
2017-02-06 06:33:56 -06:00
|
|
|
}
|
2022-05-23 07:25:53 -05:00
|
|
|
if ( dynamic_cast<RimWellLogPlot*>( pdmObject ) )
|
2017-02-06 06:33:56 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !wellAllocPlot && !rftPlot ) return true;
|
2017-02-06 06:33:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|