circuit-json-to-kicad 0.0.22 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +9 -0
- package/dist/index.js +32 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,13 @@ import { CircuitJsonUtilObjects, cju } from '@tscircuit/circuit-json-util';
|
|
|
3
3
|
import { KicadSch, KicadPcb } from 'kicadts';
|
|
4
4
|
import { Matrix } from 'transformation-matrix';
|
|
5
5
|
|
|
6
|
+
type PaperSize = "A0" | "A1" | "A2" | "A3" | "A4" | "A5";
|
|
7
|
+
interface PaperDimensions {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
name: PaperSize;
|
|
11
|
+
}
|
|
12
|
+
|
|
6
13
|
type SchematicPortId = string;
|
|
7
14
|
type SchematicTraceId = string;
|
|
8
15
|
type PcbPortId = string;
|
|
@@ -15,6 +22,8 @@ interface ConverterContext {
|
|
|
15
22
|
c2kMatSch?: Matrix;
|
|
16
23
|
/** Circuit JSON to KiCad PCB transformation matrix */
|
|
17
24
|
c2kMatPcb?: Matrix;
|
|
25
|
+
/** Selected paper size for schematic */
|
|
26
|
+
schematicPaperSize?: PaperDimensions;
|
|
18
27
|
pinPositions?: Map<SchematicPortId, {
|
|
19
28
|
x: number;
|
|
20
29
|
y: number;
|
package/dist/index.js
CHANGED
|
@@ -38,13 +38,13 @@ import { compose, translate, scale } from "transformation-matrix";
|
|
|
38
38
|
import { Paper, Uuid } from "kicadts";
|
|
39
39
|
var InitializeSchematicStage = class extends ConverterStage {
|
|
40
40
|
_step() {
|
|
41
|
-
const { kicadSch } = this.ctx;
|
|
41
|
+
const { kicadSch, schematicPaperSize } = this.ctx;
|
|
42
42
|
if (!kicadSch) {
|
|
43
43
|
throw new Error("KicadSch instance not initialized in context");
|
|
44
44
|
}
|
|
45
45
|
kicadSch.version = 20250114;
|
|
46
46
|
const paper = new Paper();
|
|
47
|
-
paper.size = "A4";
|
|
47
|
+
paper.size = schematicPaperSize?.name ?? "A4";
|
|
48
48
|
kicadSch.paper = paper;
|
|
49
49
|
kicadSch.uuid = new Uuid(crypto.randomUUID());
|
|
50
50
|
this.finished = true;
|
|
@@ -1184,6 +1184,26 @@ function getSchematicBoundsAndCenter(db) {
|
|
|
1184
1184
|
};
|
|
1185
1185
|
}
|
|
1186
1186
|
|
|
1187
|
+
// lib/schematic/selectSchematicPaperSize.ts
|
|
1188
|
+
var PAPER_SIZES = [
|
|
1189
|
+
{ name: "A4", width: 297, height: 210 },
|
|
1190
|
+
{ name: "A3", width: 420, height: 297 },
|
|
1191
|
+
{ name: "A2", width: 594, height: 420 },
|
|
1192
|
+
{ name: "A1", width: 841, height: 594 },
|
|
1193
|
+
{ name: "A0", width: 1189, height: 841 }
|
|
1194
|
+
];
|
|
1195
|
+
function selectSchematicPaperSize(contentWidth, contentHeight, paddingMm = 20) {
|
|
1196
|
+
const requiredWidth = contentWidth + 2 * paddingMm;
|
|
1197
|
+
const requiredHeight = contentHeight + 2 * paddingMm;
|
|
1198
|
+
for (let i = 0; i < PAPER_SIZES.length; i++) {
|
|
1199
|
+
const paperSize = PAPER_SIZES[i];
|
|
1200
|
+
if (requiredWidth <= paperSize.width && requiredHeight <= paperSize.height) {
|
|
1201
|
+
return paperSize;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
return PAPER_SIZES[PAPER_SIZES.length - 1];
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1187
1207
|
// lib/schematic/CircuitJsonToKicadSchConverter.ts
|
|
1188
1208
|
var CircuitJsonToKicadSchConverter = class {
|
|
1189
1209
|
ctx;
|
|
@@ -1195,10 +1215,16 @@ var CircuitJsonToKicadSchConverter = class {
|
|
|
1195
1215
|
}
|
|
1196
1216
|
constructor(circuitJson) {
|
|
1197
1217
|
const CIRCUIT_JSON_SCALE_FACTOR = 15;
|
|
1198
|
-
const KICAD_CENTER_Y = 105;
|
|
1199
|
-
const KICAD_CENTER_X = 148.5;
|
|
1200
1218
|
const db = cju(circuitJson);
|
|
1201
|
-
const { center } = getSchematicBoundsAndCenter(db);
|
|
1219
|
+
const { center, bounds } = getSchematicBoundsAndCenter(db);
|
|
1220
|
+
const schematicWidthMm = (bounds.maxX - bounds.minX) * CIRCUIT_JSON_SCALE_FACTOR;
|
|
1221
|
+
const schematicHeightMm = (bounds.maxY - bounds.minY) * CIRCUIT_JSON_SCALE_FACTOR;
|
|
1222
|
+
const paperSize = selectSchematicPaperSize(
|
|
1223
|
+
schematicWidthMm,
|
|
1224
|
+
schematicHeightMm
|
|
1225
|
+
);
|
|
1226
|
+
const KICAD_CENTER_X = paperSize.width / 2;
|
|
1227
|
+
const KICAD_CENTER_Y = paperSize.height / 2;
|
|
1202
1228
|
this.ctx = {
|
|
1203
1229
|
db,
|
|
1204
1230
|
circuitJson,
|
|
@@ -1206,6 +1232,7 @@ var CircuitJsonToKicadSchConverter = class {
|
|
|
1206
1232
|
generator: "circuit-json-to-kicad",
|
|
1207
1233
|
generatorVersion: "0.0.1"
|
|
1208
1234
|
}),
|
|
1235
|
+
schematicPaperSize: paperSize,
|
|
1209
1236
|
c2kMatSch: compose(
|
|
1210
1237
|
translate(KICAD_CENTER_X, KICAD_CENTER_Y),
|
|
1211
1238
|
scale(CIRCUIT_JSON_SCALE_FACTOR, -CIRCUIT_JSON_SCALE_FACTOR),
|