1
0

old_functions.js 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118
  1. var counter_new_functions = 0;
  2. var counter_new_parameters = 0;
  3. var counter_new_variables = 0;
  4. var counter_new_globals = 0;
  5. function addFunctionHandler() {
  6. new_function = new Funcao(i18n("new_function") + "_" + counter_new_functions, tiposDados.void, 0, new Array(), false, false, null, new Comentario(i18n('text_comment_start')));
  7. adicionarFuncao(new_function);
  8. counter_new_functions ++;
  9. renderAlgorithm();
  10. }
  11. function addGlobalVar() {
  12. var v = new Variavel(tiposDados.integer, i18n('new_global') + '_' + counter_new_globals, 1);
  13. counter_new_globals ++;
  14. programa.globais.push(v);
  15. renderAlgorithm();
  16. }
  17. function updateSequenceFunctionHandler(index_from, index_to) {
  18. programa.funcoes.splice(index_to, 0, programa.funcoes.splice(index_from, 1)[0]);
  19. renderAlgorithm();
  20. }
  21. function removeFunctionHandler(div_function, sequence) {
  22. programa.funcoes.splice(sequence, 1);
  23. $(div_function).slideUp(400, function(){
  24. renderAlgorithm();
  25. });
  26. }
  27. function minimizeFunctionHandler(div_function, sequence) {
  28. $(div_function).find(".function_area").toggle();
  29. programa.funcoes[sequence].esta_oculta = !programa.funcoes[sequence].esta_oculta;
  30. }
  31. function renderAlgorithm() {
  32. $('.all_functions').empty();
  33. for (i = 0; i < programa.funcoes.length; i++) {
  34. appendFunction(programa.funcoes[i], i);
  35. }
  36. $('.list_globals').empty();
  37. if (programa.globais.length > 0) {
  38. renderGlobals();
  39. }
  40. $('.data_types_dropdown').dropdown();
  41. $('.parameter_data_types_dropdown').dropdown();
  42. addHandlers();
  43. }
  44. function deleteGlobal(which_global) {
  45. programa.globais.splice(which_global, 1);
  46. renderAlgorithm();
  47. }
  48. function alternateGlobalConst(which_global) {
  49. programa.globais[which_global].eh_constante = !programa.globais[which_global].eh_constante;
  50. renderAlgorithm();
  51. }
  52. function renderGlobals() {
  53. var ret = "";
  54. if (programa.globais.length > 0) {
  55. for (var j = 0; j < programa.globais.length; j++) {
  56. var par_temp = programa.globais[j];
  57. ret += '<div class="ui label name_variable"><div class="global_const">const: ';
  58. ret += '<i class="ui icon toggle '+(par_temp.eh_constante?"on":"off")+' " onclick="alternateGlobalConst('+j+')"></i></div><span class="span_name_variable" ondblclick="enableNameGlobalUpdate(this.parentNode, '+j+')">'+par_temp.nome+'</span> <i class="icon small pencil alternate enable_edit_name_parameter" onclick="enableNameGlobalUpdate(this.parentNode, '+j+')"></i>';
  59. ret += '<div class="ui dropdown global_type seq_'+j+'">';
  60. if (par_temp.dimensoes > 0) {
  61. ret += '<div class="text seq_'+j+'">'+ i18n(tiposDados.vector)+':'+i18n(par_temp.tipo);
  62. for (i = 0; i < par_temp.dimensoes; i ++) {
  63. ret += ' [ ] ';
  64. }
  65. ret += '</div>';
  66. } else {
  67. ret += '<div class="text seq_'+j+'">'+i18n(par_temp.tipo)+'</div>';
  68. }
  69. ret += '<i class="dropdown icon"></i>'
  70. + '<div class="menu seq_'+j+'">';
  71. var i = 0;
  72. for (tm in tiposDados) {
  73. i ++;
  74. if (i == 1) { continue; }
  75. if (i == (Object.keys(tiposDados).length)) { break; }
  76. ret += '<div class="item ' + (par_temp.tipo == tm ? ' selected ' : '') + ' seq_'+j+' '+tm+'" >'+i18n(tm)+'</div>';
  77. }
  78. i = 0;
  79. for (tm in tiposDados) {
  80. i ++;
  81. if (i == 1) { continue; }
  82. if (i == (Object.keys(tiposDados).length)) { break; }
  83. ret += '<div class="item seq_'+j+' ">'
  84. + '<i class="dropdown icon"></i>'
  85. + i18n(tiposDados.vector)+':'+i18n(tm)
  86. + '<div class="menu seq_'+j+' ">'
  87. + '<div class="item seq_'+j+' '+tm+'" data-text="'+ i18n(tiposDados.vector)+':'+i18n(tm)+' [ ] ">[ ]</div>'
  88. + '<div class="item seq_'+j+' '+tm+'" data-text="'+ i18n(tiposDados.vector)+':'+i18n(tm)+' [ ] [ ] ">[ ] [ ] </div>'
  89. + '</div>'
  90. + '</div>';
  91. }
  92. ret += '</div></div> = ';
  93. if (par_temp.dimensoes == 0) {
  94. if (par_temp.tipo == tiposDados.real) {
  95. ret += '<div class="div_valor_var"><span class="span_value_variable" ondblclick="enableGlobalValueUpdate(this.parentNode, '+j+')" >'+par_temp.valor.toFixed(1)+'</span> <i class="icon small pencil alternate enable_edit_name_function" onclick="enableGlobalValueUpdate(this.parentNode, '+j+')"></i></div> ';
  96. } else {
  97. if (par_temp.tipo == tiposDados.boolean) {
  98. ret += '<div class="div_valor_var"><span class="span_value_variable" ondblclick="alternateBooleanGlobalValue(this.parentNode, '+j+')" >'+par_temp.valor+'</span> <i class="icon small pencil alternate enable_edit_name_function" onclick="alternateBooleanGlobalValue(this.parentNode, '+j+')"></i></div> ';
  99. } else {
  100. ret += '<div class="div_valor_var"><span class="span_value_variable" ondblclick="enableGlobalValueUpdate(this.parentNode, '+j+')" >'+par_temp.valor+'</span> <i class="icon small pencil alternate enable_edit_name_function" onclick="enableGlobalValueUpdate(this.parentNode, '+j+')"></i></div> ';
  101. }
  102. }
  103. } else {
  104. ret += '<table class="tabela_var">';
  105. if (par_temp.dimensoes == 1) {
  106. ret += '<tr>';
  107. if (par_temp.tipo == tiposDados.real) {
  108. for (var k = 0; k < par_temp.colunas; k++) {
  109. ret += '<td><span class="span_value_variable" ondblclick="enableGlobalVectorValueUpdate(this.parentNode, '+j+', '+k+')" >'+par_temp.valor[k].toFixed(1)+'</span>'+'</td>';
  110. }
  111. } else {
  112. for (var k = 0; k < par_temp.colunas; k++) {
  113. if (par_temp.tipo == tiposDados.boolean) {
  114. ret += '<td><span class="span_value_variable" ondblclick="alternateBooleanGlobalVectorValue(this.parentNode, '+j+', '+k+')" >'+par_temp.valor[k]+'</span>'+'</td>';
  115. } else {
  116. ret += '<td><span class="span_value_variable" ondblclick="enableGlobalVectorValueUpdate(this.parentNode, '+j+', '+k+')" >'+par_temp.valor[k]+'</span>'+'</td>';
  117. }
  118. }
  119. }
  120. ret += '</tr>';
  121. ret += '</table>';
  122. ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline" onclick="removeGlobalColumnVector('+j+')"></i>'
  123. + ' <i class="ui icon plus square outline" onclick="addGlobalColumnVector('+j+')"></i></div>';
  124. }
  125. if (par_temp.dimensoes == 2) {
  126. if (par_temp.tipo == tiposDados.real) {
  127. for (var l = 0; l < par_temp.linhas; l++) {
  128. ret += '<tr>';
  129. for (var k = 0; k < par_temp.colunas; k++) {
  130. ret += '<td><span class="span_value_variable" ondblclick="enableGlobalMatrixValueUpdate(this.parentNode, '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k].toFixed(1)+'</span>'+'</td>';
  131. }
  132. ret += '</tr>';
  133. }
  134. } else {
  135. for (var l = 0; l < par_temp.linhas; l++) {
  136. ret += '<tr>';
  137. for (var k = 0; k < par_temp.colunas; k++) {
  138. if (par_temp.tipo == tiposDados.boolean) {
  139. ret += '<td><span class="span_value_variable" ondblclick="alternateBooleanGlobalMatrixValue(this.parentNode, '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k]+'</span>'+'</td>';
  140. } else {
  141. ret += '<td><span class="span_value_variable" ondblclick="enableGlobalMatrixValueUpdate(this.parentNode, '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k]+'</span>'+'</td>';
  142. }
  143. }
  144. ret += '</tr>';
  145. }
  146. }
  147. if (par_temp.linhas == 0) {
  148. ret += '<tr><td></td></tr>';
  149. }
  150. ret += '<tr><td colspan="'+par_temp.colunas+'" class="tr_manage_lines"><i class="ui icon minus square outline" onclick="removeLineGlobalMatrix('+j+')"></i>'
  151. + ' <i class="ui icon plus square outline" onclick="addLineGlobalMatrix('+j+')"></i></td></tr>';
  152. ret += '</table>';
  153. ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline" onclick="removeColumnGlobalMatrix('+j+')"></i>'
  154. + ' <i class="ui icon plus square outline" onclick="addColumnGlobalMatrix('+j+')"></i></div>';
  155. }
  156. }
  157. ret += ' <i class="red icon times remove_parameter" onclick="deleteGlobal('+j+')"></i></div>';
  158. }
  159. }
  160. $('.list_globals').append(ret);
  161. }
  162. var has_element_created_draged = false;
  163. var which_element_is_draged = null;
  164. function createCommentDragObject() {
  165. var ret = '';
  166. ret += '<div class="ui comment created_element"> <i class="ui icon small quote left"></i> <span class="span_comment_text" "> Testando </span>';
  167. ret += '</div>';
  168. has_element_created_draged = true;
  169. which_element_is_draged = tiposComandos.comment;
  170. $('body').append(ret);
  171. }
  172. var myDraggable = null;
  173. // Yeah... we're going to hack the widget
  174. var widget = null;
  175. var clickEvent = null;
  176. function flutuateCreatedElement() {
  177. $('.created_element').css('top', mouseY);
  178. $('.created_element').css('left', mouseX);
  179. myDraggable = $('.created_element').draggable();
  180. // Yeah... we're going to hack the widget
  181. widget = myDraggable.data('ui-draggable');
  182. clickEvent = null;
  183. myDraggable.click(function(event){
  184. if(!clickEvent){
  185. widget._mouseStart(event);
  186. clickEvent = event;
  187. }
  188. else {
  189. widget._mouseUp(event);
  190. clickEvent = null;
  191. }
  192. });
  193. $(document).mousemove(function(event){
  194. if(clickEvent){
  195. // We need to set this to our own clickEvent, otherwise
  196. // it won't position correctly.
  197. widget._mouseDownEvent = clickEvent;
  198. widget._mouseMove(event);
  199. }
  200. });
  201. }
  202. function addHandlers() {
  203. $('.ui.buttons .dropdown').dropdown({
  204. onChange: function(value, text, $selectedItem) {
  205. if (value == tiposComandos.comment) {
  206. createCommentDragObject();
  207. }
  208. flutuateCreatedElement();
  209. }
  210. });
  211. $('.ui.dropdown.function_return')
  212. .dropdown({
  213. onChange: function(value, text, $selectedItem) {
  214. classList = $selectedItem.attr('class').split(/\s+/);
  215. $.each(classList, function(index, item) {
  216. if (item.indexOf("seq_") > -1) {
  217. seq = item.split("seq_")[1];
  218. for (tm in tiposDados) {
  219. if ($selectedItem.hasClass(tm)) {
  220. programa.funcoes[seq].tipo_retorno = tm;
  221. }
  222. }
  223. updateFunctionReturn(seq, value);
  224. }
  225. });
  226. }
  227. })
  228. ;
  229. $('.ui.dropdown.parameter_type').dropdown({
  230. onChange: function(value, text, $selectedItem) {
  231. classList = $selectedItem.attr('class').split(/\s+/);
  232. var fun;
  233. var seq;
  234. $.each(classList, function(index, item) {
  235. if (item.indexOf("fun_") > -1) {
  236. fun = item.split("fun_")[1];
  237. }
  238. if (item.indexOf("seq_") > -1) {
  239. seq = item.split("seq_")[1];
  240. }
  241. });
  242. var dim = 0;
  243. if (value.indexOf(i18n(tiposDados.vector)) > -1) {
  244. dim = 1;
  245. }
  246. for (tm in tiposDados) {
  247. if ($selectedItem.hasClass(tm)) {
  248. updateParameterType(fun, seq, tm, dim);
  249. break;
  250. }
  251. }
  252. }
  253. });
  254. $('.ui.dropdown.variable_type').dropdown({
  255. onChange: function(value, text, $selectedItem) {
  256. classList = $selectedItem.attr('class').split(/\s+/);
  257. var fun;
  258. var seq;
  259. $.each(classList, function(index, item) {
  260. if (item.indexOf("fun_") > -1) {
  261. fun = item.split("fun_")[1];
  262. }
  263. if (item.indexOf("seq_") > -1) {
  264. seq = item.split("seq_")[1];
  265. }
  266. });
  267. var dim = 0;
  268. if (value.indexOf(i18n(tiposDados.vector)) > -1) {
  269. dim = value.split('[').length - 1;
  270. }
  271. for (tm in tiposDados) {
  272. if ($selectedItem.hasClass(tm)) {
  273. updateVariableType(fun, seq, tm, dim);
  274. break;
  275. }
  276. }
  277. }
  278. });
  279. $('.ui.dropdown.global_type').dropdown({
  280. onChange: function(value, text, $selectedItem) {
  281. classList = $selectedItem.attr('class').split(/\s+/);
  282. var fun;
  283. var seq;
  284. $.each(classList, function(index, item) {
  285. if (item.indexOf("seq_") > -1) {
  286. seq = item.split("seq_")[1];
  287. }
  288. });
  289. var dim = 0;
  290. if (value.indexOf(i18n(tiposDados.vector)) > -1) {
  291. dim = value.split('[').length - 1;
  292. }
  293. for (tm in tiposDados) {
  294. if ($selectedItem.hasClass(tm)) {
  295. updateGlobalType(seq, tm, dim);
  296. break;
  297. }
  298. }
  299. }
  300. });
  301. }
  302. function updateGlobalType(wich_variable, new_value, new_dimensions) {
  303. programa.globais[wich_variable].tipo = new_value;
  304. programa.globais[wich_variable].dimensoes = new_dimensions;
  305. if (new_dimensions > 0) {
  306. programa.globais[wich_variable].linhas = new_dimensions;
  307. programa.globais[wich_variable].colunas = 2;
  308. }
  309. if (new_value == tiposDados.integer) {
  310. if (new_dimensions == 0) {
  311. programa.globais[wich_variable].valor = 1;
  312. }
  313. if (new_dimensions == 1) {
  314. programa.globais[wich_variable].valor = [1, 1];
  315. }
  316. if (new_dimensions == 2) {
  317. programa.globais[wich_variable].valor = [[1, 1], [1, 1]];
  318. }
  319. }
  320. if (new_value == tiposDados.real) {
  321. if (new_dimensions == 0) {
  322. programa.globais[wich_variable].valor = 1.0;
  323. }
  324. if (new_dimensions == 1) {
  325. programa.globais[wich_variable].valor = [1.0, 1.0];
  326. }
  327. if (new_dimensions == 2) {
  328. programa.globais[wich_variable].valor = [[1.0, 1.0], [1.0, 1.0]];
  329. }
  330. }
  331. if (new_value == tiposDados.text) {
  332. if (new_dimensions == 0) {
  333. programa.globais[wich_variable].valor = i18n(tiposDados.text);
  334. }
  335. if (new_dimensions == 1) {
  336. programa.globais[wich_variable].valor = [i18n(tiposDados.text), i18n(tiposDados.text)];
  337. }
  338. if (new_dimensions == 2) {
  339. programa.globais[wich_variable].valor = [[i18n(tiposDados.text), i18n(tiposDados.text)], [i18n(tiposDados.text), i18n(tiposDados.text)]];
  340. }
  341. }
  342. if (new_value == tiposDados.boolean) {
  343. if (new_dimensions == 0) {
  344. programa.globais[wich_variable].valor = true;
  345. }
  346. if (new_dimensions == 1) {
  347. programa.globais[wich_variable].valor = [true, true];
  348. }
  349. if (new_dimensions == 2) {
  350. programa.globais[wich_variable].valor = [[true, true], [true, true]];
  351. }
  352. }
  353. renderAlgorithm();
  354. }
  355. function updateVariableType(wich_function, wich_variable, new_value, new_dimensions) {
  356. programa.funcoes[wich_function].variaveis[wich_variable].tipo = new_value;
  357. programa.funcoes[wich_function].variaveis[wich_variable].dimensoes = new_dimensions;
  358. if (new_dimensions > 0) {
  359. programa.funcoes[wich_function].variaveis[wich_variable].linhas = new_dimensions;
  360. programa.funcoes[wich_function].variaveis[wich_variable].colunas = 2;
  361. }
  362. if (new_value == tiposDados.integer) {
  363. if (new_dimensions == 0) {
  364. programa.funcoes[wich_function].variaveis[wich_variable].valor = 1;
  365. }
  366. if (new_dimensions == 1) {
  367. programa.funcoes[wich_function].variaveis[wich_variable].valor = [1, 1];
  368. }
  369. if (new_dimensions == 2) {
  370. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[1, 1], [1, 1]];
  371. }
  372. }
  373. if (new_value == tiposDados.real) {
  374. if (new_dimensions == 0) {
  375. programa.funcoes[wich_function].variaveis[wich_variable].valor = 1.0;
  376. }
  377. if (new_dimensions == 1) {
  378. programa.funcoes[wich_function].variaveis[wich_variable].valor = [1.0, 1.0];
  379. }
  380. if (new_dimensions == 2) {
  381. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[1.0, 1.0], [1.0, 1.0]];
  382. }
  383. }
  384. if (new_value == tiposDados.text) {
  385. if (new_dimensions == 0) {
  386. programa.funcoes[wich_function].variaveis[wich_variable].valor = i18n(tiposDados.text);
  387. }
  388. if (new_dimensions == 1) {
  389. programa.funcoes[wich_function].variaveis[wich_variable].valor = [i18n(tiposDados.text), i18n(tiposDados.text)];
  390. }
  391. if (new_dimensions == 2) {
  392. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[i18n(tiposDados.text), i18n(tiposDados.text)], [i18n(tiposDados.text), i18n(tiposDados.text)]];
  393. }
  394. }
  395. if (new_value == tiposDados.boolean) {
  396. if (new_dimensions == 0) {
  397. programa.funcoes[wich_function].variaveis[wich_variable].valor = true;
  398. }
  399. if (new_dimensions == 1) {
  400. programa.funcoes[wich_function].variaveis[wich_variable].valor = [true, true];
  401. }
  402. if (new_dimensions == 2) {
  403. programa.funcoes[wich_function].variaveis[wich_variable].valor = [[true, true], [true, true]];
  404. }
  405. }
  406. renderAlgorithm();
  407. }
  408. function addGlobalColumnVector(which_variable) {
  409. programa.globais[which_variable].colunas ++;
  410. if (programa.globais[which_variable].tipo == tiposDados.integer) {
  411. programa.globais[which_variable].valor.push(1);
  412. }
  413. if (programa.globais[which_variable].tipo == tiposDados.real) {
  414. programa.globais[which_variable].valor.push(1.0);
  415. }
  416. if (programa.globais[which_variable].tipo == tiposDados.text) {
  417. programa.globais[which_variable].valor.push(i18n(tiposDados.text));
  418. }
  419. if (programa.globais[which_variable].tipo == tiposDados.boolean) {
  420. programa.globais[which_variable].valor.push(true);
  421. }
  422. renderAlgorithm();
  423. }
  424. function addColumnVector(which_function, which_variable) {
  425. programa.funcoes[which_function].variaveis[which_variable].colunas ++;
  426. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.integer) {
  427. programa.funcoes[which_function].variaveis[which_variable].valor.push(1);
  428. }
  429. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.real) {
  430. programa.funcoes[which_function].variaveis[which_variable].valor.push(1.0);
  431. }
  432. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.text) {
  433. programa.funcoes[which_function].variaveis[which_variable].valor.push(i18n(tiposDados.text));
  434. }
  435. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.boolean) {
  436. programa.funcoes[which_function].variaveis[which_variable].valor.push(true);
  437. }
  438. renderAlgorithm();
  439. }
  440. function addColumnMatrix(which_function, which_variable) {
  441. programa.funcoes[which_function].variaveis[which_variable].colunas ++;
  442. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.integer) {
  443. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  444. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(1);
  445. }
  446. }
  447. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.real) {
  448. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  449. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(1.0);
  450. }
  451. }
  452. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.text) {
  453. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  454. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(i18n(tiposDados.text));
  455. }
  456. }
  457. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.boolean) {
  458. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  459. programa.funcoes[which_function].variaveis[which_variable].valor[i].push(true);
  460. }
  461. }
  462. renderAlgorithm();
  463. }
  464. function addColumnGlobalMatrix(which_variable) {
  465. programa.globais[which_variable].colunas ++;
  466. if (programa.globais[which_variable].tipo == tiposDados.integer) {
  467. for (i = 0; i < programa.globais[which_variable].linhas; i++) {
  468. programa.globais[which_variable].valor[i].push(1);
  469. }
  470. }
  471. if (programa.globais[which_variable].tipo == tiposDados.real) {
  472. for (i = 0; i < programa.globais[which_variable].linhas; i++) {
  473. programa.globais[which_variable].valor[i].push(1.0);
  474. }
  475. }
  476. if (programa.globais[which_variable].tipo == tiposDados.text) {
  477. for (i = 0; i < programa.globais[which_variable].linhas; i++) {
  478. programa.globais[which_variable].valor[i].push(i18n(tiposDados.text));
  479. }
  480. }
  481. if (programa.globais[which_variable].tipo == tiposDados.boolean) {
  482. for (i = 0; i < programa.globais[which_variable].linhas; i++) {
  483. programa.globais[which_variable].valor[i].push(true);
  484. }
  485. }
  486. renderAlgorithm();
  487. }
  488. function addLineMatrix(which_function, which_variable) {
  489. programa.funcoes[which_function].variaveis[which_variable].linhas ++;
  490. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.integer) {
  491. var n_l = [];
  492. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  493. n_l.push(1);
  494. }
  495. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  496. }
  497. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.real) {
  498. var n_l = [];
  499. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  500. n_l.push(1.0);
  501. }
  502. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  503. }
  504. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.text) {
  505. var n_l = [];
  506. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  507. n_l.push(i18n(tiposDados.text));
  508. }
  509. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  510. }
  511. if (programa.funcoes[which_function].variaveis[which_variable].tipo == tiposDados.boolean) {
  512. var n_l = [];
  513. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].colunas; i++) {
  514. n_l.push(true);
  515. }
  516. programa.funcoes[which_function].variaveis[which_variable].valor.push(n_l);
  517. }
  518. renderAlgorithm();
  519. }
  520. function addLineGlobalMatrix(which_variable) {
  521. programa.globais[which_variable].linhas ++;
  522. if (programa.globais[which_variable].tipo == tiposDados.integer) {
  523. var n_l = [];
  524. for (i = 0; i < programa.globais[which_variable].colunas; i++) {
  525. n_l.push(1);
  526. }
  527. programa.globais[which_variable].valor.push(n_l);
  528. }
  529. if (programa.globais[which_variable].tipo == tiposDados.real) {
  530. var n_l = [];
  531. for (i = 0; i < programa.globais[which_variable].colunas; i++) {
  532. n_l.push(1.0);
  533. }
  534. programa.globais[which_variable].valor.push(n_l);
  535. }
  536. if (programa.globais[which_variable].tipo == tiposDados.text) {
  537. var n_l = [];
  538. for (i = 0; i < programa.globais[which_variable].colunas; i++) {
  539. n_l.push(i18n(tiposDados.text));
  540. }
  541. programa.globais[which_variable].valor.push(n_l);
  542. }
  543. if (programa.globais[which_variable].tipo == tiposDados.boolean) {
  544. var n_l = [];
  545. for (i = 0; i < programa.globais[which_variable].colunas; i++) {
  546. n_l.push(true);
  547. }
  548. programa.globais[which_variable].valor.push(n_l);
  549. }
  550. renderAlgorithm();
  551. }
  552. function removeGlobalColumnVector(which_variable) {
  553. if (programa.globais[which_variable].colunas == 0) {
  554. return;
  555. }
  556. programa.globais[which_variable].colunas --;
  557. programa.globais[which_variable].valor.splice(programa.globais[which_variable].valor.length - 1, 1);
  558. renderAlgorithm();
  559. }
  560. function removeColumnVector(which_function, which_variable) {
  561. if (programa.funcoes[which_function].variaveis[which_variable].colunas == 0) {
  562. return;
  563. }
  564. programa.funcoes[which_function].variaveis[which_variable].colunas --;
  565. programa.funcoes[which_function].variaveis[which_variable].valor.splice(programa.funcoes[which_function].variaveis[which_variable].valor.length - 1, 1);
  566. renderAlgorithm();
  567. }
  568. function removeColumnMatrix(which_function, which_variable) {
  569. if (programa.funcoes[which_function].variaveis[which_variable].colunas == 0) {
  570. return;
  571. }
  572. programa.funcoes[which_function].variaveis[which_variable].colunas --;
  573. for (i = 0; i < programa.funcoes[which_function].variaveis[which_variable].linhas; i++) {
  574. programa.funcoes[which_function].variaveis[which_variable].valor[i].splice(programa.funcoes[which_function].variaveis[which_variable].valor[i].length - 1, 1);
  575. }
  576. renderAlgorithm();
  577. }
  578. function removeColumnGlobalMatrix(which_variable) {
  579. if (programa.globais[which_variable].colunas == 0) {
  580. return;
  581. }
  582. programa.globais[which_variable].colunas --;
  583. for (i = 0; i < programa.globais[which_variable].linhas; i++) {
  584. programa.globais[which_variable].valor[i].splice(programa.globais[which_variable].valor[i].length - 1, 1);
  585. }
  586. renderAlgorithm();
  587. }
  588. function removeLineGlobalMatrix(which_variable) {
  589. if (programa.globais[which_variable].linhas == 0) {
  590. return;
  591. }
  592. programa.globais[which_variable].linhas --;
  593. programa.globais[which_variable].valor.splice(programa.globais[which_variable].valor.length - 1, 1);
  594. renderAlgorithm();
  595. }
  596. function removeLineMatrix(which_function, which_variable) {
  597. if (programa.funcoes[which_function].variaveis[which_variable].linhas == 0) {
  598. return;
  599. }
  600. programa.funcoes[which_function].variaveis[which_variable].linhas --;
  601. programa.funcoes[which_function].variaveis[which_variable].valor.splice(programa.funcoes[which_function].variaveis[which_variable].valor.length - 1, 1);
  602. renderAlgorithm();
  603. }
  604. function addVariable(sequence) {//tipo, nome, valor
  605. var v = new Variavel(tiposDados.integer, i18n('new_variable') + '_' + counter_new_variables, 1);
  606. adicionarVariavel(sequence, v);
  607. counter_new_variables ++;
  608. renderAlgorithm();
  609. }
  610. function deleteVariable(which_function, which_variable) {
  611. programa.funcoes[which_function].variaveis.splice(which_variable, 1);
  612. renderAlgorithm();
  613. }
  614. function addParameter(sequence) {
  615. if (programa.funcoes[sequence].lista_parametros == null) {
  616. programa.funcoes[sequence].lista_parametros = new Array();
  617. }
  618. programa.funcoes[sequence].lista_parametros.push(new Variavel(tiposDados.integer, i18n("new_parameter") + "_" + counter_new_parameters));
  619. counter_new_parameters ++;
  620. renderAlgorithm();
  621. }
  622. function updateFunctionReturn(sequence, new_value) {
  623. if (new_value.indexOf(i18n(tiposDados.vector)) > -1) {
  624. programa.funcoes[sequence].dimensoes_retorno = 1;
  625. } else {
  626. programa.funcoes[sequence].dimensoes_retorno = 0;
  627. }
  628. }
  629. function updateParameterType(wich_function, wich_parameter, new_value, new_dimensions) {
  630. programa.funcoes[wich_function].lista_parametros[wich_parameter].tipo = new_value;
  631. programa.funcoes[wich_function].lista_parametros[wich_parameter].dimensoes = new_dimensions;
  632. }
  633. var opened_name_global = false;
  634. var opened_input_global = null;
  635. var sequence_name_opened_global;
  636. function enableNameGlobalUpdate(div_el, sequence) {
  637. if (opened_name_global) {
  638. $(opened_input_global).focus();
  639. return;
  640. }
  641. opened_name_global = true;
  642. sequence_name_opened_global = sequence;
  643. $(div_el).find('.span_name_variable').text('');
  644. $( "<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'));
  645. $('.width-dynamic').on('input', function() {
  646. var inputWidth = $(this).textWidth()+10;
  647. opened_input_global = this;
  648. $(this).focus();
  649. var tmpStr = $(this).val();
  650. $(this).val('');
  651. $(this).val(tmpStr);
  652. $(this).css({
  653. width: inputWidth
  654. })
  655. }).trigger('input');
  656. $('.width-dynamic').focusout(function() {
  657. /// update array:
  658. if ($(this).val().trim()) {
  659. programa.globais[sequence].nome = $(this).val().trim();
  660. }
  661. $(this).remove();
  662. /// update elements:
  663. opened_name_global = false;
  664. opened_input_global = false;
  665. renderAlgorithm();
  666. });
  667. $('.width-dynamic').on('keydown', function(e) {
  668. var code = e.keyCode || e.which;
  669. if(code == 13) {
  670. if ($(this).val().trim()) {
  671. programa.globais[sequence].nome = $(this).val().trim();
  672. }
  673. $(this).remove();
  674. /// update elements:
  675. opened_name_global = false;
  676. opened_input_global = false;
  677. renderAlgorithm();
  678. }
  679. if(code == 27) {
  680. $(div_el).find('.span_name_function').text(programa.globais[sequence].nome);
  681. $(this).remove();
  682. /// update elements:
  683. opened_name_global = false;
  684. opened_input_global = false;
  685. }
  686. });
  687. }
  688. var opened_name_function = false;
  689. var opened_input = null;
  690. var sequence_name_opened;
  691. function enableNameFunctionUpdate(div_el, sequence) {
  692. if (opened_name_function) {
  693. $(opened_input).focus();
  694. return;
  695. }
  696. opened_name_function = true;
  697. sequence_name_opened = sequence;
  698. $(div_el).find('.span_name_function').text('');
  699. $( "<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'));
  700. $('.width-dynamic').on('input', function() {
  701. var inputWidth = $(this).textWidth()+10;
  702. opened_input = this;
  703. $(this).focus();
  704. var tmpStr = $(this).val();
  705. $(this).val('');
  706. $(this).val(tmpStr);
  707. $(this).css({
  708. width: inputWidth
  709. })
  710. }).trigger('input');
  711. $('.width-dynamic').focusout(function() {
  712. /// update array:
  713. if ($(this).val().trim()) {
  714. programa.funcoes[sequence_name_opened].nome = $(this).val().trim();
  715. }
  716. $(this).remove();
  717. /// update elements:
  718. opened_name_function = false;
  719. opened_input = false;
  720. renderAlgorithm();
  721. });
  722. $('.width-dynamic').on('keydown', function(e) {
  723. var code = e.keyCode || e.which;
  724. if(code == 13) {
  725. if ($(this).val().trim()) {
  726. programa.funcoes[sequence_name_opened].nome = $(this).val().trim();
  727. }
  728. $(this).remove();
  729. /// update elements:
  730. opened_name_function = false;
  731. opened_input = false;
  732. renderAlgorithm();
  733. }
  734. if(code == 27) {
  735. $(div_el).find('.span_name_function').text(programa.funcoes[sequence_name_opened].nome);
  736. $(this).remove();
  737. /// update elements:
  738. opened_name_function = false;
  739. opened_input = false;
  740. }
  741. });
  742. }
  743. function alternateBooleanVarVectorValue(parent_node, which_function, which_var, column_index) {
  744. programa.funcoes[which_function].variaveis[which_var].valor[column_index] = !programa.funcoes[which_function].variaveis[which_var].valor[column_index];
  745. renderAlgorithm();
  746. }
  747. function alternateBooleanGlobalVectorValue(parent_node, which_var, column_index) {
  748. programa.globais[which_var].valor[column_index] = !programa.globais[which_var].valor[column_index];
  749. renderAlgorithm();
  750. }
  751. function alternateBooleanVarMatrixValue(parent_node, which_function, which_var, row_index, column_index) {
  752. programa.funcoes[which_function].variaveis[which_var].valor[row_index][column_index] = !programa.funcoes[which_function].variaveis[which_var].valor[row_index][column_index];
  753. renderAlgorithm();
  754. }
  755. function alternateBooleanGlobalMatrixValue(parent_node, which_var, row_index, column_index) {
  756. programa.globais[which_var].valor[row_index][column_index] = !programa.globais[which_var].valor[row_index][column_index];
  757. renderAlgorithm();
  758. }
  759. function alternateBooleanGlobalValue(parent_node, which_var) {
  760. programa.globais[which_var].valor = !programa.globais[which_var].valor;
  761. renderAlgorithm();
  762. }
  763. function alternateBooleanVarValue(parent_node, which_function, which_var) {
  764. programa.funcoes[which_function].variaveis[which_var].valor = !programa.funcoes[which_function].variaveis[which_var].valor;
  765. renderAlgorithm();
  766. }
  767. var opened_name_value_vector_global_ = false;
  768. var opened_input_value_vector_global_ = null;
  769. var sequence_name_opened_value_vector_global_;
  770. function enableGlobalVectorValueUpdate(parent_node, which_parameter, column_index) {
  771. if (opened_name_value_vector_global_) {
  772. $(opened_input_value_vector_global_).focus();
  773. return;
  774. }
  775. opened_name_value_vector_global_ = true;
  776. sequence_name_opened_value_vector_global_ = which_parameter;
  777. $(parent_node).find('.span_value_variable').text('');
  778. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  779. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  780. + programa.globais[which_parameter].valor[column_index].toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  781. } else {
  782. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  783. + programa.globais[which_parameter].valor[column_index] + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  784. }
  785. $('.width-dynamic').on('input', function() {
  786. var inputWidth = $(this).textWidth()+10;
  787. opened_input_value_vector_global_ = this;
  788. $(this).focus();
  789. var tmpStr = $(this).val();
  790. $(this).val('');
  791. $(this).val(tmpStr);
  792. $(this).css({
  793. width: inputWidth
  794. })
  795. }).trigger('input');
  796. $('.width-dynamic').focusout(function() {
  797. /// update array:
  798. if ($(this).val().trim()) {
  799. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  800. programa.globais[which_parameter].valor[column_index] = parseFloat($(this).val().trim());
  801. } else {
  802. if (programa.globais[which_parameter].tipo == tiposDados.integer) {
  803. programa.globais[which_parameter].valor[column_index] = parseInt($(this).val().trim());
  804. } else {
  805. programa.globais[which_parameter].valor[column_index] = $(this).val().trim();
  806. }
  807. }
  808. }
  809. $(this).remove();
  810. /// update elements:
  811. opened_name_value_vector_global_ = false;
  812. opened_input_value_vector_global_ = false;
  813. renderAlgorithm();
  814. });
  815. $('.width-dynamic').on('keydown', function(e) {
  816. var code = e.keyCode || e.which;
  817. if(code == 13) {
  818. if ($(this).val().trim()) {
  819. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  820. programa.globais[which_parameter].valor[column_index] = parseFloat($(this).val().trim());
  821. } else {
  822. if (programa.globais[which_parameter].tipo == tiposDados.integer) {
  823. programa.globais[which_parameter].valor[column_index] = parseInt($(this).val().trim());
  824. } else {
  825. programa.globais[which_parameter].valor[column_index] = $(this).val().trim();
  826. }
  827. }
  828. }
  829. $(this).remove();
  830. /// update elements:
  831. opened_name_value_vector_global_ = false;
  832. opened_input_value_vector_global_ = false;
  833. renderAlgorithm();
  834. }
  835. if(code == 27) {
  836. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  837. $(parent_node).find('.span_value_variable').text(programa.globais[which_parameter].valor[column_index].toFixed(1));
  838. } else {
  839. $(parent_node).find('.span_value_variable').text(programa.globais[which_parameter].valor[column_index]);
  840. }
  841. $(this).remove();
  842. /// update elements:
  843. opened_name_value_vector_global_ = false;
  844. opened_input_value_vector_global_ = false;
  845. }
  846. });
  847. }
  848. var opened_name_value_vector_variable = false;
  849. var opened_input_value_vector_variable = null;
  850. var sequence_name_opened_value_vector_variable;
  851. var sequence_function_opened_value_vector_variable;
  852. function enableVarVectorValueUpdate(parent_node, which_function, which_parameter, column_index) {
  853. if (opened_name_value_vector_variable) {
  854. $(opened_input_value_vector_variable).focus();
  855. return;
  856. }
  857. opened_name_value_vector_variable = true;
  858. sequence_name_opened_value_vector_variable = which_parameter;
  859. sequence_function_opened_value_vector_variable = which_function;
  860. $(parent_node).find('.span_value_variable').text('');
  861. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  862. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  863. + programa.funcoes[which_function].variaveis[which_parameter].valor[column_index].toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  864. } else {
  865. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  866. + programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  867. }
  868. $('.width-dynamic').on('input', function() {
  869. var inputWidth = $(this).textWidth()+10;
  870. opened_input_value_vector_variable = this;
  871. $(this).focus();
  872. var tmpStr = $(this).val();
  873. $(this).val('');
  874. $(this).val(tmpStr);
  875. $(this).css({
  876. width: inputWidth
  877. })
  878. }).trigger('input');
  879. $('.width-dynamic').focusout(function() {
  880. /// update array:
  881. if ($(this).val().trim()) {
  882. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  883. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseFloat($(this).val().trim());
  884. } else {
  885. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  886. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseInt($(this).val().trim());
  887. } else {
  888. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = $(this).val().trim();
  889. }
  890. }
  891. }
  892. $(this).remove();
  893. /// update elements:
  894. opened_name_value_vector_variable = false;
  895. opened_input_value_vector_variable = false;
  896. renderAlgorithm();
  897. });
  898. $('.width-dynamic').on('keydown', function(e) {
  899. var code = e.keyCode || e.which;
  900. if(code == 13) {
  901. if ($(this).val().trim()) {
  902. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  903. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseFloat($(this).val().trim());
  904. } else {
  905. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  906. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = parseInt($(this).val().trim());
  907. } else {
  908. programa.funcoes[which_function].variaveis[which_parameter].valor[column_index] = $(this).val().trim();
  909. }
  910. }
  911. }
  912. $(this).remove();
  913. /// update elements:
  914. opened_name_value_vector_variable = false;
  915. opened_input_value_vector_variable = false;
  916. renderAlgorithm();
  917. }
  918. if(code == 27) {
  919. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  920. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[column_index].toFixed(1));
  921. } else {
  922. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[column_index]);
  923. }
  924. $(this).remove();
  925. /// update elements:
  926. opened_name_value_vector_variable = false;
  927. opened_input_value_vector_variable = false;
  928. }
  929. });
  930. }
  931. var opened_name_value_matrix_global_v = false;
  932. var opened_input_value_matrix_global_v = null;
  933. var sequence_name_opened_value_matrix_global_v;
  934. function enableGlobalMatrixValueUpdate(parent_node, which_parameter, row_index, column_index) {
  935. if (opened_name_value_matrix_global_v) {
  936. $(opened_input_value_matrix_global_v).focus();
  937. return;
  938. }
  939. opened_name_value_matrix_global_v = true;
  940. sequence_name_opened_value_matrix_global_v = which_parameter;
  941. $(parent_node).find('.span_value_variable').text('');
  942. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  943. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  944. + programa.globais[which_parameter].valor[row_index][column_index].toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  945. } else {
  946. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  947. + programa.globais[which_parameter].valor[row_index][column_index] + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  948. }
  949. $('.width-dynamic').on('input', function() {
  950. var inputWidth = $(this).textWidth()+10;
  951. opened_input_value_matrix_global_v = this;
  952. $(this).focus();
  953. var tmpStr = $(this).val();
  954. $(this).val('');
  955. $(this).val(tmpStr);
  956. $(this).css({
  957. width: inputWidth
  958. })
  959. }).trigger('input');
  960. $('.width-dynamic').focusout(function() {
  961. /// update array:
  962. if ($(this).val().trim()) {
  963. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  964. programa.globais[which_parameter].valor[row_index][column_index] = parseFloat($(this).val().trim());
  965. } else {
  966. if (programa.globais[which_parameter].tipo == tiposDados.integer) {
  967. programa.globais[which_parameter].valor[row_index][column_index] = parseInt($(this).val().trim());
  968. } else {
  969. programa.globais[which_parameter].valor[row_index][column_index] = $(this).val().trim();
  970. }
  971. }
  972. }
  973. $(this).remove();
  974. /// update elements:
  975. opened_name_value_matrix_global_v = false;
  976. opened_input_value_matrix_global_v = false;
  977. renderAlgorithm();
  978. });
  979. $('.width-dynamic').on('keydown', function(e) {
  980. var code = e.keyCode || e.which;
  981. if(code == 13) {
  982. if ($(this).val().trim()) {
  983. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  984. programa.globais[which_parameter].valor[row_index][column_index] = parseFloat($(this).val().trim());
  985. } else {
  986. if (programa.globais[which_parameter].tipo == tiposDados.integer) {
  987. programa.globais[which_parameter].valor[row_index][column_index] = parseInt($(this).val().trim());
  988. } else {
  989. programa.globais[which_parameter].valor[row_index][column_index] = $(this).val().trim();
  990. }
  991. }
  992. }
  993. $(this).remove();
  994. /// update elements:
  995. opened_name_value_matrix_global_v = false;
  996. opened_input_value_matrix_global_v = false;
  997. renderAlgorithm();
  998. }
  999. if(code == 27) {
  1000. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1001. $(parent_node).find('.span_value_variable').text(programa.globais[which_parameter].valor[row_index][column_index].toFixed(1));
  1002. } else {
  1003. $(parent_node).find('.span_value_variable').text(programa.globais[which_parameter].valor[row_index][column_index]);
  1004. }
  1005. $(this).remove();
  1006. /// update elements:
  1007. opened_name_value_matrix_global_v = false;
  1008. opened_input_value_matrix_global_v = false;
  1009. }
  1010. });
  1011. }
  1012. var opened_name_value_matrix_variable = false;
  1013. var opened_input_value_matrix_variable = null;
  1014. var sequence_name_opened_value_matrix_variable;
  1015. var sequence_function_opened_value_matrix_variable;
  1016. function enableVarMatrixValueUpdate(parent_node, which_function, which_parameter, row_index, column_index) {
  1017. if (opened_name_value_matrix_variable) {
  1018. $(opened_input_value_matrix_variable).focus();
  1019. return;
  1020. }
  1021. opened_name_value_matrix_variable = true;
  1022. sequence_name_opened_value_matrix_variable = which_parameter;
  1023. sequence_function_opened_value_matrix_variable = which_function;
  1024. $(parent_node).find('.span_value_variable').text('');
  1025. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1026. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1027. + programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index].toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1028. } else {
  1029. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1030. + programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1031. }
  1032. $('.width-dynamic').on('input', function() {
  1033. var inputWidth = $(this).textWidth()+10;
  1034. opened_input_value_matrix_variable = this;
  1035. $(this).focus();
  1036. var tmpStr = $(this).val();
  1037. $(this).val('');
  1038. $(this).val(tmpStr);
  1039. $(this).css({
  1040. width: inputWidth
  1041. })
  1042. }).trigger('input');
  1043. $('.width-dynamic').focusout(function() {
  1044. /// update array:
  1045. if ($(this).val().trim()) {
  1046. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1047. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseFloat($(this).val().trim());
  1048. } else {
  1049. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  1050. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseInt($(this).val().trim());
  1051. } else {
  1052. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = $(this).val().trim();
  1053. }
  1054. }
  1055. }
  1056. $(this).remove();
  1057. /// update elements:
  1058. opened_name_value_matrix_variable = false;
  1059. opened_input_value_matrix_variable = false;
  1060. renderAlgorithm();
  1061. });
  1062. $('.width-dynamic').on('keydown', function(e) {
  1063. var code = e.keyCode || e.which;
  1064. if(code == 13) {
  1065. if ($(this).val().trim()) {
  1066. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1067. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseFloat($(this).val().trim());
  1068. } else {
  1069. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  1070. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = parseInt($(this).val().trim());
  1071. } else {
  1072. programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index] = $(this).val().trim();
  1073. }
  1074. }
  1075. }
  1076. $(this).remove();
  1077. /// update elements:
  1078. opened_name_value_matrix_variable = false;
  1079. opened_input_value_matrix_variable = false;
  1080. renderAlgorithm();
  1081. }
  1082. if(code == 27) {
  1083. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1084. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index].toFixed(1));
  1085. } else {
  1086. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor[row_index][column_index]);
  1087. }
  1088. $(this).remove();
  1089. /// update elements:
  1090. opened_name_value_matrix_variable = false;
  1091. opened_input_value_matrix_variable = false;
  1092. }
  1093. });
  1094. }
  1095. var opened_name_value_global_var = false;
  1096. var opened_input_value_global_ar = null;
  1097. var sequence_name_opened_value_global_var;
  1098. function enableGlobalValueUpdate(parent_node, which_parameter) {
  1099. if (opened_name_value_global_var) {
  1100. $(opened_input_value_global_ar).focus();
  1101. return;
  1102. }
  1103. opened_name_value_global_var = true;
  1104. sequence_name_opened_value_global_var = which_parameter;
  1105. $(parent_node).find('.span_value_variable').text('');
  1106. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1107. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1108. + programa.globais[which_parameter].valor.toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1109. } else {
  1110. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1111. + programa.globais[which_parameter].valor + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1112. }
  1113. $('.width-dynamic').on('input', function() {
  1114. var inputWidth = $(this).textWidth()+10;
  1115. opened_input_value_global_ar = this;
  1116. $(this).focus();
  1117. var tmpStr = $(this).val();
  1118. $(this).val('');
  1119. $(this).val(tmpStr);
  1120. $(this).css({
  1121. width: inputWidth
  1122. })
  1123. }).trigger('input');
  1124. $('.width-dynamic').focusout(function() {
  1125. /// update array:
  1126. if ($(this).val().trim()) {
  1127. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1128. programa.globais[which_parameter].valor = parseFloat($(this).val().trim());
  1129. } else{
  1130. if (programa.globais[which_parameter].tipo == tiposDados.integer) {
  1131. programa.globais[which_parameter].valor = parseInt($(this).val().trim());
  1132. } else {
  1133. programa.globais[which_parameter].valor = $(this).val().trim();
  1134. }
  1135. }
  1136. }
  1137. $(this).remove();
  1138. /// update elements:
  1139. opened_name_value_global_var = false;
  1140. opened_input_value_global_ar = false;
  1141. renderAlgorithm();
  1142. });
  1143. $('.width-dynamic').on('keydown', function(e) {
  1144. var code = e.keyCode || e.which;
  1145. if(code == 13) {
  1146. if ($(this).val().trim()) {
  1147. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1148. programa.globais[which_parameter].valor = parseFloat($(this).val().trim());
  1149. } else{
  1150. if (programa.globais[which_parameter].tipo == tiposDados.integer) {
  1151. programa.globais[which_parameter].valor = parseInt($(this).val().trim());
  1152. } else {
  1153. programa.globais[which_parameter].valor = $(this).val().trim();
  1154. }
  1155. }
  1156. }
  1157. $(this).remove();
  1158. /// update elements:
  1159. opened_name_value_global_var = false;
  1160. opened_input_value_global_ar = false;
  1161. renderAlgorithm();
  1162. }
  1163. if(code == 27) {
  1164. if (programa.globais[which_parameter].tipo == tiposDados.real) {
  1165. $(parent_node).find('.span_value_variable').text(programa.globais[which_parameter].valor.toFixed(1));
  1166. } else{
  1167. $(parent_node).find('.span_value_variable').text(programa.globais[which_parameter].valor);
  1168. }
  1169. $(this).remove();
  1170. /// update elements:
  1171. opened_name_value_global_var = false;
  1172. opened_input_value_global_ar = false;
  1173. }
  1174. });
  1175. }
  1176. var opened_name_value_variable = false;
  1177. var opened_input_value_variable = null;
  1178. var sequence_name_opened_value_variable;
  1179. var sequence_function_opened_value_variable;
  1180. function enableVarValueUpdate(parent_node, which_function, which_parameter) {
  1181. if (opened_name_value_variable) {
  1182. $(opened_input_value_variable).focus();
  1183. return;
  1184. }
  1185. opened_name_value_variable = true;
  1186. sequence_name_opened_value_variable = which_parameter;
  1187. sequence_function_opened_value_variable = which_function;
  1188. $(parent_node).find('.span_value_variable').text('');
  1189. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1190. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1191. + programa.funcoes[which_function].variaveis[which_parameter].valor.toFixed(1) + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1192. } else {
  1193. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1194. + programa.funcoes[which_function].variaveis[which_parameter].valor + "' />" ).insertBefore($(parent_node).find('.span_value_variable'));
  1195. }
  1196. $('.width-dynamic').on('input', function() {
  1197. var inputWidth = $(this).textWidth()+10;
  1198. opened_input_value_variable = this;
  1199. $(this).focus();
  1200. var tmpStr = $(this).val();
  1201. $(this).val('');
  1202. $(this).val(tmpStr);
  1203. $(this).css({
  1204. width: inputWidth
  1205. })
  1206. }).trigger('input');
  1207. $('.width-dynamic').focusout(function() {
  1208. /// update array:
  1209. if ($(this).val().trim()) {
  1210. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1211. programa.funcoes[which_function].variaveis[which_parameter].valor = parseFloat($(this).val().trim());
  1212. } else{
  1213. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  1214. programa.funcoes[which_function].variaveis[which_parameter].valor = parseInt($(this).val().trim());
  1215. } else {
  1216. programa.funcoes[which_function].variaveis[which_parameter].valor = $(this).val().trim();
  1217. }
  1218. }
  1219. }
  1220. $(this).remove();
  1221. /// update elements:
  1222. opened_name_value_variable = false;
  1223. opened_input_value_variable = false;
  1224. renderAlgorithm();
  1225. });
  1226. $('.width-dynamic').on('keydown', function(e) {
  1227. var code = e.keyCode || e.which;
  1228. if(code == 13) {
  1229. if ($(this).val().trim()) {
  1230. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1231. programa.funcoes[which_function].variaveis[which_parameter].valor = parseFloat($(this).val().trim());
  1232. } else{
  1233. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.integer) {
  1234. programa.funcoes[which_function].variaveis[which_parameter].valor = parseInt($(this).val().trim());
  1235. } else {
  1236. programa.funcoes[which_function].variaveis[which_parameter].valor = $(this).val().trim();
  1237. }
  1238. }
  1239. }
  1240. $(this).remove();
  1241. /// update elements:
  1242. opened_name_value_variable = false;
  1243. opened_input_value_variable = false;
  1244. renderAlgorithm();
  1245. }
  1246. if(code == 27) {
  1247. if (programa.funcoes[which_function].variaveis[which_parameter].tipo == tiposDados.real) {
  1248. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor.toFixed(1));
  1249. } else{
  1250. $(parent_node).find('.span_value_variable').text(programa.funcoes[which_function].variaveis[which_parameter].valor);
  1251. }
  1252. $(this).remove();
  1253. /// update elements:
  1254. opened_name_value_variable = false;
  1255. opened_input_value_variable = false;
  1256. }
  1257. });
  1258. }
  1259. var opened_name_variable = false;
  1260. var opened_input_variable = null;
  1261. var sequence_name_opened_variable;
  1262. var sequence_function_opened_variable;
  1263. function enableNameVariableUpdate(parent_node, which_function, which_parameter) {
  1264. if (opened_name_variable) {
  1265. $(opened_input_variable).focus();
  1266. return;
  1267. }
  1268. opened_name_variable = true;
  1269. sequence_name_opened_variable = which_parameter;
  1270. sequence_function_opened_variable = which_function;
  1271. $(parent_node).find('.span_name_variable').text('');
  1272. $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
  1273. + programa.funcoes[which_function].variaveis[which_parameter].nome + "' />" ).insertBefore($(parent_node).find('.span_name_variable'));
  1274. $('.width-dynamic').on('input', function() {
  1275. var inputWidth = $(this).textWidth()+10;
  1276. opened_input_variable = this;
  1277. $(this).focus();
  1278. var tmpStr = $(this).val();
  1279. $(this).val('');
  1280. $(this).val(tmpStr);
  1281. $(this).css({
  1282. width: inputWidth
  1283. })
  1284. }).trigger('input');
  1285. $('.width-dynamic').focusout(function() {
  1286. /// update array:
  1287. if ($(this).val().trim()) {
  1288. programa.funcoes[which_function].variaveis[which_parameter].nome = $(this).val().trim();
  1289. }
  1290. $(this).remove();
  1291. /// update elements:
  1292. opened_name_variable = false;
  1293. opened_input_variable = false;
  1294. renderAlgorithm();
  1295. });
  1296. $('.width-dynamic').on('keydown', function(e) {
  1297. var code = e.keyCode || e.which;
  1298. if(code == 13) {
  1299. if ($(this).val().trim()) {
  1300. programa.funcoes[which_function].variaveis[which_parameter].nome = $(this).val().trim();
  1301. }
  1302. $(this).remove();
  1303. /// update elements:
  1304. opened_name_variable = false;
  1305. opened_input_variable = false;
  1306. renderAlgorithm();
  1307. }
  1308. if(code == 27) {
  1309. $(parent_node).find('.span_name_variable').text(programa.funcoes[which_function].variaveis[which_parameter].nome);
  1310. $(this).remove();
  1311. /// update elements:
  1312. opened_name_variable = false;
  1313. opened_input_variable = false;
  1314. }
  1315. });
  1316. }
  1317. var opened_name_comment = false;
  1318. var opened_input_comment = null;
  1319. var sequence_name_opened_comment;
  1320. var sequence_function_opened_comment;
  1321. function enableCommentUpdate(parent_node, function_index, is_function_comment, comment_index) {
  1322. if (opened_name_comment) {
  1323. $(opened_input_comment).focus();
  1324. return;
  1325. }
  1326. opened_name_comment = true;
  1327. sequence_name_opened_comment = comment_index;
  1328. sequence_function_opened_comment = function_index;
  1329. $(parent_node).find('.span_comment_text').text('');
  1330. var temp_value = "";
  1331. if (is_function_comment) {
  1332. temp_value = programa.funcoes[function_index].comentario_funcao.texto_comentario;
  1333. } else {
  1334. temp_value = programa.funcoes[function_index].comandos[comment_index].texto_comentario;
  1335. }
  1336. $( "<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'));
  1337. $('.width-dynamic').on('input', function() {
  1338. var inputWidth = $(this).textWidth()+10;
  1339. opened_input_comment = this;
  1340. $(this).focus();
  1341. var tmpStr = $(this).val();
  1342. $(this).val('');
  1343. $(this).val(tmpStr);
  1344. $(this).css({
  1345. width: inputWidth
  1346. })
  1347. }).trigger('input');
  1348. $('.width-dynamic').focusout(function() {
  1349. /// update array:
  1350. if ($(this).val().trim()) {
  1351. var n_value = $(this).val().trim();
  1352. if (is_function_comment) {
  1353. programa.funcoes[function_index].comentario_funcao.texto_comentario = n_value;
  1354. } else {
  1355. temp_value = programa.funcoes[function_index].comandos[comment_index].texto_comentario = n_value;
  1356. }
  1357. }
  1358. $(this).remove();
  1359. /// update elements:
  1360. opened_name_comment = false;
  1361. opened_input_comment = false;
  1362. renderAlgorithm();
  1363. });
  1364. $('.width-dynamic').on('keydown', function(e) {
  1365. var code = e.keyCode || e.which;
  1366. if(code == 13) {
  1367. if ($(this).val().trim()) {
  1368. var n_value = $(this).val().trim();
  1369. if (is_function_comment) {
  1370. programa.funcoes[function_index].comentario_funcao.texto_comentario = n_value;
  1371. } else {
  1372. temp_value = programa.funcoes[function_index].comandos[comment_index].texto_comentario = n_value;
  1373. }
  1374. }
  1375. $(this).remove();
  1376. /// update elements:
  1377. opened_name_comment = false;
  1378. opened_input_comment = false;
  1379. renderAlgorithm();
  1380. }
  1381. if(code == 27) {
  1382. $(parent_node).find('.span_comment_text').text(temp_value);
  1383. $(this).remove();
  1384. /// update elements:
  1385. opened_name_comment = false;
  1386. opened_input_comment = false;
  1387. }
  1388. });
  1389. }
  1390. var opened_name_parameter = false;
  1391. var opened_input_parameter = null;
  1392. var sequence_name_opened_parameter;
  1393. var sequence_function_opened_parameter;
  1394. function enableNameParameterUpdate(parent_node, which_function, which_parameter) {
  1395. if (opened_name_parameter) {
  1396. $(opened_input_parameter).focus();
  1397. return;
  1398. }
  1399. opened_name_parameter = true;
  1400. sequence_name_opened_parameter = which_parameter;
  1401. sequence_function_opened_parameter = which_function;
  1402. $(parent_node).find('.span_name_parameter').text('');
  1403. $( "<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'));
  1404. $('.width-dynamic').on('input', function() {
  1405. var inputWidth = $(this).textWidth()+10;
  1406. opened_input_parameter = this;
  1407. $(this).focus();
  1408. var tmpStr = $(this).val();
  1409. $(this).val('');
  1410. $(this).val(tmpStr);
  1411. $(this).css({
  1412. width: inputWidth
  1413. })
  1414. }).trigger('input');
  1415. $('.width-dynamic').focusout(function() {
  1416. /// update array:
  1417. if ($(this).val().trim()) {
  1418. programa.funcoes[which_function].lista_parametros[which_parameter].nome = $(this).val().trim();
  1419. }
  1420. $(this).remove();
  1421. /// update elements:
  1422. opened_name_parameter = false;
  1423. opened_input_parameter = false;
  1424. renderAlgorithm();
  1425. });
  1426. $('.width-dynamic').on('keydown', function(e) {
  1427. var code = e.keyCode || e.which;
  1428. if(code == 13) {
  1429. if ($(this).val().trim()) {
  1430. programa.funcoes[which_function].lista_parametros[which_parameter].nome = $(this).val().trim();
  1431. }
  1432. $(this).remove();
  1433. /// update elements:
  1434. opened_name_parameter = false;
  1435. opened_input_parameter = false;
  1436. renderAlgorithm();
  1437. }
  1438. if(code == 27) {
  1439. $(parent_node).find('.span_name_parameter').text(programa.funcoes[which_function].lista_parametros[which_parameter].nome);
  1440. $(this).remove();
  1441. /// update elements:
  1442. opened_name_parameter = false;
  1443. opened_input_parameter = false;
  1444. }
  1445. });
  1446. }
  1447. function removeParameter(parent_node, which_function, which_parameter) {
  1448. programa.funcoes[which_function].lista_parametros.splice(which_parameter, 1);
  1449. renderAlgorithm();
  1450. }
  1451. function manageDragableCommands(sequence) {
  1452. var el = document.getElementById('menu_commands_'+sequence);
  1453. var sortable = Sortable.create(el, {
  1454. handle: '.created_element',
  1455. animation: 100,
  1456. draggable: '.item',
  1457. ghostClass: 'ghost',
  1458. group: {
  1459. name: 'commands_area_'+sequence,
  1460. pull: 'clone'
  1461. },
  1462. onEnd: function (evt) {
  1463. updateSequenceFunctionHandler(evt.oldIndex, evt.newIndex);
  1464. }
  1465. });
  1466. }
  1467. function appendFunction(function_obj, sequence) {
  1468. var appender = '<div class="ui secondary segment function_div list-group-item">';
  1469. if (function_obj.comentario_funcao) {
  1470. appender += renderComment(function_obj.comentario_funcao, sequence, true, -1);
  1471. }
  1472. appender += '<span class="glyphicon glyphicon-move move_function" aria-hidden="true"><i class="icon sort alternate vertical"></i></span>';
  1473. 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>')
  1474. + '<button class="ui icon button tiny minimize_function_button" onclick="minimizeFunctionHandler(this.parentNode, '+sequence+')"><i class="icon window minimize"></i></button>';
  1475. appender += '<div class="ui icon buttons add_var_top_button"><div class="ui icon button" onclick="addVariable('+sequence+')"><i class="icon superscript"></i></div>';
  1476. appender += '<div class="ui icon button dropdown" ><i class="icon code"></i> <div class="menu" id="menu_commands_'+sequence+'"> ';
  1477. appender += '<a class="item" data-text="'+tiposComandos.reader+'"><i class="download icon"></i> ' +i18n('text_read_var')+ '</a>'
  1478. + '<a class="item" data-text="'+tiposComandos.writer+'"><i class="upload icon"></i> '+i18n('text_write_var')+'</a>'
  1479. + '<a class="item create_comment" data-text="'+tiposComandos.comment+'"><i class="quote left icon"></i> '+i18n('text_comment')+'</a>'
  1480. + '</div></div></div>';
  1481. appender += '<div class="function_signature_div">'+i18n('function')+' ';
  1482. if (function_obj.eh_principal) {
  1483. 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> '
  1484. + '( <div class="ui large labels parameters_list">';
  1485. } else {
  1486. appender += renderFunctionReturn(function_obj, sequence);
  1487. 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> '
  1488. + '( <i class="ui icon plus square outline add_parameter" onclick="addParameter('+sequence+')"></i> <div class="ui large labels parameters_list">';
  1489. }
  1490. appender += renderFunctionParameters(function_obj, sequence);
  1491. appender += '</div> ) {</div>'
  1492. + (function_obj.esta_oculta ? ' <div class="function_area" style="display: none;"> ' : ' <div class="function_area"> ')
  1493. + '<div class="ui top attached segment variables_list_div">'
  1494. + renderVariables(function_obj, sequence)
  1495. + '</div>'
  1496. + '<div class="ui bottom attached segment commands_list_div"></div>'
  1497. + '<div class="function_close_div">}</div>'
  1498. + '</div>'
  1499. + '</div>';
  1500. $('.all_functions').append(appender);
  1501. manageDragableCommands(sequence);
  1502. }
  1503. function renderComment(comment_obj, function_index, is_function_comment, comment_index) {
  1504. var ret = '';
  1505. ret += '<div class="ui comment"> <i class="ui icon small quote left"></i> <span class="span_comment_text" ondblclick="enableCommentUpdate(this.parentNode, '+function_index+', '
  1506. +is_function_comment+', '+comment_index+')"> ' + comment_obj.texto_comentario + ' </span>';
  1507. ret += '</div>';
  1508. return ret;
  1509. }
  1510. // Essa função imprime os parâmetros e cria os elementos para a sua manipulação
  1511. function renderFunctionParameters(function_obj, sequence) {
  1512. var ret = "";
  1513. if (function_obj.lista_parametros != null) {
  1514. for (var j = 0; j < function_obj.lista_parametros.length; j++) {
  1515. var par_temp = function_obj.lista_parametros[j];
  1516. 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>';
  1517. ret += '<div class="ui dropdown parameter_type seq_'+j+' fun_'+sequence+'">';
  1518. if (par_temp.dimensoes > 0) {
  1519. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+ i18n(tiposDados.vector)+':'+i18n(par_temp.tipo);
  1520. ret += '</div>';
  1521. } else {
  1522. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+i18n(par_temp.tipo)+'</div>';
  1523. }
  1524. ret += '<i class="dropdown icon"></i>'
  1525. + '<div class="menu seq_'+j+' fun_'+sequence+'">';
  1526. var i = 0;
  1527. for (tm in tiposDados) {
  1528. i ++;
  1529. if (i == 1) { continue; }
  1530. if (i == (Object.keys(tiposDados).length)) { break; }
  1531. ret += '<div class="item ' + ((par_temp.tipo == tm && par_temp.dimensoes < 1) ? ' selected ' : '') + ' seq_'+j+' fun_'+sequence+' '+tm+'" >'+i18n(tm)+'</div>';
  1532. }
  1533. i = 0;
  1534. for (tm in tiposDados) {
  1535. i ++;
  1536. if (i == 1) { continue; }
  1537. if (i == (Object.keys(tiposDados).length)) { break; }
  1538. ret += '<div class="item seq_'+j+' '+tm+' fun_'+sequence+' ' + ((par_temp.tipo == tm && par_temp.dimensoes > 0) ? ' selected ' : '') + ' ">'
  1539. + i18n(tiposDados.vector)+':'+i18n(tm)
  1540. + '</div>';
  1541. }
  1542. ret += '</div></div>';
  1543. ret += ' <i class="red icon times remove_parameter" onclick="removeParameter(this.parentNode, '+sequence+', '+j+')"></i></div>';
  1544. }
  1545. }
  1546. return ret;
  1547. }
  1548. // Essa função imprime as variáveis e os recursos para sua manipulação
  1549. function renderVariables(function_obj, sequence) {
  1550. var ret = "";
  1551. if (function_obj.variaveis != null) {
  1552. for (var j = 0; j < function_obj.variaveis.length; j++) {
  1553. var par_temp = function_obj.variaveis[j];
  1554. 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>';
  1555. ret += '<div class="ui dropdown variable_type seq_'+j+' fun_'+sequence+'">';
  1556. if (par_temp.dimensoes > 0) {
  1557. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+ i18n(tiposDados.vector)+':'+i18n(par_temp.tipo);
  1558. for (i = 0; i < par_temp.dimensoes; i ++) {
  1559. ret += ' [ ] ';
  1560. }
  1561. ret += '</div>';
  1562. } else {
  1563. ret += '<div class="text seq_'+j+' fun_'+sequence+'">'+i18n(par_temp.tipo)+'</div>';
  1564. }
  1565. ret += '<i class="dropdown icon"></i>'
  1566. + '<div class="menu seq_'+j+' fun_'+sequence+'">';
  1567. var i = 0;
  1568. for (tm in tiposDados) {
  1569. i ++;
  1570. if (i == 1) { continue; }
  1571. if (i == (Object.keys(tiposDados).length)) { break; }
  1572. ret += '<div class="item ' + (par_temp.tipo == tm ? ' selected ' : '') + ' seq_'+j+' fun_'+sequence+' '+tm+'" >'+i18n(tm)+'</div>';
  1573. }
  1574. i = 0;
  1575. for (tm in tiposDados) {
  1576. i ++;
  1577. if (i == 1) { continue; }
  1578. if (i == (Object.keys(tiposDados).length)) { break; }
  1579. ret += '<div class="item seq_'+j+' fun_'+sequence+'">'
  1580. + '<i class="dropdown icon"></i>'
  1581. + i18n(tiposDados.vector)+':'+i18n(tm)
  1582. + '<div class="menu seq_'+j+' fun_'+sequence+'">'
  1583. + '<div class="item seq_'+j+' fun_'+sequence+' '+tm+'" data-text="'+ i18n(tiposDados.vector)+':'+i18n(tm)+' [ ] ">[ ]</div>'
  1584. + '<div class="item seq_'+j+' fun_'+sequence+' '+tm+'" data-text="'+ i18n(tiposDados.vector)+':'+i18n(tm)+' [ ] [ ] ">[ ] [ ] </div>'
  1585. + '</div>'
  1586. + '</div>';
  1587. }
  1588. ret += '</div></div> = ';
  1589. if (par_temp.dimensoes == 0) {
  1590. if (par_temp.tipo == tiposDados.real) {
  1591. 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> ';
  1592. } else {
  1593. if (par_temp.tipo == tiposDados.boolean) {
  1594. 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> ';
  1595. } else {
  1596. 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> ';
  1597. }
  1598. }
  1599. } else {
  1600. ret += '<table class="tabela_var">';
  1601. if (par_temp.dimensoes == 1) {
  1602. ret += '<tr>';
  1603. if (par_temp.tipo == tiposDados.real) {
  1604. for (var k = 0; k < par_temp.colunas; k++) {
  1605. ret += '<td><span class="span_value_variable" ondblclick="enableVarVectorValueUpdate(this.parentNode, '+sequence+', '+j+', '+k+')" >'+par_temp.valor[k].toFixed(1)+'</span>'+'</td>';
  1606. }
  1607. } else {
  1608. for (var k = 0; k < par_temp.colunas; k++) {
  1609. if (par_temp.tipo == tiposDados.boolean) {
  1610. ret += '<td><span class="span_value_variable" ondblclick="alternateBooleanVarVectorValue(this.parentNode, '+sequence+', '+j+', '+k+')" >'+par_temp.valor[k]+'</span>'+'</td>';
  1611. } else {
  1612. ret += '<td><span class="span_value_variable" ondblclick="enableVarVectorValueUpdate(this.parentNode, '+sequence+', '+j+', '+k+')" >'+par_temp.valor[k]+'</span>'+'</td>';
  1613. }
  1614. }
  1615. }
  1616. ret += '</tr>';
  1617. ret += '</table>';
  1618. ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline" onclick="removeColumnVector('+sequence+', '+j+')"></i>'
  1619. + ' <i class="ui icon plus square outline" onclick="addColumnVector('+sequence+', '+j+')"></i></div>';
  1620. }
  1621. if (par_temp.dimensoes == 2) {
  1622. if (par_temp.tipo == tiposDados.real) {
  1623. for (var l = 0; l < par_temp.linhas; l++) {
  1624. ret += '<tr>';
  1625. for (var k = 0; k < par_temp.colunas; k++) {
  1626. ret += '<td><span class="span_value_variable" ondblclick="enableVarMatrixValueUpdate(this.parentNode, '+sequence+', '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k].toFixed(1)+'</span>'+'</td>';
  1627. }
  1628. ret += '</tr>';
  1629. }
  1630. } else {
  1631. for (var l = 0; l < par_temp.linhas; l++) {
  1632. ret += '<tr>';
  1633. for (var k = 0; k < par_temp.colunas; k++) {
  1634. if (par_temp.tipo == tiposDados.boolean) {
  1635. ret += '<td><span class="span_value_variable" ondblclick="alternateBooleanVarMatrixValue(this.parentNode, '+sequence+', '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k]+'</span>'+'</td>';
  1636. } else {
  1637. ret += '<td><span class="span_value_variable" ondblclick="enableVarMatrixValueUpdate(this.parentNode, '+sequence+', '+j+', '+l+', '+k+')" >'+par_temp.valor[l][k]+'</span>'+'</td>';
  1638. }
  1639. }
  1640. ret += '</tr>';
  1641. }
  1642. }
  1643. if (par_temp.linhas == 0) {
  1644. ret += '<tr><td></td></tr>';
  1645. }
  1646. ret += '<tr><td colspan="'+par_temp.colunas+'" class="tr_manage_lines"><i class="ui icon minus square outline" onclick="removeLineMatrix('+sequence+', '+j+')"></i>'
  1647. + ' <i class="ui icon plus square outline" onclick="addLineMatrix('+sequence+', '+j+')"></i></td></tr>';
  1648. ret += '</table>';
  1649. ret += '<div class="buttons_manage_columns"><i class="ui icon minus square outline" onclick="removeColumnMatrix('+sequence+', '+j+')"></i>'
  1650. + ' <i class="ui icon plus square outline" onclick="addColumnMatrix('+sequence+', '+j+')"></i></div>';
  1651. }
  1652. }
  1653. ret += ' <i class="red icon times remove_parameter" onclick="deleteVariable('+sequence+', '+j+')"></i></div>';
  1654. }
  1655. }
  1656. return ret;
  1657. }
  1658. // Essa função imprime o tipo de retorno da função e cria o menu do tipo 'select' para alteração
  1659. function renderFunctionReturn(function_obj, sequence) {
  1660. var ret = '<div class="ui dropdown function_return seq_'+sequence+'">';
  1661. if (function_obj.dimensoes_retorno > 0) {
  1662. ret += '<div class="text seq_'+sequence+'"">'+ i18n(tiposDados.vector)+':'+i18n(function_obj.tipo_retorno);
  1663. ret += '</div>';
  1664. } else {
  1665. ret += '<div class="text seq_'+sequence+'"">'+i18n(function_obj.tipo_retorno)+'</div>';
  1666. }
  1667. ret += '<i class="dropdown icon"></i>'
  1668. + '<div class="menu seq_'+sequence+'"">';
  1669. var i = 0;
  1670. for (tm in tiposDados) {
  1671. if (i == (Object.keys(tiposDados).length - 1)) { break; }
  1672. ret += '<div class="item ' + ((function_obj.tipo_retorno == tm && function_obj.dimensoes_retorno < 1) ? ' selected ' : '') + ' seq_'+sequence+' '+tm+'" >'+i18n(tm)+'</div>';
  1673. i ++;
  1674. }
  1675. i = 0;
  1676. for (tm in tiposDados) {
  1677. i ++;
  1678. if (i == 1) { continue; }
  1679. if (i == (Object.keys(tiposDados).length)) { break; }
  1680. 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)+' ">'
  1681. + i18n(tiposDados.vector)+':'+i18n(tm)
  1682. + '</div>';
  1683. }
  1684. ret += '</div></div>';
  1685. return ret;
  1686. }
  1687. $.fn.textWidth = function(text, font) {
  1688. if (!$.fn.textWidth.fakeEl) $.fn.textWidth.fakeEl = $('<span>').hide().appendTo(document.body);
  1689. $.fn.textWidth.fakeEl.text(text || this.val() || this.text() || this.attr('placeholder')).css('font', font || this.css('font'));
  1690. return $.fn.textWidth.fakeEl.width();
  1691. };