BNA8/.resources/91d74f4dd5b72e4056e7029f51a456d7dd0afe75f44ad7ec05563cce4d180946

158 lines
4.6 KiB
Plaintext

def calculateFocus(self, child, scale=1.7):
system.perspective.print(self)
# Read rotation
try:
rot = int(str(self.session.custom.rotation).replace("deg", "")) % 360
except:
rot = 0
# Device normalized coords (0..1)
x = float(child.position.x)
y = float(child.position.y)
# Per-rotation affine coefficients (dx, dy)
COEFFS = {
0: dict(ax= 956.86984, bx=-1853.94329, cx= -17.57191,
ay= 124.82245, by= -191.28916, cy= 227.58568),
90: dict(ax=-601.58230, bx= -218.90739, cx=1466.46475,
ay= 284.67701, by=-1528.43884, cy= 54.37458),
180: dict(ax=-728.83646, bx= 1521.61995, cx= 16.04437,
ay=-434.03405, by= -32.67146, cy=1071.85472),
270: dict(ax= 385.53372, bx= -44.67850, cx=-768.65879,
ay=-1341.88064, by= 1615.55073, cy= 142.77638),
}
c = COEFFS.get(rot, COEFFS[0])
dx = c['ax'] + c['bx']*x + c['cx']*y
dy = c['ay'] + c['by']*x + c['cy']*y
# Keep your wide-device tweak if you still want it (optional)
try:
deviceWidthPixels = float(child.position.width) * 1850.0
except:
deviceWidthPixels = 0.0
if deviceWidthPixels > 1200:
scale = 1.8
dy -= 100
return {"x": dx, "y": dy, "scale": scale}
def deviceType(self, path, props):
try:
docked_view = "Docked-East-"
section = "all"
devices = []
tags = []
prop = props[0]
# --- VFD ---
if "VFD" in path:
docked_view += "VFD"
section = "vfd"
# --- Conveyor ---
elif "Conv" in path or "Conveyor" in path:
docked_view += "Conv"
autStand.devices.build_device_mapping(prop)
devices = autStand.devices.build_device_table(self)
section = "conveyor"
# --- Generic devices ---
else:
docked_view += "Device"
tags = autStand.devices.getAllTags(self, prop, section=section)
return [docked_view, tags, devices]
except Exception as e:
import traceback
msg = "Error in deviceType: {}\n{}".format(str(e), traceback.format_exc())
system.perspective.print(msg)
return None
def handleTagHighlight(view, currentValue):
tagAndPriority = str(currentValue.value
or "")
container = view.rootContainer.getChildren()[0]
# --- CASE 1: Remove all highlights by applying CLEAR class ---
if tagAndPriority.upper() == "CLEAR":
for child in container.getChildren():
try:
currentClasses = child.props.style['classes'].split(" ")
filtered = [c for c in currentClasses if not c.startswith("Highlight/")]
child.props.style.classes = " ".join(filtered)
child.props.params.highlight = ""
except:
pass
return False
if "||" not in tagAndPriority:
return
parts = tagAndPriority.split("||")
tag = parts[0]
splitedTag = tag.split("/")
deviceName = splitedTag[-1]
# --- CASE 2: Open camera popup
if "Camera" in deviceName:
cameraView = container.getChild(deviceName)
ipAddress = cameraView.props.get("params", {}).get("ipaddress", "")
system.perspective.openPopup("kxYYzZ2O", "autStand/PopUp-Views/Camera", params = {"ipaddress": ipAddress}, title = deviceName)
return
components = container.getChildren()
priority = parts[1]
foundMatch = False
# clear all highlights and apply new one when found
for child in components:
props = child.meta.name
params = child.props.get("params", {})
tagProps = params.get("tagProps", {})
tagsList = list(tagProps)
if len(tagsList) == 0:
continue
# child.props.style.classes = ""
currentClasses = child.props.style.get('classes', '').split(" ")
# strip only highlight-related classes
filtered = [c for c in currentClasses if not c.startswith("Highlight/")]
child.props.style.classes = " ".join(filtered)
child.props.params.highlight = ""
tagPath = tagsList[0]
if tag == tagPath:
path = child.props.get("path")
device = str(path).split("/")[-1].lower()
child.props.params.highlight = priority
if "photoeye" not in device and not device.startswith("conveyor_"):
child.props.style.classes += " Highlight/Pulse-" + priority
docked_view = deviceType(view, path, tagProps)
system.perspective.openDock(docked_view[0], params = {'tagProps':tagProps, 'tags': docked_view[1], 'devices':docked_view[2], 'name':props})
system.perspective.sendMessage(
"focusDevice",
payload = calculateFocus(view, child),
scope="session"
)
foundMatch = True
return foundMatch