#1840 Summary case: Cut paste of summary cases

This commit is contained in:
Rebecca Cox 2017-09-12 14:08:09 +02:00
parent 6dc14c09b1
commit ee25b8424d
11 changed files with 375 additions and 5 deletions

View File

@ -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

View File

@ -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 <http://www.gnu.org/licenses/gpl.html>
// 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 <QAction>
#include <QApplication>
#include <QClipboard>
CAF_CMD_SOURCE_INIT(RicCutReferencesToClipboardFeature, "RicCutReferencesToClipboardFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicCutReferencesToClipboardFeature::isCommandEnabled()
{
return isAnyCuttableObjectSelected();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCutReferencesToClipboardFeature::onActionTriggered(bool isChecked)
{
this->disableModelChangeContribution();
if (!isAnyCuttableObjectSelected()) return;
std::vector<QString> referenceList;
std::vector<caf::PdmObject*> 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<caf::PdmObject*> 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<RimSummaryCase*>(pdmObject))
{
return true;
}
return false;
}

View File

@ -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 <http://www.gnu.org/licenses/gpl.html>
// 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);
};

View File

@ -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);
}

View File

@ -50,6 +50,8 @@ public:
static void setIconAndShortcuts(QAction* action);
static void clearClipboard();
private:
static void populateObjectGroupFromReferences(const std::vector<QString>& referenceList, caf::PdmObjectGroup* objectGroup);
static void referencesFromClipboard(std::vector<QString>& referenceList);

View File

@ -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

View File

@ -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 <http://www.gnu.org/licenses/gpl.html>
// 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 <QAction>
CAF_CMD_SOURCE_INIT(RicPasteSummaryCaseFeature, "RicPasteSummaryCaseFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicPasteSummaryCaseFeature::isCommandEnabled()
{
caf::PdmObjectHandle* destinationObject = dynamic_cast<caf::PdmObjectHandle*>(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::PdmObjectHandle*>(caf::SelectionManager::instance()->selectedItem());
std::vector<caf::PdmPointer<RimSummaryCase> > 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<caf::PdmPointer<RimSummaryCase> > RicPasteSummaryCaseFeature::summaryCases()
{
caf::PdmObjectGroup objectGroup;
RicPasteFeatureImpl::findObjectsFromClipboardRefs(&objectGroup);
std::vector<caf::PdmPointer<RimSummaryCase> > 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();
}
}

View File

@ -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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
#include "cafPdmPointer.h"
#include <vector>
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<caf::PdmPointer<RimSummaryCase> > summaryCases();
static void removeFromSourceCollection(RimSummaryCase* summaryCase);
};

View File

@ -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

View File

@ -510,10 +510,11 @@ bool RiuDragDrop::handleSummaryCaseMainCollectionDrop(Qt::DropAction action, caf
summaryCaseCollection->removeCase(summaryCase);
summaryCaseDropTarget->addCase(summaryCase);
summaryCaseCollection->updateConnectedEditors();
continue;
}
}
summaryCaseDropTarget->updateConnectedEditors();
return true;
}

View File

@ -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;