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
###############################################################################
# Copyright (c) 2018-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
#       Batch Skill Export
#   @section
#       Miscellaneous Userware Examples
#   @description
#       Export the schematic as Skill in batch mode using starsh.
#
#       Usage::
#       ```
#       starsh demo/api/SkillExportBatch.tcl \
#           -spice <READ_SPICE_OPTIONS>      \
#           -skill <SKILL_EXPORT_OPTIONS>
#       ```
#   @files
#       SkillExportBatch.tcl
#   @tag
#       spice
###############################################################################


# =============================================================================
# Start - Process command line options and invoke read Spice and export Skill.
# =============================================================================
#
proc SkillExportBatch:Start {args} {
    ##
    # Get the start index of the Spice and Skill options.
    #
    set readSpiceOptionsStart   [lsearch -exact $args "-spice"]
    set skillExportOptionsStart [lsearch -exact $args "-skill"]
    if {($readSpiceOptionsStart < 0) || ($skillExportOptionsStart < 0)} {
        error "Spice and Skill options are required."
    }

    ##
    # Spice options need to be before Skill options.
    #
    if {$readSpiceOptionsStart > $skillExportOptionsStart} {
        error "Spice options need to be before Skill options."
    }

    ##
    # Get the read Spice options.
    #
    incr readSpiceOptionsStart
    incr skillExportOptionsStart -1
    set readSpiceOptions [lrange $args  $readSpiceOptionsStart  \
                                        $skillExportOptionsStart]

    ##
    # Get the Skill export options.
    #
    incr skillExportOptionsStart 2
    set skillExportOptions [lrange $args $skillExportOptionsStart end]

    ##
    # Invoke zspice with the read Spice options.
    #
    set db [zspice {*}$readSpiceOptions]

    ##
    # Make sure that the database is sorted topologically.
    #
    $db oper tsort

    ##
    # Invoke ExportSkill with the Skill export options.
    #
    SkillExportBatch:ExportSkill $db $skillExportOptions
}


# =============================================================================
# ExportSkill - Export Skill with the given options.
# =============================================================================
#
proc SkillExportBatch:ExportSkill {db args} {
    set     cmd [list skillexport start]
    lappend cmd -spiceunits
    lappend cmd -norangelabel
    lappend cmd -scale [expr {1.0 / (16 * 10)}]
    set     cmd [concat $cmd {*}$args]
    eval   $cmd

    ##
    # Create a new headless schematic object optimized for skillexport.
    #
    set schem [$db schematic -skillexport]

    ##
    # Set configuration properties.
    #
    foreach {
        name          value
    } {
        ongrid          1
        sheetwidth      0
        sheetheight     0
        geitarget       3
        analoglayout    0
    } {
        $schem property $name $value
    }

    ##
    # Loop over all database modules and load each module into the schematic.
    #
    $db foreach module module {
        ##
        # Get the name of the module.
        #
        set moduleName [$db oid oname $module]

        ##
        # Generate the schematic of the module.
        #
        $schem loadmodule $moduleName

        ##
        # Begin the graphic export.
        #
        set gei [$schem gex begin]

        ##
        # Create the skillexport command.
        #
        set cmd [list skillexport module $moduleName $gei]

        ##
        # The oper collectModuleParam is used to produce correct pPar() calls.
        #
        $db oper collectModuleParam
        set param [$db attr $module getValue @param]
        foreach p [split $param ","] {
            lappend cmd -param $p
        }

        ##
        # Run the skillexport command.
        #
        eval $cmd

        ##
        # End the graphic export.
        #
        $schem gex end
    }

    ##
    # Free the created schematic object.
    #
    $schem free

    skillexport end
}


##
# Start the main procedure.
#
SkillExportBatch:Start {*}$argv