~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to gui/tcltk/d.m/d.m.tcl

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
##########################################################################
2
 
#
3
 
# d.m.tcl
4
 
#
5
 
# Primary tcltk script for GIS Manager: GUI for GRASS 6 
6
 
# Author: Michael Barton (Arizona State University)
7
 
# Based 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
11
 
#
12
 
# 12 November 2005
13
 
#
14
 
# COPYRIGHT:    (C) 1999 - 2005 by the GRASS Development Team
15
 
#
16
 
#               This program is free software under the GNU General Public
17
 
#               License (>=v2). Read the file COPYING that comes with GRASS
18
 
#               for details.
19
 
#
20
 
##########################################################################
21
 
 
22
 
lappend auto_path $env(GISBASE)/bwidget
23
 
package require -exact BWidget 1.2.1
24
 
 
25
 
set env(GISDBASE) [exec g.gisenv get=GISDBASE]
26
 
set env(LOCATION_NAME) [exec g.gisenv get=LOCATION_NAME]
27
 
set env(MAPSET) [exec g.gisenv get=MAPSET]
28
 
 
29
 
set gisdbase [exec g.gisenv get=GISDBASE]
30
 
set location_name [exec g.gisenv get=LOCATION_NAME]
31
 
set mapset [exec g.gisenv get=MAPSET]
32
 
 
33
 
 
34
 
set dmpath $env(GISBASE)/etc/dm/
35
 
 
36
 
set keycontrol "Control"
37
 
set tmenu "1"
38
 
set keyctrl "Ctrl"
39
 
set execom "execute"
40
 
set msg 0
41
 
set mon ""
42
 
if {[info exists env(HOSTTYPE)]} {
43
 
        set HOSTTYPE $env(HOSTTYPE)
44
 
} else {
45
 
        set HOSTTYPE ""
46
 
}
47
 
 
48
 
set bgcolor HoneyDew2
49
 
 
50
 
# add for OSX aqua
51
 
if {[info exists env(osxaqua)]} {
52
 
    set osxaqua $env(osxaqua)
53
 
} else {
54
 
    set osxaqua "0"
55
 
}
56
 
 
57
 
if { $osxaqua == "1"} {
58
 
    set keycontrol "Command"
59
 
    set tmenu "0"
60
 
    set keyctrl "Command"
61
 
    set execom "spawn"
62
 
}
63
 
 
64
 
#fetch GRASS Version number:
65
 
set fp [open $env(GISBASE)/etc/VERSIONNUMBER r]
66
 
set GRASSVERSION [read -nonewline $fp]
67
 
close $fp
68
 
 
69
 
source $env(GISBASE)/etc/gui.tcl
70
 
# gui.tcl also sources these:
71
 
# $env(GISBASE)/etc/gtcltk/gmsg.tcl
72
 
# $env(GISBASE)/etc/gtcltk/options.tcl
73
 
# $env(GISBASE)/etc/gtcltk/select.tcl
74
 
# $env(GISBASE)/etc/gtcltk/gronsole.tc
75
 
 
76
 
source $dmpath/cmd.tcl
77
 
source $dmpath/tree.tcl
78
 
source $dmpath/tool1.tcl
79
 
source $dmpath/tool2.tcl
80
 
source $dmpath/group.tcl
81
 
source $dmpath/vector.tcl
82
 
source $dmpath/raster.tcl
83
 
source $dmpath/labels.tcl
84
 
source $dmpath/gridline.tcl
85
 
source $dmpath/rgbhis.tcl
86
 
source $dmpath/legend.tcl
87
 
source $dmpath/frames.tcl
88
 
source $dmpath/barscale.tcl
89
 
source $dmpath/chart.tcl
90
 
source $dmpath/thematic.tcl
91
 
source $dmpath/fttext.tcl
92
 
source $dmpath/dtext.tcl
93
 
source $dmpath/print.tcl
94
 
 
95
 
namespace eval Dm {
96
 
    variable mainframe
97
 
    variable options
98
 
    variable status
99
 
    variable prgtext
100
 
    variable prgindic
101
 
    variable max_prgindic 20
102
 
    variable tree
103
 
    variable rcfile
104
 
}
105
 
 
106
 
 
107
 
 
108
 
 
109
 
################################################################################
110
 
 
111
 
proc execute {cmd} {
112
 
    global dlg path
113
 
 
114
 
    set code [exec -- $cmd --tcltk]
115
 
 
116
 
    set path .dialog$dlg
117
 
    toplevel $path
118
 
    eval $code
119
 
}
120
 
 
121
 
###############################################################################
122
 
 
123
 
append regexp .* $env(GISBASE) {[^:]*}
124
 
regsub -- $regexp $env(PATH) "&:$env(GISBASE)/etc/dm/script" env(PATH)
125
 
 
126
 
 
127
 
###############################################################################
128
 
proc spawn {cmd args} {
129
 
    eval exec -- $cmd $args &
130
 
}
131
 
 
132
 
###############################################################################
133
 
        proc cmd_output {fh} {
134
 
                global outtext
135
 
                while {![eof $fh]} {
136
 
                        set str [gets $fh]
137
 
                        if {[regexp -- {^GRASS_INFO_PERCENT: (.+)$} $str match val rest]} {
138
 
                                #do nothing
139
 
                        } else {
140
 
                                append str "\n"
141
 
                                if { [fblocked $fh] } { set str [read $fh] }
142
 
                                while {[set idx [string first "\b" $str]] != -1} {
143
 
                                        set last [expr $idx - 1]
144
 
                                        set str1 [string range $str 1 $last]
145
 
                                        set first [expr $idx + 1]
146
 
                                        set str [string range $str $first end]
147
 
                                        set pos [$outtext index "end - 1 chars"]
148
 
                                        $outtext delete $pos
149
 
                                        $outtext insert end $str1
150
 
                                        update idletasks
151
 
                                }
152
 
                                $outtext insert end $str
153
 
                                $outtext yview end
154
 
                                update idletasks
155
 
                        }
156
 
                }
157
 
                catch {close $fh }
158
 
                return
159
 
        }
160
 
 
161
 
###############################################################################
162
 
 
163
 
        proc run_panel {cmd} {
164
 
                global outtext
165
 
                global env
166
 
                set message_env [exec g.gisenv get=GRASS_MESSAGE_FORMAT]
167
 
                set env(GRASS_MESSAGE_FORMAT) gui
168
 
                set cmd_name $cmd
169
 
                set cmd [concat | $cmd 2>/dev/null ]
170
 
                if { [catch {open $cmd r } fh] } {
171
 
                        error $fh
172
 
                }
173
 
                $outtext insert end "$cmd_name\n"
174
 
                $outtext yview end 
175
 
                catch {cmd_output $fh}
176
 
                set env(GRASS_MESSAGE_FORMAT) $message_env
177
 
        }
178
 
 
179
 
 
180
 
###############################################################################
181
 
 
182
 
        proc runcmd {cmd} {
183
 
                global outtext
184
 
                global env
185
 
                set cmd_name $cmd
186
 
            eval exec -- $cmd >@ stdout 2>@ stderr
187
 
                $outtext insert end "$cmd_name\n"
188
 
                $outtext yview end              
189
 
        }
190
 
 
191
 
###############################################################################
192
 
proc term_panel {cmd} {
193
 
        global outtext
194
 
    global env
195
 
    eval exec -- $env(GISBASE)/etc/grass-xterm-wrapper -name xterm-grass -e $env(GISBASE)/etc/grass-run.sh $cmd &
196
 
    set str $cmd
197
 
        $outtext insert end "$cmd\n"
198
 
        $outtext yview end
199
 
 
200
 
        update idletasks
201
 
}
202
 
 
203
 
###############################################################################
204
 
proc run {cmd args} {
205
 
    eval exec -- $cmd $args >@ stdout 2>@ stderr
206
 
 
207
 
}
208
 
 
209
 
 
210
 
 
211
 
###############################################################################
212
 
proc term {cmd args} {
213
 
    global env
214
 
    eval exec -- $env(GISBASE)/etc/grass-xterm-wrapper -name xterm-grass -e $env(GISBASE)/etc/grass-run.sh $cmd $args &
215
 
}
216
 
 
217
 
###############################################################################
218
 
# Make sure there's an xmon before running some commands.
219
 
# Used in menus. Dummy for now.
220
 
proc guarantee_xmon {} {
221
 
        #pass
222
 
}
223
 
 
224
 
###############################################################################
225
 
 
226
 
proc read_moncap {} {
227
 
        global env moncap
228
 
 
229
 
        set file [open [file join $env(GISBASE) etc monitorcap] r]
230
 
        set data [read $file]
231
 
        close $file
232
 
 
233
 
        set data [subst -nocommands -novariables $data]
234
 
        set moncap {}
235
 
        foreach line [split $data \n] {
236
 
                if {[string match {\#*} $line]} continue
237
 
                if {![string match {*:*:*:*:*:*} $line]} continue
238
 
                set fields {}
239
 
                foreach field [split $line :] {
240
 
                        lappend fields [string trim $field]
241
 
                }
242
 
                lappend moncap $fields
243
 
        }
244
 
}
245
 
 
246
 
###############################################################################
247
 
 
248
 
proc monitor_menu {op} {
249
 
        global moncap
250
 
 
251
 
        set submenu {}
252
 
        set last_driver {}
253
 
        foreach mon $moncap {
254
 
                set name [lindex $mon 0]
255
 
                set driver [lindex $mon 1]
256
 
                if {$last_driver != "" && $last_driver != $driver} {
257
 
                        lappend submenu {separator}
258
 
                }
259
 
                set last_driver $driver
260
 
                lappend submenu [list command $name {} "" {} -command "run d.mon $op=$name"]    }
261
 
 
262
 
        return [list $submenu]
263
 
}
264
 
 
265
 
###############################################################################
266
 
 
267
 
read_moncap
268
 
 
269
 
proc Dm::color { color } {
270
 
    
271
 
    regexp -- {#(..)(..)(..)} $color x r g b
272
 
 
273
 
    set r [expr 0x$r ]
274
 
    set g [expr 0x$g ]
275
 
    set b [expr 0x$b ]
276
 
 
277
 
    return "$r:$g:$b"
278
 
}
279
 
 
280
 
###############################################################################
281
 
 
282
 
proc Dm::displmon { mon } {
283
 
    global dmpath outtext
284
 
    if ![catch {open "|d.mon -L" r} input] {
285
 
        while {[gets $input line] >= 0} {
286
 
            if {[regexp -nocase "$mon.*not running" $line]} {
287
 
                                run "d.mon start=$mon"
288
 
            } elseif {[regexp -nocase "$mon.* running" $line]} {
289
 
                                run "d.mon select=$mon"
290
 
            }              
291
 
        }
292
 
                close $input
293
 
    }
294
 
    return
295
 
}
296
 
 
297
 
 
298
 
###############################################################################
299
 
 
300
 
 
301
 
proc Dm::create { } {
302
 
    global dmpath
303
 
    global mainwindow
304
 
    global bgcolor
305
 
    global cmd
306
 
    global outtext
307
 
    global mon
308
 
    variable mainframe
309
 
    variable options
310
 
    variable tree
311
 
    variable prgtext
312
 
    variable prgindic
313
 
        
314
 
    set prgtext [G_msg "Loading GIS Manager"]
315
 
    set prgindic -1
316
 
    _create_intro
317
 
    update
318
 
    
319
 
        
320
 
    # eval "exec sleep 20"
321
 
 
322
 
    global env
323
 
        source $dmpath/menu.tcl
324
 
 
325
 
    set prgtext   "Creating MainFrame..."
326
 
    set mainframe [MainFrame .mainframe \
327
 
                       -menu $descmenu -background $bgcolor \
328
 
                       -textvariable Dm::status \
329
 
                       -progressvar  Dm::prgindic ]
330
 
 
331
 
    set mainwindow [$mainframe getframe]
332
 
 
333
 
        # check for currently active monitor    
334
 
        if ![catch {open "|d.mon -L" r} input] {
335
 
                while {[gets $input line] >= 0} {
336
 
                        if {[regexp -nocase {.*(selected).*} $line]} {
337
 
                                regexp -nocase {..} $line mon
338
 
                        }              
339
 
                }       
340
 
                close $input
341
 
        }
342
 
 
343
 
    # toolbar 1 & 2 creation
344
 
    set tb1  [$mainframe addtoolbar]
345
 
    DmToolBar1::create $tb1
346
 
    set tb2  [$mainframe addtoolbar]
347
 
    DmToolBar2::create $tb2
348
 
    set pw2 [PanedWindow $mainwindow.pw2 -side left -pad 0 -width 10 -background $bgcolor ]   
349
 
    pack $pw2 -side left -expand yes -fill both -anchor n 
350
 
        set firstpane [$pw2 add -minsize 50 -weight 1]
351
 
    set pw1 [PanedWindow $firstpane.pw1 -side top -pad 0 -width 6 -background $bgcolor]
352
 
    pack $pw1 -side top -expand yes -fill both -anchor n 
353
 
 
354
 
    # MANAGE DISPLAY MONITORS
355
 
    set monitor_pane  [$pw1 add -minsize 1 -weight 0 ]
356
 
 
357
 
        label $monitor_pane.lbl1 -bg $bgcolor -fg darkgreen -text "Display"
358
 
        radiobutton $monitor_pane.rb0 -text "x0" -variable mon -value "x0" \
359
 
                -bg $bgcolor -command "Dm::displmon x0"
360
 
        radiobutton $monitor_pane.rb1 -text "x1" -variable mon -value "x1" \
361
 
                -bg $bgcolor -command "Dm::displmon x1"
362
 
        radiobutton $monitor_pane.rb2 -text "x2" -variable mon -value "x2" \
363
 
                -bg $bgcolor -command "Dm::displmon x2"
364
 
        radiobutton $monitor_pane.rb3 -text "x3" -variable mon -value "x3" \
365
 
                -bg $bgcolor -command "Dm::displmon x3"
366
 
        radiobutton $monitor_pane.rb4 -text "x4" -variable mon -value "x4" \
367
 
                -bg $bgcolor -command "Dm::displmon x4"
368
 
        radiobutton $monitor_pane.rb5 -text "x5" -variable mon -value "x5" \
369
 
                -bg $bgcolor -command "Dm::displmon x5"
370
 
        radiobutton $monitor_pane.rb6 -text "x6" -variable mon -value "x6" \
371
 
                -bg $bgcolor -command "Dm::displmon x6"
372
 
 
373
 
    pack $monitor_pane.lbl1 $monitor_pane.rb0 $monitor_pane.rb1 $monitor_pane.rb2 \
374
 
        $monitor_pane.rb3 $monitor_pane.rb4 $monitor_pane.rb5 \
375
 
        $monitor_pane.rb6 -side top -expand yes -anchor nw -fill both 
376
 
    pack $monitor_pane -side left -expand no -fill both
377
 
    
378
 
   
379
 
    # tree 
380
 
    set tree_pane  [$pw1 add  -minsize 50 -weight 1]
381
 
    set tree [ DmTree::create $tree_pane ]
382
 
 
383
 
 
384
 
    # options
385
 
    set options_pane  [$pw2 add -minsize 50 -weight 1]
386
 
    set options_sw [ScrolledWindow $options_pane.sw -relief raised -borderwidth 1]
387
 
    set options_sf [ScrollableFrame $options_sw.sf]
388
 
    $options_sf configure -height 145 -width 500
389
 
    $options_sw setwidget $options_sf
390
 
    set options [$options_sf getframe]
391
 
    pack $options_sw -fill both -expand yes
392
 
    bind_scroll $options_sf
393
 
 
394
 
    # output
395
 
    set output_pane  [$pw2 add -minsize 50 -weight 1 ] 
396
 
    pack $pw2 -fill both -expand yes
397
 
 
398
 
    set output_sw [ScrolledWindow $output_pane.win -relief sunken -borderwidth 1]
399
 
        set outtext [text $output_sw.text -height 5 -width 30] 
400
 
        $output_sw setwidget $outtext
401
 
    pack $output_sw -fill both -expand yes
402
 
  
403
 
 
404
 
    set prgtext   [G_msg "Done"]
405
 
 
406
 
    set Dm::status [G_msg "Welcome to the GRASS GIS manager"]
407
 
    $mainframe showstatusbar status 
408
 
 
409
 
    pack $mainframe -fill both -expand yes
410
 
 
411
 
    set fon [font create -family Verdana -size 12 ]
412
 
    DynamicHelp::configure -font $fon -background yellow
413
 
 
414
 
 
415
 
    update idletasks
416
 
}
417
 
 
418
 
###############################################################################
419
 
 
420
 
proc Dm::_create_intro { } {
421
 
    global dmpath
422
 
    global GRASSVERSION
423
 
    global location_name
424
 
    variable max_prgindic
425
 
 
426
 
    set top [toplevel .intro -relief raised -borderwidth 2]
427
 
 
428
 
    wm withdraw $top
429
 
    wm overrideredirect $top 1
430
 
 
431
 
    set ximg  [label $top.x -image [image create photo -file "$dmpath/intro.gif"] ]
432
 
 
433
 
    set frame [frame $ximg.f -background white]
434
 
    set lab1  [label $frame.lab1 -text "GRASS $GRASSVERSION GIS Manager - $location_name" \
435
 
                     -background white -foreground black -font {times 16}]
436
 
    set lab2  [label $frame.lab2 -textvariable Dm::prgtext -background white -font {times 12} -width 35]
437
 
    set prg   [ProgressBar $frame.prg -width 50 -height 15 -background white \
438
 
                   -variable Dm::prgindic -maximum $max_prgindic]
439
 
    pack $lab1 $prg $lab2 -side left
440
 
    place $frame -x 0 -y 0 -anchor nw
441
 
    pack $ximg
442
 
    BWidget::place $top 0 0 center
443
 
    wm deiconify $top
444
 
}
445
 
 
446
 
###############################################################################
447
 
 
448
 
# create new empty
449
 
proc Dm::new { } {
450
 
    variable tree
451
 
    variable options
452
 
    global new_root_node
453
 
    
454
 
    $tree delete [$tree nodes root]
455
 
    destroy $options.fr
456
 
 
457
 
    catch {unset ::Dm::filename}
458
 
    DmPrint::init
459
 
    set new_root_node [DmGroup::create $tree "root"]
460
 
    $tree itemconfigure $new_root_node -text "UNTITLED"
461
 
    
462
 
    set ::Dm::filename Untitled.dmrc 
463
 
}
464
 
 
465
 
###############################################################################
466
 
 
467
 
#Ctrl-W to close file
468
 
proc Dm::FileClose { stay_alive} {
469
 
    variable tree
470
 
    variable options
471
 
    
472
 
    $tree delete [$tree nodes root]
473
 
    destroy $options.fr
474
 
 
475
 
    if { $stay_alive == ""} {
476
 
        catch {unset ::Dm::filename}
477
 
    }
478
 
}
479
 
 
480
 
###############################################################################
481
 
 
482
 
# add new group/layer to tree
483
 
proc Dm::add { type } {
484
 
    variable tree
485
 
    global new_root_node
486
 
 
487
 
    if { [catch {match string {} $new_root_node}] } {
488
 
    set new_root_node root
489
 
    }
490
 
    # selected node
491
 
    set parent_node [ lindex [$tree selection get] 0 ]
492
 
    if { $parent_node == "" } {
493
 
       set parent_node $new_root_node
494
 
    } 
495
 
 
496
 
    set parent_type [Dm::node_type $parent_node]
497
 
    if { $parent_type != "group" } {
498
 
        set parent_node [$tree parent $parent_node]
499
 
    }
500
 
 
501
 
    switch $type {
502
 
        group {
503
 
            DmGroup::create $tree $parent_node
504
 
        }
505
 
        raster {
506
 
            DmRaster::create $tree $parent_node
507
 
        }
508
 
        vector {
509
 
            DmVector::create $tree $parent_node
510
 
        }
511
 
        labels {
512
 
            DmLabels::create $tree $parent_node
513
 
        }
514
 
        cmd {
515
 
            DmCmd::create $tree $parent_node
516
 
        }
517
 
        gridline {
518
 
            DmGridline::create $tree $parent_node
519
 
        }
520
 
        rgbhis {
521
 
            DmRgbhis::create $tree $parent_node
522
 
        }
523
 
        legend {
524
 
            DmLegend::create $tree $parent_node
525
 
        }
526
 
        dframe {
527
 
            DmDframe::create $tree $parent_node
528
 
        }
529
 
        barscale {
530
 
            DmBarscale::create $tree $parent_node
531
 
        }
532
 
        chart {
533
 
            DmChart::create $tree $parent_node
534
 
        }
535
 
        thematic {
536
 
            DmThematic::create $tree $parent_node
537
 
        }
538
 
        fttext {
539
 
            DmFTtext::create $tree $parent_node
540
 
        }
541
 
        dtext {
542
 
            DmDtext::create $tree $parent_node
543
 
        }
544
 
    }
545
 
}
546
 
 
547
 
###############################################################################
548
 
 
549
 
# autoname layer when a map is selected
550
 
proc Dm::autoname { name } {
551
 
    variable tree
552
 
    variable node
553
 
    set node [ lindex [$tree selection get] 0 ]
554
 
    DmTree::autoname $tree $node $name
555
 
}
556
 
 
557
 
###############################################################################
558
 
# selected node ( show options )
559
 
proc Dm::select { node } {
560
 
    variable tree
561
 
    variable options
562
 
 
563
 
    set type [Dm::node_type $node]
564
 
    set id [Dm::node_id $node]
565
 
 
566
 
    # destroy old panel with options
567
 
    destroy $options.fr
568
 
 
569
 
    set opt [frame $options.fr ]
570
 
    pack $opt -fill both -expand yes
571
 
 
572
 
    switch $type {
573
 
        raster {
574
 
            DmRaster::options $id $opt
575
 
        }
576
 
        vector {
577
 
            DmVector::options $id $opt
578
 
        }
579
 
        labels {
580
 
            DmLabels::options $id $opt
581
 
        }
582
 
        cmd {
583
 
            DmCmd::options $id $opt
584
 
        }
585
 
        gridline {
586
 
            DmGridline::options $id $opt
587
 
        }
588
 
        rgbhis {
589
 
            DmRgbhis::options $id $opt
590
 
        }
591
 
        legend {
592
 
            DmLegend::options $id $opt
593
 
        }
594
 
        dframe {
595
 
            DmDframe::options $id $opt
596
 
        }
597
 
        barscale {
598
 
            DmBarscale::options $id $opt
599
 
        }
600
 
        chart {
601
 
            DmChart::options $id $opt
602
 
        }
603
 
        thematic {
604
 
            DmThematic::options $id $opt
605
 
        }
606
 
        fttext {
607
 
            DmFTtext::options $id $opt
608
 
        }
609
 
        dtext {
610
 
            DmDtext::options $id $opt
611
 
        }
612
 
    }
613
 
}
614
 
 
615
 
###############################################################################
616
 
 
617
 
# deselect ( hide options )
618
 
proc Dm::deselect { node } {
619
 
    variable tree
620
 
    variable options
621
 
 
622
 
    destroy $options.fr
623
 
}
624
 
 
625
 
###############################################################################
626
 
 
627
 
# delete selected node
628
 
proc Dm::delete { } {
629
 
    variable tree
630
 
    variable options
631
 
 
632
 
    set sel [ lindex [$tree selection get] 0 ]
633
 
    if { $sel == "" } { return }
634
 
 
635
 
    $tree delete $sel
636
 
    destroy $options.fr
637
 
}
638
 
 
639
 
###############################################################################
640
 
 
641
 
# open monitor if no one is runnning
642
 
proc Dm::monitor { } {
643
 
    if ![catch {open "|d.mon -L" r} input] {
644
 
        while {[gets $input line] >= 0} {
645
 
            if {[regexp -nocase {(x.).*display *running} $line buffer monitor]} {
646
 
                return
647
 
            }
648
 
        }
649
 
                close $input
650
 
    }
651
 
    run "d.mon start=x0"
652
 
    return
653
 
}
654
 
 
655
 
###############################################################################
656
 
 
657
 
#digitize
658
 
proc Dm::edit { } {
659
 
    variable tree
660
 
    variable options
661
 
 
662
 
    set sel [ lindex [$tree selection get] 0 ]
663
 
    if { $sel == "" } {
664
 
        set message "No map selected"
665
 
        tk_messageBox -type ok -icon warning -message $message
666
 
        return
667
 
    }
668
 
 
669
 
    set type [Dm::node_type $sel]
670
 
 
671
 
    switch $type {
672
 
        raster {
673
 
        term r.digit $sel
674
 
            return
675
 
        }
676
 
        labels {
677
 
            return
678
 
        }
679
 
        vector {
680
 
            DmVector::WorkOnVector $sel
681
 
        }
682
 
        cmd {
683
 
            return
684
 
        }
685
 
        gridline {
686
 
            return
687
 
        }
688
 
        rgbhis {
689
 
            return
690
 
        }
691
 
        legend {
692
 
            return
693
 
        }
694
 
        dframe {
695
 
            return
696
 
        }
697
 
        barscale {
698
 
            return
699
 
        }
700
 
        chart {
701
 
            return
702
 
        }
703
 
        thematic {
704
 
            return
705
 
        }
706
 
        fttext {
707
 
            return
708
 
        }
709
 
        dtext {
710
 
            return
711
 
        }
712
 
    }
713
 
 
714
 
}
715
 
 
716
 
###############################################################################
717
 
proc message_dialog { msgtxt } {
718
 
        set msg [MessageDlg .msgdlg  \
719
 
                -title "The Message Dialog" \
720
 
                -message $msgtxt \
721
 
                -type yesno ]
722
 
if { $msg == 1 } {puts "no way" }
723
 
if { $msg == 0 } {puts "way to go"}
724
 
 
725
 
}
726
 
 
727
 
 
728
 
###############################################################################
729
 
 
730
 
# display
731
 
proc Dm::display { } {
732
 
        global outtext
733
 
 
734
 
        $outtext delete 1.0 end
735
 
 
736
 
    Dm::monitor
737
 
    run "d.frame -e"
738
 
    DmGroup::display "root" 
739
 
 
740
 
}
741
 
 
742
 
###############################################################################
743
 
 
744
 
# display all
745
 
proc Dm::displayall { } {
746
 
    
747
 
    set cmd "g.region -d"
748
 
    run $cmd 
749
 
 
750
 
    Dm::display
751
 
}
752
 
 
753
 
###############################################################################
754
 
 
755
 
# display region
756
 
proc Dm::display_region { } {
757
 
   
758
 
    set reg [GSelect windows]
759
 
    if { $reg != "" } {
760
 
        set cmd "g.region region=$reg"
761
 
        run $cmd 
762
 
 
763
 
        Dm::display
764
 
    }
765
 
}
766
 
 
767
 
###############################################################################
768
 
 
769
 
# zoom
770
 
proc Dm::zoom { } {
771
 
    
772
 
    set cmd "d.zoom"
773
 
    term $cmd
774
 
 
775
 
}
776
 
 
777
 
###############################################################################
778
 
 
779
 
# zoom back
780
 
proc Dm::zoom_back { } {
781
 
    
782
 
    set cmd "d.zoom -r"
783
 
    term $cmd
784
 
 
785
 
}
786
 
 
787
 
###############################################################################
788
 
 
789
 
# pan
790
 
proc Dm::pan { } {
791
 
    
792
 
    set cmd "d.zoom -p"
793
 
    term $cmd 
794
 
 
795
 
}
796
 
 
797
 
 
798
 
###############################################################################
799
 
 
800
 
# measure
801
 
proc Dm::measure { } {
802
 
    
803
 
    set cmd "d.measure"
804
 
    term $cmd 
805
 
 
806
 
}
807
 
 
808
 
###############################################################################
809
 
 
810
 
# position
811
 
proc Dm::position { } {
812
 
    
813
 
    set cmd "d.where"
814
 
    term $cmd 
815
 
 
816
 
}
817
 
 
818
 
###############################################################################
819
 
 
820
 
# nviz
821
 
proc Dm::nviz { } {
822
 
global osxaqua
823
 
global HOSTTYPE
824
 
    
825
 
    set cmd "nviz"
826
 
        if { $HOSTTYPE == "macintosh" || $HOSTTYPE == "powermac" || $HOSTTYPE == "powerpc" || $HOSTTYPE == "intel-pc"} {
827
 
                if { $osxaqua == "1"} {
828
 
                        spawn $cmd
829
 
                } else {
830
 
                        term $cmd
831
 
                }
832
 
        } else {
833
 
                spawn $cmd
834
 
        }
835
 
 
836
 
}
837
 
 
838
 
###############################################################################
839
 
 
840
 
# fly
841
 
proc Dm::fly { } {
842
 
    
843
 
    set cmd "d.nviz -i --ui"
844
 
    eval exec $cmd &
845
 
 
846
 
}
847
 
 
848
 
###############################################################################
849
 
 
850
 
# xganim
851
 
proc Dm::xganim { } {
852
 
    
853
 
    set cmd "xganim"
854
 
    eval exec $cmd &
855
 
 
856
 
}
857
 
 
858
 
###############################################################################
859
 
 
860
 
# erase to white
861
 
proc Dm::erase { } {
862
 
    
863
 
#    set cmd "d.erase white"
864
 
    set cmd "d.frame -e"
865
 
    run_panel $cmd 
866
 
 
867
 
}
868
 
 
869
 
###############################################################################
870
 
 
871
 
# help
872
 
proc Dm::help { } {
873
 
    
874
 
    set cmd "g.manual"
875
 
    term $cmd 
876
 
 
877
 
}
878
 
 
879
 
###############################################################################
880
 
 
881
 
# display node
882
 
proc Dm::display_node { node } {
883
 
    variable tree
884
 
 
885
 
    set type [Dm::node_type $node]
886
 
 
887
 
    switch $type {
888
 
        group {
889
 
            DmGroup::display $node
890
 
        }
891
 
        raster {
892
 
            DmRaster::display $node
893
 
        }
894
 
        labels {
895
 
            DmLabels::display $node
896
 
        }
897
 
        vector {
898
 
            DmVector::display $node
899
 
        }
900
 
        cmd {
901
 
            DmCmd::display $node
902
 
        }
903
 
        gridline {
904
 
            DmGridline::display $node
905
 
        }
906
 
        rgbhis {
907
 
            DmRgbhis::display $node
908
 
        }
909
 
        legend {
910
 
            DmLegend::display $node
911
 
        }
912
 
        dframe {
913
 
            DmDframe::display $node
914
 
        }
915
 
        barscale {
916
 
            DmBarscale::display $node
917
 
        }
918
 
        chart {
919
 
            DmChart::display $node
920
 
        }
921
 
        thematic {
922
 
            DmThematic::display $node
923
 
        }
924
 
        fttext {
925
 
            DmFTtext::display $node
926
 
        }
927
 
        dtext {
928
 
            DmDtext::display $node
929
 
        }
930
 
    } 
931
 
}
932
 
 
933
 
###############################################################################
934
 
 
935
 
# display node
936
 
proc Dm::print_node { file node } {
937
 
    variable tree
938
 
    global raster_printed
939
 
 
940
 
    set type [Dm::node_type $node]
941
 
 
942
 
    switch $type {
943
 
        group {
944
 
            DmGroup::print $file $node
945
 
        }
946
 
        raster {
947
 
            if { ! $raster_printed } { 
948
 
                DmRaster::print $file $node
949
 
                set raster_printed 1
950
 
            }
951
 
        }
952
 
        labels {
953
 
            DmLabels::print $file $node
954
 
        }
955
 
        vector {
956
 
            DmVector::print $file $node
957
 
        }
958
 
        cmd {
959
 
            puts "Command may not be printed to postscript file"
960
 
        }
961
 
        gridline {
962
 
            puts "not be printed to postscript file"
963
 
        }
964
 
        rgbhis {
965
 
            puts "not be printed to postscript file"
966
 
        }
967
 
        legend {
968
 
            puts "not be printed to postscript file"
969
 
        }
970
 
        dframe {
971
 
            puts "not be printed to postscript file"
972
 
        }
973
 
        barscale {
974
 
            puts "not be printed to postscript file"
975
 
        }
976
 
        chart {
977
 
            puts "not be printed to postscript file"
978
 
        }
979
 
        thematic {
980
 
            puts "not be printed to postscript file"
981
 
        }
982
 
        fttext {
983
 
            puts "not be printed to postscript file"
984
 
        }
985
 
        dtext {
986
 
            puts "not be printed to postscript file"
987
 
        }
988
 
    } 
989
 
}
990
 
 
991
 
###############################################################################
992
 
 
993
 
# query selected map
994
 
proc Dm::query { } {
995
 
    variable tree
996
 
    variable options
997
 
 
998
 
    set sel [ lindex [$tree selection get] 0 ]
999
 
    if { $sel == "" } { return }
1000
 
 
1001
 
    set type [Dm::node_type $sel]
1002
 
 
1003
 
    switch $type {
1004
 
        raster {
1005
 
            DmRaster::query $sel
1006
 
        }
1007
 
        labels {
1008
 
            DmLabels::query $sel
1009
 
        }
1010
 
        vector {
1011
 
            DmVector::query $sel
1012
 
        }
1013
 
        cmd {
1014
 
            DmCmd::query $sel
1015
 
        }
1016
 
        gridline {
1017
 
            return
1018
 
        }
1019
 
        rgbhis {
1020
 
            DmRgbhis::query $sel
1021
 
            #return
1022
 
        }
1023
 
        legend {
1024
 
            return
1025
 
        }
1026
 
        dframe {
1027
 
            return
1028
 
        }
1029
 
        barscale {
1030
 
            return
1031
 
        }
1032
 
        chart {
1033
 
            return
1034
 
        }
1035
 
        thematic {
1036
 
            return
1037
 
        }
1038
 
        fttext {
1039
 
            return
1040
 
        }
1041
 
        dtext {
1042
 
            return
1043
 
        }
1044
 
    }
1045
 
}
1046
 
 
1047
 
###############################################################################
1048
 
 
1049
 
# duplicate selected layer
1050
 
proc Dm::duplicate { } {
1051
 
    variable tree
1052
 
    variable options
1053
 
    variable id
1054
 
    global new_root_node
1055
 
 
1056
 
    if { [catch {match string {} $new_root_node}] } {
1057
 
    set new_root_node root
1058
 
    }
1059
 
    # selected node
1060
 
    set parent_node [ lindex [$tree selection get] 0 ]
1061
 
    if { $parent_node == "" } {
1062
 
       set parent_node $new_root_node
1063
 
    } 
1064
 
 
1065
 
    set parent_type [Dm::node_type $parent_node]
1066
 
    if { $parent_type != "group" } {
1067
 
        set parent_node [$tree parent $parent_node]
1068
 
    }
1069
 
 
1070
 
    set sel [ lindex [$tree selection get] 0 ]
1071
 
    if { $sel == "" } { return }
1072
 
    
1073
 
    set type [Dm::node_type $sel]
1074
 
    set id [Dm::node_id $sel]
1075
 
 
1076
 
    switch $type {
1077
 
        raster {
1078
 
            DmRaster::duplicate $tree $parent_node $sel $id
1079
 
        }
1080
 
        labels {
1081
 
            DmLabels::duplicate $tree $parent_node $sel $id
1082
 
        }
1083
 
        vector {
1084
 
            DmVector::duplicate $tree $parent_node $sel $id
1085
 
        }
1086
 
        cmd {
1087
 
            DmCmd::duplicate $tree $parent_node $sel $id
1088
 
        }
1089
 
        gridline {
1090
 
            DmGridline::duplicate $tree $parent_node $sel $id
1091
 
        }
1092
 
        rgbhis {
1093
 
            DmRgbhis::duplicate $tree $parent_node $sel $id
1094
 
        }
1095
 
        legend {
1096
 
            DmLegend::duplicate $tree $parent_node $sel $id
1097
 
        }
1098
 
        dframe {
1099
 
            DmDframe::duplicate $tree $parent_node $sel $id
1100
 
        }
1101
 
        barscale {
1102
 
            DmBarscale::duplicate $tree $parent_node $sel $id
1103
 
        }
1104
 
        chart {
1105
 
            DmChart::duplicate $tree $parent_node $sel $id
1106
 
        }
1107
 
        thematic {
1108
 
            DmThematic::duplicate $tree $parent_node $sel $id
1109
 
        }
1110
 
        fttext {
1111
 
            DmFTtext::duplicate $tree $parent_node $sel $id
1112
 
        }
1113
 
        dtext {
1114
 
            DmDtext::duplicate $tree $parent_node $sel $id
1115
 
        }
1116
 
        group {
1117
 
            DmGroup::duplicate $tree $parent_node $sel $id
1118
 
        }
1119
 
    }
1120
 
}
1121
 
 
1122
 
 
1123
 
###############################################################################
1124
 
 
1125
 
# save tree/options to file
1126
 
proc Dm::save { spth } {
1127
 
    global gisdbase location_name mapset
1128
 
    global env
1129
 
    variable rcfile
1130
 
    variable tree
1131
 
 
1132
 
    set fpath $spth
1133
 
    set rcfile [open $fpath w]
1134
 
 
1135
 
    DmPrint::save
1136
 
    DmGroup::save $tree 0 "root"
1137
 
 
1138
 
    close $rcfile
1139
 
}
1140
 
 
1141
 
###############################################################################
1142
 
 
1143
 
# save node to file
1144
 
proc Dm::save_node { depth node } {
1145
 
    variable rcfile
1146
 
    variable tree
1147
 
 
1148
 
    set type [Dm::node_type $node]
1149
 
    set name [$tree itemcget $node -text]
1150
 
 
1151
 
    if { $type == "group" && $name == "UNTITLED" } {
1152
 
    set name "File $::Dm::filename"
1153
 
    }
1154
 
 
1155
 
    switch $type {
1156
 
        group {
1157
 
            Dm::rc_write $depth Group $name
1158
 
            incr depth
1159
 
            DmGroup::save $tree $depth $node
1160
 
        }
1161
 
        raster {
1162
 
            Dm::rc_write $depth Raster $name
1163
 
            incr depth
1164
 
            DmRaster::save $tree $depth $node
1165
 
        }
1166
 
        labels {
1167
 
            Dm::rc_write $depth Labels $name
1168
 
            incr depth
1169
 
            DmLabels::save $tree $depth $node
1170
 
        }
1171
 
        vector {
1172
 
            Dm::rc_write $depth Vector $name
1173
 
            incr depth
1174
 
            DmVector::save $tree $depth $node
1175
 
        }
1176
 
        cmd {
1177
 
            Dm::rc_write $depth Cmd $name
1178
 
            incr depth
1179
 
            DmCmd::save $tree $depth $node
1180
 
        }
1181
 
        gridline {
1182
 
            Dm::rc_write $depth gridline $name
1183
 
            incr depth
1184
 
            DmGridline::save $tree $depth $node
1185
 
        }
1186
 
        rgbhis {
1187
 
            Dm::rc_write $depth rgbhis $name
1188
 
            incr depth
1189
 
            DmRgbhis::save $tree $depth $node
1190
 
        }
1191
 
        legend {
1192
 
            Dm::rc_write $depth legend $name
1193
 
            incr depth
1194
 
            DmLegend::save $tree $depth $node
1195
 
        }
1196
 
        dframe {
1197
 
            Dm::rc_write $depth dframe $name
1198
 
            incr depth
1199
 
            DmDframe::save $tree $depth $node
1200
 
        }
1201
 
        barscale {
1202
 
            Dm::rc_write $depth barscale $name
1203
 
            incr depth
1204
 
            DmBarscale::save $tree $depth $node
1205
 
        }
1206
 
        chart {
1207
 
            Dm::rc_write $depth chart $name
1208
 
            incr depth
1209
 
            DmChart::save $tree $depth $node
1210
 
        }
1211
 
        thematic {
1212
 
            Dm::rc_write $depth thematic $name
1213
 
            incr depth
1214
 
            DmThematic::save $tree $depth $node
1215
 
        }
1216
 
        fttext {
1217
 
            Dm::rc_write $depth fttext $name
1218
 
            incr depth
1219
 
            DmFTtext::save $tree $depth $node
1220
 
        }
1221
 
        dtext {
1222
 
            Dm::rc_write $depth dtext $name
1223
 
            incr depth
1224
 
            DmDtext::save $tree $depth $node
1225
 
        }
1226
 
    } 
1227
 
    set depth [expr $depth - 1]
1228
 
    Dm::rc_write $depth End
1229
 
    
1230
 
}
1231
 
 
1232
 
###############################################################################
1233
 
 
1234
 
# load tree/options from file
1235
 
proc Dm::load { lpth } {
1236
 
    global gisdbase location_name mapset
1237
 
    global env
1238
 
    variable rcfile
1239
 
    variable tree
1240
 
    variable max_prgindic
1241
 
    variable prgtext
1242
 
 
1243
 
    set prgtext "Loading layers..."
1244
 
 
1245
 
    set fpath $lpth
1246
 
 
1247
 
    if { ![file exist $fpath] || ![file readable $fpath] } { 
1248
 
            return 
1249
 
    }
1250
 
 
1251
 
    set rcfile [open $fpath r]
1252
 
    set file_size [file size $fpath]
1253
 
    set nrows [expr $file_size / 15]
1254
 
 
1255
 
    set print_section 0
1256
 
    set parent root
1257
 
    set row 0
1258
 
    while { [gets $rcfile in] > -1 } {
1259
 
                set key ""
1260
 
                set val ""
1261
 
        set in [string trim $in " "] 
1262
 
                if { $in == "" } { continue }
1263
 
 
1264
 
                if { ![regexp -- {([^ ]+) (.+)$} $in r key val] } {
1265
 
           set key $in
1266
 
        }
1267
 
        
1268
 
        # Print
1269
 
        if { $print_section } {
1270
 
            if { $key == "End" } { 
1271
 
                set print_section 0 
1272
 
            } else {
1273
 
                DmPrint::set_option $key $val
1274
 
            }
1275
 
        } else {
1276
 
            if { $key == "Print" } {
1277
 
                 set print_section 1
1278
 
            } else {  
1279
 
                # Tree of layers        
1280
 
                switch $key {
1281
 
                    Group {
1282
 
 
1283
 
                        if { [regexp -- {^File (.+)} $val r leftover]  && ($leftover !=
1284
 
                        $::Dm::filename)} {
1285
 
                                set val "<-- $leftover"
1286
 
                        }
1287
 
 
1288
 
                        set current_node [DmGroup::create $tree $parent]
1289
 
                        $tree itemconfigure $current_node -text $val 
1290
 
                        set parent $current_node
1291
 
                    }
1292
 
                    Raster {
1293
 
                        set current_node [DmRaster::create $tree $parent]
1294
 
                        $tree itemconfigure $current_node -text $val 
1295
 
                    }
1296
 
                    Labels {
1297
 
                        set current_node [DmLabels::create $tree $parent]
1298
 
                        $tree itemconfigure $current_node -text $val 
1299
 
                    }
1300
 
                    Vector {
1301
 
                        set current_node [DmVector::create $tree $parent]
1302
 
                        $tree itemconfigure $current_node -text $val 
1303
 
                    }
1304
 
                    Cmd {
1305
 
                        set current_node [DmCmd::create $tree $parent]
1306
 
                        $tree itemconfigure $current_node -text $val 
1307
 
                    }
1308
 
                    gridline {
1309
 
                        set current_node [DmGridline::create $tree $parent]
1310
 
                        $tree itemconfigure $current_node -text $val 
1311
 
                    }
1312
 
                    rgbhis {
1313
 
                        set current_node [DmRgbhis::create $tree $parent]
1314
 
                        $tree itemconfigure $current_node -text $val 
1315
 
                    }
1316
 
                    legend {
1317
 
                        set current_node [DmLegend::create $tree $parent]
1318
 
                        $tree itemconfigure $current_node -text $val 
1319
 
                    }
1320
 
                    dframe {
1321
 
                        set current_node [DmDframe::create $tree $parent]
1322
 
                        $tree itemconfigure $current_node -text $val 
1323
 
                    }
1324
 
                    barscale {
1325
 
                        set current_node [DmBarscale::create $tree $parent]
1326
 
                        $tree itemconfigure $current_node -text $val 
1327
 
                    }
1328
 
                    chart {
1329
 
                        set current_node [DmChart::create $tree $parent]
1330
 
                        $tree itemconfigure $current_node -text $val 
1331
 
                    }
1332
 
                    thematic {
1333
 
                        set current_node [DmThematic::create $tree $parent]
1334
 
                        $tree itemconfigure $current_node -text $val 
1335
 
                    }
1336
 
                    fttext {
1337
 
                        set current_node [DmFTtext::create $tree $parent]
1338
 
                        $tree itemconfigure $current_node -text $val 
1339
 
                    }
1340
 
                    dtext {
1341
 
                        set current_node [DmDtext::create $tree $parent]
1342
 
                        $tree itemconfigure $current_node -text $val 
1343
 
                    }
1344
 
                    End {
1345
 
                                set type [Dm::node_type $current_node]
1346
 
                                if { $type == "group"  } {
1347
 
                                        set parent [$tree parent $parent]
1348
 
                                }
1349
 
                                set current_node [$tree parent $current_node]
1350
 
                    }
1351
 
                    default {
1352
 
                      if {[catch {Dm::node_type $current_node}] } {
1353
 
                        tk_messageBox -type ok -message "Can't open $fpath - bad file format"
1354
 
                        break
1355
 
                      } else {
1356
 
 
1357
 
                        set type [Dm::node_type $current_node]
1358
 
                        switch $type {
1359
 
                            group { 
1360
 
                                DmGroup::set_option $current_node $key $val
1361
 
                            }
1362
 
                            raster { 
1363
 
                                DmRaster::set_option $current_node $key $val
1364
 
                            }
1365
 
                            labels { 
1366
 
                                DmLabels::set_option $current_node $key $val
1367
 
                            }
1368
 
                            vector { 
1369
 
                                DmVector::set_option $current_node $key $val
1370
 
                            }
1371
 
                            cmd { 
1372
 
                                DmCmd::set_option $current_node $key $val
1373
 
                            }
1374
 
                            gridline { 
1375
 
                                DmGridline::set_option $current_node $key $val
1376
 
                            }
1377
 
                            rgbhis { 
1378
 
                                DmRgbhis::set_option $current_node $key $val
1379
 
                            }
1380
 
                            legend { 
1381
 
                                DmLegend::set_option $current_node $key $val
1382
 
                            }
1383
 
                            dframe { 
1384
 
                                DmDframe::set_option $current_node $key $val
1385
 
                            }
1386
 
                            barscale { 
1387
 
                                DmBarscale::set_option $current_node $key $val
1388
 
                            }
1389
 
                            chart { 
1390
 
                                DmChart::set_option $current_node $key $val
1391
 
                            }
1392
 
                            thematic { 
1393
 
                                DmThematic::set_option $current_node $key $val
1394
 
                            }
1395
 
                            fttext { 
1396
 
                                DmFTtext::set_option $current_node $key $val
1397
 
                            }
1398
 
                            dtext { 
1399
 
                                DmDtext::set_option $current_node $key $val
1400
 
                            }
1401
 
                        }
1402
 
                      }
1403
 
                    }           
1404
 
                }
1405
 
            }
1406
 
            incr row
1407
 
            set prg [expr $max_prgindic * $row / $nrows]
1408
 
            if { $prg > $max_prgindic } { set prg $max_prgindic }
1409
 
            set Dm::prgindic $prg
1410
 
        }
1411
 
    }
1412
 
    close $rcfile
1413
 
    set Dm::prgindic $max_prgindic
1414
 
    set prgtext "Layers loaded"
1415
 
}
1416
 
 
1417
 
###############################################################################
1418
 
 
1419
 
# write one row
1420
 
proc Dm::rc_write { depth args } {
1421
 
    variable rcfile
1422
 
 
1423
 
    set offset [string repeat "  " $depth]
1424
 
 
1425
 
    set key [lindex $args 0]
1426
 
    if { [llength $args] > 1 } {
1427
 
       set value [lindex $args 1]
1428
 
       set row "$offset$key $value"
1429
 
    } else {
1430
 
       set row "$offset$key"
1431
 
    }
1432
 
    puts $rcfile $row
1433
 
}
1434
 
 
1435
 
###############################################################################
1436
 
 
1437
 
# returns node type
1438
 
proc Dm::node_type { node } {
1439
 
    variable tree
1440
 
 
1441
 
    if { [string compare $node "root"] == 0 } {
1442
 
       return "group"
1443
 
    }  
1444
 
    if { [string match group* $node] } {
1445
 
       return "group"
1446
 
    }  
1447
 
    if { [string match raster* $node] } {
1448
 
       return "raster"
1449
 
    }  
1450
 
    if { [string match labels* $node] } {
1451
 
       return "labels"
1452
 
    }  
1453
 
    if { [string match vector* $node] } {
1454
 
       return "vector"
1455
 
    }  
1456
 
    if { [string match cmd* $node] } {
1457
 
       return "cmd"
1458
 
    }  
1459
 
    if { [string match gridline* $node] } {
1460
 
       return "gridline"
1461
 
    }  
1462
 
    if { [string match rgbhis* $node] } {
1463
 
       return "rgbhis"
1464
 
    }  
1465
 
    if { [string match legend* $node] } {
1466
 
       return "legend"
1467
 
    }  
1468
 
    if { [string match dframe* $node] } {
1469
 
       return "dframe"
1470
 
    }  
1471
 
    if { [string match barscale* $node] } {
1472
 
       return "barscale"
1473
 
    }  
1474
 
    if { [string match chart* $node] } {
1475
 
       return "chart"
1476
 
    }  
1477
 
    if { [string match thematic* $node] } {
1478
 
       return "thematic"
1479
 
    }  
1480
 
    if { [string match fttext* $node] } {
1481
 
       return "fttext"
1482
 
    }  
1483
 
    if { [string match dtext* $node] } {
1484
 
       return "dtext"
1485
 
    }  
1486
 
    
1487
 
    return ""
1488
 
}
1489
 
 
1490
 
###############################################################################
1491
 
 
1492
 
# returns node id
1493
 
proc Dm::node_id { node } {
1494
 
    variable tree
1495
 
 
1496
 
    if { ![regexp {[^:]+:(.+)$} $node x id] } {
1497
 
        return 0
1498
 
    } else {
1499
 
        return $id
1500
 
    }
1501
 
}
1502
 
 
1503
 
###############################################################################
1504
 
 
1505
 
# execute command
1506
 
proc Dm::execute { cmd } {
1507
 
    global env
1508
 
 
1509
 
    # warning: DBMI - be careful and test 'd.vect where=' after changes
1510
 
    puts stdout $cmd
1511
 
    
1512
 
      ## This was old version - does not work, because $shell have not LD_LIBRARY_PATH to GRASS libs ? 
1513
 
      #set shell $env(SHELL)
1514
 
      #set cmd [ string map { \" \\\" \$ \\\$ } $cmd ]
1515
 
      #eval "exec echo \"$cmd\" | $shell >@stdout 2>@stdout"
1516
 
 
1517
 
    eval "exec $cmd >@stdout 2>@stdout"
1518
 
}
1519
 
 
1520
 
###############################################################################
1521
 
 
1522
 
# open print window
1523
 
proc Dm::print { } {
1524
 
    DmPrint::window
1525
 
}
1526
 
 
1527
 
###############################################################################
1528
 
 
1529
 
#open dialog box
1530
 
proc Dm::OpenFileBox {w} {
1531
 
    global mainwindow
1532
 
    variable win
1533
 
 
1534
 
    set win $w
1535
 
    
1536
 
    if { $win == ""} {set win $mainwindow}
1537
 
    
1538
 
    set types {
1539
 
        {{Adm Resource Files} {{.dm} {.dmrc}}}
1540
 
        {{All Files} *}
1541
 
    }
1542
 
 
1543
 
        if {[catch {tk_getOpenFile \
1544
 
                -parent $win \
1545
 
                -filetypes $types \
1546
 
                -title {Load File}} \
1547
 
                ::Dm::filename_new] || \
1548
 
                [string match {} $::Dm::filename_new]} return
1549
 
        
1550
 
        if {[catch {if { [ regexp -- {^Untitled.dmrc$} $::Dm::filename r]} {}}] } {
1551
 
                set ::Dm::filename $::Dm::filename_new
1552
 
        }
1553
 
        
1554
 
        Dm::load $::Dm::filename_new
1555
 
                
1556
 
};
1557
 
 
1558
 
###############################################################################
1559
 
 
1560
 
#save dialog box
1561
 
proc Dm::SaveFileBox {w} {
1562
 
    global mainwindow
1563
 
    variable win
1564
 
 
1565
 
    set win $w
1566
 
    if { $win == ""} {set win $mainwindow}
1567
 
    catch {if { [ regexp -- {^Untitled.dmrc$} $::Dm::filename r]} {unset ::Dm::filename}}
1568
 
    if {[catch {Dm::save $::Dm::filename}]} {
1569
 
        set types {
1570
 
            {{Adm Resource Files} {{.dm} {.dmrc}}}
1571
 
            {{All Files} *}
1572
 
        }
1573
 
        if {[catch {tk_getSaveFile \
1574
 
                -parent $win \
1575
 
                -filetypes $types \
1576
 
                -title {Save File}} \
1577
 
                ::Dm::filename] || \
1578
 
                [string match {} $::Dm::filename]} return
1579
 
        
1580
 
        Dm::save $::Dm::filename
1581
 
        Dm::FileClose stay_alive
1582
 
        Dm::load $::Dm::filename
1583
 
    }
1584
 
};
1585
 
 
1586
 
###############################################################################
1587
 
 
1588
 
proc main {argc argv} {
1589
 
    global auto_path
1590
 
    global GRASSVERSION
1591
 
    global location_name
1592
 
    global keycontrol
1593
 
 
1594
 
    wm withdraw .
1595
 
    wm title . [G_msg "GRASS $GRASSVERSION GIS Manager - $location_name"]
1596
 
 
1597
 
    bind . <$keycontrol-Key-o> {
1598
 
        Dm::OpenFileBox {}
1599
 
    }
1600
 
    bind . <$keycontrol-Key-n> {
1601
 
        Dm::new
1602
 
    }
1603
 
    bind . <$keycontrol-Key-s> {
1604
 
        Dm::SaveFileBox {}
1605
 
    }
1606
 
    bind . <$keycontrol-Key-q> {
1607
 
        DmPrint::clean;  exit
1608
 
    }
1609
 
    bind . <$keycontrol-Key-x> {
1610
 
        Dm::delete
1611
 
    }
1612
 
    bind . <$keycontrol-Key-w> {
1613
 
        Dm::FileClose {}
1614
 
    }
1615
 
    bind . <$keycontrol-Key-p> {
1616
 
    Dm::print
1617
 
    }
1618
 
 
1619
 
 
1620
 
    Dm::create
1621
 
    DmPrint::init
1622
 
    DmPrint::init_tmpfiles
1623
 
    BWidget::place . 0 0 center
1624
 
    wm deiconify .
1625
 
    raise .
1626
 
    focus -force .
1627
 
    destroy .intro
1628
 
    
1629
 
    if { $argc == "1"} { 
1630
 
        set ::Dm::filename $argv
1631
 
        Dm::load $::Dm::filename
1632
 
    }
1633
 
 
1634
 
}
1635
 
 
1636
 
bind . <Destroy> { if { "%W" == "."} { DmPrint::clean } } 
1637
 
main $argc $argv
1638
 
wm geom . [wm geom .]
1639