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

Update simulator2d.js

parent 81531b98
No related branches found
No related tags found
No related merge requests found
......@@ -16,11 +16,12 @@
factorsHor = {"": 1000, "position": 5000, 'beta': 0.5, 'eta': 100, 'mu': 0.2, 'sigma': 5000000};
factorsVer = {"": 1000, "position": 5000, 'beta': 0.25, 'eta': 100, 'mu': 0.2, 'sigma': 5000000};
}
const simulator = document.location.search.indexOf('simulator=')>-1? document.location.search.split('simulator=')[1].split('&')[0]: '';
let simulator = document.location.search.indexOf('simulator=')>-1? document.location.search.split('simulator=')[1].split('&')[0]: '';
const readerPeriod = document.location.search.indexOf('readerPeriod=')>-1? document.location.search.split('readerPeriod=')[1].split('&')[0]: 200;
const displayerPeriod = document.location.search.indexOf('displayerPeriod=')>-1? document.location.search.split('displayerPeriod=')[1].split('&')[0]: 200;
const visibility = simulator==''? 'hidden': 'visible';
const scaleType = 'slider';
const simfacilities = [];
let simulatorDataHor = [];
let simulatorDataVer = [];
let scaleHor;
......@@ -34,8 +35,14 @@
function myreference(param) {
const dir = param.split('_')[0];
const action = param.split('_')[1];
if (action=='set') localStorage.setItem('reference'+dir, JSON.stringify(dir=='hor'? simulatorDataHor: simulatorDataVer));
if (action=='clear') localStorage.removeItem('reference'+dir);
if (action=='set') {
localStorage.setItem('reference'+simulator+dir, JSON.stringify(simulatorBuffer[dir=='hor'? 'Hor': 'Ver']));
$("#sr_simulatorreference"+dir).attr('visibility', "visible");
}
if (action=='clear') {
localStorage.removeItem('reference'+simulator+dir);
$("#sr_simulatorreference"+dir).attr('visibility', "hidden");
}
}
function elapseHor(step, up) {
// console.log('elapseHor()',step,scaleHor.$fill.style.width, (scaleSteps-step)/scaleSteps*90);
......@@ -58,14 +65,14 @@
}
function elapseVer(step, up) {
if (up) {
if (step<scaleSteps) {const pc = Math.round(100 - (scaleSteps-step)/scaleSteps*90); scaleVer.$fill.style.width=pc+"%";setTimeout(elapseVer, 200, step+1, up); return;}
if (step<scaleSteps) {const pc = Math.round((scaleSteps-step)/scaleSteps*90); scaleVer.$fill.style.width=pc+"%";setTimeout(elapseVer, 20, step+1, up); return;}
const buf = scaleVer._max;
scaleVer.max(buf*10);
scaleVer.min(buf/10);
scaleVer.step(buf/100);
}
else {
if (step<scaleSteps) {const pc = Math.round(step/scaleSteps*10); scaleVer.$fill.style.width=pc+"%";setTimeout(elapseVer, 200, step+1, up); return;}
if (step<scaleSteps) {const pc = Math.round(step/scaleSteps*10); scaleVer.$fill.style.width=pc+"%";setTimeout(elapseVer, 20, step+1, up); return;}
const buf = scaleVer._max/10;
scaleVer.max(buf);
scaleVer.min(buf/100);
......@@ -92,6 +99,7 @@
simulatorFactorHor = v * 1000;
}
function factorVer(v) {
console.log('factorVer(v)', v, scaleVer.$fill.style.width);
scaleVer.$fill.style.borderColor = (scaleVer.$fill.style.width=="100%" || scaleVer.$fill.style.width=="0%")? 'yellow': '#2cc9ff';
simulatorFactorVer = v * 1000;
}
......@@ -99,18 +107,9 @@
if (dirNum==0) logScaleHor = $('#logHor').attr('checked')=='checked';
else logScaleVer = $('#logVer').attr('checked')=='checked';
}
function decademinus(id) {
const buf = scaleHor._max/10; scaleHor.max(buf); scaleHor.min(buf/100);scaleHor.step(buf/1000);
console.log(id, scaleHor._max);
}
function decadeplus(id) {
const buf = scaleHor._max; scaleHor.max(buf*10); scaleHor.min(buf/10); scaleHor.step(buf/100);
console.log(id, scaleHor._max);
}
function guiscale(gui, id) {
const i = gui.children.length - 1;
gui.children[i].domElement.style.display = 'none';
// gui.children[i].domElement.children[0].innerHTML = '<span style="padding: 5px;" onClick="decademinus(\''+id+'\')">-</span> '+ gui.children[i].domElement.children[0].innerHTML + ' <span style="padding: 3px;" onClick="decadeplus(\''+id+'\')">+</span>';
gui.children[i].domElement.setAttribute('id', id);
}
function simulatorMenu(lattice, facilities, params) {
......@@ -133,7 +132,7 @@
scaleHor = gui.add(menuParams, 'scale H', maxVer/100, maxVer, Math.round(maxVer/1000)).onChange(function() {factorHor(menuParams['scale H'], gui);}).onFinishChange(function() {finishHor(gui);});
guiscale(gui, 'scaleh');
menuParams['scale V'] = simulatorFactorHor/1000;
scaleVer = gui.add(menuParams, 'scale V', maxHor/100, maxHor, Math.round(maxHor/1000)).onChange(function() {factorVer(menuParams['scale V'], gui);});
scaleVer = gui.add(menuParams, 'scale V', maxHor/100, maxHor, Math.round(maxHor/1000)).onChange(function() {factorVer(menuParams['scale V'], gui);}).onFinishChange(function() {finishVer(gui);});
guiscale(gui, 'scalev');
}
else {
......@@ -187,10 +186,10 @@
Math.round(compData[facility].pos[i][1] + f*1.05*Math.cos(beta))
);
}
appendSvg("path", {id:facility+"_simulatorhor", class: "simulatorhor trajectory "+facility, visibility:visibility, name:"simulatorhor", fill: "none", "stroke-width":"150", "stroke":"red", "stroke-opacity":"0.8", d: dhor.join(' ')+(lattice[facility].sections[0].chamber?' Z':'')}, simulator_clicked_hor, false, false, '.svg-pan-zoom_viewport');
appendSvg("path", {id:facility+"_simulatorreferencehor", class: "simulatorhor trajectory "+facility, visibility:visibility, name:"simulatorreferencehor", fill: "none", "stroke-width":"150", "stroke":"darkred", "stroke-opacity":"0.8", d: dhor.join(' ')+(lattice[facility].sections[0].chamber?' Z':'')}, simulator_clicked_hor, false, false, '.svg-pan-zoom_viewport');
appendSvg("path", {id:facility+"_simulatorver", class: "simulatorver trajectory "+facility, visibility:visibility, name:"simulatorver", fill: "none", "stroke-width":"150", "stroke":"green", "stroke-opacity":"0.8", d: dver.join(' ')+(lattice[facility].sections[0].chamber?' Z':'')}, simulator_clicked_ver, false, false, '.svg-pan-zoom_viewport');
appendSvg("path", {id:facility+"_simulatorreferencever", class: "simulatorver trajectory "+facility, visibility:visibility, name:"simulatorreferencever", fill: "none", "stroke-width":"150", "stroke":"darkgreen", "stroke-opacity":"0.8", d: dver.join(' ')+(lattice[facility].sections[0].chamber?' Z':'')}, simulator_clicked_ver, false, false, '.svg-pan-zoom_viewport');
appendSvg("path", {id:facility+"_simulatorhor", class: "simulatorhor trajectory "+facility, visibility:visibility, name:"simulatorhor", fill: "none", "stroke-width":"150", "stroke":"red", "stroke-opacity":"0.6", d: dhor.join(' ')+(lattice[facility].sections[0].chamber?' Z':'')}, simulator_clicked_hor, false, false, '.svg-pan-zoom_viewport');
appendSvg("path", {id:facility+"_simulatorreferencehor", class: "simulatorhor trajectory "+facility, visibility:visibility, name:"simulatorreferencehor", fill: "none", "stroke-width":"150", "stroke":"darkred", "stroke-opacity":"0.9", d: dhor.join(' ')+(lattice[facility].sections[0].chamber?' Z':'')}, simulator_clicked_hor, false, false, '.svg-pan-zoom_viewport');
appendSvg("path", {id:facility+"_simulatorver", class: "simulatorver trajectory "+facility, visibility:visibility, name:"simulatorver", fill: "none", "stroke-width":"150", "stroke":"limegreen", "stroke-opacity":"0.6", d: dver.join(' ')+(lattice[facility].sections[0].chamber?' Z':'')}, simulator_clicked_ver, false, false, '.svg-pan-zoom_viewport');
appendSvg("path", {id:facility+"_simulatorreferencever", class: "simulatorver trajectory "+facility, visibility:visibility, name:"simulatorreferencever", fill: "none", "stroke-width":"150", "stroke":"darkgreen", "stroke-opacity":"0.9", d: dver.join(' ')+(lattice[facility].sections[0].chamber?' Z':'')}, simulator_clicked_ver, false, false, '.svg-pan-zoom_viewport');
// console.log("path", {id:facility+"_simulatorhor", name:"simulatorhor", d: dver.join(' ')+' Z'});
}
}
......@@ -210,12 +209,33 @@
}
function simulator2d(lattice, params) {
console.log('simulator2d',lattice, params);
const facilities = [];
for (let i in lattice) {if (i!='conf') facilities.push(i);}
simulatorMenu(lattice, facilities, params);
for (let i in lattice) {if (i!='conf') simfacilities.push(i);}
simulatorMenu(lattice, simfacilities, params);
}
if (document.location.search.indexOf('ruler')>-1) {
const main = document.getElementById('main');
main.style.cursor = 'crosshair';
// main.addEventListener(measurementEvent, measurementListener, false);
main.addEventListener('mousemove', function(e) {getRulerPosition(main, e);});
rulerSwitch(500, 500);
}
function getRulerPosition(main, event) {
const rect = main.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
$('#ruler1').attr('transform', 'translate('+ ((x - panZoomPanther.getPan().x)/panZoomPanther.getSizes().realZoom)+' '+((y - panZoomPanther.getPan().y)/panZoomPanther.getSizes().realZoom)+')');
}
function rulerSwitch(cx, cy) {
appendSvg("line", {id: 'ruler1', x1: cx, y1: cy, x2: cx+1000, y2: cy, style:"display: block", stroke:"yellow", "stroke-width":100});
/*for (let i=1; i<32; i++) {
appendSvg("line", {id: 'tick'+i, x1: cx, y1: cy, x2: cx, y2: cy, style:"display: block", fill:"yellow", stroke:"black","stroke-width":1});
appendSvg("text", {id: 'tickLabel'+i, x: cx, y: cy, fill:"white", stroke:"black","stroke-width":1, "font-family":"Arial", "font-size":20, "font-weight":"bold", "text-anchor": "start"});
}*/
}
function simulatorSwitch(simulatorData, params) {
console.log('simulatorSwitch()',simulatorData, params, params.simulator);
simulator = params.simulator;
$("#sr_simulatorreferencehor").attr('visibility', "hidden");
$("#sr_simulatorreferencever").attr('visibility', "hidden");
scaleHor.$fill.style.width = "50%";
scaleVer.$fill.style.width = "50%";
if (simulatorData.reader !== false) {
......@@ -223,11 +243,9 @@
}
simulatorData.reader = false;
if (params.simulator=='position') {
$('#application').show();
$('#applicationFrame').attr("src", $('#applicationFrame').attr("data-src"));
}
else {
$('#application').hide();
$('#applicationFrame').removeAttr("src");
}
if (params.simulator=='') {
......@@ -235,14 +253,18 @@
if (typeof $('#'+facility+"_simulatorhor").attr('visibility') != 'undefined') {
$('#'+facility+"_simulatorhor").attr('visibility', "hidden");
$('#'+facility+"_simulatorver").attr('visibility', "hidden");
$('#'+facility+"_simulatorreferencehor").attr('visibility', "hidden");
$('#'+facility+"_simulatorreferencever").attr('visibility', "hidden");
}
}
$('.simulatorgauge').hide();
$('#scaleh').hide();
$('#scalev').hide();
$('#application').hide();
$('#applicationReference').hide();
}
else {
$('#application').show();
$('#applicationReference').show();
$('#scaleh').show();
$('#scalev').show();
......@@ -250,6 +272,8 @@
if (typeof $('#'+facility+"_simulatorhor").attr('visibility') != 'undefined') {
$('#'+facility+"_simulatorhor").attr('visibility', "visible");
$('#'+facility+"_simulatorver").attr('visibility', "visible");
if (localStorage.getItem('reference'+simulator+'hor')!=null) $('#'+facility+"_simulatorreferencehor").attr('visibility', "visible");
if (localStorage.getItem('reference'+simulator+'ver')!=null) $('#'+facility+"_simulatorreferencever").attr('visibility', "visible");
}
// console.log('#'+facility+"_simulatorhor", $('#'+facility+"_simulatorhor").attr('visibility'), typeof simulatorData[facility]);
if (typeof simulatorData[facility] == 'undefined' || typeof simulatorData[facility].map == 'undefined') continue;
......@@ -295,6 +319,11 @@
// console.log('simulatorRender(), val', val, simulator, compData[facility]);
simulatorDataHor = [];
simulatorDataVer = [];
let refHor, refVer;
const referenceDataHor = [];
const referenceDataVer = [];
const referencehor = JSON.parse(localStorage.getItem('reference'+simulator+'hor'));
const referencever = JSON.parse(localStorage.getItem('reference'+simulator+'ver'));
if (val.Hor) {
for (i=0; i<val.Hor.length; i++) {
if (typeof compData[facility].map[i] == 'undefined') continue;
......@@ -305,20 +334,32 @@
const beta = Math.PI*compData[facility].dir[j]/180;
// https://en.wikipedia.org/wiki/Logarithmic_scale#Extensions
const valHor = logScaleHor? Math.sign(val.Hor[i])*Math.log10(1+ Math.abs(val.Hor[i]*Math.LN10)): val.Hor[i];
if (localStorage.getItem('reference'+simulator+'hor')!=null) refHor = logScaleHor? Math.sign(referencehor[i])*Math.log10(1+ Math.abs(referencehor[i]*Math.LN10)): referencehor[i];
const valVer = logScaleVer? Math.sign(val.Ver[i])*Math.log10(1+ Math.abs(val.Ver[i]*Math.LN10)): val.Ver[i];
if (localStorage.getItem('reference'+simulator+'ver')!=null) refVer = logScaleVer? Math.sign(referencever[i])*Math.log10(1+ Math.abs(referencever[i]*Math.LN10)): referencever[i];
// if (i<20) console.log('i', i, 'pos',pos, 'dir', compData[facility].dir[i], 'facility', facility, beta, Math.cos(beta), Math.sin(beta));
simulatorDataHor.push((simulatorDataHor.length==0?'M':'L')+
Math.round(pos[0] - valHor*simulatorFactorHor*Math.sin(beta)) + ' ' +
Math.round(pos[1] + valHor*simulatorFactorHor*Math.cos(beta))
);
if (localStorage.getItem('reference'+simulator+'hor')!=null) referenceDataHor.push((referenceDataHor.length==0?'M':'L')+
Math.round(pos[0] - refHor*simulatorFactorHor*Math.sin(beta)) + ' ' +
Math.round(pos[1] + refHor*simulatorFactorHor*Math.cos(beta))
);
simulatorDataVer.push((simulatorDataVer.length==0?'M':'L')+
Math.round(pos[0] - valVer*simulatorFactorVer*Math.sin(beta)) + ' ' +
Math.round(pos[1] + valVer*simulatorFactorVer*Math.cos(beta))
);
if (localStorage.getItem('reference'+simulator+'ver')!=null) referenceDataVer.push((referenceDataVer.length==0?'M':'L')+
Math.round(pos[0] - refVer*simulatorFactorVer*Math.sin(beta)) + ' ' +
Math.round(pos[1] + refVer*simulatorFactorVer*Math.cos(beta))
);
}
// console.log('Hor', simulatorDataHor.join(' ')+(lattice[facility].sections[0].chamber?' Z':''));
$('#'+facility+"_simulatorhor").attr('d', simulatorDataHor.join(' ')+(lattice[facility].sections[0].chamber?' Z':''));
$('#'+facility+"_simulatorver").attr('d', simulatorDataVer.join(' ')+(lattice[facility].sections[0].chamber?' Z':''));
if (localStorage.getItem('reference'+simulator+'hor')!=null) $('#'+facility+"_simulatorreferencehor").attr('d', referenceDataHor.join(' ')+(lattice[facility].sections[0].chamber?' Z':''));
if (localStorage.getItem('reference'+simulator+'ver')!=null) $('#'+facility+"_simulatorreferencever").attr('d', referenceDataVer.join(' ')+(lattice[facility].sections[0].chamber?' Z':''));
}
}
function simulatorDisplay(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