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