##################################################
# primitives.slf
#

tclinit { 
######################################################################
# START: slideui.tcl
#

######################################################################
# START: SLFCONSTS.tcl
#

# SLIDE Flag Constants
#
# To be used while debugging tcl code with the "wish" program

# On/Off Flags
set SLF_OFF 0
set SLF_ON 1

# Solid Flags
set SLF_SOLID 0
set SLF_HOLLOW 1

# Shading Flags
set SLF_INHERIT 0
set SLF_WIRE 1
set SLF_FLAT 2
set SLF_GOURAUD 3
set SLF_PHONG 4

# LOD Flags
set SLF_OFF 0
set SLF_BOUND 1
set SLF_EDGES 2
set SLF_FULL 3

# Projection Flags
set SLF_PARALLEL 0
set SLF_PERSPECTIVE 1

# Lighting Type Flags
set SLF_AMBIENT 0
set SLF_DIRECTIONAL 1
set SLF_POINT 2
set SLF_SPOT 3

#
# END  : SLFCONSTS.tcl
######################################################################


######################################################################
# CreateRadioButtonFrame 
#   Parameters:
#     parent   - parent widget name
#     name     - name of the radio button frame widget (convention: rbf<name>)
#     var      - name of the global variable which will be modified
#     text     - text name to be displayed on the widget
#     enumList - enumerated list of fields and values { {field0 value0} ... }
#
#   Actions:
#     Creates a container frame widget
#     Creates and packs a title label and radio buttons inside the frame
#
#   Returns:
#     The name of the unpacked container frame widget
#
proc CreateRadioButtonFrame { parent name var text enumList } {
    set root $parent.f$name

    frame $root -relief raised -bd 2

    #global $var
    #set $var [lindex [lindex $enumList $default] 1]

    label $root.lTitle -text $text
    pack $root.lTitle -side top -fill x

    foreach choice $enumList {
	set field [lindex $choice 0]
	set value [lindex $choice 1]
	set widgetButton $root.rb$field

	radiobutton $widgetButton \
		-text $field \
		-variable $var \
		-value $value \
		-anchor w
	pack $widgetButton -side top -fill x
    }

    return $root
}

proc CalculateTickInterval { min max tickints } {
    return [expr ($max - $min)/$tickints]
}

######################################################################
# CreateScale 
#   Parameters:
#     parent   - parent widget name
#     name     - name of the widget (convention: scale<name>)
#     var      - name of the global variable which will be modified
#     text     - text name to be displayed on the widget
#     min      - minimum value for the variable
#     max      - maximum value for the variable
#     resolution - resolution for changing the value
#     tickints - how many tick marks on the scale
#     orient   - horizontal or vertical
#     length   - length of the scale
#
#   Actions:
#     Creates a scale widget
#
#   Returns:
#     The name of the unpacked scale widget
#
proc CreateScale { parent name var text min max resolution {tickints 1} {orient horizontal} {length 0} } {
    set widgetScale $parent.$name
    
    #global $var
    #set $var $default

    set tickinterval [CalculateTickInterval $min $max $tickints]

    if { $length > 0 } {
	scale $widgetScale \
		-label $text \
		-from $min \
		-to $max \
		-resolution $resolution \
		-tickint $tickinterval \
		-length $length \
		-orient $orient \
		-variable $var
    } else {
	scale $widgetScale \
		-label $text \
		-from $min \
		-to $max \
		-resolution $resolution \
		-tickint $tickinterval \
		-orient $orient \
		-variable $var
    }
    
    return $widgetScale
}

#fieldList is a list of SLIDE constants { field0 field1 ... }
#returns { {field0 value0} ... }
proc CreateSLIDEEnumList { fieldList } {
    set enumList {}

    foreach field $fieldList {
	global $field
	lappend enumList "[subst $field] [subst $$field]"
    }

    return $enumList
}

######################################################################
# CreateSLIDEOnOffEnumFrame
#   Parameters:
#     parent   - parent widget name
#     name     - name of the widget
#     var      - name of the global variable which will be modified
#     text     - text name to be displayed on the widget
#
#   Actions:
#     Creates an On/Off UI contained in a frame widget
#
#   Returns:
#     The name of the unpacked frame widget
#
proc CreateSLIDEOnOffEnumFrame { parent name var text } {
    set lodList [list SLF_OFF SLF_ON]
    set enumList [CreateSLIDEEnumList $lodList]

    return [CreateRadioButtonFrame $parent $name $var $text $enumList]
}

######################################################################
# CreateSLIDETextureFields
#   Parameters:
#     this     - name of the associative array
#
#   Actions:
#     Creates the 4 texture coordinate point fields for a standard surface
#
#   Returns:
#     True
#
proc CreateSLIDETextureFields { this } {
    global $this

    for { set i 0 } { $i < 4 } { incr i } {
	for { set j 0 } { $j < 3 } { incr j } {
	    set [subst $this](texture_[subst $i]_[subst $j]) \
		    [if { ( $j == 0 && ( $i == 1 || $i == 2 ) ) || \
		          ( $j == 1 && ( $i & 0x2 ) ) } \
			  { expr 1.0 } else { expr 0.0 }]
	    set [subst $this](texture_[subst $i]_[subst $j]_min) 0.0
	    set [subst $this](texture_[subst $i]_[subst $j]_max) 4.0
	    set [subst $this](texture_[subst $i]_[subst $j]_resolution) 0.01
	}
    }

    return 1
}

######################################################################
# CreateSLIDESolidField
#   Parameters:
#     this     - name of the associative array
#
#   Actions:
#     Creates a field for the solid enumerated type
#
#   Returns:
#     Initial value for the field
#
proc CreateSLIDESolidField { this } {
    global $this
    global SLF_SOLID

    set [subst $this](solid) $SLF_SOLID

    return [subst $[subst $this](solid)]
}

######################################################################
# CreateSLIDESolidEnumFrame
#   Parameters:
#     parent   - parent widget name
#     name     - name of the widget
#     var      - name of the global variable which will be modified
#     text     - text name to be displayed on the widget
#
#   Actions:
#     Creates a Solid UI contained in a frame widget
#
#   Returns:
#     The name of the unpacked frame widget
#
proc CreateSLIDESolidEnumFrame { parent name var text } {
    set lodList [list SLF_SOLID SLF_HOLLOW]
    set enumList [CreateSLIDEEnumList $lodList]

    return [CreateRadioButtonFrame $parent $name $var $text $enumList]
}

######################################################################
# CreateSLIDEShadingField
#   Parameters:
#     this     - name of the associative array
#
#   Actions:
#     Creates a field for the shading enumerated type
#
#   Returns:
#     Initial value for the field
#
proc CreateSLIDEShadingField { this } {
    global $this
    global SLF_INHERIT

    set [subst $this](shading) $SLF_INHERIT

    return [subst $[subst $this](shading)]
}

######################################################################
# CreateSLIDEShadingEnumFrame
#   Parameters:
#     parent   - parent widget name
#     name     - name of the widget
#     var      - name of the global variable which will be modified
#     text     - text name to be displayed on the widget
#
#   Actions:
#     Creates a Shading UI contained in a frame widget
#
#   Returns:
#     The name of the unpacked frame widget
#
proc CreateSLIDEShadingEnumFrame { parent name var text } {
    set lodList [list SLF_INHERIT SLF_WIRE SLF_FLAT SLF_GOURAUD]
    set enumList [CreateSLIDEEnumList $lodList]

    return [CreateRadioButtonFrame $parent $name $var $text $enumList]
}

######################################################################
# CreateSLIDELODField
#   Parameters:
#     this     - name of the associative array
#
#   Actions:
#     Creates a field for the LOD enumerated type
#
#   Returns:
#     Initial value for the field
#
proc CreateSLIDELODField { this } {
    global $this
    global SLF_FULL

    set [subst $this](lod) $SLF_FULL

    return [subst $[subst $this](lod)]
}

######################################################################
# CreateSLIDELODEnumFrame
#   Parameters:
#     parent   - parent widget name
#     name     - name of the widget
#     var      - name of the global variable which will be modified
#     text     - text name to be displayed on the widget
#
#   Actions:
#     Creates a LOD UI contained in a frame widget
#
#   Returns:
#     The name of the unpacked frame widget
#
proc CreateSLIDELODEnumFrame { parent name var text } {
    set lodList [list SLF_OFF SLF_BOUND SLF_EDGES SLF_FULL]
    set enumList [CreateSLIDEEnumList $lodList]

    return [CreateRadioButtonFrame $parent $name $var $text $enumList]
}

######################################################################
# CreateSLIDEProjectionEnumFrame
#   Parameters:
#     parent   - parent widget name
#     name     - name of the widget
#     var      - name of the global variable which will be modified
#     text     - text name to be displayed on the widget
#
#   Actions:
#     Creates a Projection UI contained in a frame widget
#
#   Returns:
#     The name of the unpacked frame widget
#
proc CreateSLIDEProjectionEnumFrame { parent name var text } {
    set lodList [list SLF_PERSPECTIVE SLF_PARALLEL]
    set enumList [CreateSLIDEEnumList $lodList]

    return [CreateRadioButtonFrame $parent $name $var $text $enumList]
}

######################################################################
# CreateSLIDELightEnumFrame
#   Parameters:
#     parent   - parent widget name
#     name     - name of the widget
#     var      - name of the global variable which will be modified
#     text     - text name to be displayed on the widget
#
#   Actions:
#     Creates a Light Enum UI contained in a frame widget
#
#   Returns:
#     The name of the unpacked frame widget
#
proc CreateSLIDELightEnumFrame { parent name var text } {
    set lodList [list SLF_AMBIENT SLF_DIRECTIONAL SLF_POINT SLF_SPOT]
    set enumList [CreateSLIDEEnumList $lodList]

    return [CreateRadioButtonFrame $parent $name $var $text $enumList]
}

######################################################################
# CreateSLIDEFogEnumFrame
#   Parameters:
#     parent   - parent widget name
#     name     - name of the widget
#     var      - name of the global variable which will be modified
#     text     - text name to be displayed on the widget
#
#   Actions:
#     Creates a Fog Enum UI contained in a frame widget
#
#   Returns:
#     The name of the unpacked frame widget
#
proc CreateSLIDEFogEnumFrame { parent name var text } {
    set lodList [list SLF_LINEAR SLF_EXP SLF_EXP2]
    set enumList [CreateSLIDEEnumList $lodList]

    return [CreateRadioButtonFrame $parent $name $var $text $enumList]
}

######################################################################
# CreateSLIDEStencilEnumFrame
#   Parameters:
#     parent   - parent widget name
#     name     - name of the widget
#     var      - name of the global variable which will be modified
#     text     - text name to be displayed on the widget
#
#   Actions:
#     Creates a Stencil Enum UI contained in a frame widget
#
#   Returns:
#     The name of the unpacked frame widget
#
proc CreateSLIDEStencilEnumFrame { parent name var text } {
    set lodList [list SLF_BOTH SLF_ODD SLF_EVEN]
    set enumList [CreateSLIDEEnumList $lodList]

    return [CreateRadioButtonFrame $parent $name $var $text $enumList]
}

######################################################################
# CreateSLIDERatioEnumFrame
#   Parameters:
#     parent   - parent widget name
#     name     - name of the widget
#     var      - name of the global variable which will be modified
#     text     - text name to be displayed on the widget
#
#   Actions:
#     Creates a Ratio Enum UI contained in a frame widget
#
#   Returns:
#     The name of the unpacked frame widget
#
proc CreateSLIDERatioEnumFrame { parent name var text } {
    set lodList [list SLF_FIXED SLF_ANY SLF_FULL_SCREEN]
    set enumList [CreateSLIDEEnumList $lodList]

    return [CreateRadioButtonFrame $parent $name $var $text $enumList]
}

######################################################################
# CreateSLIDESquareObject
#   Parameters:
#     name     - name of the square
#
#   Actions:
#     Creates an associative array with initialized fields for a square
#
#   Returns:
#     The name of the associative array
#
proc CreateSLIDESquareObject { name } {
    set this $name

    global $this

    # texture
    CreateSLIDETextureFields $this

    # solid
    CreateSLIDESolidField $this

    # shading
    CreateSLIDEShadingField $this

    # lod
    CreateSLIDELODField $this

    return $this
}

######################################################################
# CreateSLIDESquareUI
#   Parameters:
#     parent   - parent widget name
#     name     - name of the square
#
#   Actions:
#     Creates a square UI contained in a frame widget
#
#   Returns:
#     The name of the unpacked frame widget
#
proc CreateSLIDESquareUI { parent name } {
    set root $parent.f$name
    set this $name

    global $this

    frame $root

    ##################################################
    # Enums Frame
    frame $root.fEnums
    
    ##############################
    # lod
    set widget [CreateSLIDELODEnumFrame $root.fEnums lod \
	    [subst $this](lod) "LOD"]
    pack $widget -side left -fill y

    ##############################
    # shading
    set widget [CreateSLIDEShadingEnumFrame $root.fEnums shading \
	    [subst $this](shading) "Shading"]
    pack $widget -side left -fill y

    ##############################
    # solid
    set widget [CreateSLIDESolidEnumFrame $root.fEnums solid \
	    [subst $this](solid) "Solid"]
    pack $widget -side left -fill y

    pack $root.fEnums -side top -fill x

    ##################################################
    # Scales Frame
    frame $root.fScales
    
    ##############################
    # texture
    for { set i 0 } { $i < 4 } { incr i } {
	frame $root.fScales.scaleTexture_[subst $i]
	for { set j 0 } { $j < 2 } { incr j } {
	    set widget [CreateScale $root.fScales.scaleTexture_[subst $i] \
		    scaleTexture_[subst $i]_[subst $j] \
		    [subst $this](texture_[subst $i]_[subst $j]) \
		    "Texture($i)($j)" \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_min)] \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_max)] \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_resolution)]]
	    pack $widget -side left -fill y
	}
	pack $root.fScales.scaleTexture_[subst $i] -side top -fill x
    }
    pack $root.fScales -side top -fill x

    return $root
}

######################################################################
# CreateSLIDESphereObject
#   Parameters:
#     name     - name of the sphere
#
#   Actions:
#     Creates an associative array with initialized fields for a sphere
#
#   Returns:
#     The name of the associative array
#
proc CreateSLIDESphereObject { name } {
    set this $name

    global $this

    # radius
    set [subst $this](radius) 1.0
    set [subst $this](radius_resolution) 0.01
    set [subst $this](radius_min) [subst $[subst $this](radius_resolution)]
    set [subst $this](radius_max) 10.0

    # zmin
    set [subst $this](zmin) -1.0
    set [subst $this](zmin_min) -1.0
    set [subst $this](zmin_max) 1.0
    set [subst $this](zmin_resolution) 0.01

    # zmax
    set [subst $this](zmax) 1.0
    set [subst $this](zmax_min) -1.0
    set [subst $this](zmax_max) 1.0
    set [subst $this](zmax_resolution) 0.01

    # thetamax
    set [subst $this](thetamax) 360
    set [subst $this](thetamax_min) -360
    set [subst $this](thetamax_max) 360
    set [subst $this](thetamax_resolution) 1

    # zslices
    set [subst $this](zslices) 8
    set [subst $this](zslices_min) 1
    set [subst $this](zslices_max) 100
    set [subst $this](zslices_resolution) 1

    # thetaslices
    set [subst $this](thetaslices) 8
    set [subst $this](thetaslices_min) 1
    set [subst $this](thetaslices_max) 100
    set [subst $this](thetaslices_resolution) 1

    # texture
    CreateSLIDETextureFields $this

    # solid
    CreateSLIDESolidField $this

    # shading
    CreateSLIDEShadingField $this

    # lod
    CreateSLIDELODField $this

    return $this
}

######################################################################
# CreateSLIDESphereUI
#   Parameters:
#     parent   - parent widget name
#     name     - name of the sphere
#
#   Actions:
#     Creates a sphere UI contained in a frame widget
#
#   Returns:
#     The name of the unpacked frame widget
#
proc CreateSLIDESphereUI { parent name } {
    set root $parent.f$name
    set this $name

    global $this

    frame $root

    ##################################################
    # Enums Frame
    frame $root.fEnums
    
    ##############################
    # lod
    set widget [CreateSLIDELODEnumFrame $root.fEnums lod \
	    [subst $this](lod) "LOD"]
    pack $widget -side left -fill y

    ##############################
    # shading
    set widget [CreateSLIDEShadingEnumFrame $root.fEnums shading \
	    [subst $this](shading) "Shading"]
    pack $widget -side left -fill y

    ##############################
    # solid
    set widget [CreateSLIDESolidEnumFrame $root.fEnums solid \
	    [subst $this](solid) "Solid"]
    pack $widget -side left -fill y

    pack $root.fEnums -side top -fill x

    ##################################################
    # Scales Frame
    frame $root.fScales
    
    ##############################
    # radius
    set widget [CreateScale $root.fScales scaleRadius \
	    [subst $this](radius) "Radius" \
	    [subst $[subst $this](radius_min)] \
	    [subst $[subst $this](radius_max)] \
	    [subst $[subst $this](radius_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # zmin
    set widget [CreateScale $root.fScales scaleZMin \
	    [subst $this](zmin) "Z Min" \
	    [subst $[subst $this](zmin_min)] \
	    [subst $[subst $this](zmin_max)] \
	    [subst $[subst $this](zmin_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # zmax
    set widget [CreateScale $root.fScales scaleZMax \
	    [subst $this](zmax) "Z Max" \
	    [subst $[subst $this](zmax_min)] \
	    [subst $[subst $this](zmax_max)] \
	    [subst $[subst $this](zmax_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # thetamax
    set widget [CreateScale $root.fScales scaleThetaMax \
	    [subst $this](thetamax) "Theta Max" \
	    [subst $[subst $this](thetamax_min)] \
	    [subst $[subst $this](thetamax_max)] \
	    [subst $[subst $this](thetamax_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # zslices
    set widget [CreateScale $root.fScales scaleZSlices \
	    [subst $this](zslices) "Z Slices" \
	    [subst $[subst $this](zslices_min)] \
	    [subst $[subst $this](zslices_max)] \
	    [subst $[subst $this](zslices_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # thetaslices
    set widget [CreateScale $root.fScales scaleThetaSlices \
	    [subst $this](thetaslices) "Theta Slices" \
	    [subst $[subst $this](thetaslices_min)] \
	    [subst $[subst $this](thetaslices_max)] \
	    [subst $[subst $this](thetaslices_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # texture
    for { set i 0 } { $i < 4 } { incr i } {
	frame $root.fScales.scaleTexture_[subst $i]
	for { set j 0 } { $j < 2 } { incr j } {
	    set widget [CreateScale $root.fScales.scaleTexture_[subst $i] \
		    scaleTexture_[subst $i]_[subst $j] \
		    [subst $this](texture_[subst $i]_[subst $j]) \
		    "Texture($i)($j)" \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_min)] \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_max)] \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_resolution)]]
	    pack $widget -side left -fill y
	}
	pack $root.fScales.scaleTexture_[subst $i] -side top -fill x
    }
    pack $root.fScales -side top -fill x

    return $root
}

######################################################################
# CreateSLIDECylinderObject
#   Parameters:
#     name     - name of the cylinder
#
#   Actions:
#     Creates an associative array with initialized fields for a cylinder
#
#   Returns:
#     The name of the associative array
#
proc CreateSLIDECylinderObject { name } {
    set this $name

    global $this

    # radius
    set [subst $this](radius) 1.0
    set [subst $this](radius_resolution) 0.01
    set [subst $this](radius_min) [subst $[subst $this](radius_resolution)]
    set [subst $this](radius_max) 10.0

    # zmin
    set [subst $this](zmin) 0.0
    set [subst $this](zmin_min) -1.0
    set [subst $this](zmin_max) 1.0
    set [subst $this](zmin_resolution) 0.01

    # zmax
    set [subst $this](zmax) 1.0
    set [subst $this](zmax_min) -1.0
    set [subst $this](zmax_max) 1.0
    set [subst $this](zmax_resolution) 0.01

    # thetamax
    set [subst $this](thetamax) 360
    set [subst $this](thetamax_min) -360
    set [subst $this](thetamax_max) 360
    set [subst $this](thetamax_resolution) 1

    # zslices
    set [subst $this](zslices) 1
    set [subst $this](zslices_min) 1
    set [subst $this](zslices_max) 100
    set [subst $this](zslices_resolution) 1

    # thetaslices
    set [subst $this](thetaslices) 8
    set [subst $this](thetaslices_min) 1
    set [subst $this](thetaslices_max) 100
    set [subst $this](thetaslices_resolution) 1

    # texture
    CreateSLIDETextureFields $this

    # solid
    CreateSLIDESolidField $this

    # shading
    CreateSLIDEShadingField $this

    # lod
    CreateSLIDELODField $this

    return $this
}

######################################################################
# CreateSLIDECylinderUI
#   Parameters:
#     parent   - parent widget name
#     name     - name of the cylinder
#
#   Actions:
#     Creates a cylinder UI contained in a frame widget
#
#   Returns:
#     The name of the unpacked frame widget
#
proc CreateSLIDECylinderUI { parent name } {
    set root $parent.f$name
    set this $name

    global $this

    frame $root

    ##################################################
    # Enums Frame
    frame $root.fEnums
    
    ##############################
    # lod
    set widget [CreateSLIDELODEnumFrame $root.fEnums lod \
	    [subst $this](lod) "LOD"]
    pack $widget -side left -fill y

    ##############################
    # shading
    set widget [CreateSLIDEShadingEnumFrame $root.fEnums shading \
	    [subst $this](shading) "Shading"]
    pack $widget -side left -fill y

    ##############################
    # solid
    set widget [CreateSLIDESolidEnumFrame $root.fEnums solid \
	    [subst $this](solid) "Solid"]
    pack $widget -side left -fill y

    pack $root.fEnums -side top -fill x

    ##################################################
    # Scales Frame
    frame $root.fScales
    
    ##############################
    # radius
    set widget [CreateScale $root.fScales scaleRadius \
	    [subst $this](radius) "Radius" \
	    [subst $[subst $this](radius_min)] \
	    [subst $[subst $this](radius_max)] \
	    [subst $[subst $this](radius_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # zmin
    set widget [CreateScale $root.fScales scaleZMin \
	    [subst $this](zmin) "Z Min" \
	    [subst $[subst $this](zmin_min)] \
	    [subst $[subst $this](zmin_max)] \
	    [subst $[subst $this](zmin_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # zmax
    set widget [CreateScale $root.fScales scaleZMax \
	    [subst $this](zmax) "Z Max" \
	    [subst $[subst $this](zmax_min)] \
	    [subst $[subst $this](zmax_max)] \
	    [subst $[subst $this](zmax_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # thetamax
    set widget [CreateScale $root.fScales scaleThetaMax \
	    [subst $this](thetamax) "Theta Max" \
	    [subst $[subst $this](thetamax_min)] \
	    [subst $[subst $this](thetamax_max)] \
	    [subst $[subst $this](thetamax_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # zslices
    set widget [CreateScale $root.fScales scaleZSlices \
	    [subst $this](zslices) "Z Slices" \
	    [subst $[subst $this](zslices_min)] \
	    [subst $[subst $this](zslices_max)] \
	    [subst $[subst $this](zslices_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # thetaslices
    set widget [CreateScale $root.fScales scaleThetaSlices \
	    [subst $this](thetaslices) "Theta Slices" \
	    [subst $[subst $this](thetaslices_min)] \
	    [subst $[subst $this](thetaslices_max)] \
	    [subst $[subst $this](thetaslices_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # texture
    for { set i 0 } { $i < 4 } { incr i } {
	frame $root.fScales.scaleTexture_[subst $i]
	for { set j 0 } { $j < 2 } { incr j } {
	    set widget [CreateScale $root.fScales.scaleTexture_[subst $i] \
		    scaleTexture_[subst $i]_[subst $j] \
		    [subst $this](texture_[subst $i]_[subst $j]) \
		    "Texture($i)($j)" \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_min)] \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_max)] \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_resolution)]]
	    pack $widget -side left -fill y
	}
	pack $root.fScales.scaleTexture_[subst $i] -side top -fill x
    }
    pack $root.fScales -side top -fill x

    return $root
}

######################################################################
# CreateSLIDEConeObject
#   Parameters:
#     name     - name of the cone
#
#   Actions:
#     Creates an associative array with initialized fields for a cone
#
#   Returns:
#     The name of the associative array
#
proc CreateSLIDEConeObject { name } {
    set this $name

    global $this

    # radius
    set [subst $this](radius) 1.0
    set [subst $this](radius_resolution) 0.01
    set [subst $this](radius_min) [subst $[subst $this](radius_resolution)]
    set [subst $this](radius_max) 10.0

    # height
    set [subst $this](height) 1.0
    set [subst $this](height_min) 0.0
    set [subst $this](height_max) 10.0
    set [subst $this](height_resolution) 0.01

    # thetamax
    set [subst $this](thetamax) 360
    set [subst $this](thetamax_min) -360
    set [subst $this](thetamax_max) 360
    set [subst $this](thetamax_resolution) 1

    # zslices
    set [subst $this](zslices) 1
    set [subst $this](zslices_min) 1
    set [subst $this](zslices_max) 100
    set [subst $this](zslices_resolution) 1

    # thetaslices
    set [subst $this](thetaslices) 8
    set [subst $this](thetaslices_min) 1
    set [subst $this](thetaslices_max) 100
    set [subst $this](thetaslices_resolution) 1

    # texture
    CreateSLIDETextureFields $this

    # solid
    CreateSLIDESolidField $this

    # shading
    CreateSLIDEShadingField $this

    # lod
    CreateSLIDELODField $this

    return $this
}

######################################################################
# CreateSLIDEConeUI
#   Parameters:
#     parent   - parent widget name
#     name     - name of the cone
#
#   Actions:
#     Creates a cone UI contained in a frame widget
#
#   Returns:
#     The name of the unpacked frame widget
#
proc CreateSLIDEConeUI { parent name } {
    set root $parent.f$name
    set this $name

    global $this

    frame $root

    ##################################################
    # Enums Frame
    frame $root.fEnums
    
    ##############################
    # lod
    set widget [CreateSLIDELODEnumFrame $root.fEnums lod \
	    [subst $this](lod) "LOD"]
    pack $widget -side left -fill y

    ##############################
    # shading
    set widget [CreateSLIDEShadingEnumFrame $root.fEnums shading \
	    [subst $this](shading) "Shading"]
    pack $widget -side left -fill y

    ##############################
    # solid
    set widget [CreateSLIDESolidEnumFrame $root.fEnums solid \
	    [subst $this](solid) "Solid"]
    pack $widget -side left -fill y

    pack $root.fEnums -side top -fill x

    ##################################################
    # Scales Frame
    frame $root.fScales
    
    ##############################
    # radius
    set widget [CreateScale $root.fScales scaleRadius \
	    [subst $this](radius) "Radius" \
	    [subst $[subst $this](radius_min)] \
	    [subst $[subst $this](radius_max)] \
	    [subst $[subst $this](radius_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # height
    set widget [CreateScale $root.fScales scaleHeight \
	    [subst $this](height) "Height" \
	    [subst $[subst $this](height_min)] \
	    [subst $[subst $this](height_max)] \
	    [subst $[subst $this](height_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # thetamax
    set widget [CreateScale $root.fScales scaleThetaMax \
	    [subst $this](thetamax) "Theta Max" \
	    [subst $[subst $this](thetamax_min)] \
	    [subst $[subst $this](thetamax_max)] \
	    [subst $[subst $this](thetamax_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # zslices
    set widget [CreateScale $root.fScales scaleZSlices \
	    [subst $this](zslices) "Z Slices" \
	    [subst $[subst $this](zslices_min)] \
	    [subst $[subst $this](zslices_max)] \
	    [subst $[subst $this](zslices_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # thetaslices
    set widget [CreateScale $root.fScales scaleThetaSlices \
	    [subst $this](thetaslices) "Theta Slices" \
	    [subst $[subst $this](thetaslices_min)] \
	    [subst $[subst $this](thetaslices_max)] \
	    [subst $[subst $this](thetaslices_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # texture
    for { set i 0 } { $i < 4 } { incr i } {
	frame $root.fScales.scaleTexture_[subst $i]
	for { set j 0 } { $j < 2 } { incr j } {
	    set widget [CreateScale $root.fScales.scaleTexture_[subst $i] \
		    scaleTexture_[subst $i]_[subst $j] \
		    [subst $this](texture_[subst $i]_[subst $j]) \
		    "Texture($i)($j)" \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_min)] \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_max)] \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_resolution)]]
	    pack $widget -side left -fill y
	}
	pack $root.fScales.scaleTexture_[subst $i] -side top -fill x
    }
    pack $root.fScales -side top -fill x

    return $root
}

######################################################################
# CreateSLIDETorusObject
#   Parameters:
#     name     - name of the torus
#
#   Actions:
#     Creates an associative array with initialized fields for a torus
#
#   Returns:
#     The name of the associative array
#
proc CreateSLIDETorusObject { name } {
    set this $name

    global $this

    # majorradius
    set [subst $this](majorradius) 1.0
    set [subst $this](majorradius_resolution) 0.01
    set [subst $this](majorradius_min) [subst $[subst $this](majorradius_resolution)]
    set [subst $this](majorradius_max) 10.0

    # majorradius
    set [subst $this](minorradius) 0.5
    set [subst $this](minorradius_resolution) 0.01
    set [subst $this](minorradius_min) [subst $[subst $this](minorradius_resolution)]
    set [subst $this](minorradius_max) 10.0

    # phimin
    set [subst $this](phimin) 0
    set [subst $this](phimin_min) -360
    set [subst $this](phimin_max) 360
    set [subst $this](phimin_resolution) 1

    # phimax
    set [subst $this](phimax) 360
    set [subst $this](phimax_min) -360
    set [subst $this](phimax_max) 360
    set [subst $this](phimax_resolution) 1

    # thetamax
    set [subst $this](thetamax) 360
    set [subst $this](thetamax_min) -360
    set [subst $this](thetamax_max) 360
    set [subst $this](thetamax_resolution) 1

    # phislices
    set [subst $this](phislices) 8
    set [subst $this](phislices_min) 1
    set [subst $this](phislices_max) 100
    set [subst $this](phislices_resolution) 1

    # thetaslices
    set [subst $this](thetaslices) 8
    set [subst $this](thetaslices_min) 1
    set [subst $this](thetaslices_max) 100
    set [subst $this](thetaslices_resolution) 1

    # texture
    CreateSLIDETextureFields $this

    # solid
    CreateSLIDESolidField $this

    # shading
    CreateSLIDEShadingField $this

    # lod
    CreateSLIDELODField $this

    return $this
}

######################################################################
# CreateSLIDETorusUI
#   Parameters:
#     parent   - parent widget name
#     name     - name of the torus
#
#   Actions:
#     Creates a torus UI contained in a frame widget
#
#   Returns:
#     The name of the unpacked frame widget
#
proc CreateSLIDETorusUI { parent name } {
    set root $parent.f$name
    set this $name

    global $this

    frame $root

    ##################################################
    # Enums Frame
    frame $root.fEnums
    
    ##############################
    # lod
    set widget [CreateSLIDELODEnumFrame $root.fEnums lod \
	    [subst $this](lod) "LOD"]
    pack $widget -side left -fill y

    ##############################
    # shading
    set widget [CreateSLIDEShadingEnumFrame $root.fEnums shading \
	    [subst $this](shading) "Shading"]
    pack $widget -side left -fill y

    ##############################
    # solid
    set widget [CreateSLIDESolidEnumFrame $root.fEnums solid \
	    [subst $this](solid) "Solid"]
    pack $widget -side left -fill y

    pack $root.fEnums -side top -fill x

    ##################################################
    # Scales Frame
    frame $root.fScales
    
    ##############################
    # majorradius
    set widget [CreateScale $root.fScales scaleMajorRadius \
	    [subst $this](majorradius) "Major Radius" \
	    [subst $[subst $this](majorradius_min)] \
	    [subst $[subst $this](majorradius_max)] \
	    [subst $[subst $this](majorradius_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # minorradius
    set widget [CreateScale $root.fScales scaleMinorRadius \
	    [subst $this](minorradius) "Minor Radius" \
	    [subst $[subst $this](minorradius_min)] \
	    [subst $[subst $this](minorradius_max)] \
	    [subst $[subst $this](minorradius_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # phimin
    set widget [CreateScale $root.fScales scalePhiMin \
	    [subst $this](phimin) "Phi Min" \
	    [subst $[subst $this](phimin_min)] \
	    [subst $[subst $this](phimin_max)] \
	    [subst $[subst $this](phimin_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # phimax
    set widget [CreateScale $root.fScales scalePhiMax \
	    [subst $this](phimax) "Phi Max" \
	    [subst $[subst $this](phimax_min)] \
	    [subst $[subst $this](phimax_max)] \
	    [subst $[subst $this](phimax_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # thetamax
    set widget [CreateScale $root.fScales scaleThetaMax \
	    [subst $this](thetamax) "Theta Max" \
	    [subst $[subst $this](thetamax_min)] \
	    [subst $[subst $this](thetamax_max)] \
	    [subst $[subst $this](thetamax_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # phislices
    set widget [CreateScale $root.fScales scalePhiSlices \
	    [subst $this](phislices) "Phi Slices" \
	    [subst $[subst $this](phislices_min)] \
	    [subst $[subst $this](phislices_max)] \
	    [subst $[subst $this](phislices_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # thetaslices
    set widget [CreateScale $root.fScales scaleThetaSlices \
	    [subst $this](thetaslices) "Theta Slices" \
	    [subst $[subst $this](thetaslices_min)] \
	    [subst $[subst $this](thetaslices_max)] \
	    [subst $[subst $this](thetaslices_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # texture
    for { set i 0 } { $i < 4 } { incr i } {
	frame $root.fScales.scaleTexture_[subst $i]
	for { set j 0 } { $j < 2 } { incr j } {
	    set widget [CreateScale $root.fScales.scaleTexture_[subst $i] \
		    scaleTexture_[subst $i]_[subst $j] \
		    [subst $this](texture_[subst $i]_[subst $j]) \
		    "Texture($i)($j)" \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_min)] \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_max)] \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_resolution)]]
	    pack $widget -side left -fill y
	}
	pack $root.fScales.scaleTexture_[subst $i] -side top -fill x
    }
    pack $root.fScales -side top -fill x

    return $root
}

######################################################################
# CreateSLIDECyclideObject
#   Parameters:
#     name     - name of the cyclide
#
#   Actions:
#     Creates an associative array with initialized fields for a cyclide
#
#   Returns:
#     The name of the associative array
#
proc CreateSLIDECyclideObject { name } {
    set this $name

    global $this

    # drawellipse
    set [subst $this](drawellipse) 0
    set [subst $this](drawellipse_min) 0
    set [subst $this](drawellipse_max) 1
    set [subst $this](drawellipse_resolution) 1

    # drawhyperbola
    set [subst $this](drawhyperbola) 0
    set [subst $this](drawhyperbola_min) 0
    set [subst $this](drawhyperbola_max) 1
    set [subst $this](drawhyperbola_resolution) 1

    # a
    set [subst $this](a) 5.0
    set [subst $this](a_resolution) 0.01
    set [subst $this](a_min) [subst $[subst $this](a_resolution)]
    set [subst $this](a_max) 10.0

    # b
    set [subst $this](b) 4.0
    set [subst $this](b_resolution) 0.01
    set [subst $this](b_min) [subst $[subst $this](b_resolution)]
    set [subst $this](b_max) 10.0

    # stringlength
    set [subst $this](stringlength) 8.0
    set [subst $this](stringlength_resolution) 0.01
    set [subst $this](stringlength_min) [subst $[subst $this](stringlength_resolution)]
    set [subst $this](stringlength_max) 20.0

    # phimin
    set [subst $this](phimin) 0
    set [subst $this](phimin_min) -360
    set [subst $this](phimin_max) 360
    set [subst $this](phimin_resolution) 1

    # phimax
    set [subst $this](phimax) 360
    set [subst $this](phimax_min) -360
    set [subst $this](phimax_max) 360
    set [subst $this](phimax_resolution) 1

    # thetamin
    set [subst $this](thetamin) 0
    set [subst $this](thetamin_min) -360
    set [subst $this](thetamin_max) 360
    set [subst $this](thetamin_resolution) 1

    # thetamax
    set [subst $this](thetamax) 360
    set [subst $this](thetamax_min) -360
    set [subst $this](thetamax_max) 360
    set [subst $this](thetamax_resolution) 1

    # phislices
    set [subst $this](phislices) 8
    set [subst $this](phislices_min) 1
    set [subst $this](phislices_max) 100
    set [subst $this](phislices_resolution) 1

    # thetaslices
    set [subst $this](thetaslices) 8
    set [subst $this](thetaslices_min) 1
    set [subst $this](thetaslices_max) 100
    set [subst $this](thetaslices_resolution) 1

    # texture
    CreateSLIDETextureFields $this

    # solid
    CreateSLIDESolidField $this

    # shading
    CreateSLIDEShadingField $this

    # lod
    CreateSLIDELODField $this

    return $this
}

######################################################################
# CreateSLIDECyclideUI
#   Parameters:
#     parent   - parent widget name
#     name     - name of the cyclide
#
#   Actions:
#     Creates a cyclide UI contained in a frame widget
#
#   Returns:
#     The name of the unpacked frame widget
#
proc CreateSLIDECyclideUI { parent name } {
    set root $parent.f$name
    set this $name

    global $this

    frame $root

    ##################################################
    # Enums Frame
    frame $root.fEnums
    
    ##############################
    # lod
    set widget [CreateSLIDELODEnumFrame $root.fEnums lod \
	    [subst $this](lod) "LOD"]
    pack $widget -side left -fill y

    ##############################
    # shading
    set widget [CreateSLIDEShadingEnumFrame $root.fEnums shading \
	    [subst $this](shading) "Shading"]
    pack $widget -side left -fill y

    ##############################
    # solid
    set widget [CreateSLIDESolidEnumFrame $root.fEnums solid \
	    [subst $this](solid) "Solid"]
    pack $widget -side left -fill y

    pack $root.fEnums -side top -fill x

    ##################################################
    # Scales Frame
    frame $root.fScales
    
    ##############################
    # drawellipse
    set widget [CreateScale $root.fScales scaleDrawEllipse \
	    [subst $this](drawellipse) "Draw Ellipse" \
	    [subst $[subst $this](drawellipse_min)] \
	    [subst $[subst $this](drawellipse_max)] \
	    [subst $[subst $this](drawellipse_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # drawhyperbola
    set widget [CreateScale $root.fScales scaleDrawHyperbola \
	    [subst $this](drawhyperbola) "Draw Hyperbola" \
	    [subst $[subst $this](drawhyperbola_min)] \
	    [subst $[subst $this](drawhyperbola_max)] \
	    [subst $[subst $this](drawhyperbola_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # a
    set widget [CreateScale $root.fScales scaleA \
	    [subst $this](a) "A" \
	    [subst $[subst $this](a_min)] \
	    [subst $[subst $this](a_max)] \
	    [subst $[subst $this](a_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # b
    set widget [CreateScale $root.fScales scaleB \
	    [subst $this](b) "B" \
	    [subst $[subst $this](b_min)] \
	    [subst $[subst $this](b_max)] \
	    [subst $[subst $this](b_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # phimin
    set widget [CreateScale $root.fScales scalePhiMin \
	    [subst $this](phimin) "Phi Min" \
	    [subst $[subst $this](phimin_min)] \
	    [subst $[subst $this](phimin_max)] \
	    [subst $[subst $this](phimin_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # phimax
    set widget [CreateScale $root.fScales scalePhiMax \
	    [subst $this](phimax) "Phi Max" \
	    [subst $[subst $this](phimax_min)] \
	    [subst $[subst $this](phimax_max)] \
	    [subst $[subst $this](phimax_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # thetamin
    set widget [CreateScale $root.fScales scaleThetaMin \
	    [subst $this](thetamin) "Theta Min" \
	    [subst $[subst $this](thetamin_min)] \
	    [subst $[subst $this](thetamin_max)] \
	    [subst $[subst $this](thetamin_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # thetamax
    set widget [CreateScale $root.fScales scaleThetaMax \
	    [subst $this](thetamax) "Theta Max" \
	    [subst $[subst $this](thetamax_min)] \
	    [subst $[subst $this](thetamax_max)] \
	    [subst $[subst $this](thetamax_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # phislices
    set widget [CreateScale $root.fScales scalePhiSlices \
	    [subst $this](phislices) "Phi Slices" \
	    [subst $[subst $this](phislices_min)] \
	    [subst $[subst $this](phislices_max)] \
	    [subst $[subst $this](phislices_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # thetaslices
    set widget [CreateScale $root.fScales scaleThetaSlices \
	    [subst $this](thetaslices) "Theta Slices" \
	    [subst $[subst $this](thetaslices_min)] \
	    [subst $[subst $this](thetaslices_max)] \
	    [subst $[subst $this](thetaslices_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # texture
    for { set i 0 } { $i < 4 } { incr i } {
	frame $root.fScales.scaleTexture_[subst $i]
	for { set j 0 } { $j < 2 } { incr j } {
	    set widget [CreateScale $root.fScales.scaleTexture_[subst $i] \
		    scaleTexture_[subst $i]_[subst $j] \
		    [subst $this](texture_[subst $i]_[subst $j]) \
		    "Texture($i)($j)" \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_min)] \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_max)] \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_resolution)]]
	    pack $widget -side left -fill y
	}
	pack $root.fScales.scaleTexture_[subst $i] -side top -fill x
    }
    pack $root.fScales -side top -fill x

    return $root
}

######################################################################
# CreateSLIDEBSplinePatchObject
#   Parameters:
#     name     - name of the bsplinepatch
#
#   Actions:
#     Creates an associative array with initialized fields for a bsplinepatch
#
#   Returns:
#     The name of the associative array
#
proc CreateSLIDEBSplinePatchObject { name } {
    set this $name

    global $this

    # drawcontrols
    set [subst $this](drawcontrols) 0
    set [subst $this](drawcontrols_min) 0
    set [subst $this](drawcontrols_max) 1
    set [subst $this](drawcontrols_resolution) 1

    # uorder
    set [subst $this](uorder) 4
    set [subst $this](uorder_min) 2
    set [subst $this](uorder_max) 6
    set [subst $this](uorder_resolution) 1

    # vorder
    set [subst $this](vorder) 4
    set [subst $this](vorder_min) 2
    set [subst $this](vorder_max) 6
    set [subst $this](vorder_resolution) 1

    # uslices
    set [subst $this](uslices) 8
    set [subst $this](uslices_min) 1
    set [subst $this](uslices_max) 100
    set [subst $this](uslices_resolution) 1

    # vslices
    set [subst $this](vslices) 8
    set [subst $this](vslices_min) 1
    set [subst $this](vslices_max) 100
    set [subst $this](vslices_resolution) 1

    # texture
    CreateSLIDETextureFields $this

    # solid
    CreateSLIDESolidField $this

    # shading
    CreateSLIDEShadingField $this

    # lod
    CreateSLIDELODField $this

    return $this
}

######################################################################
# CreateSLIDEBSplinePatchUI
#   Parameters:
#     parent   - parent widget name
#     name     - name of the bsplinepatch
#
#   Actions:
#     Creates a bsplinepatch UI contained in a frame widget
#
#   Returns:
#     The name of the unpacked frame widget
#
proc CreateSLIDEBSplinePatchUI { parent name } {
    set root $parent.f$name
    set this $name

    global $this

    frame $root

    ##################################################
    # Enums Frame
    frame $root.fEnums
    
    ##############################
    # lod
    set widget [CreateSLIDELODEnumFrame $root.fEnums lod \
	    [subst $this](lod) "LOD"]
    pack $widget -side left -fill y

    ##############################
    # shading
    set widget [CreateSLIDEShadingEnumFrame $root.fEnums shading \
	    [subst $this](shading) "Shading"]
    pack $widget -side left -fill y

    ##############################
    # solid
    set widget [CreateSLIDESolidEnumFrame $root.fEnums solid \
	    [subst $this](solid) "Solid"]
    pack $widget -side left -fill y

    pack $root.fEnums -side top -fill x

    ##################################################
    # Scales Frame
    frame $root.fScales
    
    # drawcontrols
    set widget [CreateScale $root.fScales scaleDrawControls \
	    [subst $this](drawcontrols) "Draw Controls" \
	    [subst $[subst $this](drawcontrols_min)] \
	    [subst $[subst $this](drawcontrols_max)] \
	    [subst $[subst $this](drawcontrols_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # uorder
    set widget [CreateScale $root.fScales scaleUOrder \
	    [subst $this](uorder) "U Order" \
	    [subst $[subst $this](uorder_min)] \
	    [subst $[subst $this](uorder_max)] \
	    [subst $[subst $this](uorder_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # vorder
    set widget [CreateScale $root.fScales scaleVOrder \
	    [subst $this](vorder) "V Order" \
	    [subst $[subst $this](vorder_min)] \
	    [subst $[subst $this](vorder_max)] \
	    [subst $[subst $this](vorder_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # uslices
    set widget [CreateScale $root.fScales scaleUSlices \
	    [subst $this](uslices) "U Slices" \
	    [subst $[subst $this](uslices_min)] \
	    [subst $[subst $this](uslices_max)] \
	    [subst $[subst $this](uslices_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # vslices
    set widget [CreateScale $root.fScales scaleVSlices \
	    [subst $this](vslices) "V Slices" \
	    [subst $[subst $this](vslices_min)] \
	    [subst $[subst $this](vslices_max)] \
	    [subst $[subst $this](vslices_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # texture
    for { set i 0 } { $i < 4 } { incr i } {
	frame $root.fScales.scaleTexture_[subst $i]
	for { set j 0 } { $j < 2 } { incr j } {
	    set widget [CreateScale $root.fScales.scaleTexture_[subst $i] \
		    scaleTexture_[subst $i]_[subst $j] \
		    [subst $this](texture_[subst $i]_[subst $j]) \
		    "Texture($i)($j)" \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_min)] \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_max)] \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_resolution)]]
	    pack $widget -side left -fill y
	}
	pack $root.fScales.scaleTexture_[subst $i] -side top -fill x
    }
    pack $root.fScales -side top -fill x

    return $root
}

######################################################################
# CreateSLIDEBezierPatchObject
#   Parameters:
#     name     - name of the bezierpatch
#
#   Actions:
#     Creates an associative array with initialized fields for a bezierpatch
#
#   Returns:
#     The name of the associative array
#
proc CreateSLIDEBezierPatchObject { name } {
    set this $name

    global $this

    # drawcontrols
    set [subst $this](drawcontrols) 0
    set [subst $this](drawcontrols_min) 0
    set [subst $this](drawcontrols_max) 1
    set [subst $this](drawcontrols_resolution) 1

    # uorder
    set [subst $this](uorder) 4
    set [subst $this](uorder_min) 2
    set [subst $this](uorder_max) 6
    set [subst $this](uorder_resolution) 1

    # vorder
    set [subst $this](vorder) 4
    set [subst $this](vorder_min) 2
    set [subst $this](vorder_max) 6
    set [subst $this](vorder_resolution) 1

    # uslices
    set [subst $this](uslices) 8
    set [subst $this](uslices_min) 1
    set [subst $this](uslices_max) 100
    set [subst $this](uslices_resolution) 1

    # vslices
    set [subst $this](vslices) 8
    set [subst $this](vslices_min) 1
    set [subst $this](vslices_max) 100
    set [subst $this](vslices_resolution) 1

    # texture
    CreateSLIDETextureFields $this

    # solid
    CreateSLIDESolidField $this

    # shading
    CreateSLIDEShadingField $this

    # lod
    CreateSLIDELODField $this

    return $this
}

######################################################################
# CreateSLIDEBezierPatchUI
#   Parameters:
#     parent   - parent widget name
#     name     - name of the bezierpatch
#
#   Actions:
#     Creates a bezierpatch UI contained in a frame widget
#
#   Returns:
#     The name of the unpacked frame widget
#
proc CreateSLIDEBezierPatchUI { parent name } {
    set root $parent.f$name
    set this $name

    global $this

    frame $root

    ##################################################
    # Enums Frame
    frame $root.fEnums
    
    ##############################
    # lod
    set widget [CreateSLIDELODEnumFrame $root.fEnums lod \
	    [subst $this](lod) "LOD"]
    pack $widget -side left -fill y

    ##############################
    # shading
    set widget [CreateSLIDEShadingEnumFrame $root.fEnums shading \
	    [subst $this](shading) "Shading"]
    pack $widget -side left -fill y

    ##############################
    # solid
    set widget [CreateSLIDESolidEnumFrame $root.fEnums solid \
	    [subst $this](solid) "Solid"]
    pack $widget -side left -fill y

    pack $root.fEnums -side top -fill x

    ##################################################
    # Scales Frame
    frame $root.fScales
    
    # drawcontrols
    set widget [CreateScale $root.fScales scaleDrawControls \
	    [subst $this](drawcontrols) "Draw Controls" \
	    [subst $[subst $this](drawcontrols_min)] \
	    [subst $[subst $this](drawcontrols_max)] \
	    [subst $[subst $this](drawcontrols_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # uorder
    set widget [CreateScale $root.fScales scaleUOrder \
	    [subst $this](uorder) "U Order" \
	    [subst $[subst $this](uorder_min)] \
	    [subst $[subst $this](uorder_max)] \
	    [subst $[subst $this](uorder_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # vorder
    set widget [CreateScale $root.fScales scaleVOrder \
	    [subst $this](vorder) "V Order" \
	    [subst $[subst $this](vorder_min)] \
	    [subst $[subst $this](vorder_max)] \
	    [subst $[subst $this](vorder_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # uslices
    set widget [CreateScale $root.fScales scaleUSlices \
	    [subst $this](uslices) "U Slices" \
	    [subst $[subst $this](uslices_min)] \
	    [subst $[subst $this](uslices_max)] \
	    [subst $[subst $this](uslices_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # vslices
    set widget [CreateScale $root.fScales scaleVSlices \
	    [subst $this](vslices) "V Slices" \
	    [subst $[subst $this](vslices_min)] \
	    [subst $[subst $this](vslices_max)] \
	    [subst $[subst $this](vslices_resolution)]]
    pack $widget -side top -fill x

    ##############################
    # texture
    for { set i 0 } { $i < 4 } { incr i } {
	frame $root.fScales.scaleTexture_[subst $i]
	for { set j 0 } { $j < 2 } { incr j } {
	    set widget [CreateScale $root.fScales.scaleTexture_[subst $i] \
		    scaleTexture_[subst $i]_[subst $j] \
		    [subst $this](texture_[subst $i]_[subst $j]) \
		    "Texture($i)($j)" \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_min)] \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_max)] \
		    [subst $[subst $this](texture_[subst $i]_[subst $j]_resolution)]]
	    pack $widget -side left -fill y
	}
	pack $root.fScales.scaleTexture_[subst $i] -side top -fill x
    }
    pack $root.fScales -side top -fill x

    return $root
}

#
# END  : slideui.tcl
######################################################################
}

tclinit { 
  set lModels { { "Triangle" oTriangle CreateSLIDESquareUI } 
                { "Cube" oSquare CreateSLIDESquareUI } 
                { "Sphere" sph CreateSLIDESphereUI }
                { "Cylinder" cyl CreateSLIDECylinderUI }
                { "Cone" con CreateSLIDEConeUI }
                { "Torus" tor CreateSLIDETorusUI }
                { "Cyclide" cyc CreateSLIDECyclideUI }
                { "BSpline Patch" bsp CreateSLIDEBSplinePatchUI }
                { "Bezier Patch" bez CreateSLIDEBezierPatchUI }
              }


  set widgetModel ""
  set model 0
  set modelPrev ""

  proc OpenModelUI { } {
    global model modelPrev widgetModel lModels

    if { $model == $modelPrev } {
      return
    }
    set modelPrev $model

    if { $widgetModel != "" } {
       destroy $widgetModel
    }

    set root .slfWindow.ui
    set widgetModel [[lindex [lindex $lModels $model] 2] $root \
	[lindex [lindex $lModels $model] 1]]

    pack $widgetModel -side left -fill y
  }

  toplevel .slfWindow.ui

  ##################################################
  # Radio Button Frame

  frame .slfWindow.ui.radiobuttons
  
  ##############################
  # Axes On/Off Radio Buttons

  frame .slfWindow.ui.radiobuttons.axes -relief raised -borderwidth 2

  label .slfWindow.ui.radiobuttons.axes.title -text "Draw Axes" -relief ridge \
    -borderwidth 2

  pack .slfWindow.ui.radiobuttons.axes.title -side top -fill x

  set axes $SLF_FULL

  radiobutton .slfWindow.ui.radiobuttons.axes.rb0 \
    -text "Off" \
    -variable axes \
    -value $SLF_OFF \
    -anchor w
  pack .slfWindow.ui.radiobuttons.axes.rb0 -side top -fill x

  radiobutton .slfWindow.ui.radiobuttons.axes.rb1 \
    -text "On" \
    -variable axes \
    -value $SLF_FULL \
    -anchor w
  pack .slfWindow.ui.radiobuttons.axes.rb1 -side top -fill x

  pack .slfWindow.ui.radiobuttons.axes -side top -fill x

  ##############################
  # Model Radio Buttons

  frame .slfWindow.ui.radiobuttons.model -relief raised -borderwidth 2

  label .slfWindow.ui.radiobuttons.model.title -text "Model" -relief ridge \
    -borderwidth 2

  pack .slfWindow.ui.radiobuttons.model.title -side top -fill x

  for { set i 0 } { $i < [llength $lModels] } { incr i } {
    radiobutton .slfWindow.ui.radiobuttons.model.rb"$i" \
      -text [lindex [lindex $lModels $i] 0] \
      -variable model \
      -value $i \
      -anchor w \
      -command OpenModelUI

    pack .slfWindow.ui.radiobuttons.model.rb"$i" -side top -fill x
  }

  pack .slfWindow.ui.radiobuttons.model -side top -fill x

  pack .slfWindow.ui.radiobuttons -side left -fill y
}

tclinit {
  CreateSLIDESquareObject oTriangle
  CreateSLIDESquareObject oSquare
  CreateSLIDESphereObject sph
  CreateSLIDECylinderObject cyl 
  CreateSLIDEConeObject con
  CreateSLIDETorusObject tor
  CreateSLIDECyclideObject cyc
  CreateSLIDEBSplinePatchObject bsp
  CreateSLIDEBezierPatchObject bez

  OpenModelUI
}

surface sTile
  bitmap "slide_tile_flip.gif" SLF_TEXMAP
  color ( 1 1 1 )
  reflectivity ( 1 1 1 )
  exponent 2
  metallic 0
endsurface

surface sBlack
  color ( 0 0 0 )
endsurface
surface sRed
  color ( 1 0 0 )
endsurface
surface sGreen
  color ( 0 1 0 )
endsurface
surface sBlue
  color ( 0 0 1 )
endsurface

######################################################################
# START: Triangle
#

point pTri0 ( -1 -1  0 )
  texture ( {expr $oTriangle(texture_0_0)} {expr $oTriangle(texture_0_1)} )
endpoint
point pTri01 ( 0 -1  0 )
  texture ( {expr ($oTriangle(texture_0_0)+$oTriangle(texture_1_0))/2.0} {expr ($oTriangle(texture_0_1)+$oTriangle(texture_1_1))/2.0} )
endpoint
point pTri1 (  1 -1  0 )
  texture ( {expr $oTriangle(texture_1_0)} {expr $oTriangle(texture_1_1)} )
endpoint
point pTri2 (  0  1  0 )
  texture ( {expr $oTriangle(texture_2_0)} {expr $oTriangle(texture_2_1)} )
endpoint
point pTri3 (  0  1  0 )
  texture ( {expr $oTriangle(texture_3_0)} {expr $oTriangle(texture_3_1)} )
endpoint

face fTriangleL ( pTri0 pTri01 pTri3 )
endface
face fTriangleR ( pTri01 pTri1 pTri2 )
endface

object oTriangle ( fTriangleL fTriangleR )
endobject

group gTriangle
  instance oTriangle
    surface sTile

    shading { expr $oTriangle(shading) }
    rotate ( 0 1 0 ) ( 90 )
    rotate ( 1 0 0 ) ( 90 )
  endinstance
endgroup

#
# END  : Triangle
######################################################################

######################################################################
# START: Square
#
point pXY (  1  1  0 )
  texture ( {expr $oSquare(texture_2_0)} {expr $oSquare(texture_2_1)} )
endpoint
point pxY ( -1  1  0 )
  texture ( {expr $oSquare(texture_0_0)} {expr $oSquare(texture_2_1)} )
endpoint
point pXy (  1 -1  0 )
  texture ( {expr $oSquare(texture_2_0)} {expr $oSquare(texture_0_1)} )
endpoint
point pxy ( -1 -1  0 )
  texture ( {expr $oSquare(texture_0_0)} {expr $oSquare(texture_0_1)} )
endpoint

face fSquare ( pXY pxY pxy pXy )
endface

object oSquare ( fSquare )
endobject

group gCube
  instance oSquare
    translate ( 0 0 1 )
    rotate ( 0 1 0 ) ( 90 )
  endinstance
  instance oSquare
    translate ( 0 0 1 )
    rotate ( 0 1 0 ) ( -90 )
  endinstance
  instance oSquare
    translate ( 0 0 1 )
    rotate ( 1 0 0 ) ( -90 )
  endinstance
  instance oSquare
    translate ( 0 0 1 )
    rotate ( 1 0 0 ) ( 90 )
  endinstance
  instance oSquare
    translate ( 0 0 1 )
  endinstance
  instance oSquare
    translate ( 0 0 1 )
    rotate ( 0 1 0 ) ( 180 )
  endinstance
endgroup

group gAxes
  instance gCube
    surface sRed
    translate ( 1 0 0 )
    scale ( 0.5 0.01 0.01 )
  endinstance
  instance gCube
    surface sGreen
    translate ( 0 1 0 )
    scale ( 0.01 0.5 0.01 )
  endinstance
  instance gCube
    surface sBlue
    translate ( 0 0 1 )
    scale ( 0.01 0.01 0.5 )
  endinstance
endgroup

group gCubeTextured
  instance gCube
    surface sTile

    #lod { expr $oSquare(lod) }
    shading { expr $oSquare(shading) }

    rotate ( 0 1 0 ) ( 90 )
    rotate ( 1 0 0 ) ( 90 )
  endinstance
endgroup

#
# END  : Square
######################################################################

######################################################################
# START: Sphere
#

sphere sphWire
  lod { expr $sph(lod) } 
  shading SLF_WIRE
  solid SLF_HOLLOW
  surface sBlack
endsphere

sphere sph
  surface sTile

  shading { expr $sph(shading) }
  solid { expr $sph(solid) }

  radius { expr $sph(radius) } 
  zmin { expr $sph(zmin) } 
  zmax { expr $sph(zmax) } 
  thetamax { expr $sph(thetamax) } 

  zslices { expr $sph(zslices) } 
  thetaslices { expr $sph(thetaslices) } 

  texture ( {expr $sph(texture_0_0)} {expr $sph(texture_0_1)} ) ( {expr $sph(texture_2_0)} {expr $sph(texture_2_1)} )
endsphere

group gSphere
  instance sphWire
  endinstance
  instance sph
  endinstance
endgroup

#
# END  : Sphere
######################################################################

######################################################################
# START: Cylinder
#

cylinder cylWire
  lod { expr $cyl(lod) } 
  shading SLF_WIRE
  solid SLF_HOLLOW
  surface sBlack
endcylinder

cylinder cyl
  surface sTile

  shading { expr $cyl(shading) }
  solid { expr $cyl(solid) }

  radius { expr $cyl(radius) } 
  zmin { expr $cyl(zmin) } 
  zmax { expr $cyl(zmax) } 
  thetamax { expr $cyl(thetamax) } 

  zslices { expr $cyl(zslices) } 
  thetaslices { expr $cyl(thetaslices) } 

  texture ( {expr $cyl(texture_0_0)} {expr $cyl(texture_0_1)} ) ( {expr $cyl(texture_2_0)} {expr $cyl(texture_2_1)} )
endcylinder

group gCylinder
  instance cylWire
  endinstance
  instance cyl
  endinstance
endgroup

#
# END  : Cylinder
######################################################################

######################################################################
# START: Cone
#
(*
cone conWire
  lod { expr $con(lod) } 
  shading SLF_WIRE
  solid SLF_HOLLOW
  surface sBlack
endcone

cone con
  surface sTile

  shading { expr $con(shading) }
  solid { expr $con(solid) }

  radius { expr $con(radius) } 
  height { expr $con(height) } 
  thetamax { expr $con(thetamax) } 

  zslices { expr $con(zslices) } 
  thetaslices { expr $con(thetaslices) } 

  texture ( {expr $con(texture_0_0)} {expr $con(texture_0_1)} ) ( {expr $con(texture_2_0)} {expr $con(texture_2_1)} )
endcone

group gCone
  instance conWire
  endinstance
  instance con
  endinstance
endgroup
*)
#
# END  : Cone
######################################################################

######################################################################
# START: Torus
#

torus torWire
  lod { expr $tor(lod) } 
  shading SLF_WIRE
  solid SLF_HOLLOW
  surface sBlack
endtorus

torus tor
  surface sTile

  shading { expr $tor(shading) }
  solid { expr $tor(solid) }

  majorradius { expr $tor(majorradius) } 
  minorradius { expr $tor(minorradius) } 
  phimin { expr $tor(phimin) } 
  phimax { expr $tor(phimax) } 
  thetamax { expr $tor(thetamax) } 

  phislices { expr $tor(phislices) } 
  thetaslices { expr $tor(thetaslices) } 

  texture ( {expr $tor(texture_0_0)} {expr $tor(texture_0_1)} ) ( {expr $tor(texture_2_0)} {expr $tor(texture_2_1)} )
endtorus

group gTorus
  instance torWire
  endinstance
  instance tor
  endinstance
endgroup

#
# END  : Torus
######################################################################

######################################################################
# START: Cyclide
#

cyclide cycWire
  lod { expr $cyc(lod) } 
  shading SLF_WIRE
  solid SLF_HOLLOW
  surface sBlack
endcyclide

cyclide cyc
  surface sTile

  shading { expr $cyc(shading) }
  solid { expr $cyc(solid) }

  drawellipse { expr $cyc(drawellipse) } 
  drawhyperbola { expr $cyc(drawhyperbola) } 

#  a { expr $cyc(a) } 
#  b { expr $cyc(b) } 
  stringlength { expr $cyc(stringlength) } 
  phimin { expr $cyc(phimin) } 
  phimax { expr $cyc(phimax) } 
  thetamin { expr $cyc(thetamin) } 
  thetamax { expr $cyc(thetamax) } 

  phislices { expr $cyc(phislices) } 
  thetaslices { expr $cyc(thetaslices) } 

  texture ( {expr $cyc(texture_0_0)} {expr $cyc(texture_0_1)} ) ( {expr $cyc(texture_2_0)} {expr $cyc(texture_2_1)} )
endcyclide

group gCyclide
  instance cycWire
  endinstance
  instance cyc
  endinstance
endgroup

#
# END  : Cyclide
######################################################################

######################################################################
# START: BSplinePatch
#

bsplinepatch bsp
  surface sTile

  shading { expr $bsp(shading) }
  solid { expr $bsp(solid) }

  drawcontrols { expr $bsp(drawcontrols) } 

#  uorder { expr $bsp(uorder) } 
#  vorder { expr $bsp(vorder) } 
  uorder 4 
  vorder 4

  uslices { expr $bsp(uslices) } 
  vslices { expr $bsp(vslices) } 

  texture ( {expr $bsp(texture_0_0)} {expr $bsp(texture_0_1)} ) ( {expr $bsp(texture_2_0)} {expr $bsp(texture_2_1)} )
endbsplinepatch

group gBSplinePatch
  instance bsp
  endinstance
endgroup

#
# END  : BSpline Patch
######################################################################

######################################################################
# START: Bezier Patch
#

bezierpatch bez
  surface sTile

  shading { expr $bez(shading) }
  solid { expr $bez(solid) }

  drawcontrols { expr $bez(drawcontrols) } 

#  uorder { expr $bez(uorder) } 
#  vorder { expr $bez(vorder) } 
  uorder 4 
  vorder 4

  uslices { expr $bez(uslices) } 
  vslices { expr $bez(vslices) } 

  texture ( {expr $bez(texture_0_0)} {expr $bez(texture_0_1)} ) ( {expr $bez(texture_2_0)} {expr $bez(texture_2_1)} )
endbezierpatch

group gBezierPatch
  instance bez
  endinstance
endgroup

#
# END  : Bezier Patch
######################################################################

group gSwitch
  instance gAxes
    lod { expr $axes }
    scale ( 1.7 1.7 1.7 )
  endinstance

  instance gTriangle
    lod { if { $model == 0 } { expr $SLF_FULL } { expr $SLF_OFF } }
  endinstance
  instance gCubeTextured
    lod { if { $model == 1 } { expr $SLF_FULL } { expr $SLF_OFF } }
  endinstance
  instance gSphere
    lod { if { $model == 2 } { expr $SLF_FULL } { expr $SLF_OFF } }
  endinstance
  instance gCylinder
    lod { if { $model == 3 } { expr $SLF_FULL } { expr $SLF_OFF } }
  endinstance
(*
  instance gCone
    lod { if { $model == 4 } { expr $SLF_FULL } { expr $SLF_OFF } }
  endinstance
*)
  instance gTorus
    lod { if { $model == 5 } { expr $SLF_FULL } { expr $SLF_OFF } }
  endinstance
  instance gCyclide
    lod { if { $model == 6 } { expr $SLF_FULL } { expr $SLF_OFF } }
  endinstance
  instance gBSplinePatch
    lod { if { $model == 7 } { expr $SLF_FULL } { expr $SLF_OFF } }
  endinstance
  instance gBezierPatch
    lod { if { $model == 8 } { expr $SLF_FULL } { expr $SLF_OFF } }
  endinstance
endgroup

group gRoot
  instance gSwitch
    rotate ( 1 0 0 ) ( -90 )
    rotate ( 0 1 0 ) ( -90 )
    scale ( 0.25 0.25 0.25 )
    #rotate ( 0 1 0 ) ( -15 )
  endinstance
endgroup

group gCam
  instance cam
    id iCam
    translate ( 0 0 1 )
  endinstance
endgroup

camera cam
  projection SLF_PERSPECTIVE
  frustum ( -0.5 -0.5 -2 ) ( 0.5 0.5 -0.2 )
endcamera

light lAmbient
  type SLF_AMBIENT
  color ( 0.2 0.2 0.2 )
endlight

light lTop
  type SLF_POINT
  color ( 1.0 1.0 1.0 )
endlight

group gLight
  instance lTop
    id iTop
    lookat
      eye ( 0 0 0 )
      target ( 0 -1 -1 )
      up ( 0 1 0 )
    endlookat
    translate ( 0 1 1 )
  endinstance
endgroup

render Viewport gCam.iCam.cam gRoot
  light lAmbient
  light gLight.iTop.lTop
endrender

viewport Viewport Window
endviewport

window Window
  background ( 0.25 0.60 1.0 )
endwindow