imrishabh18/nema-23-stepper-controller

A four-layer NEMA23 stepper motor controller PCB featuring an RP2040 MCU, DRV8452 dual-phase driver, USB‑C PD power input/protection, current and temperature sensing, status LED/buzzer, and optional magnetic encoder.

Version
1.3.2
License
unset
Stars
1

symbol-text-compat.ts

import { SchematicText, Port } from "tscircuit"

// core 0.0.2050 attaches custom-symbol text to schematic_symbol_id but omits
// schematic_component_id. Native autolayout and SVG bounds use the latter.
// Associate the text with its owner before layout; all positions still come
// from the imported local artwork and tscircuit's layout engine.
const prototype = SchematicText.prototype as any
const marker = Symbol.for("nema23.symbol-text-owner")
if (!prototype[marker]) {
  const render = prototype.doInitialSchematicPrimitiveRender
  prototype.doInitialSchematicPrimitiveRender = function () {
    render.call(this)
    const owner = this.getParentNormalComponent()
    if (this.schematic_text_id && owner?.schematic_component_id) {
      const text = this.root.db.schematic_text.get(this.schematic_text_id)
      if (text && !text.schematic_component_id) {
        this.root.db.schematic_text.update(this.schematic_text_id, {
          schematic_component_id: owner.schematic_component_id,
        })
      }
    }
  }
  prototype[marker] = true
}

// A custom two-pin resistor drawing is already self-identifying. Core normally
// suppresses primitive resistor pin names, but its JSON symbol path prints the
// inherited "anode/cathode" aliases over this small supplier symbol.
const portPrototype = Port.prototype as any
if (!portPrototype[marker]) {
  const label = portPrototype._getBestDisplayPinLabel
  portPrototype._getBestDisplayPinLabel = function () {
    const owner = this.getParentNormalComponent()
    if (owner?.componentName === "Resistor" && owner.props.symbol) return undefined
    return label.call(this)
  }
  portPrototype[marker] = true
}