h1. Getting started

Here you learn how to install the YAKINDU SCT2 and to make the first steps.

h2. Installation

h3. Prerequisites

The *Yakindu Statechart Tools 2* are built upon Java and Xtext. So you need to have installed a "Java Runtime Environment":http://www.oracle.com/technetwork/java/index.html and Xtext installed. The easier way to get this is to install the "pre configured Xtext contribution":http://xtext.itemis.com.

The *Yakindu Statechart Tools 2* need *Eclipse Indigo 3.7* or higher and *Xtext 2.0.1* exactly (no higher) to work correctly.

h3. Installing the YAKINDU-Plug-Ins

You install the Yakindu Plug-Ins from the update site: http://updates.yakindu.com/indigo/milestones. 

* Click *Help* > *Install new software...* and *Add..* the update site _Yakindu SCT2 milestones_ - http://updates.yakindu.com/indigo/milestones/
* Check all to install the YAKINDU SCT2
* Click *Next* to start the installation and click *Next* at the next step
* Accept the licence agreement and click *Finish*
* The software will be installed

When the installation finished the wizard will ask to reopen Eclipse. The restart is important to make the newly installed software work correctly.

!images/updatesite_4.jpg!



h2. First steps: my first state machine

In the following you will create your first state machine with the YAKINDU Statechart tools and simulate it. 

h3. Creating a New Project

For modeling purposes the YAKINDU statechart tools offer a workbench perspective. Such a perspective is a bunch of editors and views that are organized in a pre defined order on the screen. Open the Yakindu *SC Modeling* perspective by clicking *Window* > *Open Perspective* > *SC Modeling*. This perspective is optimized for statechart modeling. It consists of 
* "Project Explorer":PLUGIN_ROOT/org.eclipse.platform.doc.user/concepts/cnav.htm on the left
* "Outline":PLUGIN_ROOT/org.eclipse.platform.doc.user/concepts/coutline.htm View on the right
* YAKINDU Statechart Editor at the top
* "Problems":PLUGIN_ROOT/org.eclipse.platform.doc.user/concepts/cprbview.htm and "Properties View":PLUGIN_ROOT/org.eclipse.platform.doc.user/concepts/cpropview.htm at the bottom

!images/sc_modeling_perspective.jpg!

In the Eclipse workbench all elements are organized in projects. So first to do is to create a project. Therefore click *File* > *New..." > *Project*. In the wizard click *Next* and insert a project name. Click *Finish*.

Now you see your project in the project explorer. 

h3. Defining a State Machine

In the new project now create a new statechart model:

# Click *File* > *New* > *Other...* > *YAKINDU* > *YAKINDU Statechart Model*
# Click *Next* and name the sct file
# Click *Finish*
# The YAKINDU statechart editor opens on the statechart model. It already has an initial state and an unnamed simple state connected by a transition.

The newly created model has a problem. The new state has a red dot with a cross. This is an error marker. If you look at the problems view (the *Problems* tab) you see more details to that problem. In that case it says: "A state must have a name". 
To solve the problem:
# Click in the name field of the state and type the name 'off'. 
# Click *File* > *Save*. 
The error marker and the entry in the problems view vanish.

!images/sc_modeling_perspective_errorview.jpg!

With the *YAKINDU Statechart editor* you create or modify state models. The editor automatically opens on .sct files. 

The editor consists of three parts: 
* the graphic canvas to design the state machine
* the palette on the right that owns the elements to design the state machine 
* a textual modeling field on the left

!images/sc_editor_01.jpg!

You can use the textual modeling field for declarating internal behavior of states and events or variables.  The editor also owns comfortable functionality like _syntax highlighting_, _code completion_, _live validation_. The following image shows an example of code completion in the text fields of the editor:

!images/sc_editor_code_completion.jpg! 

# Add a second state 
## Click on the symbol *State* in the palette
## Draw a state icon in the main region
## Name the second state 'on'
# Draw a transition from 'off' state to 'on' state. 
## Click on the symbol *Transition* on the palette. 
## Draw a line from 'off' to 'on'. 
## Add the following statement to the transition: after 2 s.
# Draw a transition with an event from 'on' to 'off' state. 
## Click on the symbol 'Transition'
## Draw a line from off to on state.
## In the declarations view add the statement internal: event switchOff.
## To the transition add the text switchOff

h3. Simulating the State Machine

YAKINDU SCT 2 comes with a perspective to simulate the models. To simulate a state machine open the Yakindu *SC Simulation* perspective by clicking *Window* > *Open Perspective* > *SC Simulation*. This perspective is optimized for simulation purposes and consists of:

* "Project Explorer":PLUGIN_ROOT/org.eclipse.platform.doc.user/concepts/cnav.htm on the left
* "Outline":PLUGIN_ROOT/org.eclipse.platform.doc.user/concepts/coutline.htm view on the right top
* Simulation View on the right bottom
* Debug view at the top
* YAKINDU Statechart Editor


The simulation view is an interactive view to watch and control the state machine simulation. To get it open the simulation perspective. 

# Start the simulation by clicking *Run* > *Run*. 
# The simulation starts and state 'off' is red for 2 seconds. Then state 'on' gets active (red).
# Raise event 'switchOff': Click on 'switchOff' in the simulation view.
# State 'off' is active again for 2 seconds.
# Stop the simulation: *Run* > *Terminate*.

!images/simulation_view_active.jpg!

During the simulation in the statechart editor the active state gets a red color. The previous transition is green. The simulation view shows the events that trigger the states. You can change values here to trigger events. Beneath the table there are two clocks. One for the _virtual time_ and one for the _real time_ and a slider to change virtual time.

