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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511 | ###############################################################################
# Copyright (c) 2021-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
# Switch Cell Representation
# @namespace
# SwitchCell
# @section
# Analyze the Loaded Database
# @description
# Provide different views for insts. Requires the design to be read with
# '-resolveDuplicates off' which automatically rename the cells and set
# the required attributes for this plugin.
# @test
# ModuleTest
# @files
# cust35/switchCell.tcl
# @example
# demo/rtl/aquarius/aquarius.f
# demo/spice/aquarius.sp
# demo/spice/aquarius.sym
# @cmdline
# -resolveDuplicates off
# -compact off
# -DuplSubckt ignore
# -top '*'
# -guessBus "\[" "\]"
# -F @example[0]
# -spice @example[1]
# -symlib @example[2]
# -userware @files[0]
# @tag
# gui spice rtl
###############################################################################
namespace eval SwitchCell {
variable menuEntries
variable globalViewIndex
variable maxGlobalView
variable instState
}
# =============================================================================
# Init - Initialize the plugin.
# =============================================================================
#
proc ::SwitchCell::Init {} {
variable menuEntries
variable instState
zmessage print DBG "\[SwitchCells\] Initialize Plugin"
set menuEntries {}
array set instState {}
scanDatabase
gui popup customize "SwitchCell::CustomizePopup"
##
# Analyze the db and add the userware menu.
#
addUserwareMenu
##
# Disable flat tree which may get inconsistent during
# database modifications
#
gui settings set populateFastFlatTree 0
gui database registerChangedCallback "SwitchCell::DataBaseChanged"
}
# =============================================================================
# Finit - Finalize the plugin.
# =============================================================================
#
proc ::SwitchCell::Finit {} {
variable origDesignTitle
gui popup removeCustomize "SwitchCell::CustomizePopup"
##
# Remove userware menu.
#
clearUserwareMenu
gui database removeChangedCallback "SwitchCell::DataBaseChanged"
gui window setDesignTitle $origDesignTitle
}
# =============================================================================
# CustomizePopup - Add entries to the popup menu.
# =============================================================================
#
proc ::SwitchCell::CustomizePopup {menu oidList} {
variable instState
##
# Check window class
#
set currentWindow [gui window getCurrent]
if {[gui window getClass $currentWindow] ne "Schem"} {
return
}
set db [gui database get]
if {$db == {}} {
return
}
##
# Check if exactly one item is selected.
#
if {[llength $oidList] != 1} {
return
}
##
# Check if the selected oid is of type inst.
#
set oid [lindex $oidList 0]
set type [$db oid type $oid]
if {$type ne "inst"} {
return
}
##
# Check if views are available.
#
set cell [$db oid down $oid]
set view [$db attr $cell getValue "!view"]
if {$view eq ""} {
return
}
set instState($oid) "View [$db attr $cell getValue "!viewIndex"]"
##
# Add cascaded menu.
#
set viewMenu "$menu.view"
menu $viewMenu
$menu add cascade -label "Show Cell View" -menu $viewMenu
##
# Add an entry for each available view.
#
for {set viewIndex 0} {$viewIndex < $view} {incr viewIndex} {
$viewMenu add radiobutton \
-label "View $viewIndex" \
-command "SwitchCell::ChangeView \"$oid\" $viewIndex" \
-variable SwitchCell::instState($oid)
}
}
# -----------------------------------------------------------------------------
# clearUserwareMenu - Clear the userware menu.
# -----------------------------------------------------------------------------
#
proc ::SwitchCell::clearUserwareMenu {} {
variable menuEntries
##
# Remove all current menu entries.
#
foreach entry [lreverse $menuEntries] {
gui menu removeEntry $entry
}
##
# Reset entries.
#
set menuEntries {}
}
# =============================================================================
# DataBaseChanged - Reinitialize menu if db has changed.
# =============================================================================
#
proc ::SwitchCell::DataBaseChanged {db} {
clearUserwareMenu
array set instState {}
##
# Add entries for the current db.
#
scanDatabase
addUserwareMenu
}
# =============================================================================
# ChangeGlobalView - Change the view to the new view on all insts.
# =============================================================================
#
proc ::SwitchCell::ChangeGlobalView {newViewIndex} {
variable origDesignTitle
variable globalViewIndex
variable menuIndex
set db [gui database get]
if {$db == {}} {
return
}
##
# Get the module tree of the current module.
#
set currentModulePath {}
set module [gui schem getCurrentModule]
if {$module != {}} {
lappend currentModulePath [$db oid oname $module]
while {[$db hasParentMod $module]} {
set module [$db parentModule $module]
lappend currentModulePath [$db oid oname $module]
}
}
##
# Change view of all cells.
#
$db foreach module curModule {
##
# Collect all inst oids since 'oper changecellref' changed the inst
# list.
#
set insts {}
$db foreach inst $curModule curInst {
lappend insts $curInst
}
##
# Change view.
#
foreach inst $insts {
changeCellRef $db $inst $newViewIndex
}
if {[$db isTop $curModule]} {
changeCell $db $curModule $newViewIndex
}
}
$db oper changecellref -updateOIDs
##
# Rename all cells to current view and store old view.
#
$db foreach cell currentCell {
set viewIndex [$db attr $currentCell getValue "!viewIndex"]
set name [$db attr $currentCell getValue "@name"]
if {$viewIndex == $newViewIndex} {
$db oper rename $currentCell $name
} elseif {$viewIndex == $globalViewIndex} {
$db oper rename $currentCell "${name}@view$viewIndex"
}
}
##
# Update all oids and the db.
#
$db oper rename -updateOIDs
gui database modified
##
# Set the title to the current view.
#
set globalViewIndex $newViewIndex
gui window setDesignTitle "${origDesignTitle}@view $newViewIndex"
##
# Set the view of the current module.
#
set currentModule [$db get_top_design]
foreach mod [lreverse $currentModulePath] {
set currentModuleModBased [$db search module $mod]
if {[$db oid isnull $currentModuleModBased]} {
break
}
set currentModule \
[$db oid searchTreeBased $currentModuleModBased $currentModule]
}
gui schem setCurrentModule $currentModule
}
# =============================================================================
# ChangeView - Change the view to the new view.
# =============================================================================
#
proc ::SwitchCell::ChangeView {oid newViewIndex} {
variable globalViewIndex
set db [gui database get]
if {$db == {}} {
return
}
set cellChanged [changeCellRef $db $oid $newViewIndex]
if {!$cellChanged} {
zmessage print ERR \
"\[SwitchCell\] Cannot change view to '$newViewIndex' at '$oid'."
return
}
##
# Update db and dive down.
#
$db oper changecellref -updateOIDs
set curCell [$db oid down $oid]
gui database modified
if {[$db isModule $curCell]} {
##
# Change the view off all children inst.
#
$db flat foreach instOfCell {} $curCell curInst {
changeCellRef $db $curInst $newViewIndex
}
gui schem setCurrentModule $curCell
} else {
gui schem regenerate
gui goto [list $curCell]
}
}
# -----------------------------------------------------------------------------
# changeCell - Change the cell to the given new view index.
# -----------------------------------------------------------------------------
#
proc ::SwitchCell::changeCell {db cell newViewIndex} {
variable globalViewIndex
set view [$db attr $cell getValue "!view"]
if {$view == {}} {
zmessage print DBG "\[Switch Cell\] No view for cell '$cell' available"
return {}
}
set cellName [$db attr $cell getValue "@name"]
if {$newViewIndex == $globalViewIndex} {
set newCellName $cellName
} else {
set newCellName "${cellName}@view${newViewIndex}"
}
##
# Check if a cell for the current view is available.
#
set newCell [$db search cell $newCellName]
if {[$db oid isnull $newCell]} {
zmessage print WAR "\[SwitchCell\] Cell '$newCellName' not found."
return {}
}
##
# Change top module.
#
if {[$db isModule $cell] && [$db isTop $cell]} {
$db top unset $cell
$db top set $newCell
}
return $newCellName
}
# -----------------------------------------------------------------------------
# changeCellRef - Change the view of the given inst to the new view.
# -----------------------------------------------------------------------------
#
proc ::SwitchCell::changeCellRef {db inst newViewIndex} {
set cell [$db oid down $inst]
set newCellName [changeCell $db $cell $newViewIndex]
if {$newCellName == {}} {
zmessage print DBG "\[SwitchCell\] Cell '$cell' cannot be changed."
return false
}
##
# Change the cell reference.
#
$db oper changecellref -similar $inst $newCellName
return true
}
# -----------------------------------------------------------------------------
# scanDatabase - Analyze the db.
# -----------------------------------------------------------------------------
#
proc ::SwitchCell::scanDatabase {} {
variable maxGlobalView
variable globalViewIndex
variable origDesignTitle
set db [gui database get]
set maxGlobalView -1
set origDesignTitle [gui window getDesignTitle]
if {$db == {}} {
return
}
##
# Iterate over all cells and get the count of different views.
#
$db foreach cell currentCell {
set view [$db attr $currentCell getValue "!view"]
if {$view > $maxGlobalView} {
set maxGlobalView $view
}
}
set globalViewIndex 0
##
# Hide all top module which are not of the current view.
#
$db foreach top curTop {
set viewIndex [$db attr $curTop getValue "!viewIndex"]
if {($viewIndex != "") &&
($globalViewIndex != $viewIndex)
} {
$db top unset $curTop
}
}
gui window setDesignTitle "${origDesignTitle}@view $globalViewIndex"
gui database modified
}
# -----------------------------------------------------------------------------
# addUserwareMenu - Add the userware menu.
# -----------------------------------------------------------------------------
#
proc ::SwitchCell::addUserwareMenu {} {
variable menuEntries
variable maxGlobalView
variable menuIndex
##
# Add the base entry to the userware menu.
#
set baseMenuPath {"Userware" "Switch View"}
lappend menuEntries $baseMenuPath
gui menu submenu $baseMenuPath
##
# Add entry for each view.
#
for {set viewIndex 0} {$viewIndex < $maxGlobalView} {incr viewIndex} {
set menuPath [list {*}$baseMenuPath "View $viewIndex"]
lappend menuEntries $menuPath
gui menu radiobutton \
$menuPath \
[list ::SwitchCell::ChangeGlobalView $viewIndex] \
SwitchCell::menuIndex \
view$viewIndex
}
##
# Init menu to view 0.
#
set menuIndex view0
}
# =============================================================================
# Call the initialization procedure.
# =============================================================================
#
::SwitchCell::Init
|