|
347 | 347 | } else if (obj.objName === 'radio') {
|
348 | 348 | evt.value = obj.checked
|
349 | 349 | evt.widget = 'radio'
|
350 |
| - } else if (obj.objName === 'menu') { |
| 350 | + } else if (obj.objName === 'menu') { |
351 | 351 | evt.value = obj.index
|
352 | 352 | evt.widget = 'menu'
|
353 | 353 | } else if (obj.objName === 'winput') {
|
|
362 | 362 | }
|
363 | 363 |
|
364 | 364 | // attrs are X in {'a': '23X....'} avaiable: none
|
365 |
| -let attrs = {'a':'pos', 'b':'up', 'c':'color', 'd':'trail_color', // don't use single and double quotes; available: comma, but maybe that would cause trouble |
| 365 | +var attrs = {'a':'pos', 'b':'up', 'c':'color', 'd':'trail_color', // don't use single and double quotes; available: comma, but maybe that would cause trouble |
366 | 366 | 'e':'ambient', 'f':'axis', 'g':'size', 'h':'origin', 'i':'textcolor',
|
367 | 367 | 'j':'direction', 'k':'linecolor', 'l':'bumpaxis', 'm':'dot_color',
|
368 | 368 | 'n':'foreground', 'o':'background', 'p':'ray', 'E':'center', '#':'forward', '+':'resizable',
|
|
389 | 389 | '?':'font', '/':'texture'}
|
390 | 390 |
|
391 | 391 | // attrsb are X in {'b': '23X....'}; ran out of easily typable one-character codes
|
392 |
| -let attrsb = {'a':'userzoom', 'b':'userspin', 'c':'range', 'd':'autoscale', 'e':'fov', |
| 392 | +var attrsb = {'a':'userzoom', 'b':'userspin', 'c':'range', 'd':'autoscale', 'e':'fov', |
393 | 393 | 'f':'normal', 'g':'data', 'h':'checked', 'i':'disabled', 'j':'selected',
|
394 | 394 | 'k':'vertical', 'l':'min', 'm':'max', 'n':'step', 'o':'value',
|
395 | 395 | 'p':'left', 'q':'right', 'r':'top', 's':'bottom', 't':'_cloneid',
|
396 | 396 | 'u':'logx', 'v':'logy', 'w':'dot', 'x':'dot_radius',
|
397 | 397 | 'y':'markers', 'z':'legend', 'A':'label','B':'delta', 'C':'marker_color',
|
398 |
| - 'D':'size_units', 'E':'userpan', 'F':'scroll', 'G':'choices', 'H':'depth', |
399 |
| - 'I':'round', 'J':'name', 'K':'offset', 'L':'attach_idx'} |
| 398 | + 'D':'size_units', 'E':'userpan', 'F':'scroll', 'G':'choices', 'H':'depth', 'I':'round'} |
400 | 399 |
|
401 |
| -// methods are X in {'m': '23X....'} available: u |
402 |
| -let methods = {'a':'select', 'b':'pos', 'c':'start', 'd':'stop', 'f':'clear', // unused eghijklmnopvxyzCDFAB |
| 400 | +// methods are X in {'m': '23X....'} |
| 401 | +var methods = {'a':'select', 'b':'pos', 'c':'start', 'd':'stop', 'f':'clear', // unused eghijklmnopvxyzCDFAB |
403 | 402 | 'q':'plot', 's':'add_to_trail',
|
404 |
| - 't':'follow', 'w':'clear_trail', |
| 403 | + 't':'follow', 'u':'_attach_arrow', 'w':'clear_trail', |
405 | 404 | 'G':'bind', 'H':'unbind', 'I':'waitfor', 'J':'pause', 'K':'pick', 'L':'GSprint',
|
406 | 405 | 'M':'delete', 'N':'capture'}
|
407 | 406 |
|
408 |
| -let vecattrs = ['pos', 'up', 'color', 'trail_color', 'axis', 'size', 'origin', |
| 407 | +var vecattrs = ['pos', 'up', 'color', 'trail_color', 'axis', 'size', 'origin', '_attach_arrow', |
409 | 408 | 'direction', 'linecolor', 'bumpaxis', 'dot_color', 'ambient', 'add_to_trail', 'textcolor',
|
410 | 409 | 'foreground', 'background', 'ray', 'ambient', 'center', 'forward', 'normal',
|
411 |
| - 'marker_color', 'offset'] |
| 410 | + 'marker_color'] |
412 | 411 |
|
413 |
| -let textattrs = ['text', 'align', 'caption', 'title', 'title_align', 'xtitle', 'ytitle', 'selected', 'capture', 'name', |
| 412 | +var textattrs = ['text', 'align', 'caption', 'title', 'title_align', 'xtitle', 'ytitle', 'selected', 'capture', |
414 | 413 | 'label', 'append_to_caption', 'append_to_title', 'bind', 'unbind', 'pause', 'GSprint', 'choices']
|
415 | 414 |
|
416 | 415 | // patt gets idx and attr code; vpatt gets x,y,z of a vector
|
417 |
| -const patt = /(\d+)(.)(.*)/ |
418 |
| -const vpatt = /([^,]*),([^,]*),(.*)/ |
419 |
| -const quadpatt = /([^,]*),([^,]*),(.*)/ |
420 |
| -const plotpatt = /([^,]*),([^,]*)/ |
| 416 | +var patt = /(\d+)(.)(.*)/ |
| 417 | +var vpatt = /([^,]*),([^,]*),(.*)/ |
| 418 | +var quadpatt = /([^,]*),([^,]*),(.*)/ |
| 419 | +var plotpatt = /([^,]*),([^,]*)/ |
421 | 420 |
|
422 | 421 | function decode(data) {
|
423 | 422 | "use strict";
|
|
429 | 428 | var ms = []
|
430 | 429 |
|
431 | 430 | if ('attrs' in data) {
|
432 |
| - let c = data['attrs'] |
| 431 | + var c = data['attrs'] |
433 | 432 | for (i=0; i<c.length; i++) { // step through the encoded attributes and methods
|
434 |
| - let d = c[i] |
| 433 | + var d = c[i] |
435 | 434 | // constructor or appendcmd not currently compressed
|
436 |
| - let whichlist = d[0] // 'a' or 'b' or 'm' |
437 |
| - let datatype = (whichlist == 'm') ? 'method' : 'attr' |
| 435 | + var whichlist = d[0] // 'a' or 'b' or 'm' |
| 436 | + var datatype = (whichlist == 'm') ? 'method' : 'attr' |
438 | 437 | s = d.slice(1)
|
439 | 438 | m = s.match(patt)
|
440 | 439 | idx = Number(m[1])
|
|
455 | 454 | vs = [Number(val[1]), Number(val[2]), Number(val[3]), Number(val[4])]
|
456 | 455 | }
|
457 | 456 | } else if (textattrs.indexOf(attr) > -1) {
|
458 |
| - if (attr == 'choices') { // menu choices are wrapped in a list |
459 |
| - val = m[3].slice(2,-2) |
460 |
| - val = val.replace(/'/g, '') // remove quotes |
461 |
| - let s = val.split(',') |
| 457 | + if (attr == 'choices') { // menu choices are wrapped in a list |
| 458 | + val = m[3].slice(1, -1) // remove outer brackets |
| 459 | + val = val.replace(/'/g, '') // remove quotes |
| 460 | + val = val.replace(/, /g, ',') // remove spaces after commas |
| 461 | + let s = val.split(',') |
462 | 462 | val = []
|
463 |
| - for (let a of s) {val.push(a)} |
| 463 | + for (let a of s) { val.push(a) } |
464 | 464 | } else {
|
465 | 465 | // '\n' doesn't survive JSON transmission, so in vpython.py we replace '\n' with '<br>'
|
466 | 466 | val = m[3].replace(/<br>/g, "\n")
|
|
542 | 542 | */
|
543 | 543 |
|
544 | 544 |
|
545 |
| - |
546 | 545 | if (data.cmds !== undefined && data.cmds.length > 0) handle_cmds(data.cmds)
|
547 | 546 | if (data.methods !== undefined && data.methods.length > 0) handle_methods(data.methods)
|
548 | 547 | if (data.attrs !== undefined && data.attrs.length > 0) handle_attrs(data.attrs)
|
|
569 | 568 | var vlst = ['pos', 'color', 'size', 'axis', 'up', 'direction', 'center', 'forward', 'foreground',
|
570 | 569 | 'background', 'ambient', 'linecolor', 'dot_color', 'trail_color', 'textcolor', 'attrval',
|
571 | 570 | 'origin', 'normal', 'bumpaxis','texpos', 'start_face_color', 'end_face_color', 'marker_color',
|
572 |
| - 'start_normal', 'end_normal', 'offset'] |
| 571 | + 'start_normal', 'end_normal'] |
573 | 572 | if ((obj != 'gcurve') && ( obj != 'gdots' ) ) vlst.push( 'size' )
|
574 | 573 | var cfg = {}
|
575 | 574 | var objects = []
|
|
723 | 722 | }
|
724 | 723 | break
|
725 | 724 | }
|
726 |
| - case 'local_light': { |
727 |
| - let g = glowObjs[idx] = local_light(cfg) |
728 |
| - if (cfg.offset !== undefined) { // mocking up attach_light |
729 |
| - g.__obj = glowObjs[cfg.attach_idx] |
730 |
| - g.canvas.attached_lights.push(g) |
731 |
| - } |
732 |
| - break |
733 |
| - } |
| 725 | + case 'local_light': {glowObjs[idx] = local_light(cfg); break} |
734 | 726 | case 'distant_light': {glowObjs[idx] = distant_light(cfg); break}
|
735 | 727 | case 'canvas': {
|
736 | 728 | if ((typeof isjupyterlab_vpython !== 'undefined') && (isjupyterlab_vpython === true)) {
|
|
757 | 749 | // Display frames per second and render time:
|
758 | 750 | //$("<div id='fps'/>").appendTo(glowObjs[idx].title)
|
759 | 751 | }
|
| 752 | + case 'attach_arrow': { |
| 753 | + var attrs = ['pos', 'size', 'axis', 'up', 'color'] |
| 754 | + var o = glowObjs[cfg['obj']] |
| 755 | + delete cfg['obj'] |
| 756 | + var attr = cfg['attr'] |
| 757 | + delete cfg['attr'] |
| 758 | + var val = cfg['attrval'] |
| 759 | + delete cfg['attrval'] |
| 760 | + if (attrs.indexOf(attr) < 0) attr = '_attach_arrow' |
| 761 | + o.attr = val |
| 762 | + glowObjs[idx] = attach_arrow( o, attr, cfg ) |
| 763 | + break |
| 764 | + } |
760 | 765 | case 'attach_trail': {
|
761 | 766 | if ( typeof cfg['_obj'] === 'string' ) {
|
762 | 767 | var o = cfg['_obj'] // the string '_func'
|
|
788 | 793 | break
|
789 | 794 | }
|
790 | 795 | case 'radio': {
|
791 |
| - cfg.canvas = canvas.get_selected() |
792 |
| - cfg = fix_location(cfg) |
793 |
| - delete cfg.canvas |
794 | 796 | cfg.objName = obj
|
795 | 797 | cfg.bind = control_handler
|
| 798 | + cfg = fix_location(cfg) |
796 | 799 | glowObjs[idx] = radio(cfg)
|
797 |
| - // glowObjs[idx].canvas = canvas.get_selected() |
798 | 800 | break
|
799 | 801 | }
|
800 | 802 | case 'button': {
|
|
830 | 832 | async function handle_methods(dmeth) {
|
831 | 833 | "use strict";
|
832 | 834 | //console.log('METHODS')
|
833 |
| - for (let idmeth=0; idmeth<dmeth.length; idmeth++) { // methods; cmd is ['idx':idx, 'attr':method, 'val':val] |
834 |
| - let cmd = dmeth[idmeth] |
835 |
| - let idx = cmd.idx |
836 |
| - let method = cmd.attr |
837 |
| - let val = cmd.val |
838 |
| - let obj = glowObjs[idx] |
| 835 | + for (var idmeth=0; idmeth<dmeth.length; idmeth++) { // methods; cmd is ['idx':idx, 'attr':method, 'val':val] |
| 836 | + var cmd = dmeth[idmeth] |
| 837 | + var idx = cmd.idx |
| 838 | + var method = cmd.attr |
| 839 | + var val = cmd.val |
| 840 | + var obj = glowObjs[idx] |
839 | 841 |
|
840 | 842 | if (method == 'GSprint') {
|
841 | 843 | GSprint(val)
|
|
848 | 850 | glowObjs[idx]['pos'] = val
|
849 | 851 | } else if (method === 'add_to_trail') {
|
850 | 852 | obj['_func'] = val
|
| 853 | + } else if (method === '_attach_arrow') { |
| 854 | + obj.obj._attach_arrow = val |
851 | 855 | } else if (method === 'bind') {
|
852 |
| - let evts = val.split(' ') |
853 |
| - for (let evt in evts) { |
854 |
| - let e = evts[evt] |
| 856 | + var evts = val.split(' ') |
| 857 | + for (var evt in evts) { |
| 858 | + var e = evts[evt] |
855 | 859 | if (binds.indexOf(e) == -1)
|
856 | 860 | throw new Error('There is no error type "'+e+'"')
|
857 | 861 | }
|
858 | 862 | obj.bind(val, process_binding)
|
859 | 863 | } else if (method === 'unbind') {
|
860 |
| - let evts = val.split(' ') |
861 |
| - for (let evt in evts) { |
862 |
| - let e = evts[evt] |
| 864 | + var evts = val.split(' ') |
| 865 | + for (var evt in evts) { |
| 866 | + var e = evts[evt] |
863 | 867 | if (binds.indexOf(e) == -1)
|
864 | 868 | throw new Error('There is no error type "'+e+'"')
|
865 | 869 | }
|
|
899 | 903 | function handle_attrs(dattrs) {
|
900 | 904 | "use strict";
|
901 | 905 | //console.log('ATTRS')
|
902 |
| - for (let idattrs=0; idattrs<dattrs.length; idattrs++) { // attributes; cmd is {'idx':idx, 'attr':attr, 'val':val} |
903 |
| - let cmd = dattrs[idattrs] |
904 |
| - let idx = cmd.idx |
905 |
| - let obj = glowObjs[idx] |
906 |
| - let attr = cmd['attr'] |
907 |
| - let val = cmd['val'] |
908 |
| - let triangle_quad = ['v0', 'v1', 'v2', 'v3'] |
| 906 | + for (var idattrs=0; idattrs<dattrs.length; idattrs++) { // attributes; cmd is {'idx':idx, 'attr':attr, 'val':val} |
| 907 | + var cmd = dattrs[idattrs] |
| 908 | + var idx = cmd.idx |
| 909 | + var obj = glowObjs[idx] |
| 910 | + var attr = cmd['attr'] |
| 911 | + var val = cmd['val'] |
| 912 | + var triangle_quad = ['v0', 'v1', 'v2', 'v3'] |
| 913 | + // vector attrs in attach_arrow have arbitrary names, so check for length 3 array instead |
909 | 914 | if (val instanceof vec) {
|
910 | 915 | if (attr === 'pos' && (obj instanceof points || obj instanceof curve)) {
|
911 |
| - let ptlist = [] |
912 |
| - for (let kk = 0; kk < val.length; kk++) { |
| 916 | + var ptlist = [] |
| 917 | + for (var kk = 0; kk < val.length; kk++) { |
913 | 918 | ptlist.push( val[kk] )
|
914 | 919 | }
|
915 | 920 | obj[attr] = ptlist
|
|
0 commit comments