mirror of https://codeberg.org/topola/topola.git
autorouter: put autorouter in new `Invoker` object for Command pattern
This commit is contained in:
parent
d9ff08477c
commit
7bcb3926d4
|
|
@ -161,6 +161,10 @@ impl<R: RulesTrait> Autorouter<R> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn undo_autoroute(&mut self, selection: &Selection) {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn layout(&self) -> &Arc<Mutex<Layout<R>>> {
|
pub fn layout(&self) -> &Arc<Mutex<Layout<R>>> {
|
||||||
&self.layout
|
&self.layout
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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<R: RulesTrait>(
|
||||||
|
&mut self,
|
||||||
|
invoker: &mut Invoker<R>,
|
||||||
|
observer: &mut impl RouterObserverTrait<R>,
|
||||||
|
) -> bool {
|
||||||
|
match self {
|
||||||
|
Execute::Autoroute(autoroute) => autoroute.next(&mut invoker.autorouter, observer),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Invoker<R: RulesTrait> {
|
||||||
|
autorouter: Autorouter<R>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<R: RulesTrait> Invoker<R> {
|
||||||
|
pub fn new(autorouter: Autorouter<R>) -> Self {
|
||||||
|
Self { autorouter }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn execute(&mut self, command: &Command, observer: &mut impl RouterObserverTrait<R>) {
|
||||||
|
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!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
mod autorouter;
|
mod autorouter;
|
||||||
|
pub mod invoker;
|
||||||
pub mod ratsnest;
|
pub mod ratsnest;
|
||||||
pub mod selection;
|
pub mod selection;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,10 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use topola::{
|
use topola::{
|
||||||
autorouter::Autorouter,
|
autorouter::{
|
||||||
|
invoker::{Command, Execute, Invoker},
|
||||||
|
Autorouter,
|
||||||
|
},
|
||||||
drawing::{
|
drawing::{
|
||||||
dot::FixedDotIndex,
|
dot::FixedDotIndex,
|
||||||
graph::{MakePrimitive, PrimitiveIndex},
|
graph::{MakePrimitive, PrimitiveIndex},
|
||||||
|
|
@ -202,9 +205,10 @@ impl eframe::App for App {
|
||||||
let selection = overlay.selection().clone();
|
let selection = overlay.selection().clone();
|
||||||
|
|
||||||
execute(async move {
|
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 from = autoroute.navmesh().as_ref().unwrap().from();
|
||||||
let to = autoroute.navmesh().as_ref().unwrap().to();
|
let to = autoroute.navmesh().as_ref().unwrap().to();
|
||||||
|
|
||||||
|
|
@ -214,13 +218,15 @@ impl eframe::App for App {
|
||||||
shared_data.to = Some(to);
|
shared_data.to = Some(to);
|
||||||
shared_data.navmesh = autoroute.navmesh().clone();
|
shared_data.navmesh = autoroute.navmesh().clone();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while autoroute.next(
|
while execute.next(
|
||||||
&mut autorouter,
|
&mut invoker,
|
||||||
&mut DebugRouterObserver {
|
&mut DebugRouterObserver {
|
||||||
shared_data: shared_data_arc_mutex.clone(),
|
shared_data: shared_data_arc_mutex.clone(),
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
|
if let Execute::Autoroute(ref mut autoroute) = execute {
|
||||||
shared_data_arc_mutex.lock().unwrap().navmesh =
|
shared_data_arc_mutex.lock().unwrap().navmesh =
|
||||||
autoroute.navmesh().clone();
|
autoroute.navmesh().clone();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue