1use crate::client::bridge::VirtuosoClient;
2use crate::client::layout_ops::LayoutOps;
3use crate::client::schematic_ops::SchematicOps;
4use crate::error::Result;
5use crate::models::VirtuosoResult;
6
7pub struct LayoutEditor<'a> {
8 client: &'a VirtuosoClient,
9 lib: String,
10 cell: String,
11 commands: Vec<String>,
12}
13
14impl<'a> LayoutEditor<'a> {
15 pub fn new(client: &'a VirtuosoClient, lib: &str, cell: &str) -> Self {
16 Self {
17 client,
18 lib: lib.into(),
19 cell: cell.into(),
20 commands: Vec::new(),
21 }
22 }
23
24 pub fn add_rect(&mut self, layer: &str, purpose: &str, bbox: [(i64, i64); 4]) {
25 let ops = LayoutOps;
26 self.commands.push(ops.create_rect(layer, purpose, &bbox));
27 }
28
29 pub fn add_polygon(&mut self, layer: &str, purpose: &str, points: Vec<(i64, i64)>) {
30 let ops = LayoutOps;
31 self.commands
32 .push(ops.create_polygon(layer, purpose, &points));
33 }
34
35 pub fn add_path(&mut self, layer: &str, purpose: &str, width: i64, points: Vec<(i64, i64)>) {
36 let ops = LayoutOps;
37 self.commands
38 .push(ops.create_path(layer, purpose, width, &points));
39 }
40
41 pub fn add_via(&mut self, via_def: &str, origin: (i64, i64)) {
42 let ops = LayoutOps;
43 self.commands.push(ops.create_via(via_def, origin));
44 }
45
46 pub fn add_instance(
47 &mut self,
48 lib: &str,
49 cell: &str,
50 view: &str,
51 origin: (i64, i64),
52 orient: &str,
53 ) {
54 let ops = LayoutOps;
55 self.commands
56 .push(ops.create_instance(lib, cell, view, origin, orient));
57 }
58
59 pub fn execute(self) -> Result<VirtuosoResult> {
60 self.client.execute_operations(&self.commands)
61 }
62}
63
64pub struct SchematicEditor<'a> {
65 client: &'a VirtuosoClient,
66 commands: Vec<String>,
67}
68
69impl<'a> SchematicEditor<'a> {
70 pub fn new(client: &'a VirtuosoClient) -> Self {
71 Self {
72 client,
73 commands: Vec::new(),
74 }
75 }
76
77 pub fn add_instance(
78 &mut self,
79 lib: &str,
80 cell: &str,
81 view: &str,
82 name: &str,
83 origin: (i64, i64),
84 ) {
85 let ops = SchematicOps;
86 self.commands
87 .push(ops.create_instance(lib, cell, view, name, origin));
88 }
89
90 pub fn add_wire(&mut self, points: Vec<(i64, i64)>, layer: &str, net_name: &str) {
91 let ops = SchematicOps;
92 self.commands
93 .push(ops.create_wire(&points, layer, net_name));
94 }
95
96 pub fn add_label(&mut self, net_name: &str, origin: (i64, i64)) {
97 let ops = SchematicOps;
98 self.commands.push(ops.create_wire_label(net_name, origin));
99 }
100
101 pub fn add_pin(&mut self, net_name: &str, pin_type: &str, origin: (i64, i64)) {
102 let ops = SchematicOps;
103 self.commands
104 .push(ops.create_pin(net_name, pin_type, origin));
105 }
106
107 pub fn set_param(&mut self, inst_name: &str, param: &str, value: &str) {
108 let ops = SchematicOps;
109 self.commands
110 .push(ops.set_instance_param(inst_name, param, value));
111 }
112
113 pub fn assign_net(&mut self, inst_name: &str, term_name: &str, net_name: &str) {
114 let ops = SchematicOps;
115 self.commands
116 .push(ops.assign_net(inst_name, term_name, net_name));
117 }
118
119 pub fn execute(self) -> Result<VirtuosoResult> {
120 self.client.execute_operations(&self.commands)
121 }
122}