User Code
The following behavior elements allow you to specify your own user code inside the model.
With Operations
, Opaque Actions
, respective Opaque
/Function behavior
we also support Code Synchronization between the code files and the model, since these elements represent simple, enclosed and independend elements which are only generated once inside the code files.
The syncable user code is enclosed between two single line comments. These use the single-line comment template for their generation.
Embedded Engineer uses 'new line' (depending on the system settings either \n
, \r
or \r\n
) as a delimiter to find the start and end of syncable user code.
Syncable/Non syncable
Info
Take into consideration that the code generation/sync will NOT syntax check or alter code in any way.
How to add user code
Since Enterprise Architect directly associates operations and actions with behaviors it has no need for Function/Opaque behavior types and allows direct incorporation of user code inside the behavior elements.
Operations & Entry/Do/Exit actions
Enterprise Architect will display Entry/Do/Exit actions the same way it displays an operation, the only difference is that UML only allows one entry, do and exit actions.
- Check your Model Setting: User Code storage field
- Select or add an operation/action either in the Project Browser or the Features & Properties tab
- In the Operation Properties tab go to, depending on the Model Setting: User Code storage field, either Behavior or Code.
- Enter your code
(Atomic) Actions
- Select or add a new action to your activity diagram
- Enter your code in the Effect field of the Element Properties tab
(We also support leaving the Effect field blank and directly inserting the code in the Name field)
Since MagicDraw stores Function- and Opaque behavior as elements, we will store your user code as one of those elements.
Function/Opaque behavior
- Create a new Function or Opaque behavior element
- Add your code in the Body and Language field, in the Specification dialog of the behavior element
Operation
- Add/select an operation to your class
- Open the Specification dialog for the operation and click on the "..." button of the Method field
- User the Selection dialog to either create a new or select a previously created Function- or Opaque Behavior.
Info
Embedded Engineer only support a single behavior and will only output one behavior during generation.
Entry/Do/Exit Action
- Add/select a state of your State Machine
- Open the Specification dialog for the state and scroll down to find Entry, Do Activity and Exit groupings.
- Select a Behavior Type: FunctionBehavior or OpaqueBehavior for user code or Activity for modeled behavior
- When selecting a Function- or OpaqueBehavior it will automatically be added to the state and you can enter your code in the Body and Language field
Opaque Actions
Since an Opaque Action is already specified to have "implementation-specific semantics" we do not need a separate Function-/Opaque Behavior
- Add an Opaque Action to your activity diagram. ToolBox Activity Diagram Action Opaque Action
- Check that you have a valid control flow
- Open the Specification dialog for the Opaque Action and directly input the code in the Body and Language field.
(We also support leaving the Body and Language field blank and directly inserting the code in the Name field)
See also