mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2390 Intersections: Add Copy/Paste
This commit is contained in:
@@ -12,6 +12,7 @@ ${CEE_CURRENT_LIST_DIR}RicPasteFeatureImpl.h
|
||||
${CEE_CURRENT_LIST_DIR}RicPasteEclipseCasesFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicPasteEclipseViewsFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicPasteGeoMechViewsFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicPasteIntersectionsFeature.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
@@ -22,6 +23,7 @@ ${CEE_CURRENT_LIST_DIR}RicPasteFeatureImpl.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicPasteEclipseCasesFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicPasteEclipseViewsFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicPasteGeoMechViewsFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicPasteIntersectionsFeature.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "RimEclipseCase.h"
|
||||
#include "RimEclipseView.h"
|
||||
#include "RimGeoMechView.h"
|
||||
#include "RimIntersection.h"
|
||||
#include "RimIntersectionBox.h"
|
||||
#include "RimMimeData.h"
|
||||
#include "RimSummaryCurveFilter.h"
|
||||
#include "RimSummaryPlot.h"
|
||||
@@ -136,6 +138,14 @@ bool RicCopyReferencesToClipboardFeature::isCopyOfObjectSupported(caf::PdmObject
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (dynamic_cast<RimIntersection*>(pdmObject))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (dynamic_cast<RimIntersectionBox*>(pdmObject))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (dynamic_cast<RimSummaryPlot*>(pdmObject))
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "RicPasteIntersectionsFeature.h"
|
||||
|
||||
#include "RicPasteFeatureImpl.h"
|
||||
|
||||
#include "RimIntersection.h"
|
||||
#include "RimIntersectionBox.h"
|
||||
#include "RimIntersectionCollection.h"
|
||||
|
||||
#include "RiuMainWindow.h"
|
||||
|
||||
#include "cafPdmObjectGroup.h"
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include <QAction>
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicPasteIntersectionsFeature, "RicPasteIntersectionsFeature");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicPasteIntersectionsFeature::isCommandEnabled()
|
||||
{
|
||||
caf::PdmObjectGroup objectGroup;
|
||||
RicPasteFeatureImpl::findObjectsFromClipboardRefs(&objectGroup);
|
||||
|
||||
std::vector<caf::PdmPointer<RimIntersection>> intersectionObjects;
|
||||
objectGroup.objectsByType(&intersectionObjects);
|
||||
|
||||
std::vector<caf::PdmPointer<RimIntersectionBox>> intersectionBoxObjects;
|
||||
objectGroup.objectsByType(&intersectionBoxObjects);
|
||||
|
||||
if (intersectionObjects.empty() && intersectionBoxObjects.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
caf::PdmObjectHandle* destinationObject =
|
||||
dynamic_cast<caf::PdmObjectHandle*>(caf::SelectionManager::instance()->selectedItem());
|
||||
|
||||
if (findIntersectionCollection(destinationObject))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicPasteIntersectionsFeature::onActionTriggered(bool isChecked)
|
||||
{
|
||||
caf::PdmObjectHandle* destinationObject =
|
||||
dynamic_cast<caf::PdmObjectHandle*>(caf::SelectionManager::instance()->selectedItem());
|
||||
|
||||
RimIntersectionCollection* intersectionCollection =
|
||||
RicPasteIntersectionsFeature::findIntersectionCollection(destinationObject);
|
||||
|
||||
CAF_ASSERT(intersectionCollection);
|
||||
|
||||
caf::PdmObjectGroup objectGroup;
|
||||
RicPasteFeatureImpl::findObjectsFromClipboardRefs(&objectGroup);
|
||||
|
||||
if (objectGroup.objects.size() == 0) return;
|
||||
|
||||
std::vector<caf::PdmPointer<RimIntersection>> intersectionObjects;
|
||||
objectGroup.objectsByType(&intersectionObjects);
|
||||
|
||||
for (size_t i = 0; i < intersectionObjects.size(); i++)
|
||||
{
|
||||
RimIntersection* intersection = dynamic_cast<RimIntersection*>(
|
||||
intersectionObjects[i]->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance()));
|
||||
|
||||
QString nameOfCopy = QString("Copy of ") + intersection->name;
|
||||
intersection->name = nameOfCopy;
|
||||
|
||||
if (i == intersectionObjects.size() - 1)
|
||||
{
|
||||
intersectionCollection->appendIntersectionAndUpdate(intersection);
|
||||
}
|
||||
else
|
||||
{
|
||||
intersectionCollection->appendIntersectionNoUpdate(intersection);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<caf::PdmPointer<RimIntersectionBox>> intersectionBoxObjects;
|
||||
objectGroup.objectsByType(&intersectionBoxObjects);
|
||||
|
||||
for (size_t i = 0; i < intersectionBoxObjects.size(); i++)
|
||||
{
|
||||
RimIntersectionBox* intersectionBox = dynamic_cast<RimIntersectionBox*>(
|
||||
intersectionBoxObjects[i]->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance()));
|
||||
|
||||
QString nameOfCopy = QString("Copy of ") + intersectionBox->name;
|
||||
intersectionBox->name = nameOfCopy;
|
||||
|
||||
if (i == intersectionBoxObjects.size() - 1)
|
||||
{
|
||||
intersectionCollection->appendIntersectionBoxAndUpdate(intersectionBox);
|
||||
}
|
||||
else
|
||||
{
|
||||
intersectionCollection->appendIntersectionBoxNoUpdate(intersectionBox);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicPasteIntersectionsFeature::setupActionLook(QAction* actionToSetup)
|
||||
{
|
||||
actionToSetup->setText("Paste (Intersections)");
|
||||
|
||||
RicPasteFeatureImpl::setIconAndShortcuts(actionToSetup);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimIntersectionCollection* RicPasteIntersectionsFeature::findIntersectionCollection(caf::PdmObjectHandle* objectHandle)
|
||||
{
|
||||
RimIntersectionCollection* intersectionCollection = dynamic_cast<RimIntersectionCollection*>(objectHandle);
|
||||
if (intersectionCollection)
|
||||
{
|
||||
return intersectionCollection;
|
||||
}
|
||||
|
||||
RimIntersection* intersection = dynamic_cast<RimIntersection*>(objectHandle);
|
||||
if (intersection)
|
||||
{
|
||||
intersection->firstAncestorOrThisOfType(intersectionCollection);
|
||||
return intersectionCollection;
|
||||
}
|
||||
|
||||
RimIntersectionBox* intersectionBox = dynamic_cast<RimIntersectionBox*>(objectHandle);
|
||||
if (intersectionBox)
|
||||
{
|
||||
intersectionBox->firstAncestorOrThisOfType(intersectionCollection);
|
||||
return intersectionCollection;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- 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 "cafPdmObjectHandle.h"
|
||||
|
||||
class RimIntersectionCollection;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicPasteIntersectionsFeature : 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 RimIntersectionCollection* findIntersectionCollection(caf::PdmObjectHandle* objectHandle);
|
||||
};
|
||||
@@ -449,6 +449,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
|
||||
{
|
||||
menuBuilder << "RicAppendIntersectionFeature";
|
||||
menuBuilder << "RicAppendIntersectionBoxFeature";
|
||||
menuBuilder << "RicPasteIntersectionsFeature";
|
||||
}
|
||||
else if (dynamic_cast<RimIntersection*>(uiItem))
|
||||
{
|
||||
@@ -456,11 +457,13 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
|
||||
menuBuilder << "RicAppendIntersectionBoxFeature";
|
||||
menuBuilder.addSeparator();
|
||||
menuBuilder << "RicNewIntersectionViewFeature";
|
||||
menuBuilder << "RicPasteIntersectionsFeature";
|
||||
}
|
||||
else if (dynamic_cast<RimIntersectionBox*>(uiItem))
|
||||
{
|
||||
menuBuilder << "RicAppendIntersectionFeature";
|
||||
menuBuilder << "RicAppendIntersectionBoxFeature";
|
||||
menuBuilder << "RicPasteIntersectionsFeature";
|
||||
}
|
||||
else if (dynamic_cast<RimSimWellInView*>(uiItem))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user