protected fun pushValuesOfAssociatedVariablesWithOutputEvent()

in code/debugger/src/main/kotlin/org/fbme/debugger/simulator/FBSimulator.kt [112:145]


    protected fun pushValuesOfAssociatedVariablesWithOutputEvent(eventName: String) {
        if (parent != null) {
            val associatedVariables = declaration.getAssociatedVariablesWithOutputEvent(eventName)
            for (associatedVariable in associatedVariables) {
                val associatedVariableValue = state.outputVariables[associatedVariable]!!

                val outgoingDataConnections = when (parent) {
                    is CompositeFBSimulator -> parent.declaration
                        .getOutgoingDataConnectionsFromPort(instanceName, associatedVariable)

                    is ResourceSimulator -> parent.declaration
                        .getOutgoingDataConnectionsFromPort(instanceName, associatedVariable)

                    else -> error("can't initialize outgoing connections")
                }

                for (outgoingDataConnection in outgoingDataConnections) {
                    val (targetFB, targetPort) = outgoingDataConnection.resolveTargetPortPresentation()

                    if (targetFB == null) {
                        check(parent is CompositeFBSimulator)
                        parent.state.outputVariables[targetPort] = associatedVariableValue.copy()
                    } else {
                        val targetFBSimulator = when (parent) {
                            is CompositeFBSimulator -> parent.children[targetFB]!!
                            is ResourceSimulator -> parent.children[targetFB]!!
                            else -> error("unexpected parent type")
                        }
                        targetFBSimulator.candidates[targetPort] = associatedVariableValue
                    }
                }
            }
        }
    }