
proc aie_set_v3pts_v3dset {theTree theNode} {
   global v3pts_data

   set dset [$theTree parent $theNode]
   while {[set p [$theTree parent $dset]] != "root"} {set dset $p}
   if {$dset != $v3pts_data(v3dset)} { V3_vppoint v3dset $dset }
}

proc aie_toggle_v3pts_root {theTree theNode args} {
   aie_set_v3pts_v3dset $theTree $theNode
   OnedTree::toggle $theTree $theNode
}

proc aie_toggle_v3pts {theTree theNode args} {
   aie_set_v3pts_v3dset $theTree $theNode
   OnedTree::toggle $theTree $theNode
}

proc aie_v3pts_rootmenu {mm theTree theNode id} {
   set dset [aie_set_v3pts_v3dset $theTree $theNode]

   if {[$theTree nodes $theNode] != ""} {
      OnedTree::plotmenu $mm $theTree $theNode $dset
   }

   $mm add command -label "Create A Segment" -command \
             "onedLineDEZ load"

 # add create object menu here 
}

proc aie_v3pts_menu {mm theTree theNode id} {
   set dset [aie_set_v3pts_v3dset $theTree $theNode]

   OnedTree::plotmenu $mm $theTree $theNode $dset
 #  --- the vppts corrsponding to $theNode set as the current

   $mm add command -label "Rename" -command \
              "aie_v3pts_tree rename $theNode $id"
   $mm add command -label "Remove" -command \
              "aie_v3pts_tree remove $theNode $id"
   $mm add command -label "Make new XY plot" -command \
              "aie_v3pts_tree xy_plot $theNode $id"
 # $mm add command -label "Interpolate result" -command \
 #            "aie_v3pts_update_cmd interpolate_res"
}


proc aie_v3pts_tree {what node id args} {
   global v3pts_data

   set top_tree [set ::AIEnv::GUIManagement::Tree::aieTree]

   switch -- $what {
      remove {
         if {[V3_vppoint_get plt_list] != ""} {
            if [confirm_diag "Remove it with associated XY plots"] {return}
         }
         V3_vppoint remove
      }
      rename {
         set oldname [$top_tree itemcget $node -text]
         set newname [question_box .text "Change Group's Name" \
                        "Rename group of streams" $oldname]
       # set newname [$top_tree  edit $node $oldname]
         if {$newname != ""} {
            V3_vppoint rename $newname
         }
      }
      create {
      }
      xy_plot {
         V3_vppoint xyplot $id
      }
   }
}


proc onv3SaveAsDEZLoad {} {
   global surf_info

   foreach {n v} {pt 1 scalar 1 vector 0 TQ 0 stat 0} {
      set ::surf_info(savetxt,$n) $v
   }

 # for those not in comparison
   set nst 1
   ::AIEnv::GUIManagement::ToggleGrey v3SaveAsTextStat $nst
}

proc onv3SaveAsDEZApply {} {
   global surf_info

   set fmt [::AIEnv::GUIManagement::ExclusiveGroup::GetCurrentGroupName \
                v3SaveAsFormat]
   if {$fmt == "v3SaveAsDomain"} {
      V3_surface_save_set format domain
      write_domain_surface_cmd selected
   } elseif {$fmt == "v3SaveAsText"} {
      set opt ""
      foreach {n v} {pt p scalar s vector v TQ g} {
         if {$surf_info(savetxt,$n)} {lappend opt $v}
      }
      V3_surface_save_set format text
      V3_surface_save_set txtopt $opt
      write_domain_surface_cmd selected

      if {$surf_info(savetxt,stat)} {
          
      }
   }
}
