Debian Codegraph @

src/activities/digital_electricity/components/One.qml

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