#----------------------------------------------------------------------
#Authors              : Joern Nelz, CAD-FEM GmbH, GS Hannover
#                       Schmiedestr. 31, D-31303 Burgdorf
#                       Fon 0 51 36 / 8 80 92 14
#                       Fax 0 51 36 / 89 32 69
#	              : Torsten Johne, CAD-FEM AG, Switzerland
#                       Wittenwilerstr. 25, CH-8355 Aadorf
#                       Fon +41 (052) 368 0101
#                       Fax +41 (052) 368 0109
#Filename             : adamsin1.eui Tk/Tcl Source
#additional Files     : UifuADAM.grn Granule file
#
#Version              : 1.3 02.07.2001
#Project              : G01-ANS-01
#Orderd from          : ANSYS Inc.
#Working              : Torsten Johne, Joern Nelz
#Representative       : Marc Brandenberger, Torsten Johne, Joern Nelz
#----------------------------------------------------------------------
#ANSYS RELEASE  57 Windows 2000
#----------------------------------------------------------------------
#Changes...............................................................
#  - revision 1.0 (07.05.2001) JN / TOJ, initial release
#  - revision 1.1 (15.06.2001) TOJ, How2import part 0 and 1
#  - revision 1.2 (19.06.2001) TOJ, Definition of weak springs
#  - revision 1.3 (02.07.2001) TOJ, How 2 Import Part 1 (weak springs; irlf,0)
#  - revision 1.4 (19.07.2001) TOJ, How 2 Import Part 2 (add weak springs,
#                                                         activate inertia relief;
#                                                         irlf,1 {beta version})
#  - revision 1.5 (l8.09.2001) JLO, Add labels through msgcat instead of rc file
#  - revision 1.6 (03.10.2001) TOJ, Change ADAMSIN.MAC to WSPRINGS.MAC
#  - revision 1.7 (17.10.2001) TOJ, Delateing of defined variables
#  - revision 1.8 (24.10.2001) TOJ, Change the handling of Loadstepfile for "Loads only option";
#                                   hold the defined option in once section
#
#Description            Import ADAMS-Load-Files Dialog

#----------------------------------------------------------------------
# Connection ADAMS 2 ANSYS Initialization
#----------------------------------------------------------------------
package require msgcat
package require ansys
global env

# ---------------------------------------------------------------------
# GLOBAL NAMESPACE:  ::euidl::adamsin1
#
# Purpose:        This namespace creates the
#                 Connection ADAMS 2 ANSYS context
#
# Arguments:      N/A
#
# Return Value:   N/A
#
# Comments:       N/A
#
# See Also:       N/A
#
# ---------------------------------------------------------------------
namespace eval ::euidl::adamsin1 {

    # -----------------------------------------------------------------
    # GLOBALS
    # -----------------------------------------------------------------
    variable version 1.8

    # make beta feature available (Add weak Springs, activate Inertia relief)
    variable beta false

    # -----------------------------------------------------------------
    # PROC:           create
    #
    # Purpose:        Creates the toplevel widget and all the children
    # Arguments:      N/A
    # Return Value:   N/A
    # Comments:       N/A
    # See Also:       N/A
    # -----------------------------------------------------------------
    proc create {} {
        variable parent
        variable childsite
        variable child

        variable beta

        # -------------------------------------------------------------
        # GRAB
        # -------------------------------------------------------------
        ans_greygui 0 0
        ans_greygui 1 0
        ans_greygui 3 0
        ans_greygui 4 0

        # -------------------------------------------------------------
        # VARIABLES SET BY DIALOG
        # -------------------------------------------------------------
        variable openFile
        variable openFilePath
        variable openFileDefault

        set how2imp [ans_getvalue PARM,_how2imp,TYPE ]
        if { $how2imp == 0} {
           set how2imp 1
           } elseif { $how2imp == -1} {
           set how2imp 0
           }

        variable how2import $how2imp

        # -------------------------------------------------------------
        # COMMENT MESSAGE
        # -------------------------------------------------------------
        apdl::noprint 1
        catch {ans_sendcommand )/COM,}
        catch {ans_sendcommand )/COM,********************************************}
        catch {ans_sendcommand )/COM,Use Connection ADAMS 2 ANSYS}
        apdl::noprint 0

        # -------------------------------------------------------------
        # SET DEFAULTS
        # -------------------------------------------------------------

        set openFilePath [pwd]
        set openFileDefault ""
        for {set i 0} {$i <= 4} {incr i} {
           lappend openFileDefault [ans_getvalue ACTIVE,,JOBNAM,,START,[expr $i * 9]]
        }
        set openFileDefault [string trim [join $openFileDefault {}]]
        set openFileDefault "./$openFileDefault.lod"

        # -------------------------------------------------------------
        # CREATE TOPLEVEL
        # -------------------------------------------------------------
        if [winfo exists .adamsIn] {
            wm deiconify $parent
            raise $parent
            return
        }

        set parent [euidl::dialog .adamsIn -class EUIDL]
        set childsite [$parent component childsite]
        set childsite [frame $childsite.doA2A -class AdamsIn]
        pack $childsite -fill both -expand true

        wm title $parent [msgcat::mc "Import from ADAMS"]

        $parent configure \
            -okcommand [code connect_ok] \
            -oktext [msgcat::mc "Import"] \
            -cancelcommand [code connect_cancel] \
            -helpcommand [list ans_loadhelp Hlp_impldsan]

        # -------------------------------------------------------------
        # FRAME 1 ENTRY FILENAME
        # -------------------------------------------------------------
        euidl::labeledframe $childsite.frm1 \
                -text [msgcat::mc "Import file from ADAMS"]

        set child [$childsite.frm1 component childsite]

        set types {
                {{All Files}	{*.*}}
        }
        
        ::euidl::fileinline $child.oFile \
                -buttontext [msgcat::mc "Browse ..."] \
                -defaultextension "lod" \
                -oper "open" \
                -filetypes $types \
                -title "Open *.lod" \
                -relative 0 \
                -variable [scope openFile] \
                -type ansys

             $child.oFile insert end $openFileDefault
             update

        grid $child.oFile
        grid $childsite.frm1 -column 0 -row 0 -sticky new

        # -------------------------------------------------------------
        # FRAME 2 RADIOBUTTON HOWTOIMPORT
        # -------------------------------------------------------------
        euidl::labeledframe $childsite.frm2 \
                -text [msgcat::mc "Import options"]

        set child [$childsite.frm2 component childsite]

        euidl::radiobutton $child.btHowTo0 \
                -variable  [scope how2import] -value 0 \
                -text [msgcat::mc "Import loads only"] \
                -anchor nw

        euidl::radiobutton $child.btHowTo1 \
                -variable  [scope how2import] -value 1 \
                -text [msgcat::mc "Add weak springs"] \
                -anchor nw

        if { $beta } {
        euidl::radiobutton $child.btHowTo2 \
                -wraplength 120 -justify left \
                -variable  [scope how2import] -value 2 \
                -text [msgcat::mc "Add weak springs, activate inertia relief"] \
                -anchor nw

        grid $child.btHowTo2 -row 2 -column 0 -columnspan 3 -sticky nw
        }

        grid $child.btHowTo0 -row 0 -column 0 -columnspan 3 -sticky nw
        grid $child.btHowTo1 -row 1 -column 0 -columnspan 3 -sticky nw

        grid $childsite.frm2 -column 0 -row 1 -sticky new


        # -------------------------------------------------------------
        # SHOW DIALOG
        # -------------------------------------------------------------
        uidl::registerWindow $parent
        update idletasks

        wm maxsize $parent [winfo reqwidth $parent] \
                           [winfo reqheight $parent]

        wm minsize $parent [winfo reqwidth $parent] \
                           [winfo reqheight $parent]

        $parent activate
    # -----------------------------------------------------------------
    # END OF PROC:           create
    }
    # -----------------------------------------------------------------

    # -----------------------------------------------------------------
    # PROC:           connect_ok
    #
    # Purpose:        End of Connection Dialog,
    #                 Transfer Variables to APDL
    #                 Close all Dialog windows
    #                 free grab
    # Arguments:      N/A
    # Comments:       N/A
    # See Also:       N/A
    # -----------------------------------------------------------------
    proc connect_ok {} {
        variable parent
        variable childsite
        variable child
        variable beta

        # -------------------------------------------------------------
        # VARIABLES SET BY DIALOG
        # -------------------------------------------------------------
        variable openFile
        variable openFilePath
        variable openFileDefault

        variable how2import
        variable loadStepFile
        variable loadStepFileDele
        variable loadStepFileRead

        focus -force $parent

       # -------------------------------------------------------------
       # SET LOADSTEP FILE DEFAULTS
       # -------------------------------------------------------------

        set loadStepFile [pwd]
        set loadStepFile ""
        for {set i 0} {$i <= 4} {incr i} {
           lappend loadStepFile [ans_getvalue ACTIVE,,JOBNAM,,START,[expr $i * 9]]
        }
        set loadStepFile [string trim [join $loadStepFile {}]]
        # -------------------------------------------------------------
        # IMPORT FROM ADAMS 2 ANSYS
        # -------------------------------------------------------------
        switch $how2import {
                0 {
                        apdl::noprint 1
                        catch {ans_sendcommand )/COM,}
                        set txt )/COM,***
                        append txt " "
                        append txt "Import loads only"
                        append txt " ***"
                        catch {ans_sendcommand $txt}
                        for {set i 1} {$i <= 99} {incr i} {
                            if {$i <= 9} {
                            set loadStepFileDele $loadStepFile.s0$i
                                if [file exists $loadStepFileDele] {
                                    file delete $loadStepFileDele
                                }
                            } elseif {$i > 9} {
                               set loadStepFileDele $loadStepFile.s$i
                                   if [file exists $loadStepFileDele] {
                                       file delete $loadStepFileDele
                                   }
                            }
                        }
                        catch {ans_sendcommand *DEL,_how2imp}
                        catch {ans_sendcommand /INPUT,$openFile}
                        apdl::noprint 0
                }
                1 { 
                        apdl::noprint 1
                        catch {ans_sendcommand )/COM,}
                        set txt )/COM,***
                        append txt " "
                        append txt "Add weak springs"
                        append txt " ***"
                        catch {ans_sendcommand $txt}
                        apdl::noprint 0
                        catch {ans_sendcommand WSPRINGS}
                        apdl::noprint 1
                        catch {ans_sendcommand /COM, !*}
                        #----------------------------------------------
                        # SOLUTION
                        #----------------------------------------------

                        for {set i 1} {$i <= 99} {incr i} {
                            if {$i <=9} {
                            set loadStepFileDele $loadStepFile.s0$i
                                if [file exists $loadStepFileDele] {
                                    file delete $loadStepFileDele
                                }
                            } elseif {$i > 9} {
                               set loadStepFileDele $loadStepFile.s$i
                                   if [file exists $loadStepFileDele] {
                                       file delete $loadStepFileDele
                                   }
                            }
                        }

                        catch {ans_sendcommand /INPUT,$openFile}
                        apdl::noprint 0
                        for {set i 1} {$i <= 99} {incr i} {
                            if {$i <= 9} {
                               set loadStepFileRead $loadStepFile.s0$i
                                   if [file exists $loadStepFileRead] {
                                       apdl::noprint 1
                                       catch {ans_sendcommand LSREAD,$loadStepFileRead}
                                       if { $beta } {
                                           catch {ans_sendcommand IRLF,0}
                                       } else {
                                           catch {ans_sendcommand IRLF,1}
                                       }
                                       apdl::noprint 0
                                       catch {ans_sendcommand SOLVE}
                                   }
                            } elseif {$i > 9} {
                               set loadStepFileRead $loadStepFile.s$i
                                   if [file exists $loadStepFileRead] {
                                       apdl::noprint 1
                                       catch {ans_sendcommand LSREAD,$loadStepFileRead}
                                       if { $beta } {
                                           catch {ans_sendcommand IRLF,0}
                                       } else {
                                           catch {ans_sendcommand IRLF,1}
                                       }
                                       apdl::noprint 0
                                       catch {ans_sendcommand SOLVE}
                                   }
                            }
                        }
                }
                2 { 
                        apdl::noprint 1
                        set txt )/COM,***
                        append txt " "
                        append txt "Add weak springs, activate inertia relief"
                        append txt " ***"
                        catch {ans_sendcommand $txt}
                        apdl::noprint 0
                        catch {ans_sendcommand WSPRINGS}
                        apdl::noprint 1
                        catch {ans_sendcommand /COM, !*}
                        #----------------------------------------------
                        # SOLUTION
                        #----------------------------------------------

                        for {set i 1} {$i <= 99} {incr i} {
                            if {$i <=9} {
                            set loadStepFileDele $loadStepFile.s0$i
                                if [file exists $loadStepFileDele] {
                                    file delete $loadStepFileDele
                                }
                            } elseif {$i > 9} {
                               set loadStepFileDele $loadStepFile.s$i
                                   if [file exists $loadStepFileDele] {
                                       file delete $loadStepFileDele
                                   }
                            }
                        }

                        catch {ans_sendcommand /INPUT,$openFile}
                        apdl::noprint 0
                        for {set i 1} {$i <= 99} {incr i} {
                            if {$i <=9} {
                               set loadStepFileRead $loadStepFile.s0$i
                                   if [file exists $loadStepFileRead] {
                                       apdl::noprint 1
                                       catch {ans_sendcommand LSREAD,$loadStepFileRead}
                                       catch {ans_sendcommand IRLF,1}
                                       apdl::noprint 0
                                       catch {ans_sendcommand SOLVE}
                                   }
                            } elseif {$i > 9} {
                               set loadStepFileRead $loadStepFile.s$i
                                   if [file exists $loadStepFileRead] {
                                       apdl::noprint 1
                                       catch {ans_sendcommand LSREAD,$loadStepFileRead}
                                       catch {ans_sendcommand IRLF,1}
                                       apdl::noprint 0
                                       catch {ans_sendcommand SOLVE}
                                   }
                            }
                        }
                }
        }

        # -------------------------------------------------------------
        # COMMENT MESSAGE
        # -------------------------------------------------------------
        apdl::noprint 1
        catch {ans_sendcommand )/COM,}
        catch {ans_sendcommand )/COM,********************************************}
        catch {ans_sendcommand )/COM,End of Connection ADAMS 2 ANSYS}
        apdl::noprint 0

        # -------------------------------------------------------------
        # FREE GRAB
        # -------------------------------------------------------------
        ans_greygui 0 1
        ans_greygui 1 1
        ans_greygui 3 1
        ans_greygui 4 1

        # -------------------------------------------------------------
        # END OF DIALOG
        # -------------------------------------------------------------
        if [winfo exists $parent] {
           $parent deactivate
        }
    # -----------------------------------------------------------------
    # END OF PROC:           connect_ok
    }
    # -----------------------------------------------------------------
    
    # -----------------------------------------------------------------
    # PROC:           connect_cancel
    #
    # Purpose:        End of Connection Dialog,
    #                 Transfer no Variables to APDL
    #                 Close all Dialog windows
    #                 free grab
    # Arguments:      N/A
    # Return Value:   N/A
    # Comments:       N/A
    # See Also:       N/A
    # -----------------------------------------------------------------
    proc connect_cancel {} {
        variable parent

        # -------------------------------------------------------------
        # COMMENT MESSAGE
        # -------------------------------------------------------------
        catch {ans_sendcommand )/COM,...canceled}
        catch {ans_sendcommand )/COM,********************************************}

        # -------------------------------------------------------------
        # FREE GRAB
        # -------------------------------------------------------------
        ans_greygui 0 1
        ans_greygui 1 1
        ans_greygui 3 1
        ans_greygui 4 1

        # -------------------------------------------------------------
        # END OF DIALOG
        # -------------------------------------------------------------
        if [winfo exists $parent] {
           $parent deactivate
        }
    # -----------------------------------------------------------------
    # END OF PROC:           connect_cancel
    }
    # -----------------------------------------------------------------


    # -----------------------------------------------------------------
    # PROC:           help
    #
    # Purpose:        Calls Ansys help
    # Arguments:      N/A
    # Return Value:   N/A
    # Comments:       N/A
    # See Also:       N/A
    # -----------------------------------------------------------------
    proc help {} {
            ans_loadhelp Hlp_UI_SOLU_ADVN
    # -----------------------------------------------------------------
    # END OF PROC:           help
    }
    # -----------------------------------------------------------------


# -------------------------------------------------------------
# END OF DIALOG
}
# -------------------------------------------------------------
#----------------------------------------------------------------------
#Authors              : Torsten Johne, CAD-FEM AG, Switzerland
#                       Wittenwilerstr. 25, CH-8355 Aadorf
#                       Fon +41 (052) 368 0101
#                       Fax +41 (052) 368 0109
#Filename             : adamsin2.eui Tk/Tcl Source
#additional Files     : 
#
#
#Version              : 1.1 02.07.2001
#Project              : G01-ANS-01
#Orderd from          : ANSYS Inc.
#Working              : Torsten Johne, Joern Nelz
#Representative       : Marc Brandenberger, Torsten Johne, Joern Nelz
#----------------------------------------------------------------------
#ANSYS RELEASE  57 Windows 2000
#----------------------------------------------------------------------
#Changes...............................................................
#  - revision 1.0 (19.05.2001) JN / TOJ, initial release
#  - revision 1.1 (02.07.2001) TOJ, create weak springs
#Description          :  Import ADAMS-Load-Files Dialog Part 2
#----------------------------------------------------------------------
# Connection ADAMS 2 ANSYS Initialization
#----------------------------------------------------------------------
package require msgcat
package require ansys
global env

# ---------------------------------------------------------------------
# GLOBAL NAMESPACE:  ::euidl::adamsin2
#
# Purpose:        This namespace creates the
#                 Connection ADAMS 2 ANSYS context
#
# Arguments:      N/A
#
# Return Value:   N/A
#
# Comments:       N/A
#
# See Also:       N/A
#
# ---------------------------------------------------------------------
namespace eval ::euidl::adamsin2 {

    # -----------------------------------------------------------------
    # GLOBALS
    # -----------------------------------------------------------------

    # -----------------------------------------------------------------
    # PROC:           springGen
    #
    # Purpose:        Generate weak springs
    #                 Define and add Elements and Realconstants
    # Arguments:      N/A
    # Return Value:   N/A
    # Comments:       N/A
    # See Also:       N/A
    # -----------------------------------------------------------------
    proc springGen {} {
        variable etnumx

        apdl::noprint 1
        catch {ans_sendcommand )/PREP7}
        catch {ans_sendcommand )ANTYPE,STATIC}
        #----------------------------------------------
        # INITIAL PARAMETERS FOR WEAK SPRINGS
        #----------------------------------------------
        set rlnumx [ans_evalexpr _rlnumx [catch {ans_sendcommand )_rlnumx=RLINQR(0,14)}]]
        set etnumx [ans_evalexpr _etnumx [catch {ans_sendcommand )_etnumx=ETYIQR(0,14)}]]
        set mpnumx [ans_evalexpr _mpnumx [catch {ans_sendcommand )_mpnumx=MPINQR(0,,14)}]]
        
        #----------------------------------------------
        # ADD NEW ELEMENTTYPES; WEAK SPRINGS
        #----------------------------------------------
        for {set i 1} { $i <= 3} {incr i} {
                catch {ans_sendcommand )ET,$etnumx+$i,14,,$i}
        }
        
        #----------------------------------------------
        # DEFINITION OF AVERAGED E-MODUL
        #----------------------------------------------
        set lmp_ex ""
        for {set i 1} {$i <= $mpnumx} {incr i} {
                lappend lmp_ex [ans_getvalue EX,$i]
        }

        set lmp_ex [lsort -increasing $lmp_ex]

        set mpExSum 0
        set ii 0
        set lmp_ex_num [llength $lmp_ex]
        for {set i 1} {$i <= $lmp_ex_num} {incr i} {
                set mpExSum [expr {$mpExSum+[lindex $lmp_ex $ii]}]
                set ii [expr $ii+1]
        }
        set mpExMid 0
        if {$lmp_ex_num > 0} {
           set mpExMid [expr $mpExSum/$lmp_ex_num]
        }
        #----------------------------------------------
        # SET GLOBAL ATTRIBUTES FOR WEAK SPRINGS
        #----------------------------------------------
        catch {ans_sendcommand )MAT,$mpnumx}
        catch {ans_sendcommand )REAL,$rlnumx+1}
        
        #----------------------------------------------
        # DEFINE BOUNDING BOX USING KARDAN / BRYANT ANGLES
        # DEFINITION INTERNAL BOUNDING BOX VECTOR
        #----------------------------------------------
        catch {ans_sendcommand )*DEL,_bbox_loc}
        catch {ans_sendcommand )*DIM,_bbox_loc,ARRAY,3,6}
        
        #----------------------------------------------
        # SET GLOBAL CARTESIAN COORDINATESYSTEM
        #----------------------------------------------
        set csysActive [ans_getvalue ACTIVE,0,CSYS]
        catch {ans_sendcommand )CSYS,0}
        catch {ans_sendcommand )WPCSYS,-1}
        catch {ans_sendcommand )CSYS,4}
        catch {ans_senderror 2 "Working plane is aligned with global \
                                cartesian coordinate system." }
        
        #----------------------------------------------
        # BOUNDING BOX BLOCK 1
        #----------------------------------------------
        catch {ans_sendcommand )CM,_nbase,NODE}
        catch {ans_sendcommand )CM,_ebase,ELEM}
        
        weak_spring 1
        
        #----------------------------------------------
        # BOUNDING BOX BLOCK 2
        #----------------------------------------------
        catch {ans_sendcommand )CSYS,4}
        catch {ans_sendcommand )WPROTA,90}
        catch {ans_sendcommand )CMSEL,S,_nbase}
        
        weak_spring 2

        #----------------------------------------------
        # BOUNDING BOX BLOCK 3
        #----------------------------------------------
        catch {ans_sendcommand )CSYS,4}
        catch {ans_sendcommand )WPROTA,,,90}
        catch {ans_sendcommand )CMSEL,S,_nbase}
        
        weak_spring 3

        #----------------------------------------------
        # SELECTION OF BASE MODEL AND WEAK SPRINGS
        #----------------------------------------------
        catch {ans_sendcommand )CMSEL,S,_ebase}
        catch {ans_sendcommand )CMSEL,S,_nbase}
        catch {ans_sendcommand )ESEL,A,TYPE,,$etnumx+1,$etnumx+6,1}
        catch {ans_sendcommand )NSLE}
        
        #----------------------------------------------
        # CHANGE REALCONSTANT FOR TORSIONAL SPRING
        #----------------------------------------------
#        catch {ans_sendcommand )ESEL,R,TYPE,,$etnumx+4,$etnumx+6,1}
#        catch {ans_sendcommand )EMODIF,ALL,REAL,$rlnumx+2}

        #----------------------------------------------
        # SELECTION OF BASE MODEL AND WEAK SPRINGS
        #----------------------------------------------
        catch {ans_sendcommand )CMSEL,S,_ebase}
        catch {ans_sendcommand )CMSEL,S,_nbase}
        catch {ans_sendcommand )ESEL,A,TYPE,,$etnumx+1,$etnumx+6,1}
        catch {ans_sendcommand )NSLE}

#----------------------------------------------
# BEGIN BOUNDING BOX EVALUATION
#----------------------------------------------
        #----------------------------------------------
        # DEFINITON OF MAXIMAL DIAGONAL
        #----------------------------------------------
#        for {set i 1} {$i <= 3} {incr i} {
#                catch {ans_sendcommand )_diag$i=DISTND(NODE(_bbox_loc($i,1),\
#                                                            _bbox_loc($i,2),\
#                                                            _bbox_loc($i,3)),\
#                                                        NODE(_bbox_loc($i,4),\
#                                                            _bbox_loc($i,5),\
#                                                            _bbox_loc($i,6)))}
#                set _diag$i [ans_evalexpr _diag$i]
#        }

#        set ldiag [list $_diag1 $_diag2 $_diag3]
#        set ldiag [lsort -decreasing $ldiag]
#        set lineDiagMax [lindex $ldiag 0]

        #----------------------------------------------
        # DEFINITON OF MINIMAL AREA
        #----------------------------------------------
#        catch {ans_sendcommand )_bboxl_1=DISTND(NODE(_bbox_loc(1,1),\
#                                                     _bbox_loc(1,2),\
#                                                     _bbox_loc(1,3)),\
#                                                 NODE(_bbox_loc(2,1),\
#                                                     _bbox_loc(2,2),\
#                                                     _bbox_loc(2,3)))}

#        catch {ans_sendcommand )_bboxl_2=DISTND(NODE(_bbox_loc(1,1),\
#                                                     _bbox_loc(1,2),\
#                                                     _bbox_loc(1,3)),\
#                                                 NODE(_bbox_loc(3,4),\
#                                                     _bbox_loc(3,5),\
#                                                     _bbox_loc(3,6)))}

#        catch {ans_sendcommand )_bboxl_3=DISTND(NODE(_bbox_loc(2,1),\
#                                                     _bbox_loc(2,2),\
#                                                     _bbox_loc(2,3)),\
#                                                 NODE(_bbox_loc(3,1),\
#                                                     _bbox_loc(3,2),\
#                                                     _bbox_loc(3,3)))}

#        for {set i 1} {$i <= 3} {incr i} {
#                set bboxl_$i [ans_evalexpr _bboxl_$i]
#        }

#        set bboxa_1 [expr $bboxl_1*$bboxl_2]
#        set bboxa_2 [expr $bboxl_2*$bboxl_3]
#        set bboxa_3 [expr $bboxl_1*$bboxl_3]

#        set lbboxarea [list $bboxa_1 $bboxa_2 $bboxa_3]
#        set lbboxarea [lsort -increasing $lbboxarea]
#        set areaBboxMin [lindex $lbboxarea 0]
#        set areaBboxMax [lindex $lbboxarea 2]

#        if {$areaBboxMin == 0} {
#                if {$areaBboxMax == 0} {
#                        set areaMin 1
#                } else {
#                        set areaMin $areaBboxMax
#                }
#        } else {
#                set areaMin $areaBboxMin
#        }

        #----------------------------------------------
        # REALDEFINITON FOR WEAK SPRINGS
        #----------------------------------------------
#        set realWeakSpring1 [expr  {$mpExMid\
#                                  *$areaMin\
#                                  /$lineDiagMax}]
#        set realWeakSpring2 [expr  {$mpExMid\
#                                  *$areaMin\
#                                  *$lineDiagMax}]
#        catch {ans_sendcommand )R,$rlnumx+2,$realWeakSpring2}

#----------------------------------------------
# END OF BOUNDING BOX EVALUATION
#----------------------------------------------

        #----------------------------------------------
        # REALDEFINITON FOR WEAK SPRINGS
        #----------------------------------------------
        set mpExMid [expr $mpExMid*1e-6]

        set realWeakSpring1 $mpExMid

        catch {ans_sendcommand )R,$rlnumx+1,$realWeakSpring1}

        catch {ans_sendcommand )CSYS,$csysActive}
        
        #----------------------------------------------
        # RESET OF ALL PARAMETERS
        #----------------------------------------------
        catch {ans_sendcommand )_rlnumx=}
        catch {ans_sendcommand )_etnumx=}
        catch {ans_sendcommand )_mpnumx=}
        catch {ans_sendcommand )_nfix=}
        catch {ans_sendcommand )_ebase=}
        catch {ans_sendcommand )_nbase=}
        catch {ans_sendcommand )_diag1=}
        catch {ans_sendcommand )_diag2=}
        catch {ans_sendcommand )_diag3=}
        catch {ans_sendcommand )_bboxl_1=}
        catch {ans_sendcommand )_bboxl_2=}
        catch {ans_sendcommand )_bboxl_3=}
        apdl::noprint 0

    # -----------------------------------------------------------------
    # END OF PROC:           SpringGen
    }
    # -----------------------------------------------------------------

    # -----------------------------------------------------------------
    # PROC:           weakl_spring
    #
    # Purpose:        Define Bounding box and generate weak springs
    # Arguments:      a   vector position: should be 1 or 2 or 3
    # Return Value    N/A
    # Comments:       N/A
    # See Also:       N/A
    # -----------------------------------------------------------------
   proc weak_spring {a} {
        variable etnumx
 
        apdl::noprint 1
        catch {ans_sendcommand )CSYS,4}	
        catch {ans_sendcommand )CMSEL,S,_nbase}
        set ndnumx [ans_evalexpr _ndnumx [catch {ans_sendcommand )_ndnumx=NDINQR(0,12)}]]
        if {$ndnumx == 0} {
           return
        }
        set xlocmn [ans_getvalue NODE,0,MNLOC,X]
        catch {ans_sendcommand )NSEl,R,LOC,X,$xlocmn}
        set ndnumx [ans_evalexpr _ndnumx [catch {ans_sendcommand )_ndnumx=NDINQR(0,12)}]]
        if {$ndnumx == 0} {
           return
        }
        set ylocmn [ans_getvalue NODE,0,MNLOC,Y]
        catch {ans_sendcommand )NSEl,R,LOC,Y,$ylocmn}
        set ndnumx [ans_evalexpr _ndnumx [catch {ans_sendcommand )_ndnumx=NDINQR(0,12)}]]
        if {$ndnumx == 0} {
           return
        }
        set zlocmn [ans_getvalue NODE,0,MNLOC,Z]
        catch {ans_sendcommand )NSEl,R,LOC,Z,$zlocmn}
        set nh1 [ans_getvalue NODE,0,NUM,MIN]
        set nodeNumMax [ans_evalexpr _nnumx [catch {ans_sendcommand )_nnumx=NDINQR(0,14)}]]
        catch {ans_sendcommand )N,$nodeNumMax+1,NX($nh1),NY($nh1),NZ($nh1)}
        for {set i 1} {$i <= 3} {incr i} {
                catch {ans_sendcommand )   TYPE,$etnumx+$i}
                catch {ans_sendcommand )   E,$nh1,$nodeNumMax+1}
        }
        catch {ans_sendcommand )D,$nodeNumMax+1,UX,,,,,UY,UZ}
        catch {ans_sendcommand )CSYS,0}
        catch {ans_sendcommand )_bbox_loc($a,1)=NX($nodeNumMax+1)}
        catch {ans_sendcommand )_bbox_loc($a,2)=NY($nodeNumMax+1)}
        catch {ans_sendcommand )_bbox_loc($a,3)=NZ($nodeNumMax+1)}
        
        catch {ans_sendcommand )CSYS,4}	
        catch {ans_sendcommand )CMSEL,S,_nbase}
        set xlocmx [ans_getvalue NODE,0,MXLOC,X]
        catch {ans_sendcommand )NSEl,R,LOC,X,$xlocmx}
        set ylocmx [ans_getvalue NODE,0,MXLOC,Y]
        catch {ans_sendcommand )NSEl,R,LOC,Y,$ylocmx}
        set zlocmx [ans_getvalue NODE,0,MXLOC,Z]
        catch {ans_sendcommand )NSEl,R,LOC,Z,$zlocmx}
        set nh1 [ans_getvalue NODE,0,NUM,MIN]
        set nodeNumMax [ans_evalexpr _nnumx [catch {ans_sendcommand )_nnumx=NDINQR(0,14)}]]
        catch {ans_sendcommand )N,$nodeNumMax+1,NX($nh1),NY($nh1),NZ($nh1)}
        for {set i 1} {$i <= 3} {incr i} {
                catch {ans_sendcommand )   TYPE,$etnumx+$i}
                catch {ans_sendcommand )   E,$nh1,$nodeNumMax+1}
        }
        catch {ans_sendcommand )D,$nodeNumMax+1,UX,,,,,UY,UZ}
        catch {ans_sendcommand )CSYS,0}
        catch {ans_sendcommand )_bbox_loc($a,4)=NX($nodeNumMax+1)}
        catch {ans_sendcommand )_bbox_loc($a,5)=NY($nodeNumMax+1)}
        catch {ans_sendcommand )_bbox_loc($a,6)=NZ($nodeNumMax+1)}
        apdl::noprint 0

    # -----------------------------------------------------------------
    # END OF PROC:           weak_spring
    }
    # -----------------------------------------------------------------

# -------------------------------------------------------------
# END OF DIALOG
}
# -------------------------------------------------------------
#----------------------------------------------------------------------
#Authors              : Joern Nelz, CAD-FEM GmbH, GS Hannover
#                       Schmiedestr. 31, D-31303 Burgdorf
#                       Fon 0 51 36 / 8 80 92 14
#                       Fax 0 51 36 / 89 32 69
#                     : Torsten Johne, CAD-FEM AG, Switzerland
#                       Wittenwilerstr. 25, CH-8355 Aadorf
#                       Fon +41 (052) 368 0101
#                       Fax +41 (052) 368 0109
#Filename             : adamsout.eui Tk/Tcl Source
#additional Files     : UifuADAM.grn Granule file
#
#Version              : 1.4 11.06.2001
#Project              : G01-ANS-01
#Orderd from          : ANSYS Inc.
#Working              : Torsten Johne, Joern Nelz
#Representative       : Marc Brandenberger, Torsten Johne, Joern Nelz
#----------------------------------------------------------------------
#ANSYS RELEASE  57 Windows NT 4.0(5) CELSIUS mobile-jn
#----------------------------------------------------------------------
#Changes...............................................................
#  - revision 1.0 (07.05.2001) jn, initial release
#  - revision 1.1 (29.05.2001) jn, fileinline and other formats
#  - revision 1.2 (29.05.2001) jn, create and connect_ok
#  - revision 1.3 (30.05.2001) toj, File Handling Part 1 and 2; Save *.dbmnf
#  - revision 1.4 (11.06.2001) toj, Save *.dbmnf
#  - revision 1.5 (14.09.2001) toj, Keeping the User/UNITS
#  - revision 1.6 (18.09.2001) jlo, Get rid of rc file - use msgcat
#  - revision 1.7 (01.10.2001) TOJ, Make annotations on attachment nodes
#
#Description            Export ADAMS-MNF-Files Dialog

#----------------------------------------------------------------------
# Connection ANSYS 2 ADAMS Initialization
#----------------------------------------------------------------------
package require ansys
package require msgcat
global env

# ---------------------------------------------------------------------
# GLOBAL NAMESPACE:  ::euidl::adamsout
#
# Purpose:        This namespace creates the
#                 Connection ANSYS 2 ADAMS context
#
# Arguments:      N/A
#
# Return Value:   N/A
#
# Comments:       N/A
#
# See Also:       N/A
#
# ---------------------------------------------------------------------
namespace eval ::euidl::adamsout {

    # -----------------------------------------------------------------
    # GLOBALS
    # -----------------------------------------------------------------
    # release
    variable version 1.7

    # make beta feature available (Include Element Stress)
    variable beta FALSE

    # -----------------------------------------------------------------
    # PROC:           annotation
    #
    # Purpose:        Makes annotations on attachment nodes
    # Arguments:      N/A
    # Return Value:   N/A
    # Comments:       N/A
    # See Also:       N/A
    # -----------------------------------------------------------------
    proc annotation {} {
        apdl::noprint 1
        catch {set activCsys [ans_getvalue active,,csys]}
        catch {set ncount [ans_getvalue node,0,count]}
        catch { ans_sendcommand )CM,nh1,NODE}
        catch { ans_sendcommand )CSYS,0}
        for {set i 1} {$i <= $ncount} {incr i} {
            catch {set nmx [ans_getvalue node,,num,max]}
            set nmx_x [ans_evalexpr _nmx_x [catch {ans_sendcommand )_nmx_x=nx($nmx)}]]
            set nmx_y [ans_evalexpr _nmx_y [catch {ans_sendcommand )_nmx_y=ny($nmx)}]]
            set nmx_z [ans_evalexpr _nmx_z [catch {ans_sendcommand )_nmx_z=nz($nmx)}]]
            catch { ans_sendcommand )/TSPEC,12,1,1}
            catch { ans_sendcommand )/AN3D,ANUM,0,101}
            catch { ans_sendcommand )/AN3D,TEXT,$nmx_x+1,$nmx_y+1,$nmx_z,Attachment Node $i}
            catch { ans_sendcommand )/LSPEC,12}
            catch { ans_sendcommand )/AN3D,ANUM,0,106}
            catch { ans_sendcommand )/AN3D,SYMB,3,$nmx_x,$nmx_y,$nmx_z,0.5}
            catch { ans_sendcommand )NSEL,u,,,$nmx}
            catch { ans_sendcommand )_nmx_x=}
            catch { ans_sendcommand )_nmx_y=}
            catch { ans_sendcommand )_nmx_z=}
        }
        catch { ans_sendcommand )CMSEL,,nh1}
        catch { ans_sendcommand )CMDELE,nh1}
        catch { ans_sendcommand )/REPL}
        catch { ans_sendcommand )/TSPEC,15,1,1}
        catch { ans_sendcommand )CSYS,$activCsys}
        apdl::noprint 0
    # -----------------------------------------------------------------
    # END OF PROC:           annotation
    }
    # -----------------------------------------------------------------

    # -----------------------------------------------------------------
    # PROC:           entry
    #
    # Purpose:        Entry point to the ADAMS interface
    # Arguments:      N/A
    # Return Value:   N/A
    # Comments:       N/A
    # See Also:       N/A
    # -----------------------------------------------------------------
    proc entry {} {
      apdl::noprint 1

      set _enmx [ans_evalexpr elmiqr(0,12)]
      set _ensel [ans_evalexpr elmiqr(0,13)]
      if {$_enmx > $_ensel} {
         ans_senderror 1 [msgcat::mc "Only the selected elements\
               will be transferred to ADAMS!"]
      }
      if {[ans_getvalue PARM,_eigenmodesCount,TYPE] == -1} {
         ans_sendcommand _eigenmodesCount=6
      }
      if {[ans_getvalue PARM,_elemresult,TYPE] == -1} {
         ans_sendcommand _elemresult=0
      }
      if {[ans_getvalue PARM,faktorL,TYPE] == -1} {
         ans_sendcommand _faktorL=1.0
         ans_sendcommand _faktorF=1.0
         ans_sendcommand _faktorM=1.0
         ans_sendcommand _faktorT=1.0
      }
      apdl::noprint 0

      after 500 [list uidl::callFnc Fnc_ADAMSOUT1 [code nodeSelReturn]]
    }

    proc nodeSelReturn { uidlButton } {
      switch -- $uidlButton {
         0 { #OK
            create
         }
         1 { #Cancel
         }
         2 { #Apply
            ans_sendcommand Fnc_RemoveDialogs
            create
         }
      }
    }

    # -----------------------------------------------------------------
    # PROC:           create
    #
    # Purpose:        Creates the toplevel widget and all the children
    # Arguments:      N/A
    # Return Value:   N/A
    # Comments:       N/A
    # See Also:       N/A
    # -----------------------------------------------------------------
    proc create {} {
        annotation

        variable parent
        variable childsite
        variable child

        variable beta

        # -------------------------------------------------------------
        # GRAB
        # -------------------------------------------------------------
        ans_greygui 0 0
        ans_greygui 1 0
        ans_greygui 3 0
        ans_greygui 4 0

        # -------------------------------------------------------------
        # VARIABLES SET BY DIALOG
        # -------------------------------------------------------------
        # in the first run they will be initialized, and in the following
        # runs the user input is used as default values
        variable eigenmodesCount
        variable units
        variable elemresult
        variable shelresult
        variable faktorL
        variable faktorF
        variable faktorM
        variable faktorT

        variable saveFile

        # -------------------------------------------------------------
        # INTERNAL VARIABLES
        # -------------------------------------------------------------
        variable saveFileDefault

        set saveFileDefault ""
        for {set i 0} {$i <= 4} {incr i} {
            lappend saveFileDefault [ans_getvalue ACTIVE,,JOBNAM,,START,[expr $i * 9]]
        }
        set saveFileDefault [string trim [join $saveFileDefault {}]]
        set saveFileDefault "./$saveFileDefault.mnf"

        # -------------------------------------------------------------
        # COMMENT MESSAGE
        # -------------------------------------------------------------
        apdl::noprint 1
        catch {ans_sendcommand )/COM,}
        catch {ans_sendcommand )/COM,********************************************}
        catch {ans_sendcommand )/COM,Use Connection ANSYS 2 ADAMS}
        apdl::noprint 0

        # -------------------------------------------------------------
        # GET VALUES FROM DB
        # ------------------------------------------------------------
        catch {set avail [ans_getvalue parm,_eigenmodesCount,TYPE]}
        apdl::noprint 1
        if { $avail == -1} { catch {ans_sendcommand )*SET,_eigenmodesCount,6} }
        if {[catch {set eigenmodesCount [ans_getvalue parm,_eigenmodesCount,value]}]} {
            #default value
            set eigenmodesCount 6
        }
        apdl::noprint 0

        set units  [ans_getvalue ACTIVE,0,UNITS]
        if { $units == -1 } {
            set units 1
        }

        catch {set avail [ans_getvalue parm,_elemresult,TYPE]}
        apdl::noprint 1
        if { $avail == -1} { catch {ans_sendcommand )*SET,_elemresult,0} }
        if {[catch {set elemresult  [ans_getvalue parm,_elemresult,value]}]} {
            #default value
            set elemresult 0
        }

        catch {set avail [ans_getvalue parm,_shelresult,TYPE]}
        apdl::noprint 1
        if { $avail == -1} { catch {ans_sendcommand )*SET,_shelresult,0} }
        if {[catch {set shelresult  [ans_getvalue parm,_shelresult,value]}]} {
            #default value
            set shelresult 0
        }

        catch {set faktorL [ans_getvalue common,,soptcm,,real,11]}
        catch {set faktorM [ans_getvalue common,,soptcm,,real,12]}
        catch {set faktorT [ans_getvalue common,,soptcm,,real,13]}
        catch {set faktorF [ans_getvalue common,,soptcm,,real,17]}

        # -------------------------------------------------------------
        # CREATE TOPLEVEL
        # -------------------------------------------------------------
        if [winfo exists .adamsOut] {
            wm deiconify $parent
            raise $parent
            return
        }

        set parent [euidl::dialog .adamsOut -class EUIDL]
        set childsite [$parent component childsite]
        set childsite [frame $childsite.doA2A -class AdamsOut]
        pack $childsite -expand true

        wm title $parent [msgcat::mc "Export to ADAMS"]

        $parent configure                                         \
                -okbutton 0                                       \
                -okcommand [namespace code connect_ok]            \
                -cancelcommand [namespace code connect_cancel]    \
                -helpcommand [list ans_loadhelp Hlp_G_ADVexad]

        # -------------------------------------------------------------
        # FRAME 1 COMBOBOX UNITS
        # -------------------------------------------------------------
        euidl::labeledframe $childsite.frm1 \
                -text [msgcat::mc "System of Model Units"]
        set child [$childsite.frm1 component childsite]

            euidl::combobox $child.comboUnits \
                -width 28
            $child.comboUnits insert list end            \
                [list {USER     defined} 0               \
                      {SI       m-kg-s-Centigrade} 1     \
                      {CGS      cm-g-s-Centigrade} 2     \
                      {BFT      foot-slug-s-Farenheit} 3 \
                      {BIN      inch-(lbf-s**2/inch)-s-Farenheit} 4  \
                ]
                $child.comboUnits configure \
                -variable [scope units] \
                -command  [code setUserUnitPre]

        grid $childsite.frm1 -column 0 -row 0 -sticky new
        pack $child.comboUnits

        # -------------------------------------------------------------
        # FRAME 2 ENTRY EIGENMODES
        # -------------------------------------------------------------
        euidl::labeledframe $childsite.frm2 \
                -text [msgcat::mc "Eigenmodes"]
        set child [$childsite.frm2 component childsite]

        euidl::label $child.label -height 1 \
                -text [msgcat::mc "Number of Modes to extract"]
        euidl::entry  $child.entry -width 10  \
                -variable [scope eigenmodesCount] \
                -validate focusout                \
                -validatedata ansinteger

        grid $child.label -row 0 -column 0
        grid $child.entry -row 0 -column 1
        grid $childsite.frm2 -column 0 -row 1 -sticky new

        # -------------------------------------------------------------
        # FRAME 3 COMBOBOX ELEMENT RESULTS
        # -------------------------------------------------------------
        euidl::labeledframe $childsite.frm3 \
                -text [msgcat::mc "Element Results"]
        set child [$childsite.frm3 component childsite]

            euidl::combobox $child.comboElemResult \
                -width 28
            $child.comboElemResult insert list end       \
                [list {Include no Stress and Strain} 0   \
                      {Include Stress} 1     \
                      {Include Strain} 2     \
                      {Include Stress and Strain} 3 \
                ]
                $child.comboElemResult configure \
                -variable [scope elemresult]

        grid $childsite.frm3 -column 0 -row 2 -sticky new
        pack $child.comboElemResult

        # -------------------------------------------------------------
        # FRAME 4 COMBOBOX SHELL RESULTS
        # -------------------------------------------------------------
        euidl::labeledframe $childsite.frm4 \
                -text [msgcat::mc "Shell Element Result Output Control"]
        set child [$childsite.frm4 component childsite]

            euidl::combobox $child.comboShelResult \
                -width 28
            $child.comboShelResult insert list end       \
                [list {Shell Top Surface} 0   \
                      {Shell Middle Surface} 2     \
                      {Shell Bottom Surface} 3     \
                ]
                $child.comboShelResult configure \
                -variable [scope shelresult]

        grid $childsite.frm4 -column 0 -row 3 -sticky new
        pack $child.comboShelResult


        # -------------------------------------------------------------
        # FRAME 5 GUI FILENAME
        # -------------------------------------------------------------
        euidl::labeledframe $childsite.frm5 \
                -text [msgcat::mc "Filename"]
        set child [$childsite.frm5 component childsite]

        set types {
            {{ADAMS Files}  {.mnf}}
        }


            euidl::fileinline $child.sFile \
                -variable [scope saveFile] \
                -takefocus 1               \
                -buttontext [msgcat::mc "Browse ..."] \
                -defaultextension "mnf"    \
                -oper save                 \
                -filetypes $types          \
                -title "Save MNF As"       \
                -relative 1                \
                -type normal

            $child.sFile insert end $saveFileDefault
            update

        grid $child.sFile
        grid $childsite.frm5 -column 0 -row 4 -sticky new


        # -------------------------------------------------------------
        # FRAME 6 SOLVE AND CREATE EXPORT FILE TO ADAMS => BUTTON
        # -------------------------------------------------------------
        euidl::labeledframe $childsite.frm6 \
                -text [msgcat::mc "Export to ADAMS"]

        set child [$childsite.frm6 component childsite]

        euidl::button $child.btnSolCreaFile \
                -text [msgcat::mc "Solve and create export file to ADAMS"] \
                -command  [namespace code connect_ok] 

        grid $child.btnSolCreaFile
        grid $childsite.frm6 -column 0 -row 5 -sticky new

        # -------------------------------------------------------------
        # SHOW DIALOG
        # -------------------------------------------------------------
        uidl::registerWindow $parent
        update idletasks

        wm minsize $parent [winfo reqwidth $parent] \
                           [winfo reqheight $parent]

        wm maxsize $parent [winfo reqwidth $parent] \
                           [winfo reqheight $parent]

        $parent activate

    # -----------------------------------------------------------------
    # END OF PROC:           create
    }
    # -----------------------------------------------------------------


    # -----------------------------------------------------------------
    # PROC:           setUserUnitPre
    #
    # Purpose:        Calls Proc setUserUnit if USER-Units is choosen
    # Arguments:      N/A
    # Return Value:   N/A
    # Comments:       N/A
    # See Also:       N/A
    # -----------------------------------------------------------------
    proc setUserUnitPre {} {
        variable units

        switch $units {
            0 {
                setUserUnit
            }
        }
    # -----------------------------------------------------------------
    # END OF PROC:           setUserUnitPre
    }
    # -----------------------------------------------------------------


    # -----------------------------------------------------------------
    # PROC:           setUserUnit
    #
    # Purpose:        Creates widget for User Unit factors
    # Arguments:      N/A
    # Return Value:   faktorL           real
    #                 faktorM           real
    #                 faktorF           real
    #                 faktorT           real
    # Comments:       N/A
    # See Also:       N/A
    # -----------------------------------------------------------------
    proc setUserUnit {} {
        variable childsite
        variable parent2
        variable childsite2
        variable child2

        # -------------------------------------------------------------
        # VARIABLES SET BY DIALOG
        # -------------------------------------------------------------
        variable faktorL
        variable faktorF
        variable faktorM
        variable faktorT

        # -------------------------------------------------------------
        # CREATE TOPLEVEL
        # -------------------------------------------------------------
        if [winfo exists .dsetUserUnitgo] {
            $parent2 activate
            return
        }

        set parent2 [euidl::dialog .dsetUserUnitgo \
            -class EUIDL -grabwin this]

        set childsite2 [$parent2 component childsite]
        set childsite2 [frame $childsite2.doA2A -class AdamsOut]
        pack $childsite2 -fill both -expand true


        $parent2 configure \
            -okcommand [code destroy $parent2] \
            -cancelcommand [code destroy $parent2] \
            -canceltext [option get $childsite cancelText {}] \
            -helpcommand [list ans_loadhelp Hlp_C_/UNITS]
        #    -helptext [option get $childsite helpText {}]

        wm title $parent2 [msgcat::mc "Define User Unit"]

        # -------------------------------------------------------------
        # FRAME 1 ENTRY FACTORS
        # -------------------------------------------------------------
        euidl::labeledframe $childsite2.frm6 \
                 -text [msgcat::mc "User defined System of Unit"]
        set child2 [$childsite2.frm6 component childsite]

        euidl::label $child2.lblL -height 3 -text [msgcat::mc " Length Factor"]
        euidl::entry  $child2.cmbL -width 10 \
                 -variable [scope faktorL]   \
                 -validate focusout          \
                 -validatedata ansreal
        euidl::label $child2.lblM -height 3 -text [msgcat::mc " Mass Factor"]
        euidl::entry  $child2.cmbM -width 10 \
                 -variable [scope faktorM]   \
                 -validate focusout          \
                 -validatedata ansreal
        euidl::label $child2.lblF -height 3 -text [msgcat::mc " Force Factor"]
        euidl::entry  $child2.cmbF -width 10 \
                 -variable [scope faktorF]   \
                 -validate focusout          \
                 -validatedata ansreal
        euidl::label $child2.lblT -height 3 -text [msgcat::mc " Time Factor"]
        euidl::entry  $child2.cmbT -width 10 \
                 -variable [scope faktorT]   \
                 -validate focusout          \
                 -validatedata ansreal


        grid $child2.lblL -row 0 -column 0
        grid $child2.cmbL -row 0 -column 1
        grid $child2.lblM -row 1 -column 0
        grid $child2.cmbM -row 1 -column 1
        grid $child2.lblF -row 2 -column 0
        grid $child2.cmbF -row 2 -column 1
        grid $child2.lblT -row 3 -column 0
        grid $child2.cmbT -row 3 -column 1

        grid $childsite2.frm6 -column 0 -row 1 -sticky new

        # -------------------------------------------------------------
        # SHOW DIALOG
        # -------------------------------------------------------------
        update idletasks
        wm minsize $parent2 [winfo reqwidth $parent2] \
                            [winfo reqheight $parent2]

        wm maxsize $parent2 [winfo reqwidth $parent2] \
                            [winfo reqheight $parent2]

        $parent2 activate
    # -----------------------------------------------------------------
    # END OF PROC:           setUserUnit
    }
    # -----------------------------------------------------------------


    # -----------------------------------------------------------------
    # PROC:           connect_ok
    #
    # Purpose:        End of Connection Dialog,
    #                 Transfer Variables to APDL
    #                 Close all Dialog windows
    #                 free grab
    # Arguments:      N/A
    # Return Value:   units             (si, cgs, bin, bft, user)
    #                 eigenmodesCount   integer
    #                 elemresult        integer (1, 0)
    #                 faktorL           real
    #                 faktorM           real
    #                 faktorF           real
    #                 faktorT           real
    # Comments:       N/A
    # See Also:       N/A
    # -----------------------------------------------------------------
    proc connect_ok {} {
        variable parent
        variable childsite
        variable child

        variable beta

        # -------------------------------------------------------------
        # VARIABLES SET BY DIALOG
        # -------------------------------------------------------------
        variable units
        variable eigenmodesCount
        variable elemresult
        variable shelresult
        variable faktorL
        variable faktorF
        variable faktorM
        variable faktorT

        variable saveFile
        variable saveFile1
        variable fileExt
        variable saveFileName
        variable origFile
        variable origFileName
        variable origFilePath

        # -------------------------------------------------------------
        # CHECK FOR INCORRECT INPUT
        # -------------------------------------------------------------
        # because there is no ok-button in the parent frame
        # we have to eval the valid entries manual
        focus $parent
        update
        if { [euidl::errHandler::getStatus] == 1} {
            return
        }
        euidl::errHandler::removeBalloon

        focus -force $parent

        apdl::noprint 1

        # -------------------------------------------------------------
        # SET VARIABLE eigenmodesCount
        # -------------------------------------------------------------
        catch {ans_sendcommand )/COM,}
        set txt )/COM,***
        append txt " "
        append txt [option get $childsite.frm2.label text {}]
        append txt "  $eigenmodesCount"
        append txt " ***"
        catch {ans_sendcommand $txt}
        catch { ans_sendcommand )*SET,_eigenmodesCount,$eigenmodesCount }

        # -------------------------------------------------------------
        # SET UNITS
        # -------------------------------------------------------------
        catch {ans_sendcommand )/COM,}
        set txt )/COM,***
        append txt " "
        append txt [option get $childsite.frm1 text {}]
        append txt " ***"
        catch {ans_sendcommand $txt}
        apdl::noprint 0
        switch $units {
            0 {
                catch {ans_sendcommand /UNIT,USER,$faktorL,$faktorM,$faktorT,,,,$faktorF}
                apdl::noprint 1
                catch { ans_sendcommand )*SET,_faktorL,$faktorL }
                catch { ans_sendcommand )*SET,_faktorM,$faktorM }
                catch { ans_sendcommand )*SET,_faktorT,$faktorT }
                catch { ans_sendcommand )*SET,_faktorF,$faktorF }
                apdl::noprint 0
            }
            1 {
                catch {ans_sendcommand /UNIT,SI}
            }
            2 {
                catch {ans_sendcommand /UNIT,CGS}
            }
            3 {
                catch {ans_sendcommand /UNIT,BFT}
            }
            4 {
                catch {ans_sendcommand /UNIT,BIN}
            }
        }
        apdl::noprint 1

        # -------------------------------------------------------------
        # SET VARIABLE elemresult
        # -------------------------------------------------------------
        if {$elemresult == 0} {
           set child [$childsite.frm3 component childsite]
           catch {ans_sendcommand )/COM,}
           set txt ")/COM,*** "
           append txt " include no stress and strain "
           append txt " ***"
           catch {ans_sendcommand $txt}
           apdl::noprint 1
           catch { ans_sendcommand )*SET,_elemresult,$elemresult }
           apdl::noprint 0
        } elseif {$elemresult == 1} {
           set child [$childsite.frm3 component childsite]
           catch {ans_sendcommand )/COM,}
           set txt ")/COM,*** "
           append txt " include stress "
           append txt " ***"
           catch {ans_sendcommand $txt}
           apdl::noprint 1
           catch { ans_sendcommand )*SET,_elemresult,$elemresult }
           apdl::noprint 0
        } elseif {$elemresult == 2} {
           set child [$childsite.frm3 component childsite]
           catch {ans_sendcommand )/COM,}
           set txt ")/COM,*** "
           append txt " include strain "
           append txt " ***"
           catch {ans_sendcommand $txt}
           apdl::noprint 1
           catch { ans_sendcommand )*SET,_elemresult,$elemresult }
           apdl::noprint 0
        } else {
           set child [$childsite.frm3 component childsite]
           catch {ans_sendcommand )/COM,}
           set txt ")/COM,*** "
           append txt " include stress and strain "
           append txt " ***"
           catch {ans_sendcommand $txt}
           apdl::noprint 1
           catch { ans_sendcommand )*SET,_elemresult,$elemresult }
           apdl::noprint 0
        }
        apdl::noprint 0

        # -------------------------------------------------------------
        # SET VARIABLE shelresult
        # -------------------------------------------------------------
        if {$shelresult == 2} {
           set child [$childsite.frm4 component childsite]
           catch {ans_sendcommand )/COM,}
           set txt ")/COM,*** "
           append txt " Output shell element result at middle surface "
           append txt " ***"
           catch {ans_sendcommand $txt}
           apdl::noprint 1
           catch { ans_sendcommand )*SET,_shelresult,$shelresult }
           apdl::noprint 0
        } elseif {$shelresult == 3} {
           set child [$childsite.frm4 component childsite]
           catch {ans_sendcommand )/COM,}
           set txt ")/COM,*** "
           append txt " Output shell element result at bottom surface "
           append txt " ***"
           catch {ans_sendcommand $txt}
           apdl::noprint 1
           catch { ans_sendcommand )*SET,_shelresult,$shelresult }
           apdl::noprint 0
        } else {
           set child [$childsite.frm4 component childsite]
           catch {ans_sendcommand )/COM,}
           set txt ")/COM,*** "
           append txt " Output shell element result at top surface "
           append txt " ***"
           catch {ans_sendcommand $txt}
           apdl::noprint 1
           catch { ans_sendcommand )*SET,_shelresult,$shelresult }
           apdl::noprint 0
        }
        apdl::noprint 0

        # -------------------------------------------------------------
        # FILE HANDLING PART 1
        # -------------------------------------------------------------
        # ADAMS.MAC writes in any case the file jobname.mnf, to
        # prevent overwriting save old jobname.mnf as jobname.mnfbak
        set origFilePath [pwd]
        set origFile ""
        for {set i 0} {$i <= 4} {incr i} {
            lappend origFile [ans_getvalue ACTIVE,,JOBNAM,,START,[expr $i * 9]]
        }

        set origFile [string trim [join $origFile {}]]
        set origFileName ./$origFile.mnf

        if {[string compare $origFileName $saveFile] == 0} { 
                if [file exists $origFileName] {
                        if [file exists $origFile.mnfbak] {
                        file delete $origFile.mnfbak
                        }
                file rename $origFileName $origFile.mnfbak
                }
        } else {
                if [file exists $origFileName] {
                        if [file exists $origFile.mnftmp] {
                        file delete $origFile.mnftmp
                        }
                file rename $origFileName $origFile.mnftmp
                }
        }

        # -------------------------------------------------------------
        # MAKE A SAVE OF THE MODEL AS JOBNAME.DBMNF
        # -------------------------------------------------------------
        apdl::noprint 1
        catch {ans_sendcommand )/COM,}
        catch {ans_sendcommand )/COM,********************************************}
        catch {ans_sendcommand )/COM,Model will be saved as "$origFile.dbmnf"}
        catch {ans_sendcommand )/COM,********************************************}
        catch {ans_sendcommand )CM,_nh1,NODE}
        catch {ans_sendcommand )NSLE}
        apdl::noprint 0
        if [file exists $origFile.dbmnf] {
        	file delete $origFile.dbmnf
        }	
        catch {ans_sendcommand )SAVE,'$origFile','dbmnf' }
        apdl::noprint 1
        catch {ans_sendcommand )CMSEL,,_nh1}
        catch {ans_sendcommand )_nh1=}
        apdl::noprint 0

        # -------------------------------------------------------------
        # START ADAMS.MAC (SOLVE AND EXPORT *.mnf FILE)
        # -------------------------------------------------------------
        apdl::noprint 1
        catch {ans_sendcommand )/COM,}
        set txt )/COM,***
        append txt " "
        append txt [option get $childsite.frm6.childsite.btnSolCreaFile text {}]
        append txt " ***"
        catch {ans_sendcommand $txt}
        set txt )/COM,***
        append txt " The MNF file will be saved to"
        catch {ans_sendcommand $txt}
        set txt )/COM,***
        append txt " "
        append txt [file join $saveFile]
        append txt " ***"
        catch {ans_sendcommand $txt}

        catch {ans_sendcommand )_nmaxdef=ndinqr(0,14)}
        catch {ans_sendcommand )_nselect=ndinqr(0,13)}
        catch {set nmaxdef  [ans_getvalue parm,_nmaxdef,value]}
        catch {set nselect  [ans_getvalue parm,_nselect,value]}
        if { $nselect < $nmaxdef && $nselect != 1} {
            catch {ans_sendcommand ADAMS,$eigenmodesCount,$elemresult,$shelresult}
            set nomnf 0
        } elseif { $nselect >= $nmaxdef } {
            catch {ans_senderror 3 "There were $nselect of $nmaxdef \
                    nodes selected. There are no DOFs available. \n\n \
                    The ANSYS to ADAMS Connection is aborted."}
            set nomnf 1
        } elseif { $nselect == 1 || $nselect == 1} {
            catch {ans_senderror 3 "There were $nselect of $nmaxdef \
                    nodes selected. The Minimum is 2. \n\n \
                    The ANSYS to ADAMS Connection is aborted."}
            set nomnf 1
        }

        apdl::noprint 0

        # -------------------------------------------------------------
        # FILE HANDLING PART 2
        # -------------------------------------------------------------

        if { $nomnf == 0 } {
            catch {file rename -force [file join [pwd] $origFileName] \
            [file join $saveFile]} err
        }

        if [file exists $origFile.mnftmp] {
            catch {file rename $origFile.mnftmp $origFile.mnf } err
        }

        if [file exists $saveFile.mnf] {
                if [file exists $saveFile.mnfbak] {
                catch {file delete $saveFile.mnfbak } err
                }
                catch {file rename $saveFile.mnf $saveFile.mnfbak } err
        }

        if [file exists $saveFile] {
                if {[file extension $saveFile] == ".mnf"} {	
                } else {
                catch {file rename $saveFile $saveFile.mnf} err
                }
        }

        apdl::noprint 1
        catch {ans_sendcommand )/COM,End of Connection ANSYS to ADAMS}
        catch {ans_sendcommand )/COM,********************************************}
        apdl::noprint 0

        # -------------------------------------------------------------
        # FREE GRAB
        # -------------------------------------------------------------
        ans_greygui 0 1
        ans_greygui 1 1
        ans_greygui 3 1
        ans_greygui 4 1

        # -------------------------------------------------------------
        # END OF DIALOG
        # -------------------------------------------------------------
        if [winfo exists $parent] {
           $parent deactivate
        }

    # -----------------------------------------------------------------
    # END OF PROC:           connect_ok
    }
    # -----------------------------------------------------------------


    # -----------------------------------------------------------------
    # PROC:           connect_cancel
    #
    # Purpose:        End of Connection Dialog,
    #                 Transfer no Variables to APDL
    #                 Close all Dialog windows
    #                 free grab
    # Arguments:      N/A
    # Return Value:   N/A
    # Comments:       N/A
    # See Also:       N/A
    # -----------------------------------------------------------------
    proc connect_cancel {} {
        variable parent
        variable saveFile

        # -------------------------------------------------------------
        # COMMENT MESSAGE
        # -------------------------------------------------------------
        apdl::noprint 1
        catch { ans_sendcommand )/ANNO,DELE}
        catch { ans_sendcommand )/AUTO,-1}
        catch { ans_sendcommand )/REPL}
        apdl::noprint 0

        # -------------------------------------------------------------
        # COMMENT MESSAGE
        # -------------------------------------------------------------
        catch {ans_sendcommand )/COM,...canceled}
        catch {ans_sendcommand )/COM,********************************************}

        # -------------------------------------------------------------
        # FREE GRAB
        # -------------------------------------------------------------
        ans_greygui 0 1
        ans_greygui 1 1
        ans_greygui 3 1
        ans_greygui 4 1

        # -------------------------------------------------------------
        # END OF DIALOG
        # -------------------------------------------------------------
        if [winfo exists $parent] {
           $parent deactivate
        }
    # -----------------------------------------------------------------
    # END OF PROC:           connect_cancel
    }
    # -----------------------------------------------------------------


    # -----------------------------------------------------------------
    # PROC:           help
    #
    # Purpose:        Calls Ansys help
    # Arguments:      N/A
    # Return Value:   N/A
    # Comments:       N/A
    # See Also:       N/A
    # -----------------------------------------------------------------
    proc help {} {
            ans_loadhelp Hlp_UI_SOLU_ADVN
    # -----------------------------------------------------------------
    # END OF PROC:           help
    }
    # -----------------------------------------------------------------


# -------------------------------------------------------------
# END OF DIALOG
}
# -------------------------------------------------------------
