CIBC:Documentation:SCIRun:DevManual:InterfaceToTCL
Interface to TCL
This chapter describes how to easily communicate between the GUI (Tcl/Tk) and the C++ elements of SCIRun modules.
Introduction
SCIRun uses TCL/TK as its GUI font end. However, the TCL/TK was not designed with a clean interface between TCL code and C/C++. The purpose of this directory is to provide an abstraction layer between the two and make the task of moving data between the TCL and the C++ portions of SCIRun transparent to the user.
Most of the code in the Dataflow/GuiInterface directory is used internally in SCIRun. The only exception are the GuiVars which can be access from both the tcl and the C++ codes. These variables provide a transparent mechanism in C++ to set or get the tcl variables they represent. Each such tcl variable is associated with a Module and thus contains information about the module tcl id and a pointer to the module.
Programming with the SCIRun GuiInterface
On the TCL side, the code should access the variables as regular tcl variables. On the C++ side, the code needs to declare these variables inside a Module and access them via the get() and set() functions.
GuiVar
GuiVars are variables that encapsulate the interaction between the C++ code and the GUI (Graphical User Interface) code. The variable does not hold the actual value, rather it holds information which is used to access the corresponding variable on the GUI side. From the C++ side the user may set the variable value via a set() function and retrieve the value via a get() function.
There are several specialization of GuiVar for particular variable types such as GuiInt, GuiString and GuiPoint.
In a tcl code, i.e. in a tcl module:
itcl_class foo { ... method set_defaults {} { global $this-min global $this-max set $this-min 0 # set to 0 set $this-max [set $this-min] # '[set $this-var]' returns its value } ... }
In the C++ side, i.e. in a module:
class Demo : public Module { ... GuiInt gui_min, gui_max; // define GUI variables Demo( const clString& id ); void init(); }; Demo::Demo( const clString &id ) : Module(...), gui_min("min",id, this), // initialize a variable with gui_max("max",id,this) // its name on the tcl side. { ... } void Demo::init() { gui_min.set(7); // set a tcl variable int i = gui_max.get(); // get a value from the tcl side }
Go back to Documentation:SCIRun:DevManual