Flow demos revamped 63/14263/17
Pierre-Aime Agnel [Tue, 1 Apr 2014 08:22:39 +0000 (10:22 +0200)]
Change-Id: I3128c0fa00fb1f238fe5ab40fdeb5cf4aecb6607

scilab/modules/differential_equations/demos/flow/blackhole.dem.sce
scilab/modules/differential_equations/demos/flow/blackhole.sci
scilab/modules/differential_equations/demos/flow/blackhole_interface.sci
scilab/modules/differential_equations/demos/flow/create_interface.sci [new file with mode: 0644]
scilab/modules/differential_equations/demos/flow/cylinder.dem.sce
scilab/modules/differential_equations/demos/flow/cylinder.sci
scilab/modules/differential_equations/demos/flow/cylinder_interface.sci
scilab/modules/differential_equations/demos/flow/sphere.dem.sce
scilab/modules/differential_equations/demos/flow/sphere.sci
scilab/modules/differential_equations/demos/flow/sphere_interface.sci

index a092514..ffda587 100644 (file)
@@ -6,7 +6,7 @@
 funcprot(0);
 
 my_demo_path = get_absolute_file_path("blackhole.dem.sce");
-
+exec(my_demo_path+"create_interface.sci");
 exec(my_demo_path+"blackhole.sci");
 exec(my_demo_path+"blackhole_interface.sci");
 exeblackhole();
index 5840951..b084976 100644 (file)
@@ -2,12 +2,13 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2008 - INRIA - Serge STEER
 // Copyright (C) 2008 - INRIA - Pierre MARECHAL
+// Copyright (C) 2014 - Scilab Enterprises - Pierre-Aime Agnel
 //
 // This file is distributed under the same license as the Scilab package.
 //
 
 // =============================================================================
-// Part III, black hole,z=f(x,y)=-(1/sqrt(x^2+y^2))
+// Part III, black hole, z=f(x, y)=-(1/sqrt(x^2+y^2))
 // =============================================================================
 
 
@@ -15,8 +16,8 @@
 // traj
 // ====================================
 
-function Yd=traj(tt,Y,surface)
-    [p,q,r,s,t] = surface(Y(1),Y(3));
+function Yd=traj(tt, Y, surface)
+    [p, q, r, s, t] = surface(Y(1), Y(3));
     w           = -(r*Y(2)^2+2*s*Y(2)*Y(4)+t*Y(4)^2+9.81)/(1+p^2+q^2);
     Yd          = [ Y(2) ; p*w ; Y(4) ; q*w ];
 endfunction
@@ -25,9 +26,9 @@ endfunction
 // blackhole
 // ====================================
 
-function  [p,q,r,s,t]=blackhole(x,y)
+function  [p, q, r, s, t]=blackhole(x, y)
 
-    //z=f(x,y)=-(1/sqrt(x^2+y^2));
+    //z=f(x, y)=-(1/sqrt(x^2+y^2));
     //
     //p=df/dx
     //q=df/dy
@@ -44,16 +45,12 @@ function  [p,q,r,s,t]=blackhole(x,y)
 
 endfunction
 
-
-
-
-
 // calculate_traj
 // ====================================
 
-function Y = calculate_traj(g_r,g_t,g_V,g_Vdir,t)
+function Y = calculate_traj(g_r, g_t, g_V, g_Vdir, t)
 
-    function r=blackholelim(t,y),
+    function r=blackholelim(t, y),
         r=[y(1)-2
         y(1)+2
         y(3)-2
@@ -67,7 +64,7 @@ function Y = calculate_traj(g_r,g_t,g_V,g_Vdir,t)
     Y0(3) = g_r*sin(g_t*%pi/180);      // y
     Y0(4) = g_V*sin(g_Vdir*%pi/180);   // v_y
 
-    Y     = ode("root",Y0,t(1),t,1d-10,1.D-10,list(traj,blackhole),5,blackholelim); //traj d'ecoulement
+    Y     = ode("root", Y0, t(1), t, 1d-10, 1.D-10, list(traj, blackhole), 5, blackholelim); //traj d'ecoulement
 
 endfunction
 
index e90ec1d..351d829 100644 (file)
@@ -1,6 +1,7 @@
 //
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2008 - INRIA - Pierre MARECHAL
+// Copyright (C) 2014 - Scilab Enterprises - Pierre-Aime Agnel
 //
 // This file is distributed under the same license as the Scilab package.
 //
@@ -9,10 +10,8 @@
 // BlackHole interface functions
 // =============================================================================
 // exeblackhole
-// ====================================
-
+// =============================================================================
 function exeblackhole()
-
     //initial point
     g_r = 1.1;
     g_t = 41;
@@ -22,112 +21,125 @@ function exeblackhole()
     g_Vdir = 165;
 
     // Figure parameters
-    // =========================================================================
-
     surface_frame_w = 600;     // surface frame width
     surface_frame_h = 600;     // surface frame height
 
     control_frame_w = 600;
     control_frame_h = 200;
 
-    margin_x     = 15;      // Horizontal margin between each elements
-    margin_y     = 15;      // Vertical margin between each elements
+    margin_x = 15;      // Horizontal margin between each elements
+    margin_y = 15;      // Vertical margin between each elements
 
-    axes_figure_w = 2*margin_x + max(surface_frame_w,control_frame_w);
-    axes_figure_h = 3*margin_y + surface_frame_h + control_frame_h;
+    axes_figure_w = 2 * margin_x + max(surface_frame_w, control_frame_w);
+    axes_figure_h = 3 * margin_y + surface_frame_h + control_frame_h;
 
     // Figure creation
-    // =========================================================================
+    my_figure_handle = createMainWindow([axes_figure_w axes_figure_h], _("Blackhole"), "main_figure");
+    my_figure_handle.immediate_drawing = "off";
 
-    my_figure_handle = scf(100001);
-    clf(my_figure_handle,"reset");
+    //Simulation parameters
+    speed = tlist(["sim_param", "name", "unit", "range", "default", "tag"], ...
+        "speed", ...
+        "m/s", ...
+        [0 100], ...
+        1, ...
+        "speed");
+
+    direction = tlist(["sim_param", "name", "unit", "range", "default", "tag"], ...
+        "direction", ...
+        "deg", ...
+        [0 100], ...
+        50, ...
+        "dir");
+
+    r = tlist(["sim_param", "name", "unit", "range", "default", "tag"], ...
+        "r", ...
+        "m", ...
+        [4 100], ...
+        1, ...
+        "r");
+
+    theta = tlist(["sim_param", "name", "unit", "range", "default", "tag"], ...
+        "theta", ...
+        "deg", ...
+        [0 100], ...
+        1, ...
+        "theta");
 
-    my_figure_handle.background      = -2;
-    my_figure_handle.figure_position = [0 0];
-    my_figure_handle.axes_size       = [axes_figure_w axes_figure_h];
-    my_figure_handle.figure_name     = gettext("Blackhole");
+    //Create the controls in the window bottom
+    param_list = list(r, theta, speed, direction);
+    [plot_frame, param_frame, button_frame] = create_gui(my_figure_handle);
+    create_param_zone(param_frame, param_list);
+    create_buttons(button_frame);
 
 
-    //reserve The upper part of the graphic windows for the 3d view of the scene
-    curAxe=gca();
-    curAxe.axes_bounds = [0,0,1,3/4];
     draw_blackhole();
-    draw_initial_point(g_r,g_t,g_V,g_Vdir,%T);
-
-    //Create the controls in the window bottom
-    // =========================================================================
+    draw_initial_point(g_r, g_t, g_V, g_Vdir, %T);
 
-    blackhole_create_gui()
 
     //Set control and graphics initial values
-    // =========================================================================
     change_r(g_r)
     change_theta(g_t)
     change_speed(g_V)
     change_dir(g_Vdir)
-
+    my_figure_handle.visible = "on";
 endfunction
 
 // draw_surface
-// ====================================
-
+// =============================================================================
 function draw_blackhole()
-
     r    = 1;
     orig = [0 0 0];
     xx   = -1.85:0.1:1.85;
     yy   = (-1.85:0.1:1.85)';
-    zt   = sqrt((ones(yy)*(xx.^2)+(yy.^2)*ones(xx)));
-    zz   = -1*ones(zt)./zt;
-
-    my_handle          = scf(100001);
+    zt   = sqrt((ones(yy)*(xx .^ 2) + (yy .^ 2) * ones(xx)));
+    zz   = -1 * ones(zt) ./ zt;
 
-    my_axe             = newaxes();
-    my_axe.axes_bounds = [0,0,1,3/4];
+    my_handle = get("main_figure");
 
     my_handle.immediate_drawing = "off";
-    mesh(xx,yy,zz);
-    e            = gce();
+    mesh(xx, yy, zz);
+    e = gce();
     e.color_mode = 0;
-    e.foreground=color("blue");
+    e.foreground = color("blue");
     my_handle.immediate_drawing = "on";
 endfunction
 
 // draw_initial_point
 // =============================================================================
-function draw_initial_point(g_r,g_t,g_V,g_Vdir,create)
-    x = g_r*cos(g_t*%pi/180);
-    y = g_r*sin(g_t*%pi/180);
+function draw_initial_point(g_r, g_t, g_V, g_Vdir, create)
+    x = g_r * cos(g_t * %pi / 180);
+    y = g_r * sin(g_t * %pi / 180);
     r = 0.05;
-    z = -1.0./sqrt(x^2+y^2)+r;
-    dx1 = g_V*cos(g_Vdir*%pi/180);
-    dy1 = g_V*sin(g_Vdir*%pi/180);
-    my_figure_handle = scf(100001);
+    z = -1.0 ./ sqrt(x ^ 2 + y ^ 2) + r;
+    dx1 = g_V * cos(g_Vdir * %pi / 180);
+    dy1 = g_V * sin(g_Vdir * %pi / 180);
+    my_figure_handle = get("main_figure");
     my_figure_handle.immediate_drawing = "off";
 
     if create then
         //create the graphical object used to visualize the trajectory
-        xpoly(0,0)
-        traj_handle                        =gce();
+        xpoly(0, 0)
+        traj_handle                        = gce();
         traj_handle.thickness              = 2;
         traj_handle.foreground             = 5;
         //create the graphical object used to visualize the initial speed
-        xpoly(0,0)
+        xpoly(0, 0)
         speed_handle                       =  gce();
         speed_handle.thickness             =  1;
         speed_handle.foreground            =  5;
         speed_handle.polyline_style        =  4;
         speed_handle.arrow_size_factor     =  2;
         //create the graphical objects used to visualize the initial position
-        param3d([x-r,x+r],[y,y],[z,z]);
+        param3d([x - r x + r], [y y], [z z]);
         e1                                 = gce();
         e1.thickness                       = 1;
         e1.foreground                      = 5;
-        param3d([x,x],[y-r,y+r],[z,z]);
+        param3d([x x], [y - r y + r], [z z]);
         e2                                 = gce();
         e2.thickness                       = 1;
         e2.foreground                      = 5;
-        param3d([x,x],[y,y],[z-r,z+r]);
+        param3d([x x], [y y], [z - r z + r]);
         e3                                 = gce();
         e3.thickness                       = 1;
         e3.foreground                      = 5;
@@ -135,12 +147,12 @@ function draw_initial_point(g_r,g_t,g_V,g_Vdir,create)
     else
         curAxe = gca();
         initial = curAxe.children(1).children
-        initial(1).data = [x,y,z-r;x,y,z+r];
-        initial(2).data = [x,y-r,z;x,y+r,z];
-        initial(3).data = [x-r,y,z;x+r,y,z];
+        initial(1).data = [x  y z - r ; x y z + r];
+        initial(2).data = [x y - r z ; x y + r z];
+        initial(3).data = [x - r y z ; x + r y z];
     end
-    z1= -1.0./sqrt((x+dx1)^2+(y+dy1)^2)+r;
-    initial(4).data = [x,y,z;x+dx1,y+dy1,z1];
+    z1= -1.0 ./ sqrt((x + dx1) ^ 2 + (y + dy1) ^ 2) + r;
+    initial(4).data = [x y z ; x + dx1 y + dy1 z1];
 
     my_figure_handle.immediate_drawing = "on";
 endfunction
@@ -148,20 +160,14 @@ endfunction
 // =============================================================================
 // The gui controls builder
 // =============================================================================
-
 function blackhole_create_gui()
     //initial values
-
     g_t     = 0;
     g_r     = 0;
     g_speed = 0;
-    g_Vdir   = 0;
-
-    my_figure_handle = scf(100001);
+    g_Vdir  = 0;
 
-    axes_size_figure = my_figure_handle.axes_size;
-    axes_figure_w    = axes_size_figure(1);
-    axes_figure_h    = axes_size_figure(2);
+    my_figure_handle = get("main_figure");
 
     frame_x      = 25;
     frame_y      = 200;
@@ -173,213 +179,189 @@ function blackhole_create_gui()
     text_width      = 50;
     y_margin        = 5;
     x_margin        = 10;
-    title_width     =  text_width + slider_width + value_width + unit_width +3*x_margin
+    title_width     =  text_width + slider_width + value_width + unit_width + 3 * x_margin
 
-    x_text         = frame_x
+    x_text          = frame_x
     x_slider        = x_text + text_width + x_margin;
-    x_value         = x_slider + slider_width+x_margin;
-    x_unit          = x_value  + value_width+x_margin;
+    x_value         = x_slider + slider_width + x_margin;
+    x_unit          = x_value  + value_width + x_margin;
+
+    y               = frame_y - 40;
+
+    //Create the constraints for the gridbag simulation zone / position + speed frames
+    gen_c = createConstraints("border", "bottom", [600 200]);
+
+    //Create the layout options for the frame containing position and speed frames
+    //1by2 grid with 20 pixel horizontal space for minimum paddding
+    posspeed_lay_opt = createLayoutOptions("grid", [1 2], [20 0]);
+
+
+    gui_frame = uicontrol(my_figure_handle, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "layout", "border", ...
+        "constraint", gen_c);
+
+    //Frame containing position and speed
+    gen_c.position = "center";
+    frame_posspeed = uicontrol(gui_frame, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "layout", "grid", ...
+        "layout_options", posspeed_lay_opt, ...
+        "constraint", gen_c);
+
+    //Borders and title around position or speed
+    b_f_posspeed = createBorderFont("", 16);
+    b_l_posspeed = createBorder("line", "navy", 1);
+    b_posspeed = createBorder("titled", b_l_posspeed, "starting point", "center", "top", b_f_posspeed, "navy");
+
+    //Create the internal layout options for the position and speed frames
+    //2by1 grid with 10 pixel vertical space for minimum padding
+    grid_lay_opt = createLayoutOptions("grid", [2 1], [0 10]);
+
+    //Frame initspeed
+    //title initial speed
+    //vertical grid: speed_frame | 10 | direction_frame
+    b_posspeed.title = "initial speed";
+    frame_initspeed = uicontrol(frame_posspeed, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "layout", "gridbag", ...
+        "border", b_posspeed);
+
+    //speed and direction in initspeed
+    c = createConstraints("gridbag", [1 1 1 1], [1 1], "horizontal", "center", [0 0], [0 20]);
+
+    speed_frame = uicontrol(frame_initspeed, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "layout", "gridbag", ...
+        "constraints", c);
+
+    createSliderFrame(speed_frame, "speed", "speed", "(m/s)");
+
+    c.grid =  [1 2 1 1]
+    direction_frame = uicontrol(frame_initspeed, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "layout", "gridbag", ...
+        "constraints", c);
+
+    createSliderFrame(direction_frame, "dir", "dir", "(deg)");
+    //Frame initpositiono
+    //titled starting point
+    //vertical grid: r_frame | 10 | theta_frame
+    b_posspeed.title = "initial position";
+    frame_initposition = uicontrol(frame_posspeed, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "layout", "gridbag", ...
+        "border", b_posspeed);
+
+    c.grid = [1 1 1 1]
+    r_frame = uicontrol(frame_initposition, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "layout", "gridbag", ...
+        "constraints", c);
+
+    createSliderFrame(r_frame, "r", "r", "(m)");
+
+    c.grid = [1 2 1 1]
+    theta_frame = uicontrol(frame_initposition, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "layout", "gridbag", ...
+        "constraints", c);
+
+    createSliderFrame(theta_frame, "theta", "theta", "(deg)");
+
+    //Button frame 
+    //esthetic | button 1 | est | button2 | est | button 3 | est
+    gen_c.position = "bottom"
+    gen_c.preferredsize = [0 30];
+    button_frame = uicontrol(gui_frame, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "layout", "gridbag", ...
+        "constraints", gen_c);
 
-    y               = frame_y-40;
-
-    // Title position
-    // =========================================================================
-
-    title_r = uicontrol(my_figure_handle                             , ...
-    "position"            , [x_text y title_width slider_height+y_margin]   , ...
-    "Style"               , "text"                                   , ...
-    "String"              , "Starting point"                         , ...
-    "BackgroundColor"     , [1 1 1]                                  , ...
-    "Fontsize"            , 16                                       , ...
-    "horizontalalignment" , "center"                                 , ...
-    "tag"                 , "title_r"                            );
-
-    // Slider "r"
-    // =========================================================================
-    y = y - (slider_height+y_margin)
-    text_r = uicontrol(my_figure_handle                              , ...
-    "position"          , [x_text y text_width slider_height]    , ...
-    "Style"             , "text"                                 , ...
-    "String"            , "r"                                    , ...
-    "BackgroundColor"   , [1 1 1]                                , ...
-    "tag"               , "text_r"                           );
-
-    slider_r = uicontrol(my_figure_handle                            , ...
-    "position"          , [x_slider y slider_width slider_height], ...
-    "Style"             , "slider"                               , ...
-    "Value"             , g_r                                 , ...
-    "Min"               , 0                                      , ...
-    "Max"               , 100                                      , ...
-    "callback"          , "change_r()"                           , ...
-    "tag"               , "slider_r"                         );
-
-    value_r = uicontrol(my_figure_handle                             , ...
-    "position"          , [x_value  y value_width slider_height] , ...
-    "Style"             , "text"                                 , ...
-    "String"            , string(g_r)                            , ...
-    "BackgroundColor"   , [1 1 1]                                , ...
-    "tag"               , "value_r"                          );
-
-    unite_r = uicontrol(my_figure_handle                             , ...
-    "position"          , [x_unit y unit_width slider_height]    , ...
-    "Style"             , "text"                                 , ...
-    "String"            , "(m)"                                  , ...
-    "BackgroundColor"   , [1 1 1]                                , ...
-    "tag"               , "unite_r"                          );
-
-    // Slider theta
-    // =========================================================================
-    y = y - (slider_height+y_margin)
-    text_theta = uicontrol(my_figure_handle                          , ...
-    "position"       , [x_text y text_width slider_height]       , ...
-    "Style"          , "text"                                    , ...
-    "String"         , "theta"                                   , ...
-    "BackgroundColor", [1 1 1]                                   , ...
-    "tag"            , "text_theta"                              );
-
-    slider_theta = uicontrol(my_figure_handle                        , ...
-    "position"  , [x_slider y slider_width slider_height]        , ...
-    "Style"     , "slider"                                       , ...
-    "Min"       , 0                                              , ...
-    "Max"       , 100                                            , ...
-    "Value"     , g_t                                            , ...
-    "callback"  , "change_theta()"                                   , ...
-    "tag"       , "slider_theta"                                 );
-
-    value_theta = uicontrol(my_figure_handle                         , ...
-    "position"        , [x_value  y value_width  slider_height]  , ...
-    "Style"           , "text"                                   , ...
-    "String"          , string(g_t)                              , ...
-    "BackgroundColor" , [1 1 1]                                  , ...
-    "tag"             , "value_theta"                            );
-
-    unite_theta = uicontrol(my_figure_handle                         , ...
-    "position"        , [x_unit y unit_width slider_height]      , ...
-    "Style"           , "text"                                   , ...
-    "String"          , "(deg)"                                  , ...
-    "BackgroundColor" , [1 1 1]                                  , ...
-    "tag"             , "unite_theta"                            );
-    //---------------------------------------------------------------------------
-    //second column
-    x_text          = frame_x + title_width + 3*x_margin
-    x_slider        = x_text + text_width + x_margin;
-    x_value         = x_slider + slider_width+x_margin;
-    x_unit          = x_value  + value_width+x_margin;
-
-    y               = frame_y-40;
-
-    // Title speed
-    // =========================================================================
-
-    title_speed = uicontrol(my_figure_handle                             , ...
-    "position"            , [x_text y title_width slider_height+y_margin],...
-    "Style"               , "text"                                   , ...
-    "String"              , "Initial speed"                          , ...
-    "BackgroundColor"     , [1 1 1]                                  , ...
-    "Fontsize"            , 16                                       , ...
-    "horizontalalignment" , "center"                                 , ...
-    "tag"                 , "title_speed"                            );
-
-    // Slider speed
-    // =========================================================================
-    y = y - (slider_height+y_margin)
-    text_speed = uicontrol(my_figure_handle                          , ...
-    "position"          , [x_text y text_width slider_height]    , ...
-    "Style"             , "text"                                 , ...
-    "String"            , "speed"                                , ...
-    "BackgroundColor"   , [1 1 1]                                , ...
-    "tag"               , "text_speed"                           );
-
-    slider_speed = uicontrol(my_figure_handle                        , ...
-    "position"          , [x_slider y slider_width slider_height], ...
-    "Style"             , "slider"                               , ...
-    "Value"             , g_speed                                , ...
-    "Min"               , 0                                      , ...
-    "Max"               , 100                                      , ...
-    "callback"          , "change_speed()"                       , ...
-    "tag"               , "slider_speed"                         );
-
-    value_speed = uicontrol(my_figure_handle                         , ...
-    "position"          , [x_value  y value_width slider_height] , ...
-    "Style"             , "text"                                 , ...
-    "String"            , string(g_speed)                        , ...
-    "BackgroundColor"   , [1 1 1]                                , ...
-    "tag"               , "value_speed"                          );
-
-    unite_speed = uicontrol(my_figure_handle                         , ...
-    "position"          , [x_unit y unit_width slider_height]    , ...
-    "Style"             , "text"                                 , ...
-    "String"            , "(m/s)"                                  , ...
-    "BackgroundColor"   , [1 1 1]                                , ...
-    "tag"               , "unite_speed"                          );
-
-    // Slider direction
-    // =========================================================================
-    y = y - (slider_height+y_margin)
-    text_dir = uicontrol(my_figure_handle                            , ...
-    "position"       , [x_text y text_width slider_height]       , ...
-    "Style"          , "text"                                    , ...
-    "String"         , "direction"                                   , ...
-    "BackgroundColor", [1 1 1]                                   , ...
-    "tag"            , "text_dir"                              );
-
-    slider_dir = uicontrol(my_figure_handle                          , ...
-    "position"  , [x_slider y slider_width slider_height]        , ...
-    "Style"     , "slider"                                       , ...
-    "Min"       , 0                                              , ...
-    "Max"       , 100                                            , ...
-    "Value"     , g_Vdir                                           , ...
-    "callback"  , "change_dir()"                                   , ...
-    "tag"       , "slider_dir"                                 );
-
-    value_dir = uicontrol(my_figure_handle                           , ...
-    "position"        , [x_value  y value_width  slider_height]  , ...
-    "Style"           , "text"                                   , ...
-    "String"          , string(g_Vdir)                              , ...
-    "BackgroundColor" , [1 1 1]                                  , ...
-    "tag"             , "value_dir"                            );
-
-    unite_dir = uicontrol(my_figure_handle                           , ...
-    "position"        , [x_unit y unit_width slider_height]      , ...
-    "Style"           , "text"                                   , ...
-    "String"          , "(deg)"                                  , ...
-    "BackgroundColor" , [1 1 1]                                  , ...
-    "tag"             , "unite_dir"                            );
     // Buttons
+    // est | buttons | est
     // =========================================================================
-    y = y - (slider_height+5*y_margin)
-    btn_width=100;
-    btn_margin=50;
-    btn_height=20;
-    x=frame_x+80
-    start_button = uicontrol(my_figure_handle                                   , ...
-    "Position"             , [x y btn_width btn_height]                 , ...
-    "Style"                , "pushbutton"                               , ...
-    "String"               , "Start"                                    , ...
-    "Fontsize"             , 14                                         , ...
-    "BackgroundColor"      , [1 1 1]                                    , ...
-    "callback"             , "start_simu()"                             , ...
-    "tag"                  , "start_button"                             );
-
-    x=x+btn_width+btn_margin
-    stop_button = uicontrol(my_figure_handle                                    , ...
-    "Position"               , [x y btn_width btn_height]               , ...
-    "Style"                  , "pushbutton"                             , ...
-    "String"                 , "Stop"                                   , ...
-    "Fontsize"               , 14                                       , ...
-    "BackgroundColor"        , [1 1 1]                                  , ...
-    "callback"               , "stop_simu"                              , ...
-    "tag"                    , "stop_button"                            );
-
-    x=x+btn_width+btn_margin
-    clear_button = uicontrol(my_figure_handle                                   , ...
-    "Position"               , [x y btn_width btn_height]               , ...
-    "Style"                  , "pushbutton"                             , ...
-    "String"                 , "Clear"                                  , ...
-    "Fontsize"               , 14                                       , ...
-    "BackgroundColor"        , [1 1 1]                                  , ...
-    "callback"               , "clear_simu"                             , ...
-    "tag"                    , "clear_button"                           );
+    btn_width = 100;
+    btn_margin = 50;
+    btn_height = 20;
+    x = frame_x + 80
+
+    c_button = createConstraints("gridbag", [1 1 1 1], [0 0], "none", "left", [0 0], [100 0]);
+
+    //Esthetic Empty panel
+    est_panel = uicontrol(button_frame, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "constraints", c_button);
+
+    //Buttons 
+    buttonBorder = createBorder("line", "darkgrey", 3);
+    c_button = createConstraints("gridbag", [2 1 1 1], [0 0], "both", "left", [0 0])
+    //Button Start
+    c_button.anchor = "left"
+    start_button = uicontrol(button_frame, ...
+        "Style", "pushbutton", ...
+        "String", "Start", ...
+        "Fontsize", 14, ...
+        "BackgroundColor", [0.9 0.9 0.9], ...
+        "callback", "start_simu()", ...
+        "border", buttonBorder, ...
+        "tag", "start_button", ...
+        "constraints", c_button);
+
+    //Empty panel
+    c_button = createConstraints("gridbag", [3 1 1 1], [0 0], "none", "center", [0 0], [20 0])
+    est_panel = uicontrol(button_frame, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "constraints", c_button);
+
+    //Button Stop
+    c_button = createConstraints("gridbag", [4 1 1 1], [0 0], "both", "center", [0 0])
+    stop_button = uicontrol(button_frame, ...
+        "Style", "pushbutton", ...
+        "String", "Stop", ...
+        "Fontsize", 14, ...
+        "BackgroundColor", [0.9 0.9 0.9], ...
+        "border", buttonBorder, ...
+        "callback", "stop_simu", ...
+        "tag", "stop_button", ...
+        "constraints", c_button);
+
+    //Empty panel    
+    c_button = createConstraints("gridbag", [5 1 1 1], [0 0], "none", "center", [0 0], [20 0])
+    est_panel = uicontrol(button_frame, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "constraints", c_button);
+
+    //Button Clear
+    c_button = createConstraints("gridbag", [6 1 1 1], [0 0], "both", "center", [0 0])
+    clear_button = uicontrol(button_frame, ...
+        "Style", "pushbutton", ...
+        "String", "Clear", ...
+        "Fontsize", 14, ...
+        "BackgroundColor", [0.9 0.9 0.9], ...
+        "callback", "clear_simu", ...
+        "border", buttonBorder, ...
+        "tag", "clear_button", ...
+        "constraints", c_button);
+
+    //Empty panel
+    c_button = createConstraints("gridbag", [7 1 1 1], [0 0], "none", "right", [100 0]);
+    est_panel = uicontrol(button_frame, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "constraints", c_button);
 
     return
 endfunction
@@ -387,117 +369,116 @@ endfunction
 // =============================================================================
 // The callbacks
 // =============================================================================
-
 function change_r(r)
     //r slider callback
     // r is in [0.08 2]
-    slider_r     = findobj("tag", "slider_r");
-    slider_theta = findobj("tag", "slider_theta");
-    slider_speed = findobj("tag", "slider_speed");
-    slider_dir   = findobj("tag", "slider_dir");
-    slider_r     = findobj("tag", "slider_r");
+    slider_r     = get("slider_r");
+    slider_theta = get("slider_theta");
+    slider_speed = get("slider_speed");
+    slider_dir   = get("slider_dir");
+    slider_r     = get("slider_r");
 
-    value_r       = findobj("tag", "value_r");
+    value_r       = get("value_r");
     if argn(2)==1 then
         slider_r.Value=(r-0.007)/(2-0.08)*100;
     else
         r=slider_r.Value
         r=0.007+r*(2-0.08)/100
     end
-    value_r.String=msprintf("%.3f",r)
-    draw_initial_point(0.007+slider_r.Value*(2-0.08)/100,slider_theta.value*360/100,..
-    slider_speed.Value*3/100,slider_dir.value*360/100,%F);
-
+        value_r.String=msprintf("%.3f", r)
+        draw_initial_point(0.007+slider_r.Value*(2-0.08)/100, slider_theta.value*360/100, ...
+            slider_speed.Value*3/100, slider_dir.value*360/100, %F);
 endfunction
 
 
 function change_theta(theta)
     //theta slider callback
     //theta is in [0 360]
-    slider_r     = findobj("tag", "slider_r");
-    slider_theta = findobj("tag", "slider_theta");
-    slider_speed = findobj("tag", "slider_speed");
-    slider_dir   = findobj("tag", "slider_dir");
-    slider_r     = findobj("tag", "slider_r");
+    slider_r     = get("slider_r");
+    slider_theta = get("slider_theta");
+    slider_speed = get("slider_speed");
+    slider_dir   = get("slider_dir");
+    slider_r     = get("slider_r");
 
-    value_theta   = findobj("tag", "value_theta");
+    value_theta   = get("value_theta");
     if argn(2)==1 then
         slider_theta.Value=(theta)*100/360;
     else
         theta=slider_theta.Value
         theta=theta*360/100
     end
-    value_theta.String=msprintf("%.0f",theta)
-    draw_initial_point(0.007+slider_r.Value*(2-0.08)/100,slider_theta.value*360/100,..
-    slider_speed.Value*3/100,slider_dir.value*360/100,%F);
-
+        value_theta.String=msprintf("%.0f", theta)
+        draw_initial_point(0.007+slider_r.Value*(2-0.08)/100, slider_theta.value*360/100, ..
+        slider_speed.Value*3/100, slider_dir.value*360/100, %F);
 endfunction
 
 function change_speed(speed)
     //speed slider callback
     //speed is in [0 3]
-    slider_r     = findobj("tag", "slider_r");
-    slider_theta = findobj("tag", "slider_theta");
-    slider_speed = findobj("tag", "slider_speed");
-    slider_dir   = findobj("tag", "slider_dir");
+    slider_r     = get("slider_r");
+    slider_theta = get("slider_theta");
+    slider_speed = get("slider_speed");
+    slider_dir   = get("slider_dir");
 
-    value_speed  = findobj("tag", "value_speed");
+    value_speed  = get("value_speed");
     if argn(2)==1 then
         slider_speed.Value=(speed)*100/3;
     else
         speed=slider_speed.Value
         speed=speed*3/100
     end
-    value_speed.String=msprintf("%.0f",speed)
-    draw_initial_point(0.007+slider_r.Value*(2-0.08)/100,slider_theta.value*360/100,..
-    slider_speed.Value*3/100,slider_dir.value*360/100,%F);
+    value_speed.String=msprintf("%.0f", speed)
+    draw_initial_point(0.007+slider_r.Value*(2-0.08)/100, slider_theta.value*360/100, ..
+    slider_speed.Value*3/100, slider_dir.value*360/100, %F);
 endfunction
 
 function change_dir(dir)
     //direction slider callback
     //dir is in [0 360]
-    slider_r      = findobj("tag", "slider_r");
-    slider_theta  = findobj("tag", "slider_theta");
-    slider_speed = findobj("tag", "slider_speed");
-    slider_dir   = findobj("tag", "slider_dir");
-    value_dir  = findobj("tag", "value_dir");
-    if argn(2)==1 then
-        slider_dir.Value=(dir)*100/360;
+    slider_r        = get("slider_r");
+    slider_theta    = get("slider_theta");
+    slider_speed    = get("slider_speed");
+    slider_dir      = get("slider_dir");
+    value_dir       = get("value_dir");
+
+    if argn(2) == 1 then
+        slider_dir.Value = dir * 100 / 360;
     else
-        dir=slider_dir.Value
-        dir=dir*360/100
+        dir = slider_dir.Value
+        dir = dir * 360 / 100
     end
-    value_dir.String=msprintf("%.0f",dir)
-    draw_initial_point(0.007+slider_r.Value*(2-0.08)/100,slider_theta.value*360/100,..
-    slider_speed.Value*3/100,slider_dir.value*360/100,%F);
+
+    value_dir.String = msprintf("%.0f", dir)
+    draw_initial_point(0.007 + slider_r.Value * (2 - 0.08) / 100, slider_theta.value * 360 / 100, ...
+        slider_speed.Value * 3 / 100, slider_dir.value * 360 / 100, %F);
 endfunction
 
 function start_simu()
     //start button callback
-    my_figure_handle = scf(100001);
+    my_figure_handle = get("main_figure");
     fin=my_figure_handle.user_data
     my_figure_handle.user_data=%f
-    slider_r     = findobj("tag", "slider_r");
-    slider_theta = findobj("tag", "slider_theta");
-    slider_speed = findobj("tag", "slider_speed");
-    slider_dir   = findobj("tag", "slider_dir");
+    slider_r     = get("slider_r");
+    slider_theta = get("slider_theta");
+    slider_speed = get("slider_speed");
+    slider_dir   = get("slider_dir");
     t     = 0:0.02:15;
-    Y = calculate_traj(0.007+slider_r.Value*(2-0.08)/100,slider_theta.value*360/100, ...
-    slider_speed.Value*3/100,slider_dir.value*360/100,t)
-    x = Y(1,:)
-    y = Y(3,:)
+    Y = calculate_traj(0.007 + slider_r.Value * (2 - 0.08) / 100, slider_theta.value * 360 / 100, ...
+        slider_speed.Value * 3 / 100, slider_dir.value * 360 / 100, t)
+    x = Y(1, :)
+    y = Y(3, :)
     r = 0.1; //bias to have the curve above the surface
-    z = -1.0./sqrt(x.^2+y.^2)+r;
+    z = -1.0 ./ sqrt(x .^ 2 + y .^ 2) + r;
     curAxe = gca();
     traj_handle = curAxe.children(1).children(5);
-    traj_handle.data = [x(1),y(1),z(1)];
+    traj_handle.data = [x(1) y(1) z(1)];
 
-    for k=2:size(x,"*")
+    for k=2:size(x, "*")
         sleep(10)
         if is_handle_valid(my_figure_handle) then
-            if execstr("fin=my_figure_handle.user_data","errcatch")<>0|fin then break,end
+            if execstr("fin = my_figure_handle.user_data", "errcatch") <> 0 | fin then break, end
             if is_handle_valid(traj_handle) then
-                traj_handle.data = [traj_handle.data ; [x(k),y(k),z(k)]];
+                traj_handle.data = [traj_handle.data ; [x(k) y(k) z(k)]];
             else
                 break;
             end
@@ -507,25 +488,24 @@ function start_simu()
     end
 
     if is_handle_valid(my_figure_handle) then
-        my_figure_handle.user_data=%t;
+        my_figure_handle.user_data = %t;
     end
 endfunction
 
 function stop_simu()
     //stop button callback
-    my_figure_handle = scf(100001);
-    fin   = %T;
-    my_figure_handle.user_data=fin
+    my_figure_handle = get("main_figure");
+    fin = %T;
+    my_figure_handle.user_data = fin
 endfunction
 
 function clear_simu()
     //clear button callback
-    my_figure_handle = scf(100001);
-    fin=my_figure_handle.user_data
+    my_figure_handle = get("main_figure");
+    fin = my_figure_handle.user_data
     if fin then
-        my_figure_handle = scf(100001);
         curAxe = gca();
-        traj_handle=curAxe.children(1).children(5);
-        traj_handle.data=[0,0,0];
+        traj_handle = curAxe.children(1).children(5);
+        traj_handle.data = [0 0 0];
     end
 endfunction
diff --git a/scilab/modules/differential_equations/demos/flow/create_interface.sci b/scilab/modules/differential_equations/demos/flow/create_interface.sci
new file mode 100644 (file)
index 0000000..af60581
--- /dev/null
@@ -0,0 +1,197 @@
+//
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2014 - Scilab Enterprises - Pierre-Aime Agnel
+//
+// This file is distributed under the same license as the Scilab package.
+//
+
+function fig_handle = createMainWindow(axes_size, fig_name, tag_name)
+    fig_handle = figure( ...
+        "dockable", "off", ...
+        "infobar_visible", "off", ...
+        "toolbar_visible", "off", ...
+        "toolbar", "none", ...
+        "menubar_visible", "off", ...
+        "menubar", "none", ...
+        "default_axes", "on", ...
+        "layout", "none", ...
+        "visible", "off", ...
+        "immediate_drawing", "off", ...
+        "background", -2, ...
+        "figure_position", [0 0], ...
+        "axes_size", axes_size, ...
+        "figure_name", fig_name, ...
+        "tag", tag_name);
+
+    //The plot will be in the top 3/4 of the figure
+    a = gca();
+    a.axes_bounds = [0 0 1 2/3];
+    a.tight_limits = "on";
+endfunction
+
+//Gui Creation: Plot zone and Param zone createion
+//Plot zone is twice the height of Param zone
+function [plot_frame, param_frame, button_frame] = create_gui(fig_handle)
+    //Set the layout for the figure
+    set(fig_handle, "layout", "gridbag");
+    plot_frame = [];
+
+    c = createConstraints("gridbag", [1 1 1 1], [1 1], "vertical", "left");
+    //create false panel on the left to occupy the 3/4 of the screen (figure plot)
+   empty_frame = uicontrol(fig_handle, "style", "frame", "constraints", c);
+
+    c = createConstraints("gridbag", [1 2 1 1], [1 0.25], "both", "lower", [0 0], [0 150]);
+    u = uicontrol(fig_handle, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "layout", "border", ...
+        "constraints", c);
+
+    c = createConstraints("border", "right", [20 0]);
+    left = uicontrol(u, "style", "frame", "backgroundcolor", [1 1 1], "constraints", c);
+    c = createConstraints("border", "left", [20 0]);
+    right = uicontrol(u, "style", "frame", "backgroundcolor", [1 1 1], "constraints", c);
+
+    //Border for the simulation Params
+    b_f_simuParams = createBorderFont("", 18);
+    b_l_simuParams = createBorder("line", "navy", 2);
+    b_simuParams   = createBorder("titled", b_l_simuParams, _("Simulation Parameters"), "center", "top", b_f_simuParams, "navy");
+
+    param_frame = uicontrol(u, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "border", b_simuParams, ...
+        "tag", "param_frame");
+
+    c = createConstraints("border", "bottom", [0 50]);
+    button_frame = uicontrol(u, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "constraints", c, ...
+        "tag", "button_frame");
+
+endfunction
+
+//Creates the parameter zone for all sim_param objects in the param_list
+function create_param_zone(param_frame, param_list)
+    //Set the layout for the param frame to a grid of the correct size 2 columns
+    param_frame.layout = "gridbag";
+    depth = ceil(size(param_list) / 2);
+
+    //Creates the text and slider for each parameter
+    for i = [1:depth]
+        for j = [1 5]
+            //Text on the left: name of the param
+            if i == depth & j == 5 & (depth - size(param_list) / 2) > %eps
+                c = createConstraints("gridbag", [6 i 4 1], [1 1], "both", "left", [0 5], [100 0])
+                empty_frame = uicontrol(f, "style", "frame", "constraints", c, "horizontalalignment", "left");
+            else
+                if j == 1
+                    param = param_list(i)
+                else
+                    param = param_list(depth + i)
+                end
+
+                c = createConstraints("gridbag", [j + 1 i 1 1], [1 1], "both", "left", [0 5], [75 0])
+                name_p = uicontrol(param_frame, ...
+                    "Style", "text", ...
+                    "String", param.name + " ", ...
+                    "BackgroundColor", [1 1 1], ...
+                    "horizontalalignment", "right", ...
+                    "constraints", c, ...
+                    "tag", "text_" + param.tag);
+
+                c = createConstraints("gridbag", [j + 2 i 1 1], [1 0], "both", "center", [0 5], [100 60])
+                slider_p = uicontrol(param_frame, ...
+                    "Style", "slider", ...
+                    "Value", param.default, ...
+                    "Min", param.range(1), ...
+                    "Max", param.range(2), ...
+                    "callback", "change_" + param.tag + "()", ...
+                    "constraints", c, ...
+                    "horizontalalignment", "center", ...
+                    "backgroundcolor", [1 1 1], ...
+                    "tag", "slider_" + param.tag);
+
+                c = createConstraints("gridbag", [j + 3 i 1 1], [1 1], "both", "center", [0 5], [25 0])
+                value_p = uicontrol(param_frame, ...
+                    "Style", "text", ...
+                    "String", string(param.default), ...
+                    "BackgroundColor", [1 1 1], ...
+                    "constraints", c, ...
+                    "foregroundcolor", [0 0 1], ...
+                    "horizontalalignment", "center", ...
+                    "tag", "value_" + param.tag);
+
+                c = createConstraints("gridbag", [j + 4 i 1 1], [1 1], "both", "right", [0 5], [25 0])
+                unite_p = uicontrol(param_frame, ...
+                    "Style", "text", ...
+                    "String", param.unit, ...
+                    "BackgroundColor", [1 1 1], ...
+                    "constraints", c, ...
+                    "horizontalalignment", "left", ...
+                    "tag", "unite_" + param.tag);
+            end
+        end
+    end
+endfunction
+
+function create_buttons(button_frame)
+    //Adds buttons in the middle of the frame
+    set(button_frame, "layout", "gridbag");
+    set(button_frame, "layout_options", createLayoutOptions("gridbag"));
+    c = createConstraints("gridbag", [1 1 1 1], [1 0], "horizontal", "center");
+
+    esthetic = uicontrol(button_frame, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "constraints", c);
+
+    //Place each button inside buttons
+    c_buttons = createConstraints("gridbag", [2 1 1 1], [1 0], "both", "center");
+    start_button = uicontrol(button_frame, ...
+        "Style", "pushbutton", ...
+        "String", "Start", ...
+        "Fontsize", 14, ...
+        "callback", "start_simu()", ...
+        "constraints", c_buttons, ...
+        "tag", "start_button");
+
+    c_buttons = createConstraints("gridbag", [3 1 1 1], [1 0], "both", "center");
+    esthetic = uicontrol(button_frame, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "constraints", c_buttons);
+
+    c_buttons = createConstraints("gridbag", [4 1 1 1], [1 0], "both", "center");
+
+    stop_button = uicontrol(button_frame, ...
+        "Style", "pushbutton", ...
+        "String", "Stop", ...
+        "Fontsize", 14, ...
+        "callback", "stop_simu", ...
+        "constraints", c_buttons, ...
+        "tag", "stop_button");
+
+    c_buttons = createConstraints("gridbag", [5 1 1 1], [1 0], "both", "center");
+    esthetic = uicontrol(button_frame, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "constraints", c_buttons);
+
+    c_buttons = createConstraints("gridbag", [6 1 1 1], [1 0], "both", "center");
+    clear_button = uicontrol(button_frame, ...
+        "Style", "pushbutton", ...
+        "String", "Clear", ...
+        "Fontsize", 14, ...
+        "callback", "clear_simu", ...
+        "constraints", c_buttons, ...
+        "tag", "clear_button");
+
+    //esthetic panel on the right
+    c = createConstraints("gridbag", [7 1 1 1], [1 0], "both", "right");
+    esthetic = uicontrol(button_frame, ...
+        "style", "frame", ...
+        "backgroundcolor", [1 1 1], ...
+        "constraints", c);
+endfunction
index 6b6b812..4b1afbe 100644 (file)
@@ -6,7 +6,7 @@
 funcprot(0);
 
 my_demo_path = get_absolute_file_path("cylinder.dem.sce");
-
+exec(my_demo_path+"create_interface.sci");
 exec(my_demo_path+"cylinder.sci");
 exec(my_demo_path+"cylinder_interface.sci");
 execylinder();
index 8ec593f..0dc53de 100644 (file)
@@ -2,6 +2,7 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2008 - INRIA - Serge STEER
 // Copyright (C) 2008 - INRIA - Pierre MARECHAL
+// Copyright (C) 2014 - Scilab Enterprises - Pierre-Aime Agnel
 //
 // This file is distributed under the same license as the Scilab package.
 //
 // Part II, Slanted Cylinder
 // =============================================================================
 
-function Yd=traj(tt,Y,surface)
-    [p,q,r,s,t] = surface(Y(1),Y(3))
+function Yd=traj(tt, Y, surface)
+    [p, q, r, s, t] = surface(Y(1), Y(3))
     w           = -(r*Y(2)^2+2*s*Y(2)*Y(4)+t*Y(4)^2+gravity)/(1+p^2+q^2)
     Yd          = [Y(2) ; p*w ; Y(4) ; q*w ];
 endfunction
 
 
-function [p,q,r,s,t]=SlantedCylinder(x,y)
-
+function [p, q, r, s, t]=SlantedCylinder(x, y)
     a = -tan(slope/180*%pi);
     z = sqrt(1-x^2)
     p = x/z;
@@ -26,7 +26,6 @@ function [p,q,r,s,t]=SlantedCylinder(x,y)
     r = 1/(z^3)
     s = 0
     t = 0
-
 endfunction
 
 
@@ -35,11 +34,11 @@ endfunction
 // calculate_traj
 // =============================================================================
 
-function Y = calculate_traj(g_x,g_y,g_V,g_Vdir,t,gravity,slope)
+function Y = calculate_traj(g_x, g_y, g_V, g_Vdir, t, gravity, slope)
 
-    function r=cyllim(t,y),
-        r=[y(1)-1
-        y(1)+1
+    function r=cyllim(t, y),
+        r=[y(1)-0.9
+        y(1)+0.9
         y(3)
         y(3)-14]
     endfunction
@@ -48,16 +47,15 @@ function Y = calculate_traj(g_x,g_y,g_V,g_Vdir,t,gravity,slope)
     Y0(2) = g_V*cos(g_Vdir*%pi/180);//v_x
     Y0(3) = g_y;//y
     Y0(4) = g_V*sin(g_Vdir*%pi/180);//v_y
-    Y     = ode("root",Y0,t(1),t,1d-10,1.D-10,list(traj,SlantedCylinder),4,cyllim);//traj d'ecoulement
-
+    Y     = ode("root", Y0, t(1), t, 1d-10, 1.D-10, list(traj, SlantedCylinder), 4, cyllim);//traj d'ecoulement
 endfunction
 
 // draw_bille
 // =============================================================================
 
 function draw_bille(Y)
-    g_tx = Y(1,:)';
-    g_ty = Y(3,:)';
+    g_tx = Y(1, :)';
+    g_ty = Y(3, :)';
     g_tz = -sqrt(1-g_tx^2-g_ty^2);
 endfunction
 
index 6c0a277..5da9699 100644 (file)
@@ -1,6 +1,7 @@
 //
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Scilab ( http://www.scilab.org/) - This file is part of Scilab
 // Copyright (C) 2008 - INRIA - Pierre MARECHAL
+// Copyright (C) 2014 - Scilab Enterprises - Pierre-Aime Agnel
 //
 // This file is distributed under the same license as the Scilab package.
 //
 // Step 1, set up the gradient
 // =============================================================================
 function execylinder()
-    gravity        = 9.81
-    g_pente  = 14;
+    g_gravity = 9.81;
+    g_pente = 14;
 
-    g_x      = 0.6;
-    g_y      = 0.7;
+    g_x = 0.6;
+    g_y = 0.7;
 
-    g_V      = 1;
-    g_Vdir   = 180;
+    g_V = 1;
+    g_Vdir = 180;
 
-    g_alpha  = 35;
-    g_theta  = 45;
+    g_alpha = 35;
+    g_theta = 45;
 
     // Figure parameters
     // =========================================================================
 
-    surface_frame_w = 600;     // surface frame width
-    surface_frame_h = 600;     // surface frame height
+    surface_frame_w = 600; // surface frame width
+    surface_frame_h = 600; // surface frame height
 
     control_frame_w = 600;
     control_frame_h = 200;
 
-    margin_x     = 15;      // Horizontal margin between each elements
-    margin_y     = 15;      // Vertical margin between each elements
+    margin_x = 15; // Horizontal margin between each elements
+    margin_y = 15; // Vertical margin between each elements
 
-    axes_figure_w = 2*margin_x + max(surface_frame_w,control_frame_w);
+    axes_figure_w = 2*margin_x + max(surface_frame_w, control_frame_w);
     axes_figure_h = 3*margin_y + surface_frame_h + control_frame_h;
 
     // Figure creation
     // =========================================================================
 
-    my_figure_handle = scf(100001);
-    clf(my_figure_handle,"reset");
+    my_figure_handle = createMainWindow([axes_figure_w axes_figure_h], _("Cylinder"), "main_figure");
     my_figure_handle.immediate_drawing = "off";
-    my_figure_handle.background      = -2;
-    my_figure_handle.figure_position = [0 0];
-    my_figure_handle.axes_size       = [axes_figure_w axes_figure_h];
-    my_figure_handle.figure_name     = gettext("Cylinder");
 
-    my_axe                           = gca()
-    my_axe.axes_bounds               = [0,0,1,3/4];
-    my_axe.tight_limits              = "on";
+    //Simulation parameters
+    gravity = tlist(["sim_param", "name", "unit", "range", "default", "tag"], ...
+        "gravity", ...
+        "m/s²", ...
+        [0.1 100], ...
+        9.81, ...
+        "g");
+
+    x = tlist(["sim_param", "name", "unit", "range", "default", "tag"], ...
+        "x", ...
+        "m", ...
+        [0 100], ...
+        0.6, ...
+        "x");
+
+    speed = tlist(["sim_param", "name", "unit", "range", "default", "tag"], ...
+        "speed", ...
+        "m/s", ...
+        [0 100], ...
+        0, ...
+        "speed");
+
+    slope = tlist(["sim_param", "name", "unit", "range", "default", "tag"], ...
+        "slope", ...
+        "deg", ...
+        [0 100], ...
+        14, ...
+        "slope");
+
+    y = tlist(["sim_param", "name", "unit", "range", "default", "tag"], ...
+        "y", ...
+        "m", ...
+        [1 100], ...
+        0.7, ...
+        "y");
+
+    direction = tlist(["sim_param", "name", "unit", "range", "default", "tag"], ...
+        "direction", ...
+        "deg", ...
+        [0 100], ...
+        180, ...
+        "direction");
+
+    //Setting up the GUI
+    param_list = list(gravity, x, speed, slope, y, direction);
+    [plot_frame, param_frame, button_frame] = create_gui(my_figure_handle);
+    create_param_zone(param_frame, param_list);
+    create_buttons(button_frame);
+
+    draw_cylinder(g_pente, %T);
 
-    draw_cylinder(g_pente,%T);
-    cylinder_create_gui()
     change_x(g_x)
     change_y(g_y)
     change_speed(g_V)
-    change_dir(g_Vdir)
+    change_direction(g_Vdir)
+    change_g(g_gravity)
 
-    draw_initial_point(g_x,g_y,g_V,g_Vdir,g_pente,%T)
+    draw_initial_point(g_x, g_y, g_V, g_Vdir, g_pente, %T)
 
     my_figure_handle.immediate_drawing = "on";
+
+    my_figure_handle.visible = "on";
 endfunction
 
 // draw_cylinder
 // =============================================================================
-
-function draw_cylinder(g_pente,orig)
-    a  = -tan(g_pente/180*%pi);
+function draw_cylinder(g_pente, orig)
+    a = -tan(g_pente/180*%pi);
     xx = -1:0.1:1;
     yy = (0:1:14)';
 
     if orig then
-        Z                       = -sqrt(1-ones(yy)*(xx.^2))+a*yy*ones(xx);
-        plot3d(xx,yy,Z');
+        Z = -sqrt(1-ones(yy)*(xx.^2))+a*yy*ones(xx);
+        plot3d(xx, yy, Z');
     else
-        my_figure_handle        = scf(100001);
-        my_axe                  = gca()
-        Z                       = -sqrt(1-ones(yy)*(xx^2))+a*yy*ones(xx);
-        e                       = my_axe.children(size(my_axe.children,"*"));
-        e.data.z                = Z';
-        my_axe.data_bounds(1,3) = min(Z);
+        my_figure_handle = get("main_figure");
+        my_axe = gca()
+        Z = -sqrt(1-ones(yy)*(xx.^2))+a*yy*ones(xx);
+        e = my_axe.children(size(my_axe.children, "*"));
+        e.data.z = Z';
+        my_axe.data_bounds(1, 3) = min(Z);
     end
 endfunction
 
-// draw_initial_point
-// =============================================================================
-function draw_initial_point(x,y,g_V,g_Vdir,slope,create)
+    // draw_initial_point
+    // =============================================================================
+function draw_initial_point(x, y, g_V, g_Vdir, slope, create)
     a = -tan(slope*%pi/180);
     r = 0.1;
     z = -sqrt(1-x^2)+a*y+r;
     dx1 = g_V*cos(g_Vdir*%pi/180);
     dy1 = g_V*sin(g_Vdir*%pi/180);
-    my_figure_handle = scf(100001);
+    my_figure_handle = get("main_figure");
     my_figure_handle.immediate_drawing = "off";
 
     if create then
         //create the graphical object used to visualize the trajectory
-        xpoly(0,0)
-        traj_handle                        =gce();
-        traj_handle.thickness              = 2;
-        traj_handle.foreground             = 5;
+        xpoly(0, 0)
+        traj_handle =gce();
+        traj_handle.thickness = 2;
+        traj_handle.foreground = 5;
         //create the graphical object used to visualize the initial speed
-        xpoly(0,0)
-        speed_handle                       =  gce();
-        speed_handle.thickness             =  1;
-        speed_handle.foreground            =  5;
-        speed_handle.polyline_style        =  4;
-        speed_handle.arrow_size_factor     =  2;
+        xpoly(0, 0)
+        speed_handle = gce();
+        speed_handle.thickness = 1;
+        speed_handle.foreground = 5;
+        speed_handle.polyline_style = 4;
+        speed_handle.arrow_size_factor = 2;
         //create the graphical objects used to visualize the initial position
-        param3d([x-r,x+r],[y,y],[z,z]);
-        e1                                 = gce();
-        e1.thickness                       = 1;
-        e1.foreground                      = 5;
-        param3d([x,x],[y-r,y+r],[z,z]);
-        e2                                 = gce();
-        e2.thickness                       = 1;
-        e2.foreground                      = 5;
-        param3d([x,x],[y,y],[z-r,z+r]);
-        e3                                 = gce();
-        e3.thickness                       = 1;
-        e3.foreground                      = 5;
+        param3d([x-r, x+r], [y, y], [z, z]);
+        e1 = gce();
+        e1.thickness = 1;
+        e1.foreground = 5;
+        param3d([x, x], [y-r, y+r], [z, z]);
+        e2 = gce();
+        e2.thickness = 1;
+        e2.foreground = 5;
+        param3d([x, x], [y, y], [z-r, z+r]);
+        e3 = gce();
+        e3.thickness = 1;
+        e3.foreground = 5;
         glue([traj_handle speed_handle e1 e2 e3])
     else
         curAxe = gca();
         initial=curAxe.children(1).children
-        initial(1).data = [x,y,z-r;x,y,z+r];
-        initial(2).data = [x,y-r,z;x,y+r,z];
-        initial(3).data = [x-r,y,z;x+r,y,z];
+        initial(1).data = [x, y, z-r;x, y, z+r];
+        initial(2).data = [x, y-r, z;x, y+r, z];
+        initial(3).data = [x-r, y, z;x+r, y, z];
     end
     z1=-sqrt(1-(x+dx1)^2)+a*(y+dy1)+r;
-    initial(4).data = [x,y,z;x+dx1,y+dy1,z1];
+    initial(4).data = [x, y, z;x+dx1, y+dy1, z1];
 
     my_figure_handle.immediate_drawing = "on";
 endfunction
 
-// =============================================================================
-// The gui controls builder
-// =============================================================================
-
-function cylinder_create_gui()
-    //initial values
-    gravity = 9.81
-    g_pente = 14
-    g_x     = 0;
-    g_y     = 0;
-    g_speed = 0;
-    g_Vdir  = 0;
-
-    my_figure_handle = scf(100001);
-
-    axes_size_figure = my_figure_handle.axes_size;
-    axes_figure_w    = axes_size_figure(1);
-    axes_figure_h    = axes_size_figure(2);
-
-    frame_x      = 25;
-    frame_y      = 200;
-
-    slider_height   = 15;
-    slider_width    = 140;
-    value_width     = 30;
-    unit_width      = 30;
-    text_width      = 50;
-    y_margin        = 5;
-    x_margin        = 10;
-    title_width     =  (text_width + slider_width + value_width + unit_width +3*x_margin)
-
-    x_text         = frame_x
-    x_slider        = x_text + text_width + x_margin;
-    x_value         = x_slider + slider_width+x_margin;
-    x_unit          = x_value  + value_width+x_margin;
-
-    y               = frame_y-40;
-
-    // Title position
-    // =========================================================================
-
-    title = uicontrol(my_figure_handle                             , ...
-    "position"            , [x_text y 2*title_width slider_height+y_margin]   , ...
-    "Style"               , "text"                                   , ...
-    "String"              , "Set parameters"                         , ...
-    "BackgroundColor"     , [1 1 1]                                  , ...
-    "Fontsize"            , 16                                       , ...
-    "horizontalalignment" , "center"                                 , ...
-    "tag"                 , "physics" );
-
-    // Slider "gravity"
-    // =========================================================================
-    y  = y - (slider_height+y_margin)
-    y0 = y
-    text_g = uicontrol(my_figure_handle                              , ...
-    "position"          , [x_text y text_width slider_height]    , ...
-    "Style"             , "text"                                 , ...
-    "String"            , "gravity"                                    , ...
-    "BackgroundColor"   , [1 1 1]                                , ...
-    "tag"               , "text_g"                           );
-
-    slider_g = uicontrol(my_figure_handle                            , ...
-    "position"          , [x_slider y slider_width slider_height], ...
-    "Style"             , "slider"                               , ...
-    "Value"             , gravity                                 , ...
-    "Min"               , 0.1                                      , ...
-    "Max"               , 100                                      , ...
-    "callback"          , "change_gravity()"                           , ...
-    "tag"               , "slider_gravity"                         );
-
-    value_g = uicontrol(my_figure_handle                             , ...
-    "position"          , [x_value  y value_width slider_height] , ...
-    "Style"             , "text"                                 , ...
-    "String"            , string(gravity)                            , ...
-    "BackgroundColor"   , [1 1 1]                                , ...
-    "tag"               , "value_g"                          );
-
-    unite_g = uicontrol(my_figure_handle                             , ...
-    "position"          , [x_unit y unit_width slider_height]    , ...
-    "Style"             , "text"                                 , ...
-    "String"            , "(m/s^-2)"                                  , ...
-    "BackgroundColor"   , [1 1 1]                                , ...
-    "tag"               , "unite_g"                          );
-
-    // Slider x
-    // =========================================================================
-    y = y - (slider_height+y_margin)
-    text_x = uicontrol(my_figure_handle                          , ...
-    "position"       , [x_text y text_width slider_height]       , ...
-    "Style"          , "text"                                    , ...
-    "String"         , "x"                                   , ...
-    "BackgroundColor", [1 1 1]                                   , ...
-    "tag"            , "text_x"                              );
-    slider_x = uicontrol(my_figure_handle                        , ...
-    "position"  , [x_slider y slider_width slider_height]        , ...
-    "Style"     , "slider"                                       , ...
-    "Min"       , 0                                              , ...
-    "Max"       , 100                                            , ...
-    "Value"     , g_x                                            , ...
-    "callback"  , "change_x()"                                   , ...
-    "tag"       , "slider_x"                                 );
-
-    value_x = uicontrol(my_figure_handle                         , ...
-    "position"        , [x_value  y value_width  slider_height]  , ...
-    "Style"           , "text"                                   , ...
-    "String"          , string(g_x)                              , ...
-    "BackgroundColor" , [1 1 1]                                  , ...
-    "tag"             , "value_x"                            );
-
-    unite_x = uicontrol(my_figure_handle                         , ...
-    "position"        , [x_unit y unit_width slider_height]      , ...
-    "Style"           , "text"                                   , ...
-    "String"          , "(m)"                                  , ...
-    "BackgroundColor" , [1 1 1]                                  , ...
-    "tag"             , "unite_x" ...
-    );
-    //Slider speed
-    // =========================================================================
-    y = y - (slider_height+y_margin)
-    text_speed = uicontrol(my_figure_handle                          , ...
-    "position"          , [x_text y text_width slider_height]    , ...
-    "Style"             , "text"                                 , ...
-    "String"            , "speed"                                , ...
-    "BackgroundColor"   , [1 1 1]                                , ...
-    "tag"               , "text_speed"                           );
-
-    slider_speed = uicontrol(my_figure_handle                        , ...
-    "position"          , [x_slider y slider_width slider_height], ...
-    "Style"             , "slider"                               , ...
-    "Value"             , g_speed                                , ...
-    "Min"               , 0                                      , ...
-    "Max"               , 100                                      , ...
-    "callback"          , "change_speed()"                       , ...
-    "tag"               , "slider_speed"                         );
-
-    value_speed = uicontrol(my_figure_handle                         , ...
-    "position"          , [x_value  y value_width slider_height] , ...
-    "Style"             , "text"                                 , ...
-    "String"            , string(g_speed)                        , ...
-    "BackgroundColor"   , [1 1 1]                                , ...
-    "tag"               , "value_speed"                          );
-
-    unite_speed = uicontrol(my_figure_handle                         , ...
-    "position"          , [x_unit y unit_width slider_height]    , ...
-    "Style"             , "text"                                 , ...
-    "String"            , "(m/s)"                                  , ...
-    "BackgroundColor"   , [1 1 1]                                , ...
-    "tag"               , "unite_speed"                          );
-
-
-
-    //---------------------------------------------------------------------------
-    //second column
-    x_text          = frame_x + title_width + 3*x_margin
-    x_slider        = x_text + text_width + x_margin;
-    x_value         = x_slider + slider_width+x_margin;
-    x_unit          = x_value  + value_width+x_margin;
-
-    y               = y0
-
-    // Slider slope
-    // =========================================================================
-
-    text_slope = uicontrol(my_figure_handle                          , ...
-    "position"       , [x_text y text_width slider_height]       , ...
-    "Style"          , "text"                                    , ...
-    "String"         , "slope"                                   , ...
-    "BackgroundColor", [1 1 1]                                   , ...
-    "tag"            , "text_slope"                              );
-
-    slider_slope = uicontrol(my_figure_handle                        , ...
-    "position"  , [x_slider y slider_width slider_height]        , ...
-    "Style"     , "slider"                                       , ...
-    "Min"       , 0                                              , ...
-    "Max"       , 100                                            , ...
-    "Value"     , g_pente                                            , ...
-    "callback"  , "change_slope()"                                   , ...
-    "tag"       , "slider_slope"                                 );
-
-    value_slope = uicontrol(my_figure_handle                         , ...
-    "position"        , [x_value  y value_width  slider_height]  , ...
-    "Style"           , "text"                                   , ...
-    "String"          , string(g_pente)                              , ...
-    "BackgroundColor" , [1 1 1]                                  , ...
-    "tag"             , "value_slope"                            );
-
-    unite_slope = uicontrol(my_figure_handle                         , ...
-    "position"        , [x_unit y unit_width slider_height]      , ...
-    "Style"           , "text"                                   , ...
-    "String"          , "(deg)"                                  , ...
-    "BackgroundColor" , [1 1 1]                                  , ...
-    "tag"             , "unite_slope" ...
-    );
-    // Slider y
-    // =========================================================================
-    y = y - (slider_height+y_margin)
-    text_y = uicontrol(my_figure_handle                          , ...
-    "position"       , [x_text y text_width slider_height]       , ...
-    "Style"          , "text"                                    , ...
-    "String"         , "y"                                   , ...
-    "BackgroundColor", [1 1 1]                                   , ...
-    "tag"            , "text_y"                              );
-    slider_y = uicontrol(my_figure_handle                        , ...
-    "position"  , [x_slider y slider_width slider_height]        , ...
-    "Style"     , "slider"                                       , ...
-    "Min"       , 0                                              , ...
-    "Max"       , 100                                            , ...
-    "Value"     , g_y                                            , ...
-    "callback"  , "change_y()"                                   , ...
-    "tag"       , "slider_y"                                 );
-
-    value_y = uicontrol(my_figure_handle                         , ...
-    "position"        , [x_value  y value_width  slider_height]  , ...
-    "Style"           , "text"                                   , ...
-    "String"          , string(g_y)                              , ...
-    "BackgroundColor" , [1 1 1]                                  , ...
-    "tag"             , "value_y"                            );
-
-    unite_y = uicontrol(my_figure_handle                         , ...
-    "position"        , [x_unit y unit_width slider_height]      , ...
-    "Style"           , "text"                                   , ...
-    "String"          , "(m)"                                  , ...
-    "BackgroundColor" , [1 1 1]                                  , ...
-    "tag"             , "unite_y" ...
-    );
-    // Slider direction
-    // =========================================================================
-    y = y - (slider_height+y_margin)
-    text_dir = uicontrol(my_figure_handle                            , ...
-    "position"       , [x_text y text_width slider_height]       , ...
-    "Style"          , "text"                                    , ...
-    "String"         , "direction"                                   , ...
-    "BackgroundColor", [1 1 1]                                   , ...
-    "tag"            , "text_dir"                              );
-
-    slider_dir = uicontrol(my_figure_handle                          , ...
-    "position"  , [x_slider y slider_width slider_height]        , ...
-    "Style"     , "slider"                                       , ...
-    "Min"       , 0                                              , ...
-    "Max"       , 100                                            , ...
-    "Value"     , g_Vdir                                           , ...
-    "callback"  , "change_dir()"                                   , ...
-    "tag"       , "slider_dir"                                 );
-
-    value_dir = uicontrol(my_figure_handle                           , ...
-    "position"        , [x_value  y value_width  slider_height]  , ...
-    "Style"           , "text"                                   , ...
-    "String"          , string(g_Vdir)                              , ...
-    "BackgroundColor" , [1 1 1]                                  , ...
-    "tag"             , "value_dir"                            );
-
-    unite_dir = uicontrol(my_figure_handle                           , ...
-    "position"        , [x_unit y unit_width slider_height]      , ...
-    "Style"           , "text"                                   , ...
-    "String"          , "(deg)"                                  , ...
-    "BackgroundColor" , [1 1 1]                                  , ...
-    "tag"             , "unite_dir"                            );
-    // Buttons
-    // =========================================================================
-    y = y - (slider_height+5*y_margin)
-    btn_width=100;
-    btn_margin=50;
-    btn_height=20;
-    x=frame_x+80
-    start_button = uicontrol(my_figure_handle                                   , ...
-    "Position"             , [x y btn_width btn_height]                 , ...
-    "Style"                , "pushbutton"                               , ...
-    "String"               , "Start"                                    , ...
-    "Fontsize"             , 14                                         , ...
-    "BackgroundColor"      , [1 1 1]                                    , ...
-    "callback"             , "start_simu()"                             , ...
-    "tag"                  , "start_button"                             );
-
-    x=x+btn_width+btn_margin
-    stop_button = uicontrol(my_figure_handle                                    , ...
-    "Position"               , [x y btn_width btn_height]               , ...
-    "Style"                  , "pushbutton"                             , ...
-    "String"                 , "Stop"                                   , ...
-    "Fontsize"               , 14                                       , ...
-    "BackgroundColor"        , [1 1 1]                                  , ...
-    "callback"               , "stop_simu"                              , ...
-    "tag"                    , "stop_button"                            );
-
-    x=x+btn_width+btn_margin
-    clear_button = uicontrol(my_figure_handle                                   , ...
-    "Position"               , [x y btn_width btn_height]               , ...
-    "Style"                  , "pushbutton"                             , ...
-    "String"                 , "Clear"                                  , ...
-    "Fontsize"               , 14                                       , ...
-    "BackgroundColor"        , [1 1 1]                                  , ...
-    "callback"               , "clear_simu"                             , ...
-    "tag"                    , "clear_button"                           );
-
-    return
-endfunction
-
 
 // =============================================================================
 // The callbacks
 // =============================================================================
-
 function change_x(x)
     //x slider callback
     // x is in [-0.9 0.9]
-    slider_x     = findobj("tag", "slider_x");
-    slider_y     = findobj("tag", "slider_y");
-    slider_slope = findobj("tag", "slider_slope");
-    slider_speed = findobj("tag", "slider_speed");
-    slider_dir   = findobj("tag", "slider_dir");
+    slider_x = get( "slider_x");
+    slider_y = get( "slider_y");
+    slider_slope = get( "slider_slope");
+    slider_speed = get( "slider_speed");
+    slider_direction = get( "slider_direction");
 
-    value_x       = findobj("tag", "value_x");
+    value_x = get( "value_x");
     if argn(2)==1 then
         slider_x.Value=(x+0.9)*100/1.8;
     else
         x=slider_x.Value
         x=-0.9+x*1.8/100
     end
-    value_x.String=msprintf("%.3f",x)
-    draw_initial_point(-0.9+slider_x.Value*1.8/100,slider_y.value*3/100,..
-    slider_speed.Value*2/100,slider_dir.value*360/100,slider_slope.Value*70/100,%F);
+        value_x.String=msprintf("%.3f", x)
+        draw_initial_point(-0.9+slider_x.Value*1.8/100, slider_y.value*3/100, ..
+        slider_speed.Value*2/100, slider_direction.value*360/100, slider_slope.Value*70/100, %F);
 endfunction
 
 function change_y(y)
     //y slider callback
     //y is in [0 3]
-    slider_x     = findobj("tag", "slider_x");
-    slider_y     = findobj("tag", "slider_y");
-    slider_slope = findobj("tag", "slider_slope");
-    slider_speed = findobj("tag", "slider_speed");
-    slider_dir   = findobj("tag", "slider_dir");
+    slider_x = get( "slider_x");
+    slider_y = get( "slider_y");
+    slider_slope = get( "slider_slope");
+    slider_speed = get( "slider_speed");
+    slider_direction = get( "slider_direction");
 
-    value_y       = findobj("tag", "value_y");
+    value_y = get( "value_y");
     if argn(2)==1 then
         slider_y.Value=(y)*100/3;
     else
         y=slider_y.Value
-        y=-y*3/100
+        y=y*3/100
     end
-    value_y.String=msprintf("%.3f",y)
-    draw_initial_point(-0.9+slider_x.Value*1.8/100,slider_y.value*3/100,..
-    slider_speed.Value*2/100,slider_dir.value*360/100,slider_slope.Value*70/100,%F);
+    value_y.String=msprintf("%.3f", y)
+    draw_initial_point(-0.9+slider_x.Value*1.8/100, slider_y.value*3/100, ..
+    slider_speed.Value*2/100, slider_direction.value*360/100, slider_slope.Value*70/100, %F);
 endfunction
 
 function change_speed(speed)
     //speed slider callback
     //speed is in [0 2]
-    slider_x     = findobj("tag", "slider_x");
-    slider_y     = findobj("tag", "slider_y");
-    slider_slope = findobj("tag", "slider_slope");
-    slider_speed = findobj("tag", "slider_speed");
-    slider_dir   = findobj("tag", "slider_dir");
+    slider_x = get( "slider_x");
+    slider_y = get( "slider_y");
+    slider_slope = get( "slider_slope");
+    slider_speed = get( "slider_speed");
+    slider_direction = get( "slider_direction");
 
-    value_speed  = findobj("tag", "value_speed");
+    value_speed = get( "value_speed");
     if argn(2)==1 then
         slider_speed.Value=(speed)*100/2;
     else
         speed=slider_speed.Value
         speed=speed*2/100
     end
-    value_speed.String=msprintf("%.2f",speed)
-    draw_initial_point(-0.9+slider_x.Value*1.8/100,slider_y.value*3/100,..
-    slider_speed.Value*2/100,slider_dir.value*360/100,slider_slope.Value*70/100,%F);
+    value_speed.String=msprintf("%.2f", speed)
+    draw_initial_point(-0.9+slider_x.Value*1.8/100, slider_y.value*3/100, ..
+    slider_speed.Value*2/100, slider_direction.value*360/100, slider_slope.Value*70/100, %F);
 endfunction
 
 function change_slope(slope)
     //slope slider callback
     //slope is in [0 70]
-    slider_x     = findobj("tag", "slider_x");
-    slider_y     = findobj("tag", "slider_y");
-    slider_slope = findobj("tag", "slider_slope");
-    slider_speed = findobj("tag", "slider_speed");
-    slider_dir   = findobj("tag", "slider_dir");
+    slider_x = get( "slider_x");
+    slider_y = get( "slider_y");
+    slider_slope = get( "slider_slope");
+    slider_speed = get( "slider_speed");
+    slider_direction = get( "slider_direction");
 
-    value_slope  = findobj("tag", "value_slope");
+    value_slope = get( "value_slope");
     if argn(2)==1 then
         slider_slope.Value=(slope)*100/70;
     else
         slope=slider_slope.Value
         slope=slope*70/100
     end
-    value_slope.String=msprintf("%.2f",slope)
+    value_slope.String=msprintf("%.2f", slope)
     g_pente=slope
-    draw_cylinder(g_pente,%f);
-    draw_initial_point(-0.9+slider_x.Value*1.8/100,slider_y.value*3/100,..
-    slider_speed.Value*2/100,slider_dir.value*360/100,slider_slope.Value*70/100,%F);
+    draw_cylinder(g_pente, %f);
+    draw_initial_point(-0.9+slider_x.Value*1.8/100, slider_y.value*3/100, ..
+    slider_speed.Value*2/100, slider_direction.value*360/100, slider_slope.Value*70/100, %F);
 endfunction
 
-function change_dir(dir)
+function change_direction(direction)
     //direction slider callback
     //dir is in [0 360]
-    slider_x     = findobj("tag", "slider_x");
-    slider_y     = findobj("tag", "slider_y");
-    slider_slope = findobj("tag", "slider_slope");
-    slider_speed = findobj("tag", "slider_speed");
-    slider_dir   = findobj("tag", "slider_dir");
+    slider_x = get( "slider_x");
+    slider_y = get( "slider_y");
+    slider_slope = get( "slider_slope");
+    slider_speed = get( "slider_speed");
+    slider_direction = get( "slider_direction");
 
-    value_dir  = findobj("tag", "value_dir");
+    value_direction = get( "value_direction");
     if argn(2)==1 then
-        slider_dir.Value=(dir)*100/360;
+        slider_direction.Value=(direction)*100/360;
     else
-        dir=slider_dir.Value
-        dir=dir*360/100
+        direction=slider_direction.Value
+        direction=direction*360/100
     end
-    value_dir.String=msprintf("%.0f",dir)
-    draw_initial_point(-0.9+slider_x.Value*1.8/100,slider_y.value*3/100,..
-    slider_speed.Value*2/100,slider_dir.value*360/100,slider_slope.Value*70/100,%F);
+    value_direction.String=msprintf("%.0f", direction)
+    draw_initial_point(-0.9+slider_x.Value*1.8/100, slider_y.value*3/100, ..
+    slider_speed.Value*2/100, slider_direction.value*360/100, slider_slope.Value*70/100, %F);
 endfunction
 
-function change_gravity(gravity)
+function change_g(gravity)
     //gravity slider callback
     //gravity is in [0 10]
-    slider_x       = findobj("tag", "slider_x");
-    slider_y       = findobj("tag", "slider_y");
-    slider_slope   = findobj("tag", "slider_slope");
-    slider_speed   = findobj("tag", "slider_speed");
-    slider_dir     = findobj("tag", "slider_dir");
-    slider_g       = findobj("tag", "slider_gravity");
-
-    value_g  = findobj("tag", "value_g");
+    slider_x = get( "slider_x");
+    slider_y = get( "slider_y");
+    slider_slope = get( "slider_slope");
+    slider_speed = get( "slider_speed");
+    slider_direction = get( "slider_direction");
+    slider_g = get( "slider_g");
+
+    value_g = get( "value_g");
     if argn(2)==1 then
         slider_g.Value=(gravity)*100/10;
     else
         gravity=slider_g.Value
-        gravity=gravity*360/10
+        gravity=gravity*10/100
     end
-    value_g.String=msprintf("%.2f",gravity)
-    //  draw_initial_point(-0.9+slider_x.Value*1.8/100,slider_y.value*3/100,..
-    //             slider_speed.Value*2/100,slider_dir.value*360/100,slider_slope.Value*70/100,%F);
-
+    value_g.String=msprintf("%.2f", gravity)
 endfunction
 
 
 function start_simu()
     //start button callback
-    my_figure_handle           = scf(100001);
-    fin                        = my_figure_handle.user_data
+    my_figure_handle = get("main_figure");
+    fin = my_figure_handle.user_data
     my_figure_handle.user_data = %f
 
-    slider_x       = findobj("tag", "slider_x");
-    slider_y       = findobj("tag", "slider_y");
-    slider_slope   = findobj("tag", "slider_slope");
-    slider_speed   = findobj("tag", "slider_speed");
-    slider_dir     = findobj("tag", "slider_dir");
-    slider_g       = findobj("tag", "slider_gravity");
-
-
-    t              = 0:0.01:10; //1001 track points
-
-    x       = -0.9+slider_x.Value*1.8/100
-    y       = slider_y.value*3/100
-    V       = slider_speed.Value*2/100
-    Vdir    = slider_dir.value*360/100
-    slope   = slider_slope.Value*70/100
-    gravity = slider_g.Value*360/10
-    Y = calculate_traj(x,y,V,Vdir,t,gravity,slope)
-    x = Y(1,:)
-    y = Y(3,:)
+    slider_x = get( "slider_x");
+    slider_y = get( "slider_y");
+    slider_slope = get( "slider_slope");
+    slider_speed = get( "slider_speed");
+    slider_direction = get( "slider_direction");
+    slider_g = get( "slider_g");
+
+
+    t = 0:0.01:10; //1001 track points
+
+    x = -0.9+slider_x.Value*1.8/100
+    y = slider_y.value*3/100
+    V = slider_speed.Value*2/100
+    Vdir = slider_direction.value*360/100
+    slope = slider_slope.Value*70/100
+    gravity = slider_g.Value*10/100
+    Y = calculate_traj(x, y, V, Vdir, t, gravity, slope)
+    x = Y(1, :)
+    y = Y(3, :)
     r = 0.1; //bias to have the curve above the surface
-    a  = -tan(slope/180*%pi);
+    a = -tan(slope/180*%pi);
     z = -sqrt(1-x.^2)+a*y+r;
-    my_figure_handle = scf(100001);
+    my_figure_handle = get("main_figure");
     curAxe = gca();
     traj_handle=curAxe.children(1).children(5);
-    traj_handle.data=[x(1),y(1),z(1)];
-    for k=2:size(x,"*")
-        sleep(10)
-        if execstr("fin=my_figure_handle.user_data","errcatch")<>0|fin then break,end
-        traj_handle.data=[traj_handle.data;[x(k),y(k),z(k)]];
+    traj_handle.data=[x(1), y(1), z(1)];
+    for k=2:size(x, "*")
+        sleep(3)
+        if execstr("fin=my_figure_handle.user_data", "errcatch")<>0|fin then break, end
+        traj_handle.data=[traj_handle.data;[x(k), y(k), z(k)]];
     end
-    my_figure_handle.user_data=%t
+        my_figure_handle.user_data=%t
 endfunction
 
 function stop_simu()
     //stop button callback
-    my_figure_handle = scf(100001);
-    fin   = %T;
+    my_figure_handle = get("main_figure");
+    fin = %T;
     my_figure_handle.user_data=fin
 endfunction
 
 function clear_simu()
     //clear button callback
-    my_figure_handle = scf(100001);
+    my_figure_handle = get("main_figure");
     fin=my_figure_handle.user_data
     if fin then
-        my_figure_handle = scf(100001);
+        my_figure_handle = get("main_figure");
         curAxe = gca();
         traj_handle=curAxe.children(1).children(5);
-        traj_handle.data=[0,0,0];
+        traj_handle.data=[0, 0, 0];
     end
 endfunction
index da78c6c..95b119b 100644 (file)
@@ -6,7 +6,7 @@
 funcprot(0);
 
 my_demo_path = get_absolute_file_path("sphere.dem.sce");
-
+exec(my_demo_path+"create_interface.sci");
 exec(my_demo_path+"sphere.sci");
 exec(my_demo_path+"sphere_interface.sci");
 exesphere();
index 150e3f9..7888161 100644 (file)
@@ -2,6 +2,7 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2008 - INRIA - Serge STEER
 // Copyright (C) 2008 - INRIA - Pierre MARECHAL
+// Copyright (C) 2014 - Scilab Enterprises - Pierre-Aime Agnel
 //
 // This file is distributed under the same license as the Scilab package.
 //
 // traj
 // =============================================================================
 
-function Yd=traj(tt,Y,surface)
+function Yd=traj(tt, Y, surface)
     g=9.81
-    [p,q,r,s,t]=surface(Y(1),Y(3))
+    [p, q, r, s, t]=surface(Y(1), Y(3))
     w=-(r*Y(2)^2+2*s*Y(2)*Y(4)+t*Y(4)^2+g)/(1+p^2+q^2)
     Yd=[Y(2)
     p*w
     Y(4)
     q*w]
-    if size(Yd,1)<>4|~isreal(Yd) then pause,end
+    if size(Yd, 1)<>4|~isreal(Yd) then pause, end
 endfunction
 
 
 // sphere
 // =============================================================================
 
-function  [p,q,r,s,t]=sphere(x,y)
-    //z=f(x,y)=sqrt(1-x^2-y^2)
+function  [p, q, r, s, t]=sphere(x, y)
+    //z=f(x, y)=sqrt(1-x^2-y^2)
     //
     //df/dx=-x/sqrt(1-x^2-y^2)
     //df/dy=-y/sqrt(1-x^2-y^2)
@@ -47,13 +48,13 @@ endfunction
 // calculate_traj
 // =============================================================================
 
-function Y = calculate_traj(g_r,g_t,g_V,g_Vdir,t)
-    function r=sphlim(t,y),r=y(1)^2+y(3)^2-0.9999,endfunction
+function Y = calculate_traj(g_r, g_t, g_V, g_Vdir, t)
+    function r=sphlim(t, y), r=y(1)^2+y(3)^2-0.9999, endfunction
     Y0(1) = g_r*cos(g_t*%pi/180);     // x
     Y0(2) = g_V*cos(g_Vdir*%pi/180);  // v_x
     Y0(3) = g_r*sin(g_t*%pi/180);     // y
     Y0(4) = g_V*sin(g_Vdir*%pi/180);  // v_z
-    Y     = ode("root",Y0,t(1),t,1d-10,1.D-10,list(traj,sphere),1,sphlim);//traj d'ecoulement
+    Y     = ode("root", Y0, t(1), t, 1d-10, 1.D-10, list(traj, sphere), 1, sphlim);//traj d'ecoulement
 endfunction
 
 
index b885ce8..3368456 100644 (file)
@@ -1,6 +1,7 @@
 //
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2008 - INRIA - Pierre MARECHAL
+// Copyright (C) 2014 - Scilab Enterprises - Pierre-Aime Agnel
 //
 // This file is distributed under the same license as the Scilab package.
 //
@@ -30,30 +31,58 @@ function exesphere()
     margin_x     = 15;      // Horizontal margin between each elements
     margin_y     = 15;      // Vertical margin between each elements
 
-    axes_figure_w = 2*margin_x + max(surface_frame_w,control_frame_w);
+    axes_figure_w = 2*margin_x + max(surface_frame_w, control_frame_w);
     axes_figure_h = 3*margin_y + surface_frame_h + control_frame_h;
 
     // Figure creation
     // =========================================================================
 
-    my_figure_handle = scf(100001);
-    clf(my_figure_handle,"reset");
+    my_figure_handle = createMainWindow([axes_figure_w axes_figure_h], _("Sphere"), "main_figure");
+
+
+    //Simulation parameters
+    speed = tlist(["sim_param", "name", "unit", "range", "default", "tag"], ...
+        "speed", ...
+        "m/s", ...
+        [0 100], ...
+        1, ...
+        "speed");
+
+    direction = tlist(["sim_param", "name", "unit", "range", "default", "tag"], ...
+        "direction", ...
+        "deg", ...
+        [0 100], ...
+        50, ...
+        "dir");
+
+    r = tlist(["sim_param", "name", "unit", "range", "default", "tag"], ...
+        "r", ...
+        "m", ...
+        [0 100], ...
+        0, ...
+        "r");
+
+    theta = tlist(["sim_param", "name", "unit", "range", "default", "tag"], ...
+        "theta", ...
+        "deg", ...
+        [0 100], ...
+        1, ...
+        "theta");
+
+    //Create the controls in the window bottom
+    // =========================================================================   
+    param_list = list(r, theta, speed, direction);
+    [plot_frame, param_frame, button_frame] = create_gui(my_figure_handle);
+    create_param_zone(param_frame, param_list);
+    create_buttons(button_frame);
 
-    my_figure_handle.background      = -2;
-    my_figure_handle.figure_position = [0 0];
-    my_figure_handle.axes_size       = [axes_figure_w axes_figure_h];
-    my_figure_handle.figure_name     = gettext("Sphere");
 
-    //reserve The upper part of the graphic windows for the 3d view of the scene
-    curAxe=gca();
-    curAxe.axes_bounds = [0,0,1,3/4];
     draw_sphere();
-    draw_initial_point(g_r,g_t,g_V,g_Vdir,%T);
+    draw_initial_point(g_r, g_t, g_V, g_Vdir, %T);
 
-    //Create the controls in the window bottom
-    // =========================================================================
 
-    sphere_create_gui()
+
+    //    sphere_create_gui()
 
     //Set control and graphics initial values
     // =========================================================================
@@ -62,15 +91,16 @@ function exesphere()
     change_speed(g_V)
     change_dir(g_Vdir)
 
+    my_figure_handle.visible = "on";
 endfunction
 
-// draw_sphere
-// =============================================================================
+    // draw_sphere
+    // =============================================================================
 
 function draw_sphere()
     // draw half of a sphere (the flow lines surface )
 
-    function [x,y,z]=sph(alp,tet)
+    function [x, y, z]=sph(alp, tet)
         //parametric definition of a sphere
         x = r*cos(alp).*cos(tet)+orig(1)*ones(tet)
         y = r*cos(alp).*sin(tet)+orig(2)*ones(tet)
@@ -80,48 +110,48 @@ function draw_sphere()
     r    = 1;
     orig = [0 0 0];
     //create surface facets
-    [xx,yy,zz]=eval3dp(sph,linspace(-%pi/2,0,40),linspace(0,%pi*2,20));
+    [xx, yy, zz]=eval3dp(sph, linspace(-%pi/2, 0, 40), linspace(0, %pi*2, 20));
     // draw facets
-    plot3d(xx,yy,zz);
+    plot3d(xx, yy, zz);
 
 endfunction
 
 
-// draw_initial_point
-// =============================================================================
-function draw_initial_point(g_r,g_t,g_V,g_Vdir,create)
+    // draw_initial_point
+    // =============================================================================
+function draw_initial_point(g_r, g_t, g_V, g_Vdir, create)
     x = g_r*cos(g_t*%pi/180);
     y = g_r*sin(g_t*%pi/180);
     r = 0.05;
     z = -sqrt(1-x^2-y^2)+r;
     dx1 = 0.1*g_V*cos(g_Vdir*%pi/180);
     dy1 = 0.1*g_V*sin(g_Vdir*%pi/180);
-    my_figure_handle = scf(100001);
+    my_figure_handle = get("main_figure");
     my_figure_handle.immediate_drawing = "off";
 
     if create then
         //create the graphical object used to visualize the trajectory
-        xpoly(0,0)
+        xpoly(0, 0)
         traj_handle                        =gce();
         traj_handle.thickness              = 2;
         traj_handle.foreground             = 5;
         //create the graphical object used to visualize the initial speed
-        xpoly(0,0)
+        xpoly(0, 0)
         speed_handle                       =  gce();
         speed_handle.thickness             =  1;
         speed_handle.foreground            =  5;
         speed_handle.polyline_style        =  4;
         speed_handle.arrow_size_factor     =  2;
         //create the graphical objects used to visualize the initial position
-        param3d([x-r,x+r],[y,y],[z,z]);
+        param3d([x-r, x+r], [y, y], [z, z]);
         e1                                 = gce();
         e1.thickness                       = 1;
         e1.foreground                      = 5;
-        param3d([x,x],[y-r,y+r],[z,z]);
+        param3d([x, x], [y-r, y+r], [z, z]);
         e2                                 = gce();
         e2.thickness                       = 1;
         e2.foreground                      = 5;
-        param3d([x,x],[y,y],[z-r,z+r]);
+        param3d([x, x], [y, y], [z-r, z+r]);
         e3                                 = gce();
         e3.thickness                       = 1;
         e3.foreground                      = 5;
@@ -129,382 +159,142 @@ function draw_initial_point(g_r,g_t,g_V,g_Vdir,create)
     else
         curAxe = gca();
         initial=curAxe.children(1).children
-        initial(1).data = [x,y,z-r;x,y,z+r];
-        initial(2).data = [x,y-r,z;x,y+r,z];
-        initial(3).data = [x-r,y,z;x+r,y,z];
+        initial(1).data = [x, y, z-r;x, y, z+r];
+        initial(2).data = [x, y-r, z;x, y+r, z];
+        initial(3).data = [x-r, y, z;x+r, y, z];
     end
     z1=-sqrt(1-(x+dx1)^2-(y+dy1)^2)+r
-    initial(4).data = [x,y,z;x+dx1,y+dy1,z1];
+    initial(4).data = [x, y, z;x+dx1, y+dy1, z1];
 
     my_figure_handle.immediate_drawing = "on";
 endfunction
 
-// =============================================================================
-// The gui controls builder
-// =============================================================================
-
-function sphere_create_gui()
-    //initial values
-
-    g_t     = 0;
-    g_r     = 0;
-    g_speed = 0;
-    g_Vdir   = 0;
-
-    my_figure_handle = scf(100001);
-
-    axes_size_figure = my_figure_handle.axes_size;
-    axes_figure_w    = axes_size_figure(1);
-    axes_figure_h    = axes_size_figure(2);
-
-    frame_x      = 25;
-    frame_y      = 200;
-
-    slider_height   = 15;
-    slider_width    = 140;
-    value_width     = 30;
-    unit_width      = 30;
-    text_width      = 50;
-    y_margin        = 5;
-    x_margin        = 10;
-    title_width     =  text_width + slider_width + value_width + unit_width +3*x_margin
-
-    x_text         = frame_x
-    x_slider        = x_text + text_width + x_margin;
-    x_value         = x_slider + slider_width+x_margin;
-    x_unit          = x_value  + value_width+x_margin;
-
-    y               = frame_y-40;
-
-    // Title position
-    // =========================================================================
-
-    title_r = uicontrol(my_figure_handle                             , ...
-    "position"            , [x_text y title_width slider_height+y_margin]   , ...
-    "Style"               , "text"                                   , ...
-    "String"              , "Starting point"                         , ...
-    "BackgroundColor"     , [1 1 1]                                  , ...
-    "Fontsize"            , 16                                       , ...
-    "horizontalalignment" , "center"                                 , ...
-    "tag"                 , "title_r"                            );
-
-    // Slider "r"
-    // =========================================================================
-    y = y - (slider_height+y_margin)
-    text_r = uicontrol(my_figure_handle                              , ...
-    "position"          , [x_text y text_width slider_height]    , ...
-    "Style"             , "text"                                 , ...
-    "String"            , "r"                                    , ...
-    "BackgroundColor"   , [1 1 1]                                , ...
-    "tag"               , "text_r"                           );
-
-    slider_r = uicontrol(my_figure_handle                            , ...
-    "position"          , [x_slider y slider_width slider_height], ...
-    "Style"             , "slider"                               , ...
-    "Value"             , g_r                                 , ...
-    "Min"               , 0                                      , ...
-    "Max"               , 100                                      , ...
-    "callback"          , "change_r()"                           , ...
-    "tag"               , "slider_r"                         );
-
-    value_r = uicontrol(my_figure_handle                             , ...
-    "position"          , [x_value  y value_width slider_height] , ...
-    "Style"             , "text"                                 , ...
-    "String"            , string(g_r)                            , ...
-    "BackgroundColor"   , [1 1 1]                                , ...
-    "tag"               , "value_r"                          );
-
-    unite_r = uicontrol(my_figure_handle                             , ...
-    "position"          , [x_unit y unit_width slider_height]    , ...
-    "Style"             , "text"                                 , ...
-    "String"            , "(m)"                                  , ...
-    "BackgroundColor"   , [1 1 1]                                , ...
-    "tag"               , "unite_r"                          );
-
-    // Slider theta
-    // =========================================================================
-    y = y - (slider_height+y_margin)
-    text_theta = uicontrol(my_figure_handle                          , ...
-    "position"       , [x_text y text_width slider_height]       , ...
-    "Style"          , "text"                                    , ...
-    "String"         , "theta"                                   , ...
-    "BackgroundColor", [1 1 1]                                   , ...
-    "tag"            , "text_theta"                              );
-
-    slider_theta = uicontrol(my_figure_handle                        , ...
-    "position"  , [x_slider y slider_width slider_height]        , ...
-    "Style"     , "slider"                                       , ...
-    "Min"       , 0                                              , ...
-    "Max"       , 100                                            , ...
-    "Value"     , g_t                                            , ...
-    "callback"  , "change_theta()"                                   , ...
-    "tag"       , "slider_theta"                                 );
-
-    value_theta = uicontrol(my_figure_handle                         , ...
-    "position"        , [x_value  y value_width  slider_height]  , ...
-    "Style"           , "text"                                   , ...
-    "String"          , string(g_t)                              , ...
-    "BackgroundColor" , [1 1 1]                                  , ...
-    "tag"             , "value_theta"                            );
-
-    unite_theta = uicontrol(my_figure_handle                         , ...
-    "position"        , [x_unit y unit_width slider_height]      , ...
-    "Style"           , "text"                                   , ...
-    "String"          , "(deg)"                                  , ...
-    "BackgroundColor" , [1 1 1]                                  , ...
-    "tag"             , "unite_theta"                            );
-    //---------------------------------------------------------------------------
-    //second column
-    x_text          = frame_x + title_width + 3*x_margin
-    x_slider        = x_text + text_width + x_margin;
-    x_value         = x_slider + slider_width+x_margin;
-    x_unit          = x_value  + value_width+x_margin;
-
-    y               = frame_y-40;
-
-    // Title speed
-    // =========================================================================
-
-    title_speed = uicontrol(my_figure_handle                             , ...
-    "position"            , [x_text y title_width slider_height+y_margin],...
-    "Style"               , "text"                                   , ...
-    "String"              , "Initial speed"                          , ...
-    "BackgroundColor"     , [1 1 1]                                  , ...
-    "Fontsize"            , 16                                       , ...
-    "horizontalalignment" , "center"                                 , ...
-    "tag"                 , "title_speed"                            );
-
-    // Slider speed
-    // =========================================================================
-    y = y - (slider_height+y_margin)
-    text_speed = uicontrol(my_figure_handle                          , ...
-    "position"          , [x_text y text_width slider_height]    , ...
-    "Style"             , "text"                                 , ...
-    "String"            , "speed"                                , ...
-    "BackgroundColor"   , [1 1 1]                                , ...
-    "tag"               , "text_speed"                           );
-
-    slider_speed = uicontrol(my_figure_handle                        , ...
-    "position"          , [x_slider y slider_width slider_height], ...
-    "Style"             , "slider"                               , ...
-    "Value"             , g_speed                                , ...
-    "Min"               , 0                                      , ...
-    "Max"               , 100                                      , ...
-    "callback"          , "change_speed()"                       , ...
-    "tag"               , "slider_speed"                         );
-
-    value_speed = uicontrol(my_figure_handle                         , ...
-    "position"          , [x_value  y value_width slider_height] , ...
-    "Style"             , "text"                                 , ...
-    "String"            , string(g_speed)                        , ...
-    "BackgroundColor"   , [1 1 1]                                , ...
-    "tag"               , "value_speed"                          );
-
-    unite_speed = uicontrol(my_figure_handle                         , ...
-    "position"          , [x_unit y unit_width slider_height]    , ...
-    "Style"             , "text"                                 , ...
-    "String"            , "(m/s)"                                  , ...
-    "BackgroundColor"   , [1 1 1]                                , ...
-    "tag"               , "unite_speed"                          );
-
-    // Slider direction
-    // =========================================================================
-    y = y - (slider_height+y_margin)
-    text_dir = uicontrol(my_figure_handle                            , ...
-    "position"       , [x_text y text_width slider_height]       , ...
-    "Style"          , "text"                                    , ...
-    "String"         , "direction"                                   , ...
-    "BackgroundColor", [1 1 1]                                   , ...
-    "tag"            , "text_dir"                              );
-
-    slider_dir = uicontrol(my_figure_handle                          , ...
-    "position"  , [x_slider y slider_width slider_height]        , ...
-    "Style"     , "slider"                                       , ...
-    "Min"       , 0                                              , ...
-    "Max"       , 100                                            , ...
-    "Value"     , g_Vdir                                           , ...
-    "callback"  , "change_dir()"                                   , ...
-    "tag"       , "slider_dir"                                 );
-
-    value_dir = uicontrol(my_figure_handle                           , ...
-    "position"        , [x_value  y value_width  slider_height]  , ...
-    "Style"           , "text"                                   , ...
-    "String"          , string(g_Vdir)                              , ...
-    "BackgroundColor" , [1 1 1]                                  , ...
-    "tag"             , "value_dir"                            );
-
-    unite_dir = uicontrol(my_figure_handle                           , ...
-    "position"        , [x_unit y unit_width slider_height]      , ...
-    "Style"           , "text"                                   , ...
-    "String"          , "(deg)"                                  , ...
-    "BackgroundColor" , [1 1 1]                                  , ...
-    "tag"             , "unite_dir"                            );
-    // Buttons
-    // =========================================================================
-    y = y - (slider_height+5*y_margin)
-    btn_width=100;
-    btn_margin=50;
-    btn_height=20;
-    x=frame_x+80
-    start_button = uicontrol(my_figure_handle                                   , ...
-    "Position"             , [x y btn_width btn_height]                 , ...
-    "Style"                , "pushbutton"                               , ...
-    "String"               , "Start"                                    , ...
-    "Fontsize"             , 14                                         , ...
-    "BackgroundColor"      , [1 1 1]                                    , ...
-    "callback"             , "start_simu()"                             , ...
-    "tag"                  , "start_button"                             );
-
-    x=x+btn_width+btn_margin
-    stop_button = uicontrol(my_figure_handle                                    , ...
-    "Position"               , [x y btn_width btn_height]               , ...
-    "Style"                  , "pushbutton"                             , ...
-    "String"                 , "Stop"                                   , ...
-    "Fontsize"               , 14                                       , ...
-    "BackgroundColor"        , [1 1 1]                                  , ...
-    "callback"               , "stop_simu"                              , ...
-    "tag"                    , "stop_button"                            );
-
-    x=x+btn_width+btn_margin
-    clear_button = uicontrol(my_figure_handle                                   , ...
-    "Position"               , [x y btn_width btn_height]               , ...
-    "Style"                  , "pushbutton"                             , ...
-    "String"                 , "Clear"                                  , ...
-    "Fontsize"               , 14                                       , ...
-    "BackgroundColor"        , [1 1 1]                                  , ...
-    "callback"               , "clear_simu"                             , ...
-    "tag"                    , "clear_button"                           );
-
-    return
-endfunction
-
-// =============================================================================
-// The callbacks
-// =============================================================================
+    // =============================================================================
+    // The callbacks
+    // =============================================================================
 
 function change_r(r)
     //r slider callback
     // r is in [0 1]
-    slider_r     = findobj("tag", "slider_r");
-    slider_theta = findobj("tag", "slider_theta");
-    slider_speed = findobj("tag", "slider_speed");
-    slider_dir   = findobj("tag", "slider_dir");
-    slider_r     = findobj("tag", "slider_r");
+    slider_r     = get("slider_r");
+    slider_theta = get("slider_theta");
+    slider_speed = get("slider_speed");
+    slider_dir   = get("slider_dir");
+    slider_r     = get("slider_r");
 
-    value_r       = findobj("tag", "value_r");
+    value_r       = get("value_r");
     if argn(2)==1 then
         slider_r.Value=(r)*100;
     else
         r=slider_r.Value
         r=r/100
     end
-    value_r.String=msprintf("%.3f",r)
-    draw_initial_point(slider_r.Value/100,slider_theta.value*360/100,slider_speed.Value*20/100,slider_dir.value*360/100,%F);
-
+    value_r.String=msprintf("%.3f", r)
+    draw_initial_point(slider_r.Value/100, slider_theta.value*360/100, slider_speed.Value*20/100, slider_dir.value*360/100, %F);
 endfunction
 
 
 function change_theta(theta)
     //theta slider callback
     //theta is in [0 360]
-    slider_r     = findobj("tag", "slider_r");
-    slider_theta = findobj("tag", "slider_theta");
-    slider_speed = findobj("tag", "slider_speed");
-    slider_dir   = findobj("tag", "slider_dir");
-    slider_r     = findobj("tag", "slider_r");
+    slider_r     = get("slider_r");
+    slider_theta = get("slider_theta");
+    slider_speed = get("slider_speed");
+    slider_dir   = get("slider_dir");
+    slider_r     = get("slider_r");
 
-    value_theta   = findobj("tag", "value_theta");
+    value_theta   = get("value_theta");
     if argn(2)==1 then
         slider_theta.Value=(theta)*100/360;
     else
         theta=slider_theta.Value
         theta=theta*360/100
     end
-    value_theta.String=msprintf("%.0f",theta)
-    draw_initial_point(slider_r.Value/100,slider_theta.value*360/100,slider_speed.Value*20/100,slider_dir.value*360/100,%F);
+    value_theta.String=msprintf("%.0f", theta)
+    draw_initial_point(slider_r.Value/100, slider_theta.value*360/100, slider_speed.Value*20/100, slider_dir.value*360/100, %F);
 endfunction
 
 function change_speed(speed)
     //speed slider callback
     //speed is in [0 20]
-    slider_r     = findobj("tag", "slider_r");
-    slider_theta = findobj("tag", "slider_theta");
-    slider_speed = findobj("tag", "slider_speed");
-    slider_dir   = findobj("tag", "slider_dir");
+    slider_r     = get("slider_r");
+    slider_theta = get("slider_theta");
+    slider_speed = get("slider_speed");
+    slider_dir   = get("slider_dir");
 
-    value_speed  = findobj("tag", "value_speed");
+    value_speed  = get("value_speed");
     if argn(2)==1 then
         slider_speed.Value=(speed)*100/20;
     else
         speed=slider_speed.Value
         speed=speed*20/100
     end
-    value_speed.String=msprintf("%.0f",speed)
-    draw_initial_point(slider_r.Value/100,slider_theta.value*360/100,slider_speed.Value*20/100,slider_dir.value*360/100,%F);
+    value_speed.String=msprintf("%.0f", speed)
+    draw_initial_point(slider_r.Value/100, slider_theta.value*360/100, slider_speed.Value*20/100, slider_dir.value*360/100, %F);
 endfunction
 
 function change_dir(dir)
     //direction slider callback
     //dir is in [0 360]
-    slider_r      = findobj("tag", "slider_r");
-    slider_theta  = findobj("tag", "slider_theta");
-    slider_speed  = findobj("tag", "slider_speed");
-    slider_dir    = findobj("tag", "slider_dir");
-    value_dir     = findobj("tag", "value_dir");
+    slider_r      = get("slider_r");
+    slider_theta  = get("slider_theta");
+    slider_speed  = get("slider_speed");
+    slider_dir    = get("slider_dir");
+    value_dir     = get("value_dir");
     if argn(2)==1 then
         slider_dir.Value=(dir)*100/360;
     else
         dir=slider_dir.Value
         dir=dir*360/100
     end
-    value_dir.String=msprintf("%.0f",dir)
-    draw_initial_point(slider_r.Value/100,slider_theta.value*360/100,slider_speed.Value*20/100,slider_dir.value*360/100,%F);
+    value_dir.String=msprintf("%.0f", dir)
+    draw_initial_point(slider_r.Value/100, slider_theta.value*360/100, slider_speed.Value*20/100, slider_dir.value*360/100, %F);
 endfunction
 
 function start_simu()
     //start button callback
-    my_figure_handle           = scf(100001);
+    my_figure_handle           = get("main_figure");
     fin                        = my_figure_handle.user_data
     my_figure_handle.user_data = %f
 
-    slider_r     = findobj("tag", "slider_r");
-    slider_theta = findobj("tag", "slider_theta");
-    slider_speed = findobj("tag", "slider_speed");
-    slider_dir   = findobj("tag", "slider_dir");
+    slider_r     = get("slider_r");
+    slider_theta = get("slider_theta");
+    slider_speed = get("slider_speed");
+    slider_dir   = get("slider_dir");
     t =            0:0.01:15
-    Y = calculate_traj(slider_r.Value/100,slider_theta.value*360/100, ...
-    slider_speed.Value*20/100,slider_dir.value*360/100,t)
-    x = Y(1,:)
-    y = Y(3,:)
+    Y = calculate_traj(slider_r.Value/100, slider_theta.value*360/100, ...
+        slider_speed.Value*20/100, slider_dir.value*360/100, t)
+    x = Y(1, :)
+    y = Y(3, :)
     r = 0.1; //bias to have the curve above the surface
     z = -sqrt(1-x.^2-y.^2)+r;
-    my_figure_handle = scf(100001);
+    my_figure_handle = get("main_figure");
     curAxe = gca();
     traj_handle=curAxe.children(1).children(5);
-    traj_handle.data=[x(1),y(1),z(1)];
-    for k=2:size(x,"*")
+    traj_handle.data=[x(1), y(1), z(1)];
+    for k=2:size(x, "*")
         sleep(10)
-        if execstr("fin=my_figure_handle.user_data","errcatch")<>0|fin then break,end
-        traj_handle.data=[traj_handle.data;[x(k),y(k),z(k)]];
+        if execstr("fin=my_figure_handle.user_data", "errcatch")<>0|fin then break, end
+        traj_handle.data=[traj_handle.data;[x(k), y(k), z(k)]];
     end
     my_figure_handle.user_data=%t
 endfunction
 
 function stop_simu()
     //stop button callback
-    my_figure_handle = scf(100001);
-    fin   = %T;
+    my_figure_handle = get("main_figure");
+    fin = %T;
     my_figure_handle.user_data=fin
 endfunction
 
 function clear_simu()
     //clear button callback
-    my_figure_handle = scf(100001);
+    my_figure_handle = get("main_figure");
     fin=my_figure_handle.user_data
     if fin then
-        my_figure_handle = scf(100001);
+        my_figure_handle = get("main_figure");
         curAxe = gca();
         traj_handle=curAxe.children(1).children(5);
-        traj_handle.data=[0,0,0];
+        traj_handle.data=[0, 0, 0];
     end
 endfunction