ivprog-visual-functions-1.0.js 102 KB

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