circuit-json-to-kicad 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +51 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -826,6 +826,52 @@ var AddSheetInstancesStage = class extends ConverterStage {
|
|
|
826
826
|
}
|
|
827
827
|
};
|
|
828
828
|
|
|
829
|
+
// lib/schematic/getSchematicBoundsAndCenter.ts
|
|
830
|
+
function getSchematicBoundsAndCenter(db) {
|
|
831
|
+
const schematicComponents = db.schematic_component.list();
|
|
832
|
+
const schematicTraces = db.schematic_trace.list();
|
|
833
|
+
let minX = Infinity;
|
|
834
|
+
let minY = Infinity;
|
|
835
|
+
let maxX = -Infinity;
|
|
836
|
+
let maxY = -Infinity;
|
|
837
|
+
for (const component of schematicComponents) {
|
|
838
|
+
const width = component.size?.width ?? 0;
|
|
839
|
+
const height = component.size?.height ?? 0;
|
|
840
|
+
minX = Math.min(minX, component.center.x - width / 2);
|
|
841
|
+
minY = Math.min(minY, component.center.y - height / 2);
|
|
842
|
+
maxX = Math.max(maxX, component.center.x + width / 2);
|
|
843
|
+
maxY = Math.max(maxY, component.center.y + height / 2);
|
|
844
|
+
}
|
|
845
|
+
for (const trace of schematicTraces) {
|
|
846
|
+
for (const edge of trace.edges) {
|
|
847
|
+
minX = Math.min(minX, edge.from.x, edge.to.x);
|
|
848
|
+
minY = Math.min(minY, edge.from.y, edge.to.y);
|
|
849
|
+
maxX = Math.max(maxX, edge.from.x, edge.to.x);
|
|
850
|
+
maxY = Math.max(maxY, edge.from.y, edge.to.y);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
if (minX === Infinity) {
|
|
854
|
+
minX = 0;
|
|
855
|
+
minY = 0;
|
|
856
|
+
maxX = 0;
|
|
857
|
+
maxY = 0;
|
|
858
|
+
}
|
|
859
|
+
const centerX = (minX + maxX) / 2;
|
|
860
|
+
const centerY = (minY + maxY) / 2;
|
|
861
|
+
return {
|
|
862
|
+
center: {
|
|
863
|
+
x: centerX,
|
|
864
|
+
y: centerY
|
|
865
|
+
},
|
|
866
|
+
bounds: {
|
|
867
|
+
minX,
|
|
868
|
+
minY,
|
|
869
|
+
maxX,
|
|
870
|
+
maxY
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
|
|
829
875
|
// lib/schematic/CircuitJsonToKicadSchConverter.ts
|
|
830
876
|
var CircuitJsonToKicadSchConverter = class {
|
|
831
877
|
ctx;
|
|
@@ -839,8 +885,10 @@ var CircuitJsonToKicadSchConverter = class {
|
|
|
839
885
|
const CIRCUIT_JSON_SCALE_FACTOR = 15;
|
|
840
886
|
const KICAD_CENTER_X = 95.25;
|
|
841
887
|
const KICAD_CENTER_Y = 73.66;
|
|
888
|
+
const db = cju(circuitJson);
|
|
889
|
+
const { center } = getSchematicBoundsAndCenter(db);
|
|
842
890
|
this.ctx = {
|
|
843
|
-
db
|
|
891
|
+
db,
|
|
844
892
|
circuitJson,
|
|
845
893
|
kicadSch: new KicadSch({
|
|
846
894
|
generator: "circuit-json-to-kicad",
|
|
@@ -848,7 +896,8 @@ var CircuitJsonToKicadSchConverter = class {
|
|
|
848
896
|
}),
|
|
849
897
|
c2kMatSch: compose(
|
|
850
898
|
translate(KICAD_CENTER_X, KICAD_CENTER_Y),
|
|
851
|
-
scale(CIRCUIT_JSON_SCALE_FACTOR, -CIRCUIT_JSON_SCALE_FACTOR)
|
|
899
|
+
scale(CIRCUIT_JSON_SCALE_FACTOR, -CIRCUIT_JSON_SCALE_FACTOR),
|
|
900
|
+
translate(-center.x, -center.y)
|
|
852
901
|
)
|
|
853
902
|
};
|
|
854
903
|
this.pipeline = [
|