diff --git a/src/activities/digital_electricity/components/AndGate.qml b/src/activities/digital_electricity/components/AndGate.qml index 8a32c19f4..d8846d1f9 100644 --- a/src/activities/digital_electricity/components/AndGate.qml +++ b/src/activities/digital_electricity/components/AndGate.qml @@ -1,97 +1,98 @@ /* GCompris - AndGate.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.3 import GCompris 1.0 ElectricalComponent { id: andGate terminalSize: 0.246 noOfInputs: 2 noOfOutputs: 1 property variant inputTerminalPosY: [0.219, 0.773] information: qsTr("AND gate takes 2 or more binary input in its input terminals and outputs a single " + "value. The output is 0 if any of the input is 0, else it is 1. In this activity, " + "a 2 input AND gate is shown. Truth table for 2 input AND gate is:") truthTable: [['A','B',"A.B"], ['0','0','0'], ['0','1','0'], ['1','0','0'], ['1','1','1']] property alias inputTerminals: inputTerminals property alias outputTerminals: outputTerminals Repeater { id: inputTerminals model: 2 delegate: inputTerminal Component { id: inputTerminal TerminalPoint { posX: 0.045 posY: inputTerminalPosY[index] type: "In" } } } Repeater { id: outputTerminals model: 1 delegate: outputTerminal Component { id: outputTerminal TerminalPoint { posX: 0.955 posY: 0.5 type: "Out" } } } function updateOutput(wireVisited) { var terminal = outputTerminals.itemAt(0) - terminal.value = inputTerminals.itemAt(0).value & inputTerminals.itemAt(1).value + /* Keep the output value == 0 if only one of the input terminals is connected */ + terminal.value = (inputTerminals.itemAt(0).wires.length != 0 && inputTerminals.itemAt(1).wires.length != 0) ? (inputTerminals.itemAt(0).value & inputTerminals.itemAt(1).value) : 0 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 /* // NOTE: Removed because the output of a > 1 input gate may depend on > 1 conditions // thus it may be needed to be revisited if(componentVisited[component] != true && wireVisited[wire] != true) { componentVisited[component] = true wireVisited[wire] = true component.updateOutput(wireVisited) } */ componentVisited[component] = true wireVisited[wire] = true component.updateOutput(wireVisited) } } } diff --git a/src/activities/digital_electricity/components/NandGate.qml b/src/activities/digital_electricity/components/NandGate.qml index dc1016fb1..6a1bd549f 100644 --- a/src/activities/digital_electricity/components/NandGate.qml +++ b/src/activities/digital_electricity/components/NandGate.qml @@ -1,97 +1,98 @@ /* GCompris - NandGate.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.3 import GCompris 1.0 ElectricalComponent { id: nandGate terminalSize: 0.273 noOfInputs: 2 noOfOutputs: 1 property variant inputTerminalPosY: [0.174, 0.786] information: qsTr("NAND gate takes 2 or more binary input in its input terminals and outputs a single " + "value. It is the complement of AND gate. In this activity, a 2 input NAND gate is " + "shown. Truth table for 2 input NAND gate is:") truthTable: [['A','B',"~(A.B)"], ['0','0','1'], ['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.045 posY: inputTerminalPosY[index] type: "In" } } } Repeater { id: outputTerminals model: 1 delegate: outputTerminal Component { id: outputTerminal TerminalPoint { posX: 0.955 posY: 0.484 type: "Out" } } } function updateOutput(wireVisited) { var terminal = outputTerminals.itemAt(0) - terminal.value = !(inputTerminals.itemAt(0).value & inputTerminals.itemAt(1).value) + /* Keep the output value == 0 if only one of the input terminals is connected */ + terminal.value = (inputTerminals.itemAt(0).wires.length != 0 && inputTerminals.itemAt(1).wires.length != 0) ? !(inputTerminals.itemAt(0).value & inputTerminals.itemAt(1).value) : 0 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 /* // NOTE: Removed because the output of a > 1 input gate may depend on > 1 conditions // thus it may be needed to be revisited if(componentVisited[component] != true && wireVisited[wire] != true) { componentVisited[component] = true wireVisited[wire] = true component.updateOutput(wireVisited) } */ componentVisited[component] = true wireVisited[wire] = true component.updateOutput(wireVisited) } } } diff --git a/src/activities/digital_electricity/components/NorGate.qml b/src/activities/digital_electricity/components/NorGate.qml index 0368a56f8..24af47b50 100644 --- a/src/activities/digital_electricity/components/NorGate.qml +++ b/src/activities/digital_electricity/components/NorGate.qml @@ -1,97 +1,98 @@ /* GCompris - NorGate.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.3 import GCompris 1.0 ElectricalComponent { id: norGate terminalSize: 0.251 noOfInputs: 2 noOfOutputs: 1 property variant inputTerminalPosY: [0.205, 0.769] information: qsTr("NOR gate takes 2 or more binary input in its input terminals and outputs a single " + "value. It is the complement of OR gate. In this activity, a 2 input NOR gate is " + "shown. Truth table for 2 input NOR gate is:") truthTable: [['A','B',"~(A+B)"], ['0','0','1'], ['0','1','0'], ['1','0','0'], ['1','1','0']] property alias inputTerminals: inputTerminals property alias outputTerminals: outputTerminals Repeater { id: inputTerminals model: 2 delegate: inputTerminal Component { id: inputTerminal TerminalPoint { posX: 0.045 posY: inputTerminalPosY[index] type: "In" } } } Repeater { id: outputTerminals model: 1 delegate: outputTerminal Component { id: outputTerminal TerminalPoint { posX: 0.955 posY: 0.491 type: "Out" } } } function updateOutput(wireVisited) { var terminal = outputTerminals.itemAt(0) - terminal.value = !(inputTerminals.itemAt(0).value | inputTerminals.itemAt(1).value) + /* Keep the output value == 0 if only one of the input terminals is connected */ + terminal.value = (inputTerminals.itemAt(0).wires.length != 0 && inputTerminals.itemAt(1).wires.length != 0) ? !(inputTerminals.itemAt(0).value | inputTerminals.itemAt(1).value) : 0 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 /* // NOTE: Removed because the output of a > 1 input gate may depend on > 1 conditions // thus it may be needed to be revisited if(componentVisited[component] != true && wireVisited[wire] != true) { componentVisited[component] = true wireVisited[wire] = true component.updateOutput(wireVisited) } */ componentVisited[component] = true wireVisited[wire] = true component.updateOutput(wireVisited) } } } diff --git a/src/activities/digital_electricity/components/NotGate.qml b/src/activities/digital_electricity/components/NotGate.qml index 9a8dcb5b0..cd0d1a335 100644 --- a/src/activities/digital_electricity/components/NotGate.qml +++ b/src/activities/digital_electricity/components/NotGate.qml @@ -1,87 +1,88 @@ /* GCompris - NotGate.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.3 import GCompris 1.0 ElectricalComponent { id: notGate terminalSize: 0.261 noOfInputs: 1 noOfOutputs: 1 information: qsTr("Not gate (also known as inverter) takes a binary input in its input terminal and " + "outputs a single value. The output is the complement of the input value, that is, it " + "is 0 if input is 1, and 1 if input is 0. Truth table for NOT gate is:") truthTable: [['A',"~A"], ['0','1'], ['1','0']] property alias inputTerminals: inputTerminals property alias outputTerminals: outputTerminals Repeater { id: inputTerminals model: 1 delegate: inputTerminal Component { id: inputTerminal TerminalPoint { posX: 0.046 posY: 0.503 type: "In" } } } Repeater { id: outputTerminals model: 1 delegate: outputTerminal Component { id: outputTerminal TerminalPoint { posX: 0.954 posY: 0.492 type: "Out" } } } function updateOutput(wireVisited) { var terminal = outputTerminals.itemAt(0) - terminal.value = !inputTerminals.itemAt(0).value + /* Keep the output value == 0 if only one of the input terminals is connected */ + terminal.value = (inputTerminals.itemAt(0).wires.length != 0) ? !inputTerminals.itemAt(0).value : 0 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 if(componentVisited[component] != true && wireVisited[wire] != true) { componentVisited[component] = true wireVisited[wire] = true component.updateOutput(wireVisited) } } } } diff --git a/src/activities/digital_electricity/components/OrGate.qml b/src/activities/digital_electricity/components/OrGate.qml index d6f20223b..d1f009931 100644 --- a/src/activities/digital_electricity/components/OrGate.qml +++ b/src/activities/digital_electricity/components/OrGate.qml @@ -1,96 +1,97 @@ /* GCompris - OrGate.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.3 import GCompris 1.0 ElectricalComponent { id: orGate terminalSize: 0.251 noOfInputs: 2 noOfOutputs: 1 property variant inputTerminalPosY: [0.223, 0.786] information: qsTr("OR gate takes 2 or more binary input in its input terminals and outputs a single " + "value. The output is 1 if any of the input is 1, else it is 0. In this activity, a " + "2 input OR gate is shown. Truth table for 2 input OR gate is:") truthTable: [['A','B',"A+B"], ['0','0','0'], ['0','1','1'], ['1','0','1'], ['1','1','1']] property alias inputTerminals: inputTerminals property alias outputTerminals: outputTerminals Repeater { id: inputTerminals model: 2 delegate: inputTerminal Component { id: inputTerminal TerminalPoint { posX: 0.045 posY: inputTerminalPosY[index] type: "In" } } } Repeater { id: outputTerminals model: 1 delegate: outputTerminal Component { id: outputTerminal TerminalPoint { posX: 0.955 posY: 0.509 type: "Out" } } } function updateOutput(wireVisited) { var terminal = outputTerminals.itemAt(0) - terminal.value = inputTerminals.itemAt(0).value | inputTerminals.itemAt(1).value + /* Keep the output value == 0 if only one of the input terminals is connected */ + terminal.value = (inputTerminals.itemAt(0).wires.length != 0 && inputTerminals.itemAt(1).wires.length != 0) ? (inputTerminals.itemAt(0).value | inputTerminals.itemAt(1).value) : 0 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 /* // NOTE: Removed because the output of a > 1 input gate may depend on > 1 conditions // thus it may be needed to be revisited if(componentVisited[component] != true && wireVisited[wire] != true) { componentVisited[component] = true wireVisited[wire] = true component.updateOutput(wireVisited) } */ componentVisited[component] = true wireVisited[wire] = true component.updateOutput(wireVisited) } } }