@tscircuit/core 0.0.40 → 0.0.41
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 +25 -7
- package/dist/index.js +27 -11
- package/lib/components/base-components/PrimitiveComponent.ts +4 -4
- package/lib/components/primitive-components/Footprint.ts +1 -1
- package/lib/components/primitive-components/Hole.ts +1 -1
- package/lib/components/primitive-components/PlatedHole.ts +1 -1
- package/lib/components/primitive-components/Port.ts +20 -2
- package/lib/components/primitive-components/SmtPad.ts +1 -1
- package/lib/components/primitive-components/Trace.ts +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -141,10 +141,10 @@ declare abstract class PrimitiveComponent<ZodProps extends ZodType = any> extend
|
|
|
141
141
|
_computePcbGlobalTransformBeforeLayout(): Matrix;
|
|
142
142
|
getPrimitiveContainer(): PrimitiveComponent | null;
|
|
143
143
|
/**
|
|
144
|
-
* Compute the bounds of this component the circuit json elements
|
|
145
|
-
* with it.
|
|
144
|
+
* Compute the PCB bounds of this component the circuit json elements
|
|
145
|
+
* associated with it.
|
|
146
146
|
*/
|
|
147
|
-
|
|
147
|
+
_getPcbCircuitJsonBounds(): {
|
|
148
148
|
center: {
|
|
149
149
|
x: number;
|
|
150
150
|
y: number;
|
|
@@ -161,7 +161,7 @@ declare abstract class PrimitiveComponent<ZodProps extends ZodType = any> extend
|
|
|
161
161
|
/**
|
|
162
162
|
* Set the position of this component from the layout solver. This method
|
|
163
163
|
* should operate using CircuitJson associated with this component, like
|
|
164
|
-
*
|
|
164
|
+
* _getPcbCircuitJsonBounds it can be called multiple times as different
|
|
165
165
|
* parents apply layout to their children.
|
|
166
166
|
*/
|
|
167
167
|
_setPositionFromLayout(newCenter: {
|
|
@@ -512,6 +512,24 @@ declare class Port extends PrimitiveComponent<typeof portProps> {
|
|
|
512
512
|
x: number;
|
|
513
513
|
y: number;
|
|
514
514
|
};
|
|
515
|
+
_getPcbCircuitJsonBounds(): {
|
|
516
|
+
center: {
|
|
517
|
+
x: number;
|
|
518
|
+
y: number;
|
|
519
|
+
};
|
|
520
|
+
bounds: {
|
|
521
|
+
left: number;
|
|
522
|
+
top: number;
|
|
523
|
+
right: number;
|
|
524
|
+
bottom: number;
|
|
525
|
+
};
|
|
526
|
+
width: number;
|
|
527
|
+
height: number;
|
|
528
|
+
};
|
|
529
|
+
_getGlobalPcbPositionAfterLayout(): {
|
|
530
|
+
x: number;
|
|
531
|
+
y: number;
|
|
532
|
+
};
|
|
515
533
|
_getGlobalSchematicPositionBeforeLayout(): {
|
|
516
534
|
x: number;
|
|
517
535
|
y: number;
|
|
@@ -770,7 +788,7 @@ declare class SmtPad extends PrimitiveComponent<typeof smtPadProps> {
|
|
|
770
788
|
};
|
|
771
789
|
doInitialPortMatching(): void;
|
|
772
790
|
doInitialPcbPrimitiveRender(): void;
|
|
773
|
-
|
|
791
|
+
_getPcbCircuitJsonBounds(): {
|
|
774
792
|
center: {
|
|
775
793
|
x: number;
|
|
776
794
|
y: number;
|
|
@@ -3819,7 +3837,7 @@ declare class PlatedHole extends PrimitiveComponent<typeof platedHoleProps> {
|
|
|
3819
3837
|
width: number;
|
|
3820
3838
|
height: number;
|
|
3821
3839
|
};
|
|
3822
|
-
|
|
3840
|
+
_getPcbCircuitJsonBounds(): {
|
|
3823
3841
|
center: {
|
|
3824
3842
|
x: number;
|
|
3825
3843
|
y: number;
|
|
@@ -3985,7 +4003,7 @@ declare class Hole extends PrimitiveComponent<typeof holeProps> {
|
|
|
3985
4003
|
height: number;
|
|
3986
4004
|
};
|
|
3987
4005
|
doInitialPcbPrimitiveRender(): void;
|
|
3988
|
-
|
|
4006
|
+
_getPcbCircuitJsonBounds(): {
|
|
3989
4007
|
center: {
|
|
3990
4008
|
x: number;
|
|
3991
4009
|
y: number;
|
package/dist/index.js
CHANGED
|
@@ -274,10 +274,10 @@ var PrimitiveComponent = class extends Renderable {
|
|
|
274
274
|
return this.parent?.getPrimitiveContainer?.() ?? null;
|
|
275
275
|
}
|
|
276
276
|
/**
|
|
277
|
-
* Compute the bounds of this component the circuit json elements
|
|
278
|
-
* with it.
|
|
277
|
+
* Compute the PCB bounds of this component the circuit json elements
|
|
278
|
+
* associated with it.
|
|
279
279
|
*/
|
|
280
|
-
|
|
280
|
+
_getPcbCircuitJsonBounds() {
|
|
281
281
|
return {
|
|
282
282
|
center: { x: 0, y: 0 },
|
|
283
283
|
bounds: { left: 0, top: 0, right: 0, bottom: 0 },
|
|
@@ -288,7 +288,7 @@ var PrimitiveComponent = class extends Renderable {
|
|
|
288
288
|
/**
|
|
289
289
|
* Set the position of this component from the layout solver. This method
|
|
290
290
|
* should operate using CircuitJson associated with this component, like
|
|
291
|
-
*
|
|
291
|
+
* _getPcbCircuitJsonBounds it can be called multiple times as different
|
|
292
292
|
* parents apply layout to their children.
|
|
293
293
|
*/
|
|
294
294
|
_setPositionFromLayout(newCenter) {
|
|
@@ -529,7 +529,7 @@ var Footprint = class extends PrimitiveComponent {
|
|
|
529
529
|
selector,
|
|
530
530
|
componentSelector,
|
|
531
531
|
edge,
|
|
532
|
-
bounds: component.
|
|
532
|
+
bounds: component._getPcbCircuitJsonBounds()
|
|
533
533
|
}));
|
|
534
534
|
if (involvedComponents.some((c) => c.edge)) {
|
|
535
535
|
throw new Error(
|
|
@@ -745,6 +745,22 @@ var Port = class extends PrimitiveComponent {
|
|
|
745
745
|
}
|
|
746
746
|
return matchedPcbElm?._getGlobalPcbPositionBeforeLayout() ?? { x: 0, y: 0 };
|
|
747
747
|
}
|
|
748
|
+
_getPcbCircuitJsonBounds() {
|
|
749
|
+
if (!this.pcb_port_id) {
|
|
750
|
+
return super._getPcbCircuitJsonBounds();
|
|
751
|
+
}
|
|
752
|
+
const { db } = this.root;
|
|
753
|
+
const pcb_port = db.pcb_port.get(this.pcb_port_id);
|
|
754
|
+
return {
|
|
755
|
+
center: { x: pcb_port.x, y: pcb_port.y },
|
|
756
|
+
bounds: { left: 0, top: 0, right: 0, bottom: 0 },
|
|
757
|
+
width: 0,
|
|
758
|
+
height: 0
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
_getGlobalPcbPositionAfterLayout() {
|
|
762
|
+
return this._getPcbCircuitJsonBounds().center;
|
|
763
|
+
}
|
|
748
764
|
_getGlobalSchematicPositionBeforeLayout() {
|
|
749
765
|
if (!this.schematicSymbolPortDef) {
|
|
750
766
|
return applyToPoint2(this.parent.computeSchematicGlobalTransform(), {
|
|
@@ -845,11 +861,11 @@ var Port = class extends PrimitiveComponent {
|
|
|
845
861
|
);
|
|
846
862
|
}
|
|
847
863
|
const pcbMatch = pcbMatches[0];
|
|
848
|
-
if ("
|
|
864
|
+
if ("_getPcbCircuitJsonBounds" in pcbMatch) {
|
|
849
865
|
const pcb_port = db.pcb_port.insert({
|
|
850
866
|
pcb_component_id: this.parent?.pcb_component_id,
|
|
851
867
|
layers: ["top"],
|
|
852
|
-
...pcbMatch.
|
|
868
|
+
...pcbMatch._getPcbCircuitJsonBounds().center,
|
|
853
869
|
source_port_id: this.source_port_id
|
|
854
870
|
});
|
|
855
871
|
this.pcb_port_id = pcb_port.pcb_port_id;
|
|
@@ -1136,7 +1152,7 @@ var SmtPad = class extends PrimitiveComponent {
|
|
|
1136
1152
|
this.pcb_smtpad_id = pcb_smtpad.pcb_smtpad_id;
|
|
1137
1153
|
}
|
|
1138
1154
|
}
|
|
1139
|
-
|
|
1155
|
+
_getPcbCircuitJsonBounds() {
|
|
1140
1156
|
const { db } = this.root;
|
|
1141
1157
|
const smtpad = db.pcb_smtpad.get(this.pcb_smtpad_id);
|
|
1142
1158
|
if (smtpad.shape === "rect") {
|
|
@@ -1242,7 +1258,7 @@ var PlatedHole = class extends PrimitiveComponent {
|
|
|
1242
1258
|
`getPcbSize for shape "${props.shape}" not implemented for ${this.componentName}`
|
|
1243
1259
|
);
|
|
1244
1260
|
}
|
|
1245
|
-
|
|
1261
|
+
_getPcbCircuitJsonBounds() {
|
|
1246
1262
|
const { db } = this.root;
|
|
1247
1263
|
const platedHole = db.pcb_plated_hole.get(this.pcb_plated_hole_id);
|
|
1248
1264
|
const size = this.getPcbSize();
|
|
@@ -2039,7 +2055,7 @@ function getClosest(point, candidates) {
|
|
|
2039
2055
|
// lib/components/primitive-components/Trace.ts
|
|
2040
2056
|
import "zod";
|
|
2041
2057
|
var portToObjective = (port) => {
|
|
2042
|
-
const portPosition = port.
|
|
2058
|
+
const portPosition = port._getGlobalPcbPositionAfterLayout();
|
|
2043
2059
|
return {
|
|
2044
2060
|
...portPosition,
|
|
2045
2061
|
layers: port.getAvailablePcbLayers()
|
|
@@ -3094,7 +3110,7 @@ var Hole = class extends PrimitiveComponent {
|
|
|
3094
3110
|
});
|
|
3095
3111
|
this.pcb_hole_id = inserted_hole.pcb_hole_id;
|
|
3096
3112
|
}
|
|
3097
|
-
|
|
3113
|
+
_getPcbCircuitJsonBounds() {
|
|
3098
3114
|
const { db } = this.root;
|
|
3099
3115
|
const hole = db.pcb_hole.get(this.pcb_hole_id);
|
|
3100
3116
|
const size = this.getPcbSize();
|
|
@@ -166,10 +166,10 @@ export abstract class PrimitiveComponent<
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
/**
|
|
169
|
-
* Compute the bounds of this component the circuit json elements
|
|
170
|
-
* with it.
|
|
169
|
+
* Compute the PCB bounds of this component the circuit json elements
|
|
170
|
+
* associated with it.
|
|
171
171
|
*/
|
|
172
|
-
|
|
172
|
+
_getPcbCircuitJsonBounds(): {
|
|
173
173
|
center: { x: number; y: number }
|
|
174
174
|
bounds: { left: number; top: number; right: number; bottom: number }
|
|
175
175
|
width: number
|
|
@@ -186,7 +186,7 @@ export abstract class PrimitiveComponent<
|
|
|
186
186
|
/**
|
|
187
187
|
* Set the position of this component from the layout solver. This method
|
|
188
188
|
* should operate using CircuitJson associated with this component, like
|
|
189
|
-
*
|
|
189
|
+
* _getPcbCircuitJsonBounds it can be called multiple times as different
|
|
190
190
|
* parents apply layout to their children.
|
|
191
191
|
*/
|
|
192
192
|
_setPositionFromLayout(newCenter: { x: number; y: number }) {
|
|
@@ -28,7 +28,7 @@ export class Footprint extends PrimitiveComponent<typeof footprintProps> {
|
|
|
28
28
|
selector,
|
|
29
29
|
componentSelector,
|
|
30
30
|
edge,
|
|
31
|
-
bounds: component.
|
|
31
|
+
bounds: component._getPcbCircuitJsonBounds(),
|
|
32
32
|
}))
|
|
33
33
|
|
|
34
34
|
if (involvedComponents.some((c) => c.edge)) {
|
|
@@ -32,7 +32,7 @@ export class Hole extends PrimitiveComponent<typeof holeProps> {
|
|
|
32
32
|
this.pcb_hole_id = inserted_hole.pcb_hole_id!
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
_getPcbCircuitJsonBounds(): {
|
|
36
36
|
center: { x: number; y: number }
|
|
37
37
|
bounds: { left: number; top: number; right: number; bottom: number }
|
|
38
38
|
width: number
|
|
@@ -27,7 +27,7 @@ export class PlatedHole extends PrimitiveComponent<typeof platedHoleProps> {
|
|
|
27
27
|
)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
_getPcbCircuitJsonBounds(): {
|
|
31
31
|
center: { x: number; y: number }
|
|
32
32
|
bounds: { left: number; top: number; right: number; bottom: number }
|
|
33
33
|
width: number
|
|
@@ -44,6 +44,24 @@ export class Port extends PrimitiveComponent<typeof portProps> {
|
|
|
44
44
|
return matchedPcbElm?._getGlobalPcbPositionBeforeLayout() ?? { x: 0, y: 0 }
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
_getPcbCircuitJsonBounds() {
|
|
48
|
+
if (!this.pcb_port_id) {
|
|
49
|
+
return super._getPcbCircuitJsonBounds()
|
|
50
|
+
}
|
|
51
|
+
const { db } = this.root!
|
|
52
|
+
const pcb_port = db.pcb_port.get(this.pcb_port_id)!
|
|
53
|
+
return {
|
|
54
|
+
center: { x: pcb_port.x, y: pcb_port.y },
|
|
55
|
+
bounds: { left: 0, top: 0, right: 0, bottom: 0 },
|
|
56
|
+
width: 0,
|
|
57
|
+
height: 0,
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
_getGlobalPcbPositionAfterLayout(): { x: number; y: number } {
|
|
62
|
+
return this._getPcbCircuitJsonBounds().center
|
|
63
|
+
}
|
|
64
|
+
|
|
47
65
|
_getGlobalSchematicPositionBeforeLayout(): { x: number; y: number } {
|
|
48
66
|
if (!this.schematicSymbolPortDef) {
|
|
49
67
|
return applyToPoint(this.parent!.computeSchematicGlobalTransform(), {
|
|
@@ -168,12 +186,12 @@ export class Port extends PrimitiveComponent<typeof portProps> {
|
|
|
168
186
|
|
|
169
187
|
const pcbMatch: any = pcbMatches[0]
|
|
170
188
|
|
|
171
|
-
if ("
|
|
189
|
+
if ("_getPcbCircuitJsonBounds" in pcbMatch) {
|
|
172
190
|
const pcb_port = db.pcb_port.insert({
|
|
173
191
|
pcb_component_id: this.parent?.pcb_component_id!,
|
|
174
192
|
layers: ["top"],
|
|
175
193
|
|
|
176
|
-
...pcbMatch.
|
|
194
|
+
...pcbMatch._getPcbCircuitJsonBounds().center,
|
|
177
195
|
|
|
178
196
|
source_port_id: this.source_port_id!,
|
|
179
197
|
})
|
|
@@ -97,7 +97,7 @@ export class SmtPad extends PrimitiveComponent<typeof smtPadProps> {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
_getPcbCircuitJsonBounds(): {
|
|
101
101
|
center: { x: number; y: number }
|
|
102
102
|
bounds: { left: number; top: number; right: number; bottom: number }
|
|
103
103
|
width: number
|
|
@@ -38,7 +38,7 @@ type PcbRouteObjective =
|
|
|
38
38
|
| { layers: string[]; x: number; y: number; via?: boolean }
|
|
39
39
|
|
|
40
40
|
const portToObjective = (port: Port): PcbRouteObjective => {
|
|
41
|
-
const portPosition = port.
|
|
41
|
+
const portPosition = port._getGlobalPcbPositionAfterLayout()
|
|
42
42
|
return {
|
|
43
43
|
...portPosition,
|
|
44
44
|
layers: port.getAvailablePcbLayers(),
|