summaryrefslogtreecommitdiff
path: root/modules/gui/demos/cb_uicontrol_plot3d.dem.sci
blob: 05cad018e2bad741e0fce30eeb91d1c2233cac34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2008 - INRIA - Pierre MARECHAL
// Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
//

function uicontrol_plot3d()
    demo_plot3d = figure( ...
        "dockable", "off", ...
        "infobar_visible", "off", ...
        "toolbar_visible", "off", ...
        "toolbar", "none", ...
        "menubar_visible", "on", ...
        "menubar", "none", ...
        "default_axes", "off", ...
        "layout", "border", ...
        "visible", "off");

    fakeframe_height = 10;
    demo_plot3d.figure_id       = 100001;
    demo_plot3d.background      = -2;
    demo_plot3d.color_map       = jetcolormap(128);
    demo_plot3d.figure_position = [0 0];
    demo_plot3d.figure_name     = gettext("Control Plot3d");
    demo_plot3d.axes_size       = [900 450];

    // New menu
    h = uimenu(demo_plot3d, ...
        "label" , gettext("File"));

    uimenu(h, ...
        "label"     , gettext("Close"), ...
        "callback"  , "demo_plot3d=get_figure_handle(100001);delete(demo_plot3d);", ...
        "tag"       , "close_menu");

    demo_viewCode(SCI+ "/modules/gui/demos/cb_uicontrol_plot3d.dem.sci");

    frame_left = uicontrol(demo_plot3d, ...
        "style", "frame", ...
        "constraints", createConstraints("border", "left", [250, 0]), ...
        "border", createBorder("titled", createBorder("line", "lightGray", 1), _("Control Panel"), "center", "below_top", createBorderFont("", 16, "normal"), "black"), ...
        "backgroundcolor", [1 1 1], ...
        "layout", "gridbag");

    //angle
    frame_angle = uicontrol(frame_left, ...
        "style", "frame", ...
        "backgroundcolor", [1 1 1], ...
        "constraints", createConstraints("gridbag", [1, 2, 1, 1], [0, 0], "both", "center"), ...
        "border", createBorder("titled", createBorder("line", "lightGray", 1), _("Rotation angle"), "center", "top", createBorderFont("", 11, "normal"), "black"), ...
        "layout", "border");

    uicontrol(frame_angle, ...
        "style", "slider", ...
        "backgroundcolor", [1 1 1], ...
        "value", 70, ...
        "min", 0, ...
        "max", 360, ...
        "sliderstep", [2, 30], ...
        "callback", "update_plot3d_angle");

    //colormap
    frame_colormap = uicontrol(frame_left, ...
        "style", "frame", ...
        "backgroundcolor", [1 1 1], ...
        "constraints", createConstraints("gridbag", [1, 3, 1, 1], [0, 0], "both", "center"), ...
        "border", createBorder("titled", createBorder("line", "lightGray", 1), _("Colormap"), "center", "top", createBorderFont("", 11, "normal"), "black"), ...
        "layout_options", createLayoutOptions("grid", [3, 1]));

    frame_colormap.layout = "grid";

    uicontrol(frame_colormap, ...
        "style", "radiobutton", ...
        "backgroundcolor", [1 1 1], ...
        "tag", "graycolormap", ...
        "string", "Graycolormap", ...
        "groupname", "colormap", ...
        "callback", "update_colormap");

    uicontrol(frame_colormap, ...
        "style", "radiobutton", ...
        "backgroundcolor", [1 1 1], ...
        "tag", "hotcolormap", ...
        "string", "Hotcolormap", ...
        "groupname", "colormap", ...
        "callback", "update_colormap");

    jet = uicontrol(frame_colormap, ...
        "tag", "jetcolormap", ...
        "backgroundcolor", [1 1 1], ...
        "style", "radiobutton", ...
        "string", "Jetcolormap", ...
        "groupname", "colormap", ...
        "callback", "update_colormap");

    jet.value = 1;

    //background
    frame_background = uicontrol(frame_left, ...
        "style", "frame", ...
        "backgroundcolor", [1 1 1], ...
        "constraints", createConstraints("gridbag", [1, 4, 1, 1], [0, 0], "both", "center"), ...
        "border", createBorder("titled", createBorder("line", "lightGray", 1), _("Background Color"), "center", "top", createBorderFont("", 11, "normal"), "black"), ..
        "layout", "border");

    uicontrol(frame_background, ...
        "tag", "button", ...
        "style", "pushbutton", ...
        "backgroundcolor", [1 1 1], ...
        "relief", "raised", ...
        "constraints", createConstraints("border", "center", [30 30]), ...
        "string", "Color picker", ...
        "callback", "update_background_color");

    //Show/hide
    frame_style = uicontrol(frame_left, ...
        "style", "frame", ...
        "backgroundcolor", [1 1 1], ...
        "constraints", createConstraints("gridbag", [1, 5, 1, 1], [1, 0], "both", "center"), ...
        "border", createBorder("titled", createBorder("line", "lightGray", 1), _("Show / Hide"), "center", "top", createBorderFont("", 11, "normal"), "black"), ...
        "layout_options", createLayoutOptions("grid", [4, 1]));

    frame_style.layout = "grid";

    uicontrol(frame_style, ...
        "style", "checkbox", ...
        "backgroundcolor", [1 1 1], ...
        "value", 1, ...
        "string", "Edges", ...
        "callback", "update_edges_visible");

    uicontrol(frame_style, ...
        "style", "checkbox", ...
        "backgroundcolor", [1 1 1], ...
        "value", 1, ...
        "string", "Labels", ...
        "callback", "update_labels_visible");

    uicontrol(frame_style, ...
        "style", "checkbox", ...
        "backgroundcolor", [1 1 1], ...
        "value", 1, ...
        "string", "Title", ...
        "callback", "update_title_visible");

    uicontrol(frame_style, ...
        "style", "checkbox", ...
        "backgroundcolor", [1 1 1], ...
        "value", 1, ...
        "string", "Tics", ...
        "callback", "update_tics_visible");

    //Title
    frame_style = uicontrol(frame_left, ...
        "style", "frame", ...
        "backgroundcolor", [1 1 1], ...
        "constraints", createConstraints("gridbag", [1, 6, 1, 1], [1, 0], "both", "center"), ...
        "border", createBorder("titled", createBorder("line", "lightGray", 1), _("Title"), "center", "top", createBorderFont("", 11, "normal"), "black"), ...
        "layout", "border");

    uicontrol(frame_style, ...
        "style", "edit", ...
        "backgroundcolor", [1 1 1], ...
        "string", "My Beautiful Plot", ...
        "callback", "update_title_string", ...
        "tag", "title");

    frame_style = uicontrol(frame_left, ...
        "style", "frame", ...
        "backgroundcolor", [1 1 1], ...
        "constraints", createConstraints("gridbag", [1, 7, 1, 1], [1, 1], "both", "center"));

    //Plot
    frame_right = uicontrol(demo_plot3d, ...
        "style", "frame", ...
        "layout", "border", ...
        "constraints", createConstraints("border", "center"));


    newaxes(frame_right);
    demo_plot3d.immediate_drawing = "off";
    plot3d();

    a = gca();
    a.tag                   = "plot";
    a.title.text            = "My Beautiful Plot";
    a.title.font_size       = 5;
    a.rotation_angles(1)    = 70;

    a.x_label.text          = "X";
    a.y_label.text          = "Y";
    a.z_label.text          = "Z";

    demo_plot3d.immediate_drawing     = "on";

    demo_plot3d.visible     = "on";
endfunction





function update_plot3d_angle()

    my_plot_axes = gca();
    my_new_angle = get(gcbo,"value");

    if( my_new_angle>0 & my_new_angle<360 ) then
        my_plot_axes.rotation_angles(2) = my_new_angle;
    end

endfunction

function update_colormap()

    my_figure    = gcf();
    my_plot_axes = gca();

    my_cur_color_map    = my_figure.color_map;
    my_cur_bg_color_id  = my_plot_axes.background;

    if my_cur_bg_color_id > 32 then
        my_cur_bg_color_r = my_cur_color_map(my_cur_bg_color_id,1);
        my_cur_bg_color_g = my_cur_color_map(my_cur_bg_color_id,2);
        my_cur_bg_color_b = my_cur_color_map(my_cur_bg_color_id,3);
    end

    if get(gcbo, "tag") == "jetcolormap" then
        my_figure.color_map = jetcolormap(128);
    elseif get(gcbo, "tag") == "hotcolormap" then
        my_figure.color_map = hotcolormap(128);
    elseif get(gcbo, "tag") == "graycolormap" then
        my_figure.color_map = graycolormap(128);
    end

    if my_cur_bg_color_id > 32 then

        color_id = color( ..
        my_cur_bg_color_r*255, ..
        my_cur_bg_color_g*255, ..
        my_cur_bg_color_b*255  ..
        );

        my_plot_axes.background = color_id;
    end

endfunction

function update_background_color()

    // Lancement du colorchooser
    [my_red, my_green, my_blue] = uigetcolor();

    if( (my_red<>[]) & (my_green<>[]) & (my_blue<>[]) ) then

        set(gcbo,"BackgroundColor",[ my_red/255 my_green/255 my_blue/255 ]);

        my_plot_axes            = gca();
        color_id                = color(my_red,my_green,my_blue);
        my_plot_axes.background = color_id;

    end

endfunction

function update_tics_visible()

    my_plot_axes = gca();

    if get(gcbo,"value") == 0 then
        my_plot_axes.axes_visible = ["off" "off" "off" ];
    else
        my_plot_axes.axes_visible = ["on" "on" "on" ];
    end

endfunction

function update_title_visible()

    my_plot_axes = gca();

    if get(gcbo,"value") == 0 then
        my_plot_axes.title.visible = "off";
    else
        my_plot_axes.title.visible = "on";
    end

endfunction

function update_labels_visible()

    my_plot_axes = gca();

    if get(gcbo,"value") == 0 then
        my_plot_axes.x_label.visible = "off";
        my_plot_axes.y_label.visible = "off";
        my_plot_axes.z_label.visible = "off";
    else
        my_plot_axes.x_label.visible = "on";
        my_plot_axes.y_label.visible = "on";
        my_plot_axes.z_label.visible = "on";
    end

endfunction

function update_edges_visible()

    my_plot_axes = gca();
    my_plot3d    = my_plot_axes.children($);

    if get(gcbo,"value") == 0 then
        my_plot3d.color_mode = -1;
    else
        my_plot3d.color_mode = +1;
    end

endfunction

function update_title_string

    my_plot_axes = gca();
    my_plot_axes.title.text = get(gcbo,"string");

endfunction