circuit-to-svg 0.0.89 → 0.0.91
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 +349 -20
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1281,6 +1281,8 @@ function getSchematicBoundsFromCircuitJson(soup, padding = 0.5) {
|
|
|
1281
1281
|
}
|
|
1282
1282
|
} else if (item.type === "schematic_text") {
|
|
1283
1283
|
updateBounds(item.position, { width: 0.1, height: 0.1 }, 0);
|
|
1284
|
+
} else if (item.type === "schematic_voltage_probe") {
|
|
1285
|
+
updateBounds(item.position, { width: 0.2, height: 0.4 }, 0);
|
|
1284
1286
|
}
|
|
1285
1287
|
}
|
|
1286
1288
|
minX -= padding;
|
|
@@ -1927,15 +1929,77 @@ function createSvgObjectsFromSchematicComponent(params) {
|
|
|
1927
1929
|
];
|
|
1928
1930
|
}
|
|
1929
1931
|
|
|
1930
|
-
// lib/sch/svg-object-fns/create-svg-objects-from-sch-
|
|
1932
|
+
// lib/sch/svg-object-fns/create-svg-objects-from-sch-voltage-probe.ts
|
|
1931
1933
|
import { applyToPoint as applyToPoint23 } from "transformation-matrix";
|
|
1934
|
+
function createSvgObjectsFromSchVoltageProbe(probe, transform) {
|
|
1935
|
+
const [screenX, screenY] = applyToPoint23(transform, [
|
|
1936
|
+
probe.position.x,
|
|
1937
|
+
probe.position.y
|
|
1938
|
+
]);
|
|
1939
|
+
const arrowLength = Math.abs(transform.a) * 0.6;
|
|
1940
|
+
const arrowWidth = Math.abs(transform.a) * 0.28;
|
|
1941
|
+
const baseX = screenX + arrowLength * Math.cos(-50 * Math.PI / 180);
|
|
1942
|
+
const baseY = screenY + arrowLength * Math.sin(-50 * Math.PI / 180);
|
|
1943
|
+
const tipX = screenX;
|
|
1944
|
+
const tipY = screenY;
|
|
1945
|
+
const arrowPath = [
|
|
1946
|
+
`M ${baseX},${baseY}`,
|
|
1947
|
+
`L ${tipX},${tipY}`,
|
|
1948
|
+
`M ${tipX},${tipY}`,
|
|
1949
|
+
`L ${tipX - arrowWidth * Math.cos((-50 + 150) * Math.PI / 180)},${tipY - arrowWidth * Math.sin((-50 + 150) * Math.PI / 180)}`,
|
|
1950
|
+
`L ${tipX - arrowWidth * Math.cos((-50 + 210) * Math.PI / 180)},${tipY - arrowWidth * Math.sin((-50 + 210) * Math.PI / 180)}`,
|
|
1951
|
+
"Z"
|
|
1952
|
+
].join(" ");
|
|
1953
|
+
return [
|
|
1954
|
+
{
|
|
1955
|
+
name: "path",
|
|
1956
|
+
type: "element",
|
|
1957
|
+
attributes: {
|
|
1958
|
+
d: arrowPath,
|
|
1959
|
+
stroke: colorMap.schematic.reference,
|
|
1960
|
+
fill: colorMap.schematic.reference,
|
|
1961
|
+
"stroke-width": `${getSchStrokeSize(transform)}px`
|
|
1962
|
+
},
|
|
1963
|
+
value: "",
|
|
1964
|
+
children: []
|
|
1965
|
+
},
|
|
1966
|
+
{
|
|
1967
|
+
type: "element",
|
|
1968
|
+
name: "text",
|
|
1969
|
+
value: "",
|
|
1970
|
+
attributes: {
|
|
1971
|
+
x: (baseX + 8 - (baseX - baseX)).toString(),
|
|
1972
|
+
y: (baseY - 10 + (baseY - baseY)).toString(),
|
|
1973
|
+
fill: colorMap.schematic.reference,
|
|
1974
|
+
"text-anchor": "middle",
|
|
1975
|
+
"dominant-baseline": "middle",
|
|
1976
|
+
"font-family": "sans-serif",
|
|
1977
|
+
"font-size": `${getSchScreenFontSize(transform, "reference_designator")}px`,
|
|
1978
|
+
"font-weight": "bold",
|
|
1979
|
+
"data-schematic-voltage-probe-id": probe.schematic_voltage_probe_id
|
|
1980
|
+
},
|
|
1981
|
+
children: [
|
|
1982
|
+
{
|
|
1983
|
+
type: "text",
|
|
1984
|
+
value: probe.voltage ? `${probe.voltage}V` : "",
|
|
1985
|
+
name: "",
|
|
1986
|
+
attributes: {},
|
|
1987
|
+
children: []
|
|
1988
|
+
}
|
|
1989
|
+
]
|
|
1990
|
+
}
|
|
1991
|
+
];
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
// lib/sch/svg-object-fns/create-svg-objects-from-sch-debug-object.ts
|
|
1995
|
+
import { applyToPoint as applyToPoint24 } from "transformation-matrix";
|
|
1932
1996
|
function createSvgObjectsFromSchDebugObject(debugObject, transform) {
|
|
1933
1997
|
if (debugObject.shape === "rect") {
|
|
1934
|
-
let [screenLeft, screenTop] =
|
|
1998
|
+
let [screenLeft, screenTop] = applyToPoint24(transform, [
|
|
1935
1999
|
debugObject.center.x - debugObject.size.width / 2,
|
|
1936
2000
|
debugObject.center.y - debugObject.size.height / 2
|
|
1937
2001
|
]);
|
|
1938
|
-
let [screenRight, screenBottom] =
|
|
2002
|
+
let [screenRight, screenBottom] = applyToPoint24(transform, [
|
|
1939
2003
|
debugObject.center.x + debugObject.size.width / 2,
|
|
1940
2004
|
debugObject.center.y + debugObject.size.height / 2
|
|
1941
2005
|
]);
|
|
@@ -1945,7 +2009,7 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
|
|
|
1945
2009
|
];
|
|
1946
2010
|
const width = Math.abs(screenRight - screenLeft);
|
|
1947
2011
|
const height = Math.abs(screenBottom - screenTop);
|
|
1948
|
-
const [screenCenterX, screenCenterY] =
|
|
2012
|
+
const [screenCenterX, screenCenterY] = applyToPoint24(transform, [
|
|
1949
2013
|
debugObject.center.x,
|
|
1950
2014
|
debugObject.center.y
|
|
1951
2015
|
]);
|
|
@@ -1991,11 +2055,11 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
|
|
|
1991
2055
|
];
|
|
1992
2056
|
}
|
|
1993
2057
|
if (debugObject.shape === "line") {
|
|
1994
|
-
const [screenStartX, screenStartY] =
|
|
2058
|
+
const [screenStartX, screenStartY] = applyToPoint24(transform, [
|
|
1995
2059
|
debugObject.start.x,
|
|
1996
2060
|
debugObject.start.y
|
|
1997
2061
|
]);
|
|
1998
|
-
const [screenEndX, screenEndY] =
|
|
2062
|
+
const [screenEndX, screenEndY] = applyToPoint24(transform, [
|
|
1999
2063
|
debugObject.end.x,
|
|
2000
2064
|
debugObject.end.y
|
|
2001
2065
|
]);
|
|
@@ -2045,7 +2109,7 @@ function createSvgObjectsFromSchDebugObject(debugObject, transform) {
|
|
|
2045
2109
|
}
|
|
2046
2110
|
|
|
2047
2111
|
// lib/sch/svg-object-fns/create-svg-objects-from-sch-trace.ts
|
|
2048
|
-
import { applyToPoint as
|
|
2112
|
+
import { applyToPoint as applyToPoint25 } from "transformation-matrix";
|
|
2049
2113
|
function createSchematicTrace(trace, transform) {
|
|
2050
2114
|
const edges = trace.edges;
|
|
2051
2115
|
if (edges.length === 0) return [];
|
|
@@ -2054,11 +2118,11 @@ function createSchematicTrace(trace, transform) {
|
|
|
2054
2118
|
for (let edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) {
|
|
2055
2119
|
const edge = edges[edgeIndex];
|
|
2056
2120
|
if (edge.is_crossing) continue;
|
|
2057
|
-
const [screenFromX, screenFromY] =
|
|
2121
|
+
const [screenFromX, screenFromY] = applyToPoint25(transform, [
|
|
2058
2122
|
edge.from.x,
|
|
2059
2123
|
edge.from.y
|
|
2060
2124
|
]);
|
|
2061
|
-
const [screenToX, screenToY] =
|
|
2125
|
+
const [screenToX, screenToY] = applyToPoint25(transform, [
|
|
2062
2126
|
edge.to.x,
|
|
2063
2127
|
edge.to.y
|
|
2064
2128
|
]);
|
|
@@ -2070,11 +2134,11 @@ function createSchematicTrace(trace, transform) {
|
|
|
2070
2134
|
}
|
|
2071
2135
|
for (const edge of edges) {
|
|
2072
2136
|
if (!edge.is_crossing) continue;
|
|
2073
|
-
const [screenFromX, screenFromY] =
|
|
2137
|
+
const [screenFromX, screenFromY] = applyToPoint25(transform, [
|
|
2074
2138
|
edge.from.x,
|
|
2075
2139
|
edge.from.y
|
|
2076
2140
|
]);
|
|
2077
|
-
const [screenToX, screenToY] =
|
|
2141
|
+
const [screenToX, screenToY] = applyToPoint25(transform, [
|
|
2078
2142
|
edge.to.x,
|
|
2079
2143
|
edge.to.y
|
|
2080
2144
|
]);
|
|
@@ -2150,7 +2214,7 @@ function createSchematicTrace(trace, transform) {
|
|
|
2150
2214
|
}
|
|
2151
2215
|
if (trace.junctions) {
|
|
2152
2216
|
for (const junction of trace.junctions) {
|
|
2153
|
-
const [screenX, screenY] =
|
|
2217
|
+
const [screenX, screenY] = applyToPoint25(transform, [
|
|
2154
2218
|
junction.x,
|
|
2155
2219
|
junction.y
|
|
2156
2220
|
]);
|
|
@@ -2183,7 +2247,7 @@ function createSchematicTrace(trace, transform) {
|
|
|
2183
2247
|
|
|
2184
2248
|
// lib/sch/svg-object-fns/create-svg-objects-for-sch-net-label.ts
|
|
2185
2249
|
import {
|
|
2186
|
-
applyToPoint as
|
|
2250
|
+
applyToPoint as applyToPoint26,
|
|
2187
2251
|
compose as compose6,
|
|
2188
2252
|
rotate as rotate3,
|
|
2189
2253
|
scale as scale3,
|
|
@@ -2979,14 +3043,14 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
|
|
|
2979
3043
|
const fontSizePx = getSchScreenFontSize(realToScreenTransform, "net_label");
|
|
2980
3044
|
const fontSizeMm = getSchMmFontSize("net_label");
|
|
2981
3045
|
const textWidthFSR = estimateTextWidth(schNetLabel.text || "");
|
|
2982
|
-
const screenCenter =
|
|
3046
|
+
const screenCenter = applyToPoint26(realToScreenTransform, schNetLabel.center);
|
|
2983
3047
|
const realTextGrowthVec = getUnitVectorFromOutsideToEdge(
|
|
2984
3048
|
schNetLabel.anchor_side
|
|
2985
3049
|
);
|
|
2986
3050
|
const screenTextGrowthVec = { ...realTextGrowthVec };
|
|
2987
3051
|
screenTextGrowthVec.y *= -1;
|
|
2988
3052
|
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 ?
|
|
3053
|
+
const screenAnchorPosition = schNetLabel.anchor_position ? applyToPoint26(realToScreenTransform, schNetLabel.anchor_position) : {
|
|
2990
3054
|
x: screenCenter.x - screenTextGrowthVec.x * fullWidthFsr * fontSizePx / 2,
|
|
2991
3055
|
y: screenCenter.y - screenTextGrowthVec.y * fullWidthFsr * fontSizePx / 2
|
|
2992
3056
|
};
|
|
@@ -3027,7 +3091,7 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
|
|
|
3027
3091
|
y: -0.6
|
|
3028
3092
|
}
|
|
3029
3093
|
].map(
|
|
3030
|
-
(fontRelativePoint) =>
|
|
3094
|
+
(fontRelativePoint) => applyToPoint26(
|
|
3031
3095
|
compose6(
|
|
3032
3096
|
realToScreenTransform,
|
|
3033
3097
|
translate6(realAnchorPosition.x, realAnchorPosition.y),
|
|
@@ -3104,9 +3168,9 @@ var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
|
|
|
3104
3168
|
};
|
|
3105
3169
|
|
|
3106
3170
|
// lib/sch/svg-object-fns/create-svg-objects-for-sch-text.ts
|
|
3107
|
-
import { applyToPoint as
|
|
3171
|
+
import { applyToPoint as applyToPoint27 } from "transformation-matrix";
|
|
3108
3172
|
var createSvgSchText = (elm, transform) => {
|
|
3109
|
-
const center =
|
|
3173
|
+
const center = applyToPoint27(transform, elm.position);
|
|
3110
3174
|
const textAnchorMap = {
|
|
3111
3175
|
center: "middle",
|
|
3112
3176
|
left: "start",
|
|
@@ -3147,6 +3211,265 @@ var createSvgSchText = (elm, transform) => {
|
|
|
3147
3211
|
};
|
|
3148
3212
|
};
|
|
3149
3213
|
|
|
3214
|
+
// lib/sch/svg-object-fns/create-svg-objects-for-sch-net-symbol.ts
|
|
3215
|
+
import {
|
|
3216
|
+
applyToPoint as applyToPoint28,
|
|
3217
|
+
compose as compose7,
|
|
3218
|
+
rotate as rotate4,
|
|
3219
|
+
scale as scale4,
|
|
3220
|
+
translate as translate7
|
|
3221
|
+
} from "transformation-matrix";
|
|
3222
|
+
import { symbols as symbols3 } from "schematic-symbols";
|
|
3223
|
+
var ninePointAnchorToTextAnchor2 = {
|
|
3224
|
+
top_left: "start",
|
|
3225
|
+
top_right: "end",
|
|
3226
|
+
middle_left: "start",
|
|
3227
|
+
middle_right: "end",
|
|
3228
|
+
bottom_left: "start",
|
|
3229
|
+
bottom_right: "end",
|
|
3230
|
+
center: "middle",
|
|
3231
|
+
middle_top: "middle",
|
|
3232
|
+
middle_bottom: "middle"
|
|
3233
|
+
};
|
|
3234
|
+
var ninePointAnchorToDominantBaseline2 = {
|
|
3235
|
+
top_left: "auto",
|
|
3236
|
+
top_right: "auto",
|
|
3237
|
+
bottom_left: "hanging",
|
|
3238
|
+
bottom_right: "hanging",
|
|
3239
|
+
center: "auto",
|
|
3240
|
+
middle_left: "middle",
|
|
3241
|
+
middle_right: "middle",
|
|
3242
|
+
middle_top: "auto",
|
|
3243
|
+
middle_bottom: "hanging"
|
|
3244
|
+
};
|
|
3245
|
+
var ARROW_POINT_WIDTH_FSR2 = 0.3;
|
|
3246
|
+
var END_PADDING_FSR2 = 0.3;
|
|
3247
|
+
var END_PADDING_EXTRA_PER_CHARACTER_FSR2 = 0.06;
|
|
3248
|
+
var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
3249
|
+
if (!schNetLabel.text) return [];
|
|
3250
|
+
const svgObjects = [];
|
|
3251
|
+
const symbol = symbols3["ground_horz"];
|
|
3252
|
+
if (!symbol) {
|
|
3253
|
+
svgObjects.push(
|
|
3254
|
+
createSvgSchErrorText({
|
|
3255
|
+
text: `Symbol not found: ${schNetLabel.symbol_name}`,
|
|
3256
|
+
realCenter: schNetLabel.center,
|
|
3257
|
+
realToScreenTransform
|
|
3258
|
+
})
|
|
3259
|
+
);
|
|
3260
|
+
return svgObjects;
|
|
3261
|
+
}
|
|
3262
|
+
const symbolPaths = symbol.primitives.filter((p) => p.type === "path");
|
|
3263
|
+
const symbolTexts = symbol.primitives.filter((p) => p.type === "text");
|
|
3264
|
+
const symbolCircles = symbol.primitives.filter((p) => p.type === "circle");
|
|
3265
|
+
const symbolBoxes = symbol.primitives.filter((p) => p.type === "box");
|
|
3266
|
+
const bounds = {
|
|
3267
|
+
minX: Math.min(...symbolPaths.flatMap((p) => p.points.map((pt) => pt.x))),
|
|
3268
|
+
maxX: Math.max(...symbolPaths.flatMap((p) => p.points.map((pt) => pt.x))),
|
|
3269
|
+
minY: Math.min(...symbolPaths.flatMap((p) => p.points.map((pt) => pt.y))),
|
|
3270
|
+
maxY: Math.max(...symbolPaths.flatMap((p) => p.points.map((pt) => pt.y)))
|
|
3271
|
+
};
|
|
3272
|
+
const fontSizeMm = getSchMmFontSize("net_label");
|
|
3273
|
+
const textWidthFSR = estimateTextWidth(schNetLabel.text || "");
|
|
3274
|
+
const fullWidthFsr = textWidthFSR + ARROW_POINT_WIDTH_FSR2 * 2 + END_PADDING_EXTRA_PER_CHARACTER_FSR2 * schNetLabel.text.length + END_PADDING_FSR2;
|
|
3275
|
+
const realTextGrowthVec = getUnitVectorFromOutsideToEdge(
|
|
3276
|
+
schNetLabel.anchor_side
|
|
3277
|
+
);
|
|
3278
|
+
const realAnchorPosition = schNetLabel.anchor_position ?? {
|
|
3279
|
+
x: schNetLabel.center.x - realTextGrowthVec.x * fullWidthFsr * fontSizeMm / 2,
|
|
3280
|
+
y: schNetLabel.center.y - realTextGrowthVec.y * fullWidthFsr * fontSizeMm / 2
|
|
3281
|
+
};
|
|
3282
|
+
const pathRotation = {
|
|
3283
|
+
left: 0,
|
|
3284
|
+
top: -90,
|
|
3285
|
+
bottom: 90,
|
|
3286
|
+
right: 180
|
|
3287
|
+
}[schNetLabel.anchor_side];
|
|
3288
|
+
const rotationMatrix = rotate4(pathRotation / 180 * Math.PI);
|
|
3289
|
+
const symbolBounds = {
|
|
3290
|
+
minX: Math.min(
|
|
3291
|
+
...symbol.primitives.flatMap(
|
|
3292
|
+
(p) => p.type === "path" ? p.points.map((pt) => pt.x) : []
|
|
3293
|
+
)
|
|
3294
|
+
),
|
|
3295
|
+
maxX: Math.max(
|
|
3296
|
+
...symbol.primitives.flatMap(
|
|
3297
|
+
(p) => p.type === "path" ? p.points.map((pt) => pt.x) : []
|
|
3298
|
+
)
|
|
3299
|
+
),
|
|
3300
|
+
minY: Math.min(
|
|
3301
|
+
...symbol.primitives.flatMap(
|
|
3302
|
+
(p) => p.type === "path" ? p.points.map((pt) => pt.y) : []
|
|
3303
|
+
)
|
|
3304
|
+
),
|
|
3305
|
+
maxY: Math.max(
|
|
3306
|
+
...symbol.primitives.flatMap(
|
|
3307
|
+
(p) => p.type === "path" ? p.points.map((pt) => pt.y) : []
|
|
3308
|
+
)
|
|
3309
|
+
)
|
|
3310
|
+
};
|
|
3311
|
+
const symbolEndPoint = {
|
|
3312
|
+
x: symbolBounds.minX,
|
|
3313
|
+
y: (symbolBounds.minY + symbolBounds.maxY) / 2
|
|
3314
|
+
};
|
|
3315
|
+
const rotatedSymbolEnd = applyToPoint28(rotationMatrix, symbolEndPoint);
|
|
3316
|
+
const symbolToRealTransform = compose7(
|
|
3317
|
+
translate7(
|
|
3318
|
+
realAnchorPosition.x - rotatedSymbolEnd.x,
|
|
3319
|
+
realAnchorPosition.y - rotatedSymbolEnd.y
|
|
3320
|
+
),
|
|
3321
|
+
rotationMatrix,
|
|
3322
|
+
scale4(1)
|
|
3323
|
+
// Use full symbol size
|
|
3324
|
+
);
|
|
3325
|
+
const [screenMinX, screenMinY] = applyToPoint28(
|
|
3326
|
+
compose7(realToScreenTransform, symbolToRealTransform),
|
|
3327
|
+
[bounds.minX, bounds.minY]
|
|
3328
|
+
);
|
|
3329
|
+
const [screenMaxX, screenMaxY] = applyToPoint28(
|
|
3330
|
+
compose7(realToScreenTransform, symbolToRealTransform),
|
|
3331
|
+
[bounds.maxX, bounds.maxY]
|
|
3332
|
+
);
|
|
3333
|
+
const rectHeight = Math.abs(screenMaxY - screenMinY);
|
|
3334
|
+
const rectY = Math.min(screenMinY, screenMaxY);
|
|
3335
|
+
const rectWidth = Math.abs(screenMaxX - screenMinX);
|
|
3336
|
+
const rectX = Math.min(screenMinX, screenMaxX);
|
|
3337
|
+
svgObjects.push({
|
|
3338
|
+
name: "rect",
|
|
3339
|
+
type: "element",
|
|
3340
|
+
value: "",
|
|
3341
|
+
attributes: {
|
|
3342
|
+
class: "component-overlay",
|
|
3343
|
+
x: rectX.toString(),
|
|
3344
|
+
y: rectY.toString(),
|
|
3345
|
+
width: rectWidth.toString(),
|
|
3346
|
+
height: rectHeight.toString(),
|
|
3347
|
+
fill: "transparent"
|
|
3348
|
+
},
|
|
3349
|
+
children: []
|
|
3350
|
+
});
|
|
3351
|
+
for (const path of symbolPaths) {
|
|
3352
|
+
const symbolPath = path.points.map((p, i) => {
|
|
3353
|
+
const [x, y] = applyToPoint28(
|
|
3354
|
+
compose7(realToScreenTransform, symbolToRealTransform),
|
|
3355
|
+
[p.x, p.y]
|
|
3356
|
+
);
|
|
3357
|
+
return `${i === 0 ? "M" : "L"} ${x} ${y}`;
|
|
3358
|
+
}).join(" ");
|
|
3359
|
+
svgObjects.push({
|
|
3360
|
+
name: "path",
|
|
3361
|
+
type: "element",
|
|
3362
|
+
attributes: {
|
|
3363
|
+
d: symbolPath + (path.closed ? " Z" : ""),
|
|
3364
|
+
stroke: colorMap.schematic.component_outline,
|
|
3365
|
+
fill: "none",
|
|
3366
|
+
"stroke-width": `${getSchStrokeSize(realToScreenTransform)}px`
|
|
3367
|
+
},
|
|
3368
|
+
value: "",
|
|
3369
|
+
children: []
|
|
3370
|
+
});
|
|
3371
|
+
}
|
|
3372
|
+
for (const text of symbolTexts) {
|
|
3373
|
+
const screenTextPos = applyToPoint28(
|
|
3374
|
+
compose7(realToScreenTransform, symbolToRealTransform),
|
|
3375
|
+
text
|
|
3376
|
+
);
|
|
3377
|
+
let textValue = text.text;
|
|
3378
|
+
if (textValue === "{REF}") {
|
|
3379
|
+
textValue = schNetLabel.text || "";
|
|
3380
|
+
} else if (textValue === "{VAL}") {
|
|
3381
|
+
textValue = "";
|
|
3382
|
+
}
|
|
3383
|
+
const rotationOffsetMap = {
|
|
3384
|
+
"0": { x: 8, y: -10 },
|
|
3385
|
+
// Left
|
|
3386
|
+
"-90": { x: 33, y: 28 },
|
|
3387
|
+
// Top
|
|
3388
|
+
"90": { x: -32.5, y: -38 },
|
|
3389
|
+
// Bottom
|
|
3390
|
+
"180": { x: -8.5, y: -2 }
|
|
3391
|
+
// Right
|
|
3392
|
+
};
|
|
3393
|
+
const currentRotation = pathRotation.toString();
|
|
3394
|
+
const rotationOffset = rotationOffsetMap[currentRotation] || { x: 0, y: 0 };
|
|
3395
|
+
const offsetScreenPos = {
|
|
3396
|
+
x: screenTextPos.x + rotationOffset.x,
|
|
3397
|
+
y: screenTextPos.y + rotationOffset.y
|
|
3398
|
+
};
|
|
3399
|
+
svgObjects.push({
|
|
3400
|
+
name: "text",
|
|
3401
|
+
type: "element",
|
|
3402
|
+
attributes: {
|
|
3403
|
+
x: offsetScreenPos.x.toString(),
|
|
3404
|
+
y: offsetScreenPos.y.toString(),
|
|
3405
|
+
fill: colorMap.schematic.label_global,
|
|
3406
|
+
"font-family": "sans-serif",
|
|
3407
|
+
"text-anchor": ninePointAnchorToTextAnchor2[text.anchor],
|
|
3408
|
+
"dominant-baseline": ninePointAnchorToDominantBaseline2[text.anchor],
|
|
3409
|
+
"font-size": `${getSchScreenFontSize(realToScreenTransform, "reference_designator")}px`
|
|
3410
|
+
},
|
|
3411
|
+
children: [
|
|
3412
|
+
{
|
|
3413
|
+
type: "text",
|
|
3414
|
+
value: textValue,
|
|
3415
|
+
name: "",
|
|
3416
|
+
attributes: {},
|
|
3417
|
+
children: []
|
|
3418
|
+
}
|
|
3419
|
+
],
|
|
3420
|
+
value: ""
|
|
3421
|
+
});
|
|
3422
|
+
}
|
|
3423
|
+
for (const box of symbolBoxes) {
|
|
3424
|
+
const screenBoxPos = applyToPoint28(
|
|
3425
|
+
compose7(realToScreenTransform, symbolToRealTransform),
|
|
3426
|
+
box
|
|
3427
|
+
);
|
|
3428
|
+
const symbolToScreenScale = compose7(
|
|
3429
|
+
realToScreenTransform,
|
|
3430
|
+
symbolToRealTransform
|
|
3431
|
+
).a;
|
|
3432
|
+
svgObjects.push({
|
|
3433
|
+
name: "rect",
|
|
3434
|
+
type: "element",
|
|
3435
|
+
attributes: {
|
|
3436
|
+
x: screenBoxPos.x.toString(),
|
|
3437
|
+
y: screenBoxPos.y.toString(),
|
|
3438
|
+
width: (box.width * symbolToScreenScale).toString(),
|
|
3439
|
+
height: (box.height * symbolToScreenScale).toString(),
|
|
3440
|
+
fill: "red"
|
|
3441
|
+
},
|
|
3442
|
+
value: "",
|
|
3443
|
+
children: []
|
|
3444
|
+
});
|
|
3445
|
+
}
|
|
3446
|
+
for (const circle of symbolCircles) {
|
|
3447
|
+
const screenCirclePos = applyToPoint28(
|
|
3448
|
+
compose7(realToScreenTransform, symbolToRealTransform),
|
|
3449
|
+
circle
|
|
3450
|
+
);
|
|
3451
|
+
const symbolToScreenScale = compose7(
|
|
3452
|
+
realToScreenTransform,
|
|
3453
|
+
symbolToRealTransform
|
|
3454
|
+
).a;
|
|
3455
|
+
svgObjects.push({
|
|
3456
|
+
name: "circle",
|
|
3457
|
+
type: "element",
|
|
3458
|
+
attributes: {
|
|
3459
|
+
cx: screenCirclePos.x.toString(),
|
|
3460
|
+
cy: screenCirclePos.y.toString(),
|
|
3461
|
+
r: (circle.radius * symbolToScreenScale).toString(),
|
|
3462
|
+
fill: "none",
|
|
3463
|
+
stroke: colorMap.schematic.component_outline,
|
|
3464
|
+
"stroke-width": `${getSchStrokeSize(realToScreenTransform)}px`
|
|
3465
|
+
},
|
|
3466
|
+
value: "",
|
|
3467
|
+
children: []
|
|
3468
|
+
});
|
|
3469
|
+
}
|
|
3470
|
+
return svgObjects;
|
|
3471
|
+
};
|
|
3472
|
+
|
|
3150
3473
|
// lib/sch/convert-circuit-json-to-schematic-svg.ts
|
|
3151
3474
|
function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
3152
3475
|
const realBounds = getSchematicBoundsFromCircuitJson(circuitJson);
|
|
@@ -3207,6 +3530,7 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
3207
3530
|
const schTraceSvgs = [];
|
|
3208
3531
|
const schNetLabel = [];
|
|
3209
3532
|
const schText = [];
|
|
3533
|
+
const voltageProbeSvgs = [];
|
|
3210
3534
|
for (const elm of circuitJson) {
|
|
3211
3535
|
if (elm.type === "schematic_debug_object") {
|
|
3212
3536
|
schDebugObjectSvgs.push(
|
|
@@ -3223,9 +3547,13 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
3223
3547
|
} else if (elm.type === "schematic_trace") {
|
|
3224
3548
|
schTraceSvgs.push(...createSchematicTrace(elm, transform));
|
|
3225
3549
|
} else if (elm.type === "schematic_net_label") {
|
|
3226
|
-
schNetLabel.push(...createSvgObjectsForSchNetLabel(elm, transform));
|
|
3550
|
+
elm.symbol_name ? schNetLabel.push(...createSvgObjectsForSchNetSymbol(elm, transform)) : schNetLabel.push(...createSvgObjectsForSchNetLabel(elm, transform));
|
|
3227
3551
|
} else if (elm.type === "schematic_text") {
|
|
3228
3552
|
schText.push(createSvgSchText(elm, transform));
|
|
3553
|
+
} else if (elm.type === "schematic_voltage_probe") {
|
|
3554
|
+
voltageProbeSvgs.push(
|
|
3555
|
+
...createSvgObjectsFromSchVoltageProbe(elm, transform)
|
|
3556
|
+
);
|
|
3229
3557
|
}
|
|
3230
3558
|
}
|
|
3231
3559
|
svgChildren.push(
|
|
@@ -3233,7 +3561,8 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
3233
3561
|
...schComponentSvgs,
|
|
3234
3562
|
...schTraceSvgs,
|
|
3235
3563
|
...schNetLabel,
|
|
3236
|
-
...schText
|
|
3564
|
+
...schText,
|
|
3565
|
+
...voltageProbeSvgs
|
|
3237
3566
|
);
|
|
3238
3567
|
if (options?.labeledPoints) {
|
|
3239
3568
|
svgChildren.push(
|