#!/usr/pkg/bin/wish

wm title . "MolRender"

set level 3
set model "ball"
set inputoption "-keyval"
set inputfile "molrender.in"
set keyvalkey "molecule"

proc make_inputoption { w } {
  frame $w.frame -borderwidth 10
  label $w.label -text "Input File Type"
  pack $w.label $w.frame -side top -pady 2
  radiobutton $w.frame.pdb -text "PDB File" -variable inputoption -value "-pdb" -relief flat
  radiobutton $w.frame.keyval -text "KeyVal File" -variable inputoption -value "-keyval" -relief flat
  pack $w.frame.pdb $w.frame.keyval -side top -pady 2 -expand yes -fill both
}

proc make_model { w } {
  frame $w.frame -borderwidth 10
  label $w.label -text "Model"
  pack $w.label $w.frame -side top -pady 2
  radiobutton $w.frame.ball -text "Ball" -variable model -value "ball" -relief flat
  radiobutton $w.frame.stick -text "Stick" -variable model -value "stick" -relief flat
  radiobutton $w.frame.connolly -text "Connolly" -variable model -value "connolly" -relief flat
  pack $w.frame.ball $w.frame.stick $w.frame.connolly -side top -pady 2 -expand yes -fill both
}

proc make_level { w } {
  frame $w.frame -borderwidth 10
  label $w.label -text "Sphere Subdivision Level"
  pack $w.label $w.frame -side top -pady 2
  radiobutton $w.frame.a -text "1" -variable level -value 1 -relief flat
  radiobutton $w.frame.b -text "2" -variable level -value 2 -relief flat
  radiobutton $w.frame.c -text "3" -variable level -value 3 -relief flat
  radiobutton $w.frame.d -text "4" -variable level -value 4 -relief flat
  radiobutton $w.frame.e -text "5" -variable level -value 5 -relief flat
  pack $w.frame.a $w.frame.b $w.frame.c $w.frame.d $w.frame.e -side top -pady 2 -expand yes -fill both
}

proc render {} {
  global model inputoption inputfile level keyvalkey
  #puts stdout "molrender -quiet -model $model -keyword $keyvalkey $inputoption $inputfile -level $level"
  set result [exec /usr/pkg/bin/molrender -quiet -render oogl -model $model -keyword $keyvalkey $inputoption $inputfile -level $level]
  #puts stdout "(geometry $model $result)"
  flush stdout
}

proc clear {} {
  #puts stdout "(geometry ball {})"
  #puts stdout "(geometry stick {})"
  #puts stdout "(geometry connolly {})"
  #flush stdout
}

proc done {} {
  destroy .
}

frame .inputarea
frame .inputarea.inputoption
frame .inputarea.model
frame .inputarea.level
make_inputoption .inputarea.inputoption
make_model .inputarea.model
make_level .inputarea.level

frame .inputfile
label .inputfile.label -text "Input File:"
entry .inputfile.entry -relief sunken -textvariable inputfile
pack .inputfile.label .inputfile.entry -side left -expand yes -fill both

frame .keyvalkey
label .keyvalkey.label -text "Keyword:"
entry .keyvalkey.entry -relief sunken -textvariable keyvalkey
pack .keyvalkey.label .keyvalkey.entry -side left -expand yes -fill both

frame .buttons
button .buttons.render -text "Render" -command render
button .buttons.clear -text "Clear" -command clear
button .buttons.done -text "Done" -command done
pack .buttons.render .buttons.clear .buttons.done -side left -padx 2 -expand yes -fill both
pack .inputarea.inputoption .inputarea.model .inputarea.level -side left -padx 2 -expand yes -fill both
pack .inputarea .inputfile .keyvalkey .buttons -side top -pady 2

clear
