
# ***** rename this file to aie_replay.tcl after 5.0 ******** FIXME

proc aie_replay_cmd {what args} {
    global replay_recording replay_listbox replay_file replay_dir file_name
    
    switch -- $what {
        form { file_replay }
	    load {
	        file_replay
	        replay_load
	        if [info exists replay_listbox] { wm deiconify .[lindex [split $replay_listbox .] 1] }
	    }
	    run_file {
            set file [tk_getOpenFile \
			  -filetypes {{{Replay Files} {.rpl .jrf .tcl}} {{All Files} *}} \
			  -title "Open Script File" \
			  -parent .  \
			  -initialdir [pwd] \
			  -defaultextension ".rpl"]
	        if {$file == ""} return
	        if [catch {source $file} res] {
                mess $res\n red
                busy reset
	        } else {
                replay_after_commands_done
	        }
	    } 
        run_batch {
            set file $args
	        if {(![file exists $file]) || ($file == "")} return
	        if [catch {source $file} res] {
		        mess $res\n red
		        busy reset
            }
        }  
	    recording {
	        if {$replay_recording} {
		        if {![info exist replay_listbox] || \
			        ![winfo exist $replay_listbox]} {
		            file_replay
		            top_withdraw .[lindex [split $replay_listbox .] 1]
		        }
		        replay_start_recording
	        } else {
		        replay_stop_recording
	        }
	    }
    }
}

proc replay_after_commands_done {} {
    # These are the magical things needed to make stuff show up
    # when replay is done
    global AIEnvProduct batch_mode
    if $batch_mode return

    # temporarily skip these things if tdv_default does not exist
    # but eventually, they should part of a script command in
    # the replay file if they are needed.

    global tdv_default tdv_current_viewer
    if ![winfo exist $tdv_default] {return}
    if {[info exist tdv_current_viewer] && \
        [winfo exist $tdv_current_viewer] && \
         ($tdv_current_viewer != $tdv_default)} {
       return
    }
    
    set ta [tdv_active 0]
    aie_create_initial_assemblies 0 0 0
    aie_initialize_tree_props_and_icons
    aie_init_mesh_subsets
    aie_init_geom_subsets
    aie_updateGeoVis
    aie_updateMeshVis
    aie_getBatchMeshDisplay 0
    aie_after_blocking_loaded 0
    if {$AIEnvProduct == "fea2.0"} {aie_after_load_params}
    aie_clear_dez
    aie_update_icons
    tdv_active $ta
}

