ivprog-visual-functions-1.0.js 136 KB

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