Warning, /education/gcompris/src/activities/analog_electricity/components/Switch2.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - Switch2.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: switch2 // two resistors 0017 terminalSize: 0.2 0018 noOfConnectionPoints: 3 0019 information: qsTr("A three points switch can toggle a circuit between two connection points.") 0020 source: Activity.url + "switch2_off.svg" 0021 0022 property double componentVoltage: 0 0023 property double current: 0 0024 property string resistanceValueOn: "0" 0025 property string resistanceValueOff: "100000000" 0026 property string resistanceTop: resistanceValueOn 0027 property string resistanceBottom: resistanceValueOff 0028 property alias connectionPoints: connectionPoints 0029 property var connectionPointPosX: [0.1, 0.9, 0.9] 0030 property var connectionPointPosY: [0.5, 0.165, 0.835] 0031 property string componentName: "Switch2" 0032 property var externalNetlistIndex: [0, 0, 0] 0033 property var netlistModel: 0034 [ 0035 "r", 0036 [ 0037 ], 0038 { 0039 "name": "-top", 0040 "r": resistanceValueOff, 0041 "_json_": 0 0042 }, 0043 [ 0044 0, 0045 0 0046 ] 0047 ] 0048 0049 Item { 0050 id: switch2Bottom 0051 property int jsonNumber: 0 0052 property double current: 0 0053 property var netlistModel: 0054 [ 0055 "r", 0056 [ 0057 ], 0058 { 0059 "name": "-bottom", 0060 "r": switch2.resistanceValueOn, 0061 "_json_": 0 0062 }, 0063 [ 0064 0, 0065 0 0066 ] 0067 ] 0068 } 0069 0070 Repeater { 0071 id: connectionPoints 0072 model: 3 0073 delegate: connectionPoint 0074 Component { 0075 id: connectionPoint 0076 TerminalPoint { 0077 posX: connectionPointPosX[index] 0078 posY: connectionPointPosY[index] 0079 } 0080 } 0081 } 0082 0083 MouseArea { 0084 height: parent.height * 0.33 0085 width: parent.width * 0.25 0086 anchors.horizontalCenter: parent.horizontalCenter 0087 anchors.horizontalCenterOffset: width * -0.5 0088 anchors.top: parent.top 0089 onClicked: { 0090 if(switch2.source == Activity.url + "switch2_off.svg") { 0091 switch2.source = Activity.url + "switch2_on.svg"; 0092 switch2.netlistModel[2].r = resistanceValueOn; 0093 switch2Bottom.netlistModel[2].r = resistanceValueOff; 0094 } else { 0095 switch2.source = Activity.url + "switch2_off.svg"; 0096 switch2.netlistModel[2].r = resistanceValueOff; 0097 switch2Bottom.netlistModel[2].r = resistanceValueOn; 0098 } 0099 Activity.restartTimer(); 0100 } 0101 } 0102 0103 function checkConnections() { 0104 return; 0105 } 0106 0107 function updateValues() { 0108 return; 0109 } 0110 0111 function initConnections() { 0112 var connectionIndex = Activity.connectionCount; 0113 switch2.externalNetlistIndex[0] = ++connectionIndex; 0114 connectionPoints.itemAt(0).updateNetlistIndex(connectionIndex); 0115 switch2.externalNetlistIndex[1] = ++connectionIndex; 0116 connectionPoints.itemAt(1).updateNetlistIndex(connectionIndex); 0117 switch2.externalNetlistIndex[2] = ++connectionIndex; 0118 connectionPoints.itemAt(2).updateNetlistIndex(connectionIndex); 0119 Activity.connectionCount = connectionIndex; 0120 } 0121 0122 function addToNetlist() { 0123 var netlistItem = switch2.netlistModel; 0124 Activity.netlistComponents.push(switch2); 0125 if(netlistItem[2].r === "0") { 0126 Activity.vSourcesList.push(switch2); 0127 } 0128 netlistItem[2].name = componentName + "-top"; 0129 netlistItem[2]._json = Activity.netlist.length; 0130 netlistItem[3][0] = switch2.externalNetlistIndex[0]; 0131 netlistItem[3][1] = switch2.externalNetlistIndex[1]; 0132 Activity.netlist.push(netlistItem); 0133 0134 netlistItem = switch2Bottom.netlistModel; 0135 Activity.netlistComponents.push(switch2Bottom); 0136 if(netlistItem[2].r === "0") { 0137 Activity.vSourcesList.push(switch2Bottom); 0138 } 0139 netlistItem[2].name = componentName + "-bottom"; 0140 netlistItem[2]._json = Activity.netlist.length; 0141 netlistItem[3][0] = switch2.externalNetlistIndex[0]; 0142 netlistItem[3][1] = switch2.externalNetlistIndex[2]; 0143 Activity.netlist.push(netlistItem); 0144 0145 } 0146 }