-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathaddCell.il
280 lines (241 loc) · 10.3 KB
/
addCell.il
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
;; copyleft ebecheto
unless(fboundp('whereExistCell3) load("whereExistCell3.il"))
ineed('getInstTermPoint)
ineed('angleBox)
ineed('(getMaxPoints ibBox mbBox))
;; addCell('( "gnd" "noConn") t nil t '( "analogLib" "basic" ))
;cv= geGetWindowCellView()
defun( addCell (@optional (cells '("vdd" "gnd" "vdc" "noConn")) (cv t)(xy nil)(simp t)(lib nil))
(let (i rot grid xup insts inst box yup tb)
when(cv==t cv=geGetWindowCellView())
i=0 j=0 rot="R0" grid=schGetEnv("symSnapSpacing")
xup=0.5; step it when list of list of cells
unless(xy xy=foreach(mapcar a car(cv~>bBox) round(a-xup/grid)*grid))
cellss=if(listp(cells) cells list(cells))
libs=if(listp(lib) lib list(lib)) printf("libs='%L\n" libs)
if(simp&&rexMatchp("_sim$" cv~>cellName) then rexCompile("_sim$") tb=rexReplace(cv~>cellName "" 1)
unless(member(tb cv~>instances~>cellName) cellss=append(cellss list(tb))))
insts=foreach(mapcar cell cellss
unless(lib=nth(j libs) lib=car(whereExistCell3(cell nil "symbol")))
when(lib
while(member(sprintf(nil "I%d" i) foreach(mapcar n cv~>instances~>name car(parseString(n "<")))) i++)
;while(member(sprintf(nil "I%d" i) cv~>instances~>name) i++)
nocName=sprintf(nil "I%d" i)
printf("add in %L %L\n" xy list(cell lib nocName))
inst=dbCreateInstByMasterName(cv lib cell "symbol" nocName xy rot)
;inst=css()
box=inst~>bBox
yup=cadadr(box)-cadar(box)
yup=round(yup/grid)*grid
xy=list(car(xy)+xup cadr(xy)+yup)
) j++ inst)))
;; grid=schGetEnv("schSnapSpacing")=>0.0325
;; schGetEnv("symSnapSpacing");=> 0.0625
;; xy='(2.30625 6.925)
;; inst=css()
;; xyok=foreach(mapcar a xy round(a/grid)*grid)
;; inst~>xy=xyok
;; xy='(0.0 0.1875)
;; xyd=foreach(mapcar a xy a/grid)
;; xyr=foreach(mapcar a xyd round(a)*grid)
;; addCell()
;; ibmpat='("A" "B" "C" "D" "E" "F" "H" "I" "J" "K" "L")
;; cells=foreach(mapcar pat ibmpat strcat("XOR2_" pat))
;; addCell(cells)
printf("addCell('(%L %L %L %L %L %L %L))\n" "gnd" "vdc" "vdd" "noConn" "vbit" "vpulse" "vsin")
printf("addCell('(%L %L %L))\n" "DFF_E" "DFF_H" "DFF_K")
printf("addCell%L\n" '("XOR2_A" "XOR2_B" "XOR2_C" "XOR2_D" "XOR2_E" "XOR2_F" "XOR2_H" "XOR2_I" "XOR2_J" "XOR2_K" "XOR2_L"))
printf("addCell('(%L %L) t nil t '(%L %L))\n" "gnd" "noConn" "analogLib" "basic" )
;; ; assoc("A" getInstTermPoint()) ;=> ("A" (0.0 0.125))
;; (setq nets '(("B" "Q7")("A" "A1")("Q" "Q1")))
;; (setq nets1 '("Q7" "A1" "Q1" "HOHO") )
;; (setq nets '("Q7" "A1" "Q1") )
defun( addCells (@optional (cells '("XOR2_A" "XOR2_B")) (cv nil)(nets '(("A" "A1")("Q" "Q1")("B" "Q7") ))(dx 0.1)(xyext nil))
(let (i rot grid xup xy insts lib inst box yup yext xext)
xext=car(xyext) yext=cadr(xyext)
unless(cv cv=geGetWindowCellView())
i=0 rot="R0" grid=schGetEnv("symSnapSpacing")
xup=if(xext xext 0); step it when list of list of cells
xy=foreach(mapcar a car(cv~>bBox) round(a/grid)*grid)
when(yext!=nil xy=list(car(x) yext))
cellss=if(listp(cells) cells list(cells))
insts=foreach(mapcar cell cellss
lib=car(whereExistCell3(cell nil "symbol"))
when(lib
while(member(sprintf(nil "I%d" i) cv~>instances~>name) i++) nocName=sprintf(nil "I%d" i)
printf("add in %L %L\n" xy list(cell lib nocName))
inst=dbCreateInstByMasterName(cv lib cell "symbol" nocName xy rot)
termpts=getInstTermPoint(inst)
;terma=foreach(mapcar tp termpts car(tp))
; apply('mapcar 'list list(nets terma))
;printf("supposed order : %s\n" apply('strcat foreach(mapcan tp termpts list("_" car(tp)))))
netr=nets
bBox=ibBox(inst)
foreach(mapcar tp termpts name=car(tp)
cond(
(null(netr) name=car(tp))
(listp(car(netr)) name=car(assoc(car(tp) nets)))
(listp(netr) name=car(netr) netr=cdr(netr))
)
printf("labelAtPt%L\n" list(list(name cadr(tp)) bBox))
labelAtPt(list(name cadr(tp)) bBox 0.1 cv)
)
;inst=css()
box=inst~>bBox
printf("cadar %L_%L_\n" cadadr(box) cadar(box))
yup=cadadr(box)-cadar(box)
yup=round(yup/grid)*grid
xy=list(car(xy)+xup cadr(xy)+yup)
) inst)))
; addCells("XOR2X1")
; addCells("XOR2X1" nil nil)
defun(labelAtPt (termpt bBox @optional (dx 0.1)(cv geGetWindowCellView())(font "euroStyle")) let((os x y orient wid label point)
;(setq font "euroStyle")
label=car(termpt) point=cadr(termpt)
os=angleBox(point bBox)
;os=angleSection(rodSubPoints(point centerBox(bBox)))
;printf("%L %L os=%L\n" label point os)
x=car(point) y=cadr(point)
cond((os==0 y=y-dx)(os==1 x=x+dx)(os==2 y=y+dx)(os==3 x=x-dx))
orient=sprintf(nil "R%d" mod(90*(os+1) 360))
wid=schCreateWire( cv "draw" "direct" list(point x:y) 0.0625 0.0625 0 ); <== creat wire line
schCreateWireLabel(cv car(wid) point label "lowerRight" orient font 0.0625 nil)
))
;; inst=css()
;; tps=getInstTermPoint(inst) ;; tp=car(tps)
;; symselbox=car(setof(x inst~>master~>shapes x~>layerName=="instance" && x~>objType=="rect")~>bBox)
;; bBox=dbTransformBBox(symselbox inst~>transform)
;; ;!= inst~>bBox why ?
;; foreach(mapcar tp tps labelAtPt(tp bBox))
;; (setq cell "XOR2X2")
;; (setq ios '("B1" "A1" "Q1"))
;; (setq xy 0:0)
;; (setq cv geGetWindowCellView())
defun(addCellg (@optional (g getPropList())(xyg 0:0) (cv geGetWindowCellView()) (rot css()~>orient)(fixg nil))
unless(rot rot="R0")
when(listp(g)
addCellw(car(g) cadr(g) xyg cv 0.1 rot caddr(g) nil fixg)
))
defun(addCellw (@optional (cell "XOR2X2")(ios '("B1" "A1" "Q1"))(xyg 0:0)(cv geGetWindowCellView())(dx 0.1)(rot "R0")(pp nil)(verb nil)(fixg t))
(let (i grid io xy inst lib inst box yup gtp os nocName tmp)
i=0 ;rot="R0"
grid=schGetEnv("symSnapSpacing")
io=ios
when(verb printf("In %L\n" list(cv~>cellName cell)))
xy=if(fixg foreach(mapcar a xyg round(a/grid)*grid) xyg)
lib=car(whereExistCell3(cell nil "symbol"))
if(lib then
while(member(sprintf(nil "I%d" i) cv~>instances~>name) i++)
nocName=sprintf(nil "I%d" i)
when(verb printf("add @%L %L\n" xy list(cv cell lib nocName)))
;inst=dbCreateInstByMasterName(cv lib cell "symbol" nocName xy rot)
if(pp
inst=dbCreateParamInstByMasterName(cv lib cell "symbol" nocName xy rot 1 pp)
inst=dbCreateInstByMasterName(cv lib cell "symbol" nocName xy rot 1)
)
gtp=getInstTermPoint(inst)
cond(
(io==t io=foreach(mapcar g gtp car(g)))
(type(io)=='string io=foreach(mapcar g gtp sprintf(nil "%s_%s" io car(g))))
)
;tp=cadr(gtp)
foreach(tp gtp
cond(
(car(io)==t ;os=angleSection(rodSubPoints(cadr(tp) centerBox(ibBox(inst))))
os=angleBox(cadr(tp) ibBox(inst))
tmp=tp addCellw("noConn" nil cadr(tp) cv dx sprintf(nil "R%d" os*90)) tp=tmp io=cdr(io))
(car(io)==nil t);skip when less ionames
(t labelAtPt(list(car(io) cadr(tp)) ibBox(inst) dx cv) io=cdr(io))
); printf("tp%L from %L\n" tp gtp)
) when(verb printf("Reminder choice for %s ios :%L\n" cell mapcar('car gtp)))
inst
else printf("%s NOT FOUND\n" cell) nil)))
; addCellw()
;; addCellw("INVX1" '("AA" t) 0:-1)
;; addCellw("DFX1" '("AA" "Qnn" "Qq" "DD") 0:-1.1)
;; addCellw("DFX1" '("AA" t t "DD") 0:-1.4)
;; addCellw("DFX1" '("AA" t t "DD") 0:-1.8)
;; line='("DFX1" ("AA" t t "DD") (0 -1.8))
;; apply('addCellw line);oki !
;; libList='("analogLib" "CORELIB")
;; dds=setof(dd ddGetLibList() member(dd~>name libList))
;; assocLib=foreach(mapcan d dds foreach(mapcan c d~>cells list(list(d~>name c~>name))))
;or assocLib=foreach(mapcan d ddGetLibList() foreach(mapcan c d~>cells list(list(c~>name d~>name))))
;; assocLib should be define before using addCellw1
defun(addCellw1 (@optional (cell "XOR2X2")(ios '("B1" "A1" "Q1"))(xyg 0:0)(cv geGetWindowCellView())(dx 0.1)(rot "R0")(pp nil))
(let (i grid io xy inst lib inst box yup gtp os nocName tmp)
i=0 ;rot="R0"
unless(assocLib assocLib=foreach(mapcan d ddGetLibList() foreach(mapcan c d~>cells list(list(c~>name d~>name)))))
grid=0.0625;schGetEnv("symSnapSpacing")
io=ios
xy=foreach(mapcar a xyg round(a/grid)*grid)
lib=cadr(assoc(cell assocLib))
when(lib
while(member(sprintf(nil "I%d" i) cv~>instances~>name) i++) nocName=sprintf(nil "I%d" i)
if(pp
inst=dbCreateParamInstByMasterName(cv lib cell "symbol" nocName xy rot 1 pp)
inst=dbCreateInstByMasterName(cv lib cell "symbol" nocName xy rot 1)
)
gtp=getInstTermPoint(inst)
cond(
(io==t io=foreach(mapcar g gtp car(g)))
(type(io)=='string io=foreach(mapcar g gtp sprintf(nil "%s_%s" io car(g))))
)
foreach(tp gtp
cond(
(car(io)==t os=angleBox(cadr(tp) ibBox(inst))
tmp=tp addCellw("noConn" nil cadr(tp) cv dx sprintf(nil "R%d" os*90)) tp=tmp io=cdr(io))
(car(io)==nil t);skip when less ionames
(t labelAtPt(list(car(io) cadr(tp)) ibBox(inst) dx cv) io=cdr(io))
); printf("tp%L from %L\n" tp gtp)
) when(verb printf("Reminder choice for %s ios :%L\n" cell mapcar('car gtp)))
inst
)))
defun(addCellw2 (@optional (netline '(("DFX1" ("AA" t t "DD")) ("vdc") ("switch" nil))) (xyg 0:0)(cv geGetWindowCellView())(dxl 0.1)(rot "R0")(verb nil)(dx 0.4))
let((xy yup yupm x0 inst box xup)
yup=0 yupm=0
xy=xyg
foreach(line netline
printf("xy=%L\n" xy)
x0=car(xy) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; dx pour emplacement du label
inst=addCellw(car(line) cadr(line) xy cv dxl nth(3 line)||"R0" caddr(line) verb)
box=mbBox(inst);box=inst~>bBox
yup=cadadr(box)-cadar(box)
xup=caadr(box)-caar(box)
;yupm=max(yupm ceiling(yup/grid)*grid)
yupm=max(yupm round(yup/grid)*grid)
xy=list(car(xy)+xup+dx cadr(xy))
)
xy=list(x0 cadr(xy)+yupm);+dy
when(cv!=geGetWindowCellView() geOpen(?lib cv~>libName ?cell cv~>cellName ?view "schematic"))
dbCheck(cv) dbSave(cv); dbClose(cv)
list(cv xy)
))
;; addCellw2('(("DFX1" ("AA" t t "DD")) ("vdc") ("switch" ("O" "i" "a"))))
;; addCellw2('(("DFX1" ("AA" t t "DD")) ("vdc") ("switch" "AA")))
;; addCellw2('(("DFX1" ("AA" t t "DD")) ("vdc") ("switch" t)))
;; assocLib=foreach(mapcan d ddGetLibList() foreach(mapcan c d~>cells list(list(c~>name d~>name))))
;; cadr(assoc("DFX1" assocLib));=>"CORELIB"
;; libList='("analogLib" "CORELIB")
;; dds=setof(dd ddGetLibList() member(dd~>name libList))
;; assocLib=foreach(mapcan d dds foreach(mapcan c d~>cells list(list(c~>name d~>name))))
defun(addCellw3 (@optional (netlines '((("vdc" ("gnd!" "vdd!")))(("DFX1" ("AA" t t "DD")) ("vdc") ("switch" nil)))) (xyg 0:0)(cv geGetWindowCellView())(dxl 0.1)(rot "R0")(verb nil)(dx 0.4)(dy 0.0))
let((xy yup yupm x0 inst box xup)
xy=xyg x0=car(xy)
foreach(netline netlines yup=0 yupm=0
foreach(line netline
inst=addCellw1(car(line) cadr(line) xy cv dxl nth(3 line)||"R0" caddr(line))
box=mbBox(inst);box=inst~>bBox
yup=cadadr(box)-cadar(box)
xup=caadr(box)-caar(box)
;yupm=max(yupm ceiling(yup/grid)*grid)
yupm=max(yupm round(yup/grid)*grid)
xy=list(car(xy)+xup+dx cadr(xy))
)
xy=list(x0 cadr(xy)+yupm+dy)
)
when(cv!=geGetWindowCellView() geOpen(?lib cv~>libName ?cell cv~>cellName ?view "schematic"))
dbCheck(cv) dbSave(cv); dbClose(cv)
list(cv xy)
))
;addCellw3()