ivprog-visual-functions-1.0.js 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020
  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. $('.list_globals').empty();
  37. if (programa.globais.length > 0) {
  38. renderGlobals();
  39. }
  40. $('.data_types_dropdown').dropdown();
  41. $('.parameter_data_types_dropdown').dropdown();
  42. addHandlers();
  43. }
  44. function deleteGlobal(which_global) {
  45. programa.globais.splice(which_global, 1);
  46. renderAlgorithm();
  47. }
  48. function alternateGlobalConst(which_global) {
  49. programa.globais[which_global].eh_constante = !programa.globais[which_global].eh_constante;
  50. renderAlgorithm();
  51. }
  52. function renderGlobals() {
  53. var ret = "";
  54. if (programa.globais.length > 0) {
  55. for (var j = 0; j < programa.globais.length; j++) {
  56. var par_temp = programa.globais[j];
  57. ret += '<div class="ui label name_variable"><div class="global_const">const: ';
  58. ret += '<i class="ui icon toggle '+(par_temp.eh_constante?"on":"off")+' " onclick="alternateGlobalConst('+j+')"></i></div><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>';
  59. ret += '<div class="ui dropdown global_type seq_'+j+'">';
  60. if (par_temp.dimensoes > 0) {
  61. ret += '<div class="text seq_'+j+'">'+ i18n(tiposDados.vector)+':'+i18n(par_temp.tipo);
  62. for (i = 0; i < par_temp.dimensoes; i ++) {
  63. ret += ' [ ] ';
  64. }
  65. ret += '</div>';
  66. } else {
  67. ret += '<div class="text seq_'+j+'">'+i18n(par_temp.tipo)+'</div>';
  68. }
  69. ret += '<i class="dropdown icon"></i>'
  70. + '<div class="menu seq_'+j+'">';
  71. var i = 0;
  72. for (tm in tiposDados) {
  73. i ++;
  74. if (i == 1) { continue; }
  75. if (i == (Object.keys(tiposDados).length)) { break; }
  76. ret += '<div class="item ' + (par_temp.tipo == tm ? ' selected ' : '') + ' seq_'+j+' '+tm+'" >'+i18n(tm)+'</div>';
  77. }
  78. i = 0;
  79. for (tm in tiposDados) {
  80. i ++;
  81. if (i == 1) { continue; }
  82. if (i == (Object.keys(tiposDados).length)) { break; }
  83. ret += '<div class="item seq_'+j+' ">'
  84. + '<i class="dropdown icon"></i>'
  85. + i18n(tiposDados.vector)+':'+i18n(tm)
  86. + '<div class="menu seq_'+j+' ">'
  87. + '<div class="item seq_'+j+' '+tm+'" data-text="'+ i18n(tiposDados.vector)+':'+i18n(tm)+' [ ] ">[ ]</div>'
  88. + '<div class="item seq_'+j+' '+tm+'" data-text="'+ i18n(tiposDados.vector)+':'+i18n(tm)+' [ ] [ ] ">[ ] [ ] </div>'
  89. + '</div>'
  90. + '</div>';
  91. }
  92. ret += '</div></div> = ';
  93. if (par_temp.dimensoes == 0) {
  94. if (par_temp.tipo == tiposDados.real) {
  95. 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> ';
  96. } else {
  97. if (par_temp.tipo == tiposDados.boolean) {
  98. 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> ';
  99. } else {
  100. 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> ';
  101. }
  102. }
  103. } else {
  104. ret += '<table class="tabela_var">';
  105. if (par_temp.dimensoes == 1) {
  106. ret += '<tr>';
  107. if (par_temp.tipo == tiposDados.real) {
  108. for (var k = 0; k < par_temp.colunas; k++) {
  109. ret += '<td><span class="span_value_variable" ondblclick="enableGlobalVectorValueUpdate(this.parentNode, '+j+', '+k+')" >'+par_temp.valor[k].toFixed(1)+'</span>'+'</td>';
  110. }
  111. } else {
  112. for (var k = 0; k < par_temp.colunas; k++) {
  113. if (par_temp.tipo == tiposDados.boolean) {
  114. ret += '<td><span class="span_value_variable" ondblclick="alternateBooleanGlobalVectorValue(this.parentNode, '+j+', '+k+')" >'+par_temp.valor[k]+'</span>'+'</td>';
  115. } else {
  116. ret += '<td><span class="span_value_variable" ondblclick="enableGlobalVectorValueUpdate(this.parentNode, '+j+', '+k+')" >'+par_temp.valor[k]+'</span>'+'</td>';
  117. }
  118. }
  119. }
  120. ret += '</tr>';
  121. ret += '</table>';
  122. ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline" onclick="removeGlobalColumnVector('+j+')"></i>'
  123. + ' <i class="ui icon plus square outline" onclick="addGlobalColumnVector('+j+')"></i></div>';
  124. }
  125. if (par_temp.dimensoes == 2) {
  126. if (par_temp.tipo == tiposDados.real) {
  127. for (var l = 0; l < par_temp.linhas; l++) {
  128. ret += '<tr>';
  129. for (var k = 0; k < par_temp.colunas; k++) {
  130. ret += '<td><span class="span_value_variable" ondblclick="enableGlobalMatrixValueUpdate(this.parentNode, '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k].toFixed(1)+'</span>'+'</td>';
  131. }
  132. ret += '</tr>';
  133. }
  134. } else {
  135. for (var l = 0; l < par_temp.linhas; l++) {
  136. ret += '<tr>';
  137. for (var k = 0; k < par_temp.colunas; k++) {
  138. if (par_temp.tipo == tiposDados.boolean) {
  139. ret += '<td><span class="span_value_variable" ondblclick="alternateBooleanGlobalMatrixValue(this.parentNode, '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k]+'</span>'+'</td>';
  140. } else {
  141. ret += '<td><span class="span_value_variable" ondblclick="enableGlobalMatrixValueUpdate(this.parentNode, '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k]+'</span>'+'</td>';
  142. }
  143. }
  144. ret += '</tr>';
  145. }
  146. }
  147. if (par_temp.linhas == 0) {
  148. ret += '<tr><td></td></tr>';
  149. }
  150. ret += '<tr><td colspan="'+par_temp.colunas+'" class="tr_manage_lines"><i class="ui icon minus square outline" onclick="removeLineGlobalMatrix('+j+')"></i>'
  151. + ' <i class="ui icon plus square outline" onclick="addLineGlobalMatrix('+j+')"></i></td></tr>';
  152. ret += '</table>';
  153. ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline" onclick="removeColumnGlobalMatrix('+j+')"></i>'
  154. + ' <i class="ui icon plus square outline" onclick="addColumnGlobalMatrix('+j+')"></i></div>';
  155. }
  156. }
  157. ret += ' <i class="red icon times remove_parameter" onclick="deleteGlobal('+j+')"></i></div>';
  158. }
  159. }
  160. $('.list_globals').append(ret);
  161. }
  162. function addHandlers() {
  163. $('.ui.dropdown.function_return')
  164. .dropdown({
  165. onChange: function(value, text, $selectedItem) {
  166. classList = $selectedItem.attr('class').split(/\s+/);
  167. $.each(classList, function(index, item) {
  168. if (item.indexOf("seq_") > -1) {
  169. seq = item.split("seq_")[1];
  170. for (tm in tiposDados) {
  171. if ($selectedItem.hasClass(tm)) {
  172. programa.funcoes[seq].tipo_retorno = tm;
  173. }
  174. }
  175. updateFunctionReturn(seq, value);
  176. }
  177. });
  178. }
  179. })
  180. ;
  181. $('.ui.dropdown.parameter_type').dropdown({
  182. onChange: function(value, text, $selectedItem) {
  183. classList = $selectedItem.attr('class').split(/\s+/);
  184. var fun;
  185. var seq;
  186. $.each(classList, function(index, item) {
  187. if (item.indexOf("fun_") > -1) {
  188. fun = item.split("fun_")[1];
  189. }
  190. if (item.indexOf("seq_") > -1) {
  191. seq = item.split("seq_")[1];
  192. }
  193. });
  194. var dim = 0;
  195. if (value.indexOf(i18n(tiposDados.vector)) > -1) {
  196. dim = 1;
  197. }
  198. for (tm in tiposDados) {
  199. if ($selectedItem.hasClass(tm)) {
  200. updateParameterType(fun, seq, tm, dim);
  201. break;
  202. }
  203. }
  204. }
  205. });
  206. $('.ui.dropdown.variable_type').dropdown({
  207. onChange: function(value, text, $selectedItem) {
  208. classList = $selectedItem.attr('class').split(/\s+/);
  209. var fun;
  210. var seq;
  211. $.each(classList, function(index, item) {
  212. if (item.indexOf("fun_") > -1) {
  213. fun = item.split("fun_")[1];
  214. }
  215. if (item.indexOf("seq_") > -1) {
  216. seq = item.split("seq_")[1];
  217. }
  218. });
  219. var dim = 0;
  220. if (value.indexOf(i18n(tiposDados.vector)) > -1) {
  221. dim = value.split('[').length - 1;
  222. }
  223. for (tm in tiposDados) {
  224. if ($selectedItem.hasClass(tm)) {
  225. updateVariableType(fun, seq, tm, dim);
  226. break;
  227. }
  228. }
  229. }
  230. });
  231. $('.ui.dropdown.global_type').dropdown({
  232. onChange: function(value, text, $selectedItem) {
  233. classList = $selectedItem.attr('class').split(/\s+/);
  234. var fun;
  235. var seq;
  236. $.each(classList, function(index, item) {
  237. if (item.indexOf("seq_") > -1) {
  238. seq = item.split("seq_")[1];
  239. }
  240. });
  241. var dim = 0;
  242. if (value.indexOf(i18n(tiposDados.vector)) > -1) {
  243. dim = value.split('[').length - 1;
  244. }
  245. for (tm in tiposDados) {
  246. if ($selectedItem.hasClass(tm)) {
  247. updateGlobalType(seq, tm, dim);
  248. break;
  249. }
  250. }
  251. }
  252. });
  253. }
  254. function updateGlobalType(wich_variable, new_value, new_dimensions) {
  255. programa.globais[wich_variable].tipo = new_value;
  256. programa.globais[wich_variable].dimensoes = new_dimensions;
  257. if (new_dimensions > 0) {
  258. programa.globais[wich_variable].linhas = new_dimensions;
  259. programa.globais[wich_variable].colunas = 2;
  260. }
  261. if (new_value == tiposDados.integer) {
  262. if (new_dimensions == 0) {
  263. programa.globais[wich_variable].valor = 1;
  264. }
  265. if (new_dimensions == 1) {
  266. programa.globais[wich_variable].valor = [1, 1];
  267. }
  268. if (new_dimensions == 2) {
  269. programa.globais[wich_variable].valor = [[1, 1], [1, 1]];
  270. }
  271. }
  272. if (new_value == tiposDados.real) {
  273. if (new_dimensions == 0) {
  274. programa.globais[wich_variable].valor = 1.0;
  275. }
  276. if (new_dimensions == 1) {
  277. programa.globais[wich_variable].valor = [1.0, 1.0];
  278. }
  279. if (new_dimensions == 2) {
  280. programa.globais[wich_variable].valor = [[1.0, 1.0], [1.0, 1.0]];
  281. }
  282. }
  283. if (new_value == tiposDados.text) {
  284. if (new_dimensions == 0) {
  285. programa.globais[wich_variable].valor = i18n(tiposDados.text);
  286. }
  287. if (new_dimensions == 1) {
  288. programa.globais[wich_variable].valor = [i18n(tiposDados.text), i18n(tiposDados.text)];
  289. }
  290. if (new_dimensions == 2) {
  291. programa.globais[wich_variable].valor = [[i18n(tiposDados.text), i18n(tiposDados.text)], [i18n(tiposDados.text), i18n(tiposDados.text)]];
  292. }
  293. }
  294. if (new_value == tiposDados.boolean) {
  295. if (new_dimensions == 0) {
  296. programa.globais[wich_variable].valor = true;
  297. }
  298. if (new_dimensions == 1) {
  299. programa.globais[wich_variable].valor = [true, true];
  300. }
  301. if (new_dimensions == 2) {
  302. programa.globais[wich_variable].valor = [[true, true], [true, true]];
  303. }
  304. }
  305. renderAlgorithm();
  306. }
  307. function updateVariableType(wich_function, wich_variable, new_value, new_dimensions) {
  308. programa.funcoes[wich_function].variaveis[wich_variable].tipo = new_value;
  309. programa.funcoes[wich_function].variaveis[wich_variable].dimensoes = new_dimensions;
  310. if (new_dimensions > 0) {
  311. programa.funcoes[wich_function].variaveis[wich_variable].linhas = new_dimensions;
  312. programa.funcoes[wich_function].variaveis[wich_variable].colunas = 2;
  313. }
  314. if (new_value == tiposDados.integer) {
  315. if (new_dimensions == 0) {
  316. programa.funcoes[wich_function].variaveis[wich_variable].valor = 1;
  317. }
  318. if (new_dimensions == 1) {
  319. programa.funcoes[wich_function].variaveis[wich_variable].valor = [1, 1];
  320. }
  321. if (new_dimensions == 2) {
  322. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[1, 1], [1, 1]];
  323. }
  324. }
  325. if (new_value == tiposDados.real) {
  326. if (new_dimensions == 0) {
  327. programa.funcoes[wich_function].variaveis[wich_variable].valor = 1.0;
  328. }
  329. if (new_dimensions == 1) {
  330. programa.funcoes[wich_function].variaveis[wich_variable].valor = [1.0, 1.0];
  331. }
  332. if (new_dimensions == 2) {
  333. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[1.0, 1.0], [1.0, 1.0]];
  334. }
  335. }
  336. if (new_value == tiposDados.text) {
  337. if (new_dimensions == 0) {
  338. programa.funcoes[wich_function].variaveis[wich_variable].valor = i18n(tiposDados.text);
  339. }
  340. if (new_dimensions == 1) {
  341. programa.funcoes[wich_function].variaveis[wich_variable].valor = [i18n(tiposDados.text), i18n(tiposDados.text)];
  342. }
  343. if (new_dimensions == 2) {
  344. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[i18n(tiposDados.text), i18n(tiposDados.text)], [i18n(tiposDados.text), i18n(tiposDados.text)]];
  345. }
  346. }
  347. if (new_value == tiposDados.boolean) {
  348. if (new_dimensions == 0) {
  349. programa.funcoes[wich_function].variaveis[wich_variable].valor = true;
  350. }
  351. if (new_dimensions == 1) {
  352. programa.funcoes[wich_function].variaveis[wich_variable].valor = [true, true];
  353. }
  354. if (new_dimensions == 2) {
  355. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[true, true], [true, true]];
  356. }
  357. }
  358. renderAlgorithm();
  359. }
  360. function addGlobalColumnVector(which_variable) {
  361. programa.globais[which_variable].colunas ++;
  362. if (programa.globais[which_variable].tipo == tiposDados.integer) {
  363. programa.globais[which_variable].valor.push(1);
  364. }
  365. if (programa.globais[which_variable].tipo == tiposDados.real) {
  366. programa.globais[which_variable].valor.push(1.0);
  367. }
  368. if (programa.globais[which_variable].tipo == tiposDados.text) {
  369. programa.globais[which_variable].valor.push(i18n(tiposDados.text));
  370. }
  371. if (programa.globais[which_variable].tipo == tiposDados.boolean) {
  372. programa.globais[which_variable].valor.push(true);
  373. }
  374. renderAlgorithm();
  375. }
  376. function addColumnVector(which_function, which_variable) {
  377. programa.funcoes[which_function].variaveis[which_variable].colunas ++;
  378. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.integer) {
  379. programa.funcoes[which_function].variaveis[which_variable].valor.push(1);
  380. }
  381. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.real) {
  382. programa.funcoes[which_function].variaveis[which_variable].valor.push(1.0);
  383. }
  384. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.text) {
  385. programa.funcoes[which_function].variaveis[which_variable].valor.push(i18n(tiposDados.text));
  386. }
  387. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.boolean) {
  388. programa.funcoes[which_function].variaveis[which_variable].valor.push(true);
  389. }
  390. renderAlgorithm();
  391. }
  392. function addColumnMatrix(which_function, which_variable) {
  393. programa.funcoes[which_function].variaveis[which_variable].colunas ++;
  394. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.integer) {
  395. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  396. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(1);
  397. }
  398. }
  399. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.real) {
  400. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  401. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(1.0);
  402. }
  403. }
  404. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.text) {
  405. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  406. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(i18n(tiposDados.text));
  407. }
  408. }
  409. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.boolean) {
  410. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  411. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(true);
  412. }
  413. }
  414. renderAlgorithm();
  415. }
  416. function addColumnGlobalMatrix(which_variable) {
  417. programa.globais[which_variable].colunas ++;
  418. if (programa.globais[which_variable].tipo == tiposDados.integer) {
  419. for (i = 0; i < programa.globais[which_variable].linhas; i++) {
  420. programa.globais[which_variable].valor[i].push(1);
  421. }
  422. }
  423. if (programa.globais[which_variable].tipo == tiposDados.real) {
  424. for (i = 0; i < programa.globais[which_variable].linhas; i++) {
  425. programa.globais[which_variable].valor[i].push(1.0);
  426. }
  427. }
  428. if (programa.globais[which_variable].tipo == tiposDados.text) {
  429. for (i = 0; i < programa.globais[which_variable].linhas; i++) {
  430. programa.globais[which_variable].valor[i].push(i18n(tiposDados.text));
  431. }
  432. }
  433. if (programa.globais[which_variable].tipo == tiposDados.boolean) {
  434. for (i = 0; i < programa.globais[which_variable].linhas; i++) {
  435. programa.globais[which_variable].valor[i].push(true);
  436. }
  437. }
  438. renderAlgorithm();
  439. }
  440. function addLineMatrix(which_function, which_variable) {
  441. programa.funcoes[which_function].variaveis[which_variable].linhas ++;
  442. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.integer) {
  443. var n_l = [];
  444. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  445. n_l.push(1);
  446. }
  447. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  448. }
  449. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.real) {
  450. var n_l = [];
  451. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  452. n_l.push(1.0);
  453. }
  454. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  455. }
  456. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.text) {
  457. var n_l = [];
  458. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  459. n_l.push(i18n(tiposDados.text));
  460. }
  461. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  462. }
  463. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.boolean) {
  464. var n_l = [];
  465. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  466. n_l.push(true);
  467. }
  468. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  469. }
  470. renderAlgorithm();
  471. }
  472. function addLineGlobalMatrix(which_variable) {
  473. programa.globais[which_variable].linhas ++;
  474. if (programa.globais[which_variable].tipo == tiposDados.integer) {
  475. var n_l = [];
  476. for (i = 0; i < programa.globais[which_variable].colunas; i++) {
  477. n_l.push(1);
  478. }
  479. programa.globais[which_variable].valor.push(n_l);
  480. }
  481. if (programa.globais[which_variable].tipo == tiposDados.real) {
  482. var n_l = [];
  483. for (i = 0; i < programa.globais[which_variable].colunas; i++) {
  484. n_l.push(1.0);
  485. }
  486. programa.globais[which_variable].valor.push(n_l);
  487. }
  488. if (programa.globais[which_variable].tipo == tiposDados.text) {
  489. var n_l = [];
  490. for (i = 0; i < programa.globais[which_variable].colunas; i++) {
  491. n_l.push(i18n(tiposDados.text));
  492. }
  493. programa.globais[which_variable].valor.push(n_l);
  494. }
  495. if (programa.globais[which_variable].tipo == tiposDados.boolean) {
  496. var n_l = [];
  497. for (i = 0; i < programa.globais[which_variable].colunas; i++) {
  498. n_l.push(true);
  499. }
  500. programa.globais[which_variable].valor.push(n_l);
  501. }
  502. renderAlgorithm();
  503. }
  504. function removeGlobalColumnVector(which_variable) {
  505. if (programa.globais[which_variable].colunas == 0) {
  506. return;
  507. }
  508. programa.globais[which_variable].colunas --;
  509. programa.globais[which_variable].valor.splice(programa.globais[which_variable].valor.length - 1, 1);
  510. renderAlgorithm();
  511. }
  512. function removeColumnVector(which_function, which_variable) {
  513. if (programa.funcoes[which_function].variaveis[which_variable].colunas == 0) {
  514. return;
  515. }
  516. programa.funcoes[which_function].variaveis[which_variable].colunas --;
  517. programa.funcoes[which_function].variaveis[which_variable].valor.splice(programa.funcoes[which_function].variaveis[which_variable].valor.length - 1, 1);
  518. renderAlgorithm();
  519. }
  520. function removeColumnMatrix(which_function, which_variable) {
  521. if (programa.funcoes[which_function].variaveis[which_variable].colunas == 0) {
  522. return;
  523. }
  524. programa.funcoes[which_function].variaveis[which_variable].colunas --;
  525. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  526. programa.funcoes[which_function].variaveis[which_variable].valor[i].splice(programa.funcoes[which_function].variaveis[which_variable].valor[i].length - 1, 1);
  527. }
  528. renderAlgorithm();
  529. }
  530. function removeColumnGlobalMatrix(which_variable) {
  531. if (programa.globais[which_variable].colunas == 0) {
  532. return;
  533. }
  534. programa.globais[which_variable].colunas --;
  535. for (i = 0; i < programa.globais[which_variable].linhas; i++) {
  536. programa.globais[which_variable].valor[i].splice(programa.globais[which_variable].valor[i].length - 1, 1);
  537. }
  538. renderAlgorithm();
  539. }
  540. function removeLineGlobalMatrix(which_variable) {
  541. if (programa.globais[which_variable].linhas == 0) {
  542. return;
  543. }
  544. programa.globais[which_variable].linhas --;
  545. programa.globais[which_variable].valor.splice(programa.globais[which_variable].valor.length - 1, 1);
  546. renderAlgorithm();
  547. }
  548. function removeLineMatrix(which_function, which_variable) {
  549. if (programa.funcoes[which_function].variaveis[which_variable].linhas == 0) {
  550. return;
  551. }
  552. programa.funcoes[which_function].variaveis[which_variable].linhas --;
  553. programa.funcoes[which_function].variaveis[which_variable].valor.splice(programa.funcoes[which_function].variaveis[which_variable].valor.length - 1, 1);
  554. renderAlgorithm();
  555. }
  556. function addVariable(sequence) {//tipo, nome, valor
  557. var v = new Variavel(tiposDados.integer, i18n('new_variable') + '_' + counter_new_variables, 1);
  558. adicionarVariavel(sequence, v);
  559. counter_new_variables ++;
  560. renderAlgorithm();
  561. }
  562. function deleteVariable(which_function, which_variable) {
  563. programa.funcoes[which_function].variaveis.splice(which_variable, 1);
  564. renderAlgorithm();
  565. }
  566. function addParameter(sequence) {
  567. if (programa.funcoes[sequence].lista_parametros == null) {
  568. programa.funcoes[sequence].lista_parametros = new Array();
  569. }
  570. programa.funcoes[sequence].lista_parametros.push(new Variavel(tiposDados.integer, i18n("new_parameter") + "_" + counter_new_parameters));
  571. counter_new_parameters ++;
  572. renderAlgorithm();
  573. }
  574. function updateFunctionReturn(sequence, new_value) {
  575. if (new_value.indexOf(i18n(tiposDados.vector)) > -1) {
  576. programa.funcoes[sequence].dimensoes_retorno = 1;
  577. } else {
  578. programa.funcoes[sequence].dimensoes_retorno = 0;
  579. }
  580. }
  581. function updateParameterType(wich_function, wich_parameter, new_value, new_dimensions) {
  582. programa.funcoes[wich_function].lista_parametros[wich_parameter].tipo = new_value;
  583. programa.funcoes[wich_function].lista_parametros[wich_parameter].dimensoes = new_dimensions;
  584. }
  585. var opened_name_global = false;
  586. var opened_input_global = null;
  587. var sequence_name_opened_global;
  588. function enableNameGlobalUpdate(div_el, sequence) {
  589. if (opened_name_global) {
  590. $(opened_input_global).focus();
  591. return;
  592. }
  593. opened_name_global = true;
  594. sequence_name_opened_global = sequence;
  595. $(div_el).find('.span_name_variable').text('');
  596. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"+programa.globais[sequence].nome+"' />" ).insertBefore($(div_el).find('.span_name_variable'));
  597. $('.width-dynamic').on('input', function() {
  598. var inputWidth = $(this).textWidth()+10;
  599. opened_input_global = this;
  600. $(this).focus();
  601. var tmpStr = $(this).val();
  602. $(this).val('');
  603. $(this).val(tmpStr);
  604. $(this).css({
  605. width: inputWidth
  606. })
  607. }).trigger('input');
  608. $('.width-dynamic').focusout(function() {
  609. /// update array:
  610. if ($(this).val().trim()) {
  611. programa.globais[sequence].nome = $(this).val().trim();
  612. }
  613. $(this).remove();
  614. /// update elements:
  615. opened_name_global = false;
  616. opened_input_global = false;
  617. renderAlgorithm();
  618. });
  619. $('.width-dynamic').on('keydown', function(e) {
  620. var code = e.keyCode || e.which;
  621. if(code == 13) {
  622. if ($(this).val().trim()) {
  623. programa.globais[sequence].nome = $(this).val().trim();
  624. }
  625. $(this).remove();
  626. /// update elements:
  627. opened_name_global = false;
  628. opened_input_global = false;
  629. renderAlgorithm();
  630. }
  631. if(code == 27) {
  632. $(div_el).find('.span_name_function').text(programa.globais[sequence].nome);
  633. $(this).remove();
  634. /// update elements:
  635. opened_name_global = false;
  636. opened_input_global = false;
  637. }
  638. });
  639. }
  640. var opened_name_function = false;
  641. var opened_input = null;
  642. var sequence_name_opened;
  643. function enableNameFunctionUpdate(div_el, sequence) {
  644. if (opened_name_function) {
  645. $(opened_input).focus();
  646. return;
  647. }
  648. opened_name_function = true;
  649. sequence_name_opened = sequence;
  650. $(div_el).find('.span_name_function').text('');
  651. $( "<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'));
  652. $('.width-dynamic').on('input', function() {
  653. var inputWidth = $(this).textWidth()+10;
  654. opened_input = this;
  655. $(this).focus();
  656. var tmpStr = $(this).val();
  657. $(this).val('');
  658. $(this).val(tmpStr);
  659. $(this).css({
  660. width: inputWidth
  661. })
  662. }).trigger('input');
  663. $('.width-dynamic').focusout(function() {
  664. /// update array:
  665. if ($(this).val().trim()) {
  666. programa.funcoes[sequence_name_opened].nome = $(this).val().trim();
  667. }
  668. $(this).remove();
  669. /// update elements:
  670. opened_name_function = false;
  671. opened_input = false;
  672. renderAlgorithm();
  673. });
  674. $('.width-dynamic').on('keydown', function(e) {
  675. var code = e.keyCode || e.which;
  676. if(code == 13) {
  677. if ($(this).val().trim()) {
  678. programa.funcoes[sequence_name_opened].nome = $(this).val().trim();
  679. }
  680. $(this).remove();
  681. /// update elements:
  682. opened_name_function = false;
  683. opened_input = false;
  684. renderAlgorithm();
  685. }
  686. if(code == 27) {
  687. $(div_el).find('.span_name_function').text(programa.funcoes[sequence_name_opened].nome);
  688. $(this).remove();
  689. /// update elements:
  690. opened_name_function = false;
  691. opened_input = false;
  692. }
  693. });
  694. }
  695. function alternateBooleanVarVectorValue(parent_node, which_function, which_var, column_index) {
  696. programa.funcoes[which_function].variaveis[which_var].valor[column_index] = !programa.funcoes[which_function].variaveis[which_var].valor[column_index];
  697. renderAlgorithm();
  698. }
  699. function alternateBooleanGlobalVectorValue(parent_node, which_var, column_index) {
  700. programa.globais[which_var].valor[column_index] = !programa.globais[which_var].valor[column_index];
  701. renderAlgorithm();
  702. }
  703. function alternateBooleanVarMatrixValue(parent_node, which_function, which_var, row_index, column_index) {
  704. programa.funcoes[which_function].variaveis[which_var].valor[row_index][column_index] = !programa.funcoes[which_function].variaveis[which_var].valor[row_index][column_index];
  705. renderAlgorithm();
  706. }
  707. function alternateBooleanGlobalMatrixValue(parent_node, which_var, row_index, column_index) {
  708. programa.globais[which_var].valor[row_index][column_index] = !programa.globais[which_var].valor[row_index][column_index];
  709. renderAlgorithm();
  710. }
  711. function alternateBooleanGlobalValue(parent_node, which_var) {
  712. programa.globais[which_var].valor = !programa.globais[which_var].valor;
  713. renderAlgorithm();
  714. }
  715. function alternateBooleanVarValue(parent_node, which_function, which_var) {
  716. programa.funcoes[which_function].variaveis[which_var].valor = !programa.funcoes[which_function].variaveis[which_var].valor;
  717. renderAlgorithm();
  718. }
  719. var opened_name_value_vector_global_ = false;
  720. var opened_input_value_vector_global_ = null;
  721. var sequence_name_opened_value_vector_global_;
  722. function enableGlobalVectorValueUpdate(parent_node, which_parameter, column_index) {
  723. if (opened_name_value_vector_global_) {
  724. $(opened_input_value_vector_global_).focus();
  725. return;
  726. }
  727. opened_name_value_vector_global_ = true;
  728. sequence_name_opened_value_vector_global_ = which_parameter;
  729. $(parent_node).find('.span_value_variable').text('');
  730. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  731. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  732. + programa.globais[which_parameter].valor[column_index].toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  733. } else {
  734. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  735. + programa.globais[which_parameter].valor[column_index] + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  736. }
  737. $('.width-dynamic').on('input', function() {
  738. var inputWidth = $(this).textWidth()+10;
  739. opened_input_value_vector_global_ = this;
  740. $(this).focus();
  741. var tmpStr = $(this).val();
  742. $(this).val('');
  743. $(this).val(tmpStr);
  744. $(this).css({
  745. width: inputWidth
  746. })
  747. }).trigger('input');
  748. $('.width-dynamic').focusout(function() {
  749. /// update array:
  750. if ($(this).val().trim()) {
  751. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  752. programa.globais[which_parameter].valor[column_index] = parseFloat($(this).val().trim());
  753. } else {
  754. if (programa.globais[which_parameter].tipo == tiposDados.integer) {
  755. programa.globais[which_parameter].valor[column_index] = parseInt($(this).val().trim());
  756. } else {
  757. programa.globais[which_parameter].valor[column_index] = $(this).val().trim();
  758. }
  759. }
  760. }
  761. $(this).remove();
  762. /// update elements:
  763. opened_name_value_vector_global_ = false;
  764. opened_input_value_vector_global_ = false;
  765. renderAlgorithm();
  766. });
  767. $('.width-dynamic').on('keydown', function(e) {
  768. var code = e.keyCode || e.which;
  769. if(code == 13) {
  770. if ($(this).val().trim()) {
  771. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  772. programa.globais[which_parameter].valor[column_index] = parseFloat($(this).val().trim());
  773. } else {
  774. if (programa.globais[which_parameter].tipo == tiposDados.integer) {
  775. programa.globais[which_parameter].valor[column_index] = parseInt($(this).val().trim());
  776. } else {
  777. programa.globais[which_parameter].valor[column_index] = $(this).val().trim();
  778. }
  779. }
  780. }
  781. $(this).remove();
  782. /// update elements:
  783. opened_name_value_vector_global_ = false;
  784. opened_input_value_vector_global_ = false;
  785. renderAlgorithm();
  786. }
  787. if(code == 27) {
  788. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  789. $(parent_node).find('.span_value_variable').text(programa.globais[which_parameter].valor[column_index].toFixed(1));
  790. } else {
  791. $(parent_node).find('.span_value_variable').text(programa.globais[which_parameter].valor[column_index]);
  792. }
  793. $(this).remove();
  794. /// update elements:
  795. opened_name_value_vector_global_ = false;
  796. opened_input_value_vector_global_ = false;
  797. }
  798. });
  799. }
  800. var opened_name_value_vector_variable = false;
  801. var opened_input_value_vector_variable = null;
  802. var sequence_name_opened_value_vector_variable;
  803. var sequence_function_opened_value_vector_variable;
  804. function enableVarVectorValueUpdate(parent_node, which_function, which_parameter, column_index) {
  805. if (opened_name_value_vector_variable) {
  806. $(opened_input_value_vector_variable).focus();
  807. return;
  808. }
  809. opened_name_value_vector_variable = true;
  810. sequence_name_opened_value_vector_variable = which_parameter;
  811. sequence_function_opened_value_vector_variable = which_function;
  812. $(parent_node).find('.span_value_variable').text('');
  813. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  814. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  815. + programa.funcoes[which_function].variaveis[which_parameter].valor[column_index].toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  816. } else {
  817. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  818. + programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  819. }
  820. $('.width-dynamic').on('input', function() {
  821. var inputWidth = $(this).textWidth()+10;
  822. opened_input_value_vector_variable = this;
  823. $(this).focus();
  824. var tmpStr = $(this).val();
  825. $(this).val('');
  826. $(this).val(tmpStr);
  827. $(this).css({
  828. width: inputWidth
  829. })
  830. }).trigger('input');
  831. $('.width-dynamic').focusout(function() {
  832. /// update array:
  833. if ($(this).val().trim()) {
  834. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  835. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseFloat($(this).val().trim());
  836. } else {
  837. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  838. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseInt($(this).val().trim());
  839. } else {
  840. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = $(this).val().trim();
  841. }
  842. }
  843. }
  844. $(this).remove();
  845. /// update elements:
  846. opened_name_value_vector_variable = false;
  847. opened_input_value_vector_variable = false;
  848. renderAlgorithm();
  849. });
  850. $('.width-dynamic').on('keydown', function(e) {
  851. var code = e.keyCode || e.which;
  852. if(code == 13) {
  853. if ($(this).val().trim()) {
  854. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  855. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseFloat($(this).val().trim());
  856. } else {
  857. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  858. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseInt($(this).val().trim());
  859. } else {
  860. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = $(this).val().trim();
  861. }
  862. }
  863. }
  864. $(this).remove();
  865. /// update elements:
  866. opened_name_value_vector_variable = false;
  867. opened_input_value_vector_variable = false;
  868. renderAlgorithm();
  869. }
  870. if(code == 27) {
  871. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  872. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[column_index].toFixed(1));
  873. } else {
  874. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[column_index]);
  875. }
  876. $(this).remove();
  877. /// update elements:
  878. opened_name_value_vector_variable = false;
  879. opened_input_value_vector_variable = false;
  880. }
  881. });
  882. }
  883. var opened_name_value_matrix_global_v = false;
  884. var opened_input_value_matrix_global_v = null;
  885. var sequence_name_opened_value_matrix_global_v;
  886. function enableGlobalMatrixValueUpdate(parent_node, which_parameter, row_index, column_index) {
  887. if (opened_name_value_matrix_global_v) {
  888. $(opened_input_value_matrix_global_v).focus();
  889. return;
  890. }
  891. opened_name_value_matrix_global_v = true;
  892. sequence_name_opened_value_matrix_global_v = which_parameter;
  893. $(parent_node).find('.span_value_variable').text('');
  894. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  895. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  896. + programa.globais[which_parameter].valor[row_index][column_index].toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  897. } else {
  898. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  899. + programa.globais[which_parameter].valor[row_index][column_index] + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  900. }
  901. $('.width-dynamic').on('input', function() {
  902. var inputWidth = $(this).textWidth()+10;
  903. opened_input_value_matrix_global_v = this;
  904. $(this).focus();
  905. var tmpStr = $(this).val();
  906. $(this).val('');
  907. $(this).val(tmpStr);
  908. $(this).css({
  909. width: inputWidth
  910. })
  911. }).trigger('input');
  912. $('.width-dynamic').focusout(function() {
  913. /// update array:
  914. if ($(this).val().trim()) {
  915. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  916. programa.globais[which_parameter].valor[row_index][column_index] = parseFloat($(this).val().trim());
  917. } else {
  918. if (programa.globais[which_parameter].tipo == tiposDados.integer) {
  919. programa.globais[which_parameter].valor[row_index][column_index] = parseInt($(this).val().trim());
  920. } else {
  921. programa.globais[which_parameter].valor[row_index][column_index] = $(this).val().trim();
  922. }
  923. }
  924. }
  925. $(this).remove();
  926. /// update elements:
  927. opened_name_value_matrix_global_v = false;
  928. opened_input_value_matrix_global_v = false;
  929. renderAlgorithm();
  930. });
  931. $('.width-dynamic').on('keydown', function(e) {
  932. var code = e.keyCode || e.which;
  933. if(code == 13) {
  934. if ($(this).val().trim()) {
  935. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  936. programa.globais[which_parameter].valor[row_index][column_index] = parseFloat($(this).val().trim());
  937. } else {
  938. if (programa.globais[which_parameter].tipo == tiposDados.integer) {
  939. programa.globais[which_parameter].valor[row_index][column_index] = parseInt($(this).val().trim());
  940. } else {
  941. programa.globais[which_parameter].valor[row_index][column_index] = $(this).val().trim();
  942. }
  943. }
  944. }
  945. $(this).remove();
  946. /// update elements:
  947. opened_name_value_matrix_global_v = false;
  948. opened_input_value_matrix_global_v = false;
  949. renderAlgorithm();
  950. }
  951. if(code == 27) {
  952. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  953. $(parent_node).find('.span_value_variable').text(programa.globais[which_parameter].valor[row_index][column_index].toFixed(1));
  954. } else {
  955. $(parent_node).find('.span_value_variable').text(programa.globais[which_parameter].valor[row_index][column_index]);
  956. }
  957. $(this).remove();
  958. /// update elements:
  959. opened_name_value_matrix_global_v = false;
  960. opened_input_value_matrix_global_v = false;
  961. }
  962. });
  963. }
  964. var opened_name_value_matrix_variable = false;
  965. var opened_input_value_matrix_variable = null;
  966. var sequence_name_opened_value_matrix_variable;
  967. var sequence_function_opened_value_matrix_variable;
  968. function enableVarMatrixValueUpdate(parent_node, which_function, which_parameter, row_index, column_index) {
  969. if (opened_name_value_matrix_variable) {
  970. $(opened_input_value_matrix_variable).focus();
  971. return;
  972. }
  973. opened_name_value_matrix_variable = true;
  974. sequence_name_opened_value_matrix_variable = which_parameter;
  975. sequence_function_opened_value_matrix_variable = which_function;
  976. $(parent_node).find('.span_value_variable').text('');
  977. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  978. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  979. + programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index].toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  980. } else {
  981. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  982. + programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  983. }
  984. $('.width-dynamic').on('input', function() {
  985. var inputWidth = $(this).textWidth()+10;
  986. opened_input_value_matrix_variable = this;
  987. $(this).focus();
  988. var tmpStr = $(this).val();
  989. $(this).val('');
  990. $(this).val(tmpStr);
  991. $(this).css({
  992. width: inputWidth
  993. })
  994. }).trigger('input');
  995. $('.width-dynamic').focusout(function() {
  996. /// update array:
  997. if ($(this).val().trim()) {
  998. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  999. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseFloat($(this).val().trim());
  1000. } else {
  1001. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  1002. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseInt($(this).val().trim());
  1003. } else {
  1004. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = $(this).val().trim();
  1005. }
  1006. }
  1007. }
  1008. $(this).remove();
  1009. /// update elements:
  1010. opened_name_value_matrix_variable = false;
  1011. opened_input_value_matrix_variable = false;
  1012. renderAlgorithm();
  1013. });
  1014. $('.width-dynamic').on('keydown', function(e) {
  1015. var code = e.keyCode || e.which;
  1016. if(code == 13) {
  1017. if ($(this).val().trim()) {
  1018. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1019. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseFloat($(this).val().trim());
  1020. } else {
  1021. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  1022. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseInt($(this).val().trim());
  1023. } else {
  1024. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = $(this).val().trim();
  1025. }
  1026. }
  1027. }
  1028. $(this).remove();
  1029. /// update elements:
  1030. opened_name_value_matrix_variable = false;
  1031. opened_input_value_matrix_variable = false;
  1032. renderAlgorithm();
  1033. }
  1034. if(code == 27) {
  1035. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1036. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index].toFixed(1));
  1037. } else {
  1038. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index]);
  1039. }
  1040. $(this).remove();
  1041. /// update elements:
  1042. opened_name_value_matrix_variable = false;
  1043. opened_input_value_matrix_variable = false;
  1044. }
  1045. });
  1046. }
  1047. var opened_name_value_global_var = false;
  1048. var opened_input_value_global_ar = null;
  1049. var sequence_name_opened_value_global_var;
  1050. function enableGlobalValueUpdate(parent_node, which_parameter) {
  1051. if (opened_name_value_global_var) {
  1052. $(opened_input_value_global_ar).focus();
  1053. return;
  1054. }
  1055. opened_name_value_global_var = true;
  1056. sequence_name_opened_value_global_var = which_parameter;
  1057. $(parent_node).find('.span_value_variable').text('');
  1058. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1059. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1060. + programa.globais[which_parameter].valor.toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1061. } else {
  1062. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1063. + programa.globais[which_parameter].valor + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1064. }
  1065. $('.width-dynamic').on('input', function() {
  1066. var inputWidth = $(this).textWidth()+10;
  1067. opened_input_value_global_ar = this;
  1068. $(this).focus();
  1069. var tmpStr = $(this).val();
  1070. $(this).val('');
  1071. $(this).val(tmpStr);
  1072. $(this).css({
  1073. width: inputWidth
  1074. })
  1075. }).trigger('input');
  1076. $('.width-dynamic').focusout(function() {
  1077. /// update array:
  1078. if ($(this).val().trim()) {
  1079. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1080. programa.globais[which_parameter].valor = parseFloat($(this).val().trim());
  1081. } else{
  1082. if (programa.globais[which_parameter].tipo == tiposDados.integer) {
  1083. programa.globais[which_parameter].valor = parseInt($(this).val().trim());
  1084. } else {
  1085. programa.globais[which_parameter].valor = $(this).val().trim();
  1086. }
  1087. }
  1088. }
  1089. $(this).remove();
  1090. /// update elements:
  1091. opened_name_value_global_var = false;
  1092. opened_input_value_global_ar = false;
  1093. renderAlgorithm();
  1094. });
  1095. $('.width-dynamic').on('keydown', function(e) {
  1096. var code = e.keyCode || e.which;
  1097. if(code == 13) {
  1098. if ($(this).val().trim()) {
  1099. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1100. programa.globais[which_parameter].valor = parseFloat($(this).val().trim());
  1101. } else{
  1102. if (programa.globais[which_parameter].tipo == tiposDados.integer) {
  1103. programa.globais[which_parameter].valor = parseInt($(this).val().trim());
  1104. } else {
  1105. programa.globais[which_parameter].valor = $(this).val().trim();
  1106. }
  1107. }
  1108. }
  1109. $(this).remove();
  1110. /// update elements:
  1111. opened_name_value_global_var = false;
  1112. opened_input_value_global_ar = false;
  1113. renderAlgorithm();
  1114. }
  1115. if(code == 27) {
  1116. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1117. $(parent_node).find('.span_value_variable').text(programa.globais[which_parameter].valor.toFixed(1));
  1118. } else{
  1119. $(parent_node).find('.span_value_variable').text(programa.globais[which_parameter].valor);
  1120. }
  1121. $(this).remove();
  1122. /// update elements:
  1123. opened_name_value_global_var = false;
  1124. opened_input_value_global_ar = false;
  1125. }
  1126. });
  1127. }
  1128. var opened_name_value_variable = false;
  1129. var opened_input_value_variable = null;
  1130. var sequence_name_opened_value_variable;
  1131. var sequence_function_opened_value_variable;
  1132. function enableVarValueUpdate(parent_node, which_function, which_parameter) {
  1133. if (opened_name_value_variable) {
  1134. $(opened_input_value_variable).focus();
  1135. return;
  1136. }
  1137. opened_name_value_variable = true;
  1138. sequence_name_opened_value_variable = which_parameter;
  1139. sequence_function_opened_value_variable = which_function;
  1140. $(parent_node).find('.span_value_variable').text('');
  1141. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1142. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1143. + programa.funcoes[which_function].variaveis[which_parameter].valor.toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1144. } else {
  1145. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1146. + programa.funcoes[which_function].variaveis[which_parameter].valor + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1147. }
  1148. $('.width-dynamic').on('input', function() {
  1149. var inputWidth = $(this).textWidth()+10;
  1150. opened_input_value_variable = this;
  1151. $(this).focus();
  1152. var tmpStr = $(this).val();
  1153. $(this).val('');
  1154. $(this).val(tmpStr);
  1155. $(this).css({
  1156. width: inputWidth
  1157. })
  1158. }).trigger('input');
  1159. $('.width-dynamic').focusout(function() {
  1160. /// update array:
  1161. if ($(this).val().trim()) {
  1162. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1163. programa.funcoes[which_function].variaveis[which_parameter].valor = parseFloat($(this).val().trim());
  1164. } else{
  1165. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  1166. programa.funcoes[which_function].variaveis[which_parameter].valor = parseInt($(this).val().trim());
  1167. } else {
  1168. programa.funcoes[which_function].variaveis[which_parameter].valor = $(this).val().trim();
  1169. }
  1170. }
  1171. }
  1172. $(this).remove();
  1173. /// update elements:
  1174. opened_name_value_variable = false;
  1175. opened_input_value_variable = false;
  1176. renderAlgorithm();
  1177. });
  1178. $('.width-dynamic').on('keydown', function(e) {
  1179. var code = e.keyCode || e.which;
  1180. if(code == 13) {
  1181. if ($(this).val().trim()) {
  1182. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1183. programa.funcoes[which_function].variaveis[which_parameter].valor = parseFloat($(this).val().trim());
  1184. } else{
  1185. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  1186. programa.funcoes[which_function].variaveis[which_parameter].valor = parseInt($(this).val().trim());
  1187. } else {
  1188. programa.funcoes[which_function].variaveis[which_parameter].valor = $(this).val().trim();
  1189. }
  1190. }
  1191. }
  1192. $(this).remove();
  1193. /// update elements:
  1194. opened_name_value_variable = false;
  1195. opened_input_value_variable = false;
  1196. renderAlgorithm();
  1197. }
  1198. if(code == 27) {
  1199. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1200. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor.toFixed(1));
  1201. } else{
  1202. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor);
  1203. }
  1204. $(this).remove();
  1205. /// update elements:
  1206. opened_name_value_variable = false;
  1207. opened_input_value_variable = false;
  1208. }
  1209. });
  1210. }
  1211. var opened_name_variable = false;
  1212. var opened_input_variable = null;
  1213. var sequence_name_opened_variable;
  1214. var sequence_function_opened_variable;
  1215. function enableNameVariableUpdate(parent_node, which_function, which_parameter) {
  1216. if (opened_name_variable) {
  1217. $(opened_input_variable).focus();
  1218. return;
  1219. }
  1220. opened_name_variable = true;
  1221. sequence_name_opened_variable = which_parameter;
  1222. sequence_function_opened_variable = which_function;
  1223. $(parent_node).find('.span_name_variable').text('');
  1224. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1225. + programa.funcoes[which_function].variaveis[which_parameter].nome + "' />" ).insertBefore($(parent_node).find('.span_name_variable'));
  1226. $('.width-dynamic').on('input', function() {
  1227. var inputWidth = $(this).textWidth()+10;
  1228. opened_input_variable = this;
  1229. $(this).focus();
  1230. var tmpStr = $(this).val();
  1231. $(this).val('');
  1232. $(this).val(tmpStr);
  1233. $(this).css({
  1234. width: inputWidth
  1235. })
  1236. }).trigger('input');
  1237. $('.width-dynamic').focusout(function() {
  1238. /// update array:
  1239. if ($(this).val().trim()) {
  1240. programa.funcoes[which_function].variaveis[which_parameter].nome = $(this).val().trim();
  1241. }
  1242. $(this).remove();
  1243. /// update elements:
  1244. opened_name_variable = false;
  1245. opened_input_variable = false;
  1246. renderAlgorithm();
  1247. });
  1248. $('.width-dynamic').on('keydown', function(e) {
  1249. var code = e.keyCode || e.which;
  1250. if(code == 13) {
  1251. if ($(this).val().trim()) {
  1252. programa.funcoes[which_function].variaveis[which_parameter].nome = $(this).val().trim();
  1253. }
  1254. $(this).remove();
  1255. /// update elements:
  1256. opened_name_variable = false;
  1257. opened_input_variable = false;
  1258. renderAlgorithm();
  1259. }
  1260. if(code == 27) {
  1261. $(parent_node).find('.span_name_variable').text(programa.funcoes[which_function].variaveis[which_parameter].nome);
  1262. $(this).remove();
  1263. /// update elements:
  1264. opened_name_variable = false;
  1265. opened_input_variable = false;
  1266. }
  1267. });
  1268. }
  1269. var opened_name_comment = false;
  1270. var opened_input_comment = null;
  1271. var sequence_name_opened_comment;
  1272. var sequence_function_opened_comment;
  1273. function enableCommentUpdate(parent_node, function_index, is_function_comment, comment_index) {
  1274. if (opened_name_comment) {
  1275. $(opened_input_comment).focus();
  1276. return;
  1277. }
  1278. opened_name_comment = true;
  1279. sequence_name_opened_comment = comment_index;
  1280. sequence_function_opened_comment = function_index;
  1281. $(parent_node).find('.span_comment_text').text('');
  1282. var temp_value = "";
  1283. if (is_function_comment) {
  1284. temp_value = programa.funcoes[function_index].comentario_funcao.texto_comentario;
  1285. } else {
  1286. temp_value = programa.funcoes[function_index].comandos[comment_index].texto_comentario;
  1287. }
  1288. $( "<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'));
  1289. $('.width-dynamic').on('input', function() {
  1290. var inputWidth = $(this).textWidth()+10;
  1291. opened_input_comment = this;
  1292. $(this).focus();
  1293. var tmpStr = $(this).val();
  1294. $(this).val('');
  1295. $(this).val(tmpStr);
  1296. $(this).css({
  1297. width: inputWidth
  1298. })
  1299. }).trigger('input');
  1300. $('.width-dynamic').focusout(function() {
  1301. /// update array:
  1302. if ($(this).val().trim()) {
  1303. var n_value = $(this).val().trim();
  1304. if (is_function_comment) {
  1305. programa.funcoes[function_index].comentario_funcao.texto_comentario = n_value;
  1306. } else {
  1307. temp_value = programa.funcoes[function_index].comandos[comment_index].texto_comentario = n_value;
  1308. }
  1309. }
  1310. $(this).remove();
  1311. /// update elements:
  1312. opened_name_comment = false;
  1313. opened_input_comment = false;
  1314. renderAlgorithm();
  1315. });
  1316. $('.width-dynamic').on('keydown', function(e) {
  1317. var code = e.keyCode || e.which;
  1318. if(code == 13) {
  1319. if ($(this).val().trim()) {
  1320. var n_value = $(this).val().trim();
  1321. if (is_function_comment) {
  1322. programa.funcoes[function_index].comentario_funcao.texto_comentario = n_value;
  1323. } else {
  1324. temp_value = programa.funcoes[function_index].comandos[comment_index].texto_comentario = n_value;
  1325. }
  1326. }
  1327. $(this).remove();
  1328. /// update elements:
  1329. opened_name_comment = false;
  1330. opened_input_comment = false;
  1331. renderAlgorithm();
  1332. }
  1333. if(code == 27) {
  1334. $(parent_node).find('.span_comment_text').text(temp_value);
  1335. $(this).remove();
  1336. /// update elements:
  1337. opened_name_comment = false;
  1338. opened_input_comment = false;
  1339. }
  1340. });
  1341. }
  1342. var opened_name_parameter = false;
  1343. var opened_input_parameter = null;
  1344. var sequence_name_opened_parameter;
  1345. var sequence_function_opened_parameter;
  1346. function enableNameParameterUpdate(parent_node, which_function, which_parameter) {
  1347. if (opened_name_parameter) {
  1348. $(opened_input_parameter).focus();
  1349. return;
  1350. }
  1351. opened_name_parameter = true;
  1352. sequence_name_opened_parameter = which_parameter;
  1353. sequence_function_opened_parameter = which_function;
  1354. $(parent_node).find('.span_name_parameter').text('');
  1355. $( "<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'));
  1356. $('.width-dynamic').on('input', function() {
  1357. var inputWidth = $(this).textWidth()+10;
  1358. opened_input_parameter = this;
  1359. $(this).focus();
  1360. var tmpStr = $(this).val();
  1361. $(this).val('');
  1362. $(this).val(tmpStr);
  1363. $(this).css({
  1364. width: inputWidth
  1365. })
  1366. }).trigger('input');
  1367. $('.width-dynamic').focusout(function() {
  1368. /// update array:
  1369. if ($(this).val().trim()) {
  1370. programa.funcoes[which_function].lista_parametros[which_parameter].nome = $(this).val().trim();
  1371. }
  1372. $(this).remove();
  1373. /// update elements:
  1374. opened_name_parameter = false;
  1375. opened_input_parameter = false;
  1376. renderAlgorithm();
  1377. });
  1378. $('.width-dynamic').on('keydown', function(e) {
  1379. var code = e.keyCode || e.which;
  1380. if(code == 13) {
  1381. if ($(this).val().trim()) {
  1382. programa.funcoes[which_function].lista_parametros[which_parameter].nome = $(this).val().trim();
  1383. }
  1384. $(this).remove();
  1385. /// update elements:
  1386. opened_name_parameter = false;
  1387. opened_input_parameter = false;
  1388. renderAlgorithm();
  1389. }
  1390. if(code == 27) {
  1391. $(parent_node).find('.span_name_parameter').text(programa.funcoes[which_function].lista_parametros[which_parameter].nome);
  1392. $(this).remove();
  1393. /// update elements:
  1394. opened_name_parameter = false;
  1395. opened_input_parameter = false;
  1396. }
  1397. });
  1398. }
  1399. function removeParameter(parent_node, which_function, which_parameter) {
  1400. programa.funcoes[which_function].lista_parametros.splice(which_parameter, 1);
  1401. renderAlgorithm();
  1402. }
  1403. function appendFunction(function_obj, sequence) {
  1404. var appender = '<div class="ui secondary segment function_div list-group-item">';
  1405. if (function_obj.comentario_funcao) {
  1406. appender += renderComment(function_obj.comentario_funcao, sequence, true, -1);
  1407. }
  1408. appender += '<span class="glyphicon glyphicon-move move_function" aria-hidden="true"><i class="icon sort alternate vertical"></i></span>';
  1409. 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>')
  1410. + '<button class="ui icon button tiny minimize_function_button" onclick="minimizeFunctionHandler(this.parentNode, '+sequence+')"><i class="icon window minimize"></i></button>';
  1411. 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>';
  1412. appender += '<div class="function_signature_div">'+i18n('function')+' ';
  1413. if (function_obj.eh_principal) {
  1414. 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> '
  1415. + '( <div class="ui large labels parameters_list">';
  1416. } else {
  1417. appender += renderFunctionReturn(function_obj, sequence);
  1418. 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> '
  1419. + '( <i class="ui icon plus square outline add_parameter" onclick="addParameter('+sequence+')"></i> <div class="ui large labels parameters_list">';
  1420. }
  1421. appender += renderFunctionParameters(function_obj, sequence);
  1422. appender += '</div> ) {</div>'
  1423. + (function_obj.esta_oculta ? ' <div class="function_area" style="display: none;"> ' : ' <div class="function_area"> ')
  1424. + '<div class="ui top attached segment variables_list_div">'
  1425. + renderVariables(function_obj, sequence)
  1426. + '</div>'
  1427. + '<div class="ui bottom attached segment commands_list_div"></div>'
  1428. + '<div class="function_close_div">}</div>'
  1429. + '</div>'
  1430. + '</div>';
  1431. $('.all_functions').append(appender);
  1432. }
  1433. function renderComment(comment_obj, function_index, is_function_comment, comment_index) {
  1434. var ret = '';
  1435. ret += '<div class="ui comment"> <i class="ui icon small quote left"></i> <span class="span_comment_text" ondblclick="enableCommentUpdate(this.parentNode, '+function_index+', '
  1436. +is_function_comment+', '+comment_index+')"> ' + comment_obj.texto_comentario + ' </span>';
  1437. ret += '</div>';
  1438. return ret;
  1439. }
  1440. // Essa função imprime os parâmetros e cria os elementos para a sua manipulação
  1441. function renderFunctionParameters(function_obj, sequence) {
  1442. var ret = "";
  1443. if (function_obj.lista_parametros != null) {
  1444. for (var j = 0; j < function_obj.lista_parametros.length; j++) {
  1445. var par_temp = function_obj.lista_parametros[j];
  1446. 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>';
  1447. ret += '<div class="ui dropdown parameter_type seq_'+j+' fun_'+sequence+'">';
  1448. if (par_temp.dimensoes > 0) {
  1449. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+ i18n(tiposDados.vector)+':'+i18n(par_temp.tipo);
  1450. ret += '</div>';
  1451. } else {
  1452. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+i18n(par_temp.tipo)+'</div>';
  1453. }
  1454. ret += '<i class="dropdown icon"></i>'
  1455. + '<div class="menu seq_'+j+' fun_'+sequence+'">';
  1456. var i = 0;
  1457. for (tm in tiposDados) {
  1458. i ++;
  1459. if (i == 1) { continue; }
  1460. if (i == (Object.keys(tiposDados).length)) { break; }
  1461. ret += '<div class="item ' + ((par_temp.tipo == tm && par_temp.dimensoes < 1) ? ' selected ' : '') + ' seq_'+j+' fun_'+sequence+' '+tm+'" >'+i18n(tm)+'</div>';
  1462. }
  1463. i = 0;
  1464. for (tm in tiposDados) {
  1465. i ++;
  1466. if (i == 1) { continue; }
  1467. if (i == (Object.keys(tiposDados).length)) { break; }
  1468. ret += '<div class="item seq_'+j+' '+tm+' fun_'+sequence+' ' + ((par_temp.tipo == tm && par_temp.dimensoes > 0) ? ' selected ' : '') + ' ">'
  1469. + i18n(tiposDados.vector)+':'+i18n(tm)
  1470. + '</div>';
  1471. }
  1472. ret += '</div></div>';
  1473. ret += ' <i class="red icon times remove_parameter" onclick="removeParameter(this.parentNode, '+sequence+', '+j+')"></i></div>';
  1474. }
  1475. }
  1476. return ret;
  1477. }
  1478. // Essa função imprime as variáveis e os recursos para sua manipulação
  1479. function renderVariables(function_obj, sequence) {
  1480. var ret = "";
  1481. if (function_obj.variaveis != null) {
  1482. for (var j = 0; j < function_obj.variaveis.length; j++) {
  1483. var par_temp = function_obj.variaveis[j];
  1484. 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>';
  1485. ret += '<div class="ui dropdown variable_type seq_'+j+' fun_'+sequence+'">';
  1486. if (par_temp.dimensoes > 0) {
  1487. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+ i18n(tiposDados.vector)+':'+i18n(par_temp.tipo);
  1488. for (i = 0; i < par_temp.dimensoes; i ++) {
  1489. ret += ' [ ] ';
  1490. }
  1491. ret += '</div>';
  1492. } else {
  1493. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+i18n(par_temp.tipo)+'</div>';
  1494. }
  1495. ret += '<i class="dropdown icon"></i>'
  1496. + '<div class="menu seq_'+j+' fun_'+sequence+'">';
  1497. var i = 0;
  1498. for (tm in tiposDados) {
  1499. i ++;
  1500. if (i == 1) { continue; }
  1501. if (i == (Object.keys(tiposDados).length)) { break; }
  1502. ret += '<div class="item ' + (par_temp.tipo == tm ? ' selected ' : '') + ' seq_'+j+' fun_'+sequence+' '+tm+'" >'+i18n(tm)+'</div>';
  1503. }
  1504. i = 0;
  1505. for (tm in tiposDados) {
  1506. i ++;
  1507. if (i == 1) { continue; }
  1508. if (i == (Object.keys(tiposDados).length)) { break; }
  1509. ret += '<div class="item seq_'+j+' fun_'+sequence+'">'
  1510. + '<i class="dropdown icon"></i>'
  1511. + i18n(tiposDados.vector)+':'+i18n(tm)
  1512. + '<div class="menu seq_'+j+' fun_'+sequence+'">'
  1513. + '<div class="item seq_'+j+' fun_'+sequence+' '+tm+'" data-text="'+ i18n(tiposDados.vector)+':'+i18n(tm)+' [ ] ">[ ]</div>'
  1514. + '<div class="item seq_'+j+' fun_'+sequence+' '+tm+'" data-text="'+ i18n(tiposDados.vector)+':'+i18n(tm)+' [ ] [ ] ">[ ] [ ] </div>'
  1515. + '</div>'
  1516. + '</div>';
  1517. }
  1518. ret += '</div></div> = ';
  1519. if (par_temp.dimensoes == 0) {
  1520. if (par_temp.tipo == tiposDados.real) {
  1521. 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> ';
  1522. } else {
  1523. if (par_temp.tipo == tiposDados.boolean) {
  1524. 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> ';
  1525. } else {
  1526. 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> ';
  1527. }
  1528. }
  1529. } else {
  1530. ret += '<table class="tabela_var">';
  1531. if (par_temp.dimensoes == 1) {
  1532. ret += '<tr>';
  1533. if (par_temp.tipo == tiposDados.real) {
  1534. for (var k = 0; k < par_temp.colunas; k++) {
  1535. ret += '<td><span class="span_value_variable" ondblclick="enableVarVectorValueUpdate(this.parentNode, '+sequence+', '+j+', '+k+')" >'+par_temp.valor[k].toFixed(1)+'</span>'+'</td>';
  1536. }
  1537. } else {
  1538. for (var k = 0; k < par_temp.colunas; k++) {
  1539. if (par_temp.tipo == tiposDados.boolean) {
  1540. ret += '<td><span class="span_value_variable" ondblclick="alternateBooleanVarVectorValue(this.parentNode, '+sequence+', '+j+', '+k+')" >'+par_temp.valor[k]+'</span>'+'</td>';
  1541. } else {
  1542. ret += '<td><span class="span_value_variable" ondblclick="enableVarVectorValueUpdate(this.parentNode, '+sequence+', '+j+', '+k+')" >'+par_temp.valor[k]+'</span>'+'</td>';
  1543. }
  1544. }
  1545. }
  1546. ret += '</tr>';
  1547. ret += '</table>';
  1548. ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline" onclick="removeColumnVector('+sequence+', '+j+')"></i>'
  1549. + ' <i class="ui icon plus square outline" onclick="addColumnVector('+sequence+', '+j+')"></i></div>';
  1550. }
  1551. if (par_temp.dimensoes == 2) {
  1552. if (par_temp.tipo == tiposDados.real) {
  1553. for (var l = 0; l < par_temp.linhas; l++) {
  1554. ret += '<tr>';
  1555. for (var k = 0; k < par_temp.colunas; k++) {
  1556. ret += '<td><span class="span_value_variable" ondblclick="enableVarMatrixValueUpdate(this.parentNode, '+sequence+', '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k].toFixed(1)+'</span>'+'</td>';
  1557. }
  1558. ret += '</tr>';
  1559. }
  1560. } else {
  1561. for (var l = 0; l < par_temp.linhas; l++) {
  1562. ret += '<tr>';
  1563. for (var k = 0; k < par_temp.colunas; k++) {
  1564. if (par_temp.tipo == tiposDados.boolean) {
  1565. ret += '<td><span class="span_value_variable" ondblclick="alternateBooleanVarMatrixValue(this.parentNode, '+sequence+', '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k]+'</span>'+'</td>';
  1566. } else {
  1567. ret += '<td><span class="span_value_variable" ondblclick="enableVarMatrixValueUpdate(this.parentNode, '+sequence+', '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k]+'</span>'+'</td>';
  1568. }
  1569. }
  1570. ret += '</tr>';
  1571. }
  1572. }
  1573. if (par_temp.linhas == 0) {
  1574. ret += '<tr><td></td></tr>';
  1575. }
  1576. ret += '<tr><td colspan="'+par_temp.colunas+'" class="tr_manage_lines"><i class="ui icon minus square outline" onclick="removeLineMatrix('+sequence+', '+j+')"></i>'
  1577. + ' <i class="ui icon plus square outline" onclick="addLineMatrix('+sequence+', '+j+')"></i></td></tr>';
  1578. ret += '</table>';
  1579. ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline" onclick="removeColumnMatrix('+sequence+', '+j+')"></i>'
  1580. + ' <i class="ui icon plus square outline" onclick="addColumnMatrix('+sequence+', '+j+')"></i></div>';
  1581. }
  1582. }
  1583. ret += ' <i class="red icon times remove_parameter" onclick="deleteVariable('+sequence+', '+j+')"></i></div>';
  1584. }
  1585. }
  1586. return ret;
  1587. }
  1588. // Essa função imprime o tipo de retorno da função e cria o menu do tipo 'select' para alteração
  1589. function renderFunctionReturn(function_obj, sequence) {
  1590. var ret = '<div class="ui dropdown function_return seq_'+sequence+'">';
  1591. if (function_obj.dimensoes_retorno > 0) {
  1592. ret += '<div class="text seq_'+sequence+'"">'+ i18n(tiposDados.vector)+':'+i18n(function_obj.tipo_retorno);
  1593. ret += '</div>';
  1594. } else {
  1595. ret += '<div class="text seq_'+sequence+'"">'+i18n(function_obj.tipo_retorno)+'</div>';
  1596. }
  1597. ret += '<i class="dropdown icon"></i>'
  1598. + '<div class="menu seq_'+sequence+'"">';
  1599. var i = 0;
  1600. for (tm in tiposDados) {
  1601. if (i == (Object.keys(tiposDados).length - 1)) { break; }
  1602. ret += '<div class="item ' + ((function_obj.tipo_retorno == tm && function_obj.dimensoes_retorno < 1) ? ' selected ' : '') + ' seq_'+sequence+' '+tm+'" >'+i18n(tm)+'</div>';
  1603. i ++;
  1604. }
  1605. i = 0;
  1606. for (tm in tiposDados) {
  1607. i ++;
  1608. if (i == 1) { continue; }
  1609. if (i == (Object.keys(tiposDados).length)) { break; }
  1610. 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)+' ">'
  1611. + i18n(tiposDados.vector)+':'+i18n(tm)
  1612. + '</div>';
  1613. }
  1614. ret += '</div></div>';
  1615. return ret;
  1616. }
  1617. $.fn.textWidth = function(text, font) {
  1618. if (!$.fn.textWidth.fakeEl) $.fn.textWidth.fakeEl = $('<span>').hide().appendTo(document.body);
  1619. $.fn.textWidth.fakeEl.text(text || this.val() || this.text() || this.attr('placeholder')).css('font', font || this.css('font'));
  1620. return $.fn.textWidth.fakeEl.width();
  1621. };