Adding code to sequence diagrams
Program code can be generated from new, and reverse-engineered sequence diagrams, but only for a sequence diagram linked to the "main operation".
When reverse-engineering code, standard sequence diagram elements, e.g. CombinedFragments, are "mapped/assigned" to coding elements (e.g. "if" statements, loops, etc.).
For those programming statements that have no corresponding sequence diagram elements, e.g. "i = i+1", UModel makes use of "code" notes to add code to diagrams. These notes must then be linked to the lifeline.
Note that UModel does not check, or parse, these code fragments. It is up to you to make sure that the code fragments are correct and will compile.
To add code to a sequence diagram:
1.Click the Note icon then click the model element where you want to insert it, e.g. CombinedFragment.
2.Enter the code fragment, e.g. return.
3.Click the Node Link handle of the inserted note and drop the cursor on the lifeline.
4.Activate the "Is Code" check box in the Properties tab to include this code fragment when generating code.
When selecting a note on a sequence diagram, which can be used for code generation, the property "is code" is available in the Properties window. Clicking the check box, allows you to switch between "ordinary" notes and code generation notes.
Code generation notes
- shown with a darker dog-ear
Code updates occur automatically on every forward engineering process if the "Use for forward engineering" check box is active. If changes were made to the sequence diagram, the code of the operation is always overwritten.
The sequence diagram shown below was generated by right clicking the OnCommand operation and selecting Generate sequence diagram from code. The C# code of this example is available in the C:\Users\<user>\Documents\Altova\UModel2023\UModelExamples\IDEPlugIn\Styles\ folder. Use the option Project | Import Source Project, to import the project.
The code shown below is generated from the sequence diagram.
Public void OnCommand(int nID, object pUModel)