#.============================================================================
#. Copyright 1999 SAS IP, Inc. Proprietary Data.
#. Unauthorized use, distribution, or duplication is prohibited.
#. All Rights Reserved.
#.============================================================================
#. $Revision: 145002 $
#. $Date: 2009-11-13 11:20:27 -0500 (Fri, 13 Nov 2009) $
#.============================================================================
#.File Name:     GraphicSetting.eui
#.Author:        Greg Sharpe
#.Description:   The variables and proc's to manipulate the graphics and
#.               individual graphic windows.
#.============================================================================
#.Procs:
#.   updateRenderList
#.   definerender
#.   applyRenderPlot
#.   applyTranslucency
#.   assignTranslucency
#.   assignTrans_cancel
#.   assignTrans_ok
#.   setLineNumber
#.   setAreaNumber
#.   setBCSymbols
#.   mtdisplay
#.   modelBB
#.   create
#.   S_PNUM_Ok
#.   S_PNUM_exec
#.   initializeData
#.   create
#.   updatePrinterInfo
#.   captureImage_ok
#.   captureImage_2File
#.   printPSSet
#.   graphicOnOff
#.   graphicsOnOffInitialize
#.   annotation
#.   colorUsage
#.   colorUsageDefault
#.   windowOnOff
#.   windowSet
#.   windowOnOffInitialize
#.   windowSetInitialize
#.   create
#.   S_UDOC_Ok
#.   S_UDOC_exec
#.   initializeData
#.   create
#.   contSet_Ok
#.   initializeData
#.   create
#.   dispSet_Ok
#.   dispSet_Replot
#.   zbufChange
#.   lightChange
#.   initializeData
#.============================================================================
# Load the resources for graphics settings
::euidl::loadResource GraphicSettings.hlp

# Render List Variables
variable ::euidl::renderListWin;    variable ::euidl::renderListID 1
variable ::euidl::renderListHash

# Graphic Window Settings
variable ::euidl::lineNumber 0;     variable ::euidl::areaNumber 0
variable ::euidl::BCSymbols 1;      variable ::euidl::modelBndBox -999

#
# Render List Information {
#

# Update the graphical rendering list
proc ::euidl::updateRenderList { } {
   variable renderListWin;    variable renderListID
   variable renderListHash

   # Get the available materials
   catch {unset renderList} err
   set numRender [ans_getvalue parm,_NUMPLT,value]
   catch {ans_sendcommand )/nopr} err

   set idVal 0
   for {set i 1} {$i <= $numRender} {incr i} {
      set showitem [ans_getvalue parm,_PLTDP($i,1),value]
      catch {ans_sendcommand )/nopr} err
      if {$showitem > 0} {
         set newplt [::euidl::passAnsysToString _PLTNAM 32 $i 1]
         lappend renderList $newplt
         set renderListHash(plt,$idVal) $i
         set renderListHash(id,$i) $idVal
         incr idVal
      }
   }

   set curRndr [ans_getvalue parm,_CURPLT,value]
   catch {ans_sendcommand )/nopr} err
   set renderListID $curRndr

   # Update the render list
   catch {$renderListWin delete list 0 end} err
   foreach item $renderList {
          $renderListWin insert list end [list $item]
   }
   catch {$renderListWin delete entry 0 end} err

   set pltitem $renderListHash(id,$renderListID)

   $renderListWin selection set $pltitem
}

# Entry point from the render list
proc ::euidl::definerender {} {
   variable renderListWin;    variable renderListHash
   variable renderListID

   set index [$renderListWin curselection]
   set plt $renderListHash(plt,$index)

   set euidlCmd [::euidl::passAnsysToString _PLTCMD 32 $plt 1]
   uplevel #0 [list $euidlCmd ]
}

# Assignment of rendering to model
proc ::euidl::applyRenderPlot { } {
   variable renderListWin;    variable renderListHash
   variable renderListID

   set index [$renderListWin curselection]
   set plt $renderListHash(plt,$index)

   set pltItem [ans_getvalue parm,_PLTDP($plt,2),value]
   catch {ans_sendcommand )/nopr} err
   ::euidl::mtdisplay 0 $pltItem
}

# Assignment of translucency to model areas
proc ::euidl::applyTranslucency { } {

#  set index [$win curselection]
#  set plt $renderListHash(plt,$index)
   ::euidl::assignTranslucency
}
# Create a dialog to set areas to be translucent
proc euidl::assignTranslucency { } {
   variable mainwinParent;    variable mainwinGrab
   variable renderListWin

   # Give the initial plot
   catch {ans_sendcommand /trlcy,on} err
   catch {ans_sendcommand /anno,off} err
   catch {ans_sendcommand /gline,,-1} err
   catch {ans_sendcommand APLOT} err
   # Make the Dialog
   set parent \
         [euidl::dialog $mainwinGrab.selecttransarea \
         -master $mainwinParent \
         -grabwin $mainwinGrab -class EUIDL ]
   set child [$parent component childsite]
   set child [frame $child.frm1 -class SetlectTransArea]
   pack $child -fill both -expand 1

   # There must be a class to get the title so use the child
   $parent configure \
         -title [option get $child title {}]

   # Define the dialog contents
   ::scale $child.transLevel -from 0.0 -to 1.0 -resolution 0.1 \
         -tickinterval 0 \
         -orient horizontal
   label  $child.opaque -anchor nw -justify left
   label  $child.padding -anchor nw -justify left -text "<--<<< ++ >>>-->"
   label  $child.transparent -anchor nw -justify right
   #
   grid  $child.transLevel -column 0 -row 0 -columnspan 3 -pady 0 -sticky ew
   grid  $child.opaque -column 0 -columnspan 1 -row 1 -pady 0 -sticky e
   grid  $child.padding -column 1 -columnspan 1 -row 1 -pady 0 -sticky ew
   grid  $child.transparent -column 2 -columnspan 1 -row 1 -pady 0 -sticky ew
   # Define the termination buttons
   $parent configure \
     -oktext [option get $child okText {}] \
     -canceltext [option get $child cancelText {}] \
     -okcommand [code [list ::euidl::assignTrans_ok $parent $child]] \
     -cancelcommand [list ::euidl::assignTrans_cancel $parent] \
     -helpcommand [option get $child helpCommand {}]
   ::euidl::registerWindow $parent
   # do not allow user to change rendering in mid picking
   $renderListWin configure -state disabled
   $parent activate [winfo rootx $renderListWin] [winfo rooty $renderListWin]
}

proc euidl::assignTrans_cancel {parent} {
   variable renderListWin
   catch {ans_sendcommand Fnc_RemoveDialogs} err
   $renderListWin configure -state normal
   ::euidl::destroyWin $parent
}

proc euidl::assignTrans_ok {parent child} {
   variable renderListWin
   $parent deactivate
   # reactivate render list window
   $renderListWin configure -state normal
   set level [$child.transLevel get]
   catch {ans_sendcommand *SET,_TRLLVL,$level} err
   catch {ans_sendcommand Fnc_MT_TransArea} err
   ::euidl::destroyWin $parent
}
# END OF RENDER LIST }

#
# Graphic Window Settings  {
#
proc ::euidl::setLineNumber {} {
   variable lineNumber
   catch {ans_sendcommand /PNUM,LINE,$lineNumber} err
   if {$lineNumber == 1} {
      catch {ans_sendcommand /NUM                  } err
   } else {
      catch {ans_sendcommand /NUM,1                } err
   }
}
proc ::euidl::setAreaNumber {} {
   variable areaNumber
   catch {ans_sendcommand /PNUM,AREA,$areaNumber} err
   if {$areaNumber == 1} {
      catch {ans_sendcommand /NUM                  } err
   } else {
      catch {ans_sendcommand /NUM,1                } err
   }
}
proc ::euidl::setBCSymbols {} {
   variable BCSymbols
   catch {ans_sendcommand MTBCSYMB,$BCSymbols,1} err
}

# End Graphic Window Settings  }


# Plot the specified entity
proc ::euidl::mtdisplay { {plot_type 4}  {plot_style 1} } {

# *** primary function: plot the given display type
# *** Notice - Ths file contains ANSYS Confidential information ***
# input arguments:
# plot_type(arg1) (int,sc)  type of plot to produce
#                             0 =  current plot
#                             1 =  keypoints
#                             2 =  lines
#                             3 =  areas
#                             4 =  volumes
#                             5 =  nodes
#                             6 =  elements
#                             7 =  contact pairs
#                            10 =  pldi
#                            11 =  pldi,1
#                            12 =  pldi,2
#                            13 =  model bounding box
#                     101 - 200 =  plns, _RSLTLAB(1-100,1)
#
# plot_style(arg2) (int,sc)  style of plot to produce
#                            0  = current style
#                            1  = material plot by color with legend
#                            2  = material plot by texture
#                            3  = thickness plot by color with legend
#                            4  = material plot by translucency with legend
#                            5  = wireframe
#                            6  = no color
#                            7  = show edges
#                            8  = show parts
# output arguments:
#   _success   (int,sc)     success key
#                            0 = no success
#                            1 = success
#
   # If the bounding box is showing remove it
   variable modelBndBox
   if {$modelBndBox != -999} {
      set prkey [ans_getvalue ACTIVE,,PRKEY]
      catch {ans_sendcommand )/NOPR} err
      catch {ans_sendcommand )/ANUM,$modelBndBox,DELE}
      set modelBndBox -999
      if {$prkey} {
         catch {ans_sendcommand )/GO} err
      }
   }
   set fileID [open scratch.mac w]
   set _success 1
   set _keyleg 0
   set trlkey off
   puts $fileID ")/nopr"
#   unselect the load transfer elements
   puts $fileID "esel,u,real,,104"
   puts $fileID "esel,u,real,,154"
   puts $fileID "esel,u,ename,,170"
   puts $fileID "esel,u,ename,,174"

#   **********************************************
#   ***  retrieve current states if necessary  ***
#   **********************************************
   if {$plot_style == 0} {
      set plot_style [ans_getvalue parm,_CURPLT,value]
      catch {ans_sendcommand )/nopr} err
   }
   if {$plot_type == 0} {
      set plot_type [ans_getvalue parm,_CURPTYP,value]
      catch {ans_sendcommand )/nopr} err
      if {$plot_type == 6} {
#         *** don't attempt an eplot if no elements ***
         catch {ans_sendcommand _ISELMS=ELMIQR(0,12)} err
         set iselms [ans_getvalue parm,_ISELMS,value]
         catch {ans_sendcommand )/nopr} err
         if {$iselms == 0} {
            set plot_type 4
         }
#         *** eplots can't do texturing or translucency ***
         if {$plot_style == 2 || $plot_style == 4} {
            set plot_type 4
         }
      } elseif {$plot_style < 5} {
#         *** aplots/vplots can only do material or thickness displays ***
         set plot_type 4
      }
   }
   if {$plot_style == 8} {
      set plot_type 3
   }
   set curshap [ans_getvalue parm,_CURSHAP,value]
   if {$curshap == 0} {
      set plot_type 5
   }

#  ******************************************************
#  ***  disallow wireframe stress displays for 3D devices
#  ******************************************************
   set _nlvl3d [ans_getvalue common,,d3com,,INTE,95]
   if {$_nlvl3d < 4} {
   } elseif {$plot_type >= 101 && $plot_type <= 200} {
      puts $fileID ")_PLTDP(5,1)=0"
   } else {
      puts $fileID ")_PLTDP(5,1)=1"
   }

#  ***************************************
#  ***  disallow texturing for 2D devices
#  ***************************************
   if {$_nlvl3d < 4} {
      puts $fileID ")_PLTDP(2,1)=0"
   } else {
      puts $fileID ")_PLTDP(2,1)=1"
   }

#  ************************
#  *** set plot command ***
#  ************************
   if {$plot_type == 1} {
      set _pcmd KPLOT
      if {$plot_style < 6 || $plot_style > 7 } {
         set plot_style 7
      }

   } elseif {$plot_type == 2} {
      set _pcmd LPLOT
      if {$plot_style < 6 || $plot_style > 7 } {
         set plot_style 6
      }

   } elseif {$plot_type == 3} {
      set _pcmd APLOT

   } elseif {$plot_type == 4} {
      set _pcmd VPLOT

   } elseif {$plot_type == 5} {
      set _pcmd NPLOT
      if {$plot_style < 6 || $plot_style > 7 } {
         set plot_style 7
      }

   } elseif {$plot_type == 6} {
      set _pcmd EPLOT

   } elseif {$plot_type == 7} {
      if {$::euidl::contact::ncpairs > 0} {
         catch {ans_sendcommand )/num,1} err
         for {set i 1} {$i <= $::euidl::contact::ncpairs} {incr i} {lappend cplotlist $i}
         ::euidl::contact::contactpairplot  $cplotlist
         close $fileID
         file delete scratch.mac
         return
      }

   } elseif {$plot_type == 10} {
      set _pcmd PLDI

   } elseif {$plot_type == 11} {
      set _pcmd PLDI,1

   } elseif {$plot_type == 12} {
      set _pcmd PLDI,2

   } elseif {$plot_type == 13} {
      modelBB
      close $fileID
      file delete scratch.mac
      return

   } elseif {$plot_type >= 101 && $plot_type <= 200} {
      set _j [expr $plot_type - 100]
      set ansItem [ans_getvalue PARM,_RSLTLAB($_j,1),VALUE]
      set _pcmd PLNS,$ansItem
      set item [string range $ansItem 0 3]
      if {[string match $item CONT]} {
         set comp [string range $ansItem 5 8]
         set trlkey on
         puts $fileID ")cm,_tempe,elem"
         puts $fileID ")/trl,elem,1,all"
         puts $fileID ")esel,s,ename,,174"
         puts $fileID ")/trl,elem,0,all"
         puts $fileID ")cmsel,a,_tempe"
         puts $fileID ")cmdel,_tempe"
         if {[string match $comp STA]} {
            set _pcmd PLNS,CONT,STAT
         } elseif {[string match $comp PRE]} {
            set _pcmd PLNS,CONT,PRES
         } elseif {[string match $comp FLU]} {
            set _pcmd PLNS,CONT,FLUX
         } elseif {[string match $comp TEM]} {
            set _pcmd PLNS,TEMP
         }
      }
      if {$plot_style == 5 && $_nlvl3d < 4} {
      } else {
         set plot_style 7
      }

   } else {
      set _pcmd /REPLOT
   }

#  *** get the current shape type to determine the correct
   if {$curshap > 0} {
      set _tmpxx [ans_getvalue parm,_SHAPTYP(_CURSHAP),value]
      set _pshape [string toupper $_tmpxx]
      set _tmpxx [ans_getvalue common,,d3com,,CHAR,4]
      set _lstpcmd [string toupper $_tmpxx]
      if {[string match AREA* $_pshape] == 1} {
         if {$plot_type == 4} {
            set _pcmd APLOT
         }
      }
   }

#  ***********************
#  *** set plot style  ***
#  ***********************
   puts $fileID ")/anno,dele  "
   puts $fileID ")/trl,$trlkey"
   puts $fileID ")/txtr,off   "
   puts $fileID ")/type,,6    "
   puts $fileID ")/dev,vect,0 "
   puts $fileID ")/plo,info,2 "
   puts $fileID ")/plo,leg1,off"
   puts $fileID ")/plo,leg2,off"
   puts $fileID ")/plopts,leg3,on"
   puts $fileID ")/num,1      "
   puts $fileID ")/edge       "
   puts $fileID ")/eshape     "
   puts $fileID ")/cval       "
   if {$plot_type == 6} {
      puts $fileID ")/glin"
      if {$plot_style == 3} {
         puts $fileID ")/eshape,1 "
      }
   } elseif {$plot_type >= 10 && $plot_type <= 12} {
      puts $fileID ")/gline"
      puts $fileID ")/edge,,1"
      # For a modal analysis the PLDI should not show the legend
      if [ans_getvalue ACTIVE,,KEYW,,MODAL] {
         puts $fileID "/plopts,info,off"
      }
   } else {
      puts $fileID ")/glin,,-1"
   }
#   brighten up ambient light for stress displays
   set planar [ans_getvalue parm,_PLANAR,value]
   if {$planar == 1} {
      puts $fileID ")/light,1,0,.5"
   } elseif {$plot_type >= 10 && $plot_type <= 12} {
      puts $fileID ")/light,1,0,.5"
   } elseif {$plot_type >= 101 && $plot_type <= 200} {
      puts $fileID ")/light,1,0,.5"
   } else {
      puts $fileID ")/light,1,0,0"
   }


   if {$plot_style == 1} {
#      ***  material plot by color with legend ***
      puts $fileID ")/pnum,mat,1"
      set _keyleg 1

   } elseif {$plot_style == 2} {
#      ***  material plot by texture ***
      puts $fileID ")/txtr,on"

   } elseif {$plot_style == 3} {
#      ***  thickness plot by color with legend ***
      puts $fileID ")/pnum,real,1"
      set _keyleg 2

   } elseif {$plot_style == 4} {
#      ***  material plot by translucency with legend ***
      puts $fileID ")/trl,on"
      set _keyleg 1

   } elseif {$plot_style == 5} {
#      ***  wireframe ***
      puts $fileID ")/type,,0    "
      puts $fileID ")/dev,vect,1 "
      puts $fileID ")/glin       "
      if {$plot_type >= 101 && $plot_type <= 200} {
         puts $fileID ")/num,1      "
      } else {
         puts $fileID ")/num,-1     "
      }

   } elseif {$plot_style == 6} {
#      ***  no color ***
      puts $fileID ")/num,-1"

   } elseif {$plot_style == 7} {
#      ***  show edges ***
      puts $fileID ")/pnum,type,0 "
      puts $fileID ")/pnum,mat, 0 "
      puts $fileID ")/pnum,real,0 "
      puts $fileID ")/glin        "

   } elseif {$plot_style == 8} {
#      ***  show parts ***
      if {[ans_getvalue parm,_NPARTS,type] == -1} {
         # No parts exists
      } else {
         puts $fileID ")/plo,info,3 "
         puts $fileID ")/plo,leg1,on "
         puts $fileID ")cmsel,none"
         puts $fileID ")cmsel,a,PART1"
         set n [ans_getvalue parm,_NPARTS,value]
         for {set i 2} {$i <= $n} {incr i} {
            puts $fileID ")cmsel,a,PART$i"
         }
         puts $fileID ")allsel"
         set _pcmd CMPLOT
      }

   } else {
#      ***  unknown ***
   }

   if {$_keyleg == 1} {
#     **************************
#     * legend stuff for MAT
#     **************************
      set _clr(1)   6
      set _clr(2)   3
      set _clr(3)  12
      set _clr(4)   5
      set _clr(5)   1
      set _clr(6)   8
      set _clr(7)  11
      set _clr(8)   2
      set _clr(9)   9
      set _clr(10)  4
      set _clr(11)  7
      set _cwid [ans_getvalue common,,d3com,,REAL,186]
      set _chgt [ans_getvalue common,,d3com,,REAL,244]
      puts $fileID ")/pspec,0,1,0"
      puts $fileID ")/lspec,15,0,1"
      puts $fileID ")/tspec,15"
      puts $fileID ")/ann,tmod,1"
      set _n [ans_getvalue parm,_NUMMATL,value]
      set _x1 [expr -1+.5*$_cwid]
      set _x2 [expr $_x1+3.*$_cwid]
      set _y2 [expr  1-.5*$_chgt]
      set _x1t [expr $_x1+4*$_cwid]
      set _i 1
      while {$_i <= $_n} {
         set _mused [ans_getvalue parm,_MATLDP($_i,4,1),value]
         if {$_mused == 1} {
            set _y1 [expr $_y2-$_chgt]
            set _y2a [expr $_y1+.75*$_chgt]
            set _iclr [expr ((($_i-1)%11)+1)]
            puts $fileID ")/pspec,$_clr($_iclr),1,1"
            set _mnx(1) [ans_getvalue parm,_MATLNAM($_i,1),value]
            set _mnx(2) [ans_getvalue parm,_MATLNAM($_i,2),value]
            set _mnx(3) [ans_getvalue parm,_MATLNAM($_i,3),value]
            set _mnx(4) [ans_getvalue parm,_MATLNAM($_i,4),value]
            puts $fileID ")/tlab,$_x1t,$_y1,$_mnx(1)$_mnx(2)$_mnx(3)$_mnx(4)"
            puts $fileID ")/poly,4,$_x1,$_y2a,$_x1,$_y1,$_x2,$_y1,$_x2,$_y2a"
            set _y2 $_y1
         }
         incr _i
      }

   } elseif {$_keyleg == 2} {
#     **************************
#     * legend stuff for REAL
#     **************************
      set _clr(1)   6
      set _clr(2)   3
      set _clr(3)  12
      set _clr(4)   5
      set _clr(5)   1
      set _clr(6)   8
      set _clr(7)  11
      set _clr(8)   2
      set _clr(9)   9
      set _clr(10)  4
      set _clr(11)  7
      set _cwid [ans_getvalue common,,d3com,,REAL,186]
      set _chgt [ans_getvalue common,,d3com,,REAL,244]
      puts $fileID ")/pspec,0,1,0"
      puts $fileID ")/lspec,15,0,1"
      puts $fileID ")/tspec,15"
      puts $fileID ")/ann,tmod,1"
      set _n [ans_getvalue parm,_NUMSHAP,value]
      set _x1 -1
      set _x2 [expr -1+20*$_cwid]
      set _y1 [expr 1-$_n*$_chgt-$_chgt]
      set _y2 1
#      puts $fileID ")/poly,4,$_x1,$_y2,$_x1,$_y1,$_x2,$_y1,$_x2,$_y2"
      set _x1 [expr $_x1+.5*$_cwid]
      set _x2 [expr $_x1+3.*$_cwid]
      set _y2 [expr $_y2-.5*$_chgt]
      set _i 1
      while {$_i <= $_n} {
         set _mused [ans_getvalue parm,_SHAPDP($_i,4,1),value]
         if {$_mused == 1} {
            set _y1 [expr $_y2-$_chgt]
            set _y2a [expr $_y1+.75*$_chgt]
            set _x1t [expr $_x1+4*$_cwid]
            set _k [ans_getvalue parm,_SHAPDP($_i,2,1),value]
            if {$_k == 0} {
               set _k 1
            }
            set _iclr [expr ((($_k-1)%11)+1)]
            puts $fileID ")/pspec,$_clr($_iclr),1,1"
            set _snx(1) [ans_getvalue parm,_SHAPNAM($_i,1),value]
            set _snx(2) [ans_getvalue parm,_SHAPNAM($_i,2),value]
            set _snx(3) [ans_getvalue parm,_SHAPNAM($_i,3),value]
            set _snx(4) [ans_getvalue parm,_SHAPNAM($_i,4),value]
            puts $fileID ")/tlab,$_x1t,$_y1,$_snx(1)$_snx(2)$_snx(3)$_snx(4)"
            puts $fileID ")/poly,4,$_x1,$_y2a,$_x1,$_y1,$_x2,$_y1,$_x2,$_y2a"
            set _y2 [expr $_y2-$_chgt]
         }
         incr _i
       }
   }
#   *****************************
#   ***  add legend to POST plots
#   *****************************
   if {$plot_type >= 101 && $plot_type <= 200} {
      set _j [expr $plot_type - 100]
      set _cwid [ans_getvalue common,,d3com,,REAL,186]
      set _chgt [ans_getvalue common,,d3com,,REAL,244]
      puts $fileID ")/ann,tmod,1"
      set _x1 [expr -1+.5*$_cwid]
      set _y1 [expr  1-1.5*$_chgt]
      set _snx(1) [ans_getvalue parm,_RSLTNAM($_j,1),value]
      set _snx(2) [ans_getvalue parm,_RSLTNAM($_j,2),value]
      set _snx(3) [ans_getvalue parm,_RSLTNAM($_j,3),value]
      set _snx(4) [ans_getvalue parm,_RSLTNAM($_j,4),value]
      puts $fileID ")/tlab,$_x1,$_y1,$_snx(1)$_snx(2)$_snx(3)$_snx(4)"
      if [ans_getvalue ACTIVE,,KEYW,,MODAL] {
         puts $fileID "/plopts,info,off"
      } elseif {[string match CONT,STA $ansItem] == 1} {
         # contact status - build our own legend
         puts $fileID ")/plopts,leg3,off"
         puts $fileID ")/pspec,0,1,0"
         puts $fileID ")/lspec,15,0,1"
         puts $fileID ")/tspec,15"
         puts $fileID ")/ann,tmod,1"
         puts $fileID ")/cval,,0,2.01,3.01"
         set _x1 .95
         set _x1t [expr $_x1+4.*$_cwid]
         set _x2 [expr $_x1+3.*$_cwid]
         set _y1 [expr 1-5*$_chgt]
         set _y2a [expr $_y1+.75*$_chgt]
         puts $fileID ")/tlab,$_x1t,$_y1,Not in Contact"
         puts $fileID ")/pspec,4,1,1"
         puts $fileID ")/poly,4,$_x1,$_y2a,$_x1,$_y1,$_x2,$_y1,$_x2,$_y2a"
         set _y1 [expr $_y1-$_chgt]
         set _y2a [expr $_y1+.75*$_chgt]
         if [ans_getvalue ACTIVE,,KEYW,,PR_STRUC] {
            puts $fileID ")/tlab,$_x1t,$_y1,Sliding/Partial"
         } else {
            puts $fileID ")/tlab,$_x1t,$_y1,Partial"
         }
         puts $fileID ")/pspec,8,1,1"
         puts $fileID ")/poly,4,$_x1,$_y2a,$_x1,$_y1,$_x2,$_y1,$_x2,$_y2a"
         set _y1 [expr $_y1-$_chgt]
         set _y2a [expr $_y1+.75*$_chgt]
         puts $fileID ")/tlab,$_x1t,$_y1,In Contact"
         puts $fileID ")/pspec,12,1,1"
         puts $fileID ")/poly,4,$_x1,$_y2a,$_x1,$_y1,$_x2,$_y1,$_x2,$_y2a"
      } else {
         # add units to the plot contour legend
         set _y2 [ans_getvalue common,,d3com,,REAL,167]
         if {$_y2 > [expr 1-13*$_chgt] } {
            # no existing plot: estimate the location
            #set _nc [ans_getvalue graph,1,contour,ncont]
            set _y2 [expr 1-13*$_chgt]
         }
         set _y1 [expr $_y2-$_chgt]
         set _x1 [expr 1.05+5.*$_cwid]
         if [ans_getvalue ACTIVE,,KEYW,,PR_STRUC] {
            if {[string match S,* $ansItem] == 1} {
               #puts $fileID "/eshape,1"   ### remove: causes element outlines on model
               set _snx(1) [ans_getvalue PARM,_PRESLAB(_CURUNIT),VALUE]
            } elseif {[string match CONT,PRE $ansItem] == 1} {
               set _snx(1) [ans_getvalue PARM,_PRESLAB(_CURUNIT),VALUE]
            } else {
               set _snx(1) [ans_getvalue PARM,_LENGLAB(_CURUNIT),VALUE]
            }
         } else {
            if {[string match TG* $ansItem] == 1} {
               set _snx(2) [string trim [ans_getvalue PARM,_TEMPLAB(_CURUNIT),VALUE]]
               set _snx(3) [string trim [ans_getvalue PARM,_LENGLAB(_CURUNIT),VALUE]]
               set _snx(1) "$_snx(2)/$_snx(3)"
            } elseif {[string match TF* $ansItem] == 1} {
               set _snx(1) [ans_getvalue PARM,_HFLXLAB(_CURUNIT),VALUE]
            } elseif {[string match CONT,FLU $ansItem] == 1} {
               set _snx(1) [ans_getvalue PARM,_HFLXLAB(_CURUNIT),VALUE]
            } else {
               set _snx(1) [ans_getvalue PARM,_TEMPLAB(_CURUNIT),VALUE]
            }
         }
         puts $fileID ")/tlab,$_x1,$_y1,$_snx(1)"
      }
   }

#   ***************************
#   ***  set current states ***
#   ***************************
   puts $fileID ")*set,_CURPLT,$plot_style"
   puts $fileID ")*set,_CURPTYP,$plot_type"

#   ****************************
#   ***  issue plot command  ***
#   ****************************
   puts $fileID ")$_pcmd"
   puts $fileID ")/go"
   set _success 1
   close $fileID
   catch {ans_sendcommand ")/nopr\$)scratch"} err
   file delete scratch.mac
   ::euidl::updateRenderList
}

proc ::euidl::modelBB { {lengthLab ""} } {
   variable euidlArray

   set prkey [ans_getvalue ACTIVE,,PRKEY]
   catch {ans_sendcommand )/NOPR} err
   catch {ans_sendcommand )CM,_KPOI,KP} err
   catch {ans_sendcommand )KSLL,S } err
   set minX [ans_getvalue KP,,MNLOC,X]
   set maxX [ans_getvalue KP,,MXLOC,X]
   set minY [ans_getvalue KP,,MNLOC,Y]
   set maxY [ans_getvalue KP,,MXLOC,Y]
   set minZ [ans_getvalue KP,,MNLOC,Z]
   set maxZ [ans_getvalue KP,,MXLOC,Z]

   # draw line from (min,min,min) (max,min,min) and show length
   set length \
         [format "%5.3g %s" [expr sqrt(pow(($maxX-$minX),2))] $lengthLab]
   set midPt [expr ($maxX+$minX) / 2.0]
   ans_sendcommand )/OUT,scratch
   ans_sendcommand )/GO
   ans_sendcommand )/AN3D,ANUM,0,102,$midPt,$minY,$minZ
   ans_sendcommand )/OUT,TERM
   set fileID [open scratch r]
   while {[gets $fileID line] >= 0} {
      if [string match *Annotation* $line] {
         set modelBndBox [lindex $line 1]
      }
   }
   close $fileID
   catch {ans_sendcommand )/NOPR}
   catch {ans_sendcommand )/AN3D,LINE,$minX,$minY,$minZ,$maxX,$minY,$minZ}
   catch {ans_sendcommand )/AN3D,TEXT,$midPt,$minY,$minZ,$length}
   # draw line from (min,min,min) (min,max,min) and show length
   set length \
         [format "%5.3g %s" [expr sqrt(pow(($maxY-$minY),2))] $lengthLab]
   set midPt [expr ($maxY+$minY) / 2.0]
   catch {ans_sendcommand )/AN3D,LINE,$minX,$minY,$minZ,$minX,$maxY,$minZ}
   catch {ans_sendcommand )/AN3D,TEXT,$minX,$midPt,$minZ,$length}
   # draw line from (minX,minY,minZ) (minX,minY,maxZ) and show length
   catch {ans_sendcommand )/AN3D,LINE,$minX,$minY,$minZ,$minX,$minY,$maxZ}
   set length \
         [format "%5.3g %s" [expr sqrt(pow(($maxZ-$minZ),2))] $lengthLab]
   set midPt [expr ($maxZ+$minZ) / 2.0]
   catch {ans_sendcommand )/AN3D,TEXT,$minX,$minY,$midPt,$length}

   # draw line from (maxX,minY,minZ) (maxX,maxY,minZ)
   catch {ans_sendcommand )/AN3D,LINE,$maxX,$minY,$minZ,$maxX,$maxY,$minZ}
   # draw line from (maxX,minY,minZ) (maxX,minY,maxZ)
   catch {ans_sendcommand )/AN3D,LINE,$maxX,$minY,$minZ,$maxX,$minY,$maxZ}

   # draw line from (minX,maxY,minZ) (maxX,maxY,minZ)
   catch {ans_sendcommand )/AN3D,LINE,$minX,$maxY,$minZ,$maxX,$maxY,$minZ}
   # draw line from (minX,maxY,minZ) (minX,maxY,maxZ)
   catch {ans_sendcommand )/AN3D,LINE,$minX,$maxY,$minZ,$minX,$maxY,$maxZ}

   # draw line from (minX,minY,maxZ) (maxX,minY,maxZ)
   catch {ans_sendcommand )/AN3D,LINE,$minX,$minY,$maxZ,$maxX,$minY,$maxZ}
   # draw line from (minX,minY,maxZ) (minX,maxY,maxZ)
   catch {ans_sendcommand )/AN3D,LINE,$minX,$minY,$maxZ,$minX,$maxY,$maxZ}

   # draw line from (maxX,maxY,maxZ) (maxX,minY,maxZ)
   catch {ans_sendcommand )/AN3D,LINE,$maxX,$maxY,$maxZ,$maxX,$minY,$maxZ}
   # draw line from (maxX,maxY,maxZ) (minX,maxY,maxZ)
   catch {ans_sendcommand )/AN3D,LINE,$maxX,$maxY,$maxZ,$minX,$maxY,$maxZ}
   # draw line from (maxX,maxY,maxZ) (maxX,maxY,minZ)
   catch {ans_sendcommand )/AN3D,LINE,$maxX,$maxY,$maxZ,$maxX,$maxY,$minZ}

   catch {ans_sendcommand )CMSEL,S,_KPOI} err
   catch {ans_sendcommand )/REPLOT} err
   if {$prkey} {
      catch {ans_sendcommand )/GO} err
   }
   file delete scratch
}

# End Display  }

################################################################################
# New paradigm 6/13/2000
################################################################################
# All of the commands and settings that are utilized for the graphics
# window or the individual windows should reside in the graphics namespace

namespace eval euidl::graphics {

   variable onoffArray
   # /ERASE or /NOERASE
   set onoffArray(erase) 1
   set onoffArray(showwp) 0
   set onoffArray(legend) 1
   # A variable that tells us to plot model in vector mode
   set onoffArray(vector) [ans_getvalue GRAPH,,DISPLAY]

   # A variable that tells us to plot contour results in vector mode
   set onoffArray(vector,contours) 0

namespace eval s_pnum {
      variable vA
      set vA(cmdName,Fld#,in/out) -999
      variable entityIDFrm
      variable pgrFileActive

      # /PNUM command
      proc create { } {
         variable vA
         variable parent
         variable entityIDFrm
         variable pgrFileActive

         if {[ans_getvalue active,,rout] == 31} {
            set pgrFileActive [ans_getvalue RSET,,PGR]
         }

         initializeData

         if {[winfo exists .dlg_S_PNUM]} {
            $parent activate
            return
         }

         set parent [euidl::dialog .dlg_S_PNUM \
               -class EUIDL]
         set childsite [$parent component childsite]

         grid columnconfigure $childsite 0 -weight 1

         wm title $parent [::msgcat::mc "Entity Identification"]

         euidl::labeledframe $childsite.frmNumDisplay \
               -text [::msgcat::mc "Label Entities with:"]

         set lfchildSite [$childsite.frmNumDisplay component childsite]
         grid $childsite.frmNumDisplay -column 0 -row 0 -sticky new

#         euidl::checkbutton $lfchildSite.chkAttr \
#               -text [msgcat::mc "Attribute ID"] \
#               -variable [scope vA(ATTR)] \
#               -command [namespace code S_PNUM_exec]
         euidl::combobox $lfchildSite.cmbAttr \
               -variable [scope vA(ATTR,Type)] \
               -command [namespace code S_PNUM_exec]

         if {!$pgrFileActive} {
         $lfchildSite.cmbAttr insert list end [list \
               [::msgcat::mc "Entity number"] ENT \
               ]
         }

         $lfchildSite.cmbAttr insert list end [list \
               [::msgcat::mc "Material number"] MAT \
               [::msgcat::mc "Element type number"] TYPE \
               [::msgcat::mc "Real constant number"] REAL \
               ]

         if {!$pgrFileActive} {
         $lfchildSite.cmbAttr insert list end [list \
               [::msgcat::mc "Element CS number"] ESYS \
               ]
         }

         set vA(ATTR,Type) MAT
#         grid $lfchildSite.chkAttr -column 0 -row 0 -sticky nw
#         grid $lfchildSite.cmbAttr -column 0 -row 1 -sticky nw -padx 20
         grid $lfchildSite.cmbAttr -column 0 -row 1 -sticky nw

         euidl::checkbutton $lfchildSite.chkColors \
               -text [msgcat::mc "Colors"] \
               -variable [scope vA(NUM,color)] \
               -command [namespace code S_PNUM_exec]
         euidl::checkbutton $lfchildSite.chkNumbers \
               -text [msgcat::mc "Numbers"] \
               -variable [scope vA(NUM,number)] \
               -command [namespace code S_PNUM_exec]

         grid $lfchildSite.chkColors -column 0 -row 2 -sticky nw -padx 2
         grid $lfchildSite.chkNumbers -column 0 -row 3 -sticky nw -padx 2


         euidl::labeledframe $childsite.frmEntNum \
               -text [::msgcat::mc "Display Entity Labels for:"]
         set entityIDFrm $childsite.frmEntNum

         set lfchildSite2 [$childsite.frmEntNum component childsite]

         euidl::checkbutton $lfchildSite2.chkNODE \
               -variable [scope vA(NODE)] \
               -text [msgcat::mc "Nodes"] \
               -command [namespace code S_PNUM_exec]
         euidl::checkbutton $lfchildSite2.chkELEM \
               -variable [scope vA(ELEM)] \
               -text [msgcat::mc "Elements"] \
               -command [namespace code S_PNUM_exec]
         euidl::checkbutton $lfchildSite2.chkKP \
               -variable [scope vA(KP)] \
               -text [msgcat::mc "Keypoints"] \
               -command [namespace code S_PNUM_exec]
         euidl::checkbutton $lfchildSite2.chkLINE \
               -variable [scope vA(LINE)] \
               -text [msgcat::mc "Lines"] \
               -command [namespace code S_PNUM_exec]
         euidl::checkbutton $lfchildSite2.chkAREA \
               -variable [scope vA(AREA)] \
               -text [msgcat::mc "Areas"] \
               -command [namespace code S_PNUM_exec]
         euidl::checkbutton $lfchildSite2.chkVOLU \
               -variable [scope vA(VOLU)] \
               -text [msgcat::mc "Volumes"] \
               -command [namespace code S_PNUM_exec]

         if {!$pgrFileActive} {
         grid $childsite.frmEntNum -column 0 -row 1 -sticky new
         grid $lfchildSite2.chkNODE -column 0 -row 0 -sticky nw
         grid $lfchildSite2.chkELEM -column 0 -row 1 -sticky nw
         grid $lfchildSite2.chkKP -column 0 -row 2 -sticky nw
         grid $lfchildSite2.chkLINE -column 0 -row 3 -sticky nw
         grid $lfchildSite2.chkAREA -column 0 -row 4 -sticky nw
         grid $lfchildSite2.chkVOLU -column 0 -row 5 -sticky nw

         grid columnconfigure $childsite 0 -weight 1
         grid columnconfigure $lfchildSite 0 -weight 1 -minsize 300
         grid columnconfigure $lfchildSite 0 -weight 1
         grid columnconfigure $lfchildSite2 0 -weight 1
         }

         $parent configure \
               -okcommand [namespace code S_PNUM_Ok] \
               -oktext [::msgcat::mc "Close"] \
               -canceltext [::msgcat::mc "Replot"] \
               -cancelcommand [list ans_sendcommand )/REPLOT] \
               -helpcommand [list ans_loadhelp Hlp_C_/PNUM]

         # The configure on the parent will set WM_DELTE_WINDOW to cancelcommand
         wm protocol $parent WM_DELETE_WINDOW [namespace code S_PNUM_Ok]

         $parent activate

      }
      proc S_PNUM_Ok { args } {
         variable parent
         variable vA
         variable pgrFileActive

         if {$vA(NUM,number) == 0} {
            set numVal [expr $vA(NUM,color)?1:-1]
         } else {
            set numVal [expr $vA(NUM,color)?0:2]
         }

         if {!$pgrFileActive} {
            ans_sendcommand /PNUM,KP,$vA(KP)
            ans_sendcommand /PNUM,LINE,$vA(LINE)
            ans_sendcommand /PNUM,AREA,$vA(AREA)
            ans_sendcommand /PNUM,VOLU,$vA(VOLU)
            ans_sendcommand /PNUM,NODE,$vA(NODE)
         }
         # Primary plotted item will show
         if {[string match ENT $vA(ATTR,Type)]} {
            ans_sendcommand /PNUM,MAT,0
            ans_sendcommand /PNUM,TYPE,0
            ans_sendcommand /PNUM,REAL,0
            ans_sendcommand /PNUM,ESYS,0
            ans_sendcommand /PNUM,ELEM,$vA(ELEM)
         } else {
            ans_sendcommand /PNUM,$vA(ATTR,Type),1
         }
         ans_sendcommand /NUMBER,$numVal

         $parent deactivate
         # If the user switches between pgr and r.. files we need to
         # recreate so destroy.
         destroy $parent
      }
      proc S_PNUM_exec { args } {
         variable vA
         variable entityIDFrm
         variable pgrFileActive

         if {$vA(NUM,number) == 0} {
            set numVal [expr $vA(NUM,color)?1:-1]
         } else {
            set numVal [expr $vA(NUM,color)?0:2]
         }

         ans_sendcommand )/NOPR
         if {!$pgrFileActive} {
            ans_sendcommand /PNUM,KP,$vA(KP)
            ans_sendcommand /PNUM,LINE,$vA(LINE)
            ans_sendcommand /PNUM,AREA,$vA(AREA)
            ans_sendcommand /PNUM,VOLU,$vA(VOLU)
            ans_sendcommand /PNUM,NODE,$vA(NODE)
         }
         # Primary plotted item will show
         if {[string match ENT $vA(ATTR,Type)]} {
               ans_sendcommand )/PNUM,MAT,0
               ans_sendcommand )/PNUM,TYPE,0
               ans_sendcommand )/PNUM,REAL,0
               ans_sendcommand )/PNUM,ESYS,0
               ans_sendcommand )/PNUM,ELEM,$vA(ELEM)
         } else {
               ans_sendcommand )/PNUM,$vA(ATTR,Type),1
         }
         ans_sendcommand )/NUMBER,$numVal
         ans_sendcommand )/GO
      }
      proc initializeData { } {
         variable vA
         variable pgrFileActive
         set vA(NODE) [ans_getvalue COMMON,,D3COM,,INT,96]
         set vA(ELEM) [ans_getvalue COMMON,,D3COM,,INT,97]

         set vA(MAT) [ans_getvalue COMMON,,D3COM,,INT,98]
         set vA(TYPE) [ans_getvalue COMMON,,D3COM,,INT,99]
         set vA(REAL) [ans_getvalue COMMON,,D3COM,,INT,100]
         set vA(ESYS) [ans_getvalue COMMON,,D3COM,,INT,109]

         if {$vA(MAT)} {
            set vA(NUM,Type) MAT
         } elseif {$vA(TYPE)} {
            set vA(NUM,Type) TYPE
         } elseif {$vA(REAL)} {
            set vA(NUM,Type) REAL
         } elseif {$vA(ESYS)} {
            set vA(NUM,Type) ESYS
         } else {
            if {!$pgrFileActive} {
               set vA(NUM,Type) MAT
            } else {
               set vA(NUM,Type) ENT
            }
         }

         set vA(LOC) [ans_getvalue COMMON,,D3COM,,INT,101]
         set vA(EXCL) [ans_getvalue COMMON,,D3COM,,INT,102]
         set vA(KP) [ans_getvalue COMMON,,D3COM,,INT,104]
         set vA(LINE) [ans_getvalue COMMON,,D3COM,,INT,105]
         set vA(AREA) [ans_getvalue COMMON,,D3COM,,INT,106]
         set vA(VOLU) [ans_getvalue COMMON,,D3COM,,INT,107]
         set vA(SVAL) [ans_getvalue COMMON,,D3COM,,INT,108]
         set vA(TABN) [ans_getvalue COMMON,,D3COM,,INT,110]
         set vA(SECT) [ans_getvalue COMMON,,D3COM,,INT,111]

         set num [ans_getvalue COMMON,,D3COM,,INT,30]
         switch -- $num {
            -1 {
               set vA(NUM,color) 0
               set vA(NUM,number) 0
            }
            0 {
               set vA(NUM,color) 1
               set vA(NUM,number) 1
            }
            1 {
               set vA(NUM,color) 1
               set vA(NUM,number) 0
            }
            2 {
               set vA(NUM,color) 0
               set vA(NUM,number) 1
            }
         }

      }
}

# ----------------------------------------------------------------------------
# PUBLIC PROCEDURE:  captureImage
#
# Purpose:           Used to capture the current display to a screen,
#                    printer or file
#
# Arguments:         N/A
#
# Return Value:      N/A
#
# Comments:          N/A
#
# See Also:
#
# ----------------------------------------------------------------------------
namespace eval captureImage {
   variable print2File 0
   variable printChild
   variable printerAppearance 2
   variable printerOrient 90
   variable printerData
   variable printerName
   variable printerQuality 600
   variable printMasterWin
   variable printCopies 1
   variable orientChild
   variable copyChild

proc create { {masterWin {}} {grabWin {}} } {
   variable printChild
   variable printPS
   variable printerData
   variable printerName
   variable printMasterWin
   variable printerQuality
   variable print2File
   variable orientChild
   variable copyChild

      if { [string match . $grabWin] } {
         set grabWin {}
      }
      if [winfo exists $grabWin.captureImage] {

         if {[::euidl::EuidlEditor::getPrinterInfo printerData]} {
            $printChild.print2Printer configure -state normal
            $printChild.lblPrinter configure -state normal
            $printChild.cmbPrinter configure -state normal
            set print2File 0
         } else {
            $printChild.print2Printer configure -state disabled
            $printChild.lblPrinter configure -state disabled
            $printChild.cmbPrinter configure -state disabled
            set print2File 1
      
         }
   
         $grabWin.captureImage activate
      } else {
      #
      if {[string match {} $masterWin]} {
         set parent \
               [::euidl::dialog $grabWin.captureImage -class EUIDL]
         set printMasterWin .
      } else {
         set parent \
               [::euidl::dialog $grabWin.captureImage \
                     -master $masterWin -class EUIDL ]
         set printMasterWin $masterWin
      }

      set child [$parent component childsite]

      # There must be a class to get the title so use the child
      $parent configure \
            -title [msgcat::mc "Image Capture"]

      # Create the printer group box
      euidl::labeledframe $child.grpPrinterTitle \
               -text [::msgcat::mc "Printer"]
      set printChild [$child.grpPrinterTitle component childsite]
      grid $child.grpPrinterTitle -column 0 -row 0 -sticky news
      grid columnconfigure $printChild 0 -weight 1

      grid columnconfigure $child 0 -weight 1
      grid columnconfigure $child 1 -weight 1

      label $printChild.lblPrinter \
            -text [msgcat::mc "Name:"]

      euidl::combobox $printChild.cmbPrinter \
            -command [code updatePrinterInfo] \
            -width 16 \
            -variable [scope printerName]

      label $printChild.lblPrinterQuality \
            -text [msgcat::mc "Quality:"]
      euidl::combobox $printChild.cmbPrinterQuality \
            -width 16 \
            -variable [scope printerQuality]

      $printChild.cmbPrinterQuality insert list end \
            [list [msgcat::mc draft] 600]
      $printChild.cmbPrinterQuality insert list end \
            [list [msgcat::mc normal] 1200]
      $printChild.cmbPrinterQuality insert list end \
            [list [msgcat::mc presentation] 2400]

      set printerQuality 600

      euidl::radiobutton $printChild.print2Printer \
         -command [namespace code captureToChange]  \
         -variable [scope print2File] \
         -value 0 \
         -text [msgcat::mc "Capture to printer"]

      euidl::radiobutton $printChild.print2File \
         -command [namespace code captureToChange]  \
         -variable [scope print2File] \
         -value 1 \
         -text [msgcat::mc "Capture to file"]

      euidl::radiobutton $printChild.print2Screen \
         -command [namespace code captureToChange]  \
         -variable [scope print2File] \
         -value 2 \
         -text [msgcat::mc "Capture to screen"]

      grid $printChild.print2Printer \
            -sticky nw \
            -column 0 -row 0
      grid $printChild.lblPrinter \
            -sticky nw \
            -column 0 -row 1 -padx 15
      grid $printChild.cmbPrinter \
            -sticky nw \
            -column 1 -row 1 \
            -padx 5
      grid $printChild.lblPrinterQuality \
            -sticky nw \
            -column 0 -row 2 \
            -pady 5 -padx 15
      grid $printChild.cmbPrinterQuality \
            -sticky nw \
            -column 1 -row 2 \
            -padx 5 -pady 5
      grid $printChild.print2File \
            -sticky w \
            -column 0 -row 3 \
            -columnspan 2 -padx 5
      grid $printChild.print2Screen \
            -sticky w \
            -column 0 -row 4 \
            -columnspan 2 -padx 5

      # Create the appearance group box
      euidl::labeledframe $child.grpAppearance \
               -text [::msgcat::mc "Appearance"]
      set appearChild [$child.grpAppearance component childsite]

      grid $child.grpAppearance -column 1 -row 0 -sticky news
      grid columnconfigure $appearChild 0 -weight 1
      grid rowconfigure $appearChild 4 -weight 1

      euidl::radiobutton $appearChild.monoChrome \
         -variable [scope printerAppearance] \
         -value 0 \
         -text [msgcat::mc "Monochrome"]
      euidl::radiobutton $appearChild.greyScale \
         -variable [scope printerAppearance] \
         -value 3 \
         -text [msgcat::mc "Grey scale"]
      euidl::radiobutton $appearChild.color \
         -variable [scope printerAppearance] \
         -value 2 \
         -text [msgcat::mc "Color"]

      grid $appearChild.monoChrome -column 0 -row 0 -sticky nw
      grid $appearChild.greyScale -column 0 -row 1 -sticky nw
      grid $appearChild.color -column 0 -row 2 -sticky nw

      # Create the copy group box
      euidl::labeledframe $child.grpCopy \
               -text [::msgcat::mc "Copies"]
      set copyChild [$child.grpCopy component childsite]

      grid $child.grpCopy -column 0 -row 1 -sticky news
      grid columnconfigure $copyChild 0 -weight 1

      euidl::label $copyChild.lblNumCopies \
            -text [msgcat::mc "Number of copies:"]

      euidl::spinint $copyChild.spnNumCopies \
            -width 3 \
            -range {1 999} \
            -variable [scope printCopies]

      grid $copyChild.lblNumCopies \
            -sticky w
      grid $copyChild.spnNumCopies \
            -column 1 -row 0 \
            -padx 5 -sticky w

      # Create the orientation group box
      euidl::labeledframe $child.grpOrient \
               -text [::msgcat::mc "Orientation"]
      set orientChild [$child.grpOrient component childsite]

      grid $child.grpOrient -column 1 -row 1 -sticky news
      grid columnconfigure $orientChild 0 -weight 1
      grid rowconfigure $orientChild 4 -weight 1

      euidl::radiobutton $orientChild.rdbLandscape \
         -variable [scope printerOrient] \
         -value 90 \
         -text [msgcat::mc "Landscape"]
      euidl::radiobutton $orientChild.rdbPortrait \
         -variable [scope printerOrient] \
         -value 0 \
         -text [msgcat::mc "Portrait"]

      grid $orientChild.rdbLandscape -column 0 -row 0 -sticky nw
      grid $orientChild.rdbPortrait -column 0 -row 1 -sticky nw

   # Define the action buttons
   $parent configure \
          -okcommand [code [list  captureImage_ok $parent $copyChild]] \
          -cancelcommand [list destroy $parent] \
          -helpbutton 0
          # There needs to be custom help created.
   catch {unset printerData}
   if {[::euidl::EuidlEditor::getPrinterInfo printerData]} {
      foreach printer $printerData(list) {
         $printChild.cmbPrinter insert list end \
               [list $printerData(name,$printer) $printer]
      }
      set printerName $printerData(default)
      set print2File 0
      updatePrinterInfo
   } else {
      # No printers
      $printChild.cmbPrinter insert list end \
            [list [msgcat::mc "None Installed"] -999]
      set printerName -999
      $printChild.print2Printer configure -state disabled
      $printChild.lblPrinter configure -state disabled
      $printChild.cmbPrinter configure -state disabled
      set print2File 1
   }

   ::euidl::registerWindow $parent
   $parent activate
  }
  #
}

proc captureToChange {args} {
   variable print2File
   variable printChild
   variable orientChild
   variable copyChild

   update
   switch -- $print2File {
      0 {
         # printer
         $printChild.lblPrinter configure -state normal
         $printChild.cmbPrinter configure -state normal
         $copyChild.lblNumCopies configure -state normal
         $copyChild.spnNumCopies configure -state normal 
         updatePrinterInfo
      }
      1 {
         # file
         $printChild.lblPrinter configure -state disabled
         $printChild.cmbPrinter configure -state disabled
         $printChild.lblPrinterQuality configure -state normal
         $printChild.cmbPrinterQuality configure -state normal
         $orientChild.rdbLandscape configure -state normal
         $orientChild.rdbPortrait configure -state normal
         $copyChild.lblNumCopies configure -state disabled
         $copyChild.spnNumCopies configure -state disabled 
      }
      2 {
         # screen
         $printChild.lblPrinter configure -state disabled
         $printChild.cmbPrinter configure -state disabled
         $printChild.lblPrinterQuality configure -state disabled
         $printChild.cmbPrinterQuality configure -state disabled
         $orientChild.rdbLandscape configure -state disabled
         $orientChild.rdbPortrait configure -state disabled
         $copyChild.lblNumCopies configure -state disabled
         $copyChild.spnNumCopies configure -state disabled 
      }
      default {
      }
   }
}

proc getPrinterInfo { } {
   global env tcl_platform
   variable printChild
   variable printerName
   variable printerData

   return
   # THIS SHOULD NOT BE GETTING CALLED USE ::euidl::EuidlEditor::getPrinterInfo
   set noPrinters 1
   catch {unset printerData}

   if [string match unix $tcl_platform(platform)] {
      set printerData(list) [list]
      switch -regexp -- $env(EUIDL_SYSTEM) {
         alpha {
            if {[catch {split [exec lpstat -v] \n} printerList]} {
               ans_senderror 2 [msgcat::mc "There is a problem accessing the\
                  printer information"]
               set printerList [list]
            }
            if { [string match {} $printerList] } {
               set noPrinters 1
            } else {
               foreach printer $printerList {
                  $printChild.cmbPrinter insert list end \
                        [list [lindex $printer 3] [lindex $printer 3]]
                  set printerData(name,[lindex $printer 3]) [lindex $printer 3]
                  set printerData(lpr,[lindex $printer 3]) 1
                  set printerData(psType,[lindex $printer 3]) none
                  lappend printerData(list) [lindex $printer 3]
               }
               set noPrinters 0
               set printerDefault [lindex [exec lpstat -d] end]
               if [string match destination $printerDefault] {
                  $printChild.cmbPrinter selection set 0
               } elseif { [lsearch $printerData(list) $printerDefault] == -1 } {
                  # Not found
                  $printChild.cmbPrinter selection set 0
               } else {
                   set printerName $printerDefault
               }
            }
         }
         rs64? -
         rs6000 {
            set printerList [list]
            if {[catch {lreplace [split [exec /usr/bin/lsallq] \n] 0 1} \
                  printerList]} {
               ans_senderror 2 [msgcat::mc "There is a problem accessing the\
                  printer information"]
               set printerList [list]
            }
            if { [string match {} $printerList] } {
               set noPrinters 1
            } else {
               foreach printer $printerList {
                  $printChild.cmbPrinter insert list end \
                        [list $printer $printer]
                  set printerData(name,$printer) $printer
                  set printerData(lpr,$printer) 1
                  set printerData(psType,$printer) none
               }
               $printChild.cmbPrinter selection set 0
               set noPrinters 0
            }
         }
         hppa7000 -
         hppa8000-64 -
         hppa8000 -
         solaris -
         sun64? -
         usparc -
         sgi32 -
         sgi64 {
            if {[catch {split [exec lpstat -a] \n} printerList]} {
               ans_senderror 2 [msgcat::mc "There is a problem accessing the\
                  printer information"]
               set printerList [list]
            }
            if { [string match {} $printerList] } {
               set noPrinters 1
            } else {
               foreach printer $printerList {
                  $printChild.cmbPrinter insert list end \
                        [list [lindex $printer 0] [lindex $printer 0]]
                  set printerData(name,[lindex $printer 0]) [lindex $printer 0]
                  set printerData(lpr,[lindex $printer 0]) 1
                  set printerData(psType,[lindex $printer 0]) none
                  lappend printerData(list) [lindex $printer 3]
               }
               if {[string match {} [array names env PRINTER]]} {
                  set printerDefault [lindex [exec lpstat -d] end]
                  if [string match destination $printerDefault] {
                     $printChild.cmbPrinter selection set 0
                  } elseif {[lsearch $printerData(list) $printerDefault]==-1} {
                     # Not found
                     $printChild.cmbPrinter selection set 0
                  } else {
                     set printerName $printerDefault
                  }
               } else {
                  set printerName $env(PRINTER)
               }
               set noPrinters 0
            }
         }
      }
   } else {
      $printChild.cmbPrinter delete list 0 end
      # NOTE:  changed ControlSet001 to CurrentControlSet (cet)
      if {[catch {ans_registry keys "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Print\\Printers"} printerList]} {
         set noPrinters 1
      } else {
         if { [string match {} $printerList] } {
            set noPrinters 1
         } else {
            foreach printer $printerList {
               if { [catch {ans_registry get "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Print\\Printers\\$printer" Name} printerData(name,${printer})]} {
                  #
                  unset printerData(name,${printer})
                  continue
               }

               set pn $printerData(name,$printer)
               set printerData(printer,$pn) $printer
               if { [catch {ans_registry get "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Print\\Printers\\$printer" {Printer Driver}} printerData(driver,${printer})] } {
                  unset printerData(name,${printer})
                  unset printerData(driver,${printer})
                  continue
               }

               #set printerData(driver,$printer) \
               #      [lindex [split $drvp ,] 0]
               #set printerData(port,$printer) \
               #      [lindex [split $drvp ,] 1]

               # Get the port name
               if { [catch {ans_registry get "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Print\\Printers\\$printer" {Port}} printerData(port,${printer})] } {
                  unset printerData(name,${printer})
                  unset printerData(driver,${printer})
                  unset printerData(port,${printer})
                  continue
               }

               # Determine if this is a postscript enabled printer.
               if { [catch { ans_registry type  "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Print\\Printers\\$printer\\PrinterDriverData" FreeMem } printerData(psType,$printer)] } {
                  set printerData(psType,$printer) none
               }
               set printerData(lpr,${printer}) 0
               #set printerData(lpr,$printer) 0
               $printChild.cmbPrinter insert list end \
                    [list $printerData(name,${printer}) $printer]
               set noPrinters 0
            }
         }
      }

      # Check for other printers
      if { ![catch {ans_registry keys "HKEY_CURRENT_USER\\Printers\\Connections"} connectionsKeys] } {

         # Loop over the connection keys finding the server name
         foreach connection $connectionsKeys {
            if { [catch { ans_registry get "HKEY_CURRENT_USER\\Printers\\Connections\\$connection" Server} servers($connection) ] } {
               unset servers($connection)
               continue
            }
            set servers($connection) \
                  [string trimleft $servers($connection) "\\"]
         }
   
         foreach printer [array names servers] {
            regsub -all {,} $printer {\\} printerName
            set printerData(name,$printer) $printerName
            set printerData(printer,$printerName) $printer
            set printerData(lpr,$printer) 0
            set printerData(psType,$printer) binary

            set server $servers($printer)

            if { [catch {ans_registry keys "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Providers\\LanMan Print Services\\Servers\\$server\\Printers" } serverPrinterKeys] } {
               # The above path failed. This may be a windows NT system.
               if { [catch {ans_registry keys "HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Print\\Providers\\LanMan Print Services\\Servers\\$server\\Printers" } serverPrinterKeys] } {
                  array unset printerData *,$printer
                  continue
               }
            }
            foreach printerName $serverPrinterKeys {
               if { [string match {} $printerName] } {
                  continue
               }
               if { [catch {ans_registry get "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Providers\\LanMan Print Services\\Servers\\$server\\Printers\\$printerName" {Printer Driver}} printerData(driver,$printer)] } {
                  # The above path failed. This may be a windows NT system.
                  if { [catch {ans_registry get "HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Print\\Providers\\LanMan Print Services\\Servers\\$server\\Printers\\$printerName" {Printer Driver}} printerData(driver,$printer)] } {
                     array unset printerData *,$printer
                     continue
                  }
               }
               if { [catch {ans_registry get "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Providers\\LanMan Print Services\\Servers\\$server\\Printers\\$printerName" Port} printerData(port,$printer)] } {
                  # The above path failed. This may be a windows NT system.
                  if { [catch {ans_registry get "HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Print\\Providers\\LanMan Print Services\\Servers\\$server\\Printers\\$printerName" Port} printerData(port,$printer)] } {
                     array unset printerData *,$printer
                     continue
                  }
               }
            }
            $printChild.cmbPrinter insert list end \
                  [list $printerData(name,${printer}) $printer]
            set noPrinters 0
         }
      }

      #set pn [lindex [split [ans_registry get "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows" Device] ,] 0]
      # Look for default printer
      if { [string match "Windows NT" $tcl_platform(os)] } {
         # This is a Windows NT operating system.
         if { [catch {ans_registry get "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows" Device} pn] } {
            set noPrinters 1
         } else {
            set pn [lindex [split $pn ,] 0]
            set printerName $printerData(printer,$pn)
            set noPrinters 0
         }
      } else {
         if { [catch {ans_registry get "HKEY_CURRENT_CONFIG\\System\\CurrentControlSet\\Control\\Print\\Printers" Default} pn] } {
            set noPrinters 1
         } else {
            #set pn [lindex [split $pn ,] 0]
            if { ![string match {} $pn] } {
               set printerName $printerData(printer,$pn)
               set noPrinters 0
            }
         }
      }

      # If installed as an lpr printer we can use postscript
      if {[catch {ans_registry keys "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Print\\Monitors\\LPR Port\\Ports"} printerList]} {
          #
      } else {
         if { ![string match {} $printerList] } {
            foreach printer $printerList {
               set name \
                     [ans_registry get "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Print\\Monitors\\LPR Port\\Ports\\$printer" {Printer Name}]
               set server \
                     [ans_registry get "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Print\\Monitors\\LPR Port\\Ports\\$printer" {Server Name}]
               #set printerData(lpr,\\\\${server}\\${name}) 1
               set lc1 [string tolower "\\\\${server}\\${name}"]
               regsub -all {\\} $lc1 {,} lc1
               foreach {index p} [array get printerData printer,*] {
                  set lc2 [string tolower $printerData(name,$p)]
                  regsub -all {\\} $lc2 {,} lc2
                  if { [string match $lc1 $lc2] } {
                     set printerData(lpr,$p) 1
                     set printerData(lprName,$p) $name
                     set printerData(lprServer,$p) $server
                  }
               }

               #set printerData(lpr,${printer}) 1
               #if {![catch {set pn $printerData(printer,${printer}) } err]} {
               #   set printerData(lprName,$pn) $name
               #   set printerData(lprServer,$pn) $server
               #}
            }
         }
      }
   }
   if { $noPrinters } {
      $printChild.cmbPrinter insert list end \
         [list [msgcat::mc "None Installed"] -999]
      set printerName -999
   }
   return $noPrinters
}

proc updatePrinterInfo { } {
   variable printChild
   variable printerData
   variable printerName
   variable printPS
   variable orientChild

   #set pn $printerData(name,$printerName)
   if { $printerData(lpr,$printerName) }  {
      if { [string match $printerData(psType,${printerName}) binary]} {
         $printChild.lblPrinterQuality configure -state disabled
         $printChild.cmbPrinterQuality configure -state disabled
         $orientChild.rdbLandscape configure -state disabled
         $orientChild.rdbPortrait configure -state disabled
         set printPS 0
      } else {
         $printChild.lblPrinterQuality configure -state normal
         $printChild.cmbPrinterQuality configure -state normal
         $orientChild.rdbLandscape configure -state normal
         $orientChild.rdbPortrait configure -state normal
         set printPS 1
      }
   } else {
      $printChild.lblPrinterQuality configure -state disabled
      $printChild.cmbPrinterQuality configure -state disabled
      $orientChild.rdbLandscape configure -state normal
      $orientChild.rdbPortrait configure -state normal
      set printPS 0
   }
}

proc captureImage_ok { parent child } {
   global tcl_platform
   variable printerAppearance;   variable printerQuality
   variable printerOrient;       variable print2File;   variable printerName
   variable printCopies;         variable printerData;   variable printPS

   #
   $parent deactivate 1

   if {$print2File == 1} {
      captureImage_2File
      return
   } elseif {$print2File == 2} {
      ans_sendcommand )/IMAGE,CAPT
      return
   } elseif {!$printPS} {
      switch -- $printerOrient {
         90 { # landscape
            ans_hardcopy $printerData(name,$printerName) \
                  $printerData(driver,$printerName) \
                  $printerData(port,$printerName) \
                  $printCopies 2
         }
         0 { # portrait
            ans_hardcopy $printerData(name,$printerName) \
                  $printerData(driver,$printerName) \
                  $printerData(port,$printerName) \
                  $printCopies 1
         }
      }
   } else {
      for {set i 0} {$i <= 4} {incr i} {
         lappend jobname [ans_getvalue ACTIVE,,JOBNAM,,START,[expr $i * 9]]
      }
      set jobname [string trim [join $jobname {}]]
      apdl::noprint 1

      set printer $printerName

      switch -- $printerOrient {
         90 { # landscape
            set UIORIENT LANDSCAPE
         }
         0 { # portrait
            set UIORIENT PORTRAIT
         }
      }
      # Because of a bug in Ansys we must do a double plot for greyscale
      if {$printerAppearance == 3} {
         catch {ans_sendcommand )/SHOW,PSCR} err
         catch {ans_sendcommand )PSCR,COLOR,$printerAppearance} err
         #catch {ans_sendcommand )PSCR,ROTATE,$printerOrient} err
         catch {ans_sendcommand )PSCR,PAPER,,$UIORIENT} err
         catch {ans_sendcommand )/REPLOT} err
         catch {ans_sendcommand )/SHOW,scratch} err
         catch {ans_sendcommand )/REPLOT} err
         catch {ans_sendcommand )/SHOW,CLOSE} err
         catch {ans_sendcommand )/SHOW,TERM} err
         set printFile [lindex [lsort [glob ${jobname}*.eps]] end]
         file delete -force $printFile
      }
      catch {ans_sendcommand )/GFILE,$printerQuality} err
      catch {ans_sendcommand )/SHOW,PSCR} err
      catch {ans_sendcommand )PSCR,COLOR,$printerAppearance} err
      #catch {ans_sendcommand )PSCR,ROTATE,$printerOrient} err
      catch {ans_sendcommand )PSCR,PAPER,,$UIORIENT} err
      catch {ans_sendcommand )/REPLOT} err
      catch {ans_sendcommand )/SHOW,scratch} err
      catch {ans_sendcommand )/REPLOT} err
      catch {ans_sendcommand )/SHOW,CLOSE} err
      catch {ans_sendcommand )/SHOW,TERM} err
      catch {ans_sendcommand )/GFILE} err

      set printFile [lindex [lsort [glob ${jobname}*.eps]] end]

      if [string match windows $tcl_platform(platform)] {
         for {set i 1} {$i <= $printCopies} {incr i} {
            catch {exec cmd.exe /c lpr -S $printerData(lprServer,$printerName) -P $printerData(lprName,$printerName) -ol $printFile}
            # We may have to wait for the network
            after 1000
         }
      } else {
         catch {exec lp -c -d$printer -n$printCopies $printFile}
      }
      file delete -force $printFile
      file delete -force scratch
      apdl::noprint 0
   }
}


proc captureImage_2File {  } {
   global tcl_platform tk_strictMotif
   variable printMasterWin;variable printerQuality;variable printerAppearance
   variable printerOrient

   if [string match windows $tcl_platform(platform)] {
         set types {
              { {PNG Portable Network Graphics Format} {.png} }
              { {Encapsulate Postscript} {.eps} }
              { {JPEG File Interchange Format} {.jpg} }
              { {Virtual Reality Meta Language} {.wrl} }
              { {TIF Tagged Image File Format} {.tif} }
              { {EPSI Encapsulated Postscript with TIFF preview} {.epsi} }
              { {Windows Bitmaps} {.bmp} }
              { {Windows Metafile} {.wmf} }
              { {Windows Enhanced Metafile} {.emf} }
         }
   } else {
         set types {
              { {PNG Portable Network Graphics Format} {.png} }
              { {Encapsulate Postscript} {.eps} }
              { {JPEG File Interchange Format} {.jpg} }
              { {Virtual Reality Meta Language} {.wrl} }
              { {TIF Tagged Image File Format} {.tif} }
              { {EPSI Encapsulated Postscript with TIFF preview} {.epsi} }
         }
   }


   # create a dummy window to get resource
   for {set i 0} {$i <= 4} {incr i} {
      lappend jobname [ans_getvalue ACTIVE,,JOBNAM,,START,[expr $i * 9]]
   }
   set jobname [string trim [join $jobname {}]]

   set newfilename ""
   set tk_strictMotif 0
   update

   set newfilename [euidl::getSaveFile -filetypes $types \
         -title [msgcat::mc "Save image to file"] \
         -parent $printMasterWin \
         -initialfile $jobname -initialdir [pwd] \
         -defaultextension .png]
   set tk_strictMotif 1


   if [string match "" $newfilename] {
   } else {
      set filename $newfilename
      set fileDir [file dir $filename]
      set fileRoot [file root [file tail $filename]]
      set preFileExt [file ext $filename]
      regexp {\.(.*)} $preFileExt match fileExt
      if ![info exists fileExt] {
         # We should always have some type of extension
      }
      switch -- $printerAppearance {
         0 { # monochrome
            set UICOLOR MONO
         }
         3 { # grey scale
            set UICOLOR GREY
         }
         2 { # color
            set UICOLOR COLOR
         }
      }
      switch -- $printerOrient {
         90 { # landscape
            set UIORIENT LANDSCAPE
         }
         0 { # portrait
            set UIORIENT PORTRAIT
         }
      }
      set fileExtAlt $fileExt
      ::apdl::noprint 1
      catch {ans_sendcommand )/DEV,PSFN,NINC} err
      ::apdl::noprint 0
      set graphicFile ${jobname}.$fileExtAlt
      set fexists 0
      if { [file exists $graphicFile] } {
         set fexists 1
         file rename $graphicFile __$graphicFile
      }
      switch -- $fileExt {
         eps {
               # Because of bug in Ansys we must do a double plot for greyscale
               if {$printerAppearance == 3} {
                  catch {ans_sendcommand )/SHOW,PSCR} err
                  catch {ans_sendcommand )PSCR,COLOR,$printerAppearance} err
                  catch {ans_sendcommand )PSCR,ROTATE,$printerOrient} err
                  catch {ans_sendcommand )/REPLOT} err
                  catch {ans_sendcommand )/SHOW,scratch} err
                  catch {ans_sendcommand )/REPLOT} err
                  catch {ans_sendcommand )/SHOW,PSCR} err
                  catch {ans_sendcommand )/SHOW,TERM} err
                  set printFile [lindex [lsort [glob ${jobname}*.eps]] end]
                  file delete -force $printFile
               }
               catch {ans_sendcommand /GFILE,$printerQuality} err
               catch {ans_sendcommand /SHOW,PSCR} err
               catch {ans_sendcommand PSCR,COLOR,$printerAppearance} err
               catch {ans_sendcommand PSCR,ROTATE,$printerOrient} err
               catch {ans_sendcommand /REPLOT} err
               catch {ans_sendcommand /SHOW,scratch} err
               catch {ans_sendcommand /REPLOT} err
               catch {ans_sendcommand /SHOW,PSCR} err
               catch {ans_sendcommand /SHOW,TERM} err
               catch {ans_sendcommand /GFILE} err
               file delete -force scratch

         }
         jpg {
               catch {ans_sendcommand \
                     /UI,COPY,SAVE,JPEG,GRAPH,$UICOLOR,NORM,$UIORIENT,,100} err
         }
         png {
               catch {ans_sendcommand \
                     /UI,COPY,SAVE,PNG,GRAPH,$UICOLOR,NORM,$UIORIENT,YES} err
         }
         wrl {
               catch {ans_sendcommand /GFILE,$printerQuality} err
               catch {ans_sendcommand /SHOW,VRML} err
               catch {ans_sendcommand /REPLOT} err
               catch {ans_sendcommand /SHOW,scratch} err
               catch {ans_sendcommand /REPLOT} err
               catch {ans_sendcommand /SHOW,PSCR} err
               catch {ans_sendcommand /SHOW,TERM} err
               catch {ans_sendcommand /GFILE} err
               file delete -force scratch
         }
         tif {
               catch {ans_sendcommand \
                     /UI,COPY,SAVE,TIFF,GRAPH,$UICOLOR,NORM,$UIORIENT,YES} err
         }
         epsi {
               catch {ans_sendcommand \
                     /UI,COPY,SAVE,EPSI,GRAPH,$UICOLOR,NORM,$UIORIENT,YES} err
               set fileExtAlt eps
         }
         bmp {
               catch {ans_sendcommand \
                     /UI,COPY,SAVE,BMP,GRAPH,$UICOLOR,NORM,$UIORIENT} err
         }
         wmf {
               catch {ans_sendcommand \
                     /UI,COPY,SAVE,WMF,GRAPH,$UICOLOR,NORM,$UIORIENT} err
         }
         emf {
               catch {ans_sendcommand \
                     /UI,COPY,SAVE,EMF,GRAPH,$UICOLOR,NORM,$UIORIENT} err
         }
      }

      ::apdl::noprint 1
      catch {ans_sendcommand )/DEV,PSFN} err
      ::apdl::noprint 0
#      set graphicFile [lindex [glob ${jobname}*.$fileExtAlt] end]
#      set graphicFile ${jobname}.$fileExtAlt
      if [catch \
            {file copy -force $graphicFile [file join $fileDir $fileRoot.$fileExt]} \
               err] {
         # the files are the same name so we don't delete
         if { $fexists } {
            file delete -force __$graphicFile
         }
      } else {
         file delete $graphicFile
         if { $fexists } {
            file rename __$graphicFile $graphicFile
         }
      }
   }

}

proc printPSSet { {setPS chk } } {
   global tcl_platform
   variable printPS
   if {[string match chk $setPS]} {
      if [string match unix $tcl_platform(platform)] {
         set printPS 1
      } else {
         if {[catch {set printerList [ans_registry keys "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Print\\Monitors\\LPR Port\\Ports"]} err]} {
            set printPS 0
         } else {
            set printPS 1
         }
      }
   } else {
      set printPS $setPS
   }
}

}
# End of capture image dialog

proc graphicOnOff { action } {
   variable onoffArray
   switch -- $action {
      erase {
         if {$onoffArray(erase)} {
            ans_sendcommand /ERASE
         } else {
            ans_sendcommand /NOERASE
         }
      }
      showwp {
         if {$onoffArray(showwp)} {
            ans_sendcommand WPSTYLE,,,,,,,,1
         } else {
            ans_sendcommand WPSTYLE,,,,,,,,0
         }
      }
      legend {
         if {$onoffArray(legend)} {
            # If legend is on then use user controled
            ans_sendcommand /PLOPTS,INFO,3
         } else {
            ans_sendcommand /PLOPTS,INFO,0
         }
      }
      vectCont {
         if {$onoffArray(vectCont)} {
            # If legend is on then use user controled
            ans_sendcommand /PLOPTS,INFO,3
         } else {
            ans_sendcommand /PLOPTS,INFO,0
         }
      }
      anno {
         if {$onoffArray(anno)} {
            # Turn annotation on both 2D and 3D
            ans_sendcommand /ANNO,ON
         } else {
            ans_sendcommand /ANNO,OFF
         }
      }
   }
}

proc graphicsOnOffInitialize { } {
   variable onoffArray

   set onoffArray(anno) 1
   # For now only support a cutting plane on the working plane
   catch {ans_sendcommand /CPLANE,1} err
}

proc annotation { type } {
   variable onoffArray

   set pgrFileActive 0
   if {[ans_getvalue active,,rout] == 31} {
      set pgrFileActive [ans_getvalue RSET,,PGR]
   }
   switch -- $type {
      3D {
         if {[winfo exists .postViewer]} {
            set parentWin .postViewer
         } else {
            set parentWin .
         }
         if {$pgrFileActive} {
            euidl::messageBox \
               -message [msgcat::mc "When working with a PGR file the only \
                     valid location is \"On View\"."] \
               -type ok \
               -icon info \
               -title [msgcat::mc "PGR Dynamic Annotation"] \
               -parent $parentWin
         }
         catch {ans_sendcommand )/UI,AN3D} err
      }
      default {
         catch {ans_sendcommand )/UI,ANNO} err
      }
   }


}

# SHOW Settings
namespace eval deviceSettings {
   variable ColorUsage

   proc  colorUsage { use {replot 1} } {
      variable ColorUsage

      if { [string match $ColorUsage(default) 3D] } {
         # 3D devices can not switch and is not needed.
         return
      }
      switch -regexp -- $use {
         shading {
            if {[string match $ColorUsage(type) X11]} {
               catch {ans_sendcommand /SHOW,X11} err
            } else {
               catch {ans_sendcommand /SHOW,WIN32} err
            }
         }
         contour[s]? {
            if {[string match $ColorUsage(type) X11]} {
               catch {ans_sendcommand /SHOW,X11C} err
            } else {
               catch {ans_sendcommand /SHOW,WIN32C} err
            }
         }
         default {
            if {[string match $ColorUsage(default) contour]} {
               if {[string match $ColorUsage(type) X11]} {
                  catch {ans_sendcommand /SHOW,X11C} err
               } else {
                  catch {ans_sendcommand /SHOW,WIN32C} err
               }
            } else {
               if {[string match $ColorUsage(type) X11]} {
                  catch {ans_sendcommand /SHOW,X11} err
               } else {
                  catch {ans_sendcommand /SHOW,WIN32} err
               }
            }
         }
      }
      if {$replot} {
         catch {ans_sendcommand )/REPLOT} err
      }
   }

   proc  colorUsageDefault { } {
      variable ColorUsage

      if { [ans_getvalue ACTIVE,,KEYWORD,,X3D] } {
         set ColorUsage(default) 3D
         set ColorUsage(type) 3D
      } elseif { [ans_getvalue ACTIVE,,KEYWORD,,X11] } {
         set ColorUsage(default) shading
         set ColorUsage(type) X11
      } elseif { [ans_getvalue ACTIVE,,KEYWORD,,X11C] } {
         set ColorUsage(default) contour
         set ColorUsage(type) X11
      } elseif { [ans_getvalue ACTIVE,,KEYWORD,,WIN32] } {
         set ColorUsage(default) shading
         set ColorUsage(type) WIN32
      } elseif { [ans_getvalue ACTIVE,,KEYWORD,,WIN32C] } {
         set ColorUsage(default) contour
         set ColorUsage(type) WIN32
      } else {
         set ColorUsage(default) shading
         set ColorUsage(type) unknown
      }
   }

}; # End of device settings

namespace eval colorSettings {

   proc getColorData { type } {
      switch -- $type {
         cntr {
         }
         index -
         default {
            set colorInfo [list]
            for {set i 0} {$i < 16} {incr i} {
               foreach {c j} [list r 1 g 2 b 3] {
                  set loc [expr 3*$i+$j]
                  set $c [ans_getvalue common,,d2mpcm,,int,$loc]
               }
               lappend colorInfo [list $r $g $b]
            }
         }
      }
      return $colorInfo
   }

   proc setColorData { } {
      switch -- $type {
         index {
         }
         cntr {
         }
      }
   }
}; # End of colorSettings


}; # End of the graphics namespace

# We will set printPS on the sourcing of the file
euidl::graphics::captureImage::printPSSet chk
# We will set device defaults on the sourcing of the file
euidl::graphics::deviceSettings::colorUsageDefault

namespace eval euidl::windows {

   variable onoffArray
   variable setArray

proc windowOnOff { action win } {
   variable onoffArray
   variable setArray

   set action [string tolower $action]
   switch -- $action {
      date {
         if {$onoffArray($win,date)} {
            ans_sendcommand /UDOC,$win,DATE,1
         } else {
            ans_sendcommand /UDOC,$win,DATE,0
         }
      }
      gwin {
         if {$onoffArray($win,gwin)} {
            ans_sendcommand /UDOC,$win,GWIN,1
         } else {
            ans_sendcommand /UDOC,$win,GWIN,0
         }
      }
      type {
         if {$onoffArray($win,type)} {
            ans_sendcommand /UDOC,$win,TYPE,1
         } else {
            ans_sendcommand /UDOC,$win,TYPE,0
         }
      }
      typ2 {
         if {$onoffArray($win,typ2)} {
            ans_sendcommand /UDOC,$win,TYP2,1
         } else {
            ans_sendcommand /UDOC,$win,TYP2,0
         }
      }
      inum {
         if {$onoffArray($win,inum)} {
            ans_sendcommand /UDOC,$win,INUM,1
         } else {
            ans_sendcommand /UDOC,$win,INUM,0
         }
      }
      bcdc {
         if {$onoffArray($win,bcdc)} {
            ans_sendcommand /UDOC,$win,BCDC,1
         } else {
            ans_sendcommand /UDOC,$win,BCDC,0
         }
      }
      vect {
         if {$onoffArray($win,vect)} {
            ans_sendcommand /UDOC,$win,VECT,1
         } else {
            ans_sendcommand /UDOC,$win,VECT,0
         }
      }
      surf {
         if {$onoffArray($win,surf)} {
            ans_sendcommand /UDOC,$win,SURF,1
         } else {
            ans_sendcommand /UDOC,$win,SURF,0
         }
      }
      body {
         if {$onoffArray($win,body)} {
            ans_sendcommand /UDOC,$win,BODY,1
         } else {
            ans_sendcommand /UDOC,$win,BODY,0
         }
      }
      psta {
         if {$onoffArray($win,psta)} {
            ans_sendcommand /UDOC,$win,PSTA,1
         } else {
            ans_sendcommand /UDOC,$win,PSTA,0
         }
      }
      view {
         if {$onoffArray($win,view)} {
            ans_sendcommand /UDOC,$win,VIEW,1
         } else {
            ans_sendcommand /UDOC,$win,VIEW,0
         }
      }
      misc {
         if {$onoffArray($win,misc)} {
            ans_sendcommand /UDOC,$win,MISC,1
         } else {
            ans_sendcommand /UDOC,$win,MISC,0
         }
      }
      cntr {
         if {![string match $onoffArray($win,cntr) 0]} {
            ans_sendcommand /UDOC,$win,CNTR,$setArray($win,CNTR,pos)
         } else {
            ans_sendcommand /UDOC,$win,CNTR,0
         }
      }
   }
}; #end of windowOnOff

proc windowSet { action win } {
   variable onoffArray
   variable setArray

   set action [string tolower $action]
   switch -- $action {
      cntr {
         ans_sendcommand /UDOC,$win,CNTR,$setArray($win,CNTR,pos)
      }
   }
}

proc windowMultiLegendQuery { winNum item {getPos 0} } {

   set item [string tolower $item]

   set itemList [list cntr date gwin type typ2 inum \
         bcdc vect surf body psta view misc]
   set cmPos [lsearch $itemList $item]

   set cmVal [ans_getvalue common,,udoccm,,int,[expr $cmPos * 5 + $winNum]]

   if {$getPos} {
      switch -- $cmVal {
         0 {
            set rtnVal OFF
         }
         1 {
            set rtnVal LEFT
         }
         2 {
            set rtnVal RIGHT
         }
         3 {
            set rtnVal TOP
         }
         4 {
            set rtnVal BOTTOM
         }
         default {
            set rtnVal OFF
         }
      }
   } else {
      set rtnVal [expr $cmVal ? 1 : 0]
   }
   return $rtnVal

}

proc windowOnOffInitialize { } {
   variable onoffArray

   set itemList [list cntr date gwin type typ2 inum \
         bcdc vect surf body psta view misc]

   foreach item $itemList {
      for {set winNum 1} {$winNum <= 5} {incr winNum} {
         set onoffArray($winNum,$item) \
               [windowMultiLegendQuery $winNum $item]
      }
   }
}

proc windowSetInitialize { } {
   variable setArray

   set itemList [list CNTR DATE GWIN TYPE TYP2 INUM \
         BCDC VECT SURF BODY PSTA VIEW MISC]

   foreach item $itemList {
      for {set winNum 1} {$winNum <= 5} {incr winNum} {
         set itemPos [windowMultiLegendQuery $winNum $item 1]
         if {[string match OFF $itemPos]} {
            # The setArray doesn't understand OFF so set it to the LEFT
            set setArray($winNum,$item,pos) LEFT
         } else {
            set setArray($winNum,$item,pos) $itemPos
         }
      }
   }
}

# User Docu Legend
namespace eval udocu {
      variable vA
      set vA(cmdName,Fld#,in/out) -999

      # /UDOC command
      proc create { win } {
         variable vA
         variable parent
         variable winNum
         variable udocClass

         set winNum $win
         initializeData

         if {[winfo exists .dlg_S_UDOC]} {
            $parent activate
            return
         }

         set parent [euidl::dialog .dlg_S_UDOC \
               -class EUIDL]
         set childsite [$parent component childsite]

         grid columnconfigure $childsite 0 -weight 1

         wm title $parent [::msgcat::mc "Legend Settings"]

         set i 0
         set udocClass [list \
                  TYPE  "Plot type" \
                  DATE  "Date" \
                  TYP2  "Plot information" \
                  INUM  "Numbering type" \
                  BCDC  "Boundary conditions" \
                  SURF  "Surface loads" \
                  BODY  "Body loads" \
                  VECT  "Vector result information" \
                  GWIN  "Multiple window" \
                  VIEW  "View information" \
                  PSTA  "Stress scale" \
                  MISC  "Miscellaneous" \
               ]

         foreach {class classString} $udocClass {
            euidl::checkbutton $childsite.chkClass$i \
               -variable [scope vA($class,visible)] \
               -text [::msgcat::mc $classString] \
               -command [list [namespace code S_UDOC_exec] $class]
            euidl::radiobutton $childsite.rbLeft$i \
               -variable ::euidl::windows::setArray($winNum,$class,pos) \
               -value LEFT \
               -text [msgcat::mc "left"] \
               -command [list [namespace code S_UDOC_exec] $class]
            euidl::radiobutton $childsite.rbRight$i \
               -variable ::euidl::windows::setArray($winNum,$class,pos) \
               -value RIGHT \
               -text [msgcat::mc "right"] \
               -command [list [namespace code S_UDOC_exec] $class]

            grid $childsite.chkClass$i -row $i -column 0 -sticky w
#            grid $childsite.rbOff$i -row $i -column 1 -sticky w
            grid $childsite.rbLeft$i -row $i -column 2 -sticky w -padx 2
            grid $childsite.rbRight$i -row $i -column 3 -sticky w -padx 2
            incr i
         }

         $parent configure \
               -okcommand [namespace code S_UDOC_Ok] \
               -oktext [::msgcat::mc "Close"] \
               -canceltext [::msgcat::mc "Replot"] \
               -cancelcommand [list ans_sendcommand )/REPLOT] \
               -helpcommand [list ans_loadhelp Hlp_C_UDOC_sl]
         $parent activate

      }
      proc S_UDOC_Ok { args } {
         variable parent
         variable vA
         variable pgrFileActive
         variable udocClass
         variable winNum

         foreach {class classString} $udocClass {
            set lcClass [string tolower $class]
            if {$vA($class,visible)} {
                  set euidl::windows::onoffArray($winNum,$lcClass) 1
                  ans_sendcommand /UDOC,$winNum,$class,$euidl::windows::setArray($winNum,$class,pos)
            } else {
                  ans_sendcommand /UDOC,$winNum,$class,OFF
                  set euidl::windows::onoffArray($winNum,$lcClass) 0
            }
         }
         $parent deactivate
         destroy $parent
      }

      proc S_UDOC_exec { class } {
         variable vA
         variable entityIDFrm
         variable pgrFileActive
         variable winNum

         ans_sendcommand )/NOPR
         if {$vA($class,visible)} {
               ans_sendcommand )/UDOC,$winNum,$class,$euidl::windows::setArray($winNum,$class,pos)
         } else {
               ans_sendcommand )/UDOC,$winNum,$class,OFF
         }
         ans_sendcommand )/GO
      }

      proc initializeData { } {
         variable vA
         variable winNum

         # Command execution may have modified the values
         ::euidl::windows::windowOnOffInitialize
         ::euidl::windows::windowSetInitialize

         set vA(TYPE,visible) $euidl::windows::onoffArray($winNum,type)
         set vA(DATE,visible) $euidl::windows::onoffArray($winNum,date)
         set vA(TYP2,visible) $euidl::windows::onoffArray($winNum,typ2)
         set vA(INUM,visible) $euidl::windows::onoffArray($winNum,inum)
         set vA(BCDC,visible) $euidl::windows::onoffArray($winNum,bcdc)
         set vA(SURF,visible) $euidl::windows::onoffArray($winNum,surf)
         set vA(BODY,visible) $euidl::windows::onoffArray($winNum,body)
         set vA(VECT,visible) $euidl::windows::onoffArray($winNum,vect)
         set vA(GWIN,visible) $euidl::windows::onoffArray($winNum,gwin)
         set vA(VIEW,visible) $euidl::windows::onoffArray($winNum,view)
         set vA(PSTA,visible) $euidl::windows::onoffArray($winNum,psta)
         set vA(MISC,visible) $euidl::windows::onoffArray($winNum,misc)
      }
}; # End of user docu legend settings

# Contour Settings
namespace eval contourSettings {
      variable vA
      set vA(cmdName,Fld#,in/out) -999

      set vA(CONTOUR,3,COLOR) 0

      # /CONTOUR command
      # /CVAL command
      # /CLABEL command
      # /CTYPE command
   proc create { win } {
      variable vA
      variable parent
      variable winNum

      set winNum $win

      if {[winfo exists .dlgContourProperties]} {
         initializeData
         $parent activate
         return
      }

      set parent [euidl::dialog .dlgContourProperties \
            -class EUIDL]
      set childsite [$parent component childsite]

      wm title $parent "Contour Legend Properties"

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

         set page [$tabParent add]
         $tabParent pageconfigure 0 \
               -label "Style"
         set page1 [frame $page.hold]
         pack $page1 -padx 10 -pady 10 -fill both -expand 1


         euidl::labeledframe $page1.lfCntrType \
            -text [msgcat::mc "Display Contours On"]

         set cntrChild [$page1.lfCntrType component childsite]

         euidl::radiobutton $cntrChild.rbCntr1 \
            -variable [scope vA(CTYPE,2)] \
            -value 0 \
            -text [msgcat::mc "Surfaces"]

         euidl::radiobutton $cntrChild.rbCntr2 \
            -variable [scope vA(CTYPE,2)] \
            -value 1 \
            -text [msgcat::mc "Isosurfaces (3D models only)"]

#         if {[ans_getfilter 0 X11C]} {
#            set maxColorCntr 128
#            set maxAlphaCntr 25
#         } else {
#            set maxColorCntr 9
#            set maxAlphaCntr 9
#         }
         set maxColorCntr 128
         set maxAlphaCntr 25

         grid $page1.lfCntrType -row 0 -column 0 -sticky new

         grid columnconfigure $cntrChild 1 -weight 1
         grid $cntrChild.rbCntr1 -row 0 -column 0 -sticky w
         grid $cntrChild.rbCntr2 -row 1 -column 0 -sticky w

         euidl::labeledframe $page1.lfLgndType \
            -text [msgcat::mc "Show Legend As"]

         set lgndChild [$page1.lfLgndType component childsite]

         euidl::radiobutton $lgndChild.rbColor \
            -variable [scope vA(TYPE)] \
            -value 0 \
            -text [msgcat::mc "Color bands"] \
            -anchor w

         euidl::label $lgndChild.lblcolor \
            -text [msgcat::mc "Number of contours:"]
         euidl::spinint $lgndChild.spncolor \
                  -range [list 1 $maxColorCntr] \
                  -variable [scope vA(CONTOUR,3,COLOR)] \
                  -width 4

         euidl::radiobutton $lgndChild.rbAlpha \
            -variable [scope vA(TYPE)] \
            -value 1 \
            -text [msgcat::mc "Vector lines"] \
            -anchor w
         euidl::label $lgndChild.lblAlpha \
            -text [msgcat::mc "Number of contours:"]
         euidl::spinint $lgndChild.spnAlpha \
                  -range [list 1 $maxAlphaCntr] \
                  -variable [scope vA(CONTOUR,3,ALPHA)] \
                  -width 4
         euidl::label $lgndChild.lblAlphaClabel \
            -text [msgcat::mc "label every Nth element:"]

         set maxElem [ans_getvalue elem,,num,max]
         if {$maxElem == 0} {
            set maxElem 100
         }
         euidl::spinint $lgndChild.spnAlphaClabel \
                  -range [list 1 $maxElem] \
                  -variable [scope vA(CLABEL,3)] \
                  -width 4

         grid $page1.lfLgndType -row 1 -column 0 -sticky new

         grid $lgndChild.rbColor -row 0 -column 0 -padx 0 -sticky w -columnspan 3
         grid $lgndChild.lblcolor -row 1 -column 1 -padx 0 -sticky w
         grid $lgndChild.spncolor -row 1 -column 2 -padx 5 -sticky w

         grid $lgndChild.rbAlpha -row 3 -column 0 -padx 0 -sticky w -columnspan 3
         grid $lgndChild.lblAlpha -row 4 -column 1 -padx 0 -sticky w
         grid $lgndChild.spnAlpha -row 4 -column 2 -padx 5 -sticky w
         grid $lgndChild.lblAlphaClabel -row 5 -column 1 -padx 0 -sticky w -pady 5
         grid $lgndChild.spnAlphaClabel -row 5 -column 2 -padx 5 -sticky w -pady 5

         grid columnconfigure $lgndChild 3 -weight 1
         grid columnconfigure $lgndChild 0 -minsize 25
         grid columnconfigure $lgndChild 1 -minsize 25

         grid columnconfigure $page1 2 -weight 1
         grid rowconfigure $page1 4 -weight 1

         # This are prob all *get
#         set vA(TYPE) 0
#         set vA(CTYPE,2) 0
#         set vA(CONTOUR,3,COLOR) $maxColorCntr
#         set vA(CONTOUR,3,ALPHA) $maxAlphaCntr
#         set vA(CONTOUR,3,ISO) $maxColorCntr
#         set vA(CLABEL,3) 1

         # contents

         set page [$tabParent add]
         $tabParent pageconfigure 1 \
               -label "Range"
         set page2 [frame $page.hold]
         pack $page2 -padx 10 -pady 10 -fill both -expand 1

      euidl::radiobutton $page2.rbUniform \
            -variable [scope vA(CVAL,TF)] \
            -value 0 \
            -text [msgcat::mc "Uniform contours"]

      euidl::labeledframe $page2.lfUniform \
            -text [msgcat::mc "Range of contours (VMIN VMAX)"]
      set crC [$page2.lfUniform component childsite]

      euidl::combobox $crC.cmbRng1 -style combobox \
            -variable [scope vA(CNTR,4)] \
            -width 18

      $crC.cmbRng1 insert list end \
            [list Automatic AUTO "Freeze last" USER]

#      set vA(CNTR,4) AUTO

#      euidl::combobox $crC.cmbRng2 -style combobox \
#            -variable [scope vA(CNTR,5)] \
#            -width 18
#      $crC.cmbRng2 insert list end \
#            [list "(vmax-vmin)/ncont" 1_euidl]

      euidl::entry $crC.entRng3 \
            -variable [scope vA(CNTR,6)] \
            -width 18

#      set vA(CNTR,4) {}
#      set vA(CNTR,5) {}
#      set vA(CNTR,6) {}

      grid columnconfigure $crC 4 -weight 1
      grid $crC.cmbRng1 -row 0 -column 0
#      grid $crC.cmbRng2 -row 0 -column 2 -padx 0
      grid $crC.entRng3 -row 0 -column 1 -padx 5


      euidl::radiobutton $page2.rbNonUniform \
            -variable [scope vA(CVAL,TF)] \
            -value 1 \
            -text [msgcat::mc "Non-uniform contours"]

      euidl::labeledframe $page2.lfNonUniform \
            -text [msgcat::mc "Values of contours (increasing left to right)"]
      set ncC [$page2.lfNonUniform component childsite]

      euidl::entry $ncC.entCval1 \
            -variable [scope vA(CVAL,2)] \
            -width 12
      euidl::entry $ncC.entCval2 \
            -variable [scope vA(CVAL,3)] \
            -width 12
      euidl::entry $ncC.entCval3 \
            -variable [scope vA(CVAL,4)] \
            -width 12
      euidl::entry $ncC.entCval4 \
            -variable [scope vA(CVAL,5)] \
            -width 12
      euidl::entry $ncC.entCval5 \
            -variable [scope vA(CVAL,6)] \
            -width 12
      euidl::entry $ncC.entCval6 \
            -variable [scope vA(CVAL,7)] \
            -width 12
      euidl::entry $ncC.entCval7 \
            -variable [scope vA(CVAL,8)] \
            -width 12
      euidl::entry $ncC.entCval8 \
            -variable [scope vA(CVAL,9)] \
            -width 12

      for {set id 1} {$id <= 9} {incr id} {
#         set vA(CVAL,$id) {}
      }

      euidl::label $ncC.lblCval1 \
            -text [msgcat::mc "Value 1"]
      euidl::label $ncC.lblCval2 \
            -text [msgcat::mc "Value 2"]
      euidl::label $ncC.lblCval3 \
            -text [msgcat::mc "Value 3"]
      euidl::label $ncC.lblCval4 \
            -text [msgcat::mc "Value 4"]
      euidl::label $ncC.lblCval5 \
            -text [msgcat::mc "Value 5"]
      euidl::label $ncC.lblCval6 \
            -text [msgcat::mc "Value 6"]
      euidl::label $ncC.lblCval7 \
            -text [msgcat::mc "Value 7"]
      euidl::label $ncC.lblCval8 \
            -text [msgcat::mc "Value 8"]

      grid columnconfigure $ncC 4 -weight 1
      grid $ncC.lblCval1 -row 0 -column 0 -padx 2 -pady 2
      grid $ncC.lblCval2 -row 0 -column 1 -padx 2 -pady 2
      grid $ncC.lblCval3 -row 0 -column 2 -padx 2 -pady 2
      grid $ncC.lblCval4 -row 0 -column 3 -padx 2 -pady 2
      grid $ncC.entCval1 -row 1 -column 0 -padx 2 -pady 2
      grid $ncC.entCval2 -row 1 -column 1 -padx 2 -pady 2
      grid $ncC.entCval3 -row 1 -column 2 -padx 2 -pady 2
      grid $ncC.entCval4 -row 1 -column 3 -padx 2 -pady 2

      grid $ncC.lblCval5 -row 2 -column 0 -padx 2 -pady 2
      grid $ncC.lblCval6 -row 2 -column 1 -padx 2 -pady 2
      grid $ncC.lblCval7 -row 2 -column 2 -padx 2 -pady 2
      grid $ncC.lblCval8 -row 2 -column 3 -padx 2 -pady 2
      grid $ncC.entCval5 -row 3 -column 0 -padx 2 -pady 2
      grid $ncC.entCval6 -row 3 -column 1 -padx 2 -pady 2
      grid $ncC.entCval7 -row 3 -column 2 -padx 2 -pady 2
      grid $ncC.entCval8 -row 3 -column 3 -padx 2 -pady 2

      grid $page2.rbUniform -row 0 -column 0 -sticky w
      grid $page2.lfUniform -row 1 -column 0 -sticky new

      grid $page2.rbNonUniform -row 2 -column 0 -sticky w
      grid $page2.lfNonUniform -row 3 -column 0 -sticky new

      grid columnconfigure $page2 2 -weight 1
      grid rowconfigure $page2 5 -weight 1

#      set vA(CVAL,TF) 0

      $tabParent configure -width 300 -height 200
     $tabParent select 0

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

      # Get the correct height of the widget
      set ndHeight [winfo reqheight [$tabParent component tabset]]
      set ndHpage1 [winfo reqheight $page1]
      if {$ndHeight < $ndHpage1} {set ndHeight $ndHpage1}
      set ndHpage2 [winfo reqheight $page2]
      if {$ndHeight < $ndHpage2} {set ndHeight $ndHpage2}

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


         $parent configure \
            -okcommand [namespace code contSet_Ok] \
            -cancelcommand [list destroy $parent] \
            -helpbutton 0
            # Custom widget help needs to be created

         initializeData
         $parent activate
   }

   proc contSet_Ok { } {
      variable parent
      variable vA
      variable winNum

      if {$vA(CVAL,TF)} {
         # Non-uniform contours
         if {$vA(TYPE)} {
            catch {ans_sendcommand /CLABEL,$winNum,$vA(CLABEL,3)} err
            set euidl::graphics::onoffArray(vector,contours) 1
            catch {ans_sendcommand /DEVICE,VECTOR,1} err
            # Vector mode switchs to a non-hidden which isn't supported
            # for pgr mode
            if {[ans_getvalue GRAPH,1,TYPE] == 0} {
               catch {ans_sendcommand /TYPE,ALL,6} err
            }
         } else {
            set euidl::graphics::onoffArray(vector,contours) 0
            catch {ans_sendcommand /DEVICE,VECTOR,0} err
         }
         catch {ans_sendcommand /CTYPE,$vA(CTYPE,2)} err
         catch {ans_sendcommand /CVAL,$winNum,$vA(CVAL,2),$vA(CVAL,3),$vA(CVAL,4),$vA(CVAL,5),$vA(CVAL,6),$vA(CVAL,7),$vA(CVAL,8),$vA(CVAL,9)} err
      } else {
         if {[string match $vA(CNTR,5) 1_euidl]} {
            set vA(CNTR,5) {}
         }
         # Uniform contours
         if {$vA(TYPE)} {
            if {$vA(CONTOUR,3,ALPHA) <= 9} {
               catch {ans_sendcommand /SHOW,X11} err
            }
            if {$vA(CONTOUR,3,ALPHA) <= 9 } {
               euidl::graphics::deviceSettings::colorUsage shading
            } else {
               euidl::graphics::deviceSettings::colorUsage contour
            }
            catch {ans_sendcommand /CLABEL,$winNum,$vA(CLABEL,3)} err
            catch {ans_sendcommand /CONTOUR,$winNum,$vA(CONTOUR,3,ALPHA),$vA(CNTR,4),$vA(CNTR,5),$vA(CNTR,6)} err
            set euidl::graphics::onoffArray(vector,contours) 1
            catch {ans_sendcommand /DEVICE,VECTOR,1} err
            # Vector mode switchs to a non-hidden which isn't supported
            # for pgr mode
            if {[ans_getvalue GRAPH,1,TYPE] == 0} {
               catch {ans_sendcommand /TYPE,ALL,6} err
            }
         } else {
            if {$vA(CONTOUR,3,COLOR) <= 9 } {
               euidl::graphics::deviceSettings::colorUsage shading
            } else {
               euidl::graphics::deviceSettings::colorUsage contour
            }
            catch {ans_sendcommand /CLABEL,$winNum,0} err
            catch {ans_sendcommand /CONTOUR,$winNum,$vA(CONTOUR,3,COLOR),$vA(CNTR,4),$vA(CNTR,5),$vA(CNTR,6)} err
            set euidl::graphics::onoffArray(vector,contours) 0
            catch {ans_sendcommand /DEVICE,VECTOR,0} err
         }
         catch {ans_sendcommand /CTYPE,$vA(CTYPE,2)} err
      }

      destroy $parent
   }

      proc initializeData { } {
         variable vA
         variable winNum

         if {[ans_getvalue common,,d3com,,int,83] == 0} {
            set vA(TYPE) 0
            set vA(CLABEL,3) 1
         } else {
            set vA(TYPE) 1
            set vA(CLABEL,3) [ans_getvalue common,,d3com,,int,83]
         }

         set vA(CTYPE,2) [ans_getvalue COMMON,,D3COM,,INT,70]

         set vA(CVAL,TF) [ans_getvalue common,,d3com,,int,179]

         switch -- $winNum {
            1 {
               set winOffSet 250; # this is for window 1
            }
            2 {
               set winOffSet 258; # this is for window 1
            }
            3 {
               set winOffSet 266; # this is for window 1
            }
            4 {
               set winOffSet 274; # this is for window 1
            }
            5 {
               set winOffSet 282; # this is for window 1
            }
         }

         if {$vA(CVAL,TF)} {
            set vA(CVAL,2) [ans_getvalue common,,d3com,,real,[incr winOffSet]]
            set vA(CVAL,3) [ans_getvalue common,,d3com,,real,[incr winOffSet]]
            set vA(CVAL,4) [ans_getvalue common,,d3com,,real,[incr winOffSet]]
            set vA(CVAL,5) [ans_getvalue common,,d3com,,real,[incr winOffSet]]
            set vA(CVAL,6) [ans_getvalue common,,d3com,,real,[incr winOffSet]]
            set vA(CVAL,7) [ans_getvalue common,,d3com,,real,[incr winOffSet]]
            set vA(CVAL,8) [ans_getvalue common,,d3com,,real,[incr winOffSet]]
            set vA(CVAL,9) [ans_getvalue common,,d3com,,real,[incr winOffSet]]
         } else {
            set vA(CVAL,2) {}
            set vA(CVAL,3) {}
            set vA(CVAL,4) {}
            set vA(CVAL,5) {}
            set vA(CVAL,6) {}
            set vA(CVAL,7) {}
            set vA(CVAL,8) {}
            set vA(CVAL,9) {}
         }

         if {$vA(CONTOUR,3,COLOR) == 0} {
            set vA(CONTOUR,3,COLOR) [ans_getvalue common,,d3com,,int,78]
         } else {
            if {$vA(TYPE) == 0} {
               set vA(CONTOUR,3,COLOR) [ans_getvalue common,,d3com,,int,78]
            }
         }
         set vA(CONTOUR,3,ALPHA) [ans_getvalue common,,d3com,,int,78]
         if {$vA(CONTOUR,3,ALPHA) > 25} {
            set vA(CONTOUR,3,ALPHA) 25
         }

         set vA(CNTR,4) AUTO
         set vA(CNTR,5) {}
         set vA(CNTR,6) {}

      }

}; # End of contour settings


# Display Settings
namespace eval displaySettings {
      variable vA
      set vA(cmdName,Fld#,in/out) -999

      # /TYPE command
      # /SHADE command
      # /LIGHT command
   proc create { win } {
      variable vA
      variable parent
      variable childsite
      variable winNum
      variable zbufFrame
      variable zbufChild
      variable dev3D

      set winNum $win

      if {[winfo exists .dlgDisplaySettings]} {
         initializeData
         $parent activate
         return
      }

      set parent [euidl::dialog .dlgDisplaySettings \
            -class EUIDL]
      set childsite [$parent component childsite]

      wm title $parent "Window Display Properties"

      set dev3D [ans_getvalue active,,keyw,,X3D]

         euidl::label $childsite.lblDisplayType \
            -text [::msgcat::mc "Display type"]
         euidl::combobox $childsite.cmbDisplayType \
            -variable [scope vA(S_TYPE,3)]

         $childsite.cmbDisplayType insert list end \
               [list "Hidden" 0 "Capped" 1 "Q-Slice" 2 "Non-hidden" 3]

         grid $childsite.lblDisplayType -column 0 -row 0 \
               -sticky w -padx 5 -pady 5
         grid $childsite.cmbDisplayType -column 1 -row 0 \
               -sticky w -pady 5

         euidl::checkbutton $childsite.chkDisplayZBuf \
            -variable [scope vA(S_TYPE,zbuf)] \
            -text [::msgcat::mc "Display model using software Z-buffering"] \
            -command [namespace code zbufChange]

         if {!$dev3D} {
            grid $childsite.chkDisplayZBuf -column 0 -row 1 \
               -columnspan 2 -sticky w -padx 5
         }


         set zbufFrame [euidl::labeledframe $childsite.lfZbuf]

         if {$dev3D} {
            $zbufFrame configure -text [msgcat::mc "Lighting options"]
         } else {
            $zbufFrame configure -text [msgcat::mc "Z-buffering options"]
         }

         set zbufChild [$childsite.lfZbuf component childsite]

         if {$dev3D} {
            grid $childsite.lfZbuf -column 0 -row 2 -columnspan 2
         } else {
            grid $childsite.lfZbuf -column 0 -row 2 -columnspan 2 -padx 20
         }

         if {!$dev3D} {

            euidl::label $zbufChild.lblShade \
                  -text [::msgcat::mc "Color shading uses"]
            euidl::combobox $zbufChild.cmbShade \
                  -variable [scope vA(S_SHADE,3)]
            $zbufChild.cmbShade insert list end \
               [list [msgcat::mc "No smoothing"] 0 "Gourand smoothing" 1 "Phong smoothing" 2]

            grid $zbufChild.lblShade -column 0 -row 0 -sticky w
            grid $zbufChild.cmbShade -column 1 -row 0 -columnspan 3 -sticky w
         }

         # The light for z-buf is along the view direction and if set to
         # the view direction seems to then follow it.

         euidl::checkbutton $zbufChild.chkLight \
            -variable [scope vA(S_LIGHT,3)] \
            -text [::msgcat::mc "Directional light source (otherwise ambient)"] \
            -command [namespace code lightChange]

         euidl::label $zbufChild.lblLightV \
            -text [::msgcat::mc "Vector tail coordinates"]
         euidl::label $zbufChild.lblLightX \
            -text [::msgcat::mc "XV"]
         euidl::label $zbufChild.lblLightY \
            -text [::msgcat::mc "YV"]
         euidl::label $zbufChild.lblLightZ \
            -text [::msgcat::mc "ZV"]

         euidl::entry $zbufChild.entLightX \
            -variable [scope vA(S_LIGHT,5)]
         euidl::entry $zbufChild.entLightY \
            -variable [scope vA(S_LIGHT,6)]
         euidl::entry $zbufChild.entLightZ \
            -variable [scope vA(S_LIGHT,7)]

         if {!$dev3D} {
            grid rowconfigure $zbufChild 2 -minsize 15
            grid $zbufChild.chkLight -column 0 -row 3 -columnspan 4 -sticky w
         }
         grid $zbufChild.lblLightX -column 1 -row 4 -columnspan 2
         grid $zbufChild.lblLightY -column 3 -row 4 -columnspan 2
         grid $zbufChild.lblLightZ -column 5 -row 4 -columnspan 2
         grid $zbufChild.lblLightV -column 0 -row 5 -sticky w
         grid $zbufChild.entLightX -column 1 -row 5 -padx 2 -columnspan 2
         grid $zbufChild.entLightY -column 3 -row 5 -padx 2 -columnspan 2
         grid $zbufChild.entLightZ -column 5 -row 5 -padx 2 -columnspan 2

         if {$dev3D} {
            euidl::label $zbufChild.lblAmbient \
                  -text [::msgcat::mc "Ambient Intensity"]
            euidl::label $zbufChild.lblAmbientD \
                  -text [::msgcat::mc "Darker"]
            euidl::scale $zbufChild.sclAmbient -from 0 -to 100 \
                  -tickinterval 10 \
                  -variable [scope vA(S_LIGHT,ambient,4)]
            euidl::label $zbufChild.lblAmbientB \
                  -text [::msgcat::mc "Brighter"]

            grid $zbufChild.lblAmbient -column 0 -row 7 -sticky w
            grid $zbufChild.lblAmbientD -column 1 -row 7 -sticky e
            grid $zbufChild.sclAmbient -column 2 -row 7 -sticky ew -columnspan 2
            grid $zbufChild.lblAmbientB -column 4 -row 7 -sticky w

         }

         if {$dev3D} {
            euidl::label $zbufChild.lblIntensity \
                  -text [::msgcat::mc "Directional Intensity"]
            euidl::label $zbufChild.lblIntensityD \
                  -text [::msgcat::mc "Darker"]
            euidl::scale $zbufChild.sclIntensity -from 0 -to 100 \
                  -tickinterval 10 \
                  -variable [scope vA(S_LIGHT,direct,4)]
            euidl::label $zbufChild.lblIntensityB \
                  -text [::msgcat::mc "Brighter"]

            grid $zbufChild.lblIntensity -column 0 -row 9 -sticky w
            grid $zbufChild.lblIntensityD -column 1 -row 9 -sticky e
            grid $zbufChild.sclIntensity -column 2 -row 9 -sticky ew -columnspan 2
            grid $zbufChild.lblIntensityB -column 4 -row 9 -sticky w

         }

         if {$dev3D} {
            euidl::label $zbufChild.lblReflectance \
                  -text [::msgcat::mc "Reflectance"]
            euidl::label $zbufChild.lblReflectanceL \
                  -text [::msgcat::mc "Less"]
            euidl::label $zbufChild.lblReflectanceM \
                  -text [::msgcat::mc "More"]
            euidl::scale $zbufChild.sclReflectance -from 101 -to 1 \
                  -tickinterval 10 \
                  -variable [scope vA(S_LIGHT,8)]

            grid $zbufChild.lblReflectance -column 0 -row 11 -sticky w
            grid $zbufChild.lblReflectanceL -column 1 -row 11 -sticky w
            grid $zbufChild.sclReflectance -column 2 -row 11 -sticky ew -columnspan 2
            grid $zbufChild.lblReflectanceM -column 4 -row 11 -sticky w

            grid columnconfigure $zbufChild 2 -weight 1
            grid rowconfigure $zbufChild 6 -minsize 10
            grid rowconfigure $zbufChild 8 -minsize 10
            grid rowconfigure $zbufChild 10 -minsize 10

         }

         grid columnconfigure $childsite 1 -weight 1

         $parent configure \
            -okcommand [namespace code dispSet_Ok] \
            -oktext [msgcat::mc "Close"] \
            -canceltext [msgcat::mc "Replot"] \
            -cancelcommand [namespace code dispSet_Replot] \
            -helpbutton 0
            # There needs to be custom help created.

         # The configure on the parent will set WM_DELTE_WINDOW to cancelcommand
         wm protocol $parent WM_DELETE_WINDOW [namespace code dispSet_Ok]

         initializeData

         $parent activate
   }

   proc dispSet_Ok { } {
      variable parent
      variable vA
      variable winNum
      variable dev3D

      # /TYPE
      if {$vA(S_TYPE,zbuf)} {
         # Z-Buffering
         if {$vA(S_TYPE,3) == 0} {
            set typeNum 6
         } elseif {$vA(S_TYPE,3) == 1} {
            set typeNum 7
         } elseif {$vA(S_TYPE,3) == 2} {
            set typeNum 8
         }
         catch {ans_sendcommand /TYPE,$winNum,$typeNum} err
         if {!$dev3D} {
            catch {ans_sendcommand /SHADE,$winNum,$vA(S_SHADE,3)} err
         }
         if {$dev3D} {
            set ambL [expr $vA(S_LIGHT,ambient,4)/100.0]
            set dirL [expr $vA(S_LIGHT,direct,4)/100.0]
            if {$vA(S_LIGHT,8) == 101} {
               set dirR 0
            } else {
               set dirR $vA(S_LIGHT,8)/100.0
            }
            set dirR [expr $vA(S_LIGHT,8)/100.0]
            catch {ans_sendcommand /LIGHT,$winNum,0,$ambL} err
            catch {ans_sendcommand /LIGHT,$winNum,1,$dirL \
               ,$vA(S_LIGHT,5),$vA(S_LIGHT,6),$vA(S_LIGHT,7),$dirR} err
         } else {
            if {$vA(S_LIGHT,3)} {
               catch {ans_sendcommand /LIGHT,$winNum,1 \
                     ,,$vA(S_LIGHT,5),$vA(S_LIGHT,6),$vA(S_LIGHT,7)} err
            } else {
               catch {ans_sendcommand )/LIGHT,$winNum,1,,0,0,0} err
            }
         }
      } else {
         # Non-Z-Buffering
         if {$vA(S_TYPE,3) == 0} {
            # Precise Hidden
            set typeNum 4
         } elseif {$vA(S_TYPE,3) == 1} {
            set typeNum 5
         } elseif {$vA(S_TYPE,3) == 2} {
            set typeNum 9
         } elseif {$vA(S_TYPE,3) == 3} {
            set typeNum 0
         }
         catch {ans_sendcommand /TYPE,$winNum,$typeNum} err
      }

      destroy $parent
   }


   proc dispSet_Replot { } {
      variable parent
      variable vA
      variable winNum
      variable dev3D

      # /TYPE
#      ans_sendcommand )/NOPR
      if {$vA(S_TYPE,zbuf)} {
         # Z-Buffering
         if {$vA(S_TYPE,3) == 0} {
            set typeNum 6
         } elseif {$vA(S_TYPE,3) == 1} {
            set typeNum 7
         } elseif {$vA(S_TYPE,3) == 2} {
            set typeNum 8
         }
         catch {ans_sendcommand )/TYPE,$winNum,$typeNum} err
         if {!$dev3D} {
            catch {ans_sendcommand )/SHADE,$winNum,$vA(S_SHADE,3)} err
         }
         if {$dev3D} {
            set ambL [expr $vA(S_LIGHT,ambient,4)/100.0]
            set dirL [expr $vA(S_LIGHT,direct,4)/100.0]
            if {$vA(S_LIGHT,8) == 101} {
               set dirR 0
            } else {
               set dirR $vA(S_LIGHT,8)/100.0
            }
            catch {ans_sendcommand )/LIGHT,$winNum,0,$ambL} err
            catch {ans_sendcommand )/LIGHT,$winNum,1,$dirL \
               ,$vA(S_LIGHT,5),$vA(S_LIGHT,6),$vA(S_LIGHT,7),$dirR} err
         } else {
            if {$vA(S_LIGHT,3)} {
               catch {ans_sendcommand )/LIGHT,$winNum,1 \
                     ,,$vA(S_LIGHT,5),$vA(S_LIGHT,6),$vA(S_LIGHT,7)} err
            } else {
               catch {ans_sendcommand )/LIGHT,$winNum,1,,0,0,0} err
            }
         }
      } else {
         # Non-Z-Buffering
         if {$vA(S_TYPE,3) == 0} {
            # Precise Hidden
            set typeNum 4
         } elseif {$vA(S_TYPE,3) == 1} {
            set typeNum 5
         } elseif {$vA(S_TYPE,3) == 2} {
            set typeNum 9
         } elseif {$vA(S_TYPE,3) == 3} {
            set typeNum 0
         }
         catch {ans_sendcommand )/TYPE,$winNum,$typeNum} err
      }

      catch {ans_sendcommand )/REPLOT} err
      ans_sendcommand )/GO
   }

      proc zbufChange {} {
         variable vA
         variable zbufFrame
         variable childsite

         update idletasks
         switch -- $vA(S_TYPE,zbuf) {
            0 {
               $zbufFrame configure -state disabled
               $childsite.cmbDisplayType delete list 0 end
               $childsite.cmbDisplayType insert list end \
                  [list "Hidden" 0 "Capped" 1 "Q-Slice" 2 "Non-hidden" 3]

            }
            1 {
               $zbufFrame configure -state normal
               $childsite.cmbDisplayType delete list 0 end
               $childsite.cmbDisplayType insert list end \
                  [list "Hidden" 0 "Capped" 1 "Q-Slice" 2]
               if {$vA(S_TYPE,3) == 3} {
                  set vA(S_TYPE,3) 0
               }
            }
         }

      }

      proc lightChange { } {
         variable vA
         variable zbufChild
         variable childsite
         variable dev3D

         switch -- $vA(S_LIGHT,3) {
            0 {
               $zbufChild.entLightX \
                  configure -state disabled
               $zbufChild.entLightY \
                  configure -state disabled
               $zbufChild.entLightZ \
                  configure -state disabled
               if {$dev3D} {
                  $zbufChild.sclIntensity \
                        configure -state disabled
                  $zbufChild.sclReflectance \
                        configure -state disabled
               }
            }
            1 {
               $zbufChild.entLightX \
                  configure -state normal
               $zbufChild.entLightY \
                  configure -state normal
               $zbufChild.entLightZ \
                  configure -state normal
               if {$dev3D} {
                  $zbufChild.sclIntensity \
                        configure -state normal
                  $zbufChild.sclReflectance \
                        configure -state normal
               }
            }
         }

      }

      proc initializeData { } {
         variable vA
         variable winNum
         variable dev3D

         # Graphic Device 2D or 3D
         set dev3D [ans_getvalue active,,keyw,,X3D]

         # Type
         switch -- [ans_getvalue GRAPH,$winNum,TYPE] {
            0 {
               # Non-hidden
               set vA(S_TYPE,3) 3
               set vA(S_TYPE,zbuf) 0
            }
            1 {
               # Section hidden is basically the same as a Q-slice
               # so force it to a Q-Slice
               set vA(S_TYPE,3) 2
               set vA(S_TYPE,zbuf) 0
            }
            2 -
            3 -
            4 {
               # Hidden no z-buffering, we are only supporting precise hidden
               set vA(S_TYPE,3) 0
               set vA(S_TYPE,zbuf) 0
            }
            5 {
               # Capped Hidden no z-buffering
               set vA(S_TYPE,3) 1
               set vA(S_TYPE,zbuf) 0
            }
            6 {
               # Hidden z-buffering
               set vA(S_TYPE,3) 0
               set vA(S_TYPE,zbuf) 1
            }
            7 {
               # Capped Hidden z-buffering
               set vA(S_TYPE,3) 1
               set vA(S_TYPE,zbuf) 1
            }
            8 {
               # Q-Slice z-buffering
               set vA(S_TYPE,3) 2
               set vA(S_TYPE,zbuf) 1
            }
            9 {
               # Q-Slice no z-buffering
               set vA(S_TYPE,3) 2
               set vA(S_TYPE,zbuf) 0
            }
         }
         # Shading
         set vA(S_SHADE,3) [ans_getvalue COMMON,,D3COM,,INT,121]
         # Ambient 0 - 1
         set ambL [ans_getvalue COMMON,,D3LCOM,,REAL,$winNum]
         set ambL [expr int($ambL*100)]
         set vA(S_LIGHT,ambient,4) $ambL
         # Directional 0 - 1
         set dirL [ans_getvalue COMMON,,D3LCOM,,REAL,[expr 3*($winNum-1)+66]]
         set dirL [expr int($dirL*100)]
         set vA(S_LIGHT,direct,4) $dirL
         # Reflectance
         set rflL [ans_getvalue COMMON,,D3LCOM,,REAL,[expr 3*($winNum-1)+51]]
         set rflL [expr int($dirL*100)]
         set vA(S_LIGHT,8) $rflL

         set vA(S_LIGHT,5) [ans_getvalue COMMON,,D3LCOM,,REAL,[expr 6+($winNum-1)*9]]
         set vA(S_LIGHT,6) [ans_getvalue COMMON,,D3LCOM,,REAL,[expr 7+($winNum-1)*9]]
         set vA(S_LIGHT,7) [ans_getvalue COMMON,,D3LCOM,,REAL,[expr 8+($winNum-1)*9]]
         if {$dev3D} {
            set vA(S_TYPE,zbuf) 1
         }

         zbufChange
         if {!$dev3D} {
            if {$vA(S_LIGHT,5) == 0 && $vA(S_LIGHT,6) == 0 \
                  && $vA(S_LIGHT,7) == 0} {
               set vA(S_LIGHT,3) 0
            } else {
               set vA(S_LIGHT,3) 1
            }
            lightChange
         }
      }

}; # End of display settings

# View Settings
namespace eval viewSettings {
   variable activeWin 1
   variable rateChg 30

   proc tlbInitialize { } {
      dynamicMode init
      fillWinNum
      fillRateChg
   }

   proc fillWinNum { } {
      variable rateChg
      if {![catch {::AnsysGUI::getToolbarWidgetPath ANS_VIEW Complete winnum} \
            winNumPath]} {
         $winNumPath configure -variable [scope activeWin]
         trace variable [namespace which -variable activeWin] w \
               [namespace code updateWinNum]
         # The style is set in the TLB file to be combobox so the user can
         # type in values other than these discrete values.
         $winNumPath insert list end \
               [list 1 1 2 2 3 3 4 4 5 5 ALL ALL]
      }
   }

   proc updateWinNum { args } {
      variable activeWin

      set actWin $activeWin
      if {[string match $activeWin ALL]} {
         set actWin 6
      }
      ans_graphics_activewin $actWin
   }

   proc fillRateChg { } {
      variable rateChg
      if {![catch {::AnsysGUI::getToolbarWidgetPath ANS_VIEW Complete rate} \
            ratePath]} {
         $ratePath configure -variable [namespace which -variable rateChg]
         trace variable [namespace which -variable rateChg] w \
               [namespace code updateRateChg]
         # The style is set in the TLB file to be combobox so the user can
         # type in values other than these discrete values.
         $ratePath insert list end \
               [list 1 1 15 15 30 30 45 45 60 60 75 75 90 90 100 100]
      }
   }

   proc updateRateChg { args } {
      variable rateChg

      if {[string is double $rateChg]} {
         if {($rateChg >= 1) && ($rateChg <= 100)} {
            if {[string is integer $rateChg]} {
               ans_graphics_rate $rateChg
            } else {
               set rateChg [expr int($rateChg)]
               ans_senderror 1 \
                  [msgcat::mc "The value for the rate change\
                        must be an integer value. The value\
                           of $rateChg will be used"]
            }
         } else {
            ans_senderror 2 \
               [msgcat::mc "The value for the rate change\
                     must be an integer value between 1 and 100"]
            if {$rateChg < 1} {
               set rateChg 1
            } else {
               set rateChg 100
            }
         }
      } else {
         ans_senderror 2 \
               [msgcat::mc "The value for the rate change\
                     must be an integer value"]
      }
   }

   proc direction { direction {win {}} } {
      variable activeWin

      if {[string match [list] $win]} {
         set win $activeWin
      }

      switch -- $direction {
         iso {
            catch {ans_sendcommand /VIEW,$win,1,1,1} 
            catch {ans_sendcommand /ANG,$win} 
         }
         obliq {
            catch {ans_sendcommand /VIEW,$win,1,2,3} 
            catch {ans_sendcommand /ANG,$win} 
         }
         front {
            catch {ans_sendcommand /VIEW,$win,,,1}
            catch {ans_sendcommand /ANG,$win}
         }
         back {
            catch {ans_sendcommand /VIEW,$win,,,-1}
            catch {ans_sendcommand /ANG,$win}
         }
         left {
            catch {ans_sendcommand /VIEW,$win,-1}
            catch {ans_sendcommand /ANG,$win}
         }
         right {
            catch {ans_sendcommand /VIEW,$win,1}
            catch {ans_sendcommand /ANG,$win}
         }
         top {
            catch {ans_sendcommand /VIEW,$win,,1}
            catch {ans_sendcommand /ANG,$win} 
         }
         bottom {
            catch {ans_sendcommand /VIEW,$win,,-1}
            catch {ans_sendcommand /ANG,$win} 
         }
         wp {
            catch {ans_sendcommand /VIEW,$win,WP}
         }
         fit {
            catch {ans_sendcommand /AUTO,$win} 
         }
      }
      catch {ans_sendcommand /REP,FAST}
   }

   proc focus { focus {win {}} } {
      variable activeWin
      variable rateChg

      if {[string match [list] $win]} {
         set win $activeWin
      }

      set rate [expr $rateChg / 100.0]
      switch -- $focus {
         panl {
            catch {ans_sendcommand /FOC,$win,$rate,,,1}
         }
         panr {
            catch {ans_sendcommand /FOC,$win,-$rate,,,1}
         }
         pant {
            catch {ans_sendcommand /FOC,$win,,-$rate,,1}
         }
         panb {
            catch {ans_sendcommand /FOC,$win,,$rate,,1}
         }
      }
      catch {ans_sendcommand /REP,FAST}
   }

   proc angle { angle {win {}} } {
      variable activeWin
      variable rateChg

      if {[string match [list] $win]} {
         set win $activeWin
      }

      switch -- $angle {
         cwx {
            catch {ans_sendcommand /ANG,$win,-$rateChg,XS,1}
         }
         ccwx {
            catch {ans_sendcommand /ANG,$win,$rateChg,XS,1}
         }
         cwy {
            catch {ans_sendcommand /ANG,$win,-$rateChg,YS,1}
         }
         ccwy {
            catch {ans_sendcommand /ANG,$win,$rateChg,YS,1}
         }
         cwz {
            catch {ans_sendcommand /ANG,$win,-$rateChg,ZS,1}
         }
         ccwz {
            catch {ans_sendcommand /ANG,$win,$rateChg,ZS,1}
         }
         default {
            catch {ans_sendcommand /ANG,$win,$angle}
         }
      }
      catch {ans_sendcommand /REP,FAST}
   }

   proc zoom { direction {win {}} } {
      variable activeWin
      variable rateChg

      if {[string match [list] $win]} {
         set win $activeWin
      }

      switch -- $direction {
         center {
            catch {ans_graphics_zoom center}
         }
         box {
            # Use the right mouse interaction as mode
            catch {ans_graphics_zoom box}
         }
         win {
            # Support
            catch {ans_graphics_zoom window}
         }
         back {
            catch {ans_sendcommand /ZOOM,$win,BACK}
         }
         in {
            set rate [expr pow(0.9,($rateChg/10.0))]
            catch {ans_sendcommand /DIST,$win,$rate,1}
            catch {ans_sendcommand /REP,FAST}
         }
         out {
            set rate [expr pow(0.9,((-1 * $rateChg)/10.0))]
            catch {ans_sendcommand /DIST,$win,$rate,1}
            catch {ans_sendcommand /REP,FAST}
         }
      }
   }

   proc scrollZoom { delta screenX screenY} {
      variable activeWin
      variable rateChg

      set x [expr $screenX  - [winfo rootx $::AnsysGUI::AnsysGraphics::ansGraphicArray(graphics)]]
      set y [expr $screenY  - [winfo rooty $::AnsysGUI::AnsysGraphics::ansGraphicArray(graphics)]]
      if {$x < 0 || $y < 0} {
         set x 0
         set y 0
      }
      set win [ans_graphics_findwn $x $y]
      if {$win == 0} {
         # If we aren't over a window then return
         return
      }

      if {$delta >= 0} {
         set rate [expr pow(0.9,((1 * $rateChg)/40.0))]
         catch {ans_sendcommand /DIST,$win,$rate,1}
      } else {
         set rate [expr pow(0.9,((-1 * $rateChg)/40.0))]
         catch {ans_sendcommand /DIST,$win,$rate,1}
      }
      catch {ans_sendcommand /REP,FAST}

   }

   proc activeWindow { {win {}} } {
      variable activeWin
      variable rateChg

      if {[string match [list] $win]} {
         # Dialog to query for active window
         if {[winfo exists .dlgGraphActiveWin]} {
            .dlgGraphActiveWin activate
            return
         }
         set dlg [::euidl::dialog .dlgGraphActiveWin]
         set cs [$dlg component childsite]

         ::euidl::label $cs.lblWinNum \
               -text [msgcat::mc "Active Window"]
         grid $cs.lblWinNum -column 0 -row 0

         ::euidl::combobox $cs.cmbWinNum \
               -variable [scope activeWin]
         $cs.cmbWinNum insert list end [list 1 1 2 2 3 3 4 4 5 5 All ALL]
         grid $cs.cmbWinNum -column 1 -row 0 -padx 5

         $dlg configure \
               -okbutton 0 \
               -helpbutton 0\
               -canceltext [msgcat::mc "Close"] \
               -cancelcommand [list destroy $dlg]
         $dlg activate
      } else {
         set $activeWin win
      }
   }

   proc dynamicMode { dynaMode } {
      variable dmodelVal
      variable dlightVal
      if {[string match $dynaMode init]} {
         if {![catch {::AnsysGUI::getToolbarWidgetPath \
               ANS_VIEW Complete dmodel} dmodelPath]} {
            $dmodelPath configure \
                  -variable [namespace which -variable dmodelVal]
            $dmodelPath configure \
                  -command [list [namespace code dynamicMode] model]
            set dmodelVal 0
         }
         if {![catch {::AnsysGUI::getToolbarWidgetPath \
               ANS_VIEW Complete dlight} dlightPath]} {
            $dlightPath configure \
                  -variable [namespace which -variable dlightVal]
            $dlightPath configure \
                  -command [list [namespace code dynamicMode] light]
            set dlightVal 0
         }
      } elseif {[string match $dynaMode model]} {
            set dlightVal 0
            ans_graphics_dynamic $dmodelVal model
      } elseif {[string match $dynaMode light]} {
            set dmodelVal 0
            ans_graphics_dynamic $dlightVal light
      } elseif {[string match $dynaMode visible]} {
         return [ans_getfilter 0 X3D]
      }
   }

   proc reset { {win {}} } {
      variable activeWin
      variable rateChg

      if {[string match [list] $win]} {
         set win $activeWin
      }

      catch {ans_sendcommand /VIEW,$win $/FOC,$win,AUTO $/DIST,$win \
            $/ANG,$win $/LIG,$win,1 $/REP}
   }

}; # End of view settings

}; # End of the windows namespace

euidl::graphics::graphicsOnOffInitialize
euidl::windows::windowOnOffInitialize
euidl::windows::windowSetInitialize
