#Property Browser version 3.2
#created by Rajasekaran Natarajan, Japan
#www.oocities.org/rajsekarann
#rajasekaran.natarajan <at> gmail.com
#This Property Browser GUI is based on Altair's
#material Browser available with Hyperworks written by Mr.Yaswant

lappend auto_path [ file join [ hm_info -appinfo SPECIFIEDPATH hw_tcl_common ] hwt ];

package require Metawidget;
package require mkWidgets;

#--------------Name space spec begins

namespace eval os {
    variable DirName [file dirname [info script]]
    variable globl
    # Source "$DirName/combobox.tcl"
    namespace export loadOstemplate

    namespace eval props {
       variable osTable

       namespace export getPropData
       namespace export createGUI
       namespace export createTable
       namespace export updateHMDatabase
       namespace export createProps
       namespace export selectMat
       namespace export createPBARCard
       namespace export infoAbout
       namespace export AfterSelectColor
       namespace export getSection
       }
}
#--------------Name space spec ends
##---
#--------------------------------CreateTable ends

if { [file tail [hm_info templatefilename]]  != "general" } {
   set vl [os::loadOstemplate]
   if {$vl == 1} {
         os::props::getPropData all
   }
} else {
   set os::globl(ostemplate) [hm_info templatefilename]
   os::props::getPropData all
}





#--------------proc os::loadOstemplate begins

proc os::loadOstemplate {} {

   variable globl
   set versionNo [string trimleft $::g_hw_version hw]
   #tk_messageBox -message "$versionNo"
   if { ($::tcl_platform(platform)) == "windows" } {
       set test [ catch {set globl(templatedir) [registry get "HKEY_LOCAL_MACHINE\\SOFTWARE\\Altair Engineering, Inc.\\HyperWorks\\$versionNo" TEMPLATES_DIR]} ]
       #tk_messageBox -message "$globl(altairhome)"
       if { $test != 0 } {
      tk_messageBox -title "No template or User Profile loaded" -message "Please load the Nastran template or User Profile and try again."
      return 0;
      break;
    } else {
           set globl(ostemplate) [file join "$globl(templatedir)/feoutput/nastran/general"]
           *templatefileset "$globl(ostemplate)"
       return 1;
       }
   }
}

#--------------proc os::loadOstemplate ends

#--------------proc os::props::getPropData begins
proc os::props::getPropData {dataT} {

  variable osTable
  global comps props numberOfprops
  if {[array exist ::prop_array]} {unset ::prop_array}
  if {[array exist comps]} {unset comps}
  ## Generate Desvar list
  hm_markclear props 1
#  *createmark props 1 $dataT
  hm_createmark props 1 advanced $dataT
  set propListId [hm_getmark props 1]
  hm_markclear props 1
 
  ## Get the size & shape props Config 103 & 115
  set propListName ""

foreach propId $propListId {
    lappend propListName [hm_getcollectorname props $propId]
}

  set numberOfprops [llength $propListName]


  if {![winfo exists .os_props]} {
     os::props::createGUI [expr $numberOfprops + 1]
     } else {raise .os_props}

  $osTable configure -flashmode 0
  #disable cells for props != Prop1
  $osTable tag config cellsdisabled -state disabled
    $osTable set 0,0 " "\
       0,1 " Name"\
       0,2 " PID"\
       0,3 " Type"\
       0,4 " MID"\
       0,5 " A"\
       0,6 " I1" \
       0,7 " I2" \
       0,8 " J" \
       0,9 " Eqv.Section";
#
  set i 1
  foreach pid $propListId {
#     #S NO
     $osTable set $i,0 $i
#
#    ## MAT ID
    set comps(PID,$i) [hm_getentityvalue props $pid id 0 -byid]
    if { $comps(PID,$i) == 0} {
     set $comps(PID,$i) ""
     }
#    ## MAT NAME
    if {$comps(PID,$i) > 0} {
      set comps(PIDN,$i) [hm_getentityvalue PROPERTIES $comps(PID,$i) name 1 -byid]
    } else {
     set comps(PIDN,$i) ""
    }
    set ::propDropVal($i) "$comps(PIDN,$i)"
#    ## MAT TYPE
    if {$comps(PID,$i) > 0} {
      catch {set comps(PIDTi,$i) [hm_attributeindexidentifier PROPERTIES $comps(PID,$i) 1]}
      set val [info exist comps(PIDTi,$i)]
      if {$val == 0} {
      set comps(PIDTi,$i) 99999999
      }
      switch $comps(PIDTi,$i) {
          107 {set comps(PIDTn,$i) PBAR }
          264 {set comps(PIDTn,$i) PROD }
          187 {set comps(PIDTn,$i) PBEAM }
          253 {set comps(PIDTn,$i) PGAP }
          186 {set comps(PIDTn,$i) PELAS }
          default {set comps(PIDTn,$i) ""}
     }
    } else {
      set comps(PIDTn,$i) ""
    }
#
    $osTable set $i,1 $comps(PIDN,$i)
    $osTable set $i,2 $comps(PID,$i)
    $osTable set $i,3 $comps(PIDTn,$i)
#
    if {$comps(PIDTn,$i) == "PBAR"} {
     set comps(PID,MID,$i) [hm_getentityvalue props $comps(PID,$i) materialid 0 -byid]
     set comps(PID,A,$i) [format "%6.2f" [hm_getentityvalue props $comps(PID,$i) "\$PBAR_A" 0 -byid] ]
     set comps(PID,I1,$i) [format "%3.4e" [hm_getentityvalue props $comps(PID,$i) "\$PBAR_I1" 0 -byid] ]
     set comps(PID,I2,$i) [format "%3.4e" [hm_getentityvalue props $comps(PID,$i) "\$PBAR_I2" 0 -byid] ]
     set comps(PID,J,$i) [format "%3.4e" [hm_getentityvalue props $comps(PID,$i) "\$PBAR_J" 0 -byid] ]

#   ##This sect roughly gives the equivalaent section of circulat cross section
        
     if {$comps(PID,A,$i) != "0"} {
                #set pival [expr 2*asin(1.0)]
            #set eqDia [expr ceil(sqrt ((4 * $comps(PID,A,$i) ) / $pival))]
            #set str "CIRC "
            #append str $eqDia
                #set comps(PID,SECT,$i) $str
        set str [os::props::getSection $comps(PIDN,$i) $comps(PID,A,$i) $comps(PID,I1,$i) $comps(PID,I2,$i)]
        set comps(PID,SECT,$i) $str
     }
#    
     if {$comps(PID,MID,$i) != "0"} {
        $osTable set $i,4 $comps(PID,MID,$i)
        } else {set comps(PID,MID,$i) ""; $osTable set $i,4 $comps(PID,MID,$i)}
     if {$comps(PID,A,$i) != "0"} {
        $osTable set $i,5 $comps(PID,A,$i)
        } else {set comps(PID,A,$i) ""; $osTable set $i,5 $comps(PID,A,$i)}
     if {$comps(PID,I1,$i) != "0"} {
        $osTable set $i,6 $comps(PID,I1,$i)
        } else {set comps(PID,I1,$i) ""; $osTable set $i,6 $comps(PID,I1,$i)}
     if {$comps(PID,I2,$i) != "0"} {
        $osTable set $i,7 $comps(PID,I2,$i)
        } else {set comps(PID,I2,$i) ""; $osTable set $i,7 $comps(PID,I2,$i)}
     if {$comps(PID,J,$i) != "0"} {
        $osTable set $i,8 $comps(PID,J,$i)
        } else {set comps(PID,J,$i) ""; $osTable set $i,8 $comps(PID,J,$i)}
     if {$comps(PID,SECT,$i) != "0"} {
        $osTable set $i,9 $comps(PID,SECT,$i)
        } else {set comps(PID,SECT,$i) ""; $osTable set $i,9 $comps(PID,SECT,$i)}
#
    } elseif {$comps(PIDTn,$i) == "PROD"} {
         #tk_messageBox -icon info -message "Hi Raja!!!"
     set comps(PID,MID,$i) [hm_getentityvalue props $comps(PID,$i) materialid 0 -byid]
     set comps(PID,A,$i) [format "%6.2f" [hm_getentityvalue props $comps(PID,$i) "\$PROD_A" 0 -byid]]
     set comps(PID,I1,$i) ""
     set comps(PID,I2,$i) ""
     set comps(PID,J,$i) ""
    
     if {$comps(PID,A,$i) != "0"} {
                set pival [expr 2*asin(1.0)]
            set eqDia [expr ceil(sqrt ((4 * $comps(PID,A,$i) ) / $pival))]
            set str "CIRC "
            append str $eqDia
                set comps(PID,SECT,$i) $str
        puts  $comps(PID,SECT,$i)
     }
    
     if {$comps(PID,MID,$i) != "0"} {
        $osTable set $i,4 $comps(PID,MID,$i)
        } else {set comps(PID,MID,$i) ""; $osTable set $i,4 $comps(PID,MID,$i)}
     if {$comps(PID,A,$i) != "0"} {
        $osTable set $i,5 $comps(PID,A,$i)
        } else {set comps(PID,A,$i) ""; $osTable set $i,5 $comps(PID,A,$i)}
     if {$comps(PID,SECT,$i) != "0"} {
        $osTable set $i,9 $comps(PID,SECT,$i)
        } else {set comps(PID,SECT,$i) ""; $osTable set $i,9 $comps(PID,SECT,$i)}

    } elseif {$comps(PIDTn,$i) == "PBEAM"} {
         #tk_messageBox -icon info -message "Hi PBeam!!!"
     set comps(PID,MID,$i) [hm_getentityvalue props $comps(PID,$i) materialid 0 -byid]
     set comps(PID,A,$i) [format "%6.2f" [hm_getentityvalue props $comps(PID,$i) "\$PBEAM_Aa" 0 -byid]]
     set comps(PID,I1,$i) [format "%3.4e" [hm_getentityvalue props $comps(PID,$i) "\$PBEAM_I1a" 0 -byid]]
     set comps(PID,I2,$i) [format "%3.4e" [hm_getentityvalue props $comps(PID,$i) "\$PBEAM_I2a" 0 -byid]]
     set comps(PID,J,$i) [format "%3.4e" [hm_getentityvalue props $comps(PID,$i) "\$PBEAM_Ja" 0 -byid]]
        
     if {$comps(PID,A,$i) != "0"} {
        set str [os::props::getSection $comps(PIDN,$i) $comps(PID,A,$i) $comps(PID,I1,$i) $comps(PID,I2,$i)]
        set comps(PID,SECT,$i) $str
         }
    
     if {$comps(PID,MID,$i) != "0"} {
        $osTable set $i,4 $comps(PID,MID,$i)
        } else {set comps(PID,MID,$i) ""; $osTable set $i,4 $comps(PID,MID,$i)}
     if {$comps(PID,A,$i) != "0"} {
        $osTable set $i,5 $comps(PID,A,$i)
        } else {set comps(PID,A,$i) ""; $osTable set $i,5 $comps(PID,A,$i)}
     if {$comps(PID,I1,$i) != "0"} {
        $osTable set $i,6 $comps(PID,I1,$i)
        } else {set comps(PID,I1,$i) ""; $osTable set $i,6 $comps(PID,I1,$i)}
     if {$comps(PID,I2,$i) != "0"} {
        $osTable set $i,7 $comps(PID,I2,$i)
        } else {set comps(PID,I2,$i) ""; $osTable set $i,7 $comps(PID,I2,$i)}
     if {$comps(PID,J,$i) != "0"} {
        $osTable set $i,8 $comps(PID,J,$i)
        } else {set comps(PID,J,$i) ""; $osTable set $i,8 $comps(PID,J,$i)}
     if {$comps(PID,SECT,$i) != "0"} {
        $osTable set $i,9 $comps(PID,SECT,$i)
        } else {set comps(PID,SECT,$i) ""; $osTable set $i,9 $comps(PID,SECT,$i)}

    } else {
     set comps(PID,MID,$i) ""
     set comps(PID,A,$i) ""
     set comps(PID,I1,$i) ""
     set comps(PID,I2,$i) ""
     set comps(PID,J,$i) ""
     set comps(PID,SECT,$i) ""
#
     $osTable set $i,4 $comps(PID,MID,$i)
     $osTable set $i,5 $comps(PID,A,$i)
     $osTable set $i,6 $comps(PID,I1,$i)
     $osTable set $i,7 $comps(PID,I2,$i)
     $osTable set $i,8 $comps(PID,J,$i)
     $osTable set $i,9 $comps(PID,SECT,$i)
#
     $osTable tag cell cellsdisabled $i,4
     $osTable tag cell cellsdisabled $i,5
     $osTable tag cell cellsdisabled $i,6
     $osTable tag cell cellsdisabled $i,7
     $osTable tag cell cellsdisabled $i,8
     $osTable tag cell cellsdisabled $i,9
    }
     incr i
  }
#
#
   $osTable tag config colstatedisabled -state disabled
   $osTable tag col colstatedisabled 3 9
   $osTable configure -flashmode 1
#
}

#--------------proc os::props::getPropData ends
proc os::props::createProps {} {
    
    variable globl    
    set win_x [expr {[winfo pointerx .os_props] - 100}]
    set win_y [winfo pointery .os_props]

    toplevel .os_props_createProps
    set pbar .os_props_createProps
    wm geometry $pbar +$win_x+$win_y
    wm title $pbar "Create PBAR"
    set lab [label $pbar.lab -text "Name:"]
    set propname_entry [entry $pbar.matname_entry -textvariable "prop_Name" -width 30]

    set ::pbarType "PBAR"
    set ::pbar_MID " "
    set ::pbar_A " "
    set ::pbar_I1 " "
    set ::pbar_I2 " "
    set ::pbar_J " "


    combobox $pbar.pbarTypeCombo \
        -textvariable pbarType \
        -entries {PBAR};

#     foreach val {MAT1} {
#         $mat1.matTypeCombo list insert end $val
#         }

   set mid_label [label $pbar.e_label -text "MID:"]
   set mid_entry [entry $pbar.e_entry -width 15 -justify right -textvariable "pbar_MID"]
   set a_label [label $pbar.g_label -text "A:" ]
   set a_entry [entry $pbar.g_entry  -width 15 -justify right -textvariable "pbar_A"]
   set i1_label [label $pbar.nu_label -text "I1:"]
   set i1_entry [entry $pbar.nu_entry -width 7 -justify right -textvariable "pbar_I1"]
   set i2_label [label $pbar.rho_label -text "I2:"]
   set i2_entry [entry $pbar.rho_entry  -width 15 -justify right -textvariable "pbar_I2"]
   set j_label [label $pbar.a_label -text "J:"]
   set j_entry [entry $pbar.a_entry -width 15 -justify right -textvariable "pbar_J"]


   set createpbar_button [button $pbar.createpbar_button -text "Create" -width 15 -command {
   hm_markclear props 1
#     *createmark props 1 all
   hm_createmark props 1 advanced all
   set proplistId [hm_getmark props 1]
   set proplistName ""
   foreach pId $proplistId {
     lappend proplistName [hm_getcollectorname props $pId]
   }
   if {$::prop_Name != ""} {
     if {[lsearch $proplistName $::prop_Name] == -1} {
        os::props::createPBARCard
        destroy .os_props
        os::props::getPropData all
     } else {tk_messageBox -icon warning -message "Prop name already exists."}
   } else {tk_messageBox -icon warning -message  "You Must Specify The Property Name"}
   }]
     
   pack $lab $propname_entry $mid_label $mid_entry $a_label $a_entry $i1_label $i1_entry $i2_label $i2_entry  \
         $j_label $j_entry $createpbar_button -side left -padx 2


}

    
proc os::props::createPBARCard {} {

    variable globl

    if { [file tail [hm_info templatefilename]]  != "optistruct" } {
       os::loadOstemplate
    } else {set os::globl(ostemplate) [hm_info templatefilename]}

    *collectorcreate properties "$::prop_Name" "::pbar_mid" 7
    hm_markclear properties 2
    *createmark properties 2 "$::prop_Name"

    set prop_id [hm_getmark props 2]
    *dictionaryload properties 2 "$os::globl(ostemplate)" "PBAR"
    *attributeupdateint properties $prop_id 3240 1 2 0 1

    *attributeupdatedouble properties $prop_id 68 1 2 0 $::pbar_A
    *attributeupdatedouble properties $prop_id 69 1 2 0 $::pbar_I1
    *attributeupdatedouble properties $prop_id 70 1 2 0 $::pbar_I1
    *attributeupdatedouble properties $prop_id 71 1 2 0 $::pbar_J
    
}

proc os::props::updateHMDatabase {index ovalue nvalue uChoice} {

     variable osTable
     variable ostemplate
     global comps
     set win_x [winfo pointerx .os_props]
     set win_y [winfo pointery .os_props]

     set ovalue [string trim $ovalue]
     set nvalue [string trim $nvalue]
     set row [lindex [split $index ,] 0]
     set col [lindex [split $index ,] 1]
    # tk_messageBox -message "Index: $index, Orig Val: $ovalue, New Val: $nvalue \n \
    #           row: $row, col: $col \n \
    #           orig St len: [string length $ovalue], new St len: [string length $nvalue]"


   hm_markclear props 1
   hm_createmark props 1 advanced all
   set proplistId [hm_getmark props 1]
   set proplistName ""
   foreach pId $proplistId {
     lappend proplistName [hm_getcollectorname props $pId]
   }



     switch $col {
        1 {
        #tk_messageBox -message "In Property Name"
        if { $nvalue != $ovalue} {
           if {$nvalue != ""} {

              if {[lsearch $proplistName $nvalue] == -1} {
                 catch {*renamecollector props "$ovalue" "$nvalue" }
                 #destroy .os_props
                 os::props::getPropData all
                 tk_messageBox -message "Property Renamed."
                 } else {tk_messageBox -message "Property name already exists.";$osTable set $index $ovalue}
              } else {$osTable set $index $ovalue}
           }
        }
        2 {
        #tk_messageBox -message "In Property ID"
        if {$uChoice == 0} {
          if { $nvalue != $ovalue} {
             if {$nvalue != "" || $nvalue == 0} {

                if {[lsearch $proplistId $nvalue] == -1} {
                   hm_markclear props 1
#                   *createmark props 1 $ovalue
                   hm_createmark props 1 "by id only" $ovalue
                   catch {*renumber props 1 "$nvalue" 1 0 0 }
                   os::props::getPropData all
                   tk_messageBox -message "Property card renumbered."
                   } else {tk_messageBox -message "Property ID already exists.";$osTable set $index $ovalue}
                } else {$osTable set $index $ovalue}
             }
           }
        }
        4 {
        #tk_messageBox -message $nvalue
        if {$uChoice == 0} {
        if { $nvalue != $ovalue} {
           if {$nvalue != ""} {
          set mname [hm_getcollectorname mats $nvalue]
          hm_markclear props 2
          hm_createmark props 2 "by id only" $comps(PIDN,$row)
          set propid [hm_getmark props 2]
          *materialupdate properties 2 $mname
          tk_messageBox -message "Material id  updated."
          os::props::getPropData all
          } else {$osTable set $index $ovalue}
           }
    }
        }
        5 {
        #Area
        if { $nvalue != $ovalue} {
           if {$nvalue != ""} {
              hm_markclear props 2
          puts $row
              hm_createmark props 2 "by id only" $comps(PID,$row)
              set propid [hm_getmark props 2]
              *dictionaryload props 2 "$os::globl(ostemplate)" "PBAR"
          *attributeupdatedouble props $propid 68 1 2 0 $nvalue
              tk_messageBox -message "Area value updated."
              os::props::getPropData all
              } else {$osTable set $index $ovalue}
           }
        }
        6 {
        #I1
        if { $nvalue != $ovalue} {
           if {$nvalue != ""} {
               hm_markclear properties 2
               hm_createmark props 2 "by id only" $comps(PID,$row)
               set propid [hm_getmark props 2]
              *dictionaryload properties 2 "$os::globl(ostemplate)" "PBAR"
              *attributeupdatedouble properties $propid 69 1 2 0 $nvalue
              tk_messageBox -message "I1 value updated."
              os::props::getPropData all
              } else {$osTable set $index $ovalue}
           }
        }
        7 {
        #I2
        if { $nvalue != $ovalue} {
           if {$nvalue != ""} {
               hm_markclear properties 2
               hm_createmark props 2 "by id only" $comps(PID,$row)
               set propid [hm_getmark props 2]
              *dictionaryload properties 2 "$os::globl(ostemplate)" "PBAR"
              *attributeupdatedouble properties $propid 70 1 2 0 $nvalue
              tk_messageBox -message "I2 value updated."
              os::props::getPropData all
              } else {$osTable set $index $ovalue}
           }
        }
        8 {
        #J
        if { $nvalue != $ovalue} {
           if {$nvalue != ""} {
               hm_markclear properties 2
              hm_createmark props 2 "by id only" $comps(PID,$row)
               set propid [hm_getmark props 2]
              *dictionaryload properties 2 "$os::globl(ostemplate)" "PBAR"
          *attributeupdatedouble properties $propid 71 1 2 0 $nvalue
              tk_messageBox -message "J value updated."
              os::props::getPropData all
              } else {$osTable set $index $ovalue}
           }
        }
        9 {
        #TREF
        if { $nvalue != $ovalue} {
           if {$nvalue != ""} {
               hm_markclear properties 2
#               *createmark properties 2 "$comps(MIDN,$row)"
               hm_createmark props 2 "by id only" $comps(PID,$row)
               set propid [hm_getmark props 2]
              *dictionaryload properties 2 "$os::globl(ostemplate)" "MAT1"
              *attributeupdatedouble properties $matid 6 1 1 0 $nvalue
              tk_messageBox -message "TREF value updated."
              os::props::getPropData all
              } else {$osTable set $index $ovalue}
           }
        }
     }

   
}

proc os::props::infoAbout {} {

set aboutMsg {
This Nastran Property browser is written by me, \
Rajasekaran Natarajan Kawasaki, Tokyo, Japan \
Email:rajasekaran.natarajan@gmail.com

This program based on already available Material Browser created by Yeshwant Mummaneni, Altair Inc. \
If you face any problem or need some more options let me know, \


This program tested to my abilities but not rigorously, as this is create-on-the-run-program. \
so use it with your own risk. [No gurantee attached]

The Equivalent section option is inspired by similar section recognition from  I-DEAS, SDRC. \
It recognises Circular or Rectangular sections [or Approximates a Section] \
when a section does not satisfies both these categories then it classifies it as OTHER \

Possible Improvements:
I-section recongnition and more can be included.\
The Sections Can be used to create Hyperbeam Database as \
this opens the door for many many functionalities in HM.

}
    
    set width 500
    set height  250
    set geom "[set width]x[set height]"
    set mainwin [::hwt::CreateWindow macroWindow \
      windowTitle "Convert" \
      cancelButton "Cancel" \
      cancelFunc "" \
      geometry $geom \
      propagate 1 \
      resizeable 0 0 \
      noGeometrySaving \
      destroyOnUnpost \
      maxSize 700 650 \
      minSize $width $height]
    set Recess [ ::hwt::WindowRecess macroWindow];
    set mainframe [frame $Recess.mainframe -bd 0 -relief flat]
    pack $mainframe -anchor nw -fill x -side top -padx 7 -pady 6
    set messageframe [frame $Recess.msgframe -bd 0 -relief flat]
    pack $messageframe -anchor nw -fill x -side top -padx 7 -pady 4    

    set text_help [text $messageframe.textw -font [::hwt::AppFont] -wrap word -width 150 -height 70];
    
    pack $text_help -side right -padx 7 -pady 4 -fill both -expand true;
    
    $text_help insert end $aboutMsg
        
    PostWindow macroWindow

    #tk_messageBox -icon info -message $aboutMsg

}

proc os::props::getSection {pn pA i1 i2 } {

     variable osTable
     variable ostemplate
     global comps
    
     set pname [string trim $pn]
     set area [string trim $pA]
     set ixx [string trim $i1]
     set iyy [string trim $i2]
     set izz [expr $i1+$i2]
     #tk_messageBox -message "$pA $i1 $i2"
     
     set pival [expr 2*asin(1.0)]
     set str ""
     
     if { ($area != 0) &&  ($ixx == 0)  } {
    set str "CIRC"
    set eqCirDia [expr round(sqrt ((4 * $area ) / $pival))]
    append str $eqCirDia
    tk_messageBox -message "$pname $str"
    }
    
    if { ($area != 0) &&  ($ixx != 0) && ($iyy == 0) } {
    set str "CIRC"
    set eqCirDia [expr round(sqrt ((4 * $area ) / $pival))]
    append str $eqCirDia
    tk_messageBox -message "$pname $str"
    }
    
    if { ($area != 0) &&  ($ixx != 0) && ($iyy != 0) } {
        
    if { $izz == 0} {
        set $izz [expr $ixx + $ iyy]
    }
    
    #finding equivalent circular section
    set eqCirDia [expr round(sqrt ((4 * $area ) / $pival))]
    set eqCirIxx [expr $pival * pow($eqCirDia,4)/ 64]
    set eqCirIzz [expr $eqCirIxx * 2]
    set errCixx [expr abs(($ixx - $eqCirIxx)*100/$ixx)]
    set errCizz [expr abs(($izz - $eqCirIzz)*100/$izz)]
    #puts [format "%15s\t%2.2f\t%2.3e\t%2.3e\t%2.3e\t%2.3e\t%3.3f\t%3.3f" $pname $eqCirDia $ixx $izz  $eqCirIxx $eqCirIzz $errCixx $errCizz]
    
    #finding equivalane rectangular section
    set rectd [expr round( sqrt( abs( 12 * $ixx / $area)))]
    set rectb [expr round($area/$rectd)]
    set eqRectA [expr $rectb * $rectd]
    set eqRectIxx [expr $rectb * pow($rectd,3)/12]
    set eqRectIyy [expr $rectd * pow($rectb,3)/12]
    
    set eqRectIzz [expr $rectb*$rectd/3*(pow($rectb,2)+pow($rectd,2))]
    set errRixx [expr abs(($ixx - $eqRectIxx)*100/$ixx)]
    set errRiyy [expr abs(($iyy - $eqRectIyy)*100/$iyy)]
    set errRizz [expr abs(($izz - $eqRectIzz)*100/$izz)]
    #puts [format "%15s\t%2.2f\t%2.2f\t%2.3e\t%2.3e\t%2.3e" $pname $rectb $rectd $ixx $iyy $izz]
    #puts [format "\t\t\t\t%2.3e\t%2.3e\t%2.3e\t%5.2f\t%5.2fe" $eqRectIxx $eqRectIyy $eqRectIzz $errRixx $errRiyy]
    
    if { ($errRiyy < $errCixx) && ($errRiyy < 5)} {
        set secStr "RECT"
        set secDim [format "%2.1fx%2.1f" $rectb $rectd]
        set mySect [concat $secStr $secDim]
        return $mySect
    } elseif { $errCixx < 5 } {
        set secStr "CIRC"
        set secDim [format "%2.2f" $eqCirDia]        
        set mySect [concat $secStr $secDim]
        return $mySect
    } else {
        set mySect "OTHER"
        return $mySect
    }
    }
    
    
    
}

##---

proc os::props::createGUI {rows} {
  if {[array exists fram]} {unset fram}
  set ::proptablerows $rows
  set winwidth [expr {int([hm_winfo graphicwidth] * 1.0)}]
  set xpos [expr {int([hm_winfo x] + 0.0)}]
  set ypos [expr {int([hm_winfo y] + [hm_winfo graphicheight] - 43)}]
  #set ypos [expr {int([hm_winfo y] + [hm_winfo graphicheight] - 0)}]
  set hmmenuHeight [expr {(10.0 + ( [hm_winfo height] - [hm_winfo graphicheight] ) / 1.0)}]
  set winheight    [ expr {int($hmmenuHeight) - 1}]

   toplevel .os_props
   set w .os_props
   wm geometry $w ${winwidth}x$winheight+$xpos+[expr {int($ypos) + 3}]
   wm withdraw .os_props
   wm title $w "Propertiess"

   set fram(lab) [frame $w.fram(lab)]
   set fram(tab) [frame $w.fram(tab)]
   set fram(but) [frame $w.fram(but)]
   pack $fram(lab) -padx 5 -pady 5 -fill both -expand 1
   pack $fram(tab) -padx 5 -fill both -expand 1
   pack $fram(but) -padx 5 -pady 5 -fill both -expand 1

   set fram(lab1) [frame $fram(lab).fram(lab1)]
   set fram(lab2) [frame $fram(lab).fram(lab2)]
   pack $fram(lab1) -side left -fill x -expand 1 -in $fram(lab)
   pack $fram(lab2) -side right -fill x -expand 1 -in $fram(lab)

   set select_allButton [button $fram(lab1).select_allButton -text "Select All" -width 15 -command {
        global chkFlag c
        if {$chkFlag == 0} {
        #tk_messageBox -message "0"
          for {set i 1} {$i < $::proptablerows} {incr i} {
             set c($i) 1
             $os::props::osTable tag row rowstatedelete $i
          }
          set chkFlag 1
        } else {
        #tk_messageBox -message "1"
          for {set i 1} {$i < $::proptablerows} {incr i} {
             set c($i) 0
             $os::props::osTable tag row rowhighlightnormal $i
          }
          set chkFlag 0
        }
        }];

   set createprops_button [button $fram(lab1).createprops_button -text "Create Prop1..." -width 15 -command {
             if {![winfo exists .os_props_createprops]} {
                os::props::createProps
              } else {raise .os_props_createprops}
             }]
   pack $select_allButton $createprops_button -side left -padx 2 -in $fram(lab1)

   
   set createAbout_button [button $fram(lab1).createAbout_button -text "About" -width 15 -command {os::props::infoAbout} ]
   pack $select_allButton $createAbout_button -side left -padx 2 -in $fram(lab1)

   set exit_but [button $fram(lab2).exit_but -text "Close" -width 15 -command {destroy .os_props}]
   pack $exit_but -padx 5 -side right -in $fram(lab2)




   os::props::createTable $fram(tab) $rows

   set close_button [button $fram(but).close_button -text "Close" -command {destroy .os_props}]

   wm deiconify .os_props
   #KeepOnTopWithHM $w

}
#--------------------------------CreateGUI Ends

#--------------------------------CreateTable begins
proc os::props::createTable {win rows} {

   variable osTable
   set osTable [ table $win.osTable \
        -padx 4\
        -bd 1 \
        -rows $rows \
        -cols 10 \
        -multiline 0 \
        -anchor nw \
        -relief raised \
        -colstretchmode last \
        -colstretch unset  \
        -resizeborders col \
        -takefocus 1 \
        -titlerows 1 \
        -titlecols 1 \
        -selectmode single \
        -selecttype row \
        -xscrollcommand "$win.sx set" \
        -yscrollcommand "$win.sy set" \
        -sparsearray 0 \
        -variable prop_array \
        -insertofftime 0  \
        ];

    scrollbar $win.sx -orient h -command "$osTable xview";
    scrollbar $win.sy -orient v -command "$osTable yview";
    pack $win.sy -side right -fill y -padx 5
    pack $win.sx -side top -fill x  -padx 5
    pack $osTable -fill both -side top -before $win.sx -expand 1 -padx 5

    $osTable tag configure "title" -fg black -bg #90ee90 -relief raised ;
    $osTable tag configure "sel" -relief sunken -fg black -bg white;
    $osTable tag config active -bg navy -fg white;

    $osTable set 0,0 " "\
       0,1 " Name"\
       0,2 " PID"\
       0,3 " Type"\
       0,4 " MID"\
       0,5 " A"\
       0,6 " I1" \
       0,7 " I2" \
       0,8 " J" \
       0,9 " Eqv.Section";


global chk but c disabledrows selectedC chkFlag display numberOfComps
set chkFlag 0
if {[array exists chk]} {unset chk}
if {[array exists c]} {unset c}

$osTable tag config rowstatedisabled -state disabled -bg salmon
$osTable tag config rowstatedelete -bg salmon
$osTable tag config rowhighlight -bg lavender
$osTable tag config rowhighlightnormal
   $osTable tag config rightjustify -anchor e
   $osTable tag col rightjustify 2 4 5 6 7 8 9
#$osTable tag col rowstatedisabled 4 8

set disabledrows ""
set selectedC ""
set display ""

#$osTable tag row rowhighlight $selectedC


for {set i 1} {$i < $rows} {incr i} {
  set fram($i) [frame $osTable.fram($i)]
  set chk($i) [checkbutton $osTable.chk($i) -variable "c($i)" -command {
        global chk disabledrows
        #get checked boxes
        set display ""
        for {set i 1} {$i < $::proptablerows} {incr i} {
           if {$c($i) == 1} {
             $os::props::osTable tag row rowstatedelete $i
           } else {$os::props::osTable tag row rowhighlightnormal $i}
        }
        }]
  set but($i) [button $osTable.but($i) -text "x" -bg salmon \
        -command {
        global comps chk disabledrows
            #get checked boxes
            set selectedprops ""
            for {set i 1} {$i < $::proptablerows} {incr i} {
              if {$c($i) == 1} {
                lappend selectedprops $comps(PID,$i)
                set c($i) 0
                }
              }

              if {$selectedprops != ""} {
                 hm_markclear props 1;
#                eval *createmark props 1 "$selectedprops"
                 eval [hm_createmark props 1 "by id only" $selectedprops]
                 *deletemark props 1
                 destroy .os_props;
                 os::props::getPropData all
              }
            }]

     pack $chk($i) $but($i) -side left -padx 2 -pady 2 -in $fram($i)
     $osTable window configure $i,0 -window $fram($i) -sticky news;
}

   # added to address the 2-bit characters being inserted when changing data in the cells
   bind Table <Return> {::tk::table::Insert %W ""}
   # -- End --
   
$osTable width 0 12
$osTable width 3 10
   foreach key {Return} {

     bind $osTable <$key> {
      global disabledrows

      set index [%W index active]
      set oldvalue $prop_array([%W index active])
      set newvalue [%W curvalue]
      set row [lindex [split $index ,] 0]
      set col [lindex [split $index ,] 1]
      set win_x [winfo pointerx .os_props]
      set win_y [winfo pointery .os_props]
      if {[lsearch $disabledrows $row] == -1} {
        switch $col {
          1 {
          #Updated Prop Name
             os::props::updateHMDatabase $index $oldvalue $newvalue 9
          }
          2 {
          #Update Prop ID
             os::props::updateHMDatabase $index $oldvalue $newvalue 0
          }
          4 {
          #Update E
             os::props::updateHMDatabase $index $oldvalue $newvalue 9
          }
          5 {
          #Update G
             os::props::updateHMDatabase $index $oldvalue $newvalue 9
          }
          6 {
          #Update Nu
             os::props::updateHMDatabase $index $oldvalue $newvalue 9
          }
          7 {
          #Update Rho
             os::props::updateHMDatabase $index $oldvalue $newvalue 9
          }
          8 {
          #Update A
             os::props::updateHMDatabase $index $oldvalue $newvalue 9
          }
          #9 {
          #Update TREF
          #   os::props::updateHMDatabase $index $oldvalue $newvalue 9
          #}
         }
      }
     }
   }


}