<!--

  Copyright (C) 2006 Helene Parruitte <parruit@enseirb.fr>
  Copyright (C) 2006 Bertrand Ardouin <ardouin@xmodtech.com>
  Copyright (C) 2006, 2007, 2008 Stefan Jahn <stefan@lkcc.org>

  This is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2, or (at your option)
  any later version.

-->

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE admst PUBLIC "-//adms//DTD admst 2.0//-" "http://mot-adms.sourceforge.net/xml-files/adms/admst.dtd">
<admst version="2.3.0" xmlns:admst="http://mot-adms.sourceforge.net/xml-files/admst">

<!-- handling of expression -->
<admst:template match=":expression">
  <admst:value-of select="tree/adms/datatypename"/>
  <admst:apply-templates select="tree" match=":%s" required="yes"/>
</admst:template>

<admst:template match=":number">
  <admst:value-of select="value"/>
  <admst:choose>
    <admst:when test="[scalingunit='1']">%s</admst:when>
    <admst:when test="[scalingunit='E']">%sE</admst:when>
    <admst:when test="[scalingunit='P']">%sP</admst:when>
    <admst:when test="[scalingunit='T']">%sT</admst:when>
    <admst:when test="[scalingunit='G']">%sG</admst:when>
    <admst:when test="[scalingunit='M']">%sM</admst:when>
    <admst:when test="[scalingunit='k']">%sk</admst:when>
    <admst:when test="[scalingunit='h']">(%s*1.0e+2)</admst:when>
    <admst:when test="[scalingunit='D']">(%s*1.0e+1)</admst:when>
    <admst:when test="[scalingunit='d']">(%s*1.0e-1)</admst:when>
    <admst:when test="[scalingunit='c']">(%s*1.0e-2)</admst:when>
    <admst:when test="[scalingunit='m']">%sm</admst:when>
    <admst:when test="[scalingunit='u']">%su</admst:when>
    <admst:when test="[scalingunit='n']">%sn</admst:when>
    <admst:when test="[scalingunit='A']">(%s*1.0e-10)</admst:when>
    <admst:when test="[scalingunit='p']">%sp</admst:when>
    <admst:when test="[scalingunit='f']">%sf</admst:when>
    <admst:when test="[scalingunit='a']">%sa</admst:when>
    <admst:otherwise>
      <admst:value-of select="scalingunit"/>
      <admst:fatal format="%s%s: scaling unit not supported\n"/>
    </admst:otherwise>
  </admst:choose>
</admst:template>

<admst:template match=":mapply_unary">
  <admst:if test="[name='plus']"> <admst:text format="+"/> </admst:if>
  <admst:if test="[name='minus']"> <admst:text format="-"/> </admst:if>
  <admst:if test="[name='not']"> <admst:text format="!"/> </admst:if>
  <admst:if test="[name='bw_not']"> <admst:text format="~"/> </admst:if>
  <admst:value-of select="arg1/adms/datatypename"/>	
  <admst:apply-templates select="arg1" match=":%s" required="yes"/>
</admst:template>

<admst:template match=":string">
  <admst:value-of select="value"/>%s
</admst:template>

<admst:template match=":variable">
  <!--admst:value-of select="name"/>%s-->
  <!-- recurse, return final value -->
  <admst:apply-templates select="default" match=":expression"/>
</admst:template>

<!-- handling of device: starting point -->
<admst:for-each select="/module">
<!-- definition of variables -->
<admst:value-of select="name"/>
<admst:variable name="module" select="%s"/>
<admst:count select="node"/>
<admst:variable name="nbr_nodes" select="%s"/>
</admst:for-each>

<admst:open file="$module.gui.cpp">/*
 * $(module).cpp - device implementations for $(module) module
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 * 
 */

<admst:text format="\n#include &quot;$module.gui.h&quot;\n\n"/>
<admst:text format="$module::$module()\n{\n"/>
<admst:text format="  Description = QObject::tr (&quot;$module verilog device&quot;);\n\n"/>

<admst:if test="[$module='hic0_full' or $module='hicumL0V1p2']">
<admst:text format="  Props.append (new Property (&quot;Type&quot;, &quot;npn&quot;, true,\n"/>
<admst:text format="    QObject::tr (&quot;polarity&quot;) + &quot; [npn, pnp]&quot;));\n"/>
</admst:if>
<admst:if test="[$module='mosfetbsim4']">
<admst:text format="  Props.append (new Property (&quot;Type&quot;, &quot;nfet&quot;, true,\n"/>
<admst:text format="    QObject::tr (&quot;polarity&quot;) + &quot;[nfet, pfet]&quot;));\n"/>
</admst:if>

<admst:for-each select="/module">

<!-- find temp and tnom parameters -->
<admst:variable name="tnom" string="none"/>
<admst:variable name="temp" string="none"/>
<admst:for-each select="variable">
  <admst:if test="[input='yes']">
    <admst:if test="[upper-case(name)='TNOM']">
      <admst:variable name="tnom" path="."/>
    </admst:if>
    <admst:if test="[upper-case(name)='TEMP']">
      <admst:variable name="temp" path="."/>
    </admst:if>
  </admst:if>
</admst:for-each>

<admst:for-each select="variable">
  <admst:if test="[input='yes' and name!='npn' and name !='pnp']">
    <admst:value-of select="name"/>  
    <admst:text format="  Props.append (new Property (&quot;%s&quot;, &quot;"/> 
    <admst:apply-templates select="default" match=":expression"/>
    <admst:text format="&quot;, false,\n    QObject::tr (&quot;"/>
    <admst:choose>
      <admst:when test="attribute[name='info']">
        <admst:value-of select="attribute[name='info']/value"/>
	<admst:text format="%s"/>
      </admst:when>
      <admst:when test="attribute[name='desc']">
        <admst:value-of select="attribute[name='desc']/value"/>
	<admst:text format="%s"/>
      </admst:when>
      <admst:when test="attribute[name='unit']">
        <admst:value-of select="attribute[name='unit']/value"/>
	<admst:text format=" (%s)"/>
      </admst:when>
      <admst:otherwise>-</admst:otherwise>
    </admst:choose>
    <admst:text format="&quot;)"/>
    <admst:choose>
      <admst:when test="attribute[name='unit']">
        <admst:value-of select="attribute[name='unit']/value"/>
	<admst:text format="\n    +&quot; (&quot;"/>
	<admst:text format="+QObject::tr (&quot;%s&quot;)"/>
	<admst:text format="+&quot;)&quot;"/>
      </admst:when>
    </admst:choose>
    <admst:text format="));\n"/>
  </admst:if>
</admst:for-each>
</admst:for-each>

<admst:if test="[name!='mod_amp']">
  <admst:if test="[$temp='none']">
  <admst:text format="  Props.append (new Property (&quot;Temp&quot;, &quot;"/>
  <admst:choose>
    <admst:when test="[$tnom!='none']">
      <admst:apply-templates select="$tnom/default" match=":expression"/>
    </admst:when>
    <admst:otherwise><admst:text format="26.85"/></admst:otherwise>
  </admst:choose>
  <admst:text format="&quot;, false,\n    "/>
  <admst:text format="QObject::tr (&quot;simulation temperature&quot;)));\n"/>
  </admst:if>
</admst:if>

<admst:text format="\n  createSymbol ();\n  tx = x2 + 4;\n  ty = y1 + 4;\n"/>
<admst:text format="  Model = &quot;$module&quot;;\n  Name  = &quot;T&quot;;\n"/>

<admst:text format="}\n\n"/>

<admst:text format="Component * $module::newOne()\n{\n  $module * p = new $module();"/>
  p->Props.getFirst()->Value = Props.getFirst()->Value; 
  p->recreate(0); 
  return p;
}

<admst:text format="\n"/>
<admst:text format="Element * $module::info(QString&amp; Name, char * &amp;BitmapFile, bool getNewOne)\n"/>
<admst:text format="{\n  Name = QObject::tr(&quot;$module&quot;);\n"/>

<admst:choose>
<admst:when test="[$module='hicumL2V2p1' or $module='hic2_full' or $module='hic0_full' or $module='hicumL0V1p2' or $module='hicumL2V2p23']">
<admst:text format="  BitmapFile = (char *) &quot;npnsub_therm&quot;;\n"/>
</admst:when>
<admst:when test="[$module='HBT_X']">
<admst:text format="  BitmapFile = (char *) &quot;npn_therm&quot;;\n"/>
</admst:when>
<admst:otherwise>
<admst:text format="  BitmapFile = (char *) &quot;$module&quot;;\n"/>
</admst:otherwise>
</admst:choose>

<admst:text format="\n  if(getNewOne) return new $module();\n  return 0;\n}\n\n"/>

<admst:if test="[$module='hic0_full' or $module='hicumL0V1p2']">
<admst:text format="Element * $module::info_pnp(QString&amp; Name, char * &amp;BitmapFile, bool getNewOne)\n"/>
<admst:text format="{\n  Name = QObject::tr(&quot;pnp $module&quot;);\n  BitmapFile = (char *) &quot;pnpsub_therm&quot;;\n\n"/>
<admst:text format="  if(getNewOne)\n  {\n    $module* p = new "/>
<admst:text format="$module();\n    p->Props.getFirst()->Value = &quot;pnp&quot;;\n    p->recreate(0);\n    return p;\n  }\n  return 0;\n}\n\n"/>
</admst:if>

<admst:text format="void $module::createSymbol()\n{"/>
<admst:choose>
<admst:when test="[$module='hicumL2V2p1' or $module='hic2_full' or $module='HBT_X' or $module='hic0_full' or $module='hicumL0V1p2' or $module='hicumL2V2p23']">
  // normal bipolar
  Lines.append(new Line(-10,-15,-10, 15,QPen(QPen::darkBlue,3)));
  Lines.append(new Line(-30,  0,-10,  0,QPen(QPen::darkBlue,2)));
  Lines.append(new Line(-10, -5,  0,-15,QPen(QPen::darkBlue,2)));
  Lines.append(new Line(  0,-15,  0,-30,QPen(QPen::darkBlue,2)));
  Lines.append(new Line(-10,  5,  0, 15,QPen(QPen::darkBlue,2)));
  Lines.append(new Line(  0, 15,  0, 30,QPen(QPen::darkBlue,2)));

  // substrate node
  Lines.append(new Line(  9,  0, 30,  0,QPen(QPen::darkBlue,2)));
  Lines.append(new Line(  9, -7,  9,  7,QPen(QPen::darkBlue,3)));

  // thermal node
  Lines.append(new Line(-30, 20,-20, 20,QPen(QPen::darkBlue,2)));
  Lines.append(new Line(-20, 17,-20, 23,QPen(QPen::darkBlue,2)));  

  // arrow
  if(Props.getFirst()->Value == "npn") {
    Lines.append(new Line( -6, 15,  0, 15,QPen(QPen::darkBlue,2)));
    Lines.append(new Line(  0,  9,  0, 15,QPen(QPen::darkBlue,2)));
  } else {
    Lines.append(new Line( -5, 10, -5, 16,QPen(QPen::darkBlue,2)));
    Lines.append(new Line( -5, 10,  1, 10,QPen(QPen::darkBlue,2)));
  }

  // terminal definitions
  Ports.append(new Port(  0,-30)); // collector
  Ports.append(new Port(-30,  0)); // base
  Ports.append(new Port(  0, 30)); // emitter
  Ports.append(new Port( 30,  0)); // substrate
  Ports.append(new Port(-30, 20)); // thermal node

  // relative boundings
  x1 = -30; y1 = -30;
  x2 =  30; y2 =  30;
</admst:when>
<admst:when test="[$module='mosfetbsim4']">
  // normal mosfet
  Lines.append(new Line(-14,-13,-14, 13,QPen(QPen::darkBlue,3)));
  Lines.append(new Line(-30,  0,-14,  0,QPen(QPen::darkBlue,2)));
  Lines.append(new Line(-10,-11,  0,-11,QPen(QPen::darkBlue,2)));
  Lines.append(new Line(  0,-11,  0,-30,QPen(QPen::darkBlue,2)));
  Lines.append(new Line(-10, 11,  0, 11,QPen(QPen::darkBlue,2)));
  Lines.append(new Line(  0, 11,  0, 30,QPen(QPen::darkBlue,2)));

  // bulk connection
  Lines.append(new Line(-10,  0, 20,  0,QPen(QPen::darkBlue,2)));

  // channel start and end
  Lines.append(new Line(-10,-16,-10, -7,QPen(QPen::darkBlue,3)));
  Lines.append(new Line(-10,  7,-10, 16,QPen(QPen::darkBlue,3)));

  // source marker
  Lines.append(new Line( -4, 24,  4, 20,QPen(QPen::darkBlue,2)));

  // arrow
  if(Props.first()->Value == "nfet") {
    Lines.append(new Line( -9,  0, -4, -5,QPen(QPen::darkBlue,2)));
    Lines.append(new Line( -9,  0, -4,  5,QPen(QPen::darkBlue,2)));
  }
  else {
    Lines.append(new Line( -1,  0, -6, -5,QPen(QPen::darkBlue,2)));
    Lines.append(new Line( -1,  0, -6,  5,QPen(QPen::darkBlue,2)));
  }

  // channel depletion / enhancement
  if((Props.next()->Value.stripWhiteSpace().at(0) == '-') ==
     (Props.first()->Value == "nfet"))
    Lines.append(new Line(-10, -8,-10,  8,QPen(QPen::darkBlue,3)));
  else
    Lines.append(new Line(-10, -4,-10,  4,QPen(QPen::darkBlue,3)));

  // terminal definitions
  Ports.append(new Port(-30,  0)); // gate
  Ports.append(new Port(  0,-30)); // drain
  Ports.append(new Port(  0, 30)); // source
  Ports.append(new Port( 20,  0)); // bulk

  // relative boundings
  x1 = -30; y1 = -30;
  x2 =  30; y2 =  30;
</admst:when>
<admst:when test="[$module='mod_amp' or $module='log_amp']">
  // normal amplifier symbol
  Lines.append(new Line(-30,-20,-20,-20,QPen(QPen::darkBlue,2)));
  Lines.append(new Line(-30, 20,-20, 20,QPen(QPen::darkBlue,2)));
  Lines.append(new Line( 30,  0, 40,  0,QPen(QPen::darkBlue,2)));
  Lines.append(new Line(-20,-35,-20, 35,QPen(QPen::darkBlue,2)));
  Lines.append(new Line(-20,-35, 30,  0,QPen(QPen::darkBlue,2)));
  Lines.append(new Line(-20, 35, 30,  0,QPen(QPen::darkBlue,2)));

  // terminal definitions
  Ports.append(new Port(-30,-20)); // plus
  Ports.append(new Port(-30, 20)); // minus
  Ports.append(new Port( 40,  0)); // output

  // relative boundings
  x1 = -30; y1 = -38;
  x2 =  30; y2 =  38;
</admst:when>
<admst:when test="[$module='diode']">
  // normal diode
  Lines.append(new Line(-30,  0, 30,  0,QPen(QPen::darkBlue,2)));
  Lines.append(new Line( -6, -9, -6,  9,QPen(QPen::darkBlue,2)));
  Lines.append(new Line(  6, -9,  6,  9,QPen(QPen::darkBlue,2)));
  Lines.append(new Line( -6,  0,  6, -9,QPen(QPen::darkBlue,2)));
  Lines.append(new Line( -6,  0,  6,  9,QPen(QPen::darkBlue,2)));

  // Schottky
  if(Props.getLast()->Value.at(0) == 'S') {
    Lines.append(new Line( -6, -9,-12,-12,QPen(QPen::darkBlue,2)));
    Lines.append(new Line( -6,  9,  0, 12,QPen(QPen::darkBlue,2)));
  }
  // Zener
  else if(Props.getLast()->Value.at(0) == 'Z') {
    Lines.append(new Line( -6, 9, -1, 9,QPen(QPen::darkBlue,2)));
  }

  // terminal definitions
  Ports.append(new Port(-30, 0)); // cathode
  Ports.append(new Port( 30, 0)); // anode

  // relative boundings
  x1 = -30; y1 = -11;
  x2 =  30; y2 =  11;
</admst:when>
<admst:otherwise>
  // put in here symbol drawing code and terminal definitions
</admst:otherwise>
</admst:choose>
<admst:text format="\n}\n"/>
</admst:open>

<admst:open file="$module.gui.h">/*
 * $(module).h - device definitions for $(module) module
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 * 
 */

<admst:text format="\n"/>
<admst:text format="#ifndef $module"/>_H\n
<admst:text format="#define $module"/>_H\n\n
<admst:text format="#include &quot;component.h&quot;\n\n"/>

<admst:choose>
<admst:when test="[$module='mosfetbsim4' or $module='hic0_full' or $module='hicumL0V1p2']">
<admst:text format="class $module : public MultiViewComponent\n{\n  public:\n"/>
</admst:when>
<admst:otherwise>
<admst:text format="class $module : public Component\n{\n  public:\n"/>
</admst:otherwise>
</admst:choose>
<admst:text format="    $module();\n"/>
<admst:text format="    ~$module() { };\n"/>
<admst:text format="    Component* newOne();\n    static Element* info(QString&amp;, char* &amp;, bool getNewOne=false);\n"/>
<admst:if test="[$module='hic0_full' or $module='hicumL0V1p2']">
<admst:text format="    static Element* info_pnp(QString&amp;, char* &amp;, bool getNewOne=false);\n"/>
</admst:if>
<admst:text format="  protected:\n    void createSymbol();\n};\n\n"/>

<admst:text format="#endif /* $(module)_H */\n"/>

</admst:open>
<admst:message format="$module.gui.cpp and $module.gui.h: files created\n"/>
</admst>
