workspace.py 13 KB

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