diff --git a/src/activities/digital_electricity/ActivityInfo.qml b/src/activities/digital_electricity/ActivityInfo.qml index f5b8db175..be6d8ca40 100644 --- a/src/activities/digital_electricity/ActivityInfo.qml +++ b/src/activities/digital_electricity/ActivityInfo.qml @@ -1,35 +1,35 @@ /* GCompris - ActivityInfo.qml * * Copyright (C) 2016 Pulkit Gupta * * 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 GCompris 1.0 ActivityInfo { name: "digital_electricity/DigitalElectricity.qml" difficulty: 1 icon: "digital_electricity/digital_electricity.svg" author: "Pulkit Gupta <pulkitnsit@gmail.com>" demo: true title: qsTr("Digital Electricity") description: qsTr("Create and simulate a digital electric schema") //intro: "put here in comment the text for the intro voice" goal: qsTr("Freely create a digital electric schema with a real time simulation of it.") prerequisite: qsTr("Requires some basic understanding of the concept of digital electronics.") - manual: qsTr("Drag electrical components from the selector and drop them in the working area.You can also move components by dragging them. To delete a component, select the deletion tool on top of the component selector, and select the component. You can click on the component and then on the rotate button to rotate it or info button to get information about it. You can click on the switch to open and close it. The simulation is updated in real time by any user action.") + manual: qsTr("Drag electrical components from the selector and drop them in the working area.You can also move components by dragging them. To delete a component, select the deletion tool on top of the component selector, and select the component. You can click on the component and then on the rotate button to rotate it or info button to get information about it. You can click on the switch to open and close it. To connect two terminals, click on first terminal, then on second terminal. To deselect terminal or delete tool, click on any empty area. The simulation is updated in real time by any user action.") credit: "" section: "fun" createdInVersion: 7000 } diff --git a/src/activities/digital_electricity/Component.qml b/src/activities/digital_electricity/Component.qml index a94a59a29..ab7eb09c8 100644 --- a/src/activities/digital_electricity/Component.qml +++ b/src/activities/digital_electricity/Component.qml @@ -1,140 +1,165 @@ /* GCompris - Component.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.0 +import QtQuick 2.3 import "digital_electricity.js" as Activity import GCompris 1.0 Image { id: electricalComponent property QtObject pieceParent property string imgSrc property double posX property double posY property double imgWidth property double imgHeight property int index property string toolTipTxt - property int rotationAngle - property int initialAngle + property int rotationAngle: 0 + property int initialAngle: 0 + property int startingAngle: 0 property int output + property double terminalSize + property variant inputs: [] + property variant outputs: [] property alias rotateComponent: rotateComponent x: posX * parent.width y: posY * parent.height width: imgWidth * parent.width height: imgHeight * parent.height fillMode: Image.PreserveAspectFit - state: "Initial" opacity: 1.0 source: Activity.url + imgSrc z: 2 + mipmap: true + antialiasing: true - onPaintedWidthChanged: {updateDragConstraints()} + onPaintedWidthChanged: { + updateDragConstraints() + Activity.updateWires(index) + } //SequentialAnimation { //id: rotateComponent //loops: Animation.Infinite PropertyAnimation { id: rotateComponent + //loops: 90 target: electricalComponent property: "rotation" - from: initialAngle; to: rotationAngle - duration: 750 + from: initialAngle; to: initialAngle + rotationAngle + duration: 1 onStarted:{Activity.animationInProgress = true} onStopped: { - Activity.animationInProgress = false - updateDragConstraints() + initialAngle = initialAngle + rotationAngle + //console.log("initialAngle",initialAngle) + Activity.updateWires(index) + if(initialAngle == startingAngle + rotationAngle * 45) { + if(initialAngle == 360 || initialAngle == -360) + initialAngle = 0 + startingAngle = initialAngle + Activity.animationInProgress = false + updateDragConstraints() + } + else rotateComponent.start() } easing.type: Easing.InOutQuad } //} function updateDragConstraints() { if(rotationAngle == 0 || rotationAngle == 180 || rotationAngle == 360 || rotationAngle == -360 || rotationAngle == -180) { mouseArea.drag.minimumX = (electricalComponent.paintedWidth - electricalComponent.width)/2 mouseArea.drag.minimumY = (electricalComponent.paintedHeight - electricalComponent.height)/2 mouseArea.drag.maximumX = electricalComponent.parent.width - (electricalComponent.width + electricalComponent.paintedWidth)/2 mouseArea.drag.maximumY = electricalComponent.parent.height - (electricalComponent.height + electricalComponent.paintedHeight)/2 } else { mouseArea.drag.minimumX = (electricalComponent.paintedHeight - electricalComponent.width)/2 mouseArea.drag.minimumY = (electricalComponent.paintedWidth - electricalComponent.height)/2 mouseArea.drag.maximumX = electricalComponent.parent.width - (electricalComponent.width + electricalComponent.paintedHeight)/2 mouseArea.drag.maximumY = electricalComponent.parent.height - (electricalComponent.height + electricalComponent.paintedWidth)/2 } //console.log("mouseArea",mouseArea.drag.minimumX,mouseArea.drag.minimumY) } MouseArea { id: mouseArea - anchors.fill: parent + //anchors.fill: parent + width: parent.paintedWidth + height: parent.paintedHeight + anchors.centerIn: parent drag.target: electricalComponent //drag.minimumX: 0 //drag.maximumX: electricalComponent.parent.width - (electricalComponent.width + electricalComponent.paintedWidth)/2 //drag.minimumY: 0 //drag.maximumY: (!parent && !parent.parent) ? (parent.parent.height - parent.height) : 0 onPressed: { + console.log("Component index",index) if(Activity.toolDelete) { Activity.updateToolTip("") Activity.removeComponent(index) } else { Activity.updateToolTip(toolTipTxt) Activity.componentSelected(index) } } + onPositionChanged: { + Activity.updateWires(index) + } onReleased: { /* console.log(parent.y, parent.height,parent.width,parent.height - parent.width/2) console.log(parent.paintedHeight,parent.paintedWidth) console.log("mouseArea",mouseArea.drag.minimumX,mouseArea.drag.minimumY) if(initialAngle == 0 || initialAngle == 180) { if ((parent.parent.height - parent.y > parent.paintedHeight) && (parent.parent.width - parent.x > parent.paintedWidth) && parent.x > 0 && parent.y > 0) { parent.posX = parent.x / parent.parent.width parent.posY = parent.y / parent.parent.height } } else if ((parent.parent.height - parent.y > parent.paintedHeight/2) && (parent.parent.width - parent.x > parent.paintedWidth/2) && parent.x > (parent.paintedHeight/2 - parent.paintedWidth/2) && parent.y > 0) { parent.posX = parent.x / parent.parent.width parent.posY = parent.y / parent.parent.height } */ parent.posX = parent.x / parent.parent.width parent.posY = parent.y / parent.parent.height parent.x = Qt.binding(function() { return parent.posX * parent.parent.width }) parent.y = Qt.binding(function() { return parent.posY * parent.parent.height }) Activity.updateToolTip("") } } } diff --git a/src/activities/digital_electricity/DigitalElectricity.qml b/src/activities/digital_electricity/DigitalElectricity.qml index c04d6b681..553f14716 100644 --- a/src/activities/digital_electricity/DigitalElectricity.qml +++ b/src/activities/digital_electricity/DigitalElectricity.qml @@ -1,225 +1,227 @@ /* GCompris - DigitalElectricity.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.1 import GCompris 1.0 import "../../core" import "digital_electricity.js" as Activity ActivityBase { id: activity onStart: focus = true onStop: {} pageComponent: Rectangle { id: background anchors.fill: parent color: "#ffffb3" signal start signal stop property bool vert: background.width > background.height Component.onCompleted: { activity.start.connect(start) activity.stop.connect(stop) } // Add here the QML items you need to access in javascript QtObject { id: items property Item main: activity.main property alias backgroundContainer: backgroundContainer property alias bar: bar property alias bonus: bonus property alias availablePieces: availablePieces property alias toolTip: toolTip property alias infoTxt: infoTxt property alias infoImage: infoImage } onStart: { Activity.start(items) } onStop: { Activity.stop() } Rectangle { id: backgroundContainer color: "#ffffb3" x: background.vert ? 90 * ApplicationInfo.ratio : 0 y: background.vert ? 0 : 90 * ApplicationInfo.ratio width: background.vert ? background.width - 90 * ApplicationInfo.ratio : background.width height: background.vert ? background.height - (bar.height * 1.1) : background.height - (bar.height * 1.1) - 90 * ApplicationInfo.ratio + //onHeightChanged: Activity.updateAllWires() + //onWidthChanged: Activity.updateAllWires() MouseArea { anchors.fill: parent onClicked: Activity.deselect() } GCText { id: infoTxt anchors { horizontalCenter: parent.horizontalCenter - top: tutorialTxtContainer.top + top: infoTxtContainer.top topMargin: 2 } fontSizeMode: Text.Fit minimumPixelSize: 10 color: "white" style: Text.Outline styleColor: "black" horizontalAlignment: Text.AlignHLeft width: Math.min(implicitWidth, 0.90 * parent.width) //background.vert ? Math.min(implicitWidth, 0.95 * parent.width) : //Math.min(implicitWidth, 0.85 * parent.width) height: infoImage.source == "" ? Math.min(implicitHeight, 0.9 * parent.height) : Math.min(implicitHeight, 0.4 * parent.height) wrapMode: TextEdit.WordWrap visible: false z: 4 } Rectangle { id: infoTxtContainer anchors.centerIn: parent width: infoTxt.width + 20 height: infoTxt.height + infoImage.height + 8 opacity: 0.8 radius: 10 border.width: 2 border.color: "black" visible: infoTxt.visible gradient: Gradient { GradientStop { position: 0.0; color: "#000" } GradientStop { position: 0.9; color: "#666" } GradientStop { position: 1.0; color: "#AAA" } } MouseArea { anchors.fill: parent onClicked: infoTxt.visible = false } z: 3 } Image { id: infoImage property int heightNeed: parent.height - infoTxt.height height: source == "" ? 0 : parent.height - infoTxt.height - 10 width: source == "" ? 0 : parent.width - 10 fillMode: Image.PreserveAspectFit visible: infoTxt.visible anchors { top: infoTxt.bottom horizontalCenter: parent.horizontalCenter } z: 5 } } Rectangle { id: leftWidget width: background.vert ? 90 * ApplicationInfo.ratio : background.width height: background.vert ? background.height : 90 * ApplicationInfo.ratio color: "#FFFF42" border.color: "#FFD85F" border.width: 4 anchors.left: parent.left ListWidget { id: availablePieces vert: background.vert ? true : false } } Rectangle { id: toolTip anchors { bottom: bar.top bottomMargin: 10 left: leftWidget.left leftMargin: 5 } width: toolTipTxt.width + 10 height: toolTipTxt.height + 5 opacity: 1 radius: 10 z: 100 border.width: 2 border.color: "black" gradient: Gradient { GradientStop { position: 0.0; color: "#000" } GradientStop { position: 0.9; color: "#666" } GradientStop { position: 1.0; color: "#AAA" } } property alias text: toolTipTxt.text Behavior on opacity { NumberAnimation { duration: 120 } } function show(newText) { if(newText) { text = newText opacity = 0.8 } else { opacity = 0 } } GCText { id: toolTipTxt anchors.centerIn: parent fontSize: regularSize color: "white" style: Text.Outline styleColor: "black" horizontalAlignment: Text.AlignHCenter wrapMode: TextEdit.WordWrap } } DialogHelp { id: dialogHelp onClose: home() } Bar { id: bar content: BarEnumContent { value: help | home | reload} onHelpClicked: { displayDialog(dialogHelp) } onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() onReloadClicked: Activity.reset() } Bonus { id: bonus Component.onCompleted: win.connect(Activity.nextLevel) } } } diff --git a/src/activities/digital_electricity/DragListItem.qml b/src/activities/digital_electricity/DragListItem.qml index 200509460..9db25edae 100644 --- a/src/activities/digital_electricity/DragListItem.qml +++ b/src/activities/digital_electricity/DragListItem.qml @@ -1,138 +1,142 @@ /* gcompris - DragListItem.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.1 +import QtQuick 2.3 import QtGraphicalEffects 1.0 import GCompris 1.0 import "digital_electricity.js" as Activity Item { id: item width: tile.width height: tile.height property string source: imgName property double heightInColumn property double widthInColumn property double tileWidth property double tileHeight property bool selected: false + //property double terminalSize: size signal pressed Rectangle { id: tile width: tileWidth height: tileHeight color: (parent.selected && tileImage.parent == tile) ? "#33FF294D" : "transparent" border.color: (parent.selected && tileImage.parent == tile) ? "white" : "transparent" border.width: 3 radius: 2 property double xCenter: tile.x + tile.width / 2 property double yCenter: tile.y + tile.height / 2 property bool selected: false Image { anchors.centerIn: parent width: widthInColumn height: heightInColumn fillMode: Image.PreserveAspectFit source: Activity.url + imgName } Image { id: tileImage anchors.centerIn: parent width: smallWidth height: smallHeight fillMode: Image.PreserveAspectFit source: Activity.url + imgName + mipmap: true + antialiasing: true property double smallWidth: widthInColumn property double smallHeight: heightInColumn property double fullWidth: imgWidth * backgroundContainer.width property double fullHeight: imgHeight * backgroundContainer.height property QtObject tileImageParent property bool small: true function toSmall() { width = smallWidth height = smallHeight small = true } function toFull() { width = fullWidth height = fullHeight small = false } MultiPointTouchArea { id: mouseArea touchPoints: [ TouchPoint { id: point1 } ] property real startX property real startY property bool pressedOnce anchors.fill: parent onPressed: { //item.pressed() //tileImage.toSmall() //console.log("onPressed 1",tileImage.parent) tileImage.anchors.centerIn = undefined //console.log("onPressed 2",tileImage.parent) startX = point1.x startY = point1.y tileImage.toFull() toolTip.show(toolTipText) pressedOnce = true item.selected = true } onUpdated: { var moveX = point1.x - startX var moveY = point1.y - startY parent.x = parent.x + moveX parent.y = parent.y + moveY //console.log("parent.x",parent.x,"parent.y",parent.y) } onReleased: { if (pressedOnce) { pressedOnce = false item.selected = false //console.log("dropped parent.x",parent.x,"parent.y",parent.y) var coord = backgroundContainer.mapFromItem(tileImage.parent, parent.x, parent.y) //console.log("coord.x",coord.x,"coord.y",coord.y) + //console.log("dropped",terminalSize) if(coord.x > 0 && (backgroundContainer.width - coord.x > tileImage.fullWidth)) - Activity.createComponent(coord.x, coord.y, imgName, imgWidth, imgHeight, toolTipText) + Activity.createComponent(coord.x, coord.y, imgName, imgWidth, imgHeight, toolTipText, terminalSize) tileImage.anchors.centerIn = tile tileImage.toSmall() toolTip.show("") } } } } } } diff --git a/src/activities/digital_electricity/TerminalPoint.qml b/src/activities/digital_electricity/TerminalPoint.qml new file mode 100644 index 000000000..92c34a389 --- /dev/null +++ b/src/activities/digital_electricity/TerminalPoint.qml @@ -0,0 +1,87 @@ +/* GCompris - TerminalPoint.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.0 +import "digital_electricity.js" as Activity + +import GCompris 1.0 + +Rectangle { + id: terminalPoint + + property double posX + property double posY + property double size: parent.terminalSize + property bool selected: false + property string type + property int value: -1 + property int index + property int componentIndex + property variant wireIndex: [] + + width: size * parent.paintedHeight + height: size * parent.paintedHeight + radius: width / 2 + color: "Black" + + x: (parent.width - parent.paintedWidth) / 2 + posX * parent.paintedWidth - width / 2 + y: (parent.height - parent.paintedHeight) / 2 + posY * parent.paintedHeight - height / 2 + + //property variant coord: parent.parent.mapFromItem(terminalPoint, terminalPoint.x + width / 2, terminalPoint.y + height / 2) + + property double xCenter: terminalPoint.parent.x + terminalPoint.x + width/2 + property double yCenter: terminalPoint.parent.y + terminalPoint.y + height/2 + //property double xCenterFromComponent: terminalPoint.parent.x + terminalPoint.parent.width / 2 - xCenter + //property double yCenterFromComponent: terminalPoint.parent.y + terminalPoint.parent.height / 2 - yCenter + property double xCenterFromComponent: terminalPoint.x + width/2 - terminalPoint.parent.width / 2 + property double yCenterFromComponent: terminalPoint.y + height/2 - terminalPoint.parent.height / 2 + + Rectangle { + id: boundary + anchors.centerIn: terminalPoint + width: terminalPoint.width * 1.4 + height: width + visible: selected + radius: width / 2 + color: "green" + z: -1 + } + + MouseArea { + id: mouseArea + anchors.fill: parent + onPressed: { + selected = true + console.log("Pressed Terminal",index,type,value) + Activity.terminalPointSelected(index) + //parent.parent.parent.moveFromX = parent.parent.x + mouseX + //parent.parent.parent.moveFromY = parent.parent.y + mouseY + } + /* + onPositionChanged: { + parent.parent.parent.moveToX = parent.parent.x + mouseX + parent.parent.parent.moveToY = parent.parent.y + mouseY + //console.log(parent.parent.parent.moveToX,parent.parent.parent.moveToY) + //console.log(parent.parent.x + mouseX,parent.parent.y + mouseY) + parent.parent.parent.requestPaint() + }*/ + } +} diff --git a/src/activities/digital_electricity/Wire.qml b/src/activities/digital_electricity/Wire.qml new file mode 100644 index 000000000..7d171bb00 --- /dev/null +++ b/src/activities/digital_electricity/Wire.qml @@ -0,0 +1,66 @@ +/* GCompris - Wire.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.0 +import "digital_electricity.js" as Activity + +import GCompris 1.0 + +Rectangle { + id: wire + + //property double posX1 + //property double posY1 + //property double posX2 + //property double posY2 + //property double rectWidth + //property double rotateAngle + property string wireColor + + property int index + property int from + property int to + + //width: rectWidth + height: 5 + color: wireColor //"Red" + radius: height / 2 + + //x: posX1 + //y: posY1 + + transformOrigin: Item.Left + //rotation: rotateAngle + + MouseArea { + id: mouseArea + //anchors.fill: parent + width: parent.width + height: parent.height * 3 + anchors.centerIn: parent + onPressed: { + console.log("Pressed Wire",index,color,wireColor) + if(Activity.toolDelete) { + Activity.removeWire(index) + } + } + } +} diff --git a/src/activities/digital_electricity/digital_electricity.js b/src/activities/digital_electricity/digital_electricity.js index 44beed17f..80416a4a4 100644 --- a/src/activities/digital_electricity/digital_electricity.js +++ b/src/activities/digital_electricity/digital_electricity.js @@ -1,334 +1,789 @@ /* GCompris - digital_electricity.js * * 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 . */ .pragma library .import QtQuick 2.0 as Quick var currentLevel = 0 var numberOfLevel = 4 var items var url = "qrc:/gcompris/src/activities/digital_electricity/resource/" -var components = [] -var componentIndex = 0 +//var componentIndex = 0 var toolDelete -var deletedIndex = [] var selectedIndex var animationInProgress +var selectedTerminal +var terminals = [] +var deletedIndex = [] +var components = [] +var wires = [] +var connected = [] +var deletedWireIndex = [] +var colors = ["red","green","blue","blueviolet","silver"] function start(items_) { items = items_ currentLevel = 0 items.availablePieces.model.append( { + "imgName": "zero.svg", + "imgWidth": 0.12, + "imgHeight": 0.2, + "toolTipText": qsTr("Zero input"), + "terminalSize": 0.205 + }); + items.availablePieces.model.append( { + "imgName": "one.svg", + "imgWidth": 0.12, + "imgHeight": 0.2, + "toolTipText": qsTr("One input"), + "terminalSize": 0.218 + }); + /*items.availablePieces.model.append( { "imgName": "battery.svg", "imgWidth": 0.13, "imgHeight": 0.18, "toolTipText": qsTr("Battery") }); items.availablePieces.model.append( { "imgName": "comparator.svg", "imgWidth": 0.3, "imgHeight": 0.25, "toolTipText": qsTr("Comparator") - }); + });*/ items.availablePieces.model.append( { "imgName": "ledOff.svg", "imgWidth": 0.16, "imgHeight": 0.2, - "toolTipText": qsTr("LED") + "toolTipText": qsTr("LED"), + "terminalSize": 0.111 }); - items.availablePieces.model.append( { + /*items.availablePieces.model.append( { "imgName": "switchOff.svg", "imgWidth": 0.18, "imgHeight": 0.15, "toolTipText": qsTr("Switch") }); items.availablePieces.model.append( { "imgName": "BCDTo7Segment.svg", "imgWidth": 0.3, "imgHeight": 0.4, "toolTipText": qsTr("BCD To 7 Segment") }); - //*/ items.availablePieces.model.append( { "imgName": "sevenSegmentDisplay.svg", "imgWidth": 0.18, "imgHeight": 0.4, - "toolTipText": qsTr("7 Segment Display") + "toolTipText": qsTr("7 Segment Display"), + "terminalSize": 0.097 }); + */ items.availablePieces.model.append( { "imgName": "gateAnd.svg", "imgWidth": 0.15, "imgHeight": 0.12, - "toolTipText": qsTr("AND gate") + "toolTipText": qsTr("AND gate"), + "terminalSize": 0.246 }); - items.availablePieces.model.append( { + /*items.availablePieces.model.append( { "imgName": "gateNand.svg", "imgWidth": 0.15, "imgHeight": 0.12, "toolTipText": qsTr("NAND gate") }); items.availablePieces.model.append( { "imgName": "gateNor.svg", "imgWidth": 0.15, "imgHeight": 0.12, "toolTipText": qsTr("NOR gate") }); items.availablePieces.model.append( { "imgName": "gateNot.svg", "imgWidth": 0.15, "imgHeight": 0.12, "toolTipText": qsTr("Not gate") }); items.availablePieces.model.append( { "imgName": "gateOr.svg", "imgWidth": 0.15, "imgHeight": 0.12, "toolTipText": qsTr("Or gate") }); items.availablePieces.model.append( { "imgName": "gateXor.svg", "imgWidth": 0.15, "imgHeight": 0.12, "toolTipText": qsTr("Xor gate") }); //*/ //items.availablePieces.view.refreshLeftWidget() initLevel() } function stop() { + for(var i = 0 ; i < components.length ; ++i) { var j for(j = 0 ; j < deletedIndex.length ; ++j) { if(deletedIndex[j] == i) break } if(j == deletedIndex.length) components[i].destroy() } + + /*for(var i = 0 ; i < terminals.length ; ++i) { + terminals[i].destroy(); + }*/ + + for(var i = 0 ; i < wires.length ; ++i) { + var j + for(j = 0 ; j < deletedWireIndex.length ; ++j) { + if(deletedWireIndex[j] == i) + break + } + if(j == deletedWireIndex.length) + wires[i].destroy() + } } function initLevel() { items.availablePieces.view.currentDisplayedGroup = 0 items.availablePieces.view.previousNavigation = 1 items.availablePieces.view.nextNavigation = 1 + terminals = [] + deletedIndex = [] + components = [] + wires = [] + connected = [] + deletedWireIndex = [] animationInProgress = false deselect() updateToolTip("") } function reset() { deselect() stop() initLevel() } -function createComponent(x, y, src, imgWidth, imgHeight, toolTipTxt) { +function createComponent(x, y, src, imgWidth, imgHeight, toolTipTxt, terminalSize) { var electricComponent = Qt.createComponent("qrc:/gcompris/src/activities/digital_electricity/Component.qml") if (electricComponent.status == electricComponent.Error) { // Error Handling console.log("Error loading component:", electricComponent.errorString()); } //console.log("Inside createComponent") x = x / items.backgroundContainer.width y = y / items.backgroundContainer.height //console.log("x",x,"y",y) var index if(deletedIndex.length > 0) { index = deletedIndex[deletedIndex.length - 1] deletedIndex.pop() } else index = components.length components[index] = electricComponent.createObject( items.backgroundContainer, { "index": index, "posX": x, "posY": y, "imgSrc": src, "imgWidth": imgWidth, "imgHeight": imgHeight, "toolTipTxt": toolTipTxt, - "initialAngle": 0, - "rotationAngle": 0 + "terminalSize": terminalSize }); + + var electricComponentCreated = components[index] + var terminalComponent = Qt.createComponent("qrc:/gcompris/src/activities/digital_electricity/TerminalPoint.qml") + //console.log("Error loading component:", terminalComponent.errorString()) + var terminalIndex = terminals.length + //console.log("terminalIndex",terminalIndex) + if(src == "zero.svg") { + electricComponentCreated.outputs.push(terminalIndex) + terminals[terminalIndex++] = terminalComponent.createObject( + electricComponentCreated, { + "posX": 0.91, + "posY": 0.5, + "index": terminalIndex - 1, + "type": "Out", + "componentIndex": index, + "value": 0 + }); + } + else if(src == "one.svg") { + electricComponentCreated.outputs.push(terminalIndex) + terminals[terminalIndex++] = terminalComponent.createObject( + electricComponentCreated, { + "posX": 0.91, + "posY": 0.5, + "index": terminalIndex - 1, + "type": "Out", + "componentIndex": index, + "value": 1 + }); + } + else if(src == "gateAnd.svg") { + electricComponentCreated.inputs.push(terminalIndex) + terminals[terminalIndex++] = terminalComponent.createObject( + electricComponentCreated, { + "posX": 0.045, + "posY": 0.219, + "index": terminalIndex - 1, + "type": "In", + "componentIndex": index + }); + electricComponentCreated.inputs.push(terminalIndex) + terminals[terminalIndex++] = terminalComponent.createObject( + electricComponentCreated, { + "posX": 0.045, + "posY": 0.773, + "index": terminalIndex - 1, + "type": "In", + "componentIndex": index + }); + electricComponentCreated.outputs.push(terminalIndex) + terminals[terminalIndex++] = terminalComponent.createObject( + electricComponentCreated, { + "posX": 0.955, + "posY": 0.5, + "index": terminalIndex - 1, + "type": "Out", + "componentIndex": index + }); + } + else if(src == "ledOff.svg") { + electricComponentCreated.inputs.push(terminalIndex) + terminals[terminalIndex++] = terminalComponent.createObject( + electricComponentCreated, { + "posX": 0.319, + "posY": 0.945, + "index": terminalIndex - 1, + "type": "In", + "componentIndex": index + }); + electricComponentCreated.inputs.push(terminalIndex) + terminals[terminalIndex++] = terminalComponent.createObject( + electricComponentCreated, { + "posX": 0.776, + "posY": 0.698, + "index": terminalIndex - 1, + "type": "In", + "componentIndex": index + }); + } + //terminal[index] = [] + /*if(src == "sevenSegmentDisplay.svg") { + var i = 0 + terminal[0] = terminalComponent.createObject( + electricComponentCreated, { + "posX": 0.05, + "posY": 0.049 + }); + terminal[1] = terminalComponent.createObject( + electricComponentCreated, { + "posX": 0.05, + "posY": 0.196 + }); + terminalComponent.createObject( + electricComponentCreated, { + "posX": 0.05, + "posY": 0.336 + }); + terminalComponent.createObject( + electricComponentCreated, { + "posX": 0.05, + "posY": 0.484 + }); + terminalComponent.createObject( + electricComponentCreated, { + "posX": 0.05, + "posY": 0.641 + }); + terminalComponent.createObject( + electricComponentCreated, { + "posX": 0.05, + "posY": 0.796 + }); + terminalComponent.createObject( + electricComponentCreated, { + "posX": 0.05, + "posY": 0.951 + }); + }*/ + + //console.log("Error loading component:", electricComponent.errorString()); componentSelected(index) //console.log("index",index,"toolTipTxt",toolTipTxt,components[index].toolTipTxt) //console.log("posX",x,"posX",components[components.length-1].posX) } +function terminalPointSelected(index) { + + if(selectedTerminal == -1 || selectedTerminal == index) + selectedTerminal = index + else if((terminals[index].type != terminals[selectedTerminal].type) && + terminals[index].componentIndex != terminals[selectedTerminal].componentIndex) { + var inIndex = terminals[index].type == "In" ? index : selectedTerminal + var outIndex = terminals[index].type == "Out" ? index : selectedTerminal + //console.log("in, connected[inIndex]",connected[inIndex],"inIndex",inIndex) + if(connected[inIndex] == undefined || connected[inIndex] == -1) { + //console.log("in2") + var wireComponent = Qt.createComponent("qrc:/gcompris/src/activities/digital_electricity/Wire.qml") + //console.log("Error loading component:", wireComponent.errorString()) + /*var x1 = terminals[outIndex].xCenter + var y1 = terminals[outIndex].yCenter + var x2 = terminals[inIndex].xCenter + var y2 = terminals[inIndex].yCenter + //console.log("index",index,"selectedTerminal",selectedTerminal,"x1",x1,"x2",x2,"y1",y1,"y2",y2) + var width = Math.pow((Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)),0.5) + 2 + var angle = (180/Math.PI)*Math.atan((y2-y1)/(x2-x1)) + if(x2 - x1 < 0) angle = angle - 180 + *///console.log("angle=",angle) + + var index + if(deletedWireIndex.length > 0) { + index = deletedWireIndex[deletedWireIndex.length - 1] + deletedWireIndex.pop() + } + else + index = wires.length + + var colorIndex = Math.floor(Math.random() * colors.length) + //console.log("colorIndex",colorIndex) + wires[index] = wireComponent.createObject( + items.backgroundContainer, { + //"posX1": x1, + //"posY1": y1, + //"posX2": x2, + //"posY2": y2, + "from": outIndex, + "to": inIndex, + //"rectWidth": width, + //"rotateAngle": angle, + "wireColor": colors[colorIndex], + "index": index + }); + terminals[inIndex].value = terminals[outIndex].value + terminals[inIndex].wireIndex.push(index) + terminals[outIndex].wireIndex.push(index) + //console.log("terminals[outIndex].wireIndex.length",terminals[outIndex].wireIndex.length) + updateWires(terminals[inIndex].componentIndex) + updateWires(terminals[outIndex].componentIndex) + updateComponent(terminals[inIndex].componentIndex) + connected[inIndex] = outIndex + } + deselect() + } + else { + //console.log("else") + deselect() + selectedTerminal = index + terminals[index].selected = true + } +} + +function updateComponent(index) { + + var visited = [] + /*for(var i = 0 ; i < components.length ; ++i) { + var j + for(j = 0 ; j < deletedIndex.length ; ++j) { + if(deletedIndex[j] == i) + break + } + if(j == deletedIndex.length) + visited[i] = false + }*/ + + updateComponentUtility(index, visited) +} + +function updateComponentUtility(index, visited) { + + //console.log("index",index,"components[index].imgSrc",components[index].imgSrc) + if(visited[index] != undefined) // To prevent infinite loop because of bad connection + return + visited[index] = true + + var component = components[index] + if(component.imgSrc == "gateAnd.svg") { + var output = 1 + for(var i = 0 ; i < 2 ; ++i) { + var value = terminals[component.inputs[i]].value + if(value == -1) { + output = -1 + break + } + output = output && value + } + //console.log("output",output) + terminals[component.outputs[0]].value = output + } + else if(component.imgSrc == "ledOff.svg") { + if(terminals[component.inputs[0]].value == 1 && terminals[component.inputs[1]].value == 0) + component.source = url + "ledOn.svg" + else + component.source = url + "ledOff.svg" + //console.log("component.source",component.source) + return + } + //console.log("component index",index) + + for(var i = 0 ; i < component.outputs.length ; ++i) { + var terminal = terminals[component.outputs[i]] + for(var j = 0 ; j < terminal.wireIndex.length ; ++j) { + terminals[wires[terminal.wireIndex[j]].to].value = terminal.value + } + } + + for(var i = 0 ; i < component.outputs.length ; ++i) { + var terminal = terminals[component.outputs[i]] + //console.log("terminal index",terminal.index) + for(var j = 0 ; j < terminal.wireIndex.length ; ++j) { + //console.log("wires[terminal.wireIndex[j]].to",wires[terminal.wireIndex[j]].to) + updateComponentUtility(terminals[wires[terminal.wireIndex[j]].to].componentIndex,visited) + } + } +} + +/* +function updateAllWires() { + + for(var i = 0 ; i < components.length ; ++i) { + var j + for(j = 0 ; j < deletedIndex.length ; ++j) { + if(deletedIndex[j] == i) + break + } + if(j == deletedIndex.length) + updateWires(i) + } +}*/ + +function updateWires(index) { + + var component = components[index] + if(component == undefined || component.inputs == undefined || component.outputs == undefined) + return + + var rotatedAngle = component.initialAngle * Math.PI / 180 + for(var i = 0 ; i < component.inputs.length ; ++i) { + var terminal = terminals[component.inputs[i]] + if(terminal.wireIndex.length != 0) { + var wire = wires[terminal.wireIndex[0]] + var otherAngle = components[terminals[wire.from].componentIndex].initialAngle * Math.PI / 180 + var x = terminals[wire.from].xCenterFromComponent + var y = terminals[wire.from].yCenterFromComponent + var x1 = terminals[wire.from].xCenter - x + x * Math.cos(otherAngle) - y * Math.sin(otherAngle) + var y1 = terminals[wire.from].yCenter - y + x * Math.sin(otherAngle) + y * Math.cos(otherAngle) + //console.log(otherComponentAngle,x,y,x1,y1) + + x = terminal.xCenterFromComponent + y = terminal.yCenterFromComponent + var x2 = terminal.xCenter - x + x * Math.cos(rotatedAngle) - y * Math.sin(rotatedAngle) + var y2 = terminal.yCenter - y + x * Math.sin(rotatedAngle) + y * Math.cos(rotatedAngle) + + /*if((rotatedAngle > 0 && rotatedAngle <= 90) || rotatedAngle == -270) { + x2 = component.x + component.width / 2 + (terminal.yCenterFromComponent * rotatedAngle) / 90 + y2 = component.y + component.height / 2 - (terminal.xCenterFromComponent * rotatedAngle) / 90 + } + else if(rotatedAngle == 180 || rotatedAngle == -180) { + x2 = x2 + terminal.xCenterFromComponent * 2 + y2 = y2 + terminal.yCenterFromComponent * 2 + } + else if(rotatedAngle == 270 || rotatedAngle == -90) { + x2 = component.x + component.width / 2 - terminal.yCenterFromComponent + y2 = component.y + component.height / 2 + terminal.xCenterFromComponent + }*/ + + var width = Math.pow((Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)),0.5) + 2 + var angle = (180/Math.PI)*Math.atan((y2-y1)/(x2-x1)) + if(x2 - x1 < 0) angle = angle - 180 + //wire.posX1 = x1 + //wire.posY1 = y1 + //wire.posX2 = x2 + //wire.posY2 = y2 + wire.x = x1 + wire.y = y1 + wire.width = width + wire.rotation = angle + //wire.rotateAngle = angle + } + } + //console.log("component index",component.index,"component.outputs.length",component.outputs.length) + for(var i = 0 ; i < component.outputs.length ; ++i) { + var terminal = terminals[component.outputs[i]] + //console.log("terminal index",terminal.index,"component.outputs[i]",component.outputs[i]) + for(var j = 0 ; j < terminal.wireIndex.length ; ++j) { + var x = terminal.xCenterFromComponent + var y = terminal.yCenterFromComponent + var x1 = terminal.xCenter - x + x * Math.cos(rotatedAngle) - y * Math.sin(rotatedAngle) + var y1 = terminal.yCenter - y + x * Math.sin(rotatedAngle) + y * Math.cos(rotatedAngle) + + var wire = wires[terminal.wireIndex[j]] + var otherAngle = components[terminals[wire.to].componentIndex].initialAngle * Math.PI / 180 + x = terminals[wire.to].xCenterFromComponent + y = terminals[wire.to].yCenterFromComponent + var x2 = terminals[wire.to].xCenter - x + x * Math.cos(otherAngle) - y * Math.sin(otherAngle) + var y2 = terminals[wire.to].yCenter - y + x * Math.sin(otherAngle) + y * Math.cos(otherAngle) + + /*if(rotatedAngle == 90 || rotatedAngle == -270) { + x1 = component.x + component.width / 2 + terminal.yCenterFromComponent + y1 = component.y + component.height / 2 - terminal.xCenterFromComponent + } + else if(rotatedAngle == 180 || rotatedAngle == -180) { + x1 = x1 + terminal.xCenterFromComponent * 2 + y1 = y1 + terminal.yCenterFromComponent * 2 + } + else if(rotatedAngle == 270 || rotatedAngle == -90) { + x1 = component.x + component.width / 2 - terminal.yCenterFromComponent + y1 = component.y + component.height / 2 + terminal.xCenterFromComponent + }*/ + + var width = Math.pow((Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)),0.5) + 2 + var angle = (180/Math.PI)*Math.atan((y2-y1)/(x2-x1)) + if(x2 - x1 < 0) angle = angle - 180 + //wire.posX1 = x1 + //wire.posY1 = y1 + //wire.posX2 = x2 + //wire.posY2 = y2 + wire.x = x1 + wire.y = y1 + wire.width = width + wire.rotation = angle + //wire.rotateAngle = angle + } + } +} + function deselect() { + items.availablePieces.toolDelete.state = "notSelected" items.availablePieces.rotateLeft.state = "canNotBeSelected" items.availablePieces.rotateRight.state = "canNotBeSelected" items.availablePieces.info.state = "canNotBeSelected" items.infoTxt.visible = false toolDelete = false selectedIndex = -1 + selectedTerminal = -1 + for(var i = 0 ; i < terminals.length ; ++i) { + terminals[i].selected = false + } } function removeComponent(index) { + var component = components[index] + for(var i = 0 ; i < component.inputs.length ; ++i) { + var terminal = terminals[component.inputs[i]] + if(terminal.wireIndex.length != 0) // Input Terminal can have only 1 wire + removeWire(terminal.wireIndex[0]) + } + for(var i = 0 ; i < component.outputs.length ; ++i) { + var terminal = terminals[component.outputs[i]] + //console.log("Remove terminal.wireIndex.length",terminal.wireIndex.length) + while (terminal.wireIndex.length != 0) { + //console.log("terminal.wireIndex[j]",terminal.wireIndex[j]) + removeWire(terminal.wireIndex[0]) // Output Terminal can have more than 1 wire + } + } components[index].destroy() deletedIndex.push(index) } +function removeWire(index) { + + var wire = wires[index] + var inTerminal = terminals[wire.to] + var outTerminal = terminals[wire.from] + + var removeIndex = inTerminal.wireIndex.indexOf(index) + inTerminal.wireIndex.splice(removeIndex,1) + removeIndex = outTerminal.wireIndex.indexOf(index) + outTerminal.wireIndex.splice(removeIndex,1) + //removeIndex = connected.indexOf(wire.to) + //connected.splice(wire.to,1) + connected[wire.to] = -1 + + inTerminal.value = -1 + wires[index].destroy() + deletedWireIndex.push(index) + updateComponent(inTerminal.componentIndex) +} + function componentSelected(index) { + selectedIndex = index items.availablePieces.rotateLeft.state = "canBeSelected" items.availablePieces.rotateRight.state = "canBeSelected" items.availablePieces.info.state = "canBeSelected" } function rotateLeft() { - components[selectedIndex].rotationAngle = components[selectedIndex].initialAngle - 90 + components[selectedIndex].rotationAngle = -2//components[selectedIndex].initialAngle - 90 //console.log("rotationAngle",components[selectedIndex].rotationAngle) components[selectedIndex].rotateComponent.start() - components[selectedIndex].initialAngle = components[selectedIndex].rotationAngle == -360 ? 0 : - components[selectedIndex].rotationAngle + /*components[selectedIndex].initialAngle = components[selectedIndex].rotationAngle == -360 ? 0 : + components[selectedIndex].rotationAngle*/ } function rotateRight() { - components[selectedIndex].rotationAngle = components[selectedIndex].initialAngle + 90 + components[selectedIndex].rotationAngle = 2//components[selectedIndex].initialAngle + 90 //console.log("rotationAngle",components[selectedIndex].rotationAngle) components[selectedIndex].rotateComponent.start() - components[selectedIndex].initialAngle = components[selectedIndex].rotationAngle == 360 ? 0 : - components[selectedIndex].rotationAngle + /*components[selectedIndex].initialAngle = components[selectedIndex].rotationAngle == 360 ? 0 : + components[selectedIndex].rotationAngle*/ } function displayInfo() { var componentName = components[selectedIndex].imgSrc deselect() items.infoTxt.visible = true //console.log(componentName,componentName=="battery.svg") - if(componentName == "battery.svg") { + /*if(componentName == "battery.svg") { items.infoTxt.text = qsTr("Battery is a power source of DC voltage. In analog electronics, the positive " + "terminal gives positive voltage, equal to the rating of battery and negative " + "terminal acts as ground (zero voltage). The battery can have different values " + "depending on its rating. In digital electronics, positive voltage is represented " + "by symbol ‘1’ and ground is represented by symbol ‘0’. Therefore in digital " + "electronics, there are only two states of voltage produced by battery – ‘1’ and ‘0’.") items.infoImage.source = "" + }*/ + + if(componentName == "one.svg" || componentName == "zero.svg") { + items.infoTxt.text = qsTr("Digital electronics is a branch of electronics that handle digital signals " + + "(i.e discrete signals instead of continous signals). Therefore all values within " + + "a range or band represent the same numeric value. In most cases, the number of " + + "these states is two and they are represented by two voltage bands: one near a " + + "reference value (typically termed as 'ground' or zero volts), and other value near " + + "the supply voltage. These correspond to the 'false' ('0') and 'true' ('1') values " + + "of the Boolean domain respectively (named after its inventor, George Boole). " + + "In this activity, you can give '0' and '1' as input to other logical devices, " + + "and see their output through an output device.") + items.infoImage.source = "" } else if(componentName == "gateAnd.svg") { items.infoTxt.text = 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:") items.infoImage.source = url + "AndTruthTable.svg" } else if(componentName == "gateNand.svg") { items.infoTxt.text = 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:") items.infoImage.source = url + "NandTruthTable.svg" } else if(componentName == "gateNor.svg") { items.infoTxt.text = 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:") items.infoImage.source = url + "NorTruthTable.svg" } else if(componentName == "gateNot.svg") { items.infoTxt.text = 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:") items.infoImage.source = url + "NotTruthTable.svg" } else if(componentName == "gateOr.svg") { items.infoTxt.text = 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:") items.infoImage.source = url + "OrTruthTable.svg" } else if(componentName == "gateXor.svg") { items.infoTxt.text = qsTr("XOR gate takes 2 or more binary input in its input terminals and outputs a single " + "value. The output is 1 if 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. Truth table for " + "2 input XOR gate is:") items.infoImage.source = url + "XorTruthTable.svg" } else if(componentName == "comparator.svg") { items.infoTxt.text = qsTr("Comparator takes 2 numbers as input, A and B. It compares them and outputs 3 " + "values. First value is true if A < B, else it is false. Second value is true " + "if A = B, else it is false. Third value is true if A > B, else it is false. " + "In digital electronics, true value is represented as 1, and false value is " + "represented as 0") } /*else if(componentName == "BCDTo7Segment.svg") { items.infoTxt.text = qsTr("BCD to 7 segment converter takes 4 binary inputs in its input terminals and gives " + "7 binary outputs. The 4 binary inputs represents a BCD number (binary-coded decimal). " + "The converter converts this BCD number to corresponding bits, which are used to " + "display the decimal number (represented by the BCD number) on the 7 segment display. " + "The truth table for BCD To 7 Segment converted is:") items.infoImage.source = url + "BCDTo7SegmentTruthTable.svg" }*/ else if(componentName == "BCDTo7Segment.svg") { items.infoTxt.text = qsTr("BCD to 7 segment converter takes 4 binary inputs which represent a BCD number, " + "and convert them to 7 binary bits which represent corresponding number in 7 segment " + "format. The truth table is:") items.infoImage.source = url + "BCDTo7SegmentTruthTable.svg" } else if(componentName == "sevenSegmentDisplay.svg") { items.infoTxt.text = qsTr("7 segment display takes 7 binary inputs in its input terminals. The display " + "consists of 7 segments and each segment gets lighted according to the input. " + "By generating different combination of binary inputs, the display can be used to " + "display various different symbols. The diagram is:") items.infoImage.source = url + "7SegmentDisplay.svg" } else if(componentName == "ledOn.svg" || componentName == "ledOff.svg") { - items.infoTxt.text = qsTr("LED (Light-emitting diode) is a two-lead semiconductor light source. It emits light " + - "when activated. LED has 2 input terminals, the longer terminal is the positive " + - "terminal (anode) and smaller terminal is the negative terminal (cathode). LED " + - "is activated when anode has a higher potential than cathode. In digital electronics " + - "LED can be used to check the output of the components. Connect the cathode of LED " + - "to ground (negative terminal of battery) and anode of LED to the output of the " + + items.infoTxt.text = qsTr("LED (Light-emitting diode) is a two-lead semiconductor light source. It emits " + + "light when activated. LED has 2 input terminals, the longer terminal is the " + + "positive terminal (anode) and smaller terminal is the negative terminal (cathode)" + + ". LED is activated when anode has a higher potential than cathode. In digital " + + "electronics LED can be used to check the output of the components. Connect " + + "the cathode of LED to ground ('0') and anode of LED to the output of the " + "component. If output is 1, the LED will be activated (emit light), and if " + "output is 0, the LED will be deactivated.") items.infoImage.source = "" } else if(componentName == "switchOn.svg" || componentName == "switchOff.svg") { items.infoTxt.text = qsTr("Switch is used to maintain easy connection between two terminals. If the switch is " + "turned on, then the two terminals are connected and current can flow through the " + "switch. If the switch is turned off, then the connection between terminal is broken, " + "and current can not flow through it.") items.infoImage.source = "" } //console.log(items.infoTxt.text) } function updateToolTip(toolTipTxt) { items.toolTip.show(toolTipTxt) } function nextLevel() { if(numberOfLevel <= ++currentLevel ) { currentLevel = 0 } initLevel(); } function previousLevel() { if(--currentLevel < 0) { currentLevel = numberOfLevel - 1 } initLevel(); } diff --git a/src/activities/digital_electricity/resource/gateAnd.svg b/src/activities/digital_electricity/resource/gateAnd.svg index c9450c1a7..64ab70541 100644 --- a/src/activities/digital_electricity/resource/gateAnd.svg +++ b/src/activities/digital_electricity/resource/gateAnd.svg @@ -1,100 +1,100 @@ image/svg+xml + transform="translate(-109.22969,-435.02045)"> + r="23.754402" /> + cx="132.98421" + cy="477.24649" + r="23.754499" /> + cx="132.98419" + cy="584.05078" + r="23.754499" /> diff --git a/src/activities/digital_electricity/resource/ledOff.svg b/src/activities/digital_electricity/resource/ledOff.svg index 6ca54322d..484737f4e 100644 --- a/src/activities/digital_electricity/resource/ledOff.svg +++ b/src/activities/digital_electricity/resource/ledOff.svg @@ -1,100 +1,131 @@ image/svg+xml \ No newline at end of file + style="opacity:1;fill:#090909;fill-opacity:0.80392157;stroke:none;stroke-width:1.24041164;stroke-miterlimit:3.54999995;stroke-dasharray:none;stroke-opacity:0.96688741" /> \ No newline at end of file diff --git a/src/activities/digital_electricity/resource/ledOn.svg b/src/activities/digital_electricity/resource/ledOn.svg index 0d60d994d..95c78ddb0 100644 --- a/src/activities/digital_electricity/resource/ledOn.svg +++ b/src/activities/digital_electricity/resource/ledOn.svg @@ -1,113 +1,140 @@ image/svg+xml \ No newline at end of file + id="stop18" /> \ No newline at end of file diff --git a/src/activities/digital_electricity/resource/one.svg b/src/activities/digital_electricity/resource/one.svg new file mode 100644 index 000000000..2ed14efb7 --- /dev/null +++ b/src/activities/digital_electricity/resource/one.svg @@ -0,0 +1,92 @@ + + + + + + + + + + image/svg+xml + + + + + + + + 1 + + + + diff --git a/src/activities/digital_electricity/resource/zero.svg b/src/activities/digital_electricity/resource/zero.svg new file mode 100644 index 000000000..f44210229 --- /dev/null +++ b/src/activities/digital_electricity/resource/zero.svg @@ -0,0 +1,92 @@ + + + + + + + + + + image/svg+xml + + + + + + + + 0 + + + +