ivprog-visual-functions-1.0.js 90 KB

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