nviz_tools.py 138 KB

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