ivprog-visual-functions-1.0.js 120 KB

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