#!/bin/sh
# the next line restarts with wish \
exec wish "$0" "$@"
##
## xtherion --
##
##     Therion user interface.
##
## Copyright (C) 2002 Stacho Mudrak
## 
##
## -------------------------------------------------------------------- 
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
## 
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
## -------------------------------------------------------------------- 








set xth(debug) 0
set xth(about,ver) 0.3.10







package require msgcat
namespace import ::msgcat::mc

set xth(about,nvr) {}
set xth(about,session) [list]


proc xth_ivc {} {
  global xth
  set newver {}
  catch {
    
    package require http 2.0
    
    # proxy configuration
    set httpproxy {}
    global tcl_platform env
    set winregkey [join {
         HKEY_CURRENT_USER
         Software Microsoft Windows
         CurrentVersion "Internet Settings"
    } \\]
    if {[info exists env(http_proxy)]} {
        set httpproxy $env(http_proxy)
    } else {
        if {$tcl_platform(platform) == "windows"} {
            package require registry 1.0
            array set reg {ProxyEnable 0 ProxyServer "" ProxyOverride {}}
            catch {
                set reg(ProxyEnable) [registry get $winregkey "ProxyEnable"]
                set reg(ProxyServer) [registry get $winregkey "ProxyServer"]
            }
            if {![string is bool $reg(ProxyEnable)]} {
                set reg(ProxyEnable) 0
            }
            if {$reg(ProxyEnable)} {
               if { [string first ";" $reg(ProxyServer)] == -1 } {
                   set httpproxy $reg(ProxyServer)
               } else {
                  foreach tmp [split $reg(ProxyServer) ";"] {
                      if { [string match "http=*" $tmp] } {
                          set httpproxy [string range $tmp 5 end]
                          break
                      }
                  }
                  unset tmp
               }
            }
		if {[string length $httpproxy] == 0} {
			set reg_auto {}
			catch {
				set reg_auto [registry get $winregkey "AutoConfigURL"]
				if {[string length $reg_auto] > 0} {
    					set token [::http::geturl $reg_auto]
				      upvar #0 $token pxs
					regexp -all -nocase {proxy\s+([^\:]+\:\d+)} $pxs(body) dum httpproxy
				}
			}
		}
        }
    }

    if {[string length $httpproxy] > 0} {
        if {![regexp {\w://.*} $httpproxy]} {
            set httpproxy "http://$httpproxy"
        }
        if {[regexp {\w://(.*)\:(\d*)} $httpproxy dum proxyhost proxyport]} {
          ::http::config -proxyhost $proxyhost -proxyport $proxyport
          set xth(proxy) "$proxyhost:$proxyport"
        }
    }
    
    set token [::http::geturl "http://therion.speleo.sk/update.php" -query [::http::formatQuery version $xth(about,ver) therion 1]]
    upvar #0 $token state
    if {[regexp {^(\d+)\.(\d+)\.(\d+)} $xth(about,ver) dump mv1 mv2 mv3]} {
      if {[regexp {th\_version\s+(\d+)\.(\d+)\.(\d+)} $state(body) dump nv1 nv2 nv3]} {
        if {($mv1 < $nv1) || (($mv1 == $nv1) && ($mv2 < $nv2)) || (($mv1 == $nv1) && ($mv2 == $nv2) && ($mv3 < $nv3))} {
          set newver "$nv1.$nv2.$nv3"
        }
      }
    }
  }
  set xth(about,nvr) $newver
}









set xth(destroyed) 0
set xth(prj,name) "therion"
set xth(prj,title) "therion user interface"
set xth(gui,main) ".xth"
set xth(gui,about) ".xth_about"
set xth(gui,bacw) ".xth_bac"
set xth(gui,dbg) ".xth_dbg"
set xth(gui,help) ".xth_help"
set xth(gui,message) ".xthmsg"
set xth(gui,minsize) {480 300}
set xth(gui,balloons) 0
set xth(gui,toolbar) 1
set xth(te,template) {}

set xth(kb_control) Control
set xth(kb_meta) Meta
set xth(gui,compshow) 0
set xth(gui,compcmd) "therion"
set xth(gui,auto_save) 0
set xth(gui,check_update) 1

set xth(encodings) { iso8859-1 iso8859-2 iso8859-5 iso8859-7 utf-8 }
set xth(kbencodings) {utf-8 iso8859-1 iso8859-2 cp1250 macCentEuro unicode}
set xth(length_units) {m cm in ft yd}
set xth(angle_units) {deg min grad}
set xth(point_types) {}
set xth(line_types) {}
set xth(scrap_projections) {plan elevation extended none}
set xth(app,te,filetypes) {    
  {{Therion files}       {.th}}    
  {{2D therion files}       {.th2}}    
  {{All files}       {*}}    
}
set xth(app,te,fileext) {.th}

set xth(app,me,filetypes) {    
  {{Therion 2D files}       {.th2}}    
  {{Therion files}       {.th}}    
  {{All files}       {*}}    
}

set xth(app,cp,filetypes) {    
  {{Therion config files}       {thconfig*}}    
  {{Therion config files }       {.thcfg .thconfig}}    
  {{All files}       {*}}    
}

set xth(app,mv,filetypes) {    
  {{Therion models}       {.thm}}    
  {{All files}       {*}}    
}

set xth(icmds) {survey}
set xth(cmds) {scrap centerline grade line area map layout}

set xth(datafmt,unknown) {4s}                    
set xth(datafmt,station) {4s}                    
set xth(datafmt,length) {6.2fx {-}}             
set xth(datafmt,counter) {6.2f {-}}            
set xth(datafmt,bearing) {5.1fx {-}}             
set xth(datafmt,gradient) {{5.1fx} {up down -}} 
set xth(datafmt,depth) {6.2fx {-}}            
set xth(datafmt,dimensions) {4.1fx {-}}             

set xth(gui,initdir) [pwd]
set xth(app,active) ""
set xth(app,list) {}
set xth(app,all,relw) -1
set xth(app,all,wmwd) 180
set xth(app,all,wpsw) 1

set xth(app,fencoding) utf-8
set xth(app,sencoding) iso8859-2

# autodetect some options
frame .def
scrollbar .def.scrollbar
text .def.text
if {[catch {.def.text configure -undo 1}]} {
  set xth(gui,text_undo) 0;
} else {
  set xth(gui,text_undo) 1;
}
label .def.label

set xth(gui,sbwidth) [.def.scrollbar cget -width]
set xth(gui,sbwidthb) [.def.scrollbar cget -borderwidth]
set xth(gui,lfont) [.def.label cget -font]
set xth(gui,efont) [.def.text cget -font]
set xth(gui,ecolorbg) black
set xth(gui,ecolorfg) green
set xth(gui,escolorbg) black
set xth(gui,escolorfg) red
set xth(gui,ecolorselbg) green
set xth(gui,ecolorselfg) black
set xth(gui,selfg) white
set xth(gui,selbg) darkBlue
set xth(gui,etabsize) 2
set xth(gui,controlk) Ctrl

set xth(gui,xvi_grid_clr) #00D0D0
set xth(gui,xvi_walls_fptn) gray12
set xth(gui,xvi_walls_fclr) gray80
set xth(gui,xvi_walls_oclr) gray60
set xth(gui,xvi_shot_clr) gray50
set xth(gui,xvi_station_fclr) black
set xth(gui,xvi_station_oclr) black

set xth(gui,me,nozoom) 1

destroy .def
# end of options autodetection

# map editor settings


# SCRAP
# size of scrap scaling square
set xth(gui,me,scrap,psize) 4


# POINT
# size of point
set xth(gui,me,point,psize) 4

# LINE
# size of line point
set xth(gui,me,line,psize) 4
# line width
set xth(gui,me,line,width) 3
# size of line control point
set xth(gui,me,line,cpsize) 4
# width of line between point and control point
set xth(gui,me,line,clwidth) 2
# size of start line tick
set xth(gui,me,line,ticksize) 15
# width of start line tick
set xth(gui,me,line,tickwidth) 3

set xth(gui,me,activefill) red
set xth(gui,me,pasivefill) blue
set xth(gui,me,controlfill) blue
set xth(gui,me,highlightfill) cyan

set xth(gui,me,typelistwidth) 16

set xth(gui,bindinsdel) 1

# platform dependend settings
case $tcl_platform(platform) {
  unix {
    set xth(gui,sbwidth) 9
    set xth(gui,sbwidthb) 1
    set xth(gui,efont) {fixed -20}
    set xth(gui,platform) unix
    set xth(gui,cursor) top_left_arrow
    set xth(gui,compshow) 1
  }
  windows {
    package require registry
    catch {
      set xth(gui,compcmd) "\"[file join [registry get {HKEY_LOCAL_MACHINE\SOFTWARE\Therion} InstallDir] therion.exe]\""
    }
    regsub -all {\/} $xth(gui,compcmd) {\\\\} xth(gui,compcmd)
    set xth(gui,efont) "Courier 16 roman bold"
    set xth(gui,platform) windows
    set xth(gui,cursor) arrow
    set xth(app,sencoding) cp1250
    set xth(gui,bindinsdel) 0
    if {[catch {
      set fid [open "|cmd.exe /c" r]
      read $fid;
      close $fid
    }]} {
      set xth(gui,compcmd) "command.com /c $xth(gui,compcmd)"
    } else {
      set xth(gui,compcmd) "cmd.exe /c $xth(gui,compcmd)"
    }
  }
  macintosh {
    set xth(kb_meta) Meta
    set xth(kb_control) Alt
    set xth(gui,controlk) Cmd
    set xth(gui,platform) macintosh
    set xth(gui,cursor) arrow
    set xth(gui,bindinsdel) 0
    set xth(app,sencoding) utf-8
  }
}
# end of platform dependend settings

set xth(about,image_data) {
R0lGODlhwACQAOcAAAAAAAAAVQAAqgAA/wAkAAAkVQAkqgAk/wBJAABJVQBJ
qgBJ/wBtAABtVQBtqgBt/wCSAACSVQCSqgCS/wC2AAC2VQC2qgC2/wDbAADb
VQDbqgDb/wD/AAD/VQD/qgD//yQAACQAVSQAqiQA/yQkACQkVSQkqiQk/yRJ
ACRJVSRJqiRJ/yRtACRtVSRtqiRt/ySSACSSVSSSqiSS/yS2ACS2VSS2qiS2
/yTbACTbVSTbqiTb/yT/ACT/VST/qiT//0kAAEkAVUkAqkkA/0kkAEkkVUkk
qkkk/0lJAElJVUlJqklJ/0ltAEltVUltqklt/0mSAEmSVUmSqkmS/0m2AEm2
VUm2qkm2/0nbAEnbVUnbqknb/0n/AEn/VUn/qkn//20AAG0AVW0Aqm0A/20k
AG0kVW0kqm0k/21JAG1JVW1Jqm1J/21tAG1tVW1tqm1t/22SAG2SVW2Sqm2S
/222AG22VW22qm22/23bAG3bVW3bqm3b/23/AG3/VW3/qm3//5IAAJIAVZIA
qpIA/5IkAJIkVZIkqpIk/5JJAJJJVZJJqpJJ/5JtAJJtVZJtqpJt/5KSAJKS
VZKSqpKS/5K2AJK2VZK2qpK2/5LbAJLbVZLbqpLb/5L/AJL/VZL/qpL//7YA
ALYAVbYAqrYA/7YkALYkVbYkqrYk/7ZJALZJVbZJqrZJ/7ZtALZtVbZtqrZt
/7aSALaSVbaSqraS/7a2ALa2Vba2qra2/7bbALbbVbbbqrbb/7b/ALb/Vbb/
qrb//9sAANsAVdsAqtsA/9skANskVdskqtsk/9tJANtJVdtJqttJ/9ttANtt
Vdttqttt/9uSANuSVduSqtuS/9u2ANu2Vdu2qtu2/9vbANvbVdvbqtvb/9v/
ANv/Vdv/qtv///8AAP8AVf8Aqv8A//8kAP8kVf8kqv8k//9JAP9JV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MY
shgXIdMZX5mQcsaII6FgzOmbFhQ3riJ/q0klTpQlKcZIsjmTk7RvsJkdJ5Qn
KhKO7OF3fSliHIWZEkFxb0d4Y7M2BNBsnqlDcmUYkWMczvmNo/mcyIF3vWJZ
ZdOgCNFdoHg2vwmhiKGfFaqezXUo1EQuHIqVmBceHwqhq1GcSRVT3bENivmb
v3Ef3YlH1bmi8IEa9cV/cBidGqMx1lCHiqWdBQoxQmVyPooglCE7PKIa6ZEb
DxhxP/kNommZwZaPiLELlhAHn/SkStMoPtkvU9EE98ZlbmgivVmUCaQRG5Zw
OYOcZIogpEEj6WQbp7ITL6ItT1Oj9jkQ/iuXnzNyQtqHjWlgp3fKEKtyI2mW
KDqUYQw4HCpTEEM5ofCHoJLgSADaqHh6FFWCI3ElFy+KqaWpqfZhgOhhLcny
np4pFFFXNi1KpQO0ctq2PYQnIJ8Kqo6qojyHIC/ygMSakfqQmEaFqKvxFc+i
ELDqq8YjH/eGb1MIoVFJoQk3G0oJrS6RaZrGFS/Sdohxd0PZTYmqO42QBLjE
rTWRKeNCAB9VqrZwDf7Bi0H1aJthkLPKriWRNAVTqdugDwaITWNngGooFdvK
ry8Br+NzYviITcaxGUk3ngrbM7cxQnjiDRBLHNuXd5ZgkM9asRzhro6hpj3U
iOhmPSErsh0hfxNNIAchuSSMVHOWhD8se3af6B8EQSpMtDMMerMkBxwgWZwE
ETebta9AWx5/Gj1eRVnB9bNJS3JQpaYplx69h5BR21fq9BRYGgm6gbRZCxTj
Any3kaaVGLZsEUIMazVHMUe9irZZQbJCMS5wq4WlsbJ1m7d6u7d827d++7dk
GRAAOw==
====
}

proc xth_incr_station_name {oname iii} {
  if {[regexp {^(\S+)(\@\S+)$} $oname dumm stname svname]} {
    set oname $stname
  } else {
    set svname {}
  }
  if {[regexp {^\d+$} $oname]} {
    incr oname $iii
    return "$oname$svname"
  } elseif {[regexp {^(.*\D)(\d+)$} $oname dumm s1 s2]} {
    incr s2 $iii
    return "$s1$s2$svname"
  } elseif {[regexp {^(\d+)(\D.*)$} $oname dumm s2 s1]} {
    incr s2 $iii
    return "$s2$s1$svname"
  } else {
    return "$oname$svname"
  }
}







# file generated automatically - do not modify!

  ::msgcat::mcset cz "Drag to resize control panel." [encoding convertfrom utf-8 "Zm\304\233nit \305\241\303\255\305\231ku panelu."]
  ::msgcat::mcset en "Drag to resize control panel." [encoding convertfrom utf-8 "Drag to resize control panel."]
  ::msgcat::mcset es "Drag to resize control panel." [encoding convertfrom utf-8 "Arrastar para cambiar el tama\303\261o del panel de control."]
  ::msgcat::mcset sk "Drag to resize control panel." [encoding convertfrom utf-8 "Roz\305\241\303\255ri\305\245 alebo z\303\272\305\276i\305\245 okno kontroln\303\275ch panelov."]

  ::msgcat::mcset cz "File" [encoding convertfrom utf-8 "Soubor"]
  ::msgcat::mcset en "File" [encoding convertfrom utf-8 "File"]
  ::msgcat::mcset es "File" [encoding convertfrom utf-8 "Archivo"]
  ::msgcat::mcset sk "File" [encoding convertfrom utf-8 "S\303\272bor"]

  ::msgcat::mcset cz "Maximize" [encoding convertfrom utf-8 "Maximalizovat"]
  ::msgcat::mcset en "Maximize" [encoding convertfrom utf-8 "Maximize"]
  ::msgcat::mcset es "Maximize" [encoding convertfrom utf-8 "Maximizar"]
  ::msgcat::mcset sk "Maximize" [encoding convertfrom utf-8 "Maximalizova\305\245"]

  ::msgcat::mcset cz "Normalize" [encoding convertfrom utf-8 "Norm\303\241ln\303\255 velikost"]
  ::msgcat::mcset en "Normalize" [encoding convertfrom utf-8 "Normalize"]
  ::msgcat::mcset es "Normalize" [encoding convertfrom utf-8 "Normalizar"]
  ::msgcat::mcset sk "Normalize" [encoding convertfrom utf-8 "Norm\303\241lna ve\304\276kos\305\245"]

  ::msgcat::mcset cz "Switch panels" [encoding convertfrom utf-8 "P\305\231eho\304\217 panely"]
  ::msgcat::mcset en "Switch panels" [encoding convertfrom utf-8 "Switch panels"]
  ::msgcat::mcset es "Switch panels" [encoding convertfrom utf-8 "Alternar paneles"]
  ::msgcat::mcset sk "Switch panels" [encoding convertfrom utf-8 "Preho\304\217 panely"]

  ::msgcat::mcset cz "KBD encoding" [encoding convertfrom utf-8 "K\303\263dov\303\241n\303\255 kl\303\241vesnice"]
  ::msgcat::mcset en "KBD encoding" [encoding convertfrom utf-8 "KBD encoding"]
  ::msgcat::mcset es "KBD encoding" [encoding convertfrom utf-8 "Codificaci\303\263n teclado"]
  ::msgcat::mcset sk "KBD encoding" [encoding convertfrom utf-8 "K\303\263dovanie kl\303\241vesnice"]

  ::msgcat::mcset cz "Window" [encoding convertfrom utf-8 "Okno"]
  ::msgcat::mcset en "Window" [encoding convertfrom utf-8 "Window"]
  ::msgcat::mcset es "Window" [encoding convertfrom utf-8 "Ventana"]
  ::msgcat::mcset sk "Window" [encoding convertfrom utf-8 "Okno"]

  ::msgcat::mcset cz "Quit" [encoding convertfrom utf-8 "Konec"]
  ::msgcat::mcset en "Quit" [encoding convertfrom utf-8 "Quit"]
  ::msgcat::mcset es "Quit" [encoding convertfrom utf-8 "Salir"]
  ::msgcat::mcset sk "Quit" [encoding convertfrom utf-8 "Ukon\304\215i\305\245"]

  ::msgcat::mcset cz "Help" [encoding convertfrom utf-8 "N\303\241pov\304\233da"]
  ::msgcat::mcset en "Help" [encoding convertfrom utf-8 "Help"]
  ::msgcat::mcset es "Help" [encoding convertfrom utf-8 "Ayuda"]
  ::msgcat::mcset sk "Help" [encoding convertfrom utf-8 "Pomoc"]

  ::msgcat::mcset cz "BAC calculator" [encoding convertfrom utf-8 "Alkohol tester"]
  ::msgcat::mcset en "BAC calculator" [encoding convertfrom utf-8 "BAC calculator"]
  ::msgcat::mcset es "BAC calculator" [encoding convertfrom utf-8 "Borrach\303\255metro"]
  ::msgcat::mcset sk "BAC calculator" [encoding convertfrom utf-8 "Alkohol tester"]

  ::msgcat::mcset cz "Biometric data" [encoding convertfrom utf-8 "Biometrick\303\251 \303\272daje"]
  ::msgcat::mcset en "Biometric data" [encoding convertfrom utf-8 "Biometric data"]
  ::msgcat::mcset es "Biometric data" [encoding convertfrom utf-8 "Datos biom\303\251tricos"]
  ::msgcat::mcset sk "Biometric data" [encoding convertfrom utf-8 "Biometrick\303\251 \303\272daje"]

  ::msgcat::mcset cz "age" [encoding convertfrom utf-8 "v\304\233k"]
  ::msgcat::mcset en "age" [encoding convertfrom utf-8 "age"]
  ::msgcat::mcset es "age" [encoding convertfrom utf-8 "edad"]
  ::msgcat::mcset sk "age" [encoding convertfrom utf-8 "vek"]

  ::msgcat::mcset cz "years" [encoding convertfrom utf-8 "let"]
  ::msgcat::mcset en "years" [encoding convertfrom utf-8 "years"]
  ::msgcat::mcset es "years" [encoding convertfrom utf-8 "a\303\261os"]
  ::msgcat::mcset sk "years" [encoding convertfrom utf-8 "rokov"]

  ::msgcat::mcset cz "gender" [encoding convertfrom utf-8 "pohlav\303\255"]
  ::msgcat::mcset en "gender" [encoding convertfrom utf-8 "gender"]
  ::msgcat::mcset es "gender" [encoding convertfrom utf-8 "sexo"]
  ::msgcat::mcset sk "gender" [encoding convertfrom utf-8 "pohlavie"]

  ::msgcat::mcset cz "male" [encoding convertfrom utf-8 "mu\305\276"]
  ::msgcat::mcset en "male" [encoding convertfrom utf-8 "male"]
  ::msgcat::mcset es "male" [encoding convertfrom utf-8 "hombre"]
  ::msgcat::mcset sk "male" [encoding convertfrom utf-8 "mu\305\276"]

  ::msgcat::mcset cz "female" [encoding convertfrom utf-8 "\305\276ena"]
  ::msgcat::mcset en "female" [encoding convertfrom utf-8 "female"]
  ::msgcat::mcset es "female" [encoding convertfrom utf-8 "mujer"]
  ::msgcat::mcset sk "female" [encoding convertfrom utf-8 "\305\276ena"]

  ::msgcat::mcset cz "height" [encoding convertfrom utf-8 "v\303\275\305\241ka"]
  ::msgcat::mcset en "height" [encoding convertfrom utf-8 "height"]
  ::msgcat::mcset es "height" [encoding convertfrom utf-8 "altura"]
  ::msgcat::mcset sk "height" [encoding convertfrom utf-8 "v\303\275\305\241ka"]

  ::msgcat::mcset cz "weight" [encoding convertfrom utf-8 "v\303\241ha"]
  ::msgcat::mcset en "weight" [encoding convertfrom utf-8 "weight"]
  ::msgcat::mcset es "weight" [encoding convertfrom utf-8 "peso"]
  ::msgcat::mcset sk "weight" [encoding convertfrom utf-8 "v\303\241ha"]

  ::msgcat::mcset cz "Consumption data" [encoding convertfrom utf-8 "\303\232daje o spot\305\231eb\304\233"]
  ::msgcat::mcset en "Consumption data" [encoding convertfrom utf-8 "Consumption data"]
  ::msgcat::mcset es "Consumption data" [encoding convertfrom utf-8 "Datos de ingesti\303\263n"]
  ::msgcat::mcset sk "Consumption data" [encoding convertfrom utf-8 "\303\232daje o spotrebe"]

  ::msgcat::mcset cz "volume" [encoding convertfrom utf-8 "objem"]
  ::msgcat::mcset en "volume" [encoding convertfrom utf-8 "volume"]
  ::msgcat::mcset es "volume" [encoding convertfrom utf-8 "volumen"]
  ::msgcat::mcset sk "volume" [encoding convertfrom utf-8 "objem"]

  ::msgcat::mcset cz "alcohol level" [encoding convertfrom utf-8 "koncentrace alkoholu"]
  ::msgcat::mcset en "alcohol level" [encoding convertfrom utf-8 "alcohol level"]
  ::msgcat::mcset es "alcohol level" [encoding convertfrom utf-8 "contenido alcoh\303\263lico"]
  ::msgcat::mcset sk "alcohol level" [encoding convertfrom utf-8 "koncentr\303\241cia"]

  ::msgcat::mcset cz "time elapsed" [encoding convertfrom utf-8 "uplynul\303\275 \304\215as"]
  ::msgcat::mcset en "time elapsed" [encoding convertfrom utf-8 "time elapsed"]
  ::msgcat::mcset es "time elapsed" [encoding convertfrom utf-8 "tiempo transcurrido"]
  ::msgcat::mcset sk "time elapsed" [encoding convertfrom utf-8 "uplynut\303\275 \304\215as"]

  ::msgcat::mcset cz "Calculate" [encoding convertfrom utf-8 "Vypo\304\215\303\255tat"]
  ::msgcat::mcset en "Calculate" [encoding convertfrom utf-8 "Calculate"]
  ::msgcat::mcset es "Calculate" [encoding convertfrom utf-8 "Calcular"]
  ::msgcat::mcset sk "Calculate" [encoding convertfrom utf-8 "Vypo\304\215\303\255ta\305\245"]

  ::msgcat::mcset cz "BAC" [encoding convertfrom utf-8 "Hladina alkoholu v krvi"]
  ::msgcat::mcset en "BAC" [encoding convertfrom utf-8 "BAC"]
  ::msgcat::mcset es "BAC" [encoding convertfrom utf-8 "tasa alcoholemia"]
  ::msgcat::mcset sk "BAC" [encoding convertfrom utf-8 "Hladina alkoholu"]

  ::msgcat::mcset cz "ETA" [encoding convertfrom utf-8 "\304\214as do vyst\305\231\303\255zliv\304\233n\303\255"]
  ::msgcat::mcset en "ETA" [encoding convertfrom utf-8 "ETA"]
  ::msgcat::mcset es "ETA" [encoding convertfrom utf-8 "TBE (Tiempo Bajada Estimado)"]
  ::msgcat::mcset sk "ETA" [encoding convertfrom utf-8 "\304\214as do vytriezvenia"]

  ::msgcat::mcset cz "hours" [encoding convertfrom utf-8 "hodin"]
  ::msgcat::mcset en "hours" [encoding convertfrom utf-8 "hours"]
  ::msgcat::mcset es "hours" [encoding convertfrom utf-8 "horas"]
  ::msgcat::mcset sk "hours" [encoding convertfrom utf-8 "hod\303\255n"]

  ::msgcat::mcset cz "MRR" [encoding convertfrom utf-8 "Rychlost odbour\303\241v\303\241n\303\255"]
  ::msgcat::mcset en "MRR" [encoding convertfrom utf-8 "MRR"]
  ::msgcat::mcset es "MRR" [encoding convertfrom utf-8 "tasa de descenso"]
  ::msgcat::mcset sk "MRR" [encoding convertfrom utf-8 "R\303\275chlos\305\245 odbur\303\241vania"]

  ::msgcat::mcset cz "Compiler" [encoding convertfrom utf-8 "Kompil\303\241tor"]
  ::msgcat::mcset en "Compiler" [encoding convertfrom utf-8 "Compiler"]
  ::msgcat::mcset es "Compiler" [encoding convertfrom utf-8 "Compilador"]
  ::msgcat::mcset sk "Compiler" [encoding convertfrom utf-8 "Kompil\303\241tor"]

  ::msgcat::mcset cz "Settings" [encoding convertfrom utf-8 "Nastaven\303\255"]
  ::msgcat::mcset en "Settings" [encoding convertfrom utf-8 "Settings"]
  ::msgcat::mcset es "Settings" [encoding convertfrom utf-8 "Ajustes"]
  ::msgcat::mcset sk "Settings" [encoding convertfrom utf-8 "Nastavenia"]

  ::msgcat::mcset cz "Survey structure" [encoding convertfrom utf-8 "Struktura m\304\233\305\231en\303\255 (survey)"]
  ::msgcat::mcset en "Survey structure" [encoding convertfrom utf-8 "Survey structure"]
  ::msgcat::mcset es "Survey structure" [encoding convertfrom utf-8 "Estructura de la poligonal"]
  ::msgcat::mcset sk "Survey structure" [encoding convertfrom utf-8 "\305\240trukt\303\272ra d\303\241t"]

  ::msgcat::mcset cz "Survey info" [encoding convertfrom utf-8 "Info o m\304\233\305\231en\303\255 (survey)"]
  ::msgcat::mcset en "Survey info" [encoding convertfrom utf-8 "Survey info"]
  ::msgcat::mcset es "Survey info" [encoding convertfrom utf-8 "Informaci\303\263n de la poligonal"]
  ::msgcat::mcset sk "Survey info" [encoding convertfrom utf-8 "Inform\303\241cie"]

  ::msgcat::mcset cz "Map structure" [encoding convertfrom utf-8 "Mapov\303\241 struktura"]
  ::msgcat::mcset en "Map structure" [encoding convertfrom utf-8 "Map structure"]
  ::msgcat::mcset es "Map structure" [encoding convertfrom utf-8 "Estructura del mapa"]
  ::msgcat::mcset sk "Map structure" [encoding convertfrom utf-8 "Mapov\303\241 \305\241trukt\303\272ra"]

  ::msgcat::mcset cz "Working directory" [encoding convertfrom utf-8 "Pracovn\303\255 adres\303\241\305\231"]
  ::msgcat::mcset en "Working directory" [encoding convertfrom utf-8 "Working directory"]
  ::msgcat::mcset es "Working directory" [encoding convertfrom utf-8 "Directorio actual"]
  ::msgcat::mcset sk "Working directory" [encoding convertfrom utf-8 "Pracovn\303\275 adres\303\241r"]

  ::msgcat::mcset cz "Working directory path." [encoding convertfrom utf-8 "Cesta k pracovn\303\255mu adres\303\241\305\231i."]
  ::msgcat::mcset en "Working directory path." [encoding convertfrom utf-8 "Shows working directory path."]
  ::msgcat::mcset es "Working directory path." [encoding convertfrom utf-8 "Muestra el directorio actual."]
  ::msgcat::mcset sk "Working directory path." [encoding convertfrom utf-8 "Cesta k pracovn\303\251mu adres\303\241ru."]

  ::msgcat::mcset cz "Configuration file" [encoding convertfrom utf-8 "Konfigura\304\215n\303\255 soubor"]
  ::msgcat::mcset en "Configuration file" [encoding convertfrom utf-8 "Configuration file"]
  ::msgcat::mcset es "Configuration file" [encoding convertfrom utf-8 "Archivo configuraci\303\263n"]
  ::msgcat::mcset sk "Configuration file" [encoding convertfrom utf-8 "Konfigura\304\215n\303\275 s\303\272bor"]

  ::msgcat::mcset cz "Configuration file name." [encoding convertfrom utf-8 "Jm\303\251no konfigura\304\215n\303\255ho souboru."]
  ::msgcat::mcset en "Configuration file name." [encoding convertfrom utf-8 "Shows configuration file name."]
  ::msgcat::mcset es "Configuration file name." [encoding convertfrom utf-8 "Muestra el nombre del archivo de configuraci\303\263n."]
  ::msgcat::mcset sk "Configuration file name." [encoding convertfrom utf-8 "Meno konfigura\304\215n\303\251ho s\303\272boru."]

  ::msgcat::mcset cz "Command line options" [encoding convertfrom utf-8 "Argumenty programu"]
  ::msgcat::mcset en "Command line options" [encoding convertfrom utf-8 "Command line options"]
  ::msgcat::mcset es "Command line options" [encoding convertfrom utf-8 "Opciones de l\303\255nea de comandos"]
  ::msgcat::mcset sk "Command line options" [encoding convertfrom utf-8 "Argumenty programu"]

  ::msgcat::mcset cz "Therion command line options." [encoding convertfrom utf-8 "Argumenty therionu pro p\305\231\303\255kazovou \305\231\303\241dku."]
  ::msgcat::mcset en "Therion command line options." [encoding convertfrom utf-8 "Here you can pass command line options to Therion."]
  ::msgcat::mcset es "Therion command line options." [encoding convertfrom utf-8 "Aqu\303\255 se pueden pasar a therion opciones de l\303\255nea de comandos"]
  ::msgcat::mcset sk "Therion command line options." [encoding convertfrom utf-8 "Argumenty programu v pr\303\255kazovom riadku."]

  ::msgcat::mcset cz "Compile" [encoding convertfrom utf-8 "Kompilovat"]
  ::msgcat::mcset en "Compile" [encoding convertfrom utf-8 "Compile"]
  ::msgcat::mcset es "Compile" [encoding convertfrom utf-8 "Compilar"]
  ::msgcat::mcset sk "Compile" [encoding convertfrom utf-8 "Kompilova\305\245"]

  ::msgcat::mcset cz "Run therion." [encoding convertfrom utf-8 "Spust\303\255 therion."]
  ::msgcat::mcset en "Run therion." [encoding convertfrom utf-8 "Run therion."]
  ::msgcat::mcset es "Run therion." [encoding convertfrom utf-8 "Ejecutar therion."]
  ::msgcat::mcset sk "Run therion." [encoding convertfrom utf-8 "Spusti\305\245 therion."]

  ::msgcat::mcset cz "Survey informations." [encoding convertfrom utf-8 "Informace o jednotliv\303\275ch m\304\233\305\231en\303\255ch (survey)."]
  ::msgcat::mcset en "Survey informations." [encoding convertfrom utf-8 "Survey informations."]
  ::msgcat::mcset es "Survey informations." [encoding convertfrom utf-8 "Estad\303\255sticas de la poligonal."]
  ::msgcat::mcset sk "Survey informations." [encoding convertfrom utf-8 "Inform\303\241cie o \304\215astiach."]

  ::msgcat::mcset en "User interface is not active. To activate it, open existing file or create new one." [encoding convertfrom utf-8 "User interface is not active. To activate it, open existing file or create new one."]
  ::msgcat::mcset es "User interface is not active. To activate it, open existing file or create new one." [encoding convertfrom utf-8 "El interfaz est\303\241 inactivo. Para activarlo, abre un archivo existente o crea uno nuevo."]
  ::msgcat::mcset sk "User interface is not active. To activate it, open existing file or create new one." [encoding convertfrom utf-8 "XTherion moment\303\241lne nie je akt\303\255vny. Otvorte existuj\303\272ci konfigura\304\215n\303\275 s\303\272bor alebo vytvorte nov\303\275."]

  ::msgcat::mcset cz "loading compiler..." [encoding convertfrom utf-8 "nahr\303\241v\303\241m kompil\303\241tor..."]
  ::msgcat::mcset en "loading compiler..." [encoding convertfrom utf-8 "loading compiler..."]
  ::msgcat::mcset es "loading compiler..." [encoding convertfrom utf-8 "compilador..."]
  ::msgcat::mcset sk "loading compiler..." [encoding convertfrom utf-8 "kompil\303\241tor..."]

  ::msgcat::mcset cz "Running therion ..." [encoding convertfrom utf-8 "Prob\303\255h\303\241 kompilace ..."]
  ::msgcat::mcset en "Running therion ..." [encoding convertfrom utf-8 "Running therion ..."]
  ::msgcat::mcset es "Running therion ..." [encoding convertfrom utf-8 "Ejecutando therion ..."]
  ::msgcat::mcset sk "Running therion ..." [encoding convertfrom utf-8 "Prebieha v\303\275po\304\215et..."]

  ::msgcat::mcset cz "RUNNING" [encoding convertfrom utf-8 "PRACUJI"]
  ::msgcat::mcset en "RUNNING" [encoding convertfrom utf-8 "RUNNING"]
  ::msgcat::mcset es "RUNNING" [encoding convertfrom utf-8 "EJECUTANDO"]
  ::msgcat::mcset sk "RUNNING" [encoding convertfrom utf-8 "V\303\235PO\304\214ET"]

  ::msgcat::mcset cz "ERROR" [encoding convertfrom utf-8 "CHYBA"]
  ::msgcat::mcset en "ERROR" [encoding convertfrom utf-8 "ERROR"]
  ::msgcat::mcset es "ERROR" [encoding convertfrom utf-8 "ERROR"]
  ::msgcat::mcset sk "ERROR" [encoding convertfrom utf-8 "CHYBA"]

  ::msgcat::mcset cz "OK" [encoding convertfrom utf-8 "OK"]
  ::msgcat::mcset en "OK" [encoding convertfrom utf-8 "OK"]
  ::msgcat::mcset es "OK" [encoding convertfrom utf-8 "OK"]
  ::msgcat::mcset sk "OK" [encoding convertfrom utf-8 "OK"]

  ::msgcat::mcset cz "Reading therion log file ..." [encoding convertfrom utf-8 "Na\304\215\303\255t\303\241m LOG soubor therionu ..."]
  ::msgcat::mcset en "Reading therion log file ..." [encoding convertfrom utf-8 "Reading therion log file ..."]
  ::msgcat::mcset es "Reading therion log file ..." [encoding convertfrom utf-8 "Leyendo archivo log ..."]
  ::msgcat::mcset sk "Reading therion log file ..." [encoding convertfrom utf-8 "Na\304\215it\303\241vam LOG s\303\272bor."]

  ::msgcat::mcset cz "\nerror opening therion.log file\n" [encoding convertfrom utf-8 "\nchyba p\305\231i otev\303\255r\303\241n\303\255 souboru therion.log\n"]
  ::msgcat::mcset en "\nerror opening therion.log file\n" [encoding convertfrom utf-8 "\nerror opening therion.log file\n"]
  ::msgcat::mcset es "\nerror opening therion.log file\n" [encoding convertfrom utf-8 "\nerror abriendo el archivo therion.log\n"]
  ::msgcat::mcset sk "\nerror opening therion.log file\n" [encoding convertfrom utf-8 "\nchyba pri \304\215\303\255tan\303\255 s\303\272boru therion.log\n"]

  ::msgcat::mcset cz "Show or hide this control panel" [encoding convertfrom utf-8 "Zobrazit/skr\303\275t ovl\303\241dac\303\255 panel"]
  ::msgcat::mcset en "Show or hide this control panel" [encoding convertfrom utf-8 "Click to show or hide this control panel."]
  ::msgcat::mcset es "Show or hide this control panel" [encoding convertfrom utf-8 "Clicar para mostrar u ocultar este panel de control"]
  ::msgcat::mcset sk "Show or hide this control panel" [encoding convertfrom utf-8 "Stla\304\215te ak chcete zobrazi\305\245 alebo skry\305\245 tento panel"]

  ::msgcat::mcset cz "loading map editor ..." [encoding convertfrom utf-8 "nahr\303\241v\303\241m mapov\303\275 editor..."]
  ::msgcat::mcset en "loading map editor ..." [encoding convertfrom utf-8 "loading map editor ..."]
  ::msgcat::mcset es "loading map editor ..." [encoding convertfrom utf-8 "editor de mapas..."]
  ::msgcat::mcset sk "loading map editor ..." [encoding convertfrom utf-8 "Mapov\303\275 editor"]

  ::msgcat::mcset cz "Undo %s" [encoding convertfrom utf-8 "Zp\304\233t - %s"]
  ::msgcat::mcset en "Undo %s" [encoding convertfrom utf-8 "Undo %s"]
  ::msgcat::mcset es "Undo %s" [encoding convertfrom utf-8 "Deshacer %s"]
  ::msgcat::mcset sk "Undo %s" [encoding convertfrom utf-8 "Sp\303\244\305\245 - %s"]

  ::msgcat::mcset cz "Redo %s" [encoding convertfrom utf-8 "Znovu - %s"]
  ::msgcat::mcset en "Redo %s" [encoding convertfrom utf-8 "Redo %s"]
  ::msgcat::mcset es "Redo %s" [encoding convertfrom utf-8 "Rehacer %s"]
  ::msgcat::mcset sk "Redo %s" [encoding convertfrom utf-8 "Opakova\305\245- %s"]

  ::msgcat::mcset cz "%s \[%s\] -- multiple encoding commands in file" [encoding convertfrom utf-8 "%s \[%s\] -- v\303\255cen\303\241sobn\303\275 v\303\275skyt p\305\231\303\255kazu encoding v jednom souboru"]
  ::msgcat::mcset en "%s \[%s\] -- multiple encoding commands in file" [encoding convertfrom utf-8 "%s \[%s\] -- multiple encoding commands in file"]
  ::msgcat::mcset es "%s \[%s\] -- multiple encoding commands in file" [encoding convertfrom utf-8 "%s \[%s\] -- m\303\272ltiples comandos de codificaci\303\263n en el archivo"]
  ::msgcat::mcset sk "%s \[%s\] -- multiple encoding commands in file" [encoding convertfrom utf-8 "%s \[%s\] -- viac encoding pr\303\255kazov v jednom s\303\272bore"]

  ::msgcat::mcset cz "%s \[%s\] -- unknown encoding -- %s" [encoding convertfrom utf-8 "%s \[%s\] -- nezn\303\241m\303\251 k\303\263dov\303\241n\303\255 znak\305\257 -- %s"]
  ::msgcat::mcset en "%s \[%s\] -- unknown encoding -- %s" [encoding convertfrom utf-8 "%s \[%s\] -- unknown encoding -- %s"]
  ::msgcat::mcset es "%s \[%s\] -- unknown encoding -- %s" [encoding convertfrom utf-8 "%s \[%s\] -- codificaci\303\263n desconocida -- %s"]
  ::msgcat::mcset sk "%s \[%s\] -- unknown encoding -- %s" [encoding convertfrom utf-8 "%s \[%s\] -- nezn\303\241me k\303\263dovanie znakov -- %s"]

  ::msgcat::mcset cz "adjusting area" [encoding convertfrom utf-8 "p\305\231izp\305\257soben\303\255 pracovn\303\255 plochy"]
  ::msgcat::mcset en "adjusting area" [encoding convertfrom utf-8 "adjusting area"]
  ::msgcat::mcset es "adjusting area" [encoding convertfrom utf-8 "ajustando \303\241rea"]
  ::msgcat::mcset sk "adjusting area" [encoding convertfrom utf-8 "prisp\303\264sobenie pracovnej plochy"]

  ::msgcat::mcset cz "zooming" [encoding convertfrom utf-8 "zoomov\303\241n\303\255"]
  ::msgcat::mcset en "zooming" [encoding convertfrom utf-8 "zooming"]
  ::msgcat::mcset es "zooming" [encoding convertfrom utf-8 "zooming"]
  ::msgcat::mcset sk "zooming" [encoding convertfrom utf-8 "zoomovanie"]

  ::msgcat::mcset cz "Zoom %d %%" [encoding convertfrom utf-8 "Zoom %d %%"]
  ::msgcat::mcset en "Zoom %d %%" [encoding convertfrom utf-8 "Zoom %d %%"]
  ::msgcat::mcset es "Zoom %d %%" [encoding convertfrom utf-8 "Zoom %d %%"]
  ::msgcat::mcset sk "Zoom %d %%" [encoding convertfrom utf-8 "Zoom %d %%"]

  ::msgcat::mcset cz "Zooming objects ..." [encoding convertfrom utf-8 "Zoomov\303\241n\303\255 objekt\305\257 ..."]
  ::msgcat::mcset en "Zooming objects ..." [encoding convertfrom utf-8 "Zooming objects ..."]
  ::msgcat::mcset es "Zooming objects ..." [encoding convertfrom utf-8 "Zoom sobre objetos ..."]
  ::msgcat::mcset sk "Zooming objects ..." [encoding convertfrom utf-8 "Zoomovanie objektov ..."]

  ::msgcat::mcset cz "dragging image" [encoding convertfrom utf-8 "p\305\231esouv\303\241n\303\255 obr\303\241zku"]
  ::msgcat::mcset en "dragging image" [encoding convertfrom utf-8 "dragging image"]
  ::msgcat::mcset es "dragging image" [encoding convertfrom utf-8 "arrastrando imagen"]
  ::msgcat::mcset sk "dragging image" [encoding convertfrom utf-8 "Pres\303\272vanie obr\303\241zku"]

  ::msgcat::mcset cz "Map Editor" [encoding convertfrom utf-8 "Mapov\303\275 editor"]
  ::msgcat::mcset en "Map Editor" [encoding convertfrom utf-8 "Map Editor"]
  ::msgcat::mcset es "Map Editor" [encoding convertfrom utf-8 "Editor de mapas"]
  ::msgcat::mcset sk "Map Editor" [encoding convertfrom utf-8 "Mapov\303\275 Editor"]

  ::msgcat::mcset cz "File commands" [encoding convertfrom utf-8 "P\305\231\303\255kazy"]
  ::msgcat::mcset en "File commands" [encoding convertfrom utf-8 "Objects"]
  ::msgcat::mcset es "File commands" [encoding convertfrom utf-8 "Objetos"]
  ::msgcat::mcset sk "File commands" [encoding convertfrom utf-8 "Pr\303\255kazy v s\303\272bore"]

  ::msgcat::mcset cz "Search & Select" [encoding convertfrom utf-8 "Naj\303\255t & Vybrat"]
  ::msgcat::mcset en "Search & Select" [encoding convertfrom utf-8 "Search & Select"]
  ::msgcat::mcset es "Search & Select" [encoding convertfrom utf-8 "Buscar y Seleccionar"]
  ::msgcat::mcset sk "Search & Select" [encoding convertfrom utf-8 "H\304\276adaj a Vyber"]

  ::msgcat::mcset cz "Command preview" [encoding convertfrom utf-8 "N\303\241hled p\305\231\303\255kazu"]
  ::msgcat::mcset en "Command preview" [encoding convertfrom utf-8 "Command preview"]
  ::msgcat::mcset es "Command preview" [encoding convertfrom utf-8 "Ver comandos"]
  ::msgcat::mcset sk "Command preview" [encoding convertfrom utf-8 "N\303\241h\304\276ad pr\303\255kazu"]

  ::msgcat::mcset cz "Point control" [encoding convertfrom utf-8 "Bod"]
  ::msgcat::mcset en "Point control" [encoding convertfrom utf-8 "Points"]
  ::msgcat::mcset es "Point control" [encoding convertfrom utf-8 "Puntos"]
  ::msgcat::mcset sk "Point control" [encoding convertfrom utf-8 "Bod"]

  ::msgcat::mcset cz "Line control" [encoding convertfrom utf-8 "K\305\231ivka"]
  ::msgcat::mcset en "Line control" [encoding convertfrom utf-8 "Lines"]
  ::msgcat::mcset es "Line control" [encoding convertfrom utf-8 "L\303\255neas"]
  ::msgcat::mcset sk "Line control" [encoding convertfrom utf-8 "Krivka"]

  ::msgcat::mcset cz "Line point control" [encoding convertfrom utf-8 "Bod k\305\231ivky"]
  ::msgcat::mcset en "Line point control" [encoding convertfrom utf-8 "Line points"]
  ::msgcat::mcset es "Line point control" [encoding convertfrom utf-8 "Puntos de l\303\255nea"]
  ::msgcat::mcset sk "Line point control" [encoding convertfrom utf-8 "Bod krivky"]

  ::msgcat::mcset cz "Area control" [encoding convertfrom utf-8 "Oblast"]
  ::msgcat::mcset en "Area control" [encoding convertfrom utf-8 "Areas"]
  ::msgcat::mcset es "Area control" [encoding convertfrom utf-8 "Areas"]
  ::msgcat::mcset sk "Area control" [encoding convertfrom utf-8 "Plocha"]

  ::msgcat::mcset cz "Scrap control" [encoding convertfrom utf-8 "Scrap"]
  ::msgcat::mcset en "Scrap control" [encoding convertfrom utf-8 "Scraps"]
  ::msgcat::mcset es "Scrap control" [encoding convertfrom utf-8 "Croquis"]
  ::msgcat::mcset sk "Scrap control" [encoding convertfrom utf-8 "Scrap"]

  ::msgcat::mcset cz "Text editor" [encoding convertfrom utf-8 "Textov\303\275 editor"]
  ::msgcat::mcset en "Text editor" [encoding convertfrom utf-8 "Text editor"]
  ::msgcat::mcset es "Text editor" [encoding convertfrom utf-8 "Editor de texto"]
  ::msgcat::mcset sk "Text editor" [encoding convertfrom utf-8 "Textov\303\275 editor"]

  ::msgcat::mcset cz "Drawing area" [encoding convertfrom utf-8 "Kresl\303\255c\303\255 plocha"]
  ::msgcat::mcset en "Drawing area" [encoding convertfrom utf-8 "Drawing area"]
  ::msgcat::mcset es "Drawing area" [encoding convertfrom utf-8 "Area de dibujo"]
  ::msgcat::mcset sk "Drawing area" [encoding convertfrom utf-8 "Pracovn\303\241 plocha"]

  ::msgcat::mcset cz "Background images" [encoding convertfrom utf-8 "Podkladov\303\251 obr\303\241zky"]
  ::msgcat::mcset en "Background images" [encoding convertfrom utf-8 "Background images"]
  ::msgcat::mcset es "Background images" [encoding convertfrom utf-8 "Im\303\241genes de fondo"]
  ::msgcat::mcset sk "Background images" [encoding convertfrom utf-8 "Obr\303\241zky pozadia"]

  ::msgcat::mcset cz "Current drawing area." [encoding convertfrom utf-8 "Sou\304\215asn\303\241 kresl\303\255c\303\255 plocha."]
  ::msgcat::mcset en "Current drawing area." [encoding convertfrom utf-8 "Current drawing area."]
  ::msgcat::mcset es "Current drawing area." [encoding convertfrom utf-8 "Area de dibujo actual."]
  ::msgcat::mcset sk "Current drawing area." [encoding convertfrom utf-8 "S\303\272\304\215asn\303\241 pracovn\303\241 plocha."]

  ::msgcat::mcset cz "X min." [encoding convertfrom utf-8 "X min."]
  ::msgcat::mcset en "X min." [encoding convertfrom utf-8 "X min."]
  ::msgcat::mcset es "X min." [encoding convertfrom utf-8 "X min"]
  ::msgcat::mcset sk "X min." [encoding convertfrom utf-8 "Minimum X."]

  ::msgcat::mcset cz "Y min." [encoding convertfrom utf-8 "Y min."]
  ::msgcat::mcset en "Y min." [encoding convertfrom utf-8 "Y min."]
  ::msgcat::mcset es "Y min." [encoding convertfrom utf-8 "Y min"]
  ::msgcat::mcset sk "Y min." [encoding convertfrom utf-8 "Minimum Y."]

  ::msgcat::mcset cz "X max." [encoding convertfrom utf-8 "X max."]
  ::msgcat::mcset en "X max." [encoding convertfrom utf-8 "X max."]
  ::msgcat::mcset es "X max." [encoding convertfrom utf-8 "X max"]
  ::msgcat::mcset sk "X max." [encoding convertfrom utf-8 "Maximum X."]

  ::msgcat::mcset cz "Y max." [encoding convertfrom utf-8 "Y max."]
  ::msgcat::mcset en "Y max." [encoding convertfrom utf-8 "Y max."]
  ::msgcat::mcset es "Y max." [encoding convertfrom utf-8 "Y max"]
  ::msgcat::mcset sk "Y max." [encoding convertfrom utf-8 "Maximum Y."]

  ::msgcat::mcset cz "Adjust" [encoding convertfrom utf-8 "P\305\231izp\305\257sobit"]
  ::msgcat::mcset en "Adjust" [encoding convertfrom utf-8 "Adjust"]
  ::msgcat::mcset es "Adjust" [encoding convertfrom utf-8 "Ajustar"]
  ::msgcat::mcset sk "Adjust" [encoding convertfrom utf-8 "Prisp\303\264sob"]

  ::msgcat::mcset cz "Adjust drawing area to given limits." [encoding convertfrom utf-8 "P\305\231izp\305\257sob\303\255 kresl\303\255c\303\255 plochu dan\303\275m limit\305\257m."]
  ::msgcat::mcset en "Adjust drawing area to given limits." [encoding convertfrom utf-8 "Adjust drawing area to given limits."]
  ::msgcat::mcset es "Adjust drawing area to given limits." [encoding convertfrom utf-8 "Ajustar el \303\241rea de dibujo a los l\303\255mites indicados."]
  ::msgcat::mcset sk "Adjust drawing area to given limits." [encoding convertfrom utf-8 "Prisp\303\264sobi\305\245 pracovn\303\272 plochu dan\303\275m limitom."]

  ::msgcat::mcset cz "Auto adjust" [encoding convertfrom utf-8 "Auto p\305\231izp\305\257s."]
  ::msgcat::mcset en "Auto adjust" [encoding convertfrom utf-8 "Auto adjust"]
  ::msgcat::mcset es "Auto adjust" [encoding convertfrom utf-8 "Autoajustar"]
  ::msgcat::mcset sk "Auto adjust" [encoding convertfrom utf-8 "Automaticky"]

  ::msgcat::mcset cz "Adjust drawing area to automatically calculated limits." [encoding convertfrom utf-8 "Automaticky p\305\231izp\305\257sob\303\255 kresl\303\255c\303\255 plochu v\305\241em objekt\305\257m."]
  ::msgcat::mcset en "Adjust drawing area to automatically calculated limits." [encoding convertfrom utf-8 "Adjust drawing area to automatically calculated limits."]
  ::msgcat::mcset es "Adjust drawing area to automatically calculated limits." [encoding convertfrom utf-8 "Ajustar \303\241rea de dibujo autom\303\241ticamente."]
  ::msgcat::mcset sk "Adjust drawing area to automatically calculated limits." [encoding convertfrom utf-8 "Automaticky prisp\303\264sobi\305\245 pracovn\303\272 plochu v\305\241etk\303\275m objektom."]

  ::msgcat::mcset cz "zoom" [encoding convertfrom utf-8 "zoom"]
  ::msgcat::mcset en "zoom" [encoding convertfrom utf-8 "zoom"]
  ::msgcat::mcset es "zoom" [encoding convertfrom utf-8 "zoom"]
  ::msgcat::mcset sk "zoom" [encoding convertfrom utf-8 "zoom"]

  ::msgcat::mcset cz "Zoom drawing area." [encoding convertfrom utf-8 "Zoom kresl\303\255c\303\255 plochy."]
  ::msgcat::mcset en "Zoom drawing area." [encoding convertfrom utf-8 "Zoom control. Click on rectangle to see menu."]
  ::msgcat::mcset es "Zoom drawing area." [encoding convertfrom utf-8 "Control del zoom. Clic en rect\303\241ngulo para ver men\303\272."]
  ::msgcat::mcset sk "Zoom drawing area." [encoding convertfrom utf-8 "Zoom pracovnej plochy."]

  ::msgcat::mcset cz "loading commands module ..." [encoding convertfrom utf-8 "nahr\303\241v\303\241m p\305\231\303\255kazov\303\275 modul ..."]
  ::msgcat::mcset en "loading commands module ..." [encoding convertfrom utf-8 "loading commands module ..."]
  ::msgcat::mcset es "loading commands module ..." [encoding convertfrom utf-8 "comandos ..."]
  ::msgcat::mcset sk "loading commands module ..." [encoding convertfrom utf-8 "pr\303\255kazov\303\275 modul..."]

  ::msgcat::mcset cz "Select command." [encoding convertfrom utf-8 "V\303\275b\304\233r p\305\231\303\255kazu."]
  ::msgcat::mcset en "Select command." [encoding convertfrom utf-8 "Click a line to get corresponding object selected on canvas or vice versa."]
  ::msgcat::mcset es "Select command." [encoding convertfrom utf-8 "Al clicar una de las l\303\255neas, se resaltar\303\241 en la topo el objeto correspondiente, y viceversa."]
  ::msgcat::mcset sk "Select command." [encoding convertfrom utf-8 "Vyber pr\303\255kaz."]

  ::msgcat::mcset cz "Action button." [encoding convertfrom utf-8 "Tla\304\215\303\255tko Akce."]
  ::msgcat::mcset en "Action button." [encoding convertfrom utf-8 "After clicking this button, you can insert objects by mouse. Click on action to see menu."]
  ::msgcat::mcset es "Action button." [encoding convertfrom utf-8 "Tras pulsar este bot\303\263n, se pueden insertar con el rat\303\263n puntos, lineas, etc. Clic en acci\303\263n para ver men\303\272."]
  ::msgcat::mcset sk "Action button." [encoding convertfrom utf-8 "Gomb\303\255k - akcia."]

  ::msgcat::mcset cz "Switch mouse mode to select objects." [encoding convertfrom utf-8 "P\305\231epnut\303\255 my\305\241i do v\303\275b\304\233rov\303\251ho m\303\263du."]
  ::msgcat::mcset en "Switch mouse mode to select objects." [encoding convertfrom utf-8 "After clicking this button, you can select objects on canvas by mouse."]
  ::msgcat::mcset es "Switch mouse mode to select objects." [encoding convertfrom utf-8 "Tras clicar aqu\303\255, podr\303\241s seleccionar cosas en la topo con el rat\303\263n."]
  ::msgcat::mcset sk "Switch mouse mode to select objects." [encoding convertfrom utf-8 "Nastav m\303\263d my\305\241i na vyberanie objektov."]

  ::msgcat::mcset cz "Action" [encoding convertfrom utf-8 "Akce"]
  ::msgcat::mcset en "Action" [encoding convertfrom utf-8 "Action"]
  ::msgcat::mcset es "Action" [encoding convertfrom utf-8 "Acci\303\263n"]
  ::msgcat::mcset sk "Action" [encoding convertfrom utf-8 "Akcia"]

  ::msgcat::mcset cz "Configure action assigned to action button." [encoding convertfrom utf-8 "Nastav\303\255 akci pro tla\304\215\303\255tko akc\303\255."]
  ::msgcat::mcset en "Configure action assigned to action button." [encoding convertfrom utf-8 "Action you choose will be executed by clicking on Insert <object> button."]
  ::msgcat::mcset es "Configure action assigned to action button." [encoding convertfrom utf-8 "Clic para ver men\303\272. La acci\303\263n que escojas ser\303\241 la que ejecute el bot\303\263n Insertar <objeto>"]
  ::msgcat::mcset sk "Configure action assigned to action button." [encoding convertfrom utf-8 "Nakonfiguruj akciu pre gomb\303\255k - akcia."]

  ::msgcat::mcset cz "Move up" [encoding convertfrom utf-8 "P\305\231esun v\303\275\305\241"]
  ::msgcat::mcset en "Move up" [encoding convertfrom utf-8 "Move up"]
  ::msgcat::mcset es "Move up" [encoding convertfrom utf-8 "Arriba"]
  ::msgcat::mcset sk "Move up" [encoding convertfrom utf-8 "Presu\305\210 vy\305\241\305\241ie"]

  ::msgcat::mcset cz "Move file command up in the list." [encoding convertfrom utf-8 "P\305\231esune p\305\231\303\255kaz v\303\275\305\241 v seznamu p\305\231\303\255kaz\305\257."]
  ::msgcat::mcset en "Move file command up in the list." [encoding convertfrom utf-8 "Move object up in the list. Use if object is in wrong scrap."]
  ::msgcat::mcset es "Move file command up in the list." [encoding convertfrom utf-8 "Desplaza el objeto hacia arriba en la lista. Usar si el objeto est\303\241 en lugar err\303\263neo."]
  ::msgcat::mcset sk "Move file command up in the list." [encoding convertfrom utf-8 "Presu\305\210 pr\303\255kaz vy\305\241\305\241ie v zozname pr\303\255kazov."]

  ::msgcat::mcset cz "Move down" [encoding convertfrom utf-8 "P\305\231esun n\303\255\305\276"]
  ::msgcat::mcset en "Move down" [encoding convertfrom utf-8 "Move down"]
  ::msgcat::mcset es "Move down" [encoding convertfrom utf-8 "Abajo"]
  ::msgcat::mcset sk "Move down" [encoding convertfrom utf-8 "Presu\305\210 ni\305\276\305\241ie"]

  ::msgcat::mcset cz "Move file command down in the list." [encoding convertfrom utf-8 "P\305\231esune p\305\231\303\255kaz n\303\255\305\276 v seznamu p\305\231\303\255kaz\305\257."]
  ::msgcat::mcset en "Move file command down in the list." [encoding convertfrom utf-8 "Move object down in the list. Use if object is in wrong scrap."]
  ::msgcat::mcset es "Move file command down in the list." [encoding convertfrom utf-8 "Desplaza el objeto hacia abajo en la lista. Usar si el objeto est\303\241 en lugar err\303\263neo."]
  ::msgcat::mcset sk "Move file command down in the list." [encoding convertfrom utf-8 "Presu\305\210 pr\303\255kaz ni\305\276\305\241ie v zozname pr\303\255kazov."]

  ::msgcat::mcset cz "Move file command to given position." [encoding convertfrom utf-8 "P\305\231esunout p\305\231\303\255kaz na danou pozici v seznamu."]
  ::msgcat::mcset en "Move file command to given position." [encoding convertfrom utf-8 "Move object to given position (position = number on each line)."]
  ::msgcat::mcset es "Move file command to given position." [encoding convertfrom utf-8 "Mover el objeto a la posici\303\263n indicada (n\303\272mero al principio de cada l\303\255nea)."]
  ::msgcat::mcset sk "Move file command to given position." [encoding convertfrom utf-8 "Presu\305\210 pr\303\255kaz na dan\303\272 poz\303\255ciu v zozname."]

  ::msgcat::mcset cz "Select destination scrap and position in it." [encoding convertfrom utf-8 "V\303\275b\304\233r c\303\255lov\303\251ho scrapu a pozice v n\304\233m."]
  ::msgcat::mcset en "Select destination scrap and position in it." [encoding convertfrom utf-8 "Select destination scrap and position in it."]
  ::msgcat::mcset es "Select destination scrap and position in it." [encoding convertfrom utf-8 "Seleccionar croquis de destino y la posici\303\263n en \303\251l."]
  ::msgcat::mcset sk "Select destination scrap and position in it." [encoding convertfrom utf-8 "Nastav cie\304\276ov\303\275 scrap a poz\303\255ciu v \305\210om."]

  ::msgcat::mcset cz "Update text" [encoding convertfrom utf-8 "Aktualizovat"]
  ::msgcat::mcset en "Update text" [encoding convertfrom utf-8 "Update text"]
  ::msgcat::mcset es "Update text" [encoding convertfrom utf-8 "Actualizar texto"]
  ::msgcat::mcset sk "Update text" [encoding convertfrom utf-8 "Aktualizuj text"]

  ::msgcat::mcset cz "Press this button to save code you have written." [encoding convertfrom utf-8 "Stiskn\304\233te toto tla\304\215\303\255tko pro ulo\305\276en\303\255 V\303\241mi zapsan\303\251ho k\303\263du."]
  ::msgcat::mcset en "Press this button to save code you have written." [encoding convertfrom utf-8 "Press this button to save code you have written."]
  ::msgcat::mcset es "Press this button to save code you have written." [encoding convertfrom utf-8 "Clicar aqu\303\255 para guardar los cambios hechos en el c\303\263digo."]
  ::msgcat::mcset sk "Press this button to save code you have written." [encoding convertfrom utf-8 "Stla\304\215te toto tla\304\215\303\255tko pre ulo\305\276enie Vami zap\303\255san\303\251ho k\303\263du."]

  ::msgcat::mcset cz "Editor for free text in therion 2D file." [encoding convertfrom utf-8 "Editor pro text ve 2D souborech."]
  ::msgcat::mcset en "Editor for free text in therion 2D file." [encoding convertfrom utf-8 "Use this editor window to modify .th2 files."]
  ::msgcat::mcset es "Editor for free text in therion 2D file." [encoding convertfrom utf-8 "Usa este editor para modificar los archivos .th2. Otros editores dar\303\241n problemas."]
  ::msgcat::mcset sk "Editor for free text in therion 2D file." [encoding convertfrom utf-8 "Editor pre \305\241peci\303\241lne pr\303\255kazy v 2D s\303\272boroch."]

  ::msgcat::mcset cz "expression" [encoding convertfrom utf-8 "v\303\275raz"]
  ::msgcat::mcset en "expression" [encoding convertfrom utf-8 "search for"]
  ::msgcat::mcset es "expression" [encoding convertfrom utf-8 "buscar"]
  ::msgcat::mcset sk "expression" [encoding convertfrom utf-8 "v\303\275raz"]

  ::msgcat::mcset cz "Enter search expression." [encoding convertfrom utf-8 "Vlo\305\276te hledan\303\275 v\303\275raz."]
  ::msgcat::mcset en "Enter search expression." [encoding convertfrom utf-8 "Enter word(s) to search for."]
  ::msgcat::mcset es "Enter search expression." [encoding convertfrom utf-8 "Introducir palabra(s) a buscar."]
  ::msgcat::mcset sk "Enter search expression." [encoding convertfrom utf-8 "Vlo\305\276te h\304\276adan\303\275 v\303\275raz."]

  ::msgcat::mcset cz "regular expression" [encoding convertfrom utf-8 "regul\303\241rn\303\255 v\303\275raz"]
  ::msgcat::mcset en "regular expression" [encoding convertfrom utf-8 "regular expression"]
  ::msgcat::mcset es "regular expression" [encoding convertfrom utf-8 "patr\303\263n regular (kob.*)"]
  ::msgcat::mcset sk "regular expression" [encoding convertfrom utf-8 "regul\303\241rny v\303\275raz"]

  ::msgcat::mcset cz "Search for regular expression." [encoding convertfrom utf-8 "Vyhled\303\241v\303\241n\303\255 regul\303\241rn\303\255ho v\303\275razu."]
  ::msgcat::mcset en "Search for regular expression." [encoding convertfrom utf-8 "Use wildcards on search (cav.* will find cave, cavern, cavalier...)"]
  ::msgcat::mcset es "Search for regular expression." [encoding convertfrom utf-8 "Usar comodines en la b\303\272squeda (kob.* encuentra koba, kobea, kobie, etc)."]
  ::msgcat::mcset sk "Search for regular expression." [encoding convertfrom utf-8 "Vyh\304\276ad\303\241vanie regul\303\241rneho v\303\275razu."]

  ::msgcat::mcset cz "case sensitive" [encoding convertfrom utf-8 "rozli\305\241ovat velikost p\303\255smen"]
  ::msgcat::mcset en "case sensitive" [encoding convertfrom utf-8 "case sensitive"]
  ::msgcat::mcset es "case sensitive" [encoding convertfrom utf-8 "distinguir may\303\272sculas"]
  ::msgcat::mcset sk "case sensitive" [encoding convertfrom utf-8 "rozli\305\241ova\305\245 ve\304\276kos\305\245"]

  ::msgcat::mcset cz "Case sensitive search." [encoding convertfrom utf-8 "Vyhled\303\241v\303\241n\303\255 s rozli\305\241en\303\255m velikosti p\303\255smen."]
  ::msgcat::mcset en "Case sensitive search." [encoding convertfrom utf-8 "Case sensitive search."]
  ::msgcat::mcset es "Case sensitive search." [encoding convertfrom utf-8 "B\303\272squeda sensible a las may\303\272sculas."]
  ::msgcat::mcset sk "Case sensitive search." [encoding convertfrom utf-8 "Vyh\304\276ad\303\241vanie s rozli\305\241ovan\303\255m ve\304\276k\303\275ch a mal\303\275ch p\303\255smen."]

  ::msgcat::mcset cz "Find next" [encoding convertfrom utf-8 "Naj\303\255t dal\305\241\303\255"]
  ::msgcat::mcset en "Find next" [encoding convertfrom utf-8 "Find next"]
  ::msgcat::mcset es "Find next" [encoding convertfrom utf-8 "Siguiente"]
  ::msgcat::mcset sk "Find next" [encoding convertfrom utf-8 "Nasleduj\303\272ci"]

  ::msgcat::mcset cz "Select next object matching expression." [encoding convertfrom utf-8 "Vybere dal\305\241\303\255 objekt odpov\303\255daj\303\255c\303\255 v\303\275razu."]
  ::msgcat::mcset en "Select next object matching expression." [encoding convertfrom utf-8 "Select next object matching expression."]
  ::msgcat::mcset es "Select next object matching expression." [encoding convertfrom utf-8 "Selecionar siguiente objeto encontrado."]
  ::msgcat::mcset sk "Select next object matching expression." [encoding convertfrom utf-8 "N\303\241jdi \304\217al\305\241\303\255 objekt zodpovedaj\303\272ci h\304\276adan\303\251mu v\303\275razu."]

  ::msgcat::mcset cz "Find first" [encoding convertfrom utf-8 "Naj\303\255t prvn\303\255"]
  ::msgcat::mcset en "Find first" [encoding convertfrom utf-8 "Search"]
  ::msgcat::mcset es "Find first" [encoding convertfrom utf-8 "Buscar"]
  ::msgcat::mcset sk "Find first" [encoding convertfrom utf-8 "N\303\241jdi prv\303\275"]

  ::msgcat::mcset cz "Select first object matching expression." [encoding convertfrom utf-8 "Vybere prvn\303\255 objekt odpov\303\255daj\303\255c\303\255 v\303\275razu."]
  ::msgcat::mcset en "Select first object matching expression." [encoding convertfrom utf-8 "Selects first object matching expression."]
  ::msgcat::mcset es "Select first object matching expression." [encoding convertfrom utf-8 "Selecionar el primer objeto encontrado."]
  ::msgcat::mcset sk "Select first object matching expression." [encoding convertfrom utf-8 "N\303\241jdi prv\303\275 objekt zodpovedaj\303\272ci h\304\276adan\303\251mu v\303\275razu."]

  ::msgcat::mcset cz "Show all" [encoding convertfrom utf-8 "Zobrazit v\305\241e"]
  ::msgcat::mcset en "Show all" [encoding convertfrom utf-8 "Show all"]
  ::msgcat::mcset es "Show all" [encoding convertfrom utf-8 "Mostrar todo"]
  ::msgcat::mcset sk "Show all" [encoding convertfrom utf-8 "Ozna\304\215 v\305\241etky"]

  ::msgcat::mcset cz "Highlight all objects matching expression." [encoding convertfrom utf-8 "Zv\303\275razn\303\255 v\305\241echny objekty odpov\303\255daj\303\255c\303\255 v\303\275razu."]
  ::msgcat::mcset en "Highlight all objects matching expression." [encoding convertfrom utf-8 "Highlight all objects matching expression."]
  ::msgcat::mcset es "Highlight all objects matching expression." [encoding convertfrom utf-8 "Seleccionar todos los objetos encontrados."]
  ::msgcat::mcset sk "Highlight all objects matching expression." [encoding convertfrom utf-8 "Zv\303\275razn\303\255 v\305\241etky objekty zodpovedaj\303\272ce h\304\276adan\303\251mu v\303\275razu."]

  ::msgcat::mcset cz "Clear all" [encoding convertfrom utf-8 "Zru\305\241 v\303\275b\304\233r"]
  ::msgcat::mcset en "Clear all" [encoding convertfrom utf-8 "Clear all"]
  ::msgcat::mcset es "Clear all" [encoding convertfrom utf-8 "Deseleccionar"]
  ::msgcat::mcset sk "Clear all" [encoding convertfrom utf-8 "Zru\305\241 v\303\275ber"]

  ::msgcat::mcset cz "Clear highlighted objects." [encoding convertfrom utf-8 "Zru\305\241\303\255 zv\303\275razn\304\233n\303\255 vybran\303\275ch objekt\305\257."]
  ::msgcat::mcset en "Clear highlighted objects." [encoding convertfrom utf-8 "Clear highlighted objects."]
  ::msgcat::mcset es "Clear highlighted objects." [encoding convertfrom utf-8 "Deseleccionar todos los objetos resaltados."]
  ::msgcat::mcset sk "Clear highlighted objects." [encoding convertfrom utf-8 "Zru\305\241\303\255 zv\303\275raznenie vybrat\303\275ch objektov."]

  ::msgcat::mcset cz "loading images module ..." [encoding convertfrom utf-8 "nahr\303\241v\303\241m obr\303\241zkov\303\275 modul ..."]
  ::msgcat::mcset en "loading images module ..." [encoding convertfrom utf-8 "loading images module ..."]
  ::msgcat::mcset es "loading images module ..." [encoding convertfrom utf-8 "im\303\241genes ..."]
  ::msgcat::mcset sk "loading images module ..." [encoding convertfrom utf-8 "nahr\303\241vam obr\303\241zkov\303\275 modul..."]

  ::msgcat::mcset cz "Select background image." [encoding convertfrom utf-8 "V\303\275b\304\233r podkladov\303\251ho obr\303\241zku."]
  ::msgcat::mcset en "Select background image." [encoding convertfrom utf-8 "Click on a line in the list to select correspondin image."]
  ::msgcat::mcset es "Select background image." [encoding convertfrom utf-8 "Al clicar un rengl\303\263n, seleccionar\303\241s la imagen de fondo correspondiente."]
  ::msgcat::mcset sk "Select background image." [encoding convertfrom utf-8 "Ozna\304\215 obr\303\241zok na pozad\303\255."]

  ::msgcat::mcset cz "Insert new background image." [encoding convertfrom utf-8 "Vlo\305\276en\303\255 nov\303\251ho podkladov\303\251ho obr\303\241zku."]
  ::msgcat::mcset en "Insert new background image." [encoding convertfrom utf-8 "Insert new background image (e.g., .xvi image or scanned sketch)."]
  ::msgcat::mcset es "Insert new background image." [encoding convertfrom utf-8 "Insertar nueva imagen de fondo (p. ej: un croquis escaneado de la libreta topo)."]
  ::msgcat::mcset sk "Insert new background image." [encoding convertfrom utf-8 "Vlo\305\276enie nov\303\251ho podkladov\303\251ho obr\303\241zku."]

  ::msgcat::mcset cz "Remove" [encoding convertfrom utf-8 "Odstranit"]
  ::msgcat::mcset en "Remove" [encoding convertfrom utf-8 "Remove"]
  ::msgcat::mcset es "Remove" [encoding convertfrom utf-8 "Eliminar"]
  ::msgcat::mcset sk "Remove" [encoding convertfrom utf-8 "Odstr\303\241ni\305\245"]

  ::msgcat::mcset cz "Remove selected image." [encoding convertfrom utf-8 "Odstran\303\255 vybran\303\275 obr\303\241zek."]
  ::msgcat::mcset en "Remove selected image." [encoding convertfrom utf-8 "Remove selected image."]
  ::msgcat::mcset es "Remove selected image." [encoding convertfrom utf-8 "Eliminar imagen seleccionada."]
  ::msgcat::mcset sk "Remove selected image." [encoding convertfrom utf-8 "Odstr\303\241ni ozna\304\215en\303\275 obr\303\241zok."]

  ::msgcat::mcset cz "visibility" [encoding convertfrom utf-8 "viditelnost"]
  ::msgcat::mcset en "visibility" [encoding convertfrom utf-8 "visibility"]
  ::msgcat::mcset es "visibility" [encoding convertfrom utf-8 "visibilidad"]
  ::msgcat::mcset sk "visibility" [encoding convertfrom utf-8 "vidite\304\276nos\305\245"]

  ::msgcat::mcset cz "Switch image visibility." [encoding convertfrom utf-8 "P\305\231ep\303\255n\303\241 viditelnost obr\303\241zku."]
  ::msgcat::mcset en "Switch image visibility." [encoding convertfrom utf-8 "Switch image visibility."]
  ::msgcat::mcset es "Switch image visibility." [encoding convertfrom utf-8 "Cambiar visibilidad de la imagen."]
  ::msgcat::mcset sk "Switch image visibility." [encoding convertfrom utf-8 "Prep\303\255na\304\215 vidite\304\276nosti obr\303\241zku."]

  ::msgcat::mcset cz "Control gamma value." [encoding convertfrom utf-8 "Nastaven\303\255 hodnoty gamma."]
  ::msgcat::mcset en "Control gamma value." [encoding convertfrom utf-8 "Control gamma value."]
  ::msgcat::mcset es "Control gamma value." [encoding convertfrom utf-8 "Controlar el valor gamma."]
  ::msgcat::mcset sk "Control gamma value." [encoding convertfrom utf-8 "Nastavenie gamma korekcie obr\303\241zku (farebn\303\251ho podania)."]

  ::msgcat::mcset cz "Reset" [encoding convertfrom utf-8 "Reset"]
  ::msgcat::mcset en "Reset" [encoding convertfrom utf-8 "Reset"]
  ::msgcat::mcset es "Reset" [encoding convertfrom utf-8 "Reajustar"]
  ::msgcat::mcset sk "Reset" [encoding convertfrom utf-8 "Reset"]

  ::msgcat::mcset cz "Reset image gamma value." [encoding convertfrom utf-8 "Resetuje nastavenou hodnotu gamma."]
  ::msgcat::mcset en "Reset image gamma value." [encoding convertfrom utf-8 "Click here to go back to original gamma value."]
  ::msgcat::mcset es "Reset image gamma value." [encoding convertfrom utf-8 "Click aqu\303\255 para volver a los ajustes de gamma iniciales."]
  ::msgcat::mcset sk "Reset image gamma value." [encoding convertfrom utf-8 "Resetuje nastaven\303\272 gamma korekciu obr\303\241zku."]

  ::msgcat::mcset cz "Set image gamma value." [encoding convertfrom utf-8 "Nastavuje hodnotu gamma obr\303\241zku."]
  ::msgcat::mcset en "Set image gamma value." [encoding convertfrom utf-8 "Set image gamma value."]
  ::msgcat::mcset es "Set image gamma value." [encoding convertfrom utf-8 "Ajustar valor gamma de la imagen."]
  ::msgcat::mcset sk "Set image gamma value." [encoding convertfrom utf-8 "Nastavuje gamma korekciu obr\303\241zku."]

  ::msgcat::mcset cz "Current position of selected image." [encoding convertfrom utf-8 "Sou\304\215asn\303\241 pozice vybran\303\251ho obr\303\241zku."]
  ::msgcat::mcset en "Current position of selected image." [encoding convertfrom utf-8 "Current position of selected image (pixels from canvas lower letf corner)."]
  ::msgcat::mcset es "Current position of selected image." [encoding convertfrom utf-8 "Posici\303\263n actual de la imagen seleccionada (medida en pixels desde la esquina inf. izq del lienzo)."]
  ::msgcat::mcset sk "Current position of selected image." [encoding convertfrom utf-8 "S\303\272\304\215asn\303\241 poz\303\255cia obr\303\241zku."]

  ::msgcat::mcset cz "Move to" [encoding convertfrom utf-8 "P\305\231esunout"]
  ::msgcat::mcset en "Move to" [encoding convertfrom utf-8 "Move to"]
  ::msgcat::mcset es "Move to" [encoding convertfrom utf-8 "Mover a"]
  ::msgcat::mcset sk "Move to" [encoding convertfrom utf-8 "Presu\305\210 na"]

  ::msgcat::mcset cz "Move image to given position." [encoding convertfrom utf-8 "P\305\231esune obr\303\241zek na zadanou pozici."]
  ::msgcat::mcset en "Move image to given position." [encoding convertfrom utf-8 "Move image to given position (image's upper left corner will be on given pixel)."]
  ::msgcat::mcset es "Move image to given position." [encoding convertfrom utf-8 "Mover imagen a la posici\303\263n indicada (la esquina sup. izda de la imagen aparecer\303\241 en ese pixel)."]
  ::msgcat::mcset sk "Move image to given position." [encoding convertfrom utf-8 "Presunie obr\303\241zok na zadan\303\272 poz\303\255ciu."]

  ::msgcat::mcset cz "New X coordinate of image." [encoding convertfrom utf-8 "Nov\303\241 sou\305\231adnice X obr\303\241zku."]
  ::msgcat::mcset en "New X coordinate of image." [encoding convertfrom utf-8 "New X coordinate of image."]
  ::msgcat::mcset es "New X coordinate of image." [encoding convertfrom utf-8 "Nueva coordenada X de la imagen."]
  ::msgcat::mcset sk "New X coordinate of image." [encoding convertfrom utf-8 "Nov\303\241 X s\303\272radnica obr\303\241zku."]

  ::msgcat::mcset cz "New Y coordinate of image." [encoding convertfrom utf-8 "Nov\303\241 sou\305\231adnice Y obr\303\241zku."]
  ::msgcat::mcset en "New Y coordinate of image." [encoding convertfrom utf-8 "New Y coordinate of image."]
  ::msgcat::mcset es "New Y coordinate of image." [encoding convertfrom utf-8 "Nueva coordenada Y de la imagen."]
  ::msgcat::mcset sk "New Y coordinate of image." [encoding convertfrom utf-8 "Nov\303\275 Y s\303\272radnica obr\303\241zku."]

  ::msgcat::mcset cz "Move front" [encoding convertfrom utf-8 "Dop\305\231edu"]
  ::msgcat::mcset en "Move front" [encoding convertfrom utf-8 "Move front"]
  ::msgcat::mcset es "Move front" [encoding convertfrom utf-8 "Delante"]
  ::msgcat::mcset sk "Move front" [encoding convertfrom utf-8 "Navrch"]

  ::msgcat::mcset cz "Move image in front of all images." [encoding convertfrom utf-8 "P\305\231esune obr\303\241zek nad v\305\241echny ostatn\303\255."]
  ::msgcat::mcset en "Move image in front of all images." [encoding convertfrom utf-8 "Move image in front of all images."]
  ::msgcat::mcset es "Move image in front of all images." [encoding convertfrom utf-8 "Trae la imagen al frente de todas las im\303\241genes."]
  ::msgcat::mcset sk "Move image in front of all images." [encoding convertfrom utf-8 "Presunie obr\303\241zok nad v\305\241etky ostatn\303\251."]

  ::msgcat::mcset cz "Move back" [encoding convertfrom utf-8 "Dozadu"]
  ::msgcat::mcset en "Move back" [encoding convertfrom utf-8 "Move back"]
  ::msgcat::mcset es "Move back" [encoding convertfrom utf-8 "Detr\303\241s"]
  ::msgcat::mcset sk "Move back" [encoding convertfrom utf-8 "Naspodok"]

  ::msgcat::mcset cz "Move image behind all images." [encoding convertfrom utf-8 "P\305\231esune obr\303\241zek pod v\305\241echny ostatn\303\255."]
  ::msgcat::mcset en "Move image behind all images." [encoding convertfrom utf-8 "Move image behind all images."]
  ::msgcat::mcset es "Move image behind all images." [encoding convertfrom utf-8 "Enviar la imagen detr\303\241s de todas las dem\303\241s."]
  ::msgcat::mcset sk "Move image behind all images." [encoding convertfrom utf-8 "Presunie obr\303\241zok pod v\305\241etky ostatn\303\251."]

  ::msgcat::mcset cz "loading preview module ..." [encoding convertfrom utf-8 "nahr\303\241v\303\241m zobrazovac\303\255 modul ..."]
  ::msgcat::mcset en "loading preview module ..." [encoding convertfrom utf-8 "loading preview module ..."]
  ::msgcat::mcset es "loading preview module ..." [encoding convertfrom utf-8 "ver comandos ..."]
  ::msgcat::mcset sk "loading preview module ..." [encoding convertfrom utf-8 "nahr\303\241vam n\303\241h\304\276adov\303\275 modul ..."]

  ::msgcat::mcset cz "Update command" [encoding convertfrom utf-8 "Aktualizovat"]
  ::msgcat::mcset en "Update command" [encoding convertfrom utf-8 "Update command"]
  ::msgcat::mcset es "Update command" [encoding convertfrom utf-8 "Actualizar"]
  ::msgcat::mcset sk "Update command" [encoding convertfrom utf-8 "Aktualizova\305\245"]

  ::msgcat::mcset cz "Press this button, if you have changed something and you can not see your changes here." [encoding convertfrom utf-8 "Stiskn\304\233te toto tla\304\215\303\255tko, pokud jste n\304\233co zm\304\233nili a zm\304\233ny nejsou v tomto okn\304\233 viditeln\303\251."]
  ::msgcat::mcset en "Press this button, if you have changed something and you can not see your changes here." [encoding convertfrom utf-8 "Press this button, if you have changed something and you can not see your changes here."]
  ::msgcat::mcset es "Press this button, if you have changed something and you can not see your changes here." [encoding convertfrom utf-8 "Clicar aqu\303\255 si has cambiado algo y no ves aqu\303\255 los resultados del cambio"]
  ::msgcat::mcset sk "Press this button, if you have changed something and you can not see your changes here." [encoding convertfrom utf-8 "Stla\304\215te toto tla\304\215\303\255tko, ak ste nie\304\215o zmenili a zmeny nie su v tomto okne vidite\304\276n\303\251."]

  ::msgcat::mcset cz "Command preview." [encoding convertfrom utf-8 "N\303\241hled p\305\231\303\255kazu."]
  ::msgcat::mcset en "Command preview." [encoding convertfrom utf-8 "Here you can see complete commands with options applied."]
  ::msgcat::mcset es "Command preview." [encoding convertfrom utf-8 "Aqu\303\255 se pueden ver los comandos completos, opciones inclu\303\255das."]
  ::msgcat::mcset sk "Command preview." [encoding convertfrom utf-8 "N\303\241h\304\276ad pr\303\255kazu."]

  ::msgcat::mcset cz "loading scrap module ..." [encoding convertfrom utf-8 "nahr\303\241v\303\241m scrap modul ..."]
  ::msgcat::mcset en "loading scrap module ..." [encoding convertfrom utf-8 "loading scrap module ..."]
  ::msgcat::mcset es "loading scrap module ..." [encoding convertfrom utf-8 "croquis ..."]
  ::msgcat::mcset sk "loading scrap module ..." [encoding convertfrom utf-8 "nahr\303\241vam scrap modul ..."]

  ::msgcat::mcset cz "Scrap name." [encoding convertfrom utf-8 "N\303\241zev scrapu."]
  ::msgcat::mcset en "Scrap name." [encoding convertfrom utf-8 "Scrap name."]
  ::msgcat::mcset es "Scrap name." [encoding convertfrom utf-8 "Nombre del croquis."]
  ::msgcat::mcset sk "Scrap name." [encoding convertfrom utf-8 "Identifik\303\241tor (meno) scrapu."]

  ::msgcat::mcset cz "projection" [encoding convertfrom utf-8 "projekce"]
  ::msgcat::mcset en "projection" [encoding convertfrom utf-8 "projection"]
  ::msgcat::mcset es "projection" [encoding convertfrom utf-8 "proyecci\303\263n"]
  ::msgcat::mcset sk "projection" [encoding convertfrom utf-8 "projekcia"]

  ::msgcat::mcset cz "Scrap projection." [encoding convertfrom utf-8 "Projekce scrapu."]
  ::msgcat::mcset en "Scrap projection." [encoding convertfrom utf-8 "Scrap projection (clic on triangle to see menu)."]
  ::msgcat::mcset es "Scrap projection." [encoding convertfrom utf-8 "Proyecci\303\263n del croquis (Clic en tri\303\241ngulo para ver el men\303\272)."]
  ::msgcat::mcset sk "Scrap projection." [encoding convertfrom utf-8 "Projekcia scrapu."]

  ::msgcat::mcset cz "Other scrap options." [encoding convertfrom utf-8 "Dal\305\241\303\255 volby pro scrap."]
  ::msgcat::mcset en "Other scrap options." [encoding convertfrom utf-8 "Other scrap options (more on this on thbook.pdf)"]
  ::msgcat::mcset es "Other scrap options." [encoding convertfrom utf-8 "Otras opciones del croquis. Consultar thbook.pdf"]
  ::msgcat::mcset sk "Other scrap options." [encoding convertfrom utf-8 "Ostatn\303\251 mo\305\276nosti scrapu."]

  ::msgcat::mcset cz "scale" [encoding convertfrom utf-8 "m\304\233\305\231\303\255tko"]
  ::msgcat::mcset en "scale" [encoding convertfrom utf-8 "scale"]
  ::msgcat::mcset es "scale" [encoding convertfrom utf-8 "escala"]
  ::msgcat::mcset sk "scale" [encoding convertfrom utf-8 "mierka"]

  ::msgcat::mcset cz "Scrap scale definition." [encoding convertfrom utf-8 "Nastaven\303\255 m\304\233\305\231\303\255tka scrapu."]
  ::msgcat::mcset en "Scrap scale definition." [encoding convertfrom utf-8 "Scrap scale definition."]
  ::msgcat::mcset es "Scrap scale definition." [encoding convertfrom utf-8 "Definir la escala del croquis."]
  ::msgcat::mcset sk "Scrap scale definition." [encoding convertfrom utf-8 "Nastavenie mierky scrapu."]

  ::msgcat::mcset cz "Update scrap" [encoding convertfrom utf-8 "Aktualizovat"]
  ::msgcat::mcset en "Update scrap" [encoding convertfrom utf-8 "Update scrap"]
  ::msgcat::mcset es "Update scrap" [encoding convertfrom utf-8 "Actualizar"]
  ::msgcat::mcset sk "Update scrap" [encoding convertfrom utf-8 "Aktualizuj scrap"]

  ::msgcat::mcset cz "Press this button to apply your changes to current scrap." [encoding convertfrom utf-8 "Stiskn\304\233te toto tla\304\215\303\255tko po uplatn\304\233n\303\255 zm\304\233n aktu\303\241ln\303\255ho scrapu."]
  ::msgcat::mcset en "Press this button to apply your changes to current scrap." [encoding convertfrom utf-8 "Press this button to apply your changes to current scrap."]
  ::msgcat::mcset es "Press this button to apply your changes to current scrap." [encoding convertfrom utf-8 "Clicar aqu\303\255 tras modificar las propiedades del croquis."]
  ::msgcat::mcset sk "Press this button to apply your changes to current scrap." [encoding convertfrom utf-8 "Stla\304\215te tento gomb\303\255k, aby sa va\305\241e zmeny v scrape ulo\305\276ili."]

  ::msgcat::mcset cz "picture scale points" [encoding convertfrom utf-8 "body m\304\233\305\231\303\255tka (obr\303\241zek)"]
  ::msgcat::mcset en "picture scale points" [encoding convertfrom utf-8 "picture scale points pixels)"]
  ::msgcat::mcset es "picture scale points" [encoding convertfrom utf-8 "puntos de escala (pixels)"]
  ::msgcat::mcset sk "picture scale points" [encoding convertfrom utf-8 "kalibra\304\215n\303\251 body (obrazovka)"]

  ::msgcat::mcset cz "Calibration points on the picture (X1:Y1 - X2:Y2)." [encoding convertfrom utf-8 "Kalibra\304\215n\303\255 body na obr\303\241zku (X1:Y1 - X2:Y2)."]
  ::msgcat::mcset en "Calibration points on the picture (X1:Y1 - X2:Y2)." [encoding convertfrom utf-8 "Calibration points on the picture (X1:Y1 - X2:Y2)."]
  ::msgcat::mcset es "Calibration points on the picture (X1:Y1 - X2:Y2)." [encoding convertfrom utf-8 "Puntos de calibraci\303\263n en la imagen (X1:Y1 - X2:Y2)."]
  ::msgcat::mcset sk "Calibration points on the picture (X1:Y1 - X2:Y2)." [encoding convertfrom utf-8 "S\303\272radnice kalibra\304\215n\303\275ch bodov na obrazovke (X1:Y1 - X2:Y2)"]

  ::msgcat::mcset cz "X1 picture." [encoding convertfrom utf-8 "X1 obr\303\241zek."]
  ::msgcat::mcset en "X1 picture." [encoding convertfrom utf-8 "X1 picture."]
  ::msgcat::mcset es "X1 picture." [encoding convertfrom utf-8 "Punto de escala X1 en la imagen."]
  ::msgcat::mcset sk "X1 picture." [encoding convertfrom utf-8 "X1 na obr\303\241zku."]

  ::msgcat::mcset cz "Y1 picture." [encoding convertfrom utf-8 "Y1 obr\303\241zek."]
  ::msgcat::mcset en "Y1 picture." [encoding convertfrom utf-8 "Y1 picture."]
  ::msgcat::mcset es "Y1 picture." [encoding convertfrom utf-8 "Punto de escala Y1 en la imagen."]
  ::msgcat::mcset sk "Y1 picture." [encoding convertfrom utf-8 "Y1 na obr\303\241zku."]

  ::msgcat::mcset cz "X2 picture." [encoding convertfrom utf-8 "X2 obr\303\241zek."]
  ::msgcat::mcset en "X2 picture." [encoding convertfrom utf-8 "X2 picture."]
  ::msgcat::mcset es "X2 picture." [encoding convertfrom utf-8 "Punto de escala X2 en la imagen."]
  ::msgcat::mcset sk "X2 picture." [encoding convertfrom utf-8 "X2 na obr\303\241zku."]

  ::msgcat::mcset cz "Y2 picture." [encoding convertfrom utf-8 "Y2 obr\303\241zek."]
  ::msgcat::mcset en "Y2 picture." [encoding convertfrom utf-8 "Y2 picture."]
  ::msgcat::mcset es "Y2 picture." [encoding convertfrom utf-8 "Punto de escala Y2 en la imagen."]
  ::msgcat::mcset sk "Y2 picture." [encoding convertfrom utf-8 "Y2 na obr\303\241zku."]

  ::msgcat::mcset cz "real scale points" [encoding convertfrom utf-8 "body m\304\233\305\231\303\255tka (skute\304\215n\303\251)"]
  ::msgcat::mcset en "real scale points" [encoding convertfrom utf-8 "real scale points"]
  ::msgcat::mcset es "real scale points" [encoding convertfrom utf-8 "puntos de escala (reales)"]
  ::msgcat::mcset sk "real scale points" [encoding convertfrom utf-8 "kalibra\304\215n\303\251 body (skuto\304\215n\303\251)"]

  ::msgcat::mcset cz "Real coordinates of calibration points (X1:Y1 - X2:Y2)." [encoding convertfrom utf-8 "Skute\304\215n\303\251 sou\305\231adnice kalibra\304\215n\303\255ch bod\305\257 (X1:Y1 - X2:Y2)."]
  ::msgcat::mcset en "Real coordinates of calibration points (X1:Y1 - X2:Y2)." [encoding convertfrom utf-8 "Real coordinates of calibration points (X1:Y1 - X2:Y2)."]
  ::msgcat::mcset es "Real coordinates of calibration points (X1:Y1 - X2:Y2)." [encoding convertfrom utf-8 "Coordenadas reales de los puntos de calibraci\303\263n (X1:Y1 - X2:Y2)."]
  ::msgcat::mcset sk "Real coordinates of calibration points (X1:Y1 - X2:Y2)." [encoding convertfrom utf-8 "Skuto\304\215n\303\251 s\303\272radnice kalibra\304\215n\303\275ch bodov (X1:Y1 - X2:Y2)."]

  ::msgcat::mcset cz "X1 real." [encoding convertfrom utf-8 "X1 skute\304\215n\303\275."]
  ::msgcat::mcset en "X1 real." [encoding convertfrom utf-8 "X1 real."]
  ::msgcat::mcset es "X1 real." [encoding convertfrom utf-8 "X1 real"]
  ::msgcat::mcset sk "X1 real." [encoding convertfrom utf-8 "X1 skuto\304\215n\303\275"]

  ::msgcat::mcset cz "Y1 real." [encoding convertfrom utf-8 "Y1 skute\304\215n\303\275."]
  ::msgcat::mcset en "Y1 real." [encoding convertfrom utf-8 "Y1 real."]
  ::msgcat::mcset es "Y1 real." [encoding convertfrom utf-8 "Y1 real"]
  ::msgcat::mcset sk "Y1 real." [encoding convertfrom utf-8 "Y1 skuto\304\215n\303\275"]

  ::msgcat::mcset cz "X2 real." [encoding convertfrom utf-8 "X2 skute\304\215n\303\275."]
  ::msgcat::mcset en "X2 real." [encoding convertfrom utf-8 "X2 real."]
  ::msgcat::mcset es "X2 real." [encoding convertfrom utf-8 "X2 real"]
  ::msgcat::mcset sk "X2 real." [encoding convertfrom utf-8 "X2 skuto\304\215n\303\275"]

  ::msgcat::mcset cz "Y2 real." [encoding convertfrom utf-8 "Y2 skute\304\215n\303\275."]
  ::msgcat::mcset en "Y2 real." [encoding convertfrom utf-8 "Y2 real."]
  ::msgcat::mcset es "Y2 real." [encoding convertfrom utf-8 "Y2 real"]
  ::msgcat::mcset sk "Y2 real." [encoding convertfrom utf-8 "Y2 skuto\304\215n\303\275"]

  ::msgcat::mcset cz "units" [encoding convertfrom utf-8 "jednotky"]
  ::msgcat::mcset en "units" [encoding convertfrom utf-8 "units"]
  ::msgcat::mcset es "units" [encoding convertfrom utf-8 "unidades"]
  ::msgcat::mcset sk "units" [encoding convertfrom utf-8 "jednotky"]

  ::msgcat::mcset cz "Units of real coordinates." [encoding convertfrom utf-8 "Jednotky re\303\241ln\303\275ch sou\305\231adnic."]
  ::msgcat::mcset en "Units of real coordinates." [encoding convertfrom utf-8 "Units of real coordinates."]
  ::msgcat::mcset es "Units of real coordinates." [encoding convertfrom utf-8 "Unidades de las coordenadas reales."]
  ::msgcat::mcset sk "Units of real coordinates." [encoding convertfrom utf-8 "Jednotky re\303\241lnych s\303\272radn\303\255c."]

  ::msgcat::mcset cz "loading point module ..." [encoding convertfrom utf-8 "nahr\303\241v\303\241m point modul ..."]
  ::msgcat::mcset en "loading point module ..." [encoding convertfrom utf-8 "loading point module ..."]
  ::msgcat::mcset es "loading point module ..." [encoding convertfrom utf-8 "puntos ..."]
  ::msgcat::mcset sk "loading point module ..." [encoding convertfrom utf-8 "nahr\303\241vam editor bodov ..."]

  ::msgcat::mcset cz "Update point" [encoding convertfrom utf-8 "Aktualizovat"]
  ::msgcat::mcset en "Update point" [encoding convertfrom utf-8 "Update point"]
  ::msgcat::mcset es "Update point" [encoding convertfrom utf-8 "Actualizar"]
  ::msgcat::mcset sk "Update point" [encoding convertfrom utf-8 "Akualizuj bod"]

  ::msgcat::mcset cz "Click this button to apply point changes." [encoding convertfrom utf-8 "Aktualizuje data t\303\275kaj\303\255c\303\255 se bodu."]
  ::msgcat::mcset en "Click this button to apply point changes." [encoding convertfrom utf-8 "Click this button to apply point changes."]
  ::msgcat::mcset es "Click this button to apply point changes." [encoding convertfrom utf-8 "Clicar aqu\303\255 tras modificar las propiedades del punto."]
  ::msgcat::mcset sk "Click this button to apply point changes." [encoding convertfrom utf-8 "Stla\304\215te aby sa aktualizovali zmenen\303\251 \303\272daje bodu."]

  ::msgcat::mcset cz "Point type." [encoding convertfrom utf-8 "Typ bodu."]
  ::msgcat::mcset en "Point type." [encoding convertfrom utf-8 "Point type (click on triangle to see menu)."]
  ::msgcat::mcset es "Point type." [encoding convertfrom utf-8 "Tipo de punto. Clic en tri\303\241ngulo para ver men\303\272"]
  ::msgcat::mcset sk "Point type." [encoding convertfrom utf-8 "Typ bodu."]

  ::msgcat::mcset cz "Point identifier." [encoding convertfrom utf-8 "Identifik\303\241tor bodu."]
  ::msgcat::mcset en "Point identifier." [encoding convertfrom utf-8 "Point identifier."]
  ::msgcat::mcset es "Point identifier." [encoding convertfrom utf-8 "Nombre (ID) del punto."]
  ::msgcat::mcset sk "Point identifier." [encoding convertfrom utf-8 "Identifik\303\241tor bodu."]

  ::msgcat::mcset cz "Other point options." [encoding convertfrom utf-8 "Dal\305\241\303\255 volby pro bod."]
  ::msgcat::mcset en "Other point options." [encoding convertfrom utf-8 "Options allow giving special characteristics to points."]
  ::msgcat::mcset es "Other point options." [encoding convertfrom utf-8 "Las opciones permiten dar caracter\303\255sticas especiales a los puntos."]
  ::msgcat::mcset sk "Other point options." [encoding convertfrom utf-8 "Ostatn\303\251 \305\241pecifik\303\241cie bodu."]

  ::msgcat::mcset cz "I.e, if type is label, write here: -text \042this will be displayed (P100)\042" [encoding convertfrom utf-8 "P\305\231\303\255klad: pokud type je label, zadejte: -text \042this will be displayed (P100)\042"]
  ::msgcat::mcset en "I.e, if type is label, write here: -text \042this will be displayed (P100)\042" [encoding convertfrom utf-8 "I.e, if type is label, write here: -text \042this will be displayed (P100)\042"]
  ::msgcat::mcset es "I.e, if type is label, write here: -text \042this will be displayed (P100)\042" [encoding convertfrom utf-8 "P.ej, si el tipo es label, escribe: -text \042lo que se ver\303\241 (P100)\042."]
  ::msgcat::mcset sk "I.e, if type is label, write here: -text \042this will be displayed (P100)\042" [encoding convertfrom utf-8 "Pr\303\255klad: ak je typ label, zadajte: -text \042tento text bude zobrazen\303\275\042"]

  ::msgcat::mcset cz "Enter symbol orientation angle." [encoding convertfrom utf-8 "Zadejte orientaci bodu."]
  ::msgcat::mcset en "Enter symbol orientation angle." [encoding convertfrom utf-8 "Enter symbol orientation angle."]
  ::msgcat::mcset es "Enter symbol orientation angle." [encoding convertfrom utf-8 "Introducir direcci\303\263n en que debe apuntar el s\303\255mbolo."]
  ::msgcat::mcset sk "Enter symbol orientation angle." [encoding convertfrom utf-8 "Zadajte orient\303\241ciu bodu."]

  ::msgcat::mcset cz "There are symbol types which must be orientated (i.e: gradients). Click here to giv'em orientation by mouse or keyboard." [encoding convertfrom utf-8 "Jsou symboly, kter\303\275m mus\303\255te specifikovat orientaci (nap\305\231. gradient). Zaklikn\304\233te tuto volbu a nastavte jim orientaci my\305\241\303\255 nebo z kl\303\241vesnice."]
  ::msgcat::mcset en "There are symbol types which must be orientated (i.e: gradients). Click here to giv'em orientation by mouse or keyboard." [encoding convertfrom utf-8 "Some symbol types must be orientated (i.e: gradients). Click here to giv'em orientation by mouse or keyboard."]
  ::msgcat::mcset es "There are symbol types which must be orientated (i.e: gradients). Click here to giv'em orientation by mouse or keyboard." [encoding convertfrom utf-8 "Hay tipos de s\303\255mbolo que deben ser orientados (p.ej, pendientes). Haz clic aqu\303\255 para orientarlos con rat\303\263n o teclado."]
  ::msgcat::mcset sk "There are symbol types which must be orientated (i.e: gradients). Click here to giv'em orientation by mouse or keyboard." [encoding convertfrom utf-8 "S\303\272 symboly, ktor\303\275m treba zada\305\245 orient\303\241ciu (napr. gradiet). Ozna\304\215te t\303\272to vo\304\276bu a nastavte orient\303\241ciu my\305\241ou alebo z kl\303\241vesnice."]

  ::msgcat::mcset cz "x-size" [encoding convertfrom utf-8 "x-rozsah"]
  ::msgcat::mcset en "x-size" [encoding convertfrom utf-8 "x-size"]
  ::msgcat::mcset es "x-size" [encoding convertfrom utf-8 "tama\303\261o-x"]
  ::msgcat::mcset sk "x-size" [encoding convertfrom utf-8 "ve\304\276kos\305\245-x"]

  ::msgcat::mcset cz "Set point size in main direction." [encoding convertfrom utf-8 "Nastav\303\255 rozsah bodu v hlavn\303\255m sm\304\233ru."]
  ::msgcat::mcset en "Set point size in main direction." [encoding convertfrom utf-8 "Set point size in main direction."]
  ::msgcat::mcset es "Set point size in main direction." [encoding convertfrom utf-8 "Ajustar tama\303\261o del punto en direcci\303\263n principal."]
  ::msgcat::mcset sk "Set point size in main direction." [encoding convertfrom utf-8 "Nastavte ve\304\276kos\305\245 bodu v hlavnom (X) smere."]

  ::msgcat::mcset cz "Enter point size in main direction." [encoding convertfrom utf-8 "Zadejte rozsah bodu v hlavn\303\255m sm\304\233ru."]
  ::msgcat::mcset en "Enter point size in main direction." [encoding convertfrom utf-8 "Enter point size in main direction."]
  ::msgcat::mcset es "Enter point size in main direction." [encoding convertfrom utf-8 "Introducir tama\303\261o del punto en direcci\303\263n principal."]
  ::msgcat::mcset sk "Enter point size in main direction." [encoding convertfrom utf-8 "Zadajte ve\304\276kos\305\245 bodu v hlavnom (X) smere."]

  ::msgcat::mcset cz "y-size" [encoding convertfrom utf-8 "y-rozsah"]
  ::msgcat::mcset en "y-size" [encoding convertfrom utf-8 "y-size"]
  ::msgcat::mcset es "y-size" [encoding convertfrom utf-8 "tama\303\261o-y"]
  ::msgcat::mcset sk "y-size" [encoding convertfrom utf-8 "ve\304\276kos\305\245-y"]

  ::msgcat::mcset cz "Set point size in side direction." [encoding convertfrom utf-8 "Nastav\303\255 rozsah bodu ve vedlej\305\241\303\255m sm\304\233ru."]
  ::msgcat::mcset en "Set point size in side direction." [encoding convertfrom utf-8 "Set point size in side direction."]
  ::msgcat::mcset es "Set point size in side direction." [encoding convertfrom utf-8 "Ajustar tama\303\261o del punto en direcci\303\263n lateral."]
  ::msgcat::mcset sk "Set point size in side direction." [encoding convertfrom utf-8 "Nastavte ve\304\276kos\305\245 bodu vo ved\304\276aj\305\241om smere."]

  ::msgcat::mcset cz "Enter point size in side direction." [encoding convertfrom utf-8 "Zadejte rozsah bodu ve vedlej\305\241\303\255m sm\304\233ru."]
  ::msgcat::mcset en "Enter point size in side direction." [encoding convertfrom utf-8 "Enter point size in side direction."]
  ::msgcat::mcset es "Enter point size in side direction." [encoding convertfrom utf-8 "Introducir tama\303\261o del punto en direcci\303\263n lateral."]
  ::msgcat::mcset sk "Enter point size in side direction." [encoding convertfrom utf-8 "Zadajte ve\304\276kos\305\245 bodu vo ved\304\276aj\305\241om smere."]

  ::msgcat::mcset cz "loading line module ..." [encoding convertfrom utf-8 "nahr\303\241v\303\241m k\305\231ivkov\303\275 modul ..."]
  ::msgcat::mcset en "loading line module ..." [encoding convertfrom utf-8 "loading line module ..."]
  ::msgcat::mcset es "loading line module ..." [encoding convertfrom utf-8 "l\303\255neas ..."]
  ::msgcat::mcset sk "loading line module ..." [encoding convertfrom utf-8 "nahr\303\241vam modul kriviek ..."]

  ::msgcat::mcset cz "Line type." [encoding convertfrom utf-8 "Typ k\305\231ivky."]
  ::msgcat::mcset en "Line type." [encoding convertfrom utf-8 "Line type (click on triangle to see menu)."]
  ::msgcat::mcset es "Line type." [encoding convertfrom utf-8 "Tipo de l\303\255nea. Clic en tri\303\241ngulo para ver el men\303\272."]
  ::msgcat::mcset sk "Line type." [encoding convertfrom utf-8 "Typ krivky."]

  ::msgcat::mcset cz "id" [encoding convertfrom utf-8 "id"]
  ::msgcat::mcset en "id" [encoding convertfrom utf-8 "id"]
  ::msgcat::mcset es "id" [encoding convertfrom utf-8 "ID"]
  ::msgcat::mcset sk "id" [encoding convertfrom utf-8 "id"]

  ::msgcat::mcset cz "Line identifier." [encoding convertfrom utf-8 "Identifik\303\241tor k\305\231ivky."]
  ::msgcat::mcset en "Line identifier." [encoding convertfrom utf-8 "Line identifier."]
  ::msgcat::mcset es "Line identifier." [encoding convertfrom utf-8 "Nombre (ID) de la l\303\255nea."]
  ::msgcat::mcset sk "Line identifier." [encoding convertfrom utf-8 "Identifik\303\241tor krivky."]

  ::msgcat::mcset cz "Other line options." [encoding convertfrom utf-8 "Dal\305\241\303\255 volby pro k\305\231ivku."]
  ::msgcat::mcset en "Other line options." [encoding convertfrom utf-8 "Other line options. I.e., to make line invisible, write here: -subtype invisible. See thbook.pdf"]
  ::msgcat::mcset es "Other line options." [encoding convertfrom utf-8 "Otras opciones de l\303\255nea. P. ej: para hacerla invisible, escribe: -subtype invisible (consultar thbook.pdf)"]
  ::msgcat::mcset sk "Other line options." [encoding convertfrom utf-8 "\304\216al\305\241ie mo\305\276nosti pre krivku."]

  ::msgcat::mcset cz "reverse" [encoding convertfrom utf-8 "obr\303\241tit"]
  ::msgcat::mcset en "reverse" [encoding convertfrom utf-8 "reverse"]
  ::msgcat::mcset es "reverse" [encoding convertfrom utf-8 "invertir"]
  ::msgcat::mcset sk "reverse" [encoding convertfrom utf-8 "oto\304\215i\305\245"]

  ::msgcat::mcset cz "Reverse line." [encoding convertfrom utf-8 "Obr\303\241tit k\305\231ivku."]
  ::msgcat::mcset en "Reverse line." [encoding convertfrom utf-8 "Reverse line. If symbol's ticks are on bad side, click here."]
  ::msgcat::mcset es "Reverse line." [encoding convertfrom utf-8 "Invertir l\303\255nea. Si p.ej el s\303\255mbolo de resalte aparece al rev\303\251s, haz clic aqu\303\255."]
  ::msgcat::mcset sk "Reverse line." [encoding convertfrom utf-8 "Oto\304\215i\305\245 krivku."]

  ::msgcat::mcset cz "close" [encoding convertfrom utf-8 "zav\305\231\303\255t"]
  ::msgcat::mcset en "close" [encoding convertfrom utf-8 "close"]
  ::msgcat::mcset es "close" [encoding convertfrom utf-8 "cerrar"]
  ::msgcat::mcset sk "close" [encoding convertfrom utf-8 "zavrie\305\245"]

  ::msgcat::mcset cz "Close line." [encoding convertfrom utf-8 "Uzav\305\231\303\255t k\305\231ivku."]
  ::msgcat::mcset en "Close line." [encoding convertfrom utf-8 "Close line."]
  ::msgcat::mcset es "Close line." [encoding convertfrom utf-8 "Cerrar l\303\255nea (o sea, unir \303\272ltimo punto con el primero para definir un espacio cerrado)."]
  ::msgcat::mcset sk "Close line." [encoding convertfrom utf-8 "Uzavrie\305\245 krivku."]

  ::msgcat::mcset cz "Edit line" [encoding convertfrom utf-8 "Editovat"]
  ::msgcat::mcset en "Edit line" [encoding convertfrom utf-8 "Edit line"]
  ::msgcat::mcset es "Edit line" [encoding convertfrom utf-8 "Editar"]
  ::msgcat::mcset sk "Edit line" [encoding convertfrom utf-8 "Upravi\305\245"]

  ::msgcat::mcset cz "Insert/delete line point. Split line." [encoding convertfrom utf-8 "Vlo\305\276en\303\255/smaz\303\241n\303\255 bodu k\305\231ivky. Rozd\304\233len\303\255 k\305\231ivky."]
  ::msgcat::mcset en "Insert/delete line point. Split line." [encoding convertfrom utf-8 "Insert/delete line point. Split line."]
  ::msgcat::mcset es "Insert/delete line point. Split line." [encoding convertfrom utf-8 "Permite a\303\261adir o borrar puntos de la l\303\255nea, o cortar la l\303\255nea en dos."]
  ::msgcat::mcset sk "Insert/delete line point. Split line." [encoding convertfrom utf-8 "Vlo\305\276enie/odstr\303\241nenie bodu krivky. Rozdelenie krivky."]

  ::msgcat::mcset cz "Click this button to apply line changes." [encoding convertfrom utf-8 "Aktualizuje k\305\231ivku."]
  ::msgcat::mcset en "Click this button to apply line changes." [encoding convertfrom utf-8 "Click this button to apply line changes."]
  ::msgcat::mcset es "Click this button to apply line changes." [encoding convertfrom utf-8 "Clicar aqu\303\255 tras modificar las propiedades de la l\303\255nea."]
  ::msgcat::mcset sk "Click this button to apply line changes." [encoding convertfrom utf-8 "Aktualizuje krivku."]

  ::msgcat::mcset cz "Select line point." [encoding convertfrom utf-8 "V\303\275b\304\233r bodu k\305\231ivky."]
  ::msgcat::mcset en "Select line point." [encoding convertfrom utf-8 "These are selected line points. Click on any to get it selected on canvas."]
  ::msgcat::mcset es "Select line point." [encoding convertfrom utf-8 "Lista de puntos que forman esta l\303\255nea. Clic para resaltar el punto en la topo."]
  ::msgcat::mcset sk "Select line point." [encoding convertfrom utf-8 "V\303\275ber bodu krivky."]

  ::msgcat::mcset cz "loading line point module ..." [encoding convertfrom utf-8 "nahr\303\241v\303\241m modul pro body k\305\231ivky ..."]
  ::msgcat::mcset en "loading line point module ..." [encoding convertfrom utf-8 "loading line point module ..."]
  ::msgcat::mcset es "loading line point module ..." [encoding convertfrom utf-8 "puntos de l\303\255nea ..."]
  ::msgcat::mcset sk "loading line point module ..." [encoding convertfrom utf-8 "nahr\303\241vam modul pre body krivky ..."]

  ::msgcat::mcset cz "position" [encoding convertfrom utf-8 "pozice"]
  ::msgcat::mcset en "position" [encoding convertfrom utf-8 "position"]
  ::msgcat::mcset es "position" [encoding convertfrom utf-8 "posici\303\263n"]
  ::msgcat::mcset sk "position" [encoding convertfrom utf-8 "poloha"]

  ::msgcat::mcset cz "Point position." [encoding convertfrom utf-8 "Pozice bodu."]
  ::msgcat::mcset en "Point position." [encoding convertfrom utf-8 "Point position."]
  ::msgcat::mcset es "Point position." [encoding convertfrom utf-8 "Posici\303\263n del punto."]
  ::msgcat::mcset sk "Point position." [encoding convertfrom utf-8 "Poloha bodu."]

  ::msgcat::mcset cz "Point X coordinate." [encoding convertfrom utf-8 "sou\305\231adnice X bodu."]
  ::msgcat::mcset en "Point X coordinate." [encoding convertfrom utf-8 "Point X coordinate."]
  ::msgcat::mcset es "Point X coordinate." [encoding convertfrom utf-8 "Coordenada X del punto."]
  ::msgcat::mcset sk "Point X coordinate." [encoding convertfrom utf-8 "X s\303\272radnica bodu."]

  ::msgcat::mcset cz "Point Y coordinate." [encoding convertfrom utf-8 "sou\305\231adnice Y bodu."]
  ::msgcat::mcset en "Point Y coordinate." [encoding convertfrom utf-8 "Point Y coordinate."]
  ::msgcat::mcset es "Point Y coordinate." [encoding convertfrom utf-8 "coordenada Y del punto."]
  ::msgcat::mcset sk "Point Y coordinate." [encoding convertfrom utf-8 "Y s\303\272radnica bodu."]

  ::msgcat::mcset cz "Previous control point X coordinate." [encoding convertfrom utf-8 "Sou\305\231adnice X p\305\231edchoz\303\255ho \305\231\303\255d\303\255c\303\255ho bodu."]
  ::msgcat::mcset en "Previous control point X coordinate." [encoding convertfrom utf-8 "Previous control point X coordinate."]
  ::msgcat::mcset es "Previous control point X coordinate." [encoding convertfrom utf-8 "Coordenada X del punto de control anterior."]
  ::msgcat::mcset sk "Previous control point X coordinate." [encoding convertfrom utf-8 "X s\303\272radnica predch\303\241dzaj\303\272ceho kontroln\303\251ho bodu."]

  ::msgcat::mcset cz "Previous control point Y coordinate." [encoding convertfrom utf-8 "Sou\305\231adnice Y p\305\231edchoz\303\255ho \305\231\303\255d\303\255c\303\255ho bodu."]
  ::msgcat::mcset en "Previous control point Y coordinate." [encoding convertfrom utf-8 "Previous control point Y coordinate."]
  ::msgcat::mcset es "Previous control point Y coordinate." [encoding convertfrom utf-8 "Coordenada Y del punto de control anterior."]
  ::msgcat::mcset sk "Previous control point Y coordinate." [encoding convertfrom utf-8 "Y s\303\272radnica predch\303\241dzaj\303\272ceho kontroln\303\251ho bodu."]

  ::msgcat::mcset cz "Next control point X coordinate." [encoding convertfrom utf-8 "Sou\305\231adnice X n\303\241sleduj\303\255c\303\255ho \305\231\303\255d\303\255c\303\255ho bodu."]
  ::msgcat::mcset en "Next control point X coordinate." [encoding convertfrom utf-8 "Next control point X coordinate."]
  ::msgcat::mcset es "Next control point X coordinate." [encoding convertfrom utf-8 "Coordenada X del siguiente punto de control."]
  ::msgcat::mcset sk "Next control point X coordinate." [encoding convertfrom utf-8 "X s\303\272radnica nasleduj\303\272ceho kontroln\303\251ho bodu."]

  ::msgcat::mcset cz "Next control point Y coordinate." [encoding convertfrom utf-8 "Sou\305\231adnice Y n\303\241sleduj\303\255c\303\255ho \305\231\303\255d\303\255c\303\255ho bodu."]
  ::msgcat::mcset en "Next control point Y coordinate." [encoding convertfrom utf-8 "Next control point Y coordinate."]
  ::msgcat::mcset es "Next control point Y coordinate." [encoding convertfrom utf-8 "Coordenada Y del siguiente punto de control."]
  ::msgcat::mcset sk "Next control point Y coordinate." [encoding convertfrom utf-8 "Y s\303\272radnica nasleduj\303\272ceho kontroln\303\251ho bodu."]

  ::msgcat::mcset cz "Checkbox whether to use previous control point." [encoding convertfrom utf-8 "Za\305\241krtn\304\233te pokud chcete pro tvar k\305\231ivky pou\305\276\303\255t p\305\231edchoz\303\255 \305\231\303\255d\303\255c\303\255 bod."]
  ::msgcat::mcset en "Checkbox whether to use previous control point." [encoding convertfrom utf-8 "Checkbox whether to use previous control point."]
  ::msgcat::mcset es "Checkbox whether to use previous control point." [encoding convertfrom utf-8 "Usar punto de control anterior."]
  ::msgcat::mcset sk "Checkbox whether to use previous control point." [encoding convertfrom utf-8 "Pou\305\276i predch\303\241dzaj\303\272ci kontroln\303\275 bod."]

  ::msgcat::mcset cz "smooth" [encoding convertfrom utf-8 "uhladit"]
  ::msgcat::mcset en "smooth" [encoding convertfrom utf-8 "smooth"]
  ::msgcat::mcset es "smooth" [encoding convertfrom utf-8 "suavizar"]
  ::msgcat::mcset sk "smooth" [encoding convertfrom utf-8 "vyhladi\305\245"]

  ::msgcat::mcset cz "Set line to be smooth in given point." [encoding convertfrom utf-8 "Nastav\303\255 hladkou k\305\231ivku v dan\303\251m bod\304\233."]
  ::msgcat::mcset en "Set line to be smooth in given point." [encoding convertfrom utf-8 "Set line to be smooth in given point."]
  ::msgcat::mcset es "Set line to be smooth in given point." [encoding convertfrom utf-8 "Suavizar la l\303\255nea en el punto seleccionado."]
  ::msgcat::mcset sk "Set line to be smooth in given point." [encoding convertfrom utf-8 "Nastav\303\255 kontroln\303\251 body tak, aby krivka bola v danom bode hladk\303\241."]

  ::msgcat::mcset cz "Checkbox whether to use next control point." [encoding convertfrom utf-8 "Za\305\241krtn\304\233te pokud chcete pro tvar k\305\231ivky pou\305\276\303\255t n\303\241sleduj\303\255c\303\255 \305\231\303\255d\303\255c\303\255 bod."]
  ::msgcat::mcset en "Checkbox whether to use next control point." [encoding convertfrom utf-8 "Checkbox whether to use next control point."]
  ::msgcat::mcset es "Checkbox whether to use next control point." [encoding convertfrom utf-8 "Usar siguiente punto de control."]
  ::msgcat::mcset sk "Checkbox whether to use next control point." [encoding convertfrom utf-8 "Pou\305\276i nasleduj\303\272ci kontroln\303\275 bod."]

  ::msgcat::mcset cz "orientation" [encoding convertfrom utf-8 "orientace"]
  ::msgcat::mcset en "orientation" [encoding convertfrom utf-8 "orientation"]
  ::msgcat::mcset es "orientation" [encoding convertfrom utf-8 "orientaci\303\263n"]
  ::msgcat::mcset sk "orientation" [encoding convertfrom utf-8 "orient\303\241cia"]

  ::msgcat::mcset cz "Set line point orientation." [encoding convertfrom utf-8 "Nastav\303\255 orientaci bodu."]
  ::msgcat::mcset en "Set line point orientation." [encoding convertfrom utf-8 "Set line point orientation."]
  ::msgcat::mcset es "Set line point orientation." [encoding convertfrom utf-8 "Ajustar direcci\303\263n en que apunta un punto de la l\303\255nea (p.ej una pendiente)."]
  ::msgcat::mcset sk "Set line point orientation." [encoding convertfrom utf-8 "Nastav\303\255 orient\303\241ciu symbolov v bode krivky."]

  ::msgcat::mcset cz "Enter line point orientation." [encoding convertfrom utf-8 "Zadejte orientaci bodu."]
  ::msgcat::mcset en "Enter line point orientation." [encoding convertfrom utf-8 "Enter line point orientation."]
  ::msgcat::mcset es "Enter line point orientation." [encoding convertfrom utf-8 "Introducir direcci\303\263n se\303\261alada por el punto."]
  ::msgcat::mcset sk "Enter line point orientation." [encoding convertfrom utf-8 "Zadaj orient\303\241ciu symbolov v bode krivky."]

  ::msgcat::mcset cz "r-size" [encoding convertfrom utf-8 "p-rozsah"]
  ::msgcat::mcset en "r-size" [encoding convertfrom utf-8 "r-size"]
  ::msgcat::mcset es "r-size" [encoding convertfrom utf-8 "anchura-dcha"]
  ::msgcat::mcset sk "r-size" [encoding convertfrom utf-8 "rozmer-p"]

  ::msgcat::mcset cz "Set line size in right direction." [encoding convertfrom utf-8 "Nastav\303\255 rozsah k\305\231ivky v prav\303\251m sm\304\233ru."]
  ::msgcat::mcset en "Set line size in right direction." [encoding convertfrom utf-8 "Set line size in right direction."]
  ::msgcat::mcset es "Set line size in right direction." [encoding convertfrom utf-8 "Ajustar anchura de l\303\255nea (lado derecho de la l\303\255nea)."]
  ::msgcat::mcset sk "Set line size in right direction." [encoding convertfrom utf-8 "Nastav\303\255 ve\304\276kos\305\245 symbolov napravo od krivky."]

  ::msgcat::mcset cz "Enter line size in right direction." [encoding convertfrom utf-8 "Zadejte rozsah k\305\231ivky v prav\303\251m sm\304\233ru."]
  ::msgcat::mcset en "Enter line size in right direction." [encoding convertfrom utf-8 "Enter line size in right direction."]
  ::msgcat::mcset es "Enter line size in right direction." [encoding convertfrom utf-8 "Introducir anchura de l\303\255nea (lado derecho de la l\303\255nea)."]
  ::msgcat::mcset sk "Enter line size in right direction." [encoding convertfrom utf-8 "Zadaj ve\304\276kos\305\245 symbolov napravo od krivky."]

  ::msgcat::mcset cz "l-size" [encoding convertfrom utf-8 "l-rozsah"]
  ::msgcat::mcset en "l-size" [encoding convertfrom utf-8 "l-size"]
  ::msgcat::mcset es "l-size" [encoding convertfrom utf-8 "anchura-izda"]
  ::msgcat::mcset sk "l-size" [encoding convertfrom utf-8 "rozmer-\304\276"]

  ::msgcat::mcset cz "Set line size in left direction." [encoding convertfrom utf-8 "Nastav\303\255 rozsah k\305\231ivky v lev\303\251m sm\304\233ru."]
  ::msgcat::mcset en "Set line size in left direction." [encoding convertfrom utf-8 "Set line size in left direction."]
  ::msgcat::mcset es "Set line size in left direction." [encoding convertfrom utf-8 "Ajustar anchura de l\303\255nea (lado izquierdo de la l\303\255nea). El tipo slope necesita este valor."]
  ::msgcat::mcset sk "Set line size in left direction." [encoding convertfrom utf-8 "Nastav\303\255 ve\304\276kos\305\245 symbolov na\304\276avo od krivky."]

  ::msgcat::mcset cz "Enter line size in left direction." [encoding convertfrom utf-8 "Zadejte rozsah k\305\231ivky v lev\303\251m sm\304\233ru."]
  ::msgcat::mcset en "Enter line size in left direction." [encoding convertfrom utf-8 "Enter line size in left direction."]
  ::msgcat::mcset es "Enter line size in left direction." [encoding convertfrom utf-8 "Introducir anchura de l\303\255nea (lado izquierdo de la l\303\255nea). El tipo slope necesita este valor."]
  ::msgcat::mcset sk "Enter line size in left direction." [encoding convertfrom utf-8 "Zadaj ve\304\276kos\305\245 symbolov na\304\276avo od krivky."]

  ::msgcat::mcset cz "Line point options editor." [encoding convertfrom utf-8 "Volby bodu k\305\231ivky."]
  ::msgcat::mcset en "Line point options editor." [encoding convertfrom utf-8 "Line point options editor."]
  ::msgcat::mcset es "Line point options editor." [encoding convertfrom utf-8 "Editor de puntos pertenecientes a la l\303\255nea seleccionada. Consultar thbook.pdf"]
  ::msgcat::mcset sk "Line point options editor." [encoding convertfrom utf-8 "Editor \304\217al\305\241\303\255ch mo\305\276nost\303\255 bodu krivky."]

  ::msgcat::mcset cz "Click this button to apply line point changes." [encoding convertfrom utf-8 "Aktualizovat bod k\305\231ivky."]
  ::msgcat::mcset en "Click this button to apply line point changes." [encoding convertfrom utf-8 "Click this button to apply line point changes."]
  ::msgcat::mcset es "Click this button to apply line point changes." [encoding convertfrom utf-8 "Clicar tras modificar las propiedades de los puntos de una l\303\255nea."]
  ::msgcat::mcset sk "Click this button to apply line point changes." [encoding convertfrom utf-8 "Aktializ\303\241cia bodu krivky."]

  ::msgcat::mcset cz "Editor for line point options." [encoding convertfrom utf-8 "Editor voleb bodu k\305\231ivky."]
  ::msgcat::mcset en "Editor for line point options." [encoding convertfrom utf-8 "Here you can enter options that will apply to line points."]
  ::msgcat::mcset es "Editor for line point options." [encoding convertfrom utf-8 "Aqu\303\255 se pueden meter opciones que afectar\303\241n a los puntos de esta l\303\255nea."]
  ::msgcat::mcset sk "Editor for line point options." [encoding convertfrom utf-8 "Editor \304\217al\305\241\303\255ch mo\305\276nost\303\255 bodu krivky."]

  ::msgcat::mcset cz "loading area module ..." [encoding convertfrom utf-8 "nahr\303\241v\303\241m modul pro oblasti ..."]
  ::msgcat::mcset en "loading area module ..." [encoding convertfrom utf-8 "oading area module ..."]
  ::msgcat::mcset es "loading area module ..." [encoding convertfrom utf-8 "\303\241reas..."]
  ::msgcat::mcset sk "loading area module ..." [encoding convertfrom utf-8 "nahr\303\241vam modul pre plochy ..."]

  ::msgcat::mcset cz "type" [encoding convertfrom utf-8 "typ"]
  ::msgcat::mcset en "type" [encoding convertfrom utf-8 "type"]
  ::msgcat::mcset es "type" [encoding convertfrom utf-8 "tipo"]
  ::msgcat::mcset sk "type" [encoding convertfrom utf-8 "typ"]

  ::msgcat::mcset cz "Area type." [encoding convertfrom utf-8 "Typ oblasti."]
  ::msgcat::mcset en "Area type." [encoding convertfrom utf-8 "Area type (clic on triangle to see menu)."]
  ::msgcat::mcset es "Area type." [encoding convertfrom utf-8 "Tipo de \303\241rea. Clic en tri\303\241ngulo para ver el men\303\272."]
  ::msgcat::mcset sk "Area type." [encoding convertfrom utf-8 "Typ plochy."]

  ::msgcat::mcset cz "options" [encoding convertfrom utf-8 "volby"]
  ::msgcat::mcset en "options" [encoding convertfrom utf-8 "options"]
  ::msgcat::mcset es "options" [encoding convertfrom utf-8 "opciones"]
  ::msgcat::mcset sk "options" [encoding convertfrom utf-8 "mo\305\276nosti"]

  ::msgcat::mcset cz "Other area options." [encoding convertfrom utf-8 "Dal\305\241\303\255 volby pro oblast."]
  ::msgcat::mcset en "Other area options." [encoding convertfrom utf-8 "Other area options. See thbook.pdf"]
  ::msgcat::mcset es "Other area options." [encoding convertfrom utf-8 "Otras opciones de \303\241rea. Consultar thbook.pdf"]
  ::msgcat::mcset sk "Other area options." [encoding convertfrom utf-8 "\304\216al\305\241ie mo\305\276nosti plochy."]

  ::msgcat::mcset cz "Select lines" [encoding convertfrom utf-8 "Vyber k\305\231ivky"]
  ::msgcat::mcset en "Select lines" [encoding convertfrom utf-8 "Select lines"]
  ::msgcat::mcset es "Select lines" [encoding convertfrom utf-8 "Seleccionar"]
  ::msgcat::mcset sk "Select lines" [encoding convertfrom utf-8 "Vyber krivky"]

  ::msgcat::mcset cz "Switch to insert line into area mode." [encoding convertfrom utf-8 "V\303\275b\304\233r ohrani\304\215uj\303\255c\303\255ch k\305\231ivek oblasti."]
  ::msgcat::mcset en "Switch to insert line into area mode." [encoding convertfrom utf-8 "After clicking here, select by mouse this area border lines (they must intersect)."]
  ::msgcat::mcset es "Switch to insert line into area mode." [encoding convertfrom utf-8 "Tras clicar aqu\303\255, con el rat\303\263n puedes seleccionar l\303\255neas que limiten un \303\241rea (deben cortarse entre s\303\255)."]
  ::msgcat::mcset sk "Switch to insert line into area mode." [encoding convertfrom utf-8 "Po stla\304\215en\303\255 m\303\264\305\276ete za\304\215a\305\245 vklada\305\245 krivky ohrani\304\215uj\303\272ce plochu."]

  ::msgcat::mcset cz "Delete ID from area." [encoding convertfrom utf-8 "Odstran\304\233n\303\255 objektu z oblasti."]
  ::msgcat::mcset en "Delete ID from area." [encoding convertfrom utf-8 "Delete selected line from list (will not be part of area borders)"]
  ::msgcat::mcset es "Delete ID from area." [encoding convertfrom utf-8 "Borrar la l\303\255nea seleccionada de la lista (dejar\303\241 de limitar este \303\241rea)."]
  ::msgcat::mcset sk "Delete ID from area." [encoding convertfrom utf-8 "Odstr\303\241ni\305\245 krivku z dan\303\275m ID z plochy."]

  ::msgcat::mcset cz "Insert ID" [encoding convertfrom utf-8 "Vlo\305\276 ID"]
  ::msgcat::mcset en "Insert ID" [encoding convertfrom utf-8 "Insert ID"]
  ::msgcat::mcset es "Insert ID" [encoding convertfrom utf-8 "Insertar ID"]
  ::msgcat::mcset sk "Insert ID" [encoding convertfrom utf-8 "Vlo\305\276 ID"]

  ::msgcat::mcset cz "Insert given id." [encoding convertfrom utf-8 "Vlo\305\276\303\255 objekt s dan\303\275m ID."]
  ::msgcat::mcset en "Insert given id." [encoding convertfrom utf-8 "Insert given id instead of Xtherion default."]
  ::msgcat::mcset es "Insert given id." [encoding convertfrom utf-8 "Insertar nombre (ID) indicado, no el nombre que therion crea autom\303\241ticamente"]
  ::msgcat::mcset sk "Insert given id." [encoding convertfrom utf-8 "Vlo\305\276i\305\245 ID krivky do zoznamu kriviek ohrani\304\215uj\303\272cich plochu."]

  ::msgcat::mcset cz "ID to insert." [encoding convertfrom utf-8 "ID objektu ke vlo\305\276en\303\255."]
  ::msgcat::mcset en "ID to insert." [encoding convertfrom utf-8 "ID to insert."]
  ::msgcat::mcset es "ID to insert." [encoding convertfrom utf-8 "Escribir el nombre (ID) a insertar."]
  ::msgcat::mcset sk "ID to insert." [encoding convertfrom utf-8 "ID na vlo\305\276enie."]

  ::msgcat::mcset cz "Update" [encoding convertfrom utf-8 "Aktualizovat"]
  ::msgcat::mcset en "Update" [encoding convertfrom utf-8 "Update"]
  ::msgcat::mcset es "Update" [encoding convertfrom utf-8 "Actualizar"]
  ::msgcat::mcset sk "Update" [encoding convertfrom utf-8 "Aktualizova\305\245"]

  ::msgcat::mcset cz "Click this button to apply changes you made to area." [encoding convertfrom utf-8 "Aktualizace oblasti."]
  ::msgcat::mcset en "Click this button to apply changes you made to area." [encoding convertfrom utf-8 "Click this button to apply changes you made to area."]
  ::msgcat::mcset es "Click this button to apply changes you made to area." [encoding convertfrom utf-8 "Clicar aqu\303\255 despu\303\251s de modificar las propiedades de un \303\241rea."]
  ::msgcat::mcset sk "Click this button to apply changes you made to area." [encoding convertfrom utf-8 "Aktualizova\305\245 plochu."]

  ::msgcat::mcset cz "Show" [encoding convertfrom utf-8 "Zobrazit"]
  ::msgcat::mcset en "Show" [encoding convertfrom utf-8 "Show"]
  ::msgcat::mcset es "Show" [encoding convertfrom utf-8 "Mostrar"]
  ::msgcat::mcset sk "Show" [encoding convertfrom utf-8 "Zobrazi\305\245"]

  ::msgcat::mcset cz "Show area border lines." [encoding convertfrom utf-8 "Zobraz\303\255 hranice oblasti."]
  ::msgcat::mcset en "Show area border lines." [encoding convertfrom utf-8 "Show area border lines."]
  ::msgcat::mcset es "Show area border lines." [encoding convertfrom utf-8 "Mostrar l\303\255neas l\303\255mite de \303\241rea."]
  ::msgcat::mcset sk "Show area border lines." [encoding convertfrom utf-8 "Zobraz hranice plochy."]

  ::msgcat::mcset cz "Select line in area." [encoding convertfrom utf-8 "V\303\275b\304\233r k\305\231ivky ohrani\304\215uj\303\255c\303\255 oblast"]
  ::msgcat::mcset en "Select line in area." [encoding convertfrom utf-8 "Click on any list line to get corresponding area border line selected on canvas."]
  ::msgcat::mcset es "Select line in area." [encoding convertfrom utf-8 "Cada rengl\303\263n de la lista corresponde a una l\303\255nea que limita esta \303\241rea"]
  ::msgcat::mcset sk "Select line in area." [encoding convertfrom utf-8 "Vyber hrani\304\215n\303\272 krivku."]

  ::msgcat::mcset cz "loading main menu ..." [encoding convertfrom utf-8 "nahr\303\241v\303\241m hlavn\303\255 menu ..."]
  ::msgcat::mcset en "loading main menu ..." [encoding convertfrom utf-8 "loading main menu ..."]
  ::msgcat::mcset es "loading main menu ..." [encoding convertfrom utf-8 "men\303\272 principal ..."]
  ::msgcat::mcset sk "loading main menu ..." [encoding convertfrom utf-8 "nahr\303\241vam hlavn\303\251 menu ..."]

  ::msgcat::mcset cz "Open (no pics)" [encoding convertfrom utf-8 "Otev\305\231\303\255t (bez obr\303\241zk\305\257)"]
  ::msgcat::mcset en "Open (no pics)" [encoding convertfrom utf-8 "Open (no pics)"]
  ::msgcat::mcset es "Open (no pics)" [encoding convertfrom utf-8 "Abrir (sin im\303\241genes)"]
  ::msgcat::mcset sk "Open (no pics)" [encoding convertfrom utf-8 "Otvori\305\245 (bez obr\303\241zkov)"]

  ::msgcat::mcset cz "Insert ..." [encoding convertfrom utf-8 "Vlo\305\276it ..."]
  ::msgcat::mcset en "Insert ..." [encoding convertfrom utf-8 "Insert ..."]
  ::msgcat::mcset es "Insert ..." [encoding convertfrom utf-8 "Insertar ..."]
  ::msgcat::mcset sk "Insert ..." [encoding convertfrom utf-8 "Vlo\305\276i\305\245 ..."]

  ::msgcat::mcset cz "point" [encoding convertfrom utf-8 "bod"]
  ::msgcat::mcset en "point" [encoding convertfrom utf-8 "point"]
  ::msgcat::mcset es "point" [encoding convertfrom utf-8 "punto"]
  ::msgcat::mcset sk "point" [encoding convertfrom utf-8 "bod"]

  ::msgcat::mcset cz "line" [encoding convertfrom utf-8 "k\305\231ivka"]
  ::msgcat::mcset en "line" [encoding convertfrom utf-8 "line"]
  ::msgcat::mcset es "line" [encoding convertfrom utf-8 "l\303\255nea"]
  ::msgcat::mcset sk "line" [encoding convertfrom utf-8 "krivku"]

  ::msgcat::mcset cz "area" [encoding convertfrom utf-8 "oblast"]
  ::msgcat::mcset en "area" [encoding convertfrom utf-8 "area"]
  ::msgcat::mcset es "area" [encoding convertfrom utf-8 "\303\241rea"]
  ::msgcat::mcset sk "area" [encoding convertfrom utf-8 "plochu"]

  ::msgcat::mcset cz "scrap" [encoding convertfrom utf-8 "scrap"]
  ::msgcat::mcset en "scrap" [encoding convertfrom utf-8 "scrap"]
  ::msgcat::mcset es "scrap" [encoding convertfrom utf-8 "croquis"]
  ::msgcat::mcset sk "scrap" [encoding convertfrom utf-8 "scrap"]

  ::msgcat::mcset cz "text" [encoding convertfrom utf-8 "text"]
  ::msgcat::mcset en "text" [encoding convertfrom utf-8 "text"]
  ::msgcat::mcset es "text" [encoding convertfrom utf-8 "texto"]
  ::msgcat::mcset sk "text" [encoding convertfrom utf-8 "text"]

  ::msgcat::mcset cz "Auto adjust area" [encoding convertfrom utf-8 "Auto p\305\231izp\305\257sobit"]
  ::msgcat::mcset en "Auto adjust area" [encoding convertfrom utf-8 "Auto adjust area"]
  ::msgcat::mcset es "Auto adjust area" [encoding convertfrom utf-8 "Autoajustar \303\241rea"]
  ::msgcat::mcset sk "Auto adjust area" [encoding convertfrom utf-8 "Prisp\303\264sob plochu"]

  ::msgcat::mcset cz "Insert image" [encoding convertfrom utf-8 "Vlo\305\276it obr\303\241zek"]
  ::msgcat::mcset en "Insert image" [encoding convertfrom utf-8 "Insert image"]
  ::msgcat::mcset es "Insert image" [encoding convertfrom utf-8 "Insertar imagen"]
  ::msgcat::mcset sk "Insert image" [encoding convertfrom utf-8 "Vlo\305\276i\305\245 obr\303\241zok"]

  ::msgcat::mcset cz "Zoom 100 %" [encoding convertfrom utf-8 "Zoom na 100 %"]
  ::msgcat::mcset en "Zoom 100 %" [encoding convertfrom utf-8 "Zoom 100 %"]
  ::msgcat::mcset es "Zoom 100 %" [encoding convertfrom utf-8 "Zoom 100%"]
  ::msgcat::mcset sk "Zoom 100 %" [encoding convertfrom utf-8 "Zoom 100%"]

  ::msgcat::mcset cz "Mouse mode." [encoding convertfrom utf-8 "Klikac\303\255 re\305\276im."]
  ::msgcat::mcset en "Mouse mode." [encoding convertfrom utf-8 "Mouse mode."]
  ::msgcat::mcset es "Mouse mode." [encoding convertfrom utf-8 "Modo rat\303\263n."]
  ::msgcat::mcset sk "Mouse mode." [encoding convertfrom utf-8 "M\303\263d my\305\241i."]

  ::msgcat::mcset cz "Current mouse position." [encoding convertfrom utf-8 "Aktu\303\241ln\303\255 pozice ukazatele my\305\241i."]
  ::msgcat::mcset en "Current mouse position." [encoding convertfrom utf-8 "Current mouse position."]
  ::msgcat::mcset es "Current mouse position." [encoding convertfrom utf-8 "Posici\303\263n actual del rat\303\263n."]
  ::msgcat::mcset sk "Current mouse position." [encoding convertfrom utf-8 "Aktu\303\241lna poloha my\305\241i."]

  ::msgcat::mcset cz "loading line procs ..." [encoding convertfrom utf-8 "zpracov\303\241v\303\241m k\305\231ivky ..."]
  ::msgcat::mcset en "loading line procs ..." [encoding convertfrom utf-8 "loading line procs ..."]
  ::msgcat::mcset es "loading line procs ..." [encoding convertfrom utf-8 "procesos de l\303\255nea ..."]
  ::msgcat::mcset sk "loading line procs ..." [encoding convertfrom utf-8 "na\304\215itavam modul kriviek ..."]

  ::msgcat::mcset en "Map editor is not active. To activate it, open existing file or create new one." [encoding convertfrom utf-8 "Map editor is not active. To activate it, open existing file or create new one."]
  ::msgcat::mcset es "Map editor is not active. To activate it, open existing file or create new one." [encoding convertfrom utf-8 "El editor de mapas est\303\241 inactivo. Para activarlo, abre un archivo existente o crea uno nuevo."]
  ::msgcat::mcset sk "Map editor is not active. To activate it, open existing file or create new one." [encoding convertfrom utf-8 "Mapov\303\275 editor nie je akt\303\255vny. Otvorte existuj\303\272ci s\303\272bor alebo vytvorte nov\303\275."]

  ::msgcat::mcset cz "Insert line" [encoding convertfrom utf-8 "Vlo\305\276it k\305\231ivku"]
  ::msgcat::mcset en "Insert line" [encoding convertfrom utf-8 "Insert line"]
  ::msgcat::mcset es "Insert line" [encoding convertfrom utf-8 "Insertar l\303\255nea"]
  ::msgcat::mcset sk "Insert line" [encoding convertfrom utf-8 "Vlo\305\276i\305\245 krivku"]

  ::msgcat::mcset cz "Insert scrap" [encoding convertfrom utf-8 "Vlo\305\276it scrap"]
  ::msgcat::mcset en "Insert scrap" [encoding convertfrom utf-8 "Insert scrap"]
  ::msgcat::mcset es "Insert scrap" [encoding convertfrom utf-8 "Insertar croquis"]
  ::msgcat::mcset sk "Insert scrap" [encoding convertfrom utf-8 "Vlo\305\276i\305\245 scrap"]

  ::msgcat::mcset cz "Insert text" [encoding convertfrom utf-8 "Vlo\305\276it text"]
  ::msgcat::mcset en "Insert text" [encoding convertfrom utf-8 "Insert text"]
  ::msgcat::mcset es "Insert text" [encoding convertfrom utf-8 "Insertar texto"]
  ::msgcat::mcset sk "Insert text" [encoding convertfrom utf-8 "Vlo\305\276i\305\245 text"]

  ::msgcat::mcset cz "Insert area" [encoding convertfrom utf-8 "Vlo\305\276it oblast"]
  ::msgcat::mcset en "Insert area" [encoding convertfrom utf-8 "Insert area"]
  ::msgcat::mcset es "Insert area" [encoding convertfrom utf-8 "Insertar \303\241rea"]
  ::msgcat::mcset sk "Insert area" [encoding convertfrom utf-8 "Vlo\305\276i\305\245 plochu"]

  ::msgcat::mcset cz "Delete" [encoding convertfrom utf-8 "Smazat"]
  ::msgcat::mcset en "Delete" [encoding convertfrom utf-8 "Delete"]
  ::msgcat::mcset es "Delete" [encoding convertfrom utf-8 "Borrar"]
  ::msgcat::mcset sk "Delete" [encoding convertfrom utf-8 "Odstr\303\241ni\305\245"]

  ::msgcat::mcset cz "deleting" [encoding convertfrom utf-8 "maz\303\241n\303\255"]
  ::msgcat::mcset en "deleting" [encoding convertfrom utf-8 "deleting"]
  ::msgcat::mcset es "deleting" [encoding convertfrom utf-8 "borrando"]
  ::msgcat::mcset sk "deleting" [encoding convertfrom utf-8 "mazanie"]

  ::msgcat::mcset cz "moving command" [encoding convertfrom utf-8 "p\305\231esun p\305\231\303\255kazu"]
  ::msgcat::mcset en "moving command" [encoding convertfrom utf-8 "moving command"]
  ::msgcat::mcset es "moving command" [encoding convertfrom utf-8 "desplazando comando"]
  ::msgcat::mcset sk "moving command" [encoding convertfrom utf-8 "presun pr\303\255kazu"]

  ::msgcat::mcset cz "creating endscrap" [encoding convertfrom utf-8 "vytvo\305\231en\303\255 konce scrapu"]
  ::msgcat::mcset en "creating endscrap" [encoding convertfrom utf-8 "creating endscrap"]
  ::msgcat::mcset es "creating endscrap" [encoding convertfrom utf-8 "creando l\303\255nea final de croquis (endscrap)"]
  ::msgcat::mcset sk "creating endscrap" [encoding convertfrom utf-8 "vytvorenie konca scrapu"]

  ::msgcat::mcset cz "scrap changes" [encoding convertfrom utf-8 "zm\304\233na parametr\305\257 scrapu"]
  ::msgcat::mcset en "scrap changes" [encoding convertfrom utf-8 "scrap changes"]
  ::msgcat::mcset es "scrap changes" [encoding convertfrom utf-8 "cambios del croquis (scrap)"]
  ::msgcat::mcset sk "scrap changes" [encoding convertfrom utf-8 "zmena parametrov scrapu"]

  ::msgcat::mcset cz "creating scrap" [encoding convertfrom utf-8 "vytvo\305\231en\303\255 scrapu"]
  ::msgcat::mcset en "creating scrap" [encoding convertfrom utf-8 "creating scrap"]
  ::msgcat::mcset es "creating scrap" [encoding convertfrom utf-8 "creando croquis (scrap)"]
  ::msgcat::mcset sk "creating scrap" [encoding convertfrom utf-8 "vytvorenie scrapu"]

  ::msgcat::mcset cz "creating text" [encoding convertfrom utf-8 "vytvo\305\231en\303\255 textu"]
  ::msgcat::mcset en "creating text" [encoding convertfrom utf-8 "creating text"]
  ::msgcat::mcset es "creating text" [encoding convertfrom utf-8 "creando texto"]
  ::msgcat::mcset sk "creating text" [encoding convertfrom utf-8 "vytvorenie textu"]

  ::msgcat::mcset cz "text changes" [encoding convertfrom utf-8 "zm\304\233na textu"]
  ::msgcat::mcset en "text changes" [encoding convertfrom utf-8 "text changes"]
  ::msgcat::mcset es "text changes" [encoding convertfrom utf-8 "cambios de texto"]
  ::msgcat::mcset sk "text changes" [encoding convertfrom utf-8 "zmena textu"]

  ::msgcat::mcset cz "end point insertion" [encoding convertfrom utf-8 "konec vkl\303\241d\303\241n\303\255 bod\305\257"]
  ::msgcat::mcset en "end point insertion" [encoding convertfrom utf-8 "end point insertion"]
  ::msgcat::mcset es "end point insertion" [encoding convertfrom utf-8 "final de inserci\303\263n de punto"]
  ::msgcat::mcset sk "end point insertion" [encoding convertfrom utf-8 "koniec vkladania bodov"]

  ::msgcat::mcset sk "select object" [encoding convertfrom utf-8 "ozna\304\215 objekt"]

  ::msgcat::mcset cz "Insert" [encoding convertfrom utf-8 "Vlo\305\276it"]
  ::msgcat::mcset en "Insert" [encoding convertfrom utf-8 "Insert"]
  ::msgcat::mcset es "Insert" [encoding convertfrom utf-8 "Insertar"]
  ::msgcat::mcset sk "Insert" [encoding convertfrom utf-8 "Vlo\305\276i\305\245"]

  ::msgcat::mcset sk "insert point" [encoding convertfrom utf-8 "vlo\305\276 bod"]

  ::msgcat::mcset sk "insert line point" [encoding convertfrom utf-8 "vlo\305\276 bod krivky"]

  ::msgcat::mcset sk "insert area border" [encoding convertfrom utf-8 "vlo\305\276 okraj plochy"]

  ::msgcat::mcset cz "Select" [encoding convertfrom utf-8 "Vyber"]
  ::msgcat::mcset en "Select" [encoding convertfrom utf-8 "Select"]
  ::msgcat::mcset es "Select" [encoding convertfrom utf-8 "Seleccionar"]
  ::msgcat::mcset sk "Select" [encoding convertfrom utf-8 "Vybra\305\245"]

  ::msgcat::mcset cz "creating point" [encoding convertfrom utf-8 "vytvo\305\231en\303\255 bodu"]
  ::msgcat::mcset en "creating point" [encoding convertfrom utf-8 "creating point"]
  ::msgcat::mcset es "creating point" [encoding convertfrom utf-8 "creando punto"]
  ::msgcat::mcset sk "creating point" [encoding convertfrom utf-8 "vytvorenie bodu"]

  ::msgcat::mcset cz "area changes" [encoding convertfrom utf-8 "zm\304\233na parametr\305\257 oblasti"]
  ::msgcat::mcset en "area changes" [encoding convertfrom utf-8 "area changes"]
  ::msgcat::mcset es "area changes" [encoding convertfrom utf-8 "cambios de \303\241rea"]
  ::msgcat::mcset sk "area changes" [encoding convertfrom utf-8 "zmena parametrov plochy"]

  ::msgcat::mcset cz "point changes" [encoding convertfrom utf-8 "zm\304\233na parametr\305\257 bodu"]
  ::msgcat::mcset en "point changes" [encoding convertfrom utf-8 "point changes"]
  ::msgcat::mcset es "point changes" [encoding convertfrom utf-8 "cambios de punto"]
  ::msgcat::mcset sk "point changes" [encoding convertfrom utf-8 "zmena parametrov bodu"]

  ::msgcat::mcset cz "toggle image visibility" [encoding convertfrom utf-8 "p\305\231epnut\303\255 viditelnosti obr\303\241zku"]
  ::msgcat::mcset en "toggle image visibility" [encoding convertfrom utf-8 "toggle image visibility"]
  ::msgcat::mcset es "toggle image visibility" [encoding convertfrom utf-8 "Cambiar visibilidad de la imagen"]
  ::msgcat::mcset sk "toggle image visibility" [encoding convertfrom utf-8 "prepni vidite\304\276nos\305\245 obr\303\241zku"]

  ::msgcat::mcset cz "grid - spacing %s" [encoding convertfrom utf-8 "m\305\231\303\255\305\276ka - odstup %s"]
  ::msgcat::mcset en "grid - spacing %s" [encoding convertfrom utf-8 "grid - spacing %s"]
  ::msgcat::mcset es "grid - spacing %s" [encoding convertfrom utf-8 "anchura cuadr\303\255cula %s"]
  ::msgcat::mcset sk "grid - spacing %s" [encoding convertfrom utf-8 "sie\305\245 - rozostupy %s"]

  ::msgcat::mcset cz "station - %s" [encoding convertfrom utf-8 "m\304\233\305\231i\304\215sk\303\275 bod - %s"]
  ::msgcat::mcset en "station - %s" [encoding convertfrom utf-8 "station - %s"]
  ::msgcat::mcset es "station - %s" [encoding convertfrom utf-8 "estaci\303\263n %s"]
  ::msgcat::mcset sk "station - %s" [encoding convertfrom utf-8 "m\304\233ra\304\215sk\303\275 bod - %s"]

  ::msgcat::mcset cz "New *.th2 file needs to be saved before inserting background image. Save it now?" [encoding convertfrom utf-8 "Nov\303\275 *.th2 soubor mus\303\255 b\303\275t ulo\305\276en p\305\231ed vlo\305\276en\303\255m podkladov\303\251ho obr\303\241zku. Ulo\305\276it nyn\303\255?"]
  ::msgcat::mcset en "New *.th2 file needs to be saved before inserting background image. Save it now?" [encoding convertfrom utf-8 "New *.th2 file needs to be saved before inserting background image. Save it now?"]
  ::msgcat::mcset es "New *.th2 file needs to be saved before inserting background image. Save it now?" [encoding convertfrom utf-8 "Hay que guardar el nuevo archivo .th2 antes de cargar una imagen de fondo. \302\277Guardar ahora?"]
  ::msgcat::mcset sk "New *.th2 file needs to be saved before inserting background image. Save it now?" [encoding convertfrom utf-8 "Pred vlo\305\276en\303\255m obr\303\241zku mus\303\255te nov\303\275 *.th2 s\303\272bor ulo\305\276i\305\245. Chcete tak urobi\305\245?"]

  ::msgcat::mcset cz "inserting image" [encoding convertfrom utf-8 "vkl\303\241d\303\241m obr\303\241zek"]
  ::msgcat::mcset en "inserting image" [encoding convertfrom utf-8 "inserting image"]
  ::msgcat::mcset es "inserting image" [encoding convertfrom utf-8 "insertando imagen"]
  ::msgcat::mcset sk "inserting image" [encoding convertfrom utf-8 "vkladanie obr\303\241zku"]

  ::msgcat::mcset cz "removing image" [encoding convertfrom utf-8 "odstra\305\210uji obr\303\241zek"]
  ::msgcat::mcset en "removing image" [encoding convertfrom utf-8 "removing image"]
  ::msgcat::mcset es "removing image" [encoding convertfrom utf-8 "eliminando imagen"]
  ::msgcat::mcset sk "removing image" [encoding convertfrom utf-8 "odstr\303\241nenie obr\303\241zku"]

  ::msgcat::mcset cz "moving image" [encoding convertfrom utf-8 "p\305\231esunuji obr\303\241zek"]
  ::msgcat::mcset en "moving image" [encoding convertfrom utf-8 "moving image"]
  ::msgcat::mcset es "moving image" [encoding convertfrom utf-8 "moviendo imagen"]
  ::msgcat::mcset sk "moving image" [encoding convertfrom utf-8 "posun obr\303\241zku"]

  ::msgcat::mcset cz "gamma correction" [encoding convertfrom utf-8 "gamma korekce"]
  ::msgcat::mcset en "gamma correction" [encoding convertfrom utf-8 "gamma correction"]
  ::msgcat::mcset es "gamma correction" [encoding convertfrom utf-8 "corecci\303\263n gamma"]
  ::msgcat::mcset sk "gamma correction" [encoding convertfrom utf-8 "gamma korekcia"]

  ::msgcat::mcset cz "Insert point" [encoding convertfrom utf-8 "Vlo\305\276it bod"]
  ::msgcat::mcset en "Insert point" [encoding convertfrom utf-8 "Insert point"]
  ::msgcat::mcset es "Insert point" [encoding convertfrom utf-8 "Insertar punto"]
  ::msgcat::mcset sk "Insert point" [encoding convertfrom utf-8 "Vlo\305\276i\305\245 bod"]

  ::msgcat::mcset cz "Delete point" [encoding convertfrom utf-8 "Smazat bod"]
  ::msgcat::mcset en "Delete point" [encoding convertfrom utf-8 "Delete point"]
  ::msgcat::mcset es "Delete point" [encoding convertfrom utf-8 "Borrar punto"]
  ::msgcat::mcset sk "Delete point" [encoding convertfrom utf-8 "Odstr\303\241ni\305\245 bod"]

  ::msgcat::mcset cz "Split line" [encoding convertfrom utf-8 "Rozd\304\233lit k\305\231ivku"]
  ::msgcat::mcset en "Split line" [encoding convertfrom utf-8 "Split line"]
  ::msgcat::mcset es "Split line" [encoding convertfrom utf-8 "Cortar l\303\255nea"]
  ::msgcat::mcset sk "Split line" [encoding convertfrom utf-8 "Rozdeli\305\245 krivku"]

  ::msgcat::mcset cz "deleting line point" [encoding convertfrom utf-8 "mazan\303\255 bodu na k\305\231ivce"]
  ::msgcat::mcset en "deleting line point" [encoding convertfrom utf-8 "deleting line point"]
  ::msgcat::mcset es "deleting line point" [encoding convertfrom utf-8 "borrando punto de l\303\255nea"]
  ::msgcat::mcset sk "deleting line point" [encoding convertfrom utf-8 "mazanie bodu na \304\215iare"]

  ::msgcat::mcset cz "inserting area border" [encoding convertfrom utf-8 "vlo\305\276en\303\255 hranice oblasti"]
  ::msgcat::mcset en "inserting area border" [encoding convertfrom utf-8 "inserting area border"]
  ::msgcat::mcset es "inserting area border" [encoding convertfrom utf-8 "insertando l\303\255mite de \303\241rea"]
  ::msgcat::mcset sk "inserting area border" [encoding convertfrom utf-8 "vlo\305\276enie okraja plochy"]

  ::msgcat::mcset cz "deleting area border" [encoding convertfrom utf-8 "mazan\303\255 hranice oblasti"]
  ::msgcat::mcset en "deleting area border" [encoding convertfrom utf-8 "deleting area border"]
  ::msgcat::mcset es "deleting area border" [encoding convertfrom utf-8 "borrando l\303\255mite de \303\241rea"]
  ::msgcat::mcset sk "deleting area border" [encoding convertfrom utf-8 "mazanie okraja plochy"]

  ::msgcat::mcset cz "creating area" [encoding convertfrom utf-8 "vytvo\305\231en\303\255 oblasti"]
  ::msgcat::mcset en "creating area" [encoding convertfrom utf-8 "creating area"]
  ::msgcat::mcset es "creating area" [encoding convertfrom utf-8 "creando \303\241rea"]
  ::msgcat::mcset sk "creating area" [encoding convertfrom utf-8 "vytvorenie plochy"]

  ::msgcat::mcset cz "creating line" [encoding convertfrom utf-8 "vytvo\305\231en\303\255 k\305\231ivky"]
  ::msgcat::mcset en "creating line" [encoding convertfrom utf-8 "creating line"]
  ::msgcat::mcset es "creating line" [encoding convertfrom utf-8 "creando l\303\255nea"]
  ::msgcat::mcset sk "creating line" [encoding convertfrom utf-8 "vytvorenie krivky"]

  ::msgcat::mcset cz "line changes" [encoding convertfrom utf-8 "zm\304\233na parametr\305\257 k\305\231ivky"]
  ::msgcat::mcset en "line changes" [encoding convertfrom utf-8 "line changes"]
  ::msgcat::mcset es "line changes" [encoding convertfrom utf-8 "cambios de l\303\255nea"]
  ::msgcat::mcset sk "line changes" [encoding convertfrom utf-8 "zmena parametrov krivky"]

  ::msgcat::mcset cz "line closing" [encoding convertfrom utf-8 "uzav\305\231en\303\255 k\305\231ivky"]
  ::msgcat::mcset en "line closing" [encoding convertfrom utf-8 "line closing"]
  ::msgcat::mcset es "line closing" [encoding convertfrom utf-8 "cerrando l\303\255nea"]
  ::msgcat::mcset sk "line closing" [encoding convertfrom utf-8 "uzavretie krivky"]

  ::msgcat::mcset cz "line opening" [encoding convertfrom utf-8 "otev\305\231en\303\255 k\305\231ivky"]
  ::msgcat::mcset en "line opening" [encoding convertfrom utf-8 "line opening"]
  ::msgcat::mcset es "line opening" [encoding convertfrom utf-8 "abriendo l\303\255nea"]
  ::msgcat::mcset sk "line opening" [encoding convertfrom utf-8 "otvorenie krivky"]

  ::msgcat::mcset cz "inserting line point" [encoding convertfrom utf-8 "vlo\305\276en\303\255 bodu k\305\231ivky"]
  ::msgcat::mcset en "inserting line point" [encoding convertfrom utf-8 "inserting line point"]
  ::msgcat::mcset es "inserting line point" [encoding convertfrom utf-8 "insertando punto en la l\303\255nea"]
  ::msgcat::mcset sk "inserting line point" [encoding convertfrom utf-8 "vlo\305\276enie bodu krivky"]

  ::msgcat::mcset cz "line ending" [encoding convertfrom utf-8 "ukon\304\215en\303\255 k\305\231ivky"]
  ::msgcat::mcset en "line ending" [encoding convertfrom utf-8 "line ending"]
  ::msgcat::mcset es "line ending" [encoding convertfrom utf-8 "finalizando l\303\255nea"]
  ::msgcat::mcset sk "line ending" [encoding convertfrom utf-8 "ukon\304\215enie krivky"]

  ::msgcat::mcset cz "moving control point" [encoding convertfrom utf-8 "posun \305\231\303\255d\303\255c\303\255ho bodu"]
  ::msgcat::mcset en "moving control point" [encoding convertfrom utf-8 "moving control point"]
  ::msgcat::mcset es "moving control point" [encoding convertfrom utf-8 "moviendo punto de control"]
  ::msgcat::mcset sk "moving control point" [encoding convertfrom utf-8 "posun kontroln\303\251ho bodu"]

  ::msgcat::mcset cz "split line" [encoding convertfrom utf-8 "rozd\304\233lit k\305\231ivku"]
  ::msgcat::mcset en "split line" [encoding convertfrom utf-8 "split line"]
  ::msgcat::mcset es "split line" [encoding convertfrom utf-8 "cortar l\303\255nea"]
  ::msgcat::mcset sk "split line" [encoding convertfrom utf-8 "rozdelenie \304\215iary"]

  ::msgcat::mcset cz "loading model viewer..." [encoding convertfrom utf-8 "nahr\303\241v\303\241m 3D prohl\303\255\305\276e\304\215..."]
  ::msgcat::mcset en "loading model viewer..." [encoding convertfrom utf-8 "loading model viewer..."]
  ::msgcat::mcset es "loading model viewer..." [encoding convertfrom utf-8 "visor 3D..."]
  ::msgcat::mcset sk "loading model viewer..." [encoding convertfrom utf-8 "3D prehliada\304\215..."]

  ::msgcat::mcset cz "Model viewer" [encoding convertfrom utf-8 "3D prohl\303\255\305\276e\304\215"]
  ::msgcat::mcset en "Model viewer" [encoding convertfrom utf-8 "Model viewer"]
  ::msgcat::mcset es "Model viewer" [encoding convertfrom utf-8 "Visor 3D"]
  ::msgcat::mcset sk "Model viewer" [encoding convertfrom utf-8 "3D prehliada\304\215"]

  ::msgcat::mcset cz "Camera" [encoding convertfrom utf-8 "Kamera"]
  ::msgcat::mcset en "Camera" [encoding convertfrom utf-8 "Camera"]
  ::msgcat::mcset es "Camera" [encoding convertfrom utf-8 "C\303\241mara"]
  ::msgcat::mcset sk "Camera" [encoding convertfrom utf-8 "Kamera"]

  ::msgcat::mcset cz "Model" [encoding convertfrom utf-8 "Model"]
  ::msgcat::mcset en "Model" [encoding convertfrom utf-8 "Model"]
  ::msgcat::mcset es "Model" [encoding convertfrom utf-8 "Modelo"]
  ::msgcat::mcset sk "Model" [encoding convertfrom utf-8 "Model"]

  ::msgcat::mcset cz "Reload" [encoding convertfrom utf-8 "Otev\305\231\303\255t znovu"]
  ::msgcat::mcset en "Reload" [encoding convertfrom utf-8 "Reload"]
  ::msgcat::mcset es "Reload" [encoding convertfrom utf-8 "Recargar"]
  ::msgcat::mcset sk "Reload" [encoding convertfrom utf-8 "Znovu na\304\215\303\255ta\305\245"]

  ::msgcat::mcset cz "facing" [encoding convertfrom utf-8 "azimut"]
  ::msgcat::mcset en "facing" [encoding convertfrom utf-8 "facing"]
  ::msgcat::mcset es "facing" [encoding convertfrom utf-8 "vista"]
  ::msgcat::mcset sk "facing" [encoding convertfrom utf-8 "azimut"]

  ::msgcat::mcset cz "north" [encoding convertfrom utf-8 "sever"]
  ::msgcat::mcset en "north" [encoding convertfrom utf-8 "north"]
  ::msgcat::mcset es "north" [encoding convertfrom utf-8 "norte"]
  ::msgcat::mcset sk "north" [encoding convertfrom utf-8 "sever"]

  ::msgcat::mcset cz "east" [encoding convertfrom utf-8 "v\303\275chod"]
  ::msgcat::mcset en "east" [encoding convertfrom utf-8 "east"]
  ::msgcat::mcset es "east" [encoding convertfrom utf-8 "este"]
  ::msgcat::mcset sk "east" [encoding convertfrom utf-8 "v\303\275chod"]

  ::msgcat::mcset cz "west" [encoding convertfrom utf-8 "z\303\241pad"]
  ::msgcat::mcset en "west" [encoding convertfrom utf-8 "west"]
  ::msgcat::mcset es "west" [encoding convertfrom utf-8 "oeste"]
  ::msgcat::mcset sk "west" [encoding convertfrom utf-8 "z\303\241pad"]

  ::msgcat::mcset cz "south" [encoding convertfrom utf-8 "jih"]
  ::msgcat::mcset en "south" [encoding convertfrom utf-8 "south"]
  ::msgcat::mcset es "south" [encoding convertfrom utf-8 "sur"]
  ::msgcat::mcset sk "south" [encoding convertfrom utf-8 "juh"]

  ::msgcat::mcset cz "Set facing angle." [encoding convertfrom utf-8 "Nastav\303\255 \303\272hel oto\304\215en\303\255."]
  ::msgcat::mcset en "Set facing angle." [encoding convertfrom utf-8 "Set facing angle."]
  ::msgcat::mcset es "Set facing angle." [encoding convertfrom utf-8 "Ajustar punto de vista."]
  ::msgcat::mcset sk "Set facing angle." [encoding convertfrom utf-8 "Nastav azimut poh\304\276adu."]

  ::msgcat::mcset cz "Facing angle." [encoding convertfrom utf-8 "\303\232hel oto\304\215en\303\255."]
  ::msgcat::mcset en "Facing angle." [encoding convertfrom utf-8 "Facing angle."]
  ::msgcat::mcset es "Facing angle." [encoding convertfrom utf-8 "Punto de vista."]
  ::msgcat::mcset sk "Facing angle." [encoding convertfrom utf-8 "Azimut poh\304\276adu."]

  ::msgcat::mcset cz "auto rotate" [encoding convertfrom utf-8 "auto rotace"]
  ::msgcat::mcset en "auto rotate" [encoding convertfrom utf-8 "auto rotate"]
  ::msgcat::mcset es "auto rotate" [encoding convertfrom utf-8 "rotar"]
  ::msgcat::mcset sk "auto rotate" [encoding convertfrom utf-8 "rot\303\241cia"]

  ::msgcat::mcset cz "Turn on/off camera auto rotation" [encoding convertfrom utf-8 "Zapne/vypne automatickou rotaci"]
  ::msgcat::mcset en "Turn on/off camera auto rotation" [encoding convertfrom utf-8 "Turn on/off camera auto rotation"]
  ::msgcat::mcset es "Turn on/off camera auto rotation" [encoding convertfrom utf-8 "Conectar-Desconectar rotaci\303\263n autom\303\241tica de la c\303\241mara"]
  ::msgcat::mcset sk "Turn on/off camera auto rotation" [encoding convertfrom utf-8 "Zapne/vypne automatick\303\251 ot\303\241\304\215anie kamery."]

  ::msgcat::mcset cz "profile" [encoding convertfrom utf-8 "profil"]
  ::msgcat::mcset en "profile" [encoding convertfrom utf-8 "profile"]
  ::msgcat::mcset es "profile" [encoding convertfrom utf-8 "perfil"]
  ::msgcat::mcset sk "profile" [encoding convertfrom utf-8 "profil"]

  ::msgcat::mcset cz "top" [encoding convertfrom utf-8 "pohled zhora"]
  ::msgcat::mcset en "top" [encoding convertfrom utf-8 "top"]
  ::msgcat::mcset es "top" [encoding convertfrom utf-8 "superior"]
  ::msgcat::mcset sk "top" [encoding convertfrom utf-8 "poh\304\276ad zhora"]

  ::msgcat::mcset cz "side" [encoding convertfrom utf-8 "pohled zboku"]
  ::msgcat::mcset en "side" [encoding convertfrom utf-8 "side"]
  ::msgcat::mcset es "side" [encoding convertfrom utf-8 "lateral"]
  ::msgcat::mcset sk "side" [encoding convertfrom utf-8 "poh\304\276ad zboku"]

  ::msgcat::mcset cz "bottom" [encoding convertfrom utf-8 "pohled zdola"]
  ::msgcat::mcset en "bottom" [encoding convertfrom utf-8 "bottom"]
  ::msgcat::mcset es "bottom" [encoding convertfrom utf-8 "inferior"]
  ::msgcat::mcset sk "bottom" [encoding convertfrom utf-8 "poh\304\276ad zospodu"]

  ::msgcat::mcset cz "reset" [encoding convertfrom utf-8 "reset"]
  ::msgcat::mcset en "reset" [encoding convertfrom utf-8 "reset"]
  ::msgcat::mcset es "reset" [encoding convertfrom utf-8 "reajustar"]
  ::msgcat::mcset sk "reset" [encoding convertfrom utf-8 "reset"]

  ::msgcat::mcset cz "Set profile angle." [encoding convertfrom utf-8 "Nastav\303\255 \303\272hel profilu."]
  ::msgcat::mcset en "Set profile angle." [encoding convertfrom utf-8 "Set profile angle."]
  ::msgcat::mcset es "Set profile angle." [encoding convertfrom utf-8 "Ajustar \303\241ngulo del perfil."]
  ::msgcat::mcset sk "Set profile angle." [encoding convertfrom utf-8 "Nastav\303\255 sklon poh\304\276adu."]

  ::msgcat::mcset cz "Profile angle." [encoding convertfrom utf-8 "\303\232hel profilu."]
  ::msgcat::mcset en "Profile angle." [encoding convertfrom utf-8 "Profile angle."]
  ::msgcat::mcset es "Profile angle." [encoding convertfrom utf-8 "Angulo del perfil."]
  ::msgcat::mcset sk "Profile angle." [encoding convertfrom utf-8 "Sklon poh\304\276adu."]

  ::msgcat::mcset cz "surface transparency" [encoding convertfrom utf-8 "pr\305\257hlednost povrchu"]
  ::msgcat::mcset en "surface transparency" [encoding convertfrom utf-8 "surface transparency"]
  ::msgcat::mcset es "surface transparency" [encoding convertfrom utf-8 "transparencia superficie"]
  ::msgcat::mcset sk "surface transparency" [encoding convertfrom utf-8 "prieh\304\276adnos\305\245 povrchu"]

  ::msgcat::mcset cz "Turn on/off surface transparency." [encoding convertfrom utf-8 "Zapne/vypne pr\305\257hlednost povrchu."]
  ::msgcat::mcset en "Turn on/off surface transparency." [encoding convertfrom utf-8 "Turn on/off surface transparency."]
  ::msgcat::mcset es "Turn on/off surface transparency." [encoding convertfrom utf-8 "Conectar/desconectar transparencia de la superficie."]
  ::msgcat::mcset sk "Turn on/off surface transparency." [encoding convertfrom utf-8 "Zapne/vypne prieh\304\276adnos\305\245 povrchu."]

  ::msgcat::mcset cz "light follows camera" [encoding convertfrom utf-8 "sv\304\233tlo n\303\241sleduje kameru"]
  ::msgcat::mcset en "light follows camera" [encoding convertfrom utf-8 "light follows camera"]
  ::msgcat::mcset es "light follows camera" [encoding convertfrom utf-8 "luz en c\303\241mara"]
  ::msgcat::mcset sk "light follows camera" [encoding convertfrom utf-8 "svetlo nasleduje kameru"]

  ::msgcat::mcset cz "Fix light source to camera position." [encoding convertfrom utf-8 "Sv\304\233teln\303\275 zdroj p\305\231ipevn\304\233n\303\275 ke kame\305\231e."]
  ::msgcat::mcset en "Fix light source to camera position." [encoding convertfrom utf-8 "Fix light source to camera position."]
  ::msgcat::mcset es "Fix light source to camera position." [encoding convertfrom utf-8 "La fuente de luz coincidir\303\241 siempre con la posici\303\263n de la c\303\241mara"]
  ::msgcat::mcset sk "Fix light source to camera position." [encoding convertfrom utf-8 "Zafixuje zdroj svetla na poz\303\255ciu kamery."]

  ::msgcat::mcset en "Model viewer is not active. To activate it, open some model file." [encoding convertfrom utf-8 "Model viewer is not active. To activate it, open some model file."]
  ::msgcat::mcset es "Model viewer is not active. To activate it, open some model file." [encoding convertfrom utf-8 "El visor 3D est\303\241 inactivo. Para activarlo, abre alg\303\272n modelo."]
  ::msgcat::mcset sk "Model viewer is not active. To activate it, open some model file." [encoding convertfrom utf-8 "Prehliada\304\215 modelov nie je akt\303\255vny. Aktivuje sa po otvoren\303\255 s\303\272boru."]

  ::msgcat::mcset cz "loading text editor ..." [encoding convertfrom utf-8 "nahr\303\241v\303\241m text editor ..."]
  ::msgcat::mcset en "loading text editor ..." [encoding convertfrom utf-8 "loading text editor ..."]
  ::msgcat::mcset es "loading text editor ..." [encoding convertfrom utf-8 "editor de texto ..."]
  ::msgcat::mcset sk "loading text editor ..." [encoding convertfrom utf-8 "na\304\215\303\255tavam textov\303\275 editor"]

  ::msgcat::mcset cz "Text Editor" [encoding convertfrom utf-8 "Text editor"]
  ::msgcat::mcset en "Text Editor" [encoding convertfrom utf-8 "Text Editor"]
  ::msgcat::mcset es "Text Editor" [encoding convertfrom utf-8 "Editor de texto"]
  ::msgcat::mcset sk "Text Editor" [encoding convertfrom utf-8 "Textov\303\275 editor"]

  ::msgcat::mcset cz "Files" [encoding convertfrom utf-8 "Soubory"]
  ::msgcat::mcset en "Files" [encoding convertfrom utf-8 "Files"]
  ::msgcat::mcset es "Files" [encoding convertfrom utf-8 "Archivos"]
  ::msgcat::mcset sk "Files" [encoding convertfrom utf-8 "S\303\272bory"]

  ::msgcat::mcset cz "Data table" [encoding convertfrom utf-8 "Datov\303\241 tabulka"]
  ::msgcat::mcset en "Data table" [encoding convertfrom utf-8 "Data table"]
  ::msgcat::mcset es "Data table" [encoding convertfrom utf-8 "Tabla de datos"]
  ::msgcat::mcset sk "Data table" [encoding convertfrom utf-8 "D\303\241tov\303\241 tabu\304\276ka"]

  ::msgcat::mcset cz "Search & Replace" [encoding convertfrom utf-8 "Naj\303\255t & Nahradit"]
  ::msgcat::mcset en "Search & Replace" [encoding convertfrom utf-8 "Search & Replace"]
  ::msgcat::mcset es "Search & Replace" [encoding convertfrom utf-8 "Buscar y cambiar"]
  ::msgcat::mcset sk "Search & Replace" [encoding convertfrom utf-8 "N\303\241jdi a Nahra\304\217"]

  ::msgcat::mcset cz "Switch open files." [encoding convertfrom utf-8 "P\305\231ep\303\255na\304\215 otev\305\231en\303\275ch soubor\305\257."]
  ::msgcat::mcset en "Switch open files." [encoding convertfrom utf-8 "This list shows open files. Click on the one you are interested."]
  ::msgcat::mcset es "Switch open files." [encoding convertfrom utf-8 "Esta lista muestra los archivos abiertos. Haz clic en el que te interese."]
  ::msgcat::mcset sk "Switch open files." [encoding convertfrom utf-8 "Prep\303\255na\304\215 medzi otvoren\303\275mi s\303\272bormi."]

  ::msgcat::mcset cz "Encoding" [encoding convertfrom utf-8 "K\303\263dov\303\241n\303\255"]
  ::msgcat::mcset en "Encoding" [encoding convertfrom utf-8 "Encoding"]
  ::msgcat::mcset es "Encoding" [encoding convertfrom utf-8 "Codificaci\303\263n"]
  ::msgcat::mcset sk "Encoding" [encoding convertfrom utf-8 "K\303\263dovanie"]

  ::msgcat::mcset cz "Change to" [encoding convertfrom utf-8 "Zm\304\233nit na"]
  ::msgcat::mcset en "Change to" [encoding convertfrom utf-8 "Change to"]
  ::msgcat::mcset es "Change to" [encoding convertfrom utf-8 "Cambiar a"]
  ::msgcat::mcset sk "Change to" [encoding convertfrom utf-8 "Zmeni\305\245 na"]

  ::msgcat::mcset cz "To set file encoding, type encoding name and press <Change> button." [encoding convertfrom utf-8 "Nastaven\303\255 k\303\263dov\303\241n\303\255 - vyberte k\303\263dov\303\241n\303\255 a stiskn\304\233te tla\304\215\303\255tko <Zm\304\233nit na>."]
  ::msgcat::mcset en "To set file encoding, type encoding name and press <Change> button." [encoding convertfrom utf-8 "To set file encoding, type encoding name and press <Change> button."]
  ::msgcat::mcset es "To set file encoding, type encoding name and press <Change> button." [encoding convertfrom utf-8 "Para ajustar la codificaci\303\263n, escoje la que quieras y pulsa <Cambiar a>."]
  ::msgcat::mcset sk "To set file encoding, type encoding name and press <Change> button." [encoding convertfrom utf-8 "Na nastavenie k\303\263dovania, vlo\305\276te identifik\303\241tor k\303\263dovania a stla\304\215te <Zmeni\305\245>."]

  ::msgcat::mcset cz "Scan data format" [encoding convertfrom utf-8 "Skenovat form\303\241t dat"]
  ::msgcat::mcset en "Scan data format" [encoding convertfrom utf-8 "Scan data format"]
  ::msgcat::mcset es "Scan data format" [encoding convertfrom utf-8 "Escanear formato de datos"]
  ::msgcat::mcset sk "Scan data format" [encoding convertfrom utf-8 "N\303\241jdi form\303\241t d\303\241t"]

  ::msgcat::mcset cz "Scan data format and rebuild centerline data insertion tool." [encoding convertfrom utf-8 "P\305\231e\304\215te form\303\241t dat v souboru a uprav\303\255 pole pro vkl\303\241d\303\241n\303\255 m\304\233\305\231en\303\255."]
  ::msgcat::mcset en "Scan data format and rebuild centerline data insertion tool." [encoding convertfrom utf-8 "Scans data order and rebuilds data insertion textboxes accordingly."]
  ::msgcat::mcset es "Scan data format and rebuild centerline data insertion tool." [encoding convertfrom utf-8 "Ajusta las casillas al orden en que has tomado tus datos."]
  ::msgcat::mcset sk "Scan data format and rebuild centerline data insertion tool." [encoding convertfrom utf-8 "Na\304\215\303\255ta form\303\241t d\303\241t z predch\303\241dzaj\303\272cich riadkov a pr\303\255slu\305\241ne zmen\303\255 panel na vkladanie d\303\241t."]

  ::msgcat::mcset cz "Enter station names" [encoding convertfrom utf-8 "Zad\303\241vat n\303\241zvy bod\305\257"]
  ::msgcat::mcset en "Enter station names" [encoding convertfrom utf-8 "Enter station names"]
  ::msgcat::mcset es "Enter station names" [encoding convertfrom utf-8 "Nombrar estaciones"]
  ::msgcat::mcset sk "Enter station names" [encoding convertfrom utf-8 "Zad\303\241vanie n\303\241zvov bodov"]

  ::msgcat::mcset cz "Check if you want to insert station names for each shot." [encoding convertfrom utf-8 "Za\305\241krtn\304\233te pokud chcete zad\303\241vat n\303\241zev pro ka\305\276d\303\275 m\304\233\305\231i\304\215sk\303\275 bod."]
  ::msgcat::mcset en "Check if you want to insert station names for each shot." [encoding convertfrom utf-8 "Check if you want to insert station names for each shot."]
  ::msgcat::mcset es "Check if you want to insert station names for each shot." [encoding convertfrom utf-8 "Marcar si se quiere dar un nombre a cada tirada topo."]
  ::msgcat::mcset sk "Check if you want to insert station names for each shot." [encoding convertfrom utf-8 "Za\305\241krtnite pokia\304\276 chcete vklada\305\245 aj men\303\241 bodov pre ka\305\276d\303\272 z\303\241meru."]

  ::msgcat::mcset cz "Auto format selection" [encoding convertfrom utf-8 "Auto form\303\241tov\303\241n\303\255 v\303\275b\304\233ru"]
  ::msgcat::mcset en "Auto format selection" [encoding convertfrom utf-8 "Auto format selection"]
  ::msgcat::mcset es "Auto format selection" [encoding convertfrom utf-8 "Autoformatear selecci\303\263n"]
  ::msgcat::mcset sk "Auto format selection" [encoding convertfrom utf-8 "Naform\303\241tuj v\303\275ber"]

  ::msgcat::mcset cz "Format selection to given table." [encoding convertfrom utf-8 "Naform\303\241tuje v\303\275b\304\233r do tabulky."]
  ::msgcat::mcset en "Format selection to given table." [encoding convertfrom utf-8 "Format selection to given table."]
  ::msgcat::mcset es "Format selection to given table." [encoding convertfrom utf-8 "Formatea la seleccion (ajusta tabuladores, etc)."]
  ::msgcat::mcset sk "Format selection to given table." [encoding convertfrom utf-8 "Naform\303\241tuje v\303\275ber do d\303\241tovej tabu\304\276ky."]

  ::msgcat::mcset cz "search" [encoding convertfrom utf-8 "hledat"]
  ::msgcat::mcset en "search" [encoding convertfrom utf-8 "search"]
  ::msgcat::mcset es "search" [encoding convertfrom utf-8 "buscar"]
  ::msgcat::mcset sk "search" [encoding convertfrom utf-8 "h\304\276adaj"]

  ::msgcat::mcset cz "Search expression." [encoding convertfrom utf-8 "Hledan\303\275 v\303\275raz."]
  ::msgcat::mcset en "Search expression." [encoding convertfrom utf-8 "Enter word(s) to search for."]
  ::msgcat::mcset es "Search expression." [encoding convertfrom utf-8 "Introducir palabra(s) a buscar."]
  ::msgcat::mcset sk "Search expression." [encoding convertfrom utf-8 "H\304\276adan\303\275 v\303\275raz."]

  ::msgcat::mcset cz "replace" [encoding convertfrom utf-8 "nahradit"]
  ::msgcat::mcset en "replace" [encoding convertfrom utf-8 "replace"]
  ::msgcat::mcset es "replace" [encoding convertfrom utf-8 "cambiar"]
  ::msgcat::mcset sk "replace" [encoding convertfrom utf-8 "nahradi\305\245"]

  ::msgcat::mcset cz "Check whether to replace found expression." [encoding convertfrom utf-8 "Za\305\241krtn\304\233te pokud chcete nahradit nalezen\303\251 v\303\275razy."]
  ::msgcat::mcset en "Check whether to replace found expression." [encoding convertfrom utf-8 "Check whether to replace found expression."]
  ::msgcat::mcset es "Check whether to replace found expression." [encoding convertfrom utf-8 "Marcar para cambiar los lo encontrado por lo que se escriba aqu\303\255."]
  ::msgcat::mcset sk "Check whether to replace found expression." [encoding convertfrom utf-8 "Za\305\241krtn\303\272\305\245 pokia\304\276 sa m\303\241 n\303\241jden\303\275 v\303\275raz nahradi\305\245 in\303\275m."]

  ::msgcat::mcset cz "Replace expression." [encoding convertfrom utf-8 "\305\230et\304\233zec, kter\303\275m bude v\303\275raz nahrazen."]
  ::msgcat::mcset en "Replace expression." [encoding convertfrom utf-8 "Search results will be replaced by the string entered here."]
  ::msgcat::mcset es "Replace expression." [encoding convertfrom utf-8 "Los resultados de la b\303\272squeda ser\303\241n cambiados por lo que escribas aqu\303\255."]
  ::msgcat::mcset sk "Replace expression." [encoding convertfrom utf-8 "V\303\275raz na nahradenie."]

  ::msgcat::mcset cz "case sensitive search" [encoding convertfrom utf-8 "rozli\305\241ovat velikost p\303\255smen"]
  ::msgcat::mcset en "case sensitive search" [encoding convertfrom utf-8 "case sensitive search"]
  ::msgcat::mcset es "case sensitive search" [encoding convertfrom utf-8 "sensible a may\303\272sculas"]
  ::msgcat::mcset sk "case sensitive search" [encoding convertfrom utf-8 "rozli\305\241ova\305\245 mal\303\251 a ve\304\276k\303\251"]

  ::msgcat::mcset cz "Check if search should be case sensitive." [encoding convertfrom utf-8 "Vyhled\303\241v\303\241n\303\255 s rozli\305\241en\303\255m velikosti p\303\255smen."]
  ::msgcat::mcset en "Check if search should be case sensitive." [encoding convertfrom utf-8 "Check if search should be case sensitive."]
  ::msgcat::mcset es "Check if search should be case sensitive." [encoding convertfrom utf-8 "Marcar para que la b\303\272squeda distinga entre may\303\272sculas y min\303\272sculas."]
  ::msgcat::mcset sk "Check if search should be case sensitive." [encoding convertfrom utf-8 "Za\305\241krtnite pokia\304\276 pri h\304\276adan\303\255 chcete rozli\305\241ova\305\245 mal\303\251 a ve\304\276k\303\251 p\303\255smen\303\241."]

  ::msgcat::mcset cz "regular expressions" [encoding convertfrom utf-8 "regul\303\241rn\303\255 v\303\275razy"]
  ::msgcat::mcset en "regular expressions" [encoding convertfrom utf-8 "regular expressions (cav*)"]
  ::msgcat::mcset es "regular expressions" [encoding convertfrom utf-8 "patr\303\263n regular (kob*)"]
  ::msgcat::mcset sk "regular expressions" [encoding convertfrom utf-8 "regul\303\241rny v\303\275raz"]

  ::msgcat::mcset cz "Check whether to evaluate search and replace as regular expressions." [encoding convertfrom utf-8 "Za\305\241krtn\304\233te pokud chcete vyhled\303\241vat nebo nahrazovat pomoc\303\255 regul\303\241rn\303\255ch v\303\275raz\305\257."]
  ::msgcat::mcset en "Check whether to evaluate search and replace as regular expressions." [encoding convertfrom utf-8 "Check wether to search using wildcards (cav* will find cave, cavern, cavalier...)"]
  ::msgcat::mcset es "Check whether to evaluate search and replace as regular expressions." [encoding convertfrom utf-8 "B\303\272squeda usando comodines (kob* encontrar\303\241 koba, kobea, kobie, etc)."]
  ::msgcat::mcset sk "Check whether to evaluate search and replace as regular expressions." [encoding convertfrom utf-8 "Za\305\241krtnite ak sa m\303\241 h\304\276adanie a nahradenie vykon\303\241va\305\245 v m\303\263de regul\303\241rnych v\303\275razov."]

  ::msgcat::mcset cz "search selection only" [encoding convertfrom utf-8 "pouze ve vybran\303\251m textu"]
  ::msgcat::mcset en "search selection only" [encoding convertfrom utf-8 "search selection only"]
  ::msgcat::mcset es "search selection only" [encoding convertfrom utf-8 "selecci\303\263n solo"]
  ::msgcat::mcset sk "search selection only" [encoding convertfrom utf-8 "iba vo vybratom texte"]

  ::msgcat::mcset cz "Check whether to do search only in selected text." [encoding convertfrom utf-8 "Za\305\241krtn\304\233te pokud chcete vyhled\303\241vat pouze ve vybran\303\251m textu."]
  ::msgcat::mcset en "Check whether to do search only in selected text." [encoding convertfrom utf-8 "Check whether to do search only in selected text."]
  ::msgcat::mcset es "Check whether to do search only in selected text." [encoding convertfrom utf-8 "Marcar para buscar solo dentro del texto seleccionado."]
  ::msgcat::mcset sk "Check whether to do search only in selected text." [encoding convertfrom utf-8 "Za\305\241krtnite pokia\304\276 hladanie m\303\241 prebehn\303\272\305\245 len v ozna\304\215enom texte."]

  ::msgcat::mcset cz "First" [encoding convertfrom utf-8 "Prvn\303\255"]
  ::msgcat::mcset en "First" [encoding convertfrom utf-8 "First"]
  ::msgcat::mcset es "First" [encoding convertfrom utf-8 "Buscar"]
  ::msgcat::mcset sk "First" [encoding convertfrom utf-8 "Prv\303\275"]

  ::msgcat::mcset cz "Search or replace first expression in the file." [encoding convertfrom utf-8 "Najde nebo nahrad\303\255 prvn\303\255 v\303\275raz v souboru."]
  ::msgcat::mcset en "Search or replace first expression in the file." [encoding convertfrom utf-8 "Search or replace first expression in the file."]
  ::msgcat::mcset es "Search or replace first expression in the file." [encoding convertfrom utf-8 "Buscar o reemplazar el primer resultado."]
  ::msgcat::mcset sk "Search or replace first expression in the file." [encoding convertfrom utf-8 "N\303\241jte popr\303\255pade nahrad\303\255 prv\303\275 v\303\275skyt h\304\276adan\303\251ho v\303\275razu v s\303\272bore."]

  ::msgcat::mcset cz "Search or replace next expression after the cursor in the file." [encoding convertfrom utf-8 "Najde nebo nahrad\303\255 n\303\241sleduj\303\255c\303\255 v\303\275raz v souboru."]
  ::msgcat::mcset en "Search or replace next expression after the cursor in the file." [encoding convertfrom utf-8 "Search or replace next expression after the cursor in the file."]
  ::msgcat::mcset es "Search or replace next expression after the cursor in the file." [encoding convertfrom utf-8 "Buscar o reemplazar el siguiente resultado."]
  ::msgcat::mcset sk "Search or replace next expression after the cursor in the file." [encoding convertfrom utf-8 "N\303\241jdi alebo nahra\304\217 nasleduj\303\272ci v\303\275raz v s\303\272bore."]

  ::msgcat::mcset cz "All" [encoding convertfrom utf-8 "V\305\241e"]
  ::msgcat::mcset en "All" [encoding convertfrom utf-8 "All"]
  ::msgcat::mcset es "All" [encoding convertfrom utf-8 "Todo"]
  ::msgcat::mcset sk "All" [encoding convertfrom utf-8 "V\305\241etko"]

  ::msgcat::mcset cz "Search or replace all expressions in the file." [encoding convertfrom utf-8 "Najde nebo nahrad\303\255 v\305\241echny v\303\275razy v souboru."]
  ::msgcat::mcset en "Search or replace all expressions in the file." [encoding convertfrom utf-8 "Search or replace all expressions in the file."]
  ::msgcat::mcset es "Search or replace all expressions in the file." [encoding convertfrom utf-8 "Buscar o reemplazar todos los resultados."]
  ::msgcat::mcset sk "Search or replace all expressions in the file." [encoding convertfrom utf-8 "N\303\241jdi alebo nahra\304\217 v\305\241etky v\303\275razy v s\303\272bore."]

  ::msgcat::mcset cz "Clear" [encoding convertfrom utf-8 "Zru\305\241it"]
  ::msgcat::mcset en "Clear" [encoding convertfrom utf-8 "Clear"]
  ::msgcat::mcset es "Clear" [encoding convertfrom utf-8 "Deseleccionar"]
  ::msgcat::mcset sk "Clear" [encoding convertfrom utf-8 "Vy\304\215isti"]

  ::msgcat::mcset cz "Clear all highlights in the file." [encoding convertfrom utf-8 "Zru\305\241\303\255 zv\303\275razn\304\233n\303\255 nalezen\303\275ch v\303\275raz\305\257 v souboru."]
  ::msgcat::mcset en "Clear all highlights in the file." [encoding convertfrom utf-8 "Clear all highlights in the file."]
  ::msgcat::mcset es "Clear all highlights in the file." [encoding convertfrom utf-8 "Deseleccionar todo lo seleccionado."]
  ::msgcat::mcset sk "Clear all highlights in the file." [encoding convertfrom utf-8 "Zru\305\241\303\255 zv\303\275raznenie n\303\241jden\303\275ch v\303\275razov v s\303\272bore."]

  ::msgcat::mcset cz "Opening %s ..." [encoding convertfrom utf-8 "Otev\303\255r\303\241m %s ..."]
  ::msgcat::mcset en "Opening %s ..." [encoding convertfrom utf-8 "Opening %s ..."]
  ::msgcat::mcset es "Opening %s ..." [encoding convertfrom utf-8 "Abriendo %s ..."]
  ::msgcat::mcset sk "Opening %s ..." [encoding convertfrom utf-8 "Otev\303\241ram %s ..."]

  ::msgcat::mcset cz "File %s is not saved. Save it now?" [encoding convertfrom utf-8 "Soubor %s nen\303\255 ulo\305\276en. Ulo\305\276it nyn\303\255?"]
  ::msgcat::mcset en "File %s is not saved. Save it now?" [encoding convertfrom utf-8 "File %s is not saved. Save it now?"]
  ::msgcat::mcset es "File %s is not saved. Save it now?" [encoding convertfrom utf-8 "El archivo %s no ha sido guardado. \302\277Guardar ahora?"]
  ::msgcat::mcset sk "File %s is not saved. Save it now?" [encoding convertfrom utf-8 "S\303\272bor %s nie je ulo\305\276en\303\275. Ulo\305\276i\305\245 teraz?"]

  ::msgcat::mcset cz "File %s was modified outside xtherion. Save it anyway?" [encoding convertfrom utf-8 "Soubor %s byl modifikov\303\241n mimo xtherion. P\305\231esto ulo\305\276it?"]
  ::msgcat::mcset en "File %s was modified outside xtherion. Save it anyway?" [encoding convertfrom utf-8 "File %s was modified outside xtherion. Save it anyway?"]
  ::msgcat::mcset es "File %s was modified outside xtherion. Save it anyway?" [encoding convertfrom utf-8 "El archivo %s ha sido modificado fuera de xtherion. \302\277Guardar de todos modos?"]
  ::msgcat::mcset sk "File %s was modified outside xtherion. Save it anyway?" [encoding convertfrom utf-8 "S\303\272bor %s bol modifikovan\303\275 mimo programu. Ulo\305\276i\305\245 aj tak?"]

  ::msgcat::mcset cz "Saving %s ..." [encoding convertfrom utf-8 "Ukl\303\241d\303\241m %s ..."]
  ::msgcat::mcset en "Saving %s ..." [encoding convertfrom utf-8 "Saving %s ..."]
  ::msgcat::mcset es "Saving %s ..." [encoding convertfrom utf-8 "Guardando %s ..."]
  ::msgcat::mcset sk "Saving %s ..." [encoding convertfrom utf-8 "Uklad\303\241m %s ..."]

  ::msgcat::mcset cz "New" [encoding convertfrom utf-8 "Nov\303\275"]
  ::msgcat::mcset en "New" [encoding convertfrom utf-8 "New"]
  ::msgcat::mcset es "New" [encoding convertfrom utf-8 "Nuevo"]
  ::msgcat::mcset sk "New" [encoding convertfrom utf-8 "Nov\303\275"]

  ::msgcat::mcset cz "Open" [encoding convertfrom utf-8 "Otev\305\231\303\255t..."]
  ::msgcat::mcset en "Open" [encoding convertfrom utf-8 "Open"]
  ::msgcat::mcset es "Open" [encoding convertfrom utf-8 "Abrir"]
  ::msgcat::mcset sk "Open" [encoding convertfrom utf-8 "Otvori\305\245"]

  ::msgcat::mcset cz "Save" [encoding convertfrom utf-8 "Ulo\305\276it"]
  ::msgcat::mcset en "Save" [encoding convertfrom utf-8 "Save"]
  ::msgcat::mcset es "Save" [encoding convertfrom utf-8 "Guardar"]
  ::msgcat::mcset sk "Save" [encoding convertfrom utf-8 "Ulo\305\276i\305\245"]

  ::msgcat::mcset cz "Save as" [encoding convertfrom utf-8 "Ulo\305\276it jako..."]
  ::msgcat::mcset en "Save as" [encoding convertfrom utf-8 "Save as"]
  ::msgcat::mcset es "Save as" [encoding convertfrom utf-8 "Guardar como"]
  ::msgcat::mcset sk "Save as" [encoding convertfrom utf-8 "Ulo\305\276i\305\245 ako"]

  ::msgcat::mcset cz "Save all" [encoding convertfrom utf-8 "Ulo\305\276it v\305\241e"]
  ::msgcat::mcset en "Save all" [encoding convertfrom utf-8 "Save all"]
  ::msgcat::mcset es "Save all" [encoding convertfrom utf-8 "Guardar todo"]
  ::msgcat::mcset sk "Save all" [encoding convertfrom utf-8 "Ulo\305\276i\305\245 v\305\241etko"]

  ::msgcat::mcset cz "Auto save" [encoding convertfrom utf-8 "Automaticky ukl\303\241dat"]
  ::msgcat::mcset en "Auto save" [encoding convertfrom utf-8 "Auto save"]
  ::msgcat::mcset es "Auto save" [encoding convertfrom utf-8 "Autoguardar"]
  ::msgcat::mcset sk "Auto save" [encoding convertfrom utf-8 "Uklada\305\245 automaticky"]

  ::msgcat::mcset cz "Next" [encoding convertfrom utf-8 "N\303\241sleduj\303\255c\303\255"]
  ::msgcat::mcset en "Next" [encoding convertfrom utf-8 "Next"]
  ::msgcat::mcset es "Next" [encoding convertfrom utf-8 "Siguiente"]
  ::msgcat::mcset sk "Next" [encoding convertfrom utf-8 "Nasleduj\303\272ci"]

  ::msgcat::mcset cz "Previous" [encoding convertfrom utf-8 "P\305\231edchoz\303\255"]
  ::msgcat::mcset en "Previous" [encoding convertfrom utf-8 "Previous"]
  ::msgcat::mcset es "Previous" [encoding convertfrom utf-8 "Anterior"]
  ::msgcat::mcset sk "Previous" [encoding convertfrom utf-8 "Predch\303\241dzaj\303\272ci"]

  ::msgcat::mcset cz "Edit" [encoding convertfrom utf-8 "Editovat"]
  ::msgcat::mcset en "Edit" [encoding convertfrom utf-8 "Edit"]
  ::msgcat::mcset es "Edit" [encoding convertfrom utf-8 "Editar"]
  ::msgcat::mcset sk "Edit" [encoding convertfrom utf-8 "Upravi\305\245"]

  ::msgcat::mcset cz "Undo" [encoding convertfrom utf-8 "Zp\304\233t"]
  ::msgcat::mcset en "Undo" [encoding convertfrom utf-8 "Undo"]
  ::msgcat::mcset es "Undo" [encoding convertfrom utf-8 "Deshacer"]
  ::msgcat::mcset sk "Undo" [encoding convertfrom utf-8 "Sp\303\244\305\245"]

  ::msgcat::mcset cz "Redo" [encoding convertfrom utf-8 "Opakovat"]
  ::msgcat::mcset en "Redo" [encoding convertfrom utf-8 "Redo"]
  ::msgcat::mcset es "Redo" [encoding convertfrom utf-8 "Rehacer"]
  ::msgcat::mcset sk "Redo" [encoding convertfrom utf-8 "Opakova\305\245"]

  ::msgcat::mcset cz "Cut" [encoding convertfrom utf-8 "Vyjmout"]
  ::msgcat::mcset en "Cut" [encoding convertfrom utf-8 "Cut"]
  ::msgcat::mcset es "Cut" [encoding convertfrom utf-8 "Cortar"]
  ::msgcat::mcset sk "Cut" [encoding convertfrom utf-8 "Vystrihn\303\272\305\245"]

  ::msgcat::mcset cz "Copy" [encoding convertfrom utf-8 "Kop\303\255rovat"]
  ::msgcat::mcset en "Copy" [encoding convertfrom utf-8 "Copy"]
  ::msgcat::mcset es "Copy" [encoding convertfrom utf-8 "Copiar"]
  ::msgcat::mcset sk "Copy" [encoding convertfrom utf-8 "Kop\303\255rova\305\245"]

  ::msgcat::mcset cz "Paste" [encoding convertfrom utf-8 "Vlo\305\276it"]
  ::msgcat::mcset en "Paste" [encoding convertfrom utf-8 "Paste"]
  ::msgcat::mcset es "Paste" [encoding convertfrom utf-8 "Pegar"]
  ::msgcat::mcset sk "Paste" [encoding convertfrom utf-8 "Vlo\305\276i\305\245"]

  ::msgcat::mcset cz "Select all" [encoding convertfrom utf-8 "Vybrat v\305\241e"]
  ::msgcat::mcset en "Select all" [encoding convertfrom utf-8 "Select all"]
  ::msgcat::mcset es "Select all" [encoding convertfrom utf-8 "Seleccionar todo"]
  ::msgcat::mcset sk "Select all" [encoding convertfrom utf-8 "Vyber v\305\241etko"]

  ::msgcat::mcset cz "Auto indent" [encoding convertfrom utf-8 "Automaticky odsazovat"]
  ::msgcat::mcset en "Auto indent" [encoding convertfrom utf-8 "Auto indent"]
  ::msgcat::mcset es "Auto indent" [encoding convertfrom utf-8 "Autoindentar"]
  ::msgcat::mcset sk "Auto indent" [encoding convertfrom utf-8 "Automatick\303\251 odsadenie"]

  ::msgcat::mcset cz "Processing line %s ..." [encoding convertfrom utf-8 "Zpracov\303\241v\303\241m \305\231\303\241dek %s ..."]
  ::msgcat::mcset en "Processing line %s ..." [encoding convertfrom utf-8 "Processing line %s ..."]
  ::msgcat::mcset es "Processing line %s ..." [encoding convertfrom utf-8 "Procesando l\303\255nea %s ..."]
  ::msgcat::mcset sk "Processing line %s ..." [encoding convertfrom utf-8 "Sprac\303\272vam riadok %s ..."]

  ::msgcat::mcset en "Text editor is not active. To activate it, open existing file or create new one." [encoding convertfrom utf-8 "Text editor is not active. To activate it, open existing file or create new one."]
  ::msgcat::mcset es "Text editor is not active. To activate it, open existing file or create new one." [encoding convertfrom utf-8 "El editor de texto est\303\241 inactivo. Para activarlo, abre un archivo existente o crea uno nuevo."]
  ::msgcat::mcset sk "Text editor is not active. To activate it, open existing file or create new one." [encoding convertfrom utf-8 "Textov\303\275 editor nie je akt\303\255vny. Otvorte existuj\303\272ci s\303\272bor alebo vytvorte nov\303\275."]

  ::msgcat::mcset cz "Control..." [encoding convertfrom utf-8 "Ovl\303\241d\303\241n\303\255..."]
  ::msgcat::mcset en "Control..." [encoding convertfrom utf-8 "Control..."]
  ::msgcat::mcset es "Control..." [encoding convertfrom utf-8 "Control"]
  ::msgcat::mcset sk "Control..." [encoding convertfrom utf-8 "Ovl\303\241danie..."]

  ::msgcat::mcset cz "BAC calculator..." [encoding convertfrom utf-8 "Alkohol tester..."]
  ::msgcat::mcset en "BAC calculator..." [encoding convertfrom utf-8 "BAC calculator..."]
  ::msgcat::mcset es "BAC calculator..." [encoding convertfrom utf-8 "Borrach\303\255metro"]
  ::msgcat::mcset sk "BAC calculator..." [encoding convertfrom utf-8 "Alkohol tester..."]

  ::msgcat::mcset cz "About..." [encoding convertfrom utf-8 "O programu..."]
  ::msgcat::mcset en "About..." [encoding convertfrom utf-8 "About..."]
  ::msgcat::mcset es "About..." [encoding convertfrom utf-8 "Acerca de..."]
  ::msgcat::mcset sk "About..." [encoding convertfrom utf-8 "O programe..."]

  ::msgcat::mcset cz "Search" [encoding convertfrom utf-8 "Hledat"]
  ::msgcat::mcset en "Search" [encoding convertfrom utf-8 "Search"]
  ::msgcat::mcset es "Search" [encoding convertfrom utf-8 "Buscar"]
  ::msgcat::mcset sk "Search" [encoding convertfrom utf-8 "H\304\276ada\305\245"]

  ::msgcat::mcset cz "Close" [encoding convertfrom utf-8 "Zav\305\231\303\255t"]
  ::msgcat::mcset en "Close" [encoding convertfrom utf-8 "Close"]
  ::msgcat::mcset es "Close" [encoding convertfrom utf-8 "Cerrar"]
  ::msgcat::mcset sk "Close" [encoding convertfrom utf-8 "Zavrie\305\245"]







::msgcat::mcset en "xtherion_help_control" [encoding convertfrom utf-8 {

MAP EDITOR SHORTCUTS
  
General shortcuts
 * Ctrl+Z = undo
 * Ctrl+Y = redo
 * F9 = compile current project
 * to select object in the listbox using keyboard:
    switch using "Tab" into desired listbox;
    move with underlined cursor to desired object;
    press "Space"

Drawing area and background images
 * RightClick = scroll drawing area
 * Double RightClick on the image = move the image
 
Inserting scrap
 * press "Ctrl-r" or "Edit" > "Insert" > "scrap" to insert new scrap
 * new scrap is inserted just after the current one

Inserting point
 * Ctrl+P = switch to `insert point' mode
 * LeftClick = insert point at given position
 * Ctrl+LeftClick = insert point very close to existing point (normally it
    will be inserted right above the closest point)
 * Esc = escape from the `inset point' mode

Editing point
 * LeftClick + drag = move point
 * Ctrl+LeftClick + drag = move point close to the existing
    point (normally it is moved right above closest existing point)
 * LeftClick + drag on point arrows = change point orientation or
    sizes (according to given switches in Point cotrol panel)

Inserting line
 * Crtl+L = insert new line and enter an `insert line point' mode
 * LeftClick = insert line point (without control points)
 * Ctrl+LeftClick = insert line point very close to existing point 
    (normally it's inserted right above closest existing point)
 * LeftClick + drag = insert line point (with control points)
 * hold Ctrl while dragging = fix the distance of previous control point
 * LeftClick + drag on the control point = move its position
 * RightClick on one of the previous points = selects the previous point while 
    in insert mode (useful if you want to change also the direction of
    previous control point)
 * Esc or LeftClick on the last point = end the line insertion
 * LeftClick on the first line point = close the line and end line insertion

Editing line
 * LeftClick + drag = move line point
 * Ctrl+LeftClick + drag = move line point close to the existing
    point (normally it is moved right above closest existing point)
 * LeftClick on control point + drag = move control point

Adding line point
 * select the point before which you want to insert points;
    insert required points;
    press Esc or left-click on the point you selected at the begining
  
Deleting line point
 * select the point you want to delete;
    press "Edit line" > "Delete point" in the Line control panel
    
Splitting line
 * select the point at which you want to split the line;
    press "Edit line" > "Split line" in the Line control panel
    
Inserting area
 * press "Ctrl-a" or "Edit" > "Insert" > "area" to switch to 
    the "insert area border" mode
 * RightClick on the lines, that suround desired area
 * Esc to finish area border lines insertion

Editing area
 * select area you want to edit
 * pres "Insert" in the area control to insert other border lines
    at current cursor position
 * pres "Insert ID" to insert border with given ID at current cursor position
 * pres "Delete" to remove selected area border line
    
Selecting an existing object
 * LeftClick = select object on the top
 * RightClick = select object right below the top object (useful when several
    points lie above each other)
}]

::msgcat::mcset es "xtherion_help_control" [encoding convertfrom utf-8 {

ATAJOS DE TECLADO PARA EDITAR MAPAS

Atajos generales
 * Ctrl+Z = Deshacer
 * Ctrl+Y = Rehacer
 * F9 = Compilar proyecto actual
 * para seleccionar en los menús usando el teclado:
   Pulsar "Tab" hasta seleccionar el menú deseado;
   Moverse con las flechas hasta el objeto deseado;
   pulsar "Espacio"
   
Area de dibujo e imáges de fondo
 * Click Dcho = desplazar área de dibujo
 * Doble click dcho en la imagen = mover la imagen

Insertar croquis
 * Pulsar "Ctrl-r" o "Editar" > "Insertar" > "Croquis" para insertar un croquis nuevo
 * el nuevo croquis se insertará justo detrás del actual

Insertar punto
 * CTRL+P = cambiar a modo 'insertar punto'
 * Click = insertar punto en esa posición
 * Ctrl+Click = insertar punto muy cerca de otro punto
   (normalmente se insertará justo encima del punto más cercano)
 * Esc = salir del modo 'insertar punto'

Editar punto
 * Click en punto + arrastrar = mover el punto
 * Ctrl + Click en punto + Arrastrar = mover el punto cerca de otro
 * normalmente es movido justo encima del punto más cercano
 * Click en la punta de una flecha + arrastrar = cambiar la orientación o
   el tamaño (segun lo indicado en el panel de control Punto)

Insertar línea
 * Ctrl+L = insertar nueva línea y pasar al modo "insertar puntos de línea"
 * Click = insertar punto de línea (sin puntos de control)
 * Ctrl+Click = Insertar punto de línea muy cerca de otro
   (Normalmente se inserta justo encima del punto más cercano)
 * Click + arrastrar = insertar punto de línea (con puntos de control)
 * Pulsar Ctrl mientras se arrastra = fijar la distancia al punto de control anterior
 * Arrastra punto de control = cambir su posición
 * Click dcho en uno de los puntos anteriores = seleccionar ese punto anterior cuando
   estamos en modo inserción (Util si se quiere cambiar también la dirección
   del punto de control anterior)
 * Esc o Click en último punto de la línea = finaliza la inserción de línea
 * Click en el primer punto de la línea = cierra la línea y finaliza la inserción de línea

Editar línea
 * Click en punto + arrastrar = mover punto de línea
 * Ctrl+Click+arrastrar = mover punto de línea cerca de otro punto)
   (normalmente se mueve justo encima del punto más cercano)
 * Click en punto de control + arrastrar = mover punto de control

Añadir puntos de línea
 * seleccionar el punto antes del cual se quieren insertar puntos
 * insertar los puntos que hagan falta
 * pulsar Esc o hacer click en el punto que se seleccionó al principio

Borrar puntos de línea
 * seleccionar el punto que se quiere borrar
 * pulsar "Editar" > "Borrar punto" en el panel de control Líneas

Partir líneas
 * seleccionar el punto en que se quiere cortar la línea
 * pulsar "Editar" > "Cortar línea" en el panel de control Líneas

Insertar áreas
 * pulsar Ctrl-a o "Editar" > "Insertar" > área en menú principal
 * para cambiar al modo "insertar límite de área"
 * Click dcho en las líneas que limitarán el área
 * pulsar Esc para teminar la inserción de líneas límite

Editar áreas
 * seleccionar el área que se quiere editar
 * pulsar "Insertar" en el control area para insertar otras líneas límite
   en la posición del cursor
 * pulsar "Insertar ID" para insertar un límite con el ID que se indique en l posición del cursor
 * Pulsar "Borrar" para eliminae la línea límite seleccionada

Seleccionar objetos
 * Click = seleccionar el objeto que está sobre los demás
 * Click dcho = seleccionar el objeto que está en segundo plano
   (útil cuando varios puntos están superpuestos)
}]







set xth(point_types) {
	air-draught
	altitude
	anastomosis
	anchor
	aragonite
	archeo-material
	bedrock
	blocks
	breakdown-choke
	bridge
	camp
	cave-pearl
	clay
	continuation
	crystal
	curtain
	date
	debris
	dimensions
	disk
	entrance
	fixed-ladder
	flowstone
	flowstone-choke
	flute
	gradient
	guano
	gypsum
	gypsum-flower
	height
	helictite
	ice
	karren
	label
	low-end
	moonmilk
	narrow-end
	no-equipment
	paleo-material
	passage-height
	pebbles
	pillar
	popcorn
	raft
	raft-cone
	remark
	rimstone-dam
	rimstone-pool
	root
	rope
	rope-ladder
	sand
	scallop
	section
	sink
	snow
	soda-straw
	spring
	stalactite
	stalagmite
	station
	station-name
	steps
	traverse
	vegetable-debris
	wall-calcite
	water
	water-flow
}

set xth(line_types) {
	arrow
	border
	ceiling-meander
	ceiling-step
	chimney
	contour
	floor-meander
	floor-step
	flowstone
	gradient
	label
	overhang
	pit
	rock-border
	rock-edge
	section
	slope
	survey
	wall
	water-flow
}

set xth(area_types) {
	blocks
	clay
	debris
	ice
	pebbles
	sand
	snow
	sump
	water
}

::msgcat::mcset cz "point air-draught" [encoding convertfrom utf-8 "pr\305\257van"]
::msgcat::mcset en "point air-draught" [encoding convertfrom utf-8 "air draught"]
::msgcat::mcset en_UK "point air-draught" [encoding convertfrom utf-8 "air draught"]
::msgcat::mcset en_US "point air-draught" [encoding convertfrom utf-8 "air draught"]
::msgcat::mcset es "point air-draught" [encoding convertfrom utf-8 "corriente aire"]
::msgcat::mcset fr "point air-draught" [encoding convertfrom utf-8 "courant d\342\200\231air"]
::msgcat::mcset sk "point air-draught" [encoding convertfrom utf-8 "prievan"]
::msgcat::mcset cz "point altitude" [encoding convertfrom utf-8 "nadmo\305\231sk\303\241 v\303\275\305\241ka bodu v chodb\304\233"]
::msgcat::mcset en "point altitude" [encoding convertfrom utf-8 "altitude"]
::msgcat::mcset en_UK "point altitude" [encoding convertfrom utf-8 "altitude"]
::msgcat::mcset en_US "point altitude" [encoding convertfrom utf-8 "altitude"]
::msgcat::mcset es "point altitude" [encoding convertfrom utf-8 "altura"]
::msgcat::mcset fr "point altitude" [encoding convertfrom utf-8 "altitude"]
::msgcat::mcset sk "point altitude" [encoding convertfrom utf-8 "nadmorsk\303\241 v\303\275\305\241ka bodu v chodbe"]
::msgcat::mcset cz "point anastomosis" [encoding convertfrom utf-8 "anastom\303\263za"]
::msgcat::mcset en "point anastomosis" [encoding convertfrom utf-8 "anastomosis"]
::msgcat::mcset en_UK "point anastomosis" [encoding convertfrom utf-8 "anastomosis"]
::msgcat::mcset en_US "point anastomosis" [encoding convertfrom utf-8 "anastomosis"]
::msgcat::mcset es "point anastomosis" [encoding convertfrom utf-8 "anastomosis"]
::msgcat::mcset fr "point anastomosis" [encoding convertfrom utf-8 "anastomose"]
::msgcat::mcset sk "point anastomosis" [encoding convertfrom utf-8 "anastom\303\263za"]
::msgcat::mcset cz "point anchor" [encoding convertfrom utf-8 "kotven\303\255"]
::msgcat::mcset en "point anchor" [encoding convertfrom utf-8 "anchor"]
::msgcat::mcset en_UK "point anchor" [encoding convertfrom utf-8 "anchor"]
::msgcat::mcset en_US "point anchor" [encoding convertfrom utf-8 "anchor"]
::msgcat::mcset es "point anchor" [encoding convertfrom utf-8 "anclaje"]
::msgcat::mcset fr "point anchor" [encoding convertfrom utf-8 "ancrage"]
::msgcat::mcset sk "point anchor" [encoding convertfrom utf-8 "kotvenie"]
::msgcat::mcset cz "point aragonite" [encoding convertfrom utf-8 "aragonit"]
::msgcat::mcset en "point aragonite" [encoding convertfrom utf-8 "aragonite"]
::msgcat::mcset en_UK "point aragonite" [encoding convertfrom utf-8 "aragonite"]
::msgcat::mcset en_US "point aragonite" [encoding convertfrom utf-8 "aragonite"]
::msgcat::mcset es "point aragonite" [encoding convertfrom utf-8 "aragonito"]
::msgcat::mcset fr "point aragonite" [encoding convertfrom utf-8 "aragonite"]
::msgcat::mcset sk "point aragonite" [encoding convertfrom utf-8 "aragonit"]
::msgcat::mcset cz "point archeo-material" [encoding convertfrom utf-8 "archeologick\303\251 n\303\241lezy"]
::msgcat::mcset en "point archeo-material" [encoding convertfrom utf-8 "archeo material"]
::msgcat::mcset en_UK "point archeo-material" [encoding convertfrom utf-8 "archeo material"]
::msgcat::mcset en_US "point archeo-material" [encoding convertfrom utf-8 "archeo material"]
::msgcat::mcset es "point archeo-material" [encoding convertfrom utf-8 "yacimiento (arq)"]
::msgcat::mcset fr "point archeo-material" [encoding convertfrom utf-8 "mat\303\251riel arch\303\251o"]
::msgcat::mcset sk "point archeo-material" [encoding convertfrom utf-8 "archeologick\303\251 n\303\241lezy"]
::msgcat::mcset cz "point bedrock" [encoding convertfrom utf-8 "pevn\303\241 sk\303\241la"]
::msgcat::mcset en "point bedrock" [encoding convertfrom utf-8 "bedrock"]
::msgcat::mcset en_UK "point bedrock" [encoding convertfrom utf-8 "bedrock"]
::msgcat::mcset en_US "point bedrock" [encoding convertfrom utf-8 "bedrock"]
::msgcat::mcset es "point bedrock" [encoding convertfrom utf-8 "roca madre"]
::msgcat::mcset fr "point bedrock" [encoding convertfrom utf-8 "roche"]
::msgcat::mcset sk "point bedrock" [encoding convertfrom utf-8 "pevn\303\241 skala"]
::msgcat::mcset cz "point blocks" [encoding convertfrom utf-8 "kamenn\303\251 bloky"]
::msgcat::mcset en "point blocks" [encoding convertfrom utf-8 "blocks, breakdown"]
::msgcat::mcset en_UK "point blocks" [encoding convertfrom utf-8 "blocks, breakdown"]
::msgcat::mcset en_US "point blocks" [encoding convertfrom utf-8 "blocks, breakdown"]
::msgcat::mcset es "point blocks" [encoding convertfrom utf-8 "bloques"]
::msgcat::mcset fr "point blocks" [encoding convertfrom utf-8 "blocs"]
::msgcat::mcset sk "point blocks" [encoding convertfrom utf-8 "kamenn\303\251 bloky"]
::msgcat::mcset cz "point breakdown-choke" [encoding convertfrom utf-8 "zavalen\303\275 konec"]
::msgcat::mcset en "point breakdown-choke" [encoding convertfrom utf-8 "breakdown choke"]
::msgcat::mcset en_UK "point breakdown-choke" [encoding convertfrom utf-8 "breakdown choke"]
::msgcat::mcset en_US "point breakdown-choke" [encoding convertfrom utf-8 "breakdown choke"]
::msgcat::mcset es "point breakdown-choke" [encoding convertfrom utf-8 "colmatado por derrumbe"]
::msgcat::mcset fr "point breakdown-choke" [encoding convertfrom utf-8 "tr\303\251mie"]
::msgcat::mcset sk "point breakdown-choke" [encoding convertfrom utf-8 "zavalen\303\275 koniec"]
::msgcat::mcset cz "point bridge" [encoding convertfrom utf-8 "most"]
::msgcat::mcset en "point bridge" [encoding convertfrom utf-8 "bridge"]
::msgcat::mcset en_UK "point bridge" [encoding convertfrom utf-8 "bridge"]
::msgcat::mcset en_US "point bridge" [encoding convertfrom utf-8 "bridge"]
::msgcat::mcset es "point bridge" [encoding convertfrom utf-8 "puente roca"]
::msgcat::mcset fr "point bridge" [encoding convertfrom utf-8 "pont"]
::msgcat::mcset sk "point bridge" [encoding convertfrom utf-8 "most"]
::msgcat::mcset cz "point camp" [encoding convertfrom utf-8 "bivak"]
::msgcat::mcset en "point camp" [encoding convertfrom utf-8 "camp"]
::msgcat::mcset en_UK "point camp" [encoding convertfrom utf-8 "camp"]
::msgcat::mcset en_US "point camp" [encoding convertfrom utf-8 "camp"]
::msgcat::mcset es "point camp" [encoding convertfrom utf-8 "campamento"]
::msgcat::mcset fr "point camp" [encoding convertfrom utf-8 "camp"]
::msgcat::mcset sk "point camp" [encoding convertfrom utf-8 "bivak"]
::msgcat::mcset cz "point cave-pearl" [encoding convertfrom utf-8 "jeskynn\303\255 perly"]
::msgcat::mcset en "point cave-pearl" [encoding convertfrom utf-8 "cave pearl"]
::msgcat::mcset en_UK "point cave-pearl" [encoding convertfrom utf-8 "cave pearl"]
::msgcat::mcset en_US "point cave-pearl" [encoding convertfrom utf-8 "cave pearl"]
::msgcat::mcset es "point cave-pearl" [encoding convertfrom utf-8 "perla de caverna"]
::msgcat::mcset fr "point cave-pearl" [encoding convertfrom utf-8 "perle des cavernes"]
::msgcat::mcset sk "point cave-pearl" [encoding convertfrom utf-8 "jaskynn\303\251 perly"]
::msgcat::mcset cz "point clay" [encoding convertfrom utf-8 "bahno"]
::msgcat::mcset en "point clay" [encoding convertfrom utf-8 "clay"]
::msgcat::mcset en_UK "point clay" [encoding convertfrom utf-8 "clay"]
::msgcat::mcset en_US "point clay" [encoding convertfrom utf-8 "clay"]
::msgcat::mcset es "point clay" [encoding convertfrom utf-8 "arcilla"]
::msgcat::mcset fr "point clay" [encoding convertfrom utf-8 "argile"]
::msgcat::mcset sk "point clay" [encoding convertfrom utf-8 "blato"]
::msgcat::mcset cz "point continuation" [encoding convertfrom utf-8 "mo\305\276n\303\251 pokra\304\215ov\303\241n\303\255"]
::msgcat::mcset en "point continuation" [encoding convertfrom utf-8 "possible continuation"]
::msgcat::mcset en_UK "point continuation" [encoding convertfrom utf-8 "possible continuation"]
::msgcat::mcset en_US "point continuation" [encoding convertfrom utf-8 "possible continuation"]
::msgcat::mcset es "point continuation" [encoding convertfrom utf-8 "continuaci\303\263n"]
::msgcat::mcset fr "point continuation" [encoding convertfrom utf-8 "suite possible"]
::msgcat::mcset sk "point continuation" [encoding convertfrom utf-8 "mo\305\276n\303\251 pokra\304\215ovanie"]
::msgcat::mcset cz "point crystal" [encoding convertfrom utf-8 "krystal"]
::msgcat::mcset en "point crystal" [encoding convertfrom utf-8 "crystal"]
::msgcat::mcset en_UK "point crystal" [encoding convertfrom utf-8 "crystal"]
::msgcat::mcset en_US "point crystal" [encoding convertfrom utf-8 "crystal"]
::msgcat::mcset es "point crystal" [encoding convertfrom utf-8 "cristal"]
::msgcat::mcset fr "point crystal" [encoding convertfrom utf-8 "cristaux"]
::msgcat::mcset sk "point crystal" [encoding convertfrom utf-8 "kry\305\241t\303\241l"]
::msgcat::mcset cz "point curtain" [encoding convertfrom utf-8 "sintrov\303\251 z\303\241clony"]
::msgcat::mcset en "point curtain" [encoding convertfrom utf-8 "curtain"]
::msgcat::mcset en_UK "point curtain" [encoding convertfrom utf-8 "curtain"]
::msgcat::mcset en_US "point curtain" [encoding convertfrom utf-8 "curtain"]
::msgcat::mcset es "point curtain" [encoding convertfrom utf-8 "cortina"]
::msgcat::mcset fr "point curtain" [encoding convertfrom utf-8 "rideau"]
::msgcat::mcset sk "point curtain" [encoding convertfrom utf-8 "sintrov\303\251 z\303\241clony"]
::msgcat::mcset cz "point date" [encoding convertfrom utf-8 "datum pozorov\303\241n\303\255"]
::msgcat::mcset en "point date" [encoding convertfrom utf-8 "date of observation"]
::msgcat::mcset en_UK "point date" [encoding convertfrom utf-8 "date of observation"]
::msgcat::mcset en_US "point date" [encoding convertfrom utf-8 "date of observation"]
::msgcat::mcset es "point date" [encoding convertfrom utf-8 "fecha"]
::msgcat::mcset fr "point date" [encoding convertfrom utf-8 "date"]
::msgcat::mcset sk "point date" [encoding convertfrom utf-8 "d\303\241tum pozorovania"]
::msgcat::mcset cz "point debris" [encoding convertfrom utf-8 "\305\241t\304\233rk"]
::msgcat::mcset en "point debris" [encoding convertfrom utf-8 "debris"]
::msgcat::mcset en_UK "point debris" [encoding convertfrom utf-8 "debris"]
::msgcat::mcset en_US "point debris" [encoding convertfrom utf-8 "debris"]
::msgcat::mcset es "point debris" [encoding convertfrom utf-8 "derrubios"]
::msgcat::mcset fr "point debris" [encoding convertfrom utf-8 "d\303\251bris"]
::msgcat::mcset sk "point debris" [encoding convertfrom utf-8 "\305\241trk"]
::msgcat::mcset sk "point dimensions" [encoding convertfrom utf-8 "rozmery"]
::msgcat::mcset cz "point disk" [encoding convertfrom utf-8 "disk"]
::msgcat::mcset en "point disk" [encoding convertfrom utf-8 "disk"]
::msgcat::mcset en_UK "point disk" [encoding convertfrom utf-8 "disk"]
::msgcat::mcset en_US "point disk" [encoding convertfrom utf-8 "disk"]
::msgcat::mcset es "point disk" [encoding convertfrom utf-8 "disco"]
::msgcat::mcset fr "point disk" [encoding convertfrom utf-8 "disque"]
::msgcat::mcset sk "point disk" [encoding convertfrom utf-8 "disk"]
::msgcat::mcset cz "point entrance" [encoding convertfrom utf-8 "vchod"]
::msgcat::mcset en "point entrance" [encoding convertfrom utf-8 "entrance"]
::msgcat::mcset en_UK "point entrance" [encoding convertfrom utf-8 "entrance"]
::msgcat::mcset en_US "point entrance" [encoding convertfrom utf-8 "entrance"]
::msgcat::mcset es "point entrance" [encoding convertfrom utf-8 "boca"]
::msgcat::mcset fr "point entrance" [encoding convertfrom utf-8 "entr\303\251e"]
::msgcat::mcset sk "point entrance" [encoding convertfrom utf-8 "vchod"]
::msgcat::mcset cz "point fixed-ladder" [encoding convertfrom utf-8 "pevn\303\275 \305\276eb\305\231\303\255k"]
::msgcat::mcset en "point fixed-ladder" [encoding convertfrom utf-8 "fixed ladder"]
::msgcat::mcset en_UK "point fixed-ladder" [encoding convertfrom utf-8 "fixed ladder"]
::msgcat::mcset en_US "point fixed-ladder" [encoding convertfrom utf-8 "fixed ladder"]
::msgcat::mcset es "point fixed-ladder" [encoding convertfrom utf-8 "escala fija"]
::msgcat::mcset fr "point fixed-ladder" [encoding convertfrom utf-8 "\303\251chelle fixe"]
::msgcat::mcset sk "point fixed-ladder" [encoding convertfrom utf-8 "fixn\303\275 rebr\303\255k"]
::msgcat::mcset cz "point flowstone" [encoding convertfrom utf-8 "sintr"]
::msgcat::mcset en "point flowstone" [encoding convertfrom utf-8 "flowstone"]
::msgcat::mcset en_UK "point flowstone" [encoding convertfrom utf-8 "flowstone"]
::msgcat::mcset en_US "point flowstone" [encoding convertfrom utf-8 "flowstone"]
::msgcat::mcset es "point flowstone" [encoding convertfrom utf-8 "concreci\303\263n"]
::msgcat::mcset fr "point flowstone" [encoding convertfrom utf-8 "concr\303\251tions"]
::msgcat::mcset sk "point flowstone" [encoding convertfrom utf-8 "sinter"]
::msgcat::mcset cz "point flowstone-choke" [encoding convertfrom utf-8 "zasintrovan\303\275 konec"]
::msgcat::mcset en "point flowstone-choke" [encoding convertfrom utf-8 "flowstone choke"]
::msgcat::mcset en_UK "point flowstone-choke" [encoding convertfrom utf-8 "flowstone choke"]
::msgcat::mcset en_US "point flowstone-choke" [encoding convertfrom utf-8 "flowstone choke"]
::msgcat::mcset es "point flowstone-choke" [encoding convertfrom utf-8 "colmatado por concreci\303\263n"]
::msgcat::mcset fr "point flowstone-choke" [encoding convertfrom utf-8 "tr\303\251mie calcifi\303\251e"]
::msgcat::mcset sk "point flowstone-choke" [encoding convertfrom utf-8 "zasintren\303\275 koniec"]
::msgcat::mcset cz "point flute" [encoding convertfrom utf-8 "p\303\255\305\241\305\245aly"]
::msgcat::mcset en "point flute" [encoding convertfrom utf-8 "flute"]
::msgcat::mcset en_UK "point flute" [encoding convertfrom utf-8 "flute"]
::msgcat::mcset en_US "point flute" [encoding convertfrom utf-8 "flute"]
::msgcat::mcset es "point flute" [encoding convertfrom utf-8 "canaleta"]
::msgcat::mcset fr "point flute" [encoding convertfrom utf-8 "flute (?)"]
::msgcat::mcset sk "point flute" [encoding convertfrom utf-8 "p\303\255\305\241\305\245aly"]
::msgcat::mcset cz "point gradient" [encoding convertfrom utf-8 "sklon chodby"]
::msgcat::mcset en "point gradient" [encoding convertfrom utf-8 "passage gradient"]
::msgcat::mcset en_UK "point gradient" [encoding convertfrom utf-8 "passage gradient"]
::msgcat::mcset en_US "point gradient" [encoding convertfrom utf-8 "passage gradient"]
::msgcat::mcset es "point gradient" [encoding convertfrom utf-8 "gradiente"]
::msgcat::mcset fr "point gradient" [encoding convertfrom utf-8 "pente"]
::msgcat::mcset sk "point gradient" [encoding convertfrom utf-8 "sklon chodby"]
::msgcat::mcset cz "point guano" [encoding convertfrom utf-8 "guano"]
::msgcat::mcset en "point guano" [encoding convertfrom utf-8 "guano"]
::msgcat::mcset en_UK "point guano" [encoding convertfrom utf-8 "guano"]
::msgcat::mcset en_US "point guano" [encoding convertfrom utf-8 "guano"]
::msgcat::mcset es "point guano" [encoding convertfrom utf-8 "guano"]
::msgcat::mcset fr "point guano" [encoding convertfrom utf-8 "guano"]
::msgcat::mcset sk "point guano" [encoding convertfrom utf-8 "gu\303\241no"]
::msgcat::mcset cz "point gypsum" [encoding convertfrom utf-8 "s\303\241drovec"]
::msgcat::mcset en "point gypsum" [encoding convertfrom utf-8 "gypsum"]
::msgcat::mcset en_UK "point gypsum" [encoding convertfrom utf-8 "gypsum"]
::msgcat::mcset en_US "point gypsum" [encoding convertfrom utf-8 "gypsum"]
::msgcat::mcset es "point gypsum" [encoding convertfrom utf-8 "yeso"]
::msgcat::mcset fr "point gypsum" [encoding convertfrom utf-8 "gypse"]
::msgcat::mcset sk "point gypsum" [encoding convertfrom utf-8 "s\303\241drovec"]
::msgcat::mcset cz "point gypsum-flower" [encoding convertfrom utf-8 "s\303\241drovcov\303\275 kv\304\233t"]
::msgcat::mcset en "point gypsum-flower" [encoding convertfrom utf-8 "gypsum flower"]
::msgcat::mcset en_UK "point gypsum-flower" [encoding convertfrom utf-8 "gypsum flower"]
::msgcat::mcset en_US "point gypsum-flower" [encoding convertfrom utf-8 "gypsum flower"]
::msgcat::mcset es "point gypsum-flower" [encoding convertfrom utf-8 "flor yeso"]
::msgcat::mcset fr "point gypsum-flower" [encoding convertfrom utf-8 "fleur de gypse"]
::msgcat::mcset sk "point gypsum-flower" [encoding convertfrom utf-8 "s\303\241drovcov\303\275 kvet"]
::msgcat::mcset cz "point height" [encoding convertfrom utf-8 "v\303\275\305\241ka stupn\304\233/kom\303\255nu/hloubka propasti"]
::msgcat::mcset en "point height" [encoding convertfrom utf-8 "the height of floor step/chimney/pit depth"]
::msgcat::mcset en_UK "point height" [encoding convertfrom utf-8 "the height of floor step/chimney/pit depth"]
::msgcat::mcset en_US "point height" [encoding convertfrom utf-8 "the height of floor step/chimney/pit depth"]
::msgcat::mcset es "point height" [encoding convertfrom utf-8 "altura resalte/chimenea/profundidad pozo"]
::msgcat::mcset fr "point height" [encoding convertfrom utf-8 "hauteur d\342\200\231une marche/d\342\200\231une chemin\303\251e/profondeur"]
::msgcat::mcset sk "point height" [encoding convertfrom utf-8 "v\303\275\305\241ka stup\305\210a/kom\303\255nu/h\304\272bka priepasti"]
::msgcat::mcset cz "point helictite" [encoding convertfrom utf-8 "heliktit"]
::msgcat::mcset en "point helictite" [encoding convertfrom utf-8 "helictite"]
::msgcat::mcset en_UK "point helictite" [encoding convertfrom utf-8 "helictite"]
::msgcat::mcset en_US "point helictite" [encoding convertfrom utf-8 "helictite"]
::msgcat::mcset es "point helictite" [encoding convertfrom utf-8 "exc\303\251ntrica"]
::msgcat::mcset fr "point helictite" [encoding convertfrom utf-8 "excentrique/h\303\251lictite"]
::msgcat::mcset sk "point helictite" [encoding convertfrom utf-8 "helektit"]
::msgcat::mcset cz "point ice" [encoding convertfrom utf-8 "led"]
::msgcat::mcset en "point ice" [encoding convertfrom utf-8 "ice"]
::msgcat::mcset en_UK "point ice" [encoding convertfrom utf-8 "ice"]
::msgcat::mcset en_US "point ice" [encoding convertfrom utf-8 "ice"]
::msgcat::mcset es "point ice" [encoding convertfrom utf-8 "hielo"]
::msgcat::mcset fr "point ice" [encoding convertfrom utf-8 "glace"]
::msgcat::mcset sk "point ice" [encoding convertfrom utf-8 "\304\276ad"]
::msgcat::mcset cz "point karren" [encoding convertfrom utf-8 "\305\241krapy"]
::msgcat::mcset en "point karren" [encoding convertfrom utf-8 "karren"]
::msgcat::mcset en_UK "point karren" [encoding convertfrom utf-8 "karren"]
::msgcat::mcset en_US "point karren" [encoding convertfrom utf-8 "karren"]
::msgcat::mcset es "point karren" [encoding convertfrom utf-8 "lapiaz"]
::msgcat::mcset fr "point karren" [encoding convertfrom utf-8 "lapiez"]
::msgcat::mcset sk "point karren" [encoding convertfrom utf-8 "\305\241krapy"]
::msgcat::mcset cz "point label" [encoding convertfrom utf-8 "pojmenov\303\241n\303\255"]
::msgcat::mcset sk "point label" [encoding convertfrom utf-8 "pomenovanie"]
::msgcat::mcset cz "point low-end" [encoding convertfrom utf-8 "nepr\305\257lezn\303\251 sn\303\255\305\276en\303\255"]
::msgcat::mcset en "point low-end" [encoding convertfrom utf-8 "passage low end"]
::msgcat::mcset en_UK "point low-end" [encoding convertfrom utf-8 "passage low end"]
::msgcat::mcset en_US "point low-end" [encoding convertfrom utf-8 "passage low end"]
::msgcat::mcset es "point low-end" [encoding convertfrom utf-8 "final bajo"]
::msgcat::mcset fr "point low-end" [encoding convertfrom utf-8 "passage bas"]
::msgcat::mcset sk "point low-end" [encoding convertfrom utf-8 "neprielezn\303\251 zn\303\255\305\276enie"]
::msgcat::mcset cz "point moonmilk" [encoding convertfrom utf-8 "nickam\303\255nek"]
::msgcat::mcset en "point moonmilk" [encoding convertfrom utf-8 "moonmilk"]
::msgcat::mcset en_UK "point moonmilk" [encoding convertfrom utf-8 "moonmilk"]
::msgcat::mcset en_US "point moonmilk" [encoding convertfrom utf-8 "moonmilk"]
::msgcat::mcset es "point moonmilk" [encoding convertfrom utf-8 "mondmilch"]
::msgcat::mcset fr "point moonmilk" [encoding convertfrom utf-8 "mondmilch"]
::msgcat::mcset sk "point moonmilk" [encoding convertfrom utf-8 "m\303\244kk\303\275 sinter"]
::msgcat::mcset cz "point narrow-end" [encoding convertfrom utf-8 "nepr\305\257lezn\303\251 z\303\272\305\276en\303\255"]
::msgcat::mcset en "point narrow-end" [encoding convertfrom utf-8 "passage narrow end"]
::msgcat::mcset en_UK "point narrow-end" [encoding convertfrom utf-8 "passage narrow end"]
::msgcat::mcset en_US "point narrow-end" [encoding convertfrom utf-8 "passage narrow end"]
::msgcat::mcset es "point narrow-end" [encoding convertfrom utf-8 "final estrecho"]
::msgcat::mcset fr "point narrow-end" [encoding convertfrom utf-8 "passage imp\303\251n\303\251trable"]
::msgcat::mcset sk "point narrow-end" [encoding convertfrom utf-8 "neprielezn\303\251 z\303\272\305\276enie"]
::msgcat::mcset cz "point no-equipment" [encoding convertfrom utf-8 "nevystrojen\303\251 m\303\255sto"]
::msgcat::mcset en "point no-equipment" [encoding convertfrom utf-8 "place without equipement"]
::msgcat::mcset en_UK "point no-equipment" [encoding convertfrom utf-8 "place without equipement"]
::msgcat::mcset en_US "point no-equipment" [encoding convertfrom utf-8 "place without equipement"]
::msgcat::mcset es "point no-equipment" [encoding convertfrom utf-8 "sin equipar"]
::msgcat::mcset fr "point no-equipment" [encoding convertfrom utf-8 "pas d\342\200\231\303\251quipement"]
::msgcat::mcset sk "point no-equipment" [encoding convertfrom utf-8 "nevystrojen\303\251 miesto"]
::msgcat::mcset cz "point paleo-material" [encoding convertfrom utf-8 "paleontologick\303\251 n\303\241lezy"]
::msgcat::mcset en "point paleo-material" [encoding convertfrom utf-8 "paleo material"]
::msgcat::mcset en_UK "point paleo-material" [encoding convertfrom utf-8 "paleo material"]
::msgcat::mcset en_US "point paleo-material" [encoding convertfrom utf-8 "paleo material"]
::msgcat::mcset es "point paleo-material" [encoding convertfrom utf-8 "yacimiento (pal)"]
::msgcat::mcset fr "point paleo-material" [encoding convertfrom utf-8 "mat\303\251riel pal\303\251o"]
::msgcat::mcset sk "point paleo-material" [encoding convertfrom utf-8 "paleontologick\303\251 n\303\241lezy"]
::msgcat::mcset cz "point passage-height" [encoding convertfrom utf-8 "v\303\275\305\241ka chodby"]
::msgcat::mcset en "point passage-height" [encoding convertfrom utf-8 "passage height"]
::msgcat::mcset en_UK "point passage-height" [encoding convertfrom utf-8 "passage height"]
::msgcat::mcset en_US "point passage-height" [encoding convertfrom utf-8 "passage height"]
::msgcat::mcset es "point passage-height" [encoding convertfrom utf-8 "altura"]
::msgcat::mcset fr "point passage-height" [encoding convertfrom utf-8 "hauteur du passage"]
::msgcat::mcset sk "point passage-height" [encoding convertfrom utf-8 "v\303\275\305\241ka chodby"]
::msgcat::mcset cz "point pebbles" [encoding convertfrom utf-8 "valouny"]
::msgcat::mcset en "point pebbles" [encoding convertfrom utf-8 "pebbles"]
::msgcat::mcset en_UK "point pebbles" [encoding convertfrom utf-8 "pebbles"]
::msgcat::mcset en_US "point pebbles" [encoding convertfrom utf-8 "pebbles"]
::msgcat::mcset es "point pebbles" [encoding convertfrom utf-8 "cantos rodados"]
::msgcat::mcset fr "point pebbles" [encoding convertfrom utf-8 "galets"]
::msgcat::mcset sk "point pebbles" [encoding convertfrom utf-8 "okruhliaky"]
::msgcat::mcset cz "point pillar" [encoding convertfrom utf-8 "stalagn\303\241t"]
::msgcat::mcset en "point pillar" [encoding convertfrom utf-8 "pillar"]
::msgcat::mcset en_UK "point pillar" [encoding convertfrom utf-8 "pillar"]
::msgcat::mcset en_US "point pillar" [encoding convertfrom utf-8 "pillar"]
::msgcat::mcset es "point pillar" [encoding convertfrom utf-8 "pilar"]
::msgcat::mcset fr "point pillar" [encoding convertfrom utf-8 "pillier"]
::msgcat::mcset sk "point pillar" [encoding convertfrom utf-8 "stalagn\303\241t"]
::msgcat::mcset cz "point popcorn" [encoding convertfrom utf-8 "pizolity"]
::msgcat::mcset en "point popcorn" [encoding convertfrom utf-8 "popcorn"]
::msgcat::mcset en_UK "point popcorn" [encoding convertfrom utf-8 "popcorn"]
::msgcat::mcset en_US "point popcorn" [encoding convertfrom utf-8 "popcorn"]
::msgcat::mcset es "point popcorn" [encoding convertfrom utf-8 "coliflor"]
::msgcat::mcset fr "point popcorn" [encoding convertfrom utf-8 "choux-fleur"]
::msgcat::mcset sk "point popcorn" [encoding convertfrom utf-8 "pizolity"]
::msgcat::mcset cz "point raft" [encoding convertfrom utf-8 "n\303\241plav"]
::msgcat::mcset en "point raft" [encoding convertfrom utf-8 "raft"]
::msgcat::mcset en_UK "point raft" [encoding convertfrom utf-8 "raft"]
::msgcat::mcset en_US "point raft" [encoding convertfrom utf-8 "raft"]
::msgcat::mcset es "point raft" [encoding convertfrom utf-8 "calcita flotante"]
::msgcat::mcset fr "point raft" [encoding convertfrom utf-8 "calcite flottante"]
::msgcat::mcset sk "point raft" [encoding convertfrom utf-8 "n\303\241plav"]
::msgcat::mcset cz "point raft-cone" [encoding convertfrom utf-8 "n\303\241plavov\303\275 ku\305\276el"]
::msgcat::mcset en "point raft-cone" [encoding convertfrom utf-8 "raft cone"]
::msgcat::mcset en_UK "point raft-cone" [encoding convertfrom utf-8 "raft cone"]
::msgcat::mcset en_US "point raft-cone" [encoding convertfrom utf-8 "raft cone"]
::msgcat::mcset es "point raft-cone" [encoding convertfrom utf-8 "conos"]
::msgcat::mcset fr "point raft-cone" [encoding convertfrom utf-8 "cone"]
::msgcat::mcset sk "point raft-cone" [encoding convertfrom utf-8 "n\303\241plavov\303\275 ku\305\276e\304\276"]
::msgcat::mcset cz "point remark" [encoding convertfrom utf-8 "pozn\303\241mka"]
::msgcat::mcset sk "point remark" [encoding convertfrom utf-8 "pozn\303\241mka"]
::msgcat::mcset cz "point rimstone-dam" [encoding convertfrom utf-8 "sintrov\303\241 hr\303\241zka"]
::msgcat::mcset en "point rimstone-dam" [encoding convertfrom utf-8 "rimstone dam"]
::msgcat::mcset en_UK "point rimstone-dam" [encoding convertfrom utf-8 "rimstone dam"]
::msgcat::mcset en_US "point rimstone-dam" [encoding convertfrom utf-8 "rimstone dam"]
::msgcat::mcset es "point rimstone-dam" [encoding convertfrom utf-8 "gour-presa"]
::msgcat::mcset fr "point rimstone-dam" [encoding convertfrom utf-8 "gours"]
::msgcat::mcset sk "point rimstone-dam" [encoding convertfrom utf-8 "sintrov\303\241 hr\303\241dza"]
::msgcat::mcset cz "point rimstone-pool" [encoding convertfrom utf-8 "sintrov\303\251 jez\303\255rko"]
::msgcat::mcset en "point rimstone-pool" [encoding convertfrom utf-8 "rimstone pool"]
::msgcat::mcset en_UK "point rimstone-pool" [encoding convertfrom utf-8 "rimstone pool"]
::msgcat::mcset en_US "point rimstone-pool" [encoding convertfrom utf-8 "rimstone pool"]
::msgcat::mcset es "point rimstone-pool" [encoding convertfrom utf-8 "gour-poza"]
::msgcat::mcset fr "point rimstone-pool" [encoding convertfrom utf-8 "gour"]
::msgcat::mcset sk "point rimstone-pool" [encoding convertfrom utf-8 "sintrov\303\251 jazierko"]
::msgcat::mcset cz "point root" [encoding convertfrom utf-8 "ko\305\231eny"]
::msgcat::mcset en "point root" [encoding convertfrom utf-8 "root"]
::msgcat::mcset en_UK "point root" [encoding convertfrom utf-8 "root"]
::msgcat::mcset en_US "point root" [encoding convertfrom utf-8 "root"]
::msgcat::mcset es "point root" [encoding convertfrom utf-8 "ra\303\255z"]
::msgcat::mcset fr "point root" [encoding convertfrom utf-8 "racine"]
::msgcat::mcset sk "point root" [encoding convertfrom utf-8 "korene"]
::msgcat::mcset cz "point rope" [encoding convertfrom utf-8 "lano"]
::msgcat::mcset en "point rope" [encoding convertfrom utf-8 "rope"]
::msgcat::mcset en_UK "point rope" [encoding convertfrom utf-8 "rope"]
::msgcat::mcset en_US "point rope" [encoding convertfrom utf-8 "rope"]
::msgcat::mcset es "point rope" [encoding convertfrom utf-8 "cuerda"]
::msgcat::mcset fr "point rope" [encoding convertfrom utf-8 "corde"]
::msgcat::mcset sk "point rope" [encoding convertfrom utf-8 "lano"]
::msgcat::mcset cz "point rope-ladder" [encoding convertfrom utf-8 "lanov\303\275 \305\276eb\305\231\303\255k"]
::msgcat::mcset en "point rope-ladder" [encoding convertfrom utf-8 "rope ladder"]
::msgcat::mcset en_UK "point rope-ladder" [encoding convertfrom utf-8 "rope ladder"]
::msgcat::mcset en_US "point rope-ladder" [encoding convertfrom utf-8 "rope ladder"]
::msgcat::mcset es "point rope-ladder" [encoding convertfrom utf-8 "escala"]
::msgcat::mcset fr "point rope-ladder" [encoding convertfrom utf-8 "\303\251chelle de corde"]
::msgcat::mcset sk "point rope-ladder" [encoding convertfrom utf-8 "lanov\303\275 rebr\303\255k"]
::msgcat::mcset cz "point sand" [encoding convertfrom utf-8 "p\303\255sek"]
::msgcat::mcset en "point sand" [encoding convertfrom utf-8 "sand"]
::msgcat::mcset en_UK "point sand" [encoding convertfrom utf-8 "sand"]
::msgcat::mcset en_US "point sand" [encoding convertfrom utf-8 "sand"]
::msgcat::mcset es "point sand" [encoding convertfrom utf-8 "arena"]
::msgcat::mcset fr "point sand" [encoding convertfrom utf-8 "sable"]
::msgcat::mcset sk "point sand" [encoding convertfrom utf-8 "piesok"]
::msgcat::mcset cz "point scallop" [encoding convertfrom utf-8 "erozn\303\255 \303\272tvary"]
::msgcat::mcset en "point scallop" [encoding convertfrom utf-8 "scallop"]
::msgcat::mcset en_UK "point scallop" [encoding convertfrom utf-8 "scallop"]
::msgcat::mcset en_US "point scallop" [encoding convertfrom utf-8 "scallop"]
::msgcat::mcset es "point scallop" [encoding convertfrom utf-8 "cavitaciones"]
::msgcat::mcset fr "point scallop" [encoding convertfrom utf-8 "vagues d\342\200\231\303\251rosion (coups de gouge)"]
::msgcat::mcset sk "point scallop" [encoding convertfrom utf-8 "er\303\263zne \303\272tvary"]
::msgcat::mcset cz "point section" [encoding convertfrom utf-8 "p\305\231\303\255\304\215n\303\275 \305\231ez"]
::msgcat::mcset sk "point section" [encoding convertfrom utf-8 "prie\304\215ny rez"]
::msgcat::mcset cz "point sink" [encoding convertfrom utf-8 "ponor"]
::msgcat::mcset en "point sink" [encoding convertfrom utf-8 "sink"]
::msgcat::mcset en_UK "point sink" [encoding convertfrom utf-8 "sink"]
::msgcat::mcset en_US "point sink" [encoding convertfrom utf-8 "sink"]
::msgcat::mcset es "point sink" [encoding convertfrom utf-8 "sumidero"]
::msgcat::mcset fr "point sink" [encoding convertfrom utf-8 "perte"]
::msgcat::mcset sk "point sink" [encoding convertfrom utf-8 "ponor"]
::msgcat::mcset cz "point snow" [encoding convertfrom utf-8 "sn\303\255h"]
::msgcat::mcset en "point snow" [encoding convertfrom utf-8 "snow"]
::msgcat::mcset en_UK "point snow" [encoding convertfrom utf-8 "snow"]
::msgcat::mcset en_US "point snow" [encoding convertfrom utf-8 "snow"]
::msgcat::mcset es "point snow" [encoding convertfrom utf-8 "nieve"]
::msgcat::mcset sk "point snow" [encoding convertfrom utf-8 "sneh"]
::msgcat::mcset cz "point soda-straw" [encoding convertfrom utf-8 "br\304\215ka"]
::msgcat::mcset en "point soda-straw" [encoding convertfrom utf-8 "soda straw"]
::msgcat::mcset en_UK "point soda-straw" [encoding convertfrom utf-8 "soda straw"]
::msgcat::mcset en_US "point soda-straw" [encoding convertfrom utf-8 "soda straw"]
::msgcat::mcset es "point soda-straw" [encoding convertfrom utf-8 "fistulosa"]
::msgcat::mcset fr "point soda-straw" [encoding convertfrom utf-8 "fistuleuse"]
::msgcat::mcset sk "point soda-straw" [encoding convertfrom utf-8 "br\304\215k\303\241"]
::msgcat::mcset cz "point spring" [encoding convertfrom utf-8 "v\303\275v\304\233r"]
::msgcat::mcset en "point spring" [encoding convertfrom utf-8 "spring"]
::msgcat::mcset en_UK "point spring" [encoding convertfrom utf-8 "spring"]
::msgcat::mcset en_US "point spring" [encoding convertfrom utf-8 "spring"]
::msgcat::mcset es "point spring" [encoding convertfrom utf-8 "surgencia"]
::msgcat::mcset fr "point spring" [encoding convertfrom utf-8 "source"]
::msgcat::mcset sk "point spring" [encoding convertfrom utf-8 "v\303\275ver"]
::msgcat::mcset cz "point stalactite" [encoding convertfrom utf-8 "stalaktit"]
::msgcat::mcset en "point stalactite" [encoding convertfrom utf-8 "stalactite"]
::msgcat::mcset en_UK "point stalactite" [encoding convertfrom utf-8 "stalactite"]
::msgcat::mcset en_US "point stalactite" [encoding convertfrom utf-8 "stalactite"]
::msgcat::mcset es "point stalactite" [encoding convertfrom utf-8 "estalactita"]
::msgcat::mcset fr "point stalactite" [encoding convertfrom utf-8 "stalactite"]
::msgcat::mcset sk "point stalactite" [encoding convertfrom utf-8 "stalaktit"]
::msgcat::mcset cz "point stalagmite" [encoding convertfrom utf-8 "stalagmit"]
::msgcat::mcset en "point stalagmite" [encoding convertfrom utf-8 "stalagmite"]
::msgcat::mcset en_UK "point stalagmite" [encoding convertfrom utf-8 "stalagmite"]
::msgcat::mcset en_US "point stalagmite" [encoding convertfrom utf-8 "stalagmite"]
::msgcat::mcset es "point stalagmite" [encoding convertfrom utf-8 "estalagmita"]
::msgcat::mcset fr "point stalagmite" [encoding convertfrom utf-8 "stalagmite"]
::msgcat::mcset sk "point stalagmite" [encoding convertfrom utf-8 "stalagmit"]
::msgcat::mcset cz "point station" [encoding convertfrom utf-8 "m\304\233\305\231i\304\215sk\303\275 bod"]
::msgcat::mcset en "point station" [encoding convertfrom utf-8 "survey station"]
::msgcat::mcset en_UK "point station" [encoding convertfrom utf-8 "survey station"]
::msgcat::mcset en_US "point station" [encoding convertfrom utf-8 "survey station"]
::msgcat::mcset es "point station" [encoding convertfrom utf-8 "estaci\303\263n"]
::msgcat::mcset fr "point station" [encoding convertfrom utf-8 "station topo"]
::msgcat::mcset sk "point station" [encoding convertfrom utf-8 "mera\304\215sk\303\275 bod"]
::msgcat::mcset cz "point station-name" [encoding convertfrom utf-8 "\304\215\303\255slo m\304\233\305\231i\304\215sk\303\251ho bodu"]
::msgcat::mcset en "point station-name" [encoding convertfrom utf-8 "survey station name"]
::msgcat::mcset en_UK "point station-name" [encoding convertfrom utf-8 "survey station name"]
::msgcat::mcset en_US "point station-name" [encoding convertfrom utf-8 "survey station name"]
::msgcat::mcset es "point station-name" [encoding convertfrom utf-8 "nombre estacion"]
::msgcat::mcset fr "point station-name" [encoding convertfrom utf-8 "station topo, nom"]
::msgcat::mcset sk "point station-name" [encoding convertfrom utf-8 "\304\215\303\255slo mera\304\215sk\303\251ho bodu"]
::msgcat::mcset cz "point steps" [encoding convertfrom utf-8 "schody"]
::msgcat::mcset en "point steps" [encoding convertfrom utf-8 "steps"]
::msgcat::mcset en_UK "point steps" [encoding convertfrom utf-8 "steps"]
::msgcat::mcset en_US "point steps" [encoding convertfrom utf-8 "steps"]
::msgcat::mcset es "point steps" [encoding convertfrom utf-8 "escalones"]
::msgcat::mcset fr "point steps" [encoding convertfrom utf-8 "marches"]
::msgcat::mcset sk "point steps" [encoding convertfrom utf-8 "schody"]
::msgcat::mcset cz "point traverse" [encoding convertfrom utf-8 "traverz"]
::msgcat::mcset en "point traverse" [encoding convertfrom utf-8 "traverse"]
::msgcat::mcset en_UK "point traverse" [encoding convertfrom utf-8 "traverse"]
::msgcat::mcset en_US "point traverse" [encoding convertfrom utf-8 "traverse"]
::msgcat::mcset es "point traverse" [encoding convertfrom utf-8 "pasamanos"]
::msgcat::mcset fr "point traverse" [encoding convertfrom utf-8 "travers\303\251e"]
::msgcat::mcset sk "point traverse" [encoding convertfrom utf-8 "traverz"]
::msgcat::mcset cz "point vegetable-debris" [encoding convertfrom utf-8 "zbytky rostlin"]
::msgcat::mcset en "point vegetable-debris" [encoding convertfrom utf-8 "vegetable debris"]
::msgcat::mcset en_UK "point vegetable-debris" [encoding convertfrom utf-8 "vegetable debris"]
::msgcat::mcset en_US "point vegetable-debris" [encoding convertfrom utf-8 "vegetable debris"]
::msgcat::mcset es "point vegetable-debris" [encoding convertfrom utf-8 "detritus vegetales"]
::msgcat::mcset fr "point vegetable-debris" [encoding convertfrom utf-8 "d\303\251bris v\303\251g\303\251taux"]
::msgcat::mcset sk "point vegetable-debris" [encoding convertfrom utf-8 "zvy\305\241ky rastl\303\255n"]
::msgcat::mcset cz "point wall-calcite" [encoding convertfrom utf-8 "v\303\241pencov\303\275 povlak"]
::msgcat::mcset en "point wall-calcite" [encoding convertfrom utf-8 "wall calcite"]
::msgcat::mcset en_UK "point wall-calcite" [encoding convertfrom utf-8 "wall calcite"]
::msgcat::mcset en_US "point wall-calcite" [encoding convertfrom utf-8 "wall calcite"]
::msgcat::mcset es "point wall-calcite" [encoding convertfrom utf-8 "calcita"]
::msgcat::mcset fr "point wall-calcite" [encoding convertfrom utf-8 "mur, calcite"]
::msgcat::mcset sk "point wall-calcite" [encoding convertfrom utf-8 "v\303\241pencov\303\275 povlak"]
::msgcat::mcset cz "point water" [encoding convertfrom utf-8 "voda"]
::msgcat::mcset en "point water" [encoding convertfrom utf-8 "water"]
::msgcat::mcset en_UK "point water" [encoding convertfrom utf-8 "water"]
::msgcat::mcset en_US "point water" [encoding convertfrom utf-8 "water"]
::msgcat::mcset es "point water" [encoding convertfrom utf-8 "agua"]
::msgcat::mcset fr "point water" [encoding convertfrom utf-8 "eau"]
::msgcat::mcset sk "point water" [encoding convertfrom utf-8 "voda"]
::msgcat::mcset cz "point water-flow" [encoding convertfrom utf-8 "vodn\303\255 tok"]
::msgcat::mcset en "point water-flow" [encoding convertfrom utf-8 "water flow"]
::msgcat::mcset en_UK "point water-flow" [encoding convertfrom utf-8 "water flow"]
::msgcat::mcset en_US "point water-flow" [encoding convertfrom utf-8 "water flow"]
::msgcat::mcset es "point water-flow" [encoding convertfrom utf-8 "curso agua"]
::msgcat::mcset fr "point water-flow" [encoding convertfrom utf-8 "rivi\303\250re"]
::msgcat::mcset sk "point water-flow" [encoding convertfrom utf-8 "vodn\303\275 tok"]
::msgcat::mcset cz "line arrow" [encoding convertfrom utf-8 "pomocn\303\241 \305\241ipka"]
::msgcat::mcset en "line arrow" [encoding convertfrom utf-8 "arrow"]
::msgcat::mcset en_UK "line arrow" [encoding convertfrom utf-8 "arrow"]
::msgcat::mcset en_US "line arrow" [encoding convertfrom utf-8 "arrow"]
::msgcat::mcset es "line arrow" [encoding convertfrom utf-8 "flecha"]
::msgcat::mcset fr "line arrow" [encoding convertfrom utf-8 "fl\303\250che"]
::msgcat::mcset sk "line arrow" [encoding convertfrom utf-8 "pomocn\303\241 \305\241\303\255pka"]
::msgcat::mcset cz "line border" [encoding convertfrom utf-8 "ohrani\304\215en\303\255"]
::msgcat::mcset en "line border" [encoding convertfrom utf-8 "border"]
::msgcat::mcset en_UK "line border" [encoding convertfrom utf-8 "border"]
::msgcat::mcset en_US "line border" [encoding convertfrom utf-8 "border"]
::msgcat::mcset es "line border" [encoding convertfrom utf-8 "l\303\255mite"]
::msgcat::mcset fr "line border" [encoding convertfrom utf-8 "bord"]
::msgcat::mcset sk "line border" [encoding convertfrom utf-8 "ohrani\304\215enie"]
::msgcat::mcset cz "line ceiling-meander" [encoding convertfrom utf-8 "stropn\303\255 meandr"]
::msgcat::mcset en "line ceiling-meander" [encoding convertfrom utf-8 "ceiling meander"]
::msgcat::mcset en_UK "line ceiling-meander" [encoding convertfrom utf-8 "ceiling meander"]
::msgcat::mcset en_US "line ceiling-meander" [encoding convertfrom utf-8 "ceiling meander"]
::msgcat::mcset es "line ceiling-meander" [encoding convertfrom utf-8 "meandro inverso"]
::msgcat::mcset sk "line ceiling-meander" [encoding convertfrom utf-8 "stropn\303\275 meander"]
::msgcat::mcset cz "line ceiling-step" [encoding convertfrom utf-8 "zm\304\233na v\303\275\305\241ky stropu"]
::msgcat::mcset en "line ceiling-step" [encoding convertfrom utf-8 "step on the ceiling"]
::msgcat::mcset en_UK "line ceiling-step" [encoding convertfrom utf-8 "step on the ceiling"]
::msgcat::mcset en_US "line ceiling-step" [encoding convertfrom utf-8 "step on the ceiling"]
::msgcat::mcset es "line ceiling-step" [encoding convertfrom utf-8 "resalte inverso"]
::msgcat::mcset fr "line ceiling-step" [encoding convertfrom utf-8 "marche de plafond"]
::msgcat::mcset sk "line ceiling-step" [encoding convertfrom utf-8 "zmena v\303\275\305\241ky stropu"]
::msgcat::mcset cz "line chimney" [encoding convertfrom utf-8 "kom\303\255n"]
::msgcat::mcset en "line chimney" [encoding convertfrom utf-8 "chimney"]
::msgcat::mcset en_UK "line chimney" [encoding convertfrom utf-8 "chimney"]
::msgcat::mcset en_US "line chimney" [encoding convertfrom utf-8 "chimney"]
::msgcat::mcset es "line chimney" [encoding convertfrom utf-8 "chimenea"]
::msgcat::mcset fr "line chimney" [encoding convertfrom utf-8 "chemin\303\251e"]
::msgcat::mcset sk "line chimney" [encoding convertfrom utf-8 "kom\303\255n"]
::msgcat::mcset cz "line contour" [encoding convertfrom utf-8 "vrstevnice"]
::msgcat::mcset en "line contour" [encoding convertfrom utf-8 "contour"]
::msgcat::mcset en_UK "line contour" [encoding convertfrom utf-8 "contour"]
::msgcat::mcset en_US "line contour" [encoding convertfrom utf-8 "contour"]
::msgcat::mcset es "line contour" [encoding convertfrom utf-8 "contorno"]
::msgcat::mcset fr "line contour" [encoding convertfrom utf-8 "contour"]
::msgcat::mcset sk "line contour" [encoding convertfrom utf-8 "vrstevnica"]
::msgcat::mcset cz "line floor-meander" [encoding convertfrom utf-8 "meandr ve dn\304\233"]
::msgcat::mcset en "line floor-meander" [encoding convertfrom utf-8 "floor meander"]
::msgcat::mcset en_UK "line floor-meander" [encoding convertfrom utf-8 "floor meander"]
::msgcat::mcset en_US "line floor-meander" [encoding convertfrom utf-8 "floor meander"]
::msgcat::mcset es "line floor-meander" [encoding convertfrom utf-8 "meandro"]
::msgcat::mcset sk "line floor-meander" [encoding convertfrom utf-8 "meander v dne"]
::msgcat::mcset cz "line floor-step" [encoding convertfrom utf-8 "stupe\305\210"]
::msgcat::mcset en "line floor-step" [encoding convertfrom utf-8 "floor step"]
::msgcat::mcset en_UK "line floor-step" [encoding convertfrom utf-8 "floor step"]
::msgcat::mcset en_US "line floor-step" [encoding convertfrom utf-8 "floor step"]
::msgcat::mcset es "line floor-step" [encoding convertfrom utf-8 "resalte"]
::msgcat::mcset fr "line floor-step" [encoding convertfrom utf-8 "marche"]
::msgcat::mcset sk "line floor-step" [encoding convertfrom utf-8 "stupe\305\210"]
::msgcat::mcset cz "line flowstone" [encoding convertfrom utf-8 "sintrov\303\251 n\303\241teky"]
::msgcat::mcset en "line flowstone" [encoding convertfrom utf-8 "flowstone"]
::msgcat::mcset en_UK "line flowstone" [encoding convertfrom utf-8 "flowstone"]
::msgcat::mcset en_US "line flowstone" [encoding convertfrom utf-8 "flowstone"]
::msgcat::mcset es "line flowstone" [encoding convertfrom utf-8 "concreci\303\263n"]
::msgcat::mcset fr "line flowstone" [encoding convertfrom utf-8 "concr\303\251tion"]
::msgcat::mcset sk "line flowstone" [encoding convertfrom utf-8 "sintrov\303\251 n\303\241teky"]
::msgcat::mcset cz "line gradient" [encoding convertfrom utf-8 "sklon chodby"]
::msgcat::mcset en "line gradient" [encoding convertfrom utf-8 "passage gradient"]
::msgcat::mcset en_UK "line gradient" [encoding convertfrom utf-8 "passage gradient"]
::msgcat::mcset en_US "line gradient" [encoding convertfrom utf-8 "passage gradient"]
::msgcat::mcset es "line gradient" [encoding convertfrom utf-8 "gradiente"]
::msgcat::mcset fr "line gradient" [encoding convertfrom utf-8 "pente"]
::msgcat::mcset sk "line gradient" [encoding convertfrom utf-8 "sklon chodby"]
::msgcat::mcset cz "line label" [encoding convertfrom utf-8 "pojmenov\303\241n\303\255"]
::msgcat::mcset sk "line label" [encoding convertfrom utf-8 "pomenovanie"]
::msgcat::mcset cz "line overhang" [encoding convertfrom utf-8 "p\305\231evis"]
::msgcat::mcset en "line overhang" [encoding convertfrom utf-8 "overhang"]
::msgcat::mcset en_UK "line overhang" [encoding convertfrom utf-8 "overhang"]
::msgcat::mcset en_US "line overhang" [encoding convertfrom utf-8 "overhang"]
::msgcat::mcset es "line overhang" [encoding convertfrom utf-8 "extraplomo"]
::msgcat::mcset fr "line overhang" [encoding convertfrom utf-8 "surplomb"]
::msgcat::mcset sk "line overhang" [encoding convertfrom utf-8 "previs"]
::msgcat::mcset cz "line pit" [encoding convertfrom utf-8 "propast"]
::msgcat::mcset en "line pit" [encoding convertfrom utf-8 "pitch"]
::msgcat::mcset en_UK "line pit" [encoding convertfrom utf-8 "pitch"]
::msgcat::mcset en_US "line pit" [encoding convertfrom utf-8 "pit"]
::msgcat::mcset es "line pit" [encoding convertfrom utf-8 "pozo"]
::msgcat::mcset fr "line pit" [encoding convertfrom utf-8 "puits"]
::msgcat::mcset sk "line pit" [encoding convertfrom utf-8 "priepas\305\245"]
::msgcat::mcset cz "line rock-border" [encoding convertfrom utf-8 "kameny"]
::msgcat::mcset en "line rock-border" [encoding convertfrom utf-8 "rock border"]
::msgcat::mcset en_UK "line rock-border" [encoding convertfrom utf-8 "rock border"]
::msgcat::mcset en_US "line rock-border" [encoding convertfrom utf-8 "rock border"]
::msgcat::mcset es "line rock-border" [encoding convertfrom utf-8 "l\303\255mite roca"]
::msgcat::mcset fr "line rock-border" [encoding convertfrom utf-8 "bord d\342\200\231un rocher"]
::msgcat::mcset sk "line rock-border" [encoding convertfrom utf-8 "ohrani\304\215enie kame\305\210ov"]
::msgcat::mcset cz "line rock-edge" [encoding convertfrom utf-8 "hrany kamen\305\257"]
::msgcat::mcset en "line rock-edge" [encoding convertfrom utf-8 "rock edges"]
::msgcat::mcset en_UK "line rock-edge" [encoding convertfrom utf-8 "rock edges"]
::msgcat::mcset en_US "line rock-edge" [encoding convertfrom utf-8 "rock edges"]
::msgcat::mcset es "line rock-edge" [encoding convertfrom utf-8 "arista"]
::msgcat::mcset fr "line rock-edge" [encoding convertfrom utf-8 "ar\303\252te d\342\200\231un rocher"]
::msgcat::mcset sk "line rock-edge" [encoding convertfrom utf-8 "hrany kame\305\210ov"]
::msgcat::mcset cz "line section" [encoding convertfrom utf-8 "p\305\231\303\255\304\215n\303\275 \305\231ez"]
::msgcat::mcset en "line section" [encoding convertfrom utf-8 "cross-section"]
::msgcat::mcset en_UK "line section" [encoding convertfrom utf-8 "cross-section"]
::msgcat::mcset en_US "line section" [encoding convertfrom utf-8 "cross-section"]
::msgcat::mcset es "line section" [encoding convertfrom utf-8 "secci\303\263n"]
::msgcat::mcset fr "line section" [encoding convertfrom utf-8 "section"]
::msgcat::mcset sk "line section" [encoding convertfrom utf-8 "prie\304\215ny rez"]
::msgcat::mcset cz "line slope" [encoding convertfrom utf-8 "svah"]
::msgcat::mcset en "line slope" [encoding convertfrom utf-8 "slope"]
::msgcat::mcset en_UK "line slope" [encoding convertfrom utf-8 "slope"]
::msgcat::mcset en_US "line slope" [encoding convertfrom utf-8 "slope"]
::msgcat::mcset es "line slope" [encoding convertfrom utf-8 "pendiente"]
::msgcat::mcset fr "line slope" [encoding convertfrom utf-8 "pente"]
::msgcat::mcset sk "line slope" [encoding convertfrom utf-8 "\305\241ikm\303\241 plocha"]
::msgcat::mcset cz "line survey" [encoding convertfrom utf-8 "polygonov\303\275 tah"]
::msgcat::mcset en "line survey" [encoding convertfrom utf-8 "survey lines"]
::msgcat::mcset en_UK "line survey" [encoding convertfrom utf-8 "survey lines"]
::msgcat::mcset en_US "line survey" [encoding convertfrom utf-8 "survey lines"]
::msgcat::mcset es "line survey" [encoding convertfrom utf-8 "poligonal"]
::msgcat::mcset fr "line survey" [encoding convertfrom utf-8 "vis\303\251e topo"]
::msgcat::mcset sk "line survey" [encoding convertfrom utf-8 "polyg\303\263nov\303\275 \305\245ah"]
::msgcat::mcset cz "line wall" [encoding convertfrom utf-8 "st\304\233na"]
::msgcat::mcset en "line wall" [encoding convertfrom utf-8 "wall"]
::msgcat::mcset en_UK "line wall" [encoding convertfrom utf-8 "wall"]
::msgcat::mcset en_US "line wall" [encoding convertfrom utf-8 "wall"]
::msgcat::mcset es "line wall" [encoding convertfrom utf-8 "pared"]
::msgcat::mcset fr "line wall" [encoding convertfrom utf-8 "mur"]
::msgcat::mcset sk "line wall" [encoding convertfrom utf-8 "stena"]
::msgcat::mcset cz "line water-flow" [encoding convertfrom utf-8 "vodn\303\255 tok"]
::msgcat::mcset en "line water-flow" [encoding convertfrom utf-8 "water flow"]
::msgcat::mcset en_UK "line water-flow" [encoding convertfrom utf-8 "water flow"]
::msgcat::mcset en_US "line water-flow" [encoding convertfrom utf-8 "water flow"]
::msgcat::mcset es "line water-flow" [encoding convertfrom utf-8 "curso agua"]
::msgcat::mcset fr "line water-flow" [encoding convertfrom utf-8 "rivi\303\250re"]
::msgcat::mcset sk "line water-flow" [encoding convertfrom utf-8 "vodn\303\275 tok"]
::msgcat::mcset cz "area blocks" [encoding convertfrom utf-8 "skaln\303\255 bloky"]
::msgcat::mcset en "area blocks" [encoding convertfrom utf-8 "blocks"]
::msgcat::mcset en_UK "area blocks" [encoding convertfrom utf-8 "blocks"]
::msgcat::mcset en_US "area blocks" [encoding convertfrom utf-8 "blocks"]
::msgcat::mcset es "area blocks" [encoding convertfrom utf-8 "bloques"]
::msgcat::mcset sk "area blocks" [encoding convertfrom utf-8 "skaln\303\251 bloky"]
::msgcat::mcset cz "area clay" [encoding convertfrom utf-8 "bahno"]
::msgcat::mcset en "area clay" [encoding convertfrom utf-8 "clay"]
::msgcat::mcset en_UK "area clay" [encoding convertfrom utf-8 "clay"]
::msgcat::mcset en_US "area clay" [encoding convertfrom utf-8 "clay"]
::msgcat::mcset es "area clay" [encoding convertfrom utf-8 "arcilla"]
::msgcat::mcset sk "area clay" [encoding convertfrom utf-8 "blato"]
::msgcat::mcset cz "area debris" [encoding convertfrom utf-8 "\305\241t\304\233rk"]
::msgcat::mcset en "area debris" [encoding convertfrom utf-8 "debris"]
::msgcat::mcset en_UK "area debris" [encoding convertfrom utf-8 "debris"]
::msgcat::mcset en_US "area debris" [encoding convertfrom utf-8 "debris"]
::msgcat::mcset es "area debris" [encoding convertfrom utf-8 "derrubios"]
::msgcat::mcset fr "area debris" [encoding convertfrom utf-8 "d\303\251bris"]
::msgcat::mcset sk "area debris" [encoding convertfrom utf-8 "\305\241trk"]
::msgcat::mcset cz "area ice" [encoding convertfrom utf-8 "led"]
::msgcat::mcset en "area ice" [encoding convertfrom utf-8 "ice"]
::msgcat::mcset en_UK "area ice" [encoding convertfrom utf-8 "ice"]
::msgcat::mcset en_US "area ice" [encoding convertfrom utf-8 "ice"]
::msgcat::mcset es "area ice" [encoding convertfrom utf-8 "hielo"]
::msgcat::mcset sk "area ice" [encoding convertfrom utf-8 "\304\276ad"]
::msgcat::mcset cz "area pebbles" [encoding convertfrom utf-8 "valouny"]
::msgcat::mcset en "area pebbles" [encoding convertfrom utf-8 "pebbles"]
::msgcat::mcset en_UK "area pebbles" [encoding convertfrom utf-8 "pebbles"]
::msgcat::mcset en_US "area pebbles" [encoding convertfrom utf-8 "pebbles"]
::msgcat::mcset es "area pebbles" [encoding convertfrom utf-8 "cantos rodados"]
::msgcat::mcset sk "area pebbles" [encoding convertfrom utf-8 "okr\303\272hliaky"]
::msgcat::mcset cz "area sand" [encoding convertfrom utf-8 "p\303\255sek"]
::msgcat::mcset en "area sand" [encoding convertfrom utf-8 "sand"]
::msgcat::mcset en_UK "area sand" [encoding convertfrom utf-8 "sand"]
::msgcat::mcset en_US "area sand" [encoding convertfrom utf-8 "sand"]
::msgcat::mcset es "area sand" [encoding convertfrom utf-8 "arena"]
::msgcat::mcset fr "area sand" [encoding convertfrom utf-8 "sable"]
::msgcat::mcset sk "area sand" [encoding convertfrom utf-8 "piesok"]
::msgcat::mcset cz "area snow" [encoding convertfrom utf-8 "sn\303\255h"]
::msgcat::mcset en "area snow" [encoding convertfrom utf-8 "snow"]
::msgcat::mcset en_UK "area snow" [encoding convertfrom utf-8 "snow"]
::msgcat::mcset en_US "area snow" [encoding convertfrom utf-8 "snow"]
::msgcat::mcset es "area snow" [encoding convertfrom utf-8 "nieve"]
::msgcat::mcset sk "area snow" [encoding convertfrom utf-8 "sneh"]
::msgcat::mcset cz "area sump" [encoding convertfrom utf-8 "sifon"]
::msgcat::mcset en "area sump" [encoding convertfrom utf-8 "sump"]
::msgcat::mcset en_UK "area sump" [encoding convertfrom utf-8 "sump"]
::msgcat::mcset en_US "area sump" [encoding convertfrom utf-8 "sump"]
::msgcat::mcset es "area sump" [encoding convertfrom utf-8 "sif\303\263n"]
::msgcat::mcset fr "area sump" [encoding convertfrom utf-8 "siphon"]
::msgcat::mcset sk "area sump" [encoding convertfrom utf-8 "zatopen\303\241 plocha (sif\303\263n)"]
::msgcat::mcset cz "area water" [encoding convertfrom utf-8 "vodn\303\255 plocha"]
::msgcat::mcset en "area water" [encoding convertfrom utf-8 "water"]
::msgcat::mcset en_UK "area water" [encoding convertfrom utf-8 "water"]
::msgcat::mcset en_US "area water" [encoding convertfrom utf-8 "water"]
::msgcat::mcset es "area water" [encoding convertfrom utf-8 "agua"]
::msgcat::mcset fr "area water" [encoding convertfrom utf-8 "eau"]
::msgcat::mcset sk "area water" [encoding convertfrom utf-8 "vodn\303\241 plocha"]








set xth(about,image_id) [image create photo -data $xth(about,image_data)]
set xth(about,infotime) 2500

after 0 {
  if {$xth(gui,check_update)} {
    xth_ivc
  }
  if {[string length $xth(about,nvr)] > 0} {
    bell
    if {[winfo exists $xth(gui,about)]} {
      xth_about_nvr
    } else {
      # show about window for some time seconds
      xth_about_show 0
      after $xth(about,infotime) xth_about_hide
    }
  }
}

proc xth_about_status {str} {
    global xth
    set xth(about,status) "$str"
    catch {
      $xth(gui,about).i2 configure -text "VERSION $xth(about,nvr) AVAILABLE"
    }
    update idletasks
}


proc xth_about_nvr {} {
  global xth
  if {[string length $xth(about,nvr)] == 0} {
    return
  }
  if {![winfo exists $xth(gui,about)]} {
    return
  }
  set w $xth(gui,about)
  label $w.i2 -bd 0 -relief sunken -background black -fg red -text "VERSION $xth(about,nvr) AVAILABLE" \
    -font $xth(gui,lfont) -anchor center
  pack $w.i2 -after $w.i1 -side top -expand 1 -fill both -pady 5
  update idletasks
}


proc xth_about_show {btnid} {
    global xth
    if {[winfo exists $xth(gui,about)]} xth_about_hide
    xth_about_status ""
    set w $xth(gui,about)
    toplevel $w -relief raised -bg black -bd 3 -cursor $xth(gui,cursor)
    wm transient $w
    wm withdraw $w
    set sw [winfo screenwidth .]
    set sh [winfo screenheight .]
    wm overrideredirect $w 1
    label $w.image -bd 0 -relief sunken -background black -fg white -image $xth(about,image_id)
    pack $w.image -side top -expand 1 -fill both
    label $w.status -relief flat -background black -foreground white \
    	-textvariable xth(about,status) -font $xth(gui,lfont) -anchor center
    pack $w.status -side top -expand 1 -fill both
    label $w.i1 -bd 0 -relief sunken -background black -fg white -text "xtherion\n$xth(about,ver)" \
      -font $xth(gui,lfont) -anchor center
    pack $w.i1 -side top -expand 1 -fill both -pady 5
    if {$btnid} {
      button $w.close -text "Close" -font $xth(gui,lfont) -anchor center \
        -command xth_about_hide -width 5
      pack $w.close -side top -fill none -anchor center -pady 5
      focus $w.close
    }
    xth_about_nvr
    wm geometry $xth(gui,about) -$sw-$sh
    wm deiconify $xth(gui,about)
    update idletasks
    set x [expr {($sw - [winfo width $xth(gui,about)])/2}]
    set y [expr {($sh - [winfo height $xth(gui,about)])/2}]
    wm geometry $xth(gui,about) +$x+$y
    $w configure -bg black
    $w.image configure -image $xth(about,image_id)
    $w.i1 configure -text "xtherion $xth(about,ver)\n\u00A9 2002-2004 Stacho Mudrak"
    update idletasks
}


proc xth_about_hide {} {
  global xth
  destroy $xth(gui,about)
  focus $xth(gui,main)
}








package require BWidget

if {[catch {set imgver [package require Img]}]} {
  set xth(gui,imgfiletypes) {
           { {Pictures} {.gif .pnm .ppm .xvi} }
           { {All Files}               * }
         } 
} else {
  set xth(gui,imgfiletypes) {
           { {Pictures} {.png .jpeg .jpg .gif .pnm .ppm .xvi} }
           { {All Files}                                               * }
         } 
}

# read xtherion.ini file from THERION directory
set idir {}
if {[catch {set idir $env(THERION)}]} {
  if {![catch {set idir $env(HOME)}]} {
    append idir "/.therion"
    if {[string equal $xth(gui,platform) windows]} {
      append idir ";"
    } else {
      append idir ":"
    }
  }
  if {[string equal $xth(gui,platform) windows]} {
    if {[catch {
        append idir [registry get {HKEY_LOCAL_MACHINE\SOFTWARE\Therion} InstallDir]
        }]} {
      append idir "C:/WINDOWS;C:/WINNT;C:/Program files/Therion"
    }
  } else {
    append idir "/etc:/usr/etc:/usr/local/etc"
  }
}
if {[string equal $xth(gui,platform) windows]} {
  set idirs [split $idir ";"]
} else {
  set idirs [split $idir ":"]
}

set xth(idirs) $idirs
foreach idir $xth(idirs) {
  catch {source [file join $idir xtherion.ini]}
}
catch {source xtherion.ini}

# create xth window
wm withdraw .
xth_about_show 0
toplevel $xth(gui,main)
wm withdraw $xth(gui,main)
wm protocol $xth(gui,main) WM_DELETE_WINDOW "xth_exit"
wm title $xth(gui,main) $xth(prj,name)
wm geometry $xth(gui,main) [format "%dx%d+0+0" [lindex $xth(gui,minsize) 0] \
  [lindex $xth(gui,minsize) 1]]
wm minsize $xth(gui,main) [lindex $xth(gui,minsize) 0] \
  [lindex $xth(gui,minsize) 1]
update idletasks
bind $xth(gui,main) <Configure> { 
  catch {xth_app_place $xth(app,active)}
}

set xth(gui,clock) "00:00"

# redefine some public key bindigs
if {$xth(gui,bindinsdel)} {
  bind Text <Delete> { }
}
bind Text <$xth(kb_control)-Key-o> "#"
bind Text <$xth(kb_control)-Key-a> "#"
bind Text <$xth(kb_control)-Key-i> "#"
bind Text <$xth(kb_control)-Key-s> "#"
bind Text <$xth(kb_control)-Key-w> "#"
bind Text <$xth(kb_control)-Key-q> "#"
bind Text <$xth(kb_control)-Key-x> "#"
bind Text <$xth(kb_control)-Key-n> "#"
bind Text <$xth(kb_control)-Key-p> "#"
bind Text <$xth(kb_control)-Key-c> "#"
bind Text <$xth(kb_control)-Key-v> "#"
bind Text <$xth(kb_control)-Key-f> "#"
bind Text <$xth(kb_control)-Key-h> "#"
bind Text <$xth(kb_control)-Key-z> "#"
bind Text <$xth(kb_control)-Key-y> "#"
bind Text <$xth(kb_control)-Key-d> "#"
bind Text <$xth(kb_control)-Key-k> "#"
bind Text <$xth(kb_control)-Key-r> "#"

bind Entry <$xth(kb_control)-Key-d> "#"
bind Entry <$xth(kb_control)-Key-k> "#"

set xth(gui,bind,text_tab) [bind Text <Tab>]
set xth(gui,bind,text_return) [bind Text <Return>]
bind Text <Tab> "#"
bind Text <Return> "#"








# prepare the syntax commands
foreach cmd $xth(icmds) {
  set xth(cmd,$cmd) 2
  set xth(endcmd,$cmd) end$cmd
  set xth(endcmd,end$cmd) ""
  set xth(cmd,end$cmd) -2
}

foreach cmd $xth(cmds) {
  set xth(cmd,$cmd) 1
  set xth(endcmd,$cmd) end$cmd
  set xth(endcmd,end$cmd) ""
  set xth(cmd,end$cmd) -1
}

set xth(datafmts) [list \
  "unknown      $xth(datafmt,unknown)" \
  "station      $xth(datafmt,station)" \
  "from         $xth(datafmt,station)" \
  "to           $xth(datafmt,station)" \
  "compass      $xth(datafmt,bearing)" \
  "backcompass  $xth(datafmt,bearing)" \
  "bearing      $xth(datafmt,bearing)" \
  "backbearing  $xth(datafmt,bearing)" \
  "tape         $xth(datafmt,length)" \
  "length       $xth(datafmt,length)" \
  "count        $xth(datafmt,counter)" \
  "counter      $xth(datafmt,counter)" \
  "fromcount    $xth(datafmt,counter)" \
  "tocount      $xth(datafmt,counter)" \
  "fromcounter  $xth(datafmt,counter)" \
  "tocounter    $xth(datafmt,counter)" \
  "gradient     $xth(datafmt,gradient)" \
  "clino        $xth(datafmt,gradient)" \
  "backgradient $xth(datafmt,gradient)" \
  "backclino    $xth(datafmt,gradient)" \
  "depth        $xth(datafmt,depth)" \
  "fromdepth    $xth(datafmt,depth)" \
  "todepth      $xth(datafmt,depth)" \
  "depthchange  $xth(datafmt,depth)" \
  "dx           $xth(datafmt,length)" \
  "dy           $xth(datafmt,length)" \
  "dz           $xth(datafmt,length)" \
  "northing     $xth(datafmt,length)" \
  "easting      $xth(datafmt,length)" \
  "altitude     $xth(datafmt,length)" \
  "up           $xth(datafmt,dimensions)" \
  "down         $xth(datafmt,dimensions)" \
  "left         $xth(datafmt,dimensions)" \
  "right        $xth(datafmt,dimensions)" \
  "ceiling      $xth(datafmt,dimensions)" \
  "floor        $xth(datafmt,dimensions)" \
]

foreach datafmt $xth(datafmts) {
  set qt [lindex $datafmt 0]
  set xth(datafmt,$qt,format) [lindex $datafmt 1]
  set xth(datafmt,$qt,special) [lindex $datafmt 2]
}








proc xth_status_bar {aname widg stext} {
  global xth  
  if {$xth(gui,balloons)} {
    DynamicHelp::register $widg balloon $stext
  }
  set anml $aname
  foreach aname $anml {
    set sbar $xth(gui,$aname).sf.sbar
    set widgx "$aname$widg"
    set xth(gui,sbar,$widgx,exp) 0  
    bind $widg <FocusIn> "+ if {\$xth(gui,sbar,$widgx,exp) == 0} {catch {set xth(gui,sbar,$widgx,exp) 1; set xth(gui,sbar,$widgx,otext) \[$sbar cget -text\]; $sbar configure -text [list $stext]}}"
    bind $widg <Enter> "+ if {\$xth(gui,sbar,$widgx,exp) == 0} {catch {set xth(gui,sbar,$widgx,exp) 1; set xth(gui,sbar,$widgx,otext) \[$sbar cget -text\]; $sbar configure -text [list $stext]}}"
    bind $widg <FocusOut> "+ if {\$xth(gui,sbar,$widgx,exp) == 1} {catch {$sbar configure -text \$xth(gui,sbar,$widgx,otext); set xth(gui,sbar,$widgx,exp) 0}}"
    bind $widg <Leave> "+ if {\$xth(gui,sbar,$widgx,exp) == 1} {catch {$sbar configure -text \$xth(gui,sbar,$widgx,otext); set xth(gui,sbar,$widgx,exp) 0}}"
  }
}

proc xth_status_bar_push aname {
  global xth
  catch {
  set sbar $xth(gui,$aname).sf.sbar
  if {![info exists xth(gui,sbar,$aname)]} {
    set xth(gui,sbar,$aname) [$sbar cget -text]
  } else {
    set xth(gui,sbar,$aname) [lappend $xth(gui,sbar,$aname) [$sbar cget -text]]
  }
  }
}


proc xth_status_bar_pop aname {
  global xth
  catch {
  set sbar $xth(gui,$aname).sf.sbar
  if {! [info exists xth(gui,sbar,$aname)]} {
    set xth(gui,sbar,$aname) ""
  } else {
    $sbar configure -text [lindex $xth(gui,sbar,$aname) 0]
    set xth(gui,sbar,$aname) [lreplace $xth(gui,sbar,$aname) 0 0]
  }
  }
}


proc xth_status_bar_status {aname txt} {
  global xth
  catch {
  set sbar $xth(gui,$aname).sf.sbar
  $sbar configure -text $txt
  update idletasks
  }
}









proc xth_scroll_showcmd {sbar cmd} {
  global xth
  set xth(scroll,$sbar,show) $cmd
  set xth(scroll,$sbar,open) 0
}

proc xth_scroll_hidecmd {sbar cmd} {
  global xth
  set xth(scroll,$sbar,hide) $cmd
  set xth(scroll,$sbar,open) 0
}

proc xth_scroll {sbar first last} {
  global xth
  if {[expr $first == 0.0] && [expr $last == 1.0]} {
    if {$xth(scroll,$sbar,open) == 1} {
      set xth(scroll,$sbar,open) 0
      eval $xth(scroll,$sbar,hide)
      update idletasks
    }
  } else {
    if {$xth(scroll,$sbar,open) == 0} {
      set xth(scroll,$sbar,open) 1
      eval $xth(scroll,$sbar,show)
      update idletasks
    }
    $sbar set $first $last
  }
}







set hm "$xth(gui,main).hmenu"
set xth(gui,menu,help) $hm

menu $hm -tearoff 0
$hm add command -label [mc "Control..."] -underline 0 -font $xth(gui,lfont) \
  -command xth_help_control_show
$hm add command -label [mc "BAC calculator..."] -underline 0 -font $xth(gui,lfont) \
  -command xth_bac_init
$hm add command -label [mc "About..."] -underline 0 -font $xth(gui,lfont) \
  -command {
    xth_about_show 1
    xth_about_status $xth(prj,title)
  }

proc xth_help_control_show {} {
  global xth
  if {[winfo exists $xth(gui,main).help_control]} {
    focus $xth(gui,main).help_control
  } else {
    xth_help_control_init
  }
}

proc xth_help_control_search {} {
}

proc xth_help_control_init {} {

  global xth
  
  set f $xth(gui,main).help_control
  toplevel $f
  wm transient $f $xth(gui,main)
  wm title $f "Xtherion control"

  set ff $f.lf
  frame $ff
  Entry $ff.se -font $xth(gui,lfont)
  Button $ff.sb -text [mc "Search"] -anchor center -font $xth(gui,lfont) \
  -command xth_help_control_search -width 8
  Button $ff.cb -text [mc "Close"] -anchor center -font $xth(gui,lfont) \
  -command "destroy $f" -width 8
  grid columnconf $ff 2 -weight 1
#  grid columnconf $ff 0 -weight 1
#  grid columnconf $ff 1 -weight 0
#  grid columnconf $ff 1 -weight 0
#  grid $ff.se -column 0 -row 0 -sticky news
#  grid $ff.sb -column 1 -row 0 -sticky news
  grid $ff.cb -column 2 -row 0 -sticky news


  set txb $f.tf
  frame $txb
  text $txb.txt -wrap none -font $xth(gui,lfont) \
    -relief sunken -state disabled \
    -selectbackground $xth(gui,ecolorselbg) \
    -selectforeground $xth(gui,ecolorselfg) \
    -selectborderwidth 0 \
    -yscrollcommand "$txb.sv set" \
    -xscrollcommand "$txb.sh set" 
  scrollbar $txb.sv -orient vert  -command "$txb.txt yview" \
    -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
  scrollbar $txb.sh -orient horiz  -command "$txb.txt xview" \
    -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
  grid columnconf $txb 0 -weight 1
  grid rowconf $txb 0 -weight 1
  grid $txb.txt -column 0 -row 0 -sticky news
  grid $txb.sv -column 1 -row 0 -sticky news
  grid $txb.sh -column 0 -row 1 -sticky news

  grid rowconf $f 0 -weight 1
  grid columnconf $f 0 -weight 1
  grid rowconf $f 1 -weight 0
  grid $txb -column 0 -row 0 -sticky news
  grid $ff -column 0 -row 1 -sticky news
  
 
  set sw [winfo screenwidth .]
  set sh [winfo screenheight .]
  update idletasks
  wm geometry $f +0+0
  wm geometry $f 640x480
  wm minsize $f 320 240
  set x [expr {($sw - [winfo width $f])/2}]
  set y [expr {($sh - [winfo height $f])/2}]
  wm geometry $f +$x+$y
  update idletasks
  
  $txb.txt configure -state normal
  set hlptxt [ mc "xtherion_help_control" ]  
  if {[string length $hlptxt] < 100} {
    set tmploc ::msgcat::mclocale
    ::msgcat::mclocale en
    set hlptxt [ mc "xtherion_help_control" ]  
    ::msgcat::mclocale $tmploc
  }
  $txb.txt insert end $hlptxt
    
     
  $txb.txt configure -state disabled
 
}










set xth(ctrl,all,number) 0

proc xth_ctrl_create {aname} {

  global xth
  
  set cf $xth(gui,$aname).af.ctrl  
    
  canvas $cf.c -yscrollcommand "xth_scroll $cf.sv" \
    -highlightthickness 0
  scrollbar $cf.sv -orient vert  -command "$cf.c yview" -takefocus 0 \
    -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)

  grid columnconf $cf 0 -weight 1
  grid rowconf $cf 0 -weight 1
  xth_scroll_showcmd $cf.sv "grid $cf.sv -row 0 -column 1 -sticky nsew; update idletasks; xth_ctrl_reshape te"
  xth_scroll_hidecmd $cf.sv "grid forget $cf.sv; update idletasks; xth_ctrl_reshape te"
  grid $cf.c -row 0 -column 0 -sticky nsew
  
  set xth(ctrl,$aname,number) 0
  set xth(ctrl,$aname,list) {}
}

proc xth_ctrl_add {aname cname title} {
  
  global xth
  
  incr xth(ctrl,$aname,number)
  incr xth(ctrl,all,number)
  lappend xth(ctrl,$aname,list) $cname
  set cn $xth(ctrl,$aname,number)
  set cf $xth(gui,$aname).af.ctrl  
  
  set ccf $cf.cf$cn
  frame $ccf
  frame $ccf.f 
  set cid [$cf.c create window 0 0 -window $ccf -anchor nw]
  set xth(ctrl,$aname,$cname) $ccf.f
  set xth(ctrl,$aname,$cname,frm) $ccf
  set xth(ctrl,$aname,$cname,pos) $cn
  set xth(ctrl,$aname,$cname,max) 1
  set xth(ctrl,$aname,$cname,menu) .xth_popup$xth(ctrl,all,number)
  set xth(ctrl,$aname,$cn) $cid 
  
  menu .xth_popup$xth(ctrl,all,number) -tearoff 0
  button $ccf.rb -text "$title" -command "xth_ctrl_minmax $aname $cname" \
    -font $xth(gui,lfont) -bg #aaaaaa \
    -fg white -bg darkBlue -activebackground lightBlue \
    -anchor w -relief flat \
    -takefocus 0
  bind $ccf.rb <Button-3> "tk_popup .xth_popup$xth(ctrl,all,number) %X %Y"
  xth_status_bar $aname $ccf.rb [mc "Show or hide this control panel"]
  
  pack $ccf.rb -side top -fill x -expand 1
  pack $ccf.f -expand yes -fill both

  xth_ctrl_reshape $aname
}


proc xth_ctrl_finish {aname} {

  global xth  

  foreach ct $xth(ctrl,$aname,list) {
    set cmn $xth(ctrl,$aname,$ct,menu)
    foreach oct $xth(ctrl,$aname,list) {
      if {[string compare $ct $oct] != 0} {
        $cmn add command -label [$xth(ctrl,$aname,$oct,frm).rb cget -text] \
          -command "xth_ctrl_replace $aname $ct $oct" -font $xth(gui,lfont)
      }
    }
  }

}


proc xth_ctrl_reshape {aname} {
  
  global xth
  set cn $xth(ctrl,$aname,number)
  set cnv $xth(gui,$aname).af.ctrl.c  
  
  # position the windows
  set height 0
  set width [winfo width $cnv]
  for {set i 1} {$i <= $cn} {incr i} {
    set cid $xth(ctrl,$aname,$i)
    set cw [$cnv itemcget $cid -window]
    $cnv coord $cid 0 $height
    $cnv itemconfigure $cid -width $width
    incr height [winfo height $cw]
  }

  $cnv configure -scrollregion "0 0 $width $height"
}

proc xth_ctrl_minmax {aname cname} {

  global xth

  set cmm $xth(ctrl,$aname,$cname,max)
  if {$cmm == 1} {
    pack forget $xth(ctrl,$aname,$cname)
    $xth(ctrl,$aname,$cname,frm).rb configure -relief raised
    set cmm 0
  } else {
    pack $xth(ctrl,$aname,$cname) -expand yes -fill both
    $xth(ctrl,$aname,$cname,frm).rb configure -relief flat
    set cmm 1
  }
  set xth(ctrl,$aname,$cname,max) $cmm
  
  update idletasks
  xth_ctrl_reshape $aname
}

proc xth_ctrl_replace {aname ccname dcname} {
  
  global xth

  set cnv $xth(gui,$aname).af.ctrl.c
  set p1 $xth(ctrl,$aname,$ccname,pos)
  set p2 $xth(ctrl,$aname,$dcname,pos)
  
  set xth(ctrl,$aname,$ccname,pos) $p2
  set xth(ctrl,$aname,$dcname,pos) $p1
  $cnv itemconfigure $xth(ctrl,$aname,$p1) \
    -window $xth(ctrl,$aname,$dcname,frm)
  $cnv itemconfigure $xth(ctrl,$aname,$p2) \
    -window $xth(ctrl,$aname,$ccname,frm)
    
  update idletasks
  xth_ctrl_reshape $aname
  
}

proc xth_ctrl_minimize {aname cname} {
  global xth
  set xth(ctrl,$aname,$cname,max) 1
  xth_ctrl_minmax $aname $cname
}

proc xth_ctrl_maximize {aname cname} {
  global xth
  set xth(ctrl,$aname,$cname,max) 0
  xth_ctrl_minmax $aname $cname
}

proc xth_ctrl_scroll_to {aname cname} {
  global xth
  set cf $xth(gui,$aname).af.ctrl
  set sr [$cf.c cget -scrollregion]
  set wp [$cf.c coord $xth(ctrl,$aname,[expr [lsearch $xth(ctrl,$aname,list) [lindex $xth(ctrl,$aname,list) [expr $xth(ctrl,$aname,$cname,pos) - 1]]] + 1])]
#  set wp [$cf.c coord $xth(ctrl,$aname,[expr [lsearch $xth(ctrl,$aname,list) $cname] + 1])]
  $cf.c yview moveto [expr [lindex $wp 1] / ([lindex $sr 3] - [lindex $sr 1])]   
}









proc xth_app_move_panel {aname xx} {
  global xth
  if {$xth(app,$aname,wpsw) == 1} {
    set xth(app,$aname,relw) [expr [winfo width $xth(gui,main)] - $xx + $xth(app,$aname,wrtx)]; 
  } else {
    set xth(app,$aname,relw) [expr $xx - $xth(app,$aname,wrtx)]; 
  }
  xth_app_place $aname
}


proc xth_app_create {aname title} {
  
  global xth
  
  set aw "$xth(gui,main).$aname"
  set xth(gui,$aname) $aw
  set xth(app,list) [concat $xth(app,list) $aname]
  if {![info exists xth(app,$aname,relw)]} {
    set xth(app,$aname,relw) $xth(app,all,relw)
  }
  if {![info exists xth(app,$aname,wpsw)]} {
    set xth(app,$aname,wpsw) $xth(app,all,wpsw)
  }
  if {![info exists xth(app,$aname,wmwd)]} {
    set xth(app,$aname,wmwd) $xth(app,all,wmwd)
  }
  
  # create and configure application frames
  frame $aw
  frame $aw.af
  frame $aw.af.apps
  frame $aw.af.ctrl
  frame $aw.af.lrhn -borderwidth 2 -relief raised -cursor sb_h_double_arrow
  xth_status_bar $aname $aw.af.lrhn [mc "Drag to resize control panel."]

  frame $aw.sf
  set sbar $aw.sf.sbar
  label $sbar -text "" -anchor w -relief sunken -font $xth(gui,lfont)
  pack $sbar -side left -fill both -expand 1
  
  bind $aw.af.lrhn <Configure> "set xth(app,$aname,wwid) \[winfo width $xth(gui,main)\]; set xth(app,$aname,wrtx) \[winfo rootx $xth(gui,main)]; xth_ctrl_reshape $aname"
  bind $aw.af.lrhn <B1-Motion> "xth_app_move_panel $aname %X"
  
  set amn $aw.menu
  menu $amn -tearoff 0
  set xth($aname,menu) $amn
  
  set fmn $amn.file
  menu $fmn -tearoff 0 
  $amn add cascade -label [mc "File"] -menu $fmn -font $xth(gui,lfont) -underline 0
  set xth($aname,menu,file) $fmn
  
  set xth($aname,title) $title
  set xth($aname,wtitle) [string tolower $title]

  pack $aw.af -expand yes -fill both
  pack $aw.sf -side bottom -fill x

  set fr $xth(app,$aname,relw)
  set minfr $xth(app,$aname,wmwd)
  set lrhny [expr [winfo height $xth(gui,main)] - 64]
  if {$fr < $minfr} {
    set fr $minfr
  } elseif {$fr > ([winfo width $xth(gui,main)] - $xth(app,$aname,wmwd))} {
    set fr [expr {([winfo width $xth(gui,main)] - $xth(app,$aname,wmwd))}]
  }
  set xth(app,$aname,relw) $fr
  set fr [expr 1.0 - $fr / double([winfo width $xth(gui,main)])]
  
  if {$xth(app,$aname,wpsw) == 1} {
    place $aw.af.apps -relx 0 -rely 0 -relheight 1 -relwidth $fr
    place $aw.af.ctrl -relx $fr -rely 0 -relheight 1 -relwidth [expr 1.0 - $fr]
    place $aw.af.lrhn -relx $fr -y $lrhny -width 8 -height 8 -anchor center
  } else {
    place $aw.af.ctrl -relx 0 -rely 0 -relheight 1 -relwidth $fr
    place $aw.af.apps -relx $fr -rely 0 -relheight 1 -relwidth [expr 1.0 - $fr]
    place $aw.af.lrhn -relx $fr -y $lrhny -width 8 -height 8 -anchor center
  }
  
  xth_ctrl_create $aname
  
}


proc xth_app_clock {} {
  global xth
  set xth(gui,clock) [clock format [clock seconds] -format "%H:%M"]
  after 15000 xth_app_clock
}


proc xth_app_place {aname} {
  
  global xth
  set aw "$xth(gui,main).$aname"

  set fr $xth(app,$aname,relw)
  set minfr $xth(app,$aname,wmwd)
  if {$fr < $minfr} {
    set fr $minfr
  } elseif {$fr > ([winfo width $xth(gui,main)] - $xth(app,$aname,wmwd))} {
    set fr [expr {([winfo width $xth(gui,main)] - $xth(app,$aname,wmwd))}]
  }
  set xth(app,$aname,relw) $fr
  set fr [expr 1.0 - $fr / double([winfo width $xth(gui,main)])]

  set lrhny [expr [winfo height $xth(gui,main)] - 64]
  
  if {$xth(app,$aname,wpsw) == 1} {
    place configure $aw.af.apps -relx 0 -relwidth $fr
    place configure $aw.af.ctrl -relx $fr -relwidth [expr 1.0 - $fr]
    place configure $aw.af.lrhn -relx $fr -y $lrhny
  } else {
    place configure $aw.af.apps -relx [expr 1.0 - $fr] -relwidth $fr
    place configure $aw.af.ctrl -relx 0 -relwidth [expr 1.0 - $fr]
    place configure $aw.af.lrhn -relx [expr 1.0 - $fr] -y $lrhny
  }

  xth_ctrl_reshape $aname   
}

proc xth_app_switch {} {

  global xth
  
  set aname $xth(app,active)
  
  if {$xth(app,$aname,wpsw) == 1} {
    set xth(app,$aname,wpsw) 0
  } else {
    set xth(app,$aname,wpsw) 1
  }
  
  xth_app_place $aname
}


proc xth_app_finish {} {

  global xth
  
  # add Window menu to each menu
  set m "$xth(gui,main).wmenu"
  menu $m -tearoff 0
  set i 0
  
  set xth(gui,menu,window) $m

  foreach aname $xth(app,list) {

    if {[llength $xth(app,list)] > 1} {
      set i [expr $i + 1]
      $m add command -label $xth($aname,title) -accelerator "F$i" \
        -command "xth_app_show $aname" -font $xth(gui,lfont)
      bind $xth(gui,main) <F$i> "xth_app_show $aname"
    }
    
    # add clock to aname
    set clockbar $xth(gui,$aname).sf.clockbar
    label $clockbar -textvariable xth(gui,clock) -anchor center \
      -relief sunken -font $xth(gui,lfont) -width 5
    pack $clockbar -side left

  }
  if {[llength $xth(app,list)] > 1} {
    $m add separator
  }
  $m add command -label [mc "Maximize"] -underline 1 \
      -command "xth_app_maximize" -font $xth(gui,lfont)
  $m add command -label [mc "Normalize"] -underline 1 \
      -command "xth_app_normalize" -font $xth(gui,lfont)
  $m add command -label [mc "Switch panels"] -underline 1 \
      -command "xth_app_switch" -font $xth(gui,lfont)
  $m add separator

  $m add command -label [mc "Toggle toolbar"] -underline 1 \
      -command "xth_tools_toggle" -font $xth(gui,lfont)
  
  menu $m.kbes -tearoff 0
  set encnames [encoding names]
  set xth(encoding_system) [encoding system]
  foreach ecd [lsort $xth(kbencodings)] {
    if {[lsearch $encnames $ecd] >= 0} {
      $m.kbes add radiobutton -label $ecd \
        -command "encoding system $ecd\nset xth(encoding_system) \[encoding system\]" -font $xth(gui,lfont) \
        -variable xth(encoding_system) -value $ecd
    }
  }
  $m add cascade -label [mc "KBD encoding"] -menu $m.kbes
  

  if {$xth(debug)} {
    set dm "$xth(gui,main).dmenu"
    menu $dm -tearoff 0
  
    $dm add command -label "Refresh procs" -underline 0 -command {
      source global.tcl
      source sbar.tcl
      source cp_procs.tcl
      source te_sdata.tcl
      source me_imgs.tcl
      source me_cmds.tcl
      source me_cmds2.tcl
      source me_ss.tcl
      source bac.tcl
      source mv_procs.tcl
    } -font $xth(gui,lfont)
    $dm add command -label "Screen dump" -underline 0 -command {
      after 5000 {xwd -out screendump -frame}
    } -font $xth(gui,lfont)
    $dm add separator
    $dm add command -label "Show command console" -underline 1 \
      -command "wm deiconify $xth(gui,dbg); wm transient $xth(gui,dbg) $xth(gui,main)" -font $xth(gui,lfont)
    $dm add command -label "Hide command console" -underline 1 \
      -command "wm withdraw $xth(gui,dbg)" -font $xth(gui,lfont)
  }

  bind $xth(gui,main) <$xth(kb_control)-Key-q> "xth_exit"
  bind $xth(gui,main) <$xth(kb_control)-Key-o> xth_app_control_o 
  bind $xth(gui,main) <$xth(kb_control)-Key-r> xth_app_control_r 
  bind $xth(gui,main) <$xth(kb_control)-Key-w> xth_app_control_w
  bind $xth(gui,main) <$xth(kb_control)-Key-s> xth_app_control_s 
  bind $xth(gui,main) <$xth(kb_control)-Key-z> xth_app_control_z
  bind $xth(gui,main) <$xth(kb_control)-Key-y> xth_app_control_y 
  bind $xth(gui,main) <$xth(kb_control)-Key-p> xth_app_control_p 
  bind $xth(gui,main) <$xth(kb_control)-Key-l> xth_app_control_l 
  bind $xth(gui,main) <$xth(kb_control)-Key-d> xth_app_control_d
  bind $xth(gui,main) <$xth(kb_control)-Key-a> xth_app_control_a
  bind $xth(gui,main) <Prior> xth_app_pgup
  bind $xth(gui,main) <Next> xth_app_pgdn
  bind $xth(gui,main) <Shift-Prior> xth_app_shift_pgup
  bind $xth(gui,main) <Shift-Next> xth_app_shift_pgdn
  bind $xth(gui,main) <Key-Escape> xth_app_escape 
  bind $xth(gui,main) <F9> xth_app_make
  foreach aname $xth(app,list) {
    $xth($aname,menu) add cascade -label [mc "Window"] -menu $m -underline 0 \
      -font $xth(gui,lfont)
    if $xth(debug) {
      $xth($aname,menu) add cascade -label "Debug" -menu $dm -underline 0 \
        -font $xth(gui,lfont)
    }
    $xth($aname,menu,file) add separator
    $xth($aname,menu,file) add command -label [mc "Compile"] -underline 0 \
      -command "xth_app_make" -font $xth(gui,lfont) \
      -accelerator "F9"
    $xth($aname,menu,file) add command -label [mc "Quit"] -underline 0 \
      -command "xth_exit" -font $xth(gui,lfont) \
      -accelerator "$xth(gui,controlk)-q"
    $xth($aname,menu) add cascade -label [mc "Help"] -menu $xth(gui,menu,help) \
      -underline 0  -font $xth(gui,lfont)
  }  

}

proc xth_app_title {aname} {
  
  global xth
  
  # set the application menu
  set ofn ""
  if {[info exists xth($aname,open_file)]} {
    set ofn $xth($aname,open_file)
  }
  if {[string length $xth($aname,wtitle)] > 0} {
    set atit " $xth($aname,wtitle)"
  } else {
    set atit ""
  }
  if {[string equal $aname me] && ([string length $xth(me,curscrap)] > 0)} {
    set sname " - $xth(me,curscrap)"
  } else {
    set sname ""
  }
  if {[string length $ofn] > 0} {
    wm title $xth(gui,main) "$xth(prj,name)$atit - $xth($aname,open_file)$sname"
  } else {
    wm title $xth(gui,main) "$xth(prj,name)$atit$sname"
  }
}

proc xth_app_control_o {} {

  global xth

  # puts $xth(app,active)  
  switch $xth(app,active) {
    te  {xth_te_open_file 1 {} 1}
    me  {xth_me_open_file 1 {} 1}
    cp  {
      set xth(cp,updcf) 0
      xth_cp_open_file {}
    }
    mv {xth_mv_open_file {}}
  }
}  


proc xth_app_pgup {} {
  global xth
  switch $xth(app,active) {
    te  {}
    me  {
      $xth(gui,main).me.af.ctrl.c yview scroll -1 pages
    }
    cp  {}
    mv {}
  }
}

proc xth_app_pgdn {} {
  global xth
  switch $xth(app,active) {
    te  {}
    me  {
      $xth(gui,main).me.af.ctrl.c yview scroll 1 pages
    }
    cp  {}
    mv {}
  }
}

proc xth_app_shift_pgup {} {
  global xth
  switch $xth(app,active) {
    te  {}
    me  {
      $xth(ctrl,me,cmds).cl.l yview scroll -1 pages
    }
    cp  {}
    mv {}
  }
}


proc xth_app_shift_pgdn {} {
  global xth
  switch $xth(app,active) {
    te  {}
    me  {
      $xth(ctrl,me,cmds).cl.l yview scroll 1 pages
    }
    cp  {}
    mv {}
  }
}


proc xth_app_control_a {} {

  global xth

  # puts $xth(app,active)  
  switch $xth(app,active) {
    te  {}
    me  {
      xth_me_cmds_create_area {} 1 "" "" ""
      xth_ctrl_scroll_to me ac
      xth_ctrl_maximize me ac
    }
    cp  {}
    mv {}
  }
}  


proc xth_app_control_r {} {

  global xth

  # puts $xth(app,active)  
  switch $xth(app,active) {
    te  {}
    me  {
      xth_me_cmds_create_scrap {} 1 "" ""
      xth_ctrl_scroll_to me scrap
      xth_ctrl_maximize me scrap
    }
    
    cp  {}
    mv {xth_mv_reload_file}
  }
}  


proc xth_app_control_w {} {

  global xth

  # puts $xth(app,active)  
  switch $xth(app,active) {
    me  {xth_me_close_file}
    cp  {xth_cp_close_file}
  }
}  

proc xth_app_control_s {} {

  global xth

  # puts $xth(app,active)  
  switch $xth(app,active) {
    me  {xth_me_save_file 0}
  }
}  


proc xth_app_control_z {} {

  global xth

  # puts $xth(app,active)  
  switch $xth(app,active) {
    me  {xth_me_unredo_undo}
  }
  
}  

proc xth_app_control_y {} {

  global xth

  # puts $xth(app,active)  
  switch $xth(app,active) {
    me  {xth_me_unredo_redo}
  }
}  

proc xth_app_control_p {} {
  global xth
  switch $xth(app,active) {
    me  {xth_me_cmds_set_mode 1}
  }
}  


proc xth_app_control_d {} {
  global xth
  switch $xth(app,active) {
    me  {xth_me_cmds_delete {}}
  }
}  


proc xth_app_control_l {} {
  global xth
  switch $xth(app,active) {
    me  {
      xth_me_cmds_create_line {} 1 "" "" ""
      xth_ctrl_scroll_to me line
      xth_ctrl_maximize me line
      xth_ctrl_maximize me linept
    }
  }
}  


proc xth_app_escape {} {
  global xth
  switch $xth(app,active) {
    me  {xth_me_cmds_set_mode 0}
  }
}


proc xth_app_show {aname} {

  global xth
  
  if {[string equal $xth(app,active) $aname]} {
    return;
  }
  
  if {![string equal $xth(app,active) ""]} {
    pack forget $xth(gui,$xth(app,active))
  }

  set xth(app,active) $aname
  pack $xth(gui,$aname) -expand yes -fill both

  xth_app_title $aname

  $xth(gui,main) configure -menu $xth($aname,menu)
  
  regexp {([0-9]+)x([0-9]+)} [winfo geometry $xth(gui,main)] geom xsize ysize

  if {($xsize < [lindex $xth(gui,minsize) 0]) || \
      ($ysize < [lindex $xth(gui,minsize) 1])} {
    if {($xsize < [lindex $xth(gui,minsize) 0])} {
      set xsize [lindex $xth(gui,minsize) 0]
    }
    if {($ysize < [lindex $xth(gui,minsize) 1])} {
      set ysize [lindex $xth(gui,minsize) 1]
    }
    set ogeom [winfo geometry $xth(gui,main)]
    regsub $geom $ogeom [format "%sx%s" $xsize $ysize] ngeom
    wm geometry $xth(gui,main) $ngeom
  }

  update idletasks  
  xth_ctrl_reshape $aname
  
  # toolbar changes
  # disable map editor tools
  catch {
    pack forget $xth(gui,tb).edif
    pack forget $xth(gui,tb).self
  }
  switch $aname {
    cp {
    }
    me {
      # enable map editor tools
      pack $xth(gui,tb).self -side right -anchor nw
      pack $xth(gui,tb).edif -side right
    }
    mv {
    }    
  }
}


proc xth_exit {} {

  global xth

  # save all open text editor files
  if {![info exists xth(te,flist)]} {
    set xth(te,flist) {}
  }
  
  foreach cfid $xth(te,flist) {
    if {[xth_te_before_close_file $cfid yesnocancel] == 0} {
      return
    }
  }
  
  if {[info exists xth(me,fopen)]} {
    if {$xth(me,fopen) == 1} {
      if {[xth_me_before_close_file yesnocancel] == 0} {
        return
      }
    }
  }

  if {[info exists xth(cp,fopen)]} {
    xth_cp_close_file
  }
  
  destroy $xth(gui,main)
  update
  destroy .    
  
}


proc xth_app_maximize {} {
  global xth
  set swd [winfo screenwidth $xth(gui,main)]
  set shg [winfo screenheight $xth(gui,main)]
  wm geometry $xth(gui,main) [format "%dx%d+0+0" $swd $shg]
  update idletasks
  regexp {([0-9]+)x([0-9]+)\+([0-9]+)\+([0-9]+)} [winfo geometry $xth(gui,main)] geom xsize ysize xshft yshft
  wm geometry $xth(gui,main) [format "%dx%d+0+0" [expr $swd - $xshft] [expr $shg - $yshft]]
  update idletasks
}

proc xth_app_normalize {} {
  global xth
  set twd [expr int(0.8 * [winfo screenwidth $xth(gui,main)])]
  if {$twd < [lindex $xth(gui,minsize) 0]} {
    set twd [lindex $xth(gui,minsize) 0]
  }
  set thg [expr int(0.8 * [winfo screenheight $xth(gui,main)])]
  if {$thg < [lindex $xth(gui,minsize) 1]} {
    set thg [lindex $xth(gui,minsize) 1]
  }
  set tpx [expr int(0.5 * ([winfo screenwidth $xth(gui,main)] - $twd))]
  set tpy [expr int(0.5 * ([winfo screenheight $xth(gui,main)] - $thg))]
  wm geometry $xth(gui,main) [format "%dx%d+%d+%d" $twd $thg $tpx $tpy]
  update idletasks
  regexp {([0-9]+)x([0-9]+)\+([0-9]+)\+([0-9]+)} [winfo geometry $xth(gui,main)] geom xsize ysize xshft yshft
  wm geometry $xth(gui,main) [format "%dx%d+%d+%d" [expr $twd - $xshft + $tpx] \
    [expr $thg - $yshft + $tpy] $tpx $tpy]
  update idletasks
}

proc xth_app_clipboard {ev} {
  global xth
  set w [focus -lastfor $xth(gui,main)]
  if {[winfo ismapped $w]} {
    switch $ev {
      cut {
         event generate $w <<Cut>>
      }
      copy {
         event generate $w <<Copy>>
      }
      paste {
         event generate $w <<Paste>>
      }
      undo {
         event generate $w <<Undo>>
      }
      redo {
         event generate $w <<Redo>>
      }
    }
  }
}


proc xth_app_check_text_undo_redo {} {
  global xth
  catch {
    set w [focus -lastfor $xth(gui,main)]
    if {[winfo ismapped $w]} {
      catch {
        $w edit separator
      }
    }
  }
  after idle {after 1000 xth_app_check_text_undo_redo}
}

if {$xth(gui,text_undo)} {
  after idle {after 1000 xth_app_check_text_undo_redo}
}


proc xth_app_make {} {
  global xth
  set oactive $xth(app,active)
  if {[string length $oactive] == 0} {
    set oactive cp
  }
  xth_te_save_all
  xth_me_save_file 0
  switch $oactive {
    cp {}
    default {
      set xth(cp,updcf) 0
      xth_app_show cp
    }
  }
  if {!$xth(cp,fopen)} {
    xth_cp_open_file {}
  }
  update idletasks
  if {[xth_cp_compile]} {
    if {[string equal $xth(gui,platform) windows]} {
      xth_app_show te
      xth_app_show me
      xth_app_show cp
    }
    if {![string equal $oactive cp]} {
      xth_app_show $oactive
    }
  }
}


proc xth_app_autosave_schedule {} {
  global xth
  if $xth(gui,auto_save) {
    set xth(gui,auto_save,id) [after 60000 xth_app_autosave]
  } else {
    catch {
      after cancel $xth(gui,auto_save,id)
    }
  }
}

proc xth_app_autosave {} {
  global xth
  switch $xth(app,active) {
    me {xth_me_save_file 0}
    te {xth_te_save_all}
  }
  xth_app_autosave_schedule
}










xth_about_status [mc "loading text editor ..."]

if {[string equal -nocase $xth(prj,name) svxedit]} {
  xth_app_create te {}
} else {
  xth_app_create te [mc "Text Editor"]
}

xth_ctrl_add te files [mc "Files"]
xth_ctrl_add te sdata [mc "Data table"]
xth_ctrl_add te sr [mc "Search & Replace"]
xth_ctrl_finish te

set xth(te,open_file_encoding) $xth(app,fencoding)

set xth(te,bind,text_tab) {
  if { [string equal [%W cget -state] "normal"] } {
    xth_te_insert_tab %W
    break
  }
}

set xth(te,bind,text_return) {
  regexp {(\d+)\.} [%W index insert] dum cln
  set spcs ""
  regexp {^\s+} [%W get $cln.0 $cln.end] spcs
#  set spcsc [string length $spcs]
#  set indct [string length [xth_te_get_indent %W $cln.0 1]]
#  if {$spcsc == $indct} {
#  } elseif {$spcsc > $indct} {
#    %W delete $cln.0 $cln.[expr $spcsc - $indct]
#  } elseif {$spcsc < $indct} {
#    %W insert $cln.0 [format \x25[expr $indct - $spcsc]s " "]
#  }
#  xth_te_insert_text %W "\n[xth_te_get_indent %W [expr $cln + 1].0 0]"
  xth_te_insert_text %W "\n$spcs"
}


proc xth_te_insert_text {w s} {
    if {[string equal $s ""] || [string equal [$w cget -state] "disabled"]} {
	return
    }
    set compound 0
    catch {
	if {[$w compare sel.first <= insert] \
		&& [$w compare sel.last >= insert]} {
            set oldSeparator [$w cget -autoseparators]
            if { $oldSeparator } {
                $w configure -autoseparators 0
                $w edit separator
                set compound 1
            }
	    $w delete sel.first sel.last
	}
    }
    $w insert insert $s
    $w see insert
    if { $compound && $oldSeparator } {
        $w edit separator
        $w configure -autoseparators 1
    }
}


proc xth_te_insert_tab W {
  global xth
  regexp {\.(\d+)} [$W index insert] dum col
  set nsp [expr $xth(gui,etabsize) - ($col % $xth(gui,etabsize))]
  xth_te_insert_text $W  [format \x25$nsp\s " "]
  focus $W
}


proc xth_te_sdata_enable {w} {
  global xth
  if {[string length $w] < 1} {
    set w $xth(ctrl,te,sdata)
  }
  set chlist [winfo children $w]
  if {[llength $chlist] > 0} {
    foreach sdw $chlist {
      catch {$sdw configure -state normal}
      catch {xth_te_sdata_enable $sdw}
    }
  }
}

proc xth_te_sdata_disable {w} {
  global xth
  if {[string length $w] < 1} {
    set w $xth(ctrl,te,sdata)
  }
  set chlist [winfo children $w]
  if {[llength $chlist] > 0} {
    foreach sdw $chlist {
      catch {$sdw configure -state disabled}
      catch {xth_te_sdata_disable $sdw}
    }
  }
}


set xth(te,flist) {}
set xth(te,fcurr) -1
set xth(te,fltid) 0

# create position bar
set pbar $xth(gui,te).sf.pbar
label $pbar -text "2.0" -width 8 -relief sunken -font $xth(gui,lfont)
pack $pbar -side left


# file control
frame $xth(ctrl,te,files).fl
set flbox $xth(ctrl,te,files).fl.flbox 
listbox $flbox -height 6 -selectmode single -takefocus 1 \
  -yscrollcommand "xth_scroll $xth(ctrl,te,files).fl.sv" \
  -xscrollcommand "xth_scroll $xth(ctrl,te,files).fl.sh" \
  -font $xth(gui,lfont) -exportselection no \
  -selectborderwidth 1

scrollbar $xth(ctrl,te,files).fl.sv -orient vert  -command "$flbox yview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
scrollbar $xth(ctrl,te,files).fl.sh -orient horiz  -command "$flbox xview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
frame $xth(ctrl,te,files).ef

  
bind $flbox <<ListboxSelect>> "xth_te_show_file \[lindex \[%W curselection\] 0\]"

grid columnconf $xth(ctrl,te,files).fl 0 -weight 1
grid rowconf $xth(ctrl,te,files).fl 0 -weight 1
grid $flbox -column 0 -row 0 -sticky news
xth_scroll_showcmd $xth(ctrl,te,files).fl.sv "grid $xth(ctrl,te,files).fl.sv -column 1 -row 0 -sticky news"
xth_scroll_hidecmd $xth(ctrl,te,files).fl.sv "grid forget $xth(ctrl,te,files).fl.sv"
xth_scroll_showcmd $xth(ctrl,te,files).fl.sh "grid $xth(ctrl,te,files).fl.sh -column 0 -row 1 -sticky news"
xth_scroll_hidecmd $xth(ctrl,te,files).fl.sh "grid forget $xth(ctrl,te,files).fl.sh"
xth_status_bar te $flbox [mc "Switch open files."]
grid columnconf $xth(ctrl,te,files) 0 -weight 1
grid $xth(ctrl,te,files).fl -column 0 -row 0 -sticky news
if {![string equal -nocase $xth(prj,name) svxedit]} {
grid $xth(ctrl,te,files).ef -column 0 -row 1 -sticky news
}
Label $xth(ctrl,te,files).ef.ecl -text [mc "Encoding"] -anchor e -font $xth(gui,lfont) -state disabled
ComboBox $xth(ctrl,te,files).ef.ecb -values $xth(encodings) \
  -textvariable xth(te,open_file_encoding) \
  -font $xth(gui,lfont) -height 4 -command xth_te_set_encoding \
  -state disabled
Button $xth(ctrl,te,files).ef.chb -text [mc "Change to"] -anchor e -font $xth(gui,lfont) -padx 1 -state disabled -command xth_te_set_encoding
Label $xth(ctrl,te,files).ef.cel -text "" -anchor w -padx 2 -font $xth(gui,lfont) -state disabled
#grid columnconf $xth(ctrl,te,files).ef 0 -weight 0
grid columnconf $xth(ctrl,te,files).ef 1 -weight 1
grid $xth(ctrl,te,files).ef.ecl -column 0 -row 0 -sticky news
grid $xth(ctrl,te,files).ef.cel -column 1 -row 0 -sticky news
grid $xth(ctrl,te,files).ef.chb -column 0 -row 1 -sticky news
grid $xth(ctrl,te,files).ef.ecb -column 1 -row 1 -sticky ew
xth_status_bar te $xth(ctrl,te,files).ef [mc "To set file encoding, type encoding name and press <Change> button."]

frame $xth(gui,te).af.apps.ff -bg $xth(gui,ecolorbg)
pack $xth(gui,te).af.apps.ff -fill both -expand yes



# table control
Button $xth(ctrl,te,sdata).sfb -text [mc "Scan data format"] \
  -font $xth(gui,lfont) -state disabled
xth_status_bar te $xth(ctrl,te,sdata).sfb \
  [mc "Scan data format and rebuild centerline data insertion tool."]

checkbutton $xth(ctrl,te,sdata).sfs -text [mc "Enter station names"] -anchor w \
  -font $xth(gui,lfont) -variable xth(te,sdata,es) -state disabled
xth_status_bar te $xth(ctrl,te,sdata).sfs \
  [mc "Check if you want to insert station names for each shot."]

frame $xth(ctrl,te,sdata).sdf

button $xth(ctrl,te,sdata).taf -text [mc "Auto format selection"] \
  -font $xth(gui,lfont) -state disabled
xth_status_bar te $xth(ctrl,te,sdata).taf [mc "Format selection to given table."]

grid columnconf $xth(ctrl,te,sdata) 0 -weight 1
grid $xth(ctrl,te,sdata).sfb -column 0 -row 0 -sticky nsew
grid $xth(ctrl,te,sdata).sdf -column 0 -row 1 -sticky nsew
grid $xth(ctrl,te,sdata).sfs -column 0 -row 2 -sticky nsew
grid $xth(ctrl,te,sdata).taf -column 0 -row 3 -sticky nsew




set sfm $xth(ctrl,te,sr)

set xth(ctrl,te,sr,selection_io) 0
set xth(ctrl,te,sr,search) ""
set xth(ctrl,te,sr,replace_io) 0
set xth(ctrl,te,sr,replace) ""
set xth(ctrl,te,sr,case_io) 0
set xth(ctrl,te,sr,regular_io) 0
set xth(ctrl,te,sr,selection_io) 0

set xth(ctrl,te,sr,selection_start) {}
set xth(ctrl,te,sr,selection_end) {}
set xth(ctrl,te,sr,search_end) end

Label $sfm.seal -text [mc "search"] -anchor w -font $xth(gui,lfont) -state disabled \
  -width 4
xth_status_bar te $sfm.seal [mc "Search expression."]
Entry $sfm.seae -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,te,sr,search)
xth_status_bar te $sfm.seae [mc "Search expression."]

checkbutton $sfm.replc -text [mc "replace"] -anchor w -font $xth(gui,lfont) \
  -state disabled -width 4 \
  -variable xth(ctrl,te,sr,replace_io) \
  -command {}
xth_status_bar te $sfm.replc [mc "Check whether to replace found expression."]
Entry $sfm.reple -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,te,sr,replace)
xth_status_bar te $sfm.reple [mc "Replace expression."]

checkbutton $sfm.ccase -text [mc "case sensitive search"] -anchor w -font $xth(gui,lfont) \
  -state disabled -width 0 \
  -variable xth(ctrl,te,sr,case_io) \
  -command {}
xth_status_bar te $sfm.ccase [mc "Check if search should be case sensitive."]

checkbutton $sfm.creg -text [mc "regular expressions"] -anchor w -font $xth(gui,lfont) \
  -state disabled -width 0 \
  -variable xth(ctrl,te,sr,regular_io) \
  -command {}
xth_status_bar te $sfm.creg [mc "Check whether to evaluate search and replace as regular expressions."]

checkbutton $sfm.csel -text [mc "search selection only"] -anchor w -font $xth(gui,lfont) \
  -state disabled -width 0 \
  -variable xth(ctrl,te,sr,selection_io) \
  -command {}
xth_status_bar te $sfm.csel [mc "Check whether to do search only in selected text."]

Button $sfm.bfirst -text [mc "First"] -anchor center -font $xth(gui,lfont) \
  -state disabled -width 4 -command te_sr_first
xth_status_bar te $sfm.bfirst [mc "Search or replace first expression in the file."]
Button $sfm.bnext -text [mc "Next"] -anchor center -font $xth(gui,lfont) \
  -state disabled -width 4 -command te_sr_next
xth_status_bar te $sfm.bnext [mc "Search or replace next expression after the cursor in the file."]
Button $sfm.ball -text [mc "All"] -anchor center -font $xth(gui,lfont) \
  -state disabled -width 4 -command te_sr_all
xth_status_bar te $sfm.ball [mc "Search or replace all expressions in the file."]
Button $sfm.bclear -text [mc "Clear"] -anchor center -font $xth(gui,lfont) \
  -state disabled -width 4 -command {
    te_sr_clear
    set xth(ctrl,te,sr,replace_io) 0
    update idletasks
  }
xth_status_bar te $sfm.bclear [mc "Clear all highlights in the file."]


grid columnconf $sfm 0 -weight 1
grid columnconf $sfm 1 -weight 1
grid $sfm.seal -row 0 -column 0 -sticky news
grid $sfm.seae -row 1 -column 0 -sticky news
grid $sfm.replc -row 0 -column 1 -sticky news
grid $sfm.reple -row 1 -column 1 -sticky news
grid $sfm.ccase -row 2 -column 0 -columnspan 2 -sticky news
grid $sfm.creg -row 3 -column 0 -columnspan 2 -sticky news
grid $sfm.csel -row 4 -column 0 -columnspan 2 -sticky news
grid $sfm.bfirst -row 5 -column 0 -sticky news
grid $sfm.bnext -row 5 -column 1 -sticky news
grid $sfm.ball -row 6 -column 0 -sticky news
grid $sfm.bclear -row 6 -column 1 -sticky news





proc xth_te_show_file {fidx} {

  global xth
  
  if {$xth(te,fcurr) >= 0} {
    pack forget $xth(te,[lindex $xth(te,flist) $xth(te,fcurr)],frame)
  }
  
  if {$fidx < 0} {
    set fidx 0
  }
  if {$fidx >= [llength $xth(te,flist)]} {
    set fidx [expr [llength $xth(te,flist)] - 1]
  }
  
  set xth(te,fcurr) $fidx
  if {$xth(te,fcurr) >= 0} {
    set cfid [lindex $xth(te,flist) $xth(te,fcurr)]
    pack $xth(te,$cfid,frame) -expand yes -fill both
    $xth(ctrl,te,files).fl.flbox delete $xth(te,fcurr)
    $xth(ctrl,te,files).fl.flbox insert $xth(te,fcurr) "[expr $xth(te,fcurr) + 1]. $xth(te,$cfid,name) ($xth(te,$cfid,path))"
    $xth(ctrl,te,files).fl.flbox see $fidx
    $xth(ctrl,te,files).fl.flbox selection clear 0 end
    $xth(ctrl,te,files).fl.flbox selection set $fidx $fidx
    focus $xth(te,[lindex $xth(te,flist) $xth(te,fcurr)],frame).txt
    set xth(te,open_file) $xth(te,$cfid,name)
    # set xth(te,open_file_encoding) $xth(te,$cfid,encoding)
    $xth(ctrl,te,files).ef.cel configure -text $xth(te,$cfid,encoding)
    $xth(ctrl,te,files).ef.ecl configure -state normal
    $xth(ctrl,te,files).ef.ecb configure -state normal
    $xth(ctrl,te,files).ef.chb configure -state normal
    $xth(ctrl,te,files).ef.cel configure -state normal
    $xth(te,menu) entryconfigure [mc "Edit"] -state normal
    $xth(te,menu,file) entryconfigure [mc "Save"] -state normal
    $xth(te,menu,file) entryconfigure [mc "Save as"] -state normal
    $xth(te,menu,file) entryconfigure [mc "Save all"] -state normal
    $xth(te,menu,file) entryconfigure [mc "Auto save"] -state normal
    $xth(te,menu,file) entryconfigure [mc "Close"] -state normal
    $xth(ctrl,te,sr).seal configure -state normal
    $xth(ctrl,te,sr).seae configure -state normal
    $xth(ctrl,te,sr).replc configure -state normal
    $xth(ctrl,te,sr).reple configure -state normal
    $xth(ctrl,te,sr).ccase configure -state normal
    $xth(ctrl,te,sr).creg configure -state normal
    $xth(ctrl,te,sr).csel configure -state normal
    $xth(ctrl,te,sr).bfirst configure -state normal
    $xth(ctrl,te,sr).bnext configure -state normal
    $xth(ctrl,te,sr).ball configure -state normal 
    $xth(ctrl,te,sr).bclear configure -state normal
    if {[llength $xth(te,flist)] > 1} {
      $xth(te,menu,file) entryconfigure [mc "Next"] -state normal
      $xth(te,menu,file) entryconfigure [mc "Previous"] -state normal
    } else {
      $xth(te,menu,file) entryconfigure [mc "Next"] -state disabled
      $xth(te,menu,file) entryconfigure [mc "Previous"] -state disabled
    }
    xth_te_sdata_enable ""
  } else {
    set xth(te,open_file) ""
    set xth(te,open_file_encoding) $xth(app,fencoding)
    $xth(te,menu,file) entryconfigure [mc "Save"] -state disabled
    $xth(te,menu,file) entryconfigure [mc "Save as"] -state disabled
    $xth(te,menu,file) entryconfigure [mc "Save all"] -state disabled
    $xth(te,menu,file) entryconfigure [mc "Auto save"] -state disabled
    $xth(te,menu,file) entryconfigure [mc "Close"] -state disabled
    $xth(te,menu,file) entryconfigure [mc "Next"] -state disabled
    $xth(te,menu,file) entryconfigure [mc "Previous"] -state disabled
    $xth(ctrl,te,files).ef.ecl configure -state disabled
    $xth(ctrl,te,files).ef.ecb configure -state disabled
    $xth(ctrl,te,files).ef.chb configure -state disabled
    $xth(ctrl,te,files).ef.cel configure -state disabled -text ""
    xth_te_sdata_disable ""
    $xth(te,menu) entryconfigure [mc "Edit"] -state disabled
    $xth(ctrl,te,sr).seal configure -state disabled
    $xth(ctrl,te,sr).seae configure -state disabled
    $xth(ctrl,te,sr).replc configure -state disabled
    $xth(ctrl,te,sr).reple configure -state disabled
    $xth(ctrl,te,sr).ccase configure -state disabled
    $xth(ctrl,te,sr).creg configure -state disabled
    $xth(ctrl,te,sr).csel configure -state disabled
    $xth(ctrl,te,sr).bfirst configure -state disabled
    $xth(ctrl,te,sr).bnext configure -state disabled
    $xth(ctrl,te,sr).ball configure -state disabled 
    $xth(ctrl,te,sr).bclear configure -state disabled
    xth_ctrl_minimize te sr
  }
  xth_app_title te
  
}


proc xth_te_set_encoding {} {

  global xth
 
  if {$xth(te,fcurr) >= 0} {
    # convert encoding into system's one
    set rxp "\\s+($xth(te,open_file_encoding))\\s+"
    if {[regexp -nocase $rxp $xth(encodings) dum temp]} {
      set xth(te,open_file_encoding) $temp
      set xth(te,[lindex $xth(te,flist) $xth(te,fcurr)],encoding) $temp
      $xth(ctrl,te,files).ef.cel configure -text $temp
    } else {
      MessageDlg $xth(gui,message) -parent $xth(gui,main) \
        -icon error -type ok \
        -message "uknown encoding -- $xth(te,open_file_encoding)" \
        -font $xth(gui,lfont)
    }
  }
}

proc xth_te_switch_file {fdr} {
  global xth
  set cf $xth(te,fcurr)
  if {$cf != -1} {
    incr cf $fdr
    if {$cf < 0} {
      set cf [expr [llength $xth(te,flist)] - 1]
    }
    if {$cf >= [llength $xth(te,flist)]} {
      set cf 0
    }
    xth_te_show_file $cf
  }
}


proc xth_te_create_file {} {

  global xth
  xth_status_bar_status te ""
  
  # create file variables
  incr xth(te,fltid)
  set cfid $xth(te,fltid)
  #set xth(te,$cfid,name) [format "noname%d$xth(app,te,fileext)" $cfid]
  set xth(te,$cfid,name) [format "(new file)" $cfid]
  set xth(te,$cfid,path) [file join $xth(gui,initdir) $xth(te,$cfid,name)]
  set xth(te,$cfid,newf) 1
  set xth(te,$cfid,mtime) 0
  set xth(te,$cfid,encoding) $xth(app,fencoding)
  set xth(te,$cfid,frame) $xth(gui,te).af.apps.ff.file$cfid
  set cfr $xth(te,$cfid,frame)

  # create the frame and bind the events
  set iac {if {[string equal $xth(app,active) te]} }
  frame $cfr
  text $cfr.txt  -font $xth(gui,efont) -bg $xth(gui,ecolorbg) \
    -fg $xth(gui,ecolorfg) -insertbackground $xth(gui,ecolorfg) \
    -yscrollcommand "$cfr.sv set" \
    -xscrollcommand "$cfr.sh set" \
    -relief sunken \
    -selectbackground $xth(gui,ecolorselbg) \
    -selectforeground $xth(gui,ecolorselfg) \
    -selectborderwidth 0 \
    -wrap none
  if {$xth(gui,text_undo)} {
    $cfr.txt configure -undo 1 -maxundo -1
  }
  set xth(te,$cfid,otext) [$cfr.txt get 1.0 end]
  scrollbar $cfr.sv -orient vert  -command "$cfr.txt yview" \
    -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
  scrollbar $cfr.sh -orient horiz  -command "$cfr.txt xview" \
    -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
  bind $cfr.txt <Tab> "$iac {$xth(te,bind,text_tab)}"
  bind $cfr.txt <Return> "$iac {$xth(te,bind,text_return)}"
  bind $cfr.txt <<xthPositionChange>> "xth_te_update_position $cfr.txt"
  bind $cfr.txt <Key> "+ $iac {event generate $cfr.txt <<xthPositionChange>> -when tail}"
  bind $cfr.txt <Button-1> "+ $iac {event generate $cfr.txt <<xthPositionChange>> -when tail}"
  bind $cfr.txt <$xth(kb_control)-Key-1> "$iac {xth_te_show_file 0}"
  bind $cfr.txt <$xth(kb_control)-Key-2> "$iac {xth_te_show_file 1}"
  bind $cfr.txt <$xth(kb_control)-Key-3> "$iac {xth_te_show_file 2}"
  bind $cfr.txt <$xth(kb_control)-Key-4> "$iac {xth_te_show_file 3}"
  bind $cfr.txt <$xth(kb_control)-Key-5> "$iac {xth_te_show_file 4}"
  bind $cfr.txt <$xth(kb_control)-Key-6> "$iac {xth_te_show_file 5}"
  bind $cfr.txt <$xth(kb_control)-Key-7> "$iac {xth_te_show_file 6}"
  bind $cfr.txt <$xth(kb_control)-Key-8> "$iac {xth_te_show_file 7}"
  bind $cfr.txt <$xth(kb_control)-Key-9> "$iac {xth_te_show_file 8}"
  bind $cfr.txt <$xth(kb_control)-Key-0> "$iac {xth_te_show_file 9}"
  bind $cfr.txt <$xth(kb_control)-Key-n> "$iac {xth_te_switch_file 1}"
  bind $cfr.txt <$xth(kb_control)-Key-p> "$iac {xth_te_switch_file -1}"
  bind $cfr.txt <$xth(kb_control)-Key-w> "$iac {xth_te_close_file}"
  bind $cfr.txt <$xth(kb_control)-Key-a> "$iac {xth_te_select_all}"
  bind $cfr.txt <$xth(kb_control)-Key-i> "$iac {xth_te_auto_indent}"
  bind $cfr.txt <$xth(kb_control)-Key-s> "$iac {xth_te_save_file 0 $cfid}"
  bind $cfr.txt <Destroy> "xth_te_before_close_file $cfid yesno"  
#  if {$xth(gui,bindclip) == 1} {
    bind $cfr.txt <$xth(kb_control)-Key-x> "$iac {tk_textCut $cfr.txt}"
    bind $cfr.txt <$xth(kb_control)-Key-c> "$iac {tk_textCopy $cfr.txt}"
    bind $cfr.txt <$xth(kb_control)-Key-v> "$iac {tk_textPaste $cfr.txt}"
    bind $cfr.txt <$xth(kb_control)-Key-z> "$iac {catch {$cfr.txt edit undo}}"
    bind $cfr.txt <$xth(kb_control)-Key-y> "$iac {catch {$cfr.txt edit redo}}"
  if {$xth(gui,bindinsdel)} {
    bind $cfr.txt <Delete> {
      %W delete insert
      %W see insert
    }
    bind $cfr.txt <Shift-Key-Delete> "$iac {tk_textCut $cfr.txt}"
    bind $cfr.txt <$xth(kb_control)-Key-Insert> "$iac {tk_textCopy $cfr.txt}"
    bind $cfr.txt <Shift-Key-Insert> "$iac {tk_textPaste $cfr.txt}"
#    catch {
#      bind $cfr.txt <Shift-Key-KP_Decimal> "$iac {tk_textCut $cfr.txt}"
#      bind $cfr.txt <$xth(kb_control)-Key-KP_Insert> "$iac {tk_textCopy $cfr.txt}"
#      bind $cfr.txt <Shift-Key-KP_0> "$iac {tk_textPaste $cfr.txt}"
#    }
  }
#  }
    
  grid columnconf $cfr 0 -weight 1
  grid rowconf $cfr 0 -weight 1
  grid $cfr.txt -column 0 -row 0 -sticky news
  grid $cfr.sv -column 1 -row 0 -sticky news
  grid $cfr.sh -column 0 -row 1 -sticky news
  
  
  # add file to list and listbox
  set xth(te,flist) [linsert $xth(te,flist) end $cfid]
  $xth(ctrl,te,files).fl.flbox insert end "[llength $xth(te,flist)]. $xth(te,$cfid,name) ($xth(te,$cfid,path))"
  
  xth_te_show_file [expr [llength $xth(te,flist)] - 1]

}


# xth_te_read_file --
#
# return list containing
# {success name encoding text}

proc xth_te_read_file {pth} {

  global errorInfo xth

  set curenc utf-8
  set nm [file tail $pth]
  set encspc 0
  set flnn 0
  set success 1
  set txt ""
  if {[catch {set fid [open $pth r]}]} {
    set success 0
    set nm $errorInfo
    return [list $success $nm $curenc $txt]
  }
  fconfigure $fid -encoding $curenc
  while {[eof $fid] != 1} {
    gets $fid fln
    # replace tabs
    regsub -all {\t} $fln "  " fln
    incr flnn
    if {[regexp {^\s*encoding\s+(\S+)\s*$} $fln encln enc]} {
      if {$encspc} {
        set success 0
        set nm "$pth \[$flnn\] -- multiple encoding commands in file"
        break
      }
      set encspc 1
      set rxp "\\s+($enc)\\s+"
      set validenc [regexp -nocase $rxp $xth(encodings) dum curenc]
      if {$validenc == 0} {
        set success 0
        set nm "$pth \[$flnn\] -- unknown encoding -- $enc"
        break
      }
      fconfigure $fid -encoding $curenc
    } else {
#      if {$encspc == 0} {
#        if {[regexp {^\s*[^\#]+} $fln]} {
#          set success 0
#          set nm "$pth \[$flnn\] -- encoding command expected"
#          break
#        }
#      }
      append txt "$fln\n"
    }
  }
  close $fid
  return [list $success $nm $curenc $txt]
  
}  


# xth_te_write_file --
#
# return list containing
# {success name}

proc xth_te_write_file {pth enc txt} {

  global errorInfo xth

  set curenc utf-8
  set nm [file tail $pth]
  set success 1
  if {[catch {set fid [open $pth w]}]} {
    set success 0
    set nm $errorInfo
    return [list $success $nm]
  }
  
  fconfigure $fid -encoding $curenc -translation {auto lf}
  if {![string equal $xth(prj,name) svxedit]} {
    puts $fid "encoding  $enc"
  }
  fconfigure $fid -encoding $enc -translation {auto lf}
  puts -nonewline $fid $txt
  close $fid
  return [list $success $nm]
  
}


proc xth_te_destroy_file {} {

  global xth

  if {$xth(te,fcurr) >= 0} {
  

    # delete file from list and listbox and destroy windows
    set tempcurr $xth(te,fcurr)
    set cfid [lindex $xth(te,flist) $tempcurr]
    pack forget $xth(te,$cfid,frame)
    set xth(te,flist) [lreplace $xth(te,flist) $xth(te,fcurr) $xth(te,fcurr)]
    $xth(ctrl,te,files).fl.flbox delete $tempcurr    
    set xth(te,fcurr) -1

    # set other window to be active
    xth_te_show_file $tempcurr
    
    # destroy variable
    unset xth(te,$cfid,name)
    unset xth(te,$cfid,path)
    unset xth(te,$cfid,newf)
    unset xth(te,$cfid,encoding)
    unset xth(te,$cfid,frame)
    unset xth(te,$cfid,otext)
  }  
  
}


proc xth_te_open_file {dialogid fname fline} {

  global xth
  
  if {$dialogid} {
    set fname [tk_getOpenFile -filetypes $xth(app,te,filetypes) \
      -parent $xth(gui,main) \
      -initialdir $xth(gui,initdir) -defaultextension $xth(app,te,fileext)]
  }
  
  if {[string length $fname] == 0} {
    return 0
  } else {
    set xth(gui,initdir) [file dirname $fname]
  }
  
  # now let's open file fname
  
  # check if not open exists
  for {set fid 0} {$fid < [llength $xth(te,flist)]} {incr fid} {
    if {[string equal $fname $xth(te,[lindex $xth(te,flist) $fid],path)]} {
      xth_te_show_file $fid
      return 1
    }
  }
  
  # read the file
  xth_status_bar_push te
  xth_status_bar_status te [format [mc "Opening %s ..."] $fname]
  
  set fdata [xth_te_read_file $fname]
  if {[lindex $fdata 0] == 0} {
      MessageDlg $xth(gui,message) -parent $xth(gui,main) \
        -icon error -type ok \
        -message [lindex $fdata 1] \
        -font $xth(gui,lfont)
      xth_status_bar_pop te
      return 0
  }
  
  # show the file
  xth_te_create_file
  set cfid [lindex $xth(te,flist) $xth(te,fcurr)]
  set xth(te,$cfid,name) [lindex $fdata 1]
  set xth(te,$cfid,path) $fname
  set xth(te,$cfid,newf) 0
  set xth(te,$cfid,mtime) [file mtime $fname]
  set xth(te,$cfid,encoding) [lindex $fdata 2]
  $xth(ctrl,te,files).ef.cel configure -text [lindex $fdata 2]
  regsub -all {\s*$} [lindex $fdata 3] "" ftext
  xth_te_insert_text $xth(te,$cfid,frame).txt "$ftext\n"
  catch {
    $xth(te,$cfid,frame).txt edit reset
  }
  set xth(te,$cfid,otext) [$xth(te,$cfid,frame).txt get 1.0 end]
  xth_te_show_file $xth(te,fcurr) 
  $xth(te,$cfid,frame).txt mark set insert "$fline.0"
  $xth(te,$cfid,frame).txt see insert
  if {$fline > 0} {
    $xth(te,$cfid,frame).txt tag remove sel 1.0 end
    $xth(te,$cfid,frame).txt tag add sel "$fline.0" "$fline.0 lineend"
  }
  
  xth_status_bar_pop te
  return 1
}

proc xth_te_before_close_file {cfid btns} {
  global xth
  if {
      [catch {winfo exists $xth(te,$cfid,frame).txt}] 
      || (![winfo exists $xth(te,$cfid,frame).txt])} {
    return 1
  }
  set ftext [$xth(te,$cfid,frame).txt get 1.0 end]
  if {[string compare $xth(te,$cfid,otext) $ftext] != 0} {    
    set wtd [MessageDlg $xth(gui,message) -parent $xth(gui,main) \
      -icon question -type $btns\
      -message [format [mc "File %s is not saved. Save it now?"] $xth(te,$cfid,path)]\
      -font $xth(gui,lfont)]
    switch $wtd {
      0 {
        if {[xth_te_save_file 0 $cfid] == 0} {
          return 0
        }
      }
      1 {}
      default {return 0}
    }
  }
  return 1
}

proc xth_te_close_file {} {

  global xth
  
  if {$xth(te,fcurr) < 0} {
    return
  }
  set cfid [lindex $xth(te,flist) $xth(te,fcurr)]
  if {[xth_te_before_close_file $cfid yesnocancel]} {
    xth_te_destroy_file
    return 1
  } else {
    return 0
  }
  
}

proc xth_te_save_file {dialogid cfid} {

  global xth
  
  if {[llength $xth(te,flist)] == 0} {
    return 0
  }

  set fid [lsearch -exact $xth(te,flist) $cfid]
  if {$fid == -1} {
    return 0
  }
  
  set cfid [lindex $xth(te,flist) $fid]
  
  # let's check if we need to save
  set ftext [$xth(te,$cfid,frame).txt get 1.0 end]
  if {! $dialogid} {
    if {[string compare $xth(te,$cfid,otext) $ftext] == 0} {
        return 1
    }
  }
  
  xth_status_bar_push te
  
  if {$xth(te,$cfid,newf)} {
    set dialogid 1
  }

  set fname $xth(te,$cfid,path)
  set ofname $fname
  if {$dialogid} {
    set fname [tk_getSaveFile -filetypes $xth(app,te,filetypes) \
      -parent $xth(gui,main) \
      -initialfile [file tail $fname] -initialdir [file dirname $fname] \
      -defaultextension $xth(app,te,fileext)]
  }
  
  if {($xth(te,$cfid,mtime) > 0) && [file exists $fname] && \
    ([file mtime $fname] > $xth(te,$cfid,mtime))} {
    set forcesave [MessageDlg $xth(gui,message) -parent $xth(gui,main) \
      -icon warning -type yesno -default 1 \
      -message [format [mc "File %s was modified outside xtherion. Save it anyway?"] $fname]\
      -font $xth(gui,lfont)]
    if {$forcesave != 0} {
      return 0
    }
  }
  
  if {[string length $fname] == 0} {
    return 0
  } else {
    set xth(gui,initdir) [file dirname $fname]
  }
  
  # save the file
  xth_status_bar_status te [format [mc "Saving %s ..."] $fname]
  set fdata [xth_te_write_file $fname $xth(te,$cfid,encoding) $ftext]
  if {[lindex $fdata 0] == 0} {
      MessageDlg $xth(gui,message) -parent $xth(gui,main) \
        -icon error -type ok \
        -message [lindex $fdata 1] \
        -font $xth(gui,lfont)
      xth_status_bar_pop te
      return 0
  }
  
  set xth(te,$cfid,mtime) [file mtime $fname]
  set xth(te,$cfid,otext) $ftext
  set xth(te,$cfid,newf) 0
  
  # if SaveAs, then redisplay the file
  if {$dialogid} {
    if {[string compare $ofname $fname] != 0} {
      set xth(te,$cfid,name) [lindex $fdata 1]
      set xth(te,$cfid,path) $fname
      xth_te_show_file $fid
    }
  }  

  after 250 {xth_status_bar_pop te}
  return 1
    
}

proc xth_te_save_all {} {

  global xth
  set ocur $xth(te,fcurr)
  foreach cfid $xth(te,flist) {
    xth_te_save_file 0 $cfid
  }
  xth_te_show_file $ocur
  
}


proc xth_te_update_position {W} {
  global xth
  regexp {(\d+)\.(\d+)} [$W index insert] dum lns pos
  $xth(gui,te).sf.pbar configure -text [format "%d.%d" [expr $lns + 1] $pos]
}


proc xth_te_text_select_all {txt} {
    $txt tag add sel 1.0 end
}


proc xth_te_select_all {} {
  global xth
  if {$xth(te,fcurr) > -1} {
    set cfid [lindex $xth(te,flist) $xth(te,fcurr)]
    $xth(te,$cfid,frame).txt tag add sel 1.0 end
  }
}

proc xth_te_new_file {} {
  global xth
  xth_te_create_file 
  set cfid [lindex $xth(te,flist) $xth(te,fcurr)]
  xth_te_insert_text $xth(te,$cfid,frame).txt $xth(te,template)
}

$xth(te,menu,file) add command -label [mc "New"] -command xth_te_new_file \
  -font $xth(gui,lfont) -underline 0
$xth(te,menu,file) add command -label [mc "Open"] -underline 0 \
  -accelerator "$xth(gui,controlk)-o" \
  -font $xth(gui,lfont) -command {xth_te_open_file 1 {} 1}
$xth(te,menu,file) add command -label [mc "Save"] -underline 0 \
  -accelerator "$xth(gui,controlk)-s" -state disabled \
  -font $xth(gui,lfont) -command {
    if {$xth(te,fcurr) >= 0} {
      xth_te_save_file 0 [lindex $xth(te,flist) $xth(te,fcurr)]
    }
  }
$xth(te,menu,file) add command -label [mc "Save as"] -underline 5 \
  -font $xth(gui,lfont) -state disabled -command {
    if {$xth(te,fcurr) >= 0} {
      xth_te_save_file 1 [lindex $xth(te,flist) $xth(te,fcurr)]
    }
  }
$xth(te,menu,file) add command -label [mc "Save all"] -underline 6 \
  -font $xth(gui,lfont) -state disabled -command xth_te_save_all
$xth(te,menu,file) add checkbutton -label [mc "Auto save"] -underline 1 \
  -variable xth(gui,auto_save) -font $xth(gui,lfont) \
  -state disabled -command xth_app_autosave_schedule
$xth(te,menu,file) add command -state disabled -label [mc "Close"] -underline 0 \
  -accelerator "$xth(gui,controlk)-w" \
  -font $xth(gui,lfont) \
  -command "xth_te_close_file"

$xth(te,menu,file) add separator
$xth(te,menu,file) add command -state disabled -label [mc "Next"] \
  -accelerator "$xth(gui,controlk)-n" \
  -font $xth(gui,lfont) -command "xth_te_switch_file 1" -underline 2
$xth(te,menu,file) add command -state disabled -label [mc "Previous"] \
  -accelerator "$xth(gui,controlk)-p" \
  -font $xth(gui,lfont) -command "xth_te_switch_file -1" -underline 0
  
set xth(te,menu,edit) $xth(te,menu).edit
menu $xth(te,menu,edit) -tearoff 0
$xth(te,menu) add cascade -label [mc "Edit"] -state disabled \
  -font $xth(gui,lfont) -menu $xth(te,menu,edit) -underline 0
if {$xth(gui,text_undo)} {
  $xth(te,menu,edit) add command -label [mc "Undo"] -font $xth(gui,lfont) \
    -accelerator "$xth(gui,controlk)-z" -command "xth_app_clipboard undo"
  $xth(te,menu,edit) add command -label [mc "Redo"] -font $xth(gui,lfont) \
    -accelerator "$xth(gui,controlk)-y" -command "xth_app_clipboard redo"
  $xth(te,menu,edit) add separator
}
$xth(te,menu,edit) add command -label [mc "Cut"] -font $xth(gui,lfont) \
  -accelerator "$xth(gui,controlk)-x" -command "xth_app_clipboard cut"
$xth(te,menu,edit) add command -label [mc "Copy"] -font $xth(gui,lfont) \
  -accelerator "$xth(gui,controlk)-c" -command "xth_app_clipboard copy"
$xth(te,menu,edit) add command -label [mc "Paste"] -font $xth(gui,lfont) \
  -accelerator "$xth(gui,controlk)-v" -command "xth_app_clipboard paste"
$xth(te,menu,edit) add separator
$xth(te,menu,edit) add command -label [mc "Select all"] -font $xth(gui,lfont) \
  -accelerator "$xth(gui,controlk)-a" -command "xth_te_select_all"
$xth(te,menu,edit) add command -label [mc "Auto indent"] -font $xth(gui,lfont) \
  -command "xth_te_auto_indent" -accelerator "$xth(gui,controlk)-i"

proc xth_te_get_indent {w i cilc} {

  global xth
  set indls ""
  set cmdls ""
  set cmd0s ""
  set cmdl 0
  regexp {(\d+)\.} $i dum cln
  set line0 [$w get $cln.0 $cln.end]
  regexp {\S+} $line0 cmd0s
  if {[info exists xth(cmd,$cmd0s)]} {
    set cmd0 $xth(cmd,$cmd0s)
  } else {
    set cmd0 0
  }
  set sln [expr $cln - 1]
  set line1 [$w get $sln.0 $sln.end]
  set linel $line1
  set hasl 0
  set escan 0
  while {($sln > 1) && (! $hasl)} {
    incr sln -1
    if {[regexp {\S} $linel]} {
      set cline [$w get $sln.0 $sln.end]
      if {[regexp {\\\s*$} $cline]} {
        set linel $cline
      } else {
        set hasl 1
      }
    } else {
      set linel [$w get $sln.0 $sln.end]
    }
  }
  regexp {\S+} $linel cmdls
  if {[info exists xth(cmd,$cmdls)]} {
    set cmdl $xth(cmd,$cmdls)
    set endcmdls $xth(endcmd,$cmdls)
  } else {
    set cmdl 0
  }
  regexp {^\s+} $linel indls
  set indl [string length $indls]
  set bsl1 [regexp {\\\s*$} $line1]
  
  # preskenuje prikazy nad
  #puts "cilc |$cilc|\nindl |$indl|\ncmd0 |$cmd0|\ncmd0s |$cmd0s|\ncmdl |$cmdl|\ncmdls |$cmdls|\n"
  if {$cmdl == 1} {
#    puts "$cln. cilc |$cilc|"
    set cmdcomct 0
    set cmdcomctfi 1
    set enddetect 0
    set set_cmd_counts {
      regexp {\S+} $slns cmdcomx
#      puts "$cmdls ?? $cmdcomx"
      if {[string compare $endcmdls $cmdcomx] == 0} {
        set endscan 1
        set enddetect 1
      } elseif {[string compare $cmdls $cmdcomx] == 0} {
        if {! $cmdcomctfi} {
          if {$cmdcomct} {
            set endscan 1
          }
          incr cmdcomct
        } else {
          set cmdcomctfi 0
        }
      }
    }
    set sln [expr $cln - 1]
    set slns $line1
    set endscan 0
    while {($sln > 1) && (!$endscan)} {
      incr sln -1
      if {[regexp {\S} $slns]} {
        set clns [$w get $sln.0 $sln.end]
        if {[regexp {(.*)\\\s*$} $clns dum vlns]} {
          set slns "$vlns$slns"
        } else {
          eval $set_cmd_counts
          set slns $clns
        }
      } else {
        set slns [$w get $sln.0 $sln.end]
      }
    }
    if {!$enddetect} {
      eval $set_cmd_counts
    }
 #   puts $cmdcomct
    if {$cmdcomct > 0} {
      set cmdl 0
    }
  }
  # koniec scanovania
  
  if {$bsl1} {
    set ind [expr $indl + 2 * $xth(gui,etabsize)]
  } else {
    set ind $indl
    if {$cmdl > 0} {
      incr ind $xth(gui,etabsize)
    } 
    if {$cilc && ($cmd0 < 0)} {
      incr ind -$xth(gui,etabsize)
    } 
  }
  
  if {$ind > 0} {
    return [format %$ind\s " "]
  } else {
    return ""
  }
}

proc xth_te_auto_indent {} {

  global xth
  if {$xth(te,fcurr) < 0} {
    return
  }
  set cfid [lindex $xth(te,flist) $xth(te,fcurr)]
  set W $xth(te,$cfid,frame).txt
  set rngs [$W tag ranges sel]
  set fln 1
  set tln -1
  regexp {(\d+)\.} [lindex $rngs 0] dum fln
  regexp {(\d+)\.} [lindex $rngs 1] dum tln
  xth_status_bar_push te
  for {set cln $fln} {$cln < $tln} {incr cln} {
    xth_status_bar_status te [format [mc "Processing line %s ..."] $cln]
    $W see $cln.0
    set spcs ""
    regexp {^\s+} [$W get $cln.0 $cln.end] spcs
    set spcsc [string length $spcs]
    set indct [string length [xth_te_get_indent $W $cln.0 1]]
    if {$spcsc == $indct} {
    } elseif {$spcsc > $indct} {
      $W delete $cln.0 $cln.[expr $spcsc - $indct]
    } elseif {$spcsc < $indct} {
      $W insert $cln.0 [format \x25[expr $indct - $spcsc]s " "]
    }
  }
  $W see insert
  # $W tag remove sel 1.0 end
  xth_status_bar_pop te
}


proc xth_te_text_auto_indent {W} {

  set rngs [$W tag ranges sel]
  set fln 1
  set tln -1
  regexp {(\d+)\.} [lindex $rngs 0] dum fln
  regexp {(\d+)\.} [lindex $rngs 1] dum tln
  for {set cln $fln} {$cln < $tln} {incr cln} {
    $W see $cln.0
    set spcs ""
    regexp {^\s+} [$W get $cln.0 $cln.end] spcs
    set spcsc [string length $spcs]
    set indct [string length [xth_te_get_indent $W $cln.0 1]]
    if {$spcsc == $indct} {
    } elseif {$spcsc > $indct} {
      $W delete $cln.0 $cln.[expr $spcsc - $indct]
    } elseif {$spcsc < $indct} {
      $W insert $cln.0 [format \x25[expr $indct - $spcsc]s " "]
    }
  }
  $W see insert
  
}

xth_ctrl_minimize te sr
xth_status_bar_status te [mc "Text editor is not active. To activate it, open existing file or create new one."]






proc xth_te_sdata_scan {} {

  global xth
  if {$xth(te,fcurr) < 0} {
    return [list [expr 2 * $xth(gui,etabsize)] {from to compass clino tape}]
  }
  
  set w $xth(te,[lindex $xth(te,flist) $xth(te,fcurr)],frame).txt  

  # let's find the index
  set seli [$w tag ranges sel]
  if {[llength $seli] > 0} {
    set i [lindex $seli 0]
  } else {
    set i [$w index insert]
  }
  
  regexp {(\d+)\.} $i dum cln
  incr cln
  set i [$w index $cln.0]
  regexp {(\d+)\.} $i dum cln
    
  set dind [format \x25[expr 2 * $xth(gui,etabsize)]s " "]
  set dqts {from to compass clino tape}
  set scan_data {
    if {[regexp {(\s*)data\s+\w+\s+(.*)} $slns dum dind dqts]} {
      set endscan 1
    }
  }
  set sln $cln
  set slns ""
  set endscan 0
  while {($sln > 1) && (!$endscan)} {
    incr sln -1
    if {[regexp {\S} $slns]} {
      set clns [$w get $sln.0 $sln.end]
      if {[regexp {(.*)\\\s*$} $clns dum vlns]} {
        set slns "$vlns$slns"
      } else {
        eval $scan_data
        set slns $clns
      }
    } else {
      set slns [$w get $sln.0 $sln.end]
    }
  }
  if {!$endscan} {
    eval $scan_data
  }
  
  return [list [string length $dind] $dqts]     
}


proc xth_te_sdata_buid {qts indc} {

  global xth
  set cf $xth(ctrl,te,sdata).sdf
  catch {destroy $cf}
  frame $cf 
  grid $cf -in $xth(ctrl,te,sdata) -column 0 -row 1 -sticky nsew
  grid columnconf $cf 0 -weight 0
  grid columnconf $cf 1 -weight 1
  grid columnconf $cf 2 -weight 0

  set nent 0
  set invd 0
  set sent 0
  set grow 0
  foreach qtt $qts {
    switch $qtt {
      newline {
        if {(!$invd) && ($nent > 0)} {
          frame $cf.nlf
          grid columnconf $cf.nlf 0 -weight 1
          grid columnconf $cf.nlf 1 -weight 1
          Button $cf.nlf.s$grow -text "Start series" -font $xth(gui,lfont)
          Button $cf.nlf.b$grow -text "Break series" -font $xth(gui,lfont)
          grid $cf.nlf.s$grow -column 0 -row 0 -sticky news
          grid $cf.nlf.b$grow -column 1 -row 0 -sticky news
          grid $cf.nlf -in $cf -column 0 -columnspan 3 -row $grow \
            -sticky news
          set xth(te,sdata,invd,ssb) $cf.nlf.s$grow
          set xth(te,sdata,invd,bsb) $cf.nlf.b$grow
          set xth(te,sdata,invd,ent) $nent
          set invd 1
          incr grow
        }
      }
      default {
        # zistime typ
        if {[info exists xth(datafmt,$qtt,format)]} {
          set tqtt $qtt
        } else {
          set tqtt "unknown"
        }
        set xth(te,sdata,$nent,qtt) $tqtt
        set xth(te,sdata,$nent,format) $xth(datafmt,$tqtt,format)
        set xth(te,sdata,$nent,cvalue) ""
        set xth(te,sdata,$nent,special) $xth(datafmt,$tqtt,special)
        set xth(te,sdata,$nent,de) $cf.de$grow
        set xth(te,sdata,$nent,fe) $cf.fe$grow
        set xth(te,sdata,$nent,nextde) $cf.de$grow
        set xth(te,sdata,$nent,nextvde) $cf.de$grow
        Label $cf.l$grow -text $qtt -anchor e -font $xth(gui,lfont)
        Entry $cf.de$grow -font $xth(gui,lfont) \
          -textvariable xth(te,sdata,$nent,cvalue)
        Entry $cf.fe$grow -font $xth(gui,lfont) -width 6 \
          -textvariable xth(te,sdata,$nent,format)
        bind $cf.de$grow <<xthFocusTo>> "focus $cf.de$grow; $cf.de$grow icursor 0; $cf.de$grow selection range 0 end"
        bind $cf.de$grow <Key-Tab> "event generate \$xth(te,sdata,$nent,nextde) <<xthFocusTo>> -when tail"
        bind $cf.de$grow <Key-Return> "event generate \$xth(te,sdata,$nent,nextvde) <<xthFocusTo>> -when tail"
        bind $cf.de$grow <Key-KP_Enter> "event generate \$xth(te,sdata,$nent,nextvde) <<xthFocusTo>> -when tail"
        grid $cf.l$grow -in $cf -column 0 -row $grow -sticky news
        grid $cf.de$grow -in $cf  -column 1 -row $grow -sticky news
        grid $cf.fe$grow -in $cf  -column 2 -row $grow -sticky news
        incr grow
        incr nent
      }
    }
  }
  
  set xth(te,sdata,nent) $nent
  set xth(te,sdata,indc) $indc
  set xth(te,sdata,invd) $invd
  
  xth_te_sdata_bind
}


proc xth_te_sdata_incr_station {ss} {
  return [xth_incr_station_name $ss 1]
}

proc xth_te_sdata_incr {} {

  global xth
  if {$xth(te,sdata,incr,station) != -1} {
    set xth(te,sdata,$xth(te,sdata,incr,station),cvalue) \
      [xth_te_sdata_incr_station \
      $xth(te,sdata,$xth(te,sdata,incr,station),cvalue)]
  } else {
    if {$xth(te,sdata,incr,from) != -1} {
      if {$xth(te,sdata,incr,to) != -1} {
        set xth(te,sdata,$xth(te,sdata,incr,from),cvalue) \
            $xth(te,sdata,$xth(te,sdata,incr,to),cvalue)
      }
    }
    if {$xth(te,sdata,incr,to) != -1} {
      set xth(te,sdata,$xth(te,sdata,incr,to),cvalue) \
        [xth_te_sdata_incr_station \
        $xth(te,sdata,$xth(te,sdata,incr,to),cvalue)]
    }    
  }
  
}


proc xth_te_sdata_cspc {itm} {
  if {[regexp {^\s*[^\"\[]\S*\s+\S+} $itm]} {
    #"
    set itm "\[$itm\]"
  }
  return $itm
}


proc xth_te_sdata_bind {} {

  global xth

  if {! [info exists xth(te,sdata,nent)]} {
    return
  } elseif {$xth(te,sdata,nent) < 1} {
    return
  }

  set xth(te,sdata,incr,station) -1
  set xth(te,sdata,incr,from) -1
  set xth(te,sdata,incr,to) -1
  for {set i 0} {$i < $xth(te,sdata,nent)} {incr i} {
    if {$i != [expr $xth(te,sdata,nent) - 1]} {
      set xth(te,sdata,$i,nextde) $xth(te,sdata,[expr $i + 1],de)
      set xth(te,sdata,$i,nextvde) $xth(te,sdata,[expr $i + 1],de)
    } else {
      set xth(te,sdata,$i,nextde) $xth(te,sdata,0,de)
      set xth(te,sdata,$i,nextvde) $xth(te,sdata,0,de)
    }
    set sx [lsearch {from to station} $xth(te,sdata,$i,qtt)]
    if {$sx != -1} {
      set xth(te,sdata,incr,[lindex {from to station} $sx]) $i
    }
  }
  
  if {! $xth(te,sdata,es)} {
    for {set i 0} {$i < $xth(te,sdata,nent)} {incr i} {
      if {[lsearch {station from to} $xth(te,sdata,$i,qtt)] == -1} {
        for {set j 1} {$j < $xth(te,sdata,nent)} {incr j} {
          set jj [expr ($i + $j) % $xth(te,sdata,nent)]
          if {[lsearch {station from to} $xth(te,sdata,$jj,qtt)] == -1} {
            set xth(te,sdata,$i,nextvde) $xth(te,sdata,$jj,de)
            set j $xth(te,sdata,nent)
          }
        }
      }
    }  
  }
  
  # now let's bind enter keys
  if {$xth(te,sdata,invd)} {
    set wtw1 ""
    set wtw2 ""
    set clw ""
    for {set iet 0} {$iet < $xth(te,sdata,nent)} {incr iet} {
      if {$iet < $xth(te,sdata,invd,ent)} {
        append wtw1 " \[xth_te_sdata_cspc \$xth(te,sdata,$iet,cvalue)\]"
      } else {
        append wtw2 " \[xth_te_sdata_cspc \$xth(te,sdata,$iet,cvalue)\]"
      }
      if {[lsearch {from to station} $xth(te,sdata,$iet,qtt)] == -1} {
        append clw "set xth(te,sdata,$iet,cvalue) \"\"\n"
      }
    }
    set enter_cmd "xth_te_sdata_insert \"$wtw2\" 2 insert\nxth_te_sdata_insert \"$wtw1\" 1 insert\nxth_te_sdata_incr\n$clw"
    append enter_cmd "event generate \$xth(te,sdata,[expr $xth(te,sdata,nent) - 1],nextvde) <<xthFocusTo>> -when tail"
    bind $xth(te,sdata,[expr $xth(te,sdata,nent) - 1],de) <Return> $enter_cmd
    bind $xth(te,sdata,[expr $xth(te,sdata,nent) - 1],de) <KP_Enter> $enter_cmd

    set enter_cmd "xth_te_sdata_insert \"$wtw1\" 1 insert\nxth_te_sdata_incr\n$clw"
    append enter_cmd "event generate \$xth(te,sdata,[expr $xth(te,sdata,nent) - 1],nextvde) <<xthFocusTo>> -when tail"
    $xth(te,sdata,invd,ssb) configure -command $enter_cmd

    set enter_cmd "xth_te_sdata_insert \"break\" 3 insert\n$clw"
    append enter_cmd "event generate \$xth(te,sdata,0,de) <<xthFocusTo>> -when tail"
    $xth(te,sdata,invd,bsb) configure -command $enter_cmd
    
  } else {
    set wtw ""
    set clw ""
    for {set iet 0} {$iet < $xth(te,sdata,nent)} {incr iet} {
      append wtw " \[xth_te_sdata_cspc \$xth(te,sdata,$iet,cvalue)\]"
      if {[lsearch {from to station} $xth(te,sdata,$iet,qtt)] == -1} {
        append clw "set xth(te,sdata,$iet,cvalue) \"\"\n"
      }
    }
    set enter_cmd "xth_te_sdata_insert \"$wtw\" 0 insert\nxth_te_sdata_incr\n$clw"
    append enter_cmd "event generate \$xth(te,sdata,[expr $xth(te,sdata,nent) - 1],nextvde) <<xthFocusTo>> -when tail"
    bind $xth(te,sdata,[expr $xth(te,sdata,nent) - 1],de) <Return> $enter_cmd
    bind $xth(te,sdata,[expr $xth(te,sdata,nent) - 1],de) <KP_Enter> $enter_cmd
  }  
}


$xth(ctrl,te,sdata).sfb configure -command {
  set dil [xth_te_sdata_scan]
  xth_te_sdata_buid [lindex $dil 1] [lindex $dil 0] 
}


$xth(ctrl,te,sdata).sfs configure -command xth_te_sdata_bind


proc xth_te_sdata_insert {data invd iidx} {

  global xth
  if {$xth(te,fcurr) < 0} {
    return
  }

  if {! [info exists xth(te,sdata,nent)]} {
    return
  } elseif {$xth(te,sdata,nent) < 1} {
    return
  }

  set w $xth(te,[lindex $xth(te,flist) $xth(te,fcurr)],frame).txt
  set xth(me,sdata,err_notenought) 0

  set err 0
#  if {$xth(gui,etabsize) > 0} {
#    set tabspc [format \x25$xth(gui,etabsize)s " "]
#  } else {
    set tabspc " "
#  }
  set sent 0
  set eent $xth(te,sdata,nent)
  switch $invd {
    1 {
      set eent $xth(te,sdata,invd,ent)
    }
    2 {
      set sent $xth(te,sdata,invd,ent)
    }
  }
  
  set txt ""
  set fst ""
  set iet $sent
  set tmp $data
  set ldata {}
  while {[string length $tmp] > 0} {
    if {[regexp {\S+} $tmp itm]} {
      lappend ldata $itm
    }
    regsub {\s*\S*\s*} $tmp {} tmp
  }
  if {([llength $ldata] < $eent) && (!$xth(te,sdata,invd))} {
    set xth(me,sdata,err_notenought) 1
  }
  foreach itm $ldata {
    set postwrt 0
    set tobreak 0
    if {$iet < $eent} {
      if {[lsearch -exact $xth(te,sdata,$iet,special) $itm] != -1} {
        set postwrt 1
      } else {
        set curfmt $xth(te,sdata,$iet,format)
        set extfmt 0
        if {[regsub {fx(\s*)$} $curfmt {f\1} curfmt]} {
          set extfmt 1
        }
#        puts "$itm -> $fst\x25$curfmt"
        if {[catch {append txt [format "$fst\x25$curfmt" $itm]}]} {
          set postwrt 1
#          puts "error"
          set err 1
        } elseif {$extfmt == 1} {
          if {[regexp {\.?0+\s*$} $txt txtextend]} {
            set teel [string length $txtextend]
            regsub {\.?0+\s*$} $txt [format \x25[expr $teel]s " "] txt
          }
        }
      }
    } else {
      # ak je dlhsie, uz neformatuj
#      puts $data
      set unfdata $data
      for {set ufi 0} {$ufi < $eent} {incr ufi} {
        regsub {^\s*\S+\s*} $unfdata "" unfdata
      }
      append txt $fst $unfdata
      # append txt [format $fst\x25$xth(datafmt,unknown,format) $itm]
      # set err 1
      set tobreak 1
    }
    
      
    if {$postwrt == 1} {
      if {[regexp {(\d+)\.?(\d*)} $xth(te,sdata,$iet,format) dum nfln nzadc]} {
        set nitm $itm
        if {[string length nzadc] > 0} {
          append nitm [format \x25[expr $nzadc + 1]s " "]
        }
        append txt [format $fst\x25[expr $nfln]s $nitm]
      } else {
        append txt [format $fst\x25$xth(datafmt,unknown,format) $itm]
      }
    }
    
    set fst $tabspc  
    incr iet
    if {$tobreak} {
      break
    }
  }
  
  set cind $xth(te,sdata,indc)
  if {($invd == 2) && (!$err)} {
    if {[regexp {\d+} $xth(te,sdata,0,format) plusindc]} {
      incr cind [expr $plusindc + 1]
    } else {
      incr cind [expr 2 * $xth(gui,etabsize)]
    }
  }
  
  if {($invd == 3) || $err} {
    set txt $data
    regsub {^\s+} $txt "" txt
    regsub {\s+$} $txt "" txt
  }
  
  if {$cind > 0} {
    set txt [format \x25[expr $cind + [string length $txt]]s $txt]  
  }
  
  if {[string compare $iidx insert] == 0} {
    xth_te_insert_text $w "\n$txt"
  } else {
    $w insert $iidx $txt
  }
  catch {
    $w edit separator
  }
  return $err
  
}


proc xth_te_sdata_auto_format {} {

  global xth
  if {$xth(te,fcurr) < 0} {
    return
  }

  if {! [info exists xth(te,sdata,nent)]} {
    return
  } elseif {$xth(te,sdata,nent) < 1} {
    return
  }
  
  set w $xth(te,[lindex $xth(te,flist) $xth(te,fcurr)],frame).txt
  set s [$w tag ranges sel]
  if {[llength $s] < 2} {
    return
  }
  
  set eline -1
  set sline 0
  regexp {(\d+)\.} [lindex $s 0] dum sline 
  regexp {(\d+)\.} [lindex $s 1] dum eline 
  # $w tag remove sel 1.0 end
  set ict 1
  for {set cline $sline} {$cline <= $eline} {incr cline} {
    set txt [$w get $cline.0 $cline.end]
    if {[regexp {\S+} $txt]} {
      set orig [$w get $cline.0 $cline.end]
      $w delete $cline.0 $cline.end
      if {$xth(te,sdata,invd)} {
        set formatres [xth_te_sdata_insert $txt $ict $cline.0]
        if {$formatres == 0} {
          if {$ict == 1} {
            set ict 2
          } else {
            set ict 1
          }
        } else {
          if {[regexp {^\s*break\s*$} $txt]} {
            set xth(me,sdata,err_notenought) 0
            set ict 1
          }
        }
      } else {
        set formatres [xth_te_sdata_insert $txt 0 $cline.0]
      }
      # an error occured
      if {$formatres || $xth(me,sdata,err_notenought)} {
#        puts "inserting >>$orig<<"
        $w delete $cline.0 $cline.end
        $w insert $cline.0 $orig
      }
    }
  }
  $w see insert
}


proc te_sr_reset {} {

  global xth
  if {$xth(te,fcurr) < 0} {
    return
  }
  set w $xth(te,[lindex $xth(te,flist) $xth(te,fcurr)],frame).txt

  set has_sel 0  
  if {$xth(ctrl,te,sr,selection_io)} {
    set seli [$w tag ranges sel]
    if {[llength $seli] > 0} {
      set xth(ctrl,te,sr,selection_start) [lindex $seli 0]
      set xth(ctrl,te,sr,selection_end) [lindex $seli 1]
      set xth(ctrl,te,sr,search_end) [lindex $seli 1]
      $w mark set insert [lindex $seli 0]
      set has_sel 1
    } else {
      set xth(ctrl,te,sr,selection_io) 0
      update idletasks
    }
  }
  
  if {!$has_sel} {
    set xth(ctrl,te,sr,selection_start) {}
    set xth(ctrl,te,sr,selection_end) {}
    set xth(ctrl,te,sr,search_end) end
    $w mark set insert 1.0
  }
  
}


proc te_sr_first {} {
  global xth
  if {$xth(te,fcurr) < 0} {
    return
  }
  if {[string length $xth(ctrl,te,sr,search)] == 0} {
    return
  }
  catch {
    $w edit separator
  }
  set w $xth(te,[lindex $xth(te,flist) $xth(te,fcurr)],frame).txt
  te_sr_clear  
  te_sr_reset
  if {![te_sr_next_next]} {
    bell
  }
  catch {
    $w edit separator
  }
  focus $w
}

proc te_sr_next_next {} {
  global xth
  if {$xth(te,fcurr) < 0} {
    return
  }
  if {[string length $xth(ctrl,te,sr,search)] == 0} {
    return
  }
  set w $xth(te,[lindex $xth(te,flist) $xth(te,fcurr)],frame).txt

  # prehlada text od pozicie kurzora po koniec (vyberu)
  # najde text - (zameni ho) - vyznaci ho a kurzor nastavi za neho
  
  set cnt 0
  set fndcmd "set fnd \[$w search -count cnt"
  if {!$xth(ctrl,te,sr,case_io)} {
    append fndcmd " -nocase"
  }
  if {$xth(ctrl,te,sr,regular_io)} {
    append fndcmd " -regexp"
  }
  append fndcmd { $xth(ctrl,te,sr,search) insert $xth(ctrl,te,sr,search_end)]}
  eval $fndcmd
  
  if {[string length $fnd] > 0} {
    $w mark set insert "$fnd + $cnt chars"
    $w mark set xthsrend "$fnd + $cnt chars"
    # do replace if necessary
    if {$xth(ctrl,te,sr,replace_io)} {
      set ostr [$w get $fnd xthsrend]
      $w delete $fnd xthsrend
      #puts "<<$ostr"
      set nstr $xth(ctrl,te,sr,replace)
      if {$xth(ctrl,te,sr,regular_io)} {
        set repcmd {regsub}
        if {!$xth(ctrl,te,sr,case_io)} {
          append repcmd " -nocase"
        }
        append repcmd { $xth(ctrl,te,sr,search) $ostr $xth(ctrl,te,sr,replace) nstr}
        eval $repcmd
      }
      #puts ">>$nstr"
      $w insert $fnd $nstr
    }
    $w tag add xthsr $fnd xthsrend
    $w tag configure xthsr -background $xth(gui,escolorbg) -foreground $xth(gui,escolorfg)
    $w see insert
    return 1
  } else {
    # uz sme nic nenasli
    return 0
  }  

}

proc te_sr_next {} {
  global xth
  if {$xth(te,fcurr) < 0} {
    return
  }
  if {[string length $xth(ctrl,te,sr,search)] == 0} {
    return
  }
  catch {
    $w edit separator
  }
  set w $xth(te,[lindex $xth(te,flist) $xth(te,fcurr)],frame).txt
  if {![te_sr_next_next]} {
    bell
  }
  catch {
    $w edit separator
  }
  focus $w
}

proc te_sr_all {} {
  global xth
  if {$xth(te,fcurr) < 0} {
    return
  }
  if {[string length $xth(ctrl,te,sr,search)] == 0} {
    return
  }
  catch {
    $w edit separator
  }
  set w $xth(te,[lindex $xth(te,flist) $xth(te,fcurr)],frame).txt
  te_sr_clear  
  te_sr_reset
  if {![te_sr_next_next]} {
    bell
  } else {
    while {[te_sr_next_next]} {}
  }
  catch {
    $w edit separator
  }
  focus $w
}

proc te_sr_clear {} {
  global xth
  if {$xth(te,fcurr) < 0} {
    return
  }
  set w $xth(te,[lindex $xth(te,flist) $xth(te,fcurr)],frame).txt
  $w tag remove xthsr 1.0 end
  focus $w
}







$xth(ctrl,te,sdata).taf configure -command xth_te_sdata_auto_format
xth_te_sdata_buid {from to tape compass clino} [expr 2 * $xth(gui,etabsize)] 
xth_te_sdata_disable ""






image create photo compile_img -data {
R0lGODlhEAASAPcAAFdVhrLM9LnT9Mfa+c7M+dXh+dXo+ePv+ero1urv+fH2
+QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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JBQAICr
AAaILCChYIAMHmJuEKkBQ1SCARbI1GBgo0QIGQkkgODTZEAAOw==
}








set xth(gui,openxp) 0
set xth(me,imgs,xviid) 0

proc xth_me_image_update_position {} {
  global xth 
  set iidx [lindex [$xth(ctrl,me,images).il.ilbox curselection] 0]
  set imgx [lindex $xth(me,imgs,xlist) $iidx]
  $xth(ctrl,me,images).ic.posln configure -text [format "%.0f:%.0f" \
    [lindex $xth(me,imgs,$imgx,position) 0] \
    [lindex $xth(me,imgs,$imgx,position) 1]]
  set xth(ctrl,me,images,posx) [format "%.0f" [lindex $xth(me,imgs,$imgx,position) 0]]
  set xth(ctrl,me,images,posy) [format "%.0f" [lindex $xth(me,imgs,$imgx,position) 1]]
  update idletasks
}

proc xth_me_image_update_list {} {
  global xth
  set xth(me,imgs,list) {}
  foreach imgx $xth(me,imgs,xlist) {
    if {$xth(me,imgs,$imgx,XVI)} {
      set imgsize "(XVI)"
    } elseif {[string length $xth(me,imgs,$imgx,image)] > 0} {
      set imgw [image width $xth(me,imgs,$imgx,image)]
      set imgh [image height $xth(me,imgs,$imgx,image)]
      set imgsize "($imgw x $imgh)"
    } else {
      set imgsize "(unknown)"
    }
    lappend xth(me,imgs,list) "$xth(me,imgs,$imgx,name) $imgsize"
  }
}


proc xth_me_image_move_to {} {
  global xth
  xth_me_cmds_update {}
  if {$xth(me,nimgs) < 1} {
    return;
  }
  set iidx [lindex [$xth(ctrl,me,images).il.ilbox curselection] 0]
  set imgx [lindex $xth(me,imgs,xlist) $iidx]
  xth_me_unredo_action [mc "moving image"] \
    "xth_me_image_move $imgx $xth(me,imgs,$imgx,position); xth_me_image_update_position" \
    "xth_me_image_move $imgx $xth(ctrl,me,images,posx) $xth(ctrl,me,images,posy); xth_me_image_update_position"
  xth_me_image_move $imgx $xth(ctrl,me,images,posx) $xth(ctrl,me,images,posy)
  xth_me_image_update_position
}



proc xth_me_image_move {imgx xx yy} {
  # zisti si aktualne suradnice
  global xth
  if {[catch {expr $xx}]} {
    set xx [lindex $xth(me,imgs,$imgx,position) 0]
  }
  if {[catch {expr $yy}]} {
    set yy [lindex $xth(me,imgs,$imgx,position) 1]
  }
  set xth(me,imgs,$imgx,position) [list $xx $yy]
  xth_me_image_redraw $imgx
}


proc xth_me_image_toggle_vsb {iidx} {
  global xth
  if {$xth(me,nimgs) < 1} {
    return
  }
  set isel [$xth(ctrl,me,images).il.ilbox curselection]
  if {[llength $isel] < 1} {
    return
  }
  if {[string length $iidx] < 1} {
    set iidx [lindex $isel 0]
  }
  set imgx [lindex $xth(me,imgs,xlist) $iidx]

  xth_me_unredo_action [mc "toggle image visibility"] \
    "xth_me_image_toggle_vsb $iidx" "xth_me_image_toggle_vsb $iidx"

  switch $xth(me,imgs,$imgx,vsb) {
    0 {
      set xth(me,imgs,$imgx,vsb) 1
      $xth(me,can) itemconfigure $xth(me,imgs,$imgx,image) -state normal
      xth_me_image_rescan $imgx
      xth_me_image_redraw $imgx
      set xth(ctrl,me,images,vis) 1
    }
    1 {
      set xth(me,imgs,$imgx,vsb) 0
      $xth(me,can) itemconfigure $xth(me,imgs,$imgx,image) -state hidden
      set xth(ctrl,me,images,vis) 0
    }
    default {
      set xth(ctrl,me,images,vis) 0
    }
  }
}


proc xth_me_image_set_gamma {imgx} {
  global xth
  if {$xth(me,imgs,$imgx,vsb) <= 0} {
    return
  }
  if {$xth(me,imgs,$imgx,XVI)} {
    return
  }
  set ng $xth(me,imgs,$imgx,gamma)
  xth_status_bar_push me
  set totalsi [llength $xth(me,imgs,$imgx,subimgs)]
  set csi 0
  xth_status_bar_status me [format "Correcting image gamma (%s) ..." $xth(me,imgs,$imgx,name)]
  xth_me_progbar_show $totalsi
  $xth(me,imgs,$imgx,image) configure -gamma $ng
  foreach imgl $xth(me,imgs,$imgx,subimgs) {
    set dsti [lindex $imgl 0]
    incr csi
    xth_me_progbar_prog $csi
    $dsti configure -gamma $ng
  }
  xth_me_progbar_hide
  xth_status_bar_pop me
}

if {$xth(gui,me,nozoom)} {

proc xth_me_images_rescandraw {} {
  global xth
  if {($xth(me,zoom) > 100) && $xth(gui,me,nozoom)} {
    foreach imgx $xth(me,imgs,xlist) {
      xth_me_image_redraw $imgx
    }
  }
}

proc xth_me_image_redraw {imgx} {
  global xth
  if {$xth(me,imgs,$imgx,vsb) <= 0} {
    return
  }
  if {$xth(me,imgs,$imgx,XVI)} {
    xth_me_imgs_xvi_redraw $imgx
    return
  }
  set totalsi [llength $xth(me,imgs,$imgx,subimgs)]
  set csi 0
  set x [lindex $xth(me,imgs,$imgx,position) 0]
  set y [lindex $xth(me,imgs,$imgx,position) 1]
  set w [image width $xth(me,imgs,$imgx,image)]
  set h [image height $xth(me,imgs,$imgx,image)]
  # ak je zoom 100 - nastavi image na source image
  # a kasle na ostatne
  if {$xth(me,zoom) <= 100} {
    foreach imgl $xth(me,imgs,$imgx,subimgs) {
      incr csi
      $xth(me,can) coords [lindex $imgl 1] \
        [xth_me_real2canx [expr $x + [lindex $imgl 2]]] \
        [xth_me_real2cany [expr $y - [lindex $imgl 3]]]
    }
  } else {
    # najde si suradnice z obrazka, ktore su viditelne
    set imgl [lindex $xth(me,imgs,$imgx,subimgs) 0]
    set cminx [winfo x $xth(me,can)]
    set cminy [winfo y $xth(me,can)]
    set cmaxx [expr $cminx + [winfo width $xth(me,can)]]
    set cmaxy [expr $cminy + [winfo height $xth(me,can)]]
    set sx [xth_me_can2realx [$xth(me,can) canvasx $cminx]]
    set sw [expr [xth_me_can2realx [$xth(me,can) canvasx $cmaxx]] - $sx]
    set sy [xth_me_can2realy [$xth(me,can) canvasy $cminy]]
    set sh [expr $sy - [xth_me_can2realy [$xth(me,can) canvasy $cmaxy]]]

    # ak je nieco viditelne - tak to zobrazi
    set vfx [expr round($sx - $x)]
    set vfy [expr round($y - $sy)] 
    set vtx [expr round($vfx + $sw)] 
    set vty [expr round($vfy + $sh)]
    if {$vfx < 0} {set vfx 0}
    if {$vfy < 0} {set vfy 0}
    if {$vtx > $w} {set vtx $w}
    if {$vty > $h} {set vty $h}
    
    #puts "$vfx $vfy $vtx $vty"
    if {($vtx <= 0) || ($vty <= 0) || 
        ($vfx >= $w) || ($vfy >= $h) ||
        ($vtx <= $vfx) || ($vty <= $vfy)} {
      # nezobrazime nic
      $xth(me,can) itemconfigure [lindex $imgl 1] -image {}
    } else {
      # zobrazime vyrez
      set dsti [lindex $imgl 0]
      $dsti copy $xth(me,imgs,$imgx,image) -zoom [expr $xth(me,zoom) / 100] -shrink \
        -from $vfx $vfy $vtx $vty
      $xth(me,can) itemconfigure [lindex $imgl 1] -image $dsti
      $xth(me,can) coords [lindex $imgl 1] \
        [xth_me_real2canx [expr $x + $vfx]] \
        [xth_me_real2cany [expr $y - $vfy]]
    }
  }
  update idletasks
}

proc xth_me_image_rescan {imgx} {
  global xth
  if {$xth(me,imgs,$imgx,vsb) <= 0} {
    return
  }
  if {$xth(me,imgs,$imgx,XVI)} {
    return
  }
  set srci $xth(me,imgs,$imgx,image)
  xth_status_bar_push me
  set origgamma [$srci cget -gamma]
  $srci configure -gamma 1.0
  set totalsi [llength $xth(me,imgs,$imgx,subimgs)]
  set csi 0
  xth_status_bar_status me [format "Zooming image %s ..." $xth(me,imgs,$imgx,name)]
  xth_me_progbar_show $totalsi
  foreach imgl $xth(me,imgs,$imgx,subimgs) {
    set dsti [lindex $imgl 0]
    incr csi
    xth_me_progbar_prog $csi
    switch $xth(me,zoom) {
      100 {
        $xth(me,can) itemconfigure [lindex $imgl 1] -image $srci
      }
      default {
        $xth(me,can) itemconfigure [lindex $imgl 1] -image $dsti
      }
    }
    switch $xth(me,zoom) {
      25 {$dsti copy $srci -subsample 4 -shrink}
      50 {$dsti copy $srci -subsample 2 -shrink}
      200 {}
      400 {}
      default {}
    }
  }
  xth_me_progbar_hide
  $srci configure -gamma $origgamma
  xth_status_bar_pop me
}

# NOZOOMING
} else {

proc xth_me_images_rescandraw {} {
}

proc xth_me_image_redraw {imgx} {
  global xth
  if {$xth(me,imgs,$imgx,vsb) <= 0} {
    return
  }
  if {$xth(me,imgs,$imgx,XVI)} {
    xth_me_imgs_xvi_redraw $imgx
    return
  }
  set totalsi [llength $xth(me,imgs,$imgx,subimgs)]
  set csi 0
  set x [lindex $xth(me,imgs,$imgx,position) 0]
  set y [lindex $xth(me,imgs,$imgx,position) 1]
  foreach imgl $xth(me,imgs,$imgx,subimgs) {
    incr csi
    $xth(me,can) coords [lindex $imgl 1] \
      [xth_me_real2canx [expr $x + [lindex $imgl 2]]] \
      [xth_me_real2cany [expr $y - [lindex $imgl 3]]]
  }
  update idletasks
}

proc xth_me_image_rescan {imgx} {
  global xth
  if {$xth(me,imgs,$imgx,vsb) <= 0} {
    return
  }
  if {$xth(me,imgs,$imgx,XVI)} {
    return
  }
  set srci $xth(me,imgs,$imgx,image)
  xth_status_bar_push me
  set totalsi [llength $xth(me,imgs,$imgx,subimgs)]
  set csi 0
  xth_status_bar_status me [format "Zooming image %s ..." $xth(me,imgs,$imgx,name)]
  xth_me_progbar_show $totalsi
  foreach imgl $xth(me,imgs,$imgx,subimgs) {
    set dsti [lindex $imgl 0]
    incr csi
    xth_me_progbar_prog $csi
    switch $xth(me,zoom) {
      25 {$dsti copy $srci -subsample 4 -shrink -from \
        [lindex $imgl 2] [lindex $imgl 3] [lindex $imgl 4] [lindex $imgl 5]}
      50 {$dsti copy $srci -subsample 2 -shrink -from \
        [lindex $imgl 2] [lindex $imgl 3] [lindex $imgl 4] [lindex $imgl 5]}
      200 {$dsti copy $srci -zoom 2 -shrink -from \
        [lindex $imgl 2] [lindex $imgl 3] [lindex $imgl 4] [lindex $imgl 5]}
      400 {$dsti copy $srci -zoom 4 -shrink -from \
        [lindex $imgl 2] [lindex $imgl 3] [lindex $imgl 4] [lindex $imgl 5]}
      default {$dsti copy $srci -shrink -from \
        [lindex $imgl 2] [lindex $imgl 3] [lindex $imgl 4] [lindex $imgl 5]}
    }
  }
  xth_me_progbar_hide
  xth_status_bar_pop me
}

}
# END NO NOZOOM

proc xth_me_imgs_xvi_redraw {imgx} {
  global xth
  set id $xth(me,imgs,$imgx,image)  
  
  # calculate all coordinates
  # grid
  set px [lindex $xth(me,imgs,$imgx,position) 0]
  set py [lindex $xth(me,imgs,$imgx,position) 1]
  set gx [lindex $xth(me,imgs,$imgx,XVIgrid) 0]
  set gy [lindex $xth(me,imgs,$imgx,XVIgrid) 1]
  set gxx [lindex $xth(me,imgs,$imgx,XVIgrid) 2]
  set gxy [lindex $xth(me,imgs,$imgx,XVIgrid) 3]
  set gyx [lindex $xth(me,imgs,$imgx,XVIgrid) 4]
  set gyy [lindex $xth(me,imgs,$imgx,XVIgrid) 5]
  set ngx [lindex $xth(me,imgs,$imgx,XVIgrid) 6]
  set ngy [lindex $xth(me,imgs,$imgx,XVIgrid) 7]
  
  set shx [expr double($px) - double($gx)]
  set shy [expr double($py) - double($gy)]
  
  set odd 0
  set crd {}
  for {set i 0} {$i <= $ngy} {incr i} {
    set lvx [xth_me_real2canx [expr $shx + $gx + $i * $gyx]]
    set lvy [xth_me_real2cany [expr $shy + $gy + $i * $gyy]]
    set rvx [xth_me_real2canx [expr $shx + $gx + $i * $gyx + $ngx * $gxx]]
    set rvy [xth_me_real2cany [expr $shy + $gy + $i * $gyy + $ngx * $gxy]]
    if {$odd} {
      lappend crd $lvx $lvy $rvx $rvy
      set odd 0
    } else {
      lappend crd $rvx $rvy $lvx $lvy
      set odd 1
    }
  }
  $xth(me,can) coords [format "%sGH" $id] $crd
  set crd {}
  for {set i 0} {$i <= $ngx} {incr i} {
    set lvx [xth_me_real2canx [expr $shx + $gx + $i * $gxx]]
    set lvy [xth_me_real2cany [expr $shy + $gy + $i * $gxy]]
    set rvx [xth_me_real2canx [expr $shx + $gx + $i * $gxx + $ngy * $gyx]]
    set rvy [xth_me_real2cany [expr $shy + $gy + $i * $gxy + $ngy * $gyy]]
    if {$odd} {
      lappend crd $lvx $lvy $rvx $rvy
      set odd 0
    } else {
      lappend crd $rvx $rvy $lvx $lvy
      set odd 1
    }
  }
  $xth(me,can) coords [format "%sGV" $id] $crd

  # walls
  set shts $xth(me,imgs,$imgx,XVIshots)
  for {set i 0} {$i < [llength $shts]} {incr i} {
    if {[llength [lindex $shts $i]] >= 12} {
      set x0 [xth_me_real2canx [expr $shx + [lindex [lindex $shts $i] 4]]]
      set y0 [xth_me_real2cany [expr $shy + [lindex [lindex $shts $i] 5]]]
      set x1 [xth_me_real2canx [expr $shx + [lindex [lindex $shts $i] 6]]]
      set y1 [xth_me_real2cany [expr $shy + [lindex [lindex $shts $i] 7]]]
      set x2 [xth_me_real2canx [expr $shx + [lindex [lindex $shts $i] 8]]]
      set y2 [xth_me_real2cany [expr $shy + [lindex [lindex $shts $i] 9]]]
      set x3 [xth_me_real2canx [expr $shx + [lindex [lindex $shts $i] 10]]]
      set y3 [xth_me_real2cany [expr $shy + [lindex [lindex $shts $i] 11]]]
      $xth(me,can) coords [format "%sWLF%d" $id $i] $x0 $y0 $x1 $y1 $x2 $y2 $x3 $y3
      $xth(me,can) coords [format "%sWLO%d" $id $i] $x0 $y0 $x1 $y1 $x2 $y2 $x3 $y3 $x0 $y0
    }
  }

  # shots
  for {set i 0} {$i < [llength $shts]} {incr i} {
    set fx [xth_me_real2canx [expr $shx + [lindex [lindex $shts $i] 0]]]
    set fy [xth_me_real2cany [expr $shy + [lindex [lindex $shts $i] 1]]]
    set tx [xth_me_real2canx [expr $shx + [lindex [lindex $shts $i] 2]]]
    set ty [xth_me_real2cany [expr $shy + [lindex [lindex $shts $i] 3]]]
    $xth(me,can) coords [format "%sSH%d" $id $i] $fx $fy $tx $ty
  }

  # stations
  set stns $xth(me,imgs,$imgx,XVIstations)
  set xth(me,imgs,$imgx,XVIstationsX) {}
  for {set i 0} {$i < [llength $stns]} {incr i} {
    set cx [expr $shx + [lindex [lindex $stns $i] 0]]
    set cy [expr $shy + [lindex [lindex $stns $i] 1]]
    lappend xth(me,imgs,$imgx,XVIstationsX) [list $cx $cy]
    set cx [xth_me_real2canx $cx]
    set cy [xth_me_real2cany $cy]
    $xth(me,can) coords [format "%sST%d" $id $i] [expr $cx - 3.0] [expr $cy - 3.0] [expr $cx + 3.0] [expr $cy + 3.0]
  }
  
  if {$xth(me,imgs,$imgx,vsb) == 1} {
    $xth(me,can) itemconfigure $xth(me,imgs,$imgx,image) -state normal
  }
}

proc xth_me_imgs_xvi_create {imgx} {
  global xth

  # firstly delete all imgx items
  foreach silist $xth(me,imgs,$imgx,subimgs) {
    $xth(me,can) delete [lindex $silist 1]
  }
  set xth(me,imgs,$imgx,subimgs) {}
  set id $xth(me,imgs,$imgx,image)
  set stpref [format "XVIstI%sS" $imgx] 
  # now create them

  # walls fill
  set shts $xth(me,imgs,$imgx,XVIshots)
  for {set i 0} {$i < [llength $shts]} {incr i} {
    if {[llength [lindex $shts $i]] >= 12} {
      set cid [$xth(me,can) create polygon 0 0 1 0 1 1 -stipple $xth(gui,xvi_walls_fptn) -fill $xth(gui,xvi_walls_fclr) -width 1 -state hidden -tags [list $id [format "%sWLF%d" $id $i]]]
      xth_me_bind_area_drag $cid $imgx
      xth_me_bind_image_drag $cid $imgx
      lappend xth(me,imgs,$imgx,subimgs) [list {} $cid]
    }
  }

  # grid
  set grid_info_str [format [mc "grid - spacing %s"] $xth(me,imgs,$imgx,XVIgrids)]
  set cid [$xth(me,can) create line 0 0 1 1 -fill $xth(gui,xvi_grid_clr) -width 1 -state hidden -tags [list $id [format "%sGH" $id]]]
  xth_me_bind_area_drag $cid $imgx
  xth_me_bind_image_drag $cid $imgx
  $xth(me,can) bind $cid <Enter> "xth_status_bar_push me; xth_status_bar_status me [list $grid_info_str]"
  $xth(me,can) bind $cid <Leave> "xth_status_bar_pop me"
  lappend xth(me,imgs,$imgx,subimgs) [list {} $cid]
  set cid [$xth(me,can) create line 0 0 1 1 -fill $xth(gui,xvi_grid_clr) -width 1 -state hidden -tags [list $id [format "%sGV" $id]]]
  xth_me_bind_area_drag $cid $imgx
  xth_me_bind_image_drag $cid $imgx
  $xth(me,can) bind $cid <Enter> "xth_status_bar_push me; xth_status_bar_status me [list $grid_info_str]"
  $xth(me,can) bind $cid <Leave> "xth_status_bar_pop me"
  lappend xth(me,imgs,$imgx,subimgs) [list {} $cid]

  # walls outline
  set shts $xth(me,imgs,$imgx,XVIshots)
  for {set i 0} {$i < [llength $shts]} {incr i} {
    if {[llength [lindex $shts $i]] >= 12} {
      set cid [$xth(me,can) create line 0 0 1 1 -fill $xth(gui,xvi_walls_oclr) -width 1 -state hidden -tags [list $id [format "%sWLO%d" $id $i]]]
      xth_me_bind_area_drag $cid $imgx
      xth_me_bind_image_drag $cid $imgx
      lappend xth(me,imgs,$imgx,subimgs) [list {} $cid]
    }
  }

  # shots
  for {set i 0} {$i < [llength $shts]} {incr i} {
    set cid [$xth(me,can) create line 0 0 1 1 -fill $xth(gui,xvi_shot_clr) -width 3 -state hidden -tags [list $id [format "%sSH%d" $id $i]]]
    xth_me_bind_area_drag $cid $imgx
    xth_me_bind_image_drag $cid $imgx
    lappend xth(me,imgs,$imgx,subimgs) [list {} $cid]
  }

  # stations
  set stns $xth(me,imgs,$imgx,XVIstations)
  for {set i 0} {$i < [llength $stns]} {incr i} {
    set cid [$xth(me,can) create oval 0 0 1 1 -fill $xth(gui,xvi_station_fclr) -outline $xth(gui,xvi_station_oclr) -width 1 -state hidden -tags [list $id [format "%sST%d" $id $i] "$stpref$i"]]
    xth_me_bind_area_drag $cid $imgx
    xth_me_bind_image_drag $cid $imgx
    set stinfo [format [mc "station - %s"] [lindex [lindex $stns $i] 2]]
    $xth(me,can) bind $cid <Enter> "xth_status_bar_push me; xth_status_bar_status me [list $stinfo]"
    $xth(me,can) bind $cid <Leave> "xth_status_bar_pop me"
    lappend xth(me,imgs,$imgx,subimgs) [list {} $cid]
  }

  # and change coordinates
  $xth(me,can) lower $xth(me,imgs,$imgx,image) command
  set iidx [lsearch -exact $xth(me,imgs,xlist) $imgx]
  if {$iidx > 0} {
    $xth(me,can) lower $xth(me,imgs,$imgx,image) $xth(me,imgs,[lindex $xth(me,imgs,xlist) [expr $iidx - 1]],image)
  }
  xth_me_imgs_xvi_redraw $imgx
}

proc xth_me_imgs_set_root {imgx} {
  global xth
  if {!$xth(me,imgs,$imgx,XVI)} {
    return
  }
  set rs $xth(me,imgs,$imgx,XVIroot)
  set xss $xth(me,imgs,$imgx,XVIstations)
  if {[string length $rs] < 1} {
    return
  }
  
  # prejde vsetky stations, a skusi najst tu s danym menom
  # ked ju najde, prerata position na grid origin a vynuluje
  for {set i 0} {$i < [llength $xss]} {incr i} {
    if {[string equal [lindex [lindex $xss $i] 2] $rs]} {
      set sx [lindex [lindex $xss $i] 0]
      set sy [lindex [lindex $xss $i] 1]
      set px [lindex $xth(me,imgs,$imgx,position) 0]
      set py [lindex $xth(me,imgs,$imgx,position) 1]
      set gx [lindex $xth(me,imgs,$imgx,XVIgrid) 0]
      set gy [lindex $xth(me,imgs,$imgx,XVIgrid) 1]
      set xth(me,imgs,$imgx,position) [list [expr double($gx) + double($px) - double($sx)] [expr double($gy) + double($py) - double($sy)]]
      set xth(me,imgs,$imgx,XVIroot) {}  
      break
    }
  }
}

proc xth_me_imgs_get_root {imgx} {
  global xth
  set xss $xth(me,imgs,$imgx,XVIstations)
  if {[llength $xss] > 0} {
    set i 0
    set sx [lindex [lindex $xss $i] 0]
    set sy [lindex [lindex $xss $i] 1]
    set px [lindex $xth(me,imgs,$imgx,position) 0]
    set py [lindex $xth(me,imgs,$imgx,position) 1]
    set gx [lindex $xth(me,imgs,$imgx,XVIgrid) 0]
    set gy [lindex $xth(me,imgs,$imgx,XVIgrid) 1]
    return [list [lindex $xss $i 2] [expr double($sx) + double($px) - double($gx)] [expr double($sy) + double($py) - double($gy)]]
  } else {
    return [list $xth(me,imgs,$imgx,XVIroot)]
  }
}


proc xth_me_image_insert {xx yy fname iidx imgx} {

  global xth
  
  if {! $xth(me,fopen)} {
    return
  }

  set vsb 1
  set igamma 1.0
  if {[llength $xx] > 1} {
    if {[llength $xx] > 2} {
       set igamma [lindex $xx 2]
    }
    set vsb [lindex $xx 1]
    set xx [lindex $xx 0]
  } 
  
  set XVIroot {}
  set isXVI 0
  if {[llength $yy] > 1} {
    set XVIroot [lindex $yy 1]
    set yy [lindex $yy 0]
  }

  if {[catch {expr $xx}]} {
    set xx $xth(me,area,xmin)
  }
  if {[catch {expr $yy}]} {
    if $isXVI {
      set yy $xth(me,area,ymax)
    } else {
      set yy $xth(me,area,ymin)
    }
  }
  
  set dial_id 0

  if {[string length $fname] < 1} {
  
    if {$xth(me,fnewf)} {
      set wtd [MessageDlg $xth(gui,message) -parent $xth(gui,main) \
        -icon question -type yesno \
        -message [mc "New *.th2 file needs to be saved before inserting background image. Save it now?"] \
        -font $xth(gui,lfont)]
      if {$wtd == 1} {
        return
      }
      xth_me_save_file 1
    }
    if {$xth(me,fnewf)} {
      return
    }
    
    set fname [tk_getOpenFile -parent $xth(gui,main) \
       -filetypes $xth(gui,imgfiletypes) \
       -initialdir $xth(me,fpath) -defaultextension ".gif"]  
    if {[string length $fname] < 1} {
      return
    } else {
      # overi ci cesta sedi
      if {![string equal -length [string length $xth(me,fpath)] \
        $xth(me,fpath) $fname]} {
        MessageDlg $xth(gui,message) -parent $xth(gui,main) \
          -icon error -type ok \
          -message "Picture $fname not in file path $xth(me,fpath)." \
          -font $xth(gui,lfont)
        return
      } else {
        set fname [string range $fname [expr [string length $xth(me,fpath)] + 1] end]
        set dial_id 1
      }
    }
  }

    
  xth_status_bar_push me
  xth_status_bar_status me "Loading image file $fname ..."
  set ffname [file join $xth(me,fpath) $fname]
  if {[string length $imgx] < 1} {
    set imgx $xth(me,imgln)
  }
  set imgid {}
  set XVIgrids {}
  set XVIgrid {}
  set XVIstations {}
  set XVIshots {}
	if {!$xth(gui,openxp)} {
    catch {
	      set imgid [image create photo -file $ffname]
	  } errorinf
    if {[string length $imgid] < 1} {
      catch {
        source $ffname
      } errorinf
      if {[string length $XVIgrids] > 0} {
        set isXVI 1
        set imgid "XVI$xth(me,imgs,xviid)"
        incr xth(me,imgs,xviid)
      }
    }
  } else {
		set errorinf "excluded picture"
	}
  
  if {[string length $imgid] < 1} {
    if {$xth(me,unredook)} {
      MessageDlg $xth(gui,message) -parent $xth(gui,main) \
        -icon error -type ok \
        -message "$errorinf" \
        -font $xth(gui,lfont)
    }
    xth_status_bar_pop me
    if {$dial_id} {
      return
    } else {
      set vsb [expr $vsb - 2]
    }
  }

  set undocmd "xth_me_image_remove %d"
  set redocmd "xth_me_image_insert {$xx $vsb} {$yy $XVIroot} [list $fname] %d $imgx"

  xth_me_unredo_action [mc "inserting image"] [format $undocmd $iidx] [format $redocmd $iidx]
     

  incr xth(me,nimgs)
  set xth(me,imgs,xlist) [linsert $xth(me,imgs,xlist) $iidx $imgx]
  set xth(me,imgs,$imgx,name) $fname
  set xth(me,imgs,$imgx,image) $imgid
  set xth(me,imgs,$imgx,position) [list $xx $yy]  
  set xth(me,imgs,$imgx,subimgs) {}
  set xth(me,imgs,$imgx,vsb) $vsb
  set xth(me,imgs,$imgx,gamma) $igamma
  set xth(me,imgs,$imgx,reload) [list $undocmd $redocmd]
  set xth(me,imgs,$imgx,ffname) $ffname
  set xth(me,imgs,$imgx,fmtime) 0
  catch {set xth(me,imgs,$imgx,fmtime) [file mtime $ffname]}
  set xth(me,imgs,$imgx,XVI) $isXVI
  set xth(me,imgs,$imgx,XVIroot) $XVIroot
  set xth(me,imgs,$imgx,XVIgrids) $XVIgrids
  set xth(me,imgs,$imgx,XVIgrid) $XVIgrid
  set xth(me,imgs,$imgx,XVIshots) $XVIshots
  set xth(me,imgs,$imgx,XVIstations) $XVIstations
  set xth(me,imgs,$imgx,XVIstationsX) {}
  
  xth_me_imgs_set_root $imgx
  
  
  # let's create image subimages
  if {($vsb >= 0) && (!$xth(me,imgs,$imgx,XVI))} {
    if {$xth(gui,me,nozoom)} {
      set subimg [image create photo]
      set subcimg [$xth(me,can) create image 0 0 -image $subimg -anchor nw \
        -tags "$imgid bgimg"]
      xth_me_bind_area_drag $subcimg $imgx
      xth_me_bind_image_drag $subcimg $imgx
      set iw [image width $imgid]
      set ih [image height $imgid]
      lappend xth(me,imgs,$imgx,subimgs) [list $subimg $subcimg 0 0 $iw $ih]
      $xth(me,can) lower $xth(me,imgs,$imgx,image) command
      if {$iidx > 0} {
        $xth(me,can) lower $xth(me,imgs,$imgx,image) $xth(me,imgs,[lindex $xth(me,imgs,xlist) [expr $iidx - 1]],image)
      }
    } else {
      set iw [image width $imgid]
      set ih [image height $imgid]
      set subisize 128
      for {set subx 0} {$subx < $iw} {incr subx $subisize} {
        for {set suby 0} {$suby < $ih} {incr suby $subisize} {
          set subxx [expr $subx + $subisize]
          set subyy [expr $suby + $subisize]
          if {$subxx > $iw} {
            set subxx $iw
          }
          if {$subyy > $ih} {
            set subyy $ih
          }
          set subimg [image create photo]
          set subcimg [$xth(me,can) create image 0 0 -image $subimg -anchor nw \
            -tags "$imgid bgimg"]
          xth_me_bind_area_drag $subcimg $imgx
          xth_me_bind_image_drag $subcimg $imgx
          lappend xth(me,imgs,$imgx,subimgs) [list $subimg $subcimg $subx $suby $subxx $subyy]
        }
      }
      $xth(me,can) lower $xth(me,imgs,$imgx,image) command
      set iidx [lsearch -exact $xth(me,imgs,xlist) $imgx]
      if {$iidx > 0} {
        $xth(me,can) lower $xth(me,imgs,$imgx,image) $xth(me,imgs,[lindex $xth(me,imgs,xlist) [expr $iidx - 1]],image)
      }
    }  
  }
  if {($vsb >= 0) && ($xth(me,imgs,$imgx,XVI))} {
    xth_me_imgs_xvi_create $imgx
  }
  xth_me_image_rescan $imgx
  xth_me_image_redraw $imgx
  xth_me_image_set_gamma $imgx
  xth_me_image_update_list
  xth_me_image_select 0
  incr xth(me,imgln)
  catch {$xth(me,can) raise cmd_ctrl bgimg}
  xth_status_bar_pop me
}


proc xth_me_image_destroy_all {} {
  global xth
  foreach imgx $xth(me,imgs,xlist) {
    unset xth(me,imgs,$imgx,name)
    unset xth(me,imgs,$imgx,position)
    if {[string length $xth(me,imgs,$imgx,image)] > 0} {
      catch {image delete $xth(me,imgs,$imgx,image)}
    }
    unset xth(me,imgs,$imgx,image)
    unset xth(me,imgs,$imgx,vsb)
    unset xth(me,imgs,$imgx,gamma)
    foreach silist $xth(me,imgs,$imgx,subimgs) {
      catch {image delete [lindex $silist 0]}
      $xth(me,can) delete [lindex $silist 1]
    }
    unset xth(me,imgs,$imgx,reload)
    unset xth(me,imgs,$imgx,ffname)
    unset xth(me,imgs,$imgx,fmtime)
    unset xth(me,imgs,$imgx,subimgs)
    unset xth(me,imgs,$imgx,XVI)
    unset xth(me,imgs,$imgx,XVIroot)
    unset xth(me,imgs,$imgx,XVIgrids)
    unset xth(me,imgs,$imgx,XVIgrid)
    unset xth(me,imgs,$imgx,XVIshots)
    unset xth(me,imgs,$imgx,XVIstations)
    unset xth(me,imgs,$imgx,XVIstationsX)
  }
  set xth(me,nimgs) 0
  set xth(me,imgln) 0
  set xth(me,imgs,list) {}
  set xth(me,imgs,xlist) {}
}

proc xth_me_image_remove {iidx} {
  global xth
  if {$xth(me,nimgs) < 1} {
    return
  }
  set isel [$xth(ctrl,me,images).il.ilbox curselection]
  if {[llength $isel] < 1} {
    return;
  }
  if {[string length $iidx] < 1} {
    set iidx [lindex $isel 0]
  }
  set imgx [lindex $xth(me,imgs,xlist) $iidx]
  xth_me_unredo_action [mc "removing image"] \
    "xth_me_image_insert {[lindex $xth(me,imgs,$imgx,position) 0] $xth(me,imgs,$imgx,vsb) $xth(me,imgs,$imgx,gamma)} [lindex $xth(me,imgs,$imgx,position) 1] [list $xth(me,imgs,$imgx,name)] $iidx $imgx" "xth_me_image_remove $iidx"
  unset xth(me,imgs,$imgx,name)
  unset xth(me,imgs,$imgx,position)
  if {[string length $xth(me,imgs,$imgx,image)] > 0} {
    catch {image delete $xth(me,imgs,$imgx,image)}
  }
  unset xth(me,imgs,$imgx,image)
  unset xth(me,imgs,$imgx,vsb)
  unset xth(me,imgs,$imgx,gamma)
  foreach silist $xth(me,imgs,$imgx,subimgs) {
    catch {image delete [lindex $silist 0]}
    $xth(me,can) delete [lindex $silist 1]
  }
  unset xth(me,imgs,$imgx,subimgs)
  unset xth(me,imgs,$imgx,reload)
  unset xth(me,imgs,$imgx,ffname)
  unset xth(me,imgs,$imgx,fmtime)
  unset xth(me,imgs,$imgx,XVI)
  unset xth(me,imgs,$imgx,XVIroot)
  unset xth(me,imgs,$imgx,XVIgrids)
  unset xth(me,imgs,$imgx,XVIgrid)
  unset xth(me,imgs,$imgx,XVIshots)
  unset xth(me,imgs,$imgx,XVIstations)
  unset xth(me,imgs,$imgx,XVIstationsX)
  set xth(me,nimgs) [expr $xth(me,nimgs) - 1]
  set xth(me,imgs,xlist) [lreplace $xth(me,imgs,xlist) $iidx $iidx]
  xth_me_image_update_list
  if {$iidx >= [llength $xth(me,imgs,xlist)]} {
    set iidx end
  }
  xth_me_image_select $iidx
}


proc xth_me_image_move_special {iidx newiidx} {

  global xth  

  if {$iidx == [expr $xth(me,nimgs) - 1]} {
    set iidx $xth(me,nimgs)
  }
  if {$iidx < $xth(me,nimgs)} {
    set iiidx $iidx
    set xiidx $iidx
  } else {
    set iiidx end
    set xiidx [expr $xth(me,nimgs) - 1]
  }
  set imgx [lindex $xth(me,imgs,xlist) $iiidx]

  if {$newiidx < $xth(me,nimgs)} {
    $xth(me,can) raise $xth(me,imgs,$imgx,image) $xth(me,imgs,[lindex $xth(me,imgs,xlist) $newiidx],image)
    set xth(me,imgs,xlist) [linsert [lreplace $xth(me,imgs,xlist) $iiidx $iiidx] $newiidx $imgx]
  } else {
    $xth(me,can) lower $xth(me,imgs,$imgx,image) $xth(me,imgs,[lindex $xth(me,imgs,xlist) end],image)
    set xth(me,imgs,xlist) [linsert [lreplace $xth(me,imgs,xlist) $iiidx $iiidx] end $imgx]
  }  

  xth_me_unredo_action [mc "moving image"] \
    "xth_me_image_move_special $newiidx $iidx" "xth_me_image_move_special $iidx $newiidx"
  xth_me_image_update_list
  xth_me_image_select $xiidx
  
}


proc xth_me_image_move_front {} {
  global xth
  xth_me_cmds_update {}
  if {$xth(me,nimgs) < 1} {
    return
  }
  set isel [$xth(ctrl,me,images).il.ilbox curselection]
  if {[llength $isel] < 1} {
    return;
  }
  set iidx [lindex $isel 0]
  if {$iidx == 0} {
    return
  }
  
  xth_me_image_move_special $iidx 0

}


proc xth_me_image_move_back {} {
  global xth
  xth_me_cmds_update {}
  if {$xth(me,nimgs) < 1} {
    return
  }
  set isel [$xth(ctrl,me,images).il.ilbox curselection]
  if {[llength $isel] < 1} {
    return;
  }
  set iidx [lindex $isel 0]
  if {$iidx == ($xth(me,nimgs) - 1)} {
    return
  }

  xth_me_image_move_special $iidx $xth(me,nimgs)
}


proc xth_me_image_select {iidx} {
  
  global xth

  if {!$xth(me,fopen)} {
    return
  }
  
  if {[string length $iidx] == 0} {
    set iidx 0
  }
  
  if {$xth(me,nimgs) > 0} {
    $xth(ctrl,me,images).ic.remp configure -state normal
    $xth(ctrl,me,images).ic.posl configure -state normal
    $xth(ctrl,me,images).ic.posln configure -state normal
    $xth(ctrl,me,images).ic.posch configure -state normal
    $xth(ctrl,me,images).ic.posx configure -state normal
    $xth(ctrl,me,images).ic.posy configure -state normal
    $xth(ctrl,me,images).ic.mvf configure -state normal
    $xth(ctrl,me,images).ic.mvb configure -state normal
#    $xth(ctrl,me,images).il.ilbox configure -state normal
    $xth(ctrl,me,images).il.ilbox selection clear 0 end
    $xth(ctrl,me,images).il.ilbox selection set $iidx
    set iidx [lindex [$xth(ctrl,me,images).il.ilbox curselection] 0]
    set imgx [lindex $xth(me,imgs,xlist) $iidx]
    if {$xth(me,imgs,$imgx,vsb) < 0} {
      $xth(ctrl,me,images).ic.viscb configure -state disabled
      $xth(ctrl,me,images).ic.gs configure -state disabled
      $xth(ctrl,me,images).ic.gr configure -state disabled
      $xth(ctrl,me,images).ic.gl configure -state disabled
      xth_me_image_update_gamma_scale
      set xth(ctrl,me,images,vis) 0
    } else {
      $xth(ctrl,me,images).ic.viscb configure -state normal
      $xth(ctrl,me,images).ic.gs configure -state normal
      $xth(ctrl,me,images).ic.gr configure -state normal
      $xth(ctrl,me,images).ic.gl configure -state normal
      xth_me_image_update_gamma_scale
      set xth(ctrl,me,images,vis) $xth(me,imgs,$imgx,vsb)
    }
    xth_me_image_update_position
    update idletasks
  } else {
    $xth(ctrl,me,images).ic.viscb configure -state disabled
    $xth(ctrl,me,images).ic.remp configure -state disabled
    $xth(ctrl,me,images).ic.posl configure -state disabled
    $xth(ctrl,me,images).ic.posln configure -state disabled -text ""
    set xth(ctrl,me,images,posx) ""
    set xth(ctrl,me,images,posy) ""
    $xth(ctrl,me,images).ic.posch configure -state disabled
    $xth(ctrl,me,images).ic.posx configure -state disabled
    $xth(ctrl,me,images).ic.posy configure -state disabled
    $xth(ctrl,me,images).ic.mvf configure -state disabled
    $xth(ctrl,me,images).ic.mvb configure -state disabled
    $xth(ctrl,me,images).ic.gs configure -state disabled
    $xth(ctrl,me,images).ic.gr configure -state disabled
    $xth(ctrl,me,images).ic.gl configure -state disabled -text "gamma 1.00"
#    $xth(ctrl,me,images).il.ilbox configure -state disabled
    focus $xth(gui,main)
    update idletasks
  }
  
}

proc xth_me_image_gamma {imgx gv} {
  global xth
  set og $xth(me,imgs,$imgx,gamma)
  set xth(me,imgs,$imgx,gamma) $gv
  xth_me_image_set_gamma $imgx
  xth_me_unredo_action [mc "gamma correction"] \
    "xth_me_image_gamma $imgx $og" \
    "xth_me_image_gamma $imgx $gv"
  xth_me_image_update_gamma_scale
}

proc xth_me_image_update_gamma {} {
  global xth
  catch { 
    set iidx [lindex [$xth(ctrl,me,images).il.ilbox curselection] 0]
    set imgx [lindex $xth(me,imgs,xlist) $iidx]
    if {[string length $imgx] > 0} {
      xth_me_image_gamma $imgx [expr pow(10.0,$xth(ctrl,me,images,gamma))]
    }
  }
}

proc xth_me_image_update_gamma_scale {} {
  global xth
  set iidx [lindex [$xth(ctrl,me,images).il.ilbox curselection] 0]
  set imgx [lindex $xth(me,imgs,xlist) $iidx]
  if {[string length $imgx] > 0} {
    set xth(ctrl,me,images,gamma) [expr log10($xth(me,imgs,$imgx,gamma))]
    $xth(ctrl,me,images).ic.gl configure -text [format "gamma %.2f" $xth(me,imgs,$imgx,gamma)]
  } else {
    $xth(ctrl,me,images).ic.gl configure -text "gamma 1.00"
    set xth(ctrl,me,images,gamma) 0
  }
}


proc xth_me_xvi_refresh {} {
  global xth
  if {[catch {
    set todolist $xth(me,imgs,xlist)
  }]} {
    return
  }
  foreach imgx $todolist {
    if $xth(me,imgs,$imgx,XVI) {
      set fmtime 0
      if {![catch {set fmtime [file mtime $xth(me,imgs,$imgx,ffname)]}]} {
        if {$fmtime > $xth(me,imgs,$imgx,fmtime)} {
          set cpos [lsearch -exact $xth(me,imgs,xlist) $imgx]
          if {$cpos > -1} {
            set undocmd [format [lindex $xth(me,imgs,$imgx,reload) 0] $cpos]
            set redocmd [format [lindex $xth(me,imgs,$imgx,reload) 1] $cpos]
            set xth(me,unredook) 0
            eval $undocmd
            eval $redocmd
            set xth(me,unredook) 1
          }
        }
      }
    }
  }
  xth_me_area_auto_adjust
}










proc xth_me_cmds_get_line_option {ln opt} {
  set rxl [list [list "\\s*\\-$opt\\s+\\\[(\[^\\\]\]*)\\\]" "\["]\
    [list "\\s*\\-$opt\\s+\\\"((\\\"\\\"|\[^\\\"])+)\\\"" "\""]\
    [list "\\s*\\-$opt\\s+(\\S+)" {}]]
  set rln $ln
  set val {}
  set sep {}
  set res 0
  foreach rx $rxl {
    if {[regexp [lindex $rx 0] $ln dump val]} {
      regsub [lindex $rx 0] $ln {} rln
      set sep [lindex $rx 1]
      set res 1
      break
    }
  }
  return [list $val $rln $res]
}


proc xth_me_cmds_set_action {act} {

  global xth
  
  set xth(me,cmds,action) $act
  switch $act {
    0 {
      $xth(ctrl,me,cmds).cc.go configure -text [mc "Insert line"]
    }
    1 {
      $xth(ctrl,me,cmds).cc.go configure -text [mc "Insert point"]
    }
    2 {
      $xth(ctrl,me,cmds).cc.go configure -text [mc "Insert scrap"]
    }
    3 {
      $xth(ctrl,me,cmds).cc.go configure -text [mc "Insert text"]
    }
    4 {
      $xth(ctrl,me,cmds).cc.go configure -text [mc "Delete"]
    }
    5 {
      $xth(ctrl,me,cmds).cc.go configure -text [mc "Insert area"]
    }
  }

  update idletasks

}


proc xth_me_cmds_update_buttons {} {

  global xth
  set ccbox $xth(ctrl,me,cmds).cc
  set clbox $xth(ctrl,me,cmds).cl
  set ncmd [expr [llength $xth(me,cmds,xlist)] - 1]
  if {$xth(me,fopen)} {
    $ccbox.cfg configure -state normal
    $clbox.l configure -takefocus 1
    $ccbox.go configure -state normal
    $xth(me,mbar) configure -state normal
    if {$ncmd > 0} {
      $ccbox.sel configure -state normal
      $xth(me,menu,edit) entryconfigure [mc "Select"] -state normal
      $xth(ctrl,me,prev).upd  configure -state normal

      $xth(ctrl,me,ss).xl configure -state normal
      $xth(ctrl,me,ss).xe configure -state normal
      $xth(ctrl,me,ss).cs configure -state normal
      $xth(ctrl,me,ss).rx configure -state normal
      $xth(ctrl,me,ss).sn configure -state normal
      $xth(ctrl,me,ss).sa configure -state normal
      $xth(ctrl,me,ss).sf configure -state normal
      $xth(ctrl,me,ss).ca configure -state normal
      
      if {$ncmd > 1} {
        $ccbox.mu configure -state normal
        $ccbox.md configure -state normal
        $ccbox.mt configure -state normal
        $ccbox.tt configure -state normal
     } else {
        $ccbox.mu configure -state disabled
        $ccbox.md configure -state disabled
        $ccbox.mt configure -state disabled
        $ccbox.tt configure -state disabled
      }
      $ccbox.cfg.m entryconfigure [mc "Delete"] -state normal
      $xth(me,menu,edit) entryconfigure [mc "Delete"] -state normal
    } else {
      $xth(ctrl,me,prev).upd  configure -state disabled
      $ccbox.sel configure -state disabled
      $xth(me,menu,edit) entryconfigure [mc "Select"] -state disabled
      $ccbox.cfg.m entryconfigure [mc "Delete"] -state disabled
      $xth(me,menu,edit) entryconfigure [mc "Delete"] -state disabled
      $ccbox.mu configure -state disabled
      $ccbox.md configure -state disabled
      $ccbox.mt configure -state disabled
      $ccbox.tt configure -state disabled
      if {$xth(me,cmds,action) == 4} {
        xth_me_cmds_set_action 3
      }

      $xth(ctrl,me,ss).xl configure -state disabled
      $xth(ctrl,me,ss).xe configure -state disabled
      $xth(ctrl,me,ss).cs configure -state disabled
      $xth(ctrl,me,ss).rx configure -state disabled
      $xth(ctrl,me,ss).sn configure -state disabled
      $xth(ctrl,me,ss).sa configure -state disabled
      $xth(ctrl,me,ss).sf configure -state disabled
      $xth(ctrl,me,ss).ca configure -state disabled

    }
  } else {
    xth_me_cmds_set_action 3
    $ccbox.go configure -state disabled
    $ccbox.cfg configure -state disabled
    $clbox.l configure -takefocus 0
    $xth(me,mbar) configure -text "" -state disabled -bg $xth(me,mbar,bg) -fg $xth(me,mbar,fg)
    $ccbox.sel configure -state disabled
    $ccbox.mu configure -state disabled
    $ccbox.md configure -state disabled
    $ccbox.mt configure -state disabled
    $ccbox.tt configure -state disabled

    $xth(ctrl,me,ss).xl configure -state disabled
    $xth(ctrl,me,ss).xe configure -state disabled
    $xth(ctrl,me,ss).cs configure -state disabled
    $xth(ctrl,me,ss).rx configure -state disabled
    $xth(ctrl,me,ss).sn configure -state disabled
    $xth(ctrl,me,ss).sa configure -state disabled
    $xth(ctrl,me,ss).sf configure -state disabled
    $xth(ctrl,me,ss).ca configure -state disabled

  }
  
  update idletasks
  
}


# typy prikazov
# 0 eof
# 1 text
# 2 point
# 3 line
# 4 scrap
# 5 endscrap
# 6 area

proc xth_me_cmds_create {typ id ix} {
  global xth
  if {[string length $id] < 1} {
    set id $xth(me,cmds,cmdln)
    incr xth(me,cmds,cmdln)
  }
  set xth(me,cmds,$id,listix) -1
  set xth(me,cmds,$id,ct) $typ
  set xth(me,cmds,$id,type) {}
  set xth(me,cmds,$id,name) {}
  set xth(me,cmds,$id,data) {}
  set xth(me,cmds,$id,sbar) {}
  set ix [lsearch $xth(me,cmds,xlist) $xth(me,cmds,selid)]

	# ak sme v normalnom mode a na scrape a chceme vlozit
	# point, line, area alebo scrap
  if {$xth(me,unredook)} {
		set ccmdid $xth(me,cmds,selid)
		if {($xth(me,cmds,$ccmdid,ct) == 4) && (($typ == 2) || ($typ == 3) || ($typ == 6))} {
		    incr ix;
		}
	}
	
  set xth(me,cmds,list) [linsert $xth(me,cmds,list) $ix {}]
  set xth(me,cmds,xlist) [linsert $xth(me,cmds,xlist) $ix $id]
  if {$ix != -1} {
    xth_me_cmds_update_list_ft $ix {}
  }
  xth_me_cmds_update_buttons
  return $id
  
}


proc xth_me_cmds_update_list_ft {f t} {
  global xth
  if {[string length $f] == 0} {
    set f 0
  }
  if {[string length $t] == 0} {
    set t [llength $xth(me,cmds,xlist)]
  }
  for {set ii $f} {$ii < $t} {incr ii} {
    xth_me_cmds_update_list [lindex $xth(me,cmds,xlist) $ii]
  }
}

proc xth_me_cmds_update_list {id} {
  global xth
  set ix [lsearch $xth(me,cmds,xlist) $id]
  switch $xth(me,cmds,$id,ct) {
    0 {
      set cstr "end of file"
    }
    1 {
      set cstr "$ix: text"
    }
    2 {
      set cstr "$ix: point"
    }
    3 {
      set cstr "$ix: line"
    }
    4 {
      set cstr "$ix: scrap"
    }
    5 {
      set cstr "$ix: endscrap"
    }
    6 {
      set cstr "$ix: area"
    }
  }
  if {[string length $xth(me,cmds,$id,type)] > 0} {
    set cstr "$cstr $xth(me,cmds,$id,type)"
  }
  if {[string length $xth(me,cmds,$id,name)] > 0} {
    set cstr "$cstr - $xth(me,cmds,$id,name)"
  }
  set xth(me,cmds,list) [lreplace $xth(me,cmds,list) $ix $ix $cstr]
  set xth(me,cmds,$id,listix) $ix
  update idletasks
}


proc xth_me_cmds_draw {id} {
  global xth
  switch $xth(me,cmds,$id,ct) {
    2 {
      xth_me_cmds_draw_point $id
    }
    3 {
      xth_me_cmds_draw_line $id
    }
  }
}


proc xth_me_cmds_erase {id} {
  global xth
  switch $xth(me,cmds,$id,ct) {
    2 {
      $xth(me,can) delete pt$id
    }
    3 {
      $xth(me,can) delete ln$id
    }
  }
}


proc xth_me_cmds_undelete {id pid ix} {
  global xth
  xth_me_cmds_select 0
  set xth(me,cmds,list) [linsert $xth(me,cmds,list) $ix {}]
  set xth(me,cmds,xlist) [linsert $xth(me,cmds,xlist) $ix $id]
  xth_me_cmds_update_list_ft $ix {}
  #xth_me_cmds_update_list $id
  xth_me_cmds_draw $id
  xth_me_cmds_select "$id $pid"
  xth_me_cmds_update_buttons
}

proc xth_me_cmds_delete {id} {
  global xth
  if {[string length $id] < 1} {
    set id $xth(me,cmds,selid)
  }
  if {$xth(me,cmds,$id,ct) > 0} {
    set oldselid $xth(me,cmds,selid)
    set oldselpid $xth(me,cmds,selpid)
    xth_me_cmds_select 0
    set ix [lsearch $xth(me,cmds,xlist) $id]
    set xth(me,cmds,list) [lreplace $xth(me,cmds,list) $ix $ix]
    set xth(me,cmds,xlist) [lreplace $xth(me,cmds,xlist) $ix $ix]
    xth_me_cmds_update_list_ft $ix {}
    xth_me_cmds_erase $id
    if {$oldselid == $id} {
      set nwid [lindex $xth(me,cmds,xlist) $ix]
    } else {
      set nwid $oldselid
    }
    xth_me_cmds_select $nwid
    xth_me_unredo_action [mc "deleting"] \
      "xth_me_cmds_undelete $id $oldselpid $ix" \
      "xth_me_cmds_delete $id"
    xth_me_cmds_update_buttons
  }
}


proc xth_me_cmds_update {id} {
  global xth

  if {[llength $id] < 1} {
    update idletasks
    set id $xth(me,cmds,selid)
    set pid $xth(me,cmds,selpid)
  } elseif {[llength $id] < 2} {
    set id [lindex $id 0]
    set pid $xth(me,cmds,selpid)
  } else {
    set id [lindex $id 0]
    set pid [lindex $id 1]
  }
  
  if {[string length $id] < 1} {
    set id $xth(me,cmds,selid)
  }
  switch $xth(me,cmds,$id,ct) {
    1 {
      xth_me_cmds_update_text $id [$xth(ctrl,me,text).txt get 1.0 end] \
        [$xth(ctrl,me,text).txt index insert]
    }
    2 {
      xth_me_cmds_update_point $id $xth(ctrl,me,point,x) \
        $xth(ctrl,me,point,y) $xth(ctrl,me,point,type) \
        $xth(ctrl,me,point,name) $xth(ctrl,me,point,opts) \
        $xth(ctrl,me,point,rot) $xth(ctrl,me,point,xs) \
        $xth(ctrl,me,point,ys)
      xth_me_cmds_update_point_vars $id
    }
    3 {
      xth_me_cmds_update_line $id $pid $xth(ctrl,me,line,type) \
        $xth(ctrl,me,line,name) $xth(ctrl,me,line,opts) \
        $xth(ctrl,me,line,reverse) $xth(ctrl,me,linept,x) \
        $xth(ctrl,me,linept,y) $xth(ctrl,me,linept,xp) \
        $xth(ctrl,me,linept,yp) $xth(ctrl,me,linept,xn) \
        $xth(ctrl,me,linept,yn) $xth(ctrl,me,linept,smooth) \
        $xth(ctrl,me,linept,rot) $xth(ctrl,me,linept,rs) \
        $xth(ctrl,me,linept,ls) \
        [$xth(ctrl,me,linept).oe.txt get 1.0 end] \
        [$xth(ctrl,me,linept).oe.txt index insert]
      xth_me_cmds_update_line_vars $id $pid
    }    
    4 {
      xth_me_cmds_update_scrap $id $xth(ctrl,me,scrap,name) \
        $xth(ctrl,me,scrap,projection) $xth(ctrl,me,scrap,options) \
         [list $xth(ctrl,me,scrap,px1) $xth(ctrl,me,scrap,py1) \
          $xth(ctrl,me,scrap,px2) $xth(ctrl,me,scrap,py2) \
          $xth(ctrl,me,scrap,rx1) $xth(ctrl,me,scrap,ry1) \
          $xth(ctrl,me,scrap,rx2) $xth(ctrl,me,scrap,ry2) \
          $xth(ctrl,me,scrap,units)]
      xth_me_cmds_update_scrap_vars $id
    }
    6 {
      xth_me_cmds_update_area $id $xth(ctrl,me,ac,type) \
        $xth(ctrl,me,ac,opts)
      xth_me_cmds_update_area_vars $id
    }
  }
  xth_me_cmds_update_list $id
  xth_me_prev_cmd $xth(me,cmds,$id,data)
  update idletasks
}

proc xth_me_cmds_update_text_ctrl {id} {

  global xth
  if {[string length $id] > 0} {
    $xth(ctrl,me,text).txt configure -state normal
    $xth(ctrl,me,text).txt delete 1.0 end
    $xth(ctrl,me,text).txt insert 1.0 $xth(me,cmds,$id,data)
    $xth(ctrl,me,text).txt mark set insert $xth(me,cmds,$id,cpos)
    $xth(ctrl,me,text).txt see $xth(me,cmds,$id,cpos)
    $xth(ctrl,me,text).upd configure -state normal
    xth_me_prev_cmd $xth(me,cmds,$id,data)
  } else {
    $xth(ctrl,me,text).txt configure -state normal
    $xth(ctrl,me,text).txt delete 1.0 end
    $xth(ctrl,me,text).txt see 1.0
    $xth(ctrl,me,text).txt configure -state disabled
    $xth(ctrl,me,text).upd configure -state disabled
  }
  
}



proc xth_me_cmds_unselect {id} {
  
  global xth
  if {[string length $id] < 1} {
    set id $xth(me,cmds,selid)
  }
  if {$xth(me,unredook)} {
    xth_me_cmds_update $id
  }
  switch $xth(me,cmds,$id,ct) {
    1 {xth_me_cmds_update_text_ctrl {}}
    2 {xth_me_cmds_update_point_ctrl {}}
    3 {
      xth_me_cmds_update_line_ctrl {}
      xth_me_cmds_update_linept_ctrl {} 0
      set xth(me,cmds,selpid) 0
      if {$xth(me,cmds,mode) == 2} {
        xth_me_cmds_set_mode 0
      }
    }
    4 {xth_me_cmds_update_scrap_ctrl {}}
    6 {
      xth_me_cmds_update_area_ctrl {}
      if {$xth(me,cmds,mode) == 3} {
        xth_me_cmds_set_mode 0
      }
    }
  }
  update idletasks
  
}


proc xth_me_cmds_select {id} {

  global xth
  
  if {!$xth(me,fopen)} {
    return
  }
  set center_to 0
  update idletasks
  if {[llength $id] < 1} {
    set id [lindex $xth(me,cmds,xlist) [lindex [$xth(ctrl,me,cmds).cl.l curselection] 0]]
    if {$xth(me,cmds,$id,ct) == 2} {
      set center_to 1
    }
    set pid -1
  } elseif {[llength $id] < 2} {
    set id [lindex $id 0]
    set pid -1
  } else {
    set pid [lindex $id 1]
    set id [lindex $id 0]
  }  

  if {$pid == -1} {
    set pid 0
    if {($xth(me,cmds,$id,ct) == 3) && ([llength $xth(me,cmds,$id,xplist)] > 1)} {
      set center_to [lindex $xth(me,cmds,$id,xplist) [expr [llength $xth(me,cmds,$id,xplist)] - 2]]
    }
  }
  
  set newx [lsearch $xth(me,cmds,xlist) $id]
  if {$xth(me,cmds,selid) == $id} {
    $xth(ctrl,me,cmds).cl.l selection clear 0 end  
    $xth(ctrl,me,cmds).cl.l selection set $newx $newx
    $xth(ctrl,me,cmds).cl.l see $newx
    if {($xth(me,cmds,$id,ct) == 3) && ($pid != $xth(me,cmds,selpid))} {
      xth_me_cmds_select_linept $id $pid
    }
    if {$xth(me,unredook)} {
      return
    }
  }
  if {$xth(me,cmds,$xth(me,cmds,selid),ct) != $xth(me,cmds,$id,ct)} {
    if {![string equal $xth(ctrl,me,cmds).cl.l [focus -lastfor $xth(gui,main)]]} {
      focus $xth(gui,main)
    }
  }
  
  if {$xth(me,cmds,selid) != $id} {
    xth_me_cmds_unselect $xth(me,cmds,selid)
  }

  set xth(me,cmds,selid) $id
  $xth(ctrl,me,cmds).cl.l selection clear 0 end  
  $xth(ctrl,me,cmds).cl.l selection set $newx $newx  
  $xth(ctrl,me,cmds).cl.l see $newx
  xth_me_cmds_set_colors  
  switch $xth(me,cmds,$id,ct) {
    1 {xth_me_cmds_update_text_ctrl $id}
    2 {xth_me_cmds_update_point_ctrl $id}
    3 {
      xth_me_cmds_update_line_ctrl $id
      xth_me_cmds_select_linept $id $pid
      $xth(me,can) itemconfigure lnln$id -fill $xth(gui,me,activefill)
      $xth(me,can) itemconfigure lnpt$id -fill $xth(gui,me,activefill)
    }
    4 {xth_me_cmds_update_scrap_ctrl $id}
    6 {
      xth_me_cmds_update_area_ctrl $id
      xth_me_cmds_show_current_area
    }
    default {xth_me_prev_cmd $xth(me,cmds,$id,data)}
  }
  
  if {$center_to > 0} {
    switch $xth(me,cmds,$id,ct) {
      2 { xth_me_center_to [list $xth(me,cmds,$id,x) $xth(me,cmds,$id,y)]
        }
      3 { xth_me_center_to [list \
          $xth(me,cmds,$xth(me,cmds,selid),$center_to,x) \
          $xth(me,cmds,$xth(me,cmds,selid),$center_to,y)]
        }
    }
  }
  update idletasks
}

proc xth_me_cmds_set_move_to_list {} {
  global xth
  # prejde vsetky prikazy a najde scrapy a endscrapy
  set xl [llength $xth(me,cmds,xlist)]
  set vls {}
  set lscrap {}
  for {set ii 0} {$ii < $xl} {incr ii} {
    set id [lindex $xth(me,cmds,xlist) $ii]
    switch $xth(me,cmds,$id,ct) {
      4 {
        set lscrap $xth(me,cmds,$id,name)
        lappend vls "$lscrap begin \[[expr $ii + 1]\]"
      }
      5 {
        lappend vls "$lscrap end \[$ii\]"
      }
    }
  }
  $xth(ctrl,me,cmds).cc.tt configure -values $vls
  update idletasks
}

proc xth_me_cmds_set_move_to {} {
  global xth
  set lnum {}
  regexp {\[(\d+)\]} $xth(ctrl,me,cmds,moveto) dum lnum
  set xth(ctrl,me,cmds,moveto) $lnum
  update idletasks
}


proc xth_me_cmds_move_to {id dx} {
  global xth
  xth_me_cmds_update {}
  if {[string length $dx] < 1} {
    set dx $xth(ctrl,me,cmds,moveto)
  }
  set dx [regexp -inline {\d*} $dx]
  if {[string length $dx] < 1} {
    return
  }
  if {[string length $id] < 1} {
    set id $xth(me,cmds,selid)
  }
  set sx [lsearch $xth(me,cmds,xlist) $id]
  set maxsdx [expr [llength $xth(me,cmds,xlist)] - 2]
  if {($dx == $sx) || ($sx > $maxsdx) || ($dx > $maxsdx)} {
    return;
  }

  # prehodi  
  set xth(me,cmds,list) [linsert $xth(me,cmds,list) $dx [lindex $xth(me,cmds,list) $sx]]
  set xth(me,cmds,xlist) [linsert $xth(me,cmds,xlist) $dx [lindex $xth(me,cmds,xlist) $sx]]
  if {$dx < $sx} {
    set xth(me,cmds,list) [lreplace $xth(me,cmds,list) [expr $sx + 1] [expr $sx + 1]]
    set xth(me,cmds,xlist) [lreplace $xth(me,cmds,xlist) [expr $sx + 1] [expr $sx + 1]]
  } else {
    set xth(me,cmds,list) [lreplace $xth(me,cmds,list) $sx $sx]
    set xth(me,cmds,xlist) [lreplace $xth(me,cmds,xlist) $sx $sx]
  }    

  if {$dx < $sx} {
    xth_me_cmds_update_list_ft $dx [expr $sx + 1]
  } else {
    xth_me_cmds_update_list_ft $sx [expr $dx + 1]
  }

  set nid [lindex $xth(me,cmds,xlist) $sx]
  if {$xth(me,unredook)} {
    xth_me_cmds_select $nid
  }
  

  # unredo
  xth_me_unredo_action [mc "moving command"] \
    "xth_me_cmds_move_to $id $sx\nxth_me_cmds_select $id" \
    "xth_me_cmds_move_to $id $dx\nxth_me_cmds_select $nid"
  update idletasks
  
}

proc xth_me_cmds_move_up {id} {
  global xth
  xth_me_cmds_update {}
  if {[string length $id] < 1} {
    set id $xth(me,cmds,selid)
  }
  if {$id < 1} {
    return
  }
  set ix [lsearch $xth(me,cmds,xlist) $id]
  if {$ix < 1} {
    return
  }
  set dix [expr $ix - 1]
  # vymenime v liste
  set xth(me,cmds,list) [lreplace $xth(me,cmds,list) $dix $ix \
    [lindex $xth(me,cmds,list) $ix] [lindex $xth(me,cmds,list) $dix]]
  # vymenime v xliste
  set xth(me,cmds,xlist) [lreplace $xth(me,cmds,xlist) $dix $ix \
    [lindex $xth(me,cmds,xlist) $ix] [lindex $xth(me,cmds,xlist) $dix]]
  # selection
  if {$id == $xth(me,cmds,selid)} {
    $xth(ctrl,me,cmds).cl.l selection clear 0 end  
    $xth(ctrl,me,cmds).cl.l selection set $dix $dix
    $xth(ctrl,me,cmds).cl.l see $dix
    set selcmd "\nxth_me_cmds_select $id"
  } else {
    set selcmd {}
  }
  xth_me_cmds_update_list [lindex $xth(me,cmds,xlist) $ix]
  xth_me_cmds_update_list [lindex $xth(me,cmds,xlist) $dix]
  # unredo
  xth_me_unredo_action [mc "moving command"] \
    "xth_me_cmds_move_down $id$selcmd" \
    "xth_me_cmds_move_up $id$selcmd"
  update idletasks
}


proc xth_me_cmds_move_down {id} {
  global xth
  xth_me_cmds_update {}
  if {[string length $id] < 1} {
    set id $xth(me,cmds,selid)
  }
  if {$id < 1} {
    return
  }
  set ix [lsearch $xth(me,cmds,xlist) $id]
  if {$ix > [expr [llength $xth(me,cmds,xlist)] - 3]} {
    return
  }
  set iix [expr $ix + 1]
  # vymenime v liste
  set xth(me,cmds,list) [lreplace $xth(me,cmds,list) $ix $iix \
    [lindex $xth(me,cmds,list) $iix] [lindex $xth(me,cmds,list) $ix]]
  # vymenime v xliste
  set xth(me,cmds,xlist) [lreplace $xth(me,cmds,xlist) $ix $iix \
    [lindex $xth(me,cmds,xlist) $iix] [lindex $xth(me,cmds,xlist) $ix]]
  # selection
  if {$id == $xth(me,cmds,selid)} {
    $xth(ctrl,me,cmds).cl.l selection clear 0 end  
    $xth(ctrl,me,cmds).cl.l selection set $iix $iix
    $xth(ctrl,me,cmds).cl.l see $iix
    set selcmd "\nxth_me_cmds_select $id"
  } else {
    set selcmd {}
  }
  # unredo
  xth_me_cmds_update_list [lindex $xth(me,cmds,xlist) $ix]
  xth_me_cmds_update_list [lindex $xth(me,cmds,xlist) $iix]
  xth_me_unredo_action [mc "moving command"] \
   "xth_me_cmds_move_up $id$selcmd" "xth_me_cmds_move_down $id$selcmd"
  update idletasks
}


proc xth_me_cmds_create_endscrap {ix mode name} {
  global xth
  xth_me_cmds_update {}
  set id [xth_me_cmds_create 5 {} $ix]
  set xth(me,cmds,$id,name) {}
  set xth(me,cmds,$id,data) "endscrap"
  if {[string length $name] > 0} {
    set xth(me,cmds,$id,data) "$xth(me,cmds,$id,data)\n# $name"
  }
  xth_me_cmds_update_list $id
  if {$mode} {
    xth_me_cmds_select $id
    xth_me_cmds_select [expr $id - 1]
    xth_me_unredo_action [mc "creating endscrap"] \
     "xth_me_cmds_delete $id" \
     "xth_me_cmds_undelete $id 0 [lsearch $xth(me,cmds,xlist) $id]"  
  }
}


proc xth_me_cmds_hide_scrap_xctrl {} {

  global xth

  $xth(me,can) itemconfigure $xth(me,canid,scrap,scp1) -state hidden
  $xth(me,can) bind $xth(me,canid,scrap,scp1) <Enter> ""
  $xth(me,can) bind $xth(me,canid,scrap,scp1) <Leave> ""

  $xth(me,can) itemconfigure $xth(me,canid,scrap,scp2) -state hidden
  $xth(me,can) bind $xth(me,canid,scrap,scp2) <Enter> ""
  $xth(me,can) bind $xth(me,canid,scrap,scp2) <Leave> ""
  
}


proc xth_me_cmds_move_scrap_xctrl {id x y} {
  global xth
  set x [xth_me_real2canx $x]
  set y [xth_me_real2cany $y]
  $xth(me,can) coords $xth(me,canid,scrap,scp$id) \
    [expr $x - $xth(gui,me,scrap,psize)] [expr $y - $xth(gui,me,scrap,psize)] \
    [expr $x + $xth(gui,me,scrap,psize)] [expr $y + $xth(gui,me,scrap,psize)]
}


proc xth_me_cmds_start_scrap_xctrl_drag {pid x y} {
  global xth
  xth_me_cmds_update {}
  set xth(me,scrap,xdrag_mx) $x
  set xth(me,scrap,xdrag_my) $y
  set xth(me,scrap,xdrag_px) $xth(ctrl,me,scrap,px$pid)
  set xth(me,scrap,xdrag_py) $xth(ctrl,me,scrap,py$pid)
  set xth(me,scrap,xdrag_benter) [$xth(me,can) bind $xth(me,canid,scrap,scp$pid) <Enter>]
  $xth(me,can) bind $xth(me,canid,scrap,scp$pid) <Enter> {}
  set xth(me,scrap,xdrag_bleave) [$xth(me,can) bind $xth(me,canid,scrap,scp$pid) <Leave>]
  $xth(me,can) bind $xth(me,canid,scrap,scp$pid) <Leave> {}
  $xth(me,can) itemconfigure $xth(me,canid,scrap,scp$pid) -fill {}
  $xth(me,can) bind $xth(me,canid,scrap,scp$pid) <B1-Motion> "xth_me_cmds_scrap_xctrl_drag $pid %x %y"
  $xth(me,can) bind $xth(me,canid,scrap,scp$pid) <B1-ButtonRelease> "xth_me_cmds_end_scrap_xctrl_drag $pid %x %y"
  $xth(me,can) configure -cursor {}
}


proc xth_me_cmds_scrap_xctrl_drag {pid x y} {
  global xth
  set nx [expr $xth(me,scrap,xdrag_px) - [expr double($xth(me,scrap,xdrag_mx) - $x) * 100.0 / $xth(me,zoom)]]
  set ny [expr $xth(me,scrap,xdrag_py) + [expr double($xth(me,scrap,xdrag_my) - $y) * 100.0 / $xth(me,zoom)]]
  xth_me_cmds_move_scrap_xctrl $pid $nx $ny
  set xth(ctrl,me,scrap,px$pid) $nx
  set xth(ctrl,me,scrap,py$pid) $ny
  update idletasks
}


proc xth_me_cmds_end_scrap_xctrl_drag {pid x y} {
  global xth
  xth_me_cmds_scrap_xctrl_drag $pid $x $y
  $xth(me,can) bind $xth(me,canid,scrap,scp$pid) <B1-Motion> ""
  $xth(me,can) bind $xth(me,canid,scrap,scp$pid) <B1-ButtonRelease> ""
  $xth(me,can) bind $xth(me,canid,scrap,scp$pid) <Enter> $xth(me,scrap,xdrag_benter)
  $xth(me,can) bind $xth(me,canid,scrap,scp$pid) <Leave> $xth(me,scrap,xdrag_bleave)
  $xth(me,can) itemconfigure $xth(me,canid,scrap,scp$pid) -fill yellow
  $xth(me,can) configure -cursor crosshair
  xth_me_cmds_update {}
}


proc xth_me_cmds_show_scrap_xctrl {x1 y1 x2 y2} {

  global xth
  
  xth_me_cmds_move_scrap_xctrl 1 $x1 $y1
  $xth(me,can) itemconfigure $xth(me,canid,scrap,scp1) -state normal
  $xth(me,can) raise $xth(me,canid,scrap,scp1)
  $xth(me,can) bind $xth(me,canid,scrap,scp1) <Enter> "xth_status_bar_push me; xth_status_bar_status me \"Scrap picture scale point 1.\"; $xth(me,can) itemconfigure $xth(me,canid,scrap,scp1) -fill yellow"
  $xth(me,can) bind $xth(me,canid,scrap,scp1) <Leave> "xth_status_bar_pop me; $xth(me,can) itemconfigure $xth(me,canid,scrap,scp1) -fill red"
  $xth(me,can) bind $xth(me,canid,scrap,scp1) <1> "xth_me_cmds_start_scrap_xctrl_drag 1 %x %y"

  xth_me_cmds_move_scrap_xctrl 2 $x2 $y2
  $xth(me,can) itemconfigure $xth(me,canid,scrap,scp2) -state normal
  $xth(me,can) raise $xth(me,canid,scrap,scp2)
  $xth(me,can) bind $xth(me,canid,scrap,scp2) <Enter> "xth_status_bar_push me; xth_status_bar_status me \"Scrap picture scale point 2.\"; $xth(me,can) itemconfigure $xth(me,canid,scrap,scp2) -fill yellow"
  $xth(me,can) bind $xth(me,canid,scrap,scp2) <Leave> "xth_status_bar_pop me; $xth(me,can) itemconfigure $xth(me,canid,scrap,scp2) -fill red"
  $xth(me,can) bind $xth(me,canid,scrap,scp2) <1> "xth_me_cmds_start_scrap_xctrl_drag 2 %x %y"
  
}


proc xth_me_cmds_update_scrap_ctrl {id} {
  global xth
  if {[string length $id] > 0} {
    $xth(ctrl,me,scrap).namel configure -state normal
    $xth(ctrl,me,scrap).name configure -state normal
    $xth(ctrl,me,scrap).projl configure -state normal
    $xth(ctrl,me,scrap).proj configure -state normal
    $xth(ctrl,me,scrap).optl configure -state normal
    $xth(ctrl,me,scrap).opt configure -state normal
    $xth(ctrl,me,scrap).scl configure -state normal
    $xth(ctrl,me,scrap).scpb configure -state normal
    $xth(ctrl,me,scrap).scpp configure -state normal
    $xth(ctrl,me,scrap).scrp configure -state normal
    $xth(ctrl,me,scrap).scx1p configure -state normal
    $xth(ctrl,me,scrap).scy1p configure -state normal
    $xth(ctrl,me,scrap).scx2p configure -state normal
    $xth(ctrl,me,scrap).scy2p configure -state normal
    $xth(ctrl,me,scrap).scx1r configure -state normal
    $xth(ctrl,me,scrap).scy1r configure -state normal
    $xth(ctrl,me,scrap).scx2r configure -state normal
    $xth(ctrl,me,scrap).scy2r configure -state normal
    $xth(ctrl,me,scrap).scu configure -state normal
    $xth(ctrl,me,scrap).scul configure -state normal
    set xth(ctrl,me,scrap,name) $xth(me,cmds,$id,name)
    set xth(ctrl,me,scrap,projection) $xth(me,cmds,$id,projection)
    set xth(ctrl,me,scrap,options) $xth(me,cmds,$id,options)
    set xth(ctrl,me,scrap,px1) [lindex $xth(me,cmds,$id,scale) 0]
    set xth(ctrl,me,scrap,py1) [lindex $xth(me,cmds,$id,scale) 1]
    set xth(ctrl,me,scrap,px2) [lindex $xth(me,cmds,$id,scale) 2]
    set xth(ctrl,me,scrap,py2) [lindex $xth(me,cmds,$id,scale) 3]
    set xth(ctrl,me,scrap,rx1) [lindex $xth(me,cmds,$id,scale) 4]
    set xth(ctrl,me,scrap,ry1) [lindex $xth(me,cmds,$id,scale) 5]
    set xth(ctrl,me,scrap,rx2) [lindex $xth(me,cmds,$id,scale) 6]
    set xth(ctrl,me,scrap,ry2) [lindex $xth(me,cmds,$id,scale) 7]
    set xth(ctrl,me,scrap,units) [lindex $xth(me,cmds,$id,scale) 8]
    xth_me_cmds_show_scrap_xctrl [lindex $xth(me,cmds,$id,scale) 0] \
      [lindex $xth(me,cmds,$id,scale) 1] [lindex $xth(me,cmds,$id,scale) 2] \
      [lindex $xth(me,cmds,$id,scale) 3]
    xth_me_prev_cmd $xth(me,cmds,$id,data)
  } else {
    set xth(ctrl,me,scrap,name) ""
    set xth(ctrl,me,scrap,projection) $xth(me,dflt,scrap,projection)
    set xth(ctrl,me,scrap,options) $xth(me,dflt,scrap,options)
    set xth(ctrl,me,scrap,px1) [lindex $xth(me,dflt,scrap,scale) 0]
    set xth(ctrl,me,scrap,py1) [lindex $xth(me,dflt,scrap,scale) 1]
    set xth(ctrl,me,scrap,px2) [lindex $xth(me,dflt,scrap,scale) 2]
    set xth(ctrl,me,scrap,py2) [lindex $xth(me,dflt,scrap,scale) 3]
    set xth(ctrl,me,scrap,rx1) [lindex $xth(me,dflt,scrap,scale) 4]
    set xth(ctrl,me,scrap,ry1) [lindex $xth(me,dflt,scrap,scale) 5]
    set xth(ctrl,me,scrap,rx2) [lindex $xth(me,dflt,scrap,scale) 6]
    set xth(ctrl,me,scrap,ry2) [lindex $xth(me,dflt,scrap,scale) 7]
    set xth(ctrl,me,scrap,units) [lindex $xth(me,dflt,scrap,scale) 8]
    $xth(ctrl,me,scrap).namel configure -state disabled
    $xth(ctrl,me,scrap).name configure -state disabled
    $xth(ctrl,me,scrap).projl configure -state disabled
    $xth(ctrl,me,scrap).proj configure -state disabled
    $xth(ctrl,me,scrap).optl configure -state disabled
    $xth(ctrl,me,scrap).opt configure -state disabled
    $xth(ctrl,me,scrap).scl configure -state disabled
    $xth(ctrl,me,scrap).scpb configure -state disabled
    $xth(ctrl,me,scrap).scpp configure -state disabled
    $xth(ctrl,me,scrap).scrp configure -state disabled
    $xth(ctrl,me,scrap).scx1p configure -state disabled
    $xth(ctrl,me,scrap).scy1p configure -state disabled
    $xth(ctrl,me,scrap).scx2p configure -state disabled
    $xth(ctrl,me,scrap).scy2p configure -state disabled
    $xth(ctrl,me,scrap).scx1r configure -state disabled
    $xth(ctrl,me,scrap).scy1r configure -state disabled
    $xth(ctrl,me,scrap).scx2r configure -state disabled
    $xth(ctrl,me,scrap).scy2r configure -state disabled
    $xth(ctrl,me,scrap).scu configure -state disabled
    $xth(ctrl,me,scrap).scul configure -state disabled
    xth_me_cmds_hide_scrap_xctrl    
  }
}

proc xth_me_cmds_update_scrap_vars {id} {

  global xth
  set xth(ctrl,me,scrap,name) $xth(me,cmds,$id,name)
  set xth(ctrl,me,scrap,projection) $xth(me,cmds,$id,projection)
  set xth(ctrl,me,scrap,options) $xth(me,cmds,$id,options)
  set xth(ctrl,me,scrap,px1) [lindex $xth(me,cmds,$id,scale) 0]
  set xth(ctrl,me,scrap,py1) [lindex $xth(me,cmds,$id,scale) 1]
  set xth(ctrl,me,scrap,px2) [lindex $xth(me,cmds,$id,scale) 2]
  set xth(ctrl,me,scrap,py2) [lindex $xth(me,cmds,$id,scale) 3]
  set xth(ctrl,me,scrap,rx1) [lindex $xth(me,cmds,$id,scale) 4]
  set xth(ctrl,me,scrap,ry1) [lindex $xth(me,cmds,$id,scale) 5]
  set xth(ctrl,me,scrap,rx2) [lindex $xth(me,cmds,$id,scale) 6]
  set xth(ctrl,me,scrap,ry2) [lindex $xth(me,cmds,$id,scale) 7]
  set xth(ctrl,me,scrap,units) [lindex $xth(me,cmds,$id,scale) 8]
  xth_me_cmds_move_scrap_xctrl 1 [lindex $xth(me,cmds,$id,scale) 0] \
    [lindex $xth(me,cmds,$id,scale) 1] 
  xth_me_cmds_move_scrap_xctrl 2 [lindex $xth(me,cmds,$id,scale) 2] \
    [lindex $xth(me,cmds,$id,scale) 3]

}


proc xth_me_cmds_update_scrap {id nname nproj nopt nscale} {

  global xth
  
  set oname $xth(me,cmds,$id,name)
  set oproj $xth(me,cmds,$id,projection)
  set oopt $xth(me,cmds,$id,options)
  set oscale $xth(me,cmds,$id,scale)

  regsub {^\s*} $nopt "" nopt
  regsub {\s*$} $nopt "" nopt
  if {[string length $nname] < 1} {
    set nname $oname
  }  
  if {[llength $nscale] < 8} {
    set nscale oscale
  } else {
    for {set i 0} {$i < 8} {incr i} {
      if {[catch {expr [lindex $nscale $i]}]} {
        set nscale [lreplace $nscale $i $i [lindex $oscale $i]]
      }
    }
  }
  if {[llength $nscale] == 9} {
    if {[string length [lindex $nscale 8]] == 0} {
      set nscale [lreplace $nscale 8 8]
    }
  }
  
  if {![string equal "$oname $oproj $oopt $oscale" "$nname $nproj $nopt $nscale"]} {
    xth_me_unredo_action [mc "scrap changes"] \
      "xth_me_cmds_update_scrap $id $oname [list $oproj] [list $oopt] [list $oscale]; xth_me_cmds_select $id" \
      "xth_me_cmds_update_scrap $id $nname [list $nproj] [list $nopt] [list $nscale]; xth_me_cmds_select $id"
    set xth(me,cmds,$id,name) $nname
    set xth(me,cmds,$id,projection) $nproj
    set xth(me,cmds,$id,options) $nopt
    set xth(me,cmds,$id,scale) $nscale
    xth_me_cmds_update_scrap_data $id
    xth_me_cmds_update_list $id
  }
  
}


proc xth_me_cmds_update_scrap_data {id} {

  global xth

  set d "scrap $xth(me,cmds,$id,name)"

  if {[llength $xth(me,cmds,$id,projection)] > 1} {
    set d "$d -projection \[$xth(me,cmds,$id,projection)\]"
  } elseif {[llength $xth(me,cmds,$id,projection)] > 0} {
    set d "$d -projection $xth(me,cmds,$id,projection)"
  }
  set xth(me,dflt,scrap,projection) $xth(me,cmds,$id,projection)

  if {[string length $xth(me,cmds,$id,options)] > 0} {
    set d "$d $xth(me,cmds,$id,options)"
  }
  set xth(me,dflt,scrap,options) $xth(me,cmds,$id,options)

  set d "$d -scale \[$xth(me,cmds,$id,scale)\]"
  set xth(me,dflt,scrap,scale) $xth(me,cmds,$id,scale)

  set xth(me,cmds,$id,data) "$d"
  
}


proc xth_me_cmds_create_scrap {ix mode name opts} {

  global xth
  xth_me_cmds_update {}

  set undoselect {}
  if {[string length $ix] == 0} {
    set undoselect "; xth_me_cmds_select $xth(me,cmds,selid)"

    #xth_me_cmds_select [lindex $xth(me,cmds,xlist) 0]
    set newselid 0
    set cx [lsearch -exact $xth(me,cmds,xlist) $xth(me,cmds,selid)]
    if {$cx > -1} {
      for {set cc [expr $cx + 1]} {$cc < [llength $xth(me,cmds,xlist)]} {incr cc} {
        set cselid [lindex $xth(me,cmds,xlist) $cc]
        if {$xth(me,cmds,$cselid,ct) == 4} {
          set newselid $cselid
          break
        }
      }
    }
    xth_me_cmds_select $newselid
    
  }
  
  set id [xth_me_cmds_create 4 {} $ix]

  if {[string length $name] > 0} {
    set xth(me,cmds,$id,name) $name
  } else {
    set xth(me,cmds,$id,name) "scrap$id"
  }

  if {$mode && ([string length $opts] < 1)} {
    set opts $xth(me,dflt,scrap,options)
  }
  
  # nastavit projekciu
  if {$mode} {
    set xth(me,cmds,$id,projection) $xth(me,dflt,scrap,projection)
  } else {
    set xth(me,cmds,$id,projection) {}
  }
  set optl [xth_me_cmds_get_line_option $opts projection]
  if {[lindex $optl 2]} {
    set xth(me,cmds,$id,projection) [lindex $optl 0]
    set opts [lindex $optl 1]
  }
  set optl [xth_me_cmds_get_line_option $opts proj]
  if {[lindex $optl 2]} {
    set xth(me,cmds,$id,projection) [lindex $optl 0]
    set opts [lindex $optl 1]
  }
  
  # nastavit scale
  set xth(me,cmds,$id,scale) {}
  if {[llength $xth(me,dflt,scrap,scale)] < 1} {
    set xth(me,dflt,scrap,scale) [list $xth(me,area,xmin) $xth(me,area,ymin) \
      $xth(me,area,xmax) $xth(me,area,ymin) 0.0 0.0 [expr 0.0254 * ($xth(me,area,xmax) - $xth(me,area,xmin))] 0.0 m]
  }
  set optl [xth_me_cmds_get_line_option $opts scale]
  set optv [lindex $optl 0]
  set opts [lindex $optl 1]
  switch [llength $optv] {
    1 {
      set xth(me,cmds,$id,scale) [list $xth(me,area,xmin) $xth(me,area,ymin) \
        $xth(me,area,xmax) $xth(me,area,ymin) 0.0 0.0 [expr 1.0 * $optv * ($xth(me,area,xmax) - $xth(me,area,xmin))] 0.0 m]
    }
    2 {
      set xth(me,cmds,$id,scale) [list $xth(me,area,xmin) $xth(me,area,ymin) \
        $xth(me,area,xmax) $xth(me,area,ymin) 0.0 0.0 [expr 1.0 * [lindex $optv 0] * ($xth(me,area,xmax) - $xth(me,area,xmin))] 0.0 [lindex $optv 1]]
    }
    3 {
      set xth(me,cmds,$id,scale) [list $xth(me,area,xmin) $xth(me,area,ymin) \
        $xth(me,area,xmax) $xth(me,area,ymin) 0.0 0.0 [expr 1.0 * [lindex $optv 1] / [lindex $optv 0] * ($xth(me,area,xmax) - $xth(me,area,xmin))] 0.0 [lindex $optv 2]]
    }
    8 {
      set xth(me,cmds,$id,scale) [list [lindex $optv 0] [lindex $optv 1] [lindex $optv 2] \
      [lindex $optv 3] [lindex $optv 4] [lindex $optv 5] [lindex $optv 6] [lindex $optv 7]]
    }
    9 {
      set xth(me,cmds,$id,scale) [list [lindex $optv 0] [lindex $optv 1] [lindex $optv 2] \
      [lindex $optv 3] [lindex $optv 4] [lindex $optv 5] [lindex $optv 6] [lindex $optv 7] [lindex $optv 8]]
    }
    default {
      set xth(me,cmds,$id,scale) $xth(me,dflt,scrap,scale)
    }
  }

  # nastavit options
  regsub {^\s*} $opts "" opts
  regsub {\s*$} $opts "" opts
  set xth(me,cmds,$id,options) $opts
  
  xth_me_cmds_update_list $id
  xth_me_cmds_update_scrap_data $id
  if {$mode} {
    xth_me_unredo_action [mc "creating scrap"] \
      "xth_me_cmds_delete $id$undoselect" \
      "xth_me_cmds_undelete $id 0 [lsearch $xth(me,cmds,xlist) $id]"  
    xth_me_cmds_create_endscrap $ix $mode {}
  }
}


proc xth_me_cmds_create_text {ix mode data cpos} {
  global xth
  xth_me_cmds_update {}
  set id [xth_me_cmds_create 1 {} $ix]
  set xth(me,cmds,$id,data) $data
  set xth(me,cmds,$id,cpos) $cpos
  if {$mode} {
    xth_me_cmds_select $id
    xth_me_unredo_action [mc "creating text"] \
      "xth_me_cmds_delete $id" \
      "xth_me_cmds_undelete $id 0 [lsearch $xth(me,cmds,xlist) $id]"
  }
}


proc xth_me_cmds_update_text {id newdata newcpos} {
  global xth
  set olddata $xth(me,cmds,$id,data)
  set oldcpos $xth(me,cmds,$id,cpos)
  regsub {\s*$} $newdata {} newdata
  if {![string equal $xth(me,cmds,$id,data) $newdata]} {
    set newdata "$newdata\n"
    xth_me_unredo_action [mc "text changes"] \
      "xth_me_cmds_update_text $id [list $olddata] $oldcpos; xth_me_cmds_select $id" \
      "xth_me_cmds_update_text $id [list $newdata] $newcpos; xth_me_cmds_select $id"
    set xth(me,cmds,$id,data) $newdata
    set xth(me,cmds,$id,cpos) $newcpos    
  }
}


proc xth_me_cmds_action {} {
  global xth
  switch $xth(me,cmds,action) {
    0 {
      xth_me_cmds_create_line {} 1 "" "" ""
      xth_ctrl_scroll_to me line
      xth_ctrl_maximize me line
      xth_ctrl_maximize me linept
    }
    1 {
      xth_me_cmds_set_mode 1    
    }
    2 {
      xth_me_cmds_create_scrap {} 1 "" ""
      xth_ctrl_scroll_to me scrap
      xth_ctrl_maximize me scrap
    }
    3 {
      xth_me_cmds_create_text {} 1 "\n" "1.0"
      xth_ctrl_scroll_to me text
      xth_ctrl_maximize me text
      focus $xth(ctrl,me,text).txt
    }
    4 {
      xth_me_cmds_delete {}
    }
    5 {
      xth_me_cmds_create_area {} 1 "" "" ""
      xth_ctrl_scroll_to me ac
      xth_ctrl_maximize me ac
    }
  }
}


proc xth_me_cmds_create_all {lns} {
  global xth
  set ctext {}
  xth_status_bar_push me
  set ctext_push {
    regsub {^\s*} $ctext {} ctext
    regsub {\s*$} $ctext {} ctext
    if {[string length $ctext] > 0} {
      xth_me_cmds_create_text [expr [llength $xth(me,cmds,xlist)] - 1] 0 "$ctext\n" 1.0
      set ctext {}
    }
  }
  set line_lines {}
  set line_type {}
  set line_opts {}
  set inline 0
  set linenumber 0
  set totallns [llength $lns]
  xth_me_progbar_show $totallns
  xth_status_bar_status me "Processing commands ..."
  foreach ln $lns {
    incr linenumber
    xth_me_progbar_prog $linenumber
    # here take care of special commands
    if {[regexp {^\s*scrap\s+(\S+)\s*(.*)$} $ln dum name opts]} {
      eval $ctext_push
      xth_me_cmds_create_scrap [expr [llength $xth(me,cmds,xlist)] - 1] 0 $name $opts
    } elseif {[regexp {^\s*endscrap\s*(\S*)\s*$} $ln dum name]} {
      eval $ctext_push
      xth_me_cmds_create_endscrap [expr [llength $xth(me,cmds,xlist)] - 1] 0 $name
    } elseif {[regexp {^\s*point\s+(\S+)\s+(\S+)\s+(\S+)\s*(.*)$} $ln dum x y type opts]} {
      eval $ctext_push
      xth_me_cmds_create_point [expr [llength $xth(me,cmds,xlist)] - 1] 0 $x $y $type $opts
    } elseif {[regexp {^\s*line\s+(\S+)\s*(.*)$} $ln dum line_type line_opts]} {
      eval $ctext_push
      set line_lines {}
      set inline 1
    } elseif {($inline == 1) && [regexp {^\s*endline(\s|$)} $ln]} {
      xth_me_cmds_create_line [expr [llength $xth(me,cmds,xlist)] - 1] 0 $line_type $line_opts $line_lines
      set line_lines {}
      set line_type {}
      set line_opts {}
      set inline 0
    } elseif {[regexp {^\s*area\s+(\S+)\s*(.*)$} $ln dum line_type line_opts]} {
      eval $ctext_push
      set line_lines {}
      set inline 2
    } elseif {($inline == 2) && [regexp {^\s*endarea(\s|$)} $ln]} {
      xth_me_cmds_create_area [expr [llength $xth(me,cmds,xlist)] - 1] 0 $line_type $line_opts $line_lines
      set line_lines {}
      set line_type {}
      set line_opts {}
      set inarea 0
    } elseif {($inline > 0)} {
      lappend line_lines $ln
    } else {
      set ctext "$ctext\n$ln"
    }
  }
  if {$inline > 0} {
    foreach ln $line_lines {
      set ctext "$ctext\n$ln"
    }
  }
  eval $ctext_push
  xth_me_progbar_hide
  xth_status_bar_pop me
}


proc xth_me_cmds_click {id tagOrId x y mx my} {
  global xth
  xth_me_cmds_update {}
  if {[llength $id] == 2} {
    set pid [lindex $id 1]
    set id [lindex $id 0]
  } else {
    set pid 0
  }
  
  switch $xth(me,cmds,mode) {
    0 {
      if {[llength $id] > 0} {
        if {$id != $xth(me,cmds,selid)} {
          xth_me_cmds_select "$id $pid"
          if {$pid == 0} {
            xth_ctrl_scroll_to me point
            xth_ctrl_maximize me point
          } else {
            xth_ctrl_scroll_to me line
            xth_ctrl_maximize me line
            xth_ctrl_maximize me linept
          }
        } else {
          switch $xth(me,cmds,$id,ct) {
            2 {xth_me_cmds_start_point_drag $id $mx $my}
            3 {
              if {$xth(me,cmds,selpid) != $pid} {
                xth_me_cmds_select_linept $id $pid
              } else {
                xth_me_cmds_start_linecp_drag pt$id.$pid $id 0 $pid 0 x $mx $my
              }
            }
          }
        }
      }
    }
    1 {
      xth_ctrl_scroll_to me point
      xth_ctrl_maximize me point
      # check, whether we clicked on XVI station
      set cptype {}
      set cpopts {}
      if {[regexp {XVIstI(\d+)S(\d+)} [$xth(me,can) itemcget $tagOrId -tags] dum imgx sti]} {
        set csname [lindex [lindex $xth(me,imgs,$imgx,XVIstations) $sti] 2]
        set x [lindex [lindex $xth(me,imgs,$imgx,XVIstationsX) $sti] 0]
        set y [lindex [lindex $xth(me,imgs,$imgx,XVIstationsX) $sti] 1]
        set cptype station
        set cpopts $xth(me,dflt,point,options)
        if {[regexp {\-name\s+(\S+)} $cpopts]} {
          regsub {\-name\s+(\S+)} $cpopts "-name $csname" cpopts
        } else {
          set cpopts "-name $csname"
        }
      }
      if {$id == ($xth(me,cmds,cmdln) - 1)} {
        xth_me_cmds_end_point 
      } else {
        xth_me_cmds_create_point {} 1 $x $y $cptype $cpopts
      }
    }
    2 {
      xth_ctrl_scroll_to me line
      xth_ctrl_maximize me line
      xth_ctrl_maximize me linept
      set fpid -1
      set lpid -1
      if {($id == $xth(me,cmds,selid)) && ([string length $id] > 0) && ($pid > 0)} {
        set xl $xth(me,cmds,$id,xplist)
        set lix [expr [llength $xl] - 2]
        if {$lix >= 0} {
          set fpid [lindex $xl 0]
          set lpid [lindex $xl $lix]
        }
      }
      if {($id == $xth(me,cmds,selid)) && ($pid != 0) && ($pid == $xth(me,cmds,inspid))} {
        xth_me_cmds_end_line
      } elseif {($id == $xth(me,cmds,selid)) && ($pid == $fpid) && ($xth(me,cmds,inspid) == 0)} {
        xth_me_cmds_close_line $id
      } elseif {($id == $xth(me,cmds,selid)) && ($pid == $lpid) && ($xth(me,cmds,inspid) == 0)} {
        xth_me_cmds_end_line
      } else {
        # vytvori novy bod
        xth_me_cmds_start_create_linept $tagOrId $x $y $mx $my
      }      
    }
    3 {
      if {([string length $id] > 0) && ($xth(me,cmds,$id,ct) == 3)} {
        xth_me_cmds_insert_area_lineid $id $mx $my
      }
    }
  }
}


proc xth_me_cmds_end_point {} {
  set recmds "xth_me_cmds_set_mode 0"
  set uncmds "xth_me_cmds_set_mode 1"
  eval $recmds
  xth_me_unredo_action [mc "end point insertion"] $uncmds $recmds
}




proc xth_me_cmds_click_lineln {id tagOrId mx my} {
  global xth
  xth_me_cmds_update {}
  if {[llength $id] == 2} {
    set pid [lindex $id 1]
    set id [lindex $id 0]
  } else {
    set pid 0
  }

  switch $xth(me,cmds,mode) {
    3 {
      if {$xth(me,cmds,$id,ct) == 3} {
        xth_me_cmds_insert_area_lineid $id $mx $my
      }
    }
    0 {
      xth_me_cmds_select "$id $pid"
    }
    default {
      xth_me_cmds_click_area ln$id.$pid $mx $my
    }
  }
}



proc xth_me_cmds_click_area {tagOrId x y} {
  global xth
  xth_me_cmds_click {} $tagOrId [xth_me_can2realx [$xth(me,can) canvasx $x]] [xth_me_can2realy [$xth(me,can) canvasy $y]] $x $y
}


proc xth_me_cmds_set_mode {nmode} {
  
  global xth
  
  if {!$xth(me,fopen)} {
    return
  }

  if {($nmode == 0) && ($xth(me,cmds,mode) == 0)} {
    xth_me_cmds_select_nopoint
  }

  set xth(me,cmds,mode) $nmode
  switch $nmode {
    0 {
      $xth(me,mbar) configure -text [mc "select object"] -bg green -fg black
      $xth(ctrl,me,ac).ins configure -text [mc "Insert"]
    }
    1 {
      $xth(me,mbar) configure -text [mc "insert point"] -bg red -fg white
    }
    2 {
      $xth(me,mbar) configure -text [mc "insert line point"] -bg red -fg white
    }
    3 {
      $xth(me,mbar) configure -text [mc "insert area border"] -bg red -fg white
      $xth(ctrl,me,ac).ins configure -text [mc "Select"]
    }
  }
  
  set xth(tb,me,action) $nmode
  
}


proc xth_me_cmds_create_point {ix mode x y type opts} {

  global xth
  xth_me_cmds_update {}
  set id [xth_me_cmds_create 2 {} $ix]

  set xth(me,cmds,$id,x) $x
  set xth(me,cmds,$id,y) $y
  
  if {$mode && ([string length $opts] < 1)} {
    if {([string length $type] < 1) && \
        [string equal $xth(me,dflt,point,type) station] && \
        [regexp {\-name\s+(\S+)} $xth(me,dflt,point,options) dum stname]} {
      regsub {\-name\s+(\S+)} $xth(me,dflt,point,options) "-name [xth_incr_station_name $stname $xth(me,snai)]" xth(me,dflt,point,options)
    }
    set opts $xth(me,dflt,point,options)
  }

  if {[string length $type] > 0} {
    set xth(me,cmds,$id,type) $type
  } else {
    set xth(me,cmds,$id,type) $xth(me,dflt,point,type)
  }
  
  # nastavit meno
  set optl [xth_me_cmds_get_line_option $opts id]
  if {[lindex $optl 2]} {
    set xth(me,cmds,$id,name) [lindex $optl 0]
    set opts [lindex $optl 1]
  }
  
  # nastavit rotation
  if {$mode} {
    set xth(me,cmds,$id,rotation) $xth(me,dflt,point,rotation)
  } else {
    set xth(me,cmds,$id,rotation) {}
  }
  set optl [xth_me_cmds_get_line_option $opts orientation]
  if {[lindex $optl 2]} {
    set xth(me,cmds,$id,rotation) [lindex $optl 0]
    set opts [lindex $optl 1]
  } else {
    set optl [xth_me_cmds_get_line_option $opts orient]
    if {[lindex $optl 2]} {
      set xth(me,cmds,$id,rotation) [lindex $optl 0]
      set opts [lindex $optl 1]
    }
  }

  # nastavit xsize
  if {$mode} {
    set xth(me,cmds,$id,xsize) $xth(me,dflt,point,xsize)
  } else {
    set xth(me,cmds,$id,xsize) {}
  }
  set optl [xth_me_cmds_get_line_option $opts size]
  if {[lindex $optl 2]} {
    set xth(me,cmds,$id,xsize) [lindex $optl 0]
    set xth(me,cmds,$id,ysize) [lindex $optl 0]
    set opts [lindex $optl 1]
  }
  set optl [xth_me_cmds_get_line_option $opts "x-size"]
  if {[lindex $optl 2]} {
    set xth(me,cmds,$id,xsize) [lindex $optl 0]
    set opts [lindex $optl 1]
  }

  # nastavit ysize
  if {$mode} {
    set xth(me,cmds,$id,ysize) $xth(me,dflt,point,ysize)
  } else {
    set xth(me,cmds,$id,ysize) {}
  }
  set optl [xth_me_cmds_get_line_option $opts "y-size"]
  if {[lindex $optl 2]} {
    set xth(me,cmds,$id,ysize) [lindex $optl 0]
    set opts [lindex $optl 1]
  }
  
#  if {([string length $xth(me,cmds,$id,ysize)] > 0) &&
#      ([string length $xth(me,cmds,$id,xsize)] == 0)} {
#    set xth(me,cmds,$id,xsize) $xth(me,cmds,$id,ysize)
#    set xth(me,cmds,$id,ysize) {}
#  }

  # nastavit options
  regsub {^\s*} $opts "" opts
  regsub {\s*$} $opts "" opts
  set xth(me,cmds,$id,options) $opts
  
  xth_me_cmds_draw_point $id
  if {$mode} {
    $xth(me,can) itemconfigure pt$id -fill lightBlue
  }
  xth_me_cmds_update_list $id
  xth_me_cmds_update_point_data $id
  if {$mode} {
    xth_me_unredo_action [mc "creating point"] \
      "xth_me_cmds_delete $id" \
      "xth_me_cmds_undelete $id 0 [lsearch $xth(me,cmds,xlist) $id]"  
    xth_me_cmds_select $id
  }

}


proc xth_me_cmds_update_point_data {id} {

  global xth

  set d "point $xth(me,cmds,$id,x) $xth(me,cmds,$id,y) $xth(me,cmds,$id,type)"
  set xth(me,dflt,point,type) $xth(me,cmds,$id,type)

  if {[string length $xth(me,cmds,$id,name)] > 0} {
    set d "$d -id $xth(me,cmds,$id,name)"
  }
  
  if {[string length $xth(me,cmds,$id,rotation)] > 0} {
    set d "$d -orientation $xth(me,cmds,$id,rotation)"
  }
  set xth(me,dflt,point,rotation) $xth(me,cmds,$id,rotation)

  if {[string length $xth(me,cmds,$id,xsize)] > 0} {
    set d "$d -x-size $xth(me,cmds,$id,xsize)"
  }
  set xth(me,dflt,point,xsize) $xth(me,cmds,$id,xsize)

  if {[string length $xth(me,cmds,$id,ysize)] > 0} {
    set d "$d -y-size $xth(me,cmds,$id,ysize)"
  }
  set xth(me,dflt,point,ysize) $xth(me,cmds,$id,ysize)

  if {[string length $xth(me,cmds,$id,options)] > 0} {
    set d "$d $xth(me,cmds,$id,options)"
  }
  set xth(me,dflt,point,options) $xth(me,cmds,$id,options)

  set ttype [lindex $d 3]
  set xth(me,cmds,$id,sbar) "$d"
  if {([string length $ttype] > 0)} {
    set ttyp [ mc "point $ttype"]
    if {![string equal $ttype $ttyp]} {
      set nd [lreplace $d 3 3 "$ttype:$ttyp"]
      set xth(me,cmds,$id,sbar) "$nd"
    }
  } 

  set xth(me,cmds,$id,data) "$d"
  
}


proc xth_me_cmds_move_point_xctrl {id} {
  global xth
  set cx [xth_me_real2canx $xth(me,cmds,$id,x)]
  set cy [xth_me_real2cany $xth(me,cmds,$id,y)]
  $xth(me,can) coords $xth(me,canid,point,selector) [list \
    [expr $cx - 3 * $xth(gui,me,point,psize)] \
    [expr $cy - 3 * $xth(gui,me,point,psize)] \
    [expr $cx + 3 * $xth(gui,me,point,psize)] \
    [expr $cy + 3 * $xth(gui,me,point,psize)]
  ]
}

proc xth_me_cmds_show_point_xctrl {id} {
  global xth
  $xth(me,can) itemconfigure $xth(me,canid,point,selector) -state normal
  $xth(me,can) raise $xth(me,canid,point,selector)
  $xth(me,can) raise ptfill
  $xth(me,can) lower ptfill point
  xth_me_cmds_move_point_xctrl $id
  xth_me_cmds_show_point_fill_xctrl $id
  $xth(me,can) raise pt$id
}


proc xth_me_cmds_show_point_fill_xctrl {id} {
  global xth
  if {$xth(ctrl,me,point,xsid) || $xth(ctrl,me,point,ysid)} {
    xth_me_cmds_configure_point_fill_xctrl $id 1
    xth_me_cmds_move_point_fill_xctrl $id $xth(ctrl,me,point,rot) $xth(ctrl,me,point,xs) $xth(ctrl,me,point,ys)
  } elseif {$xth(ctrl,me,point,rotid)} {
    xth_me_cmds_configure_point_fill_xctrl $id 0
    xth_me_cmds_move_point_fill_xctrl $id $xth(ctrl,me,point,rot) $xth(ctrl,me,point,xs) $xth(ctrl,me,point,ys)
  } else {
    xth_me_cmds_configure_point_fill_xctrl {} 0
  }
}


proc xth_me_cmds_hide_point_xctrl {} {
  global xth
  $xth(me,can) itemconfigure $xth(me,canid,point,selector) -state hidden
  xth_me_cmds_configure_point_fill_xctrl {} {}
}


proc xth_me_cmds_update_point_ctrl {id} {
  global xth
  if {[string length $id] > 0} {

    $xth(ctrl,me,point).posl configure -state normal
    $xth(ctrl,me,point).posx configure -state normal
    $xth(ctrl,me,point).posy configure -state normal
    $xth(ctrl,me,point).upd configure -state normal
    $xth(ctrl,me,point).typl configure -state normal
    $xth(ctrl,me,point).typ configure -state normal
    $xth(ctrl,me,point).namel configure -state normal
    $xth(ctrl,me,point).name configure -state normal
    $xth(ctrl,me,point).optl configure -state normal
    $xth(ctrl,me,point).opt configure -state normal
    $xth(ctrl,me,point).rotc configure -state normal
    $xth(ctrl,me,point).rot configure -state normal
    $xth(ctrl,me,point).xszc configure -state normal
    $xth(ctrl,me,point).xsz configure -state normal
    $xth(ctrl,me,point).yszc configure -state normal
    $xth(ctrl,me,point).ysz configure -state normal
    
    set xth(ctrl,me,point,x) $xth(me,cmds,$id,x)
    set xth(ctrl,me,point,y) $xth(me,cmds,$id,y)
    set xth(ctrl,me,point,type) $xth(me,cmds,$id,type)
    set xth(ctrl,me,point,name) $xth(me,cmds,$id,name)
    set xth(ctrl,me,point,opts) $xth(me,cmds,$id,options)

    set xth(ctrl,me,point,rot) $xth(me,cmds,$id,rotation)
    if {[string length $xth(me,cmds,$id,rotation)] > 0} {
      set xth(ctrl,me,point,rotid) 1
    } else {
      set xth(ctrl,me,point,rotid) 0
    }

    set xth(ctrl,me,point,xs) $xth(me,cmds,$id,xsize)
    if {[string length $xth(me,cmds,$id,xsize)] > 0} {
      set xth(ctrl,me,point,xsid) 1
    } else {
      set xth(ctrl,me,point,xsid) 0
    }

    set xth(ctrl,me,point,ys) $xth(me,cmds,$id,ysize)
    if {[string length $xth(me,cmds,$id,ysize)] > 0} {
      set xth(ctrl,me,point,ysid) 1
    } else {
      set xth(ctrl,me,point,ysid) 0
    }
    
    xth_me_cmds_show_point_xctrl $id
    xth_me_prev_cmd $xth(me,cmds,$id,data)
    
  } else {
  
    set xth(ctrl,me,point,x) {}
    set xth(ctrl,me,point,y) {}
    set xth(ctrl,me,point,type) $xth(me,dflt,point,type)
    set xth(ctrl,me,point,name) {}
    set xth(ctrl,me,point,opts) $xth(me,dflt,point,options)

    set xth(ctrl,me,point,rot) $xth(me,dflt,point,rotation)
    if {[string length $xth(me,dflt,point,rotation)] > 0} {
      set xth(ctrl,me,point,rotid) 1
    } else {
      set xth(ctrl,me,point,rotid) 0
    }

    set xth(ctrl,me,point,xs) $xth(me,dflt,point,xsize)
    if {[string length $xth(me,dflt,point,xsize)] > 0} {
      set xth(ctrl,me,point,xsid) 1
    } else {
      set xth(ctrl,me,point,xsid) 0
    }

    set xth(ctrl,me,point,ys) $xth(me,dflt,point,ysize)
    if {[string length $xth(me,dflt,point,ysize)] > 0} {
      set xth(ctrl,me,point,ysid) 1
    } else {
      set xth(ctrl,me,point,ysid) 0
    }

    $xth(ctrl,me,point).posl configure -state disabled
    $xth(ctrl,me,point).posx configure -state disabled
    $xth(ctrl,me,point).posy configure -state disabled
    $xth(ctrl,me,point).upd configure -state disabled
    $xth(ctrl,me,point).typl configure -state disabled
    $xth(ctrl,me,point).typ configure -state disabled
    $xth(ctrl,me,point).namel configure -state disabled
    $xth(ctrl,me,point).name configure -state disabled
    $xth(ctrl,me,point).optl configure -state disabled
    $xth(ctrl,me,point).opt configure -state disabled
    $xth(ctrl,me,point).rotc configure -state disabled
    $xth(ctrl,me,point).rot configure -state disabled
    $xth(ctrl,me,point).xszc configure -state disabled
    $xth(ctrl,me,point).xsz configure -state disabled
    $xth(ctrl,me,point).yszc configure -state disabled
    $xth(ctrl,me,point).ysz configure -state disabled
    
    xth_me_cmds_hide_point_xctrl  
  }
}


proc xth_me_cmds_update_point_vars {id} {

  global xth
  set xth(ctrl,me,point,x) $xth(me,cmds,$id,x)
  set xth(ctrl,me,point,y) $xth(me,cmds,$id,y)
  set xth(ctrl,me,point,type) $xth(me,cmds,$id,type)
  set xth(ctrl,me,point,name) $xth(me,cmds,$id,name)
  set xth(ctrl,me,point,opts) $xth(me,cmds,$id,options)
  set xth(ctrl,me,point,rot) $xth(me,cmds,$id,rotation)
  
  if {[string length $xth(me,cmds,$id,rotation)] > 0} {
    set xth(ctrl,me,point,rotid) 1
  } else {
    set xth(ctrl,me,point,rotid) 0
  }
  
  set xth(ctrl,me,point,xs) $xth(me,cmds,$id,xsize)
  if {[string length $xth(me,cmds,$id,xsize)] > 0} {
    set xth(ctrl,me,point,xsid) 1
  } else {
    set xth(ctrl,me,point,xsid) 0
  }
  
  set xth(ctrl,me,point,ys) $xth(me,cmds,$id,ysize)
  if {[string length $xth(me,cmds,$id,ysize)] > 0} {
    set xth(ctrl,me,point,ysid) 1
  } else {
    set xth(ctrl,me,point,ysid) 0
  }

  xth_me_cmds_move_point_xctrl $id
  xth_me_cmds_show_point_fill_xctrl $id
  
}

proc xth_me_cmds_update_area {id ntype nopt} {

  global xth
  
  set otype $xth(me,cmds,$id,type)
  set oopt $xth(me,cmds,$id,options)

  regsub {^\s*} $nopt "" nopt
  regsub {\s*$} $nopt "" nopt

  if {[string length $ntype] < 1} {
    set ntype $otype
  }
  if {(![string equal $ntype $otype]) && [string equal $nopt $oopt]} {
    set nopt {}
  }
  
  if {![string equal "$ntype $nopt" "$otype $oopt"]} {
    xth_me_unredo_action [mc "area changes"] \
      "xth_me_cmds_update_area $id $otype [list $oopt]; xth_me_cmds_select $id" \
      "xth_me_cmds_update_area $id $ntype [list $nopt]; xth_me_cmds_select $id"
    set xth(me,cmds,$id,type) $ntype
    set xth(me,cmds,$id,options) $nopt
    xth_me_cmds_update_area_data $id
    xth_me_cmds_update_list $id
  }

}




proc xth_me_cmds_update_point {id nx ny ntype nname nopt nrot nxs nys} {

  global xth
  
  set ox $xth(me,cmds,$id,x)
  set oy $xth(me,cmds,$id,y)
  set otype $xth(me,cmds,$id,type)
  set oname $xth(me,cmds,$id,name)
  set oopt $xth(me,cmds,$id,options)
  set orot $xth(me,cmds,$id,rotation)
  set oxs $xth(me,cmds,$id,xsize)
  set oys $xth(me,cmds,$id,ysize)

  regsub {^\s*} $nopt "" nopt
  regsub {\s*$} $nopt "" nopt

  if {[string length $ntype] < 1} {
    set ntype $otype
  }
  if {(![string equal $ntype $otype]) && [string equal $nopt $oopt]} {
    set nopt {}
    set nrot {}
    set nxs {}
    set nys {}
  }
  
  if {[string length $nrot] > 0} {
    if {[catch {expr $nrot}]} {
      set nrot $orot
    } elseif {($nrot < 0.0) || ($nrot >= 360.0)} {
      set nrot $orot
    }
  }
  
  if {[catch {expr $nx}]} {
    set nx $ox
  }
  if {[catch {expr $ny}]} {
    set ny $oy
  }
  
  if {[string length $nxs] > 0} {
    if {[catch {expr $nxs}]} {
      set nxs $oxs
    } elseif {$nxs < 0.0} {
      set nxs $oxs
    }
  }
  if {[string length $nys] > 0} {
    if {[catch {expr $nys}]} {
      set nys $oys
    } elseif {$nys < 0.0} {
      set nys $oys
    }
  }
#  if {([string length $nys] > 0) && ([string length $nxs] == 0)} {
#    set nxs $nys
#    set nys {}
#  }
  
  if {![string equal "$nx $ny $ntype $nname $nopt $nrot $nxs $nys" "$ox $oy $otype $oname $oopt $orot $oxs $oys"]} {
    xth_me_unredo_action [mc "point changes"] \
      "xth_me_cmds_update_point $id $ox $oy $otype [list $oname] [list $oopt] [list $orot] [list $oxs] [list $oys]; xth_me_cmds_select $id" \
      "xth_me_cmds_update_point $id $nx $ny $ntype [list $nname] [list $nopt] [list $nrot] [list $nxs] [list $nys]; xth_me_cmds_select $id"
    set xth(me,cmds,$id,x) $nx
    set xth(me,cmds,$id,y) $ny
    set xth(me,cmds,$id,type) $ntype
    set xth(me,cmds,$id,name) $nname
    set xth(me,cmds,$id,options) $nopt
    set xth(me,cmds,$id,rotation) $nrot
    set xth(me,cmds,$id,xsize) $nxs
    set xth(me,cmds,$id,ysize) $nys
    $xth(me,can) coords pt$id [xth_me_cmds_calc_point_coords $id]
    xth_me_cmds_update_point_data $id
    xth_me_cmds_update_list $id
  }
  
}


proc xth_me_cmds_calc_point_coords {id} {
  global xth
  return [list \
    [expr [xth_me_real2canx $xth(me,cmds,$id,x)] - $xth(gui,me,point,psize)] \
    [expr [xth_me_real2cany $xth(me,cmds,$id,y)] - $xth(gui,me,point,psize)] \
    [expr [xth_me_real2canx $xth(me,cmds,$id,x)] + $xth(gui,me,point,psize)] \
    [expr [xth_me_real2cany $xth(me,cmds,$id,y)] + $xth(gui,me,point,psize)]
  ]
}


proc xth_me_cmds_draw_point {id} {
  global xth
  $xth(me,can) create oval [xth_me_cmds_calc_point_coords $id] \
    -tags "command point pt$id" -width 1 -outline blue -fill blue
  $xth(me,can) bind pt$id <Enter> "$xth(me,can) itemconfigure pt$id -fill cyan; xth_status_bar_push me; xth_status_bar_status me \"\$xth(me,cmds,$id,listix): \$xth(me,cmds,$id,sbar)\""
  $xth(me,can) bind pt$id <Leave> "$xth(me,can) itemconfigure pt$id -fill \[$xth(me,can) itemcget pt$id -outline\]; xth_status_bar_pop me"
  $xth(me,can) bind pt$id <1> "xth_me_cmds_click $id pt$id \$xth(me,cmds,$id,x) \$xth(me,cmds,$id,y) %x %y"
  $xth(me,can) bind pt$id <3> "xth_me_cmds_special_select $id %x %y"  
  $xth(me,can) bind pt$id <Shift-1> "xth_me_cmds_special_select $id %x %y"  
  $xth(me,can) bind pt$id <$xth(kb_control)-1> "xth_me_cmds_click_area pt$id %x %y"
}


proc xth_me_cmds_special_select {id x y} {
  global xth
  if {[llength $id] == 2} {
    set pid [lindex $id 1]
    set id [lindex $id 0]
  } else {
    set pid 0
  }
  $xth(me,can) raise point
  if {$xth(me,cmds,selid) != $id} {
    xth_me_cmds_select "$id $pid"
    if {$pid != 0} {
      xth_ctrl_scroll_to me line
      xth_ctrl_maximize me line
      xth_ctrl_maximize me linept
    } else {
      xth_ctrl_scroll_to me point
      xth_ctrl_maximize me point

    }
  } elseif {($xth(me,cmds,$id,ct) == 3) && ($xth(me,cmds,selpid) != $pid)} {
    xth_me_cmds_select_linept $id $pid
    xth_ctrl_scroll_to me line
    xth_ctrl_maximize me line
    xth_ctrl_maximize me linept
  } else {
    $xth(me,can) dtag all nearest
    if {$pid != 0} {
      set utag pt$id.$pid
    } else {
      set utag pt$id
    }
    $xth(me,can) addtag nearest closest [$xth(me,can) canvasx $x] [$xth(me,can) canvasy $y] 0 $utag
    set tgs [$xth(me,can) itemcget nearest -tags]
    #puts $tgs
    if {[regexp "(^|\\s)pt(\\d+)($|\\s)" $tgs d1 d2 nid]} {
      #puts "select $nid"
      xth_me_cmds_select $nid
      xth_ctrl_scroll_to me point
      xth_ctrl_maximize me point
      catch {$xth(me,can) lower $utag point}
      catch {$xth(me,can) raise $utag line}
    } elseif {[regexp "(^|\\s)pt(\\d+)\.(\\d+)($|\\s)" $tgs d1 d2 nid npid]} {
      #puts "select $nid $npid"
      xth_me_cmds_select "$nid $npid"
      if {$npid != 0} {
        xth_ctrl_scroll_to me line
        xth_ctrl_maximize me line
        xth_ctrl_maximize me linept
      } else {
        xth_ctrl_scroll_to me point
        xth_ctrl_maximize me point
      }
      catch {$xth(me,can) lower $utag point}
      catch {$xth(me,can) raise $utag line}
    }
  }
}


proc xth_me_cmds_start_point_drag {id x y} {
  global xth
  xth_me_cmds_update {}
  xth_me_cmds_drag_point_config_xctrl $id
  set xth(me,point,drag_mx) $x
  set xth(me,point,drag_my) $y
  set xth(me,point,drag_px) $xth(me,cmds,$id,x)
  set xth(me,point,drag_py) $xth(me,cmds,$id,y)
  set xth(me,point,drag_benter) [$xth(me,can) bind pt$id <Enter>]
  set xth(me,point,drag_bleave) [$xth(me,can) bind pt$id <Leave>]
  $xth(me,can) bind pt$id <Enter> ""
  $xth(me,can) bind pt$id <Leave> ""
  $xth(me,can) itemconfigure pt$id -fill {}
  $xth(me,can) bind pt$id <B1-Motion> "xth_me_cmds_point_drag $id %x %y 1"
  $xth(me,can) bind pt$id <B1-ButtonRelease> "xth_me_cmds_end_point_drag $id %x %y 1"
  $xth(me,can) bind pt$id <$xth(kb_control)-B1-Motion> "xth_me_cmds_point_drag $id %x %y 0"
  $xth(me,can) bind pt$id <$xth(kb_control)-B1-ButtonRelease> "xth_me_cmds_end_point_drag $id %x %y 0"
  $xth(me,can) configure -cursor {}
}


proc xth_me_cmds_drag_to {id pid x y} {
  global xth
  $xth(me,can) dtag all nearest
  if {[string length $pid] > 0} {
    set stt pt$id.$pid
  } else {
    set stt pt$id
  }
  $xth(me,can) addtag nearest closest [$xth(me,can) canvasx $x] \
    [$xth(me,can) canvasy $y] 0 $stt
  set tgs [$xth(me,can) itemcget nearest -tags]
  if {[regexp "(^|\\s)pt(\\d+)($|\\s)" $tgs d1 d2 nid]} {
    # je vybraty bod, nastavime suradnice podla neho
    set nx $xth(me,cmds,$nid,x)
    set ny $xth(me,cmds,$nid,y)
    return [list 1 $nx $ny]
  } elseif {[regexp "(^|\\s)pt(\\d+)\.(\\d+)($|\\s)" $tgs d1 d2 nid npid]} {
    # je vybraty bod na ciare, nastavime suradnice podla neho
    set nx $xth(me,cmds,$nid,$npid,x)
    set ny $xth(me,cmds,$nid,$npid,y)
    return [list 1 $nx $ny]
  }
  return 0
}


proc xth_me_cmds_point_drag {id x y dragto} {
  global xth
  set nx [expr $xth(me,point,drag_px) - [expr double($xth(me,point,drag_mx) - $x) * 100.0 / $xth(me,zoom)]]
  set ny [expr $xth(me,point,drag_py) + [expr double($xth(me,point,drag_my) - $y) * 100.0 / $xth(me,zoom)]]
  set dts 0
  if $dragto {
    set dtl [xth_me_cmds_drag_to $id {} $x $y]
    if {[lindex $dtl 0]} {
      set nx [lindex $dtl 1]
      set ny [lindex $dtl 2]
      set dts 1
    }
  }
  if $dts {
    $xth(me,can) itemconfigure pt$id -fill cyan
  } else {
    $xth(me,can) itemconfigure pt$id -fill {}
  }
  set xth(me,cmds,$id,x) $nx
  set xth(me,cmds,$id,y) $ny
  set xth(ctrl,me,point,x) $nx
  set xth(ctrl,me,point,y) $ny
  xth_me_cmds_move_point_xctrl $id
  xth_me_cmds_move_point_fill_xctrl $id $xth(me,cmds,$id,rotation) $xth(me,cmds,$id,xsize) $xth(me,cmds,$id,ysize) 
  $xth(me,can) coords pt$id [xth_me_cmds_calc_point_coords $id]
  update idletasks
}


proc xth_me_cmds_end_point_drag {id x y dragto} {
  global xth
  xth_me_cmds_point_drag $id $x $y $dragto
  set xth(me,cmds,$id,x) $xth(me,point,drag_px)
  set xth(me,cmds,$id,y) $xth(me,point,drag_py)
  $xth(me,can) bind pt$id <B1-Motion> ""
  $xth(me,can) bind pt$id <B1-ButtonRelease> ""
  $xth(me,can) bind pt$id <$xth(kb_control)-B1-Motion> ""
  $xth(me,can) bind pt$id <$xth(kb_control)-B1-ButtonRelease> ""
  $xth(me,can) bind pt$id <Enter> $xth(me,point,drag_benter)
  $xth(me,can) bind pt$id <Leave> $xth(me,point,drag_bleave)
  $xth(me,can) itemconfigure pt$id -fill cyan
  $xth(me,can) configure -cursor crosshair
  set xth(me,unredola) "point dragging"
  xth_me_cmds_update {}
  xth_me_cmds_end_drag_point_config_xctrl $id
}


proc xth_me_cmds_configure_point_fill_xctrl {id sid} {
  global xth
  if {[string length $id] > 0} {
    # $xth(me,can) itemconfigure $xth(me,canid,point,fx) -state normal
    $xth(me,can) bind $xth(me,canid,point,fx) <1> \
      "xth_me_cmds_start_point_fdrag $xth(me,canid,point,fx) $id x %x %y"
    $xth(me,can) bind $xth(me,canid,point,fx) <Enter> \
      "$xth(me,can) itemconfigure $xth(me,canid,point,fx) -fill #ffda00"
    $xth(me,can) bind $xth(me,canid,point,fx) <Leave> \
      "$xth(me,can) itemconfigure $xth(me,canid,point,fx) -fill red"
    $xth(me,can) itemconfigure $xth(me,canid,point,fy) -state normal
    $xth(me,can) bind $xth(me,canid,point,fy) <1> \
      "xth_me_cmds_start_point_fdrag $xth(me,canid,point,fy) $id y %x %y"
    $xth(me,can) bind $xth(me,canid,point,fy) <Enter> \
      "$xth(me,can) itemconfigure $xth(me,canid,point,fy) -fill #ffda00"
    $xth(me,can) bind $xth(me,canid,point,fy) <Leave> \
      "$xth(me,can) itemconfigure $xth(me,canid,point,fy) -fill red"
    #$xth(me,can) itemconfigure $xth(me,canid,point,fxc) -state normal
    #$xth(me,can) bind $xth(me,canid,point,fxc) <Enter> \
    #  "$xth(me,can) itemconfigure $xth(me,canid,point,fxc) -fill yellow"
    #$xth(me,can) bind $xth(me,canid,point,fxc) <Leave> \
    #  "$xth(me,can) itemconfigure $xth(me,canid,point,fxc) -fill red"
    #$xth(me,can) bind $xth(me,canid,point,fxc) <1> \
    #  "xth_me_cmds_start_point_fdrag $xth(me,canid,point,fxc) $id x %x %y"
    #$xth(me,can) itemconfigure $xth(me,canid,point,fyc) -state normal
    #$xth(me,can) bind $xth(me,canid,point,fyc) <Enter> \
    #  "$xth(me,can) itemconfigure $xth(me,canid,point,fyc) -fill yellow"
    #$xth(me,can) bind $xth(me,canid,point,fyc) <Leave> \
    #  "$xth(me,can) itemconfigure $xth(me,canid,point,fyc) -fill red"
    #$xth(me,can) bind $xth(me,canid,point,fyc) <1> \
    #  "xth_me_cmds_start_point_fdrag $xth(me,canid,point,fyc) $id y %x %y"
    if {$sid} {
      $xth(me,can) itemconfigure $xth(me,canid,point,fill) -state normal
      #$xth(me,can) bind $xth(me,canid,point,fill) <1> \
      #  "xth_me_cmds_start_point_fdrag $xth(me,canid,point,fill) $id z %x %y"
    } else {
      $xth(me,can) itemconfigure $xth(me,canid,point,fill) -state hidden
    }
  } else {
      # $xth(me,can) bind $xth(me,canid,point,fxc) <Enter> ""
      # $xth(me,can) bind $xth(me,canid,point,fxc) <Leave> ""
      # $xth(me,can) bind $xth(me,canid,point,fyc) <Enter> ""
      # $xth(me,can) bind $xth(me,canid,point,fyc) <Leave> ""
      $xth(me,can) bind $xth(me,canid,point,fx) <1> ""
      $xth(me,can) bind $xth(me,canid,point,fy) <1> ""
      $xth(me,can) bind $xth(me,canid,point,fx) <Enter> ""
      $xth(me,can) bind $xth(me,canid,point,fx) <Leave> ""
      $xth(me,can) bind $xth(me,canid,point,fy) <Enter> ""
      $xth(me,can) bind $xth(me,canid,point,fy) <Leave> ""
      #$xth(me,can) bind $xth(me,canid,point,fill) <1> ""
      $xth(me,can) itemconfigure ptfill -state hidden
  }
}


proc xth_me_cmds_move_point_fill_xctrl {id rot sx sy} {

  global xth
  
  if {[string length $rot] > 0} {
    set rot [expr double($rot) / 180 * 3.14159265359]
  } else {
    set rot 0.0
  }

  set setfsx 0
  if {[string length $sx] > 0} {
    set sx [expr $sx * 0.01 * $xth(me,zoom)]
    set fsx $sx
  } else {
    set sx 30.0
    set setfsx 1
  }

#  if {[string length $sy] > 0} {
#    set sy [expr $sy * 0.01 * $xth(me,zoom)]
#  } else {
#    if {[string length $sx] > 0} {
#      set sy $sx
#    } else {
#      set sy 30.0
#    }
#  }

  if {[string length $sy] > 0} {
    set sy [expr $sy * 0.01 * $xth(me,zoom)]
    set fsy $sy
  } else {
    set sy 30.0
    set fsy $sx
  }

  if {$setfsx} {
    set fsx $sy
  }

  set x [xth_me_real2canx $xth(me,cmds,$id,x)]
  set y [xth_me_real2cany $xth(me,cmds,$id,y)]
  set ca [expr cos($rot)]
  set sa [expr sin($rot)]
  
  set xvx [expr $ca * $sx]
  set xvy [expr $sa * $sx]
  set yvx [expr $sa * $sy]
  set yvy [expr - $ca * $sy]

  set fxvx [expr $ca * $fsx]
  set fxvy [expr $sa * $fsx]
  set fyvx [expr $sa * $fsy]
  set fyvy [expr - $ca * $fsy]
  
  
  $xth(me,can) coords $xth(me,canid,point,fx) $x $y [expr $x + $xvx] [expr $y + $xvy]
  set xth(me,canid,point,fx_tox) [expr $x + $xvx]
  set xth(me,canid,point,fx_toy) [expr $y + $xvy]
  #$xth(me,can) coords $xth(me,canid,point,fxc) [expr $x + $xvx - $xth(gui,me,point,cpsize)] [expr $y + $xvy - $xth(gui,me,point,cpsize)] [expr $x + $xvx + $xth(gui,me,point,cpsize)] [expr $y + $xvy + $xth(gui,me,point,cpsize)]
  $xth(me,can) coords $xth(me,canid,point,fy) $x $y [expr $x + $yvx] [expr $y + $yvy]
  set xth(me,canid,point,fy_tox) [expr $x + $yvx]
  set xth(me,canid,point,fy_toy) [expr $y + $yvy]
  #$xth(me,can) coords $xth(me,canid,point,fyc) [expr $x + $yvx - $xth(gui,me,point,cpsize)] [expr $y + $yvy - $xth(gui,me,point,cpsize)] [expr $x + $yvx + $xth(gui,me,point,cpsize)] [expr $y + $yvy + $xth(gui,me,point,cpsize)]
  $xth(me,can) coords $xth(me,canid,point,fill) [expr $x + $fxvx + $fyvx] [expr $y + $fxvy + $fyvy] \
    [expr $x + $fxvx - $fyvx] [expr $y + $fxvy - $fyvy] [expr $x - $fxvx - $fyvx] [expr $y - $fxvy - $fyvy] \
    [expr $x - $fxvx + $fyvx] [expr $y - $fxvy + $fyvy]

  update idletasks    
}


proc xth_me_cmds_point_change_state {} {

  global xth  
  set newrotid $xth(ctrl,me,point,rotid)
  set newxsid $xth(ctrl,me,point,xsid)
  set newysid $xth(ctrl,me,point,ysid)

  xth_me_cmds_update {}

  if {$newrotid && \
    ([string length $xth(ctrl,me,point,rot)] < 1)} {
    set xth(ctrl,me,point,rot) 0.0
  } elseif {(! $newrotid) && \
    ([string length $xth(ctrl,me,point,rot)] > 0)} {
    set xth(ctrl,me,point,rot) {}
  }

  if {$newxsid && \
    ([string length $xth(ctrl,me,point,xs)] < 1)} {
    set xth(ctrl,me,point,xs) 40.0
  } elseif {(! $newxsid) && \
    ([string length $xth(ctrl,me,point,xs)] > 0)} {
    set xth(ctrl,me,point,xs) {}
#    set xth(ctrl,me,point,ys) {}
#    set xth(ctrl,me,point,ysid) 0
  }

  if {$newysid && \
    ([string length $xth(ctrl,me,point,ys)] < 1)} {
    set xth(ctrl,me,point,ys) 40.0
  } elseif {(! $newysid) && \
    ([string length $xth(ctrl,me,point,ys)] > 0)} {
    set xth(ctrl,me,point,ys) {}
  }

#  if {$newysid && \
#      ([string length $xth(ctrl,me,point,ys)] < 1) && \
#      $newxsid} {
#    set xth(ctrl,me,point,ys) 40.0
#  } elseif {((! $newysid) && \
#      ([string length $xth(ctrl,me,point,ys)] > 0)) || \
#      (! $newxsid)} {
#    set xth(ctrl,me,point,ys) {}
#    set xth(ctrl,me,point,ysid) 0    
#  }
  
  xth_me_cmds_update {}
  
}


proc xth_me_cmds_start_point_fdrag {tagOrId id ax x y} {
  global xth
  xth_me_cmds_update {}
  #if {[string equal $ax z]} {
  #  set distx [expr hypot([$xth(me,can) canvasx $x] - $xth(me,canid,point,fx_tox), \
  #    [$xth(me,can) canvasy $y] - $xth(me,canid,point,fx_toy))]
  #  set disty [expr hypot([$xth(me,can) canvasx $x] - $xth(me,canid,point,fy_tox), \
  #    [$xth(me,can) canvasy $y] - $xth(me,canid,point,fy_toy))]
  #  if {$disty < $distx} {
  #    set ax y
  #  } else {
  #    set ax x
  #  }
  #}
  set dx [expr [xth_me_can2realx [$xth(me,can) canvasx $x]] - $xth(me,cmds,$id,x)]
  set dy [expr [xth_me_can2realy [$xth(me,can) canvasy $y]] - $xth(me,cmds,$id,y)] 
  if {[string length $xth(me,cmds,$id,rotation)] == 0} {
    set xth(me,point,fdrag_rot) 0
  } else {
    set xth(me,point,fdrag_rot) 1
    set xth(me,point,fdrag_orot) [expr atan2($dy,$dx)]
  }
  if {([string length $xth(me,cmds,$id,xsize)] == 0) && ([string length $xth(me,cmds,$id,ysize)] == 0)} {
    set xth(me,point,fdrag_size) 0
  } elseif {[string equal $ax y] && ([string length $xth(me,cmds,$id,ysize)] == 0)} {
    set xth(me,point,fdrag_size) 0
  } elseif {[string equal $ax x] && ([string length $xth(me,cmds,$id,xsize)] == 0)} {
    set xth(me,point,fdrag_size) 0
  } else {
    set xth(me,point,fdrag_ax) $ax
    set xth(me,point,fdrag_size) 1
    set xth(me,point,fdrag_osize) [expr hypot($dy,$dx)]
  }
  $xth(me,can) itemconfigure $tagOrId -fill #ffda00
  set xth(me,point,fdrag_benter) [$xth(me,can) bind $tagOrId <Enter>]
  set xth(me,point,fdrag_bleave) [$xth(me,can) bind $tagOrId <Leave>]
  $xth(me,can) bind $tagOrId <Enter> ""
  $xth(me,can) bind $tagOrId <Leave> ""
  $xth(me,can) bind $tagOrId <B1-Motion> "xth_me_cmds_point_fdrag $id %x %y"
  $xth(me,can) bind $tagOrId <B1-ButtonRelease> "xth_me_cmds_end_point_fdrag $tagOrId $id %x %y"
  $xth(me,can) configure -cursor {}
}

proc xth_me_cmds_point_fdrag {id x y} {
  global xth
  set dx [expr [xth_me_can2realx [$xth(me,can) canvasx $x]] - $xth(me,cmds,$id,x)]
  set dy [expr [xth_me_can2realy [$xth(me,can) canvasy $y]] - $xth(me,cmds,$id,y)] 
  if $xth(me,point,fdrag_rot) {
    set rot [expr double($xth(me,cmds,$id,rotation)) - 180.0 / 3.14159265359 * (atan2($dy,$dx) - $xth(me,point,fdrag_orot))]
    if {$rot < 0.0} {
      set rot [expr 360.0 + $rot]
    } elseif {$rot >= 360.0} {
      set rot [expr $rot - 360.0]
    }
    set rot [format "%.1f" $rot]
  } else {
    set rot $xth(me,cmds,$id,rotation)
  }
  set xth(ctrl,me,point,rot) $rot
  if {$xth(me,point,fdrag_size)} {
    set cs [expr hypot($dy,$dx)]
    switch $xth(me,point,fdrag_ax) {
      x {
        set ns [expr $xth(me,cmds,$id,xsize) - $xth(me,point,fdrag_osize) + $cs]
        if {$ns <= 0.0} {set ns 0.1}
        set ns [format "%.1f" $ns]
        set xth(ctrl,me,point,xs) $ns
      }
      y {
        set ns [expr $xth(me,cmds,$id,ysize) - $xth(me,point,fdrag_osize) + $cs]
        if {$ns <= 0.0} {set ns 0.1}
        set ns [format "%.1f" $ns]
        set xth(ctrl,me,point,ys) $ns
      }
    }
  }
  xth_me_cmds_move_point_fill_xctrl $id $xth(ctrl,me,point,rot) $xth(ctrl,me,point,xs) $xth(ctrl,me,point,ys)
}

proc xth_me_cmds_end_point_fdrag {tagOrId id x y} {
  global xth
  xth_me_cmds_point_fdrag $id $x $y
  $xth(me,can) configure -cursor crosshair
  if {$xth(me,point,fdrag_size)} {
    set xth(me,unredola) "point resizing"
  } else {
    set xth(me,unredola) "point rotation"
  }
  $xth(me,can) bind $tagOrId <B1-Motion> ""
  $xth(me,can) bind $tagOrId <B1-ButtonRelease> ""
  if {[lsearch [$xth(me,can) itemcget $tagOrId -tags] current] > -1} {
    $xth(me,can) itemconfigure $tagOrId -fill #ffda00
  }
  $xth(me,can) bind $tagOrId <Enter> $xth(me,point,fdrag_benter)
  $xth(me,can) bind $tagOrId <Leave> $xth(me,point,fdrag_bleave)
  xth_me_cmds_update {}
}

proc xth_me_cmds_drag_point_config_xctrl {id} {
  global xth
  set xth(me,point,drag_stsel) [$xth(me,can) itemcget $xth(me,canid,point,selector) -state]
  $xth(me,can) itemconfigure $xth(me,canid,point,selector) -state hidden
  set xth(me,point,drag_stfx) [$xth(me,can) itemcget $xth(me,canid,point,fx) -state]
  $xth(me,can) itemconfigure $xth(me,canid,point,fx) -width 1 -arrow none
  #$xth(me,can) itemconfigure $xth(me,canid,point,fxc) -state hidden
  set xth(me,point,drag_stfy) [$xth(me,can) itemcget $xth(me,canid,point,fy) -state]
  $xth(me,can) itemconfigure $xth(me,canid,point,fy) -width 1 -arrow none
  #$xth(me,can) itemconfigure $xth(me,canid,point,fyc) -state hidden
  $xth(me,can) itemconfigure $xth(me,canid,point,fill) -fill {} -outline red
}


proc xth_me_cmds_end_drag_point_config_xctrl {id} {
  global xth
  $xth(me,can) itemconfigure $xth(me,canid,point,selector) -state $xth(me,point,drag_stsel)
  $xth(me,can) itemconfigure $xth(me,canid,point,fx) -width 5 -arrow last
  #$xth(me,can) itemconfigure $xth(me,canid,point,fxc) -state $xth(me,point,drag_stfx)
  $xth(me,can) itemconfigure $xth(me,canid,point,fy) -width 5 -arrow last
  #$xth(me,can) itemconfigure $xth(me,canid,point,fyc) -state $xth(me,point,drag_stfy)
  $xth(me,can) itemconfigure $xth(me,canid,point,fill) -fill red -outline {}
}

proc xth_me_cmds_select_nopoint {} {
  global xth
  set id $xth(me,cmds,selid)
  set ix [lsearch $xth(me,cmds,xlist) $id]
  set xl [llength $xth(me,cmds,xlist)]
  for {set ii $ix} {$ii < $xl} {incr ii} {
    set nid [lindex $xth(me,cmds,xlist) $ii]
    switch $xth(me,cmds,$nid,ct) {
      3 {
        xth_me_cmds_select "$nid 0"
        break
      }
      2 {}
      default {
        xth_me_cmds_select $nid
        break
      }
    }
  }
}


proc xth_me_get_center {} {
  global xth
  set sr [$xth(me,can) cget -scrollregion]
  set xw [$xth(me,can) xview]
  set yw [$xth(me,can) yview]
  set xx [expr double([lindex $xw 1] + [lindex $xw 0]) / 2.0]
  set yy [expr double([lindex $yw 1] + [lindex $yw 0]) / 2.0]
  set tw [expr [lindex $sr 2] - [lindex $sr 0]]
  set th [expr [lindex $sr 3] - [lindex $sr 1]]	
  set x [xth_me_can2realx [expr [lindex $sr 0] + $xx * $tw]]
  set y [xth_me_can2realy [expr [lindex $sr 1] + $yy * $th]]
	return "$x $y"
}







proc xth_me_cmds_get_option {ln opt} {
  set rxl [list [list "^\\s*$opt\\s+\\\[(\[^\\\]\]*)\\\]" "\["]\
    [list "^\\s*$opt\\s+\\\"((\\\"\\\"|\[^\\\"])+)\\\"" "\""]\
    [list "^\\s*$opt\\s+(\\S+)" {}]]
  set rln $ln
  set val {}
  set sep {}
  set res 0
  foreach rx $rxl {
    if {[regexp [lindex $rx 0] $ln dump val]} {
      regsub [lindex $rx 0] $ln {} rln
      regsub {^\s*} $rln {} rln
      set sep [lindex $rx 1]
      set res 1
      break
    }
  }
  return [list $val $rln $res]
}


proc xth_me_cmds_get_onoffauto {opt} {
  switch $opt {
    on {return 1}
    off {return 0}
    default {return -1}
  }
}


proc xth_me_cmds_get_bool {opt} {
  if {[lsearch {on 1 true yes} $opt] > -1} {
    return 1
  } else {
    return 0
  }
}


proc xth_me_cmds_update_line_ctrl {id} {

  global xth
  
  if {[string length $id] > 0} {

    $xth(ctrl,me,line).typl configure -state normal    
    $xth(ctrl,me,line).typ configure -state normal    
    $xth(ctrl,me,line).namel configure -state normal    
    $xth(ctrl,me,line).name configure -state normal    
    $xth(ctrl,me,line).optl configure -state normal    
    $xth(ctrl,me,line).opt configure -state normal    
    $xth(ctrl,me,line).rev configure -state normal    
    $xth(ctrl,me,line).cls configure -state normal    
#    $xth(ctrl,me,line).insp configure -state normal    
#    $xth(ctrl,me,line).delp configure -state normal    
    $xth(ctrl,me,line).lpa configure -state normal    
    $xth(ctrl,me,line).upd configure -state normal    
    $xth(ctrl,me,line).lpa.m entryconfigure [mc "Insert point"] -state normal    
    $xth(ctrl,me,line).lpa.m entryconfigure [mc "Delete point"] -state normal    
    $xth(ctrl,me,line).pl.l configure -takefocus 1 \
      -listvariable xth(me,cmds,$id,plist)

    set xth(ctrl,me,line,type) $xth(me,cmds,$id,type)
    set xth(ctrl,me,line,name) $xth(me,cmds,$id,name)
    set xth(ctrl,me,line,opts) $xth(me,cmds,$id,options)
    set xth(ctrl,me,line,reverse) $xth(me,cmds,$id,reverse)
    set xth(ctrl,me,line,close) $xth(me,cmds,$id,close)

    xth_me_prev_cmd $xth(me,cmds,$id,data)

    catch {$xth(me,can) raise lnln$id line}
    catch {$xth(me,can) raise lnpt$id point}
    
  } else {
  
    set xth(ctrl,me,line,name) {}
    set xth(ctrl,me,line,reverse) 0
    set xth(ctrl,me,line,close) 0
    set xth(ctrl,me,line,type) $xth(me,dflt,line,type)
    set xth(ctrl,me,line,opts) $xth(me,dflt,line,options)

    $xth(ctrl,me,line).typl configure -state disabled    
    $xth(ctrl,me,line).typ configure -state disabled    
    $xth(ctrl,me,line).namel configure -state disabled    
    $xth(ctrl,me,line).name configure -state disabled    
    $xth(ctrl,me,line).optl configure -state disabled    
    $xth(ctrl,me,line).opt configure -state disabled    
    $xth(ctrl,me,line).rev configure -state disabled    
    $xth(ctrl,me,line).cls configure -state disabled    
#    $xth(ctrl,me,line).insp configure -state disabled    
#    $xth(ctrl,me,line).delp configure -state disabled    
    $xth(ctrl,me,line).lpa configure -state disabled    
    $xth(ctrl,me,line).upd configure -state disabled
    $xth(ctrl,me,line).lpa.m entryconfigure [mc "Insert point"] -state disabled
    $xth(ctrl,me,line).lpa.m entryconfigure [mc "Delete point"] -state disabled   
    $xth(ctrl,me,line).pl.l configure -takefocus 0 \
      -listvariable xth(ctrl,me,line,empty)
    $xth(ctrl,me,line).pl.l selection clear 0 end
      
  }
  
}



proc xth_me_cmds_update_area_ctrl {id} {

  global xth
  
  if {[string length $id] > 0} {

    $xth(ctrl,me,ac).typl configure -state normal    
    $xth(ctrl,me,ac).typ configure -state normal    
    $xth(ctrl,me,ac).optl configure -state normal    
    $xth(ctrl,me,ac).opt configure -state normal    
    $xth(ctrl,me,ac).ins configure -state normal    
    $xth(ctrl,me,ac).del configure -state normal    
    $xth(ctrl,me,ac).insid configure -state normal    
    $xth(ctrl,me,ac).inside configure -state normal    
    $xth(ctrl,me,ac).upd configure -state normal    
    $xth(ctrl,me,ac).shw configure -state normal    
    $xth(ctrl,me,ac).ll.l configure -takefocus 1 \
      -listvariable xth(me,cmds,$id,llist)
    $xth(ctrl,me,ac).ll.l selection clear 0 end
    $xth(ctrl,me,ac).ll.l selection set end end
    $xth(ctrl,me,ac).ll.l see end
    
    set xth(ctrl,me,ac,type) $xth(me,cmds,$id,type)
    set xth(ctrl,me,ac,name) $xth(me,cmds,$id,name)
    set xth(ctrl,me,ac,opts) $xth(me,cmds,$id,options)
    set xth(ctrl,me,ac,insid) {}
    xth_me_prev_cmd $xth(me,cmds,$id,data)

  } else {
  
    set xth(ctrl,me,ac,name) {}
    set xth(ctrl,me,ac,insid) {}
    set xth(ctrl,me,ac,type) $xth(me,dflt,area,type)
    set xth(ctrl,me,ac,opts) $xth(me,dflt,area,options)

    $xth(ctrl,me,ac).typl configure -state disabled    
    $xth(ctrl,me,ac).typ configure -state disabled    
    $xth(ctrl,me,ac).optl configure -state disabled    
    $xth(ctrl,me,ac).opt configure -state disabled    
    $xth(ctrl,me,ac).ins configure -state disabled    
    $xth(ctrl,me,ac).del configure -state disabled    
    $xth(ctrl,me,ac).insid configure -state disabled    
    $xth(ctrl,me,ac).inside configure -state disabled    
    $xth(ctrl,me,ac).upd configure -state disabled    
    $xth(ctrl,me,ac).shw configure -state disabled    
    $xth(ctrl,me,ac).ll.l configure -takefocus 0 \
      -listvariable xth(ctrl,me,ac,empty)
    $xth(ctrl,me,ac).ll.l selection clear 0 end
      
  }
  
}



proc xth_me_cmds_move_lineptcp_xctrl {id ppid pid npid} {
  global xth
  
  set px [xth_me_real2canx $xth(me,cmds,$id,$pid,x)]
  set py [xth_me_real2cany $xth(me,cmds,$id,$pid,y)]
  
  if {$xth(me,cmds,$id,$pid,idp)} {
    set x [xth_me_real2canx $xth(me,cmds,$id,$pid,xp)]
    set y [xth_me_real2cany $xth(me,cmds,$id,$pid,yp)]
    $xth(me,can) coords $xth(me,canid,linept,pcp) [list \
      [expr $x - $xth(gui,me,line,cpsize)] \
      [expr $y - $xth(gui,me,line,cpsize)] \
      [expr $x + $xth(gui,me,line,cpsize)] \
      [expr $y + $xth(gui,me,line,cpsize)]]
    $xth(me,can) coords $xth(me,canid,linept,pcpl) $px $py $x $y
  }
  
  if {$xth(me,cmds,$id,$pid,idn)} {
    set x [xth_me_real2canx $xth(me,cmds,$id,$pid,xn)]
    set y [xth_me_real2cany $xth(me,cmds,$id,$pid,yn)]
    $xth(me,can) coords $xth(me,canid,linept,ncp) [list \
      [expr $x - $xth(gui,me,line,cpsize)] \
      [expr $y - $xth(gui,me,line,cpsize)] \
      [expr $x + $xth(gui,me,line,cpsize)] \
      [expr $y + $xth(gui,me,line,cpsize)]]
    $xth(me,can) coords $xth(me,canid,linept,ncpl) $px $py $x $y
  }

  if {($npid > 0) && $xth(me,cmds,$id,$npid,idp)} {
    set px [xth_me_real2canx $xth(me,cmds,$id,$npid,x)]
    set py [xth_me_real2cany $xth(me,cmds,$id,$npid,y)]
    set x [xth_me_real2canx $xth(me,cmds,$id,$npid,xp)]
    set y [xth_me_real2cany $xth(me,cmds,$id,$npid,yp)]
    $xth(me,can) coords $xth(me,canid,linept,nncp) [list \
      [expr $x - $xth(gui,me,line,cpsize)] \
      [expr $y - $xth(gui,me,line,cpsize)] \
      [expr $x + $xth(gui,me,line,cpsize)] \
      [expr $y + $xth(gui,me,line,cpsize)]]
    $xth(me,can) coords $xth(me,canid,linept,nncpl) $px $py $x $y
  }

  if {($ppid > 0) && $xth(me,cmds,$id,$ppid,idn)} {
    set px [xth_me_real2canx $xth(me,cmds,$id,$ppid,x)]
    set py [xth_me_real2cany $xth(me,cmds,$id,$ppid,y)]
    set x [xth_me_real2canx $xth(me,cmds,$id,$ppid,xn)]
    set y [xth_me_real2cany $xth(me,cmds,$id,$ppid,yn)]
    $xth(me,can) coords $xth(me,canid,linept,ppcp) [list \
      [expr $x - $xth(gui,me,line,cpsize)] \
      [expr $y - $xth(gui,me,line,cpsize)] \
      [expr $x + $xth(gui,me,line,cpsize)] \
      [expr $y + $xth(gui,me,line,cpsize)]]
    $xth(me,can) coords $xth(me,canid,linept,ppcpl) $px $py $x $y
  }

  xth_me_cmds_move_linept_size_xctrl $id $pid $xth(me,cmds,$id,$pid,rotation) \
    $xth(me,cmds,$id,$pid,rs) $xth(me,cmds,$id,$pid,ls)
  xth_me_cmds_move_line_xctrl $id
}


proc xth_me_cmds_move_linept_xctrl {id pid} {
  global xth
  set x [xth_me_real2canx $xth(me,cmds,$id,$pid,x)]
  set y [xth_me_real2cany $xth(me,cmds,$id,$pid,y)]
  $xth(me,can) coords $xth(me,canid,linept,selector) [list \
    [expr $x - 3 * $xth(gui,me,line,psize)] \
    [expr $y - 3 * $xth(gui,me,line,psize)] \
    [expr $x + 3 * $xth(gui,me,line,psize)] \
    [expr $y + 3 * $xth(gui,me,line,psize)]]
}


proc xth_me_cmds_move_line_xctrl {id} {
  global xth
  set pid [lindex $xth(me,cmds,$id,xplist) 0]
  set rot [xth_me_cmds_get_default_rotation $id $pid]
  if {$xth(me,cmds,$id,reverse)} {
    set rot [expr $rot + 180.0]
  }
  set x [xth_me_real2canx $xth(me,cmds,$id,$pid,x)]
  set y [xth_me_real2cany $xth(me,cmds,$id,$pid,y)]
  $xth(me,can) coords $xth(me,canid,line,tick) [list $x $y \
      [expr $x + sin($rot/180.0*3.14159265259) * $xth(gui,me,line,ticksize)] \
      [expr $y - cos($rot/180.0*3.14159265259) * $xth(gui,me,line,ticksize)]]
}


proc xth_me_cmds_show_line_xctrl {id} {
  global xth
  if {[llength $xth(me,cmds,$id,xplist)] < 3} {
    xth_me_cmds_hide_line_xctrl    
    return
  }
  xth_me_cmds_move_line_xctrl $id
  $xth(me,can) itemconfigure entirelinectrl -state normal
  $xth(me,can) raise entirelinectrl
  $xth(me,can) lower entirelinectrl point
}

proc xth_me_cmds_hide_line_xctrl {} {
  global xth
  $xth(me,can) itemconfigure entirelinectrl -state hidden
}

proc xth_me_cmds_show_linept_xctrl {id pid} {
  global xth
  set x [xth_me_real2canx $xth(me,cmds,$id,$pid,x)]
  set y [xth_me_real2cany $xth(me,cmds,$id,$pid,y)]
  set xl $xth(me,cmds,$id,xplist)
  $xth(me,can) raise linectrl
  $xth(me,can) lower linectrl point

  $xth(me,can) itemconfigure $xth(me,canid,linept,selector) -state normal
  xth_me_cmds_move_linept_xctrl $id $pid

  if {$xth(me,cmds,$id,$pid,idp)} {
    $xth(me,can) itemconfigure $xth(me,canid,linept,pcpl) -state normal
    $xth(me,can) itemconfigure $xth(me,canid,linept,pcp) -state normal
  } else {
    $xth(me,can) itemconfigure $xth(me,canid,linept,pcpl) -state hidden
    $xth(me,can) itemconfigure $xth(me,canid,linept,pcp) -state hidden
  }
  if {$xth(me,cmds,$id,$pid,idn)} {
    $xth(me,can) itemconfigure $xth(me,canid,linept,ncpl) -state normal
    $xth(me,can) itemconfigure $xth(me,canid,linept,ncp) -state normal
  } else {
    $xth(me,can) itemconfigure $xth(me,canid,linept,ncpl) -state hidden
    $xth(me,can) itemconfigure $xth(me,canid,linept,ncp) -state hidden
  }
  set ix [lsearch $xl $pid]
  set lix [expr [llength $xl] - 2]
  if {$ix > 0} {
    set ppid [lindex $xl [expr $ix - 1]]
  } elseif {$xth(me,cmds,$id,close) && ($lix > 0)} {
    set ppid [lindex $xl [expr $lix - 1]]
  } else {
    set ppid 0
  }
  if {$ix < $lix} {
    set npid [lindex $xl [expr $ix + 1]]
  } elseif {$xth(me,cmds,$id,close) && ($lix > 0)} {
    set npid [lindex $xl 1]
  } else {
    set npid 0
  }
  if {($npid > 0) && $xth(me,cmds,$id,$npid,idp)} {
    $xth(me,can) itemconfigure $xth(me,canid,linept,nncpl) -state normal
    $xth(me,can) itemconfigure $xth(me,canid,linept,nncp) -state normal
  } else {
    $xth(me,can) itemconfigure $xth(me,canid,linept,nncpl) -state hidden
    $xth(me,can) itemconfigure $xth(me,canid,linept,nncp) -state hidden
  }
  if {($ppid > 0) && $xth(me,cmds,$id,$ppid,idn)} {
    $xth(me,can) itemconfigure $xth(me,canid,linept,ppcpl) -state normal
    $xth(me,can) itemconfigure $xth(me,canid,linept,ppcp) -state normal
  } else {
    $xth(me,can) itemconfigure $xth(me,canid,linept,ppcpl) -state hidden
    $xth(me,can) itemconfigure $xth(me,canid,linept,ppcp) -state hidden
  }
  xth_me_cmds_move_lineptcp_xctrl $id $ppid $pid $npid
  $xth(me,can) raise pt$id.$pid
  $xth(me,can) bind $xth(me,canid,linept,pcp) <Enter> \
    "$xth(me,can) itemconfigure $xth(me,canid,linept,pcp) -fill yellow"
  $xth(me,can) bind $xth(me,canid,linept,pcp) <Leave> \
    "$xth(me,can) itemconfigure $xth(me,canid,linept,pcp) -fill red"
  $xth(me,can) bind $xth(me,canid,linept,pcp) <1> \
    "xth_me_cmds_start_linecp_drag $xth(me,canid,linept,pcp) $id $ppid $pid $npid p %x %y"
  $xth(me,can) bind $xth(me,canid,linept,ncp) <Enter> \
    "$xth(me,can) itemconfigure $xth(me,canid,linept,ncp) -fill yellow"
  $xth(me,can) bind $xth(me,canid,linept,ncp) <Leave> \
    "$xth(me,can) itemconfigure $xth(me,canid,linept,ncp) -fill red"
  $xth(me,can) bind $xth(me,canid,linept,ncp) <1> \
    "xth_me_cmds_start_linecp_drag $xth(me,canid,linept,ncp) $id $ppid $pid $npid n %x %y"
  $xth(me,can) bind $xth(me,canid,linept,ppcp) <Enter> \
    "$xth(me,can) itemconfigure $xth(me,canid,linept,ppcp) -fill yellow"
  $xth(me,can) bind $xth(me,canid,linept,ppcp) <Leave> \
    "$xth(me,can) itemconfigure $xth(me,canid,linept,ppcp) -fill magenta"
  $xth(me,can) bind $xth(me,canid,linept,ppcp) <1> \
    "xth_me_cmds_start_linecp_drag $xth(me,canid,linept,ppcp) $id $ppid $pid $npid pp %x %y"
  $xth(me,can) bind $xth(me,canid,linept,nncp) <Enter> \
    "$xth(me,can) itemconfigure $xth(me,canid,linept,nncp) -fill yellow"
  $xth(me,can) bind $xth(me,canid,linept,nncp) <Leave> \
    "$xth(me,can) itemconfigure $xth(me,canid,linept,nncp) -fill magenta"
  $xth(me,can) bind $xth(me,canid,linept,nncp) <1> \
    "xth_me_cmds_start_linecp_drag $xth(me,canid,linept,nncp) $id $ppid $pid $npid nn %x %y"
    
  xth_me_cmds_configure_linept_size_xctrl $id $pid
  xth_me_cmds_move_linept_size_xctrl $id $pid $xth(me,cmds,$id,$pid,rotation) \
    $xth(me,cmds,$id,$pid,rs) $xth(me,cmds,$id,$pid,ls)
  xth_me_cmds_move_line_xctrl $id
    
}


proc xth_me_cmds_hide_linept_xctrl {} {
  global xth
  $xth(me,can) itemconfigure linectrl -state hidden
  $xth(me,can) bind $xth(me,canid,linept,pcp) <Enter> ""
  $xth(me,can) bind $xth(me,canid,linept,pcp) <Leave> ""
  $xth(me,can) bind $xth(me,canid,linept,ncp) <Enter> ""
  $xth(me,can) bind $xth(me,canid,linept,ncp) <Leave> ""
  $xth(me,can) bind $xth(me,canid,linept,ppcp) <Enter> ""
  $xth(me,can) bind $xth(me,canid,linept,ppcp) <Leave> ""
  $xth(me,can) bind $xth(me,canid,linept,nncp) <Enter> ""
  $xth(me,can) bind $xth(me,canid,linept,nncp) <Leave> ""
  $xth(me,can) bind $xth(me,canid,linept,pcp) <1> ""
  $xth(me,can) bind $xth(me,canid,linept,ncp) <1> ""
  $xth(me,can) bind $xth(me,canid,linept,ppcp) <1> ""
  $xth(me,can) bind $xth(me,canid,linept,nncp) <1> ""
  xth_me_cmds_configure_linept_size_xctrl {} 0
}

proc xth_me_cmds_update_linept_ctrl {id pid} {

  global xth
  
  if {[string length $id] > 0} {
    xth_me_cmds_show_line_xctrl $id
  } else {
    xth_me_cmds_hide_line_xctrl
  }

  if {([string length $id] > 0) && ($pid > 0)} {

    $xth(ctrl,me,linept).posl configure -state normal
    $xth(ctrl,me,linept).posx configure -state normal
    $xth(ctrl,me,linept).posy configure -state normal
    $xth(ctrl,me,linept).xp configure -state normal
    $xth(ctrl,me,linept).yp configure -state normal
    $xth(ctrl,me,linept).xn configure -state normal
    $xth(ctrl,me,linept).yn configure -state normal
    $xth(ctrl,me,linept).cbp configure -state normal
    $xth(ctrl,me,linept).cbn configure -state normal
    $xth(ctrl,me,linept).cbs configure -state normal
    $xth(ctrl,me,linept).rotc configure -state normal
    $xth(ctrl,me,linept).rot configure -state normal
    $xth(ctrl,me,linept).rszc configure -state normal
    $xth(ctrl,me,linept).rsz configure -state normal
    $xth(ctrl,me,linept).lszc configure -state normal
    $xth(ctrl,me,linept).lsz configure -state normal
    $xth(ctrl,me,linept).optl configure -state normal
    $xth(ctrl,me,linept).upd configure -state normal

    $xth(ctrl,me,line).lpa.m entryconfigure [mc "Delete point"] -state normal    
    set xpid [lsearch -exact $xth(me,cmds,$id,xplist) $pid]
    if {($xpid > 0) && ($xpid < ([llength $xth(me,cmds,$id,xplist)] - 2))} {
      $xth(ctrl,me,line).lpa.m entryconfigure [mc "Split line"] -state normal
    } else {
      $xth(ctrl,me,line).lpa.m entryconfigure [mc "Split line"] -state disabled
    }

    $xth(ctrl,me,linept).oe.txt configure -state normal
    $xth(ctrl,me,linept).oe.txt delete 1.0 end
    $xth(ctrl,me,linept).oe.txt insert 1.0 $xth(me,cmds,$id,$pid,options)
    $xth(ctrl,me,linept).oe.txt mark set insert $xth(me,cmds,$id,$pid,optpos)
    $xth(ctrl,me,linept).oe.txt see $xth(me,cmds,$id,$pid,optpos)
    
    set xth(ctrl,me,linept,x) $xth(me,cmds,$id,$pid,x)
    set xth(ctrl,me,linept,y) $xth(me,cmds,$id,$pid,y)
    set xth(ctrl,me,linept,idn) $xth(me,cmds,$id,$pid,idn)
    set xth(ctrl,me,linept,idp) $xth(me,cmds,$id,$pid,idp)
    
    if $xth(me,cmds,$id,$pid,idp) {
      set xth(ctrl,me,linept,xp) $xth(me,cmds,$id,$pid,xp)
      set xth(ctrl,me,linept,yp) $xth(me,cmds,$id,$pid,yp)
    } else {
      set xth(ctrl,me,linept,xp) {}
      set xth(ctrl,me,linept,yp) {}
    }
    if $xth(me,cmds,$id,$pid,idn) {
      set xth(ctrl,me,linept,xn) $xth(me,cmds,$id,$pid,xn)
      set xth(ctrl,me,linept,yn) $xth(me,cmds,$id,$pid,yn)
    } else {
      set xth(ctrl,me,linept,xn) {}
      set xth(ctrl,me,linept,yn) {}
    }    
    set xth(ctrl,me,linept,smooth) $xth(me,cmds,$id,$pid,smooth)
    set xth(ctrl,me,linept,rot) $xth(me,cmds,$id,$pid,rotation)
    if {[string length $xth(me,cmds,$id,$pid,rotation)] > 0} {
      set xth(ctrl,me,linept,rotid) 1
    } else {
      set xth(ctrl,me,linept,rotid) 0
    }

    set xth(ctrl,me,linept,rs) $xth(me,cmds,$id,$pid,rs)
    if {[string length $xth(me,cmds,$id,$pid,rs)] > 0} {
      set xth(ctrl,me,linept,rsid) 1
    } else {
      set xth(ctrl,me,linept,rsid) 0
    }

    set xth(ctrl,me,linept,ls) $xth(me,cmds,$id,$pid,ls)
    if {[string length $xth(me,cmds,$id,$pid,ls)] > 0} {
      set xth(ctrl,me,linept,lsid) 1
    } else {
      set xth(ctrl,me,linept,lsid) 0
    }
    
    xth_me_cmds_show_linept_xctrl $id $pid
    
  } else {

    set xth(ctrl,me,linept,x) {}
    set xth(ctrl,me,linept,y) {}
    set xth(ctrl,me,linept,xp) {}
    set xth(ctrl,me,linept,yp) {}
    set xth(ctrl,me,linept,xn) {}
    set xth(ctrl,me,linept,yn) {}
    set xth(ctrl,me,linept,idn) 0
    set xth(ctrl,me,linept,idp) 0
    set xth(ctrl,me,linept,smooth) 0
    set xth(ctrl,me,linept,rot) {}
    set xth(ctrl,me,linept,rotid) 0
    set xth(ctrl,me,linept,rs) {}
    set xth(ctrl,me,linept,rsid) 0
    set xth(ctrl,me,linept,ls) {}
    set xth(ctrl,me,linept,lsid) 0

    $xth(ctrl,me,linept).posl configure -state disabled
    $xth(ctrl,me,linept).posx configure -state disabled
    $xth(ctrl,me,linept).posy configure -state disabled
    $xth(ctrl,me,linept).xp configure -state disabled
    $xth(ctrl,me,linept).upd configure -state disabled
    $xth(ctrl,me,linept).yp configure -state disabled
    $xth(ctrl,me,linept).xn configure -state disabled
    $xth(ctrl,me,linept).yn configure -state disabled
    $xth(ctrl,me,linept).cbp configure -state disabled
    $xth(ctrl,me,linept).cbn configure -state disabled
    $xth(ctrl,me,linept).cbs configure -state disabled
    $xth(ctrl,me,linept).rotc configure -state disabled
    $xth(ctrl,me,linept).rot configure -state disabled
    $xth(ctrl,me,linept).rszc configure -state disabled
    $xth(ctrl,me,linept).rsz configure -state disabled
    $xth(ctrl,me,linept).lszc configure -state disabled
    $xth(ctrl,me,linept).lsz configure -state disabled
    $xth(ctrl,me,linept).optl configure -state disabled
    $xth(ctrl,me,linept).oe.txt configure -state normal
    $xth(ctrl,me,linept).oe.txt delete 1.0 end
    $xth(ctrl,me,linept).oe.txt see 1.0
    $xth(ctrl,me,linept).oe.txt configure -state disabled

    $xth(ctrl,me,line).lpa.m entryconfigure [mc "Delete point"] -state disabled
    $xth(ctrl,me,line).lpa.m entryconfigure [mc "Split line"] -state disabled
    
    xth_me_cmds_hide_linept_xctrl  
    
  }
  
}


proc xth_me_cmds_delete_linept {id pid} {

  global xth
  
  if {[string length $id] < 1} {
    set id $xth(me,cmds,selid)
  }
  if {[string length $pid] < 1} {
    set pid $xth(me,cmds,selpid)
  }
  if {$pid == 0} {
    return
  }

  set oldselpid $xth(me,cmds,selpid)
  if {$xth(me,unredook)} {
    xth_me_cmds_update {}
  }
  
  # ak mazeme prvy alebo posledny, tak zrusime close ak je nastaveny
  set closerem 0
  if {$xth(me,cmds,$id,close) && ([llength $xth(me,cmds,$id,xplist)] > 2)} {
    set fpid [lindex $xth(me,cmds,$id,xplist) 0]
    set lpid [lindex $xth(me,cmds,$id,xplist) [expr [llength $xth(me,cmds,$id,xplist)] - 2]]
    if {$pid == $fpid} {
      set closerem 1
    } elseif {$pid == $lpid} {
      set closerem 1
    }
  }
  
  if {$closerem} {
    set closeremstr "set xth(me,cmds,$id,close) 0\nxth_me_cmds_update_line_vars $id $pid"
    set closeaddstr "set xth(me,cmds,$id,close) 1\nxth_me_cmds_update_line_vars $id $pid"
  } else {
    set closeremstr {}
    set closeaddstr {}
  }
  
  eval $closeremstr
  
  # odstrani ho zo zoznamu
  set ix [lsearch $xth(me,cmds,$id,xplist) $pid]
  set xth(me,cmds,$id,xplist) [lreplace $xth(me,cmds,$id,xplist) $ix $ix]
  set xth(me,cmds,$id,plist) [lreplace $xth(me,cmds,$id,plist) $ix $ix]
  $xth(me,can) delete pt$id.$pid
  $xth(me,can) delete ln$id.$pid
  xth_me_cmds_move_line $id
  if {$oldselpid == $pid} {
    set nwpid [lindex $xth(me,cmds,$id,xplist) $ix]
  } else {
    set nwpid $oldselpid
  }
  xth_me_cmds_update_line_data $id
  xth_me_prev_cmd $xth(me,cmds,$id,data)
  
  # BUG FIX when deleting last point
  if {$nwpid == 0} {
    set xth(me,cmds,selpid) $nwpid
  }
  xth_me_cmds_select_linept $id $nwpid
    
  xth_me_unredo_action [mc "deleting line point"] \
    "xth_me_cmds_undelete_linept $id $pid $ix\n$closeaddstr" \
    "$closeremstr\nxth_me_cmds_delete_linept $id $pid"
  
}


proc xth_me_cmds_undelete_linept {id pid ix} {
  global xth
  set oldpid [lindex $xth(me,cmds,$id,xplist) $ix]
  set xth(me,cmds,$id,xplist) [linsert $xth(me,cmds,$id,xplist) $ix $pid]
  set xth(me,cmds,$id,plist) [linsert $xth(me,cmds,$id,plist) $ix {}]
  xth_me_cmds_update_linept_list $id $pid
  if {$ix > 0} {
    set ppid [lindex $xth(me,cmds,$id,xplist) [expr $ix - 1]]
  } else {
    set ppid 0
  }
  xth_me_cmds_draw_linept $id $pid
  xth_me_cmds_draw_lineln $id $ppid $pid 
  xth_me_cmds_move_line $id
  xth_me_cmds_update_line_data $id
  xth_me_prev_cmd $xth(me,cmds,$id,data)
  xth_me_cmds_select_linept $id $pid
  
}


proc xth_me_cmds_create_line_point {id ix mode x y xp yp xn yn smooth rot rs ls opts optpos} {

  global xth
  
  incr xth(me,cmds,$id,lpid)
  set pid $xth(me,cmds,$id,lpid)
  set xth(me,cmds,$id,$pid,x) [expr double($x)]
  set xth(me,cmds,$id,$pid,y) [expr double($y)]

  if {([string length $xp] > 0) && ((![string equal $xp $x]) || (![string equal $yp $y]))} {
    set xth(me,cmds,$id,$pid,xp) [expr double($xp)]
    set xth(me,cmds,$id,$pid,yp) [expr double($yp)]
    set xth(me,cmds,$id,$pid,idp) 1
  } else {
    set xth(me,cmds,$id,$pid,xp) {}
    set xth(me,cmds,$id,$pid,yp) {}
    set xth(me,cmds,$id,$pid,idp) 0
  }
  
  if {([string length $xn] > 0) && ((![string equal $xn $x]) || (![string equal $yn $y]))} {
    set xth(me,cmds,$id,$pid,xn) [expr double($xn)]
    set xth(me,cmds,$id,$pid,yn) [expr double($yn)]
    set xth(me,cmds,$id,$pid,idn) 1
  } else {
    set xth(me,cmds,$id,$pid,xn) {}
    set xth(me,cmds,$id,$pid,yn) {}
    set xth(me,cmds,$id,$pid,idn) 0
  }
  
  if {[string length $smooth] < 1} {
    set xth(me,cmds,$id,$pid,smooth) -1
  } else {
    set xth(me,cmds,$id,$pid,smooth) $smooth
  }
  
  if {[string length $rot] > 0} {
    set rot [expr double($rot)]
  }
  set xth(me,cmds,$id,$pid,rotation) $rot

  if {[string length $ls] > 0} {
    set ls [expr double($ls)]
  }
  set xth(me,cmds,$id,$pid,ls) $ls

  if {[string length $rs] > 0} {
    set rs [expr double($rs)]
  }
  set xth(me,cmds,$id,$pid,rs) $rs
  
  regsub {\s*$} $opts "" opts
  if {[string length $opts] > 0} {
    regsub {$} $opts "\n" opts
  }
  set xth(me,cmds,$id,$pid,options) $opts
  set xth(me,cmds,$id,$pid,optpos) $optpos
  
  # vlozi ho do zoznamu
  set xth(me,cmds,$id,plist) [linsert $xth(me,cmds,$id,plist) $ix {}]
  set xth(me,cmds,$id,xplist) [linsert $xth(me,cmds,$id,xplist) $ix $pid]
  xth_me_cmds_update_linept_list $id $pid
  
  # vytvori ho
  if {$ix > 0} {
    set ppid [lindex $xth(me,cmds,$id,xplist) [expr $ix - 1]]
  } else {
    set ppid 0
  }
  xth_me_cmds_draw_lineln $id $ppid $pid
  xth_me_cmds_draw_linept $id $pid
  
}



proc xth_me_cmds_create_area_line {id ix mode txt} {

  global xth
  incr xth(me,cmds,$id,llid)
  set lid $xth(me,cmds,$id,llid)
  regsub {\s*$} $txt "" txt
  regsub {^\s*} $txt "" txt
  set xth(me,cmds,$id,$lid,txt) $txt
  # vlozi ho do zoznamu
  set xth(me,cmds,$id,llist) [linsert $xth(me,cmds,$id,llist) $ix $txt]
  set xth(me,cmds,$id,xllist) [linsert $xth(me,cmds,$id,xllist) $ix $lid]
  
}


proc xth_me_cmds_insert_area_lineid {id mx my} {
  global xth
  if {$xth(me,unredook)} {
    xth_me_cmds_update {}
  }
  if {[string length $xth(me,cmds,$id,name)] == 0} {
    set nn [format "l%d-%.0f-%.0f" $id [xth_me_can2realx [$xth(me,can) canvasx $mx]] [xth_me_can2realy [$xth(me,can) canvasy $my]]]
    set unspec "set xth(me,cmds,$id,name) {}\nxth_me_cmds_update_line_data $id\nxth_me_cmds_update_list $id"
    set respec "set xth(me,cmds,$id,name) [list $nn]\nxth_me_cmds_update_line_data $id\nxth_me_cmds_update_list $id"
    eval $respec
  } else {
    set nn $xth(me,cmds,$id,name)
    set unspec {}
    set respec {}
  }    
  xth_me_cmds_insert_area_line $nn $unspec $respec
}


proc xth_me_cmds_insert_area_line {txt unspec respec} {

  global xth
  if {$xth(me,unredook)} {
    xth_me_cmds_update {}
  }
  regsub {\s*$} $txt "" txt
  regsub {^\s*} $txt "" txt  
  if {[string length $txt] == 0} {
    return;
  }
  set id $xth(me,cmds,selid)
  set lid [lindex $xth(me,cmds,$id,xllist) [$xth(ctrl,me,ac).ll.l curselection]]
  set ix [lsearch $xth(me,cmds,$id,xllist) $lid]
  xth_me_cmds_create_area_line $id $ix 1 $txt
  set lid $xth(me,cmds,$id,llid)
  xth_me_cmds_update_area_data $id
  xth_me_prev_cmd $xth(me,cmds,$id,data)
  $xth(ctrl,me,ac).ll.l selection clear 0 end
  $xth(ctrl,me,ac).ll.l selection set [expr $ix + 1] [expr $ix + 1]
  $xth(ctrl,me,ac).ll.l see [expr $ix + 1]

  xth_me_unredo_action [mc "inserting area border"] \
    "xth_me_cmds_select $id\nxth_me_cmds_delete_area_line $id $lid\n$unspec" \
    "xth_me_cmds_select $id\n$respec\nxth_me_cmds_undelete_area_line 1 $id $lid $ix"
      
}


proc xth_me_cmds_delete_area_line {id lid} {

  global xth
  
  if {[string length $id] < 1} {
    set id $xth(me,cmds,selid)
  }
  if {[string length $lid] < 1} {
    set lid [lindex $xth(me,cmds,$id,xllist) [$xth(ctrl,me,ac).ll.l curselection]]
  }
  if {$lid == 0} {
    return
  }

  if {$xth(me,unredook)} {
    xth_me_cmds_update {}
  }
  
  # odstrani ho zo zoznamu
  set ix [lsearch $xth(me,cmds,$id,xllist) $lid]
  set xth(me,cmds,$id,xllist) [lreplace $xth(me,cmds,$id,xllist) $ix $ix]
  set xth(me,cmds,$id,llist) [lreplace $xth(me,cmds,$id,llist) $ix $ix]
  xth_me_cmds_update_area_data $id
  xth_me_prev_cmd $xth(me,cmds,$id,data)
  $xth(ctrl,me,ac).ll.l selection clear 0 end
  $xth(ctrl,me,ac).ll.l selection set $ix $ix
  $xth(ctrl,me,ac).ll.l see $ix
    
  xth_me_unredo_action [mc "deleting area border"] \
    "xth_me_cmds_undelete_area_line 0 $id $lid $ix" \
    "xth_me_cmds_delete_area_line $id $lid"
  
}


proc xth_me_cmds_undelete_area_line {cr id lid ix} {

  global xth
  set xth(me,cmds,$id,xllist) [linsert $xth(me,cmds,$id,xllist) $ix $lid]
  set xth(me,cmds,$id,llist) [linsert $xth(me,cmds,$id,llist) $ix $xth(me,cmds,$id,$lid,txt)]
  xth_me_cmds_update_area_data $id
  xth_me_prev_cmd $xth(me,cmds,$id,data)
  $xth(ctrl,me,ac).ll.l selection clear 0 end
  $xth(ctrl,me,ac).ll.l selection set [expr $ix + $cr] [expr $ix + $cr]
  $xth(ctrl,me,ac).ll.l see [expr $ix + $cr]
  
}



proc xth_me_cmds_create_area {ix mode type opts lines} {

  global xth
  if {$mode} {
    xth_me_cmds_update {}
  }
  set id [xth_me_cmds_create 6 {} $ix]
  set xth(me,cmds,$id,llid) 0
  set xth(me,cmds,$id,llist) {"end of area"}
  set xth(me,cmds,$id,xllist) {0}

  if {$mode && ([string length $opts] < 1)} {
    set opts $xth(me,dflt,area,options)
  }

  if {[string length $type] > 0} {
    set xth(me,cmds,$id,type) $type
  } else {
    set xth(me,cmds,$id,type) $xth(me,dflt,area,type)
  }  

  foreach ln $lines {
    xth_me_cmds_create_area_line $id \
          [expr [llength $xth(me,cmds,$id,xllist)] - 1] $mode $ln
  }
  
  # nastavit options
  regsub {^\s*} $opts "" opts
  regsub {\s*$} $opts "" opts
  set xth(me,cmds,$id,options) $opts

  xth_me_cmds_update_list $id
  xth_me_cmds_update_area_data $id
  if {$mode} {
    xth_me_unredo_action [mc "creating area"] \
      "xth_me_cmds_delete $id\nxth_me_cmds_set_mode 0" \
      "xth_me_cmds_undelete $id 0 [lsearch $xth(me,cmds,xlist) $id]\nxth_me_cmds_set_mode 3"  
    xth_me_cmds_select $id
    xth_me_cmds_start_area_insert 0
  }


}




proc xth_me_cmds_create_line {ix mode type opts lines} {

  global xth
  if {$mode} {
    xth_me_cmds_update {}
  }
  set id [xth_me_cmds_create 3 {} $ix]
  set xth(me,cmds,$id,lpid) 0
  set xth(me,cmds,$id,plist) {"end of line"}
  set xth(me,cmds,$id,xplist) {0}

  if {$mode && ([string length $opts] < 1)} {
    set opts $xth(me,dflt,line,options)
  }

  if {[string length $type] > 0} {
    set xth(me,cmds,$id,type) $type
  } else {
    set xth(me,cmds,$id,type) $xth(me,dflt,line,type)
  }
  
  # nastavit meno
  set optl [xth_me_cmds_get_line_option $opts id]
  if {[lindex $optl 2]} {
    set xth(me,cmds,$id,name) [lindex $optl 0]
    set opts [lindex $optl 1]
  }
  # prejde vsetky riadky a pohlada meno tam
  set newlines {}
  foreach ln $lines {
    set optl [xth_me_cmds_get_option $ln id]
    if {[lindex $optl 2]} {
      set xth(me,cmds,$id,name) [lindex $optl 0]
      set ln [lindex $optl 1]
      if {[string length $ln] > 0} {
        lappend newlines $ln
      }
    } else {
      lappend newlines $ln
    }
  }
  set lines $newlines
  
  # nastavit reversion
  set xth(me,cmds,$id,reverse) 0
  set optl [xth_me_cmds_get_line_option $opts reverse]
  if {[lindex $optl 2]} {
    #puts ">>$opts<< = >>$optl<<"
    set xth(me,cmds,$id,reverse) [xth_me_cmds_get_bool [lindex $optl 0]]
    set opts [lindex $optl 1]
    #puts "$xth(me,cmds,$id,reverse) >>$opts<<"
  }
  # prejde vsetky riadky a pohlada reverse tam
  set newlines {}
  foreach ln $lines {
    set optl [xth_me_cmds_get_option $ln reverse]
    if {[lindex $optl 2]} {
      set xth(me,cmds,$id,reverse) [xth_me_cmds_get_bool [lindex $optl 0]]
      set ln [lindex $optl 1]
      if {[string length $ln] > 0} {
        lappend newlines $ln
      }
    } else {
      lappend newlines $ln
    }
  }
  set lines $newlines
  
  # nastavit close
  set xth(me,cmds,$id,close) -1
  set optl [xth_me_cmds_get_line_option $opts close]
  if {[lindex $optl 2]} {
    set xth(me,cmds,$id,close) [xth_me_cmds_get_onoffauto [lindex $optl 0]]
    set opts [lindex $optl 1]
  }
  # prejde vsetky riadky a pohlada reverse tam
  set newlines {}
  foreach ln $lines {
    set optl [xth_me_cmds_get_option $ln close]
    if {[lindex $optl 2]} {
      set xth(me,cmds,$id,close) [xth_me_cmds_get_onoffauto [lindex $optl 0]]
      set ln [lindex $optl 1]
      if {[string length $ln] > 0} {
        lappend newlines $ln
      }
    } else {
      lappend newlines $ln
    }
  }
  set lines $newlines
  
  # nastavit options
  regsub {^\s*} $opts "" opts
  regsub {\s*$} $opts "" opts
  set xth(me,cmds,$id,options) $opts

  # vlozi body
  set has_some 0
  set opts {}
  set rsz {}
  set lsz {}
  set smth {}
  set rot {}
  foreach ln $lines {
    set what 0
    set cmt 0
    if {[regexp {^\s*\!?\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s*(\#.*)?$} \
          $ln dum x1 y1 x2 y2 x y cmt] && (![catch {expr $x * $y * $x1 * $y1 * $x2 * $y2}])} {
      set what 2
    } elseif {[regexp {^\s*\!?\s*(\S+)\s+(\S+)\s*(\#.*)?$} $ln dum x y cmt] && (![catch {expr $x * $y}])} {
      set x1 {}
      set y1 {}
      set x2 {}
      set y2 {}
      set what 1
    } elseif {$has_some} {
      # skusi jednotlive options rotation size r-size l-size smooth
      set cmt $ln
      set optl [xth_me_cmds_get_option $ln orientation]
      if {[lindex $optl 2]} {
        set rot [lindex $optl 0]
        set cmt [lindex $optl 1]
      } else {      
        set optl [xth_me_cmds_get_option $ln orient]
        if {[lindex $optl 2]} {
          set rot [lindex $optl 0]
          set cmt [lindex $optl 1]
        } else {
          set optl [xth_me_cmds_get_option $ln smooth]
          if {[lindex $optl 2]} {
            set smth [xth_me_cmds_get_onoffauto [lindex $optl 0]]
            set cmt [lindex $optl 1]
          } else {
            set optl [xth_me_cmds_get_option $ln size]
            if {[lindex $optl 2]} {
              switch $xth(me,cmds,$id,type) {
                slope {
                  set lsz [expr [lindex $optl 0]]
                }
                default {
                  set rsz [expr [lindex $optl 0] / 2.0]
                  set lsz [expr [lindex $optl 0] / 2.0]
                }
              }
              set cmt [lindex $optl 1]
            } else {
              set optl [xth_me_cmds_get_option $ln r-size]
              if {[lindex $optl 2]} {
                set rsz [lindex $optl 0]
                set cmt [lindex $optl 1]
              } else {
                set optl [xth_me_cmds_get_option $ln l-size]
                if {[lindex $optl 2]} {
                  set lsz [lindex $optl 0]
                  set cmt [lindex $optl 1]
                }
              }
            }
          }
        }
      }
      regsub {^\s*} $cmt {} cmt
    } else {
      regsub {^\s*} $ln {} ln
      set cmt $ln
    }
    if {$what == 0} {
      if {[string length $cmt] > 0} {
        if {[string length $opts] > 0} {
          set opts "$opts\n$cmt"
        } else {
          set opts "$cmt"
        }
      }
    } else {
      if {$has_some} {
        xth_me_cmds_create_line_point $id \
          [expr [llength $xth(me,cmds,$id,xplist)] - 1] $mode \
          $px $py $px2 $py2 $x1 $y1 $smth $rot $rsz $lsz $opts 1.0
        set opts {}
        set rsz {}
        set lsz {}
        set smth {}
        set rot {}
      }
      set has_some 1
      set px $x
      set py $y
      set px1 $x1
      set py1 $y1
      set px2 $x2
      set py2 $y2
    }
  }
  if {$has_some} {
    xth_me_cmds_create_line_point $id \
      [expr [llength $xth(me,cmds,$id,xplist)] - 1] $mode \
      $px $py $px2 $py2 {} {} $smth $rot $rsz $lsz $opts 1.0
  }

  if {$mode} {
    set xth(me,cmds,$id,close) 0
  } else {
    xth_me_cmds_postprocess_line $id
  }
  xth_me_cmds_update_list $id
  xth_me_cmds_update_line_data $id
  if {$mode} {
    xth_me_unredo_action [mc "creating line"] \
      "xth_me_cmds_delete $id\nxth_me_cmds_set_mode 0" \
      "xth_me_cmds_undelete $id 0 [lsearch $xth(me,cmds,xlist) $id]\nxth_me_cmds_set_mode 2"  
    xth_me_cmds_select $id
    xth_me_cmds_start_linept_insert
  }
}


proc xth_me_cmds_postprocess_line {id} {
  global xth
  set xl $xth(me,cmds,$id,xplist)
  set lix [expr [llength $xl] - 2]
  if {$lix < 0} {
    return
  }

  # overi uzavretie
  if {$xth(me,cmds,$id,close) != 0} {
      if {($xth(me,cmds,$id,[lindex $xl 0],x) == $xth(me,cmds,$id,[lindex $xl $lix],x)) && \
        ($xth(me,cmds,$id,[lindex $xl 0],y) == $xth(me,cmds,$id,[lindex $xl $lix],y)) && \
        ($lix > 0)} {
        set xth(me,cmds,$id,close) 1
      } else {
        set xth(me,cmds,$id,close) 0
      }
  }
  
  if {$xth(me,cmds,$id,close)} {
    set fid [lindex $xl 0]
    set lid [lindex $xl $lix]
    if {$xth(me,cmds,$id,$fid,idn)} {
      set xth(me,cmds,$id,$lid,idn) $xth(me,cmds,$id,$fid,idn)
      set xth(me,cmds,$id,$lid,xn) $xth(me,cmds,$id,$fid,xn)
      set xth(me,cmds,$id,$lid,yn) $xth(me,cmds,$id,$fid,yn)
    }
    if {$xth(me,cmds,$id,$lid,idp)} {
      set xth(me,cmds,$id,$fid,idp) $xth(me,cmds,$id,$lid,idp)
      set xth(me,cmds,$id,$fid,xp) $xth(me,cmds,$id,$lid,xp)
      set xth(me,cmds,$id,$fid,yp) $xth(me,cmds,$id,$lid,yp)
    }
  }

  # overi smoothness
  if {$lix == 0} {
    set pid [lindex $xth(me,cmds,$id,xplist) 0]
    if {($xth(me,cmds,$id,$pid,smooth) == -1) && \
        $xth(me,cmds,$id,$pid,idp) && \
        $xth(me,cmds,$id,$pid,idn)} {
      set xth(me,cmds,$id,$pid,smooth) [xth_me_cmds_are_smooth \
        $xth(me,cmds,$id,$pid,xp) $xth(me,cmds,$id,$pid,yp) \
        $xth(me,cmds,$id,$pid,x) $xth(me,cmds,$id,$pid,y) \
        $xth(me,cmds,$id,$pid,xn) $xth(me,cmds,$id,$pid,yn)]
    } elseif {$xth(me,cmds,$id,$pid,smooth) == -1} {
      set xth(me,cmds,$id,$pid,smooth) 0
    }
    return
  }
  
  # prejde vsetky body
  set lid [lindex $xl $lix]
  set fid [lindex $xl 0]
  set cls $xth(me,cmds,$id,close)
  for {set ix 0} {$ix <= $lix} {incr ix} {
    set pid [lindex $xl $ix]
    if {($ix == 0) && $cls} {
      set idp $xth(me,cmds,$id,$lid,idp)
    } else {
      set idp $xth(me,cmds,$id,$pid,idp)
    }
    if {($ix == $lix) && $cls} {
      set idn $xth(me,cmds,$id,$fid,idn)
    } else {
      set idn $xth(me,cmds,$id,$pid,idn)
    }
    if {$idn && $idp && ($xth(me,cmds,$id,$pid,smooth) == -1)} {
      set x $xth(me,cmds,$id,$pid,x)
      set y $xth(me,cmds,$id,$pid,y)
      if {($ix == 0) && $cls} {
        set xp $xth(me,cmds,$id,$lid,xp)
        set yp $xth(me,cmds,$id,$lid,yp)
      } else {
        set xp $xth(me,cmds,$id,$pid,xp)
        set yp $xth(me,cmds,$id,$pid,yp)
      }
      if {($ix == $lix) && $cls} {
        set xn $xth(me,cmds,$id,$fid,xn)
        set yn $xth(me,cmds,$id,$fid,yn)
      } else {
        set xn $xth(me,cmds,$id,$pid,xn)
        set yn $xth(me,cmds,$id,$pid,yn)
      }
      set xth(me,cmds,$id,$pid,smooth) [xth_me_cmds_are_smooth $xp $yp $x $y $xn $yn]
    } elseif {$xth(me,cmds,$id,$pid,smooth) == -1} {
      set xth(me,cmds,$id,$pid,smooth) 0
    }
  }
  
}


proc xth_me_cmds_update_area_data {id} {

  global xth
  set xl $xth(me,cmds,$id,xllist)
  set lix [expr [llength $xl] - 2]

  set d "area $xth(me,cmds,$id,type)"
  set xth(me,dflt,area,type) $xth(me,cmds,$id,type)

  # options
  if {[string length $xth(me,cmds,$id,options)] > 0} {
    set d "$d $xth(me,cmds,$id,options)"
  }
  set xth(me,dflt,area,options) $xth(me,cmds,$id,options)

  for {set ix 0} {$ix <= $lix} {incr ix} {
    set lid [lindex $xl $ix]
    set d "$d\n  $xth(me,cmds,$id,$lid,txt)"
  }

  set xth(me,cmds,$id,data) "$d\nendarea"
  
}



proc xth_me_cmds_update_line_data {id} {
  global xth
  set xl $xth(me,cmds,$id,xplist)
  set lix [expr [llength $xl] - 2]

  set d "line $xth(me,cmds,$id,type)"
  set xth(me,dflt,line,type) $xth(me,cmds,$id,type)

  # id
  if {[string length $xth(me,cmds,$id,name)] > 0} {
    set d "$d -id $xth(me,cmds,$id,name)"
  }
  
  if {$lix > -1} {
  
    # close
    if {$xth(me,cmds,$id,close)} {
      set d "$d -close on"
    } elseif {($xth(me,cmds,$id,[lindex $xl 0],x) == $xth(me,cmds,$id,[lindex $xl $lix],x)) && \
        ($xth(me,cmds,$id,[lindex $xl 0],y) == $xth(me,cmds,$id,[lindex $xl $lix],y))} {
      set d "$d -close off"
    }

    # reverse
    if {$xth(me,cmds,$id,reverse)} {
      set d "$d -reverse on"
    }
    
  }
  
  if {[string length $xth(me,cmds,$id,options)] > 0} {
    set d "$d $xth(me,cmds,$id,options)"
  }
  set xth(me,dflt,line,options) $xth(me,cmds,$id,options)
  
  set csbar $d
  
  set xth(me,cmds,$id,data_ln) "$d\nendline"
  set xth(me,cmds,$id,data_pt) {}
  
  for {set ix 0} {$ix <= $lix} {incr ix} {
    set cto 0
    set pid [lindex $xl $ix]
    if {$ix == 0} {
      set crd [format "  %s %s" $xth(me,cmds,$id,$pid,x) $xth(me,cmds,$id,$pid,y)]
    } else {
      if {$xth(me,cmds,$id,$pid,idp) || $xth(me,cmds,$id,$ppid,idn)} {
        if {$xth(me,cmds,$id,$ppid,idn)} {
          set x1 $xth(me,cmds,$id,$ppid,xn)
          set y1 $xth(me,cmds,$id,$ppid,yn)
        } else {
          set x1 $xth(me,cmds,$id,$ppid,x)
          set y1 $xth(me,cmds,$id,$ppid,y)
        }
        if {$xth(me,cmds,$id,$pid,idp)} {
          set x2 $xth(me,cmds,$id,$pid,xp)
          set y2 $xth(me,cmds,$id,$pid,yp)
        } else {
          set x2 $xth(me,cmds,$id,$pid,x)
          set y2 $xth(me,cmds,$id,$pid,y)
        }
        set crd [format "  %s %s %s %s" $x1 $y1 $x2 $y2]
        set cto 1
      } else {
        set crd " "
      }
      set crd "$crd [format "%s %s" $xth(me,cmds,$id,$pid,x) $xth(me,cmds,$id,$pid,y)]"
    }
    set ptd "$crd"
    # rotation lsize rsize smooth options
    if {[string length $xth(me,cmds,$id,$pid,rotation)] > 0} {
      set ptd "$ptd\n  orientation $xth(me,cmds,$id,$pid,rotation)"
    }

    if {$cto && (! $xth(me,cmds,$id,$pid,smooth))} {
      set ptd "$ptd\n  smooth off"
    }
    
    if {[string length $xth(me,cmds,$id,$pid,ls)] > 0} {
      set ptd "$ptd\n  l-size $xth(me,cmds,$id,$pid,ls)"
    }

    if {[string length $xth(me,cmds,$id,$pid,rs)] > 0} {
      set ptd "$ptd\n  r-size $xth(me,cmds,$id,$pid,rs)"
    }
    
    if {[string length $xth(me,cmds,$id,$pid,options)] > 0} {
      set popts $xth(me,cmds,$id,$pid,options)
      regsub {\s*$} $popts {} popts
      if {[string length $popts] > 0} {
        regsub -all -line {^\s*} $popts {  } popts
      }
      set ptd "$ptd\n$popts"
    }
    
    lappend xth(me,cmds,$id,data_pt) $ptd
    
    set d "$d\n$ptd"
    set ppid $pid
  }

  set xth(me,cmds,$id,data) "$d\nendline"
  set xth(me,cmds,$id,sbar) $csbar
  set ttype [lindex $csbar 1]
  if {([string length $ttype] > 0)} {
    set ttyp [ mc "line $ttype"]
    if {![string equal $ttype $ttyp]} {
      set nd [lreplace $csbar 1 1 "$ttype:$ttyp"]
      set xth(me,cmds,$id,sbar) "$nd"
    }
  } 
  
}

proc xth_me_cmds_are_smooth {xp yp x y xn yn} {
  set rv 1
  set d1 [expr hypot($x - $xp,$y - $yp)]
  set d2 [expr hypot($xn - $x,$yn - $y)]
  if {($d2 > 0) && ($d1 > 0)} {
    set a1 [expr atan2($y - $yp, $x - $xp) / 3.14159265359 * 180.0];                        
    set a2 [expr atan2($yn - $y, $xn - $x) / 3.14159265359 * 180.0];
    if {($a2 - $a1) > 180.0} {
      set a2 [expr $a2 - 360.0]
    }
    if {($a2 - $a1) < -180.0} {
      set a2 [expr $a2 + 360.0]
    }
    if {($a2 > ($a1 + 5.0)) || ($a2 < ($a1 - 5.0))} {
      set rv 0
    }
  }        
  return $rv
}


proc xth_me_cmds_select_linept {id pid} {
  global xth
  if {$xth(me,unredook)} {
    xth_me_cmds_update {}
  }
  xth_me_cmds_update_linept_ctrl $id $pid
  set ix [lsearch $xth(me,cmds,$id,xplist) $pid]
  $xth(ctrl,me,line).pl.l selection clear 0 end
  $xth(ctrl,me,line).pl.l selection set $ix $ix
  $xth(ctrl,me,line).pl.l see $ix
  set xth(me,cmds,selpid) $pid
}


proc xth_me_cmds_toggle_line_close {} {
  global xth
  set id $xth(me,cmds,selid)
  set ncls $xth(ctrl,me,line,close)
  set xth(ctrl,me,line,close_tmp) $xth(ctrl,me,line,close)
  set xth(ctrl,me,line,close) $xth(me,cmds,$id,close)
  $xth(ctrl,me,line).cls configure -variable xth(ctrl,me,line,close_tmp)
  xth_me_cmds_update {}
  set xth(ctrl,me,line,close) $ncls
  if {$ncls && (!$xth(me,cmds,$id,close))} {
    xth_me_cmds_close_line $id
  } elseif {(!$ncls) && $xth(me,cmds,$id,close)} {
    xth_me_cmds_open_line $id
  }
  $xth(ctrl,me,line).cls configure -variable xth(ctrl,me,line,close)

}


proc xth_me_cmds_toggle_line_reverse {} {
  global xth
  set id $xth(me,cmds,selid)
  set nrev $xth(ctrl,me,line,reverse)
  set xth(ctrl,me,line,reverse_tmp) $xth(ctrl,me,line,reverse)
  set xth(ctrl,me,line,reverse) $xth(me,cmds,$id,reverse)
  $xth(ctrl,me,line).rev configure -variable xth(ctrl,me,line,reverse_tmp)
  xth_me_cmds_update {}
  set xth(ctrl,me,line,reverse) $nrev
  set xth(me,unredola) "line reversion"
  xth_me_cmds_update {}
  if {[llength $xth(me,cmds,$id,xplist)] > 1} {
    xth_me_cmds_move_lineln $id [lindex $xth(me,cmds,$id,xplist) 0] [lindex $xth(me,cmds,$id,xplist) 1]
  }
  $xth(ctrl,me,line).rev configure -variable xth(ctrl,me,line,reverse)
}


proc xth_me_cmds_toggle_linept {} {

  global xth

  set nidp $xth(ctrl,me,linept,idp)
  set xth(ctrl,me,linept,idp_tmp) $nidp
  set nidn $xth(ctrl,me,linept,idn)
  set xth(ctrl,me,linept,idn_tmp) $nidn
  set nsmooth $xth(ctrl,me,linept,smooth)
  set xth(ctrl,me,linept,smooth_tmp) $nsmooth
  set nrotid $xth(ctrl,me,linept,rotid)
  set xth(ctrl,me,linept,rotid_tmp) $nrotid
  set nrsid $xth(ctrl,me,linept,rsid)
  set xth(ctrl,me,linept,rsid_tmp) $nrsid
  set nlsid $xth(ctrl,me,linept,lsid)
  set xth(ctrl,me,linept,lsid_tmp) $nlsid

  set lpc $xth(ctrl,me,linept)
  $lpc.cbp configure -variable xth(ctrl,me,linept,idp_tmp)
  $lpc.cbn configure -variable xth(ctrl,me,linept,idn_tmp)
  $lpc.cbs configure -variable xth(ctrl,me,linept,smooth_tmp)
  $lpc.rotc configure -variable xth(ctrl,me,linept,rotid_tmp)
  $lpc.rszc configure -variable xth(ctrl,me,linept,rsid_tmp)
  $lpc.lszc configure -variable xth(ctrl,me,linept,lsid_tmp)

  update idletasks
  xth_me_cmds_update {}
  
  set id $xth(me,cmds,selid)
  set pid $xth(me,cmds,selpid)

  if {(!$nidp) && $xth(me,cmds,$id,$pid,idp)} {
    set xth(ctrl,me,linept,xp) {}
    set xth(ctrl,me,linept,yp) {}
    set xth(ctrl,me,linept,smooth) 0
  } elseif {$nidp && (!$xth(me,cmds,$id,$pid,idp))} {
    set crds [xth_me_cmds_get_default_linept_cp 1 $id $pid]
    set xth(ctrl,me,linept,xp) [lindex $crds 0]
    set xth(ctrl,me,linept,yp) [lindex $crds 1]
  }

  if {(!$nidn) && $xth(me,cmds,$id,$pid,idn)} {
    set xth(ctrl,me,linept,xn) {}
    set xth(ctrl,me,linept,yn) {}
    set xth(ctrl,me,linept,smooth) 0
  } elseif {$nidn && (!$xth(me,cmds,$id,$pid,idn))} {
    set crds [xth_me_cmds_get_default_linept_cp 0 $id $pid]
    set xth(ctrl,me,linept,xn) [lindex $crds 0]
    set xth(ctrl,me,linept,yn) [lindex $crds 1]
  }

  if {$nsmooth != $xth(me,cmds,$id,$pid,smooth)} {
    if {$nsmooth} {
      if {!$xth(me,cmds,$id,$pid,idp)} {
        set crds [xth_me_cmds_get_default_linept_cp 1 $id $pid]
        set xth(ctrl,me,linept,xp) [lindex $crds 0]
        set xth(ctrl,me,linept,yp) [lindex $crds 1]
      }
      if {!$xth(me,cmds,$id,$pid,idn)} {
        set crds [xth_me_cmds_get_default_linept_cp 0 $id $pid]
        set xth(ctrl,me,linept,xn) [lindex $crds 0]
        set xth(ctrl,me,linept,yn) [lindex $crds 1]
      }
    }
    set xth(ctrl,me,linept,smooth) $nsmooth
  }
  
  if {(!$nrotid) && ([string length $xth(me,cmds,$id,$pid,rotation)] > 0)} {
    set xth(ctrl,me,linept,rot) {}
  } elseif {$nrotid && ([string length $xth(me,cmds,$id,$pid,rotation)] < 1)} {
    set xth(ctrl,me,linept,rot) [xth_me_cmds_get_default_rotation $id $pid]
  }
  
  if {(!$nrsid) && ([string length $xth(me,cmds,$id,$pid,rs)] > 0)} {
    set xth(ctrl,me,linept,rs) {}
  } elseif {$nrsid && ([string length $xth(me,cmds,$id,$pid,rs)] < 1)} {
    set xth(ctrl,me,linept,rs) 40.0
  }
  
  if {(!$nlsid) && ([string length $xth(me,cmds,$id,$pid,ls)] > 0)} {
    set xth(ctrl,me,linept,ls) {}
  } elseif {$nlsid && ([string length $xth(me,cmds,$id,$pid,ls)] < 1)} {
    set xth(ctrl,me,linept,ls) 40.0
  }
  
  xth_me_cmds_update {}

  $lpc.cbp configure -variable xth(ctrl,me,linept,idp)
  $lpc.cbn configure -variable xth(ctrl,me,linept,idn)
  $lpc.cbs configure -variable xth(ctrl,me,linept,smooth)
  $lpc.rotc configure -variable xth(ctrl,me,linept,rotid)
  $lpc.rszc configure -variable xth(ctrl,me,linept,rsid)
  $lpc.lszc configure -variable xth(ctrl,me,linept,lsid)
  update idletasks
}

proc xth_me_cmds_update_line {id pid ntype nname nopts nrev nx ny nxp nyp \
  nxn nyn nsmth nrot nrs nls nptopts nptoptpos} {

  global xth
  
  set otype $xth(me,cmds,$id,type)
  set oname $xth(me,cmds,$id,name)
  set oopts $xth(me,cmds,$id,options)
  set orev $xth(me,cmds,$id,reverse)
  set oline "$otype $oname $oopts $orev"
  
  if {$pid > 0} {
    set ox $xth(me,cmds,$id,$pid,x)
    set oy $xth(me,cmds,$id,$pid,y)
    set oxp $xth(me,cmds,$id,$pid,xp)
    set oyp $xth(me,cmds,$id,$pid,yp)
    set oxn $xth(me,cmds,$id,$pid,xn)
    set oyn $xth(me,cmds,$id,$pid,yn)
    set osmth $xth(me,cmds,$id,$pid,smooth)
    set orot $xth(me,cmds,$id,$pid,rotation)
    set ors $xth(me,cmds,$id,$pid,rs)
    set ols $xth(me,cmds,$id,$pid,ls)
    set optopts $xth(me,cmds,$id,$pid,options)
    set optoptpos $xth(me,cmds,$id,$pid,optpos)
    set olinept "$ox $oy $oxp $oyp $oxn $oyn $osmth $orot $ors $ols $optopts"
  } else {
    set ox {}
    set oy {}
    set oxp {}
    set oyp {}
    set oxn {}
    set oyn {}
    set osmth {}
    set orot {}
    set ors {}
    set ols {}
    set optopts {}
    set optoptpos {}
    set olinept ""
  }


  if {[string length $ntype] < 1} {
    set ntype $otype
  }

  set optsredo {}
  set optsundo {}

  if {(![string equal $ntype $otype]) && [string equal $nopts $oopts]} {
    set nopts {}
    set nrs {}
    set nls {}
    set nrot {} 
    foreach xpid $xth(me,cmds,$id,xplist) {
      if {$xpid > 0} {
        foreach item {rs ls rotation} {
          if {[string length $xth(me,cmds,$id,$xpid,$item)] > 0} {
            set optsredo "$optsredo set xth(me,cmds,$id,$xpid,$item) {}; "
            set optsundo "$optsundo set xth(me,cmds,$id,$xpid,$item) [list $xth(me,cmds,$id,$xpid,$item)]; "
          }
        }
      }
    }
  }

  # uprav options
  regsub {^\s*} $nopts "" nopts
  regsub {\s*$} $nopts "" nopts
  
  set nline "$ntype $nname $nopts $nrev"
  
  if {$pid > 0} {
    
    if {[catch {expr $nx}]} {
      set nx $ox
    }
    set nx [expr double($nx)]
    if {[catch {expr $ny}]} {
      set ny $oy
    }
    set ny [expr double($ny)]

    if {[string length $nxp] > 0} {
      if {[catch {expr $nxp}]} {
        set nxp $oxp
      }
      set nxp [expr double($nxp)]
    }
    if {[string length $nyp] > 0} {
      if {[catch {expr $nyp}]} {
        set nyp $oyp
      }
      set nyp [expr double($nyp)]
    }    
    if {([string length $nxp] < 1) || ([string length $nyp] < 1)} {
      set nxp {}
      set nyp {}
      set nsmth 0
    }
    
    if {[string length $nxn] > 0} {
      if {[catch {expr $nxn}]} {
        set nxn $oxn
      }
      set nxn [expr double($nxn)]
    }
    if {[string length $nyn] > 0} {
      if {[catch {expr $nyn}]} {
        set nyn $oyn
      }
      set nyn [expr double($nyn)]
    }    
    if {([string length $nxn] < 1) || ([string length $nyn] < 1)} {
      set nxn {}
      set nyn {}
      set nsmth 0
    }
    
    if {$nsmth} {
      set crds [xth_me_cmds_get_smoothed_cp 0 $nxp $nyp $nx $ny $nxn $nyn]
      set nxp [lindex $crds 0]
      set nyp [lindex $crds 1]
      set nxn [lindex $crds 2]
      set nyn [lindex $crds 3]
    }
    
    if {[string length $nrot] > 0} {
      if {[catch {expr $nrot}]} {
        set nrot $orot
      } elseif {($nrot < 0.0) || ($nrot >= 360.0)} {
        set nrot $orot
      } else {
        set nrot [expr double($nrot)]
      }
    }

    if {[string length $nrs] > 0} {
      if {[catch {expr $nrs}]} {
        set nrs $ors
      } elseif {$nrs <= 0.0} {
        set nrs $ors
      } else {
        set nrs [expr double($nrs)]
      }
    }

    if {[string length $nls] > 0} {
      if {[catch {expr $nls}]} {
        set nls $ols
      } elseif {$nls <= 0.0} {
        set nls $ols
      } else {
        set nls [expr double($nls)]
      }
    }
    
    # uprav options
    regsub {\s*$} $nptopts "" nptopts
    if {[string length $nptopts] > 0} {
      regsub {$} $nptopts "\n" nptopts
    }

    set nlinept "$nx $ny $nxp $nyp $nxn $nyn $nsmth $nrot $nrs $nls $nptopts"
  } else {
    set nlinept ""
  }

  # ak je v niecom rozdiel, tak to updatni
  if {![string equal "$nline $nlinept" "$oline $olinept"]} {
    #puts "new\n{$nline}\n===\n{$nlinept}\n===\nold\n{$oline}\n===\n{$olinept}\n===\n"
    xth_me_unredo_action [mc "line changes"] \
      "xth_me_cmds_update_line $id $pid $otype [list $oname] [list $oopts] $orev {$ox} {$oy} {$oxp} {$oyp} {$oxn} {$oyn} {$osmth} {$orot} {$ors} {$ols} [list $optopts] {$optoptpos}; $optsundo xth_me_cmds_select {$id $pid}" \
      "xth_me_cmds_update_line $id $pid $ntype [list $nname] [list $nopts] $nrev {$nx} {$ny} {$nxp} {$nyp} {$nxn} {$nyn} {$nsmth} {$nrot} {$nrs} {$nls} [list $nptopts] {$nptoptpos}; $optsredo xth_me_cmds_select {$id $pid}"    

    set xth(me,cmds,$id,type) $ntype
    set xth(me,cmds,$id,name) $nname 
    set xth(me,cmds,$id,options) $nopts 
    set xth(me,cmds,$id,reverse) $nrev 
  
    if {[string length $optsredo] > 0} {
      eval $optsredo
    }
  
    if {$pid > 0} {
      set xth(me,cmds,$id,$pid,x) $nx
      set xth(me,cmds,$id,$pid,y) $ny
      set xth(me,cmds,$id,$pid,xp) $nxp
      set xth(me,cmds,$id,$pid,yp) $nyp
      if {[string length "$nxp$nyp"] > 0} {
        set xth(me,cmds,$id,$pid,idp) 1
      } else {
        set xth(me,cmds,$id,$pid,idp) 0
      }
      set xth(me,cmds,$id,$pid,xn) $nxn
      set xth(me,cmds,$id,$pid,yn) $nyn
      if {[string length "$nxn$nyn"] > 0} {
        set xth(me,cmds,$id,$pid,idn) 1
      } else {
        set xth(me,cmds,$id,$pid,idn) 0
      }
      set xth(me,cmds,$id,$pid,smooth) $nsmth 
      set xth(me,cmds,$id,$pid,rotation) $nrot
      set xth(me,cmds,$id,$pid,rs) $nrs
      set xth(me,cmds,$id,$pid,ls) $nls
      set xth(me,cmds,$id,$pid,options) $nptopts 
      set xth(me,cmds,$id,$pid,optpos) $nptoptpos 
      xth_me_cmds_update_linept_list $id $pid
      set cpid 0
      if {$xth(me,cmds,$id,close)} {
        set fpid [lindex $xth(me,cmds,$id,xplist) 0]
        set lpid [lindex $xth(me,cmds,$id,xplist) [expr [llength $xth(me,cmds,$id,xplist)] - 2]]
        if {$pid == $fpid} {
          set cpid $lpid
        } elseif {$pid == $lpid} {
          set cpid $fpid
        }
      }
      if {$cpid > 0} {
        set xth(me,cmds,$id,$cpid,x) $nx
        set xth(me,cmds,$id,$cpid,y) $ny
        xth_me_cmds_move_linept $id $cpid
        set xth(me,cmds,$id,$cpid,xp) $nxp
        set xth(me,cmds,$id,$cpid,yp) $nyp
        set xth(me,cmds,$id,$cpid,idp) $xth(me,cmds,$id,$pid,idp)
        set xth(me,cmds,$id,$cpid,xn) $nxn
        set xth(me,cmds,$id,$cpid,yn) $nyn
        set xth(me,cmds,$id,$cpid,idn) $xth(me,cmds,$id,$pid,idn)
        set xth(me,cmds,$id,$cpid,smooth) $nsmth 
        set ix [lsearch $xth(me,cmds,$id,xplist) $cpid]
        xth_me_cmds_update_linept_list $id $cpid
      }
      xth_me_cmds_move_linelnpt $id $pid
    }  
    xth_me_cmds_update_line_data $id
    xth_me_cmds_update_list $id    
  }
  
}


proc xth_me_cmds_update_line_vars {id pid} {

  global xth
  set xth(ctrl,me,line,type) $xth(me,cmds,$id,type)
  set xth(ctrl,me,line,name) $xth(me,cmds,$id,name)
  set xth(ctrl,me,line,opts) $xth(me,cmds,$id,options)
  set xth(ctrl,me,line,reverse) $xth(me,cmds,$id,reverse)
  set xth(ctrl,me,line,close) $xth(me,cmds,$id,close)
  xth_me_cmds_update_linept_ctrl $id $pid
    
}

proc xth_me_cmds_update_area_vars {id} {

  global xth
  set xth(ctrl,me,ac,type) $xth(me,cmds,$id,type)
  set xth(ctrl,me,ac,opts) $xth(me,cmds,$id,options)
    
}





proc xth_me_cmds_get_default_linept_cp {prv id pid} {
  global xth

  set x $xth(me,cmds,$id,$pid,x)
  set y $xth(me,cmds,$id,$pid,y)
  
  if {$prv} {
    if {$xth(me,cmds,$id,$pid,idn)} {
      set dx [expr $x - $xth(me,cmds,$id,$pid,xn)]
      set dy [expr $y - $xth(me,cmds,$id,$pid,yn)]
    } else {
      set dx 0.0
      set dy 0.0
    }
  } else {
    if {$xth(me,cmds,$id,$pid,idp)} {
      set dx [expr $x - $xth(me,cmds,$id,$pid,xp)]
      set dy [expr $y - $xth(me,cmds,$id,$pid,yp)]
    } else {
      set dx 0.0
      set dy 0.0
    }
  }
  set dd [expr hypot($dy, $dx)]
  set rd $dd

  if {$dd == 0.0} {

    set ppix [expr [lsearch $xth(me,cmds,$id,xplist) $pid] - 1]
    if {$ppix >= 0} {  
      set ppid [lindex $xth(me,cmds,$id,xplist) $ppix]
      set xp $xth(me,cmds,$id,$ppid,x)
      set yp $xth(me,cmds,$id,$ppid,y)
    } else {
      set xp $x
      set yp $y
    }
  
    set npix [expr [lsearch $xth(me,cmds,$id,xplist) $pid] + 1]
    set npid [lindex $xth(me,cmds,$id,xplist) $npix]
    if {$npid > 0} {
      set xn $xth(me,cmds,$id,$npid,x)
      set yn $xth(me,cmds,$id,$npid,y)
    } else {
      set xn $x
      set yn $y
    }

    if {$prv} {
      set dx [expr $xp - $xn]
      set dy [expr $yp - $yn]
    } else {
      set dx [expr $xn - $xp]
      set dy [expr $yn - $yp]
    }
    set dd [expr hypot($dy, $dx)]
 
  }
  
  if {$dd == 0.0} {
    set dx 0.0
    set dy 1.0
    set dd 1.0
    set rd 40.0
  }
  
  if {$rd == 0.0} {
    if {$prv} {
      set ppix [expr [lsearch $xth(me,cmds,$id,xplist) $pid] - 1]
      if {$ppix >= 0} {
        set ppid [lindex $xth(me,cmds,$id,xplist) $ppix]
        if {$xth(me,cmds,$id,$ppid,idn)} {
          set rdx [expr $xth(me,cmds,$id,$ppid,xn) - $xth(me,cmds,$id,$ppid,x)]
          set rdy [expr $xth(me,cmds,$id,$ppid,yn) - $xth(me,cmds,$id,$ppid,y)]
          set rd [expr hypot($rdy,$rdx)]
        }
      }        
    } else {
      set npix [expr [lsearch $xth(me,cmds,$id,xplist) $pid] + 1]
      set npid [lindex $xth(me,cmds,$id,xplist) $npix]
      if {$npid > 0} {
        if {$xth(me,cmds,$id,$npid,idp)} {
          set rdx [expr $xth(me,cmds,$id,$npid,xp) - $xth(me,cmds,$id,$npid,x)]
          set rdy [expr $xth(me,cmds,$id,$npid,yp) - $xth(me,cmds,$id,$npid,y)]
          set rd [expr hypot($rdy,$rdx)]
        }
      }        
    }
  }
  
  if {$rd == 0.0} {
    set rd 40.0
  }
  
  return [list [expr double([format "%.2f" [expr $x + $dx / $dd * $rd]])] \
    [expr double([format "%.2f" [expr $y + $dy / $dd * $rd]])]]
  
}


proc xth_me_cmds_get_smoothed_cp {which xp yp x y xn yn} {

  set dxp [expr $x - $xp]
  set dyp [expr $y - $yp]
  set dp [expr hypot($dxp,$dyp)]

  set dxn [expr $xn - $x]
  set dyn [expr $yn - $y]
  set dn [expr hypot($dxn,$dyn)]
  
  if {($dp == 0.0) || ($dn == 0.0)} {
    return [list $xp $yp $xn $yn]
  }
  
  if {$which < 0} {
    set xp [expr $x - $dxn / $dn * $dp]
    set yp [expr $y - $dyn / $dn * $dp]
  } elseif {$which > 0} {
    set xn [expr $x + $dxp / $dp * $dn]
    set yn [expr $y + $dyp / $dp * $dn]
  } else {
    set dx [expr $xn - $xp]
    set dy [expr $yn - $yp]
    set d [expr hypot($dx,$dy)]
    if {$d == 0.0} {
       set dx [expr -1.0 * $dyp]
       set dy $dxp
       set d $dp
    }
    set xp [expr $x - $dx / $d * $dp]
    set yp [expr $y - $dy / $d * $dp]      
    set xn [expr $x + $dx / $d * $dn]
    set yn [expr $y + $dy / $d * $dn]
  }

  return [list [expr double([format "%.2f" $xp])] \
     [expr double([format "%.2f" $yp])] [expr double([format "%.2f" $xn])] \
     [expr double([format "%.2f" $yn])]]
}


proc xth_me_cmds_get_default_rotation {id pid} {

  global xth

  set x $xth(me,cmds,$id,$pid,x)
  set y $xth(me,cmds,$id,$pid,y)
  set dp 0.0
  set dn 0.0

  if {$xth(me,cmds,$id,$pid,idp) || $xth(me,cmds,$id,$pid,idn)} {

    set xp $xth(me,cmds,$id,$pid,xp)
    set yp $xth(me,cmds,$id,$pid,yp)
    set dp [expr hypot($xp - $x, $yp - $y)]
    set xn $xth(me,cmds,$id,$pid,xn)
    set yn $xth(me,cmds,$id,$pid,yn)
    set dn [expr hypot($xn - $x, $yn - $y)]
    
  } else {

    set ppix [expr [lsearch $xth(me,cmds,$id,xplist) $pid] - 1]
    if {$ppix >= 0} {
      set ppid [lindex $xth(me,cmds,$id,xplist) $ppix]
      set xp $xth(me,cmds,$id,$ppid,x)
      set yp $xth(me,cmds,$id,$ppid,y)
      set dp [expr hypot($xp - $x, $yp - $y)]
    } else {
      set xp {}
      set yp {}
    }
    
    set npix [expr [lsearch $xth(me,cmds,$id,xplist) $pid] + 1]
    set npid [lindex $xth(me,cmds,$id,xplist) $npix]
    if {$npid > 0} {
      set xn $xth(me,cmds,$id,$npid,x)
      set yn $xth(me,cmds,$id,$npid,y)
      set dn [expr hypot($xn - $x, $yn - $y)]
    } else {
      set xn {}
      set yn {}
    }
  }
  
  if {($dp > 0.0) && ($dn > 0.0)} {
    if {$dp > $dn} {
      set xn [expr $x + ($xn - $x) / $dn * $dp]
      set yn [expr $y + ($yn - $y) / $dn * $dp]
    } else {
      set xp [expr $x + ($xp - $x) / $dp * $dn]
      set yp [expr $y + ($yp - $y) / $dp * $dn]
    }
  }

  if {[string length $xn] < 1} {
    set xn $x
    set yn $y
  } 

  if {[string length $xp] < 1} {
    set xp $x
    set yp $y
  } 

  set rr [expr 360.0 - atan2($yn - $yp,$xn - $xp) / 3.14159265359 * 180.0];
  while {$rr >= 360.0} {set rr [expr $rr - 360.0]};
  while {$rr < 0.0} {set rr [expr $rr + 360.0]};
  return [format "%.1f" $rr]
  
}


proc xth_me_cmds_update_linept_list {id pid} {
  global xth
  set ix [lsearch $xth(me,cmds,$id,xplist) $pid]
  set xth(me,cmds,$id,plist) \
    [lreplace $xth(me,cmds,$id,plist) $ix $ix [format "%7.2f %7.2f" $xth(me,cmds,$id,$pid,x) $xth(me,cmds,$id,$pid,y)]]
}


proc xth_me_cmds_close_line {id} {
  global xth
  # prida bod ak treba, ak je novy, oznaci ho
  set xl $xth(me,cmds,$id,xplist)
  set lix [expr [llength $xl] - 2]
  set fpid [lindex $xl 0]
  set nwpid $xth(me,cmds,selpid)
  set olpid $xth(me,cmds,selpid)
  if {($lix < 2) || \
    ($xth(me,cmds,$id,$fpid,x) != $xth(me,cmds,$id,[lindex $xl $lix],x)) || \
    ($xth(me,cmds,$id,$fpid,y) != $xth(me,cmds,$id,[lindex $xl $lix],y))} {
    set oldurok $xth(me,unredook)
    set xth(me,unredook) 0
    set iix [expr $lix + 1]
    xth_me_cmds_create_line_point $id $iix 0 \
      $xth(me,cmds,$id,$fpid,x) $xth(me,cmds,$id,$fpid,y) $xth(me,cmds,$id,$fpid,xp) $xth(me,cmds,$id,$fpid,yp) \
      $xth(me,cmds,$id,$fpid,xn) $xth(me,cmds,$id,$fpid,yn) $xth(me,cmds,$id,$fpid,smooth) {} {} {} {} 1.0
    set xth(me,unredook) $oldurok
    set nwpid $xth(me,cmds,$id,lpid)
    xth_me_cmds_select_linept $id $nwpid
    set unpoint "xth_me_cmds_delete_linept $id $nwpid"
    set repoint "xth_me_cmds_undelete_linept $id $nwpid $iix"
  } else {
    set lpid [lindex $xl $lix]
    set unpoint "xth_me_cmds_select $id\nset xth(me,cmds,$id,$lpid,xp) {$xth(me,cmds,$id,$lpid,xp)}\nset xth(me,cmds,$id,$lpid,yp) {$xth(me,cmds,$id,$lpid,yp)}\nset xth(me,cmds,$id,$lpid,idp) {$xth(me,cmds,$id,$lpid,idp)}\nset xth(me,cmds,$id,$lpid,xn) {$xth(me,cmds,$id,$lpid,xn)}\nset xth(me,cmds,$id,$lpid,yn) {$xth(me,cmds,$id,$lpid,yn)}\nset xth(me,cmds,$id,$lpid,idn) {$xth(me,cmds,$id,$lpid,idn)}\nset xth(me,cmds,$id,$lpid,smooth) {$xth(me,cmds,$id,$lpid,smooth)}\nxth_me_cmds_move_linelnpt $id $lpid"
    set repoint "xth_me_cmds_select $id\nset xth(me,cmds,$id,$lpid,xp) {$xth(me,cmds,$id,$fpid,xp)}\nset xth(me,cmds,$id,$lpid,yp) {$xth(me,cmds,$id,$fpid,yp)}\nset xth(me,cmds,$id,$lpid,idp) {$xth(me,cmds,$id,$fpid,idp)}\nset xth(me,cmds,$id,$lpid,xn) {$xth(me,cmds,$id,$fpid,xn)}\nset xth(me,cmds,$id,$lpid,yn) {$xth(me,cmds,$id,$fpid,yn)}\nset xth(me,cmds,$id,$lpid,idn) {$xth(me,cmds,$id,$fpid,idn)}\nset xth(me,cmds,$id,$lpid,smooth) {$xth(me,cmds,$id,$fpid,smooth)}\nxth_me_cmds_move_linelnpt $id $lpid"
    eval $repoint
  }
  # nastavi close
  set xth(me,cmds,$id,close) 1
  # update vars
  xth_me_cmds_update_line_vars $id $nwpid
  xth_me_cmds_update_line_data $id
  xth_me_prev_cmd $xth(me,cmds,$id,data)
  if {$xth(me,cmds,mode) == 2} {
    set remode "xth_me_cmds_set_mode 0"
    set unmode "xth_me_cmds_set_mode 2"
    eval $remode
  } else {
    set remode ""
    set unmode ""
  }
  xth_me_unredo_action [mc "line closing"] \
  "$unpoint\nset xth(me,cmds,$id,close) 0\nxth_me_cmds_update_line_vars $id $olpid\nxth_me_cmds_update_line_data $id\nxth_me_prev_cmd \$xth(me,cmds,$id,data)\n$unmode" \
  "$repoint\nset xth(me,cmds,$id,close) 1\nxth_me_cmds_update_line_vars $id $nwpid\nxth_me_cmds_update_line_data $id\nxth_me_prev_cmd \$xth(me,cmds,$id,data)\n$remode"
  
}


proc xth_me_cmds_open_line {id} {
  global xth
  set xth(me,cmds,$id,close) 0
  xth_me_cmds_update_line_vars $id $xth(me,cmds,selpid)
  xth_me_cmds_update_line_data $id
  xth_me_prev_cmd $xth(me,cmds,$id,data)
  xth_me_unredo_action [mc "line opening"] \
    "xth_me_cmds_reclose_line $id" \
    "xth_me_cmds_open_line $id"
}

proc xth_me_cmds_reclose_line {id} {
  global xth
  set xth(me,cmds,$id,close) 1
  xth_me_cmds_update_line_data $id
  xth_me_prev_cmd $xth(me,cmds,$id,data)
  xth_me_cmds_update_line_vars $id $xth(me,cmds,selpid)
}


proc xth_me_cmds_get_bezier_coords {x1 y1 c1x c1y c2x c2y x2 y2} {
#  if {[llength $x1] > 1} {
#    set tlen [lindex $x1 2]
#    set rotation [lindex $x1 1]
#    set x1 [lindex $x1 0]
#  } else {
#    set rotation {}
#  }
  if {[string length $c1x] < 1} {
    set c1x $x1
    set c1y $y1
  }
  if {[string length $c2x] < 1} {
    set c2x $x2
    set c2y $y2
  }
  set q 20
#  if {[string length $rotation] > 0} {    
#    set crds [list [expr $x1 + $tlen * sin(double($rotation)/180.0*3.14159265359)] \
#      [expr $y1 + $tlen * cos(double($rotation)/180.0*3.14159265359)]]
#  } else {
    set crds {}
#  }
  for {set i 0} {$i <= $q} {incr i} {
    set t [expr $i.0 / $q.0]
    set t2 [expr pow($t,2.0)]
    set t3 [expr pow($t,3.0)]
    set t_ [expr 1.0 - $t]
    set t_2 [expr pow($t_,2.0)]
    set t_3 [expr pow($t_,3.0)]
    lappend crds [expr $t_3 * $x1 + 3.0 * $t * $t_2 * $c1x + 3.0 * $t2 * $t_ * $c2x + $t3 * $x2] \
      [expr $t_3 * $y1 + 3.0 * $t * $t_2 * $c1y + 3.0 * $t2 * $t_ * $c2y + $t3 * $y2]
  }
  return $crds
}


proc xth_me_cmds_real2can_coords {crds} {
  set x 1
  set r {}
  foreach c $crds {
    if $x {
      lappend r [xth_me_real2canx $c]
      set x 0
    } else {
      lappend r [xth_me_real2cany $c]
      set x 1
    }
  }
  return $r
}


proc xth_me_cmds_get_crds2state {id ppid pid} {
  global xth
#  set tlen [expr 0.01 * $xth(me,zoom) * $xth(gui,me,line,ticksize)]

  if {$ppid > 0} {

#    if {[lsearch $xth(me,cmds,$id,xplist) $ppid] == 0} {
#      set rot [xth_me_cmds_get_default_rotation $id $ppid]
#      set x1 [list $xth(me,cmds,$id,$ppid,x) $rot $tlen]
#    } else {
#      set rot {}
      set x1 $xth(me,cmds,$id,$ppid,x)
#    }

    set st normal
    if {$xth(me,cmds,$id,$ppid,idn) || $xth(me,cmds,$id,$pid,idp)} {
      set crds [xth_me_cmds_get_bezier_coords $x1 \
        $xth(me,cmds,$id,$ppid,y) $xth(me,cmds,$id,$ppid,xn) \
        $xth(me,cmds,$id,$ppid,yn) $xth(me,cmds,$id,$pid,xp) \
        $xth(me,cmds,$id,$pid,yp) $xth(me,cmds,$id,$pid,x) \
        $xth(me,cmds,$id,$pid,y)]
    } else {
#      if {[string length $rot] > 0} {
#        set crds [list [expr $xth(me,cmds,$id,$ppid,x) + $tlen * sin(double($rot)/180.0*3.14159265359)] \
#          [expr $xth(me,cmds,$id,$ppid,y) + $tlen * cos(double($rot)/180.0*3.14159265359)]]
#      } else {
        set crds {}
#      }
      lappend crds $xth(me,cmds,$id,$ppid,x) $xth(me,cmds,$id,$ppid,y) \
        $xth(me,cmds,$id,$pid,x) $xth(me,cmds,$id,$pid,y)
    }
  } else {
    set crds {0 0 10 10}
    set st hidden
  }
  return [list $st $crds]
}



proc xth_me_cmds_draw_lineln {id ppid pid} {
  global xth
  set st2crds [xth_me_cmds_get_crds2state $id $ppid $pid]
  set st [lindex $st2crds 0]
  set crds [lindex $st2crds 1]
  $xth(me,can) create line [xth_me_cmds_real2can_coords $crds] -width $xth(gui,me,line,width) -fill $xth(gui,me,activefill) \
    -tags "line ln$id lnln$id ln$id.$pid command" -state $st
  xth_me_bind_area_drag ln$id.$pid {}
  $xth(me,can) bind ln$id.$pid <1> "xth_me_cmds_click_lineln {$id $pid} pt$id.$pid %x %y"
  set highlight_on "if {\$xth(me,cmds,selid) != $id} {\$xth(me,can) itemconfigure lnln$id -fill \$xth(gui,me,highlightfill)}"
  set highlight_off "if {\$xth(me,cmds,selid) != $id} {\$xth(me,can) itemconfigure lnln$id -fill \[$xth(me,can) itemcget pt$id.$pid -outline\]}"
  $xth(me,can) bind ln$id.$pid <Enter> "$highlight_on\nxth_status_bar_push me; xth_status_bar_status me \"\$xth(me,cmds,$id,listix): \$xth(me,cmds,$id,sbar)\""
  $xth(me,can) bind ln$id.$pid <Leave> "$highlight_off\nxth_status_bar_pop me"
  catch {$xth(me,can) lower ln$id.$pid point}
}


proc xth_me_cmds_move_lineln {id ppid pid} {
  global xth
  set st2crds [xth_me_cmds_get_crds2state $id $ppid $pid]
  set st [lindex $st2crds 0]
  set crds [lindex $st2crds 1]
  $xth(me,can) coords ln$id.$pid [xth_me_cmds_real2can_coords $crds]
  $xth(me,can) itemconfigure ln$id.$pid -state $st
}


proc xth_me_cmds_draw_linept {id pid} {
  global xth
  $xth(me,can) create oval [expr [xth_me_real2canx $xth(me,cmds,$id,$pid,x)] - $xth(gui,me,line,psize)] \
  [expr [xth_me_real2cany $xth(me,cmds,$id,$pid,y)] - $xth(gui,me,line,psize)] [expr [xth_me_real2canx $xth(me,cmds,$id,$pid,x)] + $xth(gui,me,line,psize)] \
  [expr [xth_me_real2cany $xth(me,cmds,$id,$pid,y)] + $xth(gui,me,line,psize)] -width 1 -outline blue -fill $xth(gui,me,activefill) \
  -tags "point ln$id lnpt$id pt$id.$pid command"
  set highlight_on "if {\$xth(me,cmds,selid) != $id} {\$xth(me,can) itemconfigure lnln$id -fill \$xth(gui,me,highlightfill)}"
  set highlight_off "if {\$xth(me,cmds,selid) != $id} {\$xth(me,can) itemconfigure lnln$id -fill \[$xth(me,can) itemcget pt$id.$pid -outline\]}"
  $xth(me,can) bind pt$id.$pid <Enter> "$highlight_on\n$xth(me,can) itemconfigure pt$id.$pid -fill cyan; xth_status_bar_push me; xth_status_bar_status me \"\$xth(me,cmds,$id,listix): \[lindex \[regexp -inline -- {^\[^\\n\]*} \$xth(me,cmds,$id,data)\] 0\]\""
  $xth(me,can) bind pt$id.$pid <Leave> "$highlight_off\n$xth(me,can) itemconfigure pt$id.$pid -fill \[$xth(me,can) itemcget ln$id.$pid -fill\]; xth_status_bar_pop me"
  $xth(me,can) bind pt$id.$pid <1> "xth_me_cmds_click {$id $pid} pt$id.$pid \$xth(me,cmds,$id,$pid,x) \$xth(me,cmds,$id,$pid,y) %x %y"
  $xth(me,can) bind pt$id.$pid <3> "xth_me_cmds_special_select {$id $pid} %x %y"  
  $xth(me,can) bind pt$id.$pid <Shift-1> "xth_me_cmds_special_select {$id $pid} %x %y"  
  $xth(me,can) bind pt$id.$pid <$xth(kb_control)-1> "xth_me_cmds_click_area pt$id.$pid %x %y"
}


proc xth_me_cmds_move_linept {id pid} {
  global xth
  $xth(me,can) coords pt$id.$pid [expr [xth_me_real2canx $xth(me,cmds,$id,$pid,x)] - $xth(gui,me,line,psize)] \
  [expr [xth_me_real2cany $xth(me,cmds,$id,$pid,y)] - $xth(gui,me,line,psize)] [expr [xth_me_real2canx $xth(me,cmds,$id,$pid,x)] + $xth(gui,me,line,psize)] \
  [expr [xth_me_real2cany $xth(me,cmds,$id,$pid,y)] + $xth(gui,me,line,psize)]
}


proc xth_me_cmds_draw_line {id} {
  global xth
  set ppid 0
  foreach pid $xth(me,cmds,$id,xplist) {
    if {($pid > 0)} {
      xth_me_cmds_draw_lineln $id $ppid $pid
      xth_me_cmds_draw_linept $id $pid
    }
    set ppid $pid
  }
  catch {$xth(me,can) raise lnpt$id point}
}


proc xth_me_cmds_move_line {id} {
  global xth
  set ppid 0
  foreach pid $xth(me,cmds,$id,xplist) {
    if {($pid > 0)} {
      xth_me_cmds_move_lineln $id $ppid $pid
      xth_me_cmds_move_linept $id $pid
    }
    set ppid $pid
  }
}


proc xth_me_cmds_move_linelnpt {id pid} {
  global xth
  set xl $xth(me,cmds,$id,xplist)
  set ix [lsearch $xl $pid]
  if {($ix < 0) || ($pid == 0)} {
    return
  }
  
  set pix [expr $ix - 1]
  set nix [expr $ix + 1]
    
  set fix 0
  set lix [expr [llength $xl] - 2]
  
  set cpid 0
  set mpix 0
  set mnix 0
  
  if {$xth(me,cmds,$id,close)} {
    if {$ix == $fix} {
      set cpid [lindex $xl $lix]
      set pix [expr $lix - 1]
      set mpix 1
    } elseif {$ix == $lix} {
      set cpid [lindex $xl $fix]
      set nix [expr $fix + 1]
      set mnix 1
    }
  }
  xth_me_cmds_move_linept $id $pid
  if {$cpid > 0} {
    xth_me_cmds_move_linept $id $cpid
  }
  
  if {($pix >= $fix) && ($pix <= $lix)} {
    set ppid [lindex $xl $pix]
  } else {
    set ppid 0
  }
  if {$mpix} {
    xth_me_cmds_move_lineln $id $ppid $cpid
  } else {
    xth_me_cmds_move_lineln $id $ppid $pid
  }


  if {($nix >= $fix) && ($nix <= $lix)} {
    set npid [lindex $xl $nix]
    if {$mnix} {
      xth_me_cmds_move_lineln $id $cpid $npid
    } else {
      xth_me_cmds_move_lineln $id $pid $npid
    }
  }
  
}

proc xth_me_cmds_start_create_linept {tagOrId x y mx my} {

  global xth

  set xth(me,lptc,id) $xth(me,cmds,selid)
  set id $xth(me,lptc,id)
  if {$xth(me,cmds,$id,ct) != 3} {
    return
  }
  set xl $xth(me,cmds,$id,xplist)
  set inspid $xth(me,cmds,inspid)
  set oldpid $xth(me,cmds,selpid)
  set ix [lsearch $xl $inspid]
  set xth(me,lptc,mx) $mx
  set xth(me,lptc,my) $my
  set xth(me,lptc,tagOrId) $tagOrId
  if {($ix == 0) && $xth(me,cmds,$id,close)} {
    set unclosecmd "xth_me_cmds_reclose_line $id"
    set reclosecmd "xth_me_cmds_open_line $id"
    set ook $xth(me,unredook)
    set xth(me,unredook) 0
    eval $reclosecmd
    set xth(me,unredook) $ook
  } else {
    set unclosecmd ""
    set reclosecmd ""
  }

  xth_me_cmds_create_line_point $id $ix 0 $x $y {} {} {} {} 0 {} {} {} {} 1.0
  xth_me_cmds_hide_linept_xctrl  
  set pid $xth(me,cmds,$id,lpid)
  set pnpid [xth_me_cmds_get_line_pnpid $id $pid]
  set xth(me,lptc,ppid) [lindex $pnpid 0]
  set ppid $xth(me,lptc,ppid)
  set xth(me,lptc,npid) [lindex $pnpid 1]
  set npid $xth(me,lptc,npid)
  set xth(me,lptc,pid) $pid
  set xth(me,lptc,oldm) [$xth(me,can) bind $tagOrId <B1-Motion>]
  set xth(me,lptc,oldr) [$xth(me,can) bind $tagOrId <B1-ButtonRelease>]
  $xth(me,can) itemconfigure $xth(me,canid,linept,ncp) -fill yellow
  $xth(me,can) bind $tagOrId <B1-Motion> "xth_me_cmds_continue_linept_creation %x %y 1"
  $xth(me,can) bind $tagOrId <$xth(kb_control)-B1-Motion> "xth_me_cmds_continue_linept_creation %x %y 0"
  $xth(me,can) bind $tagOrId <B1-ButtonRelease> "xth_me_cmds_end_create_linept %x %y 1"
  $xth(me,can) bind $tagOrId <$xth(kb_control)-B1-ButtonRelease> "xth_me_cmds_end_create_linept %x %y 0"
  xth_me_cmds_continue_linept_creation $mx $my 1
  xth_me_unredo_action [mc "inserting line point"] \
    "xth_me_cmds_delete_linept $id $pid\n$unclosecmd\nxth_me_cmds_select_linept $id $oldpid" \
    "$reclosecmd\nxth_me_cmds_undelete_linept $id $pid $ix"
  if {($ppid > 0) && $xth(me,cmds,$id,$ppid,idn)} {
    $xth(me,can) itemconfigure lineptppcp -state normal
  }
  if {($npid > 0) && $xth(me,cmds,$id,$npid,idp)} {
    $xth(me,can) itemconfigure lineptnncp -state normal
  }
  xth_me_cmds_continue_linept_creation $mx $my 1
}


proc xth_me_cmds_continue_linept_creation {x y motionID} {
  global xth
  set id $xth(me,lptc,id)
  set pid $xth(me,lptc,pid)
  set ppid $xth(me,lptc,ppid)
  set npid $xth(me,lptc,npid)
  set dx [expr $x - $xth(me,lptc,mx)]
  set dy [expr $y - $xth(me,lptc,my)]
  set dst [expr hypot($dy,$dx)]
  if {$dst > $xth(gui,me,line,psize)} {
    set xn [xth_me_can2realx [$xth(me,can) canvasx $x]]
    set yn [xth_me_can2realy [$xth(me,can) canvasy $y]]
    set xth(me,cmds,$id,$pid,idn) 1
    set xth(me,cmds,$id,$pid,xn) [expr double([format %.2f $xn])]
    set xth(me,cmds,$id,$pid,yn) [expr double([format %.2f $yn])]
    set xth(me,cmds,$id,$pid,idp) 1
    set x $xth(me,cmds,$id,$pid,x)
    set y $xth(me,cmds,$id,$pid,y)
    set dx [expr $xn - $x]
    set dy [expr $yn - $y]
    $xth(me,can) itemconfigure lineptpcp -state normal
    $xth(me,can) itemconfigure lineptncp -state normal
    if {($ppid > 0) && $xth(me,cmds,$id,$ppid,idn)} {
      $xth(me,can) itemconfigure lineptppcp -state normal
    }
    set d [expr hypot($dy,$dx)]
    if {$motionID} {
      set xd $d
      set xth(me,lptc,xd) $d
    } else {
      if {[info exist xth(me,lptc,xd)]} {
        set xd $xth(me,lptc,xd)
      } else {
        set xd $d
      }
    }
    if {(!$motionID)} {
      set dx [expr $dx / $d * $xd]
      set dy [expr $dy / $d * $xd]
    }
    set xth(me,cmds,$id,$pid,xp) [expr double([format %.2f [expr $x - $dx]])]
    set xth(me,cmds,$id,$pid,yp) [expr double([format %.2f [expr $y - $dy]])]
    set xth(me,cmds,$id,$pid,smooth) 1
  } else {
    set xth(me,cmds,$id,$pid,idn) 0
    set xth(me,cmds,$id,$pid,xn) {}
    set xth(me,cmds,$id,$pid,yn) {}
    set xth(me,cmds,$id,$pid,idp) 0
    set xth(me,cmds,$id,$pid,xp) {}
    set xth(me,cmds,$id,$pid,yp) {}
    $xth(me,can) itemconfigure lineptpcp -state hidden
    $xth(me,can) itemconfigure lineptncp -state hidden
  }
  xth_me_cmds_move_lineptcp_xctrl $id $ppid $pid $npid
  xth_me_cmds_move_line_xctrl $id
  xth_me_cmds_move_linelnpt $id $pid
  update idletasks
}


proc xth_me_cmds_end_create_linept {x y motionID} {
  global xth
  xth_me_cmds_continue_linept_creation $x $y $motionID
  set tagOrId $xth(me,lptc,tagOrId)
  set id $xth(me,lptc,id)
  set pid $xth(me,lptc,pid)
  $xth(me,can) bind $tagOrId <B1-Motion> $xth(me,lptc,oldm)
  $xth(me,can) bind $tagOrId <B1-ButtonRelease> $xth(me,lptc,oldr)
  $xth(me,can) bind $tagOrId <$xth(kb_control)-B1-Motion> ""
  $xth(me,can) bind $tagOrId <$xth(kb_control)-B1-ButtonRelease> ""
  xth_me_cmds_hide_linept_xctrl  
  set ook $xth(me,unredook)
  set xth(me,unredook) 0
  if {$xth(me,cmds,$id,$pid,idn)} {
    $xth(me,can) itemconfigure $xth(me,canid,linept,ncp) -fill yellow
  } else {
    $xth(me,can) itemconfigure $xth(me,canid,linept,ncp) -fill red
  }
  xth_me_cmds_select_linept $id $pid
  xth_me_cmds_update_line_data $id
  xth_me_prev_cmd $xth(me,cmds,$id,data)
  set xth(me,unredook) $ook
}


proc xth_me_cmds_end_line {} {
  set recmds "xth_me_cmds_set_mode 0"
  set uncmds "xth_me_cmds_set_mode 2"
  eval $recmds
  xth_me_unredo_action [mc "line ending"] $uncmds $recmds
}


proc xth_me_cmds_start_linept_insert {} {
  global xth
  set xth(me,cmds,inspid) $xth(me,cmds,selpid)
  xth_me_cmds_set_mode 2
}


proc xth_me_cmds_start_area_insert {btn} {
  global xth
  if {$btn && ($xth(me,cmds,mode) == 3)} {
    xth_me_cmds_set_mode 0
  } else {
    xth_me_cmds_set_mode 3
  }
}


proc xth_me_cmds_get_line_pnpid {id pid} {
  global xth
  set xl $xth(me,cmds,$id,xplist)
  set ix [lsearch $xl $pid]
  set lix [expr [llength $xl] - 2]
  if {$ix > 0} {
    set ppid [lindex $xl [expr $ix - 1]]
  } elseif {$xth(me,cmds,$id,close) && ($lix > 0)} {
    set ppid [lindex $xl [expr $lix - 1]]
  } else {
    set ppid 0
  }
  if {$ix < $lix} {
    set npid [lindex $xl [expr $ix + 1]]
  } elseif {$xth(me,cmds,$id,close) && ($lix > 0)} {
    set npid [lindex $xl 1]
  } else {
    set npid 0
  }
  return [list $ppid $npid]
}


proc xth_me_cmds_start_linecp_drag {tagOrId id ppid pid npid which x y} {

  global xth
  
  xth_me_cmds_update {}

  set xth(me,lcpd,tagOrId) $tagOrId
  set xth(me,lcpd,id) $id
  set xth(me,lcpd,pid) $pid
  set xth(me,lcpd,ppid) $ppid
  set xth(me,lcpd,npid) $npid
  set xth(me,lcpd,which) $which
  set xth(me,lcpd,mx) $x
  set xth(me,lcpd,my) $y
  
  set lix [expr [llength $xth(me,cmds,$id,xplist)] - 2]
  if {$lix > 0} {
    set fpid [lindex $xth(me,cmds,$id,xplist) 0]
    set lpid [lindex $xth(me,cmds,$id,xplist) $lix] 
  }
  set altpid 0
  set altppid 0
  set altnpid 0
  if {($lix > 0) && $xth(me,cmds,$id,close)} {
    if {$pid == $fpid} {
      set altpid $lpid
    } elseif {$pid == $lpid} {
      set altpid $fpid
    }
    if {$ppid == $fpid} {
      set altppid $lpid
    } elseif {$ppid == $lpid} {
      set altppid $fpid
    }
    if {$npid == $fpid} {
      set altnpid $lpid
    } elseif {$npid == $lpid} {
      set altnpid $fpid
    }
  }
  
  set xth(me,lcpd,altpid) $altpid
  set xth(me,lcpd,altppid) $altppid
  set xth(me,lcpd,altnpid) $altnpid

  set xth(me,lcpd,oldenter) [$xth(me,can) bind $tagOrId <Enter>]
  $xth(me,can) bind $tagOrId <Enter> ""
  set xth(me,lcpd,oldleave) [$xth(me,can) bind $tagOrId <Leave>]
  $xth(me,can) bind $tagOrId <Leave> ""
  set xth(me,lcpd,oldfill) [$xth(me,can) itemcget $tagOrId -fill]
  $xth(me,can) itemconfigure $tagOrId -fill {}
  $xth(me,can) bind $tagOrId <B1-Motion> "xth_me_cmds_continue_linecp_drag %x %y 0"
  $xth(me,can) bind $tagOrId <B1-ButtonRelease> "xth_me_cmds_end_linecp_drag %x %y 0"

  set dragto 0

  switch $which {
    x {
      set dragto 1
      $xth(me,can) bind $tagOrId <B1-Motion> "xth_me_cmds_continue_linecp_drag %x %y 1"
      $xth(me,can) bind $tagOrId <B1-ButtonRelease> "xth_me_cmds_end_linecp_drag %x %y 1"
      $xth(me,can) bind $tagOrId <$xth(kb_control)-B1-Motion> "xth_me_cmds_continue_linecp_drag %x %y 0"
      $xth(me,can) bind $tagOrId <$xth(kb_control)-B1-ButtonRelease> "xth_me_cmds_end_linecp_drag %x %y 0"
      set xth(me,lcpd,oldmove,pcplstate) [$xth(me,can) itemcget $xth(me,canid,linept,pcpl) -state]
      $xth(me,can) itemconfigure $xth(me,canid,linept,pcpl) -state hidden
      set xth(me,lcpd,oldmove,ncplstate) [$xth(me,can) itemcget $xth(me,canid,linept,ncpl) -state]
      $xth(me,can) itemconfigure $xth(me,canid,linept,ncpl) -state hidden
      set xth(me,lcpd,oldmove,selstate) [$xth(me,can) itemcget $xth(me,canid,linept,selector) -state]
      $xth(me,can) itemconfigure $xth(me,canid,linept,selector) -state hidden
      set xth(me,lcpd,oldmove,pcpfill) [$xth(me,can) itemcget $xth(me,canid,linept,pcp) -fill]
      $xth(me,can) itemconfigure $xth(me,canid,linept,pcp) -fill {}
      set xth(me,lcpd,oldmove,ncpfill) [$xth(me,can) itemcget $xth(me,canid,linept,ncp) -fill]
      $xth(me,can) itemconfigure $xth(me,canid,linept,ncp) -fill {}
      $xth(me,can) itemconfigure $xth(me,canid,linept,fr) -width 1 -arrow none
      $xth(me,can) itemconfigure $xth(me,canid,linept,fl) -width 1 -arrow none
      set xth(me,lcpd,oldx) $xth(me,cmds,$id,$pid,x)
      set xth(me,lcpd,oldy) $xth(me,cmds,$id,$pid,y)
      set xth(me,lcpd,oldxp) $xth(me,cmds,$id,$pid,xp)
      set xth(me,lcpd,oldyp) $xth(me,cmds,$id,$pid,yp)
      set xth(me,lcpd,oldxn) $xth(me,cmds,$id,$pid,xn)
      set xth(me,lcpd,oldyn) $xth(me,cmds,$id,$pid,yn)
    }
    p {
      set xth(me,lcpd,oldxp) $xth(me,cmds,$id,$pid,xp)
      set xth(me,lcpd,oldyp) $xth(me,cmds,$id,$pid,yp)
      set xth(me,lcpd,oldxn) $xth(me,cmds,$id,$pid,xn)
      set xth(me,lcpd,oldyn) $xth(me,cmds,$id,$pid,yn)
    }
    n {
      set xth(me,lcpd,oldxp) $xth(me,cmds,$id,$pid,xp)
      set xth(me,lcpd,oldyp) $xth(me,cmds,$id,$pid,yp)
      set xth(me,lcpd,oldxn) $xth(me,cmds,$id,$pid,xn)
      set xth(me,lcpd,oldyn) $xth(me,cmds,$id,$pid,yn)
    }
    pp {
      set xth(me,lcpd,oldxpp) $xth(me,cmds,$id,$ppid,xn)
      set xth(me,lcpd,oldypp) $xth(me,cmds,$id,$ppid,yn)
    }
    nn {
      set xth(me,lcpd,oldxnn) $xth(me,cmds,$id,$npid,xp)
      set xth(me,lcpd,oldynn) $xth(me,cmds,$id,$npid,yp)
    }
  }
  
  xth_me_cmds_continue_linecp_drag $x $y $dragto
  $xth(me,can) configure -cursor {}
  
}


proc xth_me_cmds_continue_linecp_drag {x y dragto} {
  global xth
  set id $xth(me,lcpd,id)
  set pid $xth(me,lcpd,pid)
  set ppid $xth(me,lcpd,ppid)
  set npid $xth(me,lcpd,npid)
  set tagOrId $xth(me,lcpd,tagOrId)
  set altpid $xth(me,lcpd,altpid)
  set altppid $xth(me,lcpd,altppid)
  set altnpid $xth(me,lcpd,altnpid)
  set nx [expr double([format %.2f [xth_me_can2realx [$xth(me,can) canvasx $x]]])]
  set ny [expr double([format %.2f [xth_me_can2realy [$xth(me,can) canvasy $y]]])]
  set dts 0
  if $dragto {
    set dtl [xth_me_cmds_drag_to $id $pid $x $y]
    if {[lindex $dtl 0]} {
      set nx [lindex $dtl 1]
      set ny [lindex $dtl 2]
      set dts 1
    }
  }
  if $dts {
    $xth(me,can) itemconfigure $tagOrId -fill cyan
  } else {
    $xth(me,can) itemconfigure $tagOrId -fill {}
  }
  switch $xth(me,lcpd,which) {
    x {
      set xth(ctrl,me,linept,x) $nx
      set xth(me,cmds,$id,$pid,x) $nx
      set xth(ctrl,me,linept,y) $ny
      set xth(me,cmds,$id,$pid,y) $ny
      if {$altpid > 0} {
        set xth(me,cmds,$id,$altpid,y) $ny
        set xth(me,cmds,$id,$altpid,x) $nx
      }
      
      if {$xth(me,cmds,$id,$pid,idp)} {
        set nxp [expr double([format %.2f [expr $nx + $xth(me,lcpd,oldxp) - $xth(me,lcpd,oldx)]])]
        set nyp [expr double([format %.2f [expr $ny + $xth(me,lcpd,oldyp) - $xth(me,lcpd,oldy)]])]
        set xth(ctrl,me,linept,xp) $nxp
        set xth(me,cmds,$id,$pid,xp) $nxp
        set xth(ctrl,me,linept,yp) $nyp
        set xth(me,cmds,$id,$pid,yp) $nyp
        if {$altpid > 0} {
          set xth(me,cmds,$id,$altpid,xp) $nxp
          set xth(me,cmds,$id,$altpid,yp) $nyp
        }
      }
      
      if {$xth(me,cmds,$id,$pid,idn)} {
        set nxn [expr double([format %.2f [expr $nx + $xth(me,lcpd,oldxn) - $xth(me,lcpd,oldx)]])]
        set nyn [expr double([format %.2f [expr $ny + $xth(me,lcpd,oldyn) - $xth(me,lcpd,oldy)]])]
        set xth(ctrl,me,linept,xn) $nxn
        set xth(me,cmds,$id,$pid,xn) $nxn
        set xth(ctrl,me,linept,yn) $nyn
        set xth(me,cmds,$id,$pid,yn) $nyn
        if {$altpid > 0} {
          set xth(me,cmds,$id,$altpid,xn) $nxn
          set xth(me,cmds,$id,$altpid,yn) $nyn
        }
      }
      xth_me_cmds_move_linept_xctrl $id $pid
      xth_me_cmds_move_line_xctrl $id
    }
    p {
      set xth(ctrl,me,linept,xp) $nx
      set xth(me,cmds,$id,$pid,xp) $nx
      set xth(ctrl,me,linept,yp) $ny
      set xth(me,cmds,$id,$pid,yp) $ny
      if {$altpid > 0} {
        set xth(me,cmds,$id,$altpid,xp) $nx
        set xth(me,cmds,$id,$altpid,yp) $ny
      }
      if {$xth(me,cmds,$id,$pid,idn) && $xth(me,cmds,$id,$pid,smooth)} {
        set ncn [xth_me_cmds_get_smoothed_cp 1 $nx $ny \
          $xth(me,cmds,$id,$pid,x) $xth(me,cmds,$id,$pid,y) \
          $xth(me,cmds,$id,$pid,xn) $xth(me,cmds,$id,$pid,yn)]
        set nxn [lindex $ncn 2]
        set nyn [lindex $ncn 3]
        set xth(ctrl,me,linept,xn) $nxn
        set xth(me,cmds,$id,$pid,xn) $nxn
        set xth(ctrl,me,linept,yn) $nyn
        set xth(me,cmds,$id,$pid,yn) $nyn
        if {$altpid > 0} {
          set xth(me,cmds,$id,$altpid,xn) $nxn
          set xth(me,cmds,$id,$altpid,yn) $nyn
        }
      }
    }
    n {
      set xth(ctrl,me,linept,xn) $nx
      set xth(me,cmds,$id,$pid,xn) $nx
      set xth(ctrl,me,linept,yn) $ny
      set xth(me,cmds,$id,$pid,yn) $ny
      if {$altpid > 0} {
        set xth(me,cmds,$id,$altpid,xn) $nx
        set xth(me,cmds,$id,$altpid,yn) $ny
      }
      if {$xth(me,cmds,$id,$pid,idp) && $xth(me,cmds,$id,$pid,smooth)} {
        set ncp [xth_me_cmds_get_smoothed_cp -1 \
          $xth(me,cmds,$id,$pid,xp) $xth(me,cmds,$id,$pid,yp) \
          $xth(me,cmds,$id,$pid,x) $xth(me,cmds,$id,$pid,y) \
          $nx $ny]
        set nxp [lindex $ncp 0]
        set nyp [lindex $ncp 1]
        set xth(ctrl,me,linept,xp) $nxp
        set xth(me,cmds,$id,$pid,xp) $nxp
        set xth(ctrl,me,linept,yp) $nyp
        set xth(me,cmds,$id,$pid,yp) $nyp
        if {$altpid > 0} {
          set xth(me,cmds,$id,$altpid,xp) $nxp
          set xth(me,cmds,$id,$altpid,yp) $nyp
        }
      }
    }
    pp {
      if {$xth(me,cmds,$id,$ppid,smooth)} {
        set ncp [xth_me_cmds_get_smoothed_cp 1 \
          $xth(me,cmds,$id,$ppid,xp) $xth(me,cmds,$id,$ppid,yp) \
          $xth(me,cmds,$id,$ppid,x) $xth(me,cmds,$id,$ppid,y) \
          $nx $ny]
        set xth(me,cmds,$id,$ppid,xn) [lindex $ncp 2]
        set xth(me,cmds,$id,$ppid,yn) [lindex $ncp 3]
      } else {
        set xth(me,cmds,$id,$ppid,xn) $nx
        set xth(me,cmds,$id,$ppid,yn) $ny
      }
      if {$altppid > 0} {
        set xth(me,cmds,$id,$altppid,xn) $xth(me,cmds,$id,$ppid,xn)
        set xth(me,cmds,$id,$altppid,yn) $xth(me,cmds,$id,$ppid,yn)
      }
    }
    nn {
      if {$xth(me,cmds,$id,$npid,smooth)} {
        set ncp [xth_me_cmds_get_smoothed_cp -1 \
          $nx $ny \
          $xth(me,cmds,$id,$npid,x) $xth(me,cmds,$id,$npid,y) \
          $xth(me,cmds,$id,$npid,xn) $xth(me,cmds,$id,$npid,yn)]
        set xth(me,cmds,$id,$npid,xp) [lindex $ncp 0]
        set xth(me,cmds,$id,$npid,yp) [lindex $ncp 1]
      } else {
        set xth(me,cmds,$id,$npid,xp) $nx
        set xth(me,cmds,$id,$npid,yp) $ny
      }
      if {$altnpid > 0} {
        set xth(me,cmds,$id,$altnpid,xp) $xth(me,cmds,$id,$npid,xp)
        set xth(me,cmds,$id,$altnpid,yp) $xth(me,cmds,$id,$npid,yp)
      }
    }
  }
  xth_me_cmds_move_lineptcp_xctrl $id $ppid $pid $npid
  xth_me_cmds_move_linelnpt $id $pid
  update idletasks
}


proc xth_me_cmds_end_linecp_drag {x y dragto} {
  global xth

  xth_me_cmds_continue_linecp_drag $x $y $dragto
  set id $xth(me,lcpd,id)
  set pid $xth(me,lcpd,pid)
  set ppid $xth(me,lcpd,ppid)
  set npid $xth(me,lcpd,npid)
  set altpid $xth(me,lcpd,altpid)
  set altppid $xth(me,lcpd,altppid)
  set altnpid $xth(me,lcpd,altnpid)
  set tagOrId $xth(me,lcpd,tagOrId)

  set movecmd "xth_me_cmds_move_lineptcp_xctrl $id $ppid $pid $npid\nxth_me_cmds_move_linept_xctrl $id $pid\nxth_me_cmds_move_linelnpt $id $pid"

  switch $xth(me,lcpd,which) {
    x {
      set xth(me,cmds,$id,$pid,x) $xth(me,lcpd,oldx)
      set xth(me,cmds,$id,$pid,y) $xth(me,lcpd,oldy)
      set xth(me,cmds,$id,$pid,xp) $xth(me,lcpd,oldxp)
      set xth(me,cmds,$id,$pid,yp) $xth(me,lcpd,oldyp)
      set xth(me,cmds,$id,$pid,xn) $xth(me,lcpd,oldxn)
      set xth(me,cmds,$id,$pid,yn) $xth(me,lcpd,oldyn)
      if {$altpid > 0} {
        set xth(me,cmds,$id,$altpid,x) $xth(me,lcpd,oldx)
        set xth(me,cmds,$id,$altpid,y) $xth(me,lcpd,oldy)
        set xth(me,cmds,$id,$altpid,xp) $xth(me,lcpd,oldxp)
        set xth(me,cmds,$id,$altpid,yp) $xth(me,lcpd,oldyp)
        set xth(me,cmds,$id,$altpid,xn) $xth(me,lcpd,oldxn)
        set xth(me,cmds,$id,$altpid,yn) $xth(me,lcpd,oldyn)
      }
      set xth(me,unredola) "moving line point"
      $xth(me,can) itemconfigure $xth(me,canid,linept,pcpl) -state $xth(me,lcpd,oldmove,pcplstate)
      $xth(me,can) itemconfigure $xth(me,canid,linept,ncpl) -state $xth(me,lcpd,oldmove,ncplstate)
      $xth(me,can) itemconfigure $xth(me,canid,linept,selector) -state $xth(me,lcpd,oldmove,selstate)
      $xth(me,can) itemconfigure $xth(me,canid,linept,pcp) -fill $xth(me,lcpd,oldmove,pcpfill)
      $xth(me,can) itemconfigure $xth(me,canid,linept,ncp) -fill $xth(me,lcpd,oldmove,ncpfill)
      $xth(me,can) itemconfigure $xth(me,canid,linept,fr) -width 5 -arrow last
      $xth(me,can) itemconfigure $xth(me,canid,linept,fl) -width 5 -arrow last
    }
    p {
      set xth(me,cmds,$id,$pid,xp) $xth(me,lcpd,oldxp)
      set xth(me,cmds,$id,$pid,yp) $xth(me,lcpd,oldyp)
      set xth(me,cmds,$id,$pid,xn) $xth(me,lcpd,oldxn)
      set xth(me,cmds,$id,$pid,yn) $xth(me,lcpd,oldyn)
      if {$altpid > 0} {
        set xth(me,cmds,$id,$altpid,xp) $xth(me,lcpd,oldxp)
        set xth(me,cmds,$id,$altpid,yp) $xth(me,lcpd,oldyp)
        set xth(me,cmds,$id,$altpid,xn) $xth(me,lcpd,oldxn)
        set xth(me,cmds,$id,$altpid,yn) $xth(me,lcpd,oldyn)
      }
      set xth(me,unredola) "moving control pint"
    }
    n {
      set xth(me,cmds,$id,$pid,xp) $xth(me,lcpd,oldxp)
      set xth(me,cmds,$id,$pid,yp) $xth(me,lcpd,oldyp)
      set xth(me,cmds,$id,$pid,xn) $xth(me,lcpd,oldxn)
      set xth(me,cmds,$id,$pid,yn) $xth(me,lcpd,oldyn)
      if {$altpid > 0} {
        set xth(me,cmds,$id,$altpid,xp) $xth(me,lcpd,oldxp)
        set xth(me,cmds,$id,$altpid,yp) $xth(me,lcpd,oldyp)
        set xth(me,cmds,$id,$altpid,xn) $xth(me,lcpd,oldxn)
        set xth(me,cmds,$id,$altpid,yn) $xth(me,lcpd,oldyn)
      }
      set xth(me,unredola) "moving control pint"
    }
    pp {
      if {$altppid > 0} {
        set unaltcmd "set xth(me,cmds,$id,$altppid,xn) $xth(me,lcpd,oldxpp)\nset xth(me,cmds,$id,$altppid,yn) $xth(me,lcpd,oldypp)"
        set realtcmd "set xth(me,cmds,$id,$altppid,xn) $xth(me,cmds,$id,$ppid,xn)\nset xth(me,cmds,$id,$altppid,yn) $xth(me,cmds,$id,$ppid,yn)"
      } else {
        set unaltcmd ""
        set realtcmd ""
      }
      xth_me_unredo_action [mc "moving control point"] \
      "xth_me_cmds_select {$id $pid}\nset xth(me,cmds,$id,$ppid,xn) $xth(me,lcpd,oldxpp)\nset xth(me,cmds,$id,$ppid,yn) $xth(me,lcpd,oldypp)\n$unaltcmd\n$movecmd\nxth_me_cmds_update_line_data $id\nxth_me_prev_cmd [list $xth(me,cmds,$id,data)]" \
      "xth_me_cmds_select {$id $pid}\nset xth(me,cmds,$id,$ppid,xn) $xth(me,cmds,$id,$ppid,xn)\nset xth(me,cmds,$id,$ppid,yn) $xth(me,cmds,$id,$ppid,yn)\n$realtcmd\n$movecmd\nxth_me_cmds_update_line_data $id\nxth_me_prev_cmd [list $xth(me,cmds,$id,data)]"
    }
    nn {
      if {$altnpid > 0} {
        set unaltcmd "set xth(me,cmds,$id,$altnpid,xp) $xth(me,lcpd,oldxnn)\nset xth(me,cmds,$id,$altnpid,yp) $xth(me,lcpd,oldynn)"
        set realtcmd "set xth(me,cmds,$id,$altnpid,xp) $xth(me,cmds,$id,$npid,xp)\nset xth(me,cmds,$id,$altnpid,yp) $xth(me,cmds,$id,$npid,yp)"
      } else {
        set unaltcmd ""
        set realtcmd ""
      }
      xth_me_unredo_action [mc "moving control point"] \
      "xth_me_cmds_select {$id $pid}\nset xth(me,cmds,$id,$npid,xp) $xth(me,lcpd,oldxnn)\nset xth(me,cmds,$id,$npid,yp) $xth(me,lcpd,oldynn)\n$unaltcmd\n$movecmd\nxth_me_cmds_update_line_data $id\nxth_me_prev_cmd [list $xth(me,cmds,$id,data)]" \
      "xth_me_cmds_select {$id $pid}\nset xth(me,cmds,$id,$npid,xp) $xth(me,cmds,$id,$npid,xp)\nset xth(me,cmds,$id,$npid,yp) $xth(me,cmds,$id,$npid,yp)\n$realtcmd\n$movecmd\nxth_me_cmds_update_line_data $id\nxth_me_prev_cmd [list $xth(me,cmds,$id,data)]"
    }
  }

  $xth(me,can) bind $tagOrId <Enter> $xth(me,lcpd,oldenter)
  $xth(me,can) bind $tagOrId <Leave> $xth(me,lcpd,oldleave)
  $xth(me,can) itemconfigure $tagOrId -fill $xth(me,lcpd,oldfill)
  $xth(me,can) bind $tagOrId <B1-Motion> ""
  $xth(me,can) bind $tagOrId <B1-ButtonRelease> ""
  $xth(me,can) bind $tagOrId <$xth(kb_control)-B1-Motion> ""
  $xth(me,can) bind $tagOrId <$xth(kb_control)-B1-ButtonRelease> ""
  $xth(me,can) configure -cursor crosshair
  xth_me_cmds_update_line_data $id
  xth_me_prev_cmd $xth(me,cmds,$id,data)  
  xth_me_cmds_move_line_xctrl $id
  xth_me_cmds_update {}
  
}


proc xth_me_cmds_configure_linept_size_xctrl {id pid} {

  global xth
  
  if {([string length $id] > 0) && ($pid > 0)} {
    if {([string length $xth(me,cmds,$id,$pid,rs)] > 0)} {
      $xth(me,can) itemconfigure $xth(me,canid,linept,fr) -state normal
      $xth(me,can) bind $xth(me,canid,linept,fr) <1> \
        "xth_me_cmds_start_linept_fdrag $xth(me,canid,linept,fr) $id $pid r %x %y"
      $xth(me,can) bind $xth(me,canid,linept,fr) <Enter> \
        "$xth(me,can) itemconfigure $xth(me,canid,linept,fr) -fill #ffda00"
      $xth(me,can) bind $xth(me,canid,linept,fr) <Leave> \
        "$xth(me,can) itemconfigure $xth(me,canid,linept,fr) -fill red"
    } else {
      $xth(me,can) bind $xth(me,canid,linept,fr) <1> ""
      $xth(me,can) bind $xth(me,canid,linept,fr) <Enter> ""
      $xth(me,can) bind $xth(me,canid,linept,fr) <Leave> ""
      $xth(me,can) itemconfigure $xth(me,canid,linept,fr) -state hidden
    }
    if {([string length $xth(me,cmds,$id,$pid,ls)] > 0) || \
      (([string length $xth(me,cmds,$id,$pid,rotation)] > 0) && \
       ([string length $xth(me,cmds,$id,$pid,rs)] < 1))} {
      $xth(me,can) itemconfigure $xth(me,canid,linept,fl) -state normal
      $xth(me,can) bind $xth(me,canid,linept,fl) <1> \
        "xth_me_cmds_start_linept_fdrag $xth(me,canid,linept,fl) $id $pid l %x %y"
      $xth(me,can) bind $xth(me,canid,linept,fl) <Enter> \
        "$xth(me,can) itemconfigure $xth(me,canid,linept,fl) -fill #ffda00"
      $xth(me,can) bind $xth(me,canid,linept,fl) <Leave> \
        "$xth(me,can) itemconfigure $xth(me,canid,linept,fl) -fill red"
    } else {
      $xth(me,can) bind $xth(me,canid,linept,fl) <1> ""
      $xth(me,can) bind $xth(me,canid,linept,fl) <Enter> ""
      $xth(me,can) bind $xth(me,canid,linept,fl) <Leave> ""
      $xth(me,can) itemconfigure $xth(me,canid,linept,fl) -state hidden
    }
  } else {
      $xth(me,can) bind $xth(me,canid,linept,fr) <1> ""
      $xth(me,can) bind $xth(me,canid,linept,fr) <Enter> ""
      $xth(me,can) bind $xth(me,canid,linept,fr) <Leave> ""
      $xth(me,can) itemconfigure $xth(me,canid,linept,fr) -state hidden
      $xth(me,can) bind $xth(me,canid,linept,fl) <1> ""
      $xth(me,can) bind $xth(me,canid,linept,fl) <Enter> ""
      $xth(me,can) bind $xth(me,canid,linept,fl) <Leave> ""
      $xth(me,can) itemconfigure $xth(me,canid,linept,fl) -state hidden
  }
}


proc xth_me_cmds_move_linept_size_xctrl {id pid rot rs ls} {

  global xth
  
  set rotng 1
  if {[string length $rot] > 0} {
    set rot [expr double($rot) / 180.0 * 3.14159265359]
    set rotng 0
  } else {
    set rot [expr double([xth_me_cmds_get_default_rotation $id $pid]) / 180 * 3.14159265359]
  }

  if {[string length $rs] > 0} {
    set rs [expr 0.01 * $rs * $xth(me,zoom)]
  } else {
    set rs 30.0
  }

  if {[string length $ls] > 0} {
    set ls [expr 0.01 * $ls * $xth(me,zoom)]
  } else {
    set ls 30.0
  }


  set x [xth_me_real2canx $xth(me,cmds,$id,$pid,x)]
  set y [xth_me_real2cany $xth(me,cmds,$id,$pid,y)]
  set ca [expr cos($rot)]
  set sa [expr sin($rot)]
  
  set yvx [expr $sa * $ls]
  set yvy [expr - $ca * $ls]
  set xvx [expr - $sa * $rs]
  set xvy [expr $ca * $rs]
  
  if {$xth(me,cmds,$id,reverse) && $rotng} {
    set xvx [expr -1.0 * $xvx]
    set xvy [expr -1.0 * $xvy]
    set yvx [expr -1.0 * $yvx]
    set yvy [expr -1.0 * $yvy]
  }
  
  $xth(me,can) coords $xth(me,canid,linept,fr) $x $y [expr $x + $xvx] [expr $y + $xvy]
  $xth(me,can) coords $xth(me,canid,linept,fl) $x $y [expr $x + $yvx] [expr $y + $yvy]
  update idletasks    
}


proc xth_me_cmds_start_linept_fdrag {tagOrId id pid side x y} {
  global xth
  xth_me_cmds_update {}
  set xth(me,lptfd,tagOrId) $tagOrId
  set xth(me,lptfd,id) $id
  set xth(me,lptfd,pid) $pid
  set xth(me,lptfd,side) $side
  set dx [expr [xth_me_can2realx [$xth(me,can) canvasx $x]] - $xth(me,cmds,$id,$pid,x)]
  set dy [expr [xth_me_can2realy [$xth(me,can) canvasy $y]] - $xth(me,cmds,$id,$pid,y)] 

  if {[string length $xth(me,cmds,$id,$pid,rotation)] == 0} {
    set xth(me,lptfd,rot) 0
  } else {
    set xth(me,lptfd,rot) 1
    set xth(me,lptfd,orot) [expr atan2($dy,$dx)]
  }

  if {[string length $xth(me,cmds,$id,$pid,[format "%ss" $side])] == 0} {
    set xth(me,lptfd,size) 0
  } else {
    set xth(me,lptfd,size) 1
    set xth(me,lptfd,osize) [expr hypot($dy,$dx)]
  }

  $xth(me,can) itemconfigure $tagOrId -fill #ffda00
  set xth(me,lptfd,benter) [$xth(me,can) bind $tagOrId <Enter>]
  set xth(me,lptfd,bleave) [$xth(me,can) bind $tagOrId <Leave>]
  $xth(me,can) bind $tagOrId <Enter> ""
  $xth(me,can) bind $tagOrId <Leave> ""
  $xth(me,can) bind $tagOrId <B1-Motion> "xth_me_cmds_linept_fdrag %x %y"
  $xth(me,can) bind $tagOrId <B1-ButtonRelease> "xth_me_cmds_end_linept_fdrag %x %y"
  xth_me_cmds_linept_fdrag $x $y
  $xth(me,can) configure -cursor {}
}

proc xth_me_cmds_linept_fdrag {x y} {
  global xth
  set id $xth(me,lptfd,id)
  set pid $xth(me,lptfd,pid)
  set side $xth(me,lptfd,side)

  set dx [expr [xth_me_can2realx [$xth(me,can) canvasx $x]] - $xth(me,cmds,$id,$pid,x)]
  set dy [expr [xth_me_can2realy [$xth(me,can) canvasy $y]] - $xth(me,cmds,$id,$pid,y)]
  
  if $xth(me,lptfd,rot) {
    set rot [expr double($xth(me,cmds,$id,$pid,rotation)) - 180.0 / 3.14159265359 * (atan2($dy,$dx) - $xth(me,lptfd,orot))]
    if {$rot < 0.0} {
      set rot [expr 360.0 + $rot]
    } elseif {$rot >= 360.0} {
      set rot [expr $rot - 360.0]
    }
    set rot [format "%.1f" $rot]
    set xth(ctrl,me,linept,rot) $rot
  }
  
  if {$xth(me,lptfd,size)} {
    set cs [expr hypot($dy,$dx)]
    set ns [expr $xth(me,cmds,$id,$pid,[format "%ss" $side]) - $xth(me,lptfd,osize) + $cs]
    if {$ns <= 0.0} {set ns 0.1}
    set xth(ctrl,me,linept,[format "%ss" $side]) [format "%.1f" $ns]
  }

  xth_me_cmds_move_linept_size_xctrl $id $pid $xth(ctrl,me,linept,rot) $xth(ctrl,me,linept,rs) $xth(ctrl,me,linept,ls)
  xth_me_cmds_move_line_xctrl $id
}

proc xth_me_cmds_end_linept_fdrag {x y} {
  global xth

  xth_me_cmds_linept_fdrag $x $y

  set id $xth(me,lptfd,id)
  set pid $xth(me,lptfd,pid)
  set side $xth(me,lptfd,side)
  set tagOrId $xth(me,lptfd,tagOrId)

  $xth(me,can) configure -cursor crosshair
  if {$xth(me,lptfd,size)} {
    set xth(me,unredola) "line point resizing"
  } else {
    set xth(me,unredola) "line point rotation"
  }
  $xth(me,can) bind $tagOrId <B1-Motion> ""
  $xth(me,can) bind $tagOrId <B1-ButtonRelease> ""
  if {[lsearch [$xth(me,can) itemcget $tagOrId -tags] current] > -1} {
    $xth(me,can) itemconfigure $tagOrId -fill #ffda00
  }
  
  $xth(me,can) bind $tagOrId <Enter> $xth(me,lptfd,benter)
  $xth(me,can) bind $tagOrId <Leave> $xth(me,lptfd,bleave)
  xth_me_cmds_update {}
}


proc xth_me_cmds_set_colors {} {
  global xth
  # najde id zaciatku a konca sucasneho scrapu
  set xid [lsearch $xth(me,cmds,xlist) $xth(me,cmds,selid)]
  set llen [llength $xth(me,cmds,xlist)]
  set cid $xid
  
  set dcol #fff222
  set scol $xth(gui,me,pasivefill)
  if {$xth(me,cmds,$xth(me,cmds,selid),ct) == 4} {
    set col $dcol
    set ocol $scol
  } elseif {$xth(me,cmds,$xth(me,cmds,selid),ct) == 5} {
    set col $scol
    set ocol $dcol
  } else {
    set col $scol
    set ocol $scol
  }
  
  set xth(me,curscrap) {}
  set godown 1
  if {$cid < 0} {
    set cid [expr $xid + 1]
    set godown 0
  }
  while {(($cid >= 0) && ($cid < $llen)) || ($godown)} {
    set id [lindex $xth(me,cmds,xlist) $cid]
    switch $xth(me,cmds,$id,ct) {
      2 {
        $xth(me,can) itemconfigure pt$id -outline $col -fill $col
      }
      3 {
        $xth(me,can) itemconfigure lnpt$id -outline $col -fill $col
        $xth(me,can) itemconfigure lnln$id -fill $col
      }
      4 - 5 {
        if {(![string equal $col $dcol]) && ($xth(me,cmds,$id,ct) == 4)} {
          set xth(me,curscrap) $xth(me,cmds,$id,name)
	  if {[string equal $xth(me,cmds,$id,projection) extended]} {
	    set xth(me,snai) -1
	  } else {
	    set xth(me,snai) 1
          }
        }
        if {$cid != $xid} {
          set col $dcol
        }
      }
    }
    
    if {$godown} {
      incr cid -1      
      if {$cid < 0} {
        set cid [expr $xid + 1]
        set godown 0
        set col $ocol
      }
    } else {
      incr cid 1
    }
  }
  xth_app_title me
}


proc xth_me_cmds_show_current_area {} {

  global xth

  # najde id zaciatku a konca sucasneho scrapu
  set id $xth(me,cmds,selid)
  if {$xth(me,cmds,$id,ct) != 6} {
    return
  }

  set xid [expr [lsearch $xth(me,cmds,xlist) $id] + 1]
  set llen [llength $xth(me,cmds,xlist)]
  set cid $xid

  
  set godown 1
  if {$cid < 0} {
    set cid [expr $xid - 1]
    set godown 0
  }
  
  while {(($cid >= 0) && ($cid < $llen)) || ($godown)} {
    set oid [lindex $xth(me,cmds,xlist) $cid]
    switch $xth(me,cmds,$oid,ct) {
      3 {
        foreach lnid $xth(me,cmds,$id,llist) {
          if {[string equal $xth(me,cmds,$oid,name) $lnid]} {
            $xth(me,can) itemconfigure lnpt$oid -fill red
            $xth(me,can) itemconfigure lnln$oid -fill red
          }
        }
      }
      4 {
        return
      }
      5 {
        if {$cid != $xid} {
          set cid [expr $xid - 1]
          set godown 0
        }
      }
    }
    
    if {$godown} {
      incr cid -1      
      if {$cid < 0} {
        set cid [expr $xid - 1]
        set godown 0
      }
    } else {
      incr cid 1
    }
    
  }
}




proc xth_me_cmds_line_split {} {

  global xth
  
  xth_me_cmds_update {}
  
  set id $xth(me,cmds,selid)
  set pid $xth(me,cmds,selpid)  
	
	set prev_center [xth_me_get_center]

  # najprv zisti ci mooze, ak nie tak exit
  if {$xth(me,cmds,$id,ct) != 3} {
    return
  }
  
  set px [lsearch -exact $xth(me,cmds,$id,xplist) $pid]
  set lpx [llength $xth(me,cmds,$id,xplist)]
  if {($px <= 0) || ($px >= ($lpx - 2))} {
    return
  }
  
  # vytvori dve nove ciary, close nastavene na false
  set xth(me,unredook) 0
  set ix [lsearch $xth(me,cmds,xlist) $id]
  
  set id1 [xth_me_cmds_create 3 {} {}]
  set xth(me,cmds,$id1,lpid) 0
  set xth(me,cmds,$id1,plist) {"end of line"}
  set xth(me,cmds,$id1,xplist) {0}
  set id2 [xth_me_cmds_create 3 {} {}]
  set xth(me,cmds,$id2,lpid) 0
  set xth(me,cmds,$id2,plist) {"end of line"}
  set xth(me,cmds,$id2,xplist) {0}
  
  set xth(me,cmds,$id1,type) $xth(me,cmds,$id,type)
  set xth(me,cmds,$id2,type) $xth(me,cmds,$id,type)
  set xth(me,cmds,$id1,name) {}
  set xth(me,cmds,$id2,name) {}
  set xth(me,cmds,$id1,reverse) $xth(me,cmds,$id,reverse)
  set xth(me,cmds,$id2,reverse) $xth(me,cmds,$id,reverse)
  set xth(me,cmds,$id1,close) 0
  set xth(me,cmds,$id2,close) 0
  set xth(me,cmds,$id1,options) $xth(me,cmds,$id,options)
  set xth(me,cmds,$id2,options) $xth(me,cmds,$id,options)

  xth_me_cmds_update_list $id1
  xth_me_cmds_update_list $id2
  
  # povklada body
  set ix1 0
  set ix2 0
  for {set cx 0} {$cx < ($lpx - 1)} {incr cx} {
    set opid [lindex $xth(me,cmds,$id,xplist) $cx]
    if {$cx <= $px} {
      #vlozi ho do prvej      
      xth_me_cmds_create_line_point $id1 $ix1 0 \
      $xth(me,cmds,$id,$opid,x) $xth(me,cmds,$id,$opid,y) \
      $xth(me,cmds,$id,$opid,xp) $xth(me,cmds,$id,$opid,yp) \
      $xth(me,cmds,$id,$opid,xn) $xth(me,cmds,$id,$opid,yn) \
      $xth(me,cmds,$id,$opid,smooth) $xth(me,cmds,$id,$opid,rotation) \
      $xth(me,cmds,$id,$opid,rs) $xth(me,cmds,$id,$opid,ls) \
      $xth(me,cmds,$id,$opid,options) 1.0
      incr ix1
    }
    if {$cx >= $px} {
      #vlozi ho do druhej
      xth_me_cmds_create_line_point $id2 $ix2 0 \
      $xth(me,cmds,$id,$opid,x) $xth(me,cmds,$id,$opid,y) \
      $xth(me,cmds,$id,$opid,xp) $xth(me,cmds,$id,$opid,yp) \
      $xth(me,cmds,$id,$opid,xn) $xth(me,cmds,$id,$opid,yn) \
      $xth(me,cmds,$id,$opid,smooth) $xth(me,cmds,$id,$opid,rotation) \
      $xth(me,cmds,$id,$opid,rs) $xth(me,cmds,$id,$opid,ls) \
      $xth(me,cmds,$id,$opid,options) 1.0
      incr ix2
    }
  }
  
  xth_me_cmds_update_line_data $id1
  xth_me_cmds_update_line_data $id2
  
  # zmaze originalnu
  set pid1 0
  set pid2 [lindex $xth(me,cmds,$id2,xplist) 0]
  xth_me_cmds_delete $id
  xth_me_cmds_select [list $id2 $pid2]
	
	# scrollne sa tam, odkial sme zacinali
	xth_me_center_to $prev_center

  set xth(me,unredook) 1
  
  # nastavi undo na zmazanie novych a undelete originalnej
  # a redo na undelete novych a zmazanie originalnej
  xth_me_unredo_action [mc "split line"] \
    "xth_me_cmds_delete $id1; xth_me_cmds_delete $id2; xth_me_cmds_undelete $id $pid $ix; xth_me_center_to {$prev_center}" \
    "xth_me_cmds_undelete $id1 $pid1 $ix; xth_me_cmds_undelete $id2 $pid2 $ix; xth_me_cmds_delete $id; xth_me_cmds_select {$id2 $pid2}; xth_me_center_to {$prev_center}"

}










proc xth_me_ss_next {} {
  global xth
  xth_me_cmds_update {}
  set cselid $xth(me,cmds,selid)
  set cselpid $xth(me,cmds,selpid)
  set eofvalid [expr $cselid == 0]
  xth_status_bar_push me
  xth_status_bar_status me "Searching ..."
  if {$cselid == 0} {
    set totalcnt [llength $xth(me,cmds,xlist)]
  } else {
    set totalcnt [expr [llength $xth(me,cmds,xlist)] - [lsearch -exact $xth(me,cmds,xlist) $cselid] - 1]
  }
  set cnt 0
  xth_me_progbar_show $totalcnt
  while {($cselid != 0) || $eofvalid} {
    set eofvalid 0    
    # prejde na dalsi objekt
    if {$cselid == 0} {
      set cselid [lindex $xth(me,cmds,xlist) 0]
      if {$xth(me,cmds,$cselid,ct) == 3} {
        set cselpid [lindex $xth(me,cmds,$cselid,xplist) 0]
      } else {
        set cselpid 0
      }
      incr cnt
    } elseif {($xth(me,cmds,$cselid,ct) != 3) || ($cselpid == 0)} {
      set cselid [lindex $xth(me,cmds,xlist) \
          [expr [lsearch -exact $xth(me,cmds,xlist) $cselid] + 1]]
      if {$xth(me,cmds,$cselid,ct) == 3} {
        set cselpid [lindex $xth(me,cmds,$cselid,xplist) 0]
      } else {
        set cselpid 0
      }
      incr cnt
    } else {
      set cselpid [lindex $xth(me,cmds,$cselid,xplist) \
          [expr [lsearch -exact $xth(me,cmds,$cselid,xplist) $cselpid] + 1]]
    }
    xth_me_progbar_prog $cnt
    switch $xth(me,cmds,$cselid,ct) {
      0 {
        xth_me_cmds_select 0
        xth_me_progbar_hide
        xth_status_bar_pop me
        return
      }
      3 {
        if {$cselpid == 0} {
          if {[xth_me_ss_match $xth(me,cmds,$cselid,data_ln)]} {
            xth_me_cmds_select "$cselid 0"
            xth_me_progbar_hide
            xth_status_bar_pop me
            return
          }
        } else {
          if {[xth_me_ss_match [lindex $xth(me,cmds,$cselid,data_pt) \
              [lsearch -exact $xth(me,cmds,$cselid,xplist) $cselpid]]]} {
            xth_me_cmds_select "$cselid $cselpid"
            xth_me_progbar_hide
            xth_status_bar_pop me
            return
          }
        }
      }
      default {
        if {[xth_me_ss_match $xth(me,cmds,$cselid,data)]} {
          xth_me_cmds_select $cselid
          xth_me_progbar_hide
          xth_status_bar_pop me
          return
        }
      }
    }
  }
  xth_me_progbar_hide
  xth_status_bar_pop me
}

proc xth_me_ss_first {} {
  global xth
  xth_me_cmds_update {}
  xth_me_cmds_select 0
  xth_me_ss_next
}


proc xth_me_ss_match {s} {
  global xth
  if $xth(ctrl,me,ss,regexp) {
    if $xth(ctrl,me,ss,cases) {
      return [regexp $xth(ctrl,me,ss,expr) $s]
    } else {
      return [regexp -nocase $xth(ctrl,me,ss,expr) $s]
    }
  } else {
    if $xth(ctrl,me,ss,cases) {
      if {[string first $xth(ctrl,me,ss,expr) $s] >= 0} {
        return 1
      } else {
        return 0
      }
    } else {
      if {[string first [string tolower $xth(ctrl,me,ss,expr)] [string tolower $s]] >= 0} {
        return 1
      } else {
        return 0
      }
    }
  }
}


proc xth_me_ss_show {} {
  global xth
  xth_me_cmds_update {}
  xth_me_cmds_set_colors
  set selcol red
  xth_status_bar_push me
  xth_status_bar_status me "Searching ..."
  xth_me_progbar_show [llength $xth(me,cmds,xlist)]
  set objcnt 0
  foreach id $xth(me,cmds,xlist) {
    incr objcnt
    xth_me_progbar_prog $objcnt
    switch $xth(me,cmds,$id,ct) {
      2 {
        if {[xth_me_ss_match $xth(me,cmds,$id,data)]} {
          # oznaci bod
          $xth(me,can) itemconfigure pt$id -fill $selcol
        }
      }
      3 {
        set pnm 0
        set trywhole 1
        foreach tx $xth(me,cmds,$id,data_pt) {
          if {[xth_me_ss_match $tx]} {
            set pid [lindex $xth(me,cmds,$id,xplist) $pnm]
            # oznaci bod na ciare
            set trywhole 0
            $xth(me,can) itemconfigure pt$id.$pid -fill $selcol
            set ppid [lindex $xth(me,cmds,$id,xplist) [expr $pnm + 1]]
            if {[string length $ppid] > 0} {
              $xth(me,can) itemconfigure ln$id.$ppid -fill $selcol
            }
          }
          incr pnm 1
        }
        if {$trywhole && [xth_me_ss_match $xth(me,cmds,$id,data_ln)]} {
          # oznaci ciaru
          $xth(me,can) itemconfigure lnln$id -fill $selcol
        }
      }
    }
  }
  xth_status_bar_pop me
  xth_me_progbar_hide
}


proc xth_me_goto_line {ln} {

  global xth
  if {!$xth(me,fopen)} {
    return
  }
  
  # najprv preskoci zaciatocne prikazy
  set cln [expr [llength $xth(me,imgs,xlist)] + 4]
  
  # potom poojde prikaz za prikazom az najde taky,
  # ktory lezi na danej, alebo je mensi ako dana
  # pozicia a nasledujuci prikaz je uz zase vacsi
  set previd [lindex $xth(me,cmds,xlist) 0]
  set prevln $cln
  foreach cid $xth(me,cmds,xlist) {
    if {$xth(me,cmds,$cid,ct) == 4} {
      incr cln 2
    }
    incr cln 1
    
    # skontrolujeme ci to nebol predchadzajuci
    if {$cln > $ln} {
      xth_me_cmds_select $previd
      return
    }    
    # resp. ci to nie je tento
    set prevln $cln
    incr cln [expr 1 + [regexp -all {\n} $xth(me,cmds,$cid,data)]]
    #puts "$prevln - $cln:\n$xth(me,cmds,$cid,data)"

    if {($ln >= $prevln) && ($ln < $cln)} {
      set posttry 0
      switch $xth(me,cmds,$cid,ct) {
        1 {
          xth_ctrl_scroll_to me text
          set posttry 1
        }
        2 {xth_ctrl_scroll_to me point}
        3 {xth_ctrl_scroll_to me line}
        4 {xth_ctrl_scroll_to me scrap}
        6 {xth_ctrl_scroll_to me area}
      }
      xth_me_cmds_select $cid
      if {($ln > $prevln) || $posttry} {
        # skusime sa trafit presnejsie
        switch $xth(me,cmds,$cid,ct) {
          1 {
            set txln [expr $ln - $prevln + 1]
            focus $xth(ctrl,me,text).txt
            $xth(ctrl,me,text).txt mark set insert $txln.0
            $xth(ctrl,me,text).txt tag remove sel 1.0 end
            $xth(ctrl,me,text).txt tag add sel $txln.0 "$txln.0 lineend"
          }
          3 {
            # skusime najst bod na ciare
            set txln [expr $ln - $prevln + 1]
            if {$txln > 1} {
              set tmpxpl $xth(me,cmds,$cid,xplist)
              #puts $tmpxpl
              set cxpl {}
              set cpix [lindex $tmpxpl]
              foreach pix [lrange $tmpxpl 0 [expr [llength $tmpxpl] - 2]] {
                lappend cxpl $pix
                catch {
                  set xth(me,cmds,$cid,xplist) "$cxpl 0"
                  xth_me_cmds_update_line_data $cid
                }
                set clnln [regexp -all {\n} $xth(me,cmds,$cid,data)]
                set xth(me,cmds,$cid,xplist) $tmpxpl
                #puts "$clnln -> $txln:\n$xth(me,cmds,$cid,data)"
                if {$clnln >= $txln} {
                  set cpix $pix
                  #puts $pix
                  break
                }
              }
              set xth(me,cmds,$cid,xplist) $tmpxpl
              xth_me_cmds_update_line_data $cid
              xth_me_cmds_select "$cid $pix"
              xth_ctrl_scroll_to me linept
            }
          }
        }
      }
      return
    }
    
    set previd $cid
    
  }
  
  xth_me_cmds_select [lindex $xth(me,cmds,xlist) 0]
  
}


proc xth_me_ss_next_cmd {type} {
  global xth
  set cselid $xth(me,cmds,selid)
  set cpos [lsearch -exact $xth(me,cmds,xlist) $cselid]
  if {$cpos < 0} {set cpos 0}
  set tlen [llength $xth(me,cmds,xlist)]
  set nxlist [lrange $xth(me,cmds,xlist) [expr $cpos + 1] end]
  append nxlist " [lrange $xth(me,cmds,xlist) 0 $cpos]"
  foreach xx $nxlist {
    if {$xth(me,cmds,$xx,ct) == $type} {
      xth_me_cmds_select $xx
      break
    }
  }
}






xth_about_status [mc "loading map editor ..."]

catch {package require Img}

set xth(me,dflt,scrap,scale) {}

proc xth_me_reset_defaults {} {
  global xth

  set xth(me,dflt,scrap,projection) {}
  set xth(me,dflt,scrap,options) {}

  set xth(me,dflt,point,type) {station}
  set xth(me,dflt,point,options) {}
  set xth(me,dflt,point,rotation) {}
  set xth(me,dflt,point,xsize) {}
  set xth(me,dflt,point,ysize) {}

  set xth(me,dflt,line,type) {wall}
  set xth(me,dflt,line,options) {}

  set xth(me,dflt,area,type) {water}
  set xth(me,dflt,area,options) {}
    
}

xth_me_reset_defaults

proc xth_me_bind_entry_focusin {wlist} {
  foreach w $wlist {
    bind $w <FocusIn> "$w selection range 0 end"
  }
}

proc xth_me_bind_entry_return {wlist retcmd} {
  foreach w $wlist {
    bind $w <Return> $retcmd
  }
}

proc xth_me_bind_entry_focus_return {wlist retcmd} {
  set llen [expr [llength $wlist] - 1]
  for {set i 0} {$i < $llen} {incr i} {
    bind [lindex $wlist $i] <Return> "focus [lindex $wlist [expr $i + 1]]"
  }
  bind [lindex $wlist end] <Return> "$retcmd\nfocus [lindex $wlist 0]"
}


proc xth_me_bind_typecbx_hint {pth smbl} {
  $pth _create_popup
  bind $pth.shell.listb <Map> "xth_status_bar_push me\nevent generate $pth.shell.listb <<ListboxSelect>> -when tail"
  bind $pth.shell.listb <Unmap> "xth_status_bar_pop me"
  bind $pth.shell.listb <<ListboxSelect>> [format {
    set vals [%s cget -values]
    xth_status_bar_status me [ mc "%s [lindex $vals [%s.shell.listb curselection]]"]
    } $pth $smbl $pth]
}


proc xth_me_unredo_reset {} {
  global xth
  set xth(me,undolist) {}
  set xth(me,redolist) {}
  set xth(me,unredook) 1
  xth_me_unredo_update
}


proc xth_me_real2canx {x} {
  global xth
  return [expr 0.01 * $xth(me,zoom) * $x]
}

proc xth_me_real2cany {y} {
  global xth
  return [expr -0.01 * $xth(me,zoom) * $y]
}

proc xth_me_can2realx {x} {
  global xth
  return [expr 100.0 / $xth(me,zoom) * $x]
}

proc xth_me_can2realy {y} {
  global xth
  return [expr -100.0 / $xth(me,zoom) * $y]
}

proc xth_me_unredo_update {} {
  
  global xth
  
  if {[llength $xth(me,undolist)] > 0} {
    $xth(me,menu,edit) entryconfigure $xth(me,menu,edit,undo) \
      -label [format [mc "Undo %s"] [lindex [lindex $xth(me,undolist) 0] 0]] -state normal
  } else {
    $xth(me,menu,edit) entryconfigure $xth(me,menu,edit,undo) \
      -label [mc "Undo"] -state disabled
  }

  if {[llength $xth(me,redolist)] > 0} {
    $xth(me,menu,edit) entryconfigure $xth(me,menu,edit,redo) \
      -label [format [mc "Redo %s"] [lindex [lindex $xth(me,redolist) 0] 0]] -state normal
  } else {
    $xth(me,menu,edit) entryconfigure $xth(me,menu,edit,redo) \
      -label [mc "Redo"] -state disabled
  }

}


proc xth_me_unredo_undo {} {

  global xth
  xth_me_cmds_update {}
  if {[llength $xth(me,undolist)] > 0} {
    set acmd [lindex $xth(me,undolist) 0]
    set xth(me,undolist) [lreplace $xth(me,undolist) 0 0]
    set xth(me,redolist) [linsert $xth(me,redolist) 0 $acmd]
    set xth(me,unredook) 0
    set xth(me,unredoshift) 1
    eval [lindex $acmd 3]
    set xth(me,unredook) 1
    if {$xth(me,unredoshift)} {
      $xth(me,can) xview moveto [lindex $acmd 1]
      $xth(me,can) yview moveto [lindex $acmd 2]
      xth_me_images_rescandraw
    }
    set xth(me,fsave) 1
    xth_me_unredo_update
  }  
}


proc xth_me_get_center {} {
  global xth
  set x [winfo x $xth(me,can)]
  set y [winfo y $xth(me,can)]
  set w [winfo width $xth(me,can)]
  set h [winfo height $xth(me,can)]
  return [list [xth_me_can2realx [$xth(me,can) canvasx [expr $x + $w / 2]]] \
    [xth_me_can2realy [$xth(me,can) canvasy [expr $y + $h / 2]]]]
}


proc xth_me_center_to {crds} {
  global xth
  set x [xth_me_real2canx [lindex $crds 0]]
  set y [xth_me_real2cany [lindex $crds 1]]
  set sr [$xth(me,can) cget -scrollregion]
  set xw [$xth(me,can) xview]
  set yw [$xth(me,can) yview]
  # adjust x
  set wf [expr [lindex $xw 1] - [lindex $xw 0]]
  set hf [expr [lindex $yw 1] - [lindex $yw 0]]
  set tw [expr [lindex $sr 2] - [lindex $sr 0]]
  set th [expr [lindex $sr 3] - [lindex $sr 1]]
  if {double($wf) < 1.0} {
    set pp [expr double($x) - [lindex $sr 0] - \
      0.5 * $wf * $tw]
    if {$pp < 0} {
      set pf 0.0
    } else {
      set pf [expr double($pp) / $tw]
    }
    $xth(me,can) xview moveto $pf
  }
  # adjust y
  if {double($hf) < 1.0} {
    set pp [expr double($y) - [lindex $sr 1] - \
      0.5 * $hf * $th]
    if {$pp < 0} {
      set pf 0.0
    } else {
      set pf [expr double($pp) / $th]
    }
    $xth(me,can) yview moveto $pf
  }
  xth_me_images_rescandraw
}



proc xth_me_unredo_redo {} {

  global xth

  if {[llength $xth(me,redolist)] > 0} {
    set acmd [lindex $xth(me,redolist) 0]
    set xth(me,redolist) [lreplace $xth(me,redolist) 0 0]
    set xth(me,undolist) [linsert $xth(me,undolist) 0 $acmd]
    $xth(me,can) xview moveto [lindex $acmd 1]
    $xth(me,can) yview moveto [lindex $acmd 2]
    xth_me_images_rescandraw
    set xth(me,unredook) 0
    eval [lindex $acmd 4]
    set xth(me,unredook) 1
    set xth(me,fsave) 1
    xth_me_unredo_update
  }  
  
}


proc xth_me_unredo_action {txt undocmd redocmd} {
  
  global xth
  if {$xth(me,unredook)} {
    set xth(me,redolist) {}
    if {[string length $xth(me,unredola)] > 0} {
      set txt $xth(me,unredola)
      set xth(me,unredola) {}
    }
    set xth(me,undolist) [linsert $xth(me,undolist) 0 [list \
      $txt [lindex [$xth(me,can) xview] 0] [lindex [$xth(me,can) yview] 0] $undocmd $redocmd]]
    set xth(me,fsave) 1
    xth_me_unredo_update
  }
  
}


# create new file
proc xth_me_create_file {} {

  global xth
  xth_status_bar_status me ""
  
  # create file variables
  set xth(me,unredook) 0
  incr xth(me,fltid)
  set cfid $xth(me,fltid)
  #set xth(me,fname) [format "noname%02d.th2" $cfid]
  set xth(me,fname) [format "(new file)" $cfid]
  set xth(me,open_file) $xth(me,fname)
  set xth(me,fpath) $xth(gui,initdir)
  set xth(me,ffull) [file join $xth(gui,initdir) $xth(me,fname)]

  set xth(me,fnewf) 1
  set xth(me,fopen) 1
  set xth(me,fsave) 0
  set xth(me,mtime) 0

  set xth(me,nimgs) 0
  set xth(me,imgln) 0
  set xth(me,imgs,list) {}
  set xth(me,imgs,xlist) {}

  set xth(me,cmds,cmdln) 1
  set xth(me,cmds,list) {}
  set xth(me,cmds,xlist) {}
  set xth(me,cmds,action) {}
  set xth(me,cmds,selid) 0
  set xth(me,cmds,selpid) 0
  set xth(me,cmds,selx) 0
  set xth(me,cmds,mode) 0
  xth_me_cmds_create 0 0 0
  xth_me_cmds_update_buttons
  xth_me_cmds_set_mode 0
  xth_me_prev_cmd {}
  $xth(ctrl,me,cmds).cl.l selection set 0 0

  # enable all controls
  $xth(me,pbar) configure -state normal -text "0.0 : 0.0"
  
  $xth(ctrl,me,images).ic.insp configure -state normal
  $xth(ctrl,me,area).l configure -state normal
  $xth(ctrl,me,area).zl configure -state normal
  $xth(ctrl,me,area).zb configure -state normal
    
  $xth(me,menu,file) entryconfigure [mc "New"] -state disabled
  $xth(me,menu,file) entryconfigure [mc "Open"] -state disabled
  $xth(me,menu,file) entryconfigure [mc "Open (no pics)"] -state disabled
  $xth(me,menu,file) entryconfigure [mc "Save"] -state normal
  $xth(me,menu,file) entryconfigure [mc "Save as"] -state normal
  $xth(me,menu,file) entryconfigure [mc "Auto save"] -state normal
  $xth(me,menu,file) entryconfigure [mc "Close"] -state normal
  
  $xth(me,menu) entryconfigure [mc "Edit"] -state normal

  $xth(ctrl,me,area).xmin configure -state normal
  $xth(ctrl,me,area).ymin configure -state normal
  $xth(ctrl,me,area).xmax configure -state normal
  $xth(ctrl,me,area).ymax configure -state normal
  $xth(ctrl,me,area).mab configure -state normal
  $xth(ctrl,me,area).aab configure -state normal

  xth_me_image_select 0
  xth_me_cmds_set_action 2

  # create working area
  grid $xth(me,canf) -column 0 -row 0 -sticky news
  xth_me_area_adjust 0 0 1600 1200

  xth_app_title me  

  xth_ctrl_maximize me area
  xth_ctrl_maximize me images
  set xth(me,fsave) 0
  xth_me_unredo_reset
  xth_me_reset_defaults  
  xth_tools_me_enable
}


proc xth_me_prev_cmd {cmd} {
  global xth
  $xth(ctrl,me,prev).txt configure -state normal
  $xth(ctrl,me,prev).txt delete 1.0 end
  $xth(ctrl,me,prev).txt insert 1.0 $cmd
  $xth(ctrl,me,prev).txt configure -state disabled
  $xth(ctrl,me,prev).txt see 1.0
  update idletasks
}


proc xth_me_destroy_file {} {

  global xth
  if {$xth(me,fopen)} {
  
    xth_me_cmds_unselect {}

    set xth(me,unredook) 0
    set xth(me,open_file) ""
    set xth(me,curscrap) {}
    set xth(me,fnewf) 0
    set xth(me,fopen) 0
    xth_me_image_destroy_all
    set xth(me,fsave) 0

    set xth(me,zoom) 100
    set xth(me,zoomv) 100
    $xth(ctrl,me,area).zb configure -text [format "%d %%" 100]
    $xth(me,menu,edit) entryconfigure $xth(me,menu,edit,zoom) -label [format "Zoom %d %%" 100]
  
    # disable all controls
    $xth(me,pbar) configure -text "" -state disabled

    set xth(ctrl,me,images,posx) ""
    set xth(ctrl,me,images,posy) ""
    set xth(ctrl,me,images,vis) 0
    $xth(ctrl,me,images).ic.insp configure -state disabled
    $xth(ctrl,me,area).l configure -state disabled -text ""
    set xth(ctrl,me,area,xmin) ""
    set xth(ctrl,me,area,ymin) ""
    set xth(ctrl,me,area,xmax) ""
    set xth(ctrl,me,area,ymax) ""
    $xth(ctrl,me,area).zl configure -state disabled
    $xth(ctrl,me,area).zb configure -state disabled
    $xth(me,menu,file) entryconfigure [mc "New"] -state normal
    $xth(me,menu,file) entryconfigure [mc "Open"] -state normal
    $xth(me,menu,file) entryconfigure [mc "Open (no pics)"] -state normal
    $xth(me,menu,file) entryconfigure [mc "Save"] -state disabled
    $xth(me,menu,file) entryconfigure [mc "Save as"] -state disabled
    $xth(me,menu,file) entryconfigure [mc "Auto save"] -state disabled
    $xth(me,menu,file) entryconfigure [mc "Close"] -state disabled

    $xth(me,menu) entryconfigure [mc "Edit"] -state disabled

    $xth(ctrl,me,area).xmin configure -state disabled
    $xth(ctrl,me,area).ymin configure -state disabled
    $xth(ctrl,me,area).xmax configure -state disabled
    $xth(ctrl,me,area).ymax configure -state disabled
    $xth(ctrl,me,area).mab configure -state disabled
    $xth(ctrl,me,area).aab configure -state disabled
    xth_me_image_select 0
    focus $xth(gui,main)

    $xth(me,can) delete command
    xth_me_cmds_update_buttons
    xth_me_prev_cmd {}
    
    set xth(me,cmds,list) {}
    set xth(me,cmds,xlist) {}
    grid forget $xth(me,canf) 
    
    xth_ctrl_minimize me cmds
    xth_ctrl_minimize me prev
    xth_ctrl_minimize me ss
    xth_ctrl_minimize me point
    xth_ctrl_minimize me line
    xth_ctrl_minimize me linept
    xth_ctrl_minimize me ac
    xth_ctrl_minimize me scrap
    xth_ctrl_minimize me text
    xth_ctrl_minimize me area
    xth_ctrl_minimize me images
    
    xth_me_unredo_reset
    xth_app_title me
    
  }
  xth_tools_me_enable
}



proc xth_me_before_close_file {btns} {

  global xth
  xth_me_cmds_update {}
  if {$xth(me,fsave)} {    
    set wtd [MessageDlg $xth(gui,message) -parent $xth(gui,main) \
      -icon question -type $btns\
      -message [format [mc "File %s is not saved. Save it now?"] $xth(me,ffull)] \
      -font $xth(gui,lfont)]
    switch $wtd {
      0 {
        if {[xth_me_save_file 0] == 0} {
          return 0
        }
      }
      1 {}
      default {return 0}
    }
  }
  return 1
}



# xth_me_read_file --
#
# return success
# {success name cmds lns}

proc xth_me_read_file {pth changebs} {

  global errorInfo xth
  
  set curenc utf-8
  set nm [file tail $pth]
  set encspc 0
  set flnn 0
  set success 1
  set lastln ""
  set lns {}
  set cmds {}
  if {[catch {set fid [open $pth r]}]} {
    set success 0
    set nm $errorInfo
    return [list $success $nm {} {}]
  }
  fconfigure $fid -encoding $curenc
  while {![eof $fid]} {
    gets $fid fln
    incr flnn
    if {[regexp {^\s*encoding\s+(\S+)\s*$} $fln encln enc]} {
      if {$encspc} {
        set success 0
        set nm [format [mc "%s \[%s\] -- multiple encoding commands in file"] $pth $flnn]
        break
      }
      set encspc 1
      set rxp "\\s+($enc)\\s+"
      set validenc [regexp -nocase $rxp $xth(encodings) dum curenc]
      if {$validenc == 0} {
        set success 0
        set nm [format [mc "%s \[%s\] -- unknown encoding -- %s"] $pth $flnn $enc]
        break
      }
      fconfigure $fid -encoding $curenc
      set lastln ""
    } elseif {[regexp {^\s*\#\#XTHERION\#\#\s+(\S.*)\s*$} $fln cmmdln cmmd]} {
      lappend cmds $cmmd
      set lastln ""
      if {[regexp {^\s*\#\#BEGIN\#\#\s*$} $cmmd]} {
        fconfigure $fid -encoding utf-8
      }
      if {[regexp {^\s*\#\#END\#\#\s*$} $cmmd]} {
        fconfigure $fid -encoding $curenc
      }
    } else {
      if {$changebs && [regexp {(.*)\\\s*$} $lastln dumln prevln]} {
        set fln "$prevln$fln"
        if {[llength $lns] > 1} {
          set lns [lrange $lns 0 [expr [llength $lns] - 2]]
        } else {
          set lns {}
        }
      }
      lappend lns $fln
      set lastln $fln
    }
  }
  close $fid
  return [list $success $nm $cmds $lns]
  
}  


# xth_me_write_file --
#
# return list containing
# {success name}

proc xth_me_write_file {pth} {

  global errorInfo xth

  set curenc utf-8
  set nm [file tail $pth]
  set success 1
  if {[catch {set fid [open $pth w]}]} {
    set success 0
    set nm $errorInfo
    return [list $success $nm]
  }
  fconfigure $fid -encoding utf-8 -translation {auto lf}
  puts $fid "encoding  utf-8"
  # now let's put special commands
  puts $fid "##XTHERION## xth_me_area_adjust $xth(me,area,xmin) $xth(me,area,ymin) $xth(me,area,xmax) $xth(me,area,ymax)"
  puts $fid "##XTHERION## xth_me_area_zoom_to $xth(me,zoom)"
  # images
  set xxlist {}
  foreach imgx $xth(me,imgs,xlist) {
    set xxlist [linsert $xxlist 0 $imgx]
  }
  foreach imgx $xxlist {
    set vsb $xth(me,imgs,$imgx,vsb)
    set gamma $xth(me,imgs,$imgx,gamma)
    if {$vsb < 0} {
      set vsb [expr $xth(me,imgs,$imgx,vsb) + 2]
    }
    set root [xth_me_imgs_get_root $imgx]
    set xpos [expr [lindex $xth(me,imgs,$imgx,position) 0]]
    set ypos [expr [lindex $xth(me,imgs,$imgx,position) 1]]
    switch [llength $root] {
      1 {
        set ypos [list $ypos [lindex $root 0]]
      }
      3 {
        set xpos [lindex $root 1]
        set ypos [list [lindex $root 2] [lindex $root 0]]
      }
      0 {}
    }
    puts $fid [format "##XTHERION## xth_me_image_insert %s %s %s 0 {}" \
      "{$xpos $vsb $gamma}" \
      "{$ypos}" \
      [list $xth(me,imgs,$imgx,name)]]
  }
  foreach id $xth(me,cmds,xlist) {
    if {$xth(me,cmds,$id,ct) == 4} {
      puts $fid "\n"
    }
    puts $fid "\n$xth(me,cmds,$id,data)"
  }
  close $fid
  return [list $success $nm]
}


proc xth_me_open_file {dialogid fname fline} {

  global xth

  if {$xth(me,fopen) != 0} {
    return 0
  }
  
  if {$dialogid} {
    set fname [tk_getOpenFile -filetypes $xth(app,me,filetypes) \
      -parent $xth(gui,main) \
      -initialdir $xth(gui,initdir) -defaultextension {.th2}]
  }
  
  if {[string length $fname] == 0} {
    return 0
  } else {
    set xth(gui,initdir) [file dirname $fname]
  }
  
  # now let's open file fname
  
  # read the file
  xth_status_bar_push me
  xth_status_bar_status me [format [mc "Opening %s ..."] $fname]
  
  set fdata [xth_me_read_file $fname 1]
  if {[lindex $fdata 0] == 0} {
      MessageDlg $xth(gui,message) -parent $xth(gui,main) \
        -icon error -type ok \
        -message [lindex $fdata 1] \
        -font $xth(gui,lfont)
      xth_status_bar_pop me
      return 0
  }
  
  # show the file
  xth_me_create_file
  set xth(me,unredook) 0

  set xth(me,fname) [file tail $fname]
  set xth(me,open_file) [lindex $fdata 1]
  set xth(me,fpath) [file dirname $fname]
  set xth(me,ffull) $fname
  set xth(me,mtime) [file mtime $fname]
  
  foreach cmd [lindex $fdata 2] {
    catch {eval $cmd}
  }
  xth_me_cmds_create_all [lindex $fdata 3]
  
  xth_ctrl_maximize me cmds
  xth_ctrl_maximize me point
  xth_ctrl_maximize me line
  xth_ctrl_maximize me linept
  xth_ctrl_maximize me ac
  xth_ctrl_maximize me scrap
  xth_ctrl_maximize me text
  xth_ctrl_maximize me area
  xth_ctrl_maximize me images
  
  set xth(me,fnewf) 0
  set xth(me,fopen) 1
  set xth(me,fsave) 0
  xth_app_title me
  xth_status_bar_pop me
  xth_me_cmds_select 0
  xth_me_unredo_reset
  xth_me_reset_defaults
  return 1
}


proc xth_me_save_file {dialogid} {

  global xth
  if {$xth(me,fopen) == 0} {
    return 0
  }

  xth_me_cmds_update {}
  
  # let's check if we need to save
  if {!($xth(me,fnewf) || $xth(me,fsave) || $dialogid)} {
    return 1
  }
  
  xth_status_bar_push me
  
  if {$xth(me,fnewf)} {
    set dialogid 1
  }

  set fname $xth(me,ffull)
  set ofname $fname
  if {$dialogid} {
    set fname [tk_getSaveFile -filetypes $xth(app,me,filetypes) \
      -parent $xth(gui,main) \
      -initialfile [file tail $fname] -defaultextension {.th2} \
      -initialdir [file dirname $fname]]
  }
  
  if {[string length $fname] == 0} {
    return 0
  } else {
    set xth(gui,initdir) [file dirname $fname]
  }

  if {($xth(me,mtime) > 0) && [file exists $fname] && \
    ([file mtime $fname] > $xth(me,mtime))} {
    set forcesave [MessageDlg $xth(gui,message) -parent $xth(gui,main) \
      -icon warning -type yesno -default 1 \
      -message [format [mc "File %s was modified outside xtherion. Save it anyway?"] $fname] \
      -font $xth(gui,lfont)]
    if {$forcesave != 0} {
      return 0
    }
  }
 
  # save the file
  xth_status_bar_status me [format [mc "Saving %s ..."] $fname]
  set fdata [xth_me_write_file $fname]
  if {[lindex $fdata 0] == 0} {
      MessageDlg $xth(gui,message) -parent $xth(gui,main) \
        -icon error -type ok \
        -message [lindex $fdata 1] \
        -font $xth(gui,lfont)
      xth_status_bar_pop me
      return 0
  }
  
  set xth(me,mtime) [file mtime $fname]
  set xth(me,fnewf) 0
  set xth(me,fsave) 0
  
  # if SaveAs, then redisplay the file
  if {$dialogid} {
    if {[string compare $ofname $fname] != 0} {
      set xth(me,fname) [file tail $fname]
      set xth(me,ffull) $fname
      set xth(me,fpath) [file dirname $fname]
      set xth(me,open_file) $xth(me,fname)
      xth_app_title me
    }
  }  

  after 250 {xth_status_bar_pop me}
  return 1
    
}



proc xth_me_close_file {} {

  global xth

  if {$xth(me,fopen) == 0} {
    return
  }

  xth_me_cmds_update {}
  
  if {[xth_me_before_close_file yesnocancel]} {
    xth_me_destroy_file
    return 1
  } else {
    return 0
  }
  
}


proc xth_me_area_redraw {} {
  global xth
  set x1 [xth_me_real2canx $xth(me,area,xmin)]
  set x2 [xth_me_real2canx $xth(me,area,xmax)]
  set y1 [xth_me_real2cany $xth(me,area,ymin)]
  set y2 [xth_me_real2cany $xth(me,area,ymax)]
  $xth(me,can) coords $xth(me,canid,area) $x1 $y1 $x1 $y2 $x2 $y2 $x2 $y1  
}


proc xth_me_limitize {limits x y} {
  set xmin $x
  set xmax $x
  set ymin $y
  set ymax $y
  if {[llength $limits] == 4} {
    if {[lindex $limits 0] < $x} {
      set xmin [lindex $limits 0]
    }
    if {[lindex $limits 1] < $y} {
      set ymin [lindex $limits 1]
    }
    if {[lindex $limits 2] > $x} {
      set xmax [lindex $limits 2]
    }
    if {[lindex $limits 3] > $y} {
      set ymax [lindex $limits 3]
    }
  }
  return [list $xmin $ymin $xmax $ymax]
}


proc xth_me_area_auto_adjust {} {
  
  global xth 
  set limits {}
  
  # scan limits of pictures
  foreach imgx $xth(me,imgs,xlist) {
    set px [lindex $xth(me,imgs,$imgx,position) 0]
    set py [lindex $xth(me,imgs,$imgx,position) 1]
    set limits [xth_me_limitize $limits $px $py]
    if {$xth(me,imgs,$imgx,XVI)} {
      set gv $xth(me,imgs,$imgx,XVIgrid)
      set v1x [expr [lindex $gv 2] * ([lindex $gv 6] - 1.0)]
      set v1y [expr [lindex $gv 3] * ([lindex $gv 6] - 1.0)]
      set v2x [expr [lindex $gv 4] * ([lindex $gv 7] - 1.0)]
      set v2y [expr [lindex $gv 5] * ([lindex $gv 7] - 1.0)]
      set limits [xth_me_limitize $limits [expr $px + $v1x] [expr $py + $v1y]]
      set limits [xth_me_limitize $limits [expr $px + $v2x] [expr $py + $v2y]]
      set limits [xth_me_limitize $limits [expr $px + $v1x + $v2x] [expr $py + $v1y + $v2y]]
    } elseif {[string length $xth(me,imgs,$imgx,image)] > 0} {
      set sx [image width $xth(me,imgs,$imgx,image)]
      set sy [image height $xth(me,imgs,$imgx,image)]
      set limits [xth_me_limitize $limits [expr $px + $sx] [expr $py - $sy]]
    }
  }
  
  # scan limits of commands
  set cmdlim [$xth(me,can) bbox command]
  if {[llength $cmdlim] == 4} {
    set limits [xth_me_limitize $limits [xth_me_can2realx [lindex $cmdlim 0]] [xth_me_can2realy [lindex $cmdlim 1]]]
    set limits [xth_me_limitize $limits [xth_me_can2realx [lindex $cmdlim 2]] [xth_me_can2realy [lindex $cmdlim 3]]]
  }
  
  # adjust area limits
  if {[llength $limits] < 4} {
    set limits {128 128 128 128}
  }  
  xth_me_area_adjust [expr [lindex $limits 0] - 128] [expr [lindex $limits 1] - 128] \
    [expr [lindex $limits 2] + 128] [expr [lindex $limits 3] + 128]

}

proc xth_me_area_adjust {x1 y1 x2 y2} {
  
  global xth
  
  xth_me_unredo_action [mc "adjusting area"] \
    "xth_me_area_adjust $xth(me,area,xmin) $xth(me,area,ymin) $xth(me,area,xmax) $xth(me,area,ymax)" \
    "xth_me_area_adjust $x1 $y1 $x2 $y2"

  # let's assign zeros to non numbers
  if {[catch {expr $x1}]} {
    set x1 0.0
  }
  if {[catch {expr $x2}]} {
    set x2 0.0
  }
  if {[catch {expr $y1}]} {
    set y1 0.0
  }
  if {[catch {expr $y2}]} {
    set y2 0.0
  }
  if {($x2 - $x1) < 256} {
    set x2 [expr $x1 + 256]
  }
  if {($y2 - $y1) < 256} {
    set y2 [expr $y1 + 256]
  }
  
  set xth(me,area,xmin) $x1
  set xth(me,area,xmax) $x2
  set xth(me,area,ymin) $y1
  set xth(me,area,ymax) $y2

  set xth(ctrl,me,area,xmin) $x1
  set xth(ctrl,me,area,xmax) $x2
  set xth(ctrl,me,area,ymin) $y1
  set xth(ctrl,me,area,ymax) $y2

  xth_me_area_redraw
  xth_me_area_scroll_adjust
  
  catch {$xth(ctrl,me,area).l configure -text [format "%.0f:%.0f - %.0f:%.0f" $x1 $y1 $x2 $y2]}
  
}


proc xth_me_area_scroll {wdg fir las} {
  xth_scroll $wdg $fir $las
  xth_me_area_scroll_adjust
}


proc xth_me_area_scroll_adjust {} {
  
  global xth
  set scw [winfo width $xth(me,canf)]
  set sch [winfo height $xth(me,canf)]
  set axmax [xth_me_real2canx $xth(me,area,xmax)]
  set axmin [xth_me_real2canx $xth(me,area,xmin)]
  set aymax [xth_me_real2cany $xth(me,area,ymin)]
  set aymin [xth_me_real2cany $xth(me,area,ymax)]
  set aw [expr $axmax - $axmin]
  set ah [expr $aymax - $aymin]
  if {$aw < ($scw - 3 * $xth(gui,sbwidth))} {
    set sx1 [expr $axmin - ($scw - $aw)/2.0 + $xth(gui,sbwidth)]
    set sx2 [expr $axmax + ($scw - $aw)/2.0 - $xth(gui,sbwidth)]
    # eval $xth(scroll,$xth(me,canf).sh,hide)
  } else {
    set sx1 [expr $axmin - $xth(gui,sbwidth)/2.0]
    set sx2 [expr $axmax + $xth(gui,sbwidth)/2.0]
  }
  if {$ah < ($sch - 3 * $xth(gui,sbwidth))} {
    set sy1 [expr $aymin - ($sch - $ah)/2.0 + $xth(gui,sbwidth)]
    set sy2 [expr $aymax + ($sch - $ah)/2.0 - $xth(gui,sbwidth)]
    # eval $xth(scroll,$xth(me,canf).sv,hide)
  } else {
    set sy1 [expr $aymin - $xth(gui,sbwidth)/2.0]
    set sy2 [expr $aymax + $xth(gui,sbwidth)/2.0]
  }
  
  set csr [$xth(me,can) cget -scrollregion]
  set nsr "$sx1 $sy1 $sx2 $sy2"
  if {[string compare $csr $nsr] != 0} {
    $xth(me,can) configure -scrollregion $nsr
  }
}


proc xth_me_area_zoom_to {zv} {
  global xth
  
  xth_me_cmds_update {}
  
  if {($xth(me,cmds,$xth(me,cmds,selid),ct) == 3) && 
      ($xth(me,cmds,selpid) > 0)} {
    set ccrds [list $xth(me,cmds,$xth(me,cmds,selid),$xth(me,cmds,selpid),x) \
      $xth(me,cmds,$xth(me,cmds,selid),$xth(me,cmds,selpid),y)]
  } elseif {$xth(me,cmds,$xth(me,cmds,selid),ct) == 2} {
    set ccrds [list $xth(me,cmds,$xth(me,cmds,selid),x) \
      $xth(me,cmds,$xth(me,cmds,selid),y)]
  } else {
    set ccrds [xth_me_get_center]
  }
  
  xth_me_unredo_action [mc "zooming"] \
    "xth_me_area_zoom_to $xth(me,zoom)" \
    "xth_me_area_zoom_to $zv"
    
  set xth(me,zoom) $zv
  set xth(me,zoomv) $zv
  $xth(ctrl,me,area).zb configure -text [format "%d %%" $zv]
  $xth(me,menu,edit) entryconfigure $xth(me,menu,edit,zoom) -label [format [mc "Zoom %d %%"] $zv]
  
  xth_me_area_redraw   
  xth_me_area_scroll_adjust
  
  foreach imgx $xth(me,imgs,xlist) {
    xth_me_image_rescan $imgx
    xth_me_image_redraw $imgx
  }
  
  xth_status_bar_push me
  xth_status_bar_status me [mc "Zooming objects ..."]
  set ncmds [llength $xth(me,cmds,xlist)]
  xth_me_progbar_show $ncmds
  set ccmd 0
  foreach id $xth(me,cmds,xlist) {
    incr ccmd
    xth_me_progbar_prog $ccmd
    switch $xth(me,cmds,$id,ct) {
      4 {
        if {$id == $xth(me,cmds,selid)} {
          xth_me_cmds_move_scrap_xctrl 1 [lindex $xth(me,cmds,$id,scale) 0] \
            [lindex $xth(me,cmds,$id,scale) 1] 
          xth_me_cmds_move_scrap_xctrl 2 [lindex $xth(me,cmds,$id,scale) 2] \
            [lindex $xth(me,cmds,$id,scale) 3]
        }
      }
      3 {
        xth_me_cmds_move_line $id
        if {$id == $xth(me,cmds,selid)} {
          xth_me_cmds_show_line_xctrl $id
          set pid $xth(me,cmds,selpid)
          if {$pid != 0} {
            xth_me_cmds_show_linept_xctrl $id $pid
          }
        }
      }
      2 {
        $xth(me,can) coords pt$id [xth_me_cmds_calc_point_coords $id]
        if {$id == $xth(me,cmds,selid)} {
          xth_me_cmds_move_point_xctrl $id
          xth_me_cmds_move_point_fill_xctrl $id $xth(me,cmds,$id,rotation) $xth(me,cmds,$id,xsize) $xth(me,cmds,$id,ysize)
        }
      }
    }
  }
  
  xth_me_center_to $ccrds
  set xth(me,unredoshift) 0
  xth_me_progbar_hide
  xth_status_bar_pop me
  update idletasks
  
}

proc xth_me_image_choose {imgx} {
  global xth
  xth_me_image_select [lsearch $xth(me,imgs,xlist) $imgx]
}

proc xth_me_area_start_drag {tagOrId imgx x y} {
  global xth
  set hss [$xth(me,canf).sh get]
  set vss [$xth(me,canf).sv get]
  set srg [$xth(me,can) cget -scrollregion]
  set w [expr [lindex $srg 2] - [lindex $srg 0]]
  set h [expr [lindex $srg 3] - [lindex $srg 1]]
  set fx [expr (1 - [lindex $hss 1] + [lindex $hss 0]) * $w]
  set fy [expr (1 - [lindex $vss 1] + [lindex $vss 0]) * $h]     
  if {$fx > 0} {set fx [expr (1 - [lindex $hss 1] + [lindex $hss 0]) / $fx]}
  if {$fy > 0} {set fy [expr (1 - [lindex $vss 1] + [lindex $vss 0]) / $fy]}
  set xth(me,area,drag_fx) $fx
  set xth(me,area,drag_fy) $fy
  set xth(me,area,drag_ox) [lindex $hss 0]
  set xth(me,area,drag_oy) [lindex $vss 0]
  set xth(me,area,drag_mx) $x
  set xth(me,area,drag_my) $y
  $xth(me,can) configure -cursor plus
  $xth(me,can) bind $tagOrId <Shift-B1-Motion> "xth_me_area_drag %x %y"
  $xth(me,can) bind $tagOrId <Shift-B1-ButtonRelease> "xth_me_area_end_drag $tagOrId \"$imgx\" %x %y"
  $xth(me,can) bind $tagOrId <B3-Motion> "xth_me_area_drag %x %y"
  $xth(me,can) bind $tagOrId <B3-ButtonRelease> "xth_me_area_end_drag $tagOrId \"$imgx\" %x %y"
  update idletasks
}

proc xth_me_area_drag {x y} {
  global xth
  set xdelta [expr ($xth(me,area,drag_mx) - $x) * $xth(me,area,drag_fx)]
  set ydelta [expr ($xth(me,area,drag_my) - $y) * $xth(me,area,drag_fy)]
  $xth(me,can) xview moveto [expr $xth(me,area,drag_ox) + $xdelta]
  $xth(me,can) yview moveto [expr $xth(me,area,drag_oy) + $ydelta]
  update idletasks     
}


proc xth_me_area_end_drag {tagOrId imgx x y} {
  global xth
  xth_me_area_drag $x $y
  $xth(me,can) configure -cursor crosshair
  $xth(me,can) bind $tagOrId <Shift-B1-Motion> ""
  $xth(me,can) bind $tagOrId <Shift-B1-ButtonRelease> ""
  $xth(me,can) bind $tagOrId <B3-Motion> ""
  $xth(me,can) bind $tagOrId <B3-ButtonRelease> ""
  if {[string length $imgx] > 0} {
    xth_me_image_choose $imgx
  }
  xth_me_images_rescandraw
  update idletasks 
}


proc xth_me_area_motion {x y} {
  global xth
  $xth(me,pbar) configure -text [format "%.1f : %.1f" [xth_me_can2realx [$xth(me,can) canvasx $x]] [xth_me_can2realy [$xth(me,can) canvasy $y]]]
}


proc xth_me_bind_area_drag {tagOrId imgx} {
  global xth
  $xth(me,can) bind $tagOrId <1> "xth_me_cmds_click_area $tagOrId %x %y"
  $xth(me,can) bind $tagOrId <Motion> "xth_me_area_motion %x %y"
  $xth(me,can) bind $tagOrId <Shift-1> "xth_me_area_start_drag $tagOrId \"$imgx\" %x %y"
  $xth(me,can) bind $tagOrId <3> "xth_me_area_start_drag $tagOrId \"$imgx\" %x %y"
}

proc xth_me_bind_area_only_drag {tagOrId} {
  global xth
  $xth(me,can) bind $tagOrId <Shift-1> "xth_me_area_start_drag $tagOrId {} %x %y"
  $xth(me,can) bind $tagOrId <3> "xth_me_area_start_drag $tagOrId {} %x %y"
}




proc xth_me_image_start_drag {tagOrId imgx x y} {
  global xth
  set xth(me,imgs,drag_mx) $x
  set xth(me,imgs,drag_my) $y
  set xth(me,imgs,drag_px) [lindex $xth(me,imgs,$imgx,position) 0]
  set xth(me,imgs,drag_py) [lindex $xth(me,imgs,$imgx,position) 1]
  $xth(me,can) configure -cursor fleur
  $xth(me,can) bind $tagOrId <Shift-B1-Motion> "xth_me_image_drag $imgx %x %y"
  $xth(me,can) bind $tagOrId <Shift-B1-ButtonRelease> "xth_me_image_end_drag $tagOrId $imgx %x %y"
  $xth(me,can) bind $tagOrId <B3-Motion> "xth_me_image_drag $imgx %x %y"
  $xth(me,can) bind $tagOrId <B3-ButtonRelease> "xth_me_image_end_drag $tagOrId $imgx %x %y"
  update idletasks
}

proc xth_me_image_drag {imgx x y} {
  global xth
  set xth(me,imgs,$imgx,position) [list \
    [expr $xth(me,imgs,drag_px) - [expr double($xth(me,imgs,drag_mx) - $x) * 100.0 / $xth(me,zoom)]] \
    [expr $xth(me,imgs,drag_py) + [expr double($xth(me,imgs,drag_my) - $y) * 100.0 / $xth(me,zoom)]] \
  ]
  xth_me_image_redraw $imgx
}

proc xth_me_image_end_drag {tagOrId imgx x y} {
  global xth
  xth_me_image_drag $imgx $x $y
  $xth(me,can) configure -cursor crosshair
  $xth(me,can) bind $tagOrId <Shift-B1-Motion> ""
  $xth(me,can) bind $tagOrId <Shift-B1-ButtonRelease> ""
  $xth(me,can) bind $tagOrId <B3-Motion> ""
  $xth(me,can) bind $tagOrId <B3-ButtonRelease> ""
  xth_me_image_choose $imgx
  xth_me_unredo_action [mc "dragging image"] \
    "xth_me_image_move $imgx $xth(me,imgs,drag_px) $xth(me,imgs,drag_py)" \
    "xth_me_image_move $imgx $xth(me,imgs,$imgx,position)"
  update idletasks 
}


proc xth_me_bind_image_drag {tagOrId imgx} {
  global xth
  $xth(me,can) bind $tagOrId <Double-Shift-1> "xth_me_image_start_drag $tagOrId $imgx %x %y"
  $xth(me,can) bind $tagOrId <Double-3> "xth_me_image_start_drag $tagOrId $imgx %x %y"
}


xth_app_create me [mc "Map Editor"]

xth_ctrl_add me cmds [mc "File commands"]
xth_ctrl_add me ss [mc "Search & Select"]
xth_ctrl_add me prev [mc "Command preview"]
xth_ctrl_add me point [mc "Point control"]
xth_ctrl_add me line [mc "Line control"]
xth_ctrl_add me linept [mc "Line point control"]
xth_ctrl_add me ac [mc "Area control"]
xth_ctrl_add me scrap [mc "Scrap control"]
xth_ctrl_add me text [mc "Text editor"]
xth_ctrl_add me area [mc "Drawing area"]
xth_ctrl_add me images [mc "Background images"]
xth_ctrl_finish me

# global variables initialization
set xth(me,ffull) {}
set xth(me,fltid) 0
set xth(me,fnewf) 0
set xth(me,fopen) 0
set xth(me,fsave) 0
set xth(me,zoom) 100
set xth(me,zoomv) 100
set xth(me,area,xmin) 0
set xth(me,area,xmax) 1600
set xth(me,area,ymin) 0
set xth(me,area,ymax) 1200
set xth(me,undolist) {}
set xth(me,redolist) {}
set xth(me,unredook) 0
set xth(me,unredola) {}
set xth(me,curscrap) {}
set xth(me,snai) 1

set xth(ctrl,me,images,posx) ""
set xth(ctrl,me,images,posy) ""
set xth(ctrl,me,images,vis) 0
set xth(ctrl,me,images,gamma) 0.0
set xth(ctrl,me,area,xmin) ""
set xth(ctrl,me,area,xmax) ""
set xth(ctrl,me,area,ymin) ""
set xth(ctrl,me,area,ymax) ""

set xth(ctrl,me,cmds,moveto) ""

set xth(ctrl,me,scrap,name) ""
set xth(ctrl,me,scrap,projection) ""
set xth(ctrl,me,scrap,options) ""
set xth(ctrl,me,scrap,px1) ""
set xth(ctrl,me,scrap,py1) ""
set xth(ctrl,me,scrap,px2) ""
set xth(ctrl,me,scrap,py2) ""
set xth(ctrl,me,scrap,rx1) ""
set xth(ctrl,me,scrap,ry1) ""
set xth(ctrl,me,scrap,rx2) ""
set xth(ctrl,me,scrap,ry2) ""
set xth(ctrl,me,scrap,units) ""
set xth(ctrl,me,scrap,pp1) {}
set xth(ctrl,me,scrap,pp2) {}

set xth(ctrl,me,point,x) {}
set xth(ctrl,me,point,y) {}
set xth(ctrl,me,point,type) {}
set xth(ctrl,me,point,name) {}
set xth(ctrl,me,point,opts) {}
set xth(ctrl,me,point,rot) {}
set xth(ctrl,me,point,xs) {}
set xth(ctrl,me,point,ys) {}
set xth(ctrl,me,point,rotid) 0
set xth(ctrl,me,point,xsid) 0
set xth(ctrl,me,point,ysid) 0

set xth(ctrl,me,line,type) {}
set xth(ctrl,me,line,name) {}
set xth(ctrl,me,line,opts) {}
set xth(ctrl,me,line,reverse) 0
set xth(ctrl,me,line,close) 0
set xth(ctrl,me,line,empty) {}
set xth(ctrl,me,linept,x) {}
set xth(ctrl,me,linept,y) {}
set xth(ctrl,me,linept,xp) {}
set xth(ctrl,me,linept,yp) {}
set xth(ctrl,me,linept,xn) {}
set xth(ctrl,me,linept,yn) {}
set xth(ctrl,me,linept,idp) 0
set xth(ctrl,me,linept,idn) 0
set xth(ctrl,me,linept,smooth) 0
set xth(ctrl,me,linept,rot) {}
set xth(ctrl,me,linept,rs) {}
set xth(ctrl,me,linept,ls) {}
set xth(ctrl,me,linept,rotid) 0
set xth(ctrl,me,linept,rsid) 0
set xth(ctrl,me,linept,lsid) 0

set xth(ctrl,me,ac,type) {}
set xth(ctrl,me,ac,opts) {}
set xth(ctrl,me,ac,empty) {}


set xth(ctrl,me,ss,expr) "station"
set xth(ctrl,me,ss,regexp) 0
set xth(ctrl,me,ss,cases) 0

# initialize drawing area

xth_about_status [mc "loading area module ..."]

$xth(gui,me).af.apps configure -bg black
set canfm $xth(gui,me).af.apps.cf 
set xth(me,canf) $canfm
grid columnconf $xth(gui,me).af.apps 0 -weight 1
grid rowconf $xth(gui,me).af.apps 0 -weight 1
frame $canfm
set xth(me,can) $canfm.c
scrollbar $canfm.sv -orient vertical -command "$xth(me,can) yview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)  
bind $canfm.sv <ButtonRelease> xth_me_images_rescandraw
scrollbar $canfm.sh -orient horizontal -command "$xth(me,can) xview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
bind $canfm.sh <ButtonRelease> xth_me_images_rescandraw
canvas $xth(me,can) -relief flat -borderwidth 0 -bg black \
	-xscrollcommand "xth_me_area_scroll $canfm.sh" \
	-yscrollcommand "xth_me_area_scroll $canfm.sv" \
	-cursor crosshair
bind $xth(me,can) <Configure> xth_me_images_rescandraw
  
set xth(me,canid,area) [$xth(me,can) create polygon 0 0 0 256 256 256 256 0 -fill LightYellow]
set xth(me,canid,scrap,scp1) [$xth(me,can) create rectangle 0 0 3 3 \
  -fill red -outline red -width 1 -state hidden -tags {cmd_ctrl}]
set xth(me,canid,scrap,scp2) [$xth(me,can) create rectangle 0 0 3 3 \
  -fill red -outline red -width 1 -state hidden -tags {cmd_ctrl}]

xth_me_bind_area_drag $xth(me,canid,area) {}
xth_me_area_adjust 0 0 1600 1200

set xth(me,canid,point,selector) [$xth(me,can) create oval 0 0 10 10 \
  -fill {} -outline red -width 1 -state hidden -tags {cmd_ctrl}]
set xth(me,canid,point,fill) [$xth(me,can) create polygon 0 0 10 0 10 10 0 10 \
  -fill red -stipple gray12 -state hidden -smooth on -tags {ptfill cmd_ctrl} -width 1]
set xth(me,canid,point,fx) [$xth(me,can) create line 0 0 10 10 \
  -width 5 -fill red -arrow last -arrowshape {9 12 4} \
  -state hidden -tags {ptfill cmd_ctrl}]
set xth(me,canid,point,fy) [$xth(me,can) create line 0 0 10 10 \
  -width 5 -fill red -arrow last -arrowshape {9 12 4} \
  -state hidden -tags {ptfill cmd_ctrl}]
#set xth(me,canid,point,fxc) [$xth(me,can) create oval 0 0 10 10 \
#  -outline red -fill red  -width 1 -state hidden -tags {ptfill cmd_ctrl}]
#set xth(me,canid,point,fyc) [$xth(me,can) create oval 0 0 10 10 \
#  -outline red -fill red  -width 1 -state hidden -tags {ptfill cmd_ctrl}]

xth_me_bind_area_drag $xth(me,canid,point,fill) {}
xth_me_bind_area_drag $xth(me,canid,point,selector) {}
xth_me_bind_area_only_drag $xth(me,canid,point,fx)
xth_me_bind_area_only_drag $xth(me,canid,point,fy)

set xth(me,canid,linept,selector) [$xth(me,can) create oval 0 0 10 10 \
  -fill {} -outline red -width 1 -state hidden -tags {linectrl cmd_ctrl}]
set xth(me,canid,linept,fr) [$xth(me,can) create line 0 0 10 10 \
  -width 5 -fill red -arrow last -arrowshape {9 12 4} \
  -state hidden -tags {linectrl cmd_ctrl}]
set xth(me,canid,linept,fl) [$xth(me,can) create line 0 0 10 10 \
  -width 5 -fill red -arrow last -arrowshape {9 12 4} \
  -state hidden -tags {linectrl cmd_ctrl}]

set xth(me,canid,linept,ppcpl) [$xth(me,can) create line 0 0 10 10 \
  -width $xth(gui,me,line,clwidth) -fill magenta -state hidden -tags "linectrl lineptppcp cmd_ctrl"]
set xth(me,canid,linept,nncpl) [$xth(me,can) create line 0 0 10 10 \
  -width $xth(gui,me,line,clwidth) -fill magenta -state hidden -tags "linectrl lineptnncp cmd_ctrl"]
set xth(me,canid,linept,ppcp) [$xth(me,can) create rectangle 0 0 10 10 \
  -width 1 -fill magenta -outline magenta -state hidden -tags "linectrl lineptppcp cmd_ctrl"]
set xth(me,canid,linept,nncp) [$xth(me,can) create rectangle 0 0 10 10 \
  -width 1 -fill magenta -outline magenta -state hidden -tags "linectrl lineptnncp cmd_ctrl"]

set xth(me,canid,linept,pcpl) [$xth(me,can) create line 0 0 10 10 \
  -width $xth(gui,me,line,clwidth) -fill $xth(gui,me,controlfill) -state hidden -tags "linectrl lineptpcp cmd_ctrl"]
set xth(me,canid,linept,ncpl) [$xth(me,can) create line 0 0 10 10 \
  -width $xth(gui,me,line,clwidth) -fill $xth(gui,me,controlfill) -state hidden -tags "linectrl lineptncp cmd_ctrl"]
set xth(me,canid,linept,pcp) [$xth(me,can) create rectangle 0 0 10 10 \
  -width 1 -fill red -outline $xth(gui,me,controlfill) -state hidden -tags "linectrl lineptpcp cmd_ctrl"]
set xth(me,canid,linept,ncp) [$xth(me,can) create rectangle 0 0 10 10 \
  -width 1 -fill red -outline $xth(gui,me,controlfill) -state hidden -tags "linectrl lineptncp cmd_ctrl"]

set xth(me,canid,line,tick) [$xth(me,can) create line 0 0 10 10 \
  -width $xth(gui,me,line,tickwidth) -fill #ffda00 -state hidden -tags "entirelinectrl cmd_ctrl"]

  
xth_me_bind_area_only_drag $xth(me,canid,linept,fr)
xth_me_bind_area_only_drag $xth(me,canid,linept,fl)
xth_me_bind_area_drag $xth(me,canid,linept,pcpl) {}
xth_me_bind_area_drag $xth(me,canid,linept,ncpl) {}
xth_me_bind_area_drag $xth(me,canid,linept,ppcpl) {}
xth_me_bind_area_drag $xth(me,canid,linept,nncpl) {}
xth_me_bind_area_drag $xth(me,canid,linept,selector) {}
xth_me_bind_area_drag $xth(me,canid,line,tick) {}

grid columnconf $canfm 0 -weight 1
grid rowconf $canfm 0 -weight 1
grid $xth(me,can) -column 0 -row 0 -sticky news
xth_scroll_showcmd $canfm.sv "grid $canfm.sv -column 1 -row 0 -sticky news"
xth_scroll_hidecmd $canfm.sv "grid forget $canfm.sv"
xth_scroll_showcmd $canfm.sh "grid $canfm.sh -column 0 -row 1 -sticky news"
xth_scroll_hidecmd $canfm.sh "grid forget $canfm.sh"


Label $xth(ctrl,me,area).l -text "" -anchor center -font $xth(gui,lfont) -state disabled
xth_status_bar me $xth(ctrl,me,area).l [mc "Current drawing area."]
Entry $xth(ctrl,me,area).xmin -font $xth(gui,lfont) -state disabled -width 4 -textvariable xth(ctrl,me,area,xmin)
xth_status_bar me $xth(ctrl,me,area).xmin [mc "X min."]
Entry $xth(ctrl,me,area).ymin -font $xth(gui,lfont) -state disabled -width 4 -textvariable xth(ctrl,me,area,ymin)
xth_status_bar me $xth(ctrl,me,area).ymin [mc "Y min."]
Entry $xth(ctrl,me,area).xmax -font $xth(gui,lfont) -state disabled -width 4 -textvariable xth(ctrl,me,area,xmax)
xth_status_bar me $xth(ctrl,me,area).xmax [mc "X max."]
Entry $xth(ctrl,me,area).ymax -font $xth(gui,lfont) -state disabled -width 4 -textvariable xth(ctrl,me,area,ymax)
xth_status_bar me $xth(ctrl,me,area).ymax [mc "Y max."]
Button $xth(ctrl,me,area).mab -text [mc "Adjust"] -anchor center -font $xth(gui,lfont) -state disabled -width 12 \
  -command {
    xth_me_area_adjust $xth(ctrl,me,area,xmin) $xth(ctrl,me,area,ymin) \
      $xth(ctrl,me,area,xmax) $xth(ctrl,me,area,ymax) 
  }
xth_status_bar me $xth(ctrl,me,area).mab [mc "Adjust drawing area to given limits."]
Button $xth(ctrl,me,area).aab -text [mc "Auto adjust"] -anchor center -font $xth(gui,lfont) -state disabled -width 12 \
  -command xth_me_area_auto_adjust
xth_status_bar me $xth(ctrl,me,area).aab [mc "Adjust drawing area to automatically calculated limits."]
Label $xth(ctrl,me,area).zl -text [mc "zoom"] -anchor e -font $xth(gui,lfont) -state disabled
menubutton $xth(ctrl,me,area).zb -text "100 %" -anchor center -font $xth(gui,lfont) \
  -indicatoron true -menu $xth(ctrl,me,area).zb.m -state disabled
menu $xth(ctrl,me,area).zb.m -tearoff 0 -font $xth(gui,lfont)
$xth(ctrl,me,area).zb.m add radiobutton -label "25 %" -variable xth(me,zoomv) -value 25 -command "xth_me_area_zoom_to 25"
$xth(ctrl,me,area).zb.m add radiobutton -label "50 %" -variable xth(me,zoomv) -value 50 -command "xth_me_area_zoom_to 50"
$xth(ctrl,me,area).zb.m add radiobutton -label "100 %" -variable xth(me,zoomv) -value 100 -command "xth_me_area_zoom_to 100"
$xth(ctrl,me,area).zb.m add radiobutton -label "200 %" -variable xth(me,zoomv) -value 200 -command "xth_me_area_zoom_to 200"
$xth(ctrl,me,area).zb.m add radiobutton -label "400 %" -variable xth(me,zoomv) -value 400 -command "xth_me_area_zoom_to 400"
xth_status_bar me $xth(ctrl,me,area).zb [mc "Zoom drawing area."]
xth_status_bar me $xth(ctrl,me,area).zl [mc "Zoom drawing area."]

xth_me_bind_entry_focus_return "$xth(ctrl,me,area).xmin $xth(ctrl,me,area).ymin $xth(ctrl,me,area).xmax $xth(ctrl,me,area).ymax" {
    xth_me_area_adjust $xth(ctrl,me,area,xmin) $xth(ctrl,me,area,ymin) \
      $xth(ctrl,me,area,xmax) $xth(ctrl,me,area,ymax) 
}
xth_me_bind_entry_focusin "$xth(ctrl,me,area).xmin $xth(ctrl,me,area).ymin $xth(ctrl,me,area).xmax $xth(ctrl,me,area).ymax"


grid columnconf $xth(ctrl,me,area) 0 -weight 1
grid columnconf $xth(ctrl,me,area) 1 -weight 1
grid columnconf $xth(ctrl,me,area) 2 -weight 1
grid columnconf $xth(ctrl,me,area) 3 -weight 1
grid $xth(ctrl,me,area).l -column 0 -row 0 -columnspan 4 -sticky news
grid $xth(ctrl,me,area).xmin -column 0 -row 1 -sticky news -padx 1
grid $xth(ctrl,me,area).ymin -column 1 -row 1 -sticky news -padx 1
grid $xth(ctrl,me,area).xmax -column 2 -row 1 -sticky news -padx 1
grid $xth(ctrl,me,area).ymax -column 3 -row 1 -sticky news -padx 1
grid $xth(ctrl,me,area).mab -column 0 -row 2 -columnspan 2 -sticky news
grid $xth(ctrl,me,area).aab -column 2 -row 2 -columnspan 2 -sticky news
grid $xth(ctrl,me,area).zl -column 0 -row 3 -columnspan 2 -sticky news
grid $xth(ctrl,me,area).zb -column 2 -row 3 -columnspan 2 -sticky news


xth_about_status [mc "loading commands module ..."]

# initialize file commands
set clbox $xth(ctrl,me,cmds).cl
set ccbox $xth(ctrl,me,cmds).cc
frame $clbox
frame $ccbox
listbox $clbox.l -height 8 -selectmode single -takefocus 0 \
  -yscrollcommand "xth_scroll $clbox.sv" \
  -xscrollcommand "xth_scroll $clbox.sh" \
  -font $xth(gui,lfont) -exportselection no \
  -listvariable xth(me,cmds,list) -selectborderwidth 0
scrollbar $clbox.sv -orient vert  -command "$clbox.l yview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
scrollbar $clbox.sh -orient horiz  -command "$clbox.l xview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
bind $clbox.l <<ListboxSelect>> {xth_me_cmds_select {}}
bind $clbox.l <B1-ButtonRelease> "focus $clbox.l"

grid columnconf $clbox 0 -weight 1
grid rowconf $clbox 0 -weight 1
grid $clbox.l -column 0 -row 0 -sticky news
xth_scroll_showcmd $clbox.sv "grid $clbox.sv -column 1 -row 0 -sticky news"
xth_scroll_hidecmd $clbox.sv "grid forget $clbox.sv"
xth_scroll_showcmd $clbox.sh "grid $clbox.sh -column 0 -row 1 -sticky news"
xth_scroll_hidecmd $clbox.sh "grid forget $clbox.sh"
xth_status_bar me $clbox [mc "Select command."]

grid columnconf $xth(ctrl,me,cmds) 0 -weight 1
grid $clbox -column 0 -row 0 -sticky news
grid $ccbox -column 0 -row 1 -sticky news

Button $ccbox.go -text [mc "Insert scrap"] -anchor center -font $xth(gui,lfont) \
  -state disabled -command xth_me_cmds_action
xth_status_bar me $ccbox.go [mc "Action button."]
Button $ccbox.sel -text [mc "Select"] -anchor center -font $xth(gui,lfont) \
  -state disabled -command {xth_me_cmds_set_mode 0}
xth_status_bar me $ccbox.sel [mc "Switch mouse mode to select objects."]
menubutton $ccbox.cfg -text [mc "Action"] -anchor center -font $xth(gui,lfont) \
  -indicatoron true -menu $ccbox.cfg.m -state disabled
xth_status_bar me $ccbox.cfg [mc "Configure action assigned to action button."]
menu $ccbox.cfg.m -tearoff 0 -font $xth(gui,lfont)
$ccbox.cfg.m add command -label [mc "Insert point"] -command {xth_me_cmds_set_action 1}
$ccbox.cfg.m add command -label [mc "Insert line"] -command {xth_me_cmds_set_action 0}
$ccbox.cfg.m add command -label [mc "Insert area"] -command {xth_me_cmds_set_action 5}
$ccbox.cfg.m add command -label [mc "Insert scrap"] -command {xth_me_cmds_set_action 2}
$ccbox.cfg.m add command -label [mc "Insert text"] -command {xth_me_cmds_set_action 3}
$ccbox.cfg.m add separator
$ccbox.cfg.m add command -label [mc "Delete"] -command {xth_me_cmds_set_action 4}
Button $ccbox.mu -text [mc "Move up"] -anchor center -font $xth(gui,lfont) \
  -state disabled -width 8 -command "xth_me_cmds_move_up {}"
xth_status_bar me $ccbox.mu [mc "Move file command up in the list."]
Button $ccbox.md -text [mc "Move down"] -anchor center -font $xth(gui,lfont) \
  -state disabled -width 8 -command "xth_me_cmds_move_down {}"
xth_status_bar me $ccbox.md [mc "Move file command down in the list."]
Button $ccbox.mt -text [mc "Move to"] -anchor center -font $xth(gui,lfont) \
  -state disabled -width 8 -command "xth_me_cmds_move_to {} {}"
xth_status_bar me $ccbox.mt [mc "Move file command to given position."]
ComboBox $ccbox.tt -postcommand xth_me_cmds_set_move_to_list \
  -modifycmd xth_me_cmds_set_move_to \
  -font $xth(gui,lfont) -height 4 -state disabled -width 8 \
  -textvariable xth(ctrl,me,cmds,moveto)
xth_status_bar me $ccbox.tt [mc "Select destination scrap and position in it."]
grid columnconf $ccbox 0 -weight 1
grid columnconf $ccbox 1 -weight 1
grid $ccbox.go -column 0 -row 0 -columnspan 2 -sticky news
grid $ccbox.cfg $ccbox.sel -row 1 -sticky news
grid $ccbox.mu $ccbox.md -row 2 -sticky news
grid $ccbox.mt $ccbox.tt -row 3 -sticky news

# initialize text editor
set txb $xth(ctrl,me,text)
text $txb.txt -height 6 -wrap none -font $xth(gui,efont) \
  -bg $xth(gui,ecolorbg) \
  -fg $xth(gui,ecolorfg) -insertbackground $xth(gui,ecolorfg) \
  -relief sunken -state disabled \
  -selectbackground $xth(gui,ecolorselbg) \
  -selectforeground $xth(gui,ecolorselfg) \
  -selectborderwidth 0 \
  -yscrollcommand "$txb.sv set" \
  -xscrollcommand "$txb.sh set" 
scrollbar $txb.sv -orient vert  -command "$txb.txt yview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
scrollbar $txb.sh -orient horiz  -command "$txb.txt xview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
Button $txb.upd -text [mc "Update text"] -anchor center -font $xth(gui,lfont) \
  -state disabled \
  -command {xth_me_cmds_update {}}
xth_status_bar me $txb.upd [mc "Press this button to save code you have written."]

grid columnconf $txb 0 -weight 1
grid rowconf $txb 0 -weight 1
grid $txb.txt -column 0 -row 0 -sticky news
grid $txb.sv -column 1 -row 0 -sticky news
grid $txb.sh -column 0 -row 1 -sticky news
grid $txb.upd -column 0 -row 2 -columnspan 2 -sticky news
xth_status_bar me $txb.txt [mc "Editor for free text in therion 2D file."]
bind $txb.txt <$xth(kb_control)-Key-x> "tk_textCut $txb.txt"
bind $txb.txt <$xth(kb_control)-Key-c> "tk_textCopy $txb.txt"
bind $txb.txt <$xth(kb_control)-Key-v> "tk_textPaste $txb.txt"

if {$xth(gui,bindinsdel)} {
  bind $txb.txt <Delete> {
    %W delete insert
    %W see insert
  }
  bind $txb.txt <Shift-Key-Delete> "tk_textCut $txb.txt"
  bind $txb.txt <$xth(kb_control)-Key-Insert> "tk_textCopy $txb.txt"
  bind $txb.txt <Shift-Key-Insert> "tk_textPaste $txb.txt"
#  catch {
#    bind $txb.txt <Shift-Key-KP_Decimal> "tk_textCut $txb.txt"
#    bind $txb.txt <$xth(kb_control)-Key-KP_Insert> "tk_textCopy $txb.txt"
#    bind $txb.txt <Shift-Key-KP_0> "tk_textPaste $txb.txt"
#  }
}

if {[info exists xth(gui,te)]} {
#  bind $txb.txt <$xth(kb_control)-Key-a> "xth_te_text_select_all %W"
#  bind $txb.txt <$xth(kb_control)-Key-i> "xth_te_text_auto_indent %W"
  bind $txb.txt <Tab> $xth(te,bind,text_tab)
  bind $txb.txt <Return> $xth(te,bind,text_return)
} else {
  bind $txb.txt <Tab> $xth(gui,bind,text_tab)
  bind $txb.txt <Return> $xth(gui,bind,text_return)
}



# initialize search & select tool
set ssbx $xth(ctrl,me,ss)

Label $ssbx.xl -text [mc "expression"] -anchor e -font $xth(gui,lfont) -state disabled
xth_status_bar me $ssbx.xl [mc "Enter search expression."]
Entry $ssbx.xe -font $xth(gui,lfont) -state disabled \
  -textvariable xth(ctrl,me,ss,expr) -width 3
bind $ssbx.xe <Return> xth_me_ss_show
xth_status_bar me $ssbx.xe [mc "Enter search expression."]
checkbutton $ssbx.rx -text [mc "regular expression"] -anchor w -font $xth(gui,lfont) -state disabled \
  -variable xth(ctrl,me,ss,regexp) -command {}
xth_status_bar me $ssbx.rx [mc "Search for regular expression."]
checkbutton $ssbx.cs -text [mc "case sensitive"] -anchor w -font $xth(gui,lfont) -state disabled \
  -variable xth(ctrl,me,ss,cases) -command {}
xth_status_bar me $ssbx.cs [mc "Case sensitive search."]
Button $ssbx.sn -text [mc "Find next"] -anchor center -font $xth(gui,lfont) \
  -state disabled -command xth_me_ss_next -width 10
xth_status_bar me $ssbx.sn [mc "Select next object matching expression."]
Button $ssbx.sf -text [mc "Find first"] -anchor center -font $xth(gui,lfont) \
  -state disabled -command xth_me_ss_first -width 10
xth_status_bar me $ssbx.sf [mc "Select first object matching expression."]
Button $ssbx.sa -text [mc "Show all"] -anchor center -font $xth(gui,lfont) \
  -state disabled -command xth_me_ss_show -width 9
xth_status_bar me $ssbx.sa [mc "Highlight all objects matching expression."]
Button $ssbx.ca -text [mc "Clear all"] -anchor center -font $xth(gui,lfont) \
  -state disabled -command xth_me_cmds_set_colors -width 9
xth_status_bar me $ssbx.ca [mc "Clear highlighted objects."]

grid columnconf $ssbx 0 -weight 1
grid columnconf $ssbx 1 -weight 1
grid $ssbx.xl -column 0 -row 0 -sticky news
grid $ssbx.xe -column 1 -row 0 -sticky news
grid $ssbx.cs -column 0 -row 1 -sticky news -columnspan 2
grid $ssbx.rx -column 0 -row 2 -sticky news -columnspan 2
grid $ssbx.sf -column 0 -row 3 -sticky news
grid $ssbx.sn -column 1 -row 3 -sticky news
grid $ssbx.sa -column 0 -row 4 -sticky news
grid $ssbx.ca -column 1 -row 4 -sticky news


xth_about_status [mc "loading images module ..."]

# initialize images
frame $xth(ctrl,me,images).il
set ilbox $xth(ctrl,me,images).il.ilbox 
set xth(me,imgs,list) {}
listbox $ilbox -height 4 -selectmode single -takefocus 0 \
  -yscrollcommand "xth_scroll $xth(ctrl,me,images).il.sv" \
  -xscrollcommand "xth_scroll $xth(ctrl,me,images).il.sh" \
  -font $xth(gui,lfont) -exportselection no \
  -listvariable xth(me,imgs,list) -selectborderwidth 0
scrollbar $xth(ctrl,me,images).il.sv -orient vert  -command "$ilbox yview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
scrollbar $xth(ctrl,me,images).il.sh -orient horiz  -command "$ilbox xview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
frame $xth(ctrl,me,images).ic
bind $ilbox <<ListboxSelect>> "xth_me_image_select \[lindex \[%W curselection\] 0\]"

grid columnconf $xth(ctrl,me,images).il 0 -weight 1
grid rowconf $xth(ctrl,me,images).il 0 -weight 1
grid $ilbox -column 0 -row 0 -sticky news
xth_scroll_showcmd $xth(ctrl,me,images).il.sv "grid $xth(ctrl,me,images).il.sv -column 1 -row 0 -sticky news"
xth_scroll_hidecmd $xth(ctrl,me,images).il.sv "grid forget $xth(ctrl,me,images).il.sv"
xth_scroll_showcmd $xth(ctrl,me,images).il.sh "grid $xth(ctrl,me,images).il.sh -column 0 -row 1 -sticky news"
xth_scroll_hidecmd $xth(ctrl,me,images).il.sh "grid forget $xth(ctrl,me,images).il.sh"
xth_status_bar me $ilbox [mc "Select background image."]
grid columnconf $xth(ctrl,me,images) 0 -weight 1
grid $xth(ctrl,me,images).il -column 0 -row 0 -sticky news
grid $xth(ctrl,me,images).ic -column 0 -row 1 -sticky news

Button $xth(ctrl,me,images).ic.insp -text [mc "Insert"] -anchor center -font $xth(gui,lfont) \
  -state disabled -command {
		set nimgs [llength $xth(me,imgs,xlist)]
    xth_me_image_insert $xth(ctrl,me,images,posx) $xth(ctrl,me,images,posy) {} 0 {}
		set nnimgs [llength $xth(me,imgs,xlist)]
		if {$nnimgs > $nimgs} {
	    xth_me_area_auto_adjust
		}
  }
xth_status_bar me $xth(ctrl,me,images).ic.insp [mc "Insert new background image."]
Button $xth(ctrl,me,images).ic.remp -text [mc "Remove"] -anchor center -font $xth(gui,lfont) -state disabled \
  -command {xth_me_image_remove ""}
xth_status_bar me $xth(ctrl,me,images).ic.remp [mc "Remove selected image."]
Separator $xth(ctrl,me,images).ic.s1 -orient horizontal
checkbutton $xth(ctrl,me,images).ic.viscb -text [mc "visibility"] -anchor w -font $xth(gui,lfont) -state disabled \
  -variable xth(ctrl,me,images,vis) -command {xth_me_image_toggle_vsb ""}
xth_status_bar me $xth(ctrl,me,images).ic.viscb [mc "Switch image visibility."]

Label $xth(ctrl,me,images).ic.gl -text "gamma 1.00" -anchor w -font $xth(gui,lfont) -state disabled
xth_status_bar me $xth(ctrl,me,images).ic.gl [mc "Control gamma value."]
Button $xth(ctrl,me,images).ic.gr -text [mc "Reset"] -anchor center -font $xth(gui,lfont) \
  -state disabled -width 8 -command "set xth(ctrl,me,images,gamma) 0.0; xth_me_image_update_gamma"
xth_status_bar me $xth(ctrl,me,images).ic.gr [mc "Reset image gamma value."]
scale $xth(ctrl,me,images).ic.gs -from -1.0 -to 1.0 \
  -font $xth(gui,lfont) -state disabled -showvalue 0 -resolution 0.01 \
  -variable xth(ctrl,me,images,gamma) -orient horiz
bind $xth(ctrl,me,images).ic.gs <B1-ButtonRelease> xth_me_image_update_gamma
xth_status_bar me $xth(ctrl,me,images).ic.gs [mc "Set image gamma value."]


Label $xth(ctrl,me,images).ic.posl -text [mc "position"] -anchor e -font $xth(gui,lfont) -state disabled
xth_status_bar me $xth(ctrl,me,images).ic.posl [mc "Current position of selected image."]
Label $xth(ctrl,me,images).ic.posln -text "" -anchor center -font $xth(gui,lfont) -state disabled
xth_status_bar me $xth(ctrl,me,images).ic.posln [mc "Current position of selected image."]
Button $xth(ctrl,me,images).ic.posch -text [mc "Move to"] -anchor center -font $xth(gui,lfont) \
  -state disabled -width 8 -command "xth_me_image_move_to"
xth_status_bar me $xth(ctrl,me,images).ic.posch [mc "Move image to given position."]
Entry $xth(ctrl,me,images).ic.posx -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,images,posx)
xth_status_bar me $xth(ctrl,me,images).ic.posx [mc "New X coordinate of image."]
Entry $xth(ctrl,me,images).ic.posy -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,images,posy)
xth_status_bar me $xth(ctrl,me,images).ic.posy [mc "New Y coordinate of image."]
Button $xth(ctrl,me,images).ic.mvf -text [mc "Move front"] -anchor center -font $xth(gui,lfont) -state disabled -width 10 \
  -command xth_me_image_move_front
xth_status_bar me $xth(ctrl,me,images).ic.mvf [mc "Move image in front of all images."]
Button $xth(ctrl,me,images).ic.mvb -text [mc "Move back"] -anchor center -font $xth(gui,lfont) -state disabled -width 10 \
  -command xth_me_image_move_back
xth_status_bar me $xth(ctrl,me,images).ic.mvb [mc "Move image behind all images."]

xth_me_bind_entry_focus_return "$xth(ctrl,me,images).ic.posx $xth(ctrl,me,images).ic.posy" "xth_me_image_move_to"
xth_me_bind_entry_focusin "$xth(ctrl,me,images).ic.posx $xth(ctrl,me,images).ic.posy"

grid columnconf $xth(ctrl,me,images).ic 0 -weight 1
grid columnconf $xth(ctrl,me,images).ic 1 -weight 1
grid columnconf $xth(ctrl,me,images).ic 2 -weight 1
grid columnconf $xth(ctrl,me,images).ic 3 -weight 1
grid $xth(ctrl,me,images).ic.insp -column 0 -row 0 -sticky news -columnspan 2
grid $xth(ctrl,me,images).ic.remp -column 2 -row 0 -sticky news -columnspan 2
grid $xth(ctrl,me,images).ic.s1 -column 0 -row 1 -sticky news -columnspan 4 -pady 3
grid $xth(ctrl,me,images).ic.posl -column 0 -row 2 -sticky news -columnspan 2
grid $xth(ctrl,me,images).ic.posln -column 2 -row 2 -sticky news -columnspan 2 -padx 1
grid $xth(ctrl,me,images).ic.posch -column 0 -row 3 -sticky news -columnspan 2
grid $xth(ctrl,me,images).ic.posx -column 2 -row 3 -sticky ew -padx 1
grid $xth(ctrl,me,images).ic.posy -column 3 -row 3 -sticky ew -padx 1
grid $xth(ctrl,me,images).ic.mvf -column 0 -row 4 -sticky news -columnspan 2
grid $xth(ctrl,me,images).ic.mvb -column 2 -row 4 -sticky news -columnspan 2
grid $xth(ctrl,me,images).ic.gl -column 0 -row 5 -sticky news -columnspan 2
grid $xth(ctrl,me,images).ic.gr -column 2 -row 5 -sticky news -columnspan 2
grid $xth(ctrl,me,images).ic.gs -column 0 -row 6 -sticky news -columnspan 4
grid $xth(ctrl,me,images).ic.viscb -column 0 -row 7 -sticky news -columnspan 4
# xth_status_bar me $xth(ctrl,me,images). "To set file encoding, type encoding name and press <Change> button."


xth_about_status [mc "loading preview module ..."]

# init command preview
set txb $xth(ctrl,me,prev)
text $txb.txt -height 4 -wrap none -font $xth(gui,efont) \
  -bg $xth(gui,ecolorbg) \
  -fg $xth(gui,ecolorfg) -insertbackground $xth(gui,ecolorfg) \
  -relief sunken -state disabled \
  -selectbackground $xth(gui,ecolorselbg) \
  -selectforeground $xth(gui,ecolorselfg) \
  -selectborderwidth 0 \
  -yscrollcommand "$txb.sv set" \
  -xscrollcommand "$txb.sh set" 
scrollbar $txb.sv -orient vert  -command "$txb.txt yview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
scrollbar $txb.sh -orient horiz  -command "$txb.txt xview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
Button $txb.upd -text [mc "Update command"] -anchor center -font $xth(gui,lfont) \
  -state disabled -command {xth_me_cmds_update {}}
xth_status_bar me $txb.upd [mc "Press this button, if you have changed something and you can not see your changes here."]  
grid columnconf $txb 0 -weight 1
grid rowconf $txb 0 -weight 1
grid $txb.txt -column 0 -row 0 -sticky news
grid $txb.sv -column 1 -row 0 -sticky news
grid $txb.sh -column 0 -row 1 -sticky news
grid $txb.upd -column 0 -row 2 -columnspan 2 -sticky news
xth_status_bar me $txb.txt [mc "Command preview."]

# init scrap control

xth_about_status [mc "loading scrap module ..."]

set sfm $xth(ctrl,me,scrap)

Label $sfm.namel -text id -anchor e -font $xth(gui,lfont) -state disabled
xth_status_bar me $sfm.namel [mc "Scrap name."]
Entry $sfm.name -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,scrap,name)
xth_status_bar me $sfm.name [mc "Scrap name."]

Label $sfm.projl -text [mc "projection"] -anchor e -font $xth(gui,lfont) -state disabled
xth_status_bar me $sfm.projl [mc "Scrap projection."]
ComboBox $sfm.proj -values $xth(scrap_projections) \
  -font $xth(gui,lfont) -height 4 -state disabled -width 4 \
  -textvariable xth(ctrl,me,scrap,projection) -command {xth_me_cmds_update {}}

xth_status_bar me $sfm.proj [mc "Scrap projection."]
xth_me_bind_typecbx_hint $sfm.proj projection

Label $sfm.optl -text [mc "options"] -anchor e -font $xth(gui,lfont) -state disabled -width 8
xth_status_bar me $sfm.optl [mc "Other scrap options."]
Entry $sfm.opt -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,scrap,options)

xth_status_bar me $sfm.opt [mc "Other scrap options."] 

#Separator $sfm.s1 -orient horizontal
Label $sfm.scl -text [mc "scale"] -anchor sw -font $xth(gui,lfont) -state disabled
xth_status_bar me $sfm.scl [mc "Scrap scale definition."]
Button $sfm.scpb -text [mc "Update scrap"] -anchor center -font $xth(gui,lfont) \
  -state disabled -width 4 -command {xth_me_cmds_update {}}
xth_status_bar me $sfm.scpb [mc "Press this button to apply your changes to current scrap."]
Label $sfm.scpp -text [mc "picture scale points"] -anchor w -font $xth(gui,lfont) -state disabled
xth_status_bar me $sfm.scpp [mc "Calibration points on the picture (X1:Y1 - X2:Y2)."]
Entry $sfm.scx1p -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,scrap,px1)
xth_status_bar me $sfm.scx1p [mc "X1 picture."] 
Entry $sfm.scy1p -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,scrap,py1)
xth_status_bar me $sfm.scy1p [mc "Y1 picture."] 
Entry $sfm.scx2p -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,scrap,px2)
xth_status_bar me $sfm.scx2p [mc "X2 picture."]
Entry $sfm.scy2p -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,scrap,py2)
xth_status_bar me $sfm.scy2p [mc "Y2 picture."]
Label $sfm.scrp -text [mc "real scale points"] -anchor w -font $xth(gui,lfont) -state disabled
xth_status_bar me $sfm.scrp [mc "Real coordinates of calibration points (X1:Y1 - X2:Y2)."]
Entry $sfm.scx1r -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,scrap,rx1)
xth_status_bar me $sfm.scx1r [mc "X1 real."]
Entry $sfm.scy1r -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,scrap,ry1)
xth_status_bar me $sfm.scy1r [mc "Y1 real."]
Entry $sfm.scx2r -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,scrap,rx2)
xth_status_bar me $sfm.scx2r [mc "X2 real."]
Entry $sfm.scy2r -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,scrap,ry2)
xth_status_bar me $sfm.scy2r [mc "Y2 real."]
Label $sfm.scul -text [mc "units"] -anchor e -font $xth(gui,lfont) -state disabled
xth_status_bar me $sfm.scul [mc "Units of real coordinates."]
ComboBox $sfm.scu -values $xth(length_units) \
  -font $xth(gui,lfont) -height 5 -state disabled -width 4 \
  -textvariable xth(ctrl,me,scrap,units) -command {xth_me_cmds_update {}}
xth_status_bar me $sfm.scu [mc "Units of real coordinates."]

xth_me_bind_entry_focus_return "$sfm.scx1p $sfm.scy1p $sfm.scx2p $sfm.scy2p" {xth_me_cmds_update {}}
xth_me_bind_entry_focus_return "$sfm.scx1r $sfm.scy1r $sfm.scx2r $sfm.scy2r" {xth_me_cmds_update {}}
xth_me_bind_entry_return "$sfm.name $sfm.opt" {xth_me_cmds_update {}}
xth_me_bind_entry_focusin "$sfm.name $sfm.opt $sfm.scx1p $sfm.scy1p $sfm.scx2p $sfm.scy2p $sfm.scx1r $sfm.scy1r $sfm.scx2r $sfm.scy2r"

grid columnconf $sfm 0 -weight 1
grid columnconf $sfm 1 -weight 1
grid columnconf $sfm 2 -weight 1
grid columnconf $sfm 3 -weight 1
grid $sfm.namel -row 0 -column 0 -columnspan 2 -sticky news
grid $sfm.name  -row 0 -column 2 -columnspan 2 -sticky news -padx 1
grid $sfm.projl -row 1 -column 0 -columnspan 2 -sticky news
grid $sfm.proj  -row 1 -column 2 -columnspan 2 -sticky news -padx 2
grid $sfm.optl -row 2 -column 0 -columnspan 2 -sticky news
grid $sfm.opt  -row 2 -column 2 -columnspan 2 -sticky news -padx 1
#grid $sfm.s1 -column 0 -row 3 -sticky news -columnspan 4 -pady 3
grid $sfm.scl -row 3 -column 0 -columnspan 2 -sticky news
grid $sfm.scpb -row 3 -column 2 -columnspan 2 -sticky news
grid $sfm.scpp -column 0 -row 4 -sticky news -columnspan 4
grid $sfm.scx1p $sfm.scy1p $sfm.scx2p $sfm.scy2p -row 5 -sticky news -padx 1
grid $sfm.scrp -column 0 -row 6 -sticky news -columnspan 4
grid $sfm.scx1r $sfm.scy1r $sfm.scx2r $sfm.scy2r -row 7 -sticky news -padx 1
grid $sfm.scul -row 8 -column 0 -columnspan 2 -sticky news
grid $sfm.scu  -row 8 -column 2 -columnspan 2 -sticky news -padx 2


# point control
xth_about_status [mc "loading point module ..."]

set ptc $xth(ctrl,me,point)
Label $ptc.posl -text [mc "position"] -anchor e -font $xth(gui,lfont) -state disabled -width 8
xth_status_bar me $ptc.posl [mc "Point position."]
Entry $ptc.posx -font $xth(gui,lfont) -state disabled -width 4 -textvariable xth(ctrl,me,point,x)
xth_status_bar me $ptc.posx [mc "Point X coordinate."]
Entry $ptc.posy -font $xth(gui,lfont) -state disabled -width 4 -textvariable xth(ctrl,me,point,y)
xth_status_bar me $ptc.posy [mc "Point Y coordinate."] 

Button $ptc.upd -text [mc "Update point"] -anchor center -font $xth(gui,lfont) \
  -state disabled -command {xth_me_cmds_update {}}
xth_status_bar me $ptc.upd [mc "Click this button to apply point changes."] 

Label $ptc.typl -text [mc "type"] -anchor e -font $xth(gui,lfont) -state disabled -width 8
xth_status_bar me $ptc.typl [mc "Point type."] 
ComboBox $ptc.typ -values $xth(point_types) \
  -font $xth(gui,lfont) -height $xth(gui,me,typelistwidth) -state disabled -width 4 \
  -textvariable xth(ctrl,me,point,type) -command {xth_me_cmds_update {}}
xth_status_bar me $ptc.typ [mc "Point type."]
xth_me_bind_typecbx_hint $ptc.typ point

Label $ptc.namel -text [mc "id"] -anchor e -font $xth(gui,lfont) -state disabled
xth_status_bar me $ptc.namel [mc "Point identifier."]
Entry $ptc.name -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,point,name)
xth_status_bar me $ptc.name [mc "Point identifier."] 

Label $ptc.optl -text [mc "options"] -anchor e -font $xth(gui,lfont) -state disabled
xth_status_bar me $ptc.optl [mc "Other point options."]
Entry $ptc.opt -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,point,opts)
xth_status_bar me $ptc.opt [mc "I.e, if type is label, write here: -text \042this will be displayed (P100)\042"]
Separator $ptc.s1 -orient horizontal

checkbutton $ptc.rotc -text [mc "orientation"] -anchor w -font $xth(gui,lfont) -state disabled \
  -variable xth(ctrl,me,point,rotid) -command xth_me_cmds_point_change_state
Entry $ptc.rot -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,point,rot)
xth_status_bar me $ptc.rot [mc "Enter symbol orientation angle."]
xth_status_bar me $ptc.rotc [mc "There are symbol types which must be orientated (i.e: gradients). Click here to giv'em orientation by mouse or keyboard."]

checkbutton $ptc.xszc -text [mc "x-size"] -anchor w -font $xth(gui,lfont) -state disabled \
  -variable xth(ctrl,me,point,xsid) -command xth_me_cmds_point_change_state
xth_status_bar me $ptc.xszc [mc "Set point size in main direction."]
Entry $ptc.xsz -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,point,xs)
xth_status_bar me $ptc.xsz [mc "Enter point size in main direction."]

checkbutton $ptc.yszc -text [mc "y-size"] -anchor w -font $xth(gui,lfont) -state disabled \
  -variable xth(ctrl,me,point,ysid) -command xth_me_cmds_point_change_state
xth_status_bar me $ptc.yszc [mc "Set point size in side direction."]
Entry $ptc.ysz -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,point,ys)
xth_status_bar me $ptc.ysz [mc "Enter point size in side direction."]

xth_me_bind_entry_focus_return "$ptc.posx $ptc.posy" {xth_me_cmds_update {}}
xth_me_bind_entry_return "$ptc.name $ptc.opt $ptc.rot $ptc.xsz $ptc.ysz" {xth_me_cmds_update {}}
xth_me_bind_entry_focusin "$ptc.posx $ptc.posy $ptc.name $ptc.opt $ptc.rot $ptc.xsz $ptc.ysz"


grid columnconf $ptc 0 -weight 1
grid columnconf $ptc 1 -weight 1
grid columnconf $ptc 2 -weight 1
grid columnconf $ptc 3 -weight 1
grid $ptc.posl -row 0 -column 0 -columnspan 2 -sticky news
grid $ptc.posx -row 0 -column 2 -sticky news -padx 1
grid $ptc.posy -row 0 -column 3 -sticky news -padx 1
grid $ptc.typl -row 1 -column 0 -columnspan 2 -sticky news
grid $ptc.typ -row 1 -column 2 -columnspan 2 -sticky news -padx 2
grid $ptc.namel -row 2 -column 0 -columnspan 2 -sticky news
grid $ptc.name -row 2 -column 2 -columnspan 2 -sticky news -padx 1
grid $ptc.optl -row 3 -column 0 -columnspan 2 -sticky news
grid $ptc.opt -row 3 -column 2 -columnspan 2 -sticky news -padx 1
grid $ptc.s1 -row 4 -column 0 -columnspan 4 -sticky news -pady 3
grid $ptc.rotc -row 5 -column 0 -columnspan 2 -sticky news
grid $ptc.rot -row 5 -column 2 -columnspan 2 -sticky news -padx 1
#grid $ptc.xszc -row 6 -column 0 -columnspan 2 -sticky news
#grid $ptc.xsz -row 6 -column 2 -columnspan 2 -sticky news -padx 1
#grid $ptc.yszc -row 7 -column 0 -columnspan 2 -sticky news
#grid $ptc.ysz -row 7 -column 2 -columnspan 2 -sticky news -padx 1
grid $ptc.upd -row 8 -column 0 -columnspan 4 -sticky news


# line control
xth_about_status [mc "loading line module ..."]

set lnc $xth(ctrl,me,line)

Label $lnc.typl -text [mc "type"] -anchor e -font $xth(gui,lfont) -state disabled
xth_status_bar me $lnc.typl [mc "Line type."]
ComboBox $lnc.typ -values $xth(line_types) \
  -font $xth(gui,lfont) -height $xth(gui,me,typelistwidth) -state disabled -width 4 \
  -textvariable xth(ctrl,me,line,type) \
  -command {xth_me_cmds_update {}}
xth_status_bar me $lnc.typ [mc "Line type."]
xth_me_bind_typecbx_hint $lnc.typ line

Label $lnc.namel -text [mc "id"] -anchor e -font $xth(gui,lfont) -state disabled
xth_status_bar me $lnc.namel [mc "Line identifier."]
Entry $lnc.name -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,line,name)
xth_status_bar me $lnc.name [mc "Line identifier."]

Label $lnc.optl -text [mc "options"] -anchor e -font $xth(gui,lfont) -state disabled
xth_status_bar me $lnc.optl [mc "Other line options."]
Entry $lnc.opt -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,line,opts)
xth_status_bar me $lnc.opt [mc "Other line options."]

checkbutton $lnc.rev -text [mc "reverse"] -anchor w -font $xth(gui,lfont) \
  -state disabled \
  -variable xth(ctrl,me,line,reverse) \
  -command xth_me_cmds_toggle_line_reverse
xth_status_bar me $lnc.rev [mc "Reverse line."]
checkbutton $lnc.cls -text [mc "close"] -anchor w -font $xth(gui,lfont) \
  -state disabled \
  -variable xth(ctrl,me,line,close) \
  -command xth_me_cmds_toggle_line_close
xth_status_bar me $lnc.cls [mc "Close line."]

set plf $lnc.pl
frame $plf
listbox $plf.l -height 4 -selectmode single -takefocus 0 \
  -yscrollcommand "xth_scroll $plf.sv" \
  -xscrollcommand "xth_scroll $plf.sh" \
  -font $xth(gui,lfont) -exportselection no \
  -selectborderwidth 0
scrollbar $plf.sv -orient vert  -command "$plf.l yview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
scrollbar $plf.sh -orient horiz  -command "$plf.l xview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
bind $plf.l <<ListboxSelect>> {
  if {$xth(me,fopen)} {
    xth_me_cmds_select_linept $xth(me,cmds,selid) \
    [lindex $xth(me,cmds,$xth(me,cmds,selid),xplist) \
    [lindex [%W curselection] 0]]
    if {$xth(me,cmds,selpid) > 0} {
      xth_me_center_to [list \
        $xth(me,cmds,$xth(me,cmds,selid),$xth(me,cmds,selpid),x) \
        $xth(me,cmds,$xth(me,cmds,selid),$xth(me,cmds,selpid),y)]
    }
  }
}
bind $plf.l <B1-ButtonRelease> "focus $plf.l"

menubutton $lnc.lpa -text [mc "Edit line"] -anchor w -font $xth(gui,lfont) \
  -indicatoron true -menu $lnc.lpa.m -state disabled -width 10
xth_status_bar me $lnc.lpa [mc "Insert/delete line point. Split line."]
Button $lnc.upd -text [mc "Update"] -anchor center -font $xth(gui,lfont) \
  -state disabled -command {xth_me_cmds_update {}} -width 10
xth_status_bar me $lnc.upd [mc "Click this button to apply line changes."]

menu $lnc.lpa.m -tearoff 0 -font $xth(gui,lfont)
$lnc.lpa.m add command -label [mc "Insert point"] -command {xth_me_cmds_start_linept_insert} -state disabled
$lnc.lpa.m add command -label [mc "Delete point"] -command {xth_me_cmds_delete_linept {} {}} -state disabled
$lnc.lpa.m add command -label [mc "Split line"] -command {xth_me_cmds_line_split} -state disabled

#Button $lnc.insp -text "Insert" -anchor center -font $xth(gui,lfont) \
#  -state disabled -width 10 -command {xth_me_cmds_start_linept_insert}
#Button $lnc.delp -text "Delete" -anchor center -font $xth(gui,lfont) \
#  -state disabled -width 10 -command {xth_me_cmds_delete_linept {} {}}

grid columnconf $plf 0 -weight 1
grid rowconf $plf 0 -weight 1
grid $plf.l -column 0 -row 0 -sticky news
xth_scroll_showcmd $plf.sv "grid $plf.sv -column 1 -row 0 -sticky news"
xth_scroll_hidecmd $plf.sv "grid forget $plf.sv"
xth_scroll_showcmd $plf.sh "grid $plf.sh -column 0 -row 1 -sticky news"
xth_scroll_hidecmd $plf.sh "grid forget $plf.sh"
xth_status_bar me $plf [mc "Select line point."]


grid columnconf $lnc 0 -weight 1
grid columnconf $lnc 1 -weight 1
grid $lnc.typl -row 0 -column 0 -sticky news
grid $lnc.typ -row 0 -column 1 -sticky news -padx 2
grid $lnc.namel -row 1 -column 0 -sticky news
grid $lnc.name -row 1 -column 1 -sticky news -padx 1
grid $lnc.optl -row 2 -column 0 -sticky news
grid $lnc.opt -row 2 -column 1 -sticky news -padx 1
grid $lnc.rev -row 3 -column 0 -sticky news
grid $lnc.cls -row 3 -column 1 -sticky news
grid $plf -row 4 -column 0 -columnspan 2 -sticky news
grid $lnc.lpa -row 5 -column 0 -sticky news
grid $lnc.upd -row 5 -column 1 -sticky news
#grid $lnc.insp -row 5 -column 0 -sticky news
#grid $lnc.delp -row 5 -column 1 -sticky news

xth_me_bind_entry_return "$lnc.name $lnc.opt" {xth_me_cmds_update {}}
xth_me_bind_entry_focusin "$lnc.name $lnc.opt"

# line point control
xth_about_status [mc "loading line point module ..."]

set lpc $xth(ctrl,me,linept)

Label $lpc.posl -text [mc "position"] -anchor e -font $xth(gui,lfont) -state disabled -width 0
xth_status_bar me $lpc.posl [mc "Point position."]
Entry $lpc.posx -font $xth(gui,lfont) -state disabled \
  -textvariable xth(ctrl,me,linept,x) -width 0
xth_status_bar me $lpc.posx [mc "Point X coordinate."]
Entry $lpc.posy -font $xth(gui,lfont) -state disabled \
  -textvariable xth(ctrl,me,linept,y) -width 0
xth_status_bar me $lpc.posy [mc "Point Y coordinate."] 

Entry $lpc.xp -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,linept,xp)
xth_status_bar me $lpc.xp [mc "Previous control point X coordinate."] 
Entry $lpc.yp -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,linept,yp)
xth_status_bar me $lpc.yp [mc "Previous control point Y coordinate."] 
Entry $lpc.xn -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,linept,xn)
xth_status_bar me $lpc.xn [mc "Next control point X coordinate."] 
Entry $lpc.yn -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,linept,yn)
xth_status_bar me $lpc.yn [mc "Next control point Y coordinate."] 

checkbutton $lpc.cbp -text "<<" -anchor w -font $xth(gui,lfont) \
  -state disabled -width 0 \
  -variable xth(ctrl,me,linept,idp) \
  -command xth_me_cmds_toggle_linept
xth_status_bar me $lpc.cbp [mc "Checkbox whether to use previous control point."]
checkbutton $lpc.cbs -text [mc "smooth"] -anchor w -font $xth(gui,lfont) -state disabled \
  -variable xth(ctrl,me,linept,smooth) -width 0\
  -command xth_me_cmds_toggle_linept
xth_status_bar me $lpc.cbs [mc "Set line to be smooth in given point."]
checkbutton $lpc.cbn -text ">>" -anchor w -font $xth(gui,lfont) \
  -state disabled -width 0 \
  -variable xth(ctrl,me,linept,idn) \
  -command xth_me_cmds_toggle_linept
xth_status_bar me $lpc.cbn [mc "Checkbox whether to use next control point."]

checkbutton $lpc.rotc -text [mc "orientation"] -anchor w -font $xth(gui,lfont) -state disabled \
  -variable xth(ctrl,me,linept,rotid) -width 0 \
  -command xth_me_cmds_toggle_linept
xth_status_bar me $lpc.rotc [mc "Set line point orientation."]
Entry $lpc.rot -font $xth(gui,lfont) -state disabled -width 0 \
  -textvariable xth(ctrl,me,linept,rot)
xth_status_bar me $lpc.rot [mc "Enter line point orientation."]

checkbutton $lpc.rszc -text [mc "r-size"] -anchor w -font $xth(gui,lfont) -state disabled \
  -variable xth(ctrl,me,linept,rsid) -width 0 \
  -command xth_me_cmds_toggle_linept
xth_status_bar me $lpc.rszc [mc "Set line size in right direction."]
Entry $lpc.rsz -font $xth(gui,lfont) -state disabled -width 0 \
  -textvariable xth(ctrl,me,linept,rs)
xth_status_bar me $lpc.rsz [mc "Enter line size in right direction."]

checkbutton $lpc.lszc -text [mc "l-size"] -anchor w -font $xth(gui,lfont) -state disabled \
  -variable xth(ctrl,me,linept,lsid) -width 0  \
  -command xth_me_cmds_toggle_linept
xth_status_bar me $lpc.lszc [mc "Set line size in left direction."]
Entry $lpc.lsz -font $xth(gui,lfont) -state disabled -width 0 \
  -textvariable xth(ctrl,me,linept,ls)
xth_status_bar me $lpc.lsz [mc "Enter line size in left direction."]

Label $lpc.optl -text [mc "options"] -anchor sw -font $xth(gui,lfont) -state disabled \
 -width 0
xth_status_bar me $lpc.optl [mc "Line point options editor."]
Button $lpc.upd -text [mc "Update"] -anchor center -font $xth(gui,lfont) \
  -state disabled -command {xth_me_cmds_update {}} -width 0
xth_status_bar me $lpc.upd [mc "Click this button to apply line point changes."]

set txb $lpc.oe
frame $txb
text $txb.txt -height 2 -wrap none -font $xth(gui,efont) \
  -bg $xth(gui,ecolorbg) \
  -fg $xth(gui,ecolorfg) -insertbackground $xth(gui,ecolorfg) \
  -relief sunken -state disabled \
  -selectbackground $xth(gui,ecolorselbg) \
  -selectforeground $xth(gui,ecolorselfg) \
  -yscrollcommand "$txb.sv set" \
  -selectborderwidth 0 \
  -xscrollcommand "$txb.sh set" 
scrollbar $txb.sv -orient vert  -command "$txb.txt yview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
scrollbar $txb.sh -orient horiz  -command "$txb.txt xview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
grid columnconf $txb 0 -weight 1
grid rowconf $txb 0 -weight 1
grid $txb.txt -column 0 -row 0 -sticky news
grid $txb.sv -column 1 -row 0 -sticky news
grid $txb.sh -column 0 -row 1 -sticky news
xth_status_bar me $txb [mc "Editor for line point options."]
bind $txb.txt <$xth(kb_control)-Key-x> "tk_textCut $txb.txt"
bind $txb.txt <$xth(kb_control)-Key-c> "tk_textCopy $txb.txt"
bind $txb.txt <$xth(kb_control)-Key-v> "tk_textPaste $txb.txt"

if {$xth(gui,bindinsdel)} {
  bind $txb.txt <Delete> {
    %W delete insert
    %W see insert
  }
  bind $txb.txt <Shift-Key-Delete> "tk_textCut $txb.txt"
  bind $txb.txt <$xth(kb_control)-Key-Insert> "tk_textCopy $txb.txt"
  bind $txb.txt <Shift-Key-Insert> "tk_textPaste $txb.txt"
#  catch {
#    bind $txb.txt <Shift-Key-KP_Decimal> "tk_textCut $txb.txt"
#    bind $txb.txt <$xth(kb_control)-Key-KP_Insert> "tk_textCopy $txb.txt"
#    bind $txb.txt <Shift-Key-KP_0> "tk_textPaste $txb.txt"
#  }
}

if {[info exists xth(gui,te)]} {
  bind $txb.txt <Tab> $xth(te,bind,text_tab)
  bind $txb.txt <Return> $xth(te,bind,text_return)
} else {
  bind $txb.txt <Tab> $xth(gui,bind,text_tab)
  bind $txb.txt <Return> $xth(gui,bind,text_return)
}

grid columnconf $lpc 0 -weight 1
grid columnconf $lpc 1 -weight 1
grid columnconf $lpc 2 -weight 1
grid columnconf $lpc 3 -weight 1

grid $lpc.posl -row 0 -column 0 -columnspan 2 -sticky news
grid $lpc.posx -row 0 -column 2 -sticky news
grid $lpc.posy -row 0 -column 3 -sticky news

xth_me_bind_entry_focus_return "$lpc.posx $lpc.posy" {xth_me_cmds_update {}}

grid $lpc.xp -row 1 -column 0 -sticky news
grid $lpc.yp -row 1 -column 1 -sticky news
grid $lpc.xn -row 1 -column 2 -sticky news
grid $lpc.yn -row 1 -column 3 -sticky news

xth_me_bind_entry_focus_return "$lpc.xp $lpc.yp" {xth_me_cmds_update {}}
xth_me_bind_entry_focus_return "$lpc.xn $lpc.yn" {xth_me_cmds_update {}}
xth_me_bind_entry_focusin "$lpc.posx $lpc.posy $lpc.xp $lpc.yp $lpc.xn $lpc.yn"

grid $lpc.cbp -row 2 -column 0 -sticky news
grid $lpc.cbs -row 2 -column 1 -columnspan 2 -sticky news
grid $lpc.cbn -row 2 -column 3 -sticky news

grid $lpc.rotc -row 3 -column 0 -columnspan 2 -sticky news
grid $lpc.rot -row 3 -column 2 -columnspan 2 -sticky news

grid $lpc.lszc -row 4 -column 0 -columnspan 2 -sticky news
grid $lpc.lsz -row 4 -column 2 -columnspan 2 -sticky news

#grid $lpc.rszc -row 5 -column 0 -columnspan 2 -sticky news
#grid $lpc.rsz -row 5 -column 2 -columnspan 2 -sticky news

grid $lpc.optl -row 6 -column 0 -columnspan 2 -sticky news
grid $lpc.upd -row 6 -column 2 -columnspan 2 -sticky news

grid $txb -row 7 -column 0 -columnspan 4 -sticky news

xth_me_bind_entry_focusin "$lpc.rot $lpc.lsz $lpc.rsz"
xth_me_bind_entry_return "$lpc.rot $lpc.lsz $lpc.rsz" {xth_me_cmds_update {}}





# area control
xth_about_status [mc "loading area module ..."]

set lnc $xth(ctrl,me,ac)

Label $lnc.typl -text [mc "type"] -anchor e -font $xth(gui,lfont) -state disabled
xth_status_bar me $lnc.typl [mc "Area type."]
ComboBox $lnc.typ -values $xth(area_types) \
  -font $xth(gui,lfont) -height $xth(gui,me,typelistwidth) -state disabled -width 4 \
  -textvariable xth(ctrl,me,ac,type) \
  -command {xth_me_cmds_update {}}
xth_status_bar me $lnc.typ [mc "Area type."] 
xth_me_bind_typecbx_hint $lnc.typ area

Label $lnc.optl -text [mc "options"] -anchor e -font $xth(gui,lfont) -state disabled
xth_status_bar me $lnc.optl [mc "Other area options."]
Entry $lnc.opt -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,ac,opts)
xth_status_bar me $lnc.opt [mc "Other area options."] 

set plf $lnc.ll
frame $plf
listbox $plf.l -height 4 -selectmode single -takefocus 0 \
  -yscrollcommand "xth_scroll $plf.sv" \
  -xscrollcommand "xth_scroll $plf.sh" \
  -font $xth(gui,lfont) -exportselection no \
  -selectborderwidth 0
scrollbar $plf.sv -orient vert  -command "$plf.l yview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
scrollbar $plf.sh -orient horiz  -command "$plf.l xview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
bind $plf.l <<ListboxSelect>> {}
bind $plf.l <B1-ButtonRelease> "focus $plf.l"

Button $lnc.ins -text [mc "Select lines"] -anchor center -font $xth(gui,lfont) \
  -state disabled -width 10 -command {xth_me_cmds_start_area_insert 1}
xth_status_bar me $lnc.ins [mc "Switch to insert line into area mode."]
Button $lnc.del -text [mc "Delete"] -anchor center -font $xth(gui,lfont) \
  -state disabled -width 10 -command {xth_me_cmds_delete_area_line {} {}}
xth_status_bar me $lnc.del [mc "Delete ID from area."]

Button $lnc.insid -text [mc "Insert ID"] -anchor center -font $xth(gui,lfont) \
  -state disabled -command {xth_me_cmds_insert_area_line $xth(ctrl,me,ac,insid) {} {}} -width 10
xth_status_bar me $lnc.insid [mc "Insert given id."]
Entry $lnc.inside -font $xth(gui,lfont) -state disabled -width 4 \
  -textvariable xth(ctrl,me,ac,insid)
xth_status_bar me $lnc.inside [mc "ID to insert."] 

Button $lnc.upd -text [mc "Update"] -anchor center -font $xth(gui,lfont) \
  -state disabled -command {xth_me_cmds_update {}} -width 10
xth_status_bar me $lnc.upd [mc "Click this button to apply changes you made to area."]
Button $lnc.shw -text [mc "Show"] -anchor center -font $xth(gui,lfont) \
  -state disabled -command {xth_me_cmds_show_current_area} -width 10
xth_status_bar me $lnc.shw [mc "Show area border lines."]

grid columnconf $plf 0 -weight 1
grid rowconf $plf 0 -weight 1
grid $plf.l -column 0 -row 0 -sticky news
xth_scroll_showcmd $plf.sv "grid $plf.sv -column 1 -row 0 -sticky news"
xth_scroll_hidecmd $plf.sv "grid forget $plf.sv"
xth_scroll_showcmd $plf.sh "grid $plf.sh -column 0 -row 1 -sticky news"
xth_scroll_hidecmd $plf.sh "grid forget $plf.sh"
xth_status_bar me $plf [mc "Select line in area."]

grid columnconf $lnc 0 -weight 1
grid columnconf $lnc 1 -weight 1
grid $lnc.typl -row 0 -column 0 -sticky news
grid $lnc.typ -row 0 -column 1 -sticky news -padx 2
grid $lnc.optl -row 1 -column 0 -sticky news
grid $lnc.opt -row 1 -column 1 -sticky news -padx 1
grid $lnc.shw -row 2 -column 0 -sticky news
grid $lnc.upd -row 2 -column 1 -sticky news
grid $plf -row 3 -column 0 -columnspan 2 -sticky news
grid $lnc.ins -row 4 -column 0 -sticky news
grid $lnc.del -row 4 -column 1 -sticky news
grid $lnc.insid -row 5 -column 0 -sticky news
grid $lnc.inside -row 5 -column 1 -sticky news

xth_me_bind_entry_return "$lnc.opt" {xth_me_cmds_update {}}
xth_me_bind_entry_focusin "$lnc.opt"


# main menu
xth_about_status [mc "loading main menu ..."]


$xth(me,menu,file) add command -label [mc "New"] -command xth_me_create_file \
  -font $xth(gui,lfont) -underline 0 -state normal
$xth(me,menu,file) add command -label [mc "Open"] -underline 0 \
  -accelerator "$xth(gui,controlk)-o" -state normal \
  -font $xth(gui,lfont) -command {
			set xth(gui,openxp) 0
			xth_me_open_file 1 {} 1
	}
$xth(me,menu,file) add command -label [mc "Open (no pics)"] -underline 10 \
  -state normal -font $xth(gui,lfont) -command {
	    set xth(gui,openxp) 1
			xth_me_open_file 1 {} 1
			set xth(gui,openxp) 0
	}
$xth(me,menu,file) add command -label [mc "Save"] -underline 0 \
  -accelerator "$xth(gui,controlk)-s" -state disabled \
  -font $xth(gui,lfont) -command {xth_me_save_file 0}
$xth(me,menu,file) add command -label [mc "Save as"] -underline 5 \
  -font $xth(gui,lfont) -command {xth_me_save_file 1} -state disabled 
$xth(me,menu,file) add checkbutton -label [mc "Auto save"] -underline 1 \
  -variable xth(gui,auto_save) -font $xth(gui,lfont) \
  -state disabled -command xth_app_autosave_schedule
$xth(me,menu,file) add command -label [mc "Close"] -underline 0 \
  -accelerator "$xth(gui,controlk)-w"  -state disabled \
  -font $xth(gui,lfont) \
  -command xth_me_close_file

set xth(me,menu,edit) $xth(me,menu).edit
menu $xth(me,menu,edit) -tearoff 0
menu $xth(me,menu,edit).ins -tearoff 0
bind $xth(me,menu,edit) <FocusIn> {xth_me_cmds_update {}}
$xth(me,menu) add cascade -label [mc "Edit"] -state disabled \
  -font $xth(gui,lfont) -menu $xth(me,menu,edit) -underline 0
$xth(me,menu,edit) add command -label [mc "Undo"] -font $xth(gui,lfont) \
  -underline 0 -accelerator "$xth(gui,controlk)-z" -state disabled \
  -command xth_me_unredo_undo
$xth(me,menu,edit) add command -label [mc "Redo"] -font $xth(gui,lfont) \
  -underline 0 -accelerator "$xth(gui,controlk)-y" -state disabled \
  -command xth_me_unredo_redo
$xth(me,menu,edit) add separator
$xth(me,menu,edit) add command -label [mc "Cut"] -font $xth(gui,lfont) \
  -accelerator "$xth(gui,controlk)-x" -command "xth_app_clipboard cut"
$xth(me,menu,edit) add command -label [mc "Copy"] -font $xth(gui,lfont) \
  -accelerator "$xth(gui,controlk)-c" -command "xth_app_clipboard copy"
$xth(me,menu,edit) add command -label [mc "Paste"] -font $xth(gui,lfont) \
  -accelerator "$xth(gui,controlk)-v" -command "xth_app_clipboard paste"
$xth(me,menu,edit) add separator
$xth(me,menu,edit) add command -label [mc "Select"] \
  -accelerator "Esc" -underline 0 -font $xth(gui,lfont) -command {xth_me_cmds_set_mode 0}
$xth(me,menu,edit) add cascade -label [mc "Insert ..."] \
  -accelerator "$xth(gui,controlk)-i" -menu $xth(me,menu,edit).ins -underline 0 -font $xth(gui,lfont)
$xth(me,menu,edit).ins add command -label [mc "point"] \
  -accelerator "$xth(gui,controlk)-p" -underline 0 -font $xth(gui,lfont) -command {xth_me_cmds_set_mode 1}
$xth(me,menu,edit).ins add command -label [mc "line"] \
    -accelerator "$xth(gui,controlk)-l" -underline 0 -font $xth(gui,lfont) -command {
  xth_me_cmds_create_line {} 1 "" "" ""
  xth_ctrl_scroll_to me line
  xth_ctrl_maximize me line
  xth_ctrl_maximize me linept
}

$xth(me,menu,edit).ins add command -label [mc "area"] \
  -accelerator "$xth(gui,controlk)-a" -font $xth(gui,lfont) -underline 0 -command {
  xth_me_cmds_create_area {} 1 "" "" ""
  xth_ctrl_scroll_to me ac
  xth_ctrl_maximize me ac
}

$xth(me,menu,edit).ins add command -label [mc "scrap"] \
  -accelerator "$xth(gui,controlk)-r" -font $xth(gui,lfont) -underline 0 -command {
  xth_me_cmds_create_scrap {} 1 "" ""
  xth_ctrl_scroll_to me scrap
  xth_ctrl_maximize me scrap
}

$xth(me,menu,edit).ins add command -label [mc "text"] -font $xth(gui,lfont) -underline 0 -command {
  xth_me_cmds_create_text {} 1 "\n" "1.0"
  xth_ctrl_scroll_to me text
  xth_ctrl_maximize me text
  focus $xth(ctrl,me,text).txt
}

$xth(me,menu,edit) add command -label [mc "Delete"] \
  -accelerator "$xth(gui,controlk)-d" -underline 0 -font $xth(gui,lfont) -command {xth_me_cmds_delete {}}
$xth(me,menu,edit) add separator
$xth(me,menu,edit) add cascade -label [mc "Zoom 100 %"] -font $xth(gui,lfont) \
  -underline 0 -menu $xth(ctrl,me,area).zb.m
$xth(me,menu,edit) add command -label [mc "Auto adjust area"] \
  -font $xth(gui,lfont) -command xth_me_area_auto_adjust
$xth(me,menu,edit) add command -label [mc "Insert image"] \
  -font $xth(gui,lfont) \
  -command {xth_me_image_insert $xth(ctrl,me,images,posx) $xth(ctrl,me,images,posy) {} 0 {}}
set xth(me,menu,edit,undo) [$xth(me,menu,edit) index [mc "Undo"]]
set xth(me,menu,edit,redo) [$xth(me,menu,edit) index [mc "Redo"]]
set xth(me,menu,edit,zoom) [$xth(me,menu,edit) index [mc "Zoom 100 %"]]


# create mouse mode bar and progess bar
set barfm $xth(gui,me).sf.barfm
frame $barfm
pack $barfm -side left
grid columnconf $barfm 0 -weight 1
grid rowconf $barfm 0 -weight 1

set xth(me,mbar) $barfm.mbar
Label $xth(me,mbar) -text "" -width 17 -relief sunken -font $xth(gui,lfont) \
  -anchor center -state disabled
grid $xth(me,mbar) -column 0 -row 0 -sticky news
set xth(me,mbar,bg) [$xth(me,mbar) cget -bg]
set xth(me,mbar,fg) [$xth(me,mbar) cget -fg]
xth_status_bar me $xth(me,mbar) [mc "Mouse mode."]

set xth(me,progbar) $barfm.pbar
set xth(me,progbar,value) 0
ProgressBar $xth(me,progbar) -type normal -width 100 -variable xth(me,progbar,value) -fg darkBlue

proc xth_me_progbar_show {max} {
  global xth
  set pbw [winfo width $xth(me,mbar)]
  set pbh [winfo height $xth(me,mbar)]
  grid forget $xth(me,mbar)
  grid $xth(me,progbar) -column 0 -row 0 -sticky news
  $xth(me,progbar) configure -maximum $max -width $pbw -height $pbh
  update idletasks
}

proc xth_me_progbar_hide {} {
  global xth
  grid forget $xth(me,progbar)
  grid $xth(me,mbar) -column 0 -row 0 -sticky news
  update idletasks
}

proc xth_me_progbar_prog {val} {
  global xth
  set xth(me,progbar,value) $val
  update idletasks
}

# create position bar
set xth(me,pbar) $xth(gui,me).sf.pbar
Label $xth(me,pbar) -text "" -width 15 -relief sunken -font $xth(gui,lfont) \
  -anchor center -state disabled
pack $xth(me,pbar) -side left
xth_status_bar me $xth(me,pbar) [mc "Current mouse position."]

xth_ctrl_minimize me cmds
xth_ctrl_minimize me prev
xth_ctrl_minimize me ss
xth_ctrl_minimize me point
xth_ctrl_minimize me line
xth_ctrl_minimize me linept
xth_ctrl_minimize me ac
xth_ctrl_minimize me scrap
xth_ctrl_minimize me text
xth_ctrl_minimize me area
xth_ctrl_minimize me images
    
set xth(ctrl,me,area,xmin) ""
set xth(ctrl,me,area,ymin) ""
set xth(ctrl,me,area,xmax) ""
set xth(ctrl,me,area,ymax) ""

xth_about_status [mc "loading line procs ..."]
xth_status_bar_status me [mc "Map editor is not active. To activate it, open existing file or create new one."]









xth_about_status [mc "loading compiler..."]


proc xth_xcfg_fname {fpath} {
  set tmp [file tail $fpath]
  regsub -all {\.} $tmp {_} tmp
  return ".xth_$tmp\137xth"
}


proc xth_cp_new_file {} {
  global xth
  xth_status_bar_status cp ""
  if {$xth(cp,fopen)} {
    return
  }
  set xth(cp,fopen) 1
  set xth(cp,special) {}
  set xth(cp,ffull) [file join $xth(gui,initdir) "thconfig"]
  if {[xth_cp_save_as]} {
    set ff $xth(cp,ffull)
    set xth(cp,fopen) 0
    set xth(cp,fname) ""
    set xth(cp,open_file) ""
    set xth(cp,fpath) ""
    set xth(cp,ffull) ""
    xth_cp_open_file $ff
  } else {
    set xth(cp,fopen) 0
    set xth(cp,fname) ""
    set xth(cp,open_file) ""
    set xth(cp,fpath) ""
    set xth(cp,ffull) ""
  }
}

proc xth_cp_open_file {fpath} {
  global xth
  xth_status_bar_status cp ""
  
  if {$xth(cp,fopen)} {
    return
  }

  if {[string length $fpath] == 0} {
    set fpath [tk_getOpenFile -filetypes $xth(app,cp,filetypes) \
      -parent $xth(gui,main) -initialdir $xth(gui,initdir)]
  }
  
  if {[string length $fpath] == 0} {
    return 0
  } else {
    set xth(gui,initdir) [file dirname $fpath]
  }

  set is_config_file [xth_cp_is_config_file $fpath];
  if {[string length $is_config_file] > 0} {
    MessageDlg $xth(gui,message) -parent $xth(gui,main) \
      -icon info -type ok \
      -message  "$fpath\n-----\n$is_config_file" \
      -font $xth(gui,lfont)
    return 0;
  }
  

  # read the file
  xth_status_bar_push cp
  xth_status_bar_status cp [format [mc "Opening %s ..."] $fpath]

  set fdata [xth_me_read_file $fpath 0]
  if {[lindex $fdata 0] == 0} {
      MessageDlg $xth(gui,message) -parent $xth(gui,main) \
        -icon error -type ok \
        -message [lindex $fdata 1] \
        -font $xth(gui,lfont)
      xth_status_bar_pop cp
      return 0
  }
  
  # now let's show the file
  catch {
    set fid [open [file join [file dirname $fpath] [xth_xcfg_fname $fpath]] r]
    fconfigure $fid -encoding utf-8
    while {![eof $fid]} {
      catch {
        eval [gets $fid]
      }
    }
    close $fid
  }
  
  set xth(cp,fopen) 1
  set xth(cp,special) [lindex $fdata 2]
  set xth(cp,fname) [file tail $fpath]
  set xth(cp,open_file) [file tail $fpath]
  set xth(cp,fpath) [file dirname $fpath]
  set xth(cp,ffull) $fpath
  
  # enable controls
  $xth(cp,editor).txt configure -state normal
#  $xth(cp,editor).txt delete 1.0 end
  foreach ln [lindex $fdata 3] {
    $xth(cp,editor).txt insert end "$ln\n"
  }
  catch {
    $xth(cp,editor).txt edit reset
  }
  $xth(cp,editor).txt mark set insert $xth(cp,cursor)
  $xth(cp,editor).txt see $xth(cp,cursor)
  
  $xth(ctrl,cp,stp).wl configure -state normal
  $xth(ctrl,cp,stp).we configure -state normal
  $xth(ctrl,cp,stp).fl configure -state normal
  $xth(ctrl,cp,stp).fe configure -state normal
  $xth(ctrl,cp,stp).optl configure -state normal
  $xth(ctrl,cp,stp).opte configure -state normal
  $xth(ctrl,cp,stp).go configure -state normal
  $xth(ctrl,cp,stp).gores configure -state normal

  $xth(ctrl,cp,info).txt configure -state normal
  
  $xth(cp,menu,file) entryconfigure [mc "New"] -state disabled
  $xth(cp,menu,file) entryconfigure [mc "Open"] -state disabled
  $xth(cp,menu,file) entryconfigure [mc "Save as"] -state normal
  $xth(cp,menu,file) entryconfigure [mc "Close"] -state normal
  $xth(cp,menu) entryconfigure [mc "Edit"] -state normal
  
  xth_app_title cp
  xth_status_bar_pop cp
  update idletasks
  return 1
}


set xth(cps,n) 0
set xth(cps,mxs) 0
set xth(cps,mxl) 0
set xth(cps,ts) 0
set xth(cps,tl) 0

proc xth_cp_comp_stat {tlen tscrap} {
  global xth
  incr xth(cps,n)
  if {$tscrap > $xth(cps,mxs)} {
    set xth(cps,mxs) $tscrap
  }
  if {$tlen > $xth(cps,mxl)} {
    set xth(cps,mxl) $tlen
  }
  set xth(cps,ts) [expr $xth(cps,ts) + $tscrap]
  set xth(cps,tl) [expr $xth(cps,tl) + $tscrap]
  set xth(cps,as) [expr double($xth(cps,ts)) / double($xth(cps,n))]
  set xth(cps,al) [expr double($xth(cps,tl)) / double($xth(cps,n))]  
}



proc xth_cp_close_file {} {
  
  global xth

  xth_cp_data_tree_clear      

  if {!$xth(cp,fopen)} {
    return
  }
  
  xth_cp_write_file $xth(cp,ffull)

  # disable controls
  $xth(cp,editor).txt delete 1.0 end
  $xth(cp,editor).txt see 1.0
  $xth(cp,editor).txt configure -state disabled

  $xth(cp,log).txt configure -state normal
  $xth(cp,log).txt delete 1.0 end
  $xth(cp,log).txt see 1.0
  $xth(cp,log).txt configure -state disabled

  $xth(cp,menu,file) entryconfigure [mc "New"] -state normal
  $xth(cp,menu,file) entryconfigure [mc "Open"] -state normal
  $xth(cp,menu,file) entryconfigure [mc "Save as"] -state disabled
  $xth(cp,menu,file) entryconfigure [mc "Close"] -state disabled
  $xth(cp,menu) entryconfigure [mc "Edit"] -state disabled
  
  $xth(ctrl,cp,stp).wl configure -state disabled
  $xth(ctrl,cp,stp).we configure -state disabled
  $xth(ctrl,cp,stp).fl configure -state disabled
  $xth(ctrl,cp,stp).fe configure -state disabled
  $xth(ctrl,cp,stp).optl configure -state disabled
  $xth(ctrl,cp,stp).opte configure -state disabled
  $xth(ctrl,cp,stp).go configure -state disabled
  $xth(ctrl,cp,stp).gores configure -text "" -fg $xth(cp,resfg) -bg $xth(cp,resbg) \
    -state disabled

  $xth(ctrl,cp,info).txt configure -state disabled
  
  # set variables
  set xth(cp,fopen) 0
  set xth(cp,cursor) 1.0
  set xth(cp,fname) ""
  set xth(cp,open_file) ""
  set xth(cp,fpath) ""
  set xth(cp,opts) ""
  xth_app_title cp
  focus $xth(ctrl,cp,dat).t 
  
  set xth(ctrl,cp,datrestore) {}
  set xth(ctrl,cp,msrestore) {}

}


# xth_cp_write_file --
#
# return list containing
# {success name}

proc xth_cp_write_file {pth} {

  global errorInfo xth

  xth_status_bar_push cp
  xth_status_bar_status cp [format [mc "Saving %s ..."] $pth]

  if {[catch {set fid [open $pth w]}]} {
    MessageDlg $xth(gui,message) -parent $xth(gui,main) \
        -icon error -type ok \
        -message $errorInfo \
        -font $xth(gui,lfont)    
    xth_status_bar_pop cp
    return 0
  }

  fconfigure $fid -encoding utf-8 -translation {auto lf}
  puts $fid "encoding  utf-8"

  # let's put data
  set data [$xth(cp,editor).txt get 1.0 end]
  regsub {\s*$} $data {} data
  puts $fid $data
    
  # now let's put special commands
  foreach cmd $xth(cp,special) {
    puts $fid "##XTHERION## $cmd"
  }
  close $fid
  
  xth_status_bar_pop cp
  return 1
}

proc xth_cp_save_as {} {

  global xth

  if {!$xth(cp,fopen)} {
    return 0
  }

  set fname $xth(cp,ffull)
  set idir [file dirname $fname]
  if {[string length $idir] == 0} {
    set idir $xth(gui,initdir)
  }
  set fname [tk_getSaveFile -filetypes $xth(app,cp,filetypes) \
    -parent $xth(gui,main) \
    -initialfile [file tail $fname] \
    -initialdir [file dirname $fname]]

  if {[string length $fname] == 0} {
    return 0
  } else {
    set xth(gui,initdir) [file dirname $fname]
  }

  if {![xth_cp_write_file $fname]} {
    return 0
  }

  set xth(cp,fname) [file tail $fname]
  set xth(cp,open_file) [file tail $fname]
  set xth(cp,fpath) [file dirname $fname]
  set xth(cp,ffull) $fname
  xth_app_title cp
  update idletasks  
  return 1
}


# xth_cp_read_file --
#
# return success
# {success name cmds lns}

proc xth_cp_read_file {pth} {

  global errorInfo xth

  set curenc utf-8
  set nm [file tail $pth]
  set encspc 0
  set flnn 0
  set success 1
  set lastln ""
  set lns {}
  set cmds {}
  if {[catch {set fid [open $pth r]}]} {
    set success 0
    set nm $errorInfo
    return [list $success $nm {} {}]
  }
  fconfigure $fid -encoding $curenc
  while {![eof $fid]} {
    gets $fid fln
    incr flnn
    if {[regexp {^\s*encoding\s+(\S+)\s*$} $fln encln enc]} {
      set encspc 1
      set rxp "\\s+($enc)\\s+"
      set validenc [regexp -nocase $rxp $xth(encodings) dum curenc]
      if {$validenc == 0} {
        set success 0
        set nm "$pth \[$flnn\] -- unknown encoding -- $enc"
        break
      }
      fconfigure $fid -encoding $curenc
      set lastln ""
    } elseif {[regexp {^\s*\#\#XTHERION\#\#\s+(\S.*)\s*$} $fln cmmdln cmmd]} {
      lappend cmds $cmmd
      set lastln ""
    } else {
      if {[regexp {(.*)\\\s*$} $lastln dumln prevln]} {
        set fln "$prevln$fln"
        if {[llength $lns] > 1} {
          set lns [lrange $lns 0 [expr [llength $lns] - 2]]
        } else {
          set lns {}
        }
      }
      lappend lns $fln
      set lastln $fln
    }
  }
  close $fid
  return [list $success $nm $cmds $lns]
  
}  


proc xth_cp_is_config_file {fname} {
  set str {}
  if {[regexp {\.pdf$} $fname]} {
    catch {
      set str {not a config file}
      set fid [open $fname r]
      fconfigure $fid -eofchar {}
      set allstr [read $fid]
      close $fid
      if {[regexp {\s+\/TeXsetup\s+\/([0-9a-fA-F]+)\s+} $allstr dum wstr]} {
        set str {}
        set i 0
        while {[string length $wstr] > 0} {
          set n "0x[string range $wstr 0 1]"
          append str [format "%c" [expr (255 - $n + $i) % 256]]
          set wstr [string range $wstr 2 end]
          incr i
        }
      }
    }
  }
  return $str
}


proc xth_cp_compile {} {
  global xth errorInfo
  set xth(cp,compres) 0
  if {!$xth(cp,fopen)} {
    return 0;
  }
  set ret 1
  xth_cp_write_file $xth(cp,ffull)
  set cdir [pwd]
  cd $xth(cp,fpath)
  $xth(cp,log).txt configure -state normal
  $xth(cp,log).txt delete 1.0 end
  $xth(cp,log).txt configure -wrap word
  $xth(cp,editor).txt configure -state disabled
  xth_status_bar_push cp
  
  catch {
    set lid [open "therion.log" w]
    puts $lid "ERROR: Can not execute \"$xth(gui,compcmd) -x $xth(cp,opts) $xth(cp,fname)\"."
    close $lid
  }  
  
  xth_status_bar_status cp [mc "Running therion ..."]
  $xth(ctrl,cp,stp).gores configure -text [mc "RUNNING"] -fg black -bg yellow
  update idletasks
  set err [catch {
    set thid [open "|$xth(gui,compcmd) -x $xth(cp,opts) $xth(cp,fname)" r]
    if $xth(gui,compshow) {
      while {![eof $thid]} {
        $xth(cp,log).txt insert end [read $thid 8]
        $xth(cp,log).txt see end
        update idletasks
      }
    } else {
      read $thid;
    }
    close $thid
  }]
  
  set see_end 0
  if {$err} {
    bell
    $xth(ctrl,cp,stp).gores configure -text [mc "ERROR"] -fg white -bg red
    set ret 0
    set see_end 1
  } else {
    set xth(cp,compres) 1
    $xth(ctrl,cp,stp).gores configure -text [mc "OK"] -fg black -bg green
  }
  
  xth_status_bar_status cp [mc "Reading therion log file ..."]
  if {[catch {
    set lid [open "therion.log" r]
    $xth(cp,log).txt delete 1.0 end
    $xth(cp,log).txt configure -wrap none
    $xth(cp,log).txt insert end "[read $lid]\n"
    close $lid
    }]} {
      $xth(cp,log).txt insert end [mc "\nerror opening therion.log file\n"]
  }
  if ($see_end) {
    $xth(cp,log).txt see end
  } else {
    $xth(cp,log).txt see 1.0
  }
  xth_status_bar_pop cp
  update idletasks

  $xth(cp,log).txt configure -state normal
  $xth(cp,editor).txt configure -state normal
  xth_cp_show_errors

  # update configuration file if required
  set xth(cp,cursor) [$xth(cp,editor).txt index insert]
  if {1} {
    set fdata [xth_me_read_file $xth(cp,ffull) 0]
    if {[lindex $fdata 0] == 0} {
        MessageDlg $xth(gui,message) -parent $xth(gui,main) \
          -icon error -type ok \
          -message [lindex $fdata 1] \
          -font $xth(gui,lfont)
    } else {
      xth_cp_data_tree_clear      

      catch {
        set fid [open [file join [file dirname $xth(cp,ffull)] [xth_xcfg_fname $xth(cp,ffull)]] r]
        fconfigure $fid -encoding utf-8
        while {![eof $fid]} {
          catch {eval [gets $fid]}
        }
        close $fid
      }

      set xth(cp,special) [lindex $fdata 2]
      
      $xth(cp,editor).txt delete 1.0 end
      foreach ln [lindex $fdata 3] {
        $xth(cp,editor).txt insert end "$ln\n"
      }
      
      $xth(cp,editor).txt mark set insert $xth(cp,cursor)
      $xth(cp,editor).txt see $xth(cp,cursor)
      
    }
  }
  cd $cdir
  xth_me_xvi_refresh
  xth_me_save_file 0
  return $ret
}


proc xth_cp_data_tree_clear {} {
  global xth
  set tp $xth(ctrl,cp,dat).t 
  set xth(ctrl,cp,datrestore) {}
  foreach di $xth(ctrl,cp,datlist) {
    catch {
      append xth(ctrl,cp,datrestore) "catch \{$tp itemconfigure [lindex $di 1] -open [$tp itemcget [lindex $di 1] -open]\}\n";
    }
  }
  append xth(ctrl,cp,datrestore) "update idletasks\n"
  append xth(ctrl,cp,datrestore) "catch \{$tp xview moveto [lindex [$tp xview] 0]\}\n";
  append xth(ctrl,cp,datrestore) "catch \{$tp yview moveto [lindex [$tp yview] 0]\}\n";
  append xth(ctrl,cp,datrestore) "catch \{$tp selection set [$tp selection get]\}\n";
  append xth(ctrl,cp,datrestore) "update idletasks\n"
  catch {
    $tp delete [$tp nodes root]
  }
  set tp $xth(ctrl,cp,ms).t 
  set xth(ctrl,cp,msrestore) {}
  foreach di $xth(ctrl,cp,maplist) {
    catch {
      append xth(ctrl,cp,msrestore) "catch \{$tp itemconfigure [lindex $di 1] -open [$tp itemcget [lindex $di 1] -open]\}\n";
    }
  }
  append xth(ctrl,cp,msrestore) "update idletasks\n"
  append xth(ctrl,cp,msrestore) "catch \{$tp xview moveto [lindex [$tp xview] 0]\}\n";
  append xth(ctrl,cp,msrestore) "catch \{$tp yview moveto [lindex [$tp yview] 0]\}\n";
  append xth(ctrl,cp,msrestore) "catch \{$tp selection set [$tp selection get]\}\n";
  append xth(ctrl,cp,msrestore) "update idletasks\n"
  catch {
    $tp delete [$tp nodes root]
  }
  $xth(ctrl,cp,info).txt delete 1.0 end
  # prejde oba stromy a priradi rozvinutie/zvinutie do prikazov
  # plus ulozi poziciu
}

proc xth_cp_data_tree_insert {id parent level name fullname title stitle stat} {
  global xth
  if {[string length $title] < 1} {
    set title $name
    set stitle $name
  }
  lappend xth(ctrl,cp,datlist) [list $stitle $id $parent $level $name $fullname $title $stat]
}

proc xth_cp_data_tree_create {} {
  global xth
  if {[llength $xth(ctrl,cp,datlist)] == 0} {
    return
  }
  set nlist [lsort -dictionary -index 0 $xth(ctrl,cp,datlist)]
  set level 0
  set tocnt 1
  set copen 1
  set tp $xth(ctrl,cp,dat).t 
  while {$tocnt} {
    set tocnt 0
    foreach di $nlist {
      if {[lindex $di 3] == $level} {
        if {$level == 0} {
          set parent root
        } else {
          set parent [lindex $di 2]
        }
        catch {
          $tp insert end $parent [lindex $di 1] -data [list survey [lindex $di 5] [lindex $di 6] [lindex $di 7]] \
            -text [lindex $di 6] -image [Bitmap::get folder] -open $copen -font $xth(gui,lfont)
        }
      }
      if {[lindex $di 3] > $level} {
        set tocnt 1
      }
    }
    set copen 0
    incr level
  }
  catch {
    eval $xth(ctrl,cp,datrestore)
  }
}

proc xth_cp_map_tree_insert {type subtype id parent level name fullname title stitle} {
  global xth
  if {[string length $title] < 1} {
    set title $name
    set stitle $name
  }
  lappend xth(ctrl,cp,maplist) [list $stitle $id $parent $level $name $fullname $title $type $subtype]
}

proc xth_cp_map_tree_create {} {
  global xth
  if {[llength $xth(ctrl,cp,maplist)] == 0} {
    return
  }
  set nlist [lsort -dictionary -index 0 $xth(ctrl,cp,maplist)]
  set level 0
  set tocnt 1
  set copen 1
  set tp $xth(ctrl,cp,ms).t 
  while {$tocnt} {
    set tocnt 0
    foreach di $nlist {
      if {[lindex $di 3] == $level} {
        if {$level == 0} {
          set parent root
        } else {
          set parent [lindex $di 2]
        }
        set ccopen $copen
        switch [lindex $di 7] {
          map {
            if {[lindex $di 8]} {
              set ii [Bitmap::get file]
              set ccopen 0
            } else {
              set ii [Bitmap::get copy]
            }
          }
          scrap {
            set ii [Bitmap::get new]
          }
          default {
            set ii [Bitmap::get folder]
          } 
        }
        catch {
          $tp insert end $parent [lindex $di 1] -data [list [lindex $di 7] [lindex $di 5] [lindex $di 6]] \
            -text [lindex $di 6] -image $ii -open $ccopen -font $xth(gui,lfont)
        }
      }
      if {[lindex $di 3] > $level} {
        set tocnt 1
      }
    }
    set copen 0
    incr level
  }
  
  # odstrani projekcie bez map
  set prjs [$tp nodes root]
  foreach prj $prjs {
    set nds [$tp nodes $prj]
    switch [llength $nds] {
      0 {
        $tp delete $prj
      }
      1 {
        $tp itemconfigure $nds -open 1
      }
    }
  }

  catch {
    eval $xth(ctrl,cp,msrestore)
  }
}



proc xth_cp_data_tree_enter {node} {
  global xth
  set tp $xth(ctrl,cp,dat).t 
  xth_status_bar_push cp
  set d [$xth(ctrl,cp,dat).t itemcget $node -data]
  xth_status_bar_status cp [format "%s - %s (%s)" [lindex $d 0] [lindex $d 1] [lindex $d 2]]
}


proc xth_cp_data_tree_select {tpath node} {
  global xth
  set tp $tpath
  xth_status_bar_push cp
  set d [$tp itemcget $node -data]
  $xth(ctrl,cp,info).txt delete 1.0 end
  $xth(ctrl,cp,info).txt see 1.0
  $xth(ctrl,cp,info).txt insert 1.0 "name: [lindex $d 1]\ntitle: [lindex $d 2]\n[lindex $d 3]"
}



proc xth_cp_data_tree_leave {node} {
  xth_status_bar_pop cp
}

proc xth_cp_data_tree_double_click {node} {
  global xth
  set tp $xth(ctrl,cp,dat).t 
  set d [$tp itemcget $node -data]
  set i [$xth(cp,editor).txt index insert]  
  regexp {(\d+)\.} $i dum cln
  $xth(cp,editor).txt insert $cln.0 [format "select %s\n" [lindex $d 1]]
}

proc xth_cp_map_tree_enter {node} {
  global xth
  set tp $xth(ctrl,cp,ms).t 
  xth_status_bar_push cp
  set d [$xth(ctrl,cp,ms).t itemcget $node -data]
  xth_status_bar_status cp [format "%s - %s (%s)" [lindex $d 0] [lindex $d 1] [lindex $d 2]]
}

proc xth_cp_map_tree_leave {node} {
  xth_status_bar_pop cp
}

proc xth_cp_map_tree_double_click {node} {
  global xth
  set tp $xth(ctrl,cp,ms).t 
  set d [$tp itemcget $node -data]
  set i [$xth(cp,editor).txt index insert]  
  regexp {(\d+)\.} $i dum cln
  if {[string length [lindex $d 1]] > 0} {
    $xth(cp,editor).txt insert $cln.0 [format "select %s\n" [lindex $d 1]]
  }
}


proc xth_cp_show_errors {} {
  
  global xth
  
  set w $xth(cp,log).txt
  $w tag remove xtherr 1.0 end

  set rx {\S*[^\]\s]\s+\[\d+\]}
  set fnd [$w search -regexp -count cnt $rx 1.0 end]
  
  set i 0
  while {([string length $fnd] > 0) && ($i < 10000)} {
    
    set enx [$w index "$fnd + $cnt chars"]
    set ctext [$w get $fnd "$fnd lineend"]
    set cfnm {}
    regexp {\S+} $ctext cfnm
  
    if {![regexp {(\.mp|\.tex)\)?$} $cfnm]} {
      $w tag add xtherr $fnd $enx
    }

    set fnd [$w search -regexp -count cnt $rx $enx end]
    incr i    
    
  }
  
  $w tag configure xtherr -foreground red
  set prevcur [$xth(cp,log).txt cget -cursor]
  $w tag bind xtherr <Enter> "$w configure -cursor hand2"
  $w tag bind xtherr <Leave> "$w configure -cursor $prevcur"
  $w tag bind xtherr <1> "xth_cp_goto_error %x %y"
 
}



proc xth_cp_goto_error {x y} {
  global xth

  set epos [$xth(cp,log).txt get "@$x,$y wordstart" "@$x,$y lineend"]
  
  # skusime najst source error
  set fnm {}
  set fln {}
  if {(![regexp {\s*(\S+)\s+\[(\d+)\]} $epos dum fnm fln]) || [string equal $fnm "th"] || [string equal $fnm "th2"] || [string equal $fnm ".th"] || [string equal $fnm ".th2"]} {
    set epos [$xth(cp,log).txt get "@$x,$y linestart" "@$x,$y lineend"]
    regexp {\s*(\S+)\s+\[(\d+)\]} $epos dum fnm fln
  }
  
  if {([string length $fnm] == 0) || ([string length $fln] == 0)} {
    return
  }  
  
  if {[catch {set fln [expr $fln - 1]}]} {
    return
  }
  
  # potom sa pozrieme ci subor nemame otvoreny v kompilatore,
  # mapovom alebo textovom editore a skocime tam
  
  if $xth(cp,fopen) {
  
    set fullfnm [file join $xth(cp,fpath) $fnm]

    if {[string equal $fullfnm $xth(cp,ffull)]} {
      after idle "focus $xth(cp,editor).txt; $xth(cp,editor).txt see $fln.0; $xth(cp,editor).txt mark set insert $fln.0; $xth(cp,editor).txt tag remove sel 1.0 end; $xth(cp,editor).txt tag add sel $fln.0 \"$fln.0 lineend\""
      return
    }
    
    if {$xth(me,fopen) && [string equal $fullfnm $xth(me,ffull)]} {
      after idle "xth_app_show me; xth_me_goto_line [expr $fln + 1]"
      return
    }
  
    # skusime textovy editor, ci to mame otvorene
    foreach fx $xth(te,flist) {
      if {[string equal $fullfnm $xth(te,$fx,path)]} {
        after idle "xth_app_show te; xth_te_show_file $fx; $xth(te,$fx,frame).txt see $fln.0; $xth(te,$fx,frame).txt mark set insert $fln.0; $xth(te,$fx,frame).txt tag remove sel 1.0 end; $xth(te,$fx,frame).txt tag add sel $fln.0 \"$fln.0 lineend\""
        return
      }
    }
    
    after idle "xth_app_show te; xth_te_open_file 0 [list $fullfnm] $fln"
  
  }
  
  
}









#! /usr/bin/wish

# TODO:
# vstup hodiny : minuty

proc xth_bac_check {number from to wgt} {

  set rw 0
  if [catch {expr double($number)}] {
    set rw 1
  } else {
    set num [expr double($number)]
    if {($num < $from) || ($num > $to)} {
      set rw 1
    }
  }
  
  if {$rw} {
    $wgt configure -fg red
    return 0
  } else {
    $wgt configure -fg black
    return 1
  }
  
}

proc xth_bac_hm2h {h} {
  if {[regexp {(.+)\:(.+)} $h dum hh mm]} {
    if {[catch {
      set h [expr double($hh) + double($mm) / 60.0]
      return $h
    }]} {
      return $h
    }
  } else {
    return $h
  }
}

proc xth_bac_h2hm {h} {
  catch {
    set hh [expr int(floor($h))]
    set mm [expr int($h*60.0) % 60]
    if {$mm != 0.0} {
      set h [format "%d:%02d" $hh $mm]  
    } else {
      set h $hh
    }
  }
  return $h
}

proc xth_bac_calculate {} {

  global xth

  set xth(bac,BAC) ""
  set xth(bac,ETA) ""
  set xth(bac,MRS) ""
  set f $xth(gui,bacw)
  $f.rdle configure -bg $xth(bac,bg) -fg black

  set gender xth(bac,gender)
  set nok 0
  if [xth_bac_check $xth(bac,age) 0 1e10 $f.bdal] {set age $xth(bac,age)} else {set nok 1}
  if [xth_bac_check $xth(bac,height) 0 1e10 $f.bdhl] {set height $xth(bac,height)} else {set nok 1}
  if [xth_bac_check $xth(bac,weight) 0 1e10 $f.bdwl] {set weight $xth(bac,weight)} else {set nok 1}
  if [xth_bac_check $xth(bac,volume) 0 1e10 $f.cdvl] {set volume $xth(bac,volume)} else {set nok 1}
  if [xth_bac_check $xth(bac,level) 0 100 $f.cdll] {set level $xth(bac,level)} else {set nok 1}
  set xth(bac,time) [xth_bac_hm2h $xth(bac,time)]
  if [xth_bac_check $xth(bac,time) 0 1e10 $f.cdtl] {set elapsedTime [expr double($xth(bac,time))]} else {set nok 1}
  set xth(bac,time) [xth_bac_h2hm $xth(bac,time)]
  if $nok return

  set ALCOHOL_DENSITY 0.79
  set ingested [expr double($volume) * double($level) * 0.01 * $ALCOHOL_DENSITY]

  # in g/hr
	set METABOLIC_REMOVAL_RATE 7.0
	set remaining [expr $ingested - ($METABOLIC_REMOVAL_RATE * $elapsedTime)]
  if {$remaining < 0.0} {set remaining 0}
  
  if $xth(bac,gender) {
	  set HEIGHT_FACTOR 0.1074
    set WEIGHT_FACTOR 0.3362
    set AGE_FACTOR 0.09516
    set BODY_WATER_CONST 2.447
  } else {
    set HEIGHT_FACTOR 0.1069
    set WEIGHT_FACTOR 0.2466
    set AGE_FACTOR 0
    set BODY_WATER_CONST 2.097
  }
	set h [expr $HEIGHT_FACTOR * $height]
	set w [expr $WEIGHT_FACTOR * $weight]
	set a [expr $AGE_FACTOR * $age]
	set bodyWater [expr ($h - $a + $w + $BODY_WATER_CONST) * 1000.0]
  
	set WATER_CONTENT_OF_BLOOD 0.8157
	set BAC [expr 100.0 * ($remaining / ($bodyWater / $WATER_CONTENT_OF_BLOOD))]
	set MRS [expr 100.0 * ($METABOLIC_REMOVAL_RATE / ($bodyWater / $WATER_CONTENT_OF_BLOOD))]
  set maxRemaining [expr ($bodyWater / $WATER_CONTENT_OF_BLOOD) * 0.0002]
  if {$maxRemaining < $remaining} {
    set ETA [expr ($remaining - $maxRemaining) / $METABOLIC_REMOVAL_RATE]
  } else {
    set ETA 0.0
  }
  
  
  set xth(bac,BAC) [format "%.3f" $BAC]
  set xth(bac,ETA) [format "%d:%02d" [expr int(floor($ETA))] [expr int($ETA*60.0) % 60]]
  set xth(bac,MRS) [format "%.3f" $MRS]
  
  if {$BAC < 0.02} {
    $f.rdle configure -bg green -fg black
  } else {
    $f.rdle configure -bg red -fg white
  }

}


proc xth_bac_init {} {

  global xth
  
  set f $xth(gui,bacw)
  toplevel $f
  wm transient $f $xth(gui,main)
  wm title $f [mc "BAC calculator"]
  
  Label $f.bdl -text [mc "Biometric data"] -anchor center -font $xth(gui,lfont)
  Label $f.bdal -text [mc "age"] -anchor e -font $xth(gui,lfont)
  Entry $f.bdae -font $xth(gui,lfont) -width 5 -textvariable xth(bac,age)
  Label $f.bdau -text [mc "years"] -anchor w -font $xth(gui,lfont)
  Label $f.bdgl -text [mc "gender"] -anchor e -font $xth(gui,lfont)
  radiobutton $f.bdgm -text [mc "male"] -anchor w \
  -font $xth(gui,lfont) -variable xth(bac,gender) -value 1
  radiobutton $f.bdgf -text [mc "female"] -anchor w \
  -font $xth(gui,lfont) -variable xth(bac,gender) -value 0
  Label $f.bdhl -text [mc "height"] -anchor e -font $xth(gui,lfont)
  Entry $f.bdhe -font $xth(gui,lfont) -width 5 -textvariable xth(bac,height)
  Label $f.bdhu -text "cm" -anchor w -font $xth(gui,lfont)
  Label $f.bdwl -text [mc "weight"] -anchor e -font $xth(gui,lfont)
  Entry $f.bdwe -font $xth(gui,lfont) -width 5 -textvariable xth(bac,weight)
  Label $f.bdwu -text "kg" -anchor w -font $xth(gui,lfont)
  Separator $f.s1 -orient horizontal

  Label $f.cdl -text [mc "Consumption data"] -anchor center -font $xth(gui,lfont)
  Label $f.cdvl -text [mc "volume"] -anchor e -font $xth(gui,lfont)
  Entry $f.cdve -font $xth(gui,lfont) -width 5 -textvariable xth(bac,volume)
  Label $f.cdvu -text "ml" -anchor w -font $xth(gui,lfont)

  Label $f.cdll -text [mc "alcohol level"] -anchor e -font $xth(gui,lfont)
  Entry $f.cdle -font $xth(gui,lfont) -width 5 -textvariable xth(bac,level)
  Label $f.cdlu -text "%" -anchor w -font $xth(gui,lfont)
  
  Label $f.cdtl -text [mc "time elapsed"] -anchor e -font $xth(gui,lfont)
  Entry $f.cdte -font $xth(gui,lfont) -width 5 -textvariable xth(bac,time)
  Label $f.cdtu -text [mc "hours"] -anchor w -font $xth(gui,lfont)

  Button $f.calc -text [mc "Calculate"] -anchor center -font $xth(gui,lfont) \
  -command xth_bac_calculate

  Label $f.rdll -text [mc "BAC"] -anchor e -font $xth(gui,lfont)
  Entry $f.rdle -font $xth(gui,lfont) -width 5 -textvariable xth(bac,BAC) \
    -editable 0
  Label $f.rdlu -text "%" -anchor w -font $xth(gui,lfont)
  
  Label $f.rdtl -text [mc "ETA"] -anchor e -font $xth(gui,lfont)
  Entry $f.rdte -font $xth(gui,lfont) -width 5 -textvariable xth(bac,ETA) \
    -editable 0
  Label $f.rdtu -text [mc "hours"] -anchor w -font $xth(gui,lfont)

  Label $f.rdml -text [mc "MRR"] -anchor e -font $xth(gui,lfont)
  Entry $f.rdme -font $xth(gui,lfont) -width 5 -textvariable xth(bac,MRS) \
    -editable 0
  Label $f.rdmu -text "%/h" -anchor w -font $xth(gui,lfont)

  Button $f.cls -text [mc "Close"] -anchor center -font $xth(gui,lfont) \
  -command "destroy $f"

  
  grid columnconf $f 0 -weight 0
  grid columnconf $f 1 -weight 1
  grid columnconf $f 2 -weight 0

  grid $f.bdl -column 0 -row 0 -columnspan 3 -sticky news 
  grid $f.cdl -column 0 -row 7 -columnspan 3 -sticky news 

  grid $f.bdal -column 0 -row 1 -columnspan 1 -sticky news 
  grid $f.bdgl -column 0 -row 2 -rowspan 2 -sticky news 
  grid $f.bdhl -column 0 -row 4 -columnspan 1 -sticky news 
  grid $f.bdwl -column 0 -row 5 -columnspan 1 -sticky news 
  grid $f.cdvl -column 0 -row 8 -columnspan 1 -sticky news 
  grid $f.cdll -column 0 -row 9 -columnspan 1 -sticky news 
  grid $f.cdtl -column 0 -row 10 -columnspan 1 -sticky news 
  grid $f.rdll -column 0 -row 12 -columnspan 1 -sticky news 
  grid $f.rdtl -column 0 -row 13 -columnspan 1 -sticky news 
  grid $f.rdml -column 0 -row 14 -columnspan 1 -sticky news 

  grid $f.bdae -column 1 -row 1 -columnspan 1 -sticky news 
  grid $f.bdgf -column 1 -row 3 -columnspan 2 -sticky news 
  grid $f.bdgm -column 1 -row 2 -columnspan 2 -sticky news 
  grid $f.bdhe -column 1 -row 4 -columnspan 1 -sticky news 
  grid $f.bdwe -column 1 -row 5 -columnspan 1 -sticky news 
  grid $f.cdve -column 1 -row 8 -columnspan 1 -sticky news 
  grid $f.cdle -column 1 -row 9 -columnspan 1 -sticky news 
  grid $f.cdte -column 1 -row 10 -columnspan 1 -sticky news 
  grid $f.rdle -column 1 -row 12 -columnspan 1 -sticky news 
  grid $f.rdte -column 1 -row 13 -columnspan 1 -sticky news 
  grid $f.rdme -column 1 -row 14 -columnspan 1 -sticky news 

  grid $f.bdau -column 2 -row 1 -columnspan 1 -sticky news 
  grid $f.bdhu -column 2 -row 4 -columnspan 1 -sticky news 
  grid $f.bdwu -column 2 -row 5 -columnspan 1 -sticky news 
  grid $f.cdvu -column 2 -row 8 -columnspan 1 -sticky news 
  grid $f.cdlu -column 2 -row 9 -columnspan 1 -sticky news 
  grid $f.cdtu -column 2 -row 10 -columnspan 1 -sticky news 
  grid $f.rdlu -column 2 -row 12 -columnspan 1 -sticky news 
  grid $f.rdtu -column 2 -row 13 -columnspan 1 -sticky news 
  grid $f.rdmu -column 2 -row 14 -columnspan 1 -sticky news 

  grid $f.s1 -row 6 -column 0 -columnspan 3 -sticky news -pady 3 -padx 3
  grid $f.calc -row 11 -column 0 -columnspan 3 -sticky news -pady 3 -padx 3
  grid $f.cls -row 15 -column 0 -columnspan 3 -sticky news -pady 3 -padx 3

  set xth(bac,bg) [$f.rdle cget -bg]

  set sw [winfo screenwidth .]
  set sh [winfo screenheight .]
  update idletasks
  wm geometry $f -$sw-$sh
  set x [expr {($sw - [winfo width $f])/2}]
  set y [expr {($sh - [winfo height $f])/2}]
  wm geometry $f +$x+$y
  update idletasks
  
}


if 0 {
  package require BWidget
  source ver.tcl
  source global.tcl
  wm withdraw .
  set xth(gui,bacw) .f
  xth_bac_init
} else {
  set xth(bac,age) ""
  set xth(bac,height) ""
  set xth(bac,weight) ""
  set xth(bac,volume) ""
  set xth(bac,level) ""
  set xth(bac,time) ""
}

set xth(bac,gender) 1
set xth(bac,BAC) ""
set xth(bac,ETA) ""
set xth(bac,MRS) ""
  
if 0 {
  set xth(bac,age) "25"
  set xth(bac,height) "193"
  set xth(bac,weight) "90"
  set xth(bac,volume) "500"
  set xth(bac,level) "5.5"
  set xth(bac,time) "0"
}









xth_app_create cp [mc "Compiler"]
xth_ctrl_add cp stp [mc "Settings"]
xth_ctrl_add cp dat [mc "Survey structure"]
xth_ctrl_add cp info [mc "Survey info"]
xth_ctrl_add cp ms [mc "Map structure"]
xth_ctrl_finish cp



# create config editor
set xth(cp,editor) $xth(gui,cp).af.apps.ed
frame $xth(cp,editor)
set txb $xth(cp,editor)
text $txb.txt -wrap none -font $xth(gui,efont) \
  -bg $xth(gui,ecolorbg) \
  -fg $xth(gui,ecolorfg) -insertbackground $xth(gui,ecolorfg) \
  -relief sunken -state disabled \
  -selectbackground $xth(gui,ecolorselbg) \
  -selectforeground $xth(gui,ecolorselfg) \
  -selectborderwidth 0 \
  -yscrollcommand "$txb.sv set" \
  -xscrollcommand "$txb.sh set" 
if {$xth(gui,text_undo)} {
    $txb.txt configure -undo 1 -maxundo -1
}
scrollbar $txb.sv -orient vert  -command "$txb.txt yview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
scrollbar $txb.sh -orient horiz  -command "$txb.txt xview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
grid columnconf $txb 0 -weight 1
grid rowconf $txb 0 -weight 1
grid $txb.txt -column 0 -row 0 -sticky news
grid $txb.sv -column 1 -row 0 -sticky news
grid $txb.sh -column 0 -row 1 -sticky news
bind $txb.txt <$xth(kb_control)-Key-x> "tk_textCut $txb.txt"
bind $txb.txt <$xth(kb_control)-Key-c> "tk_textCopy $txb.txt"
bind $txb.txt <$xth(kb_control)-Key-v> "tk_textPaste $txb.txt"
bind $txb.txt <$xth(kb_control)-Key-z> "catch {$txb.txt edit undo}"
bind $txb.txt <$xth(kb_control)-Key-y> "catch {$txb.txt edit redo}"

if {$xth(gui,bindinsdel)} {
  bind $txb.txt <Delete> {
    %W delete insert
    %W see insert
  }
  bind $txb.txt <Shift-Key-Delete> "tk_textCut $txb.txt"
  bind $txb.txt <$xth(kb_control)-Key-Insert> "tk_textCopy $txb.txt"
  bind $txb.txt <Shift-Key-Insert> "tk_textPaste $txb.txt"
#  catch {
#    bind $txb.txt <Shift-Key-KP_Decimal> "tk_textCut $txb.txt"
#    bind $txb.txt <$xth(kb_control)-Key-KP_Insert> "tk_textCopy $txb.txt"
#    bind $txb.txt <Shift-Key-KP_0> "tk_textPaste $txb.txt"
#  }
}

# nechame tab, return originalny
if {[info exists xth(gui,te)]} {
#  bind $txb.txt <$xth(kb_control)-Key-a> "xth_te_text_select_all %W"
#  bind $txb.txt <$xth(kb_control)-Key-i> "xth_te_text_auto_indent %W"
  bind $txb.txt <Tab> $xth(te,bind,text_tab)
  bind $txb.txt <Return> $xth(te,bind,text_return)
} else {
  bind $txb.txt <Tab> $xth(gui,bind,text_tab)
  bind $txb.txt <Return> $xth(gui,bind,text_return)
}


# create log window
set xth(cp,log) $xth(gui,cp).af.apps.log
frame $xth(cp,log)
set txb $xth(cp,log)
text $txb.txt -wrap none -font $xth(gui,efont) \
  -bg $xth(gui,ecolorbg) \
  -fg $xth(gui,ecolorfg) -insertbackground $xth(gui,ecolorfg) \
  -relief sunken -state disabled \
  -selectbackground $xth(gui,ecolorselbg) \
  -selectforeground $xth(gui,ecolorselfg) \
  -selectborderwidth 0 \
  -yscrollcommand "$txb.sv set" \
  -xscrollcommand "$txb.sh set" 
scrollbar $txb.sv -orient vert  -command "$txb.txt yview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
scrollbar $txb.sh -orient horiz  -command "$txb.txt xview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
grid columnconf $txb 0 -weight 1
grid rowconf $txb 0 -weight 1
grid $txb.txt -column 0 -row 0 -sticky news
grid $txb.sv -column 1 -row 0 -sticky news
grid $txb.sh -column 0 -row 1 -sticky news
bind $txb.txt <$xth(kb_control)-Key-x> "tk_textCut $txb.txt"
bind $txb.txt <$xth(kb_control)-Key-c> "tk_textCopy $txb.txt"
bind $txb.txt <$xth(kb_control)-Key-v> "tk_textPaste $txb.txt"

if {$xth(gui,bindinsdel)} {
  bind $txb.txt <Delete> {
    %W delete insert
    %W see insert
  }
  bind $txb.txt <Shift-Key-Delete> "tk_textCut $txb.txt"
  bind $txb.txt <$xth(kb_control)-Key-Insert> "tk_textCopy $txb.txt"
  bind $txb.txt <Shift-Key-Insert> "tk_textPaste $txb.txt"
#  catch {
#    bind $txb.txt <Shift-Key-KP_Decimal> "tk_textCut $txb.txt"
#    bind $txb.txt <$xth(kb_control)-Key-KP_Insert> "tk_textCopy $txb.txt"
#    bind $txb.txt <Shift-Key-KP_0> "tk_textPaste $txb.txt"
#  }
}

xth_status_bar cp $txb.txt "Therion log file."


# pack editor and log widow
grid columnconf $xth(gui,cp).af.apps 0 -weight 1
grid rowconf $xth(gui,cp).af.apps 0 -weight 1
grid rowconf $xth(gui,cp).af.apps 1 -weight 1
grid $xth(cp,editor) -column 0 -row 0 -sticky news
grid $xth(cp,log) -column 0 -row 1 -sticky news

# create setup control
Label $xth(ctrl,cp,stp).wl -text [mc "Working directory"] -anchor w -font $xth(gui,lfont) -state disabled
xth_status_bar cp $xth(ctrl,cp,stp).wl [mc "Working directory path."]
Entry $xth(ctrl,cp,stp).we -font $xth(gui,lfont) -state disabled \
  -editable off -textvariable xth(cp,fpath)
xth_status_bar cp $xth(ctrl,cp,stp).we [mc "Working directory path."]

Label $xth(ctrl,cp,stp).fl -text [mc "Configuration file"] -anchor w -font $xth(gui,lfont) -state disabled
xth_status_bar cp $xth(ctrl,cp,stp).fl [mc "Configuration file name."]
Entry $xth(ctrl,cp,stp).fe -font $xth(gui,lfont) -state disabled \
  -editable off -textvariable xth(cp,fname)
xth_status_bar cp $xth(ctrl,cp,stp).fe [mc "Configuration file name."]

Label $xth(ctrl,cp,stp).optl -text [mc "Command line options"] -anchor w -font $xth(gui,lfont) -state disabled
xth_status_bar cp $xth(ctrl,cp,stp).optl [mc "Therion command line options."]
Entry $xth(ctrl,cp,stp).opte -font $xth(gui,lfont) -state disabled \
  -textvariable xth(cp,opts)
xth_status_bar cp $xth(ctrl,cp,stp).opte [mc "Therion command line options."]

Button $xth(ctrl,cp,stp).go -text [mc "Compile"] -anchor center -font $xth(gui,lfont) \
  -state disabled -command {xth_cp_compile} -width 4
Label $xth(ctrl,cp,stp).gores -text "" -anchor center -font $xth(gui,lfont) \
  -state disabled -width 4 -relief sunken
set xth(cp,resfg) [$xth(ctrl,cp,stp).gores cget -fg]
set xth(cp,resbg) [$xth(ctrl,cp,stp).gores cget -bg]
xth_status_bar cp $xth(ctrl,cp,stp).go [mc "Run therion."]

grid columnconf $xth(ctrl,cp,stp) 0 -weight 1
grid columnconf $xth(ctrl,cp,stp) 1 -weight 1
grid $xth(ctrl,cp,stp).wl -row 0 -column 0 -columnspan 2 -sticky news
grid $xth(ctrl,cp,stp).we -row 1 -column 0 -columnspan 2 -sticky news
grid $xth(ctrl,cp,stp).fl -row 2 -column 0 -columnspan 2 -sticky news
grid $xth(ctrl,cp,stp).fe -row 3 -column 0 -columnspan 2 -sticky news
grid $xth(ctrl,cp,stp).optl -row 4 -column 0 -columnspan 2 -sticky news
grid $xth(ctrl,cp,stp).opte -row 5 -column 0 -columnspan 2 -sticky news
grid $xth(ctrl,cp,stp).go -row 6 -column 0 -sticky news
grid $xth(ctrl,cp,stp).gores -row 6 -column 1 -sticky ew

# create objects control
set clbox $xth(ctrl,cp,dat)
scrollbar $clbox.sv -orient vert  -command "$clbox.t yview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
scrollbar $clbox.sh -orient horiz  -command "$clbox.t xview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
set tr [Tree $clbox.t -relief flat -height 16 -selectcommand xth_cp_data_tree_select \
  -yscrollcommand "$clbox.sv set" \
  -xscrollcommand "$clbox.sh set"]
set xth(ctrl,cp,datrestore) {}
$tr bindText <Enter> xth_cp_data_tree_enter
$tr bindText <Leave> xth_cp_data_tree_leave
$tr bindText <Double-ButtonPress-1> xth_cp_data_tree_double_click
$tr bindImage <Enter> xth_cp_data_tree_enter
$tr bindImage <Leave> xth_cp_data_tree_leave
$tr bindImage <Double-ButtonPress-1> xth_cp_data_tree_double_click

grid columnconf $clbox 0 -weight 1
grid rowconf $clbox 0 -weight 1
grid $tr -column 0 -row 0 -sticky news
grid $clbox.sv -column 1 -row 0 -sticky news
grid $clbox.sh -column 0 -row 1 -sticky news


# init survey info
set txb $xth(ctrl,cp,info)
text $txb.txt -height 4 -wrap none -font $xth(gui,efont) \
  -bg $xth(gui,ecolorbg) \
  -fg $xth(gui,ecolorfg) -insertbackground $xth(gui,ecolorfg) \
  -relief sunken -state disabled \
  -selectbackground $xth(gui,ecolorselbg) \
  -selectforeground $xth(gui,ecolorselfg) \
  -selectborderwidth 0 \
  -yscrollcommand "$txb.sv set" \
  -xscrollcommand "$txb.sh set" 
scrollbar $txb.sv -orient vert  -command "$txb.txt yview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
scrollbar $txb.sh -orient horiz  -command "$txb.txt xview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
grid columnconf $txb 0 -weight 1
grid rowconf $txb 0 -weight 1
grid $txb.txt -column 0 -row 0 -sticky news
grid $txb.sv -column 1 -row 0 -sticky news
grid $txb.sh -column 0 -row 1 -sticky news
xth_status_bar me $txb.txt [mc "Survey informations."]
bind $txb.txt <$xth(kb_control)-Key-x> "tk_textCut $txb.txt"
bind $txb.txt <$xth(kb_control)-Key-c> "tk_textCopy $txb.txt"
bind $txb.txt <$xth(kb_control)-Key-v> "tk_textPaste $txb.txt"

if {$xth(gui,bindinsdel)} {
  bind $txb.txt <Delete> {
    %W delete insert
    %W see insert
  }
  bind $txb.txt <Shift-Key-Delete> "tk_textCut $txb.txt"
  bind $txb.txt <$xth(kb_control)-Key-Insert> "tk_textCopy $txb.txt"
  bind $txb.txt <Shift-Key-Insert> "tk_textPaste $txb.txt"
#  catch {
#    bind $txb.txt <Shift-Key-KP_Decimal> "tk_textCut $txb.txt"
#    bind $txb.txt <$xth(kb_control)-Key-KP_Insert> "tk_textCopy $txb.txt"
#    bind $txb.txt <Shift-Key-KP_0> "tk_textPaste $txb.txt"
#  }
}



# create map structure control
set clbox $xth(ctrl,cp,ms)
scrollbar $clbox.sv -orient vert  -command "$clbox.t yview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
scrollbar $clbox.sh -orient horiz  -command "$clbox.t xview" \
  -takefocus 0 -width $xth(gui,sbwidth) -borderwidth $xth(gui,sbwidthb)
set tr [Tree $clbox.t -relief flat -height 16 \
  -yscrollcommand "$clbox.sv set" \
  -xscrollcommand "$clbox.sh set"]
set xth(ctrl,cp,msrestore) {}
$tr bindText <Enter> xth_cp_map_tree_enter
$tr bindText <Leave> xth_cp_map_tree_leave
$tr bindText <Double-ButtonPress-1> xth_cp_map_tree_double_click
$tr bindImage <Enter> xth_cp_map_tree_enter
$tr bindImage <Leave> xth_cp_map_tree_leave
$tr bindImage <Double-ButtonPress-1> xth_cp_map_tree_double_click
grid columnconf $clbox 0 -weight 1
grid rowconf $clbox 0 -weight 1
grid $tr -column 0 -row 0 -sticky news
grid $clbox.sv -column 1 -row 0 -sticky news
grid $clbox.sh -column 0 -row 1 -sticky news






# load menu
$xth(cp,menu,file) add command -label [mc "New"] -command {} \
  -font $xth(gui,lfont) -underline 0 -state normal -command {xth_cp_new_file}
$xth(cp,menu,file) add command -label [mc "Open"] -underline 0 \
  -accelerator "$xth(gui,controlk)-o" -state normal \
  -font $xth(gui,lfont) -command {
    xth_cp_open_file {}
  }
$xth(cp,menu,file) add command -label [mc "Save as"] -underline 5 \
  -state disabled -font $xth(gui,lfont) -command xth_cp_save_as
$xth(cp,menu,file) add command -label [mc "Close"] -underline 0 \
  -accelerator "$xth(gui,controlk)-w"  -state disabled \
  -font $xth(gui,lfont) \
  -command xth_cp_close_file

set xth(cp,menu,edit) $xth(cp,menu).edit
menu $xth(cp,menu,edit) -tearoff 0
$xth(cp,menu) add cascade -label [mc "Edit"] -state disabled \
  -font $xth(gui,lfont) -menu $xth(cp,menu,edit) -underline 0
if {$xth(gui,text_undo)} {
  $xth(cp,menu,edit) add command -label [mc "Undo"] -font $xth(gui,lfont) \
    -accelerator "$xth(gui,controlk)-z" -command "xth_app_clipboard undo"
  $xth(cp,menu,edit) add command -label [mc "Redo"] -font $xth(gui,lfont) \
    -accelerator "$xth(gui,controlk)-y" -command "xth_app_clipboard redo"
  $xth(cp,menu,edit) add separator
}
$xth(cp,menu,edit) add command -label [mc "Cut"] -font $xth(gui,lfont) \
  -accelerator "$xth(gui,controlk)-x" -command "xth_app_clipboard cut"
$xth(cp,menu,edit) add command -label [mc "Copy"] -font $xth(gui,lfont) \
  -accelerator "$xth(gui,controlk)-c" -command "xth_app_clipboard copy"
$xth(cp,menu,edit) add command -label [mc "Paste"] -font $xth(gui,lfont) \
  -accelerator "$xth(gui,controlk)-v" -command "xth_app_clipboard paste"

set xth(cp,fopen) 0
set xth(cp,cursor) 1.0
set xth(cp,fname) ""
set xth(cp,opts) ""
set xth(cp,fpath) ""

xth_ctrl_minimize cp dat
xth_ctrl_minimize cp info
xth_ctrl_minimize cp ms

set xth(ctrl,cp,datlist) {}
set xth(ctrl,cp,maplist) {}

xth_status_bar_status cp [mc "User interface is not active. To activate it, open existing file or create new one."]








set xthmvw {}

if {![catch {set tomver [package require Tom]}]} {

xth_about_status [mc "loading model viewer..."]

namespace import ::GL::*

xth_app_create mv [mc "Model viewer"] 
xth_ctrl_add mv cam [mc "Camera"]
xth_ctrl_add mv mod [mc "Model"]
xth_ctrl_finish mv

# create config editor
set xthmvw $xth(gui,mv).af.apps.tom
set xthmvv(model,surftrans) 1
set xthmvv(model,headlight) 1
set xthmvv(model,lightinpos) 1

tom $xthmvw -doublebuffer 1 -depth 1

# pack editor and log widow
grid columnconf $xth(gui,mv).af.apps 0 -weight 1
grid rowconf $xth(gui,mv).af.apps 0 -weight 1
grid $xthmvw -column 0 -row 0 -sticky news

$xth(mv,menu,file) add command -label [mc "Open"] -underline 0 \
  -accelerator "$xth(gui,controlk)-o" -state normal \
  -font $xth(gui,lfont) -command {
    xth_mv_open_file {}
  }

$xth(mv,menu,file) add command -label [mc "Reload"] -underline 0 \
  -accelerator "$xth(gui,controlk)-r" -state normal \
  -font $xth(gui,lfont) -command {
    xth_mv_reload_file
  }

set f $xth(ctrl,mv,cam)
set xthmvv(ctrlframe) $f

menubutton $f.fb -text [mc "facing"] -anchor e -font $xth(gui,lfont) \
  -indicatoron true -menu $f.fb.m -width 4
Label $f.fl -textvariable xthmvv(cam,facing) -anchor e -font $xth(gui,lfont) -width 4 -padx 30
menu $f.fb.m -tearoff 0 -font $xth(gui,lfont)
$f.fb.m add command -label [mc "north"] -command {set xthmvv(cam,facing) 0.0; xth_mv_update}
$f.fb.m add command -label [mc "east"] -command {set xthmvv(cam,facing) 90.0; xth_mv_update}
$f.fb.m add command -label [mc "west"] -command {set xthmvv(cam,facing) 180.0; xth_mv_update}
$f.fb.m add command -label [mc "south"] -command {set xthmvv(cam,facing) 270.0; xth_mv_update}
$f.fb.m add separator
$f.fb.m add command -label [mc "reset"] -command {xth_mv_init_camera; xth_mv_update}
xth_status_bar mv $f.fb [mc "Set facing angle."]
xth_status_bar mv $f.fl [mc "Facing angle."]

checkbutton $f.fa -text [mc "auto rotate"] -anchor w -font $xth(gui,lfont) \
  -variable xthmvv(cam,autorotate) -command {
    if {$xthmvv(cam,autorotate)} {
      set xthmvv(autorotate,dir) [expr -1 * $xthmvv(autorotate,dir)]
    }
    xth_mv_camera_autorotate
  } -width 4
xth_status_bar mv $f.fa [mc "Turn on/off camera auto rotation"]

menubutton $f.pb -text [mc "profile"] -anchor e -font $xth(gui,lfont) \
  -indicatoron true -menu $f.pb.m -width 4
Label $f.pl -textvariable xthmvv(cam,profile) -anchor e -font $xth(gui,lfont) -width 4 -padx 30
menu $f.pb.m -tearoff 0 -font $xth(gui,lfont)
$f.pb.m add command -label [mc "top"] -command {set xthmvv(cam,profile) 90.0; xth_mv_update}
$f.pb.m add command -label [mc "side"] -command {set xthmvv(cam,profile) 0.0; xth_mv_update}
$f.pb.m add command -label [mc "bottom"] -command {set xthmvv(cam,profile) -90.0; xth_mv_update}
$f.pb.m add separator
$f.pb.m add command -label [mc "reset"] -command {xth_mv_init_camera; xth_mv_update}
xth_status_bar mv $f.pb [mc "Set profile angle."]
xth_status_bar mv $f.pl [mc "Profile angle."]
scale $f.pscale -orient horiz -showvalue 0 -from -90.0 -to 90.0 \
  -resolution 1.0 -variable xthmvv(cam,profile)
  
grid columnconf $f 0 -weight 1
grid columnconf $f 1 -weight 1
grid $f.fb -row 0 -column 0 -sticky news
grid $f.fl -row 0 -column 1 -sticky news
grid $f.fa -row 1 -column 0 -columnspan 2 -sticky news
grid $f.pb -row 2 -column 0 -sticky news
grid $f.pl -row 2 -column 1 -sticky news
grid $f.pscale -row 3 -column 0 -columnspan 2 -sticky news


set f $xth(ctrl,mv,mod)
set xthmvv(modelframe) $f

checkbutton $f.st -text [mc "surface transparency"] -anchor w -font $xth(gui,lfont) \
  -variable xthmvv(model,surftrans) -command xth_mv_reload_file -width 4
xth_status_bar mv $f.st [mc "Turn on/off surface transparency."]

checkbutton $f.hl -text [mc "light follows camera"] -anchor w -font $xth(gui,lfont) \
  -variable xthmvv(model,headlight) -command xth_mv_update -width 4
xth_status_bar mv $f.hl [mc "Fix light source to camera position."]

grid columnconf $f 0 -weight 1
grid columnconf $f 1 -weight 1
grid $f.st -row 0 -column 0 -columnspan 2 -sticky news
grid $f.hl -row 1 -column 0 -columnspan 2 -sticky news

xth_ctrl_maximize mv cam
xth_ctrl_maximize mv mod

xth_status_bar_status mv [mc "Model viewer is not active. To activate it, open some model file."]

# IF, CI SA MV NEKONA
} 









if {[string length $xthmvw] > 0} {

proc xth_mv_configure_camera {w h} {
  global xthmvw xthmvv
  if {[string length $w] > 0} {
    glViewport 0 0 $w $h 
  } else {
    set w [winfo width $xthmvw]
    set h [winfo height $xthmvw]
  }

  set diam $xthmvv(model,diam)
  set dist $xthmvv(cam,dist)

  set prof [expr double($xthmvv(cam,profile)) / 180.0 * 3.14159265359]
  set face [expr double($xthmvv(cam,facing)) / 180.0 * 3.14159265359]

  set hdist [expr cos($prof)]
  set fwdx [expr $hdist * sin($face)]
  set fwdy [expr $hdist * cos($face)]
  set fwdz [expr - sin($prof)]
  
  set cx $xthmvv(cam,cx)
  set cy $xthmvv(cam,cy)
  set cz $xthmvv(cam,cz)

  set fromx [expr $cx - $fwdx * $dist]
  set fromy [expr $cy - $fwdy * $dist]
  set fromz [expr $cz - $fwdz * $dist]
  
#  set hdist [expr cos($prof) * $dist]
#  set fromx [expr $cx - $hdist * sin($face)]
#  set fromy [expr $cy - $hdist * cos($face)]
#  set fromz [expr $cz + sin($prof) * $dist]

  set hdist [expr sin($prof)]
  set upx [expr $hdist * sin($face)]
  set upy [expr $hdist * cos($face)]
  set upz [expr cos($prof)]
  
  set rightx [expr cos($face)]
  set righty [expr - sin($face)]
  set rightz 0.0

  set xthmvv(cam,fwdx) $fwdx
  set xthmvv(cam,fwdy) $fwdy
  set xthmvv(cam,fwdz) $fwdz
  
  set xthmvv(cam,upx) $upx
  set xthmvv(cam,upy) $upy
  set xthmvv(cam,upz) $upz

  set xthmvv(cam,rightx) $rightx
  set xthmvv(cam,righty) $righty
  set xthmvv(cam,rightz) $rightz

  set pnear [expr sqrt($fromx * $fromx + $fromy * $fromy + $fromz * $fromz) - 2.0 * $diam]
  if {$pnear < 1.0} {
    set pnear 1.0
  }
  set pfar [expr $pnear + 4.0 * $diam]

  glMatrixMode $GL::GL_PROJECTION
  glLoadIdentity
  gluPerspective 40.0 [expr double($w) / double($h)] $pnear $pfar

  glMatrixMode $GL::GL_MODELVIEW
  glLoadIdentity
  if {$xthmvv(model,headlight) || $xthmvv(model,lightinpos)} {
    glLightfv $GL::GL_LIGHT0 $GL::GL_POSITION [list 0.0 0.0 1.0 0.0]
    set xthmvv(model,lightinpos) 0
  }
  if {$xthmvv(model,headlight)} {
    set xthmvv(model,lx) $fromx
    set xthmvv(model,ly) $fromy
    set xthmvv(model,lz) $fromz
  }
  gluLookAt $fromx $fromy $fromz $cx $cy $cz $upx $upy $upz
  if {!$xthmvv(model,headlight)} {
    glLightfv $GL::GL_LIGHT0 $GL::GL_POSITION [list $xthmvv(model,lx) $xthmvv(model,ly) $xthmvv(model,lz)  0.0]
  } else {
    glLightfv $GL::GL_LIGHT0 $GL::GL_POSITION [list $fromx $fromy $fromz 0.0]
  }
  
}

proc xth_mv_update {} {
  global xthmvv
  xth_mv_configure_camera {} {}
  xth_mv_draw
  set xthmvv(cam,profile) [expr double($xthmvv(cam,profile))]
  set xthmvv(cam,facing) [expr double($xthmvv(cam,facing))]
}

proc xth_mv_draw {} {
  global xthmvw xthmvv
  # nakreslime si model
  glEnable $GL::GL_BLEND
  glClear [expr $GL::GL_COLOR_BUFFER_BIT | $GL::GL_DEPTH_BUFFER_BIT]
  glCallList $xthmvv(list,bbox)
  glCallList $xthmvv(list,model)
  xth_mv_gl_wireframe
  glFlush
  $xthmvw swap
}

proc xth_mv_gl_wireframe {} {
  glShadeModel $GL::GL_FLAT
  glPolygonMode $GL::GL_FRONT_AND_BACK $GL::GL_LINE
  glDisable $GL::GL_LIGHTING
  glDepthMask $GL::GL_TRUE
  glDisable $GL::GL_BLEND
}

proc xth_mv_gl_walls {} {
  glShadeModel $GL::GL_SMOOTH
  glPolygonMode $GL::GL_FRONT_AND_BACK $GL::GL_FILL
  glEnable $GL::GL_LIGHTING
  glColor4f 1.0 1.0 1.0 1.0
  glDepthMask $GL::GL_TRUE
  glDisable $GL::GL_BLEND
  glLightModeliv $GL::GL_LIGHT_MODEL_TWO_SIDE $GL::GL_FALSE
  glMaterialfv $::GL::GL_FRONT_AND_BACK $::GL::GL_AMBIENT {0.0 0.0 0.0 1.0}
  glMaterialfv $::GL::GL_FRONT_AND_BACK $::GL::GL_DIFFUSE {1.0 1.0 1.0 1.0}
  glMaterialfv $::GL::GL_FRONT_AND_BACK $::GL::GL_SPECULAR {0.0 0.0 0.0 1.0}
  glMaterialfv $::GL::GL_FRONT_AND_BACK $::GL::GL_SHININESS 0.5
}

proc xth_mv_gl_surface {} {
  global xthmvv
  glShadeModel $GL::GL_SMOOTH
  glPolygonMode $GL::GL_FRONT_AND_BACK $GL::GL_FILL
  glEnable $GL::GL_LIGHTING
  if $xthmvv(model,surftrans) {
    glEnable $GL::GL_BLEND
    glDepthMask $GL::GL_FALSE
  } else {
    glDepthMask $GL::GL_TRUE
    glDisable $GL::GL_BLEND
  }
  glLightModeliv $GL::GL_LIGHT_MODEL_TWO_SIDE $GL::GL_TRUE
  glColor4f 0.0 1.0 0.0 1.0
  glMaterialfv $::GL::GL_FRONT $::GL::GL_AMBIENT {0.0 0.0 0.0 1.0}
  glMaterialfv $::GL::GL_FRONT $::GL::GL_DIFFUSE {0.3 1.0 0.1 0.5}
  glMaterialfv $::GL::GL_FRONT $::GL::GL_SPECULAR {0.0 0.0 0.0 1.0}
  glMaterialfv $::GL::GL_FRONT $::GL::GL_SHININESS 0.5
  glMaterialfv $::GL::GL_BACK  $::GL::GL_AMBIENT {0.0 0.0 0.0 1.0}
  glMaterialfv $::GL::GL_BACK  $::GL::GL_DIFFUSE {0.4 0.28 0.055 0.5}
  glMaterialfv $::GL::GL_BACK  $::GL::GL_SPECULAR {0.0 0.0 0.0 1.0}
  glMaterialfv $::GL::GL_BACK  $::GL::GL_SHININESS 0.5
}

proc xth_mv_init {} {

  global xthmvw xthmvv xth
  glClearColor 0.0 0.0 0.0 0.0
  glEnable $GL::GL_DEPTH_TEST
  glEnable $GL::GL_LIGHT0
  glLightfv $GL::GL_LIGHT0 $GL::GL_AMBIENT {0.2 0.2 0.2 1.0}
  glLightfv $GL::GL_LIGHT0 $GL::GL_DIFFUSE {0.8 0.8 0.8 1.0}

  glBlendFunc $GL::GL_SRC_ALPHA $GL::GL_ONE_MINUS_SRC_ALPHA
  #glEnable $GL::GL_BLEND
  
  # vytvorime default model
  set xthmvv(list,model) 1
  set xthmvv(list,bbox) 2
  glDeleteLists $xthmvv(list,model) 1
  glNewList $xthmvv(list,model) $GL::GL_COMPILE
  xth_mv_gl_walls
  set xthmvv(model,maxx) 1.0
  set xthmvv(model,maxy) 1.0
  set xthmvv(model,maxz) 1.0
  set xthmvv(model,minx) -1.0
  set xthmvv(model,miny) -1.0
  set xthmvv(model,minz) -1.0
#  if {[string equal $xth(gui,platform) windows]} {
#    set q [gluNewQuadric]
#    gluSphere $q 1.0 20 16
#    gluDeleteQuadric $q
#  }
  glEndList
}


proc xth_mv_reload_file {} {
  global xth xthmvv
  if {[catch {source $xth(mv,ffull)} opnerr]} {
      MessageDlg $xth(gui,message) -parent $xth(gui,main) \
        -icon error -type ok \
        -message $opnerr\
        -font $xth(gui,lfont)
      return 0
  }
  xth_mv_init_model 0
}


proc xth_mv_open_file {fpath} {

  global xthmvv xth
  xth_status_bar_status mv ""

  if {[string length $fpath] == 0} {
    set fpath [tk_getOpenFile -filetypes $xth(app,mv,filetypes) \
      -parent $xth(gui,main) -initialdir $xth(gui,initdir)]
  }
  
  if {[string length $fpath] == 0} {
    return 0
  } else {
    set xth(gui,initdir) [file dirname $fpath]
  }

  xth_status_bar_push mv
  xth_status_bar_status mv "Opening $fpath ..."
  
  if {[catch {source $fpath} opnerr]} {
      MessageDlg $xth(gui,message) -parent $xth(gui,main) \
        -icon error -type ok \
        -message $opnerr\
        -font $xth(gui,lfont)
      xth_status_bar_pop mv
      return 0
  }

  set xth(mv,fopen) 1
  set xth(mv,fname) [file tail $fpath]
  set xth(mv,fpath) [file dirname $fpath]
  set xth(mv,ffull) $fpath
  
  xth_mv_init_model 1
  xth_app_title mv
  xth_status_bar_pop mv
  
  update idletasks
  return 1

}


proc xth_mv_init_camera {} {
  global xthmvv

  set xthmvv(cam,profile) 20.0
  set xthmvv(cam,facing) 160.0
  set mx $xthmvv(model,maxx)
  set my $xthmvv(model,maxy)
  set mz $xthmvv(model,maxz)
  set nx $xthmvv(model,minx)  
  set ny $xthmvv(model,miny)  
  set nz $xthmvv(model,minz)
  set xthmvv(cam,cx) [expr ($mx + $nx) / 2.0]
  set xthmvv(cam,cy) [expr ($my + $ny) / 2.0]
  set xthmvv(cam,cz) [expr ($mz + $nz) / 2.0]

  set xthmvv(cam,autorotate) 0
  set xthmvv(autorotate,dir) 1
  set xthmvv(autorotate,counter) 0
  if {$xthmvv(model,diam) > 0} {
    set xthmvv(cam,dist) [expr 4.0 * $xthmvv(model,diam)]
  } else {
    set xthmvv(cam,dist) 1.0
  }

}


proc xth_mv_init_model {initcam} {
  global xthmvv
  set mx $xthmvv(model,maxx)
  set my $xthmvv(model,maxy)
  set mz $xthmvv(model,maxz)
  set nx $xthmvv(model,minx)  
  set ny $xthmvv(model,miny)  
  set nz $xthmvv(model,minz)
  set dx [expr ($mx - $nx) / 2.0]
  set dy [expr ($my - $ny) / 2.0]
  set dz [expr ($mz - $nz) / 2.0]
  set diam [expr sqrt($dx * $dx + $dy * $dy + $dz * $dz)]
  set xthmvv(model,diam) $diam
  glDeleteLists $xthmvv(list,bbox) 1
  glNewList $xthmvv(list,bbox) $GL::GL_COMPILE
  xth_mv_gl_wireframe
  glBegin $GL::GL_LINE_STRIP
  glColor4f 1.0 0.0 0.0 1.0
  glVertex3f [expr $mx] [expr $my] [expr $mz]
  glVertex3f [expr $nx] [expr $my] [expr $mz]
  glVertex3f [expr $nx] [expr $ny] [expr $mz]
  glVertex3f [expr $mx] [expr $ny] [expr $mz]
  glVertex3f [expr $mx] [expr $my] [expr $mz]
  glVertex3f [expr $mx] [expr $my] [expr $nz]
  glVertex3f [expr $nx] [expr $my] [expr $nz]
  glVertex3f [expr $nx] [expr $my] [expr $mz]
  glVertex3f [expr $nx] [expr $my] [expr $nz]
  glVertex3f [expr $nx] [expr $ny] [expr $nz]
  glVertex3f [expr $nx] [expr $ny] [expr $mz]
  glVertex3f [expr $nx] [expr $ny] [expr $nz]
  glVertex3f [expr $mx] [expr $ny] [expr $nz]
  glVertex3f [expr $mx] [expr $ny] [expr $mz]
  glVertex3f [expr $mx] [expr $ny] [expr $nz]
  glVertex3f [expr $mx] [expr $my] [expr $nz]
  glVertex3f [expr $mx] [expr $my] [expr $mz]
  glEnd
  glEndList
  if {$initcam} {
    xth_mv_init_camera
  }
  xth_mv_update
}

proc xth_mv_change_profile {v} {
  xth_mv_update
}


proc xth_mv_start_drag {x y} {
  global xthmvv
  set xthmvv(drag,x) $x
  set xthmvv(drag,y) $y
  set xthmvv(drag,facing) $xthmvv(cam,facing)
  set xthmvv(drag,dist) $xthmvv(cam,dist)
}


proc xth_mv_start_shift {x y} {
  global xthmvv
  set xthmvv(shift,x) $x
  set xthmvv(shift,y) $y
  set xthmvv(shift,cx) $xthmvv(cam,cx)
  set xthmvv(shift,cy) $xthmvv(cam,cy)
  set xthmvv(shift,cz) $xthmvv(cam,cz)
}

proc xth_mv_start_walk {x y} {
  global xthmvv
  set xthmvv(walk,x) $x
  set xthmvv(walk,y) $y
  set xthmvv(walk,cx) $xthmvv(cam,cx)
  set xthmvv(walk,cy) $xthmvv(cam,cy)
  set xthmvv(walk,cz) $xthmvv(cam,cz)
}

proc xth_mv_continue_drag {x y} {
  global xthmvv
  set dx [expr $x - $xthmvv(drag,x)]
  set dy [expr $y - $xthmvv(drag,y)]
  if {!$xthmvv(cam,autorotate)} {
    set xthmvv(cam,facing) [expr double(int($dx + $xthmvv(drag,facing)) % 360)]
  }  
  set xthmvv(cam,dist) [expr $xthmvv(drag,dist) * pow(2.0, $dy/100.0)]
  xth_mv_update
}


proc xth_mv_check_center {} {
  global xthmvv
  set cx $xthmvv(cam,cx)
  set cy $xthmvv(cam,cy)
  set cz $xthmvv(cam,cz)
  set mx $xthmvv(model,maxx)
  set my $xthmvv(model,maxy)
  set mz $xthmvv(model,maxz)
  set nx $xthmvv(model,minx)  
  set ny $xthmvv(model,miny)  
  set nz $xthmvv(model,minz)
  if {$cx < $nx} {
    set xthmvv(cam,cx) $nx
  } elseif {$cx > $mx} {
    set xthmvv(cam,cx) $mx
  } 
  if {$cy < $ny} {
    set xthmvv(cam,cy) $ny
  } elseif {$cy > $my} {
    set xthmvv(cam,cy) $my
  } 
  if {$cz < $nz} {
    set xthmvv(cam,cz) $nz
  } elseif {$cz > $mz} {
    set xthmvv(cam,cz) $mz
  } 
}


proc xth_mv_continue_shift {x y} {
  global xthmvv
  set dx [expr double($x - $xthmvv(shift,x)) / 500.0 * $xthmvv(cam,dist)]
  set dy [expr double($y - $xthmvv(shift,y)) / 500.0 * $xthmvv(cam,dist)]
  if {!$xthmvv(cam,autorotate)} {
    set xthmvv(cam,cx) [expr $xthmvv(shift,cx) - $dx * $xthmvv(cam,rightx) + $dy * $xthmvv(cam,upx)]
    set xthmvv(cam,cy) [expr $xthmvv(shift,cy) - $dx * $xthmvv(cam,righty) + $dy * $xthmvv(cam,upy)]
    set xthmvv(cam,cz) [expr $xthmvv(shift,cz) - $dx * $xthmvv(cam,rightz) + $dy * $xthmvv(cam,upz)]
    xth_mv_check_center    
    xth_mv_update
  }  
}

proc xth_mv_continue_walk {x y} {
  global xthmvv
  set dy [expr double($y - $xthmvv(walk,y)) / 200.0 * $xthmvv(cam,dist)]
  if {!$xthmvv(cam,autorotate)} {
    set xthmvv(cam,cx) [expr $xthmvv(walk,cx) - $dy * $xthmvv(cam,fwdx)]
    set xthmvv(cam,cy) [expr $xthmvv(walk,cy) - $dy * $xthmvv(cam,fwdy)]
    set xthmvv(cam,cz) [expr $xthmvv(walk,cz) - $dy * $xthmvv(cam,fwdz)]
    xth_mv_check_center    
    xth_mv_update
  }  
}

proc xth_mv_camera_autorotate {} {
  global xthmvv
  if {$xthmvv(cam,autorotate)} {
    set xthmvv(cam,facing) [expr double(int($xthmvv(cam,facing) + $xthmvv(autorotate,dir)) % 360)]
    xth_mv_update
    if {$xthmvv(autorotate,counter) == 0} {
      set xthmvv(autorotate,watch) [clock clicks -milliseconds]
    }
    incr xthmvv(autorotate,counter)
    if {$xthmvv(autorotate,counter) == 50} {
      catch {
        $xthmvv(ctrlframe).fa configure -text "auto rotate ([format %.1f [expr 50000.0 / double([clock clicks -milliseconds] - $xthmvv(autorotate,watch))]] fps)"                 
      }
      set xthmvv(autorotate,counter) 0
      after 10 xth_mv_camera_autorotate
    } else {
      after idle xth_mv_camera_autorotate
    }
  } else {
    $xthmvv(ctrlframe).fa configure -text "auto rotate" 
    set xthmvv(autorotate,fps) {}
    set xthmvv(autorotate,counter) 0
    set xthmvv(cam,autorotate) 0
  }
}

bind $xthmvw <Configure> {
  xth_mv_configure_camera %w %h
  xth_mv_draw
}
bind $xthmvw <Expose> xth_mv_draw
bind $xthmvw <1> {xth_mv_start_drag %x %y}
bind $xthmvw <B1-Motion> {xth_mv_continue_drag %x %y}
bind $xthmvw <B1-ButtonRelease> {xth_mv_continue_drag %x %y}

bind $xthmvw <3> {xth_mv_start_shift %x %y}
bind $xthmvw <B3-Motion> {xth_mv_continue_shift %x %y}
bind $xthmvw <B3-ButtonRelease> {xth_mv_continue_shift %x %y}

bind $xthmvw <2> {xth_mv_start_walk %x %y}
bind $xthmvw <B2-Motion> {xth_mv_continue_walk %x %y}
bind $xthmvw <B2-ButtonRelease> {xth_mv_continue_walk %x %y}

case $xth(gui,platform) {
  unix {
    bind $xthmvw <4> {
      set xthmvv(cam,profile) [expr $xthmvv(cam,profile) - 10.0]
      xth_mv_update
    }
    bind $xthmvw <5> {
      set xthmvv(cam,profile) [expr $xthmvv(cam,profile) + 10.0]
      xth_mv_update
    }
  }
  windows {
    bind $xth(gui,main) <MouseWheel> {
      switch $xth(app,active) {
        mv {
          set xthmvv(cam,profile) [expr $xthmvv(cam,profile) - double(%D)/12.0]
          xth_mv_update
        }
      }
    }
  }
}

$xth(ctrl,mv,cam).pscale configure -command xth_mv_change_profile

xth_mv_init
xth_mv_init_model 1

# IF, CI SA MV KONA
} 






# - dzach add toolbar
set xth(tb,me,action) 0
set xth(gui,tb) $xth(gui,main).tb

if {[string length $xthmvw] > 0} {
  set allapps {te me cp mv}
} else {
  set allapps {te me cp}
}
option add *tb*relief flat
option add *tb*overRelief groove
option add *tb*padx 0
option add *tb*indicatorOn off
option add *tb*offRelief flat
option add *tb*Button.width 20
option add *tb*Button.height 20
option add *tb*Radiobutton.width 18
option add *tb*Radiobutton.height 18

option add *edif*relief flat
option add *edif*overRelief groove
option add *edif*padx 0
option add *edif*indicatorOn off
option add *edif*offRelief flat
option add *edif*Button.width 20
option add *edif*Button.height 20
option add *edif*Radiobutton.width 18
option add *edif*Radiobutton.height 18

option add *movf*relief flat
option add *movf*overRelief groove
option add *movf*padx 0
option add *movf*indicatorOn off
option add *movf*offRelief flat
option add *movf*Button.width 20
option add *movf*Button.height 20

frame $xth(gui,tb) -relief raised -bd 1 -padx 5
pack $xth(gui,tb) -side top -anchor nw -fill x
frame $xth(gui,tb).filf

button $xth(gui,tb).newb -image {new_img} \
		-command {
			switch -- $xth(app,active) {
				te {
					xth_te_new_file
				}
				me {
					xth_me_create_file
				}
				cp {
					xth_cp_new_file
				}
			}
		}
xth_status_bar {te me cp} $xth(gui,tb).newb [mc "New file"]



button $xth(gui,tb).openb -image {open_img} \
		-command {
			switch -- $xth(app,active) {
				te {
					xth_te_open_file 1 {} 1
				}
				me {
					xth_me_open_file 1 {} 1
				}
				cp {
					xth_cp_open_file {}
				}
        mv {
          xth_mv_open_file {}
        }
			}
		}
xth_status_bar $allapps $xth(gui,tb).openb [mc "Open file"]

button $xth(gui,tb).saveb -image {save_img} \
		-command {
			switch -- $xth(app,active) {
				te {
					if {$xth(te,fcurr) >= 0} {
					  xth_te_save_file 0 [lindex $xth(te,flist) $xth(te,fcurr)]
					}
				}
				me {
					xth_me_save_file 0
				}
			}
		}
xth_status_bar {te me cp} $xth(gui,tb).saveb [mc "Save file"]
    
button $xth(gui,tb).savasb -image {saveas_img} \
		-command {
			switch -- $xth(app,active) {
				te {
					if {$xth(te,fcurr) >= 0} {
					  xth_te_save_file 1 [lindex $xth(te,flist) $xth(te,fcurr)]
					}
				}
				me {
					xth_me_save_file 1
				}
				cp {
					xth_cp_save_as
				}
			}
		}
xth_status_bar {te me cp} $xth(gui,tb).savasb [mc "Save file as"]

button $xth(gui,tb).closeb -image {close_img} \
 	-command {
			switch -- $xth(app,active) {
				te {
					xth_te_close_file
				}
				me {
					xth_me_close_file
				}
				cp {
					xth_cp_close_file
				}
			}
		}
xth_status_bar {te me cp} $xth(gui,tb).closeb [mc "Close file"]

label $xth(gui,tb).sp01 -relief groove -width 0 -padx 0 -pady 0 -bd 1

frame $xth(gui,tb).winf
button $xth(gui,tb).edb -image {edit_img} \
		-command {
			xth_app_show te
		}
xth_status_bar $allapps $xth(gui,tb).edb [mc "Switch to text editor"]

button $xth(gui,tb).e2db -image {2d_img} \
		-command {
			xth_app_show me
		}
xth_status_bar $allapps $xth(gui,tb).e2db [mc "Switch to map editor"]

button $xth(gui,tb).cpb -image {compile_img} \
		-command {
			xth_app_show cp
		}
xth_status_bar $allapps $xth(gui,tb).cpb [mc "Switch to compiler"]
    
button $xth(gui,tb).v3db -image {3d_img} \
		-command {
			xth_app_show mv
		}
if {[string length $xthmvw] == 0} {
  $xth(gui,tb).v3db configure -state disabled
}
    
    
xth_status_bar $allapps $xth(gui,tb).v3db [mc "Switch to 3D viewer"]

label $xth(gui,tb).sp02 -relief groove -width 0 -padx 0 -pady 0 -bd 1

frame $xth(gui,tb).makf
button $xth(gui,tb).makeb -text "Make" -image {make_img} \
	-command {
		xth_app_make
	}
xth_status_bar $allapps $xth(gui,tb).makeb [mc "Compile"]

label $xth(gui,tb).sp03 -relief groove -width 0 -padx 0 -pady 0 -bd 1

frame $xth(gui,tb).self
radiobutton $xth(gui,tb).selb -text "Select" -image {select_img} \
		-variable xth(tb,me,action) -value 0 \
		-command {
			xth_me_cmds_set_mode 0
		} -state disabled
xth_status_bar me $xth(gui,tb).selb [mc "Switch to select mode"]

button $xth(gui,tb).selscrb -text "Select scrap" -image {selscr_img} \
		-command {
			xth_me_cmds_set_mode 0
      xth_me_ss_next_cmd 4
		} -state disabled
xth_status_bar me $xth(gui,tb).selscrb [mc "Select next scrap"]

button $xth(gui,tb).selarrb -image {selare_img} \
		-command {
			xth_me_cmds_set_mode 0
      xth_me_ss_next_cmd 6
		} -state disabled
xth_status_bar me $xth(gui,tb).selarrb [mc "Select next area"]
    

label $xth(gui,tb).sp1 -relief groove -width 0 -padx 0 -pady 0 -bd 1
  
frame $xth(gui,tb).edif

button $xth(gui,tb).edif.zoo+b -image {zoom+_img} \
		-command {
			if {$::xth(me,zoom)*2 > 400} return
			xth_me_area_zoom_to [expr {$::xth(me,zoom) * 2}]
		} -state disabled
  xth_status_bar me $xth(gui,tb).edif.zoo+b [mc "Zoom in"]
button $xth(gui,tb).edif.zoo-b -image {zoom-_img} \
		-command {
			if {$::xth(me,zoom)/2 < 25} return
			xth_me_area_zoom_to [expr {$::xth(me,zoom) / 2}]
		} -state disabled
xth_status_bar me $xth(gui,tb).edif.zoo-b [mc "Zoom out"]
label $xth(gui,tb).edif.spZoom -relief groove -width 0 -padx 0 -pady 0 -bd 1

button $xth(gui,tb).edif.scb -image {scrap_img} \
  -command {
    xth_me_cmds_create_scrap {} 1 "" ""
    xth_ctrl_scroll_to me scrap
    xth_ctrl_maximize me scrap
  } -state disabled
xth_status_bar me $xth(gui,tb).edif.scb [mc "Insert new scrap"]

radiobutton $xth(gui,tb).edif.ptrb \
		-image {point_img} -indicatoron off \
		-variable xth(tb,me,action) -value 1 \
		-command {xth_me_cmds_set_mode 1} -state disabled
xth_status_bar me $xth(gui,tb).edif.ptrb [mc "Insert new point"]

radiobutton $xth(gui,tb).edif.lnrb \
		-image {line_img} -indicatoron off \
		-variable xth(tb,me,action) -value 2 \
		-command {
      xth_me_cmds_create_line {} 1 "" "" ""
      xth_ctrl_scroll_to me line
      xth_ctrl_maximize me line
      xth_ctrl_maximize me linept
    } -state disabled

xth_status_bar me $xth(gui,tb).edif.lnrb [mc "Insert new line"]

radiobutton $xth(gui,tb).edif.arrb \
		-image {area_img} -indicatoron off \
		-variable xth(tb,me,action) -value 3 \
		-command {
      xth_me_cmds_create_area {} 1 "" "" ""
      xth_ctrl_scroll_to me ac
      xth_ctrl_maximize me ac
    } -state disabled
xth_status_bar me $xth(gui,tb).edif.arrb [mc "Insert new area"]

button $xth(gui,tb).edif.txrb \
		-image {text_img} \
    -command {
      xth_me_cmds_create_text {} 1 "\n" "1.0"
      xth_ctrl_scroll_to me text
      xth_ctrl_maximize me text
      focus $xth(ctrl,me,text).txt
    } -state disabled

label $xth(gui,tb).sp2 -relief groove -width 0 -padx 0 -pady 0 -bd 1
frame $xth(gui,tb).movf
	button $xth(gui,tb).movf.topb -text "top" -image {top_img} \
		-command {xth_me_cmds_move_up {}}
	button $xth(gui,tb).movf.upb -text "Up" -image {up_img} \
		-command {xth_me_cmds_move_up {}}
	button $xth(gui,tb).movf.dob -text "Down" -image {down_img} \
		-command {xth_me_cmds_move_down {}}
	button $xth(gui,tb).movf.botb -text "Bottom" -image {bottom_img} \
		-command {xth_me_cmds_move_down {}}
	button $xth(gui,tb).movf.tob -text "To" -image {to_img} \
		-command {xth_me_cmds_move_to {} {}}

button $xth(gui,tb).deb -image {delete_img} \
	-command {xth_me_cmds_delete {}} -state disabled
xth_status_bar me $xth(gui,tb).deb [mc "Delete selected object"]

	label $xth(gui,tb).sp3 -relief groove -width 0 -padx 0 -pady 0 -bd 1
# - file icons
pack $xth(gui,tb).filf -side left
pack $xth(gui,tb).newb $xth(gui,tb).openb $xth(gui,tb).saveb $xth(gui,tb).savasb \
	 $xth(gui,tb).closeb \
	-side left -anchor center -in $xth(gui,tb).filf
pack $xth(gui,tb).sp01 -padx 7 -pady 5 -fill y -side left -anchor center -in $xth(gui,tb).filf
# - window icons
pack $xth(gui,tb).winf -side left
pack $xth(gui,tb).edb $xth(gui,tb).e2db $xth(gui,tb).cpb $xth(gui,tb).v3db \
	-side left -anchor center -in $xth(gui,tb).winf
pack $xth(gui,tb).sp02 -padx 7 -pady 5 -fill y -side left -anchor center -in $xth(gui,tb).winf

# - make icons
pack $xth(gui,tb).makf -side left
pack $xth(gui,tb).makeb \
	-side left -anchor center -in $xth(gui,tb).makf
pack $xth(gui,tb).sp03 -padx 7 -pady 5 -fill y -side left -anchor center -in $xth(gui,tb).makf

# - move icons
# pack $xth(gui,tb).movf -side right -anchor nw
pack $xth(gui,tb).movf.topb $xth(gui,tb).movf.botb $xth(gui,tb).movf.tob \
	$xth(gui,tb).movf.upb $xth(gui,tb).movf.dob \
	-side left -anchor center

# - select icons
pack $xth(gui,tb).self -side right -anchor nw
pack $xth(gui,tb).selb \
	-side left -anchor center -in $xth(gui,tb).self
pack $xth(gui,tb).selscrb $xth(gui,tb).selarrb \
	-side left -anchor center -in $xth(gui,tb).self
pack $xth(gui,tb).deb \
	-side left -anchor center -in $xth(gui,tb).self
#pack $xth(gui,tb).sp1 -padx 7 -pady 5 -fill y -side left -anchor center -in $xth(gui,tb).self

# - edit icons
pack $xth(gui,tb).edif -side right 
pack $xth(gui,tb).edif.zoo+b $xth(gui,tb).edif.zoo-b -side left -anchor center
pack $xth(gui,tb).edif.spZoom -padx 7 -pady 5 -fill y -side left -anchor center
pack $xth(gui,tb).edif.scb $xth(gui,tb).edif.ptrb $xth(gui,tb).edif.lnrb $xth(gui,tb).edif.arrb \
	-side left -anchor center
pack $xth(gui,tb).sp2 -padx 7 -pady 5 -fill y -side left -anchor center -in $xth(gui,tb).edif


proc xth_tools_me_enable {} {
  global xth
  set tools [list \
    $xth(gui,tb).deb $xth(gui,tb).selb $xth(gui,tb).selscrb $xth(gui,tb).selarrb \
    $xth(gui,tb).edif.zoo+b $xth(gui,tb).edif.zoo-b \
    $xth(gui,tb).edif.scb $xth(gui,tb).edif.ptrb $xth(gui,tb).edif.lnrb $xth(gui,tb).edif.arrb \
  ]
  if {$xth(me,fopen)} {
     foreach tl $tools {
       $tl configure -state normal
     }
  } else {
     foreach tl $tools {
       $tl configure -state disabled
     }
  }
}

proc xth_tools_toggle {} {
  global xth
  set xth(gui,toolbar) [expr !$xth(gui,toolbar)]
  if $xth(gui,toolbar) {
    catch {
      pack $xth(gui,tb) -side top -anchor nw -fill x -before $xth(gui,main).$xth(app,active)
    }
  } else {
    catch {
      pack forget $xth(gui,tb)
    }
  }
}






xth_app_finish
xth_app_clock

encoding system $xth(app,sencoding)
set xth(encoding_system) [encoding system]
if {[string length $xth(about,nvr)] > 0} {
  xth_about_status $xth(prj,title)
  after $xth(about,infotime) xth_about_hide
} else {
  xth_about_hide
}

wm deiconify $xth(gui,main)
xth_app_normalize

foreach xapp $xth(app,list) {
  catch {
    set xth(app,$xapp,relw) $xth(app,$xapp,tbwidth)
    xth_app_show $xapp
  }
}

if {[llength $xth(app,list)] > 2} {
  xth_app_show [lindex $xth(app,list) 2]
} else {
  xth_app_show [lindex $xth(app,list) 0]
}


set th2open 1
set cfgopen 1

foreach fname $argv {
  if {$cfgopen && [regexp -nocase {thconfig|thcfg} $fname]} {
    set cfgopen 0
    xth_app_show cp
    update idletasks
    xth_cp_open_file $fname
  } elseif {$th2open && [regexp -nocase {\.th2$} $fname]} {
    set th2open 0
    xth_app_show me
    update idletasks
    xth_me_open_file 0 $fname 1
  } elseif {[regexp -nocase {\.thm$} $fname]} {
    if {[string length $xthmvw] > 0} {
      xth_app_show mv
      update idletasks
      xth_mv_open_file $fname
    }
  } else {
    xth_app_show te
    update idletasks
    xth_te_open_file 0 $fname 1
  }
}

foreach idir $xth(idirs) {
  catch {source [file join $idir xtherion.ini]}
}
catch {source xtherion.ini}






