LENS

Programmer's Guide: How To Create Graphical Displays


Building new graphical displays is not easy, so you are basically on your own. But here are some words of advice. First learn Tcl/Tk really well. Then read through the code in display.tcl, display.c, and displayCom.c until you pretty much understand it.

Now create a new .tcl file with a procedure that will construct all of the static widgets needed in the display. Remember to give all of your global Tcl variables and procedures names that start with a period or dash. Look where display.tcl is sourced in shell.tcl and source your file there too. Now you will need to create a C module consisting of .c, .h, and Com.c files.

There are many ways to communicate data between your C code and Tcl code. In order for the display to be fast, you do not want to be making a lot of calls to getObject to get the data from the network to the display. Rather than having Tcl code "pull" the data, you should have C code "push" the data by making calls to eval() and other Tcl library functions. Your .c file will probably mostly contain procedures that take data from the network and make calls to the interpreter to push the data to your display. You can also use the Tcl_LinkVar() command to bind Tcl variables to C variables, but use it sparingly.

The *Com.c file will define Tcl commands used to request that new data be sent or to modify some property of the display in response to a user action. As with most *Com.c files, it will mostly be parsing the command arguments and then calling the function in the .c file that does the real work. Any Tcl commands you create in *Com.c should be created using createCommand(), rather than registerCommand() and should be given names starting with a period since they will be hidden from the user.

You will probably want to create a button on the Main Window for your display. Do that by editing interface.tcl (see the section on the displayPanel). If your button should be deactivated when there is no network, add some commands to configureDisplay() in control.c. You should probably also create a shell command (or it could just be a Tcl procedure) that will launch the display even if the Main Window is hidden.

If you want to do something that has to be really fast you may need to define a new customized canvas widget. This was done in Lens for the rectangles that appear in the Unit and Link Viewers. You might get some mileage there by copying and modifying canvRect.c. You will probably also want to go hunting through the Tk source code in TclTk/tk8.3/generic/.


Douglas Rohde
Last modified: Mon Nov 13 23:58:31 EST 2000