summaryrefslogtreecommitdiff
path: root/share/library/Passive/diode.lua
blob: 295100dbecf90b990cbdc53d6f00d8131f23077f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
-- Symbol names
local names =
{
	en = "Diode",
	cs = "Dioda",
	sk = "Dióda"
}

local names_zener =
{
	en = "Zener diode",
	cs = "Zenerova dioda",
	sk = "Zenerova dióda"
}

local names_led =
{
	en = "Light-emitting diode",
	cs = "Svítivá dioda",
	sk = "Svietivá dióda"
}

local names_photo =
{
	en = "Photodiode",
	cs = "Fotodioda",
	sk = "Fotodióda"
}

-- Render area in base units (X1, Y1, X2, Y2)
local area     = {-2, -1, 2, 1}
local area_rad = {-2, -2.5, 2, 1}

-- Terminal points
local terminals = {{-2, 0}, {2, 0}}

-- Rendering
local render = function (cr)
	-- The triangle
	cr.move_to (-1, -1)
	cr.line_to (1, 0)
	cr.line_to (-1, 1)
	cr.line_to (-1, -1)

	-- The vertical line
	cr.move_to (1, 1)
	cr.line_to (1, -1)

	-- The terminals
	cr.move_to (-2, 0)
	cr.line_to (2, 0)

	cr.stroke ()
end

local render_zener = function (cr)
	render (cr)

	cr.move_to (1, 1)
	cr.line_to (0.5, 1)

	cr.stroke ()
end

local render_arrow = function (cr)
	cr.move_to (0, 0)
	cr.line_to (0, -1.5)

	cr.stroke ()

	cr.move_to (-0.3, -0.7)
	cr.line_to (0, -1.5)
	cr.line_to (0.3, -0.7)
	cr.close_path ()

	cr.fill ()
end

local render_radiation = function (cr)
	cr.save ()
	cr.translate (-0.4, 0)
	render_arrow (cr)
	cr.restore ()

	cr.save ()
	cr.translate (0.4, 0)
	render_arrow (cr)
	cr.restore ()
end

local render_led = function (cr)
	render (cr)

	cr.save ()
	cr.translate (-0.3, -1.0)
	cr.rotate (math.atan2 (1, 1))

	render_radiation (cr)

	cr.restore ()
end

local render_photo = function (cr)
	render (cr)

	cr.save ()
	cr.translate (0.75, -2.05)
	cr.rotate (math.atan2 (-1, -1))

	render_radiation (cr)

	cr.restore ()
end

-- Register the symbol
logdiag.register ("Diode",      names,       area,     terminals, render)
logdiag.register ("DiodeZener", names_zener, area,     terminals, render_zener)
logdiag.register ("DiodeLED",   names_led,   area_rad, terminals, render_led)
logdiag.register ("DiodePhoto", names_photo, area_rad, terminals, render_photo)