2019-06-10 20:42:20 +02:00
|
|
|
#include "cafPdmObject.h"
|
|
|
|
|
|
|
|
|
|
using namespace caf;
|
|
|
|
|
|
2020-08-19 07:30:51 +02:00
|
|
|
CAF_PDM_ABSTRACT_SOURCE_INIT( PdmObject, "PdmObjectBase" );
|
2020-02-21 11:01:08 +01:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 07:53:59 +02:00
|
|
|
caf::PdmObject::PdmObject()
|
|
|
|
|
: PdmObjectHandle()
|
|
|
|
|
, PdmXmlObjectHandle( this, false )
|
|
|
|
|
, PdmUiObjectHandle( this, false )
|
2020-02-21 11:01:08 +01:00
|
|
|
{
|
2020-06-19 07:53:59 +02:00
|
|
|
CAF_PDM_InitObject( "Base PDM Object", "", "", "The Abstract Base Class for the Project Data Model" );
|
2020-02-21 11:01:08 +01:00
|
|
|
}
|
|
|
|
|
|
2019-06-10 20:42:20 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 07:53:59 +02:00
|
|
|
void PdmObject::firstAncestorOrThisFromClassKeyword( const QString& classKeyword, PdmObject*& ancestor ) const
|
2019-06-10 20:42:20 +02:00
|
|
|
{
|
|
|
|
|
ancestor = nullptr;
|
|
|
|
|
|
|
|
|
|
// Check if this matches the type
|
2020-06-19 07:53:59 +02:00
|
|
|
if ( this->inheritsClassWithKeyword( classKeyword ) )
|
2019-06-10 20:42:20 +02:00
|
|
|
{
|
2020-06-19 07:53:59 +02:00
|
|
|
ancestor = const_cast<PdmObject*>( this );
|
2019-06-10 20:42:20 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Search parents for first type match
|
|
|
|
|
|
2020-06-19 07:53:59 +02:00
|
|
|
PdmObject* parent = nullptr;
|
2019-06-10 20:42:20 +02:00
|
|
|
PdmFieldHandle* parentField = this->parentField();
|
2020-06-19 07:53:59 +02:00
|
|
|
if ( parentField ) parent = dynamic_cast<PdmObject*>( parentField->ownerObject() );
|
2019-06-10 20:42:20 +02:00
|
|
|
|
2020-06-19 07:53:59 +02:00
|
|
|
while ( parent != nullptr )
|
2019-06-10 20:42:20 +02:00
|
|
|
{
|
2020-06-19 07:53:59 +02:00
|
|
|
if ( parent->inheritsClassWithKeyword( classKeyword ) )
|
2019-06-10 20:42:20 +02:00
|
|
|
{
|
|
|
|
|
ancestor = parent;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Get next level parent
|
|
|
|
|
|
|
|
|
|
PdmFieldHandle* nextParentField = parent->parentField();
|
2020-06-19 07:53:59 +02:00
|
|
|
if ( nextParentField )
|
2019-06-10 20:42:20 +02:00
|
|
|
{
|
2020-06-19 07:53:59 +02:00
|
|
|
parent = dynamic_cast<PdmObject*>( nextParentField->ownerObject() );
|
2019-06-10 20:42:20 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
parent = nullptr;
|
|
|
|
|
}
|
2020-06-19 07:53:59 +02:00
|
|
|
}
|
2019-06-10 20:42:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 07:53:59 +02:00
|
|
|
void PdmObject::descendantsIncludingThisFromClassKeyword( const QString& classKeyword,
|
|
|
|
|
std::vector<PdmObject*>& descendants ) const
|
2019-06-10 20:42:20 +02:00
|
|
|
{
|
2020-06-19 07:53:59 +02:00
|
|
|
if ( this->inheritsClassWithKeyword( classKeyword ) )
|
2019-06-10 20:42:20 +02:00
|
|
|
{
|
2020-06-19 07:53:59 +02:00
|
|
|
descendants.push_back( const_cast<PdmObject*>( this ) );
|
2019-06-10 20:42:20 +02:00
|
|
|
}
|
|
|
|
|
|
2023-05-12 21:41:34 +02:00
|
|
|
std::vector<PdmFieldHandle*> fields = this->fields();
|
2020-06-19 07:53:59 +02:00
|
|
|
for ( auto f : fields )
|
2019-06-10 20:42:20 +02:00
|
|
|
{
|
2023-05-12 21:41:34 +02:00
|
|
|
std::vector<PdmObjectHandle*> fieldChildren = f->children();
|
|
|
|
|
for ( auto child : fieldChildren )
|
2019-06-10 20:42:20 +02:00
|
|
|
{
|
2023-05-12 21:41:34 +02:00
|
|
|
PdmObject* pdmObjectChild = dynamic_cast<PdmObject*>( child );
|
2020-06-19 07:53:59 +02:00
|
|
|
if ( pdmObjectChild )
|
2019-06-10 20:42:20 +02:00
|
|
|
{
|
2020-06-19 07:53:59 +02:00
|
|
|
pdmObjectChild->descendantsIncludingThisFromClassKeyword( classKeyword, descendants );
|
2019-06-10 20:42:20 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-19 07:53:59 +02:00
|
|
|
}
|
2019-06-10 20:42:20 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 07:53:59 +02:00
|
|
|
void PdmObject::childrenFromClassKeyword( const QString& classKeyword, std::vector<PdmObject*>& children ) const
|
2019-06-10 20:42:20 +02:00
|
|
|
{
|
2023-05-12 21:41:34 +02:00
|
|
|
std::vector<PdmFieldHandle*> fields = this->fields();
|
2020-06-19 07:53:59 +02:00
|
|
|
for ( auto f : fields )
|
2019-06-10 20:42:20 +02:00
|
|
|
{
|
2023-05-12 21:41:34 +02:00
|
|
|
std::vector<PdmObjectHandle*> childObjects = f->children();
|
2020-06-19 07:53:59 +02:00
|
|
|
for ( auto childObject : childObjects )
|
2019-06-10 20:42:20 +02:00
|
|
|
{
|
2020-06-19 07:53:59 +02:00
|
|
|
PdmObject* pdmObjectChild = dynamic_cast<PdmObject*>( childObject );
|
|
|
|
|
if ( pdmObjectChild && pdmObjectChild->matchesClassKeyword( classKeyword ) )
|
2019-06-10 20:42:20 +02:00
|
|
|
{
|
2020-06-19 07:53:59 +02:00
|
|
|
children.push_back( pdmObjectChild );
|
2019-06-10 20:42:20 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|