Graphical Simulation of SIGNAL programs

advertisement
Graphical Simulation of SIGNAL programs
Aims:
 To simulate graphically the execution of a SIGNAL program
 To make portable (UNIX/Windows) the simulation program. The graphical part is written in JAVA.
Principles:
You have to write everything in SIGNAL, that means:
 The creation of graphical objects (buttons, checkboxes, canvas, sliders, text areas)
 Their position
 The writing of the entries
 The showing of outputs by calling some external functions or SIGNAL processes in the library.
These processes are defined in a predefined library called libGraphics.LIB.
To use it, you have to include this library in your SIGNAL program by adding the line: "use libGraphics;"
You have no Java code to write, except if you want to complete the SIGNAL graphical library. For example,
if you add a graphical component in the SIGNAL library, or if you add a color mechanism (that would not
be useless), you will need to modify the Java code.
1. Description of the graphic library libGraphics.LIB

The creation functions of graphical components:




CreateFrame: create a frame, where all the graphics will be built (buttons, canvas).

Input parameters: the width and the height of the frame (type integer)

Output parameters: the number associated to this object (type TWindow)
The call to createFrame is obligatory; if you use the pacemaker, this call is already done.
CreatePanel: create a panel, that means a window where we can put others graphical
components, both vertically and horizontally.

Input parameters: the number of the mother window, and the direction (horizontal and
vertical). (type TWindow, type Direction)

Output parameters: The number of this object (type TWindow)
CreateBorder: create a blank area (allows to align and separate some objects)

Input parameters: the number of the mother window, the width of the area, its height (type
TWindow, type integer, type integer)

Output parameters: the number of this object (type TWindow)
CreateButton: create a button






Input parameters: the number of the mother window (type TWindow)

Output parameters: the number of this object. (type TWindow).
CreateCheckBox: create a button with a box to check.

Input parameters: the number of the mother window, its initial state (check or uncheck)
(type TWindow, type boolean)

Output parameters: the number associated to this object
CreateSlider: create a slider (or cursor)

Input parameters: the number of the mother window, the minimum value, the maximum
value, the initial value, the width, the height, the distance between 2 ticks drawn (type
TWindow, type integer, type integer, type integer, type integer, type integer, type integer,
type integer)

Output parameters: the number associated to this object
CreateLabel: create a label, that means a text area that cannot be modified.

Input parameters: the number of the mother window, (type TWindow)

Output parameters: the number associated to this object (type TWindow)
CreateCanvas: create a canvas (to draw curves or patterns)

Input parameters: the number of the mother window, the width of the canvas, its height,
(type TWindow, type integer, type integer).

Output parameters: the number associated to this object (type TWindow)
CreateTextArea: create a text area that can be modify.

Input parameters: the number of the mother window, the width of the area, its height, (type
TWindow, type integer, type integer).

Output parameters: the number associated to this object (type TWindow)

The reading functions




ReadButton:

Input parameters: the number of the button (type TWindow)

Output parameters: true if the button has been clicked, false otherwise. (type boolean)
ReadCheckBox: reading of the state of a checkbox.

Input parameters: the number of the button to be checked (type TWindow).

Output parameters: true if the button is checked, false otherwise (type boolean).
ReadSlider: reading of the value of a slider.

Input parameters: the number of the cursor (type TWindow).

Output parameters: the value of the cursor (type boolean).
The writing functions

SetTextArea: show an integer


DrawVertLine: draw a vertical line in a canvas.


Input parameters: the number of the canvas, the X-coordinate of the line to be showed, the
Y-coordinate of the start point, the Y-coordinate of the arrival point (type TWindow, type
integer, type integer, type integer)
DrawHorLine: draw a horizontal line in a canvas.


Input parameters: the number of the text area, the value to be showed (type TWindow, type
integer)
Input parameters: the number of the canvas, the X-coordinate of the start point, the Xcoordinate of the arrival point, the height (type TWindow, type integer, type integer, type
integer)
ClearCanvas: re-initialize a rectangular area in a canvas


DrawString: show an integer in a canvas


Input parameters: the number of the canvas, the value to be showed, its position en Xcoordinate, its position in Y-coordinate (type TWindow, type integer. type integer, type
integer)
FillRect: show a full rectangle in black color in a canvas


Input parameters: the number of the canvas, the X-coordinate of the start point, the Xcoordinate of the arrival point, the Y-coordinate (type TWindow, type integer, type integer,
type integer)
Input parameters: the number of the canvas, the X and Y-coordinate of the start point, the X
and Y-coordinate of the arrival point, the value to be showed (type TWindow, type integer,
type integer. type integer, type integer)
The exit function

QuitAppli: terminate the simulation
Input parameters: the activation clock (type event)

The pace-maker
Contrary to all the functions just defined that are external functions, PACE-MAKER is a process defined
in Signal, and that calls some external functions above. The principle of the pace-maker is to be able to
have 2 simulation mode:
 Automatic: the simulation is run, the user can interrupt it only by using the step by step mode.
 Step by step: This is the user who give the speed by clicking on the button "TICK" and only one loop
of calcul is done at one time.
2. Example
Here is a very small example. This is the identity case: x:=a .
I advise you to open polychrony and to load the file VTIDENTITY.sig. The explanations will be clearer.
A model manage the entries and create all of the graphical objects for the simulation. This is the
CONTEXT model; another one show the output: this is the SCREEN model.
We want to simulate this program graphically, that means to have a slider to enter the values of the entry a,
a canvas to draw the curve of x, and a pace-maker to regulate the speed of the simulation and to have a
manual and automatic mode.
This directory contains:
 VTIDENTITY.sig and VTIDENTITY.PAR: the graphical SIGNAL program and its parameters file.




VTIDENTITY_extern.c contains the external functions of the SIGNAL program, for example the
function realtoint or readclock, and 2 necessary functions: initSimu and iterateSimu that will be called
by Java during the execution . These files contain respectively a call to VTIDENTITY_initialize and to
VTIDENTITY_iterate.
All the VTIDENTITY… files are generated by the SIGNAL compiler.
Make Simu, that is the command for building the compiler. It calls Makefile_VTIDENTITY.
LibSimu.so, that is built by the call of makeSimu: this is the dynamic library that will be called by the
Java Virtual Machine during the execution, because here the code generated by the SIGNAL compiler is
C or C++. For a Java code generation, we will have no .so file.
To run the simulation, type:
java -classpath $ADRPACKAGE simuSignal.Simu &, where ADRPACKAGE is the address of the
directory that contains the simuSignal directory.
Download