nviz_tools.py 203 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643
  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 gmail.com> (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. import colorrules
  41. from preferences import globalSettings as UserSettings
  42. try:
  43. from nviz_mapdisp import wxUpdateView, wxUpdateLight, wxUpdateProperties,\
  44. wxUpdateCPlane
  45. import wxnviz
  46. except ImportError:
  47. pass
  48. from debug import Debug
  49. class ScrolledPanel(SP.ScrolledPanel):
  50. """!Custom ScrolledPanel to avoid strange behaviour concerning focus"""
  51. def __init__(self, parent):
  52. SP.ScrolledPanel.__init__(self, parent = parent, id = wx.ID_ANY)
  53. def OnChildFocus(self, event):
  54. pass
  55. class NTCValidator(wx.PyValidator):
  56. """!validates input in textctrls, taken from wxpython demo"""
  57. def __init__(self, flag = None):
  58. wx.PyValidator.__init__(self)
  59. self.flag = flag
  60. self.Bind(wx.EVT_CHAR, self.OnChar)
  61. def Clone(self):
  62. return NTCValidator(self.flag)
  63. def OnChar(self, event):
  64. key = event.GetKeyCode()
  65. if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255:
  66. event.Skip()
  67. return
  68. if self.flag == 'DIGIT_ONLY' and chr(key) in string.digits + '.-':
  69. event.Skip()
  70. return
  71. if not wx.Validator_IsSilent():
  72. wx.Bell()
  73. # Returning without calling even.Skip eats the event before it
  74. # gets to the text control
  75. return
  76. class NumTextCtrl(wx.TextCtrl):
  77. """!Class derived from wx.TextCtrl for numerical values only"""
  78. def __init__(self, parent, **kwargs):
  79. ## self.precision = kwargs.pop('prec')
  80. wx.TextCtrl.__init__(self, parent = parent,
  81. validator = NTCValidator(flag = 'DIGIT_ONLY'), **kwargs)
  82. def SetValue(self, value):
  83. super(NumTextCtrl, self).SetValue( str(value))
  84. def GetValue(self):
  85. val = super(NumTextCtrl, self).GetValue()
  86. if val == '':
  87. val = '0'
  88. try:
  89. return float(val)
  90. except ValueError:
  91. val = ''.join(''.join(val.split('-')).split('.'))
  92. return float(val)
  93. def SetRange(self, min, max):
  94. pass
  95. class FloatSlider(wx.Slider):
  96. """!Class derived from wx.Slider for floats"""
  97. def __init__(self, **kwargs):
  98. Debug.msg(1, "FloatSlider.__init__()")
  99. wx.Slider.__init__(self, **kwargs)
  100. self.coef = 1.
  101. #init range
  102. self.minValueOrig = 0
  103. self.maxValueOrig = 1
  104. def SetValue(self, value):
  105. value *= self.coef
  106. if abs(value) < 1 and value != 0:
  107. while abs(value) < 1:
  108. value *= 100
  109. self.coef *= 100
  110. super(FloatSlider, self).SetRange(self.minValueOrig * self.coef, self.maxValueOrig * self.coef)
  111. super(FloatSlider, self).SetValue(value)
  112. Debug.msg(4, "FloatSlider.SetValue(): value = %f" % value)
  113. def SetRange(self, minValue, maxValue):
  114. self.coef = 1.
  115. self.minValueOrig = minValue
  116. self.maxValueOrig = maxValue
  117. if abs(minValue) < 1 or abs(maxValue) < 1:
  118. while (abs(minValue) < 1 and minValue != 0) or (abs(maxValue) < 1 and maxValue != 0):
  119. minValue *= 100
  120. maxValue *= 100
  121. self.coef *= 100
  122. super(FloatSlider, self).SetValue(super(FloatSlider, self).GetValue() * self.coef)
  123. super(FloatSlider, self).SetRange(minValue, maxValue)
  124. Debug.msg(4, "FloatSlider.SetRange(): minValue = %f, maxValue = %f" % (minValue, maxValue))
  125. def GetValue(self):
  126. val = super(FloatSlider, self).GetValue()
  127. Debug.msg(4, "FloatSlider.GetValue(): value = %f" % (val/self.coef))
  128. return val/self.coef
  129. class NvizToolWindow(FN.FlatNotebook):
  130. """!Nviz (3D view) tools panel
  131. """
  132. def __init__(self, parent, display, id = wx.ID_ANY,
  133. style = globalvar.FNPageStyle|FN.FNB_NO_X_BUTTON|FN.FNB_NO_NAV_BUTTONS,
  134. **kwargs):
  135. Debug.msg(5, "NvizToolWindow.__init__()")
  136. self.parent = parent # GMFrame
  137. self.mapDisplay = display
  138. self.mapWindow = display.GetWindow()
  139. self._display = self.mapWindow.GetDisplay()
  140. if globalvar.hasAgw:
  141. kwargs['agwStyle'] = style
  142. else:
  143. kwargs['style'] = style
  144. FN.FlatNotebook.__init__(self, parent, id, **kwargs)
  145. self.SetTabAreaColour(globalvar.FNPageColor)
  146. self.win = {} # window ids
  147. self.page = {} # page ids
  148. # view page
  149. self.AddPage(page = self._createViewPage(),
  150. text = " %s " % _("View"))
  151. # data page
  152. self.AddPage(page = self._createDataPage(),
  153. text = " %s " % _("Data"))
  154. # appearance page
  155. self.AddPage(page = self._createAppearancePage(),
  156. text = " %s " % _("Appearance"))
  157. # analysis page
  158. self.AddPage(page = self._createAnalysisPage(),
  159. text = " %s " % _("Analysis"))
  160. self.UpdateSettings()
  161. self.pageChanging = False
  162. self.vetoGSelectEvt = False #when setting map, event is invoked
  163. self.mapWindow.render['quick'] = False
  164. self.mapWindow.Refresh(False)
  165. # bindings
  166. self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
  167. self.Bind(wx.EVT_SIZE, self.OnSize)
  168. Debug.msg(3, "NvizToolWindow.__init__()")
  169. self.Update()
  170. wx.CallAfter(self.SetPage, 'view')
  171. wx.CallAfter(self.UpdateScrolling, (self.foldpanelData, self.foldpanelAppear,
  172. self.foldpanelAnalysis))
  173. wx.CallAfter(self.SetInitialMaps)
  174. def SetInitialMaps(self):
  175. """!Set initial raster and vector map"""
  176. for l_type in ('raster', 'vector', '3d-raster'):
  177. selectedLayer = self.mapWindow.GetSelectedLayer()
  178. layers = self.mapWindow.Map.GetListOfLayers(l_type = l_type, l_active = True)
  179. if selectedLayer in layers:
  180. selection = selectedLayer.GetName()
  181. else:
  182. try:
  183. selection = layers[0].GetName()
  184. except:
  185. continue
  186. if l_type == 'raster':
  187. self.FindWindowById(self.win['surface']['map']).SetValue(selection)
  188. self.FindWindowById(self.win['fringe']['map']).SetValue(selection)
  189. elif l_type == 'vector':
  190. self.FindWindowById(self.win['vector']['map']).SetValue(selection)
  191. elif l_type == '3d-raster':
  192. self.FindWindowById(self.win['volume']['map']).SetValue(selection)
  193. def UpdateState(self, **kwargs):
  194. if 'view' in kwargs:
  195. self.mapWindow.view = kwargs['view']
  196. self.FindWindowById(self.win['view']['position']).data = kwargs['view']
  197. if 'iview' in kwargs:
  198. self.mapWindow.iview = kwargs['iview']
  199. if 'light' in kwargs:
  200. self.mapWindow.light = kwargs['light']
  201. self.FindWindowById(self.win['light']['position']).data = kwargs['light']
  202. def OnPageChanged(self, event):
  203. new = event.GetSelection()
  204. # self.ChangeSelection(new)
  205. def PostViewEvent(self, zExag = False):
  206. """!Change view settings"""
  207. event = wxUpdateView(zExag = zExag)
  208. wx.PostEvent(self.mapWindow, event)
  209. def OnSize(self, event):
  210. """!After window is resized, update scrolling"""
  211. # workaround to resize captionbars of foldpanelbar
  212. wx.CallAfter(self.UpdateScrolling, (self.foldpanelData, self.foldpanelAppear,
  213. self.foldpanelAnalysis))
  214. event.Skip()
  215. def OnPressCaption(self, event):
  216. """!When foldpanel item collapsed/expanded, update scrollbars"""
  217. foldpanel = event.GetBar().GetGrandParent().GetParent()
  218. wx.CallAfter(self.UpdateScrolling, (foldpanel,))
  219. event.Skip()
  220. def UpdateScrolling(self, foldpanels):
  221. """!Update scrollbars in foldpanel"""
  222. for foldpanel in foldpanels:
  223. length = foldpanel.GetPanelsLength(collapsed = 0, expanded = 0)
  224. # virtual width is set to fixed value to suppress GTK warning
  225. foldpanel.GetParent().SetVirtualSize((100, length[2]))
  226. foldpanel.GetParent().Layout()
  227. def _createViewPage(self):
  228. """!Create view settings page"""
  229. panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
  230. panel.SetupScrolling(scroll_x = False)
  231. self.page['view'] = { 'id' : 0,
  232. 'notebook' : self.GetId()}
  233. pageSizer = wx.BoxSizer(wx.VERTICAL)
  234. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  235. label = " %s " % (_("Control View")))
  236. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  237. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 10)
  238. self.win['view'] = {}
  239. # position
  240. posSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  241. self._createCompass(panel = panel, sizer = posSizer, type = 'view')
  242. view = ViewPositionWindow(panel, size = (175, 175),
  243. mapwindow = self.mapWindow)
  244. self.win['view']['position'] = view.GetId()
  245. posSizer.Add(item = view,
  246. pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
  247. gridSizer.Add(item = posSizer, pos = (0, 0))
  248. # perspective
  249. # set initial defaults here (or perhaps in a default values file), not in user settings
  250. self._createControl(panel, data = self.win['view'], name = 'persp',
  251. range = (1,100),
  252. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  253. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Perspective:")),
  254. pos = (1, 0), flag = wx.ALIGN_CENTER)
  255. gridSizer.Add(item = self.FindWindowById(self.win['view']['persp']['slider']), pos = (2, 0),
  256. flag = wx.ALIGN_CENTER)
  257. gridSizer.Add(item = self.FindWindowById(self.win['view']['persp']['text']), pos = (3, 0),
  258. flag = wx.ALIGN_CENTER)
  259. # twist
  260. self._createControl(panel, data = self.win['view'], name = 'twist',
  261. range = (-180,180),
  262. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  263. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Twist:")),
  264. pos = (1, 1), flag = wx.ALIGN_CENTER)
  265. gridSizer.Add(item = self.FindWindowById(self.win['view']['twist']['slider']), pos = (2, 1))
  266. gridSizer.Add(item = self.FindWindowById(self.win['view']['twist']['text']), pos = (3, 1),
  267. flag = wx.ALIGN_CENTER)
  268. # height + z-exag
  269. self._createControl(panel, data = self.win['view'], name = 'height', sliderHor = False,
  270. range = (0, 1),
  271. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  272. self._createControl(panel, data = self.win['view'], name = 'z-exag', sliderHor = False,
  273. range = (0, 10), floatSlider = True,
  274. bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedText))
  275. self.FindWindowById(self.win['view']['z-exag']['slider']).SetValue(1)
  276. self.FindWindowById(self.win['view']['z-exag']['text']).SetValue(1)
  277. heightSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  278. heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:")),
  279. pos = (0, 0), flag = wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL, span = (1, 2))
  280. heightSizer.Add(item = self.FindWindowById(self.win['view']['height']['slider']),
  281. flag = wx.ALIGN_RIGHT, pos = (1, 0))
  282. heightSizer.Add(item = self.FindWindowById(self.win['view']['height']['text']),
  283. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT, pos = (1, 1))
  284. heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Z-exag:")),
  285. pos = (0, 2), flag = wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL, span = (1, 2))
  286. heightSizer.Add(item = self.FindWindowById(self.win['view']['z-exag']['slider']),
  287. flag = wx.ALIGN_RIGHT, pos = (1, 2))
  288. heightSizer.Add(item = self.FindWindowById(self.win['view']['z-exag']['text']),
  289. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
  290. wx.BOTTOM | wx.RIGHT, pos = (1, 3))
  291. gridSizer.Add(item = heightSizer, pos = (0, 1), flag = wx.ALIGN_CENTER)
  292. # view setup + reset
  293. viewSizer = wx.BoxSizer(wx.HORIZONTAL)
  294. viewSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY,
  295. label = _("Look:")),
  296. flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL,
  297. border = 5)
  298. here = wx.ToggleButton(panel, id = wx.ID_ANY, label = _("here"))
  299. here.Bind(wx.EVT_TOGGLEBUTTON, self.OnLookAt)
  300. here.SetName('here')
  301. viewSizer.Add(item = here, flag = wx.TOP|wx.BOTTOM|wx.LEFT|wx.ALIGN_CENTER_VERTICAL,
  302. border = 5)
  303. center = wx.Button(panel, id = wx.ID_ANY, label = _("center"))
  304. center.Bind(wx.EVT_BUTTON, self.OnLookAt)
  305. center.SetName('center')
  306. viewSizer.Add(item = center, flag = wx.TOP|wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL,
  307. border = 5)
  308. top = wx.Button(panel, id = wx.ID_ANY, label = _("top"))
  309. top.Bind(wx.EVT_BUTTON, self.OnLookAt)
  310. top.SetName('top')
  311. viewSizer.Add(item = top, flag = wx.TOP|wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL,
  312. border = 5)
  313. reset = wx.Button(panel, id = wx.ID_ANY, label = _("reset"))
  314. reset.SetToolTipString(_("Reset to default view"))
  315. reset.Bind(wx.EVT_BUTTON, self.OnResetView)
  316. viewSizer.Add(item = reset, proportion = 0,
  317. flag = wx.TOP|wx.BOTTOM|wx.RIGHT| wx.ALIGN_RIGHT,
  318. border = 5)
  319. gridSizer.AddGrowableCol(2)
  320. gridSizer.Add(item = viewSizer, pos = (4, 0), span = (1, 3),
  321. flag = wx.EXPAND)
  322. # body
  323. boxSizer.Add(item = gridSizer, proportion = 1,
  324. flag = wx.ALL | wx.EXPAND, border = 2)
  325. pageSizer.Add(item = boxSizer, proportion = 0,
  326. flag = wx.EXPAND | wx.ALL,
  327. border = 3)
  328. box = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  329. label = " %s " % (_("Image Appearance")))
  330. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  331. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  332. gridSizer.AddGrowableCol(0)
  333. # background color
  334. self.win['view']['background'] = {}
  335. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  336. label = _("Background color:")),
  337. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  338. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  339. colour = UserSettings.Get(group = 'nviz', key = 'view',
  340. subkey = ['background', 'color']),
  341. size = globalvar.DIALOG_COLOR_SIZE)
  342. self.win['view']['background']['color'] = color.GetId()
  343. color.Bind(csel.EVT_COLOURSELECT, self.OnBgColor)
  344. gridSizer.Add(item = color, pos = (0, 1))
  345. boxSizer.Add(item = gridSizer, proportion = 1,
  346. flag = wx.ALL | wx.EXPAND, border = 3)
  347. pageSizer.Add(item = boxSizer, proportion = 0,
  348. flag = wx.EXPAND | wx.LEFT | wx.RIGHT,
  349. border = 3)
  350. panel.SetSizer(pageSizer)
  351. return panel
  352. def _createDataPage(self):
  353. """!Create data (surface, vector, volume) settings page"""
  354. self.mainPanelData = ScrolledPanel(parent = self)
  355. self.mainPanelData.SetupScrolling(scroll_x = False)
  356. ## style = fpb.CaptionBarStyle()
  357. ## style.SetCaptionStyle(fpb.CAPTIONBAR_FILLED_RECTANGLE)
  358. ## style.SetFirstColour(wx.Color(250,250,250))
  359. try:# wxpython <= 2.8.10
  360. self.foldpanelData = fpb.FoldPanelBar(parent = self.mainPanelData, id = wx.ID_ANY,
  361. style = fpb.FPB_DEFAULT_STYLE,
  362. extraStyle = fpb.FPB_SINGLE_FOLD)
  363. except:
  364. try:# wxpython >= 2.8.11
  365. self.foldpanelData = fpb.FoldPanelBar(parent = self.mainPanelData, id = wx.ID_ANY,
  366. agwStyle = fpb.FPB_SINGLE_FOLD)
  367. except: # to be sure
  368. self.foldpanelData = fpb.FoldPanelBar(parent = self.mainPanelData, id = wx.ID_ANY,
  369. style = fpb.FPB_SINGLE_FOLD)
  370. self.foldpanelData.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
  371. # surface page
  372. self.surfacePanel = self.foldpanelData.AddFoldPanel(_("Surface"), collapsed = False)
  373. self.foldpanelData.AddFoldPanelWindow(self.surfacePanel,
  374. window = self._createSurfacePage(parent = self.surfacePanel), flags = fpb.FPB_ALIGN_WIDTH)
  375. self.EnablePage("surface", enabled = False)
  376. # constant page
  377. constantPanel = self.foldpanelData.AddFoldPanel(_("Constant surface"), collapsed = True)
  378. self.foldpanelData.AddFoldPanelWindow(constantPanel,
  379. window = self._createConstantPage(parent = constantPanel), flags = fpb.FPB_ALIGN_WIDTH)
  380. self.EnablePage("constant", enabled = False)
  381. # vector page
  382. vectorPanel = self.foldpanelData.AddFoldPanel(_("Vector"), collapsed = True)
  383. self.foldpanelData.AddFoldPanelWindow(vectorPanel,
  384. window = self._createVectorPage(parent = vectorPanel), flags = fpb.FPB_ALIGN_WIDTH)
  385. self.EnablePage("vector", enabled = False)
  386. # volume page
  387. volumePanel = self.foldpanelData.AddFoldPanel(_("Volume"), collapsed = True)
  388. self.foldpanelData.AddFoldPanelWindow(volumePanel,
  389. window = self._createVolumePage(parent = volumePanel), flags = fpb.FPB_ALIGN_WIDTH)
  390. self.EnablePage("volume", enabled = False)
  391. ## self.foldpanelData.ApplyCaptionStyleAll(style)
  392. sizer = wx.BoxSizer(wx.VERTICAL)
  393. sizer.Add(self.foldpanelData, proportion = 1, flag = wx.EXPAND)
  394. self.mainPanelData.SetSizer(sizer)
  395. self.mainPanelData.Layout()
  396. self.mainPanelData.Fit()
  397. return self.mainPanelData
  398. def _createAppearancePage(self):
  399. """!Create data (surface, vector, volume) settings page"""
  400. self.mainPanelAppear = ScrolledPanel(parent = self)
  401. self.mainPanelAppear.SetupScrolling(scroll_x = False)
  402. try:# wxpython <= 2.8.10
  403. self.foldpanelAppear = fpb.FoldPanelBar(parent = self.mainPanelAppear, id = wx.ID_ANY,
  404. style = fpb.FPB_DEFAULT_STYLE,
  405. extraStyle = fpb.FPB_SINGLE_FOLD)
  406. except:
  407. try:# wxpython >= 2.8.11
  408. self.foldpanelAppear = fpb.FoldPanelBar(parent = self.mainPanelAppear, id = wx.ID_ANY,
  409. agwStyle = fpb.FPB_SINGLE_FOLD)
  410. except: # to be sure
  411. self.foldpanelAppear = fpb.FoldPanelBar(parent = self.mainPanelAppear, id = wx.ID_ANY,
  412. style = fpb.FPB_SINGLE_FOLD)
  413. self.foldpanelAppear.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
  414. # light page
  415. lightPanel = self.foldpanelAppear.AddFoldPanel(_("Lighting"), collapsed = False)
  416. self.foldpanelAppear.AddFoldPanelWindow(lightPanel,
  417. window = self._createLightPage(parent = lightPanel), flags = fpb.FPB_ALIGN_WIDTH)
  418. # fringe page
  419. fringePanel = self.foldpanelAppear.AddFoldPanel(_("Fringe"), collapsed = True)
  420. self.foldpanelAppear.AddFoldPanelWindow(fringePanel,
  421. window = self._createFringePage(parent = fringePanel), flags = fpb.FPB_ALIGN_WIDTH)
  422. self.EnablePage('fringe', False)
  423. # decoration page
  424. decorationPanel = self.foldpanelAppear.AddFoldPanel(_("Decorations"), collapsed = True)
  425. self.foldpanelAppear.AddFoldPanelWindow(decorationPanel,
  426. window = self._createDecorationPage(parent = decorationPanel), flags = fpb.FPB_ALIGN_WIDTH)
  427. sizer = wx.BoxSizer(wx.VERTICAL)
  428. sizer.Add(self.foldpanelAppear, proportion = 1, flag = wx.EXPAND)
  429. self.mainPanelAppear.SetSizer(sizer)
  430. self.mainPanelAppear.Layout()
  431. self.mainPanelAppear.Fit()
  432. return self.mainPanelAppear
  433. def _createAnalysisPage(self):
  434. """!Create data analysis (cutting planes, ...) page"""
  435. self.mainPanelAnalysis = ScrolledPanel(parent = self)
  436. self.mainPanelAnalysis.SetupScrolling(scroll_x = False)
  437. self.foldpanelAnalysis = fpb.FoldPanelBar(parent = self.mainPanelAnalysis, id = wx.ID_ANY,
  438. style = fpb.FPB_SINGLE_FOLD)
  439. self.foldpanelAnalysis.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
  440. # cutting planes page
  441. cplanePanel = self.foldpanelAnalysis.AddFoldPanel(_("Cutting planes"), collapsed = False)
  442. self.foldpanelAnalysis.AddFoldPanelWindow(cplanePanel,
  443. window = self._createCPlanePage(parent = cplanePanel), flags = fpb.FPB_ALIGN_WIDTH)
  444. sizer = wx.BoxSizer(wx.VERTICAL)
  445. sizer.Add(self.foldpanelAnalysis, proportion = 1, flag = wx.EXPAND)
  446. self.mainPanelAnalysis.SetSizer(sizer)
  447. self.mainPanelAnalysis.Layout()
  448. self.mainPanelAnalysis.Fit()
  449. return self.mainPanelAnalysis
  450. def _createSurfacePage(self, parent):
  451. """!Create view settings page"""
  452. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  453. self.page['surface'] = { 'id' : 0,
  454. 'notebook' : self.foldpanelData.GetId() }
  455. pageSizer = wx.BoxSizer(wx.VERTICAL)
  456. self.win['surface'] = {}
  457. # selection
  458. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  459. label = " %s " % (_("Raster map")))
  460. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  461. rmaps = gselect.Select(parent = panel, type = 'raster',
  462. onPopup = self.GselectOnPopup)
  463. rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetRaster)
  464. self.win['surface']['map'] = rmaps.GetId()
  465. desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
  466. self.win['surface']['desc'] = desc.GetId()
  467. boxSizer.Add(item = rmaps, proportion = 0,
  468. flag = wx.ALL,
  469. border = 3)
  470. boxSizer.Add(item = desc, proportion = 0,
  471. flag = wx.ALL,
  472. border = 3)
  473. pageSizer.Add(item = boxSizer, proportion = 0,
  474. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  475. border = 3)
  476. #
  477. # draw
  478. #
  479. self.win['surface']['draw'] = {}
  480. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  481. label = " %s " % (_("Draw")))
  482. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  483. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  484. gridSizer.AddGrowableCol(3)
  485. # mode
  486. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  487. label = _("Mode:")),
  488. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  489. mode = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
  490. choices = [_("coarse"),
  491. _("fine"),
  492. _("both")])
  493. mode.SetName("selection")
  494. mode.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  495. self.win['surface']['draw']['mode'] = mode.GetId()
  496. gridSizer.Add(item = mode, flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND,
  497. pos = (0, 1),span = (1, 2))
  498. # shading
  499. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  500. label = _("Shading:")),
  501. pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
  502. shade = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
  503. choices = [_("flat"),
  504. _("gouraud")])
  505. shade.SetName("selection")
  506. self.win['surface']['draw']['shading'] = shade.GetId()
  507. shade.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  508. gridSizer.Add(item = shade, flag = wx.ALIGN_CENTER_VERTICAL,
  509. pos = (0, 4))
  510. # set to all
  511. all = wx.Button(panel, id = wx.ID_ANY, label = _("Set to all"))
  512. all.SetToolTipString(_("Use draw settings for all loaded surfaces"))
  513. all.Bind(wx.EVT_BUTTON, self.OnSurfaceModeAll)
  514. gridSizer.Add(item = all, flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  515. pos = (3, 4))
  516. self.win['surface']['all'] = all.GetId()
  517. # resolution coarse
  518. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  519. label = _("Coarse mode:")),
  520. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  521. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  522. label = _("resolution:")),
  523. pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  524. resC = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  525. initial = 6,
  526. min = 1,
  527. max = 100)
  528. resC.SetName("value")
  529. self.win['surface']['draw']['res-coarse'] = resC.GetId()
  530. resC.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
  531. gridSizer.Add(item = resC, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
  532. # Coarse style
  533. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  534. label = _("style:")),
  535. pos = (3, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  536. style = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  537. choices = [_("wire"),
  538. _("surface")])
  539. style.SetName("selection")
  540. self.win['surface']['draw']['style'] = style.GetId()
  541. style.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
  542. gridSizer.Add(item = style, flag = wx.ALIGN_CENTER_VERTICAL,
  543. pos = (3, 2))
  544. # color
  545. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  546. size = globalvar.DIALOG_COLOR_SIZE)
  547. color.SetName("colour")
  548. color.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceWireColor)
  549. color.SetToolTipString(_("Change wire color"))
  550. self.win['surface']['draw']['wire-color'] = color.GetId()
  551. gridSizer.Add(item = color, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
  552. pos = (3, 3))
  553. # resolution fine
  554. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  555. label = _("Fine mode:")),
  556. pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  557. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  558. label = _("resolution:")),
  559. pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  560. resF = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  561. initial = 3,
  562. min = 1,
  563. max = 100)
  564. resF.SetName("value")
  565. self.win['surface']['draw']['res-fine'] = resF.GetId()
  566. resF.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
  567. gridSizer.Add(item = resF, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
  568. boxSizer.Add(item = gridSizer, proportion = 1,
  569. flag = wx.ALL | wx.EXPAND, border = 3)
  570. pageSizer.Add(item = boxSizer, proportion = 0,
  571. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  572. border = 3)
  573. #
  574. # surface attributes
  575. #
  576. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  577. label = " %s " % (_("Surface attributes")))
  578. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  579. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  580. gridSizer.AddGrowableCol(2)
  581. # type
  582. self.win['surface']['attr'] = {}
  583. row = 0
  584. for code, attrb in (('color', _("Color")),
  585. ('mask', _("Mask")),
  586. ('transp', _("Transparency")),
  587. ('shine', _("Shininess"))):
  588. self.win['surface'][code] = {}
  589. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  590. label = attrb + ':'),
  591. pos = (row, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  592. use = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  593. choices = [_("map")])
  594. if code not in ('color', 'shine'):
  595. use.Insert(item = _("unset"), pos = 0)
  596. self.win['surface'][code]['required'] = False
  597. else:
  598. self.win['surface'][code]['required'] = True
  599. if code != 'mask':
  600. use.Append(item = _('constant'))
  601. self.win['surface'][code]['use'] = use.GetId()
  602. use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
  603. gridSizer.Add(item = use, flag = wx.ALIGN_CENTER_VERTICAL,
  604. pos = (row, 1))
  605. map = gselect.Select(parent = panel, id = wx.ID_ANY,
  606. # size = globalvar.DIALOG_GSELECT_SIZE,
  607. size = (-1, -1),
  608. type = "raster")
  609. self.win['surface'][code]['map'] = map.GetId() - 1 # FIXME
  610. map.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
  611. gridSizer.Add(item = map, flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND,
  612. pos = (row, 2))
  613. if code == 'color':
  614. color = UserSettings.Get(group = 'nviz', key = 'surface', subkey = ['color', 'value'])
  615. value = csel.ColourSelect(panel, id = wx.ID_ANY,
  616. colour = color,
  617. size = globalvar.DIALOG_COLOR_SIZE)
  618. value.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceMap)
  619. elif code == 'mask':
  620. value = None
  621. else:
  622. value = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  623. initial = 0)
  624. value.SetRange(minVal = 0, maxVal = 100)
  625. value.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
  626. if value:
  627. self.win['surface'][code]['const'] = value.GetId()
  628. value.Enable(False)
  629. gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
  630. pos = (row, 3))
  631. else:
  632. self.win['surface'][code]['const'] = None
  633. self.SetMapObjUseMap(nvizType = 'surface',
  634. attrb = code) # -> enable map / disable constant
  635. row += 1
  636. boxSizer.Add(item = gridSizer, proportion = 0,
  637. flag = wx.ALL | wx.EXPAND, border = 3)
  638. pageSizer.Add(item = boxSizer, proportion = 0,
  639. flag = wx.EXPAND | wx.ALL,
  640. border = 3)
  641. #
  642. # position
  643. #
  644. self.win['surface']['position'] = {}
  645. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  646. label = " %s " % (_("Position")))
  647. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  648. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  649. gridSizer.AddGrowableCol(3)
  650. # position
  651. self._createControl(panel, data = self.win['surface'], name = 'position',
  652. range = (-10000, 10000), floatSlider = True,
  653. bind = (self.OnSurfacePosition, self.OnSurfacePositionChanged, self.OnSurfacePositionText))
  654. axis = wx.Choice (parent = panel, id = wx.ID_ANY, size = (75, -1),
  655. choices = ["X",
  656. "Y",
  657. "Z"])
  658. reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
  659. reset.SetToolTipString(_("Reset to default position"))
  660. reset.Bind(wx.EVT_BUTTON, self.OnResetSurfacePosition)
  661. self.win['surface']['position']['reset'] = reset.GetId()
  662. self.win['surface']['position']['axis'] = axis.GetId()
  663. axis.SetSelection(0)
  664. axis.Bind(wx.EVT_CHOICE, self.OnSurfaceAxis)
  665. pslide = self.FindWindowById(self.win['surface']['position']['slider'])
  666. ptext = self.FindWindowById(self.win['surface']['position']['text'])
  667. ptext.SetValue('0')
  668. gridSizer.Add(item = axis, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
  669. gridSizer.Add(item = pslide, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 1))
  670. gridSizer.Add(item = ptext, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 2))
  671. gridSizer.Add(item = reset, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, pos = (0, 3))
  672. boxSizer.Add(item = gridSizer, proportion = 1,
  673. flag = wx.ALL | wx.EXPAND, border = 3)
  674. box.SetSizer(boxSizer)
  675. box.Layout()
  676. pageSizer.Add(item = boxSizer, proportion = 1,
  677. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  678. border = 3)
  679. #
  680. # mask
  681. #
  682. ## box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  683. ## label = " %s " % (_("Mask")))
  684. ## boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  685. ## gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  686. ##
  687. ## gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  688. ## label = _("Mask zeros:")),
  689. ## pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  690. ##
  691. ## elev = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  692. ## label = _("by elevation"))
  693. ## elev.Enable(False) # TODO: not implemented yet
  694. ## gridSizer.Add(item = elev, pos = (0, 1))
  695. ##
  696. ## color = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  697. ## label = _("by color"))
  698. ## color.Enable(False) # TODO: not implemented yet
  699. ## gridSizer.Add(item = color, pos = (0, 2))
  700. ##
  701. ## boxSizer.Add(item = gridSizer, proportion = 1,
  702. ## flag = wx.ALL | wx.EXPAND, border = 3)
  703. ## pageSizer.Add(item = boxSizer, proportion = 0,
  704. ## flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  705. ## border = 3)
  706. panel.SetSizer(pageSizer)
  707. panel.Layout()
  708. panel.Fit()
  709. return panel
  710. def _createCPlanePage(self, parent):
  711. """!Create cutting planes page"""
  712. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  713. self.page['cplane'] = { 'id' : 4,
  714. 'notebook' : self.foldpanelData.GetId() }
  715. self.win['cplane'] = {}
  716. pageSizer = wx.BoxSizer(wx.VERTICAL)
  717. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  718. label = " %s " % (_("Cutting planes")))
  719. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  720. horSizer = wx.BoxSizer(wx.HORIZONTAL)
  721. # planes
  722. horSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  723. label = _("Active cutting plane:")),
  724. flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
  725. choice = wx.Choice(parent = panel, id = wx.ID_ANY, choices = [])
  726. self.win['cplane']['planes'] = choice.GetId()
  727. choice.Bind(wx.EVT_CHOICE, self.OnCPlaneSelection)
  728. horSizer.Add(item = choice, flag = wx.ALL, border = 5)
  729. # shading
  730. horSizer.Add(item = wx.Size(-1, -1), proportion = 1)
  731. horSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  732. label = _("Shading:")),
  733. flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
  734. choices = [_("clear"),
  735. _("top color"),
  736. _("bottom color"),
  737. _("blend"),
  738. _("shaded")]
  739. choice = wx.Choice(parent = panel, id = wx.ID_ANY, choices = choices)
  740. self.win['cplane']['shading'] = choice.GetId()
  741. choice.Bind(wx.EVT_CHOICE, self.OnCPlaneShading)
  742. horSizer.Add(item = choice, flag = wx.ALL, border = 5)
  743. boxSizer.Add(item = horSizer, flag = wx.EXPAND)
  744. gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  745. # XYZ position
  746. self.win['cplane']['position'] = {}
  747. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  748. label = _("X:")),
  749. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  750. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  751. label = _("Y:")),
  752. pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  753. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  754. label = _("Height:")),
  755. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  756. self._createControl(panel, data = self.win['cplane']['position'], name = 'x', size = 250,
  757. range = (-1000, 1000), sliderHor = True, floatSlider = True,
  758. bind = (self.OnCPlaneChanging, self.OnCPlaneChangeDone, self.OnCPlaneChangeText))
  759. self.FindWindowById(self.win['cplane']['position']['x']['slider']).SetValue(0)
  760. self.FindWindowById(self.win['cplane']['position']['x']['text']).SetValue(0)
  761. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['position']['x']['slider']),
  762. pos = (0, 1), flag = wx.EXPAND|wx.ALIGN_RIGHT)
  763. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['position']['x']['text']),
  764. pos = (0, 2),
  765. flag = wx.ALIGN_CENTER)
  766. self._createControl(panel, data = self.win['cplane']['position'], name = 'y', size = 250,
  767. range = (-1000, 1000), sliderHor = True, floatSlider = True,
  768. bind = (self.OnCPlaneChanging, self.OnCPlaneChangeDone, self.OnCPlaneChangeText))
  769. self.FindWindowById(self.win['cplane']['position']['y']['slider']).SetValue(0)
  770. self.FindWindowById(self.win['cplane']['position']['y']['text']).SetValue(0)
  771. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['position']['y']['slider']),
  772. pos = (1, 1), flag = wx.EXPAND|wx.ALIGN_RIGHT)
  773. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['position']['y']['text']),
  774. pos = (1, 2),
  775. flag = wx.ALIGN_CENTER)
  776. posButton = wx.ToggleButton(parent = panel, id = wx.ID_ANY, label = _("On display"))
  777. posButton.Bind(wx.EVT_TOGGLEBUTTON, self.OnCPlanePos)
  778. posButton.SetName('cplaneHere')
  779. self.win['cplane']['cplaneHere'] = posButton.GetId()
  780. gridSizer.Add(item = posButton, pos = (0, 3), span = (2, 1), flag = wx.EXPAND)
  781. self._createControl(panel, data = self.win['cplane']['position'], name = 'z', size = 250,
  782. range = (-1000, 1000), sliderHor = True,
  783. bind = (self.OnCPlaneChanging, self.OnCPlaneChangeDone, self.OnCPlaneChangeText))
  784. self.FindWindowById(self.win['cplane']['position']['z']['slider']).SetValue(0)
  785. self.FindWindowById(self.win['cplane']['position']['z']['text']).SetValue(0)
  786. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['position']['z']['slider']),
  787. pos = (2, 1), flag = wx.EXPAND|wx.ALIGN_RIGHT)
  788. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['position']['z']['text']),
  789. pos = (2, 2),
  790. flag = wx.ALIGN_CENTER)
  791. # rotation
  792. self.win['cplane']['rotation'] = {}
  793. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  794. label = _("Rotation:")),
  795. pos = (3, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  796. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  797. label = _("Tilt:")),
  798. pos = (4, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  799. self._createControl(panel, data = self.win['cplane']['rotation'], name = 'rot', size = 250,
  800. range = (0, 360), sliderHor = True,
  801. bind = (self.OnCPlaneChanging, self.OnCPlaneChangeDone, self.OnCPlaneChangeText))
  802. self.FindWindowById(self.win['cplane']['rotation']['rot']['slider']).SetValue(0)
  803. self.FindWindowById(self.win['cplane']['rotation']['rot']['text']).SetValue(0)
  804. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['rotation']['rot']['slider']),
  805. pos = (3, 1), flag = wx.EXPAND|wx.ALIGN_RIGHT)
  806. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['rotation']['rot']['text']),
  807. pos = (3, 2),
  808. flag = wx.ALIGN_CENTER)
  809. self._createControl(panel, data = self.win['cplane']['rotation'], name = 'tilt', size = 250,
  810. range = (0, 360), sliderHor = True,
  811. bind = (self.OnCPlaneChanging, self.OnCPlaneChangeDone, self.OnCPlaneChangeText))
  812. self.FindWindowById(self.win['cplane']['rotation']['tilt']['slider']).SetValue(0)
  813. self.FindWindowById(self.win['cplane']['rotation']['tilt']['text']).SetValue(0)
  814. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['rotation']['tilt']['slider']),
  815. pos = (4, 1), flag = wx.EXPAND|wx.ALIGN_RIGHT)
  816. gridSizer.Add(item = self.FindWindowById(self.win['cplane']['rotation']['tilt']['text']),
  817. pos = (4, 2),
  818. flag = wx.ALIGN_CENTER)
  819. boxSizer.Add(gridSizer, proportion = 0, flag = wx.EXPAND|wx.ALL, border = 5)
  820. horSizer = wx.BoxSizer(wx.HORIZONTAL)
  821. horSizer.Add(item = wx.Size(-1, -1), proportion = 1, flag = wx.ALL, border = 5)
  822. # reset
  823. reset = wx.Button(parent = panel, id = wx.ID_ANY, label = _("Reset"))
  824. self.win['cplane']['reset'] = reset.GetId()
  825. reset.Bind(wx.EVT_BUTTON, self.OnCPlaneReset)
  826. horSizer.Add(item = reset, flag = wx.ALL, border = 5)
  827. boxSizer.Add(horSizer, proportion = 0, flag = wx.EXPAND)
  828. pageSizer.Add(boxSizer, proportion = 0, flag = wx.EXPAND)
  829. panel.SetSizer(pageSizer)
  830. panel.Fit()
  831. return panel
  832. def _createConstantPage(self, parent):
  833. """!Create constant page"""
  834. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  835. self.page['constant'] = { 'id' : 1,
  836. 'notebook' : self.foldpanelData.GetId() }
  837. self.win['constant'] = {}
  838. pageSizer = wx.BoxSizer(wx.VERTICAL)
  839. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  840. label = " %s " % (_("Constant surface")))
  841. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  842. horsizer = wx.BoxSizer(wx.HORIZONTAL)
  843. surface = wx.ComboBox(parent = panel, id = wx.ID_ANY,
  844. style = wx.CB_SIMPLE | wx.CB_READONLY,
  845. choices = [])
  846. self.win['constant']['surface'] = surface.GetId()
  847. surface.Bind(wx.EVT_COMBOBOX, self.OnConstantSelection)
  848. horsizer.Add(surface, proportion = 1, flag = wx.EXPAND|wx.RIGHT, border = 20)
  849. addNew = wx.Button(panel, id = wx.ID_ANY, label = _("New"))
  850. addNew.Bind(wx.EVT_BUTTON, self.OnNewConstant)
  851. self.win['constant']['new'] = addNew.GetId()
  852. delete = wx.Button(panel, id = wx.ID_ANY, label = _("Delete"))
  853. delete.Bind(wx.EVT_BUTTON, self.OnDeleteConstant)
  854. self.win['constant']['delete'] = delete.GetId()
  855. horsizer.Add(item = addNew, proportion = 0, flag = wx.RIGHT|wx.LEFT, border = 3)
  856. horsizer.Add(item = delete, proportion = 0, flag = wx.RIGHT|wx.LEFT, border = 3)
  857. boxSizer.Add(item = horsizer, proportion = 0, flag = wx.ALL|wx.EXPAND,
  858. border = 5)
  859. gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  860. # fine resolution
  861. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  862. label = _("Fine resolution:")),
  863. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  864. resF = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  865. initial = 3,
  866. min = 1,
  867. max = 100)
  868. resF.SetName("value")
  869. self.win['constant']['resolution'] = resF.GetId()
  870. resF.Bind(wx.EVT_SPINCTRL, self.OnSetConstantProp)
  871. gridSizer.Add(item = resF, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
  872. # value
  873. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  874. label = _("Value:")), pos = (1, 0),
  875. flag = wx.ALIGN_CENTER_VERTICAL)
  876. value = wx.SpinCtrl(panel, id = wx.ID_ANY,
  877. min = -1e9, max = 1e9,
  878. size = (65, -1))
  879. self.win['constant']['value'] = value.GetId()
  880. value.Bind(wx.EVT_SPINCTRL, self.OnSetConstantProp)
  881. gridSizer.Add(item = value, pos = (1, 1))
  882. # transparency
  883. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  884. label = _("Transparency:")), pos = (2, 0),
  885. flag = wx.ALIGN_CENTER_VERTICAL)
  886. transp = wx.SpinCtrl(panel, id = wx.ID_ANY,
  887. min = 0, max = 100,
  888. size = (65, -1))
  889. self.win['constant']['transp'] = transp.GetId()
  890. transp.Bind(wx.EVT_SPINCTRL, self.OnSetConstantProp)
  891. gridSizer.Add(item = transp, pos = (2, 1))
  892. # color
  893. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  894. label = _("Color:")), pos = (3, 0),
  895. flag = wx.ALIGN_CENTER_VERTICAL)
  896. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  897. colour = (0,0,0),
  898. size = globalvar.DIALOG_COLOR_SIZE)
  899. self.win['constant']['color'] = color.GetId()
  900. color.Bind(csel.EVT_COLOURSELECT, self.OnSetConstantProp)
  901. gridSizer.Add(item = color, pos = (3, 1))
  902. boxSizer.Add(item = gridSizer, proportion = 0, flag = wx.ALL,
  903. border = 5)
  904. pageSizer.Add(item = boxSizer, proportion = 0,
  905. flag = wx.EXPAND | wx.ALL,
  906. border = 3)
  907. panel.SetSizer(pageSizer)
  908. panel.Fit()
  909. return panel
  910. def _createVectorPage(self, parent):
  911. """!Create view settings page"""
  912. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  913. self.page['vector'] = { 'id' : 2,
  914. 'notebook' : self.foldpanelData.GetId() }
  915. pageSizer = wx.BoxSizer(wx.VERTICAL)
  916. self.win['vector'] = {}
  917. # selection
  918. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  919. label = " %s " % (_("Vector map")))
  920. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  921. vmaps = gselect.Select(parent = panel, type = 'vector',
  922. onPopup = self.GselectOnPopup)
  923. vmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetVector)
  924. self.win['vector']['map'] = vmaps.GetId()
  925. desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
  926. self.win['vector']['desc'] = desc.GetId()
  927. boxSizer.Add(item = vmaps, proportion = 0,
  928. flag = wx.ALL,
  929. border = 3)
  930. boxSizer.Add(item = desc, proportion = 0,
  931. flag = wx.ALL,
  932. border = 3)
  933. pageSizer.Add(item = boxSizer, proportion = 0,
  934. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  935. border = 3)
  936. #
  937. # vector lines
  938. #
  939. self.win['vector']['lines'] = {}
  940. showLines = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  941. label = _("Show vector lines"))
  942. showLines.SetValue(True)
  943. self.win['vector']['lines']['show'] = showLines.GetId()
  944. showLines.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
  945. pageSizer.Add(item = showLines, proportion = 0,
  946. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
  947. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  948. label = " %s " % (_("Vector lines")))
  949. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  950. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  951. gridSizer.AddGrowableCol(5)
  952. # width
  953. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  954. label = _("Line:")),
  955. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  956. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  957. label = _("width:")),
  958. pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL |
  959. wx.ALIGN_RIGHT)
  960. width = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  961. initial = 1,
  962. min = 0,
  963. max = 100)
  964. width.SetValue(1)
  965. self.win['vector']['lines']['width'] = width.GetId()
  966. width.Bind(wx.EVT_SPINCTRL, self.OnVectorLines)
  967. gridSizer.Add(item = width, pos = (0, 2),
  968. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  969. # color
  970. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  971. label = _("color:")),
  972. pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL |
  973. wx.ALIGN_RIGHT)
  974. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  975. colour = (0,0,0),
  976. size = globalvar.DIALOG_COLOR_SIZE)
  977. self.win['vector']['lines']['color'] = color.GetId()
  978. color.Bind(csel.EVT_COLOURSELECT, self.OnVectorLines)
  979. gridSizer.Add(item = color, pos = (0, 4), flag = wx.ALIGN_CENTER_VERTICAL |
  980. wx.ALIGN_LEFT)
  981. # display
  982. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  983. label = _("Display")),
  984. pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL |
  985. wx.ALIGN_LEFT)
  986. display = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
  987. choices = [_("on surface(s):"),
  988. _("flat")])
  989. self.win['vector']['lines']['flat'] = display.GetId()
  990. display.Bind(wx.EVT_CHOICE, self.OnVectorDisplay)
  991. gridSizer.Add(item = display, flag = wx.ALIGN_CENTER_VERTICAL |
  992. wx.ALIGN_LEFT|wx.EXPAND, pos = (1, 1), span = (1,4))
  993. # height
  994. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  995. label = _("Height above surface:")),
  996. pos = (2, 5), flag = wx.ALIGN_BOTTOM|wx.EXPAND)
  997. surface = wx.CheckListBox(parent = panel, id = wx.ID_ANY, size = (-1, 60),
  998. choices = [], style = wx.LB_NEEDED_SB)
  999. surface.Bind(wx.EVT_CHECKLISTBOX, self.OnVectorSurface)
  1000. self.win['vector']['lines']['surface'] = surface.GetId()
  1001. gridSizer.Add(item = surface,
  1002. pos = (2, 0), span = (3, 5),
  1003. flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND)
  1004. self._createControl(panel, data = self.win['vector']['lines'], name = 'height', size = -1,
  1005. range = (0, 500), sliderHor = True,
  1006. bind = (self.OnVectorHeight, self.OnVectorHeightFull, self.OnVectorHeightText))
  1007. self.FindWindowById(self.win['vector']['lines']['height']['slider']).SetValue(0)
  1008. self.FindWindowById(self.win['vector']['lines']['height']['text']).SetValue(0)
  1009. gridSizer.Add(item = self.FindWindowById(self.win['vector']['lines']['height']['slider']),
  1010. pos = (3, 5), flag = wx.EXPAND|wx.ALIGN_RIGHT)
  1011. gridSizer.Add(item = self.FindWindowById(self.win['vector']['lines']['height']['text']),
  1012. pos = (4, 5),
  1013. flag = wx.ALIGN_CENTER)
  1014. boxSizer.Add(item = gridSizer, proportion = 1,
  1015. flag = wx.ALL | wx.EXPAND, border = 3)
  1016. pageSizer.Add(item = boxSizer, proportion = 0,
  1017. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1018. border = 3)
  1019. #
  1020. # vector points
  1021. #
  1022. self.win['vector']['points'] = {}
  1023. showPoints = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1024. label = _("Show vector points"))
  1025. showPoints.SetValue(True)
  1026. self.win['vector']['points']['show'] = showPoints.GetId()
  1027. showPoints.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
  1028. pageSizer.Add(item = showPoints, proportion = 0,
  1029. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
  1030. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1031. label = " %s " % (_("Vector points")))
  1032. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1033. vertSizer = wx.BoxSizer(wx.VERTICAL)
  1034. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  1035. gridSizer.AddGrowableCol(0)
  1036. gridSizer.AddGrowableCol(2)
  1037. gridSizer.AddGrowableCol(4)
  1038. gridSizer.AddGrowableCol(6)
  1039. # icon size
  1040. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1041. label = _("Icon:")),
  1042. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1043. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1044. label = _("size:")),
  1045. pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL |
  1046. wx.ALIGN_RIGHT)
  1047. isize = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  1048. initial = 1,
  1049. min = 1,
  1050. max = 1e6)
  1051. isize.SetName('value')
  1052. isize.SetValue(100)
  1053. self.win['vector']['points']['size'] = isize.GetId()
  1054. isize.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
  1055. isize.Bind(wx.EVT_TEXT, self.OnVectorPoints)
  1056. gridSizer.Add(item = isize, pos = (0, 2),
  1057. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  1058. # icon color
  1059. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1060. label = _("color:")),
  1061. pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL |
  1062. wx.ALIGN_RIGHT)
  1063. icolor = csel.ColourSelect(panel, id = wx.ID_ANY,
  1064. size = globalvar.DIALOG_COLOR_SIZE)
  1065. icolor.SetName("color")
  1066. icolor.SetColour((0,0,255))
  1067. self.win['vector']['points']['color'] = icolor.GetId()
  1068. icolor.Bind(csel.EVT_COLOURSELECT, self.OnVectorPoints)
  1069. gridSizer.Add(item = icolor, flag = wx.ALIGN_CENTER_VERTICAL |
  1070. wx.ALIGN_LEFT,
  1071. pos = (0, 4))
  1072. # icon width - seems to do nothing
  1073. ## gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1074. ## label = _("width")),
  1075. ## pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL |
  1076. ## wx.ALIGN_RIGHT)
  1077. ##
  1078. ## iwidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  1079. ## initial = 1,
  1080. ## min = 1,
  1081. ## max = 1e6)
  1082. ## iwidth.SetName('value')
  1083. ## iwidth.SetValue(100)
  1084. ## self.win['vector']['points']['width'] = iwidth.GetId()
  1085. ## iwidth.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
  1086. ## iwidth.Bind(wx.EVT_TEXT, self.OnVectorPoints)
  1087. ## gridSizer.Add(item = iwidth, pos = (1, 2),
  1088. ## flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
  1089. # icon symbol
  1090. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1091. label = _("symbol:")),
  1092. pos = (0, 5), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  1093. isym = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  1094. choices = UserSettings.Get(group = 'nviz', key = 'vector',
  1095. subkey = ['points', 'marker'], internal = True))
  1096. isym.SetName("selection")
  1097. self.win['vector']['points']['marker'] = isym.GetId()
  1098. isym.Bind(wx.EVT_CHOICE, self.OnVectorPoints)
  1099. gridSizer.Add(item = isym, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
  1100. pos = (0, 6))
  1101. # thematic mapping
  1102. self.win['vector']['points']['thematic'] = {}
  1103. checkThematic = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1104. label = _("use thematic mapping for vector points"))
  1105. self.win['vector']['points']['thematic']['check'] = checkThematic.GetId()
  1106. checkThematic.Bind(wx.EVT_CHECKBOX, self.OnCheckThematic)
  1107. checkThematic.SetValue(False)
  1108. gridSizer.Add(item = checkThematic, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
  1109. pos = (1, 1), span = (1, 5))
  1110. setThematic = wx.Button(parent = panel, id = wx.ID_ANY,
  1111. label = _("Set options..."))
  1112. self.win['vector']['points']['thematic']['button'] = setThematic.GetId()
  1113. setThematic.Bind(wx.EVT_BUTTON, self.OnSetThematic)
  1114. gridSizer.Add(item = setThematic, flag = wx.ALIGN_CENTER_VERTICAL,
  1115. pos = (1, 6))
  1116. vertSizer.Add(gridSizer, proportion = 0, flag = wx.EXPAND, border = 0)
  1117. # high
  1118. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  1119. gridSizer.AddGrowableCol(1)
  1120. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1121. label = _("Display on surface(s):")),
  1122. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1123. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1124. label = _("Height above surface:")),
  1125. pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  1126. surface = wx.CheckListBox(parent = panel, id = wx.ID_ANY, size = (-1, 60),
  1127. choices = [], style = wx.LB_NEEDED_SB)
  1128. surface.Bind(wx.EVT_CHECKLISTBOX, self.OnVectorSurface)
  1129. self.win['vector']['points']['surface'] = surface.GetId()
  1130. gridSizer.Add(item = surface,
  1131. pos = (1, 0), span = (3, 1),
  1132. flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND)
  1133. self._createControl(panel, data = self.win['vector']['points'], name = 'height', size = -1,
  1134. range = (0, 500),
  1135. bind = (self.OnVectorHeight, self.OnVectorHeightFull, self.OnVectorHeightText))
  1136. self.FindWindowById(self.win['vector']['points']['height']['slider']).SetValue(0)
  1137. self.FindWindowById(self.win['vector']['points']['height']['text']).SetValue(0)
  1138. gridSizer.Add(item = self.FindWindowById(self.win['vector']['points']['height']['slider']),
  1139. pos = (2, 1),flag = wx.EXPAND|wx.ALIGN_CENTER_VERTICAL)
  1140. gridSizer.Add(item = self.FindWindowById(self.win['vector']['points']['height']['text']),
  1141. pos = (3, 1),
  1142. flag = wx.ALIGN_CENTER)
  1143. vertSizer.Add(gridSizer, proportion = 0, flag = wx.EXPAND, border = 0)
  1144. boxSizer.Add(item = vertSizer, proportion = 1,
  1145. flag = wx.ALL | wx.EXPAND, border = 3)
  1146. pageSizer.Add(item = boxSizer, proportion = 0,
  1147. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1148. border = 3)
  1149. panel.SetSizer(pageSizer)
  1150. panel.Fit()
  1151. return panel
  1152. def GselectOnPopup(self, ltype, exclude = False):
  1153. """Update gselect.Select() items"""
  1154. maps = list()
  1155. for layer in self.mapWindow.Map.GetListOfLayers(l_type = ltype, l_active = True):
  1156. maps.append(layer.GetName())
  1157. maps.append('aaaaaaaa')
  1158. return maps, exclude
  1159. def _createVolumePage(self, parent):
  1160. """!Create view settings page"""
  1161. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  1162. self.page['volume'] = { 'id' : 3,
  1163. 'notebook' : self.foldpanelData.GetId() }
  1164. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1165. self.win['volume'] = {}
  1166. # selection
  1167. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1168. label = " %s " % (_("3D raster map")))
  1169. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1170. rmaps = gselect.Select(parent = panel, type = '3d-raster',
  1171. onPopup = self.GselectOnPopup)
  1172. rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetRaster3D)
  1173. self.win['volume']['map'] = rmaps.GetId()
  1174. desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
  1175. self.win['volume']['desc'] = desc.GetId()
  1176. boxSizer.Add(item = rmaps, proportion = 0,
  1177. flag = wx.ALL,
  1178. border = 3)
  1179. boxSizer.Add(item = desc, proportion = 0,
  1180. flag = wx.ALL,
  1181. border = 3)
  1182. pageSizer.Add(item = boxSizer, proportion = 0,
  1183. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1184. border = 3)
  1185. #
  1186. # draw
  1187. #
  1188. self.win['volume']['draw'] = {}
  1189. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1190. label = " %s " % (_("Draw")))
  1191. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1192. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  1193. ## gridSizer.AddGrowableCol(4)
  1194. # mode
  1195. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1196. label = _("Mode:")),
  1197. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1198. mode = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
  1199. choices = [_("isosurfaces"),
  1200. _("slices")])
  1201. mode.SetSelection(0)
  1202. mode.SetName("selection")
  1203. mode.Bind(wx.EVT_CHOICE, self.OnVolumeMode)
  1204. self.win['volume']['draw']['mode'] = mode.GetId()
  1205. gridSizer.Add(item = mode, flag = wx.ALIGN_CENTER_VERTICAL,
  1206. pos = (0, 1))
  1207. # shading
  1208. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1209. label = _("Shading:")),
  1210. pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
  1211. shade = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  1212. choices = [_("flat"),
  1213. _("gouraud")])
  1214. shade.SetName("selection")
  1215. self.win['volume']['draw']['shading'] = shade.GetId()
  1216. shade.Bind(wx.EVT_CHOICE, self.OnVolumeDrawMode)
  1217. gridSizer.Add(item = shade, flag = wx.ALIGN_CENTER_VERTICAL,
  1218. pos = (0, 3))
  1219. # resolution (mode)
  1220. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1221. label = _("Resolution:")),
  1222. pos = (0, 4), flag = wx.ALIGN_CENTER_VERTICAL)
  1223. resol = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  1224. initial = 1,
  1225. min = 1,
  1226. max = 100)
  1227. resol.SetName("value")
  1228. self.win['volume']['draw']['resolution'] = resol.GetId()
  1229. resol.Bind(wx.EVT_SPINCTRL, self.OnVolumeResolution)
  1230. resol.Bind(wx.EVT_TEXT, self.OnVolumeResolution)
  1231. gridSizer.Add(item = resol, pos = (0, 5))
  1232. boxSizer.Add(item = gridSizer, proportion = 0,
  1233. flag = wx.ALL | wx.EXPAND, border = 3)
  1234. pageSizer.Add(item = boxSizer, proportion = 0,
  1235. flag = wx.EXPAND | wx.ALL,
  1236. border = 3)
  1237. #
  1238. # manage isosurfaces
  1239. #
  1240. box = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  1241. label = " %s " % (_("List of isosurfaces")))
  1242. box.SetName('listStaticBox')
  1243. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1244. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1245. # list
  1246. isolevel = wx.CheckListBox(parent = panel, id = wx.ID_ANY,
  1247. size = (300, 150))
  1248. self.Bind(wx.EVT_CHECKLISTBOX, self.OnVolumeCheck, isolevel)
  1249. self.Bind(wx.EVT_LISTBOX, self.OnVolumeSelect, isolevel)
  1250. self.win['volume']['isosurfs'] = isolevel.GetId()
  1251. self.win['volume']['slices'] = isolevel.GetId()
  1252. gridSizer.Add(item = isolevel, pos = (0, 0), span = (4, 1))
  1253. # buttons (add, delete, move up, move down)
  1254. btnAdd = wx.Button(parent = panel, id = wx.ID_ADD)
  1255. self.win['volume']['btnAdd'] = btnAdd.GetId()
  1256. btnAdd.Bind(wx.EVT_BUTTON, self.OnVolumeAdd)
  1257. gridSizer.Add(item = btnAdd,
  1258. pos = (0, 1))
  1259. btnDelete = wx.Button(parent = panel, id = wx.ID_DELETE)
  1260. self.win['volume']['btnDelete'] = btnDelete.GetId()
  1261. btnDelete.Bind(wx.EVT_BUTTON, self.OnVolumeDelete)
  1262. btnDelete.Enable(False)
  1263. gridSizer.Add(item = btnDelete,
  1264. pos = (1, 1))
  1265. btnMoveUp = wx.Button(parent = panel, id = wx.ID_UP)
  1266. self.win['volume']['btnMoveUp'] = btnMoveUp.GetId()
  1267. btnMoveUp.Bind(wx.EVT_BUTTON, self.OnVolumeMoveUp)
  1268. btnMoveUp.Enable(False)
  1269. gridSizer.Add(item = btnMoveUp,
  1270. pos = (2, 1))
  1271. btnMoveDown = wx.Button(parent = panel, id = wx.ID_DOWN)
  1272. self.win['volume']['btnMoveDown'] = btnMoveDown.GetId()
  1273. btnMoveDown.Bind(wx.EVT_BUTTON, self.OnVolumeMoveDown)
  1274. btnMoveDown.Enable(False)
  1275. gridSizer.Add(item = btnMoveDown,
  1276. pos = (3, 1))
  1277. boxSizer.Add(item = gridSizer, proportion = 1,
  1278. flag = wx.ALL | wx.EXPAND, border = 3)
  1279. pageSizer.Add(item = boxSizer, proportion = 0,
  1280. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1281. border = 3)
  1282. # isosurface/slice
  1283. sizer = wx.BoxSizer()
  1284. self.isoPanel = self._createIsosurfacePanel(panel)
  1285. self.slicePanel = self._createSlicePanel(panel)
  1286. sizer.Add(self.isoPanel, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 0)
  1287. sizer.Add(self.slicePanel, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 0)
  1288. sizer.Hide(self.slicePanel)
  1289. pageSizer.Add(item = sizer, proportion = 0,
  1290. flag = wx.EXPAND | wx.ALL,
  1291. border = 3)
  1292. #
  1293. # position
  1294. #
  1295. self.win['volume']['position'] = {}
  1296. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1297. label = " %s " % (_("Position")))
  1298. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1299. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1300. gridSizer.AddGrowableCol(3)
  1301. # position
  1302. self._createControl(panel, data = self.win['volume'], name = 'position',
  1303. range = (-10000, 10000), floatSlider = True,
  1304. bind = (self.OnVolumePosition, self.OnVolumePositionChanged, self.OnVolumePositionText))
  1305. axis = wx.Choice (parent = panel, id = wx.ID_ANY, size = (75, -1),
  1306. choices = ["X",
  1307. "Y",
  1308. "Z"])
  1309. reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
  1310. reset.SetToolTipString(_("Reset to default position"))
  1311. reset.Bind(wx.EVT_BUTTON, self.OnResetVolumePosition)
  1312. self.win['volume']['position']['reset'] = reset.GetId()
  1313. self.win['volume']['position']['axis'] = axis.GetId()
  1314. axis.SetSelection(0)
  1315. axis.Bind(wx.EVT_CHOICE, self.OnVolumeAxis)
  1316. pslide = self.FindWindowById(self.win['volume']['position']['slider'])
  1317. ptext = self.FindWindowById(self.win['volume']['position']['text'])
  1318. ptext.SetValue('0')
  1319. gridSizer.Add(item = axis, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
  1320. gridSizer.Add(item = pslide, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 1))
  1321. gridSizer.Add(item = ptext, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 2))
  1322. gridSizer.Add(item = reset, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, pos = (0, 3))
  1323. boxSizer.Add(item = gridSizer, proportion = 1,
  1324. flag = wx.ALL | wx.EXPAND, border = 3)
  1325. pageSizer.Add(item = boxSizer, proportion = 0,
  1326. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1327. border = 3)
  1328. panel.SetSizer(pageSizer)
  1329. panel.Fit()
  1330. return panel
  1331. def _createLightPage(self, parent):
  1332. """!Create light page"""
  1333. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  1334. self.page['light'] = { 'id' : 0,
  1335. 'notebook' : self.foldpanelAppear.GetId() }
  1336. self.win['light'] = {}
  1337. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1338. show = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1339. label = _("Show light model"))
  1340. show.Bind(wx.EVT_CHECKBOX, self.OnShowLightModel)
  1341. show.SetValue(True)
  1342. self._display.showLight = True
  1343. pageSizer.Add(item = show, proportion = 0,
  1344. flag = wx.ALL, border = 3)
  1345. ## surface = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1346. ## label = _("Follow source viewpoint"))
  1347. ## pageSizer.Add(item = surface, proportion = 0,
  1348. ## flag = wx.ALL, border = 3)
  1349. # position
  1350. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1351. label = " %s " % (_("Light source position")))
  1352. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1353. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1354. posSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1355. self._createCompass(panel = panel, sizer = posSizer, type = 'light')
  1356. pos = LightPositionWindow(panel, id = wx.ID_ANY, size = (175, 175),
  1357. mapwindow = self.mapWindow)
  1358. self.win['light']['position'] = pos.GetId()
  1359. posSizer.Add(item = pos,
  1360. pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
  1361. gridSizer.Add(item = posSizer, pos = (0, 0))
  1362. # height
  1363. self._createControl(panel, data = self.win['light'], name = 'z', sliderHor = False,
  1364. range = (0, 100),
  1365. bind = (self.OnLightChange, self.OnLightChanged, self.OnLightChange))
  1366. heightSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1367. heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:")),
  1368. pos = (0, 0), flag = wx.ALIGN_LEFT, span = (1, 2))
  1369. heightSizer.Add(item = self.FindWindowById(self.win['light']['z']['slider']),
  1370. flag = wx.ALIGN_RIGHT, pos = (1, 0))
  1371. heightSizer.Add(item = self.FindWindowById(self.win['light']['z']['text']),
  1372. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
  1373. wx.BOTTOM | wx.RIGHT, pos = (1, 1))
  1374. gridSizer.Add(item = heightSizer, pos = (0, 2), flag = wx.ALIGN_RIGHT)
  1375. boxSizer.Add(item = gridSizer, proportion = 1,
  1376. flag = wx.ALL | wx.EXPAND, border = 2)
  1377. pageSizer.Add(item = boxSizer, proportion = 0,
  1378. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1379. border = 3)
  1380. # position
  1381. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1382. label = " %s " % (_("Light color and intensity")))
  1383. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1384. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1385. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Color:")),
  1386. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1387. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  1388. colour = UserSettings.Get(group = 'nviz', key = 'light',
  1389. subkey = 'color'),
  1390. size = globalvar.DIALOG_COLOR_SIZE)
  1391. self.win['light']['color'] = color.GetId()
  1392. color.Bind(csel.EVT_COLOURSELECT, self.OnLightColor)
  1393. gridSizer.Add(item = color, pos = (0, 2))
  1394. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Brightness:")),
  1395. pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1396. self._createControl(panel, data = self.win['light'], name = 'bright', size = 300,
  1397. range = (0, 100),
  1398. bind = (self.OnLightValue, self.OnLightChanged, self.OnLightValue))
  1399. gridSizer.Add(item = self.FindWindowById(self.win['light']['bright']['slider']),
  1400. pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  1401. gridSizer.Add(item = self.FindWindowById(self.win['light']['bright']['text']),
  1402. pos = (1, 2),
  1403. flag = wx.ALIGN_CENTER)
  1404. gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Ambient:")),
  1405. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  1406. self._createControl(panel, data = self.win['light'], name = 'ambient', size = 300,
  1407. range = (0, 100),
  1408. bind = (self.OnLightValue, self.OnLightChanged, self.OnLightValue))
  1409. gridSizer.Add(item = self.FindWindowById(self.win['light']['ambient']['slider']),
  1410. pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  1411. gridSizer.Add(item = self.FindWindowById(self.win['light']['ambient']['text']),
  1412. pos = (2, 2),
  1413. flag = wx.ALIGN_CENTER)
  1414. boxSizer.Add(item = gridSizer, proportion = 1,
  1415. flag = wx.ALL | wx.EXPAND, border = 2)
  1416. pageSizer.Add(item = boxSizer, proportion = 0,
  1417. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1418. border = 3)
  1419. # reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
  1420. # reset.SetToolTipString(_("Reset to default view"))
  1421. # # self.win['reset'] = reset.GetId()
  1422. # reset.Bind(wx.EVT_BUTTON, self.OnResetView)
  1423. # viewSizer.Add(item = reset, proportion = 1,
  1424. # flag = wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT,
  1425. # border = 5)
  1426. # gridSizer.AddGrowableCol(3)
  1427. # gridSizer.Add(item = viewSizer, pos = (4, 0), span = (1, 2),
  1428. # flag = wx.EXPAND)
  1429. panel.SetSizer(pageSizer)
  1430. panel.Layout()
  1431. panel.Fit()
  1432. return panel
  1433. def _createFringePage(self, parent):
  1434. """!Create fringe page"""
  1435. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  1436. self.page['fringe'] = { 'id' : 1,
  1437. 'notebook' : self.foldpanelAppear.GetId() }
  1438. self.win['fringe'] = {}
  1439. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1440. # selection
  1441. rbox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1442. label = " %s " % (_("Surface")))
  1443. rboxSizer = wx.StaticBoxSizer(rbox, wx.VERTICAL)
  1444. rmaps = gselect.Select(parent = panel, type = 'raster',
  1445. onPopup = self.GselectOnPopup)
  1446. rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetSurface)
  1447. self.win['fringe']['map'] = rmaps.GetId()
  1448. rboxSizer.Add(item = rmaps, proportion = 0,
  1449. flag = wx.ALL,
  1450. border = 3)
  1451. pageSizer.Add(item = rboxSizer, proportion = 0,
  1452. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1453. border = 3)
  1454. ebox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1455. label = " %s " % (_("Edges with fringe")))
  1456. eboxSizer = wx.StaticBoxSizer(ebox, wx.HORIZONTAL)
  1457. for edge in [(_("N && W"), "nw"),
  1458. (_("N && E"), "ne"),
  1459. (_("S && W"), "sw"),
  1460. (_("S && E"), "se")]:
  1461. chkbox = wx.CheckBox(parent = panel,
  1462. label = edge[0],
  1463. name = edge[1])
  1464. self.win['fringe'][edge[1]] = chkbox.GetId()
  1465. eboxSizer.Add(item = chkbox, proportion = 0,
  1466. flag = wx.ADJUST_MINSIZE | wx.LEFT | wx.RIGHT, border = 5)
  1467. chkbox.Bind(wx.EVT_CHECKBOX, self.OnFringe)
  1468. pageSizer.Add(item = eboxSizer, proportion = 0,
  1469. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1470. border = 3)
  1471. sbox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1472. label = " %s " % (_("Settings")))
  1473. sboxSizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
  1474. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  1475. # elevation
  1476. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1477. label = _("Elevation of fringe from bottom:")),
  1478. pos = (0, 0),
  1479. flag = wx.ALIGN_CENTER_VERTICAL)
  1480. spin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY,
  1481. size = (65, -1), min = -1e6, max = 1e6)
  1482. spin.SetValue(UserSettings.Get(group = 'nviz', key = 'fringe', subkey = 'elev'))
  1483. spin.Bind(wx.EVT_SPINCTRL, self.OnFringe)
  1484. self.win['fringe']['elev'] = spin.GetId()
  1485. gridSizer.Add(item = spin, pos = (0, 1))
  1486. # color
  1487. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1488. label = _("Color:")),
  1489. pos = (1, 0),
  1490. flag = wx.ALIGN_CENTER_VERTICAL)
  1491. color = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
  1492. size = globalvar.DIALOG_COLOR_SIZE)
  1493. color.SetColour(UserSettings.Get(group = 'nviz', key = 'fringe',
  1494. subkey = 'color'))
  1495. color.Bind(csel.EVT_COLOURSELECT, self.OnFringe)
  1496. self.win['fringe']['color'] = color.GetId()
  1497. gridSizer.Add(item = color, pos = (1, 1))
  1498. sboxSizer.Add(item = gridSizer, proportion = 1,
  1499. flag = wx.ALL | wx.EXPAND, border = 3)
  1500. pageSizer.Add(item = sboxSizer, proportion = 0,
  1501. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1502. border = 3)
  1503. panel.SetSizer(pageSizer)
  1504. panel.Layout()
  1505. panel.Fit()
  1506. return panel
  1507. def _createDecorationPage(self, parent):
  1508. """!Create decoration (north arrow, scalebar, legend) page"""
  1509. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  1510. self.page['decoration'] = { 'id' : 2,
  1511. 'notebook' : self.foldpanelAppear.GetId()}
  1512. self.win['decoration'] = {}
  1513. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1514. # north arrow
  1515. self.win['decoration']['arrow'] = {}
  1516. nabox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1517. label = " %s " % (_("North Arrow")))
  1518. naboxSizer = wx.StaticBoxSizer(nabox, wx.VERTICAL)
  1519. gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  1520. # size
  1521. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1522. label = _("Arrow length (in map units):")),
  1523. pos = (0,0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
  1524. sizeCtrl = NumTextCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1), style = wx.TE_PROCESS_ENTER)
  1525. gridSizer.Add(sizeCtrl, pos = (0, 2))
  1526. self.win['decoration']['arrow']['size'] = sizeCtrl.GetId()
  1527. sizeCtrl.Bind(wx.EVT_TEXT_ENTER, self.OnDecorationProp)
  1528. sizeCtrl.Bind(wx.EVT_KILL_FOCUS, self.OnDecorationProp)
  1529. # color
  1530. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1531. label = _("Arrow color:")),
  1532. pos = (1,0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
  1533. color = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
  1534. size = globalvar.DIALOG_COLOR_SIZE)
  1535. gridSizer.Add(color, pos = (1, 2))
  1536. self.win['decoration']['arrow']['color'] = color.GetId()
  1537. color.Bind(csel.EVT_COLOURSELECT, self.OnDecorationProp)
  1538. # control
  1539. toggle = wx.ToggleButton(parent = panel, id = wx.ID_ANY, label = _("Place arrow"))
  1540. gridSizer.Add(item = toggle, pos = (2, 0))
  1541. toggle.Bind(wx.EVT_TOGGLEBUTTON, self.OnDecorationPlacement)
  1542. self.win['decoration']['arrow']['place'] = toggle.GetId()
  1543. toggle.SetName('placeArrow')
  1544. delete = wx.Button(parent = panel, id = wx.ID_ANY, label = _("Delete"))
  1545. gridSizer.Add(item = delete, pos = (2, 1))
  1546. delete.Bind(wx.EVT_BUTTON, self.OnArrowDelete)
  1547. naboxSizer.Add(item = gridSizer, proportion = 0, flag = wx.EXPAND, border = 3)
  1548. pageSizer.Add(item = naboxSizer, proportion = 0,
  1549. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1550. border = 3)
  1551. # north arrow
  1552. self.win['decoration']['scalebar'] = {}
  1553. nabox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1554. label = " %s " % (_("Scale bar")))
  1555. naboxSizer = wx.StaticBoxSizer(nabox, wx.VERTICAL)
  1556. gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  1557. # size
  1558. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1559. label = _("Scale bar length (in map units):")),
  1560. pos = (0,0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
  1561. sizeCtrl = NumTextCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1), style = wx.TE_PROCESS_ENTER)
  1562. gridSizer.Add(sizeCtrl, pos = (0, 2))
  1563. self.win['decoration']['scalebar']['size'] = sizeCtrl.GetId()
  1564. sizeCtrl.Bind(wx.EVT_TEXT_ENTER, self.OnDecorationProp)
  1565. sizeCtrl.Bind(wx.EVT_KILL_FOCUS, self.OnDecorationProp)
  1566. # color
  1567. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1568. label = _("Scale bar color:")),
  1569. pos = (1,0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
  1570. color = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
  1571. size = globalvar.DIALOG_COLOR_SIZE)
  1572. gridSizer.Add(color, pos = (1, 2))
  1573. self.win['decoration']['scalebar']['color'] = color.GetId()
  1574. color.Bind(csel.EVT_COLOURSELECT, self.OnDecorationProp)
  1575. # control
  1576. toggle = wx.ToggleButton(parent = panel, id = wx.ID_ANY, label = _("Place scalebar"))
  1577. gridSizer.Add(item = toggle, pos = (2, 0))
  1578. toggle.Bind(wx.EVT_TOGGLEBUTTON, self.OnDecorationPlacement)
  1579. self.win['decoration']['scalebar']['place'] = toggle.GetId()
  1580. toggle.SetName('placeScalebar')
  1581. delete = wx.Button(parent = panel, id = wx.ID_ANY, label = _("Delete last"))
  1582. gridSizer.Add(item = delete, pos = (2, 1))
  1583. delete.Bind(wx.EVT_BUTTON, self.OnScalebarDelete)
  1584. naboxSizer.Add(item = gridSizer, proportion = 0, flag = wx.EXPAND, border = 3)
  1585. pageSizer.Add(item = naboxSizer, proportion = 0,
  1586. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  1587. border = 3)
  1588. panel.SetSizer(pageSizer)
  1589. panel.Layout()
  1590. panel.Fit()
  1591. return panel
  1592. def GetLayerData(self, nvizType, nameOnly = False):
  1593. """!Get nviz data"""
  1594. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  1595. if nameOnly:
  1596. return name
  1597. if nvizType == 'surface' or nvizType == 'fringe':
  1598. return self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  1599. elif nvizType == 'vector':
  1600. return self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'nviz')
  1601. elif nvizType == 'volume':
  1602. return self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
  1603. return None
  1604. def OnNewConstant(self, event):
  1605. """!Create new surface with constant value"""
  1606. #TODO settings
  1607. name = self.mapWindow.NewConstant()
  1608. win = self.FindWindowById(self.win['constant']['surface'])
  1609. name = _("constant#") + str(name)
  1610. win.Append(name)
  1611. win.SetStringSelection(name)
  1612. self.OnConstantSelection(None)
  1613. self.EnablePage(name = 'constant', enabled = True)
  1614. self.mapWindow.Refresh(eraseBackground = False)
  1615. # need to update list of surfaces in vector page
  1616. for vtype in ('points', 'lines'):
  1617. checklist = self.FindWindowById(self.win['vector'][vtype]['surface'])
  1618. checklist.Append(name)
  1619. win = self.FindWindowById(self.win['vector']['map'])
  1620. win.SetValue(win.GetValue())
  1621. def OnDeleteConstant(self, event):
  1622. """!Delete selected constant surface"""
  1623. layerIdx = self.FindWindowById(self.win['constant']['surface']).GetSelection()
  1624. if layerIdx == wx.NOT_FOUND:
  1625. return
  1626. name = self.FindWindowById(self.win['constant']['surface']).GetStringSelection()
  1627. self.mapWindow.DeleteConstant(layerIdx)
  1628. win = self.FindWindowById(self.win['constant']['surface'])
  1629. win.Delete(layerIdx)
  1630. if win.IsEmpty():
  1631. win.SetValue("")
  1632. self.EnablePage(name = 'constant', enabled = False)
  1633. else:
  1634. win.SetSelection(0)
  1635. self.OnConstantSelection(None)
  1636. # need to update list of surfaces in vector page
  1637. for vtype in ('points', 'lines'):
  1638. checklist = self.FindWindowById(self.win['vector'][vtype]['surface'])
  1639. checklist.Delete(checklist.FindString(name))
  1640. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1641. self.mapWindow.Refresh(False)
  1642. def OnConstantSelection(self, event):
  1643. """!Constant selected"""
  1644. layerIdx = self.FindWindowById(self.win['constant']['surface']).GetSelection()
  1645. if layerIdx == wx.NOT_FOUND:
  1646. return
  1647. name = _("constant#") + str(layerIdx + 1)
  1648. data = self.mapWindow.constants[layerIdx]
  1649. for attr, value in data['constant'].iteritems():
  1650. if attr == 'color':
  1651. value = self._getColorFromString(value)
  1652. if attr in ('color', 'value', 'resolution', 'transp'):
  1653. if attr == 'transp':
  1654. self.FindWindowById(self.win['constant'][attr]).SetValue(self._getPercent(value))
  1655. self.FindWindowById(self.win['constant'][attr]).SetValue(value)
  1656. def OnSetConstantProp(self, event):
  1657. """!Change properties (color, value, resolution)
  1658. of currently selected constant surface"""
  1659. layerIdx = self.FindWindowById(self.win['constant']['surface']).GetSelection()
  1660. if layerIdx == wx.NOT_FOUND:
  1661. return
  1662. data = self.mapWindow.constants[layerIdx]
  1663. for attr in ('resolution', 'value', 'transp'):
  1664. data['constant'][attr] = self.FindWindowById(self.win['constant'][attr]).GetValue()
  1665. data['constant']['color'] = self._getColorString(
  1666. self.FindWindowById(self.win['constant']['color']).GetValue())
  1667. data['constant']['transp'] = self._getPercent(data['constant']['transp'], toPercent = False)
  1668. # update properties
  1669. event = wxUpdateProperties(data = data)
  1670. wx.PostEvent(self.mapWindow, event)
  1671. if self.mapDisplay.statusbarWin['render'].IsChecked():
  1672. self.mapWindow.Refresh(False)
  1673. def OnFringe(self, event):
  1674. """!Show/hide fringe"""
  1675. data = self.GetLayerData('fringe')['surface']
  1676. sid = data['object']['id']
  1677. elev = self.FindWindowById(self.win['fringe']['elev']).GetValue()
  1678. color = self.FindWindowById(self.win['fringe']['color']).GetValue()
  1679. self._display.SetFringe(sid, color, elev,
  1680. self.FindWindowById(self.win['fringe']['nw']).IsChecked(),
  1681. self.FindWindowById(self.win['fringe']['ne']).IsChecked(),
  1682. self.FindWindowById(self.win['fringe']['sw']).IsChecked(),
  1683. self.FindWindowById(self.win['fringe']['se']).IsChecked())
  1684. self.mapWindow.Refresh(False)
  1685. def OnScroll(self, event, win, data):
  1686. """!Generic scrolling handler"""
  1687. winName = self.__GetWindowName(win, event.GetId())
  1688. if not winName:
  1689. return
  1690. data[winName] = self.FindWindowById(event.GetId()).GetValue()
  1691. for w in win[winName].itervalues():
  1692. self.FindWindowById(w).SetValue(data[winName])
  1693. event.Skip()
  1694. def AdjustSliderRange(self, slider, value):
  1695. minim, maxim = slider.GetRange()
  1696. if not (minim <= value <= maxim):
  1697. slider.SetRange(min(minim, value), max(maxim, value))
  1698. def _createIsosurfacePanel(self, parent):
  1699. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  1700. vSizer = wx.BoxSizer(wx.HORIZONTAL)
  1701. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1702. label = " %s " % (_("Isosurface attributes")))
  1703. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1704. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1705. self.win['volume']['attr'] = {}
  1706. inout = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1707. label = _("toggle normal direction"))
  1708. gridSizer.Add(item = inout, pos = (0,0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL)
  1709. inout.Bind(wx.EVT_CHECKBOX, self.OnInOutMode)
  1710. self.win['volume']['inout'] = inout.GetId()
  1711. row = 1
  1712. for code, attrb in (('topo', _("Isosurface value")),
  1713. ('color', _("Color")),
  1714. ('mask', _("Mask")),
  1715. ('transp', _("Transparency")),
  1716. ('shine', _("Shininess"))):
  1717. self.win['volume'][code] = {}
  1718. # label
  1719. colspan = 1
  1720. if code == 'topo':
  1721. colspan = 2
  1722. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1723. label = attrb + ':'),
  1724. pos = (row, 0), span = (1, colspan),flag = wx.ALIGN_CENTER_VERTICAL)
  1725. if code != 'topo':
  1726. use = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  1727. choices = [_("map")])
  1728. else:
  1729. use = None
  1730. # check for required properties
  1731. if code not in ('topo', 'color', 'shine'):
  1732. use.Insert(item = _("unset"), pos = 0)
  1733. self.win['volume'][code]['required'] = False
  1734. else:
  1735. self.win['volume'][code]['required'] = True
  1736. if use and code != 'mask':
  1737. use.Append(item = _('constant'))
  1738. if use:
  1739. self.win['volume'][code]['use'] = use.GetId()
  1740. use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
  1741. gridSizer.Add(item = use, flag = wx.ALIGN_CENTER_VERTICAL,
  1742. pos = (row, 1))
  1743. if code != 'topo':
  1744. map = gselect.Select(parent = panel, id = wx.ID_ANY,
  1745. # size = globalvar.DIALOG_GSELECT_SIZE,
  1746. size = (200, -1),
  1747. type = "grid3")
  1748. self.win['volume'][code]['map'] = map.GetId() - 1 # FIXME
  1749. map.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
  1750. gridSizer.Add(item = map, flag = wx.ALIGN_CENTER_VERTICAL,
  1751. pos = (row, 2))
  1752. else:
  1753. map = None
  1754. if code == 'color':
  1755. color = UserSettings.Get(group = 'nviz', key = 'volume', subkey = ['color', 'value'])
  1756. value = csel.ColourSelect(panel, id = wx.ID_ANY,
  1757. colour = color,
  1758. size = globalvar.DIALOG_COLOR_SIZE)
  1759. value.Bind(csel.EVT_COLOURSELECT, self.OnVolumeIsosurfMap)
  1760. value.SetName('color')
  1761. elif code == 'mask':
  1762. value = None
  1763. elif code == 'topo':
  1764. value = NumTextCtrl(parent = panel, id = wx.ID_ANY, size = (200, -1),
  1765. style = wx.TE_PROCESS_ENTER)
  1766. value.Bind(wx.EVT_TEXT_ENTER, self.OnVolumeIsosurfMap)
  1767. value.Bind(wx.EVT_KILL_FOCUS, self.OnVolumeIsosurfMap)
  1768. ## value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
  1769. else:
  1770. size = (65, -1)
  1771. value = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = size,
  1772. initial = 0)
  1773. if code == 'topo':
  1774. value.SetRange(minVal = -1e9, maxVal = 1e9)
  1775. elif code in ('shine', 'transp'):
  1776. value.SetRange(minVal = 0, maxVal = 100)
  1777. value.Bind(wx.EVT_SPINCTRL, self.OnVolumeIsosurfMap)
  1778. value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
  1779. if value:
  1780. self.win['volume'][code]['const'] = value.GetId()
  1781. if code == 'topo':
  1782. gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
  1783. pos = (row, 2))
  1784. else:
  1785. value.Enable(False)
  1786. gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
  1787. pos = (row, 3))
  1788. else:
  1789. self.win['volume'][code]['const'] = None
  1790. if code != 'topo':
  1791. self.SetMapObjUseMap(nvizType = 'volume',
  1792. attrb = code) # -> enable map / disable constant
  1793. row += 1
  1794. boxSizer.Add(item = gridSizer, proportion = 1,
  1795. flag = wx.ALL | wx.EXPAND, border = 3)
  1796. vSizer.Add(item = boxSizer, proportion = 1,
  1797. flag = wx.EXPAND, border = 0)
  1798. panel.SetSizer(vSizer)
  1799. return panel
  1800. def _createSlicePanel(self, parent):
  1801. panel = wx.Panel(parent = parent, id = wx.ID_ANY)
  1802. vSizer = wx.BoxSizer(wx.HORIZONTAL)
  1803. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  1804. label = " %s " % (_("Slice attributes")))
  1805. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1806. hSizer = wx.BoxSizer()
  1807. self.win['volume']['slice'] = {}
  1808. hSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1809. label = _("Slice parallel to axis:")), proportion = 0,
  1810. flag = wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, border = 3)
  1811. axes = wx.Choice(parent = panel, id = wx.ID_ANY, size = (65, -1), choices = ("X", "Y", "Z"))
  1812. hSizer.Add(axes, proportion = 0, flag = wx.ALIGN_LEFT|wx.LEFT, border = 3)
  1813. self.win['volume']['slice']['axes'] = axes.GetId()
  1814. axes.Bind(wx.EVT_CHOICE, self.OnVolumeSliceAxes)
  1815. boxSizer.Add(hSizer, proportion = 0, flag = wx.ALL|wx.EXPAND, border = 3)
  1816. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  1817. gridSizer.AddGrowableCol(0,1)
  1818. gridSizer.AddGrowableCol(1,2)
  1819. gridSizer.AddGrowableCol(2,2)
  1820. # text labels
  1821. for i in range(2):
  1822. label = wx.StaticText(parent = panel, id = wx.ID_ANY)
  1823. label.SetName('label_edge_' + str(i))
  1824. gridSizer.Add(item = label, pos = (0, i + 1),
  1825. flag = wx.ALIGN_CENTER)
  1826. for i in range(2,4):
  1827. label = wx.StaticText(parent = panel, id = wx.ID_ANY)
  1828. label.SetName('label_edge_' + str(i))
  1829. gridSizer.Add(item = label, pos = (3, i -1),
  1830. flag = wx.ALIGN_CENTER)
  1831. for i in range(2):
  1832. label = wx.StaticText(parent = panel, id = wx.ID_ANY)
  1833. label.SetName('label_coord_' + str(i))
  1834. gridSizer.Add(item = label, pos = (i + 1, 0),
  1835. flag = wx.ALIGN_CENTER_VERTICAL)
  1836. label = wx.StaticText(parent = panel, id = wx.ID_ANY)
  1837. label.SetName('label_coord_2')
  1838. gridSizer.Add(item = label, pos = (4, 0),
  1839. flag = wx.ALIGN_CENTER_VERTICAL)
  1840. # sliders
  1841. for i, coord in enumerate(('x1', 'x2')):
  1842. slider = wx.Slider(parent = panel, id = wx.ID_ANY, minValue = 0, maxValue = 100, value = 0)
  1843. self.win['volume']['slice']['slider_' + coord] = slider.GetId()
  1844. slider.Bind(wx.EVT_SPIN, self.OnSlicePositionChange)
  1845. slider.Bind(wx.EVT_SCROLL_THUMBRELEASE, self.OnSlicePositionChanged)
  1846. gridSizer.Add(item = slider, pos = (1, i + 1),
  1847. flag = wx.ALIGN_CENTER|wx.EXPAND)
  1848. for i, coord in enumerate(('y1', 'y2')):
  1849. slider = wx.Slider(parent = panel, id = wx.ID_ANY, minValue = 0, maxValue = 100, value = 0)
  1850. self.win['volume']['slice']['slider_' + coord] = slider.GetId()
  1851. slider.Bind(wx.EVT_SPIN, self.OnSlicePositionChange)
  1852. slider.Bind(wx.EVT_SCROLL_THUMBRELEASE, self.OnSlicePositionChanged)
  1853. gridSizer.Add(item = slider, pos = (2, i + 1),
  1854. flag = wx.ALIGN_CENTER|wx.EXPAND)
  1855. for i, coord in enumerate(('z1', 'z2')):
  1856. slider = wx.Slider(parent = panel, id = wx.ID_ANY, minValue = 0, maxValue = 100, value = 0)
  1857. self.win['volume']['slice']['slider_' + coord] = slider.GetId()
  1858. slider.Bind(wx.EVT_SPIN, self.OnSlicePositionChange)
  1859. slider.Bind(wx.EVT_SCROLL_THUMBRELEASE, self.OnSlicePositionChanged)
  1860. gridSizer.Add(item = slider, pos = (4,i+1),
  1861. flag = wx.ALIGN_CENTER|wx.EXPAND)
  1862. boxSizer.Add(item = gridSizer, proportion = 1,
  1863. flag = wx.ALL | wx.EXPAND, border = 3)
  1864. # transparency, reset
  1865. hSizer = wx.BoxSizer()
  1866. hSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1867. label = _("Transparency:")), proportion = 0,
  1868. flag = wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, border = 7)
  1869. spin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  1870. min = 0, max = 100, initial = 0)
  1871. spin.Bind(wx.EVT_SPINCTRL, self.OnSliceTransparency)
  1872. self.win['volume']['slice']['transp'] = spin.GetId()
  1873. hSizer.Add(item = spin, proportion = 0,
  1874. flag = wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.TOP, border = 7)
  1875. hSizer.Add(item = wx.Size(-1, -1), proportion = 1,
  1876. flag = wx.EXPAND)
  1877. reset = wx.Button(parent = panel, id = wx.ID_ANY, label = _("Reset"))
  1878. reset.Bind(wx.EVT_BUTTON, self.OnSliceReset)
  1879. self.win['volume']['slice']['reset'] = reset.GetId()
  1880. hSizer.Add(item = reset, proportion = 0,
  1881. flag = wx.ALIGN_CENTER_VERTICAL|wx.TOP, border = 7)
  1882. boxSizer.Add(hSizer, proportion = 0, flag = wx.ALL|wx.EXPAND, border = 3)
  1883. panel.SetSizer(boxSizer)
  1884. return panel
  1885. def _createControl(self, parent, data, name, range, bind = (None, None, None),
  1886. sliderHor = True, size = 200, floatSlider = False):
  1887. """!Add control (Slider + TextCtrl)"""
  1888. data[name] = dict()
  1889. if sliderHor:
  1890. style = wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | \
  1891. wx.SL_BOTTOM
  1892. sizeW = (size, -1)
  1893. else:
  1894. style = wx.SL_VERTICAL | wx.SL_AUTOTICKS | \
  1895. wx.SL_INVERSE
  1896. sizeW = (-1, size)
  1897. kwargs = dict(parent = parent, id = wx.ID_ANY,
  1898. minValue = range[0],
  1899. maxValue = range[1],
  1900. style = style,
  1901. size = sizeW)
  1902. if floatSlider:
  1903. slider = FloatSlider(**kwargs)
  1904. else:
  1905. slider = wx.Slider(**kwargs)
  1906. slider.SetName('slider')
  1907. if bind[0]:
  1908. #EVT_SCROLL emits event after slider is released, EVT_SPIN not
  1909. slider.Bind(wx.EVT_SPIN, bind[0])
  1910. if bind[1]:
  1911. slider.Bind(wx.EVT_SCROLL_THUMBRELEASE, bind[1])
  1912. data[name]['slider'] = slider.GetId()
  1913. text = NumTextCtrl(parent = parent, id = wx.ID_ANY, size = (65, -1),
  1914. style = wx.TE_PROCESS_ENTER)
  1915. text.SetName('text')
  1916. if bind[2]:
  1917. text.Bind(wx.EVT_TEXT_ENTER, bind[2])
  1918. text.Bind(wx.EVT_KILL_FOCUS, bind[2])
  1919. data[name]['text'] = text.GetId()
  1920. def _createCompass(self, panel, sizer, type):
  1921. """!Create 'compass' widget for light and view page"""
  1922. w = wx.Button(panel, id = wx.ID_ANY, label = _("W"))
  1923. n = wx.Button(panel, id = wx.ID_ANY, label = _("N"))
  1924. s = wx.Button(panel, id = wx.ID_ANY, label = _("S"))
  1925. e = wx.Button(panel, id = wx.ID_ANY, label = _("E"))
  1926. nw = wx.Button(panel, id = wx.ID_ANY, label = _("NW"))
  1927. ne = wx.Button(panel, id = wx.ID_ANY, label = _("NE"))
  1928. se = wx.Button(panel, id = wx.ID_ANY, label = _("SE"))
  1929. sw = wx.Button(panel, id = wx.ID_ANY, label = _("SW"))
  1930. minWidth = sw.GetTextExtent(sw.GetLabel())[0] + 15
  1931. for win, name in zip((w, n, s, e, nw, ne, se, sw),
  1932. ('w', 'n', 's', 'e', 'nw', 'ne', 'se', 'sw')):
  1933. win.SetMinSize((minWidth, -1))
  1934. win.Bind(wx.EVT_BUTTON, self.OnLookFrom)
  1935. win.SetName(type + '_' + name)
  1936. sizer.Add(item = nw, pos = (0, 0), flag = wx.ALIGN_CENTER)
  1937. sizer.Add(item = n, pos = (0, 1), flag = wx.ALIGN_CENTER)
  1938. sizer.Add(item = ne, pos = (0, 2), flag = wx.ALIGN_CENTER)
  1939. sizer.Add(item = e, pos = (1, 2), flag = wx.ALIGN_CENTER)
  1940. sizer.Add(item = se, pos = (2, 2), flag = wx.ALIGN_CENTER)
  1941. sizer.Add(item = s, pos = (2, 1), flag = wx.ALIGN_CENTER)
  1942. sizer.Add(item = sw, pos = (2, 0), flag = wx.ALIGN_CENTER)
  1943. sizer.Add(item = w, pos = (1, 0), flag = wx.ALIGN_CENTER)
  1944. def __GetWindowName(self, data, id):
  1945. for name in data.iterkeys():
  1946. if type(data[name]) is type({}):
  1947. for win in data[name].itervalues():
  1948. if win == id:
  1949. return name
  1950. else:
  1951. if data[name] == id:
  1952. return name
  1953. return None
  1954. def UpdateSettings(self):
  1955. """!Update view from settings values
  1956. stored in self.mapWindow.view dictionary"""
  1957. for control in ('height',
  1958. 'persp',
  1959. 'twist',
  1960. 'z-exag'):
  1961. for win in self.win['view'][control].itervalues():
  1962. try:
  1963. if control == 'height':
  1964. value = int(self.mapWindow.iview[control]['value'])
  1965. else:
  1966. value = self.mapWindow.view[control]['value']
  1967. except KeyError:
  1968. value = -1
  1969. self.FindWindowById(win).SetValue(value)
  1970. viewWin = self.FindWindowById(self.win['view']['position'])
  1971. x, y = viewWin.UpdatePos(self.mapWindow.view['position']['x'],
  1972. self.mapWindow.view['position']['y'])
  1973. viewWin.Draw(pos = (x, y), scale = True)
  1974. viewWin.Refresh(False)
  1975. color = self._getColorString(self.mapWindow.view['background']['color'])
  1976. self._display.SetBgColor(str(color))
  1977. self.Update()
  1978. self.mapWindow.Refresh(eraseBackground = False)
  1979. self.mapWindow.render['quick'] = False
  1980. self.mapWindow.Refresh(True)
  1981. def OnShowLightModel(self, event):
  1982. """!Show light model"""
  1983. self._display.showLight = event.IsChecked()
  1984. self._display.DrawLightingModel()
  1985. def OnLightChange(self, event):
  1986. """!Position of the light changed"""
  1987. winName = self.__GetWindowName(self.win['light'], event.GetId())
  1988. if not winName:
  1989. return
  1990. value = self.FindWindowById(event.GetId()).GetValue()
  1991. self.mapWindow.light['position']['z'] = value
  1992. for win in self.win['light'][winName].itervalues():
  1993. self.FindWindowById(win).SetValue(value)
  1994. event = wxUpdateLight()
  1995. wx.PostEvent(self.mapWindow, event)
  1996. event.Skip()
  1997. def OnLightChanged(self, event):
  1998. """!Light"""
  1999. self.mapWindow.Refresh(False)
  2000. def OnLightColor(self, event):
  2001. """!Color of the light changed"""
  2002. self.mapWindow.light['color'] = tuple(event.GetValue())
  2003. event = wxUpdateLight(refresh = True)
  2004. wx.PostEvent(self.mapWindow, event)
  2005. event.Skip()
  2006. def OnLightValue(self, event):
  2007. """!Light brightness changed"""
  2008. data = self.mapWindow.light
  2009. self.OnScroll(event, self.win['light'], data)
  2010. event = wxUpdateLight()
  2011. wx.PostEvent(self.mapWindow, event)
  2012. event.Skip()
  2013. def OnBgColor(self, event):
  2014. """!Background color changed"""
  2015. color = event.GetValue()
  2016. self.mapWindow.view['background']['color'] = tuple(color)
  2017. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  2018. self._display.SetBgColor(str(color))
  2019. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2020. self.mapWindow.Refresh(False)
  2021. def OnSetSurface(self, event):
  2022. """!Surface selected, currently used for fringes"""
  2023. name = event.GetString()
  2024. try:
  2025. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')['surface']
  2026. except:
  2027. self.EnablePage('fringe', False)
  2028. return
  2029. layer = self.mapWindow.GetLayerByName(name, mapType = 'raster')
  2030. self.EnablePage('fringe', True)
  2031. def OnSetRaster(self, event):
  2032. """!Raster map selected, update surface page"""
  2033. name = event.GetString()
  2034. try:
  2035. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')['surface']
  2036. except:
  2037. self.EnablePage('surface', False)
  2038. return
  2039. layer = self.mapWindow.GetLayerByName(name, mapType = 'raster')
  2040. self.EnablePage('surface', True)
  2041. self.UpdateSurfacePage(layer, data, updateName = False)
  2042. def OnSetVector(self, event):
  2043. """!Vector map selected, update properties page"""
  2044. name = event.GetString()
  2045. try:
  2046. data = self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'nviz')['vector']
  2047. except:
  2048. self.EnablePage('vector', False)
  2049. return
  2050. layer = self.mapWindow.GetLayerByName(name, mapType = 'vector')
  2051. self.EnablePage('vector', True)
  2052. self.UpdateVectorPage(layer, data, updateName = False)
  2053. def OnSetRaster3D(self, event):
  2054. """!3D Raster map selected, update surface page"""
  2055. name = event.GetString()
  2056. try:
  2057. data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')['volume']
  2058. except:
  2059. self.EnablePage('volume', False)
  2060. return
  2061. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2062. self.EnablePage('volume', True)
  2063. self.UpdateVolumePage(layer, data, updateName = False)
  2064. def OnViewChange(self, event):
  2065. """!Change view, render in quick mode"""
  2066. # find control
  2067. winName = self.__GetWindowName(self.win['view'], event.GetId())
  2068. if not winName:
  2069. return
  2070. value = self.FindWindowById(event.GetId()).GetValue()
  2071. slider = self.FindWindowById(self.win['view'][winName]['slider'])
  2072. self.AdjustSliderRange(slider = slider, value = value)
  2073. if winName == 'height':
  2074. view = self.mapWindow.iview # internal
  2075. else:
  2076. view = self.mapWindow.view
  2077. if winName == 'z-exag' and value >= 0:
  2078. self.PostViewEvent(zExag = True)
  2079. else:
  2080. self.PostViewEvent(zExag = False)
  2081. if winName in ('persp', 'twist'):
  2082. convert = int
  2083. else:
  2084. convert = float
  2085. view[winName]['value'] = convert(value)
  2086. for win in self.win['view'][winName].itervalues():
  2087. self.FindWindowById(win).SetValue(value)
  2088. self.mapWindow.render['quick'] = True
  2089. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2090. self.mapWindow.Refresh(False)
  2091. event.Skip()
  2092. def OnViewChanged(self, event):
  2093. """!View changed, render in full resolution"""
  2094. self.mapWindow.render['quick'] = False
  2095. self.mapWindow.Refresh(False)
  2096. self.UpdateSettings()
  2097. try:# when calling event = None
  2098. event.Skip()
  2099. except AttributeError:
  2100. pass
  2101. def OnViewChangedText(self, event):
  2102. """!View changed, render in full resolution"""
  2103. self.mapWindow.render['quick'] = False
  2104. self.OnViewChange(event)
  2105. self.OnViewChanged(None)
  2106. self.Update()
  2107. event.Skip()
  2108. def OnLookAt(self, event):
  2109. """!Look here/center"""
  2110. name = self.FindWindowById(event.GetId()).GetName()
  2111. if name == 'center':
  2112. self._display.LookAtCenter()
  2113. focus = self.mapWindow.iview['focus']
  2114. focus['x'], focus['y'], focus['z'] = self._display.GetFocus()
  2115. self.mapWindow.Refresh(False)
  2116. elif name == 'top':
  2117. self.mapWindow.view['position']['x'] = 0.5
  2118. self.mapWindow.view['position']['y'] = 0.5
  2119. self.PostViewEvent(zExag = True)
  2120. self.UpdateSettings()
  2121. self.mapWindow.Refresh(False)
  2122. else: # here
  2123. if self.FindWindowById(event.GetId()).GetValue():
  2124. self.mapWindow.mouse['use'] = 'lookHere'
  2125. self.mapWindow.SetCursor(self.mapWindow.cursors["cross"])
  2126. else:
  2127. self.mapWindow.mouse['use'] = 'default'
  2128. self.mapWindow.SetCursor(self.mapWindow.cursors['default'])
  2129. def OnResetView(self, event):
  2130. """!Reset to default view (view page)"""
  2131. self.mapWindow.ResetView()
  2132. self.UpdateSettings()
  2133. self.mapWindow.Refresh(False)
  2134. def OnResetSurfacePosition(self, event):
  2135. """!Reset position of surface"""
  2136. for win in self.win['surface']['position'].itervalues():
  2137. if win == self.win['surface']['position']['axis']:
  2138. self.FindWindowById(win).SetSelection(0)
  2139. elif win == self.win['surface']['position']['reset']:
  2140. continue
  2141. else:
  2142. self.FindWindowById(win).SetValue(0)
  2143. data = self.GetLayerData('surface')
  2144. data['surface']['position']['x'] = 0
  2145. data['surface']['position']['y'] = 0
  2146. data['surface']['position']['z'] = 0
  2147. data['surface']['position']['update'] = None
  2148. # update properties
  2149. event = wxUpdateProperties(data = data)
  2150. wx.PostEvent(self.mapWindow, event)
  2151. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2152. self.mapWindow.Refresh(False)
  2153. def OnLookFrom(self, event):
  2154. """!Position of view/light changed by buttons"""
  2155. name = self.FindWindowById(event.GetId()).GetName()
  2156. buttonName = name.split('_')[1]
  2157. if name.split('_')[0] == 'view':
  2158. type = 'view'
  2159. data = self.mapWindow.view
  2160. else:
  2161. type = 'light'
  2162. data = self.mapWindow.light
  2163. if buttonName == 'n': # north
  2164. data['position']['x'] = 0.5
  2165. data['position']['y'] = 0.0
  2166. elif buttonName == 's': # south
  2167. data['position']['x'] = 0.5
  2168. data['position']['y'] = 1.0
  2169. elif buttonName == 'e': # east
  2170. data['position']['x'] = 1.0
  2171. data['position']['y'] = 0.5
  2172. elif buttonName =='w': # west
  2173. data['position']['x'] = 0.0
  2174. data['position']['y'] = 0.5
  2175. elif buttonName == 'nw': # north-west
  2176. data['position']['x'] = 0.0
  2177. data['position']['y'] = 0.0
  2178. elif buttonName == 'ne': # north-east
  2179. data['position']['x'] = 1.0
  2180. data['position']['y'] = 0.0
  2181. elif buttonName == 'se': # south-east
  2182. data['position']['x'] = 1.0
  2183. data['position']['y'] = 1.0
  2184. elif buttonName == 'sw': # south-west
  2185. data['position']['x'] = 0.0
  2186. data['position']['y'] = 1.0
  2187. if type == 'view':
  2188. self.PostViewEvent(zExag = True)
  2189. self.UpdateSettings()
  2190. else:
  2191. event = wxUpdateLight()
  2192. wx.PostEvent(self.mapWindow, event)
  2193. lightWin = self.FindWindowById(self.win['light']['position'])
  2194. x, y = lightWin.UpdatePos(self.mapWindow.light['position']['x'],
  2195. self.mapWindow.light['position']['y'])
  2196. lightWin.Draw(pos = (x, y), scale = True)
  2197. lightWin.Refresh(False)
  2198. self.mapWindow.render['quick'] = False
  2199. self.mapWindow.Refresh(False)
  2200. def OnMapObjUse(self, event):
  2201. """!Set surface attribute -- use -- map/constant"""
  2202. if not self.mapWindow.init:
  2203. return
  2204. wx.Yield()
  2205. # find attribute row
  2206. attrb = self.__GetWindowName(self.win['surface'], event.GetId())
  2207. if not attrb:
  2208. attrb = self.__GetWindowName(self.win['volume'], event.GetId())
  2209. nvizType = 'volume'
  2210. else:
  2211. nvizType = 'surface'
  2212. selection = event.GetSelection()
  2213. if self.win[nvizType][attrb]['required']: # no 'unset'
  2214. selection += 1
  2215. if selection == 0: # unset
  2216. useMap = None
  2217. value = ''
  2218. elif selection == 1: # map
  2219. useMap = True
  2220. value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
  2221. elif selection == 2: # constant
  2222. useMap = False
  2223. if attrb == 'color':
  2224. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
  2225. value = self._getColorString(value)
  2226. else:
  2227. value = self._getPercent(self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue(), toPercent = False)
  2228. self.SetMapObjUseMap(nvizType = nvizType,
  2229. attrb = attrb, map = useMap)
  2230. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  2231. if nvizType == 'surface':
  2232. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  2233. data[nvizType]['attribute'][attrb] = { 'map' : useMap,
  2234. 'value' : str(value),
  2235. 'update' : None }
  2236. else: # volume / isosurface
  2237. data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
  2238. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2239. id = list.GetSelection()
  2240. if id != -1:
  2241. data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
  2242. 'value' : str(value),
  2243. 'update' : None }
  2244. # update properties
  2245. event = wxUpdateProperties(data = data)
  2246. wx.PostEvent(self.mapWindow, event)
  2247. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2248. self.mapWindow.Refresh(False)
  2249. def EnablePage(self, name, enabled = True):
  2250. """!Enable/disable all widgets on page"""
  2251. for key, item in self.win[name].iteritems():
  2252. if key in ('map', 'surface', 'new','planes'):
  2253. continue
  2254. if type(item) == types.DictType:
  2255. for skey, sitem in self.win[name][key].iteritems():
  2256. if type(sitem) == types.DictType:
  2257. for ssitem in self.win[name][key][skey].itervalues():
  2258. if type(ssitem) == types.IntType:
  2259. self.FindWindowById(ssitem).Enable(enabled)
  2260. else:
  2261. if type(sitem) == types.IntType:
  2262. self.FindWindowById(sitem).Enable(enabled)
  2263. else:
  2264. if type(item) == types.IntType:
  2265. self.FindWindowById(item).Enable(enabled)
  2266. def SetMapObjUseMap(self, nvizType, attrb, map = None):
  2267. """!Update dialog widgets when attribute type changed"""
  2268. if attrb in ('topo', 'color', 'shine'):
  2269. incSel = -1 # decrement selection (no 'unset')
  2270. else:
  2271. incSel = 0
  2272. if nvizType == 'volume' and attrb == 'topo':
  2273. return
  2274. if map is True: # map
  2275. if attrb != 'topo': # changing map topography not allowed
  2276. # not sure why, but here must be disabled both ids, should be fixed!
  2277. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(True)
  2278. if self.win[nvizType][attrb]['const']:
  2279. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
  2280. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(1 + incSel)
  2281. elif map is False: # const
  2282. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
  2283. if self.win[nvizType][attrb]['const']:
  2284. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(True)
  2285. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(2 + incSel)
  2286. else: # unset
  2287. self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(0)
  2288. self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
  2289. if self.win[nvizType][attrb]['const']:
  2290. self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
  2291. def OnSurfaceMap(self, event):
  2292. """!Set surface attribute"""
  2293. if self.vetoGSelectEvt:
  2294. self.vetoGSelectEvt = False
  2295. return
  2296. self.SetMapObjAttrb(nvizType = 'surface', winId = event.GetId())
  2297. def SetMapObjAttrb(self, nvizType, winId):
  2298. """!Set map object (surface/isosurface) attribute (map/constant)"""
  2299. if not self.mapWindow.init:
  2300. return
  2301. attrb = self.__GetWindowName(self.win[nvizType], winId)
  2302. if not attrb:
  2303. return
  2304. if not (nvizType == 'volume' and attrb == 'topo'):
  2305. selection = self.FindWindowById(self.win[nvizType][attrb]['use']).GetSelection()
  2306. if self.win[nvizType][attrb]['required']:
  2307. selection += 1
  2308. if selection == 0: # unset
  2309. useMap = None
  2310. value = ''
  2311. elif selection == 1: # map
  2312. value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
  2313. useMap = True
  2314. else: # constant
  2315. if attrb == 'color':
  2316. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
  2317. # tuple to string
  2318. value = self._getColorString(value)
  2319. else:
  2320. value = self._getPercent(
  2321. self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue(), toPercent = False)
  2322. useMap = False
  2323. else:
  2324. useMap = None
  2325. value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue()
  2326. if not self.pageChanging:
  2327. name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
  2328. if nvizType == 'surface':
  2329. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  2330. data[nvizType]['attribute'][attrb] = { 'map' : useMap,
  2331. 'value' : str(value),
  2332. 'update' : None }
  2333. else:
  2334. data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
  2335. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2336. id = list.GetSelection()
  2337. if id > -1:
  2338. data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
  2339. 'value' : str(value),
  2340. 'update' : None }
  2341. if attrb == 'topo':
  2342. list = self.FindWindowById(self.win['volume']['isosurfs'])
  2343. sel = list.GetSelection()
  2344. list.SetString(sel, "%s %s" % (_("Level"), str(value)))
  2345. list.Check(sel)
  2346. # update properties
  2347. event = wxUpdateProperties(data = data)
  2348. wx.PostEvent(self.mapWindow, event)
  2349. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2350. self.mapWindow.Refresh(False)
  2351. def OnSurfaceResolution(self, event):
  2352. """!Draw resolution changed"""
  2353. self.SetSurfaceResolution()
  2354. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2355. self.mapWindow.Refresh(False)
  2356. def SetSurfaceResolution(self):
  2357. """!Set draw resolution"""
  2358. coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
  2359. fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
  2360. data = self.GetLayerData('surface')
  2361. data['surface']['draw']['resolution'] = { 'coarse' : coarse,
  2362. 'fine' : fine,
  2363. 'update' : None }
  2364. # update properties
  2365. event = wxUpdateProperties(data = data)
  2366. wx.PostEvent(self.mapWindow, event)
  2367. def SetSurfaceMode(self):
  2368. """!Set draw mode"""
  2369. mode = self.FindWindowById(self.win['surface']['draw']['mode']).GetSelection()
  2370. style = self.FindWindowById(self.win['surface']['draw']['style']).GetSelection()
  2371. if style == 0: # wire
  2372. self.FindWindowById(self.win['surface']['draw']['wire-color']).Enable(True)
  2373. elif style == 1: # surface
  2374. self.FindWindowById(self.win['surface']['draw']['wire-color']).Enable(False)
  2375. shade = self.FindWindowById(self.win['surface']['draw']['shading']).GetSelection()
  2376. value, desc = self.mapWindow.nvizDefault.GetDrawMode(mode, style, shade)
  2377. return value, desc
  2378. def OnSurfaceMode(self, event):
  2379. """!Set draw mode"""
  2380. value, desc = self.SetSurfaceMode()
  2381. data = self.GetLayerData('surface')
  2382. data['surface']['draw']['mode'] = { 'value' : value,
  2383. 'desc' : desc,
  2384. 'update' : None }
  2385. # update properties
  2386. event = wxUpdateProperties(data = data)
  2387. wx.PostEvent(self.mapWindow, event)
  2388. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2389. self.mapWindow.Refresh(False)
  2390. def OnSurfaceModeAll(self, event):
  2391. """!Set draw mode (including wire color) for all loaded surfaces"""
  2392. value, desc = self.SetSurfaceMode()
  2393. coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
  2394. fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
  2395. color = self.FindWindowById(self.win['surface']['draw']['wire-color']).GetColour()
  2396. cvalue = self._getColorString(color)
  2397. for name in self.mapWindow.GetLayerNames(type = 'raster'):
  2398. data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
  2399. if not data:
  2400. continue # shouldy no happen
  2401. data['surface']['draw']['all'] = True
  2402. data['surface']['draw']['mode'] = { 'value' : value,
  2403. 'desc' : desc,
  2404. 'update' : None }
  2405. data['surface']['draw']['resolution'] = { 'coarse' : coarse,
  2406. 'fine' : fine,
  2407. 'update' : None }
  2408. data['surface']['draw']['wire-color'] = { 'value' : cvalue,
  2409. 'update' : None }
  2410. # update properties
  2411. event = wxUpdateProperties(data = data)
  2412. wx.PostEvent(self.mapWindow, event)
  2413. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2414. self.mapWindow.Refresh(False)
  2415. def _getColorString(self, color):
  2416. """!Convert color tuple to R:G:B format
  2417. @param color tuple
  2418. @return string R:G:B
  2419. """
  2420. return str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  2421. def _getColorFromString(self, color, delim = ':'):
  2422. """!Convert color string (R:G:B) to wx.Color
  2423. @param color string
  2424. @param delim delimiter
  2425. @return wx.Color instance
  2426. """
  2427. return wx.Color(*map(int, color.split(delim)))
  2428. def _get3dRange(self, name):
  2429. """!Gelper func for getting range of 3d map"""
  2430. ret = gcmd.RunCommand('r3.info', read = True, flags = 'r', map = name)
  2431. if ret:
  2432. range = []
  2433. for value in ret.strip('\n').split('\n'):
  2434. range.append(float(value.split('=')[1]))
  2435. return range
  2436. return -1e6, 1e6
  2437. def _getPercent(self, value, toPercent = True):
  2438. """!Convert values 0 - 255 to percents and vice versa"""
  2439. value = int(value)
  2440. if toPercent:
  2441. value = int(value/255. * 100)
  2442. else:
  2443. value = int(value/100. * 255)
  2444. return value
  2445. def OnSurfaceWireColor(self, event):
  2446. """!Set wire color"""
  2447. data = self.GetLayerData('surface')
  2448. value = self._getColorString(event.GetValue())
  2449. data['surface']['draw']['wire-color'] = { 'value' : value,
  2450. 'update' : None }
  2451. # update properties
  2452. event = wxUpdateProperties(data = data)
  2453. wx.PostEvent(self.mapWindow, event)
  2454. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2455. self.mapWindow.Refresh(False)
  2456. def OnSurfaceAxis(self, event):
  2457. """!Surface position, axis changed"""
  2458. data = self.GetLayerData('surface')
  2459. id = data['surface']['object']['id']
  2460. axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
  2461. slider = self.FindWindowById(self.win['surface']['position']['slider'])
  2462. text = self.FindWindowById(self.win['surface']['position']['text'])
  2463. xydim = self._display.GetLongDim()
  2464. zdim = self._display.GetZRange()
  2465. zdim = zdim[1] - zdim[0]
  2466. x, y, z = self._display.GetSurfacePosition(id)
  2467. if axis == 0: # x
  2468. slider.SetRange(-3 * xydim, 3 * xydim)
  2469. slider.SetValue(x)
  2470. text.SetValue(x)
  2471. elif axis == 1: # y
  2472. slider.SetRange(-3 * xydim, 3 * xydim)
  2473. slider.SetValue(y)
  2474. text.SetValue(y)
  2475. else: # z
  2476. slider.SetRange(-3 * zdim, 3 * zdim)
  2477. slider.SetValue(z)
  2478. text.SetValue(z)
  2479. def OnSurfacePosition(self, event):
  2480. """!Surface position"""
  2481. winName = self.__GetWindowName(self.win['surface'], event.GetId())
  2482. if not winName:
  2483. return
  2484. axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
  2485. value = self.FindWindowById(event.GetId()).GetValue()
  2486. slider = self.FindWindowById(self.win['surface'][winName]['slider'])
  2487. self.AdjustSliderRange(slider = slider, value = value)
  2488. for win in self.win['surface']['position'].itervalues():
  2489. if win in (self.win['surface']['position']['axis'],
  2490. self.win['surface']['position']['reset']):
  2491. continue
  2492. else:
  2493. self.FindWindowById(win).SetValue(value)
  2494. data = self.GetLayerData('surface')
  2495. id = data['surface']['object']['id']
  2496. x, y, z = self._display.GetSurfacePosition(id)
  2497. if axis == 0: # x
  2498. x = value
  2499. elif axis == 1: # y
  2500. y = value
  2501. else: # z
  2502. z = value
  2503. data['surface']['position']['x'] = x
  2504. data['surface']['position']['y'] = y
  2505. data['surface']['position']['z'] = z
  2506. data['surface']['position']['update'] = None
  2507. # update properties
  2508. event = wxUpdateProperties(data = data)
  2509. wx.PostEvent(self.mapWindow, event)
  2510. self.mapWindow.render['quick'] = True
  2511. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2512. self.mapWindow.Refresh(False)
  2513. # self.UpdatePage('surface')
  2514. def OnSurfacePositionChanged(self, event):
  2515. """!Surface position changed"""
  2516. self.mapWindow.render['quick'] = False
  2517. self.mapWindow.Refresh(False)
  2518. def OnSurfacePositionText(self, event):
  2519. """!Surface position changed by textctrl"""
  2520. self.OnSurfacePosition(event)
  2521. self.OnSurfacePositionChanged(None)
  2522. def UpdateVectorShow(self, vecType, enabled):
  2523. """!Enable/disable lines/points widgets
  2524. @param vecType vector type (lines, points)
  2525. """
  2526. if vecType != 'lines' and vecType != 'points':
  2527. return False
  2528. for win in self.win['vector'][vecType].keys():
  2529. if win == 'show':
  2530. continue
  2531. if type(self.win['vector'][vecType][win]) == type({}):
  2532. for swin in self.win['vector'][vecType][win].keys():
  2533. if enabled:
  2534. self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(True)
  2535. else:
  2536. self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(False)
  2537. else:
  2538. if enabled:
  2539. self.FindWindowById(self.win['vector'][vecType][win]).Enable(True)
  2540. else:
  2541. self.FindWindowById(self.win['vector'][vecType][win]).Enable(False)
  2542. return True
  2543. def OnVectorShow(self, event):
  2544. """!Show vector lines/points"""
  2545. winId = event.GetId()
  2546. if winId == self.win['vector']['lines']['show']:
  2547. vecType = 'lines'
  2548. points = False
  2549. else: # points
  2550. vecType = 'points'
  2551. points = True
  2552. checked = event.IsChecked()
  2553. name = self.FindWindowById(self.win['vector']['map']).GetValue()
  2554. item = self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'item')
  2555. data = self.GetLayerData('vector')['vector']
  2556. if checked:
  2557. self.mapWindow.LoadVector(item, points = points)
  2558. else:
  2559. self.mapWindow.UnloadVector(item, points = points)
  2560. self.UpdateVectorShow(vecType, checked)
  2561. if checked:
  2562. try:
  2563. id = data[vecType]['object']['id']
  2564. except KeyError:
  2565. id = -1
  2566. if id > 0:
  2567. self.mapWindow.SetMapObjProperties(item, id, vecType)
  2568. # update properties
  2569. event = wxUpdateProperties(data = data)
  2570. wx.PostEvent(self.mapWindow, event)
  2571. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2572. self.mapWindow.Refresh(False)
  2573. event.Skip()
  2574. def OnVectorDisplay(self, event):
  2575. """!Display vector lines on surface/flat"""
  2576. rasters = self.mapWindow.GetLayerNames('raster')
  2577. if event.GetSelection() == 0: # surface
  2578. if len(rasters) < 1:
  2579. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(False)
  2580. self.FindWindowById(self.win['vector']['lines']['flat']).SetSelection(1)
  2581. return
  2582. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(True)
  2583. # set first found surface
  2584. data = self.GetLayerData('vector')
  2585. data['vector']['lines']['mode']['surface'] = rasters[0]
  2586. self.FindWindowById(self.win['vector']['lines']['surface']).SetStringSelection( \
  2587. rasters[0])
  2588. else: # flat
  2589. self.FindWindowById(self.win['vector']['lines']['surface']).Enable(False)
  2590. self.OnVectorLines(event)
  2591. event.Skip()
  2592. def OnVectorLines(self, event):
  2593. """!Set vector lines mode, apply changes if auto-rendering is enabled"""
  2594. data = self.GetLayerData('vector')
  2595. width = self.FindWindowById(self.win['vector']['lines']['width']).GetValue()
  2596. mode = {}
  2597. if self.FindWindowById(self.win['vector']['lines']['flat']).GetSelection() == 0:
  2598. mode['type'] = 'surface'
  2599. mode['surface'] = {}
  2600. checklist = self.FindWindowById(self.win['vector']['lines']['surface'])
  2601. value = list()
  2602. checked = list()
  2603. for surface in range(checklist.GetCount()):
  2604. value.append(checklist.GetString(surface))
  2605. checked.append(checklist.IsChecked(surface))
  2606. mode['surface']['value'] = value
  2607. mode['surface']['show'] = checked
  2608. else:
  2609. mode['type'] = 'flat'
  2610. for attrb in ('width', 'mode'):
  2611. data['vector']['lines'][attrb]['update'] = None
  2612. data['vector']['lines']['width']['value'] = width
  2613. data['vector']['lines']['mode'] = mode
  2614. color = self.FindWindowById(self.win['vector']['lines']['color']).GetColour()
  2615. if isinstance(color, csel.ColourSelect):
  2616. pass #color picker not yet instantiated
  2617. else:
  2618. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  2619. data['vector']['lines']['color']['update'] = None
  2620. data['vector']['lines']['color']['value'] = color
  2621. # update properties
  2622. event = wxUpdateProperties(data = data)
  2623. wx.PostEvent(self.mapWindow, event)
  2624. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2625. self.mapWindow.Refresh(False)
  2626. def OnVectorHeight(self, event):
  2627. id = event.GetId()
  2628. if id in self.win['vector']['lines']['height'].values():
  2629. vtype = 'lines'
  2630. else:
  2631. vtype = 'points'
  2632. value = self.FindWindowById(id).GetValue()
  2633. slider = self.FindWindowById(self.win['vector'][vtype]['height']['slider'])
  2634. self.AdjustSliderRange(slider = slider, value = value)
  2635. for win in self.win['vector'][vtype]['height'].itervalues():
  2636. self.FindWindowById(win).SetValue(value)
  2637. data = self.GetLayerData('vector')
  2638. data['vector'][vtype]['height'] = { 'value' : value,
  2639. 'update' : None }
  2640. # update properties
  2641. event = wxUpdateProperties(data = data)
  2642. wx.PostEvent(self.mapWindow, event)
  2643. self.mapWindow.render['quick'] = True
  2644. self.mapWindow.render['v' + vtype] = True
  2645. self.mapWindow.Refresh(False)
  2646. event.Skip()
  2647. def OnVectorHeightFull(self, event):
  2648. """!Vector height changed, render in full resolution"""
  2649. self.OnVectorHeight(event)
  2650. ## self.OnVectorSurface(event)
  2651. id = event.GetId()
  2652. if id in self.win['vector']['lines']['height'].values():
  2653. vtype = 'lines'
  2654. else:
  2655. vtype = 'points'
  2656. self.mapWindow.render['quick'] = False
  2657. self.mapWindow.render['v' + vtype] = False
  2658. self.mapWindow.Refresh(False)
  2659. def OnVectorHeightText(self, event):
  2660. """!Vector height changed, render in full resolution"""
  2661. # self.OnVectorHeight(event)
  2662. self.OnVectorHeightFull(event)
  2663. def OnVectorSurface(self, event):
  2664. """!Reference surface for vector map (lines/points)"""
  2665. id = event.GetId()
  2666. if id == self.win['vector']['lines']['surface']:
  2667. vtype = 'lines'
  2668. else:
  2669. vtype = 'points'
  2670. checkList = self.FindWindowById(self.win['vector'][vtype]['surface'])
  2671. checked = []
  2672. surfaces = []
  2673. for items in range(checkList.GetCount()):
  2674. checked.append(checkList.IsChecked(items))
  2675. surfaces.append(checkList.GetString(items))
  2676. data = self.GetLayerData('vector')
  2677. data['vector'][vtype]['mode']['surface'] = { 'value' : surfaces,
  2678. 'show' : checked}
  2679. data['vector'][vtype]['mode']['update'] = None
  2680. # update properties
  2681. event = wxUpdateProperties(data = data)
  2682. wx.PostEvent(self.mapWindow, event)
  2683. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2684. self.mapWindow.Refresh(False)
  2685. def OnVectorPoints(self, event):
  2686. """!Set vector points mode, apply changes if auto-rendering is enabled"""
  2687. data = self.GetLayerData('vector')
  2688. size = self.FindWindowById(self.win['vector']['points']['size']).GetValue()
  2689. marker = self.FindWindowById(self.win['vector']['points']['marker']).GetSelection()
  2690. # width = self.FindWindowById(self.win['vector']['points']['width']).GetValue()
  2691. for attrb in ('size', 'marker'):
  2692. data['vector']['points'][attrb]['update'] = None
  2693. data['vector']['points']['size']['value'] = size
  2694. # data['vector']['points']['width']['value'] = width
  2695. data['vector']['points']['marker']['value'] = marker
  2696. color = self.FindWindowById(self.win['vector']['points']['color']).GetColour()
  2697. if isinstance(color, csel.ColourSelect):
  2698. pass #color picker not yet instantiated
  2699. else:
  2700. color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  2701. data['vector']['points']['color']['update'] = None
  2702. data['vector']['points']['color']['value'] = color
  2703. # update properties
  2704. event = wxUpdateProperties(data = data)
  2705. wx.PostEvent(self.mapWindow, event)
  2706. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2707. self.mapWindow.Refresh(False)
  2708. def OnCheckThematic(self, event):
  2709. """!Switch on/off thematic mapping"""
  2710. check = self.win['vector']['points']['thematic']['check']
  2711. button = self.win['vector']['points']['thematic']['button']
  2712. if self.FindWindowById(check).GetValue():
  2713. checked = True
  2714. else:
  2715. checked = False
  2716. self.FindWindowById(button).Enable(checked)
  2717. data = self.GetLayerData('vector')
  2718. data['vector']['points']['thematic']['use'] = checked
  2719. data['vector']['points']['thematic']['update'] = None
  2720. # update properties
  2721. event = wxUpdateProperties(data = data)
  2722. wx.PostEvent(self.mapWindow, event)
  2723. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2724. self.mapWindow.Refresh(False)
  2725. def OnSetThematic(self, event):
  2726. """!Set options for thematic points"""
  2727. ctable = colorrules.ColorTable(self, raster = False, nviz = True)
  2728. ctable.CentreOnScreen()
  2729. ctable.Show()
  2730. def UpdateIsosurfButtons(self, list):
  2731. """!Enable/disable buttons 'add', 'delete',
  2732. 'move up', 'move down'"""
  2733. nitems = list.GetCount()
  2734. add = self.parent.FindWindowById(self.win['volume']['btnAdd'])
  2735. delete = self.parent.FindWindowById(self.win['volume']['btnDelete'])
  2736. moveDown = self.parent.FindWindowById(self.win['volume']['btnMoveDown'])
  2737. moveUp = self.parent.FindWindowById(self.win['volume']['btnMoveUp'])
  2738. if nitems >= wxnviz.MAX_ISOSURFS:
  2739. # disable add button on max
  2740. add.Enable(False)
  2741. else:
  2742. add.Enable(True)
  2743. if nitems < 1:
  2744. # disable 'delete' if only one item in the lis
  2745. delete.Enable(False)
  2746. else:
  2747. delete.Enable(True)
  2748. if list.GetSelection() >= nitems - 1:
  2749. # disable 'move-down' if last
  2750. moveDown.Enable(False)
  2751. else:
  2752. moveDown.Enable(True)
  2753. if list.GetSelection() < 1:
  2754. # disable 'move-up' if first
  2755. moveUp.Enable(False)
  2756. else:
  2757. moveUp.Enable(True)
  2758. def OnVolumeMode(self, event):
  2759. """!Change mode isosurfaces/slices"""
  2760. mode = self.FindWindowById(self.win['volume']['draw']['mode']).GetSelection()
  2761. data = self.GetLayerData('volume')['volume']
  2762. sizer = self.isoPanel.GetContainingSizer()
  2763. sizer = self.slicePanel.GetContainingSizer()
  2764. listBox = self.FindWindowByName('listStaticBox')
  2765. if mode == 0:
  2766. sizer.Show(self.isoPanel)
  2767. sizer.Hide(self.slicePanel)
  2768. listBox.SetLabel(" %s " % _("List of isosurfaces"))
  2769. data['draw']['mode']['value'] = 0
  2770. data['draw']['mode']['desc'] = 'isosurface'
  2771. else:
  2772. sizer.Hide(self.isoPanel)
  2773. sizer.Show(self.slicePanel)
  2774. listBox.SetLabel(" %s " % _("List of slices"))
  2775. data['draw']['mode']['value'] = 1
  2776. data['draw']['mode']['desc'] = 'slice'
  2777. if event:
  2778. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2779. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2780. self.UpdateVolumePage(layer, data, updateName = False)
  2781. sizer.Layout()
  2782. listBox.GetParent().Fit()
  2783. def OnVolumeDrawMode(self, event):
  2784. """!Set isosurface/slice draw mode"""
  2785. self.SetVolumeDrawMode(event.GetSelection())
  2786. def SetVolumeDrawMode(self, selection):
  2787. """!Set isosurface draw mode"""
  2788. data = self.GetLayerData('volume')['volume']
  2789. id = data['object']['id']
  2790. mode = 0
  2791. if selection == 0:
  2792. mode |= wxnviz.DM_FLAT
  2793. else:
  2794. mode |= wxnviz.DM_GOURAUD
  2795. if self.FindWindowById(self.win['volume']['draw']['mode']).GetSelection() == 0:
  2796. self._display.SetIsosurfaceMode(id, mode)
  2797. data['draw']['shading']['isosurface']['desc'] = 'gouraud'
  2798. data['draw']['shading']['isosurface']['value'] = mode
  2799. else:
  2800. self._display.SetSliceMode(id, mode)
  2801. data['draw']['shading']['slice']['desc'] = 'flat'
  2802. data['draw']['shading']['slice']['value'] = mode
  2803. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2804. self.mapWindow.Refresh(False)
  2805. def OnVolumeResolution(self, event):
  2806. """!Set isosurface/slice draw resolution"""
  2807. self.SetVolumeResolution(event.GetInt())
  2808. def SetVolumeResolution(self, res):
  2809. """!Set isosurface draw resolution"""
  2810. data = self.GetLayerData('volume')['volume']
  2811. id = data['object']['id']
  2812. if self.FindWindowById(self.win['volume']['draw']['mode']).GetSelection() == 0:
  2813. self._display.SetIsosurfaceRes(id, res)
  2814. data['draw']['resolution']['isosurface']['value'] = res
  2815. else:
  2816. self._display.SetSliceRes(id, res)
  2817. data['draw']['resolution']['slice']['value'] = res
  2818. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2819. self.mapWindow.Refresh(False)
  2820. def OnInOutMode(self, event):
  2821. """!Change isosurfaces mode inout"""
  2822. data = self.GetLayerData('volume')['volume']
  2823. id = data['object']['id']
  2824. isosurfId = self.FindWindowById(self.win['volume']['isosurfs']).GetSelection()
  2825. ret = self._display.SetIsosurfaceInOut(id, isosurfId, event.GetInt())
  2826. if ret == 1:
  2827. data['isosurface'][isosurfId]['inout'] = event.GetInt()
  2828. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2829. self.mapWindow.Refresh(False)
  2830. def OnVolumeIsosurfMap(self, event):
  2831. """!Set surface attribute"""
  2832. if self.vetoGSelectEvt:
  2833. self.vetoGSelectEvt = False
  2834. return
  2835. self.SetMapObjAttrb(nvizType = 'volume', winId = event.GetId())
  2836. def OnVolumeCheck(self, event):
  2837. """!Isosurface/slice checked (->load) or unchecked (->unload)"""
  2838. if self.FindWindowById(self.win['volume']['draw']['mode']).GetSelection() == 0:
  2839. mode = 'isosurf'
  2840. else:
  2841. mode = 'slice'
  2842. index = event.GetSelection()
  2843. list = self.FindWindowById(self.win['volume'][mode + 's'])
  2844. data = self.GetLayerData('volume')['volume']
  2845. vid = data['object']['id']
  2846. id = event.GetSelection()
  2847. if mode == 'isosurf':
  2848. if list.IsChecked(index):
  2849. if 'transp' in data['isosurface'][id] and\
  2850. data['isosurface'][id]['transp']['map'] is not None:
  2851. if data['isosurface'][id]['transp']['map']:
  2852. map = True
  2853. value = data['isosurface'][id]['transp']['value']
  2854. elif data['isosurface'][id]['transp']['map'] is not None:
  2855. map = False
  2856. value = data['isosurface'][id]['transp']['value']
  2857. self._display.SetIsosurfaceTransp(vid, id, map, value)
  2858. else:
  2859. self._display.SetIsosurfaceTransp(vid, id, False, "0")
  2860. else:
  2861. # disable -> make transparent
  2862. self._display.SetIsosurfaceTransp(vid, id, False, "255")
  2863. else:
  2864. if list.IsChecked(index):
  2865. value = data['slice'][id]['transp']['value']
  2866. self._display.SetSliceTransp(vid, id, value)
  2867. else:
  2868. # disable -> make transparent
  2869. self._display.SetSliceTransp(vid, id, 255)
  2870. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2871. self.mapWindow.Refresh(False)
  2872. def OnVolumeSelect(self, event):
  2873. """!Isosurface/Slice item selected"""
  2874. if self.FindWindowById(self.win['volume']['draw']['mode']).GetSelection() == 0:
  2875. mode = 'isosurf'
  2876. else:
  2877. mode = 'slice'
  2878. winUp = self.FindWindowById(self.win['volume']['btnMoveUp'])
  2879. winDown = self.FindWindowById(self.win['volume']['btnMoveDown'])
  2880. selection = event.GetSelection()
  2881. if selection == -1:
  2882. return
  2883. elif selection == 0:
  2884. winUp.Enable(False)
  2885. if not winDown.IsEnabled():
  2886. winDown.Enable()
  2887. elif selection == self.FindWindowById(event.GetId()).GetCount() - 1:
  2888. winDown.Enable(False)
  2889. if not winUp.IsEnabled():
  2890. winUp.Enable()
  2891. else:
  2892. if not winDown.IsEnabled():
  2893. winDown.Enable()
  2894. if not winUp.IsEnabled():
  2895. winUp.Enable()
  2896. # update dialog
  2897. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2898. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2899. if mode == 'isosurf':
  2900. data = self.GetLayerData('volume')['volume']['isosurface'][selection]
  2901. self.UpdateVolumeIsosurfPage(data)
  2902. else:
  2903. data = self.GetLayerData('volume')['volume']['slice'][selection]
  2904. self.UpdateVolumeSlicePage(data)
  2905. def OnVolumeAdd(self, event):
  2906. """!Add new isosurface/slice to the list"""
  2907. if self.FindWindowById(self.win['volume']['draw']['mode']).GetSelection() == 0:
  2908. mode = 'isosurf'
  2909. else:
  2910. mode = 'slice'
  2911. list = self.FindWindowById(self.win['volume'][mode + 's'])
  2912. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2913. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2914. data = self.GetLayerData('volume')['volume']
  2915. id = data['object']['id']
  2916. sel = list.GetSelection()
  2917. if mode == 'isosurf':
  2918. isosurfData = self.mapWindow.nvizDefault.SetIsosurfaceDefaultProp()
  2919. if isosurfData['color']['map']:
  2920. isosurfData['color']['value'] = layer.name
  2921. level = isosurfData['topo']['value'] = round(self._get3dRange(name = layer.name)[0], 2)
  2922. if sel < 0 or sel >= list.GetCount() - 1:
  2923. item = list.Append(item = "%s %s" % (_("Level"), str(level)))
  2924. else:
  2925. list.Insert(item = "%s %s" % (_("Level"), str(level)),
  2926. pos = sel+1) # append
  2927. item = sel + 1
  2928. else:
  2929. sliceData = self.mapWindow.nvizDefault.SetSliceDefaultProp()
  2930. axis = ("X", "Y", "Z")[sliceData['position']['axis']]
  2931. if sel < 0 or sel >= list.GetCount() - 1:
  2932. item = list.Append(item = "%s %s" % (_("Slice parallel to"), axis))
  2933. else:
  2934. list.Insert(item = "%s" % (_("Slice parallel to"), axis),
  2935. pos = sel+1) # append
  2936. item = sel + 1
  2937. list.Check(item)
  2938. list.SetSelection(item)
  2939. if mode == 'isosurf':
  2940. data['isosurface'].insert(item, isosurfData)
  2941. # add isosurface
  2942. self._display.AddIsosurface(id, float(level))
  2943. else:
  2944. data['slice'].insert(item, sliceData)
  2945. # add isosurface
  2946. nslice = self._display.AddSlice(id)
  2947. self._display.SetSlicePosition(id, nslice -1, sliceData['position']['x1'], sliceData['position']['x2'],
  2948. sliceData['position']['y1'], sliceData['position']['y2'],
  2949. sliceData['position']['z1'], sliceData['position']['z2'],
  2950. sliceData['position']['axis'])
  2951. # update properties
  2952. event = wxUpdateProperties(data = data)
  2953. wx.PostEvent(self.mapWindow, event)
  2954. # update buttons
  2955. self.UpdateIsosurfButtons(list)
  2956. if mode == 'isosurf':
  2957. self.UpdateVolumeIsosurfPage(isosurfData)
  2958. else:
  2959. self.UpdateVolumeSlicePage(sliceData)
  2960. if self.mapDisplay.statusbarWin['render'].IsChecked():
  2961. self.mapWindow.Refresh(False)
  2962. event.Skip()
  2963. def OnVolumeDelete(self, event):
  2964. """!Remove isosurface/slice from list"""
  2965. if self.FindWindowById(self.win['volume']['draw']['mode']).GetSelection() == 0:
  2966. mode = 'isosurf'
  2967. else:
  2968. mode = 'slice'
  2969. list = self.FindWindowById(self.win['volume'][mode + 's'])
  2970. # remove item from list
  2971. id = list.GetSelection()
  2972. list.Delete(id)
  2973. # select last item
  2974. if list.GetCount() > 0:
  2975. list.SetSelection(list.GetCount()-1)
  2976. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  2977. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  2978. data = self.GetLayerData('volume')['volume']
  2979. vid = data['object']['id']
  2980. # delete isosurface
  2981. if mode == 'isosurf':
  2982. del data['isosurface'][id]
  2983. self._display.DeleteIsosurface(vid, id)
  2984. else:
  2985. del data['slice'][id]
  2986. self._display.DeleteSlice(vid, id)
  2987. # update buttons
  2988. if list.GetCount() > 0:
  2989. if mode == 'isosurf':
  2990. self.UpdateVolumeIsosurfPage(data['isosurface'][list.GetSelection()])
  2991. else:
  2992. self.UpdateVolumeSlicePage(data['slice'][list.GetSelection()])
  2993. else:
  2994. if mode == 'isosurf':
  2995. self.UpdateVolumeIsosurfPage(data['attribute'])
  2996. else:
  2997. self.UpdateVolumeSlicePage(None)
  2998. self.UpdateIsosurfButtons(list)
  2999. if self.mapDisplay.statusbarWin['render'].IsChecked():
  3000. self.mapWindow.Refresh(False)
  3001. event.Skip()
  3002. def OnVolumeMoveUp(self, event):
  3003. """!Move isosurface/slice up in the list"""
  3004. if self.FindWindowById(self.win['volume']['draw']['mode']).GetSelection() == 0:
  3005. mode = 'isosurf'
  3006. else:
  3007. mode = 'slice'
  3008. list = self.FindWindowById(self.win['volume'][mode + 's'])
  3009. sel = list.GetSelection()
  3010. if sel < 1:
  3011. return # this should not happen
  3012. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  3013. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  3014. data = self.GetLayerData('volume')['volume']
  3015. id = data['object']['id']
  3016. # move item up
  3017. text = list.GetStringSelection()
  3018. list.Insert(item = text, pos = sel-1)
  3019. list.Check(sel-1)
  3020. list.SetSelection(sel-1)
  3021. list.Delete(sel+1)
  3022. if mode == 'isosurf':
  3023. data['isosurface'].insert(sel-1, data['isosurface'][sel])
  3024. del data['isosurface'][sel+1]
  3025. self._display.MoveIsosurface(id, sel, True)
  3026. else:
  3027. data['slice'].insert(sel-1, data['slice'][sel])
  3028. del data['slice'][sel+1]
  3029. self._display.MoveSlice(id, sel, True)
  3030. # update buttons
  3031. self.UpdateIsosurfButtons(list)
  3032. if self.mapDisplay.statusbarWin['render'].IsChecked():
  3033. self.mapWindow.Refresh(False)
  3034. event.Skip()
  3035. def OnVolumeMoveDown(self, event):
  3036. """!Move isosurface/slice down in the list"""
  3037. if self.FindWindowById(self.win['volume']['draw']['mode']).GetSelection() == 0:
  3038. mode = 'isosurf'
  3039. else:
  3040. mode = 'slice'
  3041. list = self.FindWindowById(self.win['volume'][mode + 's'])
  3042. sel = list.GetSelection()
  3043. if sel >= list.GetCount() - 1:
  3044. return # this should not happen
  3045. name = self.FindWindowById(self.win['volume']['map']).GetValue()
  3046. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  3047. data = self.GetLayerData('volume')['volume']
  3048. id = data['object']['id']
  3049. # move item up
  3050. text = list.GetStringSelection()
  3051. list.Insert(item = text, pos = sel+2)
  3052. list.Check(sel+2)
  3053. list.SetSelection(sel+2)
  3054. list.Delete(sel)
  3055. if mode == 'isosurf':
  3056. data['isosurface'].insert(sel+2, data['isosurface'][sel])
  3057. del data['isosurface'][sel]
  3058. self._display.MoveIsosurface(id, sel, False)
  3059. else:
  3060. data['slice'].insert(sel+2, data['slice'][sel])
  3061. del data['slice'][sel]
  3062. self._display.MoveSlice(id, sel, False)
  3063. # update buttons
  3064. self.UpdateIsosurfButtons(list)
  3065. if self.mapDisplay.statusbarWin['render'].IsChecked():
  3066. self.mapWindow.Refresh(False)
  3067. event.Skip()
  3068. def OnVolumePositionChanged(self, event):
  3069. """!Volume position changed"""
  3070. self.mapWindow.render['quick'] = False
  3071. self.mapWindow.Refresh(False)
  3072. def OnVolumePosition(self, event):
  3073. """!Volume position"""
  3074. winName = self.__GetWindowName(self.win['volume'], event.GetId())
  3075. if not winName:
  3076. return
  3077. axis = self.FindWindowById(self.win['volume']['position']['axis']).GetSelection()
  3078. value = self.FindWindowById(event.GetId()).GetValue()
  3079. slider = self.FindWindowById(self.win['volume'][winName]['slider'])
  3080. self.AdjustSliderRange(slider = slider, value = value)
  3081. for win in self.win['volume']['position'].itervalues():
  3082. if win in (self.win['volume']['position']['axis'],
  3083. self.win['volume']['position']['reset']):
  3084. continue
  3085. else:
  3086. self.FindWindowById(win).SetValue(value)
  3087. data = self.GetLayerData('volume')
  3088. id = data['volume']['object']['id']
  3089. x, y, z = self._display.GetVolumePosition(id)
  3090. if axis == 0: # x
  3091. x = value
  3092. elif axis == 1: # y
  3093. y = value
  3094. else: # z
  3095. z = value
  3096. data['volume']['position']['x'] = x
  3097. data['volume']['position']['y'] = y
  3098. data['volume']['position']['z'] = z
  3099. data['volume']['position']['update'] = None
  3100. # update properties
  3101. event = wxUpdateProperties(data = data)
  3102. wx.PostEvent(self.mapWindow, event)
  3103. self.mapWindow.render['quick'] = True
  3104. if self.mapDisplay.statusbarWin['render'].IsChecked():
  3105. self.mapWindow.Refresh(False)
  3106. def OnVolumeAxis(self, event):
  3107. """!Volume position, axis changed"""
  3108. data = self.GetLayerData('volume')
  3109. id = data['volume']['object']['id']
  3110. axis = self.FindWindowById(self.win['volume']['position']['axis']).GetSelection()
  3111. slider = self.FindWindowById(self.win['volume']['position']['slider'])
  3112. text = self.FindWindowById(self.win['volume']['position']['text'])
  3113. xydim = self._display.GetLongDim()
  3114. zdim = self._display.GetZRange()
  3115. zdim = zdim[1] - zdim[0]
  3116. x, y, z = self._display.GetVolumePosition(id)
  3117. if axis == 0: # x
  3118. slider.SetRange(-3 * xydim, 3 * xydim)
  3119. slider.SetValue(x)
  3120. text.SetValue(x)
  3121. elif axis == 1: # y
  3122. slider.SetRange(-3 * xydim, 3 * xydim)
  3123. slider.SetValue(y)
  3124. text.SetValue(y)
  3125. else: # z
  3126. slider.SetRange(-3 * zdim, 3 * zdim)
  3127. slider.SetValue(z)
  3128. text.SetValue(z)
  3129. def OnVolumePositionText(self, event):
  3130. """!Volume position changed by textctrl"""
  3131. self.OnVolumePosition(event)
  3132. self.OnVolumePositionChanged(None)
  3133. def OnResetVolumePosition(self, event):
  3134. """!Reset position of volume"""
  3135. for win in self.win['volume']['position'].itervalues():
  3136. if win == self.win['volume']['position']['axis']:
  3137. self.FindWindowById(win).SetSelection(0)
  3138. elif win == self.win['volume']['position']['reset']:
  3139. continue
  3140. else:
  3141. self.FindWindowById(win).SetValue(0)
  3142. data = self.GetLayerData('volume')
  3143. data['volume']['position']['x'] = 0
  3144. data['volume']['position']['y'] = 0
  3145. data['volume']['position']['z'] = 0
  3146. data['volume']['position']['update'] = None
  3147. # update properties
  3148. event = wxUpdateProperties(data = data)
  3149. wx.PostEvent(self.mapWindow, event)
  3150. if self.mapDisplay.statusbarWin['render'].IsChecked():
  3151. self.mapWindow.Refresh(False)
  3152. def OnVolumeSliceAxes(self, event):
  3153. """!Slice axis changed"""
  3154. self.UpdateSliceLabels()
  3155. data = self.GetLayerData('volume')
  3156. list = self.FindWindowById(self.win['volume']['slices'])
  3157. sel = list.GetSelection()
  3158. if sel < 0:
  3159. return
  3160. axis = self.FindWindowById(self.win['volume']['slice']['axes']).GetSelection()
  3161. data['volume']['slice'][sel]['position']['axis'] = axis
  3162. data['volume']['slice'][sel]['position']['update'] = None
  3163. axis = ("X", "Y", "Z")[axis]
  3164. list.SetString(sel, "%s %s" % (_("Slice parallel to"), axis))
  3165. list.Check(sel)
  3166. # update properties
  3167. event = wxUpdateProperties(data = data)
  3168. wx.PostEvent(self.mapWindow, event)
  3169. if self.mapDisplay.statusbarWin['render'].IsChecked():
  3170. self.mapWindow.Refresh(False)
  3171. def OnSliceTransparency(self, event):
  3172. """!Slice transparency changed"""
  3173. data = self.GetLayerData('volume')
  3174. list = self.FindWindowById(self.win['volume']['slices'])
  3175. sel = list.GetSelection()
  3176. if sel < 0:
  3177. return
  3178. val = self.FindWindowById(self.win['volume']['slice']['transp']).GetValue()
  3179. data['volume']['slice'][sel]['transp']['value'] = self._getPercent(val, toPercent = False)
  3180. data['volume']['slice'][sel]['transp']['update'] = None
  3181. # update properties
  3182. event = wxUpdateProperties(data = data)
  3183. wx.PostEvent(self.mapWindow, event)
  3184. if self.mapDisplay.statusbarWin['render'].IsChecked():
  3185. self.mapWindow.Refresh(False)
  3186. def OnSliceReset(self, event):
  3187. """!Slice position reset"""
  3188. data = self.GetLayerData('volume')
  3189. list = self.FindWindowById(self.win['volume']['slices'])
  3190. sel = list.GetSelection()
  3191. if sel < 0:
  3192. return
  3193. for coord, val in zip(('x1', 'x2', 'y1', 'y2', 'z1', 'z2'),(0, 1, 0, 1, 0, 1, 0)):
  3194. data['volume']['slice'][sel]['position'][coord] = val
  3195. data['volume']['slice'][sel]['position']['update'] = None
  3196. self.UpdateVolumeSlicePage(data['volume']['slice'][sel])
  3197. # update properties
  3198. event = wxUpdateProperties(data = data)
  3199. wx.PostEvent(self.mapWindow, event)
  3200. if self.mapDisplay.statusbarWin['render'].IsChecked():
  3201. self.mapWindow.Refresh(False)
  3202. def OnSlicePositionChange(self, event):
  3203. """!Slice position is changing"""
  3204. data = self.GetLayerData('volume')
  3205. list = self.FindWindowById(self.win['volume']['slices'])
  3206. sel = list.GetSelection()
  3207. if sel < 0:
  3208. return
  3209. win = self.win['volume']['slice']
  3210. winId = event.GetId()
  3211. value = event.GetInt()/100.
  3212. for coord in ('x1', 'x2', 'y1', 'y2', 'z1', 'z2'):
  3213. if win['slider_' + coord] == winId:
  3214. data['volume']['slice'][sel]['position'][coord] = value
  3215. data['volume']['slice'][sel]['position']['update'] = None
  3216. break
  3217. self.mapWindow.render['quick'] = True
  3218. # update properties
  3219. event = wxUpdateProperties(data = data)
  3220. wx.PostEvent(self.mapWindow, event)
  3221. if self.mapDisplay.statusbarWin['render'].IsChecked():
  3222. self.mapWindow.Refresh(False)
  3223. def OnSlicePositionChanged(self, event):
  3224. """!Slice position is changed"""
  3225. self.mapWindow.render['quick'] = False
  3226. if self.mapDisplay.statusbarWin['render'].IsChecked():
  3227. self.mapWindow.Refresh(False)
  3228. def OnCPlaneSelection(self, event):
  3229. """!Cutting plane selected"""
  3230. plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
  3231. try:
  3232. planeIndex = int(plane.split()[1])
  3233. self.EnablePage("cplane", enabled = True)
  3234. except:
  3235. planeIndex = -1
  3236. self.EnablePage("cplane", enabled = False)
  3237. self.mapWindow.SelectCPlane(planeIndex)
  3238. if self.mapDisplay.statusbarWin['render'].IsChecked():
  3239. self.mapWindow.Refresh(False)
  3240. self.UpdateCPlanePage(planeIndex)
  3241. def OnCPlaneChanging(self, event):
  3242. """!Cutting plane is changing"""
  3243. plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
  3244. try:
  3245. planeIndex = int(plane.split()[1])
  3246. except:#TODO disabled page
  3247. planeIndex = -1
  3248. if event.GetId() in (self.win['cplane']['rotation']['rot'].values() +
  3249. self.win['cplane']['rotation']['tilt'].values()):
  3250. action = 'rotation'
  3251. else:
  3252. action = 'position'
  3253. data = self.mapWindow.cplanes[planeIndex][action]
  3254. self.OnScroll(event, self.win['cplane'][action], data)
  3255. self.mapWindow.render['quick'] = True
  3256. event = wxUpdateCPlane(update = (action,), current = planeIndex)
  3257. wx.PostEvent(self.mapWindow, event)
  3258. if self.mapDisplay.statusbarWin['render'].IsChecked():
  3259. self.mapWindow.Refresh(False)
  3260. def OnCPlaneChangeDone(self, event):
  3261. """!Cutting plane change done"""
  3262. self.mapWindow.render['quick'] = False
  3263. if self.mapDisplay.statusbarWin['render'].IsChecked():
  3264. self.mapWindow.Refresh(False)
  3265. def OnCPlaneChangeText(self, event):
  3266. """!Cutting plane changed by textctrl"""
  3267. for axis in ('x', 'y', 'z'):
  3268. if event.GetId() == self.win['cplane']['position'][axis]['text']:
  3269. value = self.FindWindowById(event.GetId()).GetValue()
  3270. slider = self.FindWindowById(self.win['cplane']['position'][axis]['slider'])
  3271. self.AdjustSliderRange(slider = slider, value = value)
  3272. self.OnCPlaneChanging(event = event)
  3273. self.OnCPlaneChangeDone(None)
  3274. def OnCPlaneShading(self, event):
  3275. """!Cutting plane shading changed"""
  3276. shading = self.FindWindowById(self.win['cplane']['shading']).GetSelection()
  3277. plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
  3278. try:
  3279. planeIndex = int(plane.split()[1])
  3280. except:#TODO disabled page
  3281. planeIndex = -1
  3282. self.mapWindow.cplanes[planeIndex]['shading'] = shading
  3283. event = wxUpdateCPlane(update = ('shading',), current = planeIndex)
  3284. wx.PostEvent(self.mapWindow, event)
  3285. self.OnCPlaneChangeDone(None)
  3286. def OnCPlaneReset(self, event):
  3287. """!Reset current cutting plane"""
  3288. plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
  3289. try:
  3290. planeIndex = int(plane.split()[1])
  3291. except:#TODO disabled page
  3292. planeIndex = -1
  3293. self.mapWindow.cplanes[planeIndex] = copy.deepcopy(UserSettings.Get(group = 'nviz',
  3294. key = 'cplane'))
  3295. event = wxUpdateCPlane(update = ('position','rotation','shading'), current = planeIndex)
  3296. wx.PostEvent(self.mapWindow, event)
  3297. self.OnCPlaneChangeDone(None)
  3298. self.UpdateCPlanePage(planeIndex)
  3299. def OnCPlanePos(self, event):
  3300. """!Place cutting plane rotation center interactively"""
  3301. self.mapWindow.mouse['use'] = 'cplane'
  3302. self.mapWindow.SetCursor(self.mapWindow.cursors["cross"])
  3303. self.parent.curr_page.maptree.mapdisplay.SetFocus()
  3304. self.parent.curr_page.maptree.mapdisplay.Raise()
  3305. def OnDecorationPlacement(self, event):
  3306. """!Place an arrow/scalebar by clicking on display"""
  3307. if event.GetId() == self.win['decoration']['arrow']['place']:
  3308. type = 'arrow'
  3309. elif event.GetId() == self.win['decoration']['scalebar']['place']:
  3310. type = 'scalebar'
  3311. else: return
  3312. if event.GetInt():
  3313. self.mapWindow.mouse['use'] = type
  3314. self.mapWindow.SetCursor(self.mapWindow.cursors["cross"])
  3315. else:
  3316. self.mapWindow.mouse['use'] = 'default'
  3317. self.mapWindow.SetCursor(self.mapWindow.cursors["default"])
  3318. def OnArrowDelete(self, event):
  3319. """!Delete arrow"""
  3320. self._display.DeleteArrow()
  3321. self.mapWindow.decoration['arrow']['show'] = False
  3322. self.mapWindow.Refresh(False)
  3323. def OnScalebarDelete(self, event):
  3324. """!Delete scalebar"""
  3325. try:
  3326. id = self.mapWindow.decoration['scalebar'][-1]['id']
  3327. except IndexError:
  3328. return
  3329. self._display.DeleteScalebar(id = id)
  3330. del self.mapWindow.decoration['scalebar'][-1]
  3331. self.mapWindow.Refresh(False)
  3332. def OnDecorationProp(self, event):
  3333. """!Set arrow/scalebar properties"""
  3334. if event.GetId() in self.win['decoration']['arrow'].values():
  3335. type = 'arrow'
  3336. elif event.GetId() in self.win['decoration']['scalebar'].values():
  3337. type = 'scalebar'
  3338. else: return
  3339. color = self.FindWindowById(self.win['decoration'][type]['color']).GetValue()
  3340. size = self.FindWindowById(self.win['decoration'][type]['size']).GetValue()
  3341. if type == 'arrow':
  3342. self.mapWindow.decoration[type]['color'] = self._getColorString(color)
  3343. self.mapWindow.decoration[type]['size'] = size
  3344. elif type == 'scalebar'and self.mapWindow.decoration['scalebar']:
  3345. self.mapWindow.decoration[type][-1]['color'] = self._getColorString(color)
  3346. self.mapWindow.decoration[type][-1]['size'] = size
  3347. if type == 'arrow' and self.mapWindow.decoration['arrow']['show']:
  3348. self._display.SetArrow(self.mapWindow.decoration['arrow']['position']['x'],
  3349. self.mapWindow.decoration['arrow']['position']['y'],
  3350. self.mapWindow.decoration['arrow']['size'],
  3351. self.mapWindow.decoration['arrow']['color'])
  3352. self._display.DrawArrow()
  3353. elif type == 'scalebar' and self.mapWindow.decoration['scalebar']:
  3354. self._display.SetScalebar(self.mapWindow.decoration['scalebar'][-1]['id'],
  3355. self.mapWindow.decoration['scalebar'][-1]['position']['x'],
  3356. self.mapWindow.decoration['scalebar'][-1]['position']['y'],
  3357. self.mapWindow.decoration['scalebar'][-1]['size'],
  3358. self.mapWindow.decoration['scalebar'][-1]['color'])
  3359. self._display.DrawScalebar()
  3360. self.mapWindow.Refresh(False)
  3361. def UpdatePage(self, pageId):
  3362. """!Update dialog (selected page)"""
  3363. self.pageChanging = True
  3364. Debug.msg(1, "NvizToolWindow.UpdatePage(): %s", pageId)
  3365. if pageId == 'view':
  3366. self.SetPage('view')
  3367. hmin = self.mapWindow.iview['height']['min']
  3368. hmax = self.mapWindow.iview['height']['max']
  3369. hval = self.mapWindow.iview['height']['value']
  3370. zmin = self.mapWindow.view['z-exag']['min']
  3371. zmax = self.mapWindow.view['z-exag']['max']
  3372. zval = self.mapWindow.view['z-exag']['value']
  3373. for control in ('slider','text'):
  3374. self.FindWindowById(self.win['view']['height'][control]).SetRange(
  3375. hmin,hmax)
  3376. self.FindWindowById(self.win['view']['z-exag'][control]).SetRange(
  3377. zmin, zmax)
  3378. self.FindWindowById(self.win['view']['height'][control]).SetValue(hval)
  3379. self.FindWindowById(self.win['view']['z-exag'][control]).SetValue(zval)
  3380. self.FindWindowById(self.win['view']['background']['color']).SetColour(\
  3381. self.mapWindow.view['background']['color'])
  3382. tval = self.mapWindow.view['twist']['value']
  3383. pval = self.mapWindow.view['persp']['value']
  3384. for control in ('slider','text'):
  3385. self.FindWindowById(self.win['view']['twist'][control]).SetValue(tval)
  3386. self.FindWindowById(self.win['view']['persp'][control]).SetValue(pval)
  3387. elif pageId in ('surface', 'vector', 'volume'):
  3388. name = self.FindWindowById(self.win[pageId]['map']).GetValue()
  3389. data = self.GetLayerData(pageId)
  3390. if data:
  3391. if pageId == 'surface':
  3392. layer = self.mapWindow.GetLayerByName(name, mapType = 'raster')
  3393. self.UpdateSurfacePage(layer, data['surface'])
  3394. elif pageId == 'vector':
  3395. layer = self.mapWindow.GetLayerByName(name, mapType = 'vector')
  3396. self.UpdateVectorPage(layer, data['vector'])
  3397. elif pageId == 'volume':
  3398. layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
  3399. self.UpdateVolumePage(layer, data['volume'])
  3400. elif pageId == 'light':
  3401. zval = self.mapWindow.light['position']['z']
  3402. bval = self.mapWindow.light['bright']
  3403. aval = self.mapWindow.light['ambient']
  3404. for control in ('slider','text'):
  3405. self.FindWindowById(self.win['light']['z'][control]).SetValue(zval)
  3406. self.FindWindowById(self.win['light']['bright'][control]).SetValue(bval)
  3407. self.FindWindowById(self.win['light']['ambient'][control]).SetValue(aval)
  3408. self.FindWindowById(self.win['light']['color']).SetColour(self.mapWindow.light['color'])
  3409. self.FindWindowById(self.win['light']['position']).PostDraw()
  3410. elif pageId == 'fringe':
  3411. win = self.FindWindowById(self.win['fringe']['map'])
  3412. win.SetValue(self.FindWindowById(self.win['surface']['map']).GetValue())
  3413. elif pageId == 'decoration':
  3414. win = self.FindWindowById(self.win['decoration']['arrow']['size'])
  3415. win.SetValue(self.mapWindow.decoration['arrow']['size'])
  3416. win = self.FindWindowById(self.win['decoration']['scalebar']['size'])
  3417. win.SetValue(self.mapWindow._getDecorationSize())
  3418. elif pageId == 'constant':
  3419. if self.mapWindow.constants:
  3420. surface = self.FindWindowById(self.win['constant']['surface'])
  3421. for item in self.mapWindow.constants:
  3422. surface.Append(_("constant#") + str(item['constant']['object']['name']))
  3423. surface.SetSelection(0)
  3424. self.OnConstantSelection(None)
  3425. self.EnablePage('constant', True)
  3426. elif pageId == 'cplane':
  3427. count = self._display.GetCPlanesCount()
  3428. choices = [_("None"),]
  3429. for plane in range(count):
  3430. choices.append("%s %i" % (_("Plane"), plane))
  3431. self.FindWindowById(self.win['cplane']['planes']).SetItems(choices)
  3432. current = 0
  3433. for i, cplane in enumerate(self.mapWindow.cplanes):
  3434. if cplane['on']:
  3435. current = i + 1
  3436. self.FindWindowById(self.win['cplane']['planes']).SetSelection(current)
  3437. xyRange, zRange = self._display.GetXYRange(), self._display.GetZRange()
  3438. if xyRange > 0: # GTK warning
  3439. self.FindWindowById(self.win['cplane']['position']['x']['slider']).SetRange(
  3440. -xyRange/2., xyRange/2.)
  3441. self.FindWindowById(self.win['cplane']['position']['y']['slider']).SetRange(
  3442. -xyRange/2., xyRange/2.)
  3443. if zRange[0] - zRange[1] > 0:
  3444. self.FindWindowById(self.win['cplane']['position']['z']['slider']).SetRange(zRange[0], zRange[1])
  3445. self.FindWindowById(self.win['cplane']['position']['z']['slider']).SetValue(zRange[0])
  3446. self.FindWindowById(self.win['cplane']['position']['z']['text']).SetValue(zRange[0])
  3447. self.OnCPlaneSelection(None)
  3448. self.Update()
  3449. self.pageChanging = False
  3450. def UpdateCPlanePage(self, index):
  3451. """!Update widgets according to selected clip plane"""
  3452. if index == -1:
  3453. return
  3454. data = self.mapWindow.cplanes[index]
  3455. for widget in ('text', 'slider'):
  3456. for axes in ('x', 'y', 'z'):
  3457. self.FindWindowById(self.win['cplane']['position'][axes][widget]).SetValue(data['position'][axes])
  3458. for each in ('tilt', 'rot'):
  3459. self.FindWindowById(self.win['cplane']['rotation'][each][widget]).SetValue(data['rotation'][each])
  3460. self.FindWindowById(self.win['cplane']['shading']).SetSelection(data['shading'])
  3461. def UpdateSurfacePage(self, layer, data, updateName = True):
  3462. """!Update surface page"""
  3463. ret = gcmd.RunCommand('r.info',
  3464. read = True,
  3465. flags = 'm',
  3466. map = layer.name)
  3467. if ret:
  3468. desc = ret.split('=')[1].rstrip('\n')
  3469. else:
  3470. desc = None
  3471. if updateName:
  3472. self.FindWindowById(self.win['surface']['map']).SetValue(layer.name)
  3473. self.FindWindowById(self.win['surface']['desc']).SetLabel(desc)
  3474. # attributes
  3475. if layer and layer.type == 'raster':
  3476. self.vetoGSelectEvt = True
  3477. self.FindWindowById(self.win['surface']['color']['map']).SetValue(layer.name)
  3478. else:
  3479. self.FindWindowById(self.win['surface']['color']['map']).SetValue('')
  3480. self.SetMapObjUseMap(nvizType = 'surface',
  3481. attrb = 'color', map = True) # -> map
  3482. if 'color' in data['attribute']:
  3483. value = data['attribute']['color']['value']
  3484. if data['attribute']['color']['map']:
  3485. self.FindWindowById(self.win['surface']['color']['map']).SetValue(value)
  3486. else: # constant
  3487. color = map(int, value.split(':'))
  3488. self.FindWindowById(self.win['surface']['color']['const']).SetColour(color)
  3489. self.SetMapObjUseMap(nvizType = 'surface',
  3490. attrb = 'color', map = data['attribute']['color']['map'])
  3491. self.SetMapObjUseMap(nvizType = 'surface',
  3492. attrb = 'shine', map = data['attribute']['shine']['map'])
  3493. value = data['attribute']['shine']['value']
  3494. if data['attribute']['shine']['map']:
  3495. self.FindWindowById(self.win['surface']['shine']['map']).SetValue(value)
  3496. else:
  3497. self.FindWindowById(self.win['surface']['shine']['const']).SetValue(self._getPercent(value))
  3498. if 'transp' in data['attribute']:
  3499. value = data['attribute']['transp']['value']
  3500. if data['attribute']['transp']['map']:
  3501. self.FindWindowById(self.win['surface']['color']['map']).SetValue(value)
  3502. else:
  3503. self.FindWindowById(self.win['surface']['transp']['const']).SetValue(self._getPercent(value))
  3504. self.SetMapObjUseMap(nvizType = 'surface', attrb = 'transp', map = data['attribute']['transp']['map'])
  3505. else:
  3506. self.SetMapObjUseMap(nvizType = 'surface', attrb = 'transp', map = None)
  3507. #
  3508. # draw
  3509. #
  3510. for control, drawData in data['draw'].iteritems():
  3511. if control == 'all': # skip 'all' property
  3512. continue
  3513. if control == 'resolution':
  3514. self.FindWindowById(self.win['surface']['draw']['res-coarse']).SetValue(drawData['coarse'])
  3515. self.FindWindowById(self.win['surface']['draw']['res-fine']).SetValue(drawData['fine'])
  3516. continue
  3517. if control == 'mode':
  3518. if drawData['desc']['mode'] == 'coarse':
  3519. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(0)
  3520. elif drawData['desc']['mode'] == 'fine':
  3521. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(1)
  3522. else: # both
  3523. self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(2)
  3524. if drawData['desc']['style'] == 'wire':
  3525. self.FindWindowById(self.win['surface']['draw']['style']).SetSelection(0)
  3526. else: # surface
  3527. self.FindWindowById(self.win['surface']['draw']['style']).SetSelection(1)
  3528. if drawData['desc']['shading'] == 'flat':
  3529. self.FindWindowById(self.win['surface']['draw']['shading']).SetSelection(0)
  3530. else: # gouraud
  3531. self.FindWindowById(self.win['surface']['draw']['shading']).SetSelection(1)
  3532. continue
  3533. value = drawData['value']
  3534. win = self.FindWindowById(self.win['surface']['draw'][control])
  3535. name = win.GetName()
  3536. if name == "selection":
  3537. win.SetSelection(value)
  3538. elif name == "colour":
  3539. color = map(int, value.split(':'))
  3540. win.SetColour(color)
  3541. else:
  3542. win.SetValue(value)
  3543. #
  3544. # position
  3545. #
  3546. dim = self._display.GetLongDim()
  3547. self.FindWindowById(self.win['surface']['position']['slider']).SetRange(-2 * dim, 2 * dim)
  3548. if 'x' in data['position']:
  3549. xval = data['position']['x']
  3550. self.FindWindowById(self.win['surface']['position']['axis']).SetSelection(0)
  3551. for control in ('slider','text'):
  3552. self.FindWindowById(self.win['surface']['position'][control]).SetValue(xval)
  3553. # enable/disable res widget + set draw mode
  3554. self.OnSurfaceMode(event = None)
  3555. def VectorInfo(self, layer):
  3556. """!Get number of points/lines
  3557. @param layer MapLayer instance
  3558. @return num of points/features (expect of points)
  3559. @return None
  3560. """
  3561. vInfo = grass.vector_info_topo(layer.GetName())
  3562. if not vInfo:
  3563. return None
  3564. nprimitives = 0
  3565. for key, value in vInfo.iteritems():
  3566. if key in ('points',
  3567. 'lines',
  3568. 'boundaries',
  3569. 'centroids',
  3570. 'faces',
  3571. 'kernels'):
  3572. nprimitives += value
  3573. return (vInfo['points'], vInfo['lines'], nprimitives, vInfo['map3d'])
  3574. def UpdateVectorPage(self, layer, data, updateName = True):
  3575. """!Update vector page"""
  3576. npoints, nlines, nfeatures, mapIs3D = self.VectorInfo(layer)
  3577. if mapIs3D:
  3578. desc = _("Vector map is 3D")
  3579. enable = False
  3580. else:
  3581. desc = _("Vector map is 2D")
  3582. enable = True
  3583. desc += " - " + _("%(features)d features (%(points)d points)") % \
  3584. { 'features' : nfeatures, 'points' : npoints }
  3585. if updateName:
  3586. self.FindWindowById(self.win['vector']['map']).SetValue(layer.name)
  3587. self.FindWindowById(self.win['vector']['desc']).SetLabel(desc)
  3588. self.FindWindowById(self.win['vector']['lines']['flat']).Enable(enable)
  3589. for v in ('lines', 'points'):
  3590. self.FindWindowById(self.win['vector'][v]['surface']).Enable(enable)
  3591. self.FindWindowById(self.win['vector'][v]['height']['slider']).Enable(enable)
  3592. self.FindWindowById(self.win['vector'][v]['height']['text']).Enable(enable)
  3593. #
  3594. # lines
  3595. #
  3596. showLines = self.FindWindowById(self.win['vector']['lines']['show'])
  3597. if 'object' in data['lines']:
  3598. showLines.SetValue(True)
  3599. else:
  3600. showLines.SetValue(False)
  3601. if nlines > 0:
  3602. showLines.Enable(True)
  3603. else:
  3604. showLines.Enable(False)
  3605. self.UpdateVectorShow('lines',
  3606. showLines.IsChecked())
  3607. width = self.FindWindowById(self.win['vector']['lines']['width'])
  3608. width.SetValue(data['lines']['width']['value'])
  3609. color = self.FindWindowById(self.win['vector']['lines']['color'])
  3610. color.SetValue(map(int, data['lines']['color']['value'].split(':')))
  3611. for vtype in ('lines', 'points'):
  3612. if vtype == 'lines':
  3613. display = self.FindWindowById(self.win['vector']['lines']['flat'])
  3614. if data[vtype]['mode']['type'] == 'flat':
  3615. display.SetSelection(1)
  3616. else:
  3617. display.SetSelection(0)
  3618. if data[vtype]['mode']['type'] == 'surface':
  3619. rasters = self.mapWindow.GetLayerNames('raster')
  3620. constants = self.mapWindow.GetLayerNames('constant')
  3621. surfaces = rasters + constants
  3622. surfaceWin = self.FindWindowById(self.win['vector'][vtype]['surface'])
  3623. surfaceWin.SetItems(surfaces)
  3624. for idx, surface in enumerate(surfaces):
  3625. try:# TODO fix this mess
  3626. selected = data[vtype]['mode']['surface']['show'][idx]
  3627. except (TypeError, IndexError, KeyError):
  3628. selected = False
  3629. surfaceWin.Check(idx, selected)
  3630. for type in ('slider', 'text'):
  3631. win = self.FindWindowById(self.win['vector']['lines']['height'][type])
  3632. win.SetValue(data['lines']['height']['value'])
  3633. #
  3634. # points
  3635. #
  3636. showPoints = self.FindWindowById(self.win['vector']['points']['show'])
  3637. if 'object' in data['points']:
  3638. showPoints.SetValue(True)
  3639. else:
  3640. showPoints.SetValue(False)
  3641. if npoints > 0:
  3642. showPoints.Enable(True)
  3643. else:
  3644. showPoints.Enable(False)
  3645. self.UpdateVectorShow('points',
  3646. showPoints.IsChecked())
  3647. # size, width, marker, color
  3648. for prop in ('size', 'marker', 'color'):
  3649. win = self.FindWindowById(self.win['vector']['points'][prop])
  3650. name = win.GetName()
  3651. if name == 'selection':
  3652. win.SetSelection(data['points'][prop]['value'])
  3653. elif name == 'color':
  3654. color = map(int, data['points'][prop]['value'].split(':'))
  3655. win.SetValue(color)
  3656. else:
  3657. win.SetValue(data['points'][prop]['value'])
  3658. self.OnCheckThematic(None)
  3659. # height
  3660. for type in ('slider', 'text'):
  3661. win = self.FindWindowById(self.win['vector']['points']['height'][type])
  3662. win.SetValue(data['points']['height']['value'])
  3663. def UpdateVolumePage(self, layer, data, updateName = True):
  3664. """!Update volume page"""
  3665. if updateName:
  3666. self.FindWindowById(self.win['volume']['map']).SetValue(layer.name)
  3667. # draw
  3668. for control, idata in data['draw'].iteritems():
  3669. if control == 'all': # skip 'all' property
  3670. continue
  3671. win = self.FindWindowById(self.win['volume']['draw'][control])
  3672. if control == 'mode':
  3673. value = data['draw']['mode']['value']
  3674. if control == 'shading':
  3675. if data['draw']['shading'][data['draw']['mode']['desc']]['desc'] == 'flat':
  3676. value = 0
  3677. else:
  3678. value = 1
  3679. if control == 'resolution':
  3680. value = idata[data['draw']['mode']['desc']]['value']
  3681. if win.GetName() == "selection":
  3682. win.SetSelection(value)
  3683. else:
  3684. win.SetValue(value)
  3685. self.OnVolumeMode(None)
  3686. id = data['object']['id']
  3687. if data['draw']['mode']['desc'] == 'isosurface':
  3688. self._display.SetIsosurfaceMode(id, data['draw']['shading']['isosurface']['value'])
  3689. self._display.SetIsosurfaceRes(id, data['draw']['resolution']['isosurface']['value'])
  3690. else:
  3691. self._display.SetSliceMode(id, data['draw']['shading']['slice']['value'])
  3692. self._display.SetSliceRes(id, data['draw']['resolution']['slice']['value'])
  3693. box = self.FindWindowById(self.win['volume']['isosurfs'])
  3694. if data['draw']['mode']['desc'] == 'isosurface':
  3695. isosurfaces = []
  3696. for iso in data['isosurface']:
  3697. level = iso['topo']['value']
  3698. isosurfaces.append("%s %s" % (_("Level"), level))
  3699. box.Set(isosurfaces)
  3700. box.SetChecked(range(len(isosurfaces)))
  3701. if data['isosurface']:
  3702. box.SetSelection(0)
  3703. self.UpdateVolumeIsosurfPage(data['isosurface'][0])
  3704. else:
  3705. self.UpdateVolumeIsosurfPage(data['attribute'])
  3706. else:
  3707. slices = []
  3708. for slice in data['slice']:
  3709. axis = ("X", "Y", "Z")[slice['position']['axis']]
  3710. slices.append("%s %s" % (_("Slice parallel to"), axis))
  3711. box.Set(slices)
  3712. box.SetChecked(range(len(slices)))
  3713. if data['slice']:
  3714. box.SetSelection(0)
  3715. self.UpdateVolumeSlicePage(data['slice'][0])
  3716. else:
  3717. self.UpdateVolumeSlicePage(None)
  3718. #
  3719. # position
  3720. #
  3721. if 'x' in data['position']:
  3722. xval = data['position']['x']
  3723. self.FindWindowById(self.win['volume']['position']['axis']).SetSelection(0)
  3724. for control in ('slider','text'):
  3725. self.FindWindowById(self.win['volume']['position'][control]).SetValue(xval)
  3726. # set topo range
  3727. mapRange = self._get3dRange(name = layer.name)
  3728. desc = self.FindWindowById(self.win['volume']['desc'])
  3729. desc.SetLabel("%s %.2f - %.2f" % (_("range:"), mapRange[0], mapRange[1]))
  3730. def UpdateVolumeIsosurfPage(self, data):
  3731. """!Update dialog -- isosurface attributes"""
  3732. #
  3733. # isosurface attributes
  3734. #
  3735. for attrb in ('topo', 'color', 'mask',
  3736. 'transp', 'shine'):
  3737. # skip empty attributes
  3738. if attrb not in data:
  3739. self.SetMapObjUseMap(nvizType = 'volume', attrb = attrb, map = None)
  3740. continue
  3741. value = data[attrb]['value']
  3742. if attrb == 'color':
  3743. if data[attrb]['map']:
  3744. self.FindWindowById(self.win['volume'][attrb]['map']).SetValue(value)
  3745. else: # constant
  3746. color = map(int, value.split(':'))
  3747. self.FindWindowById(self.win['volume'][attrb]['const']).SetColour(color)
  3748. else:
  3749. if data[attrb]['map']:
  3750. self.vetoGSelectEvt = True
  3751. win = self.FindWindowById(self.win['volume'][attrb]['map'])
  3752. win.SetValue(value)
  3753. else:
  3754. if value:
  3755. win = self.FindWindowById(self.win['volume'][attrb]['const'])
  3756. if attrb == 'topo':
  3757. win.SetValue(float(value))
  3758. else:
  3759. win.SetValue(self._getPercent(value))
  3760. self.SetMapObjUseMap(nvizType = 'volume',
  3761. attrb = attrb, map = data[attrb]['map'])
  3762. # set inout
  3763. if 'inout' in data:
  3764. self.FindWindowById(self.win['volume']['inout']).SetValue(data['inout'])
  3765. def UpdateVolumeSlicePage(self, data):
  3766. """!Update dialog -- slice attributes"""
  3767. if data:
  3768. for coord in ('x1', 'x2', 'y1', 'y2', 'z1', 'z2'):
  3769. win = self.FindWindowById(self.win['volume']['slice']['slider_' + coord])
  3770. win.Enable()
  3771. win.SetValue(data['position'][coord] * 100)
  3772. win = self.FindWindowById(self.win['volume']['slice']['axes'])
  3773. win.SetSelection(data['position']['axis'])
  3774. win.Enable()
  3775. win = self.FindWindowById(self.win['volume']['slice']['transp'])
  3776. win.SetValue(self._getPercent(data['transp']['value']))
  3777. win.Enable()
  3778. self.FindWindowById(self.win['volume']['slice']['reset']).Enable()
  3779. else:
  3780. for coord in ('x1', 'x2', 'y1', 'y2', 'z1', 'z2'):
  3781. self.FindWindowById(self.win['volume']['slice']['slider_' + coord]).Disable()
  3782. self.FindWindowById(self.win['volume']['slice']['axes']).Disable()
  3783. self.FindWindowById(self.win['volume']['slice']['transp']).Disable()
  3784. self.FindWindowById(self.win['volume']['slice']['reset']).Disable()
  3785. self.UpdateSliceLabels()
  3786. def UpdateSliceLabels(self):
  3787. """!Update text labels of slice controls according to axis"""
  3788. sel = self.FindWindowById(self.win['volume']['slice']['axes']).GetSelection()
  3789. if sel == 0:
  3790. self.FindWindowByName('label_edge_0').SetLabel(_("North edge:"))
  3791. self.FindWindowByName('label_edge_1').SetLabel(_("South edge:"))
  3792. self.FindWindowByName('label_edge_2').SetLabel(_("West edge:"))
  3793. self.FindWindowByName('label_edge_3').SetLabel(_("East edge:"))
  3794. self.FindWindowByName('label_coord_0').SetLabel(_("Northing (Y):"))
  3795. self.FindWindowByName('label_coord_1').SetLabel(_("Height (Z):"))
  3796. self.FindWindowByName('label_coord_2').SetLabel(_("Easting (X):"))
  3797. elif sel == 1:
  3798. self.FindWindowByName('label_edge_0').SetLabel(_("West edge:"))
  3799. self.FindWindowByName('label_edge_1').SetLabel(_("East edge:"))
  3800. self.FindWindowByName('label_edge_2').SetLabel(_("North edge:"))
  3801. self.FindWindowByName('label_edge_3').SetLabel(_("South edge:"))
  3802. self.FindWindowByName('label_coord_0').SetLabel(_("Easting (X):"))
  3803. self.FindWindowByName('label_coord_1').SetLabel(_("Height (Z):"))
  3804. self.FindWindowByName('label_coord_2').SetLabel(_("Northing (Y):"))
  3805. else:
  3806. self.FindWindowByName('label_edge_0').SetLabel(_("West edge:"))
  3807. self.FindWindowByName('label_edge_1').SetLabel(_("East edge:"))
  3808. self.FindWindowByName('label_edge_2').SetLabel(_("Bottom edge:"))
  3809. self.FindWindowByName('label_edge_3').SetLabel(_("Top edge:"))
  3810. self.FindWindowByName('label_coord_0').SetLabel(_("Easting (X):"))
  3811. self.FindWindowByName('label_coord_1').SetLabel(_("Northing (Y):"))
  3812. self.FindWindowByName('label_coord_2').SetLabel(_("Height (Z):"))
  3813. def SetPage(self, name):
  3814. """!Get named page"""
  3815. if name == 'view':
  3816. self.SetSelection(0)
  3817. elif name in ('surface', 'vector', 'volume'):
  3818. self.SetSelection(1)
  3819. else:
  3820. self.SetSelection(2)
  3821. win = self.FindWindowById(self.page[name]['notebook'])
  3822. try:
  3823. win.Expand(win.GetFoldPanel(self.page[name]['id']))
  3824. self.UpdateScrolling((win.GetFoldPanel(self.page[name]['id']).GetGrandParent(),))
  3825. except AttributeError:
  3826. win.SetSelection(self.page[name]['id'])
  3827. class PositionWindow(wx.Window):
  3828. """!Abstract position control window, see subclasses
  3829. ViewPostionWindow and LightPositionWindow"""
  3830. def __init__(self, parent, mapwindow, id = wx.ID_ANY,
  3831. **kwargs):
  3832. self.mapWindow = mapwindow
  3833. self.quick = True
  3834. wx.Window.__init__(self, parent, id, **kwargs)
  3835. self.SetBackgroundColour("WHITE")
  3836. self.pdc = wx.PseudoDC()
  3837. self.pdc.SetBrush(wx.Brush(colour = 'dark green', style = wx.SOLID))
  3838. self.pdc.SetPen(wx.Pen(colour = 'dark green', width = 2, style = wx.SOLID))
  3839. self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x: None)
  3840. self.Bind(wx.EVT_PAINT, self.OnPaint)
  3841. # self.Bind(wx.EVT_MOTION, self.OnMouse)
  3842. self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
  3843. def Draw(self, pos, scale = False):
  3844. w, h = self.GetClientSize()
  3845. x, y = pos
  3846. if scale:
  3847. x = x * w
  3848. y = y * h
  3849. self.pdc.Clear()
  3850. self.pdc.BeginDrawing()
  3851. self.pdc.DrawLine(w / 2, h / 2, x, y)
  3852. self.pdc.DrawCircle(x, y, 5)
  3853. self.pdc.EndDrawing()
  3854. def OnPaint(self, event):
  3855. dc = wx.BufferedPaintDC(self)
  3856. dc.SetBackground(wx.Brush("White"))
  3857. dc.Clear()
  3858. self.PrepareDC(dc)
  3859. self.pdc.DrawToDC(dc)
  3860. def UpdatePos(self, xcoord, ycoord):
  3861. """!Update position coordinates (origin: UL)"""
  3862. if xcoord < 0.0:
  3863. xcoord = 0.0
  3864. elif xcoord > 1.0:
  3865. xcoord = 1.0
  3866. if ycoord < 0.0:
  3867. ycoord = 0.0
  3868. elif ycoord > 1.0:
  3869. ycoord = 1.0
  3870. x, y = self.TransformCoordinates(xcoord, ycoord)
  3871. self.data['position']['x'] = x
  3872. self.data['position']['y'] = y
  3873. return xcoord, ycoord
  3874. def OnMouse(self, event):
  3875. if event.LeftIsDown():
  3876. x, y = event.GetPosition()
  3877. self.Draw(pos = (x, y))
  3878. w, h = self.GetClientSize()
  3879. x = float(x) / w
  3880. y = float(y) / h
  3881. self.UpdatePos(x, y)
  3882. self.Refresh(False)
  3883. event.Skip()
  3884. def PostDraw(self):
  3885. x, y = self.UpdatePos(self.data['position']['x'],
  3886. self.data['position']['y'])
  3887. self.Draw(pos = (x,y), scale = True)
  3888. class ViewPositionWindow(PositionWindow):
  3889. """!View position control widget"""
  3890. def __init__(self, parent, mapwindow, id = wx.ID_ANY,
  3891. **kwargs):
  3892. PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
  3893. self.data = self.mapWindow.view
  3894. self.PostDraw()
  3895. def UpdatePos(self, xcoord, ycoord):
  3896. x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
  3897. event = wxUpdateView(zExag = True)
  3898. wx.PostEvent(self.mapWindow, event)
  3899. return x, y
  3900. def TransformCoordinates(self, x, y, toLight = True):
  3901. return x, y
  3902. def OnMouse(self, event):
  3903. PositionWindow.OnMouse(self, event)
  3904. if event.LeftIsDown():
  3905. self.mapWindow.render['quick'] = self.quick
  3906. self.mapWindow.Refresh(eraseBackground = False)
  3907. elif event.LeftUp():
  3908. self.mapWindow.render['quick'] = False
  3909. self.mapWindow.Refresh(eraseBackground = False)
  3910. event.Skip()
  3911. class LightPositionWindow(PositionWindow):
  3912. """!Light position control widget"""
  3913. def __init__(self, parent, mapwindow, id = wx.ID_ANY,
  3914. **kwargs):
  3915. PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
  3916. self.data = self.mapWindow.light
  3917. self.quick = False
  3918. self.PostDraw()
  3919. def UpdatePos(self, xcoord, ycoord):
  3920. x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
  3921. event = wxUpdateLight()
  3922. wx.PostEvent(self.mapWindow, event)
  3923. return x, y
  3924. def TransformCoordinates(self, x, y, toLight = True):
  3925. if toLight:
  3926. x = 2 * x - 1
  3927. y = -2 * y + 1
  3928. else:
  3929. x = (x + 1)/2
  3930. y = (1 - y)/2
  3931. return x, y
  3932. def PostDraw(self):
  3933. event = wxUpdateLight(refresh = True)
  3934. wx.PostEvent(self.mapWindow, event)
  3935. x, y = self.data['position']['x'], self.data['position']['y']
  3936. x, y = self.TransformCoordinates(x, y, toLight = False)
  3937. self.Draw(pos = (x,y), scale = True)
  3938. def OnMouse(self, event):
  3939. PositionWindow.OnMouse(self, event)
  3940. if event.LeftUp():
  3941. self.mapWindow.render['quick'] = False
  3942. self.mapWindow.Refresh(eraseBackground = False)