nviz_tools.py 139 KB

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