diff --git a/ApplicationCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake index 23a8629122..dcb19856ca 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake @@ -12,6 +12,7 @@ ${CEE_CURRENT_LIST_DIR}RicNewSummaryCurveFilterFeature.h ${CEE_CURRENT_LIST_DIR}RicViewZoomAllFeature.h ${CEE_CURRENT_LIST_DIR}RicSummaryCurveSwitchAxisFeature.h ${CEE_CURRENT_LIST_DIR}RicPasteSummaryPlotFeature.h +${CEE_CURRENT_LIST_DIR}RicPasteCurveFeature.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -21,6 +22,7 @@ ${CEE_CURRENT_LIST_DIR}RicNewSummaryCurveFilterFeature.cpp ${CEE_CURRENT_LIST_DIR}RicViewZoomAllFeature.cpp ${CEE_CURRENT_LIST_DIR}RicSummaryCurveSwitchAxisFeature.cpp ${CEE_CURRENT_LIST_DIR}RicPasteSummaryPlotFeature.cpp +${CEE_CURRENT_LIST_DIR}RicPasteCurveFeature.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicPasteCurveFeature.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicPasteCurveFeature.cpp new file mode 100644 index 0000000000..38fe7cb879 --- /dev/null +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicPasteCurveFeature.cpp @@ -0,0 +1,111 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RicPasteCurveFeature.h" + +#include "OperationsUsingObjReferences/RicPasteFeatureImpl.h" + +#include "RimSummaryPlot.h" + +#include "cafPdmDefaultObjectFactory.h" +#include "cafPdmDocument.h" +#include "cafPdmObjectGroup.h" +#include "cafSelectionManager.h" + +#include "cvfAssert.h" + +#include +#include "RimSummaryCurve.h" + + +CAF_CMD_SOURCE_INIT(RicPasteCurveFeature, "RicPasteCurveFeature"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicPasteCurveFeature::isCommandEnabled() +{ + caf::PdmObjectHandle* destinationObject = dynamic_cast(caf::SelectionManager::instance()->selectedItem()); + + RimSummaryPlot* summaryPlot = nullptr; + destinationObject->firstAncestorOrThisOfType(summaryPlot); + if (!summaryPlot) + { + return false; + } + + return RicPasteCurveFeature::summaryCurves().size() > 0; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPasteCurveFeature::onActionTriggered(bool isChecked) +{ + caf::PdmObjectHandle* destinationObject = dynamic_cast(caf::SelectionManager::instance()->selectedItem()); + + RimSummaryPlot* summaryPlot = nullptr; + destinationObject->firstAncestorOrThisOfType(summaryPlot); + if (!summaryPlot) + { + return; + } + + std::vector > sourceObjects = RicPasteCurveFeature::summaryCurves(); + + for (size_t i = 0; i < sourceObjects.size(); i++) + { + RimSummaryCurve* newObject = dynamic_cast(sourceObjects[i]->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance())); + CVF_ASSERT(newObject); + + summaryPlot->addCurve(newObject); + + // Resolve references after object has been inserted into the project data model + newObject->resolveReferencesRecursively(); + newObject->initAfterReadRecursively(); + + newObject->loadDataAndUpdate(); + newObject->updateConnectedEditors(); + + summaryPlot->updateConnectedEditors(); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPasteCurveFeature::setupActionLook(QAction* actionToSetup) +{ + actionToSetup->setText("Paste Summary Curve"); + actionToSetup->setIcon(QIcon(":/SummaryCurve16x16.png")); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector > RicPasteCurveFeature::summaryCurves() +{ + caf::PdmObjectGroup objectGroup; + RicPasteFeatureImpl::findObjectsFromClipboardRefs(&objectGroup); + + std::vector > typedObjects; + objectGroup.objectsByType(&typedObjects); + + return typedObjects; +} + diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicPasteCurveFeature.h b/ApplicationCode/Commands/SummaryPlotCommands/RicPasteCurveFeature.h new file mode 100644 index 0000000000..a36ed4054f --- /dev/null +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicPasteCurveFeature.h @@ -0,0 +1,40 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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" + +class RimSummaryCurve; + +//================================================================================================== +/// +//================================================================================================== +class RicPasteCurveFeature : 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 > summaryCurves(); +}; diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index 1b0e4ba935..ecdee81ee7 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -277,6 +277,7 @@ QStringList RimContextCommandBuilder::commandsFromSelection() commandIds << "Separator"; commandIds << "RicDeleteItemFeature"; commandIds << "RicCopyReferencesToClipboardFeature"; + commandIds << "RicPasteCurveFeature"; } else if (dynamic_cast(uiItem)) { @@ -285,6 +286,8 @@ QStringList RimContextCommandBuilder::commandsFromSelection() commandIds << "RicSummaryCurveSwitchAxisFeature"; commandIds << "Separator"; commandIds << "RicDeleteItemFeature"; + commandIds << "RicCopyReferencesToClipboardFeature"; + commandIds << "RicPasteCurveFeature"; } else if(dynamic_cast(uiItem)) { diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryCurve.cpp b/ApplicationCode/ProjectDataModel/Summary/RimSummaryCurve.cpp index 56fde6e8cb..a6500b2512 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryCurve.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryCurve.cpp @@ -372,6 +372,7 @@ void RimSummaryCurve::onLoadDataAndUpdate() if (allAddresses[i].uiText() == m_curveVariable->address().uiText()) { m_uiFilterResultSelection = static_cast(i); + updateConnectedEditors(); } } }