diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmFieldHandle.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmFieldHandle.h index 7ef8a7c244..a7a83e52db 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmFieldHandle.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmFieldHandle.h @@ -34,6 +34,7 @@ public: // Ptr referenced objects bool hasPtrReferencedObjects(); virtual void ptrReferencedObjects(std::vector*) { } + virtual void resolveReferences() { } // Capabilities void addCapability(PdmFieldCapability* capability, bool takeOwnership) { m_capabilities.push_back(std::make_pair(capability, takeOwnership)); } diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmPtrField.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmPtrField.h index 2484cfb1a5..8adb40ffab 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmPtrField.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmPtrField.h @@ -37,7 +37,7 @@ class PdmPtrField : public PdmFieldHandle public: typedef PdmPointer FieldDataType; - PdmPtrField() { } + PdmPtrField() { m_referenceString = ""; m_isResolved = false; } explicit PdmPtrField(const DataTypePtr& fieldValue); virtual ~PdmPtrField(); @@ -68,6 +68,7 @@ public: // Ptr referenced objects virtual void ptrReferencedObjects(std::vector* objectsToFill); + virtual void resolveReferences(); private: PDM_DISABLE_COPY_AND_ASSIGN(PdmPtrField); @@ -76,6 +77,10 @@ private: void setRawPtr(PdmObjectHandle* obj); PdmPointer m_fieldValue; + + // Resolving + QString m_referenceString; + bool m_isResolved; }; } // End of namespace caf diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmPtrField.inl b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmPtrField.inl index cf3dbf9d23..d6e30270a7 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmPtrField.inl +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmPtrField.inl @@ -100,5 +100,19 @@ void PdmPtrField::ptrReferencedObjects(std::vector* } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +template +void PdmPtrField::resolveReferences() +{ + if (m_isResolved) return; + if (m_referenceString.isEmpty()) return; + + PdmObjectHandle* objHandle = PdmReferenceHelper::objectFromFieldReference(this, m_referenceString); + this->setRawPtr(objHandle); + m_isResolved = true; +} + } // End of namespace caf diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmDocument.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmDocument.cpp index 74d96c06a8..0e5a83f20b 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmDocument.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmDocument.cpp @@ -91,6 +91,7 @@ void PdmDocument::readFile(QIODevice* xmlFile) // Ask all objects to initialize and set up internal datastructure and pointers // after everything is read from file + PdmDocument::resolveReferencesTraversal(this); PdmDocument::initAfterReadTraversal(this); } @@ -215,6 +216,36 @@ void PdmDocument::updateUiIconStateRecursively(PdmObjectHandle* object) } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmDocument::resolveReferencesTraversal(PdmObjectHandle* object) +{ + if (object == NULL) return; + + std::vector fields; + object->fields(fields); + + std::vector children; + size_t fIdx; + for (fIdx = 0; fIdx < fields.size(); ++fIdx) + { + PdmFieldHandle* field = fields[fIdx]; + if (field) + { + field->childObjects(&children); + + field->resolveReferences(); + } + } + + size_t cIdx; + for (cIdx = 0; cIdx < children.size(); ++cIdx) + { + PdmDocument::resolveReferencesTraversal(children[cIdx]); + } +} + } //End of namespace caf diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmDocument.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmDocument.h index 115730ffd7..3b3bd8b10a 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmDocument.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmDocument.h @@ -63,6 +63,7 @@ class PdmDocument: public PdmObject static void updateUiIconStateRecursively(PdmObjectHandle* root); static void initAfterReadTraversal(PdmObjectHandle* root); + static void resolveReferencesTraversal(PdmObjectHandle* root); private: static void setupBeforeSaveTraversal(PdmObjectHandle * root); diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmXmlFieldCapability.inl b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmXmlFieldCapability.inl index 8955f6efd6..772c204023 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmXmlFieldCapability.inl +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmXmlFieldCapability.inl @@ -67,9 +67,9 @@ template // // and then we need a traversal of the object hierarchy to resolve all references before initAfterRead. - PdmObjectHandle* objHandle = PdmReferenceHelper::objectFromFieldReference(m_field, dataString); - m_field->setRawPtr(objHandle); - } + m_field->m_isResolved = false; + m_field->m_referenceString = dataString; +} //-------------------------------------------------------------------------------------------------- ///