logo

Macros

logo
welcome: Please Sign in

the fair gds editor


location: Macros

Macros/Scripting

For automated design creation, addding new features, adjusting the user interface, parametric cells, calling external tools or as callback for different events like changing of a device parameter and completion of an external tool macros or scripting is used. The LayoutEditor offers a wide range of creating such macros or scripts. It can be recored from the user interface or programmed with internal or external tools in common programming languages like C++ or python. Fundamental parts of the macro programing are:

Macro Recording

The simplest way to use macros is macro recording. Like many office programs the LayoutEditor can record the operations you have done with the graphical user interface. The operation are stored in a C/C++ style and can be edited with any text editor. The recording can be started via StartMacroRecording and stopped via StopRecordedMacro. After stopping the recording you will be asked for a location to store the macro. Stored macros can be executed via ExecuteMacro function. Alternative you can store the macro file in a specially named folder. All macros in that folder and its sub folders will be added into the menu of the LayoutEditor.

Data Structure

Structure Overview

The data stucture in the LayoutEditor is keep simple. A short overview is given here. More detailed information can be found for each class. The scripting is object orientated using a couple of classes and extensive use of pointers.

legende

Layout Window Structure

In any variant of scripting you will get a pointer with the name 'layout' on the class layout. The class layout is the main window in the LayoutEditor. With methods in this class you can adjust the graphical user interface or call common dialog e.g for requesting a new file name. It also contains a pointer with the name 'drawing' to the class drawingField. This class stores the design data and gives a high level access to manipulate the data. Also methods for loading and saveing are avaiable. The class drawingField has a pointer 'currentCell' to the current displayed cell and a pointer 'firstCell' to a list of all cells in the design.

classes layout

Cell Data Structure

The class cell stores data belonging to a single cell likes the cell name. It has a plenty of methods for a mid level modification of the cell elements e.g. selecting elements in a defined region or moving all selected shapes. The class cell includes a list of all elements in the cell. Each single element of the design which can be one of the four basic shapes (path, box, polygon or text) or a reference (cell reference or cell reference array) is store in the class element. Via method of the class element a low level access to any data is possible e.g. selecting that element or setting the vertexes.

cell classes

C/C++ Macros

C/C++ macros are text-files and can be edited by with the EditMacro feature or any other text editor of your choice. Macros can stored everywhere and can be executed by the ExecuteMacro feature. Macros stored somewhere below the "macros"-directory (set up via the SetupDialog or by default in the layout installation-directory-tree) are inserted in the menu tree. During program launch these directory-tree is scanned and added to the corressponded place. By correct naming of the subfolder you define where in the menu the macros is displayed and even in which window (layout, schematic, text editor) it appears. A modification of the macro-program is possible while the layout-program is running. Creating of macros had to be done in a TextEditor, e.g. in the text editor build in the LayoutEditor. Macro-examples are supplied within this documentation. If you program macros, which may be interesting for the general public, please contribute them to this project.

Structure of Macros

All macros are in a pseudo C/C++ code. They had to start as follow:

   1 #!/path_to_the_layout/layout
   2 #codec=UTF-8
   3 #name=your_macro_name
   4 #help=help_for_your_macro
   5 

The line 2 (#codec...) is optional and only required, if you use non asc characters.

The main-function in the macro is executed. If a exitcode unequal 0 is returned, a warning is display. All called function had to be defined before the main function.

   1 int main(){
   2 ...
   3 }

As standard types you can use int, double, bool, void. Additional there are further type like string, point, pointArray, etc. The usage of pointers is possible. Pointer on pointer are not allowed. while, do ... while, for and if structures can be used. switch, enum and struc structures are not allowed and will case a termination. Own functions can be created, own classed are not possible. Compiler commands unless '#include' are ignored. Comments are possible. A more details description of the supported C/C++ langunage you will find here.

Most of the drawing relevant classes can be accessed via the class layout. The layer information is accessed via the class layer, the general setup via the class setup and the schematic window via the class schematic.

List of all layout specific classes

Example Macros

Python Macros

The use of python macros requires 'pylayout'. Pylayout is a python module with all the feature of the LayoutEditor. It is shipped with the LayoutEditor in some packages. It is not and will not be available for some older platform versions.

Python macro can be used in the same way as C/C++ macros. The application interface has the same structure. There are only a few python specific differences. One difference is, that python macros must contain the word 'python' in the first line to be recognize as a python macro. A simple python macro would look like this:

   1 #!use python
   2 #name=#1: Python Exsample 1
   3 #help=Helptext for Sample 1
   4 
   5 layout.drawing.point(0,0)
   6 layout.drawing.point(4000,2000)
   7 layout.drawing.box()
   8 layout.drawing.scaleFull()

This simple example will add a box to the current cell on the active layer.

Note:

The LayoutEditor uses all available processor cores in a system. So a python macro will be executed in a separate thread. Mouse and keyboard events are send to the main thread. Depending on your system configuration this may result in 'problems'/'restrictions', if you create own user interfaces. Use Python Program Extensions to avoid it.

Python Program Extension

The main LayoutEditor window as well as the juspertor library manager is written in python. These python sources are free and can be adjusted by anyone. You can add new features, integrate other tools or even embed the LayoutEditor into any other python program. The LayoutEditor uses the qt library for the graphical user interface and any of its feature is available for adaption. Please see the python-qt bindings documentations for details.

Multithreading

The LayoutEditor uses multithreading. This mean that all available processor core are used coincidental. So a design can be save during you review or print it. For data integrity and synchronisation mutexes are used. For you python extension you had to use it as well to avoid data lost or program crashes. So for any access to a layout design you had to lock the mutex and release it afterwards. So a mutex read lock will wait until any write lock has finished, etc. Please see the class drawingField for a more detailed documentation

See also


Macros (last edited 2012-04-15 10:35:05 by JürgenThies)