From 402c629646af7f6ecccdda1be5bf83a2005bef72 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 22 Nov 2016 08:48:11 +0100 Subject: [PATCH] #901 WLP: Added copy/paste of curves --- .../WellLogCommands/CMakeLists_files.cmake | 2 + .../RicPasteWellLogCurveFeature.cpp | 131 ++++++++++++++++++ .../RicPasteWellLogCurveFeature.h | 43 ++++++ .../RimContextCommandBuilder.cpp | 12 +- 4 files changed, 185 insertions(+), 3 deletions(-) create mode 100644 ApplicationCode/Commands/WellLogCommands/RicPasteWellLogCurveFeature.cpp create mode 100644 ApplicationCode/Commands/WellLogCommands/RicPasteWellLogCurveFeature.h diff --git a/ApplicationCode/Commands/WellLogCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/WellLogCommands/CMakeLists_files.cmake index 0e351d6668..128ff0eb31 100644 --- a/ApplicationCode/Commands/WellLogCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/WellLogCommands/CMakeLists_files.cmake @@ -15,6 +15,7 @@ ${CEE_CURRENT_LIST_DIR}RicWellLogPlotCurveFeatureImpl.h ${CEE_CURRENT_LIST_DIR}RicWellLogsImportFileFeature.h ${CEE_CURRENT_LIST_DIR}RicDeleteWellLogPlotTrackFeature.h ${CEE_CURRENT_LIST_DIR}RicWellLogPlotTrackFeatureImpl.h +${CEE_CURRENT_LIST_DIR}RicPasteWellLogCurveFeature.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -28,6 +29,7 @@ ${CEE_CURRENT_LIST_DIR}RicWellLogPlotCurveFeatureImpl.cpp ${CEE_CURRENT_LIST_DIR}RicWellLogsImportFileFeature.cpp ${CEE_CURRENT_LIST_DIR}RicDeleteWellLogPlotTrackFeature.cpp ${CEE_CURRENT_LIST_DIR}RicWellLogPlotTrackFeatureImpl.cpp +${CEE_CURRENT_LIST_DIR}RicPasteWellLogCurveFeature.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/Commands/WellLogCommands/RicPasteWellLogCurveFeature.cpp b/ApplicationCode/Commands/WellLogCommands/RicPasteWellLogCurveFeature.cpp new file mode 100644 index 0000000000..1f7e5c46f4 --- /dev/null +++ b/ApplicationCode/Commands/WellLogCommands/RicPasteWellLogCurveFeature.cpp @@ -0,0 +1,131 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2016 Statoil ASA +// +// 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. +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicPasteWellLogCurveFeature.h" + +#include "OperationsUsingObjReferences/RicPasteFeatureImpl.h" + +#include "RimWellLogCurve.h" +#include "RimWellLogExtractionCurve.h" +#include "RimWellLogFileCurve.h" +#include "RimWellLogTrack.h" + +#include "cafPdmObjectGroup.h" +#include "cafPdmObjectHandle.h" +#include "cafSelectionManager.h" + +#include "cvfAssert.h" + +#include + + +CAF_CMD_SOURCE_INIT(RicPasteWellLogCurveFeature, "RicPasteWellLogCurveFeature"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicPasteWellLogCurveFeature::isCommandEnabled() +{ + caf::PdmObjectHandle* destinationObject = dynamic_cast(caf::SelectionManager::instance()->selectedItem()); + + RimWellLogTrack* wellLogTrack = nullptr; + destinationObject->firstAncestorOrThisOfType(wellLogTrack); + if (!wellLogTrack) + { + return false; + } + + return RicPasteWellLogCurveFeature::curves().size() > 0; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPasteWellLogCurveFeature::onActionTriggered(bool isChecked) +{ + caf::PdmObjectHandle* destinationObject = dynamic_cast(caf::SelectionManager::instance()->selectedItem()); + + RimWellLogTrack* wellLogTrack = nullptr; + destinationObject->firstAncestorOrThisOfType(wellLogTrack); + if (!wellLogTrack) + { + return; + } + + std::vector > sourceObjects = RicPasteWellLogCurveFeature::curves(); + + for (size_t i = 0; i < sourceObjects.size(); i++) + { + RimWellLogFileCurve* fileCurve = dynamic_cast(sourceObjects[i].p()); + if (fileCurve) + { + RimWellLogFileCurve* newObject = dynamic_cast(sourceObjects[i]->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance())); + CVF_ASSERT(newObject); + + wellLogTrack->addCurve(newObject); + + // Resolve references after object has been inserted into the project data model + newObject->resolveReferencesRecursively(); + newObject->initAfterReadRecursively(); + + newObject->loadDataAndUpdate(); + + wellLogTrack->updateConnectedEditors(); + } + + RimWellLogExtractionCurve* extractionCurve = dynamic_cast(sourceObjects[i].p()); + if (extractionCurve) + { + RimWellLogExtractionCurve* newObject = dynamic_cast(sourceObjects[i]->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance())); + CVF_ASSERT(newObject); + + wellLogTrack->addCurve(newObject); + + // Resolve references after object has been inserted into the project data model + newObject->resolveReferencesRecursively(); + newObject->initAfterReadRecursively(); + + newObject->loadDataAndUpdate(); + + wellLogTrack->updateConnectedEditors(); + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPasteWellLogCurveFeature::setupActionLook(QAction* actionToSetup) +{ + actionToSetup->setText("Paste Well Log Curve"); + actionToSetup->setIcon(QIcon(":/clipboard.png")); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector > RicPasteWellLogCurveFeature::curves() +{ + caf::PdmObjectGroup objectGroup; + RicPasteFeatureImpl::findObjectsFromClipboardRefs(&objectGroup); + + std::vector > typedObjects; + objectGroup.objectsByType(&typedObjects); + + return typedObjects; +} diff --git a/ApplicationCode/Commands/WellLogCommands/RicPasteWellLogCurveFeature.h b/ApplicationCode/Commands/WellLogCommands/RicPasteWellLogCurveFeature.h new file mode 100644 index 0000000000..f25950cdd6 --- /dev/null +++ b/ApplicationCode/Commands/WellLogCommands/RicPasteWellLogCurveFeature.h @@ -0,0 +1,43 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2016 Statoil ASA +// +// 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. +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafCmdFeature.h" +#include "cafPdmPointer.h" + +#include + +class RimWellLogCurve; + +//================================================================================================== +/// +//================================================================================================== +class RicPasteWellLogCurveFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + // Overrides + virtual bool isCommandEnabled() override; + virtual void onActionTriggered( bool isChecked ) override; + virtual void setupActionLook( QAction* actionToSetup ) override; + +private: + static std::vector > curves(); +}; diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index 15d9a81d66..99962cdac8 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -255,6 +255,8 @@ QStringList RimContextCommandBuilder::commandsFromSelection() } else if (dynamic_cast(uiItem)) { + commandIds << "RicPasteWellLogCurveFeature"; + commandIds << "Separator"; commandIds << "RicNewWellLogCurveExtractionFeature"; commandIds << "RicNewWellLogFileCurveFeature"; commandIds << "Separator"; @@ -262,7 +264,7 @@ QStringList RimContextCommandBuilder::commandsFromSelection() } else if (dynamic_cast(uiItem)) { - //commandIds << "RicDeleteItemFeature"; + commandIds << "RicPasteWellLogCurveFeature"; } else if (dynamic_cast(uiItem)) { @@ -376,8 +378,12 @@ QStringList RimContextCommandBuilder::commandsFromSelection() } else if (dynamic_cast(uiItem) || dynamic_cast(uiItem) || - dynamic_cast(uiItem) || - dynamic_cast(uiItem)) + dynamic_cast(uiItem)) + { + commandIds << "RicCopyReferencesToClipboardFeature"; + commandIds << "RicExportToLasFileFeature"; + } + else if (dynamic_cast(uiItem)) { commandIds << "RicExportToLasFileFeature"; }