nviz_tools.py 105 KB

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