blob: 6ca919b155f1248cfdfa42dc5c647eaf3b61d08b [file] [log] [blame]
Sebastian Reiserd2cae8b2019-04-03 13:39:33 +02001/**
2 ********************************************************************************
3 * Copyright (c) 2018-2019 Robert Bosch GmbH.
4 *
5 * This program and the accompanying materials are made
6 * available under the terms of the Eclipse Public License 2.0
7 * which is available at https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 * Robert Bosch GmbH - initial API and implementation
13 ********************************************************************************
14 */
15
Zakir Meerbbbbdfe2019-02-21 14:22:47 +010016package templates.m2m.sw;
17
Zakir Meer502122d2019-02-26 13:35:57 +010018import com.inchron.realtime.root.model.Mode
Zakir Meerbbbbdfe2019-02-21 14:22:47 +010019import org.eclipse.app4mc.amalthea.model.ModeLiteral
20import org.eclipse.app4mc.amalthea.model.ModeValue
21import org.eclipse.app4mc.amalthea.model.ModeValueConjunction
22import org.eclipse.app4mc.amalthea.model.ModeValueDisjunction
23import org.eclipse.app4mc.amalthea.model.Process
24import templates.AbstractAmaltheaInchronTransformer
25import templates.utils.AmltCacheModel
Zakir Meere7f870b2019-02-27 14:15:02 +010026import com.google.inject.Inject
Sebastian Reiserd2cae8b2019-04-03 13:39:33 +020027import com.google.inject.Singleton
Zakir Meerbbbbdfe2019-02-21 14:22:47 +010028
Sebastian Reiserd2cae8b2019-04-03 13:39:33 +020029@Singleton
Zakir Meerbbbbdfe2019-02-21 14:22:47 +010030public class ModeValueDisjunctionTransformer extends AbstractAmaltheaInchronTransformer {
31
32var AmltCacheModel cacheModel
33
Zakir Meere7f870b2019-02-27 14:15:02 +010034@Inject ModeLabelTransformer modeLabelTransformer
35
Sebastian Reiserd2cae8b2019-04-03 13:39:33 +020036 public def create inchronModelFactory.createModeCondition createModeCondition(ModeValueDisjunction amltModeValueDisjunction,Process amltTask ){
37 cacheModel = customObjsStore.getInstance(AmltCacheModel)
38
39 it.name="ModeCondition_"+amltTask.name+"_"+it.hashCode
Zakir Meerbbbbdfe2019-02-21 14:22:47 +010040
Sebastian Reiserd2cae8b2019-04-03 13:39:33 +020041 amltModeValueDisjunction?.entries?.forEach[amltModeValueDisjunctionEntry|{
Sebastian Reiserdde603f2019-04-04 10:07:52 +020042
Sebastian Reiserd2cae8b2019-04-03 13:39:33 +020043 val inchronModeConjunction=inchronModelFactory.createModeConjunction
44 //Adding ModeConjunction
45 it.conjunctions.add(inchronModeConjunction)
46
47 if(amltModeValueDisjunctionEntry instanceof ModeValue){
48 val amltModeLiteral=amltModeValueDisjunctionEntry.value
49 var amltModeLabel=amltModeValueDisjunctionEntry.valueProvider
50 //Adding Mode
51 inchronModeConjunction.modes.add(modeLabelTransformer.getInchronMode(amltModeLabel, amltModeLiteral))
52 } else if(amltModeValueDisjunctionEntry instanceof ModeValueConjunction){
53 amltModeValueDisjunctionEntry?.entries?.forEach[amltModeValueEntry|{
54 var amltModeLiteral=amltModeValueEntry.value
55 var amltModeLabel=amltModeValueEntry.valueProvider
Sebastian Reiserdde603f2019-04-04 10:07:52 +020056 //Adding Mode
57 inchronModeConjunction.modes.add(modeLabelTransformer.getInchronMode(amltModeLabel, amltModeLiteral))
Sebastian Reiserd2cae8b2019-04-03 13:39:33 +020058 }]
59 }
60 }]
61 }
Zakir Meerbbbbdfe2019-02-21 14:22:47 +010062
63
64
Sebastian Reiserd2cae8b2019-04-03 13:39:33 +020065 public def Mode getInchronMode(ModeLiteral amltModeLiteral ){
Zakir Meer502122d2019-02-26 13:35:57 +010066
Sebastian Reiserd2cae8b2019-04-03 13:39:33 +020067 val amltModeName=amltModeLiteral?.containingMode?.name
68
69 val inchronModeGroup=cacheModel.getInchronModeGroup(amltModeName)
70
71 if(inchronModeGroup !==null){
72 val inchronMode= inchronModeGroup.modes.findFirst[inchronMode|{
73 (amltModeLiteral.name.equals(inchronMode.name))
74 }]
75 return inchronMode
76 }
77
78 return null
79
80
81 }
Zakir Meerbbbbdfe2019-02-21 14:22:47 +010082}