Go to the first, previous, next, last section, table of contents.


TCL/TK EXTENSION

In this chapter, there are exposed the advanced features of GiD in terms of expandability and total control. The Tcl/Tk extension is the way to create script files to automatize any process created with GiD. With this language it is possible to add new windows or new functionalities to the program.

For more information about the Tcl/Tk programming language look at www.scriptics.com.

If such Tcl file exists, it must be in the problem type directory; the name of the file has to be the problem type name with the .tcl extension.



Event procedures

The structure of problem_type_name.tcl can optionally implements some of these Tcl prototype procedures (and other user defined procedures). The procedures listed below are automatically called by GiD. Their syntax correspond to standard Tcl/Tk language:

proc InitGIDProject { dir } { 
  ...body...
}
proc InitGIDPostProcess {} { 
  ...body...
}
proc EndGIDProject {} { 
  ...body...
}
proc EndGiDPostprocess {} {
  ...body...
}
proc AfterOpenFile { filename format error } {
  ...body...
}
proc LoadGIDProject { filespd } {
  ...body...
}
proc SaveGIDProject { filespd } {
  ...body...
}
proc LoadResultsGIDPostProcess { file } {
  ...body...
}
proc BeforeMeshGeneration { elementsize } {
  ...body...
}
proc AfterMeshGeneration { fail } {
  ...body...
}
proc SelectGIDBatFile { dir basename } {
  ...body...
  set value ...
  return $value
}
proc BeforeRunCalculation { batfilename basename dir problemtypedir gidexe args } {
  ...body...
}
proc AfterRunCalculation { basename dir problemtypedir where error errorfilename } {
  ...body...
}
proc ChangedLanguage { language } {
  ...body...
}
proc BeforeWriteCalcFileGIDProject { file } {
  ...body...
  set value ...
  return $value
}
proc AfterWriteCalcFileGIDProject { file error } {
  ...body...
  set value ...
  return $value
}
proc AfterTransformProblemType { file oldproblemtype newproblemtype } {
  ...body...
}

proc LoadFileInGidUnknowExtension { filename } {
  ...body...
}

Note: To use Tcl to improve the capabilities of writing the calculations file, it is possible to use the command *tcl in the template file (.bas file); see section Specific commands for details.



Control functions

GiD offers the following Tcl functions:



Process function

GiD_Process command_1 command_2 ...

This is a simple function but really powerful. It is used to enter commands directly inside the central event manager. The format of the command has to be a string with the same style as if they were entered by typing on the command line interface.

You have to enter exactly the same sequence as you would do interactively, including the escape sequences, using the word escape, and selecting the menus and operations used.

It is possible to obtain the exact commands that GiD needs, by checking the right buttons toolbar (Utilities > Graphical > Toolbars). It's also possible to save a batch file (Utilities > Preferences > Batch file) and check there the commands used during the GiD session.

One simple example to create one line:

GiD_Process escape escape escape escape \
        geometry create line 0,0,0 10,0,0 escape



Info function

GiD_Info option

This function provides any information about GiD, the current data or the state of any task inside the application. Depending on the arguments introduced after the GiD_Info sentence, GiD will output different information:



Special functions

It exists some special commands to control the redraw and wait state of GiD:

.central.s disable graphics 'value' The value 0/1 Enable/Disable Graphics (GiD doesn't redraw)

EXAMPLE to disable the redraw:

.central.s disable graphics 1

.central.s disable graphinput 'value' The value 0/1 Enable/Disable GraphInput (enable or disable peripherals: mouse, keyboard, ...)

EXAMPLE to disable the peripherals input:

.central.s disable graphinput 1

.central.s disable windows 'value' The value 0/1 Enable/Disable Windows (GiD displays, or not, windows which require interaction with the user)

EXAMPLE to disable the interaction windows:

.central.s disable windows 1

.central.s waitstate 'value' The value 0/1 Enable/Disable the Wait state (GiD displays a hourglass cursor in wait state)

EXAMPLE to set the state to wait:

.central.s waitstate 1

Usually these command are used jointly:

EXAMPLE

#deactivate redraws, etc wit a widget named $w
$w conf -cursor watch
.central.s waitstate 1
update
.central.s disable graphics 1
.central.s disable windows 1
.central.s disable graphinput 1

...

#reactivate all and redraw
.central.s disable graphics 0
.central.s disable windows 0
.central.s disable graphinput 0
GiD_Process "redraw"
$w conf -cursor ""
.central.s waitstate 0


Note: It's more recommended for a tcl developer, to use the more 'user-friendly' procedures defined inside the file 'dev_kit.tcl' (located in the directory \scripts).
For example, to disable and enable redraws, you can use:

::GidUtils::DisableGraphics 
::GidUtils::EnableGraphics


It exists other GiD-tcl special commands to directly manage materials, conditions, intervals or create nodes and elements, as follows:

GiD_CreateData create|delete material ?<basename>? <name> ?<values>?
To create or delete materials

Example:

GiD_CreateData create material Steel Aluminium {3.5 4 0.2}
GiD_CreateData delete material Aluminium


GiD_AssignData material|condition <name> <over> ?<values>? <entities>
To assign materials or conditions over entities

Example:

GiD_AssignData materials Steel Surface {1 5}
GiD_AssignData condition Point-Load Nodes {3.5 2.1 8.0} {4 8}
GiD_AssignData condition Face-Load face_elements {3.5 2.1 8.0} {15 1 18 1 20 2}


GiD_ModifyData materials|intvdata|gendata ?<name>? <values>
To change all field values of materials, interval data or general data

Example:

GiD_ModifyData materials Steel {2.1e6 0.3 7800}
GiD_ModifyData intvdata  1 ...
GiD_ModifyData gendata ...


GiD_AccessValue set|get materials|conditions|intvdata|gendata ?<name>? <question> ?<attribute>? <value>
To change only some field value of materials, interval data or general data

Example:

GiD_AccessValue set gendat Solver Direct


GiD_IntervalData <mode> <number>|?copyconditions?
To create, delete or set a interval data

Example:

set current [GiD_IntervalData set]
GiD_IntervalData set 2
set newnum [GiD_IntervalData create]
set newnum [GiD_IntervalData create copyconditions]


GiD_LocalAxes <mode> <name> ?<type>? <Cx Cy Cz> <PAxex PAxey PAxez> <PPlanex PPlaney PPlanez>?
To create delete or modify local axes.


For the 'exists' operation, if only it's specified the <name> field, then it's returned 1 when this name exists, and 0 if not.
If also is specified the other values, then <name> is ignored.
The returned value is:
-1 if match the global axes.
-2 if match the automatic local axes.
-3 if match the automatic alternative local axes.
0 if it does not match with any axes.
<n> if match the user defined number <n> (n>0) local axes.

Example:

GiD_LocalAxes create "axes_1" rectangular C_XY_X {0 0 0} {0 1 0} {1 0 0}
GiD_LocalAxes delete axes_1
GiD_LocalAxes exists axes_1
	 
GiD_LocalAxes exists "" rectangular C_XY_X {0 0 0} {0 1 0} {1 0 0}
this last sample returns -1 (equivalent to global axis)


GiD_Geometry create|delete|get|list point|line|surface|volume <num>|append <data>
To create, delete, get data or list the identifiers of geometric entities


Examples:

GiD_Geometry create surface 1 nurbssurface Layer0 4 1 1 2 2 0 0 {1 1} {4 1} {3 1} {2 1} \
                  {0.17799 6.860841 0.0} {-8.43042200 6.86084199 0.0} {0.17799400 0.938510 0.0} \
		  {-8.43042 0.938510 0.0} 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0

GiD_Geometry list points 1: layer:layer_name

GiD_Mesh create|delete|edit node|element <num>|append <elemtype> <nnode> <N1 ... Nnnode> ?<matname>? | <x y z>
To create or delete mesh nodes or elements.


Examples:

GiD_Mesh create node append {1.5 3.4e2 6.0}

GiD_Mesh create element 58 triangle 3 {7 15 2} steel

GiD_Mesh delete element {58 60}

GiD_Result create|delete|get|get_nodes <data>
To create, delete or get postprocess results.


Examples:

GiD_Result create {Result "Res Nodal 1" "Load analysis" 4 Scalar OnNodes} {1 2} {2 2} {113 2} {3 5} {112 4}
GiD_Result create {Result "Res Gauss 1" "Load analysis" 4 Scalar OnGaussPoints "My Gauss"} {165 2} {2} {3} {164 5} {4} {3}
GiD_Result delete {"Res Nodal 1" "Load analysis" 4}

GiD_ModifiedFileFlag set|get ?<value>?
There is a GiD internal flag to indicate that the model has changed, and must be saved before exit.
With this command it's possible to set or get this value flag.

Example:

ModifiedFileFlag set 1
ModifiedFileFlag get


GiD_MustRemeshFlag set|get ?<value>?
There is a GiD internal flag to indicate that the geometry, conditions, etc are changed, and must re-generate the mesh before calculate.
With this command it's possible to set or get this value flag.

Example:

GID_MustRemeshFlag set 1
GID_MustRemeshFlag get


GiD_SetModelName <name>
To change the current model name.

GiD_Set <varname> ?<value>?
This command set or get GiD variables.
GiD variables can be found through the right buttons menu (see section Graphical), under the option utilities > variables.

Example:

GiD_Set CreateAlwaysNewPoint 1


drawopengl
It is possible to use directly OpenGL commands from GiD-Tcl using the command "drawopengl draw" For example: C/C++ use:

glBegin(GL_LINES);
glVertex(x1,y1,z1); 
glVertex(x2,y2,z2); 
glEnd();   

GiD-Tcl use:

drawopengl draw -begin lines
drawopengl draw -vertex [list $x1 $y1 $z1]
drawopengl draw -vertex [list $x2 $y2 $z2]
drawopengl draw -end

The standard syntax must be changed following these rules:
- OpenGL constants: "GL" prefix and underscores character '_' must be removed. The command must be written in lowercase.
Example:

GL_COLOR_MATERIAL -> colormaterial

- OpenGL functions: "GL" prefix must be removed and command written in lowercase. Pass parameters as list, without use parenthesis ()
Example:

glBegin(GL_LINES) -> glbegin lines

The subcommand "drawopengl draw" provides access to standard OpenGL commands, but also exists other "drawopengl" special GiD sucommands:

List of supported OpenGL functions:
accum alphafunc begin blendfunc call calllist clear clearaccum clearcolor cleardepth clearstencil clipplane color colormask colormaterial copypixels cullface deletelists depthfunc depthmask dfactorBlendTable disable drawbuffer drawpixels edgeflag enable end endlist evalcoord1 evalcoord2 evalmesh1 evalmesh2 finish flush fog frontface frustum genlists hint hintModeTable initnames light lightmodel linestipple linewidth loadidentity loadmatrix loadname lookat map1 map2 mapgrid1 mapgrid2 material matrixmode modeColorMatTable multmatrix newlist newListTable normal opStencilTable opStencilTable ortho perspective pickmatrix pixeltransfer pixelzoom pointsize polygonmode popattrib popmatrix popname pushattrib pushmatrix pushname rasterpos readbuffer readpixels rect rendermode rotate scale scissor selectbuffer shademodel stencilfunc stencilmask stencilop texcoord texenv texgen teximage1d teximage2d texparameter translate vertex viewport

List of special non OpenGL standard functions:
getselection

List of supported OpenGL constants:
accum accumbuffer accumbufferbit add alphatest always allattrib allattribbits ambient ambientanddiffuse autonormal aux0 aux1 aux2 aux3 back backleft backright blend bluebias bluescale ccw clamp clipplane0 clipplane1 clipplane2 clipplane3 clipplane4 clipplane5 colorbuffer colorbufferbit colorindex colormaterial compile compileandexecute constantattenuation cullface current currentbit cw decal decr depthbuffer depthbufferbit depthtest diffuse dither dstalpha dstcolor enable enablebit emission equal eval evalbit exp exp2 eyelinear eyeplane feedback fill flat fog fogbit fogcolor fogdensity fogend fogmode fogstart front frontandback frontleft frontright gequal greater greenbias greenscale hint hintbit incr invert keep left lequal less light0 light1 light2 light3 light4 light5 light6 light7 lighting lightingbit lightmodelambient lightmodellocalviewer lightmodeltwoside line linebit linear linearattenuation lineloop lines linesmooth linestipple linestrip list listbit load map1color4 map1normal map1texturecoord1 map1texturecoord2 map1texturecoord3 map1texturecoord4 map1vertex3 map1vertex4 map2color4 map2normal map2texturecoord1 map2texturecoord2 map2texturecoord3 map2texturecoord4 map2vertex3 map2vertex4 modelview modulate mult nearest never none normalize notequal objectlinear objectplane one oneminusdstalpha oneminusdstcolor oneminussrcalpha oneminussrccolor packalignment packlsbfirst packrowlength packskippixels packskiprows packswapbytes pixelmode pixelmodebit point pointbit points polygon polygonbit polygonstipple polygonstipplebit position projection q quadraticattenuation quads quadstrip r redbias redscale render repeat replace return right s scissor scissorbit select shininess smooth specular spheremap spotcutoff spotdirecion spotexponent srcalpha srcalphasaturate srccolor stenciltest stencilbuffer stencilbufferbit t texture texture1d texture2d texturebit texturebordercolor textureenv textureenvcolor textureenvmode texturegenmode texturegens texturegent texturemagfilter textureminfilter texturewraps texturewrapt transform transformbit triangles trianglefan trianglestrip unpackalignment unpacklsbfirst unpackrowlength unpackskippixels unpackskiprows unpackswapbytes viewport viewportbit zero
Can read the description of the standard OpenGL functions in an OpenGL manual.

Managing menus

GiD offers some functions to change the GiD menus. With these functions it is possible to add new menus or to change the existing ones. If you are creating a problem type, these functions should be called from the InitGIDProject or InitGIDPostProcess functions (see section TCL/TK EXTENSION).



Note: Menus and option menus are identified by its name.
Note: It is not necessary to restore the menus when leaving the problem type, GiD already does it.

The Tcl functions are:



EXAMPLE: creating and modifying menus
In this example we create a new menu called "New Menu" and we modify the GiD Help menu:



The code to make these changes would be:

CreateMenu "New Menu" "PRE"
InsertMenuOption "New Menu" "Option 1" 0 "Command_1" "PRE" 
InsertMenuOption "New Menu" "Option 2" 1 "Command_2" "PRE"
InsertMenuOption "New Menu" "---"      2 "" "PRE"
InsertMenuOption "New Menu" "Option 3" 3 "Command_3" "PRE" 

InsertMenuOption "Help" "My Help" 1 "" "PRE" "insert"
InsertMenuOption "Help" "My Help>My help 1" 0 "Command_help1" "PRE" 
InsertMenuOption "Help" "My Help>My help 2" 1 "Command_help2" "PRE" 

RemoveMenuOption  "Help" "Customization Help" "PRE" 
RemoveMenuOption  "Help" "What is new ..." "PRE"
RemoveMenuOption  "Help" "FAQ" "PRE"
UpdateMenus



EXAMPLE: removing a submenu or a submenu option
In this example we remove the option Quadrilateral of the Meshing menu.



To remove option Quadrilateral:

RemoveMenuOption  "Meshing" "Element type>Quadrilateral" "PRE" 
UpdateMenus



HTML support

The problem type developer can take advantage of the internal HTML browser if he wants to provide an online help.

HelpWindow

  1. Create a directory named html inside your problem type directory
  2. Call HelpWindow "CUSTOM_HELP" "problem_type_name", where problem_type_name is the name of your problem type with the .gid extension (for example, cmas2d.gid).
  3. Function HelpWindow opens the file "index.html" which must be inside the html folder.


It's a good idea to call the function HelpWindow "CUSTOM_HELP" "problem_type_name" using the menu functions (see section Managing menus).


EXAMPLE: Adding a customized HTML help in the Help menu for the CMAS2D problem type:

InsertMenuOption "Help" \ 
    "Help CMAS2D"  0 {HelpWindow "CUSTOM_HELP" "cmas2d.gid"} "PREPOST" 

UpdateMenus



GiDCustomHelp

From version 7.4 the problemtype developer can to take advantage of the new help format. It is essentially the same html content, but now with and enhancement look and structure. The procedure to show the help using the new format is GiDCustomHelp:

GiDCustomHelp ?args?

Where args is a list of pairs option value. The valid options are:

Structure of the help content

Assuming we have chosen html as the base directory for the multilingual elp contents we can have the following structure:

  html
    \__ en - English content
      
    \__ es - Spanish content

Each content will provably have a directory structure to organize the information. By default the help system build a tree resembling the directory structure of the help content. In this sense there will be an internal node for each subdirectory, finally the html documents will be the terminal nodes of the tree.

We can also provide a help.conf configuration file in order to provide more information about the structure of the help. In a help file we can specify a table of contents (TocPage), help subdirectories (HelpDirs) and topic index (IndexPage).

HelpDirs

With HelpDirs we can specify which of the subdirectories will be internal nodes of the help tree. Also we can specify label for the node and a link to load when the noded is clicked. The link is relative the node. For instance:

      HelpDirs {html-version "GiD Help" "intro/intro.html"} \
               {html-customization "GiD Customization"} \
               {html-faq "Frequently Asked Questions"} \
               {html-tutorials "GiD Tutorials" "tutorials_toc.html"} \
               {html_whatsnew "Whats New"}

TocPage

TocPage define an html page as a page describing a table of contents of the current node (current directory). We have considered two ways for specifying a table of content:

     1- <UL> <LI> ... </UL> (default)
     2- <DT> <DL> ... </DT>

The first is the one generated by texinfo.

For instance:

    TocPage gid_toc.html

    TolcPage contents.ht DT

IndexPage

If we specify by IndexPage a topic index we can take advantage of the search index. In indexPage we can provide a set of html index pages along with the structure type of the index. The type of the index could be:

    1- <DIR> <LI> ... </DIR> (default)
    2- <UL> <LI> ... </UL> (only one level of <UL>)

The first is the one generated by texinfo.

For instance:

    IndexPage html-version/gid_18.html html-faq/faq_11.html

Custom Data Windows

In this section the Tcl/Tk (scripted) customization of the look and feel of the data windows is shown. The layout of the properties drawn in the interior of any of the data windows either Conditions, Materials, Interval Data or Problem Data can be customized by a feature that we called TkWidget. While the common behaviour of two specific data windows: Conditions and Materials, can be changed by a tcl procedure provided for that purpose. This common behaviour include, for instance in the case of Materials, assigning/unassigning, drawing, geometry types where to assign materials, creating/deletening materials, etc.

TkWidget

The problem type developer can change the way a QUESTION is displayed and if he wishes he can also change the whole contents of the window, maintaining the basic behavior of the data set, i.e. in condition window: assign, unassign, draw; in material window: create material, delete material and so on.

With the default layout for the data windows the questions are placed one after another in one column inside a container frame, the QUESTION's label in column zero and the VALUE in column one for an example see picture below.

CONDITION: Steel_section
CONDTYPE: over lines
CONDMESHTYPE: over body elements
QUESTION: Local_Axes#LA#(-Default-,-Automatic-)
VALUE: -Default-
QUESTION: SteelName
VALUE: IPN-80
QUESTION: SteelType
VALUE: A37
END CONDITION


Default layout in data windows

The developer can override this behavior using TKWIDGET. TKWIDGET is defined as an attribute of a QUESTION and the value associated to it must be the name of Tcl procedure, normally implemented in a Tcl file of the problem type. This procedure will take care of drawing the QUESTION. A TKWIDGET may also draw the entire contents of the window and also attending some events related to the window and its data.

The prototype of a TKWIDGET procedure is as follow:

proc TKWidgetProc {event args} {
  switch $event {
    INIT {
       ...
    }
    SYNC {
       ...
    }
    DEPEND {
       ...
    }
    CLOSE {
       ...
    }
  }
}

The procedure should return:

The argument event is the type of event and args is the list of arguments depending on the event type. The possible events are: INIT, SYNC, CLOSE and DEPEND. Below is a description of each event.

The picture below shows a fragment of the data definition file and the GUI obtained. This sample is taken from problemtype RamSeries/rambshell and in this case the TKWIDGET is used to create the whole contents of the condition windows. For a full implementation, please download the problem type and check it.

CONDITION: Steel_section
CONDTYPE: over lines
CONDMESHTYPE: over body elements
QUESTION: Local_Axes#LA#(-Default-,-Automatic-)
VALUE: -Default-
QUESTION: SteelName
VALUE: -
QUESTION: SteelType
VALUE: -
TKWIDGET: SteelSections
END CONDITION


Customized layout in data windows

Data Windows Behaviour

In this subsection we explain a tcl procedure used to configure the common behaviour of Materials. We are working in providing a similar functionality for Conditions using the same interface.

GiD_DataBehaviour controls properties of data windows for Materials and Conditions (not currently implemented). For Materials we can modify the behaviour of assign, draw, unassign, impexp (import/export), new, modify and delete. We can also specify the entity type list in assign option throught the subcommands geomlist and meshlist.

The syntax of the procedure is as follow:

GiD_DataBehaviour data_class name ?cmd? proplist

where,

Example:

GiD_DataBehaviour materials Table geomlist {surfaces volumes}
GiD_DataBehaviour materials Solid hide {delete impexp}  

GiD version

Normally a problem type requires a minimum version of GiD to run. Because the problem type can be distributed or sold separately from GiD, it's important to check the GiD version before continuing with the execution of the problem type. GiD offers a function, GiDVersionCmp, which compares the version of the GiD which is currently running with a given version.

GiDVersionCmp { Version }

Returns a negative integer if Version is greater than the currently executed GiD version; zero if the two versions are identical; and a positive integer if Version is less than the GiD version.

Note: This function will always return a -1 if the GiD version is previous to 6.1.5.


EXAMPLE

proc InitGIDProject { dir } {
    global GidPriv
    set VersionRequired "7.7.0b"
    set comp -1
    catch { 
      set comp [GiDVersionCmp $VersionRequired]
    }
    if { $comp < 0 } {
	WarnWin [= "This interface requires GiD %s or later" $VersionRequired]
    }
}



Using EXEC in GiD

The Tcl language has the exec command used to invoke a sub process. This command treats its arguments as the specification of one or more sub processes to execute. It's possible to invoke a sub process from GiD using this option.

Example: invoking a process in the background

exec netscape http://www.gidhome.com & 



Note: In Windows, instead of & it's necessary to put >& NUL: & to run the process in the background. Example: exec PROGRAM_NAME >& NUL: &



Detailed example - Tcl/Tk extension creation

Next is an example of the creation of a Tcl/Tk extension, step by step. In this example we will create the cmas2d.tcl file, so, we will extend the capabilities of the cmas2d problem type. The file cmas2d.tcl has to be placed inside the cdmas2d problem type directory.

Note: The cmas2d problem type calculates the center of masses of a 2D surface. This problem type is located inside problemtypes, in the GiD directory.

In this example, the cmas2d.tcl creates a window which appears when the problem type is selected.



Window created in the cmas2d.tcl example file

This window gives information about the location, materials and conditions of the problem type. The window has two buttons: the button CONTINUE lets the users continue working with the cmas2d problem type; the button RANDOM SURFACE creates a random 2D surface in the plane XY.


Here starts the Tcl code for the example. There are three main procedures in the cmas2d.tcl file:


Go to the first, previous, next, last section, table of contents.