diff --git a/panther2d.js b/panther2d.js index 9183d135e0a2bf82679e6d9719d2c4bee4165e53..f041eb2b3a686b67ad8a70ce610f82c185cdadfa 100644 --- a/panther2d.js +++ b/panther2d.js @@ -28,6 +28,33 @@ for (let i=0; i<pa.length; i++) {const p = pa[i].split('='); parameters[p[0]] = p[1];} const machineCaseSensitive = document.location.search.indexOf('machine=')>-1? document.location.search.split('machine=')[1].split('&')[0]: 'elettra'; const machine = machineCaseSensitive.toLowerCase(); + + +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)); + $('#sr').val(-Math.round((y - panZoomPanther.getPan().y)/zoom * 43.75)); +} +function initCursorPosition(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) + ","); + main.addEventListener('mousemove', function(e) { + getCursorPosition(main, e); + }); +} +if (document.location.search.indexOf('ruler')>-1) { + $('#ruler').show(); + const main = document.getElementById('main'); + main.addEventListener('mousedown', function(e) { + initCursorPosition(main, e); + }); +} + //https://puma-01.elettra.eu/rchan.php?json&valueOnly&src=srv-tango-srf-01.fcs.elettra.trieste.it:20000/f/access_control/safety/Undulator_access_state -> 5 FEL1, 6 FEL2 if (machine.indexOf('fermi')>-1) { fetch(conf.rchan+'srv-tango-srf-01:20000/f/access_control/safety/Undulator_access_state').then((response) => {return response.json();}).then((fel) => { @@ -378,14 +405,15 @@ function transformLabel(x, y, beta, labelReverse) { if (typeof labelReverse == 'object') return "translate("+rescale(x)+" "+rescale(y)+") rotate("+(beta+labelReverse[0])+") translate("+labelReverse[1]+" "+labelReverse[2]+")"; return labelReverse==180? "translate("+rescale(x)+" "+rescale(y)+") rotate("+(beta-90)+") translate(1800 100)": - "translate("+rescale(x)+" "+rescale(y)+") rotate("+(beta+90)+") translate("+(labelReverse? -250: 250)+" "+(labelReverse? 200: 300)+")"; + //"translate("+rescale(x)+" "+rescale(y)+") rotate("+(beta+90)+") translate("+(labelReverse? -250: 250)+" "+(labelReverse? 200: 300)+")"; + "translate("+rescale(x)+" "+rescale(y)+") rotate("+(beta+90)+") translate("+(labelReverse? -350: 350)+" "+(labelReverse? 100: 200)+")"; } function appendLabel(id, labelclass, display, x, y, beta, labelReverse) { if ((beta+3600)%360 <180 && typeof labelReverse != 'object') labelReverse = [-90, -250, -100]; appendSvg("text", { id: id+'label', class: labelclass, - x:0, y:0, style:"display: "+display, fill:"white", stroke:"#eeeeee","stroke-width":10, "font-family":"Arial", "font-size":200, "font-weight":"bold", + x:0, y:0, style:"display: "+display, fill:"white", stroke:"#eeeeee","stroke-width":5, "font-family":"Arial", "font-size":100, "font-weight":"bold", "text-anchor": (labelReverse? "end": "start"), transform: transformLabel(x, y, beta, labelReverse) }, false, id); @@ -402,7 +430,7 @@ appendSvg("text", { id: id+'label', class: labelclass, - x:0, y:0, style:"display: block", fill:"red", stroke:"pink","stroke-width":10, "font-family":"Arial", "font-size":fontsize, "font-weight":"bold", + x:0, y:0, style:"display: block", fill:"red", stroke:"pink","stroke-width":5, "font-family":"Arial", "font-size":fontsize, "font-weight":"bold", "text-anchor": (labelReverse? "end": "start"), transform: transformLabel(x, y, beta, labelReverse) }, false, id); @@ -441,7 +469,7 @@ const d = Math.sqrt(dx*dx + dy*dy); const beta = 180*Math.atan2(y0-y1, x0-x1)/Math.PI; if (components) for (let i=0; i<components.length; i++) { - const comp = components[i].type.replace('booster', ''); + const comp = components[i].type;//.replace('booster', ''); let x = x0+components[i].position/d*dx; let y = y0+components[i].position/d*dy; if (components[i].offset2d) {x += components[i].offset2d[0]; y += components[i].offset2d[1];} @@ -469,7 +497,8 @@ const section = components[i].name.indexOf('_')>-1? components[i].name.split('_')[1].split('.')[0]+' ': ''; const offset = components[i].type == 'beamlineUp'? "-2100 -3500": "0 -200"; const transform = "translate("+rescale(x)+" "+rescale(y)+") rotate("+(beta+180)+") translate("+offset+")"; - appendSvg("use", {href:"#"+comp, id: id[0], name:components[i].name, class: comp+' '+section+facility, style:"cursor: pointer", transform:transform}, openTooltip); + const compid = comp + (components[i].lenght > 0 && $('#'+comp+'_'+components[i].lenght)[0]? '_'+components[i].lenght: ''); + appendSvg("use", {href:"#"+compid, id: id[0], name:components[i].name, class: comp+' '+section+facility, style:"cursor: pointer", transform:transform}, openTooltip); if (components[i].type == 'label' || components[i].type == 'beamlineDown' || components[i].type == 'beamlineUp') appendLabel2(components[i], section+facility, 'none', x, y, beta, components[i].labelReverse); else @@ -573,7 +602,9 @@ if (alpha>beta && gamma<0) gamma = gamma + 180; if (sections[i].bending && sections[i].bending.type) { const section = sections[i].bending.name.indexOf('_')>-1? sections[i].bending.name.split('_')[1].split('.')[0]+' ': ''; - appendSvg("use", {href:"#"+sections[i].bending.type.replace('dipolefermi','bending'), id:sections[i].bending.name.replace('.','_'), class: 'bending '+section+facility, style:"cursor: pointer", transform:"translate("+rescale(sections[i].start.x)+" "+rescale(sections[i].start.z)+") rotate("+gamma+") translate(-600 -200)"}, openTooltip); + const comp = sections[i].bending.type.replace('dipolefermi','bending'); + const compid = comp + (sections[i].bending.lenght > 0 && $('#'+comp+'_'+sections[i].bending.lenght)[0]? '_'+sections[i].bending.lenght: ''); + appendSvg("use", {href:"#"+compid, id:sections[i].bending.name.replace('.','_'), class: 'bending '+section+facility, style:"cursor: pointer", transform:"translate("+rescale(sections[i].start.x)+" "+rescale(sections[i].start.z)+") rotate("+gamma+") translate(-600 -200)"}, openTooltip); appendLabel(sections[i].bending.name, 'bending '+section+facility, 'block', sections[i].start.x, sections[i].start.z, gamma+180, sections[i].bending.labelReverse); // appendSvg("text", {id:sections[i].bending.name+'label', class: 'bending '+section+facility, x:0, y:0, fill:"white", stroke:"#888888","stroke-width":10, "font-family":"Arial", "font-size":300, "font-weight":"bold", transform:"translate("+rescale(sections[i].start.x)+" "+rescale(sections[i].start.z)+") rotate("+gamma+") translate(-600 -250)"}, false, sections[i].bending.name); }