1
##########################################################################
5
# Primary tcltk script for GIS Manager: GUI for GRASS 6
6
# Author: Michael Barton (Arizona State University)
7
# Based in part on Display Manager for GRASS 5.7 by Radim Blazek (ITC-IRST)
8
# and tcltkgrass for GRASS 5.7 by Michael Barton (Arizona State University)--
9
# with contributions by Glynn Clements, Markus Neteler, Lorenzo Moretti,
10
# Florian Goessmann, and others
14
# COPYRIGHT: (C) 1999 - 2006 by the GRASS Development Team
16
# This program is free software under the GNU General Public
17
# License (>=v2). Read the file COPYING that comes with GRASS
20
##########################################################################
22
lappend auto_path [file join "$env(GISBASE)" "bwidget"]
24
package require -exact BWidget 1.2.1
26
# Load up all the gis.m layers and things.
27
# pkgIndex.tcl only loads the files when they are first called.
28
lappend auto_path [file join "$env(GISBASE)" "etc" "gm"]
29
package require -exact GisM 1.0
31
# path to GIS Manager files
32
set gmpath [file join "$env(GISBASE)" "etc" "gm"]
34
# Load GUI stuff required for error reporting etc.
35
source [file join "$env(GISBASE)" "etc" "gui.tcl"]
37
# Load common procedure library
38
source [file join "$gmpath" "gmlib.tcl"]
40
# gisenv errors are fatal.
41
if {[catch {set env(GISDBASE) [exec g.gisenv get=GISDBASE]} error]} {
46
if {[catch {set env(LOCATION_NAME) [exec g.gisenv get=LOCATION_NAME]} error]} {
51
if {[catch {set env(MAPSET) [exec g.gisenv get=MAPSET]} error]} {
57
if {[catch {set gisdbase [exec g.gisenv get=GISDBASE]} error]} {
62
if {[catch {set location_name [exec g.gisenv get=LOCATION_NAME]} error]} {
67
if {[catch {set mapset [exec g.gisenv get=MAPSET]} error]} {
73
# if any of those is empty, there's no reason to continue. it's a failure.
74
if { $gisdbase=={} || $location_name=={} || $mapset=={} } {
75
GmLib::errmsg [G_msg "GISDBASE or LOCATION_NAME or MAPSET is empty. \
76
This is a fatal error. gis.m can not work without proper settings."]
80
# path to icons for GIS Manager
81
set iconpath [file join "$env(GISBASE)" "etc" "gui" "icons" "grass"]
86
set keycontrol "Control"
95
if {![catch {set env(HOSTTYPE)}]} {
96
set HOSTTYPE $env(HOSTTYPE)
102
if {![catch {set env(osxaqua)}]} {
103
set osxaqua $env(osxaqua)
108
if { $osxaqua == "1"} {
109
set keycontrol "Command"
111
set keyctrl "Command"
115
if {![catch {set env(OS)}] && $env(OS) == "Windows_NT"} {
120
set devnull "/dev/null"
124
#fetch GRASS Version number:
125
catch {set fp [open [file join "$env(GISBASE)" "etc" "VERSIONNUMBER"] r]}
126
set GRASSVERSION [read -nonewline $fp]
128
if {[catch {close $fp} error]} {
133
#source $env(GISBASE)/etc/gui.tcl
134
# gui.tcl also sources these:
135
# $env(GISBASE)/etc/gtcltk/gmsg.tcl
136
# $env(GISBASE)/etc/gtcltk/options.tcl
137
# $env(GISBASE)/etc/gtcltk/select.tcl
138
# $env(GISBASE)/etc/gtcltk/gronsole.tcl
140
# Load a console user interface
141
source [file join "$gmpath" "runandoutput.tcl"]
144
variable gm_mainframe
146
variable array tree ;# mon
152
variable selectedfont
154
global array filename ;# mon
155
variable last_directory ;# last save/load dir for reuse
165
if { $tcl_platform(platform) == "windows" } {
166
append regexp .* $env(GISBASE) {[^;]*}
167
regsub -- $regexp $env(PATH) "&;$env(GISBASE)/etc/gui/scripts" env(PATH)
169
append regexp .* $env(GISBASE) {[^:]*}
170
regsub -- $regexp $env(PATH) "&:$env(GISBASE)/etc/gui/scripts" env(PATH)
173
###############################################################################
175
# Use guarantee_xmon and any run command instead.
177
proc Gm::xmon { type cmd } {
180
if { $type == "term" } {
189
###############################################################################
192
proc Gm::create { } {
195
variable gm_mainframe
209
# set display rendering environment for PNG/PPM output
210
set env(GRASS_RENDER_IMMEDIATE) "TRUE"
213
if {[catch {set env(GRASS_FONT)}]} {set env(GRASS_FONT) "romans"}
215
set Gm::encoding "ISO-8859-1"
219
set Gm::prgtext [G_msg "Loading GIS Manager"]
224
source $gmpath/gmmenu.tcl
226
set Gm::prgtext [G_msg "Creating MainFrame..."]
228
set gm_mainframe [MainFrame .mainframe \
230
-textvariable Gm::status \
231
-progressvar Gm::prgindic ]
233
set mainwindow [$gm_mainframe getframe]
235
# toolbar 1 & 2 creation
236
set tb1 [$gm_mainframe addtoolbar]
237
GmToolBar1::create $tb1
238
set tb2 [$gm_mainframe addtoolbar]
239
GmToolBar2::create $tb2
240
set pw1 [PanedWindow $mainwindow.pw1 -side left -pad 0 -width 10 ]
243
set treemon [expr {$mon + 1}]
244
set tree_pane [$pw1 add -minsize 50 -weight 1]
245
set pgs [PagesManager $tree_pane.pgs]
248
pack $pgs -expand yes -fill both
252
set options_pane [$pw1 add -minsize 50 -weight 1]
253
set options_sw [ScrolledWindow $options_pane.sw -relief flat -borderwidth 1]
254
set options_sf [ScrollableFrame $options_sw.sf]
255
$options_sf configure -height 145 -width 460
256
$options_sw setwidget $options_sf
257
set options [$options_sf getframe]
258
pack $options_sw -fill both -expand yes
260
# Scroll the options window with the mouse
261
bind_scroll $options_sf
263
pack $pw1 -side top -expand yes -fill both -anchor n
266
set Gm::prgtext [G_msg "Done"]
268
set Gm::status [G_msg "Welcome to GRASS GIS"]
269
$gm_mainframe showstatusbar status
271
pack $gm_mainframe -fill both -expand yes
275
bind .mainframe <Destroy> {
276
if {"%W" == ".mainframe"} {
280
if { [info exists env(HOME)] } {
281
set Gm::last_directory $env(HOME)
283
set Gm::last_directory [pwd]
289
###############################################################################
291
# start new display monitor and increment canvas monitor number
292
proc Gm::startmon { } {
301
#create initial display canvas and layer tree
305
wm title .mapcan($mon) [format [G_msg "Map Display %d"] $mon]
306
wm withdraw .mapcan($mon)
307
wm deiconify .mapcan($mon)
311
###############################################################################
313
proc Gm::_create_intro { } {
321
set top [toplevel .intro -relief raised -borderwidth 2]
324
wm overrideredirect $top 1
326
set ximg [label $top.x -image [image create photo -file "$gmpath/intro.gif"] ]
328
set frame [frame $ximg.f -background white]
329
set lab1 [label $frame.lab1 \
330
-text [format [G_msg "GRASS%s GIS Manager - %s"] $GRASSVERSION $location_name] \
331
-background white -foreground black -font introfont]
332
set lab2 [label $frame.lab2 -textvariable Gm::prgtext -background white]
333
set prg [ProgressBar $frame.prg -width 50 -height 15 -background white \
334
-variable Gm::prgindic -maximum $max_prgindic]
335
pack $lab1 $prg -side left -fill both -expand yes
336
pack $lab2 -side right -expand yes
337
place $frame -x 0 -y 0 -anchor nw
339
BWidget::place $top 0 0 center
343
###############################################################################
351
if { $HOSTTYPE == "macintosh" || $HOSTTYPE == "powermac" || $HOSTTYPE == "powerpc" || $HOSTTYPE == "intel-pc"} {
352
if { $osxaqua == "1"} {
363
###############################################################################
365
# d.nviz: set up NVIZ flight path (not much use without a backdrop?)
369
exec d.nviz -i --ui &
373
###############################################################################
376
proc Gm::xganim { } {
382
###############################################################################
387
set cmd [list g.manual --ui]
392
###############################################################################
393
# sets default display font
394
proc Gm::defaultfont { source } {
398
variable selectedfont
401
# create a dialog with selector for stroke font and true type font, and
402
# text entry for character encoding
405
wm title .dispfont [G_msg "Select GRASS display font"]
407
if {[catch {set rawlist [exec d.font --q -L]} error]} {
408
GmLib::errmsg $error "d.font error"
410
set rawlist [split $rawlist "\n"]
411
foreach item $rawlist {
412
set fontinfo [split $item "|"]
413
lappend fontlist $fontinfo
415
# Case-insensitive search on font long name, removing duplicates
416
set fontlist [lsort -dictionary -unique -index 1 $fontlist]
418
set row [ frame .dispfont.fontlb ]
419
Label $row.a -text [G_msg "Font: "]
420
set fontlb [ listbox $row.b -bg white -width 30 \
421
-yscrollcommand "$row.vscrollbar set"]
423
scrollbar $row.vscrollbar -width 12 \
424
-command "$row.b yview" \
427
foreach item $fontlist {
428
$fontlb insert end [lindex $item 1]
430
# If $Gm::dfont is empty then it hasn't been set by a layer module
431
# before calling this procedure, so we should read the current
432
# default font from the GRASS_FONT environment variable
433
if {$Gm::dfont == ""} {
434
if {![catch {set env(GRASS_FONT)}] && $env(GRASS_FONT) != ""} {
435
set Gm::dfont $env(GRASS_FONT)
438
set selectedfont $Gm::dfont
440
if {$Gm::dfont != ""} {
442
foreach item $fontlist {
443
if { $Gm::dfont eq [lindex $item 0] } {
444
$fontlb selection set $fontindex
445
$fontlb see $fontindex
452
pack $row.vscrollbar -side right -fill y
453
pack $row.b -side right
454
pack $row.a -side right -anchor n
455
pack $row -side top -fill both -expand yes -pady 3 -padx 5
457
set row [ frame .dispfont.fontopt3 ]
458
Label $row.a -text [G_msg "Character encoding: "]
459
Entry $row.b -width 20 -text "$Gm::encoding" \
460
-textvariable Gm::encoding
461
pack $row.b $row.a -side right -anchor e
462
pack $row -side top -fill both -expand yes -pady 3 -padx 5
464
set row [ frame .dispfont.buttons ]
465
Button $row.ok -text [G_msg "OK"] -width 8 -bd 1 \
466
-command "Gm::setfont $source; destroy .dispfont"
467
pack $row.ok -side left -fill x -expand 0
468
button $row.cancel -text [G_msg "Cancel"] -width 8 -bd 1 \
469
-command "destroy .dispfont"
470
pack $row.cancel -side right -fill x -expand 0
471
pack $row -side bottom -pady 3 -padx 5 -expand 0 -fill x
473
bind $fontlb <<ListboxSelect>> {
474
set Gm::selectedfont [lindex [lindex $fontlist [%W curselection]] 0]
480
proc Gm::setfont { source } {
483
variable selectedfont
486
# Set GRASS environmental variables for default display font and
489
if { $encoding != "" && $encoding != "ISO-8859-1"} {
490
set env(GRASS_ENCODING) $encoding
493
set dfont $selectedfont
495
if { $source == "menu" && $dfont != "" } {
496
set env(GRASS_FONT) $dfont
502
###############################################################################
504
proc Gm::cleanup { } {
510
set mappid $MapCanvas::mappid
512
# delete all map display ppm files
514
set deletefile $mappid
515
append deletefile ".*"
516
foreach file [glob -nocomplain $deletefile] {
517
catch {file delete $file}
520
if {[info exists legfile] && [file exists $legfile]} {catch {file delete -force $legfile}}
526
# Provides remote exit call. Used by GRASS exit to close all session's gis.m instances.
527
# Argument session_id is exit caller's GIS_LOCK variable.
528
proc Gm::remoteExit { session_id } {
530
if {$env(GIS_LOCK) == $session_id} Gm::quit
533
# Provides exit from gis.m. May also do some clean-up, save-settings et.al.
534
proc Gm::quit { {full_exit false} } {
538
if { [catch {set spid $env(GRASS_SHELL_PID)}] == 0 } {
539
set leave [tk_dialog .leave [G_msg "End current GRASS session"] \
540
[G_msg "Do you really want to terminate current\
541
GRASS session?\n\nThis action will close all sessions gis.m instances.\n\nIf You have running some \
542
GRASS module from comandline, GRASS will terminate after it\
543
finishes to run."] warning 1 [G_msg "Terminate current GRASS session"] [G_msg "Cancel"]]
545
exec kill -SIGQUIT $env(GRASS_SHELL_PID)
550
tk_messageBox -type ok -title [G_msg "Not supported"] -message \
551
[G_msg "We sorry. Your shell does not support this feature. \n\
552
You have to type 'exit' in terminal manually."]
556
# It's unsafe to call exit during Destroy event
557
after idle [list destroy .]
560
###############################################################################
562
proc main {argc argv} {
563
variable gm_mainframe
573
wm title . [format [G_msg "GRASS%s GIS Manager - %s %s"] $GRASSVERSION $location_name $mapset]
575
bind . <$keycontrol-Key-o> {
578
bind . <$keycontrol-Key-n> {
581
bind . <$keycontrol-Key-s> {
584
bind . <$keycontrol-Key-q> {
587
bind . <$keycontrol-Key-w> {
592
BWidget::place . 0 0 at 400 100
601
if { [regexp -- {\.grc$} $i] || [regexp -- {\.dmrc$} $i] || [regexp -- {\.dm$} $i] } {
602
set filename($mon) [lindex $argv 0]
603
GmTree::load $filename($mon)
609
wm protocol . WM_DELETE_WINDOW {
614
wm geom . [wm geom .]