ivprog-visual-functions-1.0.js 110 KB

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