blob: 9dc293952262f2706406c0b9b545332a212903b6 [file] [log] [blame]
/**
********************************************************************************
* Copyright (c) 2018-2019 Robert Bosch GmbH.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Robert Bosch GmbH - initial API and implementation
********************************************************************************
*/
package templates.m2m.sw;
import com.google.inject.Inject
import com.google.inject.Singleton
import com.inchron.realtime.root.model.Mode
import org.eclipse.app4mc.amalthea.model.ModeLiteral
import org.eclipse.app4mc.amalthea.model.ModeValue
import org.eclipse.app4mc.amalthea.model.ModeValueConjunction
import org.eclipse.app4mc.amalthea.model.ModeValueDisjunction
import templates.AbstractAmaltheaInchronTransformer
import templates.utils.AmltCacheModel
@Singleton
public class ModeValueDisjunctionTransformer extends AbstractAmaltheaInchronTransformer {
@Inject ModeLabelTransformer modeLabelTransformer
var AmltCacheModel cacheModel
public def create inchronModelFactory.createModeCondition createModeCondition(ModeValueDisjunction amltModeValueDisjunction){
cacheModel = customObjsStore.getInstance(AmltCacheModel)
it.name="ModeCondition_"+"_"+it.hashCode
amltModeValueDisjunction?.entries?.forEach[amltModeValueDisjunctionEntry|{
val inchronModeConjunction=inchronModelFactory.createModeConjunction
//Adding ModeConjunction
it.conjunctions.add(inchronModeConjunction)
if(amltModeValueDisjunctionEntry instanceof ModeValue){
val amltModeLiteral=amltModeValueDisjunctionEntry.value
var amltModeLabel=amltModeValueDisjunctionEntry.valueProvider
//Adding Mode
inchronModeConjunction.modes.add(modeLabelTransformer.getInchronMode(amltModeLabel, amltModeLiteral))
} else if(amltModeValueDisjunctionEntry instanceof ModeValueConjunction){
amltModeValueDisjunctionEntry?.entries?.forEach[amltModeValueEntry|{
var amltModeLiteral=amltModeValueEntry.value
var amltModeLabel=amltModeValueEntry.valueProvider
//Adding Mode
inchronModeConjunction.modes.add(modeLabelTransformer.getInchronMode(amltModeLabel, amltModeLiteral))
}]
}
}]
inchronRoot.globalModeConditions.add(it)
}
public def Mode getInchronMode(ModeLiteral amltModeLiteral ){
val amltModeName=amltModeLiteral?.containingMode?.name
val inchronModeGroup=cacheModel.getInchronModeGroup(amltModeName)
if(inchronModeGroup !==null){
val inchronMode= inchronModeGroup.modes.findFirst[inchronMode|{
(amltModeLiteral.name.equals(inchronMode.name))
}]
return inchronMode
}
return null
}
}