# ============================================================================
#  Copyright 1999 SAS IP, Inc. Proprietary Data.
#  Unauthorized use, distribution, or duplication is prohibited.
#  All Rights Reserved.
# ============================================================================
#  $Revision: 145002 $
#  $Date: 2009-11-13 11:20:27 -0500 (Fri, 13 Nov 2009) $
# ============================================================================
# File Name:     DropTest.eui
# Description:   Drop test module for ANSYS/LSDyna
# ============================================================================


namespace eval euidl::lsdyna::droptest {
   variable dT

   proc create {} {
      variable parent
      variable childsite
      variable tabParent
      variable page1
      variable page2
      variable page3
      variable page4
      variable page5

      variable betaKey

      variable jobname
      variable showed_note

      set betaKey [ans_getvalue active,,keyw,,beta]

      # Disable ansys gui
      ans_greygui 0 0
      ans_greygui 1 0
      ans_greygui 3 0
      ans_greygui 4 0

      getValuesFromDB

# get the current jobname
      set job(1) [ans_getvalue active,,jobname,,start,1]
      set job(2) [ans_getvalue active,,jobname,,start,9]
      set job(3) [ans_getvalue active,,jobname,,start,17]
      set job(4) [ans_getvalue active,,jobname,,start,25]
      set jobname [string trimright "$job(1)$job(2)$job(3)$job(4)"]

      catch {ans_sendcommand )/NOPR }
      catch {ans_sendcommand )save,dt$jobname,db,,,1 }
      catch {ans_sendcommand )/GO }

      set check [ans_getvalue common,,lsdropcom,,int,9]
      set check2 [ans_getvalue common,,lsdropcom,,int,10]
      if {$check != 0 && $check2 < 2} {
         DeleteTarget
         # Reset old view - get screen out vector
         set Xot [ans_getvalue common,,lsdropcom,,real,30]
         set Yot [ans_getvalue common,,lsdropcom,,real,31]
         set Zot [ans_getvalue common,,lsdropcom,,real,32]
         catch {ans_sendcommand )/NOPR}
         catch {ans_sendcommand /VIEW,,$Xot,$Yot,$Zot}
         catch {ans_sendcommand )/GO}
         # Rotate about screen z axis - get screen up vector
         set theta [ans_getvalue common,,lsdropcom,,real,33]
         catch {ans_sendcommand )/NOPR}
         catch {ans_sendcommand /ANGLE,,$theta,ZS}
         catch {ans_sendcommand )/GO}
      } else {
         catch {ans_sendcommand CMDE,_Yelem}
         catch {ans_sendcommand CMDE,_dtdrpob}
         catch {ans_sendcommand CM,_Yelem,ELEM}
         catch {ans_sendcommand CM,_dtdrpob,NODE}
         catch {ans_sendcommand )/NOPR}
         catch {ans_sendcommand )_dttgmak=0}
         catch {ans_sendcommand )/GO}
      }

      # setup 1 means we are in droptest - needed for DropInquire
      catch {ans_sendcommand )EDUI,PUT,SETUP,1}
      catch {ans_sendcommand )/NOPR}
      catch {ans_sendcommand )EPLOT}
      catch {ans_sendcommand KEYW,DTFILT,0}
      catch {ans_sendcommand )/GO}

      if [winfo exists .drTest] {
         if {$betaKey == 0} {
            $tabParent pageconfigure 4 -state disabled \
            -tabborders false
         } else {
            $tabParent pageconfigure 4 -state normal \
            -tabborders true
         }
         $tabParent select 0
         $parent activate
         return
      } 

      #Initializing stuff - this is probably temporary

      # use the 1 at the end so there is no error message

      set showed_note 0


      catch {ans_sendcommand )/NOPR}
      catch {ans_sendcommand )_dttgmak=0}
      catch {ans_sendcommand )/GO}
      #End of Initializing

      set parent [euidl::dialog .drTest \
            -class EUIDL]
      set childsite [$parent component childsite]
      set childsite [frame $childsite.dropTest \
            -class DropTest]
      pack $childsite -fill both -expand true

      set tabParent [::euidl::tabnotebook $childsite.tnb]
      pack $tabParent -padx 3 -pady 3

      wm title $parent [msgcat::mc "Drop Test Set-up"]

      set page [$tabParent add]
      $tabParent pageconfigure 0 \
            -label [msgcat::mc "Basic"] \
            -command [code DeleteTarget]
      set page1 [frame $page.hold -class Page1]
      pack $page1 -padx 10 -pady 10

      set page [$tabParent add]
      $tabParent pageconfigure 1 \
            -label [msgcat::mc "Velocity"] \
            -command [code DeleteTarget]
      set page2 [frame $page.hold -class Page2]
      pack $page2 -padx 10 -pady 10

      set page [$tabParent add]
      $tabParent pageconfigure 2 \
            -label [msgcat::mc "Target"] \
            -command [code PreviewStatus]
      set page3 [frame $page.hold -class Page3]
      pack $page3 -padx 10 -pady 10

      set page [$tabParent add]
      $tabParent pageconfigure 3 \
            -label [msgcat::mc "Status"] \
            -command [code PreviewStatus]
      set page5 [frame $page.hold -class Page5]
      pack $page5 -padx 10 -pady 10

      set tablewinColor [ $tabParent cget -background ]

      set page [$tabParent add]
      $tabParent pageconfigure 4 \
            -label [msgcat::mc "Beta"] \
            -command [code DeleteTarget] \
            -disabledforeground $tablewinColor \
            -tabborders true
      set page4 [frame $page.hold -class Page4]
      pack $page4 -padx 10 -pady 10
      if {$betaKey == 0} {
         $tabParent pageconfigure 4 -state disabled \
            -tabborders false
      }


      page1
      page2
      page3
      page4
      page5

      $parent configure \
            -okcommand [code droptest_ok] \
            -cancelcommand [code droptest_cancel] \
            -helpcommand [code help]

      bind $parent.buttonBox.ok <ButtonPress-1> "+focus %W"

      $tabParent select 0

      update
      # Get the correct width of the widget
      set ndWidth [winfo reqwidth [$tabParent component tabset]]
      set ndWpage1 [winfo reqwidth $page1]
      if {$ndWidth < $ndWpage1} {set ndWidth $ndWpage1}
      set ndWpage2 [winfo reqwidth $page2]
      if {$ndWidth < $ndWpage2} {set ndWidth $ndWpage2}
      set ndWpage3 [winfo reqwidth $page3]
      if {$ndWidth < $ndWpage3} {set ndWidth $ndWpage3}
      set ndWpage4 [winfo reqwidth $page4]
      if {$ndWidth < $ndWpage4} {set ndWidth $ndWpage4}
      set ndWpage5 [winfo reqwidth $page5]
      if {$ndWidth < $ndWpage5} {set ndWidth $ndWpage5}

      # Get the correct width of the widget
      set ndHeight [winfo reqheight [$tabParent component tabset]]
      set ndHpage1 [winfo reqheight $page1]
      if {$ndHeight < $ndHpage1} {set ndHeight $ndHpage1}
      set ndHpage2 [winfo reqheight $page2]
      if {$ndHeight < $ndHpage2} {set ndHeight $ndHpage2}
      set ndHpage3 [winfo reqheight $page3]
      if {$ndHeight < $ndHpage3} {set ndHeight $ndHpage3}
      set ndHpage4 [winfo reqheight $page4]
      if {$ndHeight < $ndHpage4} {set ndHeight $ndHpage4}
      set ndHpage5 [winfo reqheight $page5]
      if {$ndHeight < $ndHpage5} {set ndHeight $ndHpage5}

      if {$ndHeight < 266} {set ndHeight 266}

      $tabParent configure \
            -width [expr $ndWidth + 25] \
            -height [expr $ndHeight + 50]

      uidl::registerWindow $parent
      $parent activate

      omegaFilter

   }

   proc page1 {} {
      variable childsite
      variable tabParent
      variable dT
      variable page1

      euidl::labeledframe $page1.frm1 -text [msgcat::mc "Gravity"]
      set child [$page1.frm1 component childsite]

      euidl::label $child.lblGravity -text [msgcat::mc "Magnitude of g  "]
 
      euidl::combobox $child.cmbGravity \
             -style combobox 
      $child.cmbGravity insert list end    \
            [list {  zero  } 0       \
                  { 386.4  } 386.4   \
                  {  32.2  } 32.2    \
                  {   9.81 } 9.81    \
                  {9810    } 9810.0  \
            ]
      $child.cmbGravity configure \
            -variable [scope dT(gravity)] \
            -width 16

      grid $page1.frm1 -column 0 -row 0 -sticky new
      grid $child.lblGravity -column 0 -row 0 -sticky nw -pady 2
      grid $child.cmbGravity -column 1 -row 0 -sticky new -pady 2

      euidl::labeledframe $page1.frm2 -text [msgcat::mc "Drop Height"]
      set child [$page1.frm2 component childsite]
      grid $page1.frm2 -column 0 -row 1 -sticky new -rowspan 2

      euidl::label $child.lblDropHeight -text [msgcat::mc "Height          "]
      euidl::entry $child.entDropHeight \
            -variable [scope dT(height)] \
            -width 18
            
      grid $child.lblDropHeight -column 0 -row 0 -sticky nw -pady 2
      grid $child.entDropHeight -column 1 -row 0 -sticky nw -pady 2

      euidl::label $child.lblReference -text [msgcat::mc "Reference       "]
      euidl::combobox $child.cmbReference 
      $child.cmbReference insert list end \
            [list "Lowest Obj Point" 0 "Object CG" 1]
      $child.cmbReference configure \
            -variable [scope dT(reference)] \
            -width 16
      grid $child.lblReference -column 0 -row 1 -sticky nw -pady 2
      grid $child.cmbReference -column 1 -row 1 -sticky new -pady 2

      grid columnconfigure $child 0 -minsize 20

      euidl::labeledframe $page1.frm5 -text [msgcat::mc "Set Orientation"]
      set child [$page1.frm5 component childsite]
      grid $page1.frm5 -column 0 -row 3 -sticky new -rowspan 2

      euidl::button $child.btPanZoom \
         -text [msgcat::mc "Rotate..."] \
         -width 15 \
         -command [code PanZoom]

      grid $child.btPanZoom -column 0 -row 0

      euidl::button $child.btPick2 \
         -text [msgcat::mc "Pick Nodes..."] \
         -width 15 \
         -command [code Pick2Nodes]

      grid $child.btPick2 -column 1 -row 0

      euidl::labeledframe $page1.frm3 -text [msgcat::mc "Solution Time"]
      set child [$page1.frm3 component childsite]
 
      grid $page1.frm3 -column 1 -row 0 -sticky new -rowspan 2

      euidl::radiobutton $child.rbImpactTime \
            -text [msgcat::mc "Start analysis near impact time"] \
            -variable [scope dT(droptime)] -value 0 \
            -anchor nw 
      euidl::radiobutton $child.rbDropTime \
            -text [msgcat::mc "Start analysis at drop time    "] \
            -variable [scope dT(droptime)] -value 1 \
            -anchor nw 

      grid $child.rbImpactTime -column 0 -row 0 -sticky nw -columnspan 2
      grid $child.rbDropTime -column 0 -row 1 -sticky nw -columnspan 2

      euidl::label $child.lblTimeAdd -text [msgcat::mc "Run time after impact"]
      euidl::entry $child.entTimeAdd \
            -width 12 \
            -variable [scope dT(timeadd)] 

      grid $child.lblTimeAdd -column 0 -row 3 -sticky nw -pady 2
      grid $child.entTimeAdd -column 1 -row 3 -pady 2

      euidl::labeledframe $page1.frm4 -text [msgcat::mc "Number of Results Output"]
      set child [$page1.frm4 component childsite]
      grid $page1.frm4 -column 1 -row 2 -sticky new -rowspan 2

      euidl::label $child.lblFileInt -text [msgcat::mc "On results file      "]
      euidl::entry $child.entFileInt \
            -width 12 \
            -variable [scope dT(EDRST,2)]
      euidl::label $child.lblHistInt -text [msgcat::mc "On time history file "]
      euidl::entry $child.entHistInt \
            -width 12 \
            -variable [scope dT(EDHTIME,2)]

      grid $child.lblFileInt -column 0 -row 0 -sticky nw
      grid $child.entFileInt -column 1 -row 0 -sticky ne
      grid $child.lblHistInt -column 0 -row 1 -sticky nw
      grid $child.entHistInt -column 1 -row 1 -sticky ne

   }


# Velocity page begin

   proc page2 {} {
      variable childsite
      variable tabParent
      variable dT
      variable page2

# Translational Velocity frame begin

      euidl::labeledframe $page2.frm1 -text [msgcat::mc "Translational Velocity"]
      set child [$page2.frm1 component childsite]

      grid $page2.frm1 -column 0 -row 0 -sticky new

      euidl::label $child.lblVelocityCoord \
            -text [msgcat::mc "Velocity relative to:"]
      euidl::combobox $child.cmbVelocityCoord
      $child.cmbVelocityCoord insert list end \
            [list "Screen coordinates" 0 "Object coordinates" 1 ]
      $child.cmbVelocityCoord configure \
            -width 18 \
            -variable [scope dT(velocity,coord)]

      euidl::label $child.lblXComponent \
            -justify left \
            -text [msgcat::mc "X Component   "]
      euidl::entry $child.entXComponent \
            -width 20 \
            -variable [scope dT(velocity,x)]

      euidl::label $child.lblYComponent \
            -justify left \
            -text [msgcat::mc "Y Component"]
      euidl::entry $child.entYComponent \
            -width 20 \
            -variable [scope dT(velocity,y)]

      euidl::label $child.lblZComponent \
            -justify left \
            -text [msgcat::mc "Z Component"]
      euidl::entry $child.entZComponent \
            -width 20 \
            -variable [scope dT(velocity,z)]

      grid $child.lblVelocityCoord -column 0 -row 0 -sticky nw -pady 2 -columnspan 2
      grid $child.cmbVelocityCoord -column 0 -row 1 -sticky ne -pady 2 -columnspan 2
      grid $child.lblXComponent -column 0 -row 2 -pady 2 -sticky nw
      grid $child.entXComponent -column 1 -row 2 -pady 2 -sticky ne
      grid $child.lblYComponent -column 0 -row 3 -pady 2 -sticky nw
      grid $child.entYComponent -column 1 -row 3 -pady 2 -sticky ne
      grid $child.lblZComponent -column 0 -row 4 -pady 2 -sticky nw
      grid $child.entZComponent -column 1 -row 4 -pady 2 -sticky ne

# Translational Velocity frame end

# Angular Velocity frame begin

      euidl::labeledframe $page2.frm2 -text [msgcat::mc "Angular Velocity"]
      set child [$page2.frm2 component childsite]

      grid $page2.frm2 -column 1 -row 0 -sticky new -rowspan 4

      euidl::label $child.lblVelocityCoord \
            -text [msgcat::mc "Velocity relative to:"]
      euidl::combobox $child.cmbVelocityCoord
      $child.cmbVelocityCoord insert list end \
            [list "Screen coordinates" 0 "Object coordinates" 1 ]
      $child.cmbVelocityCoord configure \
            -width 18 \
            -variable [scope dT(omega,coord)] 

      euidl::label $child.lblXComponent \
            -justify left \
            -text [msgcat::mc "X Component   "]
      euidl::entry $child.entXComponent \
            -width 20 \
            -variable [scope dT(omega,x)]

      euidl::label $child.lblYComponent \
            -justify left \
            -text [msgcat::mc "Y Component"]
      euidl::entry $child.entYComponent \
            -width 20 \
            -variable [scope dT(omega,y)]

      euidl::label $child.lblZComponent \
            -justify left \
            -text [msgcat::mc "Z Component"]
      euidl::entry $child.entZComponent \
            -width 20 \
            -variable [scope dT(omega,z)]

      grid $child.lblVelocityCoord -column 0 -row 1 -sticky nw -pady 2 -columnspan 2
      grid $child.cmbVelocityCoord -column 0 -row 2 -sticky ne -pady 2 -columnspan 2
      grid $child.lblXComponent -column 0 -row 3 -pady 2 -sticky nw
      grid $child.entXComponent -column 1 -row 3 -pady 2 -sticky ne
      grid $child.lblYComponent -column 0 -row 4 -pady 2 -sticky nw
      grid $child.entYComponent -column 1 -row 4 -pady 2 -sticky ne
      grid $child.lblZComponent -column 0 -row 5 -pady 2 -sticky nw
      grid $child.entZComponent -column 1 -row 5 -pady 2 -sticky ne

# Angular Velocity frame end

      euidl::label $page2.lblAngleNote \
            -justify left \
            -text [msgcat::mc "NOTE: The angular velocity is about  "]
      euidl::label $page2.lblAngleNote2 \
            -justify left \
            -text [msgcat::mc "      the object centroid in units of"]
      euidl::label $page2.lblAngleNote3 \
            -justify left \
            -text [msgcat::mc "      radians/(unit time)            "]

      grid $page2.lblAngleNote -column 1 -row 2
      grid $page2.lblAngleNote2 -column 1 -row 3
      grid $page2.lblAngleNote3 -column 1 -row 4

   }

# Velocity page end

# Target page begin

   proc page3 {} {
      variable childsite
      variable tabParent
      variable dT
      variable page3

# Dimension frame begin

      euidl::labeledframe $page3.frm1 -text [msgcat::mc "Dimensions"]
      set child [$page3.frm1 component childsite]

      grid $page3.frm1 -column 0 -row 0 -sticky new

      euidl::label $child.lblTargetCenter \
            -text [msgcat::mc "Center target using"]
      euidl::combobox $child.cmbTargetCenter 
      $child.cmbTargetCenter insert list end \
            [list {Lowest Obj Point} 0 \
                  {Object CG} 1 \
            ]
      $child.cmbTargetCenter configure \
            -variable [scope dT(target,center,out)] \
            -command [code ModifyTarget] \
            -width 16

      bind $child.cmbTargetCenter <Leave> [code ModifyTarget]

      euidl::label $child.lblLengthSF \
            -text [msgcat::mc "Length scale factor"]
      euidl::entry $child.entLengthSF \
            -width 18 \
            -variable [scope dT(target,length,out)]

      bind $child.entLengthSF <Leave> [code ModifyTarget]

      euidl::label $child.lblThickSF \
            -text [msgcat::mc "Thickness scale factor"]
      euidl::entry $child.entThickSF \
            -width 18 \
            -variable [scope dT(target,thick,out)]

      bind $child.entThickSF <Leave> [code ModifyTarget]

      grid $child.lblTargetCenter -column 0 -row 0 -sticky nw -pady 2
      grid $child.cmbTargetCenter -column 1 -row 0 -sticky ne -pady 2
      grid $child.lblLengthSF -column 0 -row 1 -sticky nw -pady 2
      grid $child.entLengthSF -column 1 -row 1 -sticky ne -pady 2
      grid $child.lblThickSF -column 0 -row 2 -sticky nw -pady 2
      grid $child.entThickSF -column 1 -row 2 -sticky ne -pady 2

# Dimension frame end

# Target orientation frame begin

      euidl::labeledframe $page3.frm3 -text [msgcat::mc "Orientation angle"]
      set child [$page3.frm3 component childsite]

      grid $page3.frm3 -column 0 -row 1 -sticky new

      euidl::label $child.lblRotAngle \
            -justify left \
            -text [msgcat::mc "Rotation about screen Z"]
      euidl::entry $child.entRotAngle \
            -width 17 \
            -variable [scope dT(target,rotang,out)]

      bind $child.entRotAngle <Leave> [code ModifyTarget]

      grid $child.lblRotAngle -column 0 -row 0 -pady 2 -sticky nw
      grid $child.entRotAngle -column 1 -row 0 -pady 2

# Target orientation frame end

# Material prop frame begin

      euidl::labeledframe $page3.frm2 -text [msgcat::mc "Material Properties"]
      set child [$page3.frm2 component childsite]

      grid $page3.frm2 -column 1 -row 0 -sticky new -rowspan 2

      euidl::label $child.lblYoungsMod \
            -text [msgcat::mc "Young's modulus        "]
      euidl::entry $child.entYoungsMod \
            -variable [scope dT(MP,EX,3)] \
            -width 14

      euidl::label $child.lblDensity \
            -text [msgcat::mc "Density"]
      euidl::entry $child.entDensity \
            -variable [scope dT(MP,DENS,3)] \
            -width 14

      euidl::label $child.lblPoisson \
            -text [msgcat::mc "Poisson's ratio"]
      euidl::entry $child.entPoisson \
            -variable [scope dT(MP,NUXY,3)] \
            -width 14

      grid $child.lblYoungsMod -column 0 -row 0 -sticky nw -pady 2
      grid $child.entYoungsMod -column 1 -row 0 -sticky ne -pady 2
      grid $child.lblDensity -column 0 -row 1 -sticky nw -pady 2
      grid $child.entDensity -column 1 -row 1 -sticky ne -pady 2
      grid $child.lblPoisson -column 0 -row 2 -sticky nw -pady 2
      grid $child.entPoisson -column 1 -row 2 -sticky ne -pady 2

# Material prop frame end

# Friction frame begin

      euidl::labeledframe $page3.frm4 -text [msgcat::mc "Contact"]
      set child [$page3.frm4 component childsite]

      grid $page3.frm4 -column 1 -row 1 -sticky new -rowspan 2

      euidl::label $child.lblFSCoeff \
            -justify left \
            -text [msgcat::mc "Static friction coeff "]
      euidl::entry $child.entFSCoeff \
            -variable [scope dT(EDCGEN,5)] \
            -width 14

      euidl::label $child.lblFDCoeff \
            -justify left \
            -text [msgcat::mc "Dynamic friction coeff "]
      euidl::entry $child.entFDCoeff \
            -variable [scope dT(EDCGEN,6)] \
            -width 14

      euidl::label $child.lblDCCoeff \
            -justify left \
            -text [msgcat::mc "Exponential decay coeff"]
      euidl::entry $child.entDCCoeff \
            -variable [scope dT(EDCGEN,7)] \
            -width 14

      grid $child.lblFSCoeff -column 0 -row 1 -pady 2 -sticky nw
      grid $child.entFSCoeff -column 1 -row 1 -pady 2 -sticky nw
      grid $child.lblFDCoeff -column 0 -row 2 -pady 2 -sticky nw
      grid $child.entFDCoeff -column 1 -row 2 -pady 2 -sticky nw
      grid $child.lblDCCoeff -column 0 -row 3 -pady 2 -sticky nw
      grid $child.entDCCoeff -column 1 -row 3 -pady 2 -sticky ne

# Friction frame end
   }

# Target page end

# Advanced page begin

   proc page4 {} {
      variable childsite
      variable tabParent
      variable dT
      variable page4

      euidl::labeledframe $page4.frm1 -text [msgcat::mc "Contact"]
      set child [$page4.frm1 component childsite]

      grid $page4.frm1 -column 0 -row 0 -sticky new -rowspan 1

      euidl::label $child.lblContactType \
            -text [msgcat::mc "Automatic contact type"]

      euidl::combobox $child.cmbContactType
      $child.cmbContactType insert list end \
            [list {Single surface} ASSC \
                  {General} AG \
            ]
      $child.cmbContactType configure \
            -variable [scope dT(EDCGEN,2)] \
            -width 14

      grid $child.lblContactType -column 0 -row 0 -sticky nw
      grid $child.cmbContactType -column 1 -row 0 -sticky nw

      euidl::label $child.lblVCCoeff \
            -justify left \
            -text [msgcat::mc "Viscous friction coefficient"]
      euidl::entry $child.entVCCoeff \
            -variable [scope dT(EDCGEN,8)] 

      euidl::label $child.lblVDCCoeff \
            -justify left \
            -text [msgcat::mc "Viscous damping coefficient"]
      euidl::entry $child.entVDCCoeff \
            -variable [scope dT(EDCGEN,9)] 

      grid $child.lblVCCoeff -column 0 -row 4 -pady 2 -sticky nw
      grid $child.entVCCoeff -column 1 -row 4 -pady 2 -sticky ne
      grid $child.lblVDCCoeff -column 0 -row 5 -pady 2 -sticky nw
      grid $child.entVDCCoeff -column 1 -row 5 -pady 2 -sticky ne

      euidl::labeledframe $page4.frm2 -text [msgcat::mc "Height Control"]
      set child [$page4.frm2 component childsite]

      grid $page4.frm2 -column 0 -row 1 -sticky new -rowspan 1

      euidl::label $child.lblHtFactor \
            -justify left \
            -text [msgcat::mc "Percent drop height reduction"]
      euidl::entry $child.entHtFactor \
            -variable [scope dT(advanced,factor,out)]

      grid $child.lblHtFactor -column 0 -row 0 -pady 2 -sticky nw
      grid $child.entHtFactor -column 1 -row 0 -pady 2 -sticky ne

  }

# Advanced page end

# Status page begin

   proc page5 {} {
      variable childsite
      variable tabParent
      variable dT
      variable page5

      euidl::labeledframe $page5.frm1 -text [msgcat::mc "Summary"]
      set child [$page5.frm1 component childsite]

      grid $page5.frm1 -column 0 -row 0 -sticky new

      euidl::label $child.lblGravityMag
      grid $child.lblGravityMag -column 0 -row 0 -sticky nw -pady 2

      euidl::label $child.lblVelocityMag
      grid $child.lblVelocityMag -column 0 -row 1 -sticky nw -pady 2

      euidl::label $child.lblOmegaMag
      grid $child.lblOmegaMag -column 0 -row 2 -sticky nw -pady 2

      euidl::label $child.lblTotalTime
      grid $child.lblTotalTime -column 0 -row 3 -sticky nw -pady 2

      euidl::label $child.lblBLANK -text [msgcat::mc "     "]
      grid $child.lblBLANK -column 0 -row 4 -sticky nw -pady 2

      euidl::label $child.lblDropStatus 
      grid $child.lblDropStatus -column 0 -row 5 -sticky nw -pady 2

   }

# Status page end


# Calculate Impact time - preview page and OK

  proc PreviewStatus {} {
      if {[catch {set check [ans_getvalue parm,_dttgmak,value]}]} {
         set check 0
      }
      if {$check == 0} {
         PreviewStatus2
      }
  }
  
  proc PreviewStatus2 {} {
      variable dT
      variable page5
      variable betaKey
     
      ## Put the parameters from the Basic tab on the common block
      set flds ""
      foreach fld [list \
                     gravity \
                     height \
                     reference \
                     droptime \
                     timeadd \
                   ] {
             if {[catch {set formatlabel [format "%-8.5e" $dT($fld)]}]} {
                set dT($fld) 0
             }
             set flds [concat $flds $dT($fld)]
      }
      set flds [join $flds ,]
      catch {ans_sendcommand EDUI,PUT,BASIC,$flds}

      ## Put the parameters from the Velocity tab on the common block
      set flds ""
      foreach fld [list \
                     velocity,coord \
                     velocity,x \
                     velocity,y \
                     velocity,z \
                     omega,coord \
                     omega,x \
                     omega,y \
                     omega,z \
                   ] {
             if {[catch {set formatlabel [format "%-8.5e" $dT($fld)]}]} {
                set dT($fld) 0
             }
             set flds [concat $flds $dT($fld)]
      }
      set flds [join $flds ,]
      catch {ans_sendcommand EDUI,PUT,VELO,$flds}

      ## Put the parameters from the Target tab on the common block
      set flds ""
      foreach fld [list \
                     target,center,out \
                     target,length,out \
                     target,thick,out \
                     target,rotang,out \
                  ] {
             if {[catch {set formatlabel [format "%-8.5e" $dT($fld)]}]} {
                set dT($fld) 0
             }
             set flds [concat $flds $dT($fld)]
      }
      set flds [join $flds ,]
      catch {ans_sendcommand EDUI,PUT,TARGET,$flds}

      ## Put the parameters from the Target tab on the common block
      set flds ""
      foreach fld [list \
                     advanced,factor,out \
                  ] {
             if {[catch {set formatlabel [format "%-8.5e" $dT($fld)]}]} {
                set dT($fld) 0
             }
             set flds [concat $flds $dT($fld)]
      }
      set flds [join $flds ,]
      if {$betaKey == 1} {
         catch {ans_sendcommand EDUI,PUT,ADVANCE,$flds}
      }
      catch {ans_sendcommand !}


      # target stuff

      catch {ans_sendcommand )/show,junk}
      catch {ans_sendcommand )EDUI,EXEC}
      catch {ans_sendcommand )/auto,fit}
      catch {ans_sendcommand )/show,term}
          
      catch {ans_sendcommand )/NOPR}
      cmd_exec
      catch {ans_sendcommand )/GO}

      catch {ans_sendcommand eplot}

      set endtime [ans_getvalue common,,stepcm,,real,2]

      set formatlabel [format "%-8.5e" $endtime]
      set child [$page5.frm1 component childsite]
      $child.lblTotalTime configure \
         -text [msgcat::mc "Time at end of solution is $formatlabel"]

      set formatlabel [format "%-8.5e" $dT(gravity)]
      $child.lblGravityMag configure \
         -text [msgcat::mc "Acceleration due to gravity is $formatlabel"]
      set sqrx [expr $dT(velocity,x) * $dT(velocity,x)]
      set sqry [expr $dT(velocity,y) * $dT(velocity,y)]
      set sqrz [expr $dT(velocity,z) * $dT(velocity,z)]
      set sum  [expr $sqrx + $sqry + $sqrz]
      set temp [expr sqrt($sum)]
      set formatlabel [format "%-8.5e" $temp]
      $child.lblVelocityMag configure \
         -text [msgcat::mc "Magnitude of initial translational velocity is $formatlabel"]

      set sqrx [expr $dT(omega,x) * $dT(omega,x)]
      set sqry [expr $dT(omega,y) * $dT(omega,y)]
      set sqrz [expr $dT(omega,z) * $dT(omega,z)]
      set sum  [expr $sqrx + $sqry + $sqrz]
      set temp [expr sqrt($sum)]
      set formatlabel [format "%-8.5e" $temp]
      $child.lblOmegaMag configure \
         -text [msgcat::mc "Magnitude of initial rotational velocity is $formatlabel"]

      set DropStatus [ans_getvalue common,,lsdropcom,,int,10]
      if {$DropStatus == 2} {
         $child.lblDropStatus configure \
            -text [msgcat::mc "Unsuccessful Set-Up.  See error messages."] \
            -foreground red
      } elseif {$DropStatus == 1} {
         $child.lblDropStatus configure \
            -text [msgcat::mc "Proceed with caution.  See error messages."] \
            -foreground yellow
         catch {ans_sendcommand )/NOPR}
         catch {ans_sendcommand )_dttgmak=1}
         catch {ans_sendcommand )/GO}
      } else {
         $child.lblDropStatus configure \
            -text [msgcat::mc "Successful Set-Up.  Ready to drop."] \
            -foreground black
         catch {ans_sendcommand )/NOPR}
         catch {ans_sendcommand )_dttgmak=1}
         catch {ans_sendcommand )/GO}
      }
   }

   # This pair of procs is to allow correct interaction with UIDL
   proc PanZoom {} {
      variable parent
      variable showed_note

      if {$showed_note == 0} {
         catch {ans_senderror -1 "Rotate the object to the desired orientation.  Close the Pan-Zoom-Rotate dialog to return to Set-Up."}
      }
      set showed_note 1
      catch {ans_sendcommand /show,close}
      $parent deactivate
      uidl::registerWindow $parent 0
      ::uidl::callFnc /UI,VIEW [code PanZoomReturn]
   }

   proc PanZoomReturn { uidlButton } {
      variable parent
      catch {ans_sendcommand /auto,fit}
      catch {ans_sendcommand eplot}
      $parent activate
      uidl::registerWindow $parent
   }

   proc Pick2Nodes {} {
      variable parent
      catch {ans_sendcommand /show,close}
      $parent deactivate
      uidl::registerWindow $parent 0
      ::uidl::callFnc Fnc_DropNode1 [code Pick2ndNode]
   }

   proc Pick2ndNode { uidlButton } {
      variable parent
      set node1 0
      catch {set node1 [ans_getvalue parm,_dtnd1,value]}
      if {$node1 > 0} {
         ::uidl::callFnc Fnc_DropNode2 [code OrientByNode]
      } else {
         $parent activate
         uidl::registerWindow $parent
      }
   }

   proc OrientByNode { uidlButton } {
      variable parent

      set node1 0
      set node2 0
      catch {set node1 [ans_getvalue parm,_dtnd1,value]}
      catch {set node2 [ans_getvalue parm,_dtnd2,value]}

      set x1 [ans_getvalue node,$node1,loc,x]
      set y1 [ans_getvalue node,$node1,loc,y]
      set z1 [ans_getvalue node,$node1,loc,z]

      if {$node2 > 0} {
         set x2 [ans_getvalue node,$node2,loc,x]
         set y2 [ans_getvalue node,$node2,loc,y]
         set z2 [ans_getvalue node,$node2,loc,z]
      } else {
         catch {ans_sendcommand )EDUI,CG}
         set x2 [ans_getvalue common,,lsdropcom,,real,5]
         set y2 [ans_getvalue common,,lsdropcom,,real,6]
         set z2 [ans_getvalue common,,lsdropcom,,real,7]
      }

      set xdif [expr $x2 - $x1]
      set ydif [expr $y2 - $y1]
      set zdif [expr $z2 - $z1]

      catch {ans_sendcommand )/NOPR}
      catch {ans_sendcommand )/SHOW,junk}
      catch {ans_sendcommand )/GO}
      catch {ans_sendcommand /VIEW,,$xdif,$ydif,$zdif}
      catch {ans_sendcommand /ANGLE,,-90,XS}
      catch {ans_sendcommand )/NOPR}
      catch {ans_sendcommand )/SHOW,close}
      catch {ans_sendcommand )/GO}
      catch {ans_sendcommand eplot}

      $parent activate
      uidl::registerWindow $parent
   }

   proc ModifyTarget {} {
      variable dT

      set doCmd 0

      if ![string match $dT(target,center,in) $dT(target,center,out)] {
         set dT(target,center,in) $dT(target,center,out) 
         set doCmd 1
      }
      if ![string match $dT(target,length,in) $dT(target,length,out)] {
         set dT(target,length,in) $dT(target,length,out) 
         set doCmd 1
      }
      if ![string match $dT(target,thick,in) $dT(target,thick,out)] {
         set dT(target,thick,in) $dT(target,thick,out) 
         set doCmd 1
      }
      if ![string match $dT(target,rotang,in) $dT(target,rotang,out)] {
         set dT(target,rotang,in) $dT(target,rotang,out) 
         set doCmd 1
      }

      if {$doCmd} {
         catch {ans_sendcommand )erase}
         catch {ans_sendcommand )/show,junk}
         DeleteTarget
         PreviewStatus
         catch {ans_sendcommand )/nopr}
         catch {ans_sendcommand )/show,close}
         catch {ans_sendcommand )eplot}
         catch {ans_sendcommand )/go}
         getValuesFromDB
      }

   }

   proc DeleteTarget {} {
      if {[catch {set check [ans_getvalue parm,_dttgmak,value]}]} {
         set check 0
      }
      if {$check == 1} {
         catch {ans_sendcommand CMSEL,U,_Yelem}
         catch {ans_sendcommand edel,all}
         catch {ans_sendcommand nsel,all}
         catch {ans_sendcommand esel,all}
         catch {ans_sendcommand )/NOPR}
         catch {ans_sendcommand )_dttgmak=0}
         catch {ans_sendcommand )eplo}
         catch {ans_sendcommand )/GO}
      }
      if [winfo exists .drTest] {
         omegaFilter
      }
   }

# filtering proce
   proc omegaFilter {} {
      variable dT
      variable page1
      variable page2

      set child [$page1.frm3 component childsite]
      $child.rbImpactTime configure -state normal
      $page2.frm2 configure -state normal
      $page2.lblAngleNote configure -state normal
      $page2.lblAngleNote2 configure -state normal
      $page2.lblAngleNote3 configure -state normal

      # check for rotational DOF
      set dofs [ans_getlist dof]
      set rotflag 0
      foreach dof $dofs {
         if [string match $dof "ROTX"] {
            set rotflag 1
         } elseif [string match $dof "ROTY"] {
            set rotflag 1
         } elseif [string match $dof "ROTZ"] {
            set rotflag 1
         }
      }
      if {$rotflag == 0} {
         set $dT(omega,x) 0
         set $dT(omega,y) 0
         set $dT(omega,z) 0
      }

      # if initial angular velocity is not zero, start at drop time
      if {$dT(omega,x) != 0 || $dT(omega,y) != 0 || $dT(omega,z) != 0 } {
         set dT(droptime) 1
         set child [$page1.frm3 component childsite]
         $child.rbImpactTime configure -state disabled
      }
      # if we are starting near impact time, disable initial angular velocity
      # also disable if we have no rotational dof
      if {$dT(droptime) == 0 || $rotflag == 0} {
         $page2.frm2 configure -state disabled
         $page2.lblAngleNote configure -state disabled
         $page2.lblAngleNote2 configure -state disabled
         $page2.lblAngleNote3 configure -state disabled
      }
   }

   proc getValuesFromDB {} {
      variable dT

      # Page 1 values

      set dT(gravity)   [ans_getvalue common,,lsdropcom,,real,1]
      set dT(height)    [ans_getvalue common,,lsdropcom,,real,2]
      set dT(reference) [ans_getvalue common,,lsdropcom,,int,1]
      set dT(droptime)  [ans_getvalue common,,lsdropcom,,int,2]
      set dT(timeadd)   [ans_getvalue common,,lsdropcom,,real,14]

      set dT(EDRST,2) [ans_getvalue common,,lsdynacom,,int,53]
      set dT(EDHTIME,2) [ans_getvalue common,,lsdynacom,,int,54]

#      set dT(TIME,2) [ans_getvalue common,,stepcm,,real,2]
#      set dT(TIME,2,drop) 0
#      set dT(TIME,2,impact) 0


      # Page 2 values
      set dT(velocity,coord) [ans_getvalue common,,lsdropcom,,int,3]
      set dT(velocity,x)     [ans_getvalue common,,lsdropcom,,real,15]
      set dT(velocity,y)     [ans_getvalue common,,lsdropcom,,real,16]
      set dT(velocity,z)     [ans_getvalue common,,lsdropcom,,real,17]
      set dT(omega,coord)    [ans_getvalue common,,lsdropcom,,int,4]
      set dT(omega,x)        [ans_getvalue common,,lsdropcom,,real,18]
      set dT(omega,y)        [ans_getvalue common,,lsdropcom,,real,19]
      set dT(omega,z)        [ans_getvalue common,,lsdropcom,,real,20]
 
      # Page 3 values
      set dT(target,center,in) [ans_getvalue common,,lsdropcom,,int,5]
      set dT(target,length,in) [ans_getvalue common,,lsdropcom,,real,21]
      set dT(target,thick,in)  [ans_getvalue common,,lsdropcom,,real,22]
      set dT(target,rotang,in) [ans_getvalue common,,lsdropcom,,real,23]

      set dT(target,center,out) $dT(target,center,in) 
      set dT(target,length,out) $dT(target,length,in) 
      set dT(target,thick,out)  $dT(target,thick,in)  
      set dT(target,rotang,out) $dT(target,rotang,in) 

      set targMat [ans_getvalue common,,lsdropcom,,int,9]
      if {$targMat == 0} {
         set dT(MP,EX,3) [ans_getvalue common,,lsdropcom,,real,37]
         set dT(MP,DENS,3) [ans_getvalue common,,lsdropcom,,real,38]
         set dT(MP,NUXY,3) [ans_getvalue common,,lsdropcom,,real,39]
      } else {
         set dT(MP,EX,3) [ans_getvalue ex,$targMat]
         set dT(MP,DENS,3) [ans_getvalue dens,$targMat]
         set dT(MP,NUXY,3) [ans_getvalue nuxy,$targMat]
      }

      #advanced page
      set dT(advanced,factor,in) [ans_getvalue common,,lsdropcom,,real,40]
      set dT(advanced,factor,out) $dT(advanced,factor,in) 

      if ![winfo exists .drTest] {
         set dT(EDCGEN,2) AG
         set dT(EDCGEN,3) ,
         set dT(EDCGEN,4) ""
         set dT(EDCGEN,5) 0.0
         set dT(EDCGEN,6) 0.0
         set dT(EDCGEN,7) 0.0

         # Page 4 values
         set dT(EDCGEN,8) 0.0
         set dT(EDCGEN,9) 0.0

      }


      if [winfo exists .drTest] {
         omegaFilter
      }


   }

   proc droptest_cancel {} {
      variable jobname

      catch {ans_sendcommand )/NOPR}
      catch {ans_sendcommand )resume,dt$jobname,db}
      catch {ans_sendcommand )/GO}

      droptest_close
   }

   proc droptest_close {} {
      variable parent

      ans_greygui 0 1
      ans_greygui 1 1
      ans_greygui 3 1
      ans_greygui 4 1

      catch {ans_sendcommand )EDUI,PUT,SETUP,0}
      catch {ans_sendcommand )/NOPR}
      catch {ans_sendcommand )EPLOT}
      catch {ans_sendcommand )/GO}
      catch {ans_sendcommand Fnc_REFRESH} err

      $parent deactivate
   }

   proc cmd_exec {} {

      variable dT

      # Set target material number
      set targMat [ans_getvalue common,,lsdropcom,,int,9]
      set dT(MP,EX,2) $targMat
      set dT(MP,DENS,2) $targMat
      set dT(MP,NUXY,2) $targMat

      # Command execution loop
      catch {ans_sendcommand EDUI,PUT,MISC,$targMat}
      catch {ans_sendcommand EDDC,DELE,ALL}

      foreach cmd [list \
                        EDRST \
                        EDHTIME \
                        MP,EX \
                        MP,DENS \
                        MP,NUXY \
                        EDCGEN \
                     ] {
         set flds ""
         for {set i 2} {$i <= 9} {incr i} {
            if [info exists dT($cmd,$i)] {
               set flds [concat $flds $dT($cmd,$i)]
            }
         }
         set flds [join $flds ,]
         catch {ans_sendcommand $cmd,$flds}
      }

   }

   proc droptest_ok {} {
      variable dT
      variable parent

      focus -force $parent

##   if status not already done
      if {[catch {set check [ans_getvalue parm,_dttgmak,value]}]} {
         set check 0
      }
      if {$check == 0} {
         PreviewStatus
      }

      set check [ans_getvalue common,,lsdropcom,,int,10]
      if {$check > 1} {
         catch {ans_sendcommand )/NOPR}
         catch {ans_sendcommand KEYW,DTFILT,0}
         catch {ans_sendcommand )/GO}
      } else {

         # Command execution loop
         cmd_exec
         # moved to its own proc and called from PreviewStatus, too

         catch {ans_sendcommand EDHIST,_dtpos26}
         catch {ans_sendcommand EDOUT,NODOUT}
         catch {ans_sendcommand EDOUT,GLSTAT}
         catch {ans_sendcommand )/NOPR}
         catch {ans_sendcommand KEYW,DTFILT,1}
         catch {ans_sendcommand )/GO}
         if {[catch {set cgnode [ans_getvalue parm,_dtcgnum,value]}]} {
            set cgnode 0
         }
         if {[catch {set lownode [ans_getvalue parm,_dtlownum,value]}]} {
            set lownode 0
         }
         catch {ans_sendcommand EDUI,PUT,COMP,$cgnode,$lownode}
      }
      catch {ans_sendcommand Fnc_REFRESH} err
      droptest_close
   }

   proc help {} {
      variable tabParent
      switch -- [$tabParent index select] {
         0 {
            ans_loadhelp Hlp_dtbat
         }
         1 {
            ans_loadhelp Hlp_dtvet
         }
         2 {
            ans_loadhelp Hlp_dttat
         }
         3 {
            ans_loadhelp Hlp_dtsta
         }
         4 {
            ans_loadhelp Hlp_dtsta
         }
      }
   }
}
