nviz_tools.py 157 KB

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