workspace.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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, longDim, 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'], longDim)
  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, longDim):
  213. """Set default vector properties -- points"""
  214. size_fraction = 0.005
  215. # size
  216. autosize = UserSettings.Get(group='nviz', key='vector',
  217. subkey=['points', 'autosize'])
  218. if autosize:
  219. data['size'] = {'value': longDim * size_fraction}
  220. else:
  221. data['size'] = {'value': UserSettings.Get(group='nviz', key='vector',
  222. subkey=['points', 'size'])}
  223. # width
  224. data['width'] = {'value': UserSettings.Get(group='nviz', key='vector',
  225. subkey=['points', 'width'])}
  226. # marker
  227. data['marker'] = {
  228. 'value': UserSettings.Get(
  229. group='nviz',
  230. key='vector',
  231. subkey=[
  232. 'points',
  233. 'marker'])}
  234. # color
  235. value = UserSettings.Get(group='nviz', key='vector',
  236. subkey=['points', 'color'])
  237. color = str(value[0]) + ':' + str(value[1]) + ':' + str(value[2])
  238. data['color'] = {'value': color}
  239. # mode
  240. data['mode'] = {'type': 'surface'}
  241. # 'surface' : '', }
  242. # height
  243. data['height'] = {
  244. 'value': UserSettings.Get(
  245. group='nviz',
  246. key='vector',
  247. subkey=[
  248. 'points',
  249. 'height'])}
  250. data['thematic'] = {
  251. 'rgbcolumn': UserSettings.Get(
  252. group='nviz',
  253. key='vector',
  254. subkey=[
  255. 'points',
  256. 'rgbcolumn']),
  257. 'sizecolumn': UserSettings.Get(
  258. group='nviz',
  259. key='vector',
  260. subkey=[
  261. 'points',
  262. 'sizecolumn']),
  263. 'layer': 1,
  264. 'usecolor': False,
  265. 'usesize': False}
  266. if 'object' in data:
  267. for attrb in ('size', 'width', 'marker',
  268. 'color', 'height', 'thematic'):
  269. data[attrb]['update'] = None
  270. def GetDrawMode(self, mode=None, style=None, shade=None, string=False):
  271. """Get surface draw mode (value) from description/selection
  272. :param mode:
  273. :param style:
  274. :param shade:
  275. :param string: if True input parameters are strings otherwise
  276. selections
  277. """
  278. if not wxnviz:
  279. return None
  280. value = 0
  281. desc = {}
  282. if string:
  283. if mode is not None:
  284. if mode == 'coarse':
  285. value |= wxnviz.DM_WIRE
  286. elif mode == 'fine':
  287. value |= wxnviz.DM_POLY
  288. else: # both
  289. value |= wxnviz.DM_WIRE_POLY
  290. if style is not None:
  291. if style == 'wire':
  292. value |= wxnviz.DM_GRID_WIRE
  293. else: # surface
  294. value |= wxnviz.DM_GRID_SURF
  295. if shade is not None:
  296. if shade == 'flat':
  297. value |= wxnviz.DM_FLAT
  298. else: # surface
  299. value |= wxnviz.DM_GOURAUD
  300. return value
  301. # -> string is False
  302. if mode is not None:
  303. if mode == 0: # coarse
  304. value |= wxnviz.DM_WIRE
  305. desc['mode'] = 'coarse'
  306. elif mode == 1: # fine
  307. value |= wxnviz.DM_POLY
  308. desc['mode'] = 'fine'
  309. else: # both
  310. value |= wxnviz.DM_WIRE_POLY
  311. desc['mode'] = 'both'
  312. if style is not None:
  313. if style == 0: # wire
  314. value |= wxnviz.DM_GRID_WIRE
  315. desc['style'] = 'wire'
  316. else: # surface
  317. value |= wxnviz.DM_GRID_SURF
  318. desc['style'] = 'surface'
  319. if shade is not None:
  320. if shade == 0:
  321. value |= wxnviz.DM_FLAT
  322. desc['shading'] = 'flat'
  323. else: # surface
  324. value |= wxnviz.DM_GOURAUD
  325. desc['shading'] = 'gouraud'
  326. return (value, desc)
  327. def SetDecorDefaultProp(self, type):
  328. """Set default arrow properties
  329. """
  330. data = {}
  331. # arrow
  332. if type == 'arrow':
  333. data['arrow'] = copy.deepcopy(UserSettings.Get(group='nviz',
  334. key='arrow'))
  335. data['arrow']['color'] = "%d:%d:%d" % (
  336. UserSettings.Get(group='nviz', key='arrow',
  337. subkey='color')[:3])
  338. data['arrow'].update(
  339. copy.deepcopy(
  340. UserSettings.Get(
  341. group='nviz',
  342. key='arrow',
  343. settings_type='internal')))
  344. data['arrow']['show'] = False
  345. # arrow
  346. if type == 'scalebar':
  347. data['scalebar'] = copy.deepcopy(UserSettings.Get(group='nviz',
  348. key='scalebar'))
  349. data['scalebar']['color'] = "%d:%d:%d" % (
  350. UserSettings.Get(group='nviz', key='scalebar',
  351. subkey='color')[:3])
  352. data['scalebar'].update(
  353. copy.deepcopy(
  354. UserSettings.Get(
  355. group='nviz',
  356. key='scalebar',
  357. settings_type='internal')))
  358. data['scalebar']['id'] = 0
  359. return data