Source Code Template Editor

Source Code Template Editor is a tool, which allows you to easily create your own source code templates. Software Ideas Modeler can generate a source code based on diagrams and models by these templates.

Source Code Template Editor is accessible from menu Tools / Templates / Source Codes. (This feature is available only in Ultimate edition)

Languages

Templates are grouped in languages (C#, Java, Visual Basic, etc.). Software Ideas Modeler allows you to create also your own languages, which are not yet supported in the official package. Commands for work with languages are accessible from Language toolbar in Source Code Template Management window. This toolbar consists of langauge drop-down list and three buttons:

  • Add Language – shows a dialog which allows you to add a new template language (set of templates).
  • Edit Language – edits the language selected in the drop down list, the displayed dialog allows you to change name and description of language.
  • Delete Language – removes the language selected in the drop down list.

Add Language

If you click on Add Language button, Language dialog will show and it allows you to add a new template language (set of templates). It contains three fields:

  • Name (1) – specifies a name of the new source code template language.
  • ID (2) – specifies an unique ID of the new language.
  • Description (3) – allows you to set a brief description of the new language.

The new language will be added after clicking OK button (4) or it will be discarded if you click on Cancel button (5).

Source Code Templates Editor - Add Language
Language dialog

Templates

Souce Code Template Management window shows the list of templates defined for the language selected in the drop down list in top toolbar. If no language is selected then no templates are listed and it is also not possible to add any new templates (each template has to be listed under some language).

Source Code Templates Editor - Template Settings
Source Code Templates Editor - Template Settings

1 - list of all templates for selected language, 2 - Settings tab with settings for the selected template, 3 - Files tab with files, which are included in the selected template

The list of templates is placed on the left side of the window and offers three buttons:

  • Add – adds a new template for the active language.
  • Delete – deletes the selected template.
  • More – offers a submenu with these items:
    • Duplicate – duplicates the selected template.
    • Import – copies a file with template to the source code library.
    • Export – exports the selected template to the chosen file.

Add Source Code Template

If you click on Add button in Template panel, Source Code Template dialog will show and it allows you to add a new source code template for the active language. It contains these fields:

  • Name (1) – specifies a name of the new source code template.
  • ID (2) – specifies an unique ID of the new source code template.
  • Author (3) – specifies the name of the template author.
  • Description (4) – allows you to set a brief description of the new source code template.

The new source code will be created and added to the template library after clicking OK button (5) or it will be discarded if you click on Cancel button (6).

Source Code Templates Editor - Add Template
Source Code Template dialog will be shown when you click on Add button

If you select the template in the left list, its details will be displayed in the right side of the window. There are two tabs Settings and Files. The Settings tab allows you to change name, author and description of the selected template. If you want to save the made changes, you have to click on Save button in top toolbar of Settings tab.

Source Code Templates Editor - Template Files
Source Code Templates Editor - Template Files

1 - List of template files, 2 - Preview of the selected template file

The second tab (Files) consists of three parts:

  • Toolbar – has three buttons for file manipulation:
    • Add File – adds a new file to template
    • Edit File – edits the selected file using template editor
    • Rename File – allows you to change the name of the selected file
    • Delete File – removes the selected file from the template (it will be deleted from disk)
  • List of files – displays all files that are part of the selected template.
  • Preview pane – displays preview of the selected template file.

Add Template File

If you click on Add File button in toolbar in Files tab, New Template File dialog will show and it allows you to add a new file to the edited source code template. Type the name to the File name field (1), confirm it with OK button (2) and new template file will be created. If you don't want to create a new file, but you open the New Template File dialog, you can close it with Cancel button (3).

Source Code Templates Editor - Add Template File
New Template File dialog

Source Code Template Editor

Source Code Template Editor allows to easily create and edit the template files for source code generation. Its window consists of three main parts:

  • left side bar with the list of commands
  • right top pane with editors
  • right bottom pane with preview of generated output based on the currently edited template

The right top part of windows contains the tab control with three tabs, which allows you to edit the content of the existing template:

  • Template tab
  • Source code tab
  • Settings tab

Template tab

This tab offers the graphical template editor. It allows you to create and edit the open template file using mouse and drag&drop – you can move, reorder, add and delete the template parts. It also clearly shows the hierarchy of cycles and conditional parts.

Template tab (Source Code Template Editor)
Template tab (Source Code Template Editor)

Source code tab

This tab contains the text editor with command highlighting. It allows you to fast edit the source code of the template.

Source code tab (Source Code Template Editor)
Source code tab (Source Code Template Editor)

Settings tab

This tab allows you to adjust the following settings:

  • Template type – defines the context of template, which can be Element or Diagram.
  • Output name – defines the name of outpu file generated by this template.
  • Name adjustment – offers several options for file name adjustments:
    • None
    • Camel Case
    • Remove Spaces
    • Add Underscores
  • Default type – specifies the name of type, which will be used for cases when no type is explicitly set.
  • Filter – sets the filter which determines in which cases can be used the template (e.g. only for classes or for all elements with some stereotype)
Settings tab (Source Code Template Editor)
Settings tab (Source Code Template Editor)

Comments

Paola 23 October 2014 12:43:19

Generating the Source Code in the student version

I have a question: is this function to generate the source code, starting from a class diagram for example, available also in the free student version of the software?

Because I have this version and in the menu voice "Tools", there isn't the voice "Templates" and then "Source Code".

I need help, thanks in advance.

Dusan Rodina - softwareideas.net 23 October 2014 14:13:50

RE: Generating the Source Code in the student version

Unfortunately, the source code generation and source code templates are not available in the Standard (student) version. These features are available only in higher editions.

TinTouneT 31 March 2015 20:01:48

State diagram : Entry/Do/Exit

Is there any way to get the Entry/Do/Exit functions names in the template ?

thanks

Dusan Rodina - softwareideas.net 31 March 2015 21:52:39

RE: State diagram : Entry/Do/Exit

Unfortunately, these fuctions are not exposed to template framework at the moment, but I will change it in the next version.

Thank you for your notice!

TinTouneT 1 April 2015 15:18:54

Imports

I would like to know at which element item is related the template command keyword "Imports". More precisely : how do i set up the imports for a class element.

Thanks

Dusan Rodina - softwareideas.net 1 April 2015 21:10:10

RE: Imports

Imports can be defined only globally for the whole generation (Source Code Generation dialog - Imports tab). I will add possibility to set imports individually for each class in the new version. It should be released within few weeks. If you have any other questions or suggestions, feel free to let me know.

Nico Verduin 16 May 2017 13:55:37

RE: RE: Imports

Where can I add imports to a class? Or is that not fixed yet?

Dusan Rodina - softwareideas.net 16 May 2017 21:47:16

RE: RE: RE: Imports

The imports can be added to a class using tagged values - you can find it in Properties dialog - Tagged Values tab. If you add a tagged value: Tag=Import Value=NameOfYourImport; you can enumerate the imports in the source code template this way:

<%==SIM:ForEach:Element.Imports==%>

#include <%==SIM:Import.Name==%>;<%==SIM:Line==%>

<%==SIM:EndFor==%>

EganSolo 29 June 2015 10:30:46

Template for Free Pascal?

Is there an existing template for FreePascal (ObjectPascal) in the tool already? Has anyone created such a template? Also, once the template is created, will Software Ideas Modeler be able to do a full round-trip (import/export) from Free Pascal?

Dusan Rodina - softwareideas.net 30 June 2015 8:12:12

RE: Template for Free Pascal?

You can try the template "Delphi" for source code generation (export).

Import (and also round-trip) is not yet supported and will be implemented in one of next versions.

You can create a custom template using Software Ideas Modeler, but it is only for export (not for import).

Nico Verduin 26 July 2016 15:51:59

setters and gettere

My understanding is, is that this is available since version 6. I am working with the latest version (ultimate 30 day trial) And was wondering how do I do that?

Regards

Nico

Dusan Rodina - softwareideas.net 26 July 2016 16:14:56

RE: setters and gettere

Hello,

Source Code Template editor is available in the ribbon: Process (tab)/Templates (group)/Source Code Templates

Nico Verduin 26 July 2016 16:27:21

RE: RE: setters and gettere

Figured it out. Thanks

Nico Verduin 26 July 2016 16:29:06

adding current date time in source template

Is it possible to add the generation date and time of the source files in the templates?

Dusan Rodina - softwareideas.net 26 July 2016 17:08:27

RE: adding current date time in source template

Yes, it is - using the following command:

<%==SIM:Now==%>

If you would like to add only date, it is also possible using this:

<%==SIM:Today==%>

New Comment

Comment