x-axis justierung: lines 3
This commit is contained in:
@@ -420,6 +420,80 @@ function initXAxis() {
|
||||
btn.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
// ── X-Achse übernehmen ────────────────────────────────────────────────────
|
||||
// Empfängt postMessage aus dem eingebetteten boardViewer-iframe.
|
||||
let _xaxisDirection = null; // zuletzt gemessene Richtung [vx,vy,vz]
|
||||
|
||||
const adoptBtn = document.getElementById('btn-xaxis-adopt');
|
||||
|
||||
function onXaxisMessage(e) {
|
||||
// Nachricht muss vom boardViewer-iframe stammen
|
||||
const frame = document.getElementById('xaxis-viewer-frame');
|
||||
if (!frame || e.source !== frame.contentWindow) return;
|
||||
const msg = e.data;
|
||||
if (!msg || msg.type !== 'xaxis-measurement') return;
|
||||
|
||||
if (Array.isArray(msg.direction)) {
|
||||
_xaxisDirection = msg.direction;
|
||||
const fmt = v => (v >= 0 ? '+' : '') + v.toFixed(3) + '°';
|
||||
logX(`📐 Messung empfangen: dir=[${msg.direction.map(v => v.toFixed(4)).join(', ')}]` +
|
||||
` XY=${fmt(msg.angleXY)} XZ=${fmt(msg.angleXZ)}` +
|
||||
` (${msg.numMarkers} Marker, Ø${msg.distMm.toFixed(1)} mm)`);
|
||||
if (adoptBtn) {
|
||||
adoptBtn.disabled = false;
|
||||
adoptBtn.style.opacity = '1';
|
||||
adoptBtn.style.cursor = 'pointer';
|
||||
adoptBtn.title = `X-Achse übernehmen (dir=[${_xaxisDirection.map(v => v.toFixed(4)).join(', ')}])`;
|
||||
}
|
||||
} else {
|
||||
// Ungültige / zu kleine Bewegung → Button sperren
|
||||
_xaxisDirection = null;
|
||||
if (adoptBtn) {
|
||||
adoptBtn.disabled = true;
|
||||
adoptBtn.style.opacity = '.45';
|
||||
adoptBtn.style.cursor = 'not-allowed';
|
||||
adoptBtn.title = 'Noch keine gültige Messung verfügbar';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('message', onXaxisMessage);
|
||||
|
||||
if (adoptBtn) {
|
||||
adoptBtn.addEventListener('click', async () => {
|
||||
if (!_xaxisDirection) return;
|
||||
const fmt = v => (v >= 0 ? '+' : '') + v.toFixed(4);
|
||||
logX(`🔄 Übernehme X-Achse: dir=[${_xaxisDirection.map(fmt).join(', ')}] …`);
|
||||
adoptBtn.disabled = true;
|
||||
adoptBtn.style.opacity = '.45';
|
||||
try {
|
||||
const r = await fetch('/api/robot/adopt-x-axis', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ direction: _xaxisDirection }),
|
||||
});
|
||||
const data = await r.json();
|
||||
if (!r.ok) {
|
||||
logX(`❌ Fehler: ${data.error ?? r.status}`);
|
||||
return;
|
||||
}
|
||||
logX(`✅ X-Achse gespeichert — ${data.numChanged} Marker rotiert`);
|
||||
logX(` Ursprung (A0-Schwerpunkt): [${data.origin.join(', ')}] mm`);
|
||||
logX(` Neue X-Achse: [${data.newXAxis.join(', ')}]` +
|
||||
` Korr. XY=${(data.angleXYdeg >= 0 ? '+' : '') + data.angleXYdeg}°` +
|
||||
` XZ=${(data.angleXZdeg >= 0 ? '+' : '') + data.angleXZdeg}°`);
|
||||
// Viewer neu laden damit die aktualisierten Positionen sichtbar werden
|
||||
const frame = document.getElementById('xaxis-viewer-frame');
|
||||
if (frame?.contentWindow) frame.contentWindow.postMessage({ type: 'reload' }, '*');
|
||||
} catch (err) {
|
||||
logX(`❌ Netzwerkfehler: ${err}`);
|
||||
} finally {
|
||||
adoptBtn.disabled = false;
|
||||
adoptBtn.style.opacity = '1';
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ── Tab: Board (shared helpers) ───────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user