Warning, /education/gcompris/src/activities/analog_electricity/components/Resistor.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - Resistor.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: resistor // Ammeters to measure current and voltage 0017 terminalSize: 0.2 0018 noOfConnectionPoints: 2 0019 information: qsTr("Resistors are used to reduce the current flow in an electrical circuit.") 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(resistorCurrent) 0024 source: Activity.url + "resistor.svg" 0025 0026 property var nodeVoltages: [0, 0] 0027 property double componentVoltage: 0 0028 property double resistorCurrent: 0 0029 property alias connectionPoints: connectionPoints 0030 property var connectionPointPosX: [0.1, 0.9] 0031 property var connectionPointPosY: [0.5, 0.5] 0032 property string componentName: "Resistor" 0033 property var internalNetlistIndex: [0, 0] 0034 property var externalNetlistIndex: [0, 0] 0035 property var netlistModel: 0036 [ 0037 "r", 0038 [ 0039 ], 0040 { 0041 "name": componentName, 0042 "r": "1000", 0043 "_json_": 0 0044 }, 0045 [ 0046 0, 0047 0 0048 ] 0049 ] 0050 0051 Item { 0052 id: aMeter1 0053 property int jsonNumber: 0 0054 property double current: 0 0055 property var netlistModel: 0056 [ 0057 "a", 0058 [ 0059 ], 0060 { 0061 "name": "aMeter1-", 0062 "color": "magenta", 0063 "offset": "0", 0064 "_json_": aMeter1.jsonNumber 0065 }, 0066 [ 0067 0, 0068 0 0069 ] 0070 ] 0071 } 0072 0073 Item { 0074 id: aMeter2 0075 property int jsonNumber: 0 0076 property double current: 0 0077 property var netlistModel: 0078 [ 0079 "a", 0080 [ 0081 ], 0082 { 0083 "name": "aMeter2-", 0084 "color": "magenta", 0085 "offset": "0", 0086 "_json_": aMeter2.jsonNumber 0087 }, 0088 [ 0089 0, 0090 0 0091 ] 0092 ] 0093 } 0094 0095 Repeater { 0096 id: connectionPoints 0097 model: 2 0098 delegate: connectionPoint 0099 Component { 0100 id: connectionPoint 0101 TerminalPoint { 0102 posX: connectionPointPosX[index] 0103 posY: connectionPointPosY[index] 0104 } 0105 } 0106 } 0107 0108 function checkConnections() { 0109 terminalConnected = 0; 0110 for(var i = 0; i < noOfConnectionPoints; i++) { 0111 if(connectionPoints.itemAt(i).wires.length > 0) 0112 terminalConnected += 1; 0113 } 0114 if(terminalConnected >= 2) { 0115 resistor.showLabel = true; 0116 } else { 0117 resistor.showLabel = false; 0118 } 0119 } 0120 0121 function updateValues() { 0122 resistorCurrent = (Math.abs(aMeter1.current)).toFixed(3); 0123 componentVoltage = (Math.abs(nodeVoltages[1] - nodeVoltages[0])).toFixed(2); 0124 } 0125 0126 function initConnections() { 0127 var connectionIndex = Activity.connectionCount; 0128 resistor.externalNetlistIndex[0] = ++connectionIndex; 0129 connectionPoints.itemAt(0).updateNetlistIndex(connectionIndex); 0130 resistor.internalNetlistIndex[0] = ++connectionIndex; 0131 resistor.internalNetlistIndex[1] = ++connectionIndex; 0132 resistor.externalNetlistIndex[1] = ++connectionIndex; 0133 connectionPoints.itemAt(1).updateNetlistIndex(connectionIndex); 0134 Activity.connectionCount = connectionIndex; 0135 } 0136 0137 function addToNetlist() { 0138 var netlistItem = aMeter1.netlistModel; 0139 Activity.netlistComponents.push(aMeter1); 0140 Activity.vSourcesList.push(aMeter1); 0141 netlistItem[2].name = "aMeter1-" + componentName; 0142 netlistItem[2]._json = Activity.netlist.length; 0143 netlistItem[3][0] = resistor.externalNetlistIndex[0]; 0144 netlistItem[3][1] = resistor.internalNetlistIndex[0]; 0145 Activity.netlist.push(netlistItem); 0146 0147 netlistItem = resistor.netlistModel; 0148 Activity.netlistComponents.push(resistor); 0149 netlistItem[2].name = componentName; 0150 netlistItem[2]._json = Activity.netlist.length; 0151 netlistItem[3][0] = resistor.internalNetlistIndex[0]; 0152 netlistItem[3][1] = resistor.internalNetlistIndex[1]; 0153 Activity.netlist.push(netlistItem); 0154 0155 netlistItem = aMeter2.netlistModel; 0156 Activity.netlistComponents.push(aMeter2); 0157 Activity.vSourcesList.push(aMeter2); 0158 netlistItem[2].name = "aMeter2-" + componentName; 0159 netlistItem[2]._json = Activity.netlist.length; 0160 netlistItem[3][0] = resistor.internalNetlistIndex[1]; 0161 netlistItem[3][1] = resistor.externalNetlistIndex[1]; 0162 Activity.netlist.push(netlistItem); 0163 } 0164 0165 function checkComponentAnswer() { 0166 if(resistorCurrent > 0 && terminalConnected >= 2) 0167 return "resistorIn"; 0168 else 0169 return ""; 0170 } 0171 } 0172