circuit-to-svg 0.0.92 → 0.0.94
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 +246 -229
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2568,7 +2568,9 @@ function createSchematicTrace(trace, transform) {
|
|
|
2568
2568
|
type: "element",
|
|
2569
2569
|
value: "",
|
|
2570
2570
|
attributes: {
|
|
2571
|
-
class: "trace"
|
|
2571
|
+
class: "trace",
|
|
2572
|
+
"data-circuit-json-type": "schematic_trace",
|
|
2573
|
+
"data-schematic-trace-id": trace.schematic_trace_id
|
|
2572
2574
|
},
|
|
2573
2575
|
children: svgObjects
|
|
2574
2576
|
}
|
|
@@ -2577,11 +2579,11 @@ function createSchematicTrace(trace, transform) {
|
|
|
2577
2579
|
|
|
2578
2580
|
// lib/sch/svg-object-fns/create-svg-objects-for-sch-net-label.ts
|
|
2579
2581
|
import {
|
|
2580
|
-
applyToPoint as
|
|
2581
|
-
compose as
|
|
2582
|
-
rotate as
|
|
2583
|
-
scale as
|
|
2584
|
-
translate as
|
|
2582
|
+
applyToPoint as applyToPoint30,
|
|
2583
|
+
compose as compose8,
|
|
2584
|
+
rotate as rotate4,
|
|
2585
|
+
scale as scale5,
|
|
2586
|
+
translate as translate8
|
|
2585
2587
|
} from "transformation-matrix";
|
|
2586
2588
|
|
|
2587
2589
|
// lib/sch/arial-text-metrics.ts
|
|
@@ -3363,193 +3365,22 @@ var estimateTextWidth = (text) => {
|
|
|
3363
3365
|
return totalWidth / 27;
|
|
3364
3366
|
};
|
|
3365
3367
|
|
|
3366
|
-
// lib/sch/svg-object-fns/create-svg-objects-for-sch-net-label.ts
|
|
3367
|
-
var ARROW_POINT_WIDTH_FSR = 0.3;
|
|
3368
|
-
var END_PADDING_FSR = 0.3;
|
|
3369
|
-
var END_PADDING_EXTRA_PER_CHARACTER_FSR = 0.06;
|
|
3370
|
-
var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
|
|
3371
|
-
if (!schNetLabel.text) return [];
|
|
3372
|
-
const svgObjects = [];
|
|
3373
|
-
const fontSizePx = getSchScreenFontSize(realToScreenTransform, "net_label");
|
|
3374
|
-
const fontSizeMm = getSchMmFontSize("net_label");
|
|
3375
|
-
const textWidthFSR = estimateTextWidth(schNetLabel.text || "");
|
|
3376
|
-
const screenCenter = applyToPoint29(realToScreenTransform, schNetLabel.center);
|
|
3377
|
-
const realTextGrowthVec = getUnitVectorFromOutsideToEdge(
|
|
3378
|
-
schNetLabel.anchor_side
|
|
3379
|
-
);
|
|
3380
|
-
const screenTextGrowthVec = { ...realTextGrowthVec };
|
|
3381
|
-
screenTextGrowthVec.y *= -1;
|
|
3382
|
-
const fullWidthFsr = textWidthFSR + ARROW_POINT_WIDTH_FSR * 2 + END_PADDING_EXTRA_PER_CHARACTER_FSR * schNetLabel.text.length + END_PADDING_FSR;
|
|
3383
|
-
const screenAnchorPosition = schNetLabel.anchor_position ? applyToPoint29(realToScreenTransform, schNetLabel.anchor_position) : {
|
|
3384
|
-
x: screenCenter.x - screenTextGrowthVec.x * fullWidthFsr * fontSizePx / 2,
|
|
3385
|
-
y: screenCenter.y - screenTextGrowthVec.y * fullWidthFsr * fontSizePx / 2
|
|
3386
|
-
};
|
|
3387
|
-
const realAnchorPosition = schNetLabel.anchor_position ?? {
|
|
3388
|
-
x: schNetLabel.center.x - realTextGrowthVec.x * fullWidthFsr * fontSizeMm / 2,
|
|
3389
|
-
y: schNetLabel.center.y - realTextGrowthVec.y * fullWidthFsr * fontSizeMm / 2
|
|
3390
|
-
};
|
|
3391
|
-
const pathRotation = {
|
|
3392
|
-
left: 0,
|
|
3393
|
-
top: -90,
|
|
3394
|
-
bottom: 90,
|
|
3395
|
-
right: 180
|
|
3396
|
-
}[schNetLabel.anchor_side];
|
|
3397
|
-
const screenOutlinePoints = [
|
|
3398
|
-
// Arrow point in font-relative coordinates
|
|
3399
|
-
{
|
|
3400
|
-
x: 0,
|
|
3401
|
-
y: 0
|
|
3402
|
-
},
|
|
3403
|
-
// Top left corner in font-relative coordinates
|
|
3404
|
-
{
|
|
3405
|
-
x: ARROW_POINT_WIDTH_FSR,
|
|
3406
|
-
y: 0.6
|
|
3407
|
-
},
|
|
3408
|
-
// Top right corner in font-relative coordinates
|
|
3409
|
-
{
|
|
3410
|
-
x: ARROW_POINT_WIDTH_FSR * 2 + END_PADDING_FSR + END_PADDING_EXTRA_PER_CHARACTER_FSR * schNetLabel.text.length + textWidthFSR,
|
|
3411
|
-
y: 0.6
|
|
3412
|
-
},
|
|
3413
|
-
// Bottom right corner in font-relative coordinates
|
|
3414
|
-
{
|
|
3415
|
-
x: ARROW_POINT_WIDTH_FSR * 2 + END_PADDING_FSR + END_PADDING_EXTRA_PER_CHARACTER_FSR * schNetLabel.text.length + textWidthFSR,
|
|
3416
|
-
y: -0.6
|
|
3417
|
-
},
|
|
3418
|
-
// Bottom left corner in font-relative coordinates
|
|
3419
|
-
{
|
|
3420
|
-
x: ARROW_POINT_WIDTH_FSR,
|
|
3421
|
-
y: -0.6
|
|
3422
|
-
}
|
|
3423
|
-
].map(
|
|
3424
|
-
(fontRelativePoint) => applyToPoint29(
|
|
3425
|
-
compose7(
|
|
3426
|
-
realToScreenTransform,
|
|
3427
|
-
translate7(realAnchorPosition.x, realAnchorPosition.y),
|
|
3428
|
-
scale4(fontSizeMm),
|
|
3429
|
-
rotate3(pathRotation / 180 * Math.PI)
|
|
3430
|
-
),
|
|
3431
|
-
fontRelativePoint
|
|
3432
|
-
)
|
|
3433
|
-
);
|
|
3434
|
-
const pathD = `
|
|
3435
|
-
M ${screenOutlinePoints[0].x},${screenOutlinePoints[0].y}
|
|
3436
|
-
L ${screenOutlinePoints[1].x},${screenOutlinePoints[1].y}
|
|
3437
|
-
L ${screenOutlinePoints[2].x},${screenOutlinePoints[2].y}
|
|
3438
|
-
L ${screenOutlinePoints[3].x},${screenOutlinePoints[3].y}
|
|
3439
|
-
L ${screenOutlinePoints[4].x},${screenOutlinePoints[4].y}
|
|
3440
|
-
Z
|
|
3441
|
-
`;
|
|
3442
|
-
svgObjects.push({
|
|
3443
|
-
name: "path",
|
|
3444
|
-
type: "element",
|
|
3445
|
-
attributes: {
|
|
3446
|
-
class: "net-label",
|
|
3447
|
-
d: pathD,
|
|
3448
|
-
fill: "white",
|
|
3449
|
-
stroke: colorMap.schematic.label_global,
|
|
3450
|
-
"stroke-width": `${getSchStrokeSize(realToScreenTransform)}px`
|
|
3451
|
-
},
|
|
3452
|
-
value: "",
|
|
3453
|
-
children: []
|
|
3454
|
-
});
|
|
3455
|
-
const screenTextPos = {
|
|
3456
|
-
x: screenAnchorPosition.x + screenTextGrowthVec.x * fontSizePx * 0.5,
|
|
3457
|
-
y: screenAnchorPosition.y + screenTextGrowthVec.y * fontSizePx * 0.5
|
|
3458
|
-
};
|
|
3459
|
-
const textAnchor = {
|
|
3460
|
-
left: "start",
|
|
3461
|
-
top: "start",
|
|
3462
|
-
bottom: "start",
|
|
3463
|
-
right: "end"
|
|
3464
|
-
}[schNetLabel.anchor_side];
|
|
3465
|
-
const textTransformString = {
|
|
3466
|
-
left: "",
|
|
3467
|
-
right: "",
|
|
3468
|
-
top: `rotate(90 ${screenTextPos.x} ${screenTextPos.y})`,
|
|
3469
|
-
bottom: `rotate(-90 ${screenTextPos.x} ${screenTextPos.y})`
|
|
3470
|
-
}[schNetLabel.anchor_side];
|
|
3471
|
-
svgObjects.push({
|
|
3472
|
-
name: "text",
|
|
3473
|
-
type: "element",
|
|
3474
|
-
attributes: {
|
|
3475
|
-
class: "net-label-text",
|
|
3476
|
-
x: screenTextPos.x.toString(),
|
|
3477
|
-
y: screenTextPos.y.toString(),
|
|
3478
|
-
fill: colorMap.schematic.label_global,
|
|
3479
|
-
"text-anchor": textAnchor,
|
|
3480
|
-
"dominant-baseline": "central",
|
|
3481
|
-
"font-family": "sans-serif",
|
|
3482
|
-
"font-variant-numeric": "tabular-nums",
|
|
3483
|
-
"font-size": `${fontSizePx}px`,
|
|
3484
|
-
transform: textTransformString
|
|
3485
|
-
},
|
|
3486
|
-
children: [
|
|
3487
|
-
{
|
|
3488
|
-
type: "text",
|
|
3489
|
-
value: schNetLabel.text || "",
|
|
3490
|
-
name: "",
|
|
3491
|
-
attributes: {},
|
|
3492
|
-
children: []
|
|
3493
|
-
}
|
|
3494
|
-
],
|
|
3495
|
-
value: ""
|
|
3496
|
-
});
|
|
3497
|
-
return svgObjects;
|
|
3498
|
-
};
|
|
3499
|
-
|
|
3500
|
-
// lib/sch/svg-object-fns/create-svg-objects-for-sch-text.ts
|
|
3501
|
-
import { applyToPoint as applyToPoint30 } from "transformation-matrix";
|
|
3502
|
-
var createSvgSchText = (elm, transform) => {
|
|
3503
|
-
const center = applyToPoint30(transform, elm.position);
|
|
3504
|
-
const textAnchorMap = {
|
|
3505
|
-
center: "middle",
|
|
3506
|
-
left: "start",
|
|
3507
|
-
right: "end",
|
|
3508
|
-
top: "middle",
|
|
3509
|
-
bottom: "middle"
|
|
3510
|
-
};
|
|
3511
|
-
const dominantBaselineMap = {
|
|
3512
|
-
center: "middle",
|
|
3513
|
-
left: "middle",
|
|
3514
|
-
right: "middle",
|
|
3515
|
-
top: "hanging",
|
|
3516
|
-
bottom: "ideographic"
|
|
3517
|
-
};
|
|
3518
|
-
return {
|
|
3519
|
-
type: "element",
|
|
3520
|
-
name: "text",
|
|
3521
|
-
value: "",
|
|
3522
|
-
attributes: {
|
|
3523
|
-
x: center.x.toString(),
|
|
3524
|
-
y: center.y.toString(),
|
|
3525
|
-
fill: elm.color ?? colorMap.schematic.sheet_label,
|
|
3526
|
-
"text-anchor": textAnchorMap[elm.anchor],
|
|
3527
|
-
"dominant-baseline": dominantBaselineMap[elm.anchor],
|
|
3528
|
-
"font-family": "sans-serif",
|
|
3529
|
-
"font-size": `${getSchScreenFontSize(transform, "reference_designator")}px`,
|
|
3530
|
-
transform: `rotate(${elm.rotation}, ${center.x}, ${center.y})`
|
|
3531
|
-
},
|
|
3532
|
-
children: [
|
|
3533
|
-
{
|
|
3534
|
-
type: "text",
|
|
3535
|
-
value: elm.text,
|
|
3536
|
-
name: elm.schematic_text_id,
|
|
3537
|
-
attributes: {},
|
|
3538
|
-
children: []
|
|
3539
|
-
}
|
|
3540
|
-
]
|
|
3541
|
-
};
|
|
3542
|
-
};
|
|
3543
|
-
|
|
3544
|
-
// lib/sch/svg-object-fns/create-svg-objects-for-sch-net-symbol.ts
|
|
3368
|
+
// lib/sch/svg-object-fns/create-svg-objects-for-sch-net-label-with-symbol.ts
|
|
3545
3369
|
import {
|
|
3546
|
-
applyToPoint as
|
|
3547
|
-
compose as
|
|
3548
|
-
rotate as
|
|
3549
|
-
scale as
|
|
3550
|
-
translate as
|
|
3370
|
+
applyToPoint as applyToPoint29,
|
|
3371
|
+
compose as compose7,
|
|
3372
|
+
rotate as rotate3,
|
|
3373
|
+
scale as scale4,
|
|
3374
|
+
translate as translate7
|
|
3551
3375
|
} from "transformation-matrix";
|
|
3552
3376
|
import { symbols as symbols3 } from "schematic-symbols";
|
|
3377
|
+
|
|
3378
|
+
// lib/utils/net-label-utils.ts
|
|
3379
|
+
import "transformation-matrix";
|
|
3380
|
+
import "schematic-symbols";
|
|
3381
|
+
var ARROW_POINT_WIDTH_FSR = 0.3;
|
|
3382
|
+
var END_PADDING_FSR = 0.3;
|
|
3383
|
+
var END_PADDING_EXTRA_PER_CHARACTER_FSR = 0.06;
|
|
3553
3384
|
var ninePointAnchorToTextAnchor2 = {
|
|
3554
3385
|
top_left: "start",
|
|
3555
3386
|
top_right: "end",
|
|
@@ -3572,13 +3403,27 @@ var ninePointAnchorToDominantBaseline2 = {
|
|
|
3572
3403
|
middle_top: "auto",
|
|
3573
3404
|
middle_bottom: "hanging"
|
|
3574
3405
|
};
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3406
|
+
function getTextOffsets(pathRotation, transform) {
|
|
3407
|
+
const scale7 = Math.abs(transform.a);
|
|
3408
|
+
const baseOffset = scale7 * 0.1;
|
|
3409
|
+
const rotationOffsetMap = {
|
|
3410
|
+
"0": { x: baseOffset * 0.8, y: -baseOffset },
|
|
3411
|
+
// Left
|
|
3412
|
+
"-90": { x: baseOffset * 3.3, y: baseOffset * 2.8 },
|
|
3413
|
+
// Top
|
|
3414
|
+
"90": { x: -baseOffset * 3.55, y: -baseOffset * 4.2 },
|
|
3415
|
+
// Bottom
|
|
3416
|
+
"180": { x: -baseOffset * 0.85, y: -baseOffset * 0.2 }
|
|
3417
|
+
// Right
|
|
3418
|
+
};
|
|
3419
|
+
return rotationOffsetMap[pathRotation.toString()] || { x: 0, y: 0 };
|
|
3420
|
+
}
|
|
3421
|
+
|
|
3422
|
+
// lib/sch/svg-object-fns/create-svg-objects-for-sch-net-label-with-symbol.ts
|
|
3423
|
+
var createSvgObjectsForSchNetLabelWithSymbol = (schNetLabel, realToScreenTransform) => {
|
|
3579
3424
|
if (!schNetLabel.text) return [];
|
|
3580
3425
|
const svgObjects = [];
|
|
3581
|
-
const symbol = symbols3[
|
|
3426
|
+
const symbol = symbols3[schNetLabel.symbol_name];
|
|
3582
3427
|
if (!symbol) {
|
|
3583
3428
|
svgObjects.push(
|
|
3584
3429
|
createSvgSchErrorText({
|
|
@@ -3601,7 +3446,7 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3601
3446
|
};
|
|
3602
3447
|
const fontSizeMm = getSchMmFontSize("net_label");
|
|
3603
3448
|
const textWidthFSR = estimateTextWidth(schNetLabel.text || "");
|
|
3604
|
-
const fullWidthFsr = textWidthFSR +
|
|
3449
|
+
const fullWidthFsr = textWidthFSR + ARROW_POINT_WIDTH_FSR * 2 + END_PADDING_EXTRA_PER_CHARACTER_FSR * schNetLabel.text.length + END_PADDING_FSR;
|
|
3605
3450
|
const realTextGrowthVec = getUnitVectorFromOutsideToEdge(
|
|
3606
3451
|
schNetLabel.anchor_side
|
|
3607
3452
|
);
|
|
@@ -3615,7 +3460,7 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3615
3460
|
bottom: 90,
|
|
3616
3461
|
right: 180
|
|
3617
3462
|
}[schNetLabel.anchor_side];
|
|
3618
|
-
const rotationMatrix =
|
|
3463
|
+
const rotationMatrix = rotate3(pathRotation / 180 * Math.PI);
|
|
3619
3464
|
const symbolBounds = {
|
|
3620
3465
|
minX: Math.min(
|
|
3621
3466
|
...symbol.primitives.flatMap(
|
|
@@ -3642,22 +3487,22 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3642
3487
|
x: symbolBounds.minX,
|
|
3643
3488
|
y: (symbolBounds.minY + symbolBounds.maxY) / 2
|
|
3644
3489
|
};
|
|
3645
|
-
const rotatedSymbolEnd =
|
|
3646
|
-
const symbolToRealTransform =
|
|
3647
|
-
|
|
3490
|
+
const rotatedSymbolEnd = applyToPoint29(rotationMatrix, symbolEndPoint);
|
|
3491
|
+
const symbolToRealTransform = compose7(
|
|
3492
|
+
translate7(
|
|
3648
3493
|
realAnchorPosition.x - rotatedSymbolEnd.x,
|
|
3649
3494
|
realAnchorPosition.y - rotatedSymbolEnd.y
|
|
3650
3495
|
),
|
|
3651
3496
|
rotationMatrix,
|
|
3652
|
-
|
|
3497
|
+
scale4(1)
|
|
3653
3498
|
// Use full symbol size
|
|
3654
3499
|
);
|
|
3655
|
-
const [screenMinX, screenMinY] =
|
|
3656
|
-
|
|
3500
|
+
const [screenMinX, screenMinY] = applyToPoint29(
|
|
3501
|
+
compose7(realToScreenTransform, symbolToRealTransform),
|
|
3657
3502
|
[bounds.minX, bounds.minY]
|
|
3658
3503
|
);
|
|
3659
|
-
const [screenMaxX, screenMaxY] =
|
|
3660
|
-
|
|
3504
|
+
const [screenMaxX, screenMaxY] = applyToPoint29(
|
|
3505
|
+
compose7(realToScreenTransform, symbolToRealTransform),
|
|
3661
3506
|
[bounds.maxX, bounds.maxY]
|
|
3662
3507
|
);
|
|
3663
3508
|
const rectHeight = Math.abs(screenMaxY - screenMinY);
|
|
@@ -3680,8 +3525,8 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3680
3525
|
});
|
|
3681
3526
|
for (const path of symbolPaths) {
|
|
3682
3527
|
const symbolPath = path.points.map((p, i) => {
|
|
3683
|
-
const [x, y] =
|
|
3684
|
-
|
|
3528
|
+
const [x, y] = applyToPoint29(
|
|
3529
|
+
compose7(realToScreenTransform, symbolToRealTransform),
|
|
3685
3530
|
[p.x, p.y]
|
|
3686
3531
|
);
|
|
3687
3532
|
return `${i === 0 ? "M" : "L"} ${x} ${y}`;
|
|
@@ -3700,8 +3545,8 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3700
3545
|
});
|
|
3701
3546
|
}
|
|
3702
3547
|
for (const text of symbolTexts) {
|
|
3703
|
-
const screenTextPos =
|
|
3704
|
-
|
|
3548
|
+
const screenTextPos = applyToPoint29(
|
|
3549
|
+
compose7(realToScreenTransform, symbolToRealTransform),
|
|
3705
3550
|
text
|
|
3706
3551
|
);
|
|
3707
3552
|
let textValue = text.text;
|
|
@@ -3710,18 +3555,9 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3710
3555
|
} else if (textValue === "{VAL}") {
|
|
3711
3556
|
textValue = "";
|
|
3712
3557
|
}
|
|
3713
|
-
const
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
"-90": { x: 33, y: 28 },
|
|
3717
|
-
// Top
|
|
3718
|
-
"90": { x: -32.5, y: -38 },
|
|
3719
|
-
// Bottom
|
|
3720
|
-
"180": { x: -8.5, y: -2 }
|
|
3721
|
-
// Right
|
|
3722
|
-
};
|
|
3723
|
-
const currentRotation = pathRotation.toString();
|
|
3724
|
-
const rotationOffset = rotationOffsetMap[currentRotation] || { x: 0, y: 0 };
|
|
3558
|
+
const scale7 = Math.abs(realToScreenTransform.a);
|
|
3559
|
+
const baseOffset = scale7 * 0.1;
|
|
3560
|
+
const rotationOffset = getTextOffsets(pathRotation, realToScreenTransform);
|
|
3725
3561
|
const offsetScreenPos = {
|
|
3726
3562
|
x: screenTextPos.x + rotationOffset.x,
|
|
3727
3563
|
y: screenTextPos.y + rotationOffset.y
|
|
@@ -3732,7 +3568,7 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3732
3568
|
attributes: {
|
|
3733
3569
|
x: offsetScreenPos.x.toString(),
|
|
3734
3570
|
y: offsetScreenPos.y.toString(),
|
|
3735
|
-
fill: colorMap.schematic.
|
|
3571
|
+
fill: colorMap.schematic.label_local,
|
|
3736
3572
|
"font-family": "sans-serif",
|
|
3737
3573
|
"text-anchor": ninePointAnchorToTextAnchor2[text.anchor],
|
|
3738
3574
|
"dominant-baseline": ninePointAnchorToDominantBaseline2[text.anchor],
|
|
@@ -3751,11 +3587,11 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3751
3587
|
});
|
|
3752
3588
|
}
|
|
3753
3589
|
for (const box of symbolBoxes) {
|
|
3754
|
-
const screenBoxPos =
|
|
3755
|
-
|
|
3590
|
+
const screenBoxPos = applyToPoint29(
|
|
3591
|
+
compose7(realToScreenTransform, symbolToRealTransform),
|
|
3756
3592
|
box
|
|
3757
3593
|
);
|
|
3758
|
-
const symbolToScreenScale =
|
|
3594
|
+
const symbolToScreenScale = compose7(
|
|
3759
3595
|
realToScreenTransform,
|
|
3760
3596
|
symbolToRealTransform
|
|
3761
3597
|
).a;
|
|
@@ -3774,11 +3610,11 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3774
3610
|
});
|
|
3775
3611
|
}
|
|
3776
3612
|
for (const circle of symbolCircles) {
|
|
3777
|
-
const screenCirclePos =
|
|
3778
|
-
|
|
3613
|
+
const screenCirclePos = applyToPoint29(
|
|
3614
|
+
compose7(realToScreenTransform, symbolToRealTransform),
|
|
3779
3615
|
circle
|
|
3780
3616
|
);
|
|
3781
|
-
const symbolToScreenScale =
|
|
3617
|
+
const symbolToScreenScale = compose7(
|
|
3782
3618
|
realToScreenTransform,
|
|
3783
3619
|
symbolToRealTransform
|
|
3784
3620
|
).a;
|
|
@@ -3800,6 +3636,187 @@ var createSvgObjectsForSchNetSymbol = (schNetLabel, realToScreenTransform) => {
|
|
|
3800
3636
|
return svgObjects;
|
|
3801
3637
|
};
|
|
3802
3638
|
|
|
3639
|
+
// lib/sch/svg-object-fns/create-svg-objects-for-sch-net-label.ts
|
|
3640
|
+
var createSvgObjectsForSchNetLabel = (schNetLabel, realToScreenTransform) => {
|
|
3641
|
+
if (!schNetLabel.text) return [];
|
|
3642
|
+
if (schNetLabel.symbol_name) {
|
|
3643
|
+
return createSvgObjectsForSchNetLabelWithSymbol(
|
|
3644
|
+
schNetLabel,
|
|
3645
|
+
realToScreenTransform
|
|
3646
|
+
);
|
|
3647
|
+
}
|
|
3648
|
+
const svgObjects = [];
|
|
3649
|
+
const fontSizePx = getSchScreenFontSize(realToScreenTransform, "net_label");
|
|
3650
|
+
const fontSizeMm = getSchMmFontSize("net_label");
|
|
3651
|
+
const textWidthFSR = estimateTextWidth(schNetLabel.text || "");
|
|
3652
|
+
const screenCenter = applyToPoint30(realToScreenTransform, schNetLabel.center);
|
|
3653
|
+
const realTextGrowthVec = getUnitVectorFromOutsideToEdge(
|
|
3654
|
+
schNetLabel.anchor_side
|
|
3655
|
+
);
|
|
3656
|
+
const screenTextGrowthVec = { ...realTextGrowthVec };
|
|
3657
|
+
screenTextGrowthVec.y *= -1;
|
|
3658
|
+
const fullWidthFsr = textWidthFSR + ARROW_POINT_WIDTH_FSR * 2 + END_PADDING_EXTRA_PER_CHARACTER_FSR * schNetLabel.text.length + END_PADDING_FSR;
|
|
3659
|
+
const screenAnchorPosition = schNetLabel.anchor_position ? applyToPoint30(realToScreenTransform, schNetLabel.anchor_position) : {
|
|
3660
|
+
x: screenCenter.x - screenTextGrowthVec.x * fullWidthFsr * fontSizePx / 2,
|
|
3661
|
+
y: screenCenter.y - screenTextGrowthVec.y * fullWidthFsr * fontSizePx / 2
|
|
3662
|
+
};
|
|
3663
|
+
const realAnchorPosition = schNetLabel.anchor_position ?? {
|
|
3664
|
+
x: schNetLabel.center.x - realTextGrowthVec.x * fullWidthFsr * fontSizeMm / 2,
|
|
3665
|
+
y: schNetLabel.center.y - realTextGrowthVec.y * fullWidthFsr * fontSizeMm / 2
|
|
3666
|
+
};
|
|
3667
|
+
const pathRotation = {
|
|
3668
|
+
left: 0,
|
|
3669
|
+
top: -90,
|
|
3670
|
+
bottom: 90,
|
|
3671
|
+
right: 180
|
|
3672
|
+
}[schNetLabel.anchor_side];
|
|
3673
|
+
const screenOutlinePoints = [
|
|
3674
|
+
// Arrow point in font-relative coordinates
|
|
3675
|
+
{
|
|
3676
|
+
x: 0,
|
|
3677
|
+
y: 0
|
|
3678
|
+
},
|
|
3679
|
+
// Top left corner in font-relative coordinates
|
|
3680
|
+
{
|
|
3681
|
+
x: ARROW_POINT_WIDTH_FSR,
|
|
3682
|
+
y: 0.6
|
|
3683
|
+
},
|
|
3684
|
+
// Top right corner in font-relative coordinates
|
|
3685
|
+
{
|
|
3686
|
+
x: ARROW_POINT_WIDTH_FSR * 2 + END_PADDING_FSR + END_PADDING_EXTRA_PER_CHARACTER_FSR * schNetLabel.text.length + textWidthFSR,
|
|
3687
|
+
y: 0.6
|
|
3688
|
+
},
|
|
3689
|
+
// Bottom right corner in font-relative coordinates
|
|
3690
|
+
{
|
|
3691
|
+
x: ARROW_POINT_WIDTH_FSR * 2 + END_PADDING_FSR + END_PADDING_EXTRA_PER_CHARACTER_FSR * schNetLabel.text.length + textWidthFSR,
|
|
3692
|
+
y: -0.6
|
|
3693
|
+
},
|
|
3694
|
+
// Bottom left corner in font-relative coordinates
|
|
3695
|
+
{
|
|
3696
|
+
x: ARROW_POINT_WIDTH_FSR,
|
|
3697
|
+
y: -0.6
|
|
3698
|
+
}
|
|
3699
|
+
].map(
|
|
3700
|
+
(fontRelativePoint) => applyToPoint30(
|
|
3701
|
+
compose8(
|
|
3702
|
+
realToScreenTransform,
|
|
3703
|
+
translate8(realAnchorPosition.x, realAnchorPosition.y),
|
|
3704
|
+
scale5(fontSizeMm),
|
|
3705
|
+
rotate4(pathRotation / 180 * Math.PI)
|
|
3706
|
+
),
|
|
3707
|
+
fontRelativePoint
|
|
3708
|
+
)
|
|
3709
|
+
);
|
|
3710
|
+
const pathD = `
|
|
3711
|
+
M ${screenOutlinePoints[0].x},${screenOutlinePoints[0].y}
|
|
3712
|
+
L ${screenOutlinePoints[1].x},${screenOutlinePoints[1].y}
|
|
3713
|
+
L ${screenOutlinePoints[2].x},${screenOutlinePoints[2].y}
|
|
3714
|
+
L ${screenOutlinePoints[3].x},${screenOutlinePoints[3].y}
|
|
3715
|
+
L ${screenOutlinePoints[4].x},${screenOutlinePoints[4].y}
|
|
3716
|
+
Z
|
|
3717
|
+
`;
|
|
3718
|
+
svgObjects.push({
|
|
3719
|
+
name: "path",
|
|
3720
|
+
type: "element",
|
|
3721
|
+
attributes: {
|
|
3722
|
+
class: "net-label",
|
|
3723
|
+
d: pathD,
|
|
3724
|
+
fill: "white",
|
|
3725
|
+
stroke: colorMap.schematic.label_global,
|
|
3726
|
+
"stroke-width": `${getSchStrokeSize(realToScreenTransform)}px`
|
|
3727
|
+
},
|
|
3728
|
+
value: "",
|
|
3729
|
+
children: []
|
|
3730
|
+
});
|
|
3731
|
+
const screenTextPos = {
|
|
3732
|
+
x: screenAnchorPosition.x + screenTextGrowthVec.x * fontSizePx * 0.5,
|
|
3733
|
+
y: screenAnchorPosition.y + screenTextGrowthVec.y * fontSizePx * 0.5
|
|
3734
|
+
};
|
|
3735
|
+
const textAnchor = {
|
|
3736
|
+
left: "start",
|
|
3737
|
+
top: "start",
|
|
3738
|
+
bottom: "start",
|
|
3739
|
+
right: "end"
|
|
3740
|
+
}[schNetLabel.anchor_side];
|
|
3741
|
+
const textTransformString = {
|
|
3742
|
+
left: "",
|
|
3743
|
+
right: "",
|
|
3744
|
+
top: `rotate(90 ${screenTextPos.x} ${screenTextPos.y})`,
|
|
3745
|
+
bottom: `rotate(-90 ${screenTextPos.x} ${screenTextPos.y})`
|
|
3746
|
+
}[schNetLabel.anchor_side];
|
|
3747
|
+
svgObjects.push({
|
|
3748
|
+
name: "text",
|
|
3749
|
+
type: "element",
|
|
3750
|
+
attributes: {
|
|
3751
|
+
class: "net-label-text",
|
|
3752
|
+
x: screenTextPos.x.toString(),
|
|
3753
|
+
y: screenTextPos.y.toString(),
|
|
3754
|
+
fill: colorMap.schematic.label_global,
|
|
3755
|
+
"text-anchor": textAnchor,
|
|
3756
|
+
"dominant-baseline": "central",
|
|
3757
|
+
"font-family": "sans-serif",
|
|
3758
|
+
"font-variant-numeric": "tabular-nums",
|
|
3759
|
+
"font-size": `${fontSizePx}px`,
|
|
3760
|
+
transform: textTransformString
|
|
3761
|
+
},
|
|
3762
|
+
children: [
|
|
3763
|
+
{
|
|
3764
|
+
type: "text",
|
|
3765
|
+
value: schNetLabel.text || "",
|
|
3766
|
+
name: "",
|
|
3767
|
+
attributes: {},
|
|
3768
|
+
children: []
|
|
3769
|
+
}
|
|
3770
|
+
],
|
|
3771
|
+
value: ""
|
|
3772
|
+
});
|
|
3773
|
+
return svgObjects;
|
|
3774
|
+
};
|
|
3775
|
+
|
|
3776
|
+
// lib/sch/svg-object-fns/create-svg-objects-for-sch-text.ts
|
|
3777
|
+
import { applyToPoint as applyToPoint31 } from "transformation-matrix";
|
|
3778
|
+
var createSvgSchText = (elm, transform) => {
|
|
3779
|
+
const center = applyToPoint31(transform, elm.position);
|
|
3780
|
+
const textAnchorMap = {
|
|
3781
|
+
center: "middle",
|
|
3782
|
+
left: "start",
|
|
3783
|
+
right: "end",
|
|
3784
|
+
top: "middle",
|
|
3785
|
+
bottom: "middle"
|
|
3786
|
+
};
|
|
3787
|
+
const dominantBaselineMap = {
|
|
3788
|
+
center: "middle",
|
|
3789
|
+
left: "middle",
|
|
3790
|
+
right: "middle",
|
|
3791
|
+
top: "hanging",
|
|
3792
|
+
bottom: "ideographic"
|
|
3793
|
+
};
|
|
3794
|
+
return {
|
|
3795
|
+
type: "element",
|
|
3796
|
+
name: "text",
|
|
3797
|
+
value: "",
|
|
3798
|
+
attributes: {
|
|
3799
|
+
x: center.x.toString(),
|
|
3800
|
+
y: center.y.toString(),
|
|
3801
|
+
fill: elm.color ?? colorMap.schematic.sheet_label,
|
|
3802
|
+
"text-anchor": textAnchorMap[elm.anchor],
|
|
3803
|
+
"dominant-baseline": dominantBaselineMap[elm.anchor],
|
|
3804
|
+
"font-family": "sans-serif",
|
|
3805
|
+
"font-size": `${getSchScreenFontSize(transform, "reference_designator")}px`,
|
|
3806
|
+
transform: `rotate(${elm.rotation}, ${center.x}, ${center.y})`
|
|
3807
|
+
},
|
|
3808
|
+
children: [
|
|
3809
|
+
{
|
|
3810
|
+
type: "text",
|
|
3811
|
+
value: elm.text,
|
|
3812
|
+
name: elm.schematic_text_id,
|
|
3813
|
+
attributes: {},
|
|
3814
|
+
children: []
|
|
3815
|
+
}
|
|
3816
|
+
]
|
|
3817
|
+
};
|
|
3818
|
+
};
|
|
3819
|
+
|
|
3803
3820
|
// lib/sch/convert-circuit-json-to-schematic-svg.ts
|
|
3804
3821
|
function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
3805
3822
|
const realBounds = getSchematicBoundsFromCircuitJson(circuitJson);
|
|
@@ -3877,7 +3894,7 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
|
|
|
3877
3894
|
} else if (elm.type === "schematic_trace") {
|
|
3878
3895
|
schTraceSvgs.push(...createSchematicTrace(elm, transform));
|
|
3879
3896
|
} else if (elm.type === "schematic_net_label") {
|
|
3880
|
-
|
|
3897
|
+
schNetLabel.push(...createSvgObjectsForSchNetLabel(elm, transform));
|
|
3881
3898
|
} else if (elm.type === "schematic_text") {
|
|
3882
3899
|
schText.push(createSvgSchText(elm, transform));
|
|
3883
3900
|
} else if (elm.type === "schematic_voltage_probe") {
|