2019-03-12 08:46:51 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2019- Equinor 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 <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-03-29 07:17:39 -05:00
|
|
|
#include "RicPasteGridCrossPlotDataSetFeature.h"
|
2019-03-12 08:46:51 -05:00
|
|
|
|
2019-05-06 03:36:05 -05:00
|
|
|
#include "RiaGuiApplication.h"
|
2019-03-12 08:46:51 -05:00
|
|
|
#include "RimGridCrossPlot.h"
|
2019-03-29 07:17:39 -05:00
|
|
|
#include "RimGridCrossPlotDataSet.h"
|
2019-03-12 08:46:51 -05:00
|
|
|
#include "RiuPlotMainWindowTools.h"
|
|
|
|
|
|
|
|
#include "OperationsUsingObjReferences/RicPasteFeatureImpl.h"
|
|
|
|
|
|
|
|
#include "cafPdmObjectGroup.h"
|
|
|
|
#include "cafSelectionManager.h"
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
|
2019-03-29 07:17:39 -05:00
|
|
|
CAF_CMD_SOURCE_INIT(RicPasteGridCrossPlotDataSetFeature, "RicPasteGridCrossPlotDataSetFeature");
|
2019-03-12 08:46:51 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-03-29 07:17:39 -05:00
|
|
|
bool RicPasteGridCrossPlotDataSetFeature::isCommandEnabled()
|
2019-03-12 08:46:51 -05:00
|
|
|
{
|
2019-03-29 07:17:39 -05:00
|
|
|
auto curvesOnClipboard = gridCrossPlotDataSetsOnClipboard();
|
2019-03-12 08:46:51 -05:00
|
|
|
if (curvesOnClipboard.empty()) return false;
|
|
|
|
|
|
|
|
return caf::SelectionManager::instance()->selectedItemAncestorOfType<RimGridCrossPlot>() != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-03-29 07:17:39 -05:00
|
|
|
void RicPasteGridCrossPlotDataSetFeature::onActionTriggered(bool isChecked)
|
2019-03-12 08:46:51 -05:00
|
|
|
{
|
|
|
|
RimGridCrossPlot* crossPlot = caf::SelectionManager::instance()->selectedItemAncestorOfType<RimGridCrossPlot>();
|
|
|
|
|
|
|
|
if (crossPlot)
|
|
|
|
{
|
2019-03-29 07:17:39 -05:00
|
|
|
auto curvesOnClipboard = gridCrossPlotDataSetsOnClipboard();
|
2019-03-12 08:46:51 -05:00
|
|
|
if (!curvesOnClipboard.empty())
|
|
|
|
{
|
2019-03-29 07:17:39 -05:00
|
|
|
RimGridCrossPlotDataSet* objectToSelect = nullptr;
|
2019-03-12 08:46:51 -05:00
|
|
|
|
2019-03-29 07:17:39 -05:00
|
|
|
for (RimGridCrossPlotDataSet* dataSet : gridCrossPlotDataSetsOnClipboard())
|
2019-03-12 08:46:51 -05:00
|
|
|
{
|
2019-03-29 07:17:39 -05:00
|
|
|
RimGridCrossPlotDataSet* newDataSet = dynamic_cast<RimGridCrossPlotDataSet*>(
|
|
|
|
dataSet->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance()));
|
2019-03-12 08:46:51 -05:00
|
|
|
|
2019-03-29 07:17:39 -05:00
|
|
|
crossPlot->addDataSet(newDataSet);
|
|
|
|
newDataSet->resolveReferencesRecursively();
|
|
|
|
newDataSet->initAfterReadRecursively();
|
2019-03-12 08:46:51 -05:00
|
|
|
|
2019-03-29 07:17:39 -05:00
|
|
|
objectToSelect = newDataSet;
|
2019-03-12 08:46:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-06 03:36:05 -05:00
|
|
|
RiaGuiApplication::instance()->getOrCreateMainPlotWindow();
|
2019-03-12 08:46:51 -05:00
|
|
|
crossPlot->updateAllRequiredEditors();
|
|
|
|
crossPlot->loadDataAndUpdate();
|
|
|
|
|
|
|
|
RiuPlotMainWindowTools::selectAsCurrentItem(objectToSelect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-03-29 07:17:39 -05:00
|
|
|
void RicPasteGridCrossPlotDataSetFeature::setupActionLook(QAction* actionToSetup)
|
2019-03-12 08:46:51 -05:00
|
|
|
{
|
2019-03-29 07:17:39 -05:00
|
|
|
actionToSetup->setText("Paste Data Set");
|
2019-03-27 04:29:06 -05:00
|
|
|
RicPasteFeatureImpl::setIconAndShortcuts(actionToSetup);
|
2019-03-12 08:46:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-03-29 07:17:39 -05:00
|
|
|
std::vector<caf::PdmPointer<RimGridCrossPlotDataSet>> RicPasteGridCrossPlotDataSetFeature::gridCrossPlotDataSetsOnClipboard()
|
2019-03-12 08:46:51 -05:00
|
|
|
{
|
|
|
|
caf::PdmObjectGroup objectGroup;
|
|
|
|
RicPasteFeatureImpl::findObjectsFromClipboardRefs(&objectGroup);
|
|
|
|
|
2019-03-29 07:17:39 -05:00
|
|
|
std::vector<caf::PdmPointer<RimGridCrossPlotDataSet>> typedObjects;
|
2019-03-12 08:46:51 -05:00
|
|
|
objectGroup.objectsByType(&typedObjects);
|
|
|
|
|
|
|
|
return typedObjects;
|
|
|
|
}
|