nviz_tools.py 208 KB

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