@tscircuit/schematic-viewer 1.4.0 → 1.4.1
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/biome.json +45 -0
- package/dist/index.js +55 -16
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
- package/src/Schematic.tsx +3 -1
- package/src/lib/render-context/index.ts +1 -1
- package/src/lib/types/source-component.ts +1 -1
- package/src/lib/utils/collect-element-refs.ts +4 -4
- package/src/lib/utils/colors.ts +215 -216
- package/src/lib/utils/direction-to-vec.ts +3 -3
- package/src/schematic-components/SVGPathComponent.tsx +67 -48
- package/src/schematic-components/SchematicChip.tsx +124 -85
- package/src/schematic-components/SchematicComponent.tsx +17 -8
- package/src/schematic-components/SchematicComponentFromSymbol.tsx +3 -1
- package/src/schematic-components/SchematicNetLabel.tsx +3 -0
- package/src/schematic-components/SchematicText.tsx +4 -6
- package/src/schematic-components/SchematicTrace.tsx +1 -1
- package/src/schematic-components/TableViewer.tsx +1 -1
- package/src/schematic-components/index.tsx +0 -1
- package/src/stories/basics/schematic-net-label.stories.tsx +2 -0
- package/src/stories/bug-connections.stories.tsx +18 -16
- package/src/stories/bug-high-port-numbers.stories.tsx +16 -8
- package/src/stories/bug-one-sided.stories.tsx +17 -15
- package/src/stories/bug-pin-spacing.stories.tsx +19 -17
- package/src/stories/bugs/bug1-y-flip.stories.tsx +7 -5
- package/src/stories/bugs/bug5-diode.stories.tsx +3 -1
- package/src/stories/bugs/bug6-trace-scaling.stories.tsx +5 -41
- package/src/stories/led-circuit-react.stories.tsx +3 -8
- package/src/stories/rotated-resistor.stories.tsx +10 -8
- package/src/stories/three-sided-bug.stories.tsx +17 -15
|
@@ -1,37 +1,43 @@
|
|
|
1
|
-
import { useGlobalStore } from "lib/render-context"
|
|
2
|
-
import getSVGPathBounds from "lib/utils/get-svg-path-bounds"
|
|
3
|
-
import { useState } from "react"
|
|
4
|
-
import {
|
|
1
|
+
import { useGlobalStore } from "lib/render-context"
|
|
2
|
+
import getSVGPathBounds from "lib/utils/get-svg-path-bounds"
|
|
3
|
+
import { useState } from "react"
|
|
4
|
+
import {
|
|
5
|
+
applyToPoint,
|
|
6
|
+
compose,
|
|
7
|
+
scale,
|
|
8
|
+
toSVG,
|
|
9
|
+
translate,
|
|
10
|
+
} from "transformation-matrix"
|
|
5
11
|
|
|
6
12
|
interface PathProps {
|
|
7
|
-
type?:
|
|
8
|
-
strokeWidth: number
|
|
9
|
-
stroke: string
|
|
10
|
-
fill?: string
|
|
11
|
-
d: string
|
|
13
|
+
type?: "path"
|
|
14
|
+
strokeWidth: number
|
|
15
|
+
stroke: string
|
|
16
|
+
fill?: string
|
|
17
|
+
d: string
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
interface CircleProps {
|
|
15
|
-
type:
|
|
16
|
-
cx: number
|
|
17
|
-
cy: number
|
|
18
|
-
r: number
|
|
19
|
-
strokeWidth: number
|
|
20
|
-
stroke: string
|
|
21
|
-
fill?: string
|
|
21
|
+
type: "circle"
|
|
22
|
+
cx: number
|
|
23
|
+
cy: number
|
|
24
|
+
r: number
|
|
25
|
+
strokeWidth: number
|
|
26
|
+
stroke: string
|
|
27
|
+
fill?: string
|
|
22
28
|
}
|
|
23
29
|
|
|
24
|
-
export type SVGElement = PathProps | CircleProps
|
|
30
|
+
export type SVGElement = PathProps | CircleProps
|
|
25
31
|
|
|
26
32
|
interface Props {
|
|
27
|
-
rotation: number
|
|
28
|
-
center: { x: number; y: number }
|
|
29
|
-
size: { width: number; height: number }
|
|
30
|
-
invertY?: boolean
|
|
31
|
-
shiftToBottom?: boolean
|
|
32
|
-
paths: SVGElement[]
|
|
33
|
-
zIndex?: number
|
|
34
|
-
hoverContent?: any
|
|
33
|
+
rotation: number
|
|
34
|
+
center: { x: number; y: number }
|
|
35
|
+
size: { width: number; height: number }
|
|
36
|
+
invertY?: boolean
|
|
37
|
+
shiftToBottom?: boolean
|
|
38
|
+
paths: SVGElement[]
|
|
39
|
+
zIndex?: number
|
|
40
|
+
hoverContent?: any
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
export const SVGPathComponent = ({
|
|
@@ -44,36 +50,43 @@ export const SVGPathComponent = ({
|
|
|
44
50
|
shiftToBottom,
|
|
45
51
|
hoverContent,
|
|
46
52
|
}: Props) => {
|
|
47
|
-
const ct = useGlobalStore((s) => s.camera_transform)
|
|
48
|
-
const pathBounds = getSVGPathBounds(
|
|
53
|
+
const ct = useGlobalStore((s) => s.camera_transform)
|
|
54
|
+
const pathBounds = getSVGPathBounds(
|
|
55
|
+
paths.filter((p): p is PathProps => p.type !== "circle").map((p) => p.d),
|
|
56
|
+
)
|
|
49
57
|
|
|
50
|
-
const padding = { x: 0, y: 0 }
|
|
51
|
-
const absoluteCenter = applyToPoint(ct, center)
|
|
58
|
+
const padding = { x: 0, y: 0 }
|
|
59
|
+
const absoluteCenter = applyToPoint(ct, center)
|
|
52
60
|
const innerSize = {
|
|
53
61
|
width: size.width * ct.a,
|
|
54
62
|
height: size.height * Math.abs(ct.d),
|
|
55
|
-
}
|
|
63
|
+
}
|
|
56
64
|
const fullSize = {
|
|
57
65
|
width: innerSize.width + padding.x * 2,
|
|
58
66
|
height: innerSize.height + padding.y * 2,
|
|
59
|
-
}
|
|
67
|
+
}
|
|
60
68
|
|
|
61
|
-
const [hovering, setHovering] = useState(false)
|
|
69
|
+
const [hovering, setHovering] = useState(false)
|
|
62
70
|
|
|
63
|
-
const svgLeft = absoluteCenter.x - fullSize.width / 2
|
|
64
|
-
const svgTop = absoluteCenter.y - fullSize.height / 2
|
|
71
|
+
const svgLeft = absoluteCenter.x - fullSize.width / 2
|
|
72
|
+
const svgTop = absoluteCenter.y - fullSize.height / 2
|
|
65
73
|
|
|
66
|
-
const preferredRatio =
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
const preferredRatio =
|
|
75
|
+
pathBounds.width === 0
|
|
76
|
+
? innerSize.height / pathBounds.height
|
|
77
|
+
: innerSize.width / pathBounds.width
|
|
69
78
|
|
|
70
79
|
const svgToScreen = compose(
|
|
71
80
|
scale(
|
|
72
|
-
pathBounds.width === 0
|
|
73
|
-
|
|
81
|
+
pathBounds.width === 0
|
|
82
|
+
? preferredRatio
|
|
83
|
+
: fullSize.width / pathBounds.width,
|
|
84
|
+
pathBounds.height === 0
|
|
85
|
+
? preferredRatio
|
|
86
|
+
: fullSize.height / pathBounds.height,
|
|
74
87
|
),
|
|
75
88
|
translate(-pathBounds.minX, -pathBounds.minY),
|
|
76
|
-
)
|
|
89
|
+
)
|
|
77
90
|
|
|
78
91
|
return (
|
|
79
92
|
<svg
|
|
@@ -95,15 +108,21 @@ export const SVGPathComponent = ({
|
|
|
95
108
|
width={fullSize.width}
|
|
96
109
|
height={fullSize.height}
|
|
97
110
|
>
|
|
98
|
-
{paths.map((p, i) =>
|
|
99
|
-
p.type ===
|
|
111
|
+
{paths.map((p, i) =>
|
|
112
|
+
p.type === "circle" ? (
|
|
100
113
|
<circle
|
|
101
114
|
key={i}
|
|
115
|
+
transform={toSVG(
|
|
116
|
+
compose(
|
|
117
|
+
scale(1, 1), // Add a smaller scale factor for circles
|
|
118
|
+
svgToScreen,
|
|
119
|
+
),
|
|
120
|
+
)}
|
|
102
121
|
cx={p.cx}
|
|
103
122
|
cy={p.cy}
|
|
104
123
|
r={p.r}
|
|
105
|
-
fill={
|
|
106
|
-
strokeWidth={
|
|
124
|
+
fill={"none"}
|
|
125
|
+
strokeWidth={2.25 * (p.strokeWidth || 1)}
|
|
107
126
|
stroke={p.stroke || "red"}
|
|
108
127
|
/>
|
|
109
128
|
) : (
|
|
@@ -116,10 +135,10 @@ export const SVGPathComponent = ({
|
|
|
116
135
|
stroke={p.stroke || "red"}
|
|
117
136
|
d={p.d || ""}
|
|
118
137
|
/>
|
|
119
|
-
)
|
|
138
|
+
),
|
|
120
139
|
)}
|
|
121
140
|
</svg>
|
|
122
|
-
)
|
|
123
|
-
}
|
|
141
|
+
)
|
|
142
|
+
}
|
|
124
143
|
|
|
125
|
-
export default SVGPathComponent
|
|
144
|
+
export default SVGPathComponent
|
|
@@ -1,130 +1,163 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
AnyCircuitElement,
|
|
3
|
+
SchematicPort as OriginalSchematicPort,
|
|
4
|
+
SchematicComponent,
|
|
5
|
+
} from "circuit-json"
|
|
6
|
+
import * as Type from "lib/types"
|
|
7
|
+
import { colorMap } from "lib/utils/colors"
|
|
8
|
+
import React from "react"
|
|
9
|
+
import SVGPathComponent from "./SVGPathComponent"
|
|
10
|
+
import SchematicText from "./SchematicText"
|
|
7
11
|
|
|
8
12
|
interface Props {
|
|
9
13
|
component: {
|
|
10
|
-
source: Type.SimpleBug
|
|
11
|
-
schematic: SchematicComponent
|
|
12
|
-
allElements: AnyCircuitElement[]
|
|
14
|
+
source: Type.SimpleBug
|
|
15
|
+
schematic: SchematicComponent
|
|
16
|
+
allElements: AnyCircuitElement[]
|
|
13
17
|
}
|
|
14
18
|
}
|
|
15
19
|
|
|
16
|
-
type ExtendedCenter = OriginalSchematicPort[
|
|
17
|
-
side: "left" | "right" | "top" | "bottom"
|
|
18
|
-
pinNumber: number
|
|
19
|
-
distanceFromEdge: number
|
|
20
|
-
trueIndex: number
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type SchematicPort = Omit<OriginalSchematicPort, 'center'> & {
|
|
24
|
-
center: ExtendedCenter;
|
|
25
|
-
};
|
|
20
|
+
type ExtendedCenter = OriginalSchematicPort["center"] & {
|
|
21
|
+
side: "left" | "right" | "top" | "bottom" | "center"
|
|
22
|
+
pinNumber: number
|
|
23
|
+
distanceFromEdge: number
|
|
24
|
+
trueIndex: number
|
|
25
|
+
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const chipWidth = size.width;
|
|
31
|
-
const chipHeight = size.height;
|
|
27
|
+
type SchematicPort = Omit<OriginalSchematicPort, "center"> & {
|
|
28
|
+
center: ExtendedCenter
|
|
29
|
+
}
|
|
32
30
|
|
|
33
|
-
|
|
31
|
+
export const SchematicChip: React.FC<Props> = ({
|
|
32
|
+
component: { source, schematic, allElements },
|
|
33
|
+
}) => {
|
|
34
|
+
const { center, size, rotation, schematic_component_id } = schematic
|
|
35
|
+
const { manufacturerPartNumber, name } = source
|
|
36
|
+
const chipWidth = size.width
|
|
37
|
+
const chipHeight = size.height
|
|
38
|
+
|
|
39
|
+
const paths: Array<{
|
|
40
|
+
type?: "path" | "circle"
|
|
41
|
+
strokeWidth: number
|
|
42
|
+
stroke: string
|
|
43
|
+
fill?: string
|
|
44
|
+
d?: string
|
|
45
|
+
cx?: number
|
|
46
|
+
cy?: number
|
|
47
|
+
r?: number
|
|
48
|
+
}> = []
|
|
34
49
|
|
|
35
50
|
// Main chip rectangle
|
|
36
51
|
paths.push({
|
|
37
|
-
type:
|
|
52
|
+
type: "path",
|
|
38
53
|
strokeWidth: 0.02,
|
|
39
54
|
stroke: colorMap.schematic.component_outline,
|
|
40
55
|
fill: colorMap.schematic.component_body,
|
|
41
56
|
d: `M ${-chipWidth / 2},${-chipHeight / 2} h ${chipWidth} v ${chipHeight} h ${-chipWidth} Z`,
|
|
42
|
-
})
|
|
57
|
+
})
|
|
43
58
|
|
|
44
59
|
const schematicPorts = allElements.filter(
|
|
45
|
-
(item): item is SchematicPort =>
|
|
46
|
-
item.type === "schematic_port" &&
|
|
47
|
-
item.schematic_component_id === schematic_component_id
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
const portLength = 0.2
|
|
51
|
-
const circleRadius = 0.05
|
|
52
|
-
const labelOffset = 0.1
|
|
53
|
-
|
|
54
|
-
const pinLabels: Array<{
|
|
60
|
+
(item): item is SchematicPort =>
|
|
61
|
+
item.type === "schematic_port" &&
|
|
62
|
+
item.schematic_component_id === schematic_component_id,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
const portLength = 0.2
|
|
66
|
+
const circleRadius = 0.05
|
|
67
|
+
const labelOffset = 0.1
|
|
68
|
+
|
|
69
|
+
const pinLabels: Array<{
|
|
70
|
+
x: number
|
|
71
|
+
y: number
|
|
72
|
+
text: string
|
|
73
|
+
anchor: string
|
|
74
|
+
rotation: number
|
|
75
|
+
}> = []
|
|
55
76
|
|
|
56
77
|
schematicPorts.forEach((port) => {
|
|
57
|
-
const { side, pinNumber, distanceFromEdge } = port.center
|
|
58
|
-
let x = 0,
|
|
59
|
-
|
|
60
|
-
|
|
78
|
+
const { side, pinNumber, distanceFromEdge } = port.center
|
|
79
|
+
let x = 0,
|
|
80
|
+
y = 0,
|
|
81
|
+
endX = 0,
|
|
82
|
+
endY = 0
|
|
83
|
+
let labelX = 0,
|
|
84
|
+
labelY = 0
|
|
85
|
+
let textAnchor = "middle"
|
|
86
|
+
let rotation = 0
|
|
87
|
+
|
|
88
|
+
if (side === "center") {
|
|
89
|
+
return
|
|
90
|
+
}
|
|
61
91
|
|
|
62
92
|
switch (side) {
|
|
63
93
|
case "left":
|
|
64
|
-
x = -chipWidth / 2
|
|
65
|
-
y = -chipHeight / 2 + distanceFromEdge
|
|
66
|
-
endX = x - portLength
|
|
67
|
-
endY = y
|
|
68
|
-
labelX = endX
|
|
69
|
-
labelY = y + labelOffset
|
|
70
|
-
textAnchor = "end"
|
|
71
|
-
break
|
|
94
|
+
x = -chipWidth / 2
|
|
95
|
+
y = -chipHeight / 2 + distanceFromEdge
|
|
96
|
+
endX = x - portLength
|
|
97
|
+
endY = y
|
|
98
|
+
labelX = endX
|
|
99
|
+
labelY = y + labelOffset
|
|
100
|
+
textAnchor = "end"
|
|
101
|
+
break
|
|
72
102
|
case "right":
|
|
73
|
-
x = chipWidth / 2
|
|
74
|
-
y = chipHeight / 2 - distanceFromEdge
|
|
75
|
-
endX = x + portLength
|
|
76
|
-
endY = y
|
|
77
|
-
labelX = endX - labelOffset
|
|
78
|
-
labelY = y + labelOffset
|
|
79
|
-
textAnchor = "start"
|
|
80
|
-
break
|
|
103
|
+
x = chipWidth / 2
|
|
104
|
+
y = chipHeight / 2 - distanceFromEdge
|
|
105
|
+
endX = x + portLength
|
|
106
|
+
endY = y
|
|
107
|
+
labelX = endX - labelOffset
|
|
108
|
+
labelY = y + labelOffset
|
|
109
|
+
textAnchor = "start"
|
|
110
|
+
break
|
|
81
111
|
case "bottom":
|
|
82
|
-
x = -chipWidth / 2 + distanceFromEdge
|
|
83
|
-
y = -chipHeight / 2
|
|
84
|
-
endX = x
|
|
85
|
-
endY = y - portLength
|
|
86
|
-
labelX = x
|
|
87
|
-
labelY = endY + labelOffset
|
|
88
|
-
|
|
112
|
+
x = -chipWidth / 2 + distanceFromEdge
|
|
113
|
+
y = -chipHeight / 2
|
|
114
|
+
endX = x
|
|
115
|
+
endY = y - portLength
|
|
116
|
+
labelX = x
|
|
117
|
+
labelY = endY + labelOffset
|
|
118
|
+
rotation = -90
|
|
119
|
+
break
|
|
89
120
|
case "top":
|
|
90
|
-
x = chipWidth / 2 - distanceFromEdge
|
|
91
|
-
y = chipHeight / 2
|
|
92
|
-
endX = x
|
|
93
|
-
endY = y + portLength
|
|
94
|
-
labelX = x
|
|
95
|
-
labelY = endY + labelOffset
|
|
96
|
-
|
|
121
|
+
x = chipWidth / 2 - distanceFromEdge
|
|
122
|
+
y = chipHeight / 2
|
|
123
|
+
endX = x
|
|
124
|
+
endY = y + portLength
|
|
125
|
+
labelX = x
|
|
126
|
+
labelY = endY + labelOffset
|
|
127
|
+
rotation = -90
|
|
128
|
+
break
|
|
97
129
|
}
|
|
98
130
|
|
|
99
131
|
// Port line
|
|
100
132
|
paths.push({
|
|
101
|
-
type:
|
|
102
|
-
strokeWidth: 0.
|
|
133
|
+
type: "path",
|
|
134
|
+
strokeWidth: 0.015,
|
|
103
135
|
stroke: colorMap.schematic.component_outline,
|
|
104
136
|
d: `M ${x},${y} L ${endX},${endY}`,
|
|
105
|
-
})
|
|
137
|
+
})
|
|
106
138
|
|
|
107
139
|
// Port circle at the end of the line
|
|
108
140
|
paths.push({
|
|
109
|
-
type:
|
|
141
|
+
type: "circle",
|
|
110
142
|
cx: endX,
|
|
111
143
|
cy: endY,
|
|
112
144
|
r: circleRadius,
|
|
113
145
|
strokeWidth: 0.01,
|
|
114
146
|
stroke: colorMap.schematic.component_outline,
|
|
115
147
|
fill: colorMap.schematic.component_outline,
|
|
116
|
-
})
|
|
148
|
+
})
|
|
117
149
|
|
|
118
150
|
// Add pin label
|
|
119
|
-
if(pinNumber !== undefined) {
|
|
151
|
+
if (pinNumber !== undefined) {
|
|
120
152
|
pinLabels.push({
|
|
121
153
|
x: labelX,
|
|
122
154
|
y: labelY,
|
|
123
155
|
text: `${pinNumber}`,
|
|
124
|
-
anchor: textAnchor
|
|
125
|
-
|
|
156
|
+
anchor: textAnchor,
|
|
157
|
+
rotation: rotation,
|
|
158
|
+
})
|
|
126
159
|
}
|
|
127
|
-
})
|
|
160
|
+
})
|
|
128
161
|
|
|
129
162
|
return (
|
|
130
163
|
<>
|
|
@@ -139,6 +172,7 @@ export const SchematicChip: React.FC<Props> = ({ component: { source, schematic,
|
|
|
139
172
|
key={index}
|
|
140
173
|
schematic_text={{
|
|
141
174
|
anchor: label.anchor as any,
|
|
175
|
+
rotation: 0,
|
|
142
176
|
position: {
|
|
143
177
|
x: center.x + label.x,
|
|
144
178
|
y: center.y + label.y,
|
|
@@ -147,12 +181,14 @@ export const SchematicChip: React.FC<Props> = ({ component: { source, schematic,
|
|
|
147
181
|
schematic_text_id: `PIN_LABEL_${index}`,
|
|
148
182
|
text: label.text,
|
|
149
183
|
type: "schematic_text",
|
|
184
|
+
color: colorMap.schematic.pin_number,
|
|
150
185
|
}}
|
|
151
186
|
/>
|
|
152
187
|
))}
|
|
153
188
|
<SchematicText
|
|
154
189
|
schematic_text={{
|
|
155
|
-
anchor: "
|
|
190
|
+
anchor: "right",
|
|
191
|
+
rotation: 0,
|
|
156
192
|
position: {
|
|
157
193
|
x: center.x,
|
|
158
194
|
y: center.y - chipHeight / 2 - 0.2,
|
|
@@ -161,11 +197,13 @@ export const SchematicChip: React.FC<Props> = ({ component: { source, schematic,
|
|
|
161
197
|
schematic_text_id: "SYNTHETIC_MPN",
|
|
162
198
|
text: manufacturerPartNumber,
|
|
163
199
|
type: "schematic_text",
|
|
200
|
+
color: colorMap.schematic.reference,
|
|
164
201
|
}}
|
|
165
202
|
/>
|
|
166
203
|
<SchematicText
|
|
167
204
|
schematic_text={{
|
|
168
|
-
anchor: "
|
|
205
|
+
anchor: "right",
|
|
206
|
+
rotation: 0,
|
|
169
207
|
position: {
|
|
170
208
|
x: center.x,
|
|
171
209
|
y: center.y + chipHeight / 2 + 0.2,
|
|
@@ -174,10 +212,11 @@ export const SchematicChip: React.FC<Props> = ({ component: { source, schematic,
|
|
|
174
212
|
schematic_text_id: "SYNTHETIC_NAME",
|
|
175
213
|
text: name,
|
|
176
214
|
type: "schematic_text",
|
|
215
|
+
color: colorMap.schematic.reference,
|
|
177
216
|
}}
|
|
178
217
|
/>
|
|
179
218
|
</>
|
|
180
|
-
)
|
|
181
|
-
}
|
|
219
|
+
)
|
|
220
|
+
}
|
|
182
221
|
|
|
183
|
-
export default SchematicChip
|
|
222
|
+
export default SchematicChip
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
AnyCircuitElement,
|
|
3
|
+
SchematicComponent as SchematicComponentType,
|
|
4
|
+
} from "circuit-json"
|
|
2
5
|
import * as Component from "./"
|
|
3
6
|
|
|
4
7
|
interface Props {
|
|
@@ -19,19 +22,25 @@ export const SchematicComponent = ({ component }: Props) => {
|
|
|
19
22
|
if (!source.ftype) return null
|
|
20
23
|
|
|
21
24
|
switch (source.ftype) {
|
|
22
|
-
case "simple_resistor":
|
|
25
|
+
case "simple_resistor":
|
|
23
26
|
case "simple_capacitor":
|
|
24
27
|
case "simple_power_source":
|
|
25
28
|
case "simple_ground":
|
|
26
29
|
case "simple_inductor":
|
|
27
|
-
case "simple_diode":
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
case "simple_diode": {
|
|
31
|
+
return (
|
|
32
|
+
<Component.SchematicComponentFromSymbol
|
|
33
|
+
component={{ source, schematic }}
|
|
34
|
+
/>
|
|
35
|
+
)
|
|
30
36
|
}
|
|
31
37
|
case "simple_chip":
|
|
32
|
-
case "simple_bug":
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
case "simple_bug": {
|
|
39
|
+
return (
|
|
40
|
+
<Component.SchematicChip
|
|
41
|
+
component={{ source, schematic, allElements }}
|
|
42
|
+
/>
|
|
43
|
+
)
|
|
35
44
|
}
|
|
36
45
|
default: {
|
|
37
46
|
return <div>unknown ftype: {component.source.ftype}</div>
|
|
@@ -10,7 +10,9 @@ interface Props {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export const SchematicComponentFromSymbol = ({
|
|
13
|
+
export const SchematicComponentFromSymbol = ({
|
|
14
|
+
component: { source, schematic },
|
|
15
|
+
}: Props) => {
|
|
14
16
|
const { center, rotation } = schematic
|
|
15
17
|
// Get the resistor symbol paths
|
|
16
18
|
const symbol = symbols[schematic.symbol_name]
|
|
@@ -3,6 +3,7 @@ import SVGPathComponent from "./SVGPathComponent"
|
|
|
3
3
|
import SchematicText from "./SchematicText"
|
|
4
4
|
import { getRotationFromAnchorSide } from "lib/utils/get-rotation-from-anchor-side"
|
|
5
5
|
import { getVecFromAnchorSide } from "lib/utils/get-vec-from-anchor-side"
|
|
6
|
+
import { colorMap } from "lib/utils/colors"
|
|
6
7
|
|
|
7
8
|
export const SchematicNetLabel = ({
|
|
8
9
|
net_label,
|
|
@@ -44,6 +45,7 @@ export const SchematicNetLabel = ({
|
|
|
44
45
|
/>
|
|
45
46
|
<SchematicText
|
|
46
47
|
schematic_text={{
|
|
48
|
+
rotation: is_vertical ? 0 : getRotationFromAnchorSide(anchor_side),
|
|
47
49
|
anchor: is_vertical ? "center" : anchor_side,
|
|
48
50
|
position: {
|
|
49
51
|
x: net_label.center.x + anchor_vec.x,
|
|
@@ -53,6 +55,7 @@ export const SchematicNetLabel = ({
|
|
|
53
55
|
schematic_text_id: "SYNTHETIC",
|
|
54
56
|
text: net_label.text,
|
|
55
57
|
type: "schematic_text",
|
|
58
|
+
color: colorMap.schematic.net_name,
|
|
56
59
|
}}
|
|
57
60
|
/>
|
|
58
61
|
</>
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import SVGPathComponent from "./SVGPathComponent"
|
|
3
|
-
import Path from "svg-path-generator"
|
|
4
|
-
import getSVGPathBounds from "lib/utils/get-svg-path-bounds"
|
|
1
|
+
import { SchematicText as SchematicTextType } from "circuit-json"
|
|
5
2
|
import { useGlobalStore } from "lib/render-context"
|
|
6
|
-
import { applyToPoint } from "transformation-matrix"
|
|
7
3
|
import useMeasure from "react-use-measure"
|
|
4
|
+
import { applyToPoint } from "transformation-matrix"
|
|
8
5
|
|
|
9
6
|
interface Props {
|
|
10
|
-
schematic_text:
|
|
7
|
+
schematic_text: SchematicTextType
|
|
11
8
|
}
|
|
12
9
|
|
|
13
10
|
export const SchematicText = ({ schematic_text }: Props) => {
|
|
@@ -36,6 +33,7 @@ export const SchematicText = ({ schematic_text }: Props) => {
|
|
|
36
33
|
fontSize: projectedTextSize,
|
|
37
34
|
left: tPos.x + offset[0],
|
|
38
35
|
top: tPos.y + offset[1],
|
|
36
|
+
color: schematic_text.color,
|
|
39
37
|
}}
|
|
40
38
|
>
|
|
41
39
|
{text}
|
|
@@ -72,6 +72,7 @@ export const SchematicNetLabel = () => {
|
|
|
72
72
|
y: -0.5,
|
|
73
73
|
},
|
|
74
74
|
rotation: 0,
|
|
75
|
+
color: "black",
|
|
75
76
|
},
|
|
76
77
|
{
|
|
77
78
|
type: "schematic_text",
|
|
@@ -84,6 +85,7 @@ export const SchematicNetLabel = () => {
|
|
|
84
85
|
y: -0.3,
|
|
85
86
|
},
|
|
86
87
|
rotation: 0,
|
|
88
|
+
color: "black",
|
|
87
89
|
},
|
|
88
90
|
{
|
|
89
91
|
type: "source_net",
|
|
@@ -3,22 +3,24 @@ import { Schematic } from "Schematic"
|
|
|
3
3
|
export const BugConnections = () => {
|
|
4
4
|
return (
|
|
5
5
|
<Schematic style={{ height: 600 }}>
|
|
6
|
-
<
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
<board width={10} height={10}>
|
|
7
|
+
<bug
|
|
8
|
+
name="B1"
|
|
9
|
+
schPortArrangement={{
|
|
10
|
+
leftSize: 3,
|
|
11
|
+
rightSize: 2,
|
|
12
|
+
}}
|
|
13
|
+
schHeight={5}
|
|
14
|
+
schWidth={3}
|
|
15
|
+
schPinSpacing={2}
|
|
16
|
+
schX={8}
|
|
17
|
+
schY={3}
|
|
18
|
+
pinLabels={{
|
|
19
|
+
"1": "D0",
|
|
20
|
+
"2": "D1",
|
|
21
|
+
}}
|
|
22
|
+
/>
|
|
23
|
+
</board>
|
|
22
24
|
</Schematic>
|
|
23
25
|
)
|
|
24
26
|
}
|