use crate::gui::experimental_kinetics_gui::controller::PlotController;
use crate::gui::experimental_kinetics_gui::controller_buttons_and_panels::{
NewExperimentDialogState, QuickActionPanelState, TopDropDownMenues, WrightPanelControllers,
};
use crate::gui::experimental_kinetics_gui::controller_filters::Mathematics;
use crate::gui::experimental_kinetics_gui::controller_kinetics::DirectProblemDialogState;
use crate::gui::experimental_kinetics_gui::controller_methods::KineticMethodsWindowState;
use crate::gui::experimental_kinetics_gui::controller_table::{
ColumnManagerState, show_column_manager_window,
};
use crate::gui::experimental_kinetics_gui::kitheplot_wrapper::KiThePlotWindowState;
use crate::gui::experimental_kinetics_gui::model::PlotModel;
use crate::gui::experimental_kinetics_gui::test_options::TestOptions;
use crate::gui::experimental_kinetics_gui::view::PlotView;
use eframe::egui;
pub struct PlotApp {
pub model: PlotModel,
pub quick_actions_state: QuickActionPanelState,
pub new_experiment_dialog: NewExperimentDialogState,
pub mathematics: Mathematics,
pub test_options: TestOptions,
pub kinetic_methods_state: KineticMethodsWindowState,
pub column_manager_state: ColumnManagerState,
pub kithe_plot_window: KiThePlotWindowState,
pub direct_problem_state: DirectProblemDialogState,
pub(crate) keyboard_input_focused_last_frame: bool,
}
impl PlotApp {
fn handle_escape(&mut self, ctx: &egui::Context) {
if self.keyboard_input_focused_last_frame
|| ctx.egui_wants_keyboard_input()
|| egui::Popup::is_any_open(ctx)
{
return;
}
let escape =
ctx.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::Escape));
if !escape {
return;
}
let top_layer = ctx.top_layer_id();
let closed = self.new_experiment_dialog.close_window_on_layer(top_layer)
|| self.column_manager_state.close_window_on_layer(top_layer)
|| self.mathematics.close_window_on_layer(top_layer)
|| self.kinetic_methods_state.close_window_on_layer(top_layer)
|| self.test_options.close_window_on_layer(top_layer)
|| self.direct_problem_state.close_window_on_layer(top_layer)
|| self.kithe_plot_window.close_window_on_layer(top_layer);
if closed {
ctx.request_repaint();
}
}
pub fn new() -> Self {
Self {
model: PlotModel::new(),
quick_actions_state: QuickActionPanelState::default(),
new_experiment_dialog: NewExperimentDialogState::new(),
mathematics: Mathematics::new(),
test_options: TestOptions::new(),
kinetic_methods_state: KineticMethodsWindowState::default(),
column_manager_state: ColumnManagerState::new(),
kithe_plot_window: KiThePlotWindowState::default(),
direct_problem_state: DirectProblemDialogState::new(),
keyboard_input_focused_last_frame: false,
}
}
pub fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
egui::Window::new("📊 Experimental Kinetics")
.open(open)
.resizable(true)
.default_size([1000.0, 700.0])
.min_size([600.0, 400.0])
.show(ctx, |ui| {
self.render_ui(ui);
});
self.kithe_plot_window.show(ctx);
}
fn render_ui(&mut self, ui: &mut egui::Ui) {
self.handle_escape(ui.ctx());
let document_generation = self.new_experiment_dialog.document_generation();
TopDropDownMenues::top_menus(
ui,
&mut self.model,
&mut self.mathematics,
&mut self.new_experiment_dialog,
&mut self.test_options,
&mut self.kithe_plot_window,
&mut self.kinetic_methods_state,
&mut self.direct_problem_state,
);
self.new_experiment_dialog
.show_new_experiment_dialogue(ui.ctx(), &mut self.model);
self.new_experiment_dialog
.show_manage_plot_dialog(ui.ctx(), &mut self.model);
self.new_experiment_dialog
.show_save_series_dialog(ui.ctx(), &mut self.model);
self.new_experiment_dialog
.show_unsaved_changes_dialog(ui.ctx(), &mut self.model);
self.test_options.show_load_testing_data_confirmation(
ui.ctx(),
&mut self.model,
&mut self.new_experiment_dialog,
);
if self.new_experiment_dialog.document_generation() != document_generation {
self.column_manager_state.clear_pending_confirmations();
self.kinetic_methods_state.on_document_replaced();
}
let workspace_cleared = show_column_manager_window(
ui.ctx(),
&mut self.model,
&mut self.column_manager_state,
&mut self.kinetic_methods_state,
&mut self.new_experiment_dialog.column_manager_open,
);
if workspace_cleared {
self.quick_actions_state = QuickActionPanelState::default();
self.new_experiment_dialog = NewExperimentDialogState::new();
self.mathematics = Mathematics::new();
self.test_options = TestOptions::new();
self.kinetic_methods_state = KineticMethodsWindowState::default();
self.column_manager_state = ColumnManagerState::default();
self.kithe_plot_window = KiThePlotWindowState::default();
self.direct_problem_state = DirectProblemDialogState::new();
self.keyboard_input_focused_last_frame = false;
}
if self.test_options.is_settings_window_open() {
self.test_options
.show_settings_window(ui.ctx(), &mut self.model);
}
self.test_options.open_requested_contextual_help(ui.ctx());
self.test_options.show_help_window_ui(ui.ctx());
self.test_options
.show_synthetic_data_window(ui.ctx(), &mut self.model);
self.test_options
.show_logs_window(ui.ctx(), &mut self.model);
ui.columns(2, |columns| {
columns[0].vertical(|ui| {
ui.heading("Data Plot");
ui.separator();
let plot_response = PlotView::render_plot(ui, &mut self.model, |plot_ui, model| {
PlotController::handle_plot_interactions(plot_ui, model);
});
plot_response.response.context_menu(|ui| {
if ui.button("Reset View").clicked() {
self.model.reset_view();
ui.ctx().request_repaint();
}
if ui.button("Clear All Selections").clicked() {
self.model.clear_selection();
self.model.clear_selection_rect();
}
});
});
columns[1].vertical(|ui| {
PlotView::render_info_panel(ui, &self.model);
ui.separator();
let _ = WrightPanelControllers::quick_action_panel(
ui,
&mut self.model,
&mut self.quick_actions_state,
&mut self.new_experiment_dialog,
);
WrightPanelControllers::handle_ui_interactions(
ui,
&mut self.model,
&mut self.new_experiment_dialog,
);
});
});
self.direct_problem_state.show(ui.ctx(), &mut self.model);
self.keyboard_input_focused_last_frame = ui.ctx().egui_wants_keyboard_input();
}
}