PyANGKernel.GKCatalog

class GKCatalog

The catalog contains all the alive objects in the model.

Details

The catalog contains all the alive objects in the model. It organizes the objects by type and unique identifier. An unique instance of this class exists in every GKModel instance.

Objects are added to the catalog in the newObject method and they are removed when the object is deleted (in the GKObject destructor).

It is also possible to remove the object from the catalog without deleting it by calling the method remove . If the developer wants to add the object again she can use the method add .

It keeps a list of all the objects that have been removed from the catalog (dead objects). This list is accessible using the method getDeathObjects .

When an object is added to the catalog it calls the object method addedToCatalog and when the object is removed from the catalog it calls the object method removedFromCatalog .

<h2> getObjectsByType and getUsedSubTypesFromType </h2>

The most used methods are getObjectsByType and getUsedSubTypesFromType to iterate over all the instances of one class (or a class hierarchy tree) and the find method to locate an object by identifier or by name.

Use getUsedSubTypesFromType when you want to get all the instances of a class and all its subclasses and use getObjectsByType to access all the instances of only one class.

Usually the method to use will be getUsedSubTypesFromType since it is possible that new types are added to the system and that the user uses these new types instead of the old ones. For example: an algorithm writes a report in a file for all the sections (instances of GKSection ) in a network. Later on, another developer adds a new class as a subtype of GKSection (with some extra attributes) and creates new instances of these new class. The algorithm, if using the getObjectsByType method, will not report the sections that are instances of the new class. On the other hand, if the getUsedSubTypesFromType method is used, the report will include all the sections from both classes.

An example of the use of getUsedSubTypesFromType in C++ follows (it iterates over all the instances of GKSection and all classes that inherit from GKSection to generate a report):

void GKSectionReport::generate() const
{
        QFile                                                                                                   file( reportPath );
        GKSection                                                                                               *section;
        GKCatalogObjectsById::const_iterator                                    iter;
        QVector<const GKCatalogObjectsById*>                                    types;
        QVector<const GKCatalogObjectsById *>::const_iterator   iterTypes;

        types = getModel()->getCatalog().getUsedSubTypesFromType( getModel()->getType( "GKSection" ));
        if( file.open( QIODevice::ReadOnly ) ){
                QTextStream stream( &file );

                for( iterTypes = types.begin(); iterTypes != types.end(); iterTypes++ ){
                        for( iter = (*iterTypes)->begin(); iter != (*iterTypes)->end(); iter++ ){
                                section = dynamic_cast<GKSection*>( iter.value() );
                                if( section ){
                                        stream << section->getId() << "\t" << section->getName()
                                                << "\t" << section->getDataValueDoubleByID( GKSection::speedAtt ) << "\n";
                                }
                        }
                }
                file.close();
        }
}

And example in Python that prints the ID of all the section follows:

from PyANGKernel import *

model = GKSystem.getSystem().getActiveModel()
for types in model.getCatalog().getUsedSubTypesFromType( GKSystem.getSystem().getType( "GKSection" ) ):
        for key in types:
                section = types[key]
                print section.getId()

Inheritance diagram of PyANGKernel.GKCatalog

Synopsis

Methods

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

__init__()
UUIDFromId(id)
Parameters:

id – int

Return type:

QUuid

Get the UUID from a ID

add(obj)
Parameters:

objGKObject

Adds “obj” to the model catalog. Pointer is not adopted.

catalogObjectExternalId(obj)
Parameters:

objGKObject

Catalogs this object by its external ID.

clearDeathObjects()

Clears the dead objects map

find(id)
Parameters:

id – int

Return type:

GKObject

Finds an object by id. If no object is found a NULL will be returned.

find(byName[, type=None[, caseSensitive=Qt.CaseInsensitive]])
Parameters:
Return type:

GKObject

Finds an object by name (slow operation). If type is different than NULL it will just look into objects of type “type” and subclasses of type, otherwise it will look in all the objects. If name is empty then it will return NULL. If caseSensitive is Qt::CaseSensitive the search will be case sensitive.

In Python is called findByName with the same signature.

findAll(value[, attr=None])
Parameters:
Return type:

.QSetGKObject

Find all objects that contains “value” in with an attribute “attr”. If “attr” is NULL, then it look for all the attributes.

findByName(arg__1[, arg__2=None[, arg__3=Qt.CaseInsensitive]])
Parameters:
Return type:

GKObject

findObjectByExternalId(byId[, type=None])
Parameters:
  • byId – str

  • typeGKType

Return type:

GKObject

Finds an object by its external ID. If a type is specified the object of that type with that external ID will be returned. * If no type is specified, the first object found with the specified externalID will be returned

findObjectsByExternalId(byId[, type=None])
Parameters:
  • byId – str

  • typeGKType

Return type:

.list of GKObject

Finds objects with the same external ID. If more than one is present (which is not recommended) all of them will be returned.

findSetOfObjects(byName[, type=None[, caseSensitive=Qt.CaseInsensitive]])
Parameters:
Return type:

.list of GKObject

Finds all the objects by name (slow operation). If type is different than NULL it will just look into objects of type “type” and subclasses of type, otherwise it will look in all the objects. If caseSensitive is Qt::CaseSensitive the search will be case sensitive.

findSetOfObjectsByExternalId(byEid[, type=None[, caseSensitive=Qt.CaseInsensitive]])
Parameters:
Return type:

.list of GKObject

Finds all the objects by external id (slow operation). If type is different than NULL it will just look into objects of type “type” and subclasses of type, otherwise it will look in all the objects. If caseSensitive is Qt::CaseSensitive the search will be case sensitive.

getAllIds()
Return type:

.list of uint

Returns all the objects ids sorted from smaller to bigger

getAllObjectsByUUID()
Return type:

Dictionary with keys of type .QUuid and values of type GKObject.

Return all objects sorted by UUID

getDeathObjects()
Return type:

Dictionary with keys of type .QUuid and values of type GKType.

Returns the map that contains all the dead objects just before storing the network. After storing the net this info is reseted.

getDeathObjectsInRevision()
Return type:

Dictionary with keys of type .QUuid and values of type GKType.

Returns the map that contains all the dead objects. After storing the net this info is NOT reseted. When saving a revision this ingo will be stored (and restored later on) to keep the complete delete history between sessions.

getObjects()
Return type:

Dictionary with keys of type .GKType and values of type QUuid.

Returns the model catalog (organized by type)

getObjectsByType(type)
Parameters:

typeGKType

Return type:

QMap

Returns the model catalog but only for type “type”. This catalog contains then all the instances of type “type”. Note that instances of a subtype of type will not be returned.

This method will return a null pointer when no object of type “type” exists.

getObjectsByTypeWithSubTypes(type)
Parameters:

typeGKType

Return type:

.list of GKObject

Returns the model catalog including all objects from type “type” and their subtypes.

getUsedSubTypesFromType(arg__1)
Parameters:

arg__1GKType

Return type:

object

getUsedTypes()
Return type:

.list of GKType

Returns all the types with any object in the catalog

increaseTickByType(type)
Parameters:

typeGKType

Increases the tick for all the objects of type “type” and subclasses of type found in the catalog.

isTemporary(uuid)
Parameters:

uuidQUuid

Return type:

bool

Return true is the objects with this uuid is a temporary object. * UnknownCommand isTemporary

isTemporary(id)
Parameters:

id – int

Return type:

bool

Return true is the objects with this id is a temporary object. * UnknownCommand isTemporary

remove(obj)
Parameters:

objGKObject

Return type:

bool

Removes “obj” from the model catalog. Returns true if the object was in the catalog (and, thus, has been removed). The object is not deleted, just removed from the catalog.

removeDataValue(attr)
Parameters:

attrGKColumn

Removes an external attribute value from all the objects that use it.

setModel(amodel)
Parameters:

amodelGKModel

The model. Set automatically by GKModel when creating the catalog.

setStatusOfAllObjects(status)
Parameters:

statusGKObjectStatus

Changes the status of all the objects. Used after loading or saving a model (All the objects will be marked as saved).

size(type)
Parameters:

typeGKType

Return type:

int

Returns the number of objects of type “type” (or subtypes of “type”) in the catalog. If type is null then returns the total number of objects in the catalog.

uncatalogObjectExternalId(obj)
Parameters:

objGKObject

Uncatalogs this object by its external ID.