PyANGKernel.GKFolder

class GKFolder

An unsorted list of objects and folders.

Details

GKFolder is a list of objects ( GKObject ) or folders ( GKFolder ) contained in an object ( GKObject ). Every GKObject can contain a folder, called the root folder. This root folder can contain objects and folders (that can contain objects and folder, and so on).

Folders must be registered in the system before using it. See registerFolder

Object folders allow the developer to include information to an object without modifying it. They are similar to the GKColumn and GKType mechanism (called Extensible Object Model) but unrelated (the getDataValue and setDataValue operations cannot be applied to these folders).

The main advantage is that the GUI class GListViewForModel can list in a browser the content of the GKModel folders and that these contents can be modified at run time. This allows us the addition of non-graphical object to the model (in one of GKModel ‘s folder) that will be graphically represented (as items in the GListViewForModel widget). This representation will allow the user the selection and manipulation of these objects (double click to open its editor or using the context menu to issue commands).

A GKFolder has a name (GKFolder::getName) and an internal name ( getInternalName ). The internal name identifies the folder uniquely among all the other folders in the system. It’s up to the developer to give a unique name to the folder.

Each folder has a root (the object owner of the folder) if it is not a subfolder. If it is a subfolder then the root is a folder and the final object owner can be read using the getAbsoluteRoot method.

In order to create a folder in an object that is not a folder, use the following code:

folder = GKSystem::getSystem().createFolder( object->getCreateRootFolder(), "Internal Name" );

The method getCreateRootFolder returns the root folder for the object. Since a root folder is optional, maybe the root folder has not been created yet, so instead of using the getRootFolder method that can return NULL, we use the getCreateRootFolder method that will create the root folder if needed.

And in order to create a folder in a folder, use the following code:

subfolder = GKSystem::getSystem().createFolder( folder, "Internal Name" );

Where, in both examples: - External Name: is the name of the folder that will be presented to the user. - Internal Name: is the internal name of the folder that have to be unique.

Note that GKFolder inherits from GKObject . A folder contains a list of GKObject and some of these will be GKFolder ; in order to determinate if they are folder or non folders, use the following code:

GKFolderContents::const_iterator            iter;

    for( iter = folder->getContents().begin(); iter != folder->getContents().end(); iter++ ){
            if( dynamic_cast<GKFolder*>( obj ) ){
                    // It's a folder
                    ...
            }else{
                    // It isn't a folder
                    ...
            }
    }

The developer must create the folder before inserting any object. The folder to be created depends of the object to be inserted. Check the class documentation for the folder external and internal name.

For example, to add a new centroid configuration:

folder = model->findFolder( "GKModel::centroidsConf" );
if( folder == nullptr ){
        folder = GKSystem::getSystem().createFolder( model->getCreateRootFolder(), "GKModel::centroidsConf" );
}

or, in Python:

folder = model.findFolder( "GKModel::centroidsConf" )
if folder == None:
        folder = GKSystem.getSystem().createFolder( model.getCreateRootFolder(), "GKModel::centroidsConf" )

Inheritance diagram of PyANGKernel.GKFolder

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__()
__getitem__()
Return type:

object

__iter__()
Return type:

object

__len__()
append(obj)
Parameters:

objGKObject

Adds an object to this folder

canBeRenamed()
Return type:

bool

Returns true if the name of this folder can be renamed (true by default)

clear()

Clears the folder (objects inside the folder are not deleted just removed from the folder).

contains(obj)
Parameters:

objGKObject

Return type:

bool

Returns true if obj is in this folder.

createFolder(aname, ainternalName[, showOnlyConts=false[, temporary=false]])
Parameters:
  • aname – str

  • ainternalName – str

  • showOnlyConts – bool

  • temporary – bool

Return type:

GKFolder

Creates a subfolder. First it checks if the folder is already here (using the internalName) and if so a pointer to the already existing folder is returned, if not a new one is created.

deepClear()

Clears the folder and deletes all the objects inside.

deepCopyOnStoreCopy()
Return type:

bool

In a clone operation if true the objects in this folder will be cloned and if false the contents of this folder and the contents of the original folder will be the same. False by default.

duplicateObjectName(object)
Parameters:

objectGKObject

Return type:

str

Finds the best possible duplicate object name, considering the folder’s contents * with the format “<object_name> - copy” or “<object_name> - copy(x)” for x > 2.

findBestFolderForObject(obj)
Parameters:

objGKObject

Return type:

GKFolder

Find any folder inside this folder to hold the object that may be better than the root one, * considering the object types that each folder can hold.

getAbsoluteRoot()
Return type:

GKObject

Returns the first non folder object that is a root: if the root is not a folder it will return the root. If the root is a folder it will return the getAbsoluteRoot of this folder.

getContents()
Return type:

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

Gets the content of the folder: a list with objects (including also subfolders).

getContentsTypes([staticOn=true[, mesoOn=true[, microOn=true[, travelDemand=true]]]])
Parameters:
  • staticOn – bool

  • mesoOn – bool

  • microOn – bool

  • travelDemand – bool

Return type:

.list of GKType

Returns the types of objects that this folder can contain. Since this information is optional an empty vector can be returned.

Use registerFolder to set this information.

getInternalName()
Return type:

str

Gets the internal folder name

getProblemNet()
Return type:

GKProblemNet

Search recursively in parent objects a ProblemNet. * Returns a ProblemNet if the object is in a ProblemNet, return NULL otherwise.

getRoot()
Return type:

GKObject

Gets the root of this folder: a folder if it is a subfolder or an object it is a root folder.

remove(obj)
Parameters:

objGKObject

Removes an object from this folder

setCanBeRenamed(status)
Parameters:

status – bool

Set to true if the name of this folder can be renamed (true by default)

See also

canBeRenamed()

setDeepCopyOnStoreCopy(value)
Parameters:

value – bool

In a clone operation if true the objects in this folder will be cloned and if false the contents of this folder and the contents of the original folder will be the same. False by default.

setDeepCopyOnStoreCopyRecursively(value)
Parameters:

value – bool

As setDeepCopyOnStoreCopy but it will call also setDeepCopyOnStoreCopy for each folder inside this folder (reursively).

setInternalName(iname)
Parameters:

iname – str

Sets the internal (and unique) folder name.

setRoot(aroot)
Parameters:

arootGKObject

Sets the root of this folder. It is done automatically by createFolder

setShowOnlyContents(value)
Parameters:

value – bool

If true, when listing this folder in the GListViewForModel widget only its contents will appear and not the list itself and the contents as children of the folder. False by default.

showOnlyContents()
Return type:

bool

If true, when listing this folder in the GListViewForModel widget only its contents will appear and not the list itself and the contents as children of the folder. False by default.