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();
|
RimProject* proj = RiaApplication::instance()->project();
|
||||||
CVF_ASSERT(proj);
|
CVF_ASSERT(proj);
|
||||||
|
|
||||||
std::vector<caf::PdmPointer<RimEclipseResultCase> > typedObjects;
|
std::vector<RimEclipseResultCase*> resultCases;
|
||||||
objectGroup.createCopyByType(&typedObjects, PdmDefaultObjectFactory::instance());
|
|
||||||
|
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
@@ -130,9 +139,9 @@ void RicPasteEclipseCasesFeature::addCasesToGridCaseGroup(PdmObjectGroup& object
|
|||||||
std::vector<RimEclipseResultCase*> insertedCases;
|
std::vector<RimEclipseResultCase*> insertedCases;
|
||||||
|
|
||||||
// Add cases to case group
|
// 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);
|
proj->assignCaseIdToCase(rimResultReservoir);
|
||||||
|
|
||||||
@@ -144,19 +153,11 @@ void RicPasteEclipseCasesFeature::addCasesToGridCaseGroup(PdmObjectGroup& object
|
|||||||
insertedCases.push_back(rimResultReservoir);
|
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
|
// Load stuff
|
||||||
for (size_t i = 0; i < insertedCases.size(); i++)
|
for (size_t i = 0; i < insertedCases.size(); i++)
|
||||||
{
|
{
|
||||||
RimEclipseResultCase* rimResultReservoir = insertedCases[i];
|
RimEclipseResultCase* rimResultReservoir = insertedCases[i];
|
||||||
|
|
||||||
|
|
||||||
if (!mainResultCase)
|
if (!mainResultCase)
|
||||||
{
|
{
|
||||||
rimResultReservoir->openEclipseGridFile();
|
rimResultReservoir->openEclipseGridFile();
|
||||||
|
|||||||
@@ -170,6 +170,21 @@ PdmObjectHandle* PdmXmlObjectHandle::readUnknownObjectFromXmlString(const QStrin
|
|||||||
return newObject;
|
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);
|
void readObjectFromXmlString(const QString& xmlString, PdmObjectFactory* objectFactory);
|
||||||
QString writeObjectToXmlString();
|
QString writeObjectToXmlString();
|
||||||
static PdmObjectHandle* readUnknownObjectFromXmlString(const QString& xmlString, PdmObjectFactory* objectFactory);
|
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
|
// Main XML serialization methods that is used internally by the document serialization system
|
||||||
// Not supposed to be used directly.
|
// Not supposed to be used directly.
|
||||||
|
|||||||
Reference in New Issue
Block a user