commands.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. import $ from 'jquery';
  2. import { Types } from './types';
  3. import * as Models from './ivprog_elements';
  4. import { LocalizedStrings } from './../services/localizedStringsService';
  5. import * as GlobalsManagement from './globals';
  6. import * as VariablesManagement from './variables';
  7. import * as CommentsManagement from './commands/comment';
  8. import * as ReadersManagement from './commands/reader';
  9. import * as WritersManagement from './commands/writer';
  10. import * as AttributionsManagement from './commands/attribution';
  11. import * as IftruesManagement from './commands/iftrue';
  12. import * as RepeatNtimesManagement from './commands/repeatNtimes';
  13. import * as WhiletruesManagement from './commands/whiletrue';
  14. import * as DowhiletruesManagement from './commands/dowhiletrue';
  15. import * as SwitchesManagement from './commands/switch';
  16. import * as FunctioncallsManagement from './commands/functioncall';
  17. import * as VariableValueMenuManagement from './commands/variable_value_menu';
  18. var has_element_created_draged = false;
  19. var which_element_is_draged = null;
  20. export function removeCommand (command, function_obj, dom_obj) {
  21. if (function_obj.commands.indexOf(command) > -1) {
  22. function_obj.commands.splice(function_obj.commands.indexOf(command), 1);
  23. return true;
  24. }
  25. // Utilize dois parantNode, pois o primeiro é o div de comandos
  26. if ($(dom_obj[0].parentNode.parentNode).data('command').commands_block.indexOf(command) > -1) {
  27. $(dom_obj[0].parentNode.parentNode).data('command').commands_block.splice
  28. ($(dom_obj[0].parentNode.parentNode).data('command').commands_block.indexOf(command), 1);
  29. return true;
  30. }
  31. return false;
  32. }
  33. export function createFloatingCommand (function_obj, function_container, command_type, mouse_event) {
  34. var floatingObject;
  35. switch (command_type) {
  36. case Models.COMMAND_TYPES.comment:
  37. floatingObject = CommentsManagement.createFloatingCommand();
  38. break;
  39. case Models.COMMAND_TYPES.reader:
  40. floatingObject = ReadersManagement.createFloatingCommand();
  41. break;
  42. case Models.COMMAND_TYPES.writer:
  43. floatingObject = WritersManagement.createFloatingCommand();
  44. break;
  45. case Models.COMMAND_TYPES.attribution:
  46. floatingObject = AttributionsManagement.createFloatingCommand();
  47. break;
  48. case Models.COMMAND_TYPES.iftrue:
  49. floatingObject = IftruesManagement.createFloatingCommand();
  50. break;
  51. case Models.COMMAND_TYPES.repeatNtimes:
  52. floatingObject = RepeatNtimesManagement.createFloatingCommand();
  53. break;
  54. case Models.COMMAND_TYPES.whiletrue:
  55. floatingObject = WhiletruesManagement.createFloatingCommand();
  56. break;
  57. case Models.COMMAND_TYPES.dowhiletrue:
  58. floatingObject = DowhiletruesManagement.createFloatingCommand();
  59. break;
  60. case Models.COMMAND_TYPES.switch:
  61. floatingObject = SwitchesManagement.createFloatingCommand();
  62. break;
  63. case Models.COMMAND_TYPES.functioncall:
  64. floatingObject = FunctioncallsManagement.createFloatingCommand();
  65. break;
  66. }
  67. floatingObject.draggable().appendTo("body");
  68. floatingObject.mouseup(function(evt) {
  69. manageCommand(function_obj, function_container, evt, command_type);
  70. });
  71. floatingObject.css("position", "absolute");
  72. mouse_event.type = "mousedown.draggable";
  73. mouse_event.target = floatingObject[0];
  74. floatingObject.css("left", mouse_event.pageX - 15);
  75. floatingObject.css("top", mouse_event.pageY - 15);
  76. floatingObject.trigger(mouse_event);
  77. }
  78. // before_after_inside: 1 -> before, 2 -> after, 3 -> inside
  79. export function renderCommand (command, element_reference, before_after_inside, function_obj) {
  80. var createdElement;
  81. switch (command.type) {
  82. case Models.COMMAND_TYPES.comment:
  83. createdElement = CommentsManagement.renderCommand(command, function_obj);
  84. break;
  85. case Models.COMMAND_TYPES.reader:
  86. createdElement = ReadersManagement.renderCommand(command, function_obj);
  87. break;
  88. case Models.COMMAND_TYPES.writer:
  89. createdElement = WritersManagement.renderCommand(command, function_obj);
  90. break;
  91. case Models.COMMAND_TYPES.attribution:
  92. createdElement = AttributionsManagement.renderCommand(command, function_obj);
  93. break;
  94. case Models.COMMAND_TYPES.functioncall:
  95. createdElement = FunctioncallsManagement.renderCommand(command, function_obj);
  96. break;
  97. case Models.COMMAND_TYPES.iftrue:
  98. createdElement = IftruesManagement.renderCommand(command, function_obj);
  99. break;
  100. case Models.COMMAND_TYPES.repeatNtimes:
  101. createdElement = RepeatNtimesManagement.renderCommand(command, function_obj);
  102. break;
  103. case Models.COMMAND_TYPES.whiletrue:
  104. createdElement = WhiletruesManagement.renderCommand(command, function_obj);
  105. break;
  106. case Models.COMMAND_TYPES.dowhiletrue:
  107. createdElement = DowhiletruesManagement.renderCommand(command, function_obj);
  108. break;
  109. case Models.COMMAND_TYPES.switch:
  110. createdElement = SwitchesManagement.renderCommand(command, function_obj);
  111. break;
  112. }
  113. switch (before_after_inside) {
  114. case 1:
  115. createdElement.insertBefore(element_reference);
  116. break;
  117. case 2:
  118. createdElement.insertAfter(element_reference);
  119. break;
  120. case 3:
  121. element_reference.append(createdElement);
  122. break;
  123. }
  124. }
  125. export function genericCreateCommand (command_type) {
  126. switch (command_type) {
  127. case Models.COMMAND_TYPES.comment:
  128. return new Models.Comment(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_value, LocalizedStrings.getUI('text_comment'), null, null, false));
  129. case Models.COMMAND_TYPES.reader:
  130. return new Models.Reader(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_variable, null, null, null, false));
  131. case Models.COMMAND_TYPES.writer:
  132. return new Models.Writer([new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true)]);
  133. case Models.COMMAND_TYPES.attribution:
  134. var root_node = new Models.ExpressionNode(null, new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true),
  135. null, null);
  136. return new Models.Attribution(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_variable, null, null, null, false), [root_node]);
  137. case Models.COMMAND_TYPES.functioncall:
  138. return new Models.FunctionCall(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_function, null, null, null, false), null);
  139. case Models.COMMAND_TYPES.iftrue:
  140. return new Models.IfTrue(null, null, null);
  141. case Models.COMMAND_TYPES.repeatNtimes:
  142. return new Models.RepeatNTimes(null, null, null, null);
  143. case Models.COMMAND_TYPES.whiletrue:
  144. return new Models.WhileTrue(null, null);
  145. case Models.COMMAND_TYPES.dowhiletrue:
  146. return new Models.DoWhileTrue(null, null);
  147. case Models.COMMAND_TYPES.switch:
  148. return new Models.Switch(null, null, null);
  149. }
  150. }
  151. function manageCommand (function_obj, function_container, event, command_type) {
  152. $( ".created_element" ).each(function( index ) {
  153. $(this).remove();
  154. });
  155. var el = $(document.elementFromPoint(event.clientX, event.clientY));
  156. console.log('soltou no: ');
  157. console.log(el);
  158. console.log(el.data('fun'));
  159. // Primeiro verificar se ele soltou no espaço da função correta:
  160. var hier = el.parentsUntil(".all_functions");
  161. var esta_correto = false;
  162. var esta_na_div_correta = false;
  163. if (el.hasClass("commands_list_div")) {
  164. esta_na_div_correta = true;
  165. }
  166. for (var i = 0; i < hier.length; i++) {
  167. var temp = $(hier[i]);
  168. if (temp.hasClass("commands_list_div")) {
  169. esta_na_div_correta = true;
  170. }
  171. if (temp.data('fun') == function_obj) {
  172. esta_correto = true;
  173. break;
  174. }
  175. }
  176. if (!esta_correto) {
  177. has_element_created_draged = false;
  178. which_element_is_draged = null;
  179. return;
  180. } else {
  181. if (!esta_na_div_correta) {
  182. has_element_created_draged = false;
  183. which_element_is_draged = null;
  184. return;
  185. }
  186. }
  187. // Agora é descobrir qual o escopo para adicionar o comando:
  188. // Se o elemento clicado possuir o atributo "fun", então, é direto na div dos comandos:
  189. if (typeof el.data('fun') !== 'undefined') {
  190. // Se a lista de comandos estiver vazia, então é o primeiro.
  191. // Portanto, ele deve soltar o elemento obrigatoriamente no objeto vazio
  192. if ((el.data('fun').commands == null) || (el.data('fun').commands.length == 0)) {
  193. // pode adicionar
  194. el.data('fun').commands = [];
  195. var new_cmd = genericCreateCommand(command_type);
  196. el.data('fun').commands.push(new_cmd);
  197. renderCommand(new_cmd, $(function_container).find('.commands_list_div'), 3, function_obj);
  198. } else { // Entra nesse else, caso já existam outros comandos no bloco:
  199. findNearbyCommandToAddInFunctionScope(el, event, $(function_container).find('.commands_list_div'), function_obj, command_type);
  200. }
  201. } else {
  202. console.log("soltou em um comando");
  203. // descobrir em qual comando ele soltou:
  204. var hier_find = el.parentsUntil(".commands_list_div");
  205. var hierarquia_bottom_up = [];
  206. if (typeof el.data('command') !== 'undefined') {
  207. hierarquia_bottom_up.push(el.data('command'));
  208. }
  209. for (var i = 0; i < hier_find.length; i++) {
  210. if (typeof $(hier_find[i]).data('command') !== 'undefined') {
  211. hierarquia_bottom_up.push($(hier_find[i]).data('command'));
  212. }
  213. }
  214. console.log("comando em que soltou: ");
  215. console.log(hierarquia_bottom_up[0]);
  216. console.log("hierarquia de baixo para cima na árvore, de onde ele soltou: ");
  217. for (var i = 0; i < hierarquia_bottom_up.length; i++) {
  218. console.log(hierarquia_bottom_up[i]);
  219. }
  220. // se a hierarquia possuir apenas um elemento, então está na raiz dos comandos:
  221. if (hierarquia_bottom_up.length == 1) {
  222. var sub_elemento = false;
  223. for (var i = 0; i < hier_find.length; i++) {
  224. if (typeof $(hier_find[i]).data('command') !== 'undefined') {
  225. findBeforeOrAfterCommandToAdd(hier_find[i], event, function_obj, command_type);
  226. sub_elemento = true;
  227. break;
  228. }
  229. }
  230. if (!sub_elemento) {
  231. findBeforeOrAfterCommandToAdd(el[0], event, function_obj, command_type);
  232. }
  233. } else {
  234. // caso exista mais de um elemento na hierarquia:
  235. if (typeof $(el).data('command') !== 'undefined') {
  236. console.log("PPP1");
  237. insertCommandInBlockHierar(el[0], event, function_obj, command_type, hier_find, hierarquia_bottom_up);
  238. } else {
  239. var sub_elemento = false;
  240. for (var i = 0; i < hier_find.length; i++) {
  241. if (typeof $(hier_find[i]).data('command') !== 'undefined') {
  242. insertCommandInBlockHierar(hier_find[i], event, function_obj, command_type, hier_find, hierarquia_bottom_up);
  243. sub_elemento = true;
  244. break;
  245. }
  246. }
  247. }
  248. }
  249. }
  250. has_element_created_draged = false;
  251. which_element_is_draged = null;
  252. }
  253. function insertCommandInBlockHierar (el, event, function_obj, command_type, hier_dom, hier_obj) {
  254. var el_jq = $(el);
  255. var command_parent = el_jq.data('command');
  256. if ((el_jq.data('command').type == Models.COMMAND_TYPES.repeatNtimes) ||
  257. (el_jq.data('command').type == Models.COMMAND_TYPES.whiletrue) ||
  258. (el_jq.data('command').type == Models.COMMAND_TYPES.dowhiletrue) ||
  259. (el_jq.data('command').type == Models.COMMAND_TYPES.iftrue) ||
  260. (el_jq.data('command').type == Models.COMMAND_TYPES.switch) ) {
  261. if ((el_jq.data('command').type == Models.COMMAND_TYPES.repeatNtimes) ||
  262. (el_jq.data('command').type == Models.COMMAND_TYPES.whiletrue) ||
  263. (el_jq.data('command').type == Models.COMMAND_TYPES.dowhiletrue) ) {
  264. // Se não tiver outro comando ainda no bloco, só adiciona:
  265. if (command_parent.commands_block == null || command_parent.commands_block.length == 0) {
  266. command_parent.commands_block = [];
  267. var recentComand = genericCreateCommand(command_type);
  268. command_parent.commands_block.push(recentComand);
  269. renderCommand(recentComand, el_jq.find('.block_commands'), 3, function_obj);
  270. } else { // Se já tem algum comando no bloco:
  271. findNearbyCommandToAddInBlockScope(el, event, el, function_obj, command_type, command_parent);
  272. }
  273. } else {
  274. // QUANDO FOR BLOCO DO TIPO IF OU SWITCH/CASE:
  275. }
  276. } else {
  277. // entra neste bloco, se soltou o comando sobre outro comando dentro de um subbloco:
  278. findBeforeOrAfterCommandToAddInsertBlock(el, event, function_obj, command_type);
  279. }
  280. }
  281. function findNearbyCommandToAddInBlockScope (el, event, node_list_commands, function_obj, command_type, command_parent) {
  282. var all_sub = $(node_list_commands).find('div.command_container');
  283. var menor_distancia = 999999999;
  284. var elemento_menor_distancia = null;
  285. var antes = true;
  286. var t_bot;
  287. var t_top;
  288. // Descobrindo o elemento mais próximo:
  289. for (var i = 0; i < all_sub.length; i++) {
  290. t_top = all_sub[i].getBoundingClientRect().top;
  291. t_bot = all_sub[i].getBoundingClientRect().top + all_sub[i].getBoundingClientRect().height;
  292. if ((t_top - event.clientY) < menor_distancia) {
  293. menor_distancia = event.clientY - t_top;
  294. elemento_menor_distancia = all_sub[i];
  295. }
  296. }
  297. var borda_inferior = elemento_menor_distancia.parentNode.getBoundingClientRect().top + elemento_menor_distancia.parentNode.getBoundingClientRect().height;
  298. // Está mais próximo da borda de baixo, ou seja.. inserir por último:
  299. if ((borda_inferior - event.clientY) < menor_distancia) {
  300. var recentComand = genericCreateCommand(command_type);
  301. command_parent.commands_block.push(recentComand);
  302. //
  303. renderCommand(recentComand, node_list_commands, 3, function_obj);
  304. } else {
  305. var recentComand = genericCreateCommand(command_type);
  306. var index = command_parent.commands_block.indexOf($(elemento_menor_distancia).data('command'));
  307. if (index > -1) {
  308. command_parent.commands_block.splice(index, 0, recentComand);
  309. }
  310. renderCommand(recentComand, elemento_menor_distancia, 1, function_obj);
  311. }
  312. }
  313. function findBeforeOrAfterCommandToAddInsertBlock (el, event, function_obj, command_type) {
  314. var el_jq = $(el);
  315. var command_parent = $(el.parentNode.parentNode).data('command');
  316. var command_target = el_jq.data('command');
  317. var menor_distancia = 999999999;
  318. var antes = true;
  319. var t_bot;
  320. var t_top;
  321. t_top = el.getBoundingClientRect().top;
  322. t_bot = el.getBoundingClientRect().top + el.getBoundingClientRect().height;
  323. var d_top = event.clientY - t_top; // distancia topo
  324. var d_bot = t_bot - event.clientY; // distancia baixo
  325. // Está mais próximo da borda de baixo, ou seja.. inserir por último:
  326. if (d_top < d_bot) {
  327. var recentComand = genericCreateCommand(command_type);
  328. var index = command_parent.commands_block.indexOf(command_target);
  329. if (index > -1) {
  330. command_parent.commands_block.splice(index, 0, recentComand);
  331. }
  332. renderCommand(recentComand, el, 1, function_obj);
  333. } else {
  334. var recentComand = genericCreateCommand(command_type);
  335. var index = command_parent.commands_block.indexOf(command_target);
  336. if (index > -1) {
  337. command_parent.commands_block.splice((index + 1), 0, recentComand);
  338. }
  339. renderCommand(recentComand, el, 2, function_obj);
  340. }
  341. }
  342. function insertCommandInBlock (el, event, function_obj, command_type) {
  343. var el_jq = $(el);
  344. var command_parent = el_jq.data('command');
  345. if ((el_jq.data('command').type == Models.COMMAND_TYPES.repeatNtimes) ||
  346. (el_jq.data('command').type == Models.COMMAND_TYPES.whiletrue) ||
  347. (el_jq.data('command').type == Models.COMMAND_TYPES.dowhiletrue) ) {
  348. // Se não tiver outro comando ainda no bloco, só adiciona:
  349. if (command_parent.commands_block == null || command_parent.commands_block.length == 0) {
  350. command_parent.commands_block = [];
  351. var recentComand = genericCreateCommand(command_type);
  352. command_parent.commands_block.push(recentComand);
  353. renderCommand(recentComand, el_jq.find('.block_commands'), 3, function_obj);
  354. } else { // Se já tem algum comando no bloco:
  355. findInBlockCorrectPlace(el, event, function_obj, command_type);
  356. }
  357. } else {
  358. console.log("PPP2");
  359. }
  360. }
  361. function findInBlockCorrectPlace (el, event, function_obj, command_type) {
  362. var el_jq = $(el);
  363. var all_sub = el_jq.find('div.command_container');
  364. var menor_distancia = 999999999;
  365. var elemento_menor_distancia = null;
  366. var antes = true;
  367. var t_bot;
  368. var t_top;
  369. // Descobrindo o elemento mais próximo:
  370. for (var i = 0; i < all_sub.length; i++) {
  371. t_top = all_sub[i].getBoundingClientRect().top;
  372. t_bot = all_sub[i].getBoundingClientRect().top + all_sub[i].getBoundingClientRect().height;
  373. if ((t_top - event.clientY) < menor_distancia) {
  374. menor_distancia = event.clientY - t_top;
  375. elemento_menor_distancia = all_sub[i];
  376. }
  377. }
  378. var borda_inferior = elemento_menor_distancia.parentNode.getBoundingClientRect().top + elemento_menor_distancia.parentNode.getBoundingClientRect().height;
  379. // Está mais próximo da borda de baixo, ou seja.. inserir por último:
  380. if ((borda_inferior - event.clientY) < menor_distancia) {
  381. var recentComand = genericCreateCommand(command_type);
  382. var command_parent = el_jq.data('command');
  383. command_parent.commands_block.push(recentComand);
  384. renderCommand(recentComand, $(el_jq.find('.block_commands')[0]), 3, function_obj);
  385. } else {
  386. var recentComand = genericCreateCommand(command_type);
  387. var command_parent = el_jq.data('command');
  388. var index = command_parent.commands_block.indexOf($(elemento_menor_distancia).data('command'));
  389. if (index > -1) {
  390. command_parent.commands_block.splice(index, 0, recentComand);
  391. renderCommand(recentComand, elemento_menor_distancia, 1, function_obj);
  392. }
  393. }
  394. }
  395. function findBeforeOrAfterCommandToAdd (el, event, function_obj, command_type) {
  396. switch ($(el).data('command').type) {
  397. case Models.COMMAND_TYPES.iftrue:
  398. case Models.COMMAND_TYPES.switch:
  399. case Models.COMMAND_TYPES.repeatNtimes:
  400. case Models.COMMAND_TYPES.whiletrue:
  401. case Models.COMMAND_TYPES.dowhiletrue:
  402. insertCommandInBlock(el, event, function_obj, command_type);
  403. return;
  404. }
  405. var menor_distancia = 999999999;
  406. var antes = true;
  407. var t_bot;
  408. var t_top;
  409. t_top = el.getBoundingClientRect().top;
  410. t_bot = el.getBoundingClientRect().top + el.getBoundingClientRect().height;
  411. var d_top = event.clientY - t_top; // distancia topo
  412. var d_bot = t_bot - event.clientY; // distancia baixo
  413. // Está mais próximo da borda de baixo, ou seja.. inserir por último:
  414. if (d_top < d_bot) {
  415. var recentComand = genericCreateCommand(command_type);
  416. var index = function_obj.commands.indexOf($(el).data('command'));
  417. if (index > -1) {
  418. function_obj.commands.splice(index, 0, recentComand);
  419. }
  420. renderCommand(recentComand, el, 1, function_obj);
  421. } else {
  422. var recentComand = genericCreateCommand(command_type);
  423. var index = function_obj.commands.indexOf($(el).data('command'));
  424. if (index > -1) {
  425. function_obj.commands.splice((index + 1), 0, recentComand);
  426. }
  427. renderCommand(recentComand, el, 2, function_obj);
  428. }
  429. }
  430. function findNearbyCommandToAddInFunctionScope (el, event, node_list_commands, function_obj, command_type) {
  431. var all_sub = $(node_list_commands).find('div.command_container');
  432. var menor_distancia = 999999999;
  433. var elemento_menor_distancia = null;
  434. var antes = true;
  435. var t_bot;
  436. var t_top;
  437. // Descobrindo o elemento mais próximo:
  438. for (var i = 0; i < all_sub.length; i++) {
  439. t_top = all_sub[i].getBoundingClientRect().top;
  440. t_bot = all_sub[i].getBoundingClientRect().top + all_sub[i].getBoundingClientRect().height;
  441. if ((t_top - event.clientY) < menor_distancia) {
  442. menor_distancia = event.clientY - t_top;
  443. elemento_menor_distancia = all_sub[i];
  444. }
  445. }
  446. var borda_inferior = elemento_menor_distancia.parentNode.getBoundingClientRect().top + elemento_menor_distancia.parentNode.getBoundingClientRect().height;
  447. // Está mais próximo da borda de baixo, ou seja.. inserir por último:
  448. if ((borda_inferior - event.clientY) < menor_distancia) {
  449. var recentComand = genericCreateCommand(command_type);
  450. function_obj.commands.push(recentComand);
  451. //
  452. renderCommand(recentComand, node_list_commands, 3, function_obj);
  453. } else {
  454. var recentComand = genericCreateCommand(command_type);
  455. var index = function_obj.commands.indexOf($(elemento_menor_distancia).data('command'));
  456. if (index > -1) {
  457. function_obj.commands.splice(index, 0, recentComand);
  458. }
  459. renderCommand(recentComand, elemento_menor_distancia, 1, function_obj);
  460. }
  461. }