Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String pin numbers should be converted to type number when converting to tsx #85

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}
Copy link
Contributor Author

@andrii-balitskyi andrii-balitskyi Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently it looks like this, is it correct?

Or should it look like this?

Copy link
Contributor Author

@andrii-balitskyi andrii-balitskyi Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also a duplicate SH label. Should we check for duplicate labels and add some unique characters?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope duplicates are ok!!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seveibar my bad, should've marked the PR draft. There's some ghost code as I wanted to confirm the structure.
So, the first screenshot looks right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should look like the second! Sorry for the delay

})
}

// 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
Loading