<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://www.ansys.com/stackup"
            xmlns="http://www.ansys.com/stackup"
            elementFormDefault="unqualified" >


  <!-- Use the 'schemaVersion' attribute for versioning within the namespace -->

  <xsd:element name="Stackup" type="Stackup" />

  <!-- Type declarations -->

  <xsd:complexType name="Stackup">
    <xsd:sequence>
      <xsd:element name="Materials" type="Materials" minOccurs="0" maxOccurs="1" />
      <xsd:choice>
        <xsd:element name="Layers" type="Layers" />
        <xsd:element name="ELayers" type="ELayers" />
      </xsd:choice>
    </xsd:sequence>
    <xsd:attribute name="schemaVersion" type="xsd:decimal" use="required" fixed="1.0"/>
  </xsd:complexType>

  <xsd:simpleType name="FreqEquation">
    <xsd:restriction base="xsd:token">
      <xsd:pattern value="([0-9]|[ .()+*-/^e]|Freq|abs|exp|ln|log|sqrt|sin|cos|tan|asin|acos|atan|sinh|cosh|tanh)+" />
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="PosDbl">
    <xsd:restriction base="xsd:double">
      <xsd:minInclusive value="0" />
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="OneToOneHundred">
    <xsd:restriction base="xsd:double">
      <xsd:minInclusive value="1" />
      <xsd:maxInclusive value="100" />
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:complexType name="FreqPt">
    <xsd:attribute name="F" type="PosDbl" />
    <xsd:attribute name="Val" type="xsd:double" />
  </xsd:complexType>

  <xsd:complexType name="FreqTbl">
    <xsd:sequence>
      <xsd:element name="Point" type="FreqPt" minOccurs="1" maxOccurs="unbounded" />
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="MaterialProperty">
    <xsd:choice>
      <xsd:element name="Double" type="xsd:double" />
      <xsd:element name="Equation" type="FreqEquation" />
      <xsd:element name="Table" type="FreqTbl" />
    </xsd:choice>
  </xsd:complexType>

  <xsd:complexType name="Material">
    <xsd:all>
      <xsd:element name="Permittivity" type="MaterialProperty" minOccurs="0" />
      <xsd:element name="Permeability" type="MaterialProperty" minOccurs="0" />
      <xsd:element name="Conductivity" type="MaterialProperty" minOccurs="0" />
      <xsd:element name="DielectricLossTangent" type="MaterialProperty" minOccurs="0" />
      <xsd:element name="MagneticLossTangent" type="MaterialProperty" minOccurs="0" />
    </xsd:all>
    <xsd:attribute name="Name" type="xsd:string" />
  </xsd:complexType>

  <xsd:complexType name="Materials">
    <xsd:sequence>
      <xsd:element name="Material" type="Material" minOccurs="1" maxOccurs="unbounded" />
    </xsd:sequence>
  </xsd:complexType>

  <xsd:simpleType name="LayerType">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="conductor" />
      <xsd:enumeration value="plane" />
      <xsd:enumeration value="dielectric" />
      <xsd:enumeration value="assembly" />
      <xsd:enumeration value="soldermask" />
      <xsd:enumeration value="solderpaste" />
      <xsd:enumeration value="silkscreen" />
      <xsd:enumeration value="wirebond" />
      <xsd:enumeration value="user" />
      <xsd:enumeration value="drill" />
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="HexColor">
    <xsd:restriction base="xsd:token">
      <xsd:pattern value="#([0-9a-fA-F]{2}){3}" />
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:attributeGroup name ="LayerAttr">
    <xsd:attribute name="Name" type="xsd:string" use="required" />
    <xsd:attribute name="TargetLayer" type="xsd:string" use="optional" />
    <xsd:attribute name="Color" type="HexColor" use="optional" />
    <xsd:attribute name="Material" type="xsd:string" use="optional" />
    <xsd:attribute name="Thickness" type="PosDbl" use="optional" />
    <xsd:attribute name="GDSIIVia" type="xsd:boolean" use="optional" />
    <xsd:attribute name="GDSDataType" type="xsd:string" use="optional" />
  </xsd:attributeGroup>

  <xsd:attributeGroup name="SignalLayerAttr">
    <xsd:attribute name="Negative" type="xsd:boolean" use="optional" />
    <xsd:attribute name="SolveInside" type="xsd:boolean" use="optional" />
    <xsd:attribute name="EtchFactor" type="xsd:double" use="optional" />
  </xsd:attributeGroup>

  <xsd:complexType name="GroisseSurfaceRoughness">
    <xsd:attribute name="Roughness" type="xsd:string" use="required" />
  </xsd:complexType>

  <xsd:complexType name="HuraySurfaceRoughness">
    <xsd:attribute name="NoduleRadius" type="xsd:string" use="required" />
    <xsd:attribute name="HallHuraySurfaceRatio" type="OneToOneHundred" use="required" />
  </xsd:complexType>

  <xsd:complexType name="Layer">
    <xsd:choice minOccurs="0">
      <xsd:element name="GroisseSurfaceRoughness" type="GroisseSurfaceRoughness" />
      <xsd:element name="HuraySurfaceRoughness" type="HuraySurfaceRoughness" />
    </xsd:choice>
    <xsd:attributeGroup ref="LayerAttr" />
    <xsd:attributeGroup ref="SignalLayerAttr" />
    <xsd:attribute name="Type" type="LayerType" use="required" />
    <xsd:attribute name="FillMaterial" type="xsd:string" use="optional" />
  </xsd:complexType>

  <xsd:complexType name="ELayer">
    <xsd:choice minOccurs="0">
      <xsd:element name="GroisseSurfaceRoughness" type="GroisseSurfaceRoughness" />
      <xsd:element name="HuraySurfaceRoughness" type="HuraySurfaceRoughness" />
    </xsd:choice>
    <xsd:attributeGroup ref="LayerAttr" />
    <xsd:attributeGroup ref="SignalLayerAttr" />
    <xsd:attribute name="Type" type="LayerType" use="required" />
    <xsd:attribute name="Elevation" type="PosDbl" use="optional" />
  </xsd:complexType>

  <xsd:complexType name="DielLayer">
    <xsd:attributeGroup ref="LayerAttr" />
  </xsd:complexType>

  <xsd:simpleType name="LengthType">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="nm" />
      <xsd:enumeration value="um" />
      <xsd:enumeration value="mm" />
      <xsd:enumeration value="cm" />
      <xsd:enumeration value="meter" />
      <xsd:enumeration value="mil" />
      <xsd:enumeration value="in" />
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:complexType name="Layers">
    <xsd:sequence>
      <xsd:element name="Layer" type="Layer" minOccurs="1" maxOccurs="unbounded" />
    </xsd:sequence>
    <xsd:attribute name="LengthUnit" type="LengthType" use="optional" default="mm" />
  </xsd:complexType>

  <xsd:complexType name="Dielectrics">
    <xsd:sequence>
      <xsd:element name="Layer" type="DielLayer" minOccurs="1" maxOccurs="unbounded" />
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="LayersWithElevation">
    <xsd:sequence>
      <xsd:element name="Layer" type="ELayer" minOccurs="1" maxOccurs="unbounded" />
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="ELayers">
    <xsd:sequence>
      <xsd:element name="Dielectrics" type="Dielectrics" minOccurs="0" maxOccurs="1"  />
      <xsd:element name="Layers" type="LayersWithElevation" minOccurs="1" maxOccurs="1" />
    </xsd:sequence>
    <xsd:attribute name="LengthUnit" type="LengthType" use="optional" default="mm" />
  </xsd:complexType>

</xsd:schema>
