PyANGKernel.GKObjectDelCmd¶
- class GKObjectDelCmd¶
Base class for commands generates when an object is deleted.
Details
When an object is deleted (either directly due to the user interaction or due to a cascade delete) Aimsun asks for a
GKObjectDelCmdto delete it with undo support calling the methodgetDelCmd.A delete command has the following responsibilities: - Remove the object from the catalog. - Remove the object from the geo model (if it is a graphical object). - Remove the object from the folder where lives (if any). - Remove the object from any other object that have a reference to it.
And logically, since a command must support the undo operation, revert all the previous operations.
Aimsun already implements some operations in this class: - Removes the object from the catalog. - Removes the object from the geo model (if it is a
GKGeoObject). - Removes any connection to this object (if it has connections). - Removes any top object (seeGKGeoObject). - Removes it from its folder (if the folder is set by the user).Create a new class if you need to remove (and restore) references to objects that are not folders, top objects or are connected and support the
getDelConnectionCmdmethod.<H2>Writing a delete command </H2>
If the implementation in
GKObjectDelCmdis not enough the developer can subclass it to write a more suitable command. When doing so the new class must: - If rewritesinitit has to call it in the new init method as the first line of code. - Call GKObjectDelCmd::doit as the last method called in the new doit method. - Call GKObjectDelCmd::undoit as the first method called in the new doit method.<H2>Deleting an object with the C++ delete operator </H2>
When an object is deleted using a command it is not deleted from memory (using the delete operation). It is removed from the system so it is no longer accessible for any, non deleted, object. And it is not deleted because is possible that the user undo it so the object will be add again to the system.
So, when will this object be really deleted? It will when the command is deleted by the
GKCommander. The commander deleted a command or when no longer the undo operation is possible or when the model is closed.But a command can be in one of these two states: done or undone. If the command was ‘done’, this means that the object was deleted so the destructor of the command has to delete it. If the command was ‘undone’ means that the command was undone, that is, the object was deleted and restored so the destructor of the command do not has to delete it.
This class already implements this functionality as follow:
GKObjectDelCmd::~GKObjectDelCmd() { if( obj && isDone() ){ delete obj; } }
<h2>Cascade Delete</h2> The
getDelCmdmethod can be used to implement cascade deletes, that is: delete an object requires that this object deletes other objects.For example: a
GKSectionuses a collection ofGKTurning. A turn cannot exist without its section so, when the section is deleted all the turns that this section uses must be deleted. On the other hand, a turn is aGKObjectthat implements its own delete command (a turn can be deleted without deleting the section or any other object).The delete command in
GKSectioncan use the delete commands in the turns to simplify the coding:bool GKSection::init( GKObject * aobject ) { ... section = dynamic_cast<GKSection*>(aobject); const GKConnections turnsTo = section->getOrigin()->getToTurnings( section ); for( iterT = turnsTo.begin(); iterT != turnsTo.end(); iterT++ ){ turnDel = (*iterT)->getDelCmd(); if( turnDel ){ turnings.push_back( turnDel ); } } ... }
And then, in the doit methods, call the doit for these turn commands:
void GKSection::doit() { QValueVector<GKObjectDelCmd*>::iterator iterT; ... for( iterT = turnings.begin(); iterT != turnings.end(); iterT++ ){ (*iterT)->doit(); } ... }
And, finally, we will undo the commands:
void GKSection::undoit() { QValueVector<GKObjectDelCmd*>::iterator iterT; ... for( iterT = turnings.begin(); iterT != turnings.end(); iterT++ ){ (*iterT)->undoit(); } ... }
See also
Inherited by:
GKTurningDelCmd,GKScriptDelCmd,GKPathAssignmentPlanDelCmd,GKPathAssignmentDelCmd,GKGroupingTypeDelCmdSynopsis¶
Methods¶
def
__init__()def
getObject()def
setFolder()
Virtual 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__()¶
- addMoveConnection(newObject)¶
- Parameters:
newObject –
GKGeoObject- Return type:
This command moves connections (if any) from the deleted object to a new one. Call this method after
init. By default this command removes the connections. If this call is made, the connections will be moved instead of being deleted.Gets the object to delete as set in
init.- getTopObjectsToDel()¶
- Return type:
.list of GKObjectDelCmd
Generated del commands for the top objects of the deleted object
This command removes this object from a folder. Call this method after
init.