workspace.py 14 KB

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