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