circuit-to-svg 0.0.164 → 0.0.165
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 +384 -69
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2987,69 +2987,6 @@ function drawSchematicLabeledPoints(params) {
|
|
|
2987
2987
|
};
|
|
2988
2988
|
}
|
|
2989
2989
|
|
|
2990
|
-
// lib/utils/get-unit-vector-from-outside-to-edge.ts
|
|
2991
|
-
var getUnitVectorFromOutsideToEdge = (side) => {
|
|
2992
|
-
switch (side) {
|
|
2993
|
-
case "top":
|
|
2994
|
-
return { x: 0, y: -1 };
|
|
2995
|
-
case "bottom":
|
|
2996
|
-
return { x: 0, y: 1 };
|
|
2997
|
-
case "left":
|
|
2998
|
-
return { x: 1, y: 0 };
|
|
2999
|
-
case "right":
|
|
3000
|
-
return { x: -1, y: 0 };
|
|
3001
|
-
}
|
|
3002
|
-
throw new Error(`Invalid side: ${side}`);
|
|
3003
|
-
};
|
|
3004
|
-
|
|
3005
|
-
// lib/utils/net-label-utils.ts
|
|
3006
|
-
import "transformation-matrix";
|
|
3007
|
-
import "schematic-symbols";
|
|
3008
|
-
var ARROW_POINT_WIDTH_FSR = 0.3;
|
|
3009
|
-
var END_PADDING_FSR = 0.3;
|
|
3010
|
-
var END_PADDING_EXTRA_PER_CHARACTER_FSR = 0.06;
|
|
3011
|
-
var ninePointAnchorToTextAnchor = {
|
|
3012
|
-
top_left: "start",
|
|
3013
|
-
top_right: "end",
|
|
3014
|
-
middle_left: "start",
|
|
3015
|
-
middle_right: "end",
|
|
3016
|
-
bottom_left: "start",
|
|
3017
|
-
bottom_right: "end",
|
|
3018
|
-
center: "middle",
|
|
3019
|
-
middle_top: "middle",
|
|
3020
|
-
middle_bottom: "middle"
|
|
3021
|
-
};
|
|
3022
|
-
var ninePointAnchorToDominantBaseline = {
|
|
3023
|
-
top_left: "hanging",
|
|
3024
|
-
top_right: "hanging",
|
|
3025
|
-
bottom_left: "ideographic",
|
|
3026
|
-
bottom_right: "ideographic",
|
|
3027
|
-
center: "middle",
|
|
3028
|
-
middle_left: "middle",
|
|
3029
|
-
middle_right: "middle",
|
|
3030
|
-
middle_top: "hanging",
|
|
3031
|
-
middle_bottom: "ideographic"
|
|
3032
|
-
};
|
|
3033
|
-
function getPathRotation(anchorSide) {
|
|
3034
|
-
const rotationMap = {
|
|
3035
|
-
left: 180,
|
|
3036
|
-
top: 90,
|
|
3037
|
-
bottom: -90,
|
|
3038
|
-
right: 0
|
|
3039
|
-
};
|
|
3040
|
-
return rotationMap[anchorSide] ?? 0;
|
|
3041
|
-
}
|
|
3042
|
-
function calculateAnchorPosition(schNetLabel, fontSizeMm, textWidthFSR) {
|
|
3043
|
-
const fullWidthFsr = textWidthFSR + ARROW_POINT_WIDTH_FSR * 2 + END_PADDING_EXTRA_PER_CHARACTER_FSR * schNetLabel.text.length + END_PADDING_FSR;
|
|
3044
|
-
const realTextGrowthVec = getUnitVectorFromOutsideToEdge(
|
|
3045
|
-
schNetLabel.anchor_side
|
|
3046
|
-
);
|
|
3047
|
-
return schNetLabel.anchor_position ?? {
|
|
3048
|
-
x: schNetLabel.center.x - realTextGrowthVec.x * fullWidthFsr * fontSizeMm / 2,
|
|
3049
|
-
y: schNetLabel.center.y - realTextGrowthVec.y * fullWidthFsr * fontSizeMm / 2
|
|
3050
|
-
};
|
|
3051
|
-
}
|
|
3052
|
-
|
|
3053
2990
|
// lib/sch/arial-text-metrics.ts
|
|
3054
2991
|
var arialTextMetrics = {
|
|
3055
2992
|
"0": {
|
|
@@ -3829,6 +3766,149 @@ var estimateTextWidth = (text) => {
|
|
|
3829
3766
|
return totalWidth / 27;
|
|
3830
3767
|
};
|
|
3831
3768
|
|
|
3769
|
+
// lib/sch/get-table-dimensions.ts
|
|
3770
|
+
var getTableDimensions = (schematicTable, circuitJson) => {
|
|
3771
|
+
if (schematicTable.column_widths && schematicTable.column_widths.length > 0 && schematicTable.row_heights && schematicTable.row_heights.length > 0) {
|
|
3772
|
+
const unitToMm = (v) => {
|
|
3773
|
+
if (typeof v === "number") return v;
|
|
3774
|
+
if (v.endsWith("mm")) return parseFloat(v);
|
|
3775
|
+
if (v.endsWith("in")) return parseFloat(v) * 25.4;
|
|
3776
|
+
return parseFloat(v);
|
|
3777
|
+
};
|
|
3778
|
+
return {
|
|
3779
|
+
column_widths: schematicTable.column_widths.map(unitToMm),
|
|
3780
|
+
row_heights: schematicTable.row_heights.map(unitToMm)
|
|
3781
|
+
};
|
|
3782
|
+
}
|
|
3783
|
+
const cells = circuitJson.filter(
|
|
3784
|
+
(elm) => elm.type === "schematic_table_cell" && elm.schematic_table_id === schematicTable.schematic_table_id
|
|
3785
|
+
);
|
|
3786
|
+
if (cells.length === 0) {
|
|
3787
|
+
return { column_widths: [], row_heights: [] };
|
|
3788
|
+
}
|
|
3789
|
+
const numColumns = cells.reduce((max, c) => Math.max(max, c.end_column_index), -1) + 1;
|
|
3790
|
+
const numRows = cells.reduce((max, c) => Math.max(max, c.end_row_index), -1) + 1;
|
|
3791
|
+
const { cell_padding = 0.2 } = schematicTable;
|
|
3792
|
+
const column_widths = new Array(numColumns).fill(0);
|
|
3793
|
+
const row_heights = new Array(numRows).fill(0);
|
|
3794
|
+
const cell_widths = {};
|
|
3795
|
+
const cell_heights = {};
|
|
3796
|
+
for (const cell of cells) {
|
|
3797
|
+
const fontSizeMm = getSchMmFontSize("reference_designator", cell.font_size);
|
|
3798
|
+
const textWidthMm = estimateTextWidth(cell.text ?? "") * fontSizeMm;
|
|
3799
|
+
const requiredWidth = textWidthMm + 2 * cell_padding;
|
|
3800
|
+
const requiredHeight = fontSizeMm * 1.2 + 2 * cell_padding;
|
|
3801
|
+
const key = `${cell.start_row_index}-${cell.start_column_index}`;
|
|
3802
|
+
cell_widths[key] = requiredWidth;
|
|
3803
|
+
cell_heights[key] = requiredHeight;
|
|
3804
|
+
}
|
|
3805
|
+
for (let i = 0; i < numRows; i++) {
|
|
3806
|
+
for (let j = 0; j < numColumns; j++) {
|
|
3807
|
+
const key = `${i}-${j}`;
|
|
3808
|
+
if (cell_widths[key] && cell_widths[key] > column_widths[j]) {
|
|
3809
|
+
column_widths[j] = cell_widths[key];
|
|
3810
|
+
}
|
|
3811
|
+
if (cell_heights[key] && cell_heights[key] > row_heights[i]) {
|
|
3812
|
+
row_heights[i] = cell_heights[key];
|
|
3813
|
+
}
|
|
3814
|
+
}
|
|
3815
|
+
}
|
|
3816
|
+
for (const cell of cells) {
|
|
3817
|
+
if (cell.start_column_index === cell.end_column_index && cell.start_row_index === cell.end_row_index)
|
|
3818
|
+
continue;
|
|
3819
|
+
const key = `${cell.start_row_index}-${cell.start_column_index}`;
|
|
3820
|
+
const requiredWidth = cell_widths[key];
|
|
3821
|
+
const requiredHeight = cell_heights[key];
|
|
3822
|
+
if (requiredWidth === void 0 || requiredHeight === void 0) continue;
|
|
3823
|
+
let currentWidth = 0;
|
|
3824
|
+
for (let i = cell.start_column_index; i <= cell.end_column_index; i++) {
|
|
3825
|
+
currentWidth += column_widths[i];
|
|
3826
|
+
}
|
|
3827
|
+
if (requiredWidth > currentWidth) {
|
|
3828
|
+
const diff = requiredWidth - currentWidth;
|
|
3829
|
+
const extraPerColumn = diff / (cell.end_column_index - cell.start_column_index + 1);
|
|
3830
|
+
for (let i = cell.start_column_index; i <= cell.end_column_index; i++) {
|
|
3831
|
+
column_widths[i] += extraPerColumn;
|
|
3832
|
+
}
|
|
3833
|
+
}
|
|
3834
|
+
let currentHeight = 0;
|
|
3835
|
+
for (let i = cell.start_row_index; i <= cell.end_row_index; i++) {
|
|
3836
|
+
currentHeight += row_heights[i];
|
|
3837
|
+
}
|
|
3838
|
+
if (requiredHeight > currentHeight) {
|
|
3839
|
+
const diff = requiredHeight - currentHeight;
|
|
3840
|
+
const extraPerRow = diff / (cell.end_row_index - cell.start_row_index + 1);
|
|
3841
|
+
for (let i = cell.start_row_index; i <= cell.end_row_index; i++) {
|
|
3842
|
+
row_heights[i] += extraPerRow;
|
|
3843
|
+
}
|
|
3844
|
+
}
|
|
3845
|
+
}
|
|
3846
|
+
return { column_widths, row_heights };
|
|
3847
|
+
};
|
|
3848
|
+
|
|
3849
|
+
// lib/utils/get-unit-vector-from-outside-to-edge.ts
|
|
3850
|
+
var getUnitVectorFromOutsideToEdge = (side) => {
|
|
3851
|
+
switch (side) {
|
|
3852
|
+
case "top":
|
|
3853
|
+
return { x: 0, y: -1 };
|
|
3854
|
+
case "bottom":
|
|
3855
|
+
return { x: 0, y: 1 };
|
|
3856
|
+
case "left":
|
|
3857
|
+
return { x: 1, y: 0 };
|
|
3858
|
+
case "right":
|
|
3859
|
+
return { x: -1, y: 0 };
|
|
3860
|
+
}
|
|
3861
|
+
throw new Error(`Invalid side: ${side}`);
|
|
3862
|
+
};
|
|
3863
|
+
|
|
3864
|
+
// lib/utils/net-label-utils.ts
|
|
3865
|
+
import "transformation-matrix";
|
|
3866
|
+
import "schematic-symbols";
|
|
3867
|
+
var ARROW_POINT_WIDTH_FSR = 0.3;
|
|
3868
|
+
var END_PADDING_FSR = 0.3;
|
|
3869
|
+
var END_PADDING_EXTRA_PER_CHARACTER_FSR = 0.06;
|
|
3870
|
+
var ninePointAnchorToTextAnchor = {
|
|
3871
|
+
top_left: "start",
|
|
3872
|
+
top_right: "end",
|
|
3873
|
+
middle_left: "start",
|
|
3874
|
+
middle_right: "end",
|
|
3875
|
+
bottom_left: "start",
|
|
3876
|
+
bottom_right: "end",
|
|
3877
|
+
center: "middle",
|
|
3878
|
+
middle_top: "middle",
|
|
3879
|
+
middle_bottom: "middle"
|
|
3880
|
+
};
|
|
3881
|
+
var ninePointAnchorToDominantBaseline = {
|
|
3882
|
+
top_left: "hanging",
|
|
3883
|
+
top_right: "hanging",
|
|
3884
|
+
bottom_left: "ideographic",
|
|
3885
|
+
bottom_right: "ideographic",
|
|
3886
|
+
center: "middle",
|
|
3887
|
+
middle_left: "middle",
|
|
3888
|
+
middle_right: "middle",
|
|
3889
|
+
middle_top: "hanging",
|
|
3890
|
+
middle_bottom: "ideographic"
|
|
3891
|
+
};
|
|
3892
|
+
function getPathRotation(anchorSide) {
|
|
3893
|
+
const rotationMap = {
|
|
3894
|
+
left: 180,
|
|
3895
|
+
top: 90,
|
|
3896
|
+
bottom: -90,
|
|
3897
|
+
right: 0
|
|
3898
|
+
};
|
|
3899
|
+
return rotationMap[anchorSide] ?? 0;
|
|
3900
|
+
}
|
|
3901
|
+
function calculateAnchorPosition(schNetLabel, fontSizeMm, textWidthFSR) {
|
|
3902
|
+
const fullWidthFsr = textWidthFSR + ARROW_POINT_WIDTH_FSR * 2 + END_PADDING_EXTRA_PER_CHARACTER_FSR * schNetLabel.text.length + END_PADDING_FSR;
|
|
3903
|
+
const realTextGrowthVec = getUnitVectorFromOutsideToEdge(
|
|
3904
|
+
schNetLabel.anchor_side
|
|
3905
|
+
);
|
|
3906
|
+
return schNetLabel.anchor_position ?? {
|
|
3907
|
+
x: schNetLabel.center.x - realTextGrowthVec.x * fullWidthFsr * fontSizeMm / 2,
|
|
3908
|
+
y: schNetLabel.center.y - realTextGrowthVec.y * fullWidthFsr * fontSizeMm / 2
|
|
3909
|
+
};
|
|
3910
|
+
}
|
|
3911
|
+
|
|
3832
3912
|
// lib/sch/get-schematic-bounds-from-circuit-json.ts
|
|
3833
3913
|
function getSchematicBoundsFromCircuitJson(soup, padding = 0.5) {
|
|
3834
3914
|
let minX = Number.POSITIVE_INFINITY;
|
|
@@ -3889,6 +3969,30 @@ function getSchematicBoundsFromCircuitJson(soup, padding = 0.5) {
|
|
|
3889
3969
|
{ width: item.width, height: item.height },
|
|
3890
3970
|
0
|
|
3891
3971
|
);
|
|
3972
|
+
} else if (item.type === "schematic_table") {
|
|
3973
|
+
const { column_widths, row_heights } = getTableDimensions(item, soup);
|
|
3974
|
+
const totalWidth = column_widths.reduce((a, b) => a + b, 0);
|
|
3975
|
+
const totalHeight = row_heights.reduce((a, b) => a + b, 0);
|
|
3976
|
+
const anchor = item.anchor ?? "center";
|
|
3977
|
+
let topLeftX = item.anchor_position.x;
|
|
3978
|
+
let topLeftY = item.anchor_position.y;
|
|
3979
|
+
if (anchor.includes("center")) {
|
|
3980
|
+
topLeftX -= totalWidth / 2;
|
|
3981
|
+
} else if (anchor.includes("right")) {
|
|
3982
|
+
topLeftX -= totalWidth;
|
|
3983
|
+
}
|
|
3984
|
+
if (anchor.includes("center")) {
|
|
3985
|
+
topLeftY += totalHeight / 2;
|
|
3986
|
+
} else if (anchor.includes("bottom")) {
|
|
3987
|
+
topLeftY += totalHeight;
|
|
3988
|
+
}
|
|
3989
|
+
const centerX = topLeftX + totalWidth / 2;
|
|
3990
|
+
const centerY = topLeftY - totalHeight / 2;
|
|
3991
|
+
updateBounds(
|
|
3992
|
+
{ x: centerX, y: centerY },
|
|
3993
|
+
{ width: totalWidth, height: totalHeight },
|
|
3994
|
+
0
|
|
3995
|
+
);
|
|
3892
3996
|
}
|
|
3893
3997
|
}
|
|
3894
3998
|
minX -= padding;
|
|
@@ -5412,6 +5516,206 @@ var createSvgObjectsFromSchematicBox = ({
|
|
|
5412
5516
|
];
|
|
5413
5517
|
};
|
|
5414
5518
|
|
|
5519
|
+
// lib/sch/svg-object-fns/create-svg-objects-from-sch-table.ts
|
|
5520
|
+
import { applyToPoint as applyToPoint42 } from "transformation-matrix";
|
|
5521
|
+
var createSvgObjectsFromSchematicTable = ({
|
|
5522
|
+
schematicTable,
|
|
5523
|
+
transform,
|
|
5524
|
+
colorMap: colorMap2,
|
|
5525
|
+
circuitJson
|
|
5526
|
+
}) => {
|
|
5527
|
+
const {
|
|
5528
|
+
anchor_position,
|
|
5529
|
+
border_width = 0.05,
|
|
5530
|
+
anchor = "center"
|
|
5531
|
+
} = schematicTable;
|
|
5532
|
+
const { column_widths, row_heights } = getTableDimensions(
|
|
5533
|
+
schematicTable,
|
|
5534
|
+
circuitJson
|
|
5535
|
+
);
|
|
5536
|
+
const totalWidth = column_widths.reduce((a, b) => a + b, 0);
|
|
5537
|
+
const totalHeight = row_heights.reduce((a, b) => a + b, 0);
|
|
5538
|
+
let topLeftX = anchor_position.x;
|
|
5539
|
+
let topLeftY = anchor_position.y;
|
|
5540
|
+
if (anchor.includes("center")) {
|
|
5541
|
+
topLeftX -= totalWidth / 2;
|
|
5542
|
+
} else if (anchor.includes("right")) {
|
|
5543
|
+
topLeftX -= totalWidth;
|
|
5544
|
+
}
|
|
5545
|
+
if (anchor.includes("center")) {
|
|
5546
|
+
topLeftY += totalHeight / 2;
|
|
5547
|
+
} else if (anchor.includes("bottom")) {
|
|
5548
|
+
topLeftY += totalHeight;
|
|
5549
|
+
}
|
|
5550
|
+
const svgObjects = [];
|
|
5551
|
+
const borderStrokeWidth = border_width * Math.abs(transform.a);
|
|
5552
|
+
const gridStrokeWidth = getSchStrokeSize(transform);
|
|
5553
|
+
const [screenTopLeftX, screenTopLeftY] = applyToPoint42(transform, [
|
|
5554
|
+
topLeftX,
|
|
5555
|
+
topLeftY
|
|
5556
|
+
]);
|
|
5557
|
+
const [screenBottomRightX, screenBottomRightY] = applyToPoint42(transform, [
|
|
5558
|
+
topLeftX + totalWidth,
|
|
5559
|
+
topLeftY - totalHeight
|
|
5560
|
+
]);
|
|
5561
|
+
svgObjects.push({
|
|
5562
|
+
name: "rect",
|
|
5563
|
+
type: "element",
|
|
5564
|
+
attributes: {
|
|
5565
|
+
x: screenTopLeftX.toString(),
|
|
5566
|
+
y: screenTopLeftY.toString(),
|
|
5567
|
+
width: (screenBottomRightX - screenTopLeftX).toString(),
|
|
5568
|
+
height: (screenBottomRightY - screenTopLeftY).toString(),
|
|
5569
|
+
fill: "none",
|
|
5570
|
+
stroke: "#666",
|
|
5571
|
+
"stroke-width": borderStrokeWidth.toString()
|
|
5572
|
+
},
|
|
5573
|
+
children: [],
|
|
5574
|
+
value: ""
|
|
5575
|
+
});
|
|
5576
|
+
const cells = circuitJson.filter(
|
|
5577
|
+
(elm) => elm.type === "schematic_table_cell" && elm.schematic_table_id === schematicTable.schematic_table_id
|
|
5578
|
+
);
|
|
5579
|
+
let currentX = topLeftX;
|
|
5580
|
+
for (let i = 0; i < column_widths.length - 1; i++) {
|
|
5581
|
+
currentX += column_widths[i];
|
|
5582
|
+
let segmentStartY = topLeftY;
|
|
5583
|
+
for (let j = 0; j < row_heights.length; j++) {
|
|
5584
|
+
const segmentEndY = segmentStartY - row_heights[j];
|
|
5585
|
+
const isMerged = cells.some(
|
|
5586
|
+
(cell) => cell.start_column_index <= i && cell.end_column_index > i && cell.start_row_index <= j && cell.end_row_index >= j
|
|
5587
|
+
);
|
|
5588
|
+
if (!isMerged) {
|
|
5589
|
+
const start = applyToPoint42(transform, { x: currentX, y: segmentStartY });
|
|
5590
|
+
const end = applyToPoint42(transform, { x: currentX, y: segmentEndY });
|
|
5591
|
+
svgObjects.push({
|
|
5592
|
+
name: "line",
|
|
5593
|
+
type: "element",
|
|
5594
|
+
attributes: {
|
|
5595
|
+
x1: start.x.toString(),
|
|
5596
|
+
y1: start.y.toString(),
|
|
5597
|
+
x2: end.x.toString(),
|
|
5598
|
+
y2: end.y.toString(),
|
|
5599
|
+
stroke: "#666",
|
|
5600
|
+
"stroke-width": gridStrokeWidth.toString()
|
|
5601
|
+
},
|
|
5602
|
+
children: [],
|
|
5603
|
+
value: ""
|
|
5604
|
+
});
|
|
5605
|
+
}
|
|
5606
|
+
segmentStartY = segmentEndY;
|
|
5607
|
+
}
|
|
5608
|
+
}
|
|
5609
|
+
let currentY = topLeftY;
|
|
5610
|
+
for (let i = 0; i < row_heights.length - 1; i++) {
|
|
5611
|
+
currentY -= row_heights[i];
|
|
5612
|
+
let segmentStartX = topLeftX;
|
|
5613
|
+
for (let j = 0; j < column_widths.length; j++) {
|
|
5614
|
+
const segmentEndX = segmentStartX + column_widths[j];
|
|
5615
|
+
const isMerged = cells.some(
|
|
5616
|
+
(cell) => cell.start_row_index <= i && cell.end_row_index > i && cell.start_column_index <= j && cell.end_column_index >= j
|
|
5617
|
+
);
|
|
5618
|
+
if (!isMerged) {
|
|
5619
|
+
const start = applyToPoint42(transform, {
|
|
5620
|
+
x: segmentStartX,
|
|
5621
|
+
y: currentY
|
|
5622
|
+
});
|
|
5623
|
+
const end = applyToPoint42(transform, { x: segmentEndX, y: currentY });
|
|
5624
|
+
svgObjects.push({
|
|
5625
|
+
name: "line",
|
|
5626
|
+
type: "element",
|
|
5627
|
+
attributes: {
|
|
5628
|
+
x1: start.x.toString(),
|
|
5629
|
+
y1: start.y.toString(),
|
|
5630
|
+
x2: end.x.toString(),
|
|
5631
|
+
y2: end.y.toString(),
|
|
5632
|
+
stroke: "#666",
|
|
5633
|
+
"stroke-width": gridStrokeWidth.toString()
|
|
5634
|
+
},
|
|
5635
|
+
children: [],
|
|
5636
|
+
value: ""
|
|
5637
|
+
});
|
|
5638
|
+
}
|
|
5639
|
+
segmentStartX = segmentEndX;
|
|
5640
|
+
}
|
|
5641
|
+
}
|
|
5642
|
+
for (const cell of cells) {
|
|
5643
|
+
if (cell.text) {
|
|
5644
|
+
const cellWidth = column_widths.slice(cell.start_column_index, cell.end_column_index + 1).reduce((a, b) => a + b, 0);
|
|
5645
|
+
const cellHeight = row_heights.slice(cell.start_row_index, cell.end_row_index + 1).reduce((a, b) => a + b, 0);
|
|
5646
|
+
const cellTopLeftX = topLeftX + column_widths.slice(0, cell.start_column_index).reduce((a, b) => a + b, 0);
|
|
5647
|
+
const cellTopLeftY = topLeftY - row_heights.slice(0, cell.start_row_index).reduce((a, b) => a + b, 0);
|
|
5648
|
+
const { cell_padding = 0.2 } = schematicTable;
|
|
5649
|
+
const horizontal_align = cell.horizontal_align ?? "center";
|
|
5650
|
+
const vertical_align = cell.vertical_align ?? "middle";
|
|
5651
|
+
let realTextAnchorPos = {
|
|
5652
|
+
x: cellTopLeftX + cellWidth / 2,
|
|
5653
|
+
y: cellTopLeftY - cellHeight / 2
|
|
5654
|
+
};
|
|
5655
|
+
if (horizontal_align === "left") {
|
|
5656
|
+
realTextAnchorPos.x = cellTopLeftX + cell_padding;
|
|
5657
|
+
} else if (horizontal_align === "right") {
|
|
5658
|
+
realTextAnchorPos.x = cellTopLeftX + cellWidth - cell_padding;
|
|
5659
|
+
}
|
|
5660
|
+
if (vertical_align === "top") {
|
|
5661
|
+
realTextAnchorPos.y = cellTopLeftY - cell_padding;
|
|
5662
|
+
} else if (vertical_align === "bottom") {
|
|
5663
|
+
realTextAnchorPos.y = cellTopLeftY - cellHeight + cell_padding;
|
|
5664
|
+
}
|
|
5665
|
+
const screenTextAnchorPos = applyToPoint42(transform, realTextAnchorPos);
|
|
5666
|
+
const fontSize = getSchScreenFontSize(
|
|
5667
|
+
transform,
|
|
5668
|
+
"reference_designator",
|
|
5669
|
+
cell.font_size
|
|
5670
|
+
);
|
|
5671
|
+
const textAnchorMap = {
|
|
5672
|
+
left: "start",
|
|
5673
|
+
center: "middle",
|
|
5674
|
+
right: "end"
|
|
5675
|
+
};
|
|
5676
|
+
const dominantBaselineMap = {
|
|
5677
|
+
top: "hanging",
|
|
5678
|
+
middle: "middle",
|
|
5679
|
+
bottom: "ideographic"
|
|
5680
|
+
};
|
|
5681
|
+
svgObjects.push({
|
|
5682
|
+
name: "text",
|
|
5683
|
+
type: "element",
|
|
5684
|
+
attributes: {
|
|
5685
|
+
x: screenTextAnchorPos.x.toString(),
|
|
5686
|
+
y: screenTextAnchorPos.y.toString(),
|
|
5687
|
+
"font-size": `${fontSize}px`,
|
|
5688
|
+
"text-anchor": textAnchorMap[horizontal_align],
|
|
5689
|
+
"dominant-baseline": dominantBaselineMap[vertical_align],
|
|
5690
|
+
fill: colorMap2.schematic.sheet_label,
|
|
5691
|
+
"font-family": "sans-serif"
|
|
5692
|
+
},
|
|
5693
|
+
children: [
|
|
5694
|
+
{
|
|
5695
|
+
type: "text",
|
|
5696
|
+
value: cell.text,
|
|
5697
|
+
name: "",
|
|
5698
|
+
attributes: {},
|
|
5699
|
+
children: []
|
|
5700
|
+
}
|
|
5701
|
+
],
|
|
5702
|
+
value: ""
|
|
5703
|
+
});
|
|
5704
|
+
}
|
|
5705
|
+
}
|
|
5706
|
+
return [
|
|
5707
|
+
{
|
|
5708
|
+
name: "g",
|
|
5709
|
+
type: "element",
|
|
5710
|
+
attributes: {
|
|
5711
|
+
"data-schematic-table-id": schematicTable.schematic_table_id
|
|
5712
|
+
},
|
|
5713
|
+
children: svgObjects,
|
|
5714
|
+
value: ""
|
|
5715
|
+
}
|
|
5716
|
+
];
|
|
5717
|
+
};
|
|
5718
|
+
|
|
5415
5719
|
// lib/sch/convert-circuit-json-to-schematic-svg.ts
|
|
5416
5720
|
function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
5417
5721
|
const realBounds = getSchematicBoundsFromCircuitJson(circuitJson);
|
|
@@ -5482,6 +5786,7 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
5482
5786
|
const schText = [];
|
|
5483
5787
|
const voltageProbeSvgs = [];
|
|
5484
5788
|
const schBoxSvgs = [];
|
|
5789
|
+
const schTableSvgs = [];
|
|
5485
5790
|
for (const elm of circuitJson) {
|
|
5486
5791
|
if (elm.type === "schematic_debug_object") {
|
|
5487
5792
|
schDebugObjectSvgs.push(
|
|
@@ -5539,6 +5844,15 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
5539
5844
|
colorMap: colorMap2
|
|
5540
5845
|
})
|
|
5541
5846
|
);
|
|
5847
|
+
} else if (elm.type === "schematic_table") {
|
|
5848
|
+
schTableSvgs.push(
|
|
5849
|
+
...createSvgObjectsFromSchematicTable({
|
|
5850
|
+
schematicTable: elm,
|
|
5851
|
+
transform,
|
|
5852
|
+
colorMap: colorMap2,
|
|
5853
|
+
circuitJson
|
|
5854
|
+
})
|
|
5855
|
+
);
|
|
5542
5856
|
}
|
|
5543
5857
|
}
|
|
5544
5858
|
svgChildren.push(
|
|
@@ -5548,7 +5862,8 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
5548
5862
|
...schNetLabel,
|
|
5549
5863
|
...schText,
|
|
5550
5864
|
...schBoxSvgs,
|
|
5551
|
-
...voltageProbeSvgs
|
|
5865
|
+
...voltageProbeSvgs,
|
|
5866
|
+
...schTableSvgs
|
|
5552
5867
|
);
|
|
5553
5868
|
if (options?.labeledPoints) {
|
|
5554
5869
|
svgChildren.push(
|
|
@@ -5621,18 +5936,18 @@ var circuitJsonToSchematicSvg = convertCircuitJsonToSchematicSvg;
|
|
|
5621
5936
|
// lib/pcb/convert-circuit-json-to-solder-paste-mask.ts
|
|
5622
5937
|
import { stringify as stringify4 } from "svgson";
|
|
5623
5938
|
import {
|
|
5624
|
-
applyToPoint as
|
|
5939
|
+
applyToPoint as applyToPoint45,
|
|
5625
5940
|
compose as compose11,
|
|
5626
5941
|
scale as scale8,
|
|
5627
5942
|
translate as translate11
|
|
5628
5943
|
} from "transformation-matrix";
|
|
5629
5944
|
|
|
5630
5945
|
// lib/pcb/svg-object-fns/convert-circuit-json-to-solder-paste-mask.ts
|
|
5631
|
-
import { applyToPoint as
|
|
5946
|
+
import { applyToPoint as applyToPoint44 } from "transformation-matrix";
|
|
5632
5947
|
function createSvgObjectsFromSolderPaste(solderPaste, ctx) {
|
|
5633
5948
|
const { transform, layer: layerFilter } = ctx;
|
|
5634
5949
|
if (layerFilter && solderPaste.layer !== layerFilter) return [];
|
|
5635
|
-
const [x, y] =
|
|
5950
|
+
const [x, y] = applyToPoint44(transform, [solderPaste.x, solderPaste.y]);
|
|
5636
5951
|
if (solderPaste.shape === "rect" || solderPaste.shape === "rotated_rect") {
|
|
5637
5952
|
const width = solderPaste.width * Math.abs(transform.a);
|
|
5638
5953
|
const height = solderPaste.height * Math.abs(transform.d);
|
|
@@ -5831,8 +6146,8 @@ function createSvgObjects3({ elm, ctx }) {
|
|
|
5831
6146
|
}
|
|
5832
6147
|
}
|
|
5833
6148
|
function createSvgObjectFromPcbBoundary2(transform, minX, minY, maxX, maxY) {
|
|
5834
|
-
const [x1, y1] =
|
|
5835
|
-
const [x2, y2] =
|
|
6149
|
+
const [x1, y1] = applyToPoint45(transform, [minX, minY]);
|
|
6150
|
+
const [x2, y2] = applyToPoint45(transform, [maxX, maxY]);
|
|
5836
6151
|
const width = Math.abs(x2 - x1);
|
|
5837
6152
|
const height = Math.abs(y2 - y1);
|
|
5838
6153
|
const x = Math.min(x1, x2);
|