ivprog-visual-functions-1.0.js 102 KB

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