diff --git a/INSTALL.md b/INSTALL.md index 9a83e14..e043071 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -47,7 +47,7 @@ simple THT diode bridge rectifier: ``` cd tests/single_layer/data/tht_diode_bridge_rectifier/ -topola tht_diode_bridge_rectifier.dsn tht_diode_bridge_rectifier.ses autoroute_all.cmd +topola tht_diode_bridge_rectifier.dsn tht_diode_bridge_rectifier.ses ``` ##### Viewing the results @@ -72,7 +72,7 @@ then as follows: ``` cd tests/single_layer/data/tht_diode_bridge_rectifier/ -cargo run --features cli -- tht_diode_bridge_rectifier.dsn tht_diode_bridge_rectifier.ses autoroute_all.cmd +cargo run --features cli -- tht_diode_bridge_rectifier.dsn tht_diode_bridge_rectifier.ses ``` Viewing the results is obviously the same. diff --git a/src/autorouter/history.rs b/src/autorouter/history.rs index ebe819b..d9f9db5 100644 --- a/src/autorouter/history.rs +++ b/src/autorouter/history.rs @@ -25,7 +25,7 @@ impl History { } } - pub fn destructure(self) -> (Vec, Vec) { + pub fn destruct(self) -> (Vec, Vec) { (self.done, self.undone) } diff --git a/src/autorouter/invoker.rs b/src/autorouter/invoker.rs index 79ba103..6e177a9 100644 --- a/src/autorouter/invoker.rs +++ b/src/autorouter/invoker.rs @@ -243,7 +243,7 @@ impl Invoker { #[debug_requires(self.ongoing_command.is_none())] pub fn replay(&mut self, history: History) { - let (done, undone) = history.destructure(); + let (done, undone) = history.destruct(); for command in done { self.execute(command); diff --git a/src/autorouter/selection.rs b/src/autorouter/selection.rs index 971eda9..7fe29c3 100644 --- a/src/autorouter/selection.rs +++ b/src/autorouter/selection.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; use crate::{ board::{mesadata::AccessMesadata, Board}, drawing::graph::{GetLayer, MakePrimitive}, - geometry::compound::ManageCompounds, + geometry::{compound::ManageCompounds, GenericNode}, graph::{GenericIndex, GetPetgraphIndex}, layout::{poly::PolyWeight, CompoundWeight, NodeIndex}, }; @@ -22,12 +22,26 @@ pub struct Selection { } impl Selection { - pub fn new() -> Selection { + pub fn new() -> Self { Self { selectors: HashSet::new(), } } + pub fn new_select_all(board: &Board) -> Self { + let mut this = Self::new(); + + for node in board.layout().drawing().primitive_nodes() { + if let Some(selector) = this.node_selector(board, GenericNode::Primitive(node)) { + if !this.contains_node(board, GenericNode::Primitive(node)) { + this.select(board, selector); + } + } + } + + this + } + pub fn toggle_at_node(&mut self, board: &Board, node: NodeIndex) { let Some(selector) = self.node_selector(board, node) else { return; @@ -40,11 +54,11 @@ impl Selection { } } - fn select(&mut self, board: &Board, selector: Selector) { + fn select(&mut self, _board: &Board, selector: Selector) { self.selectors.insert(selector); } - fn deselect(&mut self, board: &Board, selector: &Selector) { + fn deselect(&mut self, _board: &Board, selector: &Selector) { self.selectors.remove(selector); } diff --git a/src/bin/topola/main.rs b/src/bin/topola/main.rs index 00bec32..1e006f0 100644 --- a/src/bin/topola/main.rs +++ b/src/bin/topola/main.rs @@ -2,13 +2,21 @@ use clap::{Error, Parser}; use std::fs::File; use std::io::prelude::*; use std::io::BufReader; +use std::path::PathBuf; +use topola::autorouter::history::History; +use topola::autorouter::invoker::Command; +use topola::autorouter::invoker::Invoker; +use topola::autorouter::selection::Selection; +use topola::autorouter::Autorouter; +use topola::specctra::design::SpecctraDesign; #[derive(Parser, Debug, Default)] #[command(about, version)] struct Cli { - input: std::path::PathBuf, - output: std::path::PathBuf, - history: std::path::PathBuf, + input: PathBuf, + output: PathBuf, + #[arg(short, long, value_name = "FILE")] + commands: Option, } fn main() -> Result<(), std::io::Error> { @@ -17,15 +25,21 @@ fn main() -> Result<(), std::io::Error> { let design_file = File::open(args.input)?; let mut design_bufread = BufReader::new(design_file); - let design = topola::specctra::design::SpecctraDesign::load(design_bufread).unwrap(); + let design = SpecctraDesign::load(design_bufread).unwrap(); let board = design.make_board(); - let history_file = File::open(args.history)?; - let mut history_bufread = BufReader::new(history_file); - let mut invoker = topola::autorouter::invoker::Invoker::new( - topola::autorouter::Autorouter::new(board).unwrap(), - ); - invoker.replay(serde_json::from_reader(history_bufread).unwrap()); + let history = if let Some(commands_filename) = args.commands { + let command_file = File::open(commands_filename)?; + let commands_bufread = BufReader::new(command_file); + serde_json::from_reader(commands_bufread)? + } else { + let mut history = History::new(); + history.do_(Command::Autoroute(Selection::new_select_all(&board))); + history + }; + + let mut invoker = Invoker::new(Autorouter::new(board).unwrap()); + invoker.replay(history); let mut file = File::create(args.output).unwrap(); design.write_ses(invoker.autorouter().board(), &mut file);