Warning, /education/gcompris/src/activities/digital_electricity/components/One.qml is written in an unsupported language. File is not indexed.

0001 /* GCompris - One.qml
0002  *
0003  * SPDX-FileCopyrightText: 2016 Pulkit Gupta <pulkitnsit@gmail.com>
0004  *
0005  * Authors:
0006  *   Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version)
0007  *   Pulkit Gupta <pulkitnsit@gmail.com> (Qt Quick port)
0008  *
0009  *   SPDX-License-Identifier: GPL-3.0-or-later
0010  */
0011 import QtQuick 2.12
0012 import GCompris 1.0
0013 
0014 ElectricalComponent {
0015     id: one
0016     terminalSize: 0.25
0017     noOfInputs: 0
0018     noOfOutputs: 1
0019 
0020     information: qsTr("Digital circuits work with only two states: 0 and 1. " +
0021                       "This allows to operate mathematical operations such as additions, subtractions... " +
0022                       "It is the basics of computer technics. In reality, 0 is often the representation of a voltage nearly equal to ground voltage " +
0023                       "and 1 is the representation of the supply voltage of a circuit.")
0024 
0025     property alias outputTerminals: outputTerminals
0026 
0027     Repeater {
0028         id: outputTerminals
0029         model: 1
0030         delegate: outputTerminal
0031         Component {
0032             id: outputTerminal
0033             TerminalPoint {
0034                 posX: 0.9
0035                 posY: 0.5
0036                 value: 1
0037                 type: "Out"
0038             }
0039         }
0040     }
0041 
0042     function updateOutput(wireVisited) {
0043         var terminal = outputTerminals.itemAt(0)
0044         for(var i = 0 ; i < terminal.wires.length ; ++i)
0045             terminal.wires[i].to.value = terminal.value
0046 
0047         var componentVisited = []
0048         for(var i = 0 ; i < terminal.wires.length ; ++i) {
0049             var wire = terminal.wires[i]
0050             var component = wire.to.parent
0051             if(componentVisited[component] != true && wireVisited[wire] != true) {
0052                 componentVisited[component] = true
0053                 wireVisited[wire] = true
0054                 component.updateOutput(wireVisited)
0055             }
0056         }
0057     }
0058 }