From 9a7adb2904775f2c3c4079da05696147b1bf453b Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 22 Nov 2016 09:11:25 +0100 Subject: [PATCH] #901 WLP: Added copy/paste of tracks --- .../WellLogCommands/CMakeLists_files.cmake | 2 + .../RicPasteWellLogTrackFeature.cpp | 112 ++++++++++++++++++ .../RicPasteWellLogTrackFeature.h | 43 +++++++ .../RimContextCommandBuilder.cpp | 3 + 4 files changed, 160 insertions(+) create mode 100644 ApplicationCode/Commands/WellLogCommands/RicPasteWellLogTrackFeature.cpp create mode 100644 ApplicationCode/Commands/WellLogCommands/RicPasteWellLogTrackFeature.h diff --git a/ApplicationCode/Commands/WellLogCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/WellLogCommands/CMakeLists_files.cmake index 128ff0eb31..85ca840124 100644 --- a/ApplicationCode/Commands/WellLogCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/WellLogCommands/CMakeLists_files.cmake @@ -16,6 +16,7 @@ ${CEE_CURRENT_LIST_DIR}RicWellLogsImportFileFeature.h ${CEE_CURRENT_LIST_DIR}RicDeleteWellLogPlotTrackFeature.h ${CEE_CURRENT_LIST_DIR}RicWellLogPlotTrackFeatureImpl.h ${CEE_CURRENT_LIST_DIR}RicPasteWellLogCurveFeature.h +${CEE_CURRENT_LIST_DIR}RicPasteWellLogTrackFeature.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -30,6 +31,7 @@ ${CEE_CURRENT_LIST_DIR}RicWellLogsImportFileFeature.cpp ${CEE_CURRENT_LIST_DIR}RicDeleteWellLogPlotTrackFeature.cpp ${CEE_CURRENT_LIST_DIR}RicWellLogPlotTrackFeatureImpl.cpp ${CEE_CURRENT_LIST_DIR}RicPasteWellLogCurveFeature.cpp +${CEE_CURRENT_LIST_DIR}RicPasteWellLogTrackFeature.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/Commands/WellLogCommands/RicPasteWellLogTrackFeature.cpp b/ApplicationCode/Commands/WellLogCommands/RicPasteWellLogTrackFeature.cpp new file mode 100644 index 0000000000..8f2435397a --- /dev/null +++ b/ApplicationCode/Commands/WellLogCommands/RicPasteWellLogTrackFeature.cpp @@ -0,0 +1,112 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RicPasteWellLogTrackFeature.h" + +#include "OperationsUsingObjReferences/RicPasteFeatureImpl.h" + +#include "RimWellLogPlot.h" +#include "RimWellLogTrack.h" + +#include "cafPdmObjectGroup.h" +#include "cafPdmObjectHandle.h" +#include "cafSelectionManager.h" + +#include "cvfAssert.h" + +#include + + +CAF_CMD_SOURCE_INIT(RicPasteWellLogTrackFeature, "RicPasteWellLogTrackFeature"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicPasteWellLogTrackFeature::isCommandEnabled() +{ + caf::PdmObjectHandle* destinationObject = dynamic_cast(caf::SelectionManager::instance()->selectedItem()); + + RimWellLogPlot* wellLogPlot = nullptr; + destinationObject->firstAncestorOrThisOfType(wellLogPlot); + if (!wellLogPlot) + { + return false; + } + + return RicPasteWellLogTrackFeature::tracks().size() > 0; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPasteWellLogTrackFeature::onActionTriggered(bool isChecked) +{ + caf::PdmObjectHandle* destinationObject = dynamic_cast(caf::SelectionManager::instance()->selectedItem()); + + RimWellLogPlot* wellLogPlot = nullptr; + destinationObject->firstAncestorOrThisOfType(wellLogPlot); + if (!wellLogPlot) + { + return; + } + + std::vector > sourceObjects = RicPasteWellLogTrackFeature::tracks(); + + for (size_t i = 0; i < sourceObjects.size(); i++) + { + RimWellLogTrack* fileCurve = sourceObjects[i]; + if (fileCurve) + { + RimWellLogTrack* newObject = dynamic_cast(fileCurve->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance())); + CVF_ASSERT(newObject); + + wellLogPlot->addTrack(newObject); + + // Resolve references after object has been inserted into the project data model + newObject->resolveReferencesRecursively(); + newObject->initAfterReadRecursively(); + + newObject->loadDataAndUpdate(); + + wellLogPlot->updateConnectedEditors(); + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPasteWellLogTrackFeature::setupActionLook(QAction* actionToSetup) +{ + actionToSetup->setText("Paste Well Log Track"); + actionToSetup->setIcon(QIcon(":/clipboard.png")); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector > RicPasteWellLogTrackFeature::tracks() +{ + caf::PdmObjectGroup objectGroup; + RicPasteFeatureImpl::findObjectsFromClipboardRefs(&objectGroup); + + std::vector > typedObjects; + objectGroup.objectsByType(&typedObjects); + + return typedObjects; +} diff --git a/ApplicationCode/Commands/WellLogCommands/RicPasteWellLogTrackFeature.h b/ApplicationCode/Commands/WellLogCommands/RicPasteWellLogTrackFeature.h new file mode 100644 index 0000000000..56dd6fe954 --- /dev/null +++ b/ApplicationCode/Commands/WellLogCommands/RicPasteWellLogTrackFeature.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 RimWellLogTrack; + +//================================================================================================== +/// +//================================================================================================== +class RicPasteWellLogTrackFeature : 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 > tracks(); +}; diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index 99962cdac8..7cf7b97fc4 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -251,10 +251,13 @@ QStringList RimContextCommandBuilder::commandsFromSelection() } else if (dynamic_cast(uiItem)) { + commandIds << "RicPasteWellLogTrackFeature"; + commandIds << "Separator"; commandIds << "RicNewWellLogPlotTrackFeature"; } else if (dynamic_cast(uiItem)) { + commandIds << "RicPasteWellLogTrackFeature"; commandIds << "RicPasteWellLogCurveFeature"; commandIds << "Separator"; commandIds << "RicNewWellLogCurveExtractionFeature";