nviz_tools.py 139 KB

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