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

« back to all changes in this revision

Viewing changes to gui/wxpython/nviz/workspace.py

  • 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
 
"""!
 
1
"""
2
2
@package nviz.workspace
3
3
 
4
4
@brief wxNviz workspace settings
17
17
import copy
18
18
 
19
19
from core.settings import UserSettings
 
20
from core.utils import _
20
21
 
21
22
try:
22
23
    from nviz import wxnviz
23
24
except ImportError:
24
25
    wxnviz = None
25
26
 
 
27
 
26
28
class NvizSettings(object):
27
29
    def __init__(self):
28
30
        pass
29
 
        
 
31
 
30
32
    def SetConstantDefaultProp(self):
31
33
        """Set default constant data properties"""
32
34
        data = dict()
36
38
        data['color'] = color
37
39
 
38
40
        return data
39
 
    
40
 
    def SetSurfaceDefaultProp(self, data = None):
 
41
 
 
42
    def SetSurfaceDefaultProp(self, data=None):
41
43
        """Set default surface data properties"""
42
44
        if not data:
43
45
            data = dict()
44
46
        for sec in ('attribute', 'draw', 'mask', 'position'):
45
47
            data[sec] = {}
46
 
        
 
48
 
47
49
        #
48
50
        # attributes
49
51
        #
53
55
                                               subkey=attrb).iteritems():
54
56
                data['attribute'][attrb][key] = value
55
57
            data['attribute'][attrb]['update'] = None
56
 
        
 
58
 
57
59
        #
58
60
        # draw
59
61
        #
60
62
        data['draw']['all'] = False # apply only for current surface
61
 
        for control, value in UserSettings.Get(group='nviz', key='surface', subkey='draw').iteritems():
 
63
        for control, value in UserSettings.Get(group='nviz', key='surface',
 
64
                                               subkey='draw').iteritems():
62
65
            if control[:3] == 'res':
63
66
                if 'resolution' not in data['draw']:
64
67
                    data['draw']['resolution'] = {}
66
69
                    data['draw']['resolution']['update'] = None
67
70
                data['draw']['resolution'][control[4:]] = value
68
71
                continue
69
 
            
 
72
 
70
73
            if control == 'wire-color':
71
74
                value = str(value[0]) + ':' + str(value[1]) + ':' + str(value[2])
72
75
            elif control in ('mode', 'style', 'shading'):
76
79
 
77
80
            data['draw'][control] = { 'value' : value }
78
81
            data['draw'][control]['update'] = None
79
 
        
 
82
 
80
83
        value, desc = self.GetDrawMode(UserSettings.Get(group='nviz', key='surface', subkey=['draw', 'mode']),
81
84
                                       UserSettings.Get(group='nviz', key='surface', subkey=['draw', 'style']),
82
85
                                       UserSettings.Get(group='nviz', key='surface', subkey=['draw', 'shading']))
83
 
    
 
86
 
84
87
        data['draw']['mode'] = { 'value' : value,
85
 
                                 'desc' : desc, 
 
88
                                 'desc' : desc,
86
89
                                 'update': None }
87
90
        # position
88
91
        for coord in ('x', 'y', 'z'):
89
92
            data['position'][coord] = UserSettings.Get(group='nviz', key='surface', subkey=['position', coord])
90
93
        data['position']['update'] = None
91
 
            
 
94
 
92
95
        return data
93
 
    
 
96
 
94
97
    def SetVolumeDefaultProp(self):
95
98
        """Set default volume data properties"""
96
99
        data = dict()
98
101
            data[sec] = dict()
99
102
            for sec in ('isosurface', 'slice'):
100
103
                    data[sec] = list()
101
 
        
 
104
 
102
105
        #
103
106
        # draw
104
107
        #
106
109
            if control == 'shading':
107
110
                sel = UserSettings.Get(group='nviz', key='volume', subkey=['draw', 'shading'])
108
111
                value, desc = self.GetDrawMode(shade=sel, string=False)
109
 
                
 
112
 
110
113
                data['draw']['shading'] = {}
111
114
                data['draw']['shading']['isosurface'] = { 'value' : value,
112
115
                                                          'desc' : desc['shading'] }
120
123
                    desc = 'slice'
121
124
                data['draw']['mode'] = { 'value' : sel,
122
125
                                         'desc' : desc, }
 
126
            elif control == 'box':
 
127
                box = UserSettings.Get(group = 'nviz', key = 'volume', subkey = ['draw', 'box'])
 
128
                data['draw']['box'] = {'enabled': box}
 
129
 
123
130
            else:
124
131
                data['draw'][control] = {}
125
132
                data['draw'][control]['isosurface'] = { 'value' : value }
127
134
 
128
135
            if 'update' not in data['draw'][control]:
129
136
                data['draw'][control]['update'] = None
130
 
        
 
137
 
131
138
        #
132
139
        # isosurface attributes
133
140
        #
136
143
            for key, value in UserSettings.Get(group='nviz', key='volume',
137
144
                                               subkey=attrb).iteritems():
138
145
                data['attribute'][attrb][key] = value
139
 
        
 
146
 
140
147
        return data
141
 
    
 
148
 
142
149
    def SetIsosurfaceDefaultProp(self):
143
 
        """!Set default isosurface properties"""
 
150
        """Set default isosurface properties"""
144
151
        data = dict()
145
152
        for attr in ('shine', 'topo', 'transp', 'color', 'inout'):
146
153
            data[attr] = {}
147
154
            data[attr]['update'] = None
148
155
            if attr == 'inout':
149
156
                data[attr]['value'] = 0
150
 
                continue                
 
157
                continue
151
158
            for key, value in UserSettings.Get(group = 'nviz', key = 'volume',
152
159
                                               subkey = attr).iteritems():
153
160
                data[attr][key] = value
154
161
        return data
155
 
    
 
162
 
156
163
    def SetSliceDefaultProp(self):
157
 
        """!Set default slice properties"""
 
164
        """Set default slice properties"""
158
165
        data = dict()
159
 
        data['position'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'volume',
 
166
        data['position'] = copy.deepcopy(UserSettings.Get(group='nviz', key='volume',
160
167
                                               subkey = 'slice_position'))
161
168
        data['position']['update'] = None
162
 
        
163
 
        data['transp'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'volume',
164
 
                                               subkey = 'transp'))
 
169
 
 
170
        data['transp'] = copy.deepcopy(UserSettings.Get(group='nviz', key='volume',
 
171
                                                        subkey='transp'))
165
172
        return data
166
 
    
167
 
    def SetVectorDefaultProp(self, data = None):
 
173
 
 
174
    def SetVectorDefaultProp(self, data=None):
168
175
        """Set default vector data properties"""
169
176
        if not data:
170
177
            data = dict()
171
178
        for sec in ('lines', 'points'):
172
179
            data[sec] = {}
173
 
        
 
180
 
174
181
        self.SetVectorLinesDefaultProp(data['lines'])
175
182
        self.SetVectorPointsDefaultProp(data['points'])
176
183
 
177
184
        return data
178
 
    
 
185
 
179
186
    def SetVectorLinesDefaultProp(self, data):
180
187
        """Set default vector properties -- lines"""
181
188
        # width
182
 
        data['width'] = {'value' : UserSettings.Get(group='nviz', key='vector',
183
 
                                                    subkey=['lines', 'width']) }
184
 
        
 
189
        data['width'] = {'value': UserSettings.Get(group='nviz', key='vector',
 
190
                                                   subkey=['lines', 'width'])}
 
191
 
185
192
        # color
186
193
        value = UserSettings.Get(group='nviz', key='vector',
187
194
                                 subkey=['lines', 'color'])
188
195
        color = str(value[0]) + ':' + str(value[1]) + ':' + str(value[2])
189
 
        data['color'] = { 'value' : color }
 
196
        data['color'] = {'value': color}
190
197
 
191
198
        # mode
192
199
        if UserSettings.Get(group='nviz', key='vector',
193
200
                            subkey=['lines', 'flat']):
194
201
            type = 'flat'
195
 
            
 
202
 
196
203
        else:
197
204
            type = 'surface'
198
 
            
 
205
 
199
206
        data['mode'] = {}
200
207
        data['mode']['type'] = type
201
208
        data['mode']['update'] = None
202
 
    
 
209
 
203
210
        # height
204
211
        data['height'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
205
212
                                                      subkey=['lines', 'height']) }
 
213
        # thematic
 
214
        data['thematic'] = {'rgbcolumn' : UserSettings.Get(group='nviz', key='vector',
 
215
                                                      subkey=['lines', 'rgbcolumn']),
 
216
                            'sizecolumn' : UserSettings.Get(group='nviz', key='vector',
 
217
                                                      subkey=['lines', 'sizecolumn']),
 
218
                            'layer': 1,
 
219
                            'usecolor' : False,
 
220
                            'usewidth' : False}
206
221
        if 'object' in data:
207
 
            for attrb in ('color', 'width', 'mode', 'height'):
 
222
            for attrb in ('color', 'width', 'mode', 'height', 'thematic'):
208
223
                data[attrb]['update'] = None
209
 
        
 
224
 
210
225
    def SetVectorPointsDefaultProp(self, data):
211
226
        """Set default vector properties -- points"""
212
227
        # size
230
245
        # mode
231
246
        data['mode'] = { 'type' : 'surface'}
232
247
##                         'surface' : '', }
233
 
        
 
248
 
234
249
        # height
235
250
        data['height'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
236
251
                                                      subkey=['points', 'height']) }
237
 
        
 
252
 
 
253
        data['thematic'] = {'rgbcolumn' : UserSettings.Get(group='nviz', key='vector',
 
254
                                                      subkey=['points', 'rgbcolumn']),
 
255
                            'sizecolumn' : UserSettings.Get(group='nviz', key='vector',
 
256
                                                      subkey=['points', 'sizecolumn']),
 
257
                            'layer': 1,
 
258
                            'usecolor' : False,
 
259
                            'usesize' : False}
238
260
        if 'object' in data:
239
 
            for attrb in ('size', 'width', 'marker', 'color', 'height'):
 
261
            for attrb in ('size', 'width', 'marker',
 
262
                          'color', 'height', 'thematic'):
240
263
                data[attrb]['update'] = None
241
 
        
 
264
 
242
265
    def GetDrawMode(self, mode=None, style=None, shade=None, string=False):
243
266
        """Get surface draw mode (value) from description/selection
244
267
 
245
 
        @param mode,style,shade modes
246
 
        @param string if True input parameters are strings otherwise
247
 
        selections
 
268
        :param mode:
 
269
        :param style:
 
270
        :param shade:
 
271
        :param string: if True input parameters are strings otherwise
 
272
                       selections
248
273
        """
249
274
        if not wxnviz:
250
275
            return None
251
 
        
 
276
 
252
277
        value = 0
253
278
        desc = {}
254
279
 
266
291
                    value |= wxnviz.DM_GRID_WIRE
267
292
                else: # surface
268
293
                    value |= wxnviz.DM_GRID_SURF
269
 
                    
 
294
 
270
295
            if shade is not None:
271
296
                if shade == 'flat':
272
297
                    value |= wxnviz.DM_FLAT
302
327
            else: # surface
303
328
                value |= wxnviz.DM_GOURAUD
304
329
                desc['shading'] = 'gouraud'
305
 
        
 
330
 
306
331
        return (value, desc)
307
 
    
 
332
 
308
333
    def SetDecorDefaultProp(self, type):
309
 
        """!Set default arrow properties
 
334
        """Set default arrow properties
310
335
        """
311
336
        data = {}
312
 
        
 
337
 
313
338
        # arrow
314
339
        if type == 'arrow':
315
 
            data['arrow'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'arrow'))
 
340
            data['arrow'] = copy.deepcopy(UserSettings.Get(group='nviz',
 
341
                                                           key='arrow'))
316
342
            data['arrow']['color'] = "%d:%d:%d" % (
317
 
                UserSettings.Get(group = 'nviz', key = 'arrow', subkey = 'color')[:3])
318
 
            data['arrow'].update(copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'arrow', internal = True)))
 
343
                UserSettings.Get(group='nviz', key='arrow',
 
344
                                 subkey='color')[:3])
 
345
            data['arrow'].update(copy.deepcopy(UserSettings.Get(group='nviz',
 
346
                                                                key='arrow',
 
347
                                                                settings_type='internal')))
319
348
            data['arrow']['show'] = False
320
 
        
 
349
 
321
350
        # arrow
322
351
        if type == 'scalebar':
323
 
            data['scalebar'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'scalebar'))
 
352
            data['scalebar'] = copy.deepcopy(UserSettings.Get(group='nviz',
 
353
                                                              key='scalebar'))
324
354
            data['scalebar']['color'] = "%d:%d:%d" % (
325
 
                UserSettings.Get(group = 'nviz', key = 'scalebar', subkey = 'color')[:3])
326
 
            data['scalebar'].update(copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'scalebar', internal = True)))
 
355
                UserSettings.Get(group='nviz', key='scalebar',
 
356
                                 subkey='color')[:3])
 
357
            data['scalebar'].update(copy.deepcopy(UserSettings.Get(group='nviz',
 
358
                                                                   key='scalebar',
 
359
                                                                   settings_type='internal')))
327
360
            data['scalebar']['id'] = 0
328
361
        return data