nviz_tools.py 210 KB

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