/* GCompris - XorGate.qml * * Copyright (C) 2016 Pulkit Gupta * * Authors: * Bruno Coudoin (GTK+ version) * Pulkit Gupta (Qt Quick port) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ import QtQuick 2.6 import GCompris 1.0 ElectricalComponent { id: xorGate terminalSize: 0.5 noOfInputs: 2 noOfOutputs: 1 property var inputTerminalPosY: [0.2, 0.8] information: qsTr("XOR gate outputs 1 if the number of '1' in input is odd, and 0 if number of '1' in " + "input is even. In this activity, a 2 input XOR gate is shown. Output for 2 input XOR gate is:") truthTable: [['A','B',qsTr("A XOR B")], ['0','0','0'], ['0','1','1'], ['1','0','1'], ['1','1','0']] property alias inputTerminals: inputTerminals property alias outputTerminals: outputTerminals Repeater { id: inputTerminals model: 2 delegate: inputTerminal Component { id: inputTerminal TerminalPoint { posX: 0.04 posY: inputTerminalPosY[index] type: "In" } } } Repeater { id: outputTerminals model: 1 delegate: outputTerminal Component { id: outputTerminal TerminalPoint { posX: 0.96 posY: 0.5 type: "Out" } } } function updateOutput(wireVisited) { var terminal = outputTerminals.itemAt(0) terminal.value = inputTerminals.itemAt(0).value ^ inputTerminals.itemAt(1).value for(var i = 0 ; i < terminal.wires.length ; ++i) terminal.wires[i].to.value = terminal.value var componentVisited = [] for(var i = 0 ; i < terminal.wires.length ; ++i) { var wire = terminal.wires[i] var component = wire.to.parent componentVisited[component] = true wireVisited[wire] = true component.updateOutput(wireVisited) } } }