nviz_tools.py 108 KB

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