# Code Import and Code Generation

&umbrello; is a &UML; modelling tool, and as such its main purpose is to help you in the analysis and design of your systems. However, to make the transition between your design and your implementation, &umbrello; allows you to generate source code in different programming languages to get you started. Also, if you want to start using &UML; in an already started C++ project, &umbrello; can help you create a model of your system from the source code by analysing your source code and importing the classes found in it.

## Code Generation

&umbrello; can generate source code for various programming languages based on your &UML; Model to help you get started with the implementation of your project. The code generated consists of the class declarations, with their methods and attributes so you can fill in the blanks by providing the functionality of your classes' operations.

&umbrello; 1.2 comes with code generation support for ActionScript, Ada, C++, CORBA IDL, &Java;, JavaScript, PHP, Perl, Python, SQL and XMLSchema.

### Generating Code

In order to generate code with &umbrello;, you first need to create or load a Model containing at least one class. When you are ready to start writing some code, select the Code Generation Wizard entry from the Code menu to start a wizard which will guide you through the code generation process.

The first step is to select the classes for which you want to generate source code. By default all the classes of your model are selected, and you can remove the ones for which you do not want to generate code by moving them to the left-hand side list.

The next step of the wizard allows you to modify the parameters the Code Generator uses while writing your code. The following options are available:

Code Generation Options Options for the Code Generation in &umbrello;

Options for the Code Generation in &umbrello;

#### Generation Options

##### Code Verbosity

The option Write documentation comments even if empty instructs the Code Generator to write comments of the /** blah */ style even if the comment blocks are empty. If you added documentation to your classes, methods or attributes in your Model, the Code Generator will write these comments as Doxygen documentation regardless of what you set here, but if you select this option &umbrello; will write comment blocks for all classes, methods and attributes even if there is no documentation in the Model, in which case you should document your classes later directly in the source code.

Write comments for sections even if section is empty causes &umbrello; to write comments in the source code to delimit the different sections of a class. For example public methods or Attributes before the corresponding sections. If you select this option &umbrello; will write comments for all sections of the class even if the section is empty. For example, it would write a comment saying protected methods even if there are no protected methods in your class.

##### Folders

Write all generated files to folder. Here you should select the folder where you want &umbrello; to put the generated sources.

The Include heading files from folder option allows you to insert a heading at the beginning of each generated file. Heading files can contain copyright or licensing information and contain variables that are evaluated at generation time. You can take a look at the template heading files shipped with &umbrello; to see how to use this variables for replacing your name or the current date at generation time.

##### Overwrite Policy

This option tells &umbrello; what to do if the file it wants to create already exists in the destination folder. &umbrello; cannot modify existing source files, so you have to choose between overwriting the existing file, skipping the generation of that particular file or letting &umbrello; choose a different file name. If you choose the option to use a different name, &umbrello; will add a suffix to the file name.

##### Language

&umbrello; will by default generate code in the language you have selected as Active Language, but with the Code Generation Wizard you have the option to change this to another language.

#### Generation Wizard Generation

The third and last step of the wizard shows the status of the Code Generation process. You need only to click on the Generate button to get your classes written for you.

Note that the Options you select during the Code Generation Wizard are only valid for the current generation. The next time you run the wizard you will need to re-select all the options (your headings folder, overwrite policy, and so on). You can set the defaults used by &umbrello; in the Code Generation section of the &umbrello; settings, available at Settings Configure &umbrello;...

If you have set your Code Generation options to the right settings and want to generate some code right away without going through the wizard, you can select the entire Generate All Code from the Code menu. This will generate code for all the classes in your Model using the current settings (including Output Folder and Overwrite Policy, so use with care).

## Code Import

&umbrello; can import source code from your existing projects to help you build Model of your systems. &umbrello; 1.2 supports only C++ source code, but other languages should be available in future versions.

To import classes into your Model, select the entry Import Classes... from the Code menu. In the file dialogue select the files containing the C++ class declarations and press OK. The classes will be imported and you will find them as part of your Model in the Tree View. Note that &umbrello; will not create any kind of Diagram for showing your classes, they will only be imported into your Model so that you can use them later in any diagram you want.

Code Import Menu for importing source code in &umbrello;

Menu for importing source code in &umbrello;