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
GKModelinstance.Objects are added to the catalog in the
newObjectmethod and they are removed when the object is deleted (in theGKObjectdestructor).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 methodadd.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
addedToCatalogand when the object is removed from the catalog it calls the object methodremovedFromCatalog.<h2>
getObjectsByTypeandgetUsedSubTypesFromType</h2>The most used methods are
getObjectsByTypeandgetUsedSubTypesFromTypeto iterate over all the instances of one class (or a class hierarchy tree) and thefindmethod to locate an object by identifier or by name.Use
getUsedSubTypesFromTypewhen you want to get all the instances of a class and all its subclasses and usegetObjectsByTypeto access all the instances of only one class.Usually the method to use will be
getUsedSubTypesFromTypesince 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 ofGKSection) in a network. Later on, another developer adds a new class as a subtype ofGKSection(with some extra attributes) and creates new instances of these new class. The algorithm, if using thegetObjectsByTypemethod, will not report the sections that are instances of the new class. On the other hand, if thegetUsedSubTypesFromTypemethod is used, the report will include all the sections from both classes.An example of the use of
getUsedSubTypesFromTypein C++ follows (it iterates over all the instances ofGKSectionand all classes that inherit fromGKSectionto 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()
Synopsis¶
Methods¶
def
__init__()def
UUIDFromId()def
add()def
find()def
findAll()def
findByName()def
getAllIds()def
getObjects()def
getUsedTypes()def
isTemporary()def
remove()def
setModel()def
size()
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__()¶
Get the UUID from a ID
Adds “obj” to the model catalog. Pointer is not adopted.
Catalogs this object by its external ID.
- clearDeathObjects()¶
Clears the dead objects map
Finds an object by id. If no object is found a NULL will be returned.
- find(byName[, type=None[, caseSensitive=Qt.CaseInsensitive]])
- Parameters:
byName – str
type –
GKTypecaseSensitive –
CaseSensitivity
- Return type:
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
findByNamewith the same signature.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:
arg__1 – str
arg__2 –
GKTypearg__3 –
CaseSensitivity
- Return type:
- findObjectByExternalId(byId[, type=None])¶
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])¶
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:
byName – str
type –
GKTypecaseSensitive –
CaseSensitivity
- 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:
byEid – str
type –
GKTypecaseSensitive –
CaseSensitivity
- 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)
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.
See also
Returns the model catalog including all objects from type “type” and their subtypes.
See also
Returns all the types with any object in the catalog
Increases the tick for all the objects of type “type” and subclasses of type found in the catalog.
Return true is the objects with this uuid is a temporary object. * UnknownCommand
isTemporary- isTemporary(id)
- Parameters:
id – int
- Return type:
Return true is the objects with this id is a temporary object. * UnknownCommand
isTemporaryRemoves “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.
Removes an external attribute value from all the objects that use it.
The model. Set automatically by
GKModelwhen creating the catalog.- setStatusOfAllObjects(status)¶
- Parameters:
status –
GKObjectStatus
Changes the status of all the objects. Used after loading or saving a model (All the objects will be marked as saved).
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.
Uncatalogs this object by its external ID.