nviz_tools.py 108 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677
  1. """
  2. @package nviz_tools.py
  3. @brief Nviz tools window
  4. Classes:
  5. - NvizToolWindow
  6. - ViewPositionWindow
  7. (C) 2008-2009 by the GRASS Development Team
  8. This program is free software under the GNU General Public
  9. License (>=v2). Read the file COPYING that comes with GRASS
  10. for details.
  11. @author Martin Landa <landa.martin gmail.com> (Google SoC 2008)
  12. """
  13. import os
  14. import sys
  15. import copy
  16. import wx
  17. import wx.lib.colourselect as csel
  18. import globalvar
  19. import gselect
  20. import gcmd
  21. from preferences import globalSettings as UserSettings
  22. from nviz_mapdisp import wxUpdateView as wxUpdateView
  23. from nviz_mapdisp import wxUpdateProperties as wxUpdateProperties
  24. sys.path.append(os.path.join(globalvar.ETCWXDIR, "nviz"))
  25. import grass7_wxnviz as wxnviz
  26. class NvizToolWindow(wx.Frame):
  27. """!Experimental window for Nviz tools
  28. @todo integrate with Map display
  29. """
  30. def __init__(self, parent=None, id=wx.ID_ANY, title=_("Nviz tools"),
  31. pos=wx.DefaultPosition, size=wx.DefaultSize,
  32. mapWindow=None,
  33. style=wx.CAPTION|wx.MINIMIZE_BOX|wx.RESIZE_BORDER):
  34. self.parent = parent # MapFrame
  35. self.lmgr = self.parent.GetLayerManager() # GMFrame
  36. self.mapWindow = mapWindow
  37. wx.Frame.__init__(self, parent, id, title, pos, size, style)
  38. #
  39. # icon
  40. #
  41. self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass_nviz.ico'), wx.BITMAP_TYPE_ICO))
  42. #
  43. # dialog body
  44. #
  45. mainSizer = wx.BoxSizer(wx.VERTICAL)
  46. self.win = {} # window ids
  47. #
  48. # notebook
  49. #
  50. self.notebook = wx.Notebook(parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
  51. self.page = {}
  52. # view page
  53. self.__createViewPage()
  54. self.page['view'] = { 'id' : 0 }
  55. # surface page
  56. size = self.__createSurfacePage()
  57. size = (size[0] + 25, size[0] + 20)
  58. # vector page
  59. self.__createVectorPage()
  60. # volume page
  61. self.__createVolumePage()
  62. # settings page
  63. self.__createSettingsPage()
  64. self.page['settings'] = { 'id' : 1 }
  65. self.UpdatePage('settings')
  66. self.pageChanging = False
  67. mainSizer.Add(item=self.notebook, proportion=1,
  68. flag=wx.EXPAND | wx.ALL, border=5)
  69. #
  70. # bindings
  71. #
  72. self.Bind(wx.EVT_CLOSE, self.OnClose)
  73. self.notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
  74. #
  75. # layout
  76. #
  77. self.SetSizer(mainSizer)
  78. mainSizer.Fit(self)
  79. self.SetSize(size)
  80. def OnPageChanged(self, event):
  81. new = event.GetSelection()
  82. self.notebook.ChangeSelection(new)
  83. def PostViewEvent(self, zExag=False):
  84. """!Change view settings"""
  85. event = wxUpdateView(zExag=zExag)
  86. wx.PostEvent(self.mapWindow, event)
  87. def __createViewPage(self):
  88. """!Create view settings page"""
  89. panel = wx.Panel(parent=self.notebook, id=wx.ID_ANY)
  90. self.notebook.AddPage(page=panel,
  91. text=" %s " % _("View"))
  92. pageSizer = wx.BoxSizer(wx.VERTICAL)
  93. gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
  94. self.win['view'] = {}
  95. # position
  96. posSizer = wx.GridBagSizer(vgap=3, hgap=3)
  97. posSizer.Add(item=wx.StaticText(panel, id=wx.ID_ANY, label=_("W")),
  98. pos=(1, 0), flag=wx.ALIGN_CENTER)
  99. posSizer.Add(item=wx.StaticText(panel, id=wx.ID_ANY, label=_("N")),
  100. pos=(0, 1), flag=wx.ALIGN_CENTER | wx.ALIGN_BOTTOM)
  101. viewPos = ViewPositionWindow(panel, id=wx.ID_ANY, size=(175, 175),
  102. mapwindow=self.mapWindow)
  103. self.win['view']['pos'] = viewPos.GetId()
  104. posSizer.Add(item=viewPos,
  105. pos=(1, 1), flag=wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
  106. posSizer.Add(item=wx.StaticText(panel, id=wx.ID_ANY, label=_("S")),
  107. pos=(2, 1), flag=wx.ALIGN_CENTER | wx.ALIGN_TOP)
  108. posSizer.Add(item=wx.StaticText(panel, id=wx.ID_ANY, label=_("E")),
  109. pos=(1, 2), flag=wx.ALIGN_CENTER)
  110. gridSizer.Add(item=posSizer, pos=(0, 0))
  111. # perspective
  112. range = UserSettings.Get(group='nviz', key='view', subkey='persp', internal=True)
  113. self.CreateControl(panel, dict=self.win['view'], name='persp',
  114. range=(range['min'], range['max']),
  115. bind=(self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
  116. gridSizer.Add(item=wx.StaticText(panel, id=wx.ID_ANY, label=_("Perspective:")),
  117. pos=(1, 0), flag=wx.ALIGN_CENTER)
  118. gridSizer.Add(item=self.FindWindowById(self.win['view']['persp']['slider']), pos=(2, 0))
  119. gridSizer.Add(item=self.FindWindowById(self.win['view']['persp']['spin']), pos=(3, 0),
  120. flag=wx.ALIGN_CENTER)
  121. # twist
  122. range = UserSettings.Get(group='nviz', key='view', subkey='twist', internal=True)
  123. self.CreateControl(panel, dict=self.win['view'], name='twist',
  124. range=(range['min'], range['max']),
  125. bind=(self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
  126. gridSizer.Add(item=wx.StaticText(panel, id=wx.ID_ANY, label=_("Twist:")),
  127. pos=(1, 1), flag=wx.ALIGN_CENTER)
  128. gridSizer.Add(item=self.FindWindowById(self.win['view']['twist']['slider']), pos=(2, 1))
  129. gridSizer.Add(item=self.FindWindowById(self.win['view']['twist']['spin']), pos=(3, 1),
  130. flag=wx.ALIGN_CENTER)
  131. # height + z-exag
  132. self.CreateControl(panel, dict=self.win['view'], name='height', sliderHor=False,
  133. range=(0, 1),
  134. bind=(self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
  135. self.CreateControl(panel, dict=self.win['view'], name='z-exag', sliderHor=False,
  136. range=(0, 1),
  137. bind=(self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
  138. heightSizer = wx.GridBagSizer(vgap=3, hgap=3)
  139. heightSizer.Add(item=wx.StaticText(panel, id=wx.ID_ANY, label=_("Height:")),
  140. pos=(0, 0), flag=wx.ALIGN_LEFT, span=(1, 2))
  141. heightSizer.Add(item=self.FindWindowById(self.win['view']['height']['slider']),
  142. flag=wx.ALIGN_RIGHT, pos=(1, 0))
  143. heightSizer.Add(item=self.FindWindowById(self.win['view']['height']['spin']),
  144. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
  145. wx.BOTTOM | wx.RIGHT, pos=(1, 1))
  146. heightSizer.Add(item=wx.StaticText(panel, id=wx.ID_ANY, label=_("Z-exag:")),
  147. pos=(0, 2), flag=wx.ALIGN_LEFT, span=(1, 2))
  148. heightSizer.Add(item=self.FindWindowById(self.win['view']['z-exag']['slider']),
  149. flag=wx.ALIGN_RIGHT, pos=(1, 2))
  150. heightSizer.Add(item=self.FindWindowById(self.win['view']['z-exag']['spin']),
  151. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
  152. wx.BOTTOM | wx.RIGHT, pos=(1, 3))
  153. gridSizer.Add(item=heightSizer, pos=(0, 1), flag=wx.ALIGN_RIGHT)
  154. # view setup + reset
  155. viewSizer = wx.BoxSizer(wx.HORIZONTAL)
  156. viewSizer.Add(item=wx.StaticText(panel, id=wx.ID_ANY,
  157. label=_("Look at:")),
  158. flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=5)
  159. viewType = wx.Choice (parent=panel, id=wx.ID_ANY, size=(125, -1),
  160. choices = [_("top"),
  161. _("north"),
  162. _("south"),
  163. _("east"),
  164. _("west"),
  165. _("north-west"),
  166. _("north-east"),
  167. _("south-east"),
  168. _("south-west")])
  169. viewType.SetSelection(0)
  170. viewType.Bind(wx.EVT_CHOICE, self.OnLookAt)
  171. # self.win['lookAt'] = viewType.GetId()
  172. viewSizer.Add(item=viewType, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
  173. border=5)
  174. reset = wx.Button(panel, id=wx.ID_ANY, label=_("Reset"))
  175. reset.SetToolTipString(_("Reset to default view"))
  176. # self.win['reset'] = reset.GetId()
  177. reset.Bind(wx.EVT_BUTTON, self.OnResetView)
  178. viewSizer.Add(item=reset, proportion=1,
  179. flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT,
  180. border=5)
  181. gridSizer.AddGrowableCol(3)
  182. gridSizer.Add(item=viewSizer, pos=(4, 0), span=(1, 2),
  183. flag=wx.EXPAND)
  184. # body
  185. pageSizer.Add(item=gridSizer, proportion=1,
  186. flag=wx.EXPAND | wx.ALL,
  187. border=5)
  188. panel.SetSizer(pageSizer)
  189. return panel.GetBestSize()
  190. def __createSurfacePage(self):
  191. """!Create view settings page"""
  192. panel = wx.Panel(parent=self.notebook, id=wx.ID_ANY)
  193. self.page['surface'] = {}
  194. self.page['surface']['id'] = -1
  195. self.page['surface']['panel'] = panel.GetId()
  196. # panel = scrolled.ScrolledPanel(parent=self.notebook, id=wx.ID_ANY)
  197. # panel.SetupScrolling(scroll_x=True, scroll_y=True)
  198. pageSizer = wx.BoxSizer(wx.VERTICAL)
  199. self.win['surface'] = {}
  200. #
  201. # surface attributes
  202. #
  203. box = wx.StaticBox (parent=panel, id=wx.ID_ANY,
  204. label=" %s " % (_("Surface attributes")))
  205. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  206. gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
  207. # type
  208. self.win['surface']['attr'] = {}
  209. row = 0
  210. for code, attrb in (('topo', _("Topography")),
  211. ('color', _("Color")),
  212. ('mask', _("Mask")),
  213. ('transp', _("Transparency")),
  214. ('shine', _("Shininess")),
  215. ('emit', _("Emission"))):
  216. self.win['surface'][code] = {}
  217. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  218. label=attrb + ':'),
  219. pos=(row, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  220. use = wx.Choice (parent=panel, id=wx.ID_ANY, size=(100, -1),
  221. choices = [_("map")])
  222. if code not in ('topo', 'color', 'shine'):
  223. use.Insert(item=_("unset"), pos=0)
  224. self.win['surface'][code]['required'] = False
  225. else:
  226. self.win['surface'][code]['required'] = True
  227. if code != 'mask':
  228. use.Append(item=_('constant'))
  229. self.win['surface'][code]['use'] = use.GetId()
  230. use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
  231. gridSizer.Add(item=use, flag=wx.ALIGN_CENTER_VERTICAL,
  232. pos=(row, 1))
  233. map = gselect.Select(parent=panel, id=wx.ID_ANY,
  234. # size=globalvar.DIALOG_GSELECT_SIZE,
  235. size=(200, -1),
  236. type="raster")
  237. self.win['surface'][code]['map'] = map.GetId() - 1 # FIXME
  238. map.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
  239. # changing map topography not allowed
  240. if code == 'topo':
  241. map.Enable(False)
  242. gridSizer.Add(item=map, flag=wx.ALIGN_CENTER_VERTICAL,
  243. pos=(row, 2))
  244. if code == 'color':
  245. value = csel.ColourSelect(panel, id=wx.ID_ANY,
  246. colour=UserSettings.Get(group='nviz', key='surface',
  247. subkey=['color', 'value']))
  248. value.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceMap)
  249. elif code == 'mask':
  250. value = None
  251. else:
  252. value = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  253. initial=0)
  254. if code == 'topo':
  255. value.SetRange(minVal=-1e9, maxVal=1e9)
  256. elif code in ('shine', 'transp', 'emit'):
  257. value.SetRange(minVal=0, maxVal=255)
  258. else:
  259. value.SetRange(minVal=0, maxVal=100)
  260. value.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
  261. if value:
  262. self.win['surface'][code]['const'] = value.GetId()
  263. value.Enable(False)
  264. gridSizer.Add(item=value, flag=wx.ALIGN_CENTER_VERTICAL,
  265. pos=(row, 3))
  266. else:
  267. self.win['surface'][code]['const'] = None
  268. self.SetMapObjUseMap(nvizType='surface',
  269. attrb=code) # -> enable map / disable constant
  270. row += 1
  271. boxSizer.Add(item=gridSizer, proportion=1,
  272. flag=wx.ALL | wx.EXPAND, border=3)
  273. pageSizer.Add(item=boxSizer, proportion=0,
  274. flag=wx.EXPAND | wx.ALL,
  275. border=5)
  276. #
  277. # draw
  278. #
  279. self.win['surface']['draw'] = {}
  280. box = wx.StaticBox (parent=panel, id=wx.ID_ANY,
  281. label=" %s " % (_("Draw")))
  282. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  283. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  284. gridSizer.AddGrowableCol(4)
  285. # mode
  286. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  287. label=_("Mode:")),
  288. pos=(0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  289. mode = wx.Choice (parent=panel, id=wx.ID_ANY, size=(100, -1),
  290. choices = [_("coarse"),
  291. _("fine"),
  292. _("both")])
  293. mode.SetSelection(0)
  294. mode.SetName("selection")
  295. mode.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  296. self.win['surface']['draw']['mode'] = mode.GetId()
  297. gridSizer.Add(item=mode, flag=wx.ALIGN_CENTER_VERTICAL,
  298. pos=(0, 1))
  299. # resolution (mode)
  300. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  301. label=_("Resolution:")),
  302. pos=(0, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  303. resSizer = wx.BoxSizer(wx.HORIZONTAL)
  304. resSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  305. label=_("coarse:")),
  306. flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=3)
  307. resC = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  308. initial=1,
  309. min=1,
  310. max=100)
  311. resC.SetName("value")
  312. self.win['surface']['draw']['res-coarse'] = resC.GetId()
  313. resC.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
  314. resSizer.Add(item=resC, flag=wx.ALL, border=3)
  315. resSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  316. label=_("fine:")),
  317. flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=3)
  318. resF = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  319. initial=1,
  320. min=1,
  321. max=100)
  322. resF.SetName("value")
  323. self.win['surface']['draw']['res-fine'] = resF.GetId()
  324. resF.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
  325. resSizer.Add(item=resF, flag=wx.ALL, border=3)
  326. gridSizer.Add(item=resSizer, pos=(0, 3), span=(1, 2))
  327. # style
  328. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  329. label=_("Coarse style:")),
  330. pos=(1, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  331. style = wx.Choice (parent=panel, id=wx.ID_ANY, size=(100, -1),
  332. choices = [_("wire"),
  333. _("surface")])
  334. style.SetName("selection")
  335. self.win['surface']['draw']['style'] = style.GetId()
  336. style.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  337. gridSizer.Add(item=style, flag=wx.ALIGN_CENTER_VERTICAL,
  338. pos=(1, 1))
  339. # shading
  340. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  341. label=_("Shading:")),
  342. pos=(1, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  343. shade = wx.Choice (parent=panel, id=wx.ID_ANY, size=(100, -1),
  344. choices = [_("flat"),
  345. _("gouraud")])
  346. shade.SetName("selection")
  347. self.win['surface']['draw']['shading'] = shade.GetId()
  348. shade.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  349. gridSizer.Add(item=shade, flag=wx.ALIGN_CENTER_VERTICAL,
  350. pos=(1, 3))
  351. # color
  352. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  353. label=_("Wire color:")),
  354. pos=(2, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  355. color = csel.ColourSelect(panel, id=wx.ID_ANY)
  356. color.SetName("colour")
  357. color.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceWireColor)
  358. self.win['surface']['draw']['wire-color'] = color.GetId()
  359. gridSizer.Add(item=color, flag=wx.ALIGN_CENTER_VERTICAL,
  360. pos=(2, 1))
  361. boxSizer.Add(item=gridSizer, proportion=1,
  362. flag=wx.ALL | wx.EXPAND, border=3)
  363. pageSizer.Add(item=boxSizer, proportion=0,
  364. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  365. border=5)
  366. all = wx.Button(panel, id=wx.ID_ANY, label=_("Set to all"))
  367. all.SetToolTipString(_("Use draw settings for all loaded surfaces"))
  368. all.Bind(wx.EVT_BUTTON, self.OnSurfaceModeAll)
  369. gridSizer.Add(item=all, flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  370. pos=(2, 4))
  371. #
  372. # mask
  373. #
  374. box = wx.StaticBox (parent=panel, id=wx.ID_ANY,
  375. label=" %s " % (_("Mask")))
  376. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  377. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  378. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  379. label=_("Mask zeros:")),
  380. pos=(0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  381. elev = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  382. label=_("by elevation"))
  383. elev.Enable(False) # TODO: not implemented yet
  384. gridSizer.Add(item=elev, pos=(0, 1))
  385. color = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  386. label=_("by color"))
  387. color.Enable(False) # TODO: not implemented yet
  388. gridSizer.Add(item=color, pos=(0, 2))
  389. boxSizer.Add(item=gridSizer, proportion=1,
  390. flag=wx.ALL | wx.EXPAND, border=3)
  391. pageSizer.Add(item=boxSizer, proportion=0,
  392. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  393. border=5)
  394. #
  395. # position
  396. #
  397. self.win['surface']['position'] = {}
  398. box = wx.StaticBox (parent=panel, id=wx.ID_ANY,
  399. label=" %s " % (_("Position")))
  400. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  401. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  402. # position
  403. axis = wx.Choice (parent=panel, id=wx.ID_ANY, size=(75, -1),
  404. choices = ["X",
  405. "Y",
  406. "Z"])
  407. axis.SetSelection(0)
  408. self.win['surface']['position']['axis'] = axis.GetId()
  409. axis.Bind(wx.EVT_CHOICE, self.OnSurfaceAxis)
  410. gridSizer.Add(item=axis, flag=wx.ALIGN_CENTER_VERTICAL,
  411. pos=(0, 0))
  412. value = wx.Slider(parent=panel, id=wx.ID_ANY,
  413. value=0,
  414. minValue=-1e4,
  415. maxValue=1e4,
  416. style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | \
  417. wx.SL_TOP | wx.SL_LABELS,
  418. size=(350, -1))
  419. self.win['surface']['position']['pos'] = value.GetId()
  420. value.Bind(wx.EVT_SCROLL, self.OnSurfacePosition)
  421. gridSizer.Add(item=value, flag=wx.ALIGN_CENTER_VERTICAL,
  422. pos=(0, 1))
  423. boxSizer.Add(item=gridSizer, proportion=1,
  424. flag=wx.ALL | wx.EXPAND, border=3)
  425. pageSizer.Add(item=boxSizer, proportion=0,
  426. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  427. border=5)
  428. panel.SetSizer(pageSizer)
  429. return panel.GetBestSize()
  430. def __createVectorPage(self):
  431. """!Create view settings page"""
  432. panel = wx.Panel(parent=self.notebook, id=wx.ID_ANY)
  433. self.page['vector'] = {}
  434. self.page['vector']['id'] = -1
  435. self.page['vector']['panel'] = panel.GetId()
  436. pageSizer = wx.BoxSizer(wx.VERTICAL)
  437. self.win['vector'] = {}
  438. #
  439. # desc
  440. #
  441. desc = wx.StaticText(parent=panel, id=wx.ID_ANY,
  442. label="")
  443. self.win['vector']['desc'] = desc.GetId()
  444. pageSizer.Add(item=desc, proportion=0,
  445. flag=wx.EXPAND | wx.ALL,
  446. border=10)
  447. #
  448. # vector lines
  449. #
  450. self.win['vector']['lines'] = {}
  451. showLines = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  452. label=_("Show vector lines"))
  453. self.win['vector']['lines']['show'] = showLines.GetId()
  454. showLines.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
  455. pageSizer.Add(item=showLines, proportion=0,
  456. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5)
  457. box = wx.StaticBox (parent=panel, id=wx.ID_ANY,
  458. label=" %s " % (_("Vector lines")))
  459. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  460. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  461. # width
  462. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  463. label=_("Width:")),
  464. pos=(0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  465. width = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  466. initial=1,
  467. min=1,
  468. max=100)
  469. self.win['vector']['lines']['width'] = width.GetId()
  470. width.Bind(wx.EVT_SPINCTRL, self.OnVectorLines)
  471. gridSizer.Add(item=width, pos=(0, 1),
  472. flag=wx.ALIGN_CENTER_VERTICAL)
  473. gridSizer.AddGrowableCol(2)
  474. # color
  475. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  476. label=_("Color:")),
  477. pos=(0, 3), flag=wx.ALIGN_CENTER_VERTICAL)
  478. color = csel.ColourSelect(panel, id=wx.ID_ANY,
  479. colour=UserSettings.Get(group='nviz', key='vector',
  480. subkey=['lines', 'color']))
  481. self.win['vector']['lines']['color'] = color.GetId()
  482. color.Bind(csel.EVT_COLOURSELECT, self.OnVectorLines)
  483. gridSizer.Add(item=color, pos=(0, 4))
  484. gridSizer.AddGrowableCol(5)
  485. # display
  486. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  487. label=_("Display:")),
  488. pos=(0, 6), flag=wx.ALIGN_CENTER_VERTICAL)
  489. display = wx.Choice (parent=panel, id=wx.ID_ANY, size=(100, -1),
  490. choices = [_("on surface"),
  491. _("flat")])
  492. self.win['vector']['lines']['flat'] = display.GetId()
  493. display.Bind(wx.EVT_CHOICE, self.OnVectorDisplay)
  494. gridSizer.Add(item=display, flag=wx.ALIGN_CENTER_VERTICAL,
  495. pos=(0, 7))
  496. # height
  497. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  498. label=_("Height above surface:")),
  499. pos=(1, 0), flag=wx.ALIGN_CENTER_VERTICAL,
  500. span=(1, 2))
  501. surface = wx.ComboBox(parent=panel, id=wx.ID_ANY, size=(250, -1),
  502. style=wx.CB_SIMPLE | wx.CB_READONLY,
  503. choices=[])
  504. surface.Bind(wx.EVT_COMBOBOX, self.OnVectorSurface)
  505. self.win['vector']['lines']['surface'] = surface.GetId()
  506. gridSizer.Add(item=surface,
  507. pos=(1, 2), span=(1, 6),
  508. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  509. self.CreateControl(panel, dict=self.win['vector']['lines'], name='height', size=300,
  510. range=(0, 1000),
  511. bind=(self.OnVectorHeight, self.OnVectorHeightFull, self.OnVectorHeightSpin))
  512. gridSizer.Add(item=self.FindWindowById(self.win['vector']['lines']['height']['slider']),
  513. pos=(2, 2), span=(1, 6))
  514. gridSizer.Add(item=self.FindWindowById(self.win['vector']['lines']['height']['spin']),
  515. pos=(3, 4),
  516. flag=wx.ALIGN_CENTER)
  517. boxSizer.Add(item=gridSizer, proportion=1,
  518. flag=wx.ALL | wx.EXPAND, border=3)
  519. pageSizer.Add(item=boxSizer, proportion=0,
  520. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  521. border=5)
  522. #
  523. # vector points
  524. #
  525. self.win['vector']['points'] = {}
  526. showPoints = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  527. label=_("Show vector points"))
  528. self.win['vector']['points']['show'] = showPoints.GetId()
  529. showPoints.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
  530. pageSizer.Add(item=showPoints, proportion=0,
  531. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5)
  532. box = wx.StaticBox (parent=panel, id=wx.ID_ANY,
  533. label=" %s " % (_("Vector points")))
  534. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  535. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  536. # icon size
  537. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  538. label=_("Icon size:")),
  539. pos=(0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  540. isize = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  541. initial=1,
  542. min=1,
  543. max=1e6)
  544. isize.SetName('value')
  545. self.win['vector']['points']['size'] = isize.GetId()
  546. isize.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
  547. isize.Bind(wx.EVT_TEXT, self.OnVectorPoints)
  548. gridSizer.Add(item=isize, pos=(0, 1),
  549. flag=wx.ALIGN_CENTER_VERTICAL)
  550. # icon width
  551. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  552. label=_("width:")),
  553. pos=(0, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  554. iwidth = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  555. initial=1,
  556. min=1,
  557. max=1e6)
  558. iwidth.SetName('value')
  559. self.win['vector']['points']['width'] = iwidth.GetId()
  560. iwidth.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
  561. iwidth.Bind(wx.EVT_TEXT, self.OnVectorPoints)
  562. gridSizer.Add(item=iwidth, pos=(0, 3),
  563. flag=wx.ALIGN_CENTER_VERTICAL)
  564. # icon symbol
  565. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  566. label=_("symbol:")),
  567. pos=(0, 4), flag=wx.ALIGN_CENTER_VERTICAL)
  568. isym = wx.Choice (parent=panel, id=wx.ID_ANY, size=(100, -1),
  569. choices=UserSettings.Get(group='nviz', key='vector',
  570. subkey=['points', 'marker'], internal=True))
  571. isym.SetName("selection")
  572. self.win['vector']['points']['marker'] = isym.GetId()
  573. isym.Bind(wx.EVT_CHOICE, self.OnVectorPoints)
  574. gridSizer.Add(item=isym, flag=wx.ALIGN_CENTER_VERTICAL,
  575. pos=(0, 5))
  576. # icon color
  577. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  578. label=_("color:")),
  579. pos=(0, 6), flag=wx.ALIGN_CENTER_VERTICAL)
  580. icolor = csel.ColourSelect(panel, id=wx.ID_ANY)
  581. icolor.SetName("color")
  582. self.win['vector']['points']['color'] = icolor.GetId()
  583. icolor.Bind(csel.EVT_COLOURSELECT, self.OnVectorPoints)
  584. gridSizer.Add(item=icolor, flag=wx.ALIGN_CENTER_VERTICAL,
  585. pos=(0, 7))
  586. # high
  587. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  588. label=_("Height above surface:")),
  589. pos=(1, 0), flag=wx.ALIGN_CENTER_VERTICAL,
  590. span=(1, 2))
  591. surface = wx.ComboBox(parent=panel, id=wx.ID_ANY, size=(250, -1),
  592. style=wx.CB_SIMPLE | wx.CB_READONLY,
  593. choices=[])
  594. surface.Bind(wx.EVT_COMBOBOX, self.OnVectorSurface)
  595. self.win['vector']['points']['surface'] = surface.GetId()
  596. gridSizer.Add(item=surface,
  597. pos=(1, 2), span=(1, 6),
  598. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  599. self.CreateControl(panel, dict=self.win['vector']['points'], name='height', size=300,
  600. range=(0, 1000),
  601. bind=(self.OnVectorHeight, self.OnVectorHeightFull, self.OnVectorHeightSpin))
  602. gridSizer.Add(item=self.FindWindowById(self.win['vector']['points']['height']['slider']),
  603. pos=(2, 2), span=(1, 6))
  604. gridSizer.Add(item=self.FindWindowById(self.win['vector']['points']['height']['spin']),
  605. pos=(3, 4),
  606. flag=wx.ALIGN_CENTER)
  607. boxSizer.Add(item=gridSizer, proportion=1,
  608. flag=wx.ALL | wx.EXPAND, border=3)
  609. pageSizer.Add(item=boxSizer, proportion=0,
  610. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  611. border=5)
  612. panel.SetSizer(pageSizer)
  613. return panel.GetBestSize()
  614. def __createVolumePage(self):
  615. """!Create view settings page"""
  616. panel = wx.Panel(parent=self.notebook, id=wx.ID_ANY)
  617. self.page['volume'] = {}
  618. self.page['volume']['id'] = -1
  619. self.page['volume']['panel'] = panel.GetId()
  620. pageSizer = wx.BoxSizer(wx.VERTICAL)
  621. self.win['volume'] = {}
  622. #
  623. # draw
  624. #
  625. self.win['volume']['draw'] = {}
  626. box = wx.StaticBox (parent=panel, id=wx.ID_ANY,
  627. label=" %s " % (_("Draw")))
  628. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  629. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  630. gridSizer.AddGrowableCol(4)
  631. # mode
  632. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  633. label=_("Mode:")),
  634. pos=(0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  635. mode = wx.Choice (parent=panel, id=wx.ID_ANY, size=(150, -1),
  636. choices = [_("isosurfaces"),
  637. _("slides")])
  638. mode.SetSelection(0)
  639. mode.SetName("selection")
  640. # mode.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  641. self.win['volume']['draw']['mode'] = mode.GetId()
  642. gridSizer.Add(item=mode, flag=wx.ALIGN_CENTER_VERTICAL,
  643. pos=(0, 1))
  644. # shading
  645. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  646. label=_("Shading:")),
  647. pos=(0, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  648. shade = wx.Choice (parent=panel, id=wx.ID_ANY, size=(100, -1),
  649. choices = [_("flat"),
  650. _("gouraud")])
  651. shade.SetName("selection")
  652. self.win['volume']['draw']['shading'] = shade.GetId()
  653. shade.Bind(wx.EVT_CHOICE, self.OnVolumeIsosurfMode)
  654. gridSizer.Add(item=shade, flag=wx.ALIGN_CENTER_VERTICAL,
  655. pos=(0, 3))
  656. # resolution (mode)
  657. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  658. label=_("Resolution:")),
  659. pos=(0, 4), flag=wx.ALIGN_CENTER_VERTICAL)
  660. resol = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  661. initial=1,
  662. min=1,
  663. max=100)
  664. resol.SetName("value")
  665. self.win['volume']['draw']['resolution'] = resol.GetId()
  666. resol.Bind(wx.EVT_SPINCTRL, self.OnVolumeIsosurfResolution)
  667. resol.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfResolution)
  668. gridSizer.Add(item=resol, pos=(0, 5))
  669. boxSizer.Add(item=gridSizer, proportion=1,
  670. flag=wx.ALL | wx.EXPAND, border=3)
  671. pageSizer.Add(item=boxSizer, proportion=0,
  672. flag=wx.EXPAND | wx.ALL,
  673. border=5)
  674. #
  675. # manage isosurfaces
  676. #
  677. box = wx.StaticBox (parent=panel, id=wx.ID_ANY,
  678. label=" %s " % (_("List of isosurfaces")))
  679. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  680. gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
  681. # list
  682. isolevel = wx.CheckListBox(parent=panel, id=wx.ID_ANY,
  683. size=(300, 150))
  684. self.Bind(wx.EVT_CHECKLISTBOX, self.OnVolumeIsosurfCheck, isolevel)
  685. self.Bind(wx.EVT_LISTBOX, self.OnVolumeIsosurfSelect, isolevel)
  686. self.win['volume']['isosurfs'] = isolevel.GetId()
  687. gridSizer.Add(item=isolevel, pos=(0, 0), span=(4, 1))
  688. # buttons (add, delete, move up, move down)
  689. btnAdd = wx.Button(parent=panel, id=wx.ID_ADD)
  690. self.win['volume']['btnIsosurfAdd'] = btnAdd.GetId()
  691. btnAdd.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfAdd)
  692. gridSizer.Add(item=btnAdd,
  693. pos=(0, 1))
  694. btnDelete = wx.Button(parent=panel, id=wx.ID_DELETE)
  695. self.win['volume']['btnIsosurfDelete'] = btnDelete.GetId()
  696. btnDelete.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfDelete)
  697. btnDelete.Enable(False)
  698. gridSizer.Add(item=btnDelete,
  699. pos=(1, 1))
  700. btnMoveUp = wx.Button(parent=panel, id=wx.ID_UP)
  701. self.win['volume']['btnIsosurfMoveUp'] = btnMoveUp.GetId()
  702. btnMoveUp.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfMoveUp)
  703. btnMoveUp.Enable(False)
  704. gridSizer.Add(item=btnMoveUp,
  705. pos=(2, 1))
  706. btnMoveDown = wx.Button(parent=panel, id=wx.ID_DOWN)
  707. self.win['volume']['btnIsosurfMoveDown'] = btnMoveDown.GetId()
  708. btnMoveDown.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfMoveDown)
  709. btnMoveDown.Enable(False)
  710. gridSizer.Add(item=btnMoveDown,
  711. pos=(3, 1))
  712. boxSizer.Add(item=gridSizer, proportion=1,
  713. flag=wx.ALL | wx.EXPAND, border=3)
  714. pageSizer.Add(item=boxSizer, proportion=0,
  715. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  716. border=5)
  717. #
  718. # isosurface attributes
  719. #
  720. box = wx.StaticBox (parent=panel, id=wx.ID_ANY,
  721. label=" %s " % (_("Isosurface attributes")))
  722. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  723. gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
  724. self.win['volume']['attr'] = {}
  725. row = 0
  726. for code, attrb in (('topo', _("Topography level")),
  727. ('color', _("Color")),
  728. ('mask', _("Mask")),
  729. ('transp', _("Transparency")),
  730. ('shine', _("Shininess")),
  731. ('emit', _("Emission"))):
  732. self.win['volume'][code] = {}
  733. # label
  734. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  735. label=attrb + ':'),
  736. pos=(row, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  737. if code != 'topo':
  738. use = wx.Choice (parent=panel, id=wx.ID_ANY, size=(100, -1),
  739. choices = [_("map")])
  740. else:
  741. use = None
  742. # check for required properties
  743. if code not in ('topo', 'color', 'shine'):
  744. use.Insert(item=_("unset"), pos=0)
  745. self.win['volume'][code]['required'] = False
  746. else:
  747. self.win['volume'][code]['required'] = True
  748. if use and code != 'mask':
  749. use.Append(item=_('constant'))
  750. if use:
  751. self.win['volume'][code]['use'] = use.GetId()
  752. use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
  753. gridSizer.Add(item=use, flag=wx.ALIGN_CENTER_VERTICAL,
  754. pos=(row, 1))
  755. if code != 'topo':
  756. map = gselect.Select(parent=panel, id=wx.ID_ANY,
  757. # size=globalvar.DIALOG_GSELECT_SIZE,
  758. size=(200, -1),
  759. type="grid3")
  760. self.win['volume'][code]['map'] = map.GetId() - 1 # FIXME
  761. map.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
  762. gridSizer.Add(item=map, flag=wx.ALIGN_CENTER_VERTICAL,
  763. pos=(row, 2))
  764. else:
  765. map = None
  766. if code == 'color':
  767. value = csel.ColourSelect(panel, id=wx.ID_ANY,
  768. colour=UserSettings.Get(group='nviz', key='volume',
  769. subkey=['color', 'value']))
  770. value.Bind(csel.EVT_COLOURSELECT, self.OnVolumeIsosurfMap)
  771. elif code == 'mask':
  772. value = None
  773. else:
  774. if code == 'topo':
  775. size = (200, -1)
  776. else:
  777. size = (65, -1)
  778. value = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=size,
  779. initial=0)
  780. if code == 'topo':
  781. value.SetRange(minVal=-1e9, maxVal=1e9)
  782. elif code in ('shine', 'transp', 'emit'):
  783. value.SetRange(minVal=0, maxVal=255)
  784. else:
  785. value.SetRange(minVal=0, maxVal=100)
  786. value.Bind(wx.EVT_SPINCTRL, self.OnVolumeIsosurfMap)
  787. value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
  788. if value:
  789. self.win['volume'][code]['const'] = value.GetId()
  790. if code == 'topo':
  791. gridSizer.Add(item=value, flag=wx.ALIGN_CENTER_VERTICAL,
  792. pos=(row, 2))
  793. else:
  794. value.Enable(False)
  795. gridSizer.Add(item=value, flag=wx.ALIGN_CENTER_VERTICAL,
  796. pos=(row, 3))
  797. else:
  798. self.win['volume'][code]['const'] = None
  799. if code != 'topo':
  800. self.SetMapObjUseMap(nvizType='volume',
  801. attrb=code) # -> enable map / disable constant
  802. row += 1
  803. boxSizer.Add(item=gridSizer, proportion=1,
  804. flag=wx.ALL | wx.EXPAND, border=3)
  805. pageSizer.Add(item=boxSizer, proportion=0,
  806. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  807. border=5)
  808. panel.SetSizer(pageSizer)
  809. return panel.GetBestSize()
  810. def __createSettingsPage(self):
  811. """!Create settings page"""
  812. panel = wx.Panel(parent=self.notebook, id=wx.ID_ANY)
  813. self.notebook.AddPage(page=panel,
  814. text=" %s " % _("Settings"))
  815. pageSizer = wx.BoxSizer(wx.VERTICAL)
  816. self.win['settings'] = {}
  817. #
  818. # general
  819. #
  820. self.win['settings']['general'] = {}
  821. box = wx.StaticBox (parent=panel, id=wx.ID_ANY,
  822. label=" %s " % (_("General")))
  823. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  824. gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
  825. # background color
  826. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  827. label=_("Background color:")),
  828. pos=(0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  829. color = csel.ColourSelect(panel, id=wx.ID_ANY,
  830. colour=UserSettings.Get(group='nviz', key='settings',
  831. subkey=['general', 'bgcolor']))
  832. self.win['settings']['general']['bgcolor'] = color.GetId()
  833. color.Bind(csel.EVT_COLOURSELECT, self.OnBgColor)
  834. gridSizer.Add(item=color, pos=(0, 1))
  835. boxSizer.Add(item=gridSizer, proportion=1,
  836. flag=wx.ALL | wx.EXPAND, border=3)
  837. pageSizer.Add(item=boxSizer, proportion=0,
  838. flag=wx.EXPAND | wx.ALL,
  839. border=5)
  840. #
  841. # view
  842. #
  843. self.win['settings']['view'] = {}
  844. box = wx.StaticBox (parent=panel, id=wx.ID_ANY,
  845. label=" %s " % (_("View")))
  846. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  847. gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
  848. # perspective
  849. self.win['settings']['view']['persp'] = {}
  850. pvals = UserSettings.Get(group='nviz', key='view', subkey='persp')
  851. ipvals = UserSettings.Get(group='nviz', key='view', subkey='persp', internal=True)
  852. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  853. label=_("Perspective:")),
  854. pos=(0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  855. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  856. label=_("(value)")),
  857. pos=(0, 1), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  858. pval = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  859. initial=pvals['value'],
  860. min=ipvals['min'],
  861. max=ipvals['max'])
  862. self.win['settings']['view']['persp']['value'] = pval.GetId()
  863. gridSizer.Add(item=pval, pos=(0, 2),
  864. flag=wx.ALIGN_CENTER_VERTICAL)
  865. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  866. label=_("(step)")),
  867. pos=(0, 3), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  868. pstep = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  869. initial=pvals['step'],
  870. min=ipvals['min'],
  871. max=ipvals['max']-1)
  872. self.win['settings']['view']['persp']['step'] = pstep.GetId()
  873. gridSizer.Add(item=pstep, pos=(0, 4),
  874. flag=wx.ALIGN_CENTER_VERTICAL)
  875. # position
  876. self.win['settings']['view']['pos'] = {}
  877. posvals = UserSettings.Get(group='nviz', key='view', subkey='pos')
  878. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  879. label=_("Position:")),
  880. pos=(1, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  881. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  882. label=_("(x)")),
  883. pos=(1, 1), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  884. px = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  885. initial=posvals['x'] * 100,
  886. min=0,
  887. max=100)
  888. self.win['settings']['view']['pos']['x'] = px.GetId()
  889. gridSizer.Add(item=px, pos=(1, 2),
  890. flag=wx.ALIGN_CENTER_VERTICAL)
  891. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  892. label="(y)"),
  893. pos=(1, 3), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  894. py = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  895. initial=posvals['y'] * 100,
  896. min=0,
  897. max=100)
  898. self.win['settings']['view']['pos']['y'] = py.GetId()
  899. gridSizer.Add(item=py, pos=(1, 4),
  900. flag=wx.ALIGN_CENTER_VERTICAL)
  901. # height
  902. self.win['settings']['view']['height'] = {}
  903. hvals = UserSettings.Get(group='nviz', key='view', subkey='height')
  904. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  905. label=_("Height")),
  906. pos=(2, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  907. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  908. label=_("(step)")),
  909. pos=(2, 1), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  910. hstep = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  911. initial=hvals['step'],
  912. min=1,
  913. max=1e6)
  914. self.win['settings']['view']['height']['step'] = hstep.GetId()
  915. gridSizer.Add(item=hstep, pos=(2, 2),
  916. flag=wx.ALIGN_CENTER_VERTICAL)
  917. # twist
  918. self.win['settings']['view']['twist'] = {}
  919. tvals = UserSettings.Get(group='nviz', key='view', subkey='twist')
  920. itvals = UserSettings.Get(group='nviz', key='view', subkey='twist', internal=True)
  921. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  922. label=_("Twist")),
  923. pos=(3, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  924. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  925. label=_("(value)")),
  926. pos=(3, 1), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  927. tval = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  928. initial=tvals['value'],
  929. min=itvals['min'],
  930. max=itvals['max'])
  931. self.win['settings']['view']['twist']['value'] = tval.GetId()
  932. gridSizer.Add(item=tval, pos=(3, 2),
  933. flag=wx.ALIGN_CENTER_VERTICAL)
  934. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  935. label=_("(step)")),
  936. pos=(3, 3), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  937. tstep = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  938. initial=tvals['step'],
  939. min=itvals['min'],
  940. max=itvals['max']-1)
  941. self.win['settings']['view']['twist']['step'] = tstep.GetId()
  942. gridSizer.Add(item=tstep, pos=(3, 4),
  943. flag=wx.ALIGN_CENTER_VERTICAL)
  944. # z-exag
  945. self.win['settings']['view']['z-exag'] = {}
  946. zvals = UserSettings.Get(group='nviz', key='view', subkey='z-exag')
  947. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  948. label=_("Z-exag")),
  949. pos=(4, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  950. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  951. label=_("(value)")),
  952. pos=(4, 1), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  953. zval = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  954. initial=zvals['value'],
  955. min=-1e6,
  956. max=1e6)
  957. self.win['settings']['view']['z-exag']['value'] = zval.GetId()
  958. gridSizer.Add(item=zval, pos=(4, 2),
  959. flag=wx.ALIGN_CENTER_VERTICAL)
  960. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  961. label=_("(step):")),
  962. pos=(4, 3), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  963. zstep = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  964. initial=zvals['step'],
  965. min=-1e6,
  966. max=1e6)
  967. self.win['settings']['view']['z-exag']['step'] = zstep.GetId()
  968. gridSizer.Add(item=zstep, pos=(4, 4),
  969. flag=wx.ALIGN_CENTER_VERTICAL)
  970. boxSizer.Add(item=gridSizer, proportion=1,
  971. flag=wx.ALL | wx.EXPAND, border=3)
  972. pageSizer.Add(item=boxSizer, proportion=0,
  973. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  974. border=5)
  975. #
  976. # surface
  977. #
  978. self.win['settings']['surface'] = {}
  979. box = wx.StaticBox (parent=panel, id=wx.ID_ANY,
  980. label=" %s " % (_("Surface")))
  981. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  982. gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
  983. boxSizer.Add(item=gridSizer, proportion=1,
  984. flag=wx.ALL | wx.EXPAND, border=3)
  985. pageSizer.Add(item=boxSizer, proportion=0,
  986. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  987. border=5)
  988. #
  989. # vector lines
  990. #
  991. self.win['settings']['vector'] = {}
  992. self.win['settings']['vector']['lines'] = {}
  993. box = wx.StaticBox (parent=panel, id=wx.ID_ANY,
  994. label=" %s " % (_("Vector lines")))
  995. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  996. gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
  997. # show
  998. row = 0
  999. showLines = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1000. label=_("Show lines"))
  1001. self.win['settings']['vector']['lines']['show'] = showLines.GetId()
  1002. showLines.SetValue(UserSettings.Get(group='nviz', key='vector',
  1003. subkey=['lines', 'show']))
  1004. gridSizer.Add(item=showLines, pos=(row, 0))
  1005. boxSizer.Add(item=gridSizer, proportion=1,
  1006. flag=wx.ALL | wx.EXPAND, border=3)
  1007. pageSizer.Add(item=boxSizer, proportion=0,
  1008. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1009. border=5)
  1010. #
  1011. # vector points
  1012. #
  1013. self.win['settings']['vector']['points'] = {}
  1014. box = wx.StaticBox (parent=panel, id=wx.ID_ANY,
  1015. label=" %s " % (_("Vector points")))
  1016. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1017. gridSizer = wx.GridBagSizer(vgap=3, hgap=5)
  1018. # show
  1019. row = 0
  1020. showPoints = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1021. label=_("Show points"))
  1022. showPoints.SetValue(UserSettings.Get(group='nviz', key='vector',
  1023. subkey=['points', 'show']))
  1024. self.win['settings']['vector']['points']['show'] = showPoints.GetId()
  1025. gridSizer.Add(item=showPoints, pos=(row, 0), span=(1, 8))
  1026. # icon size
  1027. row += 1
  1028. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  1029. label=_("Size:")),
  1030. pos=(row, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  1031. isize = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  1032. initial=100,
  1033. min=1,
  1034. max=1e6)
  1035. self.win['settings']['vector']['points']['size'] = isize.GetId()
  1036. isize.SetValue(UserSettings.Get(group='nviz', key='vector',
  1037. subkey=['points', 'size']))
  1038. gridSizer.Add(item=isize, pos=(row, 1),
  1039. flag=wx.ALIGN_CENTER_VERTICAL)
  1040. # icon width
  1041. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  1042. label=_("Width:")),
  1043. pos=(row, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  1044. iwidth = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
  1045. initial=2,
  1046. min=1,
  1047. max=1e6)
  1048. self.win['settings']['vector']['points']['width'] = isize.GetId()
  1049. iwidth.SetValue(UserSettings.Get(group='nviz', key='vector',
  1050. subkey=['points', 'width']))
  1051. gridSizer.Add(item=iwidth, pos=(row, 3),
  1052. flag=wx.ALIGN_CENTER_VERTICAL)
  1053. # icon symbol
  1054. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  1055. label=_("Marker:")),
  1056. pos=(row, 4), flag=wx.ALIGN_CENTER_VERTICAL)
  1057. isym = wx.Choice (parent=panel, id=wx.ID_ANY, size=(100, -1),
  1058. choices=UserSettings.Get(group='nviz', key='vector',
  1059. subkey=['points', 'marker'], internal=True))
  1060. isym.SetName("selection")
  1061. self.win['settings']['vector']['points']['marker'] = isym.GetId()
  1062. isym.SetSelection(UserSettings.Get(group='nviz', key='vector',
  1063. subkey=['points', 'marker']))
  1064. gridSizer.Add(item=isym, flag=wx.ALIGN_CENTER_VERTICAL,
  1065. pos=(row, 5))
  1066. # icon color
  1067. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  1068. label=_("Color:")),
  1069. pos=(row, 6), flag=wx.ALIGN_CENTER_VERTICAL)
  1070. icolor = csel.ColourSelect(panel, id=wx.ID_ANY)
  1071. icolor.SetName("color")
  1072. self.win['settings']['vector']['points']['color'] = icolor.GetId()
  1073. icolor.SetColour(UserSettings.Get(group='nviz', key='vector',
  1074. subkey=['points', 'color']))
  1075. gridSizer.Add(item=icolor, flag=wx.ALIGN_CENTER_VERTICAL,
  1076. pos=(row, 7))
  1077. boxSizer.Add(item=gridSizer, proportion=1,
  1078. flag=wx.ALL | wx.EXPAND, border=3)
  1079. pageSizer.Add(item=boxSizer, proportion=0,
  1080. flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1081. border=5)
  1082. #
  1083. # buttons
  1084. #
  1085. btnDefault = wx.Button(panel, wx.ID_CANCEL, label=_("Default"))
  1086. btnSave = wx.Button(panel, wx.ID_SAVE)
  1087. btnApply = wx.Button(panel, wx.ID_APPLY)
  1088. btnDefault.Bind(wx.EVT_BUTTON, self.OnDefault)
  1089. btnDefault.SetToolTipString(_("Restore default settings"))
  1090. btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
  1091. btnApply.SetToolTipString(_("Apply changes for the current session"))
  1092. btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
  1093. btnSave.SetToolTipString(_("Apply and save changes to user settings file (default for next sessions)"))
  1094. btnSave.SetDefault()
  1095. btnSizer = wx.StdDialogButtonSizer()
  1096. btnSizer.AddButton(btnDefault)
  1097. btnSizer.AddButton(btnApply)
  1098. btnSizer.AddButton(btnSave)
  1099. btnSizer.Realize()
  1100. pageSizer.Add(item=btnSizer, proportion=1,
  1101. flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM,
  1102. border=5)
  1103. panel.SetSizer(pageSizer)
  1104. return panel.GetBestSize()
  1105. def CreateControl(self, parent, dict, name, range, bind, sliderHor=True, size=200):
  1106. """!Add control (Slider + SpinCtrl)"""
  1107. dict[name] = {}
  1108. if sliderHor:
  1109. style = wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | \
  1110. wx.SL_BOTTOM
  1111. sizeW = (size, -1)
  1112. else:
  1113. style = wx.SL_VERTICAL | wx.SL_AUTOTICKS | \
  1114. wx.SL_INVERSE
  1115. sizeW = (-1, size)
  1116. try:
  1117. val = self.mapWindow.view[name]['value']
  1118. except KeyError:
  1119. val=-1
  1120. slider = wx.Slider(parent=parent, id=wx.ID_ANY,
  1121. value=val,
  1122. minValue=range[0],
  1123. maxValue=range[1],
  1124. style=style,
  1125. size=sizeW)
  1126. slider.SetName('slider')
  1127. slider.Bind(wx.EVT_SCROLL, bind[0])
  1128. slider.Bind(wx.EVT_SCROLL_CHANGED, bind[1])
  1129. dict[name]['slider'] = slider.GetId()
  1130. spin = wx.SpinCtrl(parent=parent, id=wx.ID_ANY, size=(65, -1),
  1131. initial=val,
  1132. min=range[0],
  1133. max=range[1])
  1134. # spin = wx.SpinButton(parent=parent, id=wx.ID_ANY)
  1135. # spin.SetValue (self.mapWindow.view[name]['value'])
  1136. # spin.SetRange(self.mapWindow.view[name]['min'],
  1137. # self.mapWindow.view[name]['max'])
  1138. # no 'changed' event ... (FIXME)
  1139. spin.SetName('spin')
  1140. spin.Bind(wx.EVT_SPINCTRL, bind[2])
  1141. ### spin.Bind(wx.EVT_TEXT, bind[2])
  1142. dict[name]['spin'] = spin.GetId()
  1143. def UpdateSettings(self):
  1144. """!Update dialog settings"""
  1145. for control in ('height',
  1146. 'persp',
  1147. 'twist',
  1148. 'z-exag'):
  1149. for win in self.win['view'][control].itervalues():
  1150. if control == 'height':
  1151. value = UserSettings.Get(group='nviz', key='view',
  1152. subkey=['height', 'value'], internal=True)
  1153. else:
  1154. value = self.mapWindow.view[control]['value']
  1155. self.FindWindowById(win).SetValue(value)
  1156. self.FindWindowById(self.win['view']['pos']).Draw()
  1157. self.FindWindowById(self.win['view']['pos']).Refresh(False)
  1158. self.Refresh(False)
  1159. def __GetWindowName(self, dict, id):
  1160. for name in dict.iterkeys():
  1161. if type(dict[name]) is type({}):
  1162. for win in dict[name].itervalues():
  1163. if win == id:
  1164. return name
  1165. else:
  1166. if dict[name] == id:
  1167. return name
  1168. return None
  1169. def OnViewChange(self, event):
  1170. """!Change view, render in quick mode"""
  1171. # find control
  1172. winName = self.__GetWindowName(self.win['view'], event.GetId())
  1173. if not winName:
  1174. return
  1175. if winName == 'height':
  1176. view = self.mapWindow.iview # internal
  1177. else:
  1178. view = self.mapWindow.view
  1179. view[winName]['value'] = event.GetInt()
  1180. for win in self.win['view'][winName].itervalues():
  1181. self.FindWindowById(win).SetValue(view[winName]['value'])
  1182. if winName == 'z-exag':
  1183. zExag = True
  1184. else:
  1185. zExag = False
  1186. self.PostViewEvent(zExag)
  1187. self.mapWindow.render['quick'] = True
  1188. self.mapWindow.Refresh(False)
  1189. def OnViewChanged(self, event):
  1190. """!View changed, render in full resolution"""
  1191. self.mapWindow.render['quick'] = False
  1192. self.mapWindow.Refresh(False)
  1193. def OnViewChangedSpin(self, event):
  1194. """!View changed, render in full resolution"""
  1195. # TODO: use step value instead
  1196. self.OnViewChange(event)
  1197. self.OnViewChanged(None)
  1198. def OnResetView(self, event):
  1199. """!Reset to default view (view page)"""
  1200. self.mapWindow.ResetView()
  1201. self.UpdateSettings()
  1202. self.mapWindow.Refresh(False)
  1203. def OnLookAt(self, event):
  1204. """!Look at (view page)"""
  1205. sel = event.GetSelection()
  1206. if sel == 0: # top
  1207. self.mapWindow.view['pos']['x'] = 0.5
  1208. self.mapWindow.view['pos']['y'] = 0.5
  1209. elif sel == 1: # north
  1210. self.mapWindow.view['pos']['x'] = 0.5
  1211. self.mapWindow.view['pos']['y'] = 0.0
  1212. elif sel == 2: # south
  1213. self.mapWindow.view['pos']['x'] = 0.5
  1214. self.mapWindow.view['pos']['y'] = 1.0
  1215. elif sel == 3: # east
  1216. self.mapWindow.view['pos']['x'] = 1.0
  1217. self.mapWindow.view['pos']['y'] = 0.5
  1218. elif sel == 4: # west
  1219. self.mapWindow.view['pos']['x'] = 0.0
  1220. self.mapWindow.view['pos']['y'] = 0.5
  1221. elif sel == 5: # north-west
  1222. self.mapWindow.view['pos']['x'] = 0.0
  1223. self.mapWindow.view['pos']['y'] = 0.0
  1224. elif sel == 6: # north-east
  1225. self.mapWindow.view['pos']['x'] = 1.0
  1226. self.mapWindow.view['pos']['y'] = 0.0
  1227. elif sel == 7: # south-east
  1228. self.mapWindow.view['pos']['x'] = 1.0
  1229. self.mapWindow.view['pos']['y'] = 1.0
  1230. elif sel == 8: # south-west
  1231. self.mapWindow.view['pos']['x'] = 0.0
  1232. self.mapWindow.view['pos']['y'] = 1.0
  1233. self.PostViewEvent(zExag=True)
  1234. self.UpdateSettings()
  1235. self.mapWindow.Refresh(False)
  1236. def OnDefault(self, event):
  1237. """!Restore default settings"""
  1238. settings = copy.deepcopy(UserSettings.GetDefaultSettings()['nviz'])
  1239. UserSettings.Set(group='nviz',
  1240. value=settings)
  1241. for subgroup, key in settings.iteritems(): # view, surface, vector...
  1242. if subgroup != 'view':
  1243. continue
  1244. for subkey, value in key.iteritems():
  1245. for subvalue in value.keys():
  1246. win = self.FindWindowById(self.win['settings'][subgroup][subkey][subvalue])
  1247. val = settings[subgroup][subkey][subvalue]
  1248. if subkey == 'pos':
  1249. val = int(val * 100)
  1250. win.SetValue(val)
  1251. event.Skip()
  1252. def OnApply(self, event):
  1253. """!Apply button pressed"""
  1254. if self.notebook.GetSelection() == self.page['settings']['id']:
  1255. self.ApplySettings()
  1256. if event:
  1257. event.Skip()
  1258. def ApplySettings(self):
  1259. """!Apply Nviz settings for current session"""
  1260. settings = UserSettings.Get(group='nviz')
  1261. for subgroup, key in settings.iteritems(): # view, surface, vector...
  1262. for subkey, value in key.iteritems():
  1263. for subvalue in value.keys():
  1264. try: # TODO
  1265. win = self.FindWindowById(self.win['settings'][subgroup][subkey][subvalue])
  1266. except:
  1267. # print 'e', subgroup, subkey, subvalue
  1268. continue
  1269. if win.GetName() == "selection":
  1270. value = win.GetSelection()
  1271. elif win.GetName() == "color":
  1272. value = tuple(win.GetColour())
  1273. else:
  1274. value = win.GetValue()
  1275. if subkey == 'pos':
  1276. value = float(value) / 100
  1277. settings[subgroup][subkey][subvalue] = value
  1278. def OnSave(self, event):
  1279. """!OK button pressed
  1280. Apply changes, update map and save settings of selected layer
  1281. """
  1282. #
  1283. # apply changes
  1284. #
  1285. self.OnApply(None)
  1286. if self.notebook.GetSelection() == self.page['settings']['id']:
  1287. fileSettings = {}
  1288. UserSettings.ReadSettingsFile(settings=fileSettings)
  1289. fileSettings['nviz'] = UserSettings.Get(group='nviz')
  1290. file = UserSettings.SaveToFile(fileSettings)
  1291. self.lmgr.goutput.WriteLog(_('Nviz settings saved to file <%s>.') % file)
  1292. def OnBgColor(self, event):
  1293. """!Background color changed"""
  1294. color = event.GetValue()
  1295. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  1296. self.mapWindow.nvizClass.SetBgColor(str(color))
  1297. if self.parent.statusbarWin['render'].IsChecked():
  1298. self.mapWindow.Refresh(False)
  1299. def OnClose(self, event):
  1300. """!Close button pressed
  1301. Close dialog
  1302. """
  1303. self.Hide()
  1304. def OnMapObjUse(self, event):
  1305. """!Set surface attribute -- use -- map/constant"""
  1306. if not self.mapWindow.init:
  1307. return
  1308. wx.Yield()
  1309. # find attribute row
  1310. attrb = self.__GetWindowName(self.win['surface'], event.GetId())
  1311. if not attrb:
  1312. attrb = self.__GetWindowName(self.win['volume'], event.GetId())
  1313. nvizType = 'volume'
  1314. else:
  1315. nvizType = 'surface'
  1316. selection = event.GetSelection()
  1317. if self.win[nvizType][attrb]['required']: # no 'unset'
  1318. selection += 1
  1319. if selection == 0: # unset
  1320. useMap = None
  1321. value = ''
  1322. elif selection == 1: # map
  1323. useMap = True
  1324. value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
  1325. elif selection == 2: # constant
  1326. useMap = False
  1327. if attrb == 'color':
  1328. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
  1329. value = self._getColorString(value)
  1330. else:
  1331. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue()
  1332. self.SetMapObjUseMap(nvizType=nvizType,
  1333. attrb=attrb, map=useMap)
  1334. data = self.mapWindow.GetSelectedLayer(type='nviz')
  1335. if nvizType == 'surface':
  1336. data[nvizType]['attribute'][attrb] = { 'map' : useMap,
  1337. 'value' : str(value),
  1338. 'update' : None, }
  1339. else: # volume / isosurface
  1340. list = self.FindWindowById(self.win['volume']['isosurfs'])
  1341. id = list.GetSelection()
  1342. data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
  1343. 'value' : str(value),
  1344. 'update' : None, }
  1345. # update properties
  1346. event = wxUpdateProperties(data=data)
  1347. wx.PostEvent(self.mapWindow, event)
  1348. if self.parent.statusbarWin['render'].IsChecked():
  1349. self.mapWindow.Refresh(False)
  1350. def SetMapObjUseMap(self, nvizType, attrb, map=None):
  1351. """!Update dialog widgets when attribute type changed"""
  1352. if attrb in ('topo', 'color', 'shine'):
  1353. incSel = -1 # decrement selection (no 'unset')
  1354. else:
  1355. incSel = 0
  1356. if map is True: # map
  1357. if attrb != 'topo': # changing map topography not allowed
  1358. # not sure why, but here must be disabled both ids, should be fixed!
  1359. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(True)
  1360. if self.win[nvizType][attrb]['const']:
  1361. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
  1362. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(1 + incSel)
  1363. elif map is False: # const
  1364. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
  1365. if self.win[nvizType][attrb]['const']:
  1366. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(True)
  1367. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(2 + incSel)
  1368. else: # unset
  1369. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
  1370. if self.win[nvizType][attrb]['const']:
  1371. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
  1372. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(0)
  1373. def OnSurfaceMap(self, event):
  1374. """!Set surface attribute"""
  1375. self.SetMapObjAttrb(nvizType='surface', winId=event.GetId())
  1376. def SetMapObjAttrb(self, nvizType, winId):
  1377. """!Set map object (surface/isosurface) attribute (map/constant)"""
  1378. if not self.mapWindow.init:
  1379. return
  1380. attrb = self.__GetWindowName(self.win[nvizType], winId)
  1381. if not attrb:
  1382. return
  1383. if nvizType == 'volume' and attrb == 'topo':
  1384. return
  1385. selection = self.FindWindowById(self.win[nvizType][attrb]['use']).GetSelection()
  1386. if self.win[nvizType][attrb]['required']:
  1387. selection += 1
  1388. if selection == 0: # unset
  1389. useMap = None
  1390. value = ''
  1391. elif selection == 1: # map
  1392. value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
  1393. useMap = True
  1394. else: # constant
  1395. if attrb == 'color':
  1396. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
  1397. # tuple to string
  1398. value = self._getColorString(value)
  1399. else:
  1400. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue()
  1401. useMap = False
  1402. if not self.pageChanging:
  1403. data = self.mapWindow.GetSelectedLayer(type='nviz')
  1404. if nvizType == 'surface':
  1405. data[nvizType]['attribute'][attrb] = { 'map' : useMap,
  1406. 'value' : str(value),
  1407. 'update' : None, }
  1408. else: # volume / isosurface
  1409. list = self.FindWindowById(self.win['volume']['isosurfs'])
  1410. id = list.GetSelection()
  1411. data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
  1412. 'value' : str(value),
  1413. 'update' : None, }
  1414. # update properties
  1415. event = wxUpdateProperties(data=data)
  1416. wx.PostEvent(self.mapWindow, event)
  1417. if self.parent.statusbarWin['render'].IsChecked():
  1418. self.mapWindow.Refresh(False)
  1419. def OnSurfaceResolution(self, event):
  1420. """!Draw resolution changed"""
  1421. self.SetSurfaceResolution()
  1422. if apply and self.parent.statusbarWin['render'].IsChecked():
  1423. self.mapWindow.Refresh(False)
  1424. def SetSurfaceResolution(self):
  1425. """!Set draw resolution"""
  1426. coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
  1427. fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
  1428. data = self.mapWindow.GetSelectedLayer(type='nviz')
  1429. data['surface']['draw']['resolution'] = { 'coarse' : coarse,
  1430. 'fine' : fine,
  1431. 'update' : None, }
  1432. # update properties
  1433. event = wxUpdateProperties(data=data)
  1434. wx.PostEvent(self.mapWindow, event)
  1435. def SetSurfaceMode(self):
  1436. """!Set draw mode
  1437. @param apply allow auto-rendering
  1438. """
  1439. mode = self.FindWindowById(self.win['surface']['draw']['mode']).GetSelection()
  1440. if mode == 0: # coarse
  1441. self.FindWindowById(self.win['surface']['draw']['res-coarse']).Enable(True)
  1442. self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(False)
  1443. elif mode == 1: # fine
  1444. self.FindWindowById(self.win['surface']['draw']['res-coarse']).Enable(False)
  1445. self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(True)
  1446. else: # both
  1447. self.FindWindowById(self.win['surface']['draw']['res-coarse']).Enable(True)
  1448. self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(True)
  1449. style = self.FindWindowById(self.win['surface']['draw']['style']).GetSelection()
  1450. shade = self.FindWindowById(self.win['surface']['draw']['shading']).GetSelection()
  1451. value, desc = self.mapWindow.nvizDefault.GetDrawMode(mode, style, shade)
  1452. return value, desc
  1453. def OnSurfaceMode(self, event):
  1454. """!Set draw mode"""
  1455. value, desc = self.SetSurfaceMode()
  1456. data = self.mapWindow.GetSelectedLayer(type='nviz')
  1457. data['surface']['draw']['mode'] = { 'value' : value,
  1458. 'desc' : desc,
  1459. 'update' : None, }
  1460. # update properties
  1461. event = wxUpdateProperties(data=data)
  1462. wx.PostEvent(self.mapWindow, event)
  1463. if apply and self.parent.statusbarWin['render'].IsChecked():
  1464. self.mapWindow.Refresh(False)
  1465. def OnSurfaceModeAll(self, event):
  1466. """!Set draw mode (including wire color) for all loaded surfaces"""
  1467. value, desc = self.SetSurfaceMode()
  1468. coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
  1469. fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
  1470. color = self.FindWindowById(self.win['surface']['draw']['wire-color']).GetColour()
  1471. cvalue = self._getColorString(color)
  1472. for name in self.mapWindow.GetLayerNames(type='raster'):
  1473. data = self.mapWindow.GetLayerData(type='raster', name=name)
  1474. if not data:
  1475. continue # shouldy no happen
  1476. data['surface']['draw']['mode'] = { 'value' : value,
  1477. 'desc' : desc,
  1478. 'update' : None, }
  1479. data['surface']['draw']['resolution'] = { 'coarse' : coarse,
  1480. 'fine' : fine,
  1481. 'update' : None, }
  1482. data['surface']['draw']['wire-color'] = { 'value' : cvalue,
  1483. 'update' : None }
  1484. # update properties
  1485. event = wxUpdateProperties(data=data)
  1486. wx.PostEvent(self.mapWindow, event)
  1487. if apply and self.parent.statusbarWin['render'].IsChecked():
  1488. self.mapWindow.Refresh(False)
  1489. def _getColorString(self, color):
  1490. """!Set wire color"""
  1491. return str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  1492. def OnSurfaceWireColor(self, event):
  1493. """!Set wire color"""
  1494. data = self.mapWindow.GetSelectedLayer(type='nviz')
  1495. value = self._getColorString(event.GetValue())
  1496. data['surface']['draw']['wire-color'] = { 'value' : value,
  1497. 'update' : None }
  1498. # update properties
  1499. event = wxUpdateProperties(data=data)
  1500. wx.PostEvent(self.mapWindow, event)
  1501. if self.parent.statusbarWin['render'].IsChecked():
  1502. self.mapWindow.Refresh(False)
  1503. def OnSurfaceAxis(self, event):
  1504. """!Surface position, axis changed"""
  1505. mapLayer = self.mapWindow.GetSelectedLayer()
  1506. data = self.mapWindow.GetSelectedLayer(type='nviz')
  1507. id = data['object']['id']
  1508. axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
  1509. win = self.FindWindowById(self.win['surface']['position']['pos'])
  1510. x, y, z = self.mapWindow.nvizClass.GetSurfacePosition(id)
  1511. if axis == 0: # x
  1512. win.SetRange(-1e4, 1e4)
  1513. win.SetValue(x)
  1514. elif axis == 1: # y
  1515. win.SetRange(-1e4, 1e4)
  1516. win.SetValue(y)
  1517. else: # z
  1518. win.SetRange(-1e3, 1e3)
  1519. win.SetValue(z)
  1520. def OnSurfacePosition(self, event):
  1521. """!Surface position"""
  1522. axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
  1523. value = event.GetInt()
  1524. mapLayer = self.mapWindow.GetSelectedLayer()
  1525. data = self.mapWindow.GetSelectedLayer(type='nviz')
  1526. id = data['surface']['object']['id']
  1527. x, y, z = self.mapWindow.nvizClass.GetSurfacePosition(id)
  1528. if axis == 0: # x
  1529. x = value
  1530. elif axis == 1: # y
  1531. y = value
  1532. else: # z
  1533. z = value
  1534. data = self.mapWindow.GetSelectedLayer(type='nviz')
  1535. data['surface']['position']['x'] = x
  1536. data['surface']['position']['y'] = y
  1537. data['surface']['position']['z'] = z
  1538. data['surface']['position']['update'] = None
  1539. # update properties
  1540. event = wxUpdateProperties(data=data)
  1541. wx.PostEvent(self.mapWindow, event)
  1542. if self.parent.statusbarWin['render'].IsChecked():
  1543. self.mapWindow.Refresh(False)
  1544. def UpdateVectorShow(self, vecType, enabled):
  1545. """!Enable/disable lines/points widgets
  1546. @param vecType vector type (lines, points)
  1547. """
  1548. if vecType != 'lines' and vecType != 'points':
  1549. return False
  1550. for win in self.win['vector'][vecType].keys():
  1551. if win == 'show':
  1552. continue
  1553. if type(self.win['vector'][vecType][win]) == type({}):
  1554. for swin in self.win['vector'][vecType][win].keys():
  1555. if enabled:
  1556. self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(True)
  1557. else:
  1558. self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(False)
  1559. else:
  1560. if enabled:
  1561. self.FindWindowById(self.win['vector'][vecType][win]).Enable(True)
  1562. else:
  1563. self.FindWindowById(self.win['vector'][vecType][win]).Enable(False)
  1564. return True
  1565. def OnVectorShow(self, event):
  1566. """!Show vector lines/points"""
  1567. winId = event.GetId()
  1568. if winId == self.win['vector']['lines']['show']:
  1569. vecType = 'lines'
  1570. else: # points
  1571. vecType = 'points'
  1572. checked = event.IsChecked()
  1573. item = self.mapWindow.GetSelectedLayer(type='item')
  1574. data = self.mapWindow.GetSelectedLayer(type='nviz')['vector']
  1575. if checked:
  1576. self.mapWindow.LoadVector(item, (vecType,))
  1577. else:
  1578. self.mapWindow.UnloadVector(item, (vecType,))
  1579. self.UpdateVectorShow(vecType, checked)
  1580. if checked:
  1581. try:
  1582. id = data[vecType]['object']['id']
  1583. except KeyError:
  1584. id = -1
  1585. if id > 0:
  1586. self.mapWindow.SetMapObjProperties(item, id, vecType)
  1587. # update properties
  1588. event = wxUpdateProperties(data=data)
  1589. wx.PostEvent(self.mapWindow, event)
  1590. if self.parent.statusbarWin['render'].IsChecked():
  1591. self.mapWindow.Refresh(False)
  1592. event.Skip()
  1593. def OnVectorDisplay(self, event):
  1594. """!Display vector lines on surface/flat"""
  1595. if event.GetSelection() == 0: # surface
  1596. if len(self.mapWindow.layers['raster']['name']) < 1:
  1597. event.Veto()
  1598. return
  1599. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(True)
  1600. # set first found surface
  1601. data = self.mapWindow.GetSelectedLayer(type='nviz')
  1602. data['vector']['lines']['mode']['surface'] = self.mapWindow.layers['raster']['name'][0]
  1603. self.FindWindowById(self.win['vector']['lines']['surface']).SetStringSelection( \
  1604. self.mapWindow.layers['raster']['name'][0])
  1605. else: # flat
  1606. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(False)
  1607. self.OnVectorLines(event)
  1608. event.Skip()
  1609. def OnVectorLines(self, event):
  1610. """!Set vector lines mode, apply changes if auto-rendering is enabled"""
  1611. width = self.FindWindowById(self.win['vector']['lines']['width']).GetValue()
  1612. color = self.FindWindowById(self.win['vector']['lines']['color']).GetColour()
  1613. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  1614. mode = {}
  1615. if self.FindWindowById(self.win['vector']['lines']['flat']).GetSelection() == 0:
  1616. mode['type'] = 'surface'
  1617. mode['surface'] = self.FindWindowById(self.win['vector']['lines']['surface']).GetValue()
  1618. mode['update'] = None
  1619. else:
  1620. mode['type'] = 'flat'
  1621. data = self.mapWindow.GetSelectedLayer(type='nviz')
  1622. for attrb in ('width', 'color', 'mode'):
  1623. data['vector']['lines'][attrb]['update'] = None
  1624. data['vector']['lines']['width']['value'] = width
  1625. data['vector']['lines']['color']['value'] = color
  1626. data['vector']['lines']['mode']['value'] = mode
  1627. # update properties
  1628. event = wxUpdateProperties(data=data)
  1629. wx.PostEvent(self.mapWindow, event)
  1630. if self.parent.statusbarWin['render'].IsChecked():
  1631. self.mapWindow.Refresh(False)
  1632. def OnVectorHeight(self, event):
  1633. value = event.GetInt()
  1634. id = event.GetId()
  1635. if id == self.win['vector']['lines']['height']['spin'] or \
  1636. id == self.win['vector']['lines']['height']['slider']:
  1637. vtype = 'lines'
  1638. else:
  1639. vtype = 'points'
  1640. if type(event) == type(wx.ScrollEvent()):
  1641. # slider
  1642. win = self.FindWindowById(self.win['vector'][vtype]['height']['spin'])
  1643. else:
  1644. # spin
  1645. win = self.FindWindowById(self.win['vector'][vtype]['height']['slider'])
  1646. win.SetValue(value)
  1647. data = self.mapWindow.GetSelectedLayer(type='nviz')['vector'][vtype]
  1648. data['height'] = { 'value' : value,
  1649. 'update' : None }
  1650. # update properties
  1651. event = wxUpdateProperties(data=data)
  1652. wx.PostEvent(self.mapWindow, event)
  1653. self.mapWindow.render['quick'] = True
  1654. self.mapWindow.render['v' + vtype] = True
  1655. self.mapWindow.Refresh(False)
  1656. def OnVectorHeightFull(self, event):
  1657. """!Vector height changed, render in full resolution"""
  1658. id = event.GetId()
  1659. if id == self.win['vector']['lines']['height']['spin'] or \
  1660. id == self.win['vector']['lines']['height']['slider']:
  1661. vtype = 'lines'
  1662. else:
  1663. vtype = 'points'
  1664. self.mapWindow.render['quick'] = False
  1665. self.mapWindow.render['v' + vtype] = False
  1666. self.mapWindow.Refresh(False)
  1667. def OnVectorHeightSpin(self, event):
  1668. """!Vector height changed, render in full resolution"""
  1669. # TODO: use step value instead
  1670. self.OnVectorHeight(event)
  1671. self.OnVectorHeightFull(event)
  1672. def OnVectorSurface(self, event):
  1673. """!Reference surface for vector map (lines/points)"""
  1674. id = event.GetId()
  1675. if id == self.win['vector']['lines']['surface']:
  1676. vtype = 'lines'
  1677. else:
  1678. vtype = 'points'
  1679. data['vector'][vtype]['mode']['surface'] = { 'value' : event.GetValue(),
  1680. 'update' : None }
  1681. # update properties
  1682. event = wxUpdateProperties(data=data)
  1683. wx.PostEvent(self.mapWindow, event)
  1684. if self.parent.statusbarWin['render'].IsChecked():
  1685. self.mapWindow.Refresh(False)
  1686. def OnVectorPoints(self, event):
  1687. """!Set vector points mode, apply changes if auto-rendering is enabled"""
  1688. size = self.FindWindowById(self.win['vector']['points']['size']).GetValue()
  1689. width = self.FindWindowById(self.win['vector']['points']['width']).GetValue()
  1690. color = self.FindWindowById(self.win['vector']['points']['color']).GetColour()
  1691. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  1692. marker = self.FindWindowById(self.win['vector']['points']['marker']).GetSelection()
  1693. data = self.mapWindow.GetSelectedLayer(type='nviz')
  1694. for attrb in ('size', 'width', 'color', 'marker'):
  1695. data['vector']['points'][attrb]['update'] = None
  1696. data['vector']['points']['size']['value'] = size
  1697. data['vector']['points']['width']['value'] = width
  1698. data['vector']['points']['color']['value'] = color
  1699. data['vector']['points']['marker']['value'] = marker
  1700. # update properties
  1701. event = wxUpdateProperties(data=data)
  1702. wx.PostEvent(self.mapWindow, event)
  1703. if self.parent.statusbarWin['render'].IsChecked():
  1704. self.mapWindow.Refresh(False)
  1705. def UpdateIsosurfButtons(self, list):
  1706. """!Enable/disable buttons 'add', 'delete',
  1707. 'move up', 'move down'"""
  1708. nitems = list.GetCount()
  1709. add = self.parent.FindWindowById(self.win['volume']['btnIsosurfAdd'])
  1710. delete = self.parent.FindWindowById(self.win['volume']['btnIsosurfDelete'])
  1711. moveDown = self.parent.FindWindowById(self.win['volume']['btnIsosurfMoveDown'])
  1712. moveUp = self.parent.FindWindowById(self.win['volume']['btnIsosurfMoveUp'])
  1713. if nitems >= wxnviz.MAX_ISOSURFS:
  1714. # disable add button on max
  1715. add.Enable(False)
  1716. else:
  1717. add.Enable(True)
  1718. if nitems < 1:
  1719. # disable 'delete' if only one item in the lis
  1720. delete.Enable(False)
  1721. else:
  1722. delete.Enable(True)
  1723. if list.GetSelection() >= nitems - 1:
  1724. # disable 'move-down' if last
  1725. moveDown.Enable(False)
  1726. else:
  1727. moveDown.Enable(True)
  1728. if list.GetSelection() < 1:
  1729. # disable 'move-up' if first
  1730. moveUp.Enable(False)
  1731. else:
  1732. moveUp.Enable(True)
  1733. def OnVolumeIsosurfMode(self, event):
  1734. """!Set isosurface draw mode"""
  1735. self.SetIsosurfaceMode(event.GetSelection())
  1736. def SetIsosurfaceMode(self, selection):
  1737. """!Set isosurface draw mode"""
  1738. layer = self.mapWindow.GetSelectedLayer()
  1739. data = self.mapWindow.GetSelectedLayer(type='nviz')['volume']
  1740. id = data['object']['id']
  1741. mode = 0
  1742. if selection == 0:
  1743. mode |= wxnviz.DM_FLAT
  1744. else:
  1745. mode |= wxnviz.DM_GOURAUD
  1746. self.mapWindow.nvizClass.SetIsosurfaceMode(id, mode)
  1747. if self.parent.statusbarWin['render'].IsChecked():
  1748. self.mapWindow.Refresh(False)
  1749. def OnVolumeIsosurfResolution(self, event):
  1750. """!Set isosurface draw resolution"""
  1751. self.SetIsosurfaceResolution(event.GetInt())
  1752. def SetIsosurfaceResolution(self, res):
  1753. """!Set isosurface draw resolution"""
  1754. layer = self.mapWindow.GetSelectedLayer()
  1755. data = self.mapWindow.GetSelectedLayer(type='nviz')['volume']
  1756. id = data['object']['id']
  1757. self.mapWindow.nvizClass.SetIsosurfaceRes(id, res)
  1758. if self.parent.statusbarWin['render'].IsChecked():
  1759. self.mapWindow.Refresh(False)
  1760. def OnVolumeIsosurfMap(self, event):
  1761. """!Set surface attribute"""
  1762. self.SetMapObjAttrb(nvizType='volume', winId=event.GetId())
  1763. def OnVolumeIsosurfCheck(self, event):
  1764. """!Isosurface checked (->load) or unchecked (->unload)"""
  1765. index = event.GetSelection()
  1766. list = self.FindWindowById(self.win['volume']['isosurfs'])
  1767. data = self.mapWindow.GetSelectedLayer(type='nviz')['volume']
  1768. id = data['object']['id']
  1769. isosurfId = event.GetSelection()
  1770. if list.IsChecked(index):
  1771. self.mapWindow.nvizClass.SetIsosurfaceTransp(id, isosurfId, False, "0")
  1772. else:
  1773. # disable -> make transparent
  1774. self.mapWindow.nvizClass.SetIsosurfaceTransp(id, isosurfId, False, "255")
  1775. if self.parent.statusbarWin['render'].IsChecked():
  1776. self.mapWindow.Refresh(False)
  1777. def OnVolumeIsosurfSelect(self, event):
  1778. """!Isosurface item selected"""
  1779. winUp = self.FindWindowById(self.win['volume']['btnIsosurfMoveUp'])
  1780. winDown = self.FindWindowById(self.win['volume']['btnIsosurfMoveDown'])
  1781. selection = event.GetSelection()
  1782. if selection == 0:
  1783. winUp.Enable(False)
  1784. if not winDown.IsEnabled():
  1785. winDown.Enable()
  1786. elif selection == self.FindWindowById(event.GetId()).GetCount() - 1:
  1787. winDown.Enable(False)
  1788. if not winUp.IsEnabled():
  1789. winUp.Enable()
  1790. else:
  1791. if not winDown.IsEnabled():
  1792. winDown.Enable()
  1793. if not winUp.IsEnabled():
  1794. winUp.Enable()
  1795. # update dialog
  1796. layer = self.mapWindow.GetSelectedLayer()
  1797. data = self.mapWindow.GetSelectedLayer(type='nviz')['volume']['isosurface'][selection]
  1798. self.UpdateVolumeIsosurfPage(layer, data)
  1799. def OnVolumeIsosurfAdd(self, event):
  1800. """!Add new isosurface to the list"""
  1801. list = self.FindWindowById(self.win['volume']['isosurfs'])
  1802. level = self.FindWindowById(self.win['volume']['topo']['const']).GetValue()
  1803. sel = list.GetSelection()
  1804. if sel < 0 or sel >= list.GetCount() - 1:
  1805. item = list.Append(item="%s %s" % (_("Level"), str(level)))
  1806. else:
  1807. list.Insert(item="%s %s" % (_("Level"), str(level)),
  1808. pos=sel+1) # append
  1809. item = sel + 1
  1810. list.Check(item)
  1811. list.SetSelection(item)
  1812. layer = self.mapWindow.GetSelectedLayer()
  1813. data = self.mapWindow.GetSelectedLayer(type='nviz')['volume']
  1814. id = data['object']['id']
  1815. # collect properties
  1816. isosurfData = {}
  1817. for attrb in ('topo', 'color', 'mask',
  1818. 'transp', 'shine', 'emit'):
  1819. if attrb == 'topo':
  1820. isosurfData[attrb] = {}
  1821. win = self.FindWindowById(self.win['volume'][attrb]['const'])
  1822. isosurfData[attrb]['value'] = win.GetValue()
  1823. else:
  1824. uwin = self.FindWindowById(self.win['volume'][attrb]['use'])
  1825. sel = uwin.GetSelection()
  1826. if self.win['volume'][attrb]['required']:
  1827. sel += 1
  1828. if sel == 0: # unset
  1829. continue
  1830. isosurfData[attrb] = {}
  1831. if sel == 1: # map
  1832. isosurfData[attrb]['map'] = True
  1833. vwin = self.FindWindowById(self.win['volume'][attrb]['map'])
  1834. value = vwin.GetValue()
  1835. else: # const
  1836. isosurfData[attrb]['map'] = False
  1837. vwin = self.FindWindowById(self.win['volume'][attrb]['const'])
  1838. if vwin.GetName() == "color":
  1839. value = self._getColorString(vwin.GetValue())
  1840. else:
  1841. value = vwin.GetValue()
  1842. isosurfData[attrb]['value'] = value
  1843. data['isosurface'].insert(item, isosurfData)
  1844. # add isosurface
  1845. self.mapWindow.nvizClass.AddIsosurface(id, level)
  1846. # use by default 3d raster map for color
  1847. self.mapWindow.nvizClass.SetIsosurfaceColor(id, item, True, str(layer.name))
  1848. # update buttons
  1849. self.UpdateIsosurfButtons(list)
  1850. if self.parent.statusbarWin['render'].IsChecked():
  1851. self.mapWindow.Refresh(False)
  1852. event.Skip()
  1853. def OnVolumeIsosurfDelete(self, event):
  1854. """!Remove isosurface from list"""
  1855. list = self.FindWindowById(self.win['volume']['isosurfs'])
  1856. # remove item from list
  1857. isosurfId = list.GetSelection()
  1858. list.Delete(isosurfId)
  1859. # select last item
  1860. if list.GetCount() > 0:
  1861. list.SetSelection(list.GetCount()-1)
  1862. layer = self.mapWindow.GetSelectedLayer()
  1863. data = self.mapWindow.GetSelectedLayer(type='nviz')['volume']
  1864. id = data['object']['id']
  1865. # delete isosurface
  1866. del data['isosurface'][isosurfId]
  1867. self.mapWindow.nvizClass.DeleteIsosurface(id, isosurfId)
  1868. # update buttons
  1869. self.UpdateIsosurfButtons(list)
  1870. if self.parent.statusbarWin['render'].IsChecked():
  1871. self.mapWindow.Refresh(False)
  1872. event.Skip()
  1873. def OnVolumeIsosurfMoveUp(self, event):
  1874. """!Move isosurface up in the list"""
  1875. list = self.FindWindowById(self.win['volume']['isosurfs'])
  1876. sel = list.GetSelection()
  1877. if sel < 1:
  1878. return # this should not happen
  1879. layer = self.mapWindow.GetSelectedLayer()
  1880. data = self.mapWindow.GetSelectedLayer(type='nviz')['volume']
  1881. id = data['object']['id']
  1882. # move item up
  1883. text = list.GetStringSelection()
  1884. list.Insert(item=text, pos=sel-1)
  1885. list.Check(sel-1)
  1886. list.SetSelection(sel-1)
  1887. list.Delete(sel+1)
  1888. data['isosurface'].insert(sel-1, data['isosurface'][sel])
  1889. del data['isosurface'][sel+1]
  1890. self.mapWindow.nvizClass.MoveIsosurface(id, sel, True)
  1891. # update buttons
  1892. self.UpdateIsosurfButtons(list)
  1893. if self.parent.statusbarWin['render'].IsChecked():
  1894. self.mapWindow.Refresh(False)
  1895. event.Skip()
  1896. def OnVolumeIsosurfMoveDown(self, event):
  1897. """!Move isosurface dowm in the list"""
  1898. list = self.FindWindowById(self.win['volume']['isosurfs'])
  1899. sel = list.GetSelection()
  1900. if sel >= list.GetCount() - 1:
  1901. return # this should not happen
  1902. layer = self.mapWindow.GetSelectedLayer()
  1903. data = self.mapWindow.GetSelectedLayer(type='nviz')['volume']
  1904. id = data['object']['id']
  1905. # move item up
  1906. text = list.GetStringSelection()
  1907. list.Insert(item=text, pos=sel+2)
  1908. list.Check(sel+2)
  1909. list.SetSelection(sel+2)
  1910. list.Delete(sel)
  1911. data['isosurface'].insert(sel+2, data['isosurface'][sel])
  1912. del data['isosurface'][sel]
  1913. self.mapWindow.nvizClass.MoveIsosurface(id, sel, False)
  1914. # update buttons
  1915. self.UpdateIsosurfButtons(list)
  1916. if self.parent.statusbarWin['render'].IsChecked():
  1917. self.mapWindow.Refresh(False)
  1918. event.Skip()
  1919. def UpdatePage(self, pageId):
  1920. """!Update dialog (selected page)"""
  1921. self.pageChanging = True
  1922. layer = self.mapWindow.GetSelectedLayer()
  1923. data = self.mapWindow.GetSelectedLayer(type='nviz')
  1924. if pageId == 'view':
  1925. max = self.mapWindow.view['z-exag']['value'] * 10
  1926. hmin = self.mapWindow.iview['height']['min']
  1927. hmax = self.mapWindow.iview['height']['max']
  1928. for control in ('spin', 'slider'):
  1929. self.FindWindowById(self.win['view']['z-exag'][control]).SetRange(1,
  1930. max)
  1931. self.FindWindowById(self.win['view']['height'][control]).SetRange(hmin,
  1932. hmax)
  1933. elif pageId in ('surface', 'vector', 'volume'):
  1934. if self.notebook.GetSelection() != self.page[pageId]['id']:
  1935. for page in ('surface', 'vector', 'volume'):
  1936. if self.page[page]['id'] > -1:
  1937. self.notebook.RemovePage(self.page[page]['id'])
  1938. self.page[page]['id'] = -1
  1939. oldpanel = wx.FindWindowById(self.page[page]['panel'])
  1940. oldpanel.Hide()
  1941. self.page[pageId]['id'] = 1
  1942. self.page['settings']['id'] = 2
  1943. panel = wx.FindWindowById(self.page[pageId]['panel'])
  1944. self.notebook.InsertPage(n=self.page[pageId]['id'],
  1945. page=panel,
  1946. text=" %s " % _("Layer properties"),
  1947. select=True)
  1948. if pageId == 'surface':
  1949. self.UpdateSurfacePage(layer, data['surface'])
  1950. elif pageId == 'vector':
  1951. self.UpdateVectorPage(layer, data['vector'])
  1952. elif pageId == 'volume':
  1953. self.UpdateVectorPage(layer, data['vector'])
  1954. self.notebook.Update()
  1955. self.pageChanging = False
  1956. def UpdateSurfacePage(self, layer, data):
  1957. #
  1958. # attributes
  1959. #
  1960. for attr in ('topo', 'color'): # required
  1961. if layer and layer.type == 'raster':
  1962. self.FindWindowById(self.win['surface'][attr]['map']).SetValue(layer.name)
  1963. else:
  1964. self.FindWindowById(self.win['surface'][attr]['map']).SetValue('')
  1965. self.SetMapObjUseMap(nvizType='surface',
  1966. attrb=attr, map=True) # -> map
  1967. if data['attribute'].has_key('color'):
  1968. value = data['attribute']['color']['value']
  1969. if data['attribute']['color']['map']:
  1970. self.FindWindowById(self.win['surface']['color']['map']).SetValue(value)
  1971. else: # constant
  1972. color = map(int, value.split(':'))
  1973. self.FindWindowById(self.win['surface']['color']['const']).SetColour(color)
  1974. self.SetMapObjUseMap(nvizType='surface',
  1975. attrb=attr, map=data['attribute']['color']['map'])
  1976. self.SetMapObjUseMap(nvizType='surface',
  1977. attrb='shine', map=data['attribute']['shine']['map'])
  1978. value = data['attribute']['shine']['value']
  1979. if data['attribute']['shine']['map']:
  1980. self.FindWindowById(self.win['surface']['shine']['map']).SetValue(value)
  1981. else:
  1982. self.FindWindowById(self.win['surface']['shine']['const']).SetValue(value)
  1983. #
  1984. # draw
  1985. #
  1986. for control, dict in data['draw'].iteritems():
  1987. if control == 'all': # skip 'all' property
  1988. continue
  1989. if control == 'resolution':
  1990. self.FindWindowById(self.win['surface']['draw']['res-coarse']).SetValue(dict['coarse'])
  1991. self.FindWindowById(self.win['surface']['draw']['res-fine']).SetValue(dict['fine'])
  1992. continue
  1993. if control == 'mode':
  1994. if dict['desc']['mode'] == 'coarse':
  1995. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(0)
  1996. elif dict['desc']['mode'] == 'fine':
  1997. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(1)
  1998. else: # both
  1999. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(2)
  2000. if dict['desc']['style'] == 'wire':
  2001. self.FindWindowById(self.win['surface']['draw']['style']).SetSelection(0)
  2002. else: # surface
  2003. self.FindWindowById(self.win['surface']['draw']['style']).SetSelection(1)
  2004. if dict['desc']['shading'] == 'flat':
  2005. self.FindWindowById(self.win['surface']['draw']['shading']).SetSelection(0)
  2006. else: # gouraud
  2007. self.FindWindowById(self.win['surface']['draw']['shading']).SetSelection(1)
  2008. continue
  2009. value = dict['value']
  2010. win = self.FindWindowById(self.win['surface']['draw'][control])
  2011. name = win.GetName()
  2012. if name == "selection":
  2013. win.SetSelection(value)
  2014. elif name == "colour":
  2015. color = map(int, value.split(':'))
  2016. win.SetColour(color)
  2017. else:
  2018. win.SetValue(value)
  2019. # enable/disable res widget + set draw mode
  2020. self.SetSurfaceMode()
  2021. color = self.FindWindowById(self.win['surface']['draw']['wire-color'])
  2022. def UpdateVectorPage(self, layer, data):
  2023. vInfo = gcmd.RunCommand('v.info',
  2024. parent = self,
  2025. read = True,
  2026. flags = 't',
  2027. map = layer.name)
  2028. if not vInfo:
  2029. return
  2030. npoints = nprimitives = 0
  2031. for line in vInfo.splitlines():
  2032. key, value = line.split('=')
  2033. if key == 'map3d':
  2034. mapIs3D = int(value)
  2035. elif key == 'points':
  2036. npoints = int(value)
  2037. nprimitives = npoints
  2038. elif key in ('lines',
  2039. 'boundaries',
  2040. 'centroids',
  2041. 'faces',
  2042. 'kernels'):
  2043. nprimitives += int(value)
  2044. if mapIs3D:
  2045. desc = _("Vector map <%s> is 3D") % layer.name
  2046. enable = False
  2047. else:
  2048. desc = _("Vector map <%s> is 2D") % layer.name
  2049. enable = True
  2050. desc += " - " + _("%(primitives)d primitives (%(points)d points)") % \
  2051. { 'primitives' : nprimitives, 'points' : npoints }
  2052. self.FindWindowById(self.win['vector']['lines']['flat']).Enable(enable)
  2053. for v in ('lines', 'points'):
  2054. self.FindWindowById(self.win['vector'][v]['surface']).Enable(enable)
  2055. self.FindWindowById(self.win['vector'][v]['height']['slider']).Enable(enable)
  2056. self.FindWindowById(self.win['vector'][v]['height']['spin']).Enable(enable)
  2057. self.FindWindowById(self.win['vector']['desc']).SetLabel(desc)
  2058. #
  2059. # lines
  2060. #
  2061. showLines = self.FindWindowById(self.win['vector']['lines']['show'])
  2062. if data['lines'].has_key('object'):
  2063. showLines.SetValue(True)
  2064. else:
  2065. showLines.SetValue(False)
  2066. if nprimitives - npoints > 0:
  2067. showLines.Enable(True)
  2068. else:
  2069. showLines.Enable(False)
  2070. self.UpdateVectorShow('lines',
  2071. showLines.IsChecked())
  2072. width = self.FindWindowById(self.win['vector']['lines']['width'])
  2073. width.SetValue(data['lines']['width']['value'])
  2074. color = self.FindWindowById(self.win['vector']['lines']['color'])
  2075. color.SetValue(map(int, data['lines']['color']['value'].split(':')))
  2076. for vtype in ('lines', 'points'):
  2077. if vtype == 'lines':
  2078. display = self.FindWindowById(self.win['vector']['lines']['flat'])
  2079. if data[vtype]['mode']['type'] == 'flat':
  2080. display.SetSelection(1)
  2081. else:
  2082. display.SetSelection(0)
  2083. if data[vtype]['mode']['type'] == 'surface':
  2084. rasters = self.mapWindow.GetLayerNames('raster')
  2085. surface = self.FindWindowById(self.win['vector'][vtype]['surface'])
  2086. surface.SetItems(rasters)
  2087. if len(rasters) > 0:
  2088. surface.SetStringSelection(data[vtype]['mode']['surface'])
  2089. for type in ('slider', 'spin'):
  2090. win = self.FindWindowById(self.win['vector']['lines']['height'][type])
  2091. win.SetValue(data['lines']['height']['value'])
  2092. #
  2093. # points
  2094. #
  2095. showPoints = self.FindWindowById(self.win['vector']['points']['show'])
  2096. if data['points'].has_key('object'):
  2097. showPoints.SetValue(True)
  2098. else:
  2099. showPoints.SetValue(False)
  2100. if npoints > 0:
  2101. showPoints.Enable(True)
  2102. else:
  2103. showPoints.Enable(False)
  2104. self.UpdateVectorShow('points',
  2105. showPoints.IsChecked())
  2106. # size, width, marker, color
  2107. for prop in ('size', 'width', 'marker', 'color'):
  2108. win = self.FindWindowById(self.win['vector']['points'][prop])
  2109. name = win.GetName()
  2110. if name == 'selection':
  2111. win.SetSelection(data['points'][prop]['value'])
  2112. elif name == 'color':
  2113. color = map(int, data['points'][prop]['value'].split(':'))
  2114. win.SetValue(color)
  2115. else:
  2116. win.SetValue(data['points'][prop]['value'])
  2117. # height
  2118. for type in ('slider', 'spin'):
  2119. win = self.FindWindowById(self.win['vector']['points']['height'][type])
  2120. win.SetValue(data['points']['height']['value'])
  2121. def UpdateVolumePage(self, layer, data):
  2122. """!Update volume layer properties page"""
  2123. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2124. #
  2125. # draw
  2126. #
  2127. for control, dict in data['draw'].iteritems():
  2128. if control == 'all': # skip 'all' property
  2129. continue
  2130. win = self.FindWindowById(self.win['volume']['draw'][control])
  2131. if control == 'shading':
  2132. if data['draw']['shading']['desc'] == 'flat':
  2133. value = 0
  2134. else:
  2135. value = 1
  2136. else:
  2137. value = dict['value']
  2138. if win.GetName() == "selection":
  2139. win.SetSelection(value)
  2140. else:
  2141. win.SetValue(value)
  2142. self.SetIsosurfaceMode(data['draw']['shading']['value'])
  2143. self.SetIsosurfaceResolution(data['draw']['resolution']['value'])
  2144. self.UpdateVolumeIsosurfPage(layer, data['attribute'])
  2145. def UpdateVolumeIsosurfPage(self, layer, data):
  2146. """!Update dialog -- isosurface attributes"""
  2147. #
  2148. # isosurface attributes
  2149. #
  2150. for attrb in ('topo', 'color', 'mask',
  2151. 'transp', 'shine', 'emit'):
  2152. # check required first
  2153. if attrb == 'topo':
  2154. self.FindWindowById(self.win['volume'][attrb]['const']).SetValue(0)
  2155. continue
  2156. if attrb == 'color':
  2157. if layer and layer.type == '3d-raster':
  2158. self.FindWindowById(self.win['volume'][attrb]['map']).SetValue(layer.name)
  2159. else:
  2160. self.FindWindowById(self.win['volume'][attrb]['map']).SetValue('')
  2161. self.SetMapObjUseMap(nvizType='volume',
  2162. attrb=attrb, map=True) # -> map
  2163. continue
  2164. # skip empty attributes
  2165. if not data.has_key(attrb):
  2166. continue
  2167. value = data[attrb]['value']
  2168. if attrb == 'color':
  2169. if data[attrb]['map']:
  2170. self.FindWindowById(self.win['volume'][attrb]['map']).SetValue(value)
  2171. else: # constant
  2172. color = map(int, value.split(':'))
  2173. self.FindWindowById(self.win['volume'][attrb]['const']).SetColour(color)
  2174. else:
  2175. if data[attrb]['map']:
  2176. win = self.FindWindowById(self.win['volume'][attrb]['map'])
  2177. else:
  2178. win = self.FindWindowById(self.win['volume'][attrb]['const'])
  2179. win.SetValue(value)
  2180. self.SetMapObjUseMap(nvizType='volume',
  2181. attrb=attrb, map=data[attrb]['map'])
  2182. def SetPage(self, name):
  2183. """!Get named page"""
  2184. self.notebook.SetSelection(self.page[name]['id'])
  2185. class ViewPositionWindow(wx.Window):
  2186. """!Position control window (for NvizToolWindow)"""
  2187. def __init__(self, parent, id, mapwindow,
  2188. pos=wx.DefaultPosition,
  2189. size=wx.DefaultSize):
  2190. self.mapWindow = mapwindow
  2191. wx.Window.__init__(self, parent, id, pos, size)
  2192. self.SetBackgroundColour("WHITE")
  2193. self.pdc = wx.PseudoDC()
  2194. self.pdc.SetBrush(wx.Brush(colour='dark green', style=wx.SOLID))
  2195. self.pdc.SetPen(wx.Pen(colour='dark green', width=2, style=wx.SOLID))
  2196. self.Draw()
  2197. self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x: None)
  2198. self.Bind(wx.EVT_PAINT, self.OnPaint)
  2199. # self.Bind(wx.EVT_MOTION, self.OnMouse)
  2200. self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
  2201. def Draw(self, pos=None):
  2202. w, h = self.GetClientSize()
  2203. if pos is None:
  2204. x = self.mapWindow.view['pos']['x']
  2205. y = self.mapWindow.view['pos']['y']
  2206. x = x * w
  2207. y = y * h
  2208. else:
  2209. x, y = pos
  2210. self.pdc.Clear()
  2211. self.pdc.BeginDrawing()
  2212. self.pdc.DrawLine(w / 2, h / 2, x, y)
  2213. self.pdc.DrawCircle(x, y, 5)
  2214. self.pdc.EndDrawing()
  2215. def OnPaint(self, event):
  2216. dc = wx.BufferedPaintDC(self)
  2217. dc.SetBackground(wx.Brush("White"))
  2218. dc.Clear()
  2219. self.PrepareDC(dc)
  2220. self.pdc.DrawToDC(dc)
  2221. def OnMouse(self, event):
  2222. if event.LeftIsDown():
  2223. x, y = event.GetPosition()
  2224. self.Draw(pos=(x, y))
  2225. self.Refresh(False)
  2226. w, h = self.GetClientSize()
  2227. x = float(x) / w
  2228. y = float(y) / h
  2229. if x >= 0 and x <= 1.0:
  2230. self.mapWindow.view['pos']['x'] = x
  2231. if y >= 0 and y <= 1.0:
  2232. self.mapWindow.view['pos']['y'] = y
  2233. event = wxUpdateView(zExag=False)
  2234. wx.PostEvent(self.mapWindow, event)
  2235. self.mapWindow.render['quick'] = True
  2236. self.mapWindow.Refresh(eraseBackground=False)
  2237. elif event.LeftUp():
  2238. self.mapWindow.render['quick'] = False
  2239. self.mapWindow.Refresh(eraseBackground=False)
  2240. event.Skip()