Satimage Previous | Next
The object model
Home Documentation Smile Smile Tutorial Write a data visualization script The object model  
The object model

Each component of SmileLab (for instance a window, a menu item, a curve) is an object that a script can address at any moment to change its properties or its behavior.

Each object owns properties, such as defined in SmileLab's dictionary - that you open in the Smile menu - and a script - possibly empty - to attach to the object routines that SmileLab will call when some specific even occurs, for instance when the user selects an item in a menu, or clicks in a graph. Objects just created have properties and behaviors set to default values, that you can then change by script.

Some objects are a container for other objects, for instance a graphic window may contain a 2D plot view (the object which handles the axes, labels, etc) which in turn may contain curves.

The window's size is a property of the window, the coordinates system is a property of the view, and the numerical data or the curve's color are properties of the curve. Graphic windows support several kinds of views, for instance 3D views, able of containing surfaces or 3D objects.

Referring to objects
To handle an object by script, you use a variable which refers to the object. For instance the following line stores in the w variable a reference to the new window.
set w to make new graphic window
-- graphic window id 4
Now you can use that reference to read or change any property of the window. Here we change the window's drawing frame (the white rectangle in the window).
set pageheight of w to 200
draw w
Getting a reference to an objet
There are several ways to provide a reference to an object in Smile.
  • usually, you just store in a variable the reference which was returned when the object was created.
    set w to make new graphic window
    set v to make new plot view at w
    set c to make new curve at v
    set c's formula to "cos(x)"
    draw w


    Import script
    Note that the example uses the reference to the newly created curve, c, to assign a value (a string) to its formula property - this is how you have a curve represent a function. draw w is for refreshing the window (for optimal speed, SmileLab refreshes a graphical window only when you allow it to).
    As long as the window - and the objects it contains - exist, we can for instance change the axes' limits as in the lines below.
    set limits of v to {-2 * pi, 2 * pi, -1, 1}
    draw w
  • from the reference to an object you can derive references to objects related to it: those which contains it, and those that it contains.

    The properties container and window of a given object contain references, respectively, to the object which contains it and to the window where the object is installed. For instance, the following expressions all refer to the same object, the graphic window.

    w, container of v, window of v, container of container of c, window of container of c, window of c

    To address an object contained in a given object, use the description by index like in the script below.

  -- prepare the view for curves
set w to make new graphic window
set v to make new plot view at w
set limits of v to {0, 5, "auto", "auto"}

  -- make the curves
make new curve at v with properties {formula: "sin(x*cos(x))"}
make new curve at v with properties {formula: "sin(x)"}
draw w

  -- retrieve references to the curves
set c1 to curve 1 of v
set c2 to curve 2 of v
{c1, c2} -- display the references in the console


Import script
Likewise, v contains the exact same quantity as if it had been assigned with set v to plot view 1 of w.
Copyright ©2008 Paris, Satimage