# interface generated by SpecTcl version 1.0 from /usr/people/ramsan/tmp/pref_graphical.ui
#   root     is the parent window for this user interface

proc pref_graphical_ui {root args} {

	# this treats "." as a special case
    global base GIDDEFAULT GidPriv

	if {$root == "."} {
	    set base ""
	} else {
	    set base $root
	}
    
	frame $base.frame#3 \
		-borderwidth 2 \
		-relief ridge

	frame $base.frame#1 \
		-borderwidth 2 \
		-relief ridge

	frame $base.frame#1b \
		-borderwidth 2 \
		-relief ridge


	frame $base.frame#4
	
	frame $base.frmBackgroundColor

	checkbutton $base.checkbutton#1 \
        	-text [_ "Smoothed elems(deg):"] \
		-disabledforeground grey60 \
		-variable ChangeVarInfo(Lightsmoothedelements)

	entry $base.entry#1 \
		-borderwidth 1 \
		-cursor {} \
		-insertborderwidth 1 \
		-textvariable ChangeVarInfo(AngleSmoothed) \
		-width 8

        GidHelp "$base.checkbutton#1 $base.entry#1" [_ "If set and when rendering\
		a mesh, the intersection between elements with a small angle\
		between their normals will be illuminated as if it were\
		a continuous solid. If not, illumination is made considering\
		every element as planar.\
		\nThe angle (in degrees) is the maximum angle between normals\
		of two elements to allow smooth lighting between them.\
		If not, one edge is drawn between them."]

	label $base.label#35 \
        	-text [_ "Surface drawing type:"] -justify left

	tk_optionMenuRAM $base.menubutton#1 ChangeVarInfo(DrawSurfaceMode) \
		[list [_ "None"] [_ "Boundary lines"] [_ "Isoparametric lines"] [_ "Both modes"]] \
		{None "Boundary lines" "Isoparametric lines" "Both modes"}
	$base.menubutton#1 conf -textvariable "" -width 10 -anchor w

        GidHelp "$base.label#35 $base.menubutton#1" [_ "Lets the user choose how to\
		draw the surfaces when in wireframe (normal) mode. Options are:\
		\n'None': Surfaces are not drawn.\
		\n'Boundary lines': One magenta line is drawn for every\
		contour line. This set of lines have a small offset towards\
		the interior of the surface.\
		\n'Isoparametric lines': Two yellow lines are drawn for every\
		NURBS surface. The one for 'u=0.5' and the one for 'v=0.5'.\
		\n'Both': Draws both modes."]

        label $base.labelQuadratic -text [_ "Draw quadratic elements:"] -justify left
	tk_optionMenuRAM $base.menubuttonQuadratic ChangeVarInfo(DrawQuadratic) \
		[list [_ "No"] [_ "As lines"] [_ "As curves"]] \
		{No AsLines AsCurve}
	$base.menubuttonQuadratic conf -width 10 -anchor w
    
	global MenuColorsForceChecked
	set MenuColorsForceChecked 1
	
	menubutton $base.menuEntityColor \
		-menu $base.menuEntityColor.m \
        	-relief raised -text [_ "Change Colors"] 
	menu $base.menuEntityColor.m -tearoff 0
        $base.menuEntityColor.m add checkbutton -label [_ "Background"]... \
		-variable MenuColorsForceChecked \
		-command {SelectColorEntity BackgroundColor 0 ; set MenuColorsForceChecked 1}
        $base.menuEntityColor.m add checkbutton -label [_ "Points"]... \
		-variable MenuColorsForceChecked \
		-command {SelectColorEntity ColorPoints 1 ; set MenuColorsForceChecked 1}
        $base.menuEntityColor.m add checkbutton -label [_ "Lines"]... \
		-variable MenuColorsForceChecked \
		-command {SelectColorEntity ColorLines 2 ; set MenuColorsForceChecked 1}
        $base.menuEntityColor.m add checkbutton -label [_ "PolyLines"]... \
		-variable MenuColorsForceChecked \
		-command {SelectColorEntity ColorPolyLines 3 ; set MenuColorsForceChecked 1}
        $base.menuEntityColor.m add checkbutton -label [_ "Surfaces"]... \
		-variable MenuColorsForceChecked \
		-command {SelectColorEntity ColorSurfaces 4 ; set MenuColorsForceChecked 1}
        $base.menuEntityColor.m add checkbutton -label [_ "Surfaces Iso"]... \
		-variable MenuColorsForceChecked \
		-command {SelectColorEntity ColorSurfsIsoparametric 5 ; set MenuColorsForceChecked 1}
        $base.menuEntityColor.m add checkbutton -label [_ "Volumes"]... \
		-variable MenuColorsForceChecked \
		-command {SelectColorEntity ColorVolumes 6 ; set MenuColorsForceChecked 1}
        $base.menuEntityColor.m add checkbutton -label [_ "Nodes"]... \
		-variable MenuColorsForceChecked \
		-command {SelectColorEntity ColorNodes 7 ; set MenuColorsForceChecked 1}
        $base.menuEntityColor.m add checkbutton -label [_ "Elements"]... \
		-variable MenuColorsForceChecked \
		-command {SelectColorEntity ColorElements 8 ; set MenuColorsForceChecked 1}
	
	GidHelp "$base.menuEntityColor" \
	        [_ "User can choose with this option the entity color of\
		the graphical window."]
	
	checkbutton $base.checkbutton#4 \
        	-text [_ " GUI attenuated"] \
		-disabledforeground grey60 \
		-variable ChangeVarInfo(GUIAppearance)

	GidHelp "$base.checkbutton#4" \
	        [_ "Set the GUI appearance to standard or attenuated color.\n\
		(the change is updated restarting $GidPriv(ProgName))"]
	
	button $base.button#4 \
		-disabledforeground grey60 \
		-text +
	
	scale $base.scale#4 \
		-from 1.0 \
		-highlightbackground black \
	        -label [_ "Curve precision"] \
		-length 1 \
		-orient h \
		-to 0.0 \
		-variable ChangeVarInfo(CurvePrecision) \
		-width 16 \
		-resolution 0.1

	button $base.button#3 \
		-disabledforeground grey60 \
		-text -

	checkbutton $base.checkbutton#3 \
		-disabledforeground grey60 \
        	-text [_ "Dynamic"] \
		-variable ChangeVarInfo(Dynamic)

	GidHelp "$base.frame#1 $base.button#4 $base.scale#4 $base.button#3 \
		$base.checkbutton#3" [_ "This option gives the precision used to\
		draw curves. The internal definition of curves does not change.\
		With the dynamic button, it is possible to dynamically change\
		the drawing of a curve to test the precision."]


	button $base.button#4b \
		-disabledforeground grey60 \
		-text +
	
	scale $base.scale#4b \
		-from 1.0 \
		-highlightbackground black \
	        -label [_ "Surface precision (Render) "] \
		-length 1 \
		-orient h \
		-to 0.0 \
		-variable ChangeVarInfo(SurfacePrecision) \
		-width 16 \
		-resolution 0.1

	button $base.button#3b \
		-disabledforeground grey60 \
		-text -

	GidHelp "$base.frame#1b $base.button#4b $base.scale#4b $base.button#3b" \
	        [_ "This option gives the precision used to\
		draw surfaces when in render mode"]

	checkbutton $base.checkbutton#2 \
		-disabledforeground grey60 \
        	-text [_ "Fast rotation"] \
		-variable ChangeVarInfo(FastRotation)

        GidHelp $base.checkbutton#2 [_ "When 'Fast rotation' is set, drawing will be\
		faster for both the geometry and the mesh when rotating the\
		model. The way of increasing speed depends on the options."]

        foreach i "point line coonsurf volume" {
	    if { ![info exist GidPriv(image_${i}16)] } {
		set GidPriv(image_${i}16) [ image create photo -file $GIDDEFAULT/bitmaps/${i}16x16.gif]
	    }
	}

	# checkbutton $base.checkbutton#15 \
	# 	  -disabledforeground grey60 \
	# 	  -bitmap @$GIDDEFAULT/bitmaps/point16x16 \
	# 	  -indicatoron 0 \
	# 	  -variable ChangeVarInfo(FRPoints)
	# 
	# checkbutton $base.checkbutton#13 \
	# 	  -disabledforeground grey60 \
	# 	  -bitmap @$GIDDEFAULT/bitmaps/line16x16 \
	# 	  -indicatoron 0 \
	# 	  -variable ChangeVarInfo(FRLines)
	# 
	# checkbutton $base.checkbutton#7 \
	# 	  -disabledforeground grey60 \
	# 	  -bitmap @$GIDDEFAULT/bitmaps/coonsurf16x16 \
	# 	  -indicatoron 0 \
	# 	  -variable ChangeVarInfo(FRSurfaces)
	# 
	# checkbutton $base.checkbutton#11 \
	# 	  -disabledforeground grey60 \
	# 	  -bitmap @$GIDDEFAULT/bitmaps/volume16x16 \
	# 	  -indicatoron 0 \
	# 	  -variable ChangeVarInfo(FRVolumes)

	set pp [ $base cget -background]
	
	checkbutton $base.checkbutton#15 \
		-disabledforeground grey60 \
		-image $GidPriv(image_point16) \
		-indicatoron 0 \
		-variable ChangeVarInfo(FRPoints) -bd 1 -selectcolor $pp
	
	checkbutton $base.checkbutton#13 \
		-disabledforeground grey60 \
		-image $GidPriv(image_line16) \
		-indicatoron 0 \
		-variable ChangeVarInfo(FRLines) -bd 1 -selectcolor $pp

	checkbutton $base.checkbutton#7 \
		-disabledforeground grey60 \
		-image $GidPriv(image_coonsurf16) \
		-indicatoron 0 \
		-variable ChangeVarInfo(FRSurfaces) -bd 1 -selectcolor $pp

	checkbutton $base.checkbutton#11 \
		-disabledforeground grey60 \
		-image $GidPriv(image_volume16) \
		-indicatoron 0 \
		-variable ChangeVarInfo(FRVolumes) -bd 1 -selectcolor $pp

	GidHelp $base.checkbutton#15 $base.checkbutton#13 $base.checkbutton#7 \
	        $base.checkbutton#11" [_ "To draw or not to draw this type of entity\
	        when rotating."]

	checkbutton $base.checkbutton#10 \
		-disabledforeground grey60 \
	        -text [_ "Always geometry"] \
		-variable ChangeVarInfo(AlwaysGeom)

        GidHelp $base.checkbutton#10 \
		[_ "If set, when viewing the mesh and rotating, the geometry is drawn instead."]

        checkbutton $base.checkbutton#16 \
	        -disabledforeground grey60 \
           	-text [_ "Graphic objects"] \
		-variable ChangeVarInfo(DrawGraphicObjects)

	GidHelp $base.checkbutton#16 [_ "If not set, when rotating the geometry,\
		some graphical and temporal objects like normals or materials\
		or conditions symbols are not drawn. "]

	button $base.button#7 \
		-command {set ChangeVarInfo(FRCurvePrecision) \
		[expr $ChangeVarInfo(FRCurvePrecision)+0.1]} \
		-disabledforeground grey60 \
		-text +

	scale $base.scale#5 \
		-activebackground AntiqueWhite3 \
		-from 1.0 \
		-highlightbackground black \
	        -label [_ "Curve precision"] \
		-length 0 \
		-orient h \
		-to 0.0 \
		-variable ChangeVarInfo(FRCurvePrecision) \
		-width 16 \
		-resolution 0.1

	button $base.button#9 \
		-command {set ChangeVarInfo(FRCurvePrecision) \
		[expr $ChangeVarInfo(FRCurvePrecision)-0.1]} \
		-disabledforeground grey60 \
		-text -
		
	GidHelp "$base.button#7 $base.scale#5 $base.button#9" [_ "The same as general\
	        'Curve precision', but applied only when rotating."]

	# Geometry management
	
	grid $base.checkbutton#1 -in $root	-row 1 -column 1  \
		-sticky e
	grid $base.entry#1 -in $root	-row 1 -column 2  \
		-sticky w

	grid $base.label#35 -in $root	-row 2 -column 1  \
		-sticky e

	grid $base.menubutton#1 -in $root	-row 2 -column 2  \
		-sticky w

	grid $base.labelQuadratic -in $root	-row 3 -column 1  \
		-sticky e

	grid $base.menubuttonQuadratic -in $root -row 3 -column 2  \
		-sticky w

	grid $base.frmBackgroundColor -in $root	-row 4 -column 1  \
		-columnspan 2 \
		-padx 6 -pady 6\
		-sticky w

	grid $base.frame#1 -in $root	-row 5 -column 1  \
		-columnspan 2 \
		-padx 6 \
		-sticky ew

	grid $base.frame#1b -in $root	-row 6 -column 1  \
		-columnspan 2 \
		-padx 6 \
		-sticky ew

	grid $base.frame#3 -in $root	-row 8 -column 1  \
		-columnspan 2 \
		-padx 6 \
		-sticky ew
	
	grid $base.checkbutton#2 -in $root	-row 7 -column 1  \
		-padx 10 \
		-sticky w

	grid $base.button#4 -in $base.frame#1	-row 1 -column 1 
	grid $base.scale#4 -in $base.frame#1	-row 1 -column 2  \
		-sticky ew
	grid $base.button#3 -in $base.frame#1	-row 1 -column 3 
	grid $base.checkbutton#3 -in $base.frame#1	-row 2 -column 2  \
		-sticky w


	grid $base.button#4b -in $base.frame#1b	-row 1 -column 1 
	grid $base.scale#4b -in $base.frame#1b	-row 1 -column 2  \
		-sticky ew
	grid $base.button#3b -in $base.frame#1b	-row 1 -column 3 
	
	grid $base.menuEntityColor -in $base.frmBackgroundColor -row 1 -column 1

	grid $base.checkbutton#4 -in $base.frmBackgroundColor -row 1 -column 2

	grid $base.checkbutton#15 -in $base.frame#3	-row 1 -column 1  \
		-sticky w
	grid $base.checkbutton#13 -in $base.frame#3	-row 1 -column 2  \
		-sticky w
	grid $base.checkbutton#7 -in $base.frame#3	-row 2 -column 1 \
		-sticky w
	grid $base.checkbutton#11 -in $base.frame#3	-row 2 -column 2  \
		-sticky w
	grid $base.checkbutton#10 -in $base.frame#3	-row 1 -column 3  \
		-sticky w
	grid $base.checkbutton#16 -in $base.frame#3	-row 2 -column 3  \
		-sticky w

	grid $base.frame#4 -in $base.frame#3	-row 4 -column 1  \
		-columnspan 3 \
		-sticky ew

	grid $base.button#7 -in $base.frame#4	-row 1 -column 1 
	grid $base.scale#5 -in $base.frame#4	-row 1 -column 2  \
		-sticky ew
	grid $base.button#9 -in $base.frame#4	-row 1 -column 3 

	# Resize behavior management

	grid rowconfigure $base.frame#3 1 -weight 0 -minsize 1
	grid rowconfigure $base.frame#3 2 -weight 0 -minsize 1
	grid rowconfigure $base.frame#3 3 -weight 0 -minsize 2
	grid columnconfigure $base.frame#3 1 -weight 0 -minsize 24
	grid columnconfigure $base.frame#3 2 -weight 0 -minsize 24
	grid columnconfigure $base.frame#3 3 -weight 1 -minsize 6

	grid rowconfigure $root 1 -weight 0 -minsize 30
	grid rowconfigure $root 2 -weight 0 -minsize 30
	grid rowconfigure $root 3 -weight 0 -minsize 30
	grid rowconfigure $root 4 -weight 0 -minsize 30
	grid rowconfigure $root 5 -weight 0 -minsize 30
	grid rowconfigure $root 6 -weight 0 -minsize 30
	grid rowconfigure $root 7 -weight 0 -minsize 30
	grid rowconfigure $root 8 -weight 0 -minsize 30
	grid columnconfigure $root 1 -weight 0 -minsize 2
	grid columnconfigure $root 2 -weight 1 -minsize 2

	grid rowconfigure $base.frame#4 1 -weight 1 -minsize 2
	grid columnconfigure $base.frame#4 1 -weight 0 -minsize 2
	grid columnconfigure $base.frame#4 2 -weight 1 -minsize 90
	grid columnconfigure $base.frame#4 3 -weight 0 -minsize 22

	grid rowconfigure $base.frame#1 1 -weight 0 -minsize 2
	grid rowconfigure $base.frame#1 2 -weight 0 -minsize 2
	grid rowconfigure $base.frame#1b 1 -weight 0 -minsize 2
	grid rowconfigure $base.frame#1b 2 -weight 0 -minsize 2
	grid columnconfigure $base.frame#1 1 -weight 0 -minsize 13
	grid columnconfigure $base.frame#1 2 -weight 1 -minsize 2
	grid columnconfigure $base.frame#1 3 -weight 0 -minsize 13
	grid columnconfigure $base.frame#1b 1 -weight 0 -minsize 13
	grid columnconfigure $base.frame#1b 2 -weight 1 -minsize 2
	grid columnconfigure $base.frame#1b 3 -weight 0 -minsize 13
# additional interface code


proc ChangeFastRotation {name1 name2 op} {
    global ChangeVarInfo

    set slaves [grid slaves $ChangeVarInfo(FRFrame)]
    foreach i $slaves {
	set slaves [concat $slaves [grid slaves $i]]
    }

    foreach i $slaves {
	if { $ChangeVarInfo(FastRotation) == 0 } {
	    catch { 
		$i conf -state disabled
		if { [winfo class $i] == "Scale" } { $i conf -fg grey60 }
	    }
	} else { 
	    catch {
	    $i conf -state normal 
		if { [winfo class $i] == "Scale" } { $i conf -fg black }
	    }   
	}
    }
}

proc selectEntityColor { entity } {
    global ChangeVarInfo
    global base
    
    # Select and Update interface
    #set retcol [tk_chooseColor -initialcolor $ChangeVarInfo($entity)]
    set retcol [BWChooseColor $base.selectcolor -title [_ "Select color"] -color $ChangeVarInfo($entity)]
    
    # Set preference 
    if { $retcol != "" } {
	 set  ChangeVarInfo($entity) $retcol
	 set res 1
    } else {
	set res 0
    }
     
    return $res
}

proc ChangeColor  {name elem op} {       
  global ChangeVarInfo
  global base
  set indice 0
  foreach i "BackgroundColor ColorPoints ColorLines ColorPolyLines \
             ColorSurfaces ColorSurfsIsoparametric ColorVolumes \
             ColorNodes ColorElements" {
    if [ info exists ChangeVarInfo($i) ] {
      $base.menuEntityColor.m  entryconfigure $indice -selectcolor $ChangeVarInfo($i)
    }
    incr indice
  }
}

proc SelectColorEntity { entity indice} {
  global ChangeVarInfo
  global base
  if { [selectEntityColor $entity] } {
    $base.menuEntityColor.m  entryconfigure $indice -selectcolor $ChangeVarInfo($entity)
  }	    
}

global ChangeVarInfo

set ChangeVarInfo(PG) $base 
set ChangeVarInfo(FRFrame) $base.frame#3

trace variable ChangeVarInfo(FastRotation) w ChangeFastRotation
# mpc
#trace variable ChangeVarInfo(BackgroundColor) w changeBackgroundColor

trace variable ChangeVarInfo(BackgroundColor) w ChangeColor
trace variable ChangeVarInfo(ColorPoints) w ChangeColor
trace variable ChangeVarInfo(ColorLines) w ChangeColor
trace variable ChangeVarInfo(ColorPolyLines) w ChangeColor
trace variable ChangeVarInfo(ColorSurfaces) w ChangeColor
trace variable ChangeVarInfo(ColorSurfsIsoparametric) w ChangeColor
trace variable ChangeVarInfo(ColorVolumes) w ChangeColor
trace variable ChangeVarInfo(ColorNodes) w ChangeColor
trace variable ChangeVarInfo(ColorElements) w ChangeColor
#mpc


proc LightsmoothedelementsProc {} {
    global ChangeVarInfo

    if { $ChangeVarInfo(Lightsmoothedelements) } {
	$ChangeVarInfo(PG).entry#1 conf -state normal
	$ChangeVarInfo(PG).entry#1 conf -fg black
    } else {
	$ChangeVarInfo(PG).entry#1 conf -state disabled
	$ChangeVarInfo(PG).entry#1 conf -fg grey60
    }
}

trace variable ChangeVarInfo(Lightsmoothedelements) w \
	"LightsmoothedelementsProc ;#"

proc DrawSurfaceModeProc {} {
    global ChangeVarInfo
    switch $ChangeVarInfo(DrawSurfaceMode) {
	"Boundary lines" {
	    $ChangeVarInfo(PG).menubutton#1 conf -text [_ "Boundary"] 
	}
	"Isoparametric lines" {
	    $ChangeVarInfo(PG).menubutton#1 conf -text [_ "Isoparam."]
	}
	"Both modes" {
	    $ChangeVarInfo(PG).menubutton#1 conf -text [_ "Both"]
	}
	"None" {
	    $ChangeVarInfo(PG).menubutton#1 conf -text [_ "None"]
	}
    }
}

trace variable ChangeVarInfo(DrawSurfaceMode) w "DrawSurfaceModeProc ;#"


$base.checkbutton#3 conf -command " \
	if { \$ChangeVarInfo(Dynamic) == 1 } {  \
	    $base.scale#4 conf -command DynamicPrecision \
        } else { $base.scale#4 conf -command {} } \
	"

set ChangeVarInfo(ScalePrecision) $base.scale#4
$base.button#4 conf -command {
    $ChangeVarInfo(ScalePrecision) set \
	    [expr $ChangeVarInfo(CurvePrecision)+0.1]
}

$base.button#3 conf -command {
	$ChangeVarInfo(ScalePrecision) set \
	[expr $ChangeVarInfo(CurvePrecision)-0.1]
}

set ChangeVarInfo(ScalePrecisionb) $base.scale#4b
$base.button#4b conf -command {
    $ChangeVarInfo(ScalePrecisionb) set \
	    [expr $ChangeVarInfo(SurfacePrecision)+0.1]
}

$base.button#3b conf -command {
	$ChangeVarInfo(ScalePrecisionb) set \
	[expr $ChangeVarInfo(SurfacePrecision)-0.1]
}

# end additional interface code

}


# Allow interface to be run "stand-alone" for testing

catch {
    if {$argv0 == [info script]} {
	wm title . [_ "Testing pref_graphical"]
	pref_graphical_ui .
    }
}
