Warning, /education/gcompris/src/activities/digital_electricity/components/Switch.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - Switch.qml 0002 * 0003 * SPDX-FileCopyrightText: 2016 Pulkit Gupta <pulkitnsit@gmail.com> 0004 * 0005 * Authors: 0006 * Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version) 0007 * Pulkit Gupta <pulkitnsit@gmail.com> (Qt Quick port) 0008 * 0009 * SPDX-License-Identifier: GPL-3.0-or-later 0010 */ 0011 import QtQuick 2.12 0012 import "../digital_electricity.js" as Activity 0013 0014 import GCompris 1.0 0015 0016 ElectricalComponent { 0017 id: switchComponent 0018 terminalSize: 0.5 0019 noOfInputs: 1 0020 noOfOutputs: 1 0021 0022 information: qsTr("A switch is used to connect or disconnect two terminals. " + 0023 "If the switch is turned on, the current can flow through the switch. " + 0024 "If the switch is turned off, then the connection inside the switch is broken and the current can not flow through it.") 0025 0026 truthTable: [] 0027 0028 property alias inputTerminals: inputTerminals 0029 property alias outputTerminals: outputTerminals 0030 0031 Repeater { 0032 id: inputTerminals 0033 model: 1 0034 delegate: inputTerminal 0035 Component { 0036 id: inputTerminal 0037 TerminalPoint { 0038 posX: 0.04 0039 posY: 0.5 0040 type: "In" 0041 } 0042 } 0043 } 0044 0045 Repeater { 0046 id: outputTerminals 0047 model: 1 0048 delegate: outputTerminal 0049 Component { 0050 id: outputTerminal 0051 TerminalPoint { 0052 posX: 0.96 0053 posY: 0.5 0054 type: "Out" 0055 } 0056 } 0057 } 0058 0059 function updateOutput(wireVisited) { 0060 var terminal = outputTerminals.itemAt(0) 0061 terminal.value = imgSrc == "switchOn.svg" ? inputTerminals.itemAt(0).value : 0 0062 for(var i = 0 ; i < terminal.wires.length ; ++i) 0063 terminal.wires[i].to.value = terminal.value 0064 0065 var componentVisited = [] 0066 for(var i = 0 ; i < terminal.wires.length ; ++i) { 0067 var wire = terminal.wires[i] 0068 var component = wire.to.parent 0069 if(componentVisited[component] != true && wireVisited[wire] != true) { 0070 componentVisited[component] = true 0071 wireVisited[wire] = true 0072 component.updateOutput(wireVisited) 0073 } 0074 } 0075 } 0076 }