diff --git a/src/autorouter/anterouter.rs b/src/autorouter/anterouter.rs index 82b9857..902243d 100644 --- a/src/autorouter/anterouter.rs +++ b/src/autorouter/anterouter.rs @@ -334,7 +334,7 @@ impl Anterouter { direction: impl Into, options: &AnterouterOptions, ) -> Result<(), ()> { - let (_, dots) = self.place_fanout_via_on_bbox_in_direction( + let (via, dots) = self.place_fanout_via_on_bbox_in_direction( autorouter, recorder, ratvertex, @@ -363,7 +363,7 @@ impl Anterouter { }) .unwrap(); - autorouter.board.layout_mut().add_fixed_seg( + if let Ok(_) = autorouter.board.layout_mut().add_fixed_seg( &mut recorder.layout_edit, source_dot, fanout_dot, @@ -372,9 +372,12 @@ impl Anterouter { layer, maybe_net, }), - ); - - Ok(()) + ) { + Ok(()) + } else { + autorouter.board.remove_via(recorder, via, dots); + Err(()) + } } fn place_fanout_via_on_bbox_in_direction( diff --git a/src/board/mod.rs b/src/board/mod.rs index 980ab89..37ebb56 100644 --- a/src/board/mod.rs +++ b/src/board/mod.rs @@ -125,6 +125,20 @@ impl Board { Ok((weight, dots)) } + pub fn remove_via( + &mut self, + recorder: &mut BoardEdit, + via: GenericIndex, + dots: Vec, + ) { + for dot in dots.clone() { + self.pinname_nodes + .remove_by_value(&GenericNode::Primitive(dot.into())); + } + + self.layout.remove_via(&mut recorder.layout_edit, via, dots); + } + /// Adds a new fixed dot with an optional pin name. /// /// Inserts the dot into the layout and, if a pin name is provided, maps it to the created dot's node. diff --git a/src/layout/layout.rs b/src/layout/layout.rs index d6259d5..04478c0 100644 --- a/src/layout/layout.rs +++ b/src/layout/layout.rs @@ -157,6 +157,7 @@ impl Layout { weight: ViaWeight, ) -> Result<(GenericIndex, Vec), LayoutException> { let compound = self.drawing.add_compound(recorder, weight.into()); + let via = GenericIndex::::new(compound.index()); let mut dots = vec![]; for layer in weight.from_layer..=weight.to_layer { @@ -180,7 +181,7 @@ impl Layout { // trigger an infringement on its primitives. To take // this situation into account, we also check if the // via's center is inside the poly's polygon. - self.remove_failed_via(recorder, compound, dots); + self.remove_via(recorder, via, dots); return Err(LayoutException::HasPointInPoly(HasPointInPoly( enclosing_poly.ref_(self).shape(), weight.circle.pos, @@ -195,7 +196,7 @@ impl Layout { ); } Err(err) => { - self.remove_failed_via(recorder, compound, dots); + self.remove_via(recorder, via, dots); return Err(err.into()); } } @@ -204,13 +205,14 @@ impl Layout { Ok((GenericIndex::::new(compound.index()), dots)) } - fn remove_failed_via( + pub fn remove_via( &mut self, recorder: &mut LayoutEdit, - compound: GenericIndex, + via: GenericIndex, dots: Vec, ) { - self.drawing.remove_compound(recorder, compound); + self.drawing + .remove_compound(recorder, GenericIndex::::new(via.index())); // Remove inserted dots. for dot in dots.iter().rev() { diff --git a/src/router/navmesh.rs b/src/router/navmesh.rs index 209c470..3630080 100644 --- a/src/router/navmesh.rs +++ b/src/router/navmesh.rs @@ -24,9 +24,10 @@ use crate::{ bend::{FixedBendIndex, LooseBendIndex}, dot::FixedDotIndex, gear::{GearIndex, GetOuterGears, WalkOutwards}, - graph::PrimitiveIndex, + graph::{MakePrimitiveRef, PrimitiveIndex}, rules::AccessRules, }, + geometry::GetLayer, graph::{GenericIndex, GetIndex, MakeRef}, layout::{CompoundEntryLabel, Layout}, math::RotationSense, @@ -157,6 +158,11 @@ impl Navmesh { destination: FixedDotIndex, options: RouterOptions, ) -> Result { + assert!( + origin.primitive_ref(layout.drawing()).layer() + == destination.primitive_ref(layout.drawing()).layer() + ); + let mut graph: UnGraph = UnGraph::default(); let mut origin_navnode = None; let mut destination_navnode = None;