mirror of https://codeberg.org/topola/topola.git
cli: make command file argument named and optional
This commit is contained in:
parent
2ebd9b411b
commit
87fd5d5d05
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ impl History {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn destructure(self) -> (Vec<Command>, Vec<Command>) {
|
||||
pub fn destruct(self) -> (Vec<Command>, Vec<Command>) {
|
||||
(self.done, self.undone)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -243,7 +243,7 @@ impl<M: AccessMesadata> Invoker<M> {
|
|||
|
||||
#[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);
|
||||
|
|
|
|||
|
|
@ -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<impl AccessMesadata>) -> 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<impl AccessMesadata>, node: NodeIndex) {
|
||||
let Some(selector) = self.node_selector(board, node) else {
|
||||
return;
|
||||
|
|
@ -40,11 +54,11 @@ impl Selection {
|
|||
}
|
||||
}
|
||||
|
||||
fn select(&mut self, board: &Board<impl AccessMesadata>, selector: Selector) {
|
||||
fn select(&mut self, _board: &Board<impl AccessMesadata>, selector: Selector) {
|
||||
self.selectors.insert(selector);
|
||||
}
|
||||
|
||||
fn deselect(&mut self, board: &Board<impl AccessMesadata>, selector: &Selector) {
|
||||
fn deselect(&mut self, _board: &Board<impl AccessMesadata>, selector: &Selector) {
|
||||
self.selectors.remove(selector);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<PathBuf>,
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue