nviz_tools.py 137 KB

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