ivprog-visual-functions-1.0.js 107 KB

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