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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464 | ###############################################################################
# Copyright (c) 2017-2024 by Altair Engineering, Inc.
# All rights reserved.
#
# Altair Engineering, Inc. makes this software available as part of the Vision
# tool platform. As long as you are a licensee of the Vision tool platform
# you may make copies of the software and modify it to be used within the
# Vision tool platform, but you must include all of this notice on any copy.
# Redistribution without written permission to any third party, with or
# without modification, is not permitted.
# Altair Engineering, Inc. does not warrant that this software is error free
# or fit for any purpose. Altair Engineering, Inc. disclaims any liability for
# all claims, expenses, losses, damages and costs any user may incur as a
# result of using, copying or modifying the software.
# =============================================================================
# @plugin
# Filter Parasitic Elements
# @namespace
# FilterParasitic
# @section
# Analyze the Loaded Database
# @description
# This script can be used to filter parasitic elements of the RC network
# displayed in the Parasitic window.
# Sometimes the RC network even for a single net is too complicated and
# therefore when viewed for multiple nets, it can be very complicated to
# for debugging and visualization.
#
# This script enables the user to:
#
# 1. Remove all the resistors or capacitors from a selected net in the
# RC window (NOT from the entire database).
#
# 2. Merge series resistors or parallel capacitors of a selected net.
#
# 3. Filter resistors or capacitors below a specified threshold value of a
# selected net.
# @files
# parasitic/filterParasitics.tcl
# @example
# demo/dspf/example.dspf
# @cmdline
# -readDSPF @example[0]
# -userware @files[0]
# @tag
# gui parasitic spf dspf
###############################################################################
# =============================================================================
# Init - Initialize the plugin.
# =============================================================================
#
proc FilterParasitic:Init {} {
##
# Register a callback procedure to extend the popup menu.
#
gui popup customize "FilterParasitic:_extendPopup"
}
# =============================================================================
# Finit - Finalize the plugin.
# =============================================================================
#
proc FilterParasitic:Finit {} {
gui popup removeCustomize "FilterParasitic:_extendPopup"
}
# -----------------------------------------------------------------------------
# _updateGUI - Remove all objects flagged as zombie and inform the GUI about
# the changed database.
# Regenerate the contents loaded to the parasitic window to show
# the most compact schematic for the RC network after the
# modification.
# -----------------------------------------------------------------------------
#
proc FilterParasitic:_updateGUI {db} {
$db deleteZombies
gui database modified
gui parasitic regenerate
}
# -----------------------------------------------------------------------------
# _removeResistors - This procedure removes all resistors from a net
# containing the extracted parasitic.
# Right click on the net, select "Filter Parasitic"
# and select "Remove Resistors".
# -----------------------------------------------------------------------------
#
proc FilterParasitic:_removeResistors {db parasiticModule} {
$db foreach inst $parasiticModule inst {
##
# Skip all non-resistor instances.
#
if {[$db primFuncOf $inst] != "RES"} {
continue
}
set conNetList {}
$db foreach pin $inst pin {
if {![$db isConnected $pin]} {
continue
}
lappend conNetList [$db connectedNet $pin]
if {[llength $conNetList] > 2} {
break
}
}
if {[llength $conNetList] != 2} {
continue
}
set net1 [lindex $conNetList 0]
set net2 [lindex $conNetList 1]
$db oper mergeNet $net1 $net2
$db flag $net2 set zombie
$db flag $inst set zombie
}
FilterParasitic:_updateGUI $db
}
# -----------------------------------------------------------------------------
# _removeCapacitors - This procedure removes all the capacitors from a net
# containing the extracted parasitic.
# Right click on the net, select "Filter Parasitic"
# and select "Remove Capacitors".
# -----------------------------------------------------------------------------
#
proc FilterParasitic:_removeCapacitors {db parasiticModule} {
$db foreach inst $parasiticModule inst {
##
# Skip all non-capacitor instances.
#
if {[$db primFuncOf $inst] != "CAP"} {
continue
}
$db flag $inst set zombie
}
FilterParasitic:_updateGUI $db
}
# -----------------------------------------------------------------------------
# _mergeResistors - This procedure merges all the serial resistors in a net
# containing the extracted parasitic.
# Right click on the net, select "Filter Parasitic"
# and select "Merge Resistors".
# -----------------------------------------------------------------------------
#
proc FilterParasitic:_mergeResistors {db} {
$db oper mergeSerialRes -parasitic
FilterParasitic:_updateGUI $db
}
# -----------------------------------------------------------------------------
# _mergeCapacitors - This procedure merges all the parallel capacitors in a
# net containing the extracted parasitic.
# Right click on the net, select "Filter Parasitic"
# and select "Merge Capacitors".
# -----------------------------------------------------------------------------
#
proc FilterParasitic:_mergeCapacitors {db} {
$db oper mergeParallelCap -parasitic
FilterParasitic:_updateGUI $db
}
# -----------------------------------------------------------------------------
# _runFilterCmd - Run the given command from the filter dialog.
# -----------------------------------------------------------------------------
#
proc FilterParasitic:_runFilterCmd {w command} {
set value [$w.e get]
set value [zdb formatvalue fromspice $value]
set compareOp [$w.c get]
destroy $w
lappend command $compareOp $value
eval $command
}
# -----------------------------------------------------------------------------
# _showFilterPopup - Create a Popup window to enter a filter value.
# -----------------------------------------------------------------------------
#
proc FilterParasitic:_showFilterPopup {w title cmd} {
##
# Create the command to be executed.
#
set command [list FilterParasitic:_runFilterCmd $w $cmd]
##
# Create the toplevel dialog window.
#
toplevel $w
wm title $w $title
wm protocol $w WM_DELETE_WINDOW [list destroy $w]
bind $w <Key-Escape> [list destroy $w]
##
# Create the contents of the dialog.
#
ttk::combobox $w.c -values {"<" ">"} -width 2
$w.c insert 0 "<"
$w.c configure -state readonly
ttk::entry $w.e
ttk::button $w.b -text $title -command $command
bind $w.e <Return> $command
focus $w.e
grid $w.c -row 0 -column 0 -sticky w -padx 3
grid $w.e -row 0 -column 1 -sticky we -padx 3
grid $w.b -row 0 -column 2 -sticky e -padx 3
grid columnconfigure $w 1 -weight 1
##
# Get the mouse pointer coordinates.
#
set X [winfo pointerx .]
set Y [winfo pointery .]
##
# Get the width and height of the created dialog.
#
set width [winfo reqwidth $w]
set height [winfo reqheight $w]
##
# Adjust X and Y positions if parts of the dialog won't be
# visible on the screen.
#
set workarea [getworkarea]
set screenWidth [expr {[lindex $workarea 2] - [lindex $workarea 0]}]
set screenHeight [expr {[lindex $workarea 3] - [lindex $workarea 1]}]
if {($X + $width) > $screenWidth} {
set X [expr {$screenWidth - $width}]
}
if {($Y + $height) > $screenHeight} {
set Y [expr {$screenHeight - $height}]
}
wm geometry $w +$X+$Y
}
# -----------------------------------------------------------------------------
# _filterResistors - This procedure filters all the resistors below a
# threshold value provided by the user in a Popup window.
# Please note that this user-value should be the value
# excluding the power of 10 (for example if its 1K Ohm, then
# just include value "1").
# Right click on the net, select "Filter Parasitic"
# and select "Filter Resistors" and add a threshold value
# in the Popup window.
# -----------------------------------------------------------------------------
#
proc FilterParasitic:_filterResistors {db parasiticModule} {
set command [list FilterParasitic:_filterRes $db $parasiticModule]
FilterParasitic:_showFilterPopup \
.filter_resistor \
"Filter Resistors" \
$command
}
# -----------------------------------------------------------------------------
# _filterCapacitors - This procedure filters all the capacitors below a
# threshold value provided by the user in a Popup window.
# Please note that this user-value should be the value
# excluding the power of 10 (for example if its 1uF, then
# just include value "1").
# Right click on the net, select "Filter Parasitic"
# and select "Filter Capacitors" and add a threshold value
# in the Popup window.
# -----------------------------------------------------------------------------
#
proc FilterParasitic:_filterCapacitors {db parasiticModule} {
set command [list FilterParasitic:_filterCap $db $parasiticModule]
FilterParasitic:_showFilterPopup \
.filter_capacitor \
"Filter Capacitor" \
$command
}
# -----------------------------------------------------------------------------
# _filterRes - procedure to get the threshold value from the Popup window on
# the selection of filter resistor and performing the filtering
# of resistors.
# -----------------------------------------------------------------------------
#
proc FilterParasitic:_filterRes {db parasiticModule compareOp filterValue} {
$db foreach inst $parasiticModule inst {
##
# Skip all non-resistor instances.
#
if {[$db primFuncOf $inst] != "RES"} {
continue
}
##
# Get the resistance value of this instance.
#
set value [$db attr $inst getValue "R"]
set value [zdb formatvalue fromspice $value]
##
# Skip this instance if the value is above the threshold.
#
if {[FilterParasitic:_skipByValue $compareOp $value $filterValue]} {
continue
}
set conNetList {}
$db foreach pin $inst pin {
if {![$db isConnected $pin]} {
continue
}
lappend conNetList [$db connectedNet $pin]
if {[llength $conNetList] > 2} {
break
}
}
if {[llength $conNetList] != 2} {
continue
}
set net1 [lindex $conNetList 0]
set net2 [lindex $conNetList 1]
$db oper mergeNet $net1 $net2
$db flag $net2 set zombie
$db flag $inst set zombie
}
FilterParasitic:_updateGUI $db
}
# -----------------------------------------------------------------------------
# _filterCap - procedure to get the threshold value from the Popup window on
# the selection of filter capacitor and performing the filtering
# of capacitors.
# -----------------------------------------------------------------------------
#
proc FilterParasitic:_filterCap {db parasiticModule compareOp filterValue} {
$db foreach inst $parasiticModule inst {
##
# Skip all non-capacitor instances.
#
if {[$db primFuncOf $inst] != "CAP"} {
continue
}
##
# Get the capacitance value of this instance.
#
set value [$db attr $inst getValue "C"]
set value [zdb formatvalue fromspice $value]
##
# Skip this instance if the value is above the threshold.
#
if {[FilterParasitic:_skipByValue $compareOp $value $filterValue]} {
continue
}
$db flag $inst set zombie
}
FilterParasitic:_updateGUI $db
}
# -----------------------------------------------------------------------------
# _skipByValue - Check if an object should be skipped by its value with the
# given compare operator.
# -----------------------------------------------------------------------------
#
proc FilterParasitic:_skipByValue {compareOp value filterValue} {
if {$compareOp eq "<"} {
if {$value > $filterValue} {
return true
}
} else {
if {$value < $filterValue} {
return true
}
}
return false
}
# -----------------------------------------------------------------------------
# _extendPopup - Extend the popup menu if the passed oidList supports one of
# the parasitic related commands defined above.
# -----------------------------------------------------------------------------
#
proc FilterParasitic:_extendPopup {popupMenu oidList} {
##
# Get the database (return if the database is empty).
#
set db [gui database get]
if {$db == {}} {
return
}
##
# Do not extend the popup menu if the oidList is either empty or contains
# more than one entry.
#
if {[llength $oidList] != 1} {
return
}
##
# Get the one object from the given oidList.
#
set oid [lindex $oidList 0]
##
# Do not extend the popup menu if the given oid is not a parasitic module.
#
if {!(([$db oid type $oid] eq "module") && [$db oid isparasitic $oid])} {
return
}
##
# Add a cascaded sub-menu "Filter Parasitic".
#
$popupMenu add separator
set subMenu $popupMenu.filterParasitic
destroy $subMenu
menu $subMenu
$popupMenu add cascade -label "Filter Parasitic" -menu $subMenu
##
# Add all "Filter Parasitic" commands to the cascaded popup menu.
#
foreach {
menuEntryName calledProcName needOid
} {
"Remove Resistors" "_removeResistors" true
"Remove Capacitors" "_removeCapacitors" true
"Merge Resistors" "_mergeResistors" false
"Merge Capacitors" "_mergeCapacitors" false
"Filter Resistors" "_filterResistors" true
"Filter Capacitors" "_filterCapacitors" true
} {
set cmd [list $calledProcName $db]
if {$needOid} {
lappend cmd $oid
}
$subMenu add command -label $menuEntryName -command FilterParasitic:$cmd
}
}
# =============================================================================
# Call the initialization procedure.
# =============================================================================
#
FilterParasitic:Init
|