nviz_tools.py 209 KB

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