nviz_tools.py 139 KB

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