Add reviewed read-only Midra Preview imports in the desktop app

This commit is contained in:
Dandaedre 2026-11-13 17:20:43 +01:00
parent 793c3cb9d0
commit 5dc151cba2
13 changed files with 757 additions and 11 deletions

243
Cargo.lock generated
View File

@ -1465,6 +1465,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]]
@ -1503,6 +1504,12 @@ dependencies = [
"syn 3.0.9",
]
[[package]]
name = "futures-sink"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d"
[[package]]
name = "futures-task"
version = "0.3.34"
@ -1518,6 +1525,7 @@ dependencies = [
"futures-core",
"futures-io",
"futures-macro",
"futures-sink",
"futures-task",
"memchr",
"pin-project-lite",
@ -1776,6 +1784,88 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
[[package]]
name = "http"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6970f50e31d6fc17d3fa27329444bfa74e196cf62e95052a3f6fee181dba6425"
dependencies = [
"bytes",
"itoa",
]
[[package]]
name = "http-body"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c"
dependencies = [
"bytes",
"http",
]
[[package]]
name = "http-body-util"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a"
dependencies = [
"bytes",
"futures-core",
"http",
"http-body",
"pin-project-lite",
]
[[package]]
name = "httparse"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87"
[[package]]
name = "hyper"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55281c53a1894c864990125767da440a4e630446785086f52523b20033b74498"
dependencies = [
"atomic-waker",
"bytes",
"futures-channel",
"futures-core",
"http",
"http-body",
"httparse",
"itoa",
"pin-project-lite",
"smallvec",
"tokio",
"want",
]
[[package]]
name = "hyper-util"
version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0"
dependencies = [
"base64 0.22.1",
"bytes",
"futures-channel",
"futures-util",
"http",
"http-body",
"hyper",
"ipnet",
"libc",
"percent-encoding",
"pin-project-lite",
"socket2",
"tokio",
"tower-service",
"tracing",
]
[[package]]
name = "hypher"
version = "0.1.8"
@ -2086,6 +2176,12 @@ dependencies = [
"serde_core",
]
[[package]]
name = "ipnet"
version = "2.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2"
[[package]]
name = "is-docker"
version = "0.2.0"
@ -2399,6 +2495,7 @@ dependencies = [
"directories",
"eframe",
"image",
"reqwest",
"rfd",
"roxmltree",
"serde",
@ -2427,6 +2524,17 @@ dependencies = [
"simd-adler32",
]
[[package]]
name = "mio"
version = "1.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1788edb87fdc09c7e26304471e2f5be8cdefb1b6930d6e3985fc02ff53bf86ee"
dependencies = [
"libc",
"wasi",
"windows-sys 0.61.2",
]
[[package]]
name = "moxcms"
version = "0.8.1"
@ -3511,6 +3619,40 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832"
[[package]]
name = "reqwest"
version = "0.12.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147"
dependencies = [
"base64 0.22.1",
"bytes",
"futures-channel",
"futures-core",
"futures-util",
"http",
"http-body",
"http-body-util",
"hyper",
"hyper-util",
"js-sys",
"log",
"percent-encoding",
"pin-project-lite",
"serde",
"serde_json",
"serde_urlencoded",
"sync_wrapper",
"tokio",
"tower",
"tower-http",
"tower-service",
"url",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
]
[[package]]
name = "resvg"
version = "0.43.0"
@ -3765,6 +3907,18 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_urlencoded"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
dependencies = [
"form_urlencoded",
"itoa",
"ryu",
"serde",
]
[[package]]
name = "serde_yaml"
version = "0.9.34+deprecated"
@ -3940,6 +4094,16 @@ dependencies = [
"serde",
]
[[package]]
name = "socket2"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4"
dependencies = [
"libc",
"windows-sys 0.61.2",
]
[[package]]
name = "spin"
version = "0.9.9"
@ -4091,6 +4255,15 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "sync_wrapper"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
dependencies = [
"futures-core",
]
[[package]]
name = "synstructure"
version = "0.13.2"
@ -4306,7 +4479,11 @@ version = "1.54.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0c168a474b95bfecfe908a65d4bdffc523144b649a74c09c286afb35d53e0bc"
dependencies = [
"libc",
"mio",
"pin-project-lite",
"socket2",
"windows-sys 0.61.2",
]
[[package]]
@ -4405,6 +4582,51 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801"
[[package]]
name = "tower"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4"
dependencies = [
"futures-core",
"futures-util",
"pin-project-lite",
"sync_wrapper",
"tokio",
"tower-layer",
"tower-service",
]
[[package]]
name = "tower-http"
version = "0.6.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840"
dependencies = [
"bitflags 2.13.2",
"bytes",
"futures-util",
"http",
"http-body",
"pin-project-lite",
"tower",
"tower-layer",
"tower-service",
"url",
]
[[package]]
name = "tower-layer"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e"
[[package]]
name = "tower-service"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
[[package]]
name = "tracing"
version = "0.1.44"
@ -4437,6 +4659,12 @@ dependencies = [
"once_cell",
]
[[package]]
name = "try-lock"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]]
name = "ttf-parser"
version = "0.24.1"
@ -4956,6 +5184,21 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "want"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e"
dependencies = [
"try-lock",
]
[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
[[package]]
name = "wasip2"
version = "1.0.4+wasi-0.2.12"

View File

@ -17,3 +17,4 @@ serde_json = { version = "1", features = ["float_roundtrip"] }
base64 = "0.22"
tempfile = "3"
directories = "6"
reqwest = { version = "0.12.28", default-features = false, features = ["blocking"] }

View File

@ -0,0 +1,26 @@
//! Explicit, read-only hardware smoke check; never run by automated tests.
fn main() {
let Some(host) = std::env::args().nth(1) else {
eprintln!("Usage: cargo run -p midra-layout --example read_midra -- DEVICE_IP");
std::process::exit(2);
};
match midra_layout::device::fetch(&host) {
Ok(snapshot) => {
println!("{}", snapshot.identity);
for screen in snapshot.screens {
println!(
"Screen {}: {} × {}, Preview {}, {} layer slots",
screen.id,
screen.resolution[0],
screen.resolution[1],
screen.preview_bank,
screen.layers.len()
);
}
}
Err(error) => {
eprintln!("{error}");
std::process::exit(1);
}
}
}

View File

@ -0,0 +1,203 @@
//! Explicit read-only Eikos connection. No device mutation endpoint is exposed.
use crate::{
Geometry,
import::{DetectedShape, ImportDocument},
};
use serde_json::Value;
use std::{io::Read, net::IpAddr, time::Duration};
const MAX_RESPONSE: u64 = 32 * 1024 * 1024;
/// A locally captured device snapshot, not an editor project or writable payload.
#[derive(Clone, Debug)]
pub struct Snapshot {
pub identity: String,
pub screens: Vec<Screen>,
}
#[derive(Clone, Debug)]
pub struct Screen {
pub id: String,
pub resolution: [u32; 2],
pub preview_bank: String,
pub layers: Vec<Layer>,
}
#[derive(Clone, Debug)]
pub struct Layer {
pub id: String,
pub source: String,
pub geometry: Geometry,
pub unsupported: Option<String>,
}
fn value<'a>(v: &'a Value, path: &str) -> Result<&'a Value, String> {
v.pointer(path)
.ok_or_else(|| format!("Missing device field {path}"))
}
fn text(v: &Value, path: &str) -> Result<String, String> {
value(v, path)?
.as_str()
.map(str::to_owned)
.ok_or_else(|| format!("Invalid device text {path}"))
}
fn number(v: &Value, path: &str) -> Result<f64, String> {
value(v, path)?
.as_f64()
.filter(|n| n.is_finite())
.ok_or_else(|| format!("Invalid device number {path}"))
}
impl Snapshot {
pub fn parse(identity: &Value, raw: &Value) -> Result<Self, String> {
let kind = text(identity, "/type")?;
if kind != "Eikos 4K" {
return Err(format!(
"Unsupported device {kind}; this adapter targets Eikos 4K."
));
}
let version =
["major", "minor", "patch"].map(|k| number(identity, &format!("/version/{k}")));
let [major, minor, patch] = version;
let identity = format!("{kind} · firmware {}.{}.{}", major?, minor?, patch?);
let device = value(raw, "/device")?;
let items = value(device, "/screenList/items")?
.as_object()
.ok_or("Invalid screen list")?;
let mut screens = Vec::new();
for (id, s) in items {
let transition = text(
device,
&format!("/transition/screenList/items/{id}/status/pp/transition"),
)?;
let bank = match transition.as_str() {
"AT_DOWN" => "UP",
"AT_UP" => "DOWN",
_ => return Err(format!("Screen {id} is transitioning. Refresh when idle.")),
};
let w = number(s, "/canvas/status/size/pp/sizeH")?;
let h = number(s, "/canvas/status/size/pp/sizeV")?;
// The firmware includes disabled screen slots with a zero canvas.
if w == 0.0 && h == 0.0 {
continue;
}
if w.fract() != 0.0
|| h.fract() != 0.0
|| !(1.0..=16384.0).contains(&w)
|| !(1.0..=16384.0).contains(&h)
{
return Err(format!("Invalid canvas for screen {id}"));
}
let entries = value(s, &format!("/presetList/items/{bank}/liveLayerList/items"))?
.as_object()
.ok_or("Invalid layer list")?;
let mut layers = Vec::new();
for (id, layer) in entries {
let width = number(layer, "/size/pp/sizeH")?;
let height = number(layer, "/size/pp/sizeV")?;
let geometry = Geometry {
x: number(layer, "/position/pp/posH")? - width / 2.0,
y: number(layer, "/position/pp/posV")? - height / 2.0,
width,
height,
}
.validate()?;
let mut unsupported = None;
for field in ["crop", "mask"] {
for edge in ["left", "right", "top", "bottom"] {
if number(layer, &format!("/{field}/pp/{edge}"))? != 0.0 {
unsupported = Some(format!(
"Nonzero {field}: visible-bound conversion is not verified."
));
}
}
}
layers.push(Layer {
id: id.clone(),
source: text(layer, "/source/pp/input")?,
geometry,
unsupported,
});
}
screens.push(Screen {
id: id.clone(),
resolution: [w as u32, h as u32],
preview_bank: bank.into(),
layers,
});
}
if screens.is_empty() {
return Err("No screens returned by device".into());
}
Ok(Self { identity, screens })
}
}
impl Screen {
pub fn import(&self, indices: &[usize]) -> Result<ImportDocument, String> {
if indices.is_empty() {
return Err("Choose device layers to import.".into());
}
let mut shapes = Vec::new();
for &index in indices {
let layer = self
.layers
.get(index)
.ok_or("Device layer no longer exists")?;
if let Some(reason) = &layer.unsupported {
return Err(format!("Layer {}: {reason}", layer.id));
}
let id = format!("Screen {} · Layer {} · {}", self.id, layer.id, layer.source);
if shapes.iter().any(|s: &DetectedShape| s.id == id) {
return Err("Duplicate device layer selection".into());
}
shapes.push(DetectedShape {
id,
geometry: layer.geometry,
outline: [0.0; 2],
background: false,
background_only: false,
zoom: None,
});
}
Ok(ImportDocument {
shapes,
svg: false,
note: format!(
"Preview screen {} ({} × {}). Container position/size only. Source aspect fitting, routing, input crop and effects are not imported. Device slots may include unavailable layers. Review mapping before applying.",
self.id, self.resolution[0], self.resolution[1]
),
})
}
}
fn read_json(client: &reqwest::blocking::Client, url: &str) -> Result<Value, String> {
let response = client
.get(url)
.send()
.and_then(|r| r.error_for_status())
.map_err(|e| format!("Cannot read Midra: {e}"))?;
let mut bytes = Vec::new();
response
.take(MAX_RESPONSE + 1)
.read_to_end(&mut bytes)
.map_err(|e| e.to_string())?;
if bytes.len() as u64 > MAX_RESPONSE {
return Err("Device response exceeds 32 MiB".into());
}
serde_json::from_slice(&bytes).map_err(|e| format!("Invalid device JSON: {e}"))
}
/// Perform two GET requests, only on an explicit IP. Call from a worker thread.
pub fn fetch(host: &str) -> Result<Snapshot, String> {
let ip: IpAddr = host
.trim()
.parse()
.map_err(|_| "Enter a device IP address, without http:// or a path.")?;
let authority = match ip {
IpAddr::V4(ip) => ip.to_string(),
IpAddr::V6(ip) => format!("[{ip}]"),
};
let client = reqwest::blocking::Client::builder()
.timeout(Duration::from_secs(15))
.no_proxy()
.redirect(reqwest::redirect::Policy::none())
.build()
.map_err(|e| e.to_string())?;
let identity = read_json(&client, &format!("http://{authority}/api/tpp/v1/system"))?;
let state = read_json(&client, &format!("http://{authority}/api/stores/device"))?;
Snapshot::parse(&identity, &state)
}

View File

@ -0,0 +1,160 @@
use super::*;
use midra_layout::device;
use std::sync::mpsc::{self, Receiver, TryRecvError};
#[derive(Default)]
pub(super) struct DeviceUi {
pub open: bool,
host: String,
pending: Option<Receiver<Result<device::Snapshot, String>>>,
snapshot: Option<device::Snapshot>,
screen: usize,
chosen: Vec<bool>,
error: String,
}
impl DeviceUi {
fn fetch(&mut self, ctx: &egui::Context) {
let (tx, rx) = mpsc::channel();
self.pending = Some(rx);
self.snapshot = None;
self.chosen.clear();
self.error.clear();
let host = self.host.clone();
let ctx = ctx.clone();
std::thread::spawn(move || {
let result = device::fetch(&host);
let _ = tx.send(result);
ctx.request_repaint();
});
}
fn poll(&mut self) {
let Some(rx) = &self.pending else { return };
let result = match rx.try_recv() {
Ok(result) => result,
Err(TryRecvError::Empty) => return,
Err(TryRecvError::Disconnected) => {
Err("Device reader stopped unexpectedly. Refresh to retry.".into())
}
};
self.pending = None;
match result {
Ok(snapshot) => {
self.chosen = vec![false; snapshot.screens[0].layers.len()];
self.screen = 0;
self.snapshot = Some(snapshot);
}
Err(error) => self.error = error,
}
}
}
impl Editor {
pub(super) fn device_window(&mut self, ctx: &egui::Context) {
self.device.poll();
if !self.device.open {
return;
}
let mut open = true;
let mut document = None;
egui::Window::new("Midra connection · Preview")
.open(&mut open).default_width(660.0).collapsible(false)
.show(ctx, |ui| {
ui.label("Read a snapshot from your Eikos, then review layer mapping before importing.");
ui.horizontal(|ui| {
ui.label("Device IP");
ui.add_enabled(self.device.pending.is_none(), egui::TextEdit::singleline(&mut self.device.host).hint_text("192.168.…"));
if ui.add_enabled(self.device.pending.is_none(), egui::Button::new("Read / refresh")).clicked() { self.device.fetch(ctx); }
});
if self.device.pending.is_some() {
ui.horizontal(|ui| { ui.spinner(); ui.label("Reading device… editing remains available."); });
if ui.button("Cancel read").clicked() { self.device.pending = None; }
}
ui.weak("No automatic polling or device writes. Closing or importing a project never sends commands.");
if let Some(snapshot) = &self.device.snapshot {
ui.separator();
ui.strong(&snapshot.identity);
let previous = self.device.screen;
egui::ComboBox::from_id_salt("midra_screen")
.selected_text(format!("Screen {}", snapshot.screens[self.device.screen].id))
.show_ui(ui, |ui| {
for (i, screen) in snapshot.screens.iter().enumerate() { ui.selectable_value(&mut self.device.screen, i, format!("Screen {} · {} × {}", screen.id, screen.resolution[0], screen.resolution[1])); }
});
let screen = &snapshot.screens[self.device.screen];
if previous != self.device.screen { self.device.chosen = vec![false; screen.layers.len()]; }
ui.label(format!("Captured Preview bank: {}. Refresh to read subsequent changes.", screen.preview_bank));
let matches = screen.resolution == self.layout.formats().output;
if !matches { ui.colored_label(ui.visuals().warn_fg_color, format!("Device canvas {} × {}; editor {} × {}. Match output resolution before importing.", screen.resolution[0], screen.resolution[1], self.layout.formats().output[0], self.layout.formats().output[1])); }
egui::ScrollArea::vertical().max_height(300.0).show(ui, |ui| {
for (i, layer) in screen.layers.iter().enumerate() {
ui.horizontal(|ui| {
ui.add_enabled(layer.unsupported.is_none(), egui::Checkbox::new(&mut self.device.chosen[i], format!("Layer {} · {}", layer.id, layer.source)));
ui.label(format!("{} × {} at {}, {}", midra_layout::view_pixels(layer.geometry.width), midra_layout::view_pixels(layer.geometry.height), midra_layout::view_pixels(layer.geometry.x), midra_layout::view_pixels(layer.geometry.y)));
});
if let Some(reason) = &layer.unsupported { ui.weak(reason); }
}
});
ui.weak("Container geometry only. Source fitting, routing, input crops and effects are not imported. Device slots may include unused layers.");
let selected: Vec<_> = self.device.chosen.iter().enumerate().filter_map(|(i, &on)| on.then_some(i)).collect();
let targets = self.layout.selected_indices().len();
ui.label(format!("{} device layers → {targets} selected editor layers", selected.len()));
let valid = matches && targets > 0 && targets == selected.len();
if ui.add_enabled(valid, egui::Button::new("Review import…")).clicked() {
match screen.import(&selected) { Ok(doc) => document = Some(doc), Err(e) => self.device.error = e }
}
if !valid { ui.weak("Choose the same number of device and editor layers, with matching screen resolution."); }
}
if !self.device.error.is_empty() { ui.colored_label(ui.visuals().error_fg_color, &self.device.error); }
ui.separator();
ui.weak("Preview sends are unavailable until addressing stays safe across a TAKE. Program and shared input/output settings will never be written by this connection.");
});
self.device.open = open;
if let Some(doc) = document {
self.open_paste(String::new());
if let Some(paste) = &mut self.paste {
paste.set_document(doc);
}
self.device.open = false;
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn disconnected_reader_reports_error_and_can_retry() {
let (tx, rx) = mpsc::channel();
let mut state = DeviceUi {
pending: Some(rx),
..Default::default()
};
state.poll();
assert!(state.pending.is_some());
drop(tx);
state.poll();
assert!(state.pending.is_none());
assert!(state.error.contains("Refresh"));
}
#[test]
fn canceled_read_cannot_install_a_late_snapshot() {
let (tx, rx) = mpsc::channel();
let mut state = DeviceUi {
pending: Some(rx),
..Default::default()
};
state.pending = None;
assert!(tx.send(Err("late response".into())).is_err());
state.poll();
assert!(state.snapshot.is_none());
assert!(state.error.is_empty());
}
#[test]
fn connection_window_does_not_read_or_modify_on_open() {
let ctx = egui::Context::default();
let mut app = Editor::default();
let before = *app.layout.layers();
app.device.open = true;
super::super::tests::frame(&mut app, &ctx, vec![]);
assert!(app.device.pending.is_none());
assert_eq!(*app.layout.layers(), before);
}
}

View File

@ -1,4 +1,6 @@
use super::*;
#[path = "device_ui.rs"]
mod device_ui;
#[path = "format_ui.rs"]
mod format_ui;
#[path = "menu_ui.rs"]
@ -12,6 +14,7 @@ use midra_layout::import::{DetectedShape, ImportDocument, parse_svg, parse_value
use midra_layout::{AlignTarget, Alignment, Corner, Geometry, Layout, ResizeHandle, ResizeMode};
pub struct Editor {
device: device_ui::DeviceUi,
settings: settings::Store,
themes_open: bool,
preferences_open: bool,
@ -174,6 +177,7 @@ impl Paste {
impl Default for Editor {
fn default() -> Self {
let mut this = Self {
device: Default::default(),
settings: settings::Store::default(),
themes_open: false,
preferences_open: false,
@ -2293,6 +2297,7 @@ impl Editor {
self.formats_window(ctx);
self.project_windows(ctx);
self.preferences_window(ctx);
self.device_window(ctx);
self.theme_window(ctx);
}
}

View File

@ -1,4 +1,5 @@
//! Offline layer geometry, reversible edits and bounded draw.io/SVG imports.
//! Layer geometry, reversible edits and bounded imports.
pub mod device;
use std::collections::HashMap;
pub mod formats;
pub mod import;

View File

@ -3,6 +3,11 @@ use super::*;
impl Editor {
pub(super) fn import_menu(&mut self, ui: &mut egui::Ui) {
ui.set_min_width(225.0);
if ui.button("Midra Preview…").clicked() {
self.device.open = true;
ui.close_menu();
}
ui.separator();
ui.weak("Layer values");
let selected = !self.layout.selected_indices().is_empty();
if ui

View File

@ -104,9 +104,9 @@ impl Editor {
}
Section::Device => {
ui.heading("Midra integration");
ui.label("Offline layout planning for Eikos 4K.");
ui.label("Device mapping and export strategies are not implemented yet. No network connection or device commands are made.");
ui.weak("Hardware compatibility needs validation against the exact firmware in an isolated test setup.");
ui.label("Read Preview layer containers from an Eikos 4K and review their mapping before import.");
if ui.button("Open Midra connection…").clicked() { self.device.open = true; }
ui.weak("Reads happen only on request. Device writes and full crop conversion remain unavailable.");
}
}
});

View File

@ -0,0 +1,84 @@
use midra_layout::device::Snapshot;
use serde_json::{Value, json};
fn fixture() -> (Value, Value) {
let layer = json!({"position":{"pp":{"posH":1436,"posV":540}},"size":{"pp":{"sizeH":967,"sizeV":544}},"source":{"pp":{"input":"INPUT_4"}},"crop":{"pp":{"left":0,"right":0,"top":0,"bottom":0}},"mask":{"pp":{"left":0,"right":0,"top":0,"bottom":0}}});
let screen = json!({
"canvas": {"status": {"size": {"pp": {"sizeH": 1920, "sizeV": 1080}}}},
"presetList": {"items": {"UP": {"liveLayerList": {"items": {"1": layer}}}}}
});
let raw = json!({"device": {
"transition": {"screenList": {"items": {"2": {"status": {"pp": {"transition": "AT_DOWN"}}}}}},
"screenList": {"items": {"2": screen}}
}});
(
json!({"type":"Eikos 4K","version":{"major":3,"minor":3,"patch":10}}),
raw,
)
}
#[test]
fn preview_read_retains_half_pixels_and_maps_source_label() {
let (identity, raw) = fixture();
let snapshot = Snapshot::parse(&identity, &raw).unwrap();
assert_eq!(snapshot.identity, "Eikos 4K · firmware 3.3.10");
let screen = &snapshot.screens[0];
assert_eq!(screen.preview_bank, "UP");
let doc = screen.import(&[0]).unwrap();
assert_eq!(doc.shapes[0].geometry.x, 952.5);
assert_eq!(doc.shapes[0].geometry.y, 268.0);
assert!(doc.shapes[0].id.contains("INPUT_4"));
assert!(screen.import(&[]).is_err());
assert!(screen.import(&[0, 0]).is_err());
assert!(screen.import(&[9]).is_err());
}
#[test]
fn reject_transition_and_missing_preview_without_falling_back_to_program() {
let (identity, mut raw) = fixture();
let state = "/device/transition/screenList/items/2/status/pp/transition";
*raw.pointer_mut(state).unwrap() = json!("EFFECT_FROM_DOWN");
assert!(
Snapshot::parse(&identity, &raw)
.unwrap_err()
.contains("transitioning")
);
*raw.pointer_mut(state).unwrap() = json!("AT_UP");
assert!(Snapshot::parse(&identity, &raw).is_err());
let up = raw
.pointer("/device/screenList/items/2/presetList/items/UP")
.unwrap()
.clone();
raw["device"]["screenList"]["items"]["2"]["presetList"]["items"]["DOWN"] = up;
assert_eq!(
Snapshot::parse(&identity, &raw).unwrap().screens[0].preview_bank,
"DOWN"
);
}
#[test]
fn unsupported_framing_is_visible_but_not_importable() {
let (identity, mut raw) = fixture();
raw["device"]["screenList"]["items"]["2"]["presetList"]["items"]["UP"]["liveLayerList"]["items"]
["1"]["crop"]["pp"]["left"] = json!(18350);
let s = Snapshot::parse(&identity, &raw).unwrap();
assert_eq!(s.screens[0].layers.len(), 1);
assert!(s.screens[0].import(&[0]).unwrap_err().contains("crop"));
}
#[test]
fn malformed_device_state_fails_before_import() {
let (mut identity, mut raw) = fixture();
identity["type"] = json!("different device");
assert!(Snapshot::parse(&identity, &raw).is_err());
identity["type"] = json!("Eikos 4K");
raw["device"]["screenList"]["items"]["2"]["canvas"]["status"]["size"]["pp"]["sizeH"] =
json!(1920.5);
assert!(Snapshot::parse(&identity, &raw).is_err());
assert!(midra_layout::device::fetch("http://localhost/").is_err());
}
#[test]
fn disabled_screen_slots_are_ignored() {
let (identity, mut raw) = fixture();
let mut disabled = raw["device"]["screenList"]["items"]["2"].clone();
disabled["canvas"]["status"]["size"]["pp"] = json!({"sizeH":0,"sizeV":0});
raw["device"]["screenList"]["items"]["3"] = disabled;
raw["device"]["transition"]["screenList"]["items"]["3"] =
json!({"status":{"pp":{"transition":"AT_DOWN"}}});
assert_eq!(Snapshot::parse(&identity, &raw).unwrap().screens.len(), 1);
}

View File

@ -46,8 +46,22 @@ above come from the installed device and its own WebRCS bundle.
## Read-only import bridge
The desktop app remains offline. A standard-library Python helper provides a
reproducible read-only bridge while the GUI device adapter is developed:
The desktop app now has **Import → Midra Preview…**, also accessible from
**Preferences → Midra integration**. Enter the device IP and click **Read / refresh**.
Reads run in a worker thread; canceling discards late results. Choose a screen and
exactly as many device layers as selected editor layers, then **Review import…**
opens the existing mapping dialog. Output resolutions must match. Reading never
changes the document; only applying the reviewed import does. No automatic
connection or polling occurs, and no credentials or address are persisted.
The Rust adapter was tested against the same Eikos 3.3.10: two 1920×1080 screens;
disabled zero-canvas screen slots are filtered. A CLI smoke check is available:
```sh
cargo run -p midra-layout --example read_midra -- DEVICE_IP
```
A standard-library Python helper remains available for snapshot capture/offline replay:
```sh
python3 tools/midra_probe.py --host DEVICE_IP --save-snapshot /tmp/eikos-state.json
@ -74,8 +88,8 @@ sanitize before sharing. Its exchange contract is documented in
## Remaining integration work
- Build a reviewed GUI import with explicit screen/layer mapping and unsupported
state reporting; preserve the current project until import is accepted.
- Extend the implemented reviewed GUI container import to full source/framing
conversion after the corresponding hardware mapping is verified.
- Verify source/input and layer crop units and Centered aspect behavior. Observed
crop edge values such as `18350` must not be interpreted as editor source pixels.
- Validate size, vertical position, odd dimensions and both export strategies

View File

@ -6,7 +6,8 @@ selection, explicit-target alignment, numeric corner positioning/size, undo/redo
and camera zoom/pan. Concept A is user-approved.
Reference images, output presets/custom resolution, source/input formats and
advanced crop-backed content zoom/offset are implemented offline. Device mapping
verification and GUI connectivity remain deferred. An authorized Eikos 3.3.10
verification remains partial. GUI read-only connectivity and reviewed container
import are implemented. An authorized Eikos 3.3.10
read/Preview-write/restore check passed; see [hardware findings and import bridge](midra-layout-device-check.md). Checklist gates
that combine implemented and outstanding work remain open.
Target: Analog Way Eikos 4K, running the latest firmware according to the user.
@ -32,7 +33,8 @@ Remaining work, in priority order:
3. Additional clipboard adapters after obtaining real application/version samples.
4. Local device mappings, specific-layer export, destination review, and two
independently tested sizing/crop strategies. Hardware values remain provisional.
5. GUI device integration and broader exact-firmware verification. The user
5. Safe Preview write addressing and broader exact-firmware verification. GUI
read-only import is implemented. The user
authorized the 2026-11-13 read and Preview-only test; bidirectional connectivity
passed on Eikos 3.3.10. Program writes remain forbidden. See the hardware
findings for remaining crop, race-condition and mapping gates.

View File

@ -513,4 +513,6 @@ retain their existing behavior. One drag remains one undo step, with Escape to c
The [Eikos 3.3.10 check](midra-layout-device-check.md) records the authorized
Preview-only round trip and a read-only snapshot/SVG import helper. The desktop
editor remains offline; full device crop mapping and GUI connectivity are pending.
editor also offers **Import → Midra Preview…** for an explicit background read
and reviewed container import. Full device crop mapping and safe Preview writes
are pending; this adapter exposes no write endpoints.