ShiboSoftwareDev/linux-gameboy-advance

Restores PCB assembly metadata by assigning part numbers and 3D CAD models, removing test-point bodies, and validating top-side SMT solder-paste features without altering copper or pads.

Version
1.0.17
License
unset
Stars
0

routing-boundary.ts

import { applyPartMetadata, applyCadMetadata, applyAssemblyPasteMetadata } from "./assembly-metadata"
/** Native keepouts currently apply to both autorouting and finished copper.
 * This board needs a routing-only reservation around a pre-routed module.
 * Let native routing use the reservation, then remove ONLY the temporary central and east-edge
 * reservations before copper filling and the unmodified full copper/connectivity DRC.
 * No trace, via, clearance error, or connectivity error is suppressed. */
export function routingBoundaryRef(board: any) {
  if (!board?.root) return
  const clear = () => {
    const table=board.root.db.pcb_keepout
    for(const k of table.list()) {
      if(k.shape==='rect' && k.width===25.6 && k.height===25.6 && k.center.x===0 && k.center.y===0)
        table.delete(k.pcb_keepout_id)
    }
  }
  // Refs are attached before some lifecycle methods exist in current core.
  // The root event is stable: remove the reservation only after the carrier
  // (not the nested F1 fanout) has finished using it as a routing obstacle.
  if (!board.__carrierRoutingBoundaryListener) {
    board.__carrierRoutingBoundaryListener = true
    board.root.on("autorouting:end", (event:any) => {
      const isCarrier = event.simpleRouteJson?.obstacles?.some((obstacle:any) =>
        obstacle.type === "rect" && obstacle.width === 25.6 && obstacle.height === 25.6 &&
        obstacle.center?.x === 0 && obstacle.center?.y === 0)
      if (!isCarrier) return
      clear()
      applyPartMetadata(board)
      applyCadMetadata(board)
      applyAssemblyPasteMetadata(board)
    })
  }
  if (typeof board.doInitialPcbImplicitCopperPourRender === "function") {
    const pour=board.doInitialPcbImplicitCopperPourRender.bind(board)
    board.doInitialPcbImplicitCopperPourRender=()=>{ clear(); pour() }
  }
  if (typeof board.doInitialPcbDesignRuleChecks === "function") {
    const check=board.doInitialPcbDesignRuleChecks.bind(board)
    board.doInitialPcbDesignRuleChecks=()=>{ clear(); applyPartMetadata(board); check() }
  }
  if (typeof board.doInitialPartsEngineRender === "function") {
    const parts=board.doInitialPartsEngineRender.bind(board)
    board.doInitialPartsEngineRender=()=>{ applyCadMetadata(board); applyAssemblyPasteMetadata(board); return parts() }
  }
}