workspace.py 15 KB

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