@tscircuit/core 0.0.101 → 0.0.103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +14 -0
- package/dist/index.js +124 -123
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2762,6 +2762,20 @@ declare class TraceHint extends PrimitiveComponent<typeof traceHintProps> {
|
|
|
2762
2762
|
doInitialPcbTraceHintRender(): void;
|
|
2763
2763
|
}
|
|
2764
2764
|
|
|
2765
|
+
/**
|
|
2766
|
+
* Get the dimensions of a schematic box based on the provided parameters.
|
|
2767
|
+
*
|
|
2768
|
+
* A schematic box is a rectangular box with a set of pins on the sides.
|
|
2769
|
+
*
|
|
2770
|
+
* The user can customize the position of the pins and the spacing between them,
|
|
2771
|
+
* this makes computing the box fairly complicated.
|
|
2772
|
+
*
|
|
2773
|
+
* A note on the internals:
|
|
2774
|
+
* * A "true port" refers to a pin/port before it's remapped by the user to a
|
|
2775
|
+
* different position. True Pin 1 is guaranteed to be in the top-left corner
|
|
2776
|
+
* * We basically iterate over each side and compute how far we are from the
|
|
2777
|
+
* edge for that side by adding margins together
|
|
2778
|
+
*/
|
|
2765
2779
|
interface SchematicBoxDimensions {
|
|
2766
2780
|
pinCount: number;
|
|
2767
2781
|
getPortPositionByPinNumber(pinNumber: number): {
|
package/dist/index.js
CHANGED
|
@@ -1070,6 +1070,11 @@ var SmtPad = class extends PrimitiveComponent {
|
|
|
1070
1070
|
x: newCenter.x,
|
|
1071
1071
|
y: newCenter.y
|
|
1072
1072
|
});
|
|
1073
|
+
const solderPaste = db.pcb_solder_paste.list().find((elm) => elm.pcb_smtpad_id === this.pcb_smtpad_id);
|
|
1074
|
+
db.pcb_solder_paste.update(solderPaste?.pcb_solder_paste_id, {
|
|
1075
|
+
x: newCenter.x,
|
|
1076
|
+
y: newCenter.y
|
|
1077
|
+
});
|
|
1073
1078
|
this.matchedPort?._setPositionFromLayout(newCenter);
|
|
1074
1079
|
}
|
|
1075
1080
|
};
|
|
@@ -3226,7 +3231,7 @@ function isExplicitPinMappingArrangement(arrangement) {
|
|
|
3226
3231
|
return arrangement.leftSide !== void 0;
|
|
3227
3232
|
}
|
|
3228
3233
|
var getAllDimensionsForSchematicBox = (params) => {
|
|
3229
|
-
const
|
|
3234
|
+
const componentMargin = params.schPinSpacing;
|
|
3230
3235
|
let sidePinCounts = params.schPortArrangement ? getSizeOfSidesFromPortArrangement(params.schPortArrangement) : null;
|
|
3231
3236
|
const sideLengths = {
|
|
3232
3237
|
left: 0,
|
|
@@ -3237,7 +3242,7 @@ var getAllDimensionsForSchematicBox = (params) => {
|
|
|
3237
3242
|
let pinCount = params.pinCount ?? null;
|
|
3238
3243
|
if (pinCount === null) {
|
|
3239
3244
|
if (sidePinCounts) {
|
|
3240
|
-
pinCount = sidePinCounts.leftSize + sidePinCounts.rightSize + sidePinCounts.topSize;
|
|
3245
|
+
pinCount = sidePinCounts.leftSize + sidePinCounts.rightSize + sidePinCounts.topSize + sidePinCounts.bottomSize;
|
|
3241
3246
|
} else {
|
|
3242
3247
|
throw new Error("Could not determine pin count for the schematic box");
|
|
3243
3248
|
}
|
|
@@ -3259,139 +3264,135 @@ var getAllDimensionsForSchematicBox = (params) => {
|
|
|
3259
3264
|
bottomSize: 0
|
|
3260
3265
|
};
|
|
3261
3266
|
}
|
|
3267
|
+
const schWidth = params.schWidth ?? Math.max(sidePinCounts.topSize, sidePinCounts.bottomSize) * params.schPinSpacing + 2 * componentMargin;
|
|
3268
|
+
const schHeight = params.schHeight ?? Math.max(sidePinCounts.leftSize, sidePinCounts.rightSize) * params.schPinSpacing + 2 * componentMargin;
|
|
3269
|
+
const distributePorts = (sideSize, sideLength, totalMargin) => {
|
|
3270
|
+
if (sideSize <= 1) return 0;
|
|
3271
|
+
return (sideLength - totalMargin) / (sideSize - 1);
|
|
3272
|
+
};
|
|
3262
3273
|
const orderedTruePorts = [];
|
|
3263
|
-
let currentDistanceFromEdge = 0;
|
|
3264
3274
|
let truePinIndex = 0;
|
|
3265
|
-
|
|
3266
|
-
const
|
|
3267
|
-
const
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
currentDistanceFromEdge += pinStyle.bottomMargin;
|
|
3275
|
+
const processSide = (side, pins, direction) => {
|
|
3276
|
+
const isVertical = side === "left" || side === "right";
|
|
3277
|
+
const sideLength = isVertical ? schHeight : schWidth;
|
|
3278
|
+
let totalMargin = 0;
|
|
3279
|
+
for (const pin of pins) {
|
|
3280
|
+
const pinStyle = params.schPinStyle?.[`pin${pin}`] ?? params.schPinStyle?.[pin];
|
|
3281
|
+
if (pinStyle) {
|
|
3282
|
+
if (isVertical) {
|
|
3283
|
+
totalMargin += (pinStyle.topMargin ?? 0) + (pinStyle.bottomMargin ?? 0);
|
|
3284
|
+
} else {
|
|
3285
|
+
totalMargin += (pinStyle.leftMargin ?? 0) + (pinStyle.rightMargin ?? 0);
|
|
3286
|
+
}
|
|
3287
|
+
}
|
|
3279
3288
|
}
|
|
3280
|
-
const
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3289
|
+
const spacing = distributePorts(
|
|
3290
|
+
pins.length,
|
|
3291
|
+
sideLength - 2 * componentMargin,
|
|
3292
|
+
totalMargin
|
|
3293
|
+
);
|
|
3294
|
+
let currentDistanceFromEdge = componentMargin;
|
|
3295
|
+
pins.forEach((pinNumber, index) => {
|
|
3296
|
+
const pinStyle = params.schPinStyle?.[`pin${pinNumber}`] ?? params.schPinStyle?.[pinNumber];
|
|
3297
|
+
if (pinStyle) {
|
|
3298
|
+
if (isVertical) {
|
|
3299
|
+
if (side === "left") {
|
|
3300
|
+
currentDistanceFromEdge += direction === "top-to-bottom" ? pinStyle.topMargin ?? 0 : pinStyle.bottomMargin ?? 0;
|
|
3301
|
+
} else {
|
|
3302
|
+
currentDistanceFromEdge += direction === "top-to-bottom" ? pinStyle.bottomMargin ?? 0 : pinStyle.topMargin ?? 0;
|
|
3303
|
+
}
|
|
3304
|
+
} else {
|
|
3305
|
+
if (side === "top") {
|
|
3306
|
+
currentDistanceFromEdge += direction === "left-to-right" ? pinStyle.leftMargin ?? 0 : pinStyle.rightMargin ?? 0;
|
|
3307
|
+
} else {
|
|
3308
|
+
currentDistanceFromEdge += direction === "left-to-right" ? pinStyle.rightMargin ?? 0 : pinStyle.leftMargin ?? 0;
|
|
3309
|
+
}
|
|
3310
|
+
}
|
|
3311
|
+
}
|
|
3312
|
+
orderedTruePorts.push({
|
|
3313
|
+
trueIndex: truePinIndex,
|
|
3314
|
+
pinNumber,
|
|
3315
|
+
side,
|
|
3316
|
+
distanceFromEdge: currentDistanceFromEdge
|
|
3317
|
+
});
|
|
3318
|
+
if (pinStyle) {
|
|
3319
|
+
if (isVertical) {
|
|
3320
|
+
if (side === "left") {
|
|
3321
|
+
currentDistanceFromEdge += direction === "top-to-bottom" ? pinStyle.bottomMargin ?? 0 : pinStyle.topMargin ?? 0;
|
|
3322
|
+
} else {
|
|
3323
|
+
currentDistanceFromEdge += direction === "top-to-bottom" ? pinStyle.topMargin ?? 0 : pinStyle.bottomMargin ?? 0;
|
|
3324
|
+
}
|
|
3325
|
+
} else {
|
|
3326
|
+
if (side === "top") {
|
|
3327
|
+
currentDistanceFromEdge += direction === "left-to-right" ? pinStyle.rightMargin ?? 0 : pinStyle.leftMargin ?? 0;
|
|
3328
|
+
} else {
|
|
3329
|
+
currentDistanceFromEdge += direction === "left-to-right" ? pinStyle.leftMargin ?? 0 : pinStyle.rightMargin ?? 0;
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
}
|
|
3333
|
+
currentDistanceFromEdge += spacing;
|
|
3334
|
+
truePinIndex++;
|
|
3300
3335
|
});
|
|
3301
|
-
|
|
3302
|
-
|
|
3336
|
+
sideLengths[side] = sideLength;
|
|
3337
|
+
};
|
|
3338
|
+
if (params.schPortArrangement && isExplicitPinMappingArrangement(params.schPortArrangement)) {
|
|
3339
|
+
if (params.schPortArrangement.leftSide) {
|
|
3340
|
+
processSide(
|
|
3341
|
+
"left",
|
|
3342
|
+
params.schPortArrangement.leftSide.pins,
|
|
3343
|
+
params.schPortArrangement.leftSide.direction ?? "top-to-bottom"
|
|
3344
|
+
);
|
|
3303
3345
|
}
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
truePinIndex++;
|
|
3311
|
-
}
|
|
3312
|
-
currentDistanceFromEdge = 0;
|
|
3313
|
-
for (let sideIndex = 0; sideIndex < sidePinCounts.rightSize; sideIndex++) {
|
|
3314
|
-
const pinNumber = params.schPortArrangement && isExplicitPinMappingArrangement(params.schPortArrangement) ? params.schPortArrangement.rightSide?.pins[sideIndex] : truePinIndex + 1;
|
|
3315
|
-
const pinStyle = params.schPinStyle?.[`pin${pinNumber}`] ?? params.schPinStyle?.[pinNumber];
|
|
3316
|
-
if (pinStyle?.bottomMargin) {
|
|
3317
|
-
currentDistanceFromEdge += pinStyle.bottomMargin;
|
|
3318
|
-
}
|
|
3319
|
-
orderedTruePorts.push({
|
|
3320
|
-
trueIndex: truePinIndex,
|
|
3321
|
-
pinNumber,
|
|
3322
|
-
side: "right",
|
|
3323
|
-
distanceFromEdge: currentDistanceFromEdge
|
|
3324
|
-
});
|
|
3325
|
-
if (pinStyle?.topMargin) {
|
|
3326
|
-
currentDistanceFromEdge += pinStyle.topMargin;
|
|
3346
|
+
if (params.schPortArrangement.rightSide) {
|
|
3347
|
+
processSide(
|
|
3348
|
+
"right",
|
|
3349
|
+
params.schPortArrangement.rightSide.pins,
|
|
3350
|
+
params.schPortArrangement.rightSide.direction ?? "bottom-to-top"
|
|
3351
|
+
);
|
|
3327
3352
|
}
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
truePinIndex++;
|
|
3335
|
-
}
|
|
3336
|
-
currentDistanceFromEdge = 0;
|
|
3337
|
-
for (let sideIndex = 0; sideIndex < sidePinCounts.topSize; sideIndex++) {
|
|
3338
|
-
const pinNumber = params.schPortArrangement && isExplicitPinMappingArrangement(params.schPortArrangement) ? params.schPortArrangement.topSide?.pins[sideIndex] : truePinIndex + 1;
|
|
3339
|
-
const pinStyle = params.schPinStyle?.[`pin${pinNumber}`] ?? params.schPinStyle?.[pinNumber];
|
|
3340
|
-
if (pinStyle?.rightMargin) {
|
|
3341
|
-
currentDistanceFromEdge += pinStyle.rightMargin;
|
|
3342
|
-
}
|
|
3343
|
-
orderedTruePorts.push({
|
|
3344
|
-
trueIndex: truePinIndex,
|
|
3345
|
-
pinNumber,
|
|
3346
|
-
side: "top",
|
|
3347
|
-
distanceFromEdge: currentDistanceFromEdge
|
|
3348
|
-
});
|
|
3349
|
-
if (pinStyle?.leftMargin) {
|
|
3350
|
-
currentDistanceFromEdge += pinStyle.leftMargin;
|
|
3353
|
+
if (params.schPortArrangement.topSide) {
|
|
3354
|
+
processSide(
|
|
3355
|
+
"top",
|
|
3356
|
+
params.schPortArrangement.topSide.pins,
|
|
3357
|
+
params.schPortArrangement.topSide.direction ?? "left-to-right"
|
|
3358
|
+
);
|
|
3351
3359
|
}
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3360
|
+
if (params.schPortArrangement.bottomSide) {
|
|
3361
|
+
processSide(
|
|
3362
|
+
"bottom",
|
|
3363
|
+
params.schPortArrangement.bottomSide.pins,
|
|
3364
|
+
params.schPortArrangement.bottomSide.direction ?? "left-to-right"
|
|
3365
|
+
);
|
|
3357
3366
|
}
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
schWidth = Math.max(
|
|
3363
|
-
sideLengths.top + params.schPinSpacing * 2,
|
|
3364
|
-
sideLengths.bottom + params.schPinSpacing * 2
|
|
3367
|
+
} else {
|
|
3368
|
+
const leftSide = Array.from(
|
|
3369
|
+
{ length: sidePinCounts.leftSize },
|
|
3370
|
+
(_, i) => i + 1
|
|
3365
3371
|
);
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
+
const rightSide = Array.from(
|
|
3373
|
+
{ length: sidePinCounts.rightSize },
|
|
3374
|
+
(_, i) => i + sidePinCounts.leftSize + 1
|
|
3375
|
+
);
|
|
3376
|
+
const topSide = Array.from(
|
|
3377
|
+
{ length: sidePinCounts.topSize },
|
|
3378
|
+
(_, i) => i + sidePinCounts.leftSize + sidePinCounts.rightSize + 1
|
|
3379
|
+
);
|
|
3380
|
+
const bottomSide = Array.from(
|
|
3381
|
+
{
|
|
3382
|
+
length: pinCount - sidePinCounts.leftSize - sidePinCounts.rightSize - sidePinCounts.topSize
|
|
3383
|
+
},
|
|
3384
|
+
(_, i) => i + sidePinCounts.leftSize + sidePinCounts.rightSize + sidePinCounts.topSize + 1
|
|
3372
3385
|
);
|
|
3386
|
+
processSide("left", leftSide, "top-to-bottom");
|
|
3387
|
+
processSide("right", rightSide, "top-to-bottom");
|
|
3388
|
+
processSide("top", topSide, "left-to-right");
|
|
3389
|
+
processSide("bottom", bottomSide, "left-to-right");
|
|
3373
3390
|
}
|
|
3374
3391
|
const trueEdgePositions = {
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
},
|
|
3380
|
-
// bottom left corner
|
|
3381
|
-
bottom: {
|
|
3382
|
-
x: -sideLengths.bottom / 2,
|
|
3383
|
-
y: -schHeight / 2 - portDistanceFromEdge
|
|
3384
|
-
},
|
|
3385
|
-
// bottom right corner
|
|
3386
|
-
right: {
|
|
3387
|
-
x: schWidth / 2 + portDistanceFromEdge,
|
|
3388
|
-
y: -sideLengths.right / 2
|
|
3389
|
-
},
|
|
3390
|
-
// top right corner
|
|
3391
|
-
top: {
|
|
3392
|
-
x: sideLengths.top / 2,
|
|
3393
|
-
y: schHeight / 2 + portDistanceFromEdge
|
|
3394
|
-
}
|
|
3392
|
+
left: { x: -schWidth / 2, y: schHeight / 2 },
|
|
3393
|
+
bottom: { x: -schWidth / 2, y: schHeight / 2 },
|
|
3394
|
+
right: { x: schWidth / 2, y: -schHeight / 2 },
|
|
3395
|
+
top: { x: schWidth / 2, y: -schHeight / 2 }
|
|
3395
3396
|
};
|
|
3396
3397
|
const trueEdgeTraversalDirections = {
|
|
3397
3398
|
left: { x: 0, y: -1 },
|