workspace.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. try:
  14. import nviz.wxnviz as wxnviz
  15. except ImportError:
  16. wxnviz = None
  17. class NvizSettings(object):
  18. def __init__(self):
  19. """Default 3D settings"""
  20. UserSettings.Reset('nviz')
  21. UserSettings.ReadSettingsFile()
  22. def SetConstantDefaultProp(self):
  23. """Set default constant data properties"""
  24. data = dict()
  25. for key, value in UserSettings.Get(group='nviz', key='constant').iteritems():
  26. data[key] = value
  27. color = str(data['color'][0]) + ':' + str(data['color'][1]) + ':' + str(data['color'][2])
  28. data['color'] = color
  29. return data
  30. def SetSurfaceDefaultProp(self, data = None):
  31. """Set default surface data properties"""
  32. if not data:
  33. data = dict()
  34. for sec in ('attribute', 'draw', 'mask', 'position'):
  35. data[sec] = {}
  36. #
  37. # attributes
  38. #
  39. for attrb in ('shine', ):
  40. data['attribute'][attrb] = {}
  41. for key, value in UserSettings.Get(group='nviz', key='surface',
  42. subkey=attrb).iteritems():
  43. data['attribute'][attrb][key] = value
  44. data['attribute'][attrb]['update'] = None
  45. #
  46. # draw
  47. #
  48. data['draw']['all'] = False # apply only for current surface
  49. for control, value in UserSettings.Get(group='nviz', key='surface', 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. else:
  104. data['draw'][control] = {}
  105. data['draw'][control]['isosurface'] = { 'value' : value }
  106. data['draw'][control]['slice'] = { 'value' : value }
  107. if 'update' not in data['draw'][control]:
  108. data['draw'][control]['update'] = None
  109. #
  110. # isosurface attributes
  111. #
  112. for attrb in ('shine', ):
  113. data['attribute'][attrb] = {}
  114. for key, value in UserSettings.Get(group='nviz', key='volume',
  115. subkey=attrb).iteritems():
  116. data['attribute'][attrb][key] = value
  117. return data
  118. def SetIsosurfaceDefaultProp(self):
  119. """!Set default isosurface properties"""
  120. data = dict()
  121. for attr in ('shine', 'topo', 'transp', 'color'):
  122. data[attr] = {}
  123. for key, value in UserSettings.Get(group = 'nviz', key = 'volume',
  124. subkey = attr).iteritems():
  125. data[attr][key] = value
  126. data[attr]['update'] = None
  127. return data
  128. def SetSliceDefaultProp(self):
  129. """!Set default slice properties"""
  130. data = dict()
  131. data['position'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'volume',
  132. subkey = 'slice_position'))
  133. data['position']['update'] = None
  134. data['transp'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'volume',
  135. subkey = 'transp'))
  136. return data
  137. def SetVectorDefaultProp(self, data = None):
  138. """Set default vector data properties"""
  139. if not data:
  140. data = dict()
  141. for sec in ('lines', 'points'):
  142. data[sec] = {}
  143. self.SetVectorLinesDefaultProp(data['lines'])
  144. self.SetVectorPointsDefaultProp(data['points'])
  145. return data
  146. def SetVectorLinesDefaultProp(self, data):
  147. """Set default vector properties -- lines"""
  148. # width
  149. data['width'] = {'value' : UserSettings.Get(group='nviz', key='vector',
  150. subkey=['lines', 'width']) }
  151. # color
  152. value = UserSettings.Get(group='nviz', key='vector',
  153. subkey=['lines', 'color'])
  154. color = str(value[0]) + ':' + str(value[1]) + ':' + str(value[2])
  155. data['color'] = { 'value' : color }
  156. # mode
  157. if UserSettings.Get(group='nviz', key='vector',
  158. subkey=['lines', 'flat']):
  159. type = 'flat'
  160. else:
  161. type = 'surface'
  162. data['mode'] = {}
  163. data['mode']['type'] = type
  164. data['mode']['update'] = None
  165. # height
  166. data['height'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
  167. subkey=['lines', 'height']) }
  168. # thematic
  169. data['thematic'] = {'rgbcolumn' : UserSettings.Get(group='nviz', key='vector',
  170. subkey=['lines', 'rgbcolumn']),
  171. 'sizecolumn' : UserSettings.Get(group='nviz', key='vector',
  172. subkey=['lines', 'sizecolumn']),
  173. 'layer': 1,
  174. 'usecolor' : False,
  175. 'usewidth' : False}
  176. if 'object' in data:
  177. for attrb in ('color', 'width', 'mode', 'height', 'thematic'):
  178. data[attrb]['update'] = None
  179. def SetVectorPointsDefaultProp(self, data):
  180. """Set default vector properties -- points"""
  181. # size
  182. data['size'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
  183. subkey=['points', 'size']) }
  184. # width
  185. data['width'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
  186. subkey=['points', 'width']) }
  187. # marker
  188. data['marker'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
  189. subkey=['points', 'marker']) }
  190. # color
  191. value = UserSettings.Get(group='nviz', key='vector',
  192. subkey=['points', 'color'])
  193. color = str(value[0]) + ':' + str(value[1]) + ':' + str(value[2])
  194. data['color'] = { 'value' : color }
  195. # mode
  196. data['mode'] = { 'type' : 'surface'}
  197. ## 'surface' : '', }
  198. # height
  199. data['height'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
  200. subkey=['points', 'height']) }
  201. data['thematic'] = {'rgbcolumn' : UserSettings.Get(group='nviz', key='vector',
  202. subkey=['points', 'rgbcolumn']),
  203. 'sizecolumn' : UserSettings.Get(group='nviz', key='vector',
  204. subkey=['points', 'sizecolumn']),
  205. 'layer': 1,
  206. 'usecolor' : False,
  207. 'usesize' : False}
  208. if 'object' in data:
  209. for attrb in ('size', 'width', 'marker',
  210. 'color', 'height', 'thematic'):
  211. data[attrb]['update'] = None
  212. def GetDrawMode(self, mode=None, style=None, shade=None, string=False):
  213. """Get surface draw mode (value) from description/selection
  214. @param mode,style,shade modes
  215. @param string if True input parameters are strings otherwise
  216. selections
  217. """
  218. if not wxnviz:
  219. return None
  220. value = 0
  221. desc = {}
  222. if string:
  223. if mode is not None:
  224. if mode == 'coarse':
  225. value |= wxnviz.DM_WIRE
  226. elif mode == 'fine':
  227. value |= wxnviz.DM_POLY
  228. else: # both
  229. value |= wxnviz.DM_WIRE_POLY
  230. if style is not None:
  231. if style == 'wire':
  232. value |= wxnviz.DM_GRID_WIRE
  233. else: # surface
  234. value |= wxnviz.DM_GRID_SURF
  235. if shade is not None:
  236. if shade == 'flat':
  237. value |= wxnviz.DM_FLAT
  238. else: # surface
  239. value |= wxnviz.DM_GOURAUD
  240. return value
  241. # -> string is False
  242. if mode is not None:
  243. if mode == 0: # coarse
  244. value |= wxnviz.DM_WIRE
  245. desc['mode'] = 'coarse'
  246. elif mode == 1: # fine
  247. value |= wxnviz.DM_POLY
  248. desc['mode'] = 'fine'
  249. else: # both
  250. value |= wxnviz.DM_WIRE_POLY
  251. desc['mode'] = 'both'
  252. if style is not None:
  253. if style == 0: # wire
  254. value |= wxnviz.DM_GRID_WIRE
  255. desc['style'] = 'wire'
  256. else: # surface
  257. value |= wxnviz.DM_GRID_SURF
  258. desc['style'] = 'surface'
  259. if shade is not None:
  260. if shade == 0:
  261. value |= wxnviz.DM_FLAT
  262. desc['shading'] = 'flat'
  263. else: # surface
  264. value |= wxnviz.DM_GOURAUD
  265. desc['shading'] = 'gouraud'
  266. return (value, desc)
  267. def SetDecorDefaultProp(self, type):
  268. """!Set default arrow properties
  269. """
  270. data = {}
  271. # arrow
  272. if type == 'arrow':
  273. data['arrow'] = UserSettings.Get(group = 'nviz', key = 'arrow')
  274. data['arrow']['color'] = "%d:%d:%d" % (
  275. UserSettings.Get(group = 'nviz', key = 'arrow', subkey = 'color')[:3])
  276. data['arrow'].update(UserSettings.Get(group = 'nviz', key = 'arrow', internal = True))
  277. data['arrow']['show'] = False
  278. # arrow
  279. if type == 'scalebar':
  280. data['scalebar'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'scalebar'))
  281. data['scalebar']['color'] = "%d:%d:%d" % (
  282. UserSettings.Get(group = 'nviz', key = 'scalebar', subkey = 'color')[:3])
  283. data['scalebar'].update(copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'scalebar', internal = True)))
  284. data['scalebar']['id'] = 0
  285. return data