workspace.py 13 KB

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