circuit-json-to-kicad 0.0.7 → 0.0.9

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.
Files changed (2) hide show
  1. package/dist/index.js +53 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -364,7 +364,7 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
364
364
  isChip
365
365
  );
366
366
  pin.at = [x, y, angle];
367
- pin.length = isChip ? 2.54 : 1.27;
367
+ pin.length = isChip ? 6 : 1.27;
368
368
  const nameFont = new TextEffectsFont();
369
369
  nameFont.size = { height: 1.27, width: 1.27 };
370
370
  const nameEffects = new TextEffects({ font: nameFont });
@@ -392,7 +392,7 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
392
392
  const dy = port.y - center.y;
393
393
  let x = port.x * symbolScale;
394
394
  let y = port.y * symbolScale;
395
- const chipPinLength = 2.54;
395
+ const chipPinLength = 6;
396
396
  if (isChip && size) {
397
397
  const halfWidth = size.width / 2 * symbolScale;
398
398
  const halfHeight = size.height / 2 * symbolScale;
@@ -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: cju(circuitJson),
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 = [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "circuit-json-to-kicad",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.7",
4
+ "version": "0.0.9",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"