# ********************************************************************
# Name   : CSG.TCL
# Author : Jeff Duncan <thaellin 'at' sympatico.ca>
#          Copyright (c) 2002, All Rights Reserved.
#
# Purpose: Provides the user interface for the AC3D "CSG" plugin
#          operations.
#
# Notes  :
#    base interface generated by SpecTcl version 1.1 from 
#    C:/Program Files/SpecTcl1.1/demo/csg.ui.  Doctored for proper
#    functionality.
# 
# Revision History:
# When          Who     What
# Sep 19 2002   JSD     Initial version.
# Oct 9 2004	AC		AC3D command now sent as seperate strings rather than a single
# ********************************************************************

proc jsd_csg_dialog {} {
   global op_A op_B op_func 
   set op_A ""
   set op_B ""
   set kill_A 0
   set kill_B 0

   if ![winfo exists .csg] {
	  new_toplevel .csg "CSG Operation"
      set op_func union    

      frame .csg.frame#1
      frame .csg.frame#2
      frame .csg.frame#4
      frame .csg.frame#5
      frame .csg.frame#6
      
      label .csg.label#1 -text {Operand A}
      entry .csg.entry#1 -textvariable op_A
      button .csg.button#1 -text {Set} -command {
         if ![string compare $op_A ""] { eval ac3d jsd_csg_selA } \
          else { eval ac3d jsd_csg_opA $op_A }
      }
	  checkbutton .csg.check#1 -text {Delete} -variable kill_A

      label .csg.label#2 -text {Operand B}
      entry .csg.entry#2 -textvariable op_B
      button .csg.button#8 -text {Set} -command {
         if ![string compare $op_B ""] { eval ac3d jsd_csg_selB } \
          else { eval ac3d jsd_csg_opB $op_B }
      }
	  checkbutton .csg.check#2 -text {Delete} -variable kill_B

      radiobutton .csg.button#2 -value union     -variable op_func -text Union
      radiobutton .csg.button#3 -value intersect -variable op_func -text Intersection
      radiobutton .csg.button#4 -value a_sub_b   -variable op_func -text {Subtraction (A - B)}
      radiobutton .csg.button#5 -value b_sub_a   -variable op_func -text {Subtraction (B - A)}

      button .csg.button#7 -text Cancel -command "wm withdraw .csg"
	   button .csg.button#6 -text OK -command {
         if [ expr [string compare $op_A ""] && [string compare $op_B ""]] {
            wm withdraw .csg
			ac3d redraw_all
            #eval ac3d jsd_csg_go $op_func#$op_A#$op_B#$kill_A#$kill_B
            ac3d jsd_csg_go $op_func $op_A $op_B $kill_A $kill_B

			ac3d redraw_all
            #focus .csg.button#7
         } else {
            tk_messageBox -title "Insufficient information" \
                          -message "You must set both operands A and B before performing an operation" \
                          -parent .csg \
                          -type ok
         }
      }	

      # Geometry management
      grid .csg.frame#1 -row 1 -column 1 
      grid .csg.frame#2 -in .csg.frame#1	-row 1 -column 1 
      grid .csg.frame#4 -in .csg.frame#1	-row 3 -column 1 
      grid .csg.frame#5 -in .csg.frame#1	-row 4 -column 1 
      grid .csg.frame#6 -in .csg.frame#1	-row 2 -column 1 
      grid .csg.label#1 -in .csg.frame#2	-row 1 -column 1  -sticky e
      grid .csg.entry#1 -in .csg.frame#2	-row 1 -column 2  -sticky ew
      grid .csg.button#1 -in .csg.frame#2	-row 1 -column 3  -sticky ew
	  grid .csg.check#1 -in .csg.frame#2	-row 1 -column 4  -sticky w
      grid .csg.label#2 -in .csg.frame#6	-row 1 -column 1  -sticky e
      grid .csg.entry#2 -in .csg.frame#6	-row 1 -column 2  -sticky ew
      grid .csg.button#8 -in .csg.frame#6	-row 1 -column 3  -sticky ew
	  grid .csg.check#2 -in .csg.frame#6	-row 1 -column 4  -sticky w
      grid .csg.button#2 -in .csg.frame#4	-row 1 -column 1  -sticky esw
      grid .csg.button#3 -in .csg.frame#4	-row 1 -column 2  -sticky ew
      grid .csg.button#4 -in .csg.frame#4	-row 1 -column 3  -sticky ew
      grid .csg.button#5 -in .csg.frame#4	-row 1 -column 4 
      grid .csg.button#6 -in .csg.frame#5	-row 1 -column 1  -sticky ew
      grid .csg.button#7 -in .csg.frame#5	-row 1 -column 2  -sticky ew

      # Resize behavior management
      grid rowconfigure .csg.frame#6 1 -weight 0 -minsize 2
      grid columnconfigure .csg.frame#6 1 -weight 0 -minsize 2
      grid columnconfigure .csg.frame#6 2 -weight 0 -minsize 285
      grid columnconfigure .csg.frame#6 3 -weight 0 -minsize 80

      grid rowconfigure .csg.frame#2 1 -weight 0 -minsize 2
      grid columnconfigure .csg.frame#2 1 -weight 0 -minsize 2
      grid columnconfigure .csg.frame#2 2 -weight 0 -minsize 285
      grid columnconfigure .csg.frame#2 3 -weight 0 -minsize 80

      grid rowconfigure .csg 1 -weight 0 -minsize 2
      grid columnconfigure .csg 1 -weight 0 -minsize 2

      grid rowconfigure .csg.frame#4 1 -weight 0 -minsize 2
      grid columnconfigure .csg.frame#4 1 -weight 0 -minsize 73
      grid columnconfigure .csg.frame#4 2 -weight 0 -minsize 132
      grid columnconfigure .csg.frame#4 3 -weight 0 -minsize 153
      grid columnconfigure .csg.frame#4 4 -weight 0 -minsize 37

      grid rowconfigure .csg.frame#5 1 -weight 0 -minsize 10
      grid columnconfigure .csg.frame#5 1 -weight 0 -minsize 119
      grid columnconfigure .csg.frame#5 2 -weight 0 -minsize 121

      grid rowconfigure .csg.frame#1 1 -weight 0 -minsize 7
      grid rowconfigure .csg.frame#1 2 -weight 0 -minsize 32
      grid rowconfigure .csg.frame#1 3 -weight 0 -minsize 19
      grid rowconfigure .csg.frame#1 4 -weight 0 -minsize 34
      grid columnconfigure .csg.frame#1 1 -weight 0 -minsize 2
   }

   eval ac3d jsd_csg_reset
   eval centre_window_on_screen .csg
   wm deiconify .csg
}
# *** END OF FILE ***