mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
(#573) Added new copy method for PdmObjects
Added copy method to XmlObjectHandle, and use this method from PasteEclipseCases
This commit is contained in:
@@ -107,10 +107,19 @@ void RicPasteEclipseCasesFeature::addCasesToGridCaseGroup(PdmObjectGroup& object
|
||||
RimProject* proj = RiaApplication::instance()->project();
|
||||
CVF_ASSERT(proj);
|
||||
|
||||
std::vector<caf::PdmPointer<RimEclipseResultCase> > typedObjects;
|
||||
objectGroup.createCopyByType(&typedObjects, PdmDefaultObjectFactory::instance());
|
||||
std::vector<RimEclipseResultCase*> resultCases;
|
||||
|
||||
if (typedObjects.size() == 0)
|
||||
for (size_t i = 0; i < objectGroup.objects.size(); i++)
|
||||
{
|
||||
RimEclipseResultCase* eclCase = dynamic_cast<RimEclipseResultCase*>(objectGroup.objects[i]);
|
||||
if (eclCase)
|
||||
{
|
||||
RimEclipseResultCase* eclCaseCopy = dynamic_cast<RimEclipseResultCase*>(eclCase->copyByXmlSerialization(PdmDefaultObjectFactory::instance()));
|
||||
resultCases.push_back(eclCaseCopy);
|
||||
}
|
||||
}
|
||||
|
||||
if (resultCases.size() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -130,9 +139,9 @@ void RicPasteEclipseCasesFeature::addCasesToGridCaseGroup(PdmObjectGroup& object
|
||||
std::vector<RimEclipseResultCase*> insertedCases;
|
||||
|
||||
// Add cases to case group
|
||||
for (size_t i = 0; i < typedObjects.size(); i++)
|
||||
for (size_t i = 0; i < resultCases.size(); i++)
|
||||
{
|
||||
RimEclipseResultCase* rimResultReservoir = typedObjects[i];
|
||||
RimEclipseResultCase* rimResultReservoir = resultCases[i];
|
||||
|
||||
proj->assignCaseIdToCase(rimResultReservoir);
|
||||
|
||||
@@ -144,19 +153,11 @@ void RicPasteEclipseCasesFeature::addCasesToGridCaseGroup(PdmObjectGroup& object
|
||||
insertedCases.push_back(rimResultReservoir);
|
||||
}
|
||||
|
||||
// Initialize the new objects
|
||||
for (size_t i = 0; i < insertedCases.size(); i++)
|
||||
{
|
||||
RimEclipseResultCase* rimResultReservoir = insertedCases[i];
|
||||
rimResultReservoir->initAfterReadRecursively();
|
||||
}
|
||||
|
||||
// Load stuff
|
||||
for (size_t i = 0; i < insertedCases.size(); i++)
|
||||
{
|
||||
RimEclipseResultCase* rimResultReservoir = insertedCases[i];
|
||||
|
||||
|
||||
if (!mainResultCase)
|
||||
{
|
||||
rimResultReservoir->openEclipseGridFile();
|
||||
|
||||
@@ -170,6 +170,21 @@ PdmObjectHandle* PdmXmlObjectHandle::readUnknownObjectFromXmlString(const QStrin
|
||||
return newObject;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmObjectHandle* PdmXmlObjectHandle::copyByXmlSerialization(PdmObjectFactory* objectFactory)
|
||||
{
|
||||
this->setupBeforeSaveRecursively();
|
||||
|
||||
QString xmlString = this->writeObjectToXmlString();
|
||||
|
||||
PdmObjectHandle* objectCopy = PdmXmlObjectHandle::readUnknownObjectFromXmlString(xmlString, objectFactory);
|
||||
objectCopy->xmlCapability()->initAfterReadRecursively();
|
||||
|
||||
return objectCopy;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -36,6 +36,7 @@ public:
|
||||
void readObjectFromXmlString(const QString& xmlString, PdmObjectFactory* objectFactory);
|
||||
QString writeObjectToXmlString();
|
||||
static PdmObjectHandle* readUnknownObjectFromXmlString(const QString& xmlString, PdmObjectFactory* objectFactory);
|
||||
PdmObjectHandle* copyByXmlSerialization(PdmObjectFactory* objectFactory);
|
||||
|
||||
// Main XML serialization methods that is used internally by the document serialization system
|
||||
// Not supposed to be used directly.
|
||||
|
||||
Reference in New Issue
Block a user