circuit-to-svg 0.0.120 → 0.0.122
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 +136 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
package/dist/index.js
CHANGED
|
@@ -18,7 +18,62 @@ function createSvgObjectsFromPcbTraceError(pcbTraceError, transform, circuitJson
|
|
|
18
18
|
const port2 = circuitJson.find(
|
|
19
19
|
(el) => el.type === "pcb_port" && el.pcb_port_id === pcb_port_ids?.[1]
|
|
20
20
|
);
|
|
21
|
-
if (!port1 || !port2)
|
|
21
|
+
if (!port1 || !port2) {
|
|
22
|
+
const viaIdMatch = pcbTraceError.message?.match(
|
|
23
|
+
/pcb_via\[#?(pcb_via_\d+)\]/
|
|
24
|
+
);
|
|
25
|
+
const viaId = viaIdMatch?.[1];
|
|
26
|
+
const via = circuitJson.find(
|
|
27
|
+
(el) => el.type === "pcb_via" && el.pcb_via_id === viaId
|
|
28
|
+
);
|
|
29
|
+
if (via && via.type === "pcb_via") {
|
|
30
|
+
return createSvgObjectsForViaTraceError(pcbTraceError, via, transform);
|
|
31
|
+
}
|
|
32
|
+
if (pcbTraceError.center) {
|
|
33
|
+
const screenCenter = applyToPoint(transform, {
|
|
34
|
+
x: pcbTraceError.center.x,
|
|
35
|
+
y: pcbTraceError.center.y
|
|
36
|
+
});
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
39
|
+
name: "rect",
|
|
40
|
+
type: "element",
|
|
41
|
+
attributes: {
|
|
42
|
+
x: (screenCenter.x - 5).toString(),
|
|
43
|
+
y: (screenCenter.y - 5).toString(),
|
|
44
|
+
width: "10",
|
|
45
|
+
height: "10",
|
|
46
|
+
fill: "red",
|
|
47
|
+
transform: `rotate(45 ${screenCenter.x} ${screenCenter.y})`
|
|
48
|
+
},
|
|
49
|
+
children: [],
|
|
50
|
+
value: ""
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "text",
|
|
54
|
+
type: "element",
|
|
55
|
+
attributes: {
|
|
56
|
+
x: screenCenter.x.toString(),
|
|
57
|
+
y: (screenCenter.y - 15).toString(),
|
|
58
|
+
fill: "red",
|
|
59
|
+
"font-family": "sans-serif",
|
|
60
|
+
"font-size": "12",
|
|
61
|
+
"text-anchor": "middle"
|
|
62
|
+
},
|
|
63
|
+
children: [
|
|
64
|
+
{
|
|
65
|
+
type: "text",
|
|
66
|
+
value: pcbTraceError.message || "Pcb Trace Error",
|
|
67
|
+
name: "",
|
|
68
|
+
attributes: {},
|
|
69
|
+
children: []
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
value: ""
|
|
73
|
+
}
|
|
74
|
+
];
|
|
75
|
+
} else return [];
|
|
76
|
+
}
|
|
22
77
|
const screenPort1 = applyToPoint(transform, {
|
|
23
78
|
x: port1.x,
|
|
24
79
|
y: port1.y
|
|
@@ -104,6 +159,86 @@ function createSvgObjectsFromPcbTraceError(pcbTraceError, transform, circuitJson
|
|
|
104
159
|
];
|
|
105
160
|
return svgObjects;
|
|
106
161
|
}
|
|
162
|
+
function createSvgObjectsForViaTraceError(pcbTraceError, via, transform) {
|
|
163
|
+
if (pcbTraceError.center && via) {
|
|
164
|
+
const screenCenter = applyToPoint(transform, {
|
|
165
|
+
x: pcbTraceError.center.x,
|
|
166
|
+
y: pcbTraceError.center.y
|
|
167
|
+
});
|
|
168
|
+
const screenVia = applyToPoint(transform, {
|
|
169
|
+
x: via.x,
|
|
170
|
+
y: via.y
|
|
171
|
+
});
|
|
172
|
+
const dx = screenVia.x - screenCenter.x;
|
|
173
|
+
const dy = screenVia.y - screenCenter.y;
|
|
174
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
175
|
+
const angle = Math.atan2(dy, dx) * 180 / Math.PI;
|
|
176
|
+
const margin = 10;
|
|
177
|
+
const boxWidth = dist + margin * 2;
|
|
178
|
+
const boxHeight = 20;
|
|
179
|
+
const midX = (screenCenter.x + screenVia.x) / 2;
|
|
180
|
+
const midY = (screenCenter.y + screenVia.y) / 2;
|
|
181
|
+
return [
|
|
182
|
+
// Rotated bounding box
|
|
183
|
+
{
|
|
184
|
+
name: "rect",
|
|
185
|
+
type: "element",
|
|
186
|
+
attributes: {
|
|
187
|
+
x: (midX - boxWidth / 2).toString(),
|
|
188
|
+
y: (midY - boxHeight / 2).toString(),
|
|
189
|
+
width: boxWidth.toString(),
|
|
190
|
+
height: boxHeight.toString(),
|
|
191
|
+
fill: "none",
|
|
192
|
+
stroke: "red",
|
|
193
|
+
"stroke-width": "1",
|
|
194
|
+
"stroke-dasharray": "3,2",
|
|
195
|
+
transform: `rotate(${angle} ${midX} ${midY})`
|
|
196
|
+
},
|
|
197
|
+
children: [],
|
|
198
|
+
value: ""
|
|
199
|
+
},
|
|
200
|
+
// Error diamond
|
|
201
|
+
{
|
|
202
|
+
name: "rect",
|
|
203
|
+
type: "element",
|
|
204
|
+
attributes: {
|
|
205
|
+
x: (midX - 5).toString(),
|
|
206
|
+
y: (midY - 5).toString(),
|
|
207
|
+
width: "10",
|
|
208
|
+
height: "10",
|
|
209
|
+
fill: "red",
|
|
210
|
+
transform: `rotate(45 ${midX} ${midY})`
|
|
211
|
+
},
|
|
212
|
+
children: [],
|
|
213
|
+
value: ""
|
|
214
|
+
},
|
|
215
|
+
// Error label
|
|
216
|
+
{
|
|
217
|
+
name: "text",
|
|
218
|
+
type: "element",
|
|
219
|
+
attributes: {
|
|
220
|
+
x: midX.toString(),
|
|
221
|
+
y: (midY - boxHeight / 2 - 5).toString(),
|
|
222
|
+
fill: "red",
|
|
223
|
+
"font-family": "sans-serif",
|
|
224
|
+
"font-size": "12",
|
|
225
|
+
"text-anchor": "middle"
|
|
226
|
+
},
|
|
227
|
+
children: [
|
|
228
|
+
{
|
|
229
|
+
type: "text",
|
|
230
|
+
value: pcbTraceError.message || "Pcb Trace Error",
|
|
231
|
+
name: "",
|
|
232
|
+
attributes: {},
|
|
233
|
+
children: []
|
|
234
|
+
}
|
|
235
|
+
],
|
|
236
|
+
value: ""
|
|
237
|
+
}
|
|
238
|
+
];
|
|
239
|
+
}
|
|
240
|
+
return [];
|
|
241
|
+
}
|
|
107
242
|
|
|
108
243
|
// lib/pcb/svg-object-fns/create-svg-objects-from-pcb-fabrication-note-path.ts
|
|
109
244
|
import { applyToPoint as applyToPoint2 } from "transformation-matrix";
|