/* GCompris - Switch.qml * * SPDX-FileCopyrightText: 2016 Pulkit Gupta * * Authors: * Bruno Coudoin (GTK+ version) * Pulkit Gupta (Qt Quick port) * * SPDX-License-Identifier: GPL-3.0-or-later */ import QtQuick import core 1.0 ElectricalComponent { id: switchComponent terminalSize: 0.5 noOfInputs: 1 noOfOutputs: 1 information: qsTr("A switch is used to connect or disconnect two terminals. " + "If the switch is turned on, the current can flow through the switch. " + "If the switch is turned off, then the connection inside the switch is broken and the current can not flow through it.") truthTable: [] property alias inputTerminals: inputTerminals property alias outputTerminals: outputTerminals Repeater { id: inputTerminals model: 1 delegate: inputTerminal Component { id: inputTerminal TerminalPoint { posX: 0.04 posY: 0.5 type: "In" } } } Repeater { id: outputTerminals model: 1 delegate: outputTerminal Component { id: outputTerminal TerminalPoint { posX: 0.96 posY: 0.5 type: "Out" } } } function updateOutput(wireVisited) { var terminal = outputTerminals.itemAt(0) terminal.value = imgSrc == "switchOn.svg" ? inputTerminals.itemAt(0).value : 0 for(var i = 0 ; i < terminal.wires.length ; ++i) terminal.wires[i].to.value = terminal.value var componentVisited = [] for(var i = 0 ; i < terminal.wires.length ; ++i) { var wire = terminal.wires[i] var component = wire.to.parent if(componentVisited[component] != true && wireVisited[wire] != true) { componentVisited[component] = true wireVisited[wire] = true component.updateOutput(wireVisited) } } } }