Migrate to Statechart Editor codegenerator

For a detailed introductino to the Statechart editor refer to sce-tutorial.

Migrating Statecharts to use the Code Generator

If you created a Statechart before the Statechart Editor Code Generator (ScECG) was introduced, you need to apply some changes to your Statechart. By hand. Sorry.

  • Locate CMakeLists.txt of your Statechart Group.
  • For each header add a [StateName].generated.h line. Add the armarx package tool template line exactly once as shown below. Example:
    set(HEADERS
    MyGroupRemoteStateOfferer.h
    ./MyState.h
    #@TEMPLATE_LINE@@COMPONENT_PATH@/@COMPONENT_NAME@.h
    ./MyState.generated.h                                            # <-- add this for each state
    #@TEMPLATE_LINE@@COMPONENT_PATH@/@COMPONENT_NAME@.generated.h    # <- add this once
    )
    
  • For each state: Replace the include in [StateName].h:
    ///////// LOCATE:
    #include <ArmarXCore/statechart/xmlstates/XMLState.h>
    
    ///////// REPLACE BY:
    #include "[StateName].generated.h"
    
  • For each state: Change the inheritance, go to [StateName].h and change the class. Look for the class header. Change the class, so it inherits only from [StateName]GeneratedBase:
    namespace armarx
    {
        namespace MyGroup
        {
        ///////// LOCATE:
            class MyState :
                virtual public XMLStateTemplate < MyState > ,
            public XMLStateFactoryBase
        {
    
        ///////// REPLACE BY:
            class MyState :
                public [StateName]GeneratedBase<[StateName]>
        {
    
  • also, remove the getName definition from the class header in [StateName].h:
    /// REMOVE:
                static std::string GetName();
    
  • Modify init list of each states constructor in [StateName].cpp
    ///////// LOCATE:
    MyState::MyState(XMLStateConstructorParams stateData) :
        XMLStateTemplate<MyState>(stateData)
    {
    
    ///////// REPLACE BY:
    [StateName]::[StateName](XMLStateConstructorParams stateData) :
        XMLStateTemplate<[StateName]>(stateData),
        [StateName]GeneratedBase<[StateName]>(stateData)
    {
    
  • Remove this from every [StateName].cpp (this has moved to the generated header)
    # remove this from every [StateName].cpp
    // DO NOT EDIT NEXT FUNCTION
    std::string MyState::GetName()
    {
        return "MyState";
    }
    
  • Open the Statechart Group in the Statechart Editor and click save. This will generate all the .generated.h files.