# KiBot preflight for setting Text Variables
# https://kibot.readthedocs.io/en/latest/configuration/preflights/set_text_variables.html

kibot:
  version: 1

preflight:
  update_xml: true
  set_text_variables:

    # Git-related information
    - variable: 'REVISION'
      text: '@REVISION@'
    - variable: 'RELEASE_STATE'
      text: '@RELEASE_STATE@'
    - variable: 'RELEASE_DATE'
      command: 'git log -1 --format="%ad" --date=short'
    - variable: 'GIT_HASH_SCH'
      command: 'git log -1 --format="%h" $KIBOT_SCH_NAME'
    - variable: 'GIT_HASH_PCB'
      command: 'git log -1 --format="%h" $KIBOT_PCB_NAME'
    - variable: 'GIT_HASH'
      command: 'git log -1 --format="%h"'
    - variable: 'GIT_URL'
      text: '@GIT_URL@'

    # Metadata
    - variable: 'PROJECT_CODE'
      text: '@PROJECT_CODE@'
    - variable: 'ASSEMBLY_NUMBER'
      text: '@ASSEMBLY_NUMBER@'
    - variable: 'ASSEMBLY_NAME'
      text: '@ASSEMBLY_NAME@'
    - variable: 'ASSEMBLY_SCALE'
      text: '@ASSEMBLY_SCALING@'
    - variable: 'DWG_NUMBER_PCB'
      text: '@DWG_NUMBER_PCB@'
    - variable: 'DWG_NUMBER_SCH'
      text: '@DWG_NUMBER_SCH@'
    - variable: 'DWG_TITLE_PCB'
      text: '@DWG_TITLE_PCB@'
    - variable: 'DWG_TITLE_SCH'
      text: '@DWG_TITLE_SCH@'
    - variable: 'DWG_TITLE_ASSY'
      text: '@DWG_TITLE_ASSY@'
    - variable: 'COMPANY'
      text: '@COMPANY@'
    - variable: 'DESIGNER'
      text: '@DESIGNER@'
    - variable: 'VARIANT'
      text: '%V'

    # Fabrication notes
    - variable: 'FABRICATION_NOTES'
      expand_in_command: true
      command: '[ -f "@FABRICATION_DIR@/%f-fabrication_notes%v.txt" ] && cat "@FABRICATION_DIR@/%f-fabrication_notes%v.txt" || echo ""'

    # Assembly notes
    - variable: 'ASSEMBLY_NOTES'
      expand_in_command: true
      command: '[ -f "@ASSEMBLY_DIR@/%f-assembly_notes%v.txt" ] && cat "@ASSEMBLY_DIR@/%f-assembly_notes%v.txt" || echo ""'

    # Page titles for automatic ToC
    - variable: '@SHEET_NAME_VAR@01'
      text: 'Cover Page'
    - variable: '@SHEET_NAME_VAR@02'
      command: '@GET_SHEET_CMD@ 2'
    - variable: '@SHEET_NAME_VAR@03'
      command: '@GET_SHEET_CMD@ 3'
    - variable: '@SHEET_NAME_VAR@04'
      command: '@GET_SHEET_CMD@ 4'
    - variable: '@SHEET_NAME_VAR@05'
      command: '@GET_SHEET_CMD@ 5'
    - variable: '@SHEET_NAME_VAR@06'
      command: '@GET_SHEET_CMD@ 6'
    - variable: '@SHEET_NAME_VAR@07'
      command: '@GET_SHEET_CMD@ 7'
    - variable: '@SHEET_NAME_VAR@08'
      command: '@GET_SHEET_CMD@ 8'
    - variable: '@SHEET_NAME_VAR@09'
      command: '@GET_SHEET_CMD@ 9'
    - variable: '@SHEET_NAME_VAR@10'
      command: '@GET_SHEET_CMD@ 10'
    - variable: '@SHEET_NAME_VAR@11'
      command: '@GET_SHEET_CMD@ 11'
    - variable: '@SHEET_NAME_VAR@12'
      command: '@GET_SHEET_CMD@ 12'
    - variable: '@SHEET_NAME_VAR@13'
      command: '@GET_SHEET_CMD@ 13'
    - variable: '@SHEET_NAME_VAR@14'
      command: '@GET_SHEET_CMD@ 14'
    - variable: '@SHEET_NAME_VAR@15'
      command: '@GET_SHEET_CMD@ 15'
    - variable: '@SHEET_NAME_VAR@16'
      command: '@GET_SHEET_CMD@ 16'
    - variable: '@SHEET_NAME_VAR@17'
      command: '@GET_SHEET_CMD@ 17'
    - variable: '@SHEET_NAME_VAR@18'
      command: '@GET_SHEET_CMD@ 18'
    - variable: '@SHEET_NAME_VAR@19'
      command: '@GET_SHEET_CMD@ 19'
    - variable: '@SHEET_NAME_VAR@20'
      command: '@GET_SHEET_CMD@ 20'

...
definitions:
  PROJECT_CODE: ''
  ASSEMBLY_NUMBER: ''
  ASSEMBLY_NAME: ''
  ASSEMBLY_SCALING: ''
  DWG_NUMBER_SCH: ''
  DWG_TITLE_SCH: ''
  DWG_NUMBER_PCB: ''
  DWG_TITLE_PCB: ''
  DWG_TITLE_ASSY: ''
  COMPANY: ''
  DESIGNER: ''
  REVISION: ''
  RELEASE_STATE: ''
  RELEASE_DATE: ''
  GIT_URL: ''

  SHEET_NAME_VAR: SHEET_NAME_
  SCRIPTS_DIR: kibot/scripts
  FABRICATION_DIR: mfg/fab
  ASSEMBLY_DIR: mfg/assembly
  GET_SHEET_CMD: python3 @SCRIPTS_DIR@/get_sheet_title.py -f "${KIBOT_SCH_NAME%.kicad_sch}.xml" --dots-number 38 -p
