nviz_tools.py 109 KB

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