CanvasPlus: an improved modular canvas implementation for Tk Jorge Lima Fac. Sciences of the Univ. of Lisbon ABSTRACT This paper describes "CanvasPlus", a Tk widget targeted for 2D CAD applications. The standard canvas implementation in Tk lacks some important features, like complex object encapsulation, viewing transformations (zoom) and some object transformations (rotations), which make it inappropriate to implement modern drawing applications. Adding this features in an add-hoc fashion to standard canvas implementation can solve some particular application problem, but will increase the canvas code complexity and will always have a limited scope. A different approach, described in this article, consists in a modular canvas implementation. It comprises: a core which provides a basic drawing interface and bindings to events; and a set of application specific modules which implement the higher level commands, these can range from the ones found in the standard canvas implementation, to more structured commands which are necessary to implement complex 2D cad applications SUMMARY The "CanvasPlus" was motivated by the idea of developing a suite of EDA (Electronic Design Automation) tools using Tcl/Tk based GUI. This means that "CanvasPlus" is aimed for applications build in either C or C++, where the GUI would be build using Tcl/Tk scripting capabilities embedded into the application. Tcl/TK was chosen because it can be easily embedded into applications providing instant scripting capabilities which can be used for configuration or batch processing. Also, GUI building is supported through scripting. --- Building the GUI is time consuming and often poorly designed GUIs frustrate the intent of an application. So, it is preferable to allow users to reconfigure the look and feel of the GUI, or even completely redesign it. Tcl/Tk is a suitable framework for application development which supports both, GUI construction and scripting capabilities. However, full featured drawing applications, require specialised widgets. For simple drawing applications, the standard Tk canvas widget might be sufficient but, as the complexity of the objects being manipulated increase, more advanced and specialised widgets are necessary. The "CanvasPlus" widget doesn't provide a specialised canvas implementation. Instead, it provides a framework to develop and use specialised, application centric canvases. The system consists of a core module dealing with Tk an X internals and a set of extension modules implementing application specific drawing modes. The core module supports only a basic set of drawing operations and geometric transformations. It provides the API for extension writers and the infrastructure to load and switch between drawing modes. The core API virtualizes to extension modules a drawing canvas with a physical (in true physical dimensions) Cartesian coordinate system where they can draw using configurable pens. Every specialised canvas share a common subset of drawing operations, all have to deal with the burden of Tk and X details, and all have to interact somehow with the TCL scripting environment. All this issues are dealt only once by the core of the "CanvasPlus" implementation, while the drawing mode extensions will deal only with application specific issues. This approach considerably reduces the effort required to develop specialised canvases for layered 2D drawing applications. >From the Tcl/TK programmer’s point of view, the "CanvasPlus" works much like the standard canvas. The most notable difference resides in the drawing interface: The user will notice that no drawing is possible until a drawing mode is loaded; loading a drawing mode returns a slave Tcl interpreter which will be used for all subsequent interaction with the canvas; the operations supported will dependent on the loaded mode. Using a slave interpreter has some advantages over the standard canvas approach, based in subcommands: multi-line scripts become more readable since repeated references to the canvas name are absent; global variables (local to the slave interpreter) can be safely used to retrieve canvas status information. This difference results in a much more powerful and easy to use scripting interface, as shall be demonstrated in this paper. A "CanvasPlus" prototype has been developed is usable, although some features are still under development. The development was done on X11/Linux and currently no effort were made to port "CanvasPlus" to other platforms. The code was tested and compiles cleanly on i386 and amd64 architectures. Sample code for drawing mode extensions is available both in C and C++.