summaryrefslogtreecommitdiff
path: root/2.3-1/macros/sci2c_gui.sci
blob: cad8b24712bfc5267238ea5ee5bf06a1f335f9a8 (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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
//
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2009 - INRIA - Vincent COUVERT
//
// 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-en.txt
//

function sci2c_gui()

// Sizes
widgeth = 20;
widgetLabelWidth = 220;
btnh = 22;
btnw = 80;
defaultfont = "arial";
margin = 13;
radiow = 85;

// Figure creation
sci2cfig = figure("figure_name", gettext("Scilab to C conversion tool"),"tag","sci2cfig");

// Remove Scilab graphics menus & toolbar
delmenu(sci2cfig.figure_id, gettext("&File"));
delmenu(sci2cfig.figure_id, gettext("&Tools"));
delmenu(sci2cfig.figure_id, gettext("&Edit"));
delmenu(sci2cfig.figure_id, gettext("&?"));
toolbar(sci2cfig.figure_id, "off");

h = uimenu("parent", sci2cfig, "label", gettext("File"));
uimenu("parent", h, "label", gettext("Close"), "callback", "cb_sci2c_gui", "tag", "close_menu");

h = uimenu("parent", sci2cfig, "label", gettext("?"));
uimenu("parent", h, "label", gettext("Sci2c help page"), "callback", "cb_sci2c_gui", "tag", "sci2c_help_menu");
uimenu("parent", h, "label", gettext("About SCI2C tools..."), "callback", "cb_sci2c_gui", "tag", "about_sci2c_menu");

figw = 800;
figh = 16*margin + btnh + 10*widgeth;
sci2cfig.axes_size = [figw figh];
sci2cfig.auto_resize = "on";
//sci2cfig.visible = "off"; // to be sure that no plot can appear in the window

//-------------------
// --- Validation ---
//-------------------

// Convert button
convertbtn = uicontrol("parent", sci2cfig,...
    "backgroundcolor", [0.8 0.8 0.8],...
    "style", "pushbutton",...
    "string", gettext("Convert"),...
    "position", [figw-2*margin-2*btnw margin btnw btnh],...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "tag","convertbtn",...
    "callback","cb_sci2c_gui");

// Cancel button
cancelbtn = uicontrol("parent", sci2cfig,...
    "backgroundcolor", [0.8 0.8 0.8],...
    "style", "pushbutton",...
    "string", gettext("Cancel"),...
    "position", [figw-margin-btnw margin btnw btnh],...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "tag", "cancelbtn",...
    "callback","cb_sci2c_gui");

//----------------
// --- Options ---
//----------------
// Frame
optframe = uicontrol("parent", sci2cfig,...
    "relief", "groove",...
    "style", "frame",...
    "units", "pixels",...
    "position", [margin 2*margin+btnh figw-2*margin 7*margin+6*widgeth],...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "fontweight", "bold", ...
    "horizontalalignment", "center");
// Frame title
opttitle = uicontrol("parent", sci2cfig,...
    "style", "text",...
    "string", gettext("Options"),...
    "units", "pixels",...
    "position", [2*margin 5*margin+btnh+4*margin+6*widgeth-8 50 18],...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 11,...
    "horizontalalignment", "center");

// --- Building Tool ---
buildtooly = 2 * margin + 2 * btnh + margin;
buildtoollabel = uicontrol("parent", sci2cfig,...
    "style", "text",...
    "string", gettext("Tool to compile generated C code: "),...
    "position",[2*margin buildtooly widgetLabelWidth widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12);
buildtoolradiowin = uicontrol("parent", sci2cfig,...
    "style", "radiobutton",...
    "string", gettext("nmake for Windows with Visual Studio / Visual Express"),...
    "position",[2*margin+widgetLabelWidth buildtooly 5 * radiow widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "min", 0, ...
    "max", 1, ...
    "callback", "cb_sci2c_gui",...
    "tag", "buildtoolradiowin");
buildtoolradiounix = uicontrol("parent", sci2cfig,...
    "style", "radiobutton",...
    "string", gettext("make for Unix / Windows with Cygwin"),...
    "position",[2*margin+widgetLabelWidth buildtooly-widgeth 5 * radiow widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "min", 0, ...
    "max", 1, ...
    "callback", "cb_sci2c_gui",...
    "tag", "buildtoolradiounix");
if getos() == "Windows"
  set(buildtoolradiowin, "value", 1);
  set(buildtoolradiounix, "value", 0);
else
  set(buildtoolradiowin, "value", 0);
  set(buildtoolradiounix, "value", 1);
end

// --- Copy Scilab code into C option ---
sciintocy = buildtooly + margin + btnh ;
sciintoclabel = uicontrol("parent", sci2cfig,...
    "style", "text",...
    "string", gettext("Copy Scilab code into C: "),...
    "position",[2*margin sciintocy widgetLabelWidth widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12);
sciintocradioyes = uicontrol("parent", sci2cfig,...
    "style", "radiobutton",...
    "string", gettext("Yes"),...
    "position",[2*margin+widgetLabelWidth sciintocy radiow widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "min", 0, ...
    "max", 1, ...
    "value", 0,...
    "callback", "cb_sci2c_gui",...
    "tag", "sciintocradioyes");
sciintocradiono = uicontrol("parent", sci2cfig,...
    "style", "radiobutton",...
    "string", gettext("No"),...
    "position",[2*margin+widgetLabelWidth+radiow sciintocy radiow widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "min", 0, ...
    "max", 1, ...
    "value", 1,...
    "callback", "cb_sci2c_gui",...
    "tag", "sciintocradiono");

// --- Board Name ----
brdnmy = sciintocy + margin + btnh ;
brdnmlabel = uicontrol("parent", sci2cfig,...
    "style", "text",...
    "string", gettext("Board Name: "),...
    "position",[2*margin brdnmy widgetLabelWidth widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12);

brdnmType = uicontrol("parent", sci2cfig,...
    "style", "popupmenu",...
    "string", ["";"Uno";"Mega-ATmega1280";"Mega-2560 or Mega ADK";"Nano - ATmega168";"Nano - ATmega328";"Micro";"Mini - Atmega168";"Mini - Atmega328";"Pro Mini (3.3V, 8MHz) - ATmega328";"Pro Mini (3.3V, 8MHz) - ATmega168";"Pro Mini (5V, 16MHz) - ATmega328";"Pro Mini (5V, 16MHz) - ATmega168";"NG or older - ATmega168";"NG or older - ATmega8";"Duemilanove - ATmega328";"BT - ATmega328";"BT - ATmega 168";"Diecimila/Duemilanove - ATmega168";"Esplora";"Ethernet";"Fio";"Leonardo";"Robot Control";"Robot Motor";"LilyPad Arduino - ATmega328";"LilyPad Arduino - ATmega168";"LilyPad Arduino USB"],...
    "position",[2*margin+widgetLabelWidth brdnmy 3*radiow widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "enable", "off",...
    "fontunits", "points",...
    "fontsize", 12,...
    "min", 0, ...
    "max", 1, ...
    "value", [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0],...
    "callback", "cb_sci2c_gui",...
    "tag", "brdnmType");

sciintocy = brdnmy
// --- Output format: Standalone or Arduino
outformaty = sciintocy + margin + btnh ;
outformatlabel = uicontrol("parent", sci2cfig,...
    "style", "text",...
    "string", gettext("Type of output format: "),...
    "position",[2*margin outformaty widgetLabelWidth widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12);

outformatradiostalone = uicontrol("parent", sci2cfig,...
    "style", "radiobutton",...
    "string", gettext("Stand-alone"),...
    "position",[2*margin+widgetLabelWidth outformaty 2*radiow-10 widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "min", 0, ...
    "max", 1, ...
    "value", 1,...
    "callback", "cb_sci2c_gui",...
    "tag", "outformatradiostalone");

outformatradioarduino = uicontrol("parent", sci2cfig,...
    "style", "radiobutton",...
    "string", gettext("Arduino"),...
    "position",[margin+widgetLabelWidth+2*radiow outformaty radiow widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "min", 0, ...
    "max", 1, ...
    "value", 0,...
    "callback", "cb_sci2c_gui",...
    "tag", "outformatradioarduino");

outformatradioavr = uicontrol("parent", sci2cfig,...
    "style", "radiobutton",...
    "string", gettext("AVR"),...
    "position",[margin+widgetLabelWidth+3*radiow outformaty radiow widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "min", 0, ...
    "max", 1, ...
    "value", 0,...
    "callback", "cb_sci2c_gui",...
    "tag", "outformatradioavr");

outformatradiorpi = uicontrol("parent", sci2cfig,...
    "style", "radiobutton",...
    "string", gettext("Rpi"),...
    "position",[margin+widgetLabelWidth+4*radiow outformaty radiow widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "min", 0, ...
    "max", 1, ...
    "value", 0,...
    "callback", "cb_sci2c_gui",...
    "tag", "outformatradiorpi"); 


// --- Run mode option ---
runy = outformaty + margin + widgeth;
runlabel = uicontrol("parent", sci2cfig,...
    "style", "text",...
    "string", gettext("Run mode: "),...
    "position",[2*margin runy widgetLabelWidth widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12);
runradioall = uicontrol("parent", sci2cfig,...
    "style", "radiobutton",...
    "string", gettext("All"),...
    "position",[2*margin+widgetLabelWidth runy radiow widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "min", 0, ...
    "max", 1, ...
    "value", 1,...
    "callback", "cb_sci2c_gui",...
    "tag", "runradioall");
runradiotranslate = uicontrol("parent", sci2cfig,...
    "style", "radiobutton",...
    "string", gettext("Translate"),...
    "position",[2*margin+widgetLabelWidth+radiow runy radiow widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "min", 0, ...
    "max", 1, ...
    "value", 0,...
    "callback", "cb_sci2c_gui",...
    "tag", "runradiotranslate");
runradiogenlib = uicontrol("parent", sci2cfig,...
    "style", "radiobutton",...
    "string", gettext("Generate library"),...
    "position",[2*margin+widgetLabelWidth+2*radiow+20 runy 150 widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "min", 0, ...
    "max", 1, ...
    "value", 0,...
    "callback", "cb_sci2c_gui",...
    "tag", "runradiogenlib");

// ------------------------
// --- Output directory ---
// ------------------------
// Frame
optframemaxy = 5*margin+btnh + 4*margin+6*widgeth;
outframe = uicontrol("parent", sci2cfig,...
    "relief", "groove",...
    "style", "frame",...
    "units", "pixels",...
    "position", [margin optframemaxy+margin figw-2*margin widgeth+2*margin],...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "fontweight", "bold", ...
    "horizontalalignment", "center");
// Frame title
outtitle = uicontrol("parent", sci2cfig,...
    "style", "text",...
    "string", gettext("Output directory"),...
    "units", "pixels",...
    "position", [2*margin optframemaxy+margin+widgeth+2*margin-8 90 14],...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 11,...
    "horizontalalignment", "center");
outlabel = uicontrol("parent", sci2cfig,...
    "style", "text",...
    "string", gettext("Directory name: "),...
    "position",[2*margin optframemaxy+2*margin-1 100 widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12);
outedit = uicontrol("parent", sci2cfig,...
    "style", "edit",...
    "string", TMPDIR,...
    "units", "pixels",...
    "position",[3*margin+100 optframemaxy+2*margin-1 figw-6*margin-100-btnw widgeth],...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12, ...
    "tag", "outedit");
outbtn = uicontrol("parent", sci2cfig,...
    "backgroundcolor", [0.8 0.8 0.8],...
    "style", "pushbutton",...
    "string", gettext("Browse"),...
    "position",[figw-2*margin-btnw optframemaxy+2*margin btnw btnh],...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "callback", "cb_sci2c_gui",...
    "tag", "outbtn");

// -------------------------------
// --- SciLib main header file ---
// -------------------------------
// Frame
outframemaxy = optframemaxy + 2*margin + widgeth + margin;
// headerframe = uicontrol("parent", sci2cfig,...
//     "relief", "groove",...
//     "style", "frame",...
//     "units", "pixels",...
//     "position", [margin outframemaxy+margin figw-2*margin widgeth+2*margin],...
//     "fontname", defaultfont,...
//     "fontunits", "points",...
//     "fontsize", 12,...
//     "fontweight", "bold", ...
//     "horizontalalignment", "center");
// // Frame title
// headertitle = uicontrol("parent", sci2cfig,...
//     "style", "text",...
//     "string", gettext("Scilab library header"),...
//     "units", "pixels",...
//     "position", [2*margin outframemaxy+margin+widgeth+2*margin-8 110 14],...
//     "fontname", defaultfont,...
//     "fontunits", "points",...
//     "fontsize", 11,...
//     "horizontalalignment", "center");
// headerlabel = uicontrol("parent", sci2cfig,...
//     "style", "text",...
//     "string", gettext("File name: "),...
//     "position",[2*margin outframemaxy+2*margin-1 100 widgeth],...
//     "horizontalalignment", "left",...
//     "fontname", defaultfont,...
//     "fontunits", "points",...
//     "fontsize", 12);
// headeredit = uicontrol("parent", sci2cfig,...
//     "style", "edit",...
//     "string", gettext("<enter a file name>"),...
//     "units", "pixels",...
//     "position",[3*margin+100 outframemaxy+2*margin-1 figw-6*margin-100-btnw widgeth],...
//     "fontname", defaultfont,...
//     "fontunits", "points",...
//     "fontsize", 12, ...
//     "tag", "headeredit");
// headerbtn = uicontrol("parent", sci2cfig,...
//     "backgroundcolor", [0.8 0.8 0.8],...
//     "style", "pushbutton",...
//     "string", gettext("Browse"),...
//     "position",[figw-2*margin-btnw outframemaxy+2*margin btnw btnh],...
//     "fontname", defaultfont,...
//     "fontunits", "points",...
//     "fontsize", 12,...
//     "callback", "cb_sci2c_gui",...
//     "tag", "headerbtn");

// -------------------------
// --- File(s) selection ---
// -------------------------
// Frame
headerframemaxy = outframemaxy //+ 2*margin + widgeth + margin;
selframe = uicontrol("parent", sci2cfig,...
    "relief", "groove",...
    "style", "frame",...
    "units", "pixels",...
    "position", [margin headerframemaxy+margin figw-2*margin 3*margin+2*widgeth],...
    "fontname", "arial",...
    "fontunits", "points",...
    "fontsize", 12,...
    "fontweight", "bold", ...
    "horizontalalignment", "center");
// Frame title
seltitle = uicontrol("parent", sci2cfig,...
    "style", "text",...
    "string", gettext("Input file"),...
    "units", "pixels",...
    "position", [2*margin headerframemaxy+margin+3*margin+2*widgeth-8 50 14],...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 11,...
    "horizontalalignment", "center", ...
    "tag", "seltitle");

// --- Sub-functions selection ---
subfunslabel = uicontrol("parent", sci2cfig,...
    "style", "text",...
    "string", gettext("Sub-functions: "),...
    "position",[2*margin headerframemaxy+2*margin-1 100 widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12);
subfunsedit = uicontrol("parent", sci2cfig,...
    "style", "edit",...
    "string", "",...
    "units", "pixels",...
    "position",[3*margin+100 headerframemaxy+2*margin-1 figw-6*margin-100-btnw widgeth],...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12, ...
    "tag", "subfunsedit");
subfunsbtn = uicontrol("parent", sci2cfig,...
    "backgroundcolor", [0.8 0.8 0.8],...
    "style", "pushbutton",...
    "string", gettext("Browse"),...
    "position",[figw-2*margin-btnw headerframemaxy+2*margin btnw btnh],...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "callback", "cb_sci2c_gui",...
    "tag", "subfunsbtn");

// --- File selection ---
filelabel = uicontrol("parent", sci2cfig,...
    "style", "text",...
    "string", gettext("Main file name: "),...
    "position",[2*margin headerframemaxy+3*margin-1+widgeth 100 widgeth],...
    "horizontalalignment", "left",...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "tag", "filelabel");

fileedit = uicontrol("parent", sci2cfig,...
    "style", "edit",...
    "string", gettext("<enter a file name>"),...
    "position",[3*margin+100 headerframemaxy+3*margin-1+widgeth figw-6*margin-100-btnw widgeth],...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "tag", "fileedit");

filebtn = uicontrol("parent", sci2cfig,...
    "backgroundcolor", [0.8 0.8 0.8],...
    "style", "pushbutton",...
    "string", gettext("Browse"),...
    "position",[figw-2*margin-btnw headerframemaxy+3*margin+widgeth btnw btnh],...
    "fontname", defaultfont,...
    "fontunits", "points",...
    "fontsize", 12,...
    "callback", "cb_sci2c_gui",...
    "tag", "filebtn");

endfunction