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

« back to all changes in this revision

Viewing changes to visualization/nviz/scripts/wirecolorPopup.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
 
# mkWireColorPopup w name color
3
 
#
4
 
# Create a dialog box with sliders and buttons to adjust current color
5
 
# of wire mesh for current surface 
6
 
#
7
 
# Arguments:
8
 
#    w -        Name to use for new top-level window.
9
 
#    name -     Label for ColorPopup
10
 
#    color -    CurrentColor (set to UseMap if map is used)
11
 
# Updated Nov 2006, Michael Barton, Arizona State University
12
 
#
13
 
##########################################################################
14
 
# COPYRIGHT:    (C) 2006 by Michael Barton and 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
 
 
23
 
global CurrWireColor
24
 
 
25
 
proc mkWireColorPopup {w name {color "#000000"} {mode 0}} {
26
 
    global CurrWireColor
27
 
 
28
 
    catch {destroy $w}
29
 
    toplevel $w -class Dialog
30
 
    wm title $w [G_msg "Select Wire Color"]
31
 
    wm iconname $w "Color"
32
 
    wm geometry $w 300x450
33
 
    wm minsize $w 50 100
34
 
    wm resizable $w false false
35
 
 
36
 
    if {"$color" != "UseMap"} then {
37
 
                set tmp [tcl_to_rgb $color]
38
 
                set r [expr ($tmp&0xff0000)>>16]
39
 
                set g [expr ($tmp&0x00ff00)>>8]
40
 
                set b [expr ($tmp&0x0000ff)]
41
 
    } else {
42
 
                set r 0
43
 
                set g 0
44
 
                set b 0
45
 
    }
46
 
 
47
 
    set tmp $color
48
 
 
49
 
    # Create two frames in the main window. The top frame will hold the
50
 
    # sliders that interactively change color and the bottom one will hold 
51
 
    # the buttons for predefined color.  Below the two frames we create
52
 
    # a checkbutton widget allowing the color to be set to the colormap
53
 
    # for the surface
54
 
 
55
 
    frame $w.top -relief raised -border 1
56
 
    frame $w.bot -relief raised -border 1
57
 
    checkbutton $w.usemap -text [G_msg "use surface color"] -onvalue UseMap \
58
 
                -offvalue 0 -variable CurrWireColor
59
 
    frame $w.top.left
60
 
    Nv_mkWireColorScale $w.top.left Red $r red  $w.top.color
61
 
    Nv_mkWireColorScale $w.top.left Green $g green  $w.top.color
62
 
    Nv_mkWireColorScale $w.top.left Blue $b blue  $w.top.color
63
 
    
64
 
    pack $w.top.left.red $w.top.left.green $w.top.left.blue \
65
 
        -side top -expand 1 -pady 2     
66
 
           
67
 
        # this is the main color panel
68
 
    set CurrWireColor $color
69
 
    if {"$color" != "UseMap"} then {
70
 
                label $w.top.color -bg $color -width 20 -height 10
71
 
    } else {
72
 
                label $w.top.color -bg \#FFFFFF -width 20 -height 10
73
 
    }
74
 
    pack $w.top.left  -side left -padx 10 -pady 10 -expand 1
75
 
    pack $w.top.color -side left -padx 10 -pady 10 -expand yes
76
 
 
77
 
    tkwait visibility $w
78
 
    
79
 
    frame $w.bot.buttonframe
80
 
    button $w.bot.buttonframe.ok -text [G_msg "Ok"] -width 6 \
81
 
        -command "destroy $w" -bd 1
82
 
    button $w.bot.buttonframe.cancel  -bd 1 -width 6\
83
 
         -text [G_msg "Cancel"]  -command "set CurrWireColor $tmp; destroy $w"
84
 
    pack $w.bot.buttonframe.cancel -side right -expand 0
85
 
    pack $w.bot.buttonframe.ok -side left -expand 0
86
 
    pack $w.bot.buttonframe -side bottom -fill x \
87
 
        -pady 3 -padx 10 -expand 1
88
 
 
89
 
    mkWireColorButtons $w.bot.bf $w.top.left $w.top.color
90
 
    pack $w.bot.bf -pady 3 -side top -expand 1
91
 
    bind $w <Any-Enter> [list focus $w]
92
 
    focus $w
93
 
    if {$mode} {grab $w}
94
 
 
95
 
    pack $w.top $w.bot $w.usemap -side top -fill both \
96
 
        -expand yes
97
 
 
98
 
 
99
 
    tkwait window $w
100
 
 
101
 
    return $CurrWireColor
102
 
}
103
 
 
104
 
proc mkWireColorButtons { B S L} {
105
 
 
106
 
    global CurrWireColor
107
 
    
108
 
    frame $B
109
 
    set clist [mkWireColorList]
110
 
 
111
 
    for {set i 0; set k 0} {$i < 9 } {incr i} {
112
 
        # make frame to hold buttons in this row 
113
 
        frame $B.f$i
114
 
        for {set j 0} {$j < 5 } {incr j; incr k} {
115
 
            set color [lindex $clist $k]
116
 
            button $B.f$i.$j -bg $color \
117
 
                -activeforeground $color \
118
 
                -activebackground $color \
119
 
                -width 0 -height 0 \
120
 
                -highlightthickness 1 \
121
 
        -command "setWireScales $S $color; $L config -bg $color; set CurrWireColor $color"
122
 
            pack $B.f$i.$j -padx 1 -pady 1 -side top -expand 1
123
 
        }
124
 
        pack $B.f$i -side left
125
 
    }
126
 
}
127
 
 
128
 
proc getWireColorfromScales {S} {
129
 
 
130
 
    set r [$S.red.scale get]
131
 
    set g [$S.green.scale get]
132
 
    set b [$S.blue.scale get]
133
 
 
134
 
    set r [hexval $r]
135
 
    set g [hexval $g]
136
 
    set b [hexval $b]
137
 
 
138
 
    
139
 
    return #$r$g$b
140
 
}
141
 
 
142
 
 
143
 
proc setWireLabelfromScales {S L args} {
144
 
    global CurrWireColor
145
 
 
146
 
    set r [$S.red.scale get]
147
 
    set g [$S.green.scale get]
148
 
    set b [$S.blue.scale get]
149
 
 
150
 
    set r [hexval $r]
151
 
    set g [hexval $g]
152
 
    set b [hexval $b]
153
 
 
154
 
    $L config -bg #$r$g$b
155
 
    set CurrWireColor #$r$g$b
156
 
}
157
 
 
158
 
proc setWireScales {S c} {
159
 
    set color [tcl_to_rgb $c]
160
 
    set r [expr ($color&0xff0000)>>16]
161
 
    set g [expr ($color&0x00ff00)>>8]
162
 
    set b [expr ($color&0x0000ff)]
163
 
 
164
 
    $S.red.scale set $r
165
 
    $S.green.scale set $g
166
 
    $S.blue.scale set $b
167
 
}
168
 
 
169
 
proc mkWireColorList {} {
170
 
 
171
 
    set ramp 0
172
 
    set colorlist {}
173
 
    set maxval ff
174
 
    set minval 00
175
 
    for {set r 4; set i 0} {$r < 16} {incr r 5} {
176
 
        for {set g 4} {$g < 16} {incr g 5} {
177
 
            for {set b 4} {$b < 16 && $i < 40} {incr b 5} {
178
 
                set tmpr [hexval [expr $r/15.0*255]]
179
 
                set tmpg [hexval [expr $g/15.0*255]]
180
 
                set tmpb [hexval [expr $b/15.0*255]]
181
 
                set color #$tmpr$tmpg$tmpb
182
 
                set colorlist [concat $colorlist $color]
183
 
                incr i
184
 
            }
185
 
            if {$ramp == 0} {
186
 
                set colorlist [concat $colorlist #ff0000 #00ffff]
187
 
                incr ramp 2
188
 
                incr i 2
189
 
            } elseif {$ramp < 10} {
190
 
                set tmpg [hexval [expr $ramp/9.0*255]]
191
 
                set color #$maxval$tmpg$minval
192
 
                set colorlist [concat $colorlist $color]
193
 
                incr ramp
194
 
                incr i
195
 
 
196
 
                set tmpg [hexval [expr (1.0 - $ramp/9.0)*255]]
197
 
                set color #$minval$tmpg$maxval
198
 
                set colorlist [concat $colorlist $color]
199
 
                incr ramp
200
 
                incr i
201
 
 
202
 
            } elseif {$ramp < 16} {
203
 
                set tmpb [hexval [expr ($ramp-10)/7.0*255]]
204
 
                set color #$maxval$maxval$tmpb
205
 
                set colorlist [concat $colorlist $color]
206
 
                incr ramp
207
 
                incr i
208
 
                set tmpb [hexval [expr (1.0 - ($ramp-10)/7.0)*255]]
209
 
                set color #$minval$minval$tmpb
210
 
                set colorlist [concat $colorlist $color]
211
 
                incr ramp
212
 
                incr i
213
 
            }
214
 
        }
215
 
    }
216
 
    for {set gray 0} {$gray < 5} {incr gray} {
217
 
        set g [hexval [expr (1.0 - $gray/4.0)*255]]
218
 
        set color #$g$g$g
219
 
        set colorlist [concat $colorlist $color]
220
 
    }
221
 
 
222
 
 
223
 
    return $colorlist
224
 
 
225
 
}
226
 
 
227
 
##########################################################################
228
 
# procedure to make sliders
229
 
##########################################################################
230
 
proc Nv_mkWireColorScale { P {name " "} {curr 200}\
231
 
    {color ""} {chip ""}} {
232
 
 
233
 
    set S $P.$color
234
 
    frame $S
235
 
    frame $S.f
236
 
 
237
 
    scale $S.scale -from 0 -length 140 -showvalue 1 -orient h\
238
 
        -tickinterval 0 -to 255 -width 13 \
239
 
        -command "setWireLabelfromScales $P $chip" \
240
 
        -label $name \
241
 
        -highlightthickness 3 \
242
 
        -highlightbackground $color
243
 
       
244
 
    $S.scale set $curr
245
 
    pack $S.scale $S.f -side top
246
 
 
247
 
    return $S
248
 
}
249
 
 
250
 
 
251