kibot:
  version: 1
# Look into pcb_replace, looks sick! Also sch_replace

preflight:
  run_erc: true
  update_xml: true
  run_drc: false
  check_zone_fills: false
  ignore_unconnected: false

  # Replace variables
  set_text_variables:
    - name: "REVISION"
      command: "git rev-parse --short HEAD"
    - name: "FULL_REVISION"
      command: "git describe --always --tags"
    - name: "ISSUE"
      command: "date '+%Y-%m-%d'"
    # - name: "KENWOODFOX_3DMODELS" # My custom libs!
    #   command: "echo 'Hardware/InstrumentVisor/Libraries/kenwoodfox-kicad-libraries/3d'"

filters:
  - name: only_jlc_parts
    comment: "Only parts with JLC code"
    type: generic
    include_only:
      - column: "LCSC#"
        regex: '^C\d+'

variants:
  - name: rotated
    comment: "Just a place holder for the rotation filter"
    type: kibom
    variant: rotated
    pre_transform: _rot_footprint

outputs:
  - name: "Images"
    comment: "Schematics and media for use in docs"
    type: svg_sch_print

  - name: "3D Models"
    comment: "3D Models"
    type: step

  - name: "3D Renders"
    comment: "3D Renders for docs!"
    type: render_3d
    options:
      ray_tracing: true
      rotate_x: -1
      rotate_y: 2
      zoom: 3
      wait_render: 20
      width: 800

  # ======
  # PCBWay
  # ======

  - name: PCBWay_gerbers
    comment: Gerbers compatible with PCBWay
    type: gerber
    dir: PCBWay
    options:
      exclude_edge_layer: true
      exclude_pads_from_silkscreen: true
      plot_sheet_reference: false
      plot_footprint_refs: true
      plot_footprint_values: true
      force_plot_invisible_refs_vals: false
      tent_vias: true
      use_protel_extensions: true
      create_gerber_job_file: false
      output: "%f.%x"
      gerber_precision: 4.6
      use_gerber_x2_attributes: false
      use_gerber_net_attributes: false
      disable_aperture_macros: true
      line_width: 0.1
      subtract_mask_from_silk: false
      inner_extension_pattern: ".gl%N"
    layers:
      - copper
      - F.SilkS
      - B.SilkS
      - F.Mask
      - B.Mask
      - F.Paste
      - B.Paste
      - Edge.Cuts

  - name: PCBWay_drill
    comment: Drill files compatible with PCBWay
    type: excellon
    dir: PCBWay
    options:
      metric_units: false
      minimal_header: true
      zeros_format: SUPPRESS_LEADING
      # left_digits: 3
      # right_digits: 3
      # See https://github.com/INTI-CMNB/kicad-ci-test-spora/issues/1
      # and https://docs.oshpark.com/design-tools/gerbv/fix-drill-format/
      left_digits: 2
      right_digits: 4
      pth_and_npth_single_file: false
      pth_id: ""
      npth_id: "-NPTH"
      output: "%f%i.drl"

  - name: PCBWay
    comment: ZIP file for PCBWay
    type: compress
    dir: PCBWay
    options:
      format: ZIP
      files:
        - from_output: PCBWay_gerbers
          dest: /
        - from_output: PCBWay_drill
          dest: /

  # ======
  # JLCPCB
  # ======

  - name: JLCPCB_gerbers
    comment: Gerbers compatible with JLCPCB
    type: gerber
    dir: JLCPCB
    options:
      exclude_edge_layer: true
      exclude_pads_from_silkscreen: true
      plot_sheet_reference: false
      plot_footprint_refs: true
      plot_footprint_values: true
      force_plot_invisible_refs_vals: false
      tent_vias: true
      use_protel_extensions: true
      create_gerber_job_file: false
      disable_aperture_macros: true
      gerber_precision: 4.6
      use_gerber_x2_attributes: false
      use_gerber_net_attributes: false
      line_width: 0.1
      subtract_mask_from_silk: true
      inner_extension_pattern: ".gp%n"
    layers:
      - copper
      - F.SilkS
      - B.SilkS
      - F.Mask
      - B.Mask
      - F.Paste
      - B.Paste
      - Edge.Cuts

  - name: JLCPCB_drill
    comment: Drill files compatible with JLCPCB
    type: excellon
    dir: JLCPCB
    options:
      pth_and_npth_single_file: false
      pth_id: "-PTH"
      npth_id: "-NPTH"
      metric_units: true
      map: gerber
      route_mode_for_oval_holes: false
      output: "%f%i.%x"

  - name: "JLCPCB_position"
    comment: "Pick and place file, JLCPCB style"
    type: position
    options:
      variant: rotated
      output: "%f_cpl_jlc.%x"
      format: CSV
      units: millimeters
      separate_files_for_front_and_back: false
      only_smd: true
      columns:
        - id: Ref
          name: Designator
        - Val
        - Package
        - id: PosX
          name: "Mid X"
        - id: PosY
          name: "Mid Y"
        - id: Rot
          name: Rotation
        - id: Side
          name: Layer

  - name: "JLCPCB_bom"
    comment: "BoM for JLCPCB"
    type: bom
    options:
      output: "%f_%i_jlc.%x"
      exclude_filter: "only_jlc_parts"
      ref_separator: ","
      columns:
        - field: Value
          name: Comment
        - field: References
          name: Designator
        - Footprint
        - field: "LCSC#"
          name: "LCSC Part #"
      csv:
        hide_pcb_info: true
        hide_stats_info: true
        quote_all: true

  - name: JLCPCB
    comment: ZIP file for JLCPCB
    type: compress
    dir: JLCPCB
    options:
      files:
        - from_output: JLCPCB_gerbers
          dest: /
        - from_output: JLCPCB_drill
          dest: /
        - from_output: JLCPCB_position
          dest: /
        - from_output: JLCPCB_bom
          dest: /
