workspace.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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. import six
  13. from core.settings import UserSettings
  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 six.iteritems(UserSettings.Get(group='nviz',
  25. key='constant')):
  26. data[key] = value
  27. color = str(data['color'][0]) + ':' + str(data['color']
  28. [1]) + ':' + str(data['color'][2])
  29. data['color'] = color
  30. return data
  31. def SetSurfaceDefaultProp(self, data=None):
  32. """Set default surface data properties"""
  33. if not data:
  34. data = dict()
  35. for sec in ('attribute', 'draw', 'mask', 'position'):
  36. data[sec] = {}
  37. #
  38. # attributes
  39. #
  40. for attrb in ('shine', ):
  41. data['attribute'][attrb] = {}
  42. for key, value in six.iteritems(UserSettings.Get(group='nviz',
  43. key='surface',
  44. subkey=attrb)):
  45. data['attribute'][attrb][key] = value
  46. data['attribute'][attrb]['update'] = None
  47. #
  48. # draw
  49. #
  50. data['draw']['all'] = False # apply only for current surface
  51. for control, value in six.iteritems(UserSettings.Get(group='nviz',
  52. key='surface',
  53. subkey='draw')):
  54. if control[:3] == 'res':
  55. if 'resolution' not in data['draw']:
  56. data['draw']['resolution'] = {}
  57. if 'update' not in data['draw']['resolution']:
  58. data['draw']['resolution']['update'] = None
  59. data['draw']['resolution'][control[4:]] = value
  60. continue
  61. if control == 'wire-color':
  62. value = str(value[0]) + ':' + str(value[1]
  63. ) + ':' + str(value[2])
  64. elif control in ('mode', 'style', 'shading'):
  65. if 'mode' not in data['draw']:
  66. data['draw']['mode'] = {}
  67. continue
  68. data['draw'][control] = {'value': value}
  69. data['draw'][control]['update'] = None
  70. value, desc = self.GetDrawMode(
  71. UserSettings.Get(
  72. group='nviz', key='surface', subkey=[
  73. 'draw', 'mode']), UserSettings.Get(
  74. group='nviz', key='surface', subkey=[
  75. 'draw', 'style']), UserSettings.Get(
  76. group='nviz', key='surface', subkey=[
  77. 'draw', 'shading']))
  78. data['draw']['mode'] = {'value': value,
  79. 'desc': desc,
  80. 'update': None}
  81. # position
  82. for coord in ('x', 'y', 'z'):
  83. data['position'][coord] = UserSettings.Get(
  84. group='nviz', key='surface', subkey=['position', coord])
  85. data['position']['update'] = None
  86. return data
  87. def SetVolumeDefaultProp(self):
  88. """Set default volume data properties"""
  89. data = dict()
  90. for sec in ('attribute', 'draw', 'position'):
  91. data[sec] = dict()
  92. for sec in ('isosurface', 'slice'):
  93. data[sec] = list()
  94. #
  95. # draw
  96. #
  97. for control, value in six.iteritems(UserSettings.Get(group='nviz',
  98. key='volume',
  99. subkey='draw')):
  100. if control == 'shading':
  101. sel = UserSettings.Get(
  102. group='nviz', key='volume', subkey=[
  103. 'draw', 'shading'])
  104. value, desc = self.GetDrawMode(shade=sel, string=False)
  105. data['draw']['shading'] = {}
  106. data['draw']['shading']['isosurface'] = {
  107. 'value': value, 'desc': desc['shading']}
  108. data['draw']['shading']['slice'] = {'value': value,
  109. 'desc': desc['shading']}
  110. elif control == 'mode':
  111. sel = UserSettings.Get(
  112. group='nviz', key='volume', subkey=[
  113. 'draw', 'mode'])
  114. if sel == 0:
  115. desc = 'isosurface'
  116. else:
  117. desc = 'slice'
  118. data['draw']['mode'] = {'value': sel,
  119. 'desc': desc, }
  120. elif control == 'box':
  121. box = UserSettings.Get(
  122. group='nviz', key='volume', subkey=[
  123. 'draw', 'box'])
  124. data['draw']['box'] = {'enabled': box}
  125. else:
  126. data['draw'][control] = {}
  127. data['draw'][control]['isosurface'] = {'value': value}
  128. data['draw'][control]['slice'] = {'value': value}
  129. if 'update' not in data['draw'][control]:
  130. data['draw'][control]['update'] = None
  131. #
  132. # isosurface attributes
  133. #
  134. for attrb in ('shine', ):
  135. data['attribute'][attrb] = {}
  136. for key, value in six.iteritems(UserSettings.Get(group='nviz',
  137. key='volume',
  138. subkey=attrb)):
  139. data['attribute'][attrb][key] = value
  140. return data
  141. def SetIsosurfaceDefaultProp(self):
  142. """Set default isosurface properties"""
  143. data = dict()
  144. for attr in ('shine', 'topo', 'transp', 'color', 'inout'):
  145. data[attr] = {}
  146. data[attr]['update'] = None
  147. if attr == 'inout':
  148. data[attr]['value'] = 0
  149. continue
  150. for key, value in six.iteritems(UserSettings.Get(group='nviz',
  151. key='volume',
  152. subkey=attr)):
  153. data[attr][key] = value
  154. return data
  155. def SetSliceDefaultProp(self):
  156. """Set default slice properties"""
  157. data = dict()
  158. data['position'] = copy.deepcopy(
  159. UserSettings.Get(
  160. group='nviz',
  161. key='volume',
  162. subkey='slice_position'))
  163. data['position']['update'] = None
  164. data['transp'] = copy.deepcopy(
  165. UserSettings.Get(
  166. group='nviz',
  167. key='volume',
  168. subkey='transp'))
  169. return data
  170. def SetVectorDefaultProp(self, longDim, data=None):
  171. """Set default vector data properties"""
  172. if not data:
  173. data = dict()
  174. for sec in ('lines', 'points'):
  175. data[sec] = {}
  176. self.SetVectorLinesDefaultProp(data['lines'])
  177. self.SetVectorPointsDefaultProp(data['points'], longDim)
  178. return data
  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. # color
  185. value = UserSettings.Get(group='nviz', key='vector',
  186. subkey=['lines', 'color'])
  187. color = str(value[0]) + ':' + str(value[1]) + ':' + str(value[2])
  188. data['color'] = {'value': color}
  189. # mode
  190. if UserSettings.Get(group='nviz', key='vector',
  191. subkey=['lines', 'flat']):
  192. type = 'flat'
  193. else:
  194. type = 'surface'
  195. data['mode'] = {}
  196. data['mode']['type'] = type
  197. data['mode']['update'] = None
  198. # height
  199. data['height'] = {
  200. 'value': UserSettings.Get(
  201. group='nviz',
  202. key='vector',
  203. subkey=[
  204. 'lines',
  205. 'height'])}
  206. # thematic
  207. data['thematic'] = {'rgbcolumn': UserSettings.Get(group='nviz', key='vector',
  208. subkey=['lines', 'rgbcolumn']),
  209. 'sizecolumn': UserSettings.Get(group='nviz', key='vector',
  210. subkey=['lines', 'sizecolumn']),
  211. 'layer': 1,
  212. 'usecolor': False,
  213. 'usewidth': False}
  214. if 'object' in data:
  215. for attrb in ('color', 'width', 'mode', 'height', 'thematic'):
  216. data[attrb]['update'] = None
  217. def SetVectorPointsDefaultProp(self, data, longDim):
  218. """Set default vector properties -- points"""
  219. size_fraction = 0.005
  220. # size
  221. autosize = UserSettings.Get(group='nviz', key='vector',
  222. subkey=['points', 'autosize'])
  223. if autosize:
  224. data['size'] = {'value': longDim * size_fraction}
  225. else:
  226. data['size'] = {'value': UserSettings.Get(group='nviz', key='vector',
  227. subkey=['points', 'size'])}
  228. # width
  229. data['width'] = {'value': UserSettings.Get(group='nviz', key='vector',
  230. subkey=['points', 'width'])}
  231. # marker
  232. data['marker'] = {
  233. 'value': UserSettings.Get(
  234. group='nviz',
  235. key='vector',
  236. subkey=[
  237. 'points',
  238. 'marker'])}
  239. # color
  240. value = UserSettings.Get(group='nviz', key='vector',
  241. subkey=['points', 'color'])
  242. color = str(value[0]) + ':' + str(value[1]) + ':' + str(value[2])
  243. data['color'] = {'value': color}
  244. # mode
  245. data['mode'] = {'type': 'surface'}
  246. # 'surface' : '', }
  247. # height
  248. data['height'] = {
  249. 'value': UserSettings.Get(
  250. group='nviz',
  251. key='vector',
  252. subkey=[
  253. 'points',
  254. 'height'])}
  255. data['thematic'] = {
  256. 'rgbcolumn': UserSettings.Get(
  257. group='nviz',
  258. key='vector',
  259. subkey=[
  260. 'points',
  261. 'rgbcolumn']),
  262. 'sizecolumn': UserSettings.Get(
  263. group='nviz',
  264. key='vector',
  265. subkey=[
  266. 'points',
  267. 'sizecolumn']),
  268. 'layer': 1,
  269. 'usecolor': False,
  270. 'usesize': False}
  271. if 'object' in data:
  272. for attrb in ('size', 'width', 'marker',
  273. 'color', 'height', 'thematic'):
  274. data[attrb]['update'] = None
  275. def GetDrawMode(self, mode=None, style=None, shade=None, string=False):
  276. """Get surface draw mode (value) from description/selection
  277. :param mode:
  278. :param style:
  279. :param shade:
  280. :param string: if True input parameters are strings otherwise
  281. selections
  282. """
  283. if not wxnviz:
  284. return None
  285. value = 0
  286. desc = {}
  287. if string:
  288. if mode is not None:
  289. if mode == 'coarse':
  290. value |= wxnviz.DM_WIRE
  291. elif mode == 'fine':
  292. value |= wxnviz.DM_POLY
  293. else: # both
  294. value |= wxnviz.DM_WIRE_POLY
  295. if style is not None:
  296. if style == 'wire':
  297. value |= wxnviz.DM_GRID_WIRE
  298. else: # surface
  299. value |= wxnviz.DM_GRID_SURF
  300. if shade is not None:
  301. if shade == 'flat':
  302. value |= wxnviz.DM_FLAT
  303. else: # surface
  304. value |= wxnviz.DM_GOURAUD
  305. return value
  306. # -> string is False
  307. if mode is not None:
  308. if mode == 0: # coarse
  309. value |= wxnviz.DM_WIRE
  310. desc['mode'] = 'coarse'
  311. elif mode == 1: # fine
  312. value |= wxnviz.DM_POLY
  313. desc['mode'] = 'fine'
  314. else: # both
  315. value |= wxnviz.DM_WIRE_POLY
  316. desc['mode'] = 'both'
  317. if style is not None:
  318. if style == 0: # wire
  319. value |= wxnviz.DM_GRID_WIRE
  320. desc['style'] = 'wire'
  321. else: # surface
  322. value |= wxnviz.DM_GRID_SURF
  323. desc['style'] = 'surface'
  324. if shade is not None:
  325. if shade == 0:
  326. value |= wxnviz.DM_FLAT
  327. desc['shading'] = 'flat'
  328. else: # surface
  329. value |= wxnviz.DM_GOURAUD
  330. desc['shading'] = 'gouraud'
  331. return (value, desc)
  332. def SetDecorDefaultProp(self, type):
  333. """Set default arrow properties
  334. """
  335. data = {}
  336. # arrow
  337. if type == 'arrow':
  338. data['arrow'] = copy.deepcopy(UserSettings.Get(group='nviz',
  339. key='arrow'))
  340. data['arrow']['color'] = "%d:%d:%d" % (
  341. UserSettings.Get(group='nviz', key='arrow',
  342. subkey='color')[:3])
  343. data['arrow'].update(
  344. copy.deepcopy(
  345. UserSettings.Get(
  346. group='nviz',
  347. key='arrow',
  348. settings_type='internal')))
  349. data['arrow']['show'] = False
  350. # arrow
  351. if type == 'scalebar':
  352. data['scalebar'] = copy.deepcopy(UserSettings.Get(group='nviz',
  353. key='scalebar'))
  354. data['scalebar']['color'] = "%d:%d:%d" % (
  355. UserSettings.Get(group='nviz', key='scalebar',
  356. subkey='color')[:3])
  357. data['scalebar'].update(
  358. copy.deepcopy(
  359. UserSettings.Get(
  360. group='nviz',
  361. key='scalebar',
  362. settings_type='internal')))
  363. data['scalebar']['id'] = 0
  364. return data