ivprog-visual-functions-1.0.js 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444
  1. var counter_new_functions = 0;
  2. var counter_new_parameters = 0;
  3. var counter_new_variables = 0;
  4. var counter_new_globals = 0;
  5. function addFunctionHandler() {
  6. new_function = new Funcao(i18n("new_function") + "_" + counter_new_functions, tiposDados.void, 0, new Array(), false, false, null, new Comentario(i18n('text_comment_start')));
  7. adicionarFuncao(new_function);
  8. counter_new_functions ++;
  9. renderAlgorithm();
  10. }
  11. function addGlobalVar() {
  12. var v = new Variavel(tiposDados.integer, i18n('new_global') + '_' + counter_new_globals, 1);
  13. counter_new_globals ++;
  14. programa.globais.push(v);
  15. renderAlgorithm();
  16. }
  17. function updateSequenceFunctionHandler(index_from, index_to) {
  18. programa.funcoes.splice(index_to, 0, programa.funcoes.splice(index_from, 1)[0]);
  19. renderAlgorithm();
  20. }
  21. function removeFunctionHandler(div_function, sequence) {
  22. programa.funcoes.splice(sequence, 1);
  23. $(div_function).slideUp(400, function(){
  24. renderAlgorithm();
  25. });
  26. }
  27. function minimizeFunctionHandler(div_function, sequence) {
  28. $(div_function).find(".function_area").toggle();
  29. programa.funcoes[sequence].esta_oculta = !programa.funcoes[sequence].esta_oculta;
  30. }
  31. function renderAlgorithm() {
  32. $('.all_functions').empty();
  33. for (i = 0; i < programa.funcoes.length; i++) {
  34. appendFunction(programa.funcoes[i], i);
  35. }
  36. if (programa.globais.length > 0) {
  37. renderGlobals();
  38. }
  39. $('.data_types_dropdown').dropdown();
  40. $('.parameter_data_types_dropdown').dropdown();
  41. addHandlers();
  42. }
  43. function renderGlobals() {
  44. var ret = "";
  45. if (programa.globais.length > 0) {
  46. $('.list_globals').empty();
  47. for (var j = 0; j < programa.globais.length; j++) {
  48. var par_temp = programa.globais[j];
  49. ret += '<div class="ui label name_variable"><span class="span_name_variable" ondblclick="enableNameGlobalUpdate(this.parentNode, '+j+')">'+par_temp.nome+'</span> <i class="icon small pencil alternate enable_edit_name_parameter" onclick="enableNameGlobalUpdate(this.parentNode, '+j+')"></i>';
  50. ret += '<div class="ui dropdown global_type seq_'+j+'">';
  51. if (par_temp.dimensoes > 0) {
  52. ret += '<div class="text seq_'+j+'">'+ i18n(tiposDados.vector)+':'+i18n(par_temp.tipo);
  53. for (i = 0; i < par_temp.dimensoes; i ++) {
  54. ret += ' [ ] ';
  55. }
  56. ret += '</div>';
  57. } else {
  58. ret += '<div class="text seq_'+j+'">'+i18n(par_temp.tipo)+'</div>';
  59. }
  60. ret += '<i class="dropdown icon"></i>'
  61. + '<div class="menu seq_'+j+'">';
  62. var i = 0;
  63. for (tm in tiposDados) {
  64. i ++;
  65. if (i == 1) { continue; }
  66. if (i == (Object.keys(tiposDados).length)) { break; }
  67. ret += '<div class="item ' + (par_temp.tipo == tm ? ' selected ' : '') + ' seq_'+j+' '+tm+'" >'+i18n(tm)+'</div>';
  68. }
  69. i = 0;
  70. for (tm in tiposDados) {
  71. i ++;
  72. if (i == 1) { continue; }
  73. if (i == (Object.keys(tiposDados).length)) { break; }
  74. ret += '<div class="item seq_'+j+' ">'
  75. + '<i class="dropdown icon"></i>'
  76. + i18n(tiposDados.vector)+':'+i18n(tm)
  77. + '<div class="menu seq_'+j+' ">'
  78. + '<div class="item seq_'+j+' '+tm+'" data-text="'+ i18n(tiposDados.vector)+':'+i18n(tm)+' [ ] ">[ ]</div>'
  79. + '<div class="item seq_'+j+' '+tm+'" data-text="'+ i18n(tiposDados.vector)+':'+i18n(tm)+' [ ] [ ] ">[ ] [ ] </div>'
  80. + '</div>'
  81. + '</div>';
  82. }
  83. ret += '</div></div> = ';
  84. if (par_temp.dimensoes == 0) {
  85. if (par_temp.tipo == tiposDados.real) {
  86. ret += '<div class="div_valor_var"><span class="span_value_variable" ondblclick="enableGlobalValueUpdate(this.parentNode, '+j+')" >'+par_temp.valor.toFixed(1)+'</span> <i class="icon small pencil alternate enable_edit_name_function" onclick="enableGlobalValueUpdate(this.parentNode, '+j+')"></i></div> ';
  87. } else {
  88. if (par_temp.tipo == tiposDados.boolean) {
  89. ret += '<div class="div_valor_var"><span class="span_value_variable" ondblclick="alternateBooleanGlobalValue(this.parentNode, '+j+')" >'+par_temp.valor+'</span> <i class="icon small pencil alternate enable_edit_name_function" onclick="alternateBooleanGlobalValue(this.parentNode, '+j+')"></i></div> ';
  90. } else {
  91. ret += '<div class="div_valor_var"><span class="span_value_variable" ondblclick="enableGlobalValueUpdate(this.parentNode, '+j+')" >'+par_temp.valor+'</span> <i class="icon small pencil alternate enable_edit_name_function" onclick="enableGlobalValueUpdate(this.parentNode, '+j+')"></i></div> ';
  92. }
  93. }
  94. } else {
  95. ret += '<table class="tabela_var">';
  96. if (par_temp.dimensoes == 1) {
  97. ret += '<tr>';
  98. if (par_temp.tipo == tiposDados.real) {
  99. for (var k = 0; k < par_temp.colunas; k++) {
  100. ret += '<td><span class="span_value_variable" ondblclick="enableGlobalVectorValueUpdate(this.parentNode, '+j+', '+k+')" >'+par_temp.valor[k].toFixed(1)+'</span>'+'</td>';
  101. }
  102. } else {
  103. for (var k = 0; k < par_temp.colunas; k++) {
  104. if (par_temp.tipo == tiposDados.boolean) {
  105. ret += '<td><span class="span_value_variable" ondblclick="alternateBooleanGlobalVectorValue(this.parentNode, '+j+', '+k+')" >'+par_temp.valor[k]+'</span>'+'</td>';
  106. } else {
  107. ret += '<td><span class="span_value_variable" ondblclick="enableGlobalVectorValueUpdate(this.parentNode, '+j+', '+k+')" >'+par_temp.valor[k]+'</span>'+'</td>';
  108. }
  109. }
  110. }
  111. ret += '</tr>';
  112. ret += '</table>';
  113. ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline" onclick="removeGlobalColumnVector('+j+')"></i>'
  114. + ' <i class="ui icon plus square outline" onclick="addGlobalColumnVector('+j+')"></i></div>';
  115. }
  116. if (par_temp.dimensoes == 2) {
  117. if (par_temp.tipo == tiposDados.real) {
  118. for (var l = 0; l < par_temp.linhas; l++) {
  119. ret += '<tr>';
  120. for (var k = 0; k < par_temp.colunas; k++) {
  121. ret += '<td><span class="span_value_variable" ondblclick="enableGlobalMatrixValueUpdate(this.parentNode, '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k].toFixed(1)+'</span>'+'</td>';
  122. }
  123. ret += '</tr>';
  124. }
  125. } else {
  126. for (var l = 0; l < par_temp.linhas; l++) {
  127. ret += '<tr>';
  128. for (var k = 0; k < par_temp.colunas; k++) {
  129. if (par_temp.tipo == tiposDados.boolean) {
  130. ret += '<td><span class="span_value_variable" ondblclick="alternateBooleanGlobalMatrixValue(this.parentNode, '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k]+'</span>'+'</td>';
  131. } else {
  132. ret += '<td><span class="span_value_variable" ondblclick="enableGlobalMatrixValueUpdate(this.parentNode, '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k]+'</span>'+'</td>';
  133. }
  134. }
  135. ret += '</tr>';
  136. }
  137. }
  138. if (par_temp.linhas == 0) {
  139. ret += '<tr><td></td></tr>';
  140. }
  141. ret += '<tr><td colspan="'+par_temp.colunas+'" class="tr_manage_lines"><i class="ui icon minus square outline" onclick="removeLineGlobalMatrix('+j+')"></i>'
  142. + ' <i class="ui icon plus square outline" onclick="addLineGlobalMatrix('+j+')"></i></td></tr>';
  143. ret += '</table>';
  144. ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline" onclick="removeColumnGlobalMatrix('+j+')"></i>'
  145. + ' <i class="ui icon plus square outline" onclick="addColumnGlobalMatrix('+j+')"></i></div>';
  146. }
  147. }
  148. ret += ' <i class="red icon times remove_parameter" onclick="deleteGlobal('+j+')"></i></div>';
  149. }
  150. }
  151. $('.list_globals').append(ret);
  152. }
  153. function addHandlers() {
  154. $('.ui.dropdown.function_return')
  155. .dropdown({
  156. onChange: function(value, text, $selectedItem) {
  157. classList = $selectedItem.attr('class').split(/\s+/);
  158. $.each(classList, function(index, item) {
  159. if (item.indexOf("seq_") > -1) {
  160. seq = item.split("seq_")[1];
  161. for (tm in tiposDados) {
  162. if ($selectedItem.hasClass(tm)) {
  163. programa.funcoes[seq].tipo_retorno = tm;
  164. }
  165. }
  166. updateFunctionReturn(seq, value);
  167. }
  168. });
  169. }
  170. })
  171. ;
  172. $('.ui.dropdown.parameter_type').dropdown({
  173. onChange: function(value, text, $selectedItem) {
  174. classList = $selectedItem.attr('class').split(/\s+/);
  175. var fun;
  176. var seq;
  177. $.each(classList, function(index, item) {
  178. if (item.indexOf("fun_") > -1) {
  179. fun = item.split("fun_")[1];
  180. }
  181. if (item.indexOf("seq_") > -1) {
  182. seq = item.split("seq_")[1];
  183. }
  184. });
  185. var dim = 0;
  186. if (value.indexOf(i18n(tiposDados.vector)) > -1) {
  187. dim = 1;
  188. }
  189. for (tm in tiposDados) {
  190. if ($selectedItem.hasClass(tm)) {
  191. updateParameterType(fun, seq, tm, dim);
  192. break;
  193. }
  194. }
  195. }
  196. });
  197. $('.ui.dropdown.variable_type').dropdown({
  198. onChange: function(value, text, $selectedItem) {
  199. classList = $selectedItem.attr('class').split(/\s+/);
  200. var fun;
  201. var seq;
  202. $.each(classList, function(index, item) {
  203. if (item.indexOf("fun_") > -1) {
  204. fun = item.split("fun_")[1];
  205. }
  206. if (item.indexOf("seq_") > -1) {
  207. seq = item.split("seq_")[1];
  208. }
  209. });
  210. var dim = 0;
  211. if (value.indexOf(i18n(tiposDados.vector)) > -1) {
  212. dim = value.split('[').length - 1;
  213. }
  214. for (tm in tiposDados) {
  215. if ($selectedItem.hasClass(tm)) {
  216. updateVariableType(fun, seq, tm, dim);
  217. break;
  218. }
  219. }
  220. }
  221. });
  222. $('.ui.dropdown.global_type').dropdown({
  223. onChange: function(value, text, $selectedItem) {
  224. classList = $selectedItem.attr('class').split(/\s+/);
  225. var fun;
  226. var seq;
  227. $.each(classList, function(index, item) {
  228. if (item.indexOf("seq_") > -1) {
  229. seq = item.split("seq_")[1];
  230. }
  231. });
  232. var dim = 0;
  233. if (value.indexOf(i18n(tiposDados.vector)) > -1) {
  234. dim = value.split('[').length - 1;
  235. }
  236. for (tm in tiposDados) {
  237. if ($selectedItem.hasClass(tm)) {
  238. updateGlobalType(seq, tm, dim);
  239. break;
  240. }
  241. }
  242. }
  243. });
  244. }
  245. function updateVariableType(wich_function, wich_variable, new_value, new_dimensions) {
  246. programa.funcoes[wich_function].variaveis[wich_variable].tipo = new_value;
  247. programa.funcoes[wich_function].variaveis[wich_variable].dimensoes = new_dimensions;
  248. if (new_dimensions > 0) {
  249. programa.funcoes[wich_function].variaveis[wich_variable].linhas = new_dimensions;
  250. programa.funcoes[wich_function].variaveis[wich_variable].colunas = 2;
  251. }
  252. if (new_value == tiposDados.integer) {
  253. if (new_dimensions == 0) {
  254. programa.funcoes[wich_function].variaveis[wich_variable].valor = 1;
  255. }
  256. if (new_dimensions == 1) {
  257. programa.funcoes[wich_function].variaveis[wich_variable].valor = [1, 1];
  258. }
  259. if (new_dimensions == 2) {
  260. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[1, 1], [1, 1]];
  261. }
  262. }
  263. if (new_value == tiposDados.real) {
  264. if (new_dimensions == 0) {
  265. programa.funcoes[wich_function].variaveis[wich_variable].valor = 1.0;
  266. }
  267. if (new_dimensions == 1) {
  268. programa.funcoes[wich_function].variaveis[wich_variable].valor = [1.0, 1.0];
  269. }
  270. if (new_dimensions == 2) {
  271. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[1.0, 1.0], [1.0, 1.0]];
  272. }
  273. }
  274. if (new_value == tiposDados.text) {
  275. if (new_dimensions == 0) {
  276. programa.funcoes[wich_function].variaveis[wich_variable].valor = i18n(tiposDados.text);
  277. }
  278. if (new_dimensions == 1) {
  279. programa.funcoes[wich_function].variaveis[wich_variable].valor = [i18n(tiposDados.text), i18n(tiposDados.text)];
  280. }
  281. if (new_dimensions == 2) {
  282. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[i18n(tiposDados.text), i18n(tiposDados.text)], [i18n(tiposDados.text), i18n(tiposDados.text)]];
  283. }
  284. }
  285. if (new_value == tiposDados.boolean) {
  286. if (new_dimensions == 0) {
  287. programa.funcoes[wich_function].variaveis[wich_variable].valor = true;
  288. }
  289. if (new_dimensions == 1) {
  290. programa.funcoes[wich_function].variaveis[wich_variable].valor = [true, true];
  291. }
  292. if (new_dimensions == 2) {
  293. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[true, true], [true, true]];
  294. }
  295. }
  296. renderAlgorithm();
  297. }
  298. function addColumnVector(which_function, which_variable) {
  299. programa.funcoes[which_function].variaveis[which_variable].colunas ++;
  300. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.integer) {
  301. programa.funcoes[which_function].variaveis[which_variable].valor.push(1);
  302. }
  303. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.real) {
  304. programa.funcoes[which_function].variaveis[which_variable].valor.push(1.0);
  305. }
  306. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.text) {
  307. programa.funcoes[which_function].variaveis[which_variable].valor.push(i18n(tiposDados.text));
  308. }
  309. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.boolean) {
  310. programa.funcoes[which_function].variaveis[which_variable].valor.push(true);
  311. }
  312. renderAlgorithm();
  313. }
  314. function addColumnMatrix(which_function, which_variable) {
  315. programa.funcoes[which_function].variaveis[which_variable].colunas ++;
  316. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.integer) {
  317. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  318. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(1);
  319. }
  320. }
  321. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.real) {
  322. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  323. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(1.0);
  324. }
  325. }
  326. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.text) {
  327. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  328. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(i18n(tiposDados.text));
  329. }
  330. }
  331. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.boolean) {
  332. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  333. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(true);
  334. }
  335. }
  336. renderAlgorithm();
  337. }
  338. function addLineMatrix(which_function, which_variable) {
  339. programa.funcoes[which_function].variaveis[which_variable].linhas ++;
  340. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.integer) {
  341. var n_l = [];
  342. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  343. n_l.push(1);
  344. }
  345. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  346. }
  347. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.real) {
  348. var n_l = [];
  349. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  350. n_l.push(1.0);
  351. }
  352. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  353. }
  354. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.text) {
  355. var n_l = [];
  356. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  357. n_l.push(i18n(tiposDados.text));
  358. }
  359. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  360. }
  361. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.boolean) {
  362. var n_l = [];
  363. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  364. n_l.push(true);
  365. }
  366. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  367. }
  368. renderAlgorithm();
  369. }
  370. function removeColumnVector(which_function, which_variable) {
  371. if (programa.funcoes[which_function].variaveis[which_variable].colunas == 0) {
  372. return;
  373. }
  374. programa.funcoes[which_function].variaveis[which_variable].colunas --;
  375. programa.funcoes[which_function].variaveis[which_variable].valor.splice(programa.funcoes[which_function].variaveis[which_variable].valor.length - 1, 1);
  376. renderAlgorithm();
  377. }
  378. function removeColumnMatrix(which_function, which_variable) {
  379. if (programa.funcoes[which_function].variaveis[which_variable].colunas == 0) {
  380. return;
  381. }
  382. programa.funcoes[which_function].variaveis[which_variable].colunas --;
  383. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  384. programa.funcoes[which_function].variaveis[which_variable].valor[i].splice(programa.funcoes[which_function].variaveis[which_variable].valor[i].length - 1, 1);
  385. }
  386. renderAlgorithm();
  387. }
  388. function removeLineMatrix(which_function, which_variable) {
  389. if (programa.funcoes[which_function].variaveis[which_variable].linhas == 0) {
  390. return;
  391. }
  392. programa.funcoes[which_function].variaveis[which_variable].linhas --;
  393. programa.funcoes[which_function].variaveis[which_variable].valor.splice(programa.funcoes[which_function].variaveis[which_variable].valor.length - 1, 1);
  394. renderAlgorithm();
  395. }
  396. function addVariable(sequence) {//tipo, nome, valor
  397. var v = new Variavel(tiposDados.integer, i18n('new_variable') + '_' + counter_new_variables, 1);
  398. adicionarVariavel(sequence, v);
  399. counter_new_variables ++;
  400. renderAlgorithm();
  401. }
  402. function deleteVariable(which_function, which_variable) {
  403. programa.funcoes[which_function].variaveis.splice(which_variable, 1);
  404. renderAlgorithm();
  405. }
  406. function addParameter(sequence) {
  407. if (programa.funcoes[sequence].lista_parametros == null) {
  408. programa.funcoes[sequence].lista_parametros = new Array();
  409. }
  410. programa.funcoes[sequence].lista_parametros.push(new Variavel(tiposDados.integer, i18n("new_parameter") + "_" + counter_new_parameters));
  411. counter_new_parameters ++;
  412. renderAlgorithm();
  413. }
  414. function updateFunctionReturn(sequence, new_value) {
  415. if (new_value.indexOf(i18n(tiposDados.vector)) > -1) {
  416. programa.funcoes[sequence].dimensoes_retorno = 1;
  417. } else {
  418. programa.funcoes[sequence].dimensoes_retorno = 0;
  419. }
  420. }
  421. function updateParameterType(wich_function, wich_parameter, new_value, new_dimensions) {
  422. programa.funcoes[wich_function].lista_parametros[wich_parameter].tipo = new_value;
  423. programa.funcoes[wich_function].lista_parametros[wich_parameter].dimensoes = new_dimensions;
  424. }
  425. var opened_name_function = false;
  426. var opened_input = null;
  427. var sequence_name_opened;
  428. function enableNameFunctionUpdate(div_el, sequence) {
  429. if (opened_name_function) {
  430. $(opened_input).focus();
  431. return;
  432. }
  433. opened_name_function = true;
  434. sequence_name_opened = sequence;
  435. $(div_el).find('.span_name_function').text('');
  436. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"+programa.funcoes[sequence].nome+"' />" ).insertBefore($(div_el).find('.span_name_function'));
  437. $('.width-dynamic').on('input', function() {
  438. var inputWidth = $(this).textWidth()+10;
  439. opened_input = this;
  440. $(this).focus();
  441. var tmpStr = $(this).val();
  442. $(this).val('');
  443. $(this).val(tmpStr);
  444. $(this).css({
  445. width: inputWidth
  446. })
  447. }).trigger('input');
  448. $('.width-dynamic').focusout(function() {
  449. /// update array:
  450. if ($(this).val().trim()) {
  451. programa.funcoes[sequence_name_opened].nome = $(this).val().trim();
  452. }
  453. $(this).remove();
  454. /// update elements:
  455. opened_name_function = false;
  456. opened_input = false;
  457. renderAlgorithm();
  458. });
  459. $('.width-dynamic').on('keydown', function(e) {
  460. var code = e.keyCode || e.which;
  461. if(code == 13) {
  462. if ($(this).val().trim()) {
  463. programa.funcoes[sequence_name_opened].nome = $(this).val().trim();
  464. }
  465. $(this).remove();
  466. /// update elements:
  467. opened_name_function = false;
  468. opened_input = false;
  469. renderAlgorithm();
  470. }
  471. if(code == 27) {
  472. $(div_el).find('.span_name_function').text(programa.funcoes[sequence_name_opened].nome);
  473. $(this).remove();
  474. /// update elements:
  475. opened_name_function = false;
  476. opened_input = false;
  477. }
  478. });
  479. }
  480. function alternateBooleanVarVectorValue(parent_node, which_function, which_var, column_index) {
  481. programa.funcoes[which_function].variaveis[which_var].valor[column_index] = !programa.funcoes[which_function].variaveis[which_var].valor[column_index];
  482. renderAlgorithm();
  483. }
  484. function alternateBooleanVarMatrixValue(parent_node, which_function, which_var, row_index, column_index) {
  485. programa.funcoes[which_function].variaveis[which_var].valor[row_index][column_index] = !programa.funcoes[which_function].variaveis[which_var].valor[row_index][column_index];
  486. renderAlgorithm();
  487. }
  488. function alternateBooleanVarValue(parent_node, which_function, which_var) {
  489. programa.funcoes[which_function].variaveis[which_var].valor = !programa.funcoes[which_function].variaveis[which_var].valor;
  490. renderAlgorithm();
  491. }
  492. var opened_name_value_vector_variable = false;
  493. var opened_input_value_vector_variable = null;
  494. var sequence_name_opened_value_vector_variable;
  495. var sequence_function_opened_value_vector_variable;
  496. function enableVarVectorValueUpdate(parent_node, which_function, which_parameter, column_index) {
  497. if (opened_name_value_vector_variable) {
  498. $(opened_input_value_vector_variable).focus();
  499. return;
  500. }
  501. opened_name_value_vector_variable = true;
  502. sequence_name_opened_value_vector_variable = which_parameter;
  503. sequence_function_opened_value_vector_variable = which_function;
  504. $(parent_node).find('.span_value_variable').text('');
  505. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  506. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  507. + programa.funcoes[which_function].variaveis[which_parameter].valor[column_index].toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  508. } else {
  509. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  510. + programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  511. }
  512. $('.width-dynamic').on('input', function() {
  513. var inputWidth = $(this).textWidth()+10;
  514. opened_input_value_vector_variable = this;
  515. $(this).focus();
  516. var tmpStr = $(this).val();
  517. $(this).val('');
  518. $(this).val(tmpStr);
  519. $(this).css({
  520. width: inputWidth
  521. })
  522. }).trigger('input');
  523. $('.width-dynamic').focusout(function() {
  524. /// update array:
  525. if ($(this).val().trim()) {
  526. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  527. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseFloat($(this).val().trim());
  528. } else {
  529. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  530. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseInt($(this).val().trim());
  531. } else {
  532. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = $(this).val().trim();
  533. }
  534. }
  535. }
  536. $(this).remove();
  537. /// update elements:
  538. opened_name_value_vector_variable = false;
  539. opened_input_value_vector_variable = false;
  540. renderAlgorithm();
  541. });
  542. $('.width-dynamic').on('keydown', function(e) {
  543. var code = e.keyCode || e.which;
  544. if(code == 13) {
  545. if ($(this).val().trim()) {
  546. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  547. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseFloat($(this).val().trim());
  548. } else {
  549. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  550. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseInt($(this).val().trim());
  551. } else {
  552. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = $(this).val().trim();
  553. }
  554. }
  555. }
  556. $(this).remove();
  557. /// update elements:
  558. opened_name_value_vector_variable = false;
  559. opened_input_value_vector_variable = false;
  560. renderAlgorithm();
  561. }
  562. if(code == 27) {
  563. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  564. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[column_index].toFixed(1));
  565. } else {
  566. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[column_index]);
  567. }
  568. $(this).remove();
  569. /// update elements:
  570. opened_name_value_vector_variable = false;
  571. opened_input_value_vector_variable = false;
  572. }
  573. });
  574. }
  575. var opened_name_value_matrix_variable = false;
  576. var opened_input_value_matrix_variable = null;
  577. var sequence_name_opened_value_matrix_variable;
  578. var sequence_function_opened_value_matrix_variable;
  579. function enableVarMatrixValueUpdate(parent_node, which_function, which_parameter, row_index, column_index) {
  580. if (opened_name_value_matrix_variable) {
  581. $(opened_input_value_matrix_variable).focus();
  582. return;
  583. }
  584. opened_name_value_matrix_variable = true;
  585. sequence_name_opened_value_matrix_variable = which_parameter;
  586. sequence_function_opened_value_matrix_variable = which_function;
  587. $(parent_node).find('.span_value_variable').text('');
  588. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  589. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  590. + programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index].toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  591. } else {
  592. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  593. + programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  594. }
  595. $('.width-dynamic').on('input', function() {
  596. var inputWidth = $(this).textWidth()+10;
  597. opened_input_value_matrix_variable = this;
  598. $(this).focus();
  599. var tmpStr = $(this).val();
  600. $(this).val('');
  601. $(this).val(tmpStr);
  602. $(this).css({
  603. width: inputWidth
  604. })
  605. }).trigger('input');
  606. $('.width-dynamic').focusout(function() {
  607. /// update array:
  608. if ($(this).val().trim()) {
  609. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  610. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseFloat($(this).val().trim());
  611. } else {
  612. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  613. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseInt($(this).val().trim());
  614. } else {
  615. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = $(this).val().trim();
  616. }
  617. }
  618. }
  619. $(this).remove();
  620. /// update elements:
  621. opened_name_value_matrix_variable = false;
  622. opened_input_value_matrix_variable = false;
  623. renderAlgorithm();
  624. });
  625. $('.width-dynamic').on('keydown', function(e) {
  626. var code = e.keyCode || e.which;
  627. if(code == 13) {
  628. if ($(this).val().trim()) {
  629. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  630. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseFloat($(this).val().trim());
  631. } else {
  632. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  633. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseInt($(this).val().trim());
  634. } else {
  635. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = $(this).val().trim();
  636. }
  637. }
  638. }
  639. $(this).remove();
  640. /// update elements:
  641. opened_name_value_matrix_variable = false;
  642. opened_input_value_matrix_variable = false;
  643. renderAlgorithm();
  644. }
  645. if(code == 27) {
  646. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  647. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index].toFixed(1));
  648. } else {
  649. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index]);
  650. }
  651. $(this).remove();
  652. /// update elements:
  653. opened_name_value_matrix_variable = false;
  654. opened_input_value_matrix_variable = false;
  655. }
  656. });
  657. }
  658. var opened_name_value_variable = false;
  659. var opened_input_value_variable = null;
  660. var sequence_name_opened_value_variable;
  661. var sequence_function_opened_value_variable;
  662. function enableVarValueUpdate(parent_node, which_function, which_parameter) {
  663. if (opened_name_value_variable) {
  664. $(opened_input_value_variable).focus();
  665. return;
  666. }
  667. opened_name_value_variable = true;
  668. sequence_name_opened_value_variable = which_parameter;
  669. sequence_function_opened_value_variable = which_function;
  670. $(parent_node).find('.span_value_variable').text('');
  671. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  672. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  673. + programa.funcoes[which_function].variaveis[which_parameter].valor.toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  674. } else {
  675. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  676. + programa.funcoes[which_function].variaveis[which_parameter].valor + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  677. }
  678. $('.width-dynamic').on('input', function() {
  679. var inputWidth = $(this).textWidth()+10;
  680. opened_input_value_variable = this;
  681. $(this).focus();
  682. var tmpStr = $(this).val();
  683. $(this).val('');
  684. $(this).val(tmpStr);
  685. $(this).css({
  686. width: inputWidth
  687. })
  688. }).trigger('input');
  689. $('.width-dynamic').focusout(function() {
  690. /// update array:
  691. if ($(this).val().trim()) {
  692. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  693. programa.funcoes[which_function].variaveis[which_parameter].valor = parseFloat($(this).val().trim());
  694. } else{
  695. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  696. programa.funcoes[which_function].variaveis[which_parameter].valor = parseInt($(this).val().trim());
  697. } else {
  698. programa.funcoes[which_function].variaveis[which_parameter].valor = $(this).val().trim();
  699. }
  700. }
  701. }
  702. $(this).remove();
  703. /// update elements:
  704. opened_name_value_variable = false;
  705. opened_input_value_variable = false;
  706. renderAlgorithm();
  707. });
  708. $('.width-dynamic').on('keydown', function(e) {
  709. var code = e.keyCode || e.which;
  710. if(code == 13) {
  711. if ($(this).val().trim()) {
  712. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  713. programa.funcoes[which_function].variaveis[which_parameter].valor = parseFloat($(this).val().trim());
  714. } else{
  715. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  716. programa.funcoes[which_function].variaveis[which_parameter].valor = parseInt($(this).val().trim());
  717. } else {
  718. programa.funcoes[which_function].variaveis[which_parameter].valor = $(this).val().trim();
  719. }
  720. }
  721. }
  722. $(this).remove();
  723. /// update elements:
  724. opened_name_value_variable = false;
  725. opened_input_value_variable = false;
  726. renderAlgorithm();
  727. }
  728. if(code == 27) {
  729. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  730. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor.toFixed(1));
  731. } else{
  732. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor);
  733. }
  734. $(this).remove();
  735. /// update elements:
  736. opened_name_value_variable = false;
  737. opened_input_value_variable = false;
  738. }
  739. });
  740. }
  741. var opened_name_variable = false;
  742. var opened_input_variable = null;
  743. var sequence_name_opened_variable;
  744. var sequence_function_opened_variable;
  745. function enableNameVariableUpdate(parent_node, which_function, which_parameter) {
  746. if (opened_name_variable) {
  747. $(opened_input_variable).focus();
  748. return;
  749. }
  750. opened_name_variable = true;
  751. sequence_name_opened_variable = which_parameter;
  752. sequence_function_opened_variable = which_function;
  753. $(parent_node).find('.span_name_variable').text('');
  754. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  755. + programa.funcoes[which_function].variaveis[which_parameter].nome + "' />" ).insertBefore($(parent_node).find('.span_name_variable'));
  756. $('.width-dynamic').on('input', function() {
  757. var inputWidth = $(this).textWidth()+10;
  758. opened_input_variable = this;
  759. $(this).focus();
  760. var tmpStr = $(this).val();
  761. $(this).val('');
  762. $(this).val(tmpStr);
  763. $(this).css({
  764. width: inputWidth
  765. })
  766. }).trigger('input');
  767. $('.width-dynamic').focusout(function() {
  768. /// update array:
  769. if ($(this).val().trim()) {
  770. programa.funcoes[which_function].variaveis[which_parameter].nome = $(this).val().trim();
  771. }
  772. $(this).remove();
  773. /// update elements:
  774. opened_name_variable = false;
  775. opened_input_variable = false;
  776. renderAlgorithm();
  777. });
  778. $('.width-dynamic').on('keydown', function(e) {
  779. var code = e.keyCode || e.which;
  780. if(code == 13) {
  781. if ($(this).val().trim()) {
  782. programa.funcoes[which_function].variaveis[which_parameter].nome = $(this).val().trim();
  783. }
  784. $(this).remove();
  785. /// update elements:
  786. opened_name_variable = false;
  787. opened_input_variable = false;
  788. renderAlgorithm();
  789. }
  790. if(code == 27) {
  791. $(parent_node).find('.span_name_variable').text(programa.funcoes[which_function].variaveis[which_parameter].nome);
  792. $(this).remove();
  793. /// update elements:
  794. opened_name_variable = false;
  795. opened_input_variable = false;
  796. }
  797. });
  798. }
  799. var opened_name_comment = false;
  800. var opened_input_comment = null;
  801. var sequence_name_opened_comment;
  802. var sequence_function_opened_comment;
  803. function enableCommentUpdate(parent_node, function_index, is_function_comment, comment_index) {
  804. if (opened_name_comment) {
  805. $(opened_input_comment).focus();
  806. return;
  807. }
  808. opened_name_comment = true;
  809. sequence_name_opened_comment = comment_index;
  810. sequence_function_opened_comment = function_index;
  811. $(parent_node).find('.span_comment_text').text('');
  812. var temp_value = "";
  813. if (is_function_comment) {
  814. temp_value = programa.funcoes[function_index].comentario_funcao.texto_comentario;
  815. } else {
  816. temp_value = programa.funcoes[function_index].comandos[comment_index].texto_comentario;
  817. }
  818. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"+temp_value+"' />" ).insertBefore($(parent_node).find('.span_comment_text'));
  819. $('.width-dynamic').on('input', function() {
  820. var inputWidth = $(this).textWidth()+10;
  821. opened_input_comment = this;
  822. $(this).focus();
  823. var tmpStr = $(this).val();
  824. $(this).val('');
  825. $(this).val(tmpStr);
  826. $(this).css({
  827. width: inputWidth
  828. })
  829. }).trigger('input');
  830. $('.width-dynamic').focusout(function() {
  831. /// update array:
  832. if ($(this).val().trim()) {
  833. var n_value = $(this).val().trim();
  834. if (is_function_comment) {
  835. programa.funcoes[function_index].comentario_funcao.texto_comentario = n_value;
  836. } else {
  837. temp_value = programa.funcoes[function_index].comandos[comment_index].texto_comentario = n_value;
  838. }
  839. }
  840. $(this).remove();
  841. /// update elements:
  842. opened_name_comment = false;
  843. opened_input_comment = false;
  844. renderAlgorithm();
  845. });
  846. $('.width-dynamic').on('keydown', function(e) {
  847. var code = e.keyCode || e.which;
  848. if(code == 13) {
  849. if ($(this).val().trim()) {
  850. var n_value = $(this).val().trim();
  851. if (is_function_comment) {
  852. programa.funcoes[function_index].comentario_funcao.texto_comentario = n_value;
  853. } else {
  854. temp_value = programa.funcoes[function_index].comandos[comment_index].texto_comentario = n_value;
  855. }
  856. }
  857. $(this).remove();
  858. /// update elements:
  859. opened_name_comment = false;
  860. opened_input_comment = false;
  861. renderAlgorithm();
  862. }
  863. if(code == 27) {
  864. $(parent_node).find('.span_comment_text').text(temp_value);
  865. $(this).remove();
  866. /// update elements:
  867. opened_name_comment = false;
  868. opened_input_comment = false;
  869. }
  870. });
  871. }
  872. var opened_name_parameter = false;
  873. var opened_input_parameter = null;
  874. var sequence_name_opened_parameter;
  875. var sequence_function_opened_parameter;
  876. function enableNameParameterUpdate(parent_node, which_function, which_parameter) {
  877. if (opened_name_parameter) {
  878. $(opened_input_parameter).focus();
  879. return;
  880. }
  881. opened_name_parameter = true;
  882. sequence_name_opened_parameter = which_parameter;
  883. sequence_function_opened_parameter = which_function;
  884. $(parent_node).find('.span_name_parameter').text('');
  885. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"+programa.funcoes[which_function].lista_parametros[which_parameter].nome+"' />" ).insertBefore($(parent_node).find('.span_name_parameter'));
  886. $('.width-dynamic').on('input', function() {
  887. var inputWidth = $(this).textWidth()+10;
  888. opened_input_parameter = this;
  889. $(this).focus();
  890. var tmpStr = $(this).val();
  891. $(this).val('');
  892. $(this).val(tmpStr);
  893. $(this).css({
  894. width: inputWidth
  895. })
  896. }).trigger('input');
  897. $('.width-dynamic').focusout(function() {
  898. /// update array:
  899. if ($(this).val().trim()) {
  900. programa.funcoes[which_function].lista_parametros[which_parameter].nome = $(this).val().trim();
  901. }
  902. $(this).remove();
  903. /// update elements:
  904. opened_name_parameter = false;
  905. opened_input_parameter = false;
  906. renderAlgorithm();
  907. });
  908. $('.width-dynamic').on('keydown', function(e) {
  909. var code = e.keyCode || e.which;
  910. if(code == 13) {
  911. if ($(this).val().trim()) {
  912. programa.funcoes[which_function].lista_parametros[which_parameter].nome = $(this).val().trim();
  913. }
  914. $(this).remove();
  915. /// update elements:
  916. opened_name_parameter = false;
  917. opened_input_parameter = false;
  918. renderAlgorithm();
  919. }
  920. if(code == 27) {
  921. $(parent_node).find('.span_name_parameter').text(programa.funcoes[which_function].lista_parametros[which_parameter].nome);
  922. $(this).remove();
  923. /// update elements:
  924. opened_name_parameter = false;
  925. opened_input_parameter = false;
  926. }
  927. });
  928. }
  929. function removeParameter(parent_node, which_function, which_parameter) {
  930. programa.funcoes[which_function].lista_parametros.splice(which_parameter, 1);
  931. renderAlgorithm();
  932. }
  933. function appendFunction(function_obj, sequence) {
  934. var appender = '<div class="ui secondary segment function_div list-group-item">';
  935. if (function_obj.comentario_funcao) {
  936. appender += renderComment(function_obj.comentario_funcao, sequence, true, -1);
  937. }
  938. appender += '<span class="glyphicon glyphicon-move move_function" aria-hidden="true"><i class="icon sort alternate vertical"></i></span>';
  939. appender += (!function_obj.eh_principal ? '<button class="ui icon button large remove_function_button" onclick="removeFunctionHandler(this.parentNode, '+sequence+')"><i class="red icon times"></i></button>' : '<div class="div_start_minimize_v"> </div>')
  940. + '<button class="ui icon button tiny minimize_function_button" onclick="minimizeFunctionHandler(this.parentNode, '+sequence+')"><i class="icon window minimize"></i></button>';
  941. appender += '<div class="ui icon buttons add_var_top_button"><div class="ui icon button" onclick="addVariable('+sequence+')"><i class="icon superscript"></i></div><div class="ui icon button"><i class="icon code"></i></div></div>';
  942. appender += '<div class="function_signature_div">'+i18n('function')+' ';
  943. if (function_obj.eh_principal) {
  944. appender += '<div class="function_name_div"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' + i18n('void') + ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="span_name_function" >'+function_obj.nome+'</span> </div> '
  945. + '( <div class="ui large labels parameters_list">';
  946. } else {
  947. appender += renderFunctionReturn(function_obj, sequence);
  948. appender += '<div class="function_name_div"><span class="span_name_function" ondblclick="enableNameFunctionUpdate(this.parentNode, '+sequence+')" >'+function_obj.nome+'</span> <i class="icon small pencil alternate enable_edit_name_function" onclick="enableNameFunctionUpdate(this.parentNode, '+sequence+')"></i></div> '
  949. + '( <i class="ui icon plus square outline add_parameter" onclick="addParameter('+sequence+')"></i> <div class="ui large labels parameters_list">';
  950. }
  951. appender += renderFunctionParameters(function_obj, sequence);
  952. appender += '</div> ) {</div>'
  953. + (function_obj.esta_oculta ? ' <div class="function_area" style="display: none;"> ' : ' <div class="function_area"> ')
  954. + '<div class="ui top attached segment variables_list_div">'
  955. + renderVariables(function_obj, sequence)
  956. + '</div>'
  957. + '<div class="ui bottom attached segment commands_list_div"></div>'
  958. + '<div class="function_close_div">}</div>'
  959. + '</div>'
  960. + '</div>';
  961. $('.all_functions').append(appender);
  962. }
  963. function renderComment(comment_obj, function_index, is_function_comment, comment_index) {
  964. var ret = '';
  965. ret += '<div class="ui comment"> <i class="ui icon small quote left"></i> <span class="span_comment_text" ondblclick="enableCommentUpdate(this.parentNode, '+function_index+', '
  966. +is_function_comment+', '+comment_index+')"> ' + comment_obj.texto_comentario + ' </span>';
  967. ret += '</div>';
  968. return ret;
  969. }
  970. // Essa função imprime os parâmetros e cria os elementos para a sua manipulação
  971. function renderFunctionParameters(function_obj, sequence) {
  972. var ret = "";
  973. if (function_obj.lista_parametros != null) {
  974. for (var j = 0; j < function_obj.lista_parametros.length; j++) {
  975. var par_temp = function_obj.lista_parametros[j];
  976. ret += '<div class="ui label function_name_parameter"><span class="span_name_parameter" ondblclick="enableNameParameterUpdate(this.parentNode, '+sequence+', '+j+')">'+par_temp.nome+'</span> <i class="icon small pencil alternate enable_edit_name_parameter" onclick="enableNameParameterUpdate(this.parentNode, '+sequence+', '+j+')"></i>';
  977. ret += '<div class="ui dropdown parameter_type seq_'+j+' fun_'+sequence+'">';
  978. if (par_temp.dimensoes > 0) {
  979. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+ i18n(tiposDados.vector)+':'+i18n(par_temp.tipo);
  980. ret += '</div>';
  981. } else {
  982. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+i18n(par_temp.tipo)+'</div>';
  983. }
  984. ret += '<i class="dropdown icon"></i>'
  985. + '<div class="menu seq_'+j+' fun_'+sequence+'">';
  986. var i = 0;
  987. for (tm in tiposDados) {
  988. i ++;
  989. if (i == 1) { continue; }
  990. if (i == (Object.keys(tiposDados).length)) { break; }
  991. ret += '<div class="item ' + ((par_temp.tipo == tm && par_temp.dimensoes < 1) ? ' selected ' : '') + ' seq_'+j+' fun_'+sequence+' '+tm+'" >'+i18n(tm)+'</div>';
  992. }
  993. i = 0;
  994. for (tm in tiposDados) {
  995. i ++;
  996. if (i == 1) { continue; }
  997. if (i == (Object.keys(tiposDados).length)) { break; }
  998. ret += '<div class="item seq_'+j+' '+tm+' fun_'+sequence+' ' + ((par_temp.tipo == tm && par_temp.dimensoes > 0) ? ' selected ' : '') + ' ">'
  999. + i18n(tiposDados.vector)+':'+i18n(tm)
  1000. + '</div>';
  1001. }
  1002. ret += '</div></div>';
  1003. ret += ' <i class="red icon times remove_parameter" onclick="removeParameter(this.parentNode, '+sequence+', '+j+')"></i></div>';
  1004. }
  1005. }
  1006. return ret;
  1007. }
  1008. // Essa função imprime as variáveis e os recursos para sua manipulação
  1009. function renderVariables(function_obj, sequence) {
  1010. var ret = "";
  1011. if (function_obj.variaveis != null) {
  1012. for (var j = 0; j < function_obj.variaveis.length; j++) {
  1013. var par_temp = function_obj.variaveis[j];
  1014. ret += '<div class="ui label name_variable"><span class="span_name_variable" ondblclick="enableNameVariableUpdate(this.parentNode, '+sequence+', '+j+')">'+par_temp.nome+'</span> <i class="icon small pencil alternate enable_edit_name_parameter" onclick="enableNameVariableUpdate(this.parentNode, '+sequence+', '+j+')"></i>';
  1015. ret += '<div class="ui dropdown variable_type seq_'+j+' fun_'+sequence+'">';
  1016. if (par_temp.dimensoes > 0) {
  1017. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+ i18n(tiposDados.vector)+':'+i18n(par_temp.tipo);
  1018. for (i = 0; i < par_temp.dimensoes; i ++) {
  1019. ret += ' [ ] ';
  1020. }
  1021. ret += '</div>';
  1022. } else {
  1023. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+i18n(par_temp.tipo)+'</div>';
  1024. }
  1025. ret += '<i class="dropdown icon"></i>'
  1026. + '<div class="menu seq_'+j+' fun_'+sequence+'">';
  1027. var i = 0;
  1028. for (tm in tiposDados) {
  1029. i ++;
  1030. if (i == 1) { continue; }
  1031. if (i == (Object.keys(tiposDados).length)) { break; }
  1032. ret += '<div class="item ' + (par_temp.tipo == tm ? ' selected ' : '') + ' seq_'+j+' fun_'+sequence+' '+tm+'" >'+i18n(tm)+'</div>';
  1033. }
  1034. i = 0;
  1035. for (tm in tiposDados) {
  1036. i ++;
  1037. if (i == 1) { continue; }
  1038. if (i == (Object.keys(tiposDados).length)) { break; }
  1039. ret += '<div class="item seq_'+j+' fun_'+sequence+'">'
  1040. + '<i class="dropdown icon"></i>'
  1041. + i18n(tiposDados.vector)+':'+i18n(tm)
  1042. + '<div class="menu seq_'+j+' fun_'+sequence+'">'
  1043. + '<div class="item seq_'+j+' fun_'+sequence+' '+tm+'" data-text="'+ i18n(tiposDados.vector)+':'+i18n(tm)+' [ ] ">[ ]</div>'
  1044. + '<div class="item seq_'+j+' fun_'+sequence+' '+tm+'" data-text="'+ i18n(tiposDados.vector)+':'+i18n(tm)+' [ ] [ ] ">[ ] [ ] </div>'
  1045. + '</div>'
  1046. + '</div>';
  1047. }
  1048. ret += '</div></div> = ';
  1049. if (par_temp.dimensoes == 0) {
  1050. if (par_temp.tipo == tiposDados.real) {
  1051. ret += '<div class="div_valor_var"><span class="span_value_variable" ondblclick="enableVarValueUpdate(this.parentNode, '+sequence+', '+j+')" >'+par_temp.valor.toFixed(1)+'</span> <i class="icon small pencil alternate enable_edit_name_function" onclick="enableVarValueUpdate(this.parentNode, '+sequence+', '+j+')"></i></div> ';
  1052. } else {
  1053. if (par_temp.tipo == tiposDados.boolean) {
  1054. ret += '<div class="div_valor_var"><span class="span_value_variable" ondblclick="alternateBooleanVarValue(this.parentNode, '+sequence+', '+j+')" >'+par_temp.valor+'</span> <i class="icon small pencil alternate enable_edit_name_function" onclick="alternateBooleanVarValue(this.parentNode, '+sequence+', '+j+')"></i></div> ';
  1055. } else {
  1056. ret += '<div class="div_valor_var"><span class="span_value_variable" ondblclick="enableVarValueUpdate(this.parentNode, '+sequence+', '+j+')" >'+par_temp.valor+'</span> <i class="icon small pencil alternate enable_edit_name_function" onclick="enableVarValueUpdate(this.parentNode, '+sequence+', '+j+')"></i></div> ';
  1057. }
  1058. }
  1059. } else {
  1060. ret += '<table class="tabela_var">';
  1061. if (par_temp.dimensoes == 1) {
  1062. ret += '<tr>';
  1063. if (par_temp.tipo == tiposDados.real) {
  1064. for (var k = 0; k < par_temp.colunas; k++) {
  1065. ret += '<td><span class="span_value_variable" ondblclick="enableVarVectorValueUpdate(this.parentNode, '+sequence+', '+j+', '+k+')" >'+par_temp.valor[k].toFixed(1)+'</span>'+'</td>';
  1066. }
  1067. } else {
  1068. for (var k = 0; k < par_temp.colunas; k++) {
  1069. if (par_temp.tipo == tiposDados.boolean) {
  1070. ret += '<td><span class="span_value_variable" ondblclick="alternateBooleanVarVectorValue(this.parentNode, '+sequence+', '+j+', '+k+')" >'+par_temp.valor[k]+'</span>'+'</td>';
  1071. } else {
  1072. ret += '<td><span class="span_value_variable" ondblclick="enableVarVectorValueUpdate(this.parentNode, '+sequence+', '+j+', '+k+')" >'+par_temp.valor[k]+'</span>'+'</td>';
  1073. }
  1074. }
  1075. }
  1076. ret += '</tr>';
  1077. ret += '</table>';
  1078. ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline" onclick="removeColumnVector('+sequence+', '+j+')"></i>'
  1079. + ' <i class="ui icon plus square outline" onclick="addColumnVector('+sequence+', '+j+')"></i></div>';
  1080. }
  1081. if (par_temp.dimensoes == 2) {
  1082. if (par_temp.tipo == tiposDados.real) {
  1083. for (var l = 0; l < par_temp.linhas; l++) {
  1084. ret += '<tr>';
  1085. for (var k = 0; k < par_temp.colunas; k++) {
  1086. ret += '<td><span class="span_value_variable" ondblclick="enableVarMatrixValueUpdate(this.parentNode, '+sequence+', '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k].toFixed(1)+'</span>'+'</td>';
  1087. }
  1088. ret += '</tr>';
  1089. }
  1090. } else {
  1091. for (var l = 0; l < par_temp.linhas; l++) {
  1092. ret += '<tr>';
  1093. for (var k = 0; k < par_temp.colunas; k++) {
  1094. if (par_temp.tipo == tiposDados.boolean) {
  1095. ret += '<td><span class="span_value_variable" ondblclick="alternateBooleanVarMatrixValue(this.parentNode, '+sequence+', '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k]+'</span>'+'</td>';
  1096. } else {
  1097. ret += '<td><span class="span_value_variable" ondblclick="enableVarMatrixValueUpdate(this.parentNode, '+sequence+', '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k]+'</span>'+'</td>';
  1098. }
  1099. }
  1100. ret += '</tr>';
  1101. }
  1102. }
  1103. if (par_temp.linhas == 0) {
  1104. ret += '<tr><td></td></tr>';
  1105. }
  1106. ret += '<tr><td colspan="'+par_temp.colunas+'" class="tr_manage_lines"><i class="ui icon minus square outline" onclick="removeLineMatrix('+sequence+', '+j+')"></i>'
  1107. + ' <i class="ui icon plus square outline" onclick="addLineMatrix('+sequence+', '+j+')"></i></td></tr>';
  1108. ret += '</table>';
  1109. ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline" onclick="removeColumnMatrix('+sequence+', '+j+')"></i>'
  1110. + ' <i class="ui icon plus square outline" onclick="addColumnMatrix('+sequence+', '+j+')"></i></div>';
  1111. }
  1112. }
  1113. ret += ' <i class="red icon times remove_parameter" onclick="deleteVariable('+sequence+', '+j+')"></i></div>';
  1114. }
  1115. }
  1116. return ret;
  1117. }
  1118. // Essa função imprime o tipo de retorno da função e cria o menu do tipo 'select' para alteração
  1119. function renderFunctionReturn(function_obj, sequence) {
  1120. var ret = '<div class="ui dropdown function_return seq_'+sequence+'">';
  1121. if (function_obj.dimensoes_retorno > 0) {
  1122. ret += '<div class="text seq_'+sequence+'"">'+ i18n(tiposDados.vector)+':'+i18n(function_obj.tipo_retorno);
  1123. ret += '</div>';
  1124. } else {
  1125. ret += '<div class="text seq_'+sequence+'"">'+i18n(function_obj.tipo_retorno)+'</div>';
  1126. }
  1127. ret += '<i class="dropdown icon"></i>'
  1128. + '<div class="menu seq_'+sequence+'"">';
  1129. var i = 0;
  1130. for (tm in tiposDados) {
  1131. if (i == (Object.keys(tiposDados).length - 1)) { break; }
  1132. ret += '<div class="item ' + ((function_obj.tipo_retorno == tm && function_obj.dimensoes_retorno < 1) ? ' selected ' : '') + ' seq_'+sequence+' '+tm+'" >'+i18n(tm)+'</div>';
  1133. i ++;
  1134. }
  1135. i = 0;
  1136. for (tm in tiposDados) {
  1137. i ++;
  1138. if (i == 1) { continue; }
  1139. if (i == (Object.keys(tiposDados).length)) { break; }
  1140. ret += '<div class="item seq_'+sequence+' '+tm+' '+ ((function_obj.tipo_retorno == tm && function_obj.dimensoes_retorno > 0) ? ' selected ' : '') +'" data-text="'+i18n(tiposDados.vector)+':'+i18n(tm)+' ">'
  1141. + i18n(tiposDados.vector)+':'+i18n(tm)
  1142. + '</div>';
  1143. }
  1144. ret += '</div></div>';
  1145. return ret;
  1146. }
  1147. $.fn.textWidth = function(text, font) {
  1148. if (!$.fn.textWidth.fakeEl) $.fn.textWidth.fakeEl = $('<span>').hide().appendTo(document.body);
  1149. $.fn.textWidth.fakeEl.text(text || this.val() || this.text() || this.attr('placeholder')).css('font', font || this.css('font'));
  1150. return $.fn.textWidth.fakeEl.width();
  1151. };