Warning, /education/gcompris/src/activities/digital_electricity/components/AndGate.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - AndGate.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: andGate 0016 terminalSize: 0.50 0017 noOfInputs: 2 0018 noOfOutputs: 1 0019 property var inputTerminalPosY: [0.2, 0.8] 0020 0021 information: qsTr("An AND gate outputs 1 only if all its inputs are equal to 1. " + 0022 "As soon as one input is equal to 0 the result is 0. The output for a 2 inputs AND gate is:") 0023 0024 truthTable: [['A','B',qsTr("A AND B")], 0025 ['0','0','0'], 0026 ['0','1','0'], 0027 ['1','0','0'], 0028 ['1','1','1']] 0029 0030 property alias inputTerminals: inputTerminals 0031 property alias outputTerminals: outputTerminals 0032 0033 Repeater { 0034 id: inputTerminals 0035 model: 2 0036 delegate: inputTerminal 0037 Component { 0038 id: inputTerminal 0039 TerminalPoint { 0040 posX: 0.04 0041 posY: inputTerminalPosY[index] 0042 type: "In" 0043 } 0044 } 0045 } 0046 0047 Repeater { 0048 id: outputTerminals 0049 model: 1 0050 delegate: outputTerminal 0051 Component { 0052 id: outputTerminal 0053 TerminalPoint { 0054 posX: 0.96 0055 posY: 0.5 0056 type: "Out" 0057 } 0058 } 0059 } 0060 0061 function updateOutput(wireVisited) { 0062 var terminal = outputTerminals.itemAt(0) 0063 /* Keep the output value == 0 if only one of the input terminals is connected */ 0064 terminal.value = (inputTerminals.itemAt(0).wires.length != 0 && inputTerminals.itemAt(1).wires.length != 0) ? (inputTerminals.itemAt(0).value & inputTerminals.itemAt(1).value) : 0 0065 for(var i = 0 ; i < terminal.wires.length ; ++i) 0066 terminal.wires[i].to.value = terminal.value 0067 0068 var componentVisited = [] 0069 for(var i = 0 ; i < terminal.wires.length ; ++i) { 0070 var wire = terminal.wires[i] 0071 var component = wire.to.parent 0072 componentVisited[component] = true 0073 wireVisited[wire] = true 0074 component.updateOutput(wireVisited) 0075 } 0076 } 0077 }