

proc beamcross_cmd {what args} {
   global graphics_type black_and_white use_xwindows
   global beamcross_info

   switch -- $what {
      setup {
         if {![info exist beamcross_info(fm)] || \
                 ![winfo exist $beamcross_info(fm)]} {
            set fm [lindex $args 0]
            if ![winfo exist $fm] {return ""}

            set gt native
            if {[info exist graphics_type]} {set gt $graphics_type}

            tdv_init $fm.graph 500 500 $gt black 0 1 1
            $fm.graph configure -background #888888

            set beamcross_info(fm) $fm.graph
         }

         pack $beamcross_info(fm) -side top -anchor center \
                     -fill both -expand yes
      }
      off {
         if {[info exist beamcross_info(fm)] && \
             [winfo exist $beamcross_info(fm)]} {
            pack forget $beamcross_info(fm)
         } 
      } 
      in_plot_frame {
         global plot_frame

         if {![info exist beamcross_info(plot_fm)] || \
               ![winfo exist $beamcross_info(plot_fm)]} {
            #set fm [NoteBook $plot_frame.beam]
            set fm [frame $plot_frame.beam]
            set beamcross_info(plot_fm) $fm
         }

         pack $beamcross_info(plot_fm) -side top -anchor center \
                      -fill both -expand yes -padx 0 -pady 0

         beamcross_cmd setup $beamcross_info(plot_fm)
      }
      out_plot_frame {
         if {[info exist beamcross_info(plot_fm)] && \
             [winfo exist $beamcross_info(plot_fm)]} {
            pack forget $beamcross_info(plot_fm)
         } 
      }
      reset {
         if {![info exist beamcross_info(obj)] || \
             ([info command $beamcross_info(obj)] == "")} {
             set beamcross_info(obj) [vpbeamcross_im -pos "200 100 0" \
                      -scale "50 50 50" -fillcolor #11ff22 \
                      -color #ff2222 -transform 0]
         }
         $beamcross_info(fm) add_image $beamcross_info(obj)

         set rr [eval $beamcross_info(obj) reset $args]
         set beamcross_info(def) $args
         set beamcross_info(bx) [lindex $rr 0]
         set beamcross_info(by) [lindex $rr 1]
         foreach n {I1 I2 J area centroid} {
            set beamcross_info($n) [$beamcross_info(obj) $n]
         }
      }
      test {
         #source [file join $vpost_batch_library beamcross.tcl]
         beamcross_cmd in_plot_frame

         beamcross_cmd reset I    3.2 1.5 2.0 0.5 0.6 0.8
         beamcross_cmd reset H    1.0 0.6 3 0.5
         beamcross_cmd reset HAT  2.2 0.5 3 0.8
         beamcross_cmd reset T    2 3 0.6 0.5
         beamcross_cmd reset CHAN 1.8 2.8 0.25 0.6
         beamcross_cmd reset L    1.8 2.8 0.6 0.25
         beamcross_cmd reset BOX 3 3 0.6 0.5  
         beamcross_cmd reset TUBE 3 2
         beamcross_cmd reset ROD  3
         beamcross_cmd reset BAR 3 2
      }
   }
}


