<
From version < 11.1 >
edited by Alexander Schulz-Rosengarten
on 2014/01/10 11:28
To version < 12.1 >
edited by Alexander Schulz-Rosengarten
on 2014/01/23 11:23
>
Change comment: updated example

Summary

Details

Page properties
Content
... ... @@ -70,29 +70,36 @@
70 70  
71 71  == Example ==
72 72  
73 +In this example we will perform some transformations on SCCharts.
74 +
75 +The source chart is a ABO, the "Hello World" of SCCharts.
76 +
77 +ABO is already a CoreSCChart, so we will perform normalization and a transformation to SCG.
78 +
73 73  === Creating Mapping during Transformation ===
74 74  
75 -The following code is a modifcation of the tranformation "Spilt Trigger and Effects" of SCCharts.
81 +In order to note every single element transformation of a model transformation, we use the TransformationMapping extension.
76 76  
77 -{{code title="Modified SCChart Transformation" theme="Eclipse" linenumbers="true" language="java" firstline="1" collapse="true"}}
78 -package de.cau.cs.kieler.ktm.test.transformations
79 -import com.google.inject.Inject
80 -import de.cau.cs.kieler.ktm.extensions.TransformationMapping
81 -import de.cau.cs.kieler.sccharts.Region
82 -import de.cau.cs.kieler.sccharts.Transition
83 -import de.cau.cs.kieler.sccharts.extensions.SCChartsExtension
84 -/**
85 - * @author als
86 - */
87 -class SCChartTestTransformation {
88 - @Inject
83 +After each creation of new Objects for transformed model the mapping must be updated with it's origin information.
84 +
85 +The codeblock blow show a snipped of SCChartCoreTransformation with additional mapping registration.
86 +
87 +
88 +
89 +{{code title="transformTriggerEffect CodeSnipped" theme="Eclipse" linenumbers="true" language="java" firstline="1" collapse="true"}}
90 +...
91 +  @Inject
89 89   extension TransformationMapping
90 - @Inject
91 - extension SCChartsExtension
93 +
94 +...
95 +
92 92   // NEW - Mapping access delegation
93 93   def extractMapping() {
94 94   extractMappingData;
95 95   }
100 +
101 +...
102 +
96 96   //-------------------------------------------------------------------------
97 97   //-- S P L I T T R A N S I T I O N --
98 98   //-------------------------------------------------------------------------
... ... @@ -110,70 +110,110 @@
110 110   for (targetTransition : targetRootRegion.getAllContainedTransitions) {
111 111   targetTransition.transformTriggerEffect(targetRootRegion);
112 112   }
113 - //check if mapping is complete (only for test proposes)
114 - val diff = rootRegion.checkMappingCompleteness(targetRootRegion);
115 - if (diff.key.empty && diff.value.empty) {
116 - targetRootRegion;
117 - } else {
118 - null
119 - }
120 + val completeness = checkMappingCompleteness(rootRegion, targetRootRegion); //NEW - DEBUG
121 + targetRootRegion;
120 120   }
121 121   def void transformTriggerEffect(Transition transition, Region targetRootRegion) {
122 - // Only apply this to transition that have both, a trigger and one or more effects
123 - if (((transition.trigger != null || !transition.immediate) && !transition.effects.nullOrEmpty) ||
124 + // Only apply this to transition that have both, a trigger (or is a termination) and one or more effects
125 + if (((transition.trigger != null || !transition.immediate || transition.typeTermination) && !transition.effects.nullOrEmpty) ||
124 124   transition.effects.size > 1) {
125 125   val targetState = transition.targetState
126 126   val parentRegion = targetState.parentRegion
127 127   val transitionOriginalTarget = transition.targetState
128 128   var Transition lastTransition = transition
131 + val firstEffect = transition.effects.head
129 129   for (effect : transition.effects.immutableCopy) {
130 - val effectState = parentRegion.createState(targetState.id + effect.id)
131 - effectState.mapParents(transition.mappedParents); //NEW - mapping information
132 - effectState.setTypeConnector
133 - val effectTransition = createImmediateTransition.addEffect(effect)
134 - effectTransition.mapParents(transition.mappedParents); //NEW - mapping information
135 - effectTransition.setSourceState(effectState)
136 - lastTransition.setTargetState(effectState)
137 - lastTransition = effectTransition
133 + // Optimization: Prevent transitions without a trigger
134 + if(transition.immediate && transition.trigger == null && firstEffect == effect) {
135 + // skip
136 + } else {
137 + val effectState = parentRegion.createState(GENERATED_PREFIX + "S")
138 + effectState.mapParents(transition.mappedParents); //NEW - mapping information
139 + effectState.uniqueName
140 + val effectTransition = createImmediateTransition.addEffect(effect)
141 + effectTransition.mapParents(transition.mappedParents); //NEW - mapping information
142 +
143 + effectTransition.setSourceState(effectState)
144 + lastTransition.setTargetState(effectState)
145 + lastTransition = effectTransition
146 + }
138 138   }
139 139   lastTransition.setTargetState(transitionOriginalTarget)
140 140   }
141 141   }
142 -}
143 143  {{/code}}
144 144  
145 -=== Create TransformationTree with Mapping ===
153 +=== Create TransformationTree ===
146 146  
147 -To test the transformation and mapping we will transform th following ABO-SCChart.
155 +The following code will now perform each transformation stepwise and updates a transformation tree each step.
148 148  
149 -[[image:attach:example_abo.jpeg]]
157 +
150 150  
151 -The following code snipped performs the transformation on our ABO-example, extracts the mapping and creates a transformation tree.
152 -
153 153  {{code title="Transform and create TranformationTree" theme="Eclipse" linenumbers="true" language="java" firstline="1" collapse="true"}}
154 -aboSplitTE = transformation.transformTriggerEffect(abo);
160 +aboSplitTE = SCCtransformation.transformTriggerEffect(abo);
155 155  
156 -Model aboSplitTEModel = transformationTreeExtensions.initializeTransformationTree(
157 - transformation.extractMapping(),
158 - "splitTriggerEffect",
159 - abo, "coreSCChart",
160 - aboSplitTE, "coreSCChart-splitTriggerEffect");
162 +ModelWrapper aboSplitTEModel =
163 + transformationTree.initializeTransformationTree(SCCtransformation.extractMapping(), "TriggerEffect", abo, "coreSCChart", aboSplitTE, "coreSCChart-splitTriggerEffect");
161 161  
162 -tranformationTree = transformationTreeExtensions.root(aboSplitTEModel);
165 +aboNormalized = SCCtransformation.transformSurfaceDepth(aboSplitTE);
166 +
167 +ModelWrapper aboNormalizedModel =
168 + transformationTree.addTransformationToTree(SCCtransformation.extractMapping(), aboSplitTEModel, "SurfaceDepth", aboSplitTE, aboNormalized, "normalizedCoreSCChart");
169 +
170 +aboSCG = SCGtransformation.transformSCG(aboNormalized);
171 +
172 +ModelWrapper aboSCGModel =
173 + transformationTree.addTransformationToTree(SCGtransformation.extractMapping(), aboNormalizedModel, "SCC2SCG", aboNormalized, aboSCG,"SCG");
174 +
175 +tree = transformationTree.root(aboSCGModel);
163 163  {{/code}}
164 164  
165 -The result of transformation is the following SCChart. ABO-splitTriggerEffect.
178 +
166 166  
167 -[[image:attach:example_abo_splitTE.jpeg]]
180 +The resulting TransformationTree has following structure and representing each step and model of the transformation.
168 168  
169 -Resulting TransformationTree has following structure.
182 +
170 170  
184 +|=(% colspan="4" style="text-align: center;" %)(% colspan="4" style="text-align: center;" %)
185 +(((
171 171  [[image:attach:example_tree.jpeg]]
187 +)))
188 +|(% colspan="1" style="text-align: center;" %)(% colspan="1" style="text-align: center;" %)
189 +(((
190 +[[image:attach:example_abo.jpeg]]
191 +)))|(% colspan="1" style="text-align: center;" %)(% colspan="1" style="text-align: center;" %)
192 +(((
193 +[[image:attach:example_abo_splitTE.jpeg]]
194 +)))|(% colspan="1" style="text-align: center;" %)(% colspan="1" style="text-align: center;" %)
195 +(((
196 +[[image:attach:example_abo_norm.jpeg]]
197 +)))|(% colspan="1" style="text-align: center;" %)(% colspan="1" style="text-align: center;" %)
198 +(((
199 +[[image:attach:example_abo_scg.jpeg]]
200 +)))
172 172  
173 -Furthermore the TransformationTree now contains the following mapping information.
202 +
174 174  
175 -[[image:attach:example_tree_transformation.jpeg]]
204 +Furthermore the TransformationTree now contains mapping information for the whole transformation chain.
176 176  
177 -Here you can see the effect of the transformation causing the transformation to split up.
206 +Now we can use an additional feature of KTM, the resolving of mappings between arbitary models.
178 178  
179 -[[image:attach:als-ktm-splitTriggerEffect-detail.jpg]]
208 +The following code has starts with an instance of the initial ABO SCChart and SCG, along with the TranformationTree above.
209 +
210 +
211 +
212 +{{code title="resolveMapping" theme="Eclipse" linenumbers="true" language="java" firstline="1" collapse="true"}}
213 +@Inject
214 +extension TransformationTreeExtensions
215 +
216 +//Find nodes of model instances in tree
217 +val aboSCCModelWrapper = transformationTree.findModel(aboSCC,"coreSCChart");
218 +val aboSCGModelWrapper = transformationTree.findModel(aboSCG,"SCG");
219 +
220 +//resolve
221 +val mapping = resolvemapping(aboSCCModelWrapper, aboSCC, aboSCGModelWrapper, aboSCG);
222 +{{/code}}
223 +
224 +
225 +
226 +The returned mapping is a multi mapping between all object in aboSCC and their resulting objects in aboSCG.
Confluence.Code.ConfluencePageClass[0]
Id
... ... @@ -1,1 +1,1 @@
1 -8651594
1 +8651596
URL
... ... @@ -1,1 +1,1 @@
1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/KIELER/pages/8651594/Transformation Mapping (KTM)
1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/KIELER/pages/8651596/Transformation Mapping (KTM)