mirror of https://codeberg.org/topola/topola.git
board,dsn: introduce `MesadataTrait`, an extension of `RulesTrait`
The trait's contents aren't implemented yet. "mesa" is supposed to mean the opposite of "meta". By "mesadata" I don't mean mere content or payload: I mean data that is stored *inside* or *under* such content or payload. I found this meaning of "mesa" -- as opposite of "meta" -- by browsing somewhere on the internet. Fair chance many classicists would think poorly of this usage. But I don't care about etymology: I just need a word to close a lexical gap.
This commit is contained in:
parent
1dc3718159
commit
19a4766cb5
|
|
@ -17,11 +17,10 @@ use crate::{
|
|||
ratsnest::{Ratsnest, RatvertexIndex},
|
||||
selection::Selection,
|
||||
},
|
||||
board::Board,
|
||||
board::{mesadata::MesadataTrait, Board},
|
||||
drawing::{
|
||||
dot::FixedDotIndex,
|
||||
graph::{GetLayer, GetMaybeNet},
|
||||
rules::RulesTrait,
|
||||
},
|
||||
layout::Layout,
|
||||
router::{
|
||||
|
|
@ -55,7 +54,7 @@ pub struct Autoroute {
|
|||
impl Autoroute {
|
||||
pub fn new(
|
||||
ratlines: impl IntoIterator<Item = EdgeIndex<usize>> + 'static,
|
||||
autorouter: &mut Autorouter<impl RulesTrait>,
|
||||
autorouter: &mut Autorouter<impl MesadataTrait>,
|
||||
) -> Result<Self, AutorouterError> {
|
||||
let mut ratlines_iter = Box::new(ratlines.into_iter());
|
||||
|
||||
|
|
@ -75,10 +74,10 @@ impl Autoroute {
|
|||
Ok(this)
|
||||
}
|
||||
|
||||
pub fn step<R: RulesTrait>(
|
||||
pub fn step<M: MesadataTrait>(
|
||||
&mut self,
|
||||
autorouter: &mut Autorouter<R>,
|
||||
observer: &mut impl RouterObserverTrait<R>,
|
||||
autorouter: &mut Autorouter<M>,
|
||||
observer: &mut impl RouterObserverTrait<M>,
|
||||
) -> Result<AutorouterStatus, AutorouterError> {
|
||||
let (new_navmesh, new_ratline) = if let Some(cur_ratline) = self.ratlines_iter.next() {
|
||||
let (source, target) = autorouter.ratline_endpoints(cur_ratline);
|
||||
|
|
@ -121,13 +120,13 @@ impl Autoroute {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Autorouter<R: RulesTrait> {
|
||||
board: Board<R>,
|
||||
pub struct Autorouter<M: MesadataTrait> {
|
||||
board: Board<M>,
|
||||
ratsnest: Ratsnest,
|
||||
}
|
||||
|
||||
impl<R: RulesTrait> Autorouter<R> {
|
||||
pub fn new(board: Board<R>) -> Result<Self, InsertionError> {
|
||||
impl<M: MesadataTrait> Autorouter<M> {
|
||||
pub fn new(board: Board<M>) -> Result<Self, InsertionError> {
|
||||
let ratsnest = Ratsnest::new(board.layout())?;
|
||||
Ok(Self { board, ratsnest })
|
||||
}
|
||||
|
|
@ -135,7 +134,7 @@ impl<R: RulesTrait> Autorouter<R> {
|
|||
pub fn autoroute(
|
||||
&mut self,
|
||||
selection: &Selection,
|
||||
observer: &mut impl RouterObserverTrait<R>,
|
||||
observer: &mut impl RouterObserverTrait<M>,
|
||||
) -> Result<(), AutorouterError> {
|
||||
let mut autoroute = self.autoroute_walk(selection)?;
|
||||
|
||||
|
|
@ -225,7 +224,7 @@ impl<R: RulesTrait> Autorouter<R> {
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub fn board(&self) -> &Board<R> {
|
||||
pub fn board(&self) -> &Board<M> {
|
||||
&self.board
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
selection::Selection,
|
||||
Autoroute, Autorouter, AutorouterError, AutorouterStatus,
|
||||
},
|
||||
drawing::rules::RulesTrait,
|
||||
board::mesadata::MesadataTrait,
|
||||
layout::Layout,
|
||||
router::{EmptyRouterObserver, RouterObserverTrait},
|
||||
};
|
||||
|
|
@ -35,10 +35,10 @@ pub enum Execute {
|
|||
}
|
||||
|
||||
impl Execute {
|
||||
pub fn step<R: RulesTrait>(
|
||||
pub fn step<M: MesadataTrait>(
|
||||
&mut self,
|
||||
invoker: &mut Invoker<R>,
|
||||
observer: &mut impl RouterObserverTrait<R>,
|
||||
invoker: &mut Invoker<M>,
|
||||
observer: &mut impl RouterObserverTrait<M>,
|
||||
) -> Result<InvokerStatus, InvokerError> {
|
||||
match self {
|
||||
Execute::Autoroute(autoroute) => {
|
||||
|
|
@ -51,31 +51,31 @@ impl Execute {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Invoker<R: RulesTrait> {
|
||||
autorouter: Autorouter<R>,
|
||||
pub struct Invoker<M: MesadataTrait> {
|
||||
autorouter: Autorouter<M>,
|
||||
history: History,
|
||||
}
|
||||
|
||||
impl<R: RulesTrait> Invoker<R> {
|
||||
pub fn new(autorouter: Autorouter<R>) -> Self {
|
||||
impl<M: MesadataTrait> Invoker<M> {
|
||||
pub fn new(autorouter: Autorouter<M>) -> Self {
|
||||
Self::new_with_history(autorouter, History::new())
|
||||
}
|
||||
|
||||
pub fn new_with_history(autorouter: Autorouter<R>, history: History) -> Self {
|
||||
pub fn new_with_history(autorouter: Autorouter<M>, history: History) -> Self {
|
||||
Self {
|
||||
autorouter,
|
||||
history,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn destruct(self) -> (Autorouter<R>, History) {
|
||||
pub fn destruct(self) -> (Autorouter<M>, History) {
|
||||
(self.autorouter, self.history)
|
||||
}
|
||||
|
||||
pub fn execute(
|
||||
&mut self,
|
||||
command: Command,
|
||||
observer: &mut impl RouterObserverTrait<R>,
|
||||
observer: &mut impl RouterObserverTrait<M>,
|
||||
) -> Result<(), InvokerError> {
|
||||
let mut execute = self.execute_walk(command);
|
||||
|
||||
|
|
@ -142,7 +142,7 @@ impl<R: RulesTrait> Invoker<R> {
|
|||
self.history.set_undone(undone.into_iter());
|
||||
}
|
||||
|
||||
pub fn autorouter(&self) -> &Autorouter<R> {
|
||||
pub fn autorouter(&self) -> &Autorouter<M> {
|
||||
&self.autorouter
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,11 +3,8 @@ use std::collections::HashSet;
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
board::Board,
|
||||
drawing::{
|
||||
graph::{GetLayer, MakePrimitive, PrimitiveIndex},
|
||||
rules::RulesTrait,
|
||||
},
|
||||
board::{mesadata::MesadataTrait, Board},
|
||||
drawing::graph::{GetLayer, MakePrimitive, PrimitiveIndex},
|
||||
graph::GenericIndex,
|
||||
layout::NodeIndex,
|
||||
};
|
||||
|
|
@ -30,7 +27,7 @@ impl Selection {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn toggle_at_node(&mut self, board: &Board<impl RulesTrait>, node: NodeIndex) {
|
||||
pub fn toggle_at_node(&mut self, board: &Board<impl MesadataTrait>, node: NodeIndex) {
|
||||
let Some(selector) = self.node_selector(board, node) else {
|
||||
return;
|
||||
};
|
||||
|
|
@ -42,15 +39,15 @@ impl Selection {
|
|||
}
|
||||
}
|
||||
|
||||
fn select(&mut self, board: &Board<impl RulesTrait>, selector: Selector) {
|
||||
fn select(&mut self, board: &Board<impl MesadataTrait>, selector: Selector) {
|
||||
self.selectors.insert(selector);
|
||||
}
|
||||
|
||||
fn deselect(&mut self, board: &Board<impl RulesTrait>, selector: &Selector) {
|
||||
fn deselect(&mut self, board: &Board<impl MesadataTrait>, selector: &Selector) {
|
||||
self.selectors.remove(selector);
|
||||
}
|
||||
|
||||
pub fn contains_node(&self, board: &Board<impl RulesTrait>, node: NodeIndex) -> bool {
|
||||
pub fn contains_node(&self, board: &Board<impl MesadataTrait>, node: NodeIndex) -> bool {
|
||||
let Some(selector) = self.node_selector(board, node) else {
|
||||
return false;
|
||||
};
|
||||
|
|
@ -58,7 +55,11 @@ impl Selection {
|
|||
self.selectors.contains(&selector)
|
||||
}
|
||||
|
||||
fn node_selector(&self, board: &Board<impl RulesTrait>, node: NodeIndex) -> Option<Selector> {
|
||||
fn node_selector(
|
||||
&self,
|
||||
board: &Board<impl MesadataTrait>,
|
||||
node: NodeIndex,
|
||||
) -> Option<Selector> {
|
||||
let layer = match node {
|
||||
NodeIndex::Primitive(primitive) => {
|
||||
primitive.primitive(board.layout().drawing()).layer()
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ use topola::{
|
|||
rules::RulesTrait,
|
||||
Drawing, Infringement, LayoutException,
|
||||
},
|
||||
dsn::{design::DsnDesign, rules::DsnRules},
|
||||
dsn::{design::DsnDesign, mesadata::DsnMesadata},
|
||||
geometry::{
|
||||
compound::CompoundManagerTrait,
|
||||
primitive::{BendShape, DotShape, PrimitiveShape, PrimitiveShapeTrait, SegShape},
|
||||
|
|
@ -59,7 +59,7 @@ pub struct App {
|
|||
overlay: Option<Overlay>,
|
||||
|
||||
#[serde(skip)]
|
||||
invoker: Option<Arc<Mutex<Invoker<DsnRules>>>>,
|
||||
invoker: Option<Arc<Mutex<Invoker<DsnMesadata>>>>,
|
||||
|
||||
#[serde(skip)]
|
||||
shared_data: Arc<Mutex<SharedData>>,
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ use topola::drawing::rules::{Conditions, RulesTrait};
|
|||
use topola::drawing::seg::FixedSegWeight;
|
||||
use topola::drawing::{Infringement, LayoutException};
|
||||
use topola::dsn::design::DsnDesign;
|
||||
use topola::dsn::rules::DsnRules;
|
||||
use topola::dsn::mesadata::DsnMesadata;
|
||||
use topola::geometry::primitive::{PrimitiveShape, PrimitiveShapeTrait};
|
||||
use topola::geometry::shape::ShapeTrait;
|
||||
use topola::layout::zone::MakePolyShape;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
board::mesadata::MesadataTrait,
|
||||
drawing::{
|
||||
band::BandIndex,
|
||||
dot::{FixedDotIndex, FixedDotWeight},
|
||||
|
|
@ -20,16 +21,16 @@ use crate::{
|
|||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Board<R: RulesTrait> {
|
||||
layout: Layout<R>,
|
||||
pub struct Board<M: MesadataTrait> {
|
||||
layout: Layout<M>,
|
||||
node_to_pinname: HashMap<NodeIndex, String>,
|
||||
layer_to_layername: HashMap<u64, String>,
|
||||
net_to_netname: HashMap<usize, String>,
|
||||
pinname_pair_to_band: HashMap<(String, String), BandIndex>,
|
||||
}
|
||||
|
||||
impl<R: RulesTrait> Board<R> {
|
||||
pub fn new(layout: Layout<R>) -> Self {
|
||||
impl<M: MesadataTrait> Board<M> {
|
||||
pub fn new(layout: Layout<M>) -> Self {
|
||||
Self {
|
||||
layout,
|
||||
node_to_pinname: HashMap::new(),
|
||||
|
|
@ -122,7 +123,7 @@ impl<R: RulesTrait> Board<R> {
|
|||
&mut self,
|
||||
navmesh: Navmesh,
|
||||
width: f64,
|
||||
observer: &mut impl RouterObserverTrait<R>,
|
||||
observer: &mut impl RouterObserverTrait<M>,
|
||||
) -> Result<BandIndex, RouterError> {
|
||||
let source_pinname = self
|
||||
.node_pinname(GenericNode::Primitive(navmesh.source().into()))
|
||||
|
|
@ -199,11 +200,11 @@ impl<R: RulesTrait> Board<R> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn layout(&self) -> &Layout<R> {
|
||||
pub fn layout(&self) -> &Layout<M> {
|
||||
&self.layout
|
||||
}
|
||||
|
||||
pub fn layout_mut(&mut self) -> &mut Layout<R> {
|
||||
pub fn layout_mut(&mut self) -> &mut Layout<M> {
|
||||
&mut self.layout
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
use crate::{drawing::rules::RulesTrait, layout::NodeIndex};
|
||||
|
||||
// TODO: use this trait.
|
||||
pub trait MesadataTrait: RulesTrait {
|
||||
/*fn node_pinname(&self, node: NodeIndex);
|
||||
fn layer_layername(&self, layer: u64) -> &str;
|
||||
fn layername_layer(&self, layername: &str) -> u64;
|
||||
fn net_netname(&self, net: usize) -> &str;
|
||||
fn netname_net(&self, netname: &str) -> usize;*/
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
mod board;
|
||||
pub mod mesadata;
|
||||
|
||||
pub use board::*;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use crate::{
|
|||
drawing::{dot::FixedDotWeight, seg::FixedSegWeight, Drawing},
|
||||
dsn::{
|
||||
de,
|
||||
rules::DsnRules,
|
||||
mesadata::DsnMesadata,
|
||||
structure::{self, DsnFile, Layer, Pcb, Shape},
|
||||
},
|
||||
geometry::compound::CompoundManagerTrait,
|
||||
|
|
@ -44,8 +44,8 @@ impl DsnDesign {
|
|||
Ok(Self { pcb })
|
||||
}
|
||||
|
||||
pub fn make_board(&self) -> Board<DsnRules> {
|
||||
let rules = DsnRules::from_pcb(&self.pcb);
|
||||
pub fn make_board(&self) -> Board<DsnMesadata> {
|
||||
let rules = DsnMesadata::from_pcb(&self.pcb);
|
||||
let mut board = Board::new(Layout::new(Drawing::new(rules)));
|
||||
|
||||
// mapping of pin -> net prepared for adding pins
|
||||
|
|
@ -341,7 +341,7 @@ impl DsnDesign {
|
|||
}
|
||||
|
||||
fn layer(
|
||||
board: &Board<DsnRules>,
|
||||
board: &Board<DsnMesadata>,
|
||||
layer_vec: &Vec<Layer>,
|
||||
layer_name: &str,
|
||||
front: bool,
|
||||
|
|
@ -362,7 +362,7 @@ impl DsnDesign {
|
|||
}
|
||||
|
||||
fn add_circle(
|
||||
board: &mut Board<DsnRules>,
|
||||
board: &mut Board<DsnMesadata>,
|
||||
place_pos: Point,
|
||||
place_rot: f64,
|
||||
pin_pos: Point,
|
||||
|
|
@ -390,7 +390,7 @@ impl DsnDesign {
|
|||
}
|
||||
|
||||
fn add_rect(
|
||||
board: &mut Board<DsnRules>,
|
||||
board: &mut Board<DsnMesadata>,
|
||||
place_pos: Point,
|
||||
place_rot: f64,
|
||||
pin_pos: Point,
|
||||
|
|
@ -517,7 +517,7 @@ impl DsnDesign {
|
|||
}
|
||||
|
||||
fn add_path(
|
||||
board: &mut Board<DsnRules>,
|
||||
board: &mut Board<DsnMesadata>,
|
||||
place_pos: Point,
|
||||
place_rot: f64,
|
||||
pin_pos: Point,
|
||||
|
|
@ -600,7 +600,7 @@ impl DsnDesign {
|
|||
}
|
||||
|
||||
fn add_polygon(
|
||||
board: &mut Board<DsnRules>,
|
||||
board: &mut Board<DsnMesadata>,
|
||||
place_pos: Point,
|
||||
place_rot: f64,
|
||||
pin_pos: Point,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
board::mesadata::MesadataTrait,
|
||||
drawing::rules::{Conditions, RulesTrait},
|
||||
dsn::structure::Pcb,
|
||||
};
|
||||
|
|
@ -21,7 +22,7 @@ impl DsnRule {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DsnRules {
|
||||
pub struct DsnMesadata {
|
||||
structure_rule: DsnRule,
|
||||
// net class name -> rule
|
||||
class_rules: HashMap<String, DsnRule>,
|
||||
|
|
@ -34,7 +35,7 @@ pub struct DsnRules {
|
|||
net_to_netclass: HashMap<usize, String>,
|
||||
}
|
||||
|
||||
impl DsnRules {
|
||||
impl DsnMesadata {
|
||||
pub fn from_pcb(pcb: &Pcb) -> Self {
|
||||
let layer_ids = HashMap::from_iter(
|
||||
pcb.structure
|
||||
|
|
@ -87,7 +88,7 @@ impl DsnRules {
|
|||
}
|
||||
}
|
||||
|
||||
impl RulesTrait for DsnRules {
|
||||
impl RulesTrait for DsnMesadata {
|
||||
fn clearance(&self, conditions1: &Conditions, conditions2: &Conditions) -> f64 {
|
||||
let (Some(net1), Some(net2)) = (conditions1.maybe_net, conditions2.maybe_net) else {
|
||||
return 0.0;
|
||||
|
|
@ -115,3 +116,7 @@ impl RulesTrait for DsnRules {
|
|||
largest
|
||||
}
|
||||
}
|
||||
|
||||
impl MesadataTrait for DsnMesadata {
|
||||
//
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
mod de;
|
||||
pub mod design;
|
||||
pub mod rules;
|
||||
pub mod mesadata;
|
||||
mod structure;
|
||||
|
|
|
|||
|
|
@ -7,16 +7,13 @@ use topola::{
|
|||
invoker::{Invoker, InvokerError},
|
||||
Autorouter,
|
||||
},
|
||||
board::Board,
|
||||
drawing::{
|
||||
graph::{GetLayer, GetMaybeNet},
|
||||
rules::RulesTrait,
|
||||
},
|
||||
dsn::{design::DsnDesign, rules::DsnRules},
|
||||
board::{mesadata::MesadataTrait, Board},
|
||||
drawing::graph::{GetLayer, GetMaybeNet},
|
||||
dsn::{design::DsnDesign, mesadata::DsnMesadata},
|
||||
graph::GetNodeIndex,
|
||||
};
|
||||
|
||||
pub fn load_design_and_assert(filename: &str) -> Invoker<DsnRules> {
|
||||
pub fn load_design_and_assert(filename: &str) -> Invoker<DsnMesadata> {
|
||||
let design = DsnDesign::load_from_file(filename).unwrap();
|
||||
let mut invoker = Invoker::new(Autorouter::new(design.make_board()).unwrap());
|
||||
|
||||
|
|
@ -32,7 +29,7 @@ pub fn load_design_and_assert(filename: &str) -> Invoker<DsnRules> {
|
|||
invoker
|
||||
}
|
||||
|
||||
pub fn replay_and_assert(invoker: &mut Invoker<DsnRules>, filename: &str) {
|
||||
pub fn replay_and_assert(invoker: &mut Invoker<DsnMesadata>, filename: &str) {
|
||||
let file = File::open(filename).unwrap();
|
||||
invoker.replay(serde_json::from_reader(file).unwrap());
|
||||
|
||||
|
|
@ -59,7 +56,7 @@ pub fn replay_and_assert(invoker: &mut Invoker<DsnRules>, filename: &str) {
|
|||
}
|
||||
|
||||
pub fn assert_single_layer_groundless_autoroute(
|
||||
autorouter: &mut Autorouter<impl RulesTrait>,
|
||||
autorouter: &mut Autorouter<impl MesadataTrait>,
|
||||
layername: &str,
|
||||
) {
|
||||
let unionfind = unionfind(autorouter);
|
||||
|
|
@ -125,7 +122,7 @@ pub fn assert_single_layer_groundless_autoroute(
|
|||
}
|
||||
|
||||
/*pub fn assert_number_of_conncomps(
|
||||
autorouter: &mut Autorouter<impl RulesTrait>,
|
||||
autorouter: &mut Autorouter<impl MesadataTrait>,
|
||||
conncomp_count: usize,
|
||||
) {
|
||||
let unionfind = unionfind(autorouter);
|
||||
|
|
@ -137,7 +134,7 @@ pub fn assert_single_layer_groundless_autoroute(
|
|||
}*/
|
||||
|
||||
pub fn assert_band_length(
|
||||
board: &Board<impl RulesTrait>,
|
||||
board: &Board<impl MesadataTrait>,
|
||||
source: &str,
|
||||
target: &str,
|
||||
length: f64,
|
||||
|
|
@ -149,7 +146,7 @@ pub fn assert_band_length(
|
|||
assert!((band_length - length).abs() < epsilon);
|
||||
}
|
||||
|
||||
fn unionfind(autorouter: &mut Autorouter<impl RulesTrait>) -> UnionFind<NodeIndex<usize>> {
|
||||
fn unionfind(autorouter: &mut Autorouter<impl MesadataTrait>) -> UnionFind<NodeIndex<usize>> {
|
||||
for ratline in autorouter.ratsnest().graph().edge_indices() {
|
||||
// Accessing endpoints may create new dots because apex construction is lazy, so we access
|
||||
// tem all before starting unionfind, as it requires a constant index bound.
|
||||
|
|
|
|||
Loading…
Reference in New Issue