<
From version < 18.1 >
edited by ssm
on 2016/04/21 19:30
To version < 21.1 >
edited by ssm
on 2016/04/22 14:56
>
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -152,8 +152,8 @@
152 152  
153 153  {{code language="java"}}
154 154  SCChartsFactory sccFactory = SCChartsFactory.eINSTANCE;
155 -State state = sccFactory .createState();
156 -Transition transition = sccFactory .createTransition();
155 +State state = sccFactory.createState();
156 +Transition transition = sccFactory.createTransition();
157 157  {{/code}}
158 158  
159 159  Important: The SCCharts grammar is build on top of several other grammars. Therefore, not all language objects can be found in the SCCharts factory. For example, all expression elements are part of the KExpressions grammar and hence, have their own factory. If you need other factories, don't forget to add the corresponding plugin to your plugin dependency list.
... ... @@ -166,7 +166,7 @@
166 166  For all simple attributes, there are getter and setter methods:
167 167  
168 168  {{code language="java"}}
169 -state.setId("Root");
169 +state.setId("Init");
170 170  boolValue.setValue(true);
171 171  {{/code}}
172 172  
... ... @@ -190,8 +190,14 @@
190 190  
191 191  EMF uses the [[Eclipse Resource concept>>url:http://help.eclipse.org/juno/topic/org.eclipse.platform.doc.isv/guide/resInt.htm?cp=2_0_10||rel="nofollow" shape="rect" class="external-link"]] to save models to files and load models from files. It can use different //Resource Factories// that determine how exactly models are serialized. We will use the [[XMIResourceFactoryImpl>>url:http://download.eclipse.org/modeling/emf/emf/javadoc/2.8.0/org/eclipse/emf/ecore/xmi/impl/XMIResourceFactoryImpl.html||rel="nofollow" shape="rect" class="external-link"]] to save our models to XML files:
192 192  
193 -1. Add a dependency to the {{code language="none"}}org.eclipse.emf.ecore.xmi{{/code}} plug-in.
194 194  1. (((
194 +Add a dependency to the {{code language="none"}}com.google.inject, org.eclipse.core.resources, {{/code}}and{{code language="none"}} de.cau.cs.kieler.sccharts.text{{/code}} plug-ins.
195 +
196 +{{info title="Additional Dependencies"}}
197 +Don't worry. You will be experienced enough to add mandatory dependencies quickly in the future. However, for now just add the dependencies to proceed with the tutorial.
198 +{{/info}}
199 +)))
200 +1. (((
195 195  Use something like the following code to save the model from above:
196 196  
197 197  {{code language="java"}}
... ... @@ -198,10 +198,10 @@
198 198  // Create a resource set.
199 199  ResourceSet resourceSet = new ResourceSetImpl();
200 200  
201 -// Register the default resource factory -- only needed for stand-alone!
202 -// this tells EMF to use XML to save the model
203 -resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
204 - Resource.Factory.Registry.DEFAULT_EXTENSION, new SCTResourceFactoryImpl());
207 +// Register the resource factory -- only needed for stand-alone!
208 +SctStandaloneSetup.doSetup();
209 +
210 + 
205 205  // Get the URI of the model file.
206 206  URI fileURI = URI.createFileURI(new File("myABO.sct").getAbsolutePath());
207 207  
... ... @@ -219,24 +219,189 @@
219 219   /* error handling */
220 220  }
221 221  {{/code}}
228 +
229 +{{info title="File Extensions"}}
230 +File extensions are important! They define the parser/serializer that EMF uses. Always use the file extension that is defined for a particular model.
231 +{{/info}}
222 222  )))
233 +{{/layout-cell}}
234 +{{/layout-section}}
223 223  
236 +{{layout-section ac:type="two_right_sidebar"}}
237 +{{layout-cell}}
224 224  ==== Model Creation Task ====
225 225  
226 -With these information out of the way, on we go to some model creation:
240 +You are now equipped with the fundamentals you need to create models programmatically. Let's try it:
227 227  
228 -1. Programmatically create a valid model of ABO in the {{code language="none"}}main(){{/code}} method.
229 -1. Run the {{code language="none"}}main(){{/code}} method by right-clicking its class and selecting //Run as// -> //Java Application//. Note that this runs your {{code language="none"}}main(){{/code}} method as a simple Java program, not a complete Eclipse application. EMF models can be used in any simple Java context, not just in Eclipse applications.
230 -1. Execute the main method.
231 -1. Inspect your SCT file.
242 +1. The code fragments listed above do not suffice to create a grammatically correct model. Try to generate a model that corresponds with the serialized model listed on the right side.
243 +11. Run the {{code language="none"}}main(){{/code}} method by right-clicking its class and selecting (% style="line-height: 1.42857;" %)//Run as//(%%) -> (% style="line-height: 1.42857;" %)//Java Application//(%%). Note that this runs your {{code language="none"}}main(){{/code}} method as a simple Java program, not a complete Eclipse application. EMF models can be used in any simple Java context, not just in Eclipse applications.
244 +11. Execute the main method.
245 +11. (((
246 +Inspect your SCT file. (Press F5 to refresh your file view.)
247 +
248 +{{note title="Kext Warning"}}
249 +It is possible that kext generates a Null Pointer Exception when you save your model this way. This is a known issue. We're working on it. Just ignore it for now.
250 +{{/note}}
251 +)))
252 +1. Now, create a new Java class and proceed as before to generate a model of ABO in the {{code language="none"}}main(){{/code}} method.
232 232  1. Start your SCChart Editor Eclipse instance and load your SCT file. KLighD should now be able to visualize your ABO correctly.
254 +11. For this, open tab //Run// and select// Run Configurations...//
255 +11. Create a new //Eclipse Application// and name it appropriately.
256 +11. As product select {{code language="none"}}de.cau.cs.kieler.core.product.product{{/code}}.
257 +11. Click //Run// (or //Debug// if you opened// Debug Configuration...//)
258 +11. Create a new project and add you generated model.
259 +
260 +
233 233  {{/layout-cell}}
262 +
263 +{{layout-cell}}
264 +{{code language="java" title="Root.sct"}}
265 +scchart Root {
266 + initial state Init
267 + --> Init with true;
268 +}
269 +{{/code}}
270 +
271 +[[image:attach:RunConfiguration.png]]
272 +{{/layout-cell}}
234 234  {{/layout-section}}
235 235  
236 -{{layout-section ac:type="single"}}
275 +{{layout-section ac:type="two_right_sidebar"}}
237 237  {{layout-cell}}
277 += Model-to-Model Transformation with KiCo =
278 +
279 +You can use the [[Kieler Compiler>>url:http://rtsys.informatik.uni-kiel.de/confluence/display/KIELER/Kieler+Compiler||shape="rect"]] (KiCo) to handle all the model input/output tasks and concentrate on the actual transformation. If you executed the **Model Creation Task correctly**, you should now have a complete running SCT Editor instance that looks like the one on the right. You should see the //KIELER Compiler Selection// n the lower right part of the working space. Here you can select specific transformations that will be applied to the actual model. Simply select a transformation to test it.
280 +
281 +== Creating a new Transformation ==
282 +
283 +Now, you're going to write your own transformation with **Xtend** *drumroll*, a programming language that looks very similar to Java, but which adds some very convenient features. Xtend code compiles to Java and and was developed using Xtext. In fact, once you gain experience working with Xtend you will probably appreciate the power of Xtext even more. Xtend is particularly useful to browse & modify EMF models. You get the point... we like it. :)
284 +
238 238  
286 +
287 +Transformation Creation Task
288 +
289 +1. Therefore, create a new project within your tutorial working set as before.
290 +1. Add plugin dependencies to {{code language="none"}}de.cau.cs.kieler.kico{{/code}} and {{code language="none"}}de.cau.cs.kieler.sccharts{{/code}}.
291 +1. Create a new //Xtend class// in you package and name it "DoubleStates" and use {{code language="none"}}AbstractProductionTransformation{{/code}} as superclass.
292 +1. Here, you can automatically add the missing Xtend files by using the quickfix //Add Xtend lib to class path. //Alternatively you can simply add {{code language="none"}}com.google.guava{{/code}}, {{code language="none"}}org.eclipse.xtext.xbase.lib{{/code}}, {{code language="none"}}org.eclipse.xtend.lib{{/code}}, and {{code language="none"}}org.eclipse.xtend.lib.macro{{/code}} to you plugin dependencies.
293 +1. Click on //Add unimplemented methods//.
294 +1. (((
295 +Now, you should have a class similar to the following one.
296 +
297 +{{code language="java"}}
298 +package tutorial.transformation
299 +
300 +import de.cau.cs.kieler.kico.transformation.AbstractProductionTransformation
301 +
302 +class DoubleStates extends AbstractProductionTransformation {
303 +
304 + override getProducedFeatureId() {
305 + throw new UnsupportedOperationException("TODO: auto-generated method stub")
306 + }
307 +
308 + override getId() {
309 + throw new UnsupportedOperationException("TODO: auto-generated method stub")
310 + }
311 +
312 +}
313 +{{/code}}
314 +)))
315 +1. (((
316 +As you can see, it is mandatory to add an id for the transformation and another id of the feature that this transformation produces. Name your transformation **tutorial.doubleStates **and the id of feature you want to produce is **sccharts.doubleStates**.
317 +
318 +{{info title="Programming Guidelines"}}
319 +You should really think about some constants here. You can also look at the sccharts transformation and features constants in the sccharts plugin.
320 +{{/info}}
321 +)))
322 +1. KiCo must know about the new feature and also about your new transformation. 
323 +11. Add a new Xtend class with Feature as superclass. Add all unimplemented methods. Also set sccharts.doubleStates as Id.
324 +11. Go to the Extension tab inside your plugin configuration. 
325 +111. Add a new Extension Point de.cau.cs.kieler.kico.feature. Create a new featureClass and point it to your new feature class.
326 +111. Also add a new Extension Point de.cau.cs.kieler.kico.transformation. Create a new productionTransformationClass and point it to your transformation class.
327 +111. Finally, you have to link your transformation to the SCT Editor. Add the Extension point de.cau.cs.kieler.kico.ui.transformation. Create an editor link and fill in the following values:
328 +1111. editor: de.cau.cs.kieler.sccharts.text.sct.Sct
329 +1111. features: sccharts.doubleStates
330 +1111. label: Tutorial Compilation
331 +1111. priority: 101
332 +1111. preferred: (leave it blank)
333 +11. If you start your KIELER instance now, you should get a new compilation chain which has only one transformation: yours, which doesn't do anything.
334 +1. If you want to rename your feature in the Compiler Selection (without changing its Id), override the getName method and return a new name. Rename your feature appropriately.
335 +1. Now, fill your transformation with life:
336 +11. Inside your transformation class, add a new method with the following signature: def State transform(State rootState, KielerCompilerContext context). This transformation will be executed if the feature is selected in the Compiler Selection.
337 +11. (((
338 +Add thew following body to the function and try to understand the Xtend code.
339 +
340 +{{code language="java" title="transform"}}
341 + def State transform(State rootState, KielerCompilerContext context) {
342 + val newState = SCChartsFactory.eINSTANCE.createState => [
343 + id = "ololo"
344 + label = "ololo"
345 + ]
346 +
347 + rootState.regions.filter(ControlflowRegion).head.states += newState
348 +
349 + rootState
350 + }
351 +{{/code}}
352 +)))
353 +11. When selecting your transformation, the SCChart gets transformed and looks like the version on the right.
354 +1. Extend the transformation so that each transition is split up in two and connected via a transient state meaning that the original transformation should point to the new state and a new immediate transformation then points to the original target state.
355 +1. Try your new transformation with ABO. The result should look like the example on the right.
356 +
357 +
239 239  {{/layout-cell}}
359 +
360 +{{layout-cell}}
361 +[[image:attach:KielerSCTEditor.png]]
362 +
363 +
364 +
365 +
366 +
367 +
368 +
369 +
370 +
371 +
372 +
373 +
374 +
375 +
376 +
377 +
378 +
379 +
380 +
381 +
382 +
383 +
384 +
385 +
386 +
387 +
388 +
389 +
390 +
391 +
392 +
393 +
394 +
395 +
396 +
397 +
398 +
399 +
400 +
401 +
402 +
403 +
404 +
405 +
406 +
407 +
408 +
409 +[[image:attach:KielerSCTEditorOwnTransformation.png]]
410 +{{/layout-cell}}
240 240  {{/layout-section}}
241 241  
242 242  {{layout-section ac:type="single"}}
Confluence.Code.ConfluencePageClass[0]
Id
... ... @@ -1,1 +1,1 @@
1 -16810318
1 +16810372
URL
... ... @@ -1,1 +1,1 @@
1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/TUT/pages/16810318/SCCharts Development
1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/TUT/pages/16810372/SCCharts Development