GRASS Programmer's Manual  6.4.4(2014)-r
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', 'inout'):
146  data[attr] = {}
147  data[attr]['update'] = None
148  if attr == 'inout':
149  data[attr]['value'] = 0
150  continue
151  for key, value in UserSettings.Get(group = 'nviz', key = 'volume',
152  subkey = attr).iteritems():
153  data[attr][key] = value
154  return data
155 
157  """!Set default slice properties"""
158  data = dict()
159  data['position'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'volume',
160  subkey = 'slice_position'))
161  data['position']['update'] = None
162 
163  data['transp'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'volume',
164  subkey = 'transp'))
165  return data
166 
167  def SetVectorDefaultProp(self, data = None):
168  """Set default vector data properties"""
169  if not data:
170  data = dict()
171  for sec in ('lines', 'points'):
172  data[sec] = {}
173 
174  self.SetVectorLinesDefaultProp(data['lines'])
175  self.SetVectorPointsDefaultProp(data['points'])
176 
177  return data
178 
179  def SetVectorLinesDefaultProp(self, data):
180  """Set default vector properties -- lines"""
181  # width
182  data['width'] = {'value' : UserSettings.Get(group='nviz', key='vector',
183  subkey=['lines', 'width']) }
184 
185  # color
186  value = UserSettings.Get(group='nviz', key='vector',
187  subkey=['lines', 'color'])
188  color = str(value[0]) + ':' + str(value[1]) + ':' + str(value[2])
189  data['color'] = { 'value' : color }
190 
191  # mode
192  if UserSettings.Get(group='nviz', key='vector',
193  subkey=['lines', 'flat']):
194  type = 'flat'
195 
196  else:
197  type = 'surface'
198 
199  data['mode'] = {}
200  data['mode']['type'] = type
201  data['mode']['update'] = None
202 
203  # height
204  data['height'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
205  subkey=['lines', 'height']) }
206  if 'object' in data:
207  for attrb in ('color', 'width', 'mode', 'height'):
208  data[attrb]['update'] = None
209 
210  def SetVectorPointsDefaultProp(self, data):
211  """Set default vector properties -- points"""
212  # size
213  data['size'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
214  subkey=['points', 'size']) }
215 
216  # width
217  data['width'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
218  subkey=['points', 'width']) }
219 
220  # marker
221  data['marker'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
222  subkey=['points', 'marker']) }
223 
224  # color
225  value = UserSettings.Get(group='nviz', key='vector',
226  subkey=['points', 'color'])
227  color = str(value[0]) + ':' + str(value[1]) + ':' + str(value[2])
228  data['color'] = { 'value' : color }
229 
230  # mode
231  data['mode'] = { 'type' : 'surface'}
232 ## 'surface' : '', }
233 
234  # height
235  data['height'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
236  subkey=['points', 'height']) }
237 
238  if 'object' in data:
239  for attrb in ('size', 'width', 'marker', 'color', 'height'):
240  data[attrb]['update'] = None
241 
242  def GetDrawMode(self, mode=None, style=None, shade=None, string=False):
243  """Get surface draw mode (value) from description/selection
244 
245  @param mode,style,shade modes
246  @param string if True input parameters are strings otherwise
247  selections
248  """
249  if not wxnviz:
250  return None
251 
252  value = 0
253  desc = {}
254 
255  if string:
256  if mode is not None:
257  if mode == 'coarse':
258  value |= wxnviz.DM_WIRE
259  elif mode == 'fine':
260  value |= wxnviz.DM_POLY
261  else: # both
262  value |= wxnviz.DM_WIRE_POLY
263 
264  if style is not None:
265  if style == 'wire':
266  value |= wxnviz.DM_GRID_WIRE
267  else: # surface
268  value |= wxnviz.DM_GRID_SURF
269 
270  if shade is not None:
271  if shade == 'flat':
272  value |= wxnviz.DM_FLAT
273  else: # surface
274  value |= wxnviz.DM_GOURAUD
275 
276  return value
277 
278  # -> string is False
279  if mode is not None:
280  if mode == 0: # coarse
281  value |= wxnviz.DM_WIRE
282  desc['mode'] = 'coarse'
283  elif mode == 1: # fine
284  value |= wxnviz.DM_POLY
285  desc['mode'] = 'fine'
286  else: # both
287  value |= wxnviz.DM_WIRE_POLY
288  desc['mode'] = 'both'
289 
290  if style is not None:
291  if style == 0: # wire
292  value |= wxnviz.DM_GRID_WIRE
293  desc['style'] = 'wire'
294  else: # surface
295  value |= wxnviz.DM_GRID_SURF
296  desc['style'] = 'surface'
297 
298  if shade is not None:
299  if shade == 0:
300  value |= wxnviz.DM_FLAT
301  desc['shading'] = 'flat'
302  else: # surface
303  value |= wxnviz.DM_GOURAUD
304  desc['shading'] = 'gouraud'
305 
306  return (value, desc)
307 
308  def SetDecorDefaultProp(self, type):
309  """!Set default arrow properties
310  """
311  data = {}
312 
313  # arrow
314  if type == 'arrow':
315  data['arrow'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'arrow'))
316  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)))
319  data['arrow']['show'] = False
320 
321  # arrow
322  if type == 'scalebar':
323  data['scalebar'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'scalebar'))
324  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)))
327  data['scalebar']['id'] = 0
328  return data
def SetSliceDefaultProp(self)
Set default slice properties.
def SetVectorLinesDefaultProp(self, data)
def SetConstantDefaultProp(self)
def SetVectorPointsDefaultProp(self, data)
def update(self)
def SetVolumeDefaultProp(self)
def SetIsosurfaceDefaultProp(self)
Set default isosurface properties.
Default GUI settings.
def SetDecorDefaultProp(self, type)
Set default arrow properties.