@tscircuit/cli 0.1.954 → 0.1.955
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/cli/main.js +913 -815
- package/dist/lib/index.js +833 -735
- package/package.json +2 -2
package/dist/lib/index.js
CHANGED
|
@@ -60414,7 +60414,7 @@ var getNodeHandler = (winterSpec, { port, middleware = [] }) => {
|
|
|
60414
60414
|
}));
|
|
60415
60415
|
};
|
|
60416
60416
|
// package.json
|
|
60417
|
-
var version = "0.1.
|
|
60417
|
+
var version = "0.1.954";
|
|
60418
60418
|
var package_default = {
|
|
60419
60419
|
name: "@tscircuit/cli",
|
|
60420
60420
|
main: "dist/cli/main.js",
|
|
@@ -60443,7 +60443,7 @@ var package_default = {
|
|
|
60443
60443
|
"@types/semver": "^7.5.8",
|
|
60444
60444
|
"bun-match-svg": "^0.0.12",
|
|
60445
60445
|
chokidar: "4.0.1",
|
|
60446
|
-
"circuit-json-to-kicad": "^0.0.
|
|
60446
|
+
"circuit-json-to-kicad": "^0.0.76",
|
|
60447
60447
|
"circuit-json-to-readable-netlist": "^0.0.13",
|
|
60448
60448
|
"circuit-json-to-spice": "^0.0.10",
|
|
60449
60449
|
"circuit-json-to-tscircuit": "^0.0.9",
|
|
@@ -62999,63 +62999,79 @@ __export2(exports_dist, {
|
|
|
62999
62999
|
});
|
|
63000
63000
|
import { KicadSch } from "kicadts";
|
|
63001
63001
|
import { cju } from "@tscircuit/circuit-json-util";
|
|
63002
|
-
import { compose, translate, scale } from "transformation-matrix";
|
|
63002
|
+
import { compose as compose2, translate as translate2, scale } from "transformation-matrix";
|
|
63003
63003
|
import { Paper, Uuid } from "kicadts";
|
|
63004
63004
|
import {
|
|
63005
63005
|
EmbeddedFonts,
|
|
63006
63006
|
LibSymbols,
|
|
63007
|
-
|
|
63008
|
-
|
|
63009
|
-
|
|
63007
|
+
SchematicSymbol as SchematicSymbol4,
|
|
63008
|
+
SymbolPinNames,
|
|
63009
|
+
SymbolPinNumbers
|
|
63010
|
+
} from "kicadts";
|
|
63011
|
+
import { symbols as symbols2 } from "schematic-symbols";
|
|
63012
|
+
import { symbols } from "schematic-symbols";
|
|
63013
|
+
import { SchematicSymbol } from "kicadts";
|
|
63014
|
+
import {
|
|
63015
|
+
compose,
|
|
63016
|
+
scale as createScaleMatrix,
|
|
63017
|
+
translate
|
|
63018
|
+
} from "transformation-matrix";
|
|
63019
|
+
import { Pts, Stroke, SymbolPolyline, SymbolPolylineFill, Xy } from "kicadts";
|
|
63020
|
+
import { applyToPoint } from "transformation-matrix";
|
|
63021
|
+
import {
|
|
63022
|
+
Stroke as Stroke2,
|
|
63010
63023
|
SymbolCircle,
|
|
63011
63024
|
SymbolCircleCenter,
|
|
63012
63025
|
SymbolCircleFill,
|
|
63013
|
-
SymbolCircleRadius
|
|
63026
|
+
SymbolCircleRadius
|
|
63027
|
+
} from "kicadts";
|
|
63028
|
+
import { applyToPoint as applyToPoint2 } from "transformation-matrix";
|
|
63029
|
+
import { SymbolText, TextEffects, TextEffectsFont } from "kicadts";
|
|
63030
|
+
import { applyToPoint as applyToPoint3 } from "transformation-matrix";
|
|
63031
|
+
import { SymbolProperty } from "kicadts";
|
|
63032
|
+
import { TextEffects as TextEffects2, TextEffectsFont as TextEffectsFont2 } from "kicadts";
|
|
63033
|
+
import {
|
|
63034
|
+
SchematicSymbol as SchematicSymbol3,
|
|
63014
63035
|
SymbolPin,
|
|
63015
63036
|
SymbolPinName,
|
|
63016
|
-
SymbolPinNames,
|
|
63017
63037
|
SymbolPinNumber,
|
|
63018
|
-
|
|
63019
|
-
|
|
63020
|
-
SymbolPolylineFill,
|
|
63021
|
-
SymbolProperty,
|
|
63022
|
-
TextEffects,
|
|
63023
|
-
TextEffectsFont,
|
|
63024
|
-
Xy
|
|
63038
|
+
TextEffects as TextEffects3,
|
|
63039
|
+
TextEffectsFont as TextEffectsFont3
|
|
63025
63040
|
} from "kicadts";
|
|
63026
|
-
import {
|
|
63027
|
-
import { symbols } from "schematic-symbols";
|
|
63028
|
-
import { applyToPoint, scale as createScaleMatrix } from "transformation-matrix";
|
|
63041
|
+
import { applyToPoint as applyToPoint4, scale as createScaleMatrix2 } from "transformation-matrix";
|
|
63029
63042
|
import {
|
|
63030
|
-
SchematicSymbol as
|
|
63043
|
+
SchematicSymbol as SchematicSymbol5,
|
|
63031
63044
|
SymbolLibId,
|
|
63032
63045
|
SymbolProperty as SymbolProperty2,
|
|
63033
63046
|
SymbolPin as SymbolPin2,
|
|
63034
63047
|
SymbolInstances,
|
|
63035
63048
|
SymbolInstancesProject,
|
|
63036
63049
|
SymbolInstancePath,
|
|
63037
|
-
TextEffects as
|
|
63038
|
-
TextEffectsFont as
|
|
63039
|
-
TextEffectsJustify
|
|
63050
|
+
TextEffects as TextEffects4,
|
|
63051
|
+
TextEffectsFont as TextEffectsFont4,
|
|
63052
|
+
TextEffectsJustify,
|
|
63053
|
+
EmbeddedFonts as EmbeddedFonts2,
|
|
63054
|
+
SymbolPinNames as SymbolPinNames2,
|
|
63055
|
+
SymbolPinNumbers as SymbolPinNumbers2
|
|
63040
63056
|
} from "kicadts";
|
|
63041
|
-
import { applyToPoint as
|
|
63057
|
+
import { applyToPoint as applyToPoint5 } from "transformation-matrix";
|
|
63042
63058
|
import { symbols as symbols3 } from "schematic-symbols";
|
|
63043
63059
|
import {
|
|
63044
|
-
SchematicSymbol as
|
|
63060
|
+
SchematicSymbol as SchematicSymbol6,
|
|
63045
63061
|
SymbolLibId as SymbolLibId2,
|
|
63046
63062
|
SymbolProperty as SymbolProperty3,
|
|
63047
63063
|
SymbolPin as SymbolPin3,
|
|
63048
63064
|
SymbolInstances as SymbolInstances2,
|
|
63049
63065
|
SymbolInstancesProject as SymbolInstancesProject2,
|
|
63050
63066
|
SymbolInstancePath as SymbolInstancePath2,
|
|
63051
|
-
TextEffects as
|
|
63052
|
-
TextEffectsFont as
|
|
63067
|
+
TextEffects as TextEffects5,
|
|
63068
|
+
TextEffectsFont as TextEffectsFont5,
|
|
63053
63069
|
TextEffectsJustify as TextEffectsJustify2,
|
|
63054
63070
|
GlobalLabel
|
|
63055
63071
|
} from "kicadts";
|
|
63056
|
-
import { applyToPoint as
|
|
63057
|
-
import { Wire, Pts as Pts2, Xy as Xy2, Stroke as
|
|
63058
|
-
import { applyToPoint as
|
|
63072
|
+
import { applyToPoint as applyToPoint6 } from "transformation-matrix";
|
|
63073
|
+
import { Wire, Pts as Pts2, Xy as Xy2, Stroke as Stroke3, Junction } from "kicadts";
|
|
63074
|
+
import { applyToPoint as applyToPoint7 } from "transformation-matrix";
|
|
63059
63075
|
import {
|
|
63060
63076
|
SheetInstances,
|
|
63061
63077
|
SheetInstancesRootPath,
|
|
@@ -63064,7 +63080,7 @@ import {
|
|
|
63064
63080
|
} from "kicadts";
|
|
63065
63081
|
import { KicadPcb } from "kicadts";
|
|
63066
63082
|
import { cju as cju2 } from "@tscircuit/circuit-json-util";
|
|
63067
|
-
import { compose as
|
|
63083
|
+
import { compose as compose4, translate as translate4, scale as scale3 } from "transformation-matrix";
|
|
63068
63084
|
import {
|
|
63069
63085
|
Paper as Paper2,
|
|
63070
63086
|
PcbLayers,
|
|
@@ -63073,20 +63089,28 @@ import {
|
|
|
63073
63089
|
Setup
|
|
63074
63090
|
} from "kicadts";
|
|
63075
63091
|
import { PcbNet } from "kicadts";
|
|
63076
|
-
import { Footprint } from "kicadts";
|
|
63077
|
-
import { applyToPoint as
|
|
63078
|
-
import {
|
|
63079
|
-
|
|
63080
|
-
|
|
63081
|
-
|
|
63082
|
-
|
|
63083
|
-
|
|
63092
|
+
import { Footprint as Footprint2 } from "kicadts";
|
|
63093
|
+
import { applyToPoint as applyToPoint13 } from "transformation-matrix";
|
|
63094
|
+
import {
|
|
63095
|
+
Property,
|
|
63096
|
+
TextEffects as TextEffects6,
|
|
63097
|
+
TextEffectsFont as TextEffectsFont6,
|
|
63098
|
+
EmbeddedFonts as EmbeddedFonts4,
|
|
63099
|
+
FootprintModel,
|
|
63100
|
+
FootprintAttr
|
|
63101
|
+
} from "kicadts";
|
|
63102
|
+
import { FpCircle, Stroke as Stroke4 } from "kicadts";
|
|
63103
|
+
import { FpCircle as FpCircle2, Stroke as Stroke5 } from "kicadts";
|
|
63104
|
+
import { FpRect, Stroke as Stroke6 } from "kicadts";
|
|
63105
|
+
import { FpRect as FpRect2, Stroke as Stroke7 } from "kicadts";
|
|
63106
|
+
import { FpRect as FpRect3, Stroke as Stroke8 } from "kicadts";
|
|
63107
|
+
import { FpPoly, Pts as Pts3, Xy as Xy3, Stroke as Stroke9 } from "kicadts";
|
|
63084
63108
|
import"kicadts";
|
|
63085
|
-
import { FpText, TextEffects as
|
|
63086
|
-
import { applyToPoint as
|
|
63087
|
-
import { FpText as FpText3, TextEffects as
|
|
63088
|
-
import { applyToPoint as
|
|
63089
|
-
import { FootprintModel } from "kicadts";
|
|
63109
|
+
import { FpText, TextEffects as TextEffects7, TextEffectsFont as TextEffectsFont7 } from "kicadts";
|
|
63110
|
+
import { applyToPoint as applyToPoint8, rotate, identity } from "transformation-matrix";
|
|
63111
|
+
import { FpText as FpText3, TextEffects as TextEffects8, TextEffectsFont as TextEffectsFont8 } from "kicadts";
|
|
63112
|
+
import { applyToPoint as applyToPoint9, rotate as rotate2, identity as identity2 } from "transformation-matrix";
|
|
63113
|
+
import { FootprintModel as FootprintModel2 } from "kicadts";
|
|
63090
63114
|
import {
|
|
63091
63115
|
FootprintPad,
|
|
63092
63116
|
PadPrimitives,
|
|
@@ -63097,69 +63121,69 @@ import {
|
|
|
63097
63121
|
PadNet
|
|
63098
63122
|
} from "kicadts";
|
|
63099
63123
|
import {
|
|
63100
|
-
applyToPoint as
|
|
63101
|
-
compose as
|
|
63102
|
-
translate as
|
|
63124
|
+
applyToPoint as applyToPoint10,
|
|
63125
|
+
compose as compose3,
|
|
63126
|
+
translate as translate3,
|
|
63103
63127
|
scale as scale2,
|
|
63104
63128
|
rotate as rotate3
|
|
63105
63129
|
} from "transformation-matrix";
|
|
63106
63130
|
import { FootprintPad as FootprintPad2, PadDrill, PadNet as PadNet2 } from "kicadts";
|
|
63107
|
-
import { applyToPoint as
|
|
63131
|
+
import { applyToPoint as applyToPoint11, rotate as rotate4, identity as identity3 } from "transformation-matrix";
|
|
63108
63132
|
import { FootprintPad as FootprintPad3, PadDrill as PadDrill2 } from "kicadts";
|
|
63109
|
-
import { applyToPoint as
|
|
63133
|
+
import { applyToPoint as applyToPoint12, rotate as rotate5, identity as identity4 } from "transformation-matrix";
|
|
63110
63134
|
import { Segment, SegmentNet } from "kicadts";
|
|
63111
|
-
import { applyToPoint as
|
|
63135
|
+
import { applyToPoint as applyToPoint14 } from "transformation-matrix";
|
|
63112
63136
|
import { Via, ViaNet } from "kicadts";
|
|
63113
|
-
import { applyToPoint as
|
|
63137
|
+
import { applyToPoint as applyToPoint15 } from "transformation-matrix";
|
|
63114
63138
|
import { GrLine } from "kicadts";
|
|
63115
63139
|
import {
|
|
63116
63140
|
At,
|
|
63117
63141
|
GrText,
|
|
63118
|
-
TextEffects as
|
|
63119
|
-
TextEffectsFont as
|
|
63142
|
+
TextEffects as TextEffects9,
|
|
63143
|
+
TextEffectsFont as TextEffectsFont9,
|
|
63120
63144
|
TextEffectsJustify as TextEffectsJustify3
|
|
63121
63145
|
} from "kicadts";
|
|
63122
|
-
import { applyToPoint as
|
|
63123
|
-
import { applyToPoint as
|
|
63146
|
+
import { applyToPoint as applyToPoint16 } from "transformation-matrix";
|
|
63147
|
+
import { applyToPoint as applyToPoint18 } from "transformation-matrix";
|
|
63124
63148
|
import {
|
|
63125
63149
|
GrText as GrText2,
|
|
63126
|
-
TextEffects as
|
|
63127
|
-
TextEffectsFont as
|
|
63150
|
+
TextEffects as TextEffects10,
|
|
63151
|
+
TextEffectsFont as TextEffectsFont10,
|
|
63128
63152
|
TextEffectsJustify as TextEffectsJustify4,
|
|
63129
63153
|
At as At2
|
|
63130
63154
|
} from "kicadts";
|
|
63131
|
-
import { applyToPoint as
|
|
63155
|
+
import { applyToPoint as applyToPoint17 } from "transformation-matrix";
|
|
63132
63156
|
import { cju as cju3 } from "@tscircuit/circuit-json-util";
|
|
63133
63157
|
import { cju as cju4 } from "@tscircuit/circuit-json-util";
|
|
63134
63158
|
import { parseKicadSexpr, KicadSch as KicadSch2 } from "kicadts";
|
|
63135
63159
|
import {
|
|
63136
63160
|
parseKicadSexpr as parseKicadSexpr2,
|
|
63137
63161
|
KicadPcb as KicadPcb2,
|
|
63138
|
-
FootprintModel as
|
|
63162
|
+
FootprintModel as FootprintModel3,
|
|
63139
63163
|
At as At3,
|
|
63140
|
-
EmbeddedFonts as
|
|
63141
|
-
FootprintAttr,
|
|
63142
|
-
Property,
|
|
63143
|
-
TextEffects as
|
|
63144
|
-
TextEffectsFont as
|
|
63164
|
+
EmbeddedFonts as EmbeddedFonts5,
|
|
63165
|
+
FootprintAttr as FootprintAttr2,
|
|
63166
|
+
Property as Property2,
|
|
63167
|
+
TextEffects as TextEffects11,
|
|
63168
|
+
TextEffectsFont as TextEffectsFont11
|
|
63145
63169
|
} from "kicadts";
|
|
63146
63170
|
import { KicadSymbolLib } from "kicadts";
|
|
63147
63171
|
import { parseKicadMod } from "kicadts";
|
|
63148
63172
|
import {
|
|
63149
63173
|
parseKicadSexpr as parseKicadSexpr3,
|
|
63150
|
-
Footprint as
|
|
63151
|
-
Property as
|
|
63152
|
-
TextEffects as
|
|
63153
|
-
TextEffectsFont as
|
|
63174
|
+
Footprint as Footprint4,
|
|
63175
|
+
Property as Property3,
|
|
63176
|
+
TextEffects as TextEffects12,
|
|
63177
|
+
TextEffectsFont as TextEffectsFont12
|
|
63154
63178
|
} from "kicadts";
|
|
63155
63179
|
import { parseKicadMod as parseKicadMod2 } from "kicadts";
|
|
63156
63180
|
import {
|
|
63157
|
-
EmbeddedFonts as
|
|
63158
|
-
SymbolPinNames as
|
|
63159
|
-
SymbolPinNumbers as
|
|
63181
|
+
EmbeddedFonts as EmbeddedFonts6,
|
|
63182
|
+
SymbolPinNames as SymbolPinNames3,
|
|
63183
|
+
SymbolPinNumbers as SymbolPinNumbers3,
|
|
63160
63184
|
SymbolProperty as SymbolProperty4,
|
|
63161
|
-
TextEffects as
|
|
63162
|
-
TextEffectsFont as
|
|
63185
|
+
TextEffects as TextEffects13,
|
|
63186
|
+
TextEffectsFont as TextEffectsFont13,
|
|
63163
63187
|
TextEffectsJustify as TextEffectsJustify5
|
|
63164
63188
|
} from "kicadts";
|
|
63165
63189
|
import { KicadSymbolLib as KicadSymbolLib2 } from "kicadts";
|
|
@@ -63308,6 +63332,427 @@ function getLibraryId(sourceComp, schematicComp, cadComponent, schematicSymbolNa
|
|
|
63308
63332
|
const refPrefix = getReferencePrefixForComponent(sourceComp);
|
|
63309
63333
|
return `Device:${refPrefix}_${ergonomicName}`;
|
|
63310
63334
|
}
|
|
63335
|
+
function buildSymbolDataFromSchematicPrimitives(params2) {
|
|
63336
|
+
const {
|
|
63337
|
+
circuitJson,
|
|
63338
|
+
schematicSymbolId,
|
|
63339
|
+
schematicSymbol,
|
|
63340
|
+
schematicComponentId
|
|
63341
|
+
} = params2;
|
|
63342
|
+
const circles = circuitJson.filter((el) => el.type === "schematic_circle" && el.schematic_symbol_id === schematicSymbolId);
|
|
63343
|
+
const symbolLines = circuitJson.filter((el) => el.type === "schematic_line" && el.schematic_symbol_id === schematicSymbolId);
|
|
63344
|
+
const schLines = schematicComponentId ? circuitJson.filter((el) => el.type === "schematic_line" && el.schematic_component_id === schematicComponentId && !el.schematic_symbol_id) : [];
|
|
63345
|
+
const lines = [...symbolLines, ...schLines];
|
|
63346
|
+
const paths = circuitJson.filter((el) => el.type === "schematic_path" && el.schematic_symbol_id === schematicSymbolId);
|
|
63347
|
+
const texts = circuitJson.filter((el) => el.type === "schematic_text" && el.schematic_symbol_id === schematicSymbolId);
|
|
63348
|
+
let ports = circuitJson.filter((el) => el.type === "schematic_port" && ("schematic_symbol_id" in el) && el.schematic_symbol_id === schematicSymbolId);
|
|
63349
|
+
if (ports.length === 0 && schematicComponentId) {
|
|
63350
|
+
ports = circuitJson.filter((el) => el.type === "schematic_port" && el.schematic_component_id === schematicComponentId && el.display_pin_label !== undefined);
|
|
63351
|
+
if (ports.length === 0) {
|
|
63352
|
+
const allPorts = circuitJson.filter((el) => el.type === "schematic_port" && el.schematic_component_id === schematicComponentId);
|
|
63353
|
+
const seenPinNumbers = /* @__PURE__ */ new Set;
|
|
63354
|
+
ports = allPorts.filter((port) => {
|
|
63355
|
+
const pinNum = port.pin_number;
|
|
63356
|
+
if (pinNum !== undefined) {
|
|
63357
|
+
if (seenPinNumbers.has(pinNum)) {
|
|
63358
|
+
return false;
|
|
63359
|
+
}
|
|
63360
|
+
seenPinNumbers.add(pinNum);
|
|
63361
|
+
}
|
|
63362
|
+
return true;
|
|
63363
|
+
});
|
|
63364
|
+
}
|
|
63365
|
+
}
|
|
63366
|
+
const primitives2 = [];
|
|
63367
|
+
for (const circle of circles) {
|
|
63368
|
+
primitives2.push({
|
|
63369
|
+
type: "circle",
|
|
63370
|
+
x: circle.center?.x ?? 0,
|
|
63371
|
+
y: circle.center?.y ?? 0,
|
|
63372
|
+
radius: circle.radius ?? 0.5,
|
|
63373
|
+
fill: circle.is_filled ?? false,
|
|
63374
|
+
fillColor: circle.fill_color
|
|
63375
|
+
});
|
|
63376
|
+
}
|
|
63377
|
+
for (const line of lines) {
|
|
63378
|
+
primitives2.push({
|
|
63379
|
+
type: "path",
|
|
63380
|
+
points: [
|
|
63381
|
+
{ x: line.x1 ?? 0, y: line.y1 ?? 0 },
|
|
63382
|
+
{ x: line.x2 ?? 0, y: line.y2 ?? 0 }
|
|
63383
|
+
]
|
|
63384
|
+
});
|
|
63385
|
+
}
|
|
63386
|
+
for (const path7 of paths) {
|
|
63387
|
+
if (path7.points && path7.points.length > 0) {
|
|
63388
|
+
primitives2.push({
|
|
63389
|
+
type: "path",
|
|
63390
|
+
points: path7.points,
|
|
63391
|
+
fill: path7.is_filled ?? false,
|
|
63392
|
+
fillColor: path7.fill_color
|
|
63393
|
+
});
|
|
63394
|
+
}
|
|
63395
|
+
}
|
|
63396
|
+
const symbolTexts = texts.map((text) => ({
|
|
63397
|
+
text: text.text ?? "",
|
|
63398
|
+
x: text.position?.x ?? 0,
|
|
63399
|
+
y: text.position?.y ?? 0,
|
|
63400
|
+
fontSize: text.font_size ?? 0.2,
|
|
63401
|
+
anchor: text.anchor ?? "center"
|
|
63402
|
+
}));
|
|
63403
|
+
const symbolPorts = ports.map((port, index) => ({
|
|
63404
|
+
x: port.center?.x ?? 0,
|
|
63405
|
+
y: port.center?.y ?? 0,
|
|
63406
|
+
labels: [port.display_pin_label || `${port.pin_number || index + 1}`],
|
|
63407
|
+
pinNumber: port.pin_number || index + 1,
|
|
63408
|
+
facingDirection: port.facing_direction
|
|
63409
|
+
}));
|
|
63410
|
+
symbolPorts.sort((a, b) => a.pinNumber - b.pinNumber);
|
|
63411
|
+
return {
|
|
63412
|
+
center: schematicSymbol.center || { x: 0, y: 0 },
|
|
63413
|
+
size: schematicSymbol.size || { width: 1, height: 1 },
|
|
63414
|
+
primitives: primitives2,
|
|
63415
|
+
texts: symbolTexts,
|
|
63416
|
+
ports: symbolPorts
|
|
63417
|
+
};
|
|
63418
|
+
}
|
|
63419
|
+
function createPolylineFromPoints({
|
|
63420
|
+
points,
|
|
63421
|
+
transform,
|
|
63422
|
+
fillType
|
|
63423
|
+
}) {
|
|
63424
|
+
const polyline = new SymbolPolyline;
|
|
63425
|
+
const xyPoints = points.map((p) => {
|
|
63426
|
+
const transformed = applyToPoint(transform, p);
|
|
63427
|
+
return new Xy(transformed.x, transformed.y);
|
|
63428
|
+
});
|
|
63429
|
+
const pts = new Pts(xyPoints);
|
|
63430
|
+
polyline.points = pts;
|
|
63431
|
+
const stroke = new Stroke;
|
|
63432
|
+
stroke.width = 0.254;
|
|
63433
|
+
stroke.type = "default";
|
|
63434
|
+
polyline.stroke = stroke;
|
|
63435
|
+
const fill = new SymbolPolylineFill;
|
|
63436
|
+
fill.type = fillType;
|
|
63437
|
+
polyline.fill = fill;
|
|
63438
|
+
return polyline;
|
|
63439
|
+
}
|
|
63440
|
+
function createCircleFromPrimitive({
|
|
63441
|
+
primitive,
|
|
63442
|
+
transform,
|
|
63443
|
+
scale: scale4
|
|
63444
|
+
}) {
|
|
63445
|
+
const circle = new SymbolCircle;
|
|
63446
|
+
const scaledPos = applyToPoint2(transform, {
|
|
63447
|
+
x: primitive.x,
|
|
63448
|
+
y: primitive.y
|
|
63449
|
+
});
|
|
63450
|
+
const c = circle;
|
|
63451
|
+
c._sxCenter = new SymbolCircleCenter(scaledPos.x, scaledPos.y);
|
|
63452
|
+
c._sxRadius = new SymbolCircleRadius(primitive.radius * scale4);
|
|
63453
|
+
const stroke = new Stroke2;
|
|
63454
|
+
stroke.width = 0.254;
|
|
63455
|
+
stroke.type = "default";
|
|
63456
|
+
c._sxStroke = stroke;
|
|
63457
|
+
const fill = new SymbolCircleFill;
|
|
63458
|
+
fill.type = primitive.fill ? "background" : "none";
|
|
63459
|
+
c._sxFill = fill;
|
|
63460
|
+
return circle;
|
|
63461
|
+
}
|
|
63462
|
+
function createTextFromPrimitive({
|
|
63463
|
+
schText,
|
|
63464
|
+
transform,
|
|
63465
|
+
scale: scale4
|
|
63466
|
+
}) {
|
|
63467
|
+
const symbolText = new SymbolText;
|
|
63468
|
+
const scaledPos = applyToPoint3(transform, { x: schText.x, y: schText.y });
|
|
63469
|
+
symbolText.value = schText.text;
|
|
63470
|
+
symbolText.at = [scaledPos.x, scaledPos.y, 0];
|
|
63471
|
+
const scaledFontSize = schText.fontSize * scale4;
|
|
63472
|
+
const font = new TextEffectsFont;
|
|
63473
|
+
font.size = { height: scaledFontSize, width: scaledFontSize };
|
|
63474
|
+
symbolText.effects = new TextEffects({ font });
|
|
63475
|
+
return symbolText;
|
|
63476
|
+
}
|
|
63477
|
+
function createDrawingSubsymbol({
|
|
63478
|
+
libId,
|
|
63479
|
+
symbolData,
|
|
63480
|
+
isChip,
|
|
63481
|
+
c2kMatSchScale
|
|
63482
|
+
}) {
|
|
63483
|
+
const drawingSymbol = new SchematicSymbol({
|
|
63484
|
+
libraryId: `${libId.split(":")[1]}_0_1`
|
|
63485
|
+
});
|
|
63486
|
+
const GRID_ALIGNED_SCALE = 15.24;
|
|
63487
|
+
const symbolScale = isChip ? c2kMatSchScale : GRID_ALIGNED_SCALE;
|
|
63488
|
+
const cx = symbolData.center?.x ?? 0;
|
|
63489
|
+
const cy = symbolData.center?.y ?? 0;
|
|
63490
|
+
const transform = compose(createScaleMatrix(symbolScale, symbolScale), translate(-cx, -cy));
|
|
63491
|
+
for (const primitive of symbolData.primitives || []) {
|
|
63492
|
+
if (primitive.type === "path" && primitive.points) {
|
|
63493
|
+
const fillType = isChip || primitive.fill ? "background" : "none";
|
|
63494
|
+
const polyline = createPolylineFromPoints({
|
|
63495
|
+
points: primitive.points,
|
|
63496
|
+
transform,
|
|
63497
|
+
fillType
|
|
63498
|
+
});
|
|
63499
|
+
drawingSymbol.polylines.push(polyline);
|
|
63500
|
+
} else if (primitive.type === "circle") {
|
|
63501
|
+
const circle = createCircleFromPrimitive({
|
|
63502
|
+
primitive,
|
|
63503
|
+
transform,
|
|
63504
|
+
scale: symbolScale
|
|
63505
|
+
});
|
|
63506
|
+
drawingSymbol.circles.push(circle);
|
|
63507
|
+
}
|
|
63508
|
+
}
|
|
63509
|
+
const textsArray = Array.isArray(symbolData.texts) ? symbolData.texts : [];
|
|
63510
|
+
for (const schText of textsArray) {
|
|
63511
|
+
const symbolText = createTextFromPrimitive({
|
|
63512
|
+
schText,
|
|
63513
|
+
transform,
|
|
63514
|
+
scale: symbolScale
|
|
63515
|
+
});
|
|
63516
|
+
drawingSymbol.texts.push(symbolText);
|
|
63517
|
+
}
|
|
63518
|
+
return drawingSymbol;
|
|
63519
|
+
}
|
|
63520
|
+
function createGenericChipSymbolData(schematicComp, db) {
|
|
63521
|
+
const schematicPorts = db.schematic_port.list().filter((p) => p.schematic_component_id === schematicComp.schematic_component_id).sort((a, b) => (a.pin_number || 0) - (b.pin_number || 0));
|
|
63522
|
+
const width = schematicComp.size?.width || 1.5;
|
|
63523
|
+
const height = schematicComp.size?.height || 1;
|
|
63524
|
+
const boxPath = {
|
|
63525
|
+
type: "path",
|
|
63526
|
+
points: [
|
|
63527
|
+
{ x: -width / 2, y: -height / 2 },
|
|
63528
|
+
{ x: width / 2, y: -height / 2 },
|
|
63529
|
+
{ x: width / 2, y: height / 2 },
|
|
63530
|
+
{ x: -width / 2, y: height / 2 },
|
|
63531
|
+
{ x: -width / 2, y: -height / 2 }
|
|
63532
|
+
]
|
|
63533
|
+
};
|
|
63534
|
+
const ports = schematicPorts.map((port) => {
|
|
63535
|
+
const portX = port.center.x - schematicComp.center.x;
|
|
63536
|
+
const portY = port.center.y - schematicComp.center.y;
|
|
63537
|
+
return {
|
|
63538
|
+
x: portX,
|
|
63539
|
+
y: portY,
|
|
63540
|
+
labels: [port.display_pin_label || `${port.pin_number || 1}`],
|
|
63541
|
+
pinNumber: port.pin_number || 1
|
|
63542
|
+
};
|
|
63543
|
+
});
|
|
63544
|
+
return {
|
|
63545
|
+
center: { x: 0, y: 0 },
|
|
63546
|
+
primitives: [boxPath],
|
|
63547
|
+
ports,
|
|
63548
|
+
size: { width, height }
|
|
63549
|
+
};
|
|
63550
|
+
}
|
|
63551
|
+
function createTextEffects(size, hide) {
|
|
63552
|
+
const font = new TextEffectsFont2;
|
|
63553
|
+
font.size = { height: size, width: size };
|
|
63554
|
+
return new TextEffects2({
|
|
63555
|
+
font,
|
|
63556
|
+
hiddenText: hide
|
|
63557
|
+
});
|
|
63558
|
+
}
|
|
63559
|
+
function addSymbolProperties({
|
|
63560
|
+
symbol,
|
|
63561
|
+
libId,
|
|
63562
|
+
description,
|
|
63563
|
+
keywords,
|
|
63564
|
+
fpFilters,
|
|
63565
|
+
footprintRef = "",
|
|
63566
|
+
referencePrefix
|
|
63567
|
+
}) {
|
|
63568
|
+
const refPrefix = referencePrefix || libId.split(":")[1]?.[0] || "U";
|
|
63569
|
+
const properties = [
|
|
63570
|
+
{
|
|
63571
|
+
key: "Reference",
|
|
63572
|
+
value: refPrefix,
|
|
63573
|
+
id: 0,
|
|
63574
|
+
at: [2.032, 0, 90],
|
|
63575
|
+
hide: false
|
|
63576
|
+
},
|
|
63577
|
+
{ key: "Value", value: refPrefix, id: 1, at: [0, 0, 90], hide: false },
|
|
63578
|
+
{
|
|
63579
|
+
key: "Footprint",
|
|
63580
|
+
value: footprintRef,
|
|
63581
|
+
id: 2,
|
|
63582
|
+
at: [-1.778, 0, 90],
|
|
63583
|
+
hide: true
|
|
63584
|
+
},
|
|
63585
|
+
{
|
|
63586
|
+
key: "Datasheet",
|
|
63587
|
+
value: "~",
|
|
63588
|
+
id: 3,
|
|
63589
|
+
at: [0, 0, 0],
|
|
63590
|
+
hide: true
|
|
63591
|
+
},
|
|
63592
|
+
{
|
|
63593
|
+
key: "Description",
|
|
63594
|
+
value: description,
|
|
63595
|
+
id: 4,
|
|
63596
|
+
at: [0, 0, 0],
|
|
63597
|
+
hide: true
|
|
63598
|
+
},
|
|
63599
|
+
{
|
|
63600
|
+
key: "ki_keywords",
|
|
63601
|
+
value: keywords,
|
|
63602
|
+
id: 5,
|
|
63603
|
+
at: [0, 0, 0],
|
|
63604
|
+
hide: true
|
|
63605
|
+
},
|
|
63606
|
+
{
|
|
63607
|
+
key: "ki_fp_filters",
|
|
63608
|
+
value: fpFilters,
|
|
63609
|
+
id: 6,
|
|
63610
|
+
at: [0, 0, 0],
|
|
63611
|
+
hide: true
|
|
63612
|
+
}
|
|
63613
|
+
];
|
|
63614
|
+
for (const prop of properties) {
|
|
63615
|
+
symbol.properties.push(new SymbolProperty({
|
|
63616
|
+
key: prop.key,
|
|
63617
|
+
value: prop.value,
|
|
63618
|
+
id: prop.id,
|
|
63619
|
+
at: prop.at,
|
|
63620
|
+
effects: createTextEffects(1.27, prop.hide)
|
|
63621
|
+
}));
|
|
63622
|
+
}
|
|
63623
|
+
}
|
|
63624
|
+
function calculatePinPosition({
|
|
63625
|
+
port,
|
|
63626
|
+
center,
|
|
63627
|
+
size,
|
|
63628
|
+
isChip,
|
|
63629
|
+
portIndex,
|
|
63630
|
+
schematicComponent,
|
|
63631
|
+
schematicPorts,
|
|
63632
|
+
c2kMatSchScale
|
|
63633
|
+
}) {
|
|
63634
|
+
const GRID_ALIGNED_SCALE = 15.24;
|
|
63635
|
+
const symbolScale = isChip ? c2kMatSchScale : GRID_ALIGNED_SCALE;
|
|
63636
|
+
let portX = port.x ?? 0;
|
|
63637
|
+
let portY = port.y ?? 0;
|
|
63638
|
+
let usingCircuitJsonPort = false;
|
|
63639
|
+
if (isChip && portIndex !== undefined && schematicComponent) {
|
|
63640
|
+
const sortedPorts = schematicPorts.filter((p) => p.schematic_component_id === schematicComponent.schematic_component_id).sort((a, b) => (a.pin_number || 0) - (b.pin_number || 0));
|
|
63641
|
+
if (sortedPorts[portIndex]) {
|
|
63642
|
+
const schPort = sortedPorts[portIndex];
|
|
63643
|
+
portX = schPort.center.x - schematicComponent.center.x;
|
|
63644
|
+
portY = schPort.center.y - schematicComponent.center.y;
|
|
63645
|
+
usingCircuitJsonPort = true;
|
|
63646
|
+
}
|
|
63647
|
+
}
|
|
63648
|
+
let dx;
|
|
63649
|
+
let dy;
|
|
63650
|
+
if (usingCircuitJsonPort) {
|
|
63651
|
+
dx = portX;
|
|
63652
|
+
dy = portY;
|
|
63653
|
+
} else {
|
|
63654
|
+
const cx = center?.x ?? 0;
|
|
63655
|
+
const cy = center?.y ?? 0;
|
|
63656
|
+
dx = portX - cx;
|
|
63657
|
+
dy = portY - cy;
|
|
63658
|
+
}
|
|
63659
|
+
const scaleMatrix = createScaleMatrix2(symbolScale, symbolScale);
|
|
63660
|
+
const scaled = applyToPoint4(scaleMatrix, { x: dx, y: dy });
|
|
63661
|
+
let isHorizontalPin;
|
|
63662
|
+
if (isChip && size) {
|
|
63663
|
+
const halfWidth = size.width / 2;
|
|
63664
|
+
const halfHeight = size.height / 2;
|
|
63665
|
+
const normalizedDx = Math.abs(dx) / halfWidth;
|
|
63666
|
+
const normalizedDy = Math.abs(dy) / halfHeight;
|
|
63667
|
+
isHorizontalPin = normalizedDx > normalizedDy;
|
|
63668
|
+
} else {
|
|
63669
|
+
isHorizontalPin = Math.abs(dx) > Math.abs(dy);
|
|
63670
|
+
}
|
|
63671
|
+
let x = scaled.x;
|
|
63672
|
+
let y = scaled.y;
|
|
63673
|
+
const CHIP_PIN_LENGTH = 6;
|
|
63674
|
+
if (isChip && size) {
|
|
63675
|
+
const halfWidth = size.width / 2 * symbolScale;
|
|
63676
|
+
const halfHeight = size.height / 2 * symbolScale;
|
|
63677
|
+
if (isHorizontalPin) {
|
|
63678
|
+
x = dx > 0 ? halfWidth : -halfWidth;
|
|
63679
|
+
y = dy * symbolScale;
|
|
63680
|
+
} else {
|
|
63681
|
+
x = dx * symbolScale;
|
|
63682
|
+
y = dy > 0 ? halfHeight : -halfHeight;
|
|
63683
|
+
}
|
|
63684
|
+
}
|
|
63685
|
+
let angle = 0;
|
|
63686
|
+
if (isHorizontalPin) {
|
|
63687
|
+
if (dx > 0) {
|
|
63688
|
+
angle = 180;
|
|
63689
|
+
if (isChip)
|
|
63690
|
+
x = x + CHIP_PIN_LENGTH;
|
|
63691
|
+
} else {
|
|
63692
|
+
angle = 0;
|
|
63693
|
+
if (isChip)
|
|
63694
|
+
x = x - CHIP_PIN_LENGTH;
|
|
63695
|
+
}
|
|
63696
|
+
} else {
|
|
63697
|
+
if (dy > 0) {
|
|
63698
|
+
angle = 270;
|
|
63699
|
+
if (isChip)
|
|
63700
|
+
y = y + CHIP_PIN_LENGTH;
|
|
63701
|
+
} else {
|
|
63702
|
+
angle = 90;
|
|
63703
|
+
if (isChip)
|
|
63704
|
+
y = y - CHIP_PIN_LENGTH;
|
|
63705
|
+
}
|
|
63706
|
+
}
|
|
63707
|
+
return { x, y, angle };
|
|
63708
|
+
}
|
|
63709
|
+
function createPinSubsymbol({
|
|
63710
|
+
libId,
|
|
63711
|
+
symbolData,
|
|
63712
|
+
isChip,
|
|
63713
|
+
schematicComponent,
|
|
63714
|
+
schematicPorts,
|
|
63715
|
+
c2kMatSchScale
|
|
63716
|
+
}) {
|
|
63717
|
+
const pinSymbol = new SchematicSymbol3({
|
|
63718
|
+
libraryId: `${libId.split(":")[1]}_1_1`
|
|
63719
|
+
});
|
|
63720
|
+
const CHIP_PIN_LENGTH = 6;
|
|
63721
|
+
const CUSTOM_SYMBOL_PIN_LENGTH = 2.54;
|
|
63722
|
+
for (let i = 0;i < (symbolData.ports?.length || 0); i++) {
|
|
63723
|
+
const port = symbolData.ports[i];
|
|
63724
|
+
const pin = new SymbolPin;
|
|
63725
|
+
pin.pinElectricalType = "passive";
|
|
63726
|
+
pin.pinGraphicStyle = "line";
|
|
63727
|
+
const { x, y, angle } = calculatePinPosition({
|
|
63728
|
+
port,
|
|
63729
|
+
center: symbolData.center,
|
|
63730
|
+
size: symbolData.size,
|
|
63731
|
+
isChip,
|
|
63732
|
+
portIndex: i,
|
|
63733
|
+
schematicComponent,
|
|
63734
|
+
schematicPorts,
|
|
63735
|
+
c2kMatSchScale
|
|
63736
|
+
});
|
|
63737
|
+
pin.at = [x, y, angle];
|
|
63738
|
+
pin.length = isChip ? CHIP_PIN_LENGTH : CUSTOM_SYMBOL_PIN_LENGTH;
|
|
63739
|
+
const nameFont = new TextEffectsFont3;
|
|
63740
|
+
nameFont.size = { height: 1.27, width: 1.27 };
|
|
63741
|
+
const nameEffects = new TextEffects3({ font: nameFont });
|
|
63742
|
+
const pinName = port.labels?.[0] || "~";
|
|
63743
|
+
pin._sxName = new SymbolPinName({ value: pinName, effects: nameEffects });
|
|
63744
|
+
const numFont = new TextEffectsFont3;
|
|
63745
|
+
numFont.size = { height: 1.27, width: 1.27 };
|
|
63746
|
+
const numEffects = new TextEffects3({ font: numFont });
|
|
63747
|
+
const pinNum = port.pinNumber?.toString() || `${i + 1}`;
|
|
63748
|
+
pin._sxNumber = new SymbolPinNumber({
|
|
63749
|
+
value: pinNum,
|
|
63750
|
+
effects: numEffects
|
|
63751
|
+
});
|
|
63752
|
+
pinSymbol.pins.push(pin);
|
|
63753
|
+
}
|
|
63754
|
+
return pinSymbol;
|
|
63755
|
+
}
|
|
63311
63756
|
var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
63312
63757
|
processedSymbolNames = /* @__PURE__ */ new Set;
|
|
63313
63758
|
_step() {
|
|
@@ -63405,7 +63850,12 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
63405
63850
|
return null;
|
|
63406
63851
|
}
|
|
63407
63852
|
this.processedSymbolNames.add(libId);
|
|
63408
|
-
const symbolData =
|
|
63853
|
+
const symbolData = buildSymbolDataFromSchematicPrimitives({
|
|
63854
|
+
circuitJson: this.ctx.circuitJson,
|
|
63855
|
+
schematicSymbolId,
|
|
63856
|
+
schematicSymbol,
|
|
63857
|
+
schematicComponentId: schematicComponent.schematic_component_id
|
|
63858
|
+
});
|
|
63409
63859
|
const footprintName = getKicadCompatibleComponentName(sourceComp, cadComponent);
|
|
63410
63860
|
return this.createLibrarySymbol({
|
|
63411
63861
|
libId,
|
|
@@ -63419,74 +63869,6 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
63419
63869
|
referencePrefix: getReferencePrefixForComponent(sourceComp)
|
|
63420
63870
|
});
|
|
63421
63871
|
}
|
|
63422
|
-
buildSymbolDataFromSchematicPrimitives(schematicSymbolId, schematicSymbol, schematicComponentId) {
|
|
63423
|
-
const { circuitJson } = this.ctx;
|
|
63424
|
-
const circles = circuitJson.filter((el) => el.type === "schematic_circle" && el.schematic_symbol_id === schematicSymbolId);
|
|
63425
|
-
const lines = circuitJson.filter((el) => el.type === "schematic_line" && el.schematic_symbol_id === schematicSymbolId);
|
|
63426
|
-
const paths = circuitJson.filter((el) => el.type === "schematic_path" && el.schematic_symbol_id === schematicSymbolId);
|
|
63427
|
-
let ports = circuitJson.filter((el) => el.type === "schematic_port" && ("schematic_symbol_id" in el) && el.schematic_symbol_id === schematicSymbolId);
|
|
63428
|
-
if (ports.length === 0 && schematicComponentId) {
|
|
63429
|
-
ports = circuitJson.filter((el) => el.type === "schematic_port" && el.schematic_component_id === schematicComponentId && el.display_pin_label !== undefined);
|
|
63430
|
-
if (ports.length === 0) {
|
|
63431
|
-
const allPorts = circuitJson.filter((el) => el.type === "schematic_port" && el.schematic_component_id === schematicComponentId);
|
|
63432
|
-
const seenPinNumbers = /* @__PURE__ */ new Set;
|
|
63433
|
-
ports = allPorts.filter((port) => {
|
|
63434
|
-
const pinNum = port.pin_number;
|
|
63435
|
-
if (pinNum !== undefined) {
|
|
63436
|
-
if (seenPinNumbers.has(pinNum)) {
|
|
63437
|
-
return false;
|
|
63438
|
-
}
|
|
63439
|
-
seenPinNumbers.add(pinNum);
|
|
63440
|
-
}
|
|
63441
|
-
return true;
|
|
63442
|
-
});
|
|
63443
|
-
}
|
|
63444
|
-
}
|
|
63445
|
-
const primitives2 = [];
|
|
63446
|
-
for (const circle of circles) {
|
|
63447
|
-
primitives2.push({
|
|
63448
|
-
type: "circle",
|
|
63449
|
-
x: circle.center?.x ?? 0,
|
|
63450
|
-
y: circle.center?.y ?? 0,
|
|
63451
|
-
radius: circle.radius ?? 0.5,
|
|
63452
|
-
fill: circle.is_filled ?? false,
|
|
63453
|
-
fillColor: circle.fill_color
|
|
63454
|
-
});
|
|
63455
|
-
}
|
|
63456
|
-
for (const line of lines) {
|
|
63457
|
-
primitives2.push({
|
|
63458
|
-
type: "path",
|
|
63459
|
-
points: [
|
|
63460
|
-
{ x: line.x1 ?? 0, y: line.y1 ?? 0 },
|
|
63461
|
-
{ x: line.x2 ?? 0, y: line.y2 ?? 0 }
|
|
63462
|
-
]
|
|
63463
|
-
});
|
|
63464
|
-
}
|
|
63465
|
-
for (const path7 of paths) {
|
|
63466
|
-
if (path7.points && path7.points.length > 0) {
|
|
63467
|
-
primitives2.push({
|
|
63468
|
-
type: "path",
|
|
63469
|
-
points: path7.points,
|
|
63470
|
-
fill: path7.is_filled ?? false,
|
|
63471
|
-
fillColor: path7.fill_color
|
|
63472
|
-
});
|
|
63473
|
-
}
|
|
63474
|
-
}
|
|
63475
|
-
const symbolPorts = ports.map((port, index) => ({
|
|
63476
|
-
x: port.center?.x ?? 0,
|
|
63477
|
-
y: port.center?.y ?? 0,
|
|
63478
|
-
labels: [port.display_pin_label || `${port.pin_number || index + 1}`],
|
|
63479
|
-
pinNumber: port.pin_number || index + 1,
|
|
63480
|
-
facingDirection: port.facing_direction
|
|
63481
|
-
}));
|
|
63482
|
-
symbolPorts.sort((a, b) => a.pinNumber - b.pinNumber);
|
|
63483
|
-
return {
|
|
63484
|
-
center: schematicSymbol.center || { x: 0, y: 0 },
|
|
63485
|
-
size: schematicSymbol.size || { width: 1, height: 1 },
|
|
63486
|
-
primitives: primitives2,
|
|
63487
|
-
ports: symbolPorts
|
|
63488
|
-
};
|
|
63489
|
-
}
|
|
63490
63872
|
createLibrarySymbolForNetLabel({
|
|
63491
63873
|
netLabel,
|
|
63492
63874
|
isPower,
|
|
@@ -63512,41 +63894,10 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
63512
63894
|
}
|
|
63513
63895
|
getSymbolData(symbolName, schematicComponent) {
|
|
63514
63896
|
if (symbolName.startsWith("generic_chip_")) {
|
|
63515
|
-
return
|
|
63897
|
+
return createGenericChipSymbolData(schematicComponent, this.ctx.db);
|
|
63516
63898
|
}
|
|
63517
63899
|
return symbols2[symbolName] || null;
|
|
63518
63900
|
}
|
|
63519
|
-
createGenericChipSymbolData(schematicComp, db) {
|
|
63520
|
-
const schematicPorts = db.schematic_port.list().filter((p) => p.schematic_component_id === schematicComp.schematic_component_id).sort((a, b) => (a.pin_number || 0) - (b.pin_number || 0));
|
|
63521
|
-
const width = schematicComp.size?.width || 1.5;
|
|
63522
|
-
const height = schematicComp.size?.height || 1;
|
|
63523
|
-
const boxPath = {
|
|
63524
|
-
type: "path",
|
|
63525
|
-
points: [
|
|
63526
|
-
{ x: -width / 2, y: -height / 2 },
|
|
63527
|
-
{ x: width / 2, y: -height / 2 },
|
|
63528
|
-
{ x: width / 2, y: height / 2 },
|
|
63529
|
-
{ x: -width / 2, y: height / 2 },
|
|
63530
|
-
{ x: -width / 2, y: -height / 2 }
|
|
63531
|
-
]
|
|
63532
|
-
};
|
|
63533
|
-
const ports = schematicPorts.map((port) => {
|
|
63534
|
-
const portX = port.center.x - schematicComp.center.x;
|
|
63535
|
-
const portY = port.center.y - schematicComp.center.y;
|
|
63536
|
-
return {
|
|
63537
|
-
x: portX,
|
|
63538
|
-
y: portY,
|
|
63539
|
-
labels: [port.display_pin_label || `${port.pin_number || 1}`],
|
|
63540
|
-
pinNumber: port.pin_number || 1
|
|
63541
|
-
};
|
|
63542
|
-
});
|
|
63543
|
-
return {
|
|
63544
|
-
center: { x: 0, y: 0 },
|
|
63545
|
-
primitives: [boxPath],
|
|
63546
|
-
ports,
|
|
63547
|
-
size: { width, height }
|
|
63548
|
-
};
|
|
63549
|
-
}
|
|
63550
63901
|
createLibrarySymbol({
|
|
63551
63902
|
libId,
|
|
63552
63903
|
symbolData,
|
|
@@ -63558,7 +63909,7 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
63558
63909
|
footprintRef = "",
|
|
63559
63910
|
referencePrefix
|
|
63560
63911
|
}) {
|
|
63561
|
-
const symbol = new
|
|
63912
|
+
const symbol = new SchematicSymbol4({
|
|
63562
63913
|
libraryId: libId,
|
|
63563
63914
|
excludeFromSim: false,
|
|
63564
63915
|
inBom: true,
|
|
@@ -63570,7 +63921,7 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
63570
63921
|
const pinNames = new SymbolPinNames;
|
|
63571
63922
|
pinNames.offset = isChip ? 1.27 : 0;
|
|
63572
63923
|
symbol._sxPinNames = pinNames;
|
|
63573
|
-
|
|
63924
|
+
addSymbolProperties({
|
|
63574
63925
|
symbol,
|
|
63575
63926
|
libId,
|
|
63576
63927
|
description,
|
|
@@ -63579,87 +63930,25 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
63579
63930
|
footprintRef,
|
|
63580
63931
|
referencePrefix
|
|
63581
63932
|
});
|
|
63582
|
-
const drawingSymbol =
|
|
63933
|
+
const drawingSymbol = createDrawingSubsymbol({
|
|
63583
63934
|
libId,
|
|
63584
63935
|
symbolData,
|
|
63585
|
-
isChip
|
|
63936
|
+
isChip,
|
|
63937
|
+
c2kMatSchScale: this.ctx.c2kMatSch?.a ?? 15
|
|
63586
63938
|
});
|
|
63587
63939
|
symbol.subSymbols.push(drawingSymbol);
|
|
63588
|
-
const pinSymbol =
|
|
63940
|
+
const pinSymbol = createPinSubsymbol({
|
|
63589
63941
|
libId,
|
|
63590
63942
|
symbolData,
|
|
63591
63943
|
isChip,
|
|
63592
|
-
schematicComponent
|
|
63944
|
+
schematicComponent,
|
|
63945
|
+
schematicPorts: this.ctx.db.schematic_port.list(),
|
|
63946
|
+
c2kMatSchScale: this.ctx.c2kMatSch?.a ?? 15
|
|
63593
63947
|
});
|
|
63594
63948
|
symbol.subSymbols.push(pinSymbol);
|
|
63595
63949
|
symbol._sxEmbeddedFonts = new EmbeddedFonts(false);
|
|
63596
63950
|
return symbol;
|
|
63597
63951
|
}
|
|
63598
|
-
addSymbolProperties({
|
|
63599
|
-
symbol,
|
|
63600
|
-
libId,
|
|
63601
|
-
description,
|
|
63602
|
-
keywords,
|
|
63603
|
-
fpFilters,
|
|
63604
|
-
footprintRef = "",
|
|
63605
|
-
referencePrefix
|
|
63606
|
-
}) {
|
|
63607
|
-
const refPrefix = referencePrefix || libId.split(":")[1]?.[0] || "U";
|
|
63608
|
-
const properties = [
|
|
63609
|
-
{
|
|
63610
|
-
key: "Reference",
|
|
63611
|
-
value: refPrefix,
|
|
63612
|
-
id: 0,
|
|
63613
|
-
at: [2.032, 0, 90],
|
|
63614
|
-
hide: false
|
|
63615
|
-
},
|
|
63616
|
-
{ key: "Value", value: refPrefix, id: 1, at: [0, 0, 90], hide: false },
|
|
63617
|
-
{
|
|
63618
|
-
key: "Footprint",
|
|
63619
|
-
value: footprintRef,
|
|
63620
|
-
id: 2,
|
|
63621
|
-
at: [-1.778, 0, 90],
|
|
63622
|
-
hide: true
|
|
63623
|
-
},
|
|
63624
|
-
{
|
|
63625
|
-
key: "Datasheet",
|
|
63626
|
-
value: "~",
|
|
63627
|
-
id: 3,
|
|
63628
|
-
at: [0, 0, 0],
|
|
63629
|
-
hide: true
|
|
63630
|
-
},
|
|
63631
|
-
{
|
|
63632
|
-
key: "Description",
|
|
63633
|
-
value: description,
|
|
63634
|
-
id: 4,
|
|
63635
|
-
at: [0, 0, 0],
|
|
63636
|
-
hide: true
|
|
63637
|
-
},
|
|
63638
|
-
{
|
|
63639
|
-
key: "ki_keywords",
|
|
63640
|
-
value: keywords,
|
|
63641
|
-
id: 5,
|
|
63642
|
-
at: [0, 0, 0],
|
|
63643
|
-
hide: true
|
|
63644
|
-
},
|
|
63645
|
-
{
|
|
63646
|
-
key: "ki_fp_filters",
|
|
63647
|
-
value: fpFilters,
|
|
63648
|
-
id: 6,
|
|
63649
|
-
at: [0, 0, 0],
|
|
63650
|
-
hide: true
|
|
63651
|
-
}
|
|
63652
|
-
];
|
|
63653
|
-
for (const prop of properties) {
|
|
63654
|
-
symbol.properties.push(new SymbolProperty({
|
|
63655
|
-
key: prop.key,
|
|
63656
|
-
value: prop.value,
|
|
63657
|
-
id: prop.id,
|
|
63658
|
-
at: prop.at,
|
|
63659
|
-
effects: this.createTextEffects(1.27, prop.hide)
|
|
63660
|
-
}));
|
|
63661
|
-
}
|
|
63662
|
-
}
|
|
63663
63952
|
getDescription(sourceComp) {
|
|
63664
63953
|
if (sourceComp?.ftype === "simple_resistor")
|
|
63665
63954
|
return "Resistor";
|
|
@@ -63690,213 +63979,6 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
63690
63979
|
return "*";
|
|
63691
63980
|
return "*";
|
|
63692
63981
|
}
|
|
63693
|
-
createDrawingSubsymbol({
|
|
63694
|
-
libId,
|
|
63695
|
-
symbolData,
|
|
63696
|
-
isChip
|
|
63697
|
-
}) {
|
|
63698
|
-
const drawingSymbol = new SchematicSymbol({
|
|
63699
|
-
libraryId: `${libId.split(":")[1]}_0_1`
|
|
63700
|
-
});
|
|
63701
|
-
const GRID_ALIGNED_SCALE = 15.24;
|
|
63702
|
-
const standardScale = this.ctx.c2kMatSch?.a || 15;
|
|
63703
|
-
const symbolScale = isChip ? standardScale : GRID_ALIGNED_SCALE;
|
|
63704
|
-
for (const primitive of symbolData.primitives || []) {
|
|
63705
|
-
if (primitive.type === "path" && primitive.points) {
|
|
63706
|
-
const fillType = isChip || primitive.fill ? "background" : "none";
|
|
63707
|
-
const polyline = this.createPolylineFromPoints({
|
|
63708
|
-
points: primitive.points,
|
|
63709
|
-
scale: symbolScale,
|
|
63710
|
-
center: symbolData.center,
|
|
63711
|
-
fillType
|
|
63712
|
-
});
|
|
63713
|
-
drawingSymbol.polylines.push(polyline);
|
|
63714
|
-
} else if (primitive.type === "circle") {
|
|
63715
|
-
const circle = this.createCircleFromPrimitive({
|
|
63716
|
-
primitive,
|
|
63717
|
-
scale: symbolScale,
|
|
63718
|
-
center: symbolData.center
|
|
63719
|
-
});
|
|
63720
|
-
drawingSymbol.circles.push(circle);
|
|
63721
|
-
}
|
|
63722
|
-
}
|
|
63723
|
-
return drawingSymbol;
|
|
63724
|
-
}
|
|
63725
|
-
createPolylineFromPoints({
|
|
63726
|
-
points,
|
|
63727
|
-
scale: scale4,
|
|
63728
|
-
center,
|
|
63729
|
-
fillType
|
|
63730
|
-
}) {
|
|
63731
|
-
const polyline = new SymbolPolyline;
|
|
63732
|
-
const cx = center?.x ?? 0;
|
|
63733
|
-
const cy = center?.y ?? 0;
|
|
63734
|
-
const scaleMatrix = createScaleMatrix(scale4, scale4);
|
|
63735
|
-
const xyPoints = points.map((p) => {
|
|
63736
|
-
const translated = applyToPoint(scaleMatrix, { x: p.x - cx, y: p.y - cy });
|
|
63737
|
-
return new Xy(translated.x, translated.y);
|
|
63738
|
-
});
|
|
63739
|
-
const pts = new Pts(xyPoints);
|
|
63740
|
-
polyline.points = pts;
|
|
63741
|
-
const stroke = new Stroke;
|
|
63742
|
-
stroke.width = 0.254;
|
|
63743
|
-
stroke.type = "default";
|
|
63744
|
-
polyline.stroke = stroke;
|
|
63745
|
-
const fill = new SymbolPolylineFill;
|
|
63746
|
-
fill.type = fillType;
|
|
63747
|
-
polyline.fill = fill;
|
|
63748
|
-
return polyline;
|
|
63749
|
-
}
|
|
63750
|
-
createCircleFromPrimitive({
|
|
63751
|
-
primitive,
|
|
63752
|
-
scale: scale4,
|
|
63753
|
-
center
|
|
63754
|
-
}) {
|
|
63755
|
-
const circle = new SymbolCircle;
|
|
63756
|
-
const cx = center?.x ?? 0;
|
|
63757
|
-
const cy = center?.y ?? 0;
|
|
63758
|
-
const scaleMatrix = createScaleMatrix(scale4, scale4);
|
|
63759
|
-
const scaledPos = applyToPoint(scaleMatrix, {
|
|
63760
|
-
x: primitive.x - cx,
|
|
63761
|
-
y: primitive.y - cy
|
|
63762
|
-
});
|
|
63763
|
-
const c = circle;
|
|
63764
|
-
c._sxCenter = new SymbolCircleCenter(scaledPos.x, scaledPos.y);
|
|
63765
|
-
c._sxRadius = new SymbolCircleRadius(primitive.radius * scale4);
|
|
63766
|
-
const stroke = new Stroke;
|
|
63767
|
-
stroke.width = 0.254;
|
|
63768
|
-
stroke.type = "default";
|
|
63769
|
-
c._sxStroke = stroke;
|
|
63770
|
-
const fill = new SymbolCircleFill;
|
|
63771
|
-
fill.type = primitive.fill ? "background" : "none";
|
|
63772
|
-
c._sxFill = fill;
|
|
63773
|
-
return circle;
|
|
63774
|
-
}
|
|
63775
|
-
createPinSubsymbol({
|
|
63776
|
-
libId,
|
|
63777
|
-
symbolData,
|
|
63778
|
-
isChip,
|
|
63779
|
-
schematicComponent
|
|
63780
|
-
}) {
|
|
63781
|
-
const pinSymbol = new SchematicSymbol({
|
|
63782
|
-
libraryId: `${libId.split(":")[1]}_1_1`
|
|
63783
|
-
});
|
|
63784
|
-
for (let i = 0;i < (symbolData.ports?.length || 0); i++) {
|
|
63785
|
-
const port = symbolData.ports[i];
|
|
63786
|
-
const pin = new SymbolPin;
|
|
63787
|
-
pin.pinElectricalType = "passive";
|
|
63788
|
-
pin.pinGraphicStyle = "line";
|
|
63789
|
-
const { x, y, angle } = this.calculatePinPosition(port, symbolData.center, symbolData.size, isChip, i, schematicComponent);
|
|
63790
|
-
pin.at = [x, y, angle];
|
|
63791
|
-
const CHIP_PIN_LENGTH = 6;
|
|
63792
|
-
const CUSTOM_SYMBOL_PIN_LENGTH = 2.54;
|
|
63793
|
-
pin.length = isChip ? CHIP_PIN_LENGTH : CUSTOM_SYMBOL_PIN_LENGTH;
|
|
63794
|
-
const nameFont = new TextEffectsFont;
|
|
63795
|
-
nameFont.size = { height: 1.27, width: 1.27 };
|
|
63796
|
-
const nameEffects = new TextEffects({ font: nameFont });
|
|
63797
|
-
const pinName = port.labels?.[0] || "~";
|
|
63798
|
-
pin._sxName = new SymbolPinName({ value: pinName, effects: nameEffects });
|
|
63799
|
-
const numFont = new TextEffectsFont;
|
|
63800
|
-
numFont.size = { height: 1.27, width: 1.27 };
|
|
63801
|
-
const numEffects = new TextEffects({ font: numFont });
|
|
63802
|
-
const pinNum = port.pinNumber?.toString() || `${i + 1}`;
|
|
63803
|
-
pin._sxNumber = new SymbolPinNumber({
|
|
63804
|
-
value: pinNum,
|
|
63805
|
-
effects: numEffects
|
|
63806
|
-
});
|
|
63807
|
-
pinSymbol.pins.push(pin);
|
|
63808
|
-
}
|
|
63809
|
-
return pinSymbol;
|
|
63810
|
-
}
|
|
63811
|
-
calculatePinPosition(port, center, size, isChip, portIndex, schematicComponent) {
|
|
63812
|
-
const GRID_ALIGNED_SCALE = 15.24;
|
|
63813
|
-
const standardScale = this.ctx.c2kMatSch?.a || 15;
|
|
63814
|
-
const symbolScale = isChip ? standardScale : GRID_ALIGNED_SCALE;
|
|
63815
|
-
let portX = port.x ?? 0;
|
|
63816
|
-
let portY = port.y ?? 0;
|
|
63817
|
-
let usingCircuitJsonPort = false;
|
|
63818
|
-
if (isChip && portIndex !== undefined && schematicComponent) {
|
|
63819
|
-
const schematicPorts = this.ctx.db.schematic_port.list().filter((p) => p.schematic_component_id === schematicComponent.schematic_component_id).sort((a, b) => (a.pin_number || 0) - (b.pin_number || 0));
|
|
63820
|
-
if (schematicPorts[portIndex]) {
|
|
63821
|
-
const schPort = schematicPorts[portIndex];
|
|
63822
|
-
portX = schPort.center.x - schematicComponent.center.x;
|
|
63823
|
-
portY = schPort.center.y - schematicComponent.center.y;
|
|
63824
|
-
usingCircuitJsonPort = true;
|
|
63825
|
-
}
|
|
63826
|
-
}
|
|
63827
|
-
let dx;
|
|
63828
|
-
let dy;
|
|
63829
|
-
if (usingCircuitJsonPort) {
|
|
63830
|
-
dx = portX;
|
|
63831
|
-
dy = portY;
|
|
63832
|
-
} else {
|
|
63833
|
-
const cx = center?.x ?? 0;
|
|
63834
|
-
const cy = center?.y ?? 0;
|
|
63835
|
-
dx = portX - cx;
|
|
63836
|
-
dy = portY - cy;
|
|
63837
|
-
}
|
|
63838
|
-
const scaleMatrix = createScaleMatrix(symbolScale, symbolScale);
|
|
63839
|
-
const scaled = applyToPoint(scaleMatrix, { x: dx, y: dy });
|
|
63840
|
-
let isHorizontalPin;
|
|
63841
|
-
if (isChip && size) {
|
|
63842
|
-
const halfWidth = size.width / 2;
|
|
63843
|
-
const halfHeight = size.height / 2;
|
|
63844
|
-
const normalizedDx = Math.abs(dx) / halfWidth;
|
|
63845
|
-
const normalizedDy = Math.abs(dy) / halfHeight;
|
|
63846
|
-
isHorizontalPin = normalizedDx > normalizedDy;
|
|
63847
|
-
} else {
|
|
63848
|
-
isHorizontalPin = Math.abs(dx) > Math.abs(dy);
|
|
63849
|
-
}
|
|
63850
|
-
let x = scaled.x;
|
|
63851
|
-
let y = scaled.y;
|
|
63852
|
-
const CHIP_PIN_LENGTH = 6;
|
|
63853
|
-
if (isChip && size) {
|
|
63854
|
-
const halfWidth = size.width / 2 * symbolScale;
|
|
63855
|
-
const halfHeight = size.height / 2 * symbolScale;
|
|
63856
|
-
if (isHorizontalPin) {
|
|
63857
|
-
x = dx > 0 ? halfWidth : -halfWidth;
|
|
63858
|
-
y = dy * symbolScale;
|
|
63859
|
-
} else {
|
|
63860
|
-
x = dx * symbolScale;
|
|
63861
|
-
y = dy > 0 ? halfHeight : -halfHeight;
|
|
63862
|
-
}
|
|
63863
|
-
}
|
|
63864
|
-
let angle = 0;
|
|
63865
|
-
if (isHorizontalPin) {
|
|
63866
|
-
if (dx > 0) {
|
|
63867
|
-
angle = 180;
|
|
63868
|
-
if (isChip) {
|
|
63869
|
-
x = x + CHIP_PIN_LENGTH;
|
|
63870
|
-
}
|
|
63871
|
-
} else {
|
|
63872
|
-
angle = 0;
|
|
63873
|
-
if (isChip) {
|
|
63874
|
-
x = x - CHIP_PIN_LENGTH;
|
|
63875
|
-
}
|
|
63876
|
-
}
|
|
63877
|
-
} else {
|
|
63878
|
-
if (dy > 0) {
|
|
63879
|
-
angle = 270;
|
|
63880
|
-
if (isChip) {
|
|
63881
|
-
y = y + CHIP_PIN_LENGTH;
|
|
63882
|
-
}
|
|
63883
|
-
} else {
|
|
63884
|
-
angle = 90;
|
|
63885
|
-
if (isChip) {
|
|
63886
|
-
y = y - CHIP_PIN_LENGTH;
|
|
63887
|
-
}
|
|
63888
|
-
}
|
|
63889
|
-
}
|
|
63890
|
-
return { x, y, angle };
|
|
63891
|
-
}
|
|
63892
|
-
createTextEffects(size, hide) {
|
|
63893
|
-
const font = new TextEffectsFont;
|
|
63894
|
-
font.size = { height: size, width: size };
|
|
63895
|
-
return new TextEffects({
|
|
63896
|
-
font,
|
|
63897
|
-
hiddenText: hide
|
|
63898
|
-
});
|
|
63899
|
-
}
|
|
63900
63982
|
getOutput() {
|
|
63901
63983
|
if (!this.ctx.kicadSch) {
|
|
63902
63984
|
throw new Error("kicadSch is not initialized");
|
|
@@ -63919,12 +64001,12 @@ var AddSchematicSymbolsStage = class extends ConverterStage {
|
|
|
63919
64001
|
continue;
|
|
63920
64002
|
if (!this.ctx.c2kMatSch)
|
|
63921
64003
|
continue;
|
|
63922
|
-
const { x, y } =
|
|
64004
|
+
const { x, y } = applyToPoint5(this.ctx.c2kMatSch, {
|
|
63923
64005
|
x: schematicComponent.center.x,
|
|
63924
64006
|
y: schematicComponent.center.y
|
|
63925
64007
|
});
|
|
63926
64008
|
const uuid = crypto.randomUUID();
|
|
63927
|
-
const symbol = new
|
|
64009
|
+
const symbol = new SchematicSymbol5({
|
|
63928
64010
|
at: [x, y, 0],
|
|
63929
64011
|
unit: 1,
|
|
63930
64012
|
excludeFromSim: false,
|
|
@@ -63961,43 +64043,108 @@ var AddSchematicSymbolsStage = class extends ConverterStage {
|
|
|
63961
64043
|
symbol._sxLibId = symLibId;
|
|
63962
64044
|
const { reference, value, description } = this.getComponentMetadata(sourceComponent);
|
|
63963
64045
|
const { refTextPos, valTextPos } = this.getTextPositions(schematicComponent, { x, y });
|
|
64046
|
+
let symbolMetadata;
|
|
64047
|
+
if (schematicSymbolId) {
|
|
64048
|
+
const schSymEl = this.ctx.circuitJson.find((el) => el.type === "schematic_symbol" && el.schematic_symbol_id === schematicSymbolId);
|
|
64049
|
+
if (schSymEl && schSymEl.type === "schematic_symbol") {
|
|
64050
|
+
symbolMetadata = schSymEl.metadata?.kicad_symbol;
|
|
64051
|
+
}
|
|
64052
|
+
}
|
|
64053
|
+
const refMeta = symbolMetadata?.properties?.Reference;
|
|
63964
64054
|
const referenceProperty = new SymbolProperty2({
|
|
63965
64055
|
key: "Reference",
|
|
63966
|
-
value: reference,
|
|
64056
|
+
value: refMeta?.value ?? reference,
|
|
63967
64057
|
id: 0,
|
|
63968
64058
|
at: [refTextPos.x, refTextPos.y, 0],
|
|
63969
|
-
effects: this.createTextEffects(1.27, false)
|
|
64059
|
+
effects: this.createTextEffects(Number(refMeta?.effects?.font?.size?.x ?? 1.27), refMeta?.effects?.hide ?? false)
|
|
63970
64060
|
});
|
|
63971
64061
|
const hideValue = sourceComponent.ftype === "simple_chip";
|
|
64062
|
+
const valMeta = symbolMetadata?.properties?.Value;
|
|
63972
64063
|
const valueProperty = new SymbolProperty2({
|
|
63973
64064
|
key: "Value",
|
|
63974
|
-
value,
|
|
64065
|
+
value: valMeta?.value ?? value,
|
|
63975
64066
|
id: 1,
|
|
63976
64067
|
at: [valTextPos.x, valTextPos.y, 0],
|
|
63977
|
-
effects: this.createTextEffects(1.27, hideValue)
|
|
64068
|
+
effects: this.createTextEffects(Number(valMeta?.effects?.font?.size?.x ?? 1.27), valMeta?.effects?.hide ?? hideValue)
|
|
63978
64069
|
});
|
|
64070
|
+
const fpMeta = symbolMetadata?.properties?.Footprint;
|
|
63979
64071
|
const footprintProperty = new SymbolProperty2({
|
|
63980
64072
|
key: "Footprint",
|
|
63981
|
-
value: "",
|
|
64073
|
+
value: fpMeta?.value ?? "",
|
|
63982
64074
|
id: 2,
|
|
63983
64075
|
at: [x - 1.778, y, 90],
|
|
63984
|
-
effects: this.createTextEffects(1.27, true)
|
|
64076
|
+
effects: this.createTextEffects(1.27, fpMeta?.effects?.hide ?? true)
|
|
63985
64077
|
});
|
|
64078
|
+
const dsMeta = symbolMetadata?.properties?.Datasheet;
|
|
63986
64079
|
const datasheetProperty = new SymbolProperty2({
|
|
63987
64080
|
key: "Datasheet",
|
|
63988
|
-
value: "~",
|
|
64081
|
+
value: dsMeta?.value ?? "~",
|
|
63989
64082
|
id: 3,
|
|
63990
64083
|
at: [x, y, 0],
|
|
63991
|
-
effects: this.createTextEffects(1.27, true)
|
|
64084
|
+
effects: this.createTextEffects(1.27, dsMeta?.effects?.hide ?? true)
|
|
63992
64085
|
});
|
|
64086
|
+
const descMeta = symbolMetadata?.properties?.Description;
|
|
63993
64087
|
const descriptionProperty = new SymbolProperty2({
|
|
63994
64088
|
key: "Description",
|
|
63995
|
-
value: description,
|
|
64089
|
+
value: descMeta?.value ?? description,
|
|
63996
64090
|
id: 4,
|
|
63997
64091
|
at: [x, y, 0],
|
|
63998
|
-
effects: this.createTextEffects(1.27, true)
|
|
64092
|
+
effects: this.createTextEffects(1.27, descMeta?.effects?.hide ?? true)
|
|
63999
64093
|
});
|
|
64000
64094
|
symbol.properties.push(referenceProperty, valueProperty, footprintProperty, datasheetProperty, descriptionProperty);
|
|
64095
|
+
const kwMeta = symbolMetadata?.properties?.ki_keywords;
|
|
64096
|
+
if (kwMeta?.value) {
|
|
64097
|
+
const keywordsProperty = new SymbolProperty2({
|
|
64098
|
+
key: "ki_keywords",
|
|
64099
|
+
value: kwMeta.value,
|
|
64100
|
+
id: 5,
|
|
64101
|
+
at: [x, y, 0],
|
|
64102
|
+
effects: this.createTextEffects(1.27, kwMeta.effects?.hide ?? true)
|
|
64103
|
+
});
|
|
64104
|
+
symbol.properties.push(keywordsProperty);
|
|
64105
|
+
}
|
|
64106
|
+
const fpFilterMeta = symbolMetadata?.properties?.ki_fp_filters;
|
|
64107
|
+
if (fpFilterMeta?.value) {
|
|
64108
|
+
const fpFiltersProperty = new SymbolProperty2({
|
|
64109
|
+
key: "ki_fp_filters",
|
|
64110
|
+
value: fpFilterMeta.value,
|
|
64111
|
+
id: 6,
|
|
64112
|
+
at: [x, y, 0],
|
|
64113
|
+
effects: this.createTextEffects(1.27, fpFilterMeta.effects?.hide ?? true)
|
|
64114
|
+
});
|
|
64115
|
+
symbol.properties.push(fpFiltersProperty);
|
|
64116
|
+
}
|
|
64117
|
+
if (symbolMetadata) {
|
|
64118
|
+
if (symbolMetadata.inBom !== undefined) {
|
|
64119
|
+
symbol.inBom = symbolMetadata.inBom;
|
|
64120
|
+
}
|
|
64121
|
+
if (symbolMetadata.onBoard !== undefined) {
|
|
64122
|
+
symbol.onBoard = symbolMetadata.onBoard;
|
|
64123
|
+
}
|
|
64124
|
+
if (symbolMetadata.excludeFromSim !== undefined) {
|
|
64125
|
+
symbol.excludeFromSim = symbolMetadata.excludeFromSim;
|
|
64126
|
+
}
|
|
64127
|
+
if (symbolMetadata.pinNames) {
|
|
64128
|
+
const pinNames = new SymbolPinNames2;
|
|
64129
|
+
if (symbolMetadata.pinNames.offset !== undefined) {
|
|
64130
|
+
pinNames.offset = Number(symbolMetadata.pinNames.offset);
|
|
64131
|
+
}
|
|
64132
|
+
if (symbolMetadata.pinNames.hide !== undefined) {
|
|
64133
|
+
pinNames.hide = symbolMetadata.pinNames.hide;
|
|
64134
|
+
}
|
|
64135
|
+
symbol.pinNames = pinNames;
|
|
64136
|
+
}
|
|
64137
|
+
if (symbolMetadata.pinNumbers) {
|
|
64138
|
+
const pinNumbers = new SymbolPinNumbers2;
|
|
64139
|
+
if (symbolMetadata.pinNumbers.hide !== undefined) {
|
|
64140
|
+
pinNumbers.hide = symbolMetadata.pinNumbers.hide;
|
|
64141
|
+
}
|
|
64142
|
+
symbol.pinNumbers = pinNumbers;
|
|
64143
|
+
}
|
|
64144
|
+
if (symbolMetadata.embeddedFonts !== undefined) {
|
|
64145
|
+
symbol._sxEmbeddedFonts = new EmbeddedFonts2(symbolMetadata.embeddedFonts);
|
|
64146
|
+
}
|
|
64147
|
+
}
|
|
64001
64148
|
let schematicPorts = db.schematic_port.list().filter((p) => p.schematic_component_id === schematicComponent.schematic_component_id);
|
|
64002
64149
|
if (schematicSymbolId) {
|
|
64003
64150
|
const customSymbolPorts = schematicPorts.filter((p) => p.display_pin_label);
|
|
@@ -64034,7 +64181,7 @@ var AddSchematicSymbolsStage = class extends ConverterStage {
|
|
|
64034
64181
|
const schematicTexts = this.ctx.db.schematic_text?.list?.()?.filter((t) => t.schematic_component_id === schematicComponent.schematic_component_id) || [];
|
|
64035
64182
|
const refText = schematicTexts.find((t) => t.text && t.text.length > 0);
|
|
64036
64183
|
if (refText && this.ctx.c2kMatSch) {
|
|
64037
|
-
const refTextPos2 =
|
|
64184
|
+
const refTextPos2 = applyToPoint5(this.ctx.c2kMatSch, {
|
|
64038
64185
|
x: refText.position.x,
|
|
64039
64186
|
y: refText.position.y
|
|
64040
64187
|
});
|
|
@@ -64063,11 +64210,11 @@ var AddSchematicSymbolsStage = class extends ConverterStage {
|
|
|
64063
64210
|
const symbolCenter = symbol.center || { x: 0, y: 0 };
|
|
64064
64211
|
const isVertical = symbolName.includes("_down") || symbolName.includes("_up");
|
|
64065
64212
|
const horizontalTextOffset = isVertical ? 0.15 : 0;
|
|
64066
|
-
const refTextPos = refTextPrimitive && this.ctx.c2kMatSch ?
|
|
64213
|
+
const refTextPos = refTextPrimitive && this.ctx.c2kMatSch ? applyToPoint5(this.ctx.c2kMatSch, {
|
|
64067
64214
|
x: schematicComponent.center.x + (refTextPrimitive.x - symbolCenter.x) + horizontalTextOffset,
|
|
64068
64215
|
y: schematicComponent.center.y + (refTextPrimitive.y - symbolCenter.y)
|
|
64069
64216
|
}) : { x: symbolKicadPos.x, y: symbolKicadPos.y - 6 };
|
|
64070
|
-
const valTextPos = valTextPrimitive && this.ctx.c2kMatSch ?
|
|
64217
|
+
const valTextPos = valTextPrimitive && this.ctx.c2kMatSch ? applyToPoint5(this.ctx.c2kMatSch, {
|
|
64071
64218
|
x: schematicComponent.center.x + (valTextPrimitive.x - symbolCenter.x) + horizontalTextOffset,
|
|
64072
64219
|
y: schematicComponent.center.y + (valTextPrimitive.y - symbolCenter.y)
|
|
64073
64220
|
}) : { x: symbolKicadPos.x, y: symbolKicadPos.y + 6 };
|
|
@@ -64139,10 +64286,10 @@ var AddSchematicSymbolsStage = class extends ConverterStage {
|
|
|
64139
64286
|
};
|
|
64140
64287
|
}
|
|
64141
64288
|
createTextEffects(size, hide = false, justify) {
|
|
64142
|
-
const font = new
|
|
64289
|
+
const font = new TextEffectsFont4;
|
|
64143
64290
|
font.size = { height: size, width: size };
|
|
64144
64291
|
const justifyObj = justify ? new TextEffectsJustify({ horizontal: justify }) : undefined;
|
|
64145
|
-
const effects = new
|
|
64292
|
+
const effects = new TextEffects4({
|
|
64146
64293
|
font,
|
|
64147
64294
|
hiddenText: hide,
|
|
64148
64295
|
justify: justifyObj
|
|
@@ -64200,12 +64347,12 @@ var AddSchematicNetLabelsStage = class extends ConverterStage {
|
|
|
64200
64347
|
createSymbolFromNetLabel(netLabel, labelText, symbolName) {
|
|
64201
64348
|
if (!this.ctx.c2kMatSch)
|
|
64202
64349
|
return null;
|
|
64203
|
-
const { x, y } =
|
|
64350
|
+
const { x, y } = applyToPoint6(this.ctx.c2kMatSch, {
|
|
64204
64351
|
x: netLabel.anchor_position?.x ?? netLabel.center?.x ?? 0,
|
|
64205
64352
|
y: netLabel.anchor_position?.y ?? netLabel.center?.y ?? 0
|
|
64206
64353
|
});
|
|
64207
64354
|
const uuid = crypto.randomUUID();
|
|
64208
|
-
const symbol = new
|
|
64355
|
+
const symbol = new SchematicSymbol6({
|
|
64209
64356
|
at: [x, y, 0],
|
|
64210
64357
|
unit: 1,
|
|
64211
64358
|
excludeFromSim: false,
|
|
@@ -64275,7 +64422,7 @@ var AddSchematicNetLabelsStage = class extends ConverterStage {
|
|
|
64275
64422
|
createGlobalLabel(netLabel, labelText) {
|
|
64276
64423
|
if (!this.ctx.c2kMatSch || !this.ctx.kicadSch)
|
|
64277
64424
|
return null;
|
|
64278
|
-
const { x, y } =
|
|
64425
|
+
const { x, y } = applyToPoint6(this.ctx.c2kMatSch, {
|
|
64279
64426
|
x: netLabel.anchor_position?.x ?? netLabel.center?.x ?? 0,
|
|
64280
64427
|
y: netLabel.anchor_position?.y ?? netLabel.center?.y ?? 0
|
|
64281
64428
|
});
|
|
@@ -64308,9 +64455,9 @@ var AddSchematicNetLabelsStage = class extends ConverterStage {
|
|
|
64308
64455
|
return globalLabel;
|
|
64309
64456
|
}
|
|
64310
64457
|
createTextEffects(size, hide = false) {
|
|
64311
|
-
const font = new
|
|
64458
|
+
const font = new TextEffectsFont5;
|
|
64312
64459
|
font.size = { height: size, width: size };
|
|
64313
|
-
return new
|
|
64460
|
+
return new TextEffects5({
|
|
64314
64461
|
font,
|
|
64315
64462
|
hiddenText: hide
|
|
64316
64463
|
});
|
|
@@ -64354,11 +64501,11 @@ var AddSchematicTracesStage = class extends ConverterStage {
|
|
|
64354
64501
|
if (!this.ctx.c2kMatSch) {
|
|
64355
64502
|
throw new Error("Schematic transformation matrix not initialized in context");
|
|
64356
64503
|
}
|
|
64357
|
-
const from =
|
|
64504
|
+
const from = applyToPoint7(this.ctx.c2kMatSch, {
|
|
64358
64505
|
x: edge.from.x,
|
|
64359
64506
|
y: edge.from.y
|
|
64360
64507
|
});
|
|
64361
|
-
const to =
|
|
64508
|
+
const to = applyToPoint7(this.ctx.c2kMatSch, {
|
|
64362
64509
|
x: edge.to.x,
|
|
64363
64510
|
y: edge.to.y
|
|
64364
64511
|
});
|
|
@@ -64368,7 +64515,7 @@ var AddSchematicTracesStage = class extends ConverterStage {
|
|
|
64368
64515
|
const y2 = to.y;
|
|
64369
64516
|
const pts = new Pts2([new Xy2(x1, y1), new Xy2(x2, y2)]);
|
|
64370
64517
|
wire.points = pts;
|
|
64371
|
-
const stroke = new
|
|
64518
|
+
const stroke = new Stroke3;
|
|
64372
64519
|
stroke.width = 0;
|
|
64373
64520
|
stroke.type = "default";
|
|
64374
64521
|
wire.stroke = stroke;
|
|
@@ -64379,7 +64526,7 @@ var AddSchematicTracesStage = class extends ConverterStage {
|
|
|
64379
64526
|
if (!this.ctx.c2kMatSch) {
|
|
64380
64527
|
throw new Error("Schematic transformation matrix not initialized in context");
|
|
64381
64528
|
}
|
|
64382
|
-
const { x, y } =
|
|
64529
|
+
const { x, y } = applyToPoint7(this.ctx.c2kMatSch, {
|
|
64383
64530
|
x: junction.x,
|
|
64384
64531
|
y: junction.y
|
|
64385
64532
|
});
|
|
@@ -64501,7 +64648,7 @@ var CircuitJsonToKicadSchConverter = class {
|
|
|
64501
64648
|
generatorVersion: "0.0.1"
|
|
64502
64649
|
}),
|
|
64503
64650
|
schematicPaperSize: paperSize,
|
|
64504
|
-
c2kMatSch:
|
|
64651
|
+
c2kMatSch: compose2(translate2(KICAD_CENTER_X, KICAD_CENTER_Y), scale(CIRCUIT_JSON_SCALE_FACTOR, -CIRCUIT_JSON_SCALE_FACTOR), translate2(-center.x, -center.y))
|
|
64505
64652
|
};
|
|
64506
64653
|
this.pipeline = [
|
|
64507
64654
|
new InitializeSchematicStage(circuitJson, this.ctx),
|
|
@@ -64647,6 +64794,137 @@ function generateDeterministicUuid(data) {
|
|
|
64647
64794
|
const hash = simpleHash(data);
|
|
64648
64795
|
return `${hash.slice(0, 8)}-${hash.slice(8, 12)}-${hash.slice(12, 16)}-${hash.slice(16, 20)}-${hash.slice(20, 32)}`;
|
|
64649
64796
|
}
|
|
64797
|
+
function createTextEffects2(metadataEffects) {
|
|
64798
|
+
const font = new TextEffectsFont6;
|
|
64799
|
+
if (metadataEffects?.font?.size) {
|
|
64800
|
+
font.size = {
|
|
64801
|
+
width: Number(metadataEffects.font.size.x),
|
|
64802
|
+
height: Number(metadataEffects.font.size.y)
|
|
64803
|
+
};
|
|
64804
|
+
} else {
|
|
64805
|
+
font.size = { width: 1.27, height: 1.27 };
|
|
64806
|
+
}
|
|
64807
|
+
if (metadataEffects?.font?.thickness !== undefined) {
|
|
64808
|
+
font.thickness = Number(metadataEffects.font.thickness);
|
|
64809
|
+
} else {
|
|
64810
|
+
font.thickness = 0.15;
|
|
64811
|
+
}
|
|
64812
|
+
return new TextEffects6({ font });
|
|
64813
|
+
}
|
|
64814
|
+
function applyMetadataToFootprint(footprint, metadata, componentName) {
|
|
64815
|
+
if (metadata.properties) {
|
|
64816
|
+
const newProperties = [];
|
|
64817
|
+
const refMeta = metadata.properties.Reference;
|
|
64818
|
+
newProperties.push(new Property({
|
|
64819
|
+
key: "Reference",
|
|
64820
|
+
value: refMeta?.value ?? componentName,
|
|
64821
|
+
position: refMeta?.at ? [
|
|
64822
|
+
Number(refMeta.at.x),
|
|
64823
|
+
Number(refMeta.at.y),
|
|
64824
|
+
Number(refMeta.at.rotation ?? 0)
|
|
64825
|
+
] : [0, -3, 0],
|
|
64826
|
+
layer: refMeta?.layer ?? "F.SilkS",
|
|
64827
|
+
uuid: generateDeterministicUuid(`${componentName}-property-Reference`),
|
|
64828
|
+
effects: createTextEffects2(refMeta?.effects),
|
|
64829
|
+
hidden: refMeta?.hide
|
|
64830
|
+
}));
|
|
64831
|
+
const valMeta = metadata.properties.Value;
|
|
64832
|
+
const valueText = valMeta?.value ?? metadata.footprintName ?? "";
|
|
64833
|
+
newProperties.push(new Property({
|
|
64834
|
+
key: "Value",
|
|
64835
|
+
value: valueText,
|
|
64836
|
+
position: valMeta?.at ? [
|
|
64837
|
+
Number(valMeta.at.x),
|
|
64838
|
+
Number(valMeta.at.y),
|
|
64839
|
+
Number(valMeta.at.rotation ?? 0)
|
|
64840
|
+
] : [0, 3, 0],
|
|
64841
|
+
layer: valMeta?.layer ?? "F.Fab",
|
|
64842
|
+
uuid: generateDeterministicUuid(`${componentName}-property-Value`),
|
|
64843
|
+
effects: createTextEffects2(valMeta?.effects),
|
|
64844
|
+
hidden: valMeta?.hide
|
|
64845
|
+
}));
|
|
64846
|
+
const dsMeta = metadata.properties.Datasheet;
|
|
64847
|
+
newProperties.push(new Property({
|
|
64848
|
+
key: "Datasheet",
|
|
64849
|
+
value: dsMeta?.value ?? "",
|
|
64850
|
+
position: dsMeta?.at ? [
|
|
64851
|
+
Number(dsMeta.at.x),
|
|
64852
|
+
Number(dsMeta.at.y),
|
|
64853
|
+
Number(dsMeta.at.rotation ?? 0)
|
|
64854
|
+
] : [0, 0, 0],
|
|
64855
|
+
layer: dsMeta?.layer ?? "F.Fab",
|
|
64856
|
+
uuid: generateDeterministicUuid(`${componentName}-property-Datasheet`),
|
|
64857
|
+
effects: createTextEffects2(dsMeta?.effects),
|
|
64858
|
+
hidden: dsMeta?.hide ?? true
|
|
64859
|
+
}));
|
|
64860
|
+
const descMeta = metadata.properties.Description;
|
|
64861
|
+
newProperties.push(new Property({
|
|
64862
|
+
key: "Description",
|
|
64863
|
+
value: descMeta?.value ?? "",
|
|
64864
|
+
position: descMeta?.at ? [
|
|
64865
|
+
Number(descMeta.at.x),
|
|
64866
|
+
Number(descMeta.at.y),
|
|
64867
|
+
Number(descMeta.at.rotation ?? 0)
|
|
64868
|
+
] : [0, 0, 0],
|
|
64869
|
+
layer: descMeta?.layer ?? "F.Fab",
|
|
64870
|
+
uuid: generateDeterministicUuid(`${componentName}-property-Description`),
|
|
64871
|
+
effects: createTextEffects2(descMeta?.effects),
|
|
64872
|
+
hidden: descMeta?.hide ?? true
|
|
64873
|
+
}));
|
|
64874
|
+
footprint.properties = newProperties;
|
|
64875
|
+
}
|
|
64876
|
+
if (metadata.attributes) {
|
|
64877
|
+
if (!footprint.attr) {
|
|
64878
|
+
footprint.attr = new FootprintAttr;
|
|
64879
|
+
}
|
|
64880
|
+
if (metadata.attributes.through_hole) {
|
|
64881
|
+
footprint.attr.type = "through_hole";
|
|
64882
|
+
} else if (metadata.attributes.smd) {
|
|
64883
|
+
footprint.attr.type = "smd";
|
|
64884
|
+
}
|
|
64885
|
+
if (metadata.attributes.exclude_from_pos_files !== undefined) {
|
|
64886
|
+
footprint.attr.excludeFromPosFiles = metadata.attributes.exclude_from_pos_files;
|
|
64887
|
+
}
|
|
64888
|
+
if (metadata.attributes.exclude_from_bom !== undefined) {
|
|
64889
|
+
footprint.attr.excludeFromBom = metadata.attributes.exclude_from_bom;
|
|
64890
|
+
}
|
|
64891
|
+
}
|
|
64892
|
+
if (metadata.footprintName) {
|
|
64893
|
+
footprint.libraryLink = metadata.footprintName;
|
|
64894
|
+
}
|
|
64895
|
+
if (metadata.layer) {
|
|
64896
|
+
footprint.layer = metadata.layer;
|
|
64897
|
+
}
|
|
64898
|
+
if (metadata.embeddedFonts !== undefined) {
|
|
64899
|
+
footprint.embeddedFonts = new EmbeddedFonts4(metadata.embeddedFonts);
|
|
64900
|
+
}
|
|
64901
|
+
if (metadata.model) {
|
|
64902
|
+
const model = new FootprintModel(metadata.model.path);
|
|
64903
|
+
if (metadata.model.offset) {
|
|
64904
|
+
model.offset = {
|
|
64905
|
+
x: Number(metadata.model.offset.x),
|
|
64906
|
+
y: Number(metadata.model.offset.y),
|
|
64907
|
+
z: Number(metadata.model.offset.z)
|
|
64908
|
+
};
|
|
64909
|
+
}
|
|
64910
|
+
if (metadata.model.scale) {
|
|
64911
|
+
model.scale = {
|
|
64912
|
+
x: Number(metadata.model.scale.x),
|
|
64913
|
+
y: Number(metadata.model.scale.y),
|
|
64914
|
+
z: Number(metadata.model.scale.z)
|
|
64915
|
+
};
|
|
64916
|
+
}
|
|
64917
|
+
if (metadata.model.rotate) {
|
|
64918
|
+
model.rotate = {
|
|
64919
|
+
x: Number(metadata.model.rotate.x),
|
|
64920
|
+
y: Number(metadata.model.rotate.y),
|
|
64921
|
+
z: Number(metadata.model.rotate.z)
|
|
64922
|
+
};
|
|
64923
|
+
}
|
|
64924
|
+
const existingModels = footprint.models || [];
|
|
64925
|
+
footprint.models = [model, ...existingModels];
|
|
64926
|
+
}
|
|
64927
|
+
}
|
|
64650
64928
|
function convertSilkscreenCircles(silkscreenCircles, componentCenter) {
|
|
64651
64929
|
const fpCircles = [];
|
|
64652
64930
|
for (const circle of silkscreenCircles) {
|
|
@@ -64661,7 +64939,7 @@ function convertSilkscreenCircles(silkscreenCircles, componentCenter) {
|
|
|
64661
64939
|
center: { x: relX, y: relY },
|
|
64662
64940
|
end: { x: relX + circle.radius, y: relY },
|
|
64663
64941
|
layer: kicadLayer,
|
|
64664
|
-
stroke: new
|
|
64942
|
+
stroke: new Stroke4,
|
|
64665
64943
|
fill: false
|
|
64666
64944
|
});
|
|
64667
64945
|
if (fpCircle.stroke) {
|
|
@@ -64686,7 +64964,7 @@ function convertCourtyardCircles(courtyardCircles, componentCenter) {
|
|
|
64686
64964
|
center: { x: relX, y: relY },
|
|
64687
64965
|
end: { x: relX + circle.radius, y: relY },
|
|
64688
64966
|
layer: kicadLayer,
|
|
64689
|
-
stroke: new
|
|
64967
|
+
stroke: new Stroke5,
|
|
64690
64968
|
fill: false
|
|
64691
64969
|
});
|
|
64692
64970
|
if (fpCircle.stroke) {
|
|
@@ -64713,7 +64991,7 @@ function convertFabricationNoteRects(fabRects, componentCenter) {
|
|
|
64713
64991
|
start: { x: relX - halfW, y: relY - halfH },
|
|
64714
64992
|
end: { x: relX + halfW, y: relY + halfH },
|
|
64715
64993
|
layer: kicadLayer,
|
|
64716
|
-
stroke: new
|
|
64994
|
+
stroke: new Stroke6,
|
|
64717
64995
|
fill: false
|
|
64718
64996
|
});
|
|
64719
64997
|
if (fpRect.stroke) {
|
|
@@ -64736,7 +65014,7 @@ function convertNoteRects(noteRects, componentCenter) {
|
|
|
64736
65014
|
start: { x: relX - halfW, y: relY - halfH },
|
|
64737
65015
|
end: { x: relX + halfW, y: relY + halfH },
|
|
64738
65016
|
layer: kicadLayer,
|
|
64739
|
-
stroke: new
|
|
65017
|
+
stroke: new Stroke7,
|
|
64740
65018
|
fill: false
|
|
64741
65019
|
});
|
|
64742
65020
|
if (fpRect.stroke) {
|
|
@@ -64763,7 +65041,7 @@ function convertCourtyardRects(courtyardRects, componentCenter) {
|
|
|
64763
65041
|
start: { x: relX - halfW, y: relY - halfH },
|
|
64764
65042
|
end: { x: relX + halfW, y: relY + halfH },
|
|
64765
65043
|
layer: kicadLayer,
|
|
64766
|
-
stroke: new
|
|
65044
|
+
stroke: new Stroke8,
|
|
64767
65045
|
fill: false
|
|
64768
65046
|
});
|
|
64769
65047
|
if (fpRect.stroke) {
|
|
@@ -64793,7 +65071,7 @@ function convertCourtyardOutlines(courtyardOutlines, componentCenter) {
|
|
|
64793
65071
|
fpPoly.points = new Pts3(xyPoints);
|
|
64794
65072
|
fpPoly.layer = kicadLayer;
|
|
64795
65073
|
fpPoly.fill = false;
|
|
64796
|
-
const stroke = new
|
|
65074
|
+
const stroke = new Stroke9;
|
|
64797
65075
|
stroke.width = 0.05;
|
|
64798
65076
|
stroke.type = "default";
|
|
64799
65077
|
fpPoly.stroke = stroke;
|
|
@@ -64812,7 +65090,7 @@ function createFpTextFromCircuitJson({
|
|
|
64812
65090
|
const relativeX = textElement.anchor_position.x - componentCenter.x;
|
|
64813
65091
|
const relativeY = -(textElement.anchor_position.y - componentCenter.y);
|
|
64814
65092
|
const rotationMatrix = componentRotation !== 0 ? rotate(componentRotation * Math.PI / 180) : identity();
|
|
64815
|
-
const rotatedPos =
|
|
65093
|
+
const rotatedPos = applyToPoint8(rotationMatrix, {
|
|
64816
65094
|
x: relativeX,
|
|
64817
65095
|
y: relativeY
|
|
64818
65096
|
});
|
|
@@ -64826,9 +65104,9 @@ function createFpTextFromCircuitJson({
|
|
|
64826
65104
|
};
|
|
64827
65105
|
const kicadLayer = layerMap[textElement.layer] || textElement.layer || "F.SilkS";
|
|
64828
65106
|
const fontSize = (textElement.font_size || 1) / 1.5;
|
|
64829
|
-
const font = new
|
|
65107
|
+
const font = new TextEffectsFont7;
|
|
64830
65108
|
font.size = { width: fontSize, height: fontSize };
|
|
64831
|
-
const textEffects = new
|
|
65109
|
+
const textEffects = new TextEffects7({
|
|
64832
65110
|
font
|
|
64833
65111
|
});
|
|
64834
65112
|
const rotation = textElement.ccw_rotation || 0;
|
|
@@ -64867,11 +65145,11 @@ function convertNoteTexts(noteTexts, componentCenter, componentRotation) {
|
|
|
64867
65145
|
const relX = textElement.anchor_position.x - componentCenter.x;
|
|
64868
65146
|
const relY = -(textElement.anchor_position.y - componentCenter.y);
|
|
64869
65147
|
const rotationMatrix = componentRotation !== 0 ? rotate2(componentRotation * Math.PI / 180) : identity2();
|
|
64870
|
-
const rotatedPos =
|
|
65148
|
+
const rotatedPos = applyToPoint9(rotationMatrix, { x: relX, y: relY });
|
|
64871
65149
|
const fontSize = textElement.font_size || 1;
|
|
64872
|
-
const font = new
|
|
65150
|
+
const font = new TextEffectsFont8;
|
|
64873
65151
|
font.size = { width: fontSize, height: fontSize };
|
|
64874
|
-
const textEffects = new
|
|
65152
|
+
const textEffects = new TextEffects8({ font });
|
|
64875
65153
|
const fpText = new FpText3({
|
|
64876
65154
|
type: "user",
|
|
64877
65155
|
text: textElement.text,
|
|
@@ -64888,7 +65166,7 @@ function create3DModelsFromCadComponent(cadComponent, componentCenter) {
|
|
|
64888
65166
|
const modelUrl = cadComponent.model_step_url || cadComponent.model_wrl_url;
|
|
64889
65167
|
if (!modelUrl)
|
|
64890
65168
|
return models;
|
|
64891
|
-
const model = new
|
|
65169
|
+
const model = new FootprintModel2(modelUrl);
|
|
64892
65170
|
if (cadComponent.position) {
|
|
64893
65171
|
model.offset = {
|
|
64894
65172
|
x: (cadComponent.position.x || 0) - componentCenter.x,
|
|
@@ -64930,8 +65208,8 @@ function createSmdPadFromCircuitJson({
|
|
|
64930
65208
|
} else {
|
|
64931
65209
|
throw new Error("Pad must have either x/y coordinates or points array");
|
|
64932
65210
|
}
|
|
64933
|
-
const cj2kicadMatrix =
|
|
64934
|
-
const rotatedPos =
|
|
65211
|
+
const cj2kicadMatrix = compose3(componentRotation !== 0 ? rotate3(componentRotation * Math.PI / 180) : { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }, scale2(1, -1), translate3(-componentCenter.x, -componentCenter.y));
|
|
65212
|
+
const rotatedPos = applyToPoint10(cj2kicadMatrix, {
|
|
64935
65213
|
x: padX,
|
|
64936
65214
|
y: padY
|
|
64937
65215
|
});
|
|
@@ -64952,9 +65230,9 @@ function createSmdPadFromCircuitJson({
|
|
|
64952
65230
|
];
|
|
64953
65231
|
} else if (pcbPad.shape === "polygon" && "points" in pcbPad) {
|
|
64954
65232
|
const points = pcbPad.points;
|
|
64955
|
-
const pointTransformMatrix =
|
|
65233
|
+
const pointTransformMatrix = compose3(scale2(1, -1), translate3(-padX, -padY));
|
|
64956
65234
|
const relativePoints = points.map((p) => {
|
|
64957
|
-
const transformed =
|
|
65235
|
+
const transformed = applyToPoint10(pointTransformMatrix, { x: p.x, y: p.y });
|
|
64958
65236
|
return new Xy4(transformed.x, transformed.y);
|
|
64959
65237
|
});
|
|
64960
65238
|
const grPoly = new PadPrimitiveGrPoly;
|
|
@@ -65031,7 +65309,7 @@ function createThruHolePadFromCircuitJson({
|
|
|
65031
65309
|
const relativeX = platedHole.x - componentCenter.x;
|
|
65032
65310
|
const relativeY = -(platedHole.y - componentCenter.y);
|
|
65033
65311
|
const rotationMatrix = componentRotation !== 0 ? rotate4(componentRotation * Math.PI / 180) : identity3();
|
|
65034
|
-
const rotatedPos =
|
|
65312
|
+
const rotatedPos = applyToPoint11(rotationMatrix, {
|
|
65035
65313
|
x: relativeX,
|
|
65036
65314
|
y: relativeY
|
|
65037
65315
|
});
|
|
@@ -65047,7 +65325,7 @@ function createThruHolePadFromCircuitJson({
|
|
|
65047
65325
|
y: platedHole.hole_offset_y ?? 0
|
|
65048
65326
|
};
|
|
65049
65327
|
if (rawOffset.x !== 0 || rawOffset.y !== 0) {
|
|
65050
|
-
const rotatedOffset =
|
|
65328
|
+
const rotatedOffset = applyToPoint11(rotationMatrix, {
|
|
65051
65329
|
x: -rawOffset.x,
|
|
65052
65330
|
y: rawOffset.y
|
|
65053
65331
|
});
|
|
@@ -65161,7 +65439,7 @@ function createNpthPadFromCircuitJson({
|
|
|
65161
65439
|
const relativeX = pcbHole.x - componentCenter.x;
|
|
65162
65440
|
const relativeY = -(pcbHole.y - componentCenter.y);
|
|
65163
65441
|
const rotationMatrix = componentRotation !== 0 ? rotate5(componentRotation * Math.PI / 180) : identity4();
|
|
65164
|
-
const rotatedPos =
|
|
65442
|
+
const rotatedPos = applyToPoint12(rotationMatrix, {
|
|
65165
65443
|
x: relativeX,
|
|
65166
65444
|
y: relativeY
|
|
65167
65445
|
});
|
|
@@ -65261,12 +65539,12 @@ var AddFootprintsStage = class extends ConverterStage {
|
|
|
65261
65539
|
const sourceComponent = component.source_component_id ? this.ctx.db.source_component.get(component.source_component_id) : null;
|
|
65262
65540
|
const cadComponent = this.getCadComponentForPcbComponent(component.pcb_component_id);
|
|
65263
65541
|
const footprintName = sourceComponent ? getKicadCompatibleComponentName(sourceComponent, cadComponent) : "Unknown";
|
|
65264
|
-
const transformedPos =
|
|
65542
|
+
const transformedPos = applyToPoint13(c2kMatPcb, {
|
|
65265
65543
|
x: component.center.x,
|
|
65266
65544
|
y: component.center.y
|
|
65267
65545
|
});
|
|
65268
65546
|
const footprintData = `footprint:${component.pcb_component_id}:${transformedPos.x},${transformedPos.y}`;
|
|
65269
|
-
const footprint = new
|
|
65547
|
+
const footprint = new Footprint2({
|
|
65270
65548
|
libraryLink: `tscircuit:${footprintName}`,
|
|
65271
65549
|
layer: "F.Cu",
|
|
65272
65550
|
at: [transformedPos.x, transformedPos.y, component.rotation || 0],
|
|
@@ -65315,6 +65593,10 @@ var AddFootprintsStage = class extends ConverterStage {
|
|
|
65315
65593
|
footprint.models = models;
|
|
65316
65594
|
}
|
|
65317
65595
|
}
|
|
65596
|
+
const footprintMetadata = component.metadata?.kicad_footprint;
|
|
65597
|
+
if (footprintMetadata && sourceComponent?.name) {
|
|
65598
|
+
applyMetadataToFootprint(footprint, footprintMetadata, sourceComponent.name);
|
|
65599
|
+
}
|
|
65318
65600
|
const footprints = kicadPcb.footprints;
|
|
65319
65601
|
footprints.push(footprint);
|
|
65320
65602
|
kicadPcb.footprints = footprints;
|
|
@@ -65375,11 +65657,11 @@ var AddTracesStage = class extends ConverterStage {
|
|
|
65375
65657
|
for (let i = 0;i < trace.route.length - 1; i++) {
|
|
65376
65658
|
const startPoint = trace.route[i];
|
|
65377
65659
|
const endPoint = trace.route[i + 1];
|
|
65378
|
-
const transformedStart =
|
|
65660
|
+
const transformedStart = applyToPoint14(c2kMatPcb, {
|
|
65379
65661
|
x: startPoint.x,
|
|
65380
65662
|
y: startPoint.y
|
|
65381
65663
|
});
|
|
65382
|
-
const transformedEnd =
|
|
65664
|
+
const transformedEnd = applyToPoint14(c2kMatPcb, {
|
|
65383
65665
|
x: endPoint.x,
|
|
65384
65666
|
y: endPoint.y
|
|
65385
65667
|
});
|
|
@@ -65458,7 +65740,7 @@ var AddViasStage = class extends ConverterStage {
|
|
|
65458
65740
|
return;
|
|
65459
65741
|
}
|
|
65460
65742
|
const via = this.pcbVias[this.viasProcessed];
|
|
65461
|
-
const transformedPos =
|
|
65743
|
+
const transformedPos = applyToPoint15(c2kMatPcb, {
|
|
65462
65744
|
x: via.x,
|
|
65463
65745
|
y: via.y
|
|
65464
65746
|
});
|
|
@@ -65527,7 +65809,7 @@ function createFabricationNoteTextFromCircuitJson({
|
|
|
65527
65809
|
if (!textElement.text || !textElement.anchor_position) {
|
|
65528
65810
|
return null;
|
|
65529
65811
|
}
|
|
65530
|
-
const transformedPos =
|
|
65812
|
+
const transformedPos = applyToPoint16(c2kMatPcb, {
|
|
65531
65813
|
x: textElement.anchor_position.x,
|
|
65532
65814
|
y: textElement.anchor_position.y
|
|
65533
65815
|
});
|
|
@@ -65537,7 +65819,7 @@ function createFabricationNoteTextFromCircuitJson({
|
|
|
65537
65819
|
};
|
|
65538
65820
|
const kicadLayer = layerMap[textElement.layer] || textElement.layer || "F.Fab";
|
|
65539
65821
|
const fontSize = (textElement.font_size || 1) / 1.5;
|
|
65540
|
-
const font = new
|
|
65822
|
+
const font = new TextEffectsFont9;
|
|
65541
65823
|
font.size = { width: fontSize, height: fontSize };
|
|
65542
65824
|
const justify = new TextEffectsJustify3;
|
|
65543
65825
|
const anchorAlignment = textElement.anchor_alignment || "center";
|
|
@@ -65561,7 +65843,7 @@ function createFabricationNoteTextFromCircuitJson({
|
|
|
65561
65843
|
case "center":
|
|
65562
65844
|
break;
|
|
65563
65845
|
}
|
|
65564
|
-
const textEffects = new
|
|
65846
|
+
const textEffects = new TextEffects9({
|
|
65565
65847
|
font
|
|
65566
65848
|
});
|
|
65567
65849
|
if (anchorAlignment !== "center") {
|
|
@@ -65583,7 +65865,7 @@ function createGrTextFromCircuitJson({
|
|
|
65583
65865
|
if (!textElement.text || !textElement.anchor_position) {
|
|
65584
65866
|
return null;
|
|
65585
65867
|
}
|
|
65586
|
-
const transformedPos =
|
|
65868
|
+
const transformedPos = applyToPoint17(c2kMatPcb, {
|
|
65587
65869
|
x: textElement.anchor_position.x,
|
|
65588
65870
|
y: textElement.anchor_position.y
|
|
65589
65871
|
});
|
|
@@ -65593,7 +65875,7 @@ function createGrTextFromCircuitJson({
|
|
|
65593
65875
|
};
|
|
65594
65876
|
const kicadLayer = layerMap[textElement.layer] || textElement.layer || "F.SilkS";
|
|
65595
65877
|
const fontSize = (textElement.font_size || 1) / 1.5;
|
|
65596
|
-
const font = new
|
|
65878
|
+
const font = new TextEffectsFont10;
|
|
65597
65879
|
font.size = { width: fontSize, height: fontSize };
|
|
65598
65880
|
const justify = new TextEffectsJustify4;
|
|
65599
65881
|
const anchorAlignment = textElement.anchor_alignment || "center";
|
|
@@ -65617,7 +65899,7 @@ function createGrTextFromCircuitJson({
|
|
|
65617
65899
|
case "center":
|
|
65618
65900
|
break;
|
|
65619
65901
|
}
|
|
65620
|
-
const textEffects = new
|
|
65902
|
+
const textEffects = new TextEffects10({
|
|
65621
65903
|
font
|
|
65622
65904
|
});
|
|
65623
65905
|
if (anchorAlignment !== "center") {
|
|
@@ -65651,11 +65933,11 @@ var AddGraphicsStage = class extends ConverterStage {
|
|
|
65651
65933
|
const endPoint = path7.route[i + 1];
|
|
65652
65934
|
if (!startPoint || !endPoint)
|
|
65653
65935
|
continue;
|
|
65654
|
-
const transformedStart =
|
|
65936
|
+
const transformedStart = applyToPoint18(c2kMatPcb, {
|
|
65655
65937
|
x: startPoint.x,
|
|
65656
65938
|
y: startPoint.y
|
|
65657
65939
|
});
|
|
65658
|
-
const transformedEnd =
|
|
65940
|
+
const transformedEnd = applyToPoint18(c2kMatPcb, {
|
|
65659
65941
|
x: endPoint.x,
|
|
65660
65942
|
y: endPoint.y
|
|
65661
65943
|
});
|
|
@@ -65719,7 +66001,7 @@ var AddGraphicsStage = class extends ConverterStage {
|
|
|
65719
66001
|
{ x: board.center.x - halfWidth, y: board.center.y + halfHeight }
|
|
65720
66002
|
];
|
|
65721
66003
|
}
|
|
65722
|
-
const transformedCorners = corners.map((corner) =>
|
|
66004
|
+
const transformedCorners = corners.map((corner) => applyToPoint18(c2kMatPcb, corner));
|
|
65723
66005
|
for (let i = 0;i < transformedCorners.length; i++) {
|
|
65724
66006
|
const start = transformedCorners[i];
|
|
65725
66007
|
const end = transformedCorners[(i + 1) % transformedCorners.length];
|
|
@@ -65761,7 +66043,7 @@ var CircuitJsonToKicadPcbConverter = class {
|
|
|
65761
66043
|
generator: "circuit-json-to-kicad",
|
|
65762
66044
|
generatorVersion: "0.0.1"
|
|
65763
66045
|
}),
|
|
65764
|
-
c2kMatPcb:
|
|
66046
|
+
c2kMatPcb: compose4(translate4(KICAD_PCB_CENTER_X, KICAD_PCB_CENTER_Y), scale3(CIRCUIT_JSON_TO_MM_SCALE, -CIRCUIT_JSON_TO_MM_SCALE))
|
|
65765
66047
|
};
|
|
65766
66048
|
this.pipeline = [
|
|
65767
66049
|
new InitializePcbStage(circuitJson, this.ctx),
|
|
@@ -65996,6 +66278,10 @@ var ExtractFootprintsStage = class extends ConverterStage {
|
|
|
65996
66278
|
if (sourceComp) {
|
|
65997
66279
|
const footprintName = getKicadCompatibleComponentName(sourceComp, cadComponent);
|
|
65998
66280
|
customNames.add(footprintName);
|
|
66281
|
+
const pcbComp = this.ctx.circuitJson.find((el) => el.type === "pcb_component" && el.source_component_id === cadComponent.source_component_id);
|
|
66282
|
+
if (pcbComp && pcbComp.type === "pcb_component" && pcbComp.metadata?.kicad_footprint?.footprintName) {
|
|
66283
|
+
customNames.add(pcbComp.metadata.kicad_footprint.footprintName);
|
|
66284
|
+
}
|
|
65999
66285
|
}
|
|
66000
66286
|
}
|
|
66001
66287
|
}
|
|
@@ -66057,10 +66343,10 @@ var ExtractFootprintsStage = class extends ConverterStage {
|
|
|
66057
66343
|
footprint.tags = "";
|
|
66058
66344
|
}
|
|
66059
66345
|
if (!footprint.embeddedFonts) {
|
|
66060
|
-
footprint.embeddedFonts = new
|
|
66346
|
+
footprint.embeddedFonts = new EmbeddedFonts5(false);
|
|
66061
66347
|
}
|
|
66062
66348
|
if (!footprint.attr) {
|
|
66063
|
-
const attr = new
|
|
66349
|
+
const attr = new FootprintAttr2;
|
|
66064
66350
|
const padTypes = (footprint.fpPads ?? []).map((pad) => pad.padType);
|
|
66065
66351
|
if (padTypes.some((padType) => padType.includes("thru_hole"))) {
|
|
66066
66352
|
attr.type = "through_hole";
|
|
@@ -66073,10 +66359,10 @@ var ExtractFootprintsStage = class extends ConverterStage {
|
|
|
66073
66359
|
footprint.path = undefined;
|
|
66074
66360
|
footprint.sheetfile = undefined;
|
|
66075
66361
|
footprint.sheetname = undefined;
|
|
66076
|
-
const defaultFont = new
|
|
66362
|
+
const defaultFont = new TextEffectsFont11;
|
|
66077
66363
|
defaultFont.size = { width: 1.27, height: 1.27 };
|
|
66078
66364
|
defaultFont.thickness = 0.15;
|
|
66079
|
-
const defaultEffects = new
|
|
66365
|
+
const defaultEffects = new TextEffects11({ font: defaultFont });
|
|
66080
66366
|
const fpPads = footprint.fpPads ?? [];
|
|
66081
66367
|
let minY = 0;
|
|
66082
66368
|
let maxY = 0;
|
|
@@ -66095,7 +66381,7 @@ var ExtractFootprintsStage = class extends ConverterStage {
|
|
|
66095
66381
|
const refY = minY - 0.5;
|
|
66096
66382
|
const valY = maxY + 0.5;
|
|
66097
66383
|
footprint.properties = [
|
|
66098
|
-
new
|
|
66384
|
+
new Property2({
|
|
66099
66385
|
key: "Reference",
|
|
66100
66386
|
value: "REF**",
|
|
66101
66387
|
position: [0, refY, 0],
|
|
@@ -66103,7 +66389,7 @@ var ExtractFootprintsStage = class extends ConverterStage {
|
|
|
66103
66389
|
uuid: generateDeterministicUuid(`${footprintName}-property-Reference`),
|
|
66104
66390
|
effects: defaultEffects
|
|
66105
66391
|
}),
|
|
66106
|
-
new
|
|
66392
|
+
new Property2({
|
|
66107
66393
|
key: "Value",
|
|
66108
66394
|
value: "Val**",
|
|
66109
66395
|
position: [0, valY, 0],
|
|
@@ -66111,7 +66397,7 @@ var ExtractFootprintsStage = class extends ConverterStage {
|
|
|
66111
66397
|
uuid: generateDeterministicUuid(`${footprintName}-property-Value`),
|
|
66112
66398
|
effects: defaultEffects
|
|
66113
66399
|
}),
|
|
66114
|
-
new
|
|
66400
|
+
new Property2({
|
|
66115
66401
|
key: "Datasheet",
|
|
66116
66402
|
value: "",
|
|
66117
66403
|
position: [0, 0, 0],
|
|
@@ -66120,7 +66406,7 @@ var ExtractFootprintsStage = class extends ConverterStage {
|
|
|
66120
66406
|
uuid: generateDeterministicUuid(`${footprintName}-property-Datasheet`),
|
|
66121
66407
|
effects: defaultEffects
|
|
66122
66408
|
}),
|
|
66123
|
-
new
|
|
66409
|
+
new Property2({
|
|
66124
66410
|
key: "Description",
|
|
66125
66411
|
value: "",
|
|
66126
66412
|
position: [0, 0, 0],
|
|
@@ -66156,7 +66442,7 @@ var ExtractFootprintsStage = class extends ConverterStage {
|
|
|
66156
66442
|
if (model.path) {
|
|
66157
66443
|
const modelFilename = getBasename(model.path);
|
|
66158
66444
|
const newPath = `../../3dmodels/${fpLibraryName}.3dshapes/${modelFilename}`;
|
|
66159
|
-
const newModel = new
|
|
66445
|
+
const newModel = new FootprintModel3(newPath);
|
|
66160
66446
|
if (model.offset)
|
|
66161
66447
|
newModel.offset = model.offset;
|
|
66162
66448
|
if (model.scale)
|
|
@@ -66348,8 +66634,8 @@ function renameKicadFootprint(params2) {
|
|
|
66348
66634
|
model3dSourcePaths: kicadFootprint.model3dSourcePaths
|
|
66349
66635
|
};
|
|
66350
66636
|
}
|
|
66351
|
-
function
|
|
66352
|
-
const font = new
|
|
66637
|
+
function createTextEffects3(metadataEffects) {
|
|
66638
|
+
const font = new TextEffectsFont12;
|
|
66353
66639
|
if (metadataEffects?.font?.size) {
|
|
66354
66640
|
font.size = {
|
|
66355
66641
|
width: Number(metadataEffects.font.size.x),
|
|
@@ -66363,12 +66649,12 @@ function createTextEffects(metadataEffects) {
|
|
|
66363
66649
|
} else {
|
|
66364
66650
|
font.thickness = 0.15;
|
|
66365
66651
|
}
|
|
66366
|
-
return new
|
|
66652
|
+
return new TextEffects12({ font });
|
|
66367
66653
|
}
|
|
66368
66654
|
function applyKicadFootprintMetadata(kicadModString, metadata, footprintName) {
|
|
66369
66655
|
try {
|
|
66370
66656
|
const parsed = parseKicadSexpr3(kicadModString);
|
|
66371
|
-
const footprint = parsed.find((node) => node instanceof
|
|
66657
|
+
const footprint = parsed.find((node) => node instanceof Footprint4);
|
|
66372
66658
|
if (!footprint) {
|
|
66373
66659
|
return kicadModString;
|
|
66374
66660
|
}
|
|
@@ -66385,7 +66671,7 @@ function applyKicadFootprintMetadata(kicadModString, metadata, footprintName) {
|
|
|
66385
66671
|
if (metadata.properties) {
|
|
66386
66672
|
const newProperties = [];
|
|
66387
66673
|
const refMeta = metadata.properties.Reference;
|
|
66388
|
-
newProperties.push(new
|
|
66674
|
+
newProperties.push(new Property3({
|
|
66389
66675
|
key: "Reference",
|
|
66390
66676
|
value: refMeta?.value ?? "REF**",
|
|
66391
66677
|
position: refMeta?.at ? [
|
|
@@ -66395,11 +66681,11 @@ function applyKicadFootprintMetadata(kicadModString, metadata, footprintName) {
|
|
|
66395
66681
|
] : [0, 0, 0],
|
|
66396
66682
|
layer: refMeta?.layer ?? "F.SilkS",
|
|
66397
66683
|
uuid: refMeta?.uuid ?? generateDeterministicUuid(`${footprintName}-property-Reference`),
|
|
66398
|
-
effects:
|
|
66684
|
+
effects: createTextEffects3(refMeta?.effects),
|
|
66399
66685
|
hidden: refMeta?.hide
|
|
66400
66686
|
}));
|
|
66401
66687
|
const valMeta = metadata.properties.Value;
|
|
66402
|
-
newProperties.push(new
|
|
66688
|
+
newProperties.push(new Property3({
|
|
66403
66689
|
key: "Value",
|
|
66404
66690
|
value: valMeta?.value ?? footprintName,
|
|
66405
66691
|
position: valMeta?.at ? [
|
|
@@ -66409,11 +66695,11 @@ function applyKicadFootprintMetadata(kicadModString, metadata, footprintName) {
|
|
|
66409
66695
|
] : [0, 0, 0],
|
|
66410
66696
|
layer: valMeta?.layer ?? "F.Fab",
|
|
66411
66697
|
uuid: valMeta?.uuid ?? generateDeterministicUuid(`${footprintName}-property-Value`),
|
|
66412
|
-
effects:
|
|
66698
|
+
effects: createTextEffects3(valMeta?.effects),
|
|
66413
66699
|
hidden: valMeta?.hide
|
|
66414
66700
|
}));
|
|
66415
66701
|
const dsMeta = metadata.properties.Datasheet;
|
|
66416
|
-
newProperties.push(new
|
|
66702
|
+
newProperties.push(new Property3({
|
|
66417
66703
|
key: "Datasheet",
|
|
66418
66704
|
value: dsMeta?.value ?? "",
|
|
66419
66705
|
position: dsMeta?.at ? [
|
|
@@ -66423,11 +66709,11 @@ function applyKicadFootprintMetadata(kicadModString, metadata, footprintName) {
|
|
|
66423
66709
|
] : [0, 0, 0],
|
|
66424
66710
|
layer: dsMeta?.layer ?? "F.Fab",
|
|
66425
66711
|
uuid: dsMeta?.uuid ?? generateDeterministicUuid(`${footprintName}-property-Datasheet`),
|
|
66426
|
-
effects:
|
|
66712
|
+
effects: createTextEffects3(dsMeta?.effects),
|
|
66427
66713
|
hidden: dsMeta?.hide ?? true
|
|
66428
66714
|
}));
|
|
66429
66715
|
const descMeta = metadata.properties.Description;
|
|
66430
|
-
newProperties.push(new
|
|
66716
|
+
newProperties.push(new Property3({
|
|
66431
66717
|
key: "Description",
|
|
66432
66718
|
value: descMeta?.value ?? "",
|
|
66433
66719
|
position: descMeta?.at ? [
|
|
@@ -66437,7 +66723,7 @@ function applyKicadFootprintMetadata(kicadModString, metadata, footprintName) {
|
|
|
66437
66723
|
] : [0, 0, 0],
|
|
66438
66724
|
layer: descMeta?.layer ?? "F.Fab",
|
|
66439
66725
|
uuid: descMeta?.uuid ?? generateDeterministicUuid(`${footprintName}-property-Description`),
|
|
66440
|
-
effects:
|
|
66726
|
+
effects: createTextEffects3(descMeta?.effects),
|
|
66441
66727
|
hidden: descMeta?.hide ?? true
|
|
66442
66728
|
}));
|
|
66443
66729
|
footprint.properties = newProperties;
|
|
@@ -66476,7 +66762,9 @@ function classifyFootprintsForComponent({
|
|
|
66476
66762
|
}) {
|
|
66477
66763
|
const { tscircuitComponentName, kicadFootprints } = extractedKicadComponent;
|
|
66478
66764
|
let hasAddedUserFootprint = false;
|
|
66479
|
-
const
|
|
66765
|
+
const builtComponent = ctx.builtTscircuitComponents.find((c) => c.tscircuitComponentName === tscircuitComponentName);
|
|
66766
|
+
const pcbComponent = builtComponent?.circuitJson.find((el) => el.type === "pcb_component");
|
|
66767
|
+
const metadata = pcbComponent?.metadata?.kicad_footprint;
|
|
66480
66768
|
for (const kicadFootprint of kicadFootprints) {
|
|
66481
66769
|
if (kicadFootprint.isBuiltin) {
|
|
66482
66770
|
addBuiltinFootprint({ ctx, kicadFootprint });
|
|
@@ -66600,16 +66888,16 @@ var toNumber = (value, fallback) => {
|
|
|
66600
66888
|
return fallback;
|
|
66601
66889
|
return parsed;
|
|
66602
66890
|
};
|
|
66603
|
-
var
|
|
66891
|
+
var createTextEffects4 = (effectsMeta, fallback) => {
|
|
66604
66892
|
if (!effectsMeta)
|
|
66605
66893
|
return fallback;
|
|
66606
|
-
const effects = new
|
|
66894
|
+
const effects = new TextEffects13({
|
|
66607
66895
|
font: fallback?.font,
|
|
66608
66896
|
justify: fallback?.justify,
|
|
66609
66897
|
hiddenText: fallback?.hiddenText ?? false
|
|
66610
66898
|
});
|
|
66611
66899
|
if (!effects.font) {
|
|
66612
|
-
const defaultFont = new
|
|
66900
|
+
const defaultFont = new TextEffectsFont13;
|
|
66613
66901
|
defaultFont.size = { width: DEFAULT_TEXT_SIZE, height: DEFAULT_TEXT_SIZE };
|
|
66614
66902
|
effects.font = defaultFont;
|
|
66615
66903
|
}
|
|
@@ -66664,7 +66952,7 @@ var applySymbolProperty = (symbol, key, propertyMeta) => {
|
|
|
66664
66952
|
toNumber(propertyMeta.at.y, 0),
|
|
66665
66953
|
toNumber(propertyMeta.at.rotation, 0)
|
|
66666
66954
|
] : existingProperty?.at;
|
|
66667
|
-
const nextEffects =
|
|
66955
|
+
const nextEffects = createTextEffects4(propertyMeta.effects, existingProperty?.effects);
|
|
66668
66956
|
if (existingProperty) {
|
|
66669
66957
|
existingProperty.value = propertyMeta.value;
|
|
66670
66958
|
if (nextId !== undefined) {
|
|
@@ -66698,15 +66986,15 @@ function applyKicadSymbolMetadata(kicadSymbol, metadata) {
|
|
|
66698
66986
|
symbol.onBoard = metadata.onBoard;
|
|
66699
66987
|
}
|
|
66700
66988
|
if (metadata.embeddedFonts !== undefined) {
|
|
66701
|
-
symbol._sxEmbeddedFonts = new
|
|
66989
|
+
symbol._sxEmbeddedFonts = new EmbeddedFonts6(metadata.embeddedFonts);
|
|
66702
66990
|
}
|
|
66703
66991
|
if (metadata.pinNumbers?.hide !== undefined) {
|
|
66704
|
-
const pinNumbers = symbol.pinNumbers ?? new
|
|
66992
|
+
const pinNumbers = symbol.pinNumbers ?? new SymbolPinNumbers3;
|
|
66705
66993
|
pinNumbers.hide = metadata.pinNumbers.hide;
|
|
66706
66994
|
symbol.pinNumbers = pinNumbers;
|
|
66707
66995
|
}
|
|
66708
66996
|
if (metadata.pinNames) {
|
|
66709
|
-
const pinNames = symbol.pinNames ?? new
|
|
66997
|
+
const pinNames = symbol.pinNames ?? new SymbolPinNames3;
|
|
66710
66998
|
if (metadata.pinNames.offset !== undefined) {
|
|
66711
66999
|
pinNames.offset = toNumber(metadata.pinNames.offset, pinNames.offset);
|
|
66712
67000
|
}
|
|
@@ -66741,7 +67029,9 @@ function classifySymbolsForComponent({
|
|
|
66741
67029
|
const { tscircuitComponentName, kicadSymbols } = extractedKicadComponent;
|
|
66742
67030
|
const hasCustomFootprint = componentHasCustomFootprint(extractedKicadComponent);
|
|
66743
67031
|
let hasAddedUserSymbol = false;
|
|
66744
|
-
const
|
|
67032
|
+
const builtComponent = ctx.builtTscircuitComponents.find((c) => c.tscircuitComponentName === tscircuitComponentName);
|
|
67033
|
+
const schematicSymbol = builtComponent?.circuitJson.find((el) => el.type === "schematic_symbol");
|
|
67034
|
+
const metadata = schematicSymbol?.metadata?.kicad_symbol;
|
|
66745
67035
|
for (const kicadSymbol of kicadSymbols) {
|
|
66746
67036
|
if (!kicadSymbol.isBuiltin) {
|
|
66747
67037
|
const symbolName = kicadSymbol.symbolName;
|
|
@@ -66892,8 +67182,6 @@ var KicadLibraryConverter = class {
|
|
|
66892
67182
|
this.ctx = createKicadLibraryConverterContext({
|
|
66893
67183
|
kicadLibraryName: options.kicadLibraryName ?? "tscircuit_library",
|
|
66894
67184
|
includeBuiltins: options.includeBuiltins ?? true,
|
|
66895
|
-
getComponentKicadMetadata: options.getComponentKicadMetadata,
|
|
66896
|
-
getComponentKicadSymbolMetadata: options.getComponentKicadSymbolMetadata,
|
|
66897
67185
|
isPcm: options.isPcm ?? false,
|
|
66898
67186
|
kicadPcmPackageId: options.kicadPcmPackageId
|
|
66899
67187
|
});
|
|
@@ -66921,18 +67209,6 @@ var KicadLibraryConverter = class {
|
|
|
66921
67209
|
if (resolved)
|
|
66922
67210
|
componentPath = resolved;
|
|
66923
67211
|
}
|
|
66924
|
-
if (this.ctx.getComponentKicadMetadata) {
|
|
66925
|
-
const metadata = await this.ctx.getComponentKicadMetadata(componentPath, exportName);
|
|
66926
|
-
if (metadata) {
|
|
66927
|
-
this.ctx.footprintMetadataMap.set(exportName, metadata);
|
|
66928
|
-
}
|
|
66929
|
-
}
|
|
66930
|
-
if (this.ctx.getComponentKicadSymbolMetadata) {
|
|
66931
|
-
const symbolMetadata = await this.ctx.getComponentKicadSymbolMetadata(componentPath, exportName);
|
|
66932
|
-
if (symbolMetadata) {
|
|
66933
|
-
this.ctx.symbolMetadataMap.set(exportName, symbolMetadata);
|
|
66934
|
-
}
|
|
66935
|
-
}
|
|
66936
67212
|
const circuitJson = await this.options.buildFileToCircuitJson(componentPath, exportName);
|
|
66937
67213
|
if (circuitJson && (!Array.isArray(circuitJson) || circuitJson.length > 0)) {
|
|
66938
67214
|
builtTscircuitComponents.push({
|
|
@@ -66949,18 +67225,6 @@ var KicadLibraryConverter = class {
|
|
|
66949
67225
|
componentPath = resolved;
|
|
66950
67226
|
}
|
|
66951
67227
|
const componentName = deriveComponentNameFromPath(componentPath);
|
|
66952
|
-
if (this.ctx.getComponentKicadMetadata) {
|
|
66953
|
-
const metadata = await this.ctx.getComponentKicadMetadata(componentPath, "default");
|
|
66954
|
-
if (metadata) {
|
|
66955
|
-
this.ctx.footprintMetadataMap.set(componentName, metadata);
|
|
66956
|
-
}
|
|
66957
|
-
}
|
|
66958
|
-
if (this.ctx.getComponentKicadSymbolMetadata) {
|
|
66959
|
-
const symbolMetadata = await this.ctx.getComponentKicadSymbolMetadata(componentPath, "default");
|
|
66960
|
-
if (symbolMetadata) {
|
|
66961
|
-
this.ctx.symbolMetadataMap.set(componentName, symbolMetadata);
|
|
66962
|
-
}
|
|
66963
|
-
}
|
|
66964
67228
|
const circuitJson = await this.options.buildFileToCircuitJson(componentPath, "default");
|
|
66965
67229
|
if (circuitJson && (!Array.isArray(circuitJson) || circuitJson.length > 0)) {
|
|
66966
67230
|
builtTscircuitComponents.push({
|
|
@@ -67006,12 +67270,8 @@ function createKicadLibraryConverterContext(params2) {
|
|
|
67006
67270
|
return {
|
|
67007
67271
|
kicadLibraryName: params2.kicadLibraryName,
|
|
67008
67272
|
includeBuiltins: params2.includeBuiltins,
|
|
67009
|
-
getComponentKicadMetadata: params2.getComponentKicadMetadata,
|
|
67010
|
-
getComponentKicadSymbolMetadata: params2.getComponentKicadSymbolMetadata,
|
|
67011
67273
|
isPcm: params2.isPcm,
|
|
67012
67274
|
kicadPcmPackageId: params2.kicadPcmPackageId,
|
|
67013
|
-
footprintMetadataMap: /* @__PURE__ */ new Map,
|
|
67014
|
-
symbolMetadataMap: /* @__PURE__ */ new Map,
|
|
67015
67275
|
builtTscircuitComponents: [],
|
|
67016
67276
|
extractedKicadComponents: [],
|
|
67017
67277
|
userKicadFootprints: [],
|
|
@@ -67056,144 +67316,6 @@ async function importFromUserLand(moduleName) {
|
|
|
67056
67316
|
return import(moduleName);
|
|
67057
67317
|
}
|
|
67058
67318
|
|
|
67059
|
-
// lib/shared/extract-kicad-footprint-metadata.ts
|
|
67060
|
-
function extractKicadFootprintMetadata(Component, options = {}) {
|
|
67061
|
-
const { maxIterations = 100, debug = false } = options;
|
|
67062
|
-
let reactElm;
|
|
67063
|
-
try {
|
|
67064
|
-
reactElm = Component({});
|
|
67065
|
-
} catch (e) {
|
|
67066
|
-
if (debug) {
|
|
67067
|
-
console.log(`[extractKicadFootprintMetadata] Failed to call root component:`, e);
|
|
67068
|
-
}
|
|
67069
|
-
return {};
|
|
67070
|
-
}
|
|
67071
|
-
if (!reactElm) {
|
|
67072
|
-
return {};
|
|
67073
|
-
}
|
|
67074
|
-
const queue = [reactElm];
|
|
67075
|
-
let iterations = 0;
|
|
67076
|
-
while (queue.length > 0) {
|
|
67077
|
-
iterations++;
|
|
67078
|
-
if (iterations > maxIterations) {
|
|
67079
|
-
if (debug) {
|
|
67080
|
-
console.log(`[extractKicadFootprintMetadata] Max iterations (${maxIterations}) reached`);
|
|
67081
|
-
}
|
|
67082
|
-
break;
|
|
67083
|
-
}
|
|
67084
|
-
const elm = queue.shift();
|
|
67085
|
-
if (!elm)
|
|
67086
|
-
continue;
|
|
67087
|
-
if (typeof elm.type === "function") {
|
|
67088
|
-
try {
|
|
67089
|
-
let childElm = null;
|
|
67090
|
-
try {
|
|
67091
|
-
childElm = elm.type(elm.props || {});
|
|
67092
|
-
} catch {
|
|
67093
|
-
childElm = elm.type();
|
|
67094
|
-
}
|
|
67095
|
-
if (childElm) {
|
|
67096
|
-
queue.push(childElm);
|
|
67097
|
-
}
|
|
67098
|
-
} catch (e) {
|
|
67099
|
-
if (debug) {
|
|
67100
|
-
console.log(`[extractKicadFootprintMetadata] Failed to call functional component:`, e);
|
|
67101
|
-
}
|
|
67102
|
-
}
|
|
67103
|
-
}
|
|
67104
|
-
if (elm?.props?.kicadFootprintMetadata) {
|
|
67105
|
-
return elm.props.kicadFootprintMetadata;
|
|
67106
|
-
}
|
|
67107
|
-
if (elm?.props) {
|
|
67108
|
-
const children = elm.props.children;
|
|
67109
|
-
if (Array.isArray(children)) {
|
|
67110
|
-
for (const child of children) {
|
|
67111
|
-
if (child && typeof child === "object") {
|
|
67112
|
-
queue.push(child);
|
|
67113
|
-
}
|
|
67114
|
-
}
|
|
67115
|
-
} else if (children && typeof children === "object") {
|
|
67116
|
-
queue.push(children);
|
|
67117
|
-
}
|
|
67118
|
-
for (const [key, value] of Object.entries(elm.props)) {
|
|
67119
|
-
if (key !== "children" && value && typeof value === "object" && "type" in value && "props" in value) {
|
|
67120
|
-
queue.push(value);
|
|
67121
|
-
}
|
|
67122
|
-
}
|
|
67123
|
-
}
|
|
67124
|
-
}
|
|
67125
|
-
return {};
|
|
67126
|
-
}
|
|
67127
|
-
|
|
67128
|
-
// lib/shared/extract-kicad-symbol-metadata.ts
|
|
67129
|
-
function extractKicadSymbolMetadata(Component, options = {}) {
|
|
67130
|
-
const { maxIterations = 100, debug = false } = options;
|
|
67131
|
-
let reactElm;
|
|
67132
|
-
try {
|
|
67133
|
-
reactElm = Component({});
|
|
67134
|
-
} catch (e) {
|
|
67135
|
-
if (debug) {
|
|
67136
|
-
console.log(`[extractKicadSymbolMetadata] Failed to call root component:`, e);
|
|
67137
|
-
}
|
|
67138
|
-
return {};
|
|
67139
|
-
}
|
|
67140
|
-
if (!reactElm) {
|
|
67141
|
-
return {};
|
|
67142
|
-
}
|
|
67143
|
-
const queue = [reactElm];
|
|
67144
|
-
let iterations = 0;
|
|
67145
|
-
while (queue.length > 0) {
|
|
67146
|
-
iterations++;
|
|
67147
|
-
if (iterations > maxIterations) {
|
|
67148
|
-
if (debug) {
|
|
67149
|
-
console.log(`[extractKicadSymbolMetadata] Max iterations (${maxIterations}) reached`);
|
|
67150
|
-
}
|
|
67151
|
-
break;
|
|
67152
|
-
}
|
|
67153
|
-
const elm = queue.shift();
|
|
67154
|
-
if (!elm)
|
|
67155
|
-
continue;
|
|
67156
|
-
if (typeof elm.type === "function") {
|
|
67157
|
-
try {
|
|
67158
|
-
let childElm = null;
|
|
67159
|
-
try {
|
|
67160
|
-
childElm = elm.type(elm.props || {});
|
|
67161
|
-
} catch {
|
|
67162
|
-
childElm = elm.type();
|
|
67163
|
-
}
|
|
67164
|
-
if (childElm) {
|
|
67165
|
-
queue.push(childElm);
|
|
67166
|
-
}
|
|
67167
|
-
} catch (e) {
|
|
67168
|
-
if (debug) {
|
|
67169
|
-
console.log(`[extractKicadSymbolMetadata] Failed to call functional component:`, e);
|
|
67170
|
-
}
|
|
67171
|
-
}
|
|
67172
|
-
}
|
|
67173
|
-
if (elm?.props?.kicadSymbolMetadata) {
|
|
67174
|
-
return elm.props.kicadSymbolMetadata;
|
|
67175
|
-
}
|
|
67176
|
-
if (elm?.props) {
|
|
67177
|
-
const children = elm.props.children;
|
|
67178
|
-
if (Array.isArray(children)) {
|
|
67179
|
-
for (const child of children) {
|
|
67180
|
-
if (child && typeof child === "object") {
|
|
67181
|
-
queue.push(child);
|
|
67182
|
-
}
|
|
67183
|
-
}
|
|
67184
|
-
} else if (children && typeof children === "object") {
|
|
67185
|
-
queue.push(children);
|
|
67186
|
-
}
|
|
67187
|
-
for (const [key, value] of Object.entries(elm.props)) {
|
|
67188
|
-
if (key !== "children" && value && typeof value === "object" && "type" in value && "props" in value) {
|
|
67189
|
-
queue.push(value);
|
|
67190
|
-
}
|
|
67191
|
-
}
|
|
67192
|
-
}
|
|
67193
|
-
}
|
|
67194
|
-
return {};
|
|
67195
|
-
}
|
|
67196
|
-
|
|
67197
67319
|
// lib/shared/convert-to-kicad-library.tsx
|
|
67198
67320
|
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
67199
67321
|
async function convertToKicadLibrary({
|
|
@@ -67234,30 +67356,6 @@ async function convertToKicadLibrary({
|
|
|
67234
67356
|
const module2 = await import(pathToFileURL(filePath2).href);
|
|
67235
67357
|
return Object.keys(module2);
|
|
67236
67358
|
},
|
|
67237
|
-
getComponentKicadMetadata: async (filePath2, componentName) => {
|
|
67238
|
-
try {
|
|
67239
|
-
const module2 = await import(pathToFileURL(filePath2).href);
|
|
67240
|
-
const Component = module2[componentName];
|
|
67241
|
-
if (!Component || typeof Component !== "function") {
|
|
67242
|
-
return null;
|
|
67243
|
-
}
|
|
67244
|
-
return extractKicadFootprintMetadata(Component);
|
|
67245
|
-
} catch (error) {
|
|
67246
|
-
return null;
|
|
67247
|
-
}
|
|
67248
|
-
},
|
|
67249
|
-
getComponentKicadSymbolMetadata: async (filePath2, componentName) => {
|
|
67250
|
-
try {
|
|
67251
|
-
const module2 = await import(pathToFileURL(filePath2).href);
|
|
67252
|
-
const Component = module2[componentName];
|
|
67253
|
-
if (!Component || typeof Component !== "function") {
|
|
67254
|
-
return null;
|
|
67255
|
-
}
|
|
67256
|
-
return extractKicadSymbolMetadata(Component);
|
|
67257
|
-
} catch (error) {
|
|
67258
|
-
return null;
|
|
67259
|
-
}
|
|
67260
|
-
},
|
|
67261
67359
|
includeBuiltins: true,
|
|
67262
67360
|
isPcm,
|
|
67263
67361
|
kicadPcmPackageId
|