From b16cef931c7a44d7d5126ade36eb5e8b9c3f92b1 Mon Sep 17 00:00:00 2001 From: Lucio Zambon <lucio.zambon@elettra.eu> Date: Fri, 26 Jul 2024 01:08:36 +0000 Subject: [PATCH] Update panther2d.js --- panther2d.js | 89 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 24 deletions(-) diff --git a/panther2d.js b/panther2d.js index 20def5f..76c1e18 100644 --- a/panther2d.js +++ b/panther2d.js @@ -14,6 +14,7 @@ const panZoomTime = 500; const facilities = ['']; const names = []; + const shrinkedNames = []; const serviceareanames = []; const alias = []; let maxZoom = 230; @@ -40,27 +41,35 @@ $('#tick'+n).attr('y1', ty1); $('#tick'+n).attr('x2', tx2); $('#tick'+n).attr('y2', ty2); + $('#tickLabel'+n).attr('x', 2*tx2-tx1); + $('#tickLabel'+n).attr('y', 2*ty2-ty1); + $('#tickLabel'+n).html(x==cx || distPixel<220? '': pow10 * n / 1000); } function getCursorPosition(main, event) { const rect = main.getBoundingClientRect(); const x = event.clientX - rect.left; const y = event.clientY - rect.top; - // console.log(Math.round(x) + "," + Math.round(y) + "," + zoom); - // $('#stright').val(Math.round((x - panZoomPanther.getPan().x)/zoom * 43.75)); const distPixel = Math.sqrt(Math.pow(x - cx, 2) + Math.pow(y - cy, 2)); - const dist = distPixel/zoom * 43.75; - if (rulerStart) $('#stright').val(Math.round(dist)); + const dist = distPixel / panZoomPanther.getSizes().realZoom; + if (rulerStart) $('#stright').val(Math.round(dist)/1000); const alpha = (Math.atan2(y-cy, x-cx) * 180) / Math.PI; - $('#sr').val(Math.round((x - panZoomPanther.getPan().x)/zoom * 43.75)+' '+(-Math.round((y - panZoomPanther.getPan().y)/zoom * 43.75)) + ' a: ' + alpha); + $('#sr').val(Math.round((x - panZoomPanther.getPan().x)/panZoomPanther.getSizes().realZoom)/1000+' '+(-Math.round((y - panZoomPanther.getPan().y)/panZoomPanther.getSizes().realZoom)/1000) + ' a: ' + alpha); if (rulerStart) { const pow10 = Math.pow(10, Math.round(Math.log10(dist))-1); $('#rulerLine').attr('x2', x); $('#rulerLine').attr('y2', y); - for (let i=1; i<60; i++) { - if (i<dist/1000) setTick(x, y, cx, cy, dist, distPixel, i, pow10); else setTick(x, y, x, y, dist, distPixel, i, pow10); + for (let i=1; i<32; i++) { + if (i<dist/pow10 && distPixel>50) setTick(x, y, cx, cy, dist, distPixel, i, pow10); else setTick(x, y, x, y, dist, distPixel, i, pow10); } } - // stroke-dasharray: 0,50,50,100 + } + function clearRuler() { + $('#rulerLine').attr('x1', cx); + $('#rulerLine').attr('y1', cy); + $('#rulerLine').attr('x2', cx); + $('#rulerLine').attr('y2', cy); + $('#stright').val(''); + for (let i=1; i<32; i++) {setTick(cx, cy, cx, cy, 1, 1, i);} } function initCursorPosition(main, event) { if (rulerStart) { rulerStart = false; return;} @@ -72,15 +81,13 @@ // appendSvg("circle", {id: 'rulerStart', cx: cx, cy: cy, r:8, style:"display: block", fill:"none", stroke:"red","stroke-width":2}); if ($('#rulerLine').length==0) { appendSvg("line", {id: 'rulerLine', x1: cx, y1: cy, x2: cx, y2: cy, style:"display: block", fill:"none", stroke:"yellow","stroke-width":2}); - for (let i=1; i<60; i++) appendSvg("line", {id: 'tick'+i, x1: cx, y1: cy, x2: cx, y2: cy, style:"display: block", fill:"none", stroke:"yellow","stroke-width":2}); + for (let i=1; i<32; i++) { + appendSvg("line", {id: 'tick'+i, x1: cx, y1: cy, x2: cx, y2: cy, style:"display: block", fill:"none", stroke:"yellow","stroke-width":2}); + appendSvg("text", {id: 'tickLabel'+i, x: cx, y: cy, fill:"white", stroke:"#eeeeee","stroke-width":1, "font-family":"Arial", "font-size":12, "font-weight":"bold", "text-anchor": "start"}); + } } else { - $('#rulerLine').attr('x1', cx); - $('#rulerLine').attr('y1', cy); - $('#rulerLine').attr('x2', cx); - $('#rulerLine').attr('y2', cy); - $('#stright').val(''); - for (let i=1; i<60; i++) {setTick(cx, cy, cx, cy, 1, 1, i);} + clearRuler(); } rulerStart = true; } @@ -122,6 +129,10 @@ } // Polyfill replaceAll() if (typeof String.prototype.replaceAll !== 'function') { + String.prototype.replaceAll = function(search, replacement) { + var target = this; + return target.split(search).join(replacement); + }; } // Polyfill for parentNode.replaceChildren() if (typeof Element.prototype.replaceChildren !== 'function') { @@ -155,6 +166,9 @@ if (e.keyCode == 13) findComponent($("#sname").val().toUpperCase().replace('.','_')); // return -1; } + function shrinkName(name) { + return name.replaceAll('FEL0', 'FEL').replaceAll('PS_', 'PS').replaceAll('SIP_', 'SIP').replaceAll('KG0', 'KG').replaceAll('BC0', 'BC').replaceAll('_L0', 'L').replaceAll('_F0', 'F').replaceAll('_0', '').replaceAll('_', ''); + } // if (navigator.userAgent.indexOf('Firefox/63')==-1) {gui.add(params, 'machine', conf.machineList).onChange(function() {toggleMachine(params.machine);});} gui.add(params, 'machine', conf.machineList).onChange(function() {toggleMachine(params.machine);}); gui.add(params, 'search'); @@ -186,7 +200,11 @@ if (name==null) name = document.getElementById('sname').value; for (let i=0; i<alias.length; i++) if (alias[i][1]==name) name = alias[i][0]; document.getElementById('sname').value = name; - if (typeof $('#'+name)[0] == 'undefined') return name+' Not found'; + console.log(name, typeof $('#'+name)[0], shrinkName(name), shrinkedNames.indexOf(shrinkName(name))); + if (typeof $('#'+name)[0] == 'undefined') { + const sindex = shrinkedNames.indexOf(shrinkName(name)); + if (sindex>-1) name = names[sindex]; else return name+' Not found'; + } console.log(name, window.innerWidth/2, $('#'+name)[0].getCTM().e, $('#'+name)[0].getCTM().f); // panZoomPanther.zoomAtPoint(10, {x: window.innerWidth/2 - $('#'+name)[0].getCTM().e, y: window.innerHeight/2 - $('#'+name)[0].getCTM().f}) panZoomPanther.zoom(10); @@ -203,7 +221,7 @@ setTimeout(pinhide, 100, name, $('#'+name).eq(0).attr('transform')); } function pinhide(name, transform) { - console.log(foundAnimate, foundScale); + // console.log(foundAnimate, foundScale); foundAnimate *= foundScale; if (foundAnimate>1.5) foundScale = 0.95; if (foundAnimate<1) {foundScale = 1.05; foundAnimate = 1;} else setTimeout(pinhide, 100, name, transform); @@ -221,6 +239,7 @@ const res = search.join('&'); document.location = document.location.href.split('?')[0]+(res.length? '?'+res: ''); } + let ujiveStarted = false; async function subscribeSpeech() { mylog('subscribeSpeech()', 1, 2); let response = await fetch("./speech/talk.php?read&token="+speechToken); @@ -236,9 +255,15 @@ // Get and show the message let message = await response.text(); mylog('subscribeSpeech()', message); - const msg = findComponent(message); - // return feedback - fetch("./speech/talk.php?readresult="+msg+"&token="+speechToken); + if (message=='ujive') { + if (!ujiveStarted) window.open('../ujive.php?token='+speechToken, '_blank').focus(); + ujiveStarted = true; + } + else { + const msg = findComponent(message); + // return feedback + fetch("./speech/talk.php?readresult="+msg+"&token="+speechToken); + } // Call subscribeSpeech() again to get the next message await subscribeSpeech(); } @@ -266,7 +291,9 @@ for (let i in lattice) { if (i == 'conf') continue; // logic XOR https://stackoverflow.com/questions/2335979/is-there-anyway-to-implement-xor-in-javascript - if ((document.location.search.indexOf('servicearea')==-1) != (i=='servicearea')) initLattice(lattice[i].sections, i); else initSearch(lattice[i].sections, i); + if ((document.location.search.indexOf('servicearea')==-1) != (i=='servicearea')) initLattice(lattice[i].sections, i); else { + if (document.location.search.indexOf('+servicearea')>-1) initLattice(lattice[i].sections, i); else initSearch(lattice[i].sections, i); + } } bpmInit(facilities); if (document.location.search.indexOf('servicearea')>-1) initSearch(lattice.servicearea.sections, 'servicearea'); @@ -276,6 +303,12 @@ gui.add(params, 'gotoAdmin').name('Admin'); params.goto3D = function() {document.location = './panther.php?machine='+params.machine;}; gui.add(params, 'goto3D').name('3D'); if (lattice.conf && lattice.conf.index) initIndex(lattice); + if (document.location.search.indexOf('ruler=')>-1) { + const ruler = document.location.search.split('ruler=')[1].split('&')[0]; + if (lattice[ruler]) { + + } + } } $('.scale').attr('transform', "scale(2)"); // {$('<div><iframe style="width: 100%;height:250px;" src="../misc/gauge.html?dark&r1only=1&r=100&max=360&throttlingPeriod=50&apply=rotate&val='+0+'"></iframe></div>').insertBefore('.function');} @@ -502,9 +535,14 @@ if (comp && comp!=' ' && $('#'+comp)[0]) { const id = extractId(component.name); names.push(id[0]); + shrinkedNames.push(shrinkName(id[0])); if (facility=='servicearea') serviceareanames.push(id[0]); if (component.embedded) { - for (let j=0; j<component.embedded.length; j++) {names.push(component.embedded[j]); alias.push([id[0],component.embedded[j]]);} + for (let j=0; j<component.embedded.length; j++) { + names.push(component.embedded[j]); + shrinkedNames.push(shrinkName(component.embedded[j])); + alias.push([id[0],component.embedded[j]]); + } } } } @@ -550,10 +588,11 @@ else appendLabel(components[i].name, comp+' label '+section+facility, 'none', x, y, beta, components[i].labelReverse); names.push(id[0]); + shrinkedNames.push(shrinkName(id[0])); if (components[i].embedded) { for (let j=0; j<components[i].embedded.length; j++) {names.push(components[i].embedded[j]); alias.push([id[0],components[i].embedded[j]]);} } - if (id[1]) {names.push(id[1]); alias.push(id);} + if (id[1]) {names.push(id[1]); shrinkedNames.push(shrinkName(id[1])); alias.push(id);} if (state) { if (components[i].ps) { for (let pi=0; pi<components[i].ps.length; pi++) { @@ -609,6 +648,7 @@ if (sections[i].bending && sections[i].bending.type) { // console.log('names.push()', sections[i].bending.name); names.push(sections[i].bending.name.replace('.','_')); + shrinkedNames.push(shrinkName(sections[i].bending.name.replace('.','_'))); } if (typeof sections[i].components == 'object') for (let j=0; j<sections[i].components.length; j++) appendSearch(sections[i].components[j], facility); } @@ -739,11 +779,12 @@ // mylog('myPan', p,q); } function myZoom(oldScale, newScale) { + clearRuler(); setUrl('zoom', Math.round(newScale*100)/100); zoom = newScale; if (newScale>2) $('.label').show(); else $('.label').hide(); if (myPanZoomTimer == null && document.location.search.indexOf('&autoPanZoom')==-1) myPanZoomTimer = setTimeout(myPanZoomDelayed, panZoomTime); - // mylog('myZoom', zoom); + mylog('myZoom', zoom); } /* https://github.com/dagrejs/dagre-d3/issues/202 -- GitLab