@tscircuit/core 0.0.66 → 0.0.68
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.js +44 -21
- package/lib/Project.ts +1 -0
- package/lib/components/base-components/NormalComponent.ts +4 -20
- package/lib/components/primitive-components/PlatedHole.ts +4 -1
- package/lib/components/primitive-components/SmtPad.ts +5 -2
- package/lib/utils/get-bounds-of-pcb-components.ts +41 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1142,9 +1142,10 @@ var SmtPad = class extends PrimitiveComponent {
|
|
|
1142
1142
|
);
|
|
1143
1143
|
const isRotated90 = Math.abs(decomposedMat.rotation.angle * (180 / Math.PI) - 90) < 0.01;
|
|
1144
1144
|
let pcb_smtpad = null;
|
|
1145
|
+
const pcb_component_id = this.parent?.pcb_component_id ?? this.getPrimitiveContainer()?.pcb_component_id;
|
|
1145
1146
|
if (props.shape === "circle") {
|
|
1146
1147
|
pcb_smtpad = db.pcb_smtpad.insert({
|
|
1147
|
-
pcb_component_id
|
|
1148
|
+
pcb_component_id,
|
|
1148
1149
|
pcb_port_id: this.matchedPort?.pcb_port_id,
|
|
1149
1150
|
// port likely isn't matched
|
|
1150
1151
|
layer: props.layer ?? "top",
|
|
@@ -1157,7 +1158,7 @@ var SmtPad = class extends PrimitiveComponent {
|
|
|
1157
1158
|
});
|
|
1158
1159
|
} else if (props.shape === "rect") {
|
|
1159
1160
|
pcb_smtpad = db.pcb_smtpad.insert({
|
|
1160
|
-
pcb_component_id
|
|
1161
|
+
pcb_component_id,
|
|
1161
1162
|
pcb_port_id: this.matchedPort?.pcb_port_id,
|
|
1162
1163
|
// port likely isn't matched
|
|
1163
1164
|
layer: props.layer ?? "top",
|
|
@@ -1330,9 +1331,10 @@ var PlatedHole = class extends PrimitiveComponent {
|
|
|
1330
1331
|
const { db } = this.root;
|
|
1331
1332
|
const { _parsedProps: props } = this;
|
|
1332
1333
|
const position = this._getGlobalPcbPositionBeforeLayout();
|
|
1334
|
+
const pcb_component_id = this.parent?.pcb_component_id ?? this.getPrimitiveContainer()?.pcb_component_id;
|
|
1333
1335
|
if (props.shape === "circle") {
|
|
1334
1336
|
const pcb_plated_hole = db.pcb_plated_hole.insert({
|
|
1335
|
-
pcb_component_id
|
|
1337
|
+
pcb_component_id,
|
|
1336
1338
|
pcb_port_id: this.matchedPort?.pcb_port_id,
|
|
1337
1339
|
// @ts-ignore - some issue with @tscircuit/soup union type
|
|
1338
1340
|
outer_diameter: props.outerDiameter,
|
|
@@ -1629,6 +1631,42 @@ var createNetsFromProps = (component, props) => {
|
|
|
1629
1631
|
}
|
|
1630
1632
|
};
|
|
1631
1633
|
|
|
1634
|
+
// lib/utils/get-bounds-of-pcb-components.ts
|
|
1635
|
+
function getBoundsOfPcbComponents(components) {
|
|
1636
|
+
let minX = Infinity;
|
|
1637
|
+
let minY = Infinity;
|
|
1638
|
+
let maxX = -Infinity;
|
|
1639
|
+
let maxY = -Infinity;
|
|
1640
|
+
for (const child of components) {
|
|
1641
|
+
if (child.isPcbPrimitive) {
|
|
1642
|
+
const { x, y } = child._getGlobalPcbPositionBeforeLayout();
|
|
1643
|
+
const { width: width2, height: height2 } = child.getPcbSize();
|
|
1644
|
+
minX = Math.min(minX, x - width2 / 2);
|
|
1645
|
+
minY = Math.min(minY, y - height2 / 2);
|
|
1646
|
+
maxX = Math.max(maxX, x + width2 / 2);
|
|
1647
|
+
maxY = Math.max(maxY, y + height2 / 2);
|
|
1648
|
+
} else if (child.componentName === "Footprint") {
|
|
1649
|
+
const childBounds = getBoundsOfPcbComponents(child.children);
|
|
1650
|
+
minX = Math.min(minX, childBounds.minX);
|
|
1651
|
+
minY = Math.min(minY, childBounds.minY);
|
|
1652
|
+
maxX = Math.max(maxX, childBounds.maxX);
|
|
1653
|
+
maxY = Math.max(maxY, childBounds.maxY);
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
let width = maxX - minX;
|
|
1657
|
+
let height = maxY - minY;
|
|
1658
|
+
if (width < 0) width = 0;
|
|
1659
|
+
if (height < 0) height = 0;
|
|
1660
|
+
return {
|
|
1661
|
+
minX,
|
|
1662
|
+
minY,
|
|
1663
|
+
maxX,
|
|
1664
|
+
maxY,
|
|
1665
|
+
width,
|
|
1666
|
+
height
|
|
1667
|
+
};
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1632
1670
|
// lib/components/base-components/NormalComponent.ts
|
|
1633
1671
|
var NormalComponent = class extends PrimitiveComponent {
|
|
1634
1672
|
reactSubtrees = [];
|
|
@@ -1788,25 +1826,10 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
1788
1826
|
if (!this.pcb_component_id) return;
|
|
1789
1827
|
const { db } = this.root;
|
|
1790
1828
|
const { _parsedProps: props } = this;
|
|
1791
|
-
|
|
1792
|
-
let minY = Infinity;
|
|
1793
|
-
let maxX = -Infinity;
|
|
1794
|
-
let maxY = -Infinity;
|
|
1795
|
-
for (const child of this.children) {
|
|
1796
|
-
if (child.isPcbPrimitive) {
|
|
1797
|
-
const { x, y } = child._getGlobalPcbPositionBeforeLayout();
|
|
1798
|
-
const { width: width2, height: height2 } = child.getPcbSize();
|
|
1799
|
-
minX = Math.min(minX, x - width2 / 2);
|
|
1800
|
-
minY = Math.min(minY, y - height2 / 2);
|
|
1801
|
-
maxX = Math.max(maxX, x + width2 / 2);
|
|
1802
|
-
maxY = Math.max(maxY, y + height2 / 2);
|
|
1803
|
-
}
|
|
1804
|
-
}
|
|
1805
|
-
const width = maxX - minX;
|
|
1806
|
-
const height = maxY - minY;
|
|
1829
|
+
const bounds = getBoundsOfPcbComponents(this.children);
|
|
1807
1830
|
db.pcb_component.update(this.pcb_component_id, {
|
|
1808
|
-
width,
|
|
1809
|
-
height
|
|
1831
|
+
width: bounds.width,
|
|
1832
|
+
height: bounds.height
|
|
1810
1833
|
});
|
|
1811
1834
|
}
|
|
1812
1835
|
_renderReactSubtree(element) {
|
package/lib/Project.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { getPortFromHints } from "lib/utils/getPortFromHints"
|
|
|
18
18
|
import { createComponentsFromSoup } from "lib/utils/createComponentsFromSoup"
|
|
19
19
|
import { Net } from "../primitive-components/Net"
|
|
20
20
|
import { createNetsFromProps } from "lib/utils/components/createNetsFromProps"
|
|
21
|
+
import { getBoundsOfPcbComponents } from "lib/utils/get-bounds-of-pcb-components"
|
|
21
22
|
|
|
22
23
|
export type PortMap<T extends string> = {
|
|
23
24
|
[K in T]: Port
|
|
@@ -229,28 +230,11 @@ export class NormalComponent<
|
|
|
229
230
|
const { db } = this.root!
|
|
230
231
|
const { _parsedProps: props } = this
|
|
231
232
|
|
|
232
|
-
|
|
233
|
-
let minY = Infinity
|
|
234
|
-
let maxX = -Infinity
|
|
235
|
-
let maxY = -Infinity
|
|
236
|
-
|
|
237
|
-
for (const child of this.children) {
|
|
238
|
-
if (child.isPcbPrimitive) {
|
|
239
|
-
const { x, y } = child._getGlobalPcbPositionBeforeLayout()
|
|
240
|
-
const { width, height } = child.getPcbSize()
|
|
241
|
-
minX = Math.min(minX, x - width / 2)
|
|
242
|
-
minY = Math.min(minY, y - height / 2)
|
|
243
|
-
maxX = Math.max(maxX, x + width / 2)
|
|
244
|
-
maxY = Math.max(maxY, y + height / 2)
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const width = maxX - minX
|
|
249
|
-
const height = maxY - minY
|
|
233
|
+
const bounds = getBoundsOfPcbComponents(this.children)
|
|
250
234
|
|
|
251
235
|
db.pcb_component.update(this.pcb_component_id!, {
|
|
252
|
-
width,
|
|
253
|
-
height,
|
|
236
|
+
width: bounds.width,
|
|
237
|
+
height: bounds.height,
|
|
254
238
|
})
|
|
255
239
|
}
|
|
256
240
|
|
|
@@ -86,9 +86,12 @@ export class PlatedHole extends PrimitiveComponent<typeof platedHoleProps> {
|
|
|
86
86
|
const { db } = this.root!
|
|
87
87
|
const { _parsedProps: props } = this
|
|
88
88
|
const position = this._getGlobalPcbPositionBeforeLayout()
|
|
89
|
+
const pcb_component_id =
|
|
90
|
+
this.parent?.pcb_component_id ??
|
|
91
|
+
this.getPrimitiveContainer()?.pcb_component_id!
|
|
89
92
|
if (props.shape === "circle") {
|
|
90
93
|
const pcb_plated_hole = db.pcb_plated_hole.insert({
|
|
91
|
-
pcb_component_id
|
|
94
|
+
pcb_component_id,
|
|
92
95
|
pcb_port_id: this.matchedPort?.pcb_port_id!,
|
|
93
96
|
// @ts-ignore - some issue with @tscircuit/soup union type
|
|
94
97
|
outer_diameter: props.outerDiameter,
|
|
@@ -64,9 +64,12 @@ export class SmtPad extends PrimitiveComponent<typeof smtPadProps> {
|
|
|
64
64
|
const isRotated90 =
|
|
65
65
|
Math.abs(decomposedMat.rotation.angle * (180 / Math.PI) - 90) < 0.01
|
|
66
66
|
let pcb_smtpad: PCBSMTPad | null = null
|
|
67
|
+
const pcb_component_id =
|
|
68
|
+
this.parent?.pcb_component_id ??
|
|
69
|
+
this.getPrimitiveContainer()?.pcb_component_id!
|
|
67
70
|
if (props.shape === "circle") {
|
|
68
71
|
pcb_smtpad = db.pcb_smtpad.insert({
|
|
69
|
-
pcb_component_id
|
|
72
|
+
pcb_component_id,
|
|
70
73
|
pcb_port_id: this.matchedPort?.pcb_port_id!, // port likely isn't matched
|
|
71
74
|
layer: props.layer ?? "top",
|
|
72
75
|
shape: "circle",
|
|
@@ -81,7 +84,7 @@ export class SmtPad extends PrimitiveComponent<typeof smtPadProps> {
|
|
|
81
84
|
})
|
|
82
85
|
} else if (props.shape === "rect") {
|
|
83
86
|
pcb_smtpad = db.pcb_smtpad.insert({
|
|
84
|
-
pcb_component_id
|
|
87
|
+
pcb_component_id,
|
|
85
88
|
pcb_port_id: this.matchedPort?.pcb_port_id!, // port likely isn't matched
|
|
86
89
|
layer: props.layer ?? "top",
|
|
87
90
|
shape: "rect",
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { PrimitiveComponent } from "lib/components/base-components/PrimitiveComponent"
|
|
2
|
+
|
|
3
|
+
export function getBoundsOfPcbComponents(components: PrimitiveComponent[]) {
|
|
4
|
+
let minX = Infinity
|
|
5
|
+
let minY = Infinity
|
|
6
|
+
let maxX = -Infinity
|
|
7
|
+
let maxY = -Infinity
|
|
8
|
+
|
|
9
|
+
for (const child of components) {
|
|
10
|
+
if (child.isPcbPrimitive) {
|
|
11
|
+
const { x, y } = child._getGlobalPcbPositionBeforeLayout()
|
|
12
|
+
const { width, height } = child.getPcbSize()
|
|
13
|
+
minX = Math.min(minX, x - width / 2)
|
|
14
|
+
minY = Math.min(minY, y - height / 2)
|
|
15
|
+
maxX = Math.max(maxX, x + width / 2)
|
|
16
|
+
maxY = Math.max(maxY, y + height / 2)
|
|
17
|
+
} else if (child.componentName === "Footprint") {
|
|
18
|
+
const childBounds = getBoundsOfPcbComponents(child.children)
|
|
19
|
+
|
|
20
|
+
minX = Math.min(minX, childBounds.minX)
|
|
21
|
+
minY = Math.min(minY, childBounds.minY)
|
|
22
|
+
maxX = Math.max(maxX, childBounds.maxX)
|
|
23
|
+
maxY = Math.max(maxY, childBounds.maxY)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let width = maxX - minX
|
|
28
|
+
let height = maxY - minY
|
|
29
|
+
|
|
30
|
+
if (width < 0) width = 0
|
|
31
|
+
if (height < 0) height = 0
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
minX,
|
|
35
|
+
minY,
|
|
36
|
+
maxX,
|
|
37
|
+
maxY,
|
|
38
|
+
width,
|
|
39
|
+
height,
|
|
40
|
+
}
|
|
41
|
+
}
|