ivprog-visual-functions-1.0.js 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599
  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. var has_element_created_draged = false;
  163. var which_element_is_draged = null;
  164. function manageCommand(event) {
  165. $( ".created_element" ).each(function( index ) {
  166. $(this).remove();
  167. });
  168. var el = document.elementFromPoint(event.clientX, event.clientY);
  169. // Só irá adicionar se soltar o elemento no espaço para a função correta:
  170. if ($(el).data('fun') == function_to_add) {
  171. // Se a lista de comandos estiver vazia, então é o primeiro.
  172. // Portanto, ele deve soltar o elemento obrigatoriamente no objeto vazio
  173. if ((programa.funcoes[function_to_add].comandos == null) || (programa.funcoes[function_to_add].comandos.length == 0)) {
  174. // pode adicionar
  175. programa.funcoes[function_to_add].comandos = [];
  176. programa.funcoes[function_to_add].comandos.push(createElementGenericFunction());
  177. console.log("PP1");
  178. } else { // Entra nesse else, caso já existam outros comandos no bloco:
  179. findNearbyCommandToAdd(el, event);
  180. console.log("PP2");
  181. }
  182. } else { // Se entrar nesse bloco 'else', quer dizer que o usuário não soltou o elemento necessariamente na div específica
  183. // portanto, devemos procurar nos elementos DOM superiores, se existe algum com o data-fun
  184. /*var hier = $(el).parentsUntil(".all_functions");
  185. for (i = 0; i < hier.length; i++) {
  186. if ($(hier[i]).data('fun') == function_to_add) {
  187. programa.funcoes[function_to_add].comandos.push(createElementGenericFunction());
  188. break;
  189. }
  190. }*/
  191. findPositionAndInsertCommand(el, event);
  192. }
  193. //console.log("onde soltou:");
  194. //console.log(el);
  195. has_element_created_draged = false;
  196. which_element_is_draged = null;
  197. function_to_add = -1;
  198. renderAlgorithm();
  199. }
  200. function findNearbyCommandToAdd(el, event) {
  201. var all_sub = $('#function_drag_cmd_' + function_to_add).find('div');
  202. console.log(all_sub);
  203. var menor_distancia = 999999999;
  204. var elemento_menor_distancia = null;
  205. var antes = true;
  206. var t_bot;
  207. var t_top;
  208. // Descobrindo o elemento mais próximo:
  209. for (i = 0; i < all_sub.length; i++) {
  210. t_top = all_sub[i].getBoundingClientRect().top;
  211. t_bot = all_sub[i].getBoundingClientRect().top + all_sub[i].getBoundingClientRect().height;
  212. if ((t_top - event.clientY) < menor_distancia) {
  213. menor_distancia = event.clientY - t_top;
  214. elemento_menor_distancia = all_sub[i];
  215. }
  216. }
  217. programa.funcoes[function_to_add].comandos.splice($(elemento_menor_distancia).data('index'), 0, createElementGenericFunction());
  218. console.log("\n\nRESULTADO: ");
  219. console.log("elemento mais próximo: ");
  220. console.log(elemento_menor_distancia);
  221. console.log("antes? " + antes);
  222. console.log("menor distancia: " + menor_distancia);
  223. }
  224. function findPositionAndInsertCommand(el, event) {
  225. var identificado_local = false;
  226. if ($(el).data('command') >= 0) {
  227. console.log("soltou em cima de um command: ");
  228. // primeiro: descobrir se ele soltou para adicionar antes ou depois:
  229. var metade_componente = el.getBoundingClientRect().top + (el.getBoundingClientRect().height / 2);
  230. var antes = false;
  231. if (event.clientY < metade_componente) {
  232. antes = true;
  233. }
  234. // segundo: descobrir o contexto que está sendo inserido o comando:
  235. // se o data-parent for 0, então, ele não está inserido em um sub-bloco
  236. if ($(el).data('parent') == "0") {
  237. // vai adicionar no bloco da função
  238. if (antes) {
  239. programa.funcoes[function_to_add].comandos.splice($(el).data('index'), 0, createElementGenericFunction());
  240. } else {
  241. programa.funcoes[function_to_add].comandos.splice($(el).data('index') + 1, 0, createElementGenericFunction());
  242. }
  243. } else { // caso exista mais informação no parent, então, deve-se descobrir a hierarquia
  244. }
  245. identificado_local = true;
  246. }
  247. if (identificado_local == false) {
  248. var hier = $(el).parentsUntil(".all_functions");
  249. for (i = 0; i < hier.length; i++) {
  250. console.log("elemento índice: " + i);
  251. console.log(hier[i]);
  252. if ($(hier[i]).data('command') >= 0) {
  253. console.log("soltou em cima de um elemento dentro de um command!");
  254. identificado_local = true;
  255. break;
  256. }
  257. }
  258. }
  259. }
  260. function createElementGenericFunction() {
  261. if (which_element_is_draged == tiposComandos.comment) {
  262. return new Comentario(i18n('text_comment'));
  263. }
  264. if (which_element_is_draged == tiposComandos.reader) {
  265. return new Leitura(null);
  266. }
  267. if (which_element_is_draged == tiposComandos.writer) {
  268. return new Escrita(null);
  269. }
  270. if (which_element_is_draged == tiposComandos.attribution) {
  271. return new Atribuicao(null, null);
  272. }
  273. if (which_element_is_draged == tiposComandos.iftrue) {
  274. return new SeVerdadeiro(null, null, null);
  275. }
  276. if (which_element_is_draged == tiposComandos.repeatNtimes) {
  277. return new RepitaNVezes(null, null, null, null);
  278. }
  279. if (which_element_is_draged == tiposComandos.whiletrue) {
  280. return new EnquantoVerdadeiro(null, null);
  281. }
  282. if (which_element_is_draged == tiposComandos.dowhiletrue) {
  283. return new FacaEnquantoVerdadeiro(null, null);
  284. }
  285. if (which_element_is_draged == tiposComandos.switch) {
  286. return new Escolha(null, null);
  287. }
  288. if (which_element_is_draged == tiposComandos.functioncall) {
  289. return new ChamadaFuncao(null, null);
  290. }
  291. }
  292. function createWriterObject() {
  293. var ret = '';
  294. ret += '<div class="ui writer created_element" onclick="manageCommand(event)"> <i class="ui icon small upload"></i> <span> '+i18n('write')+' x </span>';
  295. ret += '</div>';
  296. return ret;
  297. }
  298. function createCommentDragObject() {
  299. var ret = '';
  300. ret += '<div class="ui comment created_element" onclick="manageCommand(event)"> <i class="ui icon small quote left"></i> <span class="span_comment_text" "> '+i18n('text_comment')+' </span>';
  301. ret += '</div>';
  302. return ret;
  303. }
  304. function createReaderObject() {
  305. var ret = '';
  306. ret += '<div class="ui reader created_element" onclick="manageCommand(event)"> <i class="ui icon small download"></i> <span> '+i18n('read')+' x </span>';
  307. ret += '</div>';
  308. return ret;
  309. }
  310. function createAttributionDragObject() {
  311. var ret = '';
  312. ret += '<div class="ui attribution created_element" onclick="manageCommand(event)"> <i class="ui icon small arrow left"></i> <span> x = 1 + 1 </span>';
  313. ret += '</div>';
  314. return ret;
  315. }
  316. function createIfTrueDragObject() {
  317. var ret = '';
  318. ret += '<div class="ui iftrue created_element" onclick="manageCommand(event)"> <i class="ui icon small random"></i> <span> if (x < 1) { } </span>';
  319. ret += '</div>';
  320. return ret;
  321. }
  322. function createRepeatNtimesDragObject() {
  323. var ret = '';
  324. ret += '<div class="ui repeatNtimes created_element" onclick="manageCommand(event)"> <i class="ui icon small sync"></i> <span> para (x = 0; x < 10; x ++) { } </span>';
  325. ret += '</div>';
  326. return ret;
  327. }
  328. function createWhileTrueDragObject() {
  329. var ret = '';
  330. ret += '<div class="ui whiletrue created_element" onclick="manageCommand(event)"> <i class="ui icon small sync"></i> <span> enquanto(x < 10) { } </span>';
  331. ret += '</div>';
  332. return ret;
  333. }
  334. function createDoWhileTrueDragObject() {
  335. var ret = '';
  336. ret += '<div class="ui dowhiletrue created_element" onclick="manageCommand(event)"> <i class="ui icon small sync"></i> <span> faça {<br>} enquanto(x < 10) </span>';
  337. ret += '</div>';
  338. return ret;
  339. }
  340. function createSwitchDragObject() {
  341. var ret = '';
  342. ret += '<div class="ui switch created_element" onclick="manageCommand(event)"> <i class="ui icon small random"></i> <span> escolha (x) { <br> caso 1: <br> caso 2: <br> } </span>';
  343. ret += '</div>';
  344. return ret;
  345. }
  346. function createFunctioncallDragObject() {
  347. var ret = '';
  348. ret += '<div class="ui functioncall created_element" onclick="manageCommand(event)"> <i class="hand point right icon"></i> <span> funcao() </span>';
  349. ret += '</div>';
  350. return ret;
  351. }
  352. var function_to_add = -1;
  353. function addHandlers() {
  354. $('.create_functioncall').on('click', function(e){
  355. has_element_created_draged = true;
  356. which_element_is_draged = tiposComandos.functioncall;
  357. function_to_add = $(e.target).data('fun');
  358. var inner = $(createFunctioncallDragObject()).draggable().appendTo("body");
  359. inner.css("position", "absolute");
  360. e.type = "mousedown.draggable";
  361. e.target = inner[0];
  362. inner.css("left", e.pageX - 15);
  363. inner.css("top", e.pageY - 15);
  364. inner.trigger(e);
  365. });
  366. $('.create_switch').on('click', function(e){
  367. has_element_created_draged = true;
  368. which_element_is_draged = tiposComandos.switch;
  369. function_to_add = $(e.target).data('fun');
  370. var inner = $(createSwitchDragObject()).draggable().appendTo("body");
  371. inner.css("position", "absolute");
  372. e.type = "mousedown.draggable";
  373. e.target = inner[0];
  374. inner.css("left", e.pageX - 15);
  375. inner.css("top", e.pageY - 15);
  376. inner.trigger(e);
  377. });
  378. $('.create_dowhiletrue').on('click', function(e){
  379. has_element_created_draged = true;
  380. which_element_is_draged = tiposComandos.dowhiletrue;
  381. function_to_add = $(e.target).data('fun');
  382. var inner = $(createDoWhileTrueDragObject()).draggable().appendTo("body");
  383. inner.css("position", "absolute");
  384. e.type = "mousedown.draggable";
  385. e.target = inner[0];
  386. inner.css("left", e.pageX - 15);
  387. inner.css("top", e.pageY - 15);
  388. inner.trigger(e);
  389. });
  390. $('.create_whiletrue').on('click', function(e){
  391. has_element_created_draged = true;
  392. which_element_is_draged = tiposComandos.whiletrue;
  393. function_to_add = $(e.target).data('fun');
  394. var inner = $(createWhileTrueDragObject()).draggable().appendTo("body");
  395. inner.css("position", "absolute");
  396. e.type = "mousedown.draggable";
  397. e.target = inner[0];
  398. inner.css("left", e.pageX - 15);
  399. inner.css("top", e.pageY - 15);
  400. inner.trigger(e);
  401. });
  402. $('.create_repeatNtimes').on('click', function(e){
  403. has_element_created_draged = true;
  404. which_element_is_draged = tiposComandos.repeatNtimes;
  405. function_to_add = $(e.target).data('fun');
  406. var inner = $(createRepeatNtimesDragObject()).draggable().appendTo("body");
  407. inner.css("position", "absolute");
  408. e.type = "mousedown.draggable";
  409. e.target = inner[0];
  410. inner.css("left", e.pageX - 15);
  411. inner.css("top", e.pageY - 15);
  412. inner.trigger(e);
  413. });
  414. $('.create_iftrue').on('click', function(e){
  415. has_element_created_draged = true;
  416. which_element_is_draged = tiposComandos.iftrue;
  417. function_to_add = $(e.target).data('fun');
  418. var inner = $(createIfTrueDragObject()).draggable().appendTo("body");
  419. inner.css("position", "absolute");
  420. e.type = "mousedown.draggable";
  421. e.target = inner[0];
  422. inner.css("left", e.pageX - 15);
  423. inner.css("top", e.pageY - 15);
  424. inner.trigger(e);
  425. });
  426. $('.create_comment').on('click', function(e){
  427. has_element_created_draged = true;
  428. which_element_is_draged = tiposComandos.comment;
  429. function_to_add = $(e.target).data('fun');
  430. var inner = $(createCommentDragObject()).draggable().appendTo("body");
  431. inner.css("position", "absolute");
  432. e.type = "mousedown.draggable";
  433. e.target = inner[0];
  434. inner.css("left", e.pageX - 15);
  435. inner.css("top", e.pageY - 15);
  436. inner.trigger(e);
  437. });
  438. $('.create_attribution').on('click', function(e){
  439. has_element_created_draged = true;
  440. which_element_is_draged = tiposComandos.attribution;
  441. function_to_add = $(e.target).data('fun');
  442. var inner = $(createAttributionDragObject()).draggable().appendTo("body");
  443. inner.css("position", "absolute");
  444. e.type = "mousedown.draggable";
  445. e.target = inner[0];
  446. inner.css("left", e.pageX - 15);
  447. inner.css("top", e.pageY - 15);
  448. inner.trigger(e);
  449. });
  450. $('.create_writer').on('click', function(e){
  451. has_element_created_draged = true;
  452. which_element_is_draged = tiposComandos.writer;
  453. function_to_add = $(e.target).data('fun');
  454. var inner = $(createWriterObject()).draggable().appendTo("body");
  455. inner.css("position", "absolute");
  456. e.type = "mousedown.draggable";
  457. e.target = inner[0];
  458. inner.css("left", e.pageX - 15);
  459. inner.css("top", e.pageY - 15);
  460. inner.trigger(e);
  461. });
  462. $('.create_reader').on('click', function(e){
  463. has_element_created_draged = true;
  464. which_element_is_draged = tiposComandos.reader;
  465. function_to_add = $(e.target).data('fun');
  466. var inner = $(createReaderObject()).draggable().appendTo("body");
  467. inner.css("position", "absolute");
  468. e.type = "mousedown.draggable";
  469. e.target = inner[0];
  470. inner.css("left", e.pageX - 15);
  471. inner.css("top", e.pageY - 15);
  472. inner.trigger(e);
  473. });
  474. for (i = 0; i < programa.funcoes.length; i++) {
  475. Sortable.create(document.getElementById('function_drag_cmd_' + i), {
  476. handle: '.command_drag',
  477. animation: 100,
  478. ghostClass: 'ghost',
  479. group: 'commands_inside_function_drag_' + i,
  480. onEnd: function (evt) {
  481. //updateSequenceFunctionHandler(evt.oldIndex, evt.newIndex);
  482. },
  483. onStart: function (evt) {
  484. console.log("começou");
  485. }
  486. });
  487. }
  488. $('.ui.buttons .dropdown').dropdown();
  489. $('.ui.dropdown.function_return')
  490. .dropdown({
  491. onChange: function(value, text, $selectedItem) {
  492. classList = $selectedItem.attr('class').split(/\s+/);
  493. $.each(classList, function(index, item) {
  494. if (item.indexOf("seq_") > -1) {
  495. seq = item.split("seq_")[1];
  496. for (tm in tiposDados) {
  497. if ($selectedItem.hasClass(tm)) {
  498. programa.funcoes[seq].tipo_retorno = tm;
  499. }
  500. }
  501. updateFunctionReturn(seq, value);
  502. }
  503. });
  504. }
  505. })
  506. ;
  507. $('.ui.dropdown.parameter_type').dropdown({
  508. onChange: function(value, text, $selectedItem) {
  509. classList = $selectedItem.attr('class').split(/\s+/);
  510. var fun;
  511. var seq;
  512. $.each(classList, function(index, item) {
  513. if (item.indexOf("fun_") > -1) {
  514. fun = item.split("fun_")[1];
  515. }
  516. if (item.indexOf("seq_") > -1) {
  517. seq = item.split("seq_")[1];
  518. }
  519. });
  520. var dim = 0;
  521. if (value.indexOf(i18n(tiposDados.vector)) > -1) {
  522. dim = 1;
  523. }
  524. for (tm in tiposDados) {
  525. if ($selectedItem.hasClass(tm)) {
  526. updateParameterType(fun, seq, tm, dim);
  527. break;
  528. }
  529. }
  530. }
  531. });
  532. $('.ui.dropdown.variable_type').dropdown({
  533. onChange: function(value, text, $selectedItem) {
  534. classList = $selectedItem.attr('class').split(/\s+/);
  535. var fun;
  536. var seq;
  537. $.each(classList, function(index, item) {
  538. if (item.indexOf("fun_") > -1) {
  539. fun = item.split("fun_")[1];
  540. }
  541. if (item.indexOf("seq_") > -1) {
  542. seq = item.split("seq_")[1];
  543. }
  544. });
  545. var dim = 0;
  546. if (value.indexOf(i18n(tiposDados.vector)) > -1) {
  547. dim = value.split('[').length - 1;
  548. }
  549. for (tm in tiposDados) {
  550. if ($selectedItem.hasClass(tm)) {
  551. updateVariableType(fun, seq, tm, dim);
  552. break;
  553. }
  554. }
  555. }
  556. });
  557. $('.ui.dropdown.global_type').dropdown({
  558. onChange: function(value, text, $selectedItem) {
  559. classList = $selectedItem.attr('class').split(/\s+/);
  560. var fun;
  561. var seq;
  562. $.each(classList, function(index, item) {
  563. if (item.indexOf("seq_") > -1) {
  564. seq = item.split("seq_")[1];
  565. }
  566. });
  567. var dim = 0;
  568. if (value.indexOf(i18n(tiposDados.vector)) > -1) {
  569. dim = value.split('[').length - 1;
  570. }
  571. for (tm in tiposDados) {
  572. if ($selectedItem.hasClass(tm)) {
  573. updateGlobalType(seq, tm, dim);
  574. break;
  575. }
  576. }
  577. }
  578. });
  579. }
  580. function updateGlobalType(wich_variable, new_value, new_dimensions) {
  581. programa.globais[wich_variable].tipo = new_value;
  582. programa.globais[wich_variable].dimensoes = new_dimensions;
  583. if (new_dimensions > 0) {
  584. programa.globais[wich_variable].linhas = new_dimensions;
  585. programa.globais[wich_variable].colunas = 2;
  586. }
  587. if (new_value == tiposDados.integer) {
  588. if (new_dimensions == 0) {
  589. programa.globais[wich_variable].valor = 1;
  590. }
  591. if (new_dimensions == 1) {
  592. programa.globais[wich_variable].valor = [1, 1];
  593. }
  594. if (new_dimensions == 2) {
  595. programa.globais[wich_variable].valor = [[1, 1], [1, 1]];
  596. }
  597. }
  598. if (new_value == tiposDados.real) {
  599. if (new_dimensions == 0) {
  600. programa.globais[wich_variable].valor = 1.0;
  601. }
  602. if (new_dimensions == 1) {
  603. programa.globais[wich_variable].valor = [1.0, 1.0];
  604. }
  605. if (new_dimensions == 2) {
  606. programa.globais[wich_variable].valor = [[1.0, 1.0], [1.0, 1.0]];
  607. }
  608. }
  609. if (new_value == tiposDados.text) {
  610. if (new_dimensions == 0) {
  611. programa.globais[wich_variable].valor = i18n(tiposDados.text);
  612. }
  613. if (new_dimensions == 1) {
  614. programa.globais[wich_variable].valor = [i18n(tiposDados.text), i18n(tiposDados.text)];
  615. }
  616. if (new_dimensions == 2) {
  617. programa.globais[wich_variable].valor = [[i18n(tiposDados.text), i18n(tiposDados.text)], [i18n(tiposDados.text), i18n(tiposDados.text)]];
  618. }
  619. }
  620. if (new_value == tiposDados.boolean) {
  621. if (new_dimensions == 0) {
  622. programa.globais[wich_variable].valor = true;
  623. }
  624. if (new_dimensions == 1) {
  625. programa.globais[wich_variable].valor = [true, true];
  626. }
  627. if (new_dimensions == 2) {
  628. programa.globais[wich_variable].valor = [[true, true], [true, true]];
  629. }
  630. }
  631. renderAlgorithm();
  632. }
  633. function updateVariableType(wich_function, wich_variable, new_value, new_dimensions) {
  634. programa.funcoes[wich_function].variaveis[wich_variable].tipo = new_value;
  635. programa.funcoes[wich_function].variaveis[wich_variable].dimensoes = new_dimensions;
  636. if (new_dimensions > 0) {
  637. programa.funcoes[wich_function].variaveis[wich_variable].linhas = new_dimensions;
  638. programa.funcoes[wich_function].variaveis[wich_variable].colunas = 2;
  639. }
  640. if (new_value == tiposDados.integer) {
  641. if (new_dimensions == 0) {
  642. programa.funcoes[wich_function].variaveis[wich_variable].valor = 1;
  643. }
  644. if (new_dimensions == 1) {
  645. programa.funcoes[wich_function].variaveis[wich_variable].valor = [1, 1];
  646. }
  647. if (new_dimensions == 2) {
  648. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[1, 1], [1, 1]];
  649. }
  650. }
  651. if (new_value == tiposDados.real) {
  652. if (new_dimensions == 0) {
  653. programa.funcoes[wich_function].variaveis[wich_variable].valor = 1.0;
  654. }
  655. if (new_dimensions == 1) {
  656. programa.funcoes[wich_function].variaveis[wich_variable].valor = [1.0, 1.0];
  657. }
  658. if (new_dimensions == 2) {
  659. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[1.0, 1.0], [1.0, 1.0]];
  660. }
  661. }
  662. if (new_value == tiposDados.text) {
  663. if (new_dimensions == 0) {
  664. programa.funcoes[wich_function].variaveis[wich_variable].valor = i18n(tiposDados.text);
  665. }
  666. if (new_dimensions == 1) {
  667. programa.funcoes[wich_function].variaveis[wich_variable].valor = [i18n(tiposDados.text), i18n(tiposDados.text)];
  668. }
  669. if (new_dimensions == 2) {
  670. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[i18n(tiposDados.text), i18n(tiposDados.text)], [i18n(tiposDados.text), i18n(tiposDados.text)]];
  671. }
  672. }
  673. if (new_value == tiposDados.boolean) {
  674. if (new_dimensions == 0) {
  675. programa.funcoes[wich_function].variaveis[wich_variable].valor = true;
  676. }
  677. if (new_dimensions == 1) {
  678. programa.funcoes[wich_function].variaveis[wich_variable].valor = [true, true];
  679. }
  680. if (new_dimensions == 2) {
  681. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[true, true], [true, true]];
  682. }
  683. }
  684. renderAlgorithm();
  685. }
  686. function addGlobalColumnVector(which_variable) {
  687. programa.globais[which_variable].colunas ++;
  688. if (programa.globais[which_variable].tipo == tiposDados.integer) {
  689. programa.globais[which_variable].valor.push(1);
  690. }
  691. if (programa.globais[which_variable].tipo == tiposDados.real) {
  692. programa.globais[which_variable].valor.push(1.0);
  693. }
  694. if (programa.globais[which_variable].tipo == tiposDados.text) {
  695. programa.globais[which_variable].valor.push(i18n(tiposDados.text));
  696. }
  697. if (programa.globais[which_variable].tipo == tiposDados.boolean) {
  698. programa.globais[which_variable].valor.push(true);
  699. }
  700. renderAlgorithm();
  701. }
  702. function addColumnVector(which_function, which_variable) {
  703. programa.funcoes[which_function].variaveis[which_variable].colunas ++;
  704. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.integer) {
  705. programa.funcoes[which_function].variaveis[which_variable].valor.push(1);
  706. }
  707. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.real) {
  708. programa.funcoes[which_function].variaveis[which_variable].valor.push(1.0);
  709. }
  710. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.text) {
  711. programa.funcoes[which_function].variaveis[which_variable].valor.push(i18n(tiposDados.text));
  712. }
  713. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.boolean) {
  714. programa.funcoes[which_function].variaveis[which_variable].valor.push(true);
  715. }
  716. renderAlgorithm();
  717. }
  718. function addColumnMatrix(which_function, which_variable) {
  719. programa.funcoes[which_function].variaveis[which_variable].colunas ++;
  720. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.integer) {
  721. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  722. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(1);
  723. }
  724. }
  725. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.real) {
  726. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  727. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(1.0);
  728. }
  729. }
  730. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.text) {
  731. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  732. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(i18n(tiposDados.text));
  733. }
  734. }
  735. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.boolean) {
  736. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  737. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(true);
  738. }
  739. }
  740. renderAlgorithm();
  741. }
  742. function addColumnGlobalMatrix(which_variable) {
  743. programa.globais[which_variable].colunas ++;
  744. if (programa.globais[which_variable].tipo == tiposDados.integer) {
  745. for (i = 0; i < programa.globais[which_variable].linhas; i++) {
  746. programa.globais[which_variable].valor[i].push(1);
  747. }
  748. }
  749. if (programa.globais[which_variable].tipo == tiposDados.real) {
  750. for (i = 0; i < programa.globais[which_variable].linhas; i++) {
  751. programa.globais[which_variable].valor[i].push(1.0);
  752. }
  753. }
  754. if (programa.globais[which_variable].tipo == tiposDados.text) {
  755. for (i = 0; i < programa.globais[which_variable].linhas; i++) {
  756. programa.globais[which_variable].valor[i].push(i18n(tiposDados.text));
  757. }
  758. }
  759. if (programa.globais[which_variable].tipo == tiposDados.boolean) {
  760. for (i = 0; i < programa.globais[which_variable].linhas; i++) {
  761. programa.globais[which_variable].valor[i].push(true);
  762. }
  763. }
  764. renderAlgorithm();
  765. }
  766. function addLineMatrix(which_function, which_variable) {
  767. programa.funcoes[which_function].variaveis[which_variable].linhas ++;
  768. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.integer) {
  769. var n_l = [];
  770. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  771. n_l.push(1);
  772. }
  773. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  774. }
  775. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.real) {
  776. var n_l = [];
  777. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  778. n_l.push(1.0);
  779. }
  780. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  781. }
  782. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.text) {
  783. var n_l = [];
  784. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  785. n_l.push(i18n(tiposDados.text));
  786. }
  787. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  788. }
  789. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.boolean) {
  790. var n_l = [];
  791. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  792. n_l.push(true);
  793. }
  794. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  795. }
  796. renderAlgorithm();
  797. }
  798. function addLineGlobalMatrix(which_variable) {
  799. programa.globais[which_variable].linhas ++;
  800. if (programa.globais[which_variable].tipo == tiposDados.integer) {
  801. var n_l = [];
  802. for (i = 0; i < programa.globais[which_variable].colunas; i++) {
  803. n_l.push(1);
  804. }
  805. programa.globais[which_variable].valor.push(n_l);
  806. }
  807. if (programa.globais[which_variable].tipo == tiposDados.real) {
  808. var n_l = [];
  809. for (i = 0; i < programa.globais[which_variable].colunas; i++) {
  810. n_l.push(1.0);
  811. }
  812. programa.globais[which_variable].valor.push(n_l);
  813. }
  814. if (programa.globais[which_variable].tipo == tiposDados.text) {
  815. var n_l = [];
  816. for (i = 0; i < programa.globais[which_variable].colunas; i++) {
  817. n_l.push(i18n(tiposDados.text));
  818. }
  819. programa.globais[which_variable].valor.push(n_l);
  820. }
  821. if (programa.globais[which_variable].tipo == tiposDados.boolean) {
  822. var n_l = [];
  823. for (i = 0; i < programa.globais[which_variable].colunas; i++) {
  824. n_l.push(true);
  825. }
  826. programa.globais[which_variable].valor.push(n_l);
  827. }
  828. renderAlgorithm();
  829. }
  830. function removeGlobalColumnVector(which_variable) {
  831. if (programa.globais[which_variable].colunas == 0) {
  832. return;
  833. }
  834. programa.globais[which_variable].colunas --;
  835. programa.globais[which_variable].valor.splice(programa.globais[which_variable].valor.length - 1, 1);
  836. renderAlgorithm();
  837. }
  838. function removeColumnVector(which_function, which_variable) {
  839. if (programa.funcoes[which_function].variaveis[which_variable].colunas == 0) {
  840. return;
  841. }
  842. programa.funcoes[which_function].variaveis[which_variable].colunas --;
  843. programa.funcoes[which_function].variaveis[which_variable].valor.splice(programa.funcoes[which_function].variaveis[which_variable].valor.length - 1, 1);
  844. renderAlgorithm();
  845. }
  846. function removeColumnMatrix(which_function, which_variable) {
  847. if (programa.funcoes[which_function].variaveis[which_variable].colunas == 0) {
  848. return;
  849. }
  850. programa.funcoes[which_function].variaveis[which_variable].colunas --;
  851. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  852. programa.funcoes[which_function].variaveis[which_variable].valor[i].splice(programa.funcoes[which_function].variaveis[which_variable].valor[i].length - 1, 1);
  853. }
  854. renderAlgorithm();
  855. }
  856. function removeColumnGlobalMatrix(which_variable) {
  857. if (programa.globais[which_variable].colunas == 0) {
  858. return;
  859. }
  860. programa.globais[which_variable].colunas --;
  861. for (i = 0; i < programa.globais[which_variable].linhas; i++) {
  862. programa.globais[which_variable].valor[i].splice(programa.globais[which_variable].valor[i].length - 1, 1);
  863. }
  864. renderAlgorithm();
  865. }
  866. function removeLineGlobalMatrix(which_variable) {
  867. if (programa.globais[which_variable].linhas == 0) {
  868. return;
  869. }
  870. programa.globais[which_variable].linhas --;
  871. programa.globais[which_variable].valor.splice(programa.globais[which_variable].valor.length - 1, 1);
  872. renderAlgorithm();
  873. }
  874. function removeLineMatrix(which_function, which_variable) {
  875. if (programa.funcoes[which_function].variaveis[which_variable].linhas == 0) {
  876. return;
  877. }
  878. programa.funcoes[which_function].variaveis[which_variable].linhas --;
  879. programa.funcoes[which_function].variaveis[which_variable].valor.splice(programa.funcoes[which_function].variaveis[which_variable].valor.length - 1, 1);
  880. renderAlgorithm();
  881. }
  882. function addVariable(sequence) {//tipo, nome, valor
  883. var v = new Variavel(tiposDados.integer, i18n('new_variable') + '_' + counter_new_variables, 1);
  884. adicionarVariavel(sequence, v);
  885. counter_new_variables ++;
  886. renderAlgorithm();
  887. }
  888. function deleteVariable(which_function, which_variable) {
  889. programa.funcoes[which_function].variaveis.splice(which_variable, 1);
  890. renderAlgorithm();
  891. }
  892. function addParameter(sequence) {
  893. if (programa.funcoes[sequence].lista_parametros == null) {
  894. programa.funcoes[sequence].lista_parametros = new Array();
  895. }
  896. programa.funcoes[sequence].lista_parametros.push(new Variavel(tiposDados.integer, i18n("new_parameter") + "_" + counter_new_parameters));
  897. counter_new_parameters ++;
  898. renderAlgorithm();
  899. }
  900. function updateFunctionReturn(sequence, new_value) {
  901. if (new_value.indexOf(i18n(tiposDados.vector)) > -1) {
  902. programa.funcoes[sequence].dimensoes_retorno = 1;
  903. } else {
  904. programa.funcoes[sequence].dimensoes_retorno = 0;
  905. }
  906. }
  907. function updateParameterType(wich_function, wich_parameter, new_value, new_dimensions) {
  908. programa.funcoes[wich_function].lista_parametros[wich_parameter].tipo = new_value;
  909. programa.funcoes[wich_function].lista_parametros[wich_parameter].dimensoes = new_dimensions;
  910. }
  911. var opened_name_global = false;
  912. var opened_input_global = null;
  913. var sequence_name_opened_global;
  914. function enableNameGlobalUpdate(div_el, sequence) {
  915. if (opened_name_global) {
  916. $(opened_input_global).focus();
  917. return;
  918. }
  919. opened_name_global = true;
  920. sequence_name_opened_global = sequence;
  921. $(div_el).find('.span_name_variable').text('');
  922. $( "<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'));
  923. $('.width-dynamic').on('input', function() {
  924. var inputWidth = $(this).textWidth()+10;
  925. opened_input_global = this;
  926. $(this).focus();
  927. var tmpStr = $(this).val();
  928. $(this).val('');
  929. $(this).val(tmpStr);
  930. $(this).css({
  931. width: inputWidth
  932. })
  933. }).trigger('input');
  934. $('.width-dynamic').focusout(function() {
  935. /// update array:
  936. if ($(this).val().trim()) {
  937. programa.globais[sequence].nome = $(this).val().trim();
  938. }
  939. $(this).remove();
  940. /// update elements:
  941. opened_name_global = false;
  942. opened_input_global = false;
  943. renderAlgorithm();
  944. });
  945. $('.width-dynamic').on('keydown', function(e) {
  946. var code = e.keyCode || e.which;
  947. if(code == 13) {
  948. if ($(this).val().trim()) {
  949. programa.globais[sequence].nome = $(this).val().trim();
  950. }
  951. $(this).remove();
  952. /// update elements:
  953. opened_name_global = false;
  954. opened_input_global = false;
  955. renderAlgorithm();
  956. }
  957. if(code == 27) {
  958. $(div_el).find('.span_name_function').text(programa.globais[sequence].nome);
  959. $(this).remove();
  960. /// update elements:
  961. opened_name_global = false;
  962. opened_input_global = false;
  963. }
  964. });
  965. }
  966. var opened_name_function = false;
  967. var opened_input = null;
  968. var sequence_name_opened;
  969. function enableNameFunctionUpdate(div_el, sequence) {
  970. if (opened_name_function) {
  971. $(opened_input).focus();
  972. return;
  973. }
  974. opened_name_function = true;
  975. sequence_name_opened = sequence;
  976. $(div_el).find('.span_name_function').text('');
  977. $( "<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'));
  978. $('.width-dynamic').on('input', function() {
  979. var inputWidth = $(this).textWidth()+10;
  980. opened_input = this;
  981. $(this).focus();
  982. var tmpStr = $(this).val();
  983. $(this).val('');
  984. $(this).val(tmpStr);
  985. $(this).css({
  986. width: inputWidth
  987. })
  988. }).trigger('input');
  989. $('.width-dynamic').focusout(function() {
  990. /// update array:
  991. if ($(this).val().trim()) {
  992. programa.funcoes[sequence_name_opened].nome = $(this).val().trim();
  993. }
  994. $(this).remove();
  995. /// update elements:
  996. opened_name_function = false;
  997. opened_input = false;
  998. renderAlgorithm();
  999. });
  1000. $('.width-dynamic').on('keydown', function(e) {
  1001. var code = e.keyCode || e.which;
  1002. if(code == 13) {
  1003. if ($(this).val().trim()) {
  1004. programa.funcoes[sequence_name_opened].nome = $(this).val().trim();
  1005. }
  1006. $(this).remove();
  1007. /// update elements:
  1008. opened_name_function = false;
  1009. opened_input = false;
  1010. renderAlgorithm();
  1011. }
  1012. if(code == 27) {
  1013. $(div_el).find('.span_name_function').text(programa.funcoes[sequence_name_opened].nome);
  1014. $(this).remove();
  1015. /// update elements:
  1016. opened_name_function = false;
  1017. opened_input = false;
  1018. }
  1019. });
  1020. }
  1021. function alternateBooleanVarVectorValue(parent_node, which_function, which_var, column_index) {
  1022. programa.funcoes[which_function].variaveis[which_var].valor[column_index] = !programa.funcoes[which_function].variaveis[which_var].valor[column_index];
  1023. renderAlgorithm();
  1024. }
  1025. function alternateBooleanGlobalVectorValue(parent_node, which_var, column_index) {
  1026. programa.globais[which_var].valor[column_index] = !programa.globais[which_var].valor[column_index];
  1027. renderAlgorithm();
  1028. }
  1029. function alternateBooleanVarMatrixValue(parent_node, which_function, which_var, row_index, column_index) {
  1030. programa.funcoes[which_function].variaveis[which_var].valor[row_index][column_index] = !programa.funcoes[which_function].variaveis[which_var].valor[row_index][column_index];
  1031. renderAlgorithm();
  1032. }
  1033. function alternateBooleanGlobalMatrixValue(parent_node, which_var, row_index, column_index) {
  1034. programa.globais[which_var].valor[row_index][column_index] = !programa.globais[which_var].valor[row_index][column_index];
  1035. renderAlgorithm();
  1036. }
  1037. function alternateBooleanGlobalValue(parent_node, which_var) {
  1038. programa.globais[which_var].valor = !programa.globais[which_var].valor;
  1039. renderAlgorithm();
  1040. }
  1041. function alternateBooleanVarValue(parent_node, which_function, which_var) {
  1042. programa.funcoes[which_function].variaveis[which_var].valor = !programa.funcoes[which_function].variaveis[which_var].valor;
  1043. renderAlgorithm();
  1044. }
  1045. var opened_name_value_vector_global_ = false;
  1046. var opened_input_value_vector_global_ = null;
  1047. var sequence_name_opened_value_vector_global_;
  1048. function enableGlobalVectorValueUpdate(parent_node, which_parameter, column_index) {
  1049. if (opened_name_value_vector_global_) {
  1050. $(opened_input_value_vector_global_).focus();
  1051. return;
  1052. }
  1053. opened_name_value_vector_global_ = true;
  1054. sequence_name_opened_value_vector_global_ = which_parameter;
  1055. $(parent_node).find('.span_value_variable').text('');
  1056. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1057. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1058. + programa.globais[which_parameter].valor[column_index].toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1059. } else {
  1060. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1061. + programa.globais[which_parameter].valor[column_index] + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1062. }
  1063. $('.width-dynamic').on('input', function() {
  1064. var inputWidth = $(this).textWidth()+10;
  1065. opened_input_value_vector_global_ = this;
  1066. $(this).focus();
  1067. var tmpStr = $(this).val();
  1068. $(this).val('');
  1069. $(this).val(tmpStr);
  1070. $(this).css({
  1071. width: inputWidth
  1072. })
  1073. }).trigger('input');
  1074. $('.width-dynamic').focusout(function() {
  1075. /// update array:
  1076. if ($(this).val().trim()) {
  1077. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1078. programa.globais[which_parameter].valor[column_index] = parseFloat($(this).val().trim());
  1079. } else {
  1080. if (programa.globais[which_parameter].tipo == tiposDados.integer) {
  1081. programa.globais[which_parameter].valor[column_index] = parseInt($(this).val().trim());
  1082. } else {
  1083. programa.globais[which_parameter].valor[column_index] = $(this).val().trim();
  1084. }
  1085. }
  1086. }
  1087. $(this).remove();
  1088. /// update elements:
  1089. opened_name_value_vector_global_ = false;
  1090. opened_input_value_vector_global_ = false;
  1091. renderAlgorithm();
  1092. });
  1093. $('.width-dynamic').on('keydown', function(e) {
  1094. var code = e.keyCode || e.which;
  1095. if(code == 13) {
  1096. if ($(this).val().trim()) {
  1097. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1098. programa.globais[which_parameter].valor[column_index] = parseFloat($(this).val().trim());
  1099. } else {
  1100. if (programa.globais[which_parameter].tipo == tiposDados.integer) {
  1101. programa.globais[which_parameter].valor[column_index] = parseInt($(this).val().trim());
  1102. } else {
  1103. programa.globais[which_parameter].valor[column_index] = $(this).val().trim();
  1104. }
  1105. }
  1106. }
  1107. $(this).remove();
  1108. /// update elements:
  1109. opened_name_value_vector_global_ = false;
  1110. opened_input_value_vector_global_ = false;
  1111. renderAlgorithm();
  1112. }
  1113. if(code == 27) {
  1114. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1115. $(parent_node).find('.span_value_variable').text(programa.globais[which_parameter].valor[column_index].toFixed(1));
  1116. } else {
  1117. $(parent_node).find('.span_value_variable').text(programa.globais[which_parameter].valor[column_index]);
  1118. }
  1119. $(this).remove();
  1120. /// update elements:
  1121. opened_name_value_vector_global_ = false;
  1122. opened_input_value_vector_global_ = false;
  1123. }
  1124. });
  1125. }
  1126. var opened_name_value_vector_variable = false;
  1127. var opened_input_value_vector_variable = null;
  1128. var sequence_name_opened_value_vector_variable;
  1129. var sequence_function_opened_value_vector_variable;
  1130. function enableVarVectorValueUpdate(parent_node, which_function, which_parameter, column_index) {
  1131. if (opened_name_value_vector_variable) {
  1132. $(opened_input_value_vector_variable).focus();
  1133. return;
  1134. }
  1135. opened_name_value_vector_variable = true;
  1136. sequence_name_opened_value_vector_variable = which_parameter;
  1137. sequence_function_opened_value_vector_variable = which_function;
  1138. $(parent_node).find('.span_value_variable').text('');
  1139. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1140. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1141. + programa.funcoes[which_function].variaveis[which_parameter].valor[column_index].toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1142. } else {
  1143. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1144. + programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1145. }
  1146. $('.width-dynamic').on('input', function() {
  1147. var inputWidth = $(this).textWidth()+10;
  1148. opened_input_value_vector_variable = this;
  1149. $(this).focus();
  1150. var tmpStr = $(this).val();
  1151. $(this).val('');
  1152. $(this).val(tmpStr);
  1153. $(this).css({
  1154. width: inputWidth
  1155. })
  1156. }).trigger('input');
  1157. $('.width-dynamic').focusout(function() {
  1158. /// update array:
  1159. if ($(this).val().trim()) {
  1160. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1161. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseFloat($(this).val().trim());
  1162. } else {
  1163. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  1164. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseInt($(this).val().trim());
  1165. } else {
  1166. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = $(this).val().trim();
  1167. }
  1168. }
  1169. }
  1170. $(this).remove();
  1171. /// update elements:
  1172. opened_name_value_vector_variable = false;
  1173. opened_input_value_vector_variable = false;
  1174. renderAlgorithm();
  1175. });
  1176. $('.width-dynamic').on('keydown', function(e) {
  1177. var code = e.keyCode || e.which;
  1178. if(code == 13) {
  1179. if ($(this).val().trim()) {
  1180. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1181. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseFloat($(this).val().trim());
  1182. } else {
  1183. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  1184. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseInt($(this).val().trim());
  1185. } else {
  1186. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = $(this).val().trim();
  1187. }
  1188. }
  1189. }
  1190. $(this).remove();
  1191. /// update elements:
  1192. opened_name_value_vector_variable = false;
  1193. opened_input_value_vector_variable = false;
  1194. renderAlgorithm();
  1195. }
  1196. if(code == 27) {
  1197. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1198. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[column_index].toFixed(1));
  1199. } else {
  1200. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[column_index]);
  1201. }
  1202. $(this).remove();
  1203. /// update elements:
  1204. opened_name_value_vector_variable = false;
  1205. opened_input_value_vector_variable = false;
  1206. }
  1207. });
  1208. }
  1209. var opened_name_value_matrix_global_v = false;
  1210. var opened_input_value_matrix_global_v = null;
  1211. var sequence_name_opened_value_matrix_global_v;
  1212. function enableGlobalMatrixValueUpdate(parent_node, which_parameter, row_index, column_index) {
  1213. if (opened_name_value_matrix_global_v) {
  1214. $(opened_input_value_matrix_global_v).focus();
  1215. return;
  1216. }
  1217. opened_name_value_matrix_global_v = true;
  1218. sequence_name_opened_value_matrix_global_v = which_parameter;
  1219. $(parent_node).find('.span_value_variable').text('');
  1220. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1221. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1222. + programa.globais[which_parameter].valor[row_index][column_index].toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1223. } else {
  1224. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1225. + programa.globais[which_parameter].valor[row_index][column_index] + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1226. }
  1227. $('.width-dynamic').on('input', function() {
  1228. var inputWidth = $(this).textWidth()+10;
  1229. opened_input_value_matrix_global_v = this;
  1230. $(this).focus();
  1231. var tmpStr = $(this).val();
  1232. $(this).val('');
  1233. $(this).val(tmpStr);
  1234. $(this).css({
  1235. width: inputWidth
  1236. })
  1237. }).trigger('input');
  1238. $('.width-dynamic').focusout(function() {
  1239. /// update array:
  1240. if ($(this).val().trim()) {
  1241. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1242. programa.globais[which_parameter].valor[row_index][column_index] = parseFloat($(this).val().trim());
  1243. } else {
  1244. if (programa.globais[which_parameter].tipo == tiposDados.integer) {
  1245. programa.globais[which_parameter].valor[row_index][column_index] = parseInt($(this).val().trim());
  1246. } else {
  1247. programa.globais[which_parameter].valor[row_index][column_index] = $(this).val().trim();
  1248. }
  1249. }
  1250. }
  1251. $(this).remove();
  1252. /// update elements:
  1253. opened_name_value_matrix_global_v = false;
  1254. opened_input_value_matrix_global_v = false;
  1255. renderAlgorithm();
  1256. });
  1257. $('.width-dynamic').on('keydown', function(e) {
  1258. var code = e.keyCode || e.which;
  1259. if(code == 13) {
  1260. if ($(this).val().trim()) {
  1261. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1262. programa.globais[which_parameter].valor[row_index][column_index] = parseFloat($(this).val().trim());
  1263. } else {
  1264. if (programa.globais[which_parameter].tipo == tiposDados.integer) {
  1265. programa.globais[which_parameter].valor[row_index][column_index] = parseInt($(this).val().trim());
  1266. } else {
  1267. programa.globais[which_parameter].valor[row_index][column_index] = $(this).val().trim();
  1268. }
  1269. }
  1270. }
  1271. $(this).remove();
  1272. /// update elements:
  1273. opened_name_value_matrix_global_v = false;
  1274. opened_input_value_matrix_global_v = false;
  1275. renderAlgorithm();
  1276. }
  1277. if(code == 27) {
  1278. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1279. $(parent_node).find('.span_value_variable').text(programa.globais[which_parameter].valor[row_index][column_index].toFixed(1));
  1280. } else {
  1281. $(parent_node).find('.span_value_variable').text(programa.globais[which_parameter].valor[row_index][column_index]);
  1282. }
  1283. $(this).remove();
  1284. /// update elements:
  1285. opened_name_value_matrix_global_v = false;
  1286. opened_input_value_matrix_global_v = false;
  1287. }
  1288. });
  1289. }
  1290. var opened_name_value_matrix_variable = false;
  1291. var opened_input_value_matrix_variable = null;
  1292. var sequence_name_opened_value_matrix_variable;
  1293. var sequence_function_opened_value_matrix_variable;
  1294. function enableVarMatrixValueUpdate(parent_node, which_function, which_parameter, row_index, column_index) {
  1295. if (opened_name_value_matrix_variable) {
  1296. $(opened_input_value_matrix_variable).focus();
  1297. return;
  1298. }
  1299. opened_name_value_matrix_variable = true;
  1300. sequence_name_opened_value_matrix_variable = which_parameter;
  1301. sequence_function_opened_value_matrix_variable = which_function;
  1302. $(parent_node).find('.span_value_variable').text('');
  1303. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1304. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1305. + programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index].toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1306. } else {
  1307. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1308. + programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1309. }
  1310. $('.width-dynamic').on('input', function() {
  1311. var inputWidth = $(this).textWidth()+10;
  1312. opened_input_value_matrix_variable = this;
  1313. $(this).focus();
  1314. var tmpStr = $(this).val();
  1315. $(this).val('');
  1316. $(this).val(tmpStr);
  1317. $(this).css({
  1318. width: inputWidth
  1319. })
  1320. }).trigger('input');
  1321. $('.width-dynamic').focusout(function() {
  1322. /// update array:
  1323. if ($(this).val().trim()) {
  1324. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1325. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseFloat($(this).val().trim());
  1326. } else {
  1327. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  1328. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseInt($(this).val().trim());
  1329. } else {
  1330. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = $(this).val().trim();
  1331. }
  1332. }
  1333. }
  1334. $(this).remove();
  1335. /// update elements:
  1336. opened_name_value_matrix_variable = false;
  1337. opened_input_value_matrix_variable = false;
  1338. renderAlgorithm();
  1339. });
  1340. $('.width-dynamic').on('keydown', function(e) {
  1341. var code = e.keyCode || e.which;
  1342. if(code == 13) {
  1343. if ($(this).val().trim()) {
  1344. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1345. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseFloat($(this).val().trim());
  1346. } else {
  1347. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  1348. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseInt($(this).val().trim());
  1349. } else {
  1350. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = $(this).val().trim();
  1351. }
  1352. }
  1353. }
  1354. $(this).remove();
  1355. /// update elements:
  1356. opened_name_value_matrix_variable = false;
  1357. opened_input_value_matrix_variable = false;
  1358. renderAlgorithm();
  1359. }
  1360. if(code == 27) {
  1361. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1362. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index].toFixed(1));
  1363. } else {
  1364. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index]);
  1365. }
  1366. $(this).remove();
  1367. /// update elements:
  1368. opened_name_value_matrix_variable = false;
  1369. opened_input_value_matrix_variable = false;
  1370. }
  1371. });
  1372. }
  1373. var opened_name_value_global_var = false;
  1374. var opened_input_value_global_ar = null;
  1375. var sequence_name_opened_value_global_var;
  1376. function enableGlobalValueUpdate(parent_node, which_parameter) {
  1377. if (opened_name_value_global_var) {
  1378. $(opened_input_value_global_ar).focus();
  1379. return;
  1380. }
  1381. opened_name_value_global_var = true;
  1382. sequence_name_opened_value_global_var = which_parameter;
  1383. $(parent_node).find('.span_value_variable').text('');
  1384. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1385. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1386. + programa.globais[which_parameter].valor.toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1387. } else {
  1388. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1389. + programa.globais[which_parameter].valor + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1390. }
  1391. $('.width-dynamic').on('input', function() {
  1392. var inputWidth = $(this).textWidth()+10;
  1393. opened_input_value_global_ar = this;
  1394. $(this).focus();
  1395. var tmpStr = $(this).val();
  1396. $(this).val('');
  1397. $(this).val(tmpStr);
  1398. $(this).css({
  1399. width: inputWidth
  1400. })
  1401. }).trigger('input');
  1402. $('.width-dynamic').focusout(function() {
  1403. /// update array:
  1404. if ($(this).val().trim()) {
  1405. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1406. programa.globais[which_parameter].valor = parseFloat($(this).val().trim());
  1407. } else{
  1408. if (programa.globais[which_parameter].tipo == tiposDados.integer) {
  1409. programa.globais[which_parameter].valor = parseInt($(this).val().trim());
  1410. } else {
  1411. programa.globais[which_parameter].valor = $(this).val().trim();
  1412. }
  1413. }
  1414. }
  1415. $(this).remove();
  1416. /// update elements:
  1417. opened_name_value_global_var = false;
  1418. opened_input_value_global_ar = false;
  1419. renderAlgorithm();
  1420. });
  1421. $('.width-dynamic').on('keydown', function(e) {
  1422. var code = e.keyCode || e.which;
  1423. if(code == 13) {
  1424. if ($(this).val().trim()) {
  1425. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1426. programa.globais[which_parameter].valor = parseFloat($(this).val().trim());
  1427. } else{
  1428. if (programa.globais[which_parameter].tipo == tiposDados.integer) {
  1429. programa.globais[which_parameter].valor = parseInt($(this).val().trim());
  1430. } else {
  1431. programa.globais[which_parameter].valor = $(this).val().trim();
  1432. }
  1433. }
  1434. }
  1435. $(this).remove();
  1436. /// update elements:
  1437. opened_name_value_global_var = false;
  1438. opened_input_value_global_ar = false;
  1439. renderAlgorithm();
  1440. }
  1441. if(code == 27) {
  1442. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1443. $(parent_node).find('.span_value_variable').text(programa.globais[which_parameter].valor.toFixed(1));
  1444. } else{
  1445. $(parent_node).find('.span_value_variable').text(programa.globais[which_parameter].valor);
  1446. }
  1447. $(this).remove();
  1448. /// update elements:
  1449. opened_name_value_global_var = false;
  1450. opened_input_value_global_ar = false;
  1451. }
  1452. });
  1453. }
  1454. var opened_name_value_variable = false;
  1455. var opened_input_value_variable = null;
  1456. var sequence_name_opened_value_variable;
  1457. var sequence_function_opened_value_variable;
  1458. function enableVarValueUpdate(parent_node, which_function, which_parameter) {
  1459. if (opened_name_value_variable) {
  1460. $(opened_input_value_variable).focus();
  1461. return;
  1462. }
  1463. opened_name_value_variable = true;
  1464. sequence_name_opened_value_variable = which_parameter;
  1465. sequence_function_opened_value_variable = which_function;
  1466. $(parent_node).find('.span_value_variable').text('');
  1467. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1468. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1469. + programa.funcoes[which_function].variaveis[which_parameter].valor.toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1470. } else {
  1471. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1472. + programa.funcoes[which_function].variaveis[which_parameter].valor + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1473. }
  1474. $('.width-dynamic').on('input', function() {
  1475. var inputWidth = $(this).textWidth()+10;
  1476. opened_input_value_variable = this;
  1477. $(this).focus();
  1478. var tmpStr = $(this).val();
  1479. $(this).val('');
  1480. $(this).val(tmpStr);
  1481. $(this).css({
  1482. width: inputWidth
  1483. })
  1484. }).trigger('input');
  1485. $('.width-dynamic').focusout(function() {
  1486. /// update array:
  1487. if ($(this).val().trim()) {
  1488. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1489. programa.funcoes[which_function].variaveis[which_parameter].valor = parseFloat($(this).val().trim());
  1490. } else{
  1491. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  1492. programa.funcoes[which_function].variaveis[which_parameter].valor = parseInt($(this).val().trim());
  1493. } else {
  1494. programa.funcoes[which_function].variaveis[which_parameter].valor = $(this).val().trim();
  1495. }
  1496. }
  1497. }
  1498. $(this).remove();
  1499. /// update elements:
  1500. opened_name_value_variable = false;
  1501. opened_input_value_variable = false;
  1502. renderAlgorithm();
  1503. });
  1504. $('.width-dynamic').on('keydown', function(e) {
  1505. var code = e.keyCode || e.which;
  1506. if(code == 13) {
  1507. if ($(this).val().trim()) {
  1508. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1509. programa.funcoes[which_function].variaveis[which_parameter].valor = parseFloat($(this).val().trim());
  1510. } else{
  1511. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  1512. programa.funcoes[which_function].variaveis[which_parameter].valor = parseInt($(this).val().trim());
  1513. } else {
  1514. programa.funcoes[which_function].variaveis[which_parameter].valor = $(this).val().trim();
  1515. }
  1516. }
  1517. }
  1518. $(this).remove();
  1519. /// update elements:
  1520. opened_name_value_variable = false;
  1521. opened_input_value_variable = false;
  1522. renderAlgorithm();
  1523. }
  1524. if(code == 27) {
  1525. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1526. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor.toFixed(1));
  1527. } else{
  1528. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor);
  1529. }
  1530. $(this).remove();
  1531. /// update elements:
  1532. opened_name_value_variable = false;
  1533. opened_input_value_variable = false;
  1534. }
  1535. });
  1536. }
  1537. var opened_name_variable = false;
  1538. var opened_input_variable = null;
  1539. var sequence_name_opened_variable;
  1540. var sequence_function_opened_variable;
  1541. function enableNameVariableUpdate(parent_node, which_function, which_parameter) {
  1542. if (opened_name_variable) {
  1543. $(opened_input_variable).focus();
  1544. return;
  1545. }
  1546. opened_name_variable = true;
  1547. sequence_name_opened_variable = which_parameter;
  1548. sequence_function_opened_variable = which_function;
  1549. $(parent_node).find('.span_name_variable').text('');
  1550. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1551. + programa.funcoes[which_function].variaveis[which_parameter].nome + "' />" ).insertBefore($(parent_node).find('.span_name_variable'));
  1552. $('.width-dynamic').on('input', function() {
  1553. var inputWidth = $(this).textWidth()+10;
  1554. opened_input_variable = this;
  1555. $(this).focus();
  1556. var tmpStr = $(this).val();
  1557. $(this).val('');
  1558. $(this).val(tmpStr);
  1559. $(this).css({
  1560. width: inputWidth
  1561. })
  1562. }).trigger('input');
  1563. $('.width-dynamic').focusout(function() {
  1564. /// update array:
  1565. if ($(this).val().trim()) {
  1566. programa.funcoes[which_function].variaveis[which_parameter].nome = $(this).val().trim();
  1567. }
  1568. $(this).remove();
  1569. /// update elements:
  1570. opened_name_variable = false;
  1571. opened_input_variable = false;
  1572. renderAlgorithm();
  1573. });
  1574. $('.width-dynamic').on('keydown', function(e) {
  1575. var code = e.keyCode || e.which;
  1576. if(code == 13) {
  1577. if ($(this).val().trim()) {
  1578. programa.funcoes[which_function].variaveis[which_parameter].nome = $(this).val().trim();
  1579. }
  1580. $(this).remove();
  1581. /// update elements:
  1582. opened_name_variable = false;
  1583. opened_input_variable = false;
  1584. renderAlgorithm();
  1585. }
  1586. if(code == 27) {
  1587. $(parent_node).find('.span_name_variable').text(programa.funcoes[which_function].variaveis[which_parameter].nome);
  1588. $(this).remove();
  1589. /// update elements:
  1590. opened_name_variable = false;
  1591. opened_input_variable = false;
  1592. }
  1593. });
  1594. }
  1595. var opened_name_comment = false;
  1596. var opened_input_comment = null;
  1597. var sequence_name_opened_comment;
  1598. var sequence_function_opened_comment;
  1599. function enableCommentUpdate(parent_node, function_index, is_function_comment, comment_index) {
  1600. if (opened_name_comment) {
  1601. $(opened_input_comment).focus();
  1602. return;
  1603. }
  1604. opened_name_comment = true;
  1605. sequence_name_opened_comment = comment_index;
  1606. sequence_function_opened_comment = function_index;
  1607. $(parent_node).find('.span_comment_text').text('');
  1608. var temp_value = "";
  1609. if (is_function_comment) {
  1610. temp_value = programa.funcoes[function_index].comentario_funcao.texto_comentario;
  1611. } else {
  1612. temp_value = programa.funcoes[function_index].comandos[comment_index].texto_comentario;
  1613. }
  1614. $( "<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'));
  1615. $('.width-dynamic').on('input', function() {
  1616. var inputWidth = $(this).textWidth()+10;
  1617. opened_input_comment = this;
  1618. $(this).focus();
  1619. var tmpStr = $(this).val();
  1620. $(this).val('');
  1621. $(this).val(tmpStr);
  1622. $(this).css({
  1623. width: inputWidth
  1624. })
  1625. }).trigger('input');
  1626. $('.width-dynamic').focusout(function() {
  1627. /// update array:
  1628. if ($(this).val().trim()) {
  1629. var n_value = $(this).val().trim();
  1630. if (is_function_comment) {
  1631. programa.funcoes[function_index].comentario_funcao.texto_comentario = n_value;
  1632. } else {
  1633. temp_value = programa.funcoes[function_index].comandos[comment_index].texto_comentario = n_value;
  1634. }
  1635. }
  1636. $(this).remove();
  1637. /// update elements:
  1638. opened_name_comment = false;
  1639. opened_input_comment = false;
  1640. renderAlgorithm();
  1641. });
  1642. $('.width-dynamic').on('keydown', function(e) {
  1643. var code = e.keyCode || e.which;
  1644. if(code == 13) {
  1645. if ($(this).val().trim()) {
  1646. var n_value = $(this).val().trim();
  1647. if (is_function_comment) {
  1648. programa.funcoes[function_index].comentario_funcao.texto_comentario = n_value;
  1649. } else {
  1650. temp_value = programa.funcoes[function_index].comandos[comment_index].texto_comentario = n_value;
  1651. }
  1652. }
  1653. $(this).remove();
  1654. /// update elements:
  1655. opened_name_comment = false;
  1656. opened_input_comment = false;
  1657. renderAlgorithm();
  1658. }
  1659. if(code == 27) {
  1660. $(parent_node).find('.span_comment_text').text(temp_value);
  1661. $(this).remove();
  1662. /// update elements:
  1663. opened_name_comment = false;
  1664. opened_input_comment = false;
  1665. }
  1666. });
  1667. }
  1668. var opened_name_parameter = false;
  1669. var opened_input_parameter = null;
  1670. var sequence_name_opened_parameter;
  1671. var sequence_function_opened_parameter;
  1672. function enableNameParameterUpdate(parent_node, which_function, which_parameter) {
  1673. if (opened_name_parameter) {
  1674. $(opened_input_parameter).focus();
  1675. return;
  1676. }
  1677. opened_name_parameter = true;
  1678. sequence_name_opened_parameter = which_parameter;
  1679. sequence_function_opened_parameter = which_function;
  1680. $(parent_node).find('.span_name_parameter').text('');
  1681. $( "<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'));
  1682. $('.width-dynamic').on('input', function() {
  1683. var inputWidth = $(this).textWidth()+10;
  1684. opened_input_parameter = this;
  1685. $(this).focus();
  1686. var tmpStr = $(this).val();
  1687. $(this).val('');
  1688. $(this).val(tmpStr);
  1689. $(this).css({
  1690. width: inputWidth
  1691. })
  1692. }).trigger('input');
  1693. $('.width-dynamic').focusout(function() {
  1694. /// update array:
  1695. if ($(this).val().trim()) {
  1696. programa.funcoes[which_function].lista_parametros[which_parameter].nome = $(this).val().trim();
  1697. }
  1698. $(this).remove();
  1699. /// update elements:
  1700. opened_name_parameter = false;
  1701. opened_input_parameter = false;
  1702. renderAlgorithm();
  1703. });
  1704. $('.width-dynamic').on('keydown', function(e) {
  1705. var code = e.keyCode || e.which;
  1706. if(code == 13) {
  1707. if ($(this).val().trim()) {
  1708. programa.funcoes[which_function].lista_parametros[which_parameter].nome = $(this).val().trim();
  1709. }
  1710. $(this).remove();
  1711. /// update elements:
  1712. opened_name_parameter = false;
  1713. opened_input_parameter = false;
  1714. renderAlgorithm();
  1715. }
  1716. if(code == 27) {
  1717. $(parent_node).find('.span_name_parameter').text(programa.funcoes[which_function].lista_parametros[which_parameter].nome);
  1718. $(this).remove();
  1719. /// update elements:
  1720. opened_name_parameter = false;
  1721. opened_input_parameter = false;
  1722. }
  1723. });
  1724. }
  1725. function removeParameter(parent_node, which_function, which_parameter) {
  1726. programa.funcoes[which_function].lista_parametros.splice(which_parameter, 1);
  1727. renderAlgorithm();
  1728. }
  1729. function appendFunction(function_obj, sequence) {
  1730. var appender = '<div class="ui secondary segment function_div list-group-item" data-fun="'+sequence+'">';
  1731. if (function_obj.comentario_funcao) {
  1732. appender += renderComment(function_obj.comentario_funcao, sequence, true, -1);
  1733. }
  1734. appender += '<span class="glyphicon glyphicon-move move_function" aria-hidden="true"><i class="icon sort alternate vertical"></i></span>';
  1735. 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>')
  1736. + '<button class="ui icon button tiny minimize_function_button" onclick="minimizeFunctionHandler(this.parentNode, '+sequence+')"><i class="icon window minimize"></i></button>';
  1737. appender += '<div class="ui icon buttons add_var_top_button"><div class="ui icon button" onclick="addVariable('+sequence+')"><i class="icon superscript"></i></div>';
  1738. appender += '<div class="ui icon button dropdown" ><i class="icon code"></i> <div class="menu"> ';
  1739. appender += '<a class="item create_reader" data-text="'+tiposComandos.reader+'" data-fun="'+sequence+'"><i class="download icon"></i> ' +i18n('text_read_var')+ '</a>'
  1740. + '<a class="item create_writer" data-text="'+tiposComandos.writer+'" data-fun="'+sequence+'"><i class="upload icon"></i> '+i18n('text_write_var')+'</a>'
  1741. + '<a class="item create_comment" data-text="'+tiposComandos.comment+'" data-fun="'+sequence+'"><i class="quote left icon"></i> '+i18n('text_comment')+'</a>'
  1742. + '<a class="item create_attribution" data-text="'+tiposComandos.comment+'" data-fun="'+sequence+'"><i class="arrow left icon"></i> '+i18n('text_attribution')+'</a>'
  1743. + '<a class="item create_iftrue" data-text="'+tiposComandos.iftrue+'" data-fun="'+sequence+'"><i class="random icon"></i> '+i18n('text_iftrue')+'</a>'
  1744. + '<a class="item create_repeatNtimes" data-text="'+tiposComandos.repeatNtimes+'" data-fun="'+sequence+'"><i class="sync icon"></i> '+i18n('text_repeatNtimes')+'</a>'
  1745. + '<a class="item create_whiletrue" data-text="'+tiposComandos.whiletrue+'" data-fun="'+sequence+'"><i class="sync icon"></i> '+i18n('text_whiletrue')+'</a>'
  1746. + '<a class="item create_dowhiletrue" data-text="'+tiposComandos.dowhiletrue+'" data-fun="'+sequence+'"><i class="sync icon"></i> '+i18n('text_dowhiletrue')+'</a>'
  1747. + '<a class="item create_switch" data-text="'+tiposComandos.switch+'" data-fun="'+sequence+'"><i class="list icon"></i> '+i18n('text_switch')+'</a>'
  1748. + '<a class="item create_functioncall" data-text="'+tiposComandos.functioncall+'" data-fun="'+sequence+'"><i class="hand point right icon"></i> '+i18n('text_functioncall')+'</a>'
  1749. + '</div></div></div>';
  1750. appender += '<div class="function_signature_div">'+i18n('function')+' ';
  1751. if (function_obj.eh_principal) {
  1752. 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> '
  1753. + '( <div class="ui large labels parameters_list">';
  1754. } else {
  1755. appender += renderFunctionReturn(function_obj, sequence);
  1756. 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> '
  1757. + '( <i class="ui icon plus square outline add_parameter" onclick="addParameter('+sequence+')"></i> <div class="ui large labels parameters_list">';
  1758. }
  1759. appender += renderFunctionParameters(function_obj, sequence);
  1760. appender += '</div> ) {</div>'
  1761. + (function_obj.esta_oculta ? ' <div class="function_area" style="display: none;"> ' : ' <div class="function_area"> ')
  1762. + '<div class="ui top attached segment variables_list_div">'
  1763. + renderVariables(function_obj, sequence)
  1764. + '</div>'
  1765. + '<div class="ui bottom attached segment commands_list_div" id="function_drag_cmd_'+sequence+'" data-fun="'+sequence+'">';
  1766. if (programa.funcoes[sequence].comandos) {
  1767. for (l = 0; l < programa.funcoes[sequence].comandos.length; l++) {
  1768. if (programa.funcoes[sequence].comandos[l].tipo == tiposComandos.comment) {
  1769. appender += renderComment(programa.funcoes[sequence].comandos[l], sequence, false, l, 0);
  1770. }
  1771. if (programa.funcoes[sequence].comandos[l].tipo == tiposComandos.reader) {
  1772. appender += renderReader(programa.funcoes[sequence].comandos[l], sequence, l, 0);
  1773. }
  1774. if (programa.funcoes[sequence].comandos[l].tipo == tiposComandos.writer) {
  1775. appender += renderWriter(programa.funcoes[sequence].comandos[l], sequence, l, 0);
  1776. }
  1777. if (programa.funcoes[sequence].comandos[l].tipo == tiposComandos.attribution) {
  1778. appender += renderAttribution(programa.funcoes[sequence].comandos[l], sequence, l, 0);
  1779. }
  1780. if (programa.funcoes[sequence].comandos[l].tipo == tiposComandos.iftrue) {
  1781. appender += renderIfTrue(programa.funcoes[sequence].comandos[l], sequence, l, 0);
  1782. }
  1783. if (programa.funcoes[sequence].comandos[l].tipo == tiposComandos.repeatNtimes) {
  1784. appender += renderRepeatNtimes(programa.funcoes[sequence].comandos[l], sequence, l, 0);
  1785. }
  1786. if (programa.funcoes[sequence].comandos[l].tipo == tiposComandos.whiletrue) {
  1787. appender += renderWhiletrue(programa.funcoes[sequence].comandos[l], sequence, l, 0);
  1788. }
  1789. if (programa.funcoes[sequence].comandos[l].tipo == tiposComandos.dowhiletrue) {
  1790. appender += renderDowhiletrue(programa.funcoes[sequence].comandos[l], sequence, l, 0);
  1791. }
  1792. if (programa.funcoes[sequence].comandos[l].tipo == tiposComandos.switch) {
  1793. appender += renderSwitch(programa.funcoes[sequence].comandos[l], sequence, l, 0);
  1794. }
  1795. if (programa.funcoes[sequence].comandos[l].tipo == tiposComandos.functioncall) {
  1796. appender += renderFunctioncall(programa.funcoes[sequence].comandos[l], sequence, l, 0);
  1797. }
  1798. }
  1799. }
  1800. appender += '</div>';
  1801. appender += '<div class="function_close_div">}</div>'
  1802. + '</div>'
  1803. + '</div>';
  1804. $('.all_functions').append(appender);
  1805. }
  1806. function renderFunctioncall(functioncall_obj, function_index, functioncall_index, data_parent) {
  1807. var ret = '';
  1808. ret += '<div class="ui functioncall" data-index="'+functioncall_index+'" data-command="'+functioncall_index+'" data-parent="'+data_parent+'"> <i class="hand point right icon command_drag"></i> <span> funcao() </span>';
  1809. ret += '</div>';
  1810. return ret;
  1811. }
  1812. function renderSwitch(switch_obj, function_index, repeat_index, data_parent) {
  1813. var ret = '';
  1814. ret += '<div class="ui switch" data-index="'+repeat_index+'" data-parent="'+data_parent+'"> <i class="ui icon small random command_drag" ></i> <span> escolha (x) { <br> caso 1: <br> caso 2: <br> }</span>';
  1815. ret += '</div>';
  1816. return ret;
  1817. }
  1818. function renderDowhiletrue(dowhiletrue_obj, function_index, repeat_index, data_parent) {
  1819. var ret = '';
  1820. ret += '<div class="ui dowhiletrue" data-index="'+repeat_index+'" data-parent="'+data_parent+'"> <i class="ui icon small random command_drag"></i> <span> faça { <br> } enquanto (x < 10);</span>';
  1821. ret += '</div>';
  1822. return ret;
  1823. }
  1824. function renderWhiletrue(whiletrue_obj, function_index, repeat_index, data_parent) {
  1825. var ret = '';
  1826. ret += '<div class="ui whiletrue" data-index="'+repeat_index+'" data-parent="'+data_parent+'"> <i class="ui icon small random command_drag"></i> <span> enquanto (x < 10) { <br> }</span>';
  1827. ret += '</div>';
  1828. return ret;
  1829. }
  1830. function renderRepeatNtimes(repeat_obj, function_index, repeat_index, data_parent) {
  1831. var ret = '';
  1832. ret += '<div class="ui iftrue" data-index="'+repeat_index+'" data-parent="'+data_parent+'"> <i class="ui icon small random command_drag"></i> <span> para (x = 0; x < 10; x ++) { <br> }</span>';
  1833. ret += '</div>';
  1834. return ret;
  1835. }
  1836. function renderIfTrue(writer_obj, function_index, iftrue_index, data_parent) {
  1837. var ret = '';
  1838. ret += '<div class="ui iftrue" data-index="'+iftrue_index+'" data-parent="'+data_parent+'"> <i class="ui icon small random command_drag"></i> <span> if (x < 1) { <br> } else { <br> }</span>';
  1839. ret += '</div>';
  1840. return ret;
  1841. }
  1842. function renderAttribution(writer_obj, function_index, attr_index, data_parent) {
  1843. var ret = '';
  1844. ret += '<div class="ui attribution" data-index="'+attr_index+'" data-command="'+attr_index+'" data-parent="'+data_parent+'"> <i class="ui icon small arrow left command_drag"></i> <span> x = 1 + 1</span>';
  1845. ret += '</div>';
  1846. return ret;
  1847. }
  1848. function renderWriter(writer_obj, function_index, reader_index, data_parent) {
  1849. var ret = '';
  1850. ret += '<div class="ui writer" data-index="'+reader_index+'" data-command="'+reader_index+'" data-parent="'+data_parent+'"> <i class="ui icon small upload command_drag"></i> <span>'+i18n('write')+' x</span>';
  1851. ret += '</div>';
  1852. return ret;
  1853. }
  1854. function renderReader(reader_obj, function_index, reader_index, data_parent) {
  1855. var ret = '';
  1856. ret += '<div class="ui reader" data-index="'+reader_index+'" data-command="'+reader_index+'" data-parent="'+data_parent+'"> <i class="ui icon small download command_drag"></i> <span>'+i18n('read')+' x</span>';
  1857. ret += '</div>';
  1858. return ret;
  1859. }
  1860. function renderComment(comment_obj, function_index, is_function_comment, comment_index, data_parent) {
  1861. var ret = '';
  1862. ret += '<div class="ui comment" data-index="'+comment_index+'" data-command="'+comment_index+'" data-parent="'+data_parent+'"> <i class="ui icon small quote left '+(is_function_comment?'':'command_drag')+'"></i> <span class="span_comment_text" ondblclick="enableCommentUpdate(this.parentNode, '+function_index+', '
  1863. +is_function_comment+', '+comment_index+')"> ' + comment_obj.texto_comentario + ' </span>';
  1864. ret += '</div>';
  1865. return ret;
  1866. }
  1867. // Essa função imprime os parâmetros e cria os elementos para a sua manipulação
  1868. function renderFunctionParameters(function_obj, sequence) {
  1869. var ret = "";
  1870. if (function_obj.lista_parametros != null) {
  1871. for (var j = 0; j < function_obj.lista_parametros.length; j++) {
  1872. var par_temp = function_obj.lista_parametros[j];
  1873. 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>';
  1874. ret += '<div class="ui dropdown parameter_type seq_'+j+' fun_'+sequence+'">';
  1875. if (par_temp.dimensoes > 0) {
  1876. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+ i18n(tiposDados.vector)+':'+i18n(par_temp.tipo);
  1877. ret += '</div>';
  1878. } else {
  1879. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+i18n(par_temp.tipo)+'</div>';
  1880. }
  1881. ret += '<i class="dropdown icon"></i>'
  1882. + '<div class="menu seq_'+j+' fun_'+sequence+'">';
  1883. var i = 0;
  1884. for (tm in tiposDados) {
  1885. i ++;
  1886. if (i == 1) { continue; }
  1887. if (i == (Object.keys(tiposDados).length)) { break; }
  1888. ret += '<div class="item ' + ((par_temp.tipo == tm && par_temp.dimensoes < 1) ? ' selected ' : '') + ' seq_'+j+' fun_'+sequence+' '+tm+'" >'+i18n(tm)+'</div>';
  1889. }
  1890. i = 0;
  1891. for (tm in tiposDados) {
  1892. i ++;
  1893. if (i == 1) { continue; }
  1894. if (i == (Object.keys(tiposDados).length)) { break; }
  1895. ret += '<div class="item seq_'+j+' '+tm+' fun_'+sequence+' ' + ((par_temp.tipo == tm && par_temp.dimensoes > 0) ? ' selected ' : '') + ' ">'
  1896. + i18n(tiposDados.vector)+':'+i18n(tm)
  1897. + '</div>';
  1898. }
  1899. ret += '</div></div>';
  1900. ret += ' <i class="red icon times remove_parameter" onclick="removeParameter(this.parentNode, '+sequence+', '+j+')"></i></div>';
  1901. }
  1902. }
  1903. return ret;
  1904. }
  1905. // Essa função imprime as variáveis e os recursos para sua manipulação
  1906. function renderVariables(function_obj, sequence) {
  1907. var ret = "";
  1908. if (function_obj.variaveis != null) {
  1909. for (var j = 0; j < function_obj.variaveis.length; j++) {
  1910. var par_temp = function_obj.variaveis[j];
  1911. 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>';
  1912. ret += '<div class="ui dropdown variable_type seq_'+j+' fun_'+sequence+'">';
  1913. if (par_temp.dimensoes > 0) {
  1914. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+ i18n(tiposDados.vector)+':'+i18n(par_temp.tipo);
  1915. for (i = 0; i < par_temp.dimensoes; i ++) {
  1916. ret += ' [ ] ';
  1917. }
  1918. ret += '</div>';
  1919. } else {
  1920. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+i18n(par_temp.tipo)+'</div>';
  1921. }
  1922. ret += '<i class="dropdown icon"></i>'
  1923. + '<div class="menu seq_'+j+' fun_'+sequence+'">';
  1924. var i = 0;
  1925. for (tm in tiposDados) {
  1926. i ++;
  1927. if (i == 1) { continue; }
  1928. if (i == (Object.keys(tiposDados).length)) { break; }
  1929. ret += '<div class="item ' + (par_temp.tipo == tm ? ' selected ' : '') + ' seq_'+j+' fun_'+sequence+' '+tm+'" >'+i18n(tm)+'</div>';
  1930. }
  1931. i = 0;
  1932. for (tm in tiposDados) {
  1933. i ++;
  1934. if (i == 1) { continue; }
  1935. if (i == (Object.keys(tiposDados).length)) { break; }
  1936. ret += '<div class="item seq_'+j+' fun_'+sequence+'">'
  1937. + '<i class="dropdown icon"></i>'
  1938. + i18n(tiposDados.vector)+':'+i18n(tm)
  1939. + '<div class="menu seq_'+j+' fun_'+sequence+'">'
  1940. + '<div class="item seq_'+j+' fun_'+sequence+' '+tm+'" data-text="'+ i18n(tiposDados.vector)+':'+i18n(tm)+' [ ] ">[ ]</div>'
  1941. + '<div class="item seq_'+j+' fun_'+sequence+' '+tm+'" data-text="'+ i18n(tiposDados.vector)+':'+i18n(tm)+' [ ] [ ] ">[ ] [ ] </div>'
  1942. + '</div>'
  1943. + '</div>';
  1944. }
  1945. ret += '</div></div> = ';
  1946. if (par_temp.dimensoes == 0) {
  1947. if (par_temp.tipo == tiposDados.real) {
  1948. 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> ';
  1949. } else {
  1950. if (par_temp.tipo == tiposDados.boolean) {
  1951. 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> ';
  1952. } else {
  1953. 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> ';
  1954. }
  1955. }
  1956. } else {
  1957. ret += '<table class="tabela_var">';
  1958. if (par_temp.dimensoes == 1) {
  1959. ret += '<tr>';
  1960. if (par_temp.tipo == tiposDados.real) {
  1961. for (var k = 0; k < par_temp.colunas; k++) {
  1962. ret += '<td><span class="span_value_variable" ondblclick="enableVarVectorValueUpdate(this.parentNode, '+sequence+', '+j+', '+k+')" >'+par_temp.valor[k].toFixed(1)+'</span>'+'</td>';
  1963. }
  1964. } else {
  1965. for (var k = 0; k < par_temp.colunas; k++) {
  1966. if (par_temp.tipo == tiposDados.boolean) {
  1967. ret += '<td><span class="span_value_variable" ondblclick="alternateBooleanVarVectorValue(this.parentNode, '+sequence+', '+j+', '+k+')" >'+par_temp.valor[k]+'</span>'+'</td>';
  1968. } else {
  1969. ret += '<td><span class="span_value_variable" ondblclick="enableVarVectorValueUpdate(this.parentNode, '+sequence+', '+j+', '+k+')" >'+par_temp.valor[k]+'</span>'+'</td>';
  1970. }
  1971. }
  1972. }
  1973. ret += '</tr>';
  1974. ret += '</table>';
  1975. ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline" onclick="removeColumnVector('+sequence+', '+j+')"></i>'
  1976. + ' <i class="ui icon plus square outline" onclick="addColumnVector('+sequence+', '+j+')"></i></div>';
  1977. }
  1978. if (par_temp.dimensoes == 2) {
  1979. if (par_temp.tipo == tiposDados.real) {
  1980. for (var l = 0; l < par_temp.linhas; l++) {
  1981. ret += '<tr>';
  1982. for (var k = 0; k < par_temp.colunas; k++) {
  1983. ret += '<td><span class="span_value_variable" ondblclick="enableVarMatrixValueUpdate(this.parentNode, '+sequence+', '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k].toFixed(1)+'</span>'+'</td>';
  1984. }
  1985. ret += '</tr>';
  1986. }
  1987. } else {
  1988. for (var l = 0; l < par_temp.linhas; l++) {
  1989. ret += '<tr>';
  1990. for (var k = 0; k < par_temp.colunas; k++) {
  1991. if (par_temp.tipo == tiposDados.boolean) {
  1992. ret += '<td><span class="span_value_variable" ondblclick="alternateBooleanVarMatrixValue(this.parentNode, '+sequence+', '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k]+'</span>'+'</td>';
  1993. } else {
  1994. ret += '<td><span class="span_value_variable" ondblclick="enableVarMatrixValueUpdate(this.parentNode, '+sequence+', '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k]+'</span>'+'</td>';
  1995. }
  1996. }
  1997. ret += '</tr>';
  1998. }
  1999. }
  2000. if (par_temp.linhas == 0) {
  2001. ret += '<tr><td></td></tr>';
  2002. }
  2003. ret += '<tr><td colspan="'+par_temp.colunas+'" class="tr_manage_lines"><i class="ui icon minus square outline" onclick="removeLineMatrix('+sequence+', '+j+')"></i>'
  2004. + ' <i class="ui icon plus square outline" onclick="addLineMatrix('+sequence+', '+j+')"></i></td></tr>';
  2005. ret += '</table>';
  2006. ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline" onclick="removeColumnMatrix('+sequence+', '+j+')"></i>'
  2007. + ' <i class="ui icon plus square outline" onclick="addColumnMatrix('+sequence+', '+j+')"></i></div>';
  2008. }
  2009. }
  2010. ret += ' <i class="red icon times remove_parameter" onclick="deleteVariable('+sequence+', '+j+')"></i></div>';
  2011. }
  2012. }
  2013. return ret;
  2014. }
  2015. // Essa função imprime o tipo de retorno da função e cria o menu do tipo 'select' para alteração
  2016. function renderFunctionReturn(function_obj, sequence) {
  2017. var ret = '<div class="ui dropdown function_return seq_'+sequence+'">';
  2018. if (function_obj.dimensoes_retorno > 0) {
  2019. ret += '<div class="text seq_'+sequence+'"">'+ i18n(tiposDados.vector)+':'+i18n(function_obj.tipo_retorno);
  2020. ret += '</div>';
  2021. } else {
  2022. ret += '<div class="text seq_'+sequence+'"">'+i18n(function_obj.tipo_retorno)+'</div>';
  2023. }
  2024. ret += '<i class="dropdown icon"></i>'
  2025. + '<div class="menu seq_'+sequence+'"">';
  2026. var i = 0;
  2027. for (tm in tiposDados) {
  2028. if (i == (Object.keys(tiposDados).length - 1)) { break; }
  2029. ret += '<div class="item ' + ((function_obj.tipo_retorno == tm && function_obj.dimensoes_retorno < 1) ? ' selected ' : '') + ' seq_'+sequence+' '+tm+'" >'+i18n(tm)+'</div>';
  2030. i ++;
  2031. }
  2032. i = 0;
  2033. for (tm in tiposDados) {
  2034. i ++;
  2035. if (i == 1) { continue; }
  2036. if (i == (Object.keys(tiposDados).length)) { break; }
  2037. 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)+' ">'
  2038. + i18n(tiposDados.vector)+':'+i18n(tm)
  2039. + '</div>';
  2040. }
  2041. ret += '</div></div>';
  2042. return ret;
  2043. }
  2044. $.fn.textWidth = function(text, font) {
  2045. if (!$.fn.textWidth.fakeEl) $.fn.textWidth.fakeEl = $('<span>').hide().appendTo(document.body);
  2046. $.fn.textWidth.fakeEl.text(text || this.val() || this.text() || this.attr('placeholder')).css('font', font || this.css('font'));
  2047. return $.fn.textWidth.fakeEl.width();
  2048. };