nviz_tools.py 158 KB

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