<?xml version="1.0" encoding="UTF-8"?>
<!--
  CabCodeXF — CabCode eXchange Format, 0.1 (pre-release: renumbered from "1.0" on 2026-11-12)
  Machine-neutral panel machining-intent interchange. See ../cabcodexf-spec.md for the
  prose spec, conventions and rationale. This XSD is the validatable contract a
  producer's post-processor is certified against.

  Readers ignore what they do not know; extensions go in another namespace, at
  the xs:any / xs:anyAttribute points below (see "Versions and extensions").

  Conventions enforced here structurally; semantic conventions (datum, faces,
  depth-into-face, grain-explicit) are documented in the spec.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns="https://cabcode.uk/cabcodexf"
           targetNamespace="https://cabcode.uk/cabcodexf"
           elementFormDefault="qualified">

  <!-- ============================================================= root -->
  <xs:element name="CabCodeXF">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Header" type="Header"/>
        <xs:element name="Materials" type="Materials" minOccurs="0"/>
        <xs:element name="EdgeMaterials" type="EdgeMaterials" minOccurs="0"/>
        <xs:element name="Hardware" type="Hardware" minOccurs="0"/>
        <xs:element name="Designs" type="Designs" minOccurs="0"/>
        <!-- A file holds Parts, Designs or both. A file with no Part must have a
             Designs block (the spec's rule; XSD 1.0 cannot express it). -->
        <xs:element name="Part" type="Part" minOccurs="0" maxOccurs="unbounded"/>
        <!-- One per design (design=: that cabinet in its own frame), or one already in the job's frame. -->
        <xs:element name="Assembly" type="Assembly" minOccurs="0" maxOccurs="unbounded"/>
        <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="version" type="xs:string" use="required"/>
      <xs:anyAttribute namespace="##other" processContents="lax"/>
    </xs:complexType>
  </xs:element>

  <!-- ============================================================= header -->
  <xs:complexType name="Header">
    <xs:sequence>
      <!-- Each system that contributed work (see "Provenance" in the spec). -->
      <xs:element name="Originator" minOccurs="0" maxOccurs="unbounded">
        <xs:complexType>
          <xs:attribute name="id" type="OriginatorId" use="required"/>
          <xs:attribute name="name" type="xs:string"/>
          <xs:attribute name="url" type="xs:anyURI"/>
          <xs:anyAttribute namespace="##other" processContents="lax"/>
        </xs:complexType>
      </xs:element>
      <xs:element name="Order" minOccurs="0">
        <xs:complexType>
          <xs:attribute name="ref" type="xs:string"/>
          <xs:attribute name="customer" type="xs:string"/>
          <xs:attribute name="job" type="xs:string"/>          <!-- job number in the originator's system -->
          <xs:attribute name="originator" type="OriginatorId"/>
          <xs:anyAttribute namespace="##other" processContents="lax"/>
        </xs:complexType>
      </xs:element>
      <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="units" type="xs:string" use="required"/>      <!-- "mm" -->
    <xs:attribute name="angleUnit" type="xs:string" default="deg"/>
    <xs:attribute name="producer" type="xs:string"/>
    <xs:attribute name="created" type="xs:dateTime"/>
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <xs:simpleType name="OriginatorId">
    <xs:restriction base="xs:string"><xs:pattern value="[a-z0-9\-]+"/></xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="DesignUid">
    <xs:restriction base="xs:string"><xs:pattern value="[A-Za-z0-9._:\-]{1,64}"/></xs:restriction>
  </xs:simpleType>

  <!-- ====================================================== materials lib -->
  <xs:complexType name="Materials">
    <xs:sequence>
      <xs:element name="Material" type="Material" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <!-- Neutral, resolvable descriptors + the producer's own shorthand token.
       No factory-internal code is authoritative (optional factoryCode hint only). -->
  <xs:complexType name="Material">
    <xs:attribute name="id" type="xs:ID" use="required"/>
    <xs:attribute name="token" type="xs:string"/>          <!-- producer shorthand -->
    <xs:attribute name="manufacturer" type="xs:string"/>
    <xs:attribute name="decor" type="xs:string"/>
    <xs:attribute name="finish" type="xs:string"/>
    <xs:attribute name="type" type="xs:string"/>           <!-- MFC, MDF, ply, … -->
    <xs:attribute name="thickness" type="xs:decimal"/>
    <xs:attribute name="description" type="xs:string"/>
    <xs:attribute name="factoryCode" type="xs:string"/>    <!-- non-authoritative hint -->
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <xs:complexType name="EdgeMaterials">
    <xs:sequence>
      <xs:element name="EdgeMaterial" type="EdgeMaterial" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <xs:complexType name="EdgeMaterial">
    <xs:attribute name="id" type="xs:ID" use="required"/>
    <xs:attribute name="token" type="xs:string"/>
    <xs:attribute name="kind" type="xs:string"/>           <!-- ABS, PVC, veneer, … -->
    <xs:attribute name="thickness" type="xs:decimal"/>
    <xs:attribute name="description" type="xs:string"/>
    <xs:attribute name="factoryCode" type="xs:string"/>
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <!-- ============================================================ hardware -->
  <!-- Optional: the fittings the parts are machined for (hinges, legs, handles,
       dowels, …). An operation names the fitting it is for with hardware="H1";
       the fitting sits where that operation is, so an Item carries no position.
       kind: hinge, leg, handle, dowel, shelf, … (open list; a hinge plate is
       kind hinge, ref hingeplate). ref: the producer's
       own part code (e.g. CabCode "plinthfoot150"). style: for a hinge, how the
       door sits on the carcass (INSET, OVERLAY, HALF_OVERLAY). variant: the
       fitting's own model or fixing (e.g. a hinge's THIN for thin doors).
       quantity: how many the order uses, where known. -->
  <xs:complexType name="Hardware">
    <xs:sequence>
      <xs:element name="Item" type="HardwareItem" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <xs:complexType name="HardwareItem">
    <xs:attribute name="id" type="xs:ID" use="required"/>
    <xs:attribute name="kind" type="xs:string"/>
    <xs:attribute name="ref" type="xs:string"/>
    <xs:attribute name="style" type="xs:string"/>
    <xs:attribute name="variant" type="xs:string"/>
    <xs:attribute name="quantity" type="xs:positiveInteger"/>
    <xs:attribute name="manufacturer" type="xs:string"/>
    <xs:attribute name="description" type="xs:string"/>
    <xs:attribute name="factoryCode" type="xs:string"/>    <!-- non-authoritative hint -->
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <!-- ============================================================= designs -->
  <!-- Optional: whole parametric cabinets as their producing system designed
       them (a template plus sizes, materials and settings), so that system can
       reopen, resize and re-price them. Consumers that do not know the system
       ignore this block and machine the Parts. parts="omitted" means the file
       carries no Parts for that design: only a resolver for its `system`
       (e.g. CabCode) can turn it into parts. -->
  <xs:complexType name="Designs">
    <xs:sequence>
      <xs:element name="Design" type="Design" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <xs:complexType name="Design">
    <xs:sequence>
      <!-- One per copy, in order: where that copy sits. Overrides the Design's own x/y/z/rotation. -->
      <xs:element name="Place" type="DesignPlace" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="Use" type="DesignUse" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="Param" type="DesignParam" minOccurs="0" maxOccurs="unbounded"/>
      <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="id" type="xs:ID" use="required"/>
    <xs:attribute name="system" type="xs:string" use="required"/>   <!-- owner of the template ids, e.g. "cabcode" -->
    <xs:attribute name="originator" type="OriginatorId"/>          <!-- who issued the design -->
    <xs:attribute name="uid" type="DesignUid"/>                    <!-- issued by the originator; (originator, uid) is globally unique -->
    <xs:attribute name="template" type="xs:string" use="required"/> <!-- e.g. "C101" -->
    <xs:attribute name="name" type="xs:string"/>
    <xs:attribute name="quantity" type="xs:positiveInteger" default="1"/>
    <xs:attribute name="height" type="xs:decimal" use="required"/>
    <xs:attribute name="width" type="xs:decimal" use="required"/>
    <xs:attribute name="depth" type="xs:decimal" use="required"/>
    <!-- Where the first copy sits (see DesignPlace). Unplaced copies follow the one before. -->
    <xs:attributeGroup ref="DesignPlacement"/>
    <xs:attribute name="code" type="xs:string"/>        <!-- the system's own saved-design code -->
    <xs:attribute name="catalogue" type="xs:string"/>   <!-- template catalogue version, if known -->
    <xs:attribute name="parts" type="DesignParts" default="included"/>
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <xs:simpleType name="DesignParts">
    <xs:restriction base="xs:string">
      <xs:enumeration value="included"/>
      <xs:enumeration value="omitted"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- Placement in the job, as a CabCode job places its cabinets (mm, degrees):
       x along the wall, y up, z out from the wall; (x, y, z) is the cabinet's
       left, bottom, back corner; rotation turns it about the vertical. A value
       left out carries on from the copy before (x: that copy's x plus its width). -->
  <xs:attributeGroup name="DesignPlacement">
    <xs:attribute name="x" type="xs:decimal"/>
    <xs:attribute name="y" type="xs:decimal"/>
    <xs:attribute name="z" type="xs:decimal"/>
    <xs:attribute name="rotation" type="xs:decimal"/>
  </xs:attributeGroup>

  <xs:complexType name="DesignPlace">
    <xs:attributeGroup ref="DesignPlacement"/>
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <!-- A board or edging the design uses, by role (carcass, front, back, edging, …). -->
  <xs:complexType name="DesignUse">
    <xs:attribute name="role" type="xs:string" use="required"/>
    <xs:attribute name="material" type="xs:IDREF"/>      <!-- -> Material -->
    <xs:attribute name="edgeMaterial" type="xs:IDREF"/>  <!-- -> EdgeMaterial -->
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <!-- One of the system's own design settings, opaque to other consumers. The
       setting is the `value` attribute, or else the element's text: a json
       setting is written as text, so its quotes need no escaping
       (<Param key="sp" type="json">[{"id":"MAIN"}]</Param>). -->
  <xs:complexType name="DesignParam">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="key" type="xs:string" use="required"/>
        <xs:attribute name="value" type="xs:string"/>
        <xs:attribute name="type" type="ParamType" default="string"/>
        <xs:anyAttribute namespace="##other" processContents="lax"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <xs:simpleType name="ParamType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="string"/>
      <xs:enumeration value="number"/>
      <xs:enumeration value="boolean"/>
      <xs:enumeration value="json"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- ================================================================ part -->
  <xs:complexType name="Part">
    <xs:sequence>
      <xs:element name="Edging" type="Edging" minOccurs="0"/>
      <!-- The finished footprint when it is not the full length x width rectangle. -->
      <xs:element name="Outline" type="Outline" minOccurs="0"/>
      <!-- Edges cut at an angle through the thickness. -->
      <xs:element name="Bevel" type="Bevel" minOccurs="0" maxOccurs="unbounded"/>
      <!-- Coats applied after the part is cut, one element per coat, in order. -->
      <xs:element name="Finish" type="Finish" minOccurs="0" maxOccurs="unbounded"/>
      <!-- A door or drawer front that is not a plain slab, and who supplies a bought-in part. -->
      <xs:element name="Front" type="Front" minOccurs="0"/>
      <xs:element name="Supply" type="Supply" minOccurs="0"/>
      <xs:element name="Operations" type="Operations" minOccurs="0"/>
      <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="id" type="xs:ID" use="required"/>
    <xs:attribute name="name" type="xs:string"/>
    <!-- What the part is in the cabinet (optional; for routing, labels, edging rules). -->
    <xs:attribute name="role" type="PartRole"/>
    <xs:attribute name="quantity" type="xs:positiveInteger" default="1"/>
    <xs:attribute name="length" type="xs:decimal" use="required"/>   <!-- X -->
    <xs:attribute name="width" type="xs:decimal" use="required"/>    <!-- Y -->
    <xs:attribute name="thickness" type="xs:decimal" use="required"/><!-- Z -->
    <xs:attribute name="grain" type="GrainDir"/>   <!-- left out: unknown (the factory decides) -->
    <xs:attribute name="material" type="xs:IDREF"/>                  <!-- -> Material -->
    <xs:attribute name="design" type="xs:IDREF"/>                    <!-- -> Design it came from -->
    <xs:attribute name="supply" type="PartSupply" default="made"/>   <!-- bought-in: not cut from board -->
    <xs:attribute name="partOf" type="xs:IDREF"/>                    <!-- -> the front this is a piece of -->
    <xs:attribute name="origin" type="OriginatorId"/>   <!-- who added it; default: inherited -->
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <!-- A door or drawer front that is not a plain slab (see "Fronts" in the spec). -->
  <xs:complexType name="Front">
    <xs:attribute name="style" type="FrontStyle" use="required"/>
    <xs:attribute name="build" type="FrontBuild"/>
    <xs:attribute name="profile" type="FrontProfile" default="square"/>
    <xs:attribute name="radius" type="xs:decimal"/>
    <xs:attribute name="stile" type="xs:decimal"/>
    <xs:attribute name="rail" type="xs:decimal"/>
    <xs:attribute name="midRails" type="DecimalList"/>
    <xs:attribute name="backLip" type="xs:decimal"/>
    <xs:attribute name="groove" type="xs:decimal"/>
    <xs:attribute name="grooveDepth" type="xs:decimal"/>
    <xs:attribute name="panelThickness" type="xs:decimal"/>
    <xs:attribute name="note" type="xs:string"/>
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>
  <xs:simpleType name="FrontStyle"><xs:restriction base="xs:string">
    <xs:enumeration value="slab"/><xs:enumeration value="shaker"/><xs:enumeration value="other"/>
  </xs:restriction></xs:simpleType>
  <xs:simpleType name="FrontBuild"><xs:restriction base="xs:string">
    <xs:enumeration value="routed"/><xs:enumeration value="five-piece"/>
  </xs:restriction></xs:simpleType>
  <xs:simpleType name="FrontProfile"><xs:restriction base="xs:string">
    <xs:enumeration value="square"/><xs:enumeration value="ovolo"/><xs:enumeration value="chamfer"/><xs:enumeration value="other"/>
  </xs:restriction></xs:simpleType>
  <xs:simpleType name="DecimalList"><xs:list itemType="xs:decimal"/></xs:simpleType>
  <xs:simpleType name="PartSupply"><xs:restriction base="xs:string">
    <xs:enumeration value="made"/><xs:enumeration value="bought-in"/>
  </xs:restriction></xs:simpleType>
  <!-- A bought-in part: who supplies it, and who drills it. -->
  <xs:complexType name="Supply">
    <xs:attribute name="supplier" type="xs:string"/>
    <xs:attribute name="ref" type="xs:string"/>
    <xs:attribute name="finish" type="xs:string"/>
    <xs:attribute name="drilled" type="SupplyDrilled" default="factory"/>
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>
  <xs:simpleType name="SupplyDrilled"><xs:restriction base="xs:string">
    <xs:enumeration value="supplier"/><xs:enumeration value="factory"/>
  </xs:restriction></xs:simpleType>

  <xs:simpleType name="PartRole">
    <xs:restriction base="xs:string">
      <xs:enumeration value="side"/>
      <xs:enumeration value="top"/>
      <xs:enumeration value="bottom"/>
      <xs:enumeration value="back"/>
      <xs:enumeration value="shelf"/>
      <xs:enumeration value="divider"/>
      <xs:enumeration value="rail"/>
      <xs:enumeration value="door"/>
      <xs:enumeration value="drawer-face"/>
      <xs:enumeration value="drawer-box-side"/>
      <xs:enumeration value="drawer-box-front"/>
      <xs:enumeration value="drawer-box-back"/>
      <xs:enumeration value="drawer-box-bottom"/>
      <xs:enumeration value="plinth"/>
      <xs:enumeration value="filler"/>
      <xs:enumeration value="end-panel"/>
      <xs:enumeration value="door-stile"/>
      <xs:enumeration value="door-rail"/>
      <xs:enumeration value="door-midrail"/>
      <xs:enumeration value="door-panel"/>
      <xs:enumeration value="other"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="GrainDir">
    <xs:restriction base="xs:string">
      <xs:enumeration value="length"/>
      <xs:enumeration value="width"/>
      <xs:enumeration value="none"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- ============================================================== edging -->
  <xs:complexType name="Edging">
    <xs:sequence>
      <xs:element name="Edge" maxOccurs="4">
        <xs:complexType>
          <xs:attribute name="edge" type="EdgeId" use="required"/>   <!-- geometric -->
          <xs:attribute name="as" type="xs:string"/>                 <!-- L1/L2/W1/W2 -->
          <xs:attribute name="edgeMaterial" type="xs:IDREF" use="required"/>
          <xs:anyAttribute namespace="##other" processContents="lax"/>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <xs:simpleType name="EdgeId">
    <xs:restriction base="xs:string">
      <xs:enumeration value="X0"/><xs:enumeration value="Xmax"/>
      <xs:enumeration value="Y0"/><xs:enumeration value="Ymax"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- ======================================================= angled panels -->
  <!-- Outline: the part's finished footprint as a closed polygon in the part
       frame, wound counter-clockwise in the part's x/y coordinates (positive
       signed area; the spec's "Turning sense"); the inside is the part.
       Each Seg runs from the previous point to its (x, y); the last closes to
       the first. A segment that is not along X or Y is an angle cut. length x
       width stay the polygon's bounding rectangle. as = the edge label the
       segment belongs to (L1/L2/W1/W2; a diagonal names the edge it replaces);
       edgeMaterial overrides that edge's band for this segment. -->
  <xs:complexType name="Outline">
    <xs:sequence>
      <xs:element name="Seg" minOccurs="3" maxOccurs="unbounded">
        <xs:complexType>
          <xs:attribute name="x" type="xs:decimal" use="required"/>
          <xs:attribute name="y" type="xs:decimal" use="required"/>
          <xs:attribute name="as" type="EdgeLabel"/>
          <xs:attribute name="edgeMaterial" type="xs:IDREF"/>
          <xs:anyAttribute namespace="##other" processContents="lax"/>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="closed" type="xs:boolean" default="true"/>
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <!-- Bevel: an edge cut at an angle through the thickness. edge = a rectangle
       edge label, or seg = the 0-based index of an Outline Seg (exactly one).
       angle = degrees from square, more than 0 and less than 90. refFace = the
       face that keeps the full outline size; the other face is undercut. -->
  <xs:complexType name="Bevel">
    <xs:attribute name="edge" type="EdgeLabel"/>
    <xs:attribute name="seg" type="xs:nonNegativeInteger"/>
    <xs:attribute name="angle" type="BevelAngle" use="required"/>
    <xs:attribute name="refFace" type="RefFace" use="required"/>
    <xs:attribute name="origin" type="OriginatorId"/>   <!-- who added it; default: inherited -->
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <!-- Finish: one coat sprayed or rolled on after cutting (not the board's own
       surface, which is its Material). type: primer, lacquer, paint, … (open
       list). faces: A, B or AB (both). edges: "none" (default), "all", or a
       space-separated list of edge labels (e.g. "L1 L2"). sheen: matt, satin,
       gloss, … colour: e.g. a RAL / NCS reference. coats: how many. -->
  <xs:complexType name="Finish">
    <xs:attribute name="type" type="xs:string" use="required"/>
    <xs:attribute name="faces" type="FinishFaces" use="required"/>
    <xs:attribute name="edges" type="xs:string" default="none"/>
    <xs:attribute name="sheen" type="xs:string"/>
    <xs:attribute name="colour" type="xs:string"/>
    <xs:attribute name="coats" type="xs:positiveInteger"/>
    <xs:attribute name="description" type="xs:string"/>
    <xs:attribute name="factoryCode" type="xs:string"/>    <!-- non-authoritative hint -->
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <xs:simpleType name="FinishFaces">
    <xs:restriction base="xs:string">
      <xs:enumeration value="A"/><xs:enumeration value="B"/><xs:enumeration value="AB"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="EdgeLabel">
    <xs:restriction base="xs:string">
      <xs:enumeration value="L1"/><xs:enumeration value="L2"/>
      <xs:enumeration value="W1"/><xs:enumeration value="W2"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="BevelAngle">
    <xs:restriction base="xs:decimal">
      <xs:minExclusive value="0"/><xs:maxExclusive value="90"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="RefFace">
    <xs:restriction base="xs:string">
      <xs:enumeration value="A"/><xs:enumeration value="B"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- ========================================================== operations -->
  <xs:complexType name="Operations">
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element name="Bore" type="Bore"/>
      <xs:element name="Route" type="Route"/>
      <xs:element name="Pocket" type="Pocket"/>
      <xs:any namespace="##other" processContents="lax"/>   <!-- a factory's own operation -->
    </xs:choice>
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <!-- Face id: the two faces (A/B) or an edge (for horizontal/edge boring).
       A = the show face, z = 0, on the bed when machined (rare work: the
       turned-over panel-B.mpr program). B = the back, z = thickness, the face
       usually machined: hinges, shelf holes, connectors (the main panel.mpr). -->
  <xs:simpleType name="FaceId">
    <xs:restriction base="xs:string">
      <xs:enumeration value="A"/><xs:enumeration value="B"/>
      <xs:enumeration value="X0"/><xs:enumeration value="Xmax"/>
      <xs:enumeration value="Y0"/><xs:enumeration value="Ymax"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- OpLabel: optional, on every operation. name = a short label (shown to the
       operator, or used as the machine program's operation name); note = free
       text for the operator. Neither changes what is machined: an importer
       must never read meaning from them. hardware = the Hardware Item this
       operation is machined for (a hinge's cup, a leg's fixing holes); it
       does not change what is machined either. -->
  <xs:attributeGroup name="OpLabel">
    <xs:attribute name="name" type="xs:string"/>
    <xs:attribute name="note" type="xs:string"/>
    <xs:attribute name="hardware" type="xs:IDREF"/>   <!-- -> Hardware Item -->
  </xs:attributeGroup>

  <!-- Bore: one or more holes of the same diameter/depth on one face.
       Face bore (A/B): positions use <At x= y=>. Edge bore: <At u=> + @z. -->
  <xs:complexType name="Bore">
    <xs:sequence>
      <xs:element name="At" type="At" maxOccurs="unbounded"/>
      <xs:element name="Pattern" type="Pattern" minOccurs="0"/>
    </xs:sequence>
    <xs:attribute name="face" type="FaceId" use="required"/>
    <xs:attribute name="diameter" type="xs:decimal" use="required"/>
    <xs:attribute name="depth" type="xs:decimal"/>
    <xs:attribute name="through" type="xs:boolean" default="false"/>
    <xs:attribute name="z" type="xs:decimal"/>   <!-- edge bores: height from face A -->
    <xs:attributeGroup ref="OpLabel"/>
    <xs:attribute name="origin" type="OriginatorId"/>   <!-- who added it; default: inherited -->
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <xs:complexType name="At">
    <xs:attribute name="x" type="xs:decimal"/>   <!-- face bores -->
    <xs:attribute name="y" type="xs:decimal"/>   <!-- face bores -->
    <xs:attribute name="u" type="xs:decimal"/>   <!-- edge bores: along-edge distance -->
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <!-- Pattern: count = holes per At, the At's own included; each dx / dy on from the one before. -->
  <xs:complexType name="Pattern">
    <xs:attribute name="count" type="xs:positiveInteger" use="required"/>
    <xs:attribute name="dx" type="xs:decimal" default="0"/>
    <xs:attribute name="dy" type="xs:decimal" default="0"/>
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <!-- Route: a routed path on a face, as connected Line / Arc segments in the
       part frame (X along length, Y along width; turning sense as the spec's
       "Turning sense").
       toolWidth = cutter diameter. toolSide says where the cutter runs relative
       to the direction of travel: left / right put the path on the finished
       edge (the cutter is offset to that side), centre runs the cutter centre
       on the path (a groove of toolWidth). -->
  <xs:complexType name="Route">
    <xs:sequence>
      <xs:choice maxOccurs="unbounded">
        <xs:element name="Line">
          <xs:complexType>
            <xs:attribute name="x1" type="xs:decimal" use="required"/>
            <xs:attribute name="y1" type="xs:decimal" use="required"/>
            <xs:attribute name="x2" type="xs:decimal" use="required"/>
            <xs:attribute name="y2" type="xs:decimal" use="required"/>
            <xs:anyAttribute namespace="##other" processContents="lax"/>
          </xs:complexType>
        </xs:element>
        <!-- circular arc from (x1,y1) to (x2,y2) about centre (cx,cy); dir is
             clockwise / counter-clockwise in the part's x/y coordinates
             (the spec's "Turning sense") -->
        <xs:element name="Arc">
          <xs:complexType>
            <xs:attribute name="x1" type="xs:decimal" use="required"/>
            <xs:attribute name="y1" type="xs:decimal" use="required"/>
            <xs:attribute name="x2" type="xs:decimal" use="required"/>
            <xs:attribute name="y2" type="xs:decimal" use="required"/>
            <xs:attribute name="cx" type="xs:decimal" use="required"/>
            <xs:attribute name="cy" type="xs:decimal" use="required"/>
            <xs:attribute name="dir" type="ArcDir" use="required"/>
            <xs:anyAttribute namespace="##other" processContents="lax"/>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:sequence>
    <xs:attribute name="face" type="FaceId" use="required"/>
    <xs:attribute name="toolWidth" type="xs:decimal" use="required"/>
    <xs:attribute name="toolSide" type="ToolSide" default="centre"/>
    <xs:attribute name="depth" type="xs:decimal"/>
    <xs:attribute name="through" type="xs:boolean" default="false"/>
    <xs:attribute name="closed" type="xs:boolean" default="false"/>  <!-- path returns to its start -->
    <xs:attributeGroup ref="OpLabel"/>
    <xs:attribute name="origin" type="OriginatorId"/>   <!-- who added it; default: inherited -->
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <!-- Pocket: a rectangular recess cleared to depth (a pocketing cycle, e.g.
       WoodWOP Tasche on a BHX). x,y = its centre in the part frame; sizeX /
       sizeY = its extent along part X / Y before rotation; cornerRadius = the
       radius of its corners (0 = square, a factory may leave a cutter radius);
       angle = rotation about its centre, degrees, counter-clockwise in the
       part's x/y coordinates (the spec's "Turning sense"). A pocket may run past the part's edges (an open-ended groove). -->
  <xs:complexType name="Pocket">
    <xs:attribute name="face" type="FaceId" use="required"/>
    <xs:attribute name="x" type="xs:decimal" use="required"/>
    <xs:attribute name="y" type="xs:decimal" use="required"/>
    <xs:attribute name="sizeX" type="xs:decimal" use="required"/>
    <xs:attribute name="sizeY" type="xs:decimal" use="required"/>
    <xs:attribute name="cornerRadius" type="xs:decimal" default="0"/>
    <xs:attribute name="angle" type="xs:decimal" default="0"/>
    <xs:attribute name="depth" type="xs:decimal"/>
    <xs:attribute name="through" type="xs:boolean" default="false"/>
    <xs:attributeGroup ref="OpLabel"/>
    <xs:attribute name="origin" type="OriginatorId"/>   <!-- who added it; default: inherited -->
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <xs:simpleType name="ArcDir">
    <xs:restriction base="xs:string">
      <xs:enumeration value="cw"/><xs:enumeration value="ccw"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ToolSide">
    <xs:restriction base="xs:string">
      <xs:enumeration value="left"/><xs:enumeration value="right"/><xs:enumeration value="centre"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- ============================================================ assembly -->
  <xs:complexType name="Assembly">
    <xs:sequence>
      <xs:element name="Instance" type="Instance" maxOccurs="unbounded"/>
      <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="id" type="xs:ID" use="required"/>
    <xs:attribute name="name" type="xs:string"/>
    <xs:attribute name="units" type="xs:string" default="mm"/>
    <xs:attribute name="design" type="xs:IDREF"/>   <!-- -> Design it places -->
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <xs:complexType name="Instance">
    <xs:sequence>
      <xs:element name="Position">
        <xs:complexType>
          <xs:attribute name="x" type="xs:decimal" use="required"/>
          <xs:attribute name="y" type="xs:decimal" use="required"/>
          <xs:attribute name="z" type="xs:decimal" use="required"/>
          <xs:anyAttribute namespace="##other" processContents="lax"/>
        </xs:complexType>
      </xs:element>
      <!-- Orientation: matrix (canonical) OR axis-map. matrix: 9 space-separated
           values, a row-major 3x3 local->product rotation (proper: orthonormal,
           det +1); 16 (4x4, no translation) accepted. Axis-map: localX and localY
           (+X, -Z, ...); localZ optional and, when given, localX x localY. -->
      <xs:element name="Orientation">
        <xs:complexType>
          <xs:attribute name="localX" type="AxisMap"/>
          <xs:attribute name="localY" type="AxisMap"/>
          <xs:attribute name="localZ" type="AxisMap"/>
          <xs:attribute name="matrix" type="xs:string"/>   <!-- 9 values, row-major 3x3 rotation -->
          <xs:anyAttribute namespace="##other" processContents="lax"/>
        </xs:complexType>
      </xs:element>
      <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="part" type="xs:IDREF" use="required"/>
    <xs:attribute name="id" type="xs:ID" use="required"/>
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <xs:simpleType name="AxisMap">
    <xs:restriction base="xs:string">
      <xs:pattern value="[+-](X|Y|Z)"/>
    </xs:restriction>
  </xs:simpleType>

</xs:schema>
