1
/* GCompris - BCDToSevenSegment.qml
3
* Copyright (C) 2016 Pulkit Gupta <pulkitnsit@gmail.com>
6
* Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version)
7
* Pulkit Gupta <pulkitnsit@gmail.com> (Qt Quick port)
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 3 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, see <https://www.gnu.org/licenses/>.
23
import "../digital_electricity.js" as Activity
33
property var inputTerminalPosY: [0.125, 0.375, 0.625, 0.875]
34
property var outputTerminalPosY: [0.066, 0.211, 0.355, 0.5, 0.645, 0.789, 0.934]
36
property var redChar: ["BCDTo7SegmentA_on.svg","BCDTo7SegmentB_on.svg","BCDTo7SegmentC_on.svg",
37
"BCDTo7SegmentD_on.svg","BCDTo7SegmentE_on.svg","BCDTo7SegmentF_on.svg",
38
"BCDTo7SegmentG_on.svg"]
40
information: qsTr("BCD to 7 segment converter takes 4 binary inputs in its input terminals " +
41
"and gives 7 binary outputs which allow to light BCD number segments (binary-coded decimal) " +
42
"to display numbers between 0 and 9. The output for BCD To 7 Segment converted is:")
44
truthTable: [['D','C','B','A','a','b','c','d','e','f','g'],
45
['0','0','0','0','1','1','1','1','1','1','0'],
46
['0','0','0','1','0','1','1','0','0','0','0'],
47
['0','0','1','0','1','1','0','1','1','0','1'],
48
['0','0','1','1','1','1','1','1','0','0','1'],
49
['0','1','0','0','0','1','1','0','0','1','1'],
50
['0','1','0','1','1','0','1','1','0','1','1'],
51
['0','1','1','0','1','0','1','1','1','1','1'],
52
['0','1','1','1','1','1','1','0','0','0','0'],
53
['1','0','0','0','1','1','1','1','1','1','1'],
54
['1','0','0','1','1','1','1','1','0','1','1']]
56
property alias inputTerminals: inputTerminals
57
property alias outputTerminals: outputTerminals
62
delegate: inputTerminal
67
posY: inputTerminalPosY[index]
76
delegate: outputTerminal
81
posY: outputTerminalPosY[index]
87
function updateOutput(wireVisited) {
89
for(i = 1 ; i < truthTable.length ; ++i) {
91
for(j = 0 ; j < noOfInputs; ++j) {
92
if(inputTerminals.itemAt(j).value != truthTable[i][j])
98
if(i == truthTable.length) {
99
for(var j = 0 ; j < noOfOutputs ; ++j) {
100
outputTerminals.itemAt(j).value = 0
101
outputChar.itemAt(j).source = "qrc:/gcompris/src/core/resource/empty.svg"
105
for(var j = 0 ; j < noOfOutputs ; ++j) {
106
var terminal = outputTerminals.itemAt(j)
107
terminal.value = truthTable[i][j + noOfInputs]
108
outputChar.itemAt(j).source = (terminal.value == 0 ? "qrc:/gcompris/src/core/resource/empty.svg" : Activity.url + redChar[j])
112
for(var i = 0 ; i < noOfOutputs ; ++i) {
113
var terminal = outputTerminals.itemAt(i)
114
for(var j = 0 ; j < terminal.wires.length ; ++j)
115
terminal.wires[j].to.value = terminal.value
118
var componentVisited = []
119
for(var i = 0 ; i < noOfOutputs ; ++i) {
120
var terminal = outputTerminals.itemAt(i)
121
for(var j = 0 ; j < terminal.wires.length ; ++j) {
122
var wire = terminal.wires[j]
123
var component = wire.to.parent
124
if(componentVisited[component] != true && wireVisited[wire] != true) {
125
componentVisited[component] = true
126
wireVisited[wire] = true
127
component.updateOutput(wireVisited)
136
delegate: outputCharImages
141
anchors.centerIn: parent
142
height: parent.height
144
fillMode: Image.PreserveAspectFit