7. The ATOM3 class
The ATOM3 class implements the AToM3
Kernel. It is the file you have to invoke when loading AToM3
from the command line. From the command line AToM3 accepts as
a parameter the name of the meta-model which should be loaded. If no meta-model
is specified, the it will look in the default options which, by the way,
are stored in file myOptions.py. These
are the main attributes this class contains:
Figure 1: Main attributes of the ATOM3 class
The attributes' meaning is as follows:
editGGLabel: A flag whose value is ASG.LHS if this instance of the
class is indeed being used to edit a LHS of a graph grammar rule, or
if it is used to edit a RHS, or 0 if none of the two previous things happen.
ASGroot: An object of a child class of ASG,
which contains the model the user is building.
userActionsMap: A dictionary which contains a mapping between user actions
(represented as strings, the dictionary's keys) and functions. Each button
in the user interface has associated a mode, and an attribute called mode
is set to the corresponding mode, then when the user clicks on the canvas,
the userActionsMap dictionary is fetched to call the appropriate
method. These are the modes which are always present in ATOM3 (the Mode
column represent the attribute name, whose value is a string with that
||The user didn't press any button
||The user pressed the "Edit Entity" button.
||The user pressed the "connect" button.
||The user pressed the "Expand model" button.
||The user pressed the "Insert model" button.
||The user pressed the "Delete" button.
||The user is requested by the graph grammar execution controls to select
one of the highlighted subgraphs (a rule is applicable in several places).
||The user pressed the "Smooth" button.
||The user pressed the "Delete point" button.
||The user pressed the "Insert point" button.
Table 1: ATOM3 predefined modes
||The user pressed the "Change connector" button.
Whenever a meta-model is loaded, it extends the predefined modes, as
well as the userActionsMap dictionary with the new actions it provides.
The following figure contains the most important methods of the ATOM3
types: A dictionary with the types available in the current session. You
can see the available types (as well as define new ones) clicking on Model|edit
types. When a meta-model is loaded, it initializes this dictionary
with the types that will be available when using that formalism (including
user defined types necessary for that formalism). In fact, what happens
is that the formalism fills a list of ATOM3TypeInfo
objects, and the the ATOM3 method fillDictionaryWithTypes puts this
list into the dictionary. The keys of the dictionary are the type names,
and the value is a tuple, with the first paramter a pointer to the class,
and next the type's mandatory parameters.
modes: a dictionary indexed by the Tkinter Button objects, which
has as value the mode in which AToM3 will enter if that button
is pressed. This dictionary has only the modes for modes defined in a meta-models.
This is necessary as the Buttons and the methods to execute are created
"on the fly".
ConnectivityMap: A dictionary which helps ATOM3 how to connect the objects
the user is drawing in the canvas. With this information the kernel is
able to know when to connect two objects directly or when it has to put
an intermediate connection. It is a dictionary which is generated automatically
and is indexed by the objects class names (a string), as values have other
dictionary with all the objects the key's object can be connected to. The
entries of this inner dictionary are a list of tuples, which, in the case
that an intermediary object has to be created when connection the objects,
indicate which method to call to create it. Better have a look at some
generated file, such as ERmetaMetaModel_MM.py.
CardinalityTable: A dictionary which contains the cardinalities of each
allowed connection in the formalism. It is indexed by the allowed object's
name, and as values it has a dictionary, whose keys are again object's
names, and their values are lists with tuples that have the cardinality
information. Again, have a look at some file generated from a meta-model,
such as ERmetaMetaModel_MM.py
UMLmodel: the Tkinter Canvas object where the user draws the models.
fromClass: A string which is filled when the user connects two entities.
It contains the class' name of the source object.
toClass: A string which is filled when the user connects two entities.
It contains the class' name of the destination object.
sem_objFrom: This attribute is filled when the user connects two entities.
It contains a pointer to the source object.
sem_objTo: This attribute is filled when the user connects two entities.
It contains a pointer to the destination object.
Figure 2: Main methods of the ATOM3 class
The meaning of these methods is as follows:
configureUserActions: Fills the userActionsMap dictionary with the common
actions for all formalisms.
editclass: Edits the nearest class that can be found in the canvas, executing
pre and post conditions appropriately.
createMenu: creates the menu.
loadGUImodel: Loads a model of the GUI in the 'Buttons' formalism.
Returns a ASG_Buttons class with the model.
openMetaModel: Opens a meta-model, adding the information to the previous
ones (if merge == 1). If GUIModel is None, then opens a dialog
box to ask for the name. GUIModel is the name of the GUI model (in
the 'Buttons' formalism) to be opened previous to the meta-model.
loadTrans: Loads a transformation for editing. In the future, this must
be the same as opening a model.
executeTrans: loads a list of executable Graph Grammar (children of the
class) and executes it on the current model.
connectClass: Finds the closest class and if this is the second time this
function is called, performs the actual connection to the previously selected
one. It may be necessary to add an intermediate object.
showConnection: Connects graphically two entities of the model. Checks
if graphical objects have connectors and if an intermediate object has
to bee created.
drawConnections: Performs connections with the information given by an
arbitrary number of tuples (listOfConnections parameter). The tuples'
format can be:
Size 2 and then it means (sem_objFrom, sem_objTo) and connecting respective
Size 4 and then it means (fromClass, toClass, sem_objFrom, sem_objTo)
checkCardinalities: Before connecting objects objFrom and objTo,
check if the connection is valid. If it is valid, it returns None,
if invalid, returns a tuple with the error. The 1st component of the tuple
is the error message, the second one is the actual object (to be highlighted).
drawConnection: Connects two entities of the model, whether they are given
as graphical entities (and then self.fromClass and self.toClass
must have a value) or just semantically, (and then self.sem_objFrom
and self.sem_objTo must have a value). This method is iteratively
invoked in drawConnections with the contents of each tuple wich is passed
in the parameter listOfConnections.
find_visible_closest: Returns the closest item to (x, y) which is
visible in canvas. If the item has 4 or more coordinates, then the
distance of (x,y) to the segments defined by each 4 consecutives coordinates
(x1, y1) (x2, y2) are calculated.
loadTypes: Adds the components of the 2nd paramater into self.typeList,
wrapping them into an ATOM3TypeInfo
and loads them in the types dictionary. listOfNewTypes is a list
of tuples: ( 'user-friendly name', 'class name', tuple-with-parameters,
genASGCode: Generates Python code for the ASGroot attribute (an object
of a class inheriting from ASG).
genASGNodeCode: Generates Python code (in file f) for an object
(UMLobject) of a class that inherits from ASGNode.
may contain a list with the objects with cardinality constraints
genButtons: generates the file which has the actions to create the defined
entities. This file has the same name as the keyword of the mode, but ending
Maintained by Juan de Lara.
Last modified 25 July 2002.