Figure 3: Specifying a Python Constraint in AToM3
The "Constraint name" field is mandatory and is the name of the constraint.
If Python code is generated later, a method will be created with this name.
The left-most radio buttons permit to select the language in which the
constraint or action is to be specified. In the current version of AToM3
only Python can be used, future versions will allow also to use OCL. The
next column of radio buttons are used to specify whether the code should
be evaluated before (PREcondition) or after (POSTcondition)
the event(s). The multiple-selection list on the right is used to specify
the event(s) in which the code should be evaluated. These are the events
that AToM3 handles:
|
|
|
EDIT | Semantic | The entity is clicked to be edited. |
SAVE | Semantic | The model is being saved. |
CREATE | Semantic | The entity is being created. |
CONNECT | Semantic | Two entities are being connected, both entities will receive the event* |
DELETE | Semantic | The entity is being deleted. |
DISCONNECT | Semantic | Two entities are being disconnected. |
TRANSFORM | Semantic | The model is being transformed. |
SELECT | Graphical | An entity is being Selected |
DRAG | Graphical | Beginning of a DRAG operation |
DROP | Graphical | End of a DRAG operation |
MOVE | Graphical | An object is being moved |
(*) Note that if two entities are being connected and an intermediate one has to be created, then:
The text area is used to write the Python code to be evaluated when the event(s) occurs. In the current version of AToM3 , no syntactical checking is performed, future versions will. As arbitary Python code can be specified here, lateral effects are allowed; if this is the case we call this an Action, as opossed to Constraints, which usually do not have lateral effects. Other important difference between Actions and Constraints is that the latter return a value. The value can be None, meaning that the Constraint has been satisfied, or a 2-valued tuple, meaning that the constraint has not been satisfied. If this is the case, and the constraint is a PREcondition, then the event is not executed, if the constraint is a POSTcondition, then the event is undone. The two-value tuple a constraint can return is composed of a string with the message to be shown in a dialog window, and a pointer to the object which originates the error. If the constraint is a local constraint, then this value will typically be self, which points to the current entity (a child of an ASGNode). If the constraint is global, self points to the graph object, child of ASG, so you will have to return the pointer to the object which caused the error (or None).This value is used to highlight the object when presenting the dialog window with the error. If the second value is set to None, then no highlighting is performed.
When code is generated for this model, a method called "lessThan1000" is created, this method has the following signature:
def lessThan1000(self, params):Where params is a list, which is usually empty, except for the case of the "CONNECT" event, in which the source object receives a "SOURCE" string and the destination objects receives a "DESTINATION" string.
Constraints imposed on graphical forms will be explained in section: AToM3 Graphics.