Warning, /education/gcompris/src/activities/analog_electricity/components/Battery.qml is written in an unsupported language. File is not indexed.

0001 /* GCompris - Battery.qml
0002  *
0003  * SPDX-FileCopyrightText: 2020 Aiswarya Kaitheri Kandoth <aiswaryakk29@gmail.com>
0004  *
0005  * Authors:
0006  *   Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version)
0007  *   Aiswarya Kaitheri Kandoth <aiswaryakk29@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 import "../analog_electricity.js" as Activity
0014 
0015 ElectricalComponent {
0016     id: battery
0017     terminalSize: 0.2
0018     noOfConnectionPoints: 2
0019     information: qsTr("Battery is used for powering up electrical devices. It can supply voltage in a closed circuit. Which means there should be a path for the current to flow from one terminal of the battery to the other.") + " " + qsTr("If the current in a circuit is too high then the battery can be damaged.")
0020     //: 1st V for Voltage, 2nd V for Volt
0021     labelText1: qsTr("V = %1V").arg(componentVoltage)
0022     //: I for current intensity, A for Ampere
0023     labelText2: qsTr("I = %1A").arg(current)
0024     source: Activity.url + "battery.svg"
0025 
0026     property double componentVoltage: 0
0027     property var nodeVoltages: [0, 0]
0028     property double current: 0
0029     property alias connectionPoints: connectionPoints
0030     property var connectionPointPosY: [0.1, 0.9]
0031     property var connectionPointType: ["positive", "negative"]
0032     property string componentName: "Voltage"
0033     property var externalNetlistIndex: [0, 0]
0034     property var netlistModel:
0035     [
0036         "v",
0037         [
0038         ],
0039         {
0040             "name": componentName,
0041             "value": "dc(10)",
0042             "_json_": 0
0043         },
0044         [
0045             0,
0046             0
0047         ]
0048     ]
0049 
0050     Repeater {
0051         id: connectionPoints
0052         model: 2
0053         delegate: connectionPoint
0054         Component {
0055             id: connectionPoint
0056             TerminalPoint {
0057                 posX: 0.5
0058                 posY: connectionPointPosY[index]
0059                 terminalType: connectionPointType[index]
0060             }
0061         }
0062     }
0063 
0064     function checkConnections() {
0065         terminalConnected = 0;
0066         for(var i = 0; i < noOfConnectionPoints; i++) {
0067             if(connectionPoints.itemAt(i).wires.length > 0)
0068                 terminalConnected += 1;
0069         }
0070 
0071         // show label only from level 6 or in free mode
0072         if(terminalConnected >= 2 && (!Activity.items.isTutorialMode || Activity.items.currentLevel >= 5)) {
0073             battery.showLabel = true;
0074         } else {
0075             battery.showLabel = false;
0076         }
0077     }
0078 
0079     function updateValues() {
0080         componentVoltage = (Math.abs(nodeVoltages[1] - nodeVoltages[0])).toFixed(2);
0081         current = (Math.abs(current)).toFixed(3);
0082         // short circuit case
0083         if(Math.abs(current) > 1) {
0084             battery.source = Activity.url + "battery_dead.svg";
0085         } else {
0086             battery.source = Activity.url + "battery.svg";
0087         }
0088     }
0089 
0090     function initConnections() {
0091         var connectionIndex = Activity.connectionCount;
0092         battery.externalNetlistIndex[0] = ++connectionIndex;
0093         connectionPoints.itemAt(0).updateNetlistIndex(connectionIndex);
0094         battery.externalNetlistIndex[1] = ++connectionIndex;
0095         connectionPoints.itemAt(1).updateNetlistIndex(connectionIndex);
0096         Activity.connectionCount = connectionIndex;
0097     }
0098 
0099     function addToNetlist() {
0100         var netlistItem = battery.netlistModel;
0101         Activity.netlistComponents.push(battery);
0102         Activity.vSourcesList.push(battery);
0103         netlistItem[2].name = componentName;
0104         netlistItem[2]._json = Activity.netlist.length;
0105         netlistItem[3][0] = battery.externalNetlistIndex[0];
0106         netlistItem[3][1] = battery.externalNetlistIndex[1];
0107         Activity.netlist.push(netlistItem);
0108     }
0109 
0110     function checkComponentAnswer() {
0111         if(terminalConnected >= 2)
0112             return "batteryIn";
0113         else
0114             return "";
0115     }
0116 }