2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2008 - INRIA - Pierre MARECHAL
4 // Copyright (C) 2014 - Scilab Enterprises - Pierre-Aime Agnel
6 // This file is distributed under the same license as the Scilab package.
9 // =============================================================================
10 // BlackHole interface functions
11 // =============================================================================
13 // =============================================================================
14 function exeblackhole()
24 surface_frame_w = 600; // surface frame width
25 surface_frame_h = 600; // surface frame height
27 control_frame_w = 600;
28 control_frame_h = 200;
30 margin_x = 15; // Horizontal margin between each elements
31 margin_y = 15; // Vertical margin between each elements
33 axes_figure_w = 2 * margin_x + max(surface_frame_w, control_frame_w);
34 axes_figure_h = 3 * margin_y + surface_frame_h + control_frame_h;
37 my_figure_handle = createMainWindow([axes_figure_w axes_figure_h], _("Blackhole"), "main_figure");
38 my_figure_handle.immediate_drawing = "off";
40 //Simulation parameters
41 speed = tlist(["sim_param", "name", "unit", "range", "default", "tag"], ...
48 direction = tlist(["sim_param", "name", "unit", "range", "default", "tag"], ...
55 r = tlist(["sim_param", "name", "unit", "range", "default", "tag"], ...
62 theta = tlist(["sim_param", "name", "unit", "range", "default", "tag"], ...
69 //Create the controls in the window bottom
70 param_list = list(r, theta, speed, direction);
71 [plot_frame, param_frame, button_frame] = create_gui(my_figure_handle);
72 create_param_zone(param_frame, param_list);
73 create_buttons(button_frame);
77 draw_initial_point(g_r, g_t, g_V, g_Vdir, %T);
80 //Set control and graphics initial values
85 my_figure_handle.visible = "on";
89 // =============================================================================
90 function draw_blackhole()
94 yy = (-1.85:0.1:1.85)';
95 zt = sqrt((ones(yy)*(xx .^ 2) + (yy .^ 2) * ones(xx)));
96 zz = -1 * ones(zt) ./ zt;
98 my_handle = get("main_figure");
100 my_handle.immediate_drawing = "off";
104 e.foreground = color("blue");
105 my_handle.immediate_drawing = "on";
108 // draw_initial_point
109 // =============================================================================
110 function draw_initial_point(g_r, g_t, g_V, g_Vdir, create)
111 x = g_r * cos(g_t * %pi / 180);
112 y = g_r * sin(g_t * %pi / 180);
114 z = -1.0 ./ sqrt(x ^ 2 + y ^ 2) + r;
115 dx1 = g_V * cos(g_Vdir * %pi / 180);
116 dy1 = g_V * sin(g_Vdir * %pi / 180);
117 my_figure_handle = get("main_figure");
118 my_figure_handle.immediate_drawing = "off";
121 //create the graphical object used to visualize the trajectory
124 traj_handle.thickness = 2;
125 traj_handle.foreground = 5;
126 //create the graphical object used to visualize the initial speed
128 speed_handle = gce();
129 speed_handle.thickness = 1;
130 speed_handle.foreground = 5;
131 speed_handle.polyline_style = 4;
132 speed_handle.arrow_size_factor = 2;
133 //create the graphical objects used to visualize the initial position
134 param3d([x - r x + r], [y y], [z z]);
138 param3d([x x], [y - r y + r], [z z]);
142 param3d([x x], [y y], [z - r z + r]);
146 glue([traj_handle speed_handle e1 e2 e3])
149 initial = curAxe.children(1).children
150 initial(1).data = [x y z - r ; x y z + r];
151 initial(2).data = [x y - r z ; x y + r z];
152 initial(3).data = [x - r y z ; x + r y z];
154 z1= -1.0 ./ sqrt((x + dx1) ^ 2 + (y + dy1) ^ 2) + r;
155 initial(4).data = [x y z ; x + dx1 y + dy1 z1];
157 my_figure_handle.immediate_drawing = "on";
160 // =============================================================================
161 // The gui controls builder
162 // =============================================================================
163 function blackhole_create_gui()
170 my_figure_handle = get("main_figure");
182 title_width = text_width + slider_width + value_width + unit_width + 3 * x_margin
185 x_slider = x_text + text_width + x_margin;
186 x_value = x_slider + slider_width + x_margin;
187 x_unit = x_value + value_width + x_margin;
191 //Create the constraints for the gridbag simulation zone / position + speed frames
192 gen_c = createConstraints("border", "bottom", [600 200]);
194 //Create the layout options for the frame containing position and speed frames
195 //1by2 grid with 20 pixel horizontal space for minimum padding
196 posspeed_lay_opt = createLayoutOptions("grid", [1 2], [20 0]);
199 gui_frame = uicontrol(my_figure_handle, ...
200 "style", "frame", ...
201 "backgroundcolor", [1 1 1], ...
202 "layout", "border", ...
203 "constraint", gen_c);
205 //Frame containing position and speed
206 gen_c.position = "center";
207 frame_posspeed = uicontrol(gui_frame, ...
208 "style", "frame", ...
209 "backgroundcolor", [1 1 1], ...
210 "layout", "grid", ...
211 "layout_options", posspeed_lay_opt, ...
212 "constraint", gen_c);
214 //Borders and title around position or speed
215 b_f_posspeed = createBorderFont("", 16);
216 b_l_posspeed = createBorder("line", "navy", 1);
217 b_posspeed = createBorder("titled", b_l_posspeed, "starting point", "center", "top", b_f_posspeed, "navy");
219 //Create the internal layout options for the position and speed frames
220 //2by1 grid with 10 pixel vertical space for minimum padding
221 grid_lay_opt = createLayoutOptions("grid", [2 1], [0 10]);
224 //title initial speed
225 //vertical grid: speed_frame | 10 | direction_frame
226 b_posspeed.title = "initial speed";
227 frame_initspeed = uicontrol(frame_posspeed, ...
228 "style", "frame", ...
229 "backgroundcolor", [1 1 1], ...
230 "layout", "gridbag", ...
231 "border", b_posspeed);
233 //speed and direction in initspeed
234 c = createConstraints("gridbag", [1 1 1 1], [1 1], "horizontal", "center", [0 0], [0 20]);
236 speed_frame = uicontrol(frame_initspeed, ...
237 "style", "frame", ...
238 "backgroundcolor", [1 1 1], ...
239 "layout", "gridbag", ...
242 createSliderFrame(speed_frame, "speed", "speed", "(m/s)");
245 direction_frame = uicontrol(frame_initspeed, ...
246 "style", "frame", ...
247 "backgroundcolor", [1 1 1], ...
248 "layout", "gridbag", ...
251 createSliderFrame(direction_frame, "dir", "dir", "(deg)");
252 //Frame initpositiono
253 //titled starting point
254 //vertical grid: r_frame | 10 | theta_frame
255 b_posspeed.title = "initial position";
256 frame_initposition = uicontrol(frame_posspeed, ...
257 "style", "frame", ...
258 "backgroundcolor", [1 1 1], ...
259 "layout", "gridbag", ...
260 "border", b_posspeed);
263 r_frame = uicontrol(frame_initposition, ...
264 "style", "frame", ...
265 "backgroundcolor", [1 1 1], ...
266 "layout", "gridbag", ...
269 createSliderFrame(r_frame, "r", "r", "(m)");
272 theta_frame = uicontrol(frame_initposition, ...
273 "style", "frame", ...
274 "backgroundcolor", [1 1 1], ...
275 "layout", "gridbag", ...
278 createSliderFrame(theta_frame, "theta", "theta", "(deg)");
281 //esthetic | button 1 | est | button2 | est | button 3 | est
282 gen_c.position = "bottom"
283 gen_c.preferredsize = [0 30];
284 button_frame = uicontrol(gui_frame, ...
285 "style", "frame", ...
286 "backgroundcolor", [1 1 1], ...
287 "layout", "gridbag", ...
288 "constraints", gen_c);
291 // est | buttons | est
292 // =========================================================================
298 c_button = createConstraints("gridbag", [1 1 1 1], [0 0], "none", "left", [0 0], [100 0]);
300 //Esthetic Empty panel
301 est_panel = uicontrol(button_frame, ...
302 "style", "frame", ...
303 "backgroundcolor", [1 1 1], ...
304 "constraints", c_button);
307 buttonBorder = createBorder("line", "darkgrey", 3);
308 c_button = createConstraints("gridbag", [2 1 1 1], [0 0], "both", "left", [0 0])
310 c_button.anchor = "left"
311 start_button = uicontrol(button_frame, ...
312 "Style", "pushbutton", ...
313 "String", "Start", ...
315 "BackgroundColor", [0.9 0.9 0.9], ...
316 "callback", "start_simu()", ...
317 "border", buttonBorder, ...
318 "tag", "start_button", ...
319 "constraints", c_button);
322 c_button = createConstraints("gridbag", [3 1 1 1], [0 0], "none", "center", [0 0], [20 0])
323 est_panel = uicontrol(button_frame, ...
324 "style", "frame", ...
325 "backgroundcolor", [1 1 1], ...
326 "constraints", c_button);
329 c_button = createConstraints("gridbag", [4 1 1 1], [0 0], "both", "center", [0 0])
330 stop_button = uicontrol(button_frame, ...
331 "Style", "pushbutton", ...
332 "String", "Stop", ...
334 "BackgroundColor", [0.9 0.9 0.9], ...
335 "border", buttonBorder, ...
336 "callback", "stop_simu", ...
337 "tag", "stop_button", ...
338 "constraints", c_button);
341 c_button = createConstraints("gridbag", [5 1 1 1], [0 0], "none", "center", [0 0], [20 0])
342 est_panel = uicontrol(button_frame, ...
343 "style", "frame", ...
344 "backgroundcolor", [1 1 1], ...
345 "constraints", c_button);
348 c_button = createConstraints("gridbag", [6 1 1 1], [0 0], "both", "center", [0 0])
349 clear_button = uicontrol(button_frame, ...
350 "Style", "pushbutton", ...
351 "String", "Clear", ...
353 "BackgroundColor", [0.9 0.9 0.9], ...
354 "callback", "clear_simu", ...
355 "border", buttonBorder, ...
356 "tag", "clear_button", ...
357 "constraints", c_button);
360 c_button = createConstraints("gridbag", [7 1 1 1], [0 0], "none", "right", [100 0]);
361 est_panel = uicontrol(button_frame, ...
362 "style", "frame", ...
363 "backgroundcolor", [1 1 1], ...
364 "constraints", c_button);
369 // =============================================================================
371 // =============================================================================
375 slider_r = get("slider_r");
376 slider_theta = get("slider_theta");
377 slider_speed = get("slider_speed");
378 slider_dir = get("slider_dir");
379 slider_r = get("slider_r");
381 value_r = get("value_r");
383 slider_r.Value=(r-0.007)/(2-0.08)*100;
386 r=0.007+r*(2-0.08)/100
388 value_r.String=msprintf("%.3f", r)
389 draw_initial_point(0.007+slider_r.Value*(2-0.08)/100, slider_theta.value*360/100, ...
390 slider_speed.Value*3/100, slider_dir.value*360/100, %F);
394 function change_theta(theta)
395 //theta slider callback
396 //theta is in [0 360]
397 slider_r = get("slider_r");
398 slider_theta = get("slider_theta");
399 slider_speed = get("slider_speed");
400 slider_dir = get("slider_dir");
401 slider_r = get("slider_r");
403 value_theta = get("value_theta");
405 slider_theta.Value=(theta)*100/360;
407 theta=slider_theta.Value
410 value_theta.String=msprintf("%.0f", theta)
411 draw_initial_point(0.007+slider_r.Value*(2-0.08)/100, slider_theta.value*360/100, ..
412 slider_speed.Value*3/100, slider_dir.value*360/100, %F);
415 function change_speed(speed)
416 //speed slider callback
418 slider_r = get("slider_r");
419 slider_theta = get("slider_theta");
420 slider_speed = get("slider_speed");
421 slider_dir = get("slider_dir");
423 value_speed = get("value_speed");
425 slider_speed.Value=(speed)*100/3;
427 speed=slider_speed.Value
430 value_speed.String=msprintf("%.0f", speed)
431 draw_initial_point(0.007+slider_r.Value*(2-0.08)/100, slider_theta.value*360/100, ..
432 slider_speed.Value*3/100, slider_dir.value*360/100, %F);
435 function change_dir(dir)
436 //direction slider callback
438 slider_r = get("slider_r");
439 slider_theta = get("slider_theta");
440 slider_speed = get("slider_speed");
441 slider_dir = get("slider_dir");
442 value_dir = get("value_dir");
445 slider_dir.Value = dir * 100 / 360;
447 dir = slider_dir.Value
448 dir = dir * 360 / 100
451 value_dir.String = msprintf("%.0f", dir)
452 draw_initial_point(0.007 + slider_r.Value * (2 - 0.08) / 100, slider_theta.value * 360 / 100, ...
453 slider_speed.Value * 3 / 100, slider_dir.value * 360 / 100, %F);
456 function start_simu()
457 //start button callback
458 my_figure_handle = get("main_figure");
459 fin=my_figure_handle.user_data
460 my_figure_handle.user_data=%f
461 set("clear_button", "userdata", %f);
462 slider_r = get("slider_r");
463 slider_theta = get("slider_theta");
464 slider_speed = get("slider_speed");
465 slider_dir = get("slider_dir");
467 Y = calculate_traj(0.007 + slider_r.Value * (2 - 0.08) / 100, slider_theta.value * 360 / 100, ...
468 slider_speed.Value * 3 / 100, slider_dir.value * 360 / 100, t)
471 r = 0.1; //bias to have the curve above the surface
472 z = -1.0 ./ sqrt(x .^ 2 + y .^ 2) + r;
474 traj_handle = curAxe.children(1).children(5);
475 traj_handle.data = [x(1) y(1) z(1)];
479 if is_handle_valid(my_figure_handle) then
480 if execstr("fin = my_figure_handle.user_data", "errcatch") <> 0 | fin then break, end
481 if is_handle_valid(traj_handle) then
482 traj_handle.data = [traj_handle.data ; [x(k) y(k) z(k)]];
491 if get("clear_button", "userdata") then
495 if is_handle_valid(my_figure_handle) then
496 my_figure_handle.user_data = %t;
501 set("main_figure", "userdata", %t);
502 set("clear_button", "userdata", %f);
505 function clear_simu()
506 //clear button callback
507 my_figure_handle = get("main_figure");
508 fin = my_figure_handle.user_data
511 traj_handle = curAxe.children(1).children(5);
512 traj_handle.data = [0 0 0];
515 set("main_figure", "userdata", %t);
516 set("clear_button", "userdata", %t);