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
###############################################################################
# Copyright (c) 2011-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.
# =============================================================================
#   @userware
#       Import Timings from TimeQuest
#   @section
#       Link to Other Tools
#   @description
#       A Userware to visualize the results of the `sta_report.tcl` script.
#
#       This is a Userware to provide a widget to manage timing paths.
#       The script `sta_report.tcl` executed in Altera's TimeQuest tool will
#       generate an output file that uses this PathVision Userware.
#   @files
#       quartus/pathVision.tcl
#   @tag
#       rtl verilog fpga
###############################################################################


# =============================================================================
# Show - The main procedure: shows the PathVision widget.
# =============================================================================
#
proc PathVision:Show {} {
    global PathVision

    ##
    # Show the 'Cone' tab.
    #
    gui window show Cone

    ##
    # Set the name of the custom widget.
    #
    set name "Path Vision"

    ##
    # Destroy an existing custom widgets.
    #
    if {[gui window exists $name]} {
        gui window removeCustomWidget $name
    }

    ##
    # Create the PathVision widget.
    #
    set PathVision(db) {}
    PathVision:_create [gui window insertCustomWidget $name]
}


# =============================================================================
# DataBaseChanged - Remember the database.
# =============================================================================
#
proc PathVision:DataBaseChanged {} {
    global PathVision

    set db [gui database get]
    set PathVision(db) $db
}


# =============================================================================
# AddPath - Add a path to the PathVision mega-widget. The pathInfo list expects
#           the following format: {OID Incr Total Type RF}.
# =============================================================================
#
proc PathVision:AddPath {db pathInfo} {
    global PathVision

    ##
    # Check that the database is set.
    #
    if {$PathVision(db) == {}} {
        return
    }

    ##
    # Count the number of entries.
    #
    set n 1
    foreach row [$PathVision(table) children {}] {
        incr n
    }
    set node [$PathVision(table) insert {} end -text "Path $n"]

    ##
    # Loop over all items in pathInfo and add the values to the table.
    #
    foreach item $pathInfo {
        set oid [lindex $item 0]
        set printCmd [list $db oid print $oid -noroot -nopath]
        set type [{*}$printCmd -noname -addwidth -addrange -typeastitle]
        set name [{*}$printCmd -noroot -nopath -notype -hiersep [$db hiersep]]
        $PathVision(table) insert $node end \
            -text   "$type: $name" \
            -tags   $oid \
            -values [lrange $item 1 end]
    }
}


# =============================================================================
# Clear - Clear the PathVision widget.
# =============================================================================
#
proc PathVision:Clear {} {
    global PathVision

    foreach row [$PathVision(table) children {}] {
        $PathVision(table) delete $row
    }
}


# -----------------------------------------------------------------------------
# _double - Binding for a double click in the table.
# -----------------------------------------------------------------------------
#
proc PathVision:_double {w x y} {
    global PathVision

    ##
    # Identify the item under the mouse and
    # return for if it is not a table entry.
    #
    set identification [$w identify $x $y]
    if {$identification == "nothing"} {
        return
    }
    if {[string match "heading #*" $identification]} {
        return
    }
    if {[string match "separator #*" $identification]} {
        return
    }

    ##
    # If the clicked element is a leaf node then call gui goto and return.
    #
    set oid [$w item [$w selection] -tags]
    if {$oid != {}} {
        gui goto [list $oid]
        return
    }

    ##
    # Clear all flat attributes.
    #
    $PathVision(db) foreach top top {$PathVision(db) flatattr $top deleteAll}

    ##
    # Get the oidList of the selected path.
    #
    set oidList [PathVision:_getSelected $w true false]

    ##
    # Load the path into the Cone window and zoom to fullfit.
    #
    gui cone load $oidList
    gui cone zoom fullfit

    ##
    # Update the meta attributes to display total and incr values at pins and
    # inform the GUI that the attributes have changed.
    #
    $PathVision(db) attr -db set "@nlv:pin=Total=%total\nIncr=%incr"
    gui attribute changed
}


# -----------------------------------------------------------------------------
# _showPath - Show one path in the Cone window.
# -----------------------------------------------------------------------------
#
proc PathVision:_showPath {} {
    global PathVision

    ##
    # Clear all flat attributes.
    #
    $PathVision(db) foreach top top {$PathVision(db) flatattr $top deleteAll}

    ##
    # Get the oidList of the selected path.
    #
    set oidList [PathVision:_getSelected $PathVision(table) true true]

    ##
    # Load the path into the Cone window and zoom to fullfit.
    #
    gui cone load $oidList
    gui cone zoom fullfit

    ##
    # Update the meta attributes to display total and incr values at pins and
    # inform the GUI that the attributes have changed.
    #
    $PathVision(db) attr -db set "@nlv:pin=Total=%total\nIncr=%incr"
    gui attribute changed
}


# -----------------------------------------------------------------------------
# _showAll - Load all paths to the Cone window.
# -----------------------------------------------------------------------------
#
proc PathVision:_showAll {} {
    global PathVision

    set w $PathVision(table)

    $PathVision(db) foreach top top {$PathVision(db) flatattr $top deleteAll}

    ##
    # Create a list of OIDs for all entries in the table.
    #
    set oidList {}
    foreach row [$w children {}] {
        foreach child [$w children $row] {
            ##
            # Get the OID of this node.
            #
            set oid [$w item $child -tags]
            lappend oidList $oid

            ##
            # Add timing values to the database.
            #
            set values [$w item $child -values]
            PathVision:_addValues $PathVision(db) $oid $values
        }
    }

    ##
    # Load the path into the Cone window and zoom to fullfit.
    #
    gui cone load $oidList
    gui cone zoom fullfit

    ##
    # Update the meta attributes to display total and incr values at pins and
    # inform the GUI that the attributes have changed.
    #
    $PathVision(db) attr -db set "@nlv:pin=Total=%total\nIncr=%incr"
    gui attribute changed
}


# -----------------------------------------------------------------------------
# _highlight - Highlight the selected path.
# -----------------------------------------------------------------------------
#
proc PathVision:_highlight {{color -1}} {
    global PathVision

    ##
    # Get a list of all objects for the current selection.
    #
    set oidList [PathVision:_getSelected $PathVision(table) false false]
    if {$oidList == {}} {
        return
    }

    ##
    # If no highlight color was specified then use the global setting.
    #
    if {$color < 0} {
        set color [gui settings get "hiColor"]
    }

    ##
    # Set the highlight for each object.
    #
    foreach oid $oidList {
        $PathVision(db) flathilight $oid set $color
    }

    ##
    # Inform the GUI that the highlight information has changed.
    #
    gui highlight changed
}


# -----------------------------------------------------------------------------
# _getSelected - Return an oidList with all selected paths.
# -----------------------------------------------------------------------------
#
proc PathVision:_getSelected {w addAttr onlyPath} {
    global PathVision

    ##
    # Loop over all selected items in the table.
    #
    set db $PathVision(db)
    set oidList {}
    foreach sel [$w selection] {
        ##
        # If this selected item has no children then it is a leaf node. in this
        # case add only the associated OID to the result list.
        # Else add all children to the result list.
        #
        if {[$w children $sel] == {}} {
            ##
            # Do not add leaf nodes if onlyPath is true.
            #
            if {$onlyPath} {
                continue
            }

            ##
            # Append this object to the result list.
            #
            lappend oidList [$w item $sel -tags]
        } else {
            ##
            # Add pins and netSeg objects to oidList.
            #
            foreach {item1 item2} [$w children $sel] {
                if {$item1 == {}} {
                    break
                }

                set p1 [$w item $item1 -tags]
                lappend oidList $p1

                ##
                # Add timing values for pin1 to the database.
                #
                if {$addAttr} {
                    set values [$w item $item1 -values]
                    PathVision:_addValues $db $p1 $values
                }

                if {$item2 == {}} {
                    break
                }

                set p2 [$w item $item2 -tags]
                if {![catch {$db oid createNetSeg $p1 $p2} netS]} {
                    lappend oidList $netS
                }
                lappend oidList $p2

                ##
                # Add timing values for pin2 to the database.
                #
                if {$addAttr} {
                    set values [$w item $item2 -values]
                    PathVision:_addValues $db $p2 $values
                }
            }
        }
    }

    return $oidList
}


# -----------------------------------------------------------------------------
# _addValues - Add timing values to the database.
# -----------------------------------------------------------------------------
#
proc PathVision:_addValues {db oid values} {
    $db flatattr $oid set "incr=[lindex $values 0]"
    $db flatattr $oid set "total=[lindex $values 1]"
    $db flatattr $oid set "type=[lindex $values 2]"
    $db flatattr $oid set "rf=[lindex $values 3]"
}


# -----------------------------------------------------------------------------
# _create - build the GUI to visualize paths.
# -----------------------------------------------------------------------------
#
proc PathVision:_create {w} {
    global PathVision

    ##
    # Create a toolbar and add some control buttons.
    #
    set PathVision(toolbar) [ttk::frame $w.toolbar]
    ttk::button $w.toolbar.showPath  -text    "Show Path" \
                                     -command "PathVision:_showPath"
    ttk::button $w.toolbar.showAll   -text    "Show All Paths" \
                                     -command "PathVision:_showAll"
    ttk::button $w.toolbar.highlight -text    "Highlight" \
                                     -command "PathVision:_highlight"
    pack $w.toolbar.showPath  -side left
    pack $w.toolbar.showAll   -side left
    pack $w.toolbar.highlight -side left

    ##
    # Use a Tree (as a table) to display the paths.
    #
    set PathVision(table) [ttk::treeview $w.table -columns {"Incr" "Total"} \
                           -yscrollcommand [list $w.scrollbar set]]
    $w.table heading #0      -text "Path"  -anchor w
    $w.table heading "Incr"  -text "Incr"  -anchor w
    $w.table column  "Incr"  -anchor w     -width 7
    $w.table heading "Total" -text "Total" -anchor w
    $w.table column  "Total" -anchor w     -width 7

    ttk::scrollbar $w.scrollbar -orient vertical -command [list $w.table yview]

    bind $w.table <Double-1> {
        PathVision:_double %W %x %y
        break
    }

    grid $w.toolbar   -row 0 -column 0 -sticky we   -columnspan 2
    grid $w.table     -row 1 -column 0 -sticky news
    grid $w.scrollbar -row 1 -column 1 -sticky ns
    grid columnconfigure $w 0 -weight 1
    grid rowconfigure    $w 1 -weight 1
}