#!/bin/sh
#PostDisplay -*- TCL -*- Created: miguel Jan-1997

namespace eval AnimacionEstatica {
    variable _wid
    variable _tipo
    variable _pasos
    variable _imagenes
}

proc AnimacionEstatica::Cerrar { } {
    variable _wid

    if { ![info exist _wid] || ![ winfo exist $_wid] } { return}
    destroy $_wid
}

proc AnimacionEstatica::CambiaTipo { que} {
    variable _tipo
    
    set _tipo $que
}

proc AnimacionEstatica::Aceptar { } {
    variable _wid
    variable _tipo
    variable _pasos
    global AnimacionEstatica

    set res [ scan $_pasos %d pp]
    if { ( $res != 1) || ( $_pasos <= 1)} {
	WarnWin [_ "Number of steps for the animation should be > 1, and not '%s'" $_pasos] $_wid
    } else {
	set AnimacionEstatica(tipo) $_tipo
	set AnimacionEstatica(pasos) $_pasos
	AnimacionEstatica::Cerrar
    }
}

proc AnimacionEstatica::Crear { parent_w} {
    variable _wid
    variable _tipo
    variable _pasos
    variable _imagenes
    global AnimacionEstatica GIDDEFAULT
    set _tipo $AnimacionEstatica(tipo)
    set _pasos $AnimacionEstatica(pasos)

    if { "$parent_w" == "."} {
	set _wid .__w_Animacion_estatica
    } else {
	set _wid $parent_w.__w_Animacion_estatica
    }
    
    toplevel $_wid

    wm title $_wid [_ "Creating animation of static analysis"]

    set def_back [ $parent_w cget -background]
    set realzado [ CCColorActivo $def_back]

    frame $_wid.f -bd 0

    foreach ti "Lineal Cosine Triangular Sinusoidal" {
	if { ![ info exists _imagenes($ti)]} {
	    set _imagenes($ti) [image create bitmap -file [ file join $GIDDEFAULT bitmaps StaticAnim$ti.xbm] \
		 -foreground black]
	}
    }
    radiobutton $_wid.f.rd1 -image $_imagenes(Lineal) -value Lineal -variable AnimacionEstatica::_tipo
    radiobutton $_wid.f.rd2 -image $_imagenes(Cosine) -value Cosine -variable AnimacionEstatica::_tipo
    radiobutton $_wid.f.rd3 -image $_imagenes(Triangular) -value Triangular -variable AnimacionEstatica::_tipo
    radiobutton $_wid.f.rd4 -image $_imagenes(Sinusoidal) -value Sinusoidal -variable AnimacionEstatica::_tipo
    label $_wid.f.l -text [_ "Steps:"]
    entry $_wid.f.e -width 5 -textvariable AnimacionEstatica::_pasos -bd 1 -relief sunken


    grid $_wid.f.rd1 $_wid.f.rd2 -sticky w -pady 4 -padx 4
    grid $_wid.f.rd3 $_wid.f.rd4 -sticky w -pady 4 -padx 4
    grid $_wid.f.l $_wid.f.e -sticky e -pady 4 -padx 4
    grid conf $_wid.f.e -sticky w

    # marco de los botones
    frame $_wid.but -bd 0 -background $realzado

    button $_wid.but.apply -text [_ "Apply"] -command "AnimacionEstatica::Aceptar" -takefocus 0 -bd 1
    button $_wid.but.close -text [_ "Close"] -command AnimacionEstatica::Cerrar -takefocus 0 -bd 1
    grid $_wid.but.apply -sticky ews -padx 4 -pady 10
    grid $_wid.but.close -sticky ews -padx 4 -pady 10 -row 0 -column 1

    #enpaquetamos marcos
    grid $_wid.f -sticky news -padx 0 -pady 0
    grid $_wid.but -sticky wes

    grid columnconfigure $_wid 0 -weight 1
    grid rowconfigure $_wid 0 -weight 1

    AjustaPosicion $_wid $parent_w
    
    return $_wid
}


proc PostAnimateDisableGUIUpdates { } {
    .central.s disable windows 1
    #.central.s disable graphinput 1
    #.central.s disable graphics 1
    .central.s disable warnline 1
}

proc PostAnimateEnableGUIUpdates { } {
    .central.s disable windows 0
    #.central.s disable graphinput 0
    #.central.s disable graphics 0
    .central.s disable warnline 0
}


proc PostAnimateInitValues {} {    
    global GidPriv AnimacionEstatica

    set GidPriv(PostAnimateDoing) Nothing
    set GidPriv(PostAnimateDeform) 0
    set GidPriv(PostAnimateRsultView) ""
    set GidPriv(PostAnimateCurrentButton) ""
    set GidPriv(PostAnimateDefaultDelayTime) 500
    set GidPriv(PostAnimateDelayTime) $GidPriv(PostAnimateDefaultDelayTime)
    set GidPriv(PostAnimateDelay) 0
    set GidPriv(PostAnimateOldAutoRedraw) 1
    set GidPriv(PostAnimateSaveFrame) 0
    set GidPriv(PostAnimateSaveAnimation) 0
    set GidPriv(PostAnimateSavingAnimation) 0
    set GidPriv(PostAnimateSavingRepes) 1
    set GidPriv(PostAnimateSlideDelay) 10
    set GidPriv(PostAnimateSliding) 0
    set GidPriv(PostAnimateAnalysisLimitsCb) 0
    set GidPriv(PostAnimateSaveAnimationFormat) [.central.s info post get animationformat]
    set GidPriv(PostAnimateSaveFrameFormat) "TIFF"
    set GidPriv(PostAnimateSaveAnimationFormat) "MPEG"
    set info2 [.central.s configure]
    set height_list [ lindex $info2 0]
    set width_list [ lindex $info2 1]
    set current [format "%dx%d" [ lindex $width_list 4] [ lindex $height_list 4]]
    set GidPriv(PostAnimateResizeDefault) "$current"
    set GidPriv(PostAnimateResize) Default
    set GidPriv(PostAnimateTime) 0

    # para animaciones de un solo paso de analisis
    set AnimacionEstatica(tipo) Lineal
    set AnimacionEstatica(pasos) 10
    set AnimacionEstatica(hay) 0
}

proc AnimacionEstaticaCreaFactores { factor_base} {
    global AnimacionEstatica

    switch "$AnimacionEstatica(tipo)" {
	"Lineal" {
	    set f [ expr 1.0 / double( $AnimacionEstatica(pasos))]
	    set AnimacionEstatica(factores) ""
	    for { set i 1} { $i < $AnimacionEstatica(pasos)} { incr i} {
		lappend AnimacionEstatica(factores) [ expr $factor_base * $i * $f]
	    }
	    # para asegurarnos que este
	    lappend AnimacionEstatica(factores) $factor_base
	}
	"Cosine" {
	    set f [ expr 2.0 * acos( 0.0) / double( $AnimacionEstatica(pasos))]
	    set AnimacionEstatica(factores) ""
	    for { set i 1} { $i < $AnimacionEstatica(pasos)} { incr i} {
		lappend AnimacionEstatica(factores) [ expr $factor_base * 0.5 * ( 1.0 - cos( $f * $i))]
	    }
	    # para asegurarnos que este
	    lappend AnimacionEstatica(factores) $factor_base
	}
	"Triangular" {
	    if { $AnimacionEstatica(pasos) == 2} {
		set AnimacionEstatica(factores) ""
		lappend AnimacionEstatica(factores) $factor_base
		lappend AnimacionEstatica(factores) $factor_base
	    } else {
		set p2 [ expr ( $AnimacionEstatica(pasos)) / 2]
		set f [ expr 1.0 / double( $p2)]
		set AnimacionEstatica(factores) ""
		for { set i 1} { $i < $p2} { incr i} {
		    lappend AnimacionEstatica(factores) [ expr $factor_base * $i * $f]
		}
		# para asegurarnos que este
		lappend AnimacionEstatica(factores) $factor_base
		# si es impar repetimos $factor_base, p.ej. 
		# 3 pasos -> 1.0 1.0 0.0
		# 4 pasos -> 0.5 1.0 0.5 0.0
		# 5 pasos -> 0.5 1.0 1.0 0.5 0.0
		if { [ expr $AnimacionEstatica(pasos) % 2]} {
		    lappend AnimacionEstatica(factores) $factor_base
		}
		for { set i 1} { $i <= $p2} { incr i} {
		    lappend AnimacionEstatica(factores) [ expr $factor_base * ( $p2 - $i) * $f]
		}
	    }
	}
	"Sinusoidal" {
	    if { $AnimacionEstatica(pasos) == 2} {
		set AnimacionEstatica(factores) ""
		lappend AnimacionEstatica(factores) $factor_base
		lappend AnimacionEstatica(factores) $factor_base
	    } else {
		set p2 [ expr ( $AnimacionEstatica(pasos)) / 2]
		set f [ expr 2.0 * acos( 0.0) / double( $p2)]
		set AnimacionEstatica(factores) ""
		for { set i 1} { $i < $p2} { incr i} {
		    lappend AnimacionEstatica(factores) [ expr $factor_base * 0.5 * ( 1.0 - cos( $f * $i))]
		}
		# para asegurarnos que este
		lappend AnimacionEstatica(factores) $factor_base
		# si es impar repetimos $factor_base, p.ej. 
		# 3 pasos -> 1.0 1.0 0.0
		# 4 pasos -> 0.5 1.0 0.5 0.0
		# 5 pasos -> 0.5 1.0 1.0 0.5 0.0
		if { [ expr $AnimacionEstatica(pasos) % 2]} {
		    lappend AnimacionEstatica(factores) $factor_base
		}
		for { set i 1} { $i <= $p2} { incr i} {
		    lappend AnimacionEstatica(factores) [ expr $factor_base * 0.5 * ( 1.0 - cos( $f * ( $p2 - $i)))]
		}
	    }
	}
    }
}

proc CambioPostAnimateDeform { name1 name2 op} {
    global GidPriv AnimacionEstatica

    if { ![ info exist GidPriv(PostAnimateWindow)] || ![ winfo exist $GidPriv(PostAnimateWindow)] } {
	return
    }

    # if { $GidPriv(PostAnimateDeform)}
    set mainst [.central.s info post get main_geom_state]
    if { $mainst == "Deformed" } {
	if { [ llength $GidPriv(PostAnimate_all_step)] != 1} {
	    $AnimacionEstatica(boton) conf -state disable -foreground grey60
	    set AnimacionEstatica(hay) 0
	} else {
	    $AnimacionEstatica(boton) conf -state normal -foreground black
	    set AnimacionEstatica(hay) 1
	}
	AnimacionEstaticaCreaFactores $GidPriv(PostAnimate_cur_d_factor)
    } else {
	$AnimacionEstatica(boton) conf -state disable -foreground grey60
	set AnimacionEstatica(hay) 0
    }
}

proc PostAnimateConfigureSlide {} {
    global GidPriv AnimacionEstatica

    if { ![ winfo exist $GidPriv(PostAnimateSlide)] } { return}

    if { $GidPriv(PostAnimateDeform) } {
	if { $AnimacionEstatica(hay)} {
	    $GidPriv(PostAnimateSlide) conf -from 0 -to [ expr [ llength $AnimacionEstatica(factores)]] -resolution 1
	} else {
	    $GidPriv(PostAnimateSlide) conf -from 0 -to [ expr [ llength $GidPriv(PostAnimate_all_step)]] -resolution 1
	}

	#set GidPriv(PostAnimateCurrentFrame) -1
	#$GidPriv(PostAnimateSlide) set [ expr $GidPriv(PostAnimateCurrentFrame)+1]
	#$GidPriv(PostAnimateEntry) conf -state normal
	#$GidPriv(PostAnimateEntry) del 0 end
	#$GidPriv(PostAnimateEntry) ins 0 "Orig"
	#$GidPriv(PostAnimateEntry) conf -state disabled

	if { $AnimacionEstatica(hay)} {
	    set res [ lsearch $AnimacionEstatica(factores) $GidPriv(PostAnimate_cur_d_factor)]
	} else {
	    set res [ lsearch $GidPriv(PostAnimate_all_step) $GidPriv(PostAnimate_cur_d_step)]
	}
	set frame $res

	if { $AnimacionEstatica(hay)} {
	    set istep [ lindex $AnimacionEstatica(factores) $frame]
	} else {
	    set istep [ lindex $GidPriv(PostAnimate_all_step) $frame]
	}
	$GidPriv(PostAnimateEntry) conf -state normal
	$GidPriv(PostAnimateEntry) del 0 end
	if { $istep == ""} {
	    set frame -1
	    $GidPriv(PostAnimateEntry) ins 0 "Orig"
	} else {
	    $GidPriv(PostAnimateEntry) ins 0 $istep
	}
	$GidPriv(PostAnimateEntry) conf -state disabled
	$GidPriv(PostAnimateSlide) set [ expr $frame+1]

	set frame [ expr $res+1]
	if { $AnimacionEstatica(hay)} {
	    set istep [ lindex $AnimacionEstatica(factores) $frame]
	} else {
	    set istep [ lindex $GidPriv(PostAnimate_all_step) $frame]
	}
	if { $istep == ""} {
	    set frame -1
	} else {
	    set frame $res
	}

	set GidPriv(PostAnimateCurrentFrame) $frame

    } else {
	set nsteps [ llength $GidPriv(PostAnimate_all_step)]
	if { $nsteps != 0} {
	    $GidPriv(PostAnimateSlide) conf -from 1 -to $nsteps -resolution 1

	    #set GidPriv(PostAnimateCurrentFrame) 0
	    #$GidPriv(PostAnimateSlide) set [ expr $GidPriv(PostAnimateCurrentFrame)+1]

	    set res [ lsearch $GidPriv(PostAnimate_all_step) $GidPriv(PostAnimate_cur_step)]
	    set frame $res
	    
	    set istep [ lindex $GidPriv(PostAnimate_all_step) $frame]
	    $GidPriv(PostAnimateEntry) conf -state normal
	    $GidPriv(PostAnimateEntry) del 0 end
	    $GidPriv(PostAnimateEntry) ins 0 $istep
	    $GidPriv(PostAnimateEntry) conf -state disabled
	    $GidPriv(PostAnimateSlide) set [ expr $frame+1]
	    
	    set frame [ expr $res+1]
	    set istep [ lindex $GidPriv(PostAnimate_all_step) $frame]
	    if { $istep == ""} {
		set frame 0
	    } else {
		set frame $res
	    }
	    
	    set GidPriv(PostAnimateCurrentFrame) $frame
	    
	    #$GidPriv(PostAnimateSlide) set [ expr $GidPriv(PostAnimateCurrentFrame)+1]
	    #
	    #set istep [ lindex $GidPriv(PostAnimate_all_step) $GidPriv(PostAnimateCurrentFrame)]
	    #$GidPriv(PostAnimateEntry) conf -state normal
	    #$GidPriv(PostAnimateEntry) del 0 end
	    #$GidPriv(PostAnimateEntry) ins 0 $istep
	    #$GidPriv(PostAnimateEntry) conf -state disabled
	} else {
	    $GidPriv(PostAnimateSlide) conf -from 0 -to 0 -resolution 1
	    $GidPriv(PostAnimateEntry) conf -state normal
	    $GidPriv(PostAnimateEntry) del 0 end
	    $GidPriv(PostAnimateEntry) conf -state disabled
	    
	    set GidPriv(PostAnimateCurrentFrame) 0
	}
    }
    set GidPriv(PostAnimateSlideDelay) 10
    set GidPriv(PostAnimateSliding) 0
    update
}

proc PostAnimateInitVariables { } {
    global GidPriv AnimacionEstatica

    if { [ info exist GidPriv(PostAnimateInitializing)] && $GidPriv(PostAnimateInitializing)} { return}

    if { ![ info exist GidPriv(PostAnimateDoing)] } { set GidPriv(PostAnimateDoing) "Nothing"}

    if { $GidPriv(PostAnimateDoing) != "Nothing"} { return}

    set GidPriv(PostAnimateInitializing) 1

    set GidPriv(PostAnimate_cur_anal) [.central.s info post get cur_analisis]
    set cur_anal $GidPriv(PostAnimate_cur_anal)
    set GidPriv(PostAnimate_cur_step) [.central.s info post get cur_step $cur_anal]
    set GidPriv(PostAnimate_all_step) [.central.s info post get all_steps $cur_anal]
    #set GidPriv(PostAnimate_all_step,anal) [.central.s info post get all_steps $cur_anal]
    set GidPriv(PostAnimate_cur_resv) [.central.s info post get cur_results_view]
    set GidPriv(PostAnimate_cur_res)  [ join [.central.s info post get cur_result]]
    set GidPriv(PostAnimate_cur_comp) [ join [.central.s info post get cur_component]]

    set GidPriv(PostAnimateVariosResultados) [ string tolower [ .central.s info variables postresoverres]]
    set GidPriv(PostAnimateListaResultados) [ .central.s info post get results_view_list]

    set GidPriv(PostAnimate_cur_d_defor) [ .central.s info post get main_geom_cur_deform]
    
    set GidPriv(PostAnimate_cur_d_anal) [ .central.s info post get main_geom_cur_anal]
    set GidPriv(PostAnimate_cur_d_step) [ .central.s info post get main_geom_cur_step]
    set GidPriv(PostAnimate_cur_d_factor) [.central.s info post get main_geom_cur_factor]

    set GidPriv(PostAnimate_cur_defor_type) [ .central.s info post get main_geom_deformation_type]

#    set GidPriv(PostAnimate_cur_d_factor) [.central.s info post get main_geom_factor $GidPriv(PostAnimate_cur_d_defor) $GidPriv(PostAnimate_cur_d_anal) $GidPriv(PostAnimate_cur_d_step)]
    
#     set GidPriv(PostAnimateDoing) Nothing
#     set GidPriv(PostAnimateCurrentButton) ""
#     set GidPriv(PostAnimateDefaultDelayTime) 500
#     set GidPriv(PostAnimateDelayTime) $GidPriv(PostAnimateDefaultDelayTime)
#     set GidPriv(PostAnimateDelay) 0
#     set GidPriv(PostAnimateOldAutoRedraw) 1

    regsub -all {_} $GidPriv(PostAnimate_cur_resv) {} pepe

    set GidPriv(PostAnimate_cur_resv) $pepe

    set GidPriv(PostAnimateResultViewCb) 1
    switch $GidPriv(PostAnimate_cur_resv) {
	"ShMinMax" { set GidPriv(PostAnimateResultView) $GidPriv(PostAnimate_cur_resv)}
	"ContourFill" { set GidPriv(PostAnimateResultView) $GidPriv(PostAnimate_cur_resv)}
	"SmoothContourFill" { set GidPriv(PostAnimateResultView) $GidPriv(PostAnimate_cur_resv)}
	"ContourLines" { set GidPriv(PostAnimateResultView) $GidPriv(PostAnimate_cur_resv)}
	"IsoSurfaces" { 
	    set GidPriv(PostAnimateResultView) $GidPriv(PostAnimate_cur_resv)
	    set GidPriv(PostAnimateIsoSurfaces) [ lindex [.central.s info post get iso_cur_result_values] 0]
	}
	"DisplayVectors" {
	    set GidPriv(PostAnimateResultView) $GidPriv(PostAnimate_cur_resv)
	    set GidPriv(PostAnimateDisplayVectors) [.central.s info post get cur_vector_factor \
		    Display_Vectors $GidPriv(PostAnimate_cur_res) $GidPriv(PostAnimate_cur_anal) \
		    $GidPriv(PostAnimate_cur_step)]
	}
	"ContourRanges" { set GidPriv(PostAnimateResultView) $GidPriv(PostAnimate_cur_resv)}
	"ScalarLineDiagram" { 
	    set GidPriv(PostAnimateResultView) $GidPriv(PostAnimate_cur_resv)
	    set GidPriv(PostAnimateScalarDiagram) [.central.s info post get cur_diagram_factor\
		    $GidPriv(PostAnimate_cur_res) $GidPriv(PostAnimate_cur_comp) $GidPriv(PostAnimate_cur_anal) \
		    $GidPriv(PostAnimate_cur_step)]
	}
	"VectorLineDiagram" { 
	    set GidPriv(PostAnimateResultView) $GidPriv(PostAnimate_cur_resv)
	    set GidPriv(PostAnimateVectorDiagram) [.central.s info post get cur_diagram_factor\
		    $GidPriv(PostAnimate_cur_res) $GidPriv(PostAnimate_cur_anal) \
		    $GidPriv(PostAnimate_cur_step)]
	}
	default { 
	    set GidPriv(PostAnimateResultView) ""
	    set GidPriv(PostAnimateResultViewCb) 0
	}
    }

    if { [ info exist GidPriv(PostAnimateResButtons)] && [ winfo exist $GidPriv(PostAnimateResButtons).b1] } {
	if { $GidPriv(PostAnimateResultViewCb) } {
	    #$GidPriv(PostAnimateResButtons).l conf -foreground black
	    $GidPriv(PostAnimateResButtons).b1 conf -state normal
	    #$GidPriv(PostAnimateResButtons).b2 conf -state normal
	} else {
	    #$GidPriv(PostAnimateResButtons).l conf -foreground grey60
	    $GidPriv(PostAnimateResButtons).b1 conf -state disabled
	    #$GidPriv(PostAnimateResButtons).b2 conf -state disabled
	}
    }

    #if { [ info exist GidPriv(PostAnimateAnalysisLimitsCb)] && \
    #	     $GidPriv(PostAnimateAnalysisLimitsCb) } {
    #	 PostAnimateGetAnalysisLimits "" "" ""
    #}


    set mainst [.central.s info post get main_geom_state]
    if { $mainst == "Deformed" } {
	set GidPriv(PostAnimateDeform) 1
    } else {
	set GidPriv(PostAnimateDeform) 0
    }

    if { [ info exist GidPriv(PostAnimateWindow)] && [ winfo exist $GidPriv(PostAnimateWindow)] } {
	if { ( $GidPriv(PostAnimateResultView) != "") && $GidPriv(PostAnimateDeform) } {
	    if { $GidPriv(PostAnimate_cur_d_anal) != $GidPriv(PostAnimate_cur_anal) } {

		# verificamos que en ambos analisis hay igual numero de pasos y con igual valor
		set GidPriv(PostAnimate_all_d_step) [.central.s info post get all_steps $GidPriv(PostAnimate_cur_d_anal)]
		set iguales 1
		if { [ llength $GidPriv(PostAnimate_all_step)] != [ llength $GidPriv(PostAnimate_all_d_step)] } {
		    set iguales 0
		} else {
		    set l [ llength $GidPriv(PostAnimate_all_step)]
		    for { set idx 0} { $idx < $l} { incr idx} {
			if { "[ lindex $GidPriv(PostAnimate_all_step) $idx]" != "[ lindex $GidPriv(PostAnimate_all_d_step) $idx]"} {
			    set iguales 0
			    break
			}
		    }
		}

		if { $iguales} {
		    # verificamos que el paso es el mismo para el resultado como para la deformada
		    if { $GidPriv(PostAnimate_cur_step) != $GidPriv(PostAnimate_cur_d_step)} {
			WarnWin "Current Deformation step differs from the current Result View's step." $GidPriv(PostAnimateWindow)
		    }
		} else {
		    set resp [ tk_dialog  $GidPriv(PostAnimateWindow).___pa_ww [_ "Warning"] \
			    [_ "Current Deformation analysis differs from current Result View's analysis. \
			    Choose which one should be valid for the animation"] \
			    info 2 [_ "ResultView"] [_ "Deformation"] [_ "Cancel"]]
		    switch $resp {
			0 {
			    set GidPriv(PostAnimateDeform) 0
			}
			1 {
			    set GidPriv(PostAnimateResultView) ""
			}
			2 {
			    set GidPriv(PostAnimateResultView) ""
			    set GidPriv(PostAnimateDeform) 0
			}
		    }
		}
	    }
	}
    }

    if { [ info exist GidPriv(PostAnimateSlide)] } {
	PostAnimateConfigureSlide
    }

    set GidPriv(PostAnimateInitializing) 0

    if { [ info exist GidPriv(PostAnimateAnalysisLimitsCb)] && \
	    $GidPriv(PostAnimateAnalysisLimitsCb) } {
	PostAnimateGetAnalysisLimits "" "" ""
    }
}

proc PostAnimateFrame { frame} {
    global GidPriv AnimacionEstatica
    
    #WarnWin "$GidPriv(PostAnimateDoing) $frame"
    switch $GidPriv(PostAnimateDoing) {
	"Nothing" { return}
	"Stop" {
	    PostAnimateEnableGUIUpdates
	    if { $GidPriv(PostAnimateSavingAnimation) } {
		.central.s process escape escape escape escape animationfile end
		set GidPriv(PostAnimateSavingAnimation) 0
	    }

	    if { $GidPriv(PostAnimateDeform)} {
		# reactivate redraw
		.central.s process escape escape escape escape utilities variables \
			AutomaticRedraw $GidPriv(PostAnimateOldAutoRedraw) escape escape 
		.central.s render
	    }
	    #set GidPriv(PostAnimateCurrentFrame) [ expr $frame-1]
	    set GidPriv(PostAnimateCurrentFrame) $frame
	    #WarnWin "Frame:Stop: $GidPriv(PostAnimateCurrentFrame)"
	    
	    catch {
		if { $GidPriv(PostAnimateCurrentButton) != ""} {
		    $GidPriv(PostAnimateCurrentButton) conf -relief raise
		} 
	    }
	    update
	    set GidPriv(PostAnimateDoing) Nothing

	    return
	}
	"Rewind" {
	    if { $GidPriv(PostAnimateDeform)} {
		set GidPriv(PostAnimateCurrentFrame) -1
	    } else {
		set GidPriv(PostAnimateCurrentFrame) 0
	    }
	    
	    set frame $GidPriv(PostAnimateCurrentFrame)
	    #WarnWin "Frame:Rewind: $GidPriv(PostAnimateCurrentFrame)"
	    
	    $GidPriv(PostAnimateEntry) conf -state normal
	    $GidPriv(PostAnimateEntry) del 0 end
	    if { $frame == -1} {
		$GidPriv(PostAnimateEntry) ins 0 "Orig"
	    } else {
		set all_step $GidPriv(PostAnimate_all_step) 
		set istep [ lindex $all_step $frame]
		$GidPriv(PostAnimateEntry) ins 0 $istep
	    }
	    $GidPriv(PostAnimateEntry) conf -state disabled
	    $GidPriv(PostAnimateSlide) set [ expr $frame+1]
	}
    }
	#actualizamos la slide
# 	set frame $GidPriv(PostAnimateCurrentFrame)
# 	$GidPriv(PostAnimateEntry) conf -state normal
# 	$GidPriv(PostAnimateEntry) del 0 end
# 	if { $frame == -1} {
# 	    $GidPriv(PostAnimateEntry) ins 0 "Orig"
# 	} else {
# 	    set all_step   $GidPriv(PostAnimate_all_step) 
# 	    set istep [ lindex $all_step $frame]
# 	    $GidPriv(PostAnimateEntry) ins 0 $istep
# 	}
# 	$GidPriv(PostAnimateEntry) conf -state disabled
# 	$GidPriv(PostAnimateSlide) set [ expr $frame+1]

    set cur_anal   $GidPriv(PostAnimate_cur_anal) 
    #set cur_step   $GidPriv(PostAnimate_cur_step) 
    set cur_d_anal   $GidPriv(PostAnimate_cur_d_anal) 
    #set cur_d_step   $GidPriv(PostAnimate_cur_d_step) 
    set all_step   $GidPriv(PostAnimate_all_step) 
    set cur_resv   $GidPriv(PostAnimate_cur_resv)  
    set cur_res    $GidPriv(PostAnimate_cur_res) 
    set cur_comp   $GidPriv(PostAnimate_cur_comp)
    set cur_defor  $GidPriv(PostAnimate_cur_d_defor)
    set cur_factor $GidPriv(PostAnimate_cur_d_factor)
    set cur_defor_type $GidPriv(PostAnimate_cur_defor_type)


    if { $GidPriv(PostAnimateSaveFrame)} {
	if { "$GidPriv(PostAnimateSaveFrameFormat)" == "TIFF"} {
	    set GidPriv(PostAnimateSaveFilename) [ format %s-%02d.tif \
		    $GidPriv(PostAnimateSavePrefix) [ expr $frame+1]]
	} elseif { "$GidPriv(PostAnimateSaveFrameFormat)" == "JPEG"} {
	    set GidPriv(PostAnimateSaveFilename) [ format %s-%02d.jpg \
		    $GidPriv(PostAnimateSavePrefix) [ expr $frame+1]]
	} else {
	    set GidPriv(PostAnimateSaveFilename) [ format %s-%02d.gif \
		    $GidPriv(PostAnimateSavePrefix) [ expr $frame+1]]
	}
    } else {
	set GidPriv(PostAnimateSaveFilename) ""
    }

    if { $GidPriv(PostAnimateDeform) && $frame == -1} {

	# deactivate redraw
	set GidPriv(PostAnimateOldAutoRedraw) [.central.s info variables AutomaticRedraw]
	.central.s process escape escape escape escape utilities variables \
		AutomaticRedraw -1 escape escape 

	# la original
	.central.s process escape escape escape results geometry Original
	.central.s process escape escape escape escape utilities variables \
		AutomaticRedraw $GidPriv(PostAnimateOldAutoRedraw) escape escape 
	.central.s render
	if { $GidPriv(PostAnimateSavingAnimation) } {
	    # for { set irepe 0} { $irepe < $GidPriv(PostAnimateSavingRepes)} { incr irepe} {
	    # 	  .central.s process escape escape escape escape utilities animationfile addframe
	    # }
	    .central.s process animationfile addstep
	}
	if { $GidPriv(PostAnimateSaveFrame)} {
	    #WarnWin "$GidPriv(PostAnimateSaveFilename)"
	    .central.s process escape escape escape escape utilities hardcopy \
		    $GidPriv(PostAnimateSaveFrameFormat) "\"$GidPriv(PostAnimateSaveFilename)\""
	}
	#update
	#update idletasks
	
	.central.s process escape escape escape escape utilities variables \
		AutomaticRedraw -1 escape escape 

	#actualizamos la slide
	$GidPriv(PostAnimateSlide) set [ expr $frame+1]
	$GidPriv(PostAnimateEntry) conf -state normal
	$GidPriv(PostAnimateEntry) del 0 end
	$GidPriv(PostAnimateEntry) ins 0 "Orig"
	$GidPriv(PostAnimateEntry) conf -state disabled

	if { $GidPriv(PostAnimateDoing) == "Rewind"} {
	    set GidPriv(PostAnimateDoing) Stop
	    PostAnimateFrame $frame
	    return
	}

	update idletasks
	if { $GidPriv(PostAnimateDelay) } {
	    #WarnWin "1 after $GidPriv(PostAnimateDelayTime) PostAnimateFrame 0 - $GidPriv(PostAnimateDoing)"
	    after $GidPriv(PostAnimateDelayTime) "PostAnimateFrame 0"
	} else {
	    #WarnWin "1b after $GidPriv(PostAnimateDefaultDelayTime) PostAnimateFrame 0 - $GidPriv(PostAnimateDoing)"
	    after $GidPriv(PostAnimateDefaultDelayTime) "PostAnimateFrame 0"
	}
	return
    }
    
    if { !$GidPriv(PostAnimateDeform) || !$AnimacionEstatica(hay)} {
	set istep [ lindex $all_step $frame]
    } else {
	set istep [ lindex $AnimacionEstatica(factores) $frame]
    }

    if { $istep == ""} {
	if { $GidPriv(PostAnimateDeform)} {
	    set frame -1
	} else {
	    set frame 0
	}
	if { $GidPriv(PostAnimateEndless)} {
	    #set istep [ lindex $all_step 0]
	    PostAnimateFrame $frame
	    return
	} else {
	    set GidPriv(PostAnimateDoing) Stop
	    PostAnimateFrame $frame
	    return
	}
    }

	    
    #actualizamos la slide
    $GidPriv(PostAnimateSlide) set [ expr $frame+1]
    $GidPriv(PostAnimateEntry) conf -state normal
    $GidPriv(PostAnimateEntry) del 0 end
    $GidPriv(PostAnimateEntry) ins 0 $istep
    $GidPriv(PostAnimateEntry) conf -state disabled

    #actualizamos la representacion del resultado
    .central.s process escape escape escape escape utilities variables \
	    AutomaticRedraw -1 escape escape 
    
    .central.s process escape escape escape escape results geometry noresults escape escape escape escape

    if { $GidPriv(PostAnimateDeform)} {
	# puede que cur_anal != cur_d_anal
	set postcmd "escape escape escape escape results analysissel $cur_d_anal $istep"
	.central.s process $postcmd
	#.central.s process escape escape escape escape utilities variables \
	#	AutomaticRedraw -1 escape escape 

	.central.s process escape escape escape escape \
		results options deformationtype $cur_defor_type
	if { $AnimacionEstatica(hay)} {
	    .central.s process escape escape escape results geometry Original \
		    geometry deformation $cur_defor $istep escape 
	} else {
	    .central.s process escape escape escape results geometry Original \
		    geometry deformation $cur_defor $cur_factor escape 
	}
	.central.s process escape escape escape escape \
		results options deformationtype relative
    }
    set postcmd "escape escape escape escape results analysissel $cur_anal $istep"
    .central.s process $postcmd
#escape escape escape escape escape results geometry Original geometry deformation Displacements 0.5 escape
	
    if { $GidPriv(PostAnimateResultViewCb) && $GidPriv(PostAnimateAnalysisLimitsCb)} {
	PostAnimatePushLimits
	PostAnimateSetAnalysisLimits
    }

    if { "$GidPriv(PostAnimateVariosResultados)" == "no"} {
	switch $GidPriv(PostAnimate_cur_resv) {
	    "ShMinMax" { 
		set postcmd "escape escape escape escape results $cur_resv $cur_res $cur_comp" 
	    }
	    "ContourFill" { 
		set postcmd "escape escape escape escape results $cur_resv $cur_res $cur_comp" 
	    }
	    "SmoothContourFill" { 
		set postcmd "escape escape escape escape results $cur_resv $cur_res $cur_comp" 
	    }
	    "ContourLines" { 
		set postcmd "escape escape escape escape results $cur_resv $cur_res $cur_comp" 
	    }
	    "IsoSurfaces" { 
		set postcmd "escape escape escape escape results $cur_resv Exact $cur_res $cur_comp" 
		set postcmd "$postcmd [ lindex $GidPriv(PostAnimateIsoSurfaces) 0] [ lindex $GidPriv(PostAnimateIsoSurfaces) 1]"
	    }
	    "DisplayVectors" {
		set postcmd "escape escape escape escape results $cur_resv $cur_res $cur_comp "
		set postcmd "$postcmd $GidPriv(PostAnimateDisplayVectors)"
	    }
	    "ContourRanges" { 
		set postcmd "escape escape escape escape results $cur_resv $cur_res $cur_comp" 
	    }
	    "ScalarLineDiagram" { 
		set postcmd "escape escape escape escape results LineDiagram ScalarDiagram $cur_res $cur_comp "
		set postcmd "$postcmd $GidPriv(PostAnimateScalarDiagram)"
	    }
	    "VectorLineDiagram" { 
		set postcmd "escape escape escape escape results LineDiagram VectorDiagram $cur_res "
		set postcmd "$postcmd $GidPriv(PostAnimateVectorDiagram)"
	    }
	    default {
		set postcmd ""
	    }
	}
	#	default { set GidPriv(PostAnimateResultView) ""}
	
	if { $GidPriv(PostAnimateResultViewCb) && $GidPriv(PostAnimateResultView) != ""} {
	    .central.s process $postcmd
	}
    } else {
	# varios resultados
	
	# .central.s process escape escape escape escape results geometry noresults escape escape escape escape
	foreach estado_res $GidPriv(PostAnimateListaResultados) {
	    set resv [ string tolower [ lindex $estado_res 1]]
	    set res_name [ lindex $estado_res 4]
	    set res_comp [ lindex $estado_res 5]
	    set res_factor [ lindex $estado_res 6]
	    regsub -all { } $resv {} resv
	    set postcmd ""  
	    if { "$resv" == "displayvectors"} {
		set postcmd "escape escape escape escape results $resv $res_name $res_comp "
		set postcmd "$postcmd $res_factor"
	    } elseif { "$resv" == "scalarlinediagram"} {
		set postcmd "escape escape escape escape results LineDiagram ScalarDiagram $res_name $res_comp "
		set postcmd "$postcmd $res_factor"
	    } elseif { "$resv" == "vectorlinediagram"} {
		set postcmd "escape escape escape escape results LineDiagram VectorDiagram $res_name "
		set postcmd "$postcmd $res_factor"
	    } elseif { "$resv" == "isosurfaces"} {
		set postcmd "escape escape escape escape results $resv $res_name $res_comp "
		set postcmd "escape escape escape escape results $resv Exact $res_name $res_comp" 
		set postcmd "$postcmd [ lindex $res_factor 0] [ lindex $res_factor 1]"
	    } else {
		set postcmd "escape escape escape escape results $resv $res_name $res_comp "
	    }
	    
	    if { $GidPriv(PostAnimateResultViewCb) && $GidPriv(PostAnimateResultView) != ""} {
		.central.s process $postcmd
	    }
	}

    }

    #WarnWin "istep = $istep - frame = $frame"
    
    #if { $GidPriv(PostAnimateDeform)} {
	.central.s process escape escape escape escape utilities variables \
		AutomaticRedraw $GidPriv(PostAnimateOldAutoRedraw) escape escape 
	.central.s render
    #}

    if { $GidPriv(PostAnimateSavingAnimation) } {
	# for { set irepe 0} { $irepe < $GidPriv(PostAnimateSavingRepes)} { incr irepe} {
	#     .central.s process escape escape escape escape utilities animationfile addframe
	# }
	.central.s process animationfile addstep
	#PostAnimateShowFileSize
    } else {
	PostAnimateShowTime
    }
    if { $GidPriv(PostAnimateSaveFrame)} {
	#WarnWin $GidPriv(PostAnimateSaveFilename)
	.central.s process escape escape escape utilities hardcopy \
		    $GidPriv(PostAnimateSaveFrameFormat) "\"$GidPriv(PostAnimateSaveFilename)\""
    }

    if { $GidPriv(PostAnimateResultViewCb) && $GidPriv(PostAnimateAnalysisLimitsCb)} {
	PostAnimatePopLimits
    }

    if { $GidPriv(PostAnimateDoing) == "Rewind"} {
	set GidPriv(PostAnimateDoing) Stop
	PostAnimateFrame $frame
	#WarnWin "holahola"
	return
    }

    update idletasks
    if { $GidPriv(PostAnimateDelay) } {
	#WarnWin "2 after $GidPriv(PostAnimateDelayTime) PostAnimateFrame [expr $frame + 1] - $GidPriv(PostAnimateDoing)"
	after $GidPriv(PostAnimateDelayTime) "PostAnimateFrame [expr $frame + 1]"
    } else {
	#WarnWin "2b after $GidPriv(PostAnimateDefaultDelayTime) PostAnimateFrame [expr $frame + 1] - $GidPriv(PostAnimateDoing)"
	after $GidPriv(PostAnimateDefaultDelayTime) "PostAnimateFrame [expr $frame + 1]"
    }
    return
}

proc PostAnimatePlay { w} {
    global GidPriv

    if { $GidPriv(PostAnimateDoing) != "Nothing"} { return}

    if { ( $GidPriv(PostAnimateResultView) == "" ) && !$GidPriv(PostAnimateDeform)} {
	WarnWin [_ "Please check ResultView or Deformation"] $GidPriv(PostAnimateWindow)
	return
    }

    if { ![ PostAnimateCheckWhichAnimation]} { return}

    if { $GidPriv(PostAnimateDelay)} {
	if { [ catch { set pp [ expr $GidPriv(PostAnimateDelayTime)]}] } {
	    WarnWin [_ "Delay '%s' not correct." $GidPriv(PostAnimateDelayTime)] $GidPriv(PostAnimateWindow)
	    return
	} 
	if { $GidPriv(PostAnimateDelayTime) < 0} {
	    WarnWin [_ "Delay '%s' not correct." $GidPriv(PostAnimateDelayTime)] $GidPriv(PostAnimateWindow)
	    return
	}
	if { $GidPriv(PostAnimateDelayTime) > 15000} {
	    set resp [ tk_messageBox -parent $GidPriv(PostAnimateWindow) -default no -title [_ "Confirm"] -type yesno \
		-message [_ "Are you sure you want to use %s ms as delay?" $GidPriv(PostAnimateDelayTime)]]
	    if { $resp == "no"} {
		return
	    }
	}
    }

    if { $GidPriv(PostAnimateEndless) && ( $GidPriv(PostAnimateSaveAnimation) || $GidPriv(PostAnimateSaveFrame))} {
	set what ""
	if { $GidPriv(PostAnimateSaveFrame)} {
	    set what "save $GidPriv(PostAnimateSaveFrameFormat)'s"
	}
	if { $GidPriv(PostAnimateSaveAnimation)} {
	    if { $what == ""} {
		set what "save the $GidPriv(PostAnimateSaveAnimationFormat)"
	    } else {
		set what "$what & save the $GidPriv(PostAnimateSaveAnimationFormat)"
	    }
	}
	set resp [ tk_dialog $GidPriv(PostAnimateWindow).___pa_ww2 [_ "Warning"] \
		       [_ "Are you sure to do an ENDLESS animation AND %s, so that the disk will be filled?" $what]\
		       error 1 [_ "Yes, I know"] [_ "No, I wouldn't"]]
	switch $resp {
	    0 {
		WarnWin [_ "Remember to push the STOP button to STOP the animation and so, not to fill the disk !!!"] $GidPriv(PostAnimateWindow)
	    }
	    1 {
		return
	    }
	}
    }

    if { $GidPriv(PostAnimateSaveAnimation) && !$GidPriv(PostAnimateDelay) } {
 	# set resp [ tk_messageBox -parent $GidPriv(PostAnimateWindow) -icon warning -type yesno \
	# 	  -default no -message \
	# 	  "Saving a MPEG animation file without delay between Steps can cause some strange efects in Microsoft Windows 95/98/NT.\n Are you sure you want continue?" ]
	# if { $resp == "no"} {
	#     return
	# }
	WarnWin [_ "There is no delay selected, using default of 500 ms. \n If you want no delay, please check the delay time entry."] $GidPriv(PostAnimateWindow)
    }
#     set cur_anal   $GidPriv(PostAnimate_cur_anal) 
#     set cur_step   $GidPriv(PostAnimate_cur_step) 
#     set all_step   $GidPriv(PostAnimate_all_step) 
#     set cur_resv   $GidPriv(PostAnimate_cur_resv)  
#     set cur_res    $GidPriv(PostAnimate_cur_res) 
#     set cur_comp   $GidPriv(PostAnimate_cur_comp)
#     set cur_defor  $GidPriv(PostAnimate_cur_defor)
#     set cur_factor $GidPriv(PostAnimate_cur_factor)
    
#     if { $GidPriv(PostAnimateCurrentFrame) == ""} {
# 	if { $GidPriv(PostAnimateDeform)} {
# 	    set GidPriv(PostAnimateCurrentFrame) -1
# 	} else {
# 	    set GidPriv(PostAnimateCurrentFrame) 0
# 	}
#     }

    # configuramos la slide
#     if { $GidPriv(PostAnimateDeform)} {
# 	$GidPriv(PostAnimateSlide) conf -from 0 -to [ expr [ llength $all_step]] -resolution 1
#     } else {
# 	$GidPriv(PostAnimateSlide) conf -from 1 -to [ expr [ llength $all_step]] -resolution 1
#     }
#WarnWin $GidPriv(PostAnimateCurrentFrame)

    if { $GidPriv(PostAnimateSaveAnimation) } {
	# para que no nos actualize el estado de resultados:
	#puede que estemos haciendo una animacion de deformada y estemos en el estado original
	set GidPriv(PostAnimateInitializing) 1
	.central.s process animationfile format \
		$GidPriv(PostAnimateSaveAnimationFormat)
	set GidPriv(PostAnimateInitializing) 0

	if { ( "$GidPriv(PostAnimateSaveAnimationFormat)" == "AVIMJPG") || \
		( "$GidPriv(PostAnimateSaveAnimationFormat)" == "AVI") || \
		( "$GidPriv(PostAnimateSaveAnimationFormat)" == "AVI15")} {
	    set info2 [.central.s configure]
	    set height_list [ lindex $info2 0]
	    set width_list [ lindex $info2 1]
	    set width [ lindex $width_list 4]
	    set height [ lindex $height_list 4]

	    set avisize [ expr $width * $height * ( [ llength $GidPriv(PostAnimate_all_step)] + $GidPriv(PostAnimateDeform))]
	    if { "$GidPriv(PostAnimateSaveAnimationFormat)" == "AVIMJPG" } {
		# estimacion aproximada
		set avisize [ expr $avisize * 3 * 0.1]
	    } elseif { "$GidPriv(PostAnimateSaveAnimationFormat)" == "AVI" } {
		set avisize [ expr $avisize * 3]
	    } else {
		set avisize [ expr $avisize * 2]
	    }
	    set avisize [ expr ( $avisize / 1024.0) / 1024.0]

	    if { $avisize > 95.00 } {
		set resp [ tk_messageBox -parent $GidPriv(PostAnimateWindow) -icon warning -type yesno \
			-default no -message \
			"Warning: the AVI file will be [ format %.3g $avisize] MB big !!!\n Are you sure you want continue?" ]
		if { $resp == "no"} {
		    return
		}
	    }
	    #WarnWin "The AVI file will be [ format %.3g $avisize] MB big !!!"
	}

	# Frame rate = 25 FPS == 40 ms.
	set repe 1
	if { $GidPriv(PostAnimateDelay) } {
	    if { ( $GidPriv(PostAnimateDelayTime) == 0) && \
		    ( "$GidPriv(PostAnimateSaveAnimationFormat)" == "MPEG") } {
		set resp [ tk_messageBox -parent $GidPriv(PostAnimateWindow) -icon warning -type yesno \
			-default no -message \
			"Saving a MPEG animation file without delay between Steps can cause some strange efects in Microsoft Windows 95/98/NT.\n Are you sure you want continue?" ]
		if { $resp == "no"} {
		    return
		}
	    }
#	    set repe [ expr int(0.5 + $GidPriv(PostAnimateDefaultDelayTime)/40.0)]
	    set repe [ expr int(0.5 + $GidPriv(PostAnimateDelayTime)/40.0)]
	    if { $repe == 0} { set repe 1}
	} else {
	    # por defecto medio segundo
	    set repe [ expr int(0.5 + 500.0/40.0)]
	    if { $repe == 0} { set repe 1}
	}

	set GidPriv(PostAnimateSavingRepes) $repe
	.central.s process animationfile framesperstep \
		$GidPriv(PostAnimateSavingRepes) escape escape escape escape
	.central.s process animationfile start \
		\"$GidPriv(PostAnimateSaveAnimationFile)\" yes escape escape escape escape

	set GidPriv(PostAnimateSavingAnimation) 1

	update
    }

    # para mostrar al usuario el tamanyo del archivo
    set GidPriv(PostAnimateTime) 0

    set GidPriv(PostAnimateDoing) Animate
    PostAnimateDisableGUIUpdates

    if { $w != ""} {
	$w conf -relief sunken
    }
    set GidPriv(PostAnimateCurrentButton) $w

    #WarnWin "5 $GidPriv(PostAnimateCurrentFrame)"
    PostAnimateFrame $GidPriv(PostAnimateCurrentFrame)
}

proc PostAnimateStop { w} {
    global GidPriv

    if { $GidPriv(PostAnimateDoing) == "Nothing"} { return}
    if { $GidPriv(PostAnimateCurrentButton) != ""} {
	$GidPriv(PostAnimateCurrentButton) conf -relief raise
    }
    set GidPriv(PostAnimateDoing) Stop
    if { $w != ""} {
	$w conf -relief sunken
    }
    set GidPriv(PostAnimateCurrentButton) $w
}

proc PostAnimateRewind { w} {
    global GidPriv

    if { $GidPriv(PostAnimateCurrentButton) != ""} {
	$GidPriv(PostAnimateCurrentButton) conf -relief raise
    }
    if { $w != ""} {
	$w conf -relief sunken
    }
    set GidPriv(PostAnimateCurrentButton) $w
    #WarnWin "Rewind: $GidPriv(PostAnimateDoing)"
    if { $GidPriv(PostAnimateDoing) != "Animate"} {
	set GidPriv(PostAnimateDoing) Rewind
	set oldsave $GidPriv(PostAnimateSaveFrame)
	set oldsaveanim $GidPriv(PostAnimateSaveAnimation)
	set GidPriv(PostAnimateSaveFrame) 0
	set GidPriv(PostAnimateSaveAnimation) 0
	PostAnimateFrame $GidPriv(PostAnimateCurrentFrame)
	set GidPriv(PostAnimateSaveFrame) $oldsave
	set GidPriv(PostAnimateSaveAnimation) $oldsaveanim
    } else {
	set GidPriv(PostAnimateDoing) Rewind
    }	
}

proc PostAnimateStep { w} {
    global GidPriv

    set old $GidPriv(PostAnimateDefaultDelayTime)
    set oldsave $GidPriv(PostAnimateSaveFrame)
    set oldsaveanim $GidPriv(PostAnimateSaveAnimation)
    set GidPriv(PostAnimateDefaultDelayTime) 0
    set GidPriv(PostAnimateSaveFrame) 0
    set GidPriv(PostAnimateSaveAnimation) 0
    PostAnimatePlay $w
    PostAnimateStop $w
    set GidPriv(PostAnimateSaveAnimation) $oldsaveanim
    set GidPriv(PostAnimateSaveFrame) $oldsave
    set GidPriv(PostAnimateDefaultDelayTime) $old
}

proc PostAnimateMPEGLeds { estado} {
    global GidPriv
    
    set w $GidPriv(PostAnimateWindow)
    set led_libre $GidPriv(PostAnimateMPEG_led_libre)
    set led_ocupado $GidPriv(PostAnimateMPEG_led_ocupado)

    switch $estado {
	DISABLED {
	    $w.f_anim.f.cv itemconfigure $led_libre -fill grey60
	    $w.f_anim.f.cv itemconfigure $led_ocupado -fill grey60
	}
	FREE {
	    $w.f_anim.f.cv itemconfigure $led_libre -fill green
	    $w.f_anim.f.cv itemconfigure $led_ocupado -fill grey60
	}
	BUSY {
	    $w.f_anim.f.cv itemconfigure $led_libre -fill grey60
	    $w.f_anim.f.cv itemconfigure $led_ocupado -fill red
	}
	default {
	    WarnWin [_ "Unknown led state: %s" $estado] $GidPriv(PostAnimateWindow)
	    $w.f_anim.f.cv itemconfigure $led_libre -fill grey60
	    $w.f_anim.f.cv itemconfigure $led_ocupado -fill grey60
	}
    }
    
}

proc PostAnimateTogleDelayEntry { name1 name2 op} {
    global GidPriv
    
    set w $GidPriv(PostAnimateWindow)
    if { $GidPriv(PostAnimateDelay) } {
	$w.f_opt.f_del.e conf -state normal -foreground black
	focus $w.f_opt.f_del.e
    } else {
	$w.f_opt.f_del.e conf -state disabled -foreground grey60
    }
}

proc PostAnimateTogleSaveEntry { name1 name2 op} {
    global GidPriv
    
    set w $GidPriv(PostAnimateWindow)
    if { $GidPriv(PostAnimateSaveFrame) } {
	$w.f_save.f.f.cb conf -foreground black
	$w.f_save.f.f.mb conf -state normal
	$w.f_save.f.f.l conf -foreground black
	$w.f_save.f.b conf -state normal
	$w.f_save.e conf -state normal -foreground black
	focus $w.f_save.e
    } else {
	$w.f_save.f.f.cb conf -foreground grey60
	$w.f_save.f.f.mb conf -state disabled
	$w.f_save.f.f.l conf -foreground grey60
	$w.f_save.f.b conf -state disabled
	$w.f_save.e conf -state disabled -foreground grey60
    }
}

proc PostAnimateTogleMPEGLeds { name1 name2 op} {
    global GidPriv

    if { $GidPriv(PostAnimateSavingAnimation) == 0} {
	PostAnimateMPEGLeds FREE
    }

    if { $GidPriv(PostAnimateSavingAnimation) == 1} {
	PostAnimateMPEGLeds BUSY
    }
}

proc PostAnimateChangeExtension { new_format} {
    global GidPriv

    if { "$GidPriv(PostAnimateSaveAnimationFile)" == "" } { return}
    set w $GidPriv(PostAnimateWindow)
    
    set raiz [ file root "$GidPriv(PostAnimateSaveAnimationFile)"]
    set ext [ string tolower [ file extension "$GidPriv(PostAnimateSaveAnimationFile)"]]
    switch "$new_format" {
	"MPEG" {# $w.f_anim.e 
	    if { ( "$ext" != ".mpeg") && ( "$ext" != ".mpg") } {
		if { ( "$ext" == ".avi") || ( "$ext" == ".gif") || ( "$ext" == "")} {
		    set GidPriv(PostAnimateSaveAnimationFile) ${raiz}.mpg
		}
	    }
	}
	"AVIMJPG" {
	    if { "$ext" != ".avi"} {
		if { ( "$ext" == ".mpeg") || ( "$ext" == ".mpg") || ( "$ext" == ".gif") || ( "$ext" == "")} {
		    set GidPriv(PostAnimateSaveAnimationFile) ${raiz}.avi
		}
	    }
	}
	"AVI" {
	    if { "$ext" != ".avi"} {
		if { ( "$ext" == ".mpeg") || ( "$ext" == ".mpg") || ( "$ext" == ".gif") || ( "$ext" == "")} {
		    set GidPriv(PostAnimateSaveAnimationFile) ${raiz}.avi
		}
	    }
	}
	"AVI15" {
	    if { "$ext" != ".avi"} {
		if { ( "$ext" == ".mpeg") || ( "$ext" == ".mpg") || ( "$ext" == ".gif") || ( "$ext" == "")} {
		    set GidPriv(PostAnimateSaveAnimationFile) ${raiz}.avi
		}
	    }
	}
	"GIF" {
	    if { "$ext" != ".gif"} {
		if { ( "$ext" == ".mpeg") || ( "$ext" == ".mpg") || ( "$ext" == ".avi") || ( "$ext" == "")} {
		    set GidPriv(PostAnimateSaveAnimationFile) ${raiz}.gif
		}
	    }
	}
    }
}

proc PostAnimateTogleAnimEntry { name1 name2 op} {
    global GidPriv
    
    set w $GidPriv(PostAnimateWindow)
    if { $GidPriv(PostAnimateSaveAnimation) } {
	if {  [ info exist GidPriv(PostAnimateControlsSavingAnimation) ] && \
		$GidPriv(PostAnimateControlsSavingAnimation) } {
	    WarnWin "Sorry, but couldn't save the animation while another one is active (Animation Controls Window)"
	    set GidPriv(PostAnimateSaveAnimation) 0
	    return
	}
	$w.f_anim.f.f.cb conf -foreground black
	$w.f_anim.f.f.mb conf -state normal
	$w.f_anim.f.f.l conf -foreground black
	$w.f_anim.f.b conf -state normal
	$w.f_anim.e conf -state normal -foreground black
	focus $w.f_anim.e
	PostAnimateMPEGLeds FREE
	trace variable GidPriv(PostAnimateSavingAnimation) w PostAnimateTogleMPEGLeds
    } else {
	$w.f_anim.f.f.cb conf -foreground grey60
	$w.f_anim.f.f.mb conf -state disabled
	$w.f_anim.f.f.l conf -foreground grey60
	$w.f_anim.f.b conf -state disabled
	$w.f_anim.e conf -state disabled -foreground grey60
	PostAnimateMPEGLeds DISABLED
	trace vdelete GidPriv(PostAnimateSavingAnimation) w PostAnimateTogleMPEGLeds
    }
}

proc PostAnimateCheckDelayTime { name1 name2 op} {
    global GidPriv
    
    set w $GidPriv(PostAnimateWindow)
    set len [string length $GidPriv(PostAnimateDelayTime)]
    set cur_digit [ string index $GidPriv(PostAnimateDelayTime) [ expr $len - 1]]
    if { ( $cur_digit >= 0) && ( $cur_digit <= 9)} { return}
    if { ( $cur_digit == "e") || ( $cur_digit == "E") || 
    ( $cur_digit == "+") || ( $cur_digit == "-") || ( $cur_digit == ".")} {
	return
    }
    set GidPriv(PostAnimateDelayTime) [ string range $GidPriv(PostAnimateDelayTime) 0 [ expr $len-2]]
}

proc PostAnimateFin { w} {
    global GidPriv

    set GidPriv(PostAnimateDoing) Stop
    AnimacionEstatica::Cerrar
    destroy $w
        
    catch {
	trace vdelete GidPriv(PostAnimateDelay) w PostAnimateTogleDelayEntry
	trace vdelete GidPriv(PostAnimateDelayTime) w PostAnimateCheckDelayTime
	trace vdelete GidPriv(PostAnimateSaveFrame) w PostAnimateTogleSaveEntry
	trace vdelete GidPriv(PostAnimateSaveAnimation) w PostAnimateTogleAnimEntry
	trace vdelete GidPriv(PostAnimateAnalysisLimitsCb) w PostAnimateGetAnalysisLimits
	trace vdelete GidPriv(PostAnimateSavingAnimation) w PostAnimateTogleMPEGLeds
	trace vdelete GidPriv(PostAnimateDeform) w CambioPostAnimateDeform
    }
}

proc PostAnimateDoingSlide { } {
    global GidPriv

    if { $GidPriv(PostAnimateSlideDelay)} {
	set GidPriv(PostAnimateSlideDelay) [ expr $GidPriv(PostAnimateSlideDelay)-1]
	after 100 PostAnimateDoingSlide
    } else {
	set GidPriv(PostAnimateSlideDelay) 10
	if { $GidPriv(PostAnimateDoing) == "Nothing"} {
	    set old $GidPriv(PostAnimateDefaultDelayTime)
	    set oldsave $GidPriv(PostAnimateSaveFrame)
	    set oldsaveanim $GidPriv(PostAnimateSaveAnimation)
	    set GidPriv(PostAnimateDefaultDelayTime) 0
	    set GidPriv(PostAnimateSaveFrame) 0
	    set GidPriv(PostAnimateSaveAnimation) 0
	    PostAnimatePlay ""
	    PostAnimateStop ""
	    set GidPriv(PostAnimateSaveAnimation) $oldsaveanim
	    set GidPriv(PostAnimateSaveFrame) $oldsave
	    set GidPriv(PostAnimateDefaultDelayTime) $old
	}
	set GidPriv(PostAnimateSliding) 0
    }
}

proc PostAnimateChangeScale { frame} {
    global GidPriv

    if { $GidPriv(PostAnimateInitializing)} { return}
    if { $GidPriv(PostAnimateDoing) == "Nothing"} {
	set GidPriv(PostAnimateCurrentFrame) [ expr $frame-1]
	set GidPriv(PostAnimateSlideDelay) 10
	if { !$GidPriv(PostAnimateSliding) } {
	    after 100 PostAnimateDoingSlide
	    set GidPriv(PostAnimateSliding) 1
	}
    }
}

proc PostAnimateCheckedDeform {} {
    global GidPriv

    if { $GidPriv(PostAnimateDeform) } {
	set mainst [.central.s info post get main_geom_state]
	if { $mainst != "Deformed" } {
	    #WarnWin "Animation currently not supported for Main Geometry state $mainst"
	    WarnWin [_ "Please choose a Main Deformation Visualization first."] $GidPriv(PostAnimateWindow)
	    set GidPriv(PostAnimateDeform) 0
	    return
	}
    }
    
    PostAnimateConfigureSlide
}


proc PostAnimateCheckedContour {} {
    global GidPriv
    
    regsub -all {_} $GidPriv(PostAnimate_cur_resv) {} pepe
    set GidPriv(PostAnimate_cur_resv) $pepe
    if { $GidPriv(PostAnimateResultView) == "" } {
	#WarnWin "Animation currently not suported for Results View $cur_resv"
	WarnWin [_ "Please choose a Results Visualization first."] $GidPriv(PostAnimateWindow)	
	set GidPriv(PostAnimateResultViewCb) 0
	return
    }

    if { $GidPriv(PostAnimateResultViewCb) } {
	#$GidPriv(PostAnimateResButtons).l conf -foreground black
	$GidPriv(PostAnimateResButtons).b1 conf -state normal
	#$GidPriv(PostAnimateResButtons).b2 conf -state normal
    } else {
	#$GidPriv(PostAnimateResButtons).l conf -foreground grey60
	$GidPriv(PostAnimateResButtons).b1 conf -state disabled
	#$GidPriv(PostAnimateResButtons).b2 conf -state disabled
    }
    #set GidPriv(PostAnimateAnalysisLimitsCb) 1

    PostAnimateConfigureSlide
}

proc PostAnimateCheckWhichAnimation {} {   
    global GidPriv

    regsub -all {_} $GidPriv(PostAnimate_cur_resv) {} pepe
    set GidPriv(PostAnimate_cur_resv) $pepe
    if { $GidPriv(PostAnimateResultViewCb) && ( $GidPriv(PostAnimateResultView) == "") } {
	#WarnWin "Animation currently not suported for Results View $cur_resv"
	WarnWin [_ "Please choose a Results Visualization first. Or check 'Results' out."] $GidPriv(PostAnimateWindow)
	return 0
    }

    if { $GidPriv(PostAnimateDeform)  && ( $GidPriv(PostAnimate_cur_d_defor) == "")} {
	#set mainst [.central.s info post get main_geom_state]
	#if { $mainst != "Deformed" } {
	    #WarnWin "Animation currently not supported for Main Geometry state $mainst"
	WarnWin [_ "Please choose a Main Deformation Visualization first. Or check 'Deformation' out."] $GidPriv(PostAnimateWindow)
	    set GidPriv(PostAnimateDeform) 0
	    return 0
	#}
    }
    return 1
}

proc PostAnimateChooseSavePrefix {} {
    global GidPriv

    set GidPriv(PostAnimateSaveFrame) 1
    if { $GidPriv(PostAnimateSaveFrame) } {
	set w $GidPriv(PostAnimateWindow)
	if { "$GidPriv(PostAnimateSaveFrameFormat)" == "TIFF"} {
	    set GidPriv(PostAnimateSavePrefix) [Browser-ramR file write $w [_ "Prefix for '*.tif' files"]...]
	    if { [ regexp -nocase {(.*).tif$} $GidPriv(PostAnimateSavePrefix) dum prefix]} {
		set GidPriv(PostAnimateSavePrefix) $prefix
	    }
	    if { [ regexp -nocase {(.*).tiff$} $GidPriv(PostAnimateSavePrefix) dum prefix]} {
		set GidPriv(PostAnimateSavePrefix) $prefix
	    }
	} elseif { "$GidPriv(PostAnimateSaveFrameFormat)" == "JPEG"} {
	    set GidPriv(PostAnimateSavePrefix) [Browser-ramR file write $w [_ "Prefix for '*.jpg' files"]...]
	    if { [ regexp -nocase {(.*).jpg$} $GidPriv(PostAnimateSavePrefix) dum prefix]} {
		set GidPriv(PostAnimateSavePrefix) $prefix
	    }
	    if { [ regexp -nocase {(.*).jpeg$} $GidPriv(PostAnimateSavePrefix) dum prefix]} {
		set GidPriv(PostAnimateSavePrefix) $prefix
	    }
	} else {
	    set GidPriv(PostAnimateSavePrefix) [Browser-ramR file write $w [_ "Prefix for '*.gif' files"]...]
	    if { [ regexp -nocase {(.*).gif$} $GidPriv(PostAnimateSavePrefix) dum prefix]} {
		set GidPriv(PostAnimateSavePrefix) $prefix
	    }
	}
	#$w.f_save.e del 0 end
	#$w.f_save.e ins 0 $GidPriv(PostAnimateSavePrefix)
    }
}

proc PostAnimateChooseAnimationFile {} {
    global GidPriv

    set GidPriv(PostAnimateSaveAnimation) 1
    if { $GidPriv(PostAnimateSaveAnimation) } {
	set w $GidPriv(PostAnimateWindow)
	switch "$GidPriv(PostAnimateSaveAnimationFormat)" {
	    "MPEG" {
		set GidPriv(PostAnimateSaveAnimationFile) [Browser-ramR file write $w [_ "Save MPEG on"]... \
                {} {{{Mpeg animation} {.mpg .mpeg}} {{All files} {.*}}} ".mpg" ]
	    }
	    "AVIMJPG" {
		set GidPriv(PostAnimateSaveAnimationFile) [Browser-ramR file write $w [_ "Save AVI on"]... \
                {} {{{AVI animation} {.avi}} {{All files} {.*}}} ".avi" ]
	    }
	    "AVI" {
		set GidPriv(PostAnimateSaveAnimationFile) [Browser-ramR file write $w [_ "Save AVI on"]... \
                {} {{{AVI animation} {.avi}} {{All files} {.*}}} ".avi" ]
	    }
	    "AVI15" {
		set GidPriv(PostAnimateSaveAnimationFile) [Browser-ramR file write $w [_ "Save AVI on"]... \
                {} {{{AVI animation} {.avi}} {{All files} {.*}}} ".avi" ]
	    }
	    "GIF" {
		set GidPriv(PostAnimateSaveAnimationFile) [Browser-ramR file write $w [_ "Save GIF on"]... \
                {} {{{GIF animation} {.gif}} {{All files} {.*}}} ".gif" ]
	    }
	}
	#$w.f_anim.e del 0 end
	#$w.f_anim.e ins 0 $GidPriv(PostAnimateSaveAnimationFile)
    }
}

proc PostAnimatePushLimits {} {
    global GidPriv
    set GidPriv(PostAnimateSavedLimits) [ lindex [ .central.s info post get contour_limits] 0]
}

proc PostAnimatePopLimits {} {
    global GidPriv

    if { [ lindex $GidPriv(PostAnimateSavedLimits) 0] == "STD"} {
	.central.s process escape escape escape escape Results ContOptions \
		SetMinOptions ResetValue
    } else {
	.central.s process escape escape escape escape Results ContOptions \
		SetMinOptions SetValue [ lindex $GidPriv(PostAnimateSavedLimits) 1]
    }

    if { [ lindex $GidPriv(PostAnimateSavedLimits) 2] == "STD"} {
	.central.s process escape escape escape escape Results ContOptions \
		SetMaxOptions ResetValue
    } else {
	.central.s process escape escape escape escape Results ContOptions \
		SetMaxOptions SetValue [ lindex $GidPriv(PostAnimateSavedLimits) 3]
    }

}

proc PostAnimateGetAnalysisLimits { name1 name2 op} {
    global GidPriv
    
    if { $GidPriv(PostAnimateInitializing)} { return}
    if { $GidPriv(PostAnimateResultViewCb) && $GidPriv(PostAnimateAnalysisLimitsCb) } {
	PostAnimatePushLimits 
	set GidPriv(PostAnimateInitializing) 1
#WarnWinText "hola($GidPriv(PostAnimateAnalysisLimitsCb)) -> $name1 $name2"
	# si hay varios resultados, buscamos los limites del c.fill/lines/rango
	if { $GidPriv(PostAnimateVariosResultados)} {
	    set GidPriv(PostAnimateOldAutoRedraw) [.central.s info variables AutomaticRedraw]
#WarnWinText "old = $GidPriv(PostAnimateOldAutoRedraw)"
	    .central.s process escape escape escape escape utilities variables \
		    AutomaticRedraw -1 escape escape 
    
	    .central.s process escape escape escape escape results geometry noresults escape escape escape escape
	    # pintamos solo el c.fill para conseguir los limites
	    foreach estado_res $GidPriv(PostAnimateListaResultados) {
		set resv [ string tolower [ lindex $estado_res 1]]
		set res_name [ lindex $estado_res 4]
		set res_comp [ lindex $estado_res 5]
		set res_factor [ lindex $estado_res 6]
		regsub -all { } $resv {} resv
		set postcmd ""  
		if { ( "$resv" == "contourfill") || ( "$resv" == "smoothcontourfill") || \
			( "$resv" == "contourlines") || ( "$resv" == "contourranges")} {
		    set postcmd "escape escape escape escape results $resv $res_name $res_comp "
		}
		.central.s process $postcmd
	    }
	}
	.central.s process escape escape escape escape Results ContOptions FixAnalysisLim
	set GidPriv(PostAnimateAnalysisLimits) [ lindex [ .central.s info post get contour_limits] 0]
#WarnWinText "analysis limits = $GidPriv(PostAnimateAnalysisLimits)"

	#devolvemos lo que estaba
	if { $GidPriv(PostAnimateVariosResultados)} {
	    .central.s process escape escape escape escape results geometry noresults escape escape escape escape
	    foreach estado_res $GidPriv(PostAnimateListaResultados) {
		set resv [ string tolower [ lindex $estado_res 1]]
		set res_name [ lindex $estado_res 4]
		set res_comp [ lindex $estado_res 5]
		set res_factor [ lindex $estado_res 6]
		regsub -all { } $resv {} resv
		set postcmd ""  
		if { "$resv" == "displayvectors"} {
		    set postcmd "escape escape escape escape results $resv $res_name $res_comp "
		    set postcmd "$postcmd $res_factor"
		} elseif { "$resv" == "scalarlinediagram"} {
		    set postcmd "escape escape escape escape results LineDiagram ScalarDiagram $res_name $res_comp "
		    set postcmd "$postcmd $res_factor"
		} elseif { "$resv" == "vectorlinediagram"} {
		    set postcmd "escape escape escape escape results LineDiagram VectorDiagram $res_name "
		    set postcmd "$postcmd $res_factor"
		} else {
		    set postcmd "escape escape escape escape results $resv $res_name $res_comp "
		}
		
		if { $GidPriv(PostAnimateResultViewCb) && $GidPriv(PostAnimateResultView) != ""} {
		    .central.s process $postcmd
		}
	    }
	    .central.s process escape escape escape escape utilities variables \
		    AutomaticRedraw $GidPriv(PostAnimateOldAutoRedraw) escape escape 
#WarnWinText "dejando como antes =  $GidPriv(PostAnimateOldAutoRedraw)"
	}
	PostAnimatePopLimits
	set GidPriv(PostAnimateInitializing) 0
    }
}

proc PostAnimateSetAnalysisLimits {} {
    global GidPriv

    .central.s process escape escape escape escape Results ContOptions \
	    SetMinOptions SetValue [ lindex $GidPriv(PostAnimateAnalysisLimits) 1]

    .central.s process escape escape escape escape Results ContOptions \
	    SetMaxOptions SetValue [ lindex $GidPriv(PostAnimateAnalysisLimits) 3]
}

# this func is necessary to aviod the warning when going from pre to post
proc PostAnimateM { { w .wPostAnimate } } {

    set mm [ .central.s info post get all_volumes]
    set ss [ .central.s info post get all_surfaces]
    if { ( $mm == "") && ( $ss == "") } { 
	set w .gid
	if { [ info exist GidPriv(PostAnimateWindow)] && [ winfo exist $GidPriv(PostAnimateWindow)]} {
	    set w $GidPriv(PostAnimateWindow)
	}
	WarnWin [_ "Please load a model first."] $w
	return
    }
    PostAnimate $w
}

proc PostAnimateResize { } {
    global GidPriv

    set info [ wm geometry .gid]
    set info2 [.central.s configure]
    set height_list [ lindex $info2 0]
    set width_list [ lindex $info2 1]
    if { ![ regexp {([0-9]*)x([0-9]*)} $info trozo top_width top_height] } { return }
    set width_offset [ expr $top_width - [ lindex $width_list 4]]
    set height_offset [ expr $top_height - [ lindex $height_list 4]]

    if { "$GidPriv(PostAnimateResize)" == "Default"} {
	set GidPriv(PostAnimateResize) $GidPriv(PostAnimateResizeDefault)
    } 
    if { ![ regexp {([0-9]*)x([0-9]*)} $GidPriv(PostAnimateResize) trozo new_width new_height] } { return }
    
    #WarnWinText ".gid = $info = $top_width x $top_height"
    #WarnWinText "togl = [ lindex $width_list 4]x[ lindex $height_list 4]"
    #WarnWinText "offset = $width_offset x $height_offset"
    ## 768x576 640x480 512x384 320x240
    wm geometry .gid [ expr $width_offset + $new_width]x[ expr $height_offset + $new_height]
}

proc PostAnimateCrearAnimacion { w} {
    global GidPriv AnimacionEstatica
    set win [ AnimacionEstatica::Crear $w]
    tkwait window $win
    
    if { $GidPriv(PostAnimateDeform)} {
	AnimacionEstaticaCreaFactores $GidPriv(PostAnimate_cur_d_factor)
	#WarnWin $AnimacionEstatica(factores)
	PostAnimateConfigureSlide
    }
    #WarnWin "Animacion $AnimacionEstatica(tipo) con $AnimacionEstatica(pasos) pasos"
    
}

proc PostAnimate { { w .wPostAnimate } } {
    global GidPriv GIDDEFAULT AnimacionEstatica

    set mm [ .central.s info post get all_volumes]
    set ss [ .central.s info post get all_surfaces]
    if { ( $mm == "") && ( $ss == "") } { 
	return
    }
    
    catch {
	trace vdelete GidPriv(PostAnimateDelay) w PostAnimateTogleDelayEntry
	trace vdelete GidPriv(PostAnimateDelayTime) w PostAnimateCheckDelayTime
	trace vdelete GidPriv(PostAnimateSaveFrame) w PostAnimateTogleSaveEntry
	trace vdelete GidPriv(PostAnimateSaveAnimation) w PostAnimateTogleAnimEntry
	trace vdelete GidPriv(PostAnimateAnalysisLimitsCb) w PostAnimateGetAnalysisLimits
	trace vdelete GidPriv(PostAnimateSavingAnimation) w PostAnimateTogleMPEGLeds
	trace vdelete GidPriv(PostAnimateDeform) w CambioPostAnimateDeform
    }

    set GidPriv(PostAnimateInitializing) 1
    PostAnimateInitValues

    InitWindow $w [_ "Animate"] PostAnimateWindowGeom
        
    # Las opciones
    frame $w.f_opt -relief ridge -bd 2
    
    #label $w.f_opt.l -text [_ "Check:"]
    frame $w.f_opt.res -bd 0
    checkbutton $w.f_opt.res.cb1 -text [_ "Results View"] -variable GidPriv(PostAnimateResultViewCb) \
	    -command PostAnimateCheckedContour
    frame $w.f_opt.res.opt -bd 0
    checkbutton $w.f_opt.res.opt.b1 -text [_ "Automatic Limits"] \
	    -variable GidPriv(PostAnimateAnalysisLimitsCb)
    grid $w.f_opt.res.opt.b1 -padx 22 -sticky we

    GiDPopUpHelp $w.f_opt.res.cb1 "The result view evolution is shown. \n"\
	    "NOTE: the results view should be selected previously."
    GiDPopUpHelp $w.f_opt.res.opt.b1 "The limits of the results view will be the same for the whole animation."

    set GidPriv(PostAnimateResButtons) $w.f_opt.res.opt
    #$GidPriv(PostAnimateResButtons).l conf -foreground grey60
    $GidPriv(PostAnimateResButtons).b1 conf -state disabled
    #$GidPriv(PostAnimateResButtons).b2 conf -state disabled

    grid $w.f_opt.res.cb1 -sticky w
    grid $w.f_opt.res.opt -sticky we
    grid rowconf $w.f_opt.res 1 -weight 1
    grid columnconf $w.f_opt.res 0 -weight 1
    
    checkbutton $w.f_opt.cb2 -text [_ "Deformation"] -variable GidPriv(PostAnimateDeform) \
	    -command PostAnimateCheckedDeform
    checkbutton $w.f_opt.cb3 -text [_ "Endless"] -variable GidPriv(PostAnimateEndless)

    GiDPopUpHelp $w.f_opt.cb2 "The evolution of the deformation is shown. \n"\
	    "NOTE: to use this option, the model should be deformed previously."
    GiDPopUpHelp $w.f_opt.cb3 "After pressing te 'Play' button, the "\
	    "animation wil not stop. \nNOTE: if the animation is saved, the entire disk may be filled."

    frame $w.f_opt.f_del
    checkbutton $w.f_opt.f_del.cb -text [_ "Delay:"] -variable GidPriv(PostAnimateDelay)
    entry $w.f_opt.f_del.e -relief sunken -width 5 -textvariable GidPriv(PostAnimateDelayTime)
    $w.f_opt.f_del.e conf -state disabled -foreground grey60
    label $w.f_opt.f_del.l -text [_ "ms."]
    #grid $w.f_opt.f_del.cb -sticky w
    #grid $w.f_opt.f_del.e -row 0 -column 1 -sticky w
    #grid $w.f_opt.f_del.l -row 0 -column 2 -sticky w
    grid $w.f_opt.f_del.cb $w.f_opt.f_del.e $w.f_opt.f_del.l -sticky w
    #grid rowconf $w.f_opt.f_del 0 -weight 1 
    #grid columnconf $w.f_opt.f_del 1 -weight 1 
    
    GiDPopUpHelp $w.f_opt.f_del "With this option a DelayTime of the entered milliseconds "\
	    "will be used between frames."

    #button $w.f_opt.static -text "Animation\nof static\nanalysis" -bd 1
    button $w.f_opt.static -text [_ "Static\nanalysis\nanimation\nprofile"] -bd 1 -padx 4 \
	    -command "PostAnimateCrearAnimacion $w"
    GiDPopUpHelp $w.f_opt.static "Configures the behaviour of the pseudo-animation\n"\
	    "of the deformation for analysis with only one step."
    set AnimacionEstatica(boton) $w.f_opt.static

    #grid $w.f_opt.l 
    grid $w.f_opt.res -sticky we
    grid $w.f_opt.cb2 -sticky w
    grid $w.f_opt.cb3 -sticky w
    grid $w.f_opt.f_del -sticky w
    grid $w.f_opt.static -row 1 -column 1 -rowspan 3 -sticky e
    grid rowconf $w.f_opt 0 -weight 1 
    grid columnconf $w.f_opt 0 -weight 1 
    grid rowconf $w.f_opt 3 -weight 1 
    grid columnconf $w.f_opt 0 -weight 1 
    
    # los controles
    frame $w.f_ctr -relief ridge -bd 2

    # el chivato
    frame $w.f_ctr.f1
    label $w.f_ctr.f1.l -text [_ "Step: "]
    entry $w.f_ctr.f1.e -relief sunken -width 5 -state disabled
    label $w.f_ctr.f1.l2 -fg black -font SmallFont \
	    -textvariable GidPriv(PostAnimateFileSize)
    set GidPriv(PostAnimateFileSizeLabel) $w.f_ctr.f1.l2
    grid $w.f_ctr.f1.l -sticky e
    grid $w.f_ctr.f1.e -row 0 -column 1 -sticky w
    grid $w.f_ctr.f1.l2 -row 0 -column 2 -sticky ew
    grid rowconf $w.f_ctr.f1 0 -weight 1
    grid columnconf $w.f_ctr.f1 1 -weight 1
    grid columnconf $w.f_ctr.f1 2 -weight 1

    scale $w.f_ctr.b -highlightthickness 0 -orient h -from 1 -to 2 -command PostAnimateChangeScale \
	    -bd 1 -sliderlength 16

    #-label "Frame:"
    #	    -command "ChangeStep"

    set GidPriv(PostAnimateSlide) $w.f_ctr.b
    set GidPriv(PostAnimateEntry) $w.f_ctr.f1.e
    #$w.f_ctr.b set 1

    frame $w.f_ctr.f2
    if { ![ info exists GidPriv(PostAnimatePlayImg)] } {
	set GidPriv(PostAnimatePlayImg) [image create bitmap -file $GIDDEFAULT/bitmaps/go.xbm \
		-maskfile $GIDDEFAULT/bitmaps/go-msk.xbm \
		-background yellow -foreground black]
    }
    button $w.f_ctr.f2.play -image $GidPriv(PostAnimatePlayImg) \
	    -command "PostAnimatePlay $w.f_ctr.f2.play" -bd 1
    
    if { ![ info exists GidPriv(PostAnimateStopImg)] } {
	set GidPriv(PostAnimateStopImg) [image create bitmap -file $GIDDEFAULT/bitmaps/stop.xbm \
		-maskfile $GIDDEFAULT/bitmaps/stop-msk.xbm \
		-background yellow -foreground black]
    }
    button $w.f_ctr.f2.stop -image $GidPriv(PostAnimateStopImg) \
	    -command "PostAnimateStop $w.f_ctr.f2.stop" -bd 1
    
    if { ![ info exists GidPriv(PostAnimateRewindImg)] } {
	set GidPriv(PostAnimateRewindImg) [image create bitmap -file $GIDDEFAULT/bitmaps/rewind.xbm \
		-maskfile $GIDDEFAULT/bitmaps/rewind-msk.xbm \
		-background yellow -foreground black]
    }
    button $w.f_ctr.f2.rewind -image $GidPriv(PostAnimateRewindImg) \
	    -command "PostAnimateRewind $w.f_ctr.f2.rewind" -bd 1
    
    if { ![ info exists GidPriv(PostAnimateStepImg)] } {
	set GidPriv(PostAnimateStepImg) [image create bitmap -file $GIDDEFAULT/bitmaps/go_step.xbm \
		-maskfile $GIDDEFAULT/bitmaps/go_step-msk.xbm \
		-background yellow -foreground black]
    }
    button $w.f_ctr.f2.step -image $GidPriv(PostAnimateStepImg) \
	    -command "PostAnimateStep $w.f_ctr.f2.step" -bd 1

    #     grid $w.f_ctr.f2.rewind -row 0 -column 0 -ipadx 2 -ipady 2 -padx 2 -pady 2 -sticky w
    #     grid $w.f_ctr.f2.stop -row 0 -column 1 -ipadx 2 -ipady 2 -padx 2 -pady 2 -sticky we
    #     grid $w.f_ctr.f2.play -row 0 -column 2 -ipadx 2 -ipady 2 -padx 2 -pady 2 -sticky we
    #     grid $w.f_ctr.f2.step -row 0 -column 3 -ipadx 2 -ipady 2 -padx 2 -pady 2 -sticky e
    grid $w.f_ctr.f2.rewind $w.f_ctr.f2.stop $w.f_ctr.f2.play $w.f_ctr.f2.step \
	    -ipadx 2 -ipady 2 -padx 2 -pady 2 -sticky we

    grid $w.f_ctr.f1 -sticky we 
    grid $w.f_ctr.b -sticky we
    grid $w.f_ctr.f2 -sticky we
    grid columnconf $w.f_ctr 0 -weight 1 
    grid rowconf $w.f_ctr 0 -weight 1 
    grid rowconf $w.f_ctr 1 -weight 1 
    grid rowconf $w.f_ctr 2 -weight 1 
    
    set PA_OpenFolderImage [ image create bitmap -data {
	#define folder_open_width 20
	#define folder_open_height 16
	static unsigned char folder_open_bits[] = {
	    0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x04, 0x00,
	    0xf8, 0x83, 0x00, 0xf8, 0xff, 0x00, 0xf8, 0xff, 0x00, 0x38, 0x00, 0x08,
	    0x38, 0x00, 0x04, 0x18, 0x00, 0x04, 0x18, 0x00, 0x02, 0x08, 0x00, 0x02,
	    0x08, 0x00, 0x01, 0x00, 0x00, 0x01, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00}; 
	} -maskdata {
	    #define folder_open_msk_width 20
	    #define folder_open_msk_height 16
	    static unsigned char folder_open_msk_bits[] = {
		0x00, 0x00, 0x00, 0xf0, 0x01, 0x00, 0xf8, 0x03, 0x00, 0xfc, 0x07, 0x00,
		0x04, 0xbc, 0x00, 0x04, 0x80, 0x00, 0x04, 0x80, 0x00, 0xc4, 0xff, 0x0f,
		0xc4, 0xff, 0x07, 0x64, 0x77, 0x07, 0xe4, 0xdd, 0x03, 0x74, 0x77, 0x03,
		0xd4, 0xdd, 0x01, 0x7c, 0x77, 0x01, 0xfc, 0xff, 0x00, 0x00, 0x00, 0x00}; 
	    } -background yellow -foreground black ]
    frame $w.f_save
    frame $w.f_save.f
    frame $w.f_save.f.f -bd 0
    #checkbutton $w.f_save.f.cb -text [_ "Save TIFFs on"] -variable GidPriv(PostAnimateSaveFrame)
    checkbutton $w.f_save.f.f.cb -text [_ "Save"] -variable GidPriv(PostAnimateSaveFrame)
    menubutton $w.f_save.f.f.mb -menu $w.f_save.f.f.mb.m -textvariable GidPriv(PostAnimateSaveFrameFormat) \
	    -relief raised -bd 1 -width 5 -highlightthickness 1
    menu $w.f_save.f.f.mb.m -tearoff 0 -bd 1 -activeborderwidth 1
    $w.f_save.f.f.mb.m add command -label [_ "TIFF"] -command "set GidPriv(PostAnimateSaveFrameFormat) TIFF"
    $w.f_save.f.f.mb.m add command -label [_ "JPEG"] -command "set GidPriv(PostAnimateSaveFrameFormat) JPEG"
    $w.f_save.f.f.mb.m add command -label [_ "GIF"] -command "set GidPriv(PostAnimateSaveFrameFormat) GIF"

    label $w.f_save.f.f.l -text [_ "on"]
    grid $w.f_save.f.f.cb $w.f_save.f.f.mb $w.f_save.f.f.l \
	    -padx 0 -ipadx 0 -pady 0 -ipady 0 -sticky nsew
    button $w.f_save.f.b -bd 1 -image $PA_OpenFolderImage -command PostAnimateChooseSavePrefix
    grid $w.f_save.f.f -sticky w
    grid $w.f_save.f.b -row 0 -column 1 -sticky e

    entry $w.f_save.e -relief sunken -width 5 -state disabled -textvariable GidPriv(PostAnimateSavePrefix)
		grid $w.f_save.f -sticky w
    grid $w.f_save.e -sticky we

    grid columnconf $w.f_save 0 -weight 1 
    grid rowconf $w.f_save 0 -weight 1 
    grid rowconf $w.f_save 1 -weight 1 

    GiDPopUpHelp $w.f_save "To create a image sequence, the prefix of the images names must be entered here."
    GiDPopUpHelp $w.f_save.f.f.mb "Choose the file format of the image sequence."
    GiDPopUpHelp $w.f_save.f.b "A file browser will be openned, so a file can be selected."

    frame $w.f_anim
    frame $w.f_anim.f
    frame $w.f_anim.f.f -bd 0
    #-text "Save MPEG on"
    checkbutton $w.f_anim.f.f.cb -text [_ "Save"] -variable GidPriv(PostAnimateSaveAnimation)

#    set menu [eval [ concat tk_optionMenuRAM $w.f_anim.f.f.mb GidPriv(PostAnimateSaveAnimationFormat) \
#	    [list "MPEG" "AVI/mjpeg" [_ "AVI/raw True Color"]  [_ "AVI/raw 15 bpp"] "GIF" ] \
#	    {MPEG AVIMJPG AVI AVI15 GIF}]
#    $w.f_anim.f.f.mb conf -width 5 -bd 1 -highlightthickness 1
#    $menu conf -bd 1 -activeborderwidth 1   
#    trace variable GidPriv(PostAnimateSaveAnimationFormat) w PostAnimateChangeExtension

    menubutton $w.f_anim.f.f.mb -menu $w.f_anim.f.f.mb.m -textvariable GidPriv(PostAnimateSaveAnimationFormat) \
	     -relief raised -bd 1 -width 7 -highlightthickness 1
    menu $w.f_anim.f.f.mb.m -tearoff 0 -bd 1 -activeborderwidth 1
    $w.f_anim.f.f.mb.m add command -label [_ "MPEG"] \
	    -command "set GidPriv(PostAnimateSaveAnimationFormat) MPEG; PostAnimateChangeExtension MPEG"
    $w.f_anim.f.f.mb.m add command -label [_ "AVI/mjpeg"] \
	    -command "set GidPriv(PostAnimateSaveAnimationFormat) AVIMJPG; PostAnimateChangeExtension AVIMJPG"
    $w.f_anim.f.f.mb.m add command -label [_ "AVI/raw True Color"] \
	    -command "set GidPriv(PostAnimateSaveAnimationFormat) AVI; PostAnimateChangeExtension AVI"
    $w.f_anim.f.f.mb.m add command -label [_ "AVI/raw 15 bpp"] \
	    -command "set GidPriv(PostAnimateSaveAnimationFormat) AVI15; PostAnimateChangeExtension AVI15"
    $w.f_anim.f.f.mb.m add command -label [_ "GIF"] \
	    -command "set GidPriv(PostAnimateSaveAnimationFormat) GIF; PostAnimateChangeExtension GIF"
 

    label $w.f_anim.f.f.l -text [_ "on"]
    grid $w.f_anim.f.f.cb $w.f_anim.f.f.mb $w.f_anim.f.f.l \
	    -padx 0 -ipadx 0 -pady 0 -ipady 0 -sticky nsew

    button $w.f_anim.f.b -bd 1 -image $PA_OpenFolderImage -command PostAnimateChooseAnimationFile
    canvas $w.f_anim.f.cv -width 36 -height 18
    set led_libre [ $w.f_anim.f.cv create oval 2 2 17 17 -fill grey60]
    set led_ocupado [ $w.f_anim.f.cv create oval 20 2 35 17 -fill grey60]
    set GidPriv(PostAnimateMPEG_led_libre) $led_libre
    set GidPriv(PostAnimateMPEG_led_ocupado) $led_ocupado
    PostAnimateMPEGLeds DISABLED

    GiDPopUpHelp $w.f_anim.f.cv "Animation status leds:\n"\
	    "Green: no animation is being done, \n"\
	    "       the animation file is closed.\n"\
	    "Red:   GiD is storing frames ( added \n"\
	    "       by the user, or storing redraws)\n"\
	    "       in an opened animation file."
#
#    GiDPopUpHelp $w.f_anim.f.cv "Animation status leds:\n"\
#	     "Green: no animation is being done, \n"\
#	     "       the animation file is closed.\n"\
#	     "Red:   GiD is storing frames ( added \n"\
#	     "       by the user, or storing redraws)\n"\
#	     "       in an opened animation file."
#
    grid $w.f_anim.f.f -sticky w
    grid $w.f_anim.f.b -row 0 -column 1 -sticky e
    grid $w.f_anim.f.cv -row 0 -column 2 -sticky e

    entry $w.f_anim.e -relief sunken -width 5 -state disabled -textvariable GidPriv(PostAnimateSaveAnimationFile)
    grid $w.f_anim.f -sticky w
    grid $w.f_anim.e -sticky we

    grid columnconf $w.f_anim 0 -weight 1 
    grid rowconf $w.f_anim 0 -weight 1 
    grid rowconf $w.f_anim 1 -weight 1 

    GiDPopUpHelp $w.f_anim "Here the name of the animation file must be entered."
    GiDPopUpHelp $w.f_anim.f.f.mb "Choose the file format of the animation file."
    GiDPopUpHelp $w.f_anim.f.b "A file browser will be openned, so a file can be selected."

    # close
    frame $w.f_but
    frame $w.f_but.siz -relief sunken -bd 1
    # 768x576 640x480 512x384 320x240

    #set menu [eval [ concat tk_optionMenu $w.f_but.siz.mb GidPriv(PostAnimateResize) \
    #	     "Default" 720x576 640x480 512x384 320x240]]
    #$w.f_but.siz.mb conf -width 9 -bd 1 -highlightthickness 1
    #$menu conf -bd 1 -activeborderwidth 1

    menubutton $w.f_but.siz.mb -menu $w.f_but.siz.mb.m -textvariable GidPriv(PostAnimateResize) \
	     -relief raised -bd 1 -width 8 -highlightthickness 1
    menu $w.f_but.siz.mb.m -tearoff 0 -bd 1 -activeborderwidth 1
    $w.f_but.siz.mb.m add command -label [_ "Default"] -command {set GidPriv(PostAnimateResize) Default}
    $w.f_but.siz.mb.m add command -label [_ "800x600"] -command {set GidPriv(PostAnimateResize) 800x600}
    $w.f_but.siz.mb.m add command -label [_ "720x576"] -command {set GidPriv(PostAnimateResize) 720x576}
    $w.f_but.siz.mb.m add command -label [_ "640x480"] -command {set GidPriv(PostAnimateResize) 640x480}
    $w.f_but.siz.mb.m add command -label [_ "512x384"] -command {set GidPriv(PostAnimateResize) 512x384}
    #$w.f_but.siz.mb.m add command -label [_ "352x288 (VCD-PAL)"] -command {set GidPriv(PostAnimateResize) 352x288}
    $w.f_but.siz.mb.m add command -label [_ "352x288"] -command {set GidPriv(PostAnimateResize) 352x288}
    #$w.f_but.siz.mb.m add command -label [_ "352x240 (VCD-NTSC)"] -command {set GidPriv(PostAnimateResize) 352x240}
    $w.f_but.siz.mb.m add command -label [_ "320x240"] -command {set GidPriv(PostAnimateResize) 320x240}

    button $w.f_but.siz.resize -text [_ "Resize"] -command PostAnimateResize -bd 1

    grid $w.f_but.siz.mb $w.f_but.siz.resize 

    button $w.f_but.close -text [_ "Close"] -command "PostAnimateFin $w" -bd 1

    grid $w.f_but.siz -sticky w -ipady 1 -pady 1 -ipadx 1 -padx 1
    grid $w.f_but.close -column 1 -row 0 -sticky e






    #button $w.f_but.test -text Test -command AutoAnimate::Crear -bd 1
    #grid $w.f_but.test -column 2 -row 0 -sticky e




    grid rowconf $w.f_but 0 -weight 1
    grid rowconf $w.f_but 1 -weight 1
    grid columnconf $w.f_but 0 -weight 1
    GiDPopUpHelp $w.f_but.siz "For MPEG files on windows its recommended \n"\
	    "to choose a windows-standard frame size:\n" \
	    "320x240 / 352x288 / 512x384 / 640x480 / 720x576 or 800x600"
    GiDPopUpHelp $w.f_but.siz.mb "For MPEG files on windows its recommended \n"\
	    "to choose a windows-standard frame size:\n" \
	    "320x240 / 352x288 / 512x384 / 640x480 / 720x576 or 800x600"
    GiDPopUpHelp $w.f_but.siz.resize "For MPEG files on windows its recommended \n"\
	    "to choose a windows-standard frame size:\n" \
	    "320x240 / 352x288 / 512x384 / 640x480 / 720x576 or 800x600"
    
    grid $w.f_opt -sticky news
    grid $w.f_ctr -sticky news
    grid $w.f_save -sticky ew
    grid $w.f_anim -sticky ew
    grid $w.f_but -sticky ew
    
    grid rowconf $w 1 -weight 1
    grid rowconf $w 2 -weight 1
    grid rowconf $w 3 -weight 1
    grid rowconf $w 0 -weight 1
    grid rowconf $w 4 -weight 1
    grid columnconf $w 0 -weight 1

    set GidPriv(PostAnimateInitializing) 0
    trace variable GidPriv(PostAnimateDeform) w CambioPostAnimateDeform
    PostAnimateInitVariables 
    update
    #set GidPriv(PostAnimateInitializing) 0

    catch {
	trace variable GidPriv(PostAnimateDelay) w PostAnimateTogleDelayEntry
	trace variable GidPriv(PostAnimateDelayTime) w PostAnimateCheckDelayTime
	trace variable GidPriv(PostAnimateSaveFrame) w PostAnimateTogleSaveEntry
	trace variable GidPriv(PostAnimateSaveAnimation) w PostAnimateTogleAnimEntry
	trace variable GidPriv(PostAnimateAnalysisLimitsCb) w PostAnimateGetAnalysisLimits
    }

    set GidPriv(PostAnimateDelay) 1

    if { !$GidPriv(PostAnimateSaveFrame) } { 
	$w.f_save.f.f.cb conf -foreground grey60
	$w.f_save.f.f.mb conf -state disabled
	$w.f_save.f.f.l conf -foreground grey60
	$w.f_save.f.b conf -state disabled
	$w.f_save.e conf -state disabled -foreground grey60
    }
    if { !$GidPriv(PostAnimateSaveAnimation) } {
	$w.f_anim.f.f.cb conf -foreground grey60
	$w.f_anim.f.f.mb conf -state disabled
	$w.f_anim.f.f.l conf -foreground grey60
	$w.f_anim.f.b conf -state disabled
	$w.f_anim.e conf -state disabled -foreground grey60
    }


    set GidPriv(PostAnimateAnalysisLimitsCb) 1
}


proc PostAnimateShowFileSize { } {
    global GidPriv

    if { ( [info exist GidPriv(PrePostAnimateWindow)] && [ winfo exist $GidPriv(PrePostAnimateWindow)]) || \
	( [info exist GidPriv(PostAnimateWindow)] && [ winfo exist $GidPriv(PostAnimateWindow)])} {
	file stat "$GidPriv(PostAnimateSaveAnimationFile)" pp
# GidPriv(PostAnimateCurrentFrame) GidPriv(PostAnimateDefaultDelayTime)
	# set GidPriv(PostAnimateFileSize) "[format \"%.3g MB\" [ expr $pp(size)/(1024.0*1024.0)]]"
	set GidPriv(PostAnimateTime) [ expr $GidPriv(PostAnimateTime) + $GidPriv(PostAnimateDelayTime)]
	set time [ expr $GidPriv(PostAnimateTime) / 1000]
	set GidPriv(PostAnimateFileSize) [format "%02d:%02d - %.3gMB" [ expr int( $time / 60)] [ expr int( $time % 60)] [ expr $pp(size)/(1024.0*1024.0)]]
    }
}

proc PostAnimateShowTime { } {
    global GidPriv

    if { ( [info exist GidPriv(PrePostAnimateWindow)] && [ winfo exist $GidPriv(PrePostAnimateWindow)]) || \
	( [info exist GidPriv(PostAnimateWindow)] && [ winfo exist $GidPriv(PostAnimateWindow)])} {
	set GidPriv(PostAnimateTime) [ expr $GidPriv(PostAnimateTime) + $GidPriv(PostAnimateDelayTime)]
	set time [ expr $GidPriv(PostAnimateTime) / 1000]
	set GidPriv(PostAnimateFileSize) [format "%02d:%02d" [ expr $time / 60] [ expr $time % 60]]
    }
}

######################################################################
##### Animation Controls Window #####
######################################################################

proc PostAnimateControlsResize { } {
    global GidPriv

    set info [ wm geometry .gid]
    set info2 [.central.s configure]
    set height_list [ lindex $info2 0]
    set width_list [ lindex $info2 1]
    if { ![ regexp {([0-9]*)x([0-9]*)} $info trozo top_width top_height] } { return }
    set width_offset [ expr $top_width - [ lindex $width_list 4]]
    set height_offset [ expr $top_height - [ lindex $height_list 4]]

    if { $GidPriv(PostAnimateControlsResize) == "Default"} {
	set GidPriv(PostAnimateControlsResize) $GidPriv(PostAnimateControlsResizeDefault)
    } 
    if { ![ regexp {([0-9]*)x([0-9]*)} $GidPriv(PostAnimateControlsResize) trozo new_width new_height] } { return }
    
    #WarnWinText ".gid = $info = $top_width x $top_height"
    #WarnWinText "togl = [ lindex $width_list 4]x[ lindex $height_list 4]"
    #WarnWinText "offset = $width_offset x $height_offset"
    ## 768x576 640x480 512x384 320x240
    wm geometry .gid [ expr $width_offset + $new_width]x[ expr $height_offset + $new_height]
}

proc PostAnimateControlsInitValues {} {    
    global GidPriv

    set GidPriv(PostAnimateControlsDoing) Nothing
    set GidPriv(PostAnimateControlsDefaultDelayTime) 500
    if { ![ info exist GidPriv(PostAnimateControlsDelayTime)]} {
	set GidPriv(PostAnimateControlsDelayTime) $GidPriv(PostAnimateControlsDefaultDelayTime)
    }
    set GidPriv(PostAnimateControlsDelay) 1
    set GidPriv(PostAnimateControlsSaveAnimation) 0
    set GidPriv(PostAnimateControlsSavingAnimation) 0
    set GidPriv(PostAnimateControlsSavingRepes) 1
    set GidPriv(PostAnimateControlsSaveAnimationFormat) [.central.s info post get animationformat]
    set GidPriv(PostAnimateControlsSaveFrameFormat) "TIFF"
    set GidPriv(PostAnimateControlsSaveAnimationFormat) AVIMJPG
    set info2 [.central.s configure]
    set height_list [ lindex $info2 0]
    set width_list [ lindex $info2 1]
    set current [format "%dx%d" [ lindex $width_list 4] [ lindex $height_list 4]]
    set GidPriv(PostAnimateControlsResizeDefault) "$current"
    set GidPriv(PostAnimateControlsResize) Default

    set GidPriv(PostAnimateControlsLastFile) "" 
    if { ![ info exist GidPriv(PostAnimateControlsSaveRedraws)]} {
	set GidPriv(PostAnimateControlsSaveRedraws) 0
    }
    set GidPriv(PostAnimateControlsDisableList) ""
    set GidPriv(PostAnimateControlsDisableColorList) ""
    set GidPriv(PostAnimateControlsFileSize) ""
    set GidPriv(PostAnimateControlsTime) 0
}

proc PostAnimateControlsMPEGLeds { estado} {
    global GidPriv
    
    set w $GidPriv(PostAnimateControlsMPEGCanvas)
    set led_libre $GidPriv(PostAnimateControlsMPEG_led_libre)
    set led_ocupado $GidPriv(PostAnimateControlsMPEG_led_ocupado)

    switch $estado {
	DISABLED {
	    $w itemconfigure $led_libre -fill grey60
	    $w itemconfigure $led_ocupado -fill grey60
	}
	FREE {
	    $w itemconfigure $led_libre -fill green
	    $w itemconfigure $led_ocupado -fill grey60
	}
	BUSY {
	    $w itemconfigure $led_libre -fill grey60
	    $w itemconfigure $led_ocupado -fill red
	}
	default {
	    WarnWin [_ "Unknown led state: %s" $estado] $GidPriv(PostAnimateControlsWindow)
	    $w itemconfigure $led_libre -fill grey60
	    $w itemconfigure $led_ocupado -fill grey60
	}
    }
    
}

proc PostAnimateControlsTogleDelayEntry { name1 name2 op} {
    global GidPriv
    
    set w $GidPriv(PrePostAnimateControlsWindow)
    if { $GidPriv(PostAnimateControlsDelay) } {
	$w.f_opt.f_del.e conf -state normal -foreground black
	focus $w.f_opt.f_del.e
    } else {
	$w.f_opt.f_del.e conf -state disabled -foreground grey60
    }
}

proc PostAnimateControlsTogleMPEGLeds { name1 name2 op} {
    global GidPriv

    if { $GidPriv(PostAnimateControlsSavingAnimation) == 0} {
	PostAnimateControlsMPEGLeds FREE
	foreach i $GidPriv(PostAnimateControlsDisableList) {
	    $i conf -state normal
	}
	foreach i $GidPriv(PostAnimateControlsDisableColorList) {
	    $i conf -foreground black
	}
    }

    if { $GidPriv(PostAnimateControlsSavingAnimation) == 1} {
	PostAnimateControlsMPEGLeds BUSY
	foreach i $GidPriv(PostAnimateControlsDisableList) {
	    $i conf -state disabled
	}
	foreach i $GidPriv(PostAnimateControlsDisableColorList) {
	    $i conf -foreground grey60
	}
    }
}

proc PostAnimateControlsTogleAnimEntry { name1 name2 op} {
    global GidPriv
    
    set w $GidPriv(PrePostAnimateControlsWindow)
    if { $GidPriv(PostAnimateControlsSaveAnimation) } {
	$w.f_opt.f_anim.e conf -state normal -foreground black
	focus $w.f_opt.f_anim.e
	PostAnimateControlsMPEGLeds FREE
	trace variable GidPriv(PostAnimateControlsSavingAnimation) w PostAnimateControlsTogleMPEGLeds
    } else {
	$w.f_opt.f_anim.e conf -state disabled -foreground grey60
	PostAnimateControlsMPEGLeds DISABLED
	trace vdelete GidPriv(PostAnimateControlsSavingAnimation) w PostAnimateControlsTogleMPEGLeds
    }
}

proc PostAnimateControlsCheckDelayTime { name1 name2 op} {
    global GidPriv
    
    set w $GidPriv(PrePostAnimateControlsWindow)
    set len [string length $GidPriv(PostAnimateControlsDelayTime)]
    set cur_digit [ string index $GidPriv(PostAnimateControlsDelayTime) [ expr $len - 1]]
    if { ( $cur_digit >= 0) && ( $cur_digit <= 9)} { return}
    if { ( $cur_digit == "e") || ( $cur_digit == "E") || 
    ( $cur_digit == "+") || ( $cur_digit == "-") || ( $cur_digit == ".")} {
	return
    }
    set GidPriv(PostAnimateControlsDelayTime) [ string range $GidPriv(PostAnimateControlsDelayTime) 0 [ expr $len-2]]
}

proc PostAnimateControlsAddStep { w} {
    global GidPriv

    if { $w != ""} {
	$w conf -relief sunken
    }

    if { ( [ info exist GidPriv(PostAnimateSaveAnimation) ] && \
	    $GidPriv(PostAnimateSaveAnimation)) || \
	    ( [ info exist GidPriv(PostAnimateSavingAnimation) ] && \
	    $GidPriv(PostAnimateSavingAnimation)) } {
	WarnWin "Sorry, but couldn't save the animation while another one is active (Post Animate Window)"
	return
    }
    
    if { !$GidPriv(PostAnimateControlsSavingAnimation)} {
	if { "$GidPriv(PostAnimateControlsSaveAnimationFile)" == ""} {
	    WarnWin [_ "Sorry but a file name is needed to save the animation."] $w
	    if { $w != ""} {
		$w conf -relief raised
	    }
	    return
	} else {

	    if { "$GidPriv(PostAnimateControlsLastFile)" == "$GidPriv(PostAnimateControlsSaveAnimationFile)" } {
		set resp [ tk_messageBox -parent $GidPriv(PrePostAnimateControlsWindow) -icon warning -type yesno \
			-default no -message \
			"Warning: Do you want to overwrite the file '$GidPriv(PostAnimateControlsSaveAnimationFile)'?" ]
		if { $resp == "no"} {
		    if { $w != ""} {
			$w conf -relief raised
		    }
		    return
		}
	    }

	    if { !$GidPriv(PostAnimateControlsDelay) } {
		WarnWin [_ "There is no delay selected, using default of 500 ms. \n If you want no delay, please check the delay time entry."] $w
	    }

	    .central.s process animationfile format \
		    $GidPriv(PostAnimateControlsSaveAnimationFormat)

	    if { $GidPriv(PostAnimateControlsSaveRedraws) } {
		.central.s process animationfile SaveRedraws Yes
	    }
	    
	    if { ( "$GidPriv(PostAnimateControlsSaveAnimationFormat)" == "AVIMJPG") || \
		    ( "$GidPriv(PostAnimateControlsSaveAnimationFormat)" == "AVI") || \
		    ( "$GidPriv(PostAnimateControlsSaveAnimationFormat)" == "AVI15")} {
		set info2 [.central.s configure]
		set height_list [ lindex $info2 0]
		set width_list [ lindex $info2 1]
		set width [ lindex $width_list 4]
		set height [ lindex $height_list 4]
		
		set avisize [ expr $width * $height * 1]
		if { "$GidPriv(PostAnimateControlsSaveAnimationFormat)" == "AVIMJPG" } {
		    # estimacion aproximada
		    set avisize [ expr $avisize * 3 * 0.1]
		} elseif { "$GidPriv(PostAnimateControlsSaveAnimationFormat)" == "AVI" } {
		    set avisize [ expr $avisize * 3]
		} else {
		    set avisize [ expr $avisize * 2]
		}
		set avisize [ expr ( $avisize / 1024.0) / 1024.0]
		
		if { $avisize > 95.00 } {
		    set resp [ tk_messageBox -parent $GidPriv(PrePostAnimateControlsWindow) -icon warning -type yesno \
			    -default no -message \
			    "Warning: the AVI file will be [ format %.3g $avisize] MB big !!!\n Are you sure you want continue?" ]
		    if { $resp == "no"} {
			if { $w != ""} {
			    $w conf -relief raised
			}
			return
		    }
		}
		#WarnWin "The AVI file will be [ format %.3g $avisize] MB big !!!"
	    }
	    
	    # Frame rate = 25 FPS == 40 ms.
	    set repe 1
	    if { $GidPriv(PostAnimateControlsDelay) } {
		if { ( $GidPriv(PostAnimateControlsDelayTime) == 0) && \
			( "$GidPriv(PostAnimateControlsSaveAnimationFormat)" == "MPEG") } {
		    set resp [ tk_messageBox -parent $GidPriv(PrePostAnimateControlsWindow) -icon warning -type yesno \
			    -default no -message \
			    "Saving a MPEG animation file without delay between Steps can cause some strange efects in Microsoft Windows 95/98/NT.\n Are you sure you want continue?" ]
		    if { $resp == "no"} {
			if { $w != ""} {
			    $w conf -relief raised
			}
			return
		    }
		}
		#	    set repe [ expr int(0.5 + $GidPriv(PostAnimateControlsDefaultDelayTime)/40.0)]
		set repe [ expr int(0.5 + $GidPriv(PostAnimateControlsDelayTime)/40.0)]
		if { $repe == 0} { set repe 1}
	    } else {
		# por defecto medio segundo
		set repe [ expr int(0.5 + 500.0/40.0)]
		if { $repe == 0} { set repe 1}
	    }
	    set GidPriv(PostAnimateControlsSavingRepes) $repe
	    .central.s process animationfile framesperstep \
		    $GidPriv(PostAnimateControlsSavingRepes) escape escape escape escape
	    .central.s process animationfile start \
		    \"$GidPriv(PostAnimateControlsSaveAnimationFile)\" yes escape escape escape escape
	    set GidPriv(PostAnimateControlsSavingAnimation) 1
	    update	    

	    # para mostrar al usuario el tamanyo del archivo
	    $GidPriv(PostAnimateControlsFileSizeLabel) conf -fg black
	    set GidPriv(PostAnimateControlsTime) 0
	}
    }
    
    if { $GidPriv(PostAnimateControlsSavingAnimation)} {
	if { $GidPriv(PostAnimateControlsSavingAnimation) } {
	    .central.s process animationfile addstep
	    #PostAnimateControlsShowFileSize
	}   
    }

    if { $w != ""} {
	$w conf -relief raised
    }
}

proc PostAnimateControlsShowFileSize { } {
    global GidPriv

    if { ( [info exist GidPriv(PrePostAnimateControlsWindow)] && [ winfo exist $GidPriv(PrePostAnimateControlsWindow)]) || \
	( [info exist GidPriv(PostAnimateControlsWindow)] && [ winfo exist $GidPriv(PostAnimateControlsWindow)])} {
	file stat "$GidPriv(PostAnimateControlsSaveAnimationFile)" pp
# GidPriv(PostAnimateControlsCurrentFrame) GidPriv(PostAnimateControlsDefaultDelayTime)
	# set GidPriv(PostAnimateControlsFileSize) "[format \"%.3g MB\" [ expr $pp(size)/(1024.0*1024.0)]]"
	set GidPriv(PostAnimateControlsTime) [ expr $GidPriv(PostAnimateControlsTime) + $GidPriv(PostAnimateControlsDelayTime)]
	set time [ expr $GidPriv(PostAnimateControlsTime) / 1000]
	set GidPriv(PostAnimateControlsFileSize) [format "%02d:%02d - %.3gMB" [ expr int( $time / 60)] [ expr int( $time % 60)] [ expr $pp(size)/(1024.0*1024.0)]]
    }
}

proc PostAnimateControlsShowTime { } {
    global GidPriv

    if { ( [info exist GidPriv(PrePostAnimateControlsWindow)] && [ winfo exist $GidPriv(PrePostAnimateControlsWindow)]) || \
	( [info exist GidPriv(PostAnimateControlsWindow)] && [ winfo exist $GidPriv(PostAnimateControlsWindow)])} {
	set GidPriv(PostAnimateControlsTime) [ expr $GidPriv(PostAnimateControlsTime) + $GidPriv(PostAnimateControlsDelayTime)]
	set time [ expr $GidPriv(PostAnimateControlsTime) / 1000]
	set GidPriv(PostAnimateControlsFileSize) [format "%02d:%02d" [ expr $time / 60] [ expr $time % 60]]
    }
}

proc PostAnimateControlsEndAnim { w} {
    global GidPriv

    if { $w != ""} {
	$w conf -relief sunken
    }
    
    if { $GidPriv(PostAnimateControlsSavingAnimation) } {
	.central.s process animationfile end
	set GidPriv(PostAnimateControlsSavingAnimation) 0
	set GidPriv(PostAnimateControlsLastFile) $GidPriv(PostAnimateControlsSaveAnimationFile)
	if { $GidPriv(PostAnimateControlsSaveRedraws) } {
	    .central.s process animationfile SaveRedraws No
	}
	$GidPriv(PostAnimateControlsFileSizeLabel) conf -fg grey60
    }

    if { $w != ""} {
	$w conf -relief raised
    }
}

proc PostAnimateControlsFin { w} {
    global GidPriv

    if { $GidPriv(PostAnimateControlsSavingAnimation) } {
	.central.s process animationfile end
	set GidPriv(PostAnimateControlsSavingAnimation) 0
    }

    destroy $w
        
    catch {
	trace vdelete GidPriv(PostAnimateControlsDelay) w PostAnimateControlsTogleDelayEntry
	trace vdelete GidPriv(PostAnimateControlsDelayTime) w PostAnimateControlsCheckDelayTime
	trace vdelete GidPriv(PostAnimateControlsSaveAnimation) w PostAnimateControlsTogleAnimEntry
	trace vdelete GidPriv(PostAnimateControlsSavingAnimation) w PostAnimateControlsTogleMPEGLeds
    }
}

proc PostAnimateControlsChooseAnimationFile {} {
    global GidPriv

    if { $GidPriv(PostAnimateControlsSaveAnimation) } {
	set w $GidPriv(PrePostAnimateControlsWindow)
	switch "$GidPriv(PostAnimateControlsSaveAnimationFormat)" {
	    "MPEG" {
		set GidPriv(PostAnimateControlsSaveAnimationFile) [Browser-ramR file write $w [_ "Save MPEG on"]... \
                {} {{{Mpeg animation} {.mpg .mpeg}} {{All files} {.*}}} ".mpg" ]
	    }
	    "AVIMJPG" {
		set GidPriv(PostAnimateControlsSaveAnimationFile) [Browser-ramR file write $w [_ "Save AVI on"]... \
                {} {{{AVI animation} {.avi}} {{All files} {.*}}} ".avi" ]
	    }
	    "AVI" {
		set GidPriv(PostAnimateControlsSaveAnimationFile) [Browser-ramR file write $w [_ "Save AVI on"]... \
                {} {{{AVI animation} {.avi}} {{All files} {.*}}} ".avi" ]
	    }
	    "AVI15" {
		set GidPriv(PostAnimateControlsSaveAnimationFile) [Browser-ramR file write $w [_ "Save AVI on"]... \
                {} {{{AVI animation} {.avi}} {{All files} {.*}}} ".avi" ]
	    }
	    "GIF" {
		set GidPriv(PostAnimateControlsSaveAnimationFile) [Browser-ramR file write $w [_ "Save GIF on"]... \
                {} {{{GIF animation} {.gif}} {{All files} {.*}}} ".gif" ]
	    }
	}
	#$w.f_anim.e del 0 end
	#$w.f_anim.e ins 0 $GidPriv(PostAnimateControlsSaveAnimationFile)
    }
}

proc PostAnimateControls { { w .wPostAnimateControls } } {
    global GidPriv GIDDEFAULT
    
    if { [ winfo exist $w]} {return}

    catch {
	trace vdelete GidPriv(PostAnimateControlsDelay) w PostAnimateControlsTogleDelayEntry
	trace vdelete GidPriv(PostAnimateControlsDelayTime) w PostAnimateControlsCheckDelayTime
	trace vdelete GidPriv(PostAnimateControlsSaveAnimation) w PostAnimateControlsTogleAnimEntry
	trace vdelete GidPriv(PostAnimateControlsSavingAnimation) w PostAnimateControlsTogleMPEGLeds
    }
    

    set GidPriv(PostAnimateControlsInitializing) 1
    PostAnimateControlsInitValues

    InitWindow $w [_ "Animation Controls"] PrePostAnimateControlsWindowGeom PostAnimateControls

    set color_fondo [ CCGetRGB $w [ $w cget -background]]

    # Las opciones
    frame $w.f_opt -relief ridge -bd 2
    
    frame $w.f_opt.f_del
    checkbutton $w.f_opt.f_del.cb -text [_ "Delay:"] -variable GidPriv(PostAnimateControlsDelay)
    entry $w.f_opt.f_del.e -relief sunken -width 5 -textvariable GidPriv(PostAnimateControlsDelayTime)
    $w.f_opt.f_del.e conf -state disabled -foreground grey60
    label $w.f_opt.f_del.l -text [_ "ms."]
    grid $w.f_opt.f_del.cb -sticky w
    grid $w.f_opt.f_del.e -row 0 -column 1 -sticky we 
    grid $w.f_opt.f_del.l -row 0 -column 2 -sticky e
    grid rowconf $w.f_opt.f_del 0 -weight 1 
    grid columnconf $w.f_opt.f_del 1 -weight 1 

    lappend GidPriv(PostAnimateControlsDisableList) $w.f_opt.f_del.cb
    lappend GidPriv(PostAnimateControlsDisableList) $w.f_opt.f_del.e
    lappend GidPriv(PostAnimateControlsDisableColorList) $w.f_opt.f_del.l
    
    set PA_OpenFolderImage [ image create bitmap -data {
	#define folder_open_width 20
	#define folder_open_height 16
	static unsigned char folder_open_bits[] = {
	    0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x04, 0x00,
	    0xf8, 0x83, 0x00, 0xf8, 0xff, 0x00, 0xf8, 0xff, 0x00, 0x38, 0x00, 0x08,
	    0x38, 0x00, 0x04, 0x18, 0x00, 0x04, 0x18, 0x00, 0x02, 0x08, 0x00, 0x02,
	    0x08, 0x00, 0x01, 0x00, 0x00, 0x01, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00}; 
	} -maskdata {
	    #define folder_open_msk_width 20
	    #define folder_open_msk_height 16
	    static unsigned char folder_open_msk_bits[] = {
		0x00, 0x00, 0x00, 0xf0, 0x01, 0x00, 0xf8, 0x03, 0x00, 0xfc, 0x07, 0x00,
		0x04, 0xbc, 0x00, 0x04, 0x80, 0x00, 0x04, 0x80, 0x00, 0xc4, 0xff, 0x0f,
		0xc4, 0xff, 0x07, 0x64, 0x77, 0x07, 0xe4, 0xdd, 0x03, 0x74, 0x77, 0x03,
		0xd4, 0xdd, 0x01, 0x7c, 0x77, 0x01, 0xfc, 0xff, 0x00, 0x00, 0x00, 0x00}; 
	    } -background yellow -foreground black ]
		
    frame $w.f_opt.f_anim
    frame $w.f_opt.f_anim.f
    frame $w.f_opt.f_anim.f.f -bd 0
    #-text "Save MPEG on"
    #checkbutton $w.f_opt.f_anim.f.f.cb -text [_ "Save"] -variable GidPriv(PostAnimateControlsSaveAnimation)
    label $w.f_opt.f_anim.f.f.cb -text [_ "Save"] 
    #set GidPriv(PostAnimateControlsSaveAnimation) 1

    #set menu [eval [ concat tk_optionMenu $w.f_opt.f_anim.f.f.mb GidPriv(PostAnimateControlsSaveAnimationFormat) MPEG AVI]]
    #$w.f_opt.f_anim.f.f.mb conf -width 5 -bd 1 -highlightthickness 1
    #$menu conf -bd 1 -activeborderwidth 1
    menubutton $w.f_opt.f_anim.f.f.mb -menu $w.f_opt.f_anim.f.f.mb.m -textvariable GidPriv(PostAnimateControlsSaveAnimationFormat) \
	     -relief raised -bd 1 -width 8 -highlightthickness 1
    menu $w.f_opt.f_anim.f.f.mb.m -tearoff 0 -bd 1 -activeborderwidth 1
    $w.f_opt.f_anim.f.f.mb.m add command -label [_ "MPEG"] -command "set GidPriv(PostAnimateControlsSaveAnimationFormat) MPEG"
    $w.f_opt.f_anim.f.f.mb.m add command -label [_ "AVI/mjpeg"] -command "set GidPriv(PostAnimateControlsSaveAnimationFormat) AVIMJPG"
    $w.f_opt.f_anim.f.f.mb.m add command -label [_ "AVI/raw True Color"] -command "set GidPriv(PostAnimateControlsSaveAnimationFormat) AVI"
    $w.f_opt.f_anim.f.f.mb.m add command -label [_ "AVI/raw 15 bpp"] -command "set GidPriv(PostAnimateControlsSaveAnimationFormat) AVI15"
    $w.f_opt.f_anim.f.f.mb.m add command -label [_ "GIF"] -command "set GidPriv(PostAnimateControlsSaveAnimationFormat) GIF"

    label $w.f_opt.f_anim.f.f.l -text [_ "on"]
    grid $w.f_opt.f_anim.f.f.cb $w.f_opt.f_anim.f.f.mb $w.f_opt.f_anim.f.f.l \
	    -padx 0 -ipadx 0 -pady 0 -ipady 0 -sticky nsew

    grid columnconf $w.f_opt.f_anim.f.f 1 -weight 1
    grid rowconf $w.f_opt.f_anim.f.f 0 -weight 1

    button $w.f_opt.f_anim.f.b -bd 1 -image $PA_OpenFolderImage -command PostAnimateControlsChooseAnimationFile
    # set GidPriv(PostAnimateControlsMPEGCanvas) $w.f_opt.f_anim.f.cv
    #canvas $w.f_opt.f_anim.f.cv -width 36 -height 18
    #set led_libre [ $w.f_opt.f_anim.f.cv create oval 2 2 17 17 -fill grey60]
    #set led_ocupado [ $w.f_opt.f_anim.f.cv create oval 20 2 35 17 -fill grey60]
    #set GidPriv(PostAnimateControlsMPEG_led_libre) $led_libre
    #set GidPriv(PostAnimateControlsMPEG_led_ocupado) $led_ocupado
    #PostAnimateControlsMPEGLeds DISABLED
    grid $w.f_opt.f_anim.f.f -sticky w
    grid $w.f_opt.f_anim.f.b -row 0 -column 1 -sticky e
    #grid $w.f_opt.f_anim.f.cv -row 0 -column 2 -sticky e

    grid columnconf $w.f_opt.f_anim.f 0 -weight 1
    grid rowconf $w.f_opt.f_anim.f 0 -weight 1

    entry $w.f_opt.f_anim.e -relief sunken -width 8 -state normal -textvariable GidPriv(PostAnimateControlsSaveAnimationFile)
    grid $w.f_opt.f_anim.f -sticky w
    grid $w.f_opt.f_anim.e -sticky we

    lappend GidPriv(PostAnimateControlsDisableColorList) $w.f_opt.f_anim.f.f.cb
    lappend GidPriv(PostAnimateControlsDisableList) $w.f_opt.f_anim.f.f.mb
    lappend GidPriv(PostAnimateControlsDisableColorList) $w.f_opt.f_anim.f.f.l
    lappend GidPriv(PostAnimateControlsDisableList) $w.f_opt.f_anim.f.b
    lappend GidPriv(PostAnimateControlsDisableList) $w.f_opt.f_anim.e

    grid columnconf $w.f_opt.f_anim 0 -weight 1 
    grid rowconf $w.f_opt.f_anim 0 -weight 1 
    grid rowconf $w.f_opt.f_anim 1 -weight 1 

    GiDPopUpHelp $w.f_opt.f_del "With this option a DelayTime of the entered milliseconds will be used between "\
	    "frames."

    GiDPopUpHelp $w.f_opt.f_anim "Here the name of the animation file must be entered."
    GiDPopUpHelp $w.f_opt.f_anim.f.f.mb "Choose the file format of the animation file."
    GiDPopUpHelp $w.f_opt.f_anim.f.b "A file browser will be openned, so a file can be selected."

    grid $w.f_opt.f_anim -sticky ew
    grid $w.f_opt.f_del -sticky we
    grid columnconf $w.f_opt 0 -weight 1 
    grid rowconf $w.f_opt 0 -weight 1 
    grid rowconf $w.f_opt 1 -weight 1 

    checkbutton $w.f_opt.cb_redraw -text [_ "Save redraws"] -variable GidPriv(PostAnimateControlsSaveRedraws)
    grid $w.f_opt.cb_redraw -sticky ew
    GiDPopUpHelp $w.f_opt.cb_redraw "Check this option if you want to save each redraw into the animation file.\n"\
	    "GiD will start saving redraws into the file after clicking the AddSet button in this windows."

    grid rowconf $w.f_opt 2 -weight 1 

    lappend GidPriv(PostAnimateControlsDisableList) $w.f_opt.cb_redraw

    frame $w.f_opt.f_siz -relief sunken -bd 1
    menubutton $w.f_opt.f_siz.mb -menu $w.f_opt.f_siz.mb.m -textvariable GidPriv(PostAnimateControlsResize) \
	     -relief raised -bd 1 -width 9 -highlightthickness 1
    menu $w.f_opt.f_siz.mb.m -tearoff 0 -bd 1 -activeborderwidth 1
    $w.f_opt.f_siz.mb.m add command -label [_ "Default"] -command {set GidPriv(PostAnimateControlsResize) Default}
    $w.f_opt.f_siz.mb.m add command -label [_ "800x600"] -command {set GidPriv(PostAnimateControlsResize) 800x600}
    $w.f_opt.f_siz.mb.m add command -label [_ "720x576"] -command {set GidPriv(PostAnimateControlsResize) 720x576}
    $w.f_opt.f_siz.mb.m add command -label [_ "640x480"] -command {set GidPriv(PostAnimateControlsResize) 640x480}
    $w.f_opt.f_siz.mb.m add command -label [_ "512x384"] -command {set GidPriv(PostAnimateControlsResize) 512x384}
    #$w.f_opt.f_siz.mb.m add command -label [_ "352x288 (VCD-PAL)"] -command {set GidPriv(PostAnimateControlsResize) 352x288}
    $w.f_opt.f_siz.mb.m add command -label [_ "352x288"] -command {set GidPriv(PostAnimateControlsResize) 352x288}
    #$w.f_opt.f_siz.mb.m add command -label [_ "352x240 (VCD-NTSC)"] -command {set GidPriv(PostAnimateControlsResize) 352x240}
    $w.f_opt.f_siz.mb.m add command -label [_ "320x240"] -command {set GidPriv(PostAnimateControlsResize) 320x240}

    button $w.f_opt.f_siz.resize -text [_ "Resize"] -command PostAnimateControlsResize -bd 1

    grid $w.f_opt.f_siz.mb $w.f_opt.f_siz.resize 

    grid $w.f_opt.f_siz
    GiDPopUpHelp $w.f_opt.f_siz "For MPEG files on windows its recommended \n"\
	    "to choose a windows-standard frame size:\n" \
	    "320x240 / 352x288 / 512x384 / 640x480 / 720x576 or 800x600"

    lappend GidPriv(PostAnimateControlsDisableList) $w.f_opt.f_siz.mb
    lappend GidPriv(PostAnimateControlsDisableList) $w.f_opt.f_siz.resize

    # close
    frame $w.f_but -bd 0 -background [ CCColorActivo $color_fondo]
    #frame $w.f_but.siz -relief sunken -bd 1
    # 768x576 640x480 512x384 320x240

    #set menu [eval [ concat tk_optionMenu $w.f_but.siz.mb GidPriv(PostAnimateControlsResize) \
    #	     "Default" 720x576 640x480 512x384 320x240]]
    #$w.f_but.siz.mb conf -width 9 -bd 1 -highlightthickness 1
    #$menu conf -bd 1 -activeborderwidth 1

    # menubutton $w.f_but.siz.mb -menu $w.f_but.siz.mb.m -textvariable GidPriv(PostAnimateControlsResize) \
    # 	       -relief raised -bd 1 -width 9 -highlightthickness 1
    # menu $w.f_but.siz.mb.m -tearoff 0 -bd 1 -activeborderwidth 1
    # $w.f_but.siz.mb.m add command -label [_ "Default"] -command {set GidPriv(PostAnimateControlsResize) Default}
    # $w.f_but.siz.mb.m add command -label [_ "720x576"] -command {set GidPriv(PostAnimateControlsResize) 720x576}
    # $w.f_but.siz.mb.m add command -label [_ "640x480"] -command {set GidPriv(PostAnimateControlsResize) 640x480}
    # $w.f_but.siz.mb.m add command -label [_ "512x384"] -command {set GidPriv(PostAnimateControlsResize) 512x384}
    # $w.f_but.siz.mb.m add command -label [_ "320x240"] -command {set GidPriv(PostAnimateControlsResize) 320x240}
    # $w.f_but.siz.mb.m add command -label [_ "800x600"] -command {set GidPriv(PostAnimateControlsResize) 320x240}
    # 
    # button $w.f_but.siz.resize -text [_ "Resize"] -command PostAnimateControlsResize -bd 1
    # 
    # grid $w.f_but.siz.mb $w.f_but.siz.resize 
    
    label $w.f_but.file_size -fg grey60 -textvariable GidPriv(PostAnimateControlsFileSize) -font SmallFont \
	     -background [ CCColorActivo $color_fondo]
    set GidPriv(PostAnimateControlsFileSizeLabel) $w.f_but.file_size
    button $w.f_but.close -text [_ "Close"] -command "PostAnimateControlsFin $w" -bd 1
    #grid $w.f_but.siz -sticky w -ipady 1 -pady 1 -ipadx 1 -padx 1
    grid $w.f_but.file_size $w.f_but.close -sticky wes  -pady 10 -padx 4
    #grid rowconf $w.f_but 0 -weight 1
    #grid rowconf $w.f_but 1 -weight 1
    #grid columnconf $w.f_but 0 -weight 1
    #grid columnconf $w.f_but 1 -weight 1
    
    lappend GidPriv(PostAnimateControlsDisableList) $w.f_but.close

    frame $w.f_ctr -relief ridge -bd 2
    frame $w.f_ctr.f2
    if { ![ info exists GidPriv(PostAnimateControlsAddStepImg)] } {
	set GidPriv(PostAnimateControlsAddStepImg) [image create photo -file $GIDDEFAULT/bitmaps/AddStep.gif ]
    }
    button $w.f_ctr.f2.add -image $GidPriv(PostAnimateControlsAddStepImg) \
	    -command "PostAnimateControlsAddStep $w.f_ctr.f2.add" -bd 1
    if { ![ info exists GidPriv(PostAnimateControlsEndImg)] } {
	set GidPriv(PostAnimateControlsEndImg) [image create photo -file $GIDDEFAULT/bitmaps/EndAnim.gif ]
    }
    button $w.f_ctr.f2.end -image $GidPriv(PostAnimateControlsEndImg) \
	    -command "PostAnimateControlsEndAnim $w.f_ctr.f2.end" -bd 1

    set GidPriv(PostAnimateControlsMPEGCanvas) $w.f_ctr.f2.cv
    canvas $w.f_ctr.f2.cv -width 52 -height 26
    set led_libre [ $w.f_ctr.f2.cv create oval 2 2 25 25 -fill grey60]
    set led_ocupado [ $w.f_ctr.f2.cv create oval 28 2 51 25 -fill grey60]
    set GidPriv(PostAnimateControlsMPEG_led_libre) $led_libre
    set GidPriv(PostAnimateControlsMPEG_led_ocupado) $led_ocupado
    PostAnimateControlsMPEGLeds DISABLED

    grid $w.f_ctr.f2.add $w.f_ctr.f2.end $w.f_ctr.f2.cv -ipadx 2 -ipady 2 -padx 2 -pady 2 -sticky we

    GiDPopUpHelp $w.f_ctr.f2.add \
	    "AddSet button: Adds a frame \n"\
	    "into the animation file.\n"\
	    "If the 'Save redraws' checkbox \n"\
	    "is checked, pressing this button \n"\
	    "starts saving redraws into the file."

    GiDPopUpHelp $w.f_ctr.f2.end \
	    "EndAnimation button: Ends and \n"\
	    "closes the animation file.\n"

    GiDPopUpHelp $w.f_ctr.f2.cv 7000 "Animation status leds:\n"\
	    "Green: no animation is being done, \n"\
	    "       the animation file is closed.\n"\
	    "Red:   GiD is storing frames ( added \n"\
	    "       by the user, or storing redraws)\n"\
	    "       in an opened animation file."

    grid $w.f_ctr.f2

    grid $w.f_opt -sticky news
    grid $w.f_ctr -sticky ew
    grid $w.f_but -sticky ews
    
    grid rowconf $w 0 -weight 1
    grid rowconf $w 1 -weight 1
    grid rowconf $w 2 -weight 1
    grid columnconf $w 0 -weight 1

    set GidPriv(PostAnimateControlsInitializing) 1
    update 
    set GidPriv(PostAnimateControlsInitializing) 0
    catch {
	trace variable GidPriv(PostAnimateControlsDelay) w PostAnimateControlsTogleDelayEntry
	trace variable GidPriv(PostAnimateControlsDelayTime) w PostAnimateControlsCheckDelayTime
	trace variable GidPriv(PostAnimateControlsSaveAnimation) w PostAnimateControlsTogleAnimEntry
    }

    set GidPriv(PostAnimateControlsDelay) 1

    # no hay checkbox
    set GidPriv(PostAnimateControlsSaveAnimation) 1

}

