nviz_tools.py 124 KB

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