libreda_db/l2n/mod.rs
1// Copyright (c) 2020-2021 Thomas Kramer.
2// SPDX-FileCopyrightText: 2022 Thomas Kramer
3//
4// SPDX-License-Identifier: AGPL-3.0-or-later
5
6//! Trait definitions for layouts fused with netlists.
7
8#![allow(missing_docs)] // Necessary because portrait does not generate docs.
9
10pub mod util;
11
12use super::traits::*;
13
14/// Helper trait which constrains [`trait@L2NBase`] for such that ID types
15/// are [`Send`] and [`Sync`] as commonly used for parallel algorithms.
16#[portrait::make]
17pub trait L2NBaseMT: L2NBase + LayoutBaseMT + NetlistBaseMT {}
18
19impl<L> L2NBaseMT for L where L: L2NBase + LayoutBaseMT + NetlistBaseMT {}
20
21/// Defines ID types of a netlist and layout.
22/// Implemented automatically.
23pub trait L2NIds: LayoutIds + NetlistIds {}
24
25impl<LN> L2NIds for LN where LN: LayoutIds + NetlistIds {}
26
27/// Fused layout and netlist view.
28/// This trait makes the link between netlist elements and layout elements.
29#[portrait::make]
30pub trait L2NBase: LayoutBase + NetlistBase {
31 /// Iterate over all shapes that are marked to belong to the specified net.
32 fn shapes_of_net(&self, net_id: &Self::NetId) -> Box<dyn Iterator<Item = Self::ShapeId> + '_>;
33 /// Iterate over all shapes that are part of the pin.
34 fn shapes_of_pin(&self, pin_id: &Self::PinId) -> Box<dyn Iterator<Item = Self::ShapeId> + '_>;
35 /// Get the net of a shape.
36 fn get_net_of_shape(&self, shape_id: &Self::ShapeId) -> Option<Self::NetId>;
37 /// Get the pin that belongs to the shape (if any).
38 fn get_pin_of_shape(&self, shape_id: &Self::ShapeId) -> Option<Self::PinId>;
39}
40
41/// Fused layout and netlist view.
42/// This trait makes the link between netlist elements and layout elements.
43#[portrait::make]
44pub trait L2NEdit: L2NBase + LayoutEdit + NetlistEdit {
45 /// Create the link between a circuit pin and its shapes in the layout.
46 /// Return the current pin.
47 fn set_pin_of_shape(
48 &mut self,
49 shape_id: &Self::ShapeId,
50 pin: Option<Self::PinId>,
51 ) -> Option<Self::PinId>;
52 /// Set the net of a shape.
53 /// Return the current net.
54 fn set_net_of_shape(
55 &mut self,
56 shape_id: &Self::ShapeId,
57 net: Option<Self::NetId>,
58 ) -> Option<Self::NetId>;
59}