ivprog-visual-functions-1.0.js 73 KB

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