Index: /trunk/geant4/visualization/OpenGL/Doxyfile
===================================================================
--- /trunk/geant4/visualization/OpenGL/Doxyfile	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/Doxyfile	(revision 529)
@@ -0,0 +1,1093 @@
+# Doxyfile 1.3.4
+
+# This file describes the settings to be used by the documentation system
+# doxygen (www.doxygen.org) for a project
+#
+# All text after a hash (#) is considered a comment and will be ignored
+# The format is:
+#       TAG = value [value, ...]
+# For lists items can also be appended using:
+#       TAG += value [value, ...]
+# Values that contain spaces should be placed between quotes (" ")
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+
+# The PROJECT_NAME tag is a single word (or a sequence of words surrounded 
+# by quotes) that should identify the project.
+
+PROJECT_NAME           = G4OpenGL
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number. 
+# This could be handy for archiving the generated documentation or 
+# if some version control system is used.
+
+PROJECT_NUMBER         = vis-V05-01-01
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) 
+# base path where the generated documentation will be put. 
+# If a relative path is entered, it will be relative to the location 
+# where doxygen was started. If left blank the current directory will be used.
+
+OUTPUT_DIRECTORY       = $(G4WORKDIR)/tmp/$(G4SYSTEM)/G4OpenGL
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all 
+# documentation generated by doxygen is written. Doxygen will use this 
+# information to generate all constant output in the proper language. 
+# The default language is English, other supported languages are: 
+# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, Dutch, 
+# Finnish, French, German, Greek, Hungarian, Italian, Japanese, Japanese-en 
+# (Japanese with English messages), Korean, Norwegian, Polish, Portuguese, 
+# Romanian, Russian, Serbian, Slovak, Slovene, Spanish, Swedish, and Ukrainian.
+
+OUTPUT_LANGUAGE        = English
+
+# This tag can be used to specify the encoding used in the generated output. 
+# The encoding is not always determined by the language that is chosen, 
+# but also whether or not the output is meant for Windows or non-Windows users. 
+# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES 
+# forces the Windows encoding (this is the default for the Windows binary), 
+# whereas setting the tag to NO uses a Unix-style encoding (the default for 
+# all platforms other than Windows).
+
+USE_WINDOWS_ENCODING   = NO
+
+# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will 
+# include brief member descriptions after the members that are listed in 
+# the file and class documentation (similar to JavaDoc). 
+# Set to NO to disable this.
+
+BRIEF_MEMBER_DESC      = YES
+
+# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend 
+# the brief description of a member or function before the detailed description. 
+# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the 
+# brief descriptions will be completely suppressed.
+
+REPEAT_BRIEF           = YES
+
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then 
+# Doxygen will generate a detailed section even if there is only a brief 
+# description.
+
+ALWAYS_DETAILED_SEC    = NO
+
+# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all inherited 
+# members of a class in the documentation of that class as if those members were 
+# ordinary class members. Constructors, destructors and assignment operators of 
+# the base classes will not be shown.
+
+INLINE_INHERITED_MEMB  = NO
+
+# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full 
+# path before files name in the file list and in the header files. If set 
+# to NO the shortest path that makes the file name unique will be used.
+
+FULL_PATH_NAMES        = NO
+
+# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag 
+# can be used to strip a user-defined part of the path. Stripping is 
+# only done if one of the specified strings matches the left-hand part of 
+# the path. It is allowed to use relative paths in the argument list.
+
+STRIP_FROM_PATH        = 
+
+# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter 
+# (but less readable) file names. This can be useful is your file systems 
+# doesn't support long names like on DOS, Mac, or CD-ROM.
+
+SHORT_NAMES            = NO
+
+# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen 
+# will interpret the first line (until the first dot) of a JavaDoc-style 
+# comment as the brief description. If set to NO, the JavaDoc 
+# comments will behave just like the Qt-style comments (thus requiring an 
+# explict @brief command for a brief description.
+
+JAVADOC_AUTOBRIEF      = NO
+
+# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen 
+# treat a multi-line C++ special comment block (i.e. a block of //! or /// 
+# comments) as a brief description. This used to be the default behaviour. 
+# The new default is to treat a multi-line C++ comment block as a detailed 
+# description. Set this tag to YES if you prefer the old behaviour instead.
+
+MULTILINE_CPP_IS_BRIEF = NO
+
+# If the DETAILS_AT_TOP tag is set to YES then Doxygen 
+# will output the detailed description near the top, like JavaDoc.
+# If set to NO, the detailed description appears after the member 
+# documentation.
+
+DETAILS_AT_TOP         = NO
+
+# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented 
+# member inherits the documentation from any documented member that it 
+# reimplements.
+
+INHERIT_DOCS           = YES
+
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC 
+# tag is set to YES, then doxygen will reuse the documentation of the first 
+# member in the group (if any) for the other members of the group. By default 
+# all members of a group must be documented explicitly.
+
+DISTRIBUTE_GROUP_DOC   = NO
+
+# The TAB_SIZE tag can be used to set the number of spaces in a tab. 
+# Doxygen uses this value to replace tabs by spaces in code fragments.
+
+TAB_SIZE               = 8
+
+# This tag can be used to specify a number of aliases that acts 
+# as commands in the documentation. An alias has the form "name=value". 
+# For example adding "sideeffect=\par Side Effects:\n" will allow you to 
+# put the command \sideeffect (or @sideeffect) in the documentation, which 
+# will result in a user-defined paragraph with heading "Side Effects:". 
+# You can put \n's in the value part of an alias to insert newlines.
+
+ALIASES                = 
+
+# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources 
+# only. Doxygen will then generate output that is more tailored for C. 
+# For instance, some of the names that are used will be different. The list 
+# of all members will be omitted, etc.
+
+OPTIMIZE_OUTPUT_FOR_C  = NO
+
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java sources 
+# only. Doxygen will then generate output that is more tailored for Java. 
+# For instance, namespaces will be presented as packages, qualified scopes 
+# will look different, etc.
+
+OPTIMIZE_OUTPUT_JAVA   = NO
+
+# Set the SUBGROUPING tag to YES (the default) to allow class member groups of 
+# the same type (for instance a group of public functions) to be put as a 
+# subgroup of that type (e.g. under the Public Functions section). Set it to 
+# NO to prevent subgrouping. Alternatively, this can be done per class using 
+# the \nosubgrouping command.
+
+SUBGROUPING            = YES
+
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+
+# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in 
+# documentation are documented, even if no documentation was available. 
+# Private class members and static file members will be hidden unless 
+# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
+
+EXTRACT_ALL            = YES
+
+# If the EXTRACT_PRIVATE tag is set to YES all private members of a class 
+# will be included in the documentation.
+
+EXTRACT_PRIVATE        = YES
+
+# If the EXTRACT_STATIC tag is set to YES all static members of a file 
+# will be included in the documentation.
+
+EXTRACT_STATIC         = YES
+
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) 
+# defined locally in source files will be included in the documentation. 
+# If set to NO only classes defined in header files are included.
+
+EXTRACT_LOCAL_CLASSES  = YES
+
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all 
+# undocumented members of documented classes, files or namespaces. 
+# If set to NO (the default) these members will be included in the 
+# various overviews, but no documentation section is generated. 
+# This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_MEMBERS     = NO
+
+# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all 
+# undocumented classes that are normally visible in the class hierarchy. 
+# If set to NO (the default) these classes will be included in the various 
+# overviews. This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_CLASSES     = NO
+
+# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all 
+# friend (class|struct|union) declarations. 
+# If set to NO (the default) these declarations will be included in the 
+# documentation.
+
+HIDE_FRIEND_COMPOUNDS  = NO
+
+# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any 
+# documentation blocks found inside the body of a function. 
+# If set to NO (the default) these blocks will be appended to the 
+# function's detailed documentation block.
+
+HIDE_IN_BODY_DOCS      = NO
+
+# The INTERNAL_DOCS tag determines if documentation 
+# that is typed after a \internal command is included. If the tag is set 
+# to NO (the default) then the documentation will be excluded. 
+# Set it to YES to include the internal documentation.
+
+INTERNAL_DOCS          = NO
+
+# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate 
+# file names in lower-case letters. If set to YES upper-case letters are also 
+# allowed. This is useful if you have classes or files whose names only differ 
+# in case and if your file system supports case sensitive file names. Windows 
+# users are advised to set this option to NO.
+
+CASE_SENSE_NAMES       = YES
+
+# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen 
+# will show members with their full class and namespace scopes in the 
+# documentation. If set to YES the scope will be hidden.
+
+HIDE_SCOPE_NAMES       = NO
+
+# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen 
+# will put a list of the files that are included by a file in the documentation 
+# of that file.
+
+SHOW_INCLUDE_FILES     = YES
+
+# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] 
+# is inserted in the documentation for inline members.
+
+INLINE_INFO            = YES
+
+# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen 
+# will sort the (detailed) documentation of file and class members 
+# alphabetically by member name. If set to NO the members will appear in 
+# declaration order.
+
+SORT_MEMBER_DOCS       = YES
+
+# The GENERATE_TODOLIST tag can be used to enable (YES) or 
+# disable (NO) the todo list. This list is created by putting \todo 
+# commands in the documentation.
+
+GENERATE_TODOLIST      = YES
+
+# The GENERATE_TESTLIST tag can be used to enable (YES) or 
+# disable (NO) the test list. This list is created by putting \test 
+# commands in the documentation.
+
+GENERATE_TESTLIST      = YES
+
+# The GENERATE_BUGLIST tag can be used to enable (YES) or 
+# disable (NO) the bug list. This list is created by putting \bug 
+# commands in the documentation.
+
+GENERATE_BUGLIST       = YES
+
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or 
+# disable (NO) the deprecated list. This list is created by putting 
+# \deprecated commands in the documentation.
+
+GENERATE_DEPRECATEDLIST= YES
+
+# The ENABLED_SECTIONS tag can be used to enable conditional 
+# documentation sections, marked by \if sectionname ... \endif.
+
+ENABLED_SECTIONS       = 
+
+# The MAX_INITIALIZER_LINES tag determines the maximum number of lines 
+# the initial value of a variable or define consists of for it to appear in 
+# the documentation. If the initializer consists of more lines than specified 
+# here it will be hidden. Use a value of 0 to hide initializers completely. 
+# The appearance of the initializer of individual variables and defines in the 
+# documentation can be controlled using \showinitializer or \hideinitializer 
+# command in the documentation regardless of this setting.
+
+MAX_INITIALIZER_LINES  = 30
+
+# Set the SHOW_USED_FILES tag to NO to disable the list of files generated 
+# at the bottom of the documentation of classes and structs. If set to YES the 
+# list will mention the files that were used to generate the documentation.
+
+SHOW_USED_FILES        = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+
+# The QUIET tag can be used to turn on/off the messages that are generated 
+# by doxygen. Possible values are YES and NO. If left blank NO is used.
+
+QUIET                  = YES
+
+# The WARNINGS tag can be used to turn on/off the warning messages that are 
+# generated by doxygen. Possible values are YES and NO. If left blank 
+# NO is used.
+
+WARNINGS               = YES
+
+# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings 
+# for undocumented members. If EXTRACT_ALL is set to YES then this flag will 
+# automatically be disabled.
+
+WARN_IF_UNDOCUMENTED   = YES
+
+# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for 
+# potential errors in the documentation, such as not documenting some 
+# parameters in a documented function, or documenting parameters that 
+# don't exist or using markup commands wrongly.
+
+WARN_IF_DOC_ERROR      = YES
+
+# The WARN_FORMAT tag determines the format of the warning messages that 
+# doxygen can produce. The string should contain the $file, $line, and $text 
+# tags, which will be replaced by the file and line number from which the 
+# warning originated and the warning text.
+
+WARN_FORMAT            = "$file:$line: $text"
+
+# The WARN_LOGFILE tag can be used to specify a file to which warning 
+# and error messages should be written. If left blank the output is written 
+# to stderr.
+
+WARN_LOGFILE           = 
+
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+
+# The INPUT tag can be used to specify the files and/or directories that contain 
+# documented source files. You may enter file names like "myfile.cpp" or 
+# directories like "/usr/src/myproject". Separate the files or directories 
+# with spaces.
+
+INPUT                  = include \
+                         src \
+                         ../management/include \
+                         ../management/src \
+                         ../modeling/include \
+                         ../modeling/src \
+                         ../../graphics_reps/include/G4VGraphicsScene.hh \
+                         ../../graphics_reps/include/G4VVisManager.hh \
+                         ../../graphics_reps/src/G4VVisManager.cc
+
+# If the value of the INPUT tag contains directories, you can use the 
+# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 
+# and *.h) to filter out the source-files in the directories. If left 
+# blank the following patterns are tested: 
+# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx *.hpp 
+# *.h++ *.idl *.odl *.cs *.php *.php3 *.inc
+
+FILE_PATTERNS          = 
+
+# The RECURSIVE tag can be used to turn specify whether or not subdirectories 
+# should be searched for input files as well. Possible values are YES and NO. 
+# If left blank NO is used.
+
+RECURSIVE              = NO
+
+# The EXCLUDE tag can be used to specify files and/or directories that should 
+# excluded from the INPUT source files. This way you can easily exclude a 
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+
+EXCLUDE                = 
+
+# The EXCLUDE_SYMLINKS tag can be used select whether or not files or directories 
+# that are symbolic links (a Unix filesystem feature) are excluded from the input.
+
+EXCLUDE_SYMLINKS       = NO
+
+# If the value of the INPUT tag contains directories, you can use the 
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude 
+# certain files from those directories.
+
+EXCLUDE_PATTERNS       = *Command*
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or 
+# directories that contain example code fragments that are included (see 
+# the \include command).
+
+EXAMPLE_PATH           = 
+
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the 
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 
+# and *.h) to filter out the source-files in the directories. If left 
+# blank all files are included.
+
+EXAMPLE_PATTERNS       = 
+
+# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be 
+# searched for input files to be used with the \include or \dontinclude 
+# commands irrespective of the value of the RECURSIVE tag. 
+# Possible values are YES and NO. If left blank NO is used.
+
+EXAMPLE_RECURSIVE      = NO
+
+# The IMAGE_PATH tag can be used to specify one or more files or 
+# directories that contain image that are included in the documentation (see 
+# the \image command).
+
+IMAGE_PATH             = 
+
+# The INPUT_FILTER tag can be used to specify a program that doxygen should 
+# invoke to filter for each input file. Doxygen will invoke the filter program 
+# by executing (via popen()) the command <filter> <input-file>, where <filter> 
+# is the value of the INPUT_FILTER tag, and <input-file> is the name of an 
+# input file. Doxygen will then use the output that the filter program writes 
+# to standard output.
+
+INPUT_FILTER           = 
+
+# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using 
+# INPUT_FILTER) will be used to filter the input files when producing source 
+# files to browse (i.e. when SOURCE_BROWSER is set to YES).
+
+FILTER_SOURCE_FILES    = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will 
+# be generated. Documented entities will be cross-referenced with these sources.
+
+SOURCE_BROWSER         = YES
+
+# Setting the INLINE_SOURCES tag to YES will include the body 
+# of functions and classes directly in the documentation.
+
+INLINE_SOURCES         = NO
+
+# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct 
+# doxygen to hide any special comment blocks from generated source code 
+# fragments. Normal C and C++ comments will always remain visible.
+
+STRIP_CODE_COMMENTS    = YES
+
+# If the REFERENCED_BY_RELATION tag is set to YES (the default) 
+# then for each documented function all documented 
+# functions referencing it will be listed.
+
+REFERENCED_BY_RELATION = YES
+
+# If the REFERENCES_RELATION tag is set to YES (the default) 
+# then for each documented function all documented entities 
+# called/used by that function will be listed.
+
+REFERENCES_RELATION    = YES
+
+# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen 
+# will generate a verbatim copy of the header file for each class for 
+# which an include is specified. Set to NO to disable this.
+
+VERBATIM_HEADERS       = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index 
+# of all compounds will be generated. Enable this if the project 
+# contains a lot of classes, structs, unions or interfaces.
+
+ALPHABETICAL_INDEX     = NO
+
+# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then 
+# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns 
+# in which this list will be split (can be a number in the range [1..20])
+
+COLS_IN_ALPHA_INDEX    = 5
+
+# In case all classes in a project start with a common prefix, all 
+# classes will be put under the same header in the alphabetical index. 
+# The IGNORE_PREFIX tag can be used to specify one or more prefixes that 
+# should be ignored while generating the index headers.
+
+IGNORE_PREFIX          = 
+
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_HTML tag is set to YES (the default) Doxygen will 
+# generate HTML output.
+
+GENERATE_HTML          = YES
+
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. 
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# put in front of it. If left blank `html' will be used as the default path.
+
+HTML_OUTPUT            = html
+
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for 
+# each generated HTML page (for example: .htm,.php,.asp). If it is left blank 
+# doxygen will generate files with .html extension.
+
+HTML_FILE_EXTENSION    = .html
+
+# The HTML_HEADER tag can be used to specify a personal HTML header for 
+# each generated HTML page. If it is left blank doxygen will generate a 
+# standard header.
+
+HTML_HEADER            = 
+
+# The HTML_FOOTER tag can be used to specify a personal HTML footer for 
+# each generated HTML page. If it is left blank doxygen will generate a 
+# standard footer.
+
+HTML_FOOTER            = 
+
+# The HTML_STYLESHEET tag can be used to specify a user-defined cascading 
+# style sheet that is used by each HTML page. It can be used to 
+# fine-tune the look of the HTML output. If the tag is left blank doxygen 
+# will generate a default style sheet
+
+HTML_STYLESHEET        = 
+
+# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, 
+# files or namespaces will be aligned in HTML using tables. If set to 
+# NO a bullet list will be used.
+
+HTML_ALIGN_MEMBERS     = YES
+
+# If the GENERATE_HTMLHELP tag is set to YES, additional index files 
+# will be generated that can be used as input for tools like the 
+# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) 
+# of the generated HTML documentation.
+
+GENERATE_HTMLHELP      = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can 
+# be used to specify the file name of the resulting .chm file. You 
+# can add a path in front of the file if the result should not be 
+# written to the html output dir.
+
+CHM_FILE               = 
+
+# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can 
+# be used to specify the location (absolute path including file name) of 
+# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run 
+# the HTML help compiler on the generated index.hhp.
+
+HHC_LOCATION           = 
+
+# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag 
+# controls if a separate .chi index file is generated (YES) or that 
+# it should be included in the master .chm file (NO).
+
+GENERATE_CHI           = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag 
+# controls whether a binary table of contents is generated (YES) or a 
+# normal table of contents (NO) in the .chm file.
+
+BINARY_TOC             = NO
+
+# The TOC_EXPAND flag can be set to YES to add extra items for group members 
+# to the contents of the HTML help documentation and to the tree view.
+
+TOC_EXPAND             = NO
+
+# The DISABLE_INDEX tag can be used to turn on/off the condensed index at 
+# top of each HTML page. The value NO (the default) enables the index and 
+# the value YES disables it.
+
+DISABLE_INDEX          = NO
+
+# This tag can be used to set the number of enum values (range [1..20]) 
+# that doxygen will group on one line in the generated HTML documentation.
+
+ENUM_VALUES_PER_LINE   = 4
+
+# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be
+# generated containing a tree-like index structure (just like the one that 
+# is generated for HTML Help). For this to work a browser that supports 
+# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, 
+# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are 
+# probably better off using the HTML help feature.
+
+GENERATE_TREEVIEW      = NO
+
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be 
+# used to set the initial width (in pixels) of the frame in which the tree 
+# is shown.
+
+TREEVIEW_WIDTH         = 250
+
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will 
+# generate Latex output.
+
+GENERATE_LATEX         = YES
+
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. 
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# put in front of it. If left blank `latex' will be used as the default path.
+
+LATEX_OUTPUT           = latex
+
+# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be 
+# invoked. If left blank `latex' will be used as the default command name.
+
+LATEX_CMD_NAME         = latex
+
+# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to 
+# generate index for LaTeX. If left blank `makeindex' will be used as the 
+# default command name.
+
+MAKEINDEX_CMD_NAME     = makeindex
+
+# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact 
+# LaTeX documents. This may be useful for small projects and may help to 
+# save some trees in general.
+
+COMPACT_LATEX          = NO
+
+# The PAPER_TYPE tag can be used to set the paper type that is used 
+# by the printer. Possible values are: a4, a4wide, letter, legal and 
+# executive. If left blank a4wide will be used.
+
+PAPER_TYPE             = a4wide
+
+# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX 
+# packages that should be included in the LaTeX output.
+
+EXTRA_PACKAGES         = 
+
+# The LATEX_HEADER tag can be used to specify a personal LaTeX header for 
+# the generated latex document. The header should contain everything until 
+# the first chapter. If it is left blank doxygen will generate a 
+# standard header. Notice: only use this tag if you know what you are doing!
+
+LATEX_HEADER           = 
+
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated 
+# is prepared for conversion to pdf (using ps2pdf). The pdf file will 
+# contain links (just like the HTML output) instead of page references 
+# This makes the output suitable for online browsing using a pdf viewer.
+
+PDF_HYPERLINKS         = NO
+
+# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of 
+# plain latex in the generated Makefile. Set this option to YES to get a 
+# higher quality PDF documentation.
+
+USE_PDFLATEX           = NO
+
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. 
+# command to the generated LaTeX files. This will instruct LaTeX to keep 
+# running if errors occur, instead of asking the user for help. 
+# This option is also used when generating formulas in HTML.
+
+LATEX_BATCHMODE        = NO
+
+# If LATEX_HIDE_INDICES is set to YES then doxygen will not 
+# include the index chapters (such as File Index, Compound Index, etc.) 
+# in the output.
+
+LATEX_HIDE_INDICES     = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output 
+# The RTF output is optimised for Word 97 and may not look very pretty with 
+# other RTF readers or editors.
+
+GENERATE_RTF           = NO
+
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. 
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# put in front of it. If left blank `rtf' will be used as the default path.
+
+RTF_OUTPUT             = rtf
+
+# If the COMPACT_RTF tag is set to YES Doxygen generates more compact 
+# RTF documents. This may be useful for small projects and may help to 
+# save some trees in general.
+
+COMPACT_RTF            = NO
+
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated 
+# will contain hyperlink fields. The RTF file will 
+# contain links (just like the HTML output) instead of page references. 
+# This makes the output suitable for online browsing using WORD or other 
+# programs which support those fields. 
+# Note: wordpad (write) and others do not support links.
+
+RTF_HYPERLINKS         = NO
+
+# Load stylesheet definitions from file. Syntax is similar to doxygen's 
+# config file, i.e. a series of assigments. You only have to provide 
+# replacements, missing definitions are set to their default value.
+
+RTF_STYLESHEET_FILE    = 
+
+# Set optional variables used in the generation of an rtf document. 
+# Syntax is similar to doxygen's config file.
+
+RTF_EXTENSIONS_FILE    = 
+
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_MAN tag is set to YES (the default) Doxygen will 
+# generate man pages
+
+GENERATE_MAN           = NO
+
+# The MAN_OUTPUT tag is used to specify where the man pages will be put. 
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# put in front of it. If left blank `man' will be used as the default path.
+
+MAN_OUTPUT             = man
+
+# The MAN_EXTENSION tag determines the extension that is added to 
+# the generated man pages (default is the subroutine's section .3)
+
+MAN_EXTENSION          = .3
+
+# If the MAN_LINKS tag is set to YES and Doxygen generates man output, 
+# then it will generate one additional man file for each entity 
+# documented in the real man page(s). These additional files 
+# only source the real man page, but without them the man command 
+# would be unable to find the correct page. The default is NO.
+
+MAN_LINKS              = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_XML tag is set to YES Doxygen will 
+# generate an XML file that captures the structure of 
+# the code including all documentation. Note that this 
+# feature is still experimental and incomplete at the 
+# moment.
+
+GENERATE_XML           = NO
+
+# The XML_OUTPUT tag is used to specify where the XML pages will be put. 
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# put in front of it. If left blank `xml' will be used as the default path.
+
+XML_OUTPUT             = xml
+
+# The XML_SCHEMA tag can be used to specify an XML schema, 
+# which can be used by a validating XML parser to check the 
+# syntax of the XML files.
+
+XML_SCHEMA             = 
+
+# The XML_DTD tag can be used to specify an XML DTD, 
+# which can be used by a validating XML parser to check the 
+# syntax of the XML files.
+
+XML_DTD                = 
+
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will 
+# generate an AutoGen Definitions (see autogen.sf.net) file 
+# that captures the structure of the code including all 
+# documentation. Note that this feature is still experimental 
+# and incomplete at the moment.
+
+GENERATE_AUTOGEN_DEF   = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_PERLMOD tag is set to YES Doxygen will 
+# generate a Perl module file that captures the structure of 
+# the code including all documentation. Note that this 
+# feature is still experimental and incomplete at the 
+# moment.
+
+GENERATE_PERLMOD       = NO
+
+# If the PERLMOD_LATEX tag is set to YES Doxygen will generate 
+# the necessary Makefile rules, Perl scripts and LaTeX code to be able 
+# to generate PDF and DVI output from the Perl module output.
+
+PERLMOD_LATEX          = NO
+
+# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be 
+# nicely formatted so it can be parsed by a human reader.  This is useful 
+# if you want to understand what is going on.  On the other hand, if this 
+# tag is set to NO the size of the Perl module output will be much smaller 
+# and Perl will parse it just the same.
+
+PERLMOD_PRETTY         = YES
+
+# The names of the make variables in the generated doxyrules.make file 
+# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. 
+# This is useful so different doxyrules.make files included by the same 
+# Makefile don't overwrite each other's variables.
+
+PERLMOD_MAKEVAR_PREFIX = 
+
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor   
+#---------------------------------------------------------------------------
+
+# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will 
+# evaluate all C-preprocessor directives found in the sources and include 
+# files.
+
+ENABLE_PREPROCESSING   = YES
+
+# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro 
+# names in the source code. If set to NO (the default) only conditional 
+# compilation will be performed. Macro expansion can be done in a controlled 
+# way by setting EXPAND_ONLY_PREDEF to YES.
+
+MACRO_EXPANSION        = NO
+
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES 
+# then the macro expansion is limited to the macros specified with the 
+# PREDEFINED and EXPAND_AS_PREDEFINED tags.
+
+EXPAND_ONLY_PREDEF     = NO
+
+# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files 
+# in the INCLUDE_PATH (see below) will be search if a #include is found.
+
+SEARCH_INCLUDES        = YES
+
+# The INCLUDE_PATH tag can be used to specify one or more directories that 
+# contain include files that are not input files but should be processed by 
+# the preprocessor.
+
+INCLUDE_PATH           = 
+
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard 
+# patterns (like *.h and *.hpp) to filter out the header-files in the 
+# directories. If left blank, the patterns specified with FILE_PATTERNS will 
+# be used.
+
+INCLUDE_FILE_PATTERNS  = 
+
+# The PREDEFINED tag can be used to specify one or more macro names that 
+# are defined before the preprocessor is started (similar to the -D option of 
+# gcc). The argument of the tag is a list of macros of the form: name 
+# or name=definition (no spaces). If the definition and the = are 
+# omitted =1 is assumed.
+
+PREDEFINED             = G4VIS_USE_OPENGL=1 \
+                         G4VIS_USE_OPENGLX=1 \
+                         G4VIS_USE_OPENGLXM=1 \
+                         G4VIS_USE_OPENGLWIN32=1 \
+                         G4VIS_BUILD_OPENGL_DRIVER=1 \
+                         G4VIS_BUILD_OPENGLX_DRIVER=1 \
+                         G4VIS_BUILD_OPENGLXM_DRIVER=1 \
+                         G4VIS_BUILD_OPENGLWIN32_DRIVER=1
+
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then 
+# this tag can be used to specify a list of macro names that should be expanded. 
+# The macro definition that is found in the sources will be used. 
+# Use the PREDEFINED tag if you want to use a different macro definition.
+
+EXPAND_AS_DEFINED      = 
+
+# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then 
+# doxygen's preprocessor will remove all function-like macros that are alone 
+# on a line, have an all uppercase name, and do not end with a semicolon. Such 
+# function macros are typically used for boiler-plate code, and will confuse the 
+# parser if not removed.
+
+SKIP_FUNCTION_MACROS   = YES
+
+#---------------------------------------------------------------------------
+# Configuration::addtions related to external references   
+#---------------------------------------------------------------------------
+
+# The TAGFILES option can be used to specify one or more tagfiles. 
+# Optionally an initial location of the external documentation 
+# can be added for each tagfile. The format of a tag file without 
+# this location is as follows: 
+#   TAGFILES = file1 file2 ... 
+# Adding location for the tag files is done as follows: 
+#   TAGFILES = file1=loc1 "file2 = loc2" ... 
+# where "loc1" and "loc2" can be relative or absolute paths or 
+# URLs. If a location is present for each tag, the installdox tool 
+# does not have to be run to correct the links.
+# Note that each tag file must have a unique name
+# (where the name does NOT include the path)
+# If a tag file is not located in the directory in which doxygen 
+# is run, you must also specify the path to the tagfile here.
+
+TAGFILES               = 
+
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create 
+# a tag file that is based on the input files it reads.
+
+GENERATE_TAGFILE       = 
+
+# If the ALLEXTERNALS tag is set to YES all external classes will be listed 
+# in the class index. If set to NO only the inherited external classes 
+# will be listed.
+
+ALLEXTERNALS           = NO
+
+# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed 
+# in the modules index. If set to NO, only the current project's groups will 
+# be listed.
+
+EXTERNAL_GROUPS        = YES
+
+# The PERL_PATH should be the absolute path and name of the perl script 
+# interpreter (i.e. the result of `which perl').
+
+PERL_PATH              = /usr/bin/perl
+
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool   
+#---------------------------------------------------------------------------
+
+# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will 
+# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base or 
+# super classes. Setting the tag to NO turns the diagrams off. Note that this 
+# option is superceded by the HAVE_DOT option below. This is only a fallback. It is 
+# recommended to install and use dot, since it yields more powerful graphs.
+
+CLASS_DIAGRAMS         = YES
+
+# If set to YES, the inheritance and collaboration graphs will hide 
+# inheritance and usage relations if the target is undocumented 
+# or is not a class.
+
+HIDE_UNDOC_RELATIONS   = YES
+
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is 
+# available from the path. This tool is part of Graphviz, a graph visualization 
+# toolkit from AT&T and Lucent Bell Labs. The other options in this section 
+# have no effect if this option is set to NO (the default)
+
+HAVE_DOT               = NO
+
+# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen 
+# will generate a graph for each documented class showing the direct and 
+# indirect inheritance relations. Setting this tag to YES will force the 
+# the CLASS_DIAGRAMS tag to NO.
+
+CLASS_GRAPH            = YES
+
+# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen 
+# will generate a graph for each documented class showing the direct and 
+# indirect implementation dependencies (inheritance, containment, and 
+# class references variables) of the class with other documented classes.
+
+COLLABORATION_GRAPH    = YES
+
+# If the UML_LOOK tag is set to YES doxygen will generate inheritance and 
+# collaboration diagrams in a style similiar to the OMG's Unified Modeling 
+# Language.
+
+UML_LOOK               = NO
+
+# If set to YES, the inheritance and collaboration graphs will show the 
+# relations between templates and their instances.
+
+TEMPLATE_RELATIONS     = YES
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT 
+# tags are set to YES then doxygen will generate a graph for each documented 
+# file showing the direct and indirect include dependencies of the file with 
+# other documented files.
+
+INCLUDE_GRAPH          = YES
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and 
+# HAVE_DOT tags are set to YES then doxygen will generate a graph for each 
+# documented header file showing the documented files that directly or 
+# indirectly include this file.
+
+INCLUDED_BY_GRAPH      = YES
+
+# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will 
+# generate a call dependency graph for every global function or class method. 
+# Note that enabling this option will significantly increase the time of a run. 
+# So in most cases it will be better to enable call graphs for selected 
+# functions only using the \callgraph command.
+
+CALL_GRAPH             = NO
+
+# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen 
+# will graphical hierarchy of all classes instead of a textual one.
+
+GRAPHICAL_HIERARCHY    = YES
+
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images 
+# generated by dot. Possible values are png, jpg, or gif
+# If left blank png will be used.
+
+DOT_IMAGE_FORMAT       = gif
+
+# The tag DOT_PATH can be used to specify the path where the dot tool can be 
+# found. If left blank, it is assumed the dot tool can be found on the path.
+
+DOT_PATH               = 
+
+# The DOTFILE_DIRS tag can be used to specify one or more directories that 
+# contain dot files that are included in the documentation (see the 
+# \dotfile command).
+
+DOTFILE_DIRS           = 
+
+# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width 
+# (in pixels) of the graphs generated by dot. If a graph becomes larger than 
+# this value, doxygen will try to truncate the graph, so that it fits within 
+# the specified constraint. Beware that most browsers cannot cope with very 
+# large images.
+
+MAX_DOT_GRAPH_WIDTH    = 1024
+
+# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height 
+# (in pixels) of the graphs generated by dot. If a graph becomes larger than 
+# this value, doxygen will try to truncate the graph, so that it fits within 
+# the specified constraint. Beware that most browsers cannot cope with very 
+# large images.
+
+MAX_DOT_GRAPH_HEIGHT   = 1024
+
+# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the 
+# graphs generated by dot. A depth value of 3 means that only nodes reachable 
+# from the root by following a path via at most 3 edges will be shown. Nodes that 
+# lay further from the root node will be omitted. Note that setting this option to 
+# 1 or 2 may greatly reduce the computation time needed for large code bases. Also 
+# note that a graph may be further truncated if the graph's image dimensions are 
+# not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH and MAX_DOT_GRAPH_HEIGHT). 
+# If 0 is used for the depth value (the default), the graph is not depth-constrained.
+
+MAX_DOT_GRAPH_DEPTH    = 0
+
+# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will 
+# generate a legend page explaining the meaning of the various boxes and 
+# arrows in the dot generated graphs.
+
+GENERATE_LEGEND        = YES
+
+# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will 
+# remove the intermediate dot files that are used to generate 
+# the various graphs.
+
+DOT_CLEANUP            = YES
+
+#---------------------------------------------------------------------------
+# Configuration::addtions related to the search engine   
+#---------------------------------------------------------------------------
+
+# The SEARCHENGINE tag specifies whether or not a search engine should be 
+# used. If set to NO the values of all tags below this one will be ignored.
+
+SEARCHENGINE           = NO
Index: /trunk/geant4/visualization/OpenGL/GNUmakefile
===================================================================
--- /trunk/geant4/visualization/OpenGL/GNUmakefile	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/GNUmakefile	(revision 529)
@@ -0,0 +1,33 @@
+# $Id: GNUmakefile,v 1.6 2004/06/03 11:40:13 gcosmo Exp $
+
+name := G4OpenGL
+
+ifndef G4INSTALL
+  G4INSTALL = ../../..
+endif
+
+GLOBLIBS  = libG4vis_management.lib libG4modeling.lib
+GLOBLIBS += libG4interfaces.lib libG4run.lib libG4event.lib
+GLOBLIBS += libG4tracking.lib libG4processes.lib libG4digits_hits.lib
+GLOBLIBS += libG4track.lib libG4particles.lib libG4geometry.lib
+GLOBLIBS += libG4materials.lib libG4graphics_reps.lib
+GLOBLIBS += libG4intercoms.lib libG4global.lib
+
+include $(G4INSTALL)/config/architecture.gmk
+include $(G4INSTALL)/config/G4VIS_BUILD.gmk
+include $(G4INSTALL)/config/interactivity.gmk
+
+CPPFLAGS += -I$(G4BASE)/visualization/management/include
+CPPFLAGS += -I$(G4BASE)/visualization/modeling/include
+CPPFLAGS += -I$(G4BASE)/global/management/include
+CPPFLAGS += -I$(G4BASE)/global/HEPGeometry/include
+CPPFLAGS += -I$(G4BASE)/geometry/solids/CSG/include
+CPPFLAGS += -I$(G4BASE)/geometry/solids/specific/include
+CPPFLAGS += -I$(G4BASE)/graphics_reps/include
+CPPFLAGS += -I$(G4BASE)/geometry/management/include
+CPPFLAGS += -I$(G4BASE)/intercoms/include
+CPPFLAGS += -I$(G4BASE)/interfaces/common/include
+CPPFLAGS += -I$(G4BASE)/tracking/include
+CPPFLAGS += -I$(G4BASE)/digits_hits/hits/include
+
+include $(G4INSTALL)/config/common.gmk
Index: /trunk/geant4/visualization/OpenGL/History
===================================================================
--- /trunk/geant4/visualization/OpenGL/History	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/History	(revision 529)
@@ -0,0 +1,466 @@
+$Id: History,v 1.82 2006/11/21 16:24:58 allison Exp $
+-------------------------------------------------------------------
+
+     =========================================================
+     Geant4 - an Object-Oriented Toolkit for Simulation in HEP
+     =========================================================
+
+                      Category History file
+                      ---------------------
+This file should be used by G4 developers and category coordinators
+to briefly summarize all major modifications introduced in the code
+and keep track of all category-tags.
+It DOES NOT substitute the  CVS log-message one should put at every
+committal in the CVS repository !
+
+     ----------------------------------------------------------
+     * Reverse chronological order (last date on top), please *
+     ----------------------------------------------------------
+
+History file for visualization/OpenGL
+-------------------------------------
+
+21st November 2006  John Allison  (opengl-V08-01-09)
+- Fixed compiler warnings.
+
+1st November 2006  John Allison  (opengl-V08-01-08)
+- Replace /vis/oglx/set/printEPS by /vis/oglx/printEPS.  The new command
+  actually initiates a print, rather than set a flag for printing.
+
+24th October 2006  John Allison  (opengl-V08-01-07)
+- G4OpenGLStoredViewer.cc: Calculate light front horizon properly.
+- G4OpenGLViewerMessenger.cc: Make refresh depend on auto-refresh.
+
+19th September 2006  John Allison  (opengl-V08-01-06)
+- Added time origin for light front.
+- Added /vis/ogl/set/transparency.
+- G4OpenGLStoredViewer.cc: Bug fix in time range acceptance.
+
+4th September 2006  John Allison  (opengl-V08-01-05)
+- Implement cutaways.
+- Immediate mode: G4OpenGLImmediateSceneHandler.cc: Flush all
+  primitives (see detector being drawn).
+- /vis/oglx/set/printEPS: change parameter default to true.
+
+30th August 2006  John Allison  (opengl-V08-01-04)
+- G4OpenGLSceneHandler:
+  o Implemented line width.
+  o Switched off back face culling when clipping so that the inside of
+    volumes can be seen.
+  o Added CreateSection/CutawayPolyhedron to exploit generic
+    sectioning (DCUT) and cutaways.  Currently not activated due to
+    instabilities in BooleanProcessor.  Local sectioning still active
+    but broken (at least on Mac) due to apparent change in effect of
+    clipping planes (polyhedron edges not reconstructed).
+  o Rationalised calculation of marker size.
+- G4OpenGLStoredSceneHandler:
+  o Fixed bug due to recursive calls of AddPrimitive (polymarkers -> markers).
+  o Pick up time range from G4VisAttributes.
+- G4OpenGLViewer(Messenger):
+  o Added position and colour to /vis/ogl/set/displayHeadTime.
+  o Added /vis/ogl/set/displayLightFront.
+- G4OpenGLStoredViewer.cc:
+  o Rationalised CompareForKernelVisit.  (Local sectioning still active.)
+  o Added position and colour to DisplayHeadTime.
+  o Added DisplayLightFront.
+  
+16th August 2006  John Allison  (opengl-V08-01-03)
+- Corrected Solaris compilation error.
+- Added /vis/ogl/set/fade and displayHeadTime.
+
+14th August 2006  John Allison  (opengl-V08-01-02)
+- Needs visman-V08-01-02.
+- G4OpenGLStored: Implemented display-by-time.  Only available in
+  stored mode at present.  Only implemented for circle, square,
+  polyline and polymarker at present, enough for currently available
+  trajectory models.  Time is communicated via G4AttValues.
+- Added G4OpenGLViewerMessenger.
+- Added /vis/ogl/set/startTime and endTime of displayed objects.
+- All factories: Instantiated G4OpenGLViewerMessenger.
+- G4OpenGLViewer: Added fStart/EndTime.
+- G4OpenGLXViewer.cc: Graceful recovery from unexpected tokens in
+  spewPrimitiveEPS and spewSortedFeedback.
+
+17th July  John Allison  (opengl-V08-01-01)
+- Added /vis/oglx/set/printEPS (prints eps file on every update).
+
+3rd July 2006  John Allison  (opengl-V08-01-00)
+- Elimination of redundant variable doublebuffer and implementation of
+  FinishView in all viewers.
+
+30th May 2006  Joseph Perl  (opengl-V08-00-08)
+- G4OpenGLImmediateWin32Viewer: Removed tests on doublebuffer since that
+  variable seems to have random behavior and should be assumed false for
+  this viewer.
+
+29th May 2006  Joseph Perl  (opengl-V08-00-07)
+- G4OpenGLWin32Viewer, G4OpenGLImmediateWin32Viewer, G4OpenGLStoredWin32Viewer:
+  Removed common FinishView and instead made separate FinishView for the two different
+  versions of this viewer since each wants a different buffer swapping behaviour.
+
+12th May 2006  John Allison  (opengl-V08-00-06)
+- G4OpenGLWin32Viewer: Fixed buffer swapping behaviour.
+
+28th April 2006  John Allison  (opengl-V08-00-05 - needs visman-V08-00-14)
+- G4OpenGLStoredX/Xm/Win32Viewer.cc: Fixed buffer swapping problem when
+  recomputing transients.
+
+24th April 2006  John Allison  (opengl-V08-00-04)
+- Fixed compilation problem on Windows.
+
+19th April 2006  John Allison  (opengl-V08-00-03)
+- G4OpenGLSceneHandler, G4OpenGLStoredSceneHandler and
+  G4OpenGLImmediateSceneHandler:
+  o Implemented Begin/EndPrimitives2D (needs visman-V08-00-12 and
+    greps-V08-00-02).
+  o Migrated to direct access to G4PhysicalVolumeModel.
+- G4OpenGLStoredX/Xm/Win32Viewer.cc: bug fix for conditional drawing
+  of display lists in DrawView.
+
+14th March 2006  John Allison  (opengl-V08-00-02)
+- Refined display list building and re-drawing algorithm.
+  o G4OpenGLStoredSceneHandler::EndModeling: Changed to GL_COMPILE_AND_EXECUTE.
+  o Avoided unnecessary re-execution in DrawView (X, Xm and Win32).
+- G4OpenGLStoredSceneHandler::RequestPrimitives: Refined display list
+  re-use algorithm.  In test19 with global culling off, numbers of
+  display lists used are:
+  o 191  No re-use:
+  o  73  Before this change: re-use except replicas (includes parameterised).
+  o  33  After this change: re-use except parameterised and replicas in radius.
+
+26th January 2006  John Allison  (opengl-V08-00-01)
+- Coworks with visman-V08-00-04 (removed fModified).
+- Removed references to fModified.
+- Tidying: Removed unnecessary ClearView.
+- G4OpenGLSceneHandler.cc: Added some (commented out) code for
+  possible future implementation of 2D drawing.
+- G4OpenGLXViewer.cc: Improved exception printing.
+
+11th January 2006  John Allison  (opengl-V08-00-00)
+- Improved efficiency: all DrawView's:
+  o Don't call ClearView.
+  o Set flag so SetView will not be called in ProcessView.
+  o Leave background colour to ClearView.
+- Used dynamic_cast<G4OpenGLViewer*>, no need for G4OpenGLViewerDataStore.
+- G4OpenGLXmViewerMessenger: Made a smart singleton; interrogates vis manager
+  for current viewer.
+
+24th November 2005  John Allison  (opengl-V07-01-09)
+- Protected G4OpenGLXmViewerMessenger with #ifdef G4VIS_BUILD_OPENGLXM_DRIVER.
+
+22nd November 2005  John Allison  (opengl-V07-01-08)
+- Added G4OpenGLXmViewerMessenger.
+- Corrected text position.
+- Made depth test for polyhedron GL_LEQUAL (slightly dominant).
+
+17th November 2005  Gabriele Cosmo
+- Fixed settings of background style for WIN32 viewers.
+
+13th November 2005  John Allison  (opengl-V07-01-07)
+- Implemented X-Window-style geometry hints in G4OpenGLXViewer.
+
+13th October 2005  John Allison  (opengl-V07-01-06)
+- Allowed any colour background.
+- Implemented non-uniform scaling.
+- Migration to <sstream>.
+
+29th September 2005  John Allison  (opengl-V07-01-05)
+- Added G4OpenGLViewerDataStore to facilitate access of viewer data by
+  scene handler.
+- Re-implemented transparency button in OpenGLXm.
+
+13th September 2005  John Allison  (opengl-V07-01-04 - needs visman-V07-01-02)
+- Implemented white background for all OGL viewers.
+- G4OpenGLSceneHandler.cc:
+  o Fixed hidden line removal (bug introduced in opengl-V07-01-02).
+  o Fixed treatment of triangular polygons for drawing of auxiliary/soft lines.
+  o Corrected GetTextColour(text).
+  o Corrected GetColour(polyhedron).
+
+5th September 2005  John Allison  (opengl-V07-01-03)
+- Bug fix: stored transparent objects were being lost.
+
+2nd September 2005  John Allison  (opengl-V07-01-02 - needs visman-V07-01-01)
+- Bug fix: edgeflags problem introduced with smooth shading in
+  opengl-V07-01-00.
+- Implementation of a "better algorithm" for the rendering of
+  transparent polyhedron objects.  It renders all opaque objects
+  first, then renders the transparent objects with the depth buffer in
+  read-only mode (see OpenGL Programming Guide).  It uses the new
+  facility in G4VSceneHandler::ProcessScene for an optional second pass
+  of the run-duration models in the scene.  Note this algorithm is
+  still only an approximation.  It will still give the wrong blended
+  colour if two transparent objects are rendered front first.  For
+  nested transparent objects, this is unfortunate, because
+  G4PhysicalVolumeModel traverses Geant4's mother-daughter hierarchy
+  in such a way that mothers come first.  Also, there is no guaranteed
+  relationship between the order of rendering and the depth of two
+  transparent objects if they are at the same level or in different
+  branches of the hierarchy.  Still, the only error will be an
+  incorrect colour - the objects will still give the appearance of
+  transparency, so it's a pretty good algorithm.  (An even better
+  algorithm would be to attempt to render the facets in depth order,
+  deepest first.  But how do you calculate the depth - centre of area,
+  deepest corner?  One can still imagine pathalogical cases that would
+  sometimes give the wrong colour.  Also, for stored mode, the order
+  is fixed in a display list so when the user rotates the view, one
+  would lose the depth ordering.  I think we have to accept that
+  blending in OpenGL is only ever an approximation.  For accurate
+  blending, use RayTracer.)
+
+28th August 2005  John Allison  (opengl-V07-01-01)
+- Half-way implementation of rendering of transparent polyhedron
+  objects.  In this implementation, no account is taken of the order
+  of rendering.  Transparent objects are rendered with depth testing
+  off so that objects behind can still be seen.  But this means that
+  opaque objects in front do not obscure them - and they jolly well
+  should!  A better algorithm is to render all opaque objects first,
+  then render the transparent objects with the depth buffer in
+  read-only mode (see OpenGL Programming Guide).  This is going to
+  take a little more thought - see opengl-V07-01-02.
+
+20th July 2005  John Allison  (opengl-V07-01-00)
+- Introduced smooth shading, taking advantage of hitherto un-noticed
+  feature of HepPolyhedron::GetNextFacet that calculates the normals
+  at each vertex so that curved surfaces are rendered more
+  realistically (Gouraud shading).
+- G4OpenGLImmediateSceneHandler.cc: Removed unnecessary #include's.
+- G4OpenGLXmViewer.cc: Fixed to use window size hints.  This changes
+  the default window size.  It used to be 400x400, hardcoded in
+  G4OpenGLXmViewer.cc, but now it picks up the
+  G4ViewParameters::GetWindowSizeHintX/Y, which defaults to 600x600.
+  The user may change it on the command line, e.g:
+    /vis/open OGLSXm 500
+  or
+    /vis/viewer/create ! ! 500
+
+30th May 2005  John Allison  (opengl-V07-00-03)
+- Fixed compilation problem in OpenGL on SUN.  (Replaced multimap by
+  map of vectors in G4OpenGLFontBaseStore.)
+
+4th May 2005  John Allison  (opengl-V07-00-02)
+- Restored sequence Set/Clear/DrawView in ClearTransientStore.  (It
+  was taken out to prevent recursive calling, but that seems to be OK,
+  and it is needed to implement refresh at end of event/run.)
+
+22nd April 2005  John Allison  (opengl-V07-00-01)
+- Rationalised work of opengl-V07-00-00.  Functionality unchanged.
+  o G4OpenGLViewer.hh: Created virtual void CreateFontLists(){}.
+  o In all concrete viewers, added call to CreateFontLists().
+  o Moved font code for X to G4OpenGLXViewer::CreateFontLists().
+  o There is no longer a need to implement in the XmViewer, since it
+    now inherits.  Thus the font code now only appears once for X.
+  o Awaiting implementation for WIN32.
+
+17th April 2005  John Allison  (opengl-V07-00-00)
+- Based on vis-V07-00-13.
+- Implemented text for X-Windows viewers.  Uses glXUseXFont, which
+  creates display lists for nominated fonts.  Simple-minded scheme in
+  which each viewer creates its own font display lists for a variety
+  of sizes, which are accessed by the scene handler through a new
+  class, G4OpenGLFontBaseStore.  Affected methods:
+    G4OpenGLXViewer::CreateMainWindow()
+    G4OpenGLXmViewer::CreateMainWindow()
+    G4OpenGLSceneHandler::AddPrimitive (const G4Text& text)
+
+18th November 2004  John Allison  (opengl-V06-02-07)
+- Removed redundant fLastVP from G4OpenGLStoredSceneHandler.
+
+15th November 2004  Guy Barrand
+- G4OpenGLWin32Viewer::ShowView : glFlush was not sufficient 
+  to see trajectories (for example with N03). Correct so that
+  ShowView do a FinishView that does : glFlush, wglSwapBuffer
+  and empty the Windows message queue.
+
+22nd September 2004  John Allison  (opengl-V06-02-06)
+- doxygen output to tmp area.
+- Trap non-regular polyhedrons.
+
+13th September 2004  Gabriele Cosmo  (opengl-V06-02-05)
+- G4OpenGLTransform3D.cc: simplified implementation for GetMatrix()
+  to allow for porting on CLHEP-1.9.X series.
+
+23rd July 2004  John Allison
+- Draws auxiliary edges if required.
+- Added auxiliary edge button.
+
+16th July 2004  John Allison  (opengl-V06-02-04)
+- Refinements to hidden line, hidden surface removal.
+
+14th July 2004  John Allison  (opengl-V06-02-03)
+- Removed superfluous #include "G4VisManager.hh" from G4OpenGLXmViewer.cc.
+
+13th July 2004  John Allison  (opengl-V06-02-02)
+- Hidden line *and* hidden surface removal now works.
+
+9th July 2004  John Allison  (opengl-V06-02-01)
+- Fixed long-standing problem with hidden line removal.
+- Improved messages on failure to get visual.
+- Added GLX_STENCIL_SIZE explicit request to visual attributes - most
+  systems provided by default anyway, so no effect.
+
+1st July 2004  John Allison  (opengl-V06-02-00)
+- Rationalised G4OpenGLSceneHandler ready for hidden line removal.
+- Bug fix in G4OpenGLXmPanningCallbacks.cc for dolly control.
+
+18th June 2004  Gunter Folger (geant4-06-02)
+9th June 2004  Gabriele Cosmo  (vis-V06-01-03)
+7th June 2004  Gabriele Cosmo  (vis-V06-01-02)
+- GNUmakefile and disclaimer changes - see visualization/History.
+
+9th April 2004  John Allison  (vis-V06-01-01 + interfaces-V06-01-00)
+- Tagged OpenGL as below.  Joint with interfaces-V06-01-00.
+
+7th April 2004  Guy Barrand
+- visualization/OpenGL/* : use the G4OpenGL.hh file.
+- Added : visualization/OpenGL/include/G4OpenGL.hh to encapsulate
+  the include of gl/gl.h and gl/glu.h that may be platform dependant.
+  It permits to rm some #ifdef WIN32 spread in the code. It opens also
+  the way to the usage of the Apple OpenGL on a Mac.
+
+17th February 2004  John Allison  (opengl-V06-00-00)
+- Fixed bug #581: wrong order of statements in
+  G4OpenGLXViewer::~G4OpenGLXViewer (see bug report).
+
+4th October 2003  Gabriele Cosmo  (vis-V05-02-01)
+- GNUmakefile:
+  o replaced "digits+hits" with "digits_hits".
+- Coworks with "geometry-V05-02-00" and "digits_hits-V05-02-00".
+
+22nd September 2003  John Allison  (vis-V05-02-00, greps-V05-02-00)
+- Cosmetic change to regularise names:
+  o changed _Feedback3Dcolo to G4OpenGLXViewerFeedback3Dcolor.
+  o changed _DepthIndex to G4OpenGLXViewerDepthIndex.
+
+23rd June 2003  Guy Barrand  (opengl-V05-01-02)
+- Commit a first implementation of G4OpenGLWin32Viewer.
+
+10th June 2003  Gabriele Cosmo  (opengl-V05-01-01)
+- More fixes for warnings in viewers classes.
+- Added inclusion of <windows.h> for WIN32 platforms when GL headers
+  are included.
+
+05th June 2003  Gabriele Cosmo  (opengl-V05-01-00)
+- Fixes for porting compilation on WIN32:
+  o G4OpenGLWin32Viewer[.hh.cc]: removed inclusion of <GL/glx.h>.
+  o G4OpenGLViewer.cc: replaced local variables near/far with pnear/pfar
+    since declared 'obsolete' in WIN32 platforms.
+
+27th November 2002  John Allison  (vis-V04-01-08)
+- Improved algorithm of CompareForKernelVisit.
+
+11th November 2002  John Allison  (opengl-V04-01-02)
+- Corrected inclusion of G4OpenGLXViewer #ifdef X_DRIVER.
+- Added G4OpenGLSceneHandler::AddThis for trajectories and hits - simply
+  call default but there as a marker and encourager.
+- Added tracking and digits+hits/hits to GNUmakefile.
+
+16th October 2002  John Allison  (opengl-V04-01-01)
+- Fix for WIN32.  Now compiles but viewer not implemented.
+
+24th June 2002  John Allison  (opengl-V04-01-00)
+- Further cosmetic changes in G4OpenGLXViewer.cc for DEC compiler.
+
+10th June 2002  John Allison  (opengl-V04-00-03)
+- Cosmetic changes for SUN-CC in G4OpenGLXmConvenienceRoutines.cc.
+
+6th June 2002  John Allison  (opengl-V04-00-02)
+- Cosmetic changes for GNU compiler in G4OpenGLXViewer.cc.
+
+23rd February 2002  John Allison  (opengl-V04-00-01)
+- Changes to encourage compilation on Windows in preparation for
+  implementation of G4OpenGLWin32Viewer.  Removed spurious includes of
+  glx.h, unistd.h and assert.h.
+
+24th August 2001  John Allison  (vis-V03-02-13)
+- Limited the printing of warnings in
+  G4OpenGLSceneHandler::AddPrimitive (const G4Text& text).
+
+14th August 2001  John Allison  (vis-V03-02-11)
+- Improved KernelVisitDecision.
+- Fixed a few small bugs in multiple "stored" viewers, but see next item.
+- There's an outstanding bug in OpenGL Stored.  If there is more than
+  one viewer controlled by a scene handler, after a ClearStore on the
+  scene handler, e.g., with /vis/scene/notifyHandlers, the first
+  viewer to get refreshed should trigger the display list rebuild, but
+  the second need not.  However, when the second viewer's turn comes,
+  the display lists are there, and are called, e.g.,
+  G4OpenGLStoredXViewer::DrawView calls
+  G4OpenGLStoredViewer::DrawDisplayLists that calls glCallList, but
+  nothing appears on the screen.  To overcome this there is some
+  temporary code in G4VViewer::NeedKernelVisit which marks *all*
+  viewers to force a rebuild.  To see the symptoms, comment out that
+  temporary code and issue these commands:
+    /vis/verbose c
+    /control/verbose 2
+    /vis/scene/create
+    /vis/scene/add/volume
+    /vis/sceneHandler/create OGLSX
+    /vis/viewer/create ! ! 1
+    /run/beamOn
+    /vis/viewer/create ! ! 1
+    /vis/viewer/select viewer-0
+    /vis/viewer/viewpointThetaPhi 20 20
+    /vis/viewer/select viewer-1
+    /vis/viewer/viewpointThetaPhi 40 40
+    /vis/viewer/set/style surface
+    /vis/viewer/refresh
+    /vis/viewer/select viewer-0
+    /vis/viewer/refresh
+    /vis/viewer/select viewer-1
+    /vis/viewer/set/style wireframe
+    /vis/scene/notifyHandlers
+  You may have to do this too:
+    /vis/viewer/select viewer-0
+    /vis/scene/notifyHandlers
+  One of the viewers is empty.  Curious!!
+
+9th August 2001  John Allison  (vis-V03-02-10-00)
+- Implemented G4OpenGLStoredSceneHandler::ClearTransientStore()
+- Removed G4OpenGLSceneHandler::AddPrimitive (const G4Polymarker&) (it only
+  invoked G4VSceneHandler::AddPrimitive (const G4Polymarker&) which is
+  picked up by inheritance anyway.
+- Removed lots of unnecessary header files from G4OpenGLStoredSceneHandler.cc.
+- Corrected order of calling base class functions in
+  G4OpenGLStoredSceneHandler::Begin/EndModeling.
+
+24th July 2001  John Allison  (vis-V03-02-06)
+- G4OpenGLSceneHandler::AddPrimitive (const G4Text&) handles transformation.
+
+14th July 2001  John Allison (opengl-V03-02-00)
+- Fixed crash in optimised mode: added Initialise() to viewers so
+  that windows are opened after viewers are fully constructed.
+
+2nd April 2001  John Allison (opengl-V03-00-01 wrt vis-V03-00-09)
+- Tidied G4OpenGLXmViewer callback code.  Removed superfluous header files.
+
+7th March 2001  John Allison
+- Changed char* to const char* in many places and that gave problems in
+  calls to Xt and Xm.  Hope all's OK.  Differences:
+    cvs diff -r vis-V03-00-06 vis-V03-00-07
+
+25th January 2001  John Allison  (opengl-V03-00-00)
+- Implemented running re-calculation of up-vector in the case of "object
+  rotation" (lights move with camera) to prevent "flipping" of view when
+  camera passes through up-vector.  Note that the default is "camera
+  rotation" (lights do not move with camera, i.e., remain fixed relative
+  to object) so the default is that this "flipping" can happen.  To set
+  "object rotation" (lights move with camera) use
+  /vis/lights/move_with_camera true (soon to be
+  /vis/viewer/set/lights move-with-camera) or click "Object" radio button
+  on Rotation Panel in OpenGLXm mode.
+- Changed some objects to references for efficiency.  E.g.:
+  const G4Vector3D& vp = pView->fVP.GetViewpointDirection ().unit ();
+
+22nd May 2000  John Allison  (opengl-V01-01-00)
+- Fixed slow response of 2nd window of OpenGLXm.  Worked around Mesa bug
+  by sharing static visuals in G4OpenGLXViewer (Guy Barrand):
+    static XVisualInfo* vi_single_buffer;
+    static XVisualInfo* vi_double_buffer;
+- Removed ChooseVisual from G4OpenGLXmViewer.cc - done in base class
+  G4OpenGLXViewer.
+- Protected double deletion of window in destructors of G4OpenGLXmViewer
+  and G4OpenGLXViewer (Guy Barrand).
+- Changed requested bits per colour to r,g,b = 1,1,1 in G4OpenGLViewer.cc.
+- Corrected order of CreateMainWindow() and InitializeGLView() in X*Viewer
+  constructors.
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGL.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGL.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGL.hh	(revision 529)
@@ -0,0 +1,41 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4OpenGL.hh,v 1.4 2006/06/29 21:17:36 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// G.Barrand.
+
+#ifndef G4OpenGL_h
+#define G4OpenGL_h 
+
+#ifdef WIN32
+#include <windows.h>
+#endif
+
+#include <GL/gl.h>
+#include <GL/glu.h>
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLFontBaseStore.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLFontBaseStore.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLFontBaseStore.hh	(revision 529)
@@ -0,0 +1,61 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4OpenGLFontBaseStore.hh,v 1.3 2006/06/29 21:17:38 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// J.Allison  Apr 2005.
+
+// Class Description:
+// Facilitates sharing of font bases between scene handler and viewers.
+
+#ifndef G4OPENGLFONTBASESTORE_HH
+#define G4OPENGLFONTBASESTORE_HH
+
+#include "globals.hh"
+#include <map>
+#include <vector>
+
+class G4VViewer;
+
+class G4OpenGLFontBaseStore {
+public:
+  static void AddFontBase(G4VViewer*, G4int fontBase,
+			  G4double size, const G4String& fontName);
+  static G4int GetFontBase(G4VViewer*, G4double size);
+private:
+  struct FontInfo {
+    FontInfo():
+      fFontName(""), fSize(0), fFontBase(-1) {}
+    FontInfo(const G4String& fontName, G4double size, G4int fontBase):
+      fFontName(fontName), fSize(size), fFontBase(fontBase) {}
+    G4String fFontName;
+    G4double fSize;  // In terms of G4VMarker Screen Size.
+    G4int fFontBase;
+  };
+  static std::map<G4VViewer*,std::vector<FontInfo> > fFontBaseMap;
+};
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateSceneHandler.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateSceneHandler.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateSceneHandler.hh	(revision 529)
@@ -0,0 +1,92 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLImmediateSceneHandler.hh,v 1.11 2006/08/16 10:34:36 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  10th February 1997
+// G4OpenGLImmediateSceneHandler - no Display lists.
+
+#ifdef G4VIS_BUILD_OPENGL_DRIVER
+
+#ifndef G4OPENGLIMMEDIATESCENEHANDLER_HH
+#define G4OPENGLIMMEDIATESCENEHANDLER_HH
+
+#include "G4VSceneHandler.hh"
+#include "G4OpenGLViewer.hh"
+#include "G4OpenGLImmediateViewer.hh"
+#include "globals.hh"
+#include "G4RotationMatrix.hh"
+#include "G4OpenGLSceneHandler.hh"
+
+class G4OpenGLImmediate;
+
+class G4OpenGLImmediateSceneHandler: public G4OpenGLSceneHandler {
+
+public:
+
+  G4OpenGLImmediateSceneHandler (G4VGraphicsSystem& system, const G4String& name);
+  virtual ~G4OpenGLImmediateSceneHandler ();
+  void BeginPrimitives (const G4Transform3D& objectTransformation);
+  void EndPrimitives ();
+  void BeginPrimitives2D ();
+  void EndPrimitives2D ();
+  void BeginModeling ();
+  void EndModeling ();
+  void AddPrimitive (const G4Polyline&);
+  void AddPrimitive (const G4Circle&);
+  void AddPrimitive (const G4Square&);
+  // Explicitly invoke base class methods to avoid warnings about
+  // hiding of base class methods...
+  void AddPrimitive (const G4Text& text) {
+    G4OpenGLSceneHandler::AddPrimitive (text);
+  }
+  void AddPrimitive (const G4Polyhedron& polyhedron) {
+    G4OpenGLSceneHandler::AddPrimitive (polyhedron);
+  }
+  void AddPrimitive (const G4NURBS& nurbs) {
+    G4OpenGLSceneHandler::AddPrimitive (nurbs);
+  }
+  void AddPrimitive(const G4Polymarker& polymarker) {
+    G4OpenGLSceneHandler::AddPrimitive (polymarker);
+  }
+  void AddPrimitive (const G4Scale& scale) {
+    G4OpenGLSceneHandler::AddPrimitive (scale);
+  }
+  void ClearTransientStore ();
+
+protected:
+
+  void RequestPrimitives (const G4VSolid& solid);
+  void AddPrimitivePreamble(const G4Visible& visible);
+
+  static G4int    fSceneIdCount;  // static counter for OpenGLImmediate scenes.
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateViewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateViewer.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateViewer.hh	(revision 529)
@@ -0,0 +1,60 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLImmediateViewer.hh,v 1.9 2006/09/04 12:07:59 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  7th February 1997
+// Class G4OpenGLImmediateViewer : Encapsulates the `immediateness' of
+//                                 an OpenGL viewer, for inheritance by
+//                                 derived (X, Xm...) classes.
+
+#ifdef G4VIS_BUILD_OPENGL_DRIVER
+
+#ifndef G4OPENGLIMMEDIATEVIEWER_HH
+#define G4OPENGLIMMEDIATEVIEWER_HH
+
+#include "G4VViewer.hh"
+#include "G4OpenGLViewer.hh"
+#include "G4OpenGLSceneHandler.hh"
+#include "G4OpenGLImmediateSceneHandler.hh"
+#include "G4OpenGLTransform3D.hh"
+#include "globals.hh"
+
+class G4OpenGLSceneHandler;
+class G4OpenGLImmediateSceneHandler;
+
+class G4OpenGLImmediateViewer: virtual public G4OpenGLViewer {
+  
+public:
+  G4OpenGLImmediateViewer (G4OpenGLImmediateSceneHandler& scene);
+  void ProcessView ();
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateWin32.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateWin32.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateWin32.hh	(revision 529)
@@ -0,0 +1,49 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLImmediateWin32.hh,v 1.7 2006/06/29 21:17:44 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// OpenGLImmediateWin32 graphics system factory.
+
+#if defined (G4VIS_BUILD_OPENGLWIN32_DRIVER) || defined (G4VIS_USE_OPENGLWIN32)
+
+#ifndef G4OPENGLIMMEDIATEWIN32_HH
+#define G4OPENGLIMMEDIATEWIN32_HH
+
+#include "G4VGraphicsSystem.hh"
+
+class G4OpenGLImmediateWin32: public G4VGraphicsSystem {
+public:
+  G4OpenGLImmediateWin32 ();
+  G4VSceneHandler* CreateSceneHandler (const G4String& name = "");
+  G4VViewer*  CreateViewer  (G4VSceneHandler&, const G4String& name = "");
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateWin32Viewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateWin32Viewer.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateWin32Viewer.hh	(revision 529)
@@ -0,0 +1,60 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLImmediateWin32Viewer.hh,v 1.9 2006/06/29 21:17:46 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Class G4OpenGLImmediateWin32Viewer : a class derived from
+//   G4OpenGLWin32Viewer and G4OpenGLImmediateViewer.
+
+#ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER
+
+#ifndef G4OpenGLIMMEDIATEWIN32VIEWER_HH
+#define G4OpenGLIMMEDIATEWIN32VIEWER_HH
+
+#include "G4VViewer.hh"
+#include "G4OpenGLImmediateViewer.hh"
+#include "G4OpenGLWin32Viewer.hh"
+
+#include "globals.hh"
+
+class G4OpenGLImmediateSceneHandler;
+
+class G4OpenGLImmediateWin32Viewer:
+public G4OpenGLWin32Viewer, public G4OpenGLImmediateViewer{
+  
+public:
+  G4OpenGLImmediateWin32Viewer (G4OpenGLImmediateSceneHandler& scene,
+				const G4String& name = "");
+  void Initialise ();
+  void DrawView ();
+  void FinishView ();
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateX.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateX.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateX.hh	(revision 529)
@@ -0,0 +1,51 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLImmediateX.hh,v 1.7 2006/06/29 21:17:48 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Andrew Walkden  10th February 1997
+// OpenGL graphics system factory.
+
+#if defined (G4VIS_BUILD_OPENGLX_DRIVER) || defined (G4VIS_USE_OPENGLX)
+
+#ifndef G4OPENGLIMMEDIATEX_HH
+#define G4OPENGLIMMEDIATEX_HH
+
+#include "G4VGraphicsSystem.hh"
+
+class G4OpenGLImmediateX: public G4VGraphicsSystem {
+public:
+  G4OpenGLImmediateX ();
+  virtual ~G4OpenGLImmediateX ();
+  G4VSceneHandler* CreateSceneHandler (const G4String& name = "");
+  G4VViewer*  CreateViewer  (G4VSceneHandler&, const G4String& name = "");
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateXViewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateXViewer.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateXViewer.hh	(revision 529)
@@ -0,0 +1,62 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLImmediateXViewer.hh,v 1.9 2006/07/03 16:38:13 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  7th February 1997
+// Class G4OpenGLImmediateXViewer : a class derived from G4OpenGLXViewer and
+//                                  G4OpenGLImmediateViewer.
+
+#ifdef G4VIS_BUILD_OPENGLX_DRIVER
+
+#ifndef G4OpenGLIMMEDIATEXVIEWER_HH
+#define G4OpenGLIMMEDIATEXVIEWER_HH
+
+#include "G4VViewer.hh"
+#include "G4OpenGLImmediateViewer.hh"
+#include "G4OpenGLXViewer.hh"
+
+#include "globals.hh"
+
+class G4OpenGLImmediateSceneHandler;
+
+class G4OpenGLImmediateXViewer:
+public G4OpenGLXViewer, public G4OpenGLImmediateViewer{
+  
+public:
+  G4OpenGLImmediateXViewer (G4OpenGLImmediateSceneHandler& scene,
+			  const G4String& name = "");
+  virtual ~G4OpenGLImmediateXViewer ();
+  void Initialise ();
+  void DrawView ();
+  void FinishView ();
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateXm.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateXm.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateXm.hh	(revision 529)
@@ -0,0 +1,51 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLImmediateXm.hh,v 1.7 2006/06/29 21:17:52 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Andrew Walkden  10th February 1997
+// OpenGL graphics system factory.
+
+#if defined (G4VIS_BUILD_OPENGLXM_DRIVER) || defined (G4VIS_USE_OPENGLXM)
+
+#ifndef G4OPENGLIMMEDIATEXM_HH
+#define G4OPENGLIMMEDIATEXM_HH
+
+#include "G4VGraphicsSystem.hh"
+
+class G4OpenGLImmediateXm: public G4VGraphicsSystem {
+public:
+  G4OpenGLImmediateXm ();
+  virtual ~G4OpenGLImmediateXm ();
+  G4VSceneHandler* CreateSceneHandler (const G4String& name = "");
+  G4VViewer*  CreateViewer  (G4VSceneHandler&, const G4String& name = "");
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateXmViewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateXmViewer.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateXmViewer.hh	(revision 529)
@@ -0,0 +1,63 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLImmediateXmViewer.hh,v 1.9 2006/07/03 16:38:13 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  10th February 1997
+// G4OpenGLXmViewer : Class derived from G4OpenGLXViewer, to provide
+//                  (Motif) widget OpenGL functionality for GEANT4.
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#ifndef G4OPENGLIMMEDIATEXMVIEWER_HH
+#define G4OPENGLIMMEDIATEXMVIEWER_HH
+
+#include "G4VViewer.hh"
+#include "G4OpenGLImmediateViewer.hh"
+#include "G4OpenGLXmViewer.hh"
+
+#include "globals.hh"
+
+class G4OpenGLImmediateSceneHandler;
+
+class G4OpenGLImmediateXmViewer:
+public G4OpenGLXmViewer, public G4OpenGLImmediateViewer{
+  
+public:
+  G4OpenGLImmediateXmViewer (G4OpenGLImmediateSceneHandler& scene,
+			   const G4String& name = "");
+  virtual ~G4OpenGLImmediateXmViewer ();
+  void Initialise ();
+  void DrawView ();
+  void FinishView ();
+
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLSceneHandler.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLSceneHandler.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLSceneHandler.hh	(revision 529)
@@ -0,0 +1,115 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLSceneHandler.hh,v 1.20 2006/08/30 11:37:34 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  27th March 1996
+// OpenGL scene handler - base for immediate mode and stored mode classes to
+//                        inherit from.
+
+#ifdef G4VIS_BUILD_OPENGL_DRIVER
+
+#ifndef G4OPENGLSCENEHANDLER_HH
+#define G4OPENGLSCENEHANDLER_HH
+
+#include "globals.hh"
+#include "G4RotationMatrix.hh"
+
+#include "G4OpenGL.hh"
+
+#include "G4VSceneHandler.hh"
+#include "G4OpenGLViewer.hh"
+
+// Base class for various OpenGLScene classes.
+class G4OpenGLSceneHandler: public G4VSceneHandler {
+
+public:
+  void AddPrimitive (const G4Polyline&);
+  void AddPrimitive (const G4Text&);
+  void AddPrimitive (const G4Circle&);
+  void AddPrimitive (const G4Square&);
+  void AddPrimitive (const G4Polyhedron&);
+  void AddPrimitive (const G4NURBS&);
+  // Explicitly invoke base class methods to avoid warnings about
+  // hiding of base class methods...
+  void AddPrimitive(const G4Polymarker& polymarker) {
+    G4VSceneHandler::AddPrimitive (polymarker);
+  }
+  void AddPrimitive (const G4Scale& scale) {
+    G4VSceneHandler::AddPrimitive (scale);
+  }
+
+  void AddSolid (const G4Box&);
+  void AddSolid (const G4Cons&);
+  void AddSolid (const G4Tubs&);
+  void AddSolid (const G4Trd&);
+  void AddSolid (const G4Trap&);
+  void AddSolid (const G4Sphere&);
+  void AddSolid (const G4Para&);
+  void AddSolid (const G4Torus&);
+  void AddSolid (const G4Polycone&);
+  void AddSolid (const G4Polyhedra&);
+  void AddSolid (const G4VSolid&);
+  void AddCompound (const G4VTrajectory&);
+  void AddCompound (const G4VHit&);
+
+protected:
+
+  G4OpenGLSceneHandler (G4VGraphicsSystem& system,
+			G4int id,
+			const G4String& name = "");
+  virtual ~G4OpenGLSceneHandler ();
+
+  const G4Polyhedron* CreateSectionPolyhedron ();
+  const G4Polyhedron* CreateCutawayPolyhedron ();
+
+private:
+
+  void AddCircleSquare (const G4VMarker&, G4int nSides);
+  /**************************************************
+  Not needed - but see note on future development in .cc.
+  void DrawScreenPolygon (G4double size,
+		          const G4Point3D& centre,
+		          G4int nSides);
+  // Draws in screen coordinates.
+  *********************************/
+
+  void DrawXYPolygon (G4double size,
+		      const G4Point3D& centre,
+		      G4int nSides);
+  // Draws in world coordinates a polygon in the screen plane knowing
+  // viewpoint direction and up vector.
+
+  static const GLubyte fStippleMaskHashed [128];
+};
+
+#include "G4OpenGLSceneHandler.icc"
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLSceneHandler.icc
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLSceneHandler.icc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLSceneHandler.icc	(revision 529)
@@ -0,0 +1,75 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLSceneHandler.icc,v 1.7 2006/06/29 21:17:58 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Andrew Walkden  20th January 1998
+
+inline void G4OpenGLSceneHandler::AddSolid (const G4Box& box) {
+  G4VSceneHandler::AddSolid (box);
+}
+
+inline void G4OpenGLSceneHandler::AddSolid (const G4Cons& cons) {
+  G4VSceneHandler::AddSolid (cons);
+}
+
+inline void G4OpenGLSceneHandler::AddSolid (const G4Tubs& tubs) {
+  G4VSceneHandler::AddSolid (tubs);
+}
+
+inline void G4OpenGLSceneHandler::AddSolid (const G4Trd& trd) {
+  G4VSceneHandler::AddSolid (trd);
+}
+
+inline void G4OpenGLSceneHandler::AddSolid (const G4Trap& trap) {
+  G4VSceneHandler::AddSolid (trap);
+}
+
+inline void G4OpenGLSceneHandler::AddSolid (const G4Sphere& sphere) {
+  G4VSceneHandler::AddSolid (sphere);
+}
+
+inline void G4OpenGLSceneHandler::AddSolid (const G4Para& para) {
+  G4VSceneHandler::AddSolid (para);
+}
+
+inline void G4OpenGLSceneHandler::AddSolid (const G4Torus& torus) {
+  G4VSceneHandler::AddSolid (torus);
+}
+
+inline void G4OpenGLSceneHandler::AddSolid (const G4Polycone& polycone) {
+  G4VSceneHandler::AddSolid (polycone);
+}
+
+inline void G4OpenGLSceneHandler::AddSolid (const G4Polyhedra& polyhedra) {
+  G4VSceneHandler::AddSolid (polyhedra);
+}
+
+inline void G4OpenGLSceneHandler::AddSolid (const G4VSolid& vsolid) {
+  G4VSceneHandler::AddSolid (vsolid);
+}
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredSceneHandler.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredSceneHandler.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredSceneHandler.hh	(revision 529)
@@ -0,0 +1,125 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLStoredSceneHandler.hh,v 1.21 2006/08/30 11:43:57 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  10th February 1997
+// G4OpenGLStoredSceneHandler - creates OpenGL Display lists.
+
+#ifdef G4VIS_BUILD_OPENGL_DRIVER
+
+#ifndef G4OPENGLSTOREDSCENEHANDLER_HH
+#define G4OPENGLSTOREDSCENEHANDLER_HH
+
+#include "G4VSceneHandler.hh"
+#include "G4OpenGLViewer.hh"
+#include "G4OpenGLStoredViewer.hh"
+#include "globals.hh"
+#include "G4RotationMatrix.hh"
+#include "G4OpenGLSceneHandler.hh"
+#include <map>
+#include <vector>
+
+class G4OpenGLStored;
+
+class G4OpenGLStoredSceneHandler: public G4OpenGLSceneHandler {
+
+  friend class G4OpenGLStoredViewer;  // ..allows access to P/TODLs.
+
+public:
+
+  G4OpenGLStoredSceneHandler (G4VGraphicsSystem& system, const G4String& name = "");
+  virtual ~G4OpenGLStoredSceneHandler ();
+  void BeginPrimitives (const G4Transform3D& objectTransformation);
+  void EndPrimitives ();
+  void BeginPrimitives2D ();
+  void EndPrimitives2D ();
+  void BeginModeling ();
+  void EndModeling ();
+  void AddPrimitive (const G4Polyline&);
+  void AddPrimitive (const G4Circle&);
+  void AddPrimitive (const G4Square&);
+  void AddPrimitive (const G4Polymarker& polymarker);
+  // Explicitly invoke base class methods to avoid warnings about
+  // hiding of base class methods...
+  void AddPrimitive (const G4Text& text) {
+    G4OpenGLSceneHandler::AddPrimitive (text);
+  }
+  void AddPrimitive (const G4Polyhedron& polyhedron) {
+    G4OpenGLSceneHandler::AddPrimitive (polyhedron);
+  }
+  void AddPrimitive (const G4NURBS& nurbs) {
+    G4OpenGLSceneHandler::AddPrimitive (nurbs);
+  }
+  void AddPrimitive (const G4Scale& scale) {
+    G4OpenGLSceneHandler::AddPrimitive (scale);
+  }
+  void ClearStore ();
+  void ClearTransientStore ();
+
+protected:
+
+  void RequestPrimitives (const G4VSolid& solid);
+  void AddPrimitivePreamble(const G4Visible& visible);
+  void AddPrimitivePostamble();
+
+  static G4int     fSceneIdCount;   // static counter for OpenGLStored scenes.
+  G4int            fDisplayListId;  // Workspace.
+  G4bool  fMemoryForDisplayLists;   // avoid memory overflow
+  G4int fAddPrimitivePreambleNestingDepth;
+  
+  // PODL = Persistent Object Display List.
+  GLint  fTopPODL;                  // List which calls the other PODLs.
+  struct PO {
+    PO(G4int id, const G4Transform3D& tr = G4Transform3D()):
+      fDisplayListId(id), fTransform(tr) {}
+    G4int fDisplayListId;
+    G4Transform3D fTransform;
+  };
+  std::vector<PO> fPOList; 
+  
+  // TO = Transparent Object.
+  struct TO {
+    TO(G4int id, const G4Transform3D& tr = G4Transform3D()):
+      fDisplayListId(id), fTransform(tr),
+      fStartTime(-DBL_MAX), fEndTime(DBL_MAX) {}
+    G4int fDisplayListId;
+    G4Transform3D fTransform;
+    G4double fStartTime, fEndTime;  // Time range (e.g., for trajectory steps).
+    G4Colour fColour;
+  };
+  std::vector<TO> fTOList; 
+  
+  // Stop-gap solution of structure re-use.
+  // A proper implementation would use geometry hierarchy.
+  std::map <const G4VSolid*, G4int, std::less <const G4VSolid*> > fSolidMap;
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredViewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredViewer.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredViewer.hh	(revision 529)
@@ -0,0 +1,66 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLStoredViewer.hh,v 1.9 2006/06/29 21:18:02 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Andrew Walkden  7th February 1997
+// Class G4OpenGLStoredViewer : Encapsulates the `storedness' of
+//                              an OpenGL viewer, for inheritance by
+//                              derived (X, Xm...) classes.
+
+#ifdef G4VIS_BUILD_OPENGL_DRIVER
+
+#ifndef G4OPENGLSTOREDVIEWER_HH
+#define G4OPENGLSTOREDVIEWER_HH
+
+#include "G4VViewer.hh"
+#include "G4OpenGLViewer.hh"
+#include "G4OpenGLSceneHandler.hh"
+#include "G4OpenGLStoredSceneHandler.hh"
+#include "G4OpenGLTransform3D.hh"
+#include "globals.hh"
+
+class G4OpenGLStoredSceneHandler;
+
+class G4OpenGLStoredViewer: virtual public G4OpenGLViewer {
+  
+public:
+  G4OpenGLStoredViewer (G4OpenGLStoredSceneHandler& scene);
+  virtual ~G4OpenGLStoredViewer ();
+  
+protected:
+  void KernelVisitDecision ();
+  G4bool CompareForKernelVisit(G4ViewParameters&);
+  void DrawDisplayLists ();
+  G4OpenGLStoredSceneHandler& fG4OpenGLStoredSceneHandler;
+  G4ViewParameters fLastVP;  // Memory for making kernel visit decisions.
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredWin32.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredWin32.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredWin32.hh	(revision 529)
@@ -0,0 +1,49 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLStoredWin32.hh,v 1.7 2006/06/29 21:18:04 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// OpenGLStoredWin32 graphics system factory.
+
+#if defined (G4VIS_BUILD_OPENGLWIN32_DRIVER) || defined (G4VIS_USE_OPENGLWIN32)
+
+#ifndef G4OPENGLSTOREDWIN32_HH
+#define G4OPENGLSTOREDWIN32_HH
+
+#include "G4VGraphicsSystem.hh"
+
+class G4OpenGLStoredWin32: public G4VGraphicsSystem {
+public:
+  G4OpenGLStoredWin32 ();
+  G4VSceneHandler* CreateSceneHandler (const G4String& name = "");
+  G4VViewer*  CreateViewer  (G4VSceneHandler&, const G4String& name = "");
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredWin32Viewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredWin32Viewer.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredWin32Viewer.hh	(revision 529)
@@ -0,0 +1,59 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLStoredWin32Viewer.hh,v 1.7 2006/06/29 21:18:06 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Class G4OpenGLStoredWin32Viewer : a class derived from
+//   G4OpenGLWin32Viewer and G4OpenGLStoredViewer.
+
+#ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER
+
+#ifndef G4OPENGLSTOREDWIN32VIEWER_HH
+#define G4OPENGLSTOREDWIN32VIEWER_HH
+
+#include "G4VViewer.hh"
+#include "G4OpenGLStoredViewer.hh"
+#include "G4OpenGLWin32Viewer.hh"
+
+class G4OpenGLStoredSceneHandler;
+
+class G4OpenGLStoredWin32Viewer:
+public G4OpenGLWin32Viewer, public G4OpenGLStoredViewer{
+  
+public:
+  G4OpenGLStoredWin32Viewer (G4OpenGLStoredSceneHandler& scene,
+			     const G4String& name = "");
+  void Initialise ();
+  void DrawView ();
+  void FinishView ();
+};
+
+#endif
+
+#endif
+
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredX.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredX.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredX.hh	(revision 529)
@@ -0,0 +1,51 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLStoredX.hh,v 1.7 2006/06/29 21:18:08 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Andrew Walkden  10th February 1997
+// OpenGL graphics system factory.
+
+#if defined (G4VIS_BUILD_OPENGLX_DRIVER) || defined (G4VIS_USE_OPENGLX)
+
+#ifndef G4OPENGLSTOREDX_HH
+#define G4OPENGLSTOREDX_HH
+
+#include "G4VGraphicsSystem.hh"
+
+class G4OpenGLStoredX: public G4VGraphicsSystem {
+public:
+  G4OpenGLStoredX ();
+  virtual ~G4OpenGLStoredX ();
+  G4VSceneHandler* CreateSceneHandler (const G4String& name = "");
+  G4VViewer*  CreateViewer  (G4VSceneHandler&, const G4String& name = "");
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredXViewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredXViewer.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredXViewer.hh	(revision 529)
@@ -0,0 +1,60 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLStoredXViewer.hh,v 1.7 2006/07/03 16:38:13 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  7th February 1997
+// Class G4OpenGLStoredXViewer : a class derived from G4OpenGLXViewer and
+//                               G4OpenGLStoredViewer.
+
+#ifdef G4VIS_BUILD_OPENGLX_DRIVER
+
+#ifndef G4OPENGLSTOREDXVIEWER_HH
+#define G4OPENGLSTOREDXVIEWER_HH
+
+#include "G4VViewer.hh"
+#include "G4OpenGLStoredViewer.hh"
+#include "G4OpenGLXViewer.hh"
+
+class G4OpenGLStoredSceneHandler;
+
+class G4OpenGLStoredXViewer:
+public G4OpenGLXViewer, public G4OpenGLStoredViewer{
+  
+public:
+  G4OpenGLStoredXViewer (G4OpenGLStoredSceneHandler& scene, const G4String& name = "");
+  virtual ~G4OpenGLStoredXViewer ();
+  void Initialise ();
+  void DrawView ();
+  void FinishView ();
+};
+
+#endif
+
+#endif
+
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredXm.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredXm.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredXm.hh	(revision 529)
@@ -0,0 +1,50 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLStoredXm.hh,v 1.6 2006/06/29 21:18:12 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Andrew Walkden  10th February 1997
+// OpenGL graphics system factory.
+
+#if defined (G4VIS_BUILD_OPENGLXM_DRIVER) || defined (G4VIS_USE_OPENGLXM)
+
+#ifndef G4OPENGLSTOREDXM_HH
+#define G4OPENGLSTOREDXM_HH
+
+#include "G4VGraphicsSystem.hh"
+
+class G4OpenGLStoredXm: public G4VGraphicsSystem {
+public:
+  G4OpenGLStoredXm ();
+  G4VSceneHandler* CreateSceneHandler (const G4String& name = "");
+  G4VViewer*  CreateViewer  (G4VSceneHandler&, const G4String& name = "");
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredXmViewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredXmViewer.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredXmViewer.hh	(revision 529)
@@ -0,0 +1,60 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLStoredXmViewer.hh,v 1.7 2006/07/03 16:38:13 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  10th February 1997
+// Class G4OpenGLStoredXmViewer : a class derived from G4OpenGLXmViewer 
+//                                and G4OpenGLStoredViewer.
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#ifndef G4OpenGLSTOREDXMVIEWER_HH
+#define G4OpenGLSTOREDXMVIEWER_HH
+
+#include "G4VViewer.hh"
+#include "G4OpenGLStoredViewer.hh"
+#include "G4OpenGLXmViewer.hh"
+
+class G4OpenGLStoredSceneHandler;
+
+class G4OpenGLStoredXmViewer:
+public G4OpenGLXmViewer, public G4OpenGLStoredViewer{
+  
+public:
+  G4OpenGLStoredXmViewer (G4OpenGLStoredSceneHandler& scene, const G4String& name = "");
+  virtual ~G4OpenGLStoredXmViewer ();
+  void Initialise ();
+  void DrawView ();
+  void FinishView ();
+
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLTransform3D.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLTransform3D.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLTransform3D.hh	(revision 529)
@@ -0,0 +1,54 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLTransform3D.hh,v 1.7 2006/06/29 21:18:16 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Andrew Walkden  24th October 1996
+// G4OpenGLTransform3D provides OpenGL style transformation matrix
+// from G4Transform3D.
+
+#ifdef G4VIS_BUILD_OPENGL_DRIVER
+
+#ifndef G4OPENGLTRANSFORM3D_HH
+#define G4OPENGLTRANSFORM3D_HH
+
+#include "G4Transform3D.hh"
+
+#include "G4OpenGL.hh"
+
+class G4OpenGLTransform3D : public G4Transform3D {
+public:
+  G4OpenGLTransform3D (const G4Transform3D &t);
+  const GLdouble* GetGLMatrix ();
+private:
+  GLdouble m[16];
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLViewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLViewer.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLViewer.hh	(revision 529)
@@ -0,0 +1,84 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLViewer.hh,v 1.18 2006/09/19 16:13:15 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  27th March 1996
+// OpenGL viewer - opens window, hard copy, etc.
+
+#ifdef G4VIS_BUILD_OPENGL_DRIVER
+
+#ifndef G4OPENGLVIEWER_HH
+#define G4OPENGLVIEWER_HH
+
+#include "G4VViewer.hh"
+
+class G4OpenGLSceneHandler;
+
+// Base class for various OpenGLView classes.
+class G4OpenGLViewer: virtual public G4VViewer {
+
+  friend class G4OpenGLSceneHandler;
+  friend class G4OpenGLImmediateSceneHandler;
+  friend class G4OpenGLStoredSceneHandler;
+  friend class G4OpenGLViewerMessenger;
+
+public:
+  void ClearView  ();
+
+protected:
+  G4OpenGLViewer (G4OpenGLSceneHandler& scene);
+  virtual ~G4OpenGLViewer ();
+  void SetView    ();
+  void HaloingFirstPass ();
+  void HaloingSecondPass ();
+  void HLRFirstPass ();
+  void HLRSecondPass ();
+  void HLRThirdPass ();
+  void InitializeGLView ();
+  virtual void CreateFontLists () {}
+  G4Colour background;      //the OpenGL clear colour
+  G4bool
+    transparency_enabled,   //is alpha blending enabled?
+    antialiasing_enabled,   //is antialiasing enabled?
+    haloing_enabled;        //is haloing enabled for wireframe?
+  G4double fStartTime, fEndTime;  // Time range (e.g., for trajectory steps).
+  G4double fFadeFactor;  // 0: no fade; 1: maximum fade with time within range.
+  G4bool fDisplayHeadTime;  // Display head time (fEndTime) in 2D text.
+  G4double fDisplayHeadTimeX, fDisplayHeadTimeY;  // 2D screen coords.
+  G4double fDisplayHeadTimeSize;  // Screen size.
+  G4double fDisplayHeadTimeRed, fDisplayHeadTimeGreen, fDisplayHeadTimeBlue;
+  G4bool fDisplayLightFront;// Display light front at head time originating at
+  G4double fDisplayLightFrontX, fDisplayLightFrontY, fDisplayLightFrontZ,
+    fDisplayLightFrontT;
+  G4double fDisplayLightFrontRed, fDisplayLightFrontGreen, fDisplayLightFrontBlue;
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLViewerMessenger.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLViewerMessenger.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLViewerMessenger.hh	(revision 529)
@@ -0,0 +1,61 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLViewerMessenger.hh,v 1.4 2006/09/19 16:14:21 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+
+#ifndef G4OPENGLVIEWERMESSENGER_HH
+#define G4OPENGLVIEWERMESSENGER_HH
+
+#include "G4UImessenger.hh"
+
+#include "G4String.hh"
+
+class G4UIdirectory;
+class G4UIcommand;
+class G4UIcmdWithADouble;
+class G4UIcmdWithABool;
+
+class G4OpenGLViewerMessenger: public G4UImessenger {
+public:
+  static G4OpenGLViewerMessenger* GetInstance();  // Singleton constructor.
+  ~G4OpenGLViewerMessenger();
+  void SetNewValue (G4UIcommand*, G4String);
+
+private:
+  G4OpenGLViewerMessenger();  // Private constructor.
+  static G4OpenGLViewerMessenger* fpInstance;
+  G4UIdirectory* fpDirectory;
+  G4UIdirectory* fpDirectorySet;
+  G4UIcommand* fpCommandDisplayHeadTime;
+  G4UIcommand* fpCommandDisplayLightFront;
+  G4UIcommand* fpCommandEndTime;
+  G4UIcmdWithADouble* fpCommandFade;
+  G4UIcommand* fpCommandStartTime;
+  G4UIcmdWithABool* fpCommandTransparency;
+};
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLWin32Viewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLWin32Viewer.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLWin32Viewer.hh	(revision 529)
@@ -0,0 +1,71 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLWin32Viewer.hh,v 1.13 2006/06/29 21:18:20 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// G4OpenGLWin32Viewer : Class to provide WindowsNT specific
+//                       functionality for OpenGL in GEANT4
+
+#ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER
+
+#ifndef G4OPENGLWIN32VIEWER_HH
+#define G4OPENGLWIN32VIEWER_HH
+
+#include "globals.hh"
+
+#include "G4VViewer.hh"
+#include "G4OpenGLSceneHandler.hh"
+
+class G4OpenGLSceneHandler;
+
+class G4OpenGLWin32Viewer: virtual public G4OpenGLViewer {
+
+public:
+  G4OpenGLWin32Viewer (G4OpenGLSceneHandler& scene);
+  virtual ~G4OpenGLWin32Viewer ();
+  void SetView ();
+  void ShowView ();
+protected:
+  void GetWin32Connection ();
+  void CreateGLWin32Context ();
+  virtual void CreateMainWindow ();
+protected:
+  G4int WinSize_x;
+  G4int WinSize_y;
+  HDC fHDC;
+private:
+  static LRESULT CALLBACK WindowProc(HWND,UINT,WPARAM,LPARAM);
+  static bool SetWindowPixelFormat(HDC);
+private:
+  HWND fWindow;
+  HGLRC fHGLRC;
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLXViewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLXViewer.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLXViewer.hh	(revision 529)
@@ -0,0 +1,143 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXViewer.hh,v 1.26 2006/11/01 11:22:27 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  7th February 1997
+// G4OpenGLXViewer : Class to provide XWindows specific
+//                   functionality for OpenGL in GEANT4
+
+#ifdef G4VIS_BUILD_OPENGLX_DRIVER
+
+#ifndef G4OPENGLXVIEWER_HH
+#define G4OPENGLXVIEWER_HH
+
+#include "G4VViewer.hh"
+#include "G4OpenGLSceneHandler.hh"
+#include "globals.hh"
+
+#include <X11/Xlib.h>
+#include <X11/Intrinsic.h>
+#include <X11/Xmu/StdCmap.h>
+
+#include <GL/glx.h>
+
+class G4OpenGLSceneHandler;
+
+class G4OpenGLXViewer: virtual public G4OpenGLViewer {
+
+  friend class G4OpenGLXViewerMessenger;
+
+public:
+  G4OpenGLXViewer (G4OpenGLSceneHandler& scene);
+  virtual ~G4OpenGLXViewer ();
+  void SetView ();
+  void ShowView ();
+  void print();
+
+protected:
+  void GetXConnection ();
+  void CreateGLXContext (XVisualInfo* vi);
+  virtual void CreateMainWindow ();
+  virtual void CreateFontLists ();
+
+  static int snglBuf_RGBA[12];
+  static int dblBuf_RGBA[13];
+
+  char                              print_string[50];
+  G4bool                            print_colour,
+                                    vectored_ps;
+
+//////////////////////////////Vectored PostScript production functions//////////////////////////////
+  void printBuffer(GLint, GLfloat*);
+  GLfloat* spewPrimitiveEPS (FILE*, GLfloat*);
+  void spewSortedFeedback (FILE*, GLint, GLfloat*);
+  void spewWireframeEPS (FILE*, GLint, GLfloat*, const char*);
+  void print3DcolorVertex(GLint, GLint*, GLfloat*);
+  G4float                           pointSize;
+
+
+//////////////////////////////Pixmap (screen dump) production functions//////////////////////////////
+  GLubyte* grabPixels (int inColor,
+		       unsigned int width,
+		       unsigned int height);
+  int generateEPS (char* filnam,
+		   int inColour,
+		   unsigned int width,
+		   unsigned int height);
+  GLXContext create_GL_print_context (XVisualInfo*& pvi);
+
+  XWindowAttributes                 xwa;
+  Display                           *dpy;
+  static XVisualInfo                *vi_single_buffer;
+  static XVisualInfo                *vi_double_buffer;
+  XVisualInfo                       *vi_immediate,
+                                    *vi_stored,
+                                    *vi;
+  Colormap                          cmap;
+  XSetWindowAttributes              swa;
+  GLXDrawable                       win;
+  GLXContext                        cx;
+  XEvent                            event;
+  G4int                             *attributeList,
+                                    errorBase,
+                                    eventBase,
+                                    major,
+                                    minor,
+                                    x_origin,
+                                    y_origin;
+  XSizeHints                        *norm_hints;
+  XWMHints                          *wm_hints;
+  XClassHint                        *class_hints;
+  Pixmap                            icon_pixmap;
+  XSizeHints                        *size_hints;
+  unsigned int                      WinSize_x,
+                                    WinSize_y;
+  Atom                              Xatom;
+  XTextProperty                     windowName,
+                                    iconName;
+  char                              charViewName [100];
+
+private:
+  G4OpenGLXViewer (const G4OpenGLXViewer&);
+  G4OpenGLXViewer& operator = (const G4OpenGLXViewer&);
+};
+
+typedef struct G4OpenGLXViewerFeedback3Dcolor {
+  GLfloat x;
+  GLfloat y;
+  GLfloat z;
+  GLfloat red;
+  GLfloat green;
+  GLfloat blue;
+  GLfloat alpha;
+} Feedback3Dcolor;
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLXViewerMessenger.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLXViewerMessenger.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLXViewerMessenger.hh	(revision 529)
@@ -0,0 +1,58 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXViewerMessenger.hh,v 1.2 2006/11/01 11:22:26 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+
+#ifdef G4VIS_BUILD_OPENGLX_DRIVER
+
+#ifndef G4OPENGLXVIEWERMESSENGER_HH
+#define G4OPENGLXVIEWERMESSENGER_HH
+
+#include "G4UImessenger.hh"
+
+#include "G4String.hh"
+
+class G4OpenGLXViewer;
+class G4UIdirectory;
+class G4UIcmdWithoutParameter;
+
+class G4OpenGLXViewerMessenger: public G4UImessenger {
+public:
+  static G4OpenGLXViewerMessenger* GetInstance();  // Singleton constructor.
+  ~G4OpenGLXViewerMessenger();
+  void SetNewValue (G4UIcommand*, G4String);
+
+private:
+  G4OpenGLXViewerMessenger();  // Private constructor.
+  static G4OpenGLXViewerMessenger* fpInstance;
+  G4UIdirectory* fpDirectory;
+  G4UIcmdWithoutParameter* fpCommandPrintEPS;
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmBox.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmBox.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmBox.hh	(revision 529)
@@ -0,0 +1,76 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmBox.hh,v 1.7 2006/06/29 21:18:24 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+//Box container class
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#ifndef G4OPENGLXMBOX_HH
+#define G4OPENGLXMBOX_HH
+
+#include "G4OpenGLXmVWidgetContainer.hh"
+#include "globals.hh"
+#include <Xm/Frame.h>
+#include <Xm/RowColumn.h>
+
+class G4OpenGLXmVWidgetComponent;
+class G4OpenGLXmVWidgetShell;
+
+class G4OpenGLXmBox : public G4OpenGLXmVWidgetContainer
+{
+
+public:
+  G4OpenGLXmBox (const char* = NULL,
+		 G4bool = False);   //constructor
+  virtual ~G4OpenGLXmBox ();  //destructor
+
+  void AddChild (G4OpenGLXmVWidgetComponent*);
+  void AddYourselfTo (G4OpenGLXmVWidgetShell*);
+
+  Widget* GetPointerToParent ();
+  Widget* GetPointerToWidget ();
+  
+  const char* GetName ();
+  void SetName (const char*);
+
+protected:
+  const char* name;
+  Widget* parent;
+  Widget box_row_col;
+  G4bool radio;
+
+private:
+  G4OpenGLXmBox (const G4OpenGLXmBox&);
+  G4OpenGLXmBox& operator = (const G4OpenGLXmBox&);
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmFourArrowButtons.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmFourArrowButtons.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmFourArrowButtons.hh	(revision 529)
@@ -0,0 +1,70 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmFourArrowButtons.hh,v 1.6 2006/06/29 21:18:26 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+//Four arrow buttons class. Inherits from G4OpenGLXmVWidgetComponent
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#ifndef G4OPENGLXMFOURARROWBUTTONS_HH
+#define G4OPENGLXMFOURARROWBUTTONS_HH
+
+#include "G4OpenGLXmVWidgetComponent.hh"
+
+class G4OpenGLXmFourArrowButtons : public G4OpenGLXmVWidgetComponent
+{
+
+public:
+  G4OpenGLXmFourArrowButtons (XtCallbackRec** = NULL); // array of 4 callbacks
+                                                       //constructor
+  virtual ~G4OpenGLXmFourArrowButtons ();              //destructor
+
+  void SetName (char*);
+ 
+  char* GetName ();
+
+  void AddYourselfTo (G4OpenGLXmVWidgetContainer*);
+
+  Widget* GetPointerToParent ();
+  Widget* GetPointerToWidget ();
+
+private:
+  XtCallbackRec** callback;
+  Widget arrow_form;
+  Widget arrow;
+  Widget* parent;
+
+private:
+  G4OpenGLXmFourArrowButtons (const G4OpenGLXmFourArrowButtons&);
+  G4OpenGLXmFourArrowButtons& operator = (const G4OpenGLXmFourArrowButtons&);
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmFramedBox.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmFramedBox.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmFramedBox.hh	(revision 529)
@@ -0,0 +1,67 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmFramedBox.hh,v 1.7 2006/06/29 21:18:28 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+//Framed box container class
+//Inherits from G4OpenGLXmBox
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#ifndef G4OPENGLXMFRAMEDBOX_HH
+#define G4OPENGLXMFRAMEDBOX_HH
+
+#include "G4OpenGLXmVWidgetContainer.hh"
+#include "G4OpenGLXmBox.hh"
+#include "globals.hh"
+#include <Xm/Frame.h>
+#include <Xm/RowColumn.h>
+
+class G4OpenGLXmVWidgetComponent;
+class G4OpenGLXmVWidgetShell;
+
+class G4OpenGLXmFramedBox : public G4OpenGLXmBox
+{
+
+public:
+  G4OpenGLXmFramedBox (const char* = NULL, 
+		       G4bool = False);   //constructor
+  virtual ~G4OpenGLXmFramedBox ();               //destructor
+
+  void AddChild (G4OpenGLXmVWidgetComponent*);
+  void AddYourselfTo (G4OpenGLXmVWidgetShell*);
+
+private:
+  G4OpenGLXmFramedBox (const G4OpenGLXmFramedBox&);
+  G4OpenGLXmFramedBox& operator = (const G4OpenGLXmFramedBox&);
+  Widget frame;
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmPushButton.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmPushButton.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmPushButton.hh	(revision 529)
@@ -0,0 +1,67 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmPushButton.hh,v 1.7 2006/06/29 21:18:30 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+//Push button class. Inherits from G4OpenGLXmVWidgetComponent
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#ifndef G4OPENGLXMPUSHBUTTON_HH
+#define G4OPENGLXMPUSHBUTTON_HH
+
+#include "G4OpenGLXmVWidgetComponent.hh"
+
+class G4OpenGLXmPushButton : public G4OpenGLXmVWidgetComponent
+{
+
+public:
+  G4OpenGLXmPushButton (const char* = NULL,
+			XtCallbackRec* = NULL); //constructor
+  virtual ~G4OpenGLXmPushButton ();             //destructor
+
+  void SetName (const char*);
+  const char* GetName ();
+
+  void AddYourselfTo (G4OpenGLXmVWidgetContainer*);
+
+  Widget* GetPointerToParent ();
+  Widget* GetPointerToWidget ();
+
+private:
+  G4OpenGLXmPushButton (const G4OpenGLXmPushButton&);
+  G4OpenGLXmPushButton& operator = (const G4OpenGLXmPushButton&);
+  const char* name;
+  XtCallbackRec* callback;
+  Widget button;
+  Widget* parent;
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmRadioButton.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmRadioButton.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmRadioButton.hh	(revision 529)
@@ -0,0 +1,71 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmRadioButton.hh,v 1.7 2006/06/29 21:18:32 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+//Radio button class. Inherits from G4OpenGLXmVWidgetComponent
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#ifndef G4OPENGLXMRADIOBUTTON_HH
+#define G4OPENGLXMRADIOBUTTON_HH
+
+#include "G4OpenGLXmVWidgetComponent.hh"
+
+class G4OpenGLXmRadioButton : public G4OpenGLXmVWidgetComponent
+{
+
+public:
+  G4OpenGLXmRadioButton (const char*,
+			 XtCallbackRec*,
+			 G4bool,
+			 G4int);                    //constructor
+  virtual ~G4OpenGLXmRadioButton ();                //destructor
+
+  void SetName (const char*);
+  const char* GetName ();
+
+  void AddYourselfTo (G4OpenGLXmVWidgetContainer*);
+
+  Widget* GetPointerToParent ();
+  Widget* GetPointerToWidget ();
+
+private:
+  G4OpenGLXmRadioButton (const G4OpenGLXmRadioButton&);
+  G4OpenGLXmRadioButton& operator = (const G4OpenGLXmRadioButton&);
+  const char* name;
+  XtCallbackRec* callback;
+  Widget button;
+  Widget* parent;
+  G4bool default_button;
+  G4int number;
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmResources.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmResources.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmResources.hh	(revision 529)
@@ -0,0 +1,49 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmResources.hh,v 1.5 2006/06/29 21:18:34 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+//
+// Default resources file for GEANT4 OpenGL Motif windows.
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#ifndef G4OPENGLXMRESOURCES_HH
+#define G4OPENGLXMRESOURCES_HH
+
+static String fallbackResources[] = {
+  "*glxarea*width: 500", "*glxarea*height: 500",
+  "*frame*x: 10", "*frame*y: 10",
+  "*frame*topOffset: 10", "*frame*bottomOffset: 10",
+  "*frame*rightOffset: 10", "*frame*leftOffset: 10",
+  "*frame*shadowType: SHADOW_IN", "*useColorObj: False", 
+  NULL
+  };
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmSeparator.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmSeparator.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmSeparator.hh	(revision 529)
@@ -0,0 +1,62 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmSeparator.hh,v 1.6 2006/06/29 21:18:36 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+//Separator class. Inherits from G4OpenGLXmVWidgetComponent
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#ifndef G4OPENGLXMSEPARATOR_HH
+#define G4OPENGLXMSEPARATOR_HH
+
+#include "G4OpenGLXmVWidgetComponent.hh"
+
+class G4OpenGLXmSeparator : public G4OpenGLXmVWidgetComponent
+{
+
+public:
+  G4OpenGLXmSeparator (unsigned char = XmSINGLE_LINE);           //constructor
+  virtual ~G4OpenGLXmSeparator ();                               //destructor
+
+  void AddYourselfTo (G4OpenGLXmVWidgetContainer*);
+
+  Widget* GetPointerToParent ();
+  Widget* GetPointerToWidget ();
+
+private:
+  G4OpenGLXmSeparator (const G4OpenGLXmSeparator&);
+  G4OpenGLXmSeparator& operator = (const G4OpenGLXmSeparator&);
+  unsigned char line_type;
+  Widget line;
+  Widget* parent;
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmSliderBar.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmSliderBar.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmSliderBar.hh	(revision 529)
@@ -0,0 +1,98 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmSliderBar.hh,v 1.7 2006/06/29 21:18:38 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+//Slider bar class. Inherits from G4OpenGLXmVWidgetComponent
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#ifndef G4OPENGLXMSLIDERBAR_HH
+#define G4OPENGLXMSLIDERBAR_HH
+
+#include "G4OpenGLXmVWidgetComponent.hh"
+
+class G4OpenGLXmSliderBar : public G4OpenGLXmVWidgetComponent
+{
+
+public:
+  G4OpenGLXmSliderBar (const char* = NULL,     // name of slider bar
+		       XtCallbackRec* = NULL,  // callbacks for slider bar
+		       G4bool = False,         // show current value if True
+		       short = 0,              // decimal places for show value
+		       G4double = 0.,          // initial value
+		       G4double = 0.,          // max value
+		       G4double = 0.,          // min value
+		       unsigned char = XmHORIZONTAL,
+		       unsigned char = XmMAX_ON_RIGHT); 
+                                               //constructor
+  virtual ~G4OpenGLXmSliderBar ();             //destructor
+
+  void SetName (const char*);
+  void SetShow (G4bool);
+  void SetDecimalPlaces (short);
+  void SetInitialValue (G4double);
+  void SetMaxValue (G4double);
+  void SetMinValue (G4double);
+  void SetOrientation (unsigned char);
+  void SetDirection (unsigned char);
+
+ 
+  const char* GetName ();
+  G4bool GetShow ();
+  short GetDecimalPlaces ();
+  G4double GetInitialValue ();
+  G4double GetMaxValue ();
+  G4double GetMinValue ();
+  unsigned char GetOrientation ();
+  unsigned char GetDirection ();
+
+  void AddYourselfTo (G4OpenGLXmVWidgetContainer*);
+
+  Widget* GetPointerToParent ();
+  Widget* GetPointerToWidget ();
+
+private:
+  G4OpenGLXmSliderBar (const G4OpenGLXmSliderBar&);
+  G4OpenGLXmSliderBar& operator = (const G4OpenGLXmSliderBar&);
+  const char* name;
+  XtCallbackRec* callback;
+  Widget sliderbar;
+  Widget* parent;
+  G4bool show;
+  short decimal_places;
+  G4int initial_value;
+  G4int max_value;
+  G4int min_value;
+  unsigned char orientation;
+  unsigned char direction;
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmTextField.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmTextField.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmTextField.hh	(revision 529)
@@ -0,0 +1,75 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmTextField.hh,v 1.7 2006/06/29 21:18:40 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+//Text field class. Inherits from G4OpenGLXmVWidgetComponent
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#ifndef G4OPENGLXMTEXTFIELD_HH
+#define G4OPENGLXMTEXTFIELD_HH
+
+#include "G4OpenGLXmVWidgetComponent.hh"
+//#include "G4OpenGLXmConvenienceRoutines.hh"
+
+class G4OpenGLXmTextField : public G4OpenGLXmVWidgetComponent
+{
+
+public:
+  G4OpenGLXmTextField (const char*,G4double*);   //constructor
+  G4OpenGLXmTextField (const char*,const char*); //constructor
+  virtual ~G4OpenGLXmTextField ();               //destructor
+
+  void SetName (const char*);
+  const char* GetName ();
+
+  void SetValue (G4double);
+  void SetValue (const char*);
+  const char* GetValue ();
+
+  void AddYourselfTo (G4OpenGLXmVWidgetContainer*);
+
+  Widget* GetPointerToParent ();
+  Widget* GetPointerToWidget ();
+
+private:
+  G4OpenGLXmTextField (const G4OpenGLXmTextField&);
+  G4OpenGLXmTextField& operator = (const G4OpenGLXmTextField&);
+  const char* name;
+  void* value;
+  G4bool text;
+  char* initial;
+  Widget text_label;
+  Widget text_field;
+  Widget* parent;
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmTopLevelShell.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmTopLevelShell.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmTopLevelShell.hh	(revision 529)
@@ -0,0 +1,66 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmTopLevelShell.hh,v 1.6 2006/06/29 21:18:42 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+//Top level shell class
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#ifndef G4OPENGLXMTOPLEVELSHELL_HH
+#define G4OPENGLXMTOPLEVELSHELL_HH
+
+#include "G4OpenGLXmVWidgetShell.hh"
+
+class G4OpenGLXmVWidgetContainer;
+
+class G4OpenGLXmTopLevelShell : public G4OpenGLXmVWidgetShell
+{
+
+public:
+  G4OpenGLXmTopLevelShell(G4OpenGLXmViewer*, char*);   //constructor
+  virtual ~G4OpenGLXmTopLevelShell();  //destructor
+
+  void AddChild (G4OpenGLXmVWidgetContainer*);
+  void Realize ();
+
+  Widget* GetPointerToWidget ();
+  char* GetName ();
+
+private:
+  G4OpenGLXmTopLevelShell (const G4OpenGLXmTopLevelShell&);
+  G4OpenGLXmTopLevelShell& operator = (const G4OpenGLXmTopLevelShell&);
+  char* name;
+  Widget toplevel;
+  Widget top_box;
+  Widget frame;
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmVWidgetComponent.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmVWidgetComponent.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmVWidgetComponent.hh	(revision 529)
@@ -0,0 +1,60 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmVWidgetComponent.hh,v 1.6 2006/06/29 21:18:44 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+//Base class for all Motif component widgets
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#ifndef G4OPENGLXMVWIDGETCOMPONENT_HH
+#define G4OPENGLXMVWIDGETCOMPONENT_HH
+
+#include "G4OpenGLXmVWidgetObject.hh"
+
+class G4OpenGLXmVWidgetContainer;
+
+class G4OpenGLXmVWidgetComponent : public G4OpenGLXmVWidgetObject
+{
+
+public:
+  G4OpenGLXmVWidgetComponent();           //constructor
+  virtual ~G4OpenGLXmVWidgetComponent();  //destructor
+
+  virtual void AddYourselfTo (G4OpenGLXmVWidgetContainer*) = 0;
+
+  virtual Widget* GetPointerToParent () = 0;
+  virtual Widget* GetPointerToWidget () = 0;
+
+private:
+  
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmVWidgetContainer.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmVWidgetContainer.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmVWidgetContainer.hh	(revision 529)
@@ -0,0 +1,62 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmVWidgetContainer.hh,v 1.6 2006/06/29 21:18:46 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+//Base class for all Motif container widgets
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#ifndef G4OPENGLXMVWIDGETCONTAINER_HH
+#define G4OPENGLXMVWIDGETCONTAINER_HH
+
+#include "G4OpenGLXmVWidgetObject.hh"
+
+class G4OpenGLXmVWidgetShell;
+class G4OpenGLXmVWidgetComponent;
+
+class G4OpenGLXmVWidgetContainer : public G4OpenGLXmVWidgetObject
+{
+
+public:
+  G4OpenGLXmVWidgetContainer();           //constructor
+  virtual ~G4OpenGLXmVWidgetContainer();  //destructor
+
+  virtual void AddChild (G4OpenGLXmVWidgetComponent*) = 0;
+  virtual void AddYourselfTo (G4OpenGLXmVWidgetShell*) = 0;
+
+  virtual Widget* GetPointerToParent () = 0;
+  virtual Widget* GetPointerToWidget () = 0;
+  
+private:
+
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmVWidgetObject.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmVWidgetObject.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmVWidgetObject.hh	(revision 529)
@@ -0,0 +1,68 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmVWidgetObject.hh,v 1.6 2006/06/29 21:18:48 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+//Virtual base class for all Motif widgets.
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#ifndef G4OPENGLXMVWIDGETOBJECT_HH
+#define G4OPENGLXMVWIDGETOBJECT_HH
+
+#include "globals.hh"
+#include <Xm/Xm.h>
+#include "X11/Intrinsic.h"
+#include <X11/Xlib.h>
+#include "G4OpenGLXmViewer.hh"
+
+class G4OpenGLXmVWidgetObject {
+
+public:
+
+  G4OpenGLXmVWidgetObject ();          //constructor
+  virtual ~G4OpenGLXmVWidgetObject (); //destructor
+  
+  G4OpenGLXmViewer* GetView ();  //access to the pView
+  void ProcesspView ();
+
+protected:
+  G4OpenGLXmVWidgetObject (const G4OpenGLXmVWidgetObject&);
+  G4OpenGLXmVWidgetObject& operator = (const G4OpenGLXmVWidgetObject&);
+  G4OpenGLXmViewer* pView;
+  Colormap cmap;
+  Pixel borcol;
+  Pixel bgnd;
+  unsigned int depth;
+  Visual* visual;
+  Widget top;
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmVWidgetShell.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmVWidgetShell.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmVWidgetShell.hh	(revision 529)
@@ -0,0 +1,58 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmVWidgetShell.hh,v 1.6 2006/06/29 21:18:50 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+//Base class for all Motif window widgets (shells)
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#ifndef G4OPENGLXMVWIDGETSHELL_HH
+#define G4OPENGLXMVWIDGETSHELL_HH
+
+#include "G4OpenGLXmVWidgetObject.hh"
+
+class G4OpenGLXmVWidgetContainer;
+
+class G4OpenGLXmVWidgetShell : public G4OpenGLXmVWidgetObject
+{
+
+public:
+  G4OpenGLXmVWidgetShell();   //constructor
+  virtual ~G4OpenGLXmVWidgetShell();  //destructor
+
+  virtual Widget* GetPointerToWidget() = 0;
+  virtual void AddChild (G4OpenGLXmVWidgetContainer*) = 0;
+  virtual void Realize () = 0;
+
+private:
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmViewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmViewer.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmViewer.hh	(revision 529)
@@ -0,0 +1,400 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmViewer.hh,v 1.10 2006/06/29 21:18:52 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Andrew Walkden  10th February 1997
+// G4OpenGLXmViewer : Class derived from G4OpenGLXViewer, to provide
+//                    (Motif) widget OpenGL functionality for GEANT4.
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#ifndef G4OPENGLXMVIEWER_HH
+#define G4OPENGLXMVIEWER_HH
+
+#include "G4OpenGLXViewer.hh"
+#include "G4OpenGLSceneHandler.hh"
+#include "globals.hh"
+
+#include <Xm/Xm.h>
+#include <Xm/MainW.h>
+#include <Xm/Label.h>
+#include <Xm/Form.h>
+#include <Xm/RowColumn.h>
+#include <Xm/PushB.h>
+#include <Xm/ToggleB.h>
+#include <Xm/ArrowBG.h>
+#include <Xm/CascadeB.h>
+#include <Xm/DrawingA.h>
+#include <Xm/Frame.h>
+#include <X11/keysym.h>
+#include <Xm/XmStrDefs.h>
+#include <X11/Xmu/StdCmap.h>
+#include <Xm/TextF.h>
+#include <Xm/ToggleB.h>
+#include <X11/Shell.h>
+#include <Xm/Separator.h>
+#include <Xm/Scale.h>
+
+class G4OpenGLXmTopLevelShell;
+class G4OpenGLXmRadioButton;
+class G4OpenGLXmPushButton;
+class G4OpenGLXmSliderBar;
+class G4OpenGLXmBox;
+class G4OpenGLXmTextField;
+class G4OpenGLXmFramedBox;
+class G4OpenGLXmFourArrowButtons;
+class G4OpenGLXmSeparator;
+
+class G4OpenGLXmViewer: public G4OpenGLXViewer {
+
+public:
+  G4OpenGLXmViewer (G4OpenGLSceneHandler& scene);
+  virtual ~G4OpenGLXmViewer ();
+  
+protected:
+  virtual void ShowView ();
+  void GetXmConnection ();
+  virtual void CreateMainWindow ();
+
+  XtAppContext                      app;
+  XtWorkProcId                      workId;
+  Widget                            toplevel, 
+                                    shell,
+                                    main_win, 
+                                    menubar,
+                                    style_cascade,
+                                    actions_cascade,
+                                    misc_cascade,
+                                    spec_cascade,
+                                    rep_style_pullright, 
+                                    drawing_style_pullright, 
+                                    background_color_pullright, 
+                                    transparency_pullright, 
+                                    antialias_pullright, 
+                                    haloing_pullright, 
+                                    aux_edge_pullright, 
+                                    frame, 
+                                    glxarea;
+  
+  XmString                          style_str,
+                                    actions_str,
+                                    misc_str,
+                                    spec_str,
+                                    rep_str,
+                                    draw_str,
+                                    polyhedron_str,
+                                    nurbs_str,
+                                    wireframe_str,
+                                    hlr_str,
+                                    hsr_str,
+                                    hlhsr_str,
+                                    set_str,
+				    rot_str,
+				    pan_str,
+				    exit_str,
+				    quit_str,
+                                    print_str,
+				    white_str,
+				    black_str,
+				    anti_str,
+				    trans_str,
+				    halo_str,
+				    aux_edge_str,
+				    bgnd_str,
+				    off_str,
+				    on_str;
+
+  G4double                          zoom_high,
+                                    zoom_low,
+                                    pan_low,
+                                    pan_high,
+                                    dolly_low,
+                                    dolly_high,
+                                    fov,
+                                    rot_sens_limit,
+                                    pan_sens_limit,
+                                    rot_sens,
+                                    pan_sens,
+                                    wob_sens;
+
+  Pixel                             bgnd, 
+                                    borcol;
+
+  G4bool                            pan_right,
+                                    rotate_right,
+                                    pan_up,
+                                    rotate_up;
+
+  XtIntervalId                      rotation_timer,
+                                    pan_timer,
+                                    wobble_timer;
+
+  G4Vector3D                        original_vp;
+
+  G4int                             frameNo;
+
+  G4OpenGLXmTopLevelShell*          fprotation_top;
+  G4OpenGLXmBox*                    fprotation_button_box;
+  G4OpenGLXmRadioButton*            fprotation_button1;
+  G4OpenGLXmRadioButton*            fprotation_button2;
+  G4OpenGLXmBox*                    fprotation_slider_box;
+  G4OpenGLXmSliderBar*              fprotation_slider;
+  G4OpenGLXmBox*                    fprotation_arrow_box;
+  G4OpenGLXmFourArrowButtons*       fprotation_arrow;
+
+  G4OpenGLXmTopLevelShell*          fppanning_top; 
+  G4OpenGLXmFramedBox*              fppanning_box;
+  G4OpenGLXmFourArrowButtons*       fppanning_arrows;
+  G4OpenGLXmSliderBar*              fppanning_slider;
+  G4OpenGLXmFramedBox*              fpzoom_box;
+  G4OpenGLXmSliderBar*              fpzoom_slider;
+  G4OpenGLXmFramedBox*              fpdolly_box;
+  G4OpenGLXmSliderBar*              fpdolly_slider;
+
+  G4OpenGLXmTopLevelShell*          fpsetting_top;
+  G4OpenGLXmFramedBox*              fpsetting_box;
+  G4OpenGLXmTextField*              fppan_set;
+  G4OpenGLXmTextField*              fprot_set;
+  G4OpenGLXmTextField*              fpzoom_upper;
+  G4OpenGLXmTextField*              fpzoom_lower;
+  G4OpenGLXmTextField*              fpdolly_upper;
+  G4OpenGLXmTextField*              fpdolly_lower;
+  G4OpenGLXmPushButton*             fpok_button;
+
+  G4OpenGLXmTopLevelShell*          fpmiscellany_top;
+  G4OpenGLXmFramedBox*              fpwobble_box;
+  G4OpenGLXmPushButton*             fpwobble_button;
+  G4OpenGLXmSliderBar*              fpwobble_slider;
+  G4OpenGLXmFramedBox*              fpreset_box;
+  G4OpenGLXmPushButton*             fpreset_button;
+  G4OpenGLXmFramedBox*              fpproj_style_box;
+  G4OpenGLXmRadioButton*            fporthogonal_button;
+  G4OpenGLXmRadioButton*            fpperspective_button;
+  G4OpenGLXmTextField*              fpfov_text;
+
+  G4OpenGLXmTopLevelShell*          fpprint_top;
+  G4OpenGLXmFramedBox*              fpprint_box;
+  G4OpenGLXmFramedBox*              fpprint_col_box;
+  G4OpenGLXmFramedBox*              fpprint_style_box;
+  G4OpenGLXmTextField*              fpprint_text;
+  G4OpenGLXmPushButton*             fpprint_button;
+  G4OpenGLXmSeparator*              fpprint_line;
+  G4OpenGLXmRadioButton*            fpprint_col_radio1;
+  G4OpenGLXmRadioButton*            fpprint_col_radio2;
+  G4OpenGLXmRadioButton*            fpprint_style_radio1;
+  G4OpenGLXmRadioButton*            fpprint_style_radio2;
+
+public:
+
+  static void expose_callback (Widget w, 
+			       XtPointer clientData, 
+			       XtPointer callData);
+  
+  static void resize_callback (Widget w, 
+			       XtPointer clientData, 
+			       XtPointer callData);
+  
+  static void actions_callback (Widget w, 
+				XtPointer clientData, 
+				XtPointer callData);
+  
+  static void misc_callback (Widget w, 
+			     XtPointer clientData, 
+			     XtPointer callData);
+  
+  static void Add_set_field (char* widget, 
+			     char* widget_text, 
+			     Widget* row_col_box, 
+			     Widget* wid, 
+			     G4double* val,
+			     G4OpenGLXmViewer* pView);
+  
+  static void zoom_callback (Widget w, 
+			     XtPointer clientData, 
+			     XtPointer callData);
+  
+  static void dolly_callback (Widget w, 
+			      XtPointer clientData, 
+			      XtPointer callData);
+  
+  static void pan_left_right_callback (Widget w, 
+				       XtPointer clientData, 
+				       XtPointer callData);
+  
+  static void left_right_pan_callback (XtPointer clientData, 
+				       XtIntervalId* timer_id); 
+  
+  static void theta_rotation_callback (Widget w, 
+				       XtPointer clientData, 
+				       XtPointer callData);
+  
+  static void phi_rotation_callback (Widget w, 
+				     XtPointer clientData, 
+				     XtPointer callData);
+  
+  static void pan_up_down_callback (Widget w, 
+				    XtPointer clientData, 
+				    XtPointer callData);
+  
+  static void up_down_pan_callback (XtPointer clientData, 
+				    XtIntervalId* timer_id); 
+  
+  static void drawing_style_callback (Widget w, 
+				      XtPointer clientData, 
+				      XtPointer callData);
+  
+  static void rep_style_callback (Widget w, 
+				  XtPointer clientData, 
+				  XtPointer callData);
+  
+  static void background_color_callback (Widget w, 
+					 XtPointer clientData, 
+					 XtPointer callData);
+  
+  static void set_rot_subject_callback (Widget w, 
+					XtPointer clientData, 
+					XtPointer callData);
+  
+  static void set_rot_sens_callback (Widget w, 
+				     XtPointer clientData, 
+				     XtPointer callData);
+  
+  static void set_pan_sens_callback (Widget w, 
+				     XtPointer clientData, 
+				     XtPointer callData);
+  
+  static void set_wob_sens_callback (Widget w, 
+				     XtPointer clientData, 
+				     XtPointer callData);
+  
+  static void projection_callback (Widget w, 
+				   XtPointer clientData, 
+				   XtPointer callData);
+  
+  static void wobble_callback (Widget w, 
+			       XtPointer clientData, 
+			       XtPointer callData);
+  
+  static void reset_callback (Widget w, 
+			      XtPointer clientData, 
+			      XtPointer callData);
+  
+  static void update_panels_callback (Widget w, 
+				      XtPointer clientData, 
+				      XtPointer callData);
+  
+  static void wobble_timer_callback (XtPointer clientData, 
+				     XtIntervalId* timerid);
+  
+  static void Add_radio_box (char* label_string,
+			     Widget* parent_frame_widget,
+			     XtCallbackRec* radio_box_cb,
+			     G4int num_buttons,
+			     G4int default_button,
+			     char* radio_box_name,
+			     char** button_names,
+			     G4OpenGLXmViewer* pView);
+  
+  static void Add_four_arrow_buttons (G4OpenGLXmViewer* pView,
+				      XtCallbackRec** arrow_callbacks,
+				      Widget* parent_widget);
+  
+  static void Add_slider_box (char* label_string,
+			      G4int num_sliders,
+			      char** slider_name,
+			      G4OpenGLXmViewer* pView,
+			      G4double* min_array,
+			      G4double* max_array,
+			      G4double* value_array,
+			      G4bool* show,
+			      short* decimals,
+			      unsigned char* orientation,
+			      unsigned char* direction,
+			      XtCallbackRec** slider_box_cb,
+			      Widget* parent_frame_widget);
+  
+  static void rotate_in_theta (XtPointer clientData,
+			       XtIntervalId* timer_id);
+  
+  static void rotate_in_phi (XtPointer clientData,
+			     XtIntervalId* timer_id);
+  
+  static void get_double_value_callback (Widget w, 
+					 XtPointer clientData, 
+					 XtPointer callData); 
+  
+  static void get_text_callback (Widget w, 
+				 XtPointer clientData, 
+				 XtPointer callData); 
+  
+  static void transparency_callback (Widget w, 
+				     XtPointer clientData, 
+				     XtPointer callData); 
+  
+  static void antialias_callback (Widget w, 
+				  XtPointer clientData, 
+				  XtPointer callData); 
+
+  static void haloing_callback (Widget w, 
+				XtPointer clientData, 
+				XtPointer callData); 
+
+  static void aux_edge_callback (Widget w, 
+				XtPointer clientData, 
+				XtPointer callData); 
+
+  static void set_print_colour_callback (Widget w, 
+					 XtPointer clientData, 
+					 XtPointer callData); 
+
+  static void set_print_style_callback (Widget w, 
+					XtPointer clientData, 
+					XtPointer callData); 
+
+  static void print_callback (Widget w, 
+			      XtPointer clientData, 
+			      XtPointer callData); 
+
+  static G4bool get_boolean_userData (Widget w);
+
+  static G4int  get_int_userData (Widget w);
+
+  friend class G4OpenGLXmVWidgetObject;
+  friend class G4OpenGLXmViewerMessenger;
+  
+private:
+  G4OpenGLXmViewer (const G4OpenGLXmViewer&);
+  G4OpenGLXmViewer& operator = (const G4OpenGLXmViewer&);
+  
+};
+
+#endif
+
+#endif
+  
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmViewerMessenger.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmViewerMessenger.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLXmViewerMessenger.hh	(revision 529)
@@ -0,0 +1,66 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmViewerMessenger.hh,v 1.4 2006/06/29 21:18:54 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#ifndef G4OPENGLXMVIEWERMESSENGER_HH
+#define G4OPENGLXMVIEWERMESSENGER_HH
+
+#include "G4UImessenger.hh"
+
+#include "G4String.hh"
+
+class G4OpenGLXmViewer;
+class G4UIdirectory;
+class G4UIcmdWithADoubleAndUnit;
+class G4UIcmdWithADouble;
+
+class G4OpenGLXmViewerMessenger: public G4UImessenger {
+public:
+  static G4OpenGLXmViewerMessenger* GetInstance();  // Singleton constructor.
+  ~G4OpenGLXmViewerMessenger();
+  void SetNewValue (G4UIcommand*, G4String);
+
+private:
+  G4OpenGLXmViewerMessenger();  // Private constructor.
+  static G4OpenGLXmViewerMessenger* fpInstance;
+  G4UIdirectory* fpDirectory;
+  G4UIdirectory* fpDirectorySet;
+  G4UIcmdWithADoubleAndUnit* fpCommandSetDollyHigh;
+  G4UIcmdWithADoubleAndUnit* fpCommandSetDollyLow;
+  G4UIcmdWithADoubleAndUnit* fpCommandSetPanHigh;
+  G4UIcmdWithADoubleAndUnit* fpCommandSetRotationHigh;
+  G4UIcmdWithADouble* fpCommandSetZoomHigh;
+  G4UIcmdWithADouble* fpCommandSetZoomLow;
+};
+
+#endif
+
+#endif
+
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLFontBaseStore.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLFontBaseStore.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLFontBaseStore.cc	(revision 529)
@@ -0,0 +1,59 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLFontBaseStore.cc,v 1.3 2006/06/29 21:18:56 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+
+#include "G4OpenGLFontBaseStore.hh"
+
+std::map<G4VViewer*,std::vector<G4OpenGLFontBaseStore::FontInfo> >
+G4OpenGLFontBaseStore::fFontBaseMap;
+
+void G4OpenGLFontBaseStore::AddFontBase
+(G4VViewer* viewer,G4int fontBase,
+ G4double size, const G4String& fontName) {
+  fFontBaseMap[viewer].push_back(FontInfo(fontName, size, fontBase));
+}
+
+G4int G4OpenGLFontBaseStore::GetFontBase(G4VViewer* viewer, G4double size) {
+  G4int fontBase = -1;
+  std::map<G4VViewer*,std::vector<FontInfo> >::const_iterator i;
+  i = fFontBaseMap.find(viewer);
+  if (i != fFontBaseMap.end()) {
+    G4double sizeDiscrepancy = 9999.;
+    std::vector<FontInfo>::const_iterator j, k;
+    for (j = i->second.begin(); j != i->second.end(); ++j) {
+      G4double d = std::abs(size - j->fSize);
+      if (d < sizeDiscrepancy) {
+	sizeDiscrepancy = d;
+	k = j;
+      }
+    }
+    fontBase = k->fFontBase;
+  }
+  return fontBase;
+}
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateSceneHandler.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateSceneHandler.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateSceneHandler.cc	(revision 529)
@@ -0,0 +1,205 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLImmediateSceneHandler.cc,v 1.24 2006/09/04 12:03:25 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  10th February 1997
+// OpenGL immediate scene - draws immediately to buffer
+//                           (saving space on server).
+
+#ifdef G4VIS_BUILD_OPENGL_DRIVER
+
+// Included here - problems with HP compiler if not before other includes?
+#include "G4NURBS.hh"
+
+// Here follows a special for Mesa, the OpenGL emulator.  Does not affect
+// other OpenGL's, as far as I'm aware.   John Allison 18/9/96.
+#define CENTERLINE_CLPP  /* CenterLine C++ workaround: */
+// Also seems to be required for HP's CC and AIX xlC, at least.
+
+#include "G4OpenGLImmediateSceneHandler.hh"
+
+#include "G4OpenGLTransform3D.hh"
+#include "G4Polyline.hh"
+#include "G4Circle.hh"
+#include "G4Square.hh"
+
+G4OpenGLImmediateSceneHandler::G4OpenGLImmediateSceneHandler (G4VGraphicsSystem& system,
+						const G4String& name):
+G4OpenGLSceneHandler (system, fSceneIdCount++, name)
+{}
+
+G4OpenGLImmediateSceneHandler::~G4OpenGLImmediateSceneHandler ()
+{}
+
+#include <iomanip>
+
+void G4OpenGLImmediateSceneHandler::AddPrimitivePreamble(const G4Visible& visible)
+{
+  const G4Colour& c = GetColour (visible);
+  glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
+}
+
+void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Polyline& polyline)
+{
+  AddPrimitivePreamble(polyline);
+  G4OpenGLSceneHandler::AddPrimitive(polyline);
+}
+
+void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Circle& circle)
+{
+  AddPrimitivePreamble(circle);
+  G4OpenGLSceneHandler::AddPrimitive(circle);
+}
+
+void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Square& square)
+{
+  AddPrimitivePreamble(square);
+  G4OpenGLSceneHandler::AddPrimitive(square);
+}
+
+void G4OpenGLImmediateSceneHandler::BeginPrimitives
+(const G4Transform3D& objectTransformation) {
+  G4VSceneHandler::BeginPrimitives (objectTransformation);
+  glPushMatrix();
+  G4OpenGLTransform3D oglt (objectTransformation);
+
+  /*************************** Check matrix.
+  const GLdouble* m = oglt.GetGLMatrix ();
+  G4cout << "G4OpenGLTransform3D matrix:";
+  for (int i = 0; i < 16; i++) {
+    if ((i % 4) == 0) G4cout << '\n';
+    G4cout << std::setw (15) << m[i];
+  }
+  G4cout << G4endl;
+  *****************************************/
+
+  glMultMatrixd (oglt.GetGLMatrix ());
+}
+
+void G4OpenGLImmediateSceneHandler::EndPrimitives ()
+{
+  glPopMatrix();
+
+  // See all primitives immediately...
+  glFlush ();
+
+  G4VSceneHandler::EndPrimitives ();
+}
+
+void G4OpenGLImmediateSceneHandler::BeginPrimitives2D()
+{
+  G4VSceneHandler::BeginPrimitives2D();
+
+  // Push current 3D world matrices and load identity to define screen
+  // coordinates...
+  glMatrixMode (GL_PROJECTION);
+  glPushMatrix();
+  glLoadIdentity();
+  glOrtho (-1., 1., -1., 1., -DBL_MAX, DBL_MAX);
+  glMatrixMode (GL_MODELVIEW);
+  glPushMatrix();
+  glLoadIdentity();
+}
+
+void G4OpenGLImmediateSceneHandler::EndPrimitives2D()
+{
+  // Pop current 3D world matrices back again...
+  glMatrixMode (GL_PROJECTION);
+  glPopMatrix();
+  glMatrixMode (GL_MODELVIEW);
+  glPopMatrix();
+
+  // See all primitives immediately...
+  glFlush ();
+
+  G4VSceneHandler::EndPrimitives2D ();
+}
+
+void G4OpenGLImmediateSceneHandler::BeginModeling () {
+  G4VSceneHandler::BeginModeling();
+}
+
+void G4OpenGLImmediateSceneHandler::EndModeling () {
+  G4VSceneHandler::EndModeling ();
+}
+
+void G4OpenGLImmediateSceneHandler::ClearTransientStore () {
+
+  G4VSceneHandler::ClearTransientStore ();
+
+  // Make sure screen corresponds to graphical database...
+  if (fpViewer) {
+    fpViewer -> SetView ();
+    fpViewer -> ClearView ();
+    fpViewer -> DrawView ();
+  }
+}
+
+void G4OpenGLImmediateSceneHandler::RequestPrimitives (const G4VSolid& solid)
+{
+  if (fReadyForTransients) {
+    // Always draw transient solids, e.g., hits represented as solids.
+    // (As we have no control over the order of drawing of transient
+    // objects, we cannot do anything about transparent ones, as
+    // below, so always draw them.)
+    G4VSceneHandler::RequestPrimitives (solid);
+    return;
+  }
+
+  // For non-transient (run-duration) objects, ensure transparent
+  // objects are drawn last.  The problem of
+  // blending/transparency/alpha is quite a tricky one - see History
+  // of opengl-V07-01-01/2/3.
+  // Get vis attributes - pick up defaults if none.
+  const G4VisAttributes* pVA =
+    fpViewer -> GetApplicableVisAttributes(fpVisAttribs);
+  const G4Colour& c = pVA -> GetColour ();
+  G4double opacity = c.GetAlpha ();
+
+  if (!fSecondPass) {
+    G4bool transparency_enabled = true;
+    G4OpenGLViewer* pViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
+    if (pViewer) transparency_enabled = pViewer->transparency_enabled;
+    if (transparency_enabled && opacity < 1.) {
+      // On first pass, transparent objects are not drawn, but flag is set...
+      fSecondPassRequested = true;
+      return;
+    }
+  }
+
+  // On second pass, opaque objects are not drwan...
+  if (fSecondPass && opacity >= 1.) return;
+
+  // Else invoke base class method...
+  G4VSceneHandler::RequestPrimitives (solid);
+}
+
+G4int G4OpenGLImmediateSceneHandler::fSceneIdCount = 0;
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateViewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateViewer.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateViewer.cc	(revision 529)
@@ -0,0 +1,70 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLImmediateViewer.cc,v 1.8 2006/09/04 12:07:59 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  7th February 1997
+// Class G4OpenGLImmediateViewer : Encapsulates the `immediateness' of
+//                               an OpenGL view, for inheritance by
+//                               derived (X, Xm...) classes.
+
+#ifdef G4VIS_BUILD_OPENGL_DRIVER
+
+#include "G4OpenGLImmediateViewer.hh"
+
+G4OpenGLImmediateViewer::G4OpenGLImmediateViewer (G4OpenGLImmediateSceneHandler& scene):
+G4VViewer (scene, -1),
+G4OpenGLViewer (scene)
+{}
+
+void G4OpenGLImmediateViewer::ProcessView ()
+{
+  const G4Planes& cutaways = fVP.GetCutawayPlanes();
+  G4bool cutawayUnion = fVP.IsCutaway() &&
+    fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion;
+  size_t nPasses = cutawayUnion? cutaways.size(): 1;
+  for (size_t i = 0; i < nPasses; ++i) {
+
+    if (cutawayUnion) {
+      double a[4];
+      a[0] = cutaways[i].a();
+      a[1] = cutaways[i].b();
+      a[2] = cutaways[i].c();
+      a[3] = cutaways[i].d();
+      glClipPlane (GL_CLIP_PLANE2, a);
+      glEnable (GL_CLIP_PLANE2);
+    }
+
+    NeedKernelVisit ();  // Always need to visit G4 kernel.
+    G4VViewer::ProcessView ();
+
+    if (cutawayUnion) glDisable (GL_CLIP_PLANE2);
+  }
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateWin32.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateWin32.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateWin32.cc	(revision 529)
@@ -0,0 +1,80 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLImmediateWin32.cc,v 1.11 2006/08/14 12:07:19 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// OpenGLImmediateWin32 graphics system factory.
+
+#ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER
+
+#include "G4VisFeaturesOfOpenGL.hh"
+#include "G4VSceneHandler.hh"
+#include "G4OpenGLSceneHandler.hh"
+#include "G4OpenGLViewer.hh"
+#include "G4OpenGLImmediateWin32.hh"
+#include "G4OpenGLImmediateWin32Viewer.hh"
+#include "G4OpenGLViewerMessenger.hh"
+
+G4OpenGLImmediateWin32::G4OpenGLImmediateWin32 ():
+  G4VGraphicsSystem ("OpenGLImmediateWin32",
+		     "OGLIWin32",
+		     G4VisFeaturesOfOpenGLIWin32 (),
+		     G4VGraphicsSystem::threeD)
+{
+  G4OpenGLViewerMessenger::GetInstance();
+}
+
+G4VSceneHandler* G4OpenGLImmediateWin32::CreateSceneHandler
+(const G4String& name) {
+  G4VSceneHandler* pScene = new G4OpenGLImmediateSceneHandler (*this, name);
+  return    pScene;
+}
+
+G4VViewer* G4OpenGLImmediateWin32::CreateViewer
+(G4VSceneHandler& scene, const G4String& name) {
+  G4VViewer* pView =
+    new G4OpenGLImmediateWin32Viewer
+    ((G4OpenGLImmediateSceneHandler&) scene, name);
+  if (pView) {
+    if (pView -> GetViewId () < 0) {
+      G4cerr << "G4OpenGLImmediateWin32::CreateViewer: error flagged by negative"
+	" view id in G4OpenGLImmediateWin32Viewer creation."
+	"\n Destroying view and returning null pointer."
+	   << G4endl;
+      delete pView;
+      pView = 0;
+    }
+  }
+  else {
+    G4cerr << "G4OpenGLImmediateWin32::CreateViewer: null pointer on"
+      " new G4OpenGLImmediateWin32Viewer." << G4endl;
+  }
+  return pView;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateWin32Viewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateWin32Viewer.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateWin32Viewer.cc	(revision 529)
@@ -0,0 +1,120 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLImmediateWin32Viewer.cc,v 1.16 2006/07/03 16:38:13 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Class G4OpenGLImmediateWin32Viewer : a class derived from G4OpenGLWin32Viewer and
+//                                G4OpenGLImmediateViewer.
+
+#ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER
+
+#include "G4OpenGLImmediateWin32Viewer.hh"
+
+#include "G4ios.hh"
+
+G4OpenGLImmediateWin32Viewer::G4OpenGLImmediateWin32Viewer
+(G4OpenGLImmediateSceneHandler& sceneHandler,
+ const G4String&  name):
+G4OpenGLViewer (sceneHandler),
+G4OpenGLWin32Viewer (sceneHandler),
+G4OpenGLImmediateViewer (sceneHandler),
+G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name) {
+
+  if (fViewId < 0) return;  // In case error in base class instantiation.
+}
+
+void G4OpenGLImmediateWin32Viewer::Initialise () {
+
+// ensure a suitable window was found
+
+  CreateGLWin32Context ();
+  CreateMainWindow ();
+  CreateFontLists ();
+
+  // If a double buffer context has been forced upon us, ignore the
+  // back buffer for this OpenGLImmediate view.
+  glDrawBuffer (GL_FRONT);
+
+  // clear the buffers and window.
+  ClearView ();
+  FinishView ();
+
+  glDepthFunc (GL_LEQUAL);
+  glDepthMask (GL_TRUE);
+}
+
+void G4OpenGLImmediateWin32Viewer::DrawView () {
+
+  // If a double buffer context has been forced upon us, ignore the
+  // back buffer for this OpenGLImmediate view.
+  glDrawBuffer (GL_FRONT);
+
+  G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
+
+  //Make sure current viewer is attached and clean...
+  //Win32 version needed
+  //glXMakeCurrent (dpy, win, cx);
+  glViewport (0, 0, WinSize_x, WinSize_y);
+
+  if(style!=G4ViewParameters::hlr &&
+     haloing_enabled) {
+
+    HaloingFirstPass ();
+    NeedKernelVisit ();
+    ProcessView ();
+    glFlush ();
+
+    HaloingSecondPass ();
+
+  }
+
+  NeedKernelVisit ();  // Always need to visit G4 kernel.
+  ProcessView ();
+  FinishView ();
+
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void G4OpenGLImmediateWin32Viewer::FinishView (
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(!fHDC) return;
+
+  glFlush ();
+
+  // Empty the Windows message queue :
+  MSG event;
+  while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
+    ::TranslateMessage(&event);
+    ::DispatchMessage (&event);
+  }
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateX.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateX.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateX.cc	(revision 529)
@@ -0,0 +1,83 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLImmediateX.cc,v 1.12 2006/08/14 12:07:19 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  27th March 1996
+// OpenGL graphics system factory.
+
+#ifdef G4VIS_BUILD_OPENGLX_DRIVER
+
+#include "G4VisFeaturesOfOpenGL.hh"
+#include "G4VSceneHandler.hh"
+#include "G4OpenGLSceneHandler.hh"
+#include "G4OpenGLViewer.hh"
+#include "G4OpenGLImmediateX.hh"
+#include "G4OpenGLImmediateXViewer.hh"
+#include "G4OpenGLViewerMessenger.hh"
+#include "G4OpenGLXViewerMessenger.hh"
+
+G4OpenGLImmediateX::G4OpenGLImmediateX ():
+  G4VGraphicsSystem ("OpenGLImmediateX",
+		     "OGLIX",
+		     G4VisFeaturesOfOpenGLIX (),
+		     G4VGraphicsSystem::threeD)
+{
+  G4OpenGLViewerMessenger::GetInstance();
+  G4OpenGLXViewerMessenger::GetInstance();
+}
+
+G4OpenGLImmediateX::~G4OpenGLImmediateX () {}
+
+G4VSceneHandler* G4OpenGLImmediateX::CreateSceneHandler (const G4String& name) {
+  G4VSceneHandler* pScene = new G4OpenGLImmediateSceneHandler (*this, name);
+  return    pScene;
+}
+
+G4VViewer* G4OpenGLImmediateX::CreateViewer (G4VSceneHandler& scene,
+					 const G4String& name) {
+  G4VViewer* pView =
+    new G4OpenGLImmediateXViewer ((G4OpenGLImmediateSceneHandler&) scene, name);
+  if (pView) {
+    if (pView -> GetViewId () < 0) {
+      G4cerr << "G4OpenGLImmediateX::CreateViewer: error flagged by negative"
+	" view id in G4OpenGLImmediateXViewer creation."
+	"\n Destroying view and returning null pointer."
+	   << G4endl;
+      delete pView;
+      pView = 0;
+    }
+  }
+  else {
+    G4cerr << "G4OpenGLImmediateX::CreateViewer: null pointer on"
+      " new G4OpenGLImmediateXViewer." << G4endl;
+  }
+  return pView;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateXViewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateXViewer.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateXViewer.cc	(revision 529)
@@ -0,0 +1,114 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLImmediateXViewer.cc,v 1.16 2006/07/03 16:38:13 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  7th February 1997
+// Class G4OpenGLImmediateXViewer : a class derived from G4OpenGLXViewer and
+//                                G4OpenGLImmediateViewer.
+
+#ifdef G4VIS_BUILD_OPENGLX_DRIVER
+
+#include "G4OpenGLImmediateXViewer.hh"
+
+#include "G4ios.hh"
+
+G4OpenGLImmediateXViewer::
+G4OpenGLImmediateXViewer (G4OpenGLImmediateSceneHandler& sceneHandler,
+			  const G4String&  name)
+ : G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
+   G4OpenGLViewer (sceneHandler),
+   G4OpenGLXViewer (sceneHandler),
+   G4OpenGLImmediateViewer (sceneHandler)
+{
+  if (fViewId < 0) return;  // In case error in base class instantiation.
+
+// ensure a suitable window was found
+  if (!vi_immediate) {
+    G4cerr << "G4OpenGLImmediateXViewer::G4OpenGLImmediateXViewer -"
+      " G4OpenGLXViewer couldn't get a visual." << G4endl;  
+    fViewId = -1;  // This flags an error.
+    return;
+  }
+}
+
+G4OpenGLImmediateXViewer::~G4OpenGLImmediateXViewer () {}
+
+void G4OpenGLImmediateXViewer::Initialise () {
+
+  CreateGLXContext (vi_immediate);
+  CreateMainWindow ();
+  CreateFontLists ();
+
+  InitializeGLView ();
+
+  // clear the buffers and window.
+  ClearView ();
+  FinishView ();
+
+  // If a double buffer context has been forced upon us, ignore the
+  // back buffer for this OpenGLImmediate view.
+  glDrawBuffer (GL_FRONT);
+
+  glDepthFunc (GL_LEQUAL);
+  glDepthMask (GL_TRUE);
+}
+
+void G4OpenGLImmediateXViewer::DrawView () {
+
+  G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
+
+  //Make sure current viewer is attached and clean...
+  glXMakeCurrent (dpy, win, cx);
+  glViewport (0, 0, WinSize_x, WinSize_y);
+
+  if(style!=G4ViewParameters::hlr &&
+     haloing_enabled) {
+
+    HaloingFirstPass ();
+    NeedKernelVisit ();
+    ProcessView ();
+    glFlush ();
+
+    HaloingSecondPass ();
+
+  }
+
+  NeedKernelVisit ();  // Always need to visit G4 kernel.
+  ProcessView ();
+  FinishView ();
+
+}
+
+void G4OpenGLImmediateXViewer::FinishView () {
+  glXWaitGL (); //Wait for effects of all previous OpenGL commands to
+                //be propogated before progressing.
+  glFlush ();
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateXm.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateXm.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateXm.cc	(revision 529)
@@ -0,0 +1,82 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLImmediateXm.cc,v 1.13 2006/08/14 12:07:19 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  10th February 1997
+// OpenGL graphics system factory.
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4VisFeaturesOfOpenGL.hh"
+#include "G4VSceneHandler.hh"
+#include "G4OpenGLSceneHandler.hh"
+#include "G4OpenGLViewer.hh"
+#include "G4OpenGLImmediateXm.hh"
+#include "G4OpenGLImmediateXmViewer.hh"
+#include "G4OpenGLViewerMessenger.hh"
+#include "G4OpenGLXmViewerMessenger.hh"
+
+G4OpenGLImmediateXm::G4OpenGLImmediateXm ():
+  G4VGraphicsSystem ("OpenGLImmediateXm",
+		     "OGLIXm",
+		     G4VisFeaturesOfOpenGLIXm (),
+		     G4VGraphicsSystem::threeD)
+{
+  G4OpenGLViewerMessenger::GetInstance();
+  G4OpenGLXmViewerMessenger::GetInstance();
+}
+
+G4OpenGLImmediateXm::~G4OpenGLImmediateXm () {}
+
+G4VSceneHandler* G4OpenGLImmediateXm::CreateSceneHandler (const G4String& name) {
+  G4VSceneHandler* pScene = new G4OpenGLImmediateSceneHandler (*this, name);
+  return    pScene;
+}
+
+G4VViewer* G4OpenGLImmediateXm::CreateViewer (G4VSceneHandler& scene,
+					  const G4String& name) {
+  G4VViewer* pView =
+    new G4OpenGLImmediateXmViewer ((G4OpenGLImmediateSceneHandler&) scene, name);
+  if (pView) {
+    if (pView -> GetViewId () < 0) {
+      G4cerr << "G4OpenGLImmediateXm::CreateViewer: error flagged by"
+	" negative view id in G4OpenGLImmediateXmViewer creation."
+	"\n Destroying view and returning null pointer." << G4endl;
+      delete pView;
+      pView = 0;
+    }
+  }
+  else {
+    G4cerr << "G4OpenGLImmediateXm::CreateViewer: null pointer on"
+      " new G4OpenGLImmediateXmViewer." << G4endl;
+  }
+  return pView;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateXmViewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateXmViewer.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateXmViewer.cc	(revision 529)
@@ -0,0 +1,120 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLImmediateXmViewer.cc,v 1.17 2006/07/03 16:38:13 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  10th February 1997
+// Class G4OpenGLImmediateXmViewer : a class derived from G4OpenGLXmViewer
+//                                     and G4OpenGLImmediateViewer.
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLImmediateXmViewer.hh"
+
+#include "G4ios.hh"
+
+G4OpenGLImmediateXmViewer::
+G4OpenGLImmediateXmViewer(G4OpenGLImmediateSceneHandler& sceneHandler,
+                          const G4String& name)
+ : G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
+   G4OpenGLViewer (sceneHandler),
+   G4OpenGLXmViewer (sceneHandler),
+   G4OpenGLImmediateViewer (sceneHandler)
+{
+  if (fViewId < 0) return;  // In case error in base class instantiation.
+
+// ensure a suitable window was found
+  if (!vi_immediate) {
+    G4cerr << "G4OpenGLImmediateXmViewer::G4OpenGLImmediateXmViewer -"
+      " G4OpenGLXmViewer couldn't get a visual." << G4endl;  
+    fViewId = -1;  // This flags an error.
+    return;
+  }
+}
+
+G4OpenGLImmediateXmViewer::~G4OpenGLImmediateXmViewer () {}
+
+void G4OpenGLImmediateXmViewer::Initialise () {
+
+  CreateGLXContext (vi_immediate);
+  CreateMainWindow ();
+  CreateFontLists ();
+
+  InitializeGLView ();
+
+  // clear the buffers and window.
+  ClearView ();
+  FinishView ();
+
+  glDepthFunc (GL_LEQUAL);
+  glDepthMask (GL_TRUE);
+  
+  glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+  glLineWidth (1.0);
+
+  glEnable (GL_BLEND);
+  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+  // If a double buffer context has been forced upon us, ignore the
+  // back buffer for this OpenGLImmediate view.
+  glDrawBuffer (GL_FRONT);
+}
+
+void G4OpenGLImmediateXmViewer::DrawView () {
+
+  G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
+
+  //Make sure current viewer is attached and clean...
+  glXMakeCurrent (dpy, win, cx);
+  glViewport (0, 0, WinSize_x, WinSize_y);
+
+  if(style!=G4ViewParameters::hlr &&
+     haloing_enabled) {
+
+    HaloingFirstPass ();
+    NeedKernelVisit ();
+    ProcessView ();
+    glFlush ();
+
+    HaloingSecondPass ();
+
+  }
+
+  NeedKernelVisit ();  // Always need to visit G4 kernel.
+  ProcessView ();
+  FinishView ();
+
+}
+
+void G4OpenGLImmediateXmViewer::FinishView () {
+  glXWaitGL (); //Wait for effects of all previous OpenGL commands to
+                //be propogated before progressing.
+  glFlush ();
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLSceneHandler.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLSceneHandler.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLSceneHandler.cc	(revision 529)
@@ -0,0 +1,784 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLSceneHandler.cc,v 1.45 2006/08/30 11:37:34 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  27th March 1996
+// OpenGL stored scene - creates OpenGL display lists.
+// OpenGL immediate scene - draws immediately to buffer
+//                           (saving space on server).
+
+#ifdef G4VIS_BUILD_OPENGL_DRIVER
+
+// Included here - problems with HP compiler if not before other includes?
+#include "G4NURBS.hh"
+
+// Here follows a special for Mesa, the OpenGL emulator.  Does not affect
+// other OpenGL's, as far as I'm aware.   John Allison 18/9/96.
+#define CENTERLINE_CLPP  /* CenterLine C++ workaround: */
+// Also seems to be required for HP's CC and AIX xlC, at least.
+
+#include "G4OpenGLSceneHandler.hh"
+#include "G4OpenGLViewer.hh"
+#include "G4OpenGLFontBaseStore.hh"
+#include "G4OpenGLTransform3D.hh"
+#include "G4Point3D.hh"
+#include "G4Normal3D.hh"
+#include "G4Transform3D.hh"
+#include "G4Polyline.hh"
+#include "G4Text.hh"
+#include "G4Circle.hh"
+#include "G4Square.hh"
+#include "G4VMarker.hh"
+#include "G4Polyhedron.hh"
+#include "G4VisAttributes.hh"
+#include "G4PhysicalVolumeModel.hh"
+#include "G4VPhysicalVolume.hh"
+#include "G4LogicalVolume.hh"
+#include "G4VSolid.hh"
+#include "G4Scene.hh"
+#include "G4VisExtent.hh"
+
+G4OpenGLSceneHandler::G4OpenGLSceneHandler (G4VGraphicsSystem& system,
+			      G4int id,
+			      const G4String& name):
+  G4VSceneHandler (system, id, name)
+{}
+
+G4OpenGLSceneHandler::~G4OpenGLSceneHandler ()
+{
+  ClearStore ();
+}
+
+const GLubyte G4OpenGLSceneHandler::fStippleMaskHashed [128] = {
+  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
+  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
+  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
+  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
+  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
+  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
+  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
+  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
+  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
+  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
+  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
+  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
+  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
+  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
+  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
+  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
+};
+
+const G4Polyhedron* G4OpenGLSceneHandler::CreateSectionPolyhedron ()
+{
+  // Clipping done in G4OpenGLViewer::SetView.
+  return 0;
+
+  // But...OpenGL no longer seems to reconstruct clipped edges, so,
+  // when the BooleanProcessor is up to it, abandon this and use
+  // generic clipping in G4VSceneHandler::CreateSectionPolyhedron...
+  // return G4VSceneHandler::CreateSectionPolyhedron();
+}
+
+const G4Polyhedron* G4OpenGLSceneHandler::CreateCutawayPolyhedron ()
+{
+  // Cutaway done in G4OpenGLViewer::SetView.
+  return 0;
+
+  // But...if not, when the BooleanProcessor is up to it...
+  // return G4VSceneHandler::CreateCutawayPolyhedron();
+}
+
+void G4OpenGLSceneHandler::AddPrimitive (const G4Polyline& line)
+{
+  G4int nPoints = line.size ();
+  if (nPoints <= 0) return;
+
+  // Note: colour treated in sub-class.
+
+  if (fpViewer -> GetViewParameters ().IsMarkerNotHidden ())
+    glDisable (GL_DEPTH_TEST);
+  else {glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LESS);}
+
+  glDisable (GL_LIGHTING);
+
+  G4double lineWidth = GetLineWidth(line);
+  glLineWidth(lineWidth);
+
+  glBegin (GL_LINE_STRIP);
+  for (G4int iPoint = 0; iPoint < nPoints; iPoint++) {
+  G4double x, y, z;
+    x = line[iPoint].x(); 
+    y = line[iPoint].y();
+    z = line[iPoint].z();
+    glVertex3d (x, y, z);
+  }
+  glEnd ();
+}
+
+void G4OpenGLSceneHandler::AddPrimitive (const G4Text& text) {
+
+  const G4Colour& c = GetTextColour (text);  // Picks up default if none.
+  MarkerSizeType sizeType;
+  G4double size = GetMarkerSize (text, sizeType);
+  G4ThreeVector position (text.GetPosition ());
+  G4String textString = text.GetText();
+
+  G4int font_base = G4OpenGLFontBaseStore::GetFontBase(fpViewer,size);
+  if (font_base < 0) {
+    static G4int callCount = 0;
+    ++callCount;
+    if (callCount <= 10 || callCount%100 == 0) {
+      G4cout <<
+	"G4OpenGLSceneHandler::AddPrimitive (const G4Text&) call count "
+	     << callCount <<
+	"\n  No fonts available."
+	"\n  Called with text \""
+	     << text.GetText ()
+	     << "\"\n  at " << position
+	     << ", size " << size
+	     << ", offsets " << text.GetXOffset () << ", " << text.GetYOffset ()
+	     << ", type " << G4int(sizeType)
+	     << ", colour " << c
+	     << G4endl;
+    }
+    return;
+  }
+  const char* textCString = textString.c_str();
+  glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
+  glDisable (GL_DEPTH_TEST);
+  glDisable (GL_LIGHTING);
+  
+  glRasterPos3f(position.x(),position.y(),position.z());
+  // No action on offset or layout at present.
+  glPushAttrib(GL_LIST_BIT);
+  glListBase(font_base);
+  glCallLists(strlen(textCString), GL_UNSIGNED_BYTE, (GLubyte *)textCString);
+  glPopAttrib();
+}
+
+void G4OpenGLSceneHandler::AddPrimitive (const G4Circle& circle) {
+  glEnable (GL_POINT_SMOOTH);
+  AddCircleSquare (circle, 24);
+}
+
+void G4OpenGLSceneHandler::AddPrimitive (const G4Square& square) {
+  glDisable (GL_POINT_SMOOTH);
+  AddCircleSquare (square, 4);
+}
+
+void G4OpenGLSceneHandler::AddCircleSquare
+(const G4VMarker& marker,
+ G4int nSides) {
+
+  // Note: colour treated in sub-class.
+
+  if (fpViewer -> GetViewParameters ().IsMarkerNotHidden ())
+    glDisable (GL_DEPTH_TEST);
+  else {glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LESS);}
+  
+  glDisable (GL_LIGHTING);
+  
+  G4double lineWidth = GetLineWidth(marker);
+  glLineWidth(lineWidth);
+
+  G4VMarker::FillStyle style = marker.GetFillStyle();
+  
+  switch (style) {
+  case G4VMarker::noFill: 
+    glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
+    break;
+    
+  case G4VMarker::hashed:
+    /*
+    G4cout << "Hashed fill style in G4OpenGLSceneHandler."
+	   << "\n  Not implemented.  Using G4VMarker::filled."
+	   << G4endl;
+    */
+    glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
+    glPolygonStipple (fStippleMaskHashed);
+    // See also:
+    //   if (style == G4VMarker::filled || style == G4VMarker::hashed)...
+    // (twice) below.
+    break;
+    
+  case G4VMarker::filled:
+    glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
+    break;
+    
+  default:
+    G4cout << "Unrecognised fill style in G4OpenGLSceneHandler."
+	   << "\n  Using G4VMarker::filled."
+	   << G4endl;
+    glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
+    break;
+    
+  }
+
+  // A few useful quantities...
+  G4Point3D centre = marker.GetPosition();
+  const G4Vector3D& viewpointDirection =
+    fpViewer -> GetViewParameters().GetViewpointDirection();
+  const G4Vector3D& up = fpViewer->GetViewParameters().GetUpVector();
+  MarkerSizeType sizeType;
+  G4double size = GetMarkerSize(marker, sizeType);
+
+  // Find "size" of marker in world space (but see note below)...
+  G4double worldSize;
+  if (sizeType == world) {  // Size specified in world coordinates.
+    worldSize = size;
+  }
+  else { // Size specified in screen (window) coordinates.
+
+    // Find window coordinates of centre...
+    GLdouble modelMatrix[16];
+    glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix);
+    G4double projectionMatrix[16];
+    glGetDoublev (GL_PROJECTION_MATRIX, projectionMatrix);
+    GLint viewport[4];
+    glGetIntegerv(GL_VIEWPORT,viewport);
+    GLdouble winx, winy, winz;
+    gluProject(centre.x(), centre.y(), centre.z(),
+	       modelMatrix, projectionMatrix, viewport,
+	       &winx, &winy, &winz);
+
+    // Determine ratio window:world...
+    const G4Vector3D inScreen = (up.cross(viewpointDirection)).unit();
+    const G4Vector3D p = centre + inScreen;
+    GLdouble winDx, winDy, winDz;
+    gluProject(p.x(), p.y(), p.z(),
+               modelMatrix, projectionMatrix, viewport,
+               &winDx, &winDy, &winDz);
+    G4double winWorldRatio = std::sqrt(std::pow(winx - winDx, 2) +
+				  std::pow(winy - winDy, 2));
+    worldSize = size / winWorldRatio;
+  }
+
+  // Draw...
+  DrawXYPolygon (worldSize, centre, nSides);
+}
+
+/***************************************************
+Note: We have to do it this way round so that when a global
+transformation is applied, such as with /vis/viewer/set/viewpoint,
+the markers follow the world coordinates without having to
+recreate the display lists.  The down side is that the markers
+rotate.  The only way to avoid this is to play with the modelview
+and projection matrices of OpenGL - which I need to think about.
+For future reference, here is the code to draw in window
+coordinates; its down side is that markers do not follow global
+transformations.  Some clever stuff is needed.
+
+  ...
+  // Find window coordinates of centre...
+  GLdouble modelMatrix[16];
+  glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix);
+  G4double projectionMatrix[16];
+  glGetDoublev (GL_PROJECTION_MATRIX, projectionMatrix);
+  GLint viewport[4];
+  glGetIntegerv(GL_VIEWPORT,viewport);
+  GLdouble winx, winy, winz;
+  gluProject(centre.x(), centre.y(), centre.z(),
+             modelMatrix, projectionMatrix, viewport,
+             &winx, &winy, &winz);
+
+  // Find window size...
+  G4double winSize;
+  if (size) {  // Size specified in world coordinates.
+    // Determine size in window coordinates...
+    (Note: improve this by using an inScreen vector as above.)
+    GLdouble winx1, winy1, winz1;
+    gluProject(centre.x() + size, centre.y() + size, centre.z() + size,
+               modelMatrix, projectionMatrix, viewport,
+               &winx1, &winy1, &winz1);
+    winSize = std::sqrt((std::pow(winx - winx1, 2) +
+                    std::pow(winy - winy1, 2) +
+                    std::pow(winz - winz1, 2)) / 3.);
+  }
+  else {
+    winSize = scale *
+      userSpecified ? marker.GetScreenSize() : def.GetScreenSize();
+  }
+
+  // Prepare to draw in window coordinates...
+  glMatrixMode (GL_PROJECTION);
+  glPushMatrix();
+  glLoadIdentity();
+  gluOrtho2D(GLdouble(viewport[0]),
+             GLdouble(viewport[0] + viewport[2]),
+             GLdouble(viewport[1]),
+             GLdouble(viewport[1] + viewport[3]));
+  glMatrixMode (GL_MODELVIEW);
+  glPushMatrix();
+  glLoadIdentity();
+
+  // Draw in window coordinates...
+  DrawScreenPolygon (winSize, G4Point3D(winx, winy, winz), nSides);
+
+  // Re-instate matrices...
+  glMatrixMode (GL_PROJECTION);
+  glPopMatrix();
+  glMatrixMode (GL_MODELVIEW);
+  glPopMatrix();
+  ...
+}
+
+void G4OpenGLSceneHandler::DrawScreenPolygon
+(G4double size,
+ const G4Point3D& centre,
+ G4int nSides) {
+  glBegin (GL_POLYGON);
+  const G4double dPhi = twopi / nSides;
+  const G4double r = size / 2.;
+  G4double phi;
+  G4int i;
+  for (i = 0, phi = -dPhi / 2.; i < nSides; i++, phi += dPhi) {
+    G4double x, y, z;
+    x = centre.x() + r * std::cos(phi);
+    y = centre.y() + r * std::sin(phi);
+    z = centre.z();
+    glVertex3d (x, y, z);
+  }
+  glEnd ();
+}
+**********************************************/
+
+void G4OpenGLSceneHandler::DrawXYPolygon
+(G4double size,
+ const G4Point3D& centre,
+ G4int nSides) {
+  const G4Vector3D& viewpointDirection =
+    fpViewer -> GetViewParameters().GetViewpointDirection();
+  const G4Vector3D& up = fpViewer->GetViewParameters().GetUpVector();
+  const G4double dPhi = twopi / nSides;
+  const G4double radius = size / 2.;
+  G4Vector3D start = radius * (up.cross(viewpointDirection)).unit();
+  G4double phi;
+  G4int i;
+  glBegin (GL_POLYGON);
+  for (i = 0, phi = 0.; i < nSides; i++, phi += dPhi) {
+    G4Vector3D r = start; r.rotate(phi, viewpointDirection);
+    G4Vector3D p = centre + r;
+    glVertex3d (p.x(), p.y(), p.z());
+  }
+  glEnd ();
+}
+
+//Method for handling G4Polyhedron objects for drawing solids.
+void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
+
+  // Assume all facets are planar convex quadrilaterals.
+  // Draw each facet individually
+  
+  if (polyhedron.GetNoFacets() == 0) return;
+
+  // Get vis attributes - pick up defaults if none.
+  const G4VisAttributes* pVA =
+    fpViewer -> GetApplicableVisAttributes (polyhedron.GetVisAttributes ());
+
+  // Get view parameters that the user can force through the vis
+  // attributes, thereby over-riding the current view parameter.
+  G4ViewParameters::DrawingStyle drawing_style = GetDrawingStyle (pVA);
+
+  //Get colour, etc...
+  G4bool transparency_enabled = true;
+  G4OpenGLViewer* pViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
+  if (pViewer) transparency_enabled = pViewer->transparency_enabled;
+  const G4Colour& c = GetColour (polyhedron);
+  GLfloat materialColour [4];
+  materialColour [0] = c.GetRed ();
+  materialColour [1] = c.GetGreen ();
+  materialColour [2] = c.GetBlue ();
+  if (transparency_enabled) {
+    materialColour [3] = c.GetAlpha ();
+  } else {
+    materialColour [3] = 1.;
+  }
+
+  G4double lineWidth = GetLineWidth(polyhedron);
+  glLineWidth(lineWidth);
+
+  GLfloat clear_colour[4];
+  glGetFloatv (GL_COLOR_CLEAR_VALUE, clear_colour);
+
+  G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pVA);
+
+  G4bool clipping = pViewer->fVP.IsSection() || pViewer->fVP.IsCutaway();
+
+  switch (drawing_style) {
+  case (G4ViewParameters::hlhsr):
+    // Set up as for hidden line removal but paint polygon faces later...
+  case (G4ViewParameters::hlr):
+    glEnable (GL_STENCIL_TEST);
+    // The stencil buffer is cleared in G4OpenGLViewer::ClearView.
+    // The procedure below leaves it clear.
+    glStencilFunc (GL_ALWAYS, 0, 1);
+    glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
+    glEnable (GL_DEPTH_TEST);
+    glDepthFunc (GL_LEQUAL);
+    if (materialColour[3] < 1.) {
+      // Transparent...
+      glDisable (GL_CULL_FACE);
+      glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
+    } else {
+      // Opaque...
+      if (clipping) {
+	glDisable (GL_CULL_FACE);
+	glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
+      } else {
+	glEnable (GL_CULL_FACE);
+	glCullFace (GL_BACK);
+	glPolygonMode (GL_FRONT, GL_LINE);
+      }
+    }
+    glDisable (GL_LIGHTING);
+    glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
+    break;
+  case (G4ViewParameters::hsr):
+    glEnable (GL_DEPTH_TEST);
+    glDepthFunc (GL_LEQUAL);    
+    if (materialColour[3] < 1.) {
+      // Transparent...
+      glDepthMask (0);  // Make depth buffer read-only.
+      glDisable (GL_CULL_FACE);
+      glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
+      glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, materialColour);
+    } else {
+      // Opaque...
+      glDepthMask (1);  // Make depth buffer writable (default).
+      if (clipping) {
+	glDisable (GL_CULL_FACE);
+	glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
+      } else {
+	glEnable (GL_CULL_FACE);
+	glCullFace (GL_BACK);
+	glPolygonMode (GL_FRONT, GL_FILL);
+      }
+      glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialColour);
+    }
+    glEnable (GL_LIGHTING);
+    break;
+  case (G4ViewParameters::wireframe):
+  default:
+    glEnable (GL_DEPTH_TEST);
+    glDepthFunc (GL_LEQUAL);    //??? was GL_ALWAYS
+    glDisable (GL_CULL_FACE);
+    glDisable (GL_LIGHTING);
+    glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
+    glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
+    break;
+  }
+
+  //Loop through all the facets...
+  glBegin (GL_QUADS);
+  G4bool notLastFace;
+  do {
+
+    //First, find vertices, edgeflags and normals and note "not last facet"...
+    G4Point3D vertex[4];
+    G4int edgeFlag[4];
+    G4Normal3D normals[4];
+    G4int n;
+    notLastFace = polyhedron.GetNextFacet(n, vertex, edgeFlag, normals);
+
+    //Loop through the four edges of each G4Facet...
+    G4int edgeCount = 0;
+    for(edgeCount = 0; edgeCount < n; ++edgeCount) {
+      // Check to see if edge is visible or not...
+      if (isAuxEdgeVisible) {
+	edgeFlag[edgeCount] = 1;
+      }
+      if (edgeFlag[edgeCount] > 0) {
+	glEdgeFlag (GL_TRUE);
+      } else {
+	glEdgeFlag (GL_FALSE);
+      }
+      glNormal3d (normals[edgeCount].x(), 
+		  normals[edgeCount].y(),
+		  normals[edgeCount].z());
+      glVertex3d (vertex[edgeCount].x(), 
+		  vertex[edgeCount].y(),
+		  vertex[edgeCount].z());
+    }
+    // HepPolyhedron produces triangles too; in that case add an extra
+    // vertex identical to first...
+    if (n == 3) {
+      edgeCount = 3;
+      normals[edgeCount] = normals[0];
+      vertex[edgeCount] = vertex[0];
+      edgeFlag[edgeCount] = -1;
+      glEdgeFlag (GL_FALSE);
+      glNormal3d (normals[edgeCount].x(),
+		  normals[edgeCount].y(), 
+		  normals[edgeCount].z());
+      glVertex3d (vertex[edgeCount].x(),
+		  vertex[edgeCount].y(), 
+		  vertex[edgeCount].z());
+    }
+    // Trap situation where number of edges is > 4...
+    if (n > 4) {
+      G4cerr <<
+	"G4OpenGLSceneHandler::AddPrimitive(G4Polyhedron): WARNING";
+      G4PhysicalVolumeModel* pPVModel =
+	dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
+      if (pPVModel) {
+	G4VPhysicalVolume* pCurrentPV = pPVModel->GetCurrentPV();
+	G4LogicalVolume* pCurrentLV = pPVModel->GetCurrentLV();
+	G4cerr <<
+	"\n  Volume " << pCurrentPV->GetName() <<
+	", Solid " << pCurrentLV->GetSolid()->GetName() <<
+	  " (" << pCurrentLV->GetSolid()->GetEntityType();
+      }
+      G4cerr<<
+	"\n   G4Polyhedron facet with " << n << " edges" << G4endl;
+    }
+
+    // Do it all over again (twice) for hlr...
+    if  (drawing_style == G4ViewParameters::hlr ||
+	 drawing_style == G4ViewParameters::hlhsr) {
+
+      glEnd ();  // Placed here to balance glBegin above, allowing GL
+		 // state changes below, then glBegin again.  Avoids
+		 // having glBegin/End pairs *inside* loop in the more
+		 // usual case of no hidden line removal.
+
+      // Draw through stencil...
+      glStencilFunc (GL_EQUAL, 0, 1);
+      glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
+      if (drawing_style == G4ViewParameters::hlhsr) {
+	glEnable (GL_LIGHTING);
+      }
+      glEnable (GL_DEPTH_TEST);
+      glDepthFunc (GL_LEQUAL);    
+      if (materialColour[3] < 1.) {
+	// Transparent...
+	glDepthMask (0);  // Make depth buffer read-only.
+	glDisable (GL_CULL_FACE);
+	glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
+      } else {
+	// Opaque...
+	glDepthMask (1);  // Make depth buffer writable (default).
+	if (clipping) {
+	  glDisable (GL_CULL_FACE);
+	  glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
+	} else {
+	  glEnable (GL_CULL_FACE);
+	  glCullFace (GL_BACK);
+	  glPolygonMode (GL_FRONT, GL_FILL);
+	}
+      }
+      GLfloat* painting_colour;
+      if  (drawing_style == G4ViewParameters::hlr) {
+	if (materialColour[3] < 1.) {
+	  // Transparent - don't paint...
+	  goto end_of_drawing_through_stencil;
+	}
+	painting_colour = clear_colour;
+      } else {  // drawing_style == G4ViewParameters::hlhsr
+	painting_colour = materialColour;
+      }
+      if (materialColour[3] < 1.) {
+	// Transparent...
+	glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, painting_colour);
+      } else {
+	// Opaque...
+	glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, painting_colour);
+      }
+      glColor4fv (painting_colour);
+      glBegin (GL_QUADS);
+      for (int edgeCount = 0; edgeCount < 4; ++edgeCount) {
+	if (edgeFlag[edgeCount] > 0) {
+	  glEdgeFlag (GL_TRUE);
+	} else {
+	  glEdgeFlag (GL_FALSE);
+	}
+	glNormal3d (normals[edgeCount].x(), 
+		    normals[edgeCount].y(),
+		    normals[edgeCount].z());
+	glVertex3d (vertex[edgeCount].x(), 
+		    vertex[edgeCount].y(),
+		    vertex[edgeCount].z());
+      }
+      glEnd ();
+    end_of_drawing_through_stencil:
+
+      // and once more to reset the stencil bits...
+      glStencilFunc (GL_ALWAYS, 0, 1);
+      glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
+      glDepthFunc (GL_LEQUAL);  // to make sure line gets drawn.  
+      if (materialColour[3] < 1.) {
+	// Transparent...
+	glDisable (GL_CULL_FACE);
+	glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
+      } else {
+	// Opaque...
+	if (clipping) {
+	  glDisable (GL_CULL_FACE);
+	  glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
+	} else {
+	  glEnable (GL_CULL_FACE);
+	  glCullFace (GL_BACK);
+	  glPolygonMode (GL_FRONT, GL_LINE);
+	}
+      }
+      glDisable (GL_LIGHTING);
+      glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
+      glBegin (GL_QUADS);
+      for (int edgeCount = 0; edgeCount < 4; ++edgeCount) {
+	if (edgeFlag[edgeCount] > 0) {
+	  glEdgeFlag (GL_TRUE);
+	} else {
+	  glEdgeFlag (GL_FALSE);
+	}
+	glNormal3d (normals[edgeCount].x(), 
+		    normals[edgeCount].y(),
+		    normals[edgeCount].z());
+	glVertex3d (vertex[edgeCount].x(), 
+		    vertex[edgeCount].y(),
+		    vertex[edgeCount].z());
+      }
+      glEnd ();
+      glDepthFunc (GL_LEQUAL);   // Revert for next facet.
+      glBegin (GL_QUADS);      // Ready for next facet.  GL
+			       // says it ignores incomplete
+			       // quadrilaterals, so final empty
+			       // glBegin/End sequence should be OK.
+    }
+  } while (notLastFace);  
+  
+  glEnd ();
+  glDisable (GL_STENCIL_TEST);  // Revert to default for next primitive.
+  glDepthMask (1);              // Revert to default for next primitive.
+}
+
+//Method for handling G4NURBS objects for drawing solids.
+//Knots and Ctrl Pnts MUST be arrays of GLfloats.
+void G4OpenGLSceneHandler::AddPrimitive (const G4NURBS& nurb) {
+
+  GLUnurbsObj *gl_nurb;
+  gl_nurb = gluNewNurbsRenderer ();
+
+  GLfloat *u_knot_array, *u_knot_array_ptr;
+  u_knot_array = u_knot_array_ptr = new GLfloat [nurb.GetnbrKnots(G4NURBS::U)];
+  G4NURBS::KnotsIterator u_iterator (nurb, G4NURBS::U);
+  while (u_iterator.pick (u_knot_array_ptr++));
+
+  GLfloat *v_knot_array, *v_knot_array_ptr;
+  v_knot_array = v_knot_array_ptr = new GLfloat [nurb.GetnbrKnots(G4NURBS::V)];
+  G4NURBS::KnotsIterator v_iterator (nurb, G4NURBS::V);
+  while (v_iterator.pick (v_knot_array_ptr++));
+
+  GLfloat *ctrl_pnt_array, *ctrl_pnt_array_ptr;
+  ctrl_pnt_array = ctrl_pnt_array_ptr =
+    new GLfloat [nurb.GettotalnbrCtrlPts () * G4NURBS::NofC];
+  G4NURBS::CtrlPtsCoordsIterator c_p_iterator (nurb);
+  while (c_p_iterator.pick (ctrl_pnt_array_ptr++));
+
+  // Get vis attributes - pick up defaults if none.
+  const G4VisAttributes* pVA =
+    fpViewer -> GetApplicableVisAttributes (nurb.GetVisAttributes ());
+
+  // Get view parameters that the user can force through the vis
+  // attributes, thereby over-riding the current view parameter.
+  G4ViewParameters::DrawingStyle drawing_style = GetDrawingStyle (pVA);
+  //G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pVA);
+  
+  //Get colour, etc..
+  const G4Colour& c = pVA -> GetColour ();
+
+  switch (drawing_style) {
+
+  case (G4ViewParameters::hlhsr):
+    //    G4cout << "Hidden line removal not implememented in G4OpenGL.\n"
+    // << "Using hidden surface removal." << G4endl;
+  case (G4ViewParameters::hsr):
+    {
+      glEnable (GL_LIGHTING);
+      glEnable (GL_DEPTH_TEST);
+      glEnable (GL_AUTO_NORMAL);
+      glEnable (GL_NORMALIZE);
+      gluNurbsProperty (gl_nurb, GLU_DISPLAY_MODE, GLU_FILL);
+      gluNurbsProperty (gl_nurb, GLU_SAMPLING_TOLERANCE, 50.0);
+      GLfloat materialColour [4];
+      materialColour [0] = c.GetRed ();
+      materialColour [1] = c.GetGreen ();
+      materialColour [2] = c.GetBlue ();
+      materialColour [3] = 1.0;  // = c.GetAlpha () for transparency -
+				 // but see complication in
+				 // AddPrimitive(const G4Polyhedron&).
+      glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialColour);
+      break;
+    }
+  case (G4ViewParameters::hlr):
+    //    G4cout << "Hidden line removal not implememented in G4OpenGL.\n"
+    // << "Using wireframe." << G4endl;
+  case (G4ViewParameters::wireframe):
+  default:
+    glDisable (GL_LIGHTING);
+//    glDisable (GL_DEPTH_TEST);
+    glEnable (GL_DEPTH_TEST);
+    glDisable (GL_AUTO_NORMAL);
+    glDisable (GL_NORMALIZE);
+    gluNurbsProperty (gl_nurb, GLU_DISPLAY_MODE, GLU_OUTLINE_POLYGON);
+    gluNurbsProperty (gl_nurb, GLU_SAMPLING_TOLERANCE, 50.0);
+    glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
+    break;
+  }	
+
+  gluBeginSurface (gl_nurb);
+  G4int u_stride = 4;
+  G4int v_stride = nurb.GetnbrCtrlPts(G4NURBS::U) * 4;
+
+  gluNurbsSurface (gl_nurb, 
+		   nurb.GetnbrKnots (G4NURBS::U), (GLfloat*)u_knot_array, 
+		   nurb.GetnbrKnots (G4NURBS::V), (GLfloat*)v_knot_array,
+		   u_stride,
+		   v_stride,  
+		   ctrl_pnt_array,
+		   nurb.GetUorder (),
+		   nurb.GetVorder (), 
+		   GL_MAP2_VERTEX_4);
+  
+  gluEndSurface (gl_nurb);
+
+  delete [] u_knot_array;  // These should be allocated with smart allocators
+  delete [] v_knot_array;  // to avoid memory explosion.
+  delete [] ctrl_pnt_array;
+
+  gluDeleteNurbsRenderer (gl_nurb);
+}
+
+void G4OpenGLSceneHandler::AddCompound(const G4VTrajectory& traj) {
+  G4VSceneHandler::AddCompound(traj);  // For now.
+}
+
+void G4OpenGLSceneHandler::AddCompound(const G4VHit& hit) {
+  G4VSceneHandler::AddCompound(hit);  // For now.
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredSceneHandler.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredSceneHandler.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredSceneHandler.cc	(revision 529)
@@ -0,0 +1,392 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLStoredSceneHandler.cc,v 1.31 2006/08/30 11:43:57 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  10th February 1997
+// OpenGL stored scene - creates OpenGL display lists.
+
+#ifdef G4VIS_BUILD_OPENGL_DRIVER
+
+// Included here - problems with HP compiler if not before other includes?
+#include "G4NURBS.hh"
+
+// Here follows a special for Mesa, the OpenGL emulator.  Does not affect
+// other OpenGL's, as far as I'm aware.   John Allison 18/9/96.
+#define CENTERLINE_CLPP  /* CenterLine C++ workaround: */
+// Also seems to be required for HP's CC and AIX xlC, at least.
+
+#include "G4OpenGLStoredSceneHandler.hh"
+
+#include "G4PhysicalVolumeModel.hh"
+#include "G4VPhysicalVolume.hh"
+#include "G4Polyline.hh"
+#include "G4Polymarker.hh"
+#include "G4Circle.hh"
+#include "G4Square.hh"
+
+G4OpenGLStoredSceneHandler::G4OpenGLStoredSceneHandler (G4VGraphicsSystem& system,
+					  const G4String& name):
+G4OpenGLSceneHandler (system, fSceneIdCount++, name),
+fMemoryForDisplayLists (true),
+fAddPrimitivePreambleNestingDepth (0),
+fTopPODL (0)
+{}
+
+G4OpenGLStoredSceneHandler::~G4OpenGLStoredSceneHandler ()
+{}
+
+void G4OpenGLStoredSceneHandler::AddPrimitivePreamble(const G4Visible& visible)
+{
+  // Track nesting depth to avoid recursive calls, for example, from a
+  // G4Polymarker that invokes a G4Circle...
+  fAddPrimitivePreambleNestingDepth++;
+  if (fAddPrimitivePreambleNestingDepth > 1) return;
+
+  const G4Colour& c = GetColour (visible);
+
+  if (fMemoryForDisplayLists && fReadyForTransients) {
+
+    TO& to = fTOList.back();  // Transient object information.
+
+    // Get vis attributes - pick up defaults if none.
+    const G4VisAttributes* pVA =
+      fpViewer->GetApplicableVisAttributes(visible.GetVisAttributes());
+
+    // Get time information from vis attributes.
+    to.fStartTime = pVA->GetStartTime();
+    to.fEndTime = pVA->GetEndTime();
+
+    // Keep colour out of (already started) display list so that it
+    // can be applied independently.
+    glEndList();
+    glDeleteLists(fDisplayListId, 1);
+    to.fColour = c;
+    glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
+    glNewList (fDisplayListId, GL_COMPILE_AND_EXECUTE);
+      
+  } else {
+
+    // Make sure colour is set in other cases.
+    glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
+  }
+}
+
+void G4OpenGLStoredSceneHandler::AddPrimitivePostamble()
+{
+  fAddPrimitivePreambleNestingDepth--;
+}
+
+void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polyline& polyline)
+{
+  AddPrimitivePreamble(polyline);
+  G4OpenGLSceneHandler::AddPrimitive(polyline);
+  AddPrimitivePostamble();
+}
+
+void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Circle& circle)
+{
+  AddPrimitivePreamble(circle);
+  G4OpenGLSceneHandler::AddPrimitive(circle);
+  AddPrimitivePostamble();
+}
+
+void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Square& square)
+{
+  AddPrimitivePreamble(square);
+  G4OpenGLSceneHandler::AddPrimitive(square);
+  AddPrimitivePostamble();
+}
+
+void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
+{
+  AddPrimitivePreamble(polymarker);
+  G4OpenGLSceneHandler::AddPrimitive(polymarker);
+  AddPrimitivePostamble();
+}
+
+void G4OpenGLStoredSceneHandler::BeginPrimitives
+(const G4Transform3D& objectTransformation) {
+  
+  G4VSceneHandler::BeginPrimitives (objectTransformation);
+
+  if (fMemoryForDisplayLists) {
+    fDisplayListId = glGenLists (1);
+    if (!fDisplayListId) {  // Could pre-allocate?
+      G4cout << "********************* WARNING! ********************\n"
+	   <<"Unable to allocate any more display lists in OpenGL.\n "
+	   << "      Continuing drawing in IMMEDIATE MODE.\n"
+	   << "***************************************************" << G4endl;
+      fMemoryForDisplayLists = false;
+    }
+  }
+  if (fMemoryForDisplayLists) {
+    if (fReadyForTransients) {
+      TO to(fDisplayListId, objectTransformation);
+      fTOList.push_back(to);
+      glDrawBuffer (GL_FRONT);
+      glPushMatrix();
+      G4OpenGLTransform3D oglt (objectTransformation);
+      glMultMatrixd (oglt.GetGLMatrix ());
+      glNewList (fDisplayListId, GL_COMPILE_AND_EXECUTE);
+    }
+    else {
+      fPOList.push_back(PO(fDisplayListId, objectTransformation));
+      glNewList (fDisplayListId, GL_COMPILE);
+    }
+  } else {
+    glDrawBuffer (GL_FRONT);
+    glPushMatrix();
+    G4OpenGLTransform3D oglt (objectTransformation);
+    glMultMatrixd (oglt.GetGLMatrix ());
+  }
+}
+
+void G4OpenGLStoredSceneHandler::EndPrimitives () {
+  if (fMemoryForDisplayLists) {
+    glEndList();
+  }
+  if (fReadyForTransients || !fMemoryForDisplayLists) {
+    glPopMatrix();
+    glFlush ();
+    glDrawBuffer (GL_BACK);
+  }
+  G4VSceneHandler::EndPrimitives ();
+}
+
+void G4OpenGLStoredSceneHandler::BeginPrimitives2D()
+{
+  G4VSceneHandler::BeginPrimitives2D();
+
+  if (fMemoryForDisplayLists) {
+    fDisplayListId = glGenLists (1);
+    if (!fDisplayListId) {  // Could pre-allocate?
+      G4cout << "********************* WARNING! ********************\n"
+	   <<"Unable to allocate any more display lists in OpenGL.\n "
+	   << "      Continuing drawing in IMMEDIATE MODE.\n"
+	   << "***************************************************" << G4endl;
+      fMemoryForDisplayLists = false;
+    }
+  }
+  if (fMemoryForDisplayLists) {
+    if (fReadyForTransients) {
+      fTOList.push_back(TO(fDisplayListId));
+      glDrawBuffer (GL_FRONT);
+      glNewList (fDisplayListId, GL_COMPILE_AND_EXECUTE);
+    }
+    else {
+      fPOList.push_back(PO(fDisplayListId));
+      glNewList (fDisplayListId, GL_COMPILE);
+    }
+  } else {
+    glDrawBuffer (GL_FRONT);
+  }
+  // Push current 3D world matrices and load identity to define screen
+  // coordinates...
+  glMatrixMode (GL_PROJECTION);
+  glPushMatrix();
+  glLoadIdentity();
+  glOrtho (-1., 1., -1., 1., -DBL_MAX, DBL_MAX);
+  glMatrixMode (GL_MODELVIEW);
+  glPushMatrix();
+  glLoadIdentity();
+}
+
+void G4OpenGLStoredSceneHandler::EndPrimitives2D ()
+{
+  // Pop current 3D world matrices back again...
+  glMatrixMode (GL_PROJECTION);
+  glPopMatrix();
+  glMatrixMode (GL_MODELVIEW);
+  glPopMatrix();
+
+  if (fMemoryForDisplayLists) {
+    glEndList();
+  }
+  if (fReadyForTransients || !fMemoryForDisplayLists) {
+    glFlush ();
+    glDrawBuffer (GL_BACK);
+  }
+  G4VSceneHandler::EndPrimitives2D ();
+}
+
+void G4OpenGLStoredSceneHandler::BeginModeling () {
+  G4VSceneHandler::BeginModeling();
+  ClearStore();  // ...and all that goes with it.
+  /* Debug...
+  fDisplayListId = glGenLists (1);
+  G4cout << "OGL::fDisplayListId (start): " << fDisplayListId << G4endl;
+  */
+}
+
+void G4OpenGLStoredSceneHandler::EndModeling () {
+  // Make a List which calls the other lists.
+  fTopPODL = glGenLists (1);
+  if (!fTopPODL) {
+    G4cout <<
+      "ERROR: G4OpenGLStoredSceneHandler::EndModeling: Failure to allocate"
+      "  display List for fTopPODL - try OpenGL Immediated mode."
+	   << G4endl;
+  }
+  else {
+    glNewList (fTopPODL, GL_COMPILE_AND_EXECUTE); {
+      for (size_t i = 0; i < fPOList.size (); i++) {
+	glPushMatrix();
+	G4OpenGLTransform3D oglt (fPOList[i].fTransform);
+	glMultMatrixd (oglt.GetGLMatrix ());
+	glCallList (fPOList[i].fDisplayListId);
+	glPopMatrix();
+      }
+    }
+    glEndList ();
+  }
+
+  G4VSceneHandler::EndModeling ();
+
+  /* Debug...
+  fDisplayListId = glGenLists (1);
+  G4cout << "OGL::fDisplayListId (end): " << fDisplayListId << G4endl;
+  */
+}
+
+void G4OpenGLStoredSceneHandler::ClearStore () {
+
+  G4VSceneHandler::ClearStore ();  // Sets need kernel visit, etc.
+
+  // Delete OpenGL permanent display lists.
+  for (size_t i = 0; i < fPOList.size (); i++)
+    glDeleteLists (fPOList[i].fDisplayListId, 1);
+  if (fTopPODL) glDeleteLists (fTopPODL, 1);
+  fTopPODL = 0;
+
+  // Clear other lists, dictionary, etc.
+  fPOList.clear ();
+  fSolidMap.clear ();
+
+  // ...and clear transient store...
+  for (size_t i = 0; i < fTOList.size (); i++)
+    glDeleteLists(fTOList[i].fDisplayListId, 1);
+  fTOList.clear ();
+}
+
+void G4OpenGLStoredSceneHandler::ClearTransientStore () {
+
+  G4VSceneHandler::ClearTransientStore ();
+
+  // Delete OpenGL transient display lists and Transient Objects themselves.
+  for (size_t i = 0; i < fTOList.size (); i++)
+    glDeleteLists(fTOList[i].fDisplayListId, 1);
+  fTOList.clear ();
+
+  // Make sure screen corresponds to graphical database...
+  if (fpViewer) {
+    fpViewer -> SetView ();
+    fpViewer -> ClearView ();
+    fpViewer -> DrawView ();
+  }
+}
+
+void G4OpenGLStoredSceneHandler::RequestPrimitives (const G4VSolid& solid)
+{
+  if (fReadyForTransients) {
+    // Always draw transient solids, e.g., hits represented as solids.
+    // (As we have no control over the order of drawing of transient
+    // objects, we cannot do anything about transparent ones, as
+    // below, so always draw them.)
+    G4VSceneHandler::RequestPrimitives (solid);
+    return;
+  }
+
+  // For non-transient (run-duration) objects, ensure transparent
+  // objects are drawn last.  The problem of
+  // blending/transparency/alpha is quite a tricky one - see History
+  // of opengl-V07-01-01/2/3.
+  // Get vis attributes - pick up defaults if none.
+  const G4VisAttributes* pVA =
+    fpViewer -> GetApplicableVisAttributes(fpVisAttribs);
+  const G4Colour& c = pVA -> GetColour ();
+  G4double opacity = c.GetAlpha ();
+
+  if (!fSecondPass) {
+    G4bool transparency_enabled = true;
+    G4OpenGLViewer* pViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
+    if (pViewer) transparency_enabled = pViewer->transparency_enabled;
+    if (transparency_enabled && opacity < 1.) {
+      // On first pass, transparent objects are not drawn, but flag is set...
+      fSecondPassRequested = true;
+      return;
+    }
+  }
+
+  // On second pass, opaque objects are not drwan...
+  if (fSecondPass && opacity >= 1.) return;
+
+  G4PhysicalVolumeModel* pPVModel =
+    dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
+ 
+  if (pPVModel) {
+    // If part of the geometry hierarchy, i.e., from a
+    // G4PhysicalVolumeModel, check if a display list already exists for
+    // this solid, re-use it if possible.  We could be smarter, and
+    // recognise repeated branches of the geometry hierarchy, for
+    // example.  But this algorithm should be secure, I think...
+    const G4VSolid* pSolid = &solid;
+    EAxis axis = kRho;
+    G4VPhysicalVolume* pCurrentPV = pPVModel->GetCurrentPV();
+    if (pCurrentPV -> IsReplicated ()) {
+      G4int nReplicas;
+      G4double width;
+      G4double offset;
+      G4bool consuming;
+      pCurrentPV->GetReplicationData(axis,nReplicas,width,offset,consuming);
+    }
+    // Provided it is not parametrised (because if so, the
+    // solid's parameters might have been changed)...
+    if (!(pCurrentPV -> IsParameterised ()) &&
+	// Provided it is not replicated radially (because if so, the
+	// solid's parameters will have been changed)...
+	!(pCurrentPV -> IsReplicated () && axis == kRho) &&
+	// ...and if the solid has already been rendered...
+	(fSolidMap.find (pSolid) != fSolidMap.end ())) {
+      fDisplayListId = fSolidMap [pSolid];
+      fPOList.push_back(PO(fDisplayListId,*fpObjectTransformation));
+    }
+    else {
+      G4VSceneHandler::RequestPrimitives (solid);
+      fSolidMap [pSolid] = fDisplayListId;
+    }
+    return;
+  }
+
+  // Otherwise invoke base class method...
+  G4VSceneHandler::RequestPrimitives (solid);
+}
+
+G4int G4OpenGLStoredSceneHandler::fSceneIdCount = 0;
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredViewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredViewer.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredViewer.cc	(revision 529)
@@ -0,0 +1,245 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLStoredViewer.cc,v 1.20 2006/10/24 06:23:18 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  7th February 1997
+// Class G4OpenGLStoredViewer : Encapsulates the `storedness' of
+//                            an OpenGL view, for inheritance by
+//                            derived (X, Xm...) classes.
+
+#ifdef G4VIS_BUILD_OPENGL_DRIVER
+
+#include "G4OpenGLStoredViewer.hh"
+
+#include "G4OpenGLStoredSceneHandler.hh"
+#include "G4Text.hh"
+#include "G4Circle.hh"
+#include "G4UnitsTable.hh"
+#include "G4Scene.hh"
+
+G4OpenGLStoredViewer::G4OpenGLStoredViewer
+(G4OpenGLStoredSceneHandler& sceneHandler):
+G4VViewer (sceneHandler, -1),  
+G4OpenGLViewer (sceneHandler), 
+fG4OpenGLStoredSceneHandler (sceneHandler)
+{
+  fLastVP = fDefaultVP; // Not sure if this gets executed before or
+  // after G4VViewer::G4VViewer!!  Doesn't matter much.
+}
+
+G4OpenGLStoredViewer::~G4OpenGLStoredViewer () {}
+
+void G4OpenGLStoredViewer::KernelVisitDecision () {
+  
+  // If there's a significant difference with the last view parameters
+  // of either the scene handler or this viewer, trigger a rebuild.
+
+  if (!fG4OpenGLStoredSceneHandler.fTopPODL ||
+      CompareForKernelVisit(fLastVP)) {
+    NeedKernelVisit ();
+  }      
+  fLastVP = fVP;
+}
+
+G4bool G4OpenGLStoredViewer::CompareForKernelVisit(G4ViewParameters& lastVP) {
+
+  if (
+      (lastVP.GetDrawingStyle ()    != fVP.GetDrawingStyle ())    ||
+      (lastVP.IsAuxEdgeVisible ()   != fVP.IsAuxEdgeVisible ())   ||
+      (lastVP.GetRepStyle ()        != fVP.GetRepStyle ())        ||
+      (lastVP.IsCulling ()          != fVP.IsCulling ())          ||
+      (lastVP.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
+      (lastVP.IsDensityCulling ()   != fVP.IsDensityCulling ())   ||
+      (lastVP.IsCullingCovered ()   != fVP.IsCullingCovered ())   ||
+      (lastVP.IsSection ()          != fVP.IsSection ())          ||
+      // Section (DCUT) implemented locally.  But still need to visit
+      // kernel if status changes so that back plane culling can be
+      // switched.
+      (lastVP.IsCutaway ()          != fVP.IsCutaway ())          ||
+      // Cutaways implemented locally.  But still need to visit kernel
+      // if status changes so that back plane culling can be switched.
+      (lastVP.IsExplode ()          != fVP.IsExplode ())          ||
+      (lastVP.GetNoOfSides ()       != fVP.GetNoOfSides ())       ||
+      (lastVP.IsMarkerNotHidden ()  != fVP.IsMarkerNotHidden ())  ||
+      (lastVP.GetBackgroundColour ()!= fVP.GetBackgroundColour ())
+      ) {
+    return true;
+  }
+
+  if (lastVP.IsDensityCulling () &&
+      (lastVP.GetVisibleDensity () != fVP.GetVisibleDensity ()))
+    return true;
+
+  /**************************************************************
+  Section (DCUT) implemented locally.  No need to visit kernel if
+  section plane itself changes.
+  if (lastVP.IsSection () &&
+      (lastVP.GetSectionPlane () != fVP.GetSectionPlane ()))
+    return true;
+  ***************************************************************/
+
+  /**************************************************************
+  Cutaways implemented locally.  No need to visit kernel if cutaway
+  planes themselves change.
+  if (lastVP.IsCutaway ()) {
+    if (lastVP.GetCutawayPlanes ().size () !=
+	fVP.GetCutawayPlanes ().size ()) return true;
+    for (size_t i = 0; i < lastVP.GetCutawayPlanes().size(); ++i)
+      if (lastVP.GetCutawayPlanes()[i] != fVP.GetCutawayPlanes()[i])
+	return true;
+  }
+  ***************************************************************/
+
+  if (lastVP.IsExplode () &&
+      (lastVP.GetExplodeFactor () != fVP.GetExplodeFactor ()))
+    return true;
+
+  return false;
+}
+
+void G4OpenGLStoredViewer::DrawDisplayLists () {
+
+  const G4Planes& cutaways = fVP.GetCutawayPlanes();
+  G4bool cutawayUnion = fVP.IsCutaway() &&
+    fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion;
+  size_t nPasses = cutawayUnion? cutaways.size(): 1;
+  for (size_t i = 0; i < nPasses; ++i) {
+
+    if (cutawayUnion) {
+      double a[4];
+      a[0] = cutaways[i].a();
+      a[1] = cutaways[i].b();
+      a[2] = cutaways[i].c();
+      a[3] = cutaways[i].d();
+      glClipPlane (GL_CLIP_PLANE2, a);
+      glEnable (GL_CLIP_PLANE2);
+    }
+
+    if (fG4OpenGLStoredSceneHandler.fTopPODL)
+      glCallList (fG4OpenGLStoredSceneHandler.fTopPODL);
+
+    for (size_t i = 0; i < fG4OpenGLStoredSceneHandler.fTOList.size(); ++i) {
+      G4OpenGLStoredSceneHandler::TO& to =
+	fG4OpenGLStoredSceneHandler.fTOList[i];
+      if (to.fEndTime >= fStartTime && to.fStartTime <= fEndTime) {
+	glPushMatrix();
+	G4OpenGLTransform3D oglt (to.fTransform);
+	glMultMatrixd (oglt.GetGLMatrix ());
+	G4Colour& c = to.fColour;
+	G4double bsf = 1.;  // Brightness scaling factor.
+	if (fFadeFactor > 0. && to.fEndTime < fEndTime)
+	  bsf = 1. - fFadeFactor *
+	    ((fEndTime - to.fEndTime) / (fEndTime - fStartTime));
+	glColor3d(bsf * c.GetRed (), bsf * c.GetGreen (), bsf * c.GetBlue ());
+	glCallList (to.fDisplayListId);
+	glPopMatrix();
+      }
+    }
+
+    if (cutawayUnion) glDisable (GL_CLIP_PLANE2);
+  }
+
+  // Display time at "head" of time range, which is fEndTime...
+  if (fDisplayHeadTime && fEndTime < DBL_MAX) {
+    glMatrixMode (GL_PROJECTION);
+    glPushMatrix();
+    glLoadIdentity();
+    glOrtho (-1., 1., -1., 1., -DBL_MAX, DBL_MAX);
+    glMatrixMode (GL_MODELVIEW);
+    glPushMatrix();
+    glLoadIdentity();
+    G4Text headTimeText(G4BestUnit(fEndTime,"Time"),
+			G4Point3D(fDisplayHeadTimeX, fDisplayHeadTimeY, 0.));
+    headTimeText.SetScreenSize(fDisplayHeadTimeSize);
+    G4VisAttributes visAtts (G4Colour
+			     (fDisplayHeadTimeRed,
+			      fDisplayHeadTimeGreen,
+			      fDisplayHeadTimeBlue));
+    headTimeText.SetVisAttributes(&visAtts);
+    fG4OpenGLStoredSceneHandler.AddPrimitive(headTimeText);
+    glMatrixMode (GL_PROJECTION);
+    glPopMatrix();
+    glMatrixMode (GL_MODELVIEW);
+    glPopMatrix();
+  }
+
+  // Display light front...
+  if (fDisplayLightFront && fEndTime < DBL_MAX) {
+    G4double lightFrontRadius = (fEndTime - fDisplayLightFrontT) * c_light;
+    if (lightFrontRadius > 0.) {
+      G4Point3D lightFrontCentre(fDisplayLightFrontX, fDisplayLightFrontY, fDisplayLightFrontZ);
+      G4Point3D circleCentre = lightFrontCentre;
+      G4double circleRadius = lightFrontRadius;
+      if (fVP.GetFieldHalfAngle() > 0.) {
+	// Perspective view.  Find horizon centre and radius...
+	G4Point3D targetPoint = fSceneHandler.GetScene()->GetStandardTargetPoint() +
+	  fVP.GetCurrentTargetPoint();
+	G4double sceneRadius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
+	if(sceneRadius <= 0.) sceneRadius = 1.;
+	G4double cameraDistance = fVP.GetCameraDistance(sceneRadius);
+	G4Point3D cameraPosition = targetPoint + cameraDistance * fVP.GetViewpointDirection().unit();
+	G4Vector3D lightFrontToCameraDirection = cameraPosition - lightFrontCentre;
+	G4double lightFrontCentreDistance = lightFrontToCameraDirection.mag();
+	/*
+	G4cout << "cameraPosition: " << cameraPosition
+	       << ", lightFrontCentre: " << lightFrontCentre
+	       << ", lightFrontRadius: " << lightFrontRadius
+	       << ", lightFrontCentreDistance: " << lightFrontCentreDistance
+	       << ", dot: " << lightFrontToCameraDirection * fVP.GetViewpointDirection()
+	       << G4endl;
+	*/
+	if (lightFrontToCameraDirection * fVP.GetViewpointDirection() > 0. && lightFrontRadius < lightFrontCentreDistance) {
+	  // Light front in front of camera...
+	  G4double sineHorizonAngle = lightFrontRadius / lightFrontCentreDistance;
+	  circleCentre = lightFrontCentre + (lightFrontRadius * sineHorizonAngle) * lightFrontToCameraDirection.unit();
+	  circleRadius = lightFrontRadius * std::sqrt(1. - std::pow(sineHorizonAngle, 2));
+	  /*
+	  G4cout << "sineHorizonAngle: " << sineHorizonAngle
+		 << ", circleCentre: " << circleCentre
+		 << ", circleRadius: " << circleRadius
+		 << G4endl;
+	  */
+	} else {
+	  circleRadius = -1.;
+	}
+      }
+      if (circleRadius > 0.) {
+	G4Circle lightFront(circleCentre);
+	lightFront.SetWorldRadius(circleRadius);
+	glColor3d(fDisplayLightFrontRed,
+		  fDisplayLightFrontGreen,
+		  fDisplayLightFrontBlue);
+	static_cast<G4OpenGLSceneHandler&>(fSceneHandler).
+	  G4OpenGLSceneHandler::AddPrimitive(lightFront);
+      }
+    }
+  }
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredWin32.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredWin32.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredWin32.cc	(revision 529)
@@ -0,0 +1,80 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLStoredWin32.cc,v 1.14 2006/08/14 12:07:19 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// OpenGLStoredWin32 graphics system factory.
+
+
+#ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER
+
+#include "G4VisFeaturesOfOpenGL.hh"
+#include "G4VSceneHandler.hh"
+#include "G4OpenGLSceneHandler.hh"
+#include "G4OpenGLViewer.hh"
+#include "G4OpenGLStoredWin32.hh"
+#include "G4OpenGLStoredWin32Viewer.hh"
+#include "G4OpenGLViewerMessenger.hh"
+
+G4OpenGLStoredWin32::G4OpenGLStoredWin32 ():
+  G4VGraphicsSystem ("OpenGLStoredWin32",
+		     "OGLSWin32",
+		     G4VisFeaturesOfOpenGLSWin32 (),
+		     G4VGraphicsSystem::threeD)
+{
+  G4OpenGLViewerMessenger::GetInstance();
+}
+
+G4VSceneHandler* G4OpenGLStoredWin32::CreateSceneHandler
+(const G4String& name) {
+  G4VSceneHandler* pScene = new G4OpenGLStoredSceneHandler (*this, name);
+  return    pScene;
+}
+
+G4VViewer* G4OpenGLStoredWin32::CreateViewer
+(G4VSceneHandler& scene, const G4String& name) {
+  G4VViewer* pView =
+    new G4OpenGLStoredWin32Viewer ((G4OpenGLStoredSceneHandler&) scene, name);
+  if (pView) {
+    if (pView -> GetViewId () < 0) {
+      delete pView;
+      pView = 0;
+      G4cerr << "G4OpenGLStoredWin32::CreateViewer: error flagged by"
+	" negative view id in G4OpenGLStoredWin32Viewer creation."
+	"\n Destroying view and returning null pointer." << G4endl;
+    }
+  }
+  else {
+    G4cerr << "G4OpenGLStoredWin32::CreateViewer: null pointer on"
+      " new G4OpenGLStoredWin32Viewer." << G4endl;
+  }
+  return pView;
+}
+
+#endif
+
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredWin32Viewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredWin32Viewer.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredWin32Viewer.cc	(revision 529)
@@ -0,0 +1,135 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLStoredWin32Viewer.cc,v 1.18 2006/09/04 12:07:59 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Class G4OpenGLStoredWin32Viewer : a class derived from G4OpenGLWin32Viewer and
+//                             G4OpenGLStoredViewer.
+
+#ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER
+
+#include "G4OpenGLStoredWin32Viewer.hh"
+
+#include "G4ios.hh"
+
+G4OpenGLStoredWin32Viewer::G4OpenGLStoredWin32Viewer
+(G4OpenGLStoredSceneHandler& sceneHandler,
+ const G4String&  name):
+G4OpenGLViewer (sceneHandler),
+G4OpenGLWin32Viewer (sceneHandler),
+G4OpenGLStoredViewer (sceneHandler),
+G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name) {
+
+  if (fViewId < 0) return;  // In case error in base class instantiation.
+}
+
+void G4OpenGLStoredWin32Viewer::Initialise () {
+
+  //Check that G4OpenGLWin32Viewer got a double buffered colour visual
+
+  CreateGLWin32Context ();
+  CreateMainWindow ();
+  CreateFontLists ();
+
+// clear the buffers and window.
+  ClearView ();
+  FinishView ();
+
+  glDepthFunc (GL_LEQUAL);
+  glDepthMask (GL_TRUE);
+}
+
+void G4OpenGLStoredWin32Viewer::DrawView () {
+
+  //Make sure current viewer is attached and clean...
+  //Win32 version needed
+  //  glXMakeCurrent (dpy, win, cx);
+  glViewport (0, 0, WinSize_x, WinSize_y);
+
+  G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
+
+  //See if things have changed from last time and remake if necessary...
+  // The fNeedKernelVisit flag might have been set by the user in
+  // /vis/viewer/rebuild, but if not, make decision and set flag only
+  // if necessary...
+  if (!fNeedKernelVisit) KernelVisitDecision ();
+  G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
+  ProcessView ();
+
+  if(style!=G4ViewParameters::hlr &&
+     haloing_enabled) {
+
+    HaloingFirstPass ();
+    DrawDisplayLists ();
+    glFlush ();
+
+    HaloingSecondPass ();
+
+    DrawDisplayLists ();
+    FinishView ();
+
+  } else {
+
+    // If kernel visit was needed, drawing and FinishView will already
+    // have been done, so...
+    if (!kernelVisitWasNeeded) {
+      DrawDisplayLists ();
+      FinishView ();
+    } else {
+    // However, union cutaways are implemented in DrawDisplayLists, so make
+    // an extra pass...
+      if (fVP.IsCutaway() &&
+	  fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
+	ClearView();
+	DrawDisplayLists ();
+	FinishView ();
+      }
+    }
+  }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void G4OpenGLStoredWin32Viewer::FinishView (
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(!fHDC) return;
+
+  glFlush ();
+  ::SwapBuffers(fHDC);
+
+  // Empty the Windows message queue :
+  MSG event;
+  while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
+    ::TranslateMessage(&event);
+    ::DispatchMessage (&event);
+  }
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredX.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredX.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredX.cc	(revision 529)
@@ -0,0 +1,84 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLStoredX.cc,v 1.13 2006/08/14 12:07:19 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  10th February 1997
+// OpenGL graphics system factory.
+
+
+#ifdef G4VIS_BUILD_OPENGLX_DRIVER
+
+#include "G4VisFeaturesOfOpenGL.hh"
+#include "G4VSceneHandler.hh"
+#include "G4OpenGLSceneHandler.hh"
+#include "G4OpenGLViewer.hh"
+#include "G4OpenGLStoredX.hh"
+#include "G4OpenGLStoredXViewer.hh"
+#include "G4OpenGLViewerMessenger.hh"
+#include "G4OpenGLXViewerMessenger.hh"
+
+G4OpenGLStoredX::G4OpenGLStoredX ():
+  G4VGraphicsSystem ("OpenGLStoredX",
+		     "OGLSX",
+		     G4VisFeaturesOfOpenGLSX (),
+		     G4VGraphicsSystem::threeD)
+{
+  G4OpenGLViewerMessenger::GetInstance();
+  G4OpenGLXViewerMessenger::GetInstance();
+}
+
+G4OpenGLStoredX::~G4OpenGLStoredX () {}
+
+G4VSceneHandler* G4OpenGLStoredX::CreateSceneHandler (const G4String& name) {
+  G4VSceneHandler* pScene = new G4OpenGLStoredSceneHandler (*this, name);
+  return    pScene;
+}
+
+G4VViewer* G4OpenGLStoredX::CreateViewer (G4VSceneHandler& scene,
+				      const G4String& name) {
+  G4VViewer* pView =
+    new G4OpenGLStoredXViewer ((G4OpenGLStoredSceneHandler&) scene, name);
+  if (pView) {
+    if (pView -> GetViewId () < 0) {
+      delete pView;
+      pView = 0;
+      G4cerr << "G4OpenGLStoredX::CreateViewer: error flagged by"
+	" negative view id in G4OpenGLStoredXViewer creation."
+	"\n Destroying view and returning null pointer." << G4endl;
+    }
+  }
+  else {
+    G4cerr << "G4OpenGLStoredX::CreateViewer: null pointer on"
+      " new G4OpenGLStoredXViewer." << G4endl;
+  }
+  return pView;
+}
+
+#endif
+
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredXViewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredXViewer.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredXViewer.cc	(revision 529)
@@ -0,0 +1,131 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLStoredXViewer.cc,v 1.21 2006/09/04 12:07:59 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  7th February 1997
+// Class G4OpenGLStoredXViewer : a class derived from G4OpenGLXViewer and
+//                             G4OpenGLStoredViewer.
+
+#ifdef G4VIS_BUILD_OPENGLX_DRIVER
+
+#include "G4OpenGLStoredXViewer.hh"
+
+#include "G4ios.hh"
+
+G4OpenGLStoredXViewer::
+G4OpenGLStoredXViewer (G4OpenGLStoredSceneHandler& sceneHandler,
+		 const G4String& name)
+ : G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
+   G4OpenGLViewer (sceneHandler),
+   G4OpenGLXViewer (sceneHandler),
+   G4OpenGLStoredViewer (sceneHandler)
+{
+  if (fViewId < 0) return;  // In case error in base class instantiation.
+
+  if (!vi_stored) {
+    fViewId = -1;  // This flags an error.
+    G4cerr << "G4OpenGLStoredXViewer::G4OpenGLStoredXViewer -"
+      " G4OpenGLXViewer couldn't get a visual." << G4endl;
+    return;
+  }
+}
+
+G4OpenGLStoredXViewer::~G4OpenGLStoredXViewer () {}
+
+void G4OpenGLStoredXViewer::Initialise () {
+
+  CreateGLXContext (vi_stored);
+  CreateMainWindow ();
+  CreateFontLists ();
+
+  InitializeGLView ();
+
+// clear the buffers and window.
+  ClearView ();
+  FinishView ();
+
+  glDepthFunc (GL_LEQUAL);
+  glDepthMask (GL_TRUE);
+}
+
+void G4OpenGLStoredXViewer::DrawView () {
+
+  //Make sure current viewer is attached and clean...
+  glXMakeCurrent (dpy, win, cx);
+  glViewport (0, 0, WinSize_x, WinSize_y);
+
+  G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
+
+  //See if things have changed from last time and remake if necessary...
+  // The fNeedKernelVisit flag might have been set by the user in
+  // /vis/viewer/rebuild, but if not, make decision and set flag only
+  // if necessary...
+  if (!fNeedKernelVisit) KernelVisitDecision ();
+  G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
+  ProcessView ();
+
+  if(style!=G4ViewParameters::hlr &&
+     haloing_enabled) {
+
+    HaloingFirstPass ();
+    DrawDisplayLists ();
+    glFlush ();
+
+    HaloingSecondPass ();
+
+    DrawDisplayLists ();
+    FinishView ();
+
+  } else {
+
+    // If kernel visit was needed, drawing and FinishView will already
+    // have been done, so...
+    if (!kernelVisitWasNeeded) {
+      DrawDisplayLists ();
+      FinishView ();
+    } else {
+    // However, union cutaways are implemented in DrawDisplayLists, so make
+    // an extra pass...
+      if (fVP.IsCutaway() &&
+	  fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
+	ClearView();
+	DrawDisplayLists ();
+	FinishView ();
+      }
+    }
+  }
+}
+
+void G4OpenGLStoredXViewer::FinishView () {
+  glXWaitGL (); //Wait for effects of all previous OpenGL commands to
+                //be propogated before progressing.
+  glXSwapBuffers (dpy, win);  
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredXm.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredXm.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredXm.cc	(revision 529)
@@ -0,0 +1,79 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLStoredXm.cc,v 1.11 2006/08/14 12:07:19 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  10th February 1997
+// OpenGL graphics system factory.
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4VisFeaturesOfOpenGL.hh"
+#include "G4VSceneHandler.hh"
+#include "G4OpenGLSceneHandler.hh"
+#include "G4OpenGLViewer.hh"
+#include "G4OpenGLStoredXm.hh"
+#include "G4OpenGLStoredXmViewer.hh"
+#include "G4OpenGLViewerMessenger.hh"
+#include "G4OpenGLXmViewerMessenger.hh"
+
+G4OpenGLStoredXm::G4OpenGLStoredXm ():
+  G4VGraphicsSystem ("OpenGLStoredXm",
+		     "OGLSXm",
+		     G4VisFeaturesOfOpenGLSXm (),
+		     G4VGraphicsSystem::threeD)
+{
+  G4OpenGLViewerMessenger::GetInstance();
+  G4OpenGLXmViewerMessenger::GetInstance();
+}
+
+G4VSceneHandler* G4OpenGLStoredXm::CreateSceneHandler (const G4String& name) {
+  G4VSceneHandler* pScene = new G4OpenGLStoredSceneHandler (*this, name);
+  return    pScene;
+}
+
+G4VViewer* G4OpenGLStoredXm::CreateViewer (G4VSceneHandler& scene, const G4String& name) {
+  G4VViewer* pView =
+    new G4OpenGLStoredXmViewer ((G4OpenGLStoredSceneHandler&) scene, name);
+  if (pView) {
+    if (pView -> GetViewId () < 0) {
+      delete pView;
+      pView = 0;
+      G4cerr << "G4OpenGLStoredXm::CreateViewer: error flagged by"
+	" negative view id in G4OpenGLStoredXmViewer creation."
+	"\n Destroying view and returning null pointer." << G4endl;
+    }
+  }
+  else {
+    G4cerr << "G4OpenGLStoredXm::CreateViewer: null pointer on"
+      " new G4OpenGLStoredXmViewer." << G4endl;
+  }
+  return pView;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredXmViewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredXmViewer.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredXmViewer.cc	(revision 529)
@@ -0,0 +1,136 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLStoredXmViewer.cc,v 1.21 2006/09/04 12:07:59 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  10th February 1997
+// Class G4OpenGLStoredXmViewer : a class derived from G4OpenGLXmViewer 
+//                              and G4OpenGLStoredViewer.
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLStoredXmViewer.hh"
+
+#include "G4ios.hh"
+
+G4OpenGLStoredXmViewer::
+G4OpenGLStoredXmViewer (G4OpenGLStoredSceneHandler& sceneHandler,
+			const G4String& name)
+ : G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
+   G4OpenGLViewer (sceneHandler),
+   G4OpenGLXmViewer (sceneHandler),
+   G4OpenGLStoredViewer (sceneHandler)
+{
+
+  if (fViewId < 0) return;  // In case error in base class instantiation.
+
+  if (!vi_stored) {
+    fViewId = -1;  // This flags an error.
+    G4cerr << "G4OpenGLStoredXmViewer::G4OpenGLStoredXmViewer -"
+      " G4OpenGLXmViewer couldn't get a visual." << G4endl;
+    return;
+  }
+}
+
+G4OpenGLStoredXmViewer::~G4OpenGLStoredXmViewer () {}
+
+void G4OpenGLStoredXmViewer::Initialise () {
+
+  CreateGLXContext (vi_stored);
+  CreateMainWindow ();
+  CreateFontLists ();
+
+  InitializeGLView ();
+
+// clear the buffers and window.
+  ClearView ();
+  FinishView ();
+  
+  glDepthFunc (GL_LEQUAL);
+  glDepthMask (GL_TRUE);
+  
+  glEnable (GL_BLEND);
+  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+  glDrawBuffer (GL_BACK);
+}
+
+void G4OpenGLStoredXmViewer::DrawView () {
+
+  //Make sure current viewer is attached and clean...
+  glXMakeCurrent (dpy, win, cx);
+  glViewport (0, 0, WinSize_x, WinSize_y);
+
+  G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
+
+  //See if things have changed from last time and remake if necessary...
+  // /vis/viewer/rebuild, but if not, make decision and set flag only
+  // if necessary...
+  if (!fNeedKernelVisit) KernelVisitDecision ();
+  G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
+  ProcessView ();
+
+  if(style!=G4ViewParameters::hlr &&
+     haloing_enabled) {
+
+    HaloingFirstPass ();
+    DrawDisplayLists ();
+    glFlush ();
+
+    HaloingSecondPass ();
+
+    DrawDisplayLists ();
+    FinishView ();
+
+  } else {
+
+    // If kernel visit was needed, drawing and FinishView will already
+    // have been done, so...
+    if (!kernelVisitWasNeeded) {
+      DrawDisplayLists ();
+      FinishView ();
+    } else {
+    // However, union cutaways are implemented in DrawDisplayLists, so make
+    // an extra pass...
+      if (fVP.IsCutaway() &&
+	  fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
+	ClearView();
+	DrawDisplayLists ();
+	FinishView ();
+      }
+    }
+  }
+}
+
+void G4OpenGLStoredXmViewer::FinishView () {
+  glXWaitGL (); //Wait for effects of all previous OpenGL commands to
+                //be propogated before progressing.
+  glXSwapBuffers (dpy, win);  
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLTransform3D.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLTransform3D.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLTransform3D.cc	(revision 529)
@@ -0,0 +1,57 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLTransform3D.cc,v 1.8 2006/06/29 21:19:32 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Andrew Walkden  24th October 1996
+// G4OpenGLTransform3D provides OpenGL style transformation matrix
+// from G4Transform3D.
+
+#ifdef G4VIS_BUILD_OPENGL_DRIVER
+
+#include "G4OpenGLTransform3D.hh"
+
+G4OpenGLTransform3D::G4OpenGLTransform3D (const G4Transform3D &t):
+  G4Transform3D (t) {}
+
+const GLdouble* G4OpenGLTransform3D::GetGLMatrix () 
+{
+  GLdouble *p = m;
+  for (size_t i=0; i<4; i++)
+  { 
+    for (size_t k=0; k<3; k++)
+    {
+      *p++ = operator()(k,i);
+    }
+    *p++ = 0.; 
+  } 
+  m[15] = 1.; 
+  return m;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLViewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLViewer.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLViewer.cc	(revision 529)
@@ -0,0 +1,275 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLViewer.cc,v 1.29 2006/09/19 16:13:15 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  27th March 1996
+// OpenGL view - opens window, hard copy, etc.
+
+#ifdef G4VIS_BUILD_OPENGL_DRIVER
+
+#include "G4ios.hh"
+#include "G4OpenGLViewer.hh"
+#include "G4OpenGLSceneHandler.hh"
+#include "G4OpenGLTransform3D.hh"
+
+#include "G4Scene.hh"
+#include "G4VisExtent.hh"
+#include "G4LogicalVolume.hh"
+#include "G4VSolid.hh"
+#include "G4Point3D.hh"
+#include "G4Normal3D.hh"
+#include "G4Plane3D.hh"
+
+G4OpenGLViewer::G4OpenGLViewer (G4OpenGLSceneHandler& scene):
+G4VViewer (scene, -1),
+background (G4Colour(0.,0.,0.)),
+transparency_enabled (true),
+antialiasing_enabled (false),
+haloing_enabled (false),
+fStartTime(-DBL_MAX),
+fEndTime(DBL_MAX),
+fFadeFactor(0.),
+fDisplayHeadTime(false),
+fDisplayHeadTimeX(-0.9),
+fDisplayHeadTimeY(-0.9),
+fDisplayHeadTimeSize(24.),
+fDisplayHeadTimeRed(0.),
+fDisplayHeadTimeGreen(1.),
+fDisplayHeadTimeBlue(1.),
+fDisplayLightFront(false),
+fDisplayLightFrontX(0.),
+fDisplayLightFrontY(0.),
+fDisplayLightFrontZ(0.),
+fDisplayLightFrontT(0.),
+fDisplayLightFrontRed(0.),
+fDisplayLightFrontGreen(1.),
+fDisplayLightFrontBlue(0.)
+{
+  // Make changes to view parameters for OpenGL...
+  fVP.SetAutoRefresh(true);
+  fDefaultVP.SetAutoRefresh(true);
+
+  //  glClearColor (0.0, 0.0, 0.0, 0.0);
+  //  glClearDepth (1.0);
+  //  glDisable (GL_BLEND);
+  //  glDisable (GL_LINE_SMOOTH);
+  //  glDisable (GL_POLYGON_SMOOTH);
+
+}
+
+G4OpenGLViewer::~G4OpenGLViewer () {}
+
+void G4OpenGLViewer::InitializeGLView () 
+{
+  glClearColor (0.0, 0.0, 0.0, 0.0);
+  glClearDepth (1.0);
+  glDisable (GL_BLEND);
+  glDisable (GL_LINE_SMOOTH);
+  glDisable (GL_POLYGON_SMOOTH);
+}  
+
+void G4OpenGLViewer::ClearView () {
+  glClearColor (background.GetRed(),
+		background.GetGreen(),
+		background.GetBlue(),
+		1.);
+  glClearDepth (1.0);
+  //Below line does not compile with Mesa includes. 
+  //glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
+  glClear (GL_COLOR_BUFFER_BIT);
+  glClear (GL_DEPTH_BUFFER_BIT);
+  glClear (GL_STENCIL_BUFFER_BIT);
+  glFlush ();
+}
+
+void G4OpenGLViewer::SetView () {
+  
+  // Calculates view representation based on extent of object being
+  // viewed and (initial) viewpoint.  (Note: it can change later due
+  // to user interaction via visualization system's GUI.)
+  
+  // Lighting.
+  GLfloat lightPosition [4];
+  lightPosition [0] = fVP.GetActualLightpointDirection().x();
+  lightPosition [1] = fVP.GetActualLightpointDirection().y();
+  lightPosition [2] = fVP.GetActualLightpointDirection().z();
+  lightPosition [3] = 0.;
+  // Light position is "true" light direction, so must come after gluLookAt.
+  GLfloat ambient [] = { 0.2, 0.2, 0.2, 1.};
+  GLfloat diffuse [] = { 0.8, 0.8, 0.8, 1.};
+  glEnable (GL_LIGHT0);
+  glLightfv (GL_LIGHT0, GL_AMBIENT, ambient);
+  glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse);
+  
+  // Get radius of scene, etc.
+  // Note that this procedure properly takes into account zoom, dolly and pan.
+  const G4Point3D targetPoint
+    = fSceneHandler.GetScene()->GetStandardTargetPoint()
+    + fVP.GetCurrentTargetPoint ();
+  G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
+  if(radius<=0.) radius = 1.;
+  const G4double cameraDistance = fVP.GetCameraDistance (radius);
+  const G4Point3D cameraPosition =
+    targetPoint + cameraDistance * fVP.GetViewpointDirection().unit();
+  const GLdouble pnear   = fVP.GetNearDistance (cameraDistance, radius);
+  const GLdouble pfar    = fVP.GetFarDistance  (cameraDistance, pnear, radius);
+  const GLdouble right  = fVP.GetFrontHalfHeight (pnear, radius);
+  const GLdouble left   = -right;
+  const GLdouble bottom = left;
+  const GLdouble top    = right;
+  
+  glMatrixMode (GL_PROJECTION); // set up Frustum.
+  glLoadIdentity();
+
+  const G4Vector3D scale = fVP.GetScaleFactor();
+  glScaled(scale.x(),scale.y(),scale.z());
+  
+  if (fVP.GetFieldHalfAngle() == 0.) {
+    glOrtho (left, right, bottom, top, pnear, pfar);
+  }
+  else {
+    glFrustum (left, right, bottom, top, pnear, pfar);
+  }
+  
+  glMatrixMode (GL_MODELVIEW); // apply further transformations to scene.
+  glLoadIdentity();
+  
+  const G4Normal3D& upVector = fVP.GetUpVector ();  
+  G4Point3D gltarget;
+  if (cameraDistance > 1.e-6 * radius) {
+    gltarget = targetPoint;
+  }
+  else {
+    gltarget = targetPoint - radius * fVP.GetViewpointDirection().unit();
+  }
+
+  const G4Point3D& pCamera = cameraPosition;  // An alias for brevity.
+  gluLookAt (pCamera.x(),  pCamera.y(),  pCamera.z(),       // Viewpoint.
+	     gltarget.x(), gltarget.y(), gltarget.z(),      // Target point.
+	     upVector.x(), upVector.y(), upVector.z());     // Up vector.
+  
+  // Light position is "true" light direction, so must come after gluLookAt.
+  glLightfv (GL_LIGHT0, GL_POSITION, lightPosition);
+
+  // OpenGL no longer seems to reconstruct clipped edges, so, when the
+  // BooleanProcessor is up to it, abandon this and use generic
+  // clipping in G4OpenGLSceneHandler::CreateSectionPolyhedron.  Also,
+  // force kernel visit on change of clipping plane in
+  // G4OpenGLStoredViewer::CompareForKernelVisit.
+  if (fVP.IsSection () ) {  // pair of back to back clip planes.
+    const G4Plane3D& s = fVP.GetSectionPlane ();
+    double sArray[4];
+    sArray[0] = s.a();
+    sArray[1] = s.b();
+    sArray[2] = s.c();
+    sArray[3] = s.d() + radius * 1.e-05;
+    glClipPlane (GL_CLIP_PLANE0, sArray);
+    glEnable (GL_CLIP_PLANE0);
+    sArray[0] = -s.a();
+    sArray[1] = -s.b();
+    sArray[2] = -s.c();
+    sArray[3] = -s.d() + radius * 1.e-05;
+    glClipPlane (GL_CLIP_PLANE1, sArray);
+    glEnable (GL_CLIP_PLANE1);
+  } else {
+    glDisable (GL_CLIP_PLANE0);
+    glDisable (GL_CLIP_PLANE1);
+  }
+
+  const G4Planes& cutaways = fVP.GetCutawayPlanes();
+  size_t nPlanes = cutaways.size();
+  if (fVP.IsCutaway() &&
+      fVP.GetCutawayMode() == G4ViewParameters::cutawayIntersection &&
+      nPlanes > 0) {
+    double a[4];
+    a[0] = cutaways[0].a();
+    a[1] = cutaways[0].b();
+    a[2] = cutaways[0].c();
+    a[3] = cutaways[0].d();
+    glClipPlane (GL_CLIP_PLANE2, a);
+    glEnable (GL_CLIP_PLANE2);
+    if (nPlanes > 1) {
+      a[0] = cutaways[1].a();
+      a[1] = cutaways[1].b();
+      a[2] = cutaways[1].c();
+      a[3] = cutaways[1].d();
+      glClipPlane (GL_CLIP_PLANE3, a);
+      glEnable (GL_CLIP_PLANE3);
+    }
+    if (nPlanes > 2) {
+      a[0] = cutaways[2].a();
+      a[1] = cutaways[2].b();
+      a[2] = cutaways[2].c();
+      a[3] = cutaways[2].d();
+      glClipPlane (GL_CLIP_PLANE4, a);
+      glEnable (GL_CLIP_PLANE4);
+    }
+  } else {
+    glDisable (GL_CLIP_PLANE2);
+    glDisable (GL_CLIP_PLANE3);
+    glDisable (GL_CLIP_PLANE4);
+  }
+
+  // Background.
+  background = fVP.GetBackgroundColour ();
+
+}
+
+void G4OpenGLViewer::HaloingFirstPass () {
+  
+  //To perform haloing, first Draw all information to the depth buffer
+  //alone, using a chunky line width, and then Draw all info again, to
+  //the colour buffer, setting a thinner line width an the depth testing 
+  //function to less than or equal, so if two lines cross, the one 
+  //passing behind the other will not pass the depth test, and so not
+  //get rendered either side of the infront line for a short distance.
+
+  //First, disable writing to the colo(u)r buffer...
+  glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+
+  //Now enable writing to the depth buffer...
+  glDepthMask (GL_TRUE);
+  glDepthFunc (GL_LESS);
+  glClearDepth (1.0);
+
+  //Finally, set the line width to something wide...
+  glLineWidth (3.0);
+
+}
+
+void G4OpenGLViewer::HaloingSecondPass () {
+
+  //And finally, turn the colour buffer back on with a sesible line width...
+  glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+  glDepthFunc (GL_LEQUAL);
+  glLineWidth (1.0);
+
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLViewerMessenger.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLViewerMessenger.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLViewerMessenger.cc	(revision 529)
@@ -0,0 +1,330 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLViewerMessenger.cc,v 1.5 2006/10/24 06:20:42 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+
+#include "G4OpenGLViewerMessenger.hh"
+
+#include "G4OpenGLViewer.hh"
+#include "G4OpenGLStoredViewer.hh"
+#include "G4UImanager.hh"
+#include "G4UIcommand.hh"
+#include "G4UIdirectory.hh"
+#include "G4UIcmdWithADouble.hh"
+#include "G4UIcmdWithABool.hh"
+#include "G4VisManager.hh"
+#include <sstream>
+
+G4OpenGLViewerMessenger*
+G4OpenGLViewerMessenger::fpInstance = 0;
+
+G4OpenGLViewerMessenger*
+G4OpenGLViewerMessenger::GetInstance()
+{
+  if (!fpInstance) fpInstance = new G4OpenGLViewerMessenger;
+  return fpInstance;
+}
+
+G4OpenGLViewerMessenger::G4OpenGLViewerMessenger()
+{
+  G4bool omitable;
+
+  fpDirectory = new G4UIdirectory("/vis/ogl/");
+  fpDirectory->SetGuidance("G4OpenGLViewer commands.");
+
+  fpDirectorySet = new G4UIdirectory ("/vis/ogl/set/");
+  fpDirectorySet->SetGuidance("G4OpenGLViewer set commands.");
+
+  G4UIparameter* parameter;
+
+  fpCommandDisplayHeadTime =
+    new G4UIcommand("/vis/ogl/set/displayHeadTime", this);
+  fpCommandDisplayHeadTime->SetGuidance
+    ("Display head time of range in 2D text.");
+  parameter = new G4UIparameter ("displayHeadTime", 'b', omitable = false);
+  parameter->SetDefaultValue(false);
+  fpCommandDisplayHeadTime->SetParameter(parameter);
+  parameter = new G4UIparameter ("screenX", 'd', omitable = true);
+  parameter->SetGuidance("-1 < screenX < 1");
+  parameter->SetParameterRange("screenX >= -1. && screenX <= 1.");
+  parameter->SetDefaultValue(-0.9);
+  fpCommandDisplayHeadTime->SetParameter(parameter);
+  parameter = new G4UIparameter ("screenY", 'd', omitable = true);
+  parameter->SetGuidance("-1 < screenY < 1");
+  parameter->SetParameterRange("screenY >= -1. && screenY <= 1.");
+  parameter->SetDefaultValue(-0.9);
+  fpCommandDisplayHeadTime->SetParameter(parameter);
+  parameter = new G4UIparameter ("screenSize", 'd', omitable = true);
+  parameter->SetDefaultValue(24.);
+  fpCommandDisplayHeadTime->SetParameter(parameter);
+  parameter = new G4UIparameter ("red", 'd', omitable = true);
+  parameter->SetParameterRange("red >= 0. && red <= 1.");
+  parameter->SetDefaultValue(0.);
+  fpCommandDisplayHeadTime->SetParameter(parameter);
+  parameter = new G4UIparameter ("green", 'd', omitable = true);
+  parameter->SetParameterRange("green >= 0. && green <= 1.");
+  parameter->SetDefaultValue(1.);
+  fpCommandDisplayHeadTime->SetParameter(parameter);
+  parameter = new G4UIparameter ("blue", 'd', omitable = true);
+  parameter->SetParameterRange("blue >= 0. && blue <= 1.");
+  parameter->SetDefaultValue(1.);
+  fpCommandDisplayHeadTime->SetParameter(parameter);
+
+  fpCommandDisplayLightFront =
+    new G4UIcommand("/vis/ogl/set/displayLightFront", this);
+  fpCommandDisplayLightFront->SetGuidance
+    ("Display the light front at head time.");
+  fpCommandDisplayLightFront->SetGuidance
+    ("Tip: The trajectories can appear of jump ahead of the light front"
+     "\nbecause their time range overlaps the viewer's time range.  To"
+     "\naverage out this discrete time effect, advance the light front by"
+     "\nhalf the trajectories interval. E.g., if the trajectory time slice"
+     "\ninterval is 0.01 ns:"
+     "\n  /vis/ogl/set/displayLightFront true -90 0 0 mm -0.005 ns"
+     "\nTo prevent them beating the light front at all:"
+     "\n  /vis/ogl/set/displayLightFront true -90 0 0 mm -0.01 ns");
+  parameter = new G4UIparameter ("displayLightFront", 'b', omitable = false);
+  parameter->SetDefaultValue(false);
+  fpCommandDisplayLightFront->SetParameter(parameter);
+  parameter = new G4UIparameter ("originX", 'd', omitable = true);
+  parameter->SetDefaultValue(0.);
+  fpCommandDisplayLightFront->SetParameter(parameter);
+  parameter = new G4UIparameter ("originY", 'd', omitable = true);
+  parameter->SetDefaultValue(0.);
+  fpCommandDisplayLightFront->SetParameter(parameter);
+  parameter = new G4UIparameter ("originZ", 'd', omitable = true);
+  parameter->SetDefaultValue(0.);
+  fpCommandDisplayLightFront->SetParameter(parameter);
+  parameter = new G4UIparameter ("space_unit", 's', omitable = true);
+  parameter->SetDefaultValue("m");
+  fpCommandDisplayLightFront->SetParameter(parameter);
+  parameter = new G4UIparameter ("originT", 'd', omitable = true);
+  parameter->SetDefaultValue(0.);
+  fpCommandDisplayLightFront->SetParameter(parameter);
+  parameter = new G4UIparameter ("time_unit", 's', omitable = true);
+  parameter->SetDefaultValue("s");
+  fpCommandDisplayLightFront->SetParameter(parameter);
+  parameter = new G4UIparameter ("red", 'd', omitable = true);
+  parameter->SetParameterRange("red >= 0. && red <= 1.");
+  parameter->SetDefaultValue(0.);
+  fpCommandDisplayLightFront->SetParameter(parameter);
+  parameter = new G4UIparameter ("green", 'd', omitable = true);
+  parameter->SetParameterRange("green >= 0. && green <= 1.");
+  parameter->SetDefaultValue(1.);
+  fpCommandDisplayLightFront->SetParameter(parameter);
+  parameter = new G4UIparameter ("blue", 'd', omitable = true);
+  parameter->SetParameterRange("blue >= 0. && blue <= 1.");
+  parameter->SetDefaultValue(0.);
+  fpCommandDisplayLightFront->SetParameter(parameter);
+
+  fpCommandEndTime =
+    new G4UIcommand("/vis/ogl/set/endTime", this);
+  fpCommandEndTime->SetGuidance("Set end and range of track time.");
+  parameter = new G4UIparameter ("end-time", 'd', omitable = false);
+  parameter->SetDefaultValue(DBL_MAX);
+  fpCommandEndTime->SetParameter(parameter);
+  parameter = new G4UIparameter ("end-time-unit", 's', omitable = false);
+  parameter->SetDefaultValue("ns");
+  fpCommandEndTime->SetParameter(parameter);
+  parameter = new G4UIparameter ("time-range", 'd', omitable = true);
+  parameter->SetDefaultValue(-1.);
+  fpCommandEndTime->SetParameter(parameter);
+  parameter = new G4UIparameter ("time-range-unit", 's', omitable = true);
+  parameter->SetDefaultValue("ns");
+  fpCommandEndTime->SetParameter(parameter);
+
+  fpCommandFade = new G4UIcmdWithADouble("/vis/ogl/set/fade", this);
+  fpCommandFade->SetGuidance
+    ("0: no fade; 1: maximum fade with time within range.");
+  fpCommandFade->SetParameterName("fadefactor", omitable = false);
+  fpCommandFade->SetRange("fadefactor>=0.&&fadefactor<=1.");
+  fpCommandFade->SetDefaultValue(0.);
+
+  fpCommandStartTime =
+    new G4UIcommand("/vis/ogl/set/startTime", this);
+  fpCommandStartTime->SetGuidance("Set start and range of track time.");
+  parameter = new G4UIparameter ("start-time", 'd', omitable = false);
+  parameter->SetDefaultValue(-DBL_MAX);
+  fpCommandStartTime->SetParameter(parameter);
+  parameter = new G4UIparameter ("start-time-unit", 's', omitable = false);
+  parameter->SetDefaultValue("ns");
+  fpCommandStartTime->SetParameter(parameter);
+  parameter = new G4UIparameter ("time-range", 'd', omitable = true);
+  parameter->SetDefaultValue(-1.);
+  fpCommandStartTime->SetParameter(parameter);
+  parameter = new G4UIparameter ("time-range-unit", 's', omitable = true);
+  parameter->SetDefaultValue("ns");
+  fpCommandStartTime->SetParameter(parameter);
+
+  fpCommandTransparency =
+    new G4UIcmdWithABool("/vis/ogl/set/transparency", this);
+  fpCommandTransparency->SetGuidance
+    ("True/false to enable/disable rendering of transparent objects.");
+  fpCommandTransparency->SetParameterName
+    ("transparency-enabled", omitable = true);
+  fpCommandTransparency->SetDefaultValue(true);
+}
+
+G4OpenGLViewerMessenger::~G4OpenGLViewerMessenger ()
+{
+  delete fpCommandTransparency;
+  delete fpCommandStartTime;
+  delete fpCommandFade;
+  delete fpCommandEndTime;
+  delete fpCommandDisplayLightFront;
+  delete fpCommandDisplayHeadTime;
+  delete fpDirectorySet;
+  delete fpDirectory;
+}
+
+void G4OpenGLViewerMessenger::SetNewValue
+(G4UIcommand* command, G4String newValue)
+{
+  G4VisManager* pVisManager = G4VisManager::GetInstance();
+
+  G4VViewer* pVViewer = pVisManager->GetCurrentViewer();
+
+  if (!pVViewer) {
+    G4cout <<
+      "G4OpenGLViewerMessenger::SetNewValue: No current viewer."
+      "\n  \"/vis/open\", or similar, to get one."
+           << G4endl;
+    return;
+  }
+
+  G4OpenGLViewer* pOGLViewer = dynamic_cast<G4OpenGLViewer*>(pVViewer);
+
+  if (!pOGLViewer) {
+    G4cout <<
+      "G4OpenGLViewerMessenger::SetNewValue: Current viewer is not of type"
+      "\n  OGL.  Use \"/vis/viewer/select\" or \"/vis/open\"."
+           << G4endl;
+    return;
+  }
+
+  G4OpenGLStoredViewer* pViewer =
+    dynamic_cast<G4OpenGLStoredViewer*>(pVViewer);
+
+  if (!pViewer) {
+    G4cout <<
+  "G4OpenGLViewerMessenger::SetNewValue: Current viewer is not of type OGLS."
+  "\n  The time slice viewing feature is only implemented for OGL Stored"
+  "\n  viewers at present.  Use \"/vis/viewer/select\" or \"/vis/open\"."
+           << G4endl;
+    return;
+  }
+
+  if (command == fpCommandDisplayHeadTime)
+    {
+      G4String display;
+      G4double screenX, screenY, screenSize, red, green, blue;
+      std::istringstream iss(newValue);
+      iss >> display >> screenX >> screenY
+	  >> screenSize >> red >> green >> blue;
+      pViewer->fDisplayHeadTime = command->ConvertToBool(display);
+      pViewer->fDisplayHeadTimeX = screenX;
+      pViewer->fDisplayHeadTimeY = screenY;
+      pViewer->fDisplayHeadTimeSize = screenSize;
+      pViewer->fDisplayHeadTimeRed = red;
+      pViewer->fDisplayHeadTimeGreen = green;
+      pViewer->fDisplayHeadTimeBlue = blue;
+    }
+
+  if (command == fpCommandDisplayLightFront)
+    {
+      G4String display, originX, originY, originZ, unitS, originT, unitT;
+      G4double red, green, blue;
+      std::istringstream iss(newValue);
+      iss >> display
+	  >> originX >> originY >> originZ >> unitS
+	  >> originT >> unitT
+	  >> red >> green >> blue;
+      pViewer->fDisplayLightFront = command->ConvertToBool(display);
+      pViewer->fDisplayLightFrontX =
+	command->ConvertToDimensionedDouble(G4String(originX + ' ' + unitS));
+      pViewer->fDisplayLightFrontY =
+	command->ConvertToDimensionedDouble(G4String(originY + ' ' + unitS));
+      pViewer->fDisplayLightFrontZ =
+	command->ConvertToDimensionedDouble(G4String(originZ + ' ' + unitS));
+      pViewer->fDisplayLightFrontT =
+	command->ConvertToDimensionedDouble(G4String(originT + ' ' + unitT));
+      pViewer->fDisplayLightFrontRed = red;
+      pViewer->fDisplayLightFrontGreen = green;
+      pViewer->fDisplayLightFrontBlue = blue;
+    }
+
+  if (command == fpCommandEndTime)
+    {
+      G4String end_time_string, end_time_unit,
+	time_range_string, time_range_unit;
+      std::istringstream iss(newValue);
+      iss >> end_time_string >> end_time_unit
+	  >> time_range_string >> time_range_unit;
+      pViewer->fEndTime = command->ConvertToDimensionedDouble
+	(G4String(end_time_string + ' ' + end_time_unit));
+      G4double timeRange = command->ConvertToDimensionedDouble
+	(G4String(time_range_string + ' ' + time_range_unit));
+      if (timeRange > 0.) {
+	pViewer->fStartTime = pViewer->fEndTime - timeRange;
+      }
+      if (pViewer->fVP.IsAutoRefresh())
+	G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
+    }
+
+  if (command == fpCommandFade)
+    {
+      pViewer->fFadeFactor = command->ConvertToDouble(newValue);
+      if (pViewer->fVP.IsAutoRefresh())
+	G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
+    }
+
+  if (command == fpCommandStartTime)
+    {
+      G4String start_time_string, start_time_unit,
+	time_range_string, time_range_unit;
+      std::istringstream iss(newValue);
+      iss >> start_time_string >> start_time_unit
+	  >> time_range_string >> time_range_unit;
+      pViewer->fStartTime = command->ConvertToDimensionedDouble
+	(G4String(start_time_string + ' ' + start_time_unit));
+      G4double timeRange = command->ConvertToDimensionedDouble
+	(G4String(time_range_string + ' ' + time_range_unit));
+      if (timeRange > 0.) {
+	pViewer->fEndTime = pViewer->fStartTime + timeRange;
+      }
+      if (pViewer->fVP.IsAutoRefresh())
+	G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
+    }
+
+  if (command == fpCommandTransparency)
+    {
+      pViewer->transparency_enabled = command->ConvertToBool(newValue);
+      if (pViewer->fVP.IsAutoRefresh())
+	G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
+    }
+
+}
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLWin32Viewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLWin32Viewer.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLWin32Viewer.cc	(revision 529)
@@ -0,0 +1,289 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLWin32Viewer.cc,v 1.17 2006/06/29 21:19:36 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// G4OpenGLWin32Viewer : Class to provide WindowsNT specific
+//                     functionality for OpenGL in GEANT4
+//
+// 27/06/2003 : G.Barrand : implementation (at last !).
+
+#ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER
+
+#include "G4OpenGLWin32Viewer.hh"
+
+#include "G4ios.hh"
+#include "G4VisExtent.hh"
+#include "G4LogicalVolume.hh"
+#include "G4VSolid.hh"
+#include "G4Point3D.hh"
+#include "G4Normal3D.hh"
+
+
+//////////////////////////////////////////////////////////////////////////////
+void G4OpenGLWin32Viewer::SetView (
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(!fHDC) return;
+  if(!fHGLRC) return;
+  ::wglMakeCurrent(fHDC,fHGLRC);
+  G4OpenGLViewer::SetView ();  
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void G4OpenGLWin32Viewer::ShowView (
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(!fHDC) return;
+  glFlush ();
+  // Empty the Windows message queue :
+  MSG event;
+  while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
+    ::TranslateMessage(&event);
+    ::DispatchMessage (&event);
+  }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void G4OpenGLWin32Viewer::GetWin32Connection (
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void G4OpenGLWin32Viewer::CreateGLWin32Context (
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void G4OpenGLWin32Viewer::CreateMainWindow (
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(fWindow) return; //Done.
+
+  // Bill Gates stuff...
+  static const char className[] = "G4OpenGLWin32";
+  static bool done = false;
+  if(done==false) {
+    WNDCLASS wc;
+    wc.style = CS_HREDRAW | CS_VREDRAW;
+    wc.lpfnWndProc = (WNDPROC)WindowProc;
+    wc.cbClsExtra = 0;
+    wc.cbWndExtra = 0;
+    wc.hInstance = ::GetModuleHandle(NULL);
+    wc.hIcon = LoadIcon  (NULL, IDI_APPLICATION);
+    wc.hCursor = LoadCursor(NULL,IDC_CROSS);
+    wc.hbrBackground = NULL;
+    wc.lpszMenuName = className;
+    wc.lpszClassName = className;
+    ::RegisterClass(&wc);
+    done = true;
+  }  
+  
+  WinSize_x = 400;
+  WinSize_y = 400;
+  if (WinSize_x < fVP.GetWindowSizeHintX ())
+    WinSize_x = fVP.GetWindowSizeHintX ();
+  if (WinSize_y < fVP.GetWindowSizeHintY ())
+    WinSize_y = fVP.GetWindowSizeHintY ();
+
+  fWindow = ::CreateWindow(className,fName.c_str(), 
+			   WS_OVERLAPPEDWINDOW,
+			   //WS_CHILD | WS_VISIBLE,
+			   0,0,
+			   WinSize_x,WinSize_y,
+			   NULL, NULL, 
+			   ::GetModuleHandle(NULL),
+			   NULL);
+  if(!fWindow) return;
+
+  ::SetWindowLong(fWindow,GWL_USERDATA,LONG(this));
+
+  // initialize OpenGL rendering :
+  fHDC = ::GetDC(fWindow);
+  if( fHDC && (SetWindowPixelFormat(fHDC)==TRUE) ) {
+    fHGLRC = ::wglCreateContext(fHDC);
+  }
+  
+  if(fHDC && fHGLRC) {
+    ::wglMakeCurrent(fHDC,fHGLRC);
+  }
+
+  ::SetForegroundWindow(fWindow);
+  ::ShowWindow(fWindow,SW_SHOWDEFAULT);
+  ::UpdateWindow(fWindow);
+  ::DrawMenuBar(fWindow);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+G4OpenGLWin32Viewer::G4OpenGLWin32Viewer (
+ G4OpenGLSceneHandler& scene
+)
+:G4VViewer (scene, -1)
+,G4OpenGLViewer (scene)
+,fWindow(0)
+,fHDC(0)
+,fHGLRC(0)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+}
+
+//////////////////////////////////////////////////////////////////////////////
+G4OpenGLWin32Viewer::~G4OpenGLWin32Viewer (
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  // This is the end (Jim Morisson).
+  if (fViewId >= 0) {
+    if(wglGetCurrentContext()!=NULL) wglMakeCurrent(NULL,NULL);
+    if(fHGLRC)	{
+      wglDeleteContext(fHGLRC);
+      fHGLRC = NULL;
+    }
+    
+    if(fWindow) {
+      ::SetWindowLong(fWindow,GWL_USERDATA,LONG(NULL));
+      if(fHDC) ::ReleaseDC(fWindow,fHDC);
+      ::DestroyWindow(fWindow);
+    }
+  }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+LRESULT CALLBACK G4OpenGLWin32Viewer::WindowProc ( 
+ HWND   aWindow
+,UINT   aMessage
+,WPARAM aWParam
+,LPARAM aLParam
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+/*
+  switch (aMessage) { 
+  case WM_PAINT:{
+    printf("debug : PAINT\n");
+    HDC	hDC;
+    PAINTSTRUCT	ps;
+    hDC = BeginPaint(aWindow,&ps);
+    if(This) {
+      // FIXME : To have an automatic refresh someone have to redraw here.
+    }
+    EndPaint(aWindow, &ps);
+
+    //FIXME : have to handle WM_RESIZE
+    //pView->WinSize_x = (G4int) width;
+    //pView->WinSize_y = (G4int) height;
+    G4OpenGLWin32Viewer* This = 
+      (G4OpenGLWin32Viewer*)::GetWindowLong(aWindow,GWL_USERDATA);
+    if(This) {
+      This->SetView();
+      glViewport(0,0,This->WinSize_x,This->WinSize_y);
+      This->ClearView();
+      This->DrawView();
+      // WARNING : the below empty the Windows message queue...
+      This->FinishView();
+    }
+  } return 0;
+  default:
+    return DefWindowProc(aWindow,aMessage,aWParam,aLParam);
+  }
+*/
+  return DefWindowProc(aWindow,aMessage,aWParam,aLParam);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+bool G4OpenGLWin32Viewer::SetWindowPixelFormat(
+ HDC aHdc
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  // The ungessable...
+
+  PIXELFORMATDESCRIPTOR pfd;
+  pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
+  pfd.nVersion = 1;
+  pfd.dwFlags = 
+    PFD_DRAW_TO_WINDOW | 
+    PFD_SUPPORT_OPENGL | 
+    PFD_DOUBLEBUFFER | 
+    PFD_STEREO_DONTCARE;  
+  pfd.iPixelType = PFD_TYPE_RGBA;
+  pfd.cColorBits = 32;
+  pfd.cRedBits = 8;
+  pfd.cRedShift = 16;
+  pfd.cGreenBits = 8;
+  pfd.cGreenShift = 8;
+  pfd.cBlueBits	= 8;
+  pfd.cBlueShift = 0;
+  pfd.cAlphaBits = 0;
+  pfd.cAlphaShift = 0;
+  pfd.cAccumBits = 64;	
+  pfd.cAccumRedBits = 16;
+  pfd.cAccumGreenBits = 16;
+  pfd.cAccumBlueBits = 16;
+  pfd.cAccumAlphaBits = 0;
+  pfd.cDepthBits = 32;
+  pfd.cStencilBits = 8;
+  pfd.cAuxBuffers = 0;
+  pfd.iLayerType = PFD_MAIN_PLANE;
+  pfd.bReserved	= 0;
+  pfd.dwLayerMask = 0;
+  pfd.dwVisibleMask = 0;
+  pfd.dwDamageMask = 0;
+  
+  int pixelIndex = ::ChoosePixelFormat(aHdc,&pfd);
+  if (pixelIndex==0) {
+    pixelIndex = 1;	
+    if (::DescribePixelFormat(aHdc, 
+			      pixelIndex, 
+			      sizeof(PIXELFORMATDESCRIPTOR), 
+			      &pfd)==0) {
+      return false;
+    }
+  }
+  if (::SetPixelFormat(aHdc,pixelIndex,&pfd)==FALSE) return false;
+  return true;
+}
+
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXViewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXViewer.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXViewer.cc	(revision 529)
@@ -0,0 +1,1091 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXViewer.cc,v 1.34 2006/11/01 11:22:26 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Andrew Walkden  7th February 1997
+// G4OpenGLXViewer : Class to provide XWindows specific
+//                 functionality for OpenGL in GEANT4
+
+#ifdef G4VIS_BUILD_OPENGLX_DRIVER
+
+#include "G4OpenGLXViewer.hh"
+
+#include "G4OpenGLFontBaseStore.hh"
+
+#include <sstream>
+
+#include "G4VisExtent.hh"
+#include "G4LogicalVolume.hh"
+#include "G4VSolid.hh"
+#include "G4Point3D.hh"
+#include "G4Normal3D.hh"
+
+#include <X11/Xatom.h>
+#include <X11/Xutil.h>
+
+#include <assert.h>
+
+int G4OpenGLXViewer::snglBuf_RGBA[12] =
+{ GLX_RGBA,
+  GLX_RED_SIZE, 1,
+  GLX_GREEN_SIZE, 1, 
+  GLX_BLUE_SIZE, 1,
+  GLX_DEPTH_SIZE, 1,
+  GLX_STENCIL_SIZE, 1,
+  None };
+
+int G4OpenGLXViewer::dblBuf_RGBA[13] =
+{ GLX_RGBA,
+  GLX_RED_SIZE, 1,
+  GLX_GREEN_SIZE, 1,
+  GLX_BLUE_SIZE, 1,
+  GLX_DOUBLEBUFFER,
+  GLX_DEPTH_SIZE, 1,
+  GLX_STENCIL_SIZE, 1,
+  None };
+
+#define NewString(str) \
+ ((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : (char*)NULL)
+
+#define USE_DEFAULT_COLORMAP 1
+#define USE_STANDARD_COLORMAP 0
+
+static const char* gouraudtriangleEPS[] =
+{
+  "/bd{bind def}bind def /triangle { aload pop   setrgbcolor  aload pop 5 3",
+  "roll 4 2 roll 3 2 roll exch moveto lineto lineto closepath fill } bd",
+  "/computediff1 { 2 copy sub abs threshold ge {pop pop pop true} { exch 2",
+  "index sub abs threshold ge { pop pop true} { sub abs threshold ge } ifelse",
+  "} ifelse } bd /computediff3 { 3 copy 0 get 3 1 roll 0 get 3 1 roll 0 get",
+  "computediff1 {true} { 3 copy 1 get 3 1 roll 1 get 3 1 roll 1 get",
+  "computediff1 {true} { 3 copy 2 get 3 1 roll  2 get 3 1 roll 2 get",
+  "computediff1 } ifelse } ifelse } bd /middlecolor { aload pop 4 -1 roll",
+  "aload pop 4 -1 roll add 2 div 5 1 roll 3 -1 roll add 2 div 3 1 roll add 2",
+  "div 3 1 roll exch 3 array astore } bd /gouraudtriangle { computediff3 { 4",
+  "-1 roll aload 7 1 roll 6 -1 roll pop 3 -1 roll pop add 2 div 3 1 roll add",
+  "2 div exch 3 -1 roll aload 7 1 roll exch pop 4 -1 roll pop add 2 div 3 1",
+  "roll add 2 div exch 3 -1 roll aload 7 1 roll pop 3 -1 roll pop add 2 div 3",
+  "1 roll add 2 div exch 7 3 roll 10 -3 roll dup 3 index middlecolor 4 1 roll",
+  "2 copy middlecolor 4 1 roll 3 copy pop middlecolor 4 1 roll 13 -1 roll",
+  "aload pop 17 index 6 index 15 index 19 index 6 index 17 index 6 array",
+  "astore 10 index 10 index 14 index gouraudtriangle 17 index 5 index 17",
+  "index 19 index 5 index 19 index 6 array astore 10 index 9 index 13 index",
+  "gouraudtriangle 13 index 16 index 5 index 15 index 18 index 5 index 6",
+  "array astore 12 index 12 index 9 index gouraudtriangle 17 index 16 index",
+  "15 index 19 index 18 index 17 index 6 array astore 10 index 12 index 14",
+  "index gouraudtriangle 18 {pop} repeat } { aload pop 5 3 roll aload pop 7 3",
+  "roll aload pop 9 3 roll 4 index 6 index 4 index add add 3 div 10 1 roll 7",
+  "index 5 index 3 index add add 3 div 10 1 roll 6 index 4 index 2 index add",
+  "add 3 div 10 1 roll 9 {pop} repeat 3 array astore triangle } ifelse } bd",
+  NULL
+};
+
+XVisualInfo*  G4OpenGLXViewer::vi_single_buffer = 0;
+XVisualInfo*  G4OpenGLXViewer::vi_double_buffer = 0;
+
+extern "C" {
+  Bool G4OpenGLXViewerWaitForNotify (Display*, XEvent* e, char* arg) {
+    return (e->type == MapNotify) && (e->xmap.window == (Window) arg);
+  }
+}
+
+void G4OpenGLXViewer::SetView () {
+  glXMakeCurrent (dpy, win, cx);
+  G4OpenGLViewer::SetView ();  
+}
+
+void G4OpenGLXViewer::ShowView () {
+  glXWaitGL (); //Wait for effects of all previous OpenGL commands to
+                //be propagated before progressing.
+  glFlush ();
+}
+
+void G4OpenGLXViewer::GetXConnection () {
+// get a connection.
+  dpy = XOpenDisplay (0);
+  if (!dpy) {
+    fViewId = -1;  // This flags an error.
+    G4cerr << "G4OpenGLViewer::G4OpenGLViewer couldn't open display." << G4endl;
+    return;
+  }
+
+// make sure OpenGL is supported and installed properly.
+  if (!glXQueryExtension (dpy, &errorBase, &eventBase)) {
+    fViewId = -1;  // This flags an error.
+    G4cerr << "G4OpenGLViewer::G4OpenGLViewer X Server has no GLX extension." 
+	 << G4endl;
+    return;
+  }
+
+}
+
+void G4OpenGLXViewer::CreateGLXContext (XVisualInfo* v) {
+
+  vi = v;
+// get window's attributes
+  if (!XGetWindowAttributes(dpy, XRootWindow (dpy, vi -> screen), &xwa)) {
+    fViewId = -1;  // This flags an error.
+    G4cerr << "G4OpenGLViewer::G4OpenGLViewer couldn't return window attributes"
+	 << G4endl;
+    return;
+  }
+  
+// create a GLX context
+  cx = glXCreateContext (dpy, vi, 0, true);
+  if (!cx) {
+    fViewId = -1;  // This flags an error.
+    G4cerr << "G4OpenGLViewer::G4OpenGLViewer couldn't create context."
+	 << G4endl;
+    return;
+  }
+
+// New stab at getting a colormap
+
+  Status status;
+  XStandardColormap *standardCmaps = XAllocStandardColormap ();
+  int i, numCmaps;
+
+  status = XmuLookupStandardColormap (dpy, 
+				      vi -> screen, 
+				      vi -> visualid, 
+				      vi -> depth, 
+				      XA_RGB_DEFAULT_MAP, 
+				      False, 
+				      True);
+  
+  if (status == 1) {
+    status = XGetRGBColormaps (dpy, 
+			       XRootWindow (dpy, vi -> screen), 
+			       &standardCmaps, 
+			       &numCmaps, 
+			       XA_RGB_DEFAULT_MAP);
+    if (status == 1)
+      for (i = 0; i < numCmaps; i++)
+	if (standardCmaps[i].visualid == vi -> visualid) {
+	  cmap = standardCmaps[i].colormap;
+	  XFree (standardCmaps);
+	}
+    G4cout << "Got standard cmap" << G4endl;
+  } else {
+    cmap = XCreateColormap (dpy, 
+			    XRootWindow(dpy, vi -> screen), 
+			    vi -> visual, 
+			    AllocNone);
+    G4cout << "Created own cmap" << G4endl;
+  }
+
+  if (!cmap) {
+    fViewId = -1;  // This flags an error.
+    G4cerr << "G4OpenGLViewer::G4OpenGLViewer failed to allocate a Colormap."
+	 << G4endl;
+    return;
+  }
+
+}
+  
+void G4OpenGLXViewer::CreateMainWindow () {
+  
+// create a window
+  swa.colormap = cmap;
+  swa.border_pixel = 0;
+  swa.event_mask = ExposureMask | ButtonPressMask | StructureNotifyMask;
+  swa.backing_store = WhenMapped;
+
+  // Window size and position...
+  unsigned int width, height;
+  x_origin = 0;
+  y_origin = 0;
+  size_hints = XAllocSizeHints();
+  const G4String& XGeometryString = fVP.GetXGeometryString();
+  int screen_num = DefaultScreen(dpy);
+  if (!XGeometryString.empty()) {
+    G4int geometryResultMask = XParseGeometry
+      ((char*)XGeometryString.c_str(),
+       &x_origin, &y_origin, &width, &height);
+    if (geometryResultMask & (WidthValue | HeightValue)) {
+      if (geometryResultMask & XValue) {
+	if (geometryResultMask & XNegative) {
+	  x_origin = DisplayWidth(dpy, screen_num) + x_origin - width;
+	}
+	size_hints->flags |= PPosition;
+	size_hints->x = x_origin;
+      }
+      if (geometryResultMask & YValue) {
+	if (geometryResultMask & YNegative) {
+	  y_origin = DisplayHeight(dpy, screen_num) + y_origin - height;
+	}
+	size_hints->flags |= PPosition;
+	size_hints->y = y_origin;
+      }
+    } else {
+      G4cout << "ERROR: Geometry string \""
+	     << XGeometryString
+	     << "\" invalid.  Using \"600x600\"."
+	     << G4endl;
+      width = 600;
+      height = 600;
+    }
+  }
+  size_hints->width = width;
+  size_hints->height = height;
+  size_hints->flags |= PSize;
+
+  //  G4int                             WinSize_x;
+  //  G4int                             WinSize_y;
+  WinSize_x = width;
+  WinSize_y = height;
+
+  G4cout << "Window name: " << fName << G4endl;
+  strncpy (charViewName, fName, 100);
+  char *window_name = charViewName;
+  char *icon_name = charViewName;
+  //char tmpatom[] = "XA_WM_NORMAL_HINTS"; 
+  wm_hints = XAllocWMHints();
+  class_hints = XAllocClassHint();
+
+  XStringListToTextProperty (&window_name, 1, &windowName);
+  XStringListToTextProperty (&icon_name, 1, &iconName);
+
+  wm_hints -> initial_state = NormalState;
+  wm_hints -> input = True;
+  wm_hints -> icon_pixmap = icon_pixmap;
+  wm_hints -> flags = StateHint | IconPixmapHint | InputHint;
+
+  class_hints -> res_name  = NewString("G4OpenGL");
+  class_hints -> res_class = NewString("G4OpenGL");
+
+  win = XCreateWindow (dpy, XRootWindow (dpy, vi -> screen), x_origin, 
+                       y_origin, WinSize_x, WinSize_y, 0, vi -> depth,
+                       InputOutput, vi -> visual,  
+                       CWBorderPixel | CWColormap | 
+                       CWEventMask | CWBackingStore,
+                       &swa);
+  
+  XSetWMProperties (dpy, win, &windowName, &iconName, 0, 0, 
+                    size_hints, wm_hints, class_hints);
+  
+// request X to Draw window on screen.
+  XMapWindow (dpy, win);
+
+// Wait for window to appear (wait for an "expose" event).
+  XIfEvent (dpy, &event, G4OpenGLXViewerWaitForNotify, (char*) win);
+
+// connect the context to a window
+  glXMakeCurrent (dpy, win, cx);
+
+}
+
+void G4OpenGLXViewer::CreateFontLists () {
+
+  std::map<G4double,G4String> fonts;  // G4VMarker screen size and font name.
+  fonts[10.] = "-adobe-courier-bold-r-normal--10-100-75-75-m-60-iso8859-1";
+  fonts[11.] = "-adobe-courier-bold-r-normal--11-80-100-100-m-60-iso8859-1";
+  fonts[12.] = "-adobe-courier-bold-r-normal--12-120-75-75-m-70-iso8859-1";
+  fonts[13.] = "fixed";
+  fonts[14.] = "-adobe-courier-bold-r-normal--14-100-100-100-m-90-iso8859-1";
+  fonts[17.] = "-adobe-courier-bold-r-normal--17-120-100-100-m-100-iso8859-1";
+  fonts[18.] = "-adobe-courier-bold-r-normal--18-180-75-75-m-110-iso8859-1";
+  fonts[20.] = "-adobe-courier-bold-r-normal--20-140-100-100-m-110-iso8859-1";
+  fonts[24.] = "-adobe-courier-bold-r-normal--24-240-75-75-m-150-iso8859-1";
+  fonts[25.] = "-adobe-courier-bold-r-normal--25-180-100-100-m-150-iso8859-1";
+  fonts[34.] = "-adobe-courier-bold-r-normal--34-240-100-100-m-200-iso8859-1";
+  std::map<G4double,G4String>::const_iterator i;
+  for (i = fonts.begin(); i != fonts.end(); ++i) {
+    XFontStruct* font_info = XLoadQueryFont(dpy, i->second);
+    if (!font_info) {
+      G4cerr <<
+	"G4OpenGLXViewer: XLoadQueryFont failed for font\n  "
+	     << i->second
+	     << G4endl;
+      continue;
+    }
+    G4int font_base = glGenLists(256);
+    if (!font_base) {
+      G4cerr << "G4OpenGLXViewer: out of display lists for fonts." 
+	     << G4endl;
+      continue;
+    }
+    G4int first = font_info->min_char_or_byte2;
+    G4int last  = font_info->max_char_or_byte2;
+    glXUseXFont(font_info->fid, first, last-first+1,font_base+first);
+    G4OpenGLFontBaseStore::AddFontBase(this,font_base,i->first,i->second);
+  }
+}
+
+G4OpenGLXViewer::G4OpenGLXViewer (G4OpenGLSceneHandler& scene):
+G4VViewer (scene, -1),
+G4OpenGLViewer (scene),
+print_colour (true),
+vectored_ps (true),
+vi_immediate (0),
+vi_stored (0)
+{
+
+  strcpy (print_string, "G4OpenGL.eps");
+
+  GetXConnection ();
+  if (fViewId < 0) return;
+  
+  // Try for a visual suitable for OpenGLImmediate..
+  // first try for a single buffered RGB window
+  if (!vi_single_buffer) {
+    vi_single_buffer =
+      glXChooseVisual (dpy, XDefaultScreen (dpy), snglBuf_RGBA);
+  }
+  if (!vi_double_buffer) {
+    vi_double_buffer =
+      glXChooseVisual (dpy, XDefaultScreen (dpy), dblBuf_RGBA);
+  }
+
+  if (vi_single_buffer || vi_double_buffer) {
+    if (!vi_double_buffer) {
+      G4cout <<
+	"G4OpenGLXViewer::G4OpenGLXViewer: unable to get a double buffer visual."
+	"\n  Working with a single buffer."
+	     << G4endl;
+    }
+  } else {
+    if (!vi_single_buffer) {
+      G4cout <<
+	"G4OpenGLXViewer::G4OpenGLXViewer: unable to get a single buffer visual."
+	     << G4endl;
+    }
+    if (!vi_double_buffer) {
+      G4cout <<
+	"G4OpenGLXViewer::G4OpenGLXViewer: unable to get a double buffer visual."
+	     << G4endl;
+    }
+  }
+
+  if (vi_single_buffer) {
+    vi_immediate = vi_single_buffer;
+    attributeList = snglBuf_RGBA;
+  }
+  
+  if (!vi_immediate){
+    // next try for a double buffered RGB, but Draw to top buffer
+    if (vi_double_buffer) {
+      vi_immediate = vi_double_buffer;
+      attributeList = dblBuf_RGBA;
+    }
+  }
+
+  // Now try for a visual suitable for OpenGLStored...
+  // Try for a double buffered RGB window
+  if (vi_double_buffer) {
+    vi_stored = vi_double_buffer;
+    attributeList = dblBuf_RGBA;
+  }
+
+  if (!vi_immediate || !vi_stored) {
+    G4cout <<
+    "G4OpenGLXViewer::G4OpenGLXViewer: unable to get required visuals."
+	   << G4endl;
+    fViewId = -1;  // This flags an error.
+  }
+
+  //  glClearColor (0., 0., 0., 0.);
+  //  glClearDepth (1.);
+}
+
+G4OpenGLXViewer::~G4OpenGLXViewer () {
+  if (fViewId >= 0) {
+    //Close a window from here
+    glXMakeCurrent (dpy, None, NULL);
+    glXDestroyContext (dpy, cx);
+    if (win) XDestroyWindow (dpy, win); // ...if already deleted in
+    // sub-class G4OpenGLXmViewer.
+    XFlush (dpy);
+  }
+}
+
+void G4OpenGLXViewer::print() {
+  
+  //using namespace std;
+  //cout << "print_col_callback requested with file name: " << print_string << G4endl;
+  
+  if (vectored_ps) {
+    G4int size = 5000000;
+    
+    GLfloat* feedback_buffer;
+    GLint returned;
+    FILE* file;
+    
+    feedback_buffer = new GLfloat[size];
+    glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer);
+    glRenderMode (GL_FEEDBACK);
+    
+    DrawView();
+    returned = glRenderMode (GL_RENDER);
+    
+    if (print_string) {
+      file = fopen (print_string, "w");
+      if (file) {
+	spewWireframeEPS (file, returned, feedback_buffer, "rendereps");
+      } else {
+	printf("Could not open %s\n", print_string);
+      }
+    } else {
+      printBuffer (returned, feedback_buffer);
+    }
+    //  free (feedback_buffer);
+    delete[] feedback_buffer;
+
+  } else {
+
+    XVisualInfo* pvi;
+    GLXContext pcx = create_GL_print_context(pvi);
+    GLXContext tmp_cx;
+    tmp_cx = cx;
+    cx=pcx;
+    
+    Pixmap pmap = XCreatePixmap (dpy,
+				 XRootWindow (dpy, pvi->screen),
+				 WinSize_x, WinSize_y,
+				 pvi->depth);
+    
+    GLXPixmap glxpmap = glXCreateGLXPixmap (dpy, 
+					    pvi,
+					    pmap);
+    
+    GLXDrawable tmp_win;
+    tmp_win=win;
+    win=glxpmap;
+    
+    glXMakeCurrent (dpy,
+		    glxpmap,
+		    cx);
+    
+    glViewport (0, 0, WinSize_x, WinSize_y);
+    
+    ClearView ();
+    DrawView ();
+    
+    generateEPS (print_string,
+		 print_colour,
+		 WinSize_x, WinSize_y);
+    
+    win=tmp_win;
+    cx=tmp_cx;
+    
+    glXMakeCurrent (dpy,
+		    glxpmap,
+		    cx);
+    
+  }
+
+}
+
+void G4OpenGLXViewer::print3DcolorVertex(GLint size, GLint * count, GLfloat * buffer)
+{
+  G4int i;
+
+  printf("  ");
+  for (i = 0; i < 7; i++) {
+    printf("%4.2f ", buffer[size - (*count)]);
+    *count = *count - 1;
+  }
+  printf("\n");
+}
+
+void G4OpenGLXViewer::spewWireframeEPS (FILE* file, GLint size, GLfloat* buffer, const char* cr) {
+
+  GLfloat EPS_GOURAUD_THRESHOLD=0.1;
+
+  GLfloat clearColor[4], viewport[4];
+  GLfloat lineWidth;
+  G4int i;
+
+  glGetFloatv (GL_VIEWPORT, viewport);
+  glGetFloatv (GL_COLOR_CLEAR_VALUE, clearColor);
+  glGetFloatv (GL_LINE_WIDTH, &lineWidth);
+  glGetFloatv (GL_POINT_SIZE, &pointSize);
+
+  fputs ("%!PS-Adobe-2.0 EPSF-2.0\n", file);
+  fprintf (file, "%%%%Creator: %s (using OpenGL feedback)\n", cr);
+  fprintf (file, "%%%%BoundingBox: %g %g %g %g\n", viewport[0], viewport[1], viewport[2], viewport[3]);
+  fputs ("%%EndComments\n", file);
+  fputs ("\n", file);
+  fputs ("gsave\n", file);
+  fputs ("\n", file);
+
+  fputs ("% the gouraudtriangle PostScript fragment below is free\n", file);
+  fputs ("% written by Frederic Delhoume (delhoume@ilog.fr)\n", file);
+  fprintf (file, "/threshold %g def\n", EPS_GOURAUD_THRESHOLD);
+  for (i=0; gouraudtriangleEPS[i]; i++) {
+    fprintf (file, "%s\n", gouraudtriangleEPS[i]);
+  }
+
+  fprintf(file, "\n%g setlinewidth\n", lineWidth);
+  
+  fprintf (file, "%g %g %g setrgbcolor\n", clearColor[0], clearColor[1], clearColor[2]);
+  fprintf (file, "%g %g %g %g rectfill\n\n", viewport[0], viewport[1], viewport[2], viewport[3]);
+
+  spewSortedFeedback (file, size, buffer);
+
+  fputs ("grestore\n\n", file);
+  fputs ("showpage\n", file);
+
+  fclose(file);
+}
+
+void G4OpenGLXViewer::printBuffer (GLint size, GLfloat* buffer) {
+
+  GLint count;
+  G4int token, nvertices;
+
+  count=size;
+  while(count) {
+    token=G4int (buffer[size-count]);
+    count--;
+    switch (token) {
+
+    case GL_PASS_THROUGH_TOKEN:
+      printf ("GL_PASS_THROUGH_TOKEN\n");
+      printf ("  %4.2f\n", buffer[size-count]);
+      count--;
+      break;
+
+    case GL_POINT_TOKEN:
+      printf ("GL_POINT_TOKEN\n");
+      print3DcolorVertex (size, &count, buffer);
+      break;
+
+    case GL_LINE_TOKEN:
+      printf ("GL_LINE_TOKEN\n");
+      print3DcolorVertex (size, &count, buffer);
+      print3DcolorVertex (size, &count, buffer);
+      break;
+      
+    case GL_LINE_RESET_TOKEN:
+      printf ("GL_LINE_RESET_TOKEN\n");
+      print3DcolorVertex (size, &count, buffer);
+      print3DcolorVertex (size, &count, buffer);
+      break;
+
+    case GL_POLYGON_TOKEN:
+      printf ("GL_POLYGON_TOKEN\n");
+      nvertices=G4int (buffer[size-count]);
+      count--;
+      for (; nvertices>0; nvertices--) {
+	print3DcolorVertex (size, &count, buffer);
+      }
+    }
+  }
+}
+
+G4float* G4OpenGLXViewer::spewPrimitiveEPS (FILE* file, GLfloat* loc) {
+  
+  G4int token;
+  G4int nvertices, i;
+  GLfloat red, green, blue, intensity;
+  G4int smooth;
+  GLfloat dx, dy, dr, dg, db, absR, absG, absB, colormax;
+  G4int steps;
+  Feedback3Dcolor *vertex;
+  GLfloat xstep(0.), ystep(0.), rstep(0.), gstep(0.), bstep(0.);
+  GLfloat xnext(0.), ynext(0.), rnext(0.), gnext(0.), bnext(0.), distance(0.);
+
+  token=G4int (*loc);
+  loc++;
+  switch (token) {
+  case GL_LINE_RESET_TOKEN:
+  case GL_LINE_TOKEN:
+    vertex=(Feedback3Dcolor*)loc;
+    dr=vertex[1].red - vertex[0].red;
+    dg=vertex[1].green - vertex[0].green;
+    db=vertex[1].blue - vertex[0].blue;
+
+    if (!print_colour) {
+      dr+=(dg+db);
+      dr/=3.0;
+      dg=dr;
+      db=dr;
+    }
+
+    if (dr!=0 || dg!=0 || db!=0) {
+      dx=vertex[1].x - vertex[0].x;
+      dy=vertex[1].y - vertex[0].y;
+      distance=std::sqrt(dx*dx + dy*dy);
+
+      absR=std::fabs(dr);
+      absG=std::fabs(dg);
+      absB=std::fabs(db);
+
+      #define Max(a, b) (((a)>(b))?(a):(b))
+
+      #define EPS_SMOOTH_LINE_FACTOR 0.06
+
+      colormax=Max(absR, Max(absG, absB));
+      steps=Max(1, G4int (colormax*distance*EPS_SMOOTH_LINE_FACTOR));
+      
+      xstep=dx/steps;
+      ystep=dy/steps;
+
+      rstep=dr/steps;
+      gstep=dg/steps;
+      bstep=db/steps;
+
+      xnext=vertex[0].x;
+      ynext=vertex[0].y;
+      rnext=vertex[0].red;
+      gnext=vertex[0].green;
+      bnext=vertex[0].blue;
+
+      if (!print_colour) {
+	rnext+=(gnext+bnext);
+	rnext/=3.0;
+	gnext=rnext;
+	bnext=rnext;
+      }
+
+      xnext -= xstep/2.0;
+      ynext -= ystep/2.0;
+      rnext -= rstep/2.0;
+      gnext -= gstep/2.0;
+      bnext -= bstep/2.0;
+    } else {
+      steps=0;
+    }
+    if (print_colour) {
+      fprintf (file, "%g %g %g setrgbcolor\n",
+	       vertex[0].red, vertex[0].green, vertex[0].blue);
+    } else {
+      intensity = (vertex[0].red + vertex[0].green + vertex[0].blue) / 3.0;
+      fprintf (file, "%g %g %g setrgbcolor\n",
+	       intensity, intensity, intensity);
+    }      
+    fprintf (file, "%g %g moveto\n", vertex[0].x, vertex[0].y);
+
+    for (i=0; i<steps; i++) {
+
+      xnext += xstep;
+      ynext += ystep;
+      rnext += rstep;
+      gnext += gstep;
+      bnext += bstep;
+
+      fprintf (file, "%g %g lineto stroke\n", xnext, ynext);
+      fprintf (file, "%g %g %g setrgbcolor\n", rnext, gnext, bnext);
+      fprintf (file, "%g %g moveto\n", xnext, ynext);
+    }
+    fprintf (file, "%g %g lineto stroke\n", vertex[1].x, vertex[1].y);
+
+    loc += 14;
+    break;
+
+  case GL_POLYGON_TOKEN:
+    nvertices = G4int (*loc);
+    loc++;
+    vertex=(Feedback3Dcolor*)loc;
+    if (nvertices>0) {
+      red=vertex[0].red;
+      green=vertex[0].green;
+      blue=vertex[0].blue;
+      smooth=0;
+      
+      if (!print_colour) {
+	red+=(green+blue);
+	red/=3.0;
+	green=red;
+	blue=red;
+      }
+      
+      if (print_colour) {
+	for (i=1; i<nvertices; i++) {
+	  if (red!=vertex[i].red || green!=vertex[i].green || blue!=vertex[i].blue) {
+	    smooth=1;
+	    break;
+	  }
+	}
+      } else {
+	for (i=1; i<nvertices; i++) {
+	  intensity = vertex[i].red + vertex[i].green + vertex[i].blue;
+	  intensity/=3.0;
+	  if (red!=intensity) {
+	    smooth=1;
+	    break;
+	  }
+	}
+      }
+
+      if (smooth) {
+	G4int triOffset;
+	for (i=0; i<nvertices-2; i++) {
+	  triOffset = i*7;
+	  fprintf (file, "[%g %g %g %g %g %g]",
+		   vertex[0].x, vertex[i+1].x, vertex[i+2].x,
+		   vertex[0].y, vertex[i+1].y, vertex[i+2].y);
+	  if (print_colour) {
+	    fprintf (file, " [%g %g %g] [%g %g %g] [%g %g %g] gouraudtriangle\n",
+		     vertex[0].red, vertex[0].green, vertex[0].blue,
+		     vertex[i+1].red, vertex[i+1].green, vertex[i+1].blue,
+		     vertex[i+2].red, vertex[i+2].green, vertex[i+2].blue);
+	  } else {
+
+	    intensity = vertex[0].red + vertex[0].green + vertex[0].blue;
+	    intensity/=3.0;
+	    fprintf (file, " [%g %g %g]", intensity, intensity, intensity);
+
+	    intensity = vertex[1].red + vertex[1].green + vertex[1].blue;
+	    intensity/=3.0;
+	    fprintf (file, " [%g %g %g]", intensity, intensity, intensity);
+
+	    intensity = vertex[2].red + vertex[2].green + vertex[2].blue;
+	    intensity/=3.0;
+	    fprintf (file, " [%g %g %g] gouraudtriangle\n", intensity, intensity, intensity);
+	  }
+	}
+      } else {
+	fprintf (file, "newpath\n");
+	fprintf (file, "%g %g %g setrgbcolor\n", red, green, blue);
+	fprintf (file, "%g %g moveto\n", vertex[0].x, vertex[0].y);
+	for (i=1; i<nvertices; i++) {
+	  fprintf (file, "%g %g lineto\n", vertex[i].x, vertex[i].y);
+	}
+	fprintf (file, "closepath fill\n\n");
+      }
+    }
+    loc += nvertices*7;
+    break;
+
+  case GL_POINT_TOKEN:
+    vertex=(Feedback3Dcolor*)loc;
+    if (print_colour) {
+      fprintf (file, "%g %g %g setrgbcolor\n", vertex[0].red, vertex[0].green, vertex[0].blue);
+    } else {
+      intensity = vertex[0].red + vertex[0].green + vertex[0].blue;
+      intensity/=3.0;
+      fprintf (file, "%g %g %g setrgbcolor\n", intensity, intensity, intensity);
+    }      
+    fprintf(file, "%g %g %g 0 360 arc fill\n\n", vertex[0].x, vertex[0].y, pointSize / 2.0);
+    loc += 7;           /* Each vertex element in the feedback
+                           buffer is 7 GLfloats. */
+    break;
+  default:
+    /* XXX Left as an excersie to the reader. */
+    static G4bool spewPrimitiveEPSWarned = false;
+    if (!spewPrimitiveEPSWarned) {
+      std::ostringstream oss;
+      oss <<
+	"Incomplete implementation.  Unexpected token (" << token << ")."
+	"\n  (Seems to be caused by text.)";
+      G4Exception("G4OpenGLXViewer::spewPrimitiveEPS",
+		  "Unexpected token",
+		  JustWarning,
+		  oss.str().c_str());
+      spewPrimitiveEPSWarned = true;
+    }
+  }
+  return loc;
+}
+
+typedef struct G4OpenGLXViewerDepthIndex {
+  GLfloat *ptr;
+  GLfloat depth;
+} DepthIndex;
+
+extern "C" {
+  int G4OpenGLXViewercompare(const void *a, const void *b)
+  {
+    const DepthIndex *p1 = (DepthIndex *) a;
+    const DepthIndex *p2 = (DepthIndex *) b;
+    GLfloat diff = p2->depth - p1->depth;
+    
+    if (diff > 0.0) {
+      return 1;
+    } else if (diff < 0.0) {
+      return -1;
+    } else {
+      return 0;
+    }
+  }
+}
+
+void G4OpenGLXViewer::spewSortedFeedback(FILE * file, GLint size, GLfloat * buffer)
+{
+  int token;
+  GLfloat *loc, *end;
+  Feedback3Dcolor *vertex;
+  GLfloat depthSum;
+  int nprimitives, item;
+  DepthIndex *prims;
+  int nvertices, i;
+
+  end = buffer + size;
+
+  /* Count how many primitives there are. */
+  nprimitives = 0;
+  loc = buffer;
+  while (loc < end) {
+    token = int (*loc);
+    loc++;
+    switch (token) {
+    case GL_LINE_TOKEN:
+    case GL_LINE_RESET_TOKEN:
+      loc += 14;
+      nprimitives++;
+      break;
+    case GL_POLYGON_TOKEN:
+      nvertices = int (*loc);
+      loc++;
+      loc += (7 * nvertices);
+      nprimitives++;
+      break;
+    case GL_POINT_TOKEN:
+      loc += 7;
+      nprimitives++;
+      break;
+    default:
+      /* XXX Left as an excersie to the reader. */
+      static G4bool spewSortedFeedbackWarned = false;
+      if (!spewSortedFeedbackWarned) {
+	std::ostringstream oss;
+	oss <<
+	  "Incomplete implementation.  Unexpected token (" << token << ")."
+	  "\n  (Seems to be caused by text.)";
+	G4Exception("G4OpenGLXViewer::spewSortedFeedback",
+		    "Unexpected token",
+		    JustWarning,
+		    oss.str().c_str());
+	spewSortedFeedbackWarned = true;
+      }
+      nprimitives++;
+    }
+  }
+
+  /* Allocate an array of pointers that will point back at
+     primitives in the feedback buffer.  There will be one
+     entry per primitive.  This array is also where we keep the
+     primitive's average depth.  There is one entry per
+     primitive  in the feedback buffer. */
+  prims = (DepthIndex *) malloc(sizeof(DepthIndex) * nprimitives);
+
+  item = 0;
+  loc = buffer;
+  while (loc < end) {
+    prims[item].ptr = loc;  /* Save this primitive's location. */
+    token = int (*loc);
+    loc++;
+    switch (token) {
+    case GL_LINE_TOKEN:
+    case GL_LINE_RESET_TOKEN:
+      vertex = (Feedback3Dcolor *) loc;
+      depthSum = vertex[0].z + vertex[1].z;
+      prims[item].depth = depthSum / 2.0;
+      loc += 14;
+      break;
+    case GL_POLYGON_TOKEN:
+      nvertices = int (*loc);
+      loc++;
+      vertex = (Feedback3Dcolor *) loc;
+      depthSum = vertex[0].z;
+      for (i = 1; i < nvertices; i++) {
+        depthSum += vertex[i].z;
+      }
+      prims[item].depth = depthSum / nvertices;
+      loc += (7 * nvertices);
+      break;
+    case GL_POINT_TOKEN:
+      vertex = (Feedback3Dcolor *) loc;
+      prims[item].depth = vertex[0].z;
+      loc += 7;
+      break;
+    default:
+      /* XXX Left as an excersie to the reader. */
+      assert(1);
+    }
+    item++;
+  }
+  assert(item == nprimitives);
+
+  /* Sort the primitives back to front. */
+  qsort(prims, nprimitives, sizeof(DepthIndex), G4OpenGLXViewercompare);
+
+  /* Understand that sorting by a primitives average depth
+     doesn't allow us to disambiguate some cases like self
+     intersecting polygons.  Handling these cases would require
+     breaking up the primitives.  That's too involved for this
+     example.  Sorting by depth is good enough for lots of
+     applications. */
+
+  /* Emit the Encapsulated PostScript for the primitives in
+     back to front order. */
+  for (item = 0; item < nprimitives; item++) {
+    (void) spewPrimitiveEPS(file, prims[item].ptr);
+  }
+
+  free(prims);
+}
+
+GLXContext G4OpenGLXViewer::create_GL_print_context(XVisualInfo*& pvi) {
+  
+  pvi = glXChooseVisual (dpy,
+			 XDefaultScreen (dpy),
+			 snglBuf_RGBA);
+
+  if (!pvi) {
+    pvi = glXChooseVisual (dpy,
+			   XDefaultScreen (dpy),
+			   dblBuf_RGBA);
+  }
+
+  return glXCreateContext (dpy,
+			   pvi,
+			   NULL,
+			   False);
+}
+
+int G4OpenGLXViewer::generateEPS (char* filnam,
+				int inColour,
+				unsigned int width,
+				unsigned int height) {
+
+  FILE* fp;
+  GLubyte* pixels;
+  GLubyte* curpix;
+  int components, pos, i;
+
+  pixels = grabPixels (inColour, width, height);
+
+  if (pixels == NULL)
+    return 1;
+  if (inColour) {
+    components = 3;
+  } else {
+    components = 1;
+  }
+  
+  fp = fopen (filnam, "w");
+  if (fp == NULL) {
+    return 2;
+  }
+  
+  fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n");
+  fprintf (fp, "%%%%Title: %s\n", filnam);
+  fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n");
+  fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", width, height);
+  fprintf (fp, "%%%%EndComments\n");
+  fprintf (fp, "gsave\n");
+  fprintf (fp, "/bwproc {\n");
+  fprintf (fp, "    rgbproc\n");
+  fprintf (fp, "    dup length 3 idiv string 0 3 0 \n");
+  fprintf (fp, "    5 -1 roll {\n");
+  fprintf (fp, "    add 2 1 roll 1 sub dup 0 eq\n");
+  fprintf (fp, "    { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n");
+  fprintf (fp, "       3 1 roll 5 -1 roll } put 1 add 3 0 \n");
+  fprintf (fp, "    { 2 1 roll } ifelse\n");
+  fprintf (fp, "    }forall\n");
+  fprintf (fp, "    pop pop pop\n");
+  fprintf (fp, "} def\n");
+  fprintf (fp, "systemdict /colorimage known not {\n");
+  fprintf (fp, "   /colorimage {\n");
+  fprintf (fp, "       pop\n");
+  fprintf (fp, "       pop\n");
+  fprintf (fp, "       /rgbproc exch def\n");
+  fprintf (fp, "       { bwproc } image\n");
+  fprintf (fp, "   }  def\n");
+  fprintf (fp, "} if\n");
+  fprintf (fp, "/picstr %d string def\n", width * components);
+  fprintf (fp, "%d %d scale\n", width, height);
+  fprintf (fp, "%d %d %d\n", width, height, 8);
+  fprintf (fp, "[%d 0 0 %d 0 0]\n", width, height);
+  fprintf (fp, "{currentfile picstr readhexstring pop}\n");
+  fprintf (fp, "false %d\n", components);
+  fprintf (fp, "colorimage\n");
+  
+  curpix = (GLubyte*) pixels;
+  pos = 0;
+  for (i = width*height*components; i>0; i--) {
+    fprintf (fp, "%02hx ", *(curpix++));
+    if (++pos >= 32) {
+      fprintf (fp, "\n");
+      pos = 0; 
+    }
+  }
+  if (pos)
+    fprintf (fp, "\n");
+
+  fprintf (fp, "grestore\n");
+  fprintf (fp, "showpage\n");
+  delete pixels;
+  fclose (fp);
+  return 0;
+}
+
+GLubyte* G4OpenGLXViewer::grabPixels (int inColor, unsigned int width, unsigned int height) {
+  
+  GLubyte* buffer;
+  GLint swapbytes, lsbfirst, rowlength;
+  GLint skiprows, skippixels, alignment;
+  GLenum format;
+  int size;
+
+  if (inColor) {
+    format = GL_RGB;
+    size = width*height*3;
+  } else {
+    format = GL_LUMINANCE;
+    size = width*height*1;
+  }
+
+  buffer = new GLubyte[size];
+  if (buffer == NULL)
+    return NULL;
+
+  glGetIntegerv (GL_UNPACK_SWAP_BYTES, &swapbytes);
+  glGetIntegerv (GL_UNPACK_LSB_FIRST, &lsbfirst);
+  glGetIntegerv (GL_UNPACK_ROW_LENGTH, &rowlength);
+
+  glGetIntegerv (GL_UNPACK_SKIP_ROWS, &skiprows);
+  glGetIntegerv (GL_UNPACK_SKIP_PIXELS, &skippixels);
+  glGetIntegerv (GL_UNPACK_ALIGNMENT, &alignment);
+
+  glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE);
+  glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE);
+  glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
+
+  glPixelStorei (GL_UNPACK_SKIP_ROWS, 0);
+  glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0);
+  glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
+
+  glReadPixels (0, 0, (GLsizei)width, (GLsizei)height, format, GL_UNSIGNED_BYTE, (GLvoid*) buffer);
+
+  glPixelStorei (GL_UNPACK_SWAP_BYTES, swapbytes);
+  glPixelStorei (GL_UNPACK_LSB_FIRST, lsbfirst);
+  glPixelStorei (GL_UNPACK_ROW_LENGTH, rowlength);
+  
+  glPixelStorei (GL_UNPACK_SKIP_ROWS, skiprows);
+  glPixelStorei (GL_UNPACK_SKIP_PIXELS, skippixels);
+  glPixelStorei (GL_UNPACK_ALIGNMENT, alignment);
+  
+  return buffer;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXViewerMessenger.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXViewerMessenger.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXViewerMessenger.cc	(revision 529)
@@ -0,0 +1,115 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXViewerMessenger.cc,v 1.5 2006/11/21 16:24:00 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+
+#ifdef G4VIS_BUILD_OPENGLX_DRIVER
+
+#include "G4OpenGLXViewerMessenger.hh"
+
+#include "G4OpenGLXViewer.hh"
+
+#include "G4UImanager.hh"
+#include "G4UIcommand.hh"
+#include "G4UIdirectory.hh"
+#include "G4UIcmdWithoutParameter.hh"
+#include "G4UIcmdWithABool.hh"
+#include "G4VisManager.hh"
+#include <sstream>
+
+G4OpenGLXViewerMessenger* G4OpenGLXViewerMessenger::fpInstance = 0;
+
+G4OpenGLXViewerMessenger* G4OpenGLXViewerMessenger::GetInstance()
+{
+  if (!fpInstance) fpInstance = new G4OpenGLXViewerMessenger;
+  return fpInstance;
+}
+
+G4OpenGLXViewerMessenger::G4OpenGLXViewerMessenger()
+{
+  fpDirectory = new G4UIdirectory("/vis/oglx/");
+  fpDirectory->SetGuidance("G4OpenGLXViewer commands.");
+
+  fpCommandPrintEPS =
+    new G4UIcmdWithoutParameter("/vis/oglx/printEPS", this);
+  fpCommandPrintEPS->SetGuidance("Print Encapsulated PostScript file.");
+  fpCommandPrintEPS->SetGuidance
+    ("Generates files with names G4OpenGL_n.eps, where n is a sequence"
+     "\nnumber, starting at 0.");
+}
+
+G4OpenGLXViewerMessenger::~G4OpenGLXViewerMessenger ()
+{
+  delete fpCommandPrintEPS;
+  delete fpDirectory;
+}
+
+void G4OpenGLXViewerMessenger::SetNewValue
+(G4UIcommand* command, G4String)
+{
+  G4VisManager* pVisManager = G4VisManager::GetInstance();
+
+  G4VViewer* pVViewer = pVisManager->GetCurrentViewer();
+
+  if (!pVViewer) {
+    G4cout <<
+      "G4OpenGLXViewerMessenger::SetNewValue: No current viewer."
+      "\n  \"/vis/open\", or similar, to get one."
+           << G4endl;
+    return;
+  }
+
+  G4OpenGLXViewer* pViewer = dynamic_cast<G4OpenGLXViewer*>(pVViewer);
+
+  if (!pViewer) {
+    G4cout <<
+      "G4OpenGLXViewerMessenger::SetNewValue: Current viewer is not of type"
+      "\n  OGL*X*.  This feature currently only available on X Windows."
+           << G4endl;
+    return;
+  }
+
+  if (command == fpCommandPrintEPS)
+    {
+      // Keep copy of print_string to preserve Xm behaviour...
+      char* tmp_string = new char[50];
+      strcpy (tmp_string, pViewer->print_string);
+      // Make new print string...
+      static G4int file_count = 0;
+      std::ostringstream oss;
+      oss << "G4OpenGL_" << file_count++ << ".eps";
+      strcpy (pViewer->print_string, oss.str().c_str());
+      // Print eps file...
+      pViewer->print();
+      // Restore print_string for Xm...
+      strcpy (pViewer->print_string, tmp_string);
+      delete tmp_string;
+    }
+
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmBox.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmBox.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmBox.cc	(revision 529)
@@ -0,0 +1,108 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmBox.cc,v 1.6 2006/06/29 21:19:40 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+//Box container class
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLXmFramedBox.hh"
+#include "G4OpenGLXmBox.hh"
+#include "G4OpenGLXmVWidgetComponent.hh"
+#include "G4OpenGLXmVWidgetShell.hh"
+
+G4OpenGLXmBox::G4OpenGLXmBox (const char* n, 
+			      G4bool r)
+{
+  name = n;
+  radio = r;
+  parent = NULL;
+  box_row_col = NULL;
+}
+
+G4OpenGLXmBox::~G4OpenGLXmBox () 
+{}
+
+void G4OpenGLXmBox::AddChild (G4OpenGLXmVWidgetComponent* component)
+{
+  component->AddYourselfTo(this);
+  Cardinal num_children;
+  XtVaGetValues (box_row_col,
+		 XmNnumChildren, &num_children,
+		 NULL);
+//  G4cout << name << " now parents " << num_children << " children." << G4endl;
+}
+
+void G4OpenGLXmBox::AddYourselfTo (G4OpenGLXmVWidgetShell* window)
+{
+
+  pView = window->GetView ();
+  ProcesspView ();
+  parent = window->GetPointerToWidget ();
+  
+  box_row_col =  XtVaCreateManagedWidget (name,
+					  xmRowColumnWidgetClass,
+					  *parent,
+					  
+					  XmNadjustMargin, True,
+					  XmNisHomogeneous, False,
+					  XmNlabelString, (XmString)name,
+					  XmNradioAlwaysOne, radio,
+					  XmNradioBehavior, radio,
+					  
+					  XtNvisual, visual,
+					  XtNdepth, depth,
+					  XtNcolormap, cmap,
+					  XtNborderColor, borcol,
+					  XtNbackground, bgnd,
+					  
+					  NULL);
+  
+}
+
+Widget* G4OpenGLXmBox::GetPointerToParent ()
+{
+  return parent;
+}
+
+Widget* G4OpenGLXmBox::GetPointerToWidget ()
+{
+  return &box_row_col;
+}
+
+const char* G4OpenGLXmBox::GetName ()
+{
+  return name;
+}
+
+void G4OpenGLXmBox::SetName (const char* n)
+{
+  name = n;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmConvenienceRoutines.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmConvenienceRoutines.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmConvenienceRoutines.cc	(revision 529)
@@ -0,0 +1,527 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmConvenienceRoutines.cc,v 1.11 2006/06/29 21:19:42 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Andrew Walkden  16th April 1997
+// G4OpenGLXmConvenienceRoutines : 
+//                       Collection of routines to facilitate
+//                       the addition of simple push button boxes,
+//                       and slider bars to the control panel.
+//
+// See G4OpenGLXmConvenienceRoutines.hh for more information.
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLXmViewer.hh"
+
+void G4OpenGLXmViewer::Add_four_arrow_buttons (G4OpenGLXmViewer* pView,
+					     XtCallbackRec** arrow_callbacks,
+					     Widget* parent_widget) {
+  
+  Widget arrow_form = XtVaCreateWidget 
+    ("arrow_form",
+     xmFormWidgetClass,
+     *parent_widget,
+     XmNfractionBase, 3,
+     XtNvisual, pView->vi->visual, 
+     XtNdepth, pView->vi->depth, 
+     XtNcolormap, pView->cmap, 
+     XtNborderColor, pView->borcol,
+     XtNbackground, pView->bgnd,
+     NULL);
+  
+  Widget arrow = XtVaCreateManagedWidget 
+    ("up_arrow",
+     xmArrowButtonGadgetClass, 
+     arrow_form,
+     XmNtopAttachment, XmATTACH_POSITION,
+     XmNtopPosition, 0,
+     XmNbottomAttachment, XmATTACH_POSITION,
+     XmNbottomPosition, 1,
+     XmNleftAttachment, XmATTACH_POSITION,
+     XmNleftPosition, 1,
+     XmNrightAttachment, XmATTACH_POSITION,
+     XmNrightPosition, 2,
+     XmNarrowDirection, XmARROW_UP,
+     NULL);
+  
+  XtVaSetValues (arrow,
+		 XmNuserData, True,
+		 NULL);
+  
+  XtAddCallbacks (arrow, 
+		 XmNactivateCallback, 
+		 arrow_callbacks[0]);
+  
+  XtAddCallbacks (arrow, 
+		 XmNarmCallback, 
+		 arrow_callbacks[0]);
+  
+  XtAddCallbacks (arrow, 
+		 XmNdisarmCallback, 
+		 arrow_callbacks[0]);
+  
+  arrow = XtVaCreateManagedWidget 
+    ("down_arrow",
+     xmArrowButtonGadgetClass, 
+     arrow_form,
+     XmNtopAttachment, XmATTACH_POSITION,
+     XmNtopPosition, 2,
+     XmNbottomAttachment, XmATTACH_POSITION,
+     XmNbottomPosition, 3,
+     XmNleftAttachment, XmATTACH_POSITION,
+     XmNleftPosition, 1,
+     XmNrightAttachment, XmATTACH_POSITION,
+     XmNrightPosition, 2,
+     XmNarrowDirection, XmARROW_DOWN,
+     NULL);
+  
+  XtVaSetValues (arrow,
+		 XmNuserData, False,
+		 NULL);
+  
+  XtAddCallbacks (arrow, 
+		 XmNactivateCallback, 
+		 arrow_callbacks[1]);
+  
+  XtAddCallbacks (arrow, 
+		 XmNarmCallback,
+		 arrow_callbacks[1]);
+  
+  XtAddCallbacks (arrow, 
+		 XmNdisarmCallback, 
+		 arrow_callbacks[1]);
+  
+  arrow = XtVaCreateManagedWidget 
+    ("left_arrow",
+     xmArrowButtonGadgetClass, 
+     arrow_form,
+     XmNtopAttachment, XmATTACH_POSITION,
+     XmNtopPosition, 1,
+     XmNbottomAttachment, XmATTACH_POSITION,
+     XmNbottomPosition, 2,
+     XmNleftAttachment, XmATTACH_POSITION,
+     XmNleftPosition, 0,
+     XmNrightAttachment, XmATTACH_POSITION,
+     XmNrightPosition, 1,
+     XmNarrowDirection, XmARROW_LEFT,
+     NULL);
+  
+  XtVaSetValues (arrow,
+		 XmNuserData, False,
+		 NULL);
+
+  XtAddCallbacks (arrow, 
+		 XmNactivateCallback, 
+		 arrow_callbacks[2]);
+
+  XtAddCallbacks (arrow, 
+		 XmNarmCallback, 
+		 arrow_callbacks[2]);
+  
+  XtAddCallbacks (arrow, 
+		 XmNdisarmCallback, 
+		 arrow_callbacks[2]);
+      
+  arrow = XtVaCreateManagedWidget 
+    ("right_arrow",
+     xmArrowButtonGadgetClass, 
+     arrow_form,
+     XmNtopAttachment, XmATTACH_POSITION,
+     XmNtopPosition, 1,
+     XmNbottomAttachment, XmATTACH_POSITION,
+     XmNbottomPosition, 2,
+     XmNleftAttachment, XmATTACH_POSITION,
+     XmNleftPosition, 2,
+     XmNrightAttachment, XmATTACH_POSITION,
+     XmNrightPosition, 3,
+     XmNarrowDirection, XmARROW_RIGHT,
+     NULL);
+  
+  XtVaSetValues (arrow,
+		 XmNuserData, True,
+		 NULL);
+  
+  XtAddCallbacks (arrow, 
+		 XmNactivateCallback, 
+		 arrow_callbacks[3]);
+  
+  XtAddCallbacks (arrow, 
+		 XmNarmCallback, 
+		 arrow_callbacks[3]);
+
+  XtAddCallbacks (arrow, 
+		 XmNdisarmCallback, 
+		 arrow_callbacks[3]);
+  
+  XtManageChild (arrow_form);
+  
+}
+
+void G4OpenGLXmViewer::Add_radio_box (char* label_string,
+				    Widget* parent_widget,
+				    XtCallbackRec* radio_box_callback,
+				    G4int num_buttons,
+				    G4int default_button,
+				    char* radio_box_name,
+				    char** button_names,
+				    G4OpenGLXmViewer* pView)
+{
+  XmString button_str = XmStringCreateLocalized((char*) ""); // ...to
+  // initialise to something to avoid pedantic warning.
+  Arg** args;
+  args = new Arg* [num_buttons];
+  Widget button;
+
+  G4int i;
+  for (i = 0; i < num_buttons; i++) {
+
+    args[i] = new Arg[7];
+    button_str = XmStringCreateLocalized (button_names[i]);
+
+    XtSetArg (args[i][0], XtNvisual, pView->vi->visual);
+    XtSetArg (args[i][1], XtNdepth, pView->vi->depth);
+    XtSetArg (args[i][2], XtNcolormap, pView->cmap);
+    XtSetArg (args[i][3], XtNborderColor, pView->borcol);
+    XtSetArg (args[i][4], XtNbackground, pView->bgnd);
+    XtSetArg (args[i][5], XmNlabelString, button_str); 
+
+    if (i == default_button) {
+      XtSetArg (args[i][6], XmNset, True);
+    } else {
+      XtSetArg (args[i][6], XmNset, False);
+    }
+  }
+  
+  Widget radio_box = XtVaCreateWidget (radio_box_name,
+				       xmRowColumnWidgetClass,
+				       *parent_widget,
+				       XmNisHomogeneous, False,
+				       XmNradioBehavior, True,
+				       XmNradioAlwaysOne, True,
+				       XmNuserData, pView,
+				       XtNvisual, pView->vi->visual,
+				       XtNdepth, pView->vi->depth,
+				       XtNcolormap, pView->cmap,
+				       XtNborderColor, pView->borcol,
+				       XtNbackground, pView->bgnd,
+				       NULL);
+
+  XmString lab = XmStringCreateLocalized (label_string);
+
+  // Unused!
+  //Widget label = XtVaCreateManagedWidget ("radio_label",
+  //				  xmLabelWidgetClass,
+  //				  radio_box,
+  //				  XmNalignment, XmALIGNMENT_CENTER,
+  //				  XmNlabelString, lab,
+  //				  XtNvisual, pView->vi->visual,
+  //				  XtNdepth, pView->vi->depth,
+  //				  XtNcolormap, pView->cmap,
+  //				  XtNborderColor, pView->borcol,
+  //				  XtNbackground, pView->bgnd,
+  //				  NULL);
+
+  XmStringFree (lab);
+
+  for (i = 0; i < num_buttons; i++) {
+    button = XtCreateManagedWidget (button_names[i],
+				    xmToggleButtonWidgetClass,
+				    radio_box,
+				    args[i],
+				    7);
+    XtVaSetValues (button,
+		   XmNuserData, i,
+		   NULL);
+    
+    XtAddCallbacks (button,
+		   XmNarmCallback,
+		   radio_box_callback);
+  }
+
+  XtManageChild (radio_box);
+
+  XmStringFree (button_str);
+  
+  for (i = 0; i < num_buttons; i++) {
+
+    delete[] args[i];
+
+  }
+
+  delete[] args;
+}  
+
+void G4OpenGLXmViewer::Add_set_field (char* w_name, 
+				    char* w_text,
+				    Widget* row_col_box,
+				    Widget* wid,
+				    G4double* val,
+				    G4OpenGLXmViewer* pView)
+{
+
+  char local_w_text[50];
+  strcpy (local_w_text, w_text);
+
+  char label_name[50];
+  strcpy (label_name, w_name);
+  strcat (label_name, "_label");
+  
+  char text_field_name[50];
+  strcpy (text_field_name, w_name);
+  strcat (text_field_name, "_text_field");
+  
+  XmString local_text = XmStringCreateLocalized (local_w_text);
+
+  // Unused!
+  //  Widget label = XtVaCreateManagedWidget (label_name, 
+  //				  xmLabelWidgetClass,
+  //				  *row_col_box,
+  //				  XmNlabelString, local_text,
+  //				  XtNvisual, pView->vi->visual, 
+  //				  XtNdepth, pView->vi->depth, 
+  //				  XtNcolormap, pView->cmap, 
+  //				  XtNborderColor, pView->borcol,
+  //				  XtNbackground, pView->bgnd,
+  //				  NULL);
+
+  XmStringFree (local_text);
+
+  char initial[50];
+  sprintf (initial, "%6.2f", *val);
+  
+  *wid = XtVaCreateManagedWidget (text_field_name,
+				  xmTextFieldWidgetClass,
+				  *row_col_box,
+				  XmNvalue, (String)initial,
+				  XtNvisual, pView->vi->visual, 
+				  XtNdepth, pView->vi->depth, 
+				  XtNcolormap, pView->cmap, 
+				  XtNborderColor, pView->borcol,
+				  XtNbackground, pView->bgnd,
+				  NULL);
+
+  XtAddCallback (*wid, 
+		 XmNvalueChangedCallback,
+		 get_double_value_callback,
+		 val);
+
+  Widget sep = XtVaCreateManagedWidget ("sep",
+					xmSeparatorWidgetClass,
+					*row_col_box,
+					XmNorientation, XmHORIZONTAL,
+					XtNvisual, pView->vi->visual, 
+					XtNdepth, pView->vi->depth, 
+					XtNcolormap, pView->cmap, 
+					XtNborderColor, pView->borcol,
+					XtNbackground, pView->bgnd,
+					NULL);
+
+  sep = XtVaCreateManagedWidget ("sep",
+				 xmSeparatorWidgetClass,
+				 *row_col_box,
+				 XmNseparatorType, XmNO_LINE,
+				 XmNmargin, 1,
+				 XmNorientation, XmHORIZONTAL,
+				 XtNvisual, pView->vi->visual, 
+				 XtNdepth, pView->vi->depth, 
+				 XtNcolormap, pView->cmap, 
+				 XtNborderColor, pView->borcol,
+				 XtNbackground, pView->bgnd,
+				 NULL);
+}
+
+void G4OpenGLXmViewer::Add_slider_box (char* label_string,
+				     G4int num_sliders,
+				     char** slider_names,
+				     G4OpenGLXmViewer* pView,
+				     G4double* min_array,
+				     G4double* max_array,
+				     G4double* value_array,
+				     G4bool* show,
+				     short* decimals,
+				     unsigned char* orientation,
+				     unsigned char* direction,
+				     XtCallbackRec** slider_box_callbacks,
+				     Widget* parent_widget)
+{
+  XmString slider_name_str = XmStringCreateLocalized((char*) ""); // ...to
+  // initialise to something to avoid pedantic warning.
+  Arg** slider_args;
+  slider_args = new Arg*[num_sliders];
+  Widget slider;
+  G4int j = 0;
+
+  G4int i;
+  for (i = 0; i < num_sliders; i++) {
+    j = 0; 
+    slider_args[i] = new Arg[13];
+    slider_name_str = XmStringCreateLtoR (slider_names[i], 
+					  XmFONTLIST_DEFAULT_TAG);
+    
+    XtSetArg (slider_args[i][j], 
+	      XtNvisual, pView->vi->visual); j++;
+    XtSetArg (slider_args[i][j], 
+	      XtNdepth, pView->vi->depth); j++;
+    XtSetArg (slider_args[i][j], 
+	      XtNcolormap, pView->cmap); j++;
+    XtSetArg (slider_args[i][j], 
+	      XtNborderColor, pView->borcol); j++;
+    XtSetArg (slider_args[i][j], 
+	      XtNbackground, pView->bgnd); j++;
+    
+    XtSetArg (slider_args[i][j], 
+	      XmNtitleString, slider_name_str);  j++;
+    
+    XtSetArg (slider_args[i][j], 
+	      XmNmaximum, G4int(max_array[i] * std::pow(10.0, (G4double)decimals[i]))); j++;
+    XtSetArg (slider_args[i][j], 
+	      XmNminimum, G4int(min_array[i] * std::pow(10.0, (G4double)decimals[i]))); j++;
+    XtSetArg (slider_args[i][j], 
+	      XmNvalue, G4int(value_array[i] * std::pow(10.0, (G4double)decimals[i]))); j++;
+    XtSetArg (slider_args[i][j], 
+	      XmNshowValue, show[i]); j++;
+    XtSetArg (slider_args[i][j], 
+	      XmNdecimalPoints, decimals[i]); j++;
+    
+    XtSetArg (slider_args[i][j], 
+	      XmNorientation, orientation[i]);  j++;
+    XtSetArg (slider_args[i][j], 
+	      XmNprocessingDirection, direction[i]); j++;
+
+  }
+
+  Widget slider_box = XtVaCreateWidget ("slider_box",
+					xmRowColumnWidgetClass,
+					*parent_widget,
+					XmNisHomogeneous, False,
+					XtNvisual, pView->vi->visual,
+					XtNdepth, pView->vi->depth,
+					XtNcolormap, pView->cmap,
+					XtNborderColor, pView->borcol,
+					XtNbackground, pView->bgnd,
+					NULL);
+
+  XmString lab = XmStringCreateLocalized (label_string);
+
+  // Unused!
+  //Widget label = XtVaCreateManagedWidget ("slider_label",
+  //				  xmLabelWidgetClass,
+  //				  slider_box,
+  //				  XmNlabelString, lab,
+  //				  XmNalignment, XmALIGNMENT_CENTER,
+  //				  XtNvisual, pView->vi->visual,
+  //				  XtNdepth, pView->vi->depth,
+  //				  XtNcolormap, pView->cmap,
+  //				  XtNborderColor, pView->borcol,
+  //				  XtNbackground, pView->bgnd,
+  //				  NULL);
+
+  XmStringFree (lab);
+  
+  for (i = 0; i < num_sliders; i++) {
+    
+    slider = XtCreateManagedWidget (slider_names[i],
+				    xmScaleWidgetClass,
+				    slider_box,
+				    slider_args[i],
+				    j);
+
+    XtAddCallbacks (slider,
+		   XmNvalueChangedCallback,
+		   slider_box_callbacks[i]);
+    
+    XtAddCallbacks (slider,
+		   XmNdragCallback,
+		   slider_box_callbacks[i]);
+    
+  }
+
+  XtManageChild (slider_box);
+  XmStringFree (slider_name_str);
+
+  for (i = 0; i < num_sliders; i++) {
+
+    delete[] slider_args[i];
+
+  }
+
+  delete[] slider_args;
+
+}
+
+void G4OpenGLXmViewer::get_double_value_callback (Widget w, 
+						XtPointer clientData, 
+						XtPointer) 
+{
+  G4double* val = (G4double*) clientData;
+  String string;
+
+  XtVaGetValues (w,
+		 XmNvalue, &string,
+		 NULL);
+
+  sscanf (string, "%lg", val);
+
+}
+
+void G4OpenGLXmViewer::get_text_callback (Widget w, 
+					XtPointer clientData, 
+					XtPointer) 
+{
+  char* txt = (char*)clientData;
+  String string;
+
+  XtVaGetValues (w,
+		 XmNvalue, &string,
+		 NULL);
+
+  sscanf (string, "%s", txt);
+}
+
+G4bool G4OpenGLXmViewer::get_boolean_userData (Widget w)
+{
+  XtPointer userData;
+  XtVaGetValues (w,XmNuserData,&userData,NULL);
+  return (G4bool)(unsigned long)userData;
+}
+
+G4int G4OpenGLXmViewer::get_int_userData (Widget w)
+{
+  XtPointer userData;
+  XtVaGetValues (w,XmNuserData,&userData,NULL);
+  return (G4int)(unsigned long)userData;
+}
+
+#endif
+
+
+
+
+
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmFourArrowButtons.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmFourArrowButtons.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmFourArrowButtons.cc	(revision 529)
@@ -0,0 +1,219 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmFourArrowButtons.cc,v 1.5 2006/06/29 21:19:44 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+//Four arrow buttons class. Inherits from G4OpenGLXmVWidgetComponent
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLXmVWidgetComponent.hh"
+#include "G4OpenGLXmVWidgetContainer.hh"
+#include "G4OpenGLXmFourArrowButtons.hh"
+#include <X11/Intrinsic.h>
+#include "globals.hh"
+
+G4OpenGLXmFourArrowButtons::G4OpenGLXmFourArrowButtons (XtCallbackRec** c)
+{
+  callback = c;
+}
+
+G4OpenGLXmFourArrowButtons::~G4OpenGLXmFourArrowButtons ()
+{}
+
+void G4OpenGLXmFourArrowButtons::AddYourselfTo (G4OpenGLXmVWidgetContainer* container)
+{
+
+  pView = container->GetView ();
+  ProcesspView ();
+
+  parent = container->GetPointerToWidget ();
+
+  arrow_form = XtVaCreateManagedWidget 
+    ("arrow_form",
+     xmFormWidgetClass,
+     *parent,
+     XmNfractionBase, 3,
+
+     XtNvisual, visual, 
+     XtNdepth, depth, 
+     XtNcolormap, cmap, 
+     XtNborderColor, borcol,
+     XtNbackground, bgnd,
+
+     NULL);
+
+
+///////////////`up' arrow///////////////  
+  arrow = XtVaCreateManagedWidget 
+    ("up_arrow",
+     xmArrowButtonGadgetClass, 
+     arrow_form,
+     
+     XmNtopAttachment, XmATTACH_POSITION,
+     XmNtopPosition, 0,
+     
+     XmNbottomAttachment, XmATTACH_POSITION,
+     XmNbottomPosition, 1,
+     
+     XmNleftAttachment, XmATTACH_POSITION,
+     XmNleftPosition, 1,
+
+     XmNrightAttachment, XmATTACH_POSITION,
+     XmNrightPosition, 2,
+
+     XmNarrowDirection, XmARROW_UP,
+     XmNuserData, True,
+     NULL);
+  
+  XtAddCallbacks (arrow, 
+		  XmNactivateCallback, 
+		  callback[0]);
+  
+  XtAddCallbacks (arrow, 
+		  XmNarmCallback, 
+		  callback[0]);
+  
+  XtAddCallbacks (arrow, 
+		  XmNdisarmCallback, 
+		  callback[0]);
+  
+///////////////`down' arrow///////////////  
+  arrow = XtVaCreateManagedWidget 
+    ("down_arrow",
+     xmArrowButtonGadgetClass, 
+     arrow_form,
+     
+     XmNtopAttachment, XmATTACH_POSITION,
+     XmNtopPosition, 2,
+
+     XmNbottomAttachment, XmATTACH_POSITION,
+     XmNbottomPosition, 3,
+
+     XmNleftAttachment, XmATTACH_POSITION,
+     XmNleftPosition, 1,
+
+     XmNrightAttachment, XmATTACH_POSITION,
+     XmNrightPosition, 2,
+
+     XmNarrowDirection, XmARROW_DOWN,
+     XmNuserData, False,
+     NULL);
+  
+  XtAddCallbacks (arrow, 
+		  XmNactivateCallback, 
+		  callback[1]);
+  
+  XtAddCallbacks (arrow, 
+		  XmNarmCallback, 
+		  callback[1]);
+  
+  XtAddCallbacks (arrow, 
+		  XmNdisarmCallback, 
+		  callback[1]);
+  
+///////////////`left' arrow///////////////  
+  arrow = XtVaCreateManagedWidget 
+    ("left_arrow",
+     xmArrowButtonGadgetClass, 
+     arrow_form,
+     
+     XmNtopAttachment, XmATTACH_POSITION,
+     XmNtopPosition, 1,
+     
+     XmNbottomAttachment, XmATTACH_POSITION,
+     XmNbottomPosition, 2,
+     
+     XmNleftAttachment, XmATTACH_POSITION,
+     XmNleftPosition, 0,
+     
+     XmNrightAttachment, XmATTACH_POSITION,
+     XmNrightPosition, 1,
+     
+     XmNarrowDirection, XmARROW_LEFT,
+     XmNuserData, False,
+     NULL);
+  
+  XtAddCallbacks (arrow, 
+		  XmNactivateCallback, 
+		  callback[2]);
+  
+  XtAddCallbacks (arrow, 
+		  XmNarmCallback, 
+		  callback[2]);
+  
+  XtAddCallbacks (arrow, 
+		  XmNdisarmCallback, 
+		  callback[2]);
+  
+///////////////`right' arrow///////////////  
+  arrow = XtVaCreateManagedWidget 
+    ("right_arrow",
+     xmArrowButtonGadgetClass, 
+     arrow_form,
+     
+     XmNtopAttachment, XmATTACH_POSITION,
+     XmNtopPosition, 1,
+     
+     XmNbottomAttachment, XmATTACH_POSITION,
+     XmNbottomPosition, 2,
+
+     XmNleftAttachment, XmATTACH_POSITION,
+     XmNleftPosition, 2,
+
+     XmNrightAttachment, XmATTACH_POSITION,
+     XmNrightPosition, 3,
+
+     XmNarrowDirection, XmARROW_RIGHT,
+     XmNuserData, True,
+     NULL);
+  
+  XtAddCallbacks (arrow, 
+		  XmNactivateCallback, 
+		  callback[3]);
+  
+  XtAddCallbacks (arrow, 
+		  XmNarmCallback, 
+		  callback[3]);
+  
+  XtAddCallbacks (arrow, 
+		  XmNdisarmCallback, 
+		  callback[3]);
+
+}
+
+Widget* G4OpenGLXmFourArrowButtons::GetPointerToParent ()
+{
+  return parent;
+}
+
+Widget* G4OpenGLXmFourArrowButtons::GetPointerToWidget () 
+{
+  return &arrow_form;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmFramedBox.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmFramedBox.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmFramedBox.cc	(revision 529)
@@ -0,0 +1,103 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmFramedBox.cc,v 1.6 2006/06/29 21:19:46 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+//Framed box container class
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLXmBox.hh"
+#include "G4OpenGLXmFramedBox.hh"
+#include "G4OpenGLXmVWidgetComponent.hh"
+#include "G4OpenGLXmVWidgetShell.hh"
+
+G4OpenGLXmFramedBox::G4OpenGLXmFramedBox (const char* n, 
+					  G4bool r) :
+G4OpenGLXmBox (n, r)
+{
+  frame = NULL;
+}
+
+G4OpenGLXmFramedBox::~G4OpenGLXmFramedBox () 
+{}
+
+void G4OpenGLXmFramedBox::AddChild (G4OpenGLXmVWidgetComponent* component)
+{
+  component->AddYourselfTo(this);
+  Cardinal num_children;
+  XtVaGetValues (box_row_col,
+		 XmNnumChildren, &num_children,
+		 NULL);
+//  G4cout << name << " now parents " << num_children << " children." << G4endl;
+}
+
+void G4OpenGLXmFramedBox::AddYourselfTo (G4OpenGLXmVWidgetShell* window)
+{
+
+  pView = window->GetView ();
+  ProcesspView ();
+  char framename[50];
+  strcpy (framename, name);
+  strcat (framename, "_frame");
+
+  parent = window->GetPointerToWidget ();
+  frame = XtVaCreateManagedWidget (framename,
+				    xmFrameWidgetClass,
+				    *parent,
+				    
+				    XtNvisual, visual,
+				    XtNdepth, depth,
+				    XtNcolormap, cmap,
+				    XtNborderColor, borcol,
+				    XtNbackground, bgnd,
+				    
+				    NULL);
+  
+  
+  
+  box_row_col =  XtVaCreateManagedWidget (name,
+					  xmRowColumnWidgetClass,
+					  frame,
+					  
+					  XmNadjustMargin, True,
+					  XmNisHomogeneous, False,
+					  XmNlabelString, (XmString)name,
+					  XmNradioAlwaysOne, radio,
+					  XmNradioBehavior, radio,
+					  
+					  XtNvisual, visual,
+					  XtNdepth, depth,
+					  XtNcolormap, cmap,
+					  XtNborderColor, borcol,
+					  XtNbackground, bgnd,
+					  
+					  NULL);
+  
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmMainMenubarCallbacks.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmMainMenubarCallbacks.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmMainMenubarCallbacks.cc	(revision 529)
@@ -0,0 +1,570 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmMainMenubarCallbacks.cc,v 1.13 2006/06/29 21:19:48 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Andrew Walkden  16th April 1997
+// G4OpenGLXmMainMenubarCallbacks : 
+//                       Collection of callback functions
+//                       to handle events generated by the
+//                       main OpenGLXm window menubar.
+//
+// See G4OpenGLXmMainMenubarCallbacks.hh for more information.
+
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4Xt.hh"
+
+#include "G4OpenGLXmViewer.hh"
+
+#include "G4Scene.hh"
+
+#include "G4OpenGLXmRadioButton.hh"
+#include "G4OpenGLXmSliderBar.hh"
+#include "G4OpenGLXmFourArrowButtons.hh"
+#include "G4OpenGLXmTextField.hh"
+#include "G4OpenGLXmPushButton.hh"
+#include "G4OpenGLXmBox.hh"
+#include "G4OpenGLXmFramedBox.hh"
+#include "G4OpenGLXmTopLevelShell.hh"
+#include "G4OpenGLXmSeparator.hh"
+
+#include <sstream>
+
+void G4OpenGLXmViewer::actions_callback (Widget w, 
+				       XtPointer clientData,
+				       XtPointer)
+{
+  
+  G4OpenGLXmViewer* pView;
+  G4long choice = (G4long)clientData;
+  
+  
+  XtVaGetValues (XtParent(w), 
+		 XmNuserData, &pView, 
+		 NULL);
+  
+  switch (choice) {
+    
+  case 0:
+    
+    {
+      
+      if (!pView->fprotation_top) {
+	std::ostringstream rot_Name;
+	rot_Name << pView->GetSceneHandler()->GetSceneHandlerId() << '-' << pView->fViewId;
+	
+	pView->fprotation_top = new G4OpenGLXmTopLevelShell (pView,
+							     (char*)rot_Name.str().c_str());
+	pView->fprotation_button_box = new G4OpenGLXmBox ("Rotation button box", True);
+	
+	pView->fprotation_top->AddChild (pView->fprotation_button_box);
+	
+	XtCallbackRec* rot_cb_list = new XtCallbackRec[2];
+	rot_cb_list[0].callback = set_rot_subject_callback;
+	rot_cb_list[0].closure = pView; 
+	rot_cb_list[1].callback = NULL;
+	
+	pView->fprotation_button1 = new G4OpenGLXmRadioButton
+	  ("Object",
+	   rot_cb_list,
+	   pView->GetViewParameters().GetLightsMoveWithCamera(),
+	   0);
+	
+	pView->fprotation_button2 = new G4OpenGLXmRadioButton
+	  ("Camera",
+	   rot_cb_list,
+	   !(pView->GetViewParameters().GetLightsMoveWithCamera()),
+	   1);
+	
+	pView->fprotation_button_box->AddChild (pView->fprotation_button1);
+	pView->fprotation_button_box->AddChild (pView->fprotation_button2);
+	
+	pView->fprotation_slider_box = new G4OpenGLXmBox ("Rotation slider box", False);
+	pView->fprotation_top->AddChild (pView->fprotation_slider_box);
+	
+	XtCallbackRec* rot_slider_list = new XtCallbackRec[2];
+	rot_slider_list[0].callback = set_rot_sens_callback;
+	rot_slider_list[0].closure = pView; 
+	rot_slider_list[1].callback = NULL;
+	
+	pView->fprotation_slider = new G4OpenGLXmSliderBar ("Rotation slider",
+							    rot_slider_list,
+							    True,
+							    2,
+							    pView->rot_sens,
+							    pView->rot_sens_limit,
+							    0);
+	pView->fprotation_slider_box->AddChild (pView->fprotation_slider);
+	
+	pView->fprotation_arrow_box = new G4OpenGLXmBox ("Rotation arrow box", False);
+	pView->fprotation_top->AddChild (pView->fprotation_arrow_box);
+	
+	XtCallbackRec** rotation_callbacks = new XtCallbackRec*[4];
+	for (G4int i = 0; i < 4; i++) {
+	  rotation_callbacks[i] = new XtCallbackRec[2];
+	}
+	rotation_callbacks[0][0].callback = phi_rotation_callback;
+	rotation_callbacks[0][0].closure =  pView;
+	rotation_callbacks[0][1].callback	= NULL;
+	
+	rotation_callbacks[1][0].callback = phi_rotation_callback;
+	rotation_callbacks[1][0].closure =  pView;
+	rotation_callbacks[1][1].callback	= NULL;
+	
+	rotation_callbacks[2][0].callback = theta_rotation_callback;
+	rotation_callbacks[2][0].closure =  pView;
+	rotation_callbacks[2][1].callback	= NULL;
+	
+	rotation_callbacks[3][0].callback = theta_rotation_callback;
+	rotation_callbacks[3][0].closure =  pView;
+	rotation_callbacks[3][1].callback	= NULL;
+	
+	pView->fprotation_arrow = new G4OpenGLXmFourArrowButtons (rotation_callbacks);
+	
+	pView->fprotation_arrow_box->AddChild (pView->fprotation_arrow);
+	
+	pView->fprotation_top->Realize ();
+      }
+      break;
+      
+    }
+  
+  
+  case 1:
+    {
+
+      if (!pView->fppanning_top) {
+	std::ostringstream pan_Name;
+	pan_Name << pView->GetSceneHandler()->GetSceneHandlerId() << '-' << pView->fViewId;
+	
+	pView->fppanning_top = new G4OpenGLXmTopLevelShell (pView, 
+							    (char*)pan_Name.str().c_str());
+	
+	pView->fppanning_box = new G4OpenGLXmFramedBox ("Pan up-down-left-right", 
+							False);
+	
+	pView->fppanning_top->AddChild (pView->fppanning_box);
+	
+	XtCallbackRec** pan_callbacks = new XtCallbackRec*[4];
+	for (G4int i = 0; i < 4; i++) {
+	  pan_callbacks[i] = new XtCallbackRec[2];
+	}
+	pan_callbacks[0][0].callback = pan_up_down_callback;
+	pan_callbacks[0][0].closure = pView; 
+	pan_callbacks[0][1].callback = NULL;
+	
+	pan_callbacks[1][0].callback = pan_up_down_callback;
+	pan_callbacks[1][0].closure = pView; 
+	pan_callbacks[1][1].callback = NULL;
+	
+	pan_callbacks[2][0].callback = pan_left_right_callback;
+	pan_callbacks[2][0].closure = pView; 
+	pan_callbacks[2][1].callback = NULL;
+	
+	pan_callbacks[3][0].callback = pan_left_right_callback;
+	pan_callbacks[3][0].closure = pView; 
+	pan_callbacks[3][1].callback = NULL;
+	
+	pView->fppanning_arrows = new G4OpenGLXmFourArrowButtons (pan_callbacks);
+	
+	pView->fppanning_box->AddChild (pView->fppanning_arrows);
+	
+	XtCallbackRec* pan_slider_list = new XtCallbackRec[2];
+	pan_slider_list[0].callback = set_pan_sens_callback;
+	pan_slider_list[0].closure = pView; 
+	pan_slider_list[1].callback = NULL;
+	
+	pView->fppanning_slider = new G4OpenGLXmSliderBar ("Panning slider",
+							   pan_slider_list,
+							   True,
+							   2,
+							   pView->pan_sens = pView->GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius() / 10.0,
+							   pView->pan_sens_limit = pView->GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius(),
+							   0);
+	pView->fppanning_box->AddChild (pView->fppanning_slider);
+	
+	pView->fpzoom_box = new G4OpenGLXmFramedBox ("Zoom", 
+						     False);      
+	pView->fppanning_top->AddChild (pView->fpzoom_box);
+	
+	XtCallbackRec* zoom_slider_list = new XtCallbackRec[2];
+	zoom_slider_list[0].callback = zoom_callback;
+	zoom_slider_list[0].closure = pView; 
+	zoom_slider_list[1].callback = NULL;
+	
+	pView->fpzoom_slider = new G4OpenGLXmSliderBar ("Zoom slider",
+							zoom_slider_list,
+							True,
+							2,
+							pView->fVP.GetZoomFactor(),
+							pView->zoom_high,
+							pView->zoom_low);
+	pView->fpzoom_box->AddChild (pView->fpzoom_slider);
+	
+	pView->fpdolly_box = new G4OpenGLXmFramedBox ("Dolly", 
+						      False);      
+	pView->fppanning_top->AddChild (pView->fpdolly_box);
+	
+	XtCallbackRec* dolly_slider_list = new XtCallbackRec[2];
+	dolly_slider_list[0].callback = dolly_callback;
+	dolly_slider_list[0].closure = pView; 
+	dolly_slider_list[1].callback = NULL;
+	
+	pView->fpdolly_slider = new G4OpenGLXmSliderBar ("Dolly slider",
+							 dolly_slider_list,
+							 True,
+							 2,
+							 pView->fVP.GetDolly(),
+							 pView->dolly_high = pView->GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius(),
+							 pView->dolly_low = -(pView->GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius()));
+	//							 pView->dolly_high,
+	//							 pView->dolly_low);
+	pView->fpdolly_box->AddChild (pView->fpdolly_slider);
+	
+	pView->fppanning_top->Realize ();
+      }
+
+      break;
+      
+    }
+  case 2:
+    {
+      
+      if (!pView->fpsetting_top) {
+	std::ostringstream set_Name;
+	set_Name << pView->GetSceneHandler()->GetSceneHandlerId() << '-' << pView->fViewId;
+	
+	pView->fpsetting_top = new G4OpenGLXmTopLevelShell(pView,
+							   (char*)set_Name.str().c_str());
+	
+	pView->fpsetting_box = new G4OpenGLXmFramedBox ("Set values for control panels",
+							False);
+	pView->fpsetting_top->AddChild (pView->fpsetting_box);
+	
+	pView->fppan_set = new G4OpenGLXmTextField ("Upper limit of pan sensitivity",
+						    &(pView->pan_sens_limit));
+	
+	pView->fprot_set = new G4OpenGLXmTextField ("Upper limit of rotation sensitivity",
+						    &(pView->rot_sens_limit));
+	
+	pView->fpzoom_upper = new G4OpenGLXmTextField ("Upper limit of zoom",
+						       &(pView->zoom_high));
+	
+	pView->fpzoom_lower = new G4OpenGLXmTextField ("Lower limit of zoom",
+						       &(pView->zoom_low));
+	
+	pView->fpdolly_upper = new G4OpenGLXmTextField ("Upper limit of dolly",
+							&(pView->dolly_high));
+	
+	pView->fpdolly_lower = new G4OpenGLXmTextField ("Lower limit of dolly",
+							&(pView->dolly_low));
+	
+	XtCallbackRec* ok_list = new XtCallbackRec[2];
+	ok_list[0].callback = update_panels_callback;
+	ok_list[0].closure = pView; 
+	ok_list[1].callback = NULL;
+	
+	
+	pView->fpok_button = new G4OpenGLXmPushButton ("ok",
+						       ok_list);
+	
+	pView->fpsetting_box->AddChild (pView->fppan_set);
+	pView->fpsetting_box->AddChild (pView->fprot_set);
+	pView->fpsetting_box->AddChild (pView->fpzoom_upper);
+	pView->fpsetting_box->AddChild (pView->fpzoom_lower);
+	pView->fpsetting_box->AddChild (pView->fpdolly_upper);
+	pView->fpsetting_box->AddChild (pView->fpdolly_lower);
+	pView->fpsetting_box->AddChild (pView->fpok_button);
+	
+	pView->fpsetting_top->Realize ();
+	
+      }
+
+      break;
+    }
+  
+  default:
+    G4Exception("Unrecognised widget child of control_callback");
+  }
+  
+  return;
+}
+
+
+
+void G4OpenGLXmViewer::misc_callback (Widget w, 
+				    XtPointer clientData, 
+				    XtPointer) 
+{
+  G4OpenGLXmViewer* pView;
+  G4long choice = (G4long)clientData;
+  XtVaGetValues (XtParent(w), 
+		 XmNuserData, &pView, 
+		 NULL);
+  
+  switch (choice) {
+    
+  case 0:
+    {
+
+      if (!pView->fpmiscellany_top) {
+	
+	std::ostringstream misc_Name;
+	misc_Name << pView->GetSceneHandler()->GetSceneHandlerId() << '-' << pView->fViewId;
+	
+	pView->fpmiscellany_top = new G4OpenGLXmTopLevelShell (pView, 
+							       (char*)misc_Name.str().c_str());
+	pView->fpwobble_box = new G4OpenGLXmFramedBox ("Wobble view",
+						       True);
+	pView->fpmiscellany_top->AddChild (pView->fpwobble_box);
+	
+	XtCallbackRec* wob_cb_list = new XtCallbackRec[2];
+	wob_cb_list[0].callback = wobble_callback;
+	wob_cb_list[0].closure = pView; 
+	wob_cb_list[1].callback = NULL;
+	
+	
+	pView->fpwobble_button = new G4OpenGLXmPushButton ("Wobble",
+							   wob_cb_list);
+	
+	XtCallbackRec* wobble_slider_list = new XtCallbackRec[2];
+	wobble_slider_list[0].callback = set_wob_sens_callback;
+	wobble_slider_list[0].closure = pView; 
+	wobble_slider_list[1].callback = NULL;
+	
+	pView->fpwobble_slider = new G4OpenGLXmSliderBar ("Wobble slider",
+							  wobble_slider_list,
+							  True,
+							  0,
+							  20,
+							  50,
+							  0);
+	pView->fpwobble_box->AddChild (pView->fpwobble_button);
+	pView->fpwobble_box->AddChild (pView->fpwobble_slider);
+	
+	pView->fpreset_box = new G4OpenGLXmFramedBox ("Reset view",
+						      True);
+	pView->fpmiscellany_top->AddChild (pView->fpreset_box);
+	
+	XtCallbackRec* rst_cb_list = new XtCallbackRec[3];
+	rst_cb_list[0].callback = reset_callback;
+	rst_cb_list[0].closure = pView; 
+	rst_cb_list[1].callback = update_panels_callback;
+	rst_cb_list[1].closure = pView; 
+	rst_cb_list[2].callback = NULL;
+	
+	pView->fpreset_button = new G4OpenGLXmPushButton ("Reset",
+							  rst_cb_list);
+	
+	pView->fpreset_box->AddChild (pView->fpreset_button);
+	
+	pView->fpproj_style_box = new G4OpenGLXmFramedBox ("Projection style",
+							   True);
+	pView->fpmiscellany_top->AddChild (pView->fpproj_style_box);
+	
+	XtCallbackRec* proj_cb_list = new XtCallbackRec[2];
+	proj_cb_list[0].callback = projection_callback;
+	proj_cb_list[0].closure = pView; 
+	proj_cb_list[1].callback = NULL;
+	
+	pView->fporthogonal_button = new G4OpenGLXmRadioButton ("Orthographic",
+								proj_cb_list,
+								pView->fVP.GetFieldHalfAngle() > 0. ? False : True,
+								0);
+	
+	pView->fpperspective_button = new G4OpenGLXmRadioButton ("Perspective",
+								 proj_cb_list,
+								 pView->fVP.GetFieldHalfAngle() > 0. ? True : False,
+								 1);
+	
+	pView->fpfov_text = new G4OpenGLXmTextField ("Field of view 0.1 -> 89.5 degrees.",
+						     &(pView->fov));
+	
+	pView->fpproj_style_box->AddChild (pView->fpperspective_button);
+	pView->fpproj_style_box->AddChild (pView->fporthogonal_button);
+	pView->fpproj_style_box->AddChild (pView->fpfov_text);
+	
+	pView->fpmiscellany_top->Realize ();
+
+      }
+      
+      break;
+    }
+  
+  case 1:
+    {
+      G4Xt::getInstance () -> RequireExitSecondaryLoop (OGL_EXIT_CODE);
+      break;
+    }
+  
+  case 2:
+    {
+      if (!pView->fpprint_top) {
+	
+	std::ostringstream print_Name;
+	print_Name << pView->GetSceneHandler()->GetSceneHandlerId() << '-' << pView->fViewId;
+	
+	pView->fpprint_top = new G4OpenGLXmTopLevelShell (pView, 
+							  (char*)print_Name.str().c_str());
+
+	pView->fpprint_box = new G4OpenGLXmFramedBox ("Create EPS file of current view",
+						       False);
+
+	pView->fpprint_top->AddChild (pView->fpprint_box);
+	
+	pView->fpprint_col_box = new G4OpenGLXmFramedBox ("Colour choice",
+							  True);
+	pView->fpprint_top->AddChild (pView->fpprint_col_box);
+
+	XtCallbackRec* prcol_cb_list = new XtCallbackRec[2];
+	prcol_cb_list[0].callback = set_print_colour_callback;
+	prcol_cb_list[0].closure = pView; 
+	prcol_cb_list[1].callback = NULL;
+	
+	pView->fpprint_col_radio1 = new G4OpenGLXmRadioButton ("Black and white",
+							       prcol_cb_list,
+							       pView->print_colour==false ? True : False,
+							       0);
+	
+	pView->fpprint_col_radio2 = new G4OpenGLXmRadioButton ("Colour",
+							       prcol_cb_list,
+							       pView->print_colour==true ? True : False,
+							       1);
+	
+	pView->fpprint_col_box->AddChild (pView->fpprint_col_radio1);
+	pView->fpprint_col_box->AddChild (pView->fpprint_col_radio2);
+
+	pView->fpprint_style_box = new G4OpenGLXmFramedBox ("File type",
+							    True);
+	pView->fpprint_top->AddChild (pView->fpprint_style_box);
+
+	XtCallbackRec* prsty_cb_list = new XtCallbackRec[2];
+	prsty_cb_list[0].callback = set_print_style_callback;
+	prsty_cb_list[0].closure = pView; 
+	prsty_cb_list[1].callback = NULL;
+	
+	pView->fpprint_style_radio1 = new G4OpenGLXmRadioButton ("Screen dump (pixmap)",
+								 prsty_cb_list,
+								 pView->vectored_ps==false ? True : False,
+								 0);
+	
+	pView->fpprint_style_radio2 = new G4OpenGLXmRadioButton ("PostScript",
+								 prsty_cb_list,
+								 pView->vectored_ps==true ? True : False,
+								 1);
+	
+	pView->fpprint_style_box->AddChild (pView->fpprint_style_radio1);
+	pView->fpprint_style_box->AddChild (pView->fpprint_style_radio2);
+	
+	pView->fpprint_text = new G4OpenGLXmTextField ("Name of .eps file to save",
+						       (pView->print_string));
+	pView->fpprint_box->AddChild (pView->fpprint_text);	
+	
+	pView->fpprint_line = new G4OpenGLXmSeparator ();
+	pView->fpprint_box->AddChild (pView->fpprint_line);
+
+	XtCallbackRec* pri_cb_list = new XtCallbackRec[2];
+	pri_cb_list[0].callback = print_callback;
+	pri_cb_list[0].closure = pView; 
+	pri_cb_list[1].callback = NULL;
+	
+	
+	pView->fpprint_button = new G4OpenGLXmPushButton ("Create EPS file",
+							  pri_cb_list);
+	
+	pView->fpprint_box->AddChild (pView->fpprint_button);
+	pView->fpprint_top->Realize ();
+
+      }
+      
+      ///ajw
+      break;
+    }
+  
+  default:
+    G4Exception("Unrecognised widget child of misc_callback.");
+  }
+  
+  return;
+  
+}
+
+void G4OpenGLXmViewer::set_wob_sens_callback (Widget w, 
+					    XtPointer clientData, 
+					    XtPointer callData) 
+{
+  XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
+  short dp = -1;
+  G4float ten_to_the_dp = 10.;
+  
+  XtVaGetValues (w, 
+		 XmNdecimalPoints, &dp,
+		 NULL);
+  
+  if (dp == 0) {
+    ten_to_the_dp = 1.;
+  } else if ( dp > 0) {
+    for (G4int i = 1; i < (G4int)dp; i++) {
+      ten_to_the_dp *= 10.;
+    }
+  } else {
+    G4Exception("Bad value returned for dp in set_rot_sens_callback");
+  }
+  
+  pView->wob_sens = (G4float)(cbs->value) / ten_to_the_dp;
+}  
+
+void G4OpenGLXmViewer::update_panels_callback (Widget, 
+					     XtPointer clientData, 
+					     XtPointer) 
+{
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
+  
+  if (pView->fppanning_slider) {
+    pView->fppanning_slider->SetMaxValue (pView->pan_sens_limit);
+  }
+  if (pView->fprotation_slider) {
+    pView->fprotation_slider->SetMaxValue (pView->rot_sens_limit);
+  }
+  
+  if (pView->fpzoom_slider) {
+    pView->fpzoom_slider->SetMaxValue (pView->zoom_high);
+    pView->fpzoom_slider->SetMinValue (pView->zoom_low);
+    pView->fpzoom_slider->SetInitialValue (pView->fVP.GetZoomFactor());
+  }
+  
+  if (pView->fpdolly_slider) {
+    pView->fpdolly_slider->SetMaxValue (pView->dolly_high);
+    pView->fpdolly_slider->SetMinValue (pView->dolly_low);
+  }
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmPanningCallbacks.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmPanningCallbacks.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmPanningCallbacks.cc	(revision 529)
@@ -0,0 +1,246 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmPanningCallbacks.cc,v 1.8 2006/06/29 21:19:50 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Andrew Walkden  16th April 1997
+// G4OpenGLXmPanningCallbacks : 
+//                       Several callback functions used by
+//                       elements of the control panel to`pan' 
+//                       the view (i.e. move the viewpoint and 
+//                       camera positions by equal amounts).
+//                       Zoom callback is also here.
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLXmViewer.hh"
+#include "G4Scene.hh"
+
+void G4OpenGLXmViewer::zoom_callback (Widget w, 
+				    XtPointer clientData, 
+				    XtPointer callData) 
+{
+  XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
+  short dp = -1;
+  G4float ten_to_the_dp = 10.;
+
+  XtVaGetValues (w, 
+		 XmNdecimalPoints, &dp,
+		 NULL);
+
+  if (dp == 0) {
+    ten_to_the_dp = 1.;
+  } else if ( dp > 0) {
+    for (G4int i = 1; i < (G4int)dp; i++) {
+      ten_to_the_dp *= 10.;
+    }
+  } else {
+    G4cout << "dp is " << dp << G4endl;
+    return;
+  }
+
+
+  G4double zoomBy = (G4double)(cbs->value) / ten_to_the_dp;
+  if (zoomBy <= 0.01) {
+    zoomBy = 0.01;
+  }
+
+  pView->fVP.SetZoomFactor (zoomBy);
+  pView->SetView ();
+  pView->ClearView ();
+  pView -> DrawView ();
+}  
+
+void G4OpenGLXmViewer::dolly_callback (Widget w, 
+				     XtPointer clientData, 
+				     XtPointer callData) 
+{
+  XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
+  short dp = -1;
+  G4float ten_to_the_dp = 10.;
+
+  XtVaGetValues (w, 
+		 XmNdecimalPoints, &dp,
+		 NULL);
+
+  if (dp == 0) {
+    ten_to_the_dp = 1.;
+  } else if ( dp > 0) {
+    for (G4int i = 1; i < (G4int)dp; i++) {
+      ten_to_the_dp *= 10.;
+    }
+  } else {
+    G4cout << "dp is " << dp << G4endl;
+    return;
+  }
+
+  G4double dolly = (G4double)(cbs->value) / ten_to_the_dp;
+
+  pView->fVP.SetDolly (dolly);
+  pView->SetView ();
+  pView->ClearView ();
+  pView->DrawView ();
+
+}  
+
+void G4OpenGLXmViewer::pan_left_right_callback (Widget w, 
+					      XtPointer clientData, 
+					      XtPointer callData) 
+{
+  XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
+
+  pView->pan_right = get_boolean_userData (w);
+
+  if (cbs->reason == XmCR_ARM) {
+    left_right_pan_callback (pView,NULL);
+  } else if (cbs->reason == XmCR_DISARM) {
+    XtRemoveTimeOut (pView->pan_timer);
+  }
+}
+
+void G4OpenGLXmViewer::left_right_pan_callback (XtPointer clientData,
+					      XtIntervalId* timer_id) 
+
+{
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
+  G4double delta;
+  
+  if (pView->pan_right) {
+    delta = (G4double)pView->pan_sens;
+  } else {
+    delta = -((G4double)pView->pan_sens);
+  }
+  
+  G4Point3D stp
+    = pView -> GetSceneHandler()->GetScene()->GetStandardTargetPoint();
+
+  G4Point3D tp = stp + pView -> fVP.GetCurrentTargetPoint ();
+  
+  const G4Vector3D& upVector = pView->fVP.GetUpVector ();
+  const G4Vector3D& vpVector = pView->fVP.GetViewpointDirection ();
+  
+  G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
+  G4Vector3D unitUp    = (vpVector.cross (unitRight)).unit();
+  
+  tp += delta * unitRight;
+  pView->fVP.SetCurrentTargetPoint (tp - stp);
+
+  pView->SetView ();
+  pView->ClearView ();
+  pView->DrawView ();
+
+  pView->pan_timer = XtAppAddTimeOut 
+    (pView->app,
+     timer_id == NULL ? 500 : 1,
+     left_right_pan_callback,
+     pView);
+}  
+
+void G4OpenGLXmViewer::pan_up_down_callback (Widget w, 
+					   XtPointer clientData, 
+					   XtPointer callData) 
+{
+  XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
+
+  pView->pan_up = get_boolean_userData (w);
+
+  if (cbs->reason == XmCR_ARM) {
+    up_down_pan_callback (pView,NULL);
+  } else if (cbs->reason == XmCR_DISARM) {
+    XtRemoveTimeOut (pView->pan_timer);
+  }
+}
+
+void G4OpenGLXmViewer::up_down_pan_callback (XtPointer clientData,
+					   XtIntervalId* timer_id) 
+{
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
+  G4double delta;
+  
+  if (pView->pan_up) {
+    delta = (G4double)pView->pan_sens;
+  } else {
+    delta = -((G4double)pView->pan_sens);
+  }
+  
+  G4Point3D stp
+    = pView -> GetSceneHandler()->GetScene()->GetStandardTargetPoint();
+  G4Point3D tp = stp + pView -> fVP.GetCurrentTargetPoint ();
+  const G4Vector3D& upVector = pView->fVP.GetUpVector ();
+  const G4Vector3D& vpVector = pView->fVP.GetViewpointDirection ();
+  
+  G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
+  G4Vector3D unitUp    = (vpVector.cross (unitRight)).unit();
+  tp += delta * unitUp;
+  pView->fVP.SetCurrentTargetPoint (tp - stp);
+  
+  pView->SetView ();
+  pView->ClearView ();
+  pView->DrawView ();
+
+  pView->pan_timer = XtAppAddTimeOut 
+    (pView->app,
+     timer_id == NULL ? 500 : 1,
+     up_down_pan_callback,
+     pView);
+}  
+
+void G4OpenGLXmViewer::set_pan_sens_callback (Widget w, 
+					    XtPointer clientData, 
+					    XtPointer callData) 
+{
+  XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
+  short dp = -1;
+  G4float ten_to_the_dp = 10.;
+
+  XtVaGetValues (w, 
+		 XmNdecimalPoints, &dp,
+		 NULL);
+
+  if (dp == 0) {
+    ten_to_the_dp = 1.;
+  } else if ( dp > 0) {
+    for (G4int i = 1; i < (G4int)dp; i++) {
+      ten_to_the_dp *= 10.;
+    }
+  } else {
+    G4cout << "dp is " << dp << G4endl;
+    return;
+  }
+  
+  pView->pan_sens = (G4double)((cbs->value) / ten_to_the_dp);
+}  
+
+#endif
+
+
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmPushButton.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmPushButton.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmPushButton.cc	(revision 529)
@@ -0,0 +1,108 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmPushButton.cc,v 1.6 2006/06/29 21:19:52 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+//Push button class. Inherits from G4OpenGLXmVWidgetComponent
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLXmVWidgetComponent.hh"
+#include "G4OpenGLXmVWidgetContainer.hh"
+#include "G4OpenGLXmPushButton.hh"
+#include <X11/Intrinsic.h>
+#include "globals.hh"
+
+G4OpenGLXmPushButton::G4OpenGLXmPushButton (const char* n,
+					    XtCallbackRec* c) 
+{
+  name = n;
+  callback = c;
+}
+
+G4OpenGLXmPushButton::~G4OpenGLXmPushButton ()
+{}
+
+void G4OpenGLXmPushButton::SetName (const char* n) 
+{
+  name = n;
+  XmString button_string = XmStringCreateLocalized ((char*)name);
+  XtVaSetValues (button,
+		 XmNlabelString, button_string,
+		 NULL);
+  XmStringFree (button_string);
+}
+
+const char* G4OpenGLXmPushButton::GetName () 
+{
+  return name;
+}
+
+void G4OpenGLXmPushButton::AddYourselfTo (G4OpenGLXmVWidgetContainer* container)
+{
+
+  pView = container->GetView ();
+  ProcesspView ();
+  parent = container->GetPointerToWidget ();
+
+  XmString button_str = XmStringCreateLocalized ((char*)name);
+  button = XtVaCreateManagedWidget 
+    (name,
+     xmPushButtonWidgetClass,
+     *parent,
+     XmNlabelString, button_str,
+     XmNalignment, XmALIGNMENT_CENTER,
+     XmNuserData, pView,
+
+     XtNvisual, visual, 
+     XtNdepth, depth, 
+     XtNcolormap, cmap, 
+     XtNborderColor, borcol,
+     XtNbackground, bgnd,
+     
+     NULL);
+  
+  XtAddCallbacks (button,
+		  XmNarmCallback,
+		  callback);
+  
+  XmStringFree (button_str);
+}
+
+Widget* G4OpenGLXmPushButton::GetPointerToParent ()
+{
+  return parent;
+}
+
+Widget* G4OpenGLXmPushButton::GetPointerToWidget () 
+{
+  return &button;
+}
+
+#endif
+
+
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmRadioButton.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmRadioButton.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmRadioButton.cc	(revision 529)
@@ -0,0 +1,109 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmRadioButton.cc,v 1.6 2006/06/29 21:19:54 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+//Radio button class. Inherits from G4OpenGLXmVWidgetComponent
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLXmVWidgetComponent.hh"
+#include "G4OpenGLXmVWidgetContainer.hh"
+#include "G4OpenGLXmRadioButton.hh"
+#include <X11/Intrinsic.h>
+#include "globals.hh"
+
+G4OpenGLXmRadioButton::G4OpenGLXmRadioButton (const char* n,
+					      XtCallbackRec* c,
+					      G4bool d,
+					      G4int num) 
+{
+  name = n;
+  callback = c;
+  default_button = d;
+  number = num;
+}
+
+G4OpenGLXmRadioButton::~G4OpenGLXmRadioButton ()
+{}
+
+void G4OpenGLXmRadioButton::SetName (const char* n) 
+{
+  name = n;
+  XmString button_string = XmStringCreateLocalized ((char*)name);
+  XtVaSetValues (button,
+		 XmNlabelString, button_string,
+		 NULL);
+  XmStringFree (button_string);
+}
+
+const char* G4OpenGLXmRadioButton::GetName () 
+{
+  return name;
+}
+
+void G4OpenGLXmRadioButton::AddYourselfTo (G4OpenGLXmVWidgetContainer* container)
+{
+
+  pView = container->GetView ();
+  ProcesspView ();
+  parent = container->GetPointerToWidget ();
+  XmString button_string = XmStringCreateLocalized ((char*)name);
+  button = XtVaCreateManagedWidget (name,
+				    xmToggleButtonWidgetClass,
+				    *parent,
+				    
+				    XmNlabelString, button_string,
+				    XmNset, default_button,
+				    XmNuserData, number,
+				    
+				    XtNvisual, visual,
+				    XtNdepth, depth,
+				    XtNcolormap, cmap,
+				    XtNborderColor, borcol,
+				    XtNbackground, bgnd,
+				    
+				    NULL);
+  
+  XtAddCallbacks (button,
+		  XmNarmCallback,
+		  callback);
+
+  XmStringFree (button_string);
+}
+
+Widget* G4OpenGLXmRadioButton::GetPointerToParent ()
+{
+  return parent;
+}
+
+Widget* G4OpenGLXmRadioButton::GetPointerToWidget () 
+{
+  return &button;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmRotationCallbacks.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmRotationCallbacks.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmRotationCallbacks.cc	(revision 529)
@@ -0,0 +1,305 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmRotationCallbacks.cc,v 1.14 2006/06/29 21:19:56 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Andrew Walkden  16th April 1997
+// G4OpenGLXmRotationCallbacks : 
+//                       Several callback functions used by
+//                       elements of the control panel to
+//                       rotate the view.
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLXmViewer.hh"
+
+#include "G4Scene.hh"
+#include "G4UImanager.hh"
+#include "G4ios.hh"
+
+void G4OpenGLXmViewer::theta_rotation_callback (Widget w, 
+					      XtPointer clientData, 
+					      XtPointer callData) 
+{
+  XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
+
+  pView->rotate_right = get_boolean_userData (w);
+
+  if (cbs->reason == XmCR_ARM) {
+    rotate_in_theta (pView, NULL);
+  } else if (cbs->reason == XmCR_DISARM) {
+    XtRemoveTimeOut (pView->rotation_timer);
+  }
+}
+
+void G4OpenGLXmViewer::rotate_in_theta (XtPointer clientData,
+				      XtIntervalId* timer_id) 
+{
+  //theta spin stuff here
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
+  G4double delta_theta;
+
+  if (pView->fVP.GetLightsMoveWithCamera()) {
+    if (pView->rotate_right) {
+      delta_theta = -((G4double)pView->rot_sens);
+    } else {
+      delta_theta = (G4double)pView->rot_sens;
+    }
+  } else {
+    if (pView->rotate_right) {
+      delta_theta = (G4double)pView->rot_sens;
+    } else {
+      delta_theta = -((G4double)pView->rot_sens);
+    }
+  }    
+  delta_theta *= deg;
+  // Rotates by fixed azimuthal angle delta_theta.
+
+  const G4Vector3D& vp = pView->fVP.GetViewpointDirection ().unit ();
+  const G4Vector3D& up = pView->fVP.GetUpVector ().unit ();
+  const G4Vector3D& zprime = up;
+  G4double cosalpha = up.dot (vp);
+  G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));
+  G4Vector3D yprime = (zprime.cross (vp)).unit ();
+  G4Vector3D xprime = yprime.cross (zprime);
+  // Projection of vp on plane perpendicular to up...
+  G4Vector3D a1 = sinalpha * xprime;
+  // Required new projection...
+  G4Vector3D a2 =
+    sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);
+  // Required Increment vector...
+  G4Vector3D delta = a2 - a1;
+  // So new viewpoint is...
+  G4Vector3D viewPoint = vp + delta;
+
+  pView->fVP.SetViewAndLights (viewPoint);  
+
+  pView->SetView ();
+  pView->ClearView ();
+  pView->DrawView ();
+
+  pView->rotation_timer = XtAppAddTimeOut 
+    (pView->app,
+     timer_id == NULL ? 500 : 1,
+     rotate_in_theta,
+     pView);
+}  
+
+void G4OpenGLXmViewer::phi_rotation_callback (Widget w, 
+					    XtPointer clientData, 
+					    XtPointer callData) 
+{
+  XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
+
+  pView->rotate_up = get_boolean_userData (w);
+
+  if (cbs->reason == XmCR_ARM) {
+    rotate_in_phi (pView, NULL);
+  } else if (cbs->reason == XmCR_DISARM) {
+    XtRemoveTimeOut (pView->rotation_timer);
+  }
+}
+
+void G4OpenGLXmViewer::rotate_in_phi (XtPointer clientData,
+				    XtIntervalId* timer_id)
+{
+  //phi spin stuff here
+  G4double delta_alpha;
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
+
+  if (pView->fVP.GetLightsMoveWithCamera()) {
+    if (pView -> rotate_up) {
+      delta_alpha = -((G4double)pView->rot_sens);
+    } else {
+      delta_alpha = (G4double)pView->rot_sens;
+    }
+  } else {
+    if (pView -> rotate_up) {
+      delta_alpha = (G4double)pView->rot_sens;
+    } else {
+      delta_alpha = -((G4double)pView->rot_sens);
+    }
+  }    
+
+  delta_alpha *= deg;
+
+  const G4Vector3D& vp = pView->fVP.GetViewpointDirection ().unit ();
+  const G4Vector3D& up = pView->fVP.GetUpVector ().unit ();
+
+  const G4Vector3D& xprime = vp;
+  G4Vector3D yprime = (up.cross(xprime)).unit();
+  G4Vector3D zprime = (xprime.cross(yprime)).unit();
+
+  G4Vector3D new_vp = std::cos(delta_alpha) * xprime + std::sin(delta_alpha) * zprime;
+
+  pView->fVP.SetViewAndLights (new_vp.unit());
+
+  if (pView->fVP.GetLightsMoveWithCamera()) {
+    G4Vector3D new_up = (new_vp.cross(yprime)).unit();
+    pView->fVP.SetUpVector(new_up);
+  }
+
+  pView->SetView ();
+  pView->ClearView ();
+  pView->DrawView ();
+  
+  pView->rotation_timer = XtAppAddTimeOut 
+    (pView->app,
+     timer_id == NULL ? 500 : 1,
+     rotate_in_phi,
+     pView);
+}
+
+void G4OpenGLXmViewer::set_rot_sens_callback (Widget w, 
+					    XtPointer clientData, 
+					    XtPointer callData) 
+{
+  XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
+  short dp = -1;
+  G4float ten_to_the_dp = 10.;
+
+  XtVaGetValues (w, 
+		 XmNdecimalPoints, &dp,
+		 NULL);
+
+  if (dp == 0) {
+    ten_to_the_dp = 1.;
+  } else if ( dp > 0) {
+    for (G4int i = 1; i < (G4int)dp; i++) {
+      ten_to_the_dp *= 10.;
+    }
+  } else {
+    G4Exception("Bad value returned for dp in set_rot_sens_callback");
+  }
+
+  pView->rot_sens = (G4float)(cbs->value) / ten_to_the_dp;
+}  
+
+void G4OpenGLXmViewer::set_rot_subject_callback (Widget w, 
+					       XtPointer clientData, 
+					       XtPointer) 
+{
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData;
+  
+  G4int choice = get_int_userData (w);
+  
+  switch (choice) {
+  case 0: 
+    {
+      pView->fVP.SetLightsMoveWithCamera (true);
+      break;
+    }
+  case 1:
+    {
+      pView->fVP.SetLightsMoveWithCamera (false);
+      break;
+    }
+  default:
+    {
+      G4Exception("Unrecognised choice made in set_rot_subject_callback"); 
+    }
+  }
+}  
+
+void G4OpenGLXmViewer::wobble_callback (Widget w, 
+				      XtPointer, 
+				      XtPointer) 
+{
+  G4OpenGLXmViewer* pView;
+  
+  XtVaGetValues (w,
+		 XmNuserData, &pView,
+		 NULL);
+  
+  pView->original_vp = pView->fVP.GetViewpointDirection();
+  pView->wobble_timer = XtAppAddTimeOut
+    (pView->app,
+     (long unsigned int) (1000. * (1. / pView->wob_sens)),
+     wobble_timer_callback,
+     pView);
+}  
+
+void G4OpenGLXmViewer::wobble_timer_callback (XtPointer clientData,
+					    XtIntervalId*) 
+{
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData;
+  const G4Vector3D& up = pView->fVP.GetUpVector();
+  G4Vector3D third_axis = up.cross(pView->original_vp);
+  G4double pi_div_by_ten = pi / 10.0;
+  G4Vector3D d_up = 0.1 * (std::sin ((G4double)pView->frameNo * pi_div_by_ten * 2.)) * up;
+  G4Vector3D d_third_axis = 0.1 * (std::sin ((G4double)pView->frameNo * (pi_div_by_ten))) * third_axis;
+
+  pView->fVP.SetViewAndLights (pView->original_vp + d_up + d_third_axis);
+
+  pView->SetView ();
+  pView->ClearView ();
+  pView->DrawView ();
+  
+  if (pView->frameNo++ == 20) {
+    if (pView->wobble_timer) {
+      XtRemoveTimeOut (pView->wobble_timer);
+      pView->frameNo = 0;
+      pView->fVP.SetViewAndLights (pView->original_vp);
+      pView->SetView ();
+      pView->ClearView ();
+      pView->DrawView ();
+   }
+  } else {
+    pView->wobble_timer = XtAppAddTimeOut
+      (pView->app,
+       (long unsigned int) (1000. * (1. / pView->wob_sens)),
+       wobble_timer_callback,
+       pView);
+  }
+}
+
+void G4OpenGLXmViewer::reset_callback (Widget w, 
+				     XtPointer, 
+				     XtPointer) 
+{
+  
+  G4OpenGLXmViewer* pView;
+  
+  XtVaGetValues (w,
+		 XmNuserData, &pView,
+		 NULL);
+  
+  pView->fVP.SetCurrentTargetPoint(G4Point3D());
+  pView->fVP.SetZoomFactor(1.0);
+  pView->fVP.SetDolly(0.0);
+  pView->SetView ();
+  pView->ClearView ();
+  pView->DrawView ();
+  pView->zoom_low = 0.1;
+  pView->zoom_high = 10.0;
+  
+}
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmSeparator.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmSeparator.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmSeparator.cc	(revision 529)
@@ -0,0 +1,82 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmSeparator.cc,v 1.5 2006/06/29 21:19:58 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+//Separator class. Inherits from G4OpenGLXmVWidgetComponent
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLXmVWidgetComponent.hh"
+#include "G4OpenGLXmVWidgetContainer.hh"
+#include "G4OpenGLXmSeparator.hh"
+#include <X11/Intrinsic.h>
+#include "globals.hh"
+
+G4OpenGLXmSeparator::G4OpenGLXmSeparator (unsigned char l) 
+{
+  line_type = l;
+}
+
+G4OpenGLXmSeparator::~G4OpenGLXmSeparator ()
+{}
+
+void G4OpenGLXmSeparator::AddYourselfTo (G4OpenGLXmVWidgetContainer* container)
+{
+
+  pView = container->GetView ();
+  ProcesspView ();
+
+  parent = container->GetPointerToWidget ();
+
+  line = XtVaCreateManagedWidget ("sep",
+				  xmSeparatorWidgetClass,
+				  *parent,
+				  XmNseparatorType, line_type,
+				  XmNmargin, 1,
+				  XmNorientation, XmHORIZONTAL,
+				  
+				  XtNvisual, visual, 
+				  XtNdepth, depth, 
+				  XtNcolormap, cmap, 
+				  XtNborderColor, borcol,
+				  XtNbackground, bgnd,
+				  
+				  NULL);
+}
+
+Widget* G4OpenGLXmSeparator::GetPointerToParent ()
+{
+  return parent;
+}
+
+Widget* G4OpenGLXmSeparator::GetPointerToWidget () 
+{
+  return &line;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmSliderBar.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmSliderBar.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmSliderBar.cc	(revision 529)
@@ -0,0 +1,227 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmSliderBar.cc,v 1.7 2006/06/29 21:20:00 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+//Slider bar class. Inherits from G4OpenGLXmVWidgetComponent
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLXmVWidgetComponent.hh"
+#include "G4OpenGLXmVWidgetContainer.hh"
+#include "G4OpenGLXmSliderBar.hh"
+#include <X11/Intrinsic.h>
+#include <Xm/Scale.h>
+#include "globals.hh"
+
+G4OpenGLXmSliderBar::G4OpenGLXmSliderBar (const char* n,
+					  XtCallbackRec* c,
+					  G4bool s,
+					  short dp,
+					  G4double v,
+					  G4double max,
+					  G4double min,
+					  unsigned char o,
+					  unsigned char d) 
+{
+  name = n;
+  callback = c;
+  show = s;
+  decimal_places = dp;
+  initial_value = int(v * std::pow(10.0, (G4double)dp));
+  max_value = int(max * std::pow(10.0, (G4double)dp));
+  min_value = int(min * std::pow(10.0, (G4double)dp));
+  orientation = o;
+  direction = d;
+}
+
+G4OpenGLXmSliderBar::~G4OpenGLXmSliderBar ()
+{}
+
+const char* G4OpenGLXmSliderBar::GetName () 
+{
+  return name;
+}
+
+G4bool G4OpenGLXmSliderBar::GetShow () 
+{
+  return show;
+}
+
+short G4OpenGLXmSliderBar::GetDecimalPlaces () 
+{
+  return decimal_places;
+}
+
+G4double G4OpenGLXmSliderBar::GetInitialValue () 
+{
+  return (G4double)initial_value / std::pow(10.0, (G4double)GetDecimalPlaces());
+}
+
+G4double G4OpenGLXmSliderBar::GetMaxValue () 
+{
+  return (G4double)max_value / std::pow(10.0, (G4double)GetDecimalPlaces());
+}
+
+G4double G4OpenGLXmSliderBar::GetMinValue () 
+{
+  return (G4double)min_value / std::pow(10.0, (G4double)GetDecimalPlaces());
+}
+
+unsigned char G4OpenGLXmSliderBar::GetOrientation () 
+{
+  return orientation;
+}
+
+unsigned char G4OpenGLXmSliderBar::GetDirection () 
+{
+  return direction;
+}
+
+void G4OpenGLXmSliderBar::SetName (const char* n) 
+{
+  name = n;
+  XmString sliderbar_string = XmStringCreateLocalized ((char*)name);
+  XtVaSetValues (sliderbar,
+		 XmNlabelString, sliderbar_string,
+		 NULL);
+ XmStringFree (sliderbar_string);
+}
+
+void G4OpenGLXmSliderBar::SetShow (G4bool s) 
+{
+  show = s;
+  XtVaSetValues (sliderbar,
+		 XmNshowValue, show,
+		 NULL);
+  
+}
+
+void G4OpenGLXmSliderBar::SetDecimalPlaces (short dp) 
+{
+  decimal_places = dp;
+  XtVaSetValues (sliderbar,
+		 XmNdecimalPoints, decimal_places,
+		 NULL);
+  
+}
+
+void G4OpenGLXmSliderBar::SetInitialValue (G4double v) 
+{
+  initial_value = int(v * std::pow(10.0, (G4double)GetDecimalPlaces()));
+  XtVaSetValues (sliderbar,
+		 XmNvalue, initial_value,
+		 NULL);
+  
+}
+
+void G4OpenGLXmSliderBar::SetMaxValue (G4double v) 
+{
+  max_value = int(v * std::pow(10.0, (G4double)GetDecimalPlaces()));
+  XtVaSetValues (sliderbar,
+		 XmNmaximum, max_value,
+		 NULL);
+  
+}
+
+void G4OpenGLXmSliderBar::SetMinValue (G4double v) 
+{
+  min_value = int(v * std::pow(10.0, (G4double)GetDecimalPlaces()));
+  XtVaSetValues (sliderbar,
+		 XmNminimum, min_value,
+		 NULL);
+  
+}
+
+void G4OpenGLXmSliderBar::SetOrientation (unsigned char o) 
+{
+  orientation = o;
+  XtVaSetValues (sliderbar,
+		 XmNorientation, orientation,
+		 NULL);
+  
+}
+
+void G4OpenGLXmSliderBar::SetDirection (unsigned char d) 
+{
+  direction = d;
+  XtVaSetValues (sliderbar,
+		 XmNprocessingDirection, direction,
+		 NULL);
+  
+}
+
+void G4OpenGLXmSliderBar::AddYourselfTo (G4OpenGLXmVWidgetContainer* container)
+{
+
+  pView = container->GetView ();
+  ProcesspView ();
+
+  parent = container->GetPointerToWidget ();
+  XmString name_string = XmStringCreateLocalized ((char*)name);
+  sliderbar = XtVaCreateManagedWidget (name,
+				       xmScaleWidgetClass,
+				       *parent,
+				       
+				       XmNtitleString, name_string,
+				       XmNmaximum, max_value,
+				       XmNminimum, min_value,
+				       XmNvalue, initial_value,
+				       XmNshowValue, show,
+				       XmNdecimalPoints, decimal_places,
+				       XmNorientation, orientation,
+				       XmNprocessingDirection, direction,
+  
+				       XtNvisual, visual,
+				       XtNdepth, depth,
+				       XtNcolormap, cmap,
+				       XtNborderColor, borcol,
+				       XtNbackground, bgnd,
+
+				       NULL);
+				       
+  XtAddCallbacks (sliderbar,
+		  XmNvalueChangedCallback,
+		  callback);
+
+  XtAddCallbacks (sliderbar,
+		  XmNdragCallback,
+		  callback);
+  XmStringFree (name_string);
+}
+
+Widget* G4OpenGLXmSliderBar::GetPointerToParent ()
+{
+  return parent;
+}
+
+Widget* G4OpenGLXmSliderBar::GetPointerToWidget () 
+{
+  return &sliderbar;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmStyleCallbacks.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmStyleCallbacks.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmStyleCallbacks.cc	(revision 529)
@@ -0,0 +1,314 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmStyleCallbacks.cc,v 1.14 2006/06/29 21:20:02 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Andrew Walkden  16th April 1997
+// G4OpenGLXmStyleCallbacks : 
+//                       Several callback functions used by
+//                       elements of the control panel to
+//                       determine how to visualize the view.
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLXmViewer.hh"
+
+void G4OpenGLXmViewer::drawing_style_callback (Widget w, 
+					     XtPointer clientData, 
+					     XtPointer) 
+{
+  G4long choice = (G4long)clientData;
+  G4OpenGLXmViewer* pView;
+  XtVaGetValues (XtParent(w),
+		 XmNuserData, &pView,
+		 NULL);
+  G4ViewParameters::DrawingStyle style;
+
+  switch (choice) {
+    
+  case 0:
+    style = G4ViewParameters::wireframe;
+    break;
+
+  case 1:
+    style = G4ViewParameters::hlr;
+    break;
+
+  case 2:
+    style = G4ViewParameters::hsr;
+    break;
+
+  case 3:
+    style = G4ViewParameters::hlhsr;
+    break;
+
+  default:
+    style = G4ViewParameters::wireframe;
+    G4Exception("Unrecognised case in drawing_style_callback.");
+  }
+
+  pView->fVP.SetDrawingStyle (style);
+  
+  pView->SetView ();
+  pView->ClearView ();
+  pView->DrawView ();
+}
+
+void G4OpenGLXmViewer::rep_style_callback (Widget w, 
+					 XtPointer clientData, 
+					 XtPointer) 
+{
+  G4long choice = (G4long)clientData;
+  G4OpenGLXmViewer* pView;
+  XtVaGetValues (XtParent(w),
+		 XmNuserData, &pView,
+		 NULL);
+  G4ViewParameters::RepStyle style;
+
+  switch (choice) {
+    
+  case 0:
+    style = G4ViewParameters::polyhedron;
+    break;
+
+  case 1:
+    style = G4ViewParameters::nurbs;
+    break;
+
+  default:
+    style = G4ViewParameters::polyhedron;
+    G4Exception("Unrecognised case in rep_style_callback.");
+  }
+
+  pView->fVP.SetRepStyle (style);
+
+  pView->SetView ();
+  pView->ClearView ();
+  pView->DrawView ();
+}
+
+void G4OpenGLXmViewer::background_color_callback (Widget w, 
+						XtPointer clientData, 
+						XtPointer) 
+{
+  G4long choice = (G4long)clientData;
+  G4OpenGLXmViewer* pView;
+  XtVaGetValues (XtParent(w),
+		 XmNuserData, &pView,
+		 NULL);
+
+
+  //I need to revisit the kernel if the background colour changes and
+  //hidden line removal is enabled, because hlr drawing utilises the
+  //background colour in its drawing...
+  // (Note added by JA 13/9/2005) Background now handled in view
+  // parameters.  A kernel visit is triggered on change of background.
+  switch (choice) {
+    
+  case 0:
+    ((G4ViewParameters&)pView->GetViewParameters()).
+      SetBackgroundColour(G4Colour(1.,1.,1.));  // White
+    break;
+
+  case 1:
+    ((G4ViewParameters&)pView->GetViewParameters()).
+      SetBackgroundColour(G4Colour(0.,0.,0.));  // Black
+    break;
+
+  default:
+    G4Exception("Unrecognised case in background_color_callback.");
+  }
+
+  pView->SetView ();
+  pView->ClearView ();
+  pView->DrawView ();
+}
+
+void G4OpenGLXmViewer::transparency_callback (Widget w, 
+					    XtPointer clientData, 
+					    XtPointer) 
+{
+  G4long choice = (G4long)clientData;
+  G4OpenGLXmViewer* pView;
+  XtVaGetValues (XtParent(w),
+		 XmNuserData, &pView,
+		 NULL);
+
+  switch (choice) {
+    
+  case 0:
+    pView->transparency_enabled = false;
+    break;
+
+  case 1:
+    pView->transparency_enabled = true;
+    break;
+
+  default:
+    G4Exception("Unrecognised case in transparency_callback.");
+  }
+
+  pView->SetNeedKernelVisit (true);
+  pView->SetView ();
+  pView->ClearView ();
+  pView->DrawView ();
+}
+
+void G4OpenGLXmViewer::antialias_callback (Widget w, 
+					 XtPointer clientData, 
+					 XtPointer) 
+{
+  G4long choice = (G4long)clientData;
+  G4OpenGLXmViewer* pView;
+  XtVaGetValues (XtParent(w),
+		 XmNuserData, &pView,
+		 NULL);
+
+  switch (choice) {
+    
+  case 0:
+    pView->antialiasing_enabled = false;
+    glDisable (GL_LINE_SMOOTH);
+    glDisable (GL_POLYGON_SMOOTH);
+    break;
+
+  case 1:
+    pView->antialiasing_enabled = true;
+    glEnable (GL_LINE_SMOOTH);
+    glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
+    glEnable (GL_POLYGON_SMOOTH);
+    glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
+    break;
+
+  default:
+    G4Exception("Unrecognised case in antialiasing_callback.");
+  }
+
+  pView->SetView ();
+  pView->ClearView ();
+  pView->DrawView ();
+}
+
+void G4OpenGLXmViewer::haloing_callback (Widget w, 
+				       XtPointer clientData, 
+				       XtPointer) 
+{
+  G4long choice = (G4long)clientData;
+  G4OpenGLXmViewer* pView;
+  XtVaGetValues (XtParent(w),
+		 XmNuserData, &pView,
+		 NULL);
+
+  switch (choice) {
+    
+  case 0:
+    pView->haloing_enabled = false;
+    break;
+
+  case 1:
+    pView->haloing_enabled = true;
+    break;
+
+  default:
+    G4Exception("Unrecognised case in haloing_callback.");
+  }
+
+  pView->SetView ();
+  pView->ClearView ();
+  pView->DrawView ();
+}
+
+void G4OpenGLXmViewer::aux_edge_callback (Widget w, 
+				       XtPointer clientData, 
+				       XtPointer) 
+{
+  G4long choice = (G4long)clientData;
+  G4OpenGLXmViewer* pView;
+  XtVaGetValues (XtParent(w),
+		 XmNuserData, &pView,
+		 NULL);
+
+  switch (choice) {
+    
+  case 0:
+    pView->fVP.SetAuxEdgeVisible(false);
+    break;
+
+  case 1:
+    pView->fVP.SetAuxEdgeVisible(true);
+    break;
+
+  default:
+    G4Exception("Unrecognised case in aux_edge_callback.");
+  }
+
+  pView->SetNeedKernelVisit (true);
+  pView->SetView ();
+  pView->ClearView ();
+  pView->DrawView ();
+}
+
+void G4OpenGLXmViewer::projection_callback (Widget w, 
+					  XtPointer clientData, 
+					  XtPointer) 
+{
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData;
+
+  G4int choice = get_int_userData (w);
+
+  switch (choice) {
+  case 0:
+    {
+      pView->fVP.SetFieldHalfAngle (0.);
+      break;
+    }
+
+  case 1:
+    {
+      if (pView->fov > 89.5 || pView->fov <= 0.0) {
+	G4cout << "Field half angle should be 0 < angle <= 89.5 degrees.";
+	G4cout << G4endl;
+      }
+      else {
+	pView->fVP.SetFieldHalfAngle (pView->fov * deg);
+      }
+      break;
+    }
+  default:
+    {
+      G4Exception("Unrecognised choice made in projection_callback");
+    }
+  }
+
+  pView->SetView ();
+  pView->ClearView ();
+  pView->DrawView ();
+}  
+
+#endif
+
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmTextField.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmTextField.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmTextField.cc	(revision 529)
@@ -0,0 +1,178 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmTextField.cc,v 1.7 2006/06/29 21:20:04 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+//Text field class. Inherits from G4OpenGLXmVWidgetComponent
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLXmVWidgetComponent.hh"
+#include "G4OpenGLXmVWidgetContainer.hh"
+#include "G4OpenGLXmTextField.hh"
+#include <X11/Intrinsic.h>
+#include "globals.hh"
+
+G4OpenGLXmTextField::G4OpenGLXmTextField (const char* n,
+					  G4double* val)
+{
+  name = n;
+  initial = new char[50];
+  sprintf (initial, "%6.2f", *val);
+  value = (void*)val;
+  text=false;
+}
+
+G4OpenGLXmTextField::G4OpenGLXmTextField (const char* n,
+					  const char* val)
+{
+  name = n;
+  initial = new char[50];
+  sprintf (initial, "%s", val);
+  value = (void*)val;
+  text=true;
+  //  strcpy (initial, val);
+}
+
+G4OpenGLXmTextField::~G4OpenGLXmTextField ()
+{
+  delete[] initial;
+}
+
+void G4OpenGLXmTextField::SetName (const char* n) 
+{
+  name = n;
+  XmString text_string = XmStringCreateLocalized ((char*)name);
+  XtVaSetValues (text_label,
+		 XmNlabelString, text_string,
+		 NULL);
+  XmStringFree (text_string);
+}
+
+const char* G4OpenGLXmTextField::GetName () 
+{
+  return name;
+}
+
+void G4OpenGLXmTextField::SetValue (G4double val)
+{
+  sprintf (initial, "%6.2f", val);
+  
+  XtVaSetValues (text_field,
+		 XmNvalue, (String)initial,
+		 NULL);
+  
+}
+
+void G4OpenGLXmTextField::SetValue (const char* val)
+{
+  sprintf (initial, "%s", val);
+  //  strcpy (initial, val);
+
+  XtVaSetValues (text_field,
+		 XmNvalue, (String)initial,
+		 NULL);
+  
+}
+
+const char* G4OpenGLXmTextField::GetValue ()
+{
+  return initial;
+}
+
+void G4OpenGLXmTextField::AddYourselfTo (G4OpenGLXmVWidgetContainer* container)
+{
+
+  pView = container->GetView ();
+  ProcesspView ();
+  parent = container->GetPointerToWidget ();
+
+  char local_w_text[50];
+  strcpy (local_w_text, name);
+
+  char label_name[50];
+  strcpy (label_name, name);
+  strcat (label_name, "_label");
+  
+  char text_field_name[50];
+  strcpy (text_field_name, name);
+  strcat (text_field_name, "_text_field");
+  
+  XmString local_text = XmStringCreateLocalized (local_w_text);
+  text_label = XtVaCreateManagedWidget (label_name, 
+					xmLabelWidgetClass,
+					*parent,
+
+					XmNlabelString, local_text,
+					
+					XtNvisual, visual, 
+					XtNdepth, depth, 
+					XtNcolormap, cmap, 
+					XtNborderColor, borcol,
+					XtNbackground, bgnd,
+					
+					NULL);
+  XmStringFree (local_text);
+
+  text_field = XtVaCreateManagedWidget (text_field_name,
+					xmTextFieldWidgetClass,
+					*parent,
+
+					XmNvalue, (String)initial, 
+					
+					XtNvisual, visual, 
+					XtNdepth, depth, 
+					XtNcolormap, cmap, 
+					XtNborderColor, borcol,
+					XtNbackground, bgnd,
+					
+					NULL);
+
+  if (!text) {
+    XtAddCallback (text_field, 
+		   XmNvalueChangedCallback,
+		   G4OpenGLXmViewer::get_double_value_callback,
+		   value);
+  } else {
+    XtAddCallback (text_field, 
+		   XmNvalueChangedCallback,
+		   G4OpenGLXmViewer::get_text_callback,
+		   value);
+  }
+}
+
+Widget* G4OpenGLXmTextField::GetPointerToParent ()
+{
+  return parent;
+}
+
+Widget* G4OpenGLXmTextField::GetPointerToWidget () 
+{
+  return &text_field;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmTopLevelShell.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmTopLevelShell.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmTopLevelShell.cc	(revision 529)
@@ -0,0 +1,123 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmTopLevelShell.cc,v 1.5 2006/06/29 21:20:06 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+//Top level shell class
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLXmTopLevelShell.hh"
+#include "G4OpenGLXmVWidgetContainer.hh"
+
+G4OpenGLXmTopLevelShell::G4OpenGLXmTopLevelShell (G4OpenGLXmViewer* v,
+						  char* n) 
+{
+  pView = v;
+  ProcesspView ();
+  name = n;
+  toplevel = XtVaCreatePopupShell 
+    (name,
+     topLevelShellWidgetClass,
+     top,
+     
+     XtNiconName, name,
+     XtNtitle, name,
+     XmNdeleteResponse, XmDO_NOTHING,
+     XmNisHomogeneous, False,
+     
+     XtNvisual, visual, 
+     XtNdepth, depth, 
+     XtNcolormap, cmap, 
+     XtNborderColor, borcol,
+     XtNbackground, bgnd,
+     NULL);
+
+  frame = XtVaCreateManagedWidget (name,
+				   xmFrameWidgetClass,
+				   toplevel,
+				   
+				   XtNvisual, visual,
+				   XtNdepth, depth,
+				   XtNcolormap, cmap,
+				   XtNborderColor, borcol,
+				   XtNbackground, bgnd,
+				   
+				   NULL);
+  
+  
+  
+  top_box =  XtVaCreateManagedWidget (name,
+				      xmRowColumnWidgetClass,
+				      frame,
+				      
+				      XmNadjustMargin, True,
+				      XmNisHomogeneous, False,
+				      
+				      XtNvisual, visual,
+				      XtNdepth, depth,
+				      XtNcolormap, cmap,
+				      XtNborderColor, borcol,
+				      XtNbackground, bgnd,
+				      
+				      NULL);  
+
+}
+
+G4OpenGLXmTopLevelShell::~G4OpenGLXmTopLevelShell ()
+{
+  XtDestroyWidget (toplevel);
+}
+
+void G4OpenGLXmTopLevelShell::AddChild (G4OpenGLXmVWidgetContainer* container)
+{
+  container->AddYourselfTo (this);
+}
+
+void G4OpenGLXmTopLevelShell::Realize () 
+{
+  Cardinal num_children;
+  XtVaGetValues (toplevel,
+		 XmNnumChildren, &num_children,
+		 NULL);
+//  G4cout << name << " now parents " << num_children << " children." << G4endl;
+  XtManageChild (toplevel);
+  XtRealizeWidget (toplevel);
+  XtPopup (toplevel, XtGrabNonexclusive);
+}
+
+Widget* G4OpenGLXmTopLevelShell::GetPointerToWidget ()
+{
+  return &top_box;
+}
+
+char* G4OpenGLXmTopLevelShell::GetName ()
+{
+  return name;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmVWidgetComponent.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmVWidgetComponent.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmVWidgetComponent.cc	(revision 529)
@@ -0,0 +1,42 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmVWidgetComponent.cc,v 1.5 2006/06/29 21:20:08 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+//Base class for all Motif component widgets
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLXmVWidgetComponent.hh"
+
+G4OpenGLXmVWidgetComponent::G4OpenGLXmVWidgetComponent ()
+{}
+
+G4OpenGLXmVWidgetComponent::~G4OpenGLXmVWidgetComponent ()
+{}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmVWidgetContainer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmVWidgetContainer.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmVWidgetContainer.cc	(revision 529)
@@ -0,0 +1,42 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmVWidgetContainer.cc,v 1.5 2006/06/29 21:20:10 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+//Base class for all Motif container widgets
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLXmVWidgetContainer.hh"
+
+G4OpenGLXmVWidgetContainer::G4OpenGLXmVWidgetContainer ()
+{}
+
+G4OpenGLXmVWidgetContainer::~G4OpenGLXmVWidgetContainer ()
+{}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmVWidgetObject.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmVWidgetObject.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmVWidgetObject.cc	(revision 529)
@@ -0,0 +1,57 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmVWidgetObject.cc,v 1.5 2006/06/29 21:20:12 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+//Virtual base class for all Motif widgets.
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLXmVWidgetObject.hh"
+
+G4OpenGLXmVWidgetObject::G4OpenGLXmVWidgetObject ()
+{}
+
+G4OpenGLXmVWidgetObject::~G4OpenGLXmVWidgetObject ()
+{}
+
+G4OpenGLXmViewer* G4OpenGLXmVWidgetObject::GetView ()
+{
+  return pView;
+}
+
+void G4OpenGLXmVWidgetObject::ProcesspView () 
+{
+  cmap = pView->cmap;
+  depth = pView->vi->depth;
+  visual = pView->vi->visual;
+  borcol = pView->borcol;
+  bgnd = pView->bgnd;
+  top = pView->toplevel;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmVWidgetShell.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmVWidgetShell.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmVWidgetShell.cc	(revision 529)
@@ -0,0 +1,42 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmVWidgetShell.cc,v 1.5 2006/06/29 21:20:14 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+//Base class for all Motif shell widgets
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLXmVWidgetShell.hh"
+
+G4OpenGLXmVWidgetShell::G4OpenGLXmVWidgetShell ()
+{}
+
+G4OpenGLXmVWidgetShell::~G4OpenGLXmVWidgetShell ()
+{}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmViewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmViewer.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmViewer.cc	(revision 529)
@@ -0,0 +1,666 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmViewer.cc,v 1.23 2006/06/29 21:20:16 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Andrew Walkden  10th February 1997
+// G4OpenGLXmViewer : Class derived from G4OpenGLXViewer, to provide
+//                  (Motif) widget OpenGL functionality for GEANT4.
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "globals.hh"
+
+#include "G4OpenGLXmViewer.hh"
+
+#include "G4VisExtent.hh"
+#include "G4LogicalVolume.hh"
+#include "G4VSolid.hh"
+#include "G4Point3D.hh"
+#include "G4Normal3D.hh"
+
+#include "G4OpenGLXmSliderBar.hh"
+
+#include "G4Xt.hh"
+#include <X11/Shell.h>
+
+#include <sstream>
+
+void G4OpenGLXmViewer::ShowView () {
+
+  G4Xt::getInstance () -> SecondaryLoop ();
+
+}
+
+void G4OpenGLXmViewer::GetXmConnection () {
+  
+  G4Xt* interactorManager = G4Xt::getInstance ();
+  toplevel = (Widget)interactorManager->GetMainInteractor();
+  app      = XtWidgetToApplicationContext(toplevel);
+
+  if (!toplevel) {
+    fViewId = -1;  // This flags an error.
+    G4cerr << "G4OpenGLXmViewer::GetXmConnection unable to Initialize"
+      " application context." << G4endl;
+    return;
+  }
+
+  // Better to put this in an X11 resource file !!!
+  std::ostringstream oss;
+  oss <<
+    "*glxarea*width: " << fVP.GetWindowSizeHintX() << "\n"
+    "*glxarea*height: " << fVP.GetWindowSizeHintY() << "\n"
+    /*
+    // Tried this as a replacement for the above two lines, but
+    // sub-windows (rotation, etc.) came same size!!
+    "*geometry: " << fVP.GetXGeometryString() << "\n"
+    */
+    "*frame*x: 10\n"
+    "*frame*y: 10\n"
+    "*frame*topOffset: 10\n"
+    "*frame*bottomOffset: 10\n"
+    "*frame*rightOffset: 10\n"
+    "*frame*leftOffset: 10\n"
+    "*frame*shadowType: SHADOW_IN\n"
+    "*frame*useColorObj: False\n"
+    "*frame*primaryColorSetId: 3\n"
+    "*frame*secondaryColorSetId: 3\n"
+    "*menubar*useColorObj: False\n"
+    "*menubar*primaryColorSetId: 3\n"
+    "*menubar*secondaryColorSetId: 3\n"
+    "*toplevel*useColorObj: False\n"
+    "*toplevel*primaryColorSetId: 3\n"
+    "*toplevel*secondaryColorSetId: 3\n";
+  interactorManager->PutStringInResourceDatabase ((char*)oss.str().c_str());
+
+  //  interactorManager->AddSecondaryLoopPostAction ((G4SecondaryLoopAction)G4OpenGLXmViewerSecondaryLoopPostAction);
+  
+  shell = XtAppCreateShell ((String)fName.data(),(String)fName.data(),topLevelShellWidgetClass,XtDisplay(toplevel),NULL,0); 
+  interactorManager->AddShell (shell);
+
+  dpy = XtDisplay (shell);
+
+  if (!dpy) {
+    fViewId = -1;  // This flags an error.
+    G4cerr << "G4OpenGLXmViewer::GetXmConnection unable to connect to display."
+	 << G4endl;
+    return;
+  }
+
+  if (!glXQueryExtension (dpy, &errorBase, &eventBase)) {
+    fViewId = -1;  // This flags an error.
+    G4cerr << "G4OpenGLXmViewer::GetXmConnection. X Server has no GLX extension."
+	 << G4endl;;
+    return;
+  }
+}
+
+void G4OpenGLXmViewer::CreateMainWindow () {
+
+  bgnd = XWhitePixelOfScreen (XtScreen(shell));
+  borcol = XBlackPixelOfScreen (XtScreen(shell));
+  
+  XtVaSetValues (shell, 
+		 XtNvisual, vi -> visual, 
+       		 XtNdepth, vi -> depth, 
+       		 XtNcolormap, cmap, 
+		 XtNborderColor, &borcol,
+		 XtNbackground, &bgnd,
+		 XmNtitle, fName.data(),
+		 NULL);
+
+  main_win = XtVaCreateManagedWidget ("main_win", 
+				      xmMainWindowWidgetClass,
+				      shell,
+				      XtNvisual, vi -> visual, 
+				      XtNdepth, vi -> depth, 
+				      XtNcolormap, cmap, 
+				      XtNborderColor, borcol,
+				      XtNbackground, bgnd,
+				      NULL);
+
+  //*********Create a menu bar for the window********
+  style_str = XmStringCreateLocalized ((char*)"Style");
+  actions_str = XmStringCreateLocalized ((char*)"Actions");
+  misc_str = XmStringCreateLocalized ((char*)"Miscellany");
+  spec_str = XmStringCreateLocalized ((char*)"Special");
+
+  menubar = XmVaCreateSimpleMenuBar (main_win,
+				     (char*)"menubar",
+				     XmVaCASCADEBUTTON, style_str, 'S',
+				     XmVaCASCADEBUTTON, actions_str, 'A',
+				     XmVaCASCADEBUTTON, misc_str, 'M',
+				     XmVaCASCADEBUTTON, spec_str, 'p',
+				     XtNvisual, vi -> visual, 
+				     XtNdepth, vi -> depth, 
+				     XtNcolormap, cmap, 
+				     XtNborderColor, borcol,
+				     XtNbackground, bgnd,
+				     NULL);
+
+  XmStringFree (style_str);
+  XmStringFree (actions_str);
+  XmStringFree (misc_str);
+  XmStringFree (spec_str);
+
+  G4cout << "Created menubar" << G4endl;
+
+
+  //*********Create style pulldown menu on menubar*********
+  rep_str = XmStringCreateLocalized ((char*)"Representation");
+  draw_str = XmStringCreateLocalized ((char*)"Drawing");
+  bgnd_str = XmStringCreateLocalized ((char*)"Background color");
+
+  style_cascade = XmVaCreateSimplePulldownMenu
+    (menubar,
+     (char*)"style",
+     0,
+     NULL,
+     XmVaCASCADEBUTTON, rep_str, 'R',
+     XmVaCASCADEBUTTON, draw_str, 'D',
+     XmVaCASCADEBUTTON, bgnd_str, 'B',
+     XtNvisual, vi -> visual, 
+     XtNdepth, vi -> depth, 
+     XtNcolormap, cmap, 
+     XtNborderColor, borcol,
+     XtNbackground, bgnd,
+     NULL);
+  
+  XmStringFree (rep_str);
+  XmStringFree (draw_str);
+  XmStringFree (bgnd_str);
+
+  //  G4cout << "Created Style pulldown menu" << G4endl;
+
+  //Add Representation pullright menu to style cascade...
+  polyhedron_str = XmStringCreateLocalized ((char*)"Polyhedron");
+  nurbs_str = XmStringCreateLocalized ((char*)"NURBS");
+
+  rep_style_pullright = XmVaCreateSimplePulldownMenu 
+    (style_cascade,
+     (char*)"rep_style",
+     0,
+     rep_style_callback,
+     XmVaRADIOBUTTON, polyhedron_str, 'P', NULL, NULL,
+     XmVaRADIOBUTTON, nurbs_str, 'N', NULL, NULL,
+     XmNradioBehavior, True, 
+     XmNradioAlwaysOne, True, 
+     XmNuserData, this, 
+     XtNvisual, vi -> visual, 
+     XtNdepth, vi -> depth, 
+     XtNcolormap, cmap, 
+     XtNborderColor, borcol,
+     XtNbackground, bgnd,
+     NULL);
+  
+  Widget special_widget;
+
+  G4ViewParameters::RepStyle style;
+  style = fVP.GetRepStyle();
+  
+  if (style == G4ViewParameters::polyhedron) {
+    special_widget = XtNameToWidget(rep_style_pullright, "button_0");
+    if(special_widget) {
+      XtVaSetValues (special_widget, XmNset, True, NULL);
+    }
+  } else if (style == G4ViewParameters::nurbs) {
+    special_widget = XtNameToWidget(rep_style_pullright, "button_1");
+    if(special_widget) {
+      XtVaSetValues (special_widget, XmNset, True, NULL);
+    }
+  } else {
+    G4Exception("Invalid Representation style in G4OpenGLXmViewer::CreateContext");
+  }
+  XmStringFree (polyhedron_str);
+  XmStringFree (nurbs_str);
+  
+  //  G4cout << "Created Representation pulldown menu" << G4endl;
+
+  //Add Drawing pullright menu to style cascade...
+  wireframe_str = XmStringCreateLocalized ((char*)"Wireframe");
+  hlr_str = XmStringCreateLocalized ((char*)"Hidden line removal");
+  hsr_str = XmStringCreateLocalized ((char*)"Hidden surface removal");
+  hlhsr_str = XmStringCreateLocalized ((char*)"Hidden line and surface removal");
+
+  drawing_style_pullright = XmVaCreateSimplePulldownMenu 
+    (style_cascade,
+     (char*)"drawing_style",
+     1,
+     drawing_style_callback,
+     XmVaRADIOBUTTON, wireframe_str, 'W', NULL, NULL,
+     XmVaRADIOBUTTON, hlr_str, 'L', NULL, NULL,
+     XmVaRADIOBUTTON, hsr_str, 'S', NULL, NULL,
+     XmVaRADIOBUTTON, hlhsr_str, 'H', NULL, NULL,
+     XmNradioBehavior, True, 
+     XmNradioAlwaysOne, True, 
+     XmNuserData, this,
+     XtNvisual, vi -> visual, 
+     XtNdepth, vi -> depth, 
+     XtNcolormap, cmap, 
+     XtNborderColor, borcol,
+     XtNbackground, bgnd,
+     NULL);
+  
+  G4ViewParameters::DrawingStyle d_style;
+  d_style = fVP.GetDrawingStyle();
+  
+  if (d_style == G4ViewParameters::wireframe) {
+    special_widget = XtNameToWidget(drawing_style_pullright, "button_0");
+    if(special_widget) {
+      XtVaSetValues (special_widget, XmNset, True, NULL);
+    }
+  } else if (d_style == G4ViewParameters::hlr) {
+    special_widget = XtNameToWidget(drawing_style_pullright, "button_1");
+    if(special_widget) {
+      XtVaSetValues (special_widget, XmNset, True, NULL);
+    }
+  } else if (d_style == G4ViewParameters::hsr) {
+    special_widget = XtNameToWidget(drawing_style_pullright, "button_2");
+    if(special_widget) {
+      XtVaSetValues (special_widget, XmNset, True, NULL);
+    }
+  } else if (d_style == G4ViewParameters::hlhsr) {
+    special_widget = XtNameToWidget(drawing_style_pullright, "button_3");
+    if(special_widget) {
+      XtVaSetValues (special_widget, XmNset, True, NULL);
+    }
+  } else {
+    G4Exception("Invalid Drawing style in G4OpenGLXmViewer::CreateContext");
+  }
+
+  XmStringFree (wireframe_str);
+  XmStringFree (hlr_str);
+  XmStringFree (hsr_str);
+  XmStringFree (hlhsr_str);
+
+  //  G4cout << "Created Drawing pullright menu" << G4endl;
+
+  //Add Drawing pullright menu to style cascade...
+  white_str = XmStringCreateLocalized ((char*)"White");
+  black_str = XmStringCreateLocalized ((char*)"Black");
+
+  background_color_pullright = XmVaCreateSimplePulldownMenu 
+    (style_cascade,
+     (char*)"background_color",
+     2,
+     background_color_callback,
+     XmVaRADIOBUTTON, white_str, 'W', NULL, NULL,
+     XmVaRADIOBUTTON, black_str, 'B', NULL, NULL,
+     XmNradioBehavior, True, 
+     XmNradioAlwaysOne, True, 
+     XmNuserData, this,
+     XtNvisual, vi -> visual, 
+     XtNdepth, vi -> depth, 
+     XtNcolormap, cmap, 
+     XtNborderColor, borcol,
+     XtNbackground, bgnd,
+     NULL);
+  
+  if (background.GetRed() == 1. &&
+      background.GetGreen() == 1. &&
+      background.GetBlue() == 1.) {
+    special_widget = XtNameToWidget(background_color_pullright, "button_0");
+    if(special_widget) {
+      XtVaSetValues (special_widget, XmNset, True, NULL);
+    }
+  } else {
+    special_widget = XtNameToWidget(background_color_pullright, "button_1");
+    if(special_widget) {
+      XtVaSetValues (special_widget, XmNset, True, NULL);
+    }
+  }
+
+  XmStringFree (white_str);
+  XmStringFree (black_str);
+
+  //  G4cout << "Created Background color pullright menu" << G4endl;
+
+  //*********Create actions pulldown menu on menubar*********
+  rot_str = XmStringCreateLocalized ((char*)"Rotation control panel");
+  pan_str = XmStringCreateLocalized ((char*)"Panning control panel");
+  set_str = XmStringCreateLocalized ((char*)"Set control panel limits");
+
+  actions_cascade = XmVaCreateSimplePulldownMenu
+    (menubar,
+     (char*)"actions",
+     1,
+     actions_callback,
+     XmVaPUSHBUTTON, rot_str, 'R', NULL, NULL,
+     XmVaPUSHBUTTON, pan_str, 'P', NULL, NULL,
+     XmVaPUSHBUTTON, set_str, 'S', NULL, NULL,
+     XmNuserData, this, 
+     XtNvisual, vi -> visual, 
+     XtNdepth, vi -> depth, 
+     XtNcolormap, cmap, 
+     XtNborderColor, borcol,
+     XtNbackground, bgnd,
+     NULL);
+  
+  XmStringFree (rot_str);
+  XmStringFree (pan_str);
+  XmStringFree (set_str);
+  G4cout << "Created Actions pulldown menu" << G4endl;
+
+  misc_str = XmStringCreateLocalized ((char*)"Miscellany control panel");
+  exit_str = XmStringCreateLocalized ((char*)"Exit to G4Vis>");
+  print_str = XmStringCreateLocalized ((char*)"Create .eps file");
+
+  //*********Create miscellany pulldown menu on menubar*********
+  misc_cascade = XmVaCreateSimplePulldownMenu
+    (menubar,
+     (char*)"miscellany",
+     2,
+     misc_callback,
+     XmVaPUSHBUTTON, misc_str, 'M', NULL, NULL,
+     XmVaPUSHBUTTON, exit_str, 'E', NULL, NULL,
+     XmVaPUSHBUTTON, print_str, 'P', NULL, NULL,
+     XmNuserData, this,
+     XtNvisual, vi -> visual, 
+     XtNdepth, vi -> depth, 
+     XtNcolormap, cmap, 
+     XtNborderColor, borcol,
+     XtNbackground, bgnd,
+     NULL);
+  
+  XmStringFree (misc_str);
+  XmStringFree (exit_str);
+  XmStringFree (print_str);
+  G4cout << "Created Miscellany pulldown menu" << G4endl;
+
+  trans_str = XmStringCreateLocalized ((char*)"Transparency");
+  anti_str = XmStringCreateLocalized ((char*)"Antialiasing");
+  halo_str = XmStringCreateLocalized ((char*)"Haloing");
+  aux_edge_str = XmStringCreateLocalized ((char*)"Auxiliary edges");
+
+  //*********Create special pulldown menu on menubar*********
+  spec_cascade = XmVaCreateSimplePulldownMenu
+    (menubar,
+     (char*)"special",
+     3,
+     NULL,
+     XmVaCASCADEBUTTON, trans_str, 'T',
+     XmVaCASCADEBUTTON, anti_str, 'A',
+     XmVaCASCADEBUTTON, halo_str, 'H',
+     XmVaCASCADEBUTTON, aux_edge_str, 'E',
+     XtNvisual, vi -> visual, 
+     XtNdepth, vi -> depth, 
+     XtNcolormap, cmap, 
+     XtNborderColor, borcol,
+     XtNbackground, bgnd,
+     NULL);
+  
+  XmStringFree (trans_str);
+  XmStringFree (anti_str);
+  XmStringFree (halo_str);
+  XmStringFree (aux_edge_str);
+
+  //  G4cout << "Created Special pulldown menu" << G4endl;
+
+  //Add Transparency pullright menu to special cascade...
+  off_str = XmStringCreateLocalized ((char*)"Off");
+  on_str = XmStringCreateLocalized ((char*)"On");
+
+  transparency_pullright = XmVaCreateSimplePulldownMenu 
+    (spec_cascade,
+     (char*)"transparency",
+     0,
+     transparency_callback,
+     XmVaRADIOBUTTON, off_str, 'f', NULL, NULL,
+     XmVaRADIOBUTTON, on_str, 'n', NULL, NULL,
+     XmNradioBehavior, True, 
+     XmNradioAlwaysOne, True, 
+     XmNuserData, this,
+     XtNvisual, vi -> visual, 
+     XtNdepth, vi -> depth, 
+     XtNcolormap, cmap, 
+     XtNborderColor, borcol,
+     XtNbackground, bgnd,
+     NULL);
+  
+  if (transparency_enabled == false) {
+    special_widget = XtNameToWidget(transparency_pullright, "button_0");
+    if(special_widget) {
+      XtVaSetValues (special_widget, XmNset, True, NULL);
+    }
+  } else if (transparency_enabled == true) {
+    special_widget = XtNameToWidget(transparency_pullright, "button_1");
+    if(special_widget) {
+      XtVaSetValues (special_widget, XmNset, True, NULL);
+    }
+  } else {
+    G4Exception("transparency_enabled in G4OpenGLXmViewer is neither true nor false!!");
+  }
+
+  //Add antialias pullright menu to special cascade...
+  antialias_pullright = XmVaCreateSimplePulldownMenu 
+    (spec_cascade,
+     (char*)"antialias",
+     1,
+     antialias_callback,
+     XmVaRADIOBUTTON, off_str, 'f', NULL, NULL,
+     XmVaRADIOBUTTON, on_str, 'n', NULL, NULL,
+     XmNradioBehavior, True, 
+     XmNradioAlwaysOne, True, 
+     XmNuserData, this,
+     XtNvisual, vi -> visual, 
+     XtNdepth, vi -> depth, 
+     XtNcolormap, cmap, 
+     XtNborderColor, borcol,
+     XtNbackground, bgnd,
+     NULL);
+  
+  if (antialiasing_enabled == false) {
+    special_widget = XtNameToWidget(antialias_pullright, "button_0");
+    if(special_widget) {
+      XtVaSetValues (special_widget, XmNset, True, NULL);
+    }
+  } else if (antialiasing_enabled == true) {
+    special_widget = XtNameToWidget(antialias_pullright, "button_1");
+    if(special_widget) {
+      XtVaSetValues (special_widget, XmNset, True, NULL);
+    }
+  } else {
+    G4Exception("antialiasing_enabled in G4OpenGLXmViewer is neither true nor false!!");
+  }
+
+  //Add Haloing pullright menu to special cascade...
+  haloing_pullright = XmVaCreateSimplePulldownMenu 
+    (spec_cascade,
+     (char*)"haloing",
+     2,
+     haloing_callback,
+     XmVaRADIOBUTTON, off_str, 'f', NULL, NULL,
+     XmVaRADIOBUTTON, on_str, 'n', NULL, NULL,
+     XmNradioBehavior, True, 
+     XmNradioAlwaysOne, True, 
+     XmNuserData, this,
+     XtNvisual, vi -> visual, 
+     XtNdepth, vi -> depth, 
+     XtNcolormap, cmap, 
+     XtNborderColor, borcol,
+     XtNbackground, bgnd,
+     NULL);
+  
+  if (haloing_enabled == false) {
+    special_widget = XtNameToWidget(haloing_pullright, "button_0");
+    if(special_widget) {
+      XtVaSetValues (special_widget, XmNset, True, NULL);
+    }
+  } else if (haloing_enabled == true) {
+    special_widget = XtNameToWidget(haloing_pullright, "button_1");
+    if(special_widget) {
+      XtVaSetValues (special_widget, XmNset, True, NULL);
+    }
+  } else {
+    G4Exception("haloing_enabled in G4OpenGLXmViewer is neither true nor false!!");
+  }
+
+  //Add Aux_Edge pullright menu to special cascade...
+  aux_edge_pullright = XmVaCreateSimplePulldownMenu 
+    (spec_cascade,
+     (char*)"aux_edge",
+     3,
+     aux_edge_callback,
+     XmVaRADIOBUTTON, off_str, 'f', NULL, NULL,
+     XmVaRADIOBUTTON, on_str, 'n', NULL, NULL,
+     XmNradioBehavior, True, 
+     XmNradioAlwaysOne, True, 
+     XmNuserData, this,
+     XtNvisual, vi -> visual, 
+     XtNdepth, vi -> depth, 
+     XtNcolormap, cmap, 
+     XtNborderColor, borcol,
+     XtNbackground, bgnd,
+     NULL);
+  
+  if (!fVP.IsAuxEdgeVisible()) {
+    special_widget = XtNameToWidget(aux_edge_pullright, "button_0");
+    if(special_widget) {
+      XtVaSetValues (special_widget, XmNset, True, NULL);
+    }
+  } else {
+    special_widget = XtNameToWidget(aux_edge_pullright, "button_1");
+    if(special_widget) {
+      XtVaSetValues (special_widget, XmNset, True, NULL);
+    }
+  }
+
+  XtManageChild (menubar);
+  frame = XtVaCreateManagedWidget ((char*)"frame",
+				   xmFrameWidgetClass, main_win,
+				   XtNvisual, vi -> visual, 
+				   XtNdepth, vi -> depth, 
+				   XtNcolormap, cmap, 
+				   XtNborderColor, borcol,
+				   XtNbackground, bgnd,
+				   NULL);
+
+  glxarea = XtVaCreateManagedWidget ((char*)"glxarea", 
+				     xmDrawingAreaWidgetClass,
+				     frame,
+				     XtNvisual, vi -> visual, 
+				     XtNdepth, vi -> depth, 
+				     XtNcolormap, cmap, 
+				     XtNborderColor, borcol,
+				     XtNbackground, bgnd,
+				     NULL);
+  
+  XtAddCallback (glxarea, 
+		 XmNexposeCallback, 
+		 expose_callback, 
+		 this);
+
+  XtAddCallback (glxarea, 
+		 XmNresizeCallback, 
+		 resize_callback, 
+		 this);
+
+  XmMainWindowSetAreas (main_win,  // main widget, children are specified 
+			menubar,   // widget to use as menu bar
+			NULL,      // widget to use as command window
+			NULL,      // widget for horizontal scroll bar
+			NULL,      // widget for vertical scroll bar
+			frame      // widget to be used for work window
+			);
+
+  XtRealizeWidget(shell);
+  
+  // Once widget is realized (ie, associated with a created X window), we
+  // can bind the OpenGL rendering context to the window.
+
+  Dimension width, height;
+  XtVaGetValues (glxarea,XmNwidth,&width,XmNheight,&height,NULL);
+  WinSize_x = (G4int) width;
+  WinSize_y = (G4int) height;
+
+  win = XtWindow (glxarea);
+
+  glXMakeCurrent (dpy, win, cx);
+
+}
+
+G4OpenGLXmViewer::G4OpenGLXmViewer (G4OpenGLSceneHandler& scene):
+G4VViewer (scene, -1),
+G4OpenGLViewer (scene),
+G4OpenGLXViewer (scene),
+zoom_high (fVP.GetZoomFactor() * 10.0),
+zoom_low (fVP.GetZoomFactor() / 10.0),
+dolly_low (fVP.GetDolly() - 1000.0),
+dolly_high (fVP.GetDolly() + 1000.0),
+fov (0.0),
+rot_sens_limit (90.),
+pan_sens_limit (100.),
+rot_sens (4.),
+wob_sens (20.),
+original_vp(fVP.GetViewpointDirection()),
+frameNo (0),
+fprotation_top (0),
+fprotation_slider (0),
+fppanning_top (0),
+fppanning_slider (0),
+fpzoom_slider (0),
+fpdolly_slider (0),
+fpsetting_top (0),
+fpmiscellany_top (0),
+fpprint_top (0)
+{
+  WinSize_x = 100;
+  WinSize_y = 100;
+  
+  GetXmConnection ();
+  if (fViewId < 0) return;
+}
+
+G4OpenGLXmViewer::~G4OpenGLXmViewer ()
+{
+  XtDestroyWidget  (shell);
+  win = 0; // ...to avoid XDestroyWindow in G4OpenGLXViewer base class
+  // because XtDestroyWidget has already destroyed it.
+  G4Xt::getInstance () ->RemoveShell (shell);
+
+/******************************
+  if (fprotation_top) {
+    delete fprotation_top;
+  }
+
+  if (fppanning_top) {
+    delete fppanning_top;
+  }
+
+  if (fpsetting_top) {
+    delete fpsetting_top;
+  }
+
+  if (fpmiscellany_top) {
+    delete fpmiscellany_top;
+  }
+******************************/
+
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmViewerMessenger.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmViewerMessenger.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmViewerMessenger.cc	(revision 529)
@@ -0,0 +1,280 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmViewerMessenger.cc,v 1.4 2006/06/29 21:20:18 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLXmViewerMessenger.hh"
+
+#include "G4OpenGLXmViewer.hh"
+#include "G4OpenGLXmSliderBar.hh"
+
+#include "G4UImanager.hh"
+#include "G4UIcommand.hh"
+#include "G4UIdirectory.hh"
+#include "G4UIcmdWithADoubleAndUnit.hh"
+#include "G4UIcmdWithADouble.hh"
+
+#include "G4VisManager.hh"
+
+G4OpenGLXmViewerMessenger* G4OpenGLXmViewerMessenger::fpInstance = 0;
+
+G4OpenGLXmViewerMessenger* G4OpenGLXmViewerMessenger::GetInstance()
+{
+  if (!fpInstance) fpInstance = new G4OpenGLXmViewerMessenger;
+  return fpInstance;
+}
+
+G4OpenGLXmViewerMessenger::G4OpenGLXmViewerMessenger()
+{
+  G4bool omitable;
+
+  fpDirectory = new G4UIdirectory("/vis/oglxm/");
+  fpDirectory->SetGuidance("G4OpenGLXmViewer commands.");
+
+  fpDirectorySet = new G4UIdirectory ("/vis/oglxm/set/");
+  fpDirectorySet->SetGuidance("G4OpenGLXmViewer set commands.");
+
+  fpCommandSetDollyHigh =
+    new G4UIcmdWithADoubleAndUnit("/vis/oglxm/set/dolly-high", this);
+  fpCommandSetDollyHigh->SetGuidance("Higher limit of dolly slider.");
+  fpCommandSetDollyHigh->SetParameterName("dolly-high", omitable = false);
+
+  fpCommandSetDollyLow =
+    new G4UIcmdWithADoubleAndUnit("/vis/oglxm/set/dolly-low", this);
+  fpCommandSetDollyLow->SetGuidance("Lower limit of dolly slider.");
+  fpCommandSetDollyLow->SetParameterName("dolly-low", omitable = false);
+
+  fpCommandSetPanHigh =
+    new G4UIcmdWithADoubleAndUnit("/vis/oglxm/set/pan-high", this);
+  fpCommandSetPanHigh->SetGuidance("Higher limit of pan slider.");
+  fpCommandSetPanHigh->SetParameterName("pan-high", omitable = false);
+
+  fpCommandSetRotationHigh =
+    new G4UIcmdWithADoubleAndUnit("/vis/oglxm/set/rotation-high", this);
+  fpCommandSetRotationHigh->SetGuidance("Higher limit of rotation slider.");
+  fpCommandSetRotationHigh->SetParameterName("rotation-high", omitable = false);
+
+  fpCommandSetZoomHigh =
+    new G4UIcmdWithADouble("/vis/oglxm/set/zoom-high", this);
+  fpCommandSetZoomHigh->SetGuidance("Higher limit of zoom slider.");
+  fpCommandSetZoomHigh->SetParameterName("zoom-high", omitable = false);
+
+  fpCommandSetZoomLow =
+    new G4UIcmdWithADouble("/vis/oglxm/set/zoom-low", this);
+  fpCommandSetZoomLow->SetGuidance("Lower limit of zoom slider.");
+  fpCommandSetZoomLow->SetParameterName("zoom-low", omitable = false);
+}
+
+G4OpenGLXmViewerMessenger::~G4OpenGLXmViewerMessenger ()
+{
+  delete fpCommandSetZoomLow;
+  delete fpCommandSetZoomHigh;
+  delete fpCommandSetRotationHigh;
+  delete fpCommandSetPanHigh;
+  delete fpCommandSetDollyLow;
+  delete fpCommandSetDollyHigh;
+  delete fpDirectorySet;
+  delete fpDirectory;
+}
+
+void G4OpenGLXmViewerMessenger::SetNewValue
+(G4UIcommand* command, G4String newValue)
+{
+  G4VisManager* pVisManager = G4VisManager::GetInstance();
+
+  G4VViewer* pVViewer = pVisManager->GetCurrentViewer();
+
+  if (!pVViewer) {
+    G4cout <<
+      "G4OpenGLXmViewerMessenger::SetNewValue: No current viewer."
+      "\n  \"/vis/open\", or similar, to get one."
+           << G4endl;
+    return;
+  }
+
+  G4OpenGLXmViewer* pViewer = dynamic_cast<G4OpenGLXmViewer*>(pVViewer);
+
+  if (!pViewer) {
+    G4cout <<
+      "G4OpenGLXmViewerMessenger::SetNewValue: Current viewer is not of type"
+      "\n  OGLIXm or OGLSXm.  Use \"/vis/viewer/select\" or \"/vis/open\"."
+           << G4endl;
+    return;
+  }
+
+  G4bool panningControlPanel = true;
+  G4bool rotationControlPanel = true;
+
+  if (command == fpCommandSetDollyHigh)
+    {
+      if (pViewer->fpdolly_slider)
+	{
+	  pViewer->dolly_high =
+	    fpCommandSetDollyHigh->GetNewDoubleValue(newValue);
+	  pViewer->fpdolly_slider->SetMaxValue (pViewer->dolly_high);
+	  if (pViewer->fVP.GetDolly() > pViewer->dolly_high)
+	    {
+	      pViewer->fpdolly_slider->SetInitialValue (pViewer->dolly_high);
+	      pViewer->fVP.SetDolly(pViewer->dolly_high);
+	    }
+	  else
+	    {
+	      pViewer->fpdolly_slider->SetInitialValue (pViewer->fVP.GetDolly());
+	    }
+	}
+      else
+	{
+	  panningControlPanel = false;
+	}
+    }
+
+  else if (command == fpCommandSetDollyLow)
+    {
+      if (pViewer->fpdolly_slider)
+	{
+	  pViewer->dolly_low =
+	    fpCommandSetDollyLow->GetNewDoubleValue(newValue);
+	  pViewer->fpdolly_slider->SetMinValue (pViewer->dolly_low);
+	  if (pViewer->fVP.GetDolly() < pViewer->dolly_low)
+	    {
+	      pViewer->fpdolly_slider->SetInitialValue (pViewer->dolly_low);
+	      pViewer->fVP.SetDolly(pViewer->dolly_low);
+	    }
+	  else
+	    {
+	      pViewer->fpdolly_slider->SetInitialValue (pViewer->fVP.GetDolly());
+	    }
+	}
+      else
+	{
+	  panningControlPanel = false;
+	}
+    }
+
+  else if (command == fpCommandSetPanHigh)
+    {
+      if (pViewer->fppanning_slider)
+	{
+	  pViewer->pan_sens_limit =
+	    fpCommandSetPanHigh->GetNewDoubleValue(newValue);
+	  pViewer->fppanning_slider->SetMaxValue (pViewer->pan_sens_limit);
+	  pViewer->fppanning_slider->SetInitialValue (pViewer->pan_sens_limit / 2.);
+	}
+      else
+	{
+	  panningControlPanel = false;
+	}
+    }
+
+  else if (command == fpCommandSetRotationHigh)
+    {
+      if (pViewer->fprotation_slider)
+	{
+	  // Internally in OpenGLXm, it's in degrees...
+	  pViewer->rot_sens_limit =
+	    fpCommandSetRotationHigh->GetNewDoubleValue(newValue) / deg;
+	  pViewer->fprotation_slider->SetMaxValue (pViewer->rot_sens_limit);
+	  pViewer->fprotation_slider->SetInitialValue (pViewer->rot_sens_limit / 2.);
+	}
+      else
+	{
+	  rotationControlPanel = false;
+	}
+    }
+
+  else if (command == fpCommandSetZoomHigh)
+    {
+      if (pViewer->fpzoom_slider)
+	{
+	  pViewer->zoom_high =
+	    fpCommandSetZoomHigh->GetNewDoubleValue(newValue);
+	  pViewer->fpzoom_slider->SetMaxValue (pViewer->zoom_high);
+	  pViewer->fpzoom_slider->SetInitialValue (pViewer->fVP.GetZoomFactor());
+	  if (pViewer->fVP.GetZoomFactor() > pViewer->zoom_high)
+	    {
+	      pViewer->fpzoom_slider->SetInitialValue (pViewer->zoom_high);
+	      pViewer->fVP.SetZoomFactor(pViewer->zoom_high);
+	    }
+	  else
+	    {
+	      pViewer->fpzoom_slider->SetInitialValue (pViewer->fVP.GetZoomFactor());
+	    }
+	}
+      else
+	{
+	  panningControlPanel = false;
+	}
+    }
+
+  else if (command == fpCommandSetZoomLow)
+    {
+      if (pViewer->fpzoom_slider)
+	{
+	  pViewer->zoom_low =
+	    fpCommandSetZoomLow->GetNewDoubleValue(newValue);
+	  pViewer->fpzoom_slider->SetMinValue (pViewer->zoom_low);
+	  pViewer->fpzoom_slider->SetInitialValue (pViewer->fVP.GetZoomFactor());
+	  if (pViewer->fVP.GetZoomFactor() < pViewer->zoom_low)
+	    {
+	      pViewer->fpzoom_slider->SetInitialValue (pViewer->zoom_low);
+	      pViewer->fVP.SetZoomFactor(pViewer->zoom_low);
+	    }
+	  else
+	    {
+	      pViewer->fpzoom_slider->SetInitialValue (pViewer->fVP.GetZoomFactor());
+	    }
+	}
+      else
+	{
+	  panningControlPanel = false;
+	}
+    }
+
+  if (!panningControlPanel)
+    {
+	  G4cout << 
+	    "G4OpenGLXmViewerMessenger::SetNewValue: pull down panning"
+	    "\n  control panel and re-issue command."
+		 << G4endl;
+	  return;
+    }
+
+  if (!rotationControlPanel)
+    {
+	  G4cout << 
+	    "G4OpenGLXmViewerMessenger::SetNewValue: pull down rotation"
+	    "\n  control panel and re-issue command."
+		 << G4endl;
+	  return;
+    }
+
+  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/rebuild");
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmWindowHandlingCallbacks.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmWindowHandlingCallbacks.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLXmWindowHandlingCallbacks.cc	(revision 529)
@@ -0,0 +1,114 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenGLXmWindowHandlingCallbacks.cc,v 1.6 2006/06/29 21:20:20 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Andrew Walkden  16th June 1997
+// G4OpenGLXmWindowHandlingCallbacks : Callback functions for
+//                                     (Motif) widgets to use.
+//                                     in handling (Xm) windows
+
+#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
+
+#include "G4OpenGLXmViewer.hh"
+
+void G4OpenGLXmViewer::resize_callback (Widget w, 
+				      XtPointer clientData, 
+				      XtPointer) 
+{
+  Dimension width, height;
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
+  
+  XtVaGetValues (w, 
+		 XmNwidth, &width, 
+		 XmNheight, &height, 
+		 NULL);
+  
+  pView->WinSize_x = (G4int) width;
+  pView->WinSize_y = (G4int) height;
+}
+
+
+
+void G4OpenGLXmViewer::expose_callback (Widget w, 
+				      XtPointer clientData, 
+				      XtPointer) 
+{
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
+  Dimension width, height;
+
+  XtVaGetValues (w, 
+		 XmNwidth, &width, 
+		 XmNheight, &height, 
+		 NULL);
+
+  pView->WinSize_x = (G4int) width;
+  pView->WinSize_y = (G4int) height;
+
+  glXMakeCurrent (pView->dpy, XtWindow(pView->glxarea), pView->cx);
+  glViewport (0, 0, width, height);
+
+  pView->ClearView ();
+  pView->DrawView ();
+}
+
+void G4OpenGLXmViewer::print_callback (Widget, 
+				    XtPointer clientData, 
+				    XtPointer) 
+{
+  G4OpenGLXViewer* pView = (G4OpenGLXmViewer*) clientData;
+  pView->print();
+}
+
+void G4OpenGLXmViewer::set_print_colour_callback (Widget w,
+						XtPointer clientData,
+						XtPointer) 
+{
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData;
+  
+  G4int choice = get_int_userData (w);
+  
+  pView->print_colour=(G4bool)choice;
+  G4cout << "Print colour set to " << pView->print_colour;
+  
+}
+
+void G4OpenGLXmViewer::set_print_style_callback (Widget w,
+					       XtPointer clientData,
+					       XtPointer) 
+{
+  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData;
+  
+  G4int choice = get_int_userData (w);
+  
+  pView->vectored_ps=(G4bool)choice;
+  G4cout << "`Produce vectored PostScript ?' set to : " << pView->print_colour;
+  
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/GNUmakefile
===================================================================
--- /trunk/geant4/visualization/OpenInventor/GNUmakefile	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/GNUmakefile	(revision 529)
@@ -0,0 +1,38 @@
+# $Id: GNUmakefile,v 1.8 2006/11/02 12:02:23 allison Exp $
+
+name := G4OpenInventor
+
+ifndef G4INSTALL
+  G4INSTALL = ../../..
+endif
+
+GLOBLIBS  = libG4vis_management.lib libG4modeling.lib
+GLOBLIBS += libG4interfaces.lib libG4run.lib libG4event.lib
+GLOBLIBS += libG4tracking.lib libG4processes.lib libG4digits_hits.lib
+GLOBLIBS += libG4track.lib libG4particles.lib libG4geometry.lib
+GLOBLIBS += libG4materials.lib libG4graphics_reps.lib
+GLOBLIBS += libG4intercoms.lib libG4global.lib
+
+include $(G4INSTALL)/config/architecture.gmk
+include $(G4INSTALL)/config/G4VIS_BUILD.gmk
+include $(G4INSTALL)/config/interactivity.gmk
+
+CPPFLAGS += -I$(G4BASE)/visualization/management/include
+CPPFLAGS += -I$(G4BASE)/visualization/modeling/include
+CPPFLAGS += -I$(G4BASE)/global/management/include
+CPPFLAGS += -I$(G4BASE)/global/HEPGeometry/include
+CPPFLAGS += -I$(G4BASE)/geometry/solids/CSG/include
+CPPFLAGS += -I$(G4BASE)/geometry/solids/specific/include
+CPPFLAGS += -I$(G4BASE)/graphics_reps/include
+CPPFLAGS += -I$(G4BASE)/geometry/management/include
+CPPFLAGS += -I$(G4BASE)/interfaces/common/include
+CPPFLAGS += -I$(G4BASE)/intercoms/include
+CPPFLAGS += -I$(G4BASE)/materials/include
+CPPFLAGS += -I$(G4BASE)/global/HEPRandom/include
+CPPFLAGS += -I$(G4BASE)/tracking/include
+CPPFLAGS += -I$(G4BASE)/digits_hits/hits/include
+
+include $(G4INSTALL)/config/common.gmk
+
+debug:
+	@echo $(CPPFLAGS)
Index: /trunk/geant4/visualization/OpenInventor/History
===================================================================
--- /trunk/geant4/visualization/OpenInventor/History	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/History	(revision 529)
@@ -0,0 +1,359 @@
+$Id: History,v 1.90 2006/11/05 20:49:09 allison Exp $
+-------------------------------------------------------------------
+
+     =========================================================
+     Geant4 - an Object-Oriented Toolkit for Simulation in HEP
+     =========================================================
+
+                      Category History file
+                      ---------------------
+This file should be used by G4 developers and category coordinators
+to briefly summarize all major modifications introduced in the code
+and keep track of all category-tags.
+It DOES NOT substitute the  CVS log-message one should put at every
+committal in the CVS repository !
+
+     ----------------------------------------------------------
+     * Reverse chronological order (last date on top), please *
+     ----------------------------------------------------------
+
+History file for visualization/OpenInventor
+-------------------------------------------
+
+5th November 2006  John Allison  (openinventor-V08-01-04)
+- Protected against zero material pointer.
+
+2nd November 2006  John Allison  (openinventor-V08-01-03)
+- Rationalised G4Att loading and extended picking to hits.
+
+1st November 2006  John Allison  (openinventor-V08-01-02)
+- Follow changes to greps-V08-01-09: G4AttCheck/Holder rationalisation.
+
+26th October 2006  John Allison  (openinventor-V08-01-01)
+- Added SoG4LineSet, SoG4MarkerSet and SoG4Polyhedron - classes extended to
+  include G4Atts (G4AttValues and G4AttDefs) for picking.
+- G4OpenInventorSceneHandler.cc: Load lines, markers and polyhedron objects
+  with G4Atts.
+- G4OpenInventorViewer.cc: print G4Atts on picking.
+
+29th August 2006  John Allison  (openinventor-V08-01-00)
+- G4OpenInventorViewer::CompareForKernelVisit: Rationalisation. This
+  assumes use of generic clipping (sectioning, slicing, DCUT,
+  cutaway).  If a decision is made to implement locally, this will
+  need changing.  See G4OpenGLViewer::SetView,
+  G4OpenGLStoredViewer.cc::CompareForKernelVisit and
+  G4OpenGLStoredSceneHander::CreateSection/CutawayPolyhedron.
+
+4th June 2006 Joseph Perl (openinventor-V08-00-05)
+- This tag includes all the changes below.
+
+2 June 2006  Guy Barrand :
+- G4OpenInvenot, G4OpenInvenotXt, G4OpenInvenotWin : have an Initialize 
+  method in order to init Xt and Inventor only is really used 
+  (when creating a viewer or a scene handler).
+
+19th April 2006  Gabriele Cosmo  (openinventor-V08-00-04)
+- Use cmath instead of math.h.
+
+28th March John Allison  (openinventor-V08-00-03)
+- Cosmetic.
+
+21st March John Allison  (openinventor-V08-00-02)
+- Rationalised G4OpenInventorSceneHandler:
+  o Introduced GeneratePrerequisites.
+  o Uses dynamic_cast<G4PhysicalVolumeModel*>(fpModel) instead
+    of fpCurrentPV, etc.
+  o Uses G4VSceneHandler utility functions,
+    GetApplicableVisAttributes, GetColour, GetTextColour,
+    GetMarkerSize, GetDrawingStyle, GetAuxEdgeVisible, where possible.
+  o Revision 1.43: messy version with original code commented out.
+  o Revision 1.44 (.cc) and 1.28 (.hh) (tagged): tidied versions.
+- Investigated G4OpenInventorViewer:
+  o Changed: DrawDetector and UpdateScene.  No noticeable effect!
+
+20th March John Allison
+- G4OpenInventorSceneHandler:
+  o Bug fix for transient solids.
+  o Replaced some code in AddPrimitive(const G4Polymarker&) by GetMarkerSize.
+  o Attempt to finish AddPrimitive (const G4Text&) - still draws at origin.
+
+30th January 2006  John Allison  (openinventor-V08-00-01)
+- Implemented drawn volume path.  Needs modeling-V08-00-01.  Scene
+  graph now corresponds to drawn, i.e., non-culled geometry.
+  Inability to find (drawn) mothers shouldn't happen now, and it
+  triggers an error message.
+
+26th January 2006  John Allison  (openinventor-V08-00-00)
+- Coworks with visman-V08-00-04 (removed fModified).
+- Removed references to fModified.
+
+20th December 2005  Guy Barrand
+- SoAlternateRepAction.cc : add the #ifdef G4VIS_BUILD_OI_DRIVER.
+
+12th December 2005  John Allison
+- G4OpenInventorSceneHandler.cc: Pick up colour and transformation
+  correctly for non-physical-volume solids.
+  o G4OpenInventorSceneHandler::AddPrimitive (const G4Polyhedron&):
+    Added code to pick up colour if LV and PV pointers are zero.
+  o G4OpenInventorSceneHandler::BeginPrimitives: Pick up
+    transformation if LV and PV pointers are zero.
+  o G4OpenInventorSceneHandler::PreAddSolid: Added code to pick up
+    colour if LV and PV pointers are zero and removed return statement
+    so that transformation is picked up too.
+
+30th November 2005  Gabriele Cosmo (openinventor-V07-01-04)
+- Trivial fix to SoPolyhedron for support of CLHEP-2.0.X series.
+
+15th November 2005  Guy Barrand (openinventor-V07-01-03)
+- G4OpenInventorXtViewer : handle fVP.GetXGeometryString().
+- G4OpenInventorSceneHandler : handle global scale view parameter.
+  Done in BeginPrimitives and PreAddSolid by doing a 
+  SbMatrix::multRight(sbScale) to the incoming global G4Transform3D matrix.
+- G4OpenInventor[Xt,Win]Viewer : handle set background. Done
+  in the overloaded SetView method.
+
+17th October 2005  Guy Barrand
+- G4OpenInventorViewer::G4OpenInventorViewer : read a g4view.iv
+  file at creating of a view. If found, the scene graph in g4view.iv
+  if added at head of the overall scene graph. This permits easy
+  out of band customization of the scene without having to touch
+  the code.
+- Modification in order to save geometry in an Inventor file.
+  Addition of an "alternateRep" for the SoPolyhedron (see Inventor doc).
+  Addition of an "alternateRep" for the SoDetectorTreeKit.
+  Addition of the SoAlternaterRepAction to traverse a scene graph
+  and construct / delete the alternate reps.
+  Modification of G4OpenInventorViewer::WriteInventor to write the
+  alternateRep of the SoPolyhedron and then save geometry in a 
+  .iv file by using Inventor standard lib. In particular the produced
+  .iv files are readable by the ivview standard tool.
+
+2nd September 2005  John Allison (openinventor-V07-01-02)
+- Corrected treatment of edgeflags.
+
+1st August 2005  Gabriele Cosmo  (openinventor-V07-01-01)
+- Fixed compilation errors and warnings on gcc-4.0.0. Modified files:
+  SoDetectorTreeKit.cc, gl2ps[.h.cc].
+
+20th July 2005  John Allison  (openinventor-V07-01-00)
+- Changed Geant4_SoPolyhedron to construct from G4Polyhedron rather
+  than its base class, HepPolyhedron, for possible future
+  developments.  Functionality unchanged.
+
+2nd June 2005  John Allison  (openinventor-V07-00-02)
+- Changed char* to const char* in gl2psMsg.
+
+27th May 2005  John Allison  (openinventor-V07-00-01)
+- Implemented marker sizes.
+
+25th May 2005  Guy Barrand  (openinventor-V07-00-00)
+- G4OpenInventorTransform3D.cc : use the CLHEP::Transform3D::operator(i,j)
+  to initialize the m array in order to be compatible with new versions
+  of CLHEP.
+
+19th March 2005  Guy Barrand
+- SoCounterAction.cc : remove extra ';' at end of SO_ACTION_SOURCE.
+  Code with ';;' does not compile with the "-pedantic" mode of g++-3.4.
+
+26th November 2004  Guy Barrand  (openinventor-V06-02-02)
+- G4OpenInventorXtViewer, SoPolyhedron, SoCounterAction.h : 
+  correct some warnings on g++-3.2.1 (reported by Tom Roberts).
+
+25th November 2004  Guy Barrand
+- G4OpenInventor[Viewer,SceneHandle] : handle aux edges.
+- G4OpenInventorViewer : in SetSolid, etc... avoid to do a FinishView
+  that will do a viewAll that may displace the camera.
+- G4OpenInventorViewer : put the camera under a group and put
+  a sensor (fGroupCameraSensor) on the group to detect that the viewer 
+  changed the camera type.
+- G4OpenInventor[Xt,Win]Viewer : GetCamera() to get camera of the viewer.
+- G4OpenInventorViewer : delete fSoCameraSensor.
+
+24th November 2004  John Allison
+- Fixed SetView to respond to view parameters and CameraSensorCB to
+  provide view parameters. Target point not quite right. Only for
+  orthogonal view so far.
+
+24th November 2004  Guy Barrand
+- So*.cc : have #ifdef G4VIS_BUILD_OI_DRIVER instead of OIX_DRIVER !!!
+- G4OpenInventor[Xt,Win]Viewer, SceneHandler : handle reduced wire frame
+  at the level of the view.
+- SoPolyhedron : reducedWireFramw field.
+
+23th November 2004  Guy Barrand
+- So*.cc : have #ifdef G4VIS_BUILD_OIX_DRIVER.
+
+22th November 2004  Guy Barrand
+- G4OpenInventor[Xt,Win]Viewer : "Set preview", "Set preview and full" 
+  menu items.
+- G4OpenInventorViewer : count nodes and shapes.
+- SoCounterAction : to count nodes.
+- G4OpenInventorViewer : SetSolid, SetWireFrame : arrange to avoid a SetView
+  for the moment. It will move the camera ! Arrange to not clear the
+  transient store.
+- G4OpenInventorViewer : commit commented SoNodeSensor on fSoCamera.
+- G4OpenInventorXtViewer : have a help dialog.
+- G4OpenInventorSceneHandler : delete the SbMatrix returned 
+  by G4OpenInventorTransform3D::GetSbMatrix. Not done before !
+- G4OpenInventorTransform3D : use SbMatrix instead of SoSFMatrix.
+- G4OpenInventorSceneHandler : cache SoResetTransform.
+- SoStyleCache : destructor protected.
+- G4OpenInventor[Xt,Win]Viewer : Help pulldown menu.
+- G4OpenInventorViewer : in "Scene graph stats", count triangles,lines,points.
+- G4OpenInventorViewer : set auto refresh by default.
+
+21th November 2004  Guy Barrand
+- G4OpenInventor[Xt,Win]Viewer, SceneHandler : add a simple picking that
+  dumps picked SoNode address, type and name.
+- G4OpenInventor[Xt,Win]Viewer : "Help controls" menu item.
+- G4OpenInventorSceneHandler::PreAddThis : comment the "ERROR leaf protocal"
+  message. Misleading to users.
+
+19th November 2004  Guy Barrand
+- G4OpenInventorSceneHandler::ClearStore: clear the fSeparatorMap.
+
+18th November 2004  Guy Barrand
+- G4OpenInventorSceneHandler::PreAddThis : handle viewer style.
+- G4OpenInventorView : have an SoOrthographicCamera
+  and a first implementation of SetView.
+- Removed redundant fLastVP from G4OpenInventorSceneHandler (JA).
+
+17th November 2004  Guy Barrand
+- G4OpenInventorSceneHandler : rm the AddThis(G4Box,....). We use
+  then only the generic AddPrimitive(G4Polyhedron). Much simpler.
+
+15th November 2004  Guy Barrand
+- G4OpenInventorViewer : //FIXME comment out on 
+  f[Default]VP.SetCulling(false) by default. Not convinced that it is
+  the right thing to do.
+- G4OpenInventorViewer : have f[Default]VP.SetCulling(false) by default.
+- On viewer have "Erase detector, event" menuitems for Xt and Win.
+- G4OpenInventorWinViewer : have it inheriting G4OpenInventorViewer.
+- G4OpenInventorSceneHandler : WIN32 : correct some warnings.
+
+14th November 2004  Guy Barrand
+- G4OpenInventorSceneHandler.cc : handle transparency.
+- SoImageWriter, SbPainter, SbPainterPS : material to produce pixmap PS.
+- G4OpenInventorViewer : base class for Inventor viewers.
+- Menuitem "Etc/Triangles" : to count rendered triangles.
+- Menuitem "File/IV" : to write the scene in an inventor file.
+
+14th November 2004  John Allison  (openinventor-V06-02-01)
+- Tag on branch openinventor-V06-02-01-branch.
+- Consolidating the changes below, plus:
+  - forcing culling off by default;
+  - forcing solid mode;
+  so that the user:
+  - sees all of the requested geometry volume tree;
+  - can use pointer button and CTRL-left-click to uncover (SHIFT-left-click
+    to re-cover);
+  - can use the hand button and right-click to get wireframe.
+- Removed G4OpenInventorSceneHandler::EndModeling (empty function).
+
+12th November 2004  Guy Barrand
+- G4OpenInventor.cc : initClass of Geant4_SoPolyhedron.
+- G4OpenInventorWinViewer.cc : WM_COMMAND : filter only messages
+  from the window viewer menu.
+- G4OpenInventorSceneHandler.cc : rm G4Polymarker::line handling.
+
+11th November 2004  Guy Barrand
+- Add SoPolyhedron that permits to visualize directly HepPolyhedron.
+- G4OpenInventorSceneHandler::AddThis : uses the generic
+  SoPolyhedron. Modeling is wireFrame by default.
+  Solid modeling is used only in case visAtb.SetForceSolid(true).
+- G4OpenInventorSceneHandler::PreAddThis : correct a flaw
+  in the non-leaf part ; in case mother not found in fSeparatorMap
+  the SoDetectorTreeKit were added nowhere ! This induced that 
+  exaN03Vis5 displayed no gemetry.
+- SoStyleCache : permit to cache commonly used colors, line styles and
+  light models.
+- G4OpenInventorSceneHandler : use SoStyleCache to minimize number of nodes.
+- End of the first world war. 
+- Death of Arrafat.
+
+10th November 2004  Guy Barrand
+- SoMarkerSet, SoGL2PSAction : corrections to work with SGI Inventor.
+- gl2ps : gl2psPrintPostScriptPixmap : fix nbit=2,4 width truncation. 
+  (On SoMarkerSet, the last column of pixmapswere missing ).
+
+9th November 2004  Guy Barrand
+- WIN32 : G4OpenInventorWinViewer : have a File pulldown menu
+  with an Escape button to quit secondary Windows event loops.
+- Xt : G4OpenInventorXtViewer : in destructor comment (and //FIXME)
+  the "delete fViewer". With SGI, it hangs.
+- Xt : Have a menubar and put escape button in the File pulldown menu.
+- SoGL2PSAction, gl2ps : action to handle PostScript production with gl2ps.
+- Xt : "PostScript" menu item.
+- WIN32 : "PostScript" menu item.
+
+8th November 2004  Guy Barrand
+- WIN32 : Have HEPVis/SbGL.h to access GL.h properly on Windows.
+  Use by SoMarkerSet.cc.
+- G4OpenInventor.cc : initialize SoMarkerSet.
+- G4OpenInventorWinViewer : correct bad viewer look and feel.
+
+7th November 2004  Guy Barrand
+- Have SoMarkerSet.h, .cc in the repository.
+- G4OpenInventorSceneHandler : 
+  Have a AddPrimitive(G4Polymarker) using SoMarkerSet.
+  SoMarkerSet draws markers in the frame buffer. It is much
+  more performant than having SoSphere and SoCube for markers.
+
+6th November 2004  Guy Barrand
+- G4OpenInventorXtViewer : restore the escape button.
+  This button is put in the "app buttons" of the SoXtExaminerViewer.
+  (The "app buttons" are put in the left border of decoration).
+  It is ok with SGI-2.1.510 and recent SoXt of Coin, 
+
+21th July 2004  Guy Barrand (openinventor-V06-02-00)
+- G4OpenInventorXtViewer : add include X11/Shell.h to have
+  XtNgeometry that may not come throught the includes of some
+  Inventor implementation.
+
+08th April 2004  Guy Barrand (openinventor-V06-01-00)
+- Bring in the repository the necessary HEPVis code. In fact few of HEPVis
+  is used in this G4 driver. Then HEPVis is no more needed.
+  Note that, to avoid clashes of G4/vis within experiments, the HEPVis
+  node are protected by some : #define Geant4_<node> <node>.  Then, for
+  example, within the G4OpenInventor lib there are Geant4_SoBox, etc...
+  (and not SoBox,... that may clash with other HEPVis code in  experiments).
+- Have code to run on Windows.
+- Split Viewer to have G4OpenInventorXtViewer and G4OpenInventorWinViewer.
+- Split G4OpenInventor to have G4OpenInventorXt and G4OpenInventorWin.
+  Xt and Win (and not X and Win32 like in vis/OpenGL) to follow 
+  the conventions found in the OpenInventor world.
+
+29th October 2003  Cosmo Gabriele (openinventor-V05-02-00)
+- Patch in G4OpenInventorSceneHandler in PreAddThis() to cope with changes
+  introduced in G4VPhysicalVolume in "geant4-05-02-ref-04", where pointer to
+  mother physical-volume was removed.
+  Separators map now refers to logical-volumes and is no longer built
+  iteratively for each call to the method as it was done in an attempt
+  implemented previously.
+  NOTE: requires more investigation and eventually a revision of the
+        adopted algorithm.
+- Cleared usage of 'NULL' in favour of '0'.
+
+4th October 2003  Cosmo Gabriele (vis-V05-02-01)
+- Simplified GNUmakefile.
+
+14th January 2003  John Allison  (openinventor-V05-00-00)
+- Removed vertex.transform (*fpObjectTransformation) from
+  G4OpenInventorSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron).
+  Symptom was that polyhedron objects were being transformed twice.
+  The transformation is stored in 
+  G4OpenInventorSceneHandler::PreAddThis
+  ...
+  G4OpenInventorTransform3D oiTran (objectTransformation);
+  SoSFMatrix* oiMat = oiTran.GetOIMatrix();
+  SoMatrixTransform* xform = new SoMatrixTransform;
+  xform->matrix.setValue(oiMat->getValue());
+  currentSeparator->addChild(new SoResetTransform);
+  currentSeparator->addChild(xform);
+}
+
+27th November 2002  John Allison  (vis-V04-01-08)
+- Improved algorithm of CompareForKernelVisit.
+
+14th August 2001  John Allison  (vis-V03-02-11)
+- Improved KernelVisitDecision - but see note therein.
Index: /trunk/geant4/visualization/OpenInventor/include/G4OpenInventor.hh
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/G4OpenInventor.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/G4OpenInventor.hh	(revision 529)
@@ -0,0 +1,58 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenInventor.hh,v 1.9 2006/06/29 21:20:22 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// Guy Barrand 26 Mar 1998.
+// OpenInventor graphics system factory.
+
+#ifndef G4OPENINVENTOR_HH
+#define G4OPENINVENTOR_HH
+
+#if defined(G4VIS_BUILD_OI_DRIVER) || defined(G4VIS_USE_OI)
+
+#include "G4VGraphicsSystem.hh"
+
+class G4VInteractorManager;
+
+class G4OpenInventor: public G4VGraphicsSystem {
+public:
+  G4OpenInventor(const G4String,const G4String,G4VGraphicsSystem::Functionality);
+  virtual ~G4OpenInventor();
+  void SetInteractorManager(G4VInteractorManager*);
+  G4VInteractorManager* GetInteractorManager();
+  G4VSceneHandler* CreateSceneHandler (const G4String& name);
+  void InitNodes();
+private:
+  virtual void Initialize() = 0;
+private:
+  G4VInteractorManager* interactorManager;
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorSceneHandler.hh
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorSceneHandler.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorSceneHandler.hh	(revision 529)
@@ -0,0 +1,107 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenInventorSceneHandler.hh,v 1.31 2006/11/02 12:01:20 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// J Kallenbach  27th Aug 1996
+// OpenInventor scene handler - creates OpenInventor Display lists.
+// 20 dec 1996  jck  Add HEPVis primitives - trd, box, etc.
+
+#ifndef G4OPENINVENTORSCENEHANDLER_HH
+#define G4OPENINVENTORSCENEHANDLER_HH
+
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+// Inheritance :
+#include "G4VSceneHandler.hh"
+
+#include "G4PhysicalVolumeModel.hh"
+
+#include <map>
+
+class G4OpenInventor;
+class SoSeparator;
+class Geant4_SoStyleCache;
+class G4AttHolder;
+
+// Base class for various OpenInventorScene classes.
+class G4OpenInventorSceneHandler: public G4VSceneHandler {
+
+friend class G4OpenInventorViewer;
+
+public:
+
+  G4OpenInventorSceneHandler (G4OpenInventor& system, const G4String& name = "");
+  virtual ~G4OpenInventorSceneHandler ();
+  void AddPrimitive (const G4Polyline& line);
+  void AddPrimitive (const G4Text&);
+  void AddPrimitive (const G4Circle&);
+  void AddPrimitive (const G4Square&);
+  void AddPrimitive (const G4Polyhedron& p);
+  void AddPrimitive (const G4NURBS& nurb);
+  void AddPrimitive (const G4Polymarker&);
+  ////////////////////////////////////////////////////////////////
+  // Explicitly invoke base class methods to avoid warnings about
+  // hiding of base class methods.
+  void AddPrimitive (const G4Scale& scale) {
+    G4VSceneHandler::AddPrimitive (scale);
+  }
+  ///////////////////////////////////////////////////////////////
+  // Other inherited functions.
+  void 		ClearStore ();
+  void 		ClearTransientStore ();
+  
+  //
+  // Primitives for use of HEPVis
+  //
+  void PreAddSolid (const G4Transform3D& objectTransformation,
+		    const G4VisAttributes& visAttribs);
+  void BeginPrimitives (const G4Transform3D& objectTransformation);
+
+private:
+
+  void LoadAtts(const G4Visible&, G4AttHolder*);
+  static G4int fSceneIdCount;   // static counter for OpenInventor scenes.
+  enum G4OIMarker {G4OICircle, G4OISquare};
+  void AddCircleSquare (G4OIMarker markerType, const G4VMarker&);
+  void GeneratePrerequisites();
+  std::map <G4LogicalVolume*, SoSeparator*,
+    std::less <G4LogicalVolume*> > fSeparatorMap;
+  SoSeparator* fRoot;
+  SoSeparator* fDetectorRoot;
+  SoSeparator* fTransientRoot;
+  SoSeparator* fCurrentSeparator;
+  G4bool fModelingSolid;
+  G4bool fReducedWireFrame;
+  Geant4_SoStyleCache* fStyleCache;
+  bool fPreviewAndFull;
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorTransform3D.hh
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorTransform3D.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorTransform3D.hh	(revision 529)
@@ -0,0 +1,54 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenInventorTransform3D.hh,v 1.7 2006/06/29 21:20:26 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// jck  17 Dec 1996
+// G4OpenGLInventorTransform3D provides SoSFMatrix transformation matrix
+// from G4Transform3D.
+
+#ifndef G4OPENINVENTORTRANSFORM3D_HH
+#define G4OPENINVENTORTRANSFORM3D_HH
+
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+#include "G4Transform3D.hh"
+
+class SbMatrix;
+
+class G4OpenInventorTransform3D : public G4Transform3D {
+public:
+  G4OpenInventorTransform3D (const G4Transform3D &t);
+  SbMatrix* GetSbMatrix () const;
+private:
+  G4float m[16];
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorViewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorViewer.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorViewer.hh	(revision 529)
@@ -0,0 +1,104 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+
+#ifndef G4OPENINVENTORVIEWER_HH
+#define G4OPENINVENTORVIEWER_HH
+
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+// Inheritance :
+#include "G4VViewer.hh"
+
+class SoSelection;
+class SoPath;
+class SoCamera;
+class SoSensor;
+class SoNodeSensor;
+
+class Geant4_SoImageWriter;
+class Geant4_SoGL2PSAction;
+class G4OpenInventorSceneHandler;
+class G4VInteractorManager;
+class SbVec3f;
+
+//
+// Base class for various OpenInventorView classes.
+//
+class G4OpenInventorViewer: public G4VViewer {
+public: //G4VViewer
+  virtual void DrawView();
+  virtual void ShowView();
+  virtual void ClearView();
+  virtual void SetView();
+  virtual void KernelVisitDecision();
+public:
+  G4OpenInventorViewer(G4OpenInventorSceneHandler& scene,
+		       const G4String& name = "");
+  virtual ~G4OpenInventorViewer();
+protected:
+  virtual void ViewerRender() = 0;
+  virtual SoCamera* GetCamera() = 0;
+  void Escape();
+  void WritePostScript(const G4String& file = "g4out.ps");
+  void WritePixmapPostScript(const G4String& file = "g4out.ps");
+  void WriteInventor(const G4String& file = "g4out.iv");
+  void SceneGraphStatistics();
+  void EraseDetector();
+  void EraseEvent();
+  void SetPreviewAndFull();
+  void SetPreview();
+  void SetSolid();
+  void SetWireFrame();
+  void SetReducedWireFrame(bool);
+  void UpdateScene();
+  G4String Help(const G4String& topic = "controls");
+private:
+  static void SelectionCB(void*,SoPath*);
+  //static void DeselectionCB(void*,SoPath*);
+  static void GroupCameraSensorCB(void*,SoSensor*);
+  static void CameraSensorCB(void*,SoSensor*);
+  static void pointAt(SoCamera*,const SbVec3f & targetpoint, const SbVec3f & upvector);
+  static void lookAt(SoCamera*,const SbVec3f & dir, const SbVec3f & up);
+  static void lookedAt(SoCamera*,SbVec3f & dir, SbVec3f & up);
+private:
+  G4bool CompareForKernelVisit(G4ViewParameters&);
+  void DrawDetector();
+private:
+  G4ViewParameters fLastVP;  // Memory for making kernel visit decisions.
+protected:
+  G4OpenInventorSceneHandler& fG4OpenInventorSceneHandler;
+  G4VInteractorManager* fInteractorManager;
+  SoSelection* fSoSelection;
+  Geant4_SoImageWriter* fSoImageWriter;
+  Geant4_SoGL2PSAction* fGL2PSAction;
+  SoNodeSensor* fGroupCameraSensor;
+  SoNodeSensor* fCameraSensor;
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorWin.hh
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorWin.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorWin.hh	(revision 529)
@@ -0,0 +1,52 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenInventorWin.hh,v 1.3 2006/06/29 21:20:30 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// OpenInventor graphics system factory.
+
+#if defined (G4VIS_BUILD_OIWIN32_DRIVER) || defined (G4VIS_USE_OIWIN32)
+
+#ifndef G4OPENINVENTORWIN_HH
+#define G4OPENINVENTORWIN_HH
+
+#include "G4OpenInventor.hh"
+
+class G4OpenInventorWin: public G4OpenInventor {
+public:
+  G4OpenInventorWin ();
+  virtual ~G4OpenInventorWin ();
+  G4VViewer* CreateViewer(G4VSceneHandler&,const G4String& name = "");
+private:
+  virtual void Initialize();
+private:
+  bool fInited;
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorWin32.hh
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorWin32.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorWin32.hh	(revision 529)
@@ -0,0 +1,49 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenInventorWin32.hh,v 1.7 2006/06/29 21:20:32 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// OpenInventor graphics system factory.
+
+#if defined (G4VIS_BUILD_OIWIN32_DRIVER) || defined (G4VIS_USE_OIWIN32)
+
+#ifndef G4OPENINVENTORWIN32_HH
+#define G4OPENINVENTORWIN32_HH
+
+// For backward compatibilty.
+
+#include "G4OpenInventorWin.hh"
+
+class G4OpenInventorWin32: public G4OpenInventorWin {
+public:
+  G4OpenInventorWin32 () {}
+  virtual ~G4OpenInventorWin32 () {}
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorWinViewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorWinViewer.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorWinViewer.hh	(revision 529)
@@ -0,0 +1,66 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenInventorWinViewer.hh,v 1.9 2006/06/29 21:20:34 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Jeff Kallenbach 01 Aug 1996
+// OpenInventor viewer - opens window, hard copy, etc.
+
+#ifndef G4OPENINVENTORWINVIEWER_HH
+#define G4OPENINVENTORWINVIEWER_HH
+
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+// Inheritance :
+#include "G4OpenInventorViewer.hh"
+
+#include <windows.h>
+
+class Geant4_SoWinExaminerViewer;
+
+class G4OpenInventorWinViewer: public G4OpenInventorViewer {
+public: //G4VViewer
+  virtual void FinishView();
+  virtual void SetView();
+protected:
+  virtual void ViewerRender();
+  virtual SoCamera* GetCamera();
+public:
+  G4OpenInventorWinViewer(G4OpenInventorSceneHandler& scene,
+		       const G4String& name = "");
+  virtual ~G4OpenInventorWinViewer();
+private:
+  static LRESULT CALLBACK WindowProc(HWND,UINT,WPARAM,LPARAM);
+private:
+  HWND fShell;
+  Geant4_SoWinExaminerViewer* fViewer;
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorX.hh
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorX.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorX.hh	(revision 529)
@@ -0,0 +1,51 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenInventorX.hh,v 1.7 2006/06/29 21:20:36 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Andrew Walkden  27th March 1996
+// OpenInventor graphics system factory.
+
+#if defined (G4VIS_BUILD_OIX_DRIVER) || defined (G4VIS_USE_OIX)
+
+#ifndef G4OPENINVENTORX_HH
+#define G4OPENINVENTORX_HH
+
+// For backward compatibilty.
+
+#include "G4OpenInventorXt.hh"
+
+class G4OpenInventorX: public G4OpenInventorXt {
+public:
+  G4OpenInventorX () {}
+  virtual ~G4OpenInventorX () {}
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorXt.hh
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorXt.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorXt.hh	(revision 529)
@@ -0,0 +1,54 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenInventorXt.hh,v 1.3 2006/06/29 21:20:38 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Andrew Walkden  27th March 1996
+// OpenInventor graphics system factory.
+
+#if defined (G4VIS_BUILD_OIX_DRIVER) || defined (G4VIS_USE_OIX)
+
+#ifndef G4OPENINVENTORXT_HH
+#define G4OPENINVENTORXT_HH
+
+#include "G4OpenInventor.hh"
+
+class G4OpenInventorXt: public G4OpenInventor {
+public:
+  G4OpenInventorXt ();
+  virtual ~G4OpenInventorXt ();
+  G4VViewer* CreateViewer(G4VSceneHandler&,const G4String& name = "");
+private:
+  virtual void Initialize();
+private:
+  bool fInited;
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorXtViewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorXtViewer.hh	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/G4OpenInventorXtViewer.hh	(revision 529)
@@ -0,0 +1,85 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenInventorXtViewer.hh,v 1.14 2006/06/29 21:20:40 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Jeff Kallenbach 01 Aug 1996
+// OpenInventor viewer - opens window, hard copy, etc.
+
+#ifndef G4OPENINVENTORXTVIEWER_HH
+#define G4OPENINVENTORXTVIEWER_HH
+
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+// Inheritance :
+#include "G4OpenInventorViewer.hh"
+
+#include <X11/Intrinsic.h>
+class SoXtExaminerViewer;
+
+class G4OpenInventorXtViewer: public G4OpenInventorViewer {
+public: //G4VViewer
+  virtual void FinishView();
+  virtual void SetView();
+protected:
+  virtual void ViewerRender();
+  virtual SoCamera* GetCamera();
+public:
+  G4OpenInventorXtViewer(G4OpenInventorSceneHandler& scene,
+		         const G4String& name = "");
+  virtual ~G4OpenInventorXtViewer();
+private:
+  Widget AddMenu(Widget,const G4String&,const G4String&);
+  void AddButton(Widget,const G4String&,XtCallbackProc);
+private:
+  static void PostScriptCbk(Widget,XtPointer,XtPointer);
+  static void PixmapPostScriptCbk(Widget,XtPointer,XtPointer);
+  static void WriteInventorCbk(Widget,XtPointer,XtPointer);
+  static void EscapeCbk(Widget,XtPointer,XtPointer);
+  static void SceneGraphStatisticsCbk(Widget,XtPointer,XtPointer);
+  static void EraseDetectorCbk(Widget,XtPointer,XtPointer);
+  static void EraseEventCbk(Widget,XtPointer,XtPointer);
+  static void SetSolidCbk(Widget,XtPointer,XtPointer);
+  static void SetWireFrameCbk(Widget,XtPointer,XtPointer);
+  static void SetReducedWireFrameCbk(Widget,XtPointer,XtPointer);
+  static void SetFullWireFrameCbk(Widget,XtPointer,XtPointer);
+  static void UpdateSceneCbk(Widget,XtPointer,XtPointer);
+  static void HelpCbk(Widget,XtPointer,XtPointer);
+  static void HelpCancelCbk(Widget,XtPointer,XtPointer);
+  static void SetPreviewCbk(Widget,XtPointer,XtPointer);
+  static void SetPreviewAndFullCbk(Widget,XtPointer,XtPointer);
+private:
+  Widget fShell;
+  SoXtExaminerViewer* fViewer;
+  Widget fHelpForm;
+  Widget fHelpText;
+};
+
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/Geant4_SoPolyhedron.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/Geant4_SoPolyhedron.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/Geant4_SoPolyhedron.h	(revision 529)
@@ -0,0 +1,78 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+#ifndef Geant4_SoPolyhedron_h
+#define Geant4_SoPolyhedron_h
+
+// Inheritance :
+#include <Inventor/nodes/SoShape.h>
+
+#include <Inventor/fields/SoSFBool.h>
+#include <Inventor/fields/SoSFNode.h>
+
+class G4Polyhedron;
+
+/**
+ *  SoPolyhedron is an Inventor encapsulation of the G4Polyedron
+ * class written by E.Chernyaev. In particular SoPolyhedron permits
+ * to represent boolean operations over solids.
+ *  To avoid clashes with other libraries (Geant4) where the G4Polyhedron
+ * classes may be found, the G4Polyhedron (through usage of CPP macros)
+ * had been renamed G4Polyhedron in the HEPVis lib.
+ *  The solids are modeled with G4Polyedron objects. The G4Polyhedron
+ * permits to produce a new G4Polyhedron according to the boolean 
+ * operation done on them. The resulting G4Polyhedron  is then given
+ * to an SoPolyhedron for rendering.
+ *  Note that a boolean operation could be rendered in wire frame
+ * by drawing the contour of the resulting solid (not by drawing
+ * the wire frame of a triangulation).
+ *  See the applications/Polyhedron example.
+ */
+
+class Geant4_SoPolyhedron : public SoShape {
+  SO_NODE_HEADER(Geant4_SoPolyhedron);
+public:
+  SoSFBool solid;
+  SoSFBool reducedWireFrame;
+  SoSFNode alternateRep;
+public:
+  Geant4_SoPolyhedron();
+  Geant4_SoPolyhedron(const G4Polyhedron&);
+  Geant4_SoPolyhedron(G4Polyhedron*);
+  virtual void generateAlternateRep();
+  virtual void clearAlternateRep();
+public:
+  static void initClass();
+protected:
+  virtual void computeBBox(SoAction*,SbBox3f&,SbVec3f&);
+  virtual void generatePrimitives(SoAction*);
+  virtual void doAction(SoAction*);
+protected:
+  virtual ~Geant4_SoPolyhedron();
+private: 
+  G4Polyhedron* fPolyhedron;
+};
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/HEPVis/SbGL.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/HEPVis/SbGL.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/HEPVis/SbGL.h	(revision 529)
@@ -0,0 +1,41 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+#ifndef HEPVis_SbGL_h
+#define HEPVis_SbGL_h 
+
+#ifdef WIN32
+#include <windows.h>
+#endif
+
+#ifdef APPLE_GL
+#include <gl.h>
+#include <glu.h>
+#else
+#include <GL/gl.h>
+#include <GL/glu.h>
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/HEPVis/SbMath.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/HEPVis/SbMath.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/HEPVis/SbMath.h	(revision 529)
@@ -0,0 +1,56 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: SbMath.h,v 1.4 2006/06/29 21:20:46 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+#ifndef HEPVis_SbMath_h
+#define HEPVis_SbMath_h
+
+#include <cmath>
+#ifndef M_PI
+#define M_PI       3.1415926535897931160E0
+#define M_PI_2     1.5707963267948965580E0  
+#endif
+
+#define SbMinimum(a,b) ((a)<(b)?a:b)
+#define SbMaximum(a,b) ((a)>(b)?a:b)
+
+#define FCOS(x)   ((float)cos((double)(x)))
+#define FSIN(x)   ((float)sin((double)(x)))
+#define FACOS(x)  ((float)acos((double)(x)))
+#define FASIN(x)  ((float)asin((double)(x)))
+#define FTAN(x)   ((float)tan((double)(x)))
+#define FATAN(x)  ((float)atan((double)(x)))
+#define FSQRT(x)  ((float)sqrt((double)(x)))
+#define FPOW(x,y) ((float)pow((double)(x),(double)(y)))
+#define FLOG(x)   ((float)log((double)(x)))
+#define FLOG10(x) ((float)log10((double)(x)))
+#define FFLOOR(x) ((float)floor((double)(x)))
+#define FFABS(x)  ((float)fabs((double)(x)))
+#define FCEIL(x)  ((float)ceil((double)(x)))
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/HEPVis/SbPainter.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/HEPVis/SbPainter.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/HEPVis/SbPainter.h	(revision 529)
@@ -0,0 +1,77 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// History :
+// - 09/12/98, G.Barrand : creation.
+
+#ifndef HEPVis_SbPainter_h
+#define HEPVis_SbPainter_h 
+
+#include <Inventor/SbBasic.h>
+
+/*
+#include <HEPVis/SbStyle.h>
+
+typedef enum {
+  SbPrimitivePoints,
+  SbPrimitiveLineStrip,
+  SbPrimitiveLineLoop,
+  SbPrimitiveLines,
+  SbPrimitivePolygon
+} SbPrimitiveType;
+
+class SbPainterContext {
+public:
+  float fRed,fGreen,fBlue;
+  int fLineWidth;
+  SbLineStyle fLineStyle;
+  int fMarkerSize;
+  SbMarkerStyle fMarkerStyle;
+  SbAreaStyle fAreaStyle;
+  int fPolygonMode;
+};
+*/
+
+#define SbPainter Geant4_SbPainter
+
+class SbPainter {
+public:
+  SbPainter();
+  virtual ~SbPainter();
+  void setWindowSize(int,int);
+  void enableEdges(SbBool);
+  virtual void beginTraversal() = 0;
+  virtual void clearColorBuffer(float,float,float) = 0;
+  //virtual void drawPrimitive(SbPrimitiveType,
+  //                          int,float*,float*,float*,
+   //                        const SbPainterContext&) = 0;
+  virtual void endTraversal() = 0;
+protected:
+  int fWindowWidth,fWindowHeight;
+  float fRed,fGreen,fBlue;
+  SbBool fEdges;
+};
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/HEPVis/SbPainterPS.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/HEPVis/SbPainterPS.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/HEPVis/SbPainterPS.h	(revision 529)
@@ -0,0 +1,130 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// History :
+// - 25/09/98, G.Barrand : creation.
+
+#ifndef HEPVis_SbPainterPS_h
+#define HEPVis_SbPainterPS_h 
+
+// Inheritance :
+#include <HEPVis/SbPainter.h>
+
+#include <stdarg.h>
+
+#include <Inventor/SbViewportRegion.h>
+
+#define SbPainterPS Geant4_SbPainterPS
+
+class SbPainterPS : public SbPainter {
+public:
+  SbPainterPS();
+  ~SbPainterPS();
+  void beginTraversal();
+  void clearColorBuffer(float,float,float);
+  //void drawPrimitive(SbPrimitiveType,
+  //                   int,float*,float*,float*,
+  //                   const SbPainterContext&);
+  void endTraversal();
+public:
+  void setColorScheme(int);
+  void setOrientation(int);
+  void setBackgroundDrawn(int);
+  void setBitsPerPixel(int);
+  void setLineWidth(int);
+  void* getStream();
+  void setFileName(const char*);
+  const char* getFileName() const;
+  void openFileForWriting(const char*);
+  void closeStream();
+  void putPageScaleInStream(float,float);
+  void putSaveStateInStream();
+  void putRestoreStateInStream();
+  void putTranslationInStream(float,float);
+  void putScaleInStream(float,float);
+  void putBeginPageInStream();
+  void putEndPageInStream();
+  void putRGB_InStream(float,float,float);
+  void putMarkerSizeInStream(float);
+  //void putMarkerStyleInStream(SbMarkerStyle);
+  void putBackgroundInStream(float,float,float,float,float);
+  void putFrameInStream(float,float,float,float,float);
+  void putRotateInStream(float);
+  void putNewPathInStream();
+  void putStrokeInStream();
+  void putFillInStream();
+  void putClosePathInStream();
+  void putCapInStream(int);
+  void putLineToInStream(float,float);
+  void putMoveInStream(float,float);
+  void putCircleInStream(float,float,float);
+  void putLineWidthInStream(int);
+  //void putLineStyleInStream(SbLineStyle);
+  typedef int(*GetRGB_Function)(unsigned int,unsigned int,
+                                double&,double&,double&);
+  void putImageInStream(unsigned int,unsigned int,GetRGB_Function);
+private:
+  //void drawPolygon(int,float*,float*,float,float,float,const SbAreaStyle&);
+  //void drawLines(int,float*,float*,float,float,float,const SbLineStyle&,int);
+  //void drawMarkers(int,float*,float*,
+  //                 float,float,float,const SbMarkerStyle&,int);
+  enum ColorScheme {
+    Color = 0,
+    Grey = 1,
+    BlackWhite = 2
+  };
+  struct {
+    int shade;
+    int portrait;
+    int nbit;
+    int doBack;
+    float lineWidth;
+  } fParams;
+  float fDeviceWidth;
+  float fDeviceHeight;
+  int fPageNumber;
+  long fPagePos;
+  float fMarkerSize;
+  FILE* fFile;
+  char* fFileName;
+  int fGSave;
+  int fBufferCount;
+  char* fBufferString;
+#define METAFILE_RECORD_LENGTH  80
+  unsigned char fBufferPointer[METAFILE_RECORD_LENGTH+1];
+private:
+  void putInStreamF(const char*,...);
+  void printFLN(const char*,...);
+  void printV(const char*,va_list);
+  float convertRGB_ToGrey(float,float,float);
+  void writeByte(unsigned char);
+};
+
+#endif
+
+
+
+
+
Index: /trunk/geant4/visualization/OpenInventor/include/HEPVis/actions/SoAlternateRepAction.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/HEPVis/actions/SoAlternateRepAction.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/HEPVis/actions/SoAlternateRepAction.h	(revision 529)
@@ -0,0 +1,69 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+#ifndef HEPVis_SoAlternateRepAction_h
+#define HEPVis_SoAlternateRepAction_h 
+
+// Inheritance :
+#include <Inventor/actions/SoAction.h>
+
+#include <Inventor/actions/SoSubAction.h>
+
+#define SoAlternateRepAction Geant4_SoAlternateRepAction
+
+class SoAlternateRepAction : public SoAction {
+  SO_ACTION_HEADER(SoAlternateRepAction);
+public:
+  SoAlternateRepAction();
+  virtual ~SoAlternateRepAction();  
+  static void initClass(void);
+  void setGenerate(SbBool);
+  SbBool getGenerate() const;
+private:
+  static void nodeAction(SoAction*,SoNode*);
+private:
+  SbBool fGenerate;
+};
+
+#define SO_ALTERNATEREP_DO_ACTION(aAction) \
+  if(aAction->isOfType(SoAlternateRepAction::getClassTypeId())) {\
+    if(((SoAlternateRepAction*)aAction)->getGenerate()==TRUE) {\
+      if(alternateRep.getValue()==NULL) {\
+        generateAlternateRep();\
+        SoNode* altRep = alternateRep.getValue();\
+        if((altRep!=NULL) && altRep->isOfType(SoGroup::getClassTypeId()))\
+          altRep->doAction(aAction);\
+      }\
+    } else {\
+      SoNode* altRep = alternateRep.getValue();\
+      if((altRep!=NULL) && altRep->isOfType(SoGroup::getClassTypeId()))\
+        altRep->doAction(aAction);\
+      clearAlternateRep();\
+    }\
+    return;\
+  }
+
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/HEPVis/actions/SoCounterAction.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/HEPVis/actions/SoCounterAction.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/HEPVis/actions/SoCounterAction.h	(revision 529)
@@ -0,0 +1,60 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+#ifndef HEPVis_SoCounterAction_h
+#define HEPVis_SoCounterAction_h 
+
+// Inheritance :
+#include <Inventor/actions/SoAction.h>
+
+#include <Inventor/actions/SoSubAction.h>
+
+#define SoCounterAction Geant4_SoCounterAction
+
+class SoCounterAction : public SoAction {
+  SO_ACTION_HEADER(SoCounterAction);
+public:
+  SoCounterAction();
+  virtual ~SoCounterAction();  
+  static void initClass(void);
+  enum LookFor { NODE = 1,TYPE = 2, NAME = 3 };
+  void setLookFor(LookFor);
+  void setType(const SoType,SbBool = TRUE);
+  void setName(const SbName);
+public:
+  int getCount() const;
+protected:
+  virtual void beginTraversal(SoNode*);
+private:
+  static void actionMethod(SoAction*,SoNode*);
+private:
+  int fCount;
+  int fLookFor;
+  SbName fName;
+  SoType fType;
+  SbBool fCheckDerived;
+};
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/HEPVis/actions/SoGL2PSAction.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/HEPVis/actions/SoGL2PSAction.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/HEPVis/actions/SoGL2PSAction.h	(revision 529)
@@ -0,0 +1,62 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+#ifndef HEPVis_SoGL2PSAction_h
+#define HEPVis_SoGL2PSAction_h 
+
+#include <Inventor/actions/SoGLRenderAction.h>
+
+/**
+ *  SoGL2PSAction inherits Inventor/SoGLRenderAction.
+ * It uses the gl2ps software to produce vector PostScript of a scene graph.
+ *  See applications/DetectorTreeKit, Polyhedron for examples.
+ */
+
+#define SoGL2PSAction Geant4_SoGL2PSAction
+
+class SoGL2PSAction : public SoGLRenderAction {
+  SO_ACTION_HEADER(SoGL2PSAction);
+public:
+  SoGL2PSAction(const SbViewportRegion&);
+  void setFileName(const char*);
+  void enableFileWriting();
+  void disableFileWriting();
+  SbBool fileWritingEnabled() const;
+  SbBool addBitmap(int,int,float=0,float=0,float=0,float=0);
+  void beginViewport();
+  void endViewport();
+public: /*SoINTERNAL*/
+  static void initClass();
+protected:
+  virtual void beginTraversal(SoNode*);
+private:
+  void gl2psBegin();
+private:
+  SbString fFileName;
+  FILE* fFile;
+};
+
+#endif
+
Index: /trunk/geant4/visualization/OpenInventor/include/HEPVis/misc/SoStyleCache.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/HEPVis/misc/SoStyleCache.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/HEPVis/misc/SoStyleCache.h	(revision 529)
@@ -0,0 +1,63 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//  27/03/2004 : G.Barrand : creation.
+
+#ifndef HEPVis_SoStyleCache_h
+#define HEPVis_SoStyleCache_h
+
+#include <Inventor/nodes/SoGroup.h>
+
+//#include <HEPVis/SbStyle.h>
+
+class SoMaterial;
+class SoDrawStyle;
+class SoLightModel;
+class SoResetTransform;
+class SbColor;
+ 
+#define SoStyleCache Geant4_SoStyleCache
+
+class SoStyleCache : public SoGroup {
+public:
+  SoStyleCache();
+protected:
+  ~SoStyleCache();
+public:
+  SoMaterial* getMaterial(const SbColor&,float = 0); 
+  SoMaterial* getMaterial(float,float,float,float = 0); 
+  //SoDrawStyle* getLineStyle(SbLineStyle,float = 0); 
+  SoDrawStyle* getLineStyle(unsigned short = 0xFFFF,float = 0); 
+  SoLightModel* getLightModelPhong(); 
+  SoLightModel* getLightModelBaseColor(); 
+  SoResetTransform* getResetTransform();
+private:
+  SoGroup* fMaterials;
+  SoGroup* fLineStyles;
+  SoGroup* fLightModels;
+  SoResetTransform* fResetTransform;
+};
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodekits/SoDetectorTreeKit.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodekits/SoDetectorTreeKit.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodekits/SoDetectorTreeKit.h	(revision 529)
@@ -0,0 +1,123 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: SoDetectorTreeKit.h,v 1.5 2006/06/29 21:21:16 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+/*-----------------------------HEPVis----------------------------------------*/
+/*                                                                           */
+/* Node:             SoDetectorTreeKit                                       */
+/* Description:      Easy way of browsing through a tree of detectors        */
+/* Author:           Joe Boudreau Nov 11 1996                                */
+/*                                                                           */
+/*---------------------------------------------------------------------------*/
+#ifndef HEPVis_SoDetectorTreeKit_h
+#define HEPVis_SoDetectorTreeKit_h
+
+// Inheritance :
+#include <Inventor/nodekits/SoBaseKit.h>
+
+class SoEventCallback;
+class SoSeparator;
+
+#define SoDetectorTreeKit Geant4_SoDetectorTreeKit
+
+
+class SoDetectorTreeKit:public SoBaseKit {
+
+  // The following is required:
+  SO_KIT_HEADER(SoDetectorTreeKit);
+  ////////////////////////////////////////////
+public:
+  SoSFNode alternateRep; //public in order to query if alternateRep done.
+private:
+  ////////////////////////////////////////////
+  SO_KIT_CATALOG_ENTRY_HEADER(callbackList);
+  SO_KIT_CATALOG_ENTRY_HEADER(topSeparator);
+    SO_KIT_CATALOG_ENTRY_HEADER(pickStyle);
+    SO_KIT_CATALOG_ENTRY_HEADER(appearance);
+    SO_KIT_CATALOG_ENTRY_HEADER(units);
+    SO_KIT_CATALOG_ENTRY_HEADER(transform);
+    SO_KIT_CATALOG_ENTRY_HEADER(texture2Transform);
+    SO_KIT_CATALOG_ENTRY_HEADER(childList);
+      SO_KIT_CATALOG_ENTRY_HEADER(previewSeparator);
+      SO_KIT_CATALOG_ENTRY_HEADER(fullSeparator);
+   
+
+public:
+
+  // Constructor, required
+  SoDetectorTreeKit();
+
+  // This is required
+  virtual SbBool affectsState() const;
+
+  // Class Initializer, required
+  static void initClass();
+
+  // Turn the preview on or off
+  virtual void setPreview(SbBool Flag);
+
+  // Return the preview state
+  virtual SbBool getPreview() const;
+
+  // Set SoSwitch::whichChild = SO_SWITCH_ALL
+  void setPreviewAndFull();
+
+  // Return the preview Separator
+  virtual SoSeparator *getPreviewSeparator() const;
+
+  // Return the full Separator
+  virtual SoSeparator *getFullSeparator() const;
+
+  // Generate AlternateRep, required.  Generating an alternate representation
+  // must be done upon users request.  It allows an Inventor program to read
+  // back the file without requiring *this* code to be dynamically linked. 
+  // If the users expects that *this* code will be dynamically linked, he
+  // need not invoke this method.  
+  virtual void generateAlternateRep();
+
+  // We better be able to clear it, too!
+  virtual void clearAlternateRep();
+
+protected:
+
+  // Destructor.
+  virtual ~SoDetectorTreeKit();
+
+  virtual void doAction(SoAction*);
+private: 
+
+  // This is needed as well
+  void createInitialTree();
+
+  // This is the callback function that will be 
+  // added to the callback list
+  static void   expand   (void *userData, SoEventCallback *eventCB);
+  static void   contract (void *userData, SoEventCallback *eventCB);
+};
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoBox.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoBox.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoBox.h	(revision 529)
@@ -0,0 +1,158 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: SoBox.h,v 1.3 2006/06/29 21:21:18 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+/*-----------------------------Hepvis----------------------------------------*/
+/*                                                                           */
+/* Node:             SoBox                                                   */
+/* Description:      Represents the G4Box Geant Geometry entity              */
+/* Author:           Joe Boudreau Nov 11 1996                                */
+/*                                                                           */
+/*---------------------------------------------------------------------------*/
+#ifndef HEPVis_SoBox_h
+#define HEPVis_SoBox_h
+
+#include <Inventor/fields/SoSFFloat.h>
+#include <Inventor/fields/SoSFNode.h>
+#include <Inventor/nodes/SoShape.h>
+
+class SoSFNode;
+
+//! SoBox - Inventor version of the G4Box Geant Geometry entity
+/*!
+ * Node:	     SoBox
+ * 
+ * Description:      The Inventor version of the G4Box Geant Geometry entity
+ * 
+ * Author:	     Joe Boudreau Nov 11 1996
+ * 
+ * class G4Box
+ *
+ * A Box is a cuboid of given half lengths dx,dy,dz. The Box is
+ * centred on the origin with sides parallel to the x/y/z axes.
+ *
+ * Always use Inventor Fields. This allows Inventor to detect a change to
+ * the data field and take the appropriate action; e.g., redraw the scene.
+*/
+
+#define SoBox Geant4_SoBox
+
+class SoBox:public SoShape {
+
+  // The following is required:
+  SO_NODE_HEADER(SoBox);
+ 
+public:
+
+  //
+  //! Half-length along X
+  //
+  SoSFFloat fDx;   
+  //
+  //! Half-length along Y
+  //
+  SoSFFloat fDy;
+  //
+  //! Half-length along Z
+  //
+  SoSFFloat fDz;
+  //
+  //! Alternate rep - for use by users without HEPVis shared objects
+  //
+  SoSFNode  alternateRep;
+
+  //
+  //! Constructor, required
+  //
+  SoBox();
+
+  //
+  //! Class Initializer, required
+  //
+  static void initClass();
+
+  //
+  //! Generate AlternateRep, required.  Generating an alternate representation
+  //! must be done upon users request.  It allows an Inventor program to read
+  //! back the file without requiring *this* code to be dynamically linked. 
+  //! If the users expects that *this* code will be dynamically linked, he
+  //! need not invoke this method.  
+  //
+  virtual void generateAlternateRep();
+
+  //
+  //! We better be able to clear it, too!
+  //
+  virtual void clearAlternateRep();
+
+protected:
+
+  //
+  //! compute bounding Box, required
+  //
+  virtual void computeBBox(SoAction *action, SbBox3f &box, SbVec3f &center );
+
+  //
+  //! Generate Primitives, required
+  //
+  virtual void generatePrimitives(SoAction *action);
+
+  //
+  //! GetChildList, required whenever the class has hidden children
+  //
+  virtual SoChildList *getChildren() const;
+
+
+protected:
+  //
+  //! Destructor, required
+  //
+  virtual ~SoBox();
+
+private: 
+
+  //
+  //! Generate Children. Used to create the hidden children. Required whenever
+  //! the node has hidden children.  
+  //
+  void generateChildren();  
+
+  //
+  //! Used to modify hidden children when a data field is changed. Required 
+  //! whenever the class has hidden children. 
+  //
+  void updateChildren();
+
+  //
+  //! ChildList. Required whenever the class has hidden children.  
+  //
+  SoChildList *children;
+
+};
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoCons.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoCons.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoCons.h	(revision 529)
@@ -0,0 +1,194 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: SoCons.h,v 1.3 2006/06/29 21:21:20 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+/*-----------------------------Hepvis----------------------------------------*/
+/*                                                                           */
+/* Node:             SoCons                                                  */
+/* Description:      Represents the G4Cons Geant Geometry entity             */
+/* Author:           Joe Boudreau Nov 11 1996                                */
+/*                                                                           */
+/*---------------------------------------------------------------------------*/
+#ifndef HEPVis_SoCons_h
+#define HEPVis_SoCons_h
+
+#include <Inventor/fields/SoSFFloat.h>
+#include <Inventor/fields/SoSFNode.h>
+#include <Inventor/fields/SoSFBool.h>
+#include <Inventor/nodes/SoShape.h>
+
+class SoSFNode;
+//! SoCons - Inventor version of the G4Cons Geant Geometry entity
+/*!
+ * Node:	     SoCons
+ *
+ * Description:      The Inventor version of the G4Cons Geant Geometry entity
+ *
+ * Author:	     Joe Boudreau Nov 11 1996
+ *
+ * A G4Cons is, in the general case, a Phi segment of a cone, with half-length
+ * fDz, inner and outer radii specified at -fDz and +fDz. The Phi segment is
+ * described by a starting fSPhi angle, and the +fDPhi delta angle for the shape.
+ * If the delta angle is >=2*M_PI, the shape is treated as continuous in Phi
+ *
+ * Member Data:
+ *
+ *      fRmin1  inside radius at  -fDz
+ *      fRmin2  inside radius at  +fDz
+ *      fRmax1  outside radius at -fDz
+ *      fRmax2  outside radius at +fDz
+ *      fDz     half length in z
+ *
+ *      fSPhi   starting angle of the segment in radians
+ *      fDPhi   delta angle of the segment in radians
+*/
+
+#define SoCons Geant4_SoCons
+
+class SoCons:public SoShape {
+
+  // The following is required:
+  SO_NODE_HEADER(SoCons);
+ 
+public:
+
+  //
+  //! Inside radius at -fDz
+  //
+  SoSFFloat fRmin1;   
+  //
+  //! Inside radius at +fDz
+  //
+  SoSFFloat fRmin2;   
+  //
+  //! Outside radius at -fDz
+  //
+  SoSFFloat fRmax1;
+  //
+  //! Outside radius at +fDz
+  //
+  SoSFFloat fRmax2;
+  //
+  //! Half-length along Z
+  //
+  SoSFFloat fDz;
+  //
+  //! Starting angle, in radians
+  //
+  SoSFFloat fSPhi;
+  //
+  //! Delta-angle, in radians
+  //
+  SoSFFloat fDPhi;             
+  //
+  //! An Inventor option - slightly better render, worse performance
+  //
+  SoSFBool  smoothDraw;
+  //
+  //! Alternate rep required - for use by users without HEPVis shared objects
+  //
+  SoSFNode  alternateRep;
+
+  //
+  //! Constructor, required
+  //
+  SoCons();
+
+  //
+  //! Class Initializer, required
+  //
+  static void initClass();
+
+  //
+  //! Generate AlternateRep, required.  Generating an alternate representation
+  //! must be done upon users request.  It allows an Inventor program to read
+  //! back the file without requiring *this* code to be dynamically linked. 
+  //! If the users expects that *this* code will be dynamically linked, he
+  //! need not invoke this method.  
+  //
+  virtual void generateAlternateRep();
+
+  //
+  //! We better be able to clear it, too!
+  //
+  virtual void clearAlternateRep();
+
+protected:
+
+  //
+  //! compute bounding Box, required
+  //
+  virtual void computeBBox(SoAction *action, SbBox3f &box, SbVec3f &center );
+
+  //
+  //! Generate Primitives, required
+  //
+  virtual void generatePrimitives(SoAction *action);
+
+  //
+  //! GetChildList, required whenever the class has hidden children
+  //
+  virtual SoChildList *getChildren() const;
+
+
+protected:
+  //
+  //! Destructor, required
+  //
+  virtual ~SoCons();
+
+private: 
+
+  //
+  //! Generate Children. Used to create the hidden children. Required whenever
+  //! the node has hidden children.  
+  //
+  void generateChildren();  
+
+  //
+  //! Used to modify hidden children when a data field is changed. Required 
+  //! whenever the class has hidden children. 
+  //
+  void updateChildren();
+
+  //
+  //! ChildList. Required whenever the class has hidden children.  
+  //
+  SoChildList *children;
+
+  //
+  //! help with trigonometry.  increments sines an cosines by an angle.
+  //
+  void inc(double & sinPhi, double & cosPhi, double sinDeltaPhi, double cosDeltaPhi) const {
+    double oldSin=sinPhi,oldCos=cosPhi;
+    sinPhi = oldSin*cosDeltaPhi+oldCos*sinDeltaPhi;
+    cosPhi = oldCos*cosDeltaPhi-oldSin*sinDeltaPhi;    
+  }
+};
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoImageWriter.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoImageWriter.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoImageWriter.h	(revision 529)
@@ -0,0 +1,67 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+////////////////////////////////////////////////////////////
+//
+//  This node is able to produce PostScript, GIF files. 
+//
+////////////////////////////////////////////////////////////
+
+
+#ifndef HEPVis_SoImageWriter_h
+#define HEPVis_SoImageWriter_h 
+
+#include <Inventor/nodes/SoSubNode.h>
+#include <Inventor/fields/SoSFEnum.h>
+#include <Inventor/fields/SoSFString.h>
+
+#define SoImageWriter Geant4_SoImageWriter
+
+class SoImageWriter : public SoNode {
+  SO_NODE_HEADER(SoImageWriter);
+public:
+/*  enum Format {
+    POST_SCRIPT,
+    GIF
+  };
+  SoSFEnum format;*/
+  SoSFString fileName;
+  SoImageWriter();
+  void enable();
+  void disable();
+  SbBool getStatus() const;
+protected:
+  virtual  ~SoImageWriter();
+public: /*SoEXTENDER*/
+  virtual void GLRender(SoGLRenderAction*);
+public: /*SoINTERNAL*/
+  static void initClass();
+private:
+  SbBool fEnabled;
+  SbBool fStatus;
+};
+
+#endif
+
Index: /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoMarkerSet.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoMarkerSet.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoMarkerSet.h	(revision 529)
@@ -0,0 +1,111 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+#ifndef HEPVis_SoMarkerSet_h
+#define HEPVis_SoMarkerSet_h 
+
+#include <Inventor/nodes/SoPointSet.h>
+
+#include <Inventor/fields/SoMFInt32.h>
+
+#define HEPVis_SoMarkerSet Geant4_HEPVis_SoMarkerSet
+
+class HEPVis_SoMarkerSet : public SoPointSet {
+  SO_NODE_HEADER(HEPVis_SoMarkerSet);
+public:
+  SoMFInt32 markerIndex ;
+  HEPVis_SoMarkerSet();
+
+  enum MarkerType {
+    //************ 5x5 markers
+    PLUS_5_5 = 0,
+    ASTERISK_5_5,
+    CROSS_5_5,
+    STAR_5_5,
+    CIRCLE_LINE_5_5,
+    CIRCLE_FILLED_5_5,
+    TRIANGLE_UP_LINE_5_5,
+    TRIANGLE_UP_FILLED_5_5,
+    TRIANGLE_DOWN_LINE_5_5,
+    TRIANGLE_DOWN_FILLED_5_5,
+    DAVID_STAR_LINE_5_5 = 10,
+    DAVID_STAR_FILLED_5_5,
+    SWISS_CROSS_LINE_5_5,
+    SWISS_CROSS_FILLED_5_5,
+    DIAMOND_LINE_5_5,
+    DIAMOND_FILLED_5_5,
+    SQUARE_LINE_5_5,
+    SQUARE_FILLED_5_5 = 17,
+
+    //************ 7x7 markers
+    PLUS_7_7 = 18,
+    ASTERISK_7_7,
+    CROSS_7_7,
+    STAR_7_7,
+    CIRCLE_LINE_7_7,
+    CIRCLE_FILLED_7_7,
+    TRIANGLE_UP_LINE_7_7,
+    TRIANGLE_UP_FILLED_7_7,
+    TRIANGLE_DOWN_LINE_7_7,
+    TRIANGLE_DOWN_FILLED_7_7,
+    DAVID_STAR_LINE_7_7,
+    DAVID_STAR_FILLED_7_7,
+    SWISS_CROSS_LINE_7_7 = 30,
+    SWISS_CROSS_FILLED_7_7,
+    DIAMOND_LINE_7_7,
+    DIAMOND_FILLED_7_7,
+    SQUARE_LINE_7_7,
+    SQUARE_FILLED_7_7 = 35,
+
+    //************ 9x9 markers
+    PLUS_9_9 = 36,
+    ASTERISK_9_9,
+    CROSS_9_9,
+    STAR_9_9,
+    CIRCLE_LINE_9_9,
+    CIRCLE_FILLED_9_9,
+    TRIANGLE_UP_LINE_9_9,
+    TRIANGLE_UP_FILLED_9_9,
+    TRIANGLE_DOWN_LINE_9_9,
+    TRIANGLE_DOWN_FILLED_9_9,
+    DAVID_STAR_LINE_9_9,
+    DAVID_STAR_FILLED_9_9,
+    SWISS_CROSS_LINE_9_9 = 30,
+    SWISS_CROSS_FILLED_9_9,
+    DIAMOND_LINE_9_9,
+    DIAMOND_FILLED_9_9,
+    SQUARE_LINE_9_9,
+    SQUARE_FILLED_9_9 = 53
+  } ;
+
+public: /*SoEXTENDER*/
+  virtual void GLRender(SoGLRenderAction*);
+public: /*SoINTERNAL*/
+  static void initClass();
+protected:
+  virtual ~HEPVis_SoMarkerSet();
+};
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoTrap.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoTrap.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoTrap.h	(revision 529)
@@ -0,0 +1,220 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: SoTrap.h,v 1.4 2006/06/29 21:22:06 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+/*-----------------------------Hepvis----------------------------------------*/
+/*                                                                           */
+/* Node:             SoTrap                                                  */
+/* Description:      Represents the G4Trap Geant Geometry entity             */
+/* Author:           Joe Boudreau Nov 11 1996                                */
+/*                                                                           */
+/*---------------------------------------------------------------------------*/
+#ifndef HEPVis_SoTrap_h
+#define HEPVis_SoTrap_h
+
+// Inheritance :
+#include <Inventor/nodes/SoShape.h>
+
+#include <Inventor/fields/SoSFNode.h>
+#include <Inventor/fields/SoSFBool.h>
+#include <Inventor/fields/SoSFFloat.h>
+
+//adding fields 
+#ifdef WIN32
+#include <SoWinEnterScope.h>
+#endif
+
+
+// Defining Class
+#ifdef WIN32
+#include <SoWinLeaveScope.h>
+#endif
+
+class SoSFNode;
+
+//! SoTrap - Inventor version of the G4Trap Geant Geometry entity
+/*! Node:          SoTrap
+ *
+ * Description:	   Inventor version of the G4Trap Geant Geometry entity
+ *
+ * Author:	   Joe Boudreau Nov 11 1996
+ *
+ * A G4Trap is a general trapezoid: The faces perpendicular to the z planes
+ * are tapezia, and their centres are not necessarily on a line parallel to
+ * the z axis.
+ *
+ * Note that of the 11 parameters desribed below, only 9 are really
+ * independent - a check for planarity is made in the calculation of the
+ * equation for each plane. If the planes are not parallel, a call to
+ * G4Exception is made.
+ *
+ * Always use Inventor Fields. This allows Inventor to detect a change to
+ * the data field and take the appropriate action; e.g., redraw the scene.
+ *
+*/
+
+#define SoTrap Geant4_SoTrap
+
+class SoTrap:public SoShape {
+
+  // The following is required:
+  SO_NODE_HEADER(SoTrap);
+ 
+public:
+#if defined(WIN32) && defined(BUILDING_DLL)
+   // When building the node as a DLL under Win32 we must explicitly
+   // declare this entry point as visible outside the DLL.  The macro
+   // BUILDING_DLL is defined in the node's source file.
+      _declspec(dllexport)
+#endif
+
+  //
+  //! half-length along Z
+  //
+  SoSFFloat pDz;                  
+  //
+  //! Polar angle of the line joining the centres of the faces at -/+pDz
+  //
+  SoSFFloat pTheta;
+  //
+  //! Azimuthal angle of the line joing the centre of the face at -pDz 
+  //! to the centre of the face at +pDz
+  //
+  SoSFFloat pPhi;
+  //
+  //! Half-length along y of the face at -pDz
+  //
+  SoSFFloat pDy1;
+  //
+  //! Half-length along x of the side at y=-pDy1 of the face at -pDz
+  //
+  SoSFFloat pDx1;
+  //
+  //! Half-length along x of the side at y=+pDy1 of the face at -pDz
+  //
+  SoSFFloat pDx2;
+  //
+  //! Half-length along y of the face at +pDz
+  //
+  SoSFFloat pDy2;
+  //
+  //! Half-length along x of the side at y=-pDy2 of the face at +pDz
+  //
+  SoSFFloat pDx3;
+  //
+  //! Half-length along x of the side at y=+pDy2 of the face at +pDz
+  //
+  SoSFFloat pDx4;
+  //
+  //! Angle with respect to the y axis from the centre of the side at 
+  //! y=-pDy1 to the centre at y=+pDy1 of the face at -pDz
+  //
+  SoSFFloat pAlp1;
+  //
+  //! Angle with respect to the y axis from the centre of the side at 
+  //! y=-pDy2 to the centre at y=+pDy2 of the face at +pDz
+  //
+  SoSFFloat pAlp2;
+ 
+  //
+  //! Alternate rep - required
+  //
+  SoSFNode  alternateRep;
+
+  //
+  //! Constructor, required
+  //
+  SoTrap();
+
+  //
+  //! Class Initializer, required
+  //
+  static void initClass();
+
+  //
+  //! Generate AlternateRep, required.  Generating an alternate representation
+  //! must be done upon users request.  It allows an Inventor program to read
+  //! back the file without requiring *this* code to be dynamically linked. 
+  //! If the users expects that *this* code will be dynamically linked, he
+  //! need not invoke this method.  
+  //
+  virtual void generateAlternateRep();
+
+  //
+  //! We better be able to clear it, too!
+  //
+  virtual void clearAlternateRep();
+
+protected:
+
+  //
+  //! compute bounding Box, required
+  //
+  virtual void computeBBox(SoAction *action, SbBox3f &box, SbVec3f &center );
+
+  //
+  //! Generate Primitives, required
+  //
+  virtual void generatePrimitives(SoAction *action);
+
+  //
+  //! GetChildList, required whenever the class has hidden children
+  //
+  virtual SoChildList *getChildren() const;
+
+  //
+  //! Destructor, required
+  //
+  virtual ~SoTrap();
+
+private: 
+
+  //
+  //! Generate Children. Used to create the hidden children. Required whenever
+  //! the node has hidden children.  
+  //
+  void generateChildren();  
+
+  //
+  //! Used to modify hidden children when a data field is changed. Required 
+  //! whenever the class has hidden children. 
+  //
+  void updateChildren();
+
+  //
+  //! ChildList. Required whenever the class has hidden children.  
+  //
+  SoChildList *children;
+
+};
+
+#ifdef WIN32
+#include <SoWinEnterScope.h>
+#endif
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoTrd.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoTrd.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoTrd.h	(revision 529)
@@ -0,0 +1,172 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: SoTrd.h,v 1.3 2006/06/29 21:22:08 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+/*-----------------------------Hepvis----------------------------------------*/
+/*                                                                           */
+/* Node:             SoTrd                                                   */
+/* Description:      Represents the G4Trd Geant Geometry entity              */
+/* Author:           Joe Boudreau Nov 11 1996                                */
+/*                                                                           */
+/*---------------------------------------------------------------------------*/
+#ifndef HEPVis_SoTrd_h
+#define HEPVis_SoTrd_h
+
+#include <Inventor/fields/SoSFFloat.h>
+#include <Inventor/fields/SoSFNode.h>
+#include <Inventor/fields/SoSFBool.h>
+#include <Inventor/nodes/SoShape.h>
+
+class SoSFNode;
+
+//! SoTrd - Inventor version of the G4Trd Geant Geometry entity
+/*!
+ * Node:            SoTrd
+ * 
+ * Description:     Inventor version of the G4Trd Geant Geometry entity
+ * 
+ * Author:	    Joe Boudreau Nov 11 1996
+ * 
+ * A Trd is a trapezoid with the x and y dimensions varying along z
+ *
+ * Always use Inventor Fields. This allows Inventor to detect a change to
+ * the data field and take the appropriate action; e.g., redraw the scene.
+ *
+ */
+
+#define SoTrd Geant4_SoTrd
+
+class SoTrd:public SoShape {
+
+  //
+  //! This is required
+  //
+  SO_NODE_HEADER(SoTrd);
+ 
+public:
+
+  //
+  //! half-length of x, at -fDz
+  //
+  SoSFFloat fDx1;                  
+
+  //
+  //! half-length of x, at +fDz
+  //
+  SoSFFloat fDx2;
+
+  //
+  //! half-length of y, at -fDz
+  //
+  SoSFFloat fDy1;
+
+  //
+  //! half-length of y, at +fDz
+  //
+  SoSFFloat fDy2;
+
+  //
+  //! half-length along Z
+  //
+  SoSFFloat fDz;
+
+  //
+  //! Alternate rep - required
+  //
+  SoSFNode  alternateRep;
+
+  //
+  //! Constructor, required
+  //
+  SoTrd();
+
+  //
+  //! Class Initializer, required
+  //
+  static void initClass();
+
+  //
+  //! Generate AlternateRep, required.  Generating an alternate representation
+  //! must be done upon users request.  It allows an Inventor program to read
+  //! back the file without requiring *this* code to be dynamically linked. 
+  //! If the users expects that *this* code will be dynamically linked, he
+  //! need not invoke this method.  
+  //
+  virtual void generateAlternateRep();
+
+  //
+  //! We better be able to clear it, too!
+  //
+  virtual void clearAlternateRep();
+
+protected:
+
+  //
+  //! compute bounding Box, required
+  //
+  virtual void computeBBox(SoAction *action, SbBox3f &box, SbVec3f &center );
+
+  //
+  //! Generate Primitives, required
+  //
+  virtual void generatePrimitives(SoAction *action);
+
+  //
+  //! GetChildList, required whenever the class has hidden children
+  //
+  virtual SoChildList *getChildren() const;
+
+
+protected:
+
+  //
+  //! Destructor, required
+  //
+  virtual ~SoTrd();
+
+private: 
+
+  //
+  //! Generate Children. Used to create the hidden children. Required whenever
+  //! the node has hidden children.  
+  //
+  void generateChildren();  
+
+  //
+  //! Used to modify hidden children when a data field is changed. Required 
+  //! whenever the class has hidden children. 
+  //
+  void updateChildren();
+
+  //
+  //! ChildList. Required whenever the class has hidden children.  
+  //
+  SoChildList *children;
+};
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoTubs.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoTubs.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/HEPVis/nodes/SoTubs.h	(revision 529)
@@ -0,0 +1,183 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: SoTubs.h,v 1.3 2006/06/29 21:22:10 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+/*-----------------------------Hepvis----------------------------------------*/
+/*                                                                           */
+/* Node:             SoTubs                                                  */
+/* Description:      Represents the G4Tubs Geant Geometry entity             */
+/* Author:           Joe Boudreau Nov 11 1996                                */
+/*                                                                           */
+/*---------------------------------------------------------------------------*/
+#ifndef HEPVis_SoTubs_h
+#define HEPVis_SoTubs_h
+
+#include <Inventor/fields/SoSFFloat.h>
+#include <Inventor/fields/SoSFNode.h>
+#include <Inventor/fields/SoSFBool.h>
+#include <Inventor/nodes/SoShape.h>
+
+class SoSFNode;
+
+//! SoTubs - Inventor version of the G4Tubs Geant Geometry entity
+/*!
+ * Node:	     SoTubs
+ * 
+ * Description:      The Inventor version of the G4Tubs Geant Geometry entity
+ * 
+ * Author:	     Joe Boudreau Nov 11 1996
+ * 
+ * class G4Tubs
+ * 
+ * A tube or tube segment with curved sides parallel to
+ * the z-axis. The tube has a specified half-length along
+ * the z axis, about which it is centred, and a given
+ * minimum and maximum radius. A minimum radius of 0
+ * signifies a filled tube /cylinder. The tube segment is
+ * specified by starting and delta
+ * angles for phi, with 0 being the +x axis, PI/2
+ * the +y axis. A delta angle of 2PI signifies a
+ * complete, unsegmented tube/cylinder
+ *
+ * Always use Inventor Fields. This allows Inventor to detect a change to
+ * the data field and take the appropriate action; e.g., redraw the scene.
+*/
+
+#define SoTubs Geant4_SoTubs
+
+class SoTubs:public SoShape {
+
+  // The following is required:
+  SO_NODE_HEADER(SoTubs);
+ 
+public:
+
+  //
+  //! Inside radius of the tube
+  //
+  SoSFFloat pRMin;   
+  //
+  //! Outside radius of the tube
+  //
+  SoSFFloat pRMax;
+  //
+  //! Half-length in Z
+  //
+  SoSFFloat pDz;
+  //
+  //! Starting angle, in radians
+  //
+  SoSFFloat pSPhi;
+  //
+  //! Delta-angle, in radians
+  //
+  SoSFFloat pDPhi;             
+  //
+  //! Alternate rep - required
+  //
+  SoSFNode  alternateRep;
+
+  //
+  //! Constructor, required
+  //
+  SoTubs();
+
+  //
+  //! Class Initializer, required
+  //
+  static void initClass();
+
+  //
+  //! Generate AlternateRep, required.  Generating an alternate representation
+  //! must be done upon users request.  It allows an Inventor program to read
+  //! back the file without requiring *this* code to be dynamically linked. 
+  //! If the users expects that *this* code will be dynamically linked, he
+  //! need not invoke this method.  
+  //
+  virtual void generateAlternateRep();
+
+  //
+  //! We better be able to clear it, too!
+  //
+  virtual void clearAlternateRep();
+
+protected:
+
+  //
+  //! compute bounding Box, required
+  //
+  virtual void computeBBox(SoAction *action, SbBox3f &box, SbVec3f &center );
+
+  //
+  //! Generate Primitives, required
+  //
+  virtual void generatePrimitives(SoAction *action);
+
+  //
+  //! GetChildList, required whenever the class has hidden children
+  //
+  virtual SoChildList *getChildren() const;
+
+
+protected:
+  //
+  //! Destructor, required
+  //
+  virtual ~SoTubs();
+
+private: 
+
+  //
+  //! Generate Children. Used to create the hidden children. Required whenever
+  //! the node has hidden children.  
+  //
+  void generateChildren();  
+
+  //
+  //! Used to modify hidden children when a data field is changed. Required 
+  //! whenever the class has hidden children. 
+  //
+  void updateChildren();
+
+  //
+  //! ChildList. Required whenever the class has hidden children.  
+  //
+  SoChildList *children;
+
+  //
+  //! help with trigonometry.  increments sines an cosines by an angle.
+  //
+  void inc(double & sinPhi, double & cosPhi, double sinDeltaPhi, double cosDeltaPhi) const {
+    double oldSin=sinPhi,oldCos=cosPhi;
+    sinPhi = oldSin*cosDeltaPhi+oldCos*sinDeltaPhi;
+    cosPhi = oldCos*cosDeltaPhi-oldSin*sinDeltaPhi;    
+  }
+
+};
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/include/SoG4LineSet.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/SoG4LineSet.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/SoG4LineSet.h	(revision 529)
@@ -0,0 +1,41 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: SoG4LineSet.h,v 1.2 2006/12/13 15:49:51 gunter Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// John Allison  26th October 2006
+// Extended SoLineSet to include G4Atts.
+
+#ifndef SoG4LineSet_h
+#define SoG4LineSet_h
+
+// Inheritance :
+#include <Inventor/nodes/SoLineSet.h>
+#include "G4AttHolder.hh"
+
+class SoG4LineSet: public SoLineSet, public G4AttHolder {};
+
+#endif  //SoG4LineSet_h
Index: /trunk/geant4/visualization/OpenInventor/include/SoG4MarkerSet.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/SoG4MarkerSet.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/SoG4MarkerSet.h	(revision 529)
@@ -0,0 +1,41 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: SoG4MarkerSet.h,v 1.2 2006/12/13 15:49:53 gunter Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// John Allison  26th October 2006
+// Extended SoMarkerSet to include G4Atts.
+
+#ifndef SoG4MarkerSet_h
+#define SoG4MarkerSet_h
+
+// Inheritance :
+#include <HEPVis/nodes/SoMarkerSet.h>
+#include "G4AttHolder.hh"
+
+class SoG4MarkerSet: public SoMarkerSet, public G4AttHolder {};
+
+#endif  //SoG4MarkerSet_h
Index: /trunk/geant4/visualization/OpenInventor/include/SoG4Polyhedron.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/include/SoG4Polyhedron.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/include/SoG4Polyhedron.h	(revision 529)
@@ -0,0 +1,48 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: SoG4Polyhedron.h,v 1.2 2006/12/13 15:49:56 gunter Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// John Allison  26th October 2006
+// Extended Geant4_SoPolyhedron to include G4Atts.
+
+#ifndef SoG4Polyhedron_h
+#define SoG4Polyhedron_h
+
+// Inheritance :
+#include <Geant4_SoPolyhedron.h>
+#include "G4AttHolder.hh"
+
+class G4Polyhedron;
+
+class SoG4Polyhedron: public Geant4_SoPolyhedron, public G4AttHolder {
+ public:
+  SoG4Polyhedron(const G4Polyhedron& polyhedron):
+    Geant4_SoPolyhedron(polyhedron){}
+};
+
+#endif  //SoG4Polyhedron_h
Index: /trunk/geant4/visualization/OpenInventor/src/G4OpenInventor.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/G4OpenInventor.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/G4OpenInventor.cc	(revision 529)
@@ -0,0 +1,94 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenInventor.cc,v 1.20 2006/06/29 21:22:12 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+// this :
+#include "G4OpenInventor.hh"
+
+#include "HEPVis/nodes/SoBox.h"
+#include "HEPVis/nodes/SoTubs.h"
+#include "HEPVis/nodes/SoCons.h"
+#include "HEPVis/nodes/SoTrd.h"
+#include "HEPVis/nodes/SoTrap.h"
+#include "HEPVis/nodes/SoMarkerSet.h"
+#include "HEPVis/nodes/SoImageWriter.h"
+#include "HEPVis/nodekits/SoDetectorTreeKit.h"
+#include "HEPVis/actions/SoGL2PSAction.h"
+#include "HEPVis/actions/SoCounterAction.h"
+#include "HEPVis/actions/SoAlternateRepAction.h"
+
+#include "Geant4_SoPolyhedron.h"
+
+#include "G4OpenInventorSceneHandler.hh"
+
+G4OpenInventor::G4OpenInventor (
+ const G4String name
+,const G4String nickname
+,G4VGraphicsSystem::Functionality f
+)
+:G4VGraphicsSystem(name,nickname,f)
+,interactorManager(0)
+{
+}
+
+G4OpenInventor::~G4OpenInventor () {}
+
+void G4OpenInventor::SetInteractorManager (G4VInteractorManager* im) {
+  interactorManager = im;
+}
+G4VInteractorManager* G4OpenInventor::GetInteractorManager () {
+  return interactorManager;
+}
+G4VSceneHandler* G4OpenInventor::CreateSceneHandler (const G4String& name) {
+  Initialize();
+  G4VSceneHandler* p = new G4OpenInventorSceneHandler (*this, name);
+  return    p;
+}
+
+void G4OpenInventor::InitNodes()
+{
+  SoBox::initClass();
+  SoTubs::initClass();
+  SoCons::initClass();
+  SoTrd::initClass();
+  SoTrap::initClass();
+  SoDetectorTreeKit::initClass();
+  HEPVis_SoMarkerSet::initClass();
+  SoImageWriter::initClass();
+  Geant4_SoPolyhedron::initClass();
+
+  SoGL2PSAction::initClass();
+  SoCounterAction::initClass();
+  SoAlternateRepAction::initClass();
+}
+
+
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorSceneHandler.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorSceneHandler.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorSceneHandler.cc	(revision 529)
@@ -0,0 +1,886 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenInventorSceneHandler.cc,v 1.50 2006/11/05 20:48:57 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+//
+// 
+// Jeff Kallenbach 01 Aug 1996
+// OpenInventor stored scene - creates OpenInventor display lists.
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+// this :
+#include "G4OpenInventorSceneHandler.hh"
+
+#include <Inventor/SoPath.h>
+#include <Inventor/SoNodeKitPath.h>
+#include <Inventor/nodes/SoCoordinate3.h>
+#include <Inventor/nodes/SoCoordinate4.h>
+#include <Inventor/nodes/SoSeparator.h>
+#include <Inventor/nodes/SoDrawStyle.h>
+#include <Inventor/nodes/SoLightModel.h>
+#include <Inventor/nodes/SoMaterial.h>
+#include <Inventor/nodes/SoLineSet.h>
+#include <Inventor/nodes/SoCube.h>
+#include <Inventor/nodes/SoSphere.h>
+#include <Inventor/nodes/SoFont.h>
+#include <Inventor/nodes/SoText2.h>
+#include <Inventor/nodes/SoFaceSet.h>
+#include <Inventor/nodes/SoNormal.h>
+#include <Inventor/nodes/SoNormalBinding.h>
+#include <Inventor/nodes/SoComplexity.h>
+#include <Inventor/nodes/SoNurbsSurface.h>
+#include <Inventor/nodes/SoTranslation.h>
+#include <Inventor/nodes/SoTransform.h>
+#include <Inventor/nodes/SoResetTransform.h>
+#include <Inventor/nodes/SoMatrixTransform.h>
+
+#define USE_SOPOLYHEDRON
+
+#ifndef USE_SOPOLYHEDRON
+#include "HEPVis/nodes/SoBox.h"
+#include "HEPVis/nodes/SoTubs.h"
+#include "HEPVis/nodes/SoCons.h"
+#include "HEPVis/nodes/SoTrd.h"
+#include "HEPVis/nodes/SoTrap.h"
+#endif
+#include "HEPVis/nodes/SoMarkerSet.h"
+typedef HEPVis_SoMarkerSet SoMarkerSet;
+#include "HEPVis/nodekits/SoDetectorTreeKit.h"
+#include "HEPVis/misc/SoStyleCache.h"
+
+#include "SoG4Polyhedron.h"
+#include "SoG4LineSet.h"
+#include "SoG4MarkerSet.h"
+
+#include "G4Scene.hh"
+#include "G4NURBS.hh"
+#include "G4OpenInventor.hh"
+#include "G4OpenInventorTransform3D.hh"
+#include "G4ThreeVector.hh"
+#include "G4Point3D.hh"
+#include "G4Normal3D.hh"
+#include "G4Transform3D.hh"
+#include "G4Polyline.hh"
+#include "G4Text.hh"
+#include "G4Circle.hh"
+#include "G4Square.hh"
+#include "G4Polymarker.hh"
+#include "G4Polyhedron.hh"
+#include "G4Box.hh"
+#include "G4Tubs.hh"
+#include "G4Cons.hh"
+#include "G4Trap.hh"
+#include "G4Trd.hh"
+#include "G4PhysicalVolumeModel.hh"
+#include "G4TrajectoriesModel.hh"
+#include "G4VTrajectory.hh"
+#include "G4VTrajectoryPoint.hh"
+#include "G4HitsModel.hh"
+#include "G4VHit.hh"
+#include "G4ModelingParameters.hh"
+#include "G4VPhysicalVolume.hh"
+#include "G4LogicalVolume.hh"
+#include "G4Material.hh"
+#include "G4VisAttributes.hh"
+
+G4int G4OpenInventorSceneHandler::fSceneIdCount = 0;
+
+G4OpenInventorSceneHandler::G4OpenInventorSceneHandler (G4OpenInventor& system,
+                                          const G4String& name)
+:G4VSceneHandler (system, fSceneIdCount++, name)
+,fRoot(0)
+,fDetectorRoot(0)
+,fTransientRoot(0)
+,fCurrentSeparator(0)
+,fModelingSolid(false)
+,fReducedWireFrame(true)
+,fStyleCache(0)
+,fPreviewAndFull(false)
+{
+  fStyleCache = new SoStyleCache;
+  fStyleCache->ref();
+
+  fRoot = new SoSeparator;
+  fRoot->ref();
+  fRoot->setName("Root");
+  
+  fDetectorRoot = new SoSeparator;
+  fDetectorRoot->setName("StaticRoot");
+  fRoot->addChild(fDetectorRoot);
+  
+  fTransientRoot = new SoSeparator;
+  fTransientRoot->setName("TransientRoot");
+  fRoot->addChild(fTransientRoot);
+  
+  fCurrentSeparator = fTransientRoot;
+}
+
+G4OpenInventorSceneHandler::~G4OpenInventorSceneHandler ()
+{
+  fRoot->unref();
+  fStyleCache->unref();
+}
+
+void G4OpenInventorSceneHandler::ClearStore () {
+  G4VSceneHandler::ClearStore();
+
+  fDetectorRoot->removeAllChildren();
+  fSeparatorMap.clear();
+
+  fTransientRoot->removeAllChildren();
+}
+
+void G4OpenInventorSceneHandler::ClearTransientStore () {
+  G4VSceneHandler::ClearTransientStore ();
+
+  fTransientRoot->removeAllChildren();
+}
+
+//
+// Generates prerequisites for solids
+//  
+void G4OpenInventorSceneHandler::PreAddSolid
+(const G4Transform3D& objectTransformation,
+ const G4VisAttributes& visAttribs)
+{
+  G4VSceneHandler::PreAddSolid (objectTransformation, visAttribs);
+  // Stores arguments away for future use, e.g., AddPrimitives.
+
+  GeneratePrerequisites();
+}
+
+//
+// Generates prerequisites for primitives
+//  
+void G4OpenInventorSceneHandler::BeginPrimitives
+(const G4Transform3D& objectTransformation) {
+
+  G4VSceneHandler::BeginPrimitives (objectTransformation);
+
+  // If thread of control has already passed through PreAddSolid,
+  // avoid opening a graphical data base component again.
+  if (!fProcessingSolid) {
+    GeneratePrerequisites();
+  }
+}
+
+void G4OpenInventorSceneHandler::LoadAtts
+(const G4Visible& visible,
+ G4AttHolder* holder)
+{
+  // Load G4Atts from G4VisAttributes, if any...
+  const std::map<G4String,G4AttDef>* vaDefs =
+    visible.GetVisAttributes()->GetAttDefs();
+  if (vaDefs) {
+    holder->AddAtts(visible.GetVisAttributes()->CreateAttValues(), vaDefs);
+  }
+
+  G4PhysicalVolumeModel* pPVModel =
+    dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
+  if (pPVModel) {
+    // Load G4Atts from G4PhysicalVolumeModel...
+    const std::map<G4String,G4AttDef>* defs = pPVModel->GetAttDefs();
+    if (defs) {
+      holder->AddAtts(pPVModel->CreateCurrentAttValues(), defs);
+    }
+  }
+
+  G4TrajectoriesModel* trajModel = dynamic_cast<G4TrajectoriesModel*>(fpModel);
+  if (trajModel) {
+    // Load G4Atts from trajectory...
+    const G4VTrajectory* traj = trajModel->GetCurrentTrajectory();
+    const std::map<G4String,G4AttDef>* defs = traj->GetAttDefs();
+    if (defs) {
+      holder->AddAtts(traj->CreateAttValues(), defs);
+    }
+    G4int nPoints = traj->GetPointEntries();
+    for (G4int i = 0; i < nPoints; ++i) {
+      G4VTrajectoryPoint* trajPoint = traj->GetPoint(i);
+      const std::map<G4String,G4AttDef>* defs = trajPoint->GetAttDefs();
+      if (defs) {
+	holder->AddAtts(trajPoint->CreateAttValues(), defs);
+      }
+    }
+  }
+
+  G4HitsModel* hitsModel = dynamic_cast<G4HitsModel*>(fpModel);
+  if (hitsModel) {
+    // Load G4Atts from hit...
+    const G4VHit* hit = hitsModel->GetCurrentHit();
+    const std::map<G4String,G4AttDef>* defs = hit->GetAttDefs();
+    if (defs) {
+      holder->AddAtts(hit->CreateAttValues(), defs);
+    }
+  }
+}
+
+//
+// Method for handling G4Polyline objects (from tracking).
+//
+void G4OpenInventorSceneHandler::AddPrimitive (const G4Polyline& line) {
+  G4int nPoints = line.size();
+  SbVec3f* pCoords = new SbVec3f[nPoints];
+
+  for (G4int iPoint = 0; iPoint < nPoints ; iPoint++) {
+    pCoords[iPoint].setValue((float)line[iPoint].x(),
+                             (float)line[iPoint].y(),
+                             (float)line[iPoint].z());
+  }
+
+  // Don't understand why I have to do this again (done in
+  // GeneratePrerequisites) - JA.
+  //
+  // Color
+  //
+  const G4Colour& c = GetColour (line);
+  SoMaterial* material = 
+    fStyleCache->getMaterial((float)c.GetRed(),
+                             (float)c.GetGreen(),
+                             (float)c.GetBlue(),
+                             (float)(1-c.GetAlpha()));
+  fCurrentSeparator->addChild(material);
+  
+  //
+  // Point Set
+  // 
+  SoCoordinate3 *polyCoords = new SoCoordinate3;
+  polyCoords->point.setValues(0,nPoints,pCoords);
+  fCurrentSeparator->addChild(polyCoords);
+  
+  //
+  // Wireframe
+  // 
+  SoDrawStyle* drawStyle = fStyleCache->getLineStyle();
+  fCurrentSeparator->addChild(drawStyle);
+
+  SoG4LineSet *pLine = new SoG4LineSet;
+
+  // Loads G4Atts for picking...
+  LoadAtts(line, pLine);
+
+#ifdef INVENTOR2_0
+  pLine->numVertices.setValues(0,1,(const long *)&nPoints);
+#else 
+  pLine->numVertices.setValues(0,1,&nPoints);
+#endif
+
+  fCurrentSeparator->addChild(pLine);
+
+  delete [] pCoords;
+}
+
+void G4OpenInventorSceneHandler::AddPrimitive (const G4Polymarker& polymarker) {
+  G4int pointn = polymarker.size();
+  if(pointn<=0) return;
+
+  SbVec3f* points = new SbVec3f[pointn];
+  for (G4int iPoint = 0; iPoint < pointn ; iPoint++) {
+    points[iPoint].setValue((float)polymarker[iPoint].x(),
+                            (float)polymarker[iPoint].y(),
+                            (float)polymarker[iPoint].z());
+  }
+
+  // Don't understand why I have to do this again (done in
+  // GeneratePrerequisites) - JA.
+  const G4Colour& c = GetColour (polymarker);
+  SoMaterial* material = 
+    fStyleCache->getMaterial((float)c.GetRed(),
+                             (float)c.GetGreen(),
+                             (float)c.GetBlue(),
+                             (float)(1-c.GetAlpha()));
+  fCurrentSeparator->addChild(material);
+  
+  SoCoordinate3* coordinate3 = new SoCoordinate3;
+  coordinate3->point.setValues(0,pointn,points);
+  fCurrentSeparator->addChild(coordinate3);
+
+  MarkerSizeType sizeType;
+  G4double screenSize = GetMarkerSize (polymarker, sizeType);
+  switch (sizeType) {
+  default:
+  case screen:
+    // Draw in screen coordinates.  OK.
+    break;
+  case world:
+    // Draw in world coordinates.   Not implemented.  Use screenSize = 10.
+    screenSize = 10.;
+    break;
+  }
+  
+  SoG4MarkerSet* markerSet = new SoG4MarkerSet;
+  markerSet->numPoints = pointn;
+
+  // Loads G4Atts for picking...
+  LoadAtts(polymarker, markerSet);
+
+  G4VMarker::FillStyle style = polymarker.GetFillStyle();
+  switch (polymarker.GetMarkerType()) {
+  default:
+    // Are available 5_5, 7_7 and 9_9
+  case G4Polymarker::dots:
+    if (screenSize <= 5.) {
+      markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_5_5;
+    } else if (screenSize <= 7.) {
+      markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_7_7;
+    } else {
+      markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_9_9;
+    }
+    break;
+  case G4Polymarker::circles:
+    if (screenSize <= 5.) {
+      if (style == G4VMarker::filled) {
+	markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_5_5;
+      } else {
+	markerSet->markerIndex = SoMarkerSet::CIRCLE_LINE_5_5;
+      }
+    } else if (screenSize <= 7.) {
+      if (style == G4VMarker::filled) {
+	markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_7_7;
+      } else {
+	markerSet->markerIndex = SoMarkerSet::CIRCLE_LINE_7_7;
+      }
+    } else {
+      if (style == G4VMarker::filled) {
+	markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_9_9;
+      } else {
+	markerSet->markerIndex = SoMarkerSet::CIRCLE_LINE_9_9;
+      }
+    }
+    break;
+  case G4Polymarker::squares:
+    if (screenSize <= 5.) {
+      if (style == G4VMarker::filled) {
+	markerSet->markerIndex = SoMarkerSet::SQUARE_FILLED_5_5;
+      } else {
+	markerSet->markerIndex = SoMarkerSet::SQUARE_LINE_5_5;
+      }
+    } else if (screenSize <= 7.) {
+      if (style == G4VMarker::filled) {
+	markerSet->markerIndex = SoMarkerSet::SQUARE_FILLED_7_7;
+      } else {
+	markerSet->markerIndex = SoMarkerSet::SQUARE_LINE_7_7;
+      }
+    } else {
+      if (style == G4VMarker::filled) {
+	markerSet->markerIndex = SoMarkerSet::SQUARE_FILLED_9_9;
+      } else {
+	markerSet->markerIndex = SoMarkerSet::SQUARE_LINE_9_9;
+      }
+    }
+  }
+  fCurrentSeparator->addChild(markerSet);
+
+  delete [] points;
+}
+
+// ********* NOTE ********* NOTE ********* NOTE ********* NOTE *********
+//
+//  This method (Text) has not been tested, as it is 
+//  innaccessible from the menu in the current configuration
+//
+//  Currently draws at the origin!  How do I get it to draw at
+//  text.GetPosition()?  JA
+//
+// ********* NOTE ********* NOTE ********* NOTE ********* NOTE *********
+//
+// Method for handling G4Text objects
+//
+void G4OpenInventorSceneHandler::AddPrimitive (const G4Text& text) {
+  //
+  // Color.  Note: text colour is worked out differently.  This
+  // over-rides the colour added in GeneratePrerequisites...
+  //
+  const G4Colour& c = GetTextColour (text);
+  SoMaterial* material = 
+    fStyleCache->getMaterial((float)c.GetRed(),
+                             (float)c.GetGreen(),
+                             (float)c.GetBlue(),
+                             (float)(1-c.GetAlpha()));
+  fCurrentSeparator->addChild(material);
+
+  MarkerSizeType sizeType;
+  G4double size = GetMarkerSize (text, sizeType);
+  switch (sizeType) {
+  default:
+  case screen:
+    // Draw in screen coordinates.  OK.
+    break;
+  case world:
+    // Draw in world coordinates.   Not implemented.  Use size = 20.
+    size = 20.;
+    break;
+  }
+
+  //
+  // Font
+  // 
+  SoFont *g4Font = new SoFont();
+  g4Font->size = size;
+  fCurrentSeparator->addChild(g4Font);
+
+  //
+  // Text
+  // 
+  SoText2 *g4String = new SoText2();
+  g4String->string.setValue(text.GetText());
+  g4String->spacing = 2.0;
+  switch (text.GetLayout()) {
+  default:
+  case G4Text::left:
+    g4String->justification = SoText2::LEFT; break;
+  case G4Text::centre:
+    g4String->justification = SoText2::CENTER; break;
+  case G4Text::right:
+    g4String->justification = SoText2::RIGHT; break;
+  }
+  fCurrentSeparator->addChild(g4String);
+}
+
+//
+// Method for handling G4Circle objects
+//
+void G4OpenInventorSceneHandler::AddPrimitive (const G4Circle& circle) {
+  AddCircleSquare(G4OICircle, circle);
+}
+
+//
+// Method for handling G4Square objects - defaults to wireframe
+//
+void G4OpenInventorSceneHandler::AddPrimitive (const G4Square& square) {
+  AddCircleSquare(G4OISquare, square);
+}
+
+void G4OpenInventorSceneHandler::AddCircleSquare
+(G4OIMarker markerType, const G4VMarker& marker) {
+
+  // Don't understand why I have to do this again (done in
+  // GeneratePrerequisites) - JA.
+  //
+  // Color
+  //
+  const G4Colour& c = GetColour (marker);
+  SoMaterial* material = 
+    fStyleCache->getMaterial((float)c.GetRed(),
+                             (float)c.GetGreen(),
+                             (float)c.GetBlue(),
+                             (float)(1-c.GetAlpha()));
+  fCurrentSeparator->addChild(material);
+
+  MarkerSizeType sizeType;
+  G4double screenSize = GetMarkerSize (marker, sizeType);
+  switch (sizeType) {
+  default:
+  case screen:
+    // Draw in screen coordinates.  OK.
+    break;
+  case world:
+    // Draw in world coordinates.   Not implemented.  Use size = 10.
+    screenSize = 10.;
+    break;
+  }
+
+  G4Point3D centre = marker.GetPosition();
+
+  // Borrowed from AddPrimitive(G4Polymarker) - inefficient? JA
+  SbVec3f* points = new SbVec3f[1];
+  points[0].setValue((float)centre.x(),
+		     (float)centre.y(),
+		     (float)centre.z());
+  SoCoordinate3* coordinate3 = new SoCoordinate3;
+  coordinate3->point.setValues(0,1,points);
+  fCurrentSeparator->addChild(coordinate3);
+
+  SoG4MarkerSet* markerSet = new SoG4MarkerSet;
+  markerSet->numPoints = 1;
+
+  // Loads G4Atts for picking...
+  LoadAtts(marker, markerSet);
+
+  G4VMarker::FillStyle style = marker.GetFillStyle();
+  switch (markerType) {
+  case G4OICircle:
+    if (screenSize <= 5.) {
+      if (style == G4VMarker::filled) {
+	markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_5_5;
+      } else {
+	markerSet->markerIndex = SoMarkerSet::CIRCLE_LINE_5_5;
+      }
+    } else if (screenSize <= 7.) {
+      if (style == G4VMarker::filled) {
+	markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_7_7;
+      } else {
+	markerSet->markerIndex = SoMarkerSet::CIRCLE_LINE_7_7;
+      }
+    } else {
+      if (style == G4VMarker::filled) {
+	markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_9_9;
+      } else {
+	markerSet->markerIndex = SoMarkerSet::CIRCLE_LINE_9_9;
+      }
+    }
+    break;
+  case G4OISquare:
+    if (screenSize <= 5.) {
+      if (style == G4VMarker::filled) {
+	markerSet->markerIndex = SoMarkerSet::SQUARE_FILLED_5_5;
+      } else {
+	markerSet->markerIndex = SoMarkerSet::SQUARE_LINE_5_5;
+      }
+    } else if (screenSize <= 7.) {
+      if (style == G4VMarker::filled) {
+	markerSet->markerIndex = SoMarkerSet::SQUARE_FILLED_7_7;
+      } else {
+	markerSet->markerIndex = SoMarkerSet::SQUARE_LINE_7_7;
+      }
+    } else {
+      if (style == G4VMarker::filled) {
+	markerSet->markerIndex = SoMarkerSet::SQUARE_FILLED_9_9;
+      } else {
+	markerSet->markerIndex = SoMarkerSet::SQUARE_LINE_9_9;
+      }
+    }
+  break;
+  }
+  fCurrentSeparator->addChild(markerSet);
+
+  delete [] points;
+}
+
+//
+// Method for handling G4Polyhedron objects for drawing solids.
+//
+void G4OpenInventorSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
+  if (polyhedron.GetNoFacets() == 0) return;
+
+  SoG4Polyhedron* soPolyhedron = new SoG4Polyhedron(polyhedron);
+
+  // Loads G4Atts for picking...
+  LoadAtts(polyhedron, soPolyhedron);
+
+  SbString name = "Non-geometry";
+  G4PhysicalVolumeModel* pPVModel =
+    dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
+  if (pPVModel) {
+    name = pPVModel->GetCurrentLV()->GetName().c_str();
+  }
+  SbName sbName(name);
+  soPolyhedron->setName(sbName);
+  soPolyhedron->solid.setValue(fModelingSolid);
+  soPolyhedron->reducedWireFrame.setValue(fReducedWireFrame?TRUE:FALSE);
+  fCurrentSeparator->addChild(soPolyhedron);  
+}
+
+//
+// Method for handling G4NURBS objects for drawing solids.
+// Knots and Ctrl Pnts MUST be arrays of GLfloats.
+//
+void G4OpenInventorSceneHandler::AddPrimitive (const G4NURBS& nurb) {
+
+  G4float *u_knot_array, *u_knot_array_ptr;
+  u_knot_array = u_knot_array_ptr = new G4float [nurb.GetnbrKnots(G4NURBS::U)];
+  G4NURBS::KnotsIterator u_iterator (nurb, G4NURBS::U);
+  while (u_iterator.pick (u_knot_array_ptr++));
+
+  G4float *v_knot_array, *v_knot_array_ptr;
+  v_knot_array = v_knot_array_ptr = new G4float [nurb.GetnbrKnots(G4NURBS::V)];
+  G4NURBS::KnotsIterator v_iterator (nurb, G4NURBS::V);
+  while (v_iterator.pick (v_knot_array_ptr++));
+
+  G4float *ctrl_pnt_array, *ctrl_pnt_array_ptr;
+  ctrl_pnt_array = ctrl_pnt_array_ptr =
+    new G4float [nurb.GettotalnbrCtrlPts () * G4NURBS::NofC*sizeof(G4float)];
+  G4NURBS::CtrlPtsCoordsIterator c_p_iterator (nurb);
+  while (c_p_iterator.pick (ctrl_pnt_array_ptr++));
+  
+  SoSeparator *surfSep = new SoSeparator();
+
+  //
+  // Color
+  //  
+  const G4Colour& c = GetColour (nurb);
+  SoMaterial* material = 
+    fStyleCache->getMaterial((float)c.GetRed(),
+                             (float)c.GetGreen(),
+                             (float)c.GetBlue(),
+                             (float)(1-c.GetAlpha()));
+  surfSep->addChild(material);
+
+  //
+  // Set up NURBS
+  //
+  SoComplexity *complexity = new SoComplexity;
+  SoCoordinate4 *ctlPts = new SoCoordinate4;
+  SoNurbsSurface *oi_nurb = new SoNurbsSurface;
+  
+  complexity->value = (float)0.6;
+  G4int    nPoints = nurb.GettotalnbrCtrlPts ();
+  SbVec4f* points  = new SbVec4f[nPoints];
+  for (G4int iPoint = 0; iPoint < nPoints ; iPoint++) {
+    points[iPoint].setValue(
+                            ctrl_pnt_array[iPoint*4 + 0],
+                            ctrl_pnt_array[iPoint*4 + 1],
+                            ctrl_pnt_array[iPoint*4 + 2],
+                            ctrl_pnt_array[iPoint*4 + 3]);
+  }
+  ctlPts->point.setValues (0,nPoints,points);
+  oi_nurb->numUControlPoints = nurb.GetnbrCtrlPts(G4NURBS::U);
+  oi_nurb->numVControlPoints = nurb.GetnbrCtrlPts(G4NURBS::V);
+  oi_nurb->uKnotVector.setValues(0,nurb.GetnbrKnots(G4NURBS::U),u_knot_array);
+  oi_nurb->vKnotVector.setValues(0,nurb.GetnbrKnots(G4NURBS::V),v_knot_array);
+
+  surfSep->addChild(complexity);
+  surfSep->addChild(ctlPts);
+  surfSep->addChild(oi_nurb);
+  
+  fCurrentSeparator->addChild(surfSep);
+
+  //
+  // Clean-up
+  //
+  delete [] u_knot_array;
+  delete [] v_knot_array;
+  delete [] ctrl_pnt_array;
+  delete [] points;
+}
+
+void G4OpenInventorSceneHandler::GeneratePrerequisites()
+{
+  // Utility for PreAddSolid and BeginPrimitives.
+
+  // This routines prepares for adding items to the scene database.  We
+  // are expecting two kinds of solids: leaf parts and non-leaf parts.
+  // For non-leaf parts, we create a detector tree kit.  This has two
+  // separators.  The solid itself goes in the preview separator, the
+  // full separator is forseen for daughters.  This separator is not
+  // only created--it is also put in a dictionary for future use by
+  // the leaf part.
+
+  // For leaf parts, we first locate the mother volume and find its
+  // separator through the dictionary.
+
+  // The private member fCurrentSeparator is set to the proper
+  // location on in the scene database so that when the solid is
+  // actually added (in addthis), it is put in the right place.
+
+  // Use the applicable vis attributes...
+  const G4VisAttributes* pApplicableVisAttribs =
+    fpViewer->GetApplicableVisAttributes (fpVisAttribs);
+
+  // First find the color attributes...
+  const G4Colour& g4Col =  pApplicableVisAttribs->GetColour ();
+  const double red = g4Col.GetRed ();
+  const double green = g4Col.GetGreen ();
+  const double blue = g4Col.GetBlue ();
+  double transparency = 1 - g4Col.GetAlpha();
+
+  // Drawing style...
+  G4ViewParameters::DrawingStyle drawing_style =
+    GetDrawingStyle(pApplicableVisAttribs);
+  switch (drawing_style) {
+  case (G4ViewParameters::wireframe):    
+    fModelingSolid = false;
+    break;
+  case (G4ViewParameters::hlr):
+  case (G4ViewParameters::hsr):
+  case (G4ViewParameters::hlhsr):
+    fModelingSolid = true;
+    break;
+  }	
+
+  // Edge visibility...
+  G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pApplicableVisAttribs);
+  fReducedWireFrame = !isAuxEdgeVisible;
+
+  G4PhysicalVolumeModel* pPVModel =
+    dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
+  
+  if (pPVModel) {
+
+    // This call comes from a G4PhysicalVolumeModel.  drawnPVPath is
+    // the path of the current drawn (non-culled) volume in terms of
+    // drawn (non-culled) ancesters.  Each node is identified by a
+    // PVNodeID object, which is a physical volume and copy number.  It
+    // is a vector of PVNodeIDs corresponding to the geometry hierarchy
+    // actually selected, i.e., not culled.
+    typedef G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID;
+    typedef std::vector<PVNodeID> PVPath;
+    const PVPath& drawnPVPath = pPVModel->GetDrawnPVPath();
+    //G4int currentDepth = pPVModel->GetCurrentDepth();
+    G4VPhysicalVolume* pCurrentPV = pPVModel->GetCurrentPV();
+    G4LogicalVolume* pCurrentLV = pPVModel->GetCurrentLV();
+    //G4Material* pCurrentMaterial = pPVModel->GetCurrentMaterial();
+    // Note: pCurrentMaterial may be zero (parallel world).
+
+    // The simplest algorithm, used by the Open Inventor Driver
+    // developers, is to rely on the fact the G4PhysicalVolumeModel
+    // traverses the geometry hierarchy in an orderly manner.  The last
+    // mother, if any, will be the node to which the volume should be
+    // added.  So it is enough to keep a map of scene graph nodes keyed
+    // on the volume path ID.  Actually, it is enough to use the logical
+    // volume as the key.  (An alternative would be to keep the PVNodeID
+    // in the tree and match the PVPath from the root down.)
+
+    // Find mother.  ri points to mother, if any...
+    PVPath::const_reverse_iterator ri;
+    G4LogicalVolume* MotherVolume = 0;
+    ri = ++drawnPVPath.rbegin();
+    if (ri != drawnPVPath.rend()) {
+      // This volume has a mother.
+      MotherVolume = ri->GetPhysicalVolume()->GetLogicalVolume();
+    }
+
+    if (pCurrentLV->GetNoDaughters()!=0 ||
+	pCurrentPV->IsReplicated()) {  //????Don't understand this???? JA
+      // This block of code is executed for non-leaf parts:
+
+      // Make the detector tree kit:
+      SoDetectorTreeKit* detectorTreeKit = new SoDetectorTreeKit();  
+
+      SoSeparator* previewSeparator   =  
+	(SoSeparator*) detectorTreeKit->getPart("previewSeparator",TRUE);
+      previewSeparator->renderCaching = SoSeparator::OFF;
+
+      SoSeparator* fullSeparator =  
+	(SoSeparator*) detectorTreeKit->getPart("fullSeparator",   TRUE);
+      fullSeparator->renderCaching = SoSeparator::OFF;
+
+      if(fPreviewAndFull) detectorTreeKit->setPreviewAndFull();
+      else detectorTreeKit->setPreview(TRUE);
+
+      SoMaterial* material = 
+	fStyleCache->getMaterial((float)red,
+				 (float)green,
+				 (float)blue,
+				 (float)transparency);
+      detectorTreeKit->setPart("appearance.material",material);
+
+      SoLightModel* lightModel = 
+	fModelingSolid ? fStyleCache->getLightModelPhong() : 
+	fStyleCache->getLightModelBaseColor();
+      detectorTreeKit->setPart("appearance.lightModel",lightModel);
+
+      // Add the full separator to the dictionary; it is indexed by the 
+      // address of the logical volume!
+      fSeparatorMap[pCurrentLV] = fullSeparator;
+
+      // Find out where to add this volume.
+      // If no mother can be found, it goes under root.
+      if (MotherVolume) {
+	if (fSeparatorMap.find(MotherVolume) != fSeparatorMap.end()) {
+	  //printf("debug : PreAddSolid : mother %s found in map\n",
+	  //     MotherVolume->GetName().c_str());
+	  fSeparatorMap[MotherVolume]->addChild(detectorTreeKit);
+	} else {
+	  // Mother not previously encountered.  Shouldn't happen, since
+	  // G4PhysicalVolumeModel sends volumes as it encounters them,
+	  // i.e., mothers before daughters, in its descent of the
+	  // geometry tree.  Error!
+	  G4cout <<
+	    "ERROR: G4OpenInventorSceneHandler::GeneratePrerequisites: Mother "
+		 << ri->GetPhysicalVolume()->GetName()
+		 << ':' << ri->GetCopyNo()
+		 << " not previously encountered."
+	    "\nShouldn't happen!  Please report to visualization coordinator."
+		 << G4endl;
+	  // Continue anyway.  Add to root of scene graph tree...
+	  //printf("debug : PreAddSolid : mother %s not found in map !!!\n",
+	  //     MotherVolume->GetName().c_str());
+	  fDetectorRoot->addChild(detectorTreeKit);
+	}
+      } else {
+	//printf("debug : PreAddSolid : has no mother\n");
+	fDetectorRoot->addChild(detectorTreeKit);
+      }
+
+      fCurrentSeparator = previewSeparator;
+
+    } else {
+      // This block of code is executed for leaf parts.
+
+      if (MotherVolume) {
+	if (fSeparatorMap.find(MotherVolume) != fSeparatorMap.end()) {
+	  fCurrentSeparator = fSeparatorMap[MotherVolume];
+	} else {
+	  // Mother not previously encountered.  Shouldn't happen, since
+	  // G4PhysicalVolumeModel sends volumes as it encounters them,
+	  // i.e., mothers before daughters, in its descent of the
+	  // geometry tree.  Error!
+	  G4cout << "ERROR: G4OpenInventorSceneHandler::PreAddSolid: Mother "
+		 << ri->GetPhysicalVolume()->GetName()
+		 << ':' << ri->GetCopyNo()
+		 << " not previously encountered."
+	    "\nShouldn't happen!  Please report to visualization coordinator."
+		 << G4endl;
+	  // Continue anyway.  Add to root of scene graph tree...
+	  fCurrentSeparator = fDetectorRoot;
+	}
+      } else {
+	fCurrentSeparator = fDetectorRoot;
+      }
+    }
+
+  } else {
+    // Not from G4PhysicalVolumeModel, so add to root as leaf part...
+
+    if (fReadyForTransients) {
+      fCurrentSeparator = fTransientRoot;
+    } else {
+      fCurrentSeparator = fDetectorRoot;
+    }
+  }
+
+  SoMaterial* material = 
+    fStyleCache->getMaterial((float)red,
+			     (float)green,
+			     (float)blue,
+			     (float)transparency);
+  fCurrentSeparator->addChild(material);
+
+  SoLightModel* lightModel = 
+    fModelingSolid ? fStyleCache->getLightModelPhong() : 
+    fStyleCache->getLightModelBaseColor();
+  fCurrentSeparator->addChild(lightModel);
+
+  // Set up the geometrical transformation for the coming 
+  fCurrentSeparator->addChild(fStyleCache->getResetTransform());
+
+  SoMatrixTransform* matrixTransform = new SoMatrixTransform;
+  G4OpenInventorTransform3D oiTran(*fpObjectTransformation);
+  SbMatrix* sbMatrix = oiTran.GetSbMatrix();
+
+  const G4Vector3D scale = fpViewer->GetViewParameters().GetScaleFactor();
+  SbMatrix sbScale;
+  sbScale.setScale
+    (SbVec3f((float)scale.x(),(float)scale.y(),(float)scale.z()));
+  sbMatrix->multRight(sbScale);
+
+  matrixTransform->matrix.setValue(*sbMatrix);
+  delete sbMatrix;
+  fCurrentSeparator->addChild(matrixTransform);
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorTransform3D.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorTransform3D.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorTransform3D.cc	(revision 529)
@@ -0,0 +1,73 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenInventorTransform3D.cc,v 1.8 2006/06/29 21:22:16 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// jck 17 Dec 1996
+// G4OpenInventorTransform3D provides OpenGL style transformation matrix
+// from G4Transform3D.
+// gb 22 Nov 2004 : use SbMatrix instead of SoSFMatrix.
+
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+// this :
+#include "G4OpenInventorTransform3D.hh"
+
+#include <Inventor/SbLinear.h>
+
+G4OpenInventorTransform3D::G4OpenInventorTransform3D (const G4Transform3D &t) 
+: G4Transform3D (t) {
+#define elem(i,j) ((float)t(i,j))
+  m[0]  = elem(0,0); //xx
+  m[1]  = elem(1,0); //yx
+  m[2]  = elem(2,0); //zx
+  m[3]  = 0;
+  m[4]  = elem(0,1); //xy
+  m[5]  = elem(1,1); //yy
+  m[6]  = elem(2,1); //zy
+  m[7]  = 0;
+  m[8]  = elem(0,2); //xz
+  m[9]  = elem(1,2); //yz
+  m[10] = elem(2,2); //zz
+  m[11] = 0;
+  m[12] = elem(0,3); //dx
+  m[13] = elem(1,3); //dy
+  m[14] = elem(2,3); //dz
+  m[15] = 1;
+#undef elem
+}
+
+SbMatrix* G4OpenInventorTransform3D::GetSbMatrix () const {
+  SbMatrix* tm = new SbMatrix(m[0],m[1],m[2],m[3],
+                              m[4],m[5],m[6],m[7],
+                              m[8],m[9],m[10],m[11],
+                              m[12],m[13],m[14],m[15]);
+  return tm;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorViewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorViewer.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorViewer.cc	(revision 529)
@@ -0,0 +1,710 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4OpenInventorViewer.cc,v 1.57 2006/11/01 11:06:07 allison Exp $
+// GEANT4 tag $Name: geant4-08-02-patch-01 $
+
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+// this :
+#include "G4OpenInventorViewer.hh"
+
+#include <Inventor/nodes/SoSelection.h>
+#include <Inventor/nodes/SoShape.h>
+#include <Inventor/nodes/SoOrthographicCamera.h>
+#include <Inventor/nodes/SoPerspectiveCamera.h>
+#include <Inventor/actions/SoCallbackAction.h>
+#include <Inventor/actions/SoWriteAction.h>
+#include <Inventor/sensors/SoNodeSensor.h>
+
+#include "HEPVis/nodes/SoImageWriter.h"
+#include "HEPVis/actions/SoGL2PSAction.h"
+#include "HEPVis/actions/SoCounterAction.h"
+#include "HEPVis/actions/SoAlternateRepAction.h"
+
+#include "G4OpenInventor.hh"
+#include "G4OpenInventorSceneHandler.hh"
+#include "G4VInteractorManager.hh"
+#include "G4Scene.hh"
+#include "Geant4_SoPolyhedron.h"
+#include "G4AttValue.hh"
+#include "G4AttDef.hh"
+#include "G4AttCheck.hh"
+#include "G4AttHolder.hh"
+
+G4OpenInventorViewer::G4OpenInventorViewer(
+ G4OpenInventorSceneHandler& sceneHandler
+,const G4String& name)
+:G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name)
+,fG4OpenInventorSceneHandler(sceneHandler)
+,fInteractorManager(0)
+,fSoSelection(0)
+,fSoImageWriter(0)
+,fGL2PSAction(0) //To be set be suclass.
+,fGroupCameraSensor(0)
+,fCameraSensor(0)
+{
+  fNeedKernelVisit = true;  //?? Temporary, until KernelVisitDecision fixed.
+
+  fDefaultVP.SetAutoRefresh(true);
+  fVP.SetAutoRefresh(true);
+
+  //FIXME : G.Barrand : not convinced that we have to rm culling.
+  // For viewing of all objects by default :
+  //fDefaultVP.SetCulling(false);
+  //fVP.SetCulling(false);
+
+  fInteractorManager = 
+    ((G4OpenInventor*)fG4OpenInventorSceneHandler.GetGraphicsSystem())->
+    GetInteractorManager();
+
+  // Main user scene graph root sent to the viewers.
+  fSoSelection = new SoSelection;
+  fSoSelection->ref();
+  fSoSelection->addSelectionCallback(SelectionCB,this);
+  //fSoSelection->addDeselectionCallback(DeselectionCB,this);
+  fSoSelection->policy = SoSelection::SINGLE;
+
+  SoGroup* group = new SoGroup;
+  fSoSelection->addChild(group);
+
+  //  Have a camera under fSoSelection in order
+  // that the below SceneGraphSensor be notifed
+  // when the viewer changes the camera type.
+  //  But we put the camera under a SoGroup so that
+  // the SceneGraphSensor be not triggered at each change
+  // under the fG4OpenInventorSceneHandler.fRoot.
+  SoOrthographicCamera* camera = new SoOrthographicCamera;
+  camera->viewportMapping.setValue(SoCamera::ADJUST_CAMERA);
+  //camera->aspectRatio.setValue(10);
+  camera->position.setValue(0,0,10);
+  camera->orientation.setValue(SbRotation(SbVec3f(0,1,0),0));
+  camera->height.setValue(10);
+  camera->nearDistance.setValue(1);
+  camera->farDistance.setValue(100);
+  camera->focalDistance.setValue(10);
+  group->addChild(camera);
+
+ {SoInput soInput;
+   if(soInput.openFile("g4view.iv",TRUE)) {
+    SoSeparator* separator = SoDB::readAll(&soInput);
+    if(separator) fSoSelection->addChild(separator);
+  }}
+
+  fSoSelection->addChild(fG4OpenInventorSceneHandler.fRoot);
+
+  // SoImageWriter should be the last.
+  fSoImageWriter = new SoImageWriter();
+  fSoImageWriter->fileName.setValue("g4out.ps");
+  fSoSelection->addChild(fSoImageWriter);
+
+  // Sensors :
+  // To detect that the viewer had changed the camera type :
+  fGroupCameraSensor = new SoNodeSensor(GroupCameraSensorCB,this);
+  fGroupCameraSensor->setPriority(0);//Needed in order to do getTriggerNode()
+  fGroupCameraSensor->attach(group);
+
+  fCameraSensor = new SoNodeSensor(CameraSensorCB,this);
+  fCameraSensor->setPriority(0);//Needed in order to do getTriggerNode()
+}
+
+G4OpenInventorViewer::~G4OpenInventorViewer () {
+  fCameraSensor->detach();
+  delete fCameraSensor;
+  fGroupCameraSensor->detach();
+  delete fGroupCameraSensor;
+  fSoSelection->unref();
+}
+
+void G4OpenInventorViewer::KernelVisitDecision () {
+  
+  // If there's a significant difference with the last view parameters
+  // of either the scene handler or this viewer, trigger a rebuild.
+
+  if (
+      //??fG4OpenInventorSceneHandler.fPODLList.size() == 0 ||
+      // We need a test for empty scene graph, such as
+      // staticRoot.size() or something??????????  See temporary fix
+      // in contructor.  (John Allison Aug 2001)
+      CompareForKernelVisit(fLastVP)) {
+    NeedKernelVisit ();
+  }      
+  fLastVP = fVP;
+}
+ 
+G4bool G4OpenInventorViewer::CompareForKernelVisit(G4ViewParameters& vp) {
+
+  if (
+      (vp.GetDrawingStyle ()    != fVP.GetDrawingStyle ())    ||
+      (vp.IsAuxEdgeVisible ()   != fVP.IsAuxEdgeVisible ())   ||
+      (vp.GetRepStyle ()        != fVP.GetRepStyle ())        ||
+      (vp.IsCulling ()          != fVP.IsCulling ())          ||
+      (vp.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
+      (vp.IsDensityCulling ()   != fVP.IsDensityCulling ())   ||
+      (vp.IsCullingCovered ()   != fVP.IsCullingCovered ())   ||
+      (vp.IsSection ()          != fVP.IsSection ())          ||
+      (vp.IsCutaway ()          != fVP.IsCutaway ())          ||
+      // This assumes use of generic clipping (sectioning, slicing,
+      // DCUT, cutaway).  If a decision is made to implement locally,
+      // this will need changing.  See G4OpenGLViewer::SetView,
+      // G4OpenGLStoredViewer.cc::CompareForKernelVisit and
+      // G4OpenGLStoredSceneHander::CreateSection/CutawayPolyhedron.
+      (vp.IsExplode ()          != fVP.IsExplode ())          ||
+      (vp.GetNoOfSides ()       != fVP.GetNoOfSides ())       ||
+      (vp.IsMarkerNotHidden ()  != fVP.IsMarkerNotHidden ())  ||
+      (vp.GetBackgroundColour ()!= fVP.GetBackgroundColour ())
+      ) {
+      return true;;
+  }
+  if (vp.IsDensityCulling () &&
+      (vp.GetVisibleDensity () != fVP.GetVisibleDensity ()))
+    return true;
+
+  if (vp.IsSection () &&
+      (vp.GetSectionPlane () != fVP.GetSectionPlane ()))
+    return true;
+
+  if (vp.IsCutaway ()) {
+    if (vp.GetCutawayPlanes ().size () !=
+	fVP.GetCutawayPlanes ().size ()) return true;
+    for (size_t i = 0; i < vp.GetCutawayPlanes().size(); ++i)
+      if (vp.GetCutawayPlanes()[i] != fVP.GetCutawayPlanes()[i])
+	return true;
+  }
+
+  if (vp.IsExplode () &&
+      (vp.GetExplodeFactor () != fVP.GetExplodeFactor ()))
+    return true;
+      
+  return false;
+}
+
+void G4OpenInventorViewer::ClearView () {
+}
+
+void G4OpenInventorViewer::SetView () {
+
+  // Get G4 camera infos :
+  const G4Point3D target
+    = fSceneHandler.GetScene()->GetStandardTargetPoint()
+    + fVP.GetCurrentTargetPoint ();
+  G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
+  if(radius<=0.) radius = 1.;
+  const G4double cameraDistance = fVP.GetCameraDistance (radius);
+  const G4Vector3D& direction = fVP.GetViewpointDirection().unit();
+  const G4Point3D cameraPosition = target + cameraDistance * direction;
+  //const G4double pnear = fVP.GetNearDistance (cameraDistance, radius);
+  //const G4double pfar  = fVP.GetFarDistance  (cameraDistance, pnear, radius);
+  const G4Normal3D& up = fVP.GetUpVector ();  
+
+/*
+  printf("debug : target : %g %g %g\n",target.x(),
+                                       target.y(),
+                                       target.z());
+  printf("debug : dir : %g %g %g\n",direction.x(),
+                                    direction.y(),
+                                    direction.z());
+  printf("debug : pos : %g %g %g\n",cameraPosition.x(),
+                                    cameraPosition.y(),
+                                    cameraPosition.z());
+  //printf("debug : near %g far %g\n",pnear,pfar);
+*/
+
+  SoCamera* camera = GetCamera();
+  if(!camera) return;
+
+  // viewer camera setup :
+  camera->position.setValue((float)cameraPosition.x(),
+                               (float)cameraPosition.y(),
+                               (float)cameraPosition.z());
+
+  SbVec3f sbTarget((float)target.x(),
+                   (float)target.y(),
+                   (float)target.z());
+  SbVec3f sbUp((float)up.x(),
+	       (float)up.y(),
+	       (float)up.z());
+  sbUp.normalize();
+  // Need Coin's camera->pointAt(sbTarget,sbUp); not in the SGI API
+  // Stole Coin's code...
+  pointAt(camera,sbTarget,sbUp);
+
+  //camera->height.setValue(10);
+  //camera->nearDistance.setValue((float)pnear);
+  //camera->farDistance.setValue((float)pfar);
+  //camera->focalDistance.setValue((float)cameraDistance);
+
+  if(camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
+    if (fVP.GetFieldHalfAngle() == 0.) {
+      //FIXME : ((SoOrthographicCamera*)camera)->height.setValue();
+      //FIXME : (Don't think we have to do that.)
+    } else {
+      //FIXME : Have to set a perspective camera !
+      //FIXME : viewer->setCameraType(SoPerspectiveCamera::getClassTypeId())
+      //FIXME : ((SoPerspectiveCamera*)camera)->heightAngle.setValue
+      //FIXME :   (2.*fVP.GetFieldHalfAngle());
+    }
+  } else if(camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
+    if (fVP.GetFieldHalfAngle() == 0.) {
+      //FIXME : Have to set an orthographic camera !
+      //FIXME : viewer->setCameraType(SoOrthographicCamera::getClassTypeId())
+    } else {
+      //FIXME : ((SoPerspectiveCamera*)camera)->heightAngle.setValue
+      //FIXME :   (2.*fVP.GetFieldHalfAngle());
+    }
+  }
+}
+
+//COIN_FUNCTION_EXTENSION
+void
+G4OpenInventorViewer::pointAt(SoCamera* camera,const SbVec3f & targetpoint, const SbVec3f & upvector)
+{
+  SbVec3f dir = targetpoint - camera->position.getValue();
+  if (dir.normalize() == 0.0f) return;
+  lookAt(camera,dir, upvector);
+}
+
+//COIN_FUNCTION
+// Private method that calculates a new orientation based on camera
+// direction and camera up vector. Vectors must be unit length.
+void
+G4OpenInventorViewer::lookAt(SoCamera* camera,const SbVec3f & dir, const SbVec3f & up)
+{
+  SbVec3f z = -dir;
+  SbVec3f y = up;
+  SbVec3f x = y.cross(z);
+
+  // recompute y to create a valid coordinate system
+  y = z.cross(x);
+
+  // normalize x and y to create an orthonormal coord system
+  y.normalize();
+  x.normalize();
+
+  // create a rotation matrix
+  SbMatrix rot = SbMatrix::identity();
+  rot[0][0] = x[0];
+  rot[0][1] = x[1];
+  rot[0][2] = x[2];
+
+  rot[1][0] = y[0];
+  rot[1][1] = y[1];
+  rot[1][2] = y[2];
+
+  rot[2][0] = z[0];
+  rot[2][1] = z[1];
+  rot[2][2] = z[2];
+
+  camera->orientation.setValue(SbRotation(rot));
+}
+
+void
+G4OpenInventorViewer::lookedAt(SoCamera* camera,SbVec3f & dir, SbVec3f & up)
+{
+  SbRotation rot = camera->orientation.getValue();
+  SbMatrix mrot; rot.getValue(mrot);
+
+  SbVec3f x, y, z;
+
+  // create a rotation matrix
+  x[0] = mrot[0][0];
+  x[1] = mrot[0][1];
+  x[2] = mrot[0][2];
+
+  y[0] = mrot[1][0];
+  y[1] = mrot[1][1];
+  y[2] = mrot[1][2];
+
+  z[0] = mrot[2][0];
+  z[1] = mrot[2][1];
+  z[2] = mrot[2][2];
+
+  dir = -z;
+  dir.normalize();
+  up = SbVec3f(0.f,1.f,0.f);  // Choose y-axis if possible.
+  if (std::abs(up.dot(z)) > 1.e-6) {
+    up = y;
+    up.normalize();
+  }
+}
+
+void G4OpenInventorViewer::DrawView () {
+  //G4cout << "debug Iv::DrawViewer " <<G4endl;
+  if (!fNeedKernelVisit) KernelVisitDecision();
+  ProcessView();
+  FinishView();
+}
+
+void G4OpenInventorViewer::ShowView () {
+  fInteractorManager -> SecondaryLoop ();
+}
+
+void G4OpenInventorViewer::GroupCameraSensorCB(void* aThis,SoSensor* aSensor){ 
+  G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
+
+  SoNode* node = ((SoNodeSensor*)aSensor)->getTriggerNode();
+  //printf("debug : GroupCameraSensorCB %s\n",
+  //node->getTypeId().getName().getString());
+
+  if(node->isOfType(SoCamera::getClassTypeId())) {
+    // Viewer had changed the camera type, 
+    // attach the fCameraSensor to the new camera.
+    SoCamera* camera = (SoCamera*)node;
+    This->fCameraSensor->detach();
+    This->fCameraSensor->attach(camera);
+  }
+
+}
+
+void G4OpenInventorViewer::CameraSensorCB(void* aThis,SoSensor* aSensor) { 
+  G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
+
+  //printf("debug : CameraSensorCB\n");
+
+  SoNode* node = ((SoNodeSensor*)aSensor)->getTriggerNode();
+
+  if(node->isOfType(SoCamera::getClassTypeId())) {
+    SoCamera* camera = (SoCamera*)node;
+
+    SbVec3f direction, up;
+    lookedAt(camera,direction, up);
+    This->fVP.SetViewpointDirection
+      (G4Vector3D(-direction[0],-direction[1],-direction[2]));
+    This->fVP.SetUpVector(G4Vector3D(up[0],up[1],up[2]));
+
+    SbVec3f pos = camera->position.getValue();
+    SbVec3f target = pos + direction * camera->focalDistance.getValue();
+
+    This->fVP.SetCurrentTargetPoint(G4Point3D(target[0],target[1],target[2]));
+  }
+}
+
+void G4OpenInventorViewer::SelectionCB(
+ void* aThis
+,SoPath* aPath
+) 
+{
+  G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
+  SoNode* node = ((SoFullPath*)aPath)->getTail();
+  G4AttHolder* attHolder = dynamic_cast<G4AttHolder*>(node);
+  if(attHolder && attHolder->GetAttDefs().size()) {
+    for (size_t i = 0; i < attHolder->GetAttDefs().size(); ++i) {
+      G4cout << G4AttCheck(attHolder->GetAttValues()[i],
+			   attHolder->GetAttDefs()[i]);
+    }
+  } else {
+    G4String name((char*)node->getName().getString());
+    G4String cls((char*)node->getTypeId().getName().getString());
+    G4cout << "SoNode : " << node 
+	   << " SoType : " << cls 
+	   << " name : " << name 
+	   << G4endl;
+    G4cout << "No attributes attached." << G4endl;
+  }
+  /*FIXME : to explore (need different button - this is used for picking.
+  if(node->isOfType(Geant4_SoPolyhedron::getClassTypeId())) {
+    Geant4_SoPolyhedron* polyhedron = (Geant4_SoPolyhedron*)node;
+    if(polyhedron->solid.getValue()==FALSE)
+      polyhedron->solid.setValue(TRUE);
+    else
+      polyhedron->solid.setValue(FALSE);
+  }*/
+  This->fSoSelection->deselectAll();
+}
+/*
+void G4OpenInventorViewer::DeselectionCB(
+ void* aThis
+,SoPath* aPath
+) 
+{
+  //G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
+  G4String name((char*)aPath->getTail()->getTypeId().getName().getString());
+  G4cout << "Deselect : " << name << G4endl;
+}
+*/
+
+void G4OpenInventorViewer::DrawDetector() {
+  /* Replace this... - JA
+  // DrawView does a ClearStore. Do not clear the transient store :
+  SoSeparator* tmp = fG4OpenInventorSceneHandler.fTransientRoot;
+  fG4OpenInventorSceneHandler.fTransientRoot = new SoSeparator;
+  if (!fNeedKernelVisit) KernelVisitDecision();
+  ProcessView();
+  fG4OpenInventorSceneHandler.fTransientRoot->unref();
+  fG4OpenInventorSceneHandler.fTransientRoot = tmp;
+  */
+  // ...by this... - JA
+  DrawView();
+}
+
+//////////////////////////////////////////////////////////////////////////////
+/// Menu items callbacks /////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+
+void G4OpenInventorViewer::Escape(){
+  G4cout << "Escape..." <<G4endl;
+  fInteractorManager->RequireExitSecondaryLoop (OIV_EXIT_CODE);
+}
+
+void G4OpenInventorViewer::WritePostScript(const G4String& aFile) {
+  if(!fGL2PSAction) return;
+  fGL2PSAction->setFileName(aFile.c_str());
+  G4cout << "Produce " << aFile << "..." << G4endl;
+  fGL2PSAction->enableFileWriting();
+  ViewerRender();
+  fGL2PSAction->disableFileWriting();
+}
+
+void G4OpenInventorViewer::WritePixmapPostScript(const G4String& aFile) {
+  fSoImageWriter->fileName.setValue(aFile.c_str());
+  //imageWriter->format.setValue(SoImageWriter::POST_SCRIPT);
+  fSoImageWriter->enable();
+  ViewerRender();
+  fSoImageWriter->disable();
+  if(fSoImageWriter->getStatus()) {
+    G4cout << G4String(fSoImageWriter->fileName.getValue().getString()) 
+           << " produced."
+           << G4endl;
+  } else {
+    G4cout << G4String(fSoImageWriter->fileName.getValue().getString()) 
+           << " not produced."
+           << G4endl;
+  }
+}  
+
+void G4OpenInventorViewer::WriteInventor(const G4String& aFile) {
+  G4cout << "Produce " << aFile << "..." << G4endl;
+
+  SbBool genAlternateRep = TRUE;
+  //SbBool binary = FALSE;
+  SbBool binary = TRUE;
+  SoAlternateRepAction alternateRepAction;
+  if(genAlternateRep==TRUE) {
+    alternateRepAction.setGenerate(TRUE); //Clear alternate reps.
+    alternateRepAction.apply(fSoSelection);
+  }
+
+  SoWriteAction writeAction;
+  writeAction.getOutput()->openFile(aFile.c_str());
+  writeAction.getOutput()->setBinary(binary);
+  writeAction.apply(fSoSelection);
+  writeAction.getOutput()->closeFile();
+
+  if(genAlternateRep==TRUE) {
+    alternateRepAction.setGenerate(FALSE); //Clear alternate reps.
+    alternateRepAction.apply(fSoSelection);
+  }
+
+
+
+}
+
+struct Counter {
+ int fTriangles;
+ int fLineSegments;
+ int fPoints;
+};
+
+static void CountTrianglesCB(
+ void* userData
+,SoCallbackAction*
+,const SoPrimitiveVertex*
+,const SoPrimitiveVertex*,
+const SoPrimitiveVertex*)
+{
+  Counter* counter = (Counter*)userData;
+  counter->fTriangles++;
+}
+
+static void CountLineSegmentsCB(
+ void* userData
+,SoCallbackAction*
+,const SoPrimitiveVertex*
+,const SoPrimitiveVertex*)
+{
+  Counter* counter = (Counter*)userData;
+  counter->fLineSegments++;
+}
+
+static void CountPointsCB(
+ void* userData
+,SoCallbackAction*
+,const SoPrimitiveVertex*)
+{
+  Counter* counter = (Counter*)userData;
+  counter->fPoints++;
+}
+
+void G4OpenInventorViewer::SceneGraphStatistics() {
+  Counter counter;
+  counter.fTriangles = 0;
+  counter.fLineSegments = 0;
+  counter.fPoints = 0;
+
+  SoCallbackAction callbackAction;
+  callbackAction.addTriangleCallback
+    (SoShape::getClassTypeId(),CountTrianglesCB,(void*)&counter);
+  callbackAction.addLineSegmentCallback
+    (SoShape::getClassTypeId(),CountLineSegmentsCB,(void*)&counter);
+  callbackAction.addPointCallback
+    (SoShape::getClassTypeId(),CountPointsCB,(void*)&counter);
+  callbackAction.apply(fSoSelection);
+
+  SoCounterAction counterAction;
+  counterAction.apply(fSoSelection);
+  int nodes = counterAction.getCount();
+
+  counterAction.setLookFor(SoCounterAction::TYPE);
+  counterAction.setType(SoShape::getClassTypeId());
+  counterAction.apply(fSoSelection);
+  int shapes = counterAction.getCount();
+
+  G4cout << "Number of triangles : " << counter.fTriangles << G4endl;
+  G4cout << "Number of line segments : " << counter.fLineSegments << G4endl;
+  G4cout << "Number of points : " << counter.fPoints << G4endl;
+  G4cout << "Number of nodes : " << nodes << G4endl;
+  G4cout << "Number of shapes : " << shapes << G4endl;
+}
+
+void G4OpenInventorViewer::EraseDetector() {
+  fG4OpenInventorSceneHandler.fDetectorRoot->removeAllChildren();
+}
+void G4OpenInventorViewer::EraseEvent() {
+  fG4OpenInventorSceneHandler.fTransientRoot->removeAllChildren();
+}
+
+void G4OpenInventorViewer::SetPreviewAndFull() {
+  fG4OpenInventorSceneHandler.fPreviewAndFull = true;
+
+  NeedKernelVisit();
+  DrawDetector();
+}
+
+void G4OpenInventorViewer::SetPreview() {
+  fG4OpenInventorSceneHandler.fPreviewAndFull = false;
+
+  NeedKernelVisit();
+  DrawDetector();
+}
+
+// When ViewParameter <-> SoCamera mapping ready 
+// uncomment the below
+//#define USE_SET_VIEW
+
+void G4OpenInventorViewer::SetSolid() {
+  G4ViewParameters vp = GetViewParameters();
+  G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
+  //From G4VisCommandsViewerSet : /vis/viewer/set/style solid.
+  switch (existingStyle) {
+  case G4ViewParameters::wireframe:
+    vp.SetDrawingStyle(G4ViewParameters::hsr);
+    break;
+  case G4ViewParameters::hlr:
+    vp.SetDrawingStyle(G4ViewParameters::hlhsr);
+    break;
+  case G4ViewParameters::hsr:
+    break;
+  case G4ViewParameters::hlhsr:
+    break;
+  }
+  SetViewParameters(vp);
+  DrawDetector();
+}
+void G4OpenInventorViewer::SetWireFrame() {
+  G4ViewParameters vp = GetViewParameters();
+  G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
+  switch (existingStyle) {
+  case G4ViewParameters::wireframe:
+    break;
+  case G4ViewParameters::hlr:
+    break;
+  case G4ViewParameters::hsr:
+    vp.SetDrawingStyle(G4ViewParameters::wireframe);
+    break;
+  case G4ViewParameters::hlhsr:
+    vp.SetDrawingStyle(G4ViewParameters::hlr);
+    break;
+  }
+  SetViewParameters(vp);
+  DrawDetector();
+}
+
+
+void G4OpenInventorViewer::SetReducedWireFrame(bool aValue) {
+  G4ViewParameters vp = GetViewParameters();
+
+  // Set the wire frame kind :
+  vp.SetAuxEdgeVisible(!aValue);
+
+  // Set wire frame :
+  G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
+  switch (existingStyle) {
+  case G4ViewParameters::wireframe:
+    break;
+  case G4ViewParameters::hlr:
+    break;
+  case G4ViewParameters::hsr:
+    vp.SetDrawingStyle(G4ViewParameters::wireframe);
+    break;
+  case G4ViewParameters::hlhsr:
+    vp.SetDrawingStyle(G4ViewParameters::hlr);
+    break;
+  }
+  SetViewParameters(vp);
+  NeedKernelVisit(); // Just in case it was alread in wire framw.
+  DrawDetector();
+}
+
+void G4OpenInventorViewer::UpdateScene() {
+  /* Replace this... - JA
+  fG4OpenInventorSceneHandler.ClearStore();
+  ClearView();
+  if (!fNeedKernelVisit) KernelVisitDecision();
+  ProcessView();
+  ShowView();
+  */
+  // ...by this - JA
+  NeedKernelVisit();
+  DrawView();
+}
+G4String G4OpenInventorViewer::Help(const G4String& aTopic) {
+  if(aTopic=="controls") {
+    return G4String("\
+Controls on an Inventor examiner viewer are :\n\
+- in picking mode (cursor is the upper left arrow)\n\
+  Ctrl + pick a volume : see daughters.\n\
+  Shift + pick a volume : see mother.\n\
+- in viewing mode (cursor is the hand)\n\
+  Left-button + pointer move : rotate.\n\
+  Ctrl+Left-button + pointer move : pan.\n\
+  Ctrl+Shift+Left-button + pointer move : scale.\n\
+  Middle-button + pointer move : pan.\n\
+  Right-button : popup menu.\n");
+  } else {
+    return "";
+  }
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorWin.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorWin.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorWin.cc	(revision 529)
@@ -0,0 +1,75 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenInventorWin.cc,v 1.6 2006/06/29 21:22:20 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// OpenInventor graphics system factory.
+
+#ifdef G4VIS_BUILD_OIWIN32_DRIVER
+
+// this :
+#include "G4OpenInventorWin.hh"
+
+#include <Inventor/Win/SoWin.h>
+
+#include "G4OpenInventorSceneHandler.hh"
+#include "G4OpenInventorWinViewer.hh"
+#include "G4Win32.hh"
+
+G4OpenInventorWin::G4OpenInventorWin ()
+:G4OpenInventor("OpenInventorWin","OIWin32",G4VGraphicsSystem::threeD)
+,fInited(false)
+{
+}
+
+void G4OpenInventorWin::Initialize ()
+{
+  if(fInited) return; //Done
+
+  SetInteractorManager (G4Win32::getInstance());
+  GetInteractorManager () -> RemoveDispatcher((G4DispatchFunction)G4Win32::dispatchWin32Event);  
+  GetInteractorManager () -> AddDispatcher((G4DispatchFunction)SoWin::dispatchEvent);
+
+  HWND toplevel = (HWND)GetInteractorManager()->GetMainInteractor();
+
+  SoWin::init(toplevel);
+
+  InitNodes();
+
+  fInited = true;
+}
+
+G4OpenInventorWin::~G4OpenInventorWin () {}
+G4VViewer* G4OpenInventorWin::CreateViewer (G4VSceneHandler& scene, const G4String& name) 
+{
+  Initialize();
+  G4OpenInventorSceneHandler* pScene = (G4OpenInventorSceneHandler*)&scene;
+  return new G4OpenInventorWinViewer (*pScene, name);
+}
+
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorWinViewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorWinViewer.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorWinViewer.cc	(revision 529)
@@ -0,0 +1,317 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenInventorWinViewer.cc,v 1.25 2006/06/29 21:22:22 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+/*
+ * jck : 05 Feb 1997 : Initial Implementation
+ * jck : 21 Apr 1997 : Mods for SoXtHepViewer
+ * gb : on Win32 use an SoXtExaminerViewer.
+ * gb : 05 April 2004 : creation.
+ * gb : 09 November 2004 : Pulldown menu with the escape menu item.
+ * gb 14 November 2004 : inherit G4OpenInventorViewer.
+ */
+
+#ifdef G4VIS_BUILD_OIWIN32_DRIVER
+
+// this :
+#include "G4OpenInventorWinViewer.hh"
+
+#include <Inventor/nodes/SoSelection.h>
+
+#include <Inventor/Win/SoWin.h>
+#include <Inventor/Win/viewers/SoWinExaminerViewer.h>
+
+#include "HEPVis/actions/SoGL2PSAction.h"
+
+#include "G4OpenInventor.hh"
+#include "G4OpenInventorSceneHandler.hh"
+#include "G4VInteractorManager.hh"
+
+#include <windowsx.h>
+
+// To have sizeChanged public :
+class Geant4_SoWinExaminerViewer : public SoWinExaminerViewer {
+public:
+  Geant4_SoWinExaminerViewer(HWND parent,const char* name,SbBool embed)
+  :SoWinExaminerViewer(parent,name,embed){}
+  virtual void sizeChanged(const SbVec2s & size){
+    SoWinExaminerViewer::sizeChanged(size);
+  }
+};
+
+#define SIZE 600
+// File : 
+#define ID_FILE_POSTSCRIPT 1
+#define ID_FILE_PIXMAP_POSTSCRIPT 2
+#define ID_FILE_INVENTOR 3
+#define ID_FILE_ESCAPE 4
+// Etc : 
+#define ID_ETC_ERASE_DETECTOR 101
+#define ID_ETC_ERASE_EVENT 102
+#define ID_ETC_SET_SOLID 103
+#define ID_ETC_SET_WIRE_FRAME 104
+#define ID_ETC_SET_REDUCED_WIRE_FRAME 105
+#define ID_ETC_SET_FULL_WIRE_FRAME 106
+#define ID_ETC_SET_PREVIEW 107
+#define ID_ETC_SET_PREVIEW_AND_FULL 108
+#define ID_ETC_UPDATE_SCENE 109
+#define ID_ETC_STATS 110
+// Help :
+#define ID_HELP_CONTROLS 201
+
+//static void SecondaryLoopPostAction ();
+
+static const char className[] = "G4OpenInventorShellWindow";
+
+G4OpenInventorWinViewer::G4OpenInventorWinViewer(
+ G4OpenInventorSceneHandler& sceneHandler
+,const G4String& name)
+:G4OpenInventorViewer (sceneHandler, name)
+,fShell(0)
+,fViewer(0)
+{
+  G4cout << "Window name: " << fName << G4endl;
+
+  G4String wName = fName;
+
+  HWND parent = (HWND)fInteractorManager->GetParentInteractor ();
+  if(!parent) {
+    //Create a shell window :
+    G4String shellName = wName;
+    shellName += "_shell"; 
+    static SbBool done = FALSE;
+    if(done==FALSE) {
+      HBRUSH brush = (HBRUSH) GetSysColorBrush(COLOR_BTNFACE);
+      WNDCLASS wc;
+      wc.style = CS_HREDRAW | CS_VREDRAW;
+      wc.lpfnWndProc = (WNDPROC)WindowProc;
+      wc.cbClsExtra = 0;
+      wc.cbWndExtra = 0;
+      wc.hInstance = ::GetModuleHandle(0);
+      wc.hIcon = ::LoadIcon(0, IDI_APPLICATION);
+      wc.hCursor = ::LoadCursor(0, IDC_ARROW);
+      wc.hbrBackground = brush;
+      wc.lpszMenuName = className;
+      wc.lpszClassName = className;
+      ::RegisterClass(&wc);
+      done = TRUE;
+    }
+
+    HMENU menuBar = CreateMenu();
+
+   {HMENU casc = CreatePopupMenu();
+    ::AppendMenu(menuBar,MF_POPUP,(UINT)casc,"File");
+    ::AppendMenu(casc,MF_STRING,ID_FILE_POSTSCRIPT,"PS (gl2ps)");
+    ::AppendMenu(casc,MF_STRING,ID_FILE_PIXMAP_POSTSCRIPT,"PS (pixmap)");
+    ::AppendMenu(casc,MF_STRING,ID_FILE_INVENTOR,"IV");
+    ::AppendMenu(casc,MF_STRING,ID_FILE_ESCAPE,"Escape");}
+
+   {HMENU casc = CreatePopupMenu();
+    ::AppendMenu(menuBar,MF_POPUP,(UINT)casc,"Etc");
+    ::AppendMenu(casc,MF_STRING,ID_ETC_ERASE_DETECTOR,"Erase detector");
+    ::AppendMenu(casc,MF_STRING,ID_ETC_ERASE_EVENT,"Erase event");
+    ::AppendMenu(casc,MF_STRING,ID_ETC_SET_SOLID,"Set solid");
+    //::AppendMenu(casc,MF_STRING,ID_ETC_SET_WIRE_FRAME,"Set (G4) wire frame");
+    ::AppendMenu(casc,MF_STRING,ID_ETC_SET_REDUCED_WIRE_FRAME,
+                      "Set (G4) reduced wire frame");
+    ::AppendMenu(casc,MF_STRING,ID_ETC_SET_FULL_WIRE_FRAME,
+                      "Set (G4) full wire frame");
+    ::AppendMenu(casc,MF_STRING,ID_ETC_SET_PREVIEW,
+                      "Visible mothers + invisible daughters");
+    ::AppendMenu(casc,MF_STRING,ID_ETC_SET_PREVIEW_AND_FULL,
+                      "Visible mothers + visible daughters");
+    ::AppendMenu(casc,MF_STRING,ID_ETC_UPDATE_SCENE,"Update scene");
+    ::AppendMenu(casc,MF_STRING,ID_ETC_STATS,"Scene graph stats");}
+
+   {HMENU casc = CreatePopupMenu();
+    ::AppendMenu(menuBar,MF_POPUP,(UINT)casc,"Help");
+    ::AppendMenu(casc,MF_STRING,ID_HELP_CONTROLS,"Controls");}
+
+    fShell = ::CreateWindow(className, shellName.c_str(), 
+                            WS_OVERLAPPEDWINDOW |
+                            WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
+                            CW_USEDEFAULT, CW_USEDEFAULT, 
+                            SIZE,SIZE,
+                            0,menuBar,::GetModuleHandle(0),0);
+    // Retreive window and client sizez :
+    RECT wrect,crect;
+    GetWindowRect((HWND)fShell,&wrect);
+    GetClientRect((HWND)fShell,&crect);
+    int ww = wrect.right-wrect.left;
+    int wh = wrect.bottom-wrect.top;
+    int cw = crect.right-crect.left;
+    int ch = crect.bottom-crect.top;
+    // Compell client rect to be SIZE SIZE :
+    MoveWindow((HWND)fShell,wrect.left,wrect.top,SIZE+ww-cw,SIZE+wh-ch,TRUE);
+    ::SetWindowLong((HWND)fShell,GWL_USERDATA,LONG(this));
+    ::SetWindowText((HWND)fShell,shellName.c_str());
+    parent = fShell;
+    fInteractorManager->AddShell(fShell);
+  } else {
+    char* str = fInteractorManager->GetCreationString();
+    if(str!=0) wName = str;
+  }
+  fViewer = new Geant4_SoWinExaminerViewer(parent,wName.c_str(),TRUE);
+
+  // Have a GL2PS render action :
+  const SbViewportRegion& vpRegion = fViewer->getViewportRegion();
+  fGL2PSAction = new SoGL2PSAction(vpRegion);
+  fViewer->setGLRenderAction(fGL2PSAction);
+
+  fViewer->setSize(SbVec2s(SIZE,SIZE));
+  fViewer->setSceneGraph(fSoSelection);
+  fViewer->viewAll();
+  fViewer->saveHomePosition();
+  fViewer->setTitle(fName);
+  fViewer->show();
+  if(fShell) {
+    SoWin::show(fShell);
+    fInteractorManager->FlushAndWaitExecution ();
+  }
+  fInteractorManager->SetCreatedInteractor (fViewer -> getWidget());
+}
+
+G4OpenInventorWinViewer::~G4OpenInventorWinViewer () {
+  if(fShell) fInteractorManager->RemoveShell(fShell);
+  if(fViewer) {
+    fViewer->setSceneGraph(0);
+    delete fViewer;
+  }
+  if(fShell) {
+    ::SetWindowLong((HWND)fShell,GWL_USERDATA,LONG(0));
+    ::DestroyWindow((HWND)fShell);
+  }
+}
+
+void G4OpenInventorWinViewer::FinishView () {
+  if(!fViewer) return;
+  fViewer->viewAll();
+  fViewer->saveHomePosition();
+}
+
+void G4OpenInventorWinViewer::SetView () {
+  G4OpenInventorViewer::SetView ();
+  if(!fViewer) return;
+  // Background.
+  G4Colour b = fVP.GetBackgroundColour ();
+  fViewer->setBackgroundColor
+    (SbColor((float)b.GetRed(),(float)b.GetGreen(),(float)b.GetBlue()));
+}
+void G4OpenInventorWinViewer::ViewerRender () {
+  if(!fViewer) return;
+  fViewer->render();
+}
+
+SoCamera* G4OpenInventorWinViewer::GetCamera () {
+  if(!fViewer) return 0;
+  return fViewer->getCamera();
+}
+
+
+//////////////////////////////////////////////////////////////////////////////
+LRESULT CALLBACK G4OpenInventorWinViewer::WindowProc ( 
+ HWND   aWindow
+,UINT   aMessage
+,WPARAM aWParam
+,LPARAM aLParam
+)
+//////////////////////////////////////////////////////////////////////////////
+//  Below treatment of WM_SIZE, WM_SETFOCUS not necessary 
+// with TGS, but needed with SoFree. WM_DESTROY needed for 
+// 'main top level window' so that 'Close window' induces
+// the end of the task.
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  switch (aMessage) { 
+  case WM_SIZE:{ // Assume one child window !
+    int width = LOWORD(aLParam);
+    int height = HIWORD(aLParam);
+    //printf("debug : G4SoWindow : WMS_SIZE : %d %d\n",width,height);
+    G4OpenInventorWinViewer* This = 
+      (G4OpenInventorWinViewer*)::GetWindowLong(aWindow,GWL_USERDATA);
+    if(This && This->fViewer) {
+      This->fViewer->sizeChanged(SbVec2s(width,height));
+    }
+  }return 0;
+  case WM_SETFOCUS:{ // Assume one child window !
+    HWND hwnd = ::GetFirstChild(aWindow);
+    if(hwnd!=0) ::SetFocus(hwnd);
+  }return 0;
+  case WM_DESTROY:{
+    //G4OpenInventorWinViewer* This = 
+    //  (G4OpenInventorWinViewer*)::GetWindowLong(aWindow,GWL_USERDATA);
+    //::PostQuitMessage(0);
+  }return 0;
+  case WM_COMMAND:{
+    G4OpenInventorWinViewer* This = 
+      (G4OpenInventorWinViewer*)::GetWindowLong(aWindow,GWL_USERDATA);
+    if(This) {
+      if(aLParam==0) { //From menu.
+        // File :
+        if(aWParam==ID_FILE_POSTSCRIPT) {
+          This->WritePostScript();
+        } else if(aWParam==ID_FILE_PIXMAP_POSTSCRIPT) {
+          This->WritePixmapPostScript();
+        } else if(aWParam==ID_FILE_INVENTOR) {
+          This->WriteInventor();
+        } else if(aWParam==ID_FILE_ESCAPE) {
+          This->Escape();
+        // Etc :
+        } else if(aWParam==ID_ETC_ERASE_DETECTOR) {
+          This->EraseDetector();
+        } else if(aWParam==ID_ETC_ERASE_EVENT) {
+          This->EraseEvent();
+        } else if(aWParam==ID_ETC_SET_SOLID) {
+          This->SetSolid();
+        } else if(aWParam==ID_ETC_SET_WIRE_FRAME) {
+          This->SetWireFrame();
+        } else if(aWParam==ID_ETC_SET_REDUCED_WIRE_FRAME) {
+          This->SetReducedWireFrame(true);
+        } else if(aWParam==ID_ETC_SET_FULL_WIRE_FRAME) {
+          This->SetReducedWireFrame(false);
+        } else if(aWParam==ID_ETC_SET_PREVIEW) {
+          This->SetPreview();
+        } else if(aWParam==ID_ETC_SET_PREVIEW_AND_FULL) {
+          This->SetPreviewAndFull();
+        } else if(aWParam==ID_ETC_UPDATE_SCENE) {
+          This->UpdateScene();
+        } else if(aWParam==ID_ETC_STATS) {
+          This->SceneGraphStatistics();
+        // Help :
+        } else if(aWParam==ID_HELP_CONTROLS) {
+          G4cout << This->Help() << G4endl;
+        }
+      }
+    }
+  }return 0;
+  default:
+    return (::DefWindowProc(aWindow,aMessage,aWParam,aLParam));
+  }
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorXt.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorXt.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorXt.cc	(revision 529)
@@ -0,0 +1,99 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenInventorXt.cc,v 1.4 2006/06/29 21:22:24 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+// 
+// Jeff Kallenbach 01 Aug 1996
+// OpenInventor graphics system factory.
+
+#ifdef G4VIS_BUILD_OIX_DRIVER
+
+// this :
+#include "G4OpenInventorXt.hh"
+
+#include <Inventor/Xt/SoXt.h>
+
+#include "G4Xt.hh"
+#include "G4OpenInventorSceneHandler.hh"
+#include "G4OpenInventorXtViewer.hh"
+
+G4OpenInventorXt::G4OpenInventorXt ()
+:G4OpenInventor("OpenInventorXt","OIX",G4VGraphicsSystem::threeD)
+,fInited(false)
+{
+}
+
+void G4OpenInventorXt::Initialize()
+{
+  if(fInited) return; //Done
+
+  SetInteractorManager (G4Xt::getInstance ());
+  GetInteractorManager () -> 
+    RemoveDispatcher((G4DispatchFunction)XtDispatchEvent);  
+  GetInteractorManager () -> 
+    AddDispatcher   ((G4DispatchFunction)SoXt::dispatchEvent);
+
+  Widget top = (Widget)GetInteractorManager()->GetMainInteractor();
+
+  if(getenv("XENVIRONMENT")==NULL) {
+    XrmDatabase database = XrmGetDatabase(XtDisplay(top));
+    if(database!=NULL) {
+      XrmPutLineResource(&database,"*topShadowColor:white");
+      XrmPutLineResource(&database,"*bottomShadowColor:black");
+      XrmPutLineResource(&database,"*foreground:black");
+      XrmPutLineResource(&database,"*background:lightgrey");
+      XrmPutLineResource(&database,"*borderColor:lightgrey");
+      XrmPutLineResource(&database,"*fontList:-*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-1");
+      XrmPutLineResource(&database,"*help_popup.title:Help");
+      XrmPutLineResource(&database,"*helpCancel.labelString:Cancel");
+      XrmPutLineResource(&database,"*helpText.editMode:multi_line_edit");
+      XrmPutLineResource(&database,"*helpText.columns:60");
+      XrmPutLineResource(&database,"*helpText.rows:20");
+      XrmPutLineResource(&database,"*helpText.background:white");
+      XrmPutLineResource(&database,"*helpText.fontList:*courier*-r-*--14-*");
+      XrmPutLineResource(&database,"*helpText.maxLength:8000");
+    }
+  }
+
+  SoXt::init(top);
+
+  InitNodes();
+
+  fInited = true;
+}
+
+G4OpenInventorXt::~G4OpenInventorXt () {}
+G4VViewer* G4OpenInventorXt::CreateViewer (G4VSceneHandler& scene, const G4String& name) 
+{
+  Initialize();
+  G4OpenInventorSceneHandler* pScene = (G4OpenInventorSceneHandler*)&scene;
+  return new G4OpenInventorXtViewer (*pScene, name);
+}
+
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorXtViewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorXtViewer.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/G4OpenInventorXtViewer.cc	(revision 529)
@@ -0,0 +1,361 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+// $Id: G4OpenInventorXtViewer.cc,v 1.24 2006/06/29 21:22:26 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+/*
+ * jck 05 Feb 1997 - Initial Implementation
+ * jck 21 Apr 1997 
+ *	Mods for SoXtHepViewer
+ * gb : on Win32 use an SoXtExaminerViewer.
+ * gb 05 April 2004 : revisit to separate Windows things.
+ * gb 09 November 2004 : restore the escape button.
+ * gb 09 November 2004 : have a menu bar in the viewer shell.
+ * gb 09 November 2004 : have gl2ps file production.
+ * gb 14 November 2004 : inherit G4OpenInventorViewer.
+ */
+
+#ifdef G4VIS_BUILD_OIX_DRIVER
+
+// this :
+#include "G4OpenInventorXtViewer.hh"
+
+#include <Inventor/nodes/SoSelection.h>
+
+#include <Inventor/Xt/SoXt.h>
+#include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
+
+#include <X11/StringDefs.h>
+#include <X11/Shell.h>
+
+#include <Xm/Xm.h>
+#include <Xm/PushB.h>
+#include <Xm/Form.h>
+#include <Xm/CascadeB.h>
+#include <Xm/RowColumn.h>
+#include <Xm/Text.h>
+
+#include "HEPVis/actions/SoGL2PSAction.h"
+
+#include "G4OpenInventor.hh"
+#include "G4OpenInventorSceneHandler.hh"
+#include "G4VInteractorManager.hh"
+
+G4OpenInventorXtViewer::G4OpenInventorXtViewer(
+ G4OpenInventorSceneHandler& sceneHandler
+,const G4String& name)
+:G4OpenInventorViewer (sceneHandler, name)
+,fShell(0)
+,fViewer(0)
+,fHelpForm(0)
+,fHelpText(0)
+{
+  G4cout << "Window name: " << fName << G4endl;
+
+  G4String wName = fName;
+
+#define SIZE 600
+  Widget parent = (Widget)fInteractorManager->GetParentInteractor ();
+  if(!parent) {  
+    // Check if user has specified an X-Windows-type geometry string...
+    char s[32];
+    sprintf(s,"%dx%d",SIZE,SIZE);
+    G4String sgeometry = fVP.GetXGeometryString();
+    if(sgeometry.empty()) sgeometry = s;
+
+    //Create a shell window :
+    G4String shellName = wName;
+    shellName += "_shell"; 
+    Arg args[10];
+    XtSetArg(args[0],XtNgeometry,XtNewString(sgeometry.c_str()));
+    XtSetArg(args[1],XtNborderWidth,0);
+    XtSetArg(args[2],XtNtitle,XtNewString(wName.c_str()));
+    fShell = XtAppCreateShell(shellName.c_str(),"Inventor",
+	  		       topLevelShellWidgetClass,
+			       SoXt::getDisplay(),
+			       args,3); 
+
+    XtSetArg(args[0],XmNtopAttachment   ,XmATTACH_FORM);
+    XtSetArg(args[1],XmNleftAttachment  ,XmATTACH_FORM);
+    XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
+    XtSetArg(args[3],XmNbottomAttachment,XmATTACH_FORM);
+    Widget form = XmCreateForm (fShell,(char*)"form",args,4);
+    XtManageChild (form);
+
+    XtSetArg(args[0],XmNtopAttachment   ,XmATTACH_FORM);
+    XtSetArg(args[1],XmNleftAttachment  ,XmATTACH_FORM);
+    XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
+    Widget menuBar = XmCreateMenuBar (form,(char*)"menuBar",args,3);
+    XtManageChild(menuBar);
+
+   {Widget menu = AddMenu(menuBar,"File","File");
+    AddButton(menu,"PS (gl2ps)",PostScriptCbk);
+    AddButton(menu,"PS (pixmap)",PixmapPostScriptCbk);
+    AddButton(menu,"IV",WriteInventorCbk);
+    AddButton(menu,"Escape",EscapeCbk);}
+
+   {Widget menu = AddMenu(menuBar,"Etc","Etc");
+    AddButton(menu,"Erase detector",EraseDetectorCbk);
+    AddButton(menu,"Erase event",EraseEventCbk);
+    AddButton(menu,"Set solid",SetSolidCbk);
+/*    AddButton(menu,"Set (G4) wire frame",SetWireFrameCbk);*/
+    AddButton(menu,"Set (G4) reduced wire frame",SetReducedWireFrameCbk);
+    AddButton(menu,"Set (G4) full wire frame",SetFullWireFrameCbk);
+    AddButton(menu,"Visible mothers + invisible daughters",SetPreviewCbk);
+    AddButton(menu,"Visible mothers + visible daughters",SetPreviewAndFullCbk);
+    AddButton(menu,"Update scene",UpdateSceneCbk);
+    AddButton(menu,"Scene graph stats",SceneGraphStatisticsCbk);
+   }
+
+   {Widget menu = AddMenu(menuBar,"Help","Help");
+    AddButton(menu,"Controls",HelpCbk);}
+
+    fViewer = new SoXtExaminerViewer(form,wName.c_str(),TRUE);
+    
+    XtSetArg(args[0],XmNtopAttachment   ,XmATTACH_WIDGET);
+    XtSetArg(args[1],XmNtopWidget       ,menuBar);
+    XtSetArg(args[2],XmNleftAttachment  ,XmATTACH_FORM);
+    XtSetArg(args[3],XmNrightAttachment ,XmATTACH_FORM);
+    XtSetArg(args[4],XmNbottomAttachment,XmATTACH_FORM);
+    XtSetValues(fViewer->getWidget(),args,5);
+
+    fHelpForm = XmCreateFormDialog(fShell,(char*)"help",NULL,0);
+    XtSetArg(args[0],XmNleftAttachment  ,XmATTACH_FORM);
+    XtSetArg(args[1],XmNrightAttachment ,XmATTACH_FORM);
+    XtSetArg(args[2],XmNbottomAttachment,XmATTACH_FORM);
+    Widget cancel = XmCreatePushButton(fHelpForm,(char*)"helpCancel",args,3);
+    XtAddCallback(cancel,XmNactivateCallback,HelpCancelCbk,(XtPointer)this);
+    XtManageChild(cancel);
+    XtSetArg(args[0],XmNtopAttachment   ,XmATTACH_FORM);
+    XtSetArg(args[1],XmNleftAttachment  ,XmATTACH_FORM);
+    XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
+    XtSetArg(args[3],XmNbottomAttachment,XmATTACH_WIDGET);
+    XtSetArg(args[4],XmNbottomWidget    ,cancel);
+    fHelpText = XmCreateScrolledText(fHelpForm,(char*)"helpText",args,5);
+    XtManageChild(fHelpText);
+
+    fInteractorManager->AddShell(fShell);
+
+  } else {
+    char* str = fInteractorManager->GetCreationString();
+    if(str!=0) wName = str;
+    fViewer = new SoXtExaminerViewer(parent,wName.c_str(),TRUE);
+  }
+
+  fViewer->setSize(SbVec2s(SIZE,SIZE));
+
+  // Have a GL2PS render action :
+  const SbViewportRegion& vpRegion = fViewer->getViewportRegion();
+  fGL2PSAction = new SoGL2PSAction(vpRegion);
+  fViewer->setGLRenderAction(fGL2PSAction);
+
+  // Else :
+  fViewer->setSceneGraph(fSoSelection);
+  fViewer->viewAll();
+  fViewer->saveHomePosition();
+  fViewer->setTitle(fName);
+  fViewer->show();
+  if(fShell) {
+    SoXt::show(fShell);
+    fInteractorManager->FlushAndWaitExecution ();
+  }
+  fInteractorManager->SetCreatedInteractor (fViewer -> getWidget());
+}
+
+G4OpenInventorXtViewer::~G4OpenInventorXtViewer () {
+  if(fShell) fInteractorManager->RemoveShell(fShell);
+  if(fViewer) {
+    fViewer->setSceneGraph(0);
+    //FIXME : SGI : the below "delete" block things.
+    //FIXME : CoinXt : the below "delete" crashe in ~SoXtRenderArea.
+    //FIXME : delete fViewer;
+  }
+  if(fShell) XtDestroyWidget(fShell);
+}
+
+void G4OpenInventorXtViewer::FinishView () {
+  if(!fViewer) return;
+  fViewer->viewAll();
+  fViewer->saveHomePosition();
+}
+
+void G4OpenInventorXtViewer::SetView () {
+  G4OpenInventorViewer::SetView ();
+  if(!fViewer) return;
+  // Background.
+  G4Colour b = fVP.GetBackgroundColour ();
+  fViewer->setBackgroundColor
+    (SbColor((float)b.GetRed(),(float)b.GetGreen(),(float)b.GetBlue()));
+}
+
+
+void G4OpenInventorXtViewer::ViewerRender () {
+  if(!fViewer) return;
+  fViewer->render();
+}
+
+SoCamera* G4OpenInventorXtViewer::GetCamera () {
+  if(!fViewer) return 0;
+  return fViewer->getCamera();
+}
+
+Widget G4OpenInventorXtViewer::AddMenu(
+ Widget aMenuBar
+,const G4String& aName
+,const G4String& aLabel
+)
+{
+  // Pulldown menu :
+  Widget menu = XmCreatePulldownMenu(aMenuBar,(char*)aName.c_str(),NULL,0);
+  // Cascade button :
+  Arg args[2];
+  XmString cps = 
+    XmStringLtoRCreate((char*)aLabel.c_str(),XmSTRING_DEFAULT_CHARSET);
+  XtSetArg (args[0],XmNlabelString,cps);
+  XtSetArg (args[1],XmNsubMenuId,menu);
+  Widget widget = XmCreateCascadeButton(aMenuBar,(char*)aName.c_str(),args,2);
+  XmStringFree (cps);
+  XtManageChild(widget);
+  return menu;
+}
+void G4OpenInventorXtViewer::AddButton (
+ Widget aMenu
+,const G4String& aLabel
+,XtCallbackProc aCallback
+)
+{
+  Widget widget = XmCreatePushButton(aMenu,(char*)aLabel.c_str(),NULL,0);
+  XtManageChild(widget);
+  XtAddCallback(widget,XmNactivateCallback,aCallback,(XtPointer)this);
+}
+
+void G4OpenInventorXtViewer::HelpCancelCbk(
+  Widget,XtPointer aData,XtPointer) {
+  G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
+  XtUnmanageChild(This->fHelpForm);
+}
+
+
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+
+void G4OpenInventorXtViewer::EscapeCbk(
+  Widget,XtPointer aData,XtPointer) {
+  G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
+  This->Escape();
+}
+
+void G4OpenInventorXtViewer::PostScriptCbk(
+  Widget,XtPointer aData,XtPointer) {
+  G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
+  This->WritePostScript();
+}
+
+void G4OpenInventorXtViewer::PixmapPostScriptCbk(
+  Widget,XtPointer aData,XtPointer) {
+  G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
+  This->WritePixmapPostScript();
+}
+
+void G4OpenInventorXtViewer::SceneGraphStatisticsCbk(
+  Widget,XtPointer aData,XtPointer) {
+  G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
+  This->SceneGraphStatistics();
+}
+
+void G4OpenInventorXtViewer::WriteInventorCbk(
+  Widget,XtPointer aData,XtPointer) {
+  G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
+  This->WriteInventor();
+}
+
+void G4OpenInventorXtViewer::EraseDetectorCbk(
+  Widget,XtPointer aData,XtPointer) {
+  G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
+  This->EraseDetector();
+}
+
+void G4OpenInventorXtViewer::EraseEventCbk(
+  Widget,XtPointer aData,XtPointer) {
+  G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
+  This->EraseEvent();
+}
+
+void G4OpenInventorXtViewer::SetSolidCbk(
+  Widget,XtPointer aData,XtPointer) {
+  G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
+  This->SetSolid();
+}
+
+void G4OpenInventorXtViewer::SetWireFrameCbk(
+  Widget,XtPointer aData,XtPointer) {
+  G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
+  This->SetWireFrame();
+}
+
+void G4OpenInventorXtViewer::SetReducedWireFrameCbk(
+  Widget,XtPointer aData,XtPointer) {
+  G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
+  This->SetReducedWireFrame(true);
+}
+
+void G4OpenInventorXtViewer::SetFullWireFrameCbk(
+  Widget,XtPointer aData,XtPointer) {
+  G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
+  This->SetReducedWireFrame(false);
+}
+
+void G4OpenInventorXtViewer::UpdateSceneCbk(
+  Widget,XtPointer aData,XtPointer) {
+  G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
+  This->UpdateScene();
+}
+
+void G4OpenInventorXtViewer::SetPreviewCbk(
+  Widget,XtPointer aData,XtPointer) {
+  G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
+  This->SetPreview();
+}
+
+void G4OpenInventorXtViewer::SetPreviewAndFullCbk(
+  Widget,XtPointer aData,XtPointer) {
+  G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
+  This->SetPreviewAndFull();
+}
+
+void G4OpenInventorXtViewer::HelpCbk(
+  Widget,XtPointer aData,XtPointer) {
+  G4OpenInventorXtViewer* This = (G4OpenInventorXtViewer*)aData;
+  XtManageChild(This->fHelpForm);
+  XmTextSetString(This->fHelpText,(char*)This->Help().c_str());
+}
+
+
+#endif
+
+
Index: /trunk/geant4/visualization/OpenInventor/src/Geant4_gl2ps.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/Geant4_gl2ps.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/Geant4_gl2ps.h	(revision 529)
@@ -0,0 +1,123 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+#ifndef Geant4_gl2ps_h
+#define Geant4_gl2ps_h
+
+// gl2ps-0.73.
+// The gl2ps code is prefixed by Geant4_ in order
+// to avoid clashes with other gl2ps code that may come at link
+// time from other channels.
+
+#define gl2psBeginPage Geant4_gl2psBeginPage
+#define gl2psEndPage Geant4_gl2psEndPage
+#define gl2psText Geant4_gl2psText
+#define gl2psEnable Geant4_gl2psEnable
+#define gl2psDisable Geant4_gl2psDisable
+#define gl2psPointSize Geant4_gl2psPointSize
+#define gl2psLineWidth Geant4_gl2psLineWidth
+#define gl2psNumShadeColors Geant4_gl2psNumShadeColors
+#define gl2psDrawPixels Geant4_gl2psDrawPixels
+#define gl2psBeginViewport Geant4_gl2psBeginViewport
+#define gl2psEndViewport Geant4_gl2psEndViewport
+
+#define gl2psMsg Geant4_gl2psMsg
+#define gl2psMalloc Geant4_gl2psMalloc
+#define gl2psRealloc Geant4_gl2psRealloc
+#define gl2psFree Geant4_gl2psFree
+#define gl2psListRealloc Geant4_gl2psListRealloc
+#define gl2psListCreate Geant4_gl2psListCreate
+#define gl2psListDelete Geant4_gl2psListDelete
+#define gl2psListAdd Geant4_gl2psListAdd
+#define gl2psListNbr Geant4_gl2psListNbr
+#define gl2psListPointer Geant4_gl2psListPointer
+#define gl2psListSort Geant4_gl2psListSort
+#define gl2psListAction Geant4_gl2psListAction
+#define gl2psListActionInverse Geant4_gl2psListActionInverse
+#define gl2psComparePointPlane Geant4_gl2psComparePointPlane
+#define gl2psPsca Geant4_gl2psPsca
+#define gl2psPvec Geant4_gl2psPvec
+#define gl2psNorm Geant4_gl2psNorm
+#define gl2psGetNormal Geant4_gl2psGetNormal
+#define gl2psGetPlane Geant4_gl2psGetPlane
+#define gl2psCutEdge Geant4_gl2psCutEdge
+#define gl2psCreateSplitPrimitive Geant4_gl2psCreateSplitPrimitive
+#define gl2psAddIndex Geant4_gl2psAddIndex
+#define gl2psGetIndex Geant4_gl2psGetIndex
+#define gl2psTestSplitPrimitive Geant4_gl2psTestSplitPrimitive
+#define gl2psSplitPrimitive Geant4_gl2psSplitPrimitive
+#define gl2psDivideQuad Geant4_gl2psDivideQuad
+#define gl2psCompareDepth Geant4_gl2psCompareDepth
+#define gl2psTrianglesFirst Geant4_gl2psTrianglesFirst
+#define gl2psFindRoot Geant4_gl2psFindRoot
+#define gl2psFreePrimitive Geant4_gl2psFreePrimitive
+#define gl2psAddPrimitiveInList Geant4_gl2psAddPrimitiveInList
+#define gl2psFreeBspTree Geant4_gl2psFreeBspTree
+#define gl2psGreater Geant4_gl2psGreater
+#define gl2psLess Geant4_gl2psLess
+#define gl2psBuildBspTree Geant4_gl2psBuildBspTree
+#define gl2psTraverseBspTree Geant4_gl2psTraverseBspTree
+#define gl2psGetPlaneFromPoints Geant4_gl2psGetPlaneFromPoints
+#define gl2psFreeBspImageTree Geant4_gl2psFreeBspImageTree
+#define gl2psCheckPoint Geant4_gl2psCheckPoint
+#define gl2psAddPlanesInBspTreeImage Geant4_gl2psAddPlanesInBspTreeImage
+#define gl2psCheckPrimitive Geant4_gl2psCheckPrimitive
+#define gl2psCreateSplitPrimitive2D Geant4_gl2psCreateSplitPrimitive2D
+#define gl2psSplitPrimitive2D Geant4_gl2psSplitPrimitive2D
+#define gl2psAddInImageTree Geant4_gl2psAddInImageTree
+#define gl2psAddInImage Geant4_gl2psAddInImage
+#define gl2psAddBoundaryInList Geant4_gl2psAddBoundaryInList
+#define gl2psBuildPolygonBoundary Geant4_gl2psBuildPolygonBoundary
+#define gl2psAddPolyPrimitive Geant4_gl2psAddPolyPrimitive
+#define gl2psGetVertex Geant4_gl2psGetVertex
+#define gl2psParseFeedbackBuffer Geant4_gl2psParseFeedbackBuffer
+#define gl2psSameColor Geant4_gl2psSameColor
+#define gl2psVertsSameColor Geant4_gl2psVertsSameColor
+#define gl2psPrintPostScriptHeader Geant4_gl2psPrintPostScriptHeader
+#define gl2psPrintPostScriptColor Geant4_gl2psPrintPostScriptColor
+#define gl2psResetPostScriptColor Geant4_gl2psResetPostScriptColor
+#define gl2psPrintPostScriptPrimitive Geant4_gl2psPrintPostScriptPrimitive
+#define gl2psPrintPostScriptFooter Geant4_gl2psPrintPostScriptFooter
+#define gl2psPrintTeXHeader Geant4_gl2psPrintTeXHeader
+#define gl2psPrintTeXPrimitive Geant4_gl2psPrintTeXPrimitive
+#define gl2psPrintTeXFooter Geant4_gl2psPrintTeXFooter
+
+#define gl2psPrintPostScriptBeginViewport Geant4_gl2psPrintPostScriptBeginViewport
+#define gl2psPrintPostScriptEndViewport Geant4_gl2psPrintPostScriptEndViewport
+
+#define gl2psWriteByte Geant4_gl2psWriteByte
+#define gl2psGetRGB Geant4_gl2psGetRGB
+#define gl2psPrintPostScriptPixmap Geant4_gl2psPrintPostScriptPixmap
+#define gl2psListReset Geant4_gl2psListReset
+#define gl2psAddInBspImageTree Geant4_gl2psAddInBspImageTree
+#define gl2psPrintPrimitives Geant4_gl2psPrintPrimitives
+#define gl2psPrintTeXBeginViewport Geant4_gl2psPrintTeXBeginViewport
+#define gl2psPrintTeXEndViewport Geant4_gl2psPrintTeXEndViewport
+
+#define gl2ps Geant4_gl2ps
+
+#include "gl2ps.h"
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/SbPainter.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/SbPainter.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/SbPainter.cc	(revision 529)
@@ -0,0 +1,79 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+/*----------------------------HEPVis----------------------------------------*/
+/*                                                                          */
+/* Node:             SbPainter                                              */
+/* Author:           Guy Barrand                                            */
+/*                                                                          */
+/*--------------------------------------------------------------------------*/
+
+// this :
+#include <HEPVis/SbPainter.h>
+
+//////////////////////////////////////////////////////////////////////////////
+SbPainter::SbPainter(
+)
+:fWindowWidth(0)
+,fWindowHeight(0)
+,fRed(0.)
+,fGreen(0.)
+,fBlue(0.)
+,fEdges(FALSE)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+}
+//////////////////////////////////////////////////////////////////////////////
+SbPainter::~SbPainter(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainter::setWindowSize(
+ int aWindowWidth
+,int aWindowHeight
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  fWindowWidth = aWindowWidth;
+  fWindowHeight = aWindowHeight;
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainter::enableEdges(
+ SbBool aValue
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  fEdges = aValue;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/SbPainterPS.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/SbPainterPS.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/SbPainterPS.cc	(revision 529)
@@ -0,0 +1,1055 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+/*----------------------------HEPVis----------------------------------------*/
+/*                                                                          */
+/* Node:             SbPainterPS                                            */
+/* Author:           Guy Barrand                                            */
+/*                                                                          */
+/*--------------------------------------------------------------------------*/
+// this :
+#include <HEPVis/SbPainterPS.h>
+
+//#include <HEPVis/SbString.h>
+#define STRDUP(str)  ((str) != NULL ? (::strcpy((char*)::malloc((unsigned)::strlen(str) + 1), str)) : (char*)NULL)
+#define STRDEL(str) {if((str)!=NULL) {::free(str);str=NULL;}}
+
+//#define DEBUG
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <time.h>
+#include <locale.h>
+
+#define METAFILE_DEFAULT "out.ps"
+#define METAFILE_SCALE 1.
+
+static char* GetDate();
+static double ConvertRGB_ToGrey(double,double,double);
+//////////////////////////////////////////////////////////////////////////////
+SbPainterPS::SbPainterPS(
+)
+:fDeviceWidth((8.5-1.) * 72. * METAFILE_SCALE) /* 540. * METAFILE_SCALE */
+,fDeviceHeight(11.     * 72. * METAFILE_SCALE) /* 792. * METAFILE_SCALE */
+,fPageNumber(0)
+,fPagePos(0)
+,fMarkerSize(2.)
+,fFile(NULL)
+,fFileName(NULL)
+,fGSave(0)
+,fBufferCount(0)
+,fBufferString(NULL)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  fParams.shade = Color;
+  fParams.portrait = 1;
+  fParams.nbit = 2;
+  fParams.doBack = 1;
+  fParams.lineWidth = -1.;
+#ifdef WIN32
+  ::setlocale(LC_NUMERIC,"USA");
+#endif
+}
+//////////////////////////////////////////////////////////////////////////////
+SbPainterPS::~SbPainterPS(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(fFile!=NULL) closeStream ();
+  if(fBufferString!=NULL) ::free(fBufferString);
+  fBufferString = NULL;
+  if(fGSave!=0) {
+    ::printf("SbPainterPS : bad gsave/grestore balance : %d.\n",fGSave);
+  }
+}
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::beginTraversal (
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(fFile==NULL) openFileForWriting(NULL);
+  if(fFile==NULL) return;
+  putBeginPageInStream();
+  putPageScaleInStream((float)fWindowWidth,(float)fWindowHeight);
+  putSaveStateInStream();
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::endTraversal(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(fFile==NULL) return;
+  putFrameInStream(0.0,0.0,0.0,(float)fWindowWidth,(float)fWindowHeight);
+  putRestoreStateInStream();
+  putEndPageInStream();
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::clearColorBuffer(
+ float aRed
+,float aGreen
+,float aBlue
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(fFile==NULL) return;
+  putBackgroundInStream(aRed,aGreen,aBlue,
+                           (float)fWindowWidth,(float)fWindowHeight);
+}
+/*
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::drawPrimitive (
+ SbPrimitiveType aType
+,int aPointn
+,float* aXs
+,float* aYs
+,float* //aZs
+,const SbPainterContext& aAtb
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(fFile==NULL) return;
+  switch(aType) {
+  case SbPrimitivePoints:
+    drawMarkers(aPointn,
+                aXs,aYs,
+                aAtb.fRed,aAtb.fGreen,aAtb.fBlue,
+                aAtb.fMarkerStyle,aAtb.fMarkerSize);
+    break;
+  case SbPrimitiveLineStrip:
+  case SbPrimitiveLineLoop:
+    drawLines(aPointn,
+              aXs,aYs,
+              aAtb.fRed,aAtb.fGreen,aAtb.fBlue,
+              aAtb.fLineStyle,aAtb.fLineWidth);
+    break;
+  case SbPrimitivePolygon:
+    drawPolygon(aPointn,
+                aXs,aYs,
+                aAtb.fRed,aAtb.fGreen,aAtb.fBlue,
+                aAtb.fAreaStyle);
+    break;
+  default:
+    break;
+  }
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::drawPolygon(
+ int aPointn
+,float* aXs
+,float* aYs
+,float aRed
+,float aGreen
+,float aBlue
+,const SbAreaStyle& //aStyle
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(fFile==NULL) return;
+  if(aPointn<=0) return;
+  putNewPathInStream(); 
+  putMoveInStream(aXs[0],aYs[0]);
+  for(int count=1;count<aPointn;count++) {
+    putLineToInStream(aXs[count] - aXs[count-1],
+                      aYs[count] - aYs[count-1]);
+  }
+  if ( (aXs[0]==aXs[aPointn-1]) &&
+       (aYs[0]==aYs[aPointn-1]) ) 
+    putClosePathInStream();
+  putRGB_InStream(aRed,aGreen,aBlue);
+  putFillInStream();
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::drawLines(
+ int aPointn
+,float* aXs
+,float* aYs
+,float aRed
+,float aGreen
+,float aBlue
+,const SbLineStyle& aStyle
+,int aWidth
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(fFile==NULL) return;
+  if(aPointn<=0) return;
+  putMoveInStream(aXs[0],aYs[0]);
+  for(int count=1;count<aPointn;count++) {
+    putLineToInStream(aXs[count] - aXs[count-1],
+                      aYs[count] - aYs[count-1]);
+  }
+  if ( (aXs[0]==aXs[aPointn-1]) &&
+       (aYs[0]==aYs[aPointn-1]) ) 
+    putClosePathInStream();
+  putRGB_InStream(aRed,aGreen,aBlue);
+  putLineWidthInStream(aWidth);
+  putCapInStream(1);
+  putLineStyleInStream(aStyle);
+  putStrokeInStream();
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::drawMarkers (
+ int aPointn
+,float* aXs
+,float* aYs
+,float aRed
+,float aGreen
+,float aBlue
+,const SbMarkerStyle& aStyle 
+,int aSize
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(fFile==NULL) return;
+  float mark_size  = (float)(aSize <=0 ? 1. : aSize);   
+  mark_size *= 0.6F;
+  if(aStyle==SbMarkerCircleLine) {
+    putNewPathInStream();
+    int icount = 1;
+    for(int count=0;count<aPointn;count++) {
+      putCircleInStream(aXs[count],aYs[count],mark_size);
+#define MAX_PATH_POINT 100
+      if(icount==MAX_PATH_POINT) {
+        putRGB_InStream(aRed,aGreen,aBlue);
+        putLineWidthInStream(1);
+        putCapInStream(1);
+        putStrokeInStream();
+        icount = 1;
+        if(count!=aPointn-1) putNewPathInStream();
+      } else {
+        icount++;
+      }
+    }
+    putRGB_InStream(aRed,aGreen,aBlue);
+    putLineWidthInStream(1);
+    putCapInStream(1);
+    putStrokeInStream();
+  } else {
+    putNewPathInStream();
+    int icount = 1;
+    for(int count=0;count<aPointn;count++) {
+      putMoveInStream(aXs[count],aYs[count]);
+      putMarkerSizeInStream(mark_size);
+      putMarkerStyleInStream(aStyle);
+      if(icount==MAX_PATH_POINT) {
+        putRGB_InStream(aRed,aGreen,aBlue);
+        putLineWidthInStream(1);
+        putCapInStream(1);
+        putStrokeInStream();
+        icount = 1;
+        if(count!=aPointn-1) putNewPathInStream();
+      } else {
+        icount++;
+      }
+    }
+    putRGB_InStream(aRed,aGreen,aBlue);
+    putLineWidthInStream(1);
+    putCapInStream(1);
+    putStrokeInStream();
+  }
+}
+*/
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::setColorScheme(
+ int aShade
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  fParams.shade = aShade;
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::setOrientation(
+ int aPortrait
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  fParams.portrait = aPortrait;
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::setBackgroundDrawn(
+ int aDoback
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  fParams.doBack = aDoback;
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::setBitsPerPixel(
+ int aNbit
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if( (aNbit==2) || (aNbit==4) || (aNbit==8) )
+    fParams.nbit = aNbit;
+  else 
+    fParams.nbit = 2;
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::setLineWidth(
+ int aWidth
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  fParams.lineWidth = (float)aWidth;
+}
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::setFileName(
+ const char* aString
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  STRDEL(fFileName);
+  fFileName = STRDUP(aString);
+}
+//////////////////////////////////////////////////////////////////////////////
+const char* SbPainterPS::getFileName(
+) const
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  return fFileName;
+}
+//////////////////////////////////////////////////////////////////////////////
+void* SbPainterPS::getStream(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  return fFile;
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::openFileForWriting(
+ const char* aString
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(fFile!=NULL) closeStream ();
+  if( (aString==NULL) || (*aString=='\0') ) {
+    if( (fFileName==NULL) || (*fFileName=='\0') ) { // Take default name :
+      fFile = ::fopen(METAFILE_DEFAULT,"wb");
+      STRDEL(fFileName);
+      fFileName = STRDUP(METAFILE_DEFAULT);
+    } else {
+      fFile = ::fopen(fFileName,"wb");
+    }
+  } else {
+    fFile = ::fopen(aString,"wb");
+    STRDEL(fFileName);
+    fFileName = STRDUP(aString);
+  }
+  if(fFile==NULL) return;
+
+  fBufferCount = 0;
+  fBufferPointer[METAFILE_RECORD_LENGTH] = '\0';
+  fPageNumber = 0;
+  // Header :
+  printFLN   ("%%!PS-Adobe-2.0");
+  printFLN   ("%%%%Creator: HEPVis::SbPainterPS.");
+  printFLN("%%%%CreationDate: %s",GetDate());
+  printFLN("%%%%Title: %s",fFileName);
+  printFLN("%%%%Pages: (atend)");
+  printFLN("%%%%BoundingBox: 0 0 %d %d",
+           (int)fDeviceWidth,(int)fDeviceHeight);
+  printFLN("%%%%DocumentFonts: Courier-Bold");
+  printFLN("%%%%DocumentPaperSizes: a4");
+  printFLN("%%%%EndComments");
+  // PostScript :
+  putSaveStateInStream      ();
+  // General :
+  putInStreamF("/n {newpath} def ");
+  putInStreamF("/cl {closepath} def ");
+  putInStreamF("/s {stroke} def ");
+  putInStreamF("/f {fill} def ");
+  // Move :
+  putInStreamF("/m  {moveto} def ");
+  putInStreamF("/rm {rmoveto} def ");
+  putInStreamF("/rl {rlineto} def ");
+  // Line :
+  putInStreamF("/lc {setlinecap} def ");
+  putInStreamF("/lw {setlinewidth} def ");
+  putInStreamF("/rgb {setrgbcolor} def ");
+  putInStreamF("/ss {[] 0 setdash} def ") ;            /* style solid       */
+  putInStreamF("/sd {[12 6] 0 setdash} def ");         /* style dashed      */
+  putInStreamF("/so {[6 12] 0 setdash} def ");         /* style dotted      */
+  putInStreamF("/sdo {[18 12 6 12] 0 setdash} def ");  /* style dash dotted */
+  // Mark :
+  fMarkerSize = 2.;
+  putInStreamF("/ms 2. def /msi .5 def ");        /* mark size */
+  putInStreamF("/cross {ms ms scale -1. -1. rm  ");
+  putInStreamF("2. 2. rl 0. -2. rm -2. 2. rl msi msi scale} def ");
+  putInStreamF("/plus  {ms ms scale -1. 0. rm 2. 0. rl ");
+  putInStreamF("-1. 1. rm 0. -2. rl msi msi scale} def ");
+  putInStreamF("/asterisk {ms ms scale -1. 0. rm 2. 0. rl -1. 1. rm ");
+  putInStreamF("0. -2. rl 0. 1. rm -0.707 -0.707 rm 1.414 1.414 rl ");
+  putInStreamF("0. -1.414 rm -1.414 1.414 rl msi msi scale} def ");
+  putInStreamF("/triangle {ms ms scale 0. 1. rm -0.6 -1.5 rl ");
+  putInStreamF("1.2 0. rl -0.6 1.5 rl msi msi scale} def ");
+  // Text :
+  putInStreamF("/sh {show} def ");
+  putInStreamF("/df {/Courier-Bold findfont} def ");
+  putInStreamF("/mf {makefont setfont} def ");
+  printFLN("%%%%EndProlog");
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::closeStream(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(fFile==NULL) return;
+  putRestoreStateInStream    ();
+  printFLN("%%%%Trailer");
+  printFLN("%%%%Pages: %d",fPageNumber);
+  printFLN("%%%%EOF");
+  if(fFile!=NULL) ::fclose(fFile);
+  fFile = NULL;
+  STRDEL(fFileName);
+  fFileName = NULL;
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putInStreamF(
+ const char* aFormat 
+,...
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(fFile==NULL) return;
+  va_list  args;
+  va_start(args,aFormat);
+  printV(aFormat,args);
+  va_end(args);
+  int length = ::strlen(fBufferString);
+  if(length>METAFILE_RECORD_LENGTH) {
+    ::printf("SoPostScript::putInStreamF overflow\n");
+    return;
+  }
+  int nlength = fBufferCount + length;
+  if(nlength>METAFILE_RECORD_LENGTH) {
+      fBufferPointer[fBufferCount] = '\0';
+      if(::fprintf(fFile,"%s\n",(char*)fBufferPointer)<0) {
+        ::printf("SoPostScript::putInStreamF fprintf error\n");
+      }
+      fBufferCount = 0;
+      nlength = length;
+    }
+  unsigned char* pointer = fBufferPointer + fBufferCount;
+  ::strcpy((char*)pointer,fBufferString);
+  fBufferCount = nlength;
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::printFLN(
+ const char* aFormat 
+,...
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(fFile==NULL) return;
+  va_list args;
+  va_start(args,aFormat);
+  printV(aFormat,args);
+  va_end(args);
+/* put buffer in file */
+  if(fBufferCount>0) {
+    fBufferPointer[fBufferCount] = '\0';
+    if(::fprintf (fFile,"%s\n",(char*)fBufferPointer)<0) {
+      ::printf("SbPainterPS::printFLN fprintf error\n");
+    }
+    fBufferCount = 0;
+  }
+/* put comment in file */
+  if(::fprintf (fFile,"%s\n",fBufferString)<0) {
+    ::printf("SbPainterPS::printFLN fprintf error\n");
+  }
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::printV(
+ const char* This 
+,va_list aArgs  
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+#define MAX_STR    2048
+  if(fBufferString==NULL) {
+    fBufferString = (char*)::malloc(MAX_STR * sizeof(char));
+    if(fBufferString==NULL) return;
+  }
+  fBufferString[MAX_STR-1]  = '\0';
+  ::vsprintf(fBufferString,This,aArgs);
+  if(fBufferString[MAX_STR-1]!='\0') {
+    ::printf("SbPainterPS::printV overflow\n");
+    fBufferString[0] = '\0';
+  }
+}
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putPageScaleInStream(
+ float aWidth 
+,float aHeight 
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(aWidth <=0.) aWidth  = 100.;
+  if(aHeight<=0.) aHeight = 100.;
+
+  putScaleInStream (1./METAFILE_SCALE,1./METAFILE_SCALE);
+  putTranslationInStream ((float)(fDeviceWidth/20.),
+                          (float)(fDeviceHeight/30.));
+
+  float scale;
+  if(fDeviceWidth<=fDeviceHeight)
+    scale = (aHeight<=aWidth ? 
+             fDeviceWidth /aWidth  : fDeviceWidth /aHeight );
+  else 
+    scale = (aHeight<=aWidth ? 
+             fDeviceHeight /aWidth : fDeviceHeight /aHeight );
+
+  float xtra,ytra;
+  if(fParams.portrait==1) {
+    xtra = (fDeviceWidth  - scale * aWidth)/2;
+    ytra = (fDeviceHeight - scale * aHeight)/2;
+  } else {
+    putTranslationInStream(fDeviceWidth,0.);
+    putRotateInStream(90);
+    xtra = (fDeviceHeight  - scale * aWidth)/2;
+    ytra = (fDeviceWidth   - scale * aHeight)/2;
+  }
+  putTranslationInStream (xtra,ytra);
+
+  putScaleInStream (scale,scale);
+}
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putSaveStateInStream(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  putInStreamF("gsave ");
+  fGSave++;
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putRestoreStateInStream(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  putInStreamF("grestore ");
+  fGSave--;
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putTranslationInStream(
+ float aX
+,float aY
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  putInStreamF("%.2f %.2f translate ",aX,aY);
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putScaleInStream(
+ float aX
+,float aY
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  putInStreamF("%.2f %.2f scale ",aX,aY);
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putBeginPageInStream(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  fPageNumber++;
+  printFLN("%%%%Page: %d %d",fPageNumber,fPageNumber);
+  putSaveStateInStream();
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putEndPageInStream (
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  putInStreamF("showpage ");
+  putRestoreStateInStream();
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putRGB_InStream (
+ float aR 
+,float aG
+,float aB 
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(fParams.shade==Color)       
+    putInStreamF("%.2f %.2f %.2f rgb ",aR,aG,aB);
+  else if(fParams.shade==Grey)
+    putInStreamF("%.2f setgray ",convertRGB_ToGrey(aR,aG,aB));
+  else if(fParams.shade==BlackWhite)  
+    putInStreamF("0. setgray ",convertRGB_ToGrey(aR,aG,aB));
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putLineWidthInStream(
+ int aWidth
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(fParams.lineWidth<0.) {
+    if(aWidth==1) {
+      putInStreamF("%.1f lw ",0.5); // For a better rendering.
+    } else {
+      putInStreamF("%.1f lw ",(float)(aWidth));
+    }
+  } else {
+    putInStreamF("%.1f lw ",fParams.lineWidth); 
+  }
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putMarkerSizeInStream (
+ float aSize
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(aSize==fMarkerSize) return;
+  fMarkerSize = aSize;
+  putInStreamF("/ms %g def /msi %g def ",aSize,1./aSize);
+}
+/*
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putMarkerStyleInStream (
+ SbMarkerStyle aStyle 
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  switch (aStyle) {
+  case SbMarkerPlus:
+    putInStreamF("plus ");
+    break;
+  case SbMarkerAsterisk:
+  case SbMarkerStar:
+    putInStreamF("asterisk ");
+    break;
+  case SbMarkerCross:
+    putInStreamF("cross ");
+    break;
+  case SbMarkerTriangleUpLine:
+    putInStreamF("triangle ");
+    break;
+  default:
+    putLineToInStream(0.,0.);
+    break;
+  }
+}
+*/
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putBackgroundInStream (
+ float aR
+,float aG
+,float aB
+,float aWidth 
+,float aHeight 
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  putNewPathInStream(); 
+  putMoveInStream(0.,0.);
+  putLineToInStream(aWidth,0.);
+  putLineToInStream(0.,aHeight);
+  putLineToInStream(-aWidth,0.);
+  putLineToInStream(0.,-aHeight);
+  putClosePathInStream();
+  if(fParams.doBack==1) {
+    // Back :
+    putSaveStateInStream();
+    putRGB_InStream(aR,aG,aB);
+    putFillInStream();       
+    putRestoreStateInStream();
+  }
+  // Clip :
+  putInStreamF("clip ");
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putFrameInStream (
+ float aR
+,float aG
+,float aB
+,float aWidth 
+,float aHeight 
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  putNewPathInStream(); 
+  putMoveInStream(0.,0.);
+  putLineToInStream(aWidth,0.);
+  putLineToInStream(0.,aHeight);
+  putLineToInStream(-aWidth,0.);
+  putLineToInStream(0.,-aHeight);
+  putClosePathInStream();
+  putRGB_InStream(aR,aG,aB);
+  putLineWidthInStream(1);
+  putCapInStream(1);
+  putInStreamF("ss ");
+  putStrokeInStream();
+}
+//////////////////////////////////////////////////////////////////////////////
+float SbPainterPS::convertRGB_ToGrey (
+ float aRed
+,float aGreen
+,float aBlue
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  return (0.3F * aRed + 0.59F * aGreen + 0.11F * aBlue);
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putRotateInStream(
+ float aX                  
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  putInStreamF("%.2f  rotate ",aX);
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putNewPathInStream(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  putInStreamF("n ");
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putStrokeInStream(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  putInStreamF("s ");
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putFillInStream(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  putInStreamF("f ");
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putClosePathInStream(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  putInStreamF("cl ");
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putCapInStream(
+ int aX
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  putInStreamF("%1d lc ",aX);
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putLineToInStream(
+ float aX
+,float aY
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  putInStreamF ("%.2f %.2f rl ",aX,aY);
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putMoveInStream(
+ float aX
+,float aY
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  putInStreamF ("%.2f %.2f m ",aX,aY);
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putCircleInStream(
+ float aX                            
+,float aY                            
+,float aR                            
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  putInStreamF("%.2f %.2f %.2f 0 360 arc s ",aX,aY,aR);
+}
+/*
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putLineStyleInStream(
+ SbLineStyle aStyle
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  switch(aStyle) {
+  case SbLineSolid:putInStreamF("ss ") ;break;
+  case SbLineDashed:putInStreamF("sd ") ;break;
+  case SbLineDotted:putInStreamF("so ") ;break;
+  case SbLineDashDotted:putInStreamF("sdo ");break;
+  }
+}
+*/
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+/////// Image ////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::putImageInStream (
+ unsigned int aWidth
+,unsigned int aHeight
+,GetRGB_Function aProc
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if((aWidth<=0)||(aHeight<=0)) return;
+  if(!aProc) return;
+
+  putSaveStateInStream      ();
+  putInStreamF     ("%d %d scale ", aWidth, aHeight ); 
+  int status = 1;
+  int      nbhex;
+  unsigned int row,col,col_max;
+  double   dr,dg,db;
+  typedef unsigned char Uchar;
+  Uchar    red,green,blue,b;
+  if(fParams.shade!=0) { /*grey*/
+    putInStreamF   ("/picstr %d string def ",aWidth); 
+    putInStreamF   ("%d %d %d ",aWidth,aHeight,8); 
+    putInStreamF   ("[ %d 0 0 -%d 0 %d ] ",aWidth,aHeight,aHeight); 
+    putInStreamF   ("{ currentfile picstr readhexstring pop } " );
+    printFLN ("image " );
+    for ( row = 0; row < aHeight; row++ ){
+      for ( col = 0; col < aWidth; col++){ 
+        double    fgrey;
+        Uchar     grey;
+        status    = aProc(col,row,dr,dg,db)==0 ? 0 : status;
+        fgrey     = ConvertRGB_ToGrey(dr,dg,db);
+        grey      = (Uchar) ( 255. * fgrey);
+        writeByte (grey);
+      }
+    }
+    nbhex     = aWidth * aHeight * 2; 
+    printFLN ("%%%% nbhex digit          :%d ",nbhex); 
+    printFLN ("%%%% nbhex/record_length  :%d ",nbhex/METAFILE_RECORD_LENGTH); 
+    printFLN ("%%%% nbhex%%record_length :%d ",nbhex%METAFILE_RECORD_LENGTH); 
+  }else if(fParams.nbit==2){ 
+    int       nbyte2;
+    nbyte2    = (aWidth   *  3)/4;
+    nbyte2   /=3;
+    nbyte2   *=3;
+    col_max   = (nbyte2  *  4)/3;
+    /* 2 bit for r and g and b   */
+    /* rgbs following each other */
+    putInStreamF   ("/rgbstr %d string def ",nbyte2); 
+    putInStreamF   ("%d %d %d ",col_max,aHeight,2); 
+    putInStreamF   ("[ %d 0 0 -%d 0 %d ] ",col_max,aHeight,aHeight); 
+    putInStreamF   ("{ currentfile rgbstr readhexstring pop } " );
+    putInStreamF   ("false 3 " );
+    printFLN ("colorimage " );
+    for ( row = 0; row < aHeight; row++ ){
+      for ( col = 0; col < col_max; col+=4){
+        status  = aProc(col,row,dr,dg,db)==0 ? 0 : status;
+        red     = (Uchar) ( 3. * dr);
+        green   = (Uchar) ( 3. * dg);
+        blue    = (Uchar) ( 3. * db);
+        b       = red;
+        b       = (b<<2)+green;
+        b       = (b<<2)+blue;
+        status  = aProc(col+1,row,dr,dg,db)==0 ? 0 : status;
+        red     = (Uchar) ( 3. * dr);
+        green   = (Uchar) ( 3. * dg);
+        blue    = (Uchar) ( 3. * db);
+        b     = (b<<2)+red;
+        writeByte (b);
+        
+        b       = green;
+        b       = (b<<2)+blue;
+        status  = aProc(col+2,row,dr,dg,db)==0 ? 0 : status;
+        red     = (Uchar) ( 3. * dr);
+        green   = (Uchar) ( 3. * dg);
+        blue    = (Uchar) ( 3. * db);
+        b     = (b<<2)+red;
+        b     = (b<<2)+green;
+        writeByte (b);
+        
+        b       = blue;
+        status  = aProc(col+3,row,dr,dg,db)==0 ? 0 : status;
+        red     = (Uchar) ( 3. * dr);
+        green   = (Uchar) ( 3. * dg);
+        blue    = (Uchar) ( 3. * db);
+        b     = (b<<2)+red;
+        b     = (b<<2)+green;
+        b     = (b<<2)+blue;
+        writeByte (b);
+      }
+    }
+  }else if(fParams.nbit==4){ 
+    int       nbyte4;
+    nbyte4    = (aWidth  * 3)/2;
+    nbyte4   /=3;
+    nbyte4   *=3;
+    col_max   = (nbyte4 * 2)/3;
+    /* 4 bit for r and g and b   */
+    /* rgbs following each other */
+    putInStreamF   ("/rgbstr %d string def ",nbyte4); 
+    putInStreamF   ("%d %d %d ",col_max,aHeight,4); 
+    putInStreamF   ("[ %d 0 0 -%d 0 %d ] ",col_max,aHeight,aHeight); 
+    putInStreamF   ("{ currentfile rgbstr readhexstring pop } " );
+    putInStreamF   ("false 3 " );
+    printFLN ("colorimage " );
+    for ( row = 0; row < aHeight; row++ ){
+      for ( col = 0; col < col_max; col+=2){
+        status  = aProc(col,row,dr,dg,db)==0 ? 0 : status;
+        red     = (Uchar) ( 15. * dr);
+        green   = (Uchar) ( 15. * dg);
+        putInStreamF ("%x%x",red,green);
+        blue    = (Uchar) ( 15. * db);
+        
+        status  = aProc(col+1,row,dr,dg,db)==0 ? 0 : status;
+        red     = (Uchar) ( 15. * dr);
+        putInStreamF ("%x%x",blue,red);
+        green   = (Uchar) ( 15. * dg);
+        blue    = (Uchar) ( 15. * db);
+        putInStreamF ("%x%x",green,blue);
+      }
+    }
+  }else{ 
+    int       nbyte8;
+    nbyte8    = aWidth   * 3;
+    /* 8 bit for r and g and b   */
+    putInStreamF   ("/rgbstr %d string def ",nbyte8); 
+    putInStreamF   ("%d %d %d ",aWidth,aHeight,8); 
+    putInStreamF   ("[ %d 0 0 -%d 0 %d ] ",aWidth,aHeight,aHeight); 
+    putInStreamF   ("{ currentfile rgbstr readhexstring pop } " );
+    putInStreamF   ("false 3 " );
+    printFLN   ("colorimage " );
+    for ( row = 0; row < aHeight; row++ ){
+      for ( col = 0; col < aWidth; col++){
+        status     = aProc(col,row,dr,dg,db)==0 ? 0 : status;
+        red        = (Uchar) ( 255. * dr);
+        writeByte (red);
+        green      = (Uchar) ( 255. * dg);
+        writeByte (green);
+        blue       = (Uchar) ( 255. * db);
+        writeByte (blue);
+      }
+    }
+  }
+  if(status==0) 
+    ::printf("SbPainterPS::putImageInStream: problem to retreive some pixel rgb.\n");
+  putRestoreStateInStream();
+}
+//////////////////////////////////////////////////////////////////////////////
+void SbPainterPS::writeByte (
+ unsigned char a_byte
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  unsigned char h = a_byte / 16;
+  unsigned char l = a_byte % 16;
+  putInStreamF ("%x%x",h,l);
+}
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+char* GetDate (
+)
+//////////////////////////////////////////////////////////////////////////////
+// Return local date.
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  time_t d;
+  time(&d);
+  char* string = ctime(&d);
+  string[24] = '\0';
+  return string;
+}
+//////////////////////////////////////////////////////////////////////////////
+double ConvertRGB_ToGrey(
+ double a_red
+,double a_green
+,double a_blue
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  return (0.30 * a_red + 0.59 * a_green + 0.11 * a_blue);
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/SoAlternateRepAction.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/SoAlternateRepAction.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/SoAlternateRepAction.cc	(revision 529)
@@ -0,0 +1,149 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+
+// this :
+#include <HEPVis/actions/SoAlternateRepAction.h>
+
+// Inventor :
+#include <Inventor/nodes/SoNode.h>
+#include <Inventor/elements/SoSwitchElement.h>
+#include <Inventor/elements/SoCoordinateElement.h>
+
+SO_ACTION_SOURCE(SoAlternateRepAction)
+
+//////////////////////////////////////////////////////////////////////////////
+void SoAlternateRepAction::initClass(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  SO_ACTION_INIT_CLASS(SoAlternateRepAction,SoAction);
+
+  SO_ENABLE(SoAlternateRepAction,SoSwitchElement); //SGI wants that.
+  SO_ENABLE(SoAlternateRepAction,SoCoordinateElement); //For SoMarkerSet.
+
+  SO_ACTION_ADD_METHOD(SoNode,nodeAction);
+}
+//////////////////////////////////////////////////////////////////////////////
+SoAlternateRepAction::SoAlternateRepAction(
+)
+:fGenerate(FALSE)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  SO_ACTION_CONSTRUCTOR(SoAlternateRepAction);
+}
+//////////////////////////////////////////////////////////////////////////////
+SoAlternateRepAction::~SoAlternateRepAction(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+}
+//////////////////////////////////////////////////////////////////////////////
+void SoAlternateRepAction::setGenerate(
+ SbBool aGenerate
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  fGenerate = aGenerate;
+}
+//////////////////////////////////////////////////////////////////////////////
+SbBool SoAlternateRepAction::getGenerate(
+) const
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  return fGenerate;
+}
+
+// Inventor :
+#include <Inventor/nodes/SoNode.h>
+#include <Inventor/nodes/SoGroup.h>
+#include <Inventor/nodes/SoCoordinate3.h>
+
+// HEPVisUtils :
+//#include <HEPVis/nodes/SoHighlightMaterial.h>
+//#include <HEPVis/nodes/SoSplineCurve.h>
+
+#define IF_CLASS(aClass) \
+  if(aNode->isOfType(aClass::getClassTypeId())) {\
+    /*printf("debug : SoAlternateRepAction::nodeAction : %s generate %d\n",#aClass,This->fGenerate);*/\
+    aClass* node = (aClass*)aNode;\
+    if(This->fGenerate==TRUE) {\
+      if(node->alternateRep.getValue()==NULL) {\
+        node->generateAlternateRep();\
+        /* Then go down if needed : */\
+        SoNode* altRep = node->alternateRep.getValue();\
+        if((altRep!=NULL) && altRep->isOfType(SoGroup::getClassTypeId()))\
+          altRep->doAction(This);\
+      }\
+    } else {\
+      /* First go down if needed : */\
+      SoNode* altRep = node->alternateRep.getValue();\
+      if((altRep!=NULL) && altRep->isOfType(SoGroup::getClassTypeId()))\
+        altRep->doAction(This);\
+      /* Then clear : */\
+      node->clearAlternateRep();\
+    }\
+  }
+
+//////////////////////////////////////////////////////////////////////////////
+void SoAlternateRepAction::nodeAction(
+ SoAction* aThis
+,SoNode* aNode
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  /*printf("debug : SoAlternateRepAction::nodeAction : %s %s\n",
+    aNode->getName().getString(),
+    aNode->getTypeId().getName().getString());*/
+  //SoAlternateRepAction* This = (SoAlternateRepAction*)aThis;
+
+  if(false) {}
+  // HEPVisUtils :
+  //else IF_CLASS(SoHighlightMaterial)
+  //else IF_CLASS(SoSplineCurve)
+
+  // Inventor :
+  else if(aNode->isOfType(SoGroup::getClassTypeId())) {
+    aNode->doAction(aThis);
+  }
+  else if(aNode->isOfType(SoCoordinate3::getClassTypeId())) { //For SoMakerSet.
+    aNode->doAction(aThis);
+  }
+  // Else :
+  else if(aNode->getField("alternateRep")!=NULL) {
+    aNode->doAction(aThis);
+  }
+
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/SoBox.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/SoBox.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/SoBox.cc	(revision 529)
@@ -0,0 +1,282 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+//
+// $Id: SoBox.cc,v 1.8 2006/06/29 21:22:36 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+/*----------------------------HEPVis----------------------------------------*/
+/*                                                                          */
+/* Node:             SoBox                                                  */
+/* Description:      Represents the G4Box Geant Geometry entity             */
+/* Author:           Joe Boudreau Nov 11 1996                               */
+/*                                                                          */
+/*--------------------------------------------------------------------------*/
+
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+// this :
+#include "HEPVis/nodes/SoBox.h"
+
+#include <assert.h>
+#include <cmath>
+
+#include <Inventor/SbBox.h>
+#include <Inventor/fields/SoSFFloat.h>
+#include <Inventor/misc/SoChildList.h>
+#include <Inventor/nodes/SoSeparator.h>
+#include <Inventor/nodes/SoCube.h>
+#include <Inventor/nodes/SoScale.h>
+#include <Inventor/actions/SoAction.h>
+#include <Inventor/nodes/SoIndexedFaceSet.h>
+#include <Inventor/SoPrimitiveVertex.h>
+#include <Inventor/elements/SoTextureCoordinateElement.h>
+
+// This statement is required
+SO_NODE_SOURCE(SoBox)
+
+// Constructor
+SoBox::SoBox() {
+  // This statement is required
+  SO_NODE_CONSTRUCTOR(SoBox);
+
+  // Data fields are initialized like this:
+  SO_NODE_ADD_FIELD(fDx,                (1.0));
+  SO_NODE_ADD_FIELD(fDy,                (1.0));
+  SO_NODE_ADD_FIELD(fDz,                (1.0));
+  SO_NODE_ADD_FIELD(alternateRep,       (NULL));
+  children = new SoChildList(this);
+}
+
+// Destructor
+SoBox::~SoBox() {
+ delete children;
+}
+
+
+// initClass
+void SoBox::initClass(){
+  // This statement is required.
+  SO_NODE_INIT_CLASS(SoBox,SoShape,"Shape");
+}
+
+
+// generatePrimitives
+void SoBox::generatePrimitives(SoAction *action) {
+  // This variable is used to store each vertex
+  SoPrimitiveVertex pv;
+
+  // Access the stat from the action
+  SoState *state = action->getState();
+
+  // See if we have to use a texture coordinate function,
+  // rather than generating explicit texture coordinates.
+  SbBool useTexFunction=
+    (SoTextureCoordinateElement::getType(state) == 
+     SoTextureCoordinateElement::FUNCTION);
+
+  // If we need to generate texture coordinates with a function,
+  // we'll need an SoGLTextureCoordinateElement.  Otherwise, we'll
+  // set up the coordinates directly.
+  const SoTextureCoordinateElement *tce = NULL;
+  SbVec4f texCoord;
+  if (useTexFunction) {
+    tce = SoTextureCoordinateElement::getInstance(state);
+  }
+  else {
+    texCoord[2] = 0.0;
+    texCoord[3] = 1.0;
+  }
+  SbVec3f point, normal;
+
+
+  //////////////////////////////////////////
+  //----------------------------------------
+#define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz)  \
+  point.setValue(x,y,z);                   \
+  normal.setValue(nx,ny,nz);               \
+  if (useTexFunction) {                    \
+    texCoord=tce->get(point,normal);       \
+  }                                        \
+  else {                                   \
+    texCoord[0]=s;                         \
+    texCoord[1]=t;                         \
+  }                                        \
+  pv.setPoint(point);                      \
+  pv.setNormal(normal);                    \
+  pv.setTextureCoords(texCoord);           \
+  shapeVertex(&pv);
+  //----------------------------------------
+  //////////////////////////////////////////
+
+  const int NPOINTS=8, NFACES=6, NINDICES = NFACES*5;
+  int indices[NINDICES] = {3,2,1,0, SO_END_FACE_INDEX,  //z back.
+			   4,5,6,7, SO_END_FACE_INDEX,  //z front.
+			   0,1,5,4, SO_END_FACE_INDEX,  //y up.
+			   1,2,6,5, SO_END_FACE_INDEX,  //x left.
+			   2,3,7,6, SO_END_FACE_INDEX,  //y down.
+			   3,0,4,7, SO_END_FACE_INDEX}; //x right.
+
+  
+  // points for the eight vertices
+  float points[NPOINTS][3];
+  points[0][0] =  fDx.getValue(); 
+  points[0][1] =  fDy.getValue(); 
+  points[0][2] = -fDz.getValue();
+
+  points[1][0] = -fDx.getValue();
+  points[1][1] =  fDy.getValue();
+  points[1][2] = -fDz.getValue();
+
+  points[2][0] = -fDx.getValue(); 
+  points[2][1] = -fDy.getValue(); 
+  points[2][2] = -fDz.getValue();
+
+  points[3][0] =  fDx.getValue(); 
+  points[3][1] = -fDy.getValue(); 
+  points[3][2] = -fDz.getValue();
+
+  points[4][0] =  fDx.getValue(); 
+  points[4][1] =  fDy.getValue(); 
+  points[4][2] =  fDz.getValue();
+
+  points[5][0] = -fDx.getValue(); 
+  points[5][1] =  fDy.getValue(); 
+  points[5][2] =  fDz.getValue();
+
+  points[6][0] = -fDx.getValue(); 
+  points[6][1] = -fDy.getValue(); 
+  points[6][2] =  fDz.getValue();
+
+  points[7][0] =  fDx.getValue(); 
+  points[7][1] = -fDy.getValue(); 
+  points[7][2] =  fDz.getValue();
+
+  float normals[NFACES][3];
+  //z back.
+  normals[0][0] =  0  ; normals[0][1] =    0; normals [0][2] =  -1;    
+  //z front.
+  normals[1][0] =  0  ; normals[1][1] =    0; normals [1][2] =   1;    
+  //y up.
+  normals[2][0] =  0  ; normals[2][1] =    1; normals [2][2] =   0;    
+  //x left.
+  normals[3][0] = -1  ; normals[3][1] =    0; normals [3][2] =   0;    
+  //y down.
+  normals[4][0] =  0  ; normals[4][1] =   -1; normals [4][2] =   0;    
+  //x right.
+  normals[5][0] =  1  ; normals[5][1] =    0; normals [5][2] =   0;    
+
+  float x,y,z;
+  int   index;
+  for (int nf=0;nf<NFACES;nf++) {
+    beginShape(action,TRIANGLE_FAN);
+    index = indices[nf * 5];   
+    x = points[index][0];
+    y = points[index][1];
+    z = points[index][2];
+    GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
+    index = indices[nf * 5 + 1];   
+    x = points[index][0];
+    y = points[index][1];
+    z = points[index][2];
+    GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
+    index = indices[nf * 5 + 2];   
+    x = points[index][0];
+    y = points[index][1];
+    z = points[index][2];
+    GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
+    index = indices[nf * 5 + 3];   
+    x = points[index][0];
+    y = points[index][1];
+    z = points[index][2];
+    GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
+    endShape();
+  }
+}
+
+// getChildren
+SoChildList *SoBox::getChildren() const {
+  return children;
+}
+
+
+// computeBBox
+void SoBox::computeBBox(SoAction *, SbBox3f &box, SbVec3f &center ){
+  SbVec3f vmin(-fDx.getValue(),-fDy.getValue(),-fDz.getValue()), 
+          vmax( fDx.getValue(), fDy.getValue(), fDz.getValue());
+  center.setValue(0,0,0);
+  box.setBounds(vmin,vmax);
+}
+
+
+
+
+// updateChildren
+void SoBox::updateChildren() {
+
+
+  // Redraw the G4Box....
+
+  assert(children->getLength()==1);
+  SoSeparator       *sep                = (SoSeparator *)  ( *children)[0];
+  SoScale           *scale              = (SoScale *)( sep->getChild(0));
+  //SoCube            *cube               = (SoCube  *)( sep->getChild(1));
+  scale->scaleFactor.setValue(fDx.getValue(), fDy.getValue(), fDz.getValue());
+}
+
+// generateChildren
+void SoBox::generateChildren() {
+
+  // A box consists of a set of scale factors and a 
+  // cube.
+
+  assert(children->getLength() ==0);
+  SoSeparator      *sep              = new SoSeparator(); 
+  SoScale          *scale            = new SoScale();
+  SoCube           *cube             = new SoCube();
+
+  sep->addChild(scale);
+  sep->addChild(cube);
+  children->append(sep);
+}
+
+// generateAlternateRep
+void SoBox::generateAlternateRep() {
+
+  // This routine sets the alternate representation to the child
+  // list of this mode.  
+
+  if (children->getLength() == 0) generateChildren();
+  updateChildren();
+  alternateRep.setValue((SoSeparator *)  ( *children)[0]);
+}
+
+// clearAlternateRep
+void SoBox::clearAlternateRep() {
+  alternateRep.setValue(NULL);
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/SoCons.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/SoCons.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/SoCons.cc	(revision 529)
@@ -0,0 +1,446 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+//
+// $Id: SoCons.cc,v 1.8 2006/06/29 21:22:38 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+/*-----------------------------HEPVis---------------------------------------*/
+/*                                                                          */
+/* Node:             SoCons                                                 */
+/* Description:      Represents the G4Cons Geant Geometry entity            */
+/* Author:           Joe Boudreau Nov 11 1996                               */
+/*                                                                          */
+/*--------------------------------------------------------------------------*/
+
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+// this :
+#include "HEPVis/nodes/SoCons.h"
+
+#include <assert.h>
+#include <cmath>
+#include <Inventor/SbBox.h>
+#include <Inventor/actions/SoAction.h>
+#include <Inventor/fields/SoSFFloat.h>
+#include <Inventor/misc/SoChildList.h>
+#include <Inventor/nodes/SoSeparator.h>
+#include <Inventor/nodes/SoIndexedFaceSet.h>
+#include <Inventor/nodes/SoNormal.h>
+#include <Inventor/nodes/SoCoordinate3.h>
+#include <Inventor/nodes/SoNormalBinding.h>
+#include <Inventor/SoPrimitiveVertex.h>
+#include <Inventor/elements/SoTextureCoordinateElement.h>
+
+#include "HEPVis/SbMath.h"
+
+// This statement is required
+SO_NODE_SOURCE(SoCons)
+
+// Constructor
+SoCons::SoCons() {
+  // This statement is required
+  SO_NODE_CONSTRUCTOR(SoCons);
+
+  // Data fields are initialized like this:
+  SO_NODE_ADD_FIELD(fRmin1,               (0.0));
+  SO_NODE_ADD_FIELD(fRmin2,               (0.0));
+  SO_NODE_ADD_FIELD(fRmax1,               (1.0));
+  SO_NODE_ADD_FIELD(fRmax2,               (1.0));
+  SO_NODE_ADD_FIELD(fDz,                 (10.0));
+  SO_NODE_ADD_FIELD(fSPhi,                (0.0));
+  SO_NODE_ADD_FIELD(fDPhi,             ((float)(2*M_PI)));
+  SO_NODE_ADD_FIELD(smoothDraw,          (TRUE));
+  SO_NODE_ADD_FIELD(alternateRep,        (NULL));
+  children = new SoChildList(this);
+}
+
+// Destructor
+SoCons::~SoCons() {
+  delete children;
+}
+
+
+// initClass
+void SoCons::initClass(){
+  // This statement is required.
+  SO_NODE_INIT_CLASS(SoCons,SoShape,"Shape");
+}
+
+
+// generatePrimitives
+void SoCons::generatePrimitives(SoAction *action) {
+  // This variable is used to store each vertex
+  SoPrimitiveVertex pv;
+
+  // Access the stat from the action
+  SoState *state = action->getState();
+
+  // See if we have to use a texture coordinate function,
+  // rather than generating explicit texture coordinates.
+  SbBool useTexFunction=
+    (SoTextureCoordinateElement::getType(state) == 
+     SoTextureCoordinateElement::FUNCTION);
+
+  // If we need to generate texture coordinates with a function,
+  // we'll need an SoGLTextureCoordinateElement.  Otherwise, we'll
+  // set up the coordinates directly.
+  const SoTextureCoordinateElement *tce = NULL;
+  SbVec4f texCoord;
+  if (useTexFunction) {
+    tce = SoTextureCoordinateElement::getInstance(state);
+  } else {
+    texCoord[2] = 0.0;
+    texCoord[3] = 1.0;
+  }
+  SbVec3f point, normal;
+
+  ///////////////////////////////////////////////////////
+  //-----------------------------------------------------
+#define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz)               \
+  point.setValue((float)(x),(float)(y),(float)(z));     \
+  normal.setValue((float)(nx),(float)(ny),(float)(nz)); \
+  if (useTexFunction) {                                 \
+    texCoord=tce->get(point,normal);                    \
+  } else {                                              \
+    texCoord[0]=(float)(s);                             \
+    texCoord[1]=(float)(t);                             \
+  }                                                     \
+  pv.setPoint(point);                                   \
+  pv.setNormal(normal);                                 \
+  pv.setTextureCoords(texCoord);                        \
+  shapeVertex(&pv);
+  //-----------------------------------------------------
+  ///////////////////////////////////////////////////////
+
+
+  int NPHI = (int)(2+22*std::fabs(fDPhi.getValue()/(2.0*M_PI)));
+  double deltaPhi = fDPhi.getValue()/NPHI;
+  double phi0     = fSPhi.getValue();
+  double phi1     = phi0 + fDPhi.getValue();
+  double rMax1    = fRmax1.getValue();
+  double rMin1    = fRmin1.getValue();
+  double rMax2    = fRmax2.getValue();
+  double rMin2    = fRmin2.getValue();
+  double zMax     = fDz.getValue();
+  double zMin     = -zMax;
+  double cosPhi0  = std::cos(phi0);
+  double sinPhi0  = std::sin(phi0);
+  double cosPhi1  = std::cos(phi1);
+  double sinPhi1  = std::sin(phi1);
+  double cosDeltaPhi = std::cos(deltaPhi);
+  double sinDeltaPhi = std::sin(deltaPhi);
+  //
+  // The outer surface!
+  //
+  beginShape(action,TRIANGLE_STRIP);
+  int    i;
+  double sinPhi=sinPhi0;
+  double cosPhi=cosPhi0;
+  for (i = 0; i<=NPHI; i++) {
+    GEN_VERTEX(pv,rMax2*cosPhi,rMax2*sinPhi,zMax,0.0,0.0,cosPhi,sinPhi,0);   
+    GEN_VERTEX(pv,rMax1*cosPhi,rMax1*sinPhi,zMin,1.0,1.0,cosPhi,sinPhi,0);   
+    inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);    
+  }
+  endShape();
+  //
+  // The inner surface!
+  //
+  beginShape(action,TRIANGLE_STRIP);
+  sinPhi=sinPhi0;
+  cosPhi=cosPhi0;
+  for (i = 0; i<=NPHI; i++) {
+    GEN_VERTEX(pv,rMin2*cosPhi,rMin2*sinPhi,zMax,0.0,0.0,-cosPhi,-sinPhi,0);   
+    GEN_VERTEX(pv,rMin1*cosPhi,rMin1*sinPhi,zMin,1.0,1.0,-cosPhi,-sinPhi,0);   
+    inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);    
+  } 
+  endShape();
+  if (std::fabs(deltaPhi)<2.0*M_PI) { 
+    //
+    // The end 
+    //
+    beginShape(action,TRIANGLE_STRIP);
+    sinPhi=sinPhi0;
+    cosPhi=cosPhi0;
+    GEN_VERTEX(pv,rMax2*cosPhi,rMax2*sinPhi,zMax,0.0,0.0,sinPhi,-cosPhi,0);   
+    GEN_VERTEX(pv,rMax1*cosPhi,rMax1*sinPhi,zMin,1.0,1.0,sinPhi,-cosPhi,0);   
+    GEN_VERTEX(pv,rMin2*cosPhi,rMin2*sinPhi,zMax,1.0,0.0,sinPhi,-cosPhi,0);   
+    GEN_VERTEX(pv,rMin1*cosPhi,rMin1*sinPhi,zMin,0.0,1.0,sinPhi,-cosPhi,0);   
+    endShape();
+    //
+    // The other end 
+    //
+    beginShape(action,TRIANGLE_STRIP);
+    sinPhi=sinPhi1;
+    cosPhi=cosPhi1;
+    GEN_VERTEX(pv,rMax2*cosPhi,rMax2*sinPhi, zMax,0.0,0.0,-sinPhi,+cosPhi,0);  
+    GEN_VERTEX(pv,rMax1*cosPhi,rMax1*sinPhi, zMin,1.0,1.0,-sinPhi,+cosPhi,0);  
+    GEN_VERTEX(pv,rMin2*cosPhi,rMin2*sinPhi, zMax,1.0,0.0,-sinPhi,+cosPhi,0);  
+    GEN_VERTEX(pv,rMin1*cosPhi,rMin1*sinPhi, zMin,0.0,1.0,-sinPhi,+cosPhi,0);  
+    endShape();
+  }
+
+  //
+  // The outer surface at z=+PDZ
+  //
+  beginShape(action,TRIANGLE_STRIP);
+  sinPhi=sinPhi0;
+  cosPhi=cosPhi0;
+  for (i = 0; i<=NPHI; i++) {
+    GEN_VERTEX(pv,rMin2*cosPhi,rMin2*sinPhi,zMax,0.0,0.0,0,0,1);   
+    GEN_VERTEX(pv,rMax2*cosPhi,rMax2*sinPhi,zMax,1.0,1.0,0,0,1);   
+    inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);    
+  }
+  endShape();
+  //
+  // The outer surface at z=-PDZ
+  //
+  beginShape(action,TRIANGLE_STRIP);
+  sinPhi=sinPhi0;
+  cosPhi=cosPhi0;
+  for (i = 0; i<=NPHI; i++) {
+    GEN_VERTEX(pv,rMin1*cosPhi,rMin1*sinPhi,zMin,0.0,0.0,0,0,-1);   
+    GEN_VERTEX(pv,rMax1*cosPhi,rMax1*sinPhi,zMin,1.0,1.0,0,0,-1);   
+    inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);    
+  }
+  endShape();
+
+}
+
+// getChildren
+SoChildList *SoCons::getChildren() const {
+  return children;
+}
+
+
+// computeBBox
+void SoCons::computeBBox(SoAction *, SbBox3f &box, SbVec3f &center ){
+  float fRmax= fRmax1.getValue();  
+  if (fRmax2.getValue() > fRmax) fRmax = fRmax2.getValue(); 
+
+  SbVec3f vmin(-fRmax,-fRmax,-fDz.getValue()), 
+          vmax( fRmax, fRmax, fDz.getValue());
+  center.setValue(0,0,0);
+  box.setBounds(vmin,vmax);
+}
+
+
+
+
+// updateChildren
+void SoCons::updateChildren() {
+
+
+  // Redraw the G4Cons....
+
+  assert(children->getLength()==1);
+  SoSeparator       *sep                = (SoSeparator *)  ( *children)[0];
+  SoCoordinate3     *theCoordinates     = (SoCoordinate3 *)      ( sep->getChild(0));
+  SoNormal          *theNormals         = (SoNormal *)           ( sep->getChild(1)); 
+  SoNormalBinding   *theNormalBinding   = (SoNormalBinding *)    ( sep->getChild(2));
+  SoIndexedFaceSet  *theFaceSet         = (SoIndexedFaceSet *)   ( sep->getChild(3));
+
+  const int NPHI=24, NPOINTS=2*(2*NPHI+2), NFACES=4*NPHI+2, NINDICES = NFACES*5;
+  float points[NPOINTS][3], normals[NFACES][3];
+#ifdef INVENTOR2_0
+  static long     indices[NINDICES];
+#else
+  static int32_t  indices[NINDICES];
+#endif
+  static int init=0;
+  double phi, pp, DeltaPhi;
+
+  // Indices need to be generated once! This is here to keep it close to the point
+  // generation, since otherwise it will be confusing.
+
+  int i;
+  if (!init) {
+    init = 1;
+    // Outer face
+    for (i = 0; i< NPHI; i++) {
+      // 0 1 3 2;
+      indices[5*i+0] =  2*i+0;
+      indices[5*i+1] =  2*i+1;
+      indices[5*i+2] =  2*i+3;
+      indices[5*i+3] =  2*i+2;
+      indices[5*i+4] = SO_END_FACE_INDEX;
+    }
+    // the inner face
+    for (i=0;i<NPHI;i++) {
+      indices[5*1*NPHI + 5*i+0] = 2*NPHI+2 + 2*i+0;  
+      indices[5*1*NPHI + 5*i+1] = 2*NPHI+2 + 2*i+1;
+      indices[5*1*NPHI + 5*i+2] = 2*NPHI+2 + 2*i+3;
+      indices[5*1*NPHI + 5*i+3] = 2*NPHI+2 + 2*i+2;
+      indices[5*1*NPHI + 5*i+4] = SO_END_FACE_INDEX;
+    }
+    // the top side
+    for (i=0;i<NPHI;i++) {
+      indices[5*2*NPHI + 5*i+0] = 2*i+0;
+      indices[5*2*NPHI + 5*i+1] = 2*i+2;
+      indices[5*2*NPHI + 5*i+2] = NPOINTS - (2*i+4);
+      indices[5*2*NPHI + 5*i+3] = NPOINTS - (2*i+2);
+      indices[5*2*NPHI + 5*i+4] = SO_END_FACE_INDEX;
+    }
+    // the bottom side
+    for (i=0;i<NPHI;i++) {
+      indices[5*3*NPHI + 5*i+0] = 2*i+1;
+      indices[5*3*NPHI + 5*i+1] = NPOINTS - (2*i+1);
+      indices[5*3*NPHI + 5*i+2] = NPOINTS - (2*i+3);
+      indices[5*3*NPHI + 5*i+3] = 2*i+3;
+      indices[5*3*NPHI + 5*i+4] = SO_END_FACE_INDEX;
+    }
+    // the odd side
+    indices[5*4*NPHI +0] = 2*NPHI;
+    indices[5*4*NPHI +1] = 2*NPHI+1;
+    indices[5*4*NPHI +2] = 2*NPHI+3;
+    indices[5*4*NPHI +3] = 2*NPHI+2;
+    indices[5*4*NPHI +4] = SO_END_FACE_INDEX;
+    // aother odd side
+    indices[5*4*NPHI +5 +0] = 0;
+    indices[5*4*NPHI +5 +1] = NPOINTS-2;
+    indices[5*4*NPHI +5 +2] = NPOINTS-1;
+    indices[5*4*NPHI +5 +3] = 1;
+    indices[5*4*NPHI +5 +4] = SO_END_FACE_INDEX;
+  }
+  // Points need to be generated each time:
+  // The outer surface
+  DeltaPhi = fDPhi.getValue()/NPHI, phi = fSPhi.getValue();
+  float  t,st,ct;
+  t = FATAN((fRmax2.getValue()-fRmax1.getValue())/(2*fDz.getValue()));
+  st = FSIN(t);
+  ct = FCOS(t);
+  for (i = 0; i<=NPHI; i++) {
+    points[2*i+0][0] = fRmax2.getValue()*FCOS(phi); 
+    points[2*i+0][1] = fRmax2.getValue()*FSIN(phi); 
+    points[2*i+0][2] = +fDz.getValue();
+    points[2*i+1][0] = fRmax1.getValue()*FCOS(phi); 
+    points[2*i+1][1] = fRmax1.getValue()*FSIN(phi); 
+    points[2*i+1][2] = -fDz.getValue();
+    pp = phi+DeltaPhi/2.0;
+    if (i!=NPHI) {
+      normals[i][0] = ct * FCOS(pp); 
+      normals[i][1] = ct * FSIN(pp); 
+      normals[i][2] = -st;
+    }
+    phi+=DeltaPhi;
+  }
+  // The inner surface
+  phi = fSPhi.getValue() + fDPhi.getValue();
+  t = FATAN((fRmin2.getValue()-fRmin1.getValue())/(2*fDz.getValue()));
+  st = FSIN(t);
+  ct = FCOS(t);
+  for (i = 0; i<=NPHI; i++) {
+    points[2*NPHI+2+2*i+0][0] = fRmin2.getValue()*FCOS(phi); 
+    points[2*NPHI+2+2*i+0][1] = fRmin2.getValue()*FSIN(phi); 
+    points[2*NPHI+2+2*i+0][2] = +fDz.getValue();
+    points[2*NPHI+2+2*i+1][0] = fRmin1.getValue()*FCOS(phi); 
+    points[2*NPHI+2+2*i+1][1] = fRmin1.getValue()*FSIN(phi); 
+    points[2*NPHI+2+2*i+1][2] = -fDz.getValue();
+    pp = phi-DeltaPhi/2.0;
+    if (i!=NPHI) {
+      normals[NPHI+i][0] = -ct*FCOS(pp); 
+      normals[NPHI+i][1] = -ct*FSIN(pp); 
+      normals[NPHI+i][2] = st;
+    }
+    phi-=DeltaPhi;
+  }
+  // The top side
+  for (i=0;i<NPHI;i++) {
+    normals[2*NPHI+i][0]=normals[2*NPHI+i][1]=0; 
+    normals[2*NPHI+i][2]=  1.0;
+  } 
+  // The bottom side
+  for (i=0;i<NPHI;i++) {
+    normals[3*NPHI+i][0]=normals[3*NPHI+i][1]=0; 
+    normals[3*NPHI+i][2]= -1.0;
+  } 
+  // The odd side
+  phi = fSPhi.getValue(); 
+  normals[4*NPHI+0][0]=  FSIN(phi); 
+  normals[4*NPHI+0][1]= -FCOS(phi); 
+  normals[4*NPHI+0][2]= 0;
+
+  // Another odd side
+  phi = fSPhi.getValue()+fDPhi.getValue(); 
+  normals[4*NPHI+1][0]= -FSIN(phi); 
+  normals[4*NPHI+1][1]= +FCOS(phi); 
+  normals[4*NPHI+1][2]=0;
+
+  for (int np=0;np<NPOINTS;np++) theCoordinates->point.set1Value(np,points[np][0],points[np][1],points[np][2]);
+  theFaceSet->coordIndex.setValues(0,NINDICES,indices);
+  if (smoothDraw.getValue()) {
+    //    This Line is replaced by the next one because of an apparent Bug in Inventor (mem. leak).
+    //    theNormals->vector.deleteValues(0);
+    for (int nf=0;nf<NFACES;nf++) theNormals->vector.set1Value(nf,normals[nf][0],normals[nf][1],normals[nf][2]);
+    theNormalBinding->value=SoNormalBinding::PER_FACE;
+  }
+  else {
+    for (int nf=0;nf<NFACES;nf++) theNormals->vector.set1Value(nf,normals[nf][0],normals[nf][1],normals[nf][2]);
+    theNormalBinding->value=SoNormalBinding::PER_FACE;
+  }
+}
+
+// generateChildren
+void SoCons::generateChildren() {
+
+  // This routines creates one SoSeparator, one SoCoordinate3, and
+  // one SoLineSet, and puts it in the child list.  This is done only
+  // once, whereas redrawing the position of the coordinates occurs each
+  // time an update is necessary, in the updateChildren routine. 
+
+  assert(children->getLength() ==0);
+  SoSeparator      *sep              = new SoSeparator(); 
+  SoCoordinate3    *theCoordinates   = new SoCoordinate3();
+  SoNormal         *theNormals       = new SoNormal(); 
+  SoNormalBinding  *theNormalBinding = new SoNormalBinding();
+  SoIndexedFaceSet *theFaceSet       = new SoIndexedFaceSet();
+  // 
+  // This line costs some in render quality! but gives speed.
+  // 
+  sep->addChild(theCoordinates);
+  sep->addChild(theNormals);
+  sep->addChild(theNormalBinding);
+  sep->addChild(theFaceSet);
+  children->append(sep);
+}
+
+// generateAlternateRep
+void SoCons::generateAlternateRep() {
+
+  // This routine sets the alternate representation to the child
+  // list of this mode.  
+
+  if (children->getLength() == 0) generateChildren();
+  updateChildren();
+  alternateRep.setValue((SoSeparator *)  ( *children)[0]);
+}
+
+// clearAlternateRep
+void SoCons::clearAlternateRep() {
+  alternateRep.setValue(NULL);
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/SoCounterAction.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/SoCounterAction.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/SoCounterAction.cc	(revision 529)
@@ -0,0 +1,105 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+/*----------------------------HEPVis----------------------------------------*/
+/*                                                                          */
+/* Node:             SoCounterAction                                        */
+/* Author:           Guy Barrand                                            */
+/*                                                                          */
+/*--------------------------------------------------------------------------*/
+
+// this :
+#include <HEPVis/actions/SoCounterAction.h>
+
+#include <Inventor/nodes/SoNode.h>
+#include <Inventor/nodes/SoGroup.h>
+#include <Inventor/nodes/SoSwitch.h>
+#include <Inventor/nodekits/SoBaseKit.h>
+#include <Inventor/elements/SoSwitchElement.h>
+
+SO_ACTION_SOURCE(SoCounterAction)
+
+void SoCounterAction::initClass(void){
+  SO_ACTION_INIT_CLASS(SoCounterAction,SoAction);
+
+  SO_ENABLE(SoCounterAction,SoSwitchElement);
+
+  SO_ACTION_ADD_METHOD(SoNode,SoCounterAction::actionMethod);
+}
+SoCounterAction::SoCounterAction()
+:fCount(0),fLookFor(NODE),fCheckDerived(TRUE){
+  SO_ACTION_CONSTRUCTOR(SoCounterAction);
+}
+SoCounterAction::~SoCounterAction(){}
+void SoCounterAction::beginTraversal(SoNode* node){
+  fCount = 0;
+  SoAction::beginTraversal(node);
+}
+void SoCounterAction::actionMethod(SoAction* aThis,SoNode* aNode) {
+  //printf("debug : begin : %s %s\n",aNode->getName().getString(),
+    //aNode->getTypeId().getName().getString());
+  SoCounterAction* This = (SoCounterAction*)aThis;
+  if(This->fLookFor==NODE) {
+    This->fCount++;
+  } else if(This->fLookFor==TYPE) {
+    if(This->fCheckDerived==TRUE) {
+      if(aNode->getTypeId().isDerivedFrom(This->fType)) This->fCount++;
+    } else {
+      if(aNode->getTypeId()==This->fType) This->fCount++;
+    }
+  } else if(This->fLookFor==NAME) {
+    if(This->fName==aNode->getName()) This->fCount++;
+  }
+  if(aNode->isOfType(SoSwitch::getClassTypeId())) {
+    SoSwitch* sw = (SoSwitch*)aNode;
+    SbBool flag = sw->whichChild.enableNotify(FALSE);
+    int old = sw->whichChild.getValue();
+    sw->whichChild.setValue(SO_SWITCH_ALL);
+    aNode->doAction(aThis);
+    sw->whichChild.setValue(old);
+    sw->whichChild.enableNotify(flag);
+  } else if(aNode->isOfType(SoGroup::getClassTypeId())) {
+    aNode->doAction(aThis);
+  } else if(aNode->isOfType(SoBaseKit::getClassTypeId())) {
+    aNode->doAction(aThis);
+  }
+}
+void SoCounterAction::setLookFor(LookFor aLookFor) {
+  fLookFor = aLookFor;
+}
+void SoCounterAction::setType(const SoType aType,SbBool aCheckDerived) {
+  fType = aType;
+  fCheckDerived = aCheckDerived;
+}
+void SoCounterAction::setName(const SbName aName){
+  fName = aName;
+}
+int SoCounterAction::getCount() const {
+  return fCount;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/SoDetectorTreeKit.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/SoDetectorTreeKit.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/SoDetectorTreeKit.cc	(revision 529)
@@ -0,0 +1,243 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+//
+// $Id: SoDetectorTreeKit.cc,v 1.13 2006/06/29 21:22:51 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+/*-----------------------------HEPVis----------------------------------------*/
+/*                                                                           */
+/* Node:             SoDetectorTreeKit                                       */
+/* Description:      Represents a single sided silicon strip detector        */
+/* Author:           Joe Boudreau Nov 11 1996                                */
+/*                                                                           */
+/*---------------------------------------------------------------------------*/
+
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+// this :
+#include "HEPVis/nodekits/SoDetectorTreeKit.h"
+
+#include <Inventor/SoPickedPoint.h>
+#include <Inventor/nodes/SoSeparator.h>
+#include <Inventor/nodes/SoPickStyle.h>
+#include <Inventor/nodes/SoDrawStyle.h>
+#include <Inventor/nodes/SoSwitch.h>
+#include <Inventor/nodes/SoMaterial.h>
+#include <Inventor/nodes/SoUnits.h>
+#include <Inventor/nodes/SoTransform.h>
+#include <Inventor/nodes/SoEventCallback.h>
+#include <Inventor/nodekits/SoSeparatorKit.h>
+#include <Inventor/nodekits/SoShapeKit.h>
+#include <Inventor/nodekits/SoAppearanceKit.h>
+#include <Inventor/nodekits/SoNodeKitListPart.h>
+#include <Inventor/nodekits/SoBaseKit.h>
+#include <Inventor/nodes/SoTexture2Transform.h>
+#include <Inventor/events/SoMouseButtonEvent.h>
+#include <Inventor/actions/SoHandleEventAction.h>
+
+#include <HEPVis/actions/SoAlternateRepAction.h>
+
+#include <cmath>
+
+// This statement is required
+SO_KIT_SOURCE(SoDetectorTreeKit)
+ 
+// initClass
+void SoDetectorTreeKit::initClass(){
+  SO_KIT_INIT_CLASS(SoDetectorTreeKit,SoBaseKit,"BaseKit");
+}
+
+// Constructor
+SoDetectorTreeKit::SoDetectorTreeKit() {
+  SO_KIT_CONSTRUCTOR(SoDetectorTreeKit);
+
+  SO_NODE_ADD_FIELD(alternateRep, (NULL));
+
+  SO_KIT_ADD_CATALOG_ENTRY     (     topSeparator,         SoSeparator, FALSE,          this,\0, FALSE);
+  SO_KIT_ADD_CATALOG_ENTRY     (        pickStyle,         SoSeparator, TRUE ,  topSeparator,\0, TRUE);
+  SO_KIT_ADD_CATALOG_ENTRY     (       appearance,     SoAppearanceKit, TRUE,  topSeparator ,\0, TRUE);
+  SO_KIT_ADD_CATALOG_ENTRY     (            units,             SoUnits, TRUE,  topSeparator ,\0, TRUE);
+  SO_KIT_ADD_CATALOG_ENTRY     (        transform,         SoTransform, TRUE ,  topSeparator,\0, TRUE);
+  SO_KIT_ADD_CATALOG_ENTRY     (texture2Transform, SoTexture2Transform, TRUE,  topSeparator ,\0, TRUE);
+  SO_KIT_ADD_CATALOG_ENTRY     (        childList,            SoSwitch, FALSE,  topSeparator,\0, FALSE);
+  SO_KIT_ADD_CATALOG_ENTRY     ( previewSeparator,         SoSeparator, FALSE,     childList,\0, TRUE);
+  SO_KIT_ADD_CATALOG_ENTRY     (    fullSeparator,         SoSeparator, FALSE,     childList,\0, TRUE);
+
+  SO_KIT_INIT_INSTANCE();
+  createInitialTree();
+}
+
+// Destructor
+SoDetectorTreeKit::~SoDetectorTreeKit() {
+}
+
+
+SbBool SoDetectorTreeKit::affectsState() const {
+  return FALSE;
+}
+
+void SoDetectorTreeKit::createInitialTree() {
+
+  SoEventCallback *myCallback = new SoEventCallback();
+  myCallback->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
+                               SoDetectorTreeKit::expand,
+                               this);
+  myCallback->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
+                               SoDetectorTreeKit::contract  ,
+                               this);
+  if(setPart("callbackList[0]",myCallback)==FALSE) myCallback->unref(); 
+
+  SoSwitch *theChildList = (SoSwitch *) childList.getValue();
+  theChildList->whichChild.setValue(0);
+}
+
+void SoDetectorTreeKit::expand(void *userData, SoEventCallback *eventCB){
+
+  // Was the event previously handled? Is it the right kind?
+
+  if (eventCB->isHandled()) return;
+  const SoMouseButtonEvent *event= (SoMouseButtonEvent *) eventCB->getEvent();
+  if (!SoMouseButtonEvent::isButtonPressEvent(event,SoMouseButtonEvent::BUTTON1)) return;
+  if (!event->wasCtrlDown()) return;
+  if (event->wasShiftDown()) return;
+
+  // Which Detector is this being called for?
+  SoDetectorTreeKit* This = (SoDetectorTreeKit *) userData;
+
+  // Find out whether that's the one that has been picked.  
+  // "This' is the lowest detector tree kit in the hierarchy.
+  SoHandleEventAction *handleEventAction = eventCB->getAction();
+  const SoPickedPoint *pickedPoint = handleEventAction->getPickedPoint();
+  if (!pickedPoint) return;
+
+  SoFullPath* path = (SoFullPath*)pickedPoint->getPath();
+  SoNode *ancestorNode=NULL;
+  for (int i=0;i<path->getLength();i++) {
+    ancestorNode  = path->getNodeFromTail(i);
+    if (ancestorNode->isOfType(SoDetectorTreeKit::getClassTypeId()))  break;
+  }
+  if (This!=ancestorNode) return;
+  //  if (!ancestorNode->isOfType(SoDetectorTreeKit::getClassTypeId())) return;
+ 
+  // Deactivate the Preview
+  This->setPreview(FALSE);
+  eventCB->setHandled();
+     
+}
+
+void SoDetectorTreeKit::contract(void *userData, SoEventCallback *eventCB){
+
+  // Was the event previously handled? Is it the right kind?
+  if (eventCB->isHandled()) return;
+  const SoMouseButtonEvent *event= (SoMouseButtonEvent *) eventCB->getEvent();
+  if (!SoMouseButtonEvent::isButtonPressEvent(event,SoMouseButtonEvent::BUTTON1)) return;
+  if (event->wasCtrlDown()) return;
+  if (!event->wasShiftDown()) return;
+
+  // Which Detector is this being called for?
+  SoDetectorTreeKit* This = (SoDetectorTreeKit *) userData;
+
+  // Find out whether that's the one that has been picked
+  SoHandleEventAction *handleEventAction = eventCB->getAction();
+  const SoPickedPoint *pickedPoint = handleEventAction->getPickedPoint();
+  if (!pickedPoint) return;
+ 
+  // Find out whether that's the one that has been picked.  
+  // "This" is the lowest detector tree kit in the hierarchy.
+  SoFullPath* path = (SoFullPath*)pickedPoint->getPath();
+  SoNode *ancestorNode=NULL;
+  SbBool firstTreeFound=FALSE;
+  for (int i=0;i<path->getLength();i++) {
+    ancestorNode  = path->getNodeFromTail(i);
+    if (ancestorNode->isOfType(SoDetectorTreeKit::getClassTypeId())) {
+      if (!firstTreeFound) {
+        if (This!=ancestorNode) return;
+        firstTreeFound=TRUE;
+      }
+      SoDetectorTreeKit *That = (SoDetectorTreeKit *) ancestorNode;
+      if (!That->getPreview()) {
+        That->setPreview(TRUE);
+        eventCB->setHandled();
+        return;
+      }
+    }
+  }
+}
+
+void SoDetectorTreeKit::setPreview(SbBool Flag) {
+  SoSwitch *theChildList = (SoSwitch *) childList.getValue();
+  if (Flag) {
+    theChildList->whichChild.setValue(0);
+  }
+  else {
+    theChildList->whichChild.setValue(1);
+  }
+}
+
+SbBool SoDetectorTreeKit::getPreview() const {
+  SoSwitch *theChildList = (SoSwitch *) childList.getValue();
+  if (theChildList->whichChild.getValue()==0) return TRUE;
+  return FALSE;
+}
+
+
+void SoDetectorTreeKit::setPreviewAndFull() {
+  SoSwitch *theChildList = (SoSwitch *) childList.getValue();
+  theChildList->whichChild.setValue(SO_SWITCH_ALL);
+}
+
+SoSeparator *SoDetectorTreeKit::getPreviewSeparator() const {
+  return (SoSeparator *) previewSeparator.getValue();
+}
+
+SoSeparator *SoDetectorTreeKit::getFullSeparator() const {
+  return (SoSeparator *) fullSeparator.getValue();
+}
+
+
+
+
+// generateAlternateRep
+void SoDetectorTreeKit::generateAlternateRep() {
+  alternateRep.setValue(topSeparator.getValue());
+}
+
+void SoDetectorTreeKit::clearAlternateRep() {
+  alternateRep.setValue(NULL);
+}
+//////////////////////////////////////////////////////////////////////////////
+void SoDetectorTreeKit::doAction(
+ SoAction* aAction
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  SO_ALTERNATEREP_DO_ACTION(aAction)
+  SoBaseKit::doAction(aAction);
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/SoGL2PSAction.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/SoGL2PSAction.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/SoGL2PSAction.cc	(revision 529)
@@ -0,0 +1,228 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+/*----------------------------HEPVis----------------------------------------*/
+/*                                                                          */
+/* Node:             SoGL2PSAction                                          */
+/* Author:           Guy Barrand                                            */
+/*                                                                          */
+/*--------------------------------------------------------------------------*/
+
+// this :
+#include <HEPVis/actions/SoGL2PSAction.h>
+
+// Inventor :
+#include <Inventor/elements/SoViewportRegionElement.h>
+#include <Inventor/errors/SoDebugError.h>
+
+#include "Geant4_gl2ps.h"
+
+#include <stdio.h>
+
+SO_ACTION_SOURCE(SoGL2PSAction)
+//////////////////////////////////////////////////////////////////////////////
+void SoGL2PSAction::initClass(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  SO_ACTION_INIT_CLASS(SoGL2PSAction,SoGLRenderAction);
+}
+//////////////////////////////////////////////////////////////////////////////
+SoGL2PSAction::SoGL2PSAction(
+ const SbViewportRegion& aViewPortRegion
+)
+:SoGLRenderAction(aViewPortRegion)
+,fFileName("out.ps")
+,fFile(0)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  SO_ACTION_CONSTRUCTOR(SoGL2PSAction);
+}
+//////////////////////////////////////////////////////////////////////////////
+void SoGL2PSAction::setFileName(
+ const char* aFileName
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  fFileName = aFileName;
+}
+//////////////////////////////////////////////////////////////////////////////
+void SoGL2PSAction::enableFileWriting(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  fFile = ::fopen(fFileName.getString(),"w");
+  if(!fFile) {
+    SoDebugError::post("SoGL2PSAction::enableFileWriting",
+                       "Cannot open file %s",fFileName.getString());
+    return;
+  }
+#ifdef __COIN__
+#else //SGI
+  const SbViewportRegion& vpr = getViewportRegion();
+  SoViewportRegionElement::set(getState(),vpr);
+  gl2psBegin();
+#endif
+}
+//////////////////////////////////////////////////////////////////////////////
+void SoGL2PSAction::disableFileWriting(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+#ifdef __COIN__
+#else //SGI
+  gl2psEndPage();        
+#endif
+  ::fclose(fFile);
+  fFile = 0;
+}
+//////////////////////////////////////////////////////////////////////////////
+SbBool SoGL2PSAction::fileWritingEnabled(
+) const
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  return (fFile?TRUE:FALSE);
+}
+//////////////////////////////////////////////////////////////////////////////
+SbBool SoGL2PSAction::addBitmap(
+ int aWidth
+,int aHeight
+,float aXorig
+,float aYorig
+,float aXmove
+,float aYmove
+)
+/////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(!fFile) return FALSE;
+  GLboolean valid;
+  glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID,&valid);
+  if(valid==GL_FALSE) return FALSE;
+  float pos[4];
+  glGetFloatv(GL_CURRENT_RASTER_POSITION,pos);
+  int xoff = -(int)(aXmove + aXorig);
+  int yoff = -(int)(aYmove + aYorig);
+  int x = (int)(pos[0] + xoff);
+  int y = (int)(pos[1] + yoff);
+  // Should clip against viewport area :
+  GLint vp[4];
+  glGetIntegerv(GL_VIEWPORT,vp);
+  GLsizei w = aWidth;
+  GLsizei h = aHeight;
+  if(x+w>(vp[0]+vp[2])) w = vp[0]+vp[2]-x;
+  if(y+h>(vp[1]+vp[3])) h = vp[1]+vp[3]-y;
+  int s = 3 * w * h;
+  if(s<=0) return FALSE;
+  float* image = (float*)::malloc(s * sizeof(float));
+  if(!image) return FALSE;
+  glReadPixels(x,y,w,h,GL_RGB,GL_FLOAT,image);
+  GLint status = gl2psDrawPixels(w,h,xoff,yoff,GL_RGB,GL_FLOAT,image);
+  ::free(image);
+  return (status!=GL2PS_SUCCESS ? FALSE : TRUE);
+}
+//////////////////////////////////////////////////////////////////////////////
+void SoGL2PSAction::beginViewport(
+)
+/////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(!fFile) return;
+  GLint vp[4];
+  glGetIntegerv(GL_VIEWPORT,vp);
+  gl2psBeginViewport(vp);
+}
+//////////////////////////////////////////////////////////////////////////////
+void SoGL2PSAction::endViewport(
+)
+/////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(!fFile) return;
+  gl2psEndViewport();
+}
+//////////////////////////////////////////////////////////////////////////////
+void SoGL2PSAction::beginTraversal(
+ SoNode* aNode
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(fFile) {
+#ifdef __COIN__
+    const SbViewportRegion& vpr = getViewportRegion();
+    SoViewportRegionElement::set(getState(),vpr);
+    gl2psBegin();
+    traverse(aNode);
+    gl2psEndPage();        
+#else //SGI
+    SoGLRenderAction::beginTraversal(aNode);
+#endif
+  } else {
+    SoGLRenderAction::beginTraversal(aNode);
+  }
+}
+//////////////////////////////////////////////////////////////////////////////
+void SoGL2PSAction::gl2psBegin(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(!fFile) return;
+  int options = GL2PS_OCCLUSION_CULL | 
+     GL2PS_BEST_ROOT | GL2PS_SILENT | GL2PS_DRAW_BACKGROUND;
+  int sort = GL2PS_BSP_SORT;
+  //int sort = GL2PS_SIMPLE_SORT;
+    
+  const SbViewportRegion& vpr = getViewportRegion();
+  SoViewportRegionElement::set(getState(),vpr);
+ 
+  const SbVec2s& win = vpr.getWindowSize();
+  GLint vp[4];
+  vp[0] = 0;
+  vp[1] = 0;
+  vp[2] = win[0];
+  vp[3] = win[1];
+
+  int bufsize = 0;
+  gl2psBeginPage("title","HEPVis::SoGL2PSAction", 
+                 vp,
+                 GL2PS_EPS, 
+                 sort, 
+                 options, 
+                 GL_RGBA,0, NULL,0,0,0,
+                 bufsize, 
+                 fFile,fFileName.getString());    
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/SoImageWriter.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/SoImageWriter.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/SoImageWriter.cc	(revision 529)
@@ -0,0 +1,346 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+/*----------------------------HEPVis----------------------------------------*/
+/*                                                                          */
+/* Node:             SoImageWriter                                          */
+/* Author:           Guy Barrand                                            */
+/*                                                                          */
+/*--------------------------------------------------------------------------*/
+
+// this :
+#include <HEPVis/nodes/SoImageWriter.h>
+
+#include <Inventor/errors/SoDebugError.h>
+#include <Inventor/elements/SoViewportRegionElement.h>
+#include <Inventor/actions/SoGLRenderAction.h>
+
+#include <HEPVis/SbGL.h>
+#include <HEPVis/SbPainterPS.h>
+//#include <HEPVis/SbGIF.h>
+
+#include <stdlib.h>
+
+typedef struct {
+  unsigned char red;
+  unsigned char green;
+  unsigned char blue;
+} Pixel;
+typedef unsigned char Uchar;
+
+//static void getImagePixels(int,int,float*,int&,
+//                         Uchar*&,Uchar*&,Uchar*&,Uchar*&);
+
+static int sWidth = 0;
+static int sHeight = 0;
+static float* sImage = 0;
+static int getRGB(unsigned int,unsigned int,double&,double&,double&);
+
+SO_NODE_SOURCE(SoImageWriter)
+//////////////////////////////////////////////////////////////////////////////
+void SoImageWriter::initClass (
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  SO_NODE_INIT_CLASS(SoImageWriter,SoNode,"Node");
+}
+//////////////////////////////////////////////////////////////////////////////
+SoImageWriter::SoImageWriter(
+)
+:fEnabled(FALSE)
+,fStatus(FALSE)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  SO_NODE_CONSTRUCTOR(SoImageWriter);
+  //SO_NODE_ADD_FIELD(format,(POST_SCRIPT));
+  SO_NODE_ADD_FIELD(fileName,("out.ps"));
+  
+  //SO_NODE_DEFINE_ENUM_VALUE(Format,POST_SCRIPT);
+  //SO_NODE_DEFINE_ENUM_VALUE(Format,GIF);
+  
+  //SO_NODE_SET_SF_ENUM_TYPE(format,Format);
+}
+//////////////////////////////////////////////////////////////////////////////
+SoImageWriter::~SoImageWriter (
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+}
+//////////////////////////////////////////////////////////////////////////////
+void SoImageWriter::enable(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  fEnabled = TRUE;
+}
+//////////////////////////////////////////////////////////////////////////////
+void SoImageWriter::disable(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  fEnabled = FALSE;
+}
+//////////////////////////////////////////////////////////////////////////////
+SbBool SoImageWriter::getStatus(
+) const
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  return fStatus;
+}
+//////////////////////////////////////////////////////////////////////////////
+void SoImageWriter::GLRender(
+ SoGLRenderAction* aAction
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  fStatus = FALSE;
+  //printf("debug : SoImageWriter::GLRender : enabled : %d\n",fEnabled);
+  if(!fEnabled) return;
+  SbViewportRegion vpr = SoViewportRegionElement::get(aAction->getState());
+  const SbVec2s& win = vpr.getWindowSize();
+  int w = win[0];
+  int h = win[1];
+  if((w*h)<=0) {
+    SoDebugError::postInfo("SoImageWriter::GLRender","null area window !");
+    return;
+  }
+
+  int x = 0;
+  int y = 0;
+  int s = 3 * w * h;
+  float* image = new float[s];
+  if(!image) return;
+
+  //printf("debug : SoImageWriter::GLRender : %d %d %d %d\n",x,y,w,h);
+
+  //glReadPixels(x,y,w,h,GL_RGB,GL_UNSIGNED_BYTE,image); Don't work !
+  glReadPixels(x,y,w,h,GL_RGB,GL_FLOAT,image);
+
+  //Format fm = (Format)format.getValue();
+  //if(fm==GIF) {  
+/*
+    FILE* file = fopen(fileName.getValue().getString(),"wb");
+    if(!file) {
+      SoDebugError::postInfo("SoImageWriter::GLRender",
+        "can't open file \"%s\".",fileName.getValue().getString());
+    } else {
+      int coln;
+      Uchar* rs;
+      Uchar* gs;
+      Uchar* bs;
+      Uchar* data;
+      getImagePixels(w,h,image,coln,rs,gs,bs,data);
+      
+      SbGIF::putBytesInStream(file,data,w,h,coln,rs,gs,bs);
+      
+      delete [] data;
+
+      if(rs) free(rs);
+      if(gs) free(gs);
+      if(bs) free(bs);
+
+      fclose(file);
+
+      fStatus = TRUE;
+    }
+  } else {
+*/
+
+    SbPainterPS painterPS;
+    painterPS.openFileForWriting(fileName.getValue().getString());
+    if(!painterPS.getStream()) {
+      SoDebugError::postInfo("SoImageWriter::GLRender",
+        "can't open file \"%s\".",fileName.getValue().getString());
+    } else {
+      painterPS.setWindowSize(w,h);
+      //painterPS.setBitsPerPixel(8);
+      painterPS.setBitsPerPixel(4);
+      painterPS.beginTraversal();
+      painterPS.clearColorBuffer(1.,1.,1.);
+
+      sWidth = w;
+      sHeight = h;
+      sImage = image;
+      painterPS.putImageInStream((unsigned int)w,(unsigned int)h,getRGB);
+      
+      painterPS.endTraversal();
+      
+      painterPS.closeStream();
+      
+      fStatus = TRUE;
+    }
+  //}
+  delete [] image;
+
+}
+/*
+//////////////////////////////////////////////////////////////////////////////
+void getImagePixels (
+ int aWidth
+,int aHeight
+,float* aImage
+,int& aColorn
+,Uchar*& aReds
+,Uchar*& aGreens
+,Uchar*& aBlues
+,Uchar*& aData
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  aColorn = 0;
+  aReds = 0;
+  aGreens = 0;
+  aBlues = 0;
+  aData = 0;
+  if( (aWidth * aHeight) <=0) return;
+  int size = 256;
+  Uchar* rs = (Uchar*)malloc(size * sizeof(Uchar));
+  Uchar* gs = (Uchar*)malloc(size * sizeof(Uchar));
+  Uchar* bs = (Uchar*)malloc(size * sizeof(Uchar));
+  Uchar* data = new Uchar[aWidth * aHeight];
+  if( !rs || !gs || !bs || !data ) {
+    if(rs) free(rs);
+    if(gs) free(gs);
+    if(bs) free(bs);
+    delete [] data;
+    return;
+  }
+  int pixeln = 0;
+  int row,col;
+  Uchar red,green,blue;
+  Uchar ored = 0,ogreen = 0,oblue = 0;
+  float* pimag = aImage;
+  Uchar* pdata = 0;
+  Uchar index = 0;
+  int status = 0;
+  for(row=0;row<aHeight;row++) {
+    pdata = data + (aHeight - 1 - row) * aWidth;
+    for(col=0;col<aWidth;col++){ 
+      red   = (Uchar)(255 * (*pimag));pimag++;
+      green = (Uchar)(255 * (*pimag));pimag++;
+      blue  = (Uchar)(255 * (*pimag));pimag++;
+      //printf("debug : %d %d : %d %d %d\n",row,col,red,green,blue);
+      if( (pixeln==0) || (red!=ored) || (green!=ogreen) || (blue!=oblue) ){
+        // Search exact color :
+        int found = 0;
+        for(int count=0;count<pixeln;count++){
+          if( (red==rs[count]) && (green==gs[count]) && (blue==bs[count]) ){
+            found = 1;
+            index = count;
+            break;
+          }
+        }
+        if(found==0){
+          if(pixeln>=256) {
+            // We can't store more than 256 on an Uchar.
+            // Search closest color :
+            int dr,dg,db;
+            int PRECISION = 20;
+            int closest = 0;
+            for(int count=0;count<pixeln;count++){
+              dr = red   - rs[count];dr = dr<0 ? -dr : dr;
+              dg = green - gs[count];dg = dg<0 ? -dg : dg;
+              db = blue  - bs[count];db = db<0 ? -db : db;
+              if( (dr<=PRECISION) && (dg<=PRECISION) && (db<=PRECISION) ){
+                closest = 1;
+                index = count;
+                break;
+              }
+            }
+            if(closest==0) {
+              index = 0;
+              status  = 1;
+            }
+          } else {
+            if(pixeln>=size){
+              size += 256;
+              rs = (Uchar*)realloc(rs,size * sizeof(Uchar));
+              gs = (Uchar*)realloc(gs,size * sizeof(Uchar));
+              bs = (Uchar*)realloc(bs,size * sizeof(Uchar));
+              if( !rs || !gs || !bs ) {
+                if(rs) free(rs);
+                if(gs) free(gs);
+                if(bs) free(bs);
+                delete [] data;
+                return;
+              } 
+            } 
+            //printf("debug : SoImageWriter pixeln %d : %d %d %d\n",
+            //   pixeln,red,green,blue);
+            rs[pixeln] = red;
+            gs[pixeln] = green;
+            bs[pixeln] = blue;
+            index = pixeln;
+            pixeln++;
+          }
+        }
+      }
+      *pdata = index;
+      pdata++;
+      ored = red;
+      ogreen = green;
+      oblue = blue;
+    }
+  }
+  if(status==1) 
+    printf("SoImageWriter : more than 256 colors in picture ; some colors approximated.\n");
+  aColorn = pixeln;
+  aReds = rs;
+  aGreens = gs;
+  aBlues = bs;
+  aData = data;
+}
+*/
+//////////////////////////////////////////////////////////////////////////////
+int getRGB(
+ unsigned int aX
+,unsigned int aY
+,double& aRed
+,double& aGreen
+,double& aBlue
+)
+//////////////////////////////////////////////////////////////////////////////
+// OpenGL image is from down to up.
+// PS image is up to down.
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  float* pimag = sImage + 3 * (sWidth * (sHeight - 1 - aY) + aX);
+  aRed   = *pimag;pimag++;
+  aGreen = *pimag;pimag++;
+  aBlue  = *pimag;pimag++;
+  return 1;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/SoMarkerSet.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/SoMarkerSet.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/SoMarkerSet.cc	(revision 529)
@@ -0,0 +1,791 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+/*----------------------------HEPVis----------------------------------------*/
+/*                                                                          */
+/* Node:             SoMarkerSet                                            */
+/* Author:           Guy Barrand                                            */
+/*                                                                          */
+/*--------------------------------------------------------------------------*/
+
+// this :
+#include <HEPVis/nodes/SoMarkerSet.h>
+
+#include <Inventor/errors/SoDebugError.h>
+#include <Inventor/misc/SoState.h>
+#include <Inventor/actions/SoGLRenderAction.h>
+#include <Inventor/nodes/SoPointSet.h>
+
+#include <Inventor/elements/SoCoordinateElement.h>
+#include <Inventor/elements/SoCacheElement.h>
+#include <Inventor/elements/SoLazyElement.h>
+
+#include <HEPVis/SbGL.h>
+#include <HEPVis/actions/SoGL2PSAction.h>
+
+static void drawMarker(SoAction*,int);
+static GLubyte* getBitmap(int,int,char []); 
+
+/* 
+  "  x  "
+  "  x  "
+  "xxxxx"
+  "  x  "
+  "  x  "
+
+  Should produce bitmap :
+  0x20,0x20,0xf8,0x20,0x20
+
+  The rows will be rendered down to top ; first row at bottom, last at top.
+  In the below, '-' means that glBitmap will move the pointer to next byte.
+
+  32103210 32103210 32103210 32103210 32103210
+  ..1..--- ..1..--- 11111--- ..1..--- ..1..---
+
+  0x20     0x20     0xf8     0x20     0x20
+*/
+
+///////////////////////////////////////////////////////////////
+/// 5 5 ///////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////
+static char plus_5_5[] = {
+  "  x  "
+  "  x  "
+  "xxxxx"
+  "  x  "
+  "  x  "
+};
+static char asterisk_5_5[] = {
+  "x x x"
+  " xxx "
+  "  x  "
+  " xxx "
+  "x x x"
+};
+static char cross_5_5[] = {
+  "x   x"
+  " x x "
+  "  x  "
+  " x x "
+  "x   x"
+};
+static char star_5_5[] = {
+  "x x x"
+  " xxx "
+  "xxxxx"
+  " xxx "
+  "x x x"
+};
+static char circle_line_5_5[] = {
+  " xxx "
+  "x   x"
+  "x   x"
+  "x   x"
+  " xxx "
+};       
+static char circle_filled_5_5[] = {
+  " xxx "
+  "xxxxx"
+  "xxxxx"
+  "xxxxx"
+  " xxx "
+};       
+static char triangle_up_line_5_5[] = { //OpenGL will draw with y reversed.
+  "xxxxx"
+  " x x "
+  " x x "
+  "  x  "
+  "  x  "
+};
+static char triangle_up_filled_5_5[] = {
+  "xxxxx"
+  " xxx "
+  " xxx "
+  "  x  "
+  "  x  "
+};
+static char triangle_down_line_5_5[] = {
+  "  x  "
+  "  x  "
+  " x x "
+  " x x "
+  "xxxxx"
+};
+static char triangle_down_filled_5_5[] = {
+  "  x  "
+  "  x  "
+  " xxx "
+  " xxx "
+  "xxxxx"
+};
+static char david_star_line_5_5[] = {
+  "  x  "
+  "xxxxx"
+  " x x "
+  "xxxxx"
+  "  x  "
+};       
+static char david_star_filled_5_5[] = {
+  "  x  "
+  "xxxxx"
+  " xxx "
+  "xxxxx"
+  "  x  "
+};       
+static char swiss_cross_line_5_5[] = {
+  " xxx "
+  "xx xx"
+  "x   x"
+  "xx xx"
+  " xxx "
+};       
+static char swiss_cross_filled_5_5[] = {
+  " xxx "
+  "xxxxx"
+  "xxxxx"
+  "xxxxx"
+  " xxx "
+};       
+static char diamond_line_5_5[] = {
+  "  x  "
+  " x x "
+  "x   x"
+  " x x "
+  "  x  "
+};
+static char diamond_filled_5_5[] = {
+  "  x  "
+  " xxx "
+  "xxxxx"
+  " xxx "
+  "  x  "
+};
+static char square_line_5_5[] = {
+  "xxxxx"
+  "x   x"
+  "x   x"
+  "x   x"
+  "xxxxx"
+};
+static char square_filled_5_5[] = {
+  "xxxxx"
+  "xxxxx"
+  "xxxxx"
+  "xxxxx"
+  "xxxxx"
+};
+///////////////////////////////////////////////////////////////
+/// 7 7 ///////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////
+static char plus_7_7[] = {
+  "   x   "
+  "   x   "
+  "   x   "
+  "xxxxxxx"
+  "   x   "
+  "   x   "
+  "   x   "
+};
+static char asterisk_7_7[] = {
+  "x  x  x"
+  " x x x "
+  "  xxx  "
+  "   x   "
+  "  xxx  "
+  " x x x "
+  "x  x  x"
+};
+static char cross_7_7[] = {
+  "x     x"
+  " x   x "
+  "  xxx  "
+  "   x   "
+  "  xxx  "
+  " x   x "
+  "x     x"
+};
+static char star_7_7[] = {
+  "x  x  x"
+  " x x x "
+  "  xxx  "
+  "xxxxxxx"
+  "  xxx  "
+  " x x x "
+  "x  x  x"
+};
+static char circle_line_7_7[] = {
+  " xxxxx "
+  "x     x"
+  "x     x"
+  "x     x"
+  "x     x"
+  "x     x"
+  " xxxxx "
+};       
+static char circle_filled_7_7[] = {
+  " xxxxx "
+  "xxxxxxx"
+  "xxxxxxx"
+  "xxxxxxx"
+  "xxxxxxx"
+  "xxxxxxx"
+  " xxxxx "
+};       
+static char triangle_up_line_7_7[] = { //OpenGL will draw with y reversed.
+  "xxxxxxx"
+  " x   x "
+  " x   x "
+  "  x x  "
+  "  x x  "
+  "   x   "
+  "   x   "
+};
+static char triangle_up_filled_7_7[] = {
+  "xxxxxxx"
+  " xxxxx "
+  " xxxxx "
+  "  xxx  "
+  "  xxx  "
+  "   x   "
+  "   x   "
+};
+static char triangle_down_line_7_7[] = {
+  "   x   "
+  "   x   "
+  "  x x  "
+  "  x x  "
+  " x   x "
+  " x   x "
+  "xxxxxxx"
+};
+static char triangle_down_filled_7_7[] = {
+  "   x   "
+  "   x   "
+  "  xxx  "
+  "  xxx  "
+  " xxxxx "
+  " xxxxx "
+  "xxxxxxx"
+};
+static char david_star_line_7_7[] = {
+  "   x   "
+  "xxxxxxx"
+  " x   x "
+  "  x x  "
+  " x   x "
+  "xxxxxxx"
+  "   x   "
+};       
+static char david_star_filled_7_7[] = {
+  "   x   "
+  "xxxxxxx"
+  " xxxxx "
+  "  xxx  "
+  " xxxxx "
+  "xxxxxxx"
+  "   x   "
+};       
+static char swiss_cross_line_7_7[] = {
+  "  xxx  "
+  "  x x  "
+  "xxx xxx"
+  "x     x"
+  "xxx xxx"
+  "  x x  "
+  "  xxx  "
+};       
+static char swiss_cross_filled_7_7[] = {
+  "  xxx  "
+  "  xxx  "
+  "xxxxxxx"
+  "xxxxxxx"
+  "xxxxxxx"
+  "  xxx  "
+  "  xxx  "
+};       
+static char diamond_line_7_7[] = {
+  "   x   "
+  "  x x  "
+  " x   x "
+  "x     x"
+  " x   x "
+  "  x x  "
+  "   x   "
+};
+static char diamond_filled_7_7[] = {
+  "   x   "
+  "  xxx  "
+  " xxxxx "
+  "xxxxxxx"
+  " xxxxx "
+  "  xxx  "
+  "   x   "
+};
+static char square_line_7_7[] = {
+  "xxxxxxx"
+  "x     x"
+  "x     x"
+  "x     x"
+  "x     x"
+  "x     x"
+  "xxxxxxx"
+};
+static char square_filled_7_7[] = {
+  "xxxxxxx"
+  "xxxxxxx"
+  "xxxxxxx"
+  "xxxxxxx"
+  "xxxxxxx"
+  "xxxxxxx"
+  "xxxxxxx"
+};
+
+///////////////////////////////////////////////////////////////
+/// 9 9 ///////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////
+static char plus_9_9[] = {
+  "    x    "
+  "    x    "
+  "    x    "
+  "    x    "
+  "xxxxxxxxx"
+  "    x    "
+  "    x    "
+  "    x    "
+  "    x    "
+};
+static char asterisk_9_9[] = {
+  "x   x   x"
+  " x  x  x "
+  "  x x x  "
+  "   xxx   "
+  "    x    "
+  "   xxx   "
+  "  x x x  "
+  " x  x  x "
+  "x   x   x"
+};
+static char cross_9_9[] = {
+  "x       x"
+  " x     x "
+  "  x   x  "
+  "   x x   "
+  "    x    "
+  "   x x   "
+  "  x   x  "
+  " x     x "
+  "x       x"
+};
+static char star_9_9[] = {
+  "x   x   x"
+  " x  x  x "
+  "  x x x  "
+  "   xxx   "
+  "xxxxxxxxx"
+  "   xxx   "
+  "  x x x  "
+  " x  x  x "
+  "x   x   x"
+};
+static char circle_line_9_9[] = {
+  "   xxx   "
+  " xx   xx "
+  " x     x "
+  "x       x"
+  "x       x"
+  "x       x"
+  " x     x "
+  " xx   xx "
+  "   xxx   "
+};       
+static char circle_filled_9_9[] = {
+  "   xxx   "
+  " xxxxxxx "
+  " xxxxxxx "
+  "xxxxxxxxx"
+  "xxxxxxxxx"
+  "xxxxxxxxx"
+  " xxxxxxx "
+  " xxxxxxx "
+  "   xxx   "
+};       
+static char triangle_up_line_9_9[] = { //OpenGL will draw with y reversed.
+  "xxxxxxxxx"
+  " x     x "
+  " x     x "
+  "  x   x  "
+  "  x   x  "
+  "   x x   "
+  "   x x   "
+  "    x    "
+  "    x    "
+};
+static char triangle_up_filled_9_9[] = {
+  "xxxxxxxxx"
+  " xxxxxxx "
+  " xxxxxxx "
+  "  xxxxx  "
+  "  xxxxx  "
+  "   xxx   "
+  "   xxx   "
+  "    x    "
+  "    x    "
+};
+static char triangle_down_line_9_9[] = {
+  "    x    "
+  "    x    "
+  "   x x   "
+  "   x x   "
+  "  x   x  "
+  "  x   x  "
+  " x     x "
+  " x     x "
+  "xxxxxxxxx"
+};
+static char triangle_down_filled_9_9[] = {
+  "    x    "
+  "    x    "
+  "   xxx   "
+  "   xxx   "
+  "  xxxxx  "
+  "  xxxxx  "
+  " xxxxxxx "
+  " xxxxxxx "
+  "xxxxxxxxx"
+};
+static char david_star_line_9_9[] = {
+  "    x    "
+  "   x x   "
+  "xxxxxxxxx"
+  " x     x "
+  "  x   x  "
+  " x     x "
+  "xxxxxxxxx"
+  "   x x   "
+  "    x    "
+};       
+static char david_star_filled_9_9[] = {
+  "    x    "
+  "   xxx   "
+  "xxxxxxxxx"
+  " xxxxxxx "
+  "  xxxxx  "
+  " xxxxxxx "
+  "xxxxxxxxx"
+  "   xxx   "
+  "    x    "
+};       
+static char swiss_cross_line_9_9[] = {
+  "   xxx   "
+  "   x x   "
+  "   x x   "
+  "xxxx xxxx"
+  "x       x"
+  "xxxx xxxx"
+  "   x x   "
+  "   x x   "
+  "   xxx   "
+};       
+static char swiss_cross_filled_9_9[] = {
+  "   xxx   "
+  "   xxx   "
+  "   xxx   "
+  "xxxxxxxxx"
+  "xxxxxxxxx"
+  "xxxxxxxxx"
+  "   xxx   "
+  "   xxx   "
+  "   xxx   "
+};       
+static char diamond_line_9_9[] = {
+  "    x    "
+  "   x x   "
+  "  x   x  "
+  " x     x "
+  "x       x"
+  " x     x "
+  "  x   x  "
+  "   x x   "
+  "    x    "
+};
+static char diamond_filled_9_9[] = {
+  "    x    "
+  "   xxx   "
+  "  xxxxx  "
+  " xxxxxxx "
+  "xxxxxxxxx"
+  " xxxxxxx "
+  "  xxxxx  "
+  "   xxx   "
+  "    x    "
+};
+static char square_line_9_9[] = {
+  "xxxxxxxxx"
+  "x       x"
+  "x       x"
+  "x       x"
+  "x       x"
+  "x       x"
+  "x       x"
+  "x       x"
+  "xxxxxxxxx"
+};
+static char square_filled_9_9[] = {
+  "xxxxxxxxx"
+  "xxxxxxxxx"
+  "xxxxxxxxx"
+  "xxxxxxxxx"
+  "xxxxxxxxx"
+  "xxxxxxxxx"
+  "xxxxxxxxx"
+  "xxxxxxxxx"
+  "xxxxxxxxx"
+};
+
+static char* sFigures[54] = {
+ plus_5_5,   //0
+ asterisk_5_5,
+ cross_5_5,
+ star_5_5,
+ circle_line_5_5,
+ circle_filled_5_5,
+ triangle_up_line_5_5,
+ triangle_up_filled_5_5,
+ triangle_down_line_5_5,
+ triangle_down_filled_5_5,
+ david_star_line_5_5,
+ david_star_filled_5_5,
+ swiss_cross_line_5_5,
+ swiss_cross_filled_5_5,
+ diamond_line_5_5,
+ diamond_filled_5_5,
+ square_line_5_5,
+ square_filled_5_5, //17
+ plus_7_7,
+ asterisk_7_7,
+ cross_7_7,
+ star_7_7,
+ circle_line_7_7,
+ circle_filled_7_7,
+ triangle_up_line_7_7,
+ triangle_up_filled_7_7,
+ triangle_down_line_7_7,
+ triangle_down_filled_7_7,
+ david_star_line_7_7,
+ david_star_filled_7_7,
+ swiss_cross_line_7_7,
+ swiss_cross_filled_7_7,
+ diamond_line_7_7,
+ diamond_filled_7_7,
+ square_line_7_7,
+ square_filled_7_7, //35
+ plus_9_9,
+ asterisk_9_9,
+ cross_9_9,
+ star_9_9,
+ circle_line_9_9,
+ circle_filled_9_9,
+ triangle_up_line_9_9,
+ triangle_up_filled_9_9,
+ triangle_down_line_9_9,
+ triangle_down_filled_9_9,
+ david_star_line_9_9,
+ david_star_filled_9_9,
+ swiss_cross_line_9_9,
+ swiss_cross_filled_9_9,
+ diamond_line_9_9,
+ diamond_filled_9_9,
+ square_line_9_9,
+ square_filled_9_9 //53
+};
+
+SO_NODE_SOURCE(HEPVis_SoMarkerSet)
+//////////////////////////////////////////////////////////////////////////////
+void HEPVis_SoMarkerSet::initClass (
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  SO_NODE_INIT_CLASS(HEPVis_SoMarkerSet,SoPointSet,"PointSet");
+}
+//////////////////////////////////////////////////////////////////////////////
+HEPVis_SoMarkerSet::HEPVis_SoMarkerSet (
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  SO_NODE_CONSTRUCTOR(HEPVis_SoMarkerSet);
+  
+  SO_NODE_ADD_FIELD(markerIndex,(CROSS_5_5));
+}
+//////////////////////////////////////////////////////////////////////////////
+HEPVis_SoMarkerSet::~HEPVis_SoMarkerSet (
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+}
+//////////////////////////////////////////////////////////////////////////////
+void HEPVis_SoMarkerSet::GLRender (
+ SoGLRenderAction* aAction
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  SoState* state = aAction->getState();
+
+  const SoCoordinateElement* coordinateElement = 
+    SoCoordinateElement::getInstance(state);
+  if(coordinateElement==NULL) return;
+
+  if(aAction->isOfType(SoGL2PSAction::getClassTypeId())) {
+    SoCacheElement::invalidate(state);
+  }
+
+  const SbColor& color = SoLazyElement::getDiffuse(aAction->getState(),0);
+  float red,green,blue;
+  color.getValue(red,green,blue);
+
+  int mark = markerIndex[0];
+
+  int starti = startIndex.getValue();
+  int pointn = numPoints.getValue();
+  int pointi;
+
+  glPushAttrib( (GLbitfield)(GL_CURRENT_BIT | GL_ENABLE_BIT));
+  glDisable(GL_LIGHTING);
+  glColor3f(red,green,blue);
+
+#ifdef WIN32  
+  //WIN32 : depth test is out over bitmap !
+  glDisable(GL_DEPTH_TEST);
+#endif
+
+  glPixelStorei(GL_UNPACK_ALIGNMENT,1);
+  for(pointi=starti;pointi<pointn;pointi++){
+    const SbVec3f& vec = coordinateElement->get3(pointi);
+    glRasterPos3f(vec[0],vec[1],vec[2]);
+    // Do a push, pop to correct a deffect of Mesa-3.1. 
+    // If not, further line drawing will have bad colors.
+    // The glPopAttrib will compell a reinitialisation of
+    // some internal Mesa state.
+    //glPushAttrib(GL_ALL_ATTRIB_BITS);
+    //glPopAttrib();
+    //
+    drawMarker(aAction,mark);
+  }
+
+  glPopAttrib();
+}
+//////////////////////////////////////////////////////////////////////////////
+void drawMarker(
+ SoAction* aAction
+,int aStyle
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  GLsizei w = 0,h = 0;
+  GLfloat xorig = 0,yorig = 0;
+  GLfloat xmove = 0,ymove = 0;
+
+  if((aStyle>=0)&&(aStyle<18)) {
+    w = h = 5;
+    xorig = yorig = 2;
+    GLubyte* bitmap = getBitmap(w,h,sFigures[aStyle]);
+    glBitmap(w,h,xorig,yorig,0.,0.,bitmap);
+    delete bitmap;
+  } else if((aStyle>=18)&&(aStyle<36)) {
+    w = h = 7;
+    xorig = yorig = 3;
+    GLubyte* bitmap = getBitmap(w,h,sFigures[aStyle]);
+    glBitmap(w,h,xorig,yorig,0.,0.,bitmap);
+    delete bitmap;
+  } else if((aStyle>=36)&&(aStyle<54)) {
+    w = h = 9;
+    xorig = yorig = 4;
+    GLubyte* bitmap = getBitmap(w,h,sFigures[aStyle]);
+    glBitmap(w,h,xorig,yorig,0.,0.,bitmap);
+    delete bitmap;
+  } else {
+    return;
+  }
+
+  if(aAction->isOfType(SoGL2PSAction::getClassTypeId())) {
+    ((SoGL2PSAction*)aAction)->addBitmap(w,h,xorig,yorig,xmove,ymove);
+  }
+
+}
+//////////////////////////////////////////////////////////////////////////////
+GLubyte* getBitmap(
+ int aW
+,int aH
+,char aFigure[]
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  int index = 0;
+  GLubyte* bitmap = new GLubyte[aW * aH + 1];
+  int ichar = 0;
+  int ibit = 0;
+  unsigned char byte = 0;
+  for ( int row = 0; row < aH; row++ ){
+    for ( int col = 0; col < aW; col++){ 
+      unsigned char c = aFigure[ichar];
+      ichar++;
+      if(c==' ') {
+        ibit++;
+      } else { 
+        byte += (1<<(7-ibit));
+        ibit++;
+      }
+      if(ibit==8) {
+        //unsigned char h = byte / 16;
+        //unsigned char l = byte % 16;
+        //printf("0x%x%x\n",h,l);
+        bitmap[index] = byte;
+        index++;
+        ibit = 0;
+        byte = 0;
+      }
+
+    }
+    if(ibit!=8) { //Jump to next byte.
+      //unsigned char h = byte / 16;
+      //unsigned char l = byte % 16;
+      //printf("0x%x%x\n",h,l);
+      bitmap[index] = byte;
+      index++;
+      ibit = 0;
+      byte = 0;
+    }
+  }
+  return bitmap; 
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/SoPolyhedron.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/SoPolyhedron.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/SoPolyhedron.cc	(revision 529)
@@ -0,0 +1,563 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+/*----------------------------HEPVis----------------------------------------*/
+/*                                                                          */
+/* Node:             SoPolyhedron                                           */
+/* Description:      SoNode to represent HepPolyhedron                      */
+/* Author:           Guy Barrand                                            */
+/*                                                                          */
+/*--------------------------------------------------------------------------*/
+
+// this :
+#include "Geant4_SoPolyhedron.h"
+
+#include <Inventor/SbBox.h>
+#include <Inventor/actions/SoAction.h>
+#include <Inventor/SoPrimitiveVertex.h>
+#include <Inventor/elements/SoTextureCoordinateElement.h>
+#include <Inventor/nodes/SoSeparator.h>
+
+//#include <HEPVis/SbMath.h>
+#define SbMinimum(a,b) ((a)<(b)?a:b)
+#define SbMaximum(a,b) ((a)>(b)?a:b)
+
+#include <HEPVis/actions/SoAlternateRepAction.h>
+
+#include "G4Polyhedron.hh"
+
+//typedef SbVec3f HVPoint3D;
+//typedef SbVec3f HVNormal3D;
+
+typedef HepGeom::Point3D<double> HVPoint3D;
+typedef HepGeom::Normal3D<double> HVNormal3D;
+
+SO_NODE_SOURCE(Geant4_SoPolyhedron) 
+//////////////////////////////////////////////////////////////////////////////
+void Geant4_SoPolyhedron::initClass(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  SO_NODE_INIT_CLASS(Geant4_SoPolyhedron,SoShape,"Shape");
+}
+//////////////////////////////////////////////////////////////////////////////
+Geant4_SoPolyhedron::Geant4_SoPolyhedron(
+)
+:fPolyhedron(0)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  SO_NODE_CONSTRUCTOR(Geant4_SoPolyhedron);
+  SO_NODE_ADD_FIELD(solid,(TRUE));
+  SO_NODE_ADD_FIELD(reducedWireFrame,(TRUE));
+  SO_NODE_ADD_FIELD(alternateRep,(NULL));
+}
+//////////////////////////////////////////////////////////////////////////////
+Geant4_SoPolyhedron::Geant4_SoPolyhedron(
+ const G4Polyhedron& aPolyhedron
+)
+:fPolyhedron(0)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  SO_NODE_CONSTRUCTOR(Geant4_SoPolyhedron);
+  SO_NODE_ADD_FIELD(solid,(TRUE));
+  SO_NODE_ADD_FIELD(reducedWireFrame,(TRUE));
+  SO_NODE_ADD_FIELD(alternateRep,(NULL));
+
+  fPolyhedron = new G4Polyhedron(aPolyhedron);
+}
+//////////////////////////////////////////////////////////////////////////////
+Geant4_SoPolyhedron::Geant4_SoPolyhedron(
+ G4Polyhedron* aPolyhedron
+)
+:fPolyhedron(aPolyhedron)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  SO_NODE_CONSTRUCTOR(Geant4_SoPolyhedron);
+  SO_NODE_ADD_FIELD(solid,(TRUE));
+  SO_NODE_ADD_FIELD(reducedWireFrame,(TRUE));
+  SO_NODE_ADD_FIELD(alternateRep,(NULL));
+}
+//////////////////////////////////////////////////////////////////////////////
+Geant4_SoPolyhedron::~Geant4_SoPolyhedron(
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  delete fPolyhedron;
+}
+//////////////////////////////////////////////////////////////////////////////
+void Geant4_SoPolyhedron::generatePrimitives(
+ SoAction* aAction
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(!fPolyhedron) return;
+  if(fPolyhedron->GetNoFacets()<=0) return; // Abnormal polyhedron.
+
+  SoState *state = aAction->getState();
+  SbBool useTexFunction =
+    (SoTextureCoordinateElement::getType(state) == 
+     SoTextureCoordinateElement::FUNCTION);
+  const SoTextureCoordinateElement *tce = NULL;
+  SbVec4f texCoord;
+  if (useTexFunction) {
+    tce = SoTextureCoordinateElement::getInstance(state);
+  } else {
+    texCoord[2] = 0.0;
+    texCoord[3] = 1.0;
+  }
+
+  if(solid.getValue()==TRUE) {
+    SoPrimitiveVertex pv;
+    SbVec3f point, normal;
+    //////////////////////////////////////////
+    //----------------------------------------
+#define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz)  \
+  point.setValue(x,y,z);                   \
+  normal.setValue(nx,ny,nz);               \
+  if (useTexFunction) {                    \
+    texCoord=tce->get(point,normal);       \
+  } else {                                 \
+    texCoord[0]=s;                         \
+    texCoord[1]=t;                         \
+  }                                        \
+  pv.setPoint(point);                      \
+  pv.setNormal(normal);                    \
+  pv.setTextureCoords(texCoord);           \
+  shapeVertex(&pv);
+  //----------------------------------------
+  //////////////////////////////////////////
+
+    // Assume all facets are convex quadrilaterals :
+    bool notLastFace;
+    do {
+      HVNormal3D unitNormal;
+      notLastFace = fPolyhedron->GetNextUnitNormal(unitNormal);
+
+      beginShape(aAction,POLYGON);
+      bool notLastEdge;
+      int edgeFlag = 1;
+      do {
+        HVPoint3D vertex;
+        notLastEdge = fPolyhedron->GetNextVertex(vertex,edgeFlag);
+        GEN_VERTEX(pv,
+                   vertex[0],
+                   vertex[1],
+                   vertex[2],
+                   0.0,0.0,
+                   unitNormal[0],
+                   unitNormal[1],
+                   unitNormal[2]);
+      } while (notLastEdge);
+      endShape();
+    } while (notLastFace);
+  } else {
+    SoPrimitiveVertex pvb,pve;
+    pve.setTextureCoords(texCoord);
+    pvb.setTextureCoords(texCoord);
+
+#ifdef __COIN__ // To bypass a bug in invokeLineSegment when picking.
+    beginShape(aAction,POLYGON);
+    endShape();
+#endif
+
+    SbVec3f point;
+    bool notLastFace;
+    do {
+      HVNormal3D unitNormal;
+      notLastFace = fPolyhedron->GetNextUnitNormal(unitNormal);
+
+      SbVec3f normal;
+      normal.setValue(unitNormal[0],unitNormal[1],unitNormal[2]);
+
+      // Treat edges :
+      int edgeFlag = 1;
+      int prevEdgeFlag = edgeFlag;
+      bool notLastEdge;
+      SbBool firstEdge = TRUE;
+      do {
+        HVPoint3D vertex;
+        notLastEdge = fPolyhedron->GetNextVertex(vertex,edgeFlag);
+        if(reducedWireFrame.getValue()==FALSE) edgeFlag = 1;        
+        if(firstEdge) {
+          if(edgeFlag > 0) {
+            pvb.setNormal(normal);
+            point.setValue(vertex[0],vertex[1],vertex[2]);
+            pvb.setPoint(point);
+          } else {
+          }
+          firstEdge = FALSE;
+          prevEdgeFlag = edgeFlag;
+        } else {
+          if(edgeFlag!=prevEdgeFlag) { 
+            if(edgeFlag > 0) { // Pass to a visible edge :
+              pvb.setNormal(normal);
+              point.setValue(vertex[0],vertex[1],vertex[2]);
+              pvb.setPoint(point);
+            } else { // Pass to an invisible edge :
+              pve.setNormal(normal);
+              point.setValue(vertex[0],vertex[1],vertex[2]);
+              pve.setPoint(point);
+              invokeLineSegmentCallbacks(aAction,&pvb,&pve);
+            }
+            prevEdgeFlag = edgeFlag;
+          } else {
+            if(edgeFlag > 0) {
+              pve.setNormal(normal);
+              point.setValue(vertex[0],vertex[1],vertex[2]);
+              pve.setPoint(point);
+              invokeLineSegmentCallbacks(aAction,&pvb,&pve);
+              pvb = pve;
+            } else {
+            }
+          }
+        }
+      } while (notLastEdge);
+    } while (notLastFace);
+  }
+
+}
+//////////////////////////////////////////////////////////////////////////////
+void Geant4_SoPolyhedron::computeBBox(
+ SoAction*
+,SbBox3f& aBox
+,SbVec3f& aCenter
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(!fPolyhedron) return;
+  if(fPolyhedron->GetNoFacets()<=0) { // Abnormal polyhedron.
+    SbVec3f vmin(-1,-1,-1);
+    SbVec3f vmax( 1, 1, 1);
+    aBox.setBounds(vmin,vmax);
+    aCenter.setValue(0,0,0);
+  } else {
+    SbBool first = TRUE;
+    float xmn = 0,ymn = 0,zmn = 0;
+    float xmx = 0,ymx = 0,zmx = 0;
+    float xct = 0,yct = 0,zct = 0;
+    SbVec3f point;
+    int count = 0;
+    // Assume all facets are convex quadrilaterals :
+    bool notLastFace;
+    do {
+      HVNormal3D unitNormal;
+      notLastFace = fPolyhedron->GetNextUnitNormal(unitNormal);
+      bool notLastEdge;
+      do {
+        HVPoint3D vertex;
+        int edgeFlag = 1;
+        notLastEdge = fPolyhedron->GetNextVertex(vertex,edgeFlag);
+        point.setValue(vertex[0],vertex[1],vertex[2]);
+        if(first==TRUE) {
+          xct = xmx = xmn = point[0];
+          yct = ymx = ymn = point[1];
+          zct = zmx = zmn = point[2];
+          count++;
+          first = FALSE;
+        } else {
+          xmn = SbMinimum(xmn,point[0]);
+          ymn = SbMinimum(ymn,point[1]);
+          zmn = SbMinimum(zmn,point[2]);
+          //
+          xmx = SbMaximum(xmx,point[0]);
+          ymx = SbMaximum(ymx,point[1]);
+          zmx = SbMaximum(zmx,point[2]);
+          //
+          xct += point[0];
+          yct += point[1];
+          zct += point[2];
+          count++;
+        }
+        //
+      } while (notLastEdge);
+    } while (notLastFace);
+    SbVec3f vmin(xmn,ymn,zmn);
+    SbVec3f vmax(xmx,ymx,zmx);
+    aBox.setBounds(vmin,vmax);
+    if(count==0)
+      aCenter.setValue(0,0,0);
+    else
+      aCenter.setValue(xct/count,yct/count,zct/count);
+  }
+}
+
+#include <Inventor/nodes/SoNormalBinding.h>
+#include <Inventor/nodes/SoNormal.h>
+#include <Inventor/nodes/SoCoordinate3.h>
+#include <Inventor/nodes/SoIndexedFaceSet.h>
+#include <Inventor/nodes/SoIndexedLineSet.h>
+//////////////////////////////////////////////////////////////////////////////
+void Geant4_SoPolyhedron::generateAlternateRep(
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  if(!fPolyhedron) return;
+  if(fPolyhedron->GetNoFacets()<=0) return; // Abnormal polyhedron.
+  if(fPolyhedron->GetNoVertices()<=0) return; // Abnormal polyhedron.
+
+  if(solid.getValue()==TRUE) {
+
+    SoSeparator* separator = new SoSeparator;
+
+    SoNormalBinding* normalBinding = new SoNormalBinding;
+    normalBinding->value = SoNormalBinding::PER_FACE;
+    separator->addChild(normalBinding);
+
+    SoCoordinate3* coordinate3 = new SoCoordinate3;
+    separator->addChild(coordinate3);
+    SoNormal* normal = new SoNormal;
+    separator->addChild(normal);
+    SoIndexedFaceSet* indexedFaceSet = new SoIndexedFaceSet;
+    separator->addChild(indexedFaceSet);
+
+    SbBool empty = TRUE;
+
+    int nvert = fPolyhedron->GetNoVertices();
+    int nface = fPolyhedron->GetNoFacets();
+
+    SbVec3f* normals = new SbVec3f[nface];
+    //FIXME : have the exact booking.
+    SbVec3f* points = new SbVec3f[nvert];
+    int32_t* coords = new int32_t[nvert+1];
+
+    int inormal = 0;
+    int icoord = 0;
+    int iindex = 0;
+
+    // Assume all facets are convex quadrilaterals :
+    bool notLastFace;
+    do {
+      HVNormal3D unitNormal;
+      notLastFace = fPolyhedron->GetNextUnitNormal(unitNormal);
+
+      // begin face POLYGON
+      int ipoint = 0;
+
+      bool notLastEdge;
+      int edgeFlag = 1;
+      do {
+        HVPoint3D vertex;
+        notLastEdge = fPolyhedron->GetNextVertex(vertex,edgeFlag);
+        points[ipoint].setValue(vertex[0],vertex[1],vertex[2]);
+        coords[ipoint] = icoord + ipoint;
+        ipoint++;
+        empty = FALSE;
+
+      } while (notLastEdge);
+
+      // end face.
+      coords[ipoint] = SO_END_FACE_INDEX;
+      coordinate3->point.setValues(icoord,ipoint,points);
+      icoord += ipoint;
+
+      normals[inormal].setValue(unitNormal[0],unitNormal[1],unitNormal[2]);
+      inormal++;  
+
+      indexedFaceSet->coordIndex.setValues(iindex,(ipoint+1),coords);
+      iindex += ipoint+1;
+
+    } while (notLastFace);
+
+    normal->vector.setValues(0,inormal,normals);
+
+    delete [] normals;
+    delete [] coords;
+    delete [] points;
+
+    if(empty==TRUE) {
+      separator->unref();
+    } else {
+      alternateRep.setValue(separator);
+    }
+
+  } else {
+
+    SoSeparator* separator = new SoSeparator;
+
+    int nvert = fPolyhedron->GetNoVertices();
+
+    //FIXME : have the exact booking.
+    int nedge = nvert * 3;
+    int npoint = nedge*2;
+    SbVec3f* points = new SbVec3f[npoint];
+    int ncoord = nedge*3;
+    int32_t* coords = new int32_t[ncoord];
+
+    SbVec3f pvb,pve;
+
+    SbBool empty = TRUE;
+    int ipoint = 0;
+    int icoord = 0;
+
+    bool notLastFace;
+    do {
+      HVNormal3D unitNormal;
+      notLastFace = fPolyhedron->GetNextUnitNormal(unitNormal);
+
+      //SbVec3f normal;
+      //if( (fProjection==SbProjectionRZ) || (fProjection==SbProjectionZR) ) {
+        //normal.setValue(0,0,1);
+      //} else {
+        //normal.setValue(unitNormal[0],unitNormal[1],unitNormal[2]);
+      //}
+
+      // Treat edges :
+      int edgeFlag = 1;
+      int prevEdgeFlag = edgeFlag;
+      bool notLastEdge;
+      SbBool firstEdge = TRUE;
+      do {
+        HVPoint3D vertex;
+        notLastEdge = fPolyhedron->GetNextVertex(vertex,edgeFlag);
+        if(reducedWireFrame.getValue()==FALSE) edgeFlag = 1;        
+        if(firstEdge) {
+          if(edgeFlag > 0) {
+            pvb.setValue(vertex[0],vertex[1],vertex[2]);
+          } else {
+          }
+          firstEdge = FALSE;
+          prevEdgeFlag = edgeFlag;
+        } else {
+          if(edgeFlag!=prevEdgeFlag) { 
+            if(edgeFlag > 0) { // Pass to a visible edge :
+              pvb.setValue(vertex[0],vertex[1],vertex[2]);
+            } else { // Pass to an invisible edge :
+              pve.setValue(vertex[0],vertex[1],vertex[2]);
+
+              if((ipoint+1)>=npoint) {
+                int new_npoint = 2 * npoint;
+                SbVec3f* new_points = new SbVec3f[new_npoint];
+                for(int i=0;i<npoint;i++) new_points[i] = points[i];
+                delete [] points;
+                npoint = new_npoint;
+                points = new_points;
+              }
+
+              if((icoord+2)>=ncoord) {
+                int new_ncoord = 2 * ncoord;
+                int32_t* new_coords = new int32_t[new_ncoord];
+                for(int i=0;i<ncoord;i++) new_coords[i] = coords[i];
+                delete [] coords;
+                ncoord = new_ncoord;
+                coords = new_coords;
+              }
+
+              points[ipoint+0] = pvb;
+              points[ipoint+1] = pve;
+              coords[icoord+0] = ipoint + 0;
+              coords[icoord+1] = ipoint + 1;
+              coords[icoord+2] = SO_END_LINE_INDEX;
+              ipoint += 2;
+              icoord += 3;
+              empty = FALSE;
+            }
+            prevEdgeFlag = edgeFlag;
+          } else {
+            if(edgeFlag > 0) {
+              pve.setValue(vertex[0],vertex[1],vertex[2]);
+
+              if((ipoint+1)>=npoint) {
+                int new_npoint = 2 * npoint;
+                SbVec3f* new_points = new SbVec3f[new_npoint];
+                for(int i=0;i<npoint;i++) new_points[i] = points[i];
+                delete [] points;
+                npoint = new_npoint;
+                points = new_points;
+              }
+
+              if((icoord+2)>=ncoord) {
+                int new_ncoord = 2 * ncoord;
+                int32_t* new_coords = new int32_t[new_ncoord];
+                for(int i=0;i<ncoord;i++) new_coords[i] = coords[i];
+                delete [] coords;
+                ncoord = new_ncoord;
+                coords = new_coords;
+              }
+
+              points[ipoint+0] = pvb;
+              points[ipoint+1] = pve;
+              coords[icoord+0] = ipoint + 0;
+              coords[icoord+1] = ipoint + 1;
+              coords[icoord+2] = SO_END_LINE_INDEX;
+              ipoint += 2;
+              icoord += 3;
+              empty = FALSE;
+
+              pvb = pve;
+            } else {
+            }
+          }
+        }
+      } while (notLastEdge);
+    } while (notLastFace);
+
+    SoCoordinate3* coordinate3 = new SoCoordinate3;
+    coordinate3->point.setValues(0,ipoint,points);
+    separator->addChild(coordinate3);
+
+    SoIndexedLineSet* indexedLineSet = new SoIndexedLineSet;
+    indexedLineSet->coordIndex.setValues(0,icoord,coords);
+    separator->addChild(indexedLineSet);
+
+    delete [] coords;
+    delete [] points;
+
+    if(empty==TRUE) {
+      separator->unref();
+    } else {
+      alternateRep.setValue(separator);
+    }
+  }
+}
+//////////////////////////////////////////////////////////////////////////////
+void Geant4_SoPolyhedron::clearAlternateRep(
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  alternateRep.setValue(NULL);
+}
+//////////////////////////////////////////////////////////////////////////////
+void Geant4_SoPolyhedron::doAction(
+ SoAction* aAction
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  SO_ALTERNATEREP_DO_ACTION(aAction)
+  SoShape::doAction(aAction);
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/SoStyleCache.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/SoStyleCache.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/SoStyleCache.cc	(revision 529)
@@ -0,0 +1,212 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+/*----------------------------HEPVis----------------------------------------*/
+/*                                                                          */
+/* Node:             SoStyleCache                                           */
+/* Author:           Guy Barrand                                            */
+/*                                                                          */
+/*--------------------------------------------------------------------------*/
+
+// this :
+#include <HEPVis/misc/SoStyleCache.h>
+
+#include <Inventor/nodes/SoMaterial.h>
+#include <Inventor/nodes/SoDrawStyle.h>
+#include <Inventor/nodes/SoLightModel.h>
+#include <Inventor/nodes/SoResetTransform.h>
+
+//////////////////////////////////////////////////////////////////////////////
+SoStyleCache::SoStyleCache(
+) 
+:fMaterials(0)
+,fLineStyles(0)
+,fLightModels(0)
+,fResetTransform(0)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  fMaterials = new SoGroup;
+  addChild(fMaterials);
+  fLineStyles = new SoGroup;
+  addChild(fLineStyles);
+  fLightModels = new SoGroup;
+  addChild(fLightModels);
+  fResetTransform = new SoResetTransform;
+  addChild(fResetTransform);
+}
+//////////////////////////////////////////////////////////////////////////////
+SoStyleCache::~SoStyleCache(
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+}
+//////////////////////////////////////////////////////////////////////////////
+SoMaterial* SoStyleCache::getMaterial(
+ const SbColor& aRGB
+,float aTransparency
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  int number = fMaterials->getNumChildren();
+  for(int index=0;index<number;index++) { 
+    SoMaterial* material = (SoMaterial*)fMaterials->getChild(index);
+    if( (material->diffuseColor[0]==aRGB) &&
+        (material->transparency[0]==aTransparency) ) {
+      return material;
+    }
+  }
+  SoMaterial* material = new SoMaterial;
+  material->diffuseColor.setValue(aRGB);
+  material->transparency.setValue(aTransparency);
+  fMaterials->addChild(material);
+  return material;
+}
+//////////////////////////////////////////////////////////////////////////////
+SoMaterial* SoStyleCache::getMaterial(
+ float aRed
+,float aGreen
+,float aBlue
+,float aTransparency
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  SbColor aRGB(aRed,aGreen,aBlue);
+  int number = fMaterials->getNumChildren();
+  for(int index=0;index<number;index++) { 
+    SoMaterial* material = (SoMaterial*)fMaterials->getChild(index);
+    if( (material->diffuseColor[0]==aRGB) &&
+        (material->transparency[0]==aTransparency) ) {
+      return material;
+    }
+  }
+  SoMaterial* material = new SoMaterial;
+  material->diffuseColor.setValue(aRGB);
+  material->transparency.setValue(aTransparency);
+  fMaterials->addChild(material);
+  return material;
+}
+/*
+//////////////////////////////////////////////////////////////////////////////
+SoDrawStyle* SoStyleCache::getLineStyle(
+ SbLineStyle aStyle
+,float aWidth
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  unsigned short pattern = 0xFFFF;
+  switch(aStyle) {
+  case SbLineDashed:
+    pattern = 0x00FF;
+    break;
+  case SbLineDotted:
+    pattern = 0x0101;
+    break;
+  case SbLineDashDotted:
+    pattern = 0x1C47;
+    break;
+  default: //SbLineSolid:
+    pattern = 0xFFFF;
+    break;
+  }
+  int number = fLineStyles->getNumChildren();
+  for(int index=0;index<number;index++) { 
+    SoDrawStyle* drawStyle = (SoDrawStyle*)fLineStyles->getChild(index);
+    if( (drawStyle->style.getValue()==SoDrawStyle::LINES) &&
+        (drawStyle->lineWidth.getValue()==aWidth) &&
+        (drawStyle->linePattern.getValue()==pattern) ) {
+      return drawStyle;
+    }
+  }
+  SoDrawStyle* drawStyle = new SoDrawStyle;
+  drawStyle->style.setValue(SoDrawStyle::LINES);
+  drawStyle->lineWidth.setValue(aWidth);
+  drawStyle->linePattern.setValue(pattern);
+  fLineStyles->addChild(drawStyle);
+  return drawStyle;
+}
+*/
+//////////////////////////////////////////////////////////////////////////////
+SoDrawStyle* SoStyleCache::getLineStyle(
+ unsigned short aPattern
+,float aWidth
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  int number = fLineStyles->getNumChildren();
+  for(int index=0;index<number;index++) { 
+    SoDrawStyle* drawStyle = (SoDrawStyle*)fLineStyles->getChild(index);
+    if( (drawStyle->style.getValue()==SoDrawStyle::LINES) &&
+        (drawStyle->lineWidth.getValue()==aWidth) &&
+        (drawStyle->linePattern.getValue()==aPattern) ) {
+      return drawStyle;
+    }
+  }
+  SoDrawStyle* drawStyle = new SoDrawStyle;
+  drawStyle->style.setValue(SoDrawStyle::LINES);
+  drawStyle->lineWidth.setValue(aWidth);
+  drawStyle->linePattern.setValue(aPattern);
+  fLineStyles->addChild(drawStyle);
+  return drawStyle;
+}
+//////////////////////////////////////////////////////////////////////////////
+SoLightModel* SoStyleCache::getLightModelPhong(
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  SoLightModel* lightModel = new SoLightModel;
+  lightModel->model.setValue(SoLightModel::PHONG);
+  fLightModels->addChild(lightModel);
+  return lightModel;
+}
+//////////////////////////////////////////////////////////////////////////////
+SoLightModel* SoStyleCache::getLightModelBaseColor(
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  SoLightModel* lightModel = new SoLightModel;
+  lightModel->model.setValue(SoLightModel::BASE_COLOR);
+  fLightModels->addChild(lightModel);
+  return lightModel;
+}
+//////////////////////////////////////////////////////////////////////////////
+SoResetTransform* SoStyleCache::getResetTransform(
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  return fResetTransform;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/SoTrap.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/SoTrap.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/SoTrap.cc	(revision 529)
@@ -0,0 +1,413 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+//
+// $Id: SoTrap.cc,v 1.8 2006/06/29 21:23:03 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+/*-----------------------------HEPVis----------------------------------------*/
+/*                                                                           */
+/* Node:             SoTrap                                                  */
+/* Description:      Represents the G4Trap Geant Geometry entity             */
+/* Author:           Joe Boudreau Nov 11 1996                                */
+/*                                                                           */
+/*                                                                           */
+/*---------------------------------------------------------------------------*/
+
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+// this :
+#include "HEPVis/nodes/SoTrap.h"
+
+#include <assert.h>
+#include <cmath>
+#include <Inventor/SbBox.h>
+#include <Inventor/actions/SoGLRenderAction.h>
+#include <Inventor/actions/SoAction.h>
+#include <Inventor/fields/SoSFFloat.h>
+#include <Inventor/misc/SoChildList.h>
+#include <Inventor/nodes/SoSeparator.h>
+#include <Inventor/nodes/SoIndexedFaceSet.h>
+#include <Inventor/nodes/SoNormal.h>
+#include <Inventor/nodes/SoCoordinate3.h>
+#include <Inventor/nodes/SoNormalBinding.h>
+#include <Inventor/SoPrimitiveVertex.h>
+#include <Inventor/elements/SoTextureCoordinateElement.h>
+
+#include "HEPVis/SbMath.h"
+
+// This statement is required
+SO_NODE_SOURCE(SoTrap)
+
+// Constructor
+SoTrap::SoTrap() {
+  // This statement is required
+  SO_NODE_CONSTRUCTOR(SoTrap);
+
+  // Data fields are initialized like this:
+  SO_NODE_ADD_FIELD(pDz,                 (1.0));
+  SO_NODE_ADD_FIELD(pTheta,              (0.0));
+  SO_NODE_ADD_FIELD(pPhi,                (0.0));
+  SO_NODE_ADD_FIELD(pDy1,                (1.0));
+  SO_NODE_ADD_FIELD(pDx1,                (1.0));
+  SO_NODE_ADD_FIELD(pDx2,                (1.0));
+  SO_NODE_ADD_FIELD(pDy2,                (1.0));
+  SO_NODE_ADD_FIELD(pDx3,                (1.0));
+  SO_NODE_ADD_FIELD(pDx4,                (1.0));
+  SO_NODE_ADD_FIELD(pAlp1,               (0.0));
+  SO_NODE_ADD_FIELD(pAlp2,               (0.0));
+  SO_NODE_ADD_FIELD(alternateRep,        (NULL));
+  children = new SoChildList(this);
+}
+
+// Destructor
+SoTrap::~SoTrap() {
+ delete children;
+}
+
+
+// initClass
+void SoTrap::initClass(){
+  // This statement is required.
+  SO_NODE_INIT_CLASS(SoTrap,SoShape,"Shape");
+}
+
+
+// generatePrimitives
+void SoTrap::generatePrimitives(SoAction *action) {
+  // This variable is used to store each vertex
+  SoPrimitiveVertex pv;
+
+  // Access the stat from the action
+  SoState *state = action->getState();
+
+  // See if we have to use a texture coordinate function,
+  // rather than generating explicit texture coordinates.
+  SbBool useTexFunction=
+    (SoTextureCoordinateElement::getType(state) == 
+     SoTextureCoordinateElement::FUNCTION);
+
+  // If we need to generate texture coordinates with a function,
+  // we'll need an SoGLTextureCoordinateElement.  Otherwise, we'll
+  // set up the coordinates directly.
+  const SoTextureCoordinateElement *tce = NULL;
+  SbVec4f texCoord;
+  if (useTexFunction) {
+    tce = SoTextureCoordinateElement::getInstance(state);
+  }
+  else {
+    texCoord[2] = 0.0;
+    texCoord[3] = 1.0;
+  }
+  SbVec3f point, normal;
+
+
+  //////////////////////////////////////////
+  //----------------------------------------
+#define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz)  \
+  point.setValue(x,y,z);                   \
+  normal.setValue(nx,ny,nz);               \
+  if (useTexFunction) {                    \
+    texCoord=tce->get(point,normal);       \
+  }                                        \
+  else {                                   \
+    texCoord[0]=s;                         \
+    texCoord[1]=t;                         \
+  }                                        \
+  pv.setPoint(point);                      \
+  pv.setNormal(normal);                    \
+  pv.setTextureCoords(texCoord);           \
+  shapeVertex(&pv);
+  //----------------------------------------
+  //////////////////////////////////////////
+
+  const int NPOINTS=8, NFACES=6, NINDICES = NFACES*5;
+  int indices[NINDICES] = {3,2,1,0, SO_END_FACE_INDEX,  //z back.
+			   4,5,6,7, SO_END_FACE_INDEX,  //z front.
+			   0,1,5,4, SO_END_FACE_INDEX,  //y up.
+			   1,2,6,5, SO_END_FACE_INDEX,  //x left.
+			   2,3,7,6, SO_END_FACE_INDEX,  //y down.
+			   3,0,4,7, SO_END_FACE_INDEX}; //x right.
+
+  // points for the eight vertices
+  float TthetaCphi = FTAN(pTheta.getValue())*FCOS(pPhi.getValue());
+  float TthetaSphi = FTAN(pTheta.getValue())*FSIN(pPhi.getValue());
+  float Talp1 = FTAN(pAlp1.getValue()); 
+  float Talp2 = FTAN(pAlp2.getValue());
+
+  float points[NPOINTS][3];
+  points[0][0] =  pDx2.getValue()+pDy1.getValue()*Talp1;
+  points[0][1] =  pDy1.getValue();
+  points[0][2] = -pDz.getValue();
+
+  points[1][0] = -pDx2.getValue()+pDy1.getValue()*Talp1;
+  points[1][1] =  pDy1.getValue();
+  points[1][2] = -pDz.getValue();
+
+  points[2][0] = -pDx1.getValue()-pDy1.getValue()*Talp1;
+  points[2][1] = -pDy1.getValue();
+  points[2][2] = -pDz.getValue();
+
+  points[3][0] =  pDx1.getValue()-pDy1.getValue()*Talp1;
+  points[3][1] = -pDy1.getValue();
+  points[3][2] = -pDz.getValue();
+
+  points[4][0] =  pDx4.getValue()+pDy2.getValue()*Talp2;
+  points[4][1] =  pDy2.getValue();
+  points[4][2] =  pDz.getValue();
+
+  points[5][0] = -pDx4.getValue()+pDy2.getValue()*Talp2;
+  points[5][1] =  pDy2.getValue();
+  points[5][2] =  pDz.getValue();
+
+  points[6][0] = -pDx3.getValue()-pDy2.getValue()*Talp2;
+  points[6][1] = -pDy2.getValue();
+  points[6][2] =  pDz.getValue();
+
+  points[7][0] =  pDx3.getValue()-pDy2.getValue()*Talp2;
+  points[7][1] = -pDy2.getValue();
+  points[7][2] =  pDz.getValue();
+
+  int i;
+  for (i=0;i<4;i++) {
+    points[i][0] -= pDz.getValue()*TthetaCphi;
+    points[i][1] -= pDz.getValue()*TthetaSphi;
+  }
+  for (i=4;i<8;i++) {
+    points[i][0] += pDz.getValue()*TthetaCphi;
+    points[i][1] += pDz.getValue()*TthetaSphi;
+  }
+
+  SbVec3f normals[NFACES];
+  int nf;
+  for (nf=0;nf<NFACES;nf++) {
+    int j0 = indices[5*nf + 0];
+    int j1 = indices[5*nf + 1];
+    int j2 = indices[5*nf + 2];
+    SbVec3f p0(points[j0][0],points[j0][1],points[j0][2]); 
+    SbVec3f p1(points[j1][0],points[j1][1],points[j1][2]); 
+    SbVec3f p2(points[j2][0],points[j2][1],points[j2][2]); 
+    normals[nf] = (p1-p0).cross(p2-p0);
+    normals[nf].normalize();
+  }
+
+  float x,y,z;
+  int   index;
+  for (nf=0;nf<NFACES;nf++) {
+    beginShape(action,TRIANGLE_FAN);
+    index = indices[nf * 5];   
+    x = points[index][0];
+    y = points[index][1];
+    z = points[index][2];
+    GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
+    index = indices[nf * 5 + 1];   
+    x = points[index][0];
+    y = points[index][1];
+    z = points[index][2];
+    GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
+    index = indices[nf * 5 + 2];   
+    x = points[index][0];
+    y = points[index][1];
+    z = points[index][2];
+    GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
+    index = indices[nf * 5 + 3];   
+    x = points[index][0];
+    y = points[index][1];
+    z = points[index][2];
+    GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
+    endShape();
+  }
+}
+
+// getChildren
+SoChildList *SoTrap::getChildren() const {
+  return children;
+}
+
+
+// computeBBox
+void SoTrap::computeBBox(SoAction *, SbBox3f &box, SbVec3f &center ){
+  float pDx= pDx1.getValue(),pDy=pDy1.getValue();
+  
+  if (pDx2.getValue() > pDx) pDx = pDx2.getValue(); 
+  if (pDx3.getValue() > pDx) pDx = pDx3.getValue(); 
+  if (pDx4.getValue() > pDx) pDx = pDx4.getValue(); 
+  if (pDy2.getValue() > pDy) pDy = pDy2.getValue(); 
+  float TthetaCphi = FTAN(pTheta.getValue())*FCOS(pPhi.getValue());
+  float TthetaSphi = FTAN(pTheta.getValue())*FSIN(pPhi.getValue());
+  float Xalp = FFABS(std::tan(pAlp1.getValue())*pDy1.getValue());
+  float Xalp2 = FFABS(std::tan(pAlp2.getValue())*pDy2.getValue());
+  if (Xalp< Xalp2) Xalp=Xalp2;
+  pDx += FFABS(TthetaCphi*pDz.getValue());
+  pDx += Xalp;
+  pDy += FFABS(TthetaSphi*pDz.getValue());  
+
+
+  center.setValue(0,0,0);
+  box.setBounds(SbVec3f(-pDx,-pDy,-pDz.getValue()),
+	  SbVec3f( pDx, pDy, pDz.getValue()));
+}
+
+
+
+
+// updateChildren
+void SoTrap::updateChildren() {
+
+
+  // Redraw the G4Trap....
+
+  assert(children->getLength()==1);
+  SoSeparator       *sep                = (SoSeparator *)  ( *children)[0];
+  SoCoordinate3     *theCoordinates     = (SoCoordinate3 *)      ( sep->getChild(0));
+  SoNormal          *theNormals         = (SoNormal *)           ( sep->getChild(1)); 
+  SoNormalBinding   *theNormalBinding   = (SoNormalBinding *)    ( sep->getChild(2));
+  SoIndexedFaceSet  *theFaceSet         = (SoIndexedFaceSet *)   ( sep->getChild(3));
+
+  const int NPOINTS=8, NFACES=6, NINDICES = NFACES*5;
+  float points[NPOINTS][3];
+  // Indices for the eight faces
+#ifdef INVENTOR2_0
+  static long  
+#else 
+  static int32_t
+#endif
+  indices[NINDICES] = {3,2,1,0, SO_END_FACE_INDEX, // bottom
+                     4,5,6,7, SO_END_FACE_INDEX, // top
+                     0,1,5,4, SO_END_FACE_INDEX, 
+                     1,2,6,5, SO_END_FACE_INDEX,
+                     2,3,7,6, SO_END_FACE_INDEX,
+                     3,0,4,7, SO_END_FACE_INDEX};
+
+  
+  // points for the eight vertices
+  float TthetaCphi = FTAN(pTheta.getValue())*FCOS(pPhi.getValue());
+  float TthetaSphi = FTAN(pTheta.getValue())*FSIN(pPhi.getValue());
+  float Talp1 = FTAN(pAlp1.getValue()); 
+  float Talp2 = FTAN(pAlp2.getValue());
+
+  points[0][0] =  pDx2.getValue()+pDy1.getValue()*Talp1;
+  points[0][1] =  pDy1.getValue();
+  points[0][2] = -pDz.getValue();
+
+  points[1][0] = -pDx2.getValue()+pDy1.getValue()*Talp1;
+  points[1][1] =  pDy1.getValue();
+  points[1][2] = -pDz.getValue();
+
+  points[2][0] = -pDx1.getValue()-pDy1.getValue()*Talp1;
+  points[2][1] = -pDy1.getValue();
+  points[2][2] = -pDz.getValue();
+
+  points[3][0] =  pDx1.getValue()-pDy1.getValue()*Talp1;
+  points[3][1] = -pDy1.getValue();
+  points[3][2] = -pDz.getValue();
+
+  points[4][0] =  pDx4.getValue()+pDy2.getValue()*Talp2;
+  points[4][1] =  pDy2.getValue();
+  points[4][2] =  pDz.getValue();
+
+  points[5][0] = -pDx4.getValue()+pDy2.getValue()*Talp2;
+  points[5][1] =  pDy2.getValue();
+  points[5][2] =  pDz.getValue();
+
+  points[6][0] = -pDx3.getValue()-pDy2.getValue()*Talp2;
+  points[6][1] = -pDy2.getValue();
+  points[6][2] =  pDz.getValue();
+
+  points[7][0] =  pDx3.getValue()-pDy2.getValue()*Talp2;
+  points[7][1] = -pDy2.getValue();
+  points[7][2] =  pDz.getValue();
+
+  int i;
+  for (i=0;i<4;i++) {
+    points[i][0] -= pDz.getValue()*TthetaCphi;
+    points[i][1] -= pDz.getValue()*TthetaSphi;
+  }
+  for (i=4;i<8;i++) {
+    points[i][0] += pDz.getValue()*TthetaCphi;
+    points[i][1] += pDz.getValue()*TthetaSphi;
+  }
+
+  for (int np=0;np<NPOINTS;np++) theCoordinates->point.set1Value(np,points[np][0],points[np][1],points[np][2]);
+  theFaceSet->coordIndex.setValues(0,NINDICES,indices);
+  theNormals->vector.deleteValues(0);
+  theNormals->vector.insertSpace(0,6);
+  for (int n=0;n<6;n++) {
+    int i0 = 5*n+0,i1=5*n+1,i2=5*n+2;
+    int j0 = theFaceSet->coordIndex[i0];
+    int j1 = theFaceSet->coordIndex[i1];
+    int j2 = theFaceSet->coordIndex[i2];
+    SbVec3f p0= theCoordinates->point[j0]; 
+    SbVec3f p1= theCoordinates->point[j1]; 
+    SbVec3f p2= theCoordinates->point[j2]; 
+    SbVec3f normal = (p1-p0).cross(p2-p0);
+    normal.normalize();
+    theNormals->vector.set1Value(n,normal);
+  }
+  theNormalBinding->value=SoNormalBinding::PER_FACE;
+}
+
+// generateChildren
+void SoTrap::generateChildren() {
+
+  // This routines creates one SoSeparator, one SoCoordinate3, and
+  // one SoLineSet, and puts it in the child list.  This is done only
+  // once, whereas redrawing the position of the coordinates occurs each
+  // time an update is necessary, in the updateChildren routine. 
+
+  assert(children->getLength() ==0);
+  SoSeparator      *sep              = new SoSeparator(); 
+  SoCoordinate3    *theCoordinates   = new SoCoordinate3();
+  SoNormal         *theNormals       = new SoNormal(); 
+  SoNormalBinding  *theNormalBinding = new SoNormalBinding();
+  SoIndexedFaceSet *theFaceSet       = new SoIndexedFaceSet();
+  // 
+  // This line costs some in render quality! but gives speed.
+  // 
+  sep->addChild(theCoordinates);
+  sep->addChild(theNormals);
+  sep->addChild(theNormalBinding);
+  sep->addChild(theFaceSet);
+  children->append(sep);
+}
+
+// generateAlternateRep
+void SoTrap::generateAlternateRep() {
+
+  // This routine sets the alternate representation to the child
+  // list of this mode.  
+
+  if (children->getLength() == 0) generateChildren();
+  updateChildren();
+  alternateRep.setValue((SoSeparator *)  ( *children)[0]);
+}
+
+// clearAlternateRep
+void SoTrap::clearAlternateRep() {
+  alternateRep.setValue(NULL);
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/SoTrd.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/SoTrd.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/SoTrd.cc	(revision 529)
@@ -0,0 +1,347 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+//
+// $Id: SoTrd.cc,v 1.8 2006/06/29 21:23:05 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+/*-----------------------------HEPVis---------------------------------------*/
+/*                                                                          */
+/* Node:             SoTrd                                                  */
+/* Description:      Represents the G4Trd Geant Geometry entity             */
+/* Author:           Joe Boudreau Nov 11 1996                               */
+/*                                                                          */
+/*--------------------------------------------------------------------------*/
+
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+#include <assert.h>
+#include <cmath>
+
+#include <Inventor/SbBox.h>
+#include <Inventor/actions/SoAction.h>
+#include <Inventor/fields/SoSFFloat.h>
+#include <Inventor/misc/SoChildList.h>
+#include <Inventor/nodes/SoSeparator.h>
+#include <Inventor/nodes/SoIndexedFaceSet.h>
+#include <Inventor/nodes/SoNormal.h>
+#include <Inventor/nodes/SoCoordinate3.h>
+#include <Inventor/nodes/SoNormalBinding.h>
+#include <Inventor/SoPrimitiveVertex.h>
+#include <Inventor/elements/SoTextureCoordinateElement.h>
+
+#include "HEPVis/SbMath.h"
+#include "HEPVis/nodes/SoTrd.h"
+
+// This statement is required
+SO_NODE_SOURCE(SoTrd)
+
+// initClass
+void SoTrd::initClass(){
+  SO_NODE_INIT_CLASS(SoTrd,SoShape,"Shape");
+}
+// Constructor
+SoTrd::SoTrd() {
+  // This statement is required
+  SO_NODE_CONSTRUCTOR(SoTrd);
+  // Data fields are initialized like this:
+  SO_NODE_ADD_FIELD(fDx1,(1.0));
+  SO_NODE_ADD_FIELD(fDx2,(1.0));
+  SO_NODE_ADD_FIELD(fDy1,(1.0));
+  SO_NODE_ADD_FIELD(fDy2,(1.0));
+  SO_NODE_ADD_FIELD(fDz,(1.0));
+  SO_NODE_ADD_FIELD(alternateRep,(NULL));
+  children = new SoChildList(this);
+}
+// Destructor
+SoTrd::~SoTrd() {
+  delete children;
+}
+// generatePrimitives
+void SoTrd::generatePrimitives(SoAction *action) {
+  // This variable is used to store each vertex
+  SoPrimitiveVertex pv;
+
+  // Access the stat from the action
+  SoState *state = action->getState();
+
+  // See if we have to use a texture coordinate function,
+  // rather than generating explicit texture coordinates.
+  SbBool useTexFunction=
+    (SoTextureCoordinateElement::getType(state) == 
+     SoTextureCoordinateElement::FUNCTION);
+
+  // If we need to generate texture coordinates with a function,
+  // we'll need an SoGLTextureCoordinateElement.  Otherwise, we'll
+  // set up the coordinates directly.
+  const SoTextureCoordinateElement *tce = NULL;
+  SbVec4f texCoord;
+  if (useTexFunction) {
+    tce = SoTextureCoordinateElement::getInstance(state);
+  }
+  else {
+    texCoord[2] = 0.0;
+    texCoord[3] = 1.0;
+  }
+  SbVec3f point, normal;
+
+
+  //////////////////////////////////////////
+  //----------------------------------------
+#define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz)  \
+  point.setValue(x,y,z);                   \
+  normal.setValue(nx,ny,nz);               \
+  if (useTexFunction) {                    \
+    texCoord=tce->get(point,normal);       \
+  }                                        \
+  else {                                   \
+    texCoord[0]=s;                         \
+    texCoord[1]=t;                         \
+  }                                        \
+  pv.setPoint(point);                      \
+  pv.setNormal(normal);                    \
+  pv.setTextureCoords(texCoord);           \
+  shapeVertex(&pv);
+  //----------------------------------------
+  //////////////////////////////////////////
+
+  const int NPOINTS=8, NFACES=6, NINDICES = NFACES*5;
+  int indices[NINDICES] = {3,2,1,0, SO_END_FACE_INDEX,  //z back.
+			   4,5,6,7, SO_END_FACE_INDEX,  //z front.
+			   0,1,5,4, SO_END_FACE_INDEX,  //y up.
+			   1,2,6,5, SO_END_FACE_INDEX,  //x left.
+			   2,3,7,6, SO_END_FACE_INDEX,  //y down.
+			   3,0,4,7, SO_END_FACE_INDEX}; //x right.
+
+  
+  // points for the eight vertices
+  float points[NPOINTS][3];
+  points[0][0] =  fDx1.getValue(); 
+  points[0][1] =  fDy1.getValue(); 
+  points[0][2] = -fDz.getValue();
+
+  points[1][0] = -fDx1.getValue();
+  points[1][1] =  fDy1.getValue();
+  points[1][2] = -fDz.getValue();
+
+  points[2][0] = -fDx1.getValue(); 
+  points[2][1] = -fDy1.getValue(); 
+  points[2][2] = -fDz.getValue();
+
+  points[3][0] =  fDx1.getValue(); 
+  points[3][1] = -fDy1.getValue(); 
+  points[3][2] = -fDz.getValue();
+
+  points[4][0] =  fDx2.getValue(); 
+  points[4][1] =  fDy2.getValue(); 
+  points[4][2] =  fDz.getValue();
+
+  points[5][0] = -fDx2.getValue(); 
+  points[5][1] =  fDy2.getValue(); 
+  points[5][2] =  fDz.getValue();
+
+  points[6][0] = -fDx2.getValue(); 
+  points[6][1] = -fDy2.getValue(); 
+  points[6][2] =  fDz.getValue();
+
+  points[7][0] =  fDx2.getValue(); 
+  points[7][1] = -fDy2.getValue(); 
+  points[7][2] =  fDz.getValue();
+
+  float t1  = FATAN((fDx2.getValue()-fDx1.getValue())/(2*fDz.getValue()));
+  float t2  = FATAN((fDy2.getValue()-fDy1.getValue())/(2*fDz.getValue()));
+  float st1 = FSIN(t1);
+  float st2 = FSIN(t2);
+  float ct1 = FCOS(t1);
+  float ct2 = FCOS(t2);
+
+  float normals[NFACES][3];
+  //z back.
+  normals[0][0] = 0   ; normals[0][1] =    0; normals [0][2] =  -1;    
+  //z front.
+  normals[1][0] = 0   ; normals[1][1] =    0; normals [1][2] =   1;    
+  //y up.
+  normals[2][0] = 0   ; normals[2][1] =  ct2; normals [2][2] = -st2;    
+  //x left.
+  normals[3][0] = -ct1; normals[3][1] =    0; normals [3][2] = -st1;    
+  //y down.
+  normals[4][0] = 0   ; normals[4][1] = -ct2; normals [4][2] = -st2;    
+  //x right.
+  normals[5][0] =  ct1; normals[5][1] =    0; normals [5][2] = -st1;    
+
+  float x,y,z;
+  int   index;
+  for (int nf=0;nf<NFACES;nf++) {
+    beginShape(action,TRIANGLE_FAN);
+    index = indices[nf * 5];   
+    x = points[index][0];
+    y = points[index][1];
+    z = points[index][2];
+    GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
+    index = indices[nf * 5 + 1];   
+    x = points[index][0];
+    y = points[index][1];
+    z = points[index][2];
+    GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
+    index = indices[nf * 5 + 2];   
+    x = points[index][0];
+    y = points[index][1];
+    z = points[index][2];
+    GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
+    index = indices[nf * 5 + 3];   
+    x = points[index][0];
+    y = points[index][1];
+    z = points[index][2];
+    GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
+    endShape();
+  }
+}
+
+// getChildren
+SoChildList *SoTrd::getChildren() const {
+  return children;
+}
+
+
+// computeBBox
+void SoTrd::computeBBox(SoAction *, SbBox3f &box, SbVec3f &center ){
+  float fDx= fDx1.getValue(),fDy=fDy1.getValue();
+  
+  if (fDx2.getValue() > fDx) fDx = fDx2.getValue(); 
+  if (fDy2.getValue() > fDy) fDy = fDy2.getValue(); 
+
+  SbVec3f vmin(-fDx,-fDy,-fDz.getValue()), 
+          vmax( fDx, fDy, fDz.getValue());
+
+  center.setValue(0,0,0);
+  box.setBounds(vmin,vmax);
+}
+
+
+
+
+// updateChildren
+void SoTrd::updateChildren() {
+
+
+  // Redraw the G4Trd....
+
+  assert(children->getLength()==1);
+  SoSeparator       *sep                = (SoSeparator *)  ( *children)[0];
+  SoCoordinate3     *theCoordinates     = (SoCoordinate3 *)      ( sep->getChild(0));
+  SoNormal          *theNormals         = (SoNormal *)           ( sep->getChild(1)); 
+  SoNormalBinding   *theNormalBinding   = (SoNormalBinding *)    ( sep->getChild(2));
+  SoIndexedFaceSet  *theFaceSet         = (SoIndexedFaceSet *)   ( sep->getChild(3));
+
+  const int NPOINTS=8, NFACES=6, NINDICES = NFACES*5;
+  float points[NPOINTS][3];
+  float normals[NFACES][3]= {{0,0,-1}, {0,0,1}, {0,1,0}, {-1, 0, 0}, {0, -1, 0}, {1,0,0}};
+
+  // Indices for the eight faces
+#ifdef INVENTOR2_0
+  static long  
+#else 
+  static int32_t
+#endif
+  indices[NINDICES] = {3,2,1,0, SO_END_FACE_INDEX, // bottom
+                                       4,5,6,7, SO_END_FACE_INDEX, // top
+                                       0,1,5,4, SO_END_FACE_INDEX, 
+                                       1,2,6,5, SO_END_FACE_INDEX,
+                                       2,3,7,6, SO_END_FACE_INDEX,
+                                       3,0,4,7, SO_END_FACE_INDEX};
+
+  
+  // points for the eight vertices
+  points[0][0] =  fDx1.getValue(); points[0][1] =  fDy1.getValue(); points[0][2] = -fDz.getValue();
+  points[1][0] = -fDx1.getValue(); points[1][1] =  fDy1.getValue(); points[1][2] = -fDz.getValue();
+  points[2][0] = -fDx1.getValue(); points[2][1] = -fDy1.getValue(); points[2][2] = -fDz.getValue();
+  points[3][0] =  fDx1.getValue(); points[3][1] = -fDy1.getValue(); points[3][2] = -fDz.getValue();
+  points[4][0] =  fDx2.getValue(); points[4][1] =  fDy2.getValue(); points[4][2] =  fDz.getValue();
+  points[5][0] = -fDx2.getValue(); points[5][1] =  fDy2.getValue(); points[5][2] =  fDz.getValue();
+  points[6][0] = -fDx2.getValue(); points[6][1] = -fDy2.getValue(); points[6][2] =  fDz.getValue();
+  points[7][0] =  fDx2.getValue(); points[7][1] = -fDy2.getValue(); points[7][2] =  fDz.getValue();
+
+  float t1 = FATAN((fDx2.getValue()-fDx1.getValue())/(2*fDz.getValue()));
+  float t2 = FATAN((fDy2.getValue()-fDy1.getValue())/(2*fDz.getValue()));
+  float st1 = FSIN(t1);
+  float st2 = FSIN(t2);
+  float ct1 = FCOS(t1);
+  float ct2 = FCOS(t2);
+
+  normals[0][0] = 0   ; normals[0][1] =    0; normals [0][2] =  -1;    
+  normals[1][0] = 0   ; normals[1][1] =    0; normals [1][2] =   1;    
+  normals[2][0] = 0   ; normals[2][1] =  ct2; normals [2][2] = -st2;    
+  normals[3][0] = -ct1; normals[3][1] =    0; normals [3][2] = -st1;    
+  normals[4][0] = 0   ; normals[4][1] = -ct2; normals [4][2] = -st2;    
+  normals[5][0] =  ct1; normals[5][1] =    0; normals [5][2] = -st1;    
+
+  for (int np=0;np<NPOINTS;np++) theCoordinates->point.set1Value(np,points[np][0],points[np][1],points[np][2]);
+  theFaceSet->coordIndex.setValues(0,NINDICES,indices);
+  for (int nf=0;nf<NFACES;nf++) theNormals->vector.set1Value(nf,normals[nf][0],normals[nf][1],normals[nf][2]);
+  theNormalBinding->value=SoNormalBinding::PER_FACE;
+}
+
+// generateChildren
+void SoTrd::generateChildren() {
+
+  // This routines creates one SoSeparator, one SoCoordinate3, and
+  // one SoLineSet, and puts it in the child list.  This is done only
+  // once, whereas redrawing the position of the coordinates occurs each
+  // time an update is necessary, in the updateChildren routine. 
+
+  assert(children->getLength() ==0);
+  SoSeparator      *sep              = new SoSeparator(); 
+  SoCoordinate3    *theCoordinates   = new SoCoordinate3();
+  SoNormal         *theNormals       = new SoNormal(); 
+  SoNormalBinding  *theNormalBinding = new SoNormalBinding();
+  SoIndexedFaceSet *theFaceSet       = new SoIndexedFaceSet();
+  // 
+  // This line costs some in render quality! but gives speed.
+  // 
+  sep->addChild(theCoordinates);
+  sep->addChild(theNormals);
+  sep->addChild(theNormalBinding);
+  sep->addChild(theFaceSet);
+  children->append(sep);
+}
+
+// generateAlternateRep
+void SoTrd::generateAlternateRep() {
+
+  // This routine sets the alternate representation to the child
+  // list of this mode.  
+
+  if (children->getLength() == 0) generateChildren();
+  updateChildren();
+  alternateRep.setValue((SoSeparator *)  ( *children)[0]);
+}
+
+// clearAlternateRep
+void SoTrd::clearAlternateRep() {
+  alternateRep.setValue(NULL);
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/SoTubs.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/SoTubs.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/SoTubs.cc	(revision 529)
@@ -0,0 +1,473 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+//
+//
+// $Id: SoTubs.cc,v 1.8 2006/06/29 21:23:07 gunter Exp $
+// GEANT4 tag $Name: geant4-08-01-patch-01 $
+//
+/*-----------------------------HEPVis---------------------------------------*/
+/*                                                                          */
+/* Node:             SoTubs                                                 */
+/* Description:      Represents the G4Tubs Geant Geometry entity            */
+/* Author:           Joe Boudreau Nov 11 1996                               */
+/*                                                                          */
+/*--------------------------------------------------------------------------*/
+
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+// this :
+#include "HEPVis/nodes/SoTubs.h"
+
+#include <assert.h>
+#include <cmath>
+
+#include <Inventor/SbBox.h>
+#include <Inventor/actions/SoGLRenderAction.h>
+#include <Inventor/fields/SoSFFloat.h>
+#include <Inventor/misc/SoChildList.h>
+#include <Inventor/nodes/SoSeparator.h>
+#include <Inventor/nodes/SoIndexedFaceSet.h>
+#include <Inventor/nodes/SoNormal.h>
+#include <Inventor/nodes/SoCoordinate3.h>
+#include <Inventor/nodes/SoNormalBinding.h>
+#include <Inventor/SoPrimitiveVertex.h>
+#include <Inventor/elements/SoTextureCoordinateElement.h>
+
+#include "HEPVis/SbMath.h"
+
+// This statement is required
+SO_NODE_SOURCE(SoTubs)
+
+// Constructor
+SoTubs::SoTubs() {
+
+
+  // This statement is required
+  SO_NODE_CONSTRUCTOR(SoTubs);
+
+  // Data fields are initialized like this:
+  SO_NODE_ADD_FIELD(pRMin,               (0));
+  SO_NODE_ADD_FIELD(pRMax,               (1));
+  SO_NODE_ADD_FIELD(pDz,                 (10));
+  SO_NODE_ADD_FIELD(pSPhi,               (0));
+  SO_NODE_ADD_FIELD(pDPhi,               ((float)(2*M_PI)));
+  SO_NODE_ADD_FIELD(alternateRep,        (NULL));
+  children = new SoChildList(this);
+}
+
+// Destructor
+SoTubs::~SoTubs() {
+  delete children;
+}
+
+
+// initClass
+void SoTubs::initClass(){
+  // This statement is required.
+  SO_NODE_INIT_CLASS(SoTubs,SoShape,"Shape");
+}
+
+// generatePrimitives
+void SoTubs::generatePrimitives(SoAction *action) {
+  // This variable is used to store each vertex
+  SoPrimitiveVertex pv;
+
+  // Access the stat from the action
+  SoState *state = action->getState();
+
+  // See if we have to use a texture coordinate function,
+  // rather than generating explicit texture coordinates.
+  SbBool useTexFunction=
+    (SoTextureCoordinateElement::getType(state) == 
+     SoTextureCoordinateElement::FUNCTION);
+
+  // If we need to generate texture coordinates with a function,
+  // we'll need an SoGLTextureCoordinateElement.  Otherwise, we'll
+  // set up the coordinates directly.
+  const SoTextureCoordinateElement* tce = NULL;
+  SbVec4f texCoord;
+  if (useTexFunction) {
+    tce = SoTextureCoordinateElement::getInstance(state);
+  }
+  else {
+    texCoord[2] = 0.0;
+    texCoord[3] = 1.0;
+  }
+  SbVec3f point, normal;
+
+
+  ///////////////////////////////////////////////////////
+  //-----------------------------------------------------
+#define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz)               \
+  point.setValue((float)(x),(float)(y),(float)(z));     \
+  normal.setValue((float)(nx),(float)(ny),(float)(nz)); \
+  if (useTexFunction) {                                 \
+    texCoord=tce->get(point,normal);                    \
+  } else {                                              \
+    texCoord[0]=(float)(s);                             \
+    texCoord[1]=(float)(t);                             \
+  }                                                     \
+  pv.setPoint(point);                                   \
+  pv.setNormal(normal);                                 \
+  pv.setTextureCoords(texCoord);                        \
+  shapeVertex(&pv);
+  //-----------------------------------------------------
+  ///////////////////////////////////////////////////////
+
+  int NPHI = (int)(2+22*std::fabs(pDPhi.getValue()/(2.0*M_PI)));
+  double deltaPhi = pDPhi.getValue()/NPHI, phi0 = pSPhi.getValue(),phi1=phi0+pDPhi.getValue();
+  double rMax=pRMax.getValue(),rMin=pRMin.getValue();
+  double zMax=pDz.getValue(),zMin=-zMax;
+  double cosPhi0=std::cos(phi0), sinPhi0=std::sin(phi0);
+  double cosPhi1=std::cos(phi1), sinPhi1=std::sin(phi1);
+  double cosDeltaPhi=std::cos(deltaPhi),sinDeltaPhi=std::sin(deltaPhi);
+  //
+  // The outer surface!
+  //
+  int i;
+  double sinPhi,cosPhi;
+  beginShape(action,TRIANGLE_STRIP);
+  sinPhi=sinPhi0;
+  cosPhi=cosPhi0;
+  for (i = 0; i<=NPHI; i++) {
+    GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMax,0.0,0.0,cosPhi,sinPhi,0);   
+    GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMin,1.0,1.0,cosPhi,sinPhi,0);   
+    inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);    
+  }
+  endShape();
+  //
+  // The inner surface!
+  //
+  if(rMin!=0.F) {
+    beginShape(action,TRIANGLE_STRIP);
+    sinPhi=sinPhi0;
+    cosPhi=cosPhi0;
+    for (i = 0; i<=NPHI; i++) {
+      GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMax,0.0,0.0,-cosPhi,-sinPhi,0);   
+      GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMin,1.0,1.0,-cosPhi,-sinPhi,0);   
+      inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);    
+    } 
+    endShape();
+  }
+  if (std::fabs(deltaPhi)<2.0*M_PI) { 
+    //
+    // The end 
+    //
+    beginShape(action,TRIANGLE_STRIP);
+    sinPhi=sinPhi0;
+    cosPhi=cosPhi0;
+    GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMax,0.0,0.0,sinPhi,-cosPhi,0);   
+    GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMin,1.0,1.0,sinPhi,-cosPhi,0);   
+    GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMax,1.0,0.0,sinPhi,-cosPhi,0);   
+    GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMin,0.0,1.0,sinPhi,-cosPhi,0);   
+    endShape();
+    //
+    // The other end 
+    //
+    beginShape(action,TRIANGLE_STRIP);
+    sinPhi=sinPhi1;
+    cosPhi=cosPhi1;
+    GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi, zMax,0.0,0.0,-sinPhi,+cosPhi,0);   
+    GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi, zMin,1.0,1.0,-sinPhi,+cosPhi,0);   
+    GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi, zMax,1.0,0.0,-sinPhi,+cosPhi,0);   
+    GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi, zMin,0.0,1.0,-sinPhi,+cosPhi,0);   
+    endShape();
+  }
+  //
+  // The outer surface at z=+PDZ
+  //
+  if(rMin==0.F) {
+    beginShape(action,TRIANGLE_FAN);
+    sinPhi=sinPhi0;
+    cosPhi=cosPhi0;
+    GEN_VERTEX(pv,0,0,zMax,0.0,0.0,0,0,1);   
+    for (i = 0; i<=NPHI; i++) {
+      GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMax,1.0,1.0,0,0,1);   
+      inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);    
+    }
+    endShape();
+    //
+    // The outer surface at z=-PDZ
+    //
+    beginShape(action,TRIANGLE_FAN);
+    sinPhi=sinPhi0;
+    cosPhi=cosPhi0;
+    GEN_VERTEX(pv,0,0,zMin,0.0,0.0,0,0,-1);   
+    for (i = 0; i<=NPHI; i++) {
+      GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMin,1.0,1.0,0,0,-1);   
+      inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);    
+    }
+    endShape();
+  } else {
+    beginShape(action,TRIANGLE_STRIP);
+    sinPhi=sinPhi0;
+    cosPhi=cosPhi0;
+    for (i = 0; i<=NPHI; i++) {
+      GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMax,0.0,0.0,0,0,1);   
+      GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMax,1.0,1.0,0,0,1);   
+      inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);    
+    }
+    endShape();
+    //
+    // The outer surface at z=-PDZ
+    //
+    beginShape(action,TRIANGLE_STRIP);
+    sinPhi=sinPhi0;
+    cosPhi=cosPhi0;
+    for (i = 0; i<=NPHI; i++) {
+      GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMin,0.0,0.0,0,0,-1);   
+      GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMin,1.0,1.0,0,0,-1);   
+      inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);    
+    }
+    endShape();
+  }
+}
+
+// getChildren
+SoChildList *SoTubs::getChildren() const {
+  return children;
+}
+
+
+// computeBBox
+void SoTubs::computeBBox(SoAction *, SbBox3f &box, SbVec3f &center ){
+  SbVec3f vmin(-pRMax.getValue(),-pRMax.getValue(),-pDz.getValue()), 
+          vmax( pRMax.getValue(), pRMax.getValue(), pDz.getValue());
+  center.setValue(0,0,0);
+  box.setBounds(vmin,vmax);
+}
+
+
+// updateChildren
+void SoTubs::updateChildren() {
+
+  // Redraw the G4Tubs....
+
+  assert(children->getLength()==1);
+  SoSeparator       *sep                = (SoSeparator *)  ( *children)[0];
+  SoCoordinate3     *theCoordinates     = (SoCoordinate3 *)      ( sep->getChild(0));
+  SoNormal          *theNormals         = (SoNormal *)           ( sep->getChild(1)); 
+  SoNormalBinding   *theNormalBinding   = (SoNormalBinding *)    ( sep->getChild(2));
+  SoIndexedFaceSet  *theFaceSet         = (SoIndexedFaceSet *)   ( sep->getChild(3));
+  
+  
+  const int NPHI=24, NPOINTS=2*(2*NPHI+2), NFACES=4*NPHI+2, NINDICES = NFACES*5;
+  float points[NPOINTS][3],normals[NFACES][3];
+#ifdef INVENTOR2_0
+  static long     indices[NINDICES];
+#else
+  static int32_t  indices[NINDICES];
+#endif
+    
+  static int init=0;
+  double phi, pp, DeltaPhi;
+    
+  // Indices need to be generated once! This is here to keep it close to the point
+  // generation, since otherwise it will be confusing.
+    
+  int i;
+  if (!init) {
+    init = 1;
+    // Outer face
+    for (i = 0; i< NPHI; i++) {
+      // 0 1 3 2;
+      indices[5*i+0] =  2*i+0;
+      indices[5*i+1] =  2*i+1;
+      indices[5*i+2] =  2*i+3;
+      indices[5*i+3] =  2*i+2;
+      indices[5*i+4] = SO_END_FACE_INDEX;
+    }
+    // the inner face
+    for (i=0;i<NPHI;i++) {
+      indices[5*1*NPHI + 5*i+0] = 2*NPHI+2 + 2*i+0;  
+      indices[5*1*NPHI + 5*i+1] = 2*NPHI+2 + 2*i+1;
+      indices[5*1*NPHI + 5*i+2] = 2*NPHI+2 + 2*i+3;
+      indices[5*1*NPHI + 5*i+3] = 2*NPHI+2 + 2*i+2;
+      indices[5*1*NPHI + 5*i+4] = SO_END_FACE_INDEX;
+    }
+    // the top side
+    for (i=0;i<NPHI;i++) {
+      indices[5*2*NPHI + 5*i+0] = 2*i+0;
+      indices[5*2*NPHI + 5*i+1] = 2*i+2;
+      indices[5*2*NPHI + 5*i+2] = NPOINTS - (2*i+4);
+      indices[5*2*NPHI + 5*i+3] = NPOINTS - (2*i+2);
+      indices[5*2*NPHI + 5*i+4] = SO_END_FACE_INDEX;
+    }
+    // the bottom side
+    for (i=0;i<NPHI;i++) {
+      indices[5*3*NPHI + 5*i+0] = 2*i+1;
+      indices[5*3*NPHI + 5*i+1] = NPOINTS - (2*i+1);
+      indices[5*3*NPHI + 5*i+2] = NPOINTS - (2*i+3);
+      indices[5*3*NPHI + 5*i+3] = 2*i+3;
+      indices[5*3*NPHI + 5*i+4] = SO_END_FACE_INDEX;
+    }
+    // the odd side
+    indices[5*4*NPHI +0] = 2*NPHI;
+    indices[5*4*NPHI +1] = 2*NPHI+1;
+    indices[5*4*NPHI +2] = 2*NPHI+3;
+    indices[5*4*NPHI +3] = 2*NPHI+2;
+    indices[5*4*NPHI +4] = SO_END_FACE_INDEX;
+    // aother odd side
+    indices[5*4*NPHI +5 +0] = 0;
+    indices[5*4*NPHI +5 +1] = NPOINTS-2;
+    indices[5*4*NPHI +5 +2] = NPOINTS-1;
+    indices[5*4*NPHI +5 +3] = 1;
+    indices[5*4*NPHI +5 +4] = SO_END_FACE_INDEX;
+  }
+  // Points need to be generated each time:
+  if (pDPhi.getValue()<2*M_PI) {
+    // the odd side
+    indices[5*4*NPHI +0] = 2*NPHI;
+    indices[5*4*NPHI +1] = 2*NPHI+1;
+    indices[5*4*NPHI +2] = 2*NPHI+3;
+    indices[5*4*NPHI +3] = 2*NPHI+2;
+    indices[5*4*NPHI +4] = SO_END_FACE_INDEX;
+    // aother odd side
+    indices[5*4*NPHI +5 +0] = 0;
+    indices[5*4*NPHI +5 +1] = NPOINTS-2;
+    indices[5*4*NPHI +5 +2] = NPOINTS-1;
+    indices[5*4*NPHI +5 +3] = 1;
+    indices[5*4*NPHI +5 +4] = SO_END_FACE_INDEX;
+  } 
+  else {
+    // the odd side
+    indices[5*4*NPHI +0] = SO_END_FACE_INDEX;
+    indices[5*4*NPHI +1] = SO_END_FACE_INDEX;
+    indices[5*4*NPHI +2] = SO_END_FACE_INDEX;
+    indices[5*4*NPHI +3] = SO_END_FACE_INDEX;
+    indices[5*4*NPHI +4] = SO_END_FACE_INDEX;
+    // aother odd side
+    indices[5*4*NPHI +5 +0] = SO_END_FACE_INDEX;
+    indices[5*4*NPHI +5 +1] = SO_END_FACE_INDEX;
+    indices[5*4*NPHI +5 +2] = SO_END_FACE_INDEX;
+    indices[5*4*NPHI +5 +3] = SO_END_FACE_INDEX;
+    indices[5*4*NPHI +5 +4] = SO_END_FACE_INDEX;
+  }
+  // The outer surface
+  DeltaPhi = pDPhi.getValue()/NPHI, phi = pSPhi.getValue();
+  for (i = 0; i<=NPHI; i++) {
+    points[2*i+0][0] = pRMax.getValue()*FCOS(phi); 
+    points[2*i+0][1]= pRMax.getValue()*FSIN(phi); 
+    points[2*i+0][2] = +pDz.getValue();
+
+    points[2*i+1][0] = pRMax.getValue()*FCOS(phi); 
+    points[2*i+1][1]= pRMax.getValue()*FSIN(phi); 
+    points[2*i+1][2] = -pDz.getValue();
+
+    pp = phi+DeltaPhi/2.0;
+    if (i!=NPHI) {
+      normals[i][0] = FCOS(pp); 
+      normals[i][1] = FSIN(pp); 
+      normals[i][2] = 0;
+    }
+    phi+=DeltaPhi;
+  }
+  // The inner surface
+  phi = pSPhi.getValue() + pDPhi.getValue();
+  for (i = 0; i<=NPHI; i++) {
+    points[2*NPHI+2+2*i+0][0] = pRMin.getValue()*FCOS(phi); 
+    points[2*NPHI+2+2*i+0][1] = pRMin.getValue()*FSIN(phi); 
+    points[2*NPHI+2+2*i+0][2] = +pDz.getValue();
+    points[2*NPHI+2+2*i+1][0] = pRMin.getValue()*FCOS(phi); 
+    points[2*NPHI+2+2*i+1][1] = pRMin.getValue()*FSIN(phi); 
+    points[2*NPHI+2+2*i+1][2] = -pDz.getValue();
+    pp = phi-DeltaPhi/2.0;
+    if (i!=NPHI) {
+      normals[NPHI+i][0] = -FCOS(pp); 
+      normals[NPHI+i][1] = -FSIN(pp); 
+      normals[NPHI+i][2] = 0;
+    }
+    phi-=DeltaPhi;
+  }
+  // The top side
+  for (i=0;i<NPHI;i++) {
+    normals[2*NPHI+i][0]=normals[2*NPHI+i][1]=0; 
+    normals[2*NPHI+i][2]=  1.0;
+  } 
+  // The bottom side
+  for (i=0;i<NPHI;i++) {
+    normals[3*NPHI+i][0]=normals[3*NPHI+i][1]=0; 
+    normals[3*NPHI+i][2]= -1.0;
+  } 
+  // The odd side
+  phi = pSPhi.getValue(); 
+  normals[4*NPHI+0][0]=  FSIN(phi); 
+  normals[4*NPHI+0][1]= -FCOS(phi); 
+  normals[4*NPHI+0][2]=0;
+    
+    // Another odd side
+  phi = pSPhi.getValue()+pDPhi.getValue(); 
+  normals[4*NPHI+1][0]= -FSIN(phi); 
+  normals[4*NPHI+1][1]= +FCOS(phi); 
+  normals[4*NPHI+1][2]=0;
+    
+  for (int np=0;np<NPOINTS; np++) theCoordinates->point.set1Value(np,points[np][0],points[np][1],points[np][2]);
+  for (int ni=0;ni<NINDICES;ni++) theFaceSet->coordIndex.set1Value(ni,indices[ni]);
+  for (int nf=0;nf<NFACES;nf++) theNormals->vector.set1Value(nf,normals[nf][0],normals[nf][1],normals[nf][2]);
+  theNormalBinding->value=SoNormalBinding::PER_FACE;
+}
+
+// generateChildren
+void SoTubs::generateChildren() {
+
+  // This routines creates one SoSeparator, one SoCoordinate3, and
+  // one SoLineSet, and puts it in the child list.  This is done only
+  // once, whereas redrawing the position of the coordinates occurs each
+  // time an update is necessary, in the updateChildren routine. 
+
+  assert(children->getLength() ==0);
+  SoSeparator      *sep              = new SoSeparator(); 
+  SoCoordinate3    *theCoordinates   = new SoCoordinate3();
+  SoNormal         *theNormals       = new SoNormal(); 
+  SoNormalBinding  *theNormalBinding = new SoNormalBinding();
+  SoIndexedFaceSet *theFaceSet       = new SoIndexedFaceSet();
+  // 
+  // This line costs some in render quality! but gives speed.
+  // 
+  sep->addChild(theCoordinates);
+  sep->addChild(theNormals);
+  sep->addChild(theNormalBinding);
+  sep->addChild(theFaceSet);
+  children->append(sep);
+}
+
+// generateAlternateRep
+void SoTubs::generateAlternateRep() {
+
+  // This routine sets the alternate representation to the child
+  // list of this mode.  
+
+  if (children->getLength() == 0) generateChildren();
+  updateChildren();
+  alternateRep.setValue((SoSeparator *)  ( *children)[0]);
+}
+
+// clearAlternateRep
+void SoTubs::clearAlternateRep() {
+  alternateRep.setValue(NULL);
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/gl2ps.cc
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/gl2ps.cc	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/gl2ps.cc	(revision 529)
@@ -0,0 +1,2357 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+#ifdef G4VIS_BUILD_OI_DRIVER
+
+/*
+ * GL2PS, an OpenGL to PostScript Printing Library
+ * Copyright (C) 1999-2003  Christophe Geuzaine 
+ *
+ * $Id: gl2ps.cc,v 1.11 2006/06/29 21:23:09 gunter Exp $
+ *
+ * E-mail: geuz@geuz.org
+ * URL: http://www.geuz.org/gl2ps/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <string.h>
+#include <sys/types.h>
+#include <stdarg.h>
+#include <time.h>
+#include "Geant4_gl2ps.h"
+
+/* The gl2ps context. gl2ps is not thread safe (we should create a
+   local GL2PScontext during gl2psBeginPage). */
+
+GL2PScontext *gl2ps = NULL;
+
+/* Some 'system' utility routines */
+
+void gl2psMsg(GLint level, const char *fmt, ...){
+  va_list args;
+
+  if(!(gl2ps->options & GL2PS_SILENT)){
+    switch(level){
+    case GL2PS_INFO : fprintf(stderr, "GL2PS info: "); break;
+    case GL2PS_WARNING : fprintf(stderr, "GL2PS warning: "); break;
+    case GL2PS_ERROR : fprintf(stderr, "GL2PS error: "); break;
+    }
+    va_start(args, fmt);
+    vfprintf(stderr, fmt, args); 
+    va_end(args);
+    fprintf(stderr, "\n");
+  }
+  /*
+    if(level == GL2PS_ERROR) exit(1);
+  */
+}
+
+void *gl2psMalloc(size_t size){
+  void *ptr;
+
+  if(!size) return(NULL);
+  ptr = malloc(size);
+  if(!ptr){
+    gl2psMsg(GL2PS_ERROR, "Couldn't allocate requested memory");
+    exit(1);
+  }
+  return(ptr);
+}
+
+void *gl2psRealloc(void *ptr, size_t size){
+  if(!size) return(NULL);
+  ptr = realloc(ptr, size);
+  if(!ptr){
+    gl2psMsg(GL2PS_ERROR, "Couldn't reallocate requested memory");
+    exit(1);
+  }
+  return(ptr);
+}
+
+void gl2psFree(void *ptr){
+  if(!ptr) return;
+  free(ptr);
+}
+
+/* The list handling routines */
+
+void gl2psListRealloc(GL2PSlist *list, GLint n){
+  if(n <= 0) return;
+  if(!list->array){
+    list->nmax = ((n - 1) / list->incr + 1) * list->incr;
+    list->array = (char *)gl2psMalloc(list->nmax * list->size);
+  }
+  else{
+    if(n > list->nmax){
+      list->nmax = ((n - 1) / list->incr + 1) * list->incr;
+      list->array = (char *)gl2psRealloc(list->array,
+					 list->nmax * list->size);
+    }
+  }
+}
+
+GL2PSlist *gl2psListCreate(GLint n, GLint incr, GLint size){
+  GL2PSlist *list;
+
+  if(n < 0) n = 0;
+  if(incr <= 0) incr = 1;
+  list = (GL2PSlist *)gl2psMalloc(sizeof(GL2PSlist));
+  list->nmax = 0;
+  list->incr = incr;
+  list->size = size;
+  list->n = 0;
+  list->array = NULL;
+  gl2psListRealloc(list, n);
+  return(list);
+}
+
+void gl2psListReset(GL2PSlist *list){
+  list->n = 0;
+}
+
+void gl2psListDelete(GL2PSlist *list){
+  gl2psFree(list->array);
+  gl2psFree(list);
+}
+
+void gl2psListAdd(GL2PSlist *list, void *data){
+  list->n++;
+  gl2psListRealloc(list, list->n);
+  memcpy(&list->array[(list->n - 1) * list->size], data, list->size);
+}
+
+GLint gl2psListNbr(GL2PSlist *list){
+  return(list->n);
+}
+
+void *gl2psListPointer(GL2PSlist *list, GLint index){
+  if((index < 0) || (index >= list->n)){
+    gl2psMsg(GL2PS_ERROR, "Wrong list index in gl2psListPointer");
+    return(&list->array[0]);
+  }
+  return(&list->array[index * list->size]);
+}
+
+void gl2psListSort(GL2PSlist *list,
+		   int (*fcmp)(const void *a, const void *b)){
+  qsort(list->array, list->n, list->size, fcmp);
+}
+
+void gl2psListAction(GL2PSlist *list, 
+		     void (*action)(void *data, void *dummy)){
+  GLint i, dummy;
+
+  for(i = 0; i < gl2psListNbr(list); i++){
+    (*action)(gl2psListPointer(list, i), &dummy);
+  }
+}
+
+void gl2psListActionInverse(GL2PSlist *list, 
+			    void (*action)(void *data, void *dummy)){
+  GLint i, dummy;
+
+  for(i = gl2psListNbr(list); i > 0; i--){
+    (*action)(gl2psListPointer(list, i-1), &dummy);
+  }
+}
+
+/* The 3D sorting routines */
+
+GLfloat gl2psComparePointPlane(GL2PSxyz point, GL2PSplane plane){
+  return(plane[0] * point[0] + 
+	 plane[1] * point[1] + 
+	 plane[2] * point[2] + 
+	 plane[3]);
+}
+
+GLfloat gl2psPsca(GLfloat *a, GLfloat *b){
+  return(a[0]*b[0] + a[1]*b[1] + a[2]*b[2]);
+}
+
+void gl2psPvec(GLfloat *a, GLfloat *b, GLfloat *c){
+  c[0] = a[1]*b[2] - a[2]*b[1];
+  c[1] = a[2]*b[0] - a[0]*b[2];
+  c[2] = a[0]*b[1] - a[1]*b[0];
+}
+
+GLfloat gl2psNorm(GLfloat *a){
+  return std::sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]);
+}
+
+void gl2psGetNormal(GLfloat *a, GLfloat *b, GLfloat *c){
+  GLfloat norm;
+
+  gl2psPvec(a, b, c);
+  if(!GL2PS_ZERO(norm = gl2psNorm(c))){
+    c[0] = c[0] / norm;
+    c[1] = c[1] / norm;
+    c[2] = c[2] / norm;
+  }
+  else{
+    /* The plane is still wrong, despite our tests in
+       gl2psGetPlane... Let's return a dummy value (this is a hack: we
+       should do more tests in GetPlane): */
+    c[0] = c[1] = 0.;
+    c[2] = 1.;
+  }
+}
+
+void gl2psGetPlane(GL2PSprimitive *prim, GL2PSplane plane){
+  GL2PSxyz v = {0., 0., 0.}, w = {0., 0., 0.};
+
+  switch(prim->type){
+  case GL2PS_TRIANGLE :
+  case GL2PS_QUADRANGLE :
+    v[0] = prim->verts[1].xyz[0] - prim->verts[0].xyz[0]; 
+    v[1] = prim->verts[1].xyz[1] - prim->verts[0].xyz[1]; 
+    v[2] = prim->verts[1].xyz[2] - prim->verts[0].xyz[2]; 
+    w[0] = prim->verts[2].xyz[0] - prim->verts[0].xyz[0]; 
+    w[1] = prim->verts[2].xyz[1] - prim->verts[0].xyz[1]; 
+    w[2] = prim->verts[2].xyz[2] - prim->verts[0].xyz[2]; 
+    if((GL2PS_ZERO(v[0]) && GL2PS_ZERO(v[1]) && GL2PS_ZERO(v[2])) || 
+       (GL2PS_ZERO(w[0]) && GL2PS_ZERO(w[1]) && GL2PS_ZERO(w[2]))){
+      plane[0] = plane[1] = 0.;
+      plane[2] = 1.;
+      plane[3] = -prim->verts[0].xyz[2];
+    }
+    else{
+      gl2psGetNormal(v, w, plane);
+      plane[3] = 
+	- plane[0] * prim->verts[0].xyz[0] 
+	- plane[1] * prim->verts[0].xyz[1] 
+	- plane[2] * prim->verts[0].xyz[2];
+    }
+    break;
+  case GL2PS_LINE :
+    v[0] = prim->verts[1].xyz[0] - prim->verts[0].xyz[0]; 
+    v[1] = prim->verts[1].xyz[1] - prim->verts[0].xyz[1]; 
+    v[2] = prim->verts[1].xyz[2] - prim->verts[0].xyz[2]; 
+    if(GL2PS_ZERO(v[0]) && GL2PS_ZERO(v[1]) && GL2PS_ZERO(v[2])){
+      plane[0] = plane[1] = 0.;
+      plane[2] = 1.;
+      plane[3] = -prim->verts[0].xyz[2];
+    }
+    else{
+      if(GL2PS_ZERO(v[0]))      w[0] = 1.;
+      else if(GL2PS_ZERO(v[1])) w[1] = 1.;
+      else                      w[2] = 1.;
+      gl2psGetNormal(v, w, plane);
+      plane[3] = 
+	- plane[0] * prim->verts[0].xyz[0] 
+	- plane[1] * prim->verts[0].xyz[1] 
+	- plane[2] * prim->verts[0].xyz[2];
+    }
+    break;
+  case GL2PS_POINT :
+  case GL2PS_PIXMAP :
+  case GL2PS_TEXT :
+    plane[0] = plane[1] = 0.;
+    plane[2] = 1.;
+    plane[3] = -prim->verts[0].xyz[2];
+    break;
+  default :
+    gl2psMsg(GL2PS_ERROR, "Unknown primitive type in BSP tree");
+    plane[0] = plane[1] = plane[3] = 0.;
+    plane[2] = 1.;
+    break;
+  }
+}
+
+void gl2psCutEdge(GL2PSvertex *a, GL2PSvertex *b, GL2PSplane plane, 
+		  GL2PSvertex *c){
+  GL2PSxyz v;
+  GLfloat sect;
+
+  v[0] = b->xyz[0] - a->xyz[0];
+  v[1] = b->xyz[1] - a->xyz[1];
+  v[2] = b->xyz[2] - a->xyz[2];
+  sect = - gl2psComparePointPlane(a->xyz, plane) / gl2psPsca(plane, v);
+
+  c->xyz[0] = a->xyz[0] + v[0] * sect;
+  c->xyz[1] = a->xyz[1] + v[1] * sect;
+  c->xyz[2] = a->xyz[2] + v[2] * sect;
+  
+  c->rgba[0] = (1.-sect) * a->rgba[0] + sect * b->rgba[0];
+  c->rgba[1] = (1.-sect) * a->rgba[1] + sect * b->rgba[1];
+  c->rgba[2] = (1.-sect) * a->rgba[2] + sect * b->rgba[2];
+  c->rgba[3] = (1.-sect) * a->rgba[3] + sect * b->rgba[3];
+}
+
+void gl2psCreateSplitPrimitive(GL2PSprimitive *parent, GL2PSplane plane,
+			       GL2PSprimitive *child, GLshort numverts,
+			       GLshort *index0, GLshort *index1){
+  GLshort i;
+
+  if(numverts > 4){
+    gl2psMsg(GL2PS_WARNING, "%d vertices in polygon", numverts);
+    numverts = 4;
+  }
+
+  switch(numverts){
+  case 1 : child->type = GL2PS_POINT; break; 
+  case 2 : child->type = GL2PS_LINE; break; 
+  case 3 : child->type = GL2PS_TRIANGLE; break; 
+  case 4 : child->type = GL2PS_QUADRANGLE; break;    
+  }
+  child->boundary = 0; /* not done! */
+  child->depth = parent->depth; /* should not be used in this case */
+  child->culled = parent->culled;
+  child->dash = parent->dash;
+  child->width = parent->width;
+  child->numverts = numverts;
+  child->verts = (GL2PSvertex *)gl2psMalloc(numverts * sizeof(GL2PSvertex));
+
+  for(i = 0; i < numverts; i++){
+    if(index1[i] < 0){
+      child->verts[i] = parent->verts[index0[i]];
+    }
+    else{
+      gl2psCutEdge(&parent->verts[index0[i]], &parent->verts[index1[i]], 
+		   plane, &child->verts[i]);
+    }
+  }
+}
+
+void gl2psAddIndex(GLshort *index0, GLshort *index1, GLshort *nb, 
+		   GLshort i, GLshort j){
+  GLint k;
+
+  for(k = 0; k < *nb; k++){
+    if((index0[k] == i && index1[k] == j) ||
+       (index1[k] == i && index0[k] == j)) return;
+  }
+  index0[*nb] = i;
+  index1[*nb] = j;
+  (*nb)++;
+}
+
+GLshort gl2psGetIndex(GLshort i, GLshort num){
+  return(i < num-1) ? i+1 : 0;
+}
+
+GLint gl2psTestSplitPrimitive(GL2PSprimitive *prim, GL2PSplane plane){
+  GLint type = GL2PS_COINCIDENT;
+  GLshort i, j;
+  GLfloat d[5]; 
+
+  for(i = 0; i < prim->numverts; i++){  
+    d[i] = gl2psComparePointPlane(prim->verts[i].xyz, plane);
+  }
+
+  if(prim->numverts < 2){
+    return 0;
+  }
+  else{
+    for(i = 0; i < prim->numverts; i++){
+      j = gl2psGetIndex(i, prim->numverts);
+      if(d[j] > GL2PS_EPSILON){
+	if(type == GL2PS_COINCIDENT)      type = GL2PS_IN_BACK_OF;
+	else if(type != GL2PS_IN_BACK_OF) return 1; 
+	if(d[i] < -GL2PS_EPSILON)	  return 1;
+      }
+      else if(d[j] < -GL2PS_EPSILON){
+	if(type == GL2PS_COINCIDENT)       type = GL2PS_IN_FRONT_OF;   
+	else if(type != GL2PS_IN_FRONT_OF) return 1;
+	if(d[i] > GL2PS_EPSILON)           return 1;
+      }
+    }
+  }
+  return 0;
+}
+
+GLint gl2psSplitPrimitive(GL2PSprimitive *prim, GL2PSplane plane, 
+			  GL2PSprimitive **front, GL2PSprimitive **back){
+  GLshort i, j, in=0, out=0, in0[5], in1[5], out0[5], out1[5];
+  GLint type;
+  GLfloat d[5]; 
+
+  type = GL2PS_COINCIDENT;
+
+  for(i = 0; i < prim->numverts; i++){  
+    d[i] = gl2psComparePointPlane(prim->verts[i].xyz, plane);
+  }
+
+  switch(prim->type){
+  case GL2PS_POINT :
+    if(d[0] > GL2PS_EPSILON)       type = GL2PS_IN_BACK_OF;
+    else if(d[0] < -GL2PS_EPSILON) type = GL2PS_IN_FRONT_OF;
+    else                           type = GL2PS_COINCIDENT;
+    break;
+  default :
+    for(i = 0; i < prim->numverts; i++){
+      j = gl2psGetIndex(i, prim->numverts);
+      if(d[j] > GL2PS_EPSILON){
+	if(type == GL2PS_COINCIDENT)      type = GL2PS_IN_BACK_OF;
+	else if(type != GL2PS_IN_BACK_OF) type = GL2PS_SPANNING; 
+	if(d[i] < -GL2PS_EPSILON){
+	  gl2psAddIndex(in0, in1, &in, i, j);
+	  gl2psAddIndex(out0, out1, &out, i, j);
+	  type = GL2PS_SPANNING;
+	}
+	gl2psAddIndex(out0, out1, &out, j, -1);
+      }
+      else if(d[j] < -GL2PS_EPSILON){
+	if(type == GL2PS_COINCIDENT)       type = GL2PS_IN_FRONT_OF;   
+	else if(type != GL2PS_IN_FRONT_OF) type = GL2PS_SPANNING;
+	if(d[i] > GL2PS_EPSILON){
+	  gl2psAddIndex(in0, in1, &in, i, j);
+	  gl2psAddIndex(out0, out1, &out, i, j);
+	  type = GL2PS_SPANNING;
+	}
+	gl2psAddIndex(in0, in1, &in, j, -1);
+      }
+      else{
+	gl2psAddIndex(in0, in1, &in, j, -1);
+	gl2psAddIndex(out0, out1, &out, j, -1);
+      }
+    }
+    break;
+  }
+
+  if(type == GL2PS_SPANNING){
+    *back = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive));
+    *front = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive));
+    gl2psCreateSplitPrimitive(prim, plane, *back, out, out0, out1);
+    gl2psCreateSplitPrimitive(prim, plane, *front, in, in0, in1);
+  }
+
+  return type;
+}
+
+void gl2psDivideQuad(GL2PSprimitive *quad, 
+		     GL2PSprimitive **t1, GL2PSprimitive **t2){
+  *t1 = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive));
+  *t2 = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive));
+  (*t1)->type = (*t2)->type = GL2PS_TRIANGLE;
+  (*t1)->numverts = (*t2)->numverts = 3;
+  (*t1)->depth = (*t2)->depth = quad->depth;
+  (*t1)->culled = (*t2)->culled = quad->culled;
+  (*t1)->dash = (*t2)->dash = quad->dash;
+  (*t1)->width = (*t2)->width = quad->width;
+  (*t1)->verts = (GL2PSvertex *)gl2psMalloc(3 * sizeof(GL2PSvertex));
+  (*t2)->verts = (GL2PSvertex *)gl2psMalloc(3 * sizeof(GL2PSvertex));
+  (*t1)->verts[0] = quad->verts[0];
+  (*t1)->verts[1] = quad->verts[1];
+  (*t1)->verts[2] = quad->verts[2];
+  (*t1)->boundary = ((quad->boundary & 1) ? 1 : 0) | ((quad->boundary & 2) ? 2 : 0);
+  (*t2)->verts[0] = quad->verts[0];
+  (*t2)->verts[1] = quad->verts[2];
+  (*t2)->verts[2] = quad->verts[3];
+  (*t1)->boundary = ((quad->boundary & 4) ? 2 : 0) | ((quad->boundary & 4) ? 2 : 0);
+}
+
+int gl2psCompareDepth(const void *a, const void *b){
+  GL2PSprimitive *q, *w;
+  GLfloat diff;
+
+  q = *(GL2PSprimitive**)a;
+  w = *(GL2PSprimitive**)b;
+  diff = q->depth - w->depth;
+  if(diff > 0.){
+    return 1;
+  }
+  else if(diff < 0.){
+    return -1;
+  }
+  else{
+    return 0;
+  }
+}
+
+int gl2psTrianglesFirst(const void *a, const void *b){
+  GL2PSprimitive *q, *w;
+
+  q = *(GL2PSprimitive**)a;
+  w = *(GL2PSprimitive**)b;
+  return(q->type < w->type ? 1 : -1);
+}
+
+GLint gl2psFindRoot(GL2PSlist *primitives, GL2PSprimitive **root){
+  GLint i, j, count, best = 1000000, index = 0;
+  GL2PSprimitive *prim1, *prim2;
+  GL2PSplane plane;
+  GLint maxp;
+
+  if(gl2ps->options & GL2PS_BEST_ROOT){
+    *root = *(GL2PSprimitive**)gl2psListPointer(primitives, 0);
+    maxp = gl2psListNbr(primitives);
+    if(maxp > gl2ps->maxbestroot){
+      maxp = gl2ps->maxbestroot;
+    }
+    for(i = 0; i < maxp; i++){
+      prim1 = *(GL2PSprimitive**)gl2psListPointer(primitives, i);
+      gl2psGetPlane(prim1, plane);
+      count = 0;
+      for(j = 0; j < gl2psListNbr(primitives); j++){
+	if(j != i){
+	  prim2 = *(GL2PSprimitive**)gl2psListPointer(primitives, j);
+	  count += gl2psTestSplitPrimitive(prim2, plane); 
+	}
+	if(count > best) break;
+      }
+      if(count < best){
+	best = count;
+	index = i;
+	*root = prim1;
+	if(!count) return index;
+      }
+    }
+    /* if(index) gl2psMsg(GL2PS_INFO, "GL2PS_BEST_ROOT was worth it: %d", index); */
+    return index;
+  }
+  else{
+    *root = *(GL2PSprimitive**)gl2psListPointer(primitives, 0);
+    return 0;
+  }
+}
+
+void gl2psFreePrimitive(void *a, void *){
+  GL2PSprimitive *q;
+  
+  q = *(GL2PSprimitive**)a;
+  gl2psFree(q->verts);
+  if(q->type == GL2PS_TEXT){
+    gl2psFree(q->text->str);
+    gl2psFree(q->text->fontname);
+    gl2psFree(q->text);
+  }
+  if(q->type == GL2PS_PIXMAP){
+    gl2psFree(q->image->pixels);
+    gl2psFree(q->image);
+  }
+  gl2psFree(q);
+}
+
+void gl2psAddPrimitiveInList(GL2PSprimitive *prim, GL2PSlist *list){
+  GL2PSprimitive *t1, *t2;
+
+  if(prim->type != GL2PS_QUADRANGLE){
+    gl2psListAdd(list, &prim);
+  }
+  else{
+    gl2psDivideQuad(prim, &t1, &t2);
+    gl2psListAdd(list, &t1);
+    gl2psListAdd(list, &t2);
+    gl2psFreePrimitive(&prim, NULL);
+  }
+  
+}
+
+void gl2psFreeBspTree(GL2PSbsptree **tree){
+  if(*tree){
+    if((*tree)->back) gl2psFreeBspTree(&(*tree)->back);
+    if((*tree)->primitives){
+      gl2psListAction((*tree)->primitives, gl2psFreePrimitive);
+      gl2psListDelete((*tree)->primitives);
+    }
+    if((*tree)->front) gl2psFreeBspTree(&(*tree)->front);
+    gl2psFree(*tree);
+    *tree = NULL;
+  }
+}
+
+GLboolean gl2psGreater(GLfloat f1, GLfloat f2){
+  if(f1 > f2) return 1;
+  else return 0;
+}
+
+GLboolean gl2psLess(GLfloat f1, GLfloat f2){
+  if(f1 < f2) return 1;
+  else return 0;
+}
+
+void gl2psBuildBspTree(GL2PSbsptree *tree, GL2PSlist *primitives){
+  GL2PSprimitive *prim, *frontprim, *backprim;
+  GL2PSlist *frontlist, *backlist;
+  GLint i, index;
+
+  tree->front = NULL;
+  tree->back = NULL;
+  tree->primitives = gl2psListCreate(1, 2, sizeof(GL2PSprimitive*));
+  index = gl2psFindRoot(primitives, &prim);
+  gl2psGetPlane(prim, tree->plane);
+  gl2psAddPrimitiveInList(prim, tree->primitives);
+
+  frontlist = gl2psListCreate(1, 2, sizeof(GL2PSprimitive*));
+  backlist = gl2psListCreate(1, 2, sizeof(GL2PSprimitive*));
+
+  for(i = 0; i < gl2psListNbr(primitives); i++){
+    if(i != index){
+      prim = *(GL2PSprimitive**)gl2psListPointer(primitives,i);
+      switch(gl2psSplitPrimitive(prim, tree->plane, &frontprim, &backprim)){
+      case GL2PS_COINCIDENT:
+	gl2psAddPrimitiveInList(prim, tree->primitives);
+	break;
+      case GL2PS_IN_BACK_OF:
+	gl2psAddPrimitiveInList(prim, backlist);
+	break;
+      case GL2PS_IN_FRONT_OF:
+	gl2psAddPrimitiveInList(prim, frontlist);
+	break;
+      case GL2PS_SPANNING:
+	gl2psAddPrimitiveInList(backprim, backlist);
+	gl2psAddPrimitiveInList(frontprim, frontlist);
+	gl2psFreePrimitive(&prim, NULL);
+	break;
+      }
+    }
+  }
+
+  if(gl2psListNbr(tree->primitives)){
+    gl2psListSort(tree->primitives, gl2psTrianglesFirst);
+  }
+
+  if(gl2psListNbr(frontlist)){
+    gl2psListSort(frontlist, gl2psTrianglesFirst);
+    tree->front = (GL2PSbsptree*)gl2psMalloc(sizeof(GL2PSbsptree));
+    gl2psBuildBspTree(tree->front, frontlist);
+  }
+  else{
+    gl2psListDelete(frontlist);
+  }
+
+  if(gl2psListNbr(backlist)){
+    gl2psListSort(backlist, gl2psTrianglesFirst);
+    tree->back = (GL2PSbsptree*)gl2psMalloc(sizeof(GL2PSbsptree));
+    gl2psBuildBspTree(tree->back, backlist);
+  }
+  else{
+    gl2psListDelete(backlist);
+  }
+
+  gl2psListDelete(primitives);
+}
+
+void gl2psTraverseBspTree(GL2PSbsptree *tree, GL2PSxyz eye, GLfloat epsilon,
+			  GLboolean (*compare)(GLfloat f1, GLfloat f2),
+			  void (*action)(void *data, void *dummy)){
+  GLfloat result;
+
+  if(!tree) return;
+
+  result = gl2psComparePointPlane(eye, tree->plane);
+
+  if(compare(result, epsilon)){
+    gl2psTraverseBspTree(tree->back, eye, epsilon, compare, action);
+    gl2psListAction(tree->primitives, action);
+    gl2psTraverseBspTree(tree->front, eye, epsilon, compare, action);
+  }
+  else if(compare(-epsilon, result)){ 
+    gl2psTraverseBspTree(tree->front, eye, epsilon, compare, action);
+    gl2psListAction(tree->primitives, action);
+    gl2psTraverseBspTree(tree->back, eye, epsilon, compare, action);
+  }
+  else{
+    gl2psTraverseBspTree(tree->front, eye, epsilon, compare, action);
+    gl2psTraverseBspTree(tree->back, eye, epsilon, compare, action);
+  }
+}
+
+/* The 2D sorting routines (for occlusion culling) */
+
+GLint gl2psGetPlaneFromPoints(GL2PSxyz a, GL2PSxyz b, GL2PSplane plane){  
+  GLfloat n; 
+
+  plane[0] = b[1] - a[1];
+  plane[1] = a[0] - b[0];
+  n = std::sqrt(plane[0]*plane[0] + plane[1]*plane[1]);
+  plane[2]=0.;
+  if(n != 0.){
+    plane[0] /= n;
+    plane[1] /= n;
+    plane[3] = -plane[0]*a[0]-plane[1]*a[1]; 
+    return 1;
+  }
+  else{
+    plane[0] = -1.0;
+    plane[1] = 0.;
+    plane[3] = a[0];
+    return 0;
+  }
+}
+
+void gl2psFreeBspImageTree(GL2PSbsptree2d **tree){
+  if(*tree){
+    if((*tree)->back)  gl2psFreeBspImageTree(&(*tree)->back);
+    if((*tree)->front) gl2psFreeBspImageTree(&(*tree)->front);
+    gl2psFree(*tree);
+    *tree = NULL;
+  }
+}
+
+GLint gl2psCheckPoint(GL2PSxyz point, GL2PSplane plane){
+  GLfloat pt_dis;
+
+  pt_dis = gl2psComparePointPlane(point, plane);
+  if(pt_dis > GL2PS_EPSILON)        return GL2PS_POINT_INFRONT;
+  else if(pt_dis < -GL2PS_EPSILON)  return GL2PS_POINT_BACK;
+  else                              return GL2PS_POINT_COINCIDENT;
+}
+
+void gl2psAddPlanesInBspTreeImage(GL2PSprimitive *prim,
+				  GL2PSbsptree2d **tree){
+  GLint ret = 0;
+  GLint i;
+  GLint offset = 0;
+  GL2PSbsptree2d *head = NULL, *cur = NULL;
+
+  if((*tree == NULL) && (prim->numverts > 2)){
+    head = (GL2PSbsptree2d*)gl2psMalloc(sizeof(GL2PSbsptree2d));
+    for(i = 0; i < prim->numverts-1; i++){
+      if(!gl2psGetPlaneFromPoints(prim->verts[i].xyz,
+                                  prim->verts[i+1].xyz,
+				  head->plane)){
+        if(prim->numverts-i > 3){
+	  offset++;
+	}
+	else{
+	  gl2psFree(head);
+	  return;
+	}
+      }
+      else{
+	break;
+      }
+    }
+    head->back = NULL;
+    head->front = NULL;
+    for(i = 2+offset; i < prim->numverts; i++){
+      ret = gl2psCheckPoint(prim->verts[i].xyz, head->plane);
+      if(ret != GL2PS_POINT_COINCIDENT) break;
+    }
+    switch(ret){
+    case GL2PS_POINT_INFRONT :
+      cur = head;
+      for(i = 1+offset; i < prim->numverts-1; i++){
+        if(cur->front == NULL){
+          cur->front = (GL2PSbsptree2d*)gl2psMalloc(sizeof(GL2PSbsptree2d));
+	}
+        if(gl2psGetPlaneFromPoints(prim->verts[i].xyz,
+				   prim->verts[i+1].xyz,
+				   cur->front->plane)){
+	  cur = cur->front;
+	  cur->front = NULL;
+	  cur->back = NULL;
+	}
+      }
+      if(cur->front == NULL){
+        cur->front = (GL2PSbsptree2d*)gl2psMalloc(sizeof(GL2PSbsptree2d));
+      }
+      if(gl2psGetPlaneFromPoints(prim->verts[i].xyz,
+                                 prim->verts[offset].xyz,
+				 cur->front->plane)){
+	cur->front->front = NULL;
+	cur->front->back = NULL;
+      }
+      else{
+        gl2psFree(cur->front);
+	cur->front = NULL;
+      }
+      break;
+    case GL2PS_POINT_BACK :
+      for(i = 0; i < 4; i++){
+        head->plane[i] = -head->plane[i];
+      }
+      cur = head;
+      for(i = 1+offset; i < prim->numverts-1; i++){
+        if(cur->front == NULL){
+          cur->front = (GL2PSbsptree2d*)gl2psMalloc(sizeof(GL2PSbsptree2d));
+	}
+        if(gl2psGetPlaneFromPoints(prim->verts[i+1].xyz,
+				   prim->verts[i].xyz,
+				   cur->front->plane)){
+	  cur = cur->front;
+	  cur->front = NULL;
+	  cur->back = NULL;
+	}
+      }
+      if(cur->front == NULL){
+        cur->front = (GL2PSbsptree2d*)gl2psMalloc(sizeof(GL2PSbsptree2d));
+      }
+      if(gl2psGetPlaneFromPoints(prim->verts[offset].xyz,
+                                 prim->verts[i].xyz,
+				 cur->front->plane)){
+	cur->front->front = NULL;
+	cur->front->back = NULL;
+      }
+      else{
+        gl2psFree(cur->front);
+	cur->front = NULL;
+      }
+      break;
+    default:
+      gl2psFree(head);
+      return;
+    }
+    (*tree) = head;
+  }
+}
+
+GLint gl2psCheckPrimitive(GL2PSprimitive *prim, GL2PSplane plane){
+  GLint i;
+  GLint pos;
+
+  pos = gl2psCheckPoint(prim->verts[0].xyz, plane);
+  for(i = 1; i < prim->numverts; i++){
+    pos |= gl2psCheckPoint(prim->verts[i].xyz, plane);
+    if(pos == (GL2PS_POINT_INFRONT | GL2PS_POINT_BACK)) return GL2PS_SPANNING;
+  }
+  if(pos & GL2PS_POINT_INFRONT)   return GL2PS_IN_FRONT_OF;
+  else if(pos & GL2PS_POINT_BACK) return GL2PS_IN_BACK_OF;
+  else                            return GL2PS_COINCIDENT;
+}
+
+GL2PSprimitive* gl2psCreateSplitPrimitive2D(GL2PSprimitive *parent,
+                                            GLshort numverts,
+					    GL2PSvertex *vertx){
+  GLint i;
+  GL2PSprimitive *child = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive));
+
+  switch(numverts){
+  case 1 : child->type = GL2PS_POINT; break;
+  case 2 : child->type = GL2PS_LINE; break;
+  case 3 : child->type = GL2PS_TRIANGLE; break;
+  case 4 : child->type = GL2PS_QUADRANGLE; break;
+  }
+  child->boundary = 0; /* not done! */
+  child->depth = parent->depth;
+  child->culled = parent->culled;
+  child->dash = parent->dash;
+  child->width = parent->width;
+  child->numverts = numverts;
+  child->verts = (GL2PSvertex *)gl2psMalloc(numverts * sizeof(GL2PSvertex));
+  for(i = 0; i < numverts; i++){
+    child->verts[i] = vertx[i];
+  }
+  return child;
+}
+
+void gl2psSplitPrimitive2D(GL2PSprimitive *prim, 
+			   GL2PSplane plane, 
+			   GL2PSprimitive **front, 
+			   GL2PSprimitive **back){
+
+  /* cur will hold the position of current vertex
+     prev will holds the position of previous vertex
+     prev0 will holds the position of vertex number 0
+     v1 and v2 represent the current and previous vertexs respectively
+     flag will represents that should the current be checked against the plane */
+  GLint cur = -1, prev = -1, i, v1 = 0, v2 = 0, flag = 1, prev0 = -1;
+  
+  /* list of vertexs which will go in front and back Primitive */
+  GL2PSvertex *front_list = NULL, *back_list = NULL;
+  
+  /* number of vertex in front and back list */
+  GLint front_count = 0, back_count = 0;
+
+  for(i = 0; i <= prim->numverts; i++){
+    v1 = i;
+    if(v1 == prim->numverts){
+      if(prim->numverts < 3) break;
+      v1 = 0;
+      v2 = prim->numverts-1;
+      cur = prev0;
+    }
+    else if(flag){
+      cur = gl2psCheckPoint(prim->verts[v1].xyz, plane);
+      if(i == 0){
+        prev0 = cur;
+      }
+    } 
+    if(((prev == -1) || (prev == cur) || (prev == 0) || (cur == 0)) &&
+       (i < prim->numverts)){
+      if(cur == GL2PS_POINT_INFRONT){
+	front_count++;
+	front_list = (GL2PSvertex*)gl2psRealloc(front_list,
+						sizeof(GL2PSvertex)*front_count);
+        front_list[front_count-1] = prim->verts[v1];
+      }
+      else if(cur == GL2PS_POINT_BACK){
+	back_count++;
+	back_list = (GL2PSvertex*)gl2psRealloc(back_list,
+					       sizeof(GL2PSvertex)*back_count);
+        back_list[back_count-1] = prim->verts[v1];
+      }
+      else{
+	front_count++;
+	front_list = (GL2PSvertex*)gl2psRealloc(front_list,
+						sizeof(GL2PSvertex)*front_count);
+        front_list[front_count-1] = prim->verts[v1];
+	back_count++;
+	back_list = (GL2PSvertex*)gl2psRealloc(back_list,
+					       sizeof(GL2PSvertex)*back_count);
+        back_list[back_count-1] = prim->verts[v1];
+      }
+      flag = 1;
+    }
+    else if((prev != cur) && (cur != 0) && (prev != 0)){
+      if(v1 != 0){
+	v2 = v1-1;
+	i--;
+      }
+      front_count++;
+      front_list = (GL2PSvertex*)gl2psRealloc(front_list,
+					      sizeof(GL2PSvertex)*front_count);
+      gl2psCutEdge(&prim->verts[v2],
+                   &prim->verts[v1],
+		   plane,
+		   &front_list[front_count-1]);
+      back_count++;
+      back_list = (GL2PSvertex*)gl2psRealloc(back_list,
+					     sizeof(GL2PSvertex)*back_count);
+      back_list[back_count-1] = front_list[front_count-1];
+      flag = 0;
+    }
+    prev = cur;
+  }
+  *front = gl2psCreateSplitPrimitive2D(prim, front_count, front_list);
+  *back = gl2psCreateSplitPrimitive2D(prim, back_count, back_list);
+  gl2psFree(front_list);
+  gl2psFree(back_list);
+}
+
+GLint gl2psAddInBspImageTree(GL2PSprimitive *prim, GL2PSbsptree2d **tree){
+  GLint ret = 0;
+  GL2PSprimitive *frontprim = NULL, *backprim = NULL;
+
+  if(*tree == NULL){
+    gl2psAddPlanesInBspTreeImage(prim, tree);
+    return 1;
+  }
+  else{
+    switch(gl2psCheckPrimitive(prim, (*tree)->plane)){
+    case GL2PS_IN_BACK_OF: return gl2psAddInBspImageTree(prim, &(*tree)->back);
+    case GL2PS_IN_FRONT_OF: 
+      if((*tree)->front != NULL) return gl2psAddInBspImageTree(prim, &(*tree)->front);
+      else                       return 0;
+    case GL2PS_SPANNING:
+      gl2psSplitPrimitive2D(prim, (*tree)->plane, &frontprim, &backprim);
+      ret = gl2psAddInBspImageTree(backprim, &(*tree)->back);
+      if((*tree)->front != NULL){
+        if(gl2psAddInBspImageTree(frontprim, &(*tree)->front)){
+	  ret = 1;
+	}
+      }
+      gl2psFree(frontprim->verts);
+      gl2psFree(frontprim);
+      gl2psFree(backprim->verts);
+      gl2psFree(backprim);
+      return ret;
+    case GL2PS_COINCIDENT:
+      if(prim->numverts < 3) return 1;
+      else                   return 0;
+    }
+  }
+  return 0;
+}
+
+void gl2psAddInImageTree(void *a, void *){
+  GL2PSprimitive *prim = *(GL2PSprimitive **)a;
+
+  if(!gl2psAddInBspImageTree(prim, &gl2ps->imagetree)){
+    prim->culled = 1;
+  }
+}
+
+/* Boundary contruction */
+
+void gl2psAddBoundaryInList(GL2PSprimitive *prim, GL2PSlist *list){
+  GL2PSprimitive *b;
+  GLshort i;
+  GL2PSxyz c;
+
+  c[0] = c[1] = c[2] = 0.;
+  for(i = 0; i < prim->numverts; i++){
+    c[0] += prim->verts[i].xyz[0];
+    c[1] += prim->verts[i].xyz[1];
+  }
+  c[0] /= prim->numverts;
+  c[1] /= prim->numverts;
+
+  for(i = 0; i < prim->numverts; i++){
+    if(prim->boundary & (GLint)pow(2., i)){
+      b = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive));
+      b->type = GL2PS_LINE;
+      b->dash = prim->dash;
+      b->depth = prim->depth; /* this is wrong */
+      b->culled = prim->culled;
+      b->width = prim->width;
+      b->boundary = 0;
+      b->numverts = 2;
+      b->verts = (GL2PSvertex *)gl2psMalloc(2 * sizeof(GL2PSvertex));
+
+#if 0 /* need to work on boundary offset... */
+      v[0] = c[0] - prim->verts[i].xyz[0];
+      v[1] = c[1] - prim->verts[i].xyz[1];
+      v[2] = 0.;
+      norm = gl2psNorm(v);
+      v[0] /= norm;
+      v[1] /= norm;
+      b->verts[0].xyz[0] = prim->verts[i].xyz[0] +0.1*v[0];
+      b->verts[0].xyz[1] = prim->verts[i].xyz[1] +0.1*v[1];
+      b->verts[0].xyz[2] = prim->verts[i].xyz[2];
+      v[0] = c[0] - prim->verts[gl2psGetIndex(i, prim->numverts)].xyz[0];
+      v[1] = c[1] - prim->verts[gl2psGetIndex(i, prim->numverts)].xyz[1];
+      norm = gl2psNorm(v);
+      v[0] /= norm;
+      v[1] /= norm;
+      b->verts[1].xyz[0] = prim->verts[gl2psGetIndex(i, prim->numverts)].xyz[0] +0.1*v[0];
+      b->verts[1].xyz[1] = prim->verts[gl2psGetIndex(i, prim->numverts)].xyz[1] +0.1*v[1];
+      b->verts[1].xyz[2] = prim->verts[gl2psGetIndex(i, prim->numverts)].xyz[2];
+#else
+      b->verts[0].xyz[0] = prim->verts[i].xyz[0];
+      b->verts[0].xyz[1] = prim->verts[i].xyz[1];
+      b->verts[0].xyz[2] = prim->verts[i].xyz[2];
+      b->verts[1].xyz[0] = prim->verts[gl2psGetIndex(i, prim->numverts)].xyz[0];
+      b->verts[1].xyz[1] = prim->verts[gl2psGetIndex(i, prim->numverts)].xyz[1];
+      b->verts[1].xyz[2] = prim->verts[gl2psGetIndex(i, prim->numverts)].xyz[2];
+#endif
+
+      b->verts[0].rgba[0] = 0.;
+      b->verts[0].rgba[1] = 0.;
+      b->verts[0].rgba[2] = 0.;
+      b->verts[0].rgba[3] = 0.;
+      b->verts[1].rgba[0] = 0.;
+      b->verts[1].rgba[1] = 0.;
+      b->verts[1].rgba[2] = 0.;
+      b->verts[1].rgba[3] = 0.;
+      gl2psListAdd(list, &b);
+    }
+  }
+
+}
+
+void gl2psBuildPolygonBoundary(GL2PSbsptree *tree){
+  GLint i, n;
+  GL2PSprimitive *prim;
+
+  if(!tree) return;
+  gl2psBuildPolygonBoundary(tree->back);
+  n = gl2psListNbr(tree->primitives);
+  for(i = 0; i < n; i++){
+    prim = *(GL2PSprimitive**)gl2psListPointer(tree->primitives, i);
+    if(prim->boundary) gl2psAddBoundaryInList(prim, tree->primitives);
+  }
+  gl2psBuildPolygonBoundary(tree->front);
+}
+
+/* The feedback buffer parser */
+
+void gl2psAddPolyPrimitive(GLshort type, GLshort numverts, 
+			   GL2PSvertex *verts, GLint offset, 
+			   char dash, GLfloat width,
+			   char boundary){
+  GLshort i;
+  GLfloat factor, units, area, dZ, dZdX, dZdY, maxdZ;
+  GL2PSprimitive *prim;
+
+  prim = (GL2PSprimitive *)gl2psMalloc(sizeof(GL2PSprimitive));
+  prim->type = type;
+  prim->numverts = numverts;
+  prim->verts = (GL2PSvertex *)gl2psMalloc(numverts * sizeof(GL2PSvertex));
+  memcpy(prim->verts, verts, numverts * sizeof(GL2PSvertex));
+  prim->boundary = boundary;
+  prim->dash = dash;
+  prim->width = width;
+  prim->culled = 0;
+
+  if(gl2ps->options & GL2PS_SIMPLE_LINE_OFFSET){
+
+    if(type == GL2PS_LINE){
+      if(gl2ps->sort == GL2PS_SIMPLE_SORT){
+	prim->verts[0].xyz[2] -= GL2PS_SIMPLE_OFFSET_LARGE;
+	prim->verts[1].xyz[2] -= GL2PS_SIMPLE_OFFSET_LARGE;
+      }
+      else{
+	prim->verts[0].xyz[2] -= GL2PS_SIMPLE_OFFSET;
+	prim->verts[1].xyz[2] -= GL2PS_SIMPLE_OFFSET;
+      }
+    }
+
+  }
+  else if(offset && type == GL2PS_TRIANGLE){
+
+    /* This needs some more work... */
+
+    if(gl2ps->sort == GL2PS_SIMPLE_SORT){    
+      factor = gl2ps->offset[0];
+      units = gl2ps->offset[1];
+    }
+    else{
+      factor = gl2ps->offset[0] / 800.;
+      units = gl2ps->offset[1] / 800.;
+    }
+
+    area = 
+      (prim->verts[1].xyz[0] - prim->verts[0].xyz[0]) * 
+      (prim->verts[2].xyz[1] - prim->verts[1].xyz[1]) - 
+      (prim->verts[2].xyz[0] - prim->verts[1].xyz[0]) * 
+      (prim->verts[1].xyz[1] - prim->verts[0].xyz[1]);
+    dZdX = 
+      (prim->verts[2].xyz[1] - prim->verts[1].xyz[1]) *
+      (prim->verts[1].xyz[2] - prim->verts[0].xyz[2]) -
+      (prim->verts[1].xyz[1] - prim->verts[0].xyz[1]) *
+      (prim->verts[2].xyz[2] - prim->verts[1].xyz[2]) / area;
+    dZdY = 
+      (prim->verts[1].xyz[0] - prim->verts[0].xyz[0]) *
+      (prim->verts[2].xyz[2] - prim->verts[1].xyz[2]) -
+      (prim->verts[2].xyz[0] - prim->verts[1].xyz[0]) *
+      (prim->verts[1].xyz[2] - prim->verts[0].xyz[2]) / area;
+    
+    maxdZ = std::sqrt(dZdX*dZdX + dZdY*dZdY);
+
+    dZ = factor * maxdZ + units;
+
+    prim->verts[0].xyz[2] += dZ;
+    prim->verts[1].xyz[2] += dZ;
+    prim->verts[2].xyz[2] += dZ;
+  }
+
+  prim->depth = 0.;
+  if(gl2ps->sort == GL2PS_SIMPLE_SORT){
+    for(i = 0; i < numverts; i++){
+      prim->depth += prim->verts[i].xyz[2]; 
+    }
+    prim->depth /= (GLfloat)numverts;
+  }
+  
+  gl2psListAdd(gl2ps->primitives, &prim);
+}
+
+GLint gl2psGetVertex(GL2PSvertex *v, GLfloat *p){
+  GLint i;
+
+  v->xyz[0] = p[0];
+  v->xyz[1] = p[1];
+  v->xyz[2] = GL2PS_DEPTH_FACT * p[2];
+
+  if(gl2ps->colormode == GL_COLOR_INDEX && gl2ps->colorsize > 0){
+    i = (GLint)(p[3] + 0.5);
+    v->rgba[0] = gl2ps->colormap[i][0];
+    v->rgba[1] = gl2ps->colormap[i][1];
+    v->rgba[2] = gl2ps->colormap[i][2];
+    v->rgba[3] = gl2ps->colormap[i][3];
+    return 4;
+  }
+  else{
+    v->rgba[0] = p[3];
+    v->rgba[1] = p[4];
+    v->rgba[2] = p[5];
+    v->rgba[3] = p[6];
+    return 7;
+  }
+}
+
+GLint gl2psParseFeedbackBuffer(void){
+  char flag, dash = 0;
+  GLshort boundary;
+  GLint i, used, count, v, vtot, offset = 0;
+  GLfloat lwidth = 1., psize = 1.;
+  GLfloat *current;
+  GL2PSvertex vertices[3];
+
+  used = glRenderMode(GL_RENDER);
+
+  if(used < 0){
+    gl2psMsg(GL2PS_INFO, "OpenGL feedback buffer overflow");
+    return GL2PS_OVERFLOW;
+  }
+
+  if(used == 0){
+    /* gl2psMsg(GL2PS_INFO, "Empty feedback buffer"); */
+    return GL2PS_NO_FEEDBACK;
+  }
+
+  current = gl2ps->feedback;
+  boundary = gl2ps->boundary = 0;
+
+  while(used > 0){
+
+    if(boundary) gl2ps->boundary = 1;
+    
+    switch((GLint)*current){
+    case GL_POINT_TOKEN :
+      current ++;
+      used --;
+      i = gl2psGetVertex(&vertices[0], current);
+      current += i;
+      used    -= i;
+      gl2psAddPolyPrimitive(GL2PS_POINT, 1, vertices, 0, dash, psize, 0);
+      break;
+    case GL_LINE_TOKEN :
+    case GL_LINE_RESET_TOKEN :
+      current ++;
+      used --;
+      i = gl2psGetVertex(&vertices[0], current);
+      current += i;
+      used    -= i;
+      i = gl2psGetVertex(&vertices[1], current);
+      current += i;
+      used    -= i;
+      gl2psAddPolyPrimitive(GL2PS_LINE, 2, vertices, 0, dash, lwidth, 0);
+      break;
+    case GL_POLYGON_TOKEN :
+      count = (GLint)current[1];
+      current += 2;
+      used -= 2;
+      v = vtot = 0;
+      while(count > 0 && used > 0){
+	i = gl2psGetVertex(&vertices[v], current);
+	current += i;
+	used    -= i;
+	count --;
+	vtot++;
+	if(v == 2){
+	  if(boundary){
+	    if(!count && vtot == 2) flag = 1|2|4;
+	    else if(!count) flag = 2|4;
+	    else if(vtot == 2) flag = 1|2;
+	    else flag = 2;
+	  }
+	  else
+	    flag = 0;
+	  gl2psAddPolyPrimitive(GL2PS_TRIANGLE, 3, vertices, 
+				offset, dash, 1, flag);
+	  vertices[1] = vertices[2];
+	}
+	else
+	  v ++;
+      }
+      break;      
+    case GL_BITMAP_TOKEN :
+    case GL_DRAW_PIXEL_TOKEN :
+    case GL_COPY_PIXEL_TOKEN :
+      current ++;
+      used --;
+      i = gl2psGetVertex(&vertices[0], current);
+      current += i;
+      used    -= i;
+      break;      
+    case GL_PASS_THROUGH_TOKEN :
+      switch((GLint)current[1]){
+      case GL2PS_BEGIN_POLYGON_OFFSET_FILL : offset = 1; break;
+      case GL2PS_END_POLYGON_OFFSET_FILL : offset = 0; break;
+      case GL2PS_BEGIN_POLYGON_BOUNDARY : boundary = 1; break;
+      case GL2PS_END_POLYGON_BOUNDARY : boundary = 0; break;
+      case GL2PS_BEGIN_LINE_STIPPLE : dash = 4; break;
+      case GL2PS_END_LINE_STIPPLE : dash = 0; break;
+      case GL2PS_SET_POINT_SIZE : 
+	current += 2; 
+	used -= 2; 
+	psize = current[1];
+	break;
+      case GL2PS_SET_LINE_WIDTH : 
+	current += 2; 
+	used -= 2; 
+	lwidth = current[1];
+	break;
+      }
+      current += 2; 
+      used -= 2; 
+      break;      
+    default :
+      gl2psMsg(GL2PS_WARNING, "Unknown token in buffer");
+      current ++;
+      used --;
+      break;
+    }
+  }
+  
+  return GL2PS_SUCCESS;
+}
+
+GLboolean gl2psSameColor(GL2PSrgba rgba1, GL2PSrgba rgba2){
+  return !(rgba1[0] != rgba2[0] || 
+	   rgba1[1] != rgba2[1] ||
+	   rgba1[2] != rgba2[2]);
+}
+  
+GLboolean gl2psVertsSameColor(const GL2PSprimitive *prim){
+  int i;
+
+  for(i = 1; i < prim->numverts; i++){
+    if(!gl2psSameColor(prim->verts[0].rgba, prim->verts[i].rgba)){
+      return 0;
+    }
+  }
+  return 1;
+}
+
+GLint gl2psPrintPrimitives(void);
+
+/* The PostScript routines. Other (vector) image formats should be
+   easy to generate by creating the three corresponding routines
+   (gl2psPrintXXXHeader, gl2psPrintXXXPrimitive, gl2psPrintXXXFooter,
+   gl2psPrintXXXBeginViewport and gl2psPrintXXXEndViewport) for the
+   new format. */
+
+void gl2psWriteByte(FILE *stream, unsigned char byte){
+  unsigned char h = byte / 16;
+  unsigned char l = byte % 16;
+  fprintf(stream, "%x%x", h, l);
+}
+
+int gl2psGetRGB(GLfloat *pixels, GLsizei width, GLsizei height, GLuint x, GLuint y,
+		GLfloat *red, GLfloat *green, GLfloat *blue){
+  /* OpenGL image is from down to up, PS image is up to down */
+  GLfloat *pimag;
+  pimag = pixels + 3 * (width * (height - 1 - y) + x);
+  *red   = *pimag; pimag++;
+  *green = *pimag; pimag++;
+  *blue  = *pimag; pimag++;
+  return 1;
+}
+
+void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GLsizei width, GLsizei height,
+				GLenum, GLenum, GLfloat *pixels,
+				FILE *stream){
+  typedef unsigned char Uchar;
+  int status = 1, nbhex, nbyte;
+  int row, col, ibyte,icase;
+  float dr, dg, db, fgrey;
+  Uchar red, green, blue, b, grey;
+  /* Options */
+  int shade = 0;
+  //int nbit = 2;
+  int nbit = 4;
+  //int nbit = 8;
+
+  if((width <= 0) || (height <= 0)) return;
+
+  /* Msg(INFO, "gl2psPrintPostScriptPixmap: x %g y %g w %d h %d", x, y, width, height); */
+
+  fprintf(stream, "gsave\n");
+  fprintf(stream, "%.2f %.2f translate\n", x, y); 
+  fprintf(stream, "%d %d scale\n", width, height); 
+
+  if(shade != 0){ /* grey */
+    fprintf(stream, "/picstr %d string def\n", width); 
+    fprintf(stream, "%d %d %d\n", width, height, 8); 
+    fprintf(stream, "[ %d 0 0 -%d 0 %d ]\n", width, height, height); 
+    fprintf(stream, "{ currentfile picstr readhexstring pop }\n");
+    fprintf(stream, "image\n");
+    for(row = 0; row < height; row++){
+      for(col = 0; col < width; col++){ 
+	status = gl2psGetRGB(pixels, width, height,
+			     col, row, &dr, &dg, &db) == 0 ? 0 : status;
+	fgrey = (0.30 * dr + 0.59 * dg + 0.11 * db);
+	grey = (Uchar)(255. * fgrey);
+	gl2psWriteByte(stream, grey);
+      }
+      fprintf(stream, "\n");
+    }
+    nbhex = width * height * 2; 
+    fprintf(stream, "%%%% nbhex digit          :%d\n", nbhex); 
+  }
+  else if(nbit == 2){ 
+    int nrgb = width  * 3;
+    int nbits = nrgb * nbit;
+    nbyte = nbits/8;
+    if((nbyte*8)!=nbits) nbyte++; 
+    /* 2 bit for r and g and b */
+    /* rgbs following each other */
+    fprintf(stream, "/rgbstr %d string def\n", nbyte); 
+    fprintf(stream, "%d %d %d\n", width, height, nbit); 
+    fprintf(stream, "[ %d 0 0 -%d 0 %d ]\n", width, height, height); 
+    fprintf(stream, "{ currentfile rgbstr readhexstring pop }\n" );
+    fprintf(stream, "false 3\n" );
+    fprintf(stream, "colorimage\n" );    
+    for(row = 0; row < height; row++){
+      icase = 1;
+      col = 0;
+      b = 0;
+      for(ibyte = 0; ibyte < nbyte; ibyte++){
+        if(icase==1) {
+          if(col<width) {
+	    status = gl2psGetRGB(pixels, width, height,
+			     col, row, &dr, &dg, &db) == 0 ? 0 : status;
+          } else {
+            dr = dg = db = 0;
+          }
+          col++;
+	  red = (Uchar)(3. * dr);
+	  green = (Uchar)(3. * dg);
+	  blue = (Uchar)(3. * db);
+	  b = red;
+	  b = (b<<2)+green;
+	  b = (b<<2)+blue;
+          if(col<width) {
+	    status = gl2psGetRGB(pixels, width, height,
+			     col, row, &dr, &dg, &db) == 0 ? 0 : status;
+          } else {
+            dr = dg = db = 0;
+          }
+          col++;
+	  red = (Uchar)(3. * dr);
+	  green = (Uchar)(3. * dg);
+	  blue = (Uchar)(3. * db);
+	  b = (b<<2)+red;
+	  gl2psWriteByte(stream, b);
+          b = 0;
+          icase++;
+	} else if(icase==2) {
+	  b = green;
+	  b = (b<<2)+blue;
+          if(col<width) {
+	    status = gl2psGetRGB(pixels, width, height,
+			     col, row, &dr, &dg, &db) == 0 ? 0 : status;
+          } else {
+            dr = dg = db = 0;
+          }
+          col++;
+	  red = (Uchar)(3. * dr);
+	  green = (Uchar)(3. * dg);
+	  blue = (Uchar)(3. * db);
+	  b = (b<<2)+red;
+	  b = (b<<2)+green;
+	  gl2psWriteByte(stream, b);
+          b = 0;
+          icase++;
+	} else if(icase==3) {
+	  b = blue;
+          if(col<width) {
+	    status = gl2psGetRGB(pixels,width,height,
+			     col, row, &dr, &dg, &db) == 0 ? 0 : status;
+          } else {
+            dr = dg = db = 0;
+          }
+          col++;
+	  red = (Uchar)(3. * dr);
+	  green = (Uchar)(3. * dg);
+	  blue = (Uchar)(3. * db);
+	  b = (b<<2)+red;
+	  b = (b<<2)+green;
+	  b = (b<<2)+blue;
+	  gl2psWriteByte(stream, b);
+          b = 0;
+          icase = 1;
+        }
+      }
+      fprintf(stream, "\n");
+    }
+  }
+  else if(nbit == 4){ 
+    int nrgb = width  * 3;
+    int nbits = nrgb * nbit;
+    nbyte = nbits/8;
+    if((nbyte*8)!=nbits) nbyte++; 
+    /* 4 bit for r and g and b */
+    /* rgbs following each other */
+    fprintf(stream, "/rgbstr %d string def\n", nbyte);
+    fprintf(stream, "%d %d %d\n", width, height,nbit);
+    fprintf(stream, "[ %d 0 0 -%d 0 %d ]\n", width, height, height);
+    fprintf(stream, "{ currentfile rgbstr readhexstring pop }\n");
+    fprintf(stream, "false 3\n");
+    fprintf(stream, "colorimage\n");
+    for(row = 0; row < height; row++){
+      col = 0;
+      icase = 1;
+      for(ibyte = 0; ibyte < nbyte; ibyte++){
+        if(icase==1) {
+          if(col<width) {
+            status = gl2psGetRGB(pixels, width, height,
+			     col, row, &dr, &dg, &db) == 0 ? 0 : status;
+          } else {
+            dr = dg = db = 0;
+          }
+          col++;
+	  red = (Uchar)(15. * dr);
+  	  green = (Uchar)(15. * dg);
+	  fprintf(stream, "%x%x", red, green);
+          icase++;
+        } else if(icase==2) {
+  	  blue = (Uchar)(15. * db);
+	  if(col<width) {
+  	    status = gl2psGetRGB(pixels, width, height,
+		 	     col, row, &dr, &dg, &db) == 0 ? 0 : status;
+          } else {
+            dr = dg = db = 0;
+          }
+          col++;
+	  red = (Uchar)(15. * dr);
+	  fprintf(stream,"%x%x",blue,red);
+          icase++;
+        } else if(icase==3) {
+	  green = (Uchar)(15. * dg);
+	  blue = (Uchar)(15. * db);
+	  fprintf(stream, "%x%x", green, blue);
+          icase = 1;
+        }
+      }
+      fprintf(stream, "\n");
+    }
+  }
+  else{ 
+    nbyte = width * 3;
+    /* 8 bit for r and g and b */
+    fprintf(stream, "/rgbstr %d string def\n", nbyte);
+    fprintf(stream, "%d %d %d\n", width, height, 8);
+    fprintf(stream, "[ %d 0 0 -%d 0 %d ]\n", width, height, height); 
+    fprintf(stream, "{ currentfile rgbstr readhexstring pop }\n");
+    fprintf(stream, "false 3\n");
+    fprintf(stream, "colorimage\n");
+    for(row = 0; row < height; row++){
+      for(col = 0; col < width; col++){
+	status = gl2psGetRGB(pixels, width, height,
+			     col, row, &dr, &dg, &db) == 0 ? 0 : status;
+	red = (Uchar)(255. * dr);
+	gl2psWriteByte(stream, red);
+	green = (Uchar)(255. * dg);
+	gl2psWriteByte(stream, green);
+	blue = (Uchar)(255. * db);
+	gl2psWriteByte(stream, blue);
+      }
+      fprintf(stream, "\n");
+    }
+  }
+
+  if(status == 0){
+    gl2psMsg(GL2PS_ERROR, "Problem to retreive some pixel rgb");
+  }
+  fprintf(stream, "grestore\n");
+}
+
+void gl2psPrintPostScriptHeader(void){
+  GLint index;
+  GLfloat rgba[4];
+  time_t now;
+
+  time(&now);
+
+  if(gl2ps->format == GL2PS_PS){
+    fprintf(gl2ps->stream, "%%!PS-Adobe-3.0\n");
+  }
+  else{
+    fprintf(gl2ps->stream, "%%!PS-Adobe-3.0 EPSF-3.0\n");
+  }
+
+  fprintf(gl2ps->stream, 
+	  "%%%%Title: %s\n"
+	  "%%%%Creator: GL2PS, an OpenGL to PostScript Printing Library, v. %g\n"
+	  "%%%%For: %s\n"
+	  "%%%%CreationDate: %s"
+	  "%%%%LanguageLevel: 3\n"
+	  "%%%%DocumentData: Clean7Bit\n"
+	  "%%%%Pages: 1\n",
+	  gl2ps->title, GL2PS_VERSION, gl2ps->producer, ctime(&now));
+
+  if(gl2ps->format == GL2PS_PS){
+    fprintf(gl2ps->stream, 
+	    "%%%%Orientation: %s\n"
+	    "%%%%DocumentMedia: Default %d %d 0 () ()\n",
+	    (gl2ps->options & GL2PS_LANDSCAPE) ? "Landscape" : "Portrait",
+	    (gl2ps->options & GL2PS_LANDSCAPE) ? gl2ps->viewport[3] : gl2ps->viewport[2],
+	    (gl2ps->options & GL2PS_LANDSCAPE) ? gl2ps->viewport[2] : gl2ps->viewport[3]);
+  }
+
+  fprintf(gl2ps->stream,
+	  "%%%%BoundingBox: %d %d %d %d\n"
+	  "%%%%Copyright: GNU LGPL (C) 1999-2003 Christophe Geuzaine <geuz@geuz.org>\n"
+	  "%%%%EndComments\n",
+	  (gl2ps->options & GL2PS_LANDSCAPE) ? gl2ps->viewport[1] : gl2ps->viewport[0],
+	  (gl2ps->options & GL2PS_LANDSCAPE) ? gl2ps->viewport[0] : gl2ps->viewport[1],
+	  (gl2ps->options & GL2PS_LANDSCAPE) ? gl2ps->viewport[3] : gl2ps->viewport[2],
+	  (gl2ps->options & GL2PS_LANDSCAPE) ? gl2ps->viewport[2] : gl2ps->viewport[3]);
+
+  /* RGB color: r g b C (replace C by G in output to change from rgb to gray)
+     Grayscale: r g b G
+     Font choose: size fontname FC
+     String primitive: (string) x y size fontname S
+     Point primitive: x y size P
+     Line width: width W
+     Flat-shaded line: x2 y2 x1 y1 L
+     Smooth-shaded line: x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 SL
+     Flat-shaded triangle: x3 y3 x2 y2 x1 y1 T
+     Smooth-shaded triangle: x3 y3 r3 g3 b3 x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 ST */
+
+  fprintf(gl2ps->stream,
+	  "%%%%BeginProlog\n"
+	  "/gl2psdict 64 dict def gl2psdict begin\n"
+	  "1 setlinecap 1 setlinejoin\n"
+	  "/tryPS3shading %s def %% set to false to force subdivision\n"
+	  "/rThreshold %g def %% red component subdivision threshold\n"
+	  "/gThreshold %g def %% green component subdivision threshold\n"
+	  "/bThreshold %g def %% blue component subdivision threshold\n"
+	  "/BD { bind def } bind def\n"
+	  "/C  { setrgbcolor } BD\n"
+	  "/G  { 0.082 mul exch 0.6094 mul add exch 0.3086 mul add neg 1.0 add setgray } BD\n"
+	  "/W  { setlinewidth } BD\n"
+	  "/FC { findfont exch scalefont setfont } BD\n"
+	  "/S  { FC moveto show } BD\n"
+	  "/P  { newpath 0.0 360.0 arc closepath fill } BD\n"
+	  "/L  { newpath moveto lineto stroke } BD\n"
+	  "/SL { C moveto C lineto stroke } BD\n"
+	  "/T  { newpath moveto lineto lineto closepath fill } BD\n",
+	  (gl2ps->options & GL2PS_NO_PS3_SHADING) ? "false" : "true",
+          gl2ps->threshold[0], gl2ps->threshold[1], gl2ps->threshold[2]);
+
+  /* Smooth-shaded triangle with PostScript level 3 shfill operator:
+        x3 y3 r3 g3 b3 x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 STshfill */
+
+  fprintf(gl2ps->stream,
+	  "/STshfill {\n"
+	  "      /b1 exch def /g1 exch def /r1 exch def /y1 exch def /x1 exch def\n"
+	  "      /b2 exch def /g2 exch def /r2 exch def /y2 exch def /x2 exch def\n"
+	  "      /b3 exch def /g3 exch def /r3 exch def /y3 exch def /x3 exch def\n"
+	  "      gsave << /ShadingType 4 /ColorSpace [/DeviceRGB]\n"
+	  "      /DataSource [ 0 x1 y1 r1 g1 b1 0 x2 y2 r2 g2 b2 0 x3 y3 r3 g3 b3 ] >>\n"
+	  "      shfill grestore } BD\n");
+
+  /* Flat-shaded triangle with middle color:
+        x3 y3 r3 g3 b3 x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 Tm */
+
+  fprintf(gl2ps->stream,
+          /* stack : x3 y3 r3 g3 b3 x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 */
+          "/Tm { 3 -1 roll 8 -1 roll 13 -1 roll add add 3 div\n" /* r = (r1+r2+r3)/3 */
+          /* stack : x3 y3 g3 b3 x2 y2 g2 b2 x1 y1 g1 b1 r */
+          "      3 -1 roll 7 -1 roll 11 -1 roll add add 3 div\n" /* g = (g1+g2+g3)/3 */
+          /* stack : x3 y3 b3 x2 y2 b2 x1 y1 b1 r g b */
+          "      3 -1 roll 6 -1 roll 9 -1 roll add add 3 div" /* b = (b1+b2+b3)/3 */
+          /* stack : x3 y3 x2 y2 x1 y1 r g b */
+          " C T } BD\n");
+
+  /* Split triangle in four sub-triangles (at sides middle points) and call the
+     STnoshfill procedure on each, interpolating the colors in RGB space:
+        x3 y3 r3 g3 b3 x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 STsplit
+     (in procedure comments key: (Vi) = xi yi ri gi bi) */
+
+  fprintf(gl2ps->stream,
+          "/STsplit {\n"
+          "      4 index 15 index add 0.5 mul\n" /* x13 = (x1+x3)/2 */
+          "      4 index 15 index add 0.5 mul\n" /* y13 = (y1+y3)/2 */
+          "      4 index 15 index add 0.5 mul\n" /* r13 = (r1+r3)/2 */
+          "      4 index 15 index add 0.5 mul\n" /* g13 = (g1+g3)/2 */
+          "      4 index 15 index add 0.5 mul\n" /* b13 = (b1+b3)/2 */
+          "      5 copy 5 copy 25 15 roll\n"
+          /* stack : (V3) (V13) (V13) (V13) (V2) (V1) */
+          "      9 index 30 index add 0.5 mul\n" /* x23 = (x2+x3)/2 */
+          "      9 index 30 index add 0.5 mul\n" /* y23 = (y2+y3)/2 */
+          "      9 index 30 index add 0.5 mul\n" /* r23 = (r2+r3)/2 */
+          "      9 index 30 index add 0.5 mul\n" /* g23 = (g2+g3)/2 */
+          "      9 index 30 index add 0.5 mul\n" /* b23 = (b2+b3)/2 */
+          "      5 copy 5 copy 35 5 roll 25 5 roll 15 5 roll\n"
+          /* stack : (V3) (V13) (V23) (V13) (V23) (V13) (V23) (V2) (V1) */
+          "      4 index 10 index add 0.5 mul\n" /* x12 = (x1+x2)/2 */
+          "      4 index 10 index add 0.5 mul\n" /* y12 = (y1+y2)/2 */
+          "      4 index 10 index add 0.5 mul\n" /* r12 = (r1+r2)/2 */
+          "      4 index 10 index add 0.5 mul\n" /* g12 = (g1+g2)/2 */
+          "      4 index 10 index add 0.5 mul\n" /* b12 = (b1+b2)/2 */
+          "      5 copy 5 copy 40 5 roll 25 5 roll 15 5 roll 25 5 roll\n"
+          /* stack : (V3) (V13) (V23) (V13) (V12) (V23) (V13) (V1) (V12) (V23) (V12) (V2) */
+          "      STnoshfill STnoshfill STnoshfill STnoshfill } BD\n");
+
+  /* Gouraud shaded triangle using recursive subdivision until the difference
+     between corner colors does not exceed the thresholds:
+        x3 y3 r3 g3 b3 x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 STnoshfill  */
+
+  fprintf(gl2ps->stream,
+          "/STnoshfill {\n"
+	  "      2 index 8 index sub abs rThreshold gt\n" /* |r1-r2|>rth */
+	  "      { STsplit }\n"
+          "      { 1 index 7 index sub abs gThreshold gt\n" /* |g1-g2|>gth */
+	  "        { STsplit }\n"
+          "        { dup 6 index sub abs bThreshold gt\n" /* |b1-b2|>bth */
+	  "          { STsplit }\n"
+          "          { 2 index 13 index sub abs rThreshold gt\n" /* |r1-r3|>rht */
+	  "            { STsplit }\n"
+          "            { 1 index 12 index sub abs gThreshold gt\n" /* |g1-g3|>gth */
+	  "              { STsplit }\n"
+          "              { dup 11 index sub abs bThreshold gt\n" /* |b1-b3|>bth */
+	  "                { STsplit }\n"
+          "                { 7 index 13 index sub abs rThreshold gt\n" /* |r2-r3|>rht */
+	  "                  { STsplit }\n"
+          "                  { 6 index 12 index sub abs gThreshold gt\n" /* |g2-g3|>gth */
+	  "                    { STsplit }\n"
+          "                    { 5 index 11 index sub abs bThreshold gt\n" /* |b2-b3|>bth */
+	  "                      { STsplit }\n"
+          "                      { Tm }\n" /* all colors sufficiently similar */
+          "                      ifelse }\n"
+          "                    ifelse }\n"
+          "                  ifelse }\n"
+          "                ifelse }\n"
+          "              ifelse }\n"
+          "            ifelse }\n"
+          "          ifelse }\n"
+          "        ifelse }\n"
+          "      ifelse } BD\n");
+
+  fprintf(gl2ps->stream,
+	  "tryPS3shading\n"
+	  "{ /shfill where\n"
+	  "  { /ST { STshfill } BD }\n"
+	  "  { /ST { STnoshfill } BD }\n"
+	  "  ifelse }\n"
+	  "{ /ST { STnoshfill } BD }\n"
+	  "ifelse\n");
+
+  fprintf(gl2ps->stream,
+	  "end\n"
+	  "%%%%EndProlog\n"
+	  "%%%%BeginSetup\n"
+	  "/DeviceRGB setcolorspace\n"
+	  "gl2psdict begin\n"
+	  "%%%%EndSetup\n"
+	  "%%%%Page: 1 1\n"
+	  "%%%%BeginPageSetup\n");
+
+  if(gl2ps->options & GL2PS_LANDSCAPE){
+    fprintf(gl2ps->stream,
+	    "%d 0 translate 90 rotate\n",
+	    gl2ps->viewport[3]);
+  }
+
+  fprintf(gl2ps->stream, 
+	  "%%%%EndPageSetup\n"
+	  "mark\n"
+	  "gsave\n"
+	  "1.0 1.0 scale\n");
+	  
+  if(gl2ps->options & GL2PS_DRAW_BACKGROUND){
+    if(gl2ps->colormode == GL_RGBA || gl2ps->colorsize == 0){
+      glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba);
+    }
+    else{
+      glGetIntegerv(GL_INDEX_CLEAR_VALUE, &index);
+      rgba[0] = gl2ps->colormap[index][0];
+      rgba[1] = gl2ps->colormap[index][1];
+      rgba[2] = gl2ps->colormap[index][2];
+      rgba[3] = 0.;
+    }
+    fprintf(gl2ps->stream,
+	    "%g %g %g C\n"
+	    "newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n"
+	    "closepath fill\n",
+	    rgba[0], rgba[1], rgba[2], 
+	    gl2ps->viewport[0], gl2ps->viewport[1], gl2ps->viewport[2], 
+	    gl2ps->viewport[1], gl2ps->viewport[2], gl2ps->viewport[3], 
+	    gl2ps->viewport[0], gl2ps->viewport[3]);
+  }
+}
+
+void gl2psPrintPostScriptColor(GL2PSrgba rgba){
+  if(!gl2psSameColor(gl2ps->lastrgba, rgba)){
+    gl2ps->lastrgba[0] = rgba[0];
+    gl2ps->lastrgba[1] = rgba[1];
+    gl2ps->lastrgba[2] = rgba[2];
+    fprintf(gl2ps->stream, "%g %g %g C\n", rgba[0], rgba[1], rgba[2]);
+  }
+}
+
+void gl2psResetPostScriptColor(void){
+  gl2ps->lastrgba[0] = gl2ps->lastrgba[1] = gl2ps->lastrgba[2] = -1.;
+}
+
+void gl2psPrintPostScriptPrimitive(void *a, void *){
+  GL2PSprimitive *prim;
+
+  prim = *(GL2PSprimitive**)a;
+
+  if(gl2ps->options & GL2PS_OCCLUSION_CULL && prim->culled) return;
+
+  switch(prim->type){
+  case GL2PS_PIXMAP :
+    gl2psPrintPostScriptPixmap(prim->verts[0].xyz[0], prim->verts[0].xyz[1],
+			       prim->image->width, prim->image->height,
+			       prim->image->format, prim->image->type,
+			       prim->image->pixels, gl2ps->stream);
+    break;
+  case GL2PS_TEXT :
+    gl2psPrintPostScriptColor(prim->verts[0].rgba);
+    fprintf(gl2ps->stream, "(%s) %g %g %d /%s S\n",
+	    prim->text->str, prim->verts[0].xyz[0], prim->verts[0].xyz[1],
+	    prim->text->fontsize, prim->text->fontname);
+    break;
+  case GL2PS_POINT :
+    gl2psPrintPostScriptColor(prim->verts[0].rgba);
+    fprintf(gl2ps->stream, "%g %g %g P\n", 
+	    prim->verts[0].xyz[0], prim->verts[0].xyz[1], 0.5*prim->width);
+    break;
+  case GL2PS_LINE :
+    if(gl2ps->lastlinewidth != prim->width){
+      gl2ps->lastlinewidth = prim->width;
+      fprintf(gl2ps->stream, "%g W\n", gl2ps->lastlinewidth);
+    }
+    if(prim->dash){
+      fprintf(gl2ps->stream, "[%d] 0 setdash\n", prim->dash);
+    }
+    if(gl2ps->shade && !gl2psVertsSameColor(prim)){
+      gl2psResetPostScriptColor();
+      fprintf(gl2ps->stream, "%g %g %g %g %g %g %g %g %g %g SL\n",
+	      prim->verts[1].xyz[0], prim->verts[1].xyz[1],
+	      prim->verts[1].rgba[0], prim->verts[1].rgba[1],
+	      prim->verts[1].rgba[2], prim->verts[0].xyz[0],
+	      prim->verts[0].xyz[1], prim->verts[0].rgba[0],
+	      prim->verts[0].rgba[1], prim->verts[0].rgba[2]);
+    }
+    else{
+      gl2psPrintPostScriptColor(prim->verts[0].rgba);
+      fprintf(gl2ps->stream, "%g %g %g %g L\n",
+	      prim->verts[1].xyz[0], prim->verts[1].xyz[1],
+	      prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
+    }
+    if(prim->dash){
+      fprintf(gl2ps->stream, "[] 0 setdash\n");
+    }
+    break;
+  case GL2PS_TRIANGLE :
+    if(gl2ps->shade && !gl2psVertsSameColor(prim)){
+      gl2psResetPostScriptColor();
+      fprintf(gl2ps->stream, "%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g ST\n",
+	      prim->verts[2].xyz[0], prim->verts[2].xyz[1],
+	      prim->verts[2].rgba[0], prim->verts[2].rgba[1],
+	      prim->verts[2].rgba[2], prim->verts[1].xyz[0],
+	      prim->verts[1].xyz[1], prim->verts[1].rgba[0],
+	      prim->verts[1].rgba[1], prim->verts[1].rgba[2],
+	      prim->verts[0].xyz[0], prim->verts[0].xyz[1],
+	      prim->verts[0].rgba[0], prim->verts[0].rgba[1],
+	      prim->verts[0].rgba[2]);
+    }
+    else{
+      gl2psPrintPostScriptColor(prim->verts[0].rgba);
+      fprintf(gl2ps->stream, "%g %g %g %g %g %g T\n",
+	      prim->verts[2].xyz[0], prim->verts[2].xyz[1],
+	      prim->verts[1].xyz[0], prim->verts[1].xyz[1],
+	      prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
+    }
+    break;
+  case GL2PS_QUADRANGLE :
+    gl2psMsg(GL2PS_WARNING, "There should not be any quad left to print");
+    break;
+  default :
+    gl2psMsg(GL2PS_ERROR, "Unknown type of primitive to print");
+    break;
+  }
+}
+
+void gl2psPrintPostScriptFooter(void){
+  fprintf(gl2ps->stream,
+	  "grestore\n"
+	  "showpage\n"
+	  "cleartomark\n"
+	  "%%%%PageTrailer\n"
+	  "%%%%Trailer\n"
+	  "end\n"
+	  "%%%%EOF\n");
+}
+
+void gl2psPrintPostScriptBeginViewport(GLint viewport[4]){
+  GLint index;
+  GLfloat rgba[4];
+  int x = viewport[0], y = viewport[1], w = viewport[2], h = viewport[3];
+
+  glRenderMode(GL_FEEDBACK);
+
+  fprintf(gl2ps->stream, 
+	  "gsave\n"
+	  "1.0 1.0 scale\n");
+	  
+  if(gl2ps->options & GL2PS_DRAW_BACKGROUND){
+    if(gl2ps->colormode == GL_RGBA || gl2ps->colorsize == 0){
+      glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba);
+    }
+    else{
+      glGetIntegerv(GL_INDEX_CLEAR_VALUE, &index);
+      rgba[0] = gl2ps->colormap[index][0];
+      rgba[1] = gl2ps->colormap[index][1];
+      rgba[2] = gl2ps->colormap[index][2];
+      rgba[3] = 0.;
+    }
+    fprintf(gl2ps->stream,
+	    "%g %g %g C\n"
+	    "newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n"
+	    "closepath fill\n",
+	    rgba[0], rgba[1], rgba[2], 
+	    x, y, x+w, y, x+w, y+h, x, y+h);
+    fprintf(gl2ps->stream,
+	    "newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n"
+	    "closepath clip\n",
+	    x, y, x+w, y, x+w, y+h, x, y+h);
+  }
+
+}
+
+GLint gl2psPrintPostScriptEndViewport(void){
+  GLint res;
+
+  res = gl2psPrintPrimitives();
+  fprintf(gl2ps->stream, "grestore\n");
+  return res;
+}
+
+/* The LaTeX routines */
+
+void gl2psPrintTeXHeader(void){
+  char name[256];
+  int i;
+
+  if(gl2ps->filename && strlen(gl2ps->filename) < 256){
+    for(i = strlen(gl2ps->filename)-1; i >= 0; i--){
+      if(gl2ps->filename[i] == '.'){
+	strncpy(name, gl2ps->filename, i);
+	name[i] = '\0';
+	break;
+      }
+    }
+    if(i <= 0) strcpy(name, gl2ps->filename);
+  }
+  else{
+    strcpy(name, "untitled");
+  }
+
+  fprintf(gl2ps->stream, 
+	  "\\setlength{\\unitlength}{1pt}\n"
+	  "\\begin{picture}(0,0)\n"
+	  "\\includegraphics{%s}\n"
+	  "\\end{picture}%%\n"
+	  "%s\\begin{picture}(%d,%d)(0,0)\n",
+	  name, (gl2ps->options & GL2PS_LANDSCAPE) ? "\\rotatebox{90}{" : "",
+	  gl2ps->viewport[2], gl2ps->viewport[3]);
+}
+
+void gl2psPrintTeXPrimitive(void *a, void *){
+  GL2PSprimitive *prim;
+
+  prim = *(GL2PSprimitive**)a;
+
+  switch(prim->type){
+  case GL2PS_TEXT :
+    fprintf(gl2ps->stream, "\\put(%g,%g){\\makebox(0,0)[lb]{%s}}\n",
+	    prim->verts[0].xyz[0], prim->verts[0].xyz[1], prim->text->str);
+    break;
+  default :
+    break;
+  }
+}
+
+void gl2psPrintTeXFooter(void){
+  fprintf(gl2ps->stream, "\\end{picture}%s\n",
+	  (gl2ps->options & GL2PS_LANDSCAPE) ? "}" : "");
+}
+
+void gl2psPrintTeXBeginViewport(GLint){
+}
+
+GLint gl2psPrintTeXEndViewport(void){
+  return GL2PS_SUCCESS;
+}
+
+/* The general primitive printing routine */
+
+GLint gl2psPrintPrimitives(void){
+  GL2PSbsptree *root;
+  GL2PSxyz eye = {0., 0., 100000.};
+  GLint shademodel, res;
+  void (*pprim)(void *a, void *b) = 0;
+
+  glGetIntegerv(GL_SHADE_MODEL, &shademodel);
+  gl2ps->shade = (shademodel == GL_SMOOTH);
+
+  if(gl2ps->format == GL2PS_TEX){
+    res = GL2PS_SUCCESS;
+  }
+  else{
+    res = gl2psParseFeedbackBuffer();
+  }
+
+  if(res == GL2PS_SUCCESS){
+
+    switch(gl2ps->format){
+    case GL2PS_TEX :
+      pprim = gl2psPrintTeXPrimitive;
+      break;
+    case GL2PS_PS :
+    case GL2PS_EPS :
+      pprim = gl2psPrintPostScriptPrimitive;
+      break;
+    }
+
+    switch(gl2ps->sort){
+    case GL2PS_NO_SORT :
+      gl2psListAction(gl2ps->primitives, pprim);
+      gl2psListAction(gl2ps->primitives, gl2psFreePrimitive);
+      /* reset the primitive list, waiting for the next viewport */
+      gl2psListReset(gl2ps->primitives);
+      break;
+    case GL2PS_SIMPLE_SORT :
+      gl2psListSort(gl2ps->primitives, gl2psCompareDepth);
+      if(gl2ps->options & GL2PS_OCCLUSION_CULL){
+	gl2psListAction(gl2ps->primitives, gl2psAddInImageTree);
+        gl2psFreeBspImageTree(&gl2ps->imagetree);
+      }
+      gl2psListActionInverse(gl2ps->primitives, pprim);
+      gl2psListAction(gl2ps->primitives, gl2psFreePrimitive);
+      /* reset the primitive list, waiting for the next viewport */
+      gl2psListReset(gl2ps->primitives);
+      break;
+    case GL2PS_BSP_SORT :
+      root = (GL2PSbsptree*)gl2psMalloc(sizeof(GL2PSbsptree));
+      gl2psBuildBspTree(root, gl2ps->primitives);
+      if(gl2ps->boundary) gl2psBuildPolygonBoundary(root);
+      if(gl2ps->options & GL2PS_OCCLUSION_CULL){
+	gl2psTraverseBspTree(root, eye, -(float)GL2PS_EPSILON, gl2psLess,
+			     gl2psAddInImageTree);
+	gl2psFreeBspImageTree(&gl2ps->imagetree);
+      }
+      gl2psTraverseBspTree(root, eye, (float)GL2PS_EPSILON, gl2psGreater, 
+			   pprim);
+      gl2psFreeBspTree(&root);
+      /* reallocate the primitive list (it's been deleted by
+	 gl2psBuildBspTree) in case there is another viewport */
+      gl2ps->primitives = gl2psListCreate(500, 500, sizeof(GL2PSprimitive*));
+      break;
+    default :
+      gl2psMsg(GL2PS_ERROR, "Unknown sorting algorithm: %d", gl2ps->sort);
+      res = GL2PS_ERROR;
+      break;
+    }
+    fflush(gl2ps->stream);
+
+  }
+
+  return res;
+}
+
+/* The public routines */
+
+GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer, 
+				  GLint viewport[4], GLint format, GLint sort,
+				  GLint options, GLint colormode,
+				  GLint colorsize, GL2PSrgba *colormap,
+				  GLint nr, GLint ng, GLint nb, GLint buffersize,
+				  FILE *stream, const char *filename){
+  int i;
+
+  gl2ps = (GL2PScontext*)gl2psMalloc(sizeof(GL2PScontext));
+  gl2ps->maxbestroot = 10;
+  gl2ps->format = format;
+  gl2ps->title = title;
+  gl2ps->producer = producer;
+  gl2ps->filename = filename;
+  gl2ps->sort = sort;
+  gl2ps->options = options;
+  for(i = 0; i < 4; i++){
+    gl2ps->viewport[i] = viewport[i];
+  }
+  gl2ps->threshold[0] = nr ? 1./(GLfloat)nr : 0.032;
+  gl2ps->threshold[1] = ng ? 1./(GLfloat)ng : 0.017;
+  gl2ps->threshold[2] = nb ? 1./(GLfloat)nb : 0.05;
+  gl2ps->colormode = colormode;
+  gl2ps->buffersize = buffersize > 0 ? buffersize : 2048 * 2048;
+  for(i = 0; i < 4; i++){
+    gl2ps->lastrgba[i] = -1.;
+  }
+  gl2ps->lastlinewidth = -1.;
+  gl2ps->imagetree = NULL;
+
+  if(gl2ps->colormode == GL_RGBA){
+    gl2ps->colorsize = 0;
+    gl2ps->colormap = NULL;
+  }
+  else if(gl2ps->colormode == GL_COLOR_INDEX){
+    if(!colorsize || !colormap){
+      gl2psMsg(GL2PS_ERROR, "Missing colormap for GL_COLOR_INDEX rendering");
+      gl2psFree(gl2ps);
+      gl2ps = NULL;
+      return GL2PS_ERROR;
+    }
+    gl2ps->colorsize = colorsize;
+    gl2ps->colormap = (GL2PSrgba*)gl2psMalloc(gl2ps->colorsize * sizeof(GL2PSrgba));
+    memcpy(gl2ps->colormap, colormap, gl2ps->colorsize * sizeof(GL2PSrgba));
+  }
+  else{
+    gl2psMsg(GL2PS_ERROR, "Unknown color mode in gl2psBeginPage");
+    gl2psFree(gl2ps);
+    gl2ps = NULL;
+    return GL2PS_ERROR;
+  }
+
+  if(!stream){
+    gl2psMsg(GL2PS_ERROR, "Bad file pointer");
+    gl2psFree(gl2ps);
+    gl2ps = NULL;
+    return GL2PS_ERROR;
+  }
+  else{
+    gl2ps->stream = stream;
+    /* In case gl2psEndPage failed (e.g. due to a GL2PS_OVERFLOW) and
+       we didn't reopen the stream before calling gl2psBeginPage
+       again, we need to rewind the stream */
+    rewind(gl2ps->stream);
+  }
+
+  switch(gl2ps->format){
+  case GL2PS_TEX :
+    gl2psPrintTeXHeader();
+    break;
+  case GL2PS_PS :
+  case GL2PS_EPS :
+    gl2psPrintPostScriptHeader();
+    break;
+  default :
+    gl2psMsg(GL2PS_ERROR, "Unknown output format: %d", gl2ps->format);
+    gl2psFree(gl2ps);
+    gl2ps = NULL;
+    return GL2PS_ERROR;
+  }
+
+  gl2ps->primitives = gl2psListCreate(500, 500, sizeof(GL2PSprimitive*));
+  gl2ps->feedback = (GLfloat*)gl2psMalloc(gl2ps->buffersize * sizeof(GLfloat));
+  glFeedbackBuffer(gl2ps->buffersize, GL_3D_COLOR, gl2ps->feedback);
+  glRenderMode(GL_FEEDBACK);  
+
+  return GL2PS_SUCCESS;
+}
+
+GL2PSDLL_API GLint gl2psEndPage(void){
+  GLint res;
+
+  if(!gl2ps) return GL2PS_UNINITIALIZED;
+
+  res = gl2psPrintPrimitives();
+
+  /* print the footer even if gl2psPrintPrimitives didn't succeed, so
+     that we end up with a valid file */
+  switch(gl2ps->format){
+  case GL2PS_TEX :
+    gl2psPrintTeXFooter();
+    break;
+  case GL2PS_PS :
+  case GL2PS_EPS :
+    gl2psPrintPostScriptFooter();
+    break;
+  }
+
+  fflush(gl2ps->stream);
+
+  gl2psListDelete(gl2ps->primitives);
+  gl2psFree(gl2ps->colormap);
+  gl2psFree(gl2ps->feedback);
+  gl2psFree(gl2ps);
+  gl2ps = NULL;
+
+  return res;
+}
+
+GL2PSDLL_API GLint gl2psBeginViewport(GLint viewport[4]){
+  if(!gl2ps) return GL2PS_UNINITIALIZED;
+
+  switch(gl2ps->format){
+  case GL2PS_EPS :
+    gl2psPrintPostScriptBeginViewport(viewport);
+    break;
+  default :
+    /* FIXME: handle other formats */
+    break;
+  }
+  
+  return GL2PS_SUCCESS;
+}
+
+GL2PSDLL_API GLint gl2psEndViewport(void){
+  GLint res;
+
+  if(!gl2ps) return GL2PS_UNINITIALIZED;
+
+  switch(gl2ps->format){
+  case GL2PS_EPS :
+    res = gl2psPrintPostScriptEndViewport();
+    break;
+  default :
+    /* FIXME: handle other formats */
+    res = GL2PS_SUCCESS;
+    break;
+  }
+
+  return res;
+}
+
+GL2PSDLL_API GLint gl2psText(const char *str, const char *fontname, GLshort fontsize){
+  GLfloat pos[4];
+  GL2PSprimitive *prim;
+  GLboolean valid;
+
+  if(!gl2ps || !str) return GL2PS_UNINITIALIZED;
+
+  if(gl2ps->options & GL2PS_NO_TEXT) return GL2PS_SUCCESS;
+
+  glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid);
+  if(!valid) return GL2PS_SUCCESS; /* the primitive is culled */
+
+  glGetFloatv(GL_CURRENT_RASTER_POSITION, pos);
+
+  prim = (GL2PSprimitive *)gl2psMalloc(sizeof(GL2PSprimitive));
+  prim->type = GL2PS_TEXT;
+  prim->boundary = 0;
+  prim->numverts = 1;
+  prim->verts = (GL2PSvertex *)gl2psMalloc(sizeof(GL2PSvertex));
+  prim->verts[0].xyz[0] = pos[0];
+  prim->verts[0].xyz[1] = pos[1];
+  prim->verts[0].xyz[2] = GL2PS_DEPTH_FACT * pos[2];
+  prim->depth = pos[2];
+  prim->culled = 0;
+  prim->dash = 0;
+  prim->width = 1;
+  glGetFloatv(GL_CURRENT_RASTER_COLOR, prim->verts[0].rgba);
+  prim->text = (GL2PSstring*)gl2psMalloc(sizeof(GL2PSstring));
+  prim->text->str = (char*)gl2psMalloc((strlen(str)+1)*sizeof(char));
+  strcpy(prim->text->str, str); 
+  prim->text->fontname = (char*)gl2psMalloc((strlen(fontname)+1)*sizeof(char));
+  strcpy(prim->text->fontname, fontname);
+  prim->text->fontsize = fontsize;
+
+  gl2psListAdd(gl2ps->primitives, &prim);
+
+  return GL2PS_SUCCESS;
+}
+
+GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height,
+				   GLint xorig, GLint yorig,
+				   GLenum format, GLenum type, 
+				   const void *pixels){
+  int size;
+  GLfloat pos[4];
+  GL2PSprimitive *prim;
+  GLboolean valid;
+
+  if(!gl2ps || !pixels) return GL2PS_UNINITIALIZED;
+
+  if((width <= 0) || (height <= 0)) return GL2PS_ERROR;
+
+  if(gl2ps->options & GL2PS_NO_PIXMAP) return GL2PS_SUCCESS;
+
+  if(format != GL_RGB || type != GL_FLOAT){
+    gl2psMsg(GL2PS_ERROR, "gl2psDrawPixels only implemented for GL_RGB, GL_FLOAT pixels");
+    return GL2PS_ERROR;
+  }
+
+  glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid);
+  if(!valid) return GL2PS_SUCCESS; /* the primitive is culled */
+
+  glGetFloatv(GL_CURRENT_RASTER_POSITION, pos);
+
+  prim = (GL2PSprimitive *)gl2psMalloc(sizeof(GL2PSprimitive));
+  prim->type = GL2PS_PIXMAP;
+  prim->boundary = 0;
+  prim->numverts = 1;
+  prim->verts = (GL2PSvertex *)gl2psMalloc(sizeof(GL2PSvertex));
+  prim->verts[0].xyz[0] = pos[0] + xorig;
+  prim->verts[0].xyz[1] = pos[1] + yorig;
+  prim->verts[0].xyz[2] = GL2PS_DEPTH_FACT * pos[2];
+  prim->depth = pos[2];
+  prim->culled = 0;
+  prim->dash = 0;
+  prim->width = 1;
+  glGetFloatv(GL_CURRENT_RASTER_COLOR, prim->verts[0].rgba);
+  prim->image = (GL2PSimage*)gl2psMalloc(sizeof(GL2PSimage));
+  prim->image->width = width;
+  prim->image->height = height;
+  prim->image->format = format;
+  prim->image->type = type;
+  size = height*width*3*sizeof(GLfloat); /* FIXME: generalize to other types/formats */
+  prim->image->pixels = (GLfloat*)gl2psMalloc(size);
+  memcpy(prim->image->pixels, pixels, size);
+
+  gl2psListAdd(gl2ps->primitives, &prim);
+
+  return GL2PS_SUCCESS;
+}
+
+GL2PSDLL_API GLint gl2psEnable(GLint mode){
+  if(!gl2ps) return GL2PS_UNINITIALIZED;
+
+  switch(mode){
+  case GL2PS_POLYGON_OFFSET_FILL :
+    glPassThrough(GL2PS_BEGIN_POLYGON_OFFSET_FILL);
+    glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &gl2ps->offset[0]);
+    glGetFloatv(GL_POLYGON_OFFSET_UNITS, &gl2ps->offset[1]);
+    break;
+  case GL2PS_POLYGON_BOUNDARY :
+    glPassThrough(GL2PS_BEGIN_POLYGON_BOUNDARY);
+    break;
+  case GL2PS_LINE_STIPPLE :
+    glPassThrough(GL2PS_BEGIN_LINE_STIPPLE);
+    break;
+  default :
+    gl2psMsg(GL2PS_WARNING, "Unknown mode in gl2psEnable: %d", mode);
+    return GL2PS_WARNING;
+  }
+
+  return GL2PS_SUCCESS;
+}
+
+GL2PSDLL_API GLint gl2psDisable(GLint mode){
+  if(!gl2ps) return GL2PS_UNINITIALIZED;
+
+  switch(mode){
+  case GL2PS_POLYGON_OFFSET_FILL :
+    glPassThrough(GL2PS_END_POLYGON_OFFSET_FILL);
+    break;
+  case GL2PS_POLYGON_BOUNDARY :
+    glPassThrough(GL2PS_END_POLYGON_BOUNDARY);
+    break;
+  case GL2PS_LINE_STIPPLE :
+    glPassThrough(GL2PS_END_LINE_STIPPLE);
+    break;
+  default :
+    gl2psMsg(GL2PS_WARNING, "Unknown mode in gl2psDisable: %d", mode);
+    return GL2PS_WARNING;
+  }
+
+  return GL2PS_SUCCESS;
+}
+
+GL2PSDLL_API GLint gl2psPointSize(GLfloat value){
+  if(!gl2ps) return GL2PS_UNINITIALIZED;
+
+  glPassThrough(GL2PS_SET_POINT_SIZE);
+  glPassThrough(value);
+  
+  return GL2PS_SUCCESS;
+}
+
+GL2PSDLL_API GLint gl2psLineWidth(GLfloat value){
+  if(!gl2ps) return GL2PS_UNINITIALIZED;
+
+  glPassThrough(GL2PS_SET_LINE_WIDTH);
+  glPassThrough(value);
+
+  return GL2PS_SUCCESS;
+}
+
+#endif
Index: /trunk/geant4/visualization/OpenInventor/src/gl2ps.h
===================================================================
--- /trunk/geant4/visualization/OpenInventor/src/gl2ps.h	(revision 529)
+++ /trunk/geant4/visualization/OpenInventor/src/gl2ps.h	(revision 529)
@@ -0,0 +1,258 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+/*
+ * GL2PS, an OpenGL to PostScript Printing Library
+ * Copyright (C) 1999-2003  Christophe Geuzaine
+ *
+ * $Id: gl2ps.h,v 1.5 2006/06/29 21:23:11 gunter Exp $
+ *
+ * E-mail: geuz@geuz.org
+ * URL: http://www.geuz.org/gl2ps/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifndef __GL2PS_H__
+#define __GL2PS_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <cmath>
+
+/* To generate a Windows dll, you have to define GL2PSDLL at compile
+   time */
+
+#ifdef WIN32
+#  include <windows.h>
+#  ifdef GL2PSDLL
+#    ifdef GL2PSDLL_EXPORTS
+#      define GL2PSDLL_API __declspec(dllexport)
+#    else
+#      define GL2PSDLL_API __declspec(dllimport)
+#    endif
+#  else
+#    define GL2PSDLL_API
+#  endif
+#else
+#  define GL2PSDLL_API
+#endif
+
+#ifdef __APPLE__
+#  include <OpenGL/gl.h>
+#else
+#  include <GL/gl.h>
+#endif
+
+
+#define GL2PS_VERSION                    0.8
+#define GL2PS_NONE                       0
+
+/* Output file format */
+
+#define GL2PS_PS                         1
+#define GL2PS_EPS                        2
+#define GL2PS_TEX                        3
+
+/* Sorting algorithms */
+
+#define GL2PS_NO_SORT                    1
+#define GL2PS_SIMPLE_SORT                2
+#define GL2PS_BSP_SORT                   3
+
+/* Options for gl2psBeginPage */
+
+#define GL2PS_DRAW_BACKGROUND            (1<<0)
+#define GL2PS_SIMPLE_LINE_OFFSET         (1<<1)
+#define GL2PS_SILENT                     (1<<2)
+#define GL2PS_BEST_ROOT                  (1<<3)
+#define GL2PS_OCCLUSION_CULL             (1<<4)
+#define GL2PS_NO_TEXT                    (1<<5)
+#define GL2PS_LANDSCAPE                  (1<<6)
+#define GL2PS_NO_PS3_SHADING             (1<<7)
+#define GL2PS_NO_PIXMAP                  (1<<8)
+
+/* Arguments for gl2psEnable/gl2psDisable */
+
+#define GL2PS_POLYGON_OFFSET_FILL        1
+#define GL2PS_POLYGON_BOUNDARY           2
+#define GL2PS_LINE_STIPPLE               3
+
+/* Magic numbers */
+
+#define GL2PS_EPSILON                    5.e-3
+#define GL2PS_DEPTH_FACT                 1000.0
+#define GL2PS_SIMPLE_OFFSET              0.05
+#define GL2PS_SIMPLE_OFFSET_LARGE        1.0
+#define GL2PS_ZERO(arg)                  (std::fabs(arg)<1.e-20)
+/*#define GL2PS_ZERO(arg)                ((arg)==0.0)*/
+
+/* Message levels and error codes */
+
+#define GL2PS_SUCCESS                    0
+#define GL2PS_INFO                       1
+#define GL2PS_WARNING                    2
+#define GL2PS_ERROR                      3
+#define GL2PS_NO_FEEDBACK                4
+#define GL2PS_OVERFLOW                   5
+#define GL2PS_UNINITIALIZED              6
+
+/* Primitive types */
+
+#define GL2PS_TEXT                       1
+#define GL2PS_POINT                      2
+#define GL2PS_LINE                       3
+#define GL2PS_QUADRANGLE                 4
+#define GL2PS_TRIANGLE                   5
+#define GL2PS_PIXMAP                     6
+
+/* BSP tree primitive comparison */
+
+#define GL2PS_COINCIDENT                 1
+#define GL2PS_IN_FRONT_OF                2
+#define GL2PS_IN_BACK_OF                 3
+#define GL2PS_SPANNING                   4
+
+/* 2D BSP tree primitive comparison */
+
+#define GL2PS_POINT_COINCIDENT           0
+#define GL2PS_POINT_INFRONT              1
+#define GL2PS_POINT_BACK                 2
+
+/* Pass through options */
+
+#define GL2PS_BEGIN_POLYGON_OFFSET_FILL  1
+#define GL2PS_END_POLYGON_OFFSET_FILL    2
+#define GL2PS_BEGIN_POLYGON_BOUNDARY     3
+#define GL2PS_END_POLYGON_BOUNDARY       4
+#define GL2PS_BEGIN_LINE_STIPPLE         5
+#define GL2PS_END_LINE_STIPPLE           6
+#define GL2PS_SET_POINT_SIZE             7
+#define GL2PS_SET_LINE_WIDTH             8
+
+typedef GLfloat GL2PSrgba[4];
+typedef GLfloat GL2PSxyz[3];
+typedef GLfloat GL2PSplane[4];
+
+typedef struct _GL2PSbsptree2d GL2PSbsptree2d;
+
+struct _GL2PSbsptree2d {
+  GL2PSplane plane;
+  GL2PSbsptree2d *front, *back;
+};
+
+typedef struct {
+  GLint nmax, size, incr, n;
+  char *array;
+} GL2PSlist;
+
+typedef struct _GL2PSbsptree GL2PSbsptree;
+
+struct _GL2PSbsptree {
+  GL2PSplane plane;
+  GL2PSlist *primitives;
+  GL2PSbsptree *front, *back;
+};
+
+typedef struct {
+  GL2PSxyz xyz;
+  GL2PSrgba rgba;
+} GL2PSvertex;
+
+typedef struct {
+  GLshort fontsize;
+  char *str, *fontname;
+} GL2PSstring;
+
+typedef struct {
+  GLsizei width, height;
+  GLenum format, type;
+  GLfloat *pixels;
+} GL2PSimage;
+
+typedef struct {
+  GLshort type, numverts;
+  char boundary, dash, culled;
+  GLfloat width, depth;
+  GL2PSvertex *verts;
+  GL2PSstring *text;
+  GL2PSimage *image;
+} GL2PSprimitive;
+
+typedef struct {
+  GLint format, sort, options, colorsize, colormode, buffersize, maxbestroot;
+  const char *title, *producer, *filename;
+  GLboolean shade, boundary;
+  GLfloat *feedback, offset[2];
+  GLint viewport[4];
+  GL2PSrgba *colormap, lastrgba, threshold;
+  float lastlinewidth;
+  GL2PSlist *primitives;
+  GL2PSbsptree2d *imagetree;
+  FILE *stream;
+} GL2PScontext;
+
+/* public functions */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer, 
+				  GLint viewport[4], GLint format, GLint sort,
+				  GLint options, GLint colormode,
+				  GLint colorsize, GL2PSrgba *colormap, 
+				  GLint nr, GLint ng, GLint nb, GLint buffersize,
+				  FILE *stream, const char *filename);
+GL2PSDLL_API GLint gl2psEndPage(void);
+GL2PSDLL_API GLint gl2psBeginViewport(GLint viewport[4]);
+GL2PSDLL_API GLint gl2psEndViewport(void);
+GL2PSDLL_API GLint gl2psText(const char *str, const char *fontname, GLshort fontsize);
+GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height,
+				   GLint xorig, GLint yorig,
+				   GLenum format, GLenum type, const void *pixels);
+GL2PSDLL_API GLint gl2psEnable(GLint mode);
+GL2PSDLL_API GLint gl2psDisable(GLint mode);
+GL2PSDLL_API GLint gl2psPointSize(GLfloat value);
+GL2PSDLL_API GLint gl2psLineWidth(GLfloat value);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __GL2PS_H__ */
