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
###############################################################################
# Copyright (c) 2004-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
#       Skill Export
#   @section
#       Miscellaneous Userware Examples
#   @description
#       Export the schematic as Skill.
#       SkillExport Userware example: this Userware can be used to export a
#       design as Skill in batch mode, e.g. start SpiceVision with the following
#       commandline  options:
#       ```
#       spicevisionpro -userware ../demo/api/SkillExport.tcl                 \
#           -symlib ../demo/spice/parity1.sym -symlib /path/to/analogLib.sym \
#           ../demo/spice/parity1.sp
#       ```
#
#       The design `parity1.sp` is read into the SpiceVision database, all
#       primitive symbols are mapped as specified in the spice lines of your
#       symbol library `analogLib.sym`. All sub-circuit symbols are mapped from
#       `demo/spice/parity1.sym`. If you don't know how to create your symbol
#       library (analogLib.sym) and how to map the symbols, then please refer
#       to the `doc/skillExportTutorial.html`.
#
#       After the Skill file is written SpiceVision will quit.
#   @test
#       ModuleTest
#   @files
#       SkillExport.tcl
#   @example
#       demo/spice/parity1.sp
#       demo/spice/parity1.sym
#   @cmdline
#       -hspice @example[0]
#       -symlib @example[1]
#       -userware @files[0]
#   @tag
#       gui spice
###############################################################################


# =============================================================================
# This is the configuration section.
# =============================================================================
#
array set options {}
foreach {
    optionName      hasArg extra  defaultValue
} {
    -library        true   false  "sv_lib"
    -filename       true   false  "output.il"
    -outputWhat     true   false  "tree"
    -prolog         true   true   ""
    -epilog         true   true   ""
    -technology     true   true   ""
    -multifile      false  true   false
    -overwrite      false  true   false
    -netlabel       false  true   false
    -instsuffix     false  true   false
    -metric         false  true   false
    -disabletrigger false  true   false
} {
    set options($optionName)       $hasArg
    set options($optionName:extra) $extra
    set options($optionName:value) $defaultValue
}


# =============================================================================
# SkillExport - Call 'gui skill export' and Quit the application.
# =============================================================================
#
proc SkillExport {fname lib what extraOptions db} {
    ##
    # Return if the database is empty.
    #
    if {$db == {}} {
        return
    }

    ##
    # Build export skill cmd.
    #
    set cmd [list gui export skill]

    if {($what eq "tree") || ($what eq "symbol")} {
        set window ""
    } else {
        if {$what eq "module"} {
            set window "Schem"
        } else {
            set window [string totitle $what]
        }
        set what "window"
    }

    lappend cmd $what $window $lib

    ##
    # Add optional parameters:
    #
    lappend cmd {*}$extraOptions

    ##
    # Add the output filename at the end of the command sequence.
    #
    lappend cmd $fname

    ##
    # Evaluate the command.
    #
    {*}$cmd
}


# =============================================================================
# Process all command line options of this script.
# =============================================================================
#
set extraOptions {}
for {set i 0} {$i < $argc} {incr i} {
    set name [lindex $argv $i]
    if {![info exists options($name)]} {
        error "Unknown SkillExport script option: '$name'."
    }

    if {$options($name:extra)} {
        lappend extraOptions $name
    }

    if {$options($name)} {
        if {[incr i] >= $argc} {
            error "Wrong # of args."
        }
        set value [lindex $argv $i]
        if {$options($name:extra)} {
            lappend extraOptions $value
        } else {
            set options($name:value) $value
        }
    }
}


# =============================================================================
# Run SkillExport or register a callback to execute SkillExport after a
# database is available.
# =============================================================================
#
gui database runOrRegisterChangedCallback [list \
    SkillExport                 \
    $options(-filename:value)   \
    $options(-library:value)    \
    $options(-outputWhat:value) \
    $extraOptions               \
]