diff --git a/ApplicationCode/Commands/OperationsUsingObjReferences/CMakeLists_files.cmake b/ApplicationCode/Commands/OperationsUsingObjReferences/CMakeLists_files.cmake index e651d86273..5a4634cd4e 100644 --- a/ApplicationCode/Commands/OperationsUsingObjReferences/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/OperationsUsingObjReferences/CMakeLists_files.cmake @@ -6,6 +6,7 @@ endif() set (SOURCE_GROUP_HEADER_FILES ${CEE_CURRENT_LIST_DIR}RicCopyReferencesToClipboardFeature.h +${CEE_CURRENT_LIST_DIR}RicCutReferencesToClipboardFeature.h ${CEE_CURRENT_LIST_DIR}RicPasteFeatureImpl.h ${CEE_CURRENT_LIST_DIR}RicPasteEclipseCasesFeature.h @@ -15,6 +16,7 @@ ${CEE_CURRENT_LIST_DIR}RicPasteGeoMechViewsFeature.h set (SOURCE_GROUP_SOURCE_FILES ${CEE_CURRENT_LIST_DIR}RicCopyReferencesToClipboardFeature.cpp +${CEE_CURRENT_LIST_DIR}RicCutReferencesToClipboardFeature.cpp ${CEE_CURRENT_LIST_DIR}RicPasteFeatureImpl.cpp ${CEE_CURRENT_LIST_DIR}RicPasteEclipseCasesFeature.cpp diff --git a/ApplicationCode/Commands/OperationsUsingObjReferences/RicCutReferencesToClipboardFeature.cpp b/ApplicationCode/Commands/OperationsUsingObjReferences/RicCutReferencesToClipboardFeature.cpp new file mode 100644 index 0000000000..b9706aec3b --- /dev/null +++ b/ApplicationCode/Commands/OperationsUsingObjReferences/RicCutReferencesToClipboardFeature.cpp @@ -0,0 +1,118 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017- 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 "RicCutReferencesToClipboardFeature.h" + +#include "RimMimeData.h" +#include "RimSummaryCase.h" +#include "RimSummaryCaseCollection.h" +#include "RimSummaryCaseMainCollection.h" +#include "RimSummaryCurveFilter.h" + +#include "cafPdmObject.h" +#include "cafPdmUiItem.h" +#include "cafSelectionManager.h" + +#include +#include +#include + +CAF_CMD_SOURCE_INIT(RicCutReferencesToClipboardFeature, "RicCutReferencesToClipboardFeature"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicCutReferencesToClipboardFeature::isCommandEnabled() +{ + return isAnyCuttableObjectSelected(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicCutReferencesToClipboardFeature::onActionTriggered(bool isChecked) +{ + this->disableModelChangeContribution(); + + if (!isAnyCuttableObjectSelected()) return; + + std::vector referenceList; + + std::vector selectedFormationNamesCollObjs; + caf::SelectionManager::instance()->objectsByType(&selectedFormationNamesCollObjs); + + for (caf::PdmObject* pdmObject : selectedFormationNamesCollObjs) + { + if (RicCutReferencesToClipboardFeature::isCuttingOfObjectSupported(pdmObject)) + { + QString itemRef = caf::PdmReferenceHelper::referenceFromRootToObject(caf::SelectionManager::instance()->pdmRootObject(), pdmObject); + + referenceList.push_back(itemRef); + } + } + + MimeDataWithReferences* myObject = new MimeDataWithReferences; + myObject->setReferences(referenceList); + + QClipboard* clipboard = QApplication::clipboard(); + if (clipboard) + { + clipboard->setMimeData(myObject); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicCutReferencesToClipboardFeature::setupActionLook(QAction* actionToSetup) +{ + actionToSetup->setText("Cut"); + actionToSetup->setIcon(QIcon(":/Clipboard.png")); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicCutReferencesToClipboardFeature::isAnyCuttableObjectSelected() +{ + std::vector selectedFormationNamesCollObjs; + caf::SelectionManager::instance()->objectsByType(&selectedFormationNamesCollObjs); + + for (caf::PdmObject* pdmObject : selectedFormationNamesCollObjs) + { + if (RicCutReferencesToClipboardFeature::isCuttingOfObjectSupported(pdmObject)) + { + return true; + } + } + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicCutReferencesToClipboardFeature::isCuttingOfObjectSupported(caf::PdmObject* pdmObject) +{ + if (dynamic_cast(pdmObject)) + { + return true; + } + + return false; +} diff --git a/ApplicationCode/Commands/OperationsUsingObjReferences/RicCutReferencesToClipboardFeature.h b/ApplicationCode/Commands/OperationsUsingObjReferences/RicCutReferencesToClipboardFeature.h new file mode 100644 index 0000000000..cb621c4c9b --- /dev/null +++ b/ApplicationCode/Commands/OperationsUsingObjReferences/RicCutReferencesToClipboardFeature.h @@ -0,0 +1,43 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017- 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" + +namespace caf +{ + class PdmObject; +} + +//================================================================================================== +/// +//================================================================================================== +class RicCutReferencesToClipboardFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +private: + virtual bool isCommandEnabled() override; + virtual void onActionTriggered( bool isChecked ) override; + virtual void setupActionLook( QAction* actionToSetup ) override; + + static bool isAnyCuttableObjectSelected(); + static bool isCuttingOfObjectSupported(caf::PdmObject* pdmObject); +}; diff --git a/ApplicationCode/Commands/OperationsUsingObjReferences/RicPasteFeatureImpl.cpp b/ApplicationCode/Commands/OperationsUsingObjReferences/RicPasteFeatureImpl.cpp index 859fa97d0f..b4b3d903a6 100644 --- a/ApplicationCode/Commands/OperationsUsingObjReferences/RicPasteFeatureImpl.cpp +++ b/ApplicationCode/Commands/OperationsUsingObjReferences/RicPasteFeatureImpl.cpp @@ -149,3 +149,14 @@ void RicPasteFeatureImpl::setIconAndShortcuts(QAction* action) action->setShortcuts(QKeySequence::Paste); } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPasteFeatureImpl::clearClipboard() +{ + QClipboard* clipboard = QApplication::clipboard(); + if (!clipboard) return; + + clipboard->setMimeData(nullptr); +} diff --git a/ApplicationCode/Commands/OperationsUsingObjReferences/RicPasteFeatureImpl.h b/ApplicationCode/Commands/OperationsUsingObjReferences/RicPasteFeatureImpl.h index dd39de55b9..d5fe97b7fc 100644 --- a/ApplicationCode/Commands/OperationsUsingObjReferences/RicPasteFeatureImpl.h +++ b/ApplicationCode/Commands/OperationsUsingObjReferences/RicPasteFeatureImpl.h @@ -50,6 +50,8 @@ public: static void setIconAndShortcuts(QAction* action); + static void clearClipboard(); + private: static void populateObjectGroupFromReferences(const std::vector& referenceList, caf::PdmObjectGroup* objectGroup); static void referencesFromClipboard(std::vector& referenceList); diff --git a/ApplicationCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake index 600300493a..5b421302b6 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake @@ -15,6 +15,7 @@ ${CEE_CURRENT_LIST_DIR}RicViewZoomAllFeature.h ${CEE_CURRENT_LIST_DIR}RicSummaryCurveSwitchAxisFeature.h ${CEE_CURRENT_LIST_DIR}RicPasteSummaryPlotFeature.h ${CEE_CURRENT_LIST_DIR}RicPasteSummaryCurveFeature.h +${CEE_CURRENT_LIST_DIR}RicPasteSummaryCaseFeature.h ${CEE_CURRENT_LIST_DIR}RicAsciiExportSummaryPlotFeature.h ${CEE_CURRENT_LIST_DIR}RicNewGridTimeHistoryCurveFeature.h ${CEE_CURRENT_LIST_DIR}RicSelectSummaryPlotUI.h @@ -34,6 +35,7 @@ ${CEE_CURRENT_LIST_DIR}RicViewZoomAllFeature.cpp ${CEE_CURRENT_LIST_DIR}RicSummaryCurveSwitchAxisFeature.cpp ${CEE_CURRENT_LIST_DIR}RicPasteSummaryPlotFeature.cpp ${CEE_CURRENT_LIST_DIR}RicPasteSummaryCurveFeature.cpp +${CEE_CURRENT_LIST_DIR}RicPasteSummaryCaseFeature.cpp ${CEE_CURRENT_LIST_DIR}RicAsciiExportSummaryPlotFeature.cpp ${CEE_CURRENT_LIST_DIR}RicNewGridTimeHistoryCurveFeature.cpp ${CEE_CURRENT_LIST_DIR}RicSelectSummaryPlotUI.cpp diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicPasteSummaryCaseFeature.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicPasteSummaryCaseFeature.cpp new file mode 100644 index 0000000000..cd8149acb7 --- /dev/null +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicPasteSummaryCaseFeature.cpp @@ -0,0 +1,148 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017- 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 "RicPasteSummaryCaseFeature.h" + +#include "OperationsUsingObjReferences/RicPasteFeatureImpl.h" + +#include "RimSummaryCase.h" +#include "RimSummaryCaseCollection.h" +#include "RimSummaryCaseMainCollection.h" +#include "RimSummaryPlot.h" + +#include "cafPdmDefaultObjectFactory.h" +#include "cafPdmDocument.h" +#include "cafPdmObjectGroup.h" +#include "cafSelectionManager.h" + +#include "cvfAssert.h" + +#include + +CAF_CMD_SOURCE_INIT(RicPasteSummaryCaseFeature, "RicPasteSummaryCaseFeature"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicPasteSummaryCaseFeature::isCommandEnabled() +{ + caf::PdmObjectHandle* destinationObject = dynamic_cast(caf::SelectionManager::instance()->selectedItem()); + if (!destinationObject) return false; + + RimSummaryCaseCollection* summaryCaseCollection = nullptr; + destinationObject->firstAncestorOrThisOfType(summaryCaseCollection); + + RimSummaryCaseMainCollection* summaryCaseMainCollection = nullptr; + destinationObject->firstAncestorOrThisOfType(summaryCaseMainCollection); + + if (!(summaryCaseCollection || summaryCaseMainCollection)) + { + return false; + } + + return RicPasteSummaryCaseFeature::summaryCases().size() > 0; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPasteSummaryCaseFeature::onActionTriggered(bool isChecked) +{ + caf::PdmObjectHandle* destinationObject = dynamic_cast(caf::SelectionManager::instance()->selectedItem()); + + std::vector > sourceObjects = RicPasteSummaryCaseFeature::summaryCases(); + + RimSummaryCaseCollection* summaryCaseCollection = nullptr; + destinationObject->firstAncestorOrThisOfType(summaryCaseCollection); + + if (summaryCaseCollection) + { + for (size_t i = 0; i < sourceObjects.size(); i++) + { + RicPasteSummaryCaseFeature::removeFromSourceCollection(sourceObjects[i]); + summaryCaseCollection->addCase(sourceObjects[i]); + } + + summaryCaseCollection->updateConnectedEditors(); + RicPasteFeatureImpl::clearClipboard(); + return; + } + + RimSummaryCaseMainCollection* summaryCaseMainCollection = nullptr; + destinationObject->firstAncestorOrThisOfType(summaryCaseMainCollection); + + if (summaryCaseMainCollection) + { + for (size_t i = 0; i < sourceObjects.size(); i++) + { + RicPasteSummaryCaseFeature::removeFromSourceCollection(sourceObjects[i]); + summaryCaseMainCollection->addCase(sourceObjects[i]); + } + + RicPasteFeatureImpl::clearClipboard(); + summaryCaseMainCollection->updateConnectedEditors(); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPasteSummaryCaseFeature::setupActionLook(QAction* action) +{ + action->setText("Paste Summary Case"); + action->setIcon(QIcon(":/clipboard.png")); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector > RicPasteSummaryCaseFeature::summaryCases() +{ + caf::PdmObjectGroup objectGroup; + RicPasteFeatureImpl::findObjectsFromClipboardRefs(&objectGroup); + + std::vector > typedObjects; + objectGroup.objectsByType(&typedObjects); + + return typedObjects; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPasteSummaryCaseFeature::removeFromSourceCollection(RimSummaryCase* summaryCase) +{ + RimSummaryCaseCollection* sourceSummaryCaseCollection = nullptr; + summaryCase->firstAncestorOrThisOfType(sourceSummaryCaseCollection); + + if (sourceSummaryCaseCollection) + { + sourceSummaryCaseCollection->removeCase(summaryCase); + sourceSummaryCaseCollection->updateConnectedEditors(); + return; + } + + RimSummaryCaseMainCollection* sourceSummaryCaseMainCollection = nullptr; + summaryCase->firstAncestorOrThisOfType(sourceSummaryCaseMainCollection); + + if (sourceSummaryCaseMainCollection) + { + sourceSummaryCaseMainCollection->removeCase(summaryCase); + sourceSummaryCaseMainCollection->updateConnectedEditors(); + } +} \ No newline at end of file diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicPasteSummaryCaseFeature.h b/ApplicationCode/Commands/SummaryPlotCommands/RicPasteSummaryCaseFeature.h new file mode 100644 index 0000000000..d87778e769 --- /dev/null +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicPasteSummaryCaseFeature.h @@ -0,0 +1,42 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017- 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 RimSummaryCase; + +//================================================================================================== +/// +//================================================================================================== +class RicPasteSummaryCaseFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +private: + virtual bool isCommandEnabled() override; + virtual void onActionTriggered( bool isChecked ) override; + virtual void setupActionLook(QAction* action) override; + + static std::vector > summaryCases(); + static void removeFromSourceCollection(RimSummaryCase* summaryCase); +}; \ No newline at end of file diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index 1dbe1ed42f..cebe5a0426 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -444,13 +444,15 @@ QStringList RimContextCommandBuilder::commandsFromSelection() commandIds << "RicWellPathImportCompletionsFileFeature"; commandIds << "RicFlyToObjectFeature"; commandIds << "RicExportCarfin"; + + commandIds << "RicPasteSummaryCaseFeature"; commandIds << "RicReloadSummaryCaseFeature"; commandIds << "RicCreateSummaryCaseCollectionFeature"; commandIds << "Separator"; commandIds << "RicCloseSummaryCaseFeature"; commandIds << "RicCloseSummaryCaseInCollectionFeature"; commandIds << "RicDeleteSummaryCaseCollectionFeature"; - + commandIds << "RicCutReferencesToClipboardFeature"; // Fracture commands #ifdef USE_PROTOTYPE_FEATURE_FRACTURES diff --git a/ApplicationCode/UserInterface/RiuDragDrop.cpp b/ApplicationCode/UserInterface/RiuDragDrop.cpp index 5eef012689..6c37c32d94 100644 --- a/ApplicationCode/UserInterface/RiuDragDrop.cpp +++ b/ApplicationCode/UserInterface/RiuDragDrop.cpp @@ -510,10 +510,11 @@ bool RiuDragDrop::handleSummaryCaseMainCollectionDrop(Qt::DropAction action, caf summaryCaseCollection->removeCase(summaryCase); summaryCaseDropTarget->addCase(summaryCase); summaryCaseCollection->updateConnectedEditors(); - continue; } } + summaryCaseDropTarget->updateConnectedEditors(); + return true; } diff --git a/ApplicationCode/UserInterface/RiuDragDrop.h b/ApplicationCode/UserInterface/RiuDragDrop.h index eb9b47d059..b497dc2b8d 100644 --- a/ApplicationCode/UserInterface/RiuDragDrop.h +++ b/ApplicationCode/UserInterface/RiuDragDrop.h @@ -1,7 +1,6 @@ ///////////////////////////////////////////////////////////////////////////////// // -// Copyright (C) 2015- Statoil ASA -// Copyright (C) 2015- Ceetron Solutions AS +// Copyright (C) 2017- 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 @@ -45,7 +44,7 @@ class RiuDragDrop : public caf::PdmUiDragDropInterface public: RiuDragDrop(); virtual ~RiuDragDrop(); - + protected: virtual Qt::DropActions supportedDropActions() const; virtual Qt::ItemFlags flags(const QModelIndex &index) const;