Compare commits
No commits in common. "fcbfa6e544ef6a8eae93e08db69f70c81ea7328c" and "619f9594cf297bbba0ff3872f8562557a235bd5b" have entirely different histories.
fcbfa6e544
...
619f9594cf
|
@ -2467,8 +2467,6 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"plate-tool-lib",
|
"plate-tool-lib",
|
||||||
"serde",
|
"serde",
|
||||||
"wasm-bindgen-futures",
|
|
||||||
"web-sys",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
/target
|
|
||||||
/dist
|
|
|
@ -13,17 +13,5 @@ eframe = { version = "0.30", default-features = false, features = [
|
||||||
]}
|
]}
|
||||||
|
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
|
||||||
env_logger = "0.11"
|
env_logger = "0.11"
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
|
||||||
wasm-bindgen-futures = "0.4"
|
|
||||||
web-sys = "0.3"
|
|
||||||
|
|
||||||
#[profile.release]
|
|
||||||
#opt-level = 2
|
|
||||||
|
|
||||||
#[profile.dev.package."*"]
|
|
||||||
#opt-level = 2
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
[build]
|
|
||||||
target = "index.html"
|
|
||||||
release = true
|
|
|
@ -1,53 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<link data-trunk rel="rust" data-bin="plate-tool-eframe" />
|
|
||||||
<title>Plate Tool</title>
|
|
||||||
<style>
|
|
||||||
html {
|
|
||||||
/* Remove touch delay: */
|
|
||||||
touch-action: manipulation;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
/* Light mode background color for what is not covered by the egui canvas,
|
|
||||||
or where the egui canvas is translucent. */
|
|
||||||
background: #909090;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
body {
|
|
||||||
/* Dark mode background color for what is not covered by the egui canvas,
|
|
||||||
or where the egui canvas is translucent. */
|
|
||||||
background: #404040;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allow canvas to fill entire web page: */
|
|
||||||
html,
|
|
||||||
body {
|
|
||||||
overflow: hidden;
|
|
||||||
margin: 0 !important;
|
|
||||||
padding: 0 !important;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make canvas fill entire document: */
|
|
||||||
canvas {
|
|
||||||
margin-right: auto;
|
|
||||||
margin-left: auto;
|
|
||||||
display: block;
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<canvas id="main_canvas"></canvas>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -6,7 +6,6 @@ use eframe::egui::{self};
|
||||||
use plate_tool_lib::plate::PlateFormat;
|
use plate_tool_lib::plate::PlateFormat;
|
||||||
|
|
||||||
use crate::main_state::{construct_fake_mainstate, MainState};
|
use crate::main_state::{construct_fake_mainstate, MainState};
|
||||||
use crate::modals::{self, ModalState};
|
|
||||||
use crate::plate::{add_plate, PlateUiState};
|
use crate::plate::{add_plate, PlateUiState};
|
||||||
use crate::transfer_menu::{self, transfer_menu, CurrentTransferState, TransferMenuState};
|
use crate::transfer_menu::{self, transfer_menu, CurrentTransferState, TransferMenuState};
|
||||||
use crate::tree::tree;
|
use crate::tree::tree;
|
||||||
|
@ -33,9 +32,9 @@ pub struct PlateToolEframe {
|
||||||
main_window_state: MainWindowState,
|
main_window_state: MainWindowState,
|
||||||
current_transfer_state: CurrentTransferState,
|
current_transfer_state: CurrentTransferState,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
modal_state: ModalState,
|
|
||||||
#[serde(skip)]
|
|
||||||
transfer_menu_state: TransferMenuState,
|
transfer_menu_state: TransferMenuState,
|
||||||
|
#[serde(skip)]
|
||||||
|
transfer_region_cache: plate_tool_lib::transfer_region_cache::TransferRegionCache,
|
||||||
main_state: MainState,
|
main_state: MainState,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,8 +45,9 @@ impl Default for PlateToolEframe {
|
||||||
destination_plate_state: Mutex::new(PlateUiState::default()),
|
destination_plate_state: Mutex::new(PlateUiState::default()),
|
||||||
main_window_state: MainWindowState::default(),
|
main_window_state: MainWindowState::default(),
|
||||||
current_transfer_state: CurrentTransferState::default(),
|
current_transfer_state: CurrentTransferState::default(),
|
||||||
modal_state: ModalState::default(),
|
|
||||||
transfer_menu_state: TransferMenuState::default(),
|
transfer_menu_state: TransferMenuState::default(),
|
||||||
|
transfer_region_cache: plate_tool_lib::transfer_region_cache::TransferRegionCache::new(
|
||||||
|
),
|
||||||
main_state: construct_fake_mainstate(),
|
main_state: construct_fake_mainstate(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ impl PlateToolEframe {
|
||||||
return eframe::get_value(storage, eframe::APP_KEY).unwrap_or_default();
|
return eframe::get_value(storage, eframe::APP_KEY).unwrap_or_default();
|
||||||
} else {
|
} else {
|
||||||
let pte: PlateToolEframe = Default::default();
|
let pte: PlateToolEframe = Default::default();
|
||||||
pte.main_state.transfer_region_cache
|
pte.transfer_region_cache
|
||||||
.generate_cache(&pte.main_state.transfers);
|
.generate_cache(&pte.main_state.transfers);
|
||||||
|
|
||||||
pte
|
pte
|
||||||
|
@ -79,9 +79,7 @@ impl eframe::App for PlateToolEframe {
|
||||||
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
|
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
|
||||||
egui::menu::bar(ui, |ui| {
|
egui::menu::bar(ui, |ui| {
|
||||||
ui.menu_button("File", |ui| {
|
ui.menu_button("File", |ui| {
|
||||||
if ui.button("New Plate").clicked() {
|
if ui.button("New").clicked() {}
|
||||||
crate::modals::open_new_plate_modal(ctx, &mut self.modal_state);
|
|
||||||
}
|
|
||||||
ui.menu_button("Export", |ui| {
|
ui.menu_button("Export", |ui| {
|
||||||
if ui.button("Export as CSV").clicked() {}
|
if ui.button("Export as CSV").clicked() {}
|
||||||
if ui.button("Export as JSON").clicked() {}
|
if ui.button("Export as JSON").clicked() {}
|
||||||
|
@ -90,7 +88,6 @@ impl eframe::App for PlateToolEframe {
|
||||||
if ui.button("Import from JSON").clicked() {}
|
if ui.button("Import from JSON").clicked() {}
|
||||||
if ui.button("Import transfer from CSV").clicked() {}
|
if ui.button("Import transfer from CSV").clicked() {}
|
||||||
});
|
});
|
||||||
if ui.button("Reset All").clicked() {}
|
|
||||||
});
|
});
|
||||||
ui.menu_button("Options", |ui| {
|
ui.menu_button("Options", |ui| {
|
||||||
ui.menu_button("Styles", |ui| {
|
ui.menu_button("Styles", |ui| {
|
||||||
|
@ -121,6 +118,7 @@ impl eframe::App for PlateToolEframe {
|
||||||
&self.current_transfer_state,
|
&self.current_transfer_state,
|
||||||
&mut self.transfer_menu_state,
|
&mut self.transfer_menu_state,
|
||||||
&mut self.main_state,
|
&mut self.main_state,
|
||||||
|
&self.transfer_region_cache,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -146,27 +144,27 @@ impl eframe::App for PlateToolEframe {
|
||||||
x.y /= 2.0;
|
x.y /= 2.0;
|
||||||
x
|
x
|
||||||
};
|
};
|
||||||
if let Some(source_pi) = self.main_state.get_current_source_plateinstance() {
|
if self.main_state.get_current_source().is_some() {
|
||||||
add_plate(
|
add_plate(
|
||||||
half_height,
|
half_height,
|
||||||
source_pi.plate.plate_format,
|
PlateFormat::W96,
|
||||||
self.main_state.get_current_transfers(),
|
&self.main_state.transfers,
|
||||||
plate_tool_lib::plate::PlateType::Source,
|
plate_tool_lib::plate::PlateType::Source,
|
||||||
&ordered_ids,
|
&ordered_ids,
|
||||||
&self.main_state.transfer_region_cache,
|
&self.transfer_region_cache,
|
||||||
Some(&self.current_transfer_state),
|
Some(&self.current_transfer_state),
|
||||||
ui,
|
ui,
|
||||||
self.source_plate_state.lock().unwrap().deref_mut(),
|
self.source_plate_state.lock().unwrap().deref_mut(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if let Some(destination_pi) = self.main_state.get_current_destination_plateinstance() {
|
if self.main_state.get_current_destination().is_some() {
|
||||||
add_plate(
|
add_plate(
|
||||||
half_height,
|
half_height,
|
||||||
destination_pi.plate.plate_format,
|
PlateFormat::W96,
|
||||||
self.main_state.get_current_transfers(),
|
&self.main_state.transfers,
|
||||||
plate_tool_lib::plate::PlateType::Destination,
|
plate_tool_lib::plate::PlateType::Destination,
|
||||||
&ordered_ids,
|
&ordered_ids,
|
||||||
&self.main_state.transfer_region_cache,
|
&self.transfer_region_cache,
|
||||||
Some(&self.current_transfer_state),
|
Some(&self.current_transfer_state),
|
||||||
ui,
|
ui,
|
||||||
self.destination_plate_state.lock().unwrap().deref_mut(),
|
self.destination_plate_state.lock().unwrap().deref_mut(),
|
||||||
|
@ -174,22 +172,5 @@ impl eframe::App for PlateToolEframe {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Modal processing
|
|
||||||
modals::show_modal_if_open(ctx, &mut self.modal_state);
|
|
||||||
if let modals::ModalState::NewPlateComplete(modals::NewPlateModalComplete(Some(pi))) =
|
|
||||||
&self.modal_state
|
|
||||||
{
|
|
||||||
let plate_type = pi.plate.plate_type;
|
|
||||||
match plate_type {
|
|
||||||
plate_tool_lib::plate::PlateType::Source => {
|
|
||||||
self.main_state.source_plates.push(pi.clone());
|
|
||||||
},
|
|
||||||
plate_tool_lib::plate::PlateType::Destination => {
|
|
||||||
self.main_state.destination_plates.push(pi.clone());
|
|
||||||
},
|
|
||||||
}
|
|
||||||
self.modal_state = modals::ModalState::None;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,4 @@ mod plate;
|
||||||
mod tree;
|
mod tree;
|
||||||
mod transfer_menu;
|
mod transfer_menu;
|
||||||
mod main_state;
|
mod main_state;
|
||||||
mod modals;
|
|
||||||
pub use app::PlateToolEframe;
|
pub use app::PlateToolEframe;
|
||||||
|
|
|
@ -1,48 +1,18 @@
|
||||||
use eframe::egui;
|
|
||||||
use eframe::*;
|
use eframe::*;
|
||||||
|
use eframe::egui;
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
fn main() -> eframe::Result{
|
||||||
fn main() -> eframe::Result {
|
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
log::info!("Shrimp!");
|
log::info!("Shrimp!");
|
||||||
|
|
||||||
let native_options = eframe::NativeOptions {
|
let native_options = eframe::NativeOptions {
|
||||||
viewport: egui::ViewportBuilder::default().with_title("Shrimp"),
|
viewport: egui::ViewportBuilder::default()
|
||||||
|
.with_title("Shrimp"),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
"PlateToolEframe",
|
"PlateToolEframe",
|
||||||
native_options,
|
native_options,
|
||||||
Box::new(|cc| Ok(Box::new(plate_tool_eframe::PlateToolEframe::new(cc)))),
|
Box::new(|cc| Ok(Box::new(plate_tool_eframe::PlateToolEframe::new(cc))))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
fn main() {
|
|
||||||
use eframe::wasm_bindgen::JsCast as _;
|
|
||||||
|
|
||||||
eframe::WebLogger::init(log::LevelFilter::Info).ok();
|
|
||||||
|
|
||||||
let web_options = eframe::WebOptions::default();
|
|
||||||
|
|
||||||
wasm_bindgen_futures::spawn_local(async {
|
|
||||||
let document = web_sys::window()
|
|
||||||
.expect("No window")
|
|
||||||
.document()
|
|
||||||
.expect("No document");
|
|
||||||
|
|
||||||
let canvas = document
|
|
||||||
.get_element_by_id("main_canvas")
|
|
||||||
.expect("Canvas id not found")
|
|
||||||
.dyn_into::<web_sys::HtmlCanvasElement>()
|
|
||||||
.expect("Canvas was not a HtmlCanvasElement");
|
|
||||||
|
|
||||||
let start_result = eframe::WebRunner::new()
|
|
||||||
.start(
|
|
||||||
canvas,
|
|
||||||
web_options,
|
|
||||||
Box::new(|cc| Ok(Box::new(plate_tool_eframe::PlateToolEframe::new(cc)))),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use plate_tool_lib::plate::PlateFormat;
|
|
||||||
use plate_tool_lib::plate_instances;
|
use plate_tool_lib::plate_instances;
|
||||||
use plate_tool_lib::transfer_region_cache::TransferRegionCache;
|
use plate_tool_lib::plate::PlateFormat;
|
||||||
|
|
||||||
#[derive(Default, Debug, serde::Serialize, serde::Deserialize)]
|
#[derive(Default, Debug, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct MainState {
|
pub struct MainState {
|
||||||
|
@ -15,86 +14,37 @@ pub struct MainState {
|
||||||
current_source: Option<plate_tool_lib::uuid::Uuid>,
|
current_source: Option<plate_tool_lib::uuid::Uuid>,
|
||||||
current_destination: Option<plate_tool_lib::uuid::Uuid>,
|
current_destination: Option<plate_tool_lib::uuid::Uuid>,
|
||||||
current_transfer: Option<plate_tool_lib::uuid::Uuid>,
|
current_transfer: Option<plate_tool_lib::uuid::Uuid>,
|
||||||
#[serde(skip)]
|
|
||||||
pub transfer_region_cache: plate_tool_lib::transfer_region_cache::TransferRegionCache,
|
|
||||||
}
|
}
|
||||||
impl MainState {
|
impl MainState {
|
||||||
pub fn get_current_source_uuid(&self) -> Option<plate_tool_lib::uuid::Uuid> {
|
pub fn get_current_source(&self) -> Option<plate_tool_lib::uuid::Uuid> {
|
||||||
self.current_source
|
self.current_source
|
||||||
}
|
}
|
||||||
pub fn get_current_source_plateinstance(
|
pub fn get_current_destination(&self) -> Option<plate_tool_lib::uuid::Uuid> {
|
||||||
&self,
|
|
||||||
) -> Option<&plate_tool_lib::plate_instances::PlateInstance> {
|
|
||||||
if let Some(id) = self.current_source {
|
|
||||||
self.source_plates.iter().find(|x| x.get_uuid() == id)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_current_destination_uuid(&self) -> Option<plate_tool_lib::uuid::Uuid> {
|
|
||||||
self.current_destination
|
self.current_destination
|
||||||
}
|
}
|
||||||
pub fn get_current_destination_plateinstance(
|
pub fn get_current_transfer(&self) -> Option<plate_tool_lib::uuid::Uuid> {
|
||||||
&self,
|
|
||||||
) -> Option<&plate_tool_lib::plate_instances::PlateInstance> {
|
|
||||||
if let Some(id) = self.current_destination {
|
|
||||||
self.destination_plates.iter().find(|x| x.get_uuid() == id)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_current_transfer_uuid(&self) -> Option<plate_tool_lib::uuid::Uuid> {
|
|
||||||
self.current_transfer
|
self.current_transfer
|
||||||
}
|
}
|
||||||
pub fn get_current_transfer_info(&self) -> Option<&plate_tool_lib::transfer::Transfer> {
|
|
||||||
if let Some(id) = self.current_transfer {
|
|
||||||
self.transfers.iter().find(|x| x.get_uuid() == id)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn get_current_transfers(&self) -> Option<Vec<&plate_tool_lib::transfer::Transfer>> {
|
|
||||||
let source_uuid = self.get_current_source_uuid();
|
|
||||||
let destination_uuid = self.get_current_destination_uuid();
|
|
||||||
if let (Some(source_uuid), Some(destination_uuid)) = (source_uuid, destination_uuid) {
|
|
||||||
Some(self.transfers
|
|
||||||
.iter()
|
|
||||||
.filter(|tr| tr.source_id == source_uuid && tr.dest_id == destination_uuid)
|
|
||||||
.collect())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_current_source(&mut self, id: plate_tool_lib::uuid::Uuid) -> bool {
|
pub fn set_current_source(&mut self, id: plate_tool_lib::uuid::Uuid) -> bool {
|
||||||
if self.check_source_exists(id) {
|
if self.source_plates.iter().map(|x| x.get_uuid()).find(|x| *x == id).is_some() {
|
||||||
self.current_source = Some(id);
|
self.current_source = Some(id);
|
||||||
self.set_no_current_transfer();
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn set_current_destination(&mut self, id: plate_tool_lib::uuid::Uuid) -> bool {
|
pub fn set_current_destination(&mut self, id: plate_tool_lib::uuid::Uuid) -> bool {
|
||||||
if self.check_destination_exists(id) {
|
if self.destination_plates.iter().map(|x| x.get_uuid()).find(|x| *x == id).is_some() {
|
||||||
self.current_destination = Some(id);
|
self.current_destination = Some(id);
|
||||||
self.set_no_current_transfer();
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn set_current_transfer(&mut self, id: plate_tool_lib::uuid::Uuid) -> bool {
|
pub fn set_current_transfer(&mut self, id: plate_tool_lib::uuid::Uuid) -> bool {
|
||||||
if let Some(tr) = self.transfers.iter().find(|x| x.get_uuid() == id) {
|
if self.transfers.iter().map(|x| x.get_uuid()).find(|x| *x == id).is_some() {
|
||||||
let source_exists = self.check_source_exists(tr.source_id);
|
self.current_transfer = Some(id);
|
||||||
let destination_exists = self.check_destination_exists(tr.dest_id);
|
|
||||||
if source_exists && destination_exists {
|
|
||||||
self.current_transfer = Some(id);
|
|
||||||
self.current_source = Some(tr.source_id);
|
|
||||||
self.current_destination = Some(tr.dest_id);
|
|
||||||
}
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -109,21 +59,6 @@ impl MainState {
|
||||||
pub fn set_no_current_transfer(&mut self) {
|
pub fn set_no_current_transfer(&mut self) {
|
||||||
self.current_transfer = None;
|
self.current_transfer = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_source_exists(&self, id: plate_tool_lib::uuid::Uuid) -> bool {
|
|
||||||
self.source_plates
|
|
||||||
.iter()
|
|
||||||
.map(|x| x.get_uuid())
|
|
||||||
.find(|x| *x == id)
|
|
||||||
.is_some()
|
|
||||||
}
|
|
||||||
fn check_destination_exists(&self, id: plate_tool_lib::uuid::Uuid) -> bool {
|
|
||||||
self.destination_plates
|
|
||||||
.iter()
|
|
||||||
.map(|x| x.get_uuid())
|
|
||||||
.find(|x| *x == id)
|
|
||||||
.is_some()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn construct_fake_mainstate() -> MainState {
|
pub fn construct_fake_mainstate() -> MainState {
|
||||||
|
@ -175,6 +110,7 @@ pub fn construct_fake_mainstate() -> MainState {
|
||||||
"Shrimp".to_owned(),
|
"Shrimp".to_owned(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
MainState {
|
MainState {
|
||||||
source_plates: vec![src_plate],
|
source_plates: vec![src_plate],
|
||||||
destination_plates: vec![dest_plate],
|
destination_plates: vec![dest_plate],
|
||||||
|
@ -182,6 +118,6 @@ pub fn construct_fake_mainstate() -> MainState {
|
||||||
current_source: None,
|
current_source: None,
|
||||||
current_destination: None,
|
current_destination: None,
|
||||||
current_transfer: None,
|
current_transfer: None,
|
||||||
transfer_region_cache: TransferRegionCache::default(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,107 +0,0 @@
|
||||||
use eframe::egui;
|
|
||||||
|
|
||||||
#[non_exhaustive]
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum ModalState {
|
|
||||||
NewPlate(NewPlateModalState),
|
|
||||||
NewPlateComplete(NewPlateModalComplete),
|
|
||||||
None,
|
|
||||||
}
|
|
||||||
impl Default for ModalState {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[non_exhaustive]
|
|
||||||
#[derive(Debug, Default)]
|
|
||||||
pub struct NewPlateModalState {
|
|
||||||
pub name: String,
|
|
||||||
pub plate_type: plate_tool_lib::plate::PlateType,
|
|
||||||
pub plate_format: plate_tool_lib::plate::PlateFormat,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[non_exhaustive]
|
|
||||||
#[derive(Debug, Default)]
|
|
||||||
pub struct NewPlateModalComplete(pub Option<plate_tool_lib::plate_instances::PlateInstance>);
|
|
||||||
|
|
||||||
pub fn show_modal_if_open(ctx: &egui::Context, modal_state: &mut ModalState) {
|
|
||||||
match modal_state {
|
|
||||||
ModalState::NewPlate(_) => show_new_plate_modal(ctx, modal_state),
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn show_new_plate_modal(ctx: &egui::Context, modal_state: &mut ModalState) {
|
|
||||||
let state: &mut NewPlateModalState = {
|
|
||||||
if let ModalState::NewPlate(x) = modal_state {
|
|
||||||
x
|
|
||||||
} else {
|
|
||||||
*modal_state = ModalState::NewPlate(NewPlateModalState::default());
|
|
||||||
if let ModalState::NewPlate(y) = modal_state {
|
|
||||||
y
|
|
||||||
} else {
|
|
||||||
unreachable!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut output: Option<plate_tool_lib::plate_instances::PlateInstance> = None;
|
|
||||||
egui::Window::new("New Plate")
|
|
||||||
.order(egui::Order::Foreground)
|
|
||||||
.collapsible(false)
|
|
||||||
.resizable(false)
|
|
||||||
.show(ctx, |ui| {
|
|
||||||
ui.vertical(|ui| {
|
|
||||||
ui.add(egui::TextEdit::singleline(&mut state.name).hint_text("Plate Name"));
|
|
||||||
egui::ComboBox::from_label("Plate Type")
|
|
||||||
.selected_text(format!("{:?}", state.plate_type))
|
|
||||||
.show_ui(ui, |ui| {
|
|
||||||
ui.selectable_value(
|
|
||||||
&mut state.plate_type,
|
|
||||||
plate_tool_lib::plate::PlateType::Source,
|
|
||||||
"Source",
|
|
||||||
);
|
|
||||||
ui.selectable_value(
|
|
||||||
&mut state.plate_type,
|
|
||||||
plate_tool_lib::plate::PlateType::Destination,
|
|
||||||
"Destination",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
egui::ComboBox::from_label("Plate Format")
|
|
||||||
.selected_text(format!("{:?}", state.plate_format))
|
|
||||||
.show_ui(ui, |ui| {
|
|
||||||
ui.selectable_value(
|
|
||||||
&mut state.plate_format,
|
|
||||||
plate_tool_lib::plate::PlateFormat::W96,
|
|
||||||
"96W",
|
|
||||||
);
|
|
||||||
ui.selectable_value(
|
|
||||||
&mut state.plate_format,
|
|
||||||
plate_tool_lib::plate::PlateFormat::W384,
|
|
||||||
"384W",
|
|
||||||
);
|
|
||||||
ui.selectable_value(
|
|
||||||
&mut state.plate_format,
|
|
||||||
plate_tool_lib::plate::PlateFormat::W1536,
|
|
||||||
"1536W",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
if ui.button("Add").clicked() {
|
|
||||||
output = Some(plate_tool_lib::plate_instances::PlateInstance::new(state.plate_type, state.plate_format, state.name.clone()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
if output.is_some() {
|
|
||||||
*modal_state = ModalState::NewPlateComplete(NewPlateModalComplete(output));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn open_new_plate_modal(
|
|
||||||
ctx: &egui::Context,
|
|
||||||
modal_state: &mut ModalState,
|
|
||||||
) {
|
|
||||||
// Do not close another modal
|
|
||||||
if matches!(modal_state, ModalState::None) {
|
|
||||||
*modal_state = ModalState::NewPlate(NewPlateModalState::default());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -125,7 +125,7 @@ fn get_well_from_pos(
|
||||||
fn calculate_shading_for_wells(
|
fn calculate_shading_for_wells(
|
||||||
rows: u8,
|
rows: u8,
|
||||||
columns: u8,
|
columns: u8,
|
||||||
transfers: Option<Vec<&plate_tool_lib::transfer::Transfer>>,
|
transfers: &Vec<plate_tool_lib::transfer::Transfer>,
|
||||||
plate_type: plate_tool_lib::plate::PlateType,
|
plate_type: plate_tool_lib::plate::PlateType,
|
||||||
ordered_ids: &[Uuid],
|
ordered_ids: &[Uuid],
|
||||||
cache: &plate_tool_lib::transfer_region_cache::TransferRegionCache,
|
cache: &plate_tool_lib::transfer_region_cache::TransferRegionCache,
|
||||||
|
@ -133,7 +133,6 @@ fn calculate_shading_for_wells(
|
||||||
let box_size: usize = rows as usize * columns as usize;
|
let box_size: usize = rows as usize * columns as usize;
|
||||||
let mut well_infos: Box<[Option<WellInfo>]> = vec![None; box_size].into_boxed_slice();
|
let mut well_infos: Box<[Option<WellInfo>]> = vec![None; box_size].into_boxed_slice();
|
||||||
|
|
||||||
if let Some(transfers) = transfers {
|
|
||||||
for transfer in transfers {
|
for transfer in transfers {
|
||||||
let cache_result = match plate_type {
|
let cache_result = match plate_type {
|
||||||
plate_tool_lib::plate::PlateType::Source => cache.get_or_calculate_source(transfer),
|
plate_tool_lib::plate::PlateType::Source => cache.get_or_calculate_source(transfer),
|
||||||
|
@ -161,7 +160,6 @@ fn calculate_shading_for_wells(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
well_infos
|
well_infos
|
||||||
}
|
}
|
||||||
|
@ -177,7 +175,7 @@ fn add_plate_sub(
|
||||||
size: egui::Vec2,
|
size: egui::Vec2,
|
||||||
rows: u8,
|
rows: u8,
|
||||||
columns: u8,
|
columns: u8,
|
||||||
transfers: Option<Vec<&plate_tool_lib::transfer::Transfer>>,
|
transfers: &Vec<plate_tool_lib::transfer::Transfer>,
|
||||||
plate_type: plate_tool_lib::plate::PlateType,
|
plate_type: plate_tool_lib::plate::PlateType,
|
||||||
ordered_ids: &[Uuid],
|
ordered_ids: &[Uuid],
|
||||||
cache: &plate_tool_lib::transfer_region_cache::TransferRegionCache,
|
cache: &plate_tool_lib::transfer_region_cache::TransferRegionCache,
|
||||||
|
@ -395,7 +393,7 @@ fn add_plate_sub(
|
||||||
pub fn add_plate(
|
pub fn add_plate(
|
||||||
size: egui::Vec2,
|
size: egui::Vec2,
|
||||||
pf: PlateFormat,
|
pf: PlateFormat,
|
||||||
transfers: Option<Vec<&plate_tool_lib::transfer::Transfer>>,
|
transfers: &Vec<plate_tool_lib::transfer::Transfer>,
|
||||||
plate_type: plate_tool_lib::plate::PlateType,
|
plate_type: plate_tool_lib::plate::PlateType,
|
||||||
ordered_ids: &[Uuid],
|
ordered_ids: &[Uuid],
|
||||||
cache: &plate_tool_lib::transfer_region_cache::TransferRegionCache,
|
cache: &plate_tool_lib::transfer_region_cache::TransferRegionCache,
|
||||||
|
|
|
@ -107,7 +107,7 @@ impl CurrentTransferStateInterior {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_new_from_main_state_transfer(ms: &MainState) -> Option<Self> {
|
pub fn try_new_from_main_state_transfer(ms: &MainState) -> Option<Self> {
|
||||||
let transfer_id = ms.get_current_transfer_uuid();
|
let transfer_id = ms.get_current_transfer();
|
||||||
let transfer = ms
|
let transfer = ms
|
||||||
.transfers
|
.transfers
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -141,8 +141,8 @@ impl CurrentTransferStateInterior {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_to_transfer(&self, ms: &MainState) -> Option<plate_tool_lib::transfer::Transfer> {
|
pub fn convert_to_transfer(&self, ms: &MainState) -> Option<plate_tool_lib::transfer::Transfer> {
|
||||||
let source_plate_uuid = ms.get_current_source_uuid()?;
|
let source_plate_uuid = ms.get_current_source()?;
|
||||||
let destination_plate_uuid = ms.get_current_destination_uuid()?;
|
let destination_plate_uuid = ms.get_current_destination()?;
|
||||||
let source_plate_instance = ms.source_plates.iter().find(|x| x.get_uuid() == source_plate_uuid)?;
|
let source_plate_instance = ms.source_plates.iter().find(|x| x.get_uuid() == source_plate_uuid)?;
|
||||||
let destination_plate_instance = ms.destination_plates.iter().find(|x| x.get_uuid() == destination_plate_uuid)?;
|
let destination_plate_instance = ms.destination_plates.iter().find(|x| x.get_uuid() == destination_plate_uuid)?;
|
||||||
let transfer = Some(plate_tool_lib::transfer::Transfer::new(
|
let transfer = Some(plate_tool_lib::transfer::Transfer::new(
|
||||||
|
@ -186,6 +186,7 @@ pub fn transfer_menu(
|
||||||
state: &CurrentTransferState,
|
state: &CurrentTransferState,
|
||||||
ui_state: &mut TransferMenuState,
|
ui_state: &mut TransferMenuState,
|
||||||
main_state: &mut MainState,
|
main_state: &mut MainState,
|
||||||
|
transfer_region_cache: &plate_tool_lib::transfer_region_cache::TransferRegionCache,
|
||||||
) {
|
) {
|
||||||
// Can we reduce the length of this lock pls
|
// Can we reduce the length of this lock pls
|
||||||
let mut state = state.lock().unwrap();
|
let mut state = state.lock().unwrap();
|
||||||
|
@ -282,12 +283,12 @@ pub fn transfer_menu(
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui.button("Save").clicked() {
|
if ui.button("Save").clicked() {
|
||||||
if let Some(transfer_uuid) = main_state.get_current_transfer_uuid() {
|
if let Some(transfer_uuid) = main_state.get_current_transfer() {
|
||||||
log::info!("should change transfer");
|
log::info!("should change transfer");
|
||||||
if let Some(mut transfer) = main_state.transfers.iter_mut().find(|x| x.id == transfer_uuid) {
|
if let Some(mut transfer) = main_state.transfers.iter_mut().find(|x| x.id == transfer_uuid) {
|
||||||
transfer.transfer_region = state.generate_transfer_region();
|
transfer.transfer_region = state.generate_transfer_region();
|
||||||
transfer.name = state.transfer_name.clone();
|
transfer.name = state.transfer_name.clone();
|
||||||
main_state.transfer_region_cache.invalidate(&transfer);
|
transfer_region_cache.invalidate(&transfer);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let new_transfer = state.convert_to_transfer(main_state);
|
let new_transfer = state.convert_to_transfer(main_state);
|
||||||
|
@ -296,7 +297,7 @@ pub fn transfer_menu(
|
||||||
main_state.transfers.push(new_transfer);
|
main_state.transfers.push(new_transfer);
|
||||||
let new_transfer = main_state.transfers.last()
|
let new_transfer = main_state.transfers.last()
|
||||||
.expect("Cannot be empty, just added a transfer");
|
.expect("Cannot be empty, just added a transfer");
|
||||||
main_state.transfer_region_cache.add_overwrite(new_transfer);
|
transfer_region_cache.add_overwrite(new_transfer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub fn tree(ui: &mut egui::Ui, ms: &mut MainState, cts: &CurrentTransferState) {
|
||||||
for (name, uuid) in ms.source_plates.iter().map(|x| (&x.name, x.get_uuid())) {
|
for (name, uuid) in ms.source_plates.iter().map(|x| (&x.name, x.get_uuid())) {
|
||||||
let f = {
|
let f = {
|
||||||
let mut f = egui::Frame::none();
|
let mut f = egui::Frame::none();
|
||||||
if ms.get_current_source_uuid().is_some_and(|x| x == uuid) {
|
if ms.get_current_source().is_some_and(|x| x == uuid) {
|
||||||
f = f.fill(*SELECT_COLOR);
|
f = f.fill(*SELECT_COLOR);
|
||||||
}
|
}
|
||||||
f
|
f
|
||||||
|
@ -28,15 +28,12 @@ pub fn tree(ui: &mut egui::Ui, ms: &mut MainState, cts: &CurrentTransferState) {
|
||||||
);
|
);
|
||||||
if r.clicked() {
|
if r.clicked() {
|
||||||
new_uuid = Some(uuid);
|
new_uuid = Some(uuid);
|
||||||
|
log::info!("{:?}", uuid);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if let Some(uuid) = new_uuid {
|
if let Some(uuid) = new_uuid {
|
||||||
ms.set_current_source(uuid);
|
ms.set_current_source(uuid);
|
||||||
ms.set_no_current_transfer();
|
|
||||||
if let Some(mut cts) = cts.lock().ok() {
|
|
||||||
*cts = CurrentTransferStateInterior::default();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -51,7 +48,7 @@ pub fn tree(ui: &mut egui::Ui, ms: &mut MainState, cts: &CurrentTransferState) {
|
||||||
{
|
{
|
||||||
let f = {
|
let f = {
|
||||||
let mut f = egui::Frame::none();
|
let mut f = egui::Frame::none();
|
||||||
if ms.get_current_destination_uuid().is_some_and(|x| x == uuid) {
|
if ms.get_current_destination().is_some_and(|x| x == uuid) {
|
||||||
f = f.fill(*SELECT_COLOR);
|
f = f.fill(*SELECT_COLOR);
|
||||||
}
|
}
|
||||||
f
|
f
|
||||||
|
@ -64,15 +61,12 @@ pub fn tree(ui: &mut egui::Ui, ms: &mut MainState, cts: &CurrentTransferState) {
|
||||||
);
|
);
|
||||||
if r.clicked() {
|
if r.clicked() {
|
||||||
new_uuid = Some(uuid);
|
new_uuid = Some(uuid);
|
||||||
|
log::info!("{:?}", uuid);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if let Some(uuid) = new_uuid {
|
if let Some(uuid) = new_uuid {
|
||||||
ms.set_current_destination(uuid);
|
ms.set_current_destination(uuid);
|
||||||
ms.set_no_current_transfer();
|
|
||||||
if let Some(mut cts) = cts.lock().ok() {
|
|
||||||
*cts = CurrentTransferStateInterior::default();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Add all transfers
|
// Add all transfers
|
||||||
|
@ -82,7 +76,7 @@ pub fn tree(ui: &mut egui::Ui, ms: &mut MainState, cts: &CurrentTransferState) {
|
||||||
for (name, uuid) in ms.transfers.iter().map(|x| (&x.name, x.get_uuid())) {
|
for (name, uuid) in ms.transfers.iter().map(|x| (&x.name, x.get_uuid())) {
|
||||||
let f = {
|
let f = {
|
||||||
let mut f = egui::Frame::none();
|
let mut f = egui::Frame::none();
|
||||||
if ms.get_current_transfer_uuid().is_some_and(|x| x == uuid) {
|
if ms.get_current_transfer().is_some_and(|x| x == uuid) {
|
||||||
f = f.fill(*SELECT_COLOR);
|
f = f.fill(*SELECT_COLOR);
|
||||||
}
|
}
|
||||||
f
|
f
|
||||||
|
|
Loading…
Reference in New Issue