Files
ResInsight/Fwk/AppFwk/cafProjectDataModel/cafPdmObject.cpp

104 lines
3.5 KiB
C++
Raw Normal View History

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