mod controllers_embedded;
mod layout;
mod liveplot_app;
mod panel_helpers;
mod run;
mod update;
pub use liveplot_app::LivePlotApp;
pub use run::run_liveplot;
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
use std::sync::atomic::{AtomicU64, Ordering};
use eframe::egui;
use crate::config::ScopeButton;
use crate::controllers::{
FFTController, LiveplotController, ScopesController, ThresholdController, TracesController,
UiActionController, WindowController,
};
use crate::data::data::LivePlotRequests;
use crate::data::hotkeys::Hotkeys;
use crate::data::traces::TracesCollection;
use crate::events::EventController;
use crate::panels::liveplot_ui::LiveplotPanel;
use crate::panels::panel_trait::Panel;
use crate::PlotCommand;
#[cfg(feature = "fft")]
use crate::panels::fft_ui::FftPanel;
use crate::panels::{
export_ui::ExportPanel, hotkeys_ui::HotkeysPanel, math_ui::MathPanel,
measurment_ui::MeasurementPanel, thresholds_ui::ThresholdsPanel, traces_ui::TracesPanel,
triggers_ui::TriggersPanel,
};
static PANEL_ID_COUNTER: AtomicU64 = AtomicU64::new(0);
pub(crate) struct EffectiveLayout {
pub top_bar_buttons: Vec<ScopeButton>,
pub sidebar_buttons: Vec<ScopeButton>,
pub show_top_bar: bool,
pub show_sidebar_panels: bool,
}
pub struct LivePlotPanel {
pub traces_data: TracesCollection,
pub overlays: Option<
Box<
dyn for<'a> FnMut(
&mut egui_plot::PlotUi,
&crate::data::scope::ScopeData,
&crate::data::traces::TracesCollection,
) + 'static,
>,
>,
pub hotkeys: Rc<RefCell<Hotkeys>>,
pub liveplot_panel: LiveplotPanel,
pub right_side_panels: Vec<Box<dyn Panel>>,
pub left_side_panels: Vec<Box<dyn Panel>>,
pub bottom_panels: Vec<Box<dyn Panel>>,
pub detached_panels: Vec<Box<dyn Panel>>,
pub empty_panels: Vec<Box<dyn Panel>>,
pub(crate) window_ctrl: Option<WindowController>,
pub(crate) ui_ctrl: Option<UiActionController>,
pub(crate) traces_ctrl: Option<TracesController>,
pub(crate) scopes_ctrl: Option<ScopesController>,
pub(crate) liveplot_ctrl: Option<LiveplotController>,
pub(crate) fft_ctrl: Option<FFTController>,
pub(crate) threshold_ctrl: Option<ThresholdController>,
pub(crate) event_ctrl: Option<EventController>,
pub(crate) threshold_event_cursors: HashMap<String, usize>,
pub pending_requests: LivePlotRequests,
pub top_bar_buttons: Option<Vec<ScopeButton>>,
pub sidebar_buttons: Option<Vec<ScopeButton>>,
pub min_height_for_top_bar: f32,
pub min_width_for_sidebar: f32,
pub min_height_for_sidebar: f32,
pub(crate) last_plot_size: egui::Vec2,
pub(crate) panel_id: u64,
pub compact: bool,
}
impl LivePlotPanel {
pub fn new(rx: std::sync::mpsc::Receiver<PlotCommand>) -> Self {
let hotkeys = Rc::new(RefCell::new(Hotkeys::default()));
Self {
traces_data: TracesCollection::new(rx),
overlays: None,
hotkeys: hotkeys.clone(),
liveplot_panel: LiveplotPanel::default(),
right_side_panels: vec![
Box::new(TracesPanel::default()),
Box::new(MathPanel::default()),
Box::new(HotkeysPanel::new(hotkeys.clone())),
Box::new(ThresholdsPanel::default()),
Box::new(TriggersPanel::default()),
Box::new(MeasurementPanel::default()),
],
left_side_panels: vec![],
#[cfg(feature = "fft")]
bottom_panels: vec![Box::new(FftPanel::default())],
#[cfg(not(feature = "fft"))]
bottom_panels: vec![],
detached_panels: vec![],
empty_panels: vec![Box::new(ExportPanel::default())],
window_ctrl: None,
ui_ctrl: None,
traces_ctrl: None,
scopes_ctrl: None,
liveplot_ctrl: None,
fft_ctrl: None,
threshold_ctrl: None,
event_ctrl: None,
threshold_event_cursors: HashMap::new(),
pending_requests: LivePlotRequests::default(),
top_bar_buttons: None,
sidebar_buttons: None,
min_height_for_top_bar: 200.0,
min_width_for_sidebar: 150.0,
min_height_for_sidebar: 200.0,
last_plot_size: egui::Vec2::new(10_000.0, 10_000.0),
panel_id: PANEL_ID_COUNTER.fetch_add(1, Ordering::Relaxed),
compact: false,
}
}
pub fn set_controllers(
&mut self,
window_ctrl: Option<WindowController>,
ui_ctrl: Option<UiActionController>,
traces_ctrl: Option<TracesController>,
scopes_ctrl: Option<ScopesController>,
liveplot_ctrl: Option<LiveplotController>,
fft_ctrl: Option<FFTController>,
threshold_ctrl: Option<ThresholdController>,
) {
self.window_ctrl = window_ctrl;
self.ui_ctrl = ui_ctrl;
self.traces_ctrl = traces_ctrl;
self.scopes_ctrl = scopes_ctrl;
self.liveplot_ctrl = liveplot_ctrl;
self.fft_ctrl = fft_ctrl;
self.threshold_ctrl = threshold_ctrl;
}
pub fn set_event_controller(&mut self, event_ctrl: Option<EventController>) {
self.event_ctrl = event_ctrl;
}
}