Including requirements as comments in statechart code

If you have requirements that are met by specific states or transitions in a statechart, these requirements can be included as comments in the code generated for the statechart.

Before you begin

This features can be used for C, C++, or Java code.
Note: This feature applies only to Flat statechart implementation.

Procedure

To include requirements as comments in statechart code:

  1. Associate the requirement with the state or transition by creating the requirement below the element in the browser, creating a "trace" dependency, or using an anchor to connect the requirement to the element.
  2. Open the Features window for the relevant configuration, and on the Settings tab verify that the Include Requirements as Comments in Code option is selected. (This controls the value of the CG::Configuration::IncludeRequirementsAsComments property)
  3. Generate code.

Results

Example

Here is a sample statechart and the code generated for it, including comments for the requirements associated with specific states.

IOxfReactive::TakeEventStatus Printer::rootState_processEvent() {
    IOxfReactive::TakeEventStatus res = eventNotConsumed;
    switch (rootState_active) {
        case Idle:
        {
            if(IS_EVENT_TYPE_OF(OMNullEventId))
                {
                    popNullTransition();
                    pushNullTransition();
                    rootState_subState = GettingPaper;
                    rootState_active = GettingPaper;
                    /*
                    state GettingPaper
                    Realizes requirement Printer must be able to load paper for printing #:
                    
                    */
                    
                    //#[ state ROOT.GettingPaper.(Entry) 
                    getPaper();
                    //#]
                    res = eventConsumed;
                }
            
        }
        break;
        case GettingPaper:
        {
            if(IS_EVENT_TYPE_OF(OMNullEventId))
                {
                    popNullTransition();
                    pushNullTransition();
                    rootState_subState = Printing;
                    rootState_active = Printing;
                    /*
                    state Printing
                    Realizes requirement Printer must be able to print the received data after paper is loaded #:
                    
                    */
                    
                    //#[ state ROOT.Printing.(Entry) 
                    print();
                    //#]
                    res = eventConsumed;
                }
            
        }
        break;
        case Printing:
        {
            if(IS_EVENT_TYPE_OF(OMNullEventId))
                {
                    popNullTransition();
                    pushNullTransition();
                    rootState_subState = Idle;
                    rootState_active = Idle;
                    res = eventConsumed;
                }
            
        }
        break;
        default:
            break;
    }
    return res;
}

Feedback