Debian Codegraph @

src/activities/digital_electricity/components/Switch.qml

raw
1 /* GCompris - Switch.qml
2 *
3 * SPDX-FileCopyrightText: 2016 Pulkit Gupta <[email protected]>
4 *
5 * Authors:
6 * Bruno Coudoin <[email protected]> (GTK+ version)
7 * Pulkit Gupta <[email protected]> (Qt Quick port)
8 *
9 * SPDX-License-Identifier: GPL-3.0-or-later
10 */
11 import QtQuick
12
13 import core 1.0
14
15 ElectricalComponent {
16 id: switchComponent
17 terminalSize: 0.5
18 noOfInputs: 1
19 noOfOutputs: 1
20
21 information: qsTr("A switch is used to connect or disconnect two terminals. " +
22 "If the switch is turned on, the current can flow through the switch. " +
23 "If the switch is turned off, then the connection inside the switch is broken and the current can not flow through it.")
24
25 truthTable: []
26
27 property alias inputTerminals: inputTerminals
28 property alias outputTerminals: outputTerminals
29
30 Repeater {
31 id: inputTerminals
32 model: 1
33 delegate: inputTerminal
34 Component {
35 id: inputTerminal
36 TerminalPoint {
37 posX: 0.04
38 posY: 0.5
39 type: "In"
40 }
41 }
42 }
43
44 Repeater {
45 id: outputTerminals
46 model: 1
47 delegate: outputTerminal
48 Component {
49 id: outputTerminal
50 TerminalPoint {
51 posX: 0.96
52 posY: 0.5
53 type: "Out"
54 }
55 }
56 }
57
58 function updateOutput(wireVisited) {
59 var terminal = outputTerminals.itemAt(0)
60 terminal.value = imgSrc == "switchOn.svg" ? inputTerminals.itemAt(0).value : 0
61 for(var i = 0 ; i < terminal.wires.length ; ++i)
62 terminal.wires[i].to.value = terminal.value
63
64 var componentVisited = []
65 for(var i = 0 ; i < terminal.wires.length ; ++i) {
66 var wire = terminal.wires[i]
67 var component = wire.to.parent
68 if(componentVisited[component] != true && wireVisited[wire] != true) {
69 componentVisited[component] = true
70 wireVisited[wire] = true
71 component.updateOutput(wireVisited)
72 }
73 }
74 }
75 }