v0.6.0 — Additional touchscreen modules and NIBP manual-first startup
Added touch/click settings panels for SpO₂, ART, CO₂ and the bottom-right NIBP cell. Their threshold editors use large, unit-specific +/− and ON/OFF controls; the panels expose relevant waveform/sensor options and stay synchronized with Admin. NIBP additionally provides interval selection, manual **Measure now**, Auto ON/OFF and cuff options. Startup no longer initiates a cuff cycle or shows any NIBP reading; Auto is OFF by default. Existing NIBP cycle physics and signal quality behavior are unchanged.
This commit is contained in:
parent
3f191e4c46
commit
41e1971fae
13 changed files with 1954 additions and 93 deletions
|
|
@ -283,6 +283,7 @@ pub struct Parameters {
|
|||
pub nibp_systolic: i32, // mmHg, initial measured NIBP result
|
||||
pub nibp_diastolic: i32, // mmHg, initial measured NIBP result
|
||||
pub nibp_interval_minutes: i32, // 1 / 3 / 5 / 10 / 20 / 30 / 60
|
||||
pub nibp_auto_measurement: bool, // OFF at startup; manually enable automatic cycles
|
||||
pub nibp_no_reading: bool, // force unsuccessful cuff measurement
|
||||
pub nibp_cuff_on_spo2: bool, // simulated probe on cuff extremity
|
||||
pub nibp_cuff_on_art: bool, // simulated arterial catheter on cuff extremity
|
||||
|
|
@ -361,6 +362,7 @@ impl Default for Parameters {
|
|||
nibp_systolic: 118,
|
||||
nibp_diastolic: 74,
|
||||
nibp_interval_minutes: 5,
|
||||
nibp_auto_measurement: false,
|
||||
nibp_no_reading: false,
|
||||
nibp_cuff_on_spo2: false,
|
||||
nibp_cuff_on_art: false,
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ struct Cycle {
|
|||
pub struct NibpMachine {
|
||||
cycle: Option<Cycle>,
|
||||
ever_started: bool,
|
||||
auto_enabled_on_last_update: bool,
|
||||
ever_successful: bool,
|
||||
last_completed: Option<f64>,
|
||||
last_reading: Option<NibpReading>,
|
||||
|
|
@ -47,6 +48,7 @@ impl NibpMachine {
|
|||
Self {
|
||||
cycle: None,
|
||||
ever_started: false,
|
||||
auto_enabled_on_last_update: false,
|
||||
ever_successful: false,
|
||||
last_completed: None,
|
||||
last_reading: None,
|
||||
|
|
@ -146,17 +148,22 @@ impl NibpMachine {
|
|||
self.ever_started = true;
|
||||
}
|
||||
|
||||
/// The initial cycle starts at simulation time zero. Afterwards, the
|
||||
/// interval is counted from the last completed measurement, not cycle start.
|
||||
/// Automatic cycles only start if the instructor enabled Auto measurement.
|
||||
/// In-flight manual/automatic cycles complete even after Auto is turned off.
|
||||
/// When Auto is switched on, a cycle begins immediately (if idle);
|
||||
/// later cycles start at the interval after the previous completion.
|
||||
pub fn update(&mut self, now: f64, p: &Parameters, quality_at_start: Spo2Quality) {
|
||||
if now < 0.0 { return; }
|
||||
let just_enabled_auto = p.nibp_auto_measurement && !self.auto_enabled_on_last_update;
|
||||
self.auto_enabled_on_last_update = p.nibp_auto_measurement;
|
||||
if let Some(cycle) = self.cycle {
|
||||
if now - cycle.start >= cycle.duration {
|
||||
self.complete(now, p, cycle);
|
||||
}
|
||||
} else if !self.ever_started || self.last_completed.is_some_and(|last| {
|
||||
now - last >= f64::from(p.nibp_interval_minutes.max(1)) * 60.0
|
||||
}) {
|
||||
} else if p.nibp_auto_measurement &&
|
||||
(just_enabled_auto || !self.ever_started || self.last_completed.is_some_and(|last| {
|
||||
now - last >= f64::from(p.nibp_interval_minutes.max(1)) * 60.0
|
||||
})) {
|
||||
self.start(now, p, quality_at_start);
|
||||
}
|
||||
}
|
||||
|
|
@ -206,9 +213,58 @@ mod tests {
|
|||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn intervals_and_first_values() {
|
||||
fn startup_is_blank_and_auto_is_disabled() {
|
||||
let p = Parameters::default();
|
||||
assert!(!p.nibp_auto_measurement);
|
||||
let mut m = NibpMachine::new();
|
||||
for t in [0.0, 20.0, 3600.0] {
|
||||
m.update(t, &p, Spo2Quality::Good);
|
||||
assert!(!m.measuring());
|
||||
assert_eq!(m.reading(), None);
|
||||
}
|
||||
// The first manual cycle completes even though automatic mode is OFF.
|
||||
m.measure_now(3601.0, &p, Spo2Quality::Good);
|
||||
assert!(m.measuring());
|
||||
m.update(3621.0, &p, Spo2Quality::Good);
|
||||
assert_eq!(m.reading(), Some(NibpReading { systolic: 118, diastolic: 74 }));
|
||||
m.update(4400.0, &p, Spo2Quality::Good);
|
||||
assert!(!m.measuring());
|
||||
// Enabling Auto starts the next cycle if the selected interval elapsed.
|
||||
let auto = Parameters { nibp_auto_measurement: true, ..p };
|
||||
m.update(4400.01, &auto, Spo2Quality::Good);
|
||||
assert!(m.measuring());
|
||||
// Disabling Auto again doesn't cancel this running cycle.
|
||||
m.update(4420.01, &Parameters::default(), Spo2Quality::Good);
|
||||
assert!(!m.measuring());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn turning_auto_on_after_manual_measurement_starts_new_cycle() {
|
||||
let mut m = NibpMachine::new();
|
||||
let p = Parameters::default();
|
||||
m.measure_now(0.0, &p, Spo2Quality::Good);
|
||||
m.update(20.0, &p, Spo2Quality::Good);
|
||||
assert!(m.reading().is_some());
|
||||
assert!(!m.measuring());
|
||||
// No need to wait five minutes after a manual measurement to enable Auto.
|
||||
let auto = Parameters { nibp_auto_measurement: true, ..p };
|
||||
m.update(21.0, &auto, Spo2Quality::Good);
|
||||
assert!(m.measuring());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enabling_auto_starts_first_measurement_without_preexisting_reading() {
|
||||
let mut m = NibpMachine::new();
|
||||
let p = Parameters { nibp_auto_measurement: true, ..Parameters::default() };
|
||||
m.update(10.0, &p, Spo2Quality::Good);
|
||||
assert!(m.measuring());
|
||||
assert_eq!(m.reading(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn intervals_and_first_values() {
|
||||
let mut m = NibpMachine::new();
|
||||
let p = Parameters { nibp_auto_measurement: true, ..Parameters::default() };
|
||||
m.update(0.0, &p, Spo2Quality::Good);
|
||||
assert!(m.measuring());
|
||||
assert_eq!(m.reading(), None);
|
||||
|
|
@ -233,7 +289,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn failed_measurement_and_retry_cycle() {
|
||||
let p = Parameters { nibp_no_reading: true, ..Parameters::default() };
|
||||
let p = Parameters { nibp_no_reading: true, nibp_auto_measurement: true,
|
||||
..Parameters::default() };
|
||||
let mut m = NibpMachine::new();
|
||||
m.update(0.0, &p, Spo2Quality::Good);
|
||||
assert!(m.measuring());
|
||||
|
|
@ -246,7 +303,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn cuff_interference_never_improves_quality() {
|
||||
let p = Parameters { nibp_cuff_on_spo2: true, ..Parameters::default() };
|
||||
let p = Parameters { nibp_cuff_on_spo2: true, nibp_auto_measurement: true,
|
||||
..Parameters::default() };
|
||||
let mut m = NibpMachine::new();
|
||||
m.update(0.0, &p, Spo2Quality::Good);
|
||||
assert_eq!(m.effective_spo2_quality(2.6, &p), Spo2Quality::None);
|
||||
|
|
@ -269,7 +327,7 @@ mod more_tests {
|
|||
(Spo2Quality::None, 120.0),
|
||||
] {
|
||||
let mut machine = NibpMachine::new();
|
||||
let p = Parameters::default();
|
||||
let p = Parameters { nibp_auto_measurement: true, ..Parameters::default() };
|
||||
machine.update(0.0, &p, quality);
|
||||
machine.update(seconds - 0.01, &p, quality);
|
||||
assert!(machine.measuring());
|
||||
|
|
@ -278,14 +336,15 @@ mod more_tests {
|
|||
assert_eq!(machine.reading().is_some(), quality != Spo2Quality::None);
|
||||
}
|
||||
let mut machine = NibpMachine::new();
|
||||
let p = Parameters::default();
|
||||
let p = Parameters { nibp_auto_measurement: true, ..Parameters::default() };
|
||||
machine.update(0.0, &p, Spo2Quality::Poor);
|
||||
assert!((60.0..=120.0).contains(&machine.cycle.unwrap().duration));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn first_successful_reading_uses_admin_even_after_failed_cycle() {
|
||||
let mut p = Parameters { nibp_no_reading: true, ..Parameters::default() };
|
||||
let mut p = Parameters { nibp_no_reading: true, nibp_auto_measurement: true,
|
||||
..Parameters::default() };
|
||||
let mut machine = NibpMachine::new();
|
||||
machine.update(0.0, &p, Spo2Quality::None);
|
||||
machine.update(120.0, &p, Spo2Quality::None);
|
||||
|
|
@ -298,7 +357,8 @@ mod more_tests {
|
|||
|
||||
#[test]
|
||||
fn partial_pressure_uses_diastic_and_systolic_boundaries() {
|
||||
let p = Parameters { nibp_cuff_on_art: true, ..Parameters::default() };
|
||||
let p = Parameters { nibp_cuff_on_art: true, nibp_auto_measurement: true,
|
||||
..Parameters::default() };
|
||||
let mut machine = NibpMachine::new();
|
||||
machine.update(0.0, &p, Spo2Quality::Good);
|
||||
assert_eq!(machine.cuff_zone(2.6, &p), CuffZone::Occluded);
|
||||
|
|
|
|||
|
|
@ -85,18 +85,41 @@ pub fn draw(cr: &Context, width: i32, height: i32, p: &Parameters, sim: &Simulat
|
|||
numeric_width, p, sim);
|
||||
}
|
||||
|
||||
/// Same geometry as the Cairo renderer: the full first ECG row (waveform
|
||||
/// and numeric region) is one target for touch, pen, or mouse interaction.
|
||||
/// Hidden ECG is never interactive; other rows and the header are excluded.
|
||||
pub fn ecg_hit_test(x: f64, y: f64, width: i32, height: i32, p: &Parameters) -> bool {
|
||||
if !p.show_ecg { return false; }
|
||||
/// Touch regions track the actual layout, including hidden and reordered rows.
|
||||
/// The last row uses four equal cells: only the NIBP cell is interactive.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum TouchChannel { Ecg, Spo2, Art, Capno, Nibp }
|
||||
|
||||
pub fn monitor_hit_test(x: f64, y: f64, width: i32, height: i32,
|
||||
p: &Parameters) -> Option<TouchChannel> {
|
||||
let w = f64::from(width.max(1));
|
||||
let h = f64::from(height.max(1));
|
||||
let pad = (w.min(h) * 0.018).clamp(6.0, 20.0);
|
||||
let header = (h * 0.083).clamp(32.0, 68.0);
|
||||
if x < pad || x > w - pad || y < header || y >= h - pad {
|
||||
return None;
|
||||
}
|
||||
let channels = visible_channels(p);
|
||||
let body_height = (h - header - pad).max(20.0);
|
||||
let (row_height, _) = monitor_rows(header, body_height, visible_channels(p).len());
|
||||
x >= pad && x <= w - pad && y >= header && y < header + row_height
|
||||
let (row_height, measurements_top) = monitor_rows(header, body_height, channels.len());
|
||||
if y >= measurements_top {
|
||||
let (split_x, _) = monitor_columns(w, pad);
|
||||
return if p.show_nibp && x >= split_x { Some(TouchChannel::Nibp) }
|
||||
else { None };
|
||||
}
|
||||
let index = ((y - header) / row_height) as usize;
|
||||
match channels.get(index).map(|entry| entry.0) {
|
||||
Some(Channel::Ecg) => Some(TouchChannel::Ecg),
|
||||
Some(Channel::Pleth) => Some(TouchChannel::Spo2),
|
||||
Some(Channel::Art) => Some(TouchChannel::Art),
|
||||
Some(Channel::Capno) => Some(TouchChannel::Capno),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn ecg_hit_test(x: f64, y: f64, width: i32, height: i32, p: &Parameters) -> bool {
|
||||
monitor_hit_test(x, y, width, height, p) == Some(TouchChannel::Ecg)
|
||||
}
|
||||
|
||||
/// Left/right split and the width of each bottom-row group. Outer margins
|
||||
|
|
@ -177,10 +200,14 @@ fn draw_nibp_box(cr: &Context, x: f64, top: f64, width: f64, height: f64,
|
|||
let progress_width = (width - 9.0).max(8.0);
|
||||
stroke_line(cr, x, progress_y, x + progress_width, progress_y, MUTED, 4.0);
|
||||
stroke_line(cr, x, progress_y,
|
||||
x + progress_width * sim.nibp().interval_progress(sim.time(), p.nibp_interval_minutes),
|
||||
x + progress_width * (if p.nibp_auto_measurement {
|
||||
sim.nibp().interval_progress(sim.time(), p.nibp_interval_minutes)
|
||||
} else { 0.0 }),
|
||||
progress_y, RED, 4.0);
|
||||
text(cr, &format!("Every {} min", p.nibp_interval_minutes),
|
||||
x, top + height * 0.97, small * 0.85, MUTED, false);
|
||||
let schedule = if p.nibp_auto_measurement {
|
||||
format!("Auto {} min", p.nibp_interval_minutes)
|
||||
} else { "AUTO OFF".to_owned() };
|
||||
text(cr, &schedule, x, top + height * 0.97, small * 0.85, MUTED, false);
|
||||
|
||||
// Vertical cuff-pressure gauge (0..200 mmHg), always visible when measuring.
|
||||
let gauge_x = right - 15.0;
|
||||
|
|
@ -771,4 +798,18 @@ mod tests {
|
|||
s.art = 0.0;
|
||||
assert_eq!(normalized(Channel::Art, &s, &p), 0.0);
|
||||
}
|
||||
#[test]
|
||||
fn touch_hit_test_tracks_rows_and_nibp_quarter() {
|
||||
let p = Parameters::default();
|
||||
assert_eq!(monitor_hit_test(140.0, 110.0, 1200, 760, &p), Some(TouchChannel::Ecg));
|
||||
assert_eq!(monitor_hit_test(1100.0, 250.0, 1200, 760, &p), Some(TouchChannel::Spo2));
|
||||
assert_eq!(monitor_hit_test(120.0, 400.0, 1200, 760, &p), Some(TouchChannel::Art));
|
||||
assert_eq!(monitor_hit_test(1100.0, 540.0, 1200, 760, &p), Some(TouchChannel::Capno));
|
||||
assert_eq!(monitor_hit_test(1100.0, 700.0, 1200, 760, &p), Some(TouchChannel::Nibp));
|
||||
assert_eq!(monitor_hit_test(800.0, 700.0, 1200, 760, &p), None);
|
||||
let p = Parameters { show_spo2: false, show_nibp: false, ..p };
|
||||
assert_eq!(monitor_hit_test(1100.0, 310.0, 1200, 760, &p), Some(TouchChannel::Art));
|
||||
assert_eq!(monitor_hit_test(1100.0, 700.0, 1200, 760, &p), None);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1014,6 +1014,7 @@ mod tests {
|
|||
let p = Parameters {
|
||||
nibp_cuff_on_spo2: true,
|
||||
nibp_cuff_on_art: true,
|
||||
nibp_auto_measurement: true,
|
||||
..Parameters::default()
|
||||
};
|
||||
let mut sim = Simulator::new(&p);
|
||||
|
|
|
|||
|
|
@ -15,9 +15,11 @@ use crate::render;
|
|||
use crate::simulation::Simulator;
|
||||
|
||||
type SharedParams = Rc<RefCell<Parameters>>;
|
||||
/// Refresh the Admin alarm widgets when a limit is changed on the monitor.
|
||||
type EcgAlarmChanged = Rc<RefCell<Option<Box<dyn Fn(AlarmLimits, EcgLead, bool)>>>>;
|
||||
type EcgMenuHandle = Rc<RefCell<Option<glib::WeakRef<gtk::Window>>>>;
|
||||
/// Refresh all Admin widgets whenever a monitor touch-menu commits changes.
|
||||
/// The bool indicates whether alarm limits changed (mark preset as Custom).
|
||||
type AdminChanged = Rc<RefCell<Option<Box<dyn Fn(bool)>>>>;
|
||||
/// At most one modal monitor settings panel is open at once.
|
||||
type MonitorMenuHandle = Rc<RefCell<Option<glib::WeakRef<gtk::Window>>>>;
|
||||
|
||||
// Match the RGB colors of the monitor traces (see render.rs).
|
||||
// NIBP shares the arterial-pressure red; capnography is light grey.
|
||||
|
|
@ -31,12 +33,12 @@ pub fn create_windows(app: &Application) {
|
|||
let parameters = Rc::new(RefCell::new(Parameters::default()));
|
||||
let simulator = Rc::new(RefCell::new(Simulator::new(¶meters.borrow())));
|
||||
let audio = Rc::new(RefCell::new(AlarmAudio::new()));
|
||||
install_ecg_menu_style();
|
||||
let ecg_alarm_changed: EcgAlarmChanged = Rc::new(RefCell::new(None));
|
||||
install_ecg_menu_style(); // neutral style shared by all parameter panels
|
||||
let admin_changed: AdminChanged = Rc::new(RefCell::new(None));
|
||||
let monitor = create_monitor(app, parameters.clone(), simulator.clone(),
|
||||
ecg_alarm_changed.clone());
|
||||
admin_changed.clone());
|
||||
let admin = create_admin(app, parameters.clone(), simulator.clone(), &monitor,
|
||||
audio.clone(), ecg_alarm_changed);
|
||||
audio.clone(), admin_changed);
|
||||
|
||||
// Alarm evaluation has its own 100-ms timer; waveform drawing never blocks
|
||||
// on sound playback. Audio also continues if the monitor is not mapped.
|
||||
|
|
@ -54,7 +56,7 @@ pub fn create_windows(app: &Application) {
|
|||
|
||||
fn create_monitor(app: &Application, params: SharedParams,
|
||||
simulator: Rc<RefCell<Simulator>>,
|
||||
ecg_alarm_changed: EcgAlarmChanged) -> ApplicationWindow {
|
||||
admin_changed: AdminChanged) -> ApplicationWindow {
|
||||
let window = ApplicationWindow::builder()
|
||||
.application(app)
|
||||
.title(concat!("Patient Monitor — Simulation v", env!("CARGO_PKG_VERSION")))
|
||||
|
|
@ -78,6 +80,7 @@ fn create_monitor(app: &Application, params: SharedParams,
|
|||
let previous = Rc::new(Cell::new(Instant::now()));
|
||||
canvas.add_tick_callback({
|
||||
let params = params.clone();
|
||||
let simulator = simulator.clone();
|
||||
move |area, _frame_clock| {
|
||||
let now = Instant::now();
|
||||
let elapsed = now.saturating_duration_since(previous.get()).as_secs_f64();
|
||||
|
|
@ -105,9 +108,10 @@ fn create_monitor(app: &Application, params: SharedParams,
|
|||
});
|
||||
window.add_controller(keys);
|
||||
|
||||
// A single touch/mouse target covers the entire ECG row (trace and HR).
|
||||
// GTK's gesture handles Wayland touch and pointer events alike.
|
||||
let ecg_menu: EcgMenuHandle = Rc::new(RefCell::new(None));
|
||||
// One gesture covers each visible waveform/numeric row and the NIBP
|
||||
// quarter of the bottom row. Hit regions are computed by the renderer,
|
||||
// so mouse and Wayland touch share the same dynamic geometry.
|
||||
let monitor_menu: MonitorMenuHandle = Rc::new(RefCell::new(None));
|
||||
let click = gtk::GestureClick::new();
|
||||
click.connect_released({
|
||||
let app = app.clone();
|
||||
|
|
@ -115,13 +119,16 @@ fn create_monitor(app: &Application, params: SharedParams,
|
|||
let canvas = canvas.clone();
|
||||
let params = params.clone();
|
||||
move |_gesture, _press_count, x, y| {
|
||||
let ecg_touched = {
|
||||
let touched = {
|
||||
let p = params.borrow();
|
||||
render::ecg_hit_test(x, y, canvas.width(), canvas.height(), &p)
|
||||
render::monitor_hit_test(x, y, canvas.width(), canvas.height(), &p)
|
||||
};
|
||||
if ecg_touched {
|
||||
open_ecg_menu(&app, &window, params.clone(),
|
||||
ecg_alarm_changed.clone(), ecg_menu.clone());
|
||||
match touched {
|
||||
Some(render::TouchChannel::Ecg) => open_ecg_menu(&app, &window,
|
||||
params.clone(), admin_changed.clone(), monitor_menu.clone()),
|
||||
Some(channel) => open_module_menu(&app, &window, params.clone(),
|
||||
simulator.clone(), admin_changed.clone(), monitor_menu.clone(), channel),
|
||||
None => (),
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -134,7 +141,7 @@ fn create_admin(app: &Application, params: SharedParams,
|
|||
simulator: Rc<RefCell<Simulator>>,
|
||||
monitor: &ApplicationWindow,
|
||||
audio: Rc<RefCell<AlarmAudio>>,
|
||||
ecg_alarm_changed: EcgAlarmChanged) -> ApplicationWindow {
|
||||
admin_changed: AdminChanged) -> ApplicationWindow {
|
||||
let window = ApplicationWindow::builder()
|
||||
.application(app)
|
||||
.title(concat!("Patient Monitor — Admin v", env!("CARGO_PKG_VERSION")))
|
||||
|
|
@ -324,7 +331,7 @@ fn create_admin(app: &Application, params: SharedParams,
|
|||
move |button| params.borrow_mut().spo2_sensor_attached = !button.is_active()
|
||||
});
|
||||
spo2.append(&sensor);
|
||||
let _ = add_dropdown_at(&spo2, "Signal quality", &[
|
||||
let spo2_quality_dropdown = add_dropdown_at(&spo2, "Signal quality", &[
|
||||
"0 — None (no reading)",
|
||||
"1 — Poor (*)",
|
||||
"2 — Adequate (**)",
|
||||
|
|
@ -399,9 +406,9 @@ ART and pleth are delayed. VT can be perfusing; PVT, VF and asystole are pulsele
|
|||
ppv_hint.set_xalign(0.0);
|
||||
ppv_hint.set_wrap(true);
|
||||
art.append(&ppv_hint);
|
||||
add_dropdown(&art, "Arterial waveform", &[
|
||||
let art_shape_dropdown = add_dropdown_at(&art, "Arterial waveform", &[
|
||||
"Normal", "Damped", "Hyperdynamic",
|
||||
], params.clone(), |p, selected| {
|
||||
], 0, params.clone(), |p, selected| {
|
||||
p.arterial_shape = match selected {
|
||||
1 => ArterialShape::Damped,
|
||||
2 => ArterialShape::Hyperdynamic,
|
||||
|
|
@ -425,20 +432,31 @@ ART and pleth are delayed. VT can be perfusing; PVT, VF and asystole are pulsele
|
|||
params.borrow().alarms.nibp_dia, params.clone(), |p, v| p.alarms.nibp_dia = v,
|
||||
&preset_dropdown, &updating_preset), |s| s.nibp_dia));
|
||||
|
||||
let _nibp_interval = add_dropdown_at(&nibp, "Measurement interval",
|
||||
let nibp_interval_dropdown = add_dropdown_at(&nibp, "Measurement interval",
|
||||
&["1 min", "3 min", "5 min", "10 min", "20 min", "30 min", "60 min"],
|
||||
2, params.clone(), |p, selected| {
|
||||
p.nibp_interval_minutes = match selected {
|
||||
0 => 1, 1 => 3, 2 => 5, 3 => 10, 4 => 20, 5 => 30, _ => 60,
|
||||
};
|
||||
});
|
||||
for (caption, current, update) in [
|
||||
let nibp_auto = gtk::CheckButton::with_label("Automatic NIBP measurement");
|
||||
nibp_auto.set_active(params.borrow().nibp_auto_measurement);
|
||||
nibp_auto.connect_toggled({
|
||||
let params = params.clone();
|
||||
move |button| params.borrow_mut().nibp_auto_measurement = button.is_active()
|
||||
});
|
||||
nibp.append(&nibp_auto);
|
||||
let mut nibp_extra_toggles: Vec<(gtk::CheckButton, fn(&Parameters) -> bool)> = Vec::new();
|
||||
for (caption, current, update, getter) in [
|
||||
("No reading (simulate failure)", params.borrow().nibp_no_reading,
|
||||
(|p: &mut Parameters, on| p.nibp_no_reading = on) as fn(&mut Parameters, bool)),
|
||||
(|p: &mut Parameters, on| p.nibp_no_reading = on) as fn(&mut Parameters, bool),
|
||||
(|p: &Parameters| p.nibp_no_reading) as fn(&Parameters) -> bool),
|
||||
("Cuff on SpO₂ extremity", params.borrow().nibp_cuff_on_spo2,
|
||||
(|p: &mut Parameters, on| p.nibp_cuff_on_spo2 = on) as fn(&mut Parameters, bool)),
|
||||
(|p: &mut Parameters, on| p.nibp_cuff_on_spo2 = on) as fn(&mut Parameters, bool),
|
||||
(|p: &Parameters| p.nibp_cuff_on_spo2) as fn(&Parameters) -> bool),
|
||||
("Cuff on ART extremity", params.borrow().nibp_cuff_on_art,
|
||||
(|p: &mut Parameters, on| p.nibp_cuff_on_art = on) as fn(&mut Parameters, bool)),
|
||||
(|p: &mut Parameters, on| p.nibp_cuff_on_art = on) as fn(&mut Parameters, bool),
|
||||
(|p: &Parameters| p.nibp_cuff_on_art) as fn(&Parameters) -> bool),
|
||||
] {
|
||||
let checkbox = gtk::CheckButton::with_label(caption);
|
||||
checkbox.set_active(current);
|
||||
|
|
@ -447,6 +465,7 @@ ART and pleth are delayed. VT can be perfusing; PVT, VF and asystole are pulsele
|
|||
move |button| update(&mut params.borrow_mut(), button.is_active())
|
||||
});
|
||||
nibp.append(&checkbox);
|
||||
nibp_extra_toggles.push((checkbox, getter));
|
||||
}
|
||||
let measure_now = gtk::Button::with_label("Measure now");
|
||||
measure_now.connect_clicked({
|
||||
|
|
@ -464,8 +483,8 @@ ART and pleth are delayed. VT can be perfusing; PVT, VF and asystole are pulsele
|
|||
|
||||
let capno = group(&controls, "Capnography", Some(MONITOR_GREY));
|
||||
add_visibility(&capno, params.borrow().show_capno, params.clone(), |p, show| p.show_capno = show);
|
||||
add_dropdown(&capno, "Capnogram", &["Normal", "Obstructive / shark fin"],
|
||||
params.clone(), |p, selected| {
|
||||
let capno_shape_dropdown = add_dropdown_at(&capno, "Capnogram", &["Normal", "Obstructive / shark fin"],
|
||||
0, params.clone(), |p, selected| {
|
||||
p.capno_shape = if selected == 1 { CapnoShape::Obstructive }
|
||||
else { CapnoShape::Normal };
|
||||
});
|
||||
|
|
@ -480,7 +499,9 @@ ART and pleth are delayed. VT can be perfusing; PVT, VF and asystole are pulsele
|
|||
params.borrow().alarms.rr, params.clone(), |p, v| p.alarms.rr = v,
|
||||
&preset_dropdown, &updating_preset), |s| s.rr));
|
||||
|
||||
let admin_alarm_editors = alarm_editors.clone();
|
||||
preset_dropdown.connect_selected_notify({
|
||||
let alarm_editors = admin_alarm_editors;
|
||||
let params = params.clone();
|
||||
let updating_preset = updating_preset.clone();
|
||||
move |dropdown| {
|
||||
|
|
@ -497,19 +518,36 @@ ART and pleth are delayed. VT can be perfusing; PVT, VF and asystole are pulsele
|
|||
}
|
||||
});
|
||||
|
||||
// Monitor settings are shared with Admin. Updating the HR alarm from the
|
||||
// ECG menu refreshes the visible alarm boxes and marks the preset Custom.
|
||||
*ecg_alarm_changed.borrow_mut() = Some(Box::new({
|
||||
// Every monitor menu commits to Parameters and refreshes visible Admin
|
||||
// widgets, without breaking preset editing or reentrant RefCell borrows.
|
||||
let admin_alarm_editors = alarm_editors.clone();
|
||||
*admin_changed.borrow_mut() = Some(Box::new({
|
||||
let params = params.clone();
|
||||
let preset_dropdown = preset_dropdown.clone();
|
||||
let updating_preset = updating_preset.clone();
|
||||
move |limits: AlarmLimits, lead: EcgLead, alarm_changed: bool| {
|
||||
if alarm_changed {
|
||||
updating_preset.set(true);
|
||||
hr_alarm_editor.set_limits(limits);
|
||||
updating_preset.set(false);
|
||||
preset_dropdown.set_selected(0);
|
||||
move |alarm_changed: bool| {
|
||||
let snapshot = params.borrow().clone();
|
||||
updating_preset.set(true);
|
||||
for (editor, get_limits) in &admin_alarm_editors {
|
||||
editor.set_limits(get_limits(&snapshot.alarms));
|
||||
}
|
||||
updating_preset.set(false);
|
||||
if alarm_changed { preset_dropdown.set_selected(0); }
|
||||
lead_dropdown.set_selected(snapshot.ecg_lead.index());
|
||||
spo2_quality_dropdown.set_selected(snapshot.spo2_quality as u32);
|
||||
sensor.set_active(!snapshot.spo2_sensor_attached);
|
||||
art_shape_dropdown.set_selected(match snapshot.arterial_shape {
|
||||
ArterialShape::Normal => 0, ArterialShape::Damped => 1,
|
||||
ArterialShape::Hyperdynamic => 2,
|
||||
});
|
||||
capno_shape_dropdown.set_selected(match snapshot.capno_shape {
|
||||
CapnoShape::Normal => 0, CapnoShape::Obstructive => 1,
|
||||
});
|
||||
nibp_interval_dropdown.set_selected(nibp_interval_index(snapshot.nibp_interval_minutes));
|
||||
nibp_auto.set_active(snapshot.nibp_auto_measurement);
|
||||
for (checkbox, getter) in &nibp_extra_toggles {
|
||||
checkbox.set_active(getter(&snapshot));
|
||||
}
|
||||
lead_dropdown.set_selected(lead.index());
|
||||
}
|
||||
}));
|
||||
|
||||
|
|
@ -682,8 +720,8 @@ fn ecg_touch_limit(parent: >k::Box, caption: &str,
|
|||
/// Displayed only for touches in the ECG row. The monitor window can remain
|
||||
/// fullscreen. The dialog is modal to that monitor, including on Wayland.
|
||||
fn open_ecg_menu(app: &Application, monitor: &ApplicationWindow,
|
||||
params: SharedParams, on_change: EcgAlarmChanged,
|
||||
open_menu: EcgMenuHandle) {
|
||||
params: SharedParams, on_change: AdminChanged,
|
||||
open_menu: MonitorMenuHandle) {
|
||||
if let Some(existing) = open_menu.borrow().as_ref().and_then(|weak| weak.upgrade()) {
|
||||
existing.present();
|
||||
return;
|
||||
|
|
@ -783,7 +821,7 @@ fn open_ecg_menu(app: &Application, monitor: &ApplicationWindow,
|
|||
changed
|
||||
};
|
||||
if let Some(callback) = on_change.borrow().as_ref() {
|
||||
callback(new_limits, new_lead, alarm_changed);
|
||||
callback(alarm_changed);
|
||||
}
|
||||
if let Some(window) = weak.upgrade() { window.close(); }
|
||||
}
|
||||
|
|
@ -826,6 +864,436 @@ mod ecg_touch_menu_tests {
|
|||
}
|
||||
}
|
||||
|
||||
const NIBP_INTERVALS: [i32; 7] = [1, 3, 5, 10, 20, 30, 60];
|
||||
const NIBP_INTERVAL_LABELS: [&str; 7] = [
|
||||
"1 min", "3 min", "5 min", "10 min", "20 min", "30 min", "60 min"
|
||||
];
|
||||
|
||||
fn nibp_interval_index(minutes: i32) -> u32 {
|
||||
NIBP_INTERVALS.iter().position(|&value| value == minutes).unwrap_or(2) as u32
|
||||
}
|
||||
|
||||
/// Touchscreen alarm controls for a numerical value. The two bounds are
|
||||
/// independently optional and only become active after Apply.
|
||||
struct TouchAlarmSpec {
|
||||
name: &'static str,
|
||||
unit: &'static str,
|
||||
limits: AlarmLimits,
|
||||
maximum: i32,
|
||||
step: i32,
|
||||
restore_lower: i32,
|
||||
restore_upper: i32,
|
||||
apply: fn(&mut AlarmSettings, AlarmLimits),
|
||||
}
|
||||
|
||||
struct TouchAlarmDraft {
|
||||
name: &'static str,
|
||||
lower: Rc<Cell<Option<i32>>>,
|
||||
upper: Rc<Cell<Option<i32>>>,
|
||||
apply: fn(&mut AlarmSettings, AlarmLimits),
|
||||
}
|
||||
|
||||
fn module_alarm_specs(channel: render::TouchChannel, p: &Parameters) -> Vec<TouchAlarmSpec> {
|
||||
let a = &p.alarms;
|
||||
let mut specs = Vec::new();
|
||||
macro_rules! limits {
|
||||
($name:expr, $unit:expr, $field:ident, $max:expr, $step:expr, $lo:expr, $hi:expr) => {
|
||||
specs.push(TouchAlarmSpec {
|
||||
name: $name, unit: $unit, limits: a.$field, maximum: $max,
|
||||
step: $step, restore_lower: $lo, restore_upper: $hi,
|
||||
apply: |alarms: &mut AlarmSettings, limits| alarms.$field = limits,
|
||||
});
|
||||
};
|
||||
}
|
||||
match channel {
|
||||
render::TouchChannel::Spo2 => {
|
||||
limits!("SpO₂", "%", spo2, 100, 1, 90, 100);
|
||||
limits!("Pulse rate", "bpm", pr, 240, 5, 50, 120);
|
||||
}
|
||||
render::TouchChannel::Art => {
|
||||
limits!("ART systolic", "mmHg", art_sys, 200, 5, 80, 180);
|
||||
limits!("ART MAP", "mmHg", art_map, 200, 5, 60, 100);
|
||||
limits!("ART diastolic", "mmHg", art_dia, 200, 5, 40, 100);
|
||||
limits!("PPV", "%", ppv, 60, 1, 0, 10);
|
||||
}
|
||||
render::TouchChannel::Capno => {
|
||||
limits!("EtCO₂", "mmHg", etco2, 100, 1, 30, 50);
|
||||
limits!("Respiratory rate", "/min", rr, 60, 1, 10, 20);
|
||||
}
|
||||
render::TouchChannel::Nibp => {
|
||||
limits!("NIBP systolic", "mmHg", nibp_sys, 260, 5, 80, 180);
|
||||
limits!("NIBP MAP", "mmHg", nibp_map, 260, 5, 60, 100);
|
||||
limits!("NIBP diastolic", "mmHg", nibp_dia, 260, 5, 40, 100);
|
||||
}
|
||||
render::TouchChannel::Ecg => {}
|
||||
}
|
||||
specs
|
||||
}
|
||||
|
||||
/// Generic unit-aware limit control with large +/- and ON/OFF touch buttons.
|
||||
/// Unlike the ECG-only helper, the increment and permitted range are per value.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn module_touch_limit(parent: >k::Box, caption: &str, initial: Option<i32>,
|
||||
fallback: i32, step: i32, maximum: i32) -> Rc<Cell<Option<i32>>> {
|
||||
let state = Rc::new(Cell::new(initial));
|
||||
let previous = Rc::new(Cell::new(initial.unwrap_or(fallback)));
|
||||
let row = gtk::Box::new(Orientation::Horizontal, 10);
|
||||
let caption_label = gtk::Label::new(Some(caption));
|
||||
caption_label.set_width_chars(10);
|
||||
caption_label.set_xalign(0.0);
|
||||
row.append(&caption_label);
|
||||
let minus = gtk::Button::with_label("−");
|
||||
minus.set_size_request(54, 50);
|
||||
let display = gtk::Label::new(None);
|
||||
display.add_css_class("ecg-limit-value");
|
||||
display.set_xalign(0.5);
|
||||
display.set_width_chars(5);
|
||||
let plus = gtk::Button::with_label("+");
|
||||
plus.set_size_request(54, 50);
|
||||
let toggle = gtk::Button::new();
|
||||
toggle.set_size_request(78, 50);
|
||||
show_touch_hr_limit(initial, &display, &toggle);
|
||||
row.append(&minus);
|
||||
row.append(&display);
|
||||
row.append(&plus);
|
||||
row.append(&toggle);
|
||||
for (button, direction) in [(minus, -1), (plus, 1)] {
|
||||
let state = state.clone();
|
||||
let previous = previous.clone();
|
||||
let display = display.clone();
|
||||
let toggle = toggle.clone();
|
||||
button.connect_clicked(move |_| {
|
||||
let new_value = state.get().map_or(previous.get(), |current| {
|
||||
(current + direction * step).clamp(0, maximum)
|
||||
});
|
||||
state.set(Some(new_value));
|
||||
previous.set(new_value);
|
||||
show_touch_hr_limit(Some(new_value), &display, &toggle);
|
||||
});
|
||||
}
|
||||
toggle.connect_clicked({
|
||||
let state = state.clone();
|
||||
let previous = previous.clone();
|
||||
let display = display.clone();
|
||||
move |button| {
|
||||
let new_value = match state.get() {
|
||||
Some(value) => { previous.set(value); None }
|
||||
None => Some(previous.get()),
|
||||
};
|
||||
state.set(new_value);
|
||||
show_touch_hr_limit(new_value, &display, button);
|
||||
}
|
||||
});
|
||||
parent.append(&row);
|
||||
state
|
||||
}
|
||||
|
||||
fn module_touch_selector(parent: >k::Box, label: &str, items: &[&str],
|
||||
selected: u32) -> gtk::DropDown {
|
||||
let row = gtk::Box::new(Orientation::Horizontal, 12);
|
||||
let heading = gtk::Label::new(Some(label));
|
||||
heading.set_xalign(0.0);
|
||||
heading.set_width_chars(17);
|
||||
let dropdown = gtk::DropDown::from_strings(items);
|
||||
dropdown.set_selected(selected);
|
||||
dropdown.set_hexpand(true);
|
||||
row.append(&heading);
|
||||
row.append(&dropdown);
|
||||
parent.append(&row);
|
||||
dropdown
|
||||
}
|
||||
|
||||
fn module_touch_checkbox(parent: >k::Box, text: &str, selected: bool) -> gtk::CheckButton {
|
||||
let control = gtk::CheckButton::with_label(text);
|
||||
control.set_active(selected);
|
||||
parent.append(&control);
|
||||
control
|
||||
}
|
||||
|
||||
/// Open a modal settings panel using the same black, grey, 0.8 px divider and
|
||||
/// border design as the ECG panel. All settings except Measure now are drafts.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn open_module_menu(app: &Application, monitor: &ApplicationWindow,
|
||||
params: SharedParams, simulator: Rc<RefCell<Simulator>>,
|
||||
on_change: AdminChanged, open_menu: MonitorMenuHandle,
|
||||
channel: render::TouchChannel) {
|
||||
if let Some(existing) = open_menu.borrow().as_ref().and_then(|weak| weak.upgrade()) {
|
||||
existing.present();
|
||||
return;
|
||||
}
|
||||
let current = params.borrow().clone();
|
||||
let title = match channel {
|
||||
render::TouchChannel::Spo2 => "SpO₂ / SETTINGS",
|
||||
render::TouchChannel::Art => "ART / SETTINGS",
|
||||
render::TouchChannel::Capno => "CO₂ / SETTINGS",
|
||||
render::TouchChannel::Nibp => "NIBP / SETTINGS",
|
||||
render::TouchChannel::Ecg => return,
|
||||
};
|
||||
let dialog = gtk::Window::builder()
|
||||
.application(app)
|
||||
.title(title)
|
||||
.transient_for(monitor)
|
||||
.modal(true)
|
||||
.resizable(true)
|
||||
.default_width(560)
|
||||
.default_height(if channel == render::TouchChannel::Art { 720 } else { 610 })
|
||||
.build();
|
||||
dialog.add_css_class("ecg-settings");
|
||||
dialog.set_decorated(false);
|
||||
*open_menu.borrow_mut() = Some(dialog.downgrade());
|
||||
|
||||
let content = gtk::Box::new(Orientation::Vertical, 0);
|
||||
content.add_css_class("ecg-panel");
|
||||
content.set_margin_top(1);
|
||||
content.set_margin_bottom(1);
|
||||
content.set_margin_start(1);
|
||||
content.set_margin_end(1);
|
||||
let scroller = gtk::ScrolledWindow::new();
|
||||
scroller.set_vexpand(true);
|
||||
scroller.set_policy(gtk::PolicyType::Never, gtk::PolicyType::Automatic);
|
||||
let inner = gtk::Box::new(Orientation::Vertical, 12);
|
||||
inner.set_margin_top(20);
|
||||
inner.set_margin_bottom(20);
|
||||
inner.set_margin_start(20);
|
||||
inner.set_margin_end(20);
|
||||
scroller.set_child(Some(&inner));
|
||||
content.append(&scroller);
|
||||
|
||||
let heading = gtk::Label::new(Some(title));
|
||||
heading.set_xalign(0.0);
|
||||
heading.add_css_class("title-2");
|
||||
inner.append(&heading);
|
||||
inner.append(&ecg_menu_divider());
|
||||
|
||||
// Every numeric alarm has two optional bounds, editable without a keyboard.
|
||||
let specs = module_alarm_specs(channel, ¤t);
|
||||
let mut alarm_drafts = Vec::new();
|
||||
for spec in specs {
|
||||
let label = gtk::Label::new(Some(&format!("{} alarm limits · {}", spec.name, spec.unit)));
|
||||
label.set_xalign(0.0);
|
||||
inner.append(&label);
|
||||
let lower = module_touch_limit(&inner, "↓ Lower", spec.limits.lower,
|
||||
spec.restore_lower, spec.step, spec.maximum);
|
||||
let upper = module_touch_limit(&inner, "↑ Upper", spec.limits.upper,
|
||||
spec.restore_upper, spec.step, spec.maximum);
|
||||
alarm_drafts.push(TouchAlarmDraft {
|
||||
name: spec.name, lower, upper, apply: spec.apply,
|
||||
});
|
||||
inner.append(&ecg_menu_divider());
|
||||
}
|
||||
|
||||
// Dedicated sensor/measurement options relevant to each module.
|
||||
let mut mode_selector = None;
|
||||
let mut sensor_toggle = None;
|
||||
let mut nibp_auto = None;
|
||||
let mut nibp_force_failure = None;
|
||||
let mut cuff_on_spo2 = None;
|
||||
let mut cuff_on_art = None;
|
||||
match channel {
|
||||
render::TouchChannel::Spo2 => {
|
||||
mode_selector = Some(module_touch_selector(&inner, "Signal quality", &[
|
||||
"0 — None", "1 — Poor", "2 — Adequate", "3 — Good",
|
||||
], current.spo2_quality as u32));
|
||||
sensor_toggle = Some(module_touch_checkbox(&inner,
|
||||
"Sensor not attached", !current.spo2_sensor_attached));
|
||||
}
|
||||
render::TouchChannel::Art => {
|
||||
mode_selector = Some(module_touch_selector(&inner, "Arterial waveform", &[
|
||||
"Normal", "Damped", "Hyperdynamic",
|
||||
], match current.arterial_shape {
|
||||
ArterialShape::Normal => 0, ArterialShape::Damped => 1,
|
||||
ArterialShape::Hyperdynamic => 2,
|
||||
}));
|
||||
}
|
||||
render::TouchChannel::Capno => {
|
||||
mode_selector = Some(module_touch_selector(&inner, "Capnogram", &[
|
||||
"Normal", "Obstructive / shark fin",
|
||||
], match current.capno_shape {
|
||||
CapnoShape::Normal => 0, CapnoShape::Obstructive => 1,
|
||||
}));
|
||||
}
|
||||
render::TouchChannel::Nibp => {
|
||||
mode_selector = Some(module_touch_selector(&inner, "Interval", &NIBP_INTERVAL_LABELS,
|
||||
nibp_interval_index(current.nibp_interval_minutes)));
|
||||
nibp_auto = Some(module_touch_checkbox(&inner, "Automatic measurement",
|
||||
current.nibp_auto_measurement));
|
||||
nibp_force_failure = Some(module_touch_checkbox(&inner, "No reading (simulate failure)",
|
||||
current.nibp_no_reading));
|
||||
cuff_on_spo2 = Some(module_touch_checkbox(&inner, "Cuff on SpO₂ extremity",
|
||||
current.nibp_cuff_on_spo2));
|
||||
cuff_on_art = Some(module_touch_checkbox(&inner, "Cuff on ART extremity",
|
||||
current.nibp_cuff_on_art));
|
||||
inner.append(&ecg_menu_divider());
|
||||
let measure = gtk::Button::with_label("Measure now");
|
||||
measure.set_size_request(-1, 54);
|
||||
inner.append(&measure);
|
||||
let status = gtk::Label::new(Some(
|
||||
"Manual measurement works even when Auto is OFF."
|
||||
));
|
||||
status.set_xalign(0.0);
|
||||
status.set_wrap(true);
|
||||
inner.append(&status);
|
||||
measure.connect_clicked({
|
||||
let simulator = simulator.clone();
|
||||
let params = params.clone();
|
||||
move |_| {
|
||||
let in_progress = simulator.borrow().nibp().measuring();
|
||||
if in_progress {
|
||||
status.set_text("Measurement already in progress.");
|
||||
} else {
|
||||
simulator.borrow_mut().start_nibp_now(¶ms.borrow());
|
||||
status.set_text("Cuff measurement started.");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
render::TouchChannel::Ecg => (),
|
||||
}
|
||||
inner.append(&ecg_menu_divider());
|
||||
let error = gtk::Label::new(None);
|
||||
error.set_xalign(0.0);
|
||||
error.add_css_class("menu-error");
|
||||
error.set_wrap(true);
|
||||
inner.append(&error);
|
||||
let buttons = gtk::Box::new(Orientation::Horizontal, 12);
|
||||
buttons.set_halign(gtk::Align::End);
|
||||
let cancel = gtk::Button::with_label("Cancel");
|
||||
cancel.add_css_class("ecg-close");
|
||||
cancel.connect_clicked({
|
||||
let weak = dialog.downgrade();
|
||||
move |_| { if let Some(window) = weak.upgrade() { window.close(); } }
|
||||
});
|
||||
let apply = gtk::Button::with_label("Apply");
|
||||
apply.add_css_class("ecg-apply");
|
||||
apply.connect_clicked({
|
||||
let weak = dialog.downgrade();
|
||||
move |_| {
|
||||
// Validate the complete draft first. Apply only this module's
|
||||
// fields so Admin edits in another module aren't overwritten.
|
||||
let mut selected_limits = Vec::with_capacity(alarm_drafts.len());
|
||||
for field in &alarm_drafts {
|
||||
let limits = AlarmLimits {
|
||||
lower: field.lower.get(), upper: field.upper.get(),
|
||||
};
|
||||
if !limits.valid() {
|
||||
error.set_text(&format!(
|
||||
"{}: lower limit must not exceed upper limit.", field.name));
|
||||
return;
|
||||
}
|
||||
selected_limits.push((field.apply, limits));
|
||||
}
|
||||
let changed_alarms;
|
||||
{
|
||||
let mut p = params.borrow_mut();
|
||||
let mut revised = p.alarms.clone();
|
||||
for (setter, limits) in selected_limits {
|
||||
setter(&mut revised, limits);
|
||||
}
|
||||
changed_alarms = revised != p.alarms;
|
||||
p.alarms = revised;
|
||||
match channel {
|
||||
render::TouchChannel::Spo2 => {
|
||||
if let Some(selector) = &mode_selector {
|
||||
p.spo2_quality = match selector.selected() {
|
||||
1 => Spo2Quality::Poor,
|
||||
2 => Spo2Quality::Adequate,
|
||||
3 => Spo2Quality::Good,
|
||||
_ => Spo2Quality::None,
|
||||
};
|
||||
}
|
||||
if let Some(check) = &sensor_toggle {
|
||||
p.spo2_sensor_attached = !check.is_active();
|
||||
}
|
||||
}
|
||||
render::TouchChannel::Art => {
|
||||
if let Some(selector) = &mode_selector {
|
||||
p.arterial_shape = match selector.selected() {
|
||||
1 => ArterialShape::Damped,
|
||||
2 => ArterialShape::Hyperdynamic,
|
||||
_ => ArterialShape::Normal,
|
||||
};
|
||||
}
|
||||
}
|
||||
render::TouchChannel::Capno => {
|
||||
if let Some(selector) = &mode_selector {
|
||||
p.capno_shape = if selector.selected() == 1 {
|
||||
CapnoShape::Obstructive
|
||||
} else { CapnoShape::Normal };
|
||||
}
|
||||
}
|
||||
render::TouchChannel::Nibp => {
|
||||
if let Some(selector) = &mode_selector {
|
||||
p.nibp_interval_minutes = NIBP_INTERVALS
|
||||
.get(selector.selected() as usize).copied().unwrap_or(5);
|
||||
}
|
||||
if let Some(check) = &nibp_auto {
|
||||
p.nibp_auto_measurement = check.is_active();
|
||||
}
|
||||
if let Some(check) = &nibp_force_failure {
|
||||
p.nibp_no_reading = check.is_active();
|
||||
}
|
||||
if let Some(check) = &cuff_on_spo2 {
|
||||
p.nibp_cuff_on_spo2 = check.is_active();
|
||||
}
|
||||
if let Some(check) = &cuff_on_art {
|
||||
p.nibp_cuff_on_art = check.is_active();
|
||||
}
|
||||
}
|
||||
render::TouchChannel::Ecg => (),
|
||||
}
|
||||
}
|
||||
if let Some(callback) = on_change.borrow().as_ref() {
|
||||
callback(changed_alarms);
|
||||
}
|
||||
if let Some(window) = weak.upgrade() { window.close(); }
|
||||
}
|
||||
});
|
||||
buttons.append(&cancel);
|
||||
buttons.append(&apply);
|
||||
inner.append(&buttons);
|
||||
dialog.set_child(Some(&content));
|
||||
|
||||
let escape = gtk::EventControllerKey::new();
|
||||
escape.connect_key_pressed({
|
||||
let weak = dialog.downgrade();
|
||||
move |_, key, _, _| {
|
||||
if key == gdk::Key::Escape {
|
||||
if let Some(window) = weak.upgrade() { window.close(); }
|
||||
glib::Propagation::Stop
|
||||
} else { glib::Propagation::Proceed }
|
||||
}
|
||||
});
|
||||
dialog.add_controller(escape);
|
||||
dialog.present();
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod module_touch_menu_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn all_non_ecg_modules_have_complete_alarm_specs() {
|
||||
let p = Parameters::default();
|
||||
for (channel, expected) in [
|
||||
(render::TouchChannel::Spo2, 2),
|
||||
(render::TouchChannel::Art, 4),
|
||||
(render::TouchChannel::Capno, 2),
|
||||
(render::TouchChannel::Nibp, 3),
|
||||
] {
|
||||
let specs = module_alarm_specs(channel, &p);
|
||||
assert_eq!(specs.len(), expected);
|
||||
assert!(specs.iter().all(|spec| spec.maximum > 0 && spec.step > 0));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn interval_menu_maps_exactly_to_simulator_minutes() {
|
||||
for (index, minutes) in NIBP_INTERVALS.iter().copied().enumerate() {
|
||||
assert_eq!(nibp_interval_index(minutes), index as u32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Frame a parameter section with an optional monitor-colored left sidebar.
|
||||
/// A DrawingArea keeps the color independent of the user's GTK theme/CSS.
|
||||
fn group(parent: >k::Box, title: &str, accent: Option<AccentColor>) -> gtk::Box {
|
||||
|
|
|
|||
Loading…
Reference in a new issue