diff --git a/src/autorouter/autorouter.rs b/src/autorouter/autorouter.rs index 73f4d65..401e06a 100644 --- a/src/autorouter/autorouter.rs +++ b/src/autorouter/autorouter.rs @@ -161,6 +161,10 @@ impl Autorouter { ) } + pub fn undo_autoroute(&mut self, selection: &Selection) { + todo!(); + } + pub fn layout(&self) -> &Arc>> { &self.layout } diff --git a/src/autorouter/invoker.rs b/src/autorouter/invoker.rs new file mode 100644 index 0000000..a946a65 --- /dev/null +++ b/src/autorouter/invoker.rs @@ -0,0 +1,59 @@ +use crate::{ + autorouter::{selection::Selection, Autoroute, Autorouter}, + drawing::rules::RulesTrait, + router::RouterObserverTrait, +}; + +pub enum Command { + Autoroute(Selection), +} + +pub enum Execute { + Autoroute(Autoroute), +} + +impl Execute { + pub fn next( + &mut self, + invoker: &mut Invoker, + observer: &mut impl RouterObserverTrait, + ) -> bool { + match self { + Execute::Autoroute(autoroute) => autoroute.next(&mut invoker.autorouter, observer), + } + } +} + +pub struct Invoker { + autorouter: Autorouter, +} + +impl Invoker { + pub fn new(autorouter: Autorouter) -> Self { + Self { autorouter } + } + + pub fn execute(&mut self, command: &Command, observer: &mut impl RouterObserverTrait) { + let mut execute = self.execute_walk(command); + + while execute.next(self, observer) { + // + } + } + + pub fn execute_walk(&mut self, command: &Command) -> Execute { + match command { + Command::Autoroute(selection) => { + Execute::Autoroute(self.autorouter.autoroute_walk(&selection).unwrap()) + } + } + } + + pub fn undo(&mut self) { + todo!(); + } + + pub fn redo(&mut self) { + todo!(); + } +} diff --git a/src/autorouter/mod.rs b/src/autorouter/mod.rs index 001b399..a891d0f 100644 --- a/src/autorouter/mod.rs +++ b/src/autorouter/mod.rs @@ -1,4 +1,5 @@ mod autorouter; +pub mod invoker; pub mod ratsnest; pub mod selection; diff --git a/src/bin/topola-egui/app.rs b/src/bin/topola-egui/app.rs index dda88cc..65e2c0a 100644 --- a/src/bin/topola-egui/app.rs +++ b/src/bin/topola-egui/app.rs @@ -10,7 +10,10 @@ use std::{ }; use topola::{ - autorouter::Autorouter, + autorouter::{ + invoker::{Command, Execute, Invoker}, + Autorouter, + }, drawing::{ dot::FixedDotIndex, graph::{MakePrimitive, PrimitiveIndex}, @@ -202,9 +205,10 @@ impl eframe::App for App { let selection = overlay.selection().clone(); execute(async move { - let mut autorouter = Autorouter::new(layout).unwrap(); + let mut invoker = Invoker::new(Autorouter::new(layout).unwrap()); + let mut execute = invoker.execute_walk(&Command::Autoroute(selection)); - if let Some(mut autoroute) = autorouter.autoroute_walk(&selection) { + if let Execute::Autoroute(ref mut autoroute) = execute { let from = autoroute.navmesh().as_ref().unwrap().from(); let to = autoroute.navmesh().as_ref().unwrap().to(); @@ -214,13 +218,15 @@ impl eframe::App for App { shared_data.to = Some(to); shared_data.navmesh = autoroute.navmesh().clone(); } + } - while autoroute.next( - &mut autorouter, - &mut DebugRouterObserver { - shared_data: shared_data_arc_mutex.clone(), - }, - ) { + while execute.next( + &mut invoker, + &mut DebugRouterObserver { + shared_data: shared_data_arc_mutex.clone(), + }, + ) { + if let Execute::Autoroute(ref mut autoroute) = execute { shared_data_arc_mutex.lock().unwrap().navmesh = autoroute.navmesh().clone(); }