Last Updated:

Have Multiple Enumerations with the Same Literals Using Rhapsody Model Transformations

Andy Lapping Helper

The Problem

Rhapsody models may have multiple enumerated types that have common literals. For example the model might have a type called Priority with values High and Low and another called severity with the same literals. The C++ language (which Rhapsody systems models also use to execute the models) does not allow this and such models wil not compile. 

The general solution in C++ is to use namespaces for the types. In a Rhapsody model that would mean having each type in its own package - hardly best practice in modeling. 

The Solution

Rhapsody has a feature that is not widely known - Model Transformations. Much like Model Simplifiers they are an option in the code generation process, allowing you to run your own helpers to modify the model before code is generated. However, whereas a Model Simplifier 'flattens' the model to only the code generating parts, a Model Transformer creates a complete copy of it. This makes it much easier to write a Model Transformer and also allows modifications that are just not possible with a Model Simplifier - such as this enumerated types issue. 

The model transformer can move each enumerated type into its own package in the transformed model which is used for code generation - leaving the original design model untouched. The entire sewuence can be invisible to the modeler. 

Worked Example

The zip file below contains a presentation that explains the process in more detail along with a sample Rhapsody model, profile and Eclipse project with the Model Transformer code.

Get it here