#!/bin/sh
#PostGeom -*- TCL -*- Created: ramsan&miguel Jan-1997, Modified: ramsan Jan-1997


#----------------------PostGeom ALONE---------------------------
# the next line restarts using wish \
	exec wish4.2 "$0" "$@"

# set PGRunningAlone 0
# if { ![info exists GIDDEFAULT] } {
#     set PGRunningAlone 1
#     set tcl_interactive 0
#     set tk_strictMotif 1

#     if { [catch { set GIDDEFAULT $env(GIDDEFAULT)}]!=1 } {
# 	set GIDDEFAULTTCL $GIDDEFAULT
# 	catch { set GIDDEFAULTTCL $env(GIDDEFAULTTCL) }
# 	set auto_path "$GIDDEFAULTTCL"
# 	source $GIDDEFAULTTCL/init.tcl
# 	source $GIDDEFAULTTCL/tk.tcl
#     }
# 	wm withdraw .
# }

#  LOOK AT THE END OF THE FILE !!!
#-------------------------------------------------------------------


proc FillPGInfo {} {
    global GidPriv

    if { ![info exists GidPriv(PostGeomWindow)] || \
	    ![winfo exists $GidPriv(PostGeomWindow)] } { return }

    set ret [ catch { set w $GidPriv(PostGeomWindow) } ]
    if { $ret != 0} { return }
    if { $GidPriv(PostGeomDoingAccept) } { return }

    #puts FillPGInfo2-----------------------------
    set mainst [.central.s info post get main_geom_state]
    switch $mainst {
	"Original" {
	    $w.maing.e2 del 0 end 
	    $w.maing.e2 conf -state disabled
	    set GidPriv(PostGeomMainHow) Original
	}
	"Deformed" {
	    $w.maing.e2 conf -state normal
	    $w.maing.e2 del 0 end
	    set GidPriv(PostGeomMainFact) ""
#[.central.s info post get main_geom_factor]
#	    $w.maing.e2 ins end $GidPriv(PostGeomMainFact)
	    focus $w.maing.e2
	    set GidPriv(PostGeomMainHow) Deformation
	}   
    }

    set all [.central.s info post get all_analisis]
    $w.maing.m1.menu del 0 end
    foreach j $all {
	regsub -all {_} $j { } var
	$w.maing.m1.menu add command -label $var -command \
		[list set GidPriv(PostGeomMainAnal) $var]
    }

    set cur [.central.s info post get cur_analisis]
    if { $cur != "" } {
	regsub -all {_} $cur { } cur
    } else { regsub -all {_} [ lindex $all 0] { } cur }

    set GidPriv(PostGeomMainAnal) $cur
    if { $cur != "" } {
	set GidPriv(PostGeomMainStep) [.central.s info post get cur_step $cur]
    }

    regsub -all { } $GidPriv(PostGeomMainAnal) {_} res_anal
    set all [.central.s info post get main_geom_all_deform $res_anal \
	    $GidPriv(PostGeomMainStep) ]


    set all [.central.s info post get main_geom_all_deform]
    $w.maing.m2.menu del 0 end
    foreach j $all {
	regsub -all {_} $j { } var
	$w.maing.m2.menu add command -label $var -command \
		[list set GidPriv(PostGeomMainDefor) $var]
    }
    #if { $mainst == "Deformation"} {
	set var [ .central.s info post get main_geom_cur_deform]
	if { $var == ""} { set var [ lindex $all 0] }
	regsub -all {_} $var { } var
	set GidPriv(PostGeomMainDefor) $var
    #}
    if { ( $GidPriv(PostGeomMainDefor) != "") && ( $GidPriv(PostGeomMainAnal) != "") && \
	    ( $GidPriv(PostGeomMainStep) != "") } {
	regsub -all { } $GidPriv(PostGeomMainDefor) {_} def_vec
	regsub -all { } $GidPriv(PostGeomMainAnal) {_} res_anal
	set GidPriv(PostGeomMainFact) [.central.s info post get main_geom_factor $res_anal\
		$GidPriv(PostGeomMainStep) $def_vec]
    } else {
	set GidPriv(PostGeomMainFact) 1
    }

    set all [.central.s info post get all_analisis]
    $w.showg.m1.menu del 0 end
    foreach j $all {
	regsub -all {_} $j { } var
	$w.showg.m1.menu add command -label $var -command \
		[list set GidPriv(PostGeomShowAnal) $var]
    }

    set cur [.central.s info post get show_geom_cur_analisis]
    if { $cur != "" } {
	regsub -all {_} $cur { } cur
    } else { regsub -all {_} [ lindex $all 0] { } cur }

    set GidPriv(PostGeomShowAnal) $cur
    if { $cur != "" } {
	set GidPriv(PostGeomShowStep) [.central.s info post get show_geom_cur_step]
    }

    set showst [.central.s info post get show_geom_state]
    switch $showst {
	"Off" {
	    $w.showg.e1 del 0 end 
	    $w.showg.e1 conf -state disabled
	    $w.showg.e1 conf -fg grey60
	    $w.showg.e2 del 0 end 
	    $w.showg.e2 conf -state disabled
	    $w.showg.e2 conf -fg grey60
	    set GidPriv(PostGeomShowHow) Off
	}
	"Original" {
	    $w.showg.e1 del 0 end 
	    $w.showg.e1 conf -state disabled
	    $w.showg.e1 conf -fg grey60
	    $w.showg.e2 del 0 end 
	    $w.showg.e2 conf -state disabled
	    $w.showg.e2 conf -fg grey60
	    set GidPriv(PostGeomShowHow) Original
	}
	"Deformed" {
	    $w.showg.e1 conf -state normal
	    $w.showg.e1 conf -fg black
	    $w.showg.e1 del 0 end
	    $w.showg.e2 conf -state normal
	    $w.showg.e2 conf -fg black
	    $w.showg.e2 del 0 end
# 	    regsub -all { } $GidPriv(PostGeomShowDefor) {_} def_vec
# 	    regsub -all { } $GidPriv(PostGeomShowAnal) {_} res_anal
# 	    set GidPriv(PostGeomShowFact) [.central.s info post get show_geom_factor $res_anal\
# 		    $GidPriv(PostGeomShowStep) $def_vec]
	    $w.showg.e2 ins end $GidPriv(PostGeomShowFact)
	    set GidPriv(PostGeomShowHow) Deformation

	}   
    }
    regsub -all { } $GidPriv(PostGeomShowAnal) {_} res_anal
    set all [.central.s info post get show_geom_all_deform $res_anal \
	    $GidPriv(PostGeomShowStep) ]

    $w.showg.m2.menu del 0 end
    foreach j $all {
	regsub -all {_} $j { } var
	$w.showg.m2.menu add command -label $var -command \
		[list set GidPriv(PostGeomShowDefor) $var]
    }
    #if { $showst == "Deformation"} {
	set var [ .central.s info post get show_geom_cur_deform]
	if { $var == ""} { set var [ lindex $all 0] }
	regsub -all {_} $var { } var
	set GidPriv(PostGeomShowDefor) $var
    #}    
    if { ( $GidPriv(PostGeomShowDefor) != "") && ( $GidPriv(PostGeomShowAnal) != "") && \
	    ( $GidPriv(PostGeomShowStep) != "") } {
	regsub -all { } $GidPriv(PostGeomShowDefor) {_} def_vec
	regsub -all { } $GidPriv(PostGeomShowAnal) {_} res_anal 
	set GidPriv(PostGeomShowFact) [.central.s info post get show_geom_factor $res_anal\
		$GidPriv(PostGeomShowStep) $def_vec]
    }

    set res [ .central.s info post get show_geom_color]

    set GidPriv(PostGeomColorCopia) [ lindex $res 0]
    $GidPriv(PostGeomColorBoton) conf -bg [ lindex $res 1]
    if { "$res" == "UserColor"} {
	$GidPriv(PostGeomColorBoton) conf -state normal
    } else {
	$GidPriv(PostGeomColorBoton) conf -state disabled
    }
}

proc FillMainEntry {name1 name2 op} {
    global GidPriv

    set w $GidPriv(PostGeomWindow)
    regsub -all { } $GidPriv(PostGeomMainDefor) {_} def_vec
    regsub -all { } $GidPriv(PostGeomMainAnal) {_} res_anal
    if { ( $res_anal != "") && ( $GidPriv(PostGeomMainStep) != "") && ( $def_vec != "")} {
	set GidPriv(PostGeomMainFact) [.central.s info post get main_geom_factor \
		$res_anal $GidPriv(PostGeomMainStep) $def_vec]
    } else {
	set GidPriv(PostGeomMainFact) 1
    }
}

proc FillShowEntry {name1 name2 op} {
    global GidPriv

    set w $GidPriv(PostGeomWindow)
    regsub -all { } $GidPriv(PostGeomShowDefor) {_} def_vec
    regsub -all { } $GidPriv(PostGeomShowAnal) {_} res_anal
    if { ( $res_anal != "") && ( $GidPriv(PostGeomShowStep) != "") && ( $def_vec != "")} {
	set GidPriv(PostGeomShowFact) [.central.s info post get show_geom_factor \
		$res_anal $GidPriv(PostGeomShowStep) $def_vec]
    } else {
	set GidPriv(PostGeomShowFact) 1
    }
}

proc FillPGMainSteps {name1 name2 op} {
    global GidPriv

    #puts FillPGMainSteps-----------------------------
    set w $GidPriv(PostGeomWindow)
    regsub -all { } $GidPriv(PostGeomMainAnal) {_} analisis
    $w.maing.ll.list del 0 end
    if { $analisis != ""} {
	set current [.central.s info post get cur_step $analisis]
	set currentidx 0
	set all_st [.central.s info post get all_steps $analisis]
	if { $current == "" } { set current [ lindex $all_st 0] }
	foreach i $all_st {
	    $w.maing.ll.list ins end $i
	    if { $i == $current } {
		$w.maing.ll.list sel set end
		set currentidx [$w.maing.ll.list index end]
	    }
	}
	if { $GidPriv(PostGeomMainHow) == "Deformation" } {
	    $w.maing.ll.list see $currentidx
	    $w.maing.e1 del 0 end
	    $w.maing.e1 ins end $current
	    focus $w.maing.e1
	} else {
	    $w.maing.e1 del 0 end
	    $w.maing.e1 ins end $current
	}
    } else {
	$w.maing.e1 del 0 end
	$w.maing.e1 conf -state disabled
    }
}

proc FillPGShowSteps {name1 name2 op} {
    global GidPriv

    #puts FillPGShowSteps-----------------------------
    set w $GidPriv(PostGeomWindow)
    regsub -all { } $GidPriv(PostGeomShowAnal) {_} analisis
    $w.showg.ll.list del 0 end
    if { $analisis != ""} {
	set current [.central.s info post get show_geom_cur_step]
	set currentidx 0
	set all_st [.central.s info post get all_steps $analisis]
	if { $current == "" } { set current [ lindex $all_st 0] }
	foreach i $all_st {
	    $w.showg.ll.list ins end $i
	    if { $i == $current } {
		$w.showg.ll.list sel set end
		set currentidx [$w.showg.ll.list index end]
	    }
	}
	if { $GidPriv(PostGeomShowHow) == "Deformation" } {
	    $w.showg.ll.list see $currentidx
	    $w.showg.e1 del 0 end
	    $w.showg.e1 ins end $current
	    focus $w.showg.e1
	} else {
	    $w.showg.e1 del 0 end
	    $w.showg.e1 ins end $current
	}
    } else {
	$w.showg.e1 del 0 end
	$w.showg.e1 conf -state disabled
    }
}

proc PGMainChangedEntry {name1 name2 op} {
    global GidPriv
    set w $GidPriv(PostGeomWindow)

    #puts PGMainChangedEntry-----------------------------
    set elms [$w.maing.ll.list get 0 end] 
    $w.maing.ll.list sel clear 0 end

    set first [lsearch $elms $GidPriv(PostGeomMainStep)*]
    if { $first != -1 } {
	$w.maing.ll.list see $first
	if { [lsearch [lrange $elms [expr $first+1] end] $GidPriv(PostGeomMainStep)*] == -1 } {
	    $w.maing.ll.list sel set $first
	    $w.maing.ll.list activate $first
	    set GidPriv(PostGeomMainStep) [lindex $elms $first]
	    FillPGMainMenus 
	    return
	}
    } else {
	bell
	set GidPriv(PostGeomMainStep) [string range $GidPriv(PostGeomMainStep) \
		0 [$w.maing.e1 index insert]]
	set GidPriv(PostGeomMainStep) [string range $GidPriv(PostGeomMainStep) \
		0 [expr [string length $GidPriv(PostGeomMainStep)] -2]  ]
    }
    $w.maing.ll.list sel clear 0 end
}

proc PGShowChangedEntry {name1 name2 op} {
    global GidPriv
    set w $GidPriv(PostGeomWindow)

    #puts PGShowChangedEntry-----------------------------
    set elms [$w.showg.ll.list get 0 end] 
    $w.showg.ll.list sel clear 0 end

    set first [lsearch $elms $GidPriv(PostGeomShowStep)*]
    if { $first != -1 } {
	$w.showg.ll.list see $first
	if { [lsearch [lrange $elms [expr $first+1] end] $GidPriv(PostGeomShowStep)*] == -1 } {
	    $w.showg.ll.list sel set $first
	    $w.showg.ll.list activate $first
	    set GidPriv(PostGeomShowStep) [lindex $elms $first]
	    FillPGShowMenus 
	    return
	}
    } else {
	bell
	set GidPriv(PostGeomShowStep) [string range $GidPriv(PostGeomShowStep) \
		0 [$w.showg.e1 index insert]]
	set GidPriv(PostGeomShowStep) [string range $GidPriv(PostGeomShowStep) \
		0 [expr [string length $GidPriv(PostGeomShowStep)] -2]  ]
    }
    $w.showg.ll.list sel clear 0 end
}

proc PGShowListboxToEntry {} {
    global GidPriv

    #puts PGShowListboxToEntry-----------------------------
    set w $GidPriv(PostGeomWindow)
    if { $GidPriv(PostGeomShowAnal) != "" } {
	set GidPriv(PostGeomShowStep) [$w.showg.ll.list get [$w.showg.ll.list curselection]] 
	if { $GidPriv(PostGeomShowHow) == "Deformation" } {
	    focus $w.showg.e1
	}
	FillPGShowMenus 
	#FillShowEntry "" "" ""
    }
}

proc PGMainListboxToEntry {} {
    global GidPriv

    #puts PGMainListboxToEntry-----------------------------
    set w $GidPriv(PostGeomWindow)
    if { $GidPriv(PostGeomMainAnal) != "" } {
	set GidPriv(PostGeomMainStep) [$w.maing.ll.list get [$w.maing.ll.list curselection]] 
	if { $GidPriv(PostGeomMainHow) == "Deformation" } {
	    focus $w.maing.e1
	}
	FillPGMainMenus 
    }
}

proc setPGMainToOriginal { } {
    global GidPriv
    set w $GidPriv(PostGeomWindow)

    #puts setPGMainToOriginal-----------------------------
    #$w.maing.e2 del 0 end 
    $w.maing.e2 conf -state disabled
    $w.maing.e2 conf -fg grey60
}

proc setPGMainToDeformation { } {
    global GidPriv
    set w $GidPriv(PostGeomWindow)

    #puts setPGMainToDeformation-----------------------------
    $w.maing.e2 conf -state normal
    $w.maing.e2 conf -fg black
    focus $w.maing.e2
#    $w.maing.e2 ins end $GidPriv(PostGeomMainFact)
    set all [.central.s info post get main_geom_all_deform ]
    if { $GidPriv(PostGeomMainDefor) == ""} {
	regsub -all {_} [ lindex [.central.s info post get main_geom_all_deform] 0] \
		{ } GidPriv(PostGeomMainDefor)
    }
}

proc FillPGMainMenus { } {
    global GidPriv

    #puts FillPGMainMenus-----------------------------
    set w $GidPriv(PostGeomWindow)

    if { $GidPriv(PostGeomMainHow) == "Deformation" } {
	$w.maing.e2 del 0 end
	$w.maing.e2 ins end $GidPriv(PostGeomMainFact)
	focus $w.maing.e2
    } else {
	$w.maing.e2 del 0 end
	$w.maing.e2 ins end $GidPriv(PostGeomMainFact)
    }
    regsub -all { } $GidPriv(PostGeomMainAnal) {_} res_anal
    # son los mismos para "show geom" que para "main geom"
    set all [.central.s info post get show_geom_all_deform $res_anal \
	    $GidPriv(PostGeomMainStep) ]
    $w.maing.m2.menu del 0 end
    foreach j $all {
	regsub -all {_} $j { } var
	$w.maing.m2.menu add command -label $var -command \
		[list set GidPriv(PostGeomMainDefor) $var]
    }
    regsub -all { } $GidPriv(PostGeomMainDefor) {_} res_res
    if { $res_res == "" } {
	regsub -all {_} [ lindex $all 0] { } var
    } else { 
	if { [ lsearch $all $res_res] == -1 } {
	    regsub -all {_} [ lindex $all 0] { } var
	} else { 
	    regsub -all {_} [ lindex $all 0] { } var
	}
    }
    set GidPriv(PostGeomMainDefor) $var
}

proc FillPGShowMenus { } {
    global GidPriv

    #puts FillPGShowMenus-----------------------------
    set w $GidPriv(PostGeomWindow)

    if { $GidPriv(PostGeomShowHow) == "Deformation" } {
	$w.showg.e2 del 0 end
	$w.showg.e2 ins end $GidPriv(PostGeomShowFact)
	focus $w.showg.e2
    } else {
	$w.showg.e2 del 0 end
	$w.showg.e2 ins end $GidPriv(PostGeomShowFact)
    }
    regsub -all { } $GidPriv(PostGeomShowAnal) {_} res_anal
    set all [.central.s info post get show_geom_all_deform $res_anal \
	    $GidPriv(PostGeomShowStep) ]
    #set all [.central.s info post get main_geom_all_deform]
    $w.showg.m2.menu del 0 end
    foreach j $all {
	regsub -all {_} $j { } var
	$w.showg.m2.menu add command -label $var -command \
		[list set GidPriv(PostGeomShowDefor) $var]
    }
    regsub -all { } $GidPriv(PostGeomShowDefor) {_} res_res
    if { $res_res == "" } {
	regsub -all {_} [ lindex $all 0] { } var
    } else { 
	if { [ lsearch $all $res_res] == -1 } {
	    regsub -all {_} [ lindex $all 0] { } var
	} else { 
	    regsub -all {_} [ lindex $all 0] { } var
	}
    }
    set GidPriv(PostGeomShowDefor) $var
}

proc setPGShowToOff { } {
    global GidPriv
    set w $GidPriv(PostGeomWindow)

    #puts setPGShowToOff-----------------------------
    #$w.showg.e1 del 0 end 
    $w.showg.e1 conf -state disabled
    $w.showg.e1 conf -fg grey60
    #$w.showg.e2 del 0 end 
    $w.showg.e2 conf -state disabled
    $w.showg.e2 conf -fg grey60
}

proc setPGShowToOriginal { } {
    global GidPriv

    #puts setPGShowToOriginal-----------------------------
    set w $GidPriv(PostGeomWindow)
    #$w.showg.e1 del 0 end 
    $w.showg.e1 conf -state disabled
    $w.showg.e1 conf -fg grey60
    #$w.showg.e2 del 0 end 
    $w.showg.e2 conf -state disabled
    $w.showg.e2 conf -fg grey60
}

proc setPGShowToDeformation { } {
    global GidPriv

    #puts setPGShowToDeformation-----------------------------
    set w $GidPriv(PostGeomWindow)
    $w.showg.e1 conf -state normal
    #$w.showg.e1 del 0 end
    $w.showg.e1 conf -fg black
#    $w.showg.e1 ins end [.central.s info post get show_geom_factor]
    $w.showg.e2 conf -state normal
    #$w.showg.e2 del 0 end
    $w.showg.e2 conf -fg black
    regsub -all { } $GidPriv(PostGeomShowDefor) {_} def_vec
    regsub -all { } $GidPriv(PostGeomShowAnal) {_} res_anal
    if { ( $res_anal != "") && ( $GidPriv(PostGeomShowStep) != "") && ( $def_vec != "")} {
	set kk [.central.s info post get show_geom_factor \
		$res_anal $GidPriv(PostGeomShowStep) $def_vec]
    } else {
	set kk 1
    }
#    set kk [.central.s info post get show_geom_factor]
#     if { $kk != 0 } { set GidPriv(ShowGeomShowFact) $kk }
#     if { [ info exist GidPriv(ShowGeomShowFact) ] } {
# 	$w.showg.e2 ins end $GidPriv(ShowGeomShowFact)
# 	focus $w.showg.e1
# 	focus $w.showg.e2
#    }
}

proc PGAccept { } {
    global GidPriv

    #puts PGAccept-----------------------------
    set oldAutomaticRedraw [.central.s info variables AutomaticRedraw]
    .central.s process escape escape escape escape utilities variables \
	    AutomaticRedraw -1 escape escape 

    set mainst [.central.s info post get main_geom_state]
    set GidPriv(PostGeomDoingAccept) 1
    switch $mainst {
	"Original" {
	    if { $GidPriv(PostGeomMainHow) == "Deformation" } {
		regsub -all { } $GidPriv(PostGeomMainDefor) {_} var
		regsub -all { } $GidPriv(PostGeomMainAnal) {_} res_anal
		if { ( $var != "") && ( $res_anal != "") && \
			( $GidPriv(PostGeomMainStep) != "")} {
		    .central.s process escape escape escape escape \
			    results AnalysisSel $res_anal $GidPriv(PostGeomMainStep) \
			    geometry deformation $var $GidPriv(PostGeomMainFact) escape 
		}
	    }
	}
	"Deformed" {
	    switch $GidPriv(PostGeomMainHow) {
		"Original" {
		    .central.s process escape escape escape escape \
			    results geometry Original
		}
		"Deformation" {
		    regsub -all { } $GidPriv(PostGeomMainDefor) {_} var
		    regsub -all { } $GidPriv(PostGeomMainAnal) {_} res_anal
		    if { ( $var != "") && ( $res_anal != "") && ( $GidPriv(PostGeomMainStep) != "")} {
			.central.s process escape escape escape escape \
				results AnalysisSel $res_anal \
				$GidPriv(PostGeomMainStep) geometry Original \
				geometry deformation $var $GidPriv(PostGeomMainFact) escape 
		    }
		}
	    }   
	}
    }

    .central.s process escape escape escape escape
    set showst [.central.s info post get show_geom_state]
    switch $showst {
	"Off" {
	    switch $GidPriv(PostGeomShowHow) {
		"Original" {
		.central.s process results geometry showoriginal
		}
		"Deformation" {
		    regsub -all { } $GidPriv(PostGeomShowAnal) {_} anal
		    regsub -all { } $GidPriv(PostGeomShowDefor) {_} var
		    .central.s process results geometry showdeformed $anal \
			    $GidPriv(PostGeomShowStep) $var $GidPriv(PostGeomShowFact) escape
		}
	    }
	}
	"Original" {
	    switch $GidPriv(PostGeomShowHow) {
		"Off" {
		.central.s process results geometry hidetheshow
		} 
		"Deformation" {
		    regsub -all { } $GidPriv(PostGeomShowAnal) {_} anal
		    regsub -all { } $GidPriv(PostGeomShowDefor) {_} var
		    .central.s process results geometry hidetheshow
		    .central.s process geometry showdeformed $anal \
			    $GidPriv(PostGeomShowStep) $var $GidPriv(PostGeomShowFact) escape
		}
	    }
	}
	"Deformed" {
	    switch $GidPriv(PostGeomShowHow) {
		"Off" {
		.central.s process results geometry hidetheshow
		}
		"Original" {
		    .central.s process results geometry hidetheshow
		    .central.s process geometry showoriginal
		} 
		"Deformation" {
		    regsub -all { } $GidPriv(PostGeomShowAnal) {_} anal
		    regsub -all { } $GidPriv(PostGeomShowDefor) {_} var
		    .central.s process results geometry hidetheshow
		    .central.s process geometry showdeformed $anal \
			    $GidPriv(PostGeomShowStep) $var $GidPriv(PostGeomShowFact) escape
		}
	    }

	}
    }

    .central.s process escape escape escape escape utilities variables \
	    AutomaticRedraw $oldAutomaticRedraw escape escape 
#    .central.s makecurrent
#    .central.s process redraw
    .central.s render
    set GidPriv(PostGeomDoingAccept) 0
}

proc CambiaColorCopia { wb} {

    set nuevo [ BWChooseColorMenu $wb.mc [ list below $wb] -color [ $wb cget -bg]]
    if { [ string length $nuevo]} { 
	$wb conf -bg $nuevo
	.central.s process escape escape escape escape results geometry ChangeShowCol DefineColor $nuevo
    }
}


proc PostGeom { { w .wPostGeom } } {
    global GidPriv

    set GidPriv(PostGeomDoingAccept) 0
    #puts PostGeom-----------------------------
    InitWindow $w "Mesh Deformation" PostGeomWindowGeom PostGeom

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

    catch {
	trace vdelete GidPriv(PostGeomMainAnal) w FillPGMainSteps
	trace vdelete GidPriv(PostGeomShowAnal) w FillPGShowSteps
	trace vdelete GidPriv(PostGeomMainStep) w PGMainChangedEntry
	trace vdelete GidPriv(PostGeomShowStep) w PGShowChangedEntry
	trace vdelete GidPriv(PostGeomMainDefor) w FillMainEntry
	trace vdelete GidPriv(PostGeomShowDefor) w FillShowEntry
    }




    frame $w.maing -relief ridge -bd 1
    frame $w.showg -relief ridge -bd 1

    frame $w.maing.f -bd 0
    label $w.maing.f.l1 -text "Main Geometry:" -anchor w
    label $w.maing.f.l11 -text "(where results will be drawn)" -anchor w

    frame $w.maing.f.opt -bd 0
    radiobutton $w.maing.f.opt.orig -text Original -variable GidPriv(PostGeomMainHow) \
	    -value Original -command { setPGMainToOriginal}
    radiobutton $w.maing.f.opt.defo -text Deformation: -variable GidPriv(PostGeomMainHow) \
	    -value Deformation -command { setPGMainToDeformation}
    pack $w.maing.f.opt.orig $w.maing.f.opt.defo -side top -ipady 0 -anchor w
    pack $w.maing.f.l1 $w.maing.f.l11 $w.maing.f.opt -ipady 0 -anchor w -side top -fill x



    label $w.maing.l2 -text Analysis:
    tk_optionMenu $w.maing.m1 GidPriv(PostGeomMainAnal) ""
    $w.maing.m1 conf -width 20 -bd 1 -highlightthickness 1

    frame $w.maing.ll -bd 0
    scrollbar $w.maing.ll.xscroll -relief sunken \
	    -orient horizontal -command "$w.maing.ll.list xview" \
        -bd 1 -elementborderwidth 1
    listbox $w.maing.ll.list -height 3 -xscroll \
	    "$w.maing.ll.xscroll set" -relief sunken \
	    -selectmode browse -width 1 -borderwidth 1
    bind $w.maing.ll.list <ButtonRelease-1> PGMainListboxToEntry
    scrollbar $w.maing.ll.yscroll -relief sunken -command \
	    "$w.maing.ll.list yview" -bd 1 -elementborderwidth 1
    $w.maing.ll.list conf -yscroll "$w.maing.ll.yscroll set"
    pack $w.maing.ll.yscroll -side right -fill y
    pack $w.maing.ll.xscroll -side bottom -fill x
    pack $w.maing.ll.list -fill both -side top -expand yes

    label $w.maing.l3 -text Steps:
    entry $w.maing.e1 -relief sunken -width 10 -textvariable GidPriv(PostGeomMainStep) -bd 1
#    focus $w.maing.e1







    label $w.maing.l4 -text "factor:"
    entry $w.maing.e2 -relief sunken -width 12 -textvariable GidPriv(PostGeomMainFact) -bd 1

    label $w.maing.l5 -text Results:
    tk_optionMenu $w.maing.m2 GidPriv(PostGeomMainDefor) ""
    $w.maing.m2 conf -width 16 -bd 1 -highlightthickness 1



    frame $w.showg.f -bd 0
    label $w.showg.f.l1 -text "Reference Geometry:" -anchor w
    label $w.showg.f.l11 -text "(just for viewing purposes)" -anchor w

    frame $w.showg.f.opt -bd 0
    radiobutton $w.showg.f.opt.off -text Off -variable GidPriv(PostGeomShowHow) \
	    -value Off -command { setPGShowToOff}
    radiobutton $w.showg.f.opt.orig -text Original -variable GidPriv(PostGeomShowHow) \
	    -value Original -command { setPGShowToOriginal}
    radiobutton $w.showg.f.opt.defo -text Deformation: -variable GidPriv(PostGeomShowHow) \
	    -value Deformation -command { setPGShowToDeformation}
    label $w.showg.f.opt.lcol -text "Use color:"
    radiobutton $w.showg.f.opt.rd1 -text "of mesh" -value MeshColor -variable GidPriv(PostGeomColorCopia) \
	    -command "$w.showg.f.opt.bcol conf -state disabled ; .central.s process escape escape escape escape results geometry ChangeShowCol MeshColor"
    radiobutton $w.showg.f.opt.rd2 -value UserColor -variable GidPriv(PostGeomColorCopia) \
	    -command "$w.showg.f.opt.bcol conf -state normal"
    button $w.showg.f.opt.bcol -width 3 -command "CambiaColorCopia $w.showg.f.opt.bcol"
    set GidPriv(PostGeomColorCopia) MeshColor
    set GidPriv(PostGeomColorBoton) $w.showg.f.opt.bcol
    $w.showg.f.opt.bcol conf -state disabled
    #pack $w.showg.f.opt.off $w.showg.f.opt.orig $w.showg.f.opt.defo -side top -ipady 0 -anchor w
    grid $w.showg.f.opt.off -sticky w
    grid $w.showg.f.opt.lcol -row 0 -column 1 -columnspan 2 -sticky e
    grid $w.showg.f.opt.orig -sticky w
    grid $w.showg.f.opt.rd1 -row 1 -column 1 -columnspan 2 -sticky e
    grid $w.showg.f.opt.defo -sticky w
    grid $w.showg.f.opt.rd2 -row 2 -column 1 -sticky e
    grid $w.showg.f.opt.bcol -row 2 -column 2 -sticky e
    pack $w.showg.f.l1 $w.showg.f.l11 $w.showg.f.opt -ipady 0 -anchor w -side top -fill x

    label $w.showg.l2 -text Analysis:
    tk_optionMenu $w.showg.m1 GidPriv(PostGeomShowAnal) ""
    $w.showg.m1 conf -width 20 -bd 1 -highlightthickness 1

    frame $w.showg.ll -bd 0
    scrollbar $w.showg.ll.xscroll -relief sunken \
	    -orient horizontal -command "$w.showg.ll.list xview" \
        -bd 1 -elementborderwidth 1
    listbox $w.showg.ll.list -height 2 -xscroll \
	    "$w.showg.ll.xscroll set" -relief sunken \
	    -selectmode browse -width 1 -borderwidth 1
    bind $w.showg.ll.list <ButtonRelease-1> PGShowListboxToEntry
    scrollbar $w.showg.ll.yscroll -relief sunken -command \
	    "$w.showg.ll.list yview" -bd 1 -elementborderwidth 1
    $w.showg.ll.list conf -yscroll "$w.showg.ll.yscroll set"
    pack $w.showg.ll.yscroll -side right -fill y
    pack $w.showg.ll.xscroll -side bottom -fill x
    pack $w.showg.ll.list -fill both -side top -expand yes

    label $w.showg.l3 -text Steps:
    entry $w.showg.e1 -relief sunken -width 10 -textvariable GidPriv(PostGeomShowStep) -bd 1
#    focus $w.showg.e1


    label $w.showg.l4 -text "factor:"
    entry $w.showg.e2 -relief sunken -width 12 -textvariable GidPriv(PostGeomShowFact) -bd 1

    label $w.showg.l5 -text Results:
    tk_optionMenu $w.showg.m2 GidPriv(PostGeomShowDefor) ""
    $w.showg.m2 conf -width 16 -bd 1 -highlightthickness 1


    frame $w.but -bd 0
    button $w.but.accept -text Apply -command PGAccept -takefocus 0 -bd 1
    button $w.but.close -text Close -command "destroy $w" -takefocus 0 -bd 1

    grid $w.but.accept -sticky e -padx 5 -pady 2
    grid $w.but.close -sticky w -padx 5 -pady 2 -row 0 -column 1

    grid $w.maing.f -sticky w -row 0 -column 1
    grid $w.maing.l2 -sticky e
    grid $w.maing.m1 -sticky w -row 1 -column 1
    grid $w.maing.l3 -sticky en
    grid $w.maing.ll -sticky ewns -row 2 -column 1
    grid $w.maing.e1 -sticky w -row 3 -column 1
    grid $w.maing.l5 -sticky e
    grid $w.maing.m2 -sticky w -row 4 -column 1
    grid $w.maing.l4 -sticky e
    grid $w.maing.e2 -sticky w -row 5 -column 1
    grid $w.maing - -sticky wens
    grid columnconfigure $w.maing 1 -weight 1
    grid rowconfigure $w.maing 2 -weight 1

    grid $w.showg.f -sticky w -row 0 -column 1
    grid $w.showg.l2 -sticky e
    grid $w.showg.m1 -sticky w -row 1 -column 1
    grid $w.showg.l3 -sticky en
    grid $w.showg.ll -sticky ewns -row 2 -column 1
    grid $w.showg.e1 -sticky w -row 3 -column 1
    grid $w.showg.l5 -sticky e
    grid $w.showg.m2 -sticky w -row 4 -column 1
    grid $w.showg.l4 -sticky e
    grid $w.showg.e2 -sticky w -row 5 -column 1
    grid $w.showg - -sticky ewns
    grid columnconfigure $w.showg 1 -weight 1
    grid rowconfigure $w.showg 2 -weight 1


    grid $w.but - 
#    grid columnconfigure $w 0 -weight 1
    grid columnconfigure $w 0 -weight 1
    grid rowconfigure $w 0 -weight 1
    grid columnconfigure $w 0 -weight 1
    grid rowconfigure $w 1 -weight 1

    FillPGInfo

    trace variable GidPriv(PostGeomMainAnal) w FillPGMainSteps
    trace variable GidPriv(PostGeomShowAnal) w FillPGShowSteps
    trace variable GidPriv(PostGeomMainStep) w PGMainChangedEntry
    trace variable GidPriv(PostGeomShowStep) w PGShowChangedEntry
    trace variable GidPriv(PostGeomMainDefor) w FillMainEntry
    trace variable GidPriv(PostGeomShowDefor) w FillShowEntry

    bind $w <Return> PGAccept
    bind $w <Escape> "destroy $w"

}


#----------------------SetCoord ALONE---------------------------
# if { $PGRunningAlone == 1 } {
#     PostGeom .wPostPG
# } 
#-----------------------------------------------------------------
