

proc onv3LsDynaVarsDEZLoad {} {
   global lsdyna_vars

   aie_update_lsdyna_vars setup
   aie_update_lsdyna_vars current

   update idletasks
}


proc aie_update_lsdyna_vars {what args} {
   global lsdyna_vars

   switch -- $what {
      setup {
         if ![info exist lsdyna_vars(setupped)] {

            foreach c {s v} {
               set lsdyna_vars(${c}v_classes) \
                       [V3_variables_get lsdyna_classes $c]
            }

            set lsdyna_vars(setupped) 1
         }
      }
      current {
         aie_update_lsdyna_vars setup

         set lsdyna_vars(class_s) [V3_variables_get lsdyna_current class_s]
         set lsdyna_vars(sv_bname) [V3_variables_get lsdyna_current sv_bname]

         set K $lsdyna_vars(class_s)
         set svlist [V3_variables_get lsdyna_$K s]
         v3LsDynaVarsDEZ set v3pLsDynaSVarList $svlist
         v3LsDynaVarsDEZ set v3pLsDynaSVarCur $lsdyna_vars(sv_bname)

         set lsdyna_vars(sv_min) [V3_variables_get lsdyna_current sv_min]
         set lsdyna_vars(sv_max) [V3_variables_get lsdyna_current sv_max]

         set vvlist [V3_variables_get lsdyna_$K v]
         v3LsDynaVarsDEZ set v3pLsDynaVVarList $vvlist
         if {$vvlist != ""} {
            set lsdyna_vars(class_v) [V3_variables_get lsdyna_current class_v]
            set lsdyna_vars(vv_bname) [V3_variables_get lsdyna_current vv_bname]
            v3LsDynaVarsDEZ set v3pLsDynaVVarCur  $lsdyna_vars(vv_bname)
            ::AIEnv::GUIManagement::ToggleGrey v3LsDynaVVarFm 0
         } else {
            v3LsDynaVarsDEZ set v3pLsDynaVVarCur  ""
            ::AIEnv::GUIManagement::ToggleGrey v3LsDynaVVarFm 1
         }

         set lsdyna_vars(vmax) [V3_variables_get lsdyna_current vmax]
      }
      class {
         set K $lsdyna_vars(class_s)

         set sslist [V3_variables_get lsdyna_$K s]
         set js [lsearch $sslist $lsdyna_vars(sv_bname)]
         
         v3LsDynaVarsDEZ set v3pLsDynaSVarList $sslist

         set vvlist [V3_variables_get lsdyna_$K v]
         if {$vvlist != ""} {
            v3LsDynaVarsDEZ set v3pLsDynaVVarList $vvlist
            V3_lsdyna_variable select_class v $lsdyna_vars(class_s)
            ::AIEnv::GUIManagement::ToggleGrey v3LsDynaVVarFm 0
         } else {
            v3LsDynaVarsDEZ set v3pLsDynaVVarList ""
            ::AIEnv::GUIManagement::ToggleGrey v3LsDynaVVarFm 1
         } 
         V3_lsdyna_variable select_class s $lsdyna_vars(class_s)

         aie_update_lsdyna_vars current
      }
   }
}

proc onV3LsDynaSVarModify {args} {
   global lsdyna_vars
   set K $lsdyna_vars(class_s)
 
   V3_lsdyna_variable select_$K s \
             [v3LsDynaVarsDEZ get v3pLsDynaSVarCur] [lindex $args 1]
   update idletasks

   set lsdyna_vars(sv_min) [V3_variables_get lsdyna_current sv_min]
   set lsdyna_vars(sv_max) [V3_variables_get lsdyna_current sv_max]
}

proc onV3LsDynaVVarModify {args} {
   global lsdyna_vars
   set K $lsdyna_vars(class_s)

   V3_lsdyna_variable select_$K v  \
                 [v3LsDynaVarsDEZ get v3pLsDynaVVarCur] [lindex $args 1]

   set lsdyna_vars(vmax) [V3_variables_get lsdyna_current vmax]
}


proc onv3LsDynaXYpDEZload {} {
   global lsdyna_vars

   set lsdyna_vars(xypfiles) [V3_variables_get lsdyna_xypfiles]

   set no_plot 1
   if {$lsdyna_vars(xypfiles) == ""} {
      set lsdyna_vars(xypfile) ""
      v3LsDynaXYpDEZ set v3LsDynaXYpList ""
   } elseif [info exist lsdyna_vars(xypfile)] {
      if {[lsearch $lsdyna_vars(xypfiles) $lsdyna_vars(xypfile)] > -1} {
         aie_update_lsdyna_xyp file
         set no_plot 0
      }
   }

   if {$no_plot} { ::AIEnv::GUIManagement::ToggleGrey v3LsDynaXYplot 1 }

   if {![info exist lsdyna_vars(xypwin)] || \
             ($lsdyna_vars(xypwin) == "")} {
      set lsdyna_vars(xypwin) old
   }
}

proc onv3LsDynaXYpDEZApply {} {
   set p [v3LsDynaXYpDEZ get v3LsDynaXYpWhat]
   if {($::lsdyna_vars(xypfile) != "") && ($p != "")} {
      aie_update_lsdyna_xyp plot $p
   }
}

proc onV3LsDynaXYplotModify {args} {
   if {$::lsdyna_vars(xypfile) != ""} {
      aie_update_lsdyna_xyp plot [lindex $args 1]

      ::AIEnv::GUIManagement::DEZ::SetClean v3LsDynaXYpDEZ
   }
}

proc aie_update_lsdyna_xyp {what args} {
   global lsdyna_vars

   switch -- $what {
      file {
         set L $lsdyna_vars(xypfile)
         v3LsDynaXYpDEZ set v3LsDynaXYpWhat ""
         v3LsDynaXYpDEZ set v3LsDynaXYpList [V3_lsdyna_variable select_$L load]

         ::AIEnv::GUIManagement::ToggleGrey v3LsDynaXYplot 0
      }
      win {
      }
      plot {
         set L $lsdyna_vars(xypfile)
         set lsdyna_vars(xypwin) [v3LsDynaXYpDEZ get lsdyna_vars:xypwin]
         V3_lsdyna_variable select_$L $lsdyna_vars(xypwin) [lindex $args 0]
      }
   }
}
