nviz_tools.py 107 KB

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