Skip to content

Commit

Permalink
Merge pull request #85 from tscircuit/fix-string-pin-numbers
Browse files Browse the repository at this point in the history
String pin numbers should be converted to type number when converting to tsx
  • Loading branch information
seveibar authored Oct 25, 2024
2 parents d464d30 + e8fa269 commit 4a15044
Showing 1 changed file with 37 additions and 14 deletions.
51 changes: 37 additions & 14 deletions lib/convert-to-typescript-component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,56 @@ export const convertBetterEasyToTsx = async ({
const pn = normalizeManufacturerPartNumber(rawPn)
const [cad_component] = su(circuitJson).cad_component.list()

// Derive pinLabels from easyeda json
const pinLabels: Record<string, string> = {}
for (const shape of betterEasy.dataStr.shape) {
if (shape.type === "PIN") {
const isPinLabelNumeric = /^\d+$/.test(shape.label)
const label = isPinLabelNumeric ? `pin${shape.label}` : shape.label
// Derive schPinArrangement from easyeda json
const pins = betterEasy.dataStr.shape.filter((shape) => shape.type === "PIN")

pinLabels[shape.pinNumber.toString()] = label
}
const hasStringPinNumbers = pins.some(
(pin) => typeof pin.pinNumber === "string",
)
let modifiedPins = pins
if (hasStringPinNumbers) {
modifiedPins = pins.map((pin, idx) => {
const originalPinNumber = pin.pinNumber.toString()

const newPinNumber = idx + 1

// If label is different from original pin number, create array with both pin number and label
// const newLabel =
// originalPinNumber === pin.label
// ? [pin.label]
// : [originalPinNumber, pin.label]

return {
...pin,
pinNumber: newPinNumber,
label: pin.label,
}
})
}

// Derive schPinArrangement from easyeda json
const pins = betterEasy.dataStr.shape.filter((shape) => shape.type === "PIN")
const leftPins = pins.filter((pin) => pin.rotation === 180)
const rightPins = pins.filter((pin) => pin.rotation === 0)
const leftPins = modifiedPins.filter((pin) => pin.rotation === 180)
const rightPins = modifiedPins.filter((pin) => pin.rotation === 0)

const schPinArrangement = {
leftSide: {
direction: "top-to-bottom" as const,
pins: leftPins.map((pin) => pin.pinNumber) as number[],
pins: leftPins.map((pin) => Number(pin.pinNumber)),
},
rightSide: {
direction: "bottom-to-top" as const,
pins: rightPins.map((pin) => pin.pinNumber).reverse() as number[],
pins: rightPins.map((pin) => Number(pin.pinNumber)).reverse(),
},
}

// Derive pinLabels from easyeda json
const pinLabels: Record<string, string> = {}
for (const pin of modifiedPins) {
const isPinLabelNumeric = /^\d+$/.test(pin.label)
const label = isPinLabelNumeric ? `pin${pin.label}` : pin.label

pinLabels[pin.pinNumber] = label
}

let modelObjUrl: string | undefined
if (cad_component.model_obj_url) {
const isValidUrl = await checkModelObjUrlValidity(
Expand Down

0 comments on commit 4a15044

Please sign in to comment.