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 | ###############################################################################
# Copyright (c) 2010-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
# Save/Restore Rotation and Orientation
# @namespace
# SaveRestoreRotation
# @section
# Miscellaneous Userware Examples
# @description
# Save/Restore the module rotation and pin orientation
# @test
# ModuleTest
# @configuration
# @files
# saveRotation.tcl
# @example
# demo/rtl/aquarius/aquarius.f
# @cmdline
# -F @example[0]
# -userware @files[0]
# @tag
# gui zdb
###############################################################################
set SaveRestoreRotation(scriptName) [info script]
# =============================================================================
# Init - Initialize the plugin.
# =============================================================================
#
proc SaveRestoreRotation:Init {} {
##
# Add selection box to config to allow overwriting existing files
#
gui plugin addConfig SaveRestoreRotation overwriteLayoutFiles 0 bool \
"Overwrite existing files"
gui menu command {"Userware" "Save Rotation Information"} \
SaveRestoreRotation:Save
gui menu command {"Userware" "Restore Rotation Information"} \
SaveRestoreRotation:Restore
}
# =============================================================================
# Finit - Finalize the plugin.
# =============================================================================
#
proc SaveRestoreRotation:Finit {} {
gui menu removeEntry {"Userware" "Save Rotation Information"}
gui menu removeEntry {"Userware" "Restore Rotation Information"}
}
# =============================================================================
# Save - Save all available rotation and orientation data as a tcl script
# for each module.
# =============================================================================
#
proc SaveRestoreRotation:Save {{dir {}} {overwriteEnabled {}}} {
global SaveRestoreRotation
##
# Return if the database is empty.
#
set db [gui database get]
if {$db == {}} {
return
}
if {$overwriteEnabled == {}} {
set overwriteEnabled [gui plugin getConfigValue SaveRestoreRotation \
overwriteLayoutFiles]
} elseif {![string is boolean $overwriteEnabled]} {
zmessage print ERR \
"Expected type boolean for overwriteEnabled: $overwriteEnabled"
set overwriteEnabled false
}
if {$dir == {}} {
##
# Ask the user for the target directory.
# Return if no directory was selected.
#
set dir [gui window fileDialog chooseDir "Select Output Directory" {}]
if {$dir == {}} {
return
}
}
##
# Create directory if it is not present yet.
#
if {![file exists $dir]} {
file mkdir $dir
}
$db foreach module mod {
set name [$db oid module $mod]
set fname [file join $dir "$name rotationInfo.tcl"]
if {[file exists $fname] && (!$overwriteEnabled)} {
gui console print \
"Skipping module $name, file already exists: $fname"
continue
}
set moduleRotation {}
set portRotation {}
lassign [SaveRestoreRotation:_handleModule $db $mod] \
moduleRotation portRotation
if {[llength $moduleRotation] == 0 && [llength $portRotation] == 0} {
continue
}
set f [open $fname wb]
##
# Write a header to the output file.
# 0. Get database:
#
puts $f "# Created by $SaveRestoreRotation(scriptName)"
puts $f "set db \[gui database get\]"
puts $f "set moduleRotation \{"
foreach module $moduleRotation {
puts $f "\t$module"
}
puts $f "\}"
puts $f "set portRotation \{"
foreach port $portRotation {
puts $f "\t$port"
}
puts $f "\}"
puts $f {
foreach {module rotation} $moduleRotation {
$db orient $module $rotation
}
foreach {port rotation} $portRotation {
$db flag $port set $rotation
}
gui schem regenerate
}
close $f
gui console print "Saved rotation information in $fname"
}
gui console print "Saving rotation information done"
}
# =============================================================================
# Restore - After reading in a new design (and defining a new database)
# this procedure will check for each database module, if it
# can find a file named $modulename rotationInfo.tcl - and if so it
# will execute the tcl code stored in this file to restore
# the rotation and orientation information.
# =============================================================================
#
proc SaveRestoreRotation:Restore {{dir {}} {db {}}} {
##
# Return if the database is empty.
#
if {$db == {}} {
set db [gui database get]
if {$db == {}} {
return
}
}
if {$dir == {}} {
##
# Ask the user for the source directory.
#
set dir [gui window fileDialog chooseDir \
"Select Directory To Restore From" {}]
if {$dir == {}} {
return
}
}
$db foreach module mod {
set name [$db oid module $mod]
set fname [file join $dir "$name rotationInfo.tcl"]
if {[file exists $fname]} {
gui console print "Loading layout for module $name from $fname"
source $fname
}
}
}
# -----------------------------------------------------------------------------
# _handleModule - Traverse one level of hierarchy starting at $module.
# -----------------------------------------------------------------------------
#
proc SaveRestoreRotation:_handleModule {db mod} {
##
# Loop over all ports and portBuses of the given module.
#
set portRotation {}
$db foreach port $mod oid {
set portRotation \
[SaveRestoreRotation:_handlePorts $db $oid $portRotation]
}
$db foreach portBus $mod oid {
set portRotation \
[SaveRestoreRotation:_handlePorts $db $oid $portRotation]
}
##
# Loop over all instances in the given module.
#
set moduleRotation {}
$db foreach inst $mod inst {
set moduleRotation \
[SaveRestoreRotation:_handleObject $db $inst $moduleRotation]
}
return "{$moduleRotation} {$portRotation}"
}
# -----------------------------------------------------------------------------
# _handleObject - This procedure checks if the object is rotated and
# and writes out the information to the output file.
# -----------------------------------------------------------------------------
#
proc SaveRestoreRotation:_handleObject {db oid moduleRotation} {
##
# Get the rotation information of the current instance.
#
set rotation [$db orient $oid]
if {$rotation eq "R0"} {
return $moduleRotation
}
lappend moduleRotation "{$oid} $rotation"
return $moduleRotation
}
# -----------------------------------------------------------------------------
# _handlePorts - This procedure checks if there is a rotation flag set at the
# given port and writes out the set flag to the output file.
# -----------------------------------------------------------------------------
#
proc SaveRestoreRotation:_handlePorts {db oid portRotation} {
##
# Get the rotation information.
#
set rotation [$db flag $oid get]
if {$rotation eq ""} {
return $portRotation
}
lappend portRotation "{$oid} $rotation"
return $portRotation
}
# =============================================================================
# Call the initialization procedure.
# =============================================================================
#
if {![info exists usedAsSubmodule]} {
SaveRestoreRotation:Init
}
|