4. AToM3 Graphics
In AToM3 there are two kinds of graphics the user can assign
to an AToM3 object: icons and links. The first ones inherit
from
graphEntity while
the second ones inherit from graphLink.
Both graphEntity and graphLink classes inherit from VisualObj.
4.1 VisualObj
The important attributes and methods from VisualObj
are the following:
Figure 1: Structure of class VisualObj, base class of all graphical
objects.
The attributes have the following meaning:
-
x,y : are the coordinates of the upper-left most coordinate of any graphical
form drawn.
-
tag: is a string which uniquely identifies the object, and that is added
to all the graphical forms composing the object, using the appropriate
Tkinter methods.
-
Tag2ObjMap: is a dictionary which maps tags to object instances.
-
connections: is a list of tuples (handler, #order) where #order is 0 o
1 depending on the connection order.
-
attr_display: dictionary that has the semantic attributes to be displayed.
-
dc: canvas where the object is to be drawn.
The methods have the following meaning:
-
DrawObject: Abstract method, to draw the object in canvas.
-
Move: Abstract method to move the object in the canvas.
-
getConnectionCoordinates: Gets the coordinates of the connection that joins
this object and 'obj', the connection has the direction given by
'direction' which is the string 'IN' or 'OUT'. number is
the connection number as it is possible to have several connections between
the same objects.
-
drawGGLabel: Draws the Graph Grammar label that the semantic object has.
-
destroy: The graphical appearance of the object is going to be destroyed,
so we must store its description. Particularly, we will store the description
of input and output segments
4.2 graphEntity
This is the base class of all icon-like graphical objects. This objects
are created at the meta-level, using a graphical editor (class appearanceEditor
in file appearanceDialog.py).
Figure 2: Structure of class graphEntity, base class of all
icon-like graphical objects.
The attributes have the following meaning:
-
center: is a tuple with the coordinates of the center of the object.
-
connectors: list with the handlers of the object connectors.
-
graphForms: list of graphical forms. These are objects of type GraphicalForm,
which basically wrap Tkinter Canvas graphical objects. All basic graphical
forms which compose a graphical object are embedded in a GraphicalForm,
except connectors. GraphicalForm objects are explained in the next
subsection.
The methods have the following meaning:
-
Move: Implements the VisualObj abstract method Move.
-
HighLight: Highlights (flag = 1) or LowLights (flag = 0) all the VISIBLE
elements with the 'selected' tag.
-
connect: Connects this object with another object of type 'graphLink'.
The connection may have intermediate points, stored in the list intermediatePoints.
-
erase: It is used to delete the graphical Object. atom3i is an instance
of the ATOM3 class.
-
redrawObject: The canvas in which this object was drawn has been closed,
and now it is requested to this object to draw itself again.
-
getbbox: gets the bounding box of this object
At the meta-level, you can assign a graphEntity to an AToM3 object by declaring
an attribute of type ATOM3Appearance.
4.3 GraphicalForm
Each object you draw in the graphical editor (except connectors) is indeed
a GraphicalForm object.
The following figure shows its main attributes and methods:
Figure 3: Structure of class GraphicalForm, wrapper for all
Tkinter canvas objects in AToM3.
The meaning of the attributes is the following:
-
handler: The Tkinter handler associated with this graphical form.
-
canvas: The Tkinter Canvas where this object is beind drawn.
-
name: The name associated with this graphical form. An attribute name like
this will be created in the graphical objects where this form is placed.
-
elementType: A string with the element type ("line", "rectangle", ...)
as returned by Tkinter method type.
-
hidden: An integer with value 1 if the form is invisible, 0 if it is visible.
The meaning of the methods is the following:
-
setCoords: Sets the coordinates of the form, coords is a list with
the coordinates.
-
getCoords: Returns a list with the form's coordinates.
-
setFill: Sets the color of the form, color is a string. It is responsibility
of the user to ensure that the current form has the option fill.
-
setSmooth: Sets the smooth property to the value given by flag.
-
setColor: sets the color of the shape (either the fill or the outline
property). color is a string.
-
HighLight: Highlights (flag = 1) or LowLights (flag = 0) the element if
it is not hidden.
-
setVisible: If switch is different from None, it makes the
form visible, otherwise, it makes it invisible
These objects are widely used if you want to change the object's graphical
appearance at run time (in the code of some Constraint
or Action). All you have to do is to access the graphical object's
attribute associated with the graphical form and call some of the previous
methods. An example of this is given in section 4.5
, although of course, you can also change the appearance of a graphical
form in semantic constraints.
4.4 graphLink
This is the base class for all link-type graphical objects, which usually
are meant to connect two other graphical objects. The objects they connect
can be icon-like or link-like objects. Visually a graphLink is compose
of incoming links, a center (of type graphEntity, which may be None),
and outgoing links. Links can have several points and may be smoothed.
Links can have an arrow or graphEntity object at the end, and also in the
middle. The structure of the graphLink class is shown in the following
picture:
Figure 4: Structure of class graphLink.
The meaning of the attributes is as follows:
-
selectedHandler : Tuple of the handler of the selected in/out segments,
or graphLink.NOTHING_SELECTED if nothing is selected or graphLink.CENTER_SELECTED
if the center is selected or graphLink.ALL_SELECTED if all is selected.
-
selectedPoint : If a multi-point connection is selected, this contains
the number of the point which is selected.
-
in_connections_ : List of tuples of three elements (handler, tag, segmentObject,
linkObject), where handler is the handler of the incoming
segment line, tag is its tag, segmentObject is a pointer
to the segment drawing and linkObject (or None) is a pointer to
the link drawing (or None).
-
out_connections_ : Same thing for outgoing connections.
-
unconnected: List of unconnected segments. Tuples (handler, tag, segmentObject,
linkObject).
-
semanticObject: Link to the ASGNode with the semantic information.
Icon-like objects also define this attribute in the subclasses of graphEntity.
The meaning of the methods is the following:
-
DrawObject: Draws the link in the canvas 'canvas'. If showGG
is 1, then the graph grammar label is shown.
-
Move: Moves the link and its central part if it is present. Also moves
links if they are unconnected. Moves an end of the links if connected.
-
HighLight: Highlights (flag = 1) or LowLights (flag = 0) all the selected
elements self.selectedHandler stores a tuple with the handlers of
the selected in/out segments, or graphLink.CENTER_SELECTED or graphLink.ALL_SELECTED.
-
connect: Connects this object to 'obj', where obj must be a child of VisualObject.
intermediatePoints
is a list of intermediate points between origin and destination. The function
returns the handler of the connection. The Parameters sre:
-
obj : the object to connect to.
-
px0, py0 : If present, point where the first connection (IN) should
begin.
-
px1, py1 : If present, point where the first connection should
end (if obj is of type graphEntity) or where the OUT connection must begin
if obj is of type graphLink.
-
smoothConn : Flag that indicates if the connection should be smoothed
-
numPoints1stConn : Number of points of the 1st connection (only
useful if obj is of type graphLink). It should be grater or equal than
2.
-
getSegment: returns an unconnected input or output segment or creates a
new one if there's no unconnected.
-
whichDirection is a string with values "IN" or "OUT".
-
The function returns a tuple (handler, tag, segmentObject, linkObject).
-
removeConnection: Removes the (input or output) connection whose handler
is 'handler'. If this is a 1:1 connection, then removes the whole connection
(and not just the incoming or outgoing segment). Returns:
-
-1 if handler is not a connection.
-
0 if handler corresponds to an output segment
-
1 if handler corresponds to an input segment
-
2 if the whole connection has been removed
-
select: Selects the point of the link (if it is a multi-point link) or
center part corresponding to tag.
-
smooth: Smooths a connection segment
-
deletePointFromConnection: Selects the point of the link (if it is a multi-point
link) nearest to x, y and deletes it.
-
insertIntermediatePoint: Inserts the point x,y in the connection given
by handler.
-
changeConnector: Changes a connection (the given by the handler hconnection)
to a new connector (the given by handler hnewConnector).
-
erase: It is used to delete the graphical Object. atom3i is an instance
of the ATOM3 class.
-
redrawObject: The canvas in which this object was drawn before was closed,
and now it is requested to this object to draw itself again...
-
preCondition: calls the preCondition function in all the graphEntity
children objects which compose this graphLink.
-
postCondition: calls the postCondition function in all the graphEntity
children objects which compose this graphLink.
At the meta-level, you can assign a graphLink to an AToM3 object by declaring
an attribute of type ATOM3Link
4.5 Example
Following with the previous example,
suppose you assign the following appearance to the entity you have just
created:
Figure 5: Creating an appearance icon
Suppose you have set the following Python action (by clicking on Set
Constraint|new):
number=self.semanticObject.aNumber.getValue()
# get the aNumber attribute value from the semantic object
if number > 500:
self.gf0.setFill("red")
# set the rectangle's inside to red if value's greater than 500
else:
self.gf0.setFill("green")
# set the rectangle's inside to green if value's less than 500
and that you have named this action as changeColor. This code is
an action because we are not returning any value. As we intend to change
the rectangle's inside from red to green depending on the value of aNumber,
we have to evaluate the code after the entity has been edited or created,
so we set this code as a POSTCondition on EDIT and CREATE.
When clicking in the OK button, a class named graph_aTest.py
is generated. As in the Entity Relationship Meta-Model, the Entity
objects have an ATOM3Appearance attribute, the graph_aTest class
inherits from graphEntity. Note how a method called DrawObject is
created which contains the necessary Python code to draw the object in
the canvas and a method called changeColor has been created for
the action we have defined. Methods postCondition and preCondition
have also been created, but as in our case, we only have post-conditions,
only the first method has some code.
Maintained by Juan de Lara.
Last modified 22 July 2002.