Debian Codegraph @

src/activities/digital_electricity/components/Zero.qml

raw
1 /* GCompris - Zero.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 import core 1.0
13
14 ElectricalComponent {
15 id: zero
16 terminalSize: 0.25
17 noOfInputs: 0
18 noOfOutputs: 1
19
20 information: qsTr("Digital circuits work with only two states: 0 and 1. It is the basics of computer technics. In reality, 0 is often the representation of a voltage nearly equal to ground voltage and 1 is the representation of the supply voltage of a circuit.")
21
22 property alias outputTerminals: outputTerminals
23
24 Repeater {
25 id: outputTerminals
26 model: 1
27 delegate: outputTerminal
28 Component {
29 id: outputTerminal
30 TerminalPoint {
31 posX: 0.9
32 posY: 0.5
33 value: 0
34 type: "Out"
35 }
36 }
37 }
38
39 function updateOutput(wireVisited) {
40 var terminal = outputTerminals.itemAt(0)
41 for(var i = 0 ; i < terminal.wires.length ; ++i)
42 terminal.wires[i].to.value = terminal.value
43
44 var componentVisited = []
45 for(var i = 0 ; i < terminal.wires.length ; ++i) {
46 var wire = terminal.wires[i]
47 var component = wire.to.parent
48 if(componentVisited[component] != true && wireVisited[wire] != true) {
49 componentVisited[component] = true
50 wireVisited[wire] = true
51 component.updateOutput(wireVisited)
52 }
53 }
54 }
55 }