nviz_tools.py 209 KB

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