nviz_tools.py 209 KB

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