Skip to main content

virtuoso_cli/client/
editor.rs

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); 2]) {
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        orient: &str,
85    ) {
86        let ops = SchematicOps;
87        self.commands
88            .push(ops.create_instance(lib, cell, view, name, origin, orient));
89    }
90
91    pub fn add_wire(&mut self, points: Vec<(i64, i64)>, layer: &str, net_name: &str) {
92        let ops = SchematicOps;
93        self.commands
94            .push(ops.create_wire(&points, layer, net_name));
95    }
96
97    pub fn add_label(&mut self, net_name: &str, origin: (i64, i64)) {
98        let ops = SchematicOps;
99        self.commands.push(ops.create_wire_label(net_name, origin));
100    }
101
102    pub fn add_pin(&mut self, net_name: &str, pin_type: &str, origin: (i64, i64)) {
103        let ops = SchematicOps;
104        self.commands
105            .push(ops.create_pin(net_name, pin_type, origin));
106    }
107
108    pub fn set_param(&mut self, inst_name: &str, param: &str, value: &str) {
109        let ops = SchematicOps;
110        self.commands
111            .push(ops.set_instance_param(inst_name, param, value));
112    }
113
114    pub fn assign_net(&mut self, inst_name: &str, term_name: &str, net_name: &str) {
115        let ops = SchematicOps;
116        self.commands
117            .push(ops.assign_net(inst_name, term_name, net_name));
118    }
119
120    pub fn execute(self) -> Result<VirtuosoResult> {
121        self.client.execute_operations(&self.commands)
122    }
123}