GRASS Programmer's Manual  6.4.3(2013)-r
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
nviz/workspace.py
Go to the documentation of this file.
1 """!
2 @package nviz.workspace
3 
4 @brief wxNviz workspace settings
5 
6 Classes:
7  - workspace::NvizSettings
8 
9 (C) 2007-2011 by the GRASS Development Team
10 
11 This program is free software under the GNU General Public License
12 (>=v2). Read the file COPYING that comes with GRASS for details.
13 
14 @author Anna Kratochvilova <kratochanna gmail.com> (wxNviz / Google SoC 2011)
15 """
16 
17 import copy
18 
19 from core.settings import UserSettings
20 
21 try:
22  from nviz import wxnviz
23 except ImportError:
24  wxnviz = None
25 
26 class NvizSettings(object):
27  def __init__(self):
28  pass
29 
31  """Set default constant data properties"""
32  data = dict()
33  for key, value in UserSettings.Get(group='nviz', key='constant').iteritems():
34  data[key] = value
35  color = str(data['color'][0]) + ':' + str(data['color'][1]) + ':' + str(data['color'][2])
36  data['color'] = color
37 
38  return data
39 
40  def SetSurfaceDefaultProp(self, data = None):
41  """Set default surface data properties"""
42  if not data:
43  data = dict()
44  for sec in ('attribute', 'draw', 'mask', 'position'):
45  data[sec] = {}
46 
47  #
48  # attributes
49  #
50  for attrb in ('shine', ):
51  data['attribute'][attrb] = {}
52  for key, value in UserSettings.Get(group='nviz', key='surface',
53  subkey=attrb).iteritems():
54  data['attribute'][attrb][key] = value
55  data['attribute'][attrb]['update'] = None
56 
57  #
58  # draw
59  #
60  data['draw']['all'] = False # apply only for current surface
61  for control, value in UserSettings.Get(group='nviz', key='surface', subkey='draw').iteritems():
62  if control[:3] == 'res':
63  if 'resolution' not in data['draw']:
64  data['draw']['resolution'] = {}
65  if 'update' not in data['draw']['resolution']:
66  data['draw']['resolution']['update'] = None
67  data['draw']['resolution'][control[4:]] = value
68  continue
69 
70  if control == 'wire-color':
71  value = str(value[0]) + ':' + str(value[1]) + ':' + str(value[2])
72  elif control in ('mode', 'style', 'shading'):
73  if 'mode' not in data['draw']:
74  data['draw']['mode'] = {}
75  continue
76 
77  data['draw'][control] = { 'value' : value }
78  data['draw'][control]['update'] = None
79 
80  value, desc = self.GetDrawMode(UserSettings.Get(group='nviz', key='surface', subkey=['draw', 'mode']),
81  UserSettings.Get(group='nviz', key='surface', subkey=['draw', 'style']),
82  UserSettings.Get(group='nviz', key='surface', subkey=['draw', 'shading']))
83 
84  data['draw']['mode'] = { 'value' : value,
85  'desc' : desc,
86  'update': None }
87  # position
88  for coord in ('x', 'y', 'z'):
89  data['position'][coord] = UserSettings.Get(group='nviz', key='surface', subkey=['position', coord])
90  data['position']['update'] = None
91 
92  return data
93 
95  """Set default volume data properties"""
96  data = dict()
97  for sec in ('attribute', 'draw', 'position'):
98  data[sec] = dict()
99  for sec in ('isosurface', 'slice'):
100  data[sec] = list()
101 
102  #
103  # draw
104  #
105  for control, value in UserSettings.Get(group='nviz', key='volume', subkey='draw').iteritems():
106  if control == 'shading':
107  sel = UserSettings.Get(group='nviz', key='volume', subkey=['draw', 'shading'])
108  value, desc = self.GetDrawMode(shade=sel, string=False)
109 
110  data['draw']['shading'] = {}
111  data['draw']['shading']['isosurface'] = { 'value' : value,
112  'desc' : desc['shading'] }
113  data['draw']['shading']['slice'] = { 'value' : value,
114  'desc' : desc['shading'] }
115  elif control == 'mode':
116  sel = UserSettings.Get(group='nviz', key='volume', subkey=['draw', 'mode'])
117  if sel == 0:
118  desc = 'isosurface'
119  else:
120  desc = 'slice'
121  data['draw']['mode'] = { 'value' : sel,
122  'desc' : desc, }
123  else:
124  data['draw'][control] = {}
125  data['draw'][control]['isosurface'] = { 'value' : value }
126  data['draw'][control]['slice'] = { 'value' : value }
127 
128  if 'update' not in data['draw'][control]:
129  data['draw'][control]['update'] = None
130 
131  #
132  # isosurface attributes
133  #
134  for attrb in ('shine', ):
135  data['attribute'][attrb] = {}
136  for key, value in UserSettings.Get(group='nviz', key='volume',
137  subkey=attrb).iteritems():
138  data['attribute'][attrb][key] = value
139 
140  return data
141 
143  """!Set default isosurface properties"""
144  data = dict()
145  for attr in ('shine', 'topo', 'transp', 'color'):
146  data[attr] = {}
147  for key, value in UserSettings.Get(group = 'nviz', key = 'volume',
148  subkey = attr).iteritems():
149  data[attr][key] = value
150  data[attr]['update'] = None
151  return data
152 
154  """!Set default slice properties"""
155  data = dict()
156  data['position'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'volume',
157  subkey = 'slice_position'))
158  data['position']['update'] = None
159 
160  data['transp'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'volume',
161  subkey = 'transp'))
162  return data
163 
164  def SetVectorDefaultProp(self, data = None):
165  """Set default vector data properties"""
166  if not data:
167  data = dict()
168  for sec in ('lines', 'points'):
169  data[sec] = {}
170 
171  self.SetVectorLinesDefaultProp(data['lines'])
172  self.SetVectorPointsDefaultProp(data['points'])
173 
174  return data
175 
176  def SetVectorLinesDefaultProp(self, data):
177  """Set default vector properties -- lines"""
178  # width
179  data['width'] = {'value' : UserSettings.Get(group='nviz', key='vector',
180  subkey=['lines', 'width']) }
181 
182  # color
183  value = UserSettings.Get(group='nviz', key='vector',
184  subkey=['lines', 'color'])
185  color = str(value[0]) + ':' + str(value[1]) + ':' + str(value[2])
186  data['color'] = { 'value' : color }
187 
188  # mode
189  if UserSettings.Get(group='nviz', key='vector',
190  subkey=['lines', 'flat']):
191  type = 'flat'
192 
193  else:
194  type = 'surface'
195 
196  data['mode'] = {}
197  data['mode']['type'] = type
198  data['mode']['update'] = None
199 
200  # height
201  data['height'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
202  subkey=['lines', 'height']) }
203  if 'object' in data:
204  for attrb in ('color', 'width', 'mode', 'height'):
205  data[attrb]['update'] = None
206 
207  def SetVectorPointsDefaultProp(self, data):
208  """Set default vector properties -- points"""
209  # size
210  data['size'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
211  subkey=['points', 'size']) }
212 
213  # width
214  data['width'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
215  subkey=['points', 'width']) }
216 
217  # marker
218  data['marker'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
219  subkey=['points', 'marker']) }
220 
221  # color
222  value = UserSettings.Get(group='nviz', key='vector',
223  subkey=['points', 'color'])
224  color = str(value[0]) + ':' + str(value[1]) + ':' + str(value[2])
225  data['color'] = { 'value' : color }
226 
227  # mode
228  data['mode'] = { 'type' : 'surface'}
229 ## 'surface' : '', }
230 
231  # height
232  data['height'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
233  subkey=['points', 'height']) }
234 
235  if 'object' in data:
236  for attrb in ('size', 'width', 'marker', 'color', 'height'):
237  data[attrb]['update'] = None
238 
239  def GetDrawMode(self, mode=None, style=None, shade=None, string=False):
240  """Get surface draw mode (value) from description/selection
241 
242  @param mode,style,shade modes
243  @param string if True input parameters are strings otherwise
244  selections
245  """
246  if not wxnviz:
247  return None
248 
249  value = 0
250  desc = {}
251 
252  if string:
253  if mode is not None:
254  if mode == 'coarse':
255  value |= wxnviz.DM_WIRE
256  elif mode == 'fine':
257  value |= wxnviz.DM_POLY
258  else: # both
259  value |= wxnviz.DM_WIRE_POLY
260 
261  if style is not None:
262  if style == 'wire':
263  value |= wxnviz.DM_GRID_WIRE
264  else: # surface
265  value |= wxnviz.DM_GRID_SURF
266 
267  if shade is not None:
268  if shade == 'flat':
269  value |= wxnviz.DM_FLAT
270  else: # surface
271  value |= wxnviz.DM_GOURAUD
272 
273  return value
274 
275  # -> string is False
276  if mode is not None:
277  if mode == 0: # coarse
278  value |= wxnviz.DM_WIRE
279  desc['mode'] = 'coarse'
280  elif mode == 1: # fine
281  value |= wxnviz.DM_POLY
282  desc['mode'] = 'fine'
283  else: # both
284  value |= wxnviz.DM_WIRE_POLY
285  desc['mode'] = 'both'
286 
287  if style is not None:
288  if style == 0: # wire
289  value |= wxnviz.DM_GRID_WIRE
290  desc['style'] = 'wire'
291  else: # surface
292  value |= wxnviz.DM_GRID_SURF
293  desc['style'] = 'surface'
294 
295  if shade is not None:
296  if shade == 0:
297  value |= wxnviz.DM_FLAT
298  desc['shading'] = 'flat'
299  else: # surface
300  value |= wxnviz.DM_GOURAUD
301  desc['shading'] = 'gouraud'
302 
303  return (value, desc)
304 
305  def SetDecorDefaultProp(self, type):
306  """!Set default arrow properties
307  """
308  data = {}
309 
310  # arrow
311  if type == 'arrow':
312  data['arrow'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'arrow'))
313  data['arrow']['color'] = "%d:%d:%d" % (
314  UserSettings.Get(group = 'nviz', key = 'arrow', subkey = 'color')[:3])
315  data['arrow'].update(copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'arrow', internal = True)))
316  data['arrow']['show'] = False
317 
318  # arrow
319  if type == 'scalebar':
320  data['scalebar'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'scalebar'))
321  data['scalebar']['color'] = "%d:%d:%d" % (
322  UserSettings.Get(group = 'nviz', key = 'scalebar', subkey = 'color')[:3])
323  data['scalebar'].update(copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'scalebar', internal = True)))
324  data['scalebar']['id'] = 0
325  return data
def SetDecorDefaultProp
Set default arrow properties.
def SetIsosurfaceDefaultProp
Set default isosurface properties.
Default GUI settings.
def SetSliceDefaultProp
Set default slice properties.