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