#![allow(unused_variables)]
#![allow(missing_docs)]
use crate::layout::types::{LayerInfo, UInt};
use crate::prelude::PropertyValue;
use crate::prelude::{Geometry, Rect};
use crate::traits::{
HierarchyBase, HierarchyBaseMT, HierarchyEdit, HierarchyIds, IdType, IdTypeMT,
};
use iron_shapes::transform::SimpleTransform;
use iron_shapes::CoordinateType;
use num_traits::Num;
use std::hash::Hash;
#[portrait::make]
pub trait LayoutBaseMT:
LayoutBase<LayerId = Self::LayerIdMT, ShapeId = Self::ShapeIdMT> + HierarchyBaseMT
{
type LayerIdMT: IdTypeMT;
type ShapeIdMT: IdTypeMT;
}
impl<L> LayoutBaseMT for L
where
L: LayoutBase + HierarchyBaseMT,
L::LayerId: Send + Sync,
L::ShapeId: Send + Sync,
{
type LayerIdMT = L::LayerId;
type ShapeIdMT = L::ShapeId;
}
#[portrait::make(import(crate::prelude::*))]
pub trait LayoutIds: HierarchyIds {
type Coord: CoordinateType + std::fmt::Debug + std::fmt::Display + Hash + 'static + Send + Sync;
type Area: Num + Copy + PartialOrd + From<Self::Coord> + 'static + Send + Sync;
type LayerId: IdType;
type ShapeId: IdType;
}
#[portrait::make(import(crate::prelude::*))]
pub trait LayoutBase: LayoutIds + HierarchyBase {
fn dbu(&self) -> Self::Coord;
fn each_layer(&self) -> Box<dyn Iterator<Item = Self::LayerId> + '_>;
fn layer_info(&self, layer: &Self::LayerId) -> LayerInfo<Self::NameType>;
fn find_layer(&self, index: UInt, datatype: UInt) -> Option<Self::LayerId>;
fn layer_by_name(&self, name: &str) -> Option<Self::LayerId>;
fn bounding_box_per_layer(
&self,
cell: &Self::CellId,
layer: &Self::LayerId,
) -> Option<Rect<Self::Coord>>;
fn bounding_box(&self, cell: &Self::CellId) -> Option<Rect<Self::Coord>> {
self.each_layer()
.map(|layer| self.bounding_box_per_layer(cell, &layer))
.fold(None, |a, b| match (a, b) {
(None, None) => None,
(Some(a), None) | (None, Some(a)) => Some(a),
(Some(a), Some(b)) => Some(a.add_rect(&b)),
})
}
fn each_shape_id(
&self,
cell: &Self::CellId,
layer: &Self::LayerId,
) -> Box<dyn Iterator<Item = Self::ShapeId> + '_>;
fn for_each_shape<F>(&self, cell: &Self::CellId, layer: &Self::LayerId, f: F)
where
F: FnMut(&Self::ShapeId, &Geometry<Self::Coord>);
fn with_shape<F, R>(&self, shape_id: &Self::ShapeId, f: F) -> R
where
F: FnMut(&Self::LayerId, &Geometry<Self::Coord>) -> R;
fn shape_geometry(&self, shape_id: &Self::ShapeId) -> Geometry<Self::Coord> {
self.with_shape(shape_id, |_, geo| geo.clone())
}
fn shape_layer(&self, shape_id: &Self::ShapeId) -> Self::LayerId {
self.with_shape(shape_id, |layer, _| layer.clone())
}
fn parent_of_shape(&self, shape_id: &Self::ShapeId) -> (Self::CellId, Self::LayerId);
fn for_each_shape_recursive<F>(&self, cell: &Self::CellId, layer: &Self::LayerId, mut f: F)
where
F: FnMut(SimpleTransform<Self::Coord>, &Self::ShapeId, &Geometry<Self::Coord>),
{
let mut stack = Vec::new();
stack.push((cell.clone(), SimpleTransform::identity()));
while let Some((cell, tf)) = stack.pop() {
self.for_each_cell_instance(&cell, |inst| {
let template = self.template_cell(&inst);
let transform = self.get_transform(&inst);
let tf2 = transform.then(&tf);
stack.push((template, tf2));
});
self.for_each_shape(&cell, layer, |id, g| f(tf, id, g));
}
}
fn get_transform(&self, cell_inst: &Self::CellInstId) -> SimpleTransform<Self::Coord>;
fn get_shape_property(
&self,
shape: &Self::ShapeId,
key: &Self::NameType,
) -> Option<PropertyValue> {
None
}
}
#[portrait::make]
pub trait RegionSearch: LayoutBase {
fn each_shape_in_region(
&self,
cell: &Self::CellId,
search_region: &Rect<Self::Coord>,
) -> Box<dyn Iterator<Item = Self::ShapeId> + '_> {
let cell = cell.clone(); let search_region = *search_region; Box::new(self.each_layer().flat_map(move |layer_id| {
self.each_shape_in_region_per_layer(&cell, &layer_id, &search_region)
}))
}
fn each_shape_in_region_per_layer(
&self,
cell: &Self::CellId,
layer_id: &Self::LayerId,
search_region: &Rect<Self::Coord>,
) -> Box<dyn Iterator<Item = Self::ShapeId> + '_>;
fn each_cell_instance_in_region(
&self,
cell: &Self::CellId,
search_region: &Rect<Self::Coord>,
) -> Box<dyn Iterator<Item = Self::CellInstId> + '_>;
}
#[portrait::make(import(crate::prelude::*))]
pub trait LayoutEdit: LayoutBase + HierarchyEdit {
fn set_dbu(&mut self, dbu: Self::Coord) {}
fn create_layer(&mut self, index: UInt, datatype: UInt) -> Self::LayerId;
fn create_layer_with_id(
&mut self,
layer_id: Self::LayerId,
index: UInt,
datatype: UInt,
) -> Result<(), ()>;
fn set_layer_name(
&mut self,
layer: &Self::LayerId,
name: Option<Self::NameType>,
) -> Option<Self::NameType>;
fn insert_shape(
&mut self,
parent_cell: &Self::CellId,
layer: &Self::LayerId,
geometry: Geometry<Self::Coord>,
) -> Self::ShapeId;
fn remove_shape(&mut self, shape_id: &Self::ShapeId) -> Option<Geometry<Self::Coord>>;
fn replace_shape(
&mut self,
shape_id: &Self::ShapeId,
geometry: Geometry<Self::Coord>,
) -> Geometry<Self::Coord>;
fn set_transform(&mut self, cell_inst: &Self::CellInstId, tf: SimpleTransform<Self::Coord>);
fn set_shape_property(
&mut self,
shape: &Self::ShapeId,
key: Self::NameType,
value: PropertyValue,
) {
}
}