[vtk-developers] New VTK tree : Tcl done (Windows)
Sebastien BARRE
sebastien at barre.nom.fr
Sun May 13 10:25:17 EDT 2001
Hi folks
After some kind of work and CVS hassles, I guess I succeeded in building
the new tree, as well as the Tcl and Python bindings. There are still some
glitches to fix for the Tk Render Widgets, but this is just a patch to add
to CMake. I've tested several Tcl examples (and the tk render widgets),
this looks good.
The Tcl wrappers are no more located in a single vtktcl.dll file. They are
split into several DLLs. Hence, the :
catch {load vtktcl}
is not working anymore (until we find a trick).
I think it might be a good occasion for us to switch to a more serious
structure, i.e. the *package*. This is also the perfect way to perform Tcl
commands upon VTK initialization without hard-coding them in the DLL (for
example, set the default exit method of the render window interactor to the
'exit ' command) :
package require vtktcl
I've committed two files to the CVS :
Wrapping\Tcl\README : installation instruction, and migration path.
Wrapping\Tcl\pkgIndex.tcl : the package
The contents of these file is listed below.
Feel free to flame me.
*****************************
README :
*****************************
VTK Tcl wrappers (Windows platforms)
===========================================================================
Using VTK inside Tcl/Tk is a two step process :
=============================
I) Load the 'vtktcl' package by issuing the following command before any
invocation of a VTK function (typically at the top of your Tcl script) :
package require vtktcl
NOTE: the previous VTK version was built such that the Tcl wrappers were
stored in a single DLL file. Windows users were accustomed to issue 'catch
{ load vtktcl }' in their Tcl scripts to load the VTK commands inside the
Tcl interpreter. The Tcl wrappers are now split in numerous DLL files (i.e.
shared libraries). Unless a compatibility path is found, you will have to
replace any 'catch { load vtktcl }' with the line presented above. A Tcl or
Perl script might be posted later to automate this task.
=============================
II) Install the package :
A good description of the package and library facilities is given in the
Chapter 12 "Script, Libraries and Packages" (page 135) of "Practical
Programming in Tcl & Tk", Brent B. Welch, ISBN 0-13-616830-2.
When a package is "required" by the 'package' command (see part I), the Tcl
interpreter looks through a set of directories and their subdirectories for
pkgIndex.tcl files. It sources those to build an internal database of
packages (and version information).
A pkgIndex.tcl file has been included in this VTK distribution to provide
the 'vtktcl' package to the interpreter. It will load the DLLs, set some
default behaviours and exits with an error message if the package could not
be provided (DLL not found, for example).
The package facility assume that Tcl libraries (and packages) are kept in
well-known directories (and their subdirectories). The list of well-known
directories is kept in the auto_path Tcl variable. This is initialized by
tclsh or wish to include many default directories, including the default
Tcl script library directory. For example :
% puts $auto_path
C:/devel/langages/tcl/8.3/lib/tcl8.3 C:/devel/langages/tcl/8.3/lib
C:/devel/langages/tcl/8.3/lib/tk8.3
Now let's see how we can make Tcl aware of the vtktcl package. Two
different ways :
o) EITHER copy the pkgIndex.tcl file :
- locate your Tcl install directory (see auto_path) and the lib directory
(typically "C:/Program Files/Tcl/lib" or, in my example,
"C:/devel/langages/tcl/8.3/lib").
- create whatever directory inside the lib directory (for example
C":/Program Files/Tcl/lib/vtktcl").
- copy the pkgIndex.tcl file to this directory.
That's it. As the subdirectories inside the lib directory are browsed too,
the pkgIndex.tcl file will be found and interpreted. The major disadvantage
of this method is that you will have to keep this file up-to-date with
modifications made to the pkgIndex.tcl file provided by subsequent VTK
distribution (but most probably the VTK binary installer will copy the
pkgIndex.tcl file for you).
o) OR Modify the TCLLIBPATH :
This is the way to go :) Tcl provides a way for you to tell the Tcl
interpreter to search for pkgIndex.tcl files in any user-specified
directory. Just set the TCLLIBPATH environment variable to a set of
space-separated directories to search in. If you store the VTK sources on
your hard disk or if you use the CVS, add the directory holding the
pkgIndex.tcl file (Wrapping/Tcl). For example :
TCLLIBPATH=S:/src/vtk/vtknew/Wrapping/Tcl
Now check auto_path :
% puts $auto_path
S:/src/vtk/vtknew/Wrapping/Tcl C:/devel/langages/tcl/8.3/lib/tcl8.3
C:/devel/langages/tcl/8.3/lib C:/devel/langages/tcl/8.3/lib/tk8.3
This works (and was expected to :)).
Sebastien BARRE (sebastien at barre.nom.fr)
*****************************
Package :
*****************************
Wrapping\Tcl\pkgIndex.tcl :
# Tcl package index file, version 1.0
package ifneeded vtktcl 4.0 {
set ok 1
if {$tcl_platform(platform) == "windows"} {
# Try to load at least the Common part
if {[catch {
load vtkCommonTCL
} errormsg ]} {
puts $errormsg
set ok 0
} else {
# Try to load the other components
catch {
load vtkFilteringTCL
load vtkGraphicsTCL
load vtkHybridTCL
load vtkImagingTCL
load vtkIOTCL
load vtkParallelTCL
load vtkPatentedTCL
}
# Try to set the exit method of the interactor
if {![catch {load vtkRenderingTCL}] && \
[catch {
vtkWin32RenderWindowInteractor __temp_vtkwin32iren__
__temp_vtkwin32iren__ SetClassExitMethod exit
__temp_vtkwin32iren__ Delete
} errormsg ]} {
# warn the user, but do not prevent to provide the package
puts $errormsg
}
}
}
if {$ok} {
package provide vtktcl 4.0
}
}
More information about the vtk-developers
mailing list