workspace.py 14 KB

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