From 9e61857b646f8bf39e75942e21de03bb37e326ba Mon Sep 17 00:00:00 2001
From: Lucio Zambon <lucio.zambon@elettra.eu>
Date: Thu, 23 May 2024 17:41:05 +0000
Subject: [PATCH] Update panther2d.js

---
 panther2d.js | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/panther2d.js b/panther2d.js
index 1f5f94a..b856d8f 100644
--- a/panther2d.js
+++ b/panther2d.js
@@ -75,7 +75,8 @@
 		if (e.keyCode == 13) findComponent($("#sname").val().toUpperCase().replace('.','_'));
 		// return -1;
 	}
-	if (navigator.userAgent.indexOf('Firefox/63')==-1) {gui.add(params, 'machine', conf.machineList).onChange(function() {toggleMachine(params.machine);});}
+	// 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');
 	gui.addColor(params, 'backgroundColor').onChange(function() {toggleParam('backgroundColor');});
 	params.vlv = document.location.search.indexOf('vlv')>-1;
@@ -92,8 +93,8 @@
 		if (lattice.servicearea) for (let i in lattice.servicearea.sections) {
 			for (let j in lattice.servicearea.sections[i].components) {
 				if (name.replace('.', '_')==lattice.servicearea.sections[i].components[j].name.replace('.', '_')) {servicearea = true;}
-				for (let k in lattice.servicearea.sections[i].components[j].devices) {
-					if (name==lattice.servicearea.sections[i].components[j].devices[k]) {servicearea = true;}
+				for (let k in lattice.servicearea.sections[i].components[j].embedded) {
+					if (name==lattice.servicearea.sections[i].components[j].embedded[k]) {servicearea = true;}
 				}
 			}
 		}
@@ -182,6 +183,7 @@
 					// 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);
 				}
+				bpmInit(facilities); 
 				if (document.location.search.indexOf('servicearea')>-1) initSearch(lattice.servicearea.sections, 'servicearea');
 				if (typeof blm != 'undefined') blmMenu(lattice, facilities, params);
 				if (typeof bpmData != 'undefined') bpmMenu(lattice, facilities, params);
@@ -254,7 +256,9 @@
 					const vlvSrc = data.toUpperCase().substring(14).split(',');
 					for (let i=0; i<vlvs.length; i++) { 
 						for (let j=0; j<vlvSrc.length; j++) {
-							const name = vlvSrc[j].split('/')[3].replace('.','_');
+							const vlva = vlvSrc[j].split('/');
+							if (vlva.length < 4) continue;
+							const name = vlva[3].replace('.','_');
 							if (vlvs[i].name.replace('.','_').indexOf(name)>-1) {vlvs[i].vlvsrc = state; vlvs[i].vlvindex = j; vlvs[i].type = 'vlv';}
 							if (vlvSrc[j].split('/')[2].indexOf(conf.bstmap.base)>-1) {
 								if (conf.bstmap[vlvs[i].name] && conf.bstmap[vlvs[i].name].indexOf(vlvSrc[j].split('/')[4])>-1) {
@@ -327,12 +331,12 @@
 			hideTimeout = setTimeout(hideTooltip, 120000);
 			document.getElementById('compdb').style.display = (type.indexOf('rv')==0 || type.indexOf('rc')==0 || type.indexOf('rid')==0 || type.indexOf('rd')==0 || type.indexOf('rps')==0 || type.indexOf('plc')==0)? 'none': 'block';
 			const id = evalId(this.id);
-			document.getElementById('compname').innerHTML = id;
+			if (document.getElementById('compname')) document.getElementById('compname').innerHTML = id;
 			document.getElementById('compdb').href = conf.compdb + id;
 			document.getElementById("compdb").addEventListener("click", compLink);
 			if (type.toLowerCase().indexOf('beamline')>-1) {
 				document.getElementById('compdb').href = 'http://adam.elettra.trieste.it/projects/blcs/beamwatch/';
-				document.getElementById('compdb').innerHTML = 'search '+this.id+' in ADAM Beamwatch';
+				document.getElementById('compdb').innerHTML = 'search '+this.id+' in ADAM Beamwatch <span id="compname"/>';
 			}
 			else if (machine=='elettra') document.getElementById('compdb').setAttribute("disabled", true);
 			event.stopPropagation();
@@ -376,7 +380,7 @@
 	function appendLabel2(param, labelclass, display, x, y, beta, labelReverse) {
 		const id = param.name;
 		const fontsize = labelclass.indexOf('bl')>-1? 800: 500;
-		console.log("appendLabel2()",param, labelclass, display, x, y, beta, labelReverse);
+		// console.log("appendLabel2()",param, labelclass, display, x, y, beta, labelReverse);
 		if (labelclass.indexOf('bl')>-1 && typeof labelReverse != 'object') {
 			labelReverse = [180, 17000, param.type=='beamlineUp'? -500: +800];
 			if ((beta+3690)%360 < 180) labelReverse = [0, -14000, param.type=='beamlineUp'? 1000: -300];
@@ -412,8 +416,8 @@
 				const id = extractId(component.name);
 				names.push(id[0]);
 				if (facility=='servicearea') serviceareanames.push(id[0]);
-				if (component.devices) {
-					for (let j=0; j<component.devices.length; j++)  {names.push(component.devices[j]); alias.push([id[0],component.devices[j]]);}
+				if (component.embedded) {
+					for (let j=0; j<component.embedded.length; j++)  {names.push(component.embedded[j]); alias.push([id[0],component.embedded[j]]);}
 				}
 			}
 		}
@@ -458,8 +462,8 @@
 				else
 					appendLabel(components[i].name, comp+' label '+section+facility, 'none', x, y, beta, components[i].labelReverse);
 				names.push(id[0]);
-				if (components[i].devices) {
-					for (let j=0; j<components[i].devices.length; j++)  {names.push(components[i].devices[j]); alias.push([id[0],components[i].devices[j]]);}
+				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 (state) {
@@ -512,12 +516,17 @@
 		$('.'+objclass+'scale').attr('transform', "scale("+s+") translate("+x+","+y+")");
 	}
 	function initSearch(sections, facility) { 
+		console.log('initSearch()', sections, facility);
 		for (i=0; i<sections.length; i++) { // if(i>1) break;
-			// if (sections[i].bending && sections[i].bending.type) {appendSearch(sections[i].bending, facility);}
+			if (sections[i].bending && sections[i].bending.type) {
+				console.log('names.push()', sections[i].bending.name);
+				names.push(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);
 		}
 	}
 	function initLattice(sections, facility) { 
+		initSearch(sections, facility);
 		if (document.location.search.indexOf('facility=')>-1 && facility!=document.location.search.split('facility=')[1].split('&')[0]) return;
 		if (typeof bpmData != 'undefined') {
 			bpmData[facility] = {obj: [], dir: [], pos: []};
@@ -551,14 +560,14 @@
 			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, 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);
+				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);
 				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);
 			}
 			alpha = beta;
 			appendComponent(sections[i].components, sections[i].start.x, sections[i].start.z, sections[j].start.x, sections[j].start.z, facility);
+			// if (typeof bpmData != 'undefined') bpmInit(facility); 
 		}
-		if (typeof bpmData != 'undefined') bpmInit(facility);
 	}
 	$(document).ready(function() {
 		$("svg").attr('height', window.innerHeight+'px');
-- 
GitLab