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

Update bpm2d.js

parent 1881c28b
No related branches found
No related tags found
No related merge requests found
......@@ -32,63 +32,13 @@
});
}
}
function bpmMenuOld(lattice, facilities, params) {
if (document.location.search.indexOf('old')>-1) {bpmMenuOld(lattice, facilities, params); return;}
params.bpm = '';
$('.bpmhor').css('display', 'none');
$('.bpmver').css('display', 'none');
if (document.location.search.indexOf('bpm=')>-1) {params.bpm = document.location.search.split('bpm=')[1].split('&')[0]; bpmSwitch(bpmData, params);}
gui.add(params, 'bpm', facilities).name('bpm 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() {bpmSwitch(bpmData, params);});
for (let f in facilities) {
const b = facilities[f];
if (b=='' || typeof bpmData[b] == 'undefined' || typeof lattice[b].bpm == 'undefined' || typeof lattice[b].bpm.orbitconf == 'undefined') continue;
console.log('bpmMenu() - ',b);
// bpmData[b].datasrc = lattice[b].bpm.orbithor+';'+lattice[b].bpm.orbitver;
bpmData[b].datasrc = lattice[b].bpm.orbithor;
bpmData[b].map = [];
fetch(conf.rchan+lattice[b].bpm.orbitconf)
.then((response) => {return response.json();})
.then((bpmData2) => {
let bpmCounter = 0;
let photoCounter = 0;
for (let i in bpmData2) {
const name = bpmData2[i];
if (name.indexOf(bpmData[b].skip)>-1) continue;
for (let bl in bpmData[b].obj) {
// console.log('b', bl, bpmData[b].obj, bpmData[b].obj[bl]);
if (name==bpmData[b].obj[bl]) {bpmData[b].map[bl] = bpmCounter; bpmCounter++;}
}
}
console.log('bpmMenu(), name', b, bpmData[b], lattice[b]);
});
}
}
function bpmMenuNew(lattice, facilities, params) {
params.bpm = '';
bpmSwitchNew(params);
fetch(conf.bpmSrcUrl)
.then((response) => {return response.json();})
.then((bpmData) => {
let bpmCounter = 0;
let photoCounter = 0;
console.log('bpmMenu(), name', bpmData);
for (let i in bpmData) {
const name = bpmData[i];
if (name.indexOf(conf.bpmSkip)>-1) continue;
for (let bl in bpmData[i].obj) {
console.log('bl', bl, bpmData[i].obj, bpmData[i].obj[bl]);
if (name==bpmData[i].obj[bl]) {bpmData[i].map[bl] = bpmCounter; bpmCounter++;}
}
}
});
}
const threshold = document.location.search.indexOf('threshold=')>-1? document.location.search.split('threshold=')[1].split('&')[0]: 1000;
const f = document.location.search.indexOf('factor=')>-1? document.location.search.split('factor=')[1].split('&')[0]: 3000;
function bpmInit(facilities) {
console.log('bpmData', bpmData);
for (let fi in facilities) {
const facility = facilities[fi];
if (facility.length>0 && bpmData[facility].obj.length>0) {
if (facility.length>0 && typeof bpmData[facility]!='undefined' && bpmData[facility].obj && bpmData[facility].obj.length>0) {
console.log('bpmInit', facility, bpmData[facility]);
const dhor = [];
const dver = [];
......@@ -136,49 +86,10 @@
$("#applicationFrame").height(window.innerHeight);
}
}
function bpmSwitchNew(bpmData, params) {
if (bpmData.reader !== false) clearInterval(bpmData.reader);
bpmData.reader = false;
$('.bpmhor').css('display', 'none');
$('.bpmver').css('display', 'none');
if (params.bpm=='') {
$('#application').hide();
$('#applicationFrame').removeAttr("src");
}
else {
bpmData.oldIndex = params.bpm;
bpmRead(bpmData, params);
$('#'+params.bpm+"_bpmhor").attr('visibility', "visible");
$('#'+params.bpm+"_bpmver").attr('visibility', "visible");
bpmData.reader = setInterval(bpmRead, 300, bpmData, params);
$('#application').show();
$('.bpmhor.'+params.bpm).css('display', 'block');
$('.bpmver.'+params.bpm).css('display', 'block');
$('#applicationFrame').attr("src", "/spa/index.html?s=bpm&src="+params.bpm+(document.location.search.indexOf('demo')>-1? '&demo': ''));
$("#applicationFrame").height(window.innerHeight);
}
}
function bpmRender(facility, val) {
// console.log('bpmRender()',facility, val);
/*
const bpmMaxX = Math.max.apply(null, val.x.map(Math.abs)); // https://stackoverflow.com/questions/29515761/find-absolute-max-value-in-javascript-array
const bpmMaxY = Math.max.apply(null, val.y.map(Math.abs));
let bpmPeakX = (Math.log10(bpmMaxX) + 2) * 5000;
let bpmPeakY = (Math.log10(bpmMaxY) + 2) * 5000;
bpmPeakX = bpmPeakX>20000? 20000: (bpmPeakX<2000? 2000: bpmPeakX);
bpmPeakY = bpmPeakY>20000? 20000: (bpmPeakY<2000? 2000: bpmPeakY);
const bpmFactorX = bpmPeakX/bpmMaxX;
const bpmFactorY = bpmPeakY/bpmMaxY;
/*
console.log('bpmRender(), facility', facility, 'bpmData', bpmData);
const bpmd = facility==''? bpmData: bpmData[facility];
const bpmMax = Math.max.apply(null, bpmd.val.map(Math.abs)); // https://stackoverflow.com/questions/29515761/find-absolute-max-value-in-javascript-array
let bpmPeak = (Math.log10(bpmMax) + 2) * 5000;
bpmPeak = bpmPeak>20000? 20000: (bpmPeak<2000? 2000: bpmPeak);
*/
const dhor = [];
const dver = [];
const bpmFactor = conf.bpmFactor[facility]*1000;
for (i=0; i<val.Hor.length; i++) {
// if (i>threshold) break;
const pos = bpmData[facility].pos[i];
......@@ -186,12 +97,12 @@
const beta = Math.PI*bpmData[facility].dir[i]/180;
// console.log('i', i, 'pos',pos, 'dir', bpmData[facility].dir[i], 'facility', facility, beta, Math.cos(beta), Math.sin(beta));
dhor.push((i==0?'M':'L')+
Math.round(pos[0] - val.Hor[i]/1000*Math.sin(beta)) + ' ' +
Math.round(pos[1] + val.Hor[i]/1000*Math.cos(beta))
Math.round(pos[0] - val.Hor[i]*bpmFactor*Math.sin(beta)) + ' ' +
Math.round(pos[1] + val.Hor[i]*bpmFactor*Math.cos(beta))
);
dver.push((i==0?'M':'L')+
Math.round(pos[0] - val.Ver[i]/1000*Math.sin(beta)) + ' ' +
Math.round(pos[1] + val.Ver[i]/1000*Math.cos(beta))
Math.round(pos[0] - val.Ver[i]*bpmFactor*Math.sin(beta)) + ' ' +
Math.round(pos[1] + val.Ver[i]*bpmFactor*Math.cos(beta))
);
}
$('#'+facility+"_bpmhor").attr('d', dhor.join(' ')+(lattice[facility].sections[0].chamber?' Z':''));
......
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