nviz_tools.py 124 KB

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