As mentioned in the previous chapter, the entire GUI was written using
the scripting language Tcl/Tk. The high-level of
abstraction offered by this language helped overcome many of the
tedious, low-level implementation hurdles commonly encountered when
developing a GUI. Also because there is no need to compile
Tcl scripts, development is reduced to relatively simple
iterations of edit execute cycles.
Conventional compiled languages, such as C and
C++, require much more time consuming edit
compile
link
execute cycles.
The GUI is comprised of approximately 7500 lines of Tcl/Tk code which includes about 2200 lines of internal documentation and 5300 lines of Tcl script. Using the ``autoloading'' feature of Tcl, the code was broken down into nearly three dozen sub-scripts or modules as shown in Figure 3.1. A main module named tksim is responsible for calling the appropriate procedures that create the circuit editor window and signal display window and basically serves to set the GUI in motion.
Figure 3.1: Modularization of the GUI Source
When a production release is made, all the scripts are combined into
one large script file; all the comments are stripped out so as to
reduce the overall size and increase the execution speed of
the script. In
order to run the production release, several environment variables
have to be set, which inform the GUI of the location of various bitmap
files and the location of the simulator engine executable. More details
regarding the installation of the production release is presented
in Appendix A.
One of the main problems with Tcl is the lack of modular namespaces -- the names of global variables or procedures in one module may conflict with the names of variables in other modules. To get around this problem, a naming scheme was adopted whereby the names of global variables and procedures were prefixed with unique strings which help classify the name and make the name unique. For example, variables and procedures which are directly related to components are prefixed with the string comp_; likewise, variables and procedures related to netlists are prefixed with net_. In order to encourage encapsulation, abbreviations of prefixes were used to indicated that a procedure or variable should only be used by other procedures inside the module in which it is defined. For example, the procedure draw_rotate in the draw.tcl module can be used by procedures in other modules, but the procedure dr_rotate_item should only be called within the draw.tcl module. This approach is not ideal since it is not enforced by the underlying language. However, it does help to overcome the lack of scope control in the global namespace.
Due to space constraints, it is not possible to describe in intimate detail every single procedure implemented by the GUI; therefore, only certain high-level aspects of the implementation will be elaborated upon in detail during this chapter. The code contains sufficient internal documentation, so the lack of external documentation in this report should not present too many problems to those wishing to explore and understand the internals of the package in greater detail.