circuit-to-svg 0.0.90 → 0.0.92
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 -3
- package/dist/index.js +506 -105
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -865,6 +865,345 @@ function createSvgObjectFromPcbBoundary(transform, minX, minY, maxX, maxY) {
|
|
|
865
865
|
}
|
|
866
866
|
var circuitJsonToPcbSvg = convertCircuitJsonToPcbSvg;
|
|
867
867
|
|
|
868
|
+
// lib/assembly/convert-circuit-json-to-assembly-svg.ts
|
|
869
|
+
import { stringify as stringify2 } from "svgson";
|
|
870
|
+
import { su } from "@tscircuit/soup-util";
|
|
871
|
+
import {
|
|
872
|
+
applyToPoint as applyToPoint16,
|
|
873
|
+
compose as compose4,
|
|
874
|
+
scale as scale2,
|
|
875
|
+
translate as translate4
|
|
876
|
+
} from "transformation-matrix";
|
|
877
|
+
|
|
878
|
+
// lib/assembly/svg-object-fns/create-svg-objects-from-assembly-board.ts
|
|
879
|
+
import { applyToPoint as applyToPoint13 } from "transformation-matrix";
|
|
880
|
+
var DEFAULT_BOARD_STYLE = {
|
|
881
|
+
fill: "none",
|
|
882
|
+
stroke: "rgb(0,0,0)",
|
|
883
|
+
strokeOpacity: "0.8",
|
|
884
|
+
strokeWidthFactor: 0.2
|
|
885
|
+
};
|
|
886
|
+
function createSvgObjectsFromAssemblyBoard(pcbBoard, transform, style = {}) {
|
|
887
|
+
const { width, height, center, outline } = pcbBoard;
|
|
888
|
+
let path;
|
|
889
|
+
if (outline && Array.isArray(outline) && outline.length >= 3) {
|
|
890
|
+
path = outline.map((point, index) => {
|
|
891
|
+
const [x, y] = applyToPoint13(transform, [point.x, point.y]);
|
|
892
|
+
return index === 0 ? `M ${x} ${y}` : `L ${x} ${y}`;
|
|
893
|
+
}).join(" ");
|
|
894
|
+
} else {
|
|
895
|
+
const halfWidth = width / 2;
|
|
896
|
+
const halfHeight = height / 2;
|
|
897
|
+
const topLeft = applyToPoint13(transform, [
|
|
898
|
+
center.x - halfWidth,
|
|
899
|
+
center.y - halfHeight
|
|
900
|
+
]);
|
|
901
|
+
const topRight = applyToPoint13(transform, [
|
|
902
|
+
center.x + halfWidth,
|
|
903
|
+
center.y - halfHeight
|
|
904
|
+
]);
|
|
905
|
+
const bottomRight = applyToPoint13(transform, [
|
|
906
|
+
center.x + halfWidth,
|
|
907
|
+
center.y + halfHeight
|
|
908
|
+
]);
|
|
909
|
+
const bottomLeft = applyToPoint13(transform, [
|
|
910
|
+
center.x - halfWidth,
|
|
911
|
+
center.y + halfHeight
|
|
912
|
+
]);
|
|
913
|
+
path = `M ${topLeft[0]} ${topLeft[1]} L ${topRight[0]} ${topRight[1]} L ${bottomRight[0]} ${bottomRight[1]} L ${bottomLeft[0]} ${bottomLeft[1]}`;
|
|
914
|
+
}
|
|
915
|
+
path += " Z";
|
|
916
|
+
return [
|
|
917
|
+
{
|
|
918
|
+
name: "path",
|
|
919
|
+
type: "element",
|
|
920
|
+
value: "",
|
|
921
|
+
children: [],
|
|
922
|
+
attributes: {
|
|
923
|
+
class: "pcb-board",
|
|
924
|
+
d: path,
|
|
925
|
+
fill: style.fill ?? DEFAULT_BOARD_STYLE.fill,
|
|
926
|
+
stroke: style.stroke ?? DEFAULT_BOARD_STYLE.stroke,
|
|
927
|
+
"stroke-opacity": style.strokeOpacity ?? DEFAULT_BOARD_STYLE.strokeOpacity,
|
|
928
|
+
"stroke-width": ((style.strokeWidthFactor ?? DEFAULT_BOARD_STYLE.strokeWidthFactor) * Math.abs(transform.a)).toString()
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
];
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
// lib/assembly/svg-object-fns/create-svg-objects-from-assembly-component.ts
|
|
935
|
+
import { applyToPoint as applyToPoint15 } from "transformation-matrix";
|
|
936
|
+
|
|
937
|
+
// lib/utils/get-sch-font-size.ts
|
|
938
|
+
import "transformation-matrix";
|
|
939
|
+
var getSchMmFontSize = (textType) => {
|
|
940
|
+
return textType === "error" ? 0.05 : textType === "pin_number" ? 0.15 : 0.18;
|
|
941
|
+
};
|
|
942
|
+
var getSchScreenFontSize = (transform, textType) => {
|
|
943
|
+
return Math.abs(transform.a) * getSchMmFontSize(textType);
|
|
944
|
+
};
|
|
945
|
+
|
|
946
|
+
// lib/assembly/svg-object-fns/create-svg-objects-from-assembly-component.ts
|
|
947
|
+
function createSvgObjectsFromAssemblyComponent(component, transform, firstPin, name) {
|
|
948
|
+
const { center, width, height, rotation = 0 } = component;
|
|
949
|
+
const [x, y] = applyToPoint15(transform, [center.x, center.y]);
|
|
950
|
+
const [pinX, pinY] = applyToPoint15(transform, [firstPin.x, firstPin.y]);
|
|
951
|
+
const scaledWidth = width * Math.abs(transform.a);
|
|
952
|
+
const scaledHeight = height * Math.abs(transform.d);
|
|
953
|
+
return {
|
|
954
|
+
name: "g",
|
|
955
|
+
type: "element",
|
|
956
|
+
value: "",
|
|
957
|
+
attributes: {
|
|
958
|
+
transform: `translate(${x}, ${y}) rotate(${-rotation}) scale(1, -1)`
|
|
959
|
+
},
|
|
960
|
+
children: [
|
|
961
|
+
createComponentPath(
|
|
962
|
+
scaledWidth,
|
|
963
|
+
scaledHeight,
|
|
964
|
+
x,
|
|
965
|
+
y,
|
|
966
|
+
pinX,
|
|
967
|
+
pinY,
|
|
968
|
+
rotation
|
|
969
|
+
),
|
|
970
|
+
createComponentLabel(scaledWidth, scaledHeight, name ?? "", transform)
|
|
971
|
+
]
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
function createComponentPath(scaledWidth, scaledHeight, centerX, centerY, pinX, pinY, rotation) {
|
|
975
|
+
const w = scaledWidth / 2;
|
|
976
|
+
const h = scaledHeight / 2;
|
|
977
|
+
const cornerSize = Math.min(w, h) * 0.3;
|
|
978
|
+
const isTop = pinY > centerY;
|
|
979
|
+
const isLeft = pinX < centerX;
|
|
980
|
+
const path = getComponentPathData(w, h, cornerSize, isTop, isLeft, rotation);
|
|
981
|
+
return {
|
|
982
|
+
name: "path",
|
|
983
|
+
type: "element",
|
|
984
|
+
attributes: {
|
|
985
|
+
class: "assembly-component",
|
|
986
|
+
d: path
|
|
987
|
+
},
|
|
988
|
+
value: "",
|
|
989
|
+
children: []
|
|
990
|
+
};
|
|
991
|
+
}
|
|
992
|
+
function createComponentLabel(scaledWidth, scaledHeight, name, transform) {
|
|
993
|
+
const scale7 = Math.min(scaledWidth, scaledHeight) * 0.4;
|
|
994
|
+
const fontSize = getSchScreenFontSize(transform, "net_label") * (scale7 / 2.5);
|
|
995
|
+
const scaledFontSize = scale7 < 25 ? fontSize : fontSize * 0.6;
|
|
996
|
+
return {
|
|
997
|
+
name: "text",
|
|
998
|
+
type: "element",
|
|
999
|
+
attributes: {
|
|
1000
|
+
x: "0",
|
|
1001
|
+
y: `${0 + scaledFontSize / 8}`,
|
|
1002
|
+
class: "assembly-component-label",
|
|
1003
|
+
"text-anchor": "middle",
|
|
1004
|
+
"dominant-baseline": "middle",
|
|
1005
|
+
"font-size": `${scaledFontSize}px`,
|
|
1006
|
+
transform: "scale(1, -1)"
|
|
1007
|
+
},
|
|
1008
|
+
children: [
|
|
1009
|
+
{
|
|
1010
|
+
type: "text",
|
|
1011
|
+
value: name || "",
|
|
1012
|
+
name: "",
|
|
1013
|
+
attributes: {},
|
|
1014
|
+
children: []
|
|
1015
|
+
}
|
|
1016
|
+
],
|
|
1017
|
+
value: ""
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
function getComponentPathData(w, h, cornerSize, isTop, isLeft, rotation) {
|
|
1021
|
+
const rotatePoint = (x, y, angle) => {
|
|
1022
|
+
const rad = Math.PI / 180 * angle;
|
|
1023
|
+
const cos = Math.cos(rad);
|
|
1024
|
+
const sin = Math.sin(rad);
|
|
1025
|
+
return [x * cos - y * sin, x * sin + y * cos];
|
|
1026
|
+
};
|
|
1027
|
+
let corners;
|
|
1028
|
+
if (isTop && isLeft) {
|
|
1029
|
+
corners = [
|
|
1030
|
+
[-w, -h + cornerSize],
|
|
1031
|
+
[-w + cornerSize, -h],
|
|
1032
|
+
[w, -h],
|
|
1033
|
+
[w, h],
|
|
1034
|
+
[-w, h]
|
|
1035
|
+
];
|
|
1036
|
+
} else if (isTop && !isLeft) {
|
|
1037
|
+
corners = [
|
|
1038
|
+
[-w, -h],
|
|
1039
|
+
[w - cornerSize, -h],
|
|
1040
|
+
[w, -h + cornerSize],
|
|
1041
|
+
[w, h],
|
|
1042
|
+
[-w, h]
|
|
1043
|
+
];
|
|
1044
|
+
} else if (!isTop && isLeft) {
|
|
1045
|
+
corners = [
|
|
1046
|
+
[-w, -h],
|
|
1047
|
+
[w, -h],
|
|
1048
|
+
[w, h],
|
|
1049
|
+
[-w + cornerSize, h],
|
|
1050
|
+
[-w, h - cornerSize]
|
|
1051
|
+
];
|
|
1052
|
+
} else {
|
|
1053
|
+
corners = [
|
|
1054
|
+
[-w, -h],
|
|
1055
|
+
[w, -h],
|
|
1056
|
+
[w, h - cornerSize],
|
|
1057
|
+
[w - cornerSize, h],
|
|
1058
|
+
[-w, h]
|
|
1059
|
+
];
|
|
1060
|
+
}
|
|
1061
|
+
const rotatedCorners = corners.map(([x, y]) => rotatePoint(x, y, rotation));
|
|
1062
|
+
const path = rotatedCorners.map(([x, y], index) => index === 0 ? `M${x},${y}` : `L${x},${y}`).join(" ");
|
|
1063
|
+
return `${path} Z`;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
// lib/assembly/convert-circuit-json-to-assembly-svg.ts
|
|
1067
|
+
var OBJECT_ORDER2 = ["pcb_board", "pcb_component"];
|
|
1068
|
+
function convertCircuitJsonToAssemblySvg(soup, options) {
|
|
1069
|
+
let minX = Number.POSITIVE_INFINITY;
|
|
1070
|
+
let minY = Number.POSITIVE_INFINITY;
|
|
1071
|
+
let maxX = Number.NEGATIVE_INFINITY;
|
|
1072
|
+
let maxY = Number.NEGATIVE_INFINITY;
|
|
1073
|
+
for (const item of soup) {
|
|
1074
|
+
if (item.type === "pcb_board") {
|
|
1075
|
+
const center = item.center;
|
|
1076
|
+
const width = item.width || 0;
|
|
1077
|
+
const height = item.height || 0;
|
|
1078
|
+
minX = Math.min(minX, center.x - width / 2);
|
|
1079
|
+
minY = Math.min(minY, center.y - height / 2);
|
|
1080
|
+
maxX = Math.max(maxX, center.x + width / 2);
|
|
1081
|
+
maxY = Math.max(maxY, center.y + height / 2);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
const padding = 1;
|
|
1085
|
+
const circuitWidth = maxX - minX + 2 * padding;
|
|
1086
|
+
const circuitHeight = maxY - minY + 2 * padding;
|
|
1087
|
+
const svgWidth = options?.width ?? 800;
|
|
1088
|
+
const svgHeight = options?.height ?? 600;
|
|
1089
|
+
const scaleX = svgWidth / circuitWidth;
|
|
1090
|
+
const scaleY = svgHeight / circuitHeight;
|
|
1091
|
+
const scaleFactor = Math.min(scaleX, scaleY);
|
|
1092
|
+
const offsetX = (svgWidth - circuitWidth * scaleFactor) / 2;
|
|
1093
|
+
const offsetY = (svgHeight - circuitHeight * scaleFactor) / 2;
|
|
1094
|
+
const transform = compose4(
|
|
1095
|
+
translate4(
|
|
1096
|
+
offsetX - minX * scaleFactor + padding * scaleFactor,
|
|
1097
|
+
svgHeight - offsetY + minY * scaleFactor - padding * scaleFactor
|
|
1098
|
+
),
|
|
1099
|
+
scale2(scaleFactor, -scaleFactor)
|
|
1100
|
+
// Flip in y-direction
|
|
1101
|
+
);
|
|
1102
|
+
const svgObjects = soup.sort(
|
|
1103
|
+
(a, b) => (OBJECT_ORDER2.indexOf(b.type) ?? 9999) - (OBJECT_ORDER2.indexOf(a.type) ?? 9999)
|
|
1104
|
+
).flatMap((item) => createSvgObjects2(item, transform, soup));
|
|
1105
|
+
const svgObject = {
|
|
1106
|
+
name: "svg",
|
|
1107
|
+
type: "element",
|
|
1108
|
+
attributes: {
|
|
1109
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1110
|
+
width: svgWidth.toString(),
|
|
1111
|
+
height: svgHeight.toString()
|
|
1112
|
+
},
|
|
1113
|
+
value: "",
|
|
1114
|
+
children: [
|
|
1115
|
+
{
|
|
1116
|
+
name: "style",
|
|
1117
|
+
type: "element",
|
|
1118
|
+
children: [
|
|
1119
|
+
{
|
|
1120
|
+
type: "text",
|
|
1121
|
+
value: `
|
|
1122
|
+
.assembly-component { fill: #fff; stroke: #000; stroke-width: 3; }
|
|
1123
|
+
.assembly-board { fill: #f2f2f2; stroke: rgb(0,0,0); stroke-opacity: 0.8; }
|
|
1124
|
+
.assembly-component-label {
|
|
1125
|
+
fill: #000;
|
|
1126
|
+
font-family: Arial, serif;
|
|
1127
|
+
font-weight: bold;
|
|
1128
|
+
}
|
|
1129
|
+
.assembly-boundary { fill: none; stroke: #fff; stroke-width: 0.3; }
|
|
1130
|
+
`,
|
|
1131
|
+
name: "",
|
|
1132
|
+
attributes: {},
|
|
1133
|
+
children: []
|
|
1134
|
+
}
|
|
1135
|
+
],
|
|
1136
|
+
value: "",
|
|
1137
|
+
attributes: {}
|
|
1138
|
+
},
|
|
1139
|
+
{
|
|
1140
|
+
name: "rect",
|
|
1141
|
+
type: "element",
|
|
1142
|
+
attributes: {
|
|
1143
|
+
fill: "#fff",
|
|
1144
|
+
x: "0",
|
|
1145
|
+
y: "0",
|
|
1146
|
+
width: svgWidth.toString(),
|
|
1147
|
+
height: svgHeight.toString()
|
|
1148
|
+
},
|
|
1149
|
+
value: "",
|
|
1150
|
+
children: []
|
|
1151
|
+
},
|
|
1152
|
+
createSvgObjectFromAssemblyBoundary(transform, minX, minY, maxX, maxY),
|
|
1153
|
+
...svgObjects
|
|
1154
|
+
].filter((child) => child !== null)
|
|
1155
|
+
};
|
|
1156
|
+
return stringify2(svgObject);
|
|
1157
|
+
}
|
|
1158
|
+
function createSvgObjects2(elm, transform, soup) {
|
|
1159
|
+
const sourceComponents = su(soup).source_component.list();
|
|
1160
|
+
switch (elm.type) {
|
|
1161
|
+
case "pcb_board":
|
|
1162
|
+
return createSvgObjectsFromAssemblyBoard(elm, transform);
|
|
1163
|
+
case "pcb_component": {
|
|
1164
|
+
const sourceComponent = sourceComponents.find(
|
|
1165
|
+
(item) => item.source_component_id === elm.source_component_id
|
|
1166
|
+
);
|
|
1167
|
+
const ports = su(soup).pcb_port.list().filter((port) => port.pcb_component_id === elm.pcb_component_id);
|
|
1168
|
+
const firstPort = ports[0];
|
|
1169
|
+
if (sourceComponent && firstPort) {
|
|
1170
|
+
return [
|
|
1171
|
+
createSvgObjectsFromAssemblyComponent(
|
|
1172
|
+
elm,
|
|
1173
|
+
transform,
|
|
1174
|
+
{ x: firstPort.x, y: firstPort.y },
|
|
1175
|
+
sourceComponent.name
|
|
1176
|
+
)
|
|
1177
|
+
].filter(Boolean);
|
|
1178
|
+
}
|
|
1179
|
+
return [];
|
|
1180
|
+
}
|
|
1181
|
+
default:
|
|
1182
|
+
return [];
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
function createSvgObjectFromAssemblyBoundary(transform, minX, minY, maxX, maxY) {
|
|
1186
|
+
const [x1, y1] = applyToPoint16(transform, [minX, minY]);
|
|
1187
|
+
const [x2, y2] = applyToPoint16(transform, [maxX, maxY]);
|
|
1188
|
+
const width = Math.abs(x2 - x1);
|
|
1189
|
+
const height = Math.abs(y2 - y1);
|
|
1190
|
+
const x = Math.min(x1, x2);
|
|
1191
|
+
const y = Math.min(y1, y2);
|
|
1192
|
+
return {
|
|
1193
|
+
name: "rect",
|
|
1194
|
+
type: "element",
|
|
1195
|
+
value: "",
|
|
1196
|
+
children: [],
|
|
1197
|
+
attributes: {
|
|
1198
|
+
class: "assembly-boundary",
|
|
1199
|
+
x: x.toString(),
|
|
1200
|
+
y: y.toString(),
|
|
1201
|
+
width: width.toString(),
|
|
1202
|
+
height: height.toString()
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
|
|
868
1207
|
// lib/utils/colors.ts
|
|
869
1208
|
var colorMap = {
|
|
870
1209
|
"3d_viewer": {
|
|
@@ -1103,20 +1442,20 @@ var colorMap = {
|
|
|
1103
1442
|
};
|
|
1104
1443
|
|
|
1105
1444
|
// lib/sch/convert-circuit-json-to-schematic-svg.ts
|
|
1106
|
-
import { stringify as
|
|
1445
|
+
import { stringify as stringify3 } from "svgson";
|
|
1107
1446
|
import {
|
|
1108
1447
|
fromTriangles
|
|
1109
1448
|
} from "transformation-matrix";
|
|
1110
1449
|
|
|
1111
1450
|
// lib/sch/draw-schematic-grid.ts
|
|
1112
|
-
import { applyToPoint as
|
|
1451
|
+
import { applyToPoint as applyToPoint17 } from "transformation-matrix";
|
|
1113
1452
|
function drawSchematicGrid(params) {
|
|
1114
1453
|
const { minX, minY, maxX, maxY } = params.bounds;
|
|
1115
1454
|
const cellSize = params.cellSize ?? 1;
|
|
1116
1455
|
const labelCells = params.labelCells ?? false;
|
|
1117
1456
|
const gridLines = [];
|
|
1118
1457
|
const transformPoint = (x, y) => {
|
|
1119
|
-
const [transformedX, transformedY] =
|
|
1458
|
+
const [transformedX, transformedY] = applyToPoint17(params.transform, [x, y]);
|
|
1120
1459
|
return { x: transformedX, y: transformedY };
|
|
1121
1460
|
};
|
|
1122
1461
|
for (let x = Math.floor(minX); x <= Math.ceil(maxX); x += cellSize) {
|
|
@@ -1197,15 +1536,15 @@ function drawSchematicGrid(params) {
|
|
|
1197
1536
|
}
|
|
1198
1537
|
|
|
1199
1538
|
// lib/sch/draw-schematic-labeled-points.ts
|
|
1200
|
-
import { applyToPoint as
|
|
1539
|
+
import { applyToPoint as applyToPoint18 } from "transformation-matrix";
|
|
1201
1540
|
function drawSchematicLabeledPoints(params) {
|
|
1202
1541
|
const { points, transform } = params;
|
|
1203
1542
|
const labeledPointsGroup = [];
|
|
1204
1543
|
for (const point of points) {
|
|
1205
|
-
const [x1, y1] =
|
|
1206
|
-
const [x2, y2] =
|
|
1207
|
-
const [x3, y3] =
|
|
1208
|
-
const [x4, y4] =
|
|
1544
|
+
const [x1, y1] = applyToPoint18(transform, [point.x - 0.1, point.y - 0.1]);
|
|
1545
|
+
const [x2, y2] = applyToPoint18(transform, [point.x + 0.1, point.y + 0.1]);
|
|
1546
|
+
const [x3, y3] = applyToPoint18(transform, [point.x - 0.1, point.y + 0.1]);
|
|
1547
|
+
const [x4, y4] = applyToPoint18(transform, [point.x + 0.1, point.y - 0.1]);
|
|
1209
1548
|
labeledPointsGroup.push({
|
|
1210
1549
|
name: "path",
|
|
1211
1550
|
type: "element",
|
|
@@ -1216,7 +1555,7 @@ function drawSchematicLabeledPoints(params) {
|
|
|
1216
1555
|
"stroke-opacity": "0.7"
|
|
1217
1556
|
}
|
|
1218
1557
|
});
|
|
1219
|
-
const [labelX, labelY] =
|
|
1558
|
+
const [labelX, labelY] = applyToPoint18(transform, [
|
|
1220
1559
|
point.x + 0.15,
|
|
1221
1560
|
point.y - 0.15
|
|
1222
1561
|
]);
|
|
@@ -1281,6 +1620,8 @@ function getSchematicBoundsFromCircuitJson(soup, padding = 0.5) {
|
|
|
1281
1620
|
}
|
|
1282
1621
|
} else if (item.type === "schematic_text") {
|
|
1283
1622
|
updateBounds(item.position, { width: 0.1, height: 0.1 }, 0);
|
|
1623
|
+
} else if (item.type === "schematic_voltage_probe") {
|
|
1624
|
+
updateBounds(item.position, { width: 0.2, height: 0.4 }, 0);
|
|
1284
1625
|
}
|
|
1285
1626
|
}
|
|
1286
1627
|
minX -= padding;
|
|
@@ -1307,12 +1648,12 @@ function getSchematicBoundsFromCircuitJson(soup, padding = 0.5) {
|
|
|
1307
1648
|
}
|
|
1308
1649
|
|
|
1309
1650
|
// lib/sch/svg-object-fns/create-svg-objects-from-sch-component-with-symbol.ts
|
|
1310
|
-
import { su } from "@tscircuit/soup-util";
|
|
1651
|
+
import { su as su2 } from "@tscircuit/soup-util";
|
|
1311
1652
|
import { symbols } from "schematic-symbols";
|
|
1312
1653
|
import "svgson";
|
|
1313
1654
|
import {
|
|
1314
|
-
applyToPoint as
|
|
1315
|
-
compose as
|
|
1655
|
+
applyToPoint as applyToPoint20,
|
|
1656
|
+
compose as compose6
|
|
1316
1657
|
} from "transformation-matrix";
|
|
1317
1658
|
|
|
1318
1659
|
// lib/utils/get-sch-stroke-size.ts
|
|
@@ -1382,35 +1723,26 @@ var matchSchPortsToSymbolPorts = ({
|
|
|
1382
1723
|
};
|
|
1383
1724
|
|
|
1384
1725
|
// lib/utils/point-pairs-to-matrix.ts
|
|
1385
|
-
import { compose as
|
|
1726
|
+
import { compose as compose5, scale as scale3, translate as translate5 } from "transformation-matrix";
|
|
1386
1727
|
function pointPairsToMatrix(a1, a2, b1, b2) {
|
|
1387
1728
|
const tx = a2.x - a1.x;
|
|
1388
1729
|
const ty = a2.y - a1.y;
|
|
1389
1730
|
const originalDistance = Math.sqrt((b1.x - a1.x) ** 2 + (b1.y - a1.y) ** 2);
|
|
1390
1731
|
const transformedDistance = Math.sqrt((b2.x - a2.x) ** 2 + (b2.y - a2.y) ** 2);
|
|
1391
1732
|
const a = transformedDistance / originalDistance;
|
|
1392
|
-
const translateMatrix =
|
|
1393
|
-
const scaleMatrix =
|
|
1394
|
-
return
|
|
1733
|
+
const translateMatrix = translate5(tx, ty);
|
|
1734
|
+
const scaleMatrix = scale3(a, a);
|
|
1735
|
+
return compose5(translateMatrix, scaleMatrix);
|
|
1395
1736
|
}
|
|
1396
1737
|
|
|
1397
|
-
// lib/utils/get-sch-font-size.ts
|
|
1398
|
-
import "transformation-matrix";
|
|
1399
|
-
var getSchMmFontSize = (textType) => {
|
|
1400
|
-
return textType === "error" ? 0.05 : textType === "pin_number" ? 0.15 : 0.18;
|
|
1401
|
-
};
|
|
1402
|
-
var getSchScreenFontSize = (transform, textType) => {
|
|
1403
|
-
return Math.abs(transform.a) * getSchMmFontSize(textType);
|
|
1404
|
-
};
|
|
1405
|
-
|
|
1406
1738
|
// lib/sch/svg-object-fns/create-svg-error-text.ts
|
|
1407
|
-
import { applyToPoint as
|
|
1739
|
+
import { applyToPoint as applyToPoint19 } from "transformation-matrix";
|
|
1408
1740
|
var createSvgSchErrorText = ({
|
|
1409
1741
|
text,
|
|
1410
1742
|
realCenter,
|
|
1411
1743
|
realToScreenTransform
|
|
1412
1744
|
}) => {
|
|
1413
|
-
const screenCenter =
|
|
1745
|
+
const screenCenter = applyToPoint19(realToScreenTransform, realCenter);
|
|
1414
1746
|
return {
|
|
1415
1747
|
type: "element",
|
|
1416
1748
|
name: "text",
|
|
@@ -1475,10 +1807,10 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
|
|
|
1475
1807
|
})
|
|
1476
1808
|
];
|
|
1477
1809
|
}
|
|
1478
|
-
const schPorts =
|
|
1810
|
+
const schPorts = su2(circuitJson).schematic_port.list({
|
|
1479
1811
|
schematic_component_id: schComponent.schematic_component_id
|
|
1480
1812
|
});
|
|
1481
|
-
const srcComponent =
|
|
1813
|
+
const srcComponent = su2(circuitJson).source_component.get(
|
|
1482
1814
|
schComponent.source_component_id
|
|
1483
1815
|
);
|
|
1484
1816
|
const schPortsWithSymbolPorts = matchSchPortsToSymbolPorts({
|
|
@@ -1511,12 +1843,12 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
|
|
|
1511
1843
|
minY: Math.min(...paths.flatMap((p) => p.points.map((pt) => pt.y))),
|
|
1512
1844
|
maxY: Math.max(...paths.flatMap((p) => p.points.map((pt) => pt.y)))
|
|
1513
1845
|
};
|
|
1514
|
-
const [screenMinX, screenMinY] =
|
|
1515
|
-
|
|
1846
|
+
const [screenMinX, screenMinY] = applyToPoint20(
|
|
1847
|
+
compose6(realToScreenTransform, transformFromSymbolToReal),
|
|
1516
1848
|
[bounds.minX, bounds.minY]
|
|
1517
1849
|
);
|
|
1518
|
-
const [screenMaxX, screenMaxY] =
|
|
1519
|
-
|
|
1850
|
+
const [screenMaxX, screenMaxY] = applyToPoint20(
|
|
1851
|
+
compose6(realToScreenTransform, transformFromSymbolToReal),
|
|
1520
1852
|
[bounds.maxX, bounds.maxY]
|
|
1521
1853
|
);
|
|
1522
1854
|
const rectHeight = Math.abs(screenMaxY - screenMinY);
|
|
@@ -1544,8 +1876,8 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
|
|
|
1544
1876
|
name: "path",
|
|
1545
1877
|
attributes: {
|
|
1546
1878
|
d: points.map((p, i) => {
|
|
1547
|
-
const [x, y] =
|
|
1548
|
-
|
|
1879
|
+
const [x, y] = applyToPoint20(
|
|
1880
|
+
compose6(realToScreenTransform, transformFromSymbolToReal),
|
|
1549
1881
|
[p.x, p.y]
|
|
1550
1882
|
);
|
|
1551
1883
|
return `${i === 0 ? "M" : "L"} ${x} ${y}`;
|
|
@@ -1559,8 +1891,8 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
|
|
|
1559
1891
|
});
|
|
1560
1892
|
}
|
|
1561
1893
|
for (const text of texts) {
|
|
1562
|
-
const screenTextPos =
|
|
1563
|
-
|
|
1894
|
+
const screenTextPos = applyToPoint20(
|
|
1895
|
+
compose6(realToScreenTransform, transformFromSymbolToReal),
|
|
1564
1896
|
text
|
|
1565
1897
|
);
|
|
1566
1898
|
let textValue = "";
|
|
@@ -1593,11 +1925,11 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
|
|
|
1593
1925
|
});
|
|
1594
1926
|
}
|
|
1595
1927
|
for (const box of boxes) {
|
|
1596
|
-
const screenBoxPos =
|
|
1597
|
-
|
|
1928
|
+
const screenBoxPos = applyToPoint20(
|
|
1929
|
+
compose6(realToScreenTransform, transformFromSymbolToReal),
|
|
1598
1930
|
box
|
|
1599
1931
|
);
|
|
1600
|
-
const symbolToScreenScale =
|
|
1932
|
+
const symbolToScreenScale = compose6(
|
|
1601
1933
|
realToScreenTransform,
|
|
1602
1934
|
transformFromSymbolToReal
|
|
1603
1935
|
).a;
|
|
@@ -1616,8 +1948,8 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
|
|
|
1616
1948
|
});
|
|
1617
1949
|
}
|
|
1618
1950
|
for (const port of symbol.ports) {
|
|
1619
|
-
const screenPortPos =
|
|
1620
|
-
|
|
1951
|
+
const screenPortPos = applyToPoint20(
|
|
1952
|
+
compose6(realToScreenTransform, transformFromSymbolToReal),
|
|
1621
1953
|
port
|
|
1622
1954
|
);
|
|
1623
1955
|
svgObjects.push({
|
|
@@ -1639,18 +1971,18 @@ var createSvgObjectsFromSchematicComponentWithSymbol = ({
|
|
|
1639
1971
|
};
|
|
1640
1972
|
|
|
1641
1973
|
// lib/sch/svg-object-fns/create-svg-objects-from-sch-component-with-box.ts
|
|
1642
|
-
import { su as
|
|
1974
|
+
import { su as su5 } from "@tscircuit/soup-util";
|
|
1643
1975
|
import "schematic-symbols";
|
|
1644
1976
|
import "svgson";
|
|
1645
|
-
import { applyToPoint as
|
|
1977
|
+
import { applyToPoint as applyToPoint25 } from "transformation-matrix";
|
|
1646
1978
|
|
|
1647
1979
|
// lib/sch/svg-object-fns/create-svg-objects-from-sch-port-on-box.ts
|
|
1648
1980
|
import "transformation-matrix";
|
|
1649
1981
|
import "@tscircuit/soup-util";
|
|
1650
1982
|
|
|
1651
1983
|
// lib/sch/svg-object-fns/create-svg-objects-for-sch-port-box-line.ts
|
|
1652
|
-
import { applyToPoint as
|
|
1653
|
-
import { su as
|
|
1984
|
+
import { applyToPoint as applyToPoint21 } from "transformation-matrix";
|
|
1985
|
+
import { su as su3 } from "@tscircuit/soup-util";
|
|
1654
1986
|
var PIN_CIRCLE_RADIUS_MM = 0.02;
|
|
1655
1987
|
var createSvgObjectsForSchPortBoxLine = ({
|
|
1656
1988
|
schPort,
|
|
@@ -1659,7 +1991,7 @@ var createSvgObjectsForSchPortBoxLine = ({
|
|
|
1659
1991
|
circuitJson
|
|
1660
1992
|
}) => {
|
|
1661
1993
|
const svgObjects = [];
|
|
1662
|
-
const srcPort =
|
|
1994
|
+
const srcPort = su3(circuitJson).source_port.get(schPort.source_port_id);
|
|
1663
1995
|
const realEdgePos = {
|
|
1664
1996
|
x: schPort.center.x,
|
|
1665
1997
|
y: schPort.center.y
|
|
@@ -1679,8 +2011,8 @@ var createSvgObjectsForSchPortBoxLine = ({
|
|
|
1679
2011
|
realEdgePos.y += realPinLineLength;
|
|
1680
2012
|
break;
|
|
1681
2013
|
}
|
|
1682
|
-
const screenSchPortPos =
|
|
1683
|
-
const screenRealEdgePos =
|
|
2014
|
+
const screenSchPortPos = applyToPoint21(transform, schPort.center);
|
|
2015
|
+
const screenRealEdgePos = applyToPoint21(transform, realEdgePos);
|
|
1684
2016
|
const realLineEnd = { ...schPort.center };
|
|
1685
2017
|
switch (schPort.side_of_component) {
|
|
1686
2018
|
case "left":
|
|
@@ -1696,7 +2028,7 @@ var createSvgObjectsForSchPortBoxLine = ({
|
|
|
1696
2028
|
realLineEnd.y += PIN_CIRCLE_RADIUS_MM;
|
|
1697
2029
|
break;
|
|
1698
2030
|
}
|
|
1699
|
-
const screenLineEnd =
|
|
2031
|
+
const screenLineEnd = applyToPoint21(transform, realLineEnd);
|
|
1700
2032
|
svgObjects.push({
|
|
1701
2033
|
name: "line",
|
|
1702
2034
|
type: "element",
|
|
@@ -1743,7 +2075,7 @@ var getUnitVectorFromOutsideToEdge = (side) => {
|
|
|
1743
2075
|
};
|
|
1744
2076
|
|
|
1745
2077
|
// lib/sch/svg-object-fns/create-svg-objects-for-sch-port-pin-number-text.ts
|
|
1746
|
-
import { applyToPoint as
|
|
2078
|
+
import { applyToPoint as applyToPoint22 } from "transformation-matrix";
|
|
1747
2079
|
var createSvgObjectsForSchPortPinNumberText = (params) => {
|
|
1748
2080
|
const svgObjects = [];
|
|
1749
2081
|
const { schPort, schComponent, transform, circuitJson } = params;
|
|
@@ -1761,7 +2093,7 @@ var createSvgObjectsForSchPortPinNumberText = (params) => {
|
|
|
1761
2093
|
} else {
|
|
1762
2094
|
realPinNumberPos.y += 0.02;
|
|
1763
2095
|
}
|
|
1764
|
-
const screenPinNumberTextPos =
|
|
2096
|
+
const screenPinNumberTextPos = applyToPoint22(transform, realPinNumberPos);
|
|
1765
2097
|
svgObjects.push({
|
|
1766
2098
|
name: "text",
|
|
1767
2099
|
type: "element",
|
|
@@ -1791,7 +2123,7 @@ var createSvgObjectsForSchPortPinNumberText = (params) => {
|
|
|
1791
2123
|
};
|
|
1792
2124
|
|
|
1793
2125
|
// lib/sch/svg-object-fns/create-svg-objects-for-sch-port-pin-label.ts
|
|
1794
|
-
import { applyToPoint as
|
|
2126
|
+
import { applyToPoint as applyToPoint23 } from "transformation-matrix";
|
|
1795
2127
|
var LABEL_DIST_FROM_EDGE_MM = 0.1;
|
|
1796
2128
|
var createSvgObjectsForSchPortPinLabel = (params) => {
|
|
1797
2129
|
const svgObjects = [];
|
|
@@ -1805,7 +2137,7 @@ var createSvgObjectsForSchPortPinLabel = (params) => {
|
|
|
1805
2137
|
const realPinEdgeDistance = schPort.distance_from_component_edge ?? 0.4;
|
|
1806
2138
|
realPinNumberPos.x += vecToEdge.x * (realPinEdgeDistance + LABEL_DIST_FROM_EDGE_MM);
|
|
1807
2139
|
realPinNumberPos.y += vecToEdge.y * (realPinEdgeDistance + LABEL_DIST_FROM_EDGE_MM);
|
|
1808
|
-
const screenPinNumberTextPos =
|
|
2140
|
+
const screenPinNumberTextPos = applyToPoint23(transform, realPinNumberPos);
|
|
1809
2141
|
const label = schPort.display_pin_label ?? schComponent.port_labels?.[`${schPort.pin_number}`];
|
|
1810
2142
|
if (!label) return [];
|
|
1811
2143
|
svgObjects.push({
|
|
@@ -1853,11 +2185,11 @@ var createSvgObjectsFromSchematicComponentWithBox = ({
|
|
|
1853
2185
|
circuitJson
|
|
1854
2186
|
}) => {
|
|
1855
2187
|
const svgObjects = [];
|
|
1856
|
-
const componentScreenTopLeft =
|
|
2188
|
+
const componentScreenTopLeft = applyToPoint25(transform, {
|
|
1857
2189
|
x: schComponent.center.x - schComponent.size.width / 2,
|
|
1858
2190
|
y: schComponent.center.y + schComponent.size.height / 2
|
|
1859
2191
|
});
|
|
1860
|
-
const componentScreenBottomRight =
|
|
2192
|
+
const componentScreenBottomRight = applyToPoint25(transform, {
|
|
1861
2193
|
x: schComponent.center.x + schComponent.size.width / 2,
|
|
1862
2194
|
y: schComponent.center.y - schComponent.size.height / 2
|
|
1863
2195
|
});
|
|
@@ -1893,7 +2225,7 @@ var createSvgObjectsFromSchematicComponentWithBox = ({
|
|
|
1893
2225
|
},
|
|
1894
2226
|
children: []
|
|
1895
2227
|
});
|
|
1896
|
-
const schematicPorts =
|
|
2228
|
+
const schematicPorts = su5(circuitJson).schematic_port.list({
|
|
1897
2229
|
schematic_component_id: schComponent.schematic_component_id
|
|
1898
2230
|
});
|
|
1899
2231
|
for (const schPort of schematicPorts) {
|
|
@@ -1927,15 +2259,77 @@ function createSvgObjectsFromSchematicComponent(params) {
|
|
|
1927
2259
|
];
|
|
1928
2260
|
}
|
|
1929
2261
|
|
|
2262
|
+
// lib/sch/svg-object-fns/create-svg-objects-from-sch-voltage-probe.ts
|
|
2263
|
+
import { applyToPoint as applyToPoint26 } from "transformation-matrix";
|
|
2264
|
+
function createSvgObjectsFromSchVoltageProbe(probe, transform) {
|
|
2265
|
+
const [screenX, screenY] = applyToPoint26(transform, [
|
|
2266
|
+
probe.position.x,
|
|
2267
|
+
probe.position.y
|
|
2268
|
+
]);
|
|
2269
|
+
const arrowLength = Math.abs(transform.a) * 0.6;
|
|
2270
|
+
const arrowWidth = Math.abs(transform.a) * 0.28;
|
|
2271
|
+
const baseX = screenX + arrowLength * Math.cos(-50 * Math.PI / 180);
|
|
2272
|
+
const baseY = screenY + arrowLength * Math.sin(-50 * Math.PI / 180);
|
|
2273
|
+
const tipX = screenX;
|
|
2274
|
+
const tipY = screenY;
|
|
2275
|
+
const arrowPath = [
|
|
2276
|
+
`M ${baseX},${baseY}`,
|
|
2277
|
+
`L ${tipX},${tipY}`,
|
|
2278
|
+
`M ${tipX},${tipY}`,
|
|
2279
|
+
`L ${tipX - arrowWidth * Math.cos((-50 + 150) * Math.PI / 180)},${tipY - arrowWidth * Math.sin((-50 + 150) * Math.PI / 180)}`,
|
|
2280
|
+
`L ${tipX - arrowWidth * Math.cos((-50 + 210) * Math.PI / 180)},${tipY - arrowWidth * Math.sin((-50 + 210) * Math.PI / 180)}`,
|
|
2281
|
+
"Z"
|
|
2282
|
+
].join(" ");
|
|
2283
|
+
return [
|
|
2284
|
+
{
|
|
2285
|
+
name: "path",
|
|
2286
|
+
type: "element",
|
|
2287
|
+
attributes: {
|
|
2288
|
+
d: arrowPath,
|
|
2289
|
+
stroke: colorMap.schematic.reference,
|
|
2290
|
+
fill: colorMap.schematic.reference,
|
|
2291
|
+
"stroke-width": `${getSchStrokeSize(transform)}px`
|
|
2292
|
+
},
|
|
2293
|
+
value: "",
|
|
2294
|
+
children: []
|
|
2295
|
+
},
|
|
2296
|
+
{
|
|
2297
|
+
type: "element",
|
|
2298
|
+
name: "text",
|
|
2299
|
+
value: "",
|
|
2300
|
+
attributes: {
|
|
2301
|
+
x: (baseX + 8 - (baseX - baseX)).toString(),
|
|
2302
|
+
y: (baseY - 10 + (baseY - baseY)).toString(),
|
|
2303
|
+
fill: colorMap.schematic.reference,
|
|
2304
|
+
"text-anchor": "middle",
|
|
2305
|
+
"dominant-baseline": "middle",
|
|
2306
|
+
"font-family": "sans-serif",
|
|
2307
|
+
"font-size": `${getSchScreenFontSize(transform, "reference_designator")}px`,
|
|
2308
|
+
"font-weight": "bold",
|
|
2309
|
+
"data-schematic-voltage-probe-id": probe.schematic_voltage_probe_id
|
|
2310
|
+
},
|
|
2311
|
+
children: [
|
|
2312
|
+
{
|
|
2313
|
+
type: "text",
|
|
2314
|
+
value: probe.voltage ? `${probe.voltage}V` : "",
|
|
2315
|
+
name: "",
|
|
2316
|
+
attributes: {},
|
|
2317
|
+
children: []
|
|
2318
|
+
}
|
|
2319
|
+
]
|
|
2320
|
+
}
|
|
2321
|
+
];
|
|
2322
|
+
}
|
|
2323
|
+
|
|
1930
2324
|
// lib/sch/svg-object-fns/create-svg-objects-from-sch-debug-object.ts
|
|
1931
|
-
import { applyToPoint as
|
|
2325
|
+
import { applyToPoint as applyToPoint27 } from "transformation-matrix";
|
|
1932
2326
|
function createSvgObjectsFromSchDebugObject(debugObject, transform) {
|
|
1933
2327
|
if (debugObject.shape === "rect") {
|
|
1934
|
-
let [screenLeft, screenTop] =
|
|
2328
|
+
let [screenLeft, screenTop] = applyToPoint27(transform, [
|
|
1935
2329
|
debugObject.center.x - debugObject.size.width / 2,
|
|
1936
2330
|
debugObject.center.y - debugObject.size.height / 2
|
|
1937
2331
|
]);
|
|
1938
|
-
let [screenRight, screenBottom] =
|
|
2332
|
+
let [screenRight, screenBottom] = applyToPoint27(transform, [
|
|
1939
2333
|
debugObject.center.x + debugObject.size.width / 2,
|
|
1940
2334
|
debugObject.center.y + debugObject.size.height / 2
|
|
1941
2335
|
]);
|
|
@@ -1945,7 +2339,7 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
|
|
|
1945
2339
|
];
|
|
1946
2340
|
const width = Math.abs(screenRight - screenLeft);
|
|
1947
2341
|
const height = Math.abs(screenBottom - screenTop);
|
|
1948
|
-
const [screenCenterX, screenCenterY] =
|
|
2342
|
+
const [screenCenterX, screenCenterY] = applyToPoint27(transform, [
|
|
1949
2343
|
debugObject.center.x,
|
|
1950
2344
|
debugObject.center.y
|
|
1951
2345
|
]);
|
|
@@ -1991,11 +2385,11 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
|
|
|
1991
2385
|
];
|
|
1992
2386
|
}
|
|
1993
2387
|
if (debugObject.shape === "line") {
|
|
1994
|
-
const [screenStartX, screenStartY] =
|
|
2388
|
+
const [screenStartX, screenStartY] = applyToPoint27(transform, [
|
|
1995
2389
|
debugObject.start.x,
|
|
1996
2390
|
debugObject.start.y
|
|
1997
2391
|
]);
|
|
1998
|
-
const [screenEndX, screenEndY] =
|
|
2392
|
+
const [screenEndX, screenEndY] = applyToPoint27(transform, [
|
|
1999
2393
|
debugObject.end.x,
|
|
2000
2394
|
debugObject.end.y
|
|
2001
2395
|
]);
|
|
@@ -2045,7 +2439,7 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
|
|
|
2045
2439
|
}
|
|
2046
2440
|
|
|
2047
2441
|
// lib/sch/svg-object-fns/create-svg-objects-from-sch-trace.ts
|
|
2048
|
-
import { applyToPoint as
|
|
2442
|
+
import { applyToPoint as applyToPoint28 } from "transformation-matrix";
|
|
2049
2443
|
function createSchematicTrace(trace, transform) {
|
|
2050
2444
|
const edges = trace.edges;
|
|
2051
2445
|
if (edges.length === 0) return [];
|
|
@@ -2054,11 +2448,11 @@ function createSchematicTrace(trace, transform) {
|
|
|
2054
2448
|
for (let edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) {
|
|
2055
2449
|
const edge = edges[edgeIndex];
|
|
2056
2450
|
if (edge.is_crossing) continue;
|
|
2057
|
-
const [screenFromX, screenFromY] =
|
|
2451
|
+
const [screenFromX, screenFromY] = applyToPoint28(transform, [
|
|
2058
2452
|
edge.from.x,
|
|
2059
2453
|
edge.from.y
|
|
2060
2454
|
]);
|
|
2061
|
-
const [screenToX, screenToY] =
|
|
2455
|
+
const [screenToX, screenToY] = applyToPoint28(transform, [
|
|
2062
2456
|
edge.to.x,
|
|
2063
2457
|
edge.to.y
|
|
2064
2458
|
]);
|
|
@@ -2070,11 +2464,11 @@ function createSchematicTrace(trace, transform) {
|
|
|
2070
2464
|
}
|
|
2071
2465
|
for (const edge of edges) {
|
|
2072
2466
|
if (!edge.is_crossing) continue;
|
|
2073
|
-
const [screenFromX, screenFromY] =
|
|
2467
|
+
const [screenFromX, screenFromY] = applyToPoint28(transform, [
|
|
2074
2468
|
edge.from.x,
|
|
2075
2469
|
edge.from.y
|
|
2076
2470
|
]);
|
|
2077
|
-
const [screenToX, screenToY] =
|
|
2471
|
+
const [screenToX, screenToY] = applyToPoint28(transform, [
|
|
2078
2472
|
edge.to.x,
|
|
2079
2473
|
edge.to.y
|
|
2080
2474
|
]);
|
|
@@ -2150,7 +2544,7 @@ function createSchematicTrace(trace, transform) {
|
|
|
2150
2544
|
}
|
|
2151
2545
|
if (trace.junctions) {
|
|
2152
2546
|
for (const junction of trace.junctions) {
|
|
2153
|
-
const [screenX, screenY] =
|
|
2547
|
+
const [screenX, screenY] = applyToPoint28(transform, [
|
|
2154
2548
|
junction.x,
|
|
2155
2549
|
junction.y
|
|
2156
2550
|
]);
|
|
@@ -2183,11 +2577,11 @@ function createSchematicTrace(trace, transform) {
|
|
|
2183
2577
|
|
|
2184
2578
|
// lib/sch/svg-object-fns/create-svg-objects-for-sch-net-label.ts
|
|
2185
2579
|
import {
|
|
2186
|
-
applyToPoint as
|
|
2187
|
-
compose as
|
|
2580
|
+
applyToPoint as applyToPoint29,
|
|
2581
|
+
compose as compose7,
|
|
2188
2582
|
rotate as rotate3,
|
|
2189
|
-
scale as
|
|
2190
|
-
translate as
|
|
2583
|
+
scale as scale4,
|
|
2584
|
+
translate as translate7
|
|
2191
2585
|
} from "transformation-matrix";
|
|
2192
2586
|
|
|
2193
2587
|
// lib/sch/arial-text-metrics.ts
|
|
@@ -2979,14 +3373,14 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
|
|
|
2979
3373
|
const fontSizePx = getSchScreenFontSize(realToScreenTransform, "net_label");
|
|
2980
3374
|
const fontSizeMm = getSchMmFontSize("net_label");
|
|
2981
3375
|
const textWidthFSR = estimateTextWidth(schNetLabel.text || "");
|
|
2982
|
-
const screenCenter =
|
|
3376
|
+
const screenCenter = applyToPoint29(realToScreenTransform, schNetLabel.center);
|
|
2983
3377
|
const realTextGrowthVec = getUnitVectorFromOutsideToEdge(
|
|
2984
3378
|
schNetLabel.anchor_side
|
|
2985
3379
|
);
|
|
2986
3380
|
const screenTextGrowthVec = { ...realTextGrowthVec };
|
|
2987
3381
|
screenTextGrowthVec.y *= -1;
|
|
2988
3382
|
const fullWidthFsr = textWidthFSR + ARROW_POINT_WIDTH_FSR * 2 + END_PADDING_EXTRA_PER_CHARACTER_FSR * schNetLabel.text.length + END_PADDING_FSR;
|
|
2989
|
-
const screenAnchorPosition = schNetLabel.anchor_position ?
|
|
3383
|
+
const screenAnchorPosition = schNetLabel.anchor_position ? applyToPoint29(realToScreenTransform, schNetLabel.anchor_position) : {
|
|
2990
3384
|
x: screenCenter.x - screenTextGrowthVec.x * fullWidthFsr * fontSizePx / 2,
|
|
2991
3385
|
y: screenCenter.y - screenTextGrowthVec.y * fullWidthFsr * fontSizePx / 2
|
|
2992
3386
|
};
|
|
@@ -3027,11 +3421,11 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
|
|
|
3027
3421
|
y: -0.6
|
|
3028
3422
|
}
|
|
3029
3423
|
].map(
|
|
3030
|
-
(fontRelativePoint) =>
|
|
3031
|
-
|
|
3424
|
+
(fontRelativePoint) => applyToPoint29(
|
|
3425
|
+
compose7(
|
|
3032
3426
|
realToScreenTransform,
|
|
3033
|
-
|
|
3034
|
-
|
|
3427
|
+
translate7(realAnchorPosition.x, realAnchorPosition.y),
|
|
3428
|
+
scale4(fontSizeMm),
|
|
3035
3429
|
rotate3(pathRotation / 180 * Math.PI)
|
|
3036
3430
|
),
|
|
3037
3431
|
fontRelativePoint
|
|
@@ -3104,9 +3498,9 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
|
|
|
3104
3498
|
};
|
|
3105
3499
|
|
|
3106
3500
|
// lib/sch/svg-object-fns/create-svg-objects-for-sch-text.ts
|
|
3107
|
-
import { applyToPoint as
|
|
3501
|
+
import { applyToPoint as applyToPoint30 } from "transformation-matrix";
|
|
3108
3502
|
var createSvgSchText = (elm, transform) => {
|
|
3109
|
-
const center =
|
|
3503
|
+
const center = applyToPoint30(transform, elm.position);
|
|
3110
3504
|
const textAnchorMap = {
|
|
3111
3505
|
center: "middle",
|
|
3112
3506
|
left: "start",
|
|
@@ -3149,11 +3543,11 @@ var createSvgSchText = (elm, transform) => {
|
|
|
3149
3543
|
|
|
3150
3544
|
// lib/sch/svg-object-fns/create-svg-objects-for-sch-net-symbol.ts
|
|
3151
3545
|
import {
|
|
3152
|
-
applyToPoint as
|
|
3153
|
-
compose as
|
|
3546
|
+
applyToPoint as applyToPoint31,
|
|
3547
|
+
compose as compose8,
|
|
3154
3548
|
rotate as rotate4,
|
|
3155
|
-
scale as
|
|
3156
|
-
translate as
|
|
3549
|
+
scale as scale5,
|
|
3550
|
+
translate as translate8
|
|
3157
3551
|
} from "transformation-matrix";
|
|
3158
3552
|
import { symbols as symbols3 } from "schematic-symbols";
|
|
3159
3553
|
var ninePointAnchorToTextAnchor2 = {
|
|
@@ -3248,22 +3642,22 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3248
3642
|
x: symbolBounds.minX,
|
|
3249
3643
|
y: (symbolBounds.minY + symbolBounds.maxY) / 2
|
|
3250
3644
|
};
|
|
3251
|
-
const rotatedSymbolEnd =
|
|
3252
|
-
const symbolToRealTransform =
|
|
3253
|
-
|
|
3645
|
+
const rotatedSymbolEnd = applyToPoint31(rotationMatrix, symbolEndPoint);
|
|
3646
|
+
const symbolToRealTransform = compose8(
|
|
3647
|
+
translate8(
|
|
3254
3648
|
realAnchorPosition.x - rotatedSymbolEnd.x,
|
|
3255
3649
|
realAnchorPosition.y - rotatedSymbolEnd.y
|
|
3256
3650
|
),
|
|
3257
3651
|
rotationMatrix,
|
|
3258
|
-
|
|
3652
|
+
scale5(1)
|
|
3259
3653
|
// Use full symbol size
|
|
3260
3654
|
);
|
|
3261
|
-
const [screenMinX, screenMinY] =
|
|
3262
|
-
|
|
3655
|
+
const [screenMinX, screenMinY] = applyToPoint31(
|
|
3656
|
+
compose8(realToScreenTransform, symbolToRealTransform),
|
|
3263
3657
|
[bounds.minX, bounds.minY]
|
|
3264
3658
|
);
|
|
3265
|
-
const [screenMaxX, screenMaxY] =
|
|
3266
|
-
|
|
3659
|
+
const [screenMaxX, screenMaxY] = applyToPoint31(
|
|
3660
|
+
compose8(realToScreenTransform, symbolToRealTransform),
|
|
3267
3661
|
[bounds.maxX, bounds.maxY]
|
|
3268
3662
|
);
|
|
3269
3663
|
const rectHeight = Math.abs(screenMaxY - screenMinY);
|
|
@@ -3286,8 +3680,8 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3286
3680
|
});
|
|
3287
3681
|
for (const path of symbolPaths) {
|
|
3288
3682
|
const symbolPath = path.points.map((p, i) => {
|
|
3289
|
-
const [x, y] =
|
|
3290
|
-
|
|
3683
|
+
const [x, y] = applyToPoint31(
|
|
3684
|
+
compose8(realToScreenTransform, symbolToRealTransform),
|
|
3291
3685
|
[p.x, p.y]
|
|
3292
3686
|
);
|
|
3293
3687
|
return `${i === 0 ? "M" : "L"} ${x} ${y}`;
|
|
@@ -3306,8 +3700,8 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3306
3700
|
});
|
|
3307
3701
|
}
|
|
3308
3702
|
for (const text of symbolTexts) {
|
|
3309
|
-
const screenTextPos =
|
|
3310
|
-
|
|
3703
|
+
const screenTextPos = applyToPoint31(
|
|
3704
|
+
compose8(realToScreenTransform, symbolToRealTransform),
|
|
3311
3705
|
text
|
|
3312
3706
|
);
|
|
3313
3707
|
let textValue = text.text;
|
|
@@ -3357,11 +3751,11 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3357
3751
|
});
|
|
3358
3752
|
}
|
|
3359
3753
|
for (const box of symbolBoxes) {
|
|
3360
|
-
const screenBoxPos =
|
|
3361
|
-
|
|
3754
|
+
const screenBoxPos = applyToPoint31(
|
|
3755
|
+
compose8(realToScreenTransform, symbolToRealTransform),
|
|
3362
3756
|
box
|
|
3363
3757
|
);
|
|
3364
|
-
const symbolToScreenScale =
|
|
3758
|
+
const symbolToScreenScale = compose8(
|
|
3365
3759
|
realToScreenTransform,
|
|
3366
3760
|
symbolToRealTransform
|
|
3367
3761
|
).a;
|
|
@@ -3380,11 +3774,11 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3380
3774
|
});
|
|
3381
3775
|
}
|
|
3382
3776
|
for (const circle of symbolCircles) {
|
|
3383
|
-
const screenCirclePos =
|
|
3384
|
-
|
|
3777
|
+
const screenCirclePos = applyToPoint31(
|
|
3778
|
+
compose8(realToScreenTransform, symbolToRealTransform),
|
|
3385
3779
|
circle
|
|
3386
3780
|
);
|
|
3387
|
-
const symbolToScreenScale =
|
|
3781
|
+
const symbolToScreenScale = compose8(
|
|
3388
3782
|
realToScreenTransform,
|
|
3389
3783
|
symbolToRealTransform
|
|
3390
3784
|
).a;
|
|
@@ -3466,6 +3860,7 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
3466
3860
|
const schTraceSvgs = [];
|
|
3467
3861
|
const schNetLabel = [];
|
|
3468
3862
|
const schText = [];
|
|
3863
|
+
const voltageProbeSvgs = [];
|
|
3469
3864
|
for (const elm of circuitJson) {
|
|
3470
3865
|
if (elm.type === "schematic_debug_object") {
|
|
3471
3866
|
schDebugObjectSvgs.push(
|
|
@@ -3485,6 +3880,10 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
3485
3880
|
elm.symbol_name ? schNetLabel.push(...createSvgObjectsForSchNetSymbol(elm, transform)) : schNetLabel.push(...createSvgObjectsForSchNetLabel(elm, transform));
|
|
3486
3881
|
} else if (elm.type === "schematic_text") {
|
|
3487
3882
|
schText.push(createSvgSchText(elm, transform));
|
|
3883
|
+
} else if (elm.type === "schematic_voltage_probe") {
|
|
3884
|
+
voltageProbeSvgs.push(
|
|
3885
|
+
...createSvgObjectsFromSchVoltageProbe(elm, transform)
|
|
3886
|
+
);
|
|
3488
3887
|
}
|
|
3489
3888
|
}
|
|
3490
3889
|
svgChildren.push(
|
|
@@ -3492,7 +3891,8 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
3492
3891
|
...schComponentSvgs,
|
|
3493
3892
|
...schTraceSvgs,
|
|
3494
3893
|
...schNetLabel,
|
|
3495
|
-
...schText
|
|
3894
|
+
...schText,
|
|
3895
|
+
...voltageProbeSvgs
|
|
3496
3896
|
);
|
|
3497
3897
|
if (options?.labeledPoints) {
|
|
3498
3898
|
svgChildren.push(
|
|
@@ -3550,12 +3950,13 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
3550
3950
|
],
|
|
3551
3951
|
value: ""
|
|
3552
3952
|
};
|
|
3553
|
-
return
|
|
3953
|
+
return stringify3(svgObject);
|
|
3554
3954
|
}
|
|
3555
3955
|
var circuitJsonToSchematicSvg = convertCircuitJsonToSchematicSvg;
|
|
3556
3956
|
export {
|
|
3557
3957
|
circuitJsonToPcbSvg,
|
|
3558
3958
|
circuitJsonToSchematicSvg,
|
|
3959
|
+
convertCircuitJsonToAssemblySvg,
|
|
3559
3960
|
convertCircuitJsonToPcbSvg,
|
|
3560
3961
|
convertCircuitJsonToSchematicSvg
|
|
3561
3962
|
};
|