workspace.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. elif control == 'box':
  102. box = UserSettings.Get(group = 'nviz', key = 'volume', subkey = ['draw', 'box'])
  103. data['draw']['box'] = {'enabled': box}
  104. else:
  105. data['draw'][control] = {}
  106. data['draw'][control]['isosurface'] = { 'value' : value }
  107. data['draw'][control]['slice'] = { 'value' : value }
  108. if 'update' not in data['draw'][control]:
  109. data['draw'][control]['update'] = None
  110. #
  111. # isosurface attributes
  112. #
  113. for attrb in ('shine', ):
  114. data['attribute'][attrb] = {}
  115. for key, value in UserSettings.Get(group='nviz', key='volume',
  116. subkey=attrb).iteritems():
  117. data['attribute'][attrb][key] = value
  118. return data
  119. def SetIsosurfaceDefaultProp(self):
  120. """!Set default isosurface properties"""
  121. data = dict()
  122. for attr in ('shine', 'topo', 'transp', 'color'):
  123. data[attr] = {}
  124. for key, value in UserSettings.Get(group = 'nviz', key = 'volume',
  125. subkey = attr).iteritems():
  126. data[attr][key] = value
  127. data[attr]['update'] = None
  128. return data
  129. def SetSliceDefaultProp(self):
  130. """!Set default slice properties"""
  131. data = dict()
  132. data['position'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'volume',
  133. subkey = 'slice_position'))
  134. data['position']['update'] = None
  135. data['transp'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'volume',
  136. subkey = 'transp'))
  137. return data
  138. def SetVectorDefaultProp(self, data = None):
  139. """Set default vector data properties"""
  140. if not data:
  141. data = dict()
  142. for sec in ('lines', 'points'):
  143. data[sec] = {}
  144. self.SetVectorLinesDefaultProp(data['lines'])
  145. self.SetVectorPointsDefaultProp(data['points'])
  146. return data
  147. def SetVectorLinesDefaultProp(self, data):
  148. """Set default vector properties -- lines"""
  149. # width
  150. data['width'] = {'value' : UserSettings.Get(group='nviz', key='vector',
  151. subkey=['lines', 'width']) }
  152. # color
  153. value = UserSettings.Get(group='nviz', key='vector',
  154. subkey=['lines', 'color'])
  155. color = str(value[0]) + ':' + str(value[1]) + ':' + str(value[2])
  156. data['color'] = { 'value' : color }
  157. # mode
  158. if UserSettings.Get(group='nviz', key='vector',
  159. subkey=['lines', 'flat']):
  160. type = 'flat'
  161. else:
  162. type = 'surface'
  163. data['mode'] = {}
  164. data['mode']['type'] = type
  165. data['mode']['update'] = None
  166. # height
  167. data['height'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
  168. subkey=['lines', 'height']) }
  169. # thematic
  170. data['thematic'] = {'rgbcolumn' : UserSettings.Get(group='nviz', key='vector',
  171. subkey=['lines', 'rgbcolumn']),
  172. 'sizecolumn' : UserSettings.Get(group='nviz', key='vector',
  173. subkey=['lines', 'sizecolumn']),
  174. 'layer': 1,
  175. 'usecolor' : False,
  176. 'usewidth' : False}
  177. if 'object' in data:
  178. for attrb in ('color', 'width', 'mode', 'height', 'thematic'):
  179. data[attrb]['update'] = None
  180. def SetVectorPointsDefaultProp(self, data):
  181. """Set default vector properties -- points"""
  182. # size
  183. data['size'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
  184. subkey=['points', 'size']) }
  185. # width
  186. data['width'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
  187. subkey=['points', 'width']) }
  188. # marker
  189. data['marker'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
  190. subkey=['points', 'marker']) }
  191. # color
  192. value = UserSettings.Get(group='nviz', key='vector',
  193. subkey=['points', 'color'])
  194. color = str(value[0]) + ':' + str(value[1]) + ':' + str(value[2])
  195. data['color'] = { 'value' : color }
  196. # mode
  197. data['mode'] = { 'type' : 'surface'}
  198. ## 'surface' : '', }
  199. # height
  200. data['height'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
  201. subkey=['points', 'height']) }
  202. data['thematic'] = {'rgbcolumn' : UserSettings.Get(group='nviz', key='vector',
  203. subkey=['points', 'rgbcolumn']),
  204. 'sizecolumn' : UserSettings.Get(group='nviz', key='vector',
  205. subkey=['points', 'sizecolumn']),
  206. 'layer': 1,
  207. 'usecolor' : False,
  208. 'usesize' : False}
  209. if 'object' in data:
  210. for attrb in ('size', 'width', 'marker',
  211. 'color', 'height', 'thematic'):
  212. data[attrb]['update'] = None
  213. def GetDrawMode(self, mode=None, style=None, shade=None, string=False):
  214. """Get surface draw mode (value) from description/selection
  215. @param mode,style,shade modes
  216. @param string if True input parameters are strings otherwise
  217. selections
  218. """
  219. if not wxnviz:
  220. return None
  221. value = 0
  222. desc = {}
  223. if string:
  224. if mode is not None:
  225. if mode == 'coarse':
  226. value |= wxnviz.DM_WIRE
  227. elif mode == 'fine':
  228. value |= wxnviz.DM_POLY
  229. else: # both
  230. value |= wxnviz.DM_WIRE_POLY
  231. if style is not None:
  232. if style == 'wire':
  233. value |= wxnviz.DM_GRID_WIRE
  234. else: # surface
  235. value |= wxnviz.DM_GRID_SURF
  236. if shade is not None:
  237. if shade == 'flat':
  238. value |= wxnviz.DM_FLAT
  239. else: # surface
  240. value |= wxnviz.DM_GOURAUD
  241. return value
  242. # -> string is False
  243. if mode is not None:
  244. if mode == 0: # coarse
  245. value |= wxnviz.DM_WIRE
  246. desc['mode'] = 'coarse'
  247. elif mode == 1: # fine
  248. value |= wxnviz.DM_POLY
  249. desc['mode'] = 'fine'
  250. else: # both
  251. value |= wxnviz.DM_WIRE_POLY
  252. desc['mode'] = 'both'
  253. if style is not None:
  254. if style == 0: # wire
  255. value |= wxnviz.DM_GRID_WIRE
  256. desc['style'] = 'wire'
  257. else: # surface
  258. value |= wxnviz.DM_GRID_SURF
  259. desc['style'] = 'surface'
  260. if shade is not None:
  261. if shade == 0:
  262. value |= wxnviz.DM_FLAT
  263. desc['shading'] = 'flat'
  264. else: # surface
  265. value |= wxnviz.DM_GOURAUD
  266. desc['shading'] = 'gouraud'
  267. return (value, desc)
  268. def SetDecorDefaultProp(self, type):
  269. """!Set default arrow properties
  270. """
  271. data = {}
  272. # arrow
  273. if type == 'arrow':
  274. data['arrow'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'arrow'))
  275. data['arrow']['color'] = "%d:%d:%d" % (
  276. UserSettings.Get(group = 'nviz', key = 'arrow', subkey = 'color')[:3])
  277. data['arrow'].update(copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'arrow', internal = True)))
  278. data['arrow']['show'] = False
  279. # arrow
  280. if type == 'scalebar':
  281. data['scalebar'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'scalebar'))
  282. data['scalebar']['color'] = "%d:%d:%d" % (
  283. UserSettings.Get(group = 'nviz', key = 'scalebar', subkey = 'color')[:3])
  284. data['scalebar'].update(copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'scalebar', internal = True)))
  285. data['scalebar']['id'] = 0
  286. return data