Code Generation - Turn Your Diagram to Code
UML Code Generator
Software Ideas Modeler is a feature-rich UML tool that allows you to generate code in various programming and scripting languages very easily. UML code generator supports the following programming languages with the pre-defined generation templates:
- Action Script
- Protocol Buffer
- SQL DDL
UML to Code
Software Ideas Modeler can generate code from UML diagrams. There are pre-defined templates that allow you to turn your UML Class Diagram with all the classes, interfaces, enumerations, and various relationships to source code in Java, C#, Python, C++, or other languages.
You can specify logical (UML) types for the attributes and operation and the generator will transform them into a correct type in the target language. If there is a need for language-specific types that cannot be resolved from the general logic types, you can use a type set for the specific language directly in the diagram - then the exact type will be used.
How to Generate Code for a Diagram?
There are two ways how to generate source code for a diagram - using the Generation sidebar or the Generation dialog.
The fastest way is to use the Generation sidebar. (It can be displayed from Ribbon/View tab/Window group/Sidebars drop-down/Generation). The sidebar allows you to generate code for the active diagram or only for the selected elements in the diagram editor. So you can easily generate code snippets and copy them from the code editor inside the sidebar.
How to Generate Code for Multiple Diagrams or Whole Project?
You can also generate the source code from UML using the Source Code Generation dialog. It is useful when you want to generate code for the whole project or more diagram at once. You can open it from the ribbon - Process tab / Generation group / Source Code button.
You can choose which diagrams you want to generate in the Source Code Generation dialog. The dialog supports searching in the project tree and offers the button for multiple node selection.
The dialog window is divided into two parts - a project tree on the left and a tab control with generation options on the right.
The project tree allows you to choose diagram elements for which you want to generate source code. You can select all nodes or only some folders or diagrams.
The dialog includes the following tabs: General, Imports, and Template Options.
The General tab offers main generation options. You can choose here which language and template you want to use. Some languages can offer multiple templates. You need to specify where should be the output code generated using the Output directory box. You can enter a local folder path to the box, or you can click on the button with the ellipsis on the right and choose a folder from the folder tree in the dialog.
Another option on the General tab is Encoding. The default encoding is UTF-8, but you can change it to one of the other standard options.
The following options allow you to adjust the organization of the generated code:
- Create subdirectories for packages - if checked, a hierarchy of folders will be created by project folders and packages. If unchecked, all files will be placed in the output directory without creating any additional subfolders.
- One file per diagram - the code for elements in one diagram will be generated into one file.
The Imports tab allows you to specify additional external packages that should be included in the source code files through imports and usings. The tab contains Add and Remove button for list editing. The buttons with the up and down arrows allow you to reorder the list.
Template Options tab contains template-specific settings. They may vary from template to template. Many templates offer at least these options:
- Indentation char - specifies the character used for code indentation - it can be a space or tab.
- Indentation size - specifies the number of indentation characters used for a single indentation level.
Unsupported Language or Diagram to Code Transformation
If you need to transform the diagram into code for a specific programming language or a framework in a defined language, you can do it. Software Ideas Modeler provides source code template language which allows you to define any template for any diagram type you want. You may even add a new programming language.