circuit-to-svg 0.0.122 → 0.0.123
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 +102 -62
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1486,12 +1486,35 @@ var getSchScreenFontSize = (transform, textType) => {
|
|
|
1486
1486
|
};
|
|
1487
1487
|
|
|
1488
1488
|
// lib/assembly/svg-object-fns/create-svg-objects-from-assembly-component.ts
|
|
1489
|
-
function createSvgObjectsFromAssemblyComponent(
|
|
1490
|
-
const {
|
|
1489
|
+
function createSvgObjectsFromAssemblyComponent(params, ctx) {
|
|
1490
|
+
const { elm, portPosition, name, arePinsInterchangeable } = params;
|
|
1491
|
+
const { transform } = ctx;
|
|
1492
|
+
const { center, width, height, rotation = 0, layer = "top" } = elm;
|
|
1493
|
+
if (!center || typeof width !== "number" || typeof height !== "number")
|
|
1494
|
+
return null;
|
|
1491
1495
|
const [x, y] = applyToPoint19(transform, [center.x, center.y]);
|
|
1492
|
-
const [pinX, pinY] = applyToPoint19(transform, [
|
|
1496
|
+
const [pinX, pinY] = applyToPoint19(transform, [portPosition.x, portPosition.y]);
|
|
1493
1497
|
const scaledWidth = width * Math.abs(transform.a);
|
|
1494
1498
|
const scaledHeight = height * Math.abs(transform.d);
|
|
1499
|
+
const isTopLayer = layer === "top";
|
|
1500
|
+
const isPinTop = pinY > y;
|
|
1501
|
+
const isPinLeft = pinX < x;
|
|
1502
|
+
const children = [
|
|
1503
|
+
createComponentPath(scaledWidth, scaledHeight, rotation, layer),
|
|
1504
|
+
createComponentLabel(scaledWidth, scaledHeight, name ?? "", transform)
|
|
1505
|
+
];
|
|
1506
|
+
if (!arePinsInterchangeable) {
|
|
1507
|
+
children.push(
|
|
1508
|
+
createPin1Indicator(
|
|
1509
|
+
scaledWidth,
|
|
1510
|
+
scaledHeight,
|
|
1511
|
+
rotation,
|
|
1512
|
+
layer,
|
|
1513
|
+
isPinTop,
|
|
1514
|
+
isPinLeft
|
|
1515
|
+
)
|
|
1516
|
+
);
|
|
1517
|
+
}
|
|
1495
1518
|
return {
|
|
1496
1519
|
name: "g",
|
|
1497
1520
|
type: "element",
|
|
@@ -1499,29 +1522,14 @@ function createSvgObjectsFromAssemblyComponent(component, transform, firstPin, n
|
|
|
1499
1522
|
attributes: {
|
|
1500
1523
|
transform: `translate(${x}, ${y}) scale(1, -1)`
|
|
1501
1524
|
},
|
|
1502
|
-
children
|
|
1503
|
-
createComponentPath(
|
|
1504
|
-
scaledWidth,
|
|
1505
|
-
scaledHeight,
|
|
1506
|
-
x,
|
|
1507
|
-
y,
|
|
1508
|
-
pinX,
|
|
1509
|
-
pinY,
|
|
1510
|
-
rotation,
|
|
1511
|
-
layer
|
|
1512
|
-
),
|
|
1513
|
-
createComponentLabel(scaledWidth, scaledHeight, name ?? "", transform)
|
|
1514
|
-
]
|
|
1525
|
+
children
|
|
1515
1526
|
};
|
|
1516
1527
|
}
|
|
1517
|
-
function createComponentPath(scaledWidth, scaledHeight,
|
|
1528
|
+
function createComponentPath(scaledWidth, scaledHeight, rotation, layer) {
|
|
1518
1529
|
const w = scaledWidth / 2;
|
|
1519
1530
|
const h = scaledHeight / 2;
|
|
1520
|
-
const cornerSize = Math.min(w, h) * 0.3;
|
|
1521
|
-
const isTop = pinY > centerY;
|
|
1522
|
-
const isLeft = pinX < centerX;
|
|
1523
1531
|
const strokeWidth = 0.8;
|
|
1524
|
-
const path =
|
|
1532
|
+
const path = getRectPathData(w, h, rotation);
|
|
1525
1533
|
return {
|
|
1526
1534
|
name: "path",
|
|
1527
1535
|
type: "element",
|
|
@@ -1571,47 +1579,76 @@ function createComponentLabel(scaledWidth, scaledHeight, name, transform) {
|
|
|
1571
1579
|
value: ""
|
|
1572
1580
|
};
|
|
1573
1581
|
}
|
|
1574
|
-
function
|
|
1575
|
-
const
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
let corners;
|
|
1582
|
-
if (isTop && isLeft) {
|
|
1583
|
-
corners = [
|
|
1584
|
-
[-w, -h + cornerSize],
|
|
1585
|
-
[-w + cornerSize, -h],
|
|
1586
|
-
[w, -h],
|
|
1587
|
-
[w, h],
|
|
1588
|
-
[-w, h]
|
|
1589
|
-
];
|
|
1590
|
-
} else if (isTop && !isLeft) {
|
|
1591
|
-
corners = [
|
|
1582
|
+
function createPin1Indicator(scaledWidth, scaledHeight, rotation, layer, isPinTop, isPinLeft) {
|
|
1583
|
+
const w = scaledWidth / 2;
|
|
1584
|
+
const h = scaledHeight / 2;
|
|
1585
|
+
const indicatorSize = Math.min(w, h) * 0.5;
|
|
1586
|
+
let points;
|
|
1587
|
+
if (isPinTop && isPinLeft) {
|
|
1588
|
+
points = [
|
|
1592
1589
|
[-w, -h],
|
|
1593
|
-
|
|
1594
|
-
[w, -h
|
|
1595
|
-
|
|
1596
|
-
[-w, h]
|
|
1590
|
+
// Corner point
|
|
1591
|
+
[-w + indicatorSize, -h],
|
|
1592
|
+
// Point along top edge
|
|
1593
|
+
[-w, -h + indicatorSize]
|
|
1594
|
+
// Point along left edge
|
|
1597
1595
|
];
|
|
1598
|
-
} else if (
|
|
1599
|
-
|
|
1600
|
-
[-w, -h],
|
|
1596
|
+
} else if (isPinTop && !isPinLeft) {
|
|
1597
|
+
points = [
|
|
1601
1598
|
[w, -h],
|
|
1602
|
-
|
|
1603
|
-
[
|
|
1604
|
-
|
|
1599
|
+
// Corner point
|
|
1600
|
+
[w - indicatorSize, -h],
|
|
1601
|
+
// Point along top edge
|
|
1602
|
+
[w, -h + indicatorSize]
|
|
1603
|
+
// Point along right edge
|
|
1604
|
+
];
|
|
1605
|
+
} else if (!isPinTop && isPinLeft) {
|
|
1606
|
+
points = [
|
|
1607
|
+
[-w, h],
|
|
1608
|
+
// Corner point
|
|
1609
|
+
[-w + indicatorSize, h],
|
|
1610
|
+
// Point along bottom edge
|
|
1611
|
+
[-w, h - indicatorSize]
|
|
1612
|
+
// Point along left edge
|
|
1605
1613
|
];
|
|
1606
1614
|
} else {
|
|
1607
|
-
|
|
1608
|
-
[
|
|
1609
|
-
|
|
1610
|
-
[w, h
|
|
1611
|
-
|
|
1612
|
-
[
|
|
1615
|
+
points = [
|
|
1616
|
+
[w, h],
|
|
1617
|
+
// Corner point
|
|
1618
|
+
[w - indicatorSize, h],
|
|
1619
|
+
// Point along bottom edge
|
|
1620
|
+
[w, h - indicatorSize]
|
|
1621
|
+
// Point along right edge
|
|
1613
1622
|
];
|
|
1614
1623
|
}
|
|
1624
|
+
const pointsString = points.map((p) => p.join(",")).join(" ");
|
|
1625
|
+
return {
|
|
1626
|
+
name: "polygon",
|
|
1627
|
+
type: "element",
|
|
1628
|
+
attributes: {
|
|
1629
|
+
class: "assembly-pin1-indicator",
|
|
1630
|
+
points: pointsString,
|
|
1631
|
+
fill: "#333",
|
|
1632
|
+
stroke: "none",
|
|
1633
|
+
transform: `rotate(${-rotation})`
|
|
1634
|
+
},
|
|
1635
|
+
value: "",
|
|
1636
|
+
children: []
|
|
1637
|
+
};
|
|
1638
|
+
}
|
|
1639
|
+
function getRectPathData(w, h, rotation) {
|
|
1640
|
+
const rotatePoint = (x, y, angle) => {
|
|
1641
|
+
const rad = Math.PI / 180 * angle;
|
|
1642
|
+
const cos = Math.cos(rad);
|
|
1643
|
+
const sin = Math.sin(rad);
|
|
1644
|
+
return [x * cos - y * sin, x * sin + y * cos];
|
|
1645
|
+
};
|
|
1646
|
+
const corners = [
|
|
1647
|
+
[-w, -h],
|
|
1648
|
+
[w, -h],
|
|
1649
|
+
[w, h],
|
|
1650
|
+
[-w, h]
|
|
1651
|
+
];
|
|
1615
1652
|
const rotatedCorners = corners.map(([x, y]) => rotatePoint(x, y, rotation));
|
|
1616
1653
|
const path = rotatedCorners.map(([x, y], i) => i === 0 ? `M${x},${y}` : `L${x},${y}`).join(" ");
|
|
1617
1654
|
return `${path} Z`;
|
|
@@ -1734,14 +1771,17 @@ function createSvgObjects2(elm, transform, soup) {
|
|
|
1734
1771
|
const ports = su3(soup).pcb_port.list().filter((port) => port.pcb_component_id === elm.pcb_component_id);
|
|
1735
1772
|
const firstPort = ports[0];
|
|
1736
1773
|
if (sourceComponent && firstPort) {
|
|
1737
|
-
|
|
1738
|
-
|
|
1774
|
+
const arePinsInterchangeable = sourceComponent.are_pins_interchangeable;
|
|
1775
|
+
const obj = createSvgObjectsFromAssemblyComponent(
|
|
1776
|
+
{
|
|
1739
1777
|
elm,
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1778
|
+
portPosition: { x: firstPort.x, y: firstPort.y },
|
|
1779
|
+
name: sourceComponent.name,
|
|
1780
|
+
arePinsInterchangeable
|
|
1781
|
+
},
|
|
1782
|
+
{ transform }
|
|
1783
|
+
);
|
|
1784
|
+
return obj ? [obj] : [];
|
|
1745
1785
|
}
|
|
1746
1786
|
return [];
|
|
1747
1787
|
}
|