# $Source: /usr/local/SimSoft/Sfx3D/src/gts/Gts.tcl,v $
# $Revision: 1.2 $
# $Author: baum $
# $Date: 2001/11/29 15:18:10 $
#
# Login name of the user who locked the revision
# $Locker:  $
# Tag name used to checkout the file
# $Name: Release-14 $
# State assigned to revision
# $State: Exp $
#
#
# $Log: Gts.tcl,v $
# Revision 1.2  2001/11/29 15:18:10  baum
# -Realzeitsteuerung eingebaut
# -Handsteuerung eingebaut
#

################# globale Variablen  ########################

set platform $tcl_platform(platform)

if {$platform == "windows"} {
  font create GTSFont -family "MS Sans Serif" -size 10 -weight normal \
                        -slant roman -underline 0 -overstrike 0
} else {
  font create GTSFont -family "MS Sans Serif" -size 12 -weight normal \
                        -slant roman -underline 0 -overstrike 0
}

################# globale Variablen  ########################
set DateiName  "Modell1"
set StatusZeile1 "    "
set StatusZeile2 "    "
set StatusZeileMerken 0
set DlgXPos 50
set DlgYPos 50

set NR ""
set BSTNR ""
set BSTTYP ""
set AKTBUTTON  ".knoeppe.pfeil"
set AKTANSICHT ".knoeppe.ansicht"


############################ BAUSTEINBEARBEITUNG #############################
#source ../src-gts/gts01.tcl
source gts01.tcl

######################### ICONS  ############################
#source ../src-gts/gts02.tcl
source gts02.tcl

######################### TESTUMGEBUNG ############################
#source ../src-gts/gts03.tcl

######################### AUFTRAGSBEARBEITUNG #######################
#source ../src-gts/gts04.tcl
source gts04.tcl

######################### PROZESSBEARBEITUNG ########################
#source ../src-gts/gts05.tcl
source gts05.tcl

############################## ZEITMODELL ###########################
#source ../src-gts/gts06.tcl
source gts06.tcl

############################## EREIGNISBEARBEITUNG  ###################
#source ../src-gts/gts07.tcl
source gts07.tcl

############################## BAUSTEINPARAMETER  ###################
#source ../src-gts/gts08.tcl
source gts08.tcl

############################## BAUSTEIN-INFO  #########################
#source ../src-gts/gts09.tcl
source gts09.tcl

#############################################################
if { [catch {set ssylay $env(SSYLAY)}]} {set ssylay "/"};

# ===========    Menue    =====================================================
#source ../src-gts/gts00.tcl
source gts00.tcl

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# ++++++++++++      A L L G E M E I N E   R O U T I N E N   +++++++++++++++++
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


proc put_win { str } {
  global AusgabeFenster
  $AusgabeFenster insert end $str;
  $AusgabeFenster yview moveto 1.0;
}
#  ENDE put_win

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc setButtonStatus { inp } {
    global BSTATUS   
    catch { $BSTATUS($BSTATUS($inp)) config -state normal }
}
#  ENDE setButtonStatus

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc FloatInInt { inp } {
  set stelle [string first "." $inp]
  if {$stelle >= 0} { set inp [string range $inp 0 [expr $stelle - 1]] }
  return $inp
}
#  ENDE FloatInInt

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc IstInt { c inp v } {
  if { $c == "" } { return 1 }
  if { $v == "" } {
    if {[regexp {[\ -/:-ý]} $c]}     { return 0 }
  } else {
    if {[regexp {[\ -,.-/:-ý]} $c]}  { return 0 }
  }
  if { $c == "-" } {    
     if {[$inp index insert] > 0 }           { return 0 } 
     if {[string index [$inp get] 0] == "-"} { return 0 }
  }
  if {[regexp {[-0123456789]} $c]} { setButtonStatus $inp }
  return 1
}
# ENDE IstInt

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc IstFloat { c inp } {
  if { $c == "" } { return 1 }
  if {[regexp {[\ -,//-/:-ý]} $c]}   { return 0 }
  if { $c == "." } { if { [string first "." [$inp get]] != -1 } { return 0 } }
  if { $c == "-" } {    
     if {[$inp index insert] > 0 }           { return 0 } 
     if {[string index [$inp get] 0] == "-"} { return 0 }
  }
  if {[regexp {[-.0123456789]} $c]} { setButtonStatus $inp }
  return 1
}
# ENDE IstFloat

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc IstString { c inp } {
  if { $c == "" } { return 1 }
  if {[regexp {[\ -);\{-ý]} $c]} { return 0 }
  if {[regexp {[*-z]} $c]} { setButtonStatus $inp }
  return 1
}
# ENDE IstString

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc deleteStatusZeile { zeile } {
  global StatusZeile1 StatusZeile2 StatusZeileMerken
    
  if { $zeile == 0 } {
    set StatusZeile1  ""
    set StatusZeile2  ""
    set StatusZeileMerken 0
  } elseif { $zeile == 1 } {
    set StatusZeile1 $StatusZeile2
  } elseif { $zeile == "2" } {
    set StatusZeile2      ""
    set StatusZeileMerken 0
   }
}
#  ENDE deleteStatusZeile

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc MachButton { f fuss breite {xorient "right"} {yorient "left"}} {
  if {[catch {frame $f.fr }] == 1} { return $f.fr.f }  
  pack   $f.fr  -side bottom  -fill x
  frame  $f.fr.f 
  pack   $f.fr.f  -side $xorient 
  
  set index 1
  foreach i $fuss {
    button $f.fr.f.$index -text $i -width $breite
    pack   $f.fr.f.$index -side $yorient -padx 2m -pady 2m
    incr index
  }
  return $f.fr.f
}
## ENDE MachButton


# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc SetzAktMenueStatus { b } {
  global AKTBUTTON GTS
#  put_win "ALT= $AKTBUTTON  -->"
  if { [string first "knoeppe" $AKTBUTTON] > 0 } { 
     $AKTBUTTON config -relief raised 
   } else {
   set GTS($AKTBUTTON) 0  
  }
  set AKTBUTTON $b
#  put_win "NEU= $AKTBUTTON  \n"
  if { [string first "knoeppe" $AKTBUTTON] > 0 } { 
    $AKTBUTTON config -relief sunken 
   } else {
   set GTS($AKTBUTTON) 1
  }
}
## ENDE SetzAktMenueStatus


# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc SetzAktAnsichtButton { aktButton b } {
upvar #0 $aktButton Button 
  global GTS
#  put_win "ALT= $Button  -->"
  if { [string first "knoeppe" $Button] > 0 } { 
     $Button config -relief raised 
   } else {
   set GTS($Button) 0  
  }
  set Button $b
#  put_win "NEU= $Button  \n"
  if { [string first "knoeppe" $Button] > 0 } { 
    $Button config -relief sunken 
   } else {
   set GTS($Button) 1
  }
}
## ENDE SetzAktAnsichtButton

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc SetzMenueStatus { status } {
  foreach i { 4 5 6 }         { .menu.file entryconfigure $i -state $status       }
  foreach i { 10 11 13 14 } { .menu.edit entryconfigure $i -state $status       }
  foreach i { 0 1 2 3 5 }   { .menu.logik entryconfigure $i -state $status      }
  foreach i { 0 1 }         { .menu.experiment entryconfigure $i -state $status }
}
## ENDE SetzMenueStatus

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc SetzBstButton { status } {
  foreach i { 1 2 3 5 6 } { .menu.edit entryconfigure $i -state $status }
  .knoeppe.duplizieren    configure -state $status 
  .knoeppe.loeschen       configure -state $status 
  .knoeppe.drehen         configure -state $status 
}
## ENDE SetzBstButton

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc SetzAusrichtButton { status } {
  foreach i { 7 8 } {
     .menu.edit entryconfigure $i -state $status 
  }
  if {$status == "active"} {
     .menu.edit entryconfigure 3 -state disabled
  }
  .knoeppe.vertikalausrichten    configure -state $status
  .knoeppe.horizontalausrichten  configure -state $status
}
## ENDE SetzAusrichtButton

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# ++++++++++++++++  D I A L O G :  FileDialog  ++++++++++++++++++++++++++++++
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

proc FileDialog {w  defExt  action} {
    set types {	{"Modelle" {.2gs}}  {"XML-Modelle" {.xml}}}
    global ssylay
    if {$action == "lesen"} {
	  set file [tk_getOpenFile -initialdir $ssylay -filetypes $types \
                -defaultextension $defExt]
    } else {
	  set file [tk_getSaveFile -initialdir $ssylay -filetypes $types]
    }
    if {$file != ""} { set ssylay [file dirname $file] }
    return $file
}
## ENDE FileDialog


# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc UpDownLeiste { W  hoehe} {
   global xpmPfeilUp xpmPfeilDown
   frame $W
   frame $W.space -height $hoehe
   button $W.up -image $xpmPfeilUp
   button $W.down -image $xpmPfeilDown
   pack   $W.space $W.up $W.down  -padx 1m -pady 1m    
}
# ENDE UpDownButtonLeiste


# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# ++++++++++++  D I A L O G :  DlgEineEingabe +++++++++++++++++++++++++++++++
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

proc DlgEineEingabe { fname pname inp } {
   global Confirm
   set dlg [dialog_create $fname Dialog "OK" "Abbruch"]
   set p1 [dialog_entry $dlg $pname 20 "" 10 $inp "Int"]
   dialog_focus $p1
   dialog_wait $dlg
   while {$Confirm($dlg) == "1"} {
     if {([string trimleft [$p1 get] 0] > 0)} {
       set Confirm($dlg) 3 
     } else {
       dialog_wait $dlg
     }
   }
   set ret -1
   if {$Confirm($dlg) == "3"} { set ret [string trimleft [$p1 get] 0] }
   dialog_destroy $dlg
   return $ret
}

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# ++++++++++++  Modell speichern             ++++++++++++++++++++++++++++++++
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

proc ModellSpeichern { } {
  global DateiName
  if {$DateiName != "Modell1"} {
    .menu configure -cursor watch
    update
    set ret [DlgDatei ModellSpeichern $DateiName ".2gs" 0 ];
  } else {
  	 # anpassen !!! 15-12-03: rudi
  	 set datei [FileDialog .menu exl speichernunter]
    if {$datei != ""} {
      .menu configure -cursor watch
      update
      set DateiName [file rootname $datei]
      set ret [DlgDatei ModellSpeichern $DateiName ".xml" 0 ];
      wm title . "SIMFLEX/3 - GTS - ([file tail $DateiName])"
    } else { return false }
  }
}  
## ENDE ModellSpeichern


#=============== Diverse Funktionen ====================
proc Hilfe_Fenster Hilfedatei {
  toplevel .hilfeFen
  set f .hilfeFen.hFrame 
  frame $f 
  text $f.text -relief sunken -bd 2 -font GTSFont -wrap none\
               -yscrollcommand "$f.hilfeScroll set"
  scrollbar $f.hilfeScroll -command "$f.text yview"
  pack $f -expand yes -fill both
  pack $f.hilfeScroll -side right -fill y
  pack $f.text -side left -fill both

# Hilfetext aus Datei 'Hilfedatei' einlesen!!!

  $f.text delete 1.0 end
  set d [open $Hilfedatei]
  while {![eof $d]} {
    $f.text insert end [read $d 1000]
  }
  close $d
  wm geometry .hilfeFen 380x230
  wm title .hilfeFen "FFS Hilfe"
}

#======== MENUBAR ============================================================

proc GTSBeenden {} {
  global DateiName
  
  if { [.menu.file entrycget 4 -state] == "disabled" } {
    DlgDatei GTSEnde 0 0 0;
    exit
  }
  
  if {$DateiName != "Modell1"} {
    set meld "Möchten Sie das Modell in $DateiName speichern?"
  } else {  
    set meld "Möchten Sie das Modell speichern?"
  }  
  set antwort "??"
  set antwort [tk_messageBox -parent . -title "SIMFLEX/3 - GTS -" \
               -icon question  -message $meld \
               -type yesnocancel -default yes]
  if {$antwort == "no"} {
    DlgDatei GTSEnde 0 0 0;
    exit
  } elseif {$antwort == "yes"} {
    if { [ModellSpeichern] != "false" } {
      DlgDatei GTSEnde 0 0 0;
      exit
    }
  }
}
### ENDE GTSBeenden 

proc GTSExit {} {
  DlgDatei GTSEnde 0 0 0;
  exit
}
### ENDE GTSExit 


# ===========  Balloon    =====================================================
set GTS(Balloon) [tixBalloon .gtsBalloon]
$GTS(Balloon) bind .knoeppe.pfeil       -msg "Baustein auswählen"
$GTS(Balloon) bind .knoeppe.erzeugen    -msg "Baustein erzeugen"
$GTS(Balloon) bind .knoeppe.duplizieren -msg "Baustein duplizieren"
$GTS(Balloon) bind .knoeppe.loeschen    -msg "Baustein löschen"
$GTS(Balloon) bind .knoeppe.vertikalausrichten \
                   -msg "Baustein \nvertikal ausrichten"
$GTS(Balloon) bind .knoeppe.horizontalausrichten \
                   -msg "Baustein \nhorizontal ausrichten"
$GTS(Balloon) bind .knoeppe.drehen        -msg "Baustein drehen"
$GTS(Balloon) bind .knoeppe.zoom          -msg "Fläche zoomen"
$GTS(Balloon) bind .knoeppe.zoombox       -msg "Fläche zoomen (Box)"
$GTS(Balloon) bind .knoeppe.ansicht       -msg "Default Ansicht"
$GTS(Balloon) bind .knoeppe.ansichtlinks  -msg "Ansicht links"
$GTS(Balloon) bind .knoeppe.ansichtunten  -msg "Ansicht vorn"
$GTS(Balloon) bind .knoeppe.ansichtrechts -msg "Ansicht rechts"

# ===========  Statusbar  =====================================================

set koorstatus "    "
frame .statusBar
label .statusBar.koordinate -textvariable koorstatus -width 24 -relief sunken -bd 2 -font GTSFont -anchor w
frame .statusBar.platzhalter -width 5
label .statusBar.text -textvariable StatusZeile1 -relief sunken -bd 2 -font GTSFont -anchor w
pack  .statusBar.koordinate  -side left -padx 0 -pady 2 -fill both
pack  .statusBar.platzhalter -side left -padx 0 -pady 2 -fill both
pack  .statusBar.text        -side left -padx 0 -pady 2 -fill both -expand yes

# ===========  Ende Statusbar  ================================================

#======== TEXTWINDOW ==========================================================

set AusgabeFenster .action.debug.text
set Zeichenflaeche .action.draw.drawZ  

frame .action -relief sunken -borderwidth 0          

frame .action.draw
frame .action.draw.drawZ -relief sunken -borderwidth 2

frame .action.draw.drawXY
frame .action.draw.drawXY.drawX -relief sunken -borderwidth 2
frame .action.draw.drawXY.drawY -relief sunken -borderwidth 2


frame .action.space -height 3m
frame .action.debug -relief sunken -borderwidth 2

# canvas .action.draw.client  -bg white -borderwidth 0\
#       -yscrollcommand ".action.draw.scrolly set"\
#       -xscrollcommand ".action.draw.scrollx set"
      
# scrollbar .action.draw.scrolly -command {.action.draw.client yview}
# scrollbar .action.draw.scrollx -command {.action.draw.client xview} -orient horizontal


text $AusgabeFenster -height 5 -yscrollcommand ".action.debug.scy set"\
       -borderwidth 0 -bg White -fg Black -font GTSFont -wrap none

scrollbar .action.debug.scy -command {$AusgabeFenster yview}


pack .knoeppe   -side left -ipadx 2 -fill y
pack .statusBar -side bottom -fill x -padx 0 -pady 0
pack .action -expand yes -fill both

pack .action.debug -side bottom -fill x    -expand no
pack .action.space -side bottom -fill x    -expand no
pack .action.draw  -side bottom -fill both -expand yes

pack .action.draw.drawZ -side bottom -fill both -expand yes



#pack .action.draw.drawXY  -side top -fill both -expand yes
#pack .action.draw.drawXY.drawX  -side right -fill both -expand yes
#pack .action.draw.drawXY.drawY  -side left -fill both -expand yes

# pack .action.draw.scrolly -side right -fill y
# pack .action.draw.scrollx -side bottom -fill x
# pack .action.draw.client  -fill both -expand yes

pack .action.debug.scy -side right -fill y
pack .action.debug.text -side left -fill both -expand yes

wm geometry . 700x600+1+1
update

. configure -menu .menu
bind  . <Escape>     { DlgGrafik DIALOGABBRUCH   0 0 0 }
bind  . <Control-a>  { DlgGrafik ObjectMoving 
                       DlgGrafik ALLESAUSWAEHLEN 
                       SetzAktMenueStatus .knoeppe.pfeil
                     }
                       
bind  . <Delete>     { DlgGrafik BSTLOESCHEN 0 0 0 
                       SetzAktMenueStatus .knoeppe.pfeil
                     }  


wm title . "SIMFLEX/3 - GTS - ($DateiName)"
wm protocol . WM_DELETE_WINDOW {GTSBeenden}



# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# ++++++++++++  Aufrufe fuer GTS-Initialisierung  +++++++++++++++++++++++++++
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DlgDatei GTSInit 0 0 0;
InitBasisNamen;
