Skip to content
Snippets Groups Projects
Commit 77110902 authored by Lucio Zambon's avatar Lucio Zambon
Browse files

Update gof2d.js

parent fa44b0b8
No related branches found
No related tags found
No related merge requests found
......@@ -2,9 +2,18 @@
// sr/feedback/profile_s/CorrHorFast
// sr/feedback/profile_s->GetSrCorrNames
// sr/feedback/profile_s/OrbitHorFast
// ./bpm.php?machine=elettra&src&sr
let gofFactorsHor, gofFactorsVer;
let gofSt, gofFps, gofDataTs, gPos;
let gofMaxFps = 25;
function lilclick(par) {
if (par!=123) setTimeout(lilclick, 500, 123);
gPos = $("#fps").children().eq(1).children()[0].getBoundingClientRect();
console.log('lilclick', gPos);
$('#fpsr').css('left', gPos.left);
$('#fpsr').css('top', gPos.top+gPos.height-3);
}
$(".lil-gui.root").click(lilclick);
function getParam(param, defaultValue) {
if (document.location.search.indexOf(param+'=')>-1) return document.location.search.split(param+'=')[1].split('&')[0];
return defaultValue;
......@@ -65,7 +74,7 @@
$("#sr_gofreference"+dir).attr('visibility', "hidden");
}
}
function elapseHor(step, up) {
function gofElapseHor(step, up) {
// console.log('elapseHor()',step,gofScaleHor.$fill.style.width, (gofScaleSteps-step)/gofScaleSteps*90);
if (up) {
if (step<gofScaleSteps) {const pc = Math.round((gofScaleSteps-step)/gofScaleSteps*90); gofScaleHor.$fill.style.width=pc+"%";setTimeout(elapseHor, 20, step+1, up); return;}
......@@ -84,7 +93,7 @@
gofScaleHor.$fill.style.width="10%";
gofScaleHor.$fill.style.borderColor = '#2cc9ff';
}
function elapseVer(step, up) {
function gofElapseVer(step, up) {
if (up) {
if (step<gofScaleSteps) {const pc = Math.round((gofScaleSteps-step)/gofScaleSteps*90); gofScaleVer.$fill.style.width=pc+"%";setTimeout(elapseVer, 20, step+1, up); return;}
const buf = gofScaleVer._max;
......@@ -102,27 +111,27 @@
gofScaleVer.$fill.style.width="10%";
gofScaleVer.$fill.style.borderColor = '#2cc9ff';
}
function finishHor() {
// console.log('finishHor()', gofScaleHor.$fill.style.width);
function gofFinishHor() {
// console.log('gofFinishHor()', gofScaleHor.$fill.style.width);
if (gofScaleHor.$fill.style.width=="100%" || gofScaleHor.$fill.style.width=="0%") {
// gofScaleHor.$fill.style.borderColor = 'yellow';
setTimeout(elapseHor, 200, 1, gofScaleHor.$fill.style.width=="100%");
setTimeout(gofElapseHor, 200, 1, gofScaleHor.$fill.style.width=="100%");
}
}
function finishVer() {
function gofFinishVer() {
if (gofScaleVer.$fill.style.width=="100%" || gofScaleVer.$fill.style.width=="0%") {
setTimeout(elapseVer, 200, 1, gofScaleVer.$fill.style.width=="100%");
setTimeout(gofElapseVer, 200, 1, gofScaleVer.$fill.style.width=="100%");
}
}
function factorHor(v) {
// console.log('factorHor(v)', v, gofScaleHor.$fill.style.width);
function gofSetfactorHor(v) {
// console.log('gofSetfactorHor(v)', v, gofScaleHor.$fill.style.width);
gofScaleHor.$fill.style.borderColor = (gofScaleHor.$fill.style.width=="100%" || gofScaleHor.$fill.style.width=="0%")? 'yellow': '#2cc9ff';
gofFactorHor = v * 1000;
if (localStorage.getItem('reference'+gof+'hor')!=null) localStorage.setItem('scale'+gof+'hor', gofFactorHor);
rulerScale('');
}
function factorVer(v) {
console.log('factorVer(v)', v, gofScaleVer.$fill.style.width);
function gofSetfactorVer(v) {
console.log('gofSetfactorVer(v)', v, gofScaleVer.$fill.style.width);
gofScaleVer.$fill.style.borderColor = (gofScaleVer.$fill.style.width=="100%" || gofScaleVer.$fill.style.width=="0%")? 'yellow': '#2cc9ff';
gofFactorVer = v * 1000;
if (localStorage.getItem('reference'+gof+'ver')!=null) localStorage.setItem('scale'+gof+'ver', gofFactorVer);
......@@ -146,7 +155,7 @@
$('.gofver').css('display', 'none');
params.gof = document.location.search.indexOf('gof')>-1 && document.location.search.indexOf('=gof')==-1? 'corr': '';
if (document.location.search.indexOf('gof=')>-1) params.gof = document.location.search.split('gof=')[1].split('&')[0];
const options = ['', 'corr'];
const options = ['', 'corr', 'bpm'];
if (options.indexOf(params.gof)==-1) params.gof = 'corr';
gui.add(params, 'gof', options).name('gof H <img id="h" src="red.svg" style="margin-bottom: -4px;">&nbsp;&nbsp;&nbsp;V <img id="v" src="green.svg" style="margin-bottom: -4px;"> ').onChange(function() {gofSwitch(compData, params);});
const maxVer = Math.pow(10, Math.floor(Math.log10(gofFactorVer/1000))+2);
......@@ -162,11 +171,11 @@
gui.add(menuParams, 'ruler').onChange(function() {rulerSwitch();});
guiconf(gui, 'ruler');*/
menuParams['scale H'] = gofFactorHor/1000;
gofScaleHor = gui.add(menuParams, 'scale H', maxVer/100, maxVer, Math.round(maxVer/1000)).onChange(function() {factorHor(menuParams['scale H'], gui);}).onFinishChange(function() {finishHor(gui);});
gofScaleHor = gui.add(menuParams, 'scale H', maxVer/100, maxVer, Math.round(maxVer/1000)).onChange(function() {gofSetfactorHor(menuParams['scale H'], gui);}).onFinishChange(function() {gofFinishHor(gui);});
guiconf(gui, 'scaleh');
$('#scaleh').children().eq(0).css('color','red');
menuParams['scale V'] = gofFactorHor/1000;
gofScaleVer = gui.add(menuParams, 'scale V', maxHor/100, maxHor, Math.round(maxHor/1000)).onChange(function() {factorVer(menuParams['scale V'], gui);}).onFinishChange(function() {finishVer(gui);});
gofScaleVer = gui.add(menuParams, 'scale V', maxHor/100, maxHor, Math.round(maxHor/1000)).onChange(function() {gofSetfactorVer(menuParams['scale V'], gui);}).onFinishChange(function() {gofFinishVer(gui);});
guiconf(gui, 'scalev');
$('#scalev').children().eq(0).css('color','green');
}
......@@ -185,6 +194,45 @@
const b = facilities[f];
if (b!='sr') continue;
console.log('gofMenu() - ', b, lattice[b], conf.gofSrcUrl);
compData[b].bpmMap = [];
fetch('./bpm.php?machine=elettra&src&sr', {cache: "no-store"})
.then((response) => {return response.json();})
.then((gofNaming) => {
console.log('gofBpmNaming', gofNaming, compData[b].bpmMap);
for (let i in gofNaming) {
const name = gofNaming[i];
for (let bl in compData[b].obj) {
if (name==compData[b].obj[bl] || name==compData[b].obj[bl].replace('.','_')) {compData[b].bpmMap[i] = bl;}
}
}
for (let fi in facilities) {
const facility = facilities[fi];
if (facility!='sr') continue;
console.log(fi, facility, compData);
if (facility.length>0 && typeof compData[facility]!='undefined' && compData[facility].obj && compData[facility].obj.length>0) {
console.log('gofBpmInit', facility, compData[facility]);
const dhor = [];
const dver = [];
for (i=0; i<compData[facility].pos.length; i++) {
// if (i>threshold) break;
const dir = compData[facility].dir[i];
const beta = Math.PI*dir/180;
if (threshold<1000) console.log('i', i, 'pos',compData[facility].pos[i], 'dir', dir, beta, Math.cos(beta), Math.sin(beta));
dhor.push((i==0?'M':'L')+
Math.round(compData[facility].pos[i][0] - f*Math.sin(beta)) + ' ' +
Math.round(compData[facility].pos[i][1] + f*Math.cos(beta))
);
dver.push((i==0?'M':'L')+
Math.round(compData[facility].pos[i][0] - f*1.05*Math.sin(beta)) + ' ' +
Math.round(compData[facility].pos[i][1] + f*1.05*Math.cos(beta))
);
}
console.log(dhor);
appendSvg("path", {id:facility+"_gofbpmhor", class: "gofbpmhor trajectory "+facility, visibility:gofVisibility, name:"gofbpmhor", fill: "none", "stroke-width":"150", "stroke":"red", "stroke-opacity":"0.6", d: dhor.join(' ')+(lattice[facility].sections[0].chamber?' Z':'')}, gof_clicked_hor, false, false, '.svg-pan-zoom_viewport');
appendSvg("path", {id:facility+"_gofbpmver", class: "gofbpmver trajectory "+facility, visibility:gofVisibility, name:"gofbpmver", fill: "none", "stroke-width":"150", "stroke":"limegreen", "stroke-opacity":"0.6", d: dver.join(' ')+(lattice[facility].sections[0].chamber?' Z':'')}, gof_clicked_ver, false, false, '.svg-pan-zoom_viewport');
}
}
});
compData[b].corrMap = [];
console.log((conf.gofSrcUrl+'&machine='+machine).replace('?&','?'));
fetch((conf.gofSrcUrl+'&machine='+machine).replace('?&','?'), {cache: "no-store"})
......@@ -258,6 +306,10 @@
$('#'+facility+"_gofhor").attr('visibility', "hidden");
$('#'+facility+"_gofver").attr('visibility', "hidden");
}
if (typeof $('#'+facility+"_gofbpmhor").attr('visibility') != 'undefined') {
$('#'+facility+"_gofbpmhor").attr('visibility', "hidden");
$('#'+facility+"_gofbpmver").attr('visibility', "hidden");
}
}
$('.gofgauge').hide();
$('#fps').hide();
......@@ -273,6 +325,63 @@
gofData.reader.clearInterval();
gofMaxFps = 0;
}
else if (params.gof=='bpm') {
$('#fps').show();
$('#fpsr').show();
$('#scaleh').show();
$('#scalev').show();
$('#trajectoryWidth').show();
$('#ruler').show();
$('#notice').show();
for (let facility in gofData) {
if (typeof $('#'+facility+"_gofbpmhor").attr('visibility') != 'undefined') {
$('#'+facility+"_gofbpmhor").attr('visibility', "visible");
$('#'+facility+"_gofbpmver").attr('visibility', "visible");
}
if (typeof gofData[facility] == 'undefined' || typeof gofData[facility].bpmMap == 'undefined') continue;
gofData.oldIndex = facility;
gofRead(gofData, params);
}
displayer = setInterval(gofDisplay, gofDisplayerPeriod, params);
if (gofTimeout) {
setTimeout(gofRead, gofTimeout, gofData, params);
}
else {
gofData.reader = setInterval(gofRead, gofPeriod, gofData, params);
}
$('.gofhor').css('display', 'block');
$('.gofver').css('display', 'block');
gofFactorHor = localStorage.getItem('scale'+gof+'hor')!=null? localStorage.getItem('scale'+gof+'hor')-0: gofFactorsHor[menuParams.gof]*1000;
gofFactorVer = localStorage.getItem('scale'+gof+'ver')!=null? localStorage.getItem('scale'+gof+'ver')-0: gofFactorsVer[menuParams.gof]*1000;
if (gofScaleType == 'slider') {
const fHor = gofFactorHor/1000;
menuParams['scale H'] = fHor;
const mxHor = Math.pow(10, Math.floor(Math.log10(fHor))+1);
gofScaleHor.max(mxHor);
gofScaleHor.min(mxHor/100);
gofScaleHor.step(mxHor/1000);
gofScaleHor.setValue(fHor);
const fVer = gofFactorVer/1000;
menuParams['scale V'] = fVer;
const mxVer = Math.pow(10, Math.floor(Math.log10(fVer))+1);
gofScaleVer.max(mxVer);
gofScaleVer.min(mxVer/100);
gofScaleVer.step(mxVer/1000);
gofScaleVer.setValue(fVer);
}
else {
document.getElementById("horgauge").contentWindow.maxval = Math.pow(10, Math.floor(Math.log10(gofFactorsHor[params.gof]))+2);
document.getElementById("horgauge").contentWindow.reset();
document.getElementById("horgauge").contentWindow.setVal(gofFactorsHor[params.gof]);
document.getElementById("vergauge").contentWindow.maxval = Math.pow(10, Math.floor(Math.log10(gofFactorsVer[params.gof]))+2);
document.getElementById("vergauge").contentWindow.reset();
document.getElementById("vergauge").contentWindow.setVal(gofFactorsVer[params.gof]);
$('.gofgauge').show();
}
gPos = $("#fps").children().eq(1).children()[0].getBoundingClientRect();
$('#fpsr').css('left', gPos.left);
$('#fpsr').css('top', gPos.top+gPos.height-3);
}
else {
// $('#application').show();
// $('#applicationReference').show();
......@@ -334,7 +443,7 @@
}
}
function gofRender(facility, gb, gof) {
// console.log('gofRender(), val', val, gof, compData[facility]);
// console.log('gofRender(), gb', gb, gof);
gofDataHor = [];
gofDataVer = [];
let refHor, refVer;
......@@ -345,9 +454,11 @@
if (gb[0]) {
const valh = gb[0].split(',');
const valv = gb[1].split(',');
console.log('gofRender(), valh', valh);
for (i=0; i<valh.length; i++) {
if (typeof compData[facility].corrMap[i] == 'undefined') continue;
const j = compData[facility].corrMap[i];
if (gof!='bpm' && typeof compData[facility].corrMap[i] == 'undefined') continue;
if (gof=='bpm' && typeof compData[facility].bpmMap[i] == 'undefined') continue;
const j = gof=='bpm'? compData[facility].bpmMap[i]: compData[facility].corrMap[i];
if (document.location.search.indexOf('pulse=')>-1 && i!=document.location.search.split('pulse=')[1].split('&')[0]) {valh[i] = 0;}
const pos = compData[facility].pos[j];
if (pos==null) continue;
......@@ -366,9 +477,15 @@
Math.round(pos[1] + valVer*gofFactorVer*Math.cos(beta))
);
}
// console.log('Hor', gofDataHor.join(' ')+(lattice[facility].sections[0].chamber?' Z':''));
$('#'+facility+"_gofhor").attr('d', gofDataHor.join(' ')+(lattice[facility].sections[0].chamber?' Z':''));
$('#'+facility+"_gofver").attr('d', gofDataVer.join(' ')+(lattice[facility].sections[0].chamber?' Z':''));
console.log('Hor', gofDataHor.join(' ')+(lattice[facility].sections[0].chamber?' Z':''));
if (gof=='bpm') {
$('#'+facility+"_gofbpmhor").attr('d', gofDataHor.join(' ')+(lattice[facility].sections[0].chamber?' Z':''));
$('#'+facility+"_gofbpmver").attr('d', gofDataVer.join(' ')+(lattice[facility].sections[0].chamber?' Z':''));
}
else {
$('#'+facility+"_gofhor").attr('d', gofDataHor.join(' ')+(lattice[facility].sections[0].chamber?' Z':''));
$('#'+facility+"_gofver").attr('d', gofDataVer.join(' ')+(lattice[facility].sections[0].chamber?' Z':''));
}
}
}
function gofDisplay(params) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment