ResInsight/ApplicationCode/Commands/OperationsUsingObjReferences/RicPasteFeatureImpl.cpp
Jacob Støren f5d15c19e1 firstAnchestorOfType now considers the object itself as well.
It is thus renamed to firstAnchestorOrThisOfType
2015-08-14 14:04:47 +02:00

145 lines
4.9 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
// 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 "RicPasteFeatureImpl.h"
#include "RiaApplication.h"
#include "RimCaseCollection.h"
#include "RimEclipseCase.h"
#include "RimGeoMechCase.h"
#include "RimGeoMechView.h"
#include "RimIdenticalGridCaseGroup.h"
#include "RimMimeData.h"
#include "RimProject.h"
#include "cafPdmObjectGroup.h"
#include "cafPdmObjectHandle.h"
#include <QClipboard>
#include <QString>
namespace caf
{
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicPasteFeatureImpl::populateObjectGroupFromReferences(const std::vector<QString>& referenceList, caf::PdmObjectGroup* objectGroup)
{
PdmObjectHandle* referenceRoot = RiaApplication::instance()->project();
for (size_t i = 0; i < referenceList.size(); i++)
{
QString reference = referenceList[i];
PdmObjectHandle* pdmObj = PdmReferenceHelper::objectFromReference(referenceRoot, reference);
if (pdmObj)
{
objectGroup->objects.push_back(pdmObj);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicPasteFeatureImpl::referencesFromClipboard(std::vector<QString>& referenceList)
{
QClipboard* clipboard = QApplication::clipboard();
if (!clipboard) return;
const MimeDataWithReferences* mimeDataReferences = dynamic_cast<const MimeDataWithReferences*>(clipboard->mimeData());
if (!mimeDataReferences) return;
referenceList = mimeDataReferences->references();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicPasteFeatureImpl::findObjectsFromClipboardRefs(caf::PdmObjectGroup* objectGroup)
{
std::vector<QString> referenceList;
RicPasteFeatureImpl::referencesFromClipboard(referenceList);
RicPasteFeatureImpl::populateObjectGroupFromReferences(referenceList, objectGroup);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimIdenticalGridCaseGroup* RicPasteFeatureImpl::findGridCaseGroup(PdmObjectHandle* objectHandle)
{
if (dynamic_cast<RimIdenticalGridCaseGroup*>(objectHandle))
{
return dynamic_cast<RimIdenticalGridCaseGroup*>(objectHandle);
}
else if (dynamic_cast<RimCaseCollection*>(objectHandle) ||
dynamic_cast<RimEclipseCase*>(objectHandle))
{
RimIdenticalGridCaseGroup* gridCaseGroup = NULL;
objectHandle->firstAnchestorOrThisOfType(gridCaseGroup);
return gridCaseGroup;
}
return NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimEclipseCase* RicPasteFeatureImpl::findEclipseCase(PdmObjectHandle* objectHandle)
{
if (dynamic_cast<RimEclipseCase*>(objectHandle))
{
return dynamic_cast<RimEclipseCase*>(objectHandle);
}
else if (dynamic_cast<RimEclipseView*>(objectHandle))
{
RimEclipseView* reservoirView = dynamic_cast<RimEclipseView*>(objectHandle);
return reservoirView->eclipseCase();
}
return NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimGeoMechCase* RicPasteFeatureImpl::findGeoMechCase(PdmObjectHandle* objectHandle)
{
RimGeoMechCase* geomCase = dynamic_cast<RimGeoMechCase*>(objectHandle);
if (!geomCase)
{
RimGeoMechView* geomView = dynamic_cast<RimGeoMechView*>(objectHandle);
if (geomView) geomCase = geomView->geoMechCase();
}
return geomCase;
}
} // end namespace caf