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
###############################################################################
# Copyright (c) 2006-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
#       Show Instance Comment Attribute
#   @namespace
#       ShowInstComment
#   @section
#       Miscellaneous Userware Examples
#   @description
#       Show special instance comment attribute (`$ICOMMENT`) at MOS devices
#       created by the Spice parser in the schematic view.
#       Each instance with this attribute set can be added to the Mem window.
#       The Spice parser option `-icomment` needs to be enabled to get the
#       `$ICOMMENT` attribute at instances.
#   @configuration
#   @license
#       permit spice
#   @files
#       showInstComment.tcl
#   @example
#       demo/spice/multivolt.sp
#   @cmdline
#       -icomment on
#       -hspice @example[0]
#       -userware @files[0]
#   @tag
#       spice gui
###############################################################################


# =============================================================================
# Init - Initialize the plugin.
# =============================================================================
#
proc ShowInstComment:Init {} {
    global ShowInstComment

    ##
    # Initialize the default value to display the instance comment attribute.
    #
    set ShowInstComment(displayIcommentAttribute) 1

    ##
    # Configure a pattern to match the value of the $ICOMMENT attribute value.
    #
    gui plugin addConfig ShowInstComment instCommentPattern "MARKED" text \
        "The pattern to match the value of the \$ICOMMENT attribute value."

    ##
    # Add menu entries.
    #
    gui menu submenu {"Userware" "Instance Comment"}
    gui menu checkbutton {"Userware" "Instance Comment" "Display"} \
        [list ShowInstComment:_toggleInstCommentFromMenu] \
        ShowInstComment(displayIcommentAttribute)
    gui menu command {"Userware" "Instance Comment" "Load to Memory"} \
        [list ShowInstComment:_loadToMemory]

    ##
    # Use gui database runOrRegisterChangedCallback to immediately run
    # toggleInstComment if we have a database, or otherwise register the
    # procedure to be executed after the database is available.
    #
    set ShowInstComment(callbackRegistered) [expr {[gui database get] eq ""}]
    gui database runOrRegisterChangedCallback \
        [list ShowInstComment:_toggleInstComment]
}


# =============================================================================
# Finit - Finalize the plugin.
# =============================================================================
#
proc ShowInstComment:Finit {} {
    global ShowInstComment

    ##
    # Undo modifications of the GUI.
    #
    gui menu removeEntry {"Userware" "Instance Comment"}

    ##
    # Remove the callback registration.
    #
    if {$ShowInstComment(callbackRegistered)} {
        gui database removeChangedCallback "ShowInstComment:_toggleInstComment"
    }
}


# -----------------------------------------------------------------------------
# _toggleInstCommentFromMenu - Call toggleInstComment from the added main
#                              menu entry.
# -----------------------------------------------------------------------------
#
proc ShowInstComment:_toggleInstCommentFromMenu {} {
    ShowInstComment:_toggleInstComment [gui database get]
}


# -----------------------------------------------------------------------------
# _toggleInstComment - Add a meta attribute to the database to display instance
#                      comments coming from Spice, e.g.:
#                      MP VDD A B VDD P W=5U L=1.5U   $ this is a comment
# -----------------------------------------------------------------------------
#
proc ShowInstComment:_toggleInstComment {db} {
    global ShowInstComment

    ##
    # Return if the database is empty.
    #
    if {$db == {}} {
        return
    }

    ##
    # Set the value for the ICOMMENT display attribute.
    #
    set icommentAttr "\n%{\$ICOMMENT}"

    ##
    # Loop over all primitives.
    #
    $db foreach primitive prim {
        ##
        # Skip all functions except NMOS and PMOS.
        #
        set func [$db primFuncOf $prim]
        if {$func != "PMOS" && $func != "NMOS"} {
            continue
        }

        ##
        # Get the current value of the @nlv attribute.
        #
        set curAttrValue [$db attr $prim getValue "@nlv"]

        ##
        # Toggle the ICOMMENT display attribute.
        #
        if {$ShowInstComment(displayIcommentAttribute)} {
            set newAttrValue $curAttrValue
            if {![string match "*ICOMMENT*" $curAttrValue]} {
                append newAttrValue $icommentAttr
            }
        } else {
            set newAttrValue [string map [list $icommentAttr ""] $curAttrValue]
        }
        $db attr $prim set "@nlv=$newAttrValue"
    }

    ##
    # Inform the GUI that the attributes has changed.
    #
    gui attribute changed
}


# -----------------------------------------------------------------------------
# _loadToMemory - Load all instances with a $ICOMMENT attribute set to the
#                 Memory window.
# -----------------------------------------------------------------------------
#
proc ShowInstComment:_loadToMemory {} {
    ##
    # Get the current database.
    #
    set db [gui database get]

    ##
    # Return if the database is empty.
    #
    if {$db == {}} {
        return
    }

    ##
    # Get the pattern to match the attribute value.
    #
    set pattern [gui plugin getConfigValue ShowInstComment instCommentPattern]

    ##
    # Loop over all instances in all modules.
    #
    set resList {}
    $db foreach module mod {
        $db foreach inst $mod inst {
            ##
            # Check if the value of the $ICOMMENT attribute matches
            # the configured pattern.
            #
            set icomment [$db attr $inst getValue {$ICOMMENT}]
            if {($icomment != "") && [string match $pattern $icomment]} {
                lappend resList $inst
            }
        }
    }

    ##
    # Clear and activate the Mem Window
    #
    gui mem clear
    gui window show Schem

    ##
    # Store the result list into the Memory window.
    #
    gui mem append $resList
}


# =============================================================================
# Call the initialization procedure.
# =============================================================================
#
ShowInstComment:Init