@tscircuit/core 0.0.960 → 0.0.962
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 +193 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -14002,6 +14002,26 @@ function computeCenterFromAnchorPosition(anchorPosition, ctx) {
|
|
|
14002
14002
|
}
|
|
14003
14003
|
|
|
14004
14004
|
// lib/components/primitive-components/Group/insert-autoplaced-jumpers.ts
|
|
14005
|
+
function groupPadsByInternalConnection(pads, orientation) {
|
|
14006
|
+
const tolerance = 0.01;
|
|
14007
|
+
const groups = [];
|
|
14008
|
+
for (const pad of pads) {
|
|
14009
|
+
const key = orientation === "vertical" ? pad.center.y : pad.center.x;
|
|
14010
|
+
let foundGroup = false;
|
|
14011
|
+
for (const group of groups) {
|
|
14012
|
+
const groupKey = orientation === "vertical" ? group[0].center.y : group[0].center.x;
|
|
14013
|
+
if (Math.abs(key - groupKey) < tolerance) {
|
|
14014
|
+
group.push(pad);
|
|
14015
|
+
foundGroup = true;
|
|
14016
|
+
break;
|
|
14017
|
+
}
|
|
14018
|
+
}
|
|
14019
|
+
if (!foundGroup) {
|
|
14020
|
+
groups.push([pad]);
|
|
14021
|
+
}
|
|
14022
|
+
}
|
|
14023
|
+
return groups.filter((g) => g.length >= 2);
|
|
14024
|
+
}
|
|
14005
14025
|
function insertAutoplacedJumpers(params) {
|
|
14006
14026
|
const { db, output_jumpers, subcircuit_id } = params;
|
|
14007
14027
|
for (let jumperIndex = 0; jumperIndex < output_jumpers.length; jumperIndex++) {
|
|
@@ -14023,10 +14043,26 @@ function insertAutoplacedJumpers(params) {
|
|
|
14023
14043
|
height: jumper.height || 0,
|
|
14024
14044
|
obstructs_within_bounds: false
|
|
14025
14045
|
});
|
|
14026
|
-
|
|
14046
|
+
const padData = [];
|
|
14047
|
+
for (let padIndex = 0; padIndex < jumper.pads.length; padIndex++) {
|
|
14048
|
+
const pad = jumper.pads[padIndex];
|
|
14049
|
+
const pinNumber = padIndex + 1;
|
|
14050
|
+
const sourcePort = db.source_port.insert({
|
|
14051
|
+
source_component_id: sourceComponent.source_component_id,
|
|
14052
|
+
name: `pin${pinNumber}`,
|
|
14053
|
+
pin_number: pinNumber
|
|
14054
|
+
});
|
|
14027
14055
|
const padLayer = pad.layer || pad.layers?.[0] || "top";
|
|
14028
|
-
db.
|
|
14056
|
+
const pcbPort = db.pcb_port.insert({
|
|
14029
14057
|
pcb_component_id: pcbComponent.pcb_component_id,
|
|
14058
|
+
source_port_id: sourcePort.source_port_id,
|
|
14059
|
+
x: pad.center.x,
|
|
14060
|
+
y: pad.center.y,
|
|
14061
|
+
layers: [padLayer]
|
|
14062
|
+
});
|
|
14063
|
+
const pcbSmtpad = db.pcb_smtpad.insert({
|
|
14064
|
+
pcb_component_id: pcbComponent.pcb_component_id,
|
|
14065
|
+
pcb_port_id: pcbPort.pcb_port_id,
|
|
14030
14066
|
shape: "rect",
|
|
14031
14067
|
x: pad.center.x,
|
|
14032
14068
|
y: pad.center.y,
|
|
@@ -14034,6 +14070,33 @@ function insertAutoplacedJumpers(params) {
|
|
|
14034
14070
|
height: pad.height,
|
|
14035
14071
|
layer: padLayer
|
|
14036
14072
|
});
|
|
14073
|
+
padData.push({
|
|
14074
|
+
pad,
|
|
14075
|
+
sourcePortId: sourcePort.source_port_id,
|
|
14076
|
+
pcbSmtpadId: pcbSmtpad.pcb_smtpad_id
|
|
14077
|
+
});
|
|
14078
|
+
}
|
|
14079
|
+
const internalGroups = groupPadsByInternalConnection(
|
|
14080
|
+
jumper.pads,
|
|
14081
|
+
jumper.orientation
|
|
14082
|
+
);
|
|
14083
|
+
for (const group of internalGroups) {
|
|
14084
|
+
const sourcePortIds = [];
|
|
14085
|
+
for (const groupPad of group) {
|
|
14086
|
+
const padInfo = padData.find(
|
|
14087
|
+
(p) => Math.abs(p.pad.center.x - groupPad.center.x) < 0.01 && Math.abs(p.pad.center.y - groupPad.center.y) < 0.01
|
|
14088
|
+
);
|
|
14089
|
+
if (padInfo) {
|
|
14090
|
+
sourcePortIds.push(padInfo.sourcePortId);
|
|
14091
|
+
}
|
|
14092
|
+
}
|
|
14093
|
+
if (sourcePortIds.length >= 2) {
|
|
14094
|
+
db.source_component_internal_connection.insert({
|
|
14095
|
+
source_component_id: sourceComponent.source_component_id,
|
|
14096
|
+
subcircuit_id: subcircuit_id ?? void 0,
|
|
14097
|
+
source_port_ids: sourcePortIds
|
|
14098
|
+
});
|
|
14099
|
+
}
|
|
14037
14100
|
}
|
|
14038
14101
|
}
|
|
14039
14102
|
}
|
|
@@ -14092,6 +14155,129 @@ function splitPcbTracesOnJumperSegments(route) {
|
|
|
14092
14155
|
return segments;
|
|
14093
14156
|
}
|
|
14094
14157
|
|
|
14158
|
+
// lib/components/primitive-components/Group/add-port-ids-to-traces-at-jumper-pads.ts
|
|
14159
|
+
function getJumperPadInfos(db) {
|
|
14160
|
+
const padInfos = [];
|
|
14161
|
+
const pcbSmtpads = db.pcb_smtpad.list();
|
|
14162
|
+
const jumperSmtpads = pcbSmtpads.filter((pad) => {
|
|
14163
|
+
const component = db.pcb_component.get(pad.pcb_component_id);
|
|
14164
|
+
if (!component) return false;
|
|
14165
|
+
const sourceComponent = db.source_component.get(
|
|
14166
|
+
component.source_component_id
|
|
14167
|
+
);
|
|
14168
|
+
return sourceComponent?.name?.startsWith("__autoplaced_jumper");
|
|
14169
|
+
});
|
|
14170
|
+
for (const smtpad of jumperSmtpads) {
|
|
14171
|
+
if (smtpad.shape === "polygon") continue;
|
|
14172
|
+
if (!smtpad.pcb_port_id) continue;
|
|
14173
|
+
if (smtpad.shape === "rect" || smtpad.shape === "rotated_rect") {
|
|
14174
|
+
const halfWidth = smtpad.width / 2;
|
|
14175
|
+
const halfHeight = smtpad.height / 2;
|
|
14176
|
+
padInfos.push({
|
|
14177
|
+
pcb_port_id: smtpad.pcb_port_id,
|
|
14178
|
+
x: smtpad.x,
|
|
14179
|
+
y: smtpad.y,
|
|
14180
|
+
minX: smtpad.x - halfWidth,
|
|
14181
|
+
maxX: smtpad.x + halfWidth,
|
|
14182
|
+
minY: smtpad.y - halfHeight,
|
|
14183
|
+
maxY: smtpad.y + halfHeight
|
|
14184
|
+
});
|
|
14185
|
+
} else if (smtpad.shape === "circle") {
|
|
14186
|
+
const radius = smtpad.radius;
|
|
14187
|
+
padInfos.push({
|
|
14188
|
+
pcb_port_id: smtpad.pcb_port_id,
|
|
14189
|
+
x: smtpad.x,
|
|
14190
|
+
y: smtpad.y,
|
|
14191
|
+
minX: smtpad.x - radius,
|
|
14192
|
+
maxX: smtpad.x + radius,
|
|
14193
|
+
minY: smtpad.y - radius,
|
|
14194
|
+
maxY: smtpad.y + radius
|
|
14195
|
+
});
|
|
14196
|
+
}
|
|
14197
|
+
}
|
|
14198
|
+
return padInfos;
|
|
14199
|
+
}
|
|
14200
|
+
function findJumperPortAtPosition(padInfos, x, y, tolerance = 0.01) {
|
|
14201
|
+
for (const pad of padInfos) {
|
|
14202
|
+
if (Math.abs(pad.x - x) < tolerance && Math.abs(pad.y - y) < tolerance) {
|
|
14203
|
+
return pad.pcb_port_id;
|
|
14204
|
+
}
|
|
14205
|
+
}
|
|
14206
|
+
return void 0;
|
|
14207
|
+
}
|
|
14208
|
+
function findJumperPortContainingPoint(padInfos, x, y) {
|
|
14209
|
+
for (const pad of padInfos) {
|
|
14210
|
+
if (x >= pad.minX && x <= pad.maxX && y >= pad.minY && y <= pad.maxY) {
|
|
14211
|
+
return pad;
|
|
14212
|
+
}
|
|
14213
|
+
}
|
|
14214
|
+
return void 0;
|
|
14215
|
+
}
|
|
14216
|
+
function splitRouteAtJumperPads(route, padInfos) {
|
|
14217
|
+
if (route.length === 0 || padInfos.length === 0) return [route];
|
|
14218
|
+
const segments = [];
|
|
14219
|
+
let currentSegment = [];
|
|
14220
|
+
for (let i = 0; i < route.length; i++) {
|
|
14221
|
+
const point2 = route[i];
|
|
14222
|
+
currentSegment.push(point2);
|
|
14223
|
+
if (point2.route_type === "wire" && i > 0 && i < route.length - 1) {
|
|
14224
|
+
const padInfo = findJumperPortContainingPoint(padInfos, point2.x, point2.y);
|
|
14225
|
+
if (padInfo) {
|
|
14226
|
+
if (!point2.end_pcb_port_id) {
|
|
14227
|
+
point2.end_pcb_port_id = padInfo.pcb_port_id;
|
|
14228
|
+
}
|
|
14229
|
+
segments.push(currentSegment);
|
|
14230
|
+
const newStartPoint = { ...point2 };
|
|
14231
|
+
delete newStartPoint.end_pcb_port_id;
|
|
14232
|
+
if (!newStartPoint.start_pcb_port_id) {
|
|
14233
|
+
newStartPoint.start_pcb_port_id = padInfo.pcb_port_id;
|
|
14234
|
+
}
|
|
14235
|
+
currentSegment = [newStartPoint];
|
|
14236
|
+
}
|
|
14237
|
+
}
|
|
14238
|
+
}
|
|
14239
|
+
if (currentSegment.length > 0) {
|
|
14240
|
+
segments.push(currentSegment);
|
|
14241
|
+
}
|
|
14242
|
+
return segments;
|
|
14243
|
+
}
|
|
14244
|
+
function addPortIdsToTracesAtJumperPads(segments, db) {
|
|
14245
|
+
const padInfos = getJumperPadInfos(db);
|
|
14246
|
+
if (padInfos.length === 0) return segments;
|
|
14247
|
+
const result = [];
|
|
14248
|
+
for (const segment2 of segments) {
|
|
14249
|
+
const subSegments = splitRouteAtJumperPads(segment2, padInfos);
|
|
14250
|
+
for (const subSegment of subSegments) {
|
|
14251
|
+
if (subSegment.length > 0) {
|
|
14252
|
+
const firstPoint = subSegment[0];
|
|
14253
|
+
const lastPoint = subSegment[subSegment.length - 1];
|
|
14254
|
+
if (firstPoint.route_type === "wire" && !firstPoint.start_pcb_port_id) {
|
|
14255
|
+
const portId = findJumperPortAtPosition(
|
|
14256
|
+
padInfos,
|
|
14257
|
+
firstPoint.x,
|
|
14258
|
+
firstPoint.y
|
|
14259
|
+
);
|
|
14260
|
+
if (portId) {
|
|
14261
|
+
firstPoint.start_pcb_port_id = portId;
|
|
14262
|
+
}
|
|
14263
|
+
}
|
|
14264
|
+
if (lastPoint.route_type === "wire" && !lastPoint.end_pcb_port_id) {
|
|
14265
|
+
const portId = findJumperPortAtPosition(
|
|
14266
|
+
padInfos,
|
|
14267
|
+
lastPoint.x,
|
|
14268
|
+
lastPoint.y
|
|
14269
|
+
);
|
|
14270
|
+
if (portId) {
|
|
14271
|
+
lastPoint.end_pcb_port_id = portId;
|
|
14272
|
+
}
|
|
14273
|
+
}
|
|
14274
|
+
result.push(subSegment);
|
|
14275
|
+
}
|
|
14276
|
+
}
|
|
14277
|
+
}
|
|
14278
|
+
return result;
|
|
14279
|
+
}
|
|
14280
|
+
|
|
14095
14281
|
// lib/components/primitive-components/Group/Group.ts
|
|
14096
14282
|
var Group6 = class extends NormalComponent3 {
|
|
14097
14283
|
pcb_group_id = null;
|
|
@@ -14637,12 +14823,12 @@ var Group6 = class extends NormalComponent3 {
|
|
|
14637
14823
|
const sourceTraceId = pcb_trace.connection_name;
|
|
14638
14824
|
pcb_trace.source_trace_id = sourceTraceId;
|
|
14639
14825
|
}
|
|
14640
|
-
|
|
14826
|
+
let segments = splitPcbTracesOnJumperSegments(pcb_trace.route);
|
|
14641
14827
|
if (segments === null) {
|
|
14642
|
-
|
|
14643
|
-
continue;
|
|
14828
|
+
segments = [pcb_trace.route];
|
|
14644
14829
|
}
|
|
14645
|
-
|
|
14830
|
+
const processedSegments = addPortIdsToTracesAtJumperPads(segments, db);
|
|
14831
|
+
for (const segment2 of processedSegments) {
|
|
14646
14832
|
if (segment2.length > 0) {
|
|
14647
14833
|
db.pcb_trace.insert({
|
|
14648
14834
|
...pcb_trace,
|
|
@@ -20536,7 +20722,7 @@ import { identity as identity5 } from "transformation-matrix";
|
|
|
20536
20722
|
var package_default = {
|
|
20537
20723
|
name: "@tscircuit/core",
|
|
20538
20724
|
type: "module",
|
|
20539
|
-
version: "0.0.
|
|
20725
|
+
version: "0.0.961",
|
|
20540
20726
|
types: "dist/index.d.ts",
|
|
20541
20727
|
main: "dist/index.js",
|
|
20542
20728
|
module: "dist/index.js",
|